@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
@@ -0,0 +1,347 @@
1
+ import type { RuntimeVoiceCatalogRuntime } from '@nimiplatform/kit/features/generation/runtime';
2
+ import { buildNimiRuntimeScenarioJobIdentity } from '@nimiplatform/sdk/features/generation';
3
+ import { runNimiRuntimeScenarioJob } from '@nimiplatform/sdk/runtime';
4
+ import {
5
+ ExecutionMode,
6
+ ScenarioType,
7
+ VoiceAssetStatus,
8
+ VoiceCreationSource,
9
+ } from '@nimiplatform/sdk/runtime/generated';
10
+ import type { StudioCapabilityRuntimeHandlers } from '../../ai-studio-core/runtime-dispatcher.js';
11
+ import {
12
+ createStudioScenarioJobClient,
13
+ projectStudioArtifactRunnerResult,
14
+ projectStudioRunnerNonSuccess,
15
+ type StudioCapabilityRuntimeContext,
16
+ } from '../../ai-studio-core/runtime.js';
17
+ import {
18
+ MAX_STUDIO_AUDIO_UPLOAD_BYTES,
19
+ MAX_STUDIO_VOICE_REFERENCE_AUDIO_BYTES,
20
+ type StudioSpeechSynthesizeParameters,
21
+ type StudioSpeechTranscribeParameters,
22
+ type StudioVoiceCreateParameters,
23
+ } from './parameters.js';
24
+
25
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c
26
+
27
+ // The Local App carrier derives the real subject from its protected session and
28
+ // intentionally does not project that identifier to product code. This token
29
+ // only correlates the Kit runner's request/response owner check and never
30
+ // crosses the Local App carrier.
31
+ const LOCAL_APP_OWNER_CORRELATION = 'protected-local-app-owner';
32
+
33
+ export const studioVoiceRuntimeHandlers: StudioCapabilityRuntimeHandlers = Object.freeze({
34
+ 'audio.synthesize': runSpeechSynthesize,
35
+ 'audio.transcribe': runSpeechTranscribe,
36
+ 'voice.create': runVoiceCreate,
37
+ 'speech.bundle': runSpeechBundle,
38
+ });
39
+
40
+ async function runSpeechSynthesize(context: StudioCapabilityRuntimeContext) {
41
+ if (!context.prompt) return inputRequired(context);
42
+ const parameters = context.input.parameters as StudioSpeechSynthesizeParameters | undefined;
43
+ const voiceRef = speechVoiceReference(parameters);
44
+ const result = await context.host.runners.speechSynthesize({
45
+ runtime: { ai: createStudioScenarioJobClient(context) },
46
+ appId: context.host.appId,
47
+ text: context.prompt,
48
+ ...(voiceRef ? { voiceRef } : {}),
49
+ ...(parameters?.language !== undefined ? { language: parameters.language } : {}),
50
+ ...(parameters?.audioFormat !== undefined ? { audioFormat: parameters.audioFormat } : {}),
51
+ ...(parameters?.sampleRateHz !== undefined ? { sampleRateHz: parameters.sampleRateHz } : {}),
52
+ ...(parameters?.speed !== undefined ? { speed: parameters.speed } : {}),
53
+ ...(parameters?.pitch !== undefined ? { pitch: parameters.pitch } : {}),
54
+ ...(parameters?.volume !== undefined ? { volume: parameters.volume } : {}),
55
+ ...(parameters?.emotion !== undefined ? { emotion: parameters.emotion } : {}),
56
+ ...(parameters?.timingMode !== undefined ? { timingMode: parameters.timingMode } : {}),
57
+ scenarioId: context.scenarioId,
58
+ surfaceId: context.host.surfaceId,
59
+ ...(context.input.signal ? {
60
+ signal: context.input.signal,
61
+ abortReason: context.host.abortReason,
62
+ } : {}),
63
+ });
64
+ return projectStudioArtifactRunnerResult(context, result);
65
+ }
66
+
67
+ async function runSpeechTranscribe(context: StudioCapabilityRuntimeContext) {
68
+ const parameters = context.input.parameters as StudioSpeechTranscribeParameters | undefined;
69
+ if (!context.prompt && !parameters?.audioFile) return inputRequired(context);
70
+ if (parameters?.audioFile && parameters.audioFile.sizeBytes > MAX_STUDIO_AUDIO_UPLOAD_BYTES) {
71
+ return context.host.nonSuccess(
72
+ context.capability,
73
+ 'input-invalid',
74
+ 'Speech transcription audio files must not exceed 32 MiB.',
75
+ );
76
+ }
77
+ const inferredMimeType = context.prompt ? audioMimeTypeFromUrl(context.prompt) : null;
78
+ const mimeType = parameters?.mimeType?.trim()
79
+ || parameters?.audioFile?.mimeType
80
+ || inferredMimeType;
81
+ if (!mimeType || (!parameters?.audioFile && !isHttpsUrl(context.prompt))) {
82
+ return context.host.nonSuccess(
83
+ context.capability,
84
+ 'input-invalid',
85
+ 'Speech transcription requires an HTTPS audio URL with a MIME type or a local audio file up to 32 MiB.',
86
+ );
87
+ }
88
+ const result = await context.host.runners.speechTranscribe({
89
+ runtime: { ai: createStudioScenarioJobClient(context) },
90
+ appId: context.host.appId,
91
+ ...(parameters?.audioFile ? {
92
+ audio: { type: 'bytes' as const, bytes: parameters.audioFile.bytes, mimeType },
93
+ } : { audioUrl: context.prompt, mimeType }),
94
+ ...(parameters?.language !== undefined ? { language: parameters.language } : {}),
95
+ ...(parameters?.timestamps !== undefined ? { timestamps: parameters.timestamps } : {}),
96
+ ...(parameters?.diarization !== undefined ? { diarization: parameters.diarization } : {}),
97
+ ...(parameters?.speakerCount !== undefined ? { speakerCount: parameters.speakerCount } : {}),
98
+ ...(parameters?.prompt !== undefined ? { prompt: parameters.prompt } : {}),
99
+ ...(parameters?.responseFormat !== undefined ? { responseFormat: parameters.responseFormat } : {}),
100
+ scenarioId: context.scenarioId,
101
+ surfaceId: context.host.surfaceId,
102
+ ...(context.input.signal ? {
103
+ signal: context.input.signal,
104
+ abortReason: context.host.abortReason,
105
+ } : {}),
106
+ });
107
+ if (result.ok === false) return projectStudioRunnerNonSuccess(context, result);
108
+ return {
109
+ ok: true as const,
110
+ capabilityId: context.capability.id,
111
+ capabilityLabel: context.capability.label,
112
+ message: result.message,
113
+ output: {
114
+ kind: 'transcript' as const,
115
+ text: result.output.text,
116
+ jobId: result.output.jobId,
117
+ jobState: result.output.jobStatus,
118
+ artifactCount: result.output.artifactCount,
119
+ },
120
+ ...(result.trace?.traceId ? { trace: { traceId: result.trace.traceId } } : {}),
121
+ };
122
+ }
123
+
124
+ async function runVoiceCreate(context: StudioCapabilityRuntimeContext) {
125
+ const parameters = context.input.parameters as StudioVoiceCreateParameters | undefined;
126
+ const creationSource = parameters?.creationSource ?? 'reference-audio';
127
+ if (!context.prompt && !parameters?.referenceAudioFile) return inputRequired(context);
128
+ if (creationSource === 'reference-audio') {
129
+ const audio = parameters?.referenceAudioFile;
130
+ if (!audio || audio.sizeBytes === 0
131
+ || audio.sizeBytes > MAX_STUDIO_VOICE_REFERENCE_AUDIO_BYTES
132
+ || !audio.mimeType.startsWith('audio/')) {
133
+ return context.host.nonSuccess(
134
+ context.capability,
135
+ 'input-invalid',
136
+ 'Reference-audio voice creation requires a non-empty audio file up to 20 MiB with an audio MIME type.',
137
+ );
138
+ }
139
+ }
140
+ const identity = buildNimiRuntimeScenarioJobIdentity({
141
+ appId: context.host.appId,
142
+ capabilityId: 'voice.create',
143
+ scenarioId: context.scenarioId,
144
+ });
145
+ const terminalResult = await runNimiRuntimeScenarioJob({
146
+ ai: createStudioScenarioJobClient(context),
147
+ request: {
148
+ head: undefined,
149
+ scenarioType: ScenarioType.VOICE_CREATE,
150
+ executionMode: ExecutionMode.ASYNC_JOB,
151
+ spec: {
152
+ spec: creationSource === 'reference-audio'
153
+ ? {
154
+ oneofKind: 'voiceCreate',
155
+ voiceCreate: {
156
+ targetModelId: '',
157
+ source: {
158
+ oneofKind: 'referenceAudio',
159
+ referenceAudio: {
160
+ referenceAudioBytes: parameters!.referenceAudioFile!.bytes,
161
+ referenceAudioUri: '',
162
+ referenceAudioMime: parameters!.referenceAudioFile!.mimeType,
163
+ languageHints: commaSeparatedTokens(parameters?.languageHints),
164
+ preferredName: parameters?.preferredName?.trim() ?? '',
165
+ text: context.prompt,
166
+ },
167
+ },
168
+ },
169
+ }
170
+ : {
171
+ oneofKind: 'voiceCreate',
172
+ voiceCreate: {
173
+ targetModelId: '',
174
+ source: {
175
+ oneofKind: 'textDescription',
176
+ textDescription: {
177
+ instructionText: context.prompt,
178
+ previewText: parameters?.previewText?.trim() ?? '',
179
+ language: parameters?.language?.trim() ?? '',
180
+ preferredName: parameters?.preferredName?.trim() ?? '',
181
+ },
182
+ },
183
+ },
184
+ },
185
+ },
186
+ requestId: identity.requestId,
187
+ idempotencyKey: identity.idempotencyKey,
188
+ labels: { scenarioId: context.scenarioId, surfaceId: context.host.surfaceId },
189
+ extensions: [],
190
+ },
191
+ ...(context.input.signal ? {
192
+ signal: context.input.signal,
193
+ abortReason: context.host.abortReason,
194
+ } : {}),
195
+ });
196
+ const terminalJob = terminalResult.job;
197
+ const resultAsset = terminalResult.asset;
198
+ const voiceReference = terminalResult.voiceReference;
199
+ const expectedCreationSource = creationSource === 'reference-audio'
200
+ ? VoiceCreationSource.REFERENCE_AUDIO
201
+ : VoiceCreationSource.TEXT_DESCRIPTION;
202
+ if (!resultAsset || resultAsset.status !== VoiceAssetStatus.ACTIVE
203
+ || resultAsset.creationSource !== expectedCreationSource) {
204
+ throw new Error('Completed voice.create did not return an ACTIVE VoiceAsset with the requested source.');
205
+ }
206
+ const returnedVoiceReference = voiceReference?.reference;
207
+ const returnedVoiceAssetId = returnedVoiceReference?.oneofKind === 'voiceAssetId'
208
+ ? (returnedVoiceReference as { readonly oneofKind: 'voiceAssetId'; readonly voiceAssetId: string }).voiceAssetId
209
+ : '';
210
+ if (!returnedVoiceAssetId || returnedVoiceAssetId !== resultAsset.voiceAssetId) {
211
+ throw new Error('Completed voice.create did not return an exact VoiceAsset reference.');
212
+ }
213
+ const listed = await context.host.client.ai.voiceAssets.list({ pageSize: 100 });
214
+ const listedAsset = listed.assets.find((asset) => asset.voiceAssetId === resultAsset.voiceAssetId);
215
+ if (!listedAsset || listedAsset.status !== 'active' || listedAsset.creationSource !== creationSource) {
216
+ throw new Error('Completed voice.create did not project its ACTIVE VoiceAsset through the protected owner catalog.');
217
+ }
218
+ return {
219
+ ok: true as const,
220
+ capabilityId: context.capability.id,
221
+ capabilityLabel: context.capability.label,
222
+ message: `Runtime completed voice.create (${creationSource}) and returned a reusable VoiceAsset.`,
223
+ output: {
224
+ kind: 'voice-asset' as const,
225
+ jobId: terminalJob.jobId,
226
+ jobState: 'completed',
227
+ voiceAssetId: listedAsset.voiceAssetId,
228
+ creationSource: listedAsset.creationSource,
229
+ assetStatus: listedAsset.status,
230
+ voiceReference: { kind: 'voice_asset_id' as const, voiceAssetId: resultAsset.voiceAssetId },
231
+ },
232
+ ...(terminalJob.traceId ? { trace: { traceId: terminalJob.traceId } } : {}),
233
+ };
234
+ }
235
+
236
+ async function runSpeechBundle(context: StudioCapabilityRuntimeContext) {
237
+ const result = await context.host.runners.voiceCatalog({
238
+ runtime: createLocalAppVoiceCatalogRuntime(context),
239
+ appId: context.host.appId,
240
+ subjectUserId: LOCAL_APP_OWNER_CORRELATION,
241
+ });
242
+ if (result.ok === false) return projectStudioRunnerNonSuccess(context, result);
243
+ return {
244
+ ok: true as const,
245
+ capabilityId: context.capability.id,
246
+ capabilityLabel: context.capability.label,
247
+ message: result.message,
248
+ output: {
249
+ kind: 'voice-catalog' as const,
250
+ voiceCount: result.output.voiceCount,
251
+ sample: result.output.voiceReferences.slice(0, 20).map((voice) => ({
252
+ voiceId: voice.voiceAssetId,
253
+ creationSource: VoiceCreationSource[voice.creationSource] || String(voice.creationSource),
254
+ status: VoiceAssetStatus[voice.status] || String(voice.status),
255
+ })),
256
+ },
257
+ };
258
+ }
259
+
260
+ function inputRequired(context: StudioCapabilityRuntimeContext) {
261
+ return context.host.nonSuccess(
262
+ context.capability,
263
+ 'input-invalid',
264
+ `${context.capability.label} requires non-empty input.`,
265
+ );
266
+ }
267
+
268
+ function createLocalAppVoiceCatalogRuntime(
269
+ context: StudioCapabilityRuntimeContext,
270
+ ): RuntimeVoiceCatalogRuntime {
271
+ return {
272
+ ai: {
273
+ async listVoiceAssets(request) {
274
+ const result = await context.host.client.ai.voiceAssets.list({
275
+ pageSize: request.pageSize,
276
+ pageToken: request.pageToken,
277
+ });
278
+ return {
279
+ assets: result.assets.map((asset) => ({
280
+ voiceAssetId: asset.voiceAssetId,
281
+ appId: request.appId,
282
+ subjectUserId: request.subjectUserId,
283
+ creationSource: asset.creationSource === 'text-description'
284
+ ? VoiceCreationSource.TEXT_DESCRIPTION
285
+ : VoiceCreationSource.REFERENCE_AUDIO,
286
+ provider: '',
287
+ modelId: '',
288
+ targetModelId: '',
289
+ providerVoiceRef: '',
290
+ persistence: 0,
291
+ status: localVoiceAssetStatus(asset.status),
292
+ ...(asset.createdAt ? { createdAt: asset.createdAt } : {}),
293
+ ...(asset.updatedAt ? { updatedAt: asset.updatedAt } : {}),
294
+ ...(asset.expiresAt ? { expiresAt: asset.expiresAt } : {}),
295
+ })),
296
+ nextPageToken: result.nextPageToken,
297
+ };
298
+ },
299
+ },
300
+ };
301
+ }
302
+
303
+ function localVoiceAssetStatus(status: 'active' | 'expired' | 'deleted' | 'failed'): VoiceAssetStatus {
304
+ if (status === 'active') return VoiceAssetStatus.ACTIVE;
305
+ if (status === 'expired') return VoiceAssetStatus.EXPIRED;
306
+ if (status === 'deleted') return VoiceAssetStatus.DELETED;
307
+ return VoiceAssetStatus.FAILED;
308
+ }
309
+
310
+ function speechVoiceReference(parameters: StudioSpeechSynthesizeParameters | undefined) {
311
+ if (parameters?.voiceKind === 'preset' && parameters.voicePreset?.trim()) {
312
+ return { kind: 'preset_voice_id' as const, presetVoiceId: parameters.voicePreset.trim() };
313
+ }
314
+ if (parameters?.voiceKind === 'asset' && parameters.voiceAssetId?.trim()) {
315
+ return { kind: 'voice_asset_id' as const, voiceAssetId: parameters.voiceAssetId.trim() };
316
+ }
317
+ return undefined;
318
+ }
319
+
320
+ function isHttpsUrl(value: string): boolean {
321
+ try {
322
+ return new URL(value).protocol === 'https:';
323
+ } catch {
324
+ return false;
325
+ }
326
+ }
327
+
328
+ function audioMimeTypeFromUrl(value: string): string | null {
329
+ try {
330
+ const url = new URL(value);
331
+ if (url.protocol !== 'https:') return null;
332
+ const extension = url.pathname.split('.').pop()?.toLowerCase();
333
+ if (extension === 'wav') return 'audio/wav';
334
+ if (extension === 'mp3') return 'audio/mpeg';
335
+ if (extension === 'm4a') return 'audio/mp4';
336
+ if (extension === 'ogg') return 'audio/ogg';
337
+ if (extension === 'webm') return 'audio/webm';
338
+ if (extension === 'flac') return 'audio/flac';
339
+ return null;
340
+ } catch {
341
+ return null;
342
+ }
343
+ }
344
+
345
+ function commaSeparatedTokens(value: string | undefined): string[] {
346
+ return (value ?? '').split(',').map((token) => token.trim()).filter(Boolean);
347
+ }
@@ -0,0 +1,31 @@
1
+ import { StatusBadge, Surface } from '@nimiplatform/kit/ui';
2
+
3
+ export type WorkbenchEmptyStateProps = {
4
+ readonly appTitle: string;
5
+ readonly eyebrow: string;
6
+ readonly title: string;
7
+ readonly description: string;
8
+ readonly status: string;
9
+ };
10
+
11
+ export function WorkbenchEmptyState({
12
+ appTitle,
13
+ eyebrow,
14
+ title,
15
+ description,
16
+ status,
17
+ }: WorkbenchEmptyStateProps) {
18
+ return (
19
+ <section className="workbench-empty-state" data-testid="workbench-empty-state">
20
+ <Surface className="workbench-empty-state__panel" material="glass-regular" tone="panel" elevation="raised">
21
+ <p className="workbench-empty-state__eyebrow">{eyebrow}</p>
22
+ <div className="workbench-empty-state__heading">
23
+ <h1>{appTitle}</h1>
24
+ <StatusBadge tone="neutral" shape="dot">{status}</StatusBadge>
25
+ </div>
26
+ <h2>{title}</h2>
27
+ <p className="workbench-empty-state__description">{description}</p>
28
+ </Surface>
29
+ </section>
30
+ );
31
+ }
@@ -0,0 +1,17 @@
1
+ export {
2
+ WorkbenchCore,
3
+ type WorkbenchCoreProps,
4
+ type WorkbenchNavigationGroup,
5
+ type WorkbenchNavigationIconProps,
6
+ type WorkbenchNavigationItem,
7
+ } from './workbench-core.js';
8
+ export {
9
+ WorkbenchRuntimeGate,
10
+ type WorkbenchRuntimeGateCopy,
11
+ type WorkbenchRuntimeGateProjection,
12
+ type WorkbenchRuntimeGateProps,
13
+ } from './runtime-gate.js';
14
+ export {
15
+ WorkbenchEmptyState,
16
+ type WorkbenchEmptyStateProps,
17
+ } from './empty-state.js';
@@ -0,0 +1,131 @@
1
+ import { useCallback, useEffect, useState, type ReactNode } from 'react';
2
+ import { OfflineCoordinator, type OfflineTier } from '@nimiplatform/kit/core/offline-coordinator';
3
+ import { Button, InlineAlert, StatusBadge, Surface } from '@nimiplatform/kit/ui';
4
+
5
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c
6
+
7
+ export type WorkbenchRuntimeGateProjection =
8
+ | { readonly status: 'ready' }
9
+ | {
10
+ readonly status: 'unavailable';
11
+ readonly body: string;
12
+ readonly signInRequired: boolean;
13
+ readonly nextAction?: string;
14
+ };
15
+
16
+ export type WorkbenchRuntimeGateCopy = {
17
+ readonly checking: string;
18
+ readonly setupRequired: string;
19
+ readonly signInRequired: string;
20
+ readonly connectionRequired: string;
21
+ readonly retry: string;
22
+ readonly offlineTier: (tier: OfflineTier) => string;
23
+ readonly nextAction: (action: string) => string;
24
+ };
25
+
26
+ export type WorkbenchRuntimeGateProps = {
27
+ readonly appTitle: string;
28
+ readonly copy: WorkbenchRuntimeGateCopy;
29
+ readonly resolve: () => Promise<WorkbenchRuntimeGateProjection>;
30
+ readonly clear: () => void;
31
+ readonly toErrorMessage: (error: unknown) => string;
32
+ readonly children: ReactNode;
33
+ };
34
+
35
+ type WorkbenchRuntimeGateState =
36
+ | { readonly kind: 'checking' }
37
+ | { readonly kind: 'ready' }
38
+ | {
39
+ readonly kind: 'blocked';
40
+ readonly projection: Extract<WorkbenchRuntimeGateProjection, { readonly status: 'unavailable' }>;
41
+ readonly offlineTier: OfflineTier;
42
+ };
43
+
44
+ export function WorkbenchRuntimeGate({
45
+ appTitle,
46
+ copy,
47
+ resolve,
48
+ clear,
49
+ toErrorMessage,
50
+ children,
51
+ }: WorkbenchRuntimeGateProps) {
52
+ const [offlineCoordinator] = useState(() => new OfflineCoordinator());
53
+ const [state, setState] = useState<WorkbenchRuntimeGateState>({ kind: 'checking' });
54
+ const [reloadKey, setReloadKey] = useState(0);
55
+
56
+ const retry = useCallback(() => {
57
+ clear();
58
+ setReloadKey((value) => value + 1);
59
+ }, [clear]);
60
+
61
+ useEffect(() => {
62
+ let active = true;
63
+ // A re-run triggered by a changed resolve/toErrorMessage identity (for
64
+ // example a locale switch) must not tear down the ready subtree: keep the
65
+ // current state while re-checking, and only surface the checking screen
66
+ // when no successful check has completed yet.
67
+ setState((current) => (current.kind === 'ready' ? current : { kind: 'checking' }));
68
+ void resolve().then((projection) => {
69
+ if (!active) return;
70
+ if (projection.status === 'ready') {
71
+ offlineCoordinator.markRuntimeReachability('reachable');
72
+ setState({ kind: 'ready' });
73
+ return;
74
+ }
75
+ offlineCoordinator.markRuntimeReachability('unreachable');
76
+ setState({
77
+ kind: 'blocked',
78
+ projection,
79
+ offlineTier: offlineCoordinator.getTier(),
80
+ });
81
+ }).catch((error) => {
82
+ if (!active) return;
83
+ offlineCoordinator.markRuntimeReachability('unreachable');
84
+ setState({
85
+ kind: 'blocked',
86
+ projection: {
87
+ status: 'unavailable',
88
+ body: toErrorMessage(error),
89
+ signInRequired: false,
90
+ },
91
+ offlineTier: offlineCoordinator.getTier(),
92
+ });
93
+ });
94
+ return () => {
95
+ active = false;
96
+ };
97
+ }, [offlineCoordinator, reloadKey, resolve, toErrorMessage]);
98
+
99
+ if (state.kind === 'checking') {
100
+ return (
101
+ <main className="runtime-check-screen">
102
+ <StatusBadge tone="neutral" shape="dot">{copy.checking}</StatusBadge>
103
+ </main>
104
+ );
105
+ }
106
+
107
+ if (state.kind === 'blocked') {
108
+ const { projection } = state;
109
+ return (
110
+ <main className="runtime-unavailable-screen" aria-live="polite">
111
+ <Surface className="runtime-unavailable-panel" material="glass-thick" tone="panel" elevation="floating">
112
+ <div className="runtime-unavailable-heading">
113
+ <StatusBadge tone="warning" shape="dot">{copy.setupRequired}</StatusBadge>
114
+ <h1>{appTitle}</h1>
115
+ </div>
116
+ <InlineAlert tone="warning">
117
+ <div className="runtime-alert-copy">
118
+ <strong>{projection.signInRequired ? copy.signInRequired : copy.connectionRequired}</strong>
119
+ <span>{projection.body}</span>
120
+ </div>
121
+ </InlineAlert>
122
+ <p className="runtime-action-hint">{copy.offlineTier(state.offlineTier)}</p>
123
+ {projection.nextAction ? <p className="runtime-action-hint">{copy.nextAction(projection.nextAction)}</p> : null}
124
+ <Button type="button" tone="primary" onClick={retry}>{copy.retry}</Button>
125
+ </Surface>
126
+ </main>
127
+ );
128
+ }
129
+
130
+ return <>{children}</>;
131
+ }