多智能体会商上传文件
This commit is contained in:
1 parent
cf5550ab0a
commit
f01789a17e
9 files changed
+411
-49
No files matched your search
@@ -19,9 +19,11 @@ import {
|
||||
initIntent,
|
||||
streamIntent,
|
||||
type IntentErrorDetail,
|
||||
type IntentFileRef,
|
||||
type IntentStreamPhase,
|
||||
type IntentSummary,
|
||||
} from "@/roundtable-planning/api/intent";
|
||||
import { uploadFiles } from "@/core/uploads/api";
|
||||
import {
|
||||
clarificationKey,
|
||||
formatIntentClarificationAnswer,
|
||||
@@ -42,6 +44,8 @@ export type InteractiveMessage = {
|
||||
time: string;
|
||||
streaming?: boolean;
|
||||
phase?: string;
|
||||
/** 用户气泡里附带的上传文件(仅展示用:文件名 + 大小)。 */
|
||||
files?: Array<{ filename: string; size: number }>;
|
||||
/** First clarification (back-compat); prefer `clarifications`. */
|
||||
clarification?: ClarificationPayload;
|
||||
/**
|
||||
@@ -109,8 +113,12 @@ export interface UseStep1IntentReturn {
|
||||
// ─── Handlers ────────────────────────────────────────────────────────
|
||||
/** 清空当前 Step 1 状态并重新拉取 intent thread。 */
|
||||
runStep1Init: () => void;
|
||||
/** 把 `userText` 作为用户气泡发给 intent agent,流式渲染回复。 */
|
||||
sendIntentMessage: (userText: string) => Promise<void>;
|
||||
/**
|
||||
* 把 `userText` 作为用户气泡发给 intent agent,流式渲染回复。
|
||||
* `files`:可选的本地文件,发送前先上传到 intent thread,再把引用随消息提交(后端
|
||||
* 注入 additional_kwargs.files,意图智能体即可 read_file 读取)。允许「仅文件无文本」。
|
||||
*/
|
||||
sendIntentMessage: (userText: string, files?: File[]) => Promise<void>;
|
||||
/**
|
||||
* 提交某条 agent 消息的全部澄清问题答案 —— 逐题取各自选择,拼成一条合并消息
|
||||
* 发回。至少答一题才会发送。单题时退化为发送该题答案。
|
||||
@@ -275,9 +283,10 @@ export function useStep1Intent(options: UseStep1IntentOptions): UseStep1IntentRe
|
||||
}, [interactiveMessages, intentReady]);
|
||||
|
||||
const sendIntentMessage = useCallback(
|
||||
async (userText: string) => {
|
||||
async (userText: string, files?: File[]) => {
|
||||
const trimmed = userText.trim();
|
||||
if (!trimmed) return;
|
||||
const hasFiles = !!(files && files.length > 0);
|
||||
if (!trimmed && !hasFiles) return;
|
||||
if (!intentThreadId) {
|
||||
triggerToast("⚠️ 任务理解智能体尚未就绪,请稍候");
|
||||
return;
|
||||
@@ -304,16 +313,24 @@ export function useStep1Intent(options: UseStep1IntentOptions): UseStep1IntentRe
|
||||
senderName: "用户",
|
||||
content: trimmed,
|
||||
time: userMsgTime,
|
||||
files: hasFiles
|
||||
? files!.map((f) => ({ filename: f.name, size: f.size }))
|
||||
: undefined,
|
||||
};
|
||||
setInteractiveMessages((prev) => [...prev, userMsg]);
|
||||
|
||||
const timelineDesc = trimmed
|
||||
? trimmed.length > 25
|
||||
? trimmed.substring(0, 25) + "..."
|
||||
: trimmed
|
||||
: `上传了 ${files!.length} 个文件`;
|
||||
setTimelineEntries((prev) => [
|
||||
...prev,
|
||||
{
|
||||
id: prev.length + 1,
|
||||
time: userMsgTime,
|
||||
title: "用户实时反馈",
|
||||
desc: trimmed.length > 25 ? trimmed.substring(0, 25) + "..." : trimmed,
|
||||
desc: timelineDesc,
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -333,10 +350,49 @@ export function useStep1Intent(options: UseStep1IntentOptions): UseStep1IntentRe
|
||||
|
||||
setIsIntentSending(true);
|
||||
try {
|
||||
// 先把本地文件上传到 intent thread —— 与普通聊天同一上传接口/技能链路。
|
||||
// 拿到 virtual_path 后随消息提交,后端注入 additional_kwargs.files。
|
||||
let fileRefs: IntentFileRef[] | undefined;
|
||||
if (hasFiles) {
|
||||
setInteractiveMessages((prev) =>
|
||||
prev.map((m) =>
|
||||
m.id === agentMsgId ? { ...m, phase: "正在上传文件" } : m,
|
||||
),
|
||||
);
|
||||
try {
|
||||
const up = await uploadFiles(intentThreadId, files!);
|
||||
fileRefs = up.files.map((f) => ({
|
||||
filename: f.filename,
|
||||
size: f.size,
|
||||
path: f.virtual_path,
|
||||
status: "uploaded" as const,
|
||||
}));
|
||||
} catch (err) {
|
||||
setInteractiveMessages((prev) =>
|
||||
prev.map((m) =>
|
||||
m.id === agentMsgId
|
||||
? {
|
||||
...m,
|
||||
content: `(文件上传失败) ${(err as Error).message}`,
|
||||
streaming: false,
|
||||
}
|
||||
: m,
|
||||
),
|
||||
);
|
||||
triggerToast(`❌ 文件上传失败: ${(err as Error).message}`);
|
||||
if (intentAborterRef.current === aborter) {
|
||||
intentAborterRef.current = null;
|
||||
}
|
||||
setIsIntentSending(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const res = await streamIntent({
|
||||
threadId: intentThreadId,
|
||||
message: trimmed,
|
||||
model: selectedModelRef.current || undefined,
|
||||
files: fileRefs,
|
||||
signal: aborter.signal,
|
||||
onTextDelta: (delta) => {
|
||||
setInteractiveMessages((prev) =>
|
||||
|
||||
Reference in new issue
Block a user