@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.
- package/.gitignore +6 -0
- package/.tbox/app.json +3 -19
- package/.tbox/default-modules.json +4 -1
- package/.tbox/miniapp-containers.json +1 -1
- package/AGENTS.md +52 -147
- package/README.md +11 -9
- 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 -40
- package/apps/client/src/platform/AppShell.tsx +42 -0
- package/apps/client/src/platform/bootstrap.ts +55 -0
- package/apps/client/src/platform/card-preview-page.tsx +10 -0
- package/apps/client/src/platform/mount-page.tsx +20 -0
- package/apps/client/src/vite-env.d.ts +0 -3
- package/apps/client/tsconfig.json +10 -2
- package/apps/client/vite.config.ts +6 -10
- package/apps/server/package.json +1 -1
- package/apps/server/src/app.ts +18 -18
- package/apps/server/src/cli/collect-registry.ts +7 -11
- package/apps/server/src/dev.ts +47 -49
- package/apps/server/src/index.ts +28 -22
- 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 +181 -179
- 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 -35
- package/apps/client/src/business/App.tsx +0 -11
- package/apps/client/src/business/README.md +0 -76
- package/apps/client/src/main.tsx +0 -54
- 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
|
@@ -1,142 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* verify:generated
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* 自包含实现(模板独立于 CLI 包),全量校验以 CLI `module doctor` / `module diff` 为准。
|
|
3
|
+
* verify:generated 守卫(v1):
|
|
4
|
+
* - 调用 app-build checkApp:apps/布局、无 legacy 装配面、shared 包、agent 卡片预览;
|
|
5
|
+
* - 确认 .tbox-gen/manifest.json 已生成;
|
|
6
|
+
* - 不再维护双端 modules.ts 锚点。
|
|
8
7
|
*/
|
|
9
|
-
import { existsSync
|
|
10
|
-
import { readdir } from 'node:fs/promises';
|
|
8
|
+
import { existsSync } from 'node:fs';
|
|
11
9
|
import path from 'node:path';
|
|
12
10
|
import process from 'node:process';
|
|
11
|
+
import { checkApp } from '@tbox.cn/app-build';
|
|
13
12
|
|
|
14
13
|
const appDir = path.resolve(process.argv[2] ?? path.join(import.meta.dirname, '..'));
|
|
15
14
|
const failures = [];
|
|
16
15
|
const warnings = [];
|
|
17
16
|
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
{ path: 'apps/client/src/modules.ts', markers: ['imports', 'register'] },
|
|
21
|
-
];
|
|
17
|
+
const manifest = path.join(appDir, 'apps/client/.tbox-gen/manifest.json');
|
|
18
|
+
if (!existsSync(manifest)) failures.push('apps/client/.tbox-gen/manifest.json: 缺失(先运行 pnpm generate)');
|
|
22
19
|
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
function isAnchorBegin(line) {
|
|
30
|
-
return line.trim() === '// @tbox:imports-begin';
|
|
31
|
-
}
|
|
32
|
-
function isAnchorEnd(line) {
|
|
33
|
-
return line.trim() === '// @tbox:imports-end';
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** 读取 .tbox/app.json 的 npm 模块清单 */
|
|
37
|
-
function readManifestModules() {
|
|
38
|
-
try {
|
|
39
|
-
const raw = JSON.parse(readFileSync(path.join(appDir, '.tbox/app.json'), 'utf8'));
|
|
40
|
-
return Array.isArray(raw?.npmModules) ? raw.npmModules : [];
|
|
41
|
-
} catch {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** 收集 packages/* 下本地模块 id(有 tbox.module.json) */
|
|
47
|
-
async function listLocalModuleIds() {
|
|
48
|
-
const packagesDir = path.join(appDir, 'packages');
|
|
49
|
-
if (!existsSync(packagesDir)) return [];
|
|
50
|
-
const entries = await readdir(packagesDir, { withFileTypes: true });
|
|
51
|
-
const ids = [];
|
|
52
|
-
for (const entry of entries) {
|
|
53
|
-
if (!entry.isDirectory()) continue;
|
|
54
|
-
if (existsSync(path.join(packagesDir, entry.name, 'tbox.module.json'))) {
|
|
55
|
-
ids.push(entry.name);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return ids;
|
|
20
|
+
const result = await checkApp({ root: appDir });
|
|
21
|
+
for (const issue of result.issues) {
|
|
22
|
+
const line = `${issue.file ? issue.file + ': ' : ''}${issue.message}`;
|
|
23
|
+
if (issue.severity === 'error') failures.push(line);
|
|
24
|
+
else warnings.push(line);
|
|
59
25
|
}
|
|
60
26
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
const b = content.indexOf(begin);
|
|
65
|
-
if (b === -1) return null;
|
|
66
|
-
const e = content.indexOf(end, b);
|
|
67
|
-
if (e === -1) return null;
|
|
68
|
-
return content.slice(b + begin.length, e);
|
|
27
|
+
if (warnings.length > 0) {
|
|
28
|
+
console.warn('[verify:generated] 告警:');
|
|
29
|
+
for (const w of warnings) console.warn(` - ${w}`);
|
|
69
30
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async function main() {
|
|
76
|
-
// ② 锚点完整 + ③ 无裸露 import
|
|
77
|
-
for (const file of ASSEMBLY_FILES) {
|
|
78
|
-
const full = path.join(appDir, file.path);
|
|
79
|
-
if (!existsSync(full)) {
|
|
80
|
-
failures.push(`${file.path}: 缺失`);
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
const content = readFileSync(full, 'utf8');
|
|
84
|
-
for (const marker of file.markers) {
|
|
85
|
-
const block = extractBlock(content, marker);
|
|
86
|
-
if (block === null) {
|
|
87
|
-
failures.push(`${file.path}: 缺 ${marker} 锚区`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
const lines = content.split(/\r?\n/);
|
|
91
|
-
let inAnchor = false;
|
|
92
|
-
lines.forEach((line, i) => {
|
|
93
|
-
if (isAnchorBegin(line)) inAnchor = true;
|
|
94
|
-
else if (isAnchorEnd(line)) inAnchor = false;
|
|
95
|
-
// import type 属类型导入(非模块装配),锚区外合法,不视为裸露
|
|
96
|
-
else if (IMPORT_LINE.test(line.trim()) && !line.trim().startsWith('import type') && !inAnchor) {
|
|
97
|
-
failures.push(`${file.path}:${i + 1} 裸露 import(不在 imports 锚区内): ${line.trim()}`);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// ① 漂移 = 0:声明(manifest + 本地模块)vs 服务端 modules.ts 实际装配
|
|
103
|
-
// 契约包(无 tbox.module.json / 无 serverModule)不参与 modules.ts 装配,不计入声明
|
|
104
|
-
// (客户端 modules.ts 装配漂移由 CLI module doctor 全量校验兜底)
|
|
105
|
-
const npmModules = readManifestModules();
|
|
106
|
-
const declared = new Set([
|
|
107
|
-
...npmModules
|
|
108
|
-
.filter((m) => existsSync(path.join(appDir, 'packages', m.id, 'tbox.module.json')))
|
|
109
|
-
.map((m) => m.id),
|
|
110
|
-
...(await listLocalModuleIds()),
|
|
111
|
-
]);
|
|
112
|
-
const modulesTs = existsSync(path.join(appDir, 'apps/server/src/modules.ts'))
|
|
113
|
-
? readFileSync(path.join(appDir, 'apps/server/src/modules.ts'), 'utf8')
|
|
114
|
-
: '';
|
|
115
|
-
const importsBlock = extractBlock(modulesTs, 'imports') ?? '';
|
|
116
|
-
const actual = new Set(
|
|
117
|
-
[...importsBlock.matchAll(/from\s+['"]([^'"]+)['"]/g)].map((m) => idFromPkg(m[1])),
|
|
118
|
-
);
|
|
119
|
-
for (const id of declared) {
|
|
120
|
-
if (!actual.has(id)) failures.push(`模块 ${id} 已声明未装配(modules.ts imports 锚区)`);
|
|
121
|
-
}
|
|
122
|
-
for (const id of actual) {
|
|
123
|
-
if (!declared.has(id)) warnings.push(`模块 ${id} 已装配未声明(仅告警,可能为手接)`);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
if (warnings.length > 0) {
|
|
127
|
-
console.warn('[verify:generated] 告警:');
|
|
128
|
-
for (const w of warnings) console.warn(` - ${w}`);
|
|
129
|
-
}
|
|
130
|
-
if (failures.length > 0) {
|
|
131
|
-
console.error('[verify:generated] 校验失败:');
|
|
132
|
-
for (const f of failures) console.error(` - ${f}`);
|
|
133
|
-
process.exitCode = 1;
|
|
134
|
-
} else {
|
|
135
|
-
console.log('[verify:generated] 通过(装配一致 + 锚点完整 + 无裸露 import)');
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
main().catch((err) => {
|
|
140
|
-
console.error('[verify:generated] 执行失败:', err);
|
|
31
|
+
if (failures.length > 0) {
|
|
32
|
+
console.error('[verify:generated] 校验失败:');
|
|
33
|
+
for (const f of failures) console.error(` - ${f}`);
|
|
141
34
|
process.exitCode = 1;
|
|
142
|
-
}
|
|
35
|
+
} else {
|
|
36
|
+
console.log('[verify:generated] 通过(apps/ 布局 + generated manifest + 无 legacy 装配面)');
|
|
37
|
+
}
|
package/apps/client/src/app.tsx
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { lazy, Suspense } from 'react';
|
|
2
|
-
import BusinessApp from '@/business/App';
|
|
3
|
-
|
|
4
|
-
// dev 卡片预览页(/_tbox/card-preview):
|
|
5
|
-
// - 守卫用**三元**而非 if——`DEV || __TBOX_CARD_PREVIEW__` 在生产构建(define false)被
|
|
6
|
-
// 静态替换为 false,lazy 分支成为可摇除死代码,动态 import 与页面 chunk 一并消失
|
|
7
|
-
// (若用顶层 if,lazy() 调用本身活过 treeshaking,chunk 仍会产出);
|
|
8
|
-
// - 方案 W:沙箱 protected 静态面经 __TBOX_CARD_PREVIEW__(build + TBOX_DEV_TOKEN)放行,
|
|
9
|
-
// dev 面仍由 import.meta.env.DEV 放行——两态共用同一 lazy 装配;
|
|
10
|
-
// - lazy 双动态 import 组装(SDK 页面 + 模板 registry/authClient 单例注入——
|
|
11
|
-
// authClient 含模板选项,不经预览页自建)。
|
|
12
|
-
const CARD_PREVIEW_PATH = '/_tbox/card-preview';
|
|
13
|
-
const DevCardPreview = import.meta.env.DEV || __TBOX_CARD_PREVIEW__
|
|
14
|
-
? lazy(async () => {
|
|
15
|
-
const [{ CardPreviewPage }, { CARD_REGISTRY }, { authClient }] = await Promise.all([
|
|
16
|
-
import('@tbox.cn/app-agent-sdk-client/client/card-preview'),
|
|
17
|
-
import('@/cards/registry'),
|
|
18
|
-
import('@/platform/agent-runtime'),
|
|
19
|
-
]);
|
|
20
|
-
return {
|
|
21
|
-
default: () => <CardPreviewPage registry={CARD_REGISTRY} authClient={authClient} />,
|
|
22
|
-
};
|
|
23
|
-
})
|
|
24
|
-
: null;
|
|
25
|
-
|
|
26
|
-
export default function App() {
|
|
27
|
-
if ((import.meta.env.DEV || __TBOX_CARD_PREVIEW__) && DevCardPreview && window.location.pathname === CARD_PREVIEW_PATH) {
|
|
28
|
-
return (
|
|
29
|
-
<Suspense fallback={<div>加载卡片预览…</div>}>
|
|
30
|
-
<DevCardPreview />
|
|
31
|
-
</Suspense>
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
return <BusinessApp />;
|
|
35
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import AgentChatApp from '@/platform/AgentChatApp';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 业务应用唯一入口。
|
|
5
|
-
* mall 模板:空态首屏由 IndexPage 内 MallHome 呈现(商圈主屏),无需 landing 注入;
|
|
6
|
-
* 业务能力经 `npx --yes @tbox.cn/app-cli module add` 扩展(shopping-guide/member 等)。
|
|
7
|
-
* 新应用替换本组件;需要定制首屏时组合 AgentChatApp 或改 pages/index。
|
|
8
|
-
*/
|
|
9
|
-
export default function BusinessApp() {
|
|
10
|
-
return <AgentChatApp />;
|
|
11
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
# Business application entry
|
|
2
|
-
|
|
3
|
-
`App.tsx` 是业务应用的唯一入口。缺省出厂 = 空装配 chat 形态(`AgentChatApp` 直出对话流,无 landing 注入——014 已退役)。商圈形态经 `npx --yes @tbox.cn/app-cli create --profile mall` 加装:mall-core 模块经 home 槽供给联单式主屏(欢迎区 + 单一联单活动主卡 + 会员/停车双快览 + 四域开发测试入口),消息追加在首页内容下方,底部保留三枚快捷指令与输入区。四域开发测试入口可见性由后端开关控制(`MALL_HOME_DEV_SERVICES` env → `GET /api/m/mall-core/config`,fail-closed 缺省隐藏;详见模板 ENV.md)。会员快览严格区分登录与入会状态,仅对已入会用户展示服务端返回的真实积分。
|
|
4
|
-
|
|
5
|
-
业务能力经 `npx --yes @tbox.cn/app-cli module add` 扩展(shopping-guide/member/parking/promotion/alipay-activity),安装后自动装配进双端 `modules.ts`;联单节点是支付宝活动回执的支付笔数投影(mall-core 家页面),不从会话业务卡或本地默认值派生。生成完成后运行 `pnpm verify:generated`。
|
|
6
|
-
|
|
7
|
-
## 本地交互应用
|
|
8
|
-
|
|
9
|
-
当需求当前只涉及客户端本地行为时:
|
|
10
|
-
|
|
11
|
-
1. 直接替换 `App.tsx`。
|
|
12
|
-
2. 页面、feature、业务 store 和本地规则引擎都放在当前目录。
|
|
13
|
-
3. 持久化状态使用 `@/platform/state/createPersistedStore`。
|
|
14
|
-
4. 起始阶段无需展开 `server/`、`adapters/`、`bridge/`、chat store。
|
|
15
|
-
5. 保留根 `client/src/app.tsx`、inspector 和 Vite 配置。
|
|
16
|
-
|
|
17
|
-
首次编辑前不需要读取根目录结构、`client/src` 目录结构、`vite.config.ts`、`index.html` 或默认对话实现。除上面的入口和 tokens 外,只按实际功能读取持久化 store、Toast 等直接依赖。
|
|
18
|
-
|
|
19
|
-
以上是起始范围,不是永久限制。首次编辑后,直接依赖、远端契约、测试或构建结果证明需求跨层时,应进入对应所有者模块,不要在 `business/` 内重复实现平台能力。
|
|
20
|
-
|
|
21
|
-
推荐结构:
|
|
22
|
-
|
|
23
|
-
```text
|
|
24
|
-
business/
|
|
25
|
-
App.tsx
|
|
26
|
-
features/
|
|
27
|
-
store/
|
|
28
|
-
data/
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## 图标视觉基线
|
|
32
|
-
|
|
33
|
-
图标用于辅助识别,不应压过标题、数据和主要内容。生成或修改业务页面时遵守以下约束:
|
|
34
|
-
|
|
35
|
-
- 优先使用 `@phosphor-icons/react`(模板缺省未内置,按需 `pnpm add @phosphor-icons/react` 引入;pnpm 严格 node_modules 下不随 kit 传递解析),同一区域统一图标系列、`weight`、底板形状和用色方式。浅色底板上的普通入口默认使用 `weight="regular"`;不要为了缩小图标而统一改成 `bold`,否则线条会显得拥挤、厚重。`bold` 只用于确实需要强调的单个操作,`fill` 只用于选中态或少量主操作,不要整页铺满粗线或实心图标。
|
|
36
|
-
- **Phosphor 的 `size` 属性是最终屏幕 CSS 像素,不会经过 PostCSS 的 750 稿换算。** 不要按设计稿尺寸写 `size={36}`、`size={48}`。普通导航/按钮使用 `18~24`,网格入口使用 `20~24`,列表或卡片前导图标使用 `24~28`;只有真正的空状态或主视觉才能更大。
|
|
37
|
-
- 图标底板写 Less 的 750 稿尺寸:四宫格/八宫格入口建议 `72~80px`,列表前导图标建议 `80~96px`。内部图形的视觉宽高不超过底板的 `55%~60%`。
|
|
38
|
-
- 点击热区和图标视觉尺寸分开处理。按钮可以保持足够大的可点击区域,但不要靠放大图标填满热区。
|
|
39
|
-
- 同屏多个入口默认使用浅色底板配单色图标;强渐变和高饱和底板只留给一个主操作或少量重点入口。图标容器不要同时使用大圆角、强渐变和重阴影。
|
|
40
|
-
- 列表和卡片以文字、真实图片或业务数据为主体。纯图标占位不得超过列表项高度的约 `60%`,也不得挤压标题和摘要宽度。
|
|
41
|
-
- 尺寸和颜色通过局部 class 或变量统一管理,不要在每个 JSX 图标上散落互不一致的 `size`、渐变和圆角。
|
|
42
|
-
|
|
43
|
-
示例:
|
|
44
|
-
|
|
45
|
-
```tsx
|
|
46
|
-
<button className="feature-entry">
|
|
47
|
-
<span className="feature-entry__icon">
|
|
48
|
-
<Ticket size={22} weight="regular" />
|
|
49
|
-
</span>
|
|
50
|
-
<span>优惠券</span>
|
|
51
|
-
</button>
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
```less
|
|
55
|
-
.feature-entry {
|
|
56
|
-
min-height: 112px; // 点击热区可以大于视觉图标
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.feature-entry__icon {
|
|
60
|
-
width: 76px; // 750 稿尺寸,实际约 38 CSS px
|
|
61
|
-
height: 76px;
|
|
62
|
-
border-radius: 16px;
|
|
63
|
-
display: flex;
|
|
64
|
-
align-items: center;
|
|
65
|
-
justify-content: center;
|
|
66
|
-
flex-shrink: 0;
|
|
67
|
-
color: var(--tbox-primary);
|
|
68
|
-
background: var(--tbox-primary-light);
|
|
69
|
-
}
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
## 对话智能体应用
|
|
73
|
-
|
|
74
|
-
保留平台对话能力时继续使用 `AgentChatApp`。缺省无 landing 注入:空态首屏 = 平台对话,服务端欢迎卡经 `engine.emitCard` 旁路呈现(012 出卡协议);mall 形态(`--profile mall`)下首屏由 home 槽供给(`MallHome`,来源 = `mall-core 模块`)。生成欢迎卡的智能体可直接由服务端出卡,无需改 `App.tsx`。
|
|
75
|
-
|
|
76
|
-
修改对话组件、卡片或服务端工具时再读取对应目录的 `AGENTS.md`。不要修改通用首页入口来写死具体行业内容。
|
package/apps/client/src/main.tsx
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { StrictMode } from 'react';
|
|
2
|
-
import { createRoot } from 'react-dom/client';
|
|
3
|
-
import { configureRuntime, createLogger, installGlobalErrorReporting } from '@tbox.cn/app-agent-sdk-client';
|
|
4
|
-
import App from './app';
|
|
5
|
-
import { configureChatConfigDefaults } from '@app/agent-ui-kit';
|
|
6
|
-
import '@app/agent-ui-kit/theme/global.less';
|
|
7
|
-
// 品牌主题(出厂接线——theme-tbox 平台品牌资产包:素材/标题经本包承载,模块零品牌资产)。
|
|
8
|
-
// 换主题 = 替换三行(index.css + brand.js + applyTheme;叠加会致旧主题残留死重);
|
|
9
|
-
// 部署者轨迹见 cookbook·build-app-image「主题接线」。CLI 自由区,module sync 永不触碰。
|
|
10
|
-
import '@tbox.cn/app-theme-tbox/index.css';
|
|
11
|
-
import '@tbox.cn/app-theme-tbox/brand.js';
|
|
12
|
-
import { applyTheme } from '@app/agent-ui-kit/theme';
|
|
13
|
-
applyTheme('tbox');
|
|
14
|
-
// chat.json 构建期快照 → kit 静态配置 store(createRoot 前注入,首帧即快照值;
|
|
15
|
-
// HELLO_ACK settings 达后经 ChatPage 内水合覆盖)
|
|
16
|
-
import chatConfigJson from '../../../config/chat.json';
|
|
17
|
-
|
|
18
|
-
const bootLogger = createLogger('BOOT');
|
|
19
|
-
|
|
20
|
-
// 壳→H5 接入契约观测:落页即打印 URL 参数(search + hash 双读源,全量加载仅一次)。
|
|
21
|
-
// 壳侧若把参数移进 hash,mall-scope-url 的 search-only 读源会静默失效——这里第一时间暴露。
|
|
22
|
-
// code/token 类值部分脱敏(前缀 + 长度,对齐 provider log-redact 惯例)。
|
|
23
|
-
const SENSITIVE_PARAM = /^(code|token|auth_code|visitortoken|session)$/i;
|
|
24
|
-
const collectParams = (source: string): Record<string, string> => {
|
|
25
|
-
const out: Record<string, string> = {};
|
|
26
|
-
new URLSearchParams(source).forEach((value, key) => {
|
|
27
|
-
out[key] = SENSITIVE_PARAM.test(key) ? `${value.slice(0, 6)}…(len=${value.length})` : value;
|
|
28
|
-
});
|
|
29
|
-
return out;
|
|
30
|
-
};
|
|
31
|
-
const hashQuery = window.location.hash.includes('?')
|
|
32
|
-
? window.location.hash.slice(window.location.hash.indexOf('?') + 1)
|
|
33
|
-
: '';
|
|
34
|
-
bootLogger.info(
|
|
35
|
-
`url params: ${JSON.stringify({ search: collectParams(window.location.search), hash: collectParams(hashQuery) })}`,
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
// H1:环境值注入点(SDK 零 Vite 依赖)——VITE_API_URL 空串 = 同源相对路径
|
|
39
|
-
configureRuntime({ apiBaseUrl: import.meta.env.VITE_API_URL as string | undefined });
|
|
40
|
-
|
|
41
|
-
// 全局错误兜底:未捕获异常/rejection → 统一日志行(本地落地;上报扩展点见 SDK client logger)
|
|
42
|
-
installGlobalErrorReporting();
|
|
43
|
-
|
|
44
|
-
configureChatConfigDefaults(chatConfigJson as Record<string, unknown>);
|
|
45
|
-
|
|
46
|
-
const el = document.getElementById('root');
|
|
47
|
-
|
|
48
|
-
if (el) {
|
|
49
|
-
createRoot(el).render(
|
|
50
|
-
<StrictMode>
|
|
51
|
-
<App />
|
|
52
|
-
</StrictMode>,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 客户端模块注册装配文件(与 apps/server/src/modules.ts 逐行同构)。
|
|
3
|
-
* tbox CLI 协助维护锚点区;你也可以直接编辑自由区。
|
|
4
|
-
*
|
|
5
|
-
* 锚点区:@tbox:imports-begin/end(模块 import 行)+ @tbox:register-begin/end(模块数组)
|
|
6
|
-
* CLI 行为:增量插入/删除模块行,保留非标行。
|
|
7
|
-
*/
|
|
8
|
-
import type { ClientContext, InferModuleCards } from '@tbox.cn/app-agent-sdk-client';
|
|
9
|
-
|
|
10
|
-
// @tbox:imports-begin
|
|
11
|
-
// 其余能力经 `npx --yes @tbox.cn/app-cli module add` 扩展(shopping-guide/member 等商圈模块;mall-core 经 profiles/mall)
|
|
12
|
-
// @tbox:imports-end
|
|
13
|
-
|
|
14
|
-
// @tbox:register-begin
|
|
15
|
-
// 单一模板统一化:缺省出厂 = 空装配(chat 流;home 槽缺席 → chat 形态派生)——
|
|
16
|
-
// mall-core(home 槽/覆盖卡/内联过滤)经 profiles/mall 加装(接线)。
|
|
17
|
-
// 形态约定:数组恒多行(register 锚区行式插入依赖换行结构;单行 [] 会让 add 只插 import 不插注册行)
|
|
18
|
-
const modules = [
|
|
19
|
-
] as const;
|
|
20
|
-
// @tbox:register-end
|
|
21
|
-
|
|
22
|
-
// 自由区:可做装配级定制——条件注册、顺序调整
|
|
23
|
-
|
|
24
|
-
/** 注册所有已安装模块(客户端装配——勿与 apps/server/src/modules.ts 混淆) */
|
|
25
|
-
export function registerAll(ctx: ClientContext): void {
|
|
26
|
-
// 空装配下 (typeof modules)[number] = never:经最小注册面断言遍历(add 模块后自动收缩为具体类型)
|
|
27
|
-
for (const m of modules as readonly { register(ctx: ClientContext): void }[]) {
|
|
28
|
-
m.register(ctx);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// 类型从运行时装配数组自动推导:增删模块后 CardType 自动收缩/扩展(002 §6.7)
|
|
33
|
-
export type CardType = InferModuleCards<(typeof modules)[number]>;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { ServerContext } from '@tbox.cn/app-agent-sdk-server';
|
|
2
|
-
import { translateTool } from './tools/translate.js';
|
|
3
|
-
import { clockTool } from './tools/clock.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* apps 级工具统一注册面(010:双注册面同步):
|
|
7
|
-
* start()(运行时)与 cli/collect-registry.ts(doctor/inspect 视图)两处同调本函数,
|
|
8
|
-
* 未来新增 apps 级工具只改此处,避免两处注册面失同步(R 评审修正)。
|
|
9
|
-
* mall-info(含 preTool/缓存)迁 module-mall-core(模块注册面自持)。
|
|
10
|
-
*/
|
|
11
|
-
export function registerAppTools(ctx: ServerContext): void {
|
|
12
|
-
ctx.tools.register(translateTool);
|
|
13
|
-
ctx.tools.register(clockTool);
|
|
14
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 服务端模块注册装配文件(与 apps/client/src/modules.ts 逐行同构)。
|
|
3
|
-
* tbox CLI 协助维护锚点区;你也可以直接编辑自由区。
|
|
4
|
-
*
|
|
5
|
-
* 锚点区:@tbox:imports-begin/end(模块 import 行)+ @tbox:register-begin/end(模块数组)
|
|
6
|
-
* CLI 行为:增量插入/删除模块行,保留非标行。
|
|
7
|
-
*/
|
|
8
|
-
import type { ServerContext, InferModuleCards } from '@tbox.cn/app-agent-sdk-server';
|
|
9
|
-
|
|
10
|
-
// @tbox:imports-begin
|
|
11
|
-
// SDK 装配框架(非模块行,CLI 增量维护保留非标行)
|
|
12
|
-
import { registerServerModules } from '@tbox.cn/app-agent-sdk-server';
|
|
13
|
-
import { serverModule as providerCustom } from '@app/provider-custom/server';
|
|
14
|
-
// @tbox:imports-end
|
|
15
|
-
|
|
16
|
-
// @tbox:register-begin
|
|
17
|
-
// 单一模板统一化:缺省出厂 = 空装配(仅 provider-custom 自定义 API 落点 + contracts-mall shim)——
|
|
18
|
-
// mall 能力(mall-core + 业务模块)经 profiles/mall 加装(npx --yes @tbox.cn/app-cli create --profile mall, 接线)
|
|
19
|
-
// footer `] as const` 为空数组类型锚(CLI 增删模块时保留变体)
|
|
20
|
-
const modules = [
|
|
21
|
-
providerCustom,
|
|
22
|
-
] as const;
|
|
23
|
-
// @tbox:register-end
|
|
24
|
-
|
|
25
|
-
// 自由区:可做装配级定制——条件注册、顺序调整、包裹中间件
|
|
26
|
-
// const dynamicModule = process.env.ENABLE_X ? xModule : null;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 注册所有已安装模块(服务端装配——勿与 apps/client/src/modules.ts 混淆)。
|
|
30
|
-
* 010 下沉:声明式字段自动注册(skills/preTools)与 async register 等待由
|
|
31
|
-
* SDK registerServerModules 承载——未来新增声明式字段只改 SDK,本文件零改动。
|
|
32
|
-
*/
|
|
33
|
-
export function registerAll(ctx: ServerContext): Promise<void> {
|
|
34
|
-
return registerServerModules(ctx, modules);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 类型从运行时装配数组自动推导:增删模块后 CardType 自动收缩/扩展(002 §6.7)
|
|
38
|
-
export type CardType = InferModuleCards<(typeof modules)[number]>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|