@nimiplatform/app-tools 0.7.5 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/README.md +59 -5
  2. package/bin/nimi-app.mjs +11 -3
  3. package/lib/app-access-declaration.mjs +1 -0
  4. package/lib/app-dependency-combinations.mjs +16 -28
  5. package/lib/app-doctor-update.mjs +66 -7
  6. package/lib/app-info.mjs +8 -1
  7. package/lib/app-project-lifecycle.mjs +82 -9
  8. package/lib/app-scaffold-capabilities.mjs +3 -3
  9. package/lib/app-scaffold-profiles.mjs +96 -26
  10. package/lib/app-scaffold.mjs +54 -7
  11. package/lib/canonical-capability-ids.generated.mjs +4 -0
  12. package/package.json +26 -25
  13. package/scripts/dev-shell.mjs +61 -17
  14. package/skills/nimi-app-lifecycle/references/acceptance.md +1 -1
  15. package/skills/nimi-app-lifecycle/references/adapt.md +2 -2
  16. package/skills/nimi-app-lifecycle/references/release.md +1 -1
  17. package/skills/nimi-app-lifecycle/references/upgrade-platform.md +14 -0
  18. package/templates/app-source/src/ai-studio-core/ai-config.ts +17 -3
  19. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +40 -3
  20. package/templates/app-source/src/ai-studio-core/audio-separation-request.ts +24 -0
  21. package/templates/app-source/src/ai-studio-core/contexts.tsx +4 -0
  22. package/templates/app-source/src/ai-studio-core/history-policy.ts +395 -41
  23. package/templates/app-source/src/ai-studio-core/history.ts +262 -10
  24. package/templates/app-source/src/ai-studio-core/host-context.tsx +15 -2
  25. package/templates/app-source/src/ai-studio-core/index.ts +15 -4
  26. package/templates/app-source/src/ai-studio-core/job-recovery-panel.tsx +105 -0
  27. package/templates/app-source/src/ai-studio-core/job-recovery.ts +224 -0
  28. package/templates/app-source/src/ai-studio-core/managed-result-references.ts +79 -0
  29. package/templates/app-source/src/ai-studio-core/messages/en.json +185 -10
  30. package/templates/app-source/src/ai-studio-core/messages/zh.json +185 -10
  31. package/templates/app-source/src/ai-studio-core/module-registration.ts +9 -1
  32. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +81 -2
  33. package/templates/app-source/src/ai-studio-core/parameters.ts +34 -1
  34. package/templates/app-source/src/ai-studio-core/runtime-types.ts +124 -8
  35. package/templates/app-source/src/ai-studio-core/runtime.ts +218 -20
  36. package/templates/app-source/src/ai-studio-core/section-ai-testing-annotation-result.tsx +123 -0
  37. package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +3 -0
  38. package/templates/app-source/src/ai-studio-core/section-ai-testing-audio-separation-result.tsx +26 -0
  39. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +14 -7
  40. package/templates/app-source/src/ai-studio-core/section-ai-testing-decision-result.tsx +76 -0
  41. package/templates/app-source/src/ai-studio-core/section-ai-testing-exchange-result.tsx +71 -0
  42. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +20 -4
  43. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +29 -0
  44. package/templates/app-source/src/ai-studio-core/section-ai-testing-music-result.tsx +45 -0
  45. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +132 -10
  46. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +122 -38
  47. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +4 -3
  48. package/templates/app-source/src/ai-studio-core/section-ai-testing-session-result.tsx +66 -0
  49. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +100 -22
  50. package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +6 -0
  51. package/templates/app-source/src/ai-studio-core/section-ai-testing-transcript-result.tsx +45 -0
  52. package/templates/app-source/src/ai-studio-core/section-ai-testing-transcription-result.tsx +106 -0
  53. package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +23 -4
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-voice-asset-actions.tsx +40 -0
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-voice-conversion-result.tsx +20 -0
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +219 -35
  57. package/templates/app-source/src/ai-studio-core/text-annotation-document.ts +50 -0
  58. package/templates/app-source/src/ai-studio-core/text-media-replay.ts +51 -0
  59. package/templates/app-source/src/ai-studio-core/voice-assets.ts +17 -0
  60. package/templates/app-source/src/ai-studio-core/workspace.tsx +48 -6
  61. package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +1 -1
  62. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +13 -1
  63. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +13 -1
  64. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +11 -2
  65. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +2 -2
  66. package/templates/app-source/src/studio-modules/studio-create/registration.ts +2 -2
  67. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +121 -3
  68. package/templates/app-source/src/studio-modules/studio-media/audio-separate-parameters.tsx +72 -0
  69. package/templates/app-source/src/studio-modules/studio-media/audio-separate-runtime.ts +90 -0
  70. package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +16 -1
  71. package/templates/app-source/src/studio-modules/studio-media/index.ts +2 -0
  72. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +225 -7
  73. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +225 -7
  74. package/templates/app-source/src/studio-modules/studio-media/music-parameters.tsx +85 -0
  75. package/templates/app-source/src/studio-modules/studio-media/music-transcription-parameters.tsx +85 -0
  76. package/templates/app-source/src/studio-modules/studio-media/music-transcription-runtime.ts +64 -0
  77. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +9 -26
  78. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +170 -6
  79. package/templates/app-source/src/studio-modules/studio-media/registration.ts +29 -1
  80. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +90 -6
  81. package/templates/app-source/src/studio-modules/studio-media/vision-parameters.tsx +1 -0
  82. package/templates/app-source/src/studio-modules/studio-media/vision-runtime.ts +23 -5
  83. package/templates/app-source/src/studio-modules/studio-media/voice-convert-parameters.tsx +132 -0
  84. package/templates/app-source/src/studio-modules/studio-media/voice-convert-runtime.ts +120 -0
  85. package/templates/app-source/src/studio-modules/studio-voice/audio-url.ts +25 -0
  86. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +4 -4
  87. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +4 -4
  88. package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +28 -0
  89. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +66 -30
  90. package/templates/app-source/src/workbench-core/index.ts +2 -0
  91. package/templates/app-source/src/workbench-core/runtime-gate.tsx +102 -6
  92. package/templates/app-source/src/workbench-core/workbench-core.css +42 -0
  93. package/templates/app-source/src/workbench-core/workbench-core.tsx +69 -18
  94. package/templates/app-source.manifest.json +100 -0
  95. package/templates/default-starter/README.md +2 -1
  96. package/templates/default-starter/src/shell/workbench-target-adapter.ts +102 -12
  97. package/templates/default-starter.manifest.json +0 -4
@@ -1,6 +1,6 @@
1
- import type { RuntimeVoiceCatalogRuntime } from '@nimiplatform/kit/features/generation/runtime';
1
+ import { observeRuntimeSpeechSynthesize, observeRuntimeSpeechTranscribe, type RuntimeSpeechTranscribeResult, type RuntimeVoiceCatalogRuntime } from '@nimiplatform/kit/features/generation/runtime';
2
2
  import { buildNimiRuntimeScenarioJobIdentity } from '@nimiplatform/sdk/features/generation';
3
- import { runNimiRuntimeScenarioJob } from '@nimiplatform/sdk/runtime';
3
+ import { runNimiRuntimeScenarioJob, observeNimiRuntimeScenarioJob, type NimiRuntimeScenarioJobResult } from '@nimiplatform/sdk/runtime';
4
4
  import {
5
5
  ExecutionMode,
6
6
  ScenarioType,
@@ -8,9 +8,12 @@ import {
8
8
  VoiceCreationSource,
9
9
  } from '@nimiplatform/sdk/runtime/generated';
10
10
  import type { StudioCapabilityRuntimeHandlers } from '../../ai-studio-core/runtime-dispatcher.js';
11
+ import { audioMimeTypeFromUrl, isHttpsUrl } from './audio-url.js';
12
+ import { listLabVoiceAssets } from '../../ai-studio-core/voice-assets.js';
11
13
  import {
12
- createStudioScenarioJobClient,
14
+ createStudioScenarioJobClient, recoverStudioJobAction, adoptStudioJobArtifact,
13
15
  projectStudioArtifactRunnerResult,
16
+ managedStudioAssetPath,
14
17
  projectStudioRunnerNonSuccess,
15
18
  type StudioCapabilityRuntimeContext,
16
19
  } from '../../ai-studio-core/runtime.js';
@@ -38,6 +41,14 @@ export const studioVoiceRuntimeHandlers: StudioCapabilityRuntimeHandlers = Objec
38
41
  });
39
42
 
40
43
  async function runSpeechSynthesize(context: StudioCapabilityRuntimeContext) {
44
+ const recovery = await recoverStudioJobAction(context, ScenarioType.SPEECH_SYNTHESIZE);
45
+ if (recovery) {
46
+ if (recovery.saved) return recovery.saved;
47
+ const result = await observeRuntimeSpeechSynthesize({ runtime: { ai: createStudioScenarioJobClient(context) }, jobId: recovery.jobId!,
48
+ signal: context.input.observationSignal, cancelSignal: context.input.signal, abortReason: context.host.abortReason,
49
+ onObservation: context.input.onObservation, onJobUpdate: context.input.onJobUpdate });
50
+ return projectStudioArtifactRunnerResult(context, result);
51
+ }
41
52
  if (!context.prompt) return inputRequired(context);
42
53
  const parameters = context.input.parameters as StudioSpeechSynthesizeParameters | undefined;
43
54
  const voiceRef = speechVoiceReference(parameters);
@@ -56,6 +67,8 @@ async function runSpeechSynthesize(context: StudioCapabilityRuntimeContext) {
56
67
  ...(parameters?.timingMode !== undefined ? { timingMode: parameters.timingMode } : {}),
57
68
  scenarioId: context.scenarioId,
58
69
  surfaceId: context.host.surfaceId,
70
+ observationSignal: context.input.observationSignal,
71
+ onObservation: context.input.onObservation,
59
72
  ...(context.input.signal ? {
60
73
  signal: context.input.signal,
61
74
  abortReason: context.host.abortReason,
@@ -65,6 +78,15 @@ async function runSpeechSynthesize(context: StudioCapabilityRuntimeContext) {
65
78
  }
66
79
 
67
80
  async function runSpeechTranscribe(context: StudioCapabilityRuntimeContext) {
81
+ const recovery = await recoverStudioJobAction(context, ScenarioType.SPEECH_TRANSCRIBE);
82
+ if (recovery) {
83
+ if (recovery.saved) return recovery.saved;
84
+ const result = await observeRuntimeSpeechTranscribe({ runtime: { ai: createStudioScenarioJobClient(context) }, jobId: recovery.jobId!,
85
+ timestamps: recovery.entry.details?.timestamps,
86
+ signal: context.input.observationSignal, cancelSignal: context.input.signal, abortReason: context.host.abortReason,
87
+ onObservation: context.input.onObservation, onJobUpdate: context.input.onJobUpdate });
88
+ return projectStudioTranscript(context, result);
89
+ }
68
90
  const parameters = context.input.parameters as StudioSpeechTranscribeParameters | undefined;
69
91
  if (!context.prompt && !parameters?.audioFile) return inputRequired(context);
70
92
  if (parameters?.audioFile && parameters.audioFile.sizeBytes > MAX_STUDIO_AUDIO_UPLOAD_BYTES) {
@@ -99,11 +121,17 @@ async function runSpeechTranscribe(context: StudioCapabilityRuntimeContext) {
99
121
  ...(parameters?.responseFormat !== undefined ? { responseFormat: parameters.responseFormat } : {}),
100
122
  scenarioId: context.scenarioId,
101
123
  surfaceId: context.host.surfaceId,
124
+ observationSignal: context.input.observationSignal,
125
+ onObservation: context.input.onObservation,
102
126
  ...(context.input.signal ? {
103
127
  signal: context.input.signal,
104
128
  abortReason: context.host.abortReason,
105
129
  } : {}),
106
130
  });
131
+ return projectStudioTranscript(context, result);
132
+ }
133
+
134
+ function projectStudioTranscript(context: StudioCapabilityRuntimeContext, result: RuntimeSpeechTranscribeResult) {
107
135
  if (result.ok === false) return projectStudioRunnerNonSuccess(context, result);
108
136
  return {
109
137
  ok: true as const,
@@ -116,12 +144,23 @@ async function runSpeechTranscribe(context: StudioCapabilityRuntimeContext) {
116
144
  jobId: result.output.jobId,
117
145
  jobState: result.output.jobStatus,
118
146
  artifactCount: result.output.artifactCount,
147
+ ...(result.output.transcription ? { transcription: result.output.transcription } : {}),
119
148
  },
120
149
  ...(result.trace?.traceId ? { trace: { traceId: result.trace.traceId } } : {}),
121
150
  };
122
151
  }
123
152
 
124
153
  async function runVoiceCreate(context: StudioCapabilityRuntimeContext) {
154
+ const recovery = await recoverStudioJobAction(context, ScenarioType.VOICE_CREATE);
155
+ if (recovery) {
156
+ if (recovery.saved) return recovery.saved;
157
+ const source = recovery.entry.details?.creationSource;
158
+ if (!source) throw new Error('Saved voice action is missing its creation source');
159
+ const result = await observeNimiRuntimeScenarioJob({ ai: createStudioScenarioJobClient(context), jobId: recovery.jobId!, scenarioType: ScenarioType.VOICE_CREATE,
160
+ signal: context.input.observationSignal, cancelSignal: context.input.signal, abortReason: context.host.abortReason,
161
+ onObservation: context.input.onObservation, onJobUpdate: context.input.onJobUpdate });
162
+ return projectVoiceCreation(context, result, source);
163
+ }
125
164
  const parameters = context.input.parameters as StudioVoiceCreateParameters | undefined;
126
165
  const creationSource = parameters?.creationSource ?? 'reference-audio';
127
166
  if (!context.prompt && !parameters?.referenceAudioFile) return inputRequired(context);
@@ -188,11 +227,17 @@ async function runVoiceCreate(context: StudioCapabilityRuntimeContext) {
188
227
  labels: { scenarioId: context.scenarioId, surfaceId: context.host.surfaceId },
189
228
  extensions: [],
190
229
  },
230
+ observationSignal: context.input.observationSignal,
231
+ onObservation: context.input.onObservation,
191
232
  ...(context.input.signal ? {
192
233
  signal: context.input.signal,
193
234
  abortReason: context.host.abortReason,
194
235
  } : {}),
195
236
  });
237
+ return projectVoiceCreation(context, terminalResult, creationSource);
238
+ }
239
+
240
+ async function projectVoiceCreation(context: StudioCapabilityRuntimeContext, terminalResult: NimiRuntimeScenarioJobResult, creationSource: 'reference-audio' | 'text-description') {
196
241
  const terminalJob = terminalResult.job;
197
242
  const resultAsset = terminalResult.asset;
198
243
  const voiceReference = terminalResult.voiceReference;
@@ -210,11 +255,24 @@ async function runVoiceCreate(context: StudioCapabilityRuntimeContext) {
210
255
  if (!returnedVoiceAssetId || returnedVoiceAssetId !== resultAsset.voiceAssetId) {
211
256
  throw new Error('Completed voice.create did not return an exact VoiceAsset reference.');
212
257
  }
213
- const listed = await context.host.client.ai.voiceAssets.list({ pageSize: 100 });
214
- const listedAsset = listed.assets.find((asset) => asset.voiceAssetId === resultAsset.voiceAssetId);
258
+ const listed = await listLabVoiceAssets(context.host.client.ai.voiceAssets);
259
+ const listedAsset = listed.find((asset) => asset.voiceAssetId === resultAsset.voiceAssetId);
215
260
  if (!listedAsset || listedAsset.status !== 'active' || listedAsset.creationSource !== creationSource) {
216
261
  throw new Error('Completed voice.create did not project its ACTIVE VoiceAsset through the protected owner catalog.');
217
262
  }
263
+ if (terminalResult.artifacts.length > 1) throw new Error('Voice creation returned multiple preview artifacts.');
264
+ const sourcePreview = terminalResult.artifacts[0];
265
+ let preview;
266
+ if (sourcePreview) {
267
+ if (!sourcePreview.artifactId || !sourcePreview.mimeType.startsWith('audio/') || Number(sourcePreview.sizeBytes) <= 0) throw new Error('Voice preview artifact metadata is invalid.');
268
+ const { asset: adopted } = await adoptStudioJobArtifact(context, sourcePreview, await managedStudioAssetPath(context.capability.id, terminalJob.jobId, 0));
269
+ if (adopted.mediaType !== sourcePreview.mimeType || adopted.sizeBytes !== Number(sourcePreview.sizeBytes)) {
270
+ await context.host.client.storage.assets.remove(adopted.relativePath);
271
+ throw new Error('Saved voice preview does not match its Runtime artifact.');
272
+ }
273
+ preview = { relativePath: adopted.relativePath, mediaType: adopted.mediaType, sizeBytes: adopted.sizeBytes, sha256: adopted.sha256, displayName: context.capability.label, previewSource: 'managed-asset' as const };
274
+ }
275
+ const expires = listedAsset.expiresAt;
218
276
  return {
219
277
  ok: true as const,
220
278
  capabilityId: context.capability.id,
@@ -227,6 +285,9 @@ async function runVoiceCreate(context: StudioCapabilityRuntimeContext) {
227
285
  voiceAssetId: listedAsset.voiceAssetId,
228
286
  creationSource: listedAsset.creationSource,
229
287
  assetStatus: listedAsset.status,
288
+ ...(preview ? { preview } : {}),
289
+ ...(expires ? { expiresAt: new Date(Number(expires.seconds) * 1000 + expires.nanos / 1e6).toISOString() } : {}),
290
+ ...(terminalJob.usage ? { inputTokens: Number(terminalJob.usage.inputTokens), outputTokens: Number(terminalJob.usage.outputTokens) } : {}),
230
291
  voiceReference: { kind: 'voice_asset_id' as const, voiceAssetId: resultAsset.voiceAssetId },
231
292
  },
232
293
  ...(terminalJob.traceId ? { trace: { traceId: terminalJob.traceId } } : {}),
@@ -317,31 +378,6 @@ function speechVoiceReference(parameters: StudioSpeechSynthesizeParameters | und
317
378
  return undefined;
318
379
  }
319
380
 
320
- function isHttpsUrl(value: string): boolean {
321
- try {
322
- return new URL(value).protocol === 'https:';
323
- } catch {
324
- return false;
325
- }
326
- }
327
-
328
- function audioMimeTypeFromUrl(value: string): string | null {
329
- try {
330
- const url = new URL(value);
331
- if (url.protocol !== 'https:') return null;
332
- const extension = url.pathname.split('.').pop()?.toLowerCase();
333
- if (extension === 'wav') return 'audio/wav';
334
- if (extension === 'mp3') return 'audio/mpeg';
335
- if (extension === 'm4a') return 'audio/mp4';
336
- if (extension === 'ogg') return 'audio/ogg';
337
- if (extension === 'webm') return 'audio/webm';
338
- if (extension === 'flac') return 'audio/flac';
339
- return null;
340
- } catch {
341
- return null;
342
- }
343
- }
344
-
345
381
  function commaSeparatedTokens(value: string | undefined): string[] {
346
382
  return (value ?? '').split(',').map((token) => token.trim()).filter(Boolean);
347
383
  }
@@ -10,6 +10,8 @@ export {
10
10
  type WorkbenchRuntimeGateCopy,
11
11
  type WorkbenchRuntimeGateProjection,
12
12
  type WorkbenchRuntimeGateProps,
13
+ type WorkbenchRuntimeGateRecoveryAction,
14
+ type WorkbenchRuntimeGateTechnicalDetail,
13
15
  } from './runtime-gate.js';
14
16
  export {
15
17
  WorkbenchEmptyState,
@@ -1,9 +1,21 @@
1
- import { useCallback, useEffect, useState, type ReactNode } from 'react';
1
+ import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react';
2
2
  import { OfflineCoordinator, type OfflineTier } from '@nimiplatform/kit/core/offline-coordinator';
3
3
  import { Button, InlineAlert, StatusBadge, Surface } from '@nimiplatform/kit/ui';
4
4
 
5
5
  // @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c
6
6
 
7
+ export type WorkbenchRuntimeGateTechnicalDetail = {
8
+ readonly label: string;
9
+ readonly value: string;
10
+ };
11
+
12
+ // A real way out of the blocked state besides checking again, such as opening
13
+ // Nimi. `run` resolves to one short plain-language result for the person.
14
+ export type WorkbenchRuntimeGateRecoveryAction = {
15
+ readonly label: string;
16
+ readonly run: () => Promise<string>;
17
+ };
18
+
7
19
  export type WorkbenchRuntimeGateProjection =
8
20
  | { readonly status: 'ready' }
9
21
  | {
@@ -11,6 +23,9 @@ export type WorkbenchRuntimeGateProjection =
11
23
  readonly body: string;
12
24
  readonly signInRequired: boolean;
13
25
  readonly nextAction?: string;
26
+ readonly recoveryAction?: WorkbenchRuntimeGateRecoveryAction;
27
+ // Reason codes and hints stay in the folded technical area.
28
+ readonly technicalDetails?: readonly WorkbenchRuntimeGateTechnicalDetail[];
14
29
  };
15
30
 
16
31
  export type WorkbenchRuntimeGateCopy = {
@@ -21,6 +36,7 @@ export type WorkbenchRuntimeGateCopy = {
21
36
  readonly retry: string;
22
37
  readonly offlineTier: (tier: OfflineTier) => string;
23
38
  readonly nextAction: (action: string) => string;
39
+ readonly technicalDetails: string;
24
40
  };
25
41
 
26
42
  export type WorkbenchRuntimeGateProps = {
@@ -29,35 +45,83 @@ export type WorkbenchRuntimeGateProps = {
29
45
  readonly resolve: () => Promise<WorkbenchRuntimeGateProjection>;
30
46
  readonly clear: () => void;
31
47
  readonly toErrorMessage: (error: unknown) => string;
48
+ // Reports a lost session after the gate opened; the gate then runs the same
49
+ // check again instead of leaving the App on stale access.
50
+ readonly revalidate?: (onLoss: () => void) => () => void;
51
+ // Called when such a re-check finds the session ready again.
52
+ readonly onRevalidated?: () => void;
32
53
  readonly children: ReactNode;
33
54
  };
34
55
 
56
+ type WorkbenchRuntimeGateBlockedProjection = Extract<WorkbenchRuntimeGateProjection, { readonly status: 'unavailable' }>;
57
+
35
58
  type WorkbenchRuntimeGateState =
36
59
  | { readonly kind: 'checking' }
37
60
  | { readonly kind: 'ready' }
38
61
  | {
39
62
  readonly kind: 'blocked';
40
- readonly projection: Extract<WorkbenchRuntimeGateProjection, { readonly status: 'unavailable' }>;
63
+ readonly projection: WorkbenchRuntimeGateBlockedProjection;
41
64
  readonly offlineTier: OfflineTier;
42
65
  };
43
66
 
67
+ type WorkbenchRuntimeGateRecoveryState =
68
+ | { readonly kind: 'idle' }
69
+ | { readonly kind: 'running' }
70
+ | { readonly kind: 'done'; readonly message: string };
71
+
44
72
  export function WorkbenchRuntimeGate({
45
73
  appTitle,
46
74
  copy,
47
75
  resolve,
48
76
  clear,
49
77
  toErrorMessage,
78
+ revalidate,
79
+ onRevalidated,
50
80
  children,
51
81
  }: WorkbenchRuntimeGateProps) {
52
82
  const [offlineCoordinator] = useState(() => new OfflineCoordinator());
53
83
  const [state, setState] = useState<WorkbenchRuntimeGateState>({ kind: 'checking' });
54
84
  const [reloadKey, setReloadKey] = useState(0);
85
+ const [recovery, setRecovery] = useState<WorkbenchRuntimeGateRecoveryState>({ kind: 'idle' });
86
+ // A recovery result belongs to the blocked check that offered it.
87
+ const recoveryGeneration = useRef(0);
88
+ // One re-check at a time answers every loss reported while it runs.
89
+ const revalidating = useRef(false);
90
+ const onRevalidatedRef = useRef(onRevalidated);
91
+ onRevalidatedRef.current = onRevalidated;
92
+
93
+ useEffect(() => {
94
+ if (!revalidate) return undefined;
95
+ return revalidate(() => {
96
+ if (revalidating.current) return;
97
+ revalidating.current = true;
98
+ // The failed request is not retried; the ready subtree stays mounted
99
+ // while the check runs and only a failed check blocks it.
100
+ clear();
101
+ setReloadKey((value) => value + 1);
102
+ });
103
+ }, [clear, revalidate]);
55
104
 
56
105
  const retry = useCallback(() => {
106
+ recoveryGeneration.current += 1;
107
+ setRecovery({ kind: 'idle' });
57
108
  clear();
58
109
  setReloadKey((value) => value + 1);
59
110
  }, [clear]);
60
111
 
112
+ const runRecovery = useCallback((action: WorkbenchRuntimeGateRecoveryAction) => {
113
+ const generation = recoveryGeneration.current + 1;
114
+ recoveryGeneration.current = generation;
115
+ setRecovery({ kind: 'running' });
116
+ void action.run().then((message) => {
117
+ if (recoveryGeneration.current === generation) setRecovery({ kind: 'done', message });
118
+ }, () => {
119
+ // The action owns its plain result; a rejected run reports nothing and
120
+ // leaves the action available again.
121
+ if (recoveryGeneration.current === generation) setRecovery({ kind: 'idle' });
122
+ });
123
+ }, []);
124
+
61
125
  useEffect(() => {
62
126
  let active = true;
63
127
  // A re-run triggered by a changed resolve/toErrorMessage identity (for
@@ -67,9 +131,12 @@ export function WorkbenchRuntimeGate({
67
131
  setState((current) => (current.kind === 'ready' ? current : { kind: 'checking' }));
68
132
  void resolve().then((projection) => {
69
133
  if (!active) return;
134
+ const revalidated = revalidating.current;
135
+ revalidating.current = false;
70
136
  if (projection.status === 'ready') {
71
137
  offlineCoordinator.markRuntimeReachability('reachable');
72
138
  setState({ kind: 'ready' });
139
+ if (revalidated) onRevalidatedRef.current?.();
73
140
  return;
74
141
  }
75
142
  offlineCoordinator.markRuntimeReachability('unreachable');
@@ -80,6 +147,7 @@ export function WorkbenchRuntimeGate({
80
147
  });
81
148
  }).catch((error) => {
82
149
  if (!active) return;
150
+ revalidating.current = false;
83
151
  offlineCoordinator.markRuntimeReachability('unreachable');
84
152
  setState({
85
153
  kind: 'blocked',
@@ -106,22 +174,50 @@ export function WorkbenchRuntimeGate({
106
174
 
107
175
  if (state.kind === 'blocked') {
108
176
  const { projection } = state;
177
+ const recoveryAction = projection.recoveryAction;
109
178
  return (
110
179
  <main className="runtime-unavailable-screen" aria-live="polite">
111
180
  <Surface className="runtime-unavailable-panel" material="glass-thick" tone="panel" elevation="floating">
112
181
  <div className="runtime-unavailable-heading">
113
- <StatusBadge tone="warning" shape="dot">{copy.setupRequired}</StatusBadge>
182
+ <StatusBadge tone="info" shape="dot">{copy.setupRequired}</StatusBadge>
114
183
  <h1>{appTitle}</h1>
115
184
  </div>
116
- <InlineAlert tone="warning">
185
+ <InlineAlert tone="info">
117
186
  <div className="runtime-alert-copy">
118
187
  <strong>{projection.signInRequired ? copy.signInRequired : copy.connectionRequired}</strong>
119
188
  <span>{projection.body}</span>
120
189
  </div>
121
190
  </InlineAlert>
122
- <p className="runtime-action-hint">{copy.offlineTier(state.offlineTier)}</p>
123
191
  {projection.nextAction ? <p className="runtime-action-hint">{copy.nextAction(projection.nextAction)}</p> : null}
124
- <Button type="button" tone="primary" onClick={retry}>{copy.retry}</Button>
192
+ <div className="runtime-gate-actions">
193
+ <Button type="button" tone="primary" onClick={retry}>{copy.retry}</Button>
194
+ {recoveryAction ? (
195
+ <Button
196
+ type="button"
197
+ tone="secondary"
198
+ loading={recovery.kind === 'running'}
199
+ disabled={recovery.kind === 'running'}
200
+ onClick={() => runRecovery(recoveryAction)}
201
+ >
202
+ {recoveryAction.label}
203
+ </Button>
204
+ ) : null}
205
+ </div>
206
+ {recovery.kind === 'done' ? <p className="runtime-action-hint" role="status">{recovery.message}</p> : null}
207
+ <details className="runtime-gate-details">
208
+ <summary>{copy.technicalDetails}</summary>
209
+ {projection.technicalDetails?.length ? (
210
+ <dl>
211
+ {projection.technicalDetails.map((detail) => (
212
+ <div key={detail.label}>
213
+ <dt>{detail.label}</dt>
214
+ <dd>{detail.value}</dd>
215
+ </div>
216
+ ))}
217
+ </dl>
218
+ ) : null}
219
+ <p>{copy.offlineTier(state.offlineTier)}</p>
220
+ </details>
125
221
  </Surface>
126
222
  </main>
127
223
  );
@@ -178,6 +178,48 @@
178
178
  font-size: 13px;
179
179
  }
180
180
 
181
+ .runtime-gate-actions {
182
+ display: flex;
183
+ flex-wrap: wrap;
184
+ gap: 10px;
185
+ }
186
+
187
+ .runtime-gate-details {
188
+ min-width: 0;
189
+ color: var(--nimi-text-secondary);
190
+ font-size: 12px;
191
+ }
192
+
193
+ .runtime-gate-details summary {
194
+ width: fit-content;
195
+ cursor: pointer;
196
+ }
197
+
198
+ .runtime-gate-details dl {
199
+ display: grid;
200
+ grid-template-columns: max-content minmax(0, 1fr);
201
+ gap: 6px 12px;
202
+ margin: 10px 0 0;
203
+ }
204
+
205
+ .runtime-gate-details dl > div {
206
+ display: contents;
207
+ }
208
+
209
+ .runtime-gate-details dt {
210
+ font-weight: 600;
211
+ }
212
+
213
+ .runtime-gate-details dd {
214
+ margin: 0;
215
+ overflow-wrap: anywhere;
216
+ font-family: var(--nimi-font-mono);
217
+ }
218
+
219
+ .runtime-gate-details p {
220
+ margin: 10px 0 0;
221
+ }
222
+
181
223
  .workbench-empty-state {
182
224
  display: grid;
183
225
  place-items: center;
@@ -13,19 +13,25 @@ export type WorkbenchNavigationItem<TViewId extends string> = {
13
13
  readonly id: TViewId;
14
14
  readonly label: string;
15
15
  readonly icon: ComponentType<WorkbenchNavigationIconProps>;
16
+ readonly detail?: string;
16
17
  readonly semanticId?: string;
17
18
  };
18
19
 
19
20
  export type WorkbenchNavigationGroup<TViewId extends string> = {
20
21
  readonly id: string;
22
+ readonly label?: string;
21
23
  readonly items: readonly WorkbenchNavigationItem<TViewId>[];
22
24
  };
23
25
 
24
26
  export type WorkbenchCoreProps<TViewId extends string> = {
25
27
  readonly activeViewId: TViewId | null;
26
28
  readonly navigationLabel: string;
29
+ readonly navigationPresentation?: 'rail' | 'catalog';
30
+ readonly navigationTitle?: string;
31
+ readonly navigationDescription?: string;
27
32
  readonly navigationGroups: readonly WorkbenchNavigationGroup<TViewId>[];
28
33
  readonly bottomNavigationItems?: readonly WorkbenchNavigationItem<TViewId>[];
34
+ readonly bottomNavigationLabel?: string;
29
35
  readonly onSelectView: (viewId: TViewId) => void;
30
36
  readonly accountSlot?: ReactNode;
31
37
  readonly rootTestId?: string;
@@ -35,27 +41,39 @@ export type WorkbenchCoreProps<TViewId extends string> = {
35
41
  export function WorkbenchCore<TViewId extends string>({
36
42
  activeViewId,
37
43
  navigationLabel,
44
+ navigationPresentation = 'rail',
45
+ navigationTitle,
46
+ navigationDescription,
38
47
  navigationGroups,
39
48
  bottomNavigationItems = [],
49
+ bottomNavigationLabel,
40
50
  onSelectView,
41
51
  accountSlot,
42
52
  rootTestId,
43
53
  children,
44
54
  }: WorkbenchCoreProps<TViewId>) {
45
55
  return (
46
- <main className="workbench" data-testid={rootTestId}>
56
+ <main className="workbench" data-testid={rootTestId} data-navigation-presentation={navigationPresentation}>
47
57
  <div className="workbench__body">
48
58
  <aside className="workbench-side-nav" aria-label={navigationLabel}>
59
+ {navigationPresentation === 'catalog' && navigationTitle ? (
60
+ <div className="workbench-side-nav__heading">
61
+ <h1>{navigationTitle}</h1>
62
+ {navigationDescription ? <p>{navigationDescription}</p> : null}
63
+ </div>
64
+ ) : null}
49
65
  <nav className="workbench-side-nav__groups" aria-label={navigationLabel}>
50
66
  {navigationGroups.map((group) => (
51
67
  <WorkbenchNavigationList
52
68
  key={group.id}
53
69
  activeViewId={activeViewId}
54
70
  items={group.items}
71
+ label={group.label}
55
72
  onSelectView={onSelectView}
73
+ presentation={navigationPresentation}
56
74
  />
57
75
  ))}
58
- {(bottomNavigationItems.length > 0 || accountSlot) ? (
76
+ {navigationPresentation === 'rail' && (bottomNavigationItems.length > 0 || accountSlot) ? (
59
77
  <div className="workbench-side-nav__group" data-nav-placement="bottom">
60
78
  <ul>
61
79
  {bottomNavigationItems.map((item) => (
@@ -64,6 +82,7 @@ export function WorkbenchCore<TViewId extends string>({
64
82
  active={activeViewId === item.id}
65
83
  item={item}
66
84
  onSelectView={onSelectView}
85
+ presentation="rail"
67
86
  />
68
87
  ))}
69
88
  {accountSlot ? (
@@ -73,6 +92,20 @@ export function WorkbenchCore<TViewId extends string>({
73
92
  </div>
74
93
  ) : null}
75
94
  </nav>
95
+ {navigationPresentation === 'catalog' && (bottomNavigationItems.length > 0 || accountSlot) ? (
96
+ <div className="workbench-side-nav__footer" role="navigation" aria-label={bottomNavigationLabel ?? navigationLabel}>
97
+ {bottomNavigationItems.length > 0 ? (
98
+ <WorkbenchNavigationList
99
+ activeViewId={activeViewId}
100
+ items={bottomNavigationItems}
101
+ label={bottomNavigationLabel}
102
+ onSelectView={onSelectView}
103
+ presentation="catalog"
104
+ />
105
+ ) : null}
106
+ {accountSlot ? <div className="workbench-side-nav__account">{accountSlot}</div> : null}
107
+ </div>
108
+ ) : null}
76
109
  </aside>
77
110
  <div className="workbench__main">
78
111
  <div className="workbench__content">{children}</div>
@@ -85,14 +118,19 @@ export function WorkbenchCore<TViewId extends string>({
85
118
  function WorkbenchNavigationList<TViewId extends string>({
86
119
  activeViewId,
87
120
  items,
121
+ label,
88
122
  onSelectView,
123
+ presentation,
89
124
  }: {
90
125
  readonly activeViewId: TViewId | null;
91
126
  readonly items: readonly WorkbenchNavigationItem<TViewId>[];
127
+ readonly label?: string;
92
128
  readonly onSelectView: (viewId: TViewId) => void;
129
+ readonly presentation: 'rail' | 'catalog';
93
130
  }) {
94
131
  return (
95
132
  <div className="workbench-side-nav__group">
133
+ {presentation === 'catalog' && label ? <h2 className="workbench-side-nav__group-label">{label}</h2> : null}
96
134
  <ul>
97
135
  {items.map((item) => (
98
136
  <WorkbenchNavigationListItem
@@ -100,6 +138,7 @@ function WorkbenchNavigationList<TViewId extends string>({
100
138
  active={activeViewId === item.id}
101
139
  item={item}
102
140
  onSelectView={onSelectView}
141
+ presentation={presentation}
103
142
  />
104
143
  ))}
105
144
  </ul>
@@ -111,30 +150,42 @@ function WorkbenchNavigationListItem<TViewId extends string>({
111
150
  active,
112
151
  item,
113
152
  onSelectView,
153
+ presentation,
114
154
  }: {
115
155
  readonly active: boolean;
116
156
  readonly item: WorkbenchNavigationItem<TViewId>;
117
157
  readonly onSelectView: (viewId: TViewId) => void;
158
+ readonly presentation: 'rail' | 'catalog';
118
159
  }) {
119
160
  const Icon = item.icon;
161
+ const button = (
162
+ <Button
163
+ type="button"
164
+ tone="ghost"
165
+ size="sm"
166
+ data-nimi-semantic-id={item.semanticId}
167
+ data-workbench-rail-item=""
168
+ className={active ? 'workbench-side-nav__item workbench-side-nav__item--active' : 'workbench-side-nav__item'}
169
+ onClick={() => onSelectView(item.id)}
170
+ aria-label={item.label}
171
+ aria-current={active ? 'page' : undefined}
172
+ >
173
+ <Icon size={18} strokeWidth={1.9} aria-hidden="true" />
174
+ {presentation === 'catalog' ? (
175
+ <span className="workbench-side-nav__item-copy">
176
+ <span className="workbench-side-nav__item-label">{item.label}</span>
177
+ {item.detail ? <span className="workbench-side-nav__item-detail">{item.detail}</span> : null}
178
+ </span>
179
+ ) : (
180
+ <span className="workbench-side-nav__item-label" data-workbench-rail-label="">{item.label}</span>
181
+ )}
182
+ </Button>
183
+ );
120
184
  return (
121
185
  <li>
122
- <Tooltip content={item.label} placement="right" className="w-full">
123
- <Button
124
- type="button"
125
- tone="ghost"
126
- size="sm"
127
- data-nimi-semantic-id={item.semanticId}
128
- data-workbench-rail-item=""
129
- className={active ? 'workbench-side-nav__item workbench-side-nav__item--active' : 'workbench-side-nav__item'}
130
- onClick={() => onSelectView(item.id)}
131
- aria-label={item.label}
132
- aria-current={active ? 'page' : undefined}
133
- >
134
- <Icon size={18} strokeWidth={1.9} aria-hidden="true" />
135
- <span className="workbench-side-nav__item-label" data-workbench-rail-label="">{item.label}</span>
136
- </Button>
137
- </Tooltip>
186
+ {presentation === 'catalog'
187
+ ? button
188
+ : <Tooltip content={item.label} placement="right" className="w-full">{button}</Tooltip>}
138
189
  </li>
139
190
  );
140
191
  }