@tbox.cn/app-template-agent 0.10.30 → 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/.tbox/app.json +3 -19
- package/.tbox/default-modules.json +4 -1
- package/.tbox/miniapp-containers.json +1 -1
- package/AGENTS.md +52 -148
- package/README.md +10 -8
- package/apps/AGENTS.md +13 -0
- package/apps/client/.tbox-gen/app-kind.ts +1 -0
- package/apps/client/.tbox-gen/documents/_tbox/card-preview.html +38 -0
- package/apps/client/.tbox-gen/documents/index.html +39 -0
- package/apps/client/.tbox-gen/entries/card-preview.tsx +18 -0
- package/apps/client/.tbox-gen/entries/index.tsx +18 -0
- package/apps/client/.tbox-gen/manifest.json +17 -0
- package/apps/client/.tbox-gen/registry.client.ts +6 -0
- package/apps/client/.tbox-gen/registry.server.ts +15 -0
- package/apps/client/index.html +1 -1
- package/apps/client/package.json +3 -2
- package/apps/client/src/cards/registry.ts +6 -19
- package/apps/client/src/pages/page.tsx +11 -0
- package/apps/client/src/platform/AgentChatApp.tsx +2 -10
- package/apps/client/src/platform/card-preview-page.tsx +3 -5
- package/apps/client/src/platform/mount-page.tsx +9 -14
- package/apps/client/vite.config.ts +3 -32
- package/apps/server/package.json +1 -1
- package/apps/server/src/app.ts +7 -14
- package/apps/server/src/cli/collect-registry.ts +7 -11
- package/apps/server/src/dev.ts +38 -64
- package/apps/server/src/index.ts +27 -45
- package/apps/server/src/pre-tools.ts +1 -1
- package/apps/server/src/tools/{clock.ts → clock.tool.ts} +1 -1
- package/apps/server/src/tools/{translate.ts → translate.tool.ts} +1 -1
- package/apps/server/tests/cards-registry.test.ts +1 -1
- package/apps/server/tests/helpers/register.ts +10 -0
- package/apps/server/tests/tool-runtime.test.ts +2 -2
- package/apps/server/tsconfig.json +1 -1
- package/apps/server/tsup.config.ts +6 -3
- package/{packages → modules}/provider-custom/AGENTS.md +1 -1
- package/modules/provider-custom/INTEGRATION.md +10 -0
- package/{packages → modules}/provider-custom/package.json +1 -0
- package/package.json +11 -6
- package/packages/agent-ui-kit/package.json +1 -1
- package/packages/shared/AGENTS.md +11 -0
- package/packages/shared/package.json +13 -0
- package/packages/shared/src/index.ts +8 -0
- package/packages/shared/tsconfig.json +7 -0
- package/pnpm-lock.template.yaml +183 -155
- package/pnpm-workspace.template.yaml +10 -8
- package/scripts/generate.mjs +3 -0
- package/scripts/verify-generated.mjs +22 -127
- package/apps/client/src/app.tsx +0 -11
- package/apps/client/src/business/App.tsx +0 -11
- package/apps/client/src/business/README.md +0 -99
- package/apps/client/src/business/routes.json +0 -3
- package/apps/client/src/main.tsx +0 -17
- package/apps/client/src/modules.ts +0 -33
- package/apps/server/src/app-tools.ts +0 -14
- package/apps/server/src/modules.ts +0 -38
- /package/{packages → modules}/provider-custom/LICENSE +0 -0
- /package/{packages → modules}/provider-custom/README.md +0 -0
- /package/{packages → modules}/provider-custom/src/index.ts +0 -0
- /package/{packages → modules}/provider-custom/src/server/example-adapter.ts +0 -0
- /package/{packages → modules}/provider-custom/src/server/index.ts +0 -0
- /package/{packages → modules}/provider-custom/tbox.module.json +0 -0
- /package/{packages → modules}/provider-custom/tests/provider-custom.test.ts +0 -0
- /package/{packages → modules}/provider-custom/tsconfig.json +0 -0
- /package/{packages → modules}/provider-custom/tsup.config.ts +0 -0
package/.tbox/app.json
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
|
|
5
|
-
"id": "provider-custom",
|
|
6
|
-
"package": "@tbox.cn/app-provider-custom",
|
|
7
|
-
"version": "0.1.0",
|
|
8
|
-
"mode": "codegen",
|
|
9
|
-
"baseVersion": "0.1.0"
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
"id": "agent-ui-kit",
|
|
13
|
-
"package": "@tbox.cn/app-agent-ui-kit",
|
|
14
|
-
"version": "0.1.1",
|
|
15
|
-
"mode": "codegen",
|
|
16
|
-
"baseVersion": "0.1.1",
|
|
17
|
-
"kind": "ui-kit"
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
"miniappContainers": []
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"appKind": "agent",
|
|
4
|
+
"templateVersion": "1.0.0-alpha.1"
|
|
21
5
|
}
|
package/AGENTS.md
CHANGED
|
@@ -1,171 +1,75 @@
|
|
|
1
1
|
# AGENTS.md
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
本应用是 tbox-app 1.0 多包 workspace:`apps/` 是唯一运行入口,`packages/` 放库与共享 DTO,`modules/` 放运行时模块。客户端同时运行在浏览器和支付宝小程序 web-view 壳中。
|
|
4
4
|
|
|
5
5
|
## 工程结构
|
|
6
6
|
|
|
7
|
-
|
|
|
7
|
+
| 路径 | 职责 |
|
|
8
8
|
|---|---|
|
|
9
|
-
| `apps/
|
|
10
|
-
| `apps/
|
|
11
|
-
| `packages
|
|
12
|
-
| `
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
| `apps/client` | React/Vite 页面、平台运行时、聊天壳与卡片渲染 |
|
|
10
|
+
| `apps/server` | Express + WebSocket、agent engine、TTS、上传/ASR、auth、会话 |
|
|
11
|
+
| `packages/shared` | 跨端 DTO,包名 `@app/shared`,只放纯类型与常量 |
|
|
12
|
+
| `packages/agent-ui-kit` | 对话 UI 组件库(普通 workspace 包,不是模块) |
|
|
13
|
+
| `packages/contracts-mall` | 商圈领域契约 shim |
|
|
14
|
+
| `modules/*` | 运行时模块;必须有 `tbox.module.json` |
|
|
15
|
+
| `config/` | app 配置面(chat/agent/integrations/plugins/llm_provider) |
|
|
16
|
+
| `profiles/` | 创建期画像(`--profile mall`);应用运行时不读取 |
|
|
17
|
+
|
|
18
|
+
## 启动链
|
|
19
|
+
|
|
20
|
+
- 页面:`apps/client/src/pages/page.tsx`,inline `export const page`;入口脚本由 app-build 生成。
|
|
21
|
+
- 函数:`apps/server/src/functions/*.server.ts`,文件名即 `/api/fn/<id>`。
|
|
22
|
+
- 工具/技能/卡片:`apps/server/src/tools/*.tool.ts`、`skills/*.skill.ts`、`cards/*.card.ts`;卡片客户端成对 `apps/client/src/cards/*.card.tsx`。
|
|
23
|
+
- 模块:`modules/<id>/src/server/index.ts` 导出 `serverModule`,`src/client/index.ts` 导出 `clientModule`;只注册,不在顶层解析服务。
|
|
24
|
+
- 双端 registry 与 manifest 由 `tboxApp generate` 生成,不要手写 `.tbox-gen`。
|
|
25
|
+
- 生产只启动 `apps/server/dist/index.js`;静态根是 `apps/client/dist`。
|
|
26
|
+
|
|
27
|
+
## 共享 DTO
|
|
28
|
+
|
|
29
|
+
`packages/shared` 是唯一跨端 DTO 包:
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import type { ApiResult, ApiError } from '@app/shared';
|
|
33
|
+
```
|
|
15
34
|
|
|
16
|
-
|
|
35
|
+
只放纯类型/常量;不 import React、Node、`apps/*`、`modules/*`、数据库或网络。不要创建 `apps/shared/`。
|
|
17
36
|
|
|
18
|
-
|
|
19
|
-
`register` 内经 `ctx.tools/cards.registerMap/handlers/routes/services/bus` 自注册;只注册不解析(resolveService 仅 handle/事件回调内)。
|
|
20
|
-
- client 入口 `src/client/index.ts`:`export const clientModule = { cards, register(ctx) {...} } satisfies ClientModule`;
|
|
21
|
-
`register` 内经 `ctx.cards.registerMap(cards)` 注册卡片组件。
|
|
22
|
-
- `cards` map 的 **key 约定 = meta.cardType**(server 端 meta 的 cardType;doctor 会校验),无卡片模块写 `cards: {}`;
|
|
23
|
-
模块对象必须用 `satisfies`(不能 `: ServerModule` 标注——标注会把 cards 泛化导致类型推导失效)。
|
|
24
|
-
- 每个模块根目录有 `tbox.module.json`(schema v1)声明 `declare`(tools/cards/handlers/routes/pages/tabs + `owns`/`consumes` 服务面)。
|
|
25
|
-
跨模块写操作走 `ctx.services.register/resolve` + 类型化事件总线,业务代码只 import `@tbox.cn/app-contracts`(或领域契约包),不 import `apps/*`。
|
|
37
|
+
## 模块
|
|
26
38
|
|
|
27
|
-
|
|
39
|
+
模块是双端单包,必须用 `satisfies`:
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
| `apps/client/src/modules.ts` | 客户端模块装配(与 server 端逐行同构) |
|
|
33
|
-
|
|
34
|
-
装配文件含锚点区(`@tbox:imports-begin/end` + `@tbox:register-begin/end`,由 tbox CLI 增量维护,保留非标行)和自由区(可手动编辑)。
|
|
35
|
-
`CardType` 从装配数组自动推导(`InferModuleCards`):增删模块后两端 `CardType` 自动收缩/扩展,`CardOverrides` 等消费方随之编译报错。
|
|
36
|
-
客户端注册表快照在 `apps/client/src/cards/registry.ts`(createClientContext + registerAll → `ctx.cards.getAll()`)。
|
|
37
|
-
|
|
38
|
-
> **模块与 app 版本配套**:双端模块描述对象为破坏性变更——新模块(serverModule/clientModule 形态)需新版 app(含对应 CLI)装配;
|
|
39
|
-
> 老形态模块(registerServer 函数)add 到新版 app 会跳过装配并告警(需升级模块)。
|
|
40
|
-
|
|
41
|
-
## 关键入口
|
|
42
|
-
|
|
43
|
-
```text
|
|
44
|
-
apps/client/src/main.tsx # 客户端根入口(启动层 = platform/bootstrap)
|
|
45
|
-
apps/client/src/business/routes.json # 页面清单(MPA 文档模式唯一真源;删除 = 单页 legacy)
|
|
46
|
-
apps/client/src/business/App.tsx # 业务应用入口
|
|
47
|
-
apps/client/src/platform/AgentChatApp.tsx # 默认对话运行时
|
|
48
|
-
apps/client/src/modules.ts # 客户端模块装配(与 server 端同构)
|
|
49
|
-
apps/client/src/cards/registry.ts # 卡片注册表快照(CardType → CardComponent)
|
|
50
|
-
apps/server/src/index.ts # 服务端入口(静态产物 HTTP + WS;vite dev 链 = src/dev.ts)
|
|
51
|
-
apps/server/src/modules.ts # 服务端模块装配(registerAll)
|
|
52
|
-
apps/server/src/module-ports.ts # 模块 ports 动态装配(LinkedPanel/bumpin 数据源;契约派生 + 漂移守卫)
|
|
53
|
-
packages/provider-custom/src/server/index.ts # 自定义 API adapter 实施落点(指引:npx --yes @tbox.cn/app-cli skills get provider-custom)
|
|
54
|
-
config/ # 应用配置面(integrations/chat/agent 等,见 config/README.md)
|
|
41
|
+
```ts
|
|
42
|
+
export const serverModule = { cards: {}, register(ctx) {} } satisfies ServerModule;
|
|
43
|
+
export const clientModule = { cards: {}, register(ctx) {} } satisfies ClientModule;
|
|
55
44
|
```
|
|
56
45
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
验证走三级回路,按改动面选最小充分集:
|
|
46
|
+
- `cards` 的 key 必须等于 meta.cardType。
|
|
47
|
+
- 跨模块交互走 `ctx.services` / 事件总线;不 import 其他模块源码。
|
|
48
|
+
- 模块在 v1 目录 `modules/<id>`,本地模块可无 package.json;vendored 模块带 package.json。
|
|
49
|
+
- 安装/删除模块统一走 `npx --yes @tbox.cn/app-cli module add|remove`,不要手改 registry。
|
|
62
50
|
|
|
63
|
-
|
|
64
|
-
|---|---|---|
|
|
65
|
-
| 代码(类型/契约) | 静态 | `pnpm typecheck`(单模块 `pnpm --filter <pkg> typecheck` 秒级) |
|
|
66
|
-
| 集成/配置/新增模块 | 一次性运行时 | `pnpm smoke`(boot + browser 登录 + `/api/auth/me`,随机端口) |
|
|
67
|
-
| 看运行效果 | 8000 活体 | `curl -s http://127.0.0.1:8000/api/health` |
|
|
68
|
-
|
|
69
|
-
- **编译验证 = typecheck + smoke**;`pnpm smoke` 失败时先读尾部日志(fail-soft 配置降级在此可见)。
|
|
70
|
-
- **不要运行 `pnpm build` / `pnpm verify`**:冷构建超过沙箱命令时限(必超时),且 dev/smoke 不消费 `dist`;产物构建归平台生命周期脚本。
|
|
71
|
-
- `pnpm verify:fast` = typecheck + test + verify:generated + check(提交前静态收口)。
|
|
72
|
-
- `curl` 连接被拒绝 ≠ 应用损坏:平台在轮末自启服务,8000 空窗属正常态。
|
|
73
|
-
- 长驻进程纪律:不要用 `&`/`nohup` 方式自行拉起 server;一次性验证只允许 `pnpm smoke`(自带进程组清理)。
|
|
51
|
+
## 命令
|
|
74
52
|
|
|
75
53
|
```sh
|
|
76
|
-
pnpm
|
|
54
|
+
pnpm generate # 生成 manifest/registry/entries
|
|
55
|
+
pnpm check # 结构、workspace、inspector
|
|
77
56
|
pnpm typecheck
|
|
78
57
|
pnpm test
|
|
79
|
-
pnpm
|
|
80
|
-
pnpm
|
|
81
|
-
pnpm
|
|
82
|
-
pnpm
|
|
83
|
-
pnpm plugin:inspect <pluginId> <toolId>
|
|
58
|
+
pnpm dev # 单端口 8000(Vite + server)
|
|
59
|
+
pnpm build
|
|
60
|
+
pnpm smoke
|
|
61
|
+
pnpm verify:generated
|
|
84
62
|
```
|
|
85
63
|
|
|
86
|
-
环境变量与配置面(`config/`)见 `ENV.md`。
|
|
87
|
-
|
|
88
|
-
## tbox-app CLI(模块与装配管理)
|
|
89
|
-
|
|
90
|
-
CLI 免安装,命令一律以 `npx --yes @tbox.cn/app-cli <cmd>` 运行(完整命令面加 `--help`)。
|
|
91
|
-
add/remove/sync 后需 `pnpm install`:
|
|
92
|
-
|
|
93
|
-
| 命令 | 用途 |
|
|
94
|
-
|---|---|
|
|
95
|
-
| `module add <pkg> --mode codegen --source <pkg\|路径\|tgz>` | 安装模块(codegen 展开 / local 本地目录 / sdk registry 安装) |
|
|
96
|
-
| `module remove <id>` | 卸载模块(见「删除模块」) |
|
|
97
|
-
| `module list` / `sync` / `diff` / `doctor` | 已装清单 / 增量装配 / 漂移对比 / 结构校验 |
|
|
98
|
-
| `module update <module>` | 升级模块(codegen → 3-way merge) |
|
|
99
|
-
| `module inspect [id]` | 能力/服务绑定矩阵(`--json` 机器可读) |
|
|
100
|
-
| `new <module\|provider\|theme> <name>` | 应用内脚手架(生成 `packages/<id>` 并完成装配) |
|
|
101
|
-
| `provider use / bind / unbind / unuse` | 集成绑定(写 `config/integrations.json`;v8 起自定义 API 统一 `provider-custom` 字符串厂商——CLI 全覆盖三层,含 `--module` 模块级单点绑定;bind/use 整槽覆盖既有 provider) |
|
|
102
|
-
| `provider use <p> --activate` | 应用默认厂商 + 该厂商供给面槽位批量激活(`*.snapshot` 聚合槽除外) |
|
|
103
|
-
| `skills list` / `skills get <topic>` | 流程知识(integration / provider-custom / verify / miniapp-container) |
|
|
104
|
-
| `schema [file]` | 配置形状(`config/integrations.json` / `tbox.module.json`) |
|
|
105
|
-
| `theme use <id>` / `theme list` | 主题接线 / 状态 |
|
|
106
|
-
| `starter --list` / `starter --type <type>` | starter 文档查询(商圈模块清单见 `--type agent-mall`) |
|
|
107
|
-
|
|
108
64
|
## 自定义服务集成(provider-custom)
|
|
109
65
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
`npx --yes @tbox.cn/app-cli skills get integration` 读取完整流程、任务路由与接入材料清单
|
|
113
|
-
规范,再动手**。本节不再展开(指引真源 = CLI skills,勿在本节扩展)。
|
|
114
|
-
|
|
115
|
-
## 删除模块
|
|
116
|
-
|
|
117
|
-
模块装卸一律走 CLI——不要手动删 `packages/<id>` 目录或改装配锚点区:
|
|
118
|
-
|
|
119
|
-
```sh
|
|
120
|
-
npx --yes @tbox.cn/app-cli module list # 确认模块 id(= packages/ 目录名)
|
|
121
|
-
npx --yes @tbox.cn/app-cli module remove <id>
|
|
122
|
-
pnpm install
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
- `remove` 自动完成:删包(或恢复 `contracts-mall` SDK shim)+ 清锚点装配 + 清理集成绑定
|
|
126
|
-
死项 + doctor 复查。
|
|
127
|
-
- 被其他模块 required 依赖时会阻止并列出依赖方:先删依赖方;`--force` 仅确认知情时使用。
|
|
128
|
-
- 删除后跑 `pnpm typecheck`:`CardType` 随装配自动收缩,残留消费方会编译报错——按报错
|
|
129
|
-
清理引用后 `pnpm verify:fast` 收尾。
|
|
130
|
-
- 提示「contracts-mall 已无依赖者」时可再 `module remove contracts-mall` 恢复 SDK shim。
|
|
131
|
-
|
|
132
|
-
## 平台基础设施
|
|
133
|
-
|
|
134
|
-
以下链路受保护,不得删除或绕过(守卫随 `@tbox.cn/app-sdk` 分发:`pnpm check:inspector` / `tbox-inspector-check`,已入 `pnpm check` 静态门禁):
|
|
135
|
-
|
|
136
|
-
- `@tbox.cn/app-sdk/platform` 的 `installInspector`(`@infrastructure-locked`;`apps/server/src/index.ts` 从 `@tbox.cn/app-sdk/platform` import 并调用 `installInspector(app)`)
|
|
137
|
-
- `apps/client/index.html` 中的 `/__vs_inspector__.js`(`RUNTIME_PATH` 约定不变)
|
|
138
|
-
- `apps/client/babel-plugins/code-inspect.cjs` + `apps/client/vite.config.ts` 中 code-inspect plugin 接入
|
|
139
|
-
- 单端口 8000(dev 和生产统一)
|
|
140
|
-
- 生产环境由 server serve `apps/client/dist`
|
|
141
|
-
|
|
142
|
-
## 双运行时与插件
|
|
143
|
-
|
|
144
|
-
- 原生能力统一走 `@tbox.cn/app-sdk/client` 的 `createPlatformAdapters()`(ASR/TTS/upload/feedback);业务/UI 不直接判断支付宝壳。
|
|
145
|
-
- API/WS 地址由 `@tbox.cn/app-sdk/client` 的 `configureRuntime({ apiBaseUrl })` 注入(`platform/bootstrap.ts`),不得硬编码 host;不直接读 `import.meta.env` 之外的环境。
|
|
146
|
-
- **不直接 import `@tbox-dev-js/sdk`(全禁)**——平台能力(auth/会话/TTS/LLM/插件/能力适配器/协议客户端)一律经 `@tbox.cn/app-sdk` 公开 API。
|
|
147
|
-
- 平台"插件"页添加插件时只改 `config/plugins.json`。应用代码不复制插件鉴权、参数注入、runtime ID 或 SDK 客户端。
|
|
148
|
-
- 插件结果出卡时按 `@tbox.cn/app-contracts` 的 cards schema 注册,在模块包内注册 adapter 和 client 组件。
|
|
149
|
-
|
|
150
|
-
## web-view 样式约定
|
|
151
|
-
|
|
152
|
-
客户端同时跑浏览器与支付宝小程序 web-view 壳(组件挂载于 H5 视口,非小程序原生渲染),样式遵守:
|
|
153
|
-
|
|
154
|
-
0. **视觉体系 = mall-vis 蓝系**(换肤面四级级联;域色矩阵 member 金 · parking 藏蓝 · sg 蓝 · promotion 红/UI 模式);视觉值只住 kit tokens / 模块域变量块 / 素材变量消费三层(品牌视觉经主题包覆写——出厂接线 `@tbox.cn/app-theme-tbox` 三行,见 `apps/client/src/platform/bootstrap.ts`),平台 token 名字零增减。
|
|
155
|
-
1. **长度单位 PX 大写**(如 `800PX`)——postcss-pxtorem 大小写敏感转义:小写 `px` 按设计稿换算 rem(750 稿 2x),需要固定屏幕像素不随 rem 缩放的值用大写 `PX`(转换器跳过,详见 `apps/client/STYLE_GUIDE.md`)。
|
|
156
|
-
2. **flex 子项设 `flex-shrink: 0`**——壳内内容宽度不定,防元素被压缩变形。
|
|
157
|
-
3. **滚动容器隐藏滚动条**(`::-webkit-scrollbar { display: none }`)——web-view 无原生滚动条,出现即破相。
|
|
158
|
-
4. **颜色用 `rgba()` 传统语法**——避免 `color-mix`/`oklch` 等新语法在低版本 web-view 内核不渲染。
|
|
159
|
-
|
|
160
|
-
## 工程边界(check-workspace 校验)
|
|
161
|
-
|
|
162
|
-
- `packages/*` 业务包必须有 `tbox.module.json`;SDK/契约(`app-sdk` / `contracts*` / `shared`)豁免。
|
|
163
|
-
- `scripts/` 下所有文件保持可执行位(git 100755;CLI create 后 chmod 兜底)。
|
|
164
|
-
- 装配文件不得裸 import(全部 import 行在锚区内);模块包不得 import SDK/契约内部路径(仅公开入口 `@tbox.cn/app-sdk{/server,/client,/platform}` 与 `@tbox.cn/app-contracts`)。
|
|
165
|
-
- 构建序列单源 = 根 `build` / `build:client` script;`scripts/build.sh` 只管环境 + install + 委托(平台调用)。
|
|
66
|
+
对接自定义 API 时先读 CLI 流程知识:`npx --yes @tbox.cn/app-cli skills get integration`。
|
|
67
|
+
实施落点 = `modules/provider-custom/`;不要把它当普通 packages 依赖或第二套 HTTP 客户端。
|
|
166
68
|
|
|
167
|
-
##
|
|
69
|
+
## 能力边界
|
|
168
70
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
71
|
+
- 保留:对话/WS、auth、TTS/语音、上传/ASR、工具/技能/卡片、AI 支付、provider/integrations、plugins、长期记忆、mall profile、agent-ui-kit。
|
|
72
|
+
- 平台包只从公开入口 import;禁止直接 import `@tbox-dev-js/sdk`。
|
|
73
|
+
- 平台 inspector 链路不得删除或绕过:`installInspector`、`/__vs_inspector__.js`、code-inspect 插件。
|
|
74
|
+
- 生产:`NODE_ENV=production` + 平台注入 `AUTH_TOKEN_SECRET`;生产静态页由 `apps/client/dist` 供给。
|
|
75
|
+
- 不要创建 `app/`、`apps/client/src/modules.ts`、`apps/server/src/modules.ts`、`routes.json`。
|
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# template-agent
|
|
2
2
|
|
|
3
|
-
tbox AI Agent 全栈模板(npm 包名 `@tbox.cn/app-template-agent`,唯一模板——W4 单一模板统一化),多包 pnpm workspace:`apps/`
|
|
3
|
+
tbox AI Agent 全栈模板(npm 包名 `@tbox.cn/app-template-agent`,唯一模板——W4 单一模板统一化),多包 pnpm workspace:`apps/` 运行入口 + `packages/` 库/DTO + `modules/` 运行时模块。
|
|
4
4
|
缺省出厂 = 带 AI 支付体验的 chat 形态;**商圈形态经 `profiles/mall` 画像加装**(`npx --yes @tbox.cn/app-cli create --profile mall`:mall-core + 七业务模块 + 商圈配置叠加)。
|
|
5
5
|
客户端同时支持浏览器和支付宝小程序 web-view;平台能力(鉴权/会话/TTS/ASR/上传/反馈)经 `@tbox.cn/app-sdk` 统一提供(007 下沉)。
|
|
6
6
|
|
|
7
|
-
创建应用时按 `.tbox/default-modules.json` 加装 AI 支付模块,源码落在 `
|
|
7
|
+
创建应用时按 `.tbox/default-modules.json` 加装 AI 支付模块,源码落在 `modules/module-ai-payment`。
|
|
8
8
|
|
|
9
|
-
创建应用时默认使用 `@tbox.cn/app-miniapp-container-alipay@0.
|
|
9
|
+
创建应用时默认使用 `@tbox.cn/app-miniapp-container-alipay@1.0.0-alpha.1` 生成 `apps/miniapp-container-alipay`,容器计划见 `.tbox/miniapp-containers.json`。使用前配置小程序 AppId 和 H5 地址;重复创建保留已登记的容器。
|
|
10
10
|
|
|
11
11
|
`pnpm dev` 仅启动 H5/server(express :8000 = /api + /ws + 页面 + HMR);带支付宝小程序壳用 `pnpm dev-alipay`(同时启动 server 与 minidev 容器;容器或 minidev 缺席时报错退出并附修复指引,不静默降级)。容器异常退出不影响 H5/server,Ctrl+C 统一停止本次启动的进程。
|
|
12
12
|
|
|
@@ -29,7 +29,7 @@ npx --yes @tbox.cn/app-cli module add parking promotion # 停车/活动(可选
|
|
|
29
29
|
npx --yes @tbox.cn/app-cli module doctor # 30 条结构校验
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
**MallHome 服务域**(015;`--profile mall` 加装 mall-core 后生效):家页 `
|
|
32
|
+
**MallHome 服务域**(015;`--profile mall` 加装 mall-core 后生效):家页 `modules/module-mall-core` 四域开箱——门店导览/会员/活动优惠(promotion)/停车服务(parking);域 query 走工具与意图路由链(模块 add/remove 即增删能力,无部署级门控)。
|
|
33
33
|
|
|
34
34
|
**宿主效果链**(015):支付/支付宝授权效果由 SDK 自动执行(host-effect-runner:壳内拉起收银台/授权、浏览器环境自动降级),结果经补签 grant 回传收口——模板零装配;停车场次/入会 pending 收口均为显式按钮交互。
|
|
35
35
|
|
|
@@ -58,7 +58,9 @@ template-agent/
|
|
|
58
58
|
server/ Express + WS 装配端(~120 行装配:auth 中间件 + 模块挂载 + 平台路由面/TTS/WS)
|
|
59
59
|
server/skills/ 本地 Skill(SKILL.md 目录格式,随模板复制/pack)
|
|
60
60
|
packages/
|
|
61
|
-
|
|
61
|
+
agent-ui-kit / contracts-mall / shared(库、契约、跨端 DTO;不再放运行模块)
|
|
62
|
+
modules/
|
|
63
|
+
运行模块(能力经 `npx --yes @tbox.cn/app-cli module add` 扩展;app-build 扫描生成 registry)
|
|
62
64
|
config/ chat/model/plugin 配置
|
|
63
65
|
scripts/ 构建、检查和平台脚本
|
|
64
66
|
pnpm-workspace.template.yaml 应用 workspace 模板(create 生成应用 pnpm-workspace.yaml 的来源)
|
|
@@ -87,10 +89,10 @@ apps/server/skills/<skill-name>/
|
|
|
87
89
|
|
|
88
90
|
### 模块级 Skill(文件加载)
|
|
89
91
|
|
|
90
|
-
模块包内放 `skills/` 目录(与 `src/` 平级),顶层 await 加载后填回 `serverModule.skills`
|
|
92
|
+
模块包内放 `skills/` 目录(与 `src/` 平级),顶层 await 加载后填回 `serverModule.skills` 声明式通道(app-build 生成的 registry 交给 `registerServerModules` 统一注册,register 内零代码):
|
|
91
93
|
|
|
92
94
|
```text
|
|
93
|
-
|
|
95
|
+
modules/<module-id>/
|
|
94
96
|
├── skills/<skill-name>/
|
|
95
97
|
│ ├── SKILL.md # frontmatter(name/description/metadata.routingTerms)+ SOP
|
|
96
98
|
│ └── references/*.md
|
|
@@ -99,7 +101,7 @@ packages/<module-id>/
|
|
|
99
101
|
```
|
|
100
102
|
|
|
101
103
|
```ts
|
|
102
|
-
//
|
|
104
|
+
// modules/<module-id>/src/server/index.ts
|
|
103
105
|
import { loadModuleSkills } from '@tbox.cn/app-sdk/server';
|
|
104
106
|
|
|
105
107
|
const skills = Object.fromEntries(
|
package/apps/AGENTS.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# 应用代码
|
|
2
|
+
|
|
3
|
+
<!-- tbox:agents:begin -->
|
|
4
|
+
# 应用代码
|
|
5
|
+
|
|
6
|
+
- 页面:`apps/client/src/pages/**/page.tsx`;目录即 URL;inline `export const page`。
|
|
7
|
+
- 函数:`apps/server/src/functions/*.server.ts`;文件名即 `/api/fn/<id>`。
|
|
8
|
+
- 工具/技能/卡片:`apps/server/src/{tools,skills,cards}`;卡片与 `apps/client/src/cards` 成对。
|
|
9
|
+
- 共享 DTO:`packages/shared/`,导入 `@app/shared`。
|
|
10
|
+
- 模块:`modules/<id>/`,必须有 `tbox.module.json`。
|
|
11
|
+
- 构建产物:`apps/client/dist`(部署静态根)、`apps/server/dist`。
|
|
12
|
+
- 不要创建 `app/`、`modules.ts`、`routes.json`、`apps/shared/`;不要手写 `.tbox-gen`。
|
|
13
|
+
<!-- tbox:agents:end -->
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const appKind = 'agent' as const;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<!-- 移动端视口;缩放锁定,配合 postcss-pxtorem 的 750→rem 换算 -->
|
|
6
|
+
<meta
|
|
7
|
+
name="viewport"
|
|
8
|
+
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
|
|
9
|
+
/>
|
|
10
|
+
<meta name="theme-color" content="#fbfcfe" />
|
|
11
|
+
<!-- rem 弹性根字号(对齐原模板 hd.ts:threshold 450 / designWidth 750)。
|
|
12
|
+
在 CSS 前同步执行,避免首屏字号闪动。
|
|
13
|
+
- 移动端(clientWidth<=450):动态 (100/750)*clientWidth;
|
|
14
|
+
- PC(clientWidth>450):固定 50px(页面不随窗口缩放,内容 800px 居中、渐变底铺满)。 -->
|
|
15
|
+
<script>
|
|
16
|
+
(function () {
|
|
17
|
+
var THRESHOLD = 450,
|
|
18
|
+
DESIGN = 750;
|
|
19
|
+
function setRootFontSize() {
|
|
20
|
+
var w = document.documentElement.clientWidth;
|
|
21
|
+
document.documentElement.style.fontSize =
|
|
22
|
+
(w > THRESHOLD ? 50 : (100 / DESIGN) * w) + 'px';
|
|
23
|
+
}
|
|
24
|
+
setRootFontSize();
|
|
25
|
+
window.addEventListener('resize', setRootFontSize);
|
|
26
|
+
window.addEventListener('orientationchange', setRootFontSize);
|
|
27
|
+
})();
|
|
28
|
+
</script>
|
|
29
|
+
<!-- 出厂标题 = 此处静态值(theme-tbox brand.js 出厂不覆写标题);租户主题经其 brand.js 运行时覆写 document.title -->
|
|
30
|
+
<title>卡片预览</title>
|
|
31
|
+
<!-- 平台微调(inspector) runtime:由 server 提供 GET /__vs_inspector__.js;dev 下经 Vite 代理到 server。-->
|
|
32
|
+
|
|
33
|
+
</head>
|
|
34
|
+
<body>
|
|
35
|
+
<div id="root"></div>
|
|
36
|
+
<script type="module" src="/.tbox-gen/entries/card-preview.tsx"></script>
|
|
37
|
+
</body>
|
|
38
|
+
</html>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<!-- 移动端视口;缩放锁定,配合 postcss-pxtorem 的 750→rem 换算 -->
|
|
6
|
+
<meta
|
|
7
|
+
name="viewport"
|
|
8
|
+
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
|
|
9
|
+
/>
|
|
10
|
+
<meta name="theme-color" content="#fbfcfe" />
|
|
11
|
+
<!-- rem 弹性根字号(对齐原模板 hd.ts:threshold 450 / designWidth 750)。
|
|
12
|
+
在 CSS 前同步执行,避免首屏字号闪动。
|
|
13
|
+
- 移动端(clientWidth<=450):动态 (100/750)*clientWidth;
|
|
14
|
+
- PC(clientWidth>450):固定 50px(页面不随窗口缩放,内容 800px 居中、渐变底铺满)。 -->
|
|
15
|
+
<script>
|
|
16
|
+
(function () {
|
|
17
|
+
var THRESHOLD = 450,
|
|
18
|
+
DESIGN = 750;
|
|
19
|
+
function setRootFontSize() {
|
|
20
|
+
var w = document.documentElement.clientWidth;
|
|
21
|
+
document.documentElement.style.fontSize =
|
|
22
|
+
(w > THRESHOLD ? 50 : (100 / DESIGN) * w) + 'px';
|
|
23
|
+
}
|
|
24
|
+
setRootFontSize();
|
|
25
|
+
window.addEventListener('resize', setRootFontSize);
|
|
26
|
+
window.addEventListener('orientationchange', setRootFontSize);
|
|
27
|
+
})();
|
|
28
|
+
</script>
|
|
29
|
+
<!-- 出厂标题 = 此处静态值(theme-tbox brand.js 出厂不覆写标题);租户主题经其 brand.js 运行时覆写 document.title -->
|
|
30
|
+
<title>AI 助手</title>
|
|
31
|
+
<!-- 平台微调(inspector) runtime:由 server 提供 GET /__vs_inspector__.js;dev 下经 Vite 代理到 server。-->
|
|
32
|
+
|
|
33
|
+
<meta name="description" content="tbox AI Agent 应用" />
|
|
34
|
+
</head>
|
|
35
|
+
<body>
|
|
36
|
+
<div id="root"></div>
|
|
37
|
+
<script type="module" src="/.tbox-gen/entries/index.tsx"></script>
|
|
38
|
+
</body>
|
|
39
|
+
</html>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @generated by @tbox.cn/app-build; do not edit.
|
|
2
|
+
import { registerClientModules, registerClientCards } from '@tbox.cn/app-sdk-client';
|
|
3
|
+
import { modules, cards } from '../registry.client.ts';
|
|
4
|
+
import { mountPage } from '../../src/platform/mount-page.tsx';
|
|
5
|
+
|
|
6
|
+
registerClientCards(cards);
|
|
7
|
+
|
|
8
|
+
async function start() {
|
|
9
|
+
try {
|
|
10
|
+
await registerClientModules(modules);
|
|
11
|
+
const { default: Page } = await import('../../src/platform/card-preview-page.tsx');
|
|
12
|
+
mountPage(Page, { shell: false });
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error('[app-build] page bootstrap failed', error);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
void start();
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// @generated by @tbox.cn/app-build; do not edit.
|
|
2
|
+
import { registerClientModules, registerClientCards } from '@tbox.cn/app-sdk-client';
|
|
3
|
+
import { modules, cards } from '../registry.client.ts';
|
|
4
|
+
import { mountPage } from '../../src/platform/mount-page.tsx';
|
|
5
|
+
|
|
6
|
+
registerClientCards(cards);
|
|
7
|
+
|
|
8
|
+
async function start() {
|
|
9
|
+
try {
|
|
10
|
+
await registerClientModules(modules);
|
|
11
|
+
const { default: Page } = await import('../../src/pages/page.tsx');
|
|
12
|
+
mountPage(Page);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.error('[app-build] page bootstrap failed', error);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
void start();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"pages": [
|
|
4
|
+
{
|
|
5
|
+
"path": "/",
|
|
6
|
+
"entry": "/.tbox-gen/entries/index.tsx",
|
|
7
|
+
"document": "index.html",
|
|
8
|
+
"title": "AI 助手"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"path": "/_tbox/card-preview",
|
|
12
|
+
"entry": "/.tbox-gen/entries/card-preview.tsx",
|
|
13
|
+
"document": "_tbox/card-preview.html",
|
|
14
|
+
"title": "卡片预览"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @generated by @tbox.cn/app-build; do not edit.
|
|
2
|
+
import { tool as tool0 } from '../../server/src/tools/clock.tool.ts';
|
|
3
|
+
import { tool as tool1 } from '../../server/src/tools/translate.tool.ts';
|
|
4
|
+
import { serverModule as module0 } from '../../../modules/provider-custom/src/server/index.ts';
|
|
5
|
+
|
|
6
|
+
export const functions = {
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const tools = [tool0, tool1];
|
|
10
|
+
export const skills = [];
|
|
11
|
+
export const cards = {
|
|
12
|
+
};
|
|
13
|
+
export const modules = [module0];
|
|
14
|
+
|
|
15
|
+
export const registry = { functions, tools, skills, cards, modules };
|
package/apps/client/index.html
CHANGED
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
<title>AI 助手</title>
|
|
31
31
|
<!-- 平台微调(inspector) runtime:由 server 提供 GET /__vs_inspector__.js;dev 下经 Vite 代理到 server。-->
|
|
32
32
|
<script src="/__vs_inspector__.js" defer></script>
|
|
33
|
+
|
|
33
34
|
</head>
|
|
34
35
|
<body>
|
|
35
36
|
<div id="root"></div>
|
|
36
|
-
<script type="module" src="/src/main.tsx"></script>
|
|
37
37
|
</body>
|
|
38
38
|
</html>
|
package/apps/client/package.json
CHANGED
|
@@ -11,15 +11,16 @@
|
|
|
11
11
|
"test": "vitest run"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
+
"@app/shared": "file:../../packages/shared",
|
|
14
15
|
"@tbox.cn/app-contracts": "catalog:",
|
|
15
16
|
"@tbox.cn/app-theme-tbox": "catalog:",
|
|
16
17
|
"react": "catalog:",
|
|
17
18
|
"react-dom": "catalog:",
|
|
18
19
|
"zustand": "catalog:",
|
|
19
|
-
"@app/provider-custom": "workspace:*",
|
|
20
20
|
"@app/agent-ui-kit": "workspace:*",
|
|
21
21
|
"@app/contracts-mall": "workspace:*",
|
|
22
|
-
"@tbox.cn/app-agent-sdk-client": "catalog:"
|
|
22
|
+
"@tbox.cn/app-agent-sdk-client": "catalog:",
|
|
23
|
+
"@tbox.cn/app-sdk-client": "catalog:"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@tbox.cn/app-agent-sdk-server": "catalog:",
|
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 卡片注册表 +
|
|
3
|
-
*
|
|
4
|
-
* 卡片注册发生在各模块 clientModule.register(ctx) 内(模块内自注册闭环),
|
|
5
|
-
* 本文件仅消费组装端上下文;CardType 由 apps/client/src/modules.ts 从装配数组自动推导。
|
|
6
|
-
*
|
|
7
|
-
* 薄装配:三通道全经 ctx 读取——
|
|
8
|
-
* - CHAT_REGISTRY = 原始注册 + 覆盖通道(聊天视图;覆盖优先);
|
|
9
|
-
* - CARD_REGISTRY = 原始注册(RawCardRenderer 详情弹层消费);
|
|
10
|
-
* - INLINE_CARD_FILTER = 内联流过滤复合(ChatPage filterInlineCards 注入值);
|
|
11
|
-
* - CLIENT_SLOTS = 槽注册表(home 槽由模块注册)。
|
|
2
|
+
* 卡片注册表 + 客户端组装上下文(模块加载期快照)。
|
|
3
|
+
* 注册由生成 entry 的 registerClientModules 完成;本文件只读取同一 ClientContext。
|
|
12
4
|
*/
|
|
13
5
|
import type { CardComponent, TboxCardPayload } from '@tbox.cn/app-contracts';
|
|
14
|
-
import {
|
|
15
|
-
import { registerAll, type CardType } from '../modules';
|
|
6
|
+
import { getClientContext } from '@tbox.cn/app-agent-sdk-client';
|
|
16
7
|
|
|
17
|
-
|
|
18
|
-
const ctx = createClientContext();
|
|
19
|
-
registerAll(ctx);
|
|
8
|
+
const ctx = getClientContext();
|
|
20
9
|
|
|
21
10
|
/** 运行时卡片注册表(原始形态;由各模块 clientModule.register 填充) */
|
|
22
|
-
export const CARD_REGISTRY = ctx.cards.getAll() as Record<
|
|
11
|
+
export const CARD_REGISTRY = ctx.cards.getAll() as Record<string, CardComponent>;
|
|
23
12
|
|
|
24
13
|
/** 聊天入口 registry:模块注册 + 覆盖通道(同 cardType 覆盖优先) */
|
|
25
14
|
export const CHAT_REGISTRY: Record<string, CardComponent> = {
|
|
@@ -31,7 +20,5 @@ export const CHAT_REGISTRY: Record<string, CardComponent> = {
|
|
|
31
20
|
export const INLINE_CARD_FILTER = (cards: readonly TboxCardPayload[]): TboxCardPayload[] =>
|
|
32
21
|
ctx.cards.applyInlineFilters(cards);
|
|
33
22
|
|
|
34
|
-
/** 客户端槽注册表(home 槽由模块 register
|
|
23
|
+
/** 客户端槽注册表(home 槽由模块 register 注册) */
|
|
35
24
|
export const CLIENT_SLOTS = ctx.slots;
|
|
36
|
-
|
|
37
|
-
export type { CardType } from '../modules';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PageMeta } from '@tbox.cn/app-agent-sdk-client';
|
|
2
|
+
import AgentChatApp from '@/platform/AgentChatApp';
|
|
3
|
+
|
|
4
|
+
export const page = {
|
|
5
|
+
title: 'AI 助手',
|
|
6
|
+
meta: { description: 'tbox AI Agent 应用' },
|
|
7
|
+
} satisfies PageMeta;
|
|
8
|
+
|
|
9
|
+
export default function HomePage() {
|
|
10
|
+
return <AgentChatApp />;
|
|
11
|
+
}
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 平台默认的全栈对话运行时。普通本地应用无需读取或修改。
|
|
3
|
-
* 外壳(session/适配器)抽至 AppShell 共享——MPA 生成 entry 与本入口同一平台能力面。
|
|
4
|
-
*/
|
|
5
1
|
import IndexPage from '@/pages/index/index';
|
|
6
|
-
import { AppShell } from './AppShell';
|
|
7
2
|
|
|
3
|
+
/** 平台默认对话运行时;AppShell 由 mount-page 统一包裹。 */
|
|
8
4
|
export default function AgentChatApp() {
|
|
9
|
-
return
|
|
10
|
-
<AppShell>
|
|
11
|
-
<IndexPage />
|
|
12
|
-
</AppShell>
|
|
13
|
-
);
|
|
5
|
+
return <IndexPage />;
|
|
14
6
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* dev 面经 dev-runtime 平台表分支服务 entry 替换 shell——两面共用同一生成 entry
|
|
4
|
-
* (.tbox-gen/card-preview.ts → mountPage → 本模块,单一装配路径,HMR 完好)。
|
|
2
|
+
* 卡片预览平台页:生成 entry 已注册模块/卡片,这里只读取同一 ClientContext。
|
|
5
3
|
*/
|
|
6
4
|
import { CardPreviewPage } from '@tbox.cn/app-agent-sdk-client/client/card-preview';
|
|
7
|
-
import {
|
|
5
|
+
import { getRegisteredClientCards } from '@tbox.cn/app-agent-sdk-client';
|
|
8
6
|
import { authClient } from '@/platform/agent-runtime';
|
|
9
7
|
|
|
10
8
|
export default function CardPreviewRoute() {
|
|
11
|
-
return <CardPreviewPage registry={
|
|
9
|
+
return <CardPreviewPage registry={getRegisteredClientCards()} authClient={authClient} />;
|
|
12
10
|
}
|