33 lines
956 B
TypeScript
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;
|
|
}
|