@nimiplatform/app-tools 0.7.5 → 0.12.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 (97) hide show
  1. package/README.md +59 -5
  2. package/bin/nimi-app.mjs +11 -3
  3. package/lib/app-access-declaration.mjs +1 -0
  4. package/lib/app-dependency-combinations.mjs +16 -28
  5. package/lib/app-doctor-update.mjs +66 -7
  6. package/lib/app-info.mjs +8 -1
  7. package/lib/app-project-lifecycle.mjs +82 -9
  8. package/lib/app-scaffold-capabilities.mjs +3 -3
  9. package/lib/app-scaffold-profiles.mjs +96 -26
  10. package/lib/app-scaffold.mjs +54 -7
  11. package/lib/canonical-capability-ids.generated.mjs +4 -0
  12. package/package.json +26 -25
  13. package/scripts/dev-shell.mjs +61 -17
  14. package/skills/nimi-app-lifecycle/references/acceptance.md +1 -1
  15. package/skills/nimi-app-lifecycle/references/adapt.md +2 -2
  16. package/skills/nimi-app-lifecycle/references/release.md +1 -1
  17. package/skills/nimi-app-lifecycle/references/upgrade-platform.md +14 -0
  18. package/templates/app-source/src/ai-studio-core/ai-config.ts +17 -3
  19. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +40 -3
  20. package/templates/app-source/src/ai-studio-core/audio-separation-request.ts +24 -0
  21. package/templates/app-source/src/ai-studio-core/contexts.tsx +4 -0
  22. package/templates/app-source/src/ai-studio-core/history-policy.ts +395 -41
  23. package/templates/app-source/src/ai-studio-core/history.ts +262 -10
  24. package/templates/app-source/src/ai-studio-core/host-context.tsx +15 -2
  25. package/templates/app-source/src/ai-studio-core/index.ts +15 -4
  26. package/templates/app-source/src/ai-studio-core/job-recovery-panel.tsx +105 -0
  27. package/templates/app-source/src/ai-studio-core/job-recovery.ts +224 -0
  28. package/templates/app-source/src/ai-studio-core/managed-result-references.ts +79 -0
  29. package/templates/app-source/src/ai-studio-core/messages/en.json +185 -10
  30. package/templates/app-source/src/ai-studio-core/messages/zh.json +185 -10
  31. package/templates/app-source/src/ai-studio-core/module-registration.ts +9 -1
  32. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +81 -2
  33. package/templates/app-source/src/ai-studio-core/parameters.ts +34 -1
  34. package/templates/app-source/src/ai-studio-core/runtime-types.ts +124 -8
  35. package/templates/app-source/src/ai-studio-core/runtime.ts +218 -20
  36. package/templates/app-source/src/ai-studio-core/section-ai-testing-annotation-result.tsx +123 -0
  37. package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +3 -0
  38. package/templates/app-source/src/ai-studio-core/section-ai-testing-audio-separation-result.tsx +26 -0
  39. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +14 -7
  40. package/templates/app-source/src/ai-studio-core/section-ai-testing-decision-result.tsx +76 -0
  41. package/templates/app-source/src/ai-studio-core/section-ai-testing-exchange-result.tsx +71 -0
  42. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +20 -4
  43. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +29 -0
  44. package/templates/app-source/src/ai-studio-core/section-ai-testing-music-result.tsx +45 -0
  45. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +132 -10
  46. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +122 -38
  47. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +4 -3
  48. package/templates/app-source/src/ai-studio-core/section-ai-testing-session-result.tsx +66 -0
  49. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +100 -22
  50. package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +6 -0
  51. package/templates/app-source/src/ai-studio-core/section-ai-testing-transcript-result.tsx +45 -0
  52. package/templates/app-source/src/ai-studio-core/section-ai-testing-transcription-result.tsx +106 -0
  53. package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +23 -4
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-voice-asset-actions.tsx +40 -0
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-voice-conversion-result.tsx +20 -0
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +219 -35
  57. package/templates/app-source/src/ai-studio-core/text-annotation-document.ts +50 -0
  58. package/templates/app-source/src/ai-studio-core/text-media-replay.ts +51 -0
  59. package/templates/app-source/src/ai-studio-core/voice-assets.ts +17 -0
  60. package/templates/app-source/src/ai-studio-core/workspace.tsx +48 -6
  61. package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +1 -1
  62. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +13 -1
  63. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +13 -1
  64. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +11 -2
  65. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +2 -2
  66. package/templates/app-source/src/studio-modules/studio-create/registration.ts +2 -2
  67. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +121 -3
  68. package/templates/app-source/src/studio-modules/studio-media/audio-separate-parameters.tsx +72 -0
  69. package/templates/app-source/src/studio-modules/studio-media/audio-separate-runtime.ts +90 -0
  70. package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +16 -1
  71. package/templates/app-source/src/studio-modules/studio-media/index.ts +2 -0
  72. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +225 -7
  73. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +225 -7
  74. package/templates/app-source/src/studio-modules/studio-media/music-parameters.tsx +85 -0
  75. package/templates/app-source/src/studio-modules/studio-media/music-transcription-parameters.tsx +85 -0
  76. package/templates/app-source/src/studio-modules/studio-media/music-transcription-runtime.ts +64 -0
  77. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +9 -26
  78. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +170 -6
  79. package/templates/app-source/src/studio-modules/studio-media/registration.ts +29 -1
  80. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +90 -6
  81. package/templates/app-source/src/studio-modules/studio-media/vision-parameters.tsx +1 -0
  82. package/templates/app-source/src/studio-modules/studio-media/vision-runtime.ts +23 -5
  83. package/templates/app-source/src/studio-modules/studio-media/voice-convert-parameters.tsx +132 -0
  84. package/templates/app-source/src/studio-modules/studio-media/voice-convert-runtime.ts +120 -0
  85. package/templates/app-source/src/studio-modules/studio-voice/audio-url.ts +25 -0
  86. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +4 -4
  87. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +4 -4
  88. package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +28 -0
  89. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +66 -30
  90. package/templates/app-source/src/workbench-core/index.ts +2 -0
  91. package/templates/app-source/src/workbench-core/runtime-gate.tsx +102 -6
  92. package/templates/app-source/src/workbench-core/workbench-core.css +42 -0
  93. package/templates/app-source/src/workbench-core/workbench-core.tsx +69 -18
  94. package/templates/app-source.manifest.json +100 -0
  95. package/templates/default-starter/README.md +2 -1
  96. package/templates/default-starter/src/shell/workbench-target-adapter.ts +102 -12
  97. package/templates/default-starter.manifest.json +0 -4
@@ -1,15 +1,25 @@
1
+ import { VoiceAssetActions } from './section-ai-testing-voice-asset-actions.js';
2
+ import { MusicGenerationNotice } from './section-ai-testing-music-result.js';
3
+ import { MusicTranscriptionNotice } from './section-ai-testing-transcription-result.js';
4
+ import { VoiceConversionNotice } from './section-ai-testing-voice-conversion-result.js';
5
+ import { AudioSeparationNotice } from './section-ai-testing-audio-separation-result.js';
6
+ import { TextAnnotationResultView } from './section-ai-testing-annotation-result.js';
7
+ import { SpeechTranscriptResultView } from './section-ai-testing-transcript-result.js';
8
+ import { TextExchangeResultView } from './section-ai-testing-exchange-result.js';
9
+ import { TextDecisionResultView } from './section-ai-testing-decision-result.js';
10
+ import { FaceSwapNotice, SessionSummaryView } from './section-ai-testing-session-result.js';
1
11
  import { useEffect, useState, type ReactNode } from 'react';
2
- import { EmptyState, IconButton, StatusBadge, Surface, Tooltip } from '@nimiplatform/kit/ui';
3
- import { AlertTriangle, ChevronRight, Clock, Copy as CopyIcon, Download as DownloadIcon, FileText, FolderOpen, Loader2, RefreshCw, Sparkles, Square } from 'lucide-react';
12
+ import { Button, EmptyState, IconButton, StatusBadge, Surface, Tooltip } from '@nimiplatform/kit/ui';
13
+ import { AlertTriangle, ChevronRight, Clock, Copy as CopyIcon, Download as DownloadIcon, FileText, FolderOpen, Loader2, RefreshCw, SlidersHorizontal, Sparkles, Square } from 'lucide-react';
4
14
  import { useAIStudioHost } from './host-context.js';
5
15
  import { VisionLocateResultView } from './section-ai-testing-vision-result.js';
6
16
  import type { StudioCapabilityRunResult } from './runtime-types.js';
7
17
  import type { StudioCapabilityDescriptor, StudioCapabilityRegistration } from './module-registration.js';
8
18
  import { formatStudioRunTimestamp } from './history.js';
9
- import { studioNonSuccessReasonUserAction, studioNonSuccessReasonUserMessage, type StudioTranslate } from './non-success-presentation.js';
19
+ import { isStoppedDirectCall, studioNonSuccessNeedsTargetReselection, studioNonSuccessReasonUserAction, studioNonSuccessReasonUserMessage, type StudioTranslate } from './non-success-presentation.js';
10
20
  import { countStudioWords } from './studio-directives.js';
11
21
  import type { CapabilityStatus } from './section-ai-testing-admission.js';
12
- import { ArtifactMediaResult, RuntimeDiagnosticsActions, formatTypedOutput, formatNonSuccessOutput, resultPlainText, TextStudioOutputBody } from './section-ai-testing-output.js';
22
+ import { ArtifactMediaPreview, ArtifactMediaResult, EmbeddingResultBody, SpeakerEmbeddingResultBody, KnownJobNotice, RuntimeDiagnosticsActions, formatTypedOutput, formatNonSuccessOutput, resultPlainText, TextStudioOutputBody } from './section-ai-testing-output.js';
13
23
 
14
24
  // Readable body for a successful typed result (light surface), with structured
15
25
  // summaries for embedding / voice-catalog rather than raw JSON (which moves to
@@ -18,13 +28,28 @@ function ReadyBody({ result }: { result: StudioCapabilityRunResult & { ok: true
18
28
  const { translate: t } = useAIStudioHost();
19
29
  const output = result.output;
20
30
  if (output.kind === 'vision-locate') return <VisionLocateResultView output={output} />;
21
- if (output.kind === 'text' || output.kind === 'transcript') {
22
- return <TextStudioOutputBody text={output.text} />;
31
+ if (output.kind === 'text') {
32
+ return <div className="studio-result__rich">
33
+ {output.sourceImage ? <ArtifactMediaPreview artifact={output.sourceImage} fallbackLabel={output.sourceImage.displayName || output.sourceImage.relativePath} /> : null}
34
+ <TextStudioOutputBody text={output.text} />
35
+ </div>;
23
36
  }
37
+ if (output.kind === 'transcript') {
38
+ return <SpeechTranscriptResultView text={output.text} transcription={output.transcription} />;
39
+ }
40
+ if (output.kind === 'text-annotation') return <TextAnnotationResultView output={output} />;
41
+ if (output.kind === 'text-exchange') return <TextExchangeResultView output={output} />;
42
+ if (output.kind === 'text-decision') return <TextDecisionResultView output={output} traceId={result.trace?.traceId} />;
43
+ if (output.kind === 'session') return <SessionSummaryView output={output} />;
24
44
  if (output.kind === 'artifacts') {
25
45
  return (
26
46
  <div className="studio-result__rich">
27
- {output.artifacts.map((artifact, index) => (
47
+ <MusicGenerationNotice value={output.musicGeneration} />
48
+ <MusicTranscriptionNotice value={output.musicTranscription} recordId={output.jobId} />
49
+ <VoiceConversionNotice value={output.voiceConversion} />
50
+ <AudioSeparationNotice value={output.audioSeparation} />
51
+ <FaceSwapNotice value={output.faceSwap} />
52
+ {output.artifacts.filter((artifact) => !output.musicTranscription && !output.voiceConversion && !output.audioSeparation && artifact.relativePath !== output.musicGeneration?.generatedScore?.relativePath).map((artifact, index) => (
28
53
  <ArtifactMediaResult
29
54
  key={artifact.relativePath}
30
55
  artifact={artifact}
@@ -34,17 +59,17 @@ function ReadyBody({ result }: { result: StudioCapabilityRunResult & { ok: true
34
59
  </div>
35
60
  );
36
61
  }
62
+ if (output.kind === 'speaker-embedding') return <SpeakerEmbeddingResultBody spaceId={output.spaceId} vector={output.vector} />;
37
63
  if (output.kind === 'embedding') {
38
- return (
39
- <div className="studio-result__rich">
40
- <p className="studio-result__plain">{t('StudioShell.embeddingSuccess')}</p>
41
- </div>
42
- );
64
+ return <EmbeddingResultBody spaceId={output.spaceId} />;
43
65
  }
44
66
  if (output.kind === 'voice-asset') {
45
67
  return (
46
68
  <div className="studio-result__rich">
47
69
  <p className="studio-result__plain">{t('StudioShell.voiceAssetSuccess')}</p>
70
+ {output.preview ? <ArtifactMediaResult artifact={output.preview} fallbackLabel={output.jobId} /> : null}
71
+ {output.expiresAt ? <p>{t('StudioShell.voiceExpiry', { date: new Date(output.expiresAt).toLocaleString() })}</p> : null}
72
+ <VoiceAssetActions key={output.voiceAssetId} voiceAssetId={output.voiceAssetId} />
48
73
  </div>
49
74
  );
50
75
  }
@@ -188,6 +213,7 @@ export function StudioResult({
188
213
  onDownload,
189
214
  onRegenerate,
190
215
  onCancel,
216
+ onOpenIntentConfig,
191
217
  }: {
192
218
  result: StudioCapabilityRunResult | null;
193
219
  running: boolean;
@@ -205,6 +231,7 @@ export function StudioResult({
205
231
  onDownload: () => void;
206
232
  onRegenerate: () => void;
207
233
  onCancel?: () => void;
234
+ onOpenIntentConfig?: () => void;
208
235
  }) {
209
236
  const rendererHost = useAIStudioHost();
210
237
  const t = rendererHost.translate;
@@ -212,6 +239,7 @@ export function StudioResult({
212
239
  const profile = registration.profile;
213
240
  const ready = result?.ok ? result : null;
214
241
  const operationAborted = result && !result.ok && result.reason === 'operation-aborted' ? result : null;
242
+ const stoppedDirectCall = Boolean(operationAborted && isStoppedDirectCall(operationAborted.reason, capability.id));
215
243
  const canceled = result && !result.ok && result.reason === 'runtime-canceled' ? result : null;
216
244
  const timedOut = result && !result.ok && result.reason === 'runtime-timeout' ? result : null;
217
245
  const blocked = result && !result.ok
@@ -220,14 +248,14 @@ export function StudioResult({
220
248
  && result.reason !== 'runtime-timeout' ? result : null;
221
249
  const plainText = ready ? resultPlainText(ready, t) : '';
222
250
  const canExport = Boolean(ready && plainText);
223
- const revealsManagedAsset = ready?.output.kind === 'artifacts';
251
+ const revealsManagedAsset = ready?.output.kind === 'artifacts' || ready?.output.kind === 'text-annotation';
224
252
  const displayIntentLabel = studioResultIntentLabel(result, capability, intentLabel, t);
225
253
  const [requestSettingsOpen, setRequestSettingsOpen] = useState(false);
226
254
  const hasRequestSettings = Boolean(requestSettings);
227
255
  const runTimeLabel = createdAt
228
256
  ? formatStudioRunTimestamp(createdAt, new Date(rendererHost.clock.now()))
229
257
  : running ? t('Studio.result.statRunning') : t('Studio.result.notRecorded');
230
- const statusTitleKey = cancelRequested ? 'stopping' : running ? 'runtimeRunning' : operationAborted ? 'operationAborted' : canceled ? 'runtimeCanceled' : timedOut ? 'runtimeTimedOut' : blocked ? 'runtimeBlocked' : ready ? 'runtimeResult' : 'runtimeWaiting';
258
+ const statusTitleKey = cancelRequested ? 'stopping' : running ? 'runtimeRunning' : operationAborted ? (stoppedDirectCall ? 'stoppedDirectCall' : 'operationAborted') : canceled ? 'runtimeCanceled' : timedOut ? 'runtimeTimedOut' : blocked ? 'runtimeBlocked' : ready ? 'runtimeResult' : 'runtimeWaiting';
231
259
  const statusTitle = t(`Studio.result.status.${statusTitleKey}`);
232
260
  const statusTone = blocked || operationAborted || canceled || timedOut ? 'warning' : ready ? 'success' : running ? 'info' : 'neutral';
233
261
  useEffect(() => {
@@ -246,7 +274,7 @@ export function StudioResult({
246
274
  if (!result.ok) return [{
247
275
  label: t('Studio.result.statStatus'),
248
276
  value: t(result.reason === 'operation-aborted'
249
- ? 'Studio.result.statStopped'
277
+ ? (isStoppedDirectCall(result.reason, capability.id) ? 'Studio.result.statStoppedDirect' : 'Studio.result.statStopped')
250
278
  : result.reason === 'runtime-canceled'
251
279
  ? 'Studio.result.statCanceled'
252
280
  : result.reason === 'runtime-timeout'
@@ -264,16 +292,42 @@ export function StudioResult({
264
292
  if (output.kind === 'transcript') {
265
293
  return [
266
294
  { label: t('Studio.result.statCharacters'), value: String(output.text.length) },
295
+ ...(output.transcription?.words.length ? [{ label: t('StudioResults.transcript.words'), value: String(output.transcription.words.length) }] : []),
267
296
  { label: t('Studio.result.statArtifacts'), value: String(output.artifactCount) },
268
297
  ];
269
298
  }
270
299
  if (output.kind === 'embedding') {
271
- return [{ label: t('Studio.result.statResult'), value: t('Studio.result.statCreated') }];
300
+ return [
301
+ { label: t('Studio.result.statResult'), value: t('Studio.result.statCreated') },
302
+ ...(output.totalTokens !== undefined ? [{ label: t('Studio.result.statTokens'), value: String(output.totalTokens) }] : []),
303
+ ];
304
+ }
305
+ if (output.kind === 'text-annotation') {
306
+ return [
307
+ { label: t('StudioResults.stats.documents'), value: String(output.documentCount) },
308
+ { label: t('StudioResults.stats.tokens'), value: String(output.tokenCount) },
309
+ { label: t('StudioResults.stats.sentences'), value: String(output.sentenceCount) },
310
+ ];
311
+ }
312
+ if (output.kind === 'text-exchange') {
313
+ return [
314
+ { label: t('StudioResults.stats.steps'), value: String(output.steps.length) },
315
+ { label: t('Studio.result.statCharacters'), value: String(output.text.length) },
316
+ ];
317
+ }
318
+ if (output.kind === 'text-decision') {
319
+ return [{ label: t('StudioResults.stats.questions'), value: String(output.answers.length) }];
320
+ }
321
+ if (output.kind === 'session') {
322
+ return [{
323
+ label: t('Studio.result.statState'),
324
+ value: t(output.ending === 'closed' ? 'StudioResults.session.stateClosed' : 'StudioResults.session.stateTerminated'),
325
+ }];
272
326
  }
273
327
  if (output.kind === 'artifacts') {
274
328
  return [
275
329
  { label: t('Studio.result.statArtifacts'), value: String(output.artifactCount) },
276
- { label: t('Studio.result.statState'), value: output.jobState === 'COMPLETED' ? t('Studio.result.statCompleted') : output.jobState || t('Studio.result.stateUnknown') },
330
+ { label: t('Studio.result.statState'), value: output.jobState.toUpperCase() === 'COMPLETED' ? t('Studio.result.statCompleted') : output.jobState || t('Studio.result.stateUnknown') },
277
331
  ];
278
332
  }
279
333
  if (output.kind === 'voice-asset') {
@@ -282,6 +336,7 @@ export function StudioResult({
282
336
  { label: t('Studio.result.statResult'), value: t(output.creationSource === 'text-description' ? 'Studio.result.createdFromDescription' : 'Studio.result.createdFromAudio') },
283
337
  ];
284
338
  }
339
+ if (output.kind === 'speaker-embedding') return [{ label: t('Studio.result.statResult'), value: String(output.vector.length) }];
285
340
  if (output.kind === 'vision-locate') return [{ label: t('VisionLocate.matches'), value: String(output.result.locations.length) }];
286
341
  return [
287
342
  { label: t('Studio.result.statVoices'), value: String(output.voiceCount) },
@@ -292,10 +347,14 @@ export function StudioResult({
292
347
  let metric = '-';
293
348
  if (ready) {
294
349
  const output = ready.output;
295
- if (output.kind === 'text' || output.kind === 'transcript') metric = t('Studio.result.metricWords', { count: countStudioWords(output.text) });
350
+ if (output.kind === 'text' || output.kind === 'transcript' || output.kind === 'text-exchange') metric = t('Studio.result.metricWords', { count: countStudioWords(output.text) });
351
+ else if (output.kind === 'text-annotation') metric = String(output.tokenCount);
352
+ else if (output.kind === 'text-decision') metric = String(output.answers.length);
353
+ else if (output.kind === 'session') metric = output.terminalReason;
296
354
  else if (output.kind === 'artifacts') metric = t('Studio.result.metricArtifacts', { count: output.artifactCount });
297
355
  else if (output.kind === 'embedding') metric = t('Studio.result.metricCreated');
298
356
  else if (output.kind === 'voice-asset') metric = output.creationSource;
357
+ else if (output.kind === 'speaker-embedding') metric = String(output.vector.length);
299
358
  else if (output.kind === 'vision-locate') metric = String(output.result.locations.length);
300
359
  else metric = t('Studio.result.metricVoices', { count: output.voiceCount });
301
360
  }
@@ -310,6 +369,9 @@ export function StudioResult({
310
369
  <Loader2 size={15} aria-hidden="true" className="studio-spin" />
311
370
  <span>{cancelRequested
312
371
  ? t('Studio.result.pendingCancel')
372
+ : capability.id === 'music.transcribe' ? t('Transcription.running')
373
+ : capability.id === 'audio.voice.convert' ? t('VoiceConvert.running')
374
+ : capability.id === 'audio.separate' ? t('AudioSeparate.running')
313
375
  : capability.id === 'vision.locate' && jobStatus ? t(`VisionLocate.${jobStatus}`)
314
376
  : profile.pendingLabelKey
315
377
  ? t(profile.pendingLabelKey)
@@ -325,8 +387,9 @@ export function StudioResult({
325
387
  <Clock size={15} aria-hidden="true" />
326
388
  <span>{statusTitle}</span>
327
389
  </div>
328
- <p>{studioNonSuccessReasonUserMessage(operationAborted.reason, t)}</p>
329
- <p className="studio-result__hint">{studioNonSuccessReasonUserAction(operationAborted.reason, t)}</p>
390
+ <p>{studioNonSuccessReasonUserMessage(operationAborted.reason, t, capability.id)}</p>
391
+ <p className="studio-result__hint">{studioNonSuccessReasonUserAction(operationAborted.reason, t, capability.id)}</p>
392
+ <KnownJobNotice jobId={operationAborted.jobId} />
330
393
  </div>
331
394
  );
332
395
  } else if (canceled) {
@@ -338,6 +401,7 @@ export function StudioResult({
338
401
  </div>
339
402
  <p>{studioNonSuccessReasonUserMessage(canceled.reason, t)}</p>
340
403
  <p className="studio-result__hint">{studioNonSuccessReasonUserAction(canceled.reason, t)}</p>
404
+ <KnownJobNotice jobId={canceled.jobId} />
341
405
  </div>
342
406
  );
343
407
  } else if (timedOut) {
@@ -349,6 +413,7 @@ export function StudioResult({
349
413
  </div>
350
414
  <p>{studioNonSuccessReasonUserMessage(timedOut.reason, t)}</p>
351
415
  <p className="studio-result__hint">{studioNonSuccessReasonUserAction(timedOut.reason, t)}</p>
416
+ <KnownJobNotice jobId={timedOut.jobId} />
352
417
  </div>
353
418
  );
354
419
  } else if (blocked) {
@@ -358,8 +423,21 @@ export function StudioResult({
358
423
  <AlertTriangle size={15} aria-hidden="true" />
359
424
  <span>{t('StudioShell.generationFailed')}</span>
360
425
  </div>
361
- <p>{studioNonSuccessReasonUserMessage(blocked.reason, t, blocked.capabilityId, blocked.diagnostics)}</p>
426
+ <p>{studioNonSuccessReasonUserMessage(blocked.reason, t, blocked.capabilityId, blocked.diagnostics, blocked.message)}</p>
362
427
  <p className="studio-result__hint">{studioNonSuccessReasonUserAction(blocked.reason, t, blocked.capabilityId, blocked.diagnostics)}</p>
428
+ {onOpenIntentConfig && studioNonSuccessNeedsTargetReselection(blocked.diagnostics) ? (
429
+ <Button
430
+ type="button"
431
+ tone="secondary"
432
+ size="sm"
433
+ className="studio-result__reselect"
434
+ leadingIcon={<SlidersHorizontal size={15} aria-hidden="true" />}
435
+ onClick={onOpenIntentConfig}
436
+ >
437
+ {t('NonSuccess.openAIConfig')}
438
+ </Button>
439
+ ) : null}
440
+ <KnownJobNotice jobId={blocked.jobId} />
363
441
  </div>
364
442
  );
365
443
  } else if (ready) {
@@ -419,7 +497,7 @@ export function StudioResult({
419
497
  <div className="studio-result__meta">
420
498
  <StatusBadge tone={statusTone} shape="soft" className="min-h-[30px] shrink-0 gap-[7px] px-3 text-sm font-[var(--nimi-type-page-title-weight)]">
421
499
  <Sparkles size={14} aria-hidden="true" />
422
- <span>{t('Studio.result.runtimeChip')}</span>
500
+ <span>{t(capability.id === 'music.transcribe' ? 'Transcription.estimateLabel' : 'Studio.result.runtimeChip')}</span>
423
501
  </StatusBadge>
424
502
  <div className="studio-result__stats studio-result__stats--top" aria-label={t('Studio.result.generationMetrics')}>
425
503
  {stats.map((stat) => (
@@ -22,6 +22,12 @@ export { StudioResult } from './section-ai-testing-studio-result.js';
22
22
  export type StudioAIConfigPanelRenderInput = {
23
23
  readonly runtime: StudioRuntimeInspection | null;
24
24
  readonly capabilityId: string;
25
+ /**
26
+ * The panel calls this once Runtime reports its AIConfig write committed.
27
+ * Closing the drawer does not wait for a write, so a commit can land after
28
+ * the close; this still re-reads every mounted consumer.
29
+ */
30
+ readonly onCommitted: () => void;
25
31
  };
26
32
 
27
33
  export type SectionAITestingProps = {
@@ -0,0 +1,45 @@
1
+ import type { NimiLocalAppSpeechTranscript } from '@nimiplatform/sdk/app';
2
+ import { Button } from '@nimiplatform/kit/ui';
3
+ import { useAIStudioHost } from './host-context.js';
4
+ import { downloadTextFile, TextStudioOutputBody } from './section-ai-testing-output.js';
5
+
6
+ const MAX_VISIBLE_WORDS = 400;
7
+
8
+ export function SpeechTranscriptResultView({
9
+ text,
10
+ transcription,
11
+ }: {
12
+ readonly text: string;
13
+ readonly transcription?: NimiLocalAppSpeechTranscript;
14
+ }) {
15
+ const host = useAIStudioHost();
16
+ const { translate: t } = host;
17
+ const words = transcription?.words ?? [];
18
+ const visibleWords = words.slice(0, MAX_VISIBLE_WORDS);
19
+ return (
20
+ <section className="studio-result__rich" aria-label={t('StudioResults.transcript.title')}>
21
+ <TextStudioOutputBody text={text} />
22
+ {transcription ? (
23
+ <Button size="sm" tone="secondary" onClick={() => void downloadTextFile(
24
+ host, 'speech-transcript.json', JSON.stringify(transcription, null, 2),
25
+ )}>
26
+ {t('StudioResults.transcript.exportComplete')}
27
+ </Button>
28
+ ) : null}
29
+ {transcription?.language ? <p className="studio-result__hint">{t('StudioResults.transcript.detectedLanguage', { language: transcription.language })}</p> : null}
30
+ {words.length > 0 ? (
31
+ <details className="studio-annotation" open>
32
+ <summary>{t('StudioResults.transcript.wordTimes', { count: words.length })}</summary>
33
+ <p className="studio-result__hint">{t('StudioResults.transcript.timeHint')}</p>
34
+ <table className="studio-annotation__tokens">
35
+ <thead><tr><th>#</th><th>{t('StudioResults.transcript.word')}</th><th>{t('StudioResults.transcript.start')}</th><th>{t('StudioResults.transcript.end')}</th></tr></thead>
36
+ <tbody>{visibleWords.map((word, index) => (
37
+ <tr key={`${index}:${word.startSeconds}`}><td>{index + 1}</td><td>{word.text}</td><td>{word.startSeconds.toFixed(3)}</td><td>{word.endSeconds.toFixed(3)}</td></tr>
38
+ ))}</tbody>
39
+ </table>
40
+ {visibleWords.length < words.length ? <p className="studio-result__hint">{t('StudioResults.transcript.truncatedView', { shown: visibleWords.length, total: words.length })}</p> : null}
41
+ </details>
42
+ ) : null}
43
+ </section>
44
+ );
45
+ }
@@ -0,0 +1,106 @@
1
+ import { useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import { Button, TextareaField } from '@nimiplatform/kit/ui';
3
+ import { useAIStudioHost } from './host-context.js';
4
+ import { ArtifactMediaResult } from './section-ai-testing-output.js';
5
+ import type { StudioMusicTranscription } from './runtime-types.js';
6
+
7
+ export function MusicTranscriptionNotice({ value, recordId }: { readonly value?: StudioMusicTranscription; readonly recordId: string }) {
8
+ const host = useAIStudioHost(); const { translate: t } = host;
9
+ const recordKey = value ? JSON.stringify([recordId, value.sourceAudio.relativePath, value.sourceAudio.sha256,
10
+ value.inputRange, value.scores, value.timelineRelativePath]) : '';
11
+ const [selection, setSelection] = useState<{ recordKey: string; path: string } | null>(null);
12
+ const selected = selection?.recordKey === recordKey ? selection.path : '';
13
+ const sourceKey = JSON.stringify([recordKey, selected]);
14
+ type Loaded = { sourceKey: string; path: string; bytes: Uint8Array; body: string; filename: string; mediaType: string; midi: boolean };
15
+ const [loaded, setLoaded] = useState<Loaded | null>(null);
16
+ const [feedback, setFeedback] = useState<{ sourceKey: string; error?: string; exportedPath?: string } | null>(null);
17
+ const [exporting, setExporting] = useState('');
18
+ const currentSource = useRef(sourceKey);
19
+ useLayoutEffect(() => { currentSource.current = sourceKey; }, [sourceKey]);
20
+ const scores = value?.scores;
21
+ const timelinePath = value?.timelineRelativePath;
22
+ // Render and actions gate on provenance before passive effects can run.
23
+ const file = loaded?.sourceKey === sourceKey ? loaded : null;
24
+ const body = file?.body ?? '';
25
+ const error = feedback?.sourceKey === sourceKey ? feedback.error : '';
26
+ const exportedPath = feedback?.sourceKey === sourceKey ? feedback.exportedPath : '';
27
+ useEffect(() => {
28
+ if (!selected) return;
29
+ let active = true;
30
+ const timeline = selected === timelinePath;
31
+ const score = scores?.find(item => item.relativePath === selected);
32
+ if (!timeline && !score) return;
33
+ const midi = score?.format === 'midi';
34
+ const mediaType = timeline ? 'application/vnd.nimi.music-timeline+json' : midi ? 'audio/midi' : 'text/vnd.abc';
35
+ const filename = timeline ? 'music-timeline.json' : midi ? 'estimated-notes.mid' : 'transcribed-score.abc';
36
+ void (async () => {
37
+ const read = await host.sdk.assets.read({ relativePath: selected });
38
+ const iterator = read.body[Symbol.asyncIterator]();
39
+ const limit = timeline || midi ? 16777216 : 1048576;
40
+ try {
41
+ if (read.asset.mediaType !== mediaType || read.asset.sizeBytes < 1 || read.asset.sizeBytes > limit) throw new Error(t('Music.scoreTooLarge'));
42
+ const bytes = new Uint8Array(read.asset.sizeBytes); let offset = 0;
43
+ for await (const chunk of { [Symbol.asyncIterator]: () => iterator }) {
44
+ if (offset + chunk.length > bytes.length) throw new Error(t('Music.scoreTooLarge'));
45
+ bytes.set(chunk, offset); offset += chunk.length;
46
+ }
47
+ if (offset !== bytes.length) throw new Error(t('Music.scoreIncomplete'));
48
+ const body = midi ? '' : new TextDecoder('utf-8', { fatal: true }).decode(bytes);
49
+ if (active) setLoaded({ sourceKey, path: selected, bytes, body, filename, mediaType, midi });
50
+ } finally { await iterator.return?.(); }
51
+ })().catch((cause: unknown) => { if (active) setFeedback({ sourceKey, error: String(cause) }); });
52
+ return () => { active = false; };
53
+ }, [sourceKey, selected, timelinePath, scores, host, t]);
54
+ async function exportSelected() {
55
+ const snapshot = file;
56
+ if (!snapshot || snapshot.sourceKey !== currentSource.current || exporting === snapshot.sourceKey) return;
57
+ setExporting(snapshot.sourceKey);
58
+ const bytes = snapshot.bytes;
59
+ async function* chunks() { yield bytes; }
60
+ try {
61
+ const saved = await host.sdk.assets.write({ relativePath: `studio/music/exports/${crypto.randomUUID()}/${snapshot.filename}`,
62
+ body: chunks(), mediaType: snapshot.mediaType, overwrite: false });
63
+ setFeedback({ sourceKey: snapshot.sourceKey, exportedPath: saved.relativePath });
64
+ try { await host.sdk.assets.reveal(saved.relativePath); }
65
+ catch {
66
+ setFeedback({ sourceKey: snapshot.sourceKey, exportedPath: saved.relativePath,
67
+ error: t('Common.exportSavedRevealFailed', { path: saved.relativePath }) });
68
+ }
69
+ } catch { setFeedback({ sourceKey: snapshot.sourceKey, error: t('Common.exportFailed') }); }
70
+ finally { setExporting(previous => previous === snapshot.sourceKey ? '' : previous); }
71
+ }
72
+ function choose(path: string) {
73
+ setSelection({ recordKey, path: selected === path ? '' : path });
74
+ }
75
+ async function revealSelected() {
76
+ const snapshot = file;
77
+ if (!snapshot || snapshot.sourceKey !== currentSource.current) return;
78
+ try { await host.sdk.assets.reveal(snapshot.path); }
79
+ catch { setFeedback({ sourceKey: snapshot.sourceKey, error: t('Common.assetRevealFailed', { path: snapshot.path }) }); }
80
+ }
81
+ if (!value) return null;
82
+ return <section className="space-y-3" aria-label={t('Transcription.result')}>
83
+ <p>{t('Transcription.estimate')}</p>
84
+ <p>{t(`Transcription.completeness.${value.completeness}`)}</p>
85
+ <p>{t('Transcription.range', { start: (value.inputRange.startFrame / value.sourceInfo.sampleRateHz).toFixed(3),
86
+ end: (value.inputRange.endFrame / value.sourceInfo.sampleRateHz).toFixed(3), hz: value.sourceInfo.sampleRateHz })}</p>
87
+ <ArtifactMediaResult artifact={value.sourceAudio} fallbackLabel={t('Transcription.source')} />
88
+ <div className="flex flex-wrap gap-2">
89
+ {value.scores.map(score => <Button key={score.relativePath} onClick={() => {
90
+ choose(score.relativePath);
91
+ }}>{t(`Transcription.parts.${score.part}`)} · {score.format.toUpperCase()}</Button>)}
92
+ {timelinePath ? <Button onClick={() => choose(timelinePath)}>{t('Transcription.timeline')}</Button> : null}
93
+ </div>
94
+ {file?.midi ? <div className="space-y-2">
95
+ <p>{t('Transcription.midiTimeBasis', { start: (value.inputRange.startFrame / value.sourceInfo.sampleRateHz).toFixed(3) })}</p>
96
+ <Button disabled={exporting === sourceKey} onClick={() => void exportSelected()}>{t('Transcription.exportMidi')}</Button>
97
+ <Button onClick={() => void revealSelected()}>{t('Transcription.showFile')}</Button>
98
+ </div> : null}
99
+ {body ? <>
100
+ <TextareaField value={body} readOnly textareaClassName="min-h-48 max-h-96 font-mono" aria-label={t('Transcription.result')} />
101
+ <Button disabled={exporting === sourceKey} onClick={() => void exportSelected()}>{t('Transcription.export')}</Button>
102
+ </> : null}
103
+ {exportedPath ? <p>{t('Transcription.exported', { path: exportedPath })}</p> : null}
104
+ {error ? <p role="alert">{error}</p> : null}
105
+ </section>;
106
+ }
@@ -1,14 +1,33 @@
1
- import { useState } from 'react';
1
+ import { useEffect, useState } from 'react';
2
+ import { openNimiLocalAppAssetMediaUrl } from '@nimiplatform/kit/shell/renderer/bridge';
2
3
  import type { StudioTypedOutput } from './runtime-types.js';
3
4
  import { useAIStudioHost } from './host-context.js';
4
5
 
5
6
  export function VisionLocateResultView({ output }: { output: Extract<StudioTypedOutput, {kind:'vision-locate'}> }) {
6
- const { translate: t } = useAIStudioHost();
7
+ const host = useAIStudioHost();
8
+ const { translate: t } = host;
7
9
  const [imageFailed, setImageFailed] = useState(false);
10
+ const [retained, setRetained] = useState<{ readonly sourceKey: string; readonly url: string } | null>(null);
11
+ const source = output.sourceImage;
12
+ const sourceKey = source ? JSON.stringify([source.relativePath, source.sha256, source.sizeBytes, source.mediaType]) : '';
13
+ useEffect(() => {
14
+ setRetained(null); setImageFailed(false);
15
+ if (!source) return undefined;
16
+ let active = true; let revoke: (() => Promise<void>) | undefined;
17
+ void (async () => {
18
+ const stat = await host.sdk.assets.stat(source.relativePath);
19
+ if (stat.sha256 !== source.sha256 || stat.sizeBytes !== source.sizeBytes || stat.mediaType !== source.mediaType) throw new Error('Saved source image changed');
20
+ const handle = await openNimiLocalAppAssetMediaUrl(source.relativePath);
21
+ revoke = handle.revoke;
22
+ if (active) setRetained({ sourceKey, url: handle.url }); else await handle.revoke();
23
+ })().catch(() => { if (active) setImageFailed(true); });
24
+ return () => { active = false; if (revoke) void revoke(); };
25
+ }, [source, sourceKey, host]);
26
+ const imageUrl = source ? retained?.sourceKey === sourceKey ? retained.url : null : output.imagePreviewUrl;
8
27
  const { width, height, locations, imageArtifactId } = output.result;
9
28
  return <figure className="studio-locate-result">
10
- {output.imagePreviewUrl && !imageFailed ? <div className="studio-locate-result__image" style={{ aspectRatio: `${width} / ${height}` }}>
11
- <img src={output.imagePreviewUrl} alt={t('VisionLocate.sourceImage')} onError={() => setImageFailed(true)} />
29
+ {imageUrl && !imageFailed ? <div className="studio-locate-result__image" style={{ aspectRatio: `${width} / ${height}` }}>
30
+ <img src={imageUrl} alt={t('VisionLocate.sourceImage')} onError={() => setImageFailed(true)} />
12
31
  <svg viewBox={`0 0 ${width} ${height}`} role="img" aria-label={t('VisionLocate.overlay')}>
13
32
  {locations.map((location, index) => <g key={index}>
14
33
  <title>{location.label || t('VisionLocate.target', { index: index+1 })}</title>
@@ -0,0 +1,40 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { Button, ConfirmDialog } from '@nimiplatform/kit/ui';
3
+ import { useAIStudioHost } from './host-context.js';
4
+
5
+ export function VoiceAssetActions({ voiceAssetId }: { readonly voiceAssetId: string }) {
6
+ const { sdk, translate: t } = useAIStudioHost();
7
+ const [status, setStatus] = useState('loading');
8
+ const [confirm, setConfirm] = useState(false);
9
+ const [busy, setBusy] = useState(false);
10
+ const [error, setError] = useState('');
11
+ useEffect(() => {
12
+ let current = true;
13
+ void sdk.listLocalAppVoiceAssets().then((assets) => {
14
+ if (current) setStatus(assets.find((asset) => asset.voiceAssetId === voiceAssetId)?.status ?? 'unavailable');
15
+ }, () => { if (current) setStatus('unavailable'); });
16
+ return () => { current = false; };
17
+ }, [sdk, voiceAssetId]);
18
+ async function remove() {
19
+ setBusy(true);
20
+ setError('');
21
+ try {
22
+ await sdk.deleteLocalAppVoiceAsset(voiceAssetId);
23
+ setStatus('deleted');
24
+ setConfirm(false);
25
+ } catch {
26
+ setError(t('StudioShell.voiceDeleteFailed'));
27
+ } finally {
28
+ setBusy(false);
29
+ }
30
+ }
31
+ return <div className="studio-result__rich">
32
+ {status === 'deleted' ? <p role="status">{t('StudioShell.voiceDeleted')}</p> :
33
+ <Button tone="danger" disabled={status !== 'active'} onClick={() => setConfirm(true)}>{t('StudioShell.voiceDelete')}</Button>}
34
+ {status === 'unavailable' ? <p>{t('StudioShell.voiceUnavailable')}</p> : null}
35
+ <ConfirmDialog open={confirm} title={t('StudioShell.voiceDeleteTitle')}
36
+ message={<>{t('StudioShell.voiceDeleteDescription')}{error ? <p role="alert">{error}</p> : null}</>}
37
+ confirmLabel={t('StudioShell.voiceDelete')} cancelLabel={t('StudioShell.voiceDeleteCancel')}
38
+ loading={busy} onConfirm={() => { void remove(); }} onClose={() => setConfirm(false)} />
39
+ </div>;
40
+ }
@@ -0,0 +1,20 @@
1
+ import { useAIStudioHost } from './host-context.js';
2
+ import { ArtifactMediaResult } from './section-ai-testing-output.js';
3
+ import type { StudioVoiceConversion } from './runtime-types.js';
4
+
5
+ export function VoiceConversionNotice({ value }: { readonly value?: StudioVoiceConversion }) {
6
+ const host = useAIStudioHost(); const { translate: t } = host;
7
+ if (!value) return null;
8
+ const delta = value.durationDeltaMs;
9
+ return <section className="space-y-3" aria-label={t('VoiceConvert.result')}>
10
+ <p>{t('VoiceConvert.lengthRelation', { relation: t(`VoiceConvert.length.${value.lengthRelation}`), delta: `${delta > 0 ? '+' : ''}${delta}` })}</p>
11
+ <p>{t('VoiceConvert.sourceFacts', { hz: value.sourceInfo.sampleRateHz, channels: value.sourceInfo.channels, durationMs: value.sourceInfo.durationMs })}</p>
12
+ <p>{t('VoiceConvert.vocalFacts', { hz: value.vocalInfo.sampleRateHz, channels: value.vocalInfo.channels, durationMs: value.vocalInfo.durationMs })}</p>
13
+ <p>{t('VoiceConvert.range', { start: (value.inputRange.startFrame / value.sourceInfo.sampleRateHz).toFixed(3),
14
+ end: (value.inputRange.endFrame / value.sourceInfo.sampleRateHz).toFixed(3), hz: value.sourceInfo.sampleRateHz })}</p>
15
+ <p className="text-sm opacity-70">{t('VoiceConvert.derivation')}</p>
16
+ <ArtifactMediaResult artifact={value.sourceVocal} fallbackLabel={t('VoiceConvert.source')} />
17
+ {value.targetVoice ? <ArtifactMediaResult artifact={value.targetVoice} fallbackLabel={t('VoiceConvert.target')} /> : null}
18
+ <ArtifactMediaResult artifact={value.vocal} fallbackLabel={t('VoiceConvert.result')} />
19
+ </section>;
20
+ }