@tbox.cn/app-build 0.0.0-stage → 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/LICENSE +9 -0
- package/README.md +22 -2
- package/agents/app-agent.md +5 -0
- package/agents/app-base.md +8 -0
- package/agents/app-web.md +4 -0
- package/agents/base.md +12 -0
- package/agents/kind-agent.md +5 -0
- package/agents/kind-web.md +3 -0
- package/agents/modules.md +9 -0
- package/dist/index.d.ts +200 -0
- package/dist/index.js +1038 -0
- package/package.json +45 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) tbox
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tbox.cn/app-build
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
tbox-app 1.0 构建期叶子包。负责:
|
|
4
|
+
|
|
5
|
+
- 扫描 `apps/client`、`apps/server` 与 `modules/<id>/`;
|
|
6
|
+
- 生成 `apps/client/.tbox-gen/{manifest.json,registry.*,entries,documents}`;
|
|
7
|
+
- 提供 Vite 插件;
|
|
8
|
+
- `checkApp` 结构检查;
|
|
9
|
+
- `composeAgents` / `syncAgents`。
|
|
10
|
+
|
|
11
|
+
不依赖 `@tbox.cn/app-toolkit`。
|
|
12
|
+
|
|
13
|
+
## API
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { generateApp, checkApp, tboxAppPlugin, composeAgents } from '@tbox.cn/app-build';
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
await generateApp({ root: process.cwd(), watch: true });
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
生成物是 disposable IR;不要手改。manifest 只含 `schemaVersion` 与 `pages`。
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# 应用代码
|
|
2
|
+
|
|
3
|
+
- 页面:`apps/client/src/pages/**/page.tsx`。
|
|
4
|
+
- 函数:`apps/server/src/functions/*.server.ts`,直接 import 使用。
|
|
5
|
+
- HTTP:`request`;不要新增第二套 HTTP 客户端。
|
|
6
|
+
- 共享 DTO:`packages/shared/`,导入 `@app/shared`。
|
|
7
|
+
- 构建产物:`apps/client/dist`(部署静态根)、`apps/server/dist`。
|
|
8
|
+
- 不要手写路由表;页面目录就是路由。
|
package/agents/base.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# tbox-app
|
|
2
|
+
|
|
3
|
+
这是一个 tbox-app 1.0 应用。应用代码根是 `apps/`(`apps/client` + `apps/server`)。
|
|
4
|
+
|
|
5
|
+
- `apps/client/src/pages/**/page.tsx`:页面;目录即 URL;页面元数据用 inline `export const page`。
|
|
6
|
+
- `apps/server/src/functions/*.server.ts`:函数;文件名即 `/api/fn/<id>`。
|
|
7
|
+
- `apps/server/src/tools/*.tool.ts`、`skills/*.skill.ts`、`cards/*.card.ts`:应用级原语(仅 agent)。
|
|
8
|
+
- `packages/shared/`:跨端 DTO(`@app/shared`),只放纯类型与常量。
|
|
9
|
+
- `modules/<id>/`:可复用/可分发模块;必须有 `tbox.module.json`。
|
|
10
|
+
- 不要创建 `app/`、`apps/client/src/modules.ts`、`routes.json`、`page.config.jsonc`。
|
|
11
|
+
|
|
12
|
+
修改后先运行 `pnpm check`,再按需运行 `pnpm typecheck`。
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# 模块
|
|
2
|
+
|
|
3
|
+
模块只在需要复用、分发或自定义安装后源码时创建。
|
|
4
|
+
|
|
5
|
+
- 本地模块:`modules/<id>/`,无 `package.json`。
|
|
6
|
+
- Vendored 模块:`modules/<id>/`,有 `package.json` 与 `tbox.upstream`。
|
|
7
|
+
- 两种模块都必须有 `tbox.module.json`。
|
|
8
|
+
- 模块入口:`src/server/index.ts` 导出 `serverModule`;`src/client/index.ts` 导出 `clientModule`。
|
|
9
|
+
- 模块只注册,不解析;跨模块经 `ctx`。
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
declare class AppBuildError extends Error {
|
|
4
|
+
readonly code: string;
|
|
5
|
+
readonly file?: string;
|
|
6
|
+
readonly fix?: string;
|
|
7
|
+
constructor(code: string, message: string, options?: {
|
|
8
|
+
file?: string;
|
|
9
|
+
fix?: string;
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
type AppKind = 'agent' | 'web';
|
|
14
|
+
interface AppMeta {
|
|
15
|
+
schemaVersion: 1;
|
|
16
|
+
appKind: AppKind;
|
|
17
|
+
templateVersion?: string;
|
|
18
|
+
npmModules?: unknown[];
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}
|
|
21
|
+
interface PageEntry {
|
|
22
|
+
path: string;
|
|
23
|
+
entry: string;
|
|
24
|
+
document: string;
|
|
25
|
+
title: string;
|
|
26
|
+
}
|
|
27
|
+
interface AppManifest {
|
|
28
|
+
schemaVersion: 1;
|
|
29
|
+
pages: PageEntry[];
|
|
30
|
+
}
|
|
31
|
+
interface PageMeta {
|
|
32
|
+
title: string;
|
|
33
|
+
meta?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
interface PageModule {
|
|
36
|
+
id: string;
|
|
37
|
+
route: string;
|
|
38
|
+
file: string;
|
|
39
|
+
relativeFile: string;
|
|
40
|
+
meta: PageMeta;
|
|
41
|
+
}
|
|
42
|
+
interface FunctionModule {
|
|
43
|
+
id: string;
|
|
44
|
+
file: string;
|
|
45
|
+
relativeFile: string;
|
|
46
|
+
}
|
|
47
|
+
interface ToolModule {
|
|
48
|
+
id: string;
|
|
49
|
+
file: string;
|
|
50
|
+
relativeFile: string;
|
|
51
|
+
}
|
|
52
|
+
interface SkillModule {
|
|
53
|
+
id: string;
|
|
54
|
+
file: string;
|
|
55
|
+
relativeFile: string;
|
|
56
|
+
}
|
|
57
|
+
interface CardModule {
|
|
58
|
+
cardType: string;
|
|
59
|
+
serverFile: string;
|
|
60
|
+
clientFile: string;
|
|
61
|
+
serverRelativeFile: string;
|
|
62
|
+
clientRelativeFile: string;
|
|
63
|
+
}
|
|
64
|
+
interface ModuleDescriptor {
|
|
65
|
+
schemaVersion: 1;
|
|
66
|
+
id: string;
|
|
67
|
+
version: string;
|
|
68
|
+
declare: {
|
|
69
|
+
tools?: string[];
|
|
70
|
+
cards?: Array<string | {
|
|
71
|
+
cardType: string;
|
|
72
|
+
[key: string]: unknown;
|
|
73
|
+
}>;
|
|
74
|
+
skills?: string[];
|
|
75
|
+
providers?: {
|
|
76
|
+
slots?: Array<string | Record<string, unknown>>;
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
};
|
|
79
|
+
owns?: Array<string | Record<string, unknown>>;
|
|
80
|
+
consumes?: Array<string | Record<string, unknown>>;
|
|
81
|
+
resources?: unknown[];
|
|
82
|
+
};
|
|
83
|
+
dependencies?: {
|
|
84
|
+
modules?: Array<string | {
|
|
85
|
+
id: string;
|
|
86
|
+
required?: boolean;
|
|
87
|
+
}>;
|
|
88
|
+
packages?: string[];
|
|
89
|
+
};
|
|
90
|
+
env?: string[];
|
|
91
|
+
}
|
|
92
|
+
interface LoadedModule {
|
|
93
|
+
id: string;
|
|
94
|
+
dir: string;
|
|
95
|
+
relativeDir: string;
|
|
96
|
+
descriptor: ModuleDescriptor;
|
|
97
|
+
packageName?: string;
|
|
98
|
+
vendored: boolean;
|
|
99
|
+
appKinds: AppKind[];
|
|
100
|
+
hasServer: boolean;
|
|
101
|
+
hasClient: boolean;
|
|
102
|
+
}
|
|
103
|
+
interface ScanResult {
|
|
104
|
+
root: string;
|
|
105
|
+
appDir: string;
|
|
106
|
+
appKind: AppKind;
|
|
107
|
+
pages: PageModule[];
|
|
108
|
+
functions: FunctionModule[];
|
|
109
|
+
tools: ToolModule[];
|
|
110
|
+
skills: SkillModule[];
|
|
111
|
+
cards: CardModule[];
|
|
112
|
+
modules: LoadedModule[];
|
|
113
|
+
}
|
|
114
|
+
interface GeneratedApp {
|
|
115
|
+
root: string;
|
|
116
|
+
appDir: string;
|
|
117
|
+
genDir: string;
|
|
118
|
+
appKind: AppKind;
|
|
119
|
+
manifest: AppManifest;
|
|
120
|
+
scan: ScanResult;
|
|
121
|
+
files: string[];
|
|
122
|
+
}
|
|
123
|
+
interface CheckIssue {
|
|
124
|
+
code: string;
|
|
125
|
+
severity: 'error' | 'warning';
|
|
126
|
+
file?: string;
|
|
127
|
+
message: string;
|
|
128
|
+
fix?: string;
|
|
129
|
+
}
|
|
130
|
+
interface CheckResult {
|
|
131
|
+
ok: boolean;
|
|
132
|
+
issues: CheckIssue[];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
declare function readAppMeta(root: string): Promise<AppMeta>;
|
|
136
|
+
|
|
137
|
+
declare function scanApp(root: string): Promise<ScanResult>;
|
|
138
|
+
|
|
139
|
+
declare function parsePageMeta(file: string): Promise<PageMeta>;
|
|
140
|
+
declare function scanPages(root: string): Promise<PageModule[]>;
|
|
141
|
+
|
|
142
|
+
declare const FUNCTION_ID_RE: RegExp;
|
|
143
|
+
declare function scanFunctions(root: string): Promise<FunctionModule[]>;
|
|
144
|
+
|
|
145
|
+
interface PrimitiveSet {
|
|
146
|
+
tools: ToolModule[];
|
|
147
|
+
skills: SkillModule[];
|
|
148
|
+
cards: CardModule[];
|
|
149
|
+
}
|
|
150
|
+
declare function scanAppPrimitives(root: string): Promise<PrimitiveSet>;
|
|
151
|
+
declare function scanModulePrimitives(moduleDir: string): Promise<PrimitiveSet>;
|
|
152
|
+
|
|
153
|
+
declare function scanModules(root: string): Promise<LoadedModule[]>;
|
|
154
|
+
|
|
155
|
+
interface GenerateOptions {
|
|
156
|
+
root: string;
|
|
157
|
+
watch?: boolean;
|
|
158
|
+
onManifest?: (manifest: AppManifest) => void;
|
|
159
|
+
onError?: (error: Error) => void;
|
|
160
|
+
}
|
|
161
|
+
interface GenerateResult {
|
|
162
|
+
manifest: AppManifest;
|
|
163
|
+
appKind: AppKind;
|
|
164
|
+
files: string[];
|
|
165
|
+
scan: ScanResult;
|
|
166
|
+
close: () => Promise<void>;
|
|
167
|
+
}
|
|
168
|
+
declare function buildManifest(scan: ScanResult): AppManifest;
|
|
169
|
+
declare function generateApp(options: GenerateOptions): Promise<GenerateResult>;
|
|
170
|
+
declare function listGeneratedFiles(root: string): Promise<string[]>;
|
|
171
|
+
|
|
172
|
+
declare function checkApp(options: {
|
|
173
|
+
root: string;
|
|
174
|
+
}): Promise<CheckResult>;
|
|
175
|
+
|
|
176
|
+
interface ComposeAgentsOptions {
|
|
177
|
+
appKind: AppKind;
|
|
178
|
+
hasModules?: boolean;
|
|
179
|
+
}
|
|
180
|
+
declare function composeAgents(options: ComposeAgentsOptions): Promise<{
|
|
181
|
+
root: string;
|
|
182
|
+
app: string;
|
|
183
|
+
modules?: string;
|
|
184
|
+
}>;
|
|
185
|
+
declare function wrapBlock(content: string): string;
|
|
186
|
+
declare function extractOverlay(existing: string): string;
|
|
187
|
+
declare function replaceBlock(existing: string, content: string): string;
|
|
188
|
+
interface SyncAgentsOptions extends ComposeAgentsOptions {
|
|
189
|
+
root: string;
|
|
190
|
+
allowAppend?: boolean;
|
|
191
|
+
}
|
|
192
|
+
declare function syncAgents(options: SyncAgentsOptions): Promise<string[]>;
|
|
193
|
+
|
|
194
|
+
interface TboxAppPluginOptions {
|
|
195
|
+
root?: string;
|
|
196
|
+
getManifest?: () => AppManifest;
|
|
197
|
+
}
|
|
198
|
+
declare function tboxAppPlugin(options?: TboxAppPluginOptions): Plugin;
|
|
199
|
+
|
|
200
|
+
export { AppBuildError, type AppKind, type AppManifest, type AppMeta, type CardModule, type CheckIssue, type CheckResult, FUNCTION_ID_RE, type FunctionModule, type GenerateOptions, type GenerateResult, type GeneratedApp, type LoadedModule, type ModuleDescriptor, type PageEntry, type PageMeta, type PageModule, type ScanResult, type SkillModule, type TboxAppPluginOptions, type ToolModule, buildManifest, checkApp, composeAgents, extractOverlay, generateApp, listGeneratedFiles, parsePageMeta, readAppMeta, replaceBlock, scanApp, scanAppPrimitives, scanFunctions, scanModulePrimitives, scanModules, scanPages, syncAgents, tboxAppPlugin, wrapBlock };
|