@zhin.js/scaffold-wizard 0.2.0 → 0.2.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 (50) hide show
  1. package/README.md +2 -1
  2. package/lib/adapter-configurers.js +1 -1
  3. package/lib/adapter-configurers.js.map +1 -1
  4. package/lib/adapter.d.ts +5 -0
  5. package/lib/adapter.d.ts.map +1 -1
  6. package/lib/adapter.js +9 -2
  7. package/lib/adapter.js.map +1 -1
  8. package/lib/ai.d.ts +6 -0
  9. package/lib/ai.d.ts.map +1 -1
  10. package/lib/ai.js +20 -4
  11. package/lib/ai.js.map +1 -1
  12. package/lib/apply.d.ts +11 -6
  13. package/lib/apply.d.ts.map +1 -1
  14. package/lib/apply.js +84 -15
  15. package/lib/apply.js.map +1 -1
  16. package/lib/env.d.ts +14 -0
  17. package/lib/env.d.ts.map +1 -0
  18. package/lib/env.js +89 -0
  19. package/lib/env.js.map +1 -0
  20. package/lib/index.d.ts +4 -3
  21. package/lib/index.d.ts.map +1 -1
  22. package/lib/index.js +3 -2
  23. package/lib/index.js.map +1 -1
  24. package/lib/optional-peers.d.ts.map +1 -1
  25. package/lib/optional-peers.js +11 -0
  26. package/lib/optional-peers.js.map +1 -1
  27. package/lib/project-config-plan.d.ts +0 -1
  28. package/lib/project-config-plan.d.ts.map +1 -1
  29. package/lib/project-config-plan.js +0 -8
  30. package/lib/project-config-plan.js.map +1 -1
  31. package/lib/project-deps.d.ts +2 -1
  32. package/lib/project-deps.d.ts.map +1 -1
  33. package/lib/project-deps.js +13 -4
  34. package/lib/project-deps.js.map +1 -1
  35. package/lib/zhin-stack-deps.d.ts +4 -3
  36. package/lib/zhin-stack-deps.d.ts.map +1 -1
  37. package/lib/zhin-stack-deps.js +4 -20
  38. package/lib/zhin-stack-deps.js.map +1 -1
  39. package/package.json +1 -1
  40. package/src/adapter-configurers.ts +1 -1
  41. package/src/adapter.ts +10 -2
  42. package/src/ai.ts +21 -4
  43. package/src/apply.ts +98 -14
  44. package/src/env.ts +113 -0
  45. package/src/index.ts +11 -2
  46. package/src/optional-peers.ts +9 -0
  47. package/src/project-config-plan.ts +0 -9
  48. package/src/project-deps.ts +13 -4
  49. package/src/stack-versions.generated.json +36 -38
  50. package/src/zhin-stack-deps.ts +4 -22
package/src/index.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  export type { InitOptions, DatabaseConfig } from './types.js';
2
2
  export { DATABASE_PACKAGES } from './types.js';
3
3
 
4
- export type { AdapterSetupResult, AdapterPluginInstance } from './adapter.js';
4
+ export type { AdapterSetupResult, AdapterPluginInstance, AdapterDefinition } from './adapter.js';
5
5
  export {
6
+ ADAPTERS,
7
+ findAdapterByPackage,
6
8
  configureAdapters,
7
9
  buildFieldBasedInstanceConfig,
8
10
  generateAdapterEnvVars,
@@ -31,6 +33,12 @@ export {
31
33
 
32
34
  export { configureDatabaseOptions } from './database.js';
33
35
 
36
+ export {
37
+ formatEnvValue,
38
+ mergeEnvText,
39
+ generateDatabaseEnvVars,
40
+ } from './env.js';
41
+
34
42
  export {
35
43
  AI_STACK_VERSIONS,
36
44
  MCP_SDK_VERSION,
@@ -100,13 +108,14 @@ export type {
100
108
  } from './project-config-plan.js';
101
109
 
102
110
  export {
103
- CONSOLE_HOST_PLUGINS,
104
111
  applyDatabaseToConfig,
105
112
  applyAdaptersToConfig,
106
113
  applyAIToConfig,
107
114
  appendWizardEnvVars,
108
115
  collectWizardDependencies,
116
+ collectWizardFeatures,
109
117
  mergeDependenciesIntoPackageJson,
118
+ mergeFeaturesIntoPackageJson,
110
119
  mergePluginManifestIntoPackageJson,
111
120
  finalizeWizardOptions,
112
121
  applyWizardOptionsToConfig,
@@ -46,6 +46,15 @@ function configUsesHtmlImageAdapter(config: Record<string, unknown>): boolean {
46
46
  if (plugin.includes(`adapter-${ctx}`)) return true;
47
47
  }
48
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
+ }
56
+ }
57
+ }
49
58
  const endpoints = Array.isArray(config.endpoints) ? config.endpoints : [];
50
59
  for (const ep of endpoints) {
51
60
  if (!ep || typeof ep !== 'object' || Array.isArray(ep)) continue;
@@ -12,8 +12,6 @@ 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 数组配置诊断 */
16
- const CONSOLE_HOST_PLUGINS = ['@zhin.js/host-router', '@zhin.js/host-api'] as const;
17
15
  const SANDBOX_PLUGIN = '@zhin.js/adapter-sandbox';
18
16
  const LEGACY_AI_PROVIDER_FIELDS = ['driver', 'api', 'preset', 'spec'] as const;
19
17
 
@@ -66,7 +64,6 @@ export interface ProjectConfigPlan {
66
64
  }
67
65
 
68
66
  export interface ConsoleConfigDiagnosis {
69
- missingHostPlugins: string[];
70
67
  missingSandboxPlugin: boolean;
71
68
  missingConsoleOrigin: boolean;
72
69
  missingHttpToken: boolean;
@@ -344,10 +341,6 @@ export function createProjectConfigPlan(options: ProjectConfigPlanOptions): Proj
344
341
  const mutations: string[] = [];
345
342
 
346
343
  if (loaded.status === 'loaded' || options.config) {
347
- if (options.ensureConsole && Array.isArray(after.plugins)) {
348
- // legacy 数组形态:host 插件仍需写入列表(旧项目行为不变)
349
- ensurePlugins(after, CONSOLE_HOST_PLUGINS, mutations);
350
- }
351
344
  if (options.ensureSandbox) {
352
345
  ensurePlugins(after, [SANDBOX_PLUGIN], mutations);
353
346
  }
@@ -406,7 +399,6 @@ export function diagnoseConsoleConfig(config: Record<string, unknown>): ConsoleC
406
399
  // legacy 数组形式配置
407
400
  const plugins = config.plugins.filter((p): p is string => typeof p === 'string');
408
401
  return {
409
- missingHostPlugins: CONSOLE_HOST_PLUGINS.filter((plugin) => !plugins.includes(plugin)),
410
402
  missingSandboxPlugin: !plugins.includes(SANDBOX_PLUGIN),
411
403
  missingConsoleOrigin: !hasConsoleOrigin(corsOrigins.filter((origin): origin is string => typeof origin === 'string')),
412
404
  missingHttpToken: typeof http.token !== 'string' || http.token.trim().length === 0,
@@ -418,7 +410,6 @@ export function diagnoseConsoleConfig(config: Record<string, unknown>): ConsoleC
418
410
  ? config.plugins as Record<string, unknown>
419
411
  : {};
420
412
  return {
421
- missingHostPlugins: [],
422
413
  missingSandboxPlugin: !('sandbox' in plugins),
423
414
  missingConsoleOrigin: !hasConsoleOrigin(corsOrigins.filter((origin): origin is string => typeof origin === 'string')),
424
415
  missingHttpToken: typeof http.token !== 'string' || http.token.trim().length === 0,
@@ -211,7 +211,7 @@ export function findInstalledAiStackIncompatibilities(
211
211
  /** 启用 AI 时将写入 package.json 的依赖名(用于向导提示与 CLI 输出) */
212
212
  export function listAIDependencyNames(provider?: string, options?: { includeMcp?: boolean }): string[] {
213
213
  const names = ['@zhin.js/agent', 'zod', 'ai'];
214
- if (options?.includeMcp !== false) {
214
+ if (options?.includeMcp === true) {
215
215
  names.push('@modelcontextprotocol/sdk');
216
216
  }
217
217
  const sdk = providerSdkPackage(provider);
@@ -314,7 +314,11 @@ export function findUnresolvedPackageInstalls(cwd: string, packageNames: string[
314
314
  try {
315
315
  req.resolve(`${name}/package.json`);
316
316
  } catch {
317
- missing.push(name);
317
+ // exports map 未暴露 ./package.json(ERR_PACKAGE_PATH_NOT_EXPORTED,如 zhin.js)
318
+ // 时 resolve 必炸,退到 node_modules 文件系统判断(pnpm 顶层 symlink 可直达)。
319
+ if (!fs.existsSync(path.join(cwd, 'node_modules', name, 'package.json'))) {
320
+ missing.push(name);
321
+ }
318
322
  }
319
323
  }
320
324
  return missing;
@@ -376,7 +380,8 @@ export function formatAIDependencyFixCommand(packages: string[], required: Recor
376
380
  }
377
381
 
378
382
  /**
379
- * AI 启用时安装 agent 栈 + 所选 provider 的 @ai-sdk/* + 可选 MCP SDK。
383
+ * AI 启用时安装 agent 栈 + 所选 provider 的 @ai-sdk/*。
384
+ * `@modelcontextprotocol/sdk` 仅在 memoryMcp / mcpServers 时写入(与 doctor 对齐)。
380
385
  */
381
386
  export function getAIDependencies(ai?: AISetupConfig): Record<string, string> {
382
387
  if (!ai?.enabled) return {};
@@ -385,9 +390,13 @@ export function getAIDependencies(ai?: AISetupConfig): Record<string, string> {
385
390
  '@zhin.js/agent': AI_STACK_VERSIONS['@zhin.js/agent'],
386
391
  zod: AI_STACK_VERSIONS.zod,
387
392
  ai: AI_STACK_VERSIONS.ai,
388
- '@modelcontextprotocol/sdk': AI_STACK_VERSIONS['@modelcontextprotocol/sdk'],
389
393
  ...collectSdkPackagesFromSetup(ai),
390
394
  };
395
+ const needsMcp = ai.memoryMcp === true
396
+ || (Array.isArray(ai.mcpServers) && ai.mcpServers.length > 0);
397
+ if (needsMcp) {
398
+ deps['@modelcontextprotocol/sdk'] = AI_STACK_VERSIONS['@modelcontextprotocol/sdk'];
399
+ }
391
400
 
392
401
  return deps;
393
402
  }
@@ -1,48 +1,46 @@
1
1
  {
2
2
  "$comment": "Auto-generated by scripts/sync-scaffold-deps.mjs — do not edit; run pnpm sync:scaffold-deps",
3
3
  "zhinStack": {
4
- "zhin.js": "^4.1.0",
5
- "@zhin.js/cli": "^1.0.91",
6
- "@zhin.js/agent": "^1.0.1",
7
- "@zhin.js/database": "^1.0.74",
8
- "@zhin.js/host-router": "^2.0.1",
9
- "@zhin.js/host-api": "^2.0.3",
10
- "@zhin.js/client": "^2.0.3",
11
- "@zhin.js/contract": "^1.0.1",
12
- "@zhin.js/satori": "^1.0.15",
13
- "@zhin.js/speech": "^1.0.1",
14
- "@zhin.js/html-renderer": "^1.0.1",
15
- "@zhin.js/mcp": "^4.0.0",
16
- "@zhin.js/adapter-sandbox": "^5.0.3",
17
- "@zhin.js/adapter-dingtalk": "^4.0.0",
18
- "@zhin.js/adapter-discord": "^5.0.0",
19
- "@zhin.js/adapter-email": "^3.0.0",
20
- "@zhin.js/adapter-github": "^3.0.0",
21
- "@zhin.js/adapter-icqq": "^6.0.0",
22
- "@zhin.js/adapter-kook": "^5.0.0",
23
- "@zhin.js/adapter-lark": "^4.0.0",
24
- "@zhin.js/adapter-line": "^2.0.0",
25
- "@zhin.js/adapter-milky": "^3.0.0",
26
- "@zhin.js/adapter-napcat": "^3.0.0",
27
- "@zhin.js/adapter-onebot11": "^4.0.0",
28
- "@zhin.js/adapter-onebot12": "^3.0.0",
29
- "@zhin.js/adapter-qq": "^5.0.0",
30
- "@zhin.js/adapter-satori": "^3.0.0",
31
- "@zhin.js/adapter-slack": "^4.0.0",
32
- "@zhin.js/adapter-telegram": "^5.0.0",
33
- "@zhin.js/adapter-wechat-mp": "^3.0.0",
34
- "@zhin.js/adapter-wecom": "^2.0.0",
35
- "@zhin.js/adapter-weixin-ilink": "^3.0.0"
4
+ "zhin.js": "^5.0.0",
5
+ "@zhin.js/cli": "^2.0.0",
6
+ "@zhin.js/agent": "^1.0.5",
7
+ "@zhin.js/database": "^1.0.77",
8
+ "@zhin.js/client": "^2.1.0",
9
+ "@zhin.js/contract": "^1.0.5",
10
+ "@zhin.js/satori": "^1.0.16",
11
+ "@zhin.js/speech": "^2.0.0",
12
+ "@zhin.js/html-renderer": "^2.0.0",
13
+ "@zhin.js/mcp": "^5.0.0",
14
+ "@zhin.js/adapter-sandbox": "^6.0.0",
15
+ "@zhin.js/adapter-dingtalk": "^5.0.0",
16
+ "@zhin.js/adapter-discord": "^6.0.0",
17
+ "@zhin.js/adapter-email": "^4.0.0",
18
+ "@zhin.js/adapter-github": "^4.0.0",
19
+ "@zhin.js/adapter-icqq": "^7.0.0",
20
+ "@zhin.js/adapter-kook": "^6.0.0",
21
+ "@zhin.js/adapter-lark": "^5.0.0",
22
+ "@zhin.js/adapter-line": "^3.0.0",
23
+ "@zhin.js/adapter-milky": "^5.0.0",
24
+ "@zhin.js/adapter-napcat": "^5.0.0",
25
+ "@zhin.js/adapter-onebot11": "^5.0.0",
26
+ "@zhin.js/adapter-onebot12": "^4.0.0",
27
+ "@zhin.js/adapter-qq": "^6.0.0",
28
+ "@zhin.js/adapter-satori": "^4.0.0",
29
+ "@zhin.js/adapter-slack": "^5.0.0",
30
+ "@zhin.js/adapter-telegram": "^6.0.0",
31
+ "@zhin.js/adapter-wechat-mp": "^4.0.0",
32
+ "@zhin.js/adapter-wecom": "^3.0.0",
33
+ "@zhin.js/adapter-weixin-ilink": "^4.0.0"
36
34
  },
37
35
  "aiStack": {
38
- "@zhin.js/agent": "^1.0.1",
36
+ "@zhin.js/agent": "^1.0.5",
39
37
  "ai": "^7.0.0",
40
38
  "zod": "^4.0.0",
41
- "@ai-sdk/openai": "^4.0.0",
42
- "@ai-sdk/anthropic": "^4.0.0",
43
- "@ai-sdk/google": "^4.0.0",
44
- "@ai-sdk/deepseek": "^3.0.0",
45
- "@ai-sdk/openai-compatible": "^3.0.0",
39
+ "@ai-sdk/openai": "^4.0.8",
40
+ "@ai-sdk/anthropic": "^4.0.9",
41
+ "@ai-sdk/google": "^4.0.9",
42
+ "@ai-sdk/deepseek": "^3.0.5",
43
+ "@ai-sdk/openai-compatible": "^3.0.5",
46
44
  "@modelcontextprotocol/sdk": "^1.29.0"
47
45
  }
48
46
  }
@@ -20,8 +20,6 @@ export const ZHIN_STACK_VERSIONS = {
20
20
  '@zhin.js/component': 'latest',
21
21
  '@zhin.js/core': 'latest',
22
22
  '@zhin.js/tool': 'latest',
23
- '@zhin.js/host-router': 'latest',
24
- '@zhin.js/host-api': 'latest',
25
23
  '@zhin.js/client': 'latest',
26
24
  '@zhin.js/contract': 'latest',
27
25
  '@zhin.js/satori': 'latest',
@@ -52,11 +50,6 @@ export const ZHIN_STACK_VERSIONS = {
52
50
 
53
51
  export type ZhinStackPackage = keyof typeof ZHIN_STACK_VERSIONS;
54
52
 
55
- const HOST_CONSOLE_PLUGINS = new Set([
56
- '@zhin.js/host-router',
57
- '@zhin.js/host-api',
58
- ]);
59
-
60
53
  function parseMajor(versionSpec: string | undefined): number | undefined {
61
54
  if (!versionSpec?.trim()) return undefined;
62
55
  if (versionSpec === 'workspace:*') return undefined;
@@ -115,17 +108,13 @@ export function getCreateBotPnpmConfig(_aiEnabled?: boolean): Record<string, unk
115
108
  };
116
109
  }
117
110
 
118
- /** create-zhin-app Plugin Runtime 骨架 production 依赖(不含适配器 / AI / 数据库驱动) */
111
+ /**
112
+ * create-zhin-app Plugin Runtime 骨架 production 依赖(不含适配器 / AI / 数据库驱动)。
113
+ * Stable Features(adapter/command/component/middleware)由 `@zhin.js/core` 的 `package.json#zhin.features` 继承;创作面 API 经 `zhin.js/*` 便利入口。
114
+ */
119
115
  export function getCreateBotBaseDependencies(): Record<string, string> {
120
116
  return {
121
117
  'zhin.js': ZHIN_STACK_VERSIONS['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'],
128
- '@zhin.js/satori': ZHIN_STACK_VERSIONS['@zhin.js/satori'],
129
118
  };
130
119
  }
131
120
 
@@ -149,13 +138,6 @@ export function getRequiredZhinDependenciesForConfig(config: Record<string, unkn
149
138
  }
150
139
  }
151
140
 
152
- const usesHost = collectZhinPluginsFromConfig(config).some((p) => HOST_CONSOLE_PLUGINS.has(p));
153
- if (usesHost) {
154
- for (const pkg of ['@zhin.js/host-router', '@zhin.js/host-api'] as const) {
155
- deps[pkg] = ZHIN_STACK_VERSIONS[pkg];
156
- }
157
- }
158
-
159
141
  return deps;
160
142
  }
161
143