@tbox.cn/app-template-agent 0.10.29 → 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.
Files changed (69) hide show
  1. package/.gitignore +6 -0
  2. package/.tbox/app.json +3 -19
  3. package/.tbox/default-modules.json +4 -1
  4. package/.tbox/miniapp-containers.json +1 -1
  5. package/AGENTS.md +52 -147
  6. package/README.md +11 -9
  7. package/apps/AGENTS.md +13 -0
  8. package/apps/client/.tbox-gen/app-kind.ts +1 -0
  9. package/apps/client/.tbox-gen/documents/_tbox/card-preview.html +38 -0
  10. package/apps/client/.tbox-gen/documents/index.html +39 -0
  11. package/apps/client/.tbox-gen/entries/card-preview.tsx +18 -0
  12. package/apps/client/.tbox-gen/entries/index.tsx +18 -0
  13. package/apps/client/.tbox-gen/manifest.json +17 -0
  14. package/apps/client/.tbox-gen/registry.client.ts +6 -0
  15. package/apps/client/.tbox-gen/registry.server.ts +15 -0
  16. package/apps/client/index.html +1 -1
  17. package/apps/client/package.json +3 -2
  18. package/apps/client/src/cards/registry.ts +6 -19
  19. package/apps/client/src/pages/page.tsx +11 -0
  20. package/apps/client/src/platform/AgentChatApp.tsx +2 -40
  21. package/apps/client/src/platform/AppShell.tsx +42 -0
  22. package/apps/client/src/platform/bootstrap.ts +55 -0
  23. package/apps/client/src/platform/card-preview-page.tsx +10 -0
  24. package/apps/client/src/platform/mount-page.tsx +20 -0
  25. package/apps/client/src/vite-env.d.ts +0 -3
  26. package/apps/client/tsconfig.json +10 -2
  27. package/apps/client/vite.config.ts +6 -10
  28. package/apps/server/package.json +1 -1
  29. package/apps/server/src/app.ts +18 -18
  30. package/apps/server/src/cli/collect-registry.ts +7 -11
  31. package/apps/server/src/dev.ts +47 -49
  32. package/apps/server/src/index.ts +28 -22
  33. package/apps/server/src/pre-tools.ts +1 -1
  34. package/apps/server/src/tools/{clock.ts → clock.tool.ts} +1 -1
  35. package/apps/server/src/tools/{translate.ts → translate.tool.ts} +1 -1
  36. package/apps/server/tests/cards-registry.test.ts +1 -1
  37. package/apps/server/tests/helpers/register.ts +10 -0
  38. package/apps/server/tests/tool-runtime.test.ts +2 -2
  39. package/apps/server/tsconfig.json +1 -1
  40. package/apps/server/tsup.config.ts +6 -3
  41. package/{packages → modules}/provider-custom/AGENTS.md +1 -1
  42. package/modules/provider-custom/INTEGRATION.md +10 -0
  43. package/{packages → modules}/provider-custom/package.json +1 -0
  44. package/package.json +11 -6
  45. package/packages/agent-ui-kit/package.json +1 -1
  46. package/packages/shared/AGENTS.md +11 -0
  47. package/packages/shared/package.json +13 -0
  48. package/packages/shared/src/index.ts +8 -0
  49. package/packages/shared/tsconfig.json +7 -0
  50. package/pnpm-lock.template.yaml +181 -179
  51. package/pnpm-workspace.template.yaml +10 -8
  52. package/scripts/generate.mjs +3 -0
  53. package/scripts/verify-generated.mjs +22 -127
  54. package/apps/client/src/app.tsx +0 -35
  55. package/apps/client/src/business/App.tsx +0 -11
  56. package/apps/client/src/business/README.md +0 -76
  57. package/apps/client/src/main.tsx +0 -54
  58. package/apps/client/src/modules.ts +0 -33
  59. package/apps/server/src/app-tools.ts +0 -14
  60. package/apps/server/src/modules.ts +0 -38
  61. /package/{packages → modules}/provider-custom/LICENSE +0 -0
  62. /package/{packages → modules}/provider-custom/README.md +0 -0
  63. /package/{packages → modules}/provider-custom/src/index.ts +0 -0
  64. /package/{packages → modules}/provider-custom/src/server/example-adapter.ts +0 -0
  65. /package/{packages → modules}/provider-custom/src/server/index.ts +0 -0
  66. /package/{packages → modules}/provider-custom/tbox.module.json +0 -0
  67. /package/{packages → modules}/provider-custom/tests/provider-custom.test.ts +0 -0
  68. /package/{packages → modules}/provider-custom/tsconfig.json +0 -0
  69. /package/{packages → modules}/provider-custom/tsup.config.ts +0 -0
@@ -6,7 +6,7 @@ import { z } from 'zod';
6
6
  * 翻译工具 — 中英文互译
7
7
  * 由原 translator Skill 改造而来,现在作为 Tool 注册,LLM 自主调用
8
8
  */
9
- export const translateTool = createTool({
9
+ export const tool = createTool({
10
10
  id: 'translate',
11
11
  description:
12
12
  '中英文互译工具。当用户需要翻译文本时调用此工具。自动检测源语言并翻译为目标语言:中文→英文,英文→中文。',
@@ -4,7 +4,7 @@
4
4
  import { describe, it, expect } from 'vitest';
5
5
  import { diagnosePlugins } from '@tbox.cn/agent-plugin/doctor';
6
6
  import { createServerContext, createPluginIntegration } from '@tbox.cn/app-agent-sdk-server';
7
- import { registerAll } from '../src/modules.js';
7
+ import { registerAll } from './helpers/register.js';
8
8
 
9
9
  describe('工具 / 卡片 registry 一致性(自注册闭环)', () => {
10
10
  it('C2: ctx.tools 每个 key === tool.id', async () => {
@@ -0,0 +1,10 @@
1
+ import { registerServerModules, type ServerContext } from '@tbox.cn/app-agent-sdk-server';
2
+ import { registry } from '../../../client/.tbox-gen/registry.server';
3
+
4
+ /** 与 createApp 同源的注册面,供单测复用生成 registry。 */
5
+ export async function registerAll(ctx: ServerContext): Promise<void> {
6
+ for (const tool of registry.tools) ctx.tools.register(tool);
7
+ for (const skill of registry.skills) ctx.skills.register(skill);
8
+ for (const card of Object.values(registry.cards)) ctx.cards.register(card as never);
9
+ await registerServerModules(ctx, registry.modules);
10
+ }
@@ -6,8 +6,8 @@ import {
6
6
  createInMemoryMemoryStore,
7
7
  resolveMemoryStore,
8
8
  } from '@tbox.cn/app-agent-sdk-server';
9
- import { registerAll } from '../src/modules.js';
10
- import { translateTool } from '../src/tools/translate.js';
9
+ import { registerAll } from './helpers/register.js';
10
+ import { tool as translateTool } from '../src/tools/translate.tool.js';
11
11
 
12
12
  describe('tool runtime 宿主装配(自注册闭环)', () => {
13
13
  it('空装配(mall 模板):无模块工具,app 级工具正常注册', async () => {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "extends": "../../tsconfig.base.json",
3
3
  "compilerOptions": {},
4
- "include": ["src", "tests"]
4
+ "include": ["src", "tests", "../../client/.tbox-gen"]
5
5
  }
@@ -9,9 +9,8 @@ export default defineConfig({
9
9
  clean: true,
10
10
  sourcemap: true,
11
11
  // 本地 workspace 源码包(exports 指向 src/*.ts,node 无法直接加载)必须内联:@app/*。
12
- // @tbox.cn/{app-sdk,contracts} 以发布态消费(dist 产物,node 可直载);codegen 平台包经 @app/* 内联;
13
- // 已发布 npm 的 @tbox.cn/agent-plugin(exports 指向 dist 产物)保持 external。
14
- noExternal: [/^@app\//],
12
+ // @tbox.cn/* 同样内联:模板源/生成应用验证态消费 workspace 源码,离线启动不依赖发布态 dist。
13
+ noExternal: [/^@app\//, /^@tbox\.cn\//],
15
14
  // vite 不进 bundle 的结构防线:静态入口图(entry: index.ts → app.ts 链)任何 vite 引用
16
15
  // (含 dev.ts 误入 entry)在 onResolve 即失败——dev 形态仅存在于 src/dev.ts(tsx 运行)。
17
16
  esbuildPlugins: [
@@ -35,4 +34,8 @@ export default defineConfig({
35
34
  'http',
36
35
  'fs',
37
36
  ],
37
+ // 内联 CJS 依赖(ws 等)的 require() 在 ESM 输出中经真实 createRequire 落地。
38
+ banner: {
39
+ js: "import { createRequire as __tboxCreateRequire } from 'module';const require=__tboxCreateRequire(import.meta.url);",
40
+ },
38
41
  });
@@ -3,7 +3,7 @@
3
3
  本包是自定义 API 的 adapter 代码落点:某服务槽声明 `provider-custom` 而 adapter 未实施时,
4
4
  服务调用报 `PROVIDER_NOT_IMPLEMENTED`——按指引实施并注册命中后即恢复。
5
5
 
6
- **先读流程知识(随 CLI 发布,无需安装)**:
6
+ **先读流程知识(随 CLI 发布,无需安装;接入材料与任务路由见 [INTEGRATION.md](INTEGRATION.md))**:
7
7
 
8
8
  ```sh
9
9
  npx --yes @tbox.cn/app-cli skills get provider-custom # 实施三步/声明形态/代码骨架/注册/凭据
@@ -0,0 +1,10 @@
1
+ # provider-custom 集成
2
+
3
+ 本包是自定义 API 的 adapter 实施落点。接入流程与材料清单以 CLI 流程知识为唯一真源:
4
+
5
+ ```sh
6
+ npx --yes @tbox.cn/app-cli skills get provider-custom
7
+ npx --yes @tbox.cn/app-cli skills get integration
8
+ ```
9
+
10
+ 代码落点、provider 名三处一致与凭据边界见同目录 [AGENTS.md](AGENTS.md)。
@@ -40,6 +40,7 @@
40
40
  "tsconfig.json",
41
41
  "tsup.config.ts",
42
42
  "AGENTS.md",
43
+ "INTEGRATION.md",
43
44
  "README.md",
44
45
  "LICENSE"
45
46
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tbox.cn/app-template-agent",
3
- "version": "0.10.29",
3
+ "version": "1.0.0-alpha.1",
4
4
  "description": "tbox AI Agent 全栈模板(多包 pnpm workspace):apps/client + apps/server。唯一模板(W4 单一模板统一化:缺省带 AI 支付体验的 chat 形态;mall 能力经 profiles/mall 加装),能力经 CLI module add 模块扩展(shopping-guide/member 等)。",
5
5
  "engines": {
6
6
  "node": ">=24.0.0 <25.0.0"
@@ -15,8 +15,11 @@
15
15
  "config",
16
16
  "profiles",
17
17
  "packages",
18
+ "modules",
18
19
  "!packages/**/node_modules",
19
20
  "!packages/**/*.tsbuildinfo",
21
+ "!modules/**/node_modules",
22
+ "!modules/**/*.tsbuildinfo",
20
23
  "scripts",
21
24
  ".tbox",
22
25
  ".gitignore",
@@ -36,7 +39,8 @@
36
39
  "typescript-eslint": "8.67.0",
37
40
  "eslint-plugin-react-hooks": "5.2.0",
38
41
  "vite": "6.4.3",
39
- "@tbox.cn/app-sdk-server": "0.26.3"
42
+ "@tbox.cn/app-sdk-server": "1.0.0-alpha.1",
43
+ "@tbox.cn/app-build": "1.0.0-alpha.1"
40
44
  },
41
45
  "license": "MIT",
42
46
  "publishConfig": {
@@ -45,10 +49,11 @@
45
49
  "scripts": {
46
50
  "dev": "pnpm --filter ./apps/server dev",
47
51
  "dev-alipay": "node scripts/dev-alipay.mjs",
48
- "build": "pnpm check && pnpm --filter ./apps/server build && pnpm --filter ./apps/client build",
49
- "build:client": "pnpm check && pnpm --filter ./apps/client build",
50
- "typecheck": "pnpm -r --filter \"./{apps,packages}/*\" typecheck",
51
- "test": "pnpm -r --filter \"./{apps,packages}/*\" test",
52
+ "generate": "node scripts/generate.mjs",
53
+ "build": "pnpm check && pnpm generate && pnpm --filter ./apps/server build && pnpm --filter ./apps/client build",
54
+ "build:client": "pnpm check && pnpm generate && pnpm --filter ./apps/client build",
55
+ "typecheck": "pnpm generate && pnpm -r --filter \"./{apps,packages,modules}/*\" typecheck",
56
+ "test": "pnpm -r --filter \"./{apps,packages,modules}/*\" test",
52
57
  "lint": "eslint apps $(find packages -mindepth 1 -maxdepth 1 -type d -print -quit 2>/dev/null | grep -q . && echo packages)",
53
58
  "smoke": "node scripts/smoke.mjs",
54
59
  "verify": "pnpm typecheck && pnpm test && pnpm lint && pnpm build && pnpm smoke --self-test && pnpm verify:generated && pnpm check:inspector",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app/agent-ui-kit",
3
- "version": "0.1.1",
3
+ "version": "1.0.0-alpha.1",
4
4
  "type": "module",
5
5
  "description": "Agent 对话壳 UI 组件包(源码发布,单一模板统一化 W2-1):ChatPage/壳组件族/主题 tokens。",
6
6
  "exports": {
@@ -0,0 +1,11 @@
1
+ # packages/shared
2
+
3
+ 这是应用唯一的跨端 DTO 包,包名 `@app/shared`。
4
+
5
+ - 只放纯类型、常量、可序列化数据结构。
6
+ - 不 import React、Node、Express、数据库、网络客户端。
7
+ - 不 import `apps/*` 或 `modules/*`。
8
+ - 不放服务端实现、鉴权逻辑、HTTP 客户端。
9
+ - client 与 server 都使用 `import type { ... } from '@app/shared'`。
10
+ - 新增类型按 `<Domain><Action>Input` / `<Domain><Action>Output` 命名。
11
+ - 不放空 `export {}`;至少有一个真实导出。
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@app/shared",
3
+ "version": "0.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "exports": {
8
+ ".": {
9
+ "types": "./src/index.ts",
10
+ "import": "./src/index.ts"
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,8 @@
1
+ export interface ApiError {
2
+ code: string;
3
+ message: string;
4
+ }
5
+
6
+ export type ApiResult<T> =
7
+ | { ok: true; data: T }
8
+ | { ok: false; error: ApiError };
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src"
5
+ },
6
+ "include": ["src"]
7
+ }