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 { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { toast } from "sonner";
|
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 { getAPIClient } from "../api";
|
||||||
import { getBackendBaseURL } from "../config";
|
import { getBackendBaseURL } from "../config";
|
||||||
|
|
@ -17,6 +19,7 @@ import type { UploadedFileInfo } from "../uploads";
|
||||||
import { uploadFiles } from "../uploads";
|
import { uploadFiles } from "../uploads";
|
||||||
import type { UploadTarget } from "../uploads/api";
|
import type { UploadTarget } from "../uploads/api";
|
||||||
|
|
||||||
|
import { buildFilesForSubmit } from "./submit-files";
|
||||||
import type {
|
import type {
|
||||||
AgentThread,
|
AgentThread,
|
||||||
AgentThreadContext,
|
AgentThreadContext,
|
||||||
|
|
@ -549,15 +552,14 @@ export function useThreadStream({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build files metadata for submission (included in additional_kwargs)
|
// Build files metadata for submission (single envelope for uploads + references)
|
||||||
const filesForSubmit: FileInMessage[] = uploadedFileInfo.map(
|
const { files: filesForSubmit, staleCount } = buildFilesForSubmit(
|
||||||
(info) => ({
|
uploadedFileInfo,
|
||||||
filename: info.filename,
|
message.references,
|
||||||
size: info.size,
|
|
||||||
path: info.virtual_path,
|
|
||||||
status: "uploaded" as const,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
|
if (staleCount > 0) {
|
||||||
|
toast.error("部分引用已失效,已自动移除");
|
||||||
|
}
|
||||||
|
|
||||||
await thread.submit(
|
await thread.submit(
|
||||||
{
|
{
|
||||||
|
|
@ -663,7 +665,10 @@ export function useSubmitThread({
|
||||||
const text = message.text.trim();
|
const text = message.text.trim();
|
||||||
|
|
||||||
const hasFiles = !!(message.files && message.files.length > 0);
|
const hasFiles = !!(message.files && message.files.length > 0);
|
||||||
if (!text && !hasFiles) {
|
const hasReferences = !!(
|
||||||
|
message.references && message.references.length > 0
|
||||||
|
);
|
||||||
|
if (!text && !hasFiles && !hasReferences) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -709,6 +714,14 @@ export function useSubmitThread({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { files: filesForSubmit, staleCount } = buildFilesForSubmit(
|
||||||
|
[],
|
||||||
|
message.references,
|
||||||
|
);
|
||||||
|
if (staleCount > 0) {
|
||||||
|
toast.error("部分引用已失效,已自动移除");
|
||||||
|
}
|
||||||
|
|
||||||
await thread.submit(
|
await thread.submit(
|
||||||
{
|
{
|
||||||
messages: [
|
messages: [
|
||||||
|
|
@ -720,6 +733,8 @@ export function useSubmitThread({
|
||||||
text,
|
text,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
additional_kwargs:
|
||||||
|
filesForSubmit.length > 0 ? { files: filesForSubmit } : {},
|
||||||
},
|
},
|
||||||
] as Message[],
|
] as Message[],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue