@zhin.js/scaffold-wizard 0.2.6 → 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.
Files changed (45) hide show
  1. package/lib/adapter-configurers.d.ts.map +1 -1
  2. package/lib/adapter-configurers.js +2 -1
  3. package/lib/adapter-configurers.js.map +1 -1
  4. package/lib/adapter.js +1 -1
  5. package/lib/adapter.js.map +1 -1
  6. package/lib/ai.d.ts +1 -7
  7. package/lib/ai.d.ts.map +1 -1
  8. package/lib/ai.js +0 -63
  9. package/lib/ai.js.map +1 -1
  10. package/lib/apply.d.ts +4 -4
  11. package/lib/apply.d.ts.map +1 -1
  12. package/lib/apply.js +6 -23
  13. package/lib/apply.js.map +1 -1
  14. package/lib/index.d.ts +3 -3
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +3 -3
  17. package/lib/index.js.map +1 -1
  18. package/lib/optional-peers.d.ts.map +1 -1
  19. package/lib/optional-peers.js +5 -16
  20. package/lib/optional-peers.js.map +1 -1
  21. package/lib/project-config-plan.d.ts +2 -1
  22. package/lib/project-config-plan.d.ts.map +1 -1
  23. package/lib/project-config-plan.js +29 -83
  24. package/lib/project-config-plan.js.map +1 -1
  25. package/lib/project-deps.d.ts +1 -1
  26. package/lib/project-deps.d.ts.map +1 -1
  27. package/lib/project-deps.js +5 -7
  28. package/lib/project-deps.js.map +1 -1
  29. package/lib/types.d.ts +1 -1
  30. package/lib/types.d.ts.map +1 -1
  31. package/lib/zhin-stack-deps.d.ts +1 -0
  32. package/lib/zhin-stack-deps.d.ts.map +1 -1
  33. package/lib/zhin-stack-deps.js +32 -20
  34. package/lib/zhin-stack-deps.js.map +1 -1
  35. package/package.json +3 -3
  36. package/src/adapter-configurers.ts +2 -1
  37. package/src/adapter.ts +1 -1
  38. package/src/ai.ts +1 -70
  39. package/src/apply.ts +9 -22
  40. package/src/index.ts +2 -3
  41. package/src/optional-peers.ts +4 -14
  42. package/src/project-config-plan.ts +35 -79
  43. package/src/project-deps.ts +5 -6
  44. package/src/types.ts +2 -2
  45. package/src/zhin-stack-deps.ts +31 -22
@@ -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',
@@ -61,6 +62,12 @@ function parseMajor(versionSpec: string | undefined): number | undefined {
61
62
  return match ? Number(match[1]) : undefined;
62
63
  }
63
64
 
65
+ function parseMajorMinor(versionSpec: string | undefined): [number, number] | undefined {
66
+ if (!versionSpec?.trim()) return undefined;
67
+ const match = versionSpec.trim().replace(/^[\^~>=<]+/, '').match(/^(\d+)\.(\d+)/);
68
+ return match ? [Number(match[1]), Number(match[2])] : undefined;
69
+ }
70
+
64
71
  function getDeclaredPackageVersion(pkg: PackageJsonLike, name: string): string | undefined {
65
72
  return pkg.dependencies?.[name] ?? pkg.devDependencies?.[name];
66
73
  }
@@ -77,26 +84,31 @@ function readInstalledMajor(cwd: string, packageName: string): number | undefine
77
84
  }
78
85
  }
79
86
 
87
+ function readInstalledVersion(cwd: string, packageName: string): string | undefined {
88
+ const pkgJson = path.join(cwd, 'package.json');
89
+ if (!fs.existsSync(pkgJson)) return undefined;
90
+ try {
91
+ const req = createRequire(pkgJson);
92
+ const installed = req(`${packageName}/package.json`) as { version?: string };
93
+ return installed.version;
94
+ } catch {
95
+ return undefined;
96
+ }
97
+ }
98
+
80
99
  function resolvePackageMajor(cwd: string, pkg: PackageJsonLike, packageName: string): number | undefined {
81
100
  return readInstalledMajor(cwd, packageName) ?? parseMajor(getDeclaredPackageVersion(pkg, packageName));
82
101
  }
83
102
 
84
- function resolveStackVersion(packageName: string): string {
85
- return ZHIN_STACK_VERSIONS[packageName as ZhinStackPackage] ?? 'latest';
103
+ function supportsSplitAiInstallation(versionSpec: string | undefined): boolean | undefined {
104
+ const version = parseMajorMinor(versionSpec);
105
+ if (!version) return undefined;
106
+ const [major, minor] = version;
107
+ return major >= 4 || (major === 1 && minor >= 1);
86
108
  }
87
109
 
88
- function collectZhinPluginsFromConfig(config: Record<string, unknown>): string[] {
89
- // legacy 数组形式:条目即包名
90
- if (Array.isArray(config.plugins)) {
91
- const plugins = config.plugins.filter((p): p is string => typeof p === 'string');
92
- return [...new Set(plugins.filter((p) => p.startsWith('@zhin.js/')))];
93
- }
94
- // 新 runtime:plugins 为 instanceKey 映射,包名在 package.json zhin.plugins 清单中,
95
- // 无法从配置推导;仅收集直接以包名出现的键(防御性)
96
- if (config.plugins && typeof config.plugins === 'object') {
97
- return Object.keys(config.plugins as Record<string, unknown>).filter((key) => key.startsWith('@zhin.js/'));
98
- }
99
- return [];
110
+ function resolveStackVersion(packageName: string): string {
111
+ return ZHIN_STACK_VERSIONS[packageName as ZhinStackPackage] ?? 'latest';
100
112
  }
101
113
 
102
114
  /** create-zhin / minimal-bot 默认 Host 端口(避免与常见 8086 占用冲突) */
@@ -119,6 +131,7 @@ export function getCreateBotPnpmConfig(_aiEnabled?: boolean): Record<string, unk
119
131
  export function getCreateBotBaseDependencies(): Record<string, string> {
120
132
  return {
121
133
  'zhin.js': ZHIN_STACK_VERSIONS['zhin.js'],
134
+ '@zhin.js/skill': ZHIN_STACK_VERSIONS['@zhin.js/skill'],
122
135
  };
123
136
  }
124
137
 
@@ -128,10 +141,6 @@ export function getRequiredZhinDependenciesForConfig(config: Record<string, unkn
128
141
  'zhin.js': ZHIN_STACK_VERSIONS['zhin.js'],
129
142
  };
130
143
 
131
- for (const plugin of collectZhinPluginsFromConfig(config)) {
132
- deps[plugin] = resolveStackVersion(plugin);
133
- }
134
-
135
144
  const database = config.database;
136
145
  if (database && typeof database === 'object' && !Array.isArray(database)) {
137
146
  deps['@zhin.js/database'] = ZHIN_STACK_VERSIONS['@zhin.js/database'];
@@ -173,14 +182,14 @@ export function findInstalledZhinStackIncompatibilities(
173
182
  config: Record<string, unknown>,
174
183
  ): ZhinStackIncompatibility[] {
175
184
  const issues: ZhinStackIncompatibility[] = [];
176
- const zhinMajor = resolvePackageMajor(cwd, pkg, 'zhin.js');
185
+ const zhinVersion = readInstalledVersion(cwd, 'zhin.js') ?? getDeclaredPackageVersion(pkg, 'zhin.js');
177
186
  const agentDeclared = getDeclaredPackageVersion(pkg, '@zhin.js/agent');
178
187
  const aiEnabled = isAiEnabledInConfig(config);
179
188
 
180
- if (zhinMajor != null && zhinMajor < 4 && (aiEnabled || agentDeclared)) {
189
+ if (supportsSplitAiInstallation(zhinVersion) === false && (aiEnabled || agentDeclared)) {
181
190
  issues.push({
182
191
  package: 'zhin.js',
183
- reason: 'zhin.js 4.x 才支持 @zhin.js/agent 与 AI 安装分层(ADR 0019),请升级 zhin.js',
192
+ reason: 'zhin.js 1.1.x 稳定线才支持当前 @zhin.js/agent 与 AI 安装分层,请升级 zhin.js',
184
193
  });
185
194
  }
186
195
 
@@ -192,7 +201,7 @@ export function findInstalledZhinStackIncompatibilities(
192
201
  if (agentMajor != null && agentMajor < 1 && aiEnabled) {
193
202
  issues.push({
194
203
  package: '@zhin.js/agent',
195
- reason: '@zhin.js/agent 1.x 与 zhin.js 4.x / AI SDK 7 配套,请升级 @zhin.js/agent',
204
+ reason: '@zhin.js/agent 1.x 与 zhin.js 1.1.x 稳定线 / AI SDK 7 配套,请升级 @zhin.js/agent',
196
205
  });
197
206
  }
198
207