17 lines
2.7 KiB
TypeScript
17 lines
2.7 KiB
TypeScript
/* eslint-disable react-refresh/only-export-components */
|
||
import { useMemo, useSyncExternalStore } from "react";
|
||
import { AuiConfig, Tools, defineToolkit, useExternalStoreRuntime, type ToolCallMessagePartComponent } from "@assistant-ui/react";
|
||
import type { HarnessClientStore } from "./HarnessClientStore.js";
|
||
|
||
const AdsTool: ToolCallMessagePartComponent<Record<string, unknown>, unknown> = ({ args, result, status }) => <section className="tool-card" aria-label="广告指标工具"><div className="tool-card__head"><span>mock_ads_metrics</span><span className="status-dot">{status.type}</span></div><p>账户:{String(args.accountId ?? "等待参数")}</p><p>范围:最近 {String(args.days ?? "–")} 天</p>{result !== undefined && <pre>{JSON.stringify(result, null, 2).slice(0, 800)}</pre>}</section>;
|
||
const AnalyzeReportTool: ToolCallMessagePartComponent<Record<string, unknown>, unknown> = ({ args, result, status }) => <section className="tool-card" aria-label="表格日报分析工具"><div className="tool-card__head"><span>analyze_uploaded_report</span><span>{status.type}</span></div><p>正在解析上传的 Excel/CSV 日报</p><p className="muted">附件:{String(args.attachmentId ?? "等待附件")}</p>{result !== undefined && <p>表格证据已生成,Agent 正在形成日报结论。</p>}</section>;
|
||
const BuildBriefTool: ToolCallMessagePartComponent<Record<string, unknown>, unknown> = ({ args, result, status }) => <section className="tool-card" aria-label="Skill 日报模板生成工具"><div className="tool-card__head"><span>build_daily_brief</span><span>{status.type}</span></div><p>正在套用 daily-campaign-triage 固定四段式模板</p><p className="muted">日报日期:{String(args.analysis_date ?? "等待日期")}</p>{result !== undefined && <p>Skill 模板 Word 已生成,可点击下载。</p>}</section>;
|
||
export const toolkit = defineToolkit({ mock_ads_metrics: { type: "backend", display: "standalone", render: AdsTool }, analyze_uploaded_report: { type: "backend", display: "standalone", render: AnalyzeReportTool }, build_daily_brief: { type: "backend", display: "standalone", render: BuildBriefTool } });
|
||
export const harnessAuiConfig = AuiConfig({ tools: Tools({ toolkit }) });
|
||
|
||
export function useHarnessRuntime(store: HarnessClientStore) {
|
||
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot);
|
||
const runtime = useExternalStoreRuntime({ messages: snapshot.messages, convertMessage: (message) => message, isRunning: snapshot.running, isSendDisabled: !snapshot.model.configured, onNew: store.onNew, onCancel: store.cancel, adapters: { attachments: store.attachmentAdapter } });
|
||
return useMemo(() => ({ runtime, snapshot }), [runtime, snapshot]);
|
||
}
|