@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,11 +1,12 @@
1
- import { useContext, useMemo, useState } from 'react';
2
- import { Button, IconButton, InlineAlert, nimiToast, Popover, PopoverContent, PopoverTrigger, Tooltip } from '@nimiplatform/kit/ui';
3
- import { Check, ChevronRight, FileX, Funnel, RefreshCw, Search, Sparkles, Trash2 } from 'lucide-react';
1
+ import { useContext, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { Button, IconButton, InlineAlert, nimiToast, OverlayShell, Popover, PopoverContent, PopoverTrigger } from '@nimiplatform/kit/ui';
3
+ import { Check, ChevronRight, Ellipsis, FileX, Funnel, GitCompareArrows, RefreshCw, Search, Sparkles, Trash2, X } from 'lucide-react';
4
4
  import { useAIStudioHost } from './host-context.js';
5
5
  import type { StudioCapabilityRegistration } from './module-registration.js';
6
6
  import {
7
7
  flattenStudioRunHistory,
8
8
  formatStudioRunHistoryTimestamp,
9
+ getStudioRunConfigParamRows,
9
10
  getStudioRunMetricSummary,
10
11
  getStudioRunIntentLabel,
11
12
  getStudioRunIntentSource,
@@ -16,6 +17,7 @@ import {
16
17
  type StudioRunHistory,
17
18
  type StudioRunHistoryRecord,
18
19
  } from './history.js';
20
+ import { studioConfiguredTargetLabel } from './section-ai-testing-run.js';
19
21
  import {
20
22
  StudioHistoryActionsContext,
21
23
  StudioHistoryLoadContext,
@@ -27,6 +29,7 @@ import { studioHistoryDocumentPaths } from './history-policy.js';
27
29
  import { isStoppedDirectCall } from './non-success-presentation.js';
28
30
 
29
31
  type HistoryStatusFilter = 'all' | StudioRunHistoryRecord['status'];
32
+ const HISTORY_PAGE_SIZE = 24;
30
33
  type HistoryEnvironmentFilter = 'all' | 'local' | 'cloud' | 'remote-control';
31
34
  type HistoryActivityFilter = 'all' | 'today' | '7d' | '30d';
32
35
  type HistoryGroupBy = 'none' | 'date' | 'capability';
@@ -124,6 +127,8 @@ function matchesHistorySearch(record: StudioRunHistoryRecord, query: string): bo
124
127
  record.message,
125
128
  record.result?.summary ?? '',
126
129
  getStudioRunIntentLabel(record),
130
+ record.runConfig?.target.targetLabel ?? '',
131
+ record.runConfig?.target.targetRef ?? '',
127
132
  ];
128
133
  return haystacks.some((value) => value.toLowerCase().includes(query));
129
134
  }
@@ -178,6 +183,7 @@ export function CapabilityRunHistory({
178
183
  history,
179
184
  activeRunId,
180
185
  onSelectRun,
186
+ onClose,
181
187
  collapsed,
182
188
  currentCapabilityId,
183
189
  registrations,
@@ -185,6 +191,7 @@ export function CapabilityRunHistory({
185
191
  history: StudioRunHistory | null;
186
192
  activeRunId: string | null;
187
193
  onSelectRun: (record: StudioRunHistoryRecord) => void;
194
+ onClose?: () => void;
188
195
  collapsed: boolean;
189
196
  currentCapabilityId: string;
190
197
  registrations: readonly StudioCapabilityRegistration[];
@@ -194,6 +201,10 @@ export function CapabilityRunHistory({
194
201
  const historyLoad = useContext(StudioHistoryLoadContext);
195
202
  const historyActions = useContext(StudioHistoryActionsContext);
196
203
  const historyPanel = useContext(StudioHistoryPanelContext);
204
+ const closeButton = useRef<HTMLButtonElement>(null);
205
+ useEffect(() => {
206
+ if (!collapsed) closeButton.current?.focus();
207
+ }, [collapsed]);
197
208
  const locale = rendererHost.locale.startsWith('zh') ? 'zh-CN' : 'en-US';
198
209
  const runtimeHistoryCapabilities = useMemo(() => registrations.filter((item) => (
199
210
  item.descriptor.execution === 'runtime-sdk' || item.descriptor.execution === 'standalone-electron'
@@ -204,11 +215,18 @@ export function CapabilityRunHistory({
204
215
  const [filterOpen, setFilterOpen] = useState(false);
205
216
  const [activeMenu, setActiveMenu] = useState<HistoryFilterMenuId | null>(null);
206
217
  const [searchQuery, setSearchQuery] = useState('');
218
+ const [visibleLimit, setVisibleLimit] = useState(HISTORY_PAGE_SIZE);
207
219
  const [clearArmed, setClearArmed] = useState(false);
220
+ const [historyActionsOpen, setHistoryActionsOpen] = useState(false);
221
+ const [comparing, setComparing] = useState(false);
222
+ const [comparisonIds, setComparisonIds] = useState<readonly string[]>([]);
223
+ const [comparisonOpen, setComparisonOpen] = useState(false);
208
224
  const scope: StudioHistoryPanelScope = historyPanel?.scope ?? 'capability';
209
225
  const hideFailures = historyPanel?.hideFailures ?? false;
210
226
  const setScope = (next: StudioHistoryPanelScope) => {
211
227
  setClearArmed(false);
228
+ setComparing(false);
229
+ setComparisonIds([]);
212
230
  historyPanel?.setScope(next);
213
231
  };
214
232
  const setHideFailures = (next: boolean) => historyPanel?.setHideFailures(next);
@@ -220,7 +238,15 @@ export function CapabilityRunHistory({
220
238
  const [sortBy, setSortBy] = useState<HistorySortBy>('recency');
221
239
  const now = useMemo(() => new Date(rendererHost.clock.now()), [history, rendererHost]);
222
240
  const query = searchQuery.trim().toLowerCase();
223
- const records = useMemo(() => flattenStudioRunHistory(history, resolveCapabilityLabel)
241
+ useEffect(() => {
242
+ setVisibleLimit(HISTORY_PAGE_SIZE);
243
+ }, [collapsed, currentCapabilityId, scope, query, hideFailures, statusFilter, capabilityFilter, environmentFilter, activityFilter, groupBy, sortBy]);
244
+ const allRecords = useMemo(() => flattenStudioRunHistory(history, resolveCapabilityLabel), [history, registrations]);
245
+ const comparisonRecords = comparisonIds.flatMap((id) => {
246
+ const record = allRecords.find((item) => item.id === id);
247
+ return record ? [record] : [];
248
+ });
249
+ const records = useMemo(() => allRecords
224
250
  .filter((record) => (scope === 'capability'
225
251
  ? record.capabilityId === currentCapabilityId
226
252
  : capabilityFilter === 'all' || record.capabilityId === capabilityFilter))
@@ -231,7 +257,7 @@ export function CapabilityRunHistory({
231
257
  .filter((record) => matchesHistoryActivity(record, activityFilter, now))
232
258
  .sort((left, right) => sortBy === 'recency'
233
259
  ? right.createdAt.localeCompare(left.createdAt)
234
- : left.createdAt.localeCompare(right.createdAt)), [activityFilter, capabilityFilter, currentCapabilityId, environmentFilter, hideFailures, history, now, query, registrations, scope, sortBy, statusFilter]);
260
+ : left.createdAt.localeCompare(right.createdAt)), [activityFilter, allRecords, capabilityFilter, currentCapabilityId, environmentFilter, hideFailures, now, query, scope, sortBy, statusFilter]);
235
261
  const mediaRecords = useMemo(() => (historyPanel?.imageRecords ?? [])
236
262
  .filter((record) => !hideFailures || record.status === 'ready')
237
263
  .filter((record) => matchesMediaSearch(record, query))
@@ -239,7 +265,7 @@ export function CapabilityRunHistory({
239
265
 
240
266
  function handleSelectMediaRecord(record: StudioMediaHistoryRecord) {
241
267
  const linkageId = record.runId || record.id;
242
- const runRecord = flattenStudioRunHistory(history, resolveCapabilityLabel).find((entry) => entry.id === linkageId);
268
+ const runRecord = allRecords.find((entry) => entry.id === linkageId);
243
269
  if (!runRecord) {
244
270
  nimiToast.warning(t('History.linkedRunMissing'));
245
271
  return;
@@ -257,6 +283,7 @@ export function CapabilityRunHistory({
257
283
 
258
284
  function handleClearScope(deleteAssets: boolean) {
259
285
  setClearArmed(false);
286
+ setHistoryActionsOpen(false);
260
287
  void historyActions?.clearScope(scope === 'capability' ? currentCapabilityId : null, deleteAssets);
261
288
  }
262
289
 
@@ -268,20 +295,21 @@ export function CapabilityRunHistory({
268
295
  }
269
296
 
270
297
  function historySubtitleForRun(record: StudioRunHistoryRecord): string {
271
- const intent = getStudioRunIntentLabel(record);
272
- const source = historySourceLabelForRun(record);
298
+ const target = studioConfiguredTargetLabel(record.runConfig?.target, t);
299
+ const capability = scope === 'all' ? historyCapabilityLabel(record.capabilityId) : '';
273
300
  if (record.status === 'canceled') {
274
301
  const reason = historyFailureReasonForRun(record);
275
302
  const stoppedLabel = reason !== 'operation-aborted' ? 'History.canceled' : isStoppedDirectCall(reason, record.capabilityId) ? 'History.stopped' : 'History.stoppedWaiting';
276
- return [t(stoppedLabel), intent, source, reason].filter(Boolean).join(' / ');
303
+ return [t(stoppedLabel), capability, target, reason].filter(Boolean).join(' / ');
277
304
  }
278
305
  if (record.status === 'timed-out') {
279
- return [t('History.timedOut'), intent, source, historyFailureReasonForRun(record)].filter(Boolean).join(' / ');
306
+ return [t('History.timedOut'), capability, target, historyFailureReasonForRun(record)].filter(Boolean).join(' / ');
280
307
  }
281
308
  if (isFailureHistoryStatus(record)) {
282
- return [t('History.failed'), intent, source, historyFailureReasonForRun(record)].filter(Boolean).join(' / ');
309
+ return [t('History.failed'), capability, target, historyFailureReasonForRun(record)].filter(Boolean).join(' / ');
283
310
  }
284
- return [intent, source].filter(Boolean).join(' / ');
311
+ const state = record.status === 'ready' ? t('Studio.result.status.runtimeResult') : rendererHost.app.projection.runStatusLabel(record.status);
312
+ return [state, target, capability].filter(Boolean).join(' / ');
285
313
  }
286
314
 
287
315
  function historyLabelForRun(record: StudioFlatRunRecord): string {
@@ -321,9 +349,10 @@ export function CapabilityRunHistory({
321
349
  }
322
350
 
323
351
  const groups = useMemo(() => {
324
- if (groupBy === 'none') return [{ id: 'all', label: '', records }];
352
+ const visibleRecords = records.slice(0, visibleLimit);
353
+ if (groupBy === 'none') return [{ id: 'all', label: '', records: visibleRecords }];
325
354
  const grouped = new Map<string, { id: string; label: string; records: StudioFlatRunRecord[] }>();
326
- for (const record of records) {
355
+ for (const record of visibleRecords) {
327
356
  const label = groupBy === 'date' ? historyDateGroupLabel(record.createdAt) : historyCapabilityLabel(record.capabilityId as string);
328
357
  const id = groupBy === 'date' ? `date:${label}` : `capability:${record.capabilityId}`;
329
358
  const existing = grouped.get(id);
@@ -334,7 +363,7 @@ export function CapabilityRunHistory({
334
363
  }
335
364
  }
336
365
  return [...grouped.values()];
337
- }, [groupBy, now, records, locale, t]);
366
+ }, [groupBy, now, records, locale, t, visibleLimit]);
338
367
  const activeMenuLabel = {
339
368
  status: optionLabel(HISTORY_STATUS_OPTIONS, statusFilter),
340
369
  capability: historyCapabilityLabel(capabilityFilter),
@@ -398,14 +427,32 @@ export function CapabilityRunHistory({
398
427
  setActiveMenu(null);
399
428
  }
400
429
 
430
+ if (collapsed) return <div className="studio-history-shell studio-history-shell--collapsed" inert />;
431
+
401
432
  return (
402
- <div className={collapsed ? 'studio-history-shell studio-history-shell--collapsed' : 'studio-history-shell'}>
403
- <aside className={collapsed ? 'studio-history studio-history--collapsed' : 'studio-history'} aria-label={t('History.panelAriaLabel')}>
433
+ <div className={collapsed ? 'studio-history-shell studio-history-shell--collapsed' : 'studio-history-shell'} inert={collapsed}>
434
+ <aside
435
+ className={collapsed ? 'studio-history studio-history--collapsed' : 'studio-history'}
436
+ aria-label={t('History.panelAriaLabel')}
437
+ onKeyDown={onClose ? (event) => { if (event.key === 'Escape' && !filterOpen && !historyActionsOpen) onClose(); } : undefined}
438
+ >
404
439
  <div className="studio-recent__head">
405
440
  <div className="studio-history__title">
406
441
  <strong>{t('History.title')}</strong>
407
442
  </div>
408
443
  <div className="studio-history__actions">
444
+ {scope !== 'media' && !comparing && records.length > 1 ? (
445
+ <Button
446
+ type="button"
447
+ size="sm"
448
+ tone="ghost"
449
+ className="studio-history__compare-trigger"
450
+ leadingIcon={<GitCompareArrows size={14} aria-hidden="true" />}
451
+ onClick={() => setComparing(true)}
452
+ >
453
+ {t('History.compareRuns')}
454
+ </Button>
455
+ ) : null}
409
456
  {scope !== 'media' ? (
410
457
  <Popover
411
458
  open={filterOpen && !collapsed}
@@ -473,6 +520,52 @@ export function CapabilityRunHistory({
473
520
  </PopoverContent>
474
521
  </Popover>
475
522
  ) : null}
523
+ {scope !== 'media' && historyActions ? (
524
+ <Popover open={historyActionsOpen && !collapsed} onOpenChange={(open) => {
525
+ setHistoryActionsOpen(open);
526
+ if (!open) setClearArmed(false);
527
+ }}>
528
+ <PopoverTrigger asChild>
529
+ <IconButton
530
+ type="button"
531
+ size="sm"
532
+ tone="ghost"
533
+ aria-label={t('History.moreActions')}
534
+ icon={<Ellipsis size={17} aria-hidden="true" />}
535
+ />
536
+ </PopoverTrigger>
537
+ <PopoverContent align="end" sideOffset={8} className="grid gap-2 p-2" aria-label={t('History.moreActions')}>
538
+ {clearArmed ? (
539
+ <div className="grid justify-items-start gap-2 p-1" role="group" aria-label={t('History.clearChoiceAriaLabel')}>
540
+ <Button type="button" tone="ghost" size="sm" onClick={() => handleClearScope(false)}>
541
+ {t('History.clearRecordsOnly')}
542
+ </Button>
543
+ <Button type="button" tone="danger" size="sm" onClick={() => handleClearScope(true)}>
544
+ {t('History.clearRecordsAndAssets')}
545
+ </Button>
546
+ <Button type="button" tone="ghost" size="sm" onClick={() => setClearArmed(false)}>
547
+ {t('Common.close')}
548
+ </Button>
549
+ </div>
550
+ ) : (
551
+ <Button type="button" tone="ghost" size="sm" onClick={() => setClearArmed(true)}>
552
+ {t('History.clearScope')}
553
+ </Button>
554
+ )}
555
+ </PopoverContent>
556
+ </Popover>
557
+ ) : null}
558
+ {onClose ? (
559
+ <IconButton
560
+ ref={closeButton}
561
+ type="button"
562
+ tone="ghost"
563
+ size="sm"
564
+ aria-label={t('History.closePanel')}
565
+ icon={<X size={17} aria-hidden="true" />}
566
+ onClick={onClose}
567
+ />
568
+ ) : null}
476
569
  </div>
477
570
  </div>
478
571
  <div className="studio-history__search">
@@ -528,21 +621,16 @@ export function CapabilityRunHistory({
528
621
  >
529
622
  {hideFailures ? t('History.showFailures') : t('History.hideFailures')}
530
623
  </Button>
531
- {scope !== 'media' && historyActions ? (
532
- clearArmed ? (
533
- <div role="group" aria-label={t('History.clearChoiceAriaLabel')}>
534
- <Button type="button" tone="ghost" size="sm" className="studio-history__scope-option" onClick={() => handleClearScope(false)}>
535
- {t('History.clearRecordsOnly')}
536
- </Button>
537
- <Button type="button" tone="ghost" size="sm" className="studio-history__scope-option studio-history__scope-option--danger" onClick={() => handleClearScope(true)}>
538
- {t('History.clearRecordsAndAssets')}
539
- </Button>
540
- </div>
541
- ) : (
542
- <Button type="button" tone="ghost" size="sm" className="studio-history__scope-option" onClick={() => setClearArmed(true)}>
543
- {t('History.clearScope')}
544
- </Button>
545
- )
624
+ {scope !== 'media' && comparing ? (
625
+ <div className="studio-history__comparison">
626
+ <span role="status">{t('History.compareCount', { count: comparisonRecords.length })}</span>
627
+ <Button type="button" size="sm" tone="secondary" disabled={comparisonRecords.length !== 2}
628
+ onClick={() => setComparisonOpen(true)}>{t('History.openComparison')}</Button>
629
+ <Button type="button" size="sm" tone="ghost" onClick={() => {
630
+ setComparing(false);
631
+ setComparisonIds([]);
632
+ }}>{t('Common.close')}</Button>
633
+ </div>
546
634
  ) : null}
547
635
  </div>
548
636
  <div className="studio-history__runs">
@@ -564,7 +652,7 @@ export function CapabilityRunHistory({
564
652
  ) : scope === 'media' ? (
565
653
  mediaRecords.length > 0 ? (
566
654
  <ul className="studio-recent__rows">
567
- {mediaRecords.map((record) => (
655
+ {mediaRecords.slice(0, visibleLimit).map((record) => (
568
656
  <li key={record.id}>
569
657
  <Button
570
658
  type="button"
@@ -581,9 +669,9 @@ export function CapabilityRunHistory({
581
669
  <span className="studio-recent__copy">
582
670
  <span className="studio-recent__summary">
583
671
  <span className="studio-recent__title">
584
- <Tooltip content={record.title} placement="top" className="studio-recent__intent-tooltip">
672
+ <span title={record.title} className="studio-recent__intent-tooltip">
585
673
  <span className="studio-recent__intent-name">{record.title}</span>
586
- </Tooltip>
674
+ </span>
587
675
  <time dateTime={record.createdAt}>{formatStudioRunHistoryTimestamp(record.createdAt, now)}</time>
588
676
  </span>
589
677
  </span>
@@ -593,17 +681,16 @@ export function CapabilityRunHistory({
593
681
  </span>
594
682
  </Button>
595
683
  {historyActions ? (
596
- <Tooltip content={t('History.deleteRecordAndAsset')} placement="left">
597
684
  <IconButton
598
685
  type="button"
599
686
  tone="ghost"
600
687
  size="sm"
601
688
  className="studio-recent__row-delete"
602
689
  aria-label={t('History.deleteRecordAndAsset')}
690
+ title={t('History.deleteRecordAndAsset')}
603
691
  onClick={() => handleRemoveMediaRecord(record)}
604
692
  icon={<Trash2 size={13} strokeWidth={1.9} aria-hidden="true" />}
605
693
  />
606
- </Tooltip>
607
694
  ) : null}
608
695
  </li>
609
696
  ))}
@@ -619,8 +706,23 @@ export function CapabilityRunHistory({
619
706
  {group.records.map((record) => {
620
707
  const capability = runtimeHistoryCapabilities.find((item) => item.descriptor.id === record.capabilityId);
621
708
  const Icon = capability?.icon ?? Sparkles;
709
+ const selected = comparisonRecords.some(item => item.id === record.id);
710
+ const selectable = comparisonRecords.length < 2 && comparisonRecords.every(item => item.capabilityId === record.capabilityId);
711
+ const title = historyTitleForRun(record);
712
+ const subtitle = historySubtitleForRun(record);
622
713
  return (
623
- <li key={record.id}>
714
+ <li key={record.id} className={comparing ? 'studio-recent__compare-row' : undefined}>
715
+ {comparing ? (
716
+ <input
717
+ type="checkbox"
718
+ checked={selected}
719
+ disabled={!selected && !selectable}
720
+ aria-label={t('History.selectComparisonRun', { run: historyLabelForRun(record) })}
721
+ onChange={() => setComparisonIds(selected
722
+ ? comparisonRecords.filter(item => item.id !== record.id).map(item => item.id)
723
+ : [...comparisonRecords.map(item => item.id), record.id])}
724
+ />
725
+ ) : null}
624
726
  <Button
625
727
  type="button"
626
728
  tone="ghost"
@@ -637,44 +739,42 @@ export function CapabilityRunHistory({
637
739
  <span className="studio-recent__copy">
638
740
  <span className="studio-recent__summary">
639
741
  <span className="studio-recent__title">
640
- <Tooltip content={historyTitleForRun(record)} placement="top" className="studio-recent__intent-tooltip">
641
- <span className="studio-recent__intent-name">{historyTitleForRun(record)}</span>
642
- </Tooltip>
742
+ <span title={title} className="studio-recent__intent-tooltip">
743
+ <span className="studio-recent__intent-name">{title}</span>
744
+ </span>
643
745
  <time dateTime={record.createdAt}>{formatStudioRunHistoryTimestamp(record.createdAt, now)}</time>
644
746
  </span>
645
747
  </span>
646
- <Tooltip content={historySubtitleForRun(record)} placement="top" className="studio-recent__detail-tooltip">
748
+ <span title={subtitle} className="studio-recent__detail-tooltip">
647
749
  <span className={isFailureHistoryStatus(record) ? 'studio-recent__detail studio-recent__detail--failed' : 'studio-recent__detail'}>
648
- {historySubtitleForRun(record)}
750
+ {subtitle}
649
751
  </span>
650
- </Tooltip>
752
+ </span>
651
753
  </span>
652
754
  </Button>
653
755
  {historyActions ? (
654
- <Tooltip content={t('History.deleteRecordOnly')} placement="left">
655
756
  <IconButton
656
757
  type="button"
657
758
  tone="ghost"
658
759
  size="sm"
659
760
  className="studio-recent__row-delete"
660
761
  aria-label={t('History.deleteRecordOnly')}
762
+ title={t('History.deleteRecordOnly')}
661
763
  onClick={() => handleRemoveRecord(record)}
662
764
  icon={<Trash2 size={13} strokeWidth={1.9} aria-hidden="true" />}
663
765
  />
664
- </Tooltip>
665
766
  ) : null}
666
767
  {historyActions && studioHistoryDocumentPaths(record).length > 0 ? (
667
- <Tooltip content={t('History.deleteRecordAndDocument')} placement="left">
668
768
  <IconButton
669
769
  type="button"
670
770
  tone="ghost"
671
771
  size="sm"
672
772
  className="studio-recent__row-delete studio-recent__row-delete--document"
673
773
  aria-label={t('History.deleteRecordAndDocument')}
774
+ title={t('History.deleteRecordAndDocument')}
674
775
  onClick={() => handleRemoveRecord(record, true)}
675
776
  icon={<FileX size={13} strokeWidth={1.9} aria-hidden="true" />}
676
777
  />
677
- </Tooltip>
678
778
  ) : null}
679
779
  </li>
680
780
  );
@@ -685,8 +785,65 @@ export function CapabilityRunHistory({
685
785
  ) : (
686
786
  <p className="studio-history__empty">{history ? t('History.emptyFiltered') : t('History.emptyNone')}</p>
687
787
  )}
788
+ {(scope === 'media' ? mediaRecords.length : records.length) > visibleLimit && (scope === 'media' || !historyLoad?.error) ? (
789
+ <Button type="button" tone="ghost" size="sm" onClick={() => setVisibleLimit(limit => limit + HISTORY_PAGE_SIZE)}>
790
+ {t('History.showMoreRuns')}
791
+ </Button>
792
+ ) : null}
688
793
  </div>
689
794
  </aside>
795
+ <OverlayShell
796
+ open={comparisonOpen && comparisonRecords.length === 2}
797
+ kind="dialog"
798
+ size="L"
799
+ title={t('History.compareRuns')}
800
+ description={t('History.comparisonDescription')}
801
+ footer={<Button type="button" tone="secondary" onClick={() => setComparisonOpen(false)}>{t('Common.close')}</Button>}
802
+ onClose={() => setComparisonOpen(false)}
803
+ >
804
+ <div className="grid min-w-0 gap-4 sm:grid-cols-2">
805
+ {comparisonRecords.map(record => {
806
+ const snapshot = record.result;
807
+ const params = record.runConfig ? getStudioRunConfigParamRows(record.runConfig) : [];
808
+ const defaults = record.runConfig?.target.configuredDefaults
809
+ ? getStudioRunConfigParamRows(record.runConfig, record.runConfig.target.configuredDefaults) : [];
810
+ const jobId = snapshot && 'jobId' in snapshot ? snapshot.jobId : undefined;
811
+ const traceId = record.runConfig?.traceId ?? (snapshot?.ok ? snapshot.traceId : snapshot?.diagnostics?.traceId);
812
+ const output = snapshot?.ok && (snapshot.kind === 'text' || snapshot.kind === 'transcript')
813
+ ? snapshot.body : getStudioRunResultSummary(record);
814
+ return (
815
+ <section key={record.id} className="grid min-w-0 content-start gap-2 rounded-lg border border-[var(--nimi-border-subtle)] p-3">
816
+ <h3 className="m-0 text-sm font-semibold">{historyCapabilityLabel(record.capabilityId)} · {formatStudioRunHistoryTimestamp(record.createdAt, now)}</h3>
817
+ <p className="m-0 text-sm">{historySubtitleForRun(record)}</p>
818
+ <strong className="text-sm">{t('History.compareInput')}</strong>
819
+ <p className="m-0 whitespace-pre-wrap break-words text-sm">{record.prompt || t('History.compareUnknown')}</p>
820
+ {record.inputTruncated ? <p className="m-0 text-xs">{t('StudioShell.historyInputTruncated')}</p> : null}
821
+ {record.runConfig?.promptControls.context ? <p className="m-0 whitespace-pre-wrap break-words text-sm">
822
+ {t('StudioShell.contextLabel')} · {record.runConfig.promptControls.context}
823
+ </p> : null}
824
+ <strong className="text-sm">{t('StudioShell.requestSettings')}</strong>
825
+ {params.length ? <dl className="m-0 space-y-1 break-words text-sm">{params.map(row => (
826
+ <div key={row.key}><dt className="inline">{row.label} · </dt><dd className="m-0 inline">{row.value}</dd></div>
827
+ ))}</dl> : <p className="m-0 text-sm">{t(record.runConfig ? 'History.compareNoParameters' : 'History.compareUnknown')}</p>}
828
+ {defaults.length ? <>
829
+ <strong className="text-sm">{t('StudioShell.configuredDefaults')}</strong>
830
+ <dl className="m-0 space-y-1 break-words text-sm">{defaults.map(row => (
831
+ <div key={row.key}><dt className="inline">{row.label} · </dt><dd className="m-0 inline">{row.value}</dd></div>
832
+ ))}</dl>
833
+ </> : null}
834
+ <strong className="text-sm">{t('History.compareOutput')}</strong>
835
+ <p className="m-0 max-h-48 overflow-y-auto whitespace-pre-wrap break-words text-sm">{output || t('History.compareUnknown')}</p>
836
+ {jobId ? <p className="m-0 break-all text-xs">{t('Studio.result.jobLabel')} · <code>{jobId}</code></p> : null}
837
+ {traceId ? <p className="m-0 break-all text-xs">{t('Studio.result.traceLabel')} · <code>{traceId}</code></p> : null}
838
+ <Button type="button" size="sm" tone="secondary" onClick={() => {
839
+ setComparisonOpen(false);
840
+ onSelectRun(record);
841
+ }}>{t('History.openRun')}</Button>
842
+ </section>
843
+ );
844
+ })}
845
+ </div>
846
+ </OverlayShell>
690
847
  </div>
691
848
  );
692
849
  }
@@ -45,5 +45,6 @@ export function canCancelStudioCapabilityRun(input: {
45
45
  || input.resultKind === 'text-decision'
46
46
  || input.resultKind === 'transcript'
47
47
  || input.resultKind === 'vision-locate'
48
+ || input.resultKind === 'speaker-embedding'
48
49
  || input.resultKind === 'voice-asset';
49
50
  }
@@ -2,8 +2,7 @@ import { useEffect, useState, type ReactNode } from 'react';
2
2
  import { Button, Dialog, DialogContent, DialogTitle, IconButton, nimiToast, Tooltip } from '@nimiplatform/kit/ui';
3
3
  import { Copy as CopyIcon, Download as DownloadIcon, Maximize2, X } from 'lucide-react';
4
4
  import { useAIStudioHost, type AIStudioHostPort, type StudioTextExportResult } from './host-context.js';
5
- import type { StudioCapabilityRunResult } from './runtime-types.js';
6
- import { openNimiLocalAppAssetMediaUrl } from '@nimiplatform/kit/shell/renderer/bridge';
5
+ import type { StudioCapabilityRunResult, StudioEmbeddingRetrieval } from './runtime-types.js';
7
6
  import { studioNonSuccessReasonTitle, type StudioTranslate } from './non-success-presentation.js';
8
7
  import {
9
8
  STUDIO_ARTIFACT_IMAGE_LOADING,
@@ -30,6 +29,7 @@ export function formatTypedOutput(
30
29
  spaceId: output.spaceId ?? null,
31
30
  sample: output.sample,
32
31
  totalTokens: output.totalTokens,
32
+ ...(output.retrieval ? { retrieval: output.retrieval } : {}),
33
33
  }, null, 2);
34
34
  }
35
35
  if (output.kind === 'text-annotation') {
@@ -111,7 +111,7 @@ export function KnownJobNotice({ jobId }: { readonly jobId?: string }) {
111
111
  return <p className="studio-result__hint">{t('StudioResults.job.known', { jobId })}</p>;
112
112
  }
113
113
 
114
- export function EmbeddingResultBody({ spaceId }: { readonly spaceId?: string }) {
114
+ export function EmbeddingResultBody({ spaceId, retrieval }: { readonly spaceId?: string; readonly retrieval?: StudioEmbeddingRetrieval }) {
115
115
  const { translate: t } = useAIStudioHost();
116
116
  return (
117
117
  <div className="studio-result__rich">
@@ -119,6 +119,15 @@ export function EmbeddingResultBody({ spaceId }: { readonly spaceId?: string })
119
119
  <p className="studio-result__hint">
120
120
  {spaceId ? t('StudioResults.embedding.space', { spaceId }) : t('StudioResults.embedding.spaceNotRecorded')}
121
121
  </p>
122
+ {retrieval ? <section aria-label={t('Studio.embeddingRetrieval.title')}>
123
+ <h3>{t('Studio.embeddingRetrieval.title')}</h3>
124
+ <p>{retrieval.query}</p>
125
+ <ol>{retrieval.matches.map((match, index) => <li key={match.inputIndex}>
126
+ <strong>{t('Studio.embeddingRetrieval.match', { rank: index + 1, input: match.inputIndex + 1, score: match.score.toFixed(4) })}</strong>
127
+ <p>{match.excerpt}</p>
128
+ </li>)}</ol>
129
+ <p className="studio-result__hint">{t('Studio.embeddingRetrieval.hint')}</p>
130
+ </section> : null}
122
131
  </div>
123
132
  );
124
133
  }
@@ -221,37 +230,43 @@ export function ArtifactMediaPreview({
221
230
  const relativePath = artifact?.relativePath;
222
231
  const mimeType = artifact?.mediaType ?? '';
223
232
  const branch = studioArtifactRenderBranch(artifact);
224
- const { translate: t } = useAIStudioHost();
233
+ const { translate: t, app: { commands: { openAssetMediaUrl } } } = useAIStudioHost();
225
234
  const [imagePreviewOpen, setImagePreviewOpen] = useState(false);
226
235
  const [imagePreviewUrl, setImagePreviewUrl] = useState<string | null>(null);
227
236
  const [url, setUrl] = useState<string | null>(null);
237
+ const [previewFailed, setPreviewFailed] = useState(false);
238
+ const [attempt, setAttempt] = useState(0);
228
239
  useEffect(() => {
229
240
  setImagePreviewOpen(false);
230
241
  setUrl(null);
242
+ setPreviewFailed(false);
231
243
  if (!relativePath || !hasPreviewableArtifact(artifact)) return undefined;
244
+ const controller = new AbortController();
232
245
  let active = true;
233
246
  let revoke: (() => Promise<void>) | null = null;
234
- void openNimiLocalAppAssetMediaUrl(relativePath)
247
+ void openAssetMediaUrl(relativePath, controller.signal)
235
248
  .then((handle) => {
236
249
  revoke = handle.revoke;
237
250
  if (active) setUrl(handle.url);
238
251
  else void handle.revoke();
239
252
  })
240
253
  .catch(() => {
241
- if (active) setUrl(null);
254
+ if (active) setPreviewFailed(true);
242
255
  });
243
256
  return () => {
244
257
  active = false;
258
+ controller.abort();
245
259
  setUrl(null);
246
260
  if (revoke) void revoke();
247
261
  };
248
- }, [artifact, mimeType, relativePath]);
262
+ }, [artifact, mimeType, relativePath, openAssetMediaUrl, attempt]);
249
263
  useEffect(() => {
250
264
  setImagePreviewUrl(null);
251
265
  if (!imagePreviewOpen || !relativePath) return undefined;
266
+ const controller = new AbortController();
252
267
  let active = true;
253
268
  let revoke: (() => Promise<void>) | undefined;
254
- void openNimiLocalAppAssetMediaUrl(relativePath)
269
+ void openAssetMediaUrl(relativePath, controller.signal)
255
270
  .then((handle) => {
256
271
  revoke = handle.revoke;
257
272
  if (active) setImagePreviewUrl(handle.url);
@@ -263,10 +278,14 @@ export function ArtifactMediaPreview({
263
278
  nimiToast.danger(t('StudioShell.imagePreviewFailed'));
264
279
  });
265
280
  return () => {
266
- active = false;
281
+ active = false; controller.abort();
267
282
  if (revoke) void revoke();
268
283
  };
269
- }, [imagePreviewOpen, relativePath, t]);
284
+ }, [imagePreviewOpen, relativePath, t, openAssetMediaUrl]);
285
+ if (previewFailed) return <div role="alert">
286
+ <p>{t('StudioShell.mediaPreviewFailed')}</p>
287
+ <Button size="sm" tone="secondary" onClick={() => setAttempt(value => value + 1)}>{t('Common.retry')}</Button>
288
+ </div>;
270
289
  if (!hasPreviewableArtifact(artifact) || !url) return null;
271
290
  const label = mediaLabel || artifact?.displayName || relativePath || fallbackLabel;
272
291
  const isImage = branch === 'image';
@@ -409,6 +428,8 @@ export async function downloadTextFile(
409
428
  }
410
429
  if (!result.ok) {
411
430
  nimiToast.danger(host.translate('Common.exportFailed'));
431
+ } else if (result.value.destination === 'browser-download') {
432
+ nimiToast.success(host.translate('Common.downloadRequested'));
412
433
  } else if (!result.value.revealed) {
413
434
  nimiToast.warning(host.translate('Common.exportSavedRevealFailed', { path: result.value.artifactPath }), { durationMs: 12000 });
414
435
  } else {
@@ -417,13 +438,14 @@ export async function downloadTextFile(
417
438
  return result;
418
439
  }
419
440
 
420
- export async function revealStudioAsset(host: Pick<AIStudioHostPort, 'sdk' | 'translate'>, relativePath: string): Promise<boolean> {
441
+ export async function exportStudioAsset(host: Pick<AIStudioHostPort, 'app' | 'translate'>, relativePath: string): Promise<boolean> {
442
+ const downloading = host.app.projection.assetExportAction() === 'download';
421
443
  try {
422
- await host.sdk.revealLocalAppAsset(relativePath);
423
- nimiToast.success(host.translate('Common.assetRevealed'));
444
+ await host.app.commands.exportAsset(relativePath);
445
+ nimiToast.success(host.translate(downloading ? 'Common.downloadRequested' : 'Common.assetRevealed'));
424
446
  return true;
425
447
  } catch {
426
- nimiToast.danger(host.translate('Common.assetRevealFailed', { path: relativePath }));
448
+ nimiToast.danger(host.translate(downloading ? 'Common.exportFailed' : 'Common.assetRevealFailed', { path: relativePath }));
427
449
  return false;
428
450
  }
429
451
  }