From c50bfb97a972764240a0509264519da541f7ee63 Mon Sep 17 00:00:00 2001 From: MT-Mint <798521692@qq.com> Date: Wed, 15 Apr 2026 10:18:47 +0800 Subject: [PATCH] feat(phase-06): merge references into additional_kwargs.files with soft-fail --- frontend/src/core/threads/hooks.ts | 35 +++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/frontend/src/core/threads/hooks.ts b/frontend/src/core/threads/hooks.ts index 6abfa7d1..6c036da4 100644 --- a/frontend/src/core/threads/hooks.ts +++ b/frontend/src/core/threads/hooks.ts @@ -5,7 +5,9 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { useCallback, useEffect, useRef, useState } from "react"; import { toast } from "sonner"; -import type { PromptInputMessage } from "@/components/ai-elements/prompt-input"; +import type { + PromptInputMessage, +} from "@/components/ai-elements/prompt-input"; import { getAPIClient } from "../api"; import { getBackendBaseURL } from "../config"; @@ -17,6 +19,7 @@ import type { UploadedFileInfo } from "../uploads"; import { uploadFiles } from "../uploads"; import type { UploadTarget } from "../uploads/api"; +import { buildFilesForSubmit } from "./submit-files"; import type { AgentThread, AgentThreadContext, @@ -549,15 +552,14 @@ export function useThreadStream({ } } - // Build files metadata for submission (included in additional_kwargs) - const filesForSubmit: FileInMessage[] = uploadedFileInfo.map( - (info) => ({ - filename: info.filename, - size: info.size, - path: info.virtual_path, - status: "uploaded" as const, - }), + // Build files metadata for submission (single envelope for uploads + references) + const { files: filesForSubmit, staleCount } = buildFilesForSubmit( + uploadedFileInfo, + message.references, ); + if (staleCount > 0) { + toast.error("部分引用已失效,已自动移除"); + } await thread.submit( { @@ -663,7 +665,10 @@ export function useSubmitThread({ const text = message.text.trim(); const hasFiles = !!(message.files && message.files.length > 0); - if (!text && !hasFiles) { + const hasReferences = !!( + message.references && message.references.length > 0 + ); + if (!text && !hasFiles && !hasReferences) { return; } @@ -709,6 +714,14 @@ export function useSubmitThread({ } } + const { files: filesForSubmit, staleCount } = buildFilesForSubmit( + [], + message.references, + ); + if (staleCount > 0) { + toast.error("部分引用已失效,已自动移除"); + } + await thread.submit( { messages: [ @@ -720,6 +733,8 @@ export function useSubmitThread({ text, }, ], + additional_kwargs: + filesForSubmit.length > 0 ? { files: filesForSubmit } : {}, }, ] as Message[], },