@tbox.cn/app-agent-ui-kit 0.0.0-stage → 1.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +16 -2
- package/assets/keyboard-circle.svg +12 -0
- package/assets/more-circle.svg +3 -0
- package/assets/new-chat.svg +3 -0
- package/assets/quick-command-star.svg +3 -0
- package/assets/send-gradient.svg +14 -0
- package/assets/stop@2x.png +0 -0
- package/assets/voice-circle.svg +3 -0
- package/package.json +55 -3
- package/src/ChatPage.less +62 -0
- package/src/ChatPage.tsx +305 -0
- package/src/chat-config.test.ts +82 -0
- package/src/chat-config.ts +62 -0
- package/src/components/ActionBar/DebugButton.test.tsx +84 -0
- package/src/components/ActionBar/DebugButton.tsx +53 -0
- package/src/components/ActionBar/index.less +123 -0
- package/src/components/ActionBar/index.test.tsx +83 -0
- package/src/components/ActionBar/index.tsx +159 -0
- package/src/components/CardRenderer.tsx +36 -0
- package/src/components/ChatHeader/index.less +148 -0
- package/src/components/ChatHeader/index.test.tsx +74 -0
- package/src/components/ChatHeader/index.tsx +75 -0
- package/src/components/ChatInput/index.less +394 -0
- package/src/components/ChatInput/index.test.tsx +156 -0
- package/src/components/ChatInput/index.tsx +284 -0
- package/src/components/ChatInput/voice/VoicePressField.tsx +34 -0
- package/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +51 -0
- package/src/components/ChatInput/voice/machine.ts +27 -0
- package/src/components/ChatInput/voice/useVoicePress.ts +207 -0
- package/src/components/HistoryEntry/index.less +49 -0
- package/src/components/HistoryEntry/index.tsx +42 -0
- package/src/components/MediaList/index.less +241 -0
- package/src/components/MediaList/index.tsx +256 -0
- package/src/components/MessageBubble/index.less +325 -0
- package/src/components/MessageBubble/index.test.tsx +134 -0
- package/src/components/MessageBubble/index.tsx +177 -0
- package/src/components/PullDownIndicator/index.less +32 -0
- package/src/components/PullDownIndicator/index.tsx +32 -0
- package/src/components/QuickCommands/index.less +63 -0
- package/src/components/QuickCommands/index.test.tsx +99 -0
- package/src/components/QuickCommands/index.tsx +52 -0
- package/src/components/ReasoningBlock/index.less +90 -0
- package/src/components/ReasoningBlock/index.tsx +56 -0
- package/src/components/ScrollToBottomButton/index.less +32 -0
- package/src/components/ScrollToBottomButton/index.tsx +10 -0
- package/src/components/ToolCallBlock/detail.test.ts +346 -0
- package/src/components/ToolCallBlock/detail.ts +204 -0
- package/src/components/ToolCallBlock/index.less +312 -0
- package/src/components/ToolCallBlock/index.test.tsx +261 -0
- package/src/components/ToolCallBlock/index.tsx +212 -0
- package/src/components/ToolCallBlock/titles.ts +102 -0
- package/src/hooks/use-drag-gesture.test.ts +66 -0
- package/src/hooks/use-drag-gesture.ts +129 -0
- package/src/hooks/use-pull-down-history.ts +241 -0
- package/src/hooks/use-pull-down-wheel-native.test.ts +64 -0
- package/src/hooks/useMediaUpload.ts +242 -0
- package/src/hooks/useTTSAutoPlay.ts +82 -0
- package/src/index.ts +69 -0
- package/src/store-context.tsx +92 -0
- package/src/test/setup.ts +7 -0
- package/src/theme/contract.json +72 -0
- package/src/theme/global.less +99 -0
- package/src/theme/motion.less +19 -0
- package/src/theme/theme-contract.test.ts +69 -0
- package/src/theme/theme.ts +17 -0
- package/src/theme/tokens.less +79 -0
- package/src/types.ts +29 -0
- package/src/utils/copyText.ts +11 -0
- package/src/utils/haptics.test.ts +51 -0
- package/src/utils/haptics.ts +44 -0
- package/src/utils/imagePreview.ts +10 -0
- package/src/utils/pull-down-machine.test.ts +188 -0
- package/src/utils/pull-down-machine.ts +157 -0
- package/src/utils/session-error.ts +5 -0
- package/src/utils/toast.ts +15 -0
- package/src/utils/tool-call-display.test.ts +240 -0
- package/src/utils/tool-call-display.ts +146 -0
- package/src/vite-env.d.ts +1 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具展示语义判定(010 下沉 S5):「什么伪工具怎么显示」是框架语义,不该散在 UI 组件。
|
|
3
|
+
* - describeToolCall:ToolCallInfo → ToolCallDisplay 四分支(skill / preTool / normal / memory);
|
|
4
|
+
* - 纯函数零 UI 语义:徽标/颜色/展开交互留装配层(模板 ToolCallBlock 纯渲染);
|
|
5
|
+
* - preTool error 态经 result payload 的 status 判定(preTool 通道的 RESULT 恒置 done——
|
|
6
|
+
* isError 仅模型路径工具失败终态,R''8)——新增伪工具类型只需在此加 case;
|
|
7
|
+
* - memory(018 tool-debug):状态从 result envelope 派生(合成路径 RESULT 恒 done,
|
|
8
|
+
* ToolCallInfo.status 不承载语义,preTool 同款 R''8)。
|
|
9
|
+
*/
|
|
10
|
+
import {
|
|
11
|
+
MEMORY_TOOL_CALL_NAME,
|
|
12
|
+
PRE_TOOL_CALL_NAME,
|
|
13
|
+
SKILL_TOOL_CALL_NAME,
|
|
14
|
+
parseMemoryToolCallResult,
|
|
15
|
+
parsePreToolToolCallArgs,
|
|
16
|
+
parsePreToolToolCallResult,
|
|
17
|
+
parseSkillToolCallArgs,
|
|
18
|
+
} from '@tbox.cn/app-contracts';
|
|
19
|
+
import type { ToolCallInfo } from '@tbox.cn/app-agent-sdk-client';
|
|
20
|
+
|
|
21
|
+
export type ToolCallDisplay =
|
|
22
|
+
| { kind: 'skill'; label: string; hasDetail: false }
|
|
23
|
+
| {
|
|
24
|
+
kind: 'preTool';
|
|
25
|
+
label: string;
|
|
26
|
+
status: 'calling' | 'done' | 'error';
|
|
27
|
+
hasDetail: boolean;
|
|
28
|
+
resultText?: string;
|
|
29
|
+
errorText?: string;
|
|
30
|
+
}
|
|
31
|
+
| { kind: 'normal'; label: string; hasDetail: boolean }
|
|
32
|
+
| {
|
|
33
|
+
kind: 'memory';
|
|
34
|
+
label: string;
|
|
35
|
+
/** 召回结果语义(result envelope 派生) */
|
|
36
|
+
status: 'hit' | 'miss' | 'degraded' | 'skipped';
|
|
37
|
+
/** 命中条数(hit ≥1,其余 0) */
|
|
38
|
+
hits: number;
|
|
39
|
+
hasDetail: boolean;
|
|
40
|
+
/** 详情文本(hit: records 预览;degraded: 错误信息);miss/skipped 缺省 */
|
|
41
|
+
detailText?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
function prettyJson(value: unknown): string {
|
|
45
|
+
try {
|
|
46
|
+
return JSON.stringify(JSON.parse(JSON.stringify(value)), null, 2);
|
|
47
|
+
} catch {
|
|
48
|
+
return String(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** skipped reason 机器值 → 展示文案(未知值降级省略) */
|
|
53
|
+
const MEMORY_SKIP_REASON_TEXT: Record<string, string> = { intent: '意图命中' };
|
|
54
|
+
|
|
55
|
+
export function describeToolCall(tc: ToolCallInfo): ToolCallDisplay {
|
|
56
|
+
if (tc.name === SKILL_TOOL_CALL_NAME) {
|
|
57
|
+
const args = parseSkillToolCallArgs(tc.args);
|
|
58
|
+
return { kind: 'skill', label: args?.skillName ?? '', hasDetail: false };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (tc.name === PRE_TOOL_CALL_NAME) {
|
|
62
|
+
const args = parsePreToolToolCallArgs(tc.args);
|
|
63
|
+
const result = parsePreToolToolCallResult(tc.result);
|
|
64
|
+
const status: 'calling' | 'done' | 'error' =
|
|
65
|
+
tc.status === 'calling' ? 'calling' : result?.status === 'error' ? 'error' : 'done';
|
|
66
|
+
return {
|
|
67
|
+
kind: 'preTool',
|
|
68
|
+
label: args?.description ?? args?.toolName ?? '',
|
|
69
|
+
status,
|
|
70
|
+
// 详情:done → 结果(有用户价值);error → 错误文案;calling → 无
|
|
71
|
+
hasDetail: status !== 'calling' && !!tc.result,
|
|
72
|
+
...(status === 'done' && result?.result !== undefined
|
|
73
|
+
? { resultText: prettyJson(result.result) }
|
|
74
|
+
: {}),
|
|
75
|
+
...(status === 'error' ? { errorText: result?.error ?? '预执行失败' } : {}),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (tc.name === MEMORY_TOOL_CALL_NAME) {
|
|
80
|
+
const result = parseMemoryToolCallResult(tc.result);
|
|
81
|
+
const status = result?.status ?? 'miss';
|
|
82
|
+
const hits = status === 'hit' ? (result?.hits ?? 0) : 0;
|
|
83
|
+
const skipText =
|
|
84
|
+
status === 'skipped' && result?.reason
|
|
85
|
+
? MEMORY_SKIP_REASON_TEXT[result.reason]
|
|
86
|
+
: undefined;
|
|
87
|
+
const label =
|
|
88
|
+
status === 'hit'
|
|
89
|
+
? `记忆召回 · ${hits} 条命中`
|
|
90
|
+
: status === 'degraded'
|
|
91
|
+
? '记忆召回降级'
|
|
92
|
+
: status === 'skipped'
|
|
93
|
+
? `记忆召回 · 跳过${skipText ? `(${skipText})` : ''}`
|
|
94
|
+
: '记忆召回';
|
|
95
|
+
const detailText =
|
|
96
|
+
status === 'degraded'
|
|
97
|
+
? (result?.error ?? '记忆召回超时或存储异常')
|
|
98
|
+
: status === 'hit' && result?.records && result.records.length > 0
|
|
99
|
+
? result.records.map((r) => `[${r.kind}] ${r.text}`).join('\n')
|
|
100
|
+
: undefined;
|
|
101
|
+
return {
|
|
102
|
+
kind: 'memory',
|
|
103
|
+
label,
|
|
104
|
+
status,
|
|
105
|
+
hits,
|
|
106
|
+
hasDetail: !!detailText,
|
|
107
|
+
...(detailText !== undefined ? { detailText } : {}),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
kind: 'normal',
|
|
113
|
+
label: tc.name,
|
|
114
|
+
hasDetail: !!(tc.result || tc.error),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ===== 紧凑 IO 格式化(018 dev 视图;纯函数单源——双模板共用) =====
|
|
119
|
+
|
|
120
|
+
const COMPACT_IO_HEAD = 900;
|
|
121
|
+
const COMPACT_IO_TAIL = 300;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 工具出入参紧凑格式化(018 dev 视图):
|
|
125
|
+
* - 合法 JSON → 单行化(无缩进 stringify);超长 → 头尾保留 + 中段省略标记
|
|
126
|
+
* (head > tail 刻意为之:cards 字段与错误信息恒在尾部——修正 500 头截断截掉要害的缺陷);
|
|
127
|
+
* - 非法 JSON 原文同策略截断;
|
|
128
|
+
* - 仅服务屏显紧凑;复制场景请用原文/美化全文,不经本函数。
|
|
129
|
+
*/
|
|
130
|
+
export function formatCompactToolIo(
|
|
131
|
+
raw: string,
|
|
132
|
+
opts?: { head?: number; tail?: number },
|
|
133
|
+
): string {
|
|
134
|
+
if (!raw) return '';
|
|
135
|
+
const head = opts?.head ?? COMPACT_IO_HEAD;
|
|
136
|
+
const tail = opts?.tail ?? COMPACT_IO_TAIL;
|
|
137
|
+
let text = raw;
|
|
138
|
+
try {
|
|
139
|
+
text = JSON.stringify(JSON.parse(raw));
|
|
140
|
+
} catch {
|
|
141
|
+
// 非 JSON:原文截断
|
|
142
|
+
}
|
|
143
|
+
if (text.length <= head + tail) return text;
|
|
144
|
+
const omitted = text.length - head - tail;
|
|
145
|
+
return `${text.slice(0, head)}\n…[已省略 ${omitted} 字符]…\n${text.slice(-tail)}`;
|
|
146
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|