@tbox.cn/app-template-agent 0.7.5 → 0.9.0

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.
Files changed (152) hide show
  1. package/.gitignore +5 -0
  2. package/.tbox/app.json +9 -1
  3. package/AGENTS.md +12 -4
  4. package/ENV.md +105 -21
  5. package/README.md +40 -38
  6. package/apps/client/VISUAL_RESTORE.md +11 -11
  7. package/apps/client/index.html +3 -1
  8. package/apps/client/package.json +9 -8
  9. package/apps/client/src/business/App.tsx +4 -4
  10. package/apps/client/src/business/README.md +5 -11
  11. package/apps/client/src/cards/registry.ts +23 -8
  12. package/apps/client/src/main.tsx +36 -2
  13. package/apps/client/src/modules.ts +7 -4
  14. package/apps/client/src/pages/index/index.tsx +18 -162
  15. package/apps/client/src/platform/AgentChatApp.tsx +7 -6
  16. package/apps/client/src/platform/agent-runtime.ts +5 -0
  17. package/apps/client/src/store/chat.ts +47 -185
  18. package/apps/client/src/test/setup.ts +7 -0
  19. package/apps/client/vite.config.ts +16 -1
  20. package/apps/server/package.json +0 -3
  21. package/apps/server/src/app-tools.ts +2 -1
  22. package/apps/server/src/app.ts +248 -119
  23. package/apps/server/src/config/integration.ts +2 -6
  24. package/apps/server/src/dev.ts +0 -1
  25. package/apps/server/src/intent-routes.ts +3 -3
  26. package/apps/server/src/modules.ts +4 -4
  27. package/apps/server/src/pre-tools.ts +4 -3
  28. package/apps/server/tests/agent-prompt.test.ts +81 -0
  29. package/apps/server/tests/cards-registry.test.ts +1 -3
  30. package/apps/server/tests/deployment-loader.test.ts +35 -56
  31. package/apps/server/tests/tool-runtime.test.ts +25 -61
  32. package/package.json +5 -4
  33. package/packages/agent-ui-kit/LICENSE +21 -0
  34. package/packages/agent-ui-kit/README.md +17 -0
  35. package/packages/agent-ui-kit/package.json +58 -0
  36. package/packages/agent-ui-kit/src/ChatPage.less +62 -0
  37. package/packages/agent-ui-kit/src/ChatPage.tsx +305 -0
  38. package/packages/agent-ui-kit/src/chat-config.test.ts +82 -0
  39. package/packages/agent-ui-kit/src/chat-config.ts +62 -0
  40. package/{apps/client → packages/agent-ui-kit}/src/components/ActionBar/DebugButton.tsx +2 -2
  41. package/{apps/client → packages/agent-ui-kit}/src/components/ActionBar/index.less +19 -16
  42. package/{apps/client → packages/agent-ui-kit}/src/components/ActionBar/index.tsx +10 -15
  43. package/packages/agent-ui-kit/src/components/CardRenderer.tsx +36 -0
  44. package/packages/agent-ui-kit/src/components/ChatHeader/index.less +148 -0
  45. package/packages/agent-ui-kit/src/components/ChatHeader/index.test.tsx +74 -0
  46. package/{apps/client → packages/agent-ui-kit}/src/components/ChatHeader/index.tsx +27 -15
  47. package/{apps/client → packages/agent-ui-kit}/src/components/ChatInput/index.less +47 -39
  48. package/packages/agent-ui-kit/src/components/ChatInput/index.test.tsx +156 -0
  49. package/{apps/client → packages/agent-ui-kit}/src/components/ChatInput/index.tsx +13 -4
  50. package/{apps/client → packages/agent-ui-kit}/src/components/ChatInput/voice/useVoicePress.ts +2 -2
  51. package/packages/agent-ui-kit/src/components/HistoryEntry/index.less +49 -0
  52. package/packages/agent-ui-kit/src/components/HistoryEntry/index.tsx +42 -0
  53. package/{apps/client → packages/agent-ui-kit}/src/components/MediaList/index.less +3 -3
  54. package/{apps/client → packages/agent-ui-kit}/src/components/MediaList/index.tsx +6 -6
  55. package/{apps/client → packages/agent-ui-kit}/src/components/MessageBubble/index.less +25 -20
  56. package/packages/agent-ui-kit/src/components/MessageBubble/index.test.tsx +112 -0
  57. package/{apps/client → packages/agent-ui-kit}/src/components/MessageBubble/index.tsx +22 -17
  58. package/{apps/client → packages/agent-ui-kit}/src/components/PullDownIndicator/index.less +2 -2
  59. package/{apps/client → packages/agent-ui-kit}/src/components/PullDownIndicator/index.tsx +2 -2
  60. package/packages/agent-ui-kit/src/components/QuickCommands/index.less +63 -0
  61. package/packages/agent-ui-kit/src/components/QuickCommands/index.test.tsx +99 -0
  62. package/packages/agent-ui-kit/src/components/QuickCommands/index.tsx +52 -0
  63. package/{apps/client → packages/agent-ui-kit}/src/components/ScrollToBottomButton/index.less +1 -1
  64. package/packages/agent-ui-kit/src/components/ToolCallBlock/detail.test.ts +346 -0
  65. package/packages/agent-ui-kit/src/components/ToolCallBlock/detail.ts +204 -0
  66. package/packages/agent-ui-kit/src/components/ToolCallBlock/index.less +312 -0
  67. package/packages/agent-ui-kit/src/components/ToolCallBlock/index.test.tsx +261 -0
  68. package/packages/agent-ui-kit/src/components/ToolCallBlock/index.tsx +212 -0
  69. package/packages/agent-ui-kit/src/components/ToolCallBlock/titles.ts +102 -0
  70. package/packages/agent-ui-kit/src/hooks/use-drag-gesture.test.ts +66 -0
  71. package/packages/agent-ui-kit/src/hooks/use-drag-gesture.ts +129 -0
  72. package/packages/agent-ui-kit/src/hooks/use-pull-down-history.ts +241 -0
  73. package/packages/agent-ui-kit/src/hooks/use-pull-down-wheel-native.test.ts +64 -0
  74. package/{apps/client → packages/agent-ui-kit}/src/hooks/useMediaUpload.ts +3 -3
  75. package/{apps/client → packages/agent-ui-kit}/src/hooks/useTTSAutoPlay.ts +7 -5
  76. package/packages/agent-ui-kit/src/index.ts +69 -0
  77. package/packages/agent-ui-kit/src/store-context.tsx +92 -0
  78. package/packages/agent-ui-kit/src/test/setup.ts +7 -0
  79. package/packages/agent-ui-kit/src/theme/contract.json +72 -0
  80. package/packages/agent-ui-kit/src/theme/global.less +99 -0
  81. package/packages/agent-ui-kit/src/theme/motion.less +19 -0
  82. package/packages/agent-ui-kit/src/theme/theme-contract.test.ts +69 -0
  83. package/packages/agent-ui-kit/src/theme/theme.ts +17 -0
  84. package/packages/agent-ui-kit/src/theme/tokens.less +79 -0
  85. package/packages/agent-ui-kit/src/utils/haptics.test.ts +51 -0
  86. package/packages/agent-ui-kit/src/utils/haptics.ts +44 -0
  87. package/packages/agent-ui-kit/src/utils/pull-down-machine.test.ts +188 -0
  88. package/packages/agent-ui-kit/src/utils/pull-down-machine.ts +157 -0
  89. package/packages/agent-ui-kit/src/utils/tool-call-display.test.ts +240 -0
  90. package/packages/agent-ui-kit/src/utils/tool-call-display.ts +146 -0
  91. package/packages/agent-ui-kit/src/vite-env.d.ts +1 -0
  92. package/packages/agent-ui-kit/tsconfig.json +8 -0
  93. package/packages/agent-ui-kit/vitest.config.ts +7 -0
  94. package/pnpm-lock.template.yaml +177 -111
  95. package/pnpm-workspace.template.yaml +12 -4
  96. package/profiles/mall/config/agent.jsonc +33 -0
  97. package/profiles/mall/config/chat.json +21 -0
  98. package/profiles/mall/config/knowledge.json +5 -0
  99. package/profiles/mall/config/llm_provider.json +5 -0
  100. package/profiles/mall/config/plugins.json +3 -0
  101. package/profiles/mall.json +16 -0
  102. package/scripts/check-workspace.mjs +3 -2
  103. package/apps/client/assets/copy@2x.png +0 -0
  104. package/apps/client/assets/debug.png +0 -0
  105. package/apps/client/assets/dislike@2x.png +0 -0
  106. package/apps/client/assets/like@2x.png +0 -0
  107. package/apps/client/assets/speaker@2x.png +0 -0
  108. package/apps/client/src/cards/CardRenderer.tsx +0 -20
  109. package/apps/client/src/components/ChatHeader/index.less +0 -104
  110. package/apps/client/src/components/ErrorBoundary.tsx +0 -2
  111. package/apps/client/src/components/QuickCommands/index.less +0 -48
  112. package/apps/client/src/components/QuickCommands/index.tsx +0 -29
  113. package/apps/client/src/components/ToolCallBlock/index.less +0 -131
  114. package/apps/client/src/components/ToolCallBlock/index.tsx +0 -125
  115. package/apps/client/src/examples/tourism/TourismLanding.tsx +0 -96
  116. package/apps/client/src/examples/tourism/index.less +0 -192
  117. package/apps/client/src/pages/index/index.less +0 -43
  118. package/apps/client/src/store/chat-config.ts +0 -40
  119. package/apps/client/src/styles/global.less +0 -60
  120. package/apps/client/src/styles/tokens.less +0 -60
  121. package/apps/server/src/config/deployment.ts +0 -47
  122. package/packages/module-weather/package.json +0 -36
  123. package/packages/module-weather/skills/weather-guide/SKILL.md +0 -22
  124. package/packages/module-weather/skills/weather-guide/references/dressing-tips.md +0 -5
  125. package/packages/module-weather/src/client/cards/weather/index.less +0 -22
  126. package/packages/module-weather/src/client/cards/weather/index.tsx +0 -14
  127. package/packages/module-weather/src/client/index.ts +0 -19
  128. package/packages/module-weather/src/index.ts +0 -2
  129. package/packages/module-weather/src/server/cards/weather/meta.ts +0 -27
  130. package/packages/module-weather/src/server/index.ts +0 -45
  131. package/packages/module-weather/src/server/pre-tools.ts +0 -20
  132. package/packages/module-weather/src/server/tool.ts +0 -29
  133. package/packages/module-weather/tbox.module.json +0 -27
  134. package/packages/module-weather/tsconfig.json +0 -14
  135. /package/{apps/client → packages/agent-ui-kit}/assets/keyboard-circle.svg +0 -0
  136. /package/{apps/client → packages/agent-ui-kit}/assets/more-circle.svg +0 -0
  137. /package/{apps/client → packages/agent-ui-kit}/assets/new-chat.svg +0 -0
  138. /package/{apps/client → packages/agent-ui-kit}/assets/quick-command-star.svg +0 -0
  139. /package/{apps/client → packages/agent-ui-kit}/assets/send-gradient.svg +0 -0
  140. /package/{apps/client → packages/agent-ui-kit}/assets/stop@2x.png +0 -0
  141. /package/{apps/client → packages/agent-ui-kit}/assets/voice-circle.svg +0 -0
  142. /package/{apps/client → packages/agent-ui-kit}/src/components/ChatInput/voice/VoicePressField.tsx +0 -0
  143. /package/{apps/client → packages/agent-ui-kit}/src/components/ChatInput/voice/VoiceRecordingOverlay.tsx +0 -0
  144. /package/{apps/client → packages/agent-ui-kit}/src/components/ChatInput/voice/machine.ts +0 -0
  145. /package/{apps/client → packages/agent-ui-kit}/src/components/ReasoningBlock/index.less +0 -0
  146. /package/{apps/client → packages/agent-ui-kit}/src/components/ReasoningBlock/index.tsx +0 -0
  147. /package/{apps/client → packages/agent-ui-kit}/src/components/ScrollToBottomButton/index.tsx +0 -0
  148. /package/{apps/client/src/types/chat.ts → packages/agent-ui-kit/src/types.ts} +0 -0
  149. /package/{apps/client → packages/agent-ui-kit}/src/utils/copyText.ts +0 -0
  150. /package/{apps/client → packages/agent-ui-kit}/src/utils/imagePreview.ts +0 -0
  151. /package/{apps/client → packages/agent-ui-kit}/src/utils/session-error.ts +0 -0
  152. /package/{apps/client → packages/agent-ui-kit}/src/utils/toast.ts +0 -0
@@ -1,27 +0,0 @@
1
- import { z } from 'zod';
2
- import type { CardMeta } from '@tbox.cn/app-contracts';
3
-
4
- export const dataSchema = z.object({
5
- city: z.string(),
6
- temp: z.number(),
7
- weather: z.string(),
8
- humidity: z.number(),
9
- });
10
-
11
- export type WeatherCardData = z.infer<typeof dataSchema>;
12
-
13
- const meta: CardMeta<typeof dataSchema> = {
14
- cardType: 'weather',
15
- dataSchema,
16
- displayName: '天气卡片',
17
- description: '展示某城市的天气数据,含温度、天气状况、湿度',
18
- sampleData: {
19
- city: '北京',
20
- temp: 22,
21
- weather: '晴',
22
- humidity: 35,
23
- },
24
- };
25
-
26
- export default meta;
27
- export { meta as weatherMeta };
@@ -1,45 +0,0 @@
1
- import { weatherTool } from './tool';
2
- import weatherMeta from './cards/weather/meta';
3
- import { loadModuleSkills } from '@tbox.cn/app-sdk/server';
4
- import type { LocalSkill, ServerContext, ServerModule } from '@tbox.cn/app-sdk/server';
5
- import { weatherPreTool } from './pre-tools';
6
-
7
- export { weatherTool, weatherMeta };
8
-
9
- /** 卡片 meta 声明 map(key 约定 = meta.cardType;数据 + 类型源) */
10
- const cards = {
11
- weather: weatherMeta,
12
- } as const;
13
-
14
- /**
15
- * 模块 skill 声明(009 模块文件化:SKILL.md 目录格式,文件即唯一源)。
16
- * - 底层能力:SDK `loadModuleSkills(packageName, import.meta.url)` 单策略定位包根
17
- * (createRequire 包名解析:dev workspace link / 模块 dist / 应用 bundle dist / 发布态
18
- * node_modules 全形态恒命中;失败 warn 可行动 + 恒 resolve []);
19
- * - 顶层 await 加载 → 填回 serverModule.skills 声明式通道(装配端 registerAll 自动注册);
20
- * - 前置:本包 exports 须含 "./package.json"(见 package.json);
21
- * - 生成应用内(codegen 展开)调用名由 CLI 自动改写为 @app/<id>,源码按字面量包名写法。
22
- */
23
- const skills = Object.fromEntries(
24
- (await loadModuleSkills('@app/module-weather', import.meta.url)).map((s) => [s.name, s]),
25
- ) satisfies Record<string, LocalSkill>;
26
-
27
- /**
28
- * 模块前置工具声明(010:key 约定 = toolId,纯数据 + 一个 resolve 函数)。
29
- * 装配端 registerServerModules 自动注册(register 内无需代码)。
30
- */
31
- const preTools = {
32
- getWeather: weatherPreTool,
33
- } as const;
34
-
35
- /** 模块注册入口:自注册闭环(与客户端 clientModule 对称) */
36
- export const serverModule = {
37
- cards,
38
- skills,
39
- preTools,
40
- declaration: { moduleId: 'weather' },
41
- register(ctx: ServerContext): void {
42
- ctx.tools.register(weatherTool);
43
- ctx.cards.registerMap(cards);
44
- },
45
- } satisfies ServerModule;
@@ -1,20 +0,0 @@
1
- import { definePreTool } from '@tbox.cn/app-sdk/server';
2
- import { weatherTool } from './tool';
3
-
4
- /**
5
- * 前置工具声明(010):getWeather 的 city 参数可工程化抽取(城市词表),
6
- * 无需模型抽参——词表命中即预执行,模型第一轮直接作答(省一轮 loop)。
7
- *
8
- * 演示形态:文本工程化抽取——决策即构造:
9
- * 抽到城市 → { decision: 'run', args: { city } }(预执行,args 强类型由 tool 推断);
10
- * 抽不到 → { decision: 'skip' }(本轮不生效,模型正常调用工具)。
11
- */
12
- const CITIES = ['北京', '上海', '广州', '深圳', '杭州', '成都', '武汉', '西安', '南京', '重庆'];
13
-
14
- export const weatherPreTool = definePreTool(weatherTool, {
15
- routing: { mode: 'keywords', terms: ['天气', '气温', '下雨', '下雪', '穿衣', '出行'] },
16
- decide: ({ text }) => {
17
- const city = CITIES.find((c) => text.includes(c));
18
- return city ? { decision: 'run', args: { city } } : { decision: 'skip' };
19
- },
20
- });
@@ -1,29 +0,0 @@
1
- import { createTool, withCardEmissionHint } from '@tbox.cn/app-sdk/server';
2
- import { z } from 'zod';
3
-
4
- /**
5
- * 天气查询工具 — 示例(v2 出卡协议:出参 cards 字段)
6
- * 顶层 = 答话事实(模型作答依据);cards = 出卡声明(平台 capture 注入候选池并剥离 data,
7
- * 模型可见 descriptor {id, cardType, note},正文末尾逐字引用当前 descriptor 的 id 决策出卡。
8
- * W2(2026-09-01):withCardEmissionHint 预告知——description 注明「返回可展示卡片」。
9
- * W7:note = 主体+关键事实(城市/天气/温度),模型可据此转述要点。
10
- */
11
- export const weatherTool = withCardEmissionHint(
12
- createTool({
13
- id: 'getWeather',
14
- description: '查询城市天气信息',
15
- inputSchema: z.object({
16
- city: z.string().describe('城市名称,如 北京、上海'),
17
- }),
18
- execute: async ({ city }) => {
19
- const mockData: Record<string, { temp: number; weather: string; humidity: number }> = {
20
- 北京: { temp: 22, weather: '晴', humidity: 35 },
21
- 上海: { temp: 25, weather: '多云', humidity: 65 },
22
- 广州: { temp: 30, weather: '阵雨', humidity: 80 },
23
- 深圳: { temp: 29, weather: '多云', humidity: 75 },
24
- };
25
- const data = { city, ...(mockData[city] || { temp: 20, weather: '未知', humidity: 50 }) };
26
- return { ...data, cards: [{ cardType: 'weather', data, note: `${city} ${data.weather} ${data.temp}℃` }] };
27
- },
28
- }),
29
- );
@@ -1,27 +0,0 @@
1
- {
2
- "schemaVersion": 1,
3
- "name": "module-weather",
4
- "version": "0.1.0",
5
- "kind": "business",
6
- "risk": {
7
- "level": "low",
8
- "writeBoundary": "source"
9
- },
10
- "distribution": {
11
- "defaultMode": "codegen"
12
- },
13
- "contributes": {
14
- "handlers": [],
15
- "tools": ["getWeather"],
16
- "cards": [
17
- { "cardType": "weather", "schemaVersion": 1 }
18
- ],
19
- "routes": [],
20
- "pages": [],
21
- "tabs": []
22
- },
23
- "dependencies": {
24
- "modules": []
25
- },
26
- "env": []
27
- }
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "baseUrl": ".",
5
- "jsx": "react-jsx",
6
- "paths": {
7
- "@tbox.cn/app-contracts": ["../contracts/src/index.ts"],
8
- "@tbox.cn/app-contracts/*": ["../contracts/src/*"],
9
- "@tbox.cn/app-sdk/server": ["../app-sdk/src/server/index.ts"],
10
- "@tbox.cn/app-sdk/client": ["../app-sdk/src/client/index.ts"]
11
- }
12
- },
13
- "include": ["src"]
14
- }