@nimiplatform/app-tools 0.1.3 → 0.2.0

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 (120) hide show
  1. package/LICENSE +198 -6
  2. package/README.md +83 -27
  3. package/bin/nimi-app.mjs +328 -45
  4. package/lib/app-access-declaration.mjs +49 -0
  5. package/lib/app-doctor-update.mjs +411 -149
  6. package/lib/app-pack.mjs +401 -0
  7. package/lib/app-project-lifecycle.mjs +1141 -0
  8. package/lib/app-scaffold-capabilities.mjs +769 -0
  9. package/lib/app-scaffold-default-source.mjs +21 -0
  10. package/lib/app-scaffold-profiles.mjs +1093 -0
  11. package/lib/app-scaffold.mjs +1266 -813
  12. package/lib/index.mjs +194 -42
  13. package/lib/simulator-conformance-ast.mjs +498 -0
  14. package/lib/simulator-conformance-css.mjs +116 -0
  15. package/lib/simulator-conformance-graph.mjs +757 -0
  16. package/lib/simulator-conformance.d.mts +14 -0
  17. package/lib/simulator-conformance.mjs +203 -0
  18. package/lib/simulator-css-profile.d.mts +27 -0
  19. package/lib/simulator-css-profile.mjs +531 -0
  20. package/lib/simulator-kit-export-resolution.mjs +70 -0
  21. package/lib/simulator-manifest.mjs +334 -0
  22. package/package.json +66 -3
  23. package/scripts/dev-shell.mjs +465 -0
  24. package/scripts/sync-app-source.mjs +300 -0
  25. package/scripts/sync-scaffold-versions.mjs +91 -0
  26. package/templates/app-source/LICENSE +21 -0
  27. package/templates/app-source/src/ai-studio-core/ai-config.ts +100 -0
  28. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +338 -0
  29. package/templates/app-source/src/ai-studio-core/contexts.tsx +61 -0
  30. package/templates/app-source/src/ai-studio-core/history-policy.ts +447 -0
  31. package/templates/app-source/src/ai-studio-core/history.ts +824 -0
  32. package/templates/app-source/src/ai-studio-core/host-context.tsx +79 -0
  33. package/templates/app-source/src/ai-studio-core/index.ts +214 -0
  34. package/templates/app-source/src/ai-studio-core/messages/en.json +310 -0
  35. package/templates/app-source/src/ai-studio-core/messages/index.ts +47 -0
  36. package/templates/app-source/src/ai-studio-core/messages/zh.json +310 -0
  37. package/templates/app-source/src/ai-studio-core/module-registration.ts +109 -0
  38. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +65 -0
  39. package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +247 -0
  40. package/templates/app-source/src/ai-studio-core/parameters.ts +110 -0
  41. package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +69 -0
  42. package/templates/app-source/src/ai-studio-core/run-target.ts +123 -0
  43. package/templates/app-source/src/ai-studio-core/runtime-dispatcher.ts +35 -0
  44. package/templates/app-source/src/ai-studio-core/runtime-types.ts +86 -0
  45. package/templates/app-source/src/ai-studio-core/runtime.ts +306 -0
  46. package/templates/app-source/src/ai-studio-core/section-ai-testing-admission.ts +38 -0
  47. package/templates/app-source/src/ai-studio-core/section-ai-testing-ai-config.tsx +30 -0
  48. package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +40 -0
  49. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +257 -0
  50. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +676 -0
  51. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +19 -0
  52. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +291 -0
  53. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +413 -0
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +174 -0
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +449 -0
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +45 -0
  57. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +494 -0
  58. package/templates/app-source/src/ai-studio-core/studio-directives.ts +33 -0
  59. package/templates/app-source/src/ai-studio-core/workspace.tsx +381 -0
  60. package/templates/app-source/src/product-modules/agent-center/index.tsx +27 -0
  61. package/templates/app-source/src/product-modules/agent-conversation/index.tsx +19 -0
  62. package/templates/app-source/src/product-modules/agent-realtime/index.tsx +29 -0
  63. package/templates/app-source/src/product-modules/kit-recipes/gallery.tsx +142 -0
  64. package/templates/app-source/src/product-modules/kit-recipes/index.tsx +19 -0
  65. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-data-recipes.tsx +336 -0
  66. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-demos.tsx +165 -0
  67. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-recipes.tsx +682 -0
  68. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-surface.tsx +341 -0
  69. package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +26 -0
  70. package/templates/app-source/src/studio-modules/studio-create/index.ts +14 -0
  71. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +67 -0
  72. package/templates/app-source/src/studio-modules/studio-create/messages/index.ts +5 -0
  73. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +67 -0
  74. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +153 -0
  75. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +70 -0
  76. package/templates/app-source/src/studio-modules/studio-create/registration.ts +46 -0
  77. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +339 -0
  78. package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +22 -0
  79. package/templates/app-source/src/studio-modules/studio-media/index.ts +12 -0
  80. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +82 -0
  81. package/templates/app-source/src/studio-modules/studio-media/messages/index.ts +5 -0
  82. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +82 -0
  83. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +283 -0
  84. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +94 -0
  85. package/templates/app-source/src/studio-modules/studio-media/registration.ts +44 -0
  86. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +113 -0
  87. package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +28 -0
  88. package/templates/app-source/src/studio-modules/studio-voice/index.ts +16 -0
  89. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +99 -0
  90. package/templates/app-source/src/studio-modules/studio-voice/messages/index.ts +5 -0
  91. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +99 -0
  92. package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +284 -0
  93. package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +116 -0
  94. package/templates/app-source/src/studio-modules/studio-voice/registration.ts +59 -0
  95. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +347 -0
  96. package/templates/app-source/src/workbench-core/empty-state.tsx +31 -0
  97. package/templates/app-source/src/workbench-core/index.ts +17 -0
  98. package/templates/app-source/src/workbench-core/runtime-gate.tsx +131 -0
  99. package/templates/app-source/src/workbench-core/workbench-core.css +255 -0
  100. package/templates/app-source/src/workbench-core/workbench-core.tsx +140 -0
  101. package/templates/app-source.manifest.json +333 -0
  102. package/templates/default-starter/AGENTS.md +33 -0
  103. package/templates/default-starter/LICENSE +21 -0
  104. package/templates/default-starter/README.md +41 -0
  105. package/templates/default-starter/SECURITY.md +5 -0
  106. package/templates/default-starter/index.html +12 -0
  107. package/templates/default-starter/scripts/validate.mjs +26 -0
  108. package/templates/default-starter/src/shell/App.tsx +27 -0
  109. package/templates/default-starter/src/shell/auth/app-identity.ts +3 -0
  110. package/templates/default-starter/src/shell/auth/local-app-client.ts +18 -0
  111. package/templates/default-starter/src/shell/auth/runtime-platform.ts +110 -0
  112. package/templates/default-starter/src/shell/authenticated-shell.tsx +20 -0
  113. package/templates/default-starter/src/shell/workbench-target-adapter.ts +40 -0
  114. package/templates/default-starter/src/styles.css +26 -0
  115. package/templates/default-starter/src-tauri/Cargo.toml +17 -0
  116. package/templates/default-starter/src-tauri/build.rs +5 -0
  117. package/templates/default-starter/src-tauri/capabilities/default.json +7 -0
  118. package/templates/default-starter/src-tauri/tauri.conf.json +26 -0
  119. package/templates/default-starter/tsconfig.json +18 -0
  120. package/templates/default-starter.manifest.json +99 -0
package/lib/index.mjs CHANGED
@@ -1,24 +1,38 @@
1
- import { existsSync, mkdirSync, readdirSync, statSync, writeFileSync } from 'node:fs';
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
2
+ import { spawnSync } from 'node:child_process';
2
3
  import path from 'node:path';
3
- import { createAppScaffold } from './app-scaffold.mjs';
4
- import { doctorApp, updateApp } from './app-doctor-update.mjs';
5
-
6
- const SDK_VERSION = '^0.5.15';
7
- const APP_TOOLS_VERSION = '^0.1.3';
8
- const KIT_VERSION = '^0.1.0';
9
- const REACT_VERSION = '^19.1.0';
10
- const REACT_DOM_VERSION = '^19.1.0';
11
- const TYPESCRIPT_VERSION = '^5.9.3';
12
- const TSX_VERSION = '^4.21.0';
13
- const NODE_TYPES_VERSION = '^24.10.1';
14
- const REACT_TYPES_VERSION = '^19.2.14';
15
- const REACT_DOM_TYPES_VERSION = '^19.2.3';
16
- const VITE_VERSION = '^7.2.4';
17
- const VITE_REACT_PLUGIN_VERSION = '^5.1.1';
18
- const TAURI_API_VERSION = '^2.9.1';
19
- const TAURI_CLI_VERSION = '^2.11.2';
20
- const NIMI_SHELL_TAURI_VERSION = '0.1.0';
21
- const AI_SDK_VERSION = '^6.0.85';
4
+ import {
5
+ buildAppScaffoldCandidateCreatePlan,
6
+ buildAppScaffoldCreatePlan,
7
+ createAppScaffold,
8
+ createAppScaffoldCandidate,
9
+ resolveAppScaffoldCandidateCreateInput,
10
+ resolveAppScaffoldCreateInput,
11
+ } from './app-scaffold.mjs';
12
+ import { initApp } from './app-doctor-update.mjs';
13
+ import {
14
+ buildAppProject,
15
+ checkAppProject,
16
+ syncAppProject,
17
+ testAppProject,
18
+ } from './app-project-lifecycle.mjs';
19
+ import { aggregateAppTargetCandidates, packAppTarget } from './app-pack.mjs';
20
+ export { runDevShell } from '../scripts/dev-shell.mjs';
21
+ export {
22
+ validateSimulatorAppSource,
23
+ validateSimulatorAppSourceWithCanonicalKitExports,
24
+ } from './simulator-conformance.mjs';
25
+ export { APP_SCAFFOLD_FEATURE_IDS } from './app-scaffold-capabilities.mjs';
26
+
27
+ const APP_TOOLS_PACKAGE_MANIFEST = JSON.parse(
28
+ readFileSync(new URL('../package.json', import.meta.url), 'utf8'),
29
+ );
30
+ if (!APP_TOOLS_PACKAGE_MANIFEST.nimiScaffoldVersions
31
+ || typeof APP_TOOLS_PACKAGE_MANIFEST.nimiScaffoldVersions !== 'object'
32
+ || Array.isArray(APP_TOOLS_PACKAGE_MANIFEST.nimiScaffoldVersions)) {
33
+ throw new Error('app-tools package manifest is missing nimiScaffoldVersions');
34
+ }
35
+ const SCAFFOLD_VERSIONS = Object.freeze({ ...APP_TOOLS_PACKAGE_MANIFEST.nimiScaffoldVersions });
22
36
 
23
37
  function ensureDirEmptyOrMissing(targetDir) {
24
38
  if (!existsSync(targetDir)) {
@@ -46,29 +60,98 @@ function createFileTree(baseDir, files) {
46
60
  }
47
61
  }
48
62
 
49
- function appScaffoldVersions() {
63
+ export function appScaffoldVersions() {
64
+ return { ...SCAFFOLD_VERSIONS };
65
+ }
66
+
67
+ function runNimicodingSync(targetDir, mode) {
68
+ if (!['apply', 'check'].includes(mode)) {
69
+ throw new Error(`Unsupported nimicoding sync mode: ${mode}`);
70
+ }
71
+ const flag = mode === 'apply' ? '--apply' : '--check';
72
+ const pnpmArgs = ['--silent', 'exec', 'nimicoding', 'sync', flag, '--json'];
73
+ const command =
74
+ process.platform === 'win32'
75
+ ? { binary: 'cmd.exe', args: ['/d', '/c', 'corepack', 'pnpm', ...pnpmArgs] }
76
+ : { binary: 'corepack', args: ['pnpm', ...pnpmArgs] };
77
+ const result = spawnSync(command.binary, command.args, {
78
+ cwd: targetDir,
79
+ encoding: 'utf8',
80
+ });
81
+ if (result.status !== 0) {
82
+ const output = [result.error?.message, result.stdout, result.stderr].filter(Boolean).join('\n').trim();
83
+ throw new Error(`nimicoding sync ${mode} failed. Run pnpm install before rerunning the lifecycle command. ${output}`);
84
+ }
85
+ try {
86
+ return JSON.parse(result.stdout);
87
+ } catch (error) {
88
+ const message = error instanceof Error ? error.message : String(error);
89
+ throw new Error(`nimicoding sync ${mode} returned invalid JSON: ${message}`);
90
+ }
91
+ }
92
+
93
+ function runAppCommand(targetDir, command, options = {}) {
94
+ const result = spawnSync(command, {
95
+ cwd: targetDir,
96
+ shell: true,
97
+ encoding: 'utf8',
98
+ stdio: options.capture ? 'pipe' : 'inherit',
99
+ });
50
100
  return {
51
- sdkVersion: SDK_VERSION,
52
- appToolsVersion: APP_TOOLS_VERSION,
53
- aiSdkVersion: AI_SDK_VERSION,
54
- kitVersion: KIT_VERSION,
55
- reactVersion: REACT_VERSION,
56
- reactDomVersion: REACT_DOM_VERSION,
57
- tsxVersion: TSX_VERSION,
58
- typescriptVersion: TYPESCRIPT_VERSION,
59
- nodeTypesVersion: NODE_TYPES_VERSION,
60
- reactTypesVersion: REACT_TYPES_VERSION,
61
- reactDomTypesVersion: REACT_DOM_TYPES_VERSION,
62
- viteVersion: VITE_VERSION,
63
- viteReactPluginVersion: VITE_REACT_PLUGIN_VERSION,
64
- tauriApiVersion: TAURI_API_VERSION,
65
- tauriCliVersion: TAURI_CLI_VERSION,
66
- nimiShellTauriVersion: NIMI_SHELL_TAURI_VERSION,
101
+ status: result.status ?? 1,
102
+ stdout: result.stdout || '',
103
+ stderr: [result.error?.message, result.stderr].filter(Boolean).join('\n'),
67
104
  };
68
105
  }
69
106
 
107
+ function signWindowsTarget(targetDir, relativePayloadPath) {
108
+ const targetPath = path.resolve(targetDir, ...relativePayloadPath.split('/'));
109
+ const rootPrefix = `${path.resolve(targetDir)}${path.sep}`;
110
+ if (!targetPath.startsWith(rootPrefix) || !existsSync(targetPath) || !statSync(targetPath).isFile()) {
111
+ throw new Error(`Windows production signing target is missing: ${relativePayloadPath}`);
112
+ }
113
+ const script = [
114
+ "$ErrorActionPreference = 'Stop'",
115
+ "if ([string]::IsNullOrWhiteSpace($env:WINDOWS_CERTIFICATE_BASE64) -or [string]::IsNullOrWhiteSpace($env:WINDOWS_CERTIFICATE_PASSWORD)) { throw 'Windows signing credentials are missing' }",
116
+ "$pfxPath = Join-Path ([IO.Path]::GetTempPath()) ('nimi-app-sign-' + [guid]::NewGuid().ToString('N') + '.pfx')",
117
+ '$cert = $null',
118
+ 'try {',
119
+ ' [IO.File]::WriteAllBytes($pfxPath, [Convert]::FromBase64String($env:WINDOWS_CERTIFICATE_BASE64))',
120
+ ' $password = ConvertTo-SecureString $env:WINDOWS_CERTIFICATE_PASSWORD -AsPlainText -Force',
121
+ " $cert = Import-PfxCertificate -FilePath $pfxPath -CertStoreLocation 'Cert:\\CurrentUser\\My' -Password $password -Exportable:$false",
122
+ " if (-not $cert) { throw 'Windows signing certificate import failed' }",
123
+ " $kitsRoot = Join-Path ${env:ProgramFiles(x86)} 'Windows Kits\\10\\bin'",
124
+ " $signTool = Get-ChildItem -LiteralPath $kitsRoot -Filter 'signtool.exe' -Recurse -File | Where-Object { $_.FullName -match '\\\\x64\\\\signtool\\.exe$' } | Sort-Object FullName -Descending | Select-Object -First 1",
125
+ " if (-not $signTool) { throw 'signtool.exe was not found' }",
126
+ " & $signTool.FullName sign /fd SHA256 /td SHA256 /tr 'http://timestamp.digicert.com' /sha1 $cert.Thumbprint $env:NIMI_APP_SIGN_TARGET",
127
+ " if ($LASTEXITCODE -ne 0) { throw 'signtool failed' }",
128
+ ' $signature = Get-AuthenticodeSignature -LiteralPath $env:NIMI_APP_SIGN_TARGET',
129
+ " if ($signature.Status -ne 'Valid') { throw ('Authenticode status: ' + $signature.Status) }",
130
+ ' $signature.SignerCertificate.Subject',
131
+ '} finally {',
132
+ " if ($cert) { Remove-Item -LiteralPath ('Cert:\\CurrentUser\\My\\' + $cert.Thumbprint) -Force -ErrorAction SilentlyContinue }",
133
+ ' [IO.File]::Delete($pfxPath)',
134
+ '}',
135
+ ].join('\n');
136
+ const result = spawnSync('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', script], {
137
+ cwd: targetDir,
138
+ encoding: 'utf8',
139
+ env: { ...process.env, NIMI_APP_SIGN_TARGET: targetPath },
140
+ });
141
+ if (result.status !== 0) {
142
+ const detail = [result.error?.message, result.stdout, result.stderr].filter(Boolean).join('\n').trim();
143
+ throw new Error(`Windows production signing failed${detail ? `: ${detail}` : ''}`);
144
+ }
145
+ return { subject: String(result.stdout || '').trim() };
146
+ }
147
+
148
+ function appToolRunners() {
149
+ return { runNimicodingSync, runAppCommand, signWindowsTarget };
150
+ }
151
+
70
152
  export function createApp(cwd, options = {}) {
71
- createAppScaffold({
153
+ const plan = options.plan || resolveAppCreatePlan(cwd, options);
154
+ return createAppScaffold({
72
155
  cwd,
73
156
  options: {
74
157
  dir: options.dir,
@@ -78,18 +161,87 @@ export function createApp(cwd, options = {}) {
78
161
  title: options.title,
79
162
  packageName: options.packageName,
80
163
  author: options.author,
164
+ features: options.features,
165
+ silent: options.silent,
81
166
  },
82
167
  versions: appScaffoldVersions(),
83
168
  createFileTree,
84
169
  ensureDirEmptyOrMissing,
85
170
  mkdirSync,
171
+ plan,
172
+ });
173
+ }
174
+
175
+ export function resolveAppCreateInput(cwd, options = {}) {
176
+ return resolveAppScaffoldCreateInput({ cwd, options });
177
+ }
178
+
179
+ export function resolveAppCreatePlan(cwd, options = {}) {
180
+ return resolveAppCreatePlanWith(
181
+ cwd,
182
+ options,
183
+ resolveAppScaffoldCreateInput,
184
+ buildAppScaffoldCreatePlan,
185
+ );
186
+ }
187
+
188
+ export function resolveCandidateAppCreatePlan(cwd, options = {}) {
189
+ return resolveAppCreatePlanWith(
190
+ cwd,
191
+ options,
192
+ resolveAppScaffoldCandidateCreateInput,
193
+ buildAppScaffoldCandidateCreatePlan,
194
+ );
195
+ }
196
+
197
+ function resolveAppCreatePlanWith(cwd, options, resolveInput, buildPlan) {
198
+ const resolvedInput = resolveInput({ cwd, options });
199
+ ensureDirEmptyOrMissing(resolvedInput.targetDir);
200
+ const topology = resolveCreateTopology();
201
+ const versions = appScaffoldVersions();
202
+ const plan = buildPlan({ cwd, options, versions, topology });
203
+ return plan;
204
+ }
205
+
206
+ export function createCandidateApp(cwd, options = {}) {
207
+ const plan = options.plan || resolveCandidateAppCreatePlan(cwd, options);
208
+ return createAppScaffoldCandidate({
209
+ cwd,
210
+ options,
211
+ versions: appScaffoldVersions(),
212
+ createFileTree,
213
+ ensureDirEmptyOrMissing,
214
+ mkdirSync,
215
+ plan,
86
216
  });
87
217
  }
88
218
 
89
- export function doctorAppScaffold(cwd, options = {}) {
90
- return doctorApp(cwd, options, appScaffoldVersions());
219
+ function resolveCreateTopology() {
220
+ return Object.freeze({ profile: 'standalone' });
221
+ }
222
+
223
+ export function initAppScaffold(cwd, options = {}) {
224
+ return initApp(cwd, options, appScaffoldVersions(), appToolRunners());
225
+ }
226
+
227
+ export function syncApp(cwd, options = {}) {
228
+ return syncAppProject(cwd, options, appScaffoldVersions(), appToolRunners());
229
+ }
230
+
231
+ export function checkApp(cwd, options = {}) {
232
+ return checkAppProject(cwd, options, appScaffoldVersions(), appToolRunners());
233
+ }
234
+
235
+ export function testApp(cwd, options = {}) {
236
+ return testAppProject(cwd, options, appToolRunners());
237
+ }
238
+
239
+ export function buildApp(cwd, options = {}) {
240
+ return buildAppProject(cwd, options, appToolRunners());
91
241
  }
92
242
 
93
- export function updateAppScaffold(cwd, options = {}) {
94
- return updateApp(cwd, options, appScaffoldVersions());
243
+ export function packApp(cwd, options = {}) {
244
+ return options.aggregate
245
+ ? aggregateAppTargetCandidates(cwd, options)
246
+ : packAppTarget(cwd, options);
95
247
  }