@nimiplatform/app-tools 0.13.1 → 0.16.0-rc.9
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.
- package/README.md +65 -8
- package/bin/nimi-app.mjs +26 -10
- package/lib/app-access-declaration.mjs +3 -0
- package/lib/app-dependency-combinations.mjs +70 -20
- package/lib/app-doctor-update.mjs +95 -36
- package/lib/app-host-support.mjs +6 -0
- package/lib/app-icons.mjs +181 -0
- package/lib/app-identifiers.mjs +27 -0
- package/lib/app-info.mjs +21 -33
- package/lib/app-lifecycle-guidance.mjs +2 -1
- package/lib/app-pack.mjs +14 -36
- package/lib/app-project-lifecycle.mjs +141 -243
- package/lib/app-scaffold-capabilities.mjs +13 -109
- package/lib/app-scaffold-profiles.mjs +108 -117
- package/lib/app-scaffold.mjs +70 -165
- package/lib/app-toolchain-updates.mjs +45 -0
- package/lib/canonical-capability-ids.generated.mjs +2 -0
- package/lib/development-environment.d.mts +10 -0
- package/lib/development-environment.mjs +39 -0
- package/lib/hosted-web-release.mjs +98 -0
- package/lib/index.mjs +40 -1
- package/lib/mobile-development.mjs +19 -0
- package/lib/realm-environments.generated.mjs +5 -0
- package/lib/web-coordination.mjs +59 -0
- package/lib/web-development.d.mts +23 -0
- package/lib/web-development.mjs +118 -0
- package/lib/web-scaffold.mjs +125 -0
- package/package.json +39 -27
- package/scripts/dev-shell.mjs +4 -1
- package/scripts/sync-scaffold-versions.mjs +0 -2
- package/skills/nimi-app-lifecycle/SKILL.md +13 -5
- package/skills/nimi-app-lifecycle/references/acceptance.md +6 -2
- package/skills/nimi-app-lifecycle/references/adapt.md +7 -3
- package/skills/nimi-app-lifecycle/references/audit.md +3 -2
- package/skills/nimi-app-lifecycle/references/create.md +8 -2
- package/skills/nimi-app-lifecycle/references/release.md +2 -0
- package/skills/nimi-app-lifecycle/references/upgrade-platform.md +15 -1
- package/templates/app-source/src/ai-studio-core/ai-studio-core.css +87 -52
- package/templates/app-source/src/ai-studio-core/history-policy.ts +45 -11
- package/templates/app-source/src/ai-studio-core/history.ts +22 -11
- package/templates/app-source/src/ai-studio-core/host-context.tsx +9 -4
- package/templates/app-source/src/ai-studio-core/index.ts +2 -0
- package/templates/app-source/src/ai-studio-core/job-recovery-panel.tsx +15 -5
- package/templates/app-source/src/ai-studio-core/job-recovery.ts +2 -2
- package/templates/app-source/src/ai-studio-core/messages/en.json +79 -19
- package/templates/app-source/src/ai-studio-core/messages/zh.json +79 -19
- package/templates/app-source/src/ai-studio-core/module-registration.ts +1 -0
- package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +40 -5
- package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +12 -6
- package/templates/app-source/src/ai-studio-core/parameters.ts +4 -0
- package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +42 -0
- package/templates/app-source/src/ai-studio-core/runtime-types.ts +9 -2
- package/templates/app-source/src/ai-studio-core/runtime.ts +8 -4
- package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +98 -90
- package/templates/app-source/src/ai-studio-core/section-ai-testing-exchange-result.tsx +1 -1
- package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +205 -48
- package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +1 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +36 -14
- package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +102 -77
- package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +62 -16
- package/templates/app-source/src/ai-studio-core/section-ai-testing-session-result.tsx +2 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +12 -21
- package/templates/app-source/src/ai-studio-core/section-ai-testing-transcription-result.tsx +26 -9
- package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +3 -3
- package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +182 -81
- package/templates/app-source/src/ai-studio-core/workspace.tsx +49 -22
- package/templates/app-source/src/product-modules/agent-center/index.tsx +2 -3
- package/templates/app-source/src/product-modules/agent-conversation/index.tsx +2 -3
- package/templates/app-source/src/studio-modules/studio-create/messages/en.json +17 -3
- package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +17 -3
- package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +33 -1
- package/templates/app-source/src/studio-modules/studio-create/parameters.ts +3 -1
- package/templates/app-source/src/studio-modules/studio-create/runtime.ts +47 -4
- package/templates/app-source/src/studio-modules/studio-media/messages/en.json +59 -8
- package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +59 -8
- package/templates/app-source/src/studio-modules/studio-media/music-parameters.tsx +2 -1
- package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +271 -83
- package/templates/app-source/src/studio-modules/studio-media/parameters.ts +120 -2
- package/templates/app-source/src/studio-modules/studio-media/registration.ts +1 -0
- package/templates/app-source/src/studio-modules/studio-media/runtime.ts +24 -14
- package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +1 -1
- package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +3 -2
- package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +3 -2
- package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +46 -23
- package/templates/app-source/src/studio-modules/studio-voice/registration.ts +2 -1
- package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +2 -2
- package/templates/app-source/src/workbench-core/workbench-core.tsx +27 -3
- package/templates/default-starter/AGENTS.md +8 -5
- package/templates/default-starter/NIMI_APP.md +7 -0
- package/templates/default-starter/README.md +3 -1
- package/templates/default-starter/src/shell/App.tsx +12 -20
- package/templates/default-starter/src/shell/auth/local-app-client.ts +6 -15
- package/templates/default-starter/src/shell/auth/runtime-platform.ts +7 -107
- package/templates/default-starter/src/shell/workbench-target-adapter.ts +9 -126
- package/templates/default-starter.manifest.json +4 -16
- package/templates/hosted-web-release.yml +88 -0
- package/templates/default-starter/src-tauri/Cargo.toml +0 -17
- package/templates/default-starter/src-tauri/build.rs +0 -32
- package/templates/default-starter/src-tauri/capabilities/default.json +0 -7
- package/templates/default-starter/src-tauri/tauri.conf.json +0 -26
|
@@ -8,17 +8,17 @@ import { SpeechTranscriptResultView } from './section-ai-testing-transcript-resu
|
|
|
8
8
|
import { TextExchangeResultView } from './section-ai-testing-exchange-result.js';
|
|
9
9
|
import { TextDecisionResultView } from './section-ai-testing-decision-result.js';
|
|
10
10
|
import { FaceSwapNotice, SessionSummaryView } from './section-ai-testing-session-result.js';
|
|
11
|
-
import {
|
|
11
|
+
import { useEffect, useRef, type ReactNode } from 'react';
|
|
12
12
|
import { IconButton, nimiToast, StatusBadge, Tooltip } from '@nimiplatform/kit/ui';
|
|
13
|
-
import { AlertTriangle,
|
|
13
|
+
import { AlertTriangle, Copy as CopyIcon, Download as DownloadIcon, FileText, FolderOpen, MessageSquare, RefreshCw, SlidersHorizontal, SquarePen } from 'lucide-react';
|
|
14
14
|
import { useAIStudioHost } from './host-context.js';
|
|
15
15
|
import { VisionLocateResultView } from './section-ai-testing-vision-result.js';
|
|
16
16
|
import type { StudioCapabilityRegistration } from './module-registration.js';
|
|
17
|
-
import { getStudioRunHistoryExportText, formatStudioRunTimestamp, getStudioRunConfigParamRows,
|
|
18
|
-
import { studioNonSuccessReasonTitle, studioNonSuccessReasonUserAction, studioNonSuccessReasonUserMessage } from './non-success-presentation.js';
|
|
17
|
+
import { getStudioRunHistoryExportText, formatStudioRunTimestamp, getStudioRunConfigParamRows, getStudioRunPromptControlFacts, getStudioRunResultTags, getStudioRunStatusTone, type StudioRunConfigParamRow, type StudioRunHistoryRecord, type StudioRunHistoryResultSnapshot, type StudioRunPromptControlFact } from './history.js';
|
|
18
|
+
import { studioNonSuccessReasonTitle, studioNonSuccessReasonUserAction, studioNonSuccessReasonUserMessage, studioTerminalStatusKey } from './non-success-presentation.js';
|
|
19
19
|
import { ArtifactMediaPreview, ArtifactMediaResult, RuntimeDiagnosticsActions, StudioResult, TextStudioOutputBody, downloadTextFile, statusForCapability } from './section-ai-testing-surface.js';
|
|
20
|
-
import { EmbeddingResultBody, SpeakerEmbeddingResultBody, KnownJobNotice,
|
|
21
|
-
import type
|
|
20
|
+
import { EmbeddingResultBody, SpeakerEmbeddingResultBody, KnownJobNotice, exportStudioAsset } from './section-ai-testing-output.js';
|
|
21
|
+
import { studioConfiguredTargetLabel, type TextStudioActiveRun } from './section-ai-testing-run.js';
|
|
22
22
|
|
|
23
23
|
function TextStudioPromptControlFacts({ facts }: { facts: readonly StudioRunPromptControlFact[] }) {
|
|
24
24
|
if (facts.length === 0) return null;
|
|
@@ -69,16 +69,13 @@ function groupParamRows(rows: readonly StudioRunConfigParamRow[]): Array<{ group
|
|
|
69
69
|
function TextStudioRequestSettings({ record }: { record: StudioRunHistoryRecord }) {
|
|
70
70
|
const { translate: t } = useAIStudioHost();
|
|
71
71
|
const runConfig = record.runConfig;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
return null;
|
|
80
|
-
}
|
|
81
|
-
const paramGroups = groupParamRows(paramRows);
|
|
72
|
+
const target = runConfig?.target;
|
|
73
|
+
const paramGroups = runConfig ? groupParamRows(getStudioRunConfigParamRows(runConfig)) : [];
|
|
74
|
+
const defaults = runConfig && target?.configuredDefaults
|
|
75
|
+
? getStudioRunConfigParamRows(runConfig, target.configuredDefaults) : [];
|
|
76
|
+
const snapshot = record.result;
|
|
77
|
+
const jobId = snapshot && 'jobId' in snapshot ? snapshot.jobId : undefined;
|
|
78
|
+
const traceId = runConfig?.traceId ?? (snapshot?.ok ? snapshot.traceId : snapshot?.diagnostics?.traceId);
|
|
82
79
|
|
|
83
80
|
return (
|
|
84
81
|
<section className="studio-history-settings" aria-label={t('StudioShell.requestSettings')}>
|
|
@@ -86,6 +83,30 @@ function TextStudioRequestSettings({ record }: { record: StudioRunHistoryRecord
|
|
|
86
83
|
<SlidersHorizontal size={14} aria-hidden="true" />
|
|
87
84
|
<strong>{t('StudioShell.requestSettings')}</strong>
|
|
88
85
|
</div>
|
|
86
|
+
<dl className="studio-history-settings__params">
|
|
87
|
+
<div>
|
|
88
|
+
<dt>{t('StudioShell.intentLabel')}</dt>
|
|
89
|
+
<dd>
|
|
90
|
+
{target ? studioConfiguredTargetLabel(target, t) : t('History.compareUnknown')}
|
|
91
|
+
{target && !target.targetLabel ? ` · ${t('StudioShell.modelNotRecorded')}` : null}
|
|
92
|
+
{target?.targetRef && target.targetRef !== target.targetLabel ? <><br /><code>{target.targetRef}</code></> : null}
|
|
93
|
+
</dd>
|
|
94
|
+
</div>
|
|
95
|
+
{jobId ? <div><dt>{t('Studio.result.jobLabel')}</dt><dd><code>{jobId}</code></dd></div> : null}
|
|
96
|
+
{traceId ? <div><dt>{t('Studio.result.traceLabel')}</dt><dd><code>{traceId}</code></dd></div> : null}
|
|
97
|
+
</dl>
|
|
98
|
+
<p className="studio-result__hint">{t('StudioShell.recordedConfigScope')}</p>
|
|
99
|
+
{paramGroups.length === 0 ? <p className="studio-result__hint">
|
|
100
|
+
{target?.paramsSummary.join(' / ') || t(runConfig ? 'History.compareNoParameters' : 'StudioShell.parametersNotRecorded')}
|
|
101
|
+
</p> : null}
|
|
102
|
+
{defaults.length ? (
|
|
103
|
+
<div className="studio-history-settings__group">
|
|
104
|
+
<strong className="studio-history-settings__group-title">{t('StudioShell.configuredDefaults')}</strong>
|
|
105
|
+
<dl className="studio-history-settings__params">
|
|
106
|
+
{defaults.map((row) => <div key={row.key}><dt>{row.label}</dt><dd>{row.value}</dd></div>)}
|
|
107
|
+
</dl>
|
|
108
|
+
</div>
|
|
109
|
+
) : null}
|
|
89
110
|
{paramGroups.map((group) => (
|
|
90
111
|
<div key={group.group} className="studio-history-settings__group">
|
|
91
112
|
<strong className="studio-history-settings__group-title">{group.group}</strong>
|
|
@@ -103,12 +124,6 @@ function TextStudioRequestSettings({ record }: { record: StudioRunHistoryRecord
|
|
|
103
124
|
);
|
|
104
125
|
}
|
|
105
126
|
|
|
106
|
-
function hasTextStudioRequestSettings(record: StudioRunHistoryRecord): boolean {
|
|
107
|
-
const runConfig = record.runConfig;
|
|
108
|
-
if (!runConfig) return false;
|
|
109
|
-
return getStudioRunConfigParamRows(runConfig).length > 0 || Boolean(runConfig.target.paramsSummary.join(' / '));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
127
|
function historyNonSuccessDiagnosticsText(snapshot: Extract<StudioRunHistoryResultSnapshot, { ok: false }>): string {
|
|
113
128
|
return [
|
|
114
129
|
`Reason: ${snapshot.reason}`,
|
|
@@ -138,12 +153,14 @@ function TextStudioHistoryRecordResult({
|
|
|
138
153
|
registration,
|
|
139
154
|
record,
|
|
140
155
|
canRegenerate,
|
|
156
|
+
canRestoreInputs,
|
|
141
157
|
onRegenerate,
|
|
142
158
|
onUseAsDraft,
|
|
143
159
|
}: {
|
|
144
160
|
registration: StudioCapabilityRegistration;
|
|
145
161
|
record: StudioRunHistoryRecord;
|
|
146
162
|
canRegenerate: boolean;
|
|
163
|
+
canRestoreInputs: boolean;
|
|
147
164
|
onRegenerate: () => void;
|
|
148
165
|
onUseAsDraft: (record: StudioRunHistoryRecord) => void;
|
|
149
166
|
}) {
|
|
@@ -152,15 +169,15 @@ function TextStudioHistoryRecordResult({
|
|
|
152
169
|
const snapshot = record.result;
|
|
153
170
|
const HistoryActions = registration.historyActions;
|
|
154
171
|
const blocked = snapshot && !snapshot.ok ? snapshot : null;
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
?
|
|
160
|
-
:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const intentLabel =
|
|
172
|
+
const statusLabel = snapshot || record.status === 'ready'
|
|
173
|
+
? t(studioTerminalStatusKey(blocked?.reason, record.capabilityId))
|
|
174
|
+
: rendererHost.app.projection.runStatusLabel(record.status);
|
|
175
|
+
const tags = blocked
|
|
176
|
+
? [studioNonSuccessReasonTitle(blocked.reason, t, record.capabilityId)]
|
|
177
|
+
: snapshot?.ok && snapshot.kind === 'text'
|
|
178
|
+
? [t('Studio.result.runtimeChip'), t('Studio.result.metricCharacters', { count: snapshot.body.length })]
|
|
179
|
+
: getStudioRunResultTags(record);
|
|
180
|
+
const intentLabel = studioConfiguredTargetLabel(record.runConfig?.target, t);
|
|
164
181
|
const toneClass = historyResultToneClass(record);
|
|
165
182
|
const exportText = getStudioRunHistoryExportText(record);
|
|
166
183
|
const managedArtifact = snapshot?.ok && snapshot.kind === 'artifacts'
|
|
@@ -175,10 +192,8 @@ function TextStudioHistoryRecordResult({
|
|
|
175
192
|
&& Number(record.runConfig?.target.params.additionalDocuments ?? 0) > 0;
|
|
176
193
|
const canUseAsDraft = !sessionOnly && !faceSwapNeedsMedia && !speakerNeedsMedia && !record.inputTruncated;
|
|
177
194
|
const canReplay = canUseAsDraft && !additionalDocumentsNotRetained;
|
|
178
|
-
const revealsManagedAsset = Boolean(managedArtifact?.relativePath);
|
|
179
|
-
const canExport = !blocked && (
|
|
180
|
-
const hasRequestSettings = hasTextStudioRequestSettings(record);
|
|
181
|
-
const [requestSettingsOpen, setRequestSettingsOpen] = useState(false);
|
|
195
|
+
const revealsManagedAsset = Boolean(managedArtifact?.relativePath) && rendererHost.app.projection.assetExportAction() === 'reveal';
|
|
196
|
+
const canExport = !blocked && (Boolean(managedArtifact?.relativePath) || Boolean(exportText.trim()));
|
|
182
197
|
function handleCopy() {
|
|
183
198
|
if (!exportText.trim()) return;
|
|
184
199
|
void rendererHost.app.commands.copyText(exportText)
|
|
@@ -195,7 +210,7 @@ function TextStudioHistoryRecordResult({
|
|
|
195
210
|
}
|
|
196
211
|
function handleDownload() {
|
|
197
212
|
if (managedArtifact?.relativePath) {
|
|
198
|
-
void
|
|
213
|
+
void exportStudioAsset(rendererHost, managedArtifact.relativePath);
|
|
199
214
|
return;
|
|
200
215
|
}
|
|
201
216
|
const stamp = record.createdAt.replace(/[:.]/g, '-');
|
|
@@ -239,7 +254,7 @@ function TextStudioHistoryRecordResult({
|
|
|
239
254
|
<div className="studio-history-result__head">
|
|
240
255
|
<div className="studio-history-result__line">
|
|
241
256
|
<StatusBadge tone={getStudioRunStatusTone(record.status)} shape="dot">
|
|
242
|
-
{
|
|
257
|
+
{statusLabel}
|
|
243
258
|
</StatusBadge>
|
|
244
259
|
<span className="studio-history-result__title-stack">
|
|
245
260
|
<time dateTime={record.createdAt}>{t('StudioShell.runLabel')} / {formatStudioRunTimestamp(record.createdAt, new Date(rendererHost.clock.now()))}</time>
|
|
@@ -249,7 +264,7 @@ function TextStudioHistoryRecordResult({
|
|
|
249
264
|
{!blocked ? (
|
|
250
265
|
<>
|
|
251
266
|
<Tooltip content={t('Common.copy')} placement="top">
|
|
252
|
-
<IconButton type="button" className="studio-result__action" onClick={handleCopy} disabled={!
|
|
267
|
+
<IconButton type="button" className="studio-result__action" onClick={handleCopy} disabled={blocked !== null || !exportText.trim()} aria-label={t('StudioShell.copyGeneration')} icon={<CopyIcon size={16} aria-hidden="true" />} />
|
|
253
268
|
</Tooltip>
|
|
254
269
|
<Tooltip content={t(revealsManagedAsset ? 'StudioShell.revealAsset' : 'StudioShell.download')} placement="top">
|
|
255
270
|
<IconButton type="button" className="studio-result__action" onClick={handleDownload} disabled={!canExport} aria-label={t(revealsManagedAsset ? 'StudioShell.revealGeneration' : 'StudioShell.downloadGeneration')} icon={revealsManagedAsset ? <FolderOpen size={16} aria-hidden="true" /> : <DownloadIcon size={16} aria-hidden="true" />} />
|
|
@@ -258,7 +273,7 @@ function TextStudioHistoryRecordResult({
|
|
|
258
273
|
) : null}
|
|
259
274
|
{canUseAsDraft ? (
|
|
260
275
|
<Tooltip content={t('StudioShell.useAsDraft')} placement="top">
|
|
261
|
-
<IconButton type="button" className="studio-result__action" onClick={() => onUseAsDraft(record)} aria-label={t('StudioShell.useAsDraft')} icon={<SquarePen size={16} aria-hidden="true" />} />
|
|
276
|
+
<IconButton type="button" className="studio-result__action" onClick={() => onUseAsDraft(record)} disabled={!canRestoreInputs} aria-label={t('StudioShell.useAsDraft')} icon={<SquarePen size={16} aria-hidden="true" />} />
|
|
262
277
|
</Tooltip>
|
|
263
278
|
) : null}
|
|
264
279
|
{canReplay ? (
|
|
@@ -274,26 +289,13 @@ function TextStudioHistoryRecordResult({
|
|
|
274
289
|
</div>
|
|
275
290
|
<div className="studio-history-result__intent">
|
|
276
291
|
<span>{t('StudioShell.intentLabel')}</span>
|
|
277
|
-
<div className=
|
|
292
|
+
<div className="studio-intent-pill__box studio-intent-pill__box--static">
|
|
278
293
|
<Tooltip content={intentLabel} placement="top" className="min-w-0">
|
|
279
294
|
<strong>{intentLabel}</strong>
|
|
280
295
|
</Tooltip>
|
|
281
|
-
{hasRequestSettings ? (
|
|
282
|
-
<Tooltip content={requestSettingsOpen ? t('StudioShell.hideRequestSettings') : t('StudioShell.showRequestSettings')} placement="top">
|
|
283
|
-
<IconButton
|
|
284
|
-
type="button"
|
|
285
|
-
className={requestSettingsOpen ? 'studio-intent-pill__trigger studio-intent-pill__trigger--open' : 'studio-intent-pill__trigger'}
|
|
286
|
-
aria-label={requestSettingsOpen ? t('StudioShell.hideRequestSettings') : t('StudioShell.showRequestSettings')}
|
|
287
|
-
aria-expanded={requestSettingsOpen}
|
|
288
|
-
onClick={() => setRequestSettingsOpen((value) => !value)}
|
|
289
|
-
icon={<ChevronRight size={15} aria-hidden="true" />}
|
|
290
|
-
/>
|
|
291
|
-
</Tooltip>
|
|
292
|
-
) : null}
|
|
293
296
|
</div>
|
|
294
297
|
</div>
|
|
295
298
|
</div>
|
|
296
|
-
{requestSettingsOpen && hasRequestSettings ? <TextStudioRequestSettings record={record} /> : null}
|
|
297
299
|
{HistoryActions ? <HistoryActions key={record.id} record={record} /> : null}
|
|
298
300
|
{body}
|
|
299
301
|
{additionalDocumentsNotRetained ? <p className="studio-result__hint">{t('StudioShell.historyAdditionalDocumentsNotRetained')}</p> : null}
|
|
@@ -320,7 +322,7 @@ function TextStudioHistorySnapshotBody({ snapshot, recordId, submittedParameters
|
|
|
320
322
|
}
|
|
321
323
|
if (snapshot.kind === 'speaker-embedding') return <SpeakerEmbeddingResultBody spaceId={snapshot.spaceId} vector={snapshot.vector} />;
|
|
322
324
|
if (snapshot.kind === 'embedding') {
|
|
323
|
-
return <EmbeddingResultBody spaceId={snapshot.spaceId} />;
|
|
325
|
+
return <EmbeddingResultBody spaceId={snapshot.spaceId} retrieval={snapshot.retrieval} />;
|
|
324
326
|
}
|
|
325
327
|
if (snapshot.kind === 'text-annotation') {
|
|
326
328
|
return <TextAnnotationResultView output={{
|
|
@@ -413,6 +415,7 @@ export function TextStudioResultState({
|
|
|
413
415
|
intentLabel,
|
|
414
416
|
running,
|
|
415
417
|
canRegenerate,
|
|
418
|
+
canRestoreInputs,
|
|
416
419
|
regenerateHint,
|
|
417
420
|
cancelRequested,
|
|
418
421
|
streamingText,
|
|
@@ -431,6 +434,7 @@ export function TextStudioResultState({
|
|
|
431
434
|
intentLabel: string;
|
|
432
435
|
running: boolean;
|
|
433
436
|
canRegenerate: boolean;
|
|
437
|
+
canRestoreInputs: boolean;
|
|
434
438
|
regenerateHint?: string;
|
|
435
439
|
cancelRequested: boolean;
|
|
436
440
|
streamingText: string | null;
|
|
@@ -445,28 +449,23 @@ export function TextStudioResultState({
|
|
|
445
449
|
}) {
|
|
446
450
|
const { translate: t } = useAIStudioHost();
|
|
447
451
|
const capability = registration.descriptor;
|
|
452
|
+
const parameterOwnedInput = Boolean(registration.parameters.recordedInput);
|
|
453
|
+
const hasRecordedInput = Boolean(activeRun.prompt) && (parameterOwnedInput || registration.profile.inputKind !== 'none');
|
|
454
|
+
const resultScroll = useRef<HTMLDivElement>(null);
|
|
455
|
+
const draftDisclosure = useRef<HTMLDetailsElement>(null);
|
|
456
|
+
useEffect(() => {
|
|
457
|
+
if (resultScroll.current) resultScroll.current.scrollTop = 0;
|
|
458
|
+
}, [activeRun.id]);
|
|
459
|
+
useEffect(() => {
|
|
460
|
+
if (!running) return;
|
|
461
|
+
if (draftDisclosure.current?.open) {
|
|
462
|
+
draftDisclosure.current.open = false;
|
|
463
|
+
resultScroll.current?.focus({ preventScroll: true });
|
|
464
|
+
}
|
|
465
|
+
}, [running]);
|
|
448
466
|
return (
|
|
449
467
|
<section className="studio-thread" aria-label={t('StudioShell.resultAriaLabel', { capability: t(capability.labelKey) })}>
|
|
450
|
-
<div className="studio-thread__scroll">
|
|
451
|
-
{regenerateHint ? <p className="studio-result__hint" role="status">{regenerateHint}</p> : null}
|
|
452
|
-
{registration.parameters.recordedInput ? (
|
|
453
|
-
// A parameter-owned input is shown as the complete request it recorded.
|
|
454
|
-
<article className="studio-turn studio-turn--user">
|
|
455
|
-
<details className="studio-diag studio-turn__request">
|
|
456
|
-
<summary>{t('StudioShell.requestLabel')}</summary>
|
|
457
|
-
<pre className="studio-diag__json">{activeRun.prompt}</pre>
|
|
458
|
-
</details>
|
|
459
|
-
{activeRun.record?.inputTruncated ? <p className="studio-result__hint">{t('StudioShell.historyInputTruncated')}</p> : null}
|
|
460
|
-
</article>
|
|
461
|
-
) : registration.profile.inputKind !== 'none' && activeRun.prompt ? <article className="studio-turn studio-turn--user">
|
|
462
|
-
<div className="studio-turn__label">
|
|
463
|
-
<MessageSquare size={14} aria-hidden="true" />
|
|
464
|
-
<span>{t('StudioShell.promptLabel')}</span>
|
|
465
|
-
</div>
|
|
466
|
-
<p>{activeRun.prompt}</p>
|
|
467
|
-
{activeRun.record?.inputTruncated ? <p className="studio-result__hint">{t('StudioShell.historyInputTruncated')}</p> : null}
|
|
468
|
-
<TextStudioPromptSettings activeRun={activeRun} />
|
|
469
|
-
</article> : null}
|
|
468
|
+
<div ref={resultScroll} className="studio-thread__scroll" tabIndex={-1}>
|
|
470
469
|
<article className="studio-turn studio-turn--assistant">
|
|
471
470
|
<div className="studio-turn__label">
|
|
472
471
|
<FileText size={14} aria-hidden="true" />
|
|
@@ -485,7 +484,6 @@ export function TextStudioResultState({
|
|
|
485
484
|
admission={admission}
|
|
486
485
|
createdAt={activeRun.createdAt}
|
|
487
486
|
intentLabel={intentLabel}
|
|
488
|
-
requestSettings={activeRun.record && hasTextStudioRequestSettings(activeRun.record) ? <TextStudioRequestSettings record={activeRun.record} /> : null}
|
|
489
487
|
streamingText={streamingText}
|
|
490
488
|
jobStatus={activeRun.jobStatus}
|
|
491
489
|
verboseConsole={verboseConsole}
|
|
@@ -497,11 +495,38 @@ export function TextStudioResultState({
|
|
|
497
495
|
/>
|
|
498
496
|
</>
|
|
499
497
|
) : activeRun.record ? (
|
|
500
|
-
<TextStudioHistoryRecordResult registration={registration} record={activeRun.record} canRegenerate={canRegenerate} onRegenerate={onRegenerate} onUseAsDraft={onUseAsDraft} />
|
|
498
|
+
<TextStudioHistoryRecordResult registration={registration} record={activeRun.record} canRegenerate={canRegenerate} canRestoreInputs={canRestoreInputs} onRegenerate={onRegenerate} onUseAsDraft={onUseAsDraft} />
|
|
501
499
|
) : null}
|
|
500
|
+
{regenerateHint ? <p className="studio-result__hint" role="status">{regenerateHint}</p> : null}
|
|
502
501
|
</article>
|
|
502
|
+
{activeRun.record ? (
|
|
503
|
+
<div className="studio-turn"><TextStudioRequestSettings record={activeRun.record} /></div>
|
|
504
|
+
) : null}
|
|
505
|
+
{hasRecordedInput ? (
|
|
506
|
+
<details key={activeRun.id} className="studio-review-disclosure">
|
|
507
|
+
<summary>
|
|
508
|
+
<MessageSquare size={15} aria-hidden="true" />
|
|
509
|
+
<span>{t('StudioShell.recordedInput')}</span>
|
|
510
|
+
</summary>
|
|
511
|
+
<div className="studio-review-disclosure__body">
|
|
512
|
+
{parameterOwnedInput ? <pre className="studio-diag__json">{activeRun.prompt}</pre> : (
|
|
513
|
+
<>
|
|
514
|
+
<p className="studio-review-disclosure__prompt">{activeRun.prompt}</p>
|
|
515
|
+
<TextStudioPromptSettings activeRun={activeRun} />
|
|
516
|
+
</>
|
|
517
|
+
)}
|
|
518
|
+
{activeRun.record?.inputTruncated ? <p className="studio-result__hint">{t('StudioShell.historyInputTruncated')}</p> : null}
|
|
519
|
+
</div>
|
|
520
|
+
</details>
|
|
521
|
+
) : null}
|
|
522
|
+
<details ref={draftDisclosure} className="studio-review-disclosure">
|
|
523
|
+
<summary>
|
|
524
|
+
<SquarePen size={15} aria-hidden="true" />
|
|
525
|
+
<span>{t('StudioShell.editNextRun')}</span>
|
|
526
|
+
</summary>
|
|
527
|
+
<div className="studio-review-disclosure__body">{composer}</div>
|
|
528
|
+
</details>
|
|
503
529
|
</div>
|
|
504
|
-
<div className="studio-thread__composer">{composer}</div>
|
|
505
530
|
</section>
|
|
506
531
|
);
|
|
507
532
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import type
|
|
2
|
+
import { runtimeAIConfigStructToJson, type NimiAIConfigSnapshot } from '@nimiplatform/sdk/ai';
|
|
3
3
|
|
|
4
|
+
import { findStudioCapabilityIntent } from './ai-config.js';
|
|
4
5
|
import { useAIStudioHost } from './host-context.js';
|
|
5
6
|
import type { StudioCapabilityRegistration, CapabilityStudioProfile } from './module-registration.js';
|
|
6
7
|
import type { StudioCapabilityRunResult, StudioManagedArtifact, StudioRuntimeInspection } from './runtime-types.js';
|
|
@@ -18,15 +19,19 @@ import {
|
|
|
18
19
|
TONE_OPTIONS,
|
|
19
20
|
} from './studio-directives.js';
|
|
20
21
|
import type { StudioTranslate } from './non-success-presentation.js';
|
|
22
|
+
import type { StudioParameterValue } from './parameters.js';
|
|
21
23
|
|
|
22
24
|
export type TextStudioActiveRun = {
|
|
23
25
|
attachmentCount?: number;
|
|
24
26
|
replayMedia?: StudioManagedArtifact;
|
|
27
|
+
// Latest submission's session-only input; history never stores these bytes.
|
|
28
|
+
submittedParameters?: StudioParameterValue;
|
|
25
29
|
jobStatus?: 'queued' | 'running';
|
|
26
30
|
id: string;
|
|
27
31
|
prompt: string;
|
|
28
32
|
context: string;
|
|
29
33
|
createdAt: string;
|
|
34
|
+
configuredTarget?: Pick<StudioRunTargetSummary, 'source' | 'targetLabel'>;
|
|
30
35
|
result: StudioCapabilityRunResult | null;
|
|
31
36
|
record: StudioRunHistoryRecord | null;
|
|
32
37
|
error: string | null;
|
|
@@ -55,7 +60,17 @@ export function textStudioRunTargetIntentSummary(
|
|
|
55
60
|
runTarget: StudioRunTargetSummary,
|
|
56
61
|
translate: StudioTranslate,
|
|
57
62
|
): string {
|
|
58
|
-
return translate('Studio.composer.intentSummary', { intent: runTarget
|
|
63
|
+
return translate('Studio.composer.intentSummary', { intent: studioConfiguredTargetLabel(runTarget, translate) });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function studioConfiguredTargetLabel(
|
|
67
|
+
target: Pick<StudioRunTargetSummary, 'source' | 'targetLabel'> | undefined,
|
|
68
|
+
translate: StudioTranslate,
|
|
69
|
+
): string {
|
|
70
|
+
const route = target?.source === 'local' ? translate('Studio.composer.routeLocal')
|
|
71
|
+
: target?.source === 'cloud' ? translate('Studio.composer.routeCloud')
|
|
72
|
+
: translate('Studio.composer.routeUnknown');
|
|
73
|
+
return target?.targetLabel ? `${route} · ${target.targetLabel}` : route;
|
|
59
74
|
}
|
|
60
75
|
|
|
61
76
|
export function canConfigureRunTarget(runTarget: StudioRunTargetSummary): boolean {
|
|
@@ -65,31 +80,31 @@ export function canConfigureRunTarget(runTarget: StudioRunTargetSummary): boolea
|
|
|
65
80
|
export function useStudioRunTargetSummary(
|
|
66
81
|
registration: StudioCapabilityRegistration,
|
|
67
82
|
runtime: StudioRuntimeInspection | null,
|
|
68
|
-
): StudioRunTargetSummary {
|
|
83
|
+
): StudioRunTargetSummary & { readonly snapshot: NimiAIConfigSnapshot | null; readonly configReadFailed: boolean } {
|
|
69
84
|
const host = useAIStudioHost();
|
|
70
85
|
const [configProjection, setConfigProjection] = useState<{
|
|
71
86
|
state: 'loading' | 'loaded' | 'failed';
|
|
72
|
-
|
|
87
|
+
snapshot: NimiAIConfigSnapshot | null;
|
|
73
88
|
error: string | null;
|
|
74
|
-
}>({ state: 'loading',
|
|
89
|
+
}>({ state: 'loading', snapshot: null, error: null });
|
|
75
90
|
|
|
76
91
|
useEffect(() => {
|
|
77
92
|
let cancelled = false;
|
|
78
93
|
let requestGeneration = 0;
|
|
79
94
|
const refresh = () => {
|
|
80
95
|
const generation = ++requestGeneration;
|
|
81
|
-
setConfigProjection({ state: 'loading',
|
|
82
|
-
void host.sdk.aiConfig.
|
|
96
|
+
setConfigProjection({ state: 'loading', snapshot: null, error: null });
|
|
97
|
+
void host.sdk.aiConfig.getSnapshot()
|
|
83
98
|
.then((next) => {
|
|
84
99
|
if (!cancelled && generation === requestGeneration) {
|
|
85
|
-
setConfigProjection({ state: 'loaded',
|
|
100
|
+
setConfigProjection({ state: 'loaded', snapshot: next, error: null });
|
|
86
101
|
}
|
|
87
102
|
})
|
|
88
103
|
.catch((cause) => {
|
|
89
104
|
if (!cancelled && generation === requestGeneration) {
|
|
90
105
|
setConfigProjection({
|
|
91
106
|
state: 'failed',
|
|
92
|
-
|
|
107
|
+
snapshot: null,
|
|
93
108
|
error: cause instanceof Error ? cause.message : String(cause || host.translate('Studio.run.aiConfigLoadFailed')),
|
|
94
109
|
});
|
|
95
110
|
}
|
|
@@ -104,13 +119,41 @@ export function useStudioRunTargetSummary(
|
|
|
104
119
|
};
|
|
105
120
|
}, [host]);
|
|
106
121
|
|
|
107
|
-
return useMemo(() =>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
return useMemo(() => {
|
|
123
|
+
const { snapshot } = configProjection;
|
|
124
|
+
const config = snapshot?.config ?? null;
|
|
125
|
+
const target = host.app.projection.projectRunTarget({
|
|
126
|
+
capability: registration.descriptor,
|
|
127
|
+
runtime,
|
|
128
|
+
config,
|
|
129
|
+
configState: configProjection.state,
|
|
130
|
+
configError: configProjection.error,
|
|
131
|
+
});
|
|
132
|
+
const readState = { snapshot, configReadFailed: configProjection.state === 'failed' };
|
|
133
|
+
if (!target.capabilityContract || !target.canDispatch) return { ...target, ...readState };
|
|
134
|
+
const selection = snapshot?.effectiveSelections.find((item) => item.capabilityContract === target.capabilityContract);
|
|
135
|
+
const resource = selection?.resource;
|
|
136
|
+
const intent = findStudioCapabilityIntent(config, target.capabilityContract);
|
|
137
|
+
const configuredCloudModel = intent?.route.oneofKind === 'cloud'
|
|
138
|
+
? runtimeAIConfigStructToJson(intent.route.cloud.providerModelTarget).providerModelId
|
|
139
|
+
: undefined;
|
|
140
|
+
const label = resource?.oneofKind === 'local' ? resource.local.label
|
|
141
|
+
: resource?.oneofKind === 'cloud' ? resource.cloud.target.label
|
|
142
|
+
: configuredCloudModel;
|
|
143
|
+
const targetLabel = typeof label === 'string' && label.trim() ? label : undefined;
|
|
144
|
+
const targetRef = resource?.oneofKind === 'local' ? resource.local.loadoutRef
|
|
145
|
+
: typeof configuredCloudModel === 'string' ? configuredCloudModel : undefined;
|
|
146
|
+
const recordedConfig = {
|
|
147
|
+
targetLabel,
|
|
148
|
+
targetRef,
|
|
149
|
+
configuredDefaults: intent ? runtimeAIConfigStructToJson(intent.defaults) : undefined,
|
|
150
|
+
};
|
|
151
|
+
if (selection && selection.state !== 'ready') {
|
|
152
|
+
return { ...target, ...readState, ...recordedConfig, status: 'blocked', canDispatch: false,
|
|
153
|
+
detail: host.translate('Studio.run.effectiveTargetUnavailable') };
|
|
154
|
+
}
|
|
155
|
+
return { ...target, ...readState, ...recordedConfig };
|
|
156
|
+
}, [configProjection, host, registration.descriptor, runtime]);
|
|
114
157
|
}
|
|
115
158
|
|
|
116
159
|
export type TextStudioPromptStyle = { tone: string; length: string };
|
|
@@ -163,6 +206,9 @@ export function createRunConfigSnapshot(input: {
|
|
|
163
206
|
status: target.status,
|
|
164
207
|
source: target.source,
|
|
165
208
|
intentLabel: target.intentLabel,
|
|
209
|
+
...(target.targetLabel ? { targetLabel: target.targetLabel } : {}),
|
|
210
|
+
...(target.targetRef ? { targetRef: target.targetRef } : {}),
|
|
211
|
+
...(target.configuredDefaults ? { configuredDefaults: target.configuredDefaults } : {}),
|
|
166
212
|
detail: target.detail,
|
|
167
213
|
params,
|
|
168
214
|
paramsSummary: [...target.paramsSummary],
|
|
@@ -24,6 +24,8 @@ export function SessionSummaryView({ output }: { readonly output: SessionOutput
|
|
|
24
24
|
<div><dt>{t('StudioResults.session.duration')}</dt><dd>{t('StudioResults.session.seconds', { seconds: seconds.toFixed(1) })}</dd></div>
|
|
25
25
|
<div><dt>{t('StudioResults.session.terminalReason')}</dt><dd><code>{output.terminalReason}</code></dd></div>
|
|
26
26
|
</dl>
|
|
27
|
+
{output.audioUsage ? <p className="studio-result__hint">{t(output.audioUsage.final ? 'StudioResults.session.audioUsageFinal' : 'StudioResults.session.audioUsagePartial', { seconds: output.audioUsage.audioSeconds })}</p> : null}
|
|
28
|
+
{output.closure ? <p className="studio-result__hint">{t(!output.closure.localResourcesReleased ? 'StudioResults.session.localClosureUnconfirmed' : output.closure.providerSessionClosed ? 'StudioResults.session.providerClosureConfirmed' : 'StudioResults.session.localClosureConfirmed')}</p> : null}
|
|
27
29
|
{counters.length > 0 ? (
|
|
28
30
|
<ul className="studio-voice-list">
|
|
29
31
|
{counters.map(([name, count]) => (
|
|
@@ -16,7 +16,7 @@ import { VisionLocateResultView } from './section-ai-testing-vision-result.js';
|
|
|
16
16
|
import type { StudioCapabilityRunResult } from './runtime-types.js';
|
|
17
17
|
import type { StudioCapabilityDescriptor, StudioCapabilityRegistration } from './module-registration.js';
|
|
18
18
|
import { formatStudioRunTimestamp } from './history.js';
|
|
19
|
-
import { isStoppedDirectCall, studioNonSuccessNeedsTargetReselection, studioNonSuccessReasonUserAction, studioNonSuccessReasonUserMessage, type StudioTranslate } from './non-success-presentation.js';
|
|
19
|
+
import { isStoppedDirectCall, studioNonSuccessNeedsTargetReselection, studioNonSuccessReasonUserAction, studioNonSuccessReasonUserMessage, studioTerminalStatusKey, type StudioTranslate } from './non-success-presentation.js';
|
|
20
20
|
import { countStudioWords } from './studio-directives.js';
|
|
21
21
|
import type { CapabilityStatus } from './section-ai-testing-admission.js';
|
|
22
22
|
import { ArtifactMediaPreview, ArtifactMediaResult, EmbeddingResultBody, SpeakerEmbeddingResultBody, KnownJobNotice, RuntimeDiagnosticsActions, formatTypedOutput, formatNonSuccessOutput, resultPlainText, TextStudioOutputBody } from './section-ai-testing-output.js';
|
|
@@ -61,7 +61,7 @@ function ReadyBody({ result }: { result: StudioCapabilityRunResult & { ok: true
|
|
|
61
61
|
}
|
|
62
62
|
if (output.kind === 'speaker-embedding') return <SpeakerEmbeddingResultBody spaceId={output.spaceId} vector={output.vector} />;
|
|
63
63
|
if (output.kind === 'embedding') {
|
|
64
|
-
return <EmbeddingResultBody spaceId={output.spaceId} />;
|
|
64
|
+
return <EmbeddingResultBody spaceId={output.spaceId} retrieval={output.retrieval} />;
|
|
65
65
|
}
|
|
66
66
|
if (output.kind === 'voice-asset') {
|
|
67
67
|
return (
|
|
@@ -239,7 +239,6 @@ export function StudioResult({
|
|
|
239
239
|
const profile = registration.profile;
|
|
240
240
|
const ready = result?.ok ? result : null;
|
|
241
241
|
const operationAborted = result && !result.ok && result.reason === 'operation-aborted' ? result : null;
|
|
242
|
-
const stoppedDirectCall = Boolean(operationAborted && isStoppedDirectCall(operationAborted.reason, capability.id));
|
|
243
242
|
const canceled = result && !result.ok && result.reason === 'runtime-canceled' ? result : null;
|
|
244
243
|
const timedOut = result && !result.ok && result.reason === 'runtime-timeout' ? result : null;
|
|
245
244
|
const blocked = result && !result.ok
|
|
@@ -248,15 +247,18 @@ export function StudioResult({
|
|
|
248
247
|
&& result.reason !== 'runtime-timeout' ? result : null;
|
|
249
248
|
const plainText = ready ? resultPlainText(ready, t) : '';
|
|
250
249
|
const canExport = Boolean(ready && plainText);
|
|
251
|
-
const revealsManagedAsset = ready?.output.kind === 'artifacts' || ready?.output.kind === 'text-annotation'
|
|
250
|
+
const revealsManagedAsset = (ready?.output.kind === 'artifacts' || ready?.output.kind === 'text-annotation')
|
|
251
|
+
&& rendererHost.app.projection.assetExportAction() === 'reveal';
|
|
252
252
|
const displayIntentLabel = studioResultIntentLabel(result, capability, intentLabel, t);
|
|
253
253
|
const [requestSettingsOpen, setRequestSettingsOpen] = useState(false);
|
|
254
254
|
const hasRequestSettings = Boolean(requestSettings);
|
|
255
255
|
const runTimeLabel = createdAt
|
|
256
256
|
? formatStudioRunTimestamp(createdAt, new Date(rendererHost.clock.now()))
|
|
257
257
|
: running ? t('Studio.result.statRunning') : t('Studio.result.notRecorded');
|
|
258
|
-
const
|
|
259
|
-
|
|
258
|
+
const statusTitle = t(cancelRequested ? 'Studio.result.status.stopping'
|
|
259
|
+
: running ? 'Studio.result.status.runtimeRunning'
|
|
260
|
+
: result ? studioTerminalStatusKey(result.ok ? undefined : result.reason, capability.id)
|
|
261
|
+
: 'Studio.result.status.runtimeWaiting');
|
|
260
262
|
const statusTone = blocked || operationAborted || canceled || timedOut ? 'warning' : ready ? 'success' : running ? 'info' : 'neutral';
|
|
261
263
|
useEffect(() => {
|
|
262
264
|
if (!hasRequestSettings) setRequestSettingsOpen(false);
|
|
@@ -454,23 +456,12 @@ export function StudioResult({
|
|
|
454
456
|
}
|
|
455
457
|
|
|
456
458
|
return (
|
|
457
|
-
<Surface className="studio-result"
|
|
459
|
+
<Surface className="studio-result" tone="card" padding="none">
|
|
458
460
|
<div className="studio-result__top">
|
|
459
461
|
<div className="studio-result__identity">
|
|
460
|
-
<StatusBadge
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
className="grid h-11 w-11 place-items-center rounded-[var(--nimi-radius-md)] p-0"
|
|
464
|
-
aria-hidden="true"
|
|
465
|
-
>
|
|
466
|
-
<Sparkles size={20} />
|
|
467
|
-
</StatusBadge>
|
|
468
|
-
<span className="studio-result__title-stack">
|
|
469
|
-
<strong>{statusTitle}</strong>
|
|
470
|
-
<span className="studio-result__time">
|
|
471
|
-
<Clock size={14} aria-hidden="true" />
|
|
472
|
-
<time dateTime={createdAt}>{t('Studio.result.runTimeLabel', { time: runTimeLabel })}</time>
|
|
473
|
-
</span>
|
|
462
|
+
<StatusBadge tone={statusTone} shape="dot">{statusTitle}</StatusBadge>
|
|
463
|
+
<span className="studio-result__time">
|
|
464
|
+
<time dateTime={createdAt}>{t('Studio.result.runTimeLabel', { time: runTimeLabel })}</time>
|
|
474
465
|
</span>
|
|
475
466
|
</div>
|
|
476
467
|
<div className="studio-result__actions">
|
|
@@ -16,7 +16,10 @@ export function MusicTranscriptionNotice({ value, recordId }: { readonly value?:
|
|
|
16
16
|
const [feedback, setFeedback] = useState<{ sourceKey: string; error?: string; exportedPath?: string } | null>(null);
|
|
17
17
|
const [exporting, setExporting] = useState('');
|
|
18
18
|
const currentSource = useRef(sourceKey);
|
|
19
|
-
useLayoutEffect(() => {
|
|
19
|
+
useLayoutEffect(() => {
|
|
20
|
+
currentSource.current = sourceKey;
|
|
21
|
+
return () => { if (currentSource.current === sourceKey) currentSource.current = ''; };
|
|
22
|
+
}, [sourceKey]);
|
|
20
23
|
const scores = value?.scores;
|
|
21
24
|
const timelinePath = value?.timelineRelativePath;
|
|
22
25
|
// Render and actions gate on provenance before passive effects can run.
|
|
@@ -33,23 +36,37 @@ export function MusicTranscriptionNotice({ value, recordId }: { readonly value?:
|
|
|
33
36
|
const midi = score?.format === 'midi';
|
|
34
37
|
const mediaType = timeline ? 'application/vnd.nimi.music-timeline+json' : midi ? 'audio/midi' : 'text/vnd.abc';
|
|
35
38
|
const filename = timeline ? 'music-timeline.json' : midi ? 'estimated-notes.mid' : 'transcribed-score.abc';
|
|
39
|
+
let iterator: AsyncIterator<Uint8Array> | undefined;
|
|
40
|
+
let closing: Promise<unknown> | undefined;
|
|
41
|
+
const current = () => active && currentSource.current === sourceKey;
|
|
42
|
+
const close = (): Promise<unknown> => {
|
|
43
|
+
if (!iterator) return Promise.resolve();
|
|
44
|
+
const retiring = iterator;
|
|
45
|
+
return closing ??= Promise.resolve().then(() => retiring.return?.());
|
|
46
|
+
};
|
|
36
47
|
void (async () => {
|
|
37
48
|
const read = await host.sdk.assets.read({ relativePath: selected });
|
|
38
|
-
|
|
49
|
+
iterator = read.body[Symbol.asyncIterator]();
|
|
39
50
|
const limit = timeline || midi ? 16777216 : 1048576;
|
|
40
51
|
try {
|
|
52
|
+
if (!current()) return;
|
|
41
53
|
if (read.asset.mediaType !== mediaType || read.asset.sizeBytes < 1 || read.asset.sizeBytes > limit) throw new Error(t('Music.scoreTooLarge'));
|
|
42
54
|
const bytes = new Uint8Array(read.asset.sizeBytes); let offset = 0;
|
|
43
|
-
for
|
|
55
|
+
for (;;) {
|
|
56
|
+
if (!current()) return;
|
|
57
|
+
const next = await iterator.next();
|
|
58
|
+
if (!current()) return;
|
|
59
|
+
if (next.done) break;
|
|
60
|
+
const chunk = next.value;
|
|
44
61
|
if (offset + chunk.length > bytes.length) throw new Error(t('Music.scoreTooLarge'));
|
|
45
62
|
bytes.set(chunk, offset); offset += chunk.length;
|
|
46
63
|
}
|
|
47
64
|
if (offset !== bytes.length) throw new Error(t('Music.scoreIncomplete'));
|
|
48
65
|
const body = midi ? '' : new TextDecoder('utf-8', { fatal: true }).decode(bytes);
|
|
49
|
-
if (
|
|
50
|
-
} finally { await
|
|
51
|
-
})().catch((cause: unknown) => { if (
|
|
52
|
-
return () => { active = false; };
|
|
66
|
+
if (current()) setLoaded({ sourceKey, path: selected, bytes, body, filename, mediaType, midi });
|
|
67
|
+
} finally { await close(); }
|
|
68
|
+
})().catch((cause: unknown) => { if (current()) setFeedback({ sourceKey, error: String(cause) }); });
|
|
69
|
+
return () => { active = false; void close().catch(() => undefined); };
|
|
53
70
|
}, [sourceKey, selected, timelinePath, scores, host, t]);
|
|
54
71
|
async function exportSelected() {
|
|
55
72
|
const snapshot = file;
|
|
@@ -61,7 +78,7 @@ export function MusicTranscriptionNotice({ value, recordId }: { readonly value?:
|
|
|
61
78
|
const saved = await host.sdk.assets.write({ relativePath: `studio/music/exports/${crypto.randomUUID()}/${snapshot.filename}`,
|
|
62
79
|
body: chunks(), mediaType: snapshot.mediaType, overwrite: false });
|
|
63
80
|
setFeedback({ sourceKey: snapshot.sourceKey, exportedPath: saved.relativePath });
|
|
64
|
-
try { await host.
|
|
81
|
+
try { await host.app.commands.exportAsset(saved.relativePath); }
|
|
65
82
|
catch {
|
|
66
83
|
setFeedback({ sourceKey: snapshot.sourceKey, exportedPath: saved.relativePath,
|
|
67
84
|
error: t('Common.exportSavedRevealFailed', { path: saved.relativePath }) });
|
|
@@ -75,7 +92,7 @@ export function MusicTranscriptionNotice({ value, recordId }: { readonly value?:
|
|
|
75
92
|
async function revealSelected() {
|
|
76
93
|
const snapshot = file;
|
|
77
94
|
if (!snapshot || snapshot.sourceKey !== currentSource.current) return;
|
|
78
|
-
try { await host.
|
|
95
|
+
try { await host.app.commands.exportAsset(snapshot.path); }
|
|
79
96
|
catch { setFeedback({ sourceKey: snapshot.sourceKey, error: t('Common.assetRevealFailed', { path: snapshot.path }) }); }
|
|
80
97
|
}
|
|
81
98
|
if (!value) return null;
|