@tbox.cn/app-template-agent 0.10.15 → 0.10.17

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.
@@ -0,0 +1,3 @@
1
+ [
2
+ "@tbox.cn/app-module-ai-payment"
3
+ ]
@@ -0,0 +1,6 @@
1
+ [
2
+ {
3
+ "platform": "alipay",
4
+ "source": "@tbox.cn/app-miniapp-container-alipay@0.2.3"
5
+ }
6
+ ]
package/README.md CHANGED
@@ -1,18 +1,24 @@
1
1
  # template-agent
2
2
 
3
3
  tbox AI Agent 全栈模板(npm 包名 `@tbox.cn/app-template-agent`,唯一模板——W4 单一模板统一化),多包 pnpm workspace:`apps/` 薄组装端 + `packages/` 模块。
4
- 缺省出厂 = 空装配(chat 形态);**商圈形态经 `profiles/mall` 画像加装**(`tbox-app create --profile mall`:mall-core + 六业务模块 + 商圈配置叠加)。
4
+ 缺省出厂 = 带 AI 支付体验的 chat 形态;**商圈形态经 `profiles/mall` 画像加装**(`tbox-app create --profile mall`:mall-core + 七业务模块 + 商圈配置叠加)。
5
5
  客户端同时支持浏览器和支付宝小程序 web-view;平台能力(鉴权/会话/TTS/ASR/上传/反馈)经 `@tbox.cn/app-sdk` 统一提供(007 下沉)。
6
6
 
7
+ 创建应用时按 `.tbox/default-modules.json` 加装 AI 支付模块,源码落在 `packages/module-ai-payment`。
8
+
9
+ 创建应用时默认生成 `apps/miniapp-container-alipay`,容器计划见 `.tbox/miniapp-containers.json`。使用前配置小程序 AppId 和 H5 地址;重复创建保留已登记的容器。
10
+
11
+ `pnpm dev` 始终启动原有 H5/server;容器已安装且 PATH 中有 `minidev` 时同时启动容器,否则跳过。容器异常退出不影响 H5/server,Ctrl+C 统一停止本次启动的进程。
12
+
7
13
  ## 快速开始
8
14
 
9
15
  ```sh
10
16
  pnpm install
11
- pnpm dev # 单进程 http://localhost:8000(API + WS + 页面 + HMR)
17
+ pnpm dev # H5/server + 可选 minidev 小程序容器
12
18
  pnpm verify # typecheck + test + build
13
19
  ```
14
20
 
15
- **能力加装**(空装配起点,能力即模块;mall 全套可改用 `create --profile mall` 一步到位):
21
+ **能力加装**(已有 AI 支付体验,能力即模块;mall 全套可改用 `create --profile mall` 一步到位):
16
22
 
17
23
  ```sh
18
24
  tbox-app module add shopping-guide # 导购/找店/业态/客服(模块级 intents + LLM 工具 + 卡片)
@@ -28,7 +34,7 @@ tbox-app module doctor # 26 条结构校验
28
34
  > 环境变量:本地开发用 shell export 注入(见 `ENV.md`,含必需变量命令块;每次新终端需重新执行),
29
35
  > 生产建议在 tbox 平台页面上配置(平台托管 env,密钥不进代码仓库)。
30
36
 
31
- > 平台包消费(005 v0.4.0 发布态):生成应用初始通过 `@app/contracts-mall` shim 使用 `catalog:` 引用的发布包;添加依赖 contracts-mall 的 codegen 模块后,CLI 将 shim 替换为本地源码包——
37
+ > 平台包消费(005 v0.4.0 发布态):模板通过 `@app/contracts-mall` shim 使用 `catalog:` 引用的发布包;创建时默认安装 AI 支付模块,CLI 按依赖将 shim 替换为本地源码包——
32
38
  > 生产(registry 已发布)直接 `pnpm install`;平台包未发布 npm 时,由 `tbox-app create --local-deps <平台 tgz 目录>`
33
39
  > 注入 overrides(`file:` 本地发布态产物)后 install 离线可用。
34
40
  >
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-template-agent",
3
- "version": "0.10.15",
4
- "description": "tbox AI Agent 全栈模板(多包 pnpm workspace):apps/client + apps/server。唯一模板(W4 单一模板统一化:缺省空装配 chat 形态;mall 能力经 profiles/mall 加装),能力经 tbox-app module add 模块扩展(shopping-guide/member 等)。",
3
+ "version": "0.10.17",
4
+ "description": "tbox AI Agent 全栈模板(多包 pnpm workspace):apps/client + apps/server。唯一模板(W4 单一模板统一化:缺省带 AI 支付体验的 chat 形态;mall 能力经 profiles/mall 加装),能力经 tbox-app module add 模块扩展(shopping-guide/member 等)。",
5
5
  "engines": {
6
6
  "node": ">=24.0.0 <25.0.0"
7
7
  },
@@ -44,7 +44,7 @@
44
44
  "access": "public"
45
45
  },
46
46
  "scripts": {
47
- "dev": "pnpm --filter ./apps/server dev",
47
+ "dev": "node scripts/dev.mjs",
48
48
  "build": "pnpm check && pnpm --filter ./apps/server build && pnpm --filter ./apps/client build",
49
49
  "build:client": "pnpm check && pnpm --filter ./apps/client build",
50
50
  "typecheck": "pnpm -r --filter \"./{apps,packages}/*\" typecheck",
@@ -27,6 +27,9 @@ catalogs:
27
27
  '@tbox.cn/app-contracts-mall':
28
28
  specifier: 0.13.0
29
29
  version: 0.13.0
30
+ '@tbox.cn/app-sdk-client':
31
+ specifier: 0.21.3
32
+ version: 0.21.3
30
33
  '@tbox.cn/app-sdk-server':
31
34
  specifier: 0.25.0
32
35
  version: 0.25.0
@@ -190,6 +193,24 @@ importers:
190
193
  specifier: 'catalog:'
191
194
  version: 4.1.10(@opentelemetry/api@1.9.1)(@types/node@24.13.3)(happy-dom@20.11.2)(vite@6.4.3(@types/node@24.13.3)(less@4.8.1)(tsx@4.23.11))
192
195
 
196
+ apps/miniapp-container-alipay:
197
+ devDependencies:
198
+ '@mini-types/alipay':
199
+ specifier: ^3.0.14
200
+ version: 3.0.14
201
+ '@tbox.cn/app-sdk-client':
202
+ specifier: 'catalog:'
203
+ version: 0.21.3
204
+ '@tbox.cn/app-sdk-server':
205
+ specifier: 'catalog:'
206
+ version: 0.25.0
207
+ typescript:
208
+ specifier: 'catalog:'
209
+ version: 5.9.3
210
+ vitest:
211
+ specifier: 'catalog:'
212
+ version: 4.1.10(@opentelemetry/api@1.9.1)(@types/node@24.13.3)(happy-dom@20.11.2)(vite@6.4.3(@types/node@24.13.3)(less@4.8.1)(tsx@4.23.11))
213
+
193
214
  apps/server:
194
215
  dependencies:
195
216
  '@app/contracts-mall':
@@ -1101,6 +1122,15 @@ packages:
1101
1122
  peerDependencies:
1102
1123
  zod: ^3.25.0 || ^4.0.0
1103
1124
 
1125
+ '@mini-types/alipay@3.0.14':
1126
+ resolution: {integrity: sha512-FakzSsKvybtWlEIVTIRlr89kuQFn+XY86Ho9VUFFaKLplhW6Wx8FUxTDE7IzV7B9rT8DP/Icy637vUHlXPsw1g==}
1127
+
1128
+ '@mini-types/global@3.0.14':
1129
+ resolution: {integrity: sha512-St2ucFRfKRskposOqV/9iNJTKn1MbyqDypQiy/0DaVJjEm2MFi82RJjX9sBz1uWhQIqzu741PgTjGSy7L/Qj9g==}
1130
+
1131
+ '@mini-types/my@3.0.14':
1132
+ resolution: {integrity: sha512-aEgmM+rbEvEzTvqltCFRAg/h6KKs14M1y+FrOkz+hn2EyNpOVPesUzTjbRhSiFFsE3WdfBh54lHNYBahAmHq7w==}
1133
+
1104
1134
  '@modelcontextprotocol/core@2.0.0':
1105
1135
  resolution: {integrity: sha512-pJCEwGG7Lfr/+PQp9ZTwKXNeO5wzbfKL7H3MYpCorM4oFBoQrdjnBgEoqG+RjhsvS1FKrDbKux+M1HhlnGWqcA==}
1106
1136
  engines: {node: '>=20'}
@@ -3907,6 +3937,15 @@ snapshots:
3907
3937
  zod: 3.25.76
3908
3938
  zod-from-json-schema: 0.5.6
3909
3939
 
3940
+ '@mini-types/alipay@3.0.14':
3941
+ dependencies:
3942
+ '@mini-types/global': 3.0.14
3943
+ '@mini-types/my': 3.0.14
3944
+
3945
+ '@mini-types/global@3.0.14': {}
3946
+
3947
+ '@mini-types/my@3.0.14': {}
3948
+
3910
3949
  '@modelcontextprotocol/core@2.0.0':
3911
3950
  dependencies:
3912
3951
  zod: 4.4.3
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$comment": "mall 画像(单一模板统一化 W4):create --profile mall 执行器(W5 接线)按 modules 序列加装 + configOverlay 叠加(--config-dir 通道)+ rootFiles 根文件落地(TEMPLATE.md 使用指南 → 应用根)。provider 轴独立(缺省 mock-only 演示态;vendor 档由部署者后续 add)。",
3
3
  "name": "mall",
4
- "description": "商圈 AI Agent:家页形态(home 槽)+ 域装配 + 六业务域(导购/会员/停车/营销/活动/客服)",
4
+ "description": "商圈 AI Agent:家页形态(home 槽)+ 域装配 + 七业务域(导购/会员/停车/营销/活动/客服/AI 支付)",
5
5
  "modules": [
6
6
  "@tbox.cn/app-module-mall-core",
7
7
  "@tbox.cn/app-module-shopping-guide",
@@ -9,7 +9,8 @@
9
9
  "@tbox.cn/app-module-parking",
10
10
  "@tbox.cn/app-module-promotion",
11
11
  "@tbox.cn/app-module-alipay-activity",
12
- "@tbox.cn/app-module-customer-service"
12
+ "@tbox.cn/app-module-customer-service",
13
+ "@tbox.cn/app-module-ai-payment"
13
14
  ],
14
15
  "configOverlay": "profiles/mall/config",
15
16
  "rootFiles": ["TEMPLATE.md"]
@@ -0,0 +1,91 @@
1
+ import { spawn } from 'node:child_process';
2
+ import { accessSync, constants, existsSync, statSync } from 'node:fs';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ export function hasCommand(command, env = process.env) {
7
+ const extensions = process.platform === 'win32' ? (env.PATHEXT ?? '.EXE;.CMD;.BAT').split(';') : [''];
8
+ return (env.PATH ?? '').split(path.delimiter).some(dir => extensions.some(extension => {
9
+ try {
10
+ const executable = path.join(dir || '.', command + extension);
11
+ accessSync(executable, constants.X_OK);
12
+ return statSync(executable).isFile();
13
+ }
14
+ catch { return false; }
15
+ }));
16
+ }
17
+
18
+ function stopChild(child, signal) {
19
+ if (!child?.pid) return;
20
+ try {
21
+ if (process.platform === 'win32') child.kill(signal);
22
+ else process.kill(-child.pid, signal);
23
+ } catch (error) {
24
+ if (error.code !== 'ESRCH') throw error;
25
+ }
26
+ }
27
+
28
+ /** H5/server 为主进程;可选容器失败不终止主进程。 */
29
+ export function startDev({
30
+ projectDir,
31
+ spawnProcess = spawn,
32
+ commandExists = hasCommand,
33
+ stopProcess = stopChild,
34
+ signals = process,
35
+ log = console,
36
+ finish = code => { process.exitCode = code; },
37
+ }) {
38
+ const options = { cwd: projectDir, detached: process.platform !== 'win32', shell: process.platform === 'win32' };
39
+ const containerInstalled = existsSync(path.join(projectDir, 'apps/miniapp-container-alipay/package.json'));
40
+ const containerEnabled = containerInstalled && commandExists('minidev');
41
+ const server = spawnProcess('pnpm', ['--filter', './apps/server', 'dev'], {
42
+ ...options, stdio: containerEnabled ? ['ignore', 'inherit', 'inherit'] : 'inherit',
43
+ });
44
+ let container;
45
+ let stopping = false;
46
+ let requestedCode;
47
+ let completed = false;
48
+ const stop = code => {
49
+ if (stopping) return;
50
+ stopping = true;
51
+ requestedCode = code;
52
+ stopProcess(server, 'SIGTERM');
53
+ stopProcess(container, 'SIGTERM');
54
+ setTimeout(() => {
55
+ stopProcess(server, 'SIGKILL');
56
+ stopProcess(container, 'SIGKILL');
57
+ }, 2000);
58
+ };
59
+ const interrupt = () => stop(130);
60
+ const terminate = () => stop(143);
61
+ signals.on('SIGINT', interrupt);
62
+ signals.on('SIGTERM', terminate);
63
+ const complete = code => {
64
+ if (completed) return;
65
+ completed = true;
66
+ stop(code);
67
+ signals.removeListener('SIGINT', interrupt);
68
+ signals.removeListener('SIGTERM', terminate);
69
+ finish(requestedCode ?? code);
70
+ };
71
+ server.once('error', error => { log.error(`H5/server 启动失败:${error.message}`); complete(1); });
72
+ server.once('exit', (code, signal) => complete(code ?? (signal ? 1 : 0)));
73
+
74
+ if (!containerInstalled) {
75
+ log.info('未安装支付宝小程序容器,仅启动 H5/server。');
76
+ } else if (!containerEnabled) {
77
+ log.info('未找到 minidev,跳过小程序容器,H5/server 正常启动。');
78
+ } else {
79
+ log.info('同时启动支付宝小程序容器(minidev)。');
80
+ container = spawnProcess('pnpm', ['--filter', '@app/miniapp-container-alipay', 'dev'], { ...options, stdio: 'inherit' });
81
+ container.once('error', error => log.warn(`小程序容器启动失败,H5/server 继续运行:${error.message}`));
82
+ container.once('exit', code => {
83
+ if (!stopping) log.info(`小程序容器已退出(${code ?? 'signal'}),H5/server 继续运行。`);
84
+ });
85
+ }
86
+ return { server, get container() { return container; }, stop };
87
+ }
88
+
89
+ if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
90
+ startDev({ projectDir: path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') });
91
+ }
package/scripts/dev.sh CHANGED
@@ -12,4 +12,4 @@ pnpm install
12
12
  echo "Starting development server..."
13
13
  echo " - http://localhost:8000 (API + WS + 页面 + HMR)"
14
14
 
15
- pnpm --filter @app/server dev
15
+ pnpm dev