@nimiplatform/app-tools 0.14.0 → 0.16.0-rc.12

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 (99) hide show
  1. package/README.md +112 -24
  2. package/bin/nimi-app.mjs +35 -15
  3. package/lib/app-access-declaration.mjs +3 -0
  4. package/lib/app-dependency-combinations.mjs +70 -24
  5. package/lib/app-doctor-update.mjs +97 -39
  6. package/lib/app-host-support.mjs +6 -0
  7. package/lib/app-identifiers.mjs +27 -0
  8. package/lib/app-info.mjs +292 -1
  9. package/lib/app-lifecycle-guidance.mjs +1 -1
  10. package/lib/app-pack.mjs +65 -39
  11. package/lib/app-project-lifecycle.mjs +149 -244
  12. package/lib/app-scaffold-capabilities.mjs +13 -109
  13. package/lib/app-scaffold-profiles.mjs +81 -115
  14. package/lib/app-scaffold.mjs +74 -166
  15. package/lib/app-toolchain-updates.mjs +45 -0
  16. package/lib/canonical-capability-ids.generated.mjs +2 -0
  17. package/lib/development-environment.d.mts +10 -0
  18. package/lib/development-environment.mjs +39 -0
  19. package/lib/hosted-web-release.mjs +98 -0
  20. package/lib/index.mjs +43 -3
  21. package/lib/mobile-development.mjs +19 -0
  22. package/lib/realm-environments.generated.mjs +5 -0
  23. package/lib/storefront-media.mjs +154 -0
  24. package/lib/web-coordination.mjs +59 -0
  25. package/lib/web-development.d.mts +23 -0
  26. package/lib/web-development.mjs +118 -0
  27. package/lib/web-scaffold.mjs +125 -0
  28. package/package.json +33 -21
  29. package/scripts/dev-shell.mjs +4 -1
  30. package/scripts/sync-scaffold-versions.mjs +0 -2
  31. package/skills/nimi-app-lifecycle/SKILL.md +3 -1
  32. package/skills/nimi-app-lifecycle/references/acceptance.md +6 -2
  33. package/skills/nimi-app-lifecycle/references/adapt.md +5 -3
  34. package/skills/nimi-app-lifecycle/references/audit.md +3 -2
  35. package/skills/nimi-app-lifecycle/references/create.md +6 -2
  36. package/skills/nimi-app-lifecycle/references/release.md +10 -0
  37. package/skills/nimi-app-lifecycle/references/upgrade-platform.md +12 -7
  38. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +87 -52
  39. package/templates/app-source/src/ai-studio-core/history-policy.ts +45 -11
  40. package/templates/app-source/src/ai-studio-core/history.ts +22 -11
  41. package/templates/app-source/src/ai-studio-core/host-context.tsx +9 -4
  42. package/templates/app-source/src/ai-studio-core/index.ts +2 -0
  43. package/templates/app-source/src/ai-studio-core/job-recovery-panel.tsx +15 -5
  44. package/templates/app-source/src/ai-studio-core/job-recovery.ts +2 -2
  45. package/templates/app-source/src/ai-studio-core/messages/en.json +73 -19
  46. package/templates/app-source/src/ai-studio-core/messages/zh.json +73 -19
  47. package/templates/app-source/src/ai-studio-core/module-registration.ts +1 -0
  48. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +30 -5
  49. package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +12 -6
  50. package/templates/app-source/src/ai-studio-core/parameters.ts +4 -0
  51. package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +42 -0
  52. package/templates/app-source/src/ai-studio-core/runtime-types.ts +9 -2
  53. package/templates/app-source/src/ai-studio-core/runtime.ts +8 -4
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +98 -90
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-exchange-result.tsx +1 -1
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +205 -48
  57. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +1 -0
  58. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +36 -14
  59. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +96 -75
  60. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +59 -16
  61. package/templates/app-source/src/ai-studio-core/section-ai-testing-session-result.tsx +2 -0
  62. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +12 -21
  63. package/templates/app-source/src/ai-studio-core/section-ai-testing-transcription-result.tsx +2 -2
  64. package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +3 -3
  65. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +158 -76
  66. package/templates/app-source/src/ai-studio-core/workspace.tsx +49 -22
  67. package/templates/app-source/src/product-modules/agent-center/index.tsx +2 -3
  68. package/templates/app-source/src/product-modules/agent-conversation/index.tsx +2 -3
  69. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +12 -3
  70. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +12 -3
  71. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +11 -2
  72. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +2 -1
  73. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +47 -5
  74. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +59 -8
  75. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +68 -8
  76. package/templates/app-source/src/studio-modules/studio-media/music-parameters.tsx +2 -1
  77. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +271 -83
  78. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +120 -2
  79. package/templates/app-source/src/studio-modules/studio-media/registration.ts +1 -0
  80. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +24 -14
  81. package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +1 -1
  82. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +3 -2
  83. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +3 -2
  84. package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +46 -23
  85. package/templates/app-source/src/studio-modules/studio-voice/registration.ts +2 -1
  86. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +2 -2
  87. package/templates/app-source/src/workbench-core/workbench-core.tsx +27 -3
  88. package/templates/default-starter/AGENTS.md +3 -3
  89. package/templates/default-starter/README.md +1 -1
  90. package/templates/default-starter/src/shell/App.tsx +6 -18
  91. package/templates/default-starter/src/shell/auth/local-app-client.ts +6 -15
  92. package/templates/default-starter/src/shell/auth/runtime-platform.ts +7 -107
  93. package/templates/default-starter/src/shell/workbench-target-adapter.ts +9 -126
  94. package/templates/default-starter.manifest.json +0 -16
  95. package/templates/hosted-web-release.yml +98 -0
  96. package/templates/default-starter/src-tauri/Cargo.toml +0 -17
  97. package/templates/default-starter/src-tauri/build.rs +0 -32
  98. package/templates/default-starter/src-tauri/capabilities/default.json +0 -7
  99. package/templates/default-starter/src-tauri/tauri.conf.json +0 -26
@@ -1,7 +1,7 @@
1
1
  import { StudioJobRecoveryPanel } from './job-recovery-panel.js';
2
2
  import { isStudioJobRecoveryCapability } from './job-recovery.js';
3
- import { Suspense, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
4
- import { Button, IconButton, LoadingSkeleton, nimiToast, OverlayShell, StatusBadge, Tooltip } from '@nimiplatform/kit/ui';
3
+ import { Suspense, useCallback, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
4
+ import { Button, IconButton, LoadingSkeleton, InlineAlert, nimiToast, OverlayShell, StatusBadge, Tooltip } from '@nimiplatform/kit/ui';
5
5
  import { PanelRight, SquarePen } from 'lucide-react';
6
6
  import { createBrowserDataUrlAttachmentAdapter, useChatComposer, type BrowserDataUrlAttachment } from '@nimiplatform/kit/features/chat/headless';
7
7
  import { notifyStudioAIConfigChanged } from './ai-config.js';
@@ -9,7 +9,7 @@ import { useAIStudioHost } from './host-context.js';
9
9
  import type { StudioCapabilityRegistration } from './module-registration.js';
10
10
  import type { StudioParameterValue } from './parameters.js';
11
11
  import type { StudioCapabilityRunResult, StudioRuntimeInspection } from './runtime-types.js';
12
- import { getStudioRunIntentLabel, restoreStudioCapabilityRunResult, type StudioRunConfigSnapshot, type StudioRunHistory, type StudioRunHistoryRecord } from './history.js';
12
+ import { restoreStudioCapabilityRunResult, type StudioRunConfigSnapshot, type StudioRunHistory, type StudioRunHistoryRecord } from './history.js';
13
13
  import { CapabilityRunHistory, DrawerErrorBoundary, downloadTextFile, resultPlainText, statusForCapability, type CapabilityStatus, type SectionAITestingProps } from './section-ai-testing-surface.js';
14
14
  import { TextStudioComposer, TextStudioStartState } from './section-ai-testing-composer.js';
15
15
  import { ScenarioJobStatus } from '@nimiplatform/sdk/runtime/generated';
@@ -21,8 +21,8 @@ import {
21
21
  } from './section-ai-testing-input.js';
22
22
  import { TextStudioResultState } from './section-ai-testing-result.js';
23
23
  import { readStudioTextReplayMedia, readStudioLocateReplayImage } from './text-media-replay.js';
24
- import { revealStudioAsset } from './section-ai-testing-output.js';
25
- import { canConfigureRunTarget, createRunConfigSnapshot, effectiveTextStudioPromptStyle, textStudioDirectiveForTarget, textStudioRunTargetIntentSummary, textStudioRuntimePrompt, useStudioRunTargetSummary, type TextStudioActiveRun } from './section-ai-testing-run.js';
24
+ import { exportStudioAsset } from './section-ai-testing-output.js';
25
+ import { canConfigureRunTarget, createRunConfigSnapshot, effectiveTextStudioPromptStyle, studioConfiguredTargetLabel, textStudioDirectiveForTarget, textStudioRunTargetIntentSummary, textStudioRuntimePrompt, useStudioRunTargetSummary, type TextStudioActiveRun } from './section-ai-testing-run.js';
26
26
  import { StudioCapabilityParameterContext, StudioHistoryLoadContext, StudioHistoryPanelContext } from './contexts.js';
27
27
 
28
28
  // Admission pill labels are keyed by the typed status so locale changes do not
@@ -70,22 +70,37 @@ function TextStudioShell({
70
70
  const ParameterPanel = registration.parameterPanel;
71
71
  const profile = registration.profile;
72
72
  const preset = registration.preset;
73
- const [prompt, setPrompt] = useState(() => (
74
- rendererHost.app.projection.promptDraft({
75
- surfaceId: 'ai-capabilities',
76
- capabilityId: capability.id,
77
- scenarioId: preset.id,
78
- }, draftPersistence).prompt ?? preset.prompt
79
- ));
73
+ const [prompt, setPrompt] = useState(preset.prompt);
74
+ const promptEditRevision = useRef(0);
75
+ const [draftError, setDraftError] = useState<string | null>(null);
80
76
  const [context, setContext] = useState('');
81
77
  const [executingRun, setExecutingRun] = useState<TextStudioActiveRun | null>(null);
82
78
  const [cancelRequested, setCancelRequested] = useState(false);
83
79
  const [streamingText, setStreamingText] = useState<string | null>(null);
84
- const [mediaInputState, setMediaInputState] = useState<'checking' | 'supported' | 'unsupported' | 'unavailable'>('checking');
80
+ const inputPreparationsRef = useRef(new Map<string, number>());
81
+ const [inputPreparations, setInputPreparations] = useState<ReadonlyMap<string, number>>(inputPreparationsRef.current);
82
+ const startInputPreparation = useCallback(() => {
83
+ const id = capability.id;
84
+ const update = (delta: number) => {
85
+ const next = new Map(inputPreparationsRef.current);
86
+ const count = (next.get(id) ?? 0) + delta;
87
+ if (count > 0) next.set(id, count);
88
+ else next.delete(id);
89
+ inputPreparationsRef.current = next;
90
+ setInputPreparations(next);
91
+ };
92
+ update(1);
93
+ return () => update(-1);
94
+ }, [capability.id]);
95
+ const preparingInput = inputPreparations.has(capability.id);
85
96
  const [activeRun, setActiveRun] = useState<TextStudioActiveRun | null>(null);
86
97
  const [sessionRuns, setSessionRuns] = useState<Record<string, TextStudioActiveRun>>({});
87
98
  const historyPanel = useContext(StudioHistoryPanelContext);
88
- const historyCollapsed = historyPanel?.collapsed ?? true;
99
+ const workspaceRef = useRef<HTMLDivElement>(null);
100
+ const historyToggleRef = useRef<HTMLButtonElement>(null);
101
+ const [compactHistory, setCompactHistory] = useState(false);
102
+ const [compactHistoryOpen, setCompactHistoryOpen] = useState(false);
103
+ const historyCollapsed = compactHistory ? !compactHistoryOpen : historyPanel?.collapsed ?? true;
89
104
  const runSeqRef = useRef(0);
90
105
  const [observationIssue, setObservationIssue] = useState(false);
91
106
  const abortControllerRef = useRef<{ runId: string; controller: AbortController; observation: AbortController } | null>(null);
@@ -104,25 +119,6 @@ function TextStudioShell({
104
119
  onTextChange: updatePrompt,
105
120
  disabled: running,
106
121
  });
107
- useEffect(() => {
108
- if (capability.id !== 'text.generate') return;
109
- let disposed = false;
110
- let generation = 0;
111
- const refresh = () => {
112
- const current = ++generation;
113
- setMediaInputState('checking');
114
- void rendererHost.sdk.aiConfig.getSnapshot().then((snapshot) => {
115
- if (!disposed && generation === current) {
116
- setMediaInputState(textStudioMediaInputAvailable(snapshot, composerState.attachments[0]?.mimeType) ? 'supported' : 'unsupported');
117
- }
118
- }, () => {
119
- if (!disposed && generation === current) setMediaInputState('unavailable');
120
- });
121
- };
122
- refresh();
123
- const unsubscribe = rendererHost.app.events.subscribeAIConfigRefresh(refresh);
124
- return () => { disposed = true; generation += 1; unsubscribe(); };
125
- }, [capability.id, rendererHost, composerState.attachments[0]?.mimeType]);
126
122
  const hasRequiredImage = capability.id !== 'vision.locate'
127
123
  || (composerState.attachments.length === 1 && composerState.attachments[0]?.kind === 'image');
128
124
  const hasActiveRun = Boolean(displayedRun);
@@ -133,7 +129,6 @@ function TextStudioShell({
133
129
  ))
134
130
  : null)
135
131
  : lastResult?.capabilityId === capability.id ? lastResult : null;
136
- const headerResult = hasActiveRun ? currentResult : null;
137
132
  const savedTextMedia = (currentResult?.ok && (currentResult.output.kind === 'text' || currentResult.output.kind === 'vision-locate') ? currentResult.output.sourceImage : undefined)
138
133
  ?? displayedRun?.replayMedia;
139
134
  const displayedAttachmentCount = displayedRun?.record?.runConfig?.promptControls.attachmentCount
@@ -144,7 +139,12 @@ function TextStudioShell({
144
139
  (displayedAttachmentCount === 0 && !savedTextMedia) ||
145
140
  (displayedAttachmentCount <= 1 && Boolean(savedTextMedia) && displayedRun?.record?.status !== 'unavailable');
146
141
  const runTarget = useStudioRunTargetSummary(registration, runtime);
147
- const admission = statusForCapability(registration, runTarget, headerResult, t);
142
+ const admission = statusForCapability(registration, runTarget, null, t);
143
+ const mediaInputState = runTarget.snapshot
144
+ ? (textStudioMediaInputAvailable(runTarget.snapshot, composerState.attachments[0]?.mimeType) ? 'supported' : 'unsupported')
145
+ : (runTarget.configReadFailed ? 'unavailable' : 'checking');
146
+ const canRetryPreparation = capability.execution === 'runtime-sdk'
147
+ && (runTarget.status === 'checking' || runTarget.status === 'not-admitted' || runTarget.configReadFailed);
148
148
  const requiresPrompt = profile.inputKind !== 'none';
149
149
  const supportsMedia = profile.supportsAttachments;
150
150
  const attachmentBlocked = capability.id === 'text.generate' && composerState.attachments.length > 0 && mediaInputState !== 'supported';
@@ -154,7 +154,9 @@ function TextStudioShell({
154
154
  capabilityParameters,
155
155
  ), [capabilityParameters, registration.parameters, runTarget.source]);
156
156
  const parameterSummary = registration.parameters.summarize(effectiveCapabilityParameters);
157
- const hasAlternativeInput = registration.parameters.hasAlternativeInput(capabilityParameters);
157
+ const hasAlternativeInput = registration.parameters.hasAlternativeInput(effectiveCapabilityParameters);
158
+ const promptEnabled = profile.inputKind !== 'url' || runtime?.mode !== 'remote-app';
159
+ const inputIssueKey = registration.parameters.requiredInputIssue?.(effectiveCapabilityParameters);
158
160
  const recordedInput = registration.parameters.recordedInput;
159
161
  const displayedRunPrompt = displayedRun?.prompt;
160
162
  // A parameter-owned input reruns the displayed run's recorded request, which
@@ -197,6 +199,19 @@ function TextStudioShell({
197
199
  const replayAssetsAvailable = replayAssetPaths.length === 0
198
200
  || (replayAssets?.key === replayAssetKey && replayAssets.available);
199
201
 
202
+ useEffect(() => {
203
+ const workspace = workspaceRef.current;
204
+ if (!workspace || typeof ResizeObserver === 'undefined') return;
205
+ const observer = new ResizeObserver(([entry]) => {
206
+ if (!entry) return;
207
+ const compact = entry.contentRect.width <= 1080;
208
+ setCompactHistory(compact);
209
+ if (!compact) setCompactHistoryOpen(false);
210
+ });
211
+ observer.observe(workspace);
212
+ return () => observer.disconnect();
213
+ }, []);
214
+
200
215
  useEffect(() => {
201
216
  const error = historyLoad?.error ?? null;
202
217
  if (!error) {
@@ -205,28 +220,36 @@ function TextStudioShell({
205
220
  }
206
221
  if (expandedHistoryErrorRef.current === error) return;
207
222
  expandedHistoryErrorRef.current = error;
208
- historyPanel?.setCollapsed(false);
209
- }, [historyLoad?.error, historyPanel]);
223
+ if (compactHistory) setCompactHistoryOpen(true);
224
+ else historyPanel?.setCollapsed(false);
225
+ }, [historyLoad?.error, historyPanel, compactHistory]);
210
226
 
211
227
  function updatePrompt(nextPrompt: string) {
228
+ const editRevision = ++promptEditRevision.current;
212
229
  setPrompt(nextPrompt);
230
+ setDraftError(null);
213
231
  void rendererHost.app.commands.savePromptDraft({
214
232
  surfaceId: 'ai-capabilities',
215
233
  capabilityId: capability.id,
216
234
  scenarioId: preset.id,
217
- }, nextPrompt, draftPersistence);
235
+ }, nextPrompt, draftPersistence).catch(error => { if (editRevision === promptEditRevision.current) setDraftError(error instanceof Error ? error.message : String(error)); });
218
236
  }
219
237
 
220
238
  useEffect(() => {
221
239
  abortControllerRef.current?.observation.abort('studio-capability-changed');
222
240
  abortControllerRef.current = null;
223
- const draft = rendererHost.app.projection.promptDraft({
241
+ let active = true;
242
+ const editRevision = ++promptEditRevision.current;
243
+ setDraftError(null);
244
+ void rendererHost.app.projection.promptDraft({
224
245
  surfaceId: 'ai-capabilities',
225
246
  capabilityId: capability.id,
226
247
  scenarioId: preset.id,
227
- }, draftPersistence);
248
+ }, draftPersistence).then(draft => {
249
+ if (active && editRevision === promptEditRevision.current) setPrompt(draft.prompt ?? preset.prompt);
250
+ }).catch(error => { if (active) setDraftError(error instanceof Error ? error.message : String(error)); });
228
251
  runSeqRef.current += 1;
229
- setPrompt(draft.prompt ?? preset.prompt);
252
+ setPrompt(preset.prompt);
230
253
  setContext('');
231
254
  setActiveRun(null);
232
255
  setSessionRuns({});
@@ -234,9 +257,11 @@ function TextStudioShell({
234
257
  setCancelRequested(false);
235
258
  setObservationIssue(false);
236
259
  setStreamingText(null);
260
+ return () => { active = false; };
237
261
  }, [capability.id, draftPersistence, preset, rendererHost]);
238
262
 
239
263
  useEffect(() => () => {
264
+ promptEditRevision.current += 1;
240
265
  runSeqRef.current += 1;
241
266
  abortControllerRef.current?.observation.abort('studio-view-closed');
242
267
  }, []);
@@ -249,6 +274,7 @@ function TextStudioShell({
249
274
 
250
275
  async function run(nextPrompt = prompt, nextContext = context, replay = false) {
251
276
  if (abortControllerRef.current) return;
277
+ if (!replay && inputPreparationsRef.current.has(capability.id)) return;
252
278
  if (replay && !textMediaReplayable) return;
253
279
  if (replay && (!displayedRunReplayable || !replayAssetsAvailable)) return;
254
280
  const replayTextMedia = replay && (capability.id === 'text.generate' || capability.id === 'vision.locate');
@@ -259,13 +285,14 @@ function TextStudioShell({
259
285
  const runEffectiveParameters = replay && registration.parameters.restoreRecordedParameters
260
286
  ? runParameters
261
287
  : registration.parameters.project(runTarget.source, runParameters);
262
- const runHasAlternativeInput = registration.parameters.hasAlternativeInput(runParameters);
288
+ if (registration.parameters.requiredInputIssue?.(runEffectiveParameters)) return;
289
+ const runHasAlternativeInput = registration.parameters.hasAlternativeInput(runEffectiveParameters);
263
290
  // Raw document inputs retain their original whitespace so annotation
264
291
  // offsets refer to the exact text the user entered. A parameter-owned input
265
292
  // records its complete encoded request.
266
293
  const displayPrompt = recordedInput
267
294
  ? (runHasAlternativeInput ? recordedInput.encode(runEffectiveParameters) : '')
268
- : profile.rawPrompt ? nextPrompt : nextPrompt.trim();
295
+ : !promptEnabled ? '' : profile.rawPrompt ? nextPrompt : nextPrompt.trim();
269
296
  if (!hasStudioCapabilityRunInput({ requiresPrompt, prompt: displayPrompt, hasAlternativeInput: runHasAlternativeInput })) return;
270
297
  if ((capability.id === 'music.transcribe' || capability.id === 'audio.voice.convert' || capability.id === 'audio.separate') && !runHasAlternativeInput) return;
271
298
  if (profile.requiresParameterInput && !runHasAlternativeInput) return;
@@ -287,6 +314,7 @@ function TextStudioShell({
287
314
  prompt: displayPrompt || (runHasAlternativeInput ? '' : preset.prompt),
288
315
  context: nextContext.trim(),
289
316
  createdAt: new Date(startedAt).toISOString(),
317
+ configuredTarget: { source: runTarget.source, targetLabel: runTarget.targetLabel },
290
318
  result: null,
291
319
  record: null,
292
320
  error: null,
@@ -316,7 +344,8 @@ function TextStudioShell({
316
344
  }
317
345
  }
318
346
  abortController.signal.throwIfAborted();
319
- const isStreaming = capability.id === 'chat.stream';
347
+ const isStreaming = capability.id === 'chat.stream'
348
+ || (capability.id === 'text.tools' && submittedParameters.delivery === 'stream');
320
349
  if (isStreaming) setStreamingText('');
321
350
  const directive = textStudioDirectiveForTarget(runTarget, profile);
322
351
  if (capability.id === 'text.generate' && runAttachments.length > 0 &&
@@ -332,7 +361,7 @@ function TextStudioShell({
332
361
  recordedRunConfig: runConfig,
333
362
  recordedCreatedAt: pendingRun.createdAt,
334
363
  recordedPrompt: displayPrompt,
335
- prompt: (capability.id === 'world.generate' && runHasAlternativeInput && !displayPrompt && !nextContext.trim()) || usesVerbatimStudioPrompt(capability.id) || profile.rawPrompt || recordedInput
364
+ prompt: ((capability.id === 'world.generate' || capability.id === 'video.generate') && runHasAlternativeInput && !displayPrompt && !nextContext.trim()) || usesVerbatimStudioPrompt(capability.id) || profile.rawPrompt || recordedInput
336
365
  ? displayPrompt
337
366
  : textStudioRuntimePrompt(displayPrompt, nextContext, directive),
338
367
  scenarioId: preset.id,
@@ -390,11 +419,11 @@ function TextStudioShell({
390
419
  next[finishedRun.id] = finishedRun;
391
420
  return next;
392
421
  });
393
- setActiveRun(finishedRun);
422
+ setActiveRun(current => current?.id === pendingRun.id ? finishedRun : current);
394
423
  } catch (error) {
395
424
  if (runSeq !== runSeqRef.current) return;
396
425
  const message = error instanceof Error ? error.message : String(error || 'Runtime call failed.');
397
- setActiveRun({ ...pendingRun, error: message });
426
+ setActiveRun(current => current?.id === pendingRun.id ? { ...pendingRun, error: message } : current);
398
427
  } finally {
399
428
  if (runSeq === runSeqRef.current) {
400
429
  if (abortControllerRef.current?.controller === abortController) abortControllerRef.current = null;
@@ -428,12 +457,12 @@ function TextStudioShell({
428
457
  if (currentResult.ok && currentResult.output.kind === 'artifacts') {
429
458
  const artifact = currentResult.output.firstArtifact;
430
459
  if (artifact?.relativePath) {
431
- await revealStudioAsset(rendererHost, artifact.relativePath);
460
+ await exportStudioAsset(rendererHost, artifact.relativePath);
432
461
  }
433
462
  return;
434
463
  }
435
464
  if (currentResult.ok && currentResult.output.kind === 'text-annotation') {
436
- await revealStudioAsset(rendererHost, currentResult.output.document.relativePath);
465
+ await exportStudioAsset(rendererHost, currentResult.output.document.relativePath);
437
466
  return;
438
467
  }
439
468
  const stamp = new Date(rendererHost.clock.now()).toISOString().replace(/[:.]/g, '-');
@@ -476,12 +505,12 @@ function TextStudioShell({
476
505
  const restored = recordedInput.decode(record.prompt);
477
506
  if (!restored || !parameterStore) return;
478
507
  parameterStore.setParameters(capability.id, { ...capabilityParameters, ...restored });
479
- setActiveRun(null);
508
+ handleNewRun();
480
509
  return;
481
510
  }
482
511
  updatePrompt(record.prompt);
483
512
  setContext(record.runConfig?.promptControls.context ?? '');
484
- setActiveRun(null);
513
+ handleNewRun();
485
514
  }
486
515
 
487
516
  const historyPreviewId = useRef<string | null>(null);
@@ -513,8 +542,8 @@ function TextStudioShell({
513
542
  : 'Studio.profiles.textGenerate.imageTargetUnsupported') : undefined}
514
543
  onOpenAttachmentPicker={composerState.openAttachmentPicker}
515
544
  onRemoveAttachment={composerState.removeAttachment}
516
- canDispatch={runTarget.canDispatch}
517
- canConfigureIntent={canConfigureRunTarget(runTarget)}
545
+ canDispatch={runTarget.canDispatch && !preparingInput}
546
+ canConfigureIntent={!runTarget.configReadFailed && canConfigureRunTarget(runTarget)}
518
547
  intentConfigurable={capability.execution === 'runtime-sdk'}
519
548
  compact={Boolean(activeRun)}
520
549
  parameterPanel={parameterStore && capability.execution === 'runtime-sdk' && ParameterPanel ? (
@@ -523,26 +552,41 @@ function TextStudioShell({
523
552
  contract={registration.parameters}
524
553
  source={runTarget.source}
525
554
  parameters={capabilityParameters}
526
- disabled={running}
555
+ disabled={running || preparingInput}
527
556
  onChange={(next) => parameterStore.setParameters(capability.id, next)}
557
+ onInputPreparationStart={startInputPreparation}
528
558
  />
529
559
  ) : undefined}
530
560
  parametersActive={Object.keys(parameterSummary).length > 0}
531
561
  hasAlternativeInput={hasAlternativeInput}
562
+ promptEnabled={promptEnabled}
563
+ inputIssue={inputIssueKey ? t(inputIssueKey) : undefined}
532
564
  onPromptChange={updatePrompt}
533
565
  onContextChange={setContext}
534
566
  onOpenIntentConfig={onOpenConfig}
535
567
  onSubmit={() => void run()}
536
568
  />
537
569
  );
538
- const showAdmissionBadge = true;
539
-
540
570
  function handleHistoryCollapseToggle() {
541
- historyPanel?.setCollapsed(!historyCollapsed);
571
+ if (compactHistory) setCompactHistoryOpen((open) => !open);
572
+ else historyPanel?.setCollapsed(!historyCollapsed);
573
+ }
574
+
575
+ function closeCompactHistory() {
576
+ setCompactHistoryOpen(false);
577
+ historyToggleRef.current?.focus();
578
+ }
579
+
580
+ function selectHistoryRecord(record: StudioRunHistoryRecord) {
581
+ onSelectHistoryRun(record);
582
+ if (compactHistory) closeCompactHistory();
542
583
  }
543
584
 
544
585
  function handleNewRun() {
545
586
  setActiveRun(null);
587
+ workspaceRef.current?.ownerDocument.defaultView?.requestAnimationFrame(() => {
588
+ workspaceRef.current?.querySelector<HTMLElement>('.studio-start')?.focus();
589
+ });
546
590
  }
547
591
 
548
592
  function handleCancel() {
@@ -554,17 +598,43 @@ function TextStudioShell({
554
598
 
555
599
  return (
556
600
  <div className={hasActiveRun ? 'studio studio--has-run' : 'studio studio--landing'}>
557
- <div className="studio__workspace studio__workspace--with-history">
601
+ <div
602
+ ref={workspaceRef}
603
+ className={compactHistory ? 'studio__workspace studio__workspace--overlay-history' : 'studio__workspace studio__workspace--with-history'}
604
+ >
558
605
  <div className="studio__primary">
559
606
  <header className="studio__head">
560
- <div className="studio__title">
561
- {showAdmissionBadge ? (
607
+ <div className="studio__heading">
608
+ <div className="studio__title">
609
+ <h2>{t(capability.labelKey)}</h2>
610
+ {capability.capabilityContract ? <code>{capability.capabilityContract}</code> : null}
611
+ </div>
612
+ <div className="studio__status" role="status">
613
+ {capability.execution === 'runtime-sdk' ? (
614
+ <span className="studio__runtime-state">
615
+ {t(runtime?.status === 'connected' ? 'Studio.run.runtimeConnected'
616
+ : runtime ? 'Studio.run.runtimeUnavailable' : 'Studio.run.runtimeChecking')}
617
+ </span>
618
+ ) : null}
562
619
  <StatusBadge tone={admission.tone} shape="dot">
563
620
  {t(registration.profile.statusLabelKey ?? ADMISSION_STATUS_LABEL_KEY[admission.label] ?? admission.label)}
564
621
  </StatusBadge>
565
- ) : null}
622
+ {runTarget.configReadFailed && runtime?.status === 'connected' ? (
623
+ <span className="studio__runtime-state">{t('Studio.run.aiConfigLoadFailed')}</span>
624
+ ) : null}
625
+ {runTarget.status === 'blocked' && runTarget.source !== 'unknown' ? (
626
+ <span className="studio__runtime-state">{runTarget.detail}</span>
627
+ ) : null}
628
+ </div>
566
629
  </div>
567
630
  <div className="studio__head-actions">
631
+ {canRetryPreparation ? (
632
+ <Button type="button" size="sm" tone="secondary" onClick={() => {
633
+ if (workspaceRef.current) notifyStudioAIConfigChanged(workspaceRef.current);
634
+ }}>
635
+ {t('Studio.run.retryPreparation')}
636
+ </Button>
637
+ ) : null}
568
638
  {headerActions}
569
639
  {executingRun && !displayingExecution ? (
570
640
  <Button size="sm" tone="secondary" onClick={() => setActiveRun(executingRun)}>
@@ -572,22 +642,23 @@ function TextStudioShell({
572
642
  </Button>
573
643
  ) : null}
574
644
  {hasActiveRun ? (
575
- <Tooltip content={t('StudioShell.newRun')} placement="bottom">
576
- <IconButton
577
- type="button"
578
- className="studio-history-toggle"
579
- aria-label={t('StudioShell.newRun')}
580
- onClick={handleNewRun}
581
- disabled={running}
582
- icon={<SquarePen size={17} strokeWidth={1.8} aria-hidden="true" />}
583
- />
584
- </Tooltip>
645
+ <Button
646
+ type="button"
647
+ size="sm"
648
+ tone="secondary"
649
+ onClick={handleNewRun}
650
+ disabled={running}
651
+ leadingIcon={<SquarePen size={15} aria-hidden="true" />}
652
+ >
653
+ {t('StudioShell.newRun')}
654
+ </Button>
585
655
  ) : null}
586
656
  <Tooltip
587
657
  content={historyCollapsed ? t('StudioShell.showHistory') : t('StudioShell.hideHistory')}
588
658
  placement="bottom"
589
659
  >
590
660
  <IconButton
661
+ ref={historyToggleRef}
591
662
  type="button"
592
663
  className={historyCollapsed ? 'studio-history-toggle' : 'studio-history-toggle studio-history-toggle--expanded'}
593
664
  aria-label={historyCollapsed ? t('StudioShell.showHistory') : t('StudioShell.hideHistory')}
@@ -597,6 +668,7 @@ function TextStudioShell({
597
668
  />
598
669
  </Tooltip>
599
670
  </div>
671
+ {draftError ? <InlineAlert className="studio__head-alert" tone="warning">{draftError}</InlineAlert> : null}
600
672
  </header>
601
673
  <main className="studio__stage">
602
674
  {hasActiveRun && displayedRun ? (
@@ -604,11 +676,12 @@ function TextStudioShell({
604
676
  registration={registration}
605
677
  activeRun={displayedRun}
606
678
  admission={admission}
607
- intentLabel={displayedRun.record ? getStudioRunIntentLabel(displayedRun.record) : runTarget.intentLabel}
679
+ intentLabel={studioConfiguredTargetLabel(displayedRun.record?.runConfig?.target ?? displayedRun.configuredTarget, t)}
608
680
  running={displayingExecution}
609
681
  canRestoreInputs={displayedRunParameters !== null}
610
682
  canRegenerate={!running && runTarget.canDispatch && (capability.id !== 'vision.locate' || Boolean(savedTextMedia)) && textMediaReplayable && displayedRunReplayable && replayAssetsAvailable}
611
- regenerateHint={!running && !textMediaReplayable ? t('Studio.profiles.textGenerate.savedMediaUnavailable')
683
+ regenerateHint={currentResult && !currentResult.ok && currentResult.reason === 'input-invalid' ? undefined
684
+ : !running && !textMediaReplayable ? t('Studio.profiles.textGenerate.savedMediaUnavailable')
612
685
  : !running && replayAssetsChecking ? t('StudioShell.historyInputsChecking')
613
686
  : !running && (!displayedRunReplayable || !replayAssetsAvailable) ? t('StudioShell.historyInputsUnavailable') : undefined}
614
687
  cancelRequested={displayingExecution && cancelRequested}
@@ -635,13 +708,22 @@ function TextStudioShell({
635
708
  />
636
709
  )}
637
710
  {displayingExecution && observationIssue ? <p role="status">{t('Music.observationIssue')}</p> : null}
638
- {isStudioJobRecoveryCapability(capability.id) ? <StudioJobRecoveryPanel key={capability.id} capability={capability.id} disabled={running} /> : null}
711
+ {isStudioJobRecoveryCapability(capability.id) ? (
712
+ <StudioJobRecoveryPanel
713
+ key={capability.id}
714
+ capability={capability.id}
715
+ disabled={running}
716
+ history={history?.[capability.id]}
717
+ onSelectHistoryRun={selectHistoryRecord}
718
+ />
719
+ ) : null}
639
720
  </main>
640
721
  </div>
641
722
  <CapabilityRunHistory
642
723
  history={history}
643
724
  activeRunId={displayedRun?.id ?? null}
644
- onSelectRun={onSelectHistoryRun}
725
+ onSelectRun={selectHistoryRecord}
726
+ onClose={compactHistory ? closeCompactHistory : undefined}
645
727
  collapsed={historyCollapsed}
646
728
  currentCapabilityId={capability.id}
647
729
  registrations={registrations}
@@ -35,7 +35,9 @@ export type AIStudioHistoryProjection = {
35
35
  readonly mediaHistory: readonly StudioMediaHistoryRecord[];
36
36
  };
37
37
 
38
+ type SavedHistoryRefreshFailure = { readonly record: StudioRunHistoryRecord; readonly refreshError: string };
38
39
  export type AIStudioHistoryPersistOutcome =
40
+ | ({ readonly ok: true } & SavedHistoryRefreshFailure)
39
41
  | { readonly ok: true; readonly projection: AIStudioHistoryProjection; readonly record?: StudioRunHistoryRecord }
40
42
  | {
41
43
  readonly ok: false;
@@ -76,7 +78,7 @@ export type AIStudioHistoryRepository = {
76
78
  readonly result: StudioCapabilityRunResult;
77
79
  readonly record: StudioRunHistoryRecord;
78
80
  }) => Promise<AIStudioHistoryPersistOutcome>;
79
- readonly appendRecord: (record: StudioRunHistoryRecord) => Promise<AIStudioHistoryProjection>;
81
+ readonly appendRecord: (record: StudioRunHistoryRecord) => Promise<AIStudioHistoryProjection | SavedHistoryRefreshFailure>;
80
82
  readonly cleanupArtifacts: (relativePaths: readonly string[]) => Promise<AIStudioArtifactCleanupOutcome>;
81
83
  readonly remove: (recordId: string, deleteAssets: boolean) => Promise<AIStudioHistoryMutationOutcome>;
82
84
  readonly clear: (capabilityId: string | null, deleteAssets: boolean) => Promise<AIStudioHistoryMutationOutcome>;
@@ -126,7 +128,7 @@ export type AIStudioWorkspaceController = {
126
128
  };
127
129
 
128
130
  type AIStudioHistoryIssue =
129
- | { readonly kind: 'load'; readonly message: string }
131
+ | { readonly kind: 'load'; readonly message: string; readonly saved?: boolean }
130
132
  | {
131
133
  readonly kind: 'save';
132
134
  readonly message: string;
@@ -167,10 +169,12 @@ export function useAIStudioWorkspaceController({
167
169
  const next = await historyRepository.load();
168
170
  if (!active.current || currentRepository.current !== historyRepository) return;
169
171
  setProjection(next);
170
- setHistoryIssue(null);
172
+ setHistoryIssue(current => current?.kind === 'save' ? current : null);
171
173
  } catch (error) {
172
174
  if (!active.current || currentRepository.current !== historyRepository) return;
173
- setHistoryIssue({ kind: 'load', message: errorMessage(error, 'History load failed.') });
175
+ setHistoryIssue(current => current?.kind === 'save' ? current : {
176
+ kind: 'load', saved: current?.saved, message: errorMessage(error, 'History load failed.'),
177
+ });
174
178
  }
175
179
  }, [historyRepository]);
176
180
 
@@ -183,6 +187,10 @@ export function useAIStudioWorkspaceController({
183
187
  try {
184
188
  const next = await historyRepository.appendRecord(record);
185
189
  if (!active.current || currentRepository.current !== historyRepository) return;
190
+ if ('refreshError' in next) {
191
+ setHistoryIssue(current => current?.kind === 'save' ? current : { kind: 'load', saved: true, message: next.refreshError });
192
+ return;
193
+ }
186
194
  setProjection(next);
187
195
  setHistoryIssue((current) => {
188
196
  if (!current || current.kind === 'load') return null;
@@ -280,18 +288,21 @@ export function useAIStudioWorkspaceController({
280
288
  outcome = await historyRepository.persist({ result, record });
281
289
  } catch (error) {
282
290
  const message = errorMessage(error, 'History persistence failed.');
283
- setHistoryIssue({ kind: 'save', message, records: [record], cleanupPaths: [] });
291
+ setHistoryIssue(current => ({ kind: 'save', message,
292
+ records: [...(current?.kind === 'save' ? current.records.filter(item => item.id !== record.id) : []), record],
293
+ cleanupPaths: current?.kind === 'save' ? current.cleanupPaths : [] }));
284
294
  throw new Error(message);
285
295
  }
286
296
  if (outcome.ok) {
287
- setProjection(outcome.projection);
297
+ const refreshIssue = 'refreshError' in outcome ? { kind: 'load' as const, saved: true, message: outcome.refreshError } : null;
298
+ if ('projection' in outcome) setProjection(outcome.projection);
288
299
  setHistoryIssue((current) => {
289
- if (!current || current.kind === 'load') return null;
300
+ if (!current || current.kind === 'load') return refreshIssue;
290
301
  const records = current.records.filter((pending) => pending.id !== record.id
291
302
  && !(pending.capabilityId === record.capabilityId && pending.result?.ok && record.result?.ok
292
303
  && 'jobId' in pending.result && 'jobId' in record.result && pending.result.jobId === record.result.jobId));
293
304
  return records.length === 0 && current.cleanupPaths.length === 0
294
- ? null
305
+ ? refreshIssue
295
306
  : { ...current, records };
296
307
  });
297
308
  return outcome.record ?? record;
@@ -327,30 +338,42 @@ export function useAIStudioWorkspaceController({
327
338
  await refreshHistory();
328
339
  return;
329
340
  }
330
- setHistoryIssue(null);
331
- const cleanup = await historyRepository.cleanupArtifacts(issue.cleanupPaths);
341
+ let cleanup: AIStudioArtifactCleanupOutcome;
342
+ try {
343
+ cleanup = await historyRepository.cleanupArtifacts(issue.cleanupPaths);
344
+ } catch (error) {
345
+ setHistoryIssue(current => current?.kind === 'save'
346
+ ? { ...current, message: errorMessage(error, 'History cleanup failed.') } : current);
347
+ return;
348
+ }
349
+ let refreshError: string | undefined;
332
350
  const retryErrors = [...cleanup.failures];
333
351
  let completed = 0;
334
352
  let nextProjection: AIStudioHistoryProjection | null = null;
335
353
  for (const record of issue.records) {
336
354
  try {
337
- nextProjection = await historyRepository.appendRecord(record);
355
+ const saved = await historyRepository.appendRecord(record);
356
+ if ('refreshError' in saved) refreshError = saved.refreshError;
357
+ else nextProjection = saved;
338
358
  completed += 1;
339
359
  } catch (error) {
340
360
  retryErrors.push(errorMessage(error, 'History persistence failed.'));
341
361
  break;
342
362
  }
343
363
  }
364
+ if (!active.current || currentRepository.current !== historyRepository) return;
344
365
  if (nextProjection) setProjection(nextProjection);
345
- const records = issue.records.slice(completed);
346
- if (retryErrors.length || records.length || cleanup.remainingCleanupPaths.length) {
347
- setHistoryIssue({
348
- kind: 'save',
349
- message: retryErrors.join(' ') || 'History persistence retry is incomplete.',
350
- records,
351
- cleanupPaths: cleanup.remainingCleanupPaths,
352
- });
353
- }
366
+ const attemptedIds = new Set(issue.records.slice(0, completed).map(record => record.id));
367
+ const clearedPaths = new Set(issue.cleanupPaths.filter(path => !cleanup.remainingCleanupPaths.includes(path)));
368
+ setHistoryIssue(current => {
369
+ if (current?.kind !== 'save') return current;
370
+ const records = current.records.filter(record => !attemptedIds.has(record.id));
371
+ const cleanupPaths = current.cleanupPaths.filter(path => !clearedPaths.has(path));
372
+ if (retryErrors.length || records.length || cleanupPaths.length) {
373
+ return { ...current, records, cleanupPaths, message: retryErrors.join(' ') || current.message };
374
+ }
375
+ return refreshError ? { kind: 'load', saved: true, message: refreshError } : null;
376
+ });
354
377
  }, [historyIssue, historyRepository, refreshHistory]);
355
378
 
356
379
  const selectionEntry = useRef<string | null>(null);
@@ -369,13 +392,17 @@ export function useAIStudioWorkspaceController({
369
392
  nimiToast.warning(translate('History.unsupportedCapability'));
370
393
  return;
371
394
  }
395
+ if (selectedRecord?.id === record.id && selectedRecord.capabilityId === record.capabilityId) {
396
+ setHistorySelectionRequest(current => ({ requestId: (current?.requestId ?? 0) + 1, record: selectedRecord }));
397
+ return;
398
+ }
372
399
  onSelectCapability(record.capabilityId, record.id);
373
- }, [onSelectCapability, registrations, translate]);
400
+ }, [onSelectCapability, registrations, selectedRecord, translate]);
374
401
 
375
402
  return {
376
403
  parameterStore,
377
404
  historyLoadState: {
378
- title: translate(historyIssue?.kind === 'save' ? 'History.saveFailedTitle' : 'History.loadFailedTitle'),
405
+ title: translate(historyIssue?.kind === 'save' ? 'History.saveFailedTitle' : historyIssue?.saved ? 'History.savedRefreshFailedTitle' : 'History.loadFailedTitle'),
379
406
  error: historyIssue?.message ?? null,
380
407
  retry: () => { void retryHistory(); },
381
408
  },