@nimiplatform/app-tools 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/LICENSE +198 -6
  2. package/README.md +83 -27
  3. package/bin/nimi-app.mjs +328 -45
  4. package/lib/app-access-declaration.mjs +49 -0
  5. package/lib/app-doctor-update.mjs +411 -149
  6. package/lib/app-pack.mjs +401 -0
  7. package/lib/app-project-lifecycle.mjs +1141 -0
  8. package/lib/app-scaffold-capabilities.mjs +769 -0
  9. package/lib/app-scaffold-default-source.mjs +21 -0
  10. package/lib/app-scaffold-profiles.mjs +1093 -0
  11. package/lib/app-scaffold.mjs +1266 -813
  12. package/lib/index.mjs +194 -42
  13. package/lib/simulator-conformance-ast.mjs +498 -0
  14. package/lib/simulator-conformance-css.mjs +116 -0
  15. package/lib/simulator-conformance-graph.mjs +757 -0
  16. package/lib/simulator-conformance.d.mts +14 -0
  17. package/lib/simulator-conformance.mjs +203 -0
  18. package/lib/simulator-css-profile.d.mts +27 -0
  19. package/lib/simulator-css-profile.mjs +531 -0
  20. package/lib/simulator-kit-export-resolution.mjs +70 -0
  21. package/lib/simulator-manifest.mjs +334 -0
  22. package/package.json +66 -3
  23. package/scripts/dev-shell.mjs +465 -0
  24. package/scripts/sync-app-source.mjs +300 -0
  25. package/scripts/sync-scaffold-versions.mjs +91 -0
  26. package/templates/app-source/LICENSE +21 -0
  27. package/templates/app-source/src/ai-studio-core/ai-config.ts +100 -0
  28. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +338 -0
  29. package/templates/app-source/src/ai-studio-core/contexts.tsx +61 -0
  30. package/templates/app-source/src/ai-studio-core/history-policy.ts +447 -0
  31. package/templates/app-source/src/ai-studio-core/history.ts +824 -0
  32. package/templates/app-source/src/ai-studio-core/host-context.tsx +79 -0
  33. package/templates/app-source/src/ai-studio-core/index.ts +214 -0
  34. package/templates/app-source/src/ai-studio-core/messages/en.json +310 -0
  35. package/templates/app-source/src/ai-studio-core/messages/index.ts +47 -0
  36. package/templates/app-source/src/ai-studio-core/messages/zh.json +310 -0
  37. package/templates/app-source/src/ai-studio-core/module-registration.ts +109 -0
  38. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +65 -0
  39. package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +247 -0
  40. package/templates/app-source/src/ai-studio-core/parameters.ts +110 -0
  41. package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +69 -0
  42. package/templates/app-source/src/ai-studio-core/run-target.ts +123 -0
  43. package/templates/app-source/src/ai-studio-core/runtime-dispatcher.ts +35 -0
  44. package/templates/app-source/src/ai-studio-core/runtime-types.ts +86 -0
  45. package/templates/app-source/src/ai-studio-core/runtime.ts +306 -0
  46. package/templates/app-source/src/ai-studio-core/section-ai-testing-admission.ts +38 -0
  47. package/templates/app-source/src/ai-studio-core/section-ai-testing-ai-config.tsx +30 -0
  48. package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +40 -0
  49. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +257 -0
  50. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +676 -0
  51. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +19 -0
  52. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +291 -0
  53. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +413 -0
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +174 -0
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +449 -0
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +45 -0
  57. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +494 -0
  58. package/templates/app-source/src/ai-studio-core/studio-directives.ts +33 -0
  59. package/templates/app-source/src/ai-studio-core/workspace.tsx +381 -0
  60. package/templates/app-source/src/product-modules/agent-center/index.tsx +27 -0
  61. package/templates/app-source/src/product-modules/agent-conversation/index.tsx +19 -0
  62. package/templates/app-source/src/product-modules/agent-realtime/index.tsx +29 -0
  63. package/templates/app-source/src/product-modules/kit-recipes/gallery.tsx +142 -0
  64. package/templates/app-source/src/product-modules/kit-recipes/index.tsx +19 -0
  65. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-data-recipes.tsx +336 -0
  66. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-demos.tsx +165 -0
  67. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-recipes.tsx +682 -0
  68. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-surface.tsx +341 -0
  69. package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +26 -0
  70. package/templates/app-source/src/studio-modules/studio-create/index.ts +14 -0
  71. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +67 -0
  72. package/templates/app-source/src/studio-modules/studio-create/messages/index.ts +5 -0
  73. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +67 -0
  74. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +153 -0
  75. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +70 -0
  76. package/templates/app-source/src/studio-modules/studio-create/registration.ts +46 -0
  77. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +339 -0
  78. package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +22 -0
  79. package/templates/app-source/src/studio-modules/studio-media/index.ts +12 -0
  80. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +82 -0
  81. package/templates/app-source/src/studio-modules/studio-media/messages/index.ts +5 -0
  82. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +82 -0
  83. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +283 -0
  84. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +94 -0
  85. package/templates/app-source/src/studio-modules/studio-media/registration.ts +44 -0
  86. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +113 -0
  87. package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +28 -0
  88. package/templates/app-source/src/studio-modules/studio-voice/index.ts +16 -0
  89. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +99 -0
  90. package/templates/app-source/src/studio-modules/studio-voice/messages/index.ts +5 -0
  91. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +99 -0
  92. package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +284 -0
  93. package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +116 -0
  94. package/templates/app-source/src/studio-modules/studio-voice/registration.ts +59 -0
  95. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +347 -0
  96. package/templates/app-source/src/workbench-core/empty-state.tsx +31 -0
  97. package/templates/app-source/src/workbench-core/index.ts +17 -0
  98. package/templates/app-source/src/workbench-core/runtime-gate.tsx +131 -0
  99. package/templates/app-source/src/workbench-core/workbench-core.css +255 -0
  100. package/templates/app-source/src/workbench-core/workbench-core.tsx +140 -0
  101. package/templates/app-source.manifest.json +333 -0
  102. package/templates/default-starter/AGENTS.md +33 -0
  103. package/templates/default-starter/LICENSE +21 -0
  104. package/templates/default-starter/README.md +41 -0
  105. package/templates/default-starter/SECURITY.md +5 -0
  106. package/templates/default-starter/index.html +12 -0
  107. package/templates/default-starter/scripts/validate.mjs +26 -0
  108. package/templates/default-starter/src/shell/App.tsx +27 -0
  109. package/templates/default-starter/src/shell/auth/app-identity.ts +3 -0
  110. package/templates/default-starter/src/shell/auth/local-app-client.ts +18 -0
  111. package/templates/default-starter/src/shell/auth/runtime-platform.ts +110 -0
  112. package/templates/default-starter/src/shell/authenticated-shell.tsx +20 -0
  113. package/templates/default-starter/src/shell/workbench-target-adapter.ts +40 -0
  114. package/templates/default-starter/src/styles.css +26 -0
  115. package/templates/default-starter/src-tauri/Cargo.toml +17 -0
  116. package/templates/default-starter/src-tauri/build.rs +5 -0
  117. package/templates/default-starter/src-tauri/capabilities/default.json +7 -0
  118. package/templates/default-starter/src-tauri/tauri.conf.json +26 -0
  119. package/templates/default-starter/tsconfig.json +18 -0
  120. package/templates/default-starter.manifest.json +99 -0
@@ -0,0 +1,449 @@
1
+ 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';
4
+ import { useAIStudioHost } from './host-context.js';
5
+ import type { StudioCapabilityRunResult } from './runtime-types.js';
6
+ import type { StudioCapabilityDescriptor, StudioCapabilityRegistration } from './module-registration.js';
7
+ import { formatStudioRunTimestamp } from './history.js';
8
+ import { studioNonSuccessReasonUserAction, studioNonSuccessReasonUserMessage, type StudioTranslate } from './non-success-presentation.js';
9
+ import { countStudioWords } from './studio-directives.js';
10
+ import type { CapabilityStatus } from './section-ai-testing-admission.js';
11
+ import { ArtifactMediaResult, RuntimeDiagnosticsActions, formatTypedOutput, formatNonSuccessOutput, resultPlainText, TextStudioOutputBody } from './section-ai-testing-output.js';
12
+
13
+ // Readable body for a successful typed result (light surface), with structured
14
+ // summaries for embedding / voice-catalog rather than raw JSON (which moves to
15
+ // the Runtime details disclosure).
16
+ function ReadyBody({ result }: { result: StudioCapabilityRunResult & { ok: true } }) {
17
+ const { translate: t } = useAIStudioHost();
18
+ const output = result.output;
19
+ if (output.kind === 'text' || output.kind === 'transcript') {
20
+ return <TextStudioOutputBody text={output.text} />;
21
+ }
22
+ if (output.kind === 'artifacts') {
23
+ return (
24
+ <div className="studio-result__rich">
25
+ {output.artifacts.map((artifact, index) => (
26
+ <ArtifactMediaResult
27
+ key={artifact.relativePath}
28
+ artifact={artifact}
29
+ fallbackLabel={`${output.jobId}:${index + 1}`}
30
+ />
31
+ ))}
32
+ </div>
33
+ );
34
+ }
35
+ if (output.kind === 'embedding') {
36
+ return (
37
+ <div className="studio-result__rich">
38
+ <p className="studio-result__plain">{t('StudioShell.embeddingSuccess')}</p>
39
+ </div>
40
+ );
41
+ }
42
+ if (output.kind === 'voice-asset') {
43
+ return (
44
+ <div className="studio-result__rich">
45
+ <p className="studio-result__plain">{t('StudioShell.voiceAssetSuccess')}</p>
46
+ </div>
47
+ );
48
+ }
49
+ return (
50
+ <ul className="studio-voice-list">
51
+ {output.sample.map((voice) => (
52
+ <li key={voice.voiceId}>
53
+ <strong>{voice.voiceId}</strong>
54
+ <span>{voice.creationSource} / {voice.status}</span>
55
+ </li>
56
+ ))}
57
+ {output.sample.length === 0 ? <li><span>{t('StudioShell.noVoices')}</span></li> : null}
58
+ </ul>
59
+ );
60
+ }
61
+
62
+ // Runtime details disclosure shared by every AI Studio host.
63
+ // (runtime method id, admission detail, typed JSON, trace) beneath the product
64
+ // result view. Blockers are returned as typed unavailable results, surfaced here.
65
+ // The exported text stays English: it is a machine-oriented diagnostic dump.
66
+ function formatRuntimeDetailsExport({
67
+ registration,
68
+ result,
69
+ admission,
70
+ verboseConsole,
71
+ translate,
72
+ }: {
73
+ registration: StudioCapabilityRegistration;
74
+ result: StudioCapabilityRunResult | null;
75
+ admission: CapabilityStatus;
76
+ verboseConsole: boolean;
77
+ translate: StudioTranslate;
78
+ }): string {
79
+ const capability = registration.descriptor;
80
+ const lines = [
81
+ 'Runtime details',
82
+ '',
83
+ `Capability: ${capability.id}`,
84
+ `Method: ${registration.runtimeMethod}`,
85
+ `Admission: ${admission.detail}`,
86
+ ];
87
+ if (result && !result.ok) {
88
+ lines.push(`Reason: ${result.reason}`);
89
+ }
90
+ if (result?.ok && result.trace?.traceId) {
91
+ lines.push(`Trace: ${result.trace.traceId}`);
92
+ }
93
+ if (result) {
94
+ lines.push('', result.ok ? 'Output:' : 'Diagnostics:', result.ok ? formatTypedOutput(result, translate) : formatNonSuccessOutput(result, translate));
95
+ }
96
+ if (verboseConsole) {
97
+ lines.push('', `Verbose console: capability ${capability.id}; ${result ? (result.ok ? 'typed success' : `fail-closed ${result.reason}`) : 'no current-session result'}.`);
98
+ }
99
+ return lines.join('\n');
100
+ }
101
+
102
+ function RuntimeDetails({
103
+ registration,
104
+ result,
105
+ admission,
106
+ verboseConsole,
107
+ }: {
108
+ registration: StudioCapabilityRegistration;
109
+ result: StudioCapabilityRunResult | null;
110
+ admission: CapabilityStatus;
111
+ verboseConsole: boolean;
112
+ }) {
113
+ const { translate: t } = useAIStudioHost();
114
+ const capability = registration.descriptor;
115
+ const diagnosticsText = result && !result.ok ? formatNonSuccessOutput(result, t) : '';
116
+ const runtimeDetailsText = formatRuntimeDetailsExport({ registration, result, admission, verboseConsole, translate: t });
117
+ return (
118
+ <details className="studio-diag">
119
+ <summary>{t('StudioShell.runtimeDetails')}</summary>
120
+ <RuntimeDiagnosticsActions text={runtimeDetailsText} filenameBase={capability.id} />
121
+ <dl className="studio-diag__grid">
122
+ <div>
123
+ <dt>{t('Studio.result.methodLabel')}</dt>
124
+ <dd><code>{registration.runtimeMethod}</code></dd>
125
+ </div>
126
+ <div>
127
+ <dt>{t('Studio.result.admissionLabel')}</dt>
128
+ <dd>{admission.detail}</dd>
129
+ </div>
130
+ {result && !result.ok ? (
131
+ <div>
132
+ <dt>{t('Studio.result.reasonLabel')}</dt>
133
+ <dd>{result.reason}</dd>
134
+ </div>
135
+ ) : null}
136
+ {result?.ok && result.trace?.traceId ? (
137
+ <div>
138
+ <dt>{t('Studio.result.traceLabel')}</dt>
139
+ <dd><code>{result.trace.traceId}</code></dd>
140
+ </div>
141
+ ) : null}
142
+ </dl>
143
+ {result ? <pre className="studio-diag__json">{result.ok ? formatTypedOutput(result, t) : diagnosticsText}</pre> : null}
144
+ {verboseConsole ? (
145
+ <p className="studio-diag__note">
146
+ {t('Studio.result.verboseConsoleNote', {
147
+ capability: capability.id,
148
+ state: result
149
+ ? (result.ok
150
+ ? t('Studio.result.verboseTypedSuccess')
151
+ : t('Studio.result.verboseFailClosed', { reason: result.reason }))
152
+ : t('Studio.result.verboseNoResult'),
153
+ })}
154
+ </p>
155
+ ) : null}
156
+ </details>
157
+ );
158
+ }
159
+
160
+ type StudioResultStat = {
161
+ label: string;
162
+ value: string;
163
+ };
164
+
165
+ function studioResultIntentLabel(result: StudioCapabilityRunResult | null, capability: StudioCapabilityDescriptor, preferredLabel: string | undefined, translate: (key: string) => string): string {
166
+ const preferred = preferredLabel?.trim();
167
+ if (preferred) return preferred;
168
+ if (result && !result.ok) return translate('Studio.result.sdkUnavailable');
169
+ return translate(capability.labelKey);
170
+ }
171
+
172
+ export function StudioResult({
173
+ result,
174
+ running,
175
+ cancelRequested,
176
+ registration,
177
+ admission,
178
+ createdAt,
179
+ intentLabel,
180
+ requestSettings,
181
+ streamingText,
182
+ verboseConsole,
183
+ onCopy,
184
+ onDownload,
185
+ onRegenerate,
186
+ onCancel,
187
+ }: {
188
+ result: StudioCapabilityRunResult | null;
189
+ running: boolean;
190
+ cancelRequested: boolean;
191
+ registration: StudioCapabilityRegistration;
192
+ admission: CapabilityStatus;
193
+ createdAt?: string;
194
+ intentLabel?: string;
195
+ requestSettings?: ReactNode;
196
+ streamingText?: string | null;
197
+ verboseConsole: boolean;
198
+ onCopy: () => void;
199
+ onDownload: () => void;
200
+ onRegenerate: () => void;
201
+ onCancel?: () => void;
202
+ }) {
203
+ const rendererHost = useAIStudioHost();
204
+ const t = rendererHost.translate;
205
+ const capability = registration.descriptor;
206
+ const profile = registration.profile;
207
+ const ready = result?.ok ? result : null;
208
+ const operationAborted = result && !result.ok && result.reason === 'operation-aborted' ? result : null;
209
+ const canceled = result && !result.ok && result.reason === 'runtime-canceled' ? result : null;
210
+ const timedOut = result && !result.ok && result.reason === 'runtime-timeout' ? result : null;
211
+ const blocked = result && !result.ok
212
+ && result.reason !== 'runtime-canceled'
213
+ && result.reason !== 'operation-aborted'
214
+ && result.reason !== 'runtime-timeout' ? result : null;
215
+ const plainText = ready ? resultPlainText(ready, t) : '';
216
+ const canExport = Boolean(ready && plainText);
217
+ const revealsManagedAsset = ready?.output.kind === 'artifacts';
218
+ const displayIntentLabel = studioResultIntentLabel(result, capability, intentLabel, t);
219
+ const [requestSettingsOpen, setRequestSettingsOpen] = useState(false);
220
+ const hasRequestSettings = Boolean(requestSettings);
221
+ const runTimeLabel = createdAt
222
+ ? formatStudioRunTimestamp(createdAt, new Date(rendererHost.clock.now()))
223
+ : running ? t('Studio.result.statRunning') : t('Studio.result.notRecorded');
224
+ const statusTitleKey = cancelRequested ? 'stopping' : running ? 'runtimeRunning' : operationAborted ? 'operationAborted' : canceled ? 'runtimeCanceled' : timedOut ? 'runtimeTimedOut' : blocked ? 'runtimeBlocked' : ready ? 'runtimeResult' : 'runtimeWaiting';
225
+ const statusTitle = t(`Studio.result.status.${statusTitleKey}`);
226
+ const statusTone = blocked || operationAborted || canceled || timedOut ? 'warning' : ready ? 'success' : running ? 'info' : 'neutral';
227
+ useEffect(() => {
228
+ if (!hasRequestSettings) setRequestSettingsOpen(false);
229
+ }, [hasRequestSettings]);
230
+
231
+ function formatStudioTokenCount(inputTokens?: number, outputTokens?: number, totalTokens?: number): string {
232
+ if (typeof totalTokens === 'number') return String(totalTokens);
233
+ if (typeof inputTokens === 'number' && typeof outputTokens === 'number') return String(inputTokens + outputTokens);
234
+ return t('Studio.result.tokensNotCaptured');
235
+ }
236
+
237
+ function studioResultStats(fallbackMetric: string): StudioResultStat[] {
238
+ if (running) return [{ label: t('Studio.result.statStatus'), value: t(cancelRequested ? 'Studio.result.statStopping' : 'Studio.result.statRunning') }];
239
+ if (!result) return [{ label: t('Studio.result.statStatus'), value: t('Studio.result.statWaiting') }];
240
+ if (!result.ok) return [{
241
+ label: t('Studio.result.statStatus'),
242
+ value: t(result.reason === 'operation-aborted'
243
+ ? 'Studio.result.statStopped'
244
+ : result.reason === 'runtime-canceled'
245
+ ? 'Studio.result.statCanceled'
246
+ : result.reason === 'runtime-timeout'
247
+ ? 'Studio.result.statTimedOut'
248
+ : 'Studio.result.statBlocked'),
249
+ }];
250
+ const output = result.output;
251
+ if (output.kind === 'text') {
252
+ const tokenCount = formatStudioTokenCount(output.inputTokens, output.outputTokens, output.totalTokens);
253
+ return [
254
+ ...(tokenCount === t('Studio.result.tokensNotCaptured') ? [] : [{ label: t('Studio.result.statTokens'), value: tokenCount }]),
255
+ { label: t('Studio.result.statCharacters'), value: String(output.text.length) },
256
+ ];
257
+ }
258
+ if (output.kind === 'transcript') {
259
+ return [
260
+ { label: t('Studio.result.statCharacters'), value: String(output.text.length) },
261
+ { label: t('Studio.result.statArtifacts'), value: String(output.artifactCount) },
262
+ ];
263
+ }
264
+ if (output.kind === 'embedding') {
265
+ return [{ label: t('Studio.result.statResult'), value: t('Studio.result.statCreated') }];
266
+ }
267
+ if (output.kind === 'artifacts') {
268
+ return [
269
+ { label: t('Studio.result.statArtifacts'), value: String(output.artifactCount) },
270
+ { label: t('Studio.result.statState'), value: output.jobState === 'COMPLETED' ? t('Studio.result.statCompleted') : output.jobState || t('Studio.result.stateUnknown') },
271
+ ];
272
+ }
273
+ if (output.kind === 'voice-asset') {
274
+ return [
275
+ { label: t('Studio.result.statState'), value: t('Studio.result.statAvailable') },
276
+ { label: t('Studio.result.statResult'), value: t(output.creationSource === 'text-description' ? 'Studio.result.createdFromDescription' : 'Studio.result.createdFromAudio') },
277
+ ];
278
+ }
279
+ return [
280
+ { label: t('Studio.result.statVoices'), value: String(output.voiceCount) },
281
+ { label: t('Studio.result.statResult'), value: fallbackMetric },
282
+ ];
283
+ }
284
+
285
+ let metric = '-';
286
+ if (ready) {
287
+ const output = ready.output;
288
+ if (output.kind === 'text' || output.kind === 'transcript') metric = t('Studio.result.metricWords', { count: countStudioWords(output.text) });
289
+ else if (output.kind === 'artifacts') metric = t('Studio.result.metricArtifacts', { count: output.artifactCount });
290
+ else if (output.kind === 'embedding') metric = t('Studio.result.metricCreated');
291
+ else if (output.kind === 'voice-asset') metric = output.creationSource;
292
+ else metric = t('Studio.result.metricVoices', { count: output.voiceCount });
293
+ }
294
+ const stats = studioResultStats(metric);
295
+
296
+ let body: ReactNode;
297
+ if (running) {
298
+ const hasStream = typeof streamingText === 'string';
299
+ body = (
300
+ <div className="studio-result__pending">
301
+ <div className="studio-result__pending-line">
302
+ <Loader2 size={15} aria-hidden="true" className="studio-spin" />
303
+ <span>{cancelRequested
304
+ ? t('Studio.result.pendingCancel')
305
+ : profile.pendingLabelKey
306
+ ? t(profile.pendingLabelKey)
307
+ : hasStream ? t('Studio.result.pendingStreaming') : t('Studio.result.pendingRuntime')}</span>
308
+ </div>
309
+ {hasStream ? <div className="studio-result__text studio-result__text--stream" aria-live="polite">{streamingText || '...'}</div> : null}
310
+ </div>
311
+ );
312
+ } else if (operationAborted) {
313
+ body = (
314
+ <div className="studio-result__blocked">
315
+ <div className="studio-result__blocked-line">
316
+ <Clock size={15} aria-hidden="true" />
317
+ <span>{statusTitle}</span>
318
+ </div>
319
+ <p>{studioNonSuccessReasonUserMessage(operationAborted.reason, t)}</p>
320
+ <p className="studio-result__hint">{studioNonSuccessReasonUserAction(operationAborted.reason, t)}</p>
321
+ </div>
322
+ );
323
+ } else if (canceled) {
324
+ body = (
325
+ <div className="studio-result__blocked">
326
+ <div className="studio-result__blocked-line">
327
+ <Clock size={15} aria-hidden="true" />
328
+ <span>{t('StudioShell.generationCanceled')}</span>
329
+ </div>
330
+ <p>{studioNonSuccessReasonUserMessage(canceled.reason, t)}</p>
331
+ <p className="studio-result__hint">{studioNonSuccessReasonUserAction(canceled.reason, t)}</p>
332
+ </div>
333
+ );
334
+ } else if (timedOut) {
335
+ body = (
336
+ <div className="studio-result__blocked">
337
+ <div className="studio-result__blocked-line">
338
+ <Clock size={15} aria-hidden="true" />
339
+ <span>{statusTitle}</span>
340
+ </div>
341
+ <p>{studioNonSuccessReasonUserMessage(timedOut.reason, t)}</p>
342
+ <p className="studio-result__hint">{studioNonSuccessReasonUserAction(timedOut.reason, t)}</p>
343
+ </div>
344
+ );
345
+ } else if (blocked) {
346
+ body = (
347
+ <div className="studio-result__blocked">
348
+ <div className="studio-result__blocked-line">
349
+ <AlertTriangle size={15} aria-hidden="true" />
350
+ <span>{t('StudioShell.generationFailed')}</span>
351
+ </div>
352
+ <p>{studioNonSuccessReasonUserMessage(blocked.reason, t)}</p>
353
+ <p className="studio-result__hint">{studioNonSuccessReasonUserAction(blocked.reason, t)}</p>
354
+ </div>
355
+ );
356
+ } else if (ready) {
357
+ body = <ReadyBody result={ready} />;
358
+ } else {
359
+ body = (
360
+ <EmptyState
361
+ className="studio-empty"
362
+ icon={<FileText size={18} aria-hidden="true" />}
363
+ title={t(profile.emptyTitleKey)}
364
+ description={t(profile.emptyHintKey)}
365
+ />
366
+ );
367
+ }
368
+
369
+ return (
370
+ <Surface className="studio-result" material="glass-regular" tone="panel" elevation="floating" padding="none">
371
+ <div className="studio-result__top">
372
+ <div className="studio-result__identity">
373
+ <StatusBadge
374
+ tone={statusTone}
375
+ shape="soft"
376
+ className="grid h-11 w-11 place-items-center rounded-[var(--nimi-radius-md)] p-0"
377
+ aria-hidden="true"
378
+ >
379
+ <Sparkles size={20} />
380
+ </StatusBadge>
381
+ <span className="studio-result__title-stack">
382
+ <strong>{statusTitle}</strong>
383
+ <span className="studio-result__time">
384
+ <Clock size={14} aria-hidden="true" />
385
+ <time dateTime={createdAt}>{t('Studio.result.runTimeLabel', { time: runTimeLabel })}</time>
386
+ </span>
387
+ </span>
388
+ </div>
389
+ <div className="studio-result__actions">
390
+ {running && onCancel ? (
391
+ <Tooltip content={t(cancelRequested ? 'StudioShell.cancelRequested' : 'StudioShell.cancelGeneration')} placement="top">
392
+ <IconButton type="button" className="studio-result__action" onClick={onCancel} disabled={cancelRequested} aria-label={t(cancelRequested ? 'StudioShell.cancelRequested' : 'StudioShell.cancelGeneration')} icon={<Square size={14} aria-hidden="true" />} />
393
+ </Tooltip>
394
+ ) : null}
395
+ {!blocked && !canceled ? (
396
+ <>
397
+ <Tooltip content={t('Common.copy')} placement="top">
398
+ <IconButton type="button" className="studio-result__action" onClick={onCopy} disabled={!canExport} aria-label={t('StudioShell.copyGeneration')} icon={<CopyIcon size={15} aria-hidden="true" />} />
399
+ </Tooltip>
400
+ <Tooltip content={t(revealsManagedAsset ? 'StudioShell.revealAsset' : 'StudioShell.download')} placement="top">
401
+ <IconButton type="button" className="studio-result__action" onClick={onDownload} disabled={!canExport} aria-label={t(revealsManagedAsset ? 'StudioShell.revealGeneration' : 'StudioShell.downloadGeneration')} icon={revealsManagedAsset ? <FolderOpen size={15} aria-hidden="true" /> : <DownloadIcon size={15} aria-hidden="true" />} />
402
+ </Tooltip>
403
+ </>
404
+ ) : null}
405
+ <Tooltip content={t('StudioShell.regenerate')} placement="top">
406
+ <IconButton type="button" className="studio-result__action" onClick={onRegenerate} disabled={running} aria-label={t('StudioShell.regenerate')} icon={<RefreshCw size={15} aria-hidden="true" />} />
407
+ </Tooltip>
408
+ </div>
409
+ </div>
410
+ <div className="studio-result__meta">
411
+ <StatusBadge tone={statusTone} shape="soft" className="min-h-[30px] shrink-0 gap-[7px] px-3 text-sm font-[var(--nimi-type-page-title-weight)]">
412
+ <Sparkles size={14} aria-hidden="true" />
413
+ <span>{t('Studio.result.runtimeChip')}</span>
414
+ </StatusBadge>
415
+ <div className="studio-result__stats studio-result__stats--top" aria-label={t('Studio.result.generationMetrics')}>
416
+ {stats.map((stat) => (
417
+ <span key={stat.label} className="studio-result__metric">
418
+ <strong>{stat.value}</strong>
419
+ <span>{stat.label}</span>
420
+ </span>
421
+ ))}
422
+ </div>
423
+ <div className="studio-result__intent-pill">
424
+ <span>{t('StudioShell.intentLabel')}</span>
425
+ <div className={hasRequestSettings ? 'studio-intent-pill__box' : 'studio-intent-pill__box studio-intent-pill__box--static'}>
426
+ <Tooltip content={displayIntentLabel} placement="top" className="min-w-0">
427
+ <strong>{displayIntentLabel}</strong>
428
+ </Tooltip>
429
+ {hasRequestSettings ? (
430
+ <Tooltip content={requestSettingsOpen ? t('StudioShell.hideRequestSettings') : t('StudioShell.showRequestSettings')} placement="top">
431
+ <IconButton
432
+ type="button"
433
+ className={requestSettingsOpen ? 'studio-intent-pill__trigger studio-intent-pill__trigger--open' : 'studio-intent-pill__trigger'}
434
+ aria-label={requestSettingsOpen ? t('StudioShell.hideRequestSettings') : t('StudioShell.showRequestSettings')}
435
+ aria-expanded={requestSettingsOpen}
436
+ onClick={() => setRequestSettingsOpen((value) => !value)}
437
+ icon={<ChevronRight size={15} aria-hidden="true" />}
438
+ />
439
+ </Tooltip>
440
+ ) : null}
441
+ </div>
442
+ </div>
443
+ </div>
444
+ {requestSettingsOpen && requestSettings ? requestSettings : null}
445
+ <div className="studio-result__body">{body}</div>
446
+ <RuntimeDetails registration={registration} result={result} admission={admission} verboseConsole={verboseConsole} />
447
+ </Surface>
448
+ );
449
+ }
@@ -0,0 +1,45 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ import type { StudioCapabilityRegistration } from './module-registration.js';
4
+ import type { StudioCapabilityRunResult, StudioRuntimeInspection } from './runtime-types.js';
5
+ import type { StudioRunConfigSnapshot, StudioRunHistory, StudioRunHistoryRecord } from './history.js';
6
+
7
+ export { statusForCapability } from './section-ai-testing-admission.js';
8
+ export type { CapabilityStatus } from './section-ai-testing-admission.js';
9
+ export { CapabilityRunHistory } from './section-ai-testing-history.js';
10
+ export { DrawerErrorBoundary } from './section-ai-testing-ai-config.js';
11
+ export {
12
+ ArtifactMediaPreview,
13
+ ArtifactMediaResult,
14
+ RuntimeDiagnosticsActions,
15
+ TextStudioOutputBody,
16
+ downloadTextFile,
17
+ hasPreviewableArtifact,
18
+ resultPlainText,
19
+ } from './section-ai-testing-output.js';
20
+ export { StudioResult } from './section-ai-testing-studio-result.js';
21
+
22
+ export type StudioAIConfigPanelRenderInput = {
23
+ readonly runtime: StudioRuntimeInspection | null;
24
+ readonly capabilityId: string;
25
+ };
26
+
27
+ export type SectionAITestingProps = {
28
+ readonly registration: StudioCapabilityRegistration;
29
+ readonly registrations: readonly StudioCapabilityRegistration[];
30
+ readonly runtime: StudioRuntimeInspection | null;
31
+ readonly onResult: (
32
+ result: StudioCapabilityRunResult,
33
+ prompt: string,
34
+ runConfig?: StudioRunConfigSnapshot,
35
+ ) => StudioRunHistoryRecord | null | Promise<StudioRunHistoryRecord | null>;
36
+ readonly history: StudioRunHistory | null;
37
+ readonly lastResult: StudioCapabilityRunResult | null;
38
+ readonly historySelectionRequest: { requestId: number; record: StudioRunHistoryRecord } | null;
39
+ readonly onSelectHistoryRun: (record: StudioRunHistoryRecord) => void;
40
+ readonly verboseConsole: boolean;
41
+ readonly draftPersistence: boolean;
42
+ readonly headerActions?: ReactNode;
43
+ readonly renderAIConfigPanel?: (input: StudioAIConfigPanelRenderInput) => ReactNode;
44
+ readonly rootTestId?: string;
45
+ };