Files
Agent-System/web/src/lib/turnAttachments.ts
T
weichen 457e870330 fix(chat): 只上传文档时给出梳理或追问,不再裸报 HTTP 400
空消息加附件可以进入回合。无文字时按解析状态引导或回退审阅,有文字但未处理文档时先回答再追问。4xx 信封不再被前端丢弃。
2026-09-28 02:00:24 +00:00

33 lines
956 B
TypeScript

export type TurnAttachmentRef = {
filename: string;
doc_id?: string;
asset_id?: number;
parse_state?: string;
};
type AttachmentLike = {
name?: string;
docId?: string;
assetId?: number;
parseState?: string;
};
/** 把输入区附件收成对话回合引用。没有文件名的占位项不进入请求。 */
export function turnAttachmentRefs(
attachments: AttachmentLike[] | undefined,
): TurnAttachmentRef[] {
if (!attachments?.length) return [];
const refs: TurnAttachmentRef[] = [];
for (const att of attachments) {
const filename = att.name?.trim() || '';
if (!filename && !att.docId && !(att.assetId && att.assetId > 0)) continue;
refs.push({
filename: filename || '未命名文档',
...(att.docId ? { doc_id: att.docId } : {}),
...(att.assetId && att.assetId > 0 ? { asset_id: att.assetId } : {}),
...(att.parseState ? { parse_state: att.parseState } : {}),
});
}
return refs;
}