@nimiplatform/app-tools 0.6.3 → 0.11.4

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 (115) hide show
  1. package/README.md +153 -12
  2. package/bin/nimi-app.mjs +16 -14
  3. package/lib/app-access-declaration.mjs +1 -0
  4. package/lib/app-dependency-combinations.mjs +49 -0
  5. package/lib/app-doctor-update.mjs +84 -23
  6. package/lib/app-info.mjs +33 -3
  7. package/lib/app-lifecycle-guidance.mjs +4 -2
  8. package/lib/app-pack.mjs +5 -2
  9. package/lib/app-project-lifecycle.mjs +284 -53
  10. package/lib/app-safety-profile.mjs +204 -0
  11. package/lib/app-scaffold-capabilities.mjs +11 -3
  12. package/lib/app-scaffold-profiles.mjs +136 -27
  13. package/lib/app-scaffold.mjs +55 -7
  14. package/lib/canonical-capability-ids.generated.mjs +25 -0
  15. package/lib/index.mjs +0 -4
  16. package/package.json +27 -31
  17. package/scripts/dev-shell.mjs +80 -18
  18. package/skills/nimi-app-lifecycle/SKILL.md +7 -3
  19. package/skills/nimi-app-lifecycle/references/acceptance.md +7 -1
  20. package/skills/nimi-app-lifecycle/references/adapt.md +46 -1
  21. package/skills/nimi-app-lifecycle/references/audit.md +55 -0
  22. package/skills/nimi-app-lifecycle/references/platform-gaps.md +15 -0
  23. package/skills/nimi-app-lifecycle/references/release.md +2 -2
  24. package/skills/nimi-app-lifecycle/references/safety-declaration.md +37 -0
  25. package/skills/nimi-app-lifecycle/references/upgrade-platform.md +16 -2
  26. package/templates/app-source/src/ai-studio-core/ai-config.ts +17 -3
  27. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +40 -3
  28. package/templates/app-source/src/ai-studio-core/audio-separation-request.ts +24 -0
  29. package/templates/app-source/src/ai-studio-core/contexts.tsx +4 -0
  30. package/templates/app-source/src/ai-studio-core/history-policy.ts +395 -41
  31. package/templates/app-source/src/ai-studio-core/history.ts +262 -10
  32. package/templates/app-source/src/ai-studio-core/host-context.tsx +15 -2
  33. package/templates/app-source/src/ai-studio-core/index.ts +15 -4
  34. package/templates/app-source/src/ai-studio-core/job-recovery-panel.tsx +105 -0
  35. package/templates/app-source/src/ai-studio-core/job-recovery.ts +224 -0
  36. package/templates/app-source/src/ai-studio-core/managed-result-references.ts +79 -0
  37. package/templates/app-source/src/ai-studio-core/messages/en.json +185 -10
  38. package/templates/app-source/src/ai-studio-core/messages/zh.json +185 -10
  39. package/templates/app-source/src/ai-studio-core/module-registration.ts +9 -1
  40. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +81 -2
  41. package/templates/app-source/src/ai-studio-core/parameters.ts +34 -1
  42. package/templates/app-source/src/ai-studio-core/runtime-types.ts +124 -8
  43. package/templates/app-source/src/ai-studio-core/runtime.ts +218 -20
  44. package/templates/app-source/src/ai-studio-core/section-ai-testing-annotation-result.tsx +123 -0
  45. package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +3 -0
  46. package/templates/app-source/src/ai-studio-core/section-ai-testing-audio-separation-result.tsx +26 -0
  47. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +14 -7
  48. package/templates/app-source/src/ai-studio-core/section-ai-testing-decision-result.tsx +76 -0
  49. package/templates/app-source/src/ai-studio-core/section-ai-testing-exchange-result.tsx +71 -0
  50. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +20 -4
  51. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +29 -0
  52. package/templates/app-source/src/ai-studio-core/section-ai-testing-music-result.tsx +45 -0
  53. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +132 -10
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +122 -38
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +4 -3
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing-session-result.tsx +66 -0
  57. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +100 -22
  58. package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +6 -0
  59. package/templates/app-source/src/ai-studio-core/section-ai-testing-transcript-result.tsx +45 -0
  60. package/templates/app-source/src/ai-studio-core/section-ai-testing-transcription-result.tsx +106 -0
  61. package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +23 -4
  62. package/templates/app-source/src/ai-studio-core/section-ai-testing-voice-asset-actions.tsx +40 -0
  63. package/templates/app-source/src/ai-studio-core/section-ai-testing-voice-conversion-result.tsx +20 -0
  64. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +219 -35
  65. package/templates/app-source/src/ai-studio-core/text-annotation-document.ts +50 -0
  66. package/templates/app-source/src/ai-studio-core/text-media-replay.ts +51 -0
  67. package/templates/app-source/src/ai-studio-core/voice-assets.ts +17 -0
  68. package/templates/app-source/src/ai-studio-core/workspace.tsx +48 -6
  69. package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +1 -1
  70. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +13 -1
  71. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +13 -1
  72. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +11 -2
  73. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +2 -2
  74. package/templates/app-source/src/studio-modules/studio-create/registration.ts +2 -2
  75. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +121 -3
  76. package/templates/app-source/src/studio-modules/studio-media/audio-separate-parameters.tsx +72 -0
  77. package/templates/app-source/src/studio-modules/studio-media/audio-separate-runtime.ts +90 -0
  78. package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +16 -1
  79. package/templates/app-source/src/studio-modules/studio-media/index.ts +2 -0
  80. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +225 -7
  81. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +225 -7
  82. package/templates/app-source/src/studio-modules/studio-media/music-parameters.tsx +85 -0
  83. package/templates/app-source/src/studio-modules/studio-media/music-transcription-parameters.tsx +85 -0
  84. package/templates/app-source/src/studio-modules/studio-media/music-transcription-runtime.ts +64 -0
  85. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +9 -26
  86. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +170 -6
  87. package/templates/app-source/src/studio-modules/studio-media/registration.ts +29 -1
  88. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +90 -6
  89. package/templates/app-source/src/studio-modules/studio-media/vision-parameters.tsx +1 -0
  90. package/templates/app-source/src/studio-modules/studio-media/vision-runtime.ts +23 -5
  91. package/templates/app-source/src/studio-modules/studio-media/voice-convert-parameters.tsx +132 -0
  92. package/templates/app-source/src/studio-modules/studio-media/voice-convert-runtime.ts +120 -0
  93. package/templates/app-source/src/studio-modules/studio-voice/audio-url.ts +25 -0
  94. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +4 -4
  95. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +4 -4
  96. package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +36 -10
  97. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +66 -30
  98. package/templates/app-source/src/workbench-core/index.ts +2 -0
  99. package/templates/app-source/src/workbench-core/runtime-gate.tsx +102 -6
  100. package/templates/app-source/src/workbench-core/workbench-core.css +42 -0
  101. package/templates/app-source/src/workbench-core/workbench-core.tsx +69 -18
  102. package/templates/app-source.manifest.json +100 -0
  103. package/templates/default-starter/AGENTS.md +4 -2
  104. package/templates/default-starter/README.md +2 -1
  105. package/templates/default-starter/src/shell/workbench-target-adapter.ts +102 -12
  106. package/templates/default-starter.manifest.json +0 -4
  107. package/lib/simulator-conformance-ast.mjs +0 -498
  108. package/lib/simulator-conformance-css.mjs +0 -116
  109. package/lib/simulator-conformance-graph.mjs +0 -757
  110. package/lib/simulator-conformance.d.mts +0 -14
  111. package/lib/simulator-conformance.mjs +0 -203
  112. package/lib/simulator-css-profile.d.mts +0 -27
  113. package/lib/simulator-css-profile.mjs +0 -531
  114. package/lib/simulator-kit-export-resolution.mjs +0 -70
  115. package/lib/simulator-manifest.mjs +0 -334
@@ -1,5 +1,7 @@
1
+ import type { StudioAudioSeparation, StudioFaceSwap, StudioJsonValue, StudioMusicGeneration, StudioMusicTranscription, StudioSessionSummary, StudioTextDecisionAnswer, StudioTextExchangeStep, StudioVoiceConversion } from './runtime-types.js';
1
2
  import { isJsonObject } from '@nimiplatform/sdk/types';
2
- import type { NimiLocalAppVisionLocateResult } from '@nimiplatform/sdk/app';
3
+ import { studioResultAssetReferences } from './managed-result-references.js';
4
+ import type { NimiLocalAppSpeechTranscript, NimiLocalAppVisionLocateResult } from '@nimiplatform/sdk/app';
3
5
  import type {
4
6
  StudioCapabilityRunResult,
5
7
  StudioManagedArtifact,
@@ -51,7 +53,8 @@ export type StudioRunConfigSnapshot = {
51
53
  };
52
54
 
53
55
  export type StudioRunHistoryResultSnapshot =
54
- | { ok: true; kind: 'vision-locate'; summary: string; jobId: string; result?: NimiLocalAppVisionLocateResult; traceId?: string }
56
+ | { ok: true; kind: 'speaker-embedding'; summary: string; jobId: string; spaceId: string; vector: number[]; traceId?: string }
57
+ | { ok: true; kind: 'vision-locate'; summary: string; jobId: string; result?: NimiLocalAppVisionLocateResult; sourceImage?: StudioManagedArtifact; traceId?: string }
55
58
  | {
56
59
  ok: true;
57
60
  kind: 'text';
@@ -63,6 +66,7 @@ export type StudioRunHistoryResultSnapshot =
63
66
  inputTokens?: number;
64
67
  outputTokens?: number;
65
68
  totalTokens?: number;
69
+ sourceImage?: StudioManagedArtifact;
66
70
  traceId?: string;
67
71
  }
68
72
  | {
@@ -71,6 +75,7 @@ export type StudioRunHistoryResultSnapshot =
71
75
  summary: string;
72
76
  vectorCount: number;
73
77
  dimensions: number;
78
+ spaceId?: string;
74
79
  sample: number[];
75
80
  totalTokens?: number;
76
81
  traceId?: string;
@@ -78,6 +83,12 @@ export type StudioRunHistoryResultSnapshot =
78
83
  | {
79
84
  ok: true;
80
85
  kind: 'artifacts';
86
+ sourceImage?: StudioManagedArtifact;
87
+ musicGeneration?: StudioMusicGeneration;
88
+ musicTranscription?: StudioMusicTranscription;
89
+ voiceConversion?: StudioVoiceConversion;
90
+ audioSeparation?: StudioAudioSeparation;
91
+ faceSwap?: StudioFaceSwap;
81
92
  summary: string;
82
93
  jobId: string;
83
94
  jobState: string;
@@ -95,6 +106,7 @@ export type StudioRunHistoryResultSnapshot =
95
106
  jobId: string;
96
107
  jobState: string;
97
108
  artifactCount: number;
109
+ transcription?: NimiLocalAppSpeechTranscript;
98
110
  traceId?: string;
99
111
  }
100
112
  | {
@@ -106,6 +118,10 @@ export type StudioRunHistoryResultSnapshot =
106
118
  voiceAssetId: string;
107
119
  creationSource: 'reference-audio' | 'text-description';
108
120
  assetStatus: string;
121
+ preview?: StudioManagedArtifact;
122
+ expiresAt?: string;
123
+ inputTokens?: number;
124
+ outputTokens?: number;
109
125
  traceId?: string;
110
126
  }
111
127
  | {
@@ -116,6 +132,45 @@ export type StudioRunHistoryResultSnapshot =
116
132
  sample: Array<{ voiceId: string; creationSource: string; status: string }>;
117
133
  traceId?: string;
118
134
  }
135
+ | {
136
+ ok: true;
137
+ kind: 'text-annotation';
138
+ summary: string;
139
+ jobId: string;
140
+ jobState: string;
141
+ language: string;
142
+ documentCount: number;
143
+ tokenCount: number;
144
+ sentenceCount: number;
145
+ document: StudioManagedArtifact;
146
+ traceId?: string;
147
+ }
148
+ | {
149
+ ok: true;
150
+ kind: 'text-exchange';
151
+ summary: string;
152
+ scenario: 'tool-call' | 'structured-output';
153
+ steps: StudioTextExchangeStep[];
154
+ text: string;
155
+ structured?: StudioJsonValue;
156
+ traceId?: string;
157
+ }
158
+ | {
159
+ ok: true;
160
+ kind: 'text-decision';
161
+ summary: string;
162
+ questionCount: number;
163
+ // Absent only when the answers were too large for the shared history
164
+ // budget; the record then keeps its summary alone.
165
+ answers?: StudioTextDecisionAnswer[];
166
+ traceId?: string;
167
+ }
168
+ | ({
169
+ ok: true;
170
+ kind: 'session';
171
+ summary: string;
172
+ traceId?: string;
173
+ } & StudioSessionSummary)
119
174
  | {
120
175
  ok: false;
121
176
  kind: 'non-success';
@@ -125,6 +180,7 @@ export type StudioRunHistoryResultSnapshot =
125
180
  actionHint: string;
126
181
  missingSurface?: string;
127
182
  diagnostics?: StudioNonSuccessDiagnostics;
183
+ jobId?: string;
128
184
  };
129
185
 
130
186
  export type StudioRunHistoryRecord = {
@@ -136,6 +192,9 @@ export type StudioRunHistoryRecord = {
136
192
  createdAt: string;
137
193
  result?: StudioRunHistoryResultSnapshot;
138
194
  runConfig?: StudioRunConfigSnapshot;
195
+ // Set when history keeps only the beginning of a long prompt or context;
196
+ // such a record cannot be reused as a draft or rerun.
197
+ inputTruncated?: true;
139
198
  };
140
199
 
141
200
  export type StudioRunHistory = Record<string, StudioRunHistoryRecord[]>;
@@ -225,6 +284,32 @@ export async function projectStudioManagedHistory(input: {
225
284
  projectedIDs.add(id);
226
285
  }
227
286
  }
287
+ if (result?.ok === true && result.kind === 'voice-asset' && result.preview) {
288
+ const verification = await verifyStudioManagedArtifact(input.statArtifact, result.preview, record);
289
+ if (verification.status === 'unavailable') unavailableReason = verification.message;
290
+ }
291
+ if (result?.ok === true && result.kind === 'text-annotation') {
292
+ // The saved document is the only complete result; reopening never
293
+ // presents a missing or altered document as saved.
294
+ const verification = await verifyStudioManagedArtifact(input.statArtifact, result.document, record);
295
+ if (verification.status === 'unavailable') unavailableReason = verification.message;
296
+ }
297
+ if (result?.ok === true && (result.kind === 'text' || result.kind === 'vision-locate') && result.sourceImage) {
298
+ const verification = await verifyStudioManagedArtifact(input.statArtifact, result.sourceImage, record);
299
+ if (verification.status === 'unavailable') unavailableReason = verification.message;
300
+ }
301
+ // Inputs are part of the saved result too. Missing canonical sources or
302
+ // targets must not leave a seemingly complete, replayable music result.
303
+ if (result?.ok) {
304
+ const outputPaths = new Set(result.kind === 'artifacts'
305
+ ? (result.artifacts ?? (result.firstArtifact ? [result.firstArtifact] : [])).map(item => item.relativePath) : []);
306
+ for (const reference of studioResultAssetReferences(result)) {
307
+ if (outputPaths.has(reference.relativePath as string) || typeof reference.sha256 !== 'string'
308
+ || typeof reference.sizeBytes !== 'number') continue;
309
+ const verification = await verifyStudioManagedArtifact(input.statArtifact, reference as StudioManagedArtifact, record);
310
+ if (verification.status === 'unavailable' && !unavailableReason) unavailableReason = verification.message;
311
+ }
312
+ }
228
313
  if (unavailableReason && record.status === 'ready') {
229
314
  projectedRecord = { ...record, status: 'unavailable', message: unavailableReason };
230
315
  }
@@ -427,6 +512,25 @@ function compactBodySummary(value: string): string {
427
512
  return normalized.length > 180 ? `${normalized.slice(0, 177)}...` : normalized;
428
513
  }
429
514
 
515
+ function studioTextDecisionSummary(answers: readonly StudioTextDecisionAnswer[]): string {
516
+ return answers.map((answer) => {
517
+ if (answer.kind === 'boolean') return `${answer.questionId}: true ${answer.trueProbability.toFixed(2)}`;
518
+ const selected = answer.probabilities.find((entry) => entry.candidateId === answer.selectedCandidateId);
519
+ return `${answer.questionId}: ${answer.selectedCandidateId}${selected ? ` ${selected.probability.toFixed(2)}` : ''}`;
520
+ }).join(' / ');
521
+ }
522
+
523
+ function copyStudioTextDecisionAnswer(answer: StudioTextDecisionAnswer): StudioTextDecisionAnswer {
524
+ return answer.kind === 'choice'
525
+ ? {
526
+ questionId: answer.questionId,
527
+ kind: 'choice',
528
+ selectedCandidateId: answer.selectedCandidateId,
529
+ probabilities: answer.probabilities.map((entry) => ({ candidateId: entry.candidateId, probability: entry.probability })),
530
+ }
531
+ : { questionId: answer.questionId, kind: 'boolean', trueProbability: answer.trueProbability };
532
+ }
533
+
430
534
  function traceFields(result: StudioCapabilityRunResult): Pick<Extract<StudioRunHistoryResultSnapshot, { ok: true }>, 'traceId'> {
431
535
  if (isStudioNonSuccessRunResult(result)) return {};
432
536
  return {
@@ -453,12 +557,13 @@ export function createStudioRunHistoryResultSnapshot(result: StudioCapabilityRun
453
557
  actionHint: result.actionHint,
454
558
  missingSurface: result.missingSurface,
455
559
  ...(result.diagnostics ? { diagnostics: { ...result.diagnostics } } : {}),
560
+ ...(result.jobId ? { jobId: result.jobId } : {}),
456
561
  };
457
562
  }
458
563
 
459
564
  const trace = traceFields(result);
460
565
  const output = result.output;
461
- if (output.kind === 'vision-locate') return { ok: true, kind: 'vision-locate', summary: result.message, jobId: output.jobId, result: output.result, ...trace };
566
+ if (output.kind === 'vision-locate') return { ok: true, kind: 'vision-locate', summary: result.message, jobId: output.jobId, result: output.result, ...(output.sourceImage ? { sourceImage: { ...output.sourceImage } } : {}), ...trace };
462
567
  if (output.kind === 'text') {
463
568
  return {
464
569
  ok: true,
@@ -471,27 +576,87 @@ export function createStudioRunHistoryResultSnapshot(result: StudioCapabilityRun
471
576
  inputTokens: output.inputTokens,
472
577
  outputTokens: output.outputTokens,
473
578
  totalTokens: output.totalTokens,
579
+ ...(output.sourceImage ? { sourceImage: { ...output.sourceImage } } : {}),
474
580
  ...trace,
475
581
  };
476
582
  }
583
+ if (output.kind === 'speaker-embedding') return { ok: true, kind: output.kind, summary: result.message, jobId: output.jobId, spaceId: output.spaceId, vector: [...output.vector], ...trace };
477
584
  if (output.kind === 'embedding') {
478
585
  return {
479
586
  ok: true,
480
587
  kind: 'embedding',
481
- summary: `${output.vectorCount} vector${output.vectorCount === 1 ? '' : 's'} / ${output.dimensions} dimensions`,
588
+ summary: `${output.vectorCount} vector${output.vectorCount === 1 ? '' : 's'} / ${output.dimensions} dimensions${output.spaceId ? ` / space ${output.spaceId}` : ''}`,
482
589
  vectorCount: output.vectorCount,
483
590
  dimensions: output.dimensions,
591
+ ...(output.spaceId ? { spaceId: output.spaceId } : {}),
484
592
  sample: output.sample,
485
593
  totalTokens: output.totalTokens,
486
594
  ...trace,
487
595
  };
488
596
  }
597
+ if (output.kind === 'text-annotation') {
598
+ return {
599
+ ok: true,
600
+ kind: 'text-annotation',
601
+ summary: `${output.language} / ${output.documentCount} document${output.documentCount === 1 ? '' : 's'} / ${output.tokenCount} token${output.tokenCount === 1 ? '' : 's'} / ${output.sentenceCount} sentence${output.sentenceCount === 1 ? '' : 's'}`,
602
+ jobId: output.jobId,
603
+ jobState: output.jobState,
604
+ language: output.language,
605
+ documentCount: output.documentCount,
606
+ tokenCount: output.tokenCount,
607
+ sentenceCount: output.sentenceCount,
608
+ document: { ...output.document },
609
+ ...trace,
610
+ };
611
+ }
612
+ if (output.kind === 'text-exchange') {
613
+ return {
614
+ ok: true,
615
+ kind: 'text-exchange',
616
+ summary: compactBodySummary(output.text),
617
+ scenario: output.scenario,
618
+ steps: output.steps.map((step) => ({ ...step, items: [...step.items] })),
619
+ text: output.text,
620
+ ...(output.structured !== undefined ? { structured: output.structured } : {}),
621
+ ...trace,
622
+ };
623
+ }
624
+ if (output.kind === 'text-decision') {
625
+ return {
626
+ ok: true,
627
+ kind: 'text-decision',
628
+ summary: compactBodySummary(studioTextDecisionSummary(output.answers)),
629
+ questionCount: output.answers.length,
630
+ answers: output.answers.map(copyStudioTextDecisionAnswer),
631
+ ...trace,
632
+ };
633
+ }
634
+ if (output.kind === 'session') {
635
+ return {
636
+ ok: true,
637
+ kind: 'session',
638
+ summary: `${output.capabilityContract} / ${output.ending} / ${output.terminalReason}`,
639
+ capabilityContract: output.capabilityContract,
640
+ startedAt: output.startedAt,
641
+ endedAt: output.endedAt,
642
+ ending: output.ending,
643
+ terminalReason: output.terminalReason,
644
+ observed: { ...output.observed },
645
+ ...trace,
646
+ };
647
+ }
489
648
  if (output.kind === 'artifacts') {
490
649
  const artifacts = output.artifacts.map((artifact) => ({ ...artifact }));
491
650
  const firstArtifact = artifacts[0];
492
651
  return {
493
652
  ok: true,
494
653
  kind: 'artifacts',
654
+ ...(output.sourceImage ? { sourceImage: { ...output.sourceImage } } : {}),
655
+ ...(output.musicGeneration ? { musicGeneration: output.musicGeneration } : {}),
656
+ ...(output.musicTranscription ? { musicTranscription: output.musicTranscription } : {}),
657
+ ...(output.voiceConversion ? { voiceConversion: output.voiceConversion } : {}),
658
+ ...(output.audioSeparation ? { audioSeparation: output.audioSeparation } : {}),
659
+ ...(output.faceSwap ? { faceSwap: output.faceSwap } : {}),
495
660
  summary: `${output.jobState || 'unknown'} / ${output.artifactCount} artifact${output.artifactCount === 1 ? '' : 's'}${firstArtifact?.mediaType ? ` / ${firstArtifact.mediaType}` : ''}`,
496
661
  jobId: output.jobId,
497
662
  jobState: output.jobState,
@@ -511,6 +676,7 @@ export function createStudioRunHistoryResultSnapshot(result: StudioCapabilityRun
511
676
  jobId: output.jobId,
512
677
  jobState: output.jobState,
513
678
  artifactCount: output.artifactCount,
679
+ ...(output.transcription ? { transcription: output.transcription } : {}),
514
680
  ...trace,
515
681
  };
516
682
  }
@@ -524,6 +690,10 @@ export function createStudioRunHistoryResultSnapshot(result: StudioCapabilityRun
524
690
  voiceAssetId: output.voiceAssetId,
525
691
  creationSource: output.creationSource,
526
692
  assetStatus: output.assetStatus,
693
+ ...(output.preview ? { preview: { ...output.preview } } : {}),
694
+ ...(output.expiresAt ? { expiresAt: output.expiresAt } : {}),
695
+ ...(output.inputTokens !== undefined ? { inputTokens: output.inputTokens } : {}),
696
+ ...(output.outputTokens !== undefined ? { outputTokens: output.outputTokens } : {}),
527
697
  ...trace,
528
698
  };
529
699
  }
@@ -538,7 +708,7 @@ export function createStudioRunHistoryResultSnapshot(result: StudioCapabilityRun
538
708
  }
539
709
 
540
710
  export function restoreStudioCapabilityRunResult(
541
- record: StudioRunHistoryRecord,
711
+ record: Pick<StudioRunHistoryRecord, 'capabilityId' | 'result' | 'message'>,
542
712
  resolveCapabilityLabel: StudioCapabilityLabelResolver,
543
713
  ): StudioCapabilityRunResult | null {
544
714
  const snapshot = record.result;
@@ -552,6 +722,7 @@ export function restoreStudioCapabilityRunResult(
552
722
  actionHint: snapshot.actionHint,
553
723
  ...(snapshot.missingSurface ? { missingSurface: snapshot.missingSurface } : {}),
554
724
  ...(snapshot.diagnostics ? { diagnostics: { ...snapshot.diagnostics } } : {}),
725
+ ...(snapshot.jobId ? { jobId: snapshot.jobId } : {}),
555
726
  };
556
727
  }
557
728
 
@@ -572,7 +743,7 @@ export function restoreStudioCapabilityRunResult(
572
743
  message: record.message,
573
744
  ...(trace ? { trace } : {}),
574
745
  };
575
- if (snapshot.kind === 'vision-locate') return snapshot.result ? { ...common, output: { kind: 'vision-locate', jobId: snapshot.jobId, result: snapshot.result } } : null;
746
+ if (snapshot.kind === 'vision-locate') return snapshot.result ? { ...common, output: { kind: 'vision-locate', jobId: snapshot.jobId, result: snapshot.result, ...(snapshot.sourceImage ? { sourceImage: { ...snapshot.sourceImage } } : {}) } } : null;
576
747
  if (snapshot.kind === 'text') {
577
748
  return {
578
749
  ...common,
@@ -584,9 +755,11 @@ export function restoreStudioCapabilityRunResult(
584
755
  inputTokens: snapshot.inputTokens,
585
756
  outputTokens: snapshot.outputTokens,
586
757
  totalTokens: snapshot.totalTokens,
758
+ ...(snapshot.sourceImage ? { sourceImage: { ...snapshot.sourceImage } } : {}),
587
759
  },
588
760
  };
589
761
  }
762
+ if (snapshot.kind === 'speaker-embedding') return { ...common, output: { kind: snapshot.kind, jobId: snapshot.jobId, spaceId: snapshot.spaceId, vector: [...snapshot.vector] } };
590
763
  if (snapshot.kind === 'embedding') {
591
764
  return {
592
765
  ...common,
@@ -594,11 +767,58 @@ export function restoreStudioCapabilityRunResult(
594
767
  kind: 'embedding',
595
768
  vectorCount: snapshot.vectorCount,
596
769
  dimensions: snapshot.dimensions,
770
+ ...(snapshot.spaceId ? { spaceId: snapshot.spaceId } : {}),
597
771
  sample: snapshot.sample,
598
772
  totalTokens: snapshot.totalTokens,
599
773
  },
600
774
  };
601
775
  }
776
+ if (snapshot.kind === 'text-annotation') {
777
+ return {
778
+ ...common,
779
+ output: {
780
+ kind: 'text-annotation',
781
+ jobId: snapshot.jobId,
782
+ jobState: snapshot.jobState,
783
+ language: snapshot.language,
784
+ documentCount: snapshot.documentCount,
785
+ tokenCount: snapshot.tokenCount,
786
+ sentenceCount: snapshot.sentenceCount,
787
+ document: { ...snapshot.document },
788
+ },
789
+ };
790
+ }
791
+ if (snapshot.kind === 'text-exchange') {
792
+ return {
793
+ ...common,
794
+ output: {
795
+ kind: 'text-exchange',
796
+ scenario: snapshot.scenario,
797
+ steps: snapshot.steps.map((step) => ({ ...step, items: [...step.items] })),
798
+ text: snapshot.text,
799
+ ...(snapshot.structured !== undefined ? { structured: snapshot.structured } : {}),
800
+ },
801
+ };
802
+ }
803
+ if (snapshot.kind === 'text-decision') {
804
+ return snapshot.answers
805
+ ? { ...common, output: { kind: 'text-decision', answers: snapshot.answers.map(copyStudioTextDecisionAnswer) } }
806
+ : null;
807
+ }
808
+ if (snapshot.kind === 'session') {
809
+ return {
810
+ ...common,
811
+ output: {
812
+ kind: 'session',
813
+ capabilityContract: snapshot.capabilityContract,
814
+ startedAt: snapshot.startedAt,
815
+ endedAt: snapshot.endedAt,
816
+ ending: snapshot.ending,
817
+ terminalReason: snapshot.terminalReason,
818
+ observed: { ...snapshot.observed },
819
+ },
820
+ };
821
+ }
602
822
  if (snapshot.kind === 'artifacts') {
603
823
  const artifacts = snapshot.artifacts?.map((artifact) => ({ ...artifact }))
604
824
  ?? (snapshot.firstArtifact ? [{ ...snapshot.firstArtifact }] : []);
@@ -606,6 +826,12 @@ export function restoreStudioCapabilityRunResult(
606
826
  ...common,
607
827
  output: {
608
828
  kind: 'artifacts',
829
+ ...(snapshot.sourceImage ? { sourceImage: { ...snapshot.sourceImage } } : {}),
830
+ ...(snapshot.musicGeneration ? { musicGeneration: snapshot.musicGeneration } : {}),
831
+ ...(snapshot.musicTranscription ? { musicTranscription: snapshot.musicTranscription } : {}),
832
+ ...(snapshot.voiceConversion ? { voiceConversion: snapshot.voiceConversion } : {}),
833
+ ...(snapshot.audioSeparation ? { audioSeparation: snapshot.audioSeparation } : {}),
834
+ ...(snapshot.faceSwap ? { faceSwap: snapshot.faceSwap } : {}),
609
835
  jobId: snapshot.jobId,
610
836
  jobState: snapshot.jobState,
611
837
  artifactCount: snapshot.artifactCount,
@@ -623,6 +849,7 @@ export function restoreStudioCapabilityRunResult(
623
849
  jobId: snapshot.jobId,
624
850
  jobState: snapshot.jobState,
625
851
  artifactCount: snapshot.artifactCount,
852
+ ...(snapshot.transcription ? { transcription: snapshot.transcription } : {}),
626
853
  },
627
854
  };
628
855
  }
@@ -636,6 +863,10 @@ export function restoreStudioCapabilityRunResult(
636
863
  voiceAssetId: snapshot.voiceAssetId,
637
864
  creationSource: snapshot.creationSource,
638
865
  assetStatus: snapshot.assetStatus,
866
+ ...(snapshot.preview ? { preview: { ...snapshot.preview } } : {}),
867
+ ...(snapshot.expiresAt ? { expiresAt: snapshot.expiresAt } : {}),
868
+ ...(snapshot.inputTokens !== undefined ? { inputTokens: snapshot.inputTokens } : {}),
869
+ ...(snapshot.outputTokens !== undefined ? { outputTokens: snapshot.outputTokens } : {}),
639
870
  voiceReference: { kind: 'voice_asset_id', voiceAssetId: snapshot.voiceAssetId },
640
871
  },
641
872
  };
@@ -796,13 +1027,19 @@ export function getStudioRunMetricSummary(record: StudioRunHistoryRecord): strin
796
1027
  `${result.charCount} chars`,
797
1028
  ].filter(Boolean).join(' / ');
798
1029
  }
1030
+ if (result.kind === 'speaker-embedding') return `${result.vector.length} dims / ${result.spaceId}`;
799
1031
  if (result.kind === 'embedding') {
800
1032
  return [
801
1033
  formatStudioTokenUsage(undefined, undefined, result.totalTokens),
802
1034
  `${result.vectorCount} vector${result.vectorCount === 1 ? '' : 's'}`,
803
1035
  `${result.dimensions} dims`,
1036
+ result.spaceId ? `space ${result.spaceId}` : '',
804
1037
  ].filter(Boolean).join(' / ');
805
1038
  }
1039
+ if (result.kind === 'text-annotation') return `${result.jobState || 'unknown'} / ${result.documentCount} doc${result.documentCount === 1 ? '' : 's'} / ${result.tokenCount} tokens`;
1040
+ if (result.kind === 'text-exchange') return `${result.scenario} / ${result.steps.length} step${result.steps.length === 1 ? '' : 's'}`;
1041
+ if (result.kind === 'text-decision') return `${result.questionCount} question${result.questionCount === 1 ? '' : 's'}`;
1042
+ if (result.kind === 'session') return `${result.ending} / ${result.terminalReason}`;
806
1043
  if (result.kind === 'artifacts') return `${result.jobState || 'unknown'} / ${result.artifactCount} artifact${result.artifactCount === 1 ? '' : 's'}`;
807
1044
  if (result.kind === 'transcript') return `${result.jobState || 'unknown'} / ${result.charCount} chars / ${result.artifactCount} artifact${result.artifactCount === 1 ? '' : 's'}`;
808
1045
  if (result.kind === 'voice-asset') return `${result.jobState || 'unknown'} / ${result.creationSource} / ${result.assetStatus}`;
@@ -821,10 +1058,25 @@ export function getStudioRunResultTags(record: StudioRunHistoryRecord): string[]
821
1058
  result.totalTokens === undefined ? '' : `${result.totalTokens} tokens`,
822
1059
  ].filter(Boolean);
823
1060
  }
824
- if (result.kind === 'embedding') return ['Embedding ready'];
825
- if (result.kind === 'artifacts') return ['Ready'];
826
- if (result.kind === 'transcript') return ['Ready'];
827
- if (result.kind === 'voice-asset') return ['VoiceAsset ready', result.creationSource];
1061
+ if (result.kind === 'speaker-embedding') return [String(result.vector.length)];
1062
+ if (result.kind === 'embedding') return ['Embedding ready', ...(result.spaceId ? [result.spaceId] : [])];
1063
+ if (result.kind === 'text-annotation') return ['Annotation', result.language];
1064
+ if (result.kind === 'text-exchange') return [result.scenario];
1065
+ if (result.kind === 'text-decision') return ['Decision', `${result.questionCount} question${result.questionCount === 1 ? '' : 's'}`];
1066
+ if (result.kind === 'session') return ['Session', result.ending];
1067
+ if (result.kind === 'artifacts' || result.kind === 'transcript') return [getStudioRunMetricSummary(record)];
1068
+ if (result.kind === 'voice-asset') return [result.creationSource];
828
1069
  if (result.kind === 'vision-locate') return result.result ? ['Locate', String(result.result.locations.length)] : ['Locate'];
829
1070
  return [`${result.voiceCount} voices`];
830
1071
  }
1072
+
1073
+ export function getStudioRunHistoryExportText(record: StudioRunHistoryRecord): string {
1074
+ const snapshot = record.result;
1075
+ if (!snapshot) return record.message;
1076
+ if (!snapshot.ok) return snapshot.message;
1077
+ if (snapshot.kind === 'text' || snapshot.kind === 'transcript') return snapshot.body;
1078
+ if (snapshot.kind === 'text-exchange') return snapshot.text;
1079
+ if (snapshot.kind === 'speaker-embedding') return JSON.stringify({ jobId: snapshot.jobId, spaceId: snapshot.spaceId, vector: snapshot.vector }, null, 2);
1080
+ if (snapshot.kind === 'text-decision' && snapshot.answers) return JSON.stringify({ answers: snapshot.answers }, null, 2);
1081
+ return snapshot.summary;
1082
+ }
@@ -1,6 +1,6 @@
1
1
  import type { NimiLocalAppClient } from '@nimiplatform/sdk/app';
2
2
  import { createContext, useContext, type ReactNode } from 'react';
3
- import type { NimiPortableAppAIConfig } from '@nimiplatform/sdk/ai';
3
+ import type { NimiPortableAppAIConfig, NimiAIConfigSnapshot } from '@nimiplatform/sdk/ai';
4
4
  import type { StudioCapabilityRunInput, StudioCapabilityRunResult } from './runtime-types.js';
5
5
  import type { StudioCapabilityDescriptor } from './module-registration.js';
6
6
  import type { StudioRunTargetSummary } from './history.js';
@@ -12,6 +12,15 @@ export type StudioHostCommandResult<TValue extends object = Record<string, never
12
12
  | { readonly ok: true; readonly value?: TValue }
13
13
  | { readonly ok: false; readonly error?: unknown };
14
14
 
15
+ export type StudioTextExportResult =
16
+ | { readonly ok: true; readonly value: {
17
+ readonly filename: string;
18
+ readonly artifactPath: string;
19
+ readonly byteSize: number;
20
+ readonly revealed: boolean;
21
+ } }
22
+ | { readonly ok: false; readonly error?: unknown };
23
+
15
24
  export type AIStudioHostPort = {
16
25
  readonly appTitle: string;
17
26
  readonly translate: (key: string, values?: Readonly<Record<string, unknown>>) => string;
@@ -37,11 +46,12 @@ export type AIStudioHostPort = {
37
46
  readonly commands: {
38
47
  readonly savePromptDraft: (key: StudioPromptDraftKey, prompt: string, enabled: boolean) => Promise<unknown>;
39
48
  readonly copyText: (text: string) => Promise<StudioHostCommandResult<{ readonly copied: boolean }>>;
40
- readonly exportText: (input: { readonly filename: string; readonly body: string }) => Promise<unknown>;
49
+ readonly exportText: (input: { readonly filename: string; readonly body: string }) => Promise<StudioTextExportResult>;
41
50
  };
42
51
  };
43
52
  readonly sdk: {
44
53
  readonly runCapability: (input: StudioCapabilityRunInput) => Promise<StudioCapabilityRunResult>;
54
+ readonly deleteLocalAppVoiceAsset: (voiceAssetId: string) => Promise<{ readonly deleted: true }>;
45
55
  readonly listLocalAppVoiceAssets: () => Promise<readonly {
46
56
  readonly voiceAssetId: string;
47
57
  readonly creationSource: string;
@@ -55,7 +65,10 @@ export type AIStudioHostPort = {
55
65
  readonly sizeBytes: number;
56
66
  readonly mimeType: NimiLocalAppArtifactUploadMime;
57
67
  }>;
68
+ readonly assets: NimiLocalAppClient['storage']['assets'];
69
+ readonly storage: Pick<NimiLocalAppClient['storage'], 'readJson' | 'writeJson'>;
58
70
  readonly aiConfig: {
71
+ readonly getSnapshot: () => Promise<NimiAIConfigSnapshot>;
59
72
  readonly get: () => Promise<NimiPortableAppAIConfig | null>;
60
73
  };
61
74
  readonly revealLocalAppAsset: (relativePath: string) => Promise<{ readonly revealed: true }>;
@@ -28,6 +28,7 @@ export {
28
28
  defineStudioParameters,
29
29
  type StudioParameterContract,
30
30
  type StudioParameterPresentation,
31
+ type StudioRecordedParameterInput,
31
32
  type StudioParameterRouteMatrix,
32
33
  type StudioParameterRouteState,
33
34
  type StudioParameterState,
@@ -49,8 +50,10 @@ export {
49
50
  type StudioParameterTranslate,
50
51
  } from './parameter-fields.js';
51
52
  export {
53
+ STUDIO_AI_CONFIG_CHANGED_EVENT,
52
54
  findStudioCapabilityIntent,
53
55
  loadStudioAIConfig,
56
+ notifyStudioAIConfigChanged,
54
57
  requireStudioAIConfigOwner,
55
58
  studioCloudIntentHasExactTarget,
56
59
  subscribeStudioAIConfigRefresh,
@@ -63,10 +66,7 @@ export {
63
66
  } from './run-target.js';
64
67
  export {
65
68
  DEFAULT_AI_STUDIO_HISTORY_PANEL_PREFERENCES,
66
- STUDIO_HISTORY_LIMIT_BYTES,
67
- STUDIO_HISTORY_LIMIT_PER_CAPABILITY,
68
- STUDIO_HISTORY_LIMIT_TOTAL_RECORDS,
69
- boundStudioRunHistoryWithRecord,
69
+ appendStudioRunHistoryRecord,
70
70
  cleanupStudioHistoryArtifacts,
71
71
  clearStudioRunHistory,
72
72
  clearStudioHistoryWithPolicy,
@@ -77,6 +77,7 @@ export {
77
77
  removeStudioRunHistoryRecord,
78
78
  studioHistoryClearOutcomeTone,
79
79
  studioHistoryArtifactPaths,
80
+ studioHistoryDocumentPaths,
80
81
  studioHistoryFromRecords,
81
82
  type StudioHistoryPolicyMutationIssue,
82
83
  type StudioHistoryPolicyMutationOutcome,
@@ -140,12 +141,21 @@ export {
140
141
  export type {
141
142
  StudioCapabilityRunInput,
142
143
  StudioCapabilityRunResult,
144
+ StudioFaceSwap,
145
+ StudioFaceSwapInput,
146
+ StudioFaceSwapInputRole,
147
+ StudioJsonValue,
143
148
  StudioManagedArtifact,
144
149
  StudioNonSuccess,
145
150
  StudioNonSuccessDiagnostics,
146
151
  StudioNonSuccessReason,
147
152
  StudioRuntimeCapabilityDescriptor,
148
153
  StudioRuntimeInspection,
154
+ StudioSessionSummary,
155
+ StudioTextDecisionAnswer,
156
+ StudioTextDecisionProbability,
157
+ StudioTextExchangeItem,
158
+ StudioTextExchangeStep,
149
159
  StudioTrace,
150
160
  StudioTypedOutput,
151
161
  StudioTypedSuccess,
@@ -189,6 +199,7 @@ export {
189
199
  useAIStudioHost,
190
200
  type AIStudioHostPort,
191
201
  type StudioHostCommandResult,
202
+ type StudioTextExportResult,
192
203
  } from './host-context.js';
193
204
  export { SectionAITesting } from './section-ai-testing.js';
194
205
  export type { SectionAITestingProps, StudioAIConfigPanelRenderInput } from './section-ai-testing-surface.js';