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