@zhin.js/scaffold-wizard 1.1.0 → 1.1.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/src/ai.ts CHANGED
@@ -5,8 +5,6 @@ import { formatEnvValue } from './env.js';
5
5
  export interface AISetupConfig {
6
6
  enabled: boolean;
7
7
  agentProvider?: string;
8
- /** @deprecated Use agentProvider. Kept for one compatibility cycle. */
9
- defaultProvider?: string;
10
8
  providers?: Record<string, {
11
9
  sdk?: string;
12
10
  apiKey?: string;
@@ -134,9 +132,8 @@ function defaultModelForProvider(driver: string): string {
134
132
  return entry?.defaultModel ?? '';
135
133
  }
136
134
 
137
- export function resolveAISetupAgentProvider(config: Pick<AISetupConfig, 'agentProvider' | 'defaultProvider' | 'providers'>): string {
135
+ export function resolveAISetupAgentProvider(config: Pick<AISetupConfig, 'agentProvider' | 'providers'>): string {
138
136
  return config.agentProvider
139
- ?? config.defaultProvider
140
137
  ?? Object.keys(config.providers ?? {})[0]
141
138
  ?? 'openai';
142
139
  }
@@ -529,72 +526,6 @@ export function generateAIConfigYaml(config: AISetupConfig): string {
529
526
  return lines.join('\n');
530
527
  }
531
528
 
532
- /**
533
- * 生成 TOML 格式的 AI 配置段
534
- */
535
- export function generateAIConfigToml(config: AISetupConfig): string {
536
- if (!config.enabled) return '';
537
-
538
- const lines: string[] = [
539
- '',
540
- '[ai]',
541
- `memoryMcp = ${config.memoryMcp ?? false}`,
542
- ];
543
-
544
- if (config.providers) {
545
- for (const [name, providerConfig] of Object.entries(config.providers)) {
546
- lines.push('', `[ai.providers.${name}]`);
547
- lines.push(`sdk = "${providerConfig.sdk ?? providerSdkFor(name)}"`);
548
- if (providerConfig.apiKey) lines.push(`apiKey = "${providerConfig.apiKey}"`);
549
- if (providerConfig.host) lines.push(`host = "${providerConfig.host}"`);
550
- if (providerConfig.models?.length) {
551
- lines.push(`models = ${JSON.stringify(providerConfig.models)}`);
552
- }
553
- if (providerConfig.baseUrl) lines.push(`baseUrl = "${providerConfig.baseUrl}"`);
554
- }
555
- }
556
-
557
- const providerAlias = resolveAISetupAgentProvider(config);
558
- lines.push('', '[ai.agents.zhin]');
559
- lines.push(`provider = "${providerAlias}"`);
560
- const zhinModel = resolveAISetupAgentModel(config, providerAlias);
561
- if (zhinModel) lines.push(`model = "${zhinModel}"`);
562
-
563
- if (config.trigger) {
564
- lines.push('', '[ai.trigger]');
565
- lines.push(`respondToAt = ${config.trigger.respondToAt}`);
566
- lines.push(`respondToPrivate = ${config.trigger.respondToPrivate}`);
567
- lines.push(`prefixes = ${JSON.stringify(config.trigger.prefixes)}`);
568
- lines.push(`ignorePrefixes = ${JSON.stringify(config.trigger.ignorePrefixes)}`);
569
- lines.push(`timeout = ${config.trigger.timeout}`);
570
- }
571
-
572
- if (config.sessions) {
573
- lines.push('', '[ai.sessions]');
574
- lines.push(`useDatabase = ${config.sessions.useDatabase}`);
575
- lines.push(`maxHistory = ${config.sessions.maxHistory}`);
576
- lines.push(`expireMs = ${config.sessions.expireMs}`);
577
- }
578
-
579
- if (config.context) {
580
- lines.push('', '[ai.context]');
581
- lines.push(`enabled = ${config.context.enabled}`);
582
- lines.push(`maxRecentMessages = ${config.context.maxRecentMessages}`);
583
- lines.push(`summaryThreshold = ${config.context.summaryThreshold}`);
584
- lines.push(`keepAfterSummary = ${config.context.keepAfterSummary}`);
585
- }
586
-
587
- if (config.agent) {
588
- lines.push('', '[ai.agent]');
589
- lines.push(`execSecurity = "${config.agent.execSecurity}"`);
590
- lines.push(`execPreset = "${config.agent.execPreset}"`);
591
- lines.push(`execAllowlist = ${JSON.stringify(config.agent.execAllowlist)}`);
592
- lines.push(`phaseTrace = ${config.agent.phaseTrace}`);
593
- }
594
-
595
- return lines.join('\n');
596
- }
597
-
598
529
  /**
599
530
  * 生成 JSON 格式的 AI 配置段
600
531
  */
package/src/apply.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import fs from 'fs-extra';
2
2
  import path from 'path';
3
3
  import yaml from 'yaml';
4
- import { stringify as stringifyToml } from 'smol-toml';
4
+ import { readPluginConfigurationMap } from '@zhin.js/plugin-runtime';
5
5
  import type { AdapterSetupResult, AISetupConfig, DatabaseConfig, InitOptions } from './types.js';
6
6
  import {
7
7
  collectAdapterPluginConfigs,
@@ -13,31 +13,21 @@ import { generateAIEnvVars, materializeAIConfig } from './ai.js';
13
13
  import { generateDatabaseEnvVars, mergeEnvText } from './env.js';
14
14
  import { ensureDatabaseForAdapters, ensureDatabaseForAI, getAIDependencies } from './project-deps.js';
15
15
  import { DEFAULT_CREATE_BOT_HTTP_PORT, ZHIN_STACK_VERSIONS } from './zhin-stack-deps.js';
16
- import { packageToInstanceKey } from './project-config-plan.js';
17
16
 
18
17
  export function applyDatabaseToConfig(config: Record<string, unknown>, database: DatabaseConfig): void {
19
18
  // 物化为可落盘对象:非 SQLite 连接参数引用 .env(${VAR}),明文密码不进配置文件
20
19
  config.database = materializeDatabaseConfig(database);
21
20
  }
22
21
 
23
- /** 将 legacy 数组形式 plugins 归一化为新 runtime 的 instanceKey 映射 */
24
- export function normalizePluginsMap(value: unknown): Record<string, unknown> {
25
- if (Array.isArray(value)) {
26
- const map: Record<string, unknown> = {};
27
- for (const entry of value) {
28
- if (typeof entry !== 'string') continue;
29
- map[packageToInstanceKey(entry)] ??= {};
30
- }
31
- return map;
32
- }
33
- if (value && typeof value === 'object') {
34
- return { ...(value as Record<string, unknown>) };
35
- }
36
- return {};
22
+ /** Returns a mutable copy of the canonical Plugin instance configuration map. */
23
+ export function clonePluginConfigurationMap(
24
+ config: Readonly<Record<string, unknown>>,
25
+ ): Record<string, unknown> {
26
+ return { ...readPluginConfigurationMap(config) };
37
27
  }
38
28
 
39
29
  export function applyAdaptersToConfig(config: Record<string, unknown>, result: AdapterSetupResult): void {
40
- const plugins = normalizePluginsMap(config.plugins);
30
+ const plugins = clonePluginConfigurationMap(config);
41
31
  for (const instance of result.instances) {
42
32
  plugins[instance.instanceKey] = mergeAdapterInstanceConfig(
43
33
  instance.instanceKey,
@@ -46,8 +36,6 @@ export function applyAdaptersToConfig(config: Record<string, unknown>, result: A
46
36
  );
47
37
  }
48
38
  config.plugins = plugins;
49
- // legacy endpoints 列表不被 runtime 配置 schema 接受(additionalProperties: false)
50
- delete config.endpoints;
51
39
  }
52
40
 
53
41
  function endpointId(endpoint: unknown): string | undefined {
@@ -327,12 +315,11 @@ export function buildRuntimeConfigDocument(options: InitOptions): Record<string,
327
315
  return doc;
328
316
  }
329
317
 
330
- /** 序列化配置文档为 zhin.config.yml / json / toml 文本 */
318
+ /** Serialize a Root Runtime YAML or JSON configuration document. */
331
319
  export function serializeRuntimeConfig(
332
320
  doc: Record<string, unknown>,
333
- format: 'yaml' | 'json' | 'toml',
321
+ format: 'yaml' | 'json',
334
322
  ): string {
335
323
  if (format === 'json') return `${JSON.stringify(doc, null, 2)}\n`;
336
- if (format === 'toml') return stringifyToml(doc);
337
324
  return yaml.stringify(doc);
338
325
  }
package/src/index.ts CHANGED
@@ -27,7 +27,6 @@ export {
27
27
  generateAIEnvVars,
28
28
  generateAIConfigYaml,
29
29
  generateAIConfigJSON,
30
- generateAIConfigToml,
31
30
  RECOMMENDED_AI_DEFAULTS,
32
31
  } from './ai.js';
33
32
 
@@ -46,7 +45,7 @@ export {
46
45
  listAIDependencyNames,
47
46
  formatAIDependencyHint,
48
47
  isAiEnabledInConfig,
49
- resolveDefaultProviderFromConfig,
48
+ resolveAgentProviderFromConfig,
50
49
  getRequiredAIDependenciesForConfig,
51
50
  diagnoseAIDependencies,
52
51
  formatAIDependencyFixCommand,
@@ -119,7 +118,7 @@ export {
119
118
  mergePluginManifestIntoPackageJson,
120
119
  finalizeWizardOptions,
121
120
  applyWizardOptionsToConfig,
122
- normalizePluginsMap,
121
+ clonePluginConfigurationMap,
123
122
  materializeDatabaseConfig,
124
123
  buildRuntimeConfigDocument,
125
124
  serializeRuntimeConfig,
@@ -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 plugins = Array.isArray(config.plugins)
42
- ? config.plugins.filter((p): p is string => typeof p === 'string')
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 (plugin.includes(`adapter-${ctx}`)) return true;
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 { parse as parseToml, stringify as stringifyToml } from 'smol-toml';
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 = 'yaml' | 'json' | 'toml' | 'ts';
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
- const ext = path.extname(filePath).toLowerCase();
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
- if (format === 'toml') {
99
- const parsed = parseToml(content) as unknown;
100
- return parsed && typeof parsed === 'object' && !Array.isArray(parsed)
101
- ? parsed as Record<string, unknown>
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
- for (const candidate of CONFIG_CANDIDATES) {
115
- const configPath = path.join(cwd, candidate);
116
- if (fs.existsSync(configPath)) return configPath;
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: '未找到 zhin.config.yml/json/toml',
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
- if (format === 'ts') {
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: 'zhin.config.ts 只读;请迁移为 zhin.config.yml/json/toml 后自动修复',
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: parseConfig(content, format),
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
- if (Array.isArray(config.plugins)) {
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 || !config.plugins || typeof config.plugins !== 'object') {
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: options.format ?? (options.configPath ? configFormatFromPath(options.configPath) ?? undefined : undefined),
300
+ format: configuredFormat,
332
301
  config: options.config,
333
- writable: Boolean(options.configPath && (options.format ?? configFormatFromPath(options.configPath)) !== 'ts'),
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 && plan.format !== 'ts' ? plan.format : 'yaml';
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 || plan.format === 'ts') return false;
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
- if (Array.isArray(config.plugins)) {
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')),
@@ -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 ?? ai.defaultProvider;
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 = resolveDefaultProviderFromConfig(config);
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 resolveDefaultProviderFromConfig(config: { ai?: unknown }): string | undefined {
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: resolveDefaultProviderFromConfig(config),
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: resolveDefaultProviderFromConfig(config),
367
+ provider: resolveAgentProviderFromConfig(config),
369
368
  required,
370
369
  missingFromPackageJson,
371
370
  outdatedInPackageJson,
package/src/types.ts CHANGED
@@ -7,7 +7,7 @@ export type { AdapterSetupResult } from './adapter.js';
7
7
  export interface InitOptions {
8
8
  name?: string;
9
9
  template?: 'default' | 'life-assistant';
10
- config?: 'json' | 'yaml' | 'toml';
10
+ config?: 'json' | 'yaml';
11
11
  runtime?: 'node' | 'bun';
12
12
  yes?: boolean;
13
13
  httpToken?: string;
@@ -30,4 +30,4 @@ export const DATABASE_PACKAGES: Record<DatabaseConfig['dialect'], string | undef
30
30
  pg: 'pg',
31
31
  mongodb: 'mongodb',
32
32
  redis: 'redis'
33
- };
33
+ };
@@ -23,6 +23,7 @@ export const ZHIN_STACK_VERSIONS = {
23
23
  '@zhin.js/layout': 'latest',
24
24
  '@zhin.js/page': 'latest',
25
25
  '@zhin.js/prompt-section': 'latest',
26
+ '@zhin.js/skill': 'latest',
26
27
  '@zhin.js/tool': 'latest',
27
28
  '@zhin.js/client': 'latest',
28
29
  '@zhin.js/contract': 'latest',
@@ -110,20 +111,6 @@ function resolveStackVersion(packageName: string): string {
110
111
  return ZHIN_STACK_VERSIONS[packageName as ZhinStackPackage] ?? 'latest';
111
112
  }
112
113
 
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
114
  /** create-zhin / minimal-bot 默认 Host 端口(避免与常见 8086 占用冲突) */
128
115
  export const DEFAULT_CREATE_BOT_HTTP_PORT = 8068;
129
116
 
@@ -144,6 +131,7 @@ export function getCreateBotPnpmConfig(_aiEnabled?: boolean): Record<string, unk
144
131
  export function getCreateBotBaseDependencies(): Record<string, string> {
145
132
  return {
146
133
  'zhin.js': ZHIN_STACK_VERSIONS['zhin.js'],
134
+ '@zhin.js/skill': ZHIN_STACK_VERSIONS['@zhin.js/skill'],
147
135
  };
148
136
  }
149
137
 
@@ -153,10 +141,6 @@ export function getRequiredZhinDependenciesForConfig(config: Record<string, unkn
153
141
  'zhin.js': ZHIN_STACK_VERSIONS['zhin.js'],
154
142
  };
155
143
 
156
- for (const plugin of collectZhinPluginsFromConfig(config)) {
157
- deps[plugin] = resolveStackVersion(plugin);
158
- }
159
-
160
144
  const database = config.database;
161
145
  if (database && typeof database === 'object' && !Array.isArray(database)) {
162
146
  deps['@zhin.js/database'] = ZHIN_STACK_VERSIONS['@zhin.js/database'];