@zhin.js/scaffold-wizard 1.1.0 → 1.1.2
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 +5 -0
- package/lib/adapter.js +1 -1
- package/lib/adapter.js.map +1 -1
- package/lib/ai.d.ts +1 -7
- package/lib/ai.d.ts.map +1 -1
- package/lib/ai.js +0 -63
- package/lib/ai.js.map +1 -1
- package/lib/apply.d.ts +5 -5
- package/lib/apply.d.ts.map +1 -1
- package/lib/apply.js +13 -23
- package/lib/apply.js.map +1 -1
- package/lib/database-definitions.d.ts +28 -0
- package/lib/database-definitions.d.ts.map +1 -0
- package/lib/database-definitions.js +290 -0
- package/lib/database-definitions.js.map +1 -0
- package/lib/database.d.ts.map +1 -1
- package/lib/database.js +69 -51
- package/lib/database.js.map +1 -1
- package/lib/env.d.ts +6 -0
- package/lib/env.d.ts.map +1 -1
- package/lib/env.js +51 -0
- package/lib/env.js.map +1 -1
- package/lib/index.d.ts +8 -6
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +7 -6
- package/lib/index.js.map +1 -1
- package/lib/optional-peers.d.ts.map +1 -1
- package/lib/optional-peers.js +5 -16
- package/lib/optional-peers.js.map +1 -1
- package/lib/project-config-plan.d.ts +2 -1
- package/lib/project-config-plan.d.ts.map +1 -1
- package/lib/project-config-plan.js +29 -83
- package/lib/project-config-plan.js.map +1 -1
- package/lib/project-deps.d.ts +1 -1
- package/lib/project-deps.d.ts.map +1 -1
- package/lib/project-deps.js +5 -7
- package/lib/project-deps.js.map +1 -1
- package/lib/types.d.ts +4 -3
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +6 -8
- package/lib/types.js.map +1 -1
- package/lib/zhin-stack-deps.d.ts +8 -6
- package/lib/zhin-stack-deps.d.ts.map +1 -1
- package/lib/zhin-stack-deps.js +16 -25
- package/lib/zhin-stack-deps.js.map +1 -1
- package/package.json +3 -3
- package/src/adapter.ts +1 -1
- package/src/ai.ts +1 -70
- package/src/apply.ts +17 -23
- package/src/database-definitions.ts +336 -0
- package/src/database.ts +77 -52
- package/src/env.ts +52 -0
- package/src/index.ts +18 -6
- package/src/optional-peers.ts +4 -14
- package/src/project-config-plan.ts +35 -79
- package/src/project-deps.ts +5 -6
- package/src/types.ts +13 -10
- package/src/zhin-stack-deps.ts +16 -27
package/src/index.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
export type { InitOptions, DatabaseConfig } from './types.js';
|
|
2
|
-
export { DATABASE_PACKAGES } from './types.js';
|
|
2
|
+
export { DATABASE_DRIVER_VERSIONS, DATABASE_PACKAGES } from './types.js';
|
|
3
|
+
export {
|
|
4
|
+
DATABASE_DIALECT_DEFINITIONS,
|
|
5
|
+
databaseChoiceLabel,
|
|
6
|
+
getDatabaseDialectDefinition,
|
|
7
|
+
validateDatabaseConfig,
|
|
8
|
+
} from './database-definitions.js';
|
|
9
|
+
export type {
|
|
10
|
+
DatabaseDialect,
|
|
11
|
+
DatabaseDialectDefinition,
|
|
12
|
+
DatabaseDriverDefinition,
|
|
13
|
+
DatabaseSchemaIssue,
|
|
14
|
+
} from './database-definitions.js';
|
|
3
15
|
|
|
4
16
|
export type { AdapterSetupResult, AdapterPluginInstance, AdapterDefinition } from './adapter.js';
|
|
5
17
|
export {
|
|
@@ -27,7 +39,6 @@ export {
|
|
|
27
39
|
generateAIEnvVars,
|
|
28
40
|
generateAIConfigYaml,
|
|
29
41
|
generateAIConfigJSON,
|
|
30
|
-
generateAIConfigToml,
|
|
31
42
|
RECOMMENDED_AI_DEFAULTS,
|
|
32
43
|
} from './ai.js';
|
|
33
44
|
|
|
@@ -36,6 +47,7 @@ export { configureDatabaseOptions } from './database.js';
|
|
|
36
47
|
export {
|
|
37
48
|
formatEnvValue,
|
|
38
49
|
mergeEnvText,
|
|
50
|
+
generateDatabaseEnvExample,
|
|
39
51
|
generateDatabaseEnvVars,
|
|
40
52
|
} from './env.js';
|
|
41
53
|
|
|
@@ -46,7 +58,7 @@ export {
|
|
|
46
58
|
listAIDependencyNames,
|
|
47
59
|
formatAIDependencyHint,
|
|
48
60
|
isAiEnabledInConfig,
|
|
49
|
-
|
|
61
|
+
resolveAgentProviderFromConfig,
|
|
50
62
|
getRequiredAIDependenciesForConfig,
|
|
51
63
|
diagnoseAIDependencies,
|
|
52
64
|
formatAIDependencyFixCommand,
|
|
@@ -61,9 +73,9 @@ export type { AiStackIncompatibility } from './project-deps.js';
|
|
|
61
73
|
export {
|
|
62
74
|
ZHIN_STACK_VERSIONS,
|
|
63
75
|
DEFAULT_CREATE_BOT_HTTP_PORT,
|
|
64
|
-
|
|
76
|
+
CREATE_BOT_PACKAGE_MANAGER,
|
|
65
77
|
getCreateBotBaseDependencies,
|
|
66
|
-
|
|
78
|
+
getCreateBotPnpmWorkspaceConfig,
|
|
67
79
|
getRequiredZhinDependenciesForConfig,
|
|
68
80
|
diagnoseZhinStackDependencies,
|
|
69
81
|
formatZhinStackFixCommand,
|
|
@@ -119,7 +131,7 @@ export {
|
|
|
119
131
|
mergePluginManifestIntoPackageJson,
|
|
120
132
|
finalizeWizardOptions,
|
|
121
133
|
applyWizardOptionsToConfig,
|
|
122
|
-
|
|
134
|
+
clonePluginConfigurationMap,
|
|
123
135
|
materializeDatabaseConfig,
|
|
124
136
|
buildRuntimeConfigDocument,
|
|
125
137
|
serializeRuntimeConfig,
|
package/src/optional-peers.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { readPluginConfigurationMap } from '@zhin.js/plugin-runtime';
|
|
3
4
|
import { findMissingPackageDependencies, findUnresolvedPackageInstalls, type PackageJsonLike } from './project-deps.js';
|
|
4
5
|
|
|
5
6
|
export const SPEECH_PACKAGE = '@zhin.js/speech';
|
|
@@ -38,21 +39,10 @@ function readSpeechStrategy(config: Record<string, unknown>): string | undefined
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
function configUsesHtmlImageAdapter(config: Record<string, unknown>): boolean {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
: [];
|
|
44
|
-
for (const plugin of plugins) {
|
|
42
|
+
for (const instanceKey of Object.keys(readPluginConfigurationMap(config))) {
|
|
43
|
+
if (ADAPTERS_PREFER_HTML_IMAGE.has(instanceKey)) return true;
|
|
45
44
|
for (const ctx of ADAPTERS_PREFER_HTML_IMAGE) {
|
|
46
|
-
if (
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
// 新 runtime 配置形态:plugins 为 instanceKey → 配置 的映射,instanceKey 即适配器 context
|
|
50
|
-
if (config.plugins && typeof config.plugins === 'object' && !Array.isArray(config.plugins)) {
|
|
51
|
-
for (const instanceKey of Object.keys(config.plugins as Record<string, unknown>)) {
|
|
52
|
-
if (ADAPTERS_PREFER_HTML_IMAGE.has(instanceKey)) return true;
|
|
53
|
-
for (const ctx of ADAPTERS_PREFER_HTML_IMAGE) {
|
|
54
|
-
if (instanceKey.includes(`adapter-${ctx}`)) return true;
|
|
55
|
-
}
|
|
45
|
+
if (instanceKey.includes(`adapter-${ctx}`)) return true;
|
|
56
46
|
}
|
|
57
47
|
}
|
|
58
48
|
const endpoints = Array.isArray(config.endpoints) ? config.endpoints : [];
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import yaml from 'yaml';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
readPluginConfigurationMap,
|
|
6
|
+
ROOT_CONFIG_FILE_NAMES,
|
|
7
|
+
rootConfigFormat,
|
|
8
|
+
selectRootConfigFile,
|
|
9
|
+
type RootConfigFormat,
|
|
10
|
+
} from '@zhin.js/plugin-runtime';
|
|
5
11
|
import { providerSdkFor } from './ai.js';
|
|
6
12
|
|
|
7
13
|
const CONSOLE_URL = 'https://console.zhin.dev';
|
|
8
|
-
const CONFIG_CANDIDATES = [
|
|
9
|
-
'zhin.config.yml',
|
|
10
|
-
'zhin.config.yaml',
|
|
11
|
-
'zhin.config.json',
|
|
12
|
-
'zhin.config.toml',
|
|
13
|
-
'zhin.config.ts',
|
|
14
|
-
] as const;
|
|
15
14
|
const SANDBOX_PLUGIN = '@zhin.js/adapter-sandbox';
|
|
16
15
|
const LEGACY_AI_PROVIDER_FIELDS = ['driver', 'api', 'preset', 'spec'] as const;
|
|
17
16
|
|
|
@@ -23,7 +22,7 @@ export function packageToInstanceKey(packageName: string): string {
|
|
|
23
22
|
return name.replace(/^(adapter|plugin|service)-/, '');
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
export type ProjectConfigFormat =
|
|
25
|
+
export type ProjectConfigFormat = RootConfigFormat;
|
|
27
26
|
|
|
28
27
|
export interface LoadedProjectConfig {
|
|
29
28
|
status: 'loaded' | 'missing' | 'unsupported';
|
|
@@ -70,12 +69,7 @@ export interface ConsoleConfigDiagnosis {
|
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
function configFormatFromPath(filePath: string): ProjectConfigFormat | null {
|
|
73
|
-
|
|
74
|
-
if (ext === '.yml' || ext === '.yaml') return 'yaml';
|
|
75
|
-
if (ext === '.json') return 'json';
|
|
76
|
-
if (ext === '.toml') return 'toml';
|
|
77
|
-
if (ext === '.ts') return 'ts';
|
|
78
|
-
return null;
|
|
72
|
+
return rootConfigFormat(filePath) ?? null;
|
|
79
73
|
}
|
|
80
74
|
|
|
81
75
|
function cloneConfig(config: Record<string, unknown>): Record<string, unknown> {
|
|
@@ -83,39 +77,28 @@ function cloneConfig(config: Record<string, unknown>): Record<string, unknown> {
|
|
|
83
77
|
}
|
|
84
78
|
|
|
85
79
|
function parseConfig(content: string, format: ProjectConfigFormat): Record<string, unknown> {
|
|
86
|
-
if (format === 'yaml') {
|
|
87
|
-
const parsed = yaml.parse(content) as unknown;
|
|
88
|
-
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
89
|
-
? parsed as Record<string, unknown>
|
|
90
|
-
: {};
|
|
91
|
-
}
|
|
92
80
|
if (format === 'json') {
|
|
93
81
|
const parsed = JSON.parse(content) as unknown;
|
|
94
82
|
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
95
83
|
? parsed as Record<string, unknown>
|
|
96
84
|
: {};
|
|
97
85
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
: {};
|
|
103
|
-
}
|
|
104
|
-
return {};
|
|
86
|
+
const parsed = yaml.parse(content) as unknown;
|
|
87
|
+
return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
|
|
88
|
+
? parsed as Record<string, unknown>
|
|
89
|
+
: {};
|
|
105
90
|
}
|
|
106
91
|
|
|
107
92
|
function serializeConfig(config: Record<string, unknown>, format: ProjectConfigFormat): string {
|
|
108
93
|
if (format === 'json') return `${JSON.stringify(config, null, 2)}\n`;
|
|
109
|
-
if (format === 'toml') return stringifyToml(config as Record<string, unknown>);
|
|
110
94
|
return yaml.stringify(config);
|
|
111
95
|
}
|
|
112
96
|
|
|
113
97
|
function findProjectConfigPath(cwd: string): string | null {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return null;
|
|
98
|
+
const existing = ROOT_CONFIG_FILE_NAMES
|
|
99
|
+
.map((candidate) => path.join(cwd, candidate))
|
|
100
|
+
.filter((configPath) => fs.existsSync(configPath));
|
|
101
|
+
return selectRootConfigFile(existing) ?? null;
|
|
119
102
|
}
|
|
120
103
|
|
|
121
104
|
export function loadProjectConfig(cwd = process.cwd(), configPath?: string): LoadedProjectConfig {
|
|
@@ -126,7 +109,7 @@ export function loadProjectConfig(cwd = process.cwd(), configPath?: string): Loa
|
|
|
126
109
|
cwd,
|
|
127
110
|
config: {},
|
|
128
111
|
writable: false,
|
|
129
|
-
message: '未找到
|
|
112
|
+
message: '未找到 Root YAML/JSON 配置文件',
|
|
130
113
|
};
|
|
131
114
|
}
|
|
132
115
|
|
|
@@ -144,51 +127,35 @@ export function loadProjectConfig(cwd = process.cwd(), configPath?: string): Loa
|
|
|
144
127
|
};
|
|
145
128
|
}
|
|
146
129
|
|
|
147
|
-
|
|
130
|
+
const content = fs.readFileSync(resolvedPath, 'utf8');
|
|
131
|
+
const config = parseConfig(content, format);
|
|
132
|
+
try {
|
|
133
|
+
readPluginConfigurationMap(config, relativePath);
|
|
134
|
+
} catch (error) {
|
|
148
135
|
return {
|
|
149
136
|
status: 'unsupported',
|
|
150
137
|
cwd,
|
|
151
138
|
configPath: resolvedPath,
|
|
152
139
|
relativePath,
|
|
153
140
|
format,
|
|
154
|
-
config
|
|
141
|
+
config,
|
|
155
142
|
writable: false,
|
|
156
|
-
message:
|
|
143
|
+
message: `${error instanceof Error ? error.message : String(error)};请先运行 zhin migrate`,
|
|
157
144
|
};
|
|
158
145
|
}
|
|
159
|
-
|
|
160
|
-
const content = fs.readFileSync(resolvedPath, 'utf8');
|
|
161
146
|
return {
|
|
162
147
|
status: 'loaded',
|
|
163
148
|
cwd,
|
|
164
149
|
configPath: resolvedPath,
|
|
165
150
|
relativePath,
|
|
166
151
|
format,
|
|
167
|
-
config
|
|
152
|
+
config,
|
|
168
153
|
writable: true,
|
|
169
154
|
};
|
|
170
155
|
}
|
|
171
156
|
|
|
172
157
|
function ensurePlugins(config: Record<string, unknown>, pluginsToAdd: readonly string[], mutations: string[]): void {
|
|
173
|
-
|
|
174
|
-
// legacy 数组形式:保持原形态追加,避免改写旧项目结构
|
|
175
|
-
const plugins = config.plugins.filter((p): p is string => typeof p === 'string');
|
|
176
|
-
let changed = false;
|
|
177
|
-
for (const plugin of pluginsToAdd) {
|
|
178
|
-
if (plugins.includes(plugin)) continue;
|
|
179
|
-
plugins.push(plugin);
|
|
180
|
-
mutations.push(`added ${plugin} to plugins`);
|
|
181
|
-
changed = true;
|
|
182
|
-
}
|
|
183
|
-
if (changed) {
|
|
184
|
-
config.plugins = plugins;
|
|
185
|
-
}
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
// 新 Plugin Runtime:plugins 为 <instanceKey>: <配置> 映射
|
|
189
|
-
const plugins = config.plugins && typeof config.plugins === 'object'
|
|
190
|
-
? { ...(config.plugins as Record<string, unknown>) }
|
|
191
|
-
: {};
|
|
158
|
+
const plugins = { ...readPluginConfigurationMap(config) };
|
|
192
159
|
let changed = false;
|
|
193
160
|
for (const pkg of pluginsToAdd) {
|
|
194
161
|
const instanceKey = packageToInstanceKey(pkg);
|
|
@@ -197,7 +164,7 @@ function ensurePlugins(config: Record<string, unknown>, pluginsToAdd: readonly s
|
|
|
197
164
|
mutations.push(`added ${instanceKey} (${pkg}) to plugins`);
|
|
198
165
|
changed = true;
|
|
199
166
|
}
|
|
200
|
-
if (changed ||
|
|
167
|
+
if (changed || config.plugins === undefined) {
|
|
201
168
|
config.plugins = plugins;
|
|
202
169
|
}
|
|
203
170
|
}
|
|
@@ -321,6 +288,8 @@ function applyAiLegacyMigration(config: Record<string, unknown>, mutations: stri
|
|
|
321
288
|
|
|
322
289
|
export function createProjectConfigPlan(options: ProjectConfigPlanOptions): ProjectConfigPlan {
|
|
323
290
|
const cwd = options.cwd ?? options.loaded?.cwd ?? process.cwd();
|
|
291
|
+
const configuredFormat = options.format
|
|
292
|
+
?? (options.configPath ? configFormatFromPath(options.configPath) ?? undefined : undefined);
|
|
324
293
|
const loaded = options.loaded ?? (
|
|
325
294
|
options.config
|
|
326
295
|
? {
|
|
@@ -328,9 +297,9 @@ export function createProjectConfigPlan(options: ProjectConfigPlanOptions): Proj
|
|
|
328
297
|
cwd,
|
|
329
298
|
configPath: options.configPath,
|
|
330
299
|
relativePath: options.configPath ? path.relative(cwd, options.configPath) : undefined,
|
|
331
|
-
format:
|
|
300
|
+
format: configuredFormat,
|
|
332
301
|
config: options.config,
|
|
333
|
-
writable: Boolean(options.configPath &&
|
|
302
|
+
writable: Boolean(options.configPath && configuredFormat),
|
|
334
303
|
}
|
|
335
304
|
: loadProjectConfig(cwd, options.configPath)
|
|
336
305
|
);
|
|
@@ -373,7 +342,7 @@ export function createProjectConfigPlan(options: ProjectConfigPlanOptions): Proj
|
|
|
373
342
|
|
|
374
343
|
export function renderProjectConfigPatch(plan: ProjectConfigPlan): string {
|
|
375
344
|
if (!plan.changed) return '配置无需改动。';
|
|
376
|
-
const format = plan.format
|
|
345
|
+
const format = plan.format ?? 'yaml';
|
|
377
346
|
const name = plan.relativePath ?? 'zhin.config.yml';
|
|
378
347
|
return [
|
|
379
348
|
`# ${name}`,
|
|
@@ -384,7 +353,7 @@ export function renderProjectConfigPatch(plan: ProjectConfigPlan): string {
|
|
|
384
353
|
|
|
385
354
|
export async function applyProjectConfigPlan(plan: ProjectConfigPlan): Promise<boolean> {
|
|
386
355
|
if (!plan.changed) return false;
|
|
387
|
-
if (!plan.writable || !plan.configPath || !plan.format
|
|
356
|
+
if (!plan.writable || !plan.configPath || !plan.format) return false;
|
|
388
357
|
await fs.writeFile(plan.configPath, serializeConfig(plan.after, plan.format));
|
|
389
358
|
return true;
|
|
390
359
|
}
|
|
@@ -395,20 +364,7 @@ export function diagnoseConsoleConfig(config: Record<string, unknown>): ConsoleC
|
|
|
395
364
|
: {};
|
|
396
365
|
const corsOrigins = Array.isArray(http.corsOrigins) ? http.corsOrigins : [];
|
|
397
366
|
|
|
398
|
-
|
|
399
|
-
// legacy 数组形式配置
|
|
400
|
-
const plugins = config.plugins.filter((p): p is string => typeof p === 'string');
|
|
401
|
-
return {
|
|
402
|
-
missingSandboxPlugin: !plugins.includes(SANDBOX_PLUGIN),
|
|
403
|
-
missingConsoleOrigin: !hasConsoleOrigin(corsOrigins.filter((origin): origin is string => typeof origin === 'string')),
|
|
404
|
-
missingHttpToken: typeof http.token !== 'string' || http.token.trim().length === 0,
|
|
405
|
-
};
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// 新 Plugin Runtime:Console Host 由 CLI 装配,无需 host 插件;Sandbox 为 plugins.sandbox 实例
|
|
409
|
-
const plugins = config.plugins && typeof config.plugins === 'object'
|
|
410
|
-
? config.plugins as Record<string, unknown>
|
|
411
|
-
: {};
|
|
367
|
+
const plugins = readPluginConfigurationMap(config);
|
|
412
368
|
return {
|
|
413
369
|
missingSandboxPlugin: !('sandbox' in plugins),
|
|
414
370
|
missingConsoleOrigin: !hasConsoleOrigin(corsOrigins.filter((origin): origin is string => typeof origin === 'string')),
|
package/src/project-deps.ts
CHANGED
|
@@ -88,7 +88,7 @@ function packagesForSdkIds(sdkIds: Iterable<string>): Record<string, string> {
|
|
|
88
88
|
|
|
89
89
|
function collectSdkPackagesFromSetup(ai: AISetupConfig): Record<string, string> {
|
|
90
90
|
const sdkIds = new Set<string>();
|
|
91
|
-
const agentProvider = ai.agentProvider
|
|
91
|
+
const agentProvider = ai.agentProvider;
|
|
92
92
|
if (agentProvider) {
|
|
93
93
|
const id = inferSdkId(agentProvider, ai.providers?.[agentProvider] as { sdk?: string });
|
|
94
94
|
if (id) sdkIds.add(id);
|
|
@@ -124,7 +124,7 @@ function collectSdkPackagesFromConfig(config: { ai?: unknown }): Record<string,
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
if (sdkIds.size === 0) {
|
|
127
|
-
const alias =
|
|
127
|
+
const alias = resolveAgentProviderFromConfig(config);
|
|
128
128
|
if (alias) {
|
|
129
129
|
const id = inferSdkId(alias, providers?.[alias]);
|
|
130
130
|
if (id) sdkIds.add(id);
|
|
@@ -249,7 +249,7 @@ export function isAiEnabledInConfig(config: { ai?: unknown }): boolean {
|
|
|
249
249
|
return false;
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
export function
|
|
252
|
+
export function resolveAgentProviderFromConfig(config: { ai?: unknown }): string | undefined {
|
|
253
253
|
const ai = config.ai;
|
|
254
254
|
if (!ai || typeof ai !== 'object' || Array.isArray(ai)) return undefined;
|
|
255
255
|
const rec = ai as Record<string, unknown>;
|
|
@@ -265,7 +265,6 @@ export function resolveDefaultProviderFromConfig(config: { ai?: unknown }): stri
|
|
|
265
265
|
const first = Object.keys(providers as Record<string, unknown>)[0];
|
|
266
266
|
if (first) return first;
|
|
267
267
|
}
|
|
268
|
-
if (rec.defaultProvider != null) return String(rec.defaultProvider);
|
|
269
268
|
return undefined;
|
|
270
269
|
}
|
|
271
270
|
|
|
@@ -281,7 +280,7 @@ export function getRequiredAIDependenciesForConfig(config: { ai?: unknown }): Re
|
|
|
281
280
|
const ai = config.ai as Record<string, unknown>;
|
|
282
281
|
const setup: AISetupConfig = {
|
|
283
282
|
enabled: true,
|
|
284
|
-
agentProvider:
|
|
283
|
+
agentProvider: resolveAgentProviderFromConfig(config),
|
|
285
284
|
providers: ai.providers as AISetupConfig['providers'],
|
|
286
285
|
memoryMcp: aiConfigNeedsMcp(ai),
|
|
287
286
|
};
|
|
@@ -365,7 +364,7 @@ export function diagnoseAIDependencies(
|
|
|
365
364
|
const notInstalled = findUnresolvedPackageInstalls(cwd, declared);
|
|
366
365
|
return {
|
|
367
366
|
enabled: true,
|
|
368
|
-
provider:
|
|
367
|
+
provider: resolveAgentProviderFromConfig(config),
|
|
369
368
|
required,
|
|
370
369
|
missingFromPackageJson,
|
|
371
370
|
outdatedInPackageJson,
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AISetupConfig } from './ai.js';
|
|
2
2
|
import type { AdapterSetupResult } from './adapter.js';
|
|
3
|
+
import { DATABASE_DIALECT_DEFINITIONS } from './database-definitions.js';
|
|
3
4
|
|
|
4
5
|
export type { AISetupConfig } from './ai.js';
|
|
5
6
|
export type { AdapterSetupResult } from './adapter.js';
|
|
@@ -7,7 +8,7 @@ export type { AdapterSetupResult } from './adapter.js';
|
|
|
7
8
|
export interface InitOptions {
|
|
8
9
|
name?: string;
|
|
9
10
|
template?: 'default' | 'life-assistant';
|
|
10
|
-
config?: 'json' | 'yaml'
|
|
11
|
+
config?: 'json' | 'yaml';
|
|
11
12
|
runtime?: 'node' | 'bun';
|
|
12
13
|
yes?: boolean;
|
|
13
14
|
httpToken?: string;
|
|
@@ -19,15 +20,17 @@ export interface InitOptions {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export interface DatabaseConfig {
|
|
22
|
-
dialect: 'sqlite' | 'mysql' | 'pg' | 'mongodb' | 'redis';
|
|
23
|
+
dialect: 'sqlite' | 'mysql' | 'pg' | 'mongodb' | 'redis' | 'memory';
|
|
23
24
|
[key: string]: any;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
//
|
|
27
|
-
export const DATABASE_PACKAGES
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
// 数据库驱动映射(SQLite / Memory 使用内置实现,无需额外安装)
|
|
28
|
+
export const DATABASE_PACKAGES = Object.freeze(Object.fromEntries(
|
|
29
|
+
DATABASE_DIALECT_DEFINITIONS.map((definition) => [definition.dialect, definition.driver?.package]),
|
|
30
|
+
)) as Readonly<Record<DatabaseConfig['dialect'], string | undefined>>;
|
|
31
|
+
|
|
32
|
+
export const DATABASE_DRIVER_VERSIONS = Object.freeze(Object.fromEntries(
|
|
33
|
+
DATABASE_DIALECT_DEFINITIONS.flatMap((definition) => definition.driver
|
|
34
|
+
? [[definition.driver.package, definition.driver.version] as const]
|
|
35
|
+
: []),
|
|
36
|
+
)) as Readonly<Record<string, string>>;
|
package/src/zhin-stack-deps.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import { DATABASE_PACKAGES } from './types.js';
|
|
4
|
+
import { DATABASE_DRIVER_VERSIONS, DATABASE_PACKAGES } from './types.js';
|
|
5
5
|
import { findMissingPackageDependencies, findUnresolvedPackageInstalls, isAiEnabledInConfig, type PackageJsonLike } from './project-deps.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* User project dependency policy: scaffolded
|
|
9
|
-
*
|
|
8
|
+
* User project dependency policy: scaffolded Zhin packages intentionally float to latest.
|
|
9
|
+
* Database drivers use the live-tested ranges declared by the database definitions.
|
|
10
|
+
* WARNING: `latest` is not reproducible; pin Zhin package versions for production.
|
|
10
11
|
*/
|
|
11
12
|
export const ZHIN_STACK_VERSIONS = {
|
|
12
13
|
'zhin.js': 'latest',
|
|
@@ -23,6 +24,7 @@ export const ZHIN_STACK_VERSIONS = {
|
|
|
23
24
|
'@zhin.js/layout': 'latest',
|
|
24
25
|
'@zhin.js/page': 'latest',
|
|
25
26
|
'@zhin.js/prompt-section': 'latest',
|
|
27
|
+
'@zhin.js/skill': 'latest',
|
|
26
28
|
'@zhin.js/tool': 'latest',
|
|
27
29
|
'@zhin.js/client': 'latest',
|
|
28
30
|
'@zhin.js/contract': 'latest',
|
|
@@ -110,30 +112,20 @@ function resolveStackVersion(packageName: string): string {
|
|
|
110
112
|
return ZHIN_STACK_VERSIONS[packageName as ZhinStackPackage] ?? 'latest';
|
|
111
113
|
}
|
|
112
114
|
|
|
113
|
-
function collectZhinPluginsFromConfig(config: Record<string, unknown>): string[] {
|
|
114
|
-
// legacy 数组形式:条目即包名
|
|
115
|
-
if (Array.isArray(config.plugins)) {
|
|
116
|
-
const plugins = config.plugins.filter((p): p is string => typeof p === 'string');
|
|
117
|
-
return [...new Set(plugins.filter((p) => p.startsWith('@zhin.js/')))];
|
|
118
|
-
}
|
|
119
|
-
// 新 runtime:plugins 为 instanceKey 映射,包名在 package.json zhin.plugins 清单中,
|
|
120
|
-
// 无法从配置推导;仅收集直接以包名出现的键(防御性)
|
|
121
|
-
if (config.plugins && typeof config.plugins === 'object') {
|
|
122
|
-
return Object.keys(config.plugins as Record<string, unknown>).filter((key) => key.startsWith('@zhin.js/'));
|
|
123
|
-
}
|
|
124
|
-
return [];
|
|
125
|
-
}
|
|
126
|
-
|
|
127
115
|
/** create-zhin / minimal-bot 默认 Host 端口(避免与常见 8086 占用冲突) */
|
|
128
116
|
export const DEFAULT_CREATE_BOT_HTTP_PORT = 8068;
|
|
129
117
|
|
|
130
|
-
/** create-zhin
|
|
131
|
-
export const
|
|
118
|
+
/** create-zhin 生成项目固定使用的 pnpm 版本。 */
|
|
119
|
+
export const CREATE_BOT_PACKAGE_MANAGER = 'pnpm@11.27.1';
|
|
132
120
|
|
|
133
|
-
/** create-zhin 生成项目的 pnpm
|
|
134
|
-
export function
|
|
121
|
+
/** create-zhin 生成项目的 pnpm-workspace.yaml 配置。 */
|
|
122
|
+
export function getCreateBotPnpmWorkspaceConfig(): Record<string, unknown> {
|
|
135
123
|
return {
|
|
136
|
-
|
|
124
|
+
packages: ['.', 'plugins/*', 'packages/*'],
|
|
125
|
+
strictPeerDependencies: false,
|
|
126
|
+
allowBuilds: {
|
|
127
|
+
esbuild: true,
|
|
128
|
+
},
|
|
137
129
|
};
|
|
138
130
|
}
|
|
139
131
|
|
|
@@ -144,6 +136,7 @@ export function getCreateBotPnpmConfig(_aiEnabled?: boolean): Record<string, unk
|
|
|
144
136
|
export function getCreateBotBaseDependencies(): Record<string, string> {
|
|
145
137
|
return {
|
|
146
138
|
'zhin.js': ZHIN_STACK_VERSIONS['zhin.js'],
|
|
139
|
+
'@zhin.js/skill': ZHIN_STACK_VERSIONS['@zhin.js/skill'],
|
|
147
140
|
};
|
|
148
141
|
}
|
|
149
142
|
|
|
@@ -153,17 +146,13 @@ export function getRequiredZhinDependenciesForConfig(config: Record<string, unkn
|
|
|
153
146
|
'zhin.js': ZHIN_STACK_VERSIONS['zhin.js'],
|
|
154
147
|
};
|
|
155
148
|
|
|
156
|
-
for (const plugin of collectZhinPluginsFromConfig(config)) {
|
|
157
|
-
deps[plugin] = resolveStackVersion(plugin);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
149
|
const database = config.database;
|
|
161
150
|
if (database && typeof database === 'object' && !Array.isArray(database)) {
|
|
162
151
|
deps['@zhin.js/database'] = ZHIN_STACK_VERSIONS['@zhin.js/database'];
|
|
163
152
|
const dialect = String((database as Record<string, unknown>).dialect ?? '');
|
|
164
153
|
const driver = DATABASE_PACKAGES[dialect as keyof typeof DATABASE_PACKAGES];
|
|
165
154
|
if (driver) {
|
|
166
|
-
deps[driver] =
|
|
155
|
+
deps[driver] = DATABASE_DRIVER_VERSIONS[driver];
|
|
167
156
|
}
|
|
168
157
|
}
|
|
169
158
|
|