feat(phase-06): merge references into additional_kwargs.files with soft-fail
This commit is contained in:
parent
99e0fe13fd
commit
c50bfb97a9
|
|
@ -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[],
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue