From 24db7e6f706c4fd0b43e895cc4f053aeeeebe8e7 Mon Sep 17 00:00:00 2001 From: Lex Lim Date: Sun, 29 Jun 2025 02:47:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E8=A6=86=E7=9B=96=E5=AF=B9?= =?UTF-8?q?=E8=AF=9D=E5=88=A4=E6=96=AD=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entity/Conversation.ts | 18 ++++++++++-------- src/entity/ConversationDialogue.ts | 3 +++ src/proxies/OpenAIApiProxy.ts | 1 + src/types/MetaConfig.ts | 2 ++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/entity/Conversation.ts b/src/entity/Conversation.ts index 742a83d..0123ed7 100644 --- a/src/entity/Conversation.ts +++ b/src/entity/Conversation.ts @@ -300,22 +300,24 @@ export class Conversation { */ public async appendMessages(app: App, messages: any[], options: { dialogueCount?: number, - replaceCurrentDialogue?: boolean + workflowRunId?: string | null, } = {}): Promise { // 确保当前页存在 await this.ensureCurrentPage(app); let conversationDialogue: ConversationDialogue | null = null; if (typeof options.dialogueCount === "number") { - if (options.replaceCurrentDialogue) { - // 删除当前对话在内的后续对话 - await this.removeDialogueAfter(app, options.dialogueCount); - } else { - // 删除后续对话 - await this.removeDialogueAfter(app, options.dialogueCount + 1); - } // 获取指定对话轮数的对话块 conversationDialogue = await this.getDialogueAt(app, options.dialogueCount); + + if (conversationDialogue && conversationDialogue.workflowRunId === options.workflowRunId) { + // 如果对话块存在且工作流运行 ID 相同,则仅删除后续对话 + await this.removeDialogueAfter(app, options.dialogueCount + 1); + } else { + // 如果对话块不存在或工作流运行 ID 不同,则删除当前对话在内的后续对话 + conversationDialogue = null; + await this.removeDialogueAfter(app, options.dialogueCount); + } } if (!conversationDialogue) { diff --git a/src/entity/ConversationDialogue.ts b/src/entity/ConversationDialogue.ts index 1452bc2..70809b7 100644 --- a/src/entity/ConversationDialogue.ts +++ b/src/entity/ConversationDialogue.ts @@ -13,6 +13,9 @@ export class ConversationDialogue { @Column("integer", { name: "dialogue_count", default: 0 }) dialogueCount!: number + @Column("text", { name: "workflow_run_id", nullable: true }) + workflowRunId!: string | null + @Column("integer", { default: 0 }) page!: number diff --git a/src/proxies/OpenAIApiProxy.ts b/src/proxies/OpenAIApiProxy.ts index ff6fceb..6a95f7d 100644 --- a/src/proxies/OpenAIApiProxy.ts +++ b/src/proxies/OpenAIApiProxy.ts @@ -222,6 +222,7 @@ export class OpenAIApiProxy extends BaseLLMProxy { await conversation.appendMessages(this.app, newMessages, { dialogueCount: metaConfig.dialogueCount, + workflowRunId: metaConfig.workflowRunId, }); } diff --git a/src/types/MetaConfig.ts b/src/types/MetaConfig.ts index 4f8b88d..4038783 100644 --- a/src/types/MetaConfig.ts +++ b/src/types/MetaConfig.ts @@ -5,6 +5,8 @@ export interface EchoBackMetaConfig { export interface ApiProxyMetaConfig { /** 对话 ID */ conversationId?: string; + /** 工作流运行 ID */ + workflowRunId?: string; /** 当前对话轮数 */ dialogueCount?: number; /** 是否将此次对话记录到记忆中 */