mirror of
https://github.com/coaidev/coai.git
synced 2025-05-30 02:10:25 +09:00
fix message dispatch error
This commit is contained in:
parent
0064408160
commit
2044e1bbe6
@ -1,7 +1,7 @@
|
||||
import axios from "axios";
|
||||
import { Model } from "./conversation/types.ts";
|
||||
|
||||
export const version = "3.5.3";
|
||||
export const version = "3.5.4";
|
||||
export const dev: boolean = window.location.hostname === "localhost";
|
||||
export const deploy: boolean = true;
|
||||
export let rest_api: string = "http://localhost:8094";
|
||||
|
@ -3,7 +3,7 @@ import { Message } from "./types.ts";
|
||||
import { sharingEvent } from "../events/sharing.ts";
|
||||
import { connectionEvent } from "../events/connection.ts";
|
||||
|
||||
type ConversationCallback = (idx: number, message: Message[]) => void;
|
||||
type ConversationCallback = (idx: number, message: Message[]) => boolean;
|
||||
|
||||
export class Conversation {
|
||||
protected connection?: Connection;
|
||||
@ -109,7 +109,11 @@ export class Conversation {
|
||||
}
|
||||
|
||||
public triggerCallback() {
|
||||
this.callback && this.callback(this.id, this.copyMessages());
|
||||
if (!this.callback) return;
|
||||
const interval = setInterval(() => {
|
||||
const state = this.callback && this.callback(this.id, this.copyMessages());
|
||||
if (state) clearInterval(interval);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
public addMessage(message: Message): number {
|
||||
|
@ -38,11 +38,12 @@ export class Manager {
|
||||
this.dispatch = dispatch;
|
||||
}
|
||||
|
||||
public callback(idx: number, message: Message[]): void {
|
||||
public callback(idx: number, message: Message[]): boolean {
|
||||
console.debug(
|
||||
`[manager] conversation receive message (id: ${idx}, length: ${message.length})`,
|
||||
);
|
||||
if (idx === this.current) this.dispatch?.(setMessages(message));
|
||||
return !!this.dispatch;
|
||||
}
|
||||
|
||||
public getCurrent(): number {
|
||||
@ -56,8 +57,8 @@ export class Manager {
|
||||
public createConversation(id: number): Conversation {
|
||||
console.debug(`[manager] create conversation instance (id: ${id})`);
|
||||
const _this = this;
|
||||
return new Conversation(id, function (idx: number, message: Message[]) {
|
||||
_this.callback(idx, message);
|
||||
return new Conversation(id, function (idx: number, message: Message[]): boolean {
|
||||
return _this.callback(idx, message);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user