Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/chat-engine/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class ChatEngine implements IChatEngine {

private llmService!: LLMService;

private config!: ChatServiceConfig;
private configSetter!: ChatServiceConfigSetter;

private lastRequestParams: ChatRequestParams | undefined;

Expand Down Expand Up @@ -58,6 +58,14 @@ export default class ChatEngine implements IChatEngine {
return this.messages.at(-1)?.status || 'idle';
}

/**
* 获取当前配置
* 如果 configSetter 是函数,每次调用都会执行函数获取最新配置
*/
private get config(): ChatServiceConfig {
return typeof this.configSetter === 'function' ? this.configSetter() : this.configSetter || {};
}

/**
* 销毁聊天引擎实例
* @description 中止请求,清理消息存储和适配器,释放资源
Expand All @@ -81,9 +89,9 @@ export default class ChatEngine implements IChatEngine {
*/
public init(configSetter: ChatServiceConfigSetter, initialMessages?: ChatMessagesData[]) {
this.messageStore.initialize(this.convertMessages(initialMessages));
this.config = typeof configSetter === 'function' ? configSetter() : configSetter || {};
this.configSetter = configSetter;
this.llmService = new LLMService();
// 初始化AGUI适配器
// 初始化AGUI适配器(使用初始配置判断协议类型)
if (this.config.protocol === 'agui') {
this.aguiAdapter = new AGUIAdapter();
}
Expand Down
Loading