@zhin.js/scaffold-wizard 0.1.8 → 0.1.9
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 +4 -0
- package/lib/adapter-configurers.d.ts.map +1 -1
- package/lib/adapter-configurers.js +14 -53
- package/lib/adapter-configurers.js.map +1 -1
- package/lib/adapter.d.ts +17 -9
- package/lib/adapter.d.ts.map +1 -1
- package/lib/adapter.js +77 -104
- package/lib/adapter.js.map +1 -1
- package/lib/apply.d.ts +22 -1
- package/lib/apply.d.ts.map +1 -1
- package/lib/apply.js +156 -23
- package/lib/apply.js.map +1 -1
- package/lib/index.d.ts +4 -4
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/project-config-plan.d.ts +2 -0
- package/lib/project-config-plan.d.ts.map +1 -1
- package/lib/project-config-plan.js +54 -15
- package/lib/project-config-plan.js.map +1 -1
- package/lib/zhin-stack-deps.d.ts +9 -1
- package/lib/zhin-stack-deps.d.ts.map +1 -1
- package/lib/zhin-stack-deps.js +26 -10
- package/lib/zhin-stack-deps.js.map +1 -1
- package/package.json +1 -1
- package/src/adapter-configurers.ts +14 -52
- package/src/adapter.ts +91 -108
- package/src/apply.ts +170 -21
- package/src/index.ts +9 -4
- package/src/project-config-plan.ts +55 -15
- package/src/zhin-stack-deps.ts +26 -10
|
@@ -12,10 +12,19 @@ const CONFIG_CANDIDATES = [
|
|
|
12
12
|
'zhin.config.toml',
|
|
13
13
|
'zhin.config.ts',
|
|
14
14
|
] as const;
|
|
15
|
+
/** @deprecated Plugin Runtime 由 CLI 装配 Console Host,无需在配置中声明;仅用于 legacy 数组配置诊断 */
|
|
15
16
|
const CONSOLE_HOST_PLUGINS = ['@zhin.js/host-router', '@zhin.js/host-api'] as const;
|
|
16
17
|
const SANDBOX_PLUGIN = '@zhin.js/adapter-sandbox';
|
|
17
18
|
const LEGACY_AI_PROVIDER_FIELDS = ['driver', 'api', 'preset', 'spec'] as const;
|
|
18
19
|
|
|
20
|
+
/** 由插件包名推导默认 instanceKey(@zhin.js/adapter-telegram → telegram) */
|
|
21
|
+
export function packageToInstanceKey(packageName: string): string {
|
|
22
|
+
const name = packageName.includes('/')
|
|
23
|
+
? packageName.split('/').pop() ?? packageName
|
|
24
|
+
: packageName;
|
|
25
|
+
return name.replace(/^(adapter|plugin|service)-/, '');
|
|
26
|
+
}
|
|
27
|
+
|
|
19
28
|
export type ProjectConfigFormat = 'yaml' | 'json' | 'toml' | 'ts';
|
|
20
29
|
|
|
21
30
|
export interface LoadedProjectConfig {
|
|
@@ -164,17 +173,34 @@ export function loadProjectConfig(cwd = process.cwd(), configPath?: string): Loa
|
|
|
164
173
|
}
|
|
165
174
|
|
|
166
175
|
function ensurePlugins(config: Record<string, unknown>, pluginsToAdd: readonly string[], mutations: string[]): void {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
:
|
|
176
|
+
if (Array.isArray(config.plugins)) {
|
|
177
|
+
// legacy 数组形式:保持原形态追加,避免改写旧项目结构
|
|
178
|
+
const plugins = config.plugins.filter((p): p is string => typeof p === 'string');
|
|
179
|
+
let changed = false;
|
|
180
|
+
for (const plugin of pluginsToAdd) {
|
|
181
|
+
if (plugins.includes(plugin)) continue;
|
|
182
|
+
plugins.push(plugin);
|
|
183
|
+
mutations.push(`added ${plugin} to plugins`);
|
|
184
|
+
changed = true;
|
|
185
|
+
}
|
|
186
|
+
if (changed) {
|
|
187
|
+
config.plugins = plugins;
|
|
188
|
+
}
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// 新 Plugin Runtime:plugins 为 <instanceKey>: <配置> 映射
|
|
192
|
+
const plugins = config.plugins && typeof config.plugins === 'object'
|
|
193
|
+
? { ...(config.plugins as Record<string, unknown>) }
|
|
194
|
+
: {};
|
|
170
195
|
let changed = false;
|
|
171
|
-
for (const
|
|
172
|
-
|
|
173
|
-
plugins
|
|
174
|
-
|
|
196
|
+
for (const pkg of pluginsToAdd) {
|
|
197
|
+
const instanceKey = packageToInstanceKey(pkg);
|
|
198
|
+
if (instanceKey in plugins) continue;
|
|
199
|
+
plugins[instanceKey] = {};
|
|
200
|
+
mutations.push(`added ${instanceKey} (${pkg}) to plugins`);
|
|
175
201
|
changed = true;
|
|
176
202
|
}
|
|
177
|
-
if (changed || !
|
|
203
|
+
if (changed || !config.plugins || typeof config.plugins !== 'object') {
|
|
178
204
|
config.plugins = plugins;
|
|
179
205
|
}
|
|
180
206
|
}
|
|
@@ -318,7 +344,8 @@ export function createProjectConfigPlan(options: ProjectConfigPlanOptions): Proj
|
|
|
318
344
|
const mutations: string[] = [];
|
|
319
345
|
|
|
320
346
|
if (loaded.status === 'loaded' || options.config) {
|
|
321
|
-
if (options.ensureConsole) {
|
|
347
|
+
if (options.ensureConsole && Array.isArray(after.plugins)) {
|
|
348
|
+
// legacy 数组形态:host 插件仍需写入列表(旧项目行为不变)
|
|
322
349
|
ensurePlugins(after, CONSOLE_HOST_PLUGINS, mutations);
|
|
323
350
|
}
|
|
324
351
|
if (options.ensureSandbox) {
|
|
@@ -327,7 +354,8 @@ export function createProjectConfigPlan(options: ProjectConfigPlanOptions): Proj
|
|
|
327
354
|
if (options.enablePlugins?.length) {
|
|
328
355
|
ensurePlugins(after, options.enablePlugins, mutations);
|
|
329
356
|
}
|
|
330
|
-
if (options.ensureHttp) {
|
|
357
|
+
if (options.ensureConsole || options.ensureHttp) {
|
|
358
|
+
// 新形态下 Console Host 由 CLI composition root 装配;Console 可达只需 http.token + corsOrigins
|
|
331
359
|
ensureHttp(after, mutations);
|
|
332
360
|
}
|
|
333
361
|
if (options.migrateAiLegacy) {
|
|
@@ -369,17 +397,29 @@ export async function applyProjectConfigPlan(plan: ProjectConfigPlan): Promise<b
|
|
|
369
397
|
}
|
|
370
398
|
|
|
371
399
|
export function diagnoseConsoleConfig(config: Record<string, unknown>): ConsoleConfigDiagnosis {
|
|
372
|
-
const plugins = Array.isArray(config.plugins)
|
|
373
|
-
? config.plugins.filter((p): p is string => typeof p === 'string')
|
|
374
|
-
: [];
|
|
375
400
|
const http = config.http && typeof config.http === 'object' && !Array.isArray(config.http)
|
|
376
401
|
? config.http as Record<string, unknown>
|
|
377
402
|
: {};
|
|
378
403
|
const corsOrigins = Array.isArray(http.corsOrigins) ? http.corsOrigins : [];
|
|
379
404
|
|
|
405
|
+
if (Array.isArray(config.plugins)) {
|
|
406
|
+
// legacy 数组形式配置
|
|
407
|
+
const plugins = config.plugins.filter((p): p is string => typeof p === 'string');
|
|
408
|
+
return {
|
|
409
|
+
missingHostPlugins: CONSOLE_HOST_PLUGINS.filter((plugin) => !plugins.includes(plugin)),
|
|
410
|
+
missingSandboxPlugin: !plugins.includes(SANDBOX_PLUGIN),
|
|
411
|
+
missingConsoleOrigin: !hasConsoleOrigin(corsOrigins.filter((origin): origin is string => typeof origin === 'string')),
|
|
412
|
+
missingHttpToken: typeof http.token !== 'string' || http.token.trim().length === 0,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// 新 Plugin Runtime:Console Host 由 CLI 装配,无需 host 插件;Sandbox 为 plugins.sandbox 实例
|
|
417
|
+
const plugins = config.plugins && typeof config.plugins === 'object'
|
|
418
|
+
? config.plugins as Record<string, unknown>
|
|
419
|
+
: {};
|
|
380
420
|
return {
|
|
381
|
-
missingHostPlugins:
|
|
382
|
-
missingSandboxPlugin: !plugins
|
|
421
|
+
missingHostPlugins: [],
|
|
422
|
+
missingSandboxPlugin: !('sandbox' in plugins),
|
|
383
423
|
missingConsoleOrigin: !hasConsoleOrigin(corsOrigins.filter((origin): origin is string => typeof origin === 'string')),
|
|
384
424
|
missingHttpToken: typeof http.token !== 'string' || http.token.trim().length === 0,
|
|
385
425
|
};
|
package/src/zhin-stack-deps.ts
CHANGED
|
@@ -6,12 +6,20 @@ import { findMissingPackageDependencies, findUnresolvedPackageInstalls, isAiEnab
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* User project dependency policy: scaffolded dependencies intentionally float to latest.
|
|
9
|
+
* WARNING: this is not reproducible; pin versions for production. See scaffold-wizard README.
|
|
9
10
|
*/
|
|
10
11
|
export const ZHIN_STACK_VERSIONS = {
|
|
11
12
|
'zhin.js': 'latest',
|
|
12
13
|
'@zhin.js/cli': 'latest',
|
|
13
14
|
'@zhin.js/agent': 'latest',
|
|
14
15
|
'@zhin.js/database': 'latest',
|
|
16
|
+
'@zhin.js/plugin-runtime': 'latest',
|
|
17
|
+
'@zhin.js/runtime': 'latest',
|
|
18
|
+
'@zhin.js/adapter': 'latest',
|
|
19
|
+
'@zhin.js/command': 'latest',
|
|
20
|
+
'@zhin.js/component': 'latest',
|
|
21
|
+
'@zhin.js/core': 'latest',
|
|
22
|
+
'@zhin.js/tool': 'latest',
|
|
15
23
|
'@zhin.js/host-router': 'latest',
|
|
16
24
|
'@zhin.js/host-api': 'latest',
|
|
17
25
|
'@zhin.js/client': 'latest',
|
|
@@ -81,10 +89,17 @@ function resolveStackVersion(packageName: string): string {
|
|
|
81
89
|
}
|
|
82
90
|
|
|
83
91
|
function collectZhinPluginsFromConfig(config: Record<string, unknown>): string[] {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
:
|
|
87
|
-
|
|
92
|
+
// legacy 数组形式:条目即包名
|
|
93
|
+
if (Array.isArray(config.plugins)) {
|
|
94
|
+
const plugins = config.plugins.filter((p): p is string => typeof p === 'string');
|
|
95
|
+
return [...new Set(plugins.filter((p) => p.startsWith('@zhin.js/')))];
|
|
96
|
+
}
|
|
97
|
+
// 新 runtime:plugins 为 instanceKey 映射,包名在 package.json zhin.plugins 清单中,
|
|
98
|
+
// 无法从配置推导;仅收集直接以包名出现的键(防御性)
|
|
99
|
+
if (config.plugins && typeof config.plugins === 'object') {
|
|
100
|
+
return Object.keys(config.plugins as Record<string, unknown>).filter((key) => key.startsWith('@zhin.js/'));
|
|
101
|
+
}
|
|
102
|
+
return [];
|
|
88
103
|
}
|
|
89
104
|
|
|
90
105
|
/** create-zhin / minimal-bot 默认 Host 端口(避免与常见 8086 占用冲突) */
|
|
@@ -100,15 +115,16 @@ export function getCreateBotPnpmConfig(_aiEnabled?: boolean): Record<string, unk
|
|
|
100
115
|
};
|
|
101
116
|
}
|
|
102
117
|
|
|
103
|
-
/** create-zhin-app
|
|
118
|
+
/** create-zhin-app Plugin Runtime 骨架 production 依赖(不含适配器 / AI / 数据库驱动) */
|
|
104
119
|
export function getCreateBotBaseDependencies(): Record<string, string> {
|
|
105
120
|
return {
|
|
106
121
|
'zhin.js': ZHIN_STACK_VERSIONS['zhin.js'],
|
|
107
|
-
'@zhin.js/
|
|
108
|
-
'@zhin.js/
|
|
109
|
-
'@zhin.js/
|
|
110
|
-
'@zhin.js/
|
|
111
|
-
'@zhin.js/
|
|
122
|
+
'@zhin.js/plugin-runtime': ZHIN_STACK_VERSIONS['@zhin.js/plugin-runtime'],
|
|
123
|
+
'@zhin.js/runtime': ZHIN_STACK_VERSIONS['@zhin.js/runtime'],
|
|
124
|
+
'@zhin.js/adapter': ZHIN_STACK_VERSIONS['@zhin.js/adapter'],
|
|
125
|
+
'@zhin.js/command': ZHIN_STACK_VERSIONS['@zhin.js/command'],
|
|
126
|
+
'@zhin.js/component': ZHIN_STACK_VERSIONS['@zhin.js/component'],
|
|
127
|
+
'@zhin.js/core': ZHIN_STACK_VERSIONS['@zhin.js/core'],
|
|
112
128
|
'@zhin.js/satori': ZHIN_STACK_VERSIONS['@zhin.js/satori'],
|
|
113
129
|
};
|
|
114
130
|
}
|