@tbox.cn/app-cli 1.0.0-alpha.4 → 1.0.0-alpha.6
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/README.md +12 -0
- package/dist/chunk-H674JLDR.js +11 -0
- package/dist/chunk-M4PMIFN7.js +17 -0
- package/dist/{chunk-735OVBDV.js → chunk-SBUQHMW4.js} +1 -1
- package/dist/core.d.ts +10 -3
- package/dist/core.js +1 -1
- package/dist/{declared-Y3HHI2LL.js → declared-LRF2J6XQ.js} +1 -1
- package/dist/index.js +131 -84
- package/package.json +5 -5
- package/scaffold/app-action/apps/server/src/actions/__ID__.action.ts +25 -0
- package/scaffold/app-action/scaffold.json +1 -0
- package/scaffold/app-card/apps/client/src/cards/__ID__.card.tsx +23 -0
- package/scaffold/app-card/apps/server/src/cards/__ID__.card.ts +24 -0
- package/scaffold/app-card/packages/shared/src/cards/__ID__.ts +18 -0
- package/scaffold/app-card/scaffold.json +1 -0
- package/scaffold/app-scenario/scaffold.json +1 -0
- package/scaffold/app-scenario/scenarios/__ID__.json +13 -0
- package/scaffold/app-state/apps/server/src/state/__ID__.ts +31 -0
- package/scaffold/app-state/scaffold.json +1 -0
- package/scaffold/app-tool/apps/server/src/tools/__ID__.tool.ts +32 -0
- package/scaffold/app-tool/scaffold.json +1 -0
- package/scaffold/archetypes/README.md +27 -0
- package/scaffold/archetypes/activity-list/card.tsx.tpl +55 -0
- package/scaffold/archetypes/bill/card.tsx.tpl +38 -0
- package/scaffold/archetypes/entity-list/card.tsx.tpl +43 -0
- package/scaffold/archetypes/hero-stats/card.tsx.tpl +35 -0
- package/scaffold/archetypes/info/card.tsx.tpl +28 -0
- package/scaffold/archetypes/route/card.tsx.tpl +34 -0
- package/scaffold/archetypes/ticket-list/card.tsx.tpl +49 -0
- package/scaffold/theme/index.css +2 -2
- package/scaffold/theme/tokens.css +1 -1
- package/skills/client-runtime.md +45 -0
- package/starter/agent.md +22 -0
- package/dist/chunk-24FH6YZH.js +0 -17
- package/dist/chunk-MYYUZ76H.js +0 -11
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tbox.cn/app-cli",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.6",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "tbox-app CLI(生成应用面):starter / create / new / skills / schema / module add|remove|list|sync|diff|doctor|inspect|update / provider / theme / miniapp-container(纯函数核心 + commander 薄壳)。仓内开发命令见私有 @tbox.cn/app-cli-dev。",
|
|
5
|
+
"description": "tbox-app CLI(生成应用面):starter / create / new / skills / schema / module add|remove|list|sync|diff|doctor|inspect|update / provider / theme / home / miniapp-container(纯函数核心 + commander 薄壳)。仓内开发命令见私有 @tbox.cn/app-cli-dev。",
|
|
6
6
|
"bin": {
|
|
7
7
|
"tbox-app": "dist/index.js"
|
|
8
8
|
},
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"zod": "3.25.76",
|
|
36
36
|
"jsonc-parser": "3.3.1",
|
|
37
37
|
"zod-to-json-schema": "3.25.2",
|
|
38
|
-
"@tbox.cn/app-toolkit": "1.0.0-alpha.
|
|
39
|
-
"@tbox.cn/app-build": "1.0.0-alpha.
|
|
38
|
+
"@tbox.cn/app-toolkit": "1.0.0-alpha.6",
|
|
39
|
+
"@tbox.cn/app-build": "1.0.0-alpha.6"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/diff": "7.0.2",
|
|
43
43
|
"@types/node": "24.13.3",
|
|
44
44
|
"tsup": "8.5.1",
|
|
45
45
|
"vitest": "4.1.10",
|
|
46
|
-
"@tbox.cn/app-contracts": "1.0.0-alpha.
|
|
46
|
+
"@tbox.cn/app-contracts": "1.0.0-alpha.6"
|
|
47
47
|
},
|
|
48
48
|
"license": "MIT",
|
|
49
49
|
"publishConfig": {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// #region recipe:action
|
|
2
|
+
import { actionResult, defineAction } from '@tbox.cn/app-agent-sdk-server';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* __TITLE__ 动作:卡片上的确定性入口,点击后直接执行,不过模型。
|
|
7
|
+
*
|
|
8
|
+
* - `id` 全局唯一,卡片里用 `invoke('__ID__')` 触发;
|
|
9
|
+
* - `cardType` 决定这张动作挂在哪种卡上(出卡时平台按它签发令牌);
|
|
10
|
+
* - 写操作用 `singleUse: true` 防重复提交;
|
|
11
|
+
* - 结果用 `actionResult.notice` / `updateResult(card, data)` / `cardResult(card, data)` 构造:
|
|
12
|
+
* 本卡状态变了用 update,另一类结果用 card,只要一句提示用 notice;不要同时返回 card 与 update。
|
|
13
|
+
*/
|
|
14
|
+
export const action = defineAction({
|
|
15
|
+
id: '__ID__',
|
|
16
|
+
cardType: '__CARD_TYPE__',
|
|
17
|
+
inputSchema: z.object({}),
|
|
18
|
+
singleUse: true,
|
|
19
|
+
label: '__TITLE__',
|
|
20
|
+
async execute(_input, { userId }) {
|
|
21
|
+
// 幂等判断放在写副作用之前:同一业务键只生效一次
|
|
22
|
+
return actionResult.notice(`已处理(${userId})`);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
// #endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"targets": ["agent"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// #region recipe:card-client
|
|
2
|
+
import type { __PASCAL__CardData } from '@app/shared/cards/__ID__';
|
|
3
|
+
import { Card, CardHeader, KeyValueList, StatusTag, defineCard } from '@tbox.cn/app-agent-ui-kit';
|
|
4
|
+
import type { CardRenderProps } from '@tbox.cn/app-agent-ui-kit';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* __ID__ 卡片的客户端渲染。
|
|
8
|
+
* - `type` 与同 base 的服务端 `cardType` 必须相同;
|
|
9
|
+
* - 组件入参由 `defineCard` 固定(data / cardId / isHistory / actionTokens);
|
|
10
|
+
* - 排版用 kit 基元(Card / KeyValueList / StatusTag …),基元表达不了的用工具类,不新建样式文件;
|
|
11
|
+
* - 要加按钮时用 `useCardActions()`:`send` 走模型、`invoke` 走卡片动作、`disabled` 统一门控。
|
|
12
|
+
*/
|
|
13
|
+
function __PASCAL__Card({ data }: CardRenderProps<__PASCAL__CardData>) {
|
|
14
|
+
return (
|
|
15
|
+
<Card>
|
|
16
|
+
<CardHeader title={data.title} status={<StatusTag tone="info">{data.status}</StatusTag>} />
|
|
17
|
+
<KeyValueList items={data.rows.map((row) => ({ label: row.label, value: row.value }))} />
|
|
18
|
+
</Card>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const card = defineCard({ type: '__ID__' }, __PASCAL__Card);
|
|
23
|
+
// #endregion
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// #region recipe:card-meta
|
|
2
|
+
import type { CardMeta } from '@tbox.cn/app-contracts';
|
|
3
|
+
import { __CAMEL__CardSchema } from '@app/shared/cards/__ID__';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* __ID__ 卡片的服务端声明。三条约束:
|
|
7
|
+
* - `cardType` 必须是字符串字面量(app-build 扫描器读静态值),且与客户端 `defineCard` 的 `type` 相同;
|
|
8
|
+
* - `dataSchema` 直接引用 `@app/shared` 的 schema(形状只写一处,客户端只 import 类型);
|
|
9
|
+
* - `sampleData` / `samples` 必须是静态字面量:`card render` 与场景断言按字面量读取,
|
|
10
|
+
* 引用常量或函数会读不到(doctor 与 check:fast 都会提示)。
|
|
11
|
+
*/
|
|
12
|
+
export const card = {
|
|
13
|
+
cardType: '__ID__',
|
|
14
|
+
dataSchema: __CAMEL__CardSchema,
|
|
15
|
+
displayName: '__TITLE__',
|
|
16
|
+
description: '__TITLE__ 卡片(待补充说明)',
|
|
17
|
+
sampleData: {
|
|
18
|
+
title: '__TITLE__',
|
|
19
|
+
status: '示例状态',
|
|
20
|
+
rows: [{ label: '示例字段', value: '示例值' }],
|
|
21
|
+
},
|
|
22
|
+
schemaVersion: 1,
|
|
23
|
+
} satisfies CardMeta<typeof __CAMEL__CardSchema>;
|
|
24
|
+
// #endregion
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// #region recipe:card-schema
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* __ID__ 卡片的数据形状:两端共用的唯一声明。
|
|
6
|
+
*
|
|
7
|
+
* - schema 与类型由 `z.infer` 单点推导,不再手写第二份 interface;
|
|
8
|
+
* - 服务端 `apps/server/src/cards/__ID__.card.ts` 直接引用本 schema;
|
|
9
|
+
* - 客户端只允许 `import type`,schema 的运行时(zod)不进客户端产物。
|
|
10
|
+
*/
|
|
11
|
+
export const __CAMEL__CardSchema = z.object({
|
|
12
|
+
title: z.string(),
|
|
13
|
+
status: z.string(),
|
|
14
|
+
rows: z.array(z.object({ label: z.string(), value: z.string() })),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export type __PASCAL__CardData = z.infer<typeof __CAMEL__CardSchema>;
|
|
18
|
+
// #endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"targets": ["agent"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"targets": ["agent"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// #region recipe:state
|
|
2
|
+
import { createUserState } from '@tbox.cn/app-agent-sdk-server';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* __TITLE__ 的用户状态(按 userId 隔离,进程内)。
|
|
6
|
+
*
|
|
7
|
+
* - 默认进程内、重启即丢;`createUserState(init, { persist: 'file' })` 落盘到应用根 .tbox/state/;
|
|
8
|
+
* - 需要跨重启或跨实例时,把这块能力做成 `modules/<id>`,在 `register(ctx)` 里用 `ctx.state`;
|
|
9
|
+
* - 写操作先判幂等(同一业务键只生效一次),再改数据。
|
|
10
|
+
*/
|
|
11
|
+
export interface __PASCAL__State {
|
|
12
|
+
/** 业务状态,按需增删字段 */
|
|
13
|
+
status: 'idle' | 'active';
|
|
14
|
+
updatedAt: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const __CAMEL__State = createUserState<__PASCAL__State>(() => ({
|
|
18
|
+
status: 'idle',
|
|
19
|
+
updatedAt: new Date(0).toISOString(),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
/** 幂等写:只有状态真正变化时才更新时间戳 */
|
|
23
|
+
export function mark__PASCAL__(userId: string, status: __PASCAL__State['status']): __PASCAL__State {
|
|
24
|
+
return __CAMEL__State.update(userId, (draft) => {
|
|
25
|
+
if (draft.status !== status) {
|
|
26
|
+
draft.status = status;
|
|
27
|
+
draft.updatedAt = new Date().toISOString();
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
// #endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"targets": ["agent"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// #region recipe:tool
|
|
2
|
+
import { defineTool } from '@tbox.cn/app-agent-sdk-server';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* __ID__ 工具:把一次查询或操作做成模型可调用的能力。
|
|
7
|
+
* - `id` 必须是字符串字面量(app-build 扫描器读静态值),同类工具 id 唯一;
|
|
8
|
+
* - `description` 写「什么时候用」,出卡工具在末尾声明会附卡片;
|
|
9
|
+
* - `execute` 第二参拿到 `{ userId, identity }`,不要自己兜底成固定字符串;
|
|
10
|
+
* - 有对应卡片模块时加 `cards: [card]`,描述会自动补出卡提示(这里不假设卡片存在,故手写提示)。
|
|
11
|
+
*/
|
|
12
|
+
export const tool = defineTool({
|
|
13
|
+
id: '__ID__',
|
|
14
|
+
description: '__TITLE__:调用后返回 __TITLE__ 的事实数据。命中数据时结果附可展示卡片(cards)。',
|
|
15
|
+
inputSchema: z.object({}),
|
|
16
|
+
// 出卡工具不声明 outputSchema:出参解析会把保留字段 `cards` 剥掉,卡片随之消失。
|
|
17
|
+
// 需要约束出参形状时,用 `z.object({...}).passthrough()` 并保留 cards 可选。
|
|
18
|
+
execute: async (_args, { userId, identity }) => {
|
|
19
|
+
// 业务事实:这里的示例只回显身份,替换成真实查询或写入。
|
|
20
|
+
const facts = {
|
|
21
|
+
title: '__TITLE__',
|
|
22
|
+
status: identity.source === 'guest' ? '访客' : '已登录',
|
|
23
|
+
rows: [
|
|
24
|
+
{ label: '用户', value: userId },
|
|
25
|
+
{ label: '来源', value: identity.source },
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
// 出卡:cards 是保留字段,模型看到的是 { id, cardType, note } 摘要,data 只进卡片渲染。
|
|
29
|
+
return { ...facts, cards: [{ cardType: '__ID__', data: facts, note: '__TITLE__ 数据' }] };
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
// #endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"targets": ["agent"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# 卡片原型(archetypes)
|
|
2
|
+
|
|
3
|
+
蓝图命令按规格里的 `archetype` 选择本目录下的 `<name>/card.tsx.tpl`,把它展开成
|
|
4
|
+
`apps/client/src/cards/<id>.card.tsx`。新增原型 = 新建一个目录并放 `card.tsx.tpl`;
|
|
5
|
+
CLI 代码零改动。
|
|
6
|
+
|
|
7
|
+
模板是一份完整 tsx(数据契约类型、`defineCard` 与 `export const card` 都在模板里),
|
|
8
|
+
CLI 只替换双下划线 token:
|
|
9
|
+
|
|
10
|
+
| token | 含义 |
|
|
11
|
+
|---|---|
|
|
12
|
+
| `__ID__` | 卡片 id(= cardType) |
|
|
13
|
+
| `__TITLE__` | 卡片标题 |
|
|
14
|
+
| `__CAMEL__` / `__PASCAL__` | id 的驼峰 / 帕斯卡形式 |
|
|
15
|
+
| `__TYPE__` | 共享包导出的数据类型名(`<Pascal>CardData`) |
|
|
16
|
+
| `__SCHEMA__` | 共享包导出的 zod schema 名(`<camel>CardSchema`) |
|
|
17
|
+
| `__FIELDS_VIEW__` | `record` + `fields` 视图数组(key/label/kind/value,枚举带 values) |
|
|
18
|
+
| `__TEXT_HELPER__` | 把任意字段值显示成文字的 `text()` 函数 |
|
|
19
|
+
| `__ACTIONS_PROPS__` | 有动作时的解构片段 `, cardId, isHistory, actionTokens` |
|
|
20
|
+
| `__ACTIONS_IMPORT__` | 有动作时的 `ActionList` / `useCardActions` import |
|
|
21
|
+
| `__ACTIONS_HOOK__` | 有动作时的 `useCardActions(...)` 调用 |
|
|
22
|
+
| `__ACTIONS_BLOCK__` | 有动作时的 `<ActionList ... />` |
|
|
23
|
+
|
|
24
|
+
模板里的 token 必须全部被替换(否则生成报错)。版式与基元选择只写在模板里:
|
|
25
|
+
`info` = Card + CardHeader + KeyValueList,`bill` = Bill + KeyValueList,`ticket-list` = Ticket 列表,
|
|
26
|
+
`entity-list` = EntityRow 列表,`route` = Steps,`hero-stats` = Hero + StatGrid,
|
|
27
|
+
`activity-list` = EntityRow + TagList。
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { __TYPE__ } from '@app/shared/cards/__ID__';
|
|
2
|
+
import { Card, CardHeader, EntityRow, StatusTag, TagList, defineCard } from '@app/agent-ui-kit';
|
|
3
|
+
import type { CardRenderProps } from '@app/agent-ui-kit';
|
|
4
|
+
__ACTIONS_IMPORT__
|
|
5
|
+
/**
|
|
6
|
+
* __TITLE__ 卡片(activity-list 原型):活动行 + 标签组。
|
|
7
|
+
*
|
|
8
|
+
* 有数组字段时逐项出 EntityRow;数组字段的值同时作为标签组。
|
|
9
|
+
*/
|
|
10
|
+
function __PASCAL__Card({ data__ACTIONS_PROPS__ }: CardRenderProps<__TYPE__>) {
|
|
11
|
+
__FIELDS_VIEW__
|
|
12
|
+
|
|
13
|
+
__TEXT_HELPER__
|
|
14
|
+
__ACTIONS_HOOK__
|
|
15
|
+
const statusField = fields.find((field) => field.key === 'status') ?? fields.find((field) => field.kind === 'enum');
|
|
16
|
+
const listField = fields.find((field) => field.kind === 'array');
|
|
17
|
+
const listValues = listField && Array.isArray(listField.value) ? listField.value : [];
|
|
18
|
+
const titleField = fields.find((field) => field.kind === 'string');
|
|
19
|
+
const priceField = fields.find((field) => field.kind === 'number');
|
|
20
|
+
const tagFields = fields.filter((field) => field.kind === 'array' && field !== listField);
|
|
21
|
+
const metaFields = fields.filter(
|
|
22
|
+
(field) => field !== titleField && field !== priceField && field !== statusField && !tagFields.includes(field),
|
|
23
|
+
);
|
|
24
|
+
const tags = tagFields.flatMap((field) =>
|
|
25
|
+
Array.isArray(field.value) ? field.value.map((item) => text(item)) : [text(field.value)],
|
|
26
|
+
);
|
|
27
|
+
return (
|
|
28
|
+
<Card>
|
|
29
|
+
<CardHeader
|
|
30
|
+
title="__TITLE__"
|
|
31
|
+
status={statusField ? <StatusTag tone="info">{text(statusField.value)}</StatusTag> : undefined}
|
|
32
|
+
/>
|
|
33
|
+
{listField && listValues.length > 0
|
|
34
|
+
? listValues.map((item, index) => (
|
|
35
|
+
<EntityRow
|
|
36
|
+
key={index}
|
|
37
|
+
title={text(item)}
|
|
38
|
+
meta={listField.label}
|
|
39
|
+
price={priceField ? text(priceField.value) : undefined}
|
|
40
|
+
/>
|
|
41
|
+
))
|
|
42
|
+
: (
|
|
43
|
+
<EntityRow
|
|
44
|
+
title={titleField ? text(titleField.value) : '__TITLE__'}
|
|
45
|
+
meta={metaFields.map((field) => `${field.label} ${text(field.value)}`).join(' · ')}
|
|
46
|
+
price={priceField ? text(priceField.value) : undefined}
|
|
47
|
+
/>
|
|
48
|
+
)}
|
|
49
|
+
{tags.length > 0 ? <TagList tags={tags} /> : null}
|
|
50
|
+
__ACTIONS_BLOCK__
|
|
51
|
+
</Card>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const card = defineCard({ type: '__ID__' }, __PASCAL__Card);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { __TYPE__ } from '@app/shared/cards/__ID__';
|
|
2
|
+
import { Bill, Card, CardHeader, KeyValueList, StatusTag, defineCard } from '@app/agent-ui-kit';
|
|
3
|
+
import type { CardRenderProps } from '@app/agent-ui-kit';
|
|
4
|
+
__ACTIONS_IMPORT__
|
|
5
|
+
/**
|
|
6
|
+
* __TITLE__ 卡片(bill 原型):金额明细 + 其余属性。
|
|
7
|
+
*
|
|
8
|
+
* 第一个 number 字段作为合计,其余 number 字段作为明细行。
|
|
9
|
+
*/
|
|
10
|
+
function __PASCAL__Card({ data__ACTIONS_PROPS__ }: CardRenderProps<__TYPE__>) {
|
|
11
|
+
__FIELDS_VIEW__
|
|
12
|
+
|
|
13
|
+
__TEXT_HELPER__
|
|
14
|
+
__ACTIONS_HOOK__
|
|
15
|
+
const statusField = fields.find((field) => field.key === 'status') ?? fields.find((field) => field.kind === 'enum');
|
|
16
|
+
const numbers = fields.filter((field) => field.kind === 'number');
|
|
17
|
+
const totalField = numbers[0];
|
|
18
|
+
const lineFields = numbers.slice(1);
|
|
19
|
+
const textFields = fields.filter((field) => field.kind !== 'number');
|
|
20
|
+
return (
|
|
21
|
+
<Card>
|
|
22
|
+
<CardHeader
|
|
23
|
+
title="__TITLE__"
|
|
24
|
+
status={statusField ? <StatusTag tone="info">{text(statusField.value)}</StatusTag> : undefined}
|
|
25
|
+
/>
|
|
26
|
+
<Bill
|
|
27
|
+
lines={lineFields.map((field) => ({ label: field.label, value: text(field.value), muted: true }))}
|
|
28
|
+
total={totalField ? { label: totalField.label, value: text(totalField.value) } : undefined}
|
|
29
|
+
/>
|
|
30
|
+
{textFields.length > 0 ? (
|
|
31
|
+
<KeyValueList items={textFields.map((field) => ({ label: field.label, value: text(field.value) }))} />
|
|
32
|
+
) : null}
|
|
33
|
+
__ACTIONS_BLOCK__
|
|
34
|
+
</Card>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const card = defineCard({ type: '__ID__' }, __PASCAL__Card);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { __TYPE__ } from '@app/shared/cards/__ID__';
|
|
2
|
+
import { Card, CardHeader, EntityRow, StatusTag, defineCard } from '@app/agent-ui-kit';
|
|
3
|
+
import type { CardRenderProps } from '@app/agent-ui-kit';
|
|
4
|
+
__ACTIONS_IMPORT__
|
|
5
|
+
/**
|
|
6
|
+
* __TITLE__ 卡片(entity-list 原型):实体行列表。
|
|
7
|
+
*
|
|
8
|
+
* 有数组字段时逐项出 EntityRow;没有数组字段时把顶层字段拼成一行。
|
|
9
|
+
*/
|
|
10
|
+
function __PASCAL__Card({ data__ACTIONS_PROPS__ }: CardRenderProps<__TYPE__>) {
|
|
11
|
+
__FIELDS_VIEW__
|
|
12
|
+
|
|
13
|
+
__TEXT_HELPER__
|
|
14
|
+
__ACTIONS_HOOK__
|
|
15
|
+
const statusField = fields.find((field) => field.key === 'status') ?? fields.find((field) => field.kind === 'enum');
|
|
16
|
+
const listField = fields.find((field) => field.kind === 'array');
|
|
17
|
+
const listValues = listField && Array.isArray(listField.value) ? listField.value : [];
|
|
18
|
+
const titleField = fields.find((field) => field.kind === 'string');
|
|
19
|
+
const priceField = fields.find((field) => field.kind === 'number');
|
|
20
|
+
const metaFields = fields.filter((field) => field !== titleField && field !== priceField && field !== statusField);
|
|
21
|
+
return (
|
|
22
|
+
<Card>
|
|
23
|
+
<CardHeader
|
|
24
|
+
title="__TITLE__"
|
|
25
|
+
status={statusField ? <StatusTag tone="info">{text(statusField.value)}</StatusTag> : undefined}
|
|
26
|
+
/>
|
|
27
|
+
{listField && listValues.length > 0
|
|
28
|
+
? listValues.map((item, index) => (
|
|
29
|
+
<EntityRow key={index} title={text(item)} meta={listField.label} />
|
|
30
|
+
))
|
|
31
|
+
: (
|
|
32
|
+
<EntityRow
|
|
33
|
+
title={titleField ? text(titleField.value) : '__TITLE__'}
|
|
34
|
+
meta={metaFields.map((field) => `${field.label} ${text(field.value)}`).join(' · ')}
|
|
35
|
+
price={priceField ? text(priceField.value) : undefined}
|
|
36
|
+
/>
|
|
37
|
+
)}
|
|
38
|
+
__ACTIONS_BLOCK__
|
|
39
|
+
</Card>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const card = defineCard({ type: '__ID__' }, __PASCAL__Card);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { __TYPE__ } from '@app/shared/cards/__ID__';
|
|
2
|
+
import { Card, Hero, StatGrid, defineCard } from '@app/agent-ui-kit';
|
|
3
|
+
import type { CardRenderProps } from '@app/agent-ui-kit';
|
|
4
|
+
__ACTIONS_IMPORT__
|
|
5
|
+
/**
|
|
6
|
+
* __TITLE__ 卡片(hero-stats 原型):数字主视觉 + 并列数值格。
|
|
7
|
+
*
|
|
8
|
+
* 第一个 number 字段进 Hero,其余 number 字段进 StatGrid。
|
|
9
|
+
*/
|
|
10
|
+
function __PASCAL__Card({ data__ACTIONS_PROPS__ }: CardRenderProps<__TYPE__>) {
|
|
11
|
+
__FIELDS_VIEW__
|
|
12
|
+
|
|
13
|
+
__TEXT_HELPER__
|
|
14
|
+
__ACTIONS_HOOK__
|
|
15
|
+
const numericFields = fields.filter((field) => field.kind === 'number');
|
|
16
|
+
const heroField = numericFields[0];
|
|
17
|
+
const eyebrowField = fields.find((field) => field.kind === 'enum') ?? fields.find((field) => field.kind === 'string');
|
|
18
|
+
const footnoteField = fields.find((field) => field.kind === 'string');
|
|
19
|
+
const statFields =
|
|
20
|
+
numericFields.length > 1 ? numericFields.slice(1) : fields.filter((field) => field !== heroField).slice(0, 3);
|
|
21
|
+
return (
|
|
22
|
+
<Card>
|
|
23
|
+
<Hero
|
|
24
|
+
eyebrow={eyebrowField ? text(eyebrowField.value) : undefined}
|
|
25
|
+
title="__TITLE__"
|
|
26
|
+
value={heroField ? text(heroField.value) : undefined}
|
|
27
|
+
footnote={footnoteField ? text(footnoteField.value) : undefined}
|
|
28
|
+
/>
|
|
29
|
+
<StatGrid items={statFields.map((field) => ({ label: field.label, value: text(field.value) }))} />
|
|
30
|
+
__ACTIONS_BLOCK__
|
|
31
|
+
</Card>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const card = defineCard({ type: '__ID__' }, __PASCAL__Card);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { __TYPE__ } from '@app/shared/cards/__ID__';
|
|
2
|
+
import { Card, CardHeader, KeyValueList, StatusTag, defineCard } from '@app/agent-ui-kit';
|
|
3
|
+
import type { CardRenderProps } from '@app/agent-ui-kit';
|
|
4
|
+
__ACTIONS_IMPORT__
|
|
5
|
+
/**
|
|
6
|
+
* __TITLE__ 卡片(info 原型):标题 + 属性清单。
|
|
7
|
+
*
|
|
8
|
+
* 版式在原型模板里;要换布局时改本文件,不要改数据契约。
|
|
9
|
+
*/
|
|
10
|
+
function __PASCAL__Card({ data__ACTIONS_PROPS__ }: CardRenderProps<__TYPE__>) {
|
|
11
|
+
__FIELDS_VIEW__
|
|
12
|
+
|
|
13
|
+
__TEXT_HELPER__
|
|
14
|
+
__ACTIONS_HOOK__
|
|
15
|
+
const statusField = fields.find((field) => field.key === 'status') ?? fields.find((field) => field.kind === 'enum');
|
|
16
|
+
return (
|
|
17
|
+
<Card>
|
|
18
|
+
<CardHeader
|
|
19
|
+
title="__TITLE__"
|
|
20
|
+
status={statusField ? <StatusTag tone="info">{text(statusField.value)}</StatusTag> : undefined}
|
|
21
|
+
/>
|
|
22
|
+
<KeyValueList items={fields.map((field) => ({ label: field.label, value: text(field.value) }))} />
|
|
23
|
+
__ACTIONS_BLOCK__
|
|
24
|
+
</Card>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const card = defineCard({ type: '__ID__' }, __PASCAL__Card);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { __TYPE__ } from '@app/shared/cards/__ID__';
|
|
2
|
+
import { Card, CardHeader, StatusTag, Steps, defineCard } from '@app/agent-ui-kit';
|
|
3
|
+
import type { CardRenderProps } from '@app/agent-ui-kit';
|
|
4
|
+
__ACTIONS_IMPORT__
|
|
5
|
+
/**
|
|
6
|
+
* __TITLE__ 卡片(route 原型):步骤 / 路线。
|
|
7
|
+
*
|
|
8
|
+
* 有数组字段时逐项成步;没有数组字段时每个字段一步。
|
|
9
|
+
*/
|
|
10
|
+
function __PASCAL__Card({ data__ACTIONS_PROPS__ }: CardRenderProps<__TYPE__>) {
|
|
11
|
+
__FIELDS_VIEW__
|
|
12
|
+
|
|
13
|
+
__TEXT_HELPER__
|
|
14
|
+
__ACTIONS_HOOK__
|
|
15
|
+
const statusField = fields.find((field) => field.key === 'status') ?? fields.find((field) => field.kind === 'enum');
|
|
16
|
+
const listField = fields.find((field) => field.kind === 'array');
|
|
17
|
+
const listValues = listField && Array.isArray(listField.value) ? listField.value : [];
|
|
18
|
+
const steps =
|
|
19
|
+
listField && listValues.length > 0
|
|
20
|
+
? listValues.map((item) => ({ title: text(item), detail: listField.label }))
|
|
21
|
+
: fields.map((field) => ({ title: field.label, detail: text(field.value) }));
|
|
22
|
+
return (
|
|
23
|
+
<Card>
|
|
24
|
+
<CardHeader
|
|
25
|
+
title="__TITLE__"
|
|
26
|
+
status={statusField ? <StatusTag tone="info">{text(statusField.value)}</StatusTag> : undefined}
|
|
27
|
+
/>
|
|
28
|
+
<Steps steps={steps} />
|
|
29
|
+
__ACTIONS_BLOCK__
|
|
30
|
+
</Card>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const card = defineCard({ type: '__ID__' }, __PASCAL__Card);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { __TYPE__ } from '@app/shared/cards/__ID__';
|
|
2
|
+
import { Card, CardHeader, StatusTag, Ticket, defineCard } from '@app/agent-ui-kit';
|
|
3
|
+
import type { CardRenderProps } from '@app/agent-ui-kit';
|
|
4
|
+
__ACTIONS_IMPORT__
|
|
5
|
+
/**
|
|
6
|
+
* __TITLE__ 卡片(ticket-list 原型):票券列表。
|
|
7
|
+
*
|
|
8
|
+
* 有数组字段时逐项出 Ticket;没有数组字段时把顶层字段拼成一张票。
|
|
9
|
+
*/
|
|
10
|
+
function __PASCAL__Card({ data__ACTIONS_PROPS__ }: CardRenderProps<__TYPE__>) {
|
|
11
|
+
__FIELDS_VIEW__
|
|
12
|
+
|
|
13
|
+
__TEXT_HELPER__
|
|
14
|
+
__ACTIONS_HOOK__
|
|
15
|
+
const statusField = fields.find((field) => field.key === 'status') ?? fields.find((field) => field.kind === 'enum');
|
|
16
|
+
const listField = fields.find((field) => field.kind === 'array');
|
|
17
|
+
const listValues = listField && Array.isArray(listField.value) ? listField.value : [];
|
|
18
|
+
const amountField = fields.find((field) => field.key === 'amount') ?? fields.find((field) => field.kind === 'number');
|
|
19
|
+
const conditionField = fields.find((field) => field.kind === 'string' && field !== amountField);
|
|
20
|
+
const metaFields = fields.filter((field) => field !== amountField && field !== conditionField && field !== statusField);
|
|
21
|
+
return (
|
|
22
|
+
<Card>
|
|
23
|
+
<CardHeader
|
|
24
|
+
title="__TITLE__"
|
|
25
|
+
status={statusField ? <StatusTag tone="info">{text(statusField.value)}</StatusTag> : undefined}
|
|
26
|
+
/>
|
|
27
|
+
{listField && listValues.length > 0
|
|
28
|
+
? listValues.map((item, index) => (
|
|
29
|
+
<Ticket
|
|
30
|
+
key={index}
|
|
31
|
+
amount={text(item)}
|
|
32
|
+
condition={listField.label}
|
|
33
|
+
status={statusField ? <StatusTag tone="info">{text(statusField.value)}</StatusTag> : undefined}
|
|
34
|
+
/>
|
|
35
|
+
))
|
|
36
|
+
: (
|
|
37
|
+
<Ticket
|
|
38
|
+
amount={amountField ? text(amountField.value) : '__TITLE__'}
|
|
39
|
+
condition={conditionField ? text(conditionField.value) : undefined}
|
|
40
|
+
meta={metaFields.map((field) => `${field.label} ${text(field.value)}`).join(' · ')}
|
|
41
|
+
status={statusField ? <StatusTag tone="info">{text(statusField.value)}</StatusTag> : undefined}
|
|
42
|
+
/>
|
|
43
|
+
)}
|
|
44
|
+
__ACTIONS_BLOCK__
|
|
45
|
+
</Card>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const card = defineCard({ type: '__ID__' }, __PASCAL__Card);
|
package/scaffold/theme/index.css
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* 接线(生成应用侧三行,客户端启动层 platform/bootstrap.ts 自由区;存量应用 main.tsx):
|
|
5
5
|
* import '__PKG__/index.css';
|
|
6
6
|
* import '__PKG__/brand.js';
|
|
7
|
-
* import { applyTheme } from '@app
|
|
7
|
+
* import { applyTheme } from '@tbox.cn/app-agent-ui-kit/theme';
|
|
8
8
|
* applyTheme('__ID__');
|
|
9
9
|
* (接线管理:npx --yes @tbox.cn/app-cli theme use <id> --source <本包目录>;npx --yes @tbox.cn/app-cli theme list 查看状态)
|
|
10
10
|
*
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* domains 域色通道覆写(--tbox-domain-*)
|
|
16
16
|
* assets 素材变量覆写(--tbox-asset-* 九语义位——IP 素材唯一归宿)
|
|
17
17
|
*
|
|
18
|
-
* 覆写变量必须 ⊆ kit 主题契约封闭清单(@app
|
|
18
|
+
* 覆写变量必须 ⊆ kit 主题契约封闭清单(@tbox.cn/app-agent-ui-kit/theme/contract)。
|
|
19
19
|
*/
|
|
20
20
|
@import './tokens.css';
|
|
21
21
|
@import './motion.css';
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# 客户端运行时与装配(app.config)
|
|
2
|
+
|
|
3
|
+
## 页面入口
|
|
4
|
+
|
|
5
|
+
- 应用只写页面:`apps/client/src/pages/**/page.tsx`,目录即 URL;`export const page = { title, meta }` 是页面元数据。
|
|
6
|
+
- 入口脚本由 app-build 生成;不要创建 `apps/client/src/main.tsx`,不要手写 `.tbox-gen`。
|
|
7
|
+
- 默认不要创建 `apps/client/src/entry.tsx`。只有需要完全自定义路由/注册/挂载时才用它全量接管入口(高级逃生舱),并自行负责主题、auth、模块注册顺序。
|
|
8
|
+
|
|
9
|
+
## app.config.ts(唯一启动源码)
|
|
10
|
+
|
|
11
|
+
`apps/client/src/app.config.ts` 是客户端装配真源,生成 entry 的第一个 import。职责只有部署选择:
|
|
12
|
+
|
|
13
|
+
- 模块顶层:静态样式/主题 import;`createAuthClient({ scopeKey })`(auth 单例必须先于 modules 顶层创建)。
|
|
14
|
+
- 默认 export:`apiBaseUrl`、`setup()`(主题应用、chat 配置快照)、`shell`(自定义/关闭 Agent 壳)、`adapters`、`onSession`。
|
|
15
|
+
- 不写路由表、不注册模块/卡片、不写页面挂载;这些由 SDK 与生成 entry 统一处理。
|
|
16
|
+
|
|
17
|
+
主题接线三行落在 app.config:主题 `index.css`、`brand.js`、`applyTheme('<id>')`。换主题用 CLI `theme use <id>`(替换语义,勿叠加)。
|
|
18
|
+
|
|
19
|
+
## 启动顺序
|
|
20
|
+
|
|
21
|
+
1. 生成 entry import `app.config`(auth 单例/主题样式)。
|
|
22
|
+
2. import 生成 registry(模块/卡片只声明,不解析服务)。
|
|
23
|
+
3. SDK `startAgentApp` / `startApp`:运行时配置 → 全局错误上报 → URL 参数日志 → `config.setup()` → 注册卡片/模块 → 加载页面 → 渲染。
|
|
24
|
+
|
|
25
|
+
模块不要在 import 期调用 `getAuthClient()` / `getPlatformApi()` / 解析 theme/chat;延迟到 render/请求期。
|
|
26
|
+
|
|
27
|
+
## 常用命令
|
|
28
|
+
|
|
29
|
+
> 沙箱/无端口环境不要跑 `pnpm dev`/`pnpm build`(长驻进程 + Vite + 端口);改完先 `pnpm typecheck && pnpm test && pnpm verify:generated`。
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
pnpm generate # 生成 manifest/registry/entries/documents
|
|
33
|
+
pnpm check # 结构检查
|
|
34
|
+
pnpm typecheck
|
|
35
|
+
pnpm test
|
|
36
|
+
pnpm dev # 单端口 8000
|
|
37
|
+
pnpm build
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 扩展点
|
|
41
|
+
|
|
42
|
+
- 自定义 ASR/TTS/upload/feedback:在 app.config 的 `adapters` 覆盖 SDK 默认实现。
|
|
43
|
+
- 自定义壳:`shell` 传组件;不需要壳时传 `false`。
|
|
44
|
+
- 应用级 auth/platform 单例:`getAuthClient()` / `getPlatformApi()`,只在 render/请求期读取。
|
|
45
|
+
- 卡片预览:由生成 entry 的 `startCardPreview` 承载,不需要应用侧文件。
|
package/starter/agent.md
CHANGED
|
@@ -21,6 +21,28 @@ pnpm install
|
|
|
21
21
|
|
|
22
22
|
单一应用模板;缺省 create(不带 `--profile`)为带 AI 支付体验的 chat 形态。业务域形态经模板画像加装(`--profile`),商圈指南见 `npx --yes @tbox.cn/app-cli starter --type agent-mall`,全部类型 `npx --yes @tbox.cn/app-cli starter --list` 查看。
|
|
23
23
|
|
|
24
|
+
## 初始化首页
|
|
25
|
+
|
|
26
|
+
创建通用 Agent 应用时,根据用户需求自行选择一套首页并完成组装,不让用户挑选或确认,也不说明选择理由。用户指定首页(包括 `<_tbox_home>` 描述)时优先遵循;明确要求纯对话时不加首页;已有首页(尤其商圈首页)时保留现有接线。
|
|
27
|
+
|
|
28
|
+
| 首页组合 | 适用需求 | 组件顺序 |
|
|
29
|
+
|---|---|---|
|
|
30
|
+
| 服务推荐模板 | 多项服务推荐、功能导航;默认选择 | `BlockIntro` → `BlockServiceList` → `BlockServiceIconList` → `BlockQuestionList` |
|
|
31
|
+
| 此刻服务 | 当下场景、即时服务推荐 | `BlockIntro` → `BlockNowList` → `BlockServiceIconList` → `BlockBarrage` |
|
|
32
|
+
| 特色推荐模板 | 旅游、目的地或图文特色内容推荐 | `BlockIntro` → `BlockTravelCarousel` → `BlockServiceIconList`(图标网格)→ `BlockBarrage` |
|
|
33
|
+
| 快捷服务模板 | 以双列快捷服务入口为主 | `TwoCol` |
|
|
34
|
+
| IP互动模板 | IP 形象与动画互动入口 | `BlockAnimal` |
|
|
35
|
+
| 扇形卡 | 以扇形卡片浏览推荐内容 | `BlockIntroCenter` → `BlockFanSwiper` → `BlockServiceIconList`(图标网格)→ `BlockBarrage` |
|
|
36
|
+
| 基础模板 | 简洁的单列服务入口 | `OneCol` |
|
|
37
|
+
|
|
38
|
+
内容按用户业务定制,视觉遵循用户需求和已选 UI Style,不编造素材地址或真实业务数据。
|
|
39
|
+
|
|
40
|
+
初始化后读取项目根目录 `AGENTS.md`,再完成首页:
|
|
41
|
+
|
|
42
|
+
1. 用 `npx --yes @tbox.cn/app-cli home list` 查看组件,`npx --yes @tbox.cn/app-cli home inspect <id>` 读取用法。
|
|
43
|
+
2. 用 `npx --yes @tbox.cn/app-cli home add <ids...>` 复制所选组件,运行 `pnpm install`。
|
|
44
|
+
3. 按复制的 `apps/client/src/components/home/shared/home-integration.md` 组合页面并接入 home 槽;`home add` 不会自动接线。
|
|
45
|
+
|
|
24
46
|
## 模板与模块
|
|
25
47
|
|
|
26
48
|
应用模板:`@tbox.cn/app-template-agent`。模板提供浏览器与支付宝小程序 web-view 共用的 Agent 应用壳,包含 server/client、配置链与模块装配。出厂携带 agent-ui-kit 组件库、provider-custom 自定义 API 落点与 contracts-mall SDK shim,初始化时默认加装 `@tbox.cn/app-module-ai-payment`(0.01 元体验订单卡),能力经 `npx --yes @tbox.cn/app-cli module add` / `npx --yes @tbox.cn/app-cli new` 扩展。
|