@theoremjs/react 0.3.4-next.881.gf46821d → 0.3.5-next.1000.g569f044

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 (88) hide show
  1. package/README.md +132 -6
  2. package/client/live/use-live-caption-log.d.ts +1 -1
  3. package/client/trace-story.d.ts +1 -1
  4. package/client/transcript-groups.d.ts +27 -4
  5. package/client/transcript-groups.js +45 -7
  6. package/components/InkWaveform.d.ts +1 -1
  7. package/components/live/use-live-call.d.ts +3 -3
  8. package/components/live/use-live-runner-controls.d.ts +2 -2
  9. package/components/live/use-live-runner-ui.d.ts +3 -3
  10. package/components/live/use-live-session-client.d.ts +2 -2
  11. package/components/use-composer-voice.d.ts +1 -1
  12. package/components/use-voice-playback.d.ts +1 -1
  13. package/hooks/use-embedding-index.d.ts +1 -1
  14. package/hooks/use-theorem-chat.d.ts +45 -44
  15. package/hooks/use-theorem-chat.js +10 -1
  16. package/hooks/use-theorem-decision.d.ts +1 -1
  17. package/hooks/use-theorem-embedding.d.ts +1 -1
  18. package/hooks/use-theorem-host.d.ts +1 -1
  19. package/hooks/use-turn-clock.d.ts +19 -0
  20. package/hooks/use-turn-clock.js +71 -0
  21. package/index.d.ts +8 -6
  22. package/index.js +1 -0
  23. package/live.d.ts +4 -4
  24. package/package.json +5 -5
  25. package/ui/ChatComposerBar.d.ts +17 -0
  26. package/ui/ChatComposerBar.js +141 -50
  27. package/ui/ChatComposerRow.d.ts +54 -0
  28. package/ui/ChatComposerRow.js +194 -0
  29. package/ui/ChatTranscript.d.ts +31 -2
  30. package/ui/ChatTranscript.js +158 -90
  31. package/ui/ConsoleFrame.d.ts +2 -2
  32. package/ui/DecisionAnswers.d.ts +1 -1
  33. package/ui/DecisionAnswers.js +9 -6
  34. package/ui/DecisionImages.d.ts +4 -3
  35. package/ui/EmbeddingDocuments.d.ts +2 -2
  36. package/ui/EmbeddingQuery.d.ts +2 -2
  37. package/ui/EmbeddingResults.d.ts +3 -3
  38. package/ui/LiveCallTile.d.ts +2 -2
  39. package/ui/LiveCaptionsPanel.d.ts +1 -1
  40. package/ui/LiveRunner.d.ts +6 -4
  41. package/ui/LiveRunner.js +4 -4
  42. package/ui/LiveToolGateDialog.d.ts +1 -1
  43. package/ui/LiveVideoPreview.d.ts +1 -1
  44. package/ui/RadialCharts.d.ts +2 -2
  45. package/ui/RankedBars.d.ts +1 -1
  46. package/ui/SchemaFields.d.ts +1 -1
  47. package/ui/SchemaFields.js +56 -3
  48. package/ui/ShapedData.js +4 -4
  49. package/ui/StateFields.d.ts +1 -1
  50. package/ui/StateFields.js +3 -3
  51. package/ui/TheoremChat.d.ts +72 -4
  52. package/ui/TheoremChat.js +53 -33
  53. package/ui/TheoremDecision.d.ts +3 -3
  54. package/ui/TheoremEmbedding.d.ts +2 -2
  55. package/ui/TheoremHost.d.ts +16 -2
  56. package/ui/TheoremHost.js +6 -6
  57. package/ui/TheoremSurface.d.ts +22 -0
  58. package/ui/TheoremSurface.js +13 -0
  59. package/ui/ToolResult.js +8 -6
  60. package/ui/TraceCharts.d.ts +2 -2
  61. package/ui/TraceGuardrails.d.ts +2 -2
  62. package/ui/TraceInspectorPanel.d.ts +1 -1
  63. package/ui/TraceOverview.d.ts +2 -2
  64. package/ui/TraceSpanDetail.d.ts +1 -1
  65. package/ui/TraceStory.d.ts +2 -2
  66. package/ui/TraceValues.d.ts +2 -2
  67. package/ui/TraceWaterfall.d.ts +1 -1
  68. package/ui/approval-heading.d.ts +1 -1
  69. package/ui/built/theme.css +91 -41
  70. package/ui/built/theme.css.d.ts +2 -2
  71. package/ui/built/theorem.d.ts +2 -2
  72. package/ui/built/theorem.js +41 -19
  73. package/ui/built/theorem.variants.d.ts +2 -2
  74. package/ui/embedding-space-view.d.ts +1 -1
  75. package/ui/index.d.ts +33 -28
  76. package/ui/index.js +4 -1
  77. package/ui/labels-provider.d.ts +1 -1
  78. package/ui/labels.d.ts +66 -2
  79. package/ui/labels.js +64 -0
  80. package/ui/media-viewer.d.ts +34 -0
  81. package/ui/media-viewer.js +27 -0
  82. package/ui/tool-media-shown.d.ts +13 -0
  83. package/ui/tool-media-shown.js +15 -0
  84. package/ui/tool-media.d.ts +34 -0
  85. package/ui/tool-media.js +52 -0
  86. package/ui/trace-patterns.d.ts +1 -1
  87. package/ui/transcript-copy-text.d.ts +1 -1
  88. package/ui/transcript-copy-text.js +1 -1
@@ -9,7 +9,6 @@ import { HStack } from '@astryxdesign/core/HStack';
9
9
  import { Icon } from '@astryxdesign/core/Icon';
10
10
  import { IconButton } from '@astryxdesign/core/IconButton';
11
11
  import { useLocale } from '@astryxdesign/core/i18n';
12
- import { useLightbox } from '@astryxdesign/core/Lightbox';
13
12
  import { Markdown } from '@astryxdesign/core/Markdown';
14
13
  import { OverflowList } from '@astryxdesign/core/OverflowList';
15
14
  import { Skeleton } from '@astryxdesign/core/Skeleton';
@@ -23,54 +22,36 @@ import { IconCheck, IconCopy } from '@tabler/icons-react';
23
22
  import { stopText } from '@theoremjs/agents/interface';
24
23
  import { citationsFromBlock } from '@theoremjs/web/client';
25
24
  import { createContext, useContext, useEffect, useMemo, useRef, useState, } from 'react';
26
- import { assistantTurnCopyText, assistantTurnTiming, composeAssistantTurn, groupTranscriptBlocks, pendingPromptOf, promptReplyKey, promptTime, replyKey, toolCallLabel, workStatus, } from "../client/transcript-groups.js";
25
+ import { assistantTurnCopyText, assistantTurnTiming, composeAssistantTurn, groupTranscriptBlocks, pendingPromptOf, promptReplyKey, promptTime, toolCallLabel, workStatus, } from "../client/transcript-groups.js";
27
26
  import { useSecondTicker } from "../hooks/use-second-ticker.js";
27
+ import { useTurnClock } from "../hooks/use-turn-clock.js";
28
28
  import { useDisclosureMotion } from "./disclosure-motion.js";
29
29
  import { usageLine, workDuration, workStatusLabel } from "./labels.js";
30
30
  import { TheoremLabelsProvider, useLabels } from "./labels-provider.js";
31
31
  import { useMarkdownPlugins } from "./markdown-plugins.js";
32
+ import { useMediaViewer } from "./media-viewer.js";
32
33
  import { keyedByContent } from "./row-keys.js";
33
34
  import { ShapedData } from "./ShapedData.js";
34
35
  import { ApprovalCard, AuthChallengeCard } from "./ToolGateCard.js";
36
+ import { MediaFileToken, toolMediaShows, useResolvedMedia, useToolMedia, } from "./tool-media.js";
35
37
  import { transcriptBlockCopyText } from "./transcript-copy-text.js";
36
38
  import { VoiceNote } from "./VoiceNote.js";
37
39
  /** Whether the transcript shows usage (`ChatTranscriptProps.usage`). */
38
40
  const ShowUsage = createContext(false);
41
+ /** Whether a tool call's row opens on its detail (`ChatTranscriptProps.showToolData`). */
42
+ const ShowToolData = createContext(true);
43
+ /** Whether a finished tool call's row shows how long it ran (`ChatTranscriptProps.showToolDurations`). */
44
+ const ShowToolDurations = createContext(true);
45
+ /** What the transcript's props say a tool call's row shows. */
46
+ function useToolRowShows() {
47
+ return {
48
+ usage: useContext(ShowUsage),
49
+ detail: useContext(ShowToolData),
50
+ duration: useContext(ShowToolDurations),
51
+ };
52
+ }
39
53
  /** Largest a generated image renders in the transcript. */
40
54
  const GENERATED_IMAGE_MAX_WIDTH = 512;
41
- /** First-seen time per group key, so timestamps don't jump while streaming. */
42
- function useFirstSeen(keys) {
43
- const times = useRef(new Map());
44
- const now = Date.now();
45
- for (const key of keys) {
46
- if (!times.current.has(key))
47
- times.current.set(key, now);
48
- }
49
- return (key) => times.current.get(key) ?? now;
50
- }
51
- /**
52
- * Each turn's span, keyed by the user group that started it. A turn stops at
53
- * a gate and streams again under the same prompt once it's answered; the wait
54
- * in between counts as paused, not worked.
55
- */
56
- function useTurnSpans(streaming, lastUserKey) {
57
- const spans = useRef(new Map());
58
- // why: The first send mounts the transcript already streaming; that's the start.
59
- const wasStreaming = useRef(false);
60
- if (lastUserKey && streaming !== wasStreaming.current) {
61
- const now = Date.now();
62
- const span = spans.current.get(lastUserKey);
63
- if (streaming) {
64
- const pausedMs = span?.endedAt === undefined ? 0 : span.pausedMs + now - span.endedAt;
65
- spans.current.set(lastUserKey, { pausedMs });
66
- }
67
- else if (span) {
68
- spans.current.set(lastUserKey, { ...span, endedAt: now });
69
- }
70
- }
71
- wasStreaming.current = streaming;
72
- return spans.current;
73
- }
74
55
  function CopyButton({ text }) {
75
56
  const t = useLabels();
76
57
  const [copied, setCopied] = useState(false);
@@ -211,9 +192,11 @@ function turnNotice(error, stopped) {
211
192
  function dataUrl(mimeType, data) {
212
193
  return data === undefined ? undefined : `data:${mimeType};base64,${data}`;
213
194
  }
214
- function ImageAttachment({ src, name }) {
215
- const lightbox = useLightbox({ media: { src, alt: name, caption: name }, hasZoom: true });
216
- return (_jsxs(_Fragment, { children: [_jsx(Thumbnail, { src: src, alt: name, label: name, onClick: () => lightbox.open() }), lightbox.element] }));
195
+ function ImageAttachment({ src, name, reference, }) {
196
+ const viewer = useMediaViewer([
197
+ { type: 'image', src, alt: name, caption: name, ...(reference ? { reference } : {}) },
198
+ ]);
199
+ return (_jsxs(_Fragment, { children: [_jsx(Thumbnail, { src: src, alt: name, label: name, onClick: () => viewer.open() }), viewer.element] }));
217
200
  }
218
201
  function UserBlock({ block, metadata }) {
219
202
  if (block.kind === 'user-text')
@@ -224,9 +207,24 @@ function UserBlock({ block, metadata }) {
224
207
  }
225
208
  /** An attached image or voice note inline; any other file as a Token. */
226
209
  function UserFile({ block }) {
227
- const src = dataUrl(block.mimeType, block.data);
210
+ if (block.uri !== undefined)
211
+ return _jsx(SavedUserFile, { block: block, uri: block.uri });
212
+ return _jsx(UserFileView, { block: block, src: dataUrl(block.mimeType, block.data) });
213
+ }
214
+ /** A file the app saved, as its resolver shows it; the named file while it resolves, or when nothing does. */
215
+ function SavedUserFile({ block, uri }) {
216
+ const reference = {
217
+ type: block.type ?? (block.kind === 'user-voice' ? 'audio' : 'document'),
218
+ mimeType: block.mimeType,
219
+ uri,
220
+ ...(block.metadata ? { metadata: block.metadata } : {}),
221
+ };
222
+ const src = useResolvedMedia(reference);
223
+ return _jsx(UserFileView, { block: block, src: src ?? undefined, reference: reference });
224
+ }
225
+ function UserFileView({ block, src, reference, }) {
228
226
  if (src && block.mimeType.startsWith('image/')) {
229
- return _jsx(ImageAttachment, { src: src, name: block.name });
227
+ return _jsx(ImageAttachment, { src: src, name: block.name, ...(reference ? { reference } : {}) });
230
228
  }
231
229
  if (src && block.mimeType.startsWith('audio/')) {
232
230
  return _jsx(VoiceNote, { src: src, mimeType: block.mimeType });
@@ -234,9 +232,9 @@ function UserFile({ block }) {
234
232
  return _jsx(Token, { label: block.name, description: block.mimeType });
235
233
  }
236
234
  function mediaSrc(block) {
237
- return block.url ?? dataUrl(block.mimeType, block.data);
235
+ return dataUrl(block.mimeType, block.data);
238
236
  }
239
- function lightboxMedia(t, src, mimeType) {
237
+ function viewerItem(t, src, mimeType) {
240
238
  if (mimeType.startsWith('image/'))
241
239
  return { src, alt: t('@theorem.transcript.generated_image'), type: 'image' };
242
240
  if (mimeType.startsWith('video/'))
@@ -248,22 +246,22 @@ function galleryItemOf(t, block) {
248
246
  if (block.kind !== 'media')
249
247
  return undefined;
250
248
  const src = mediaSrc(block);
251
- const media = src ? lightboxMedia(t, src, block.mimeType) : undefined;
252
- return media ? { media, preview: block.previewUrl ?? media.src } : undefined;
249
+ const media = src ? viewerItem(t, src, block.mimeType) : undefined;
250
+ return media ? { media } : undefined;
253
251
  }
254
252
  /**
255
253
  * Consecutive images and videos as one wrapping row of Astryx Thumbnails that
256
- * share a Lightbox gallery (Astryx's `useLightbox({ media: [...] })` pattern).
254
+ * share one viewer, so its arrows walk them all.
257
255
  */
258
256
  function MediaGallery({ items }) {
259
- const lightbox = useLightbox({ media: items.map((item) => item.media), hasZoom: true });
260
- return (_jsxs(HStack, { gap: 2, wrap: "wrap", children: [items.map(({ media: item, preview }, i) => (_jsx(Thumbnail, { src: item.type === 'image' ? preview : undefined, alt: item.alt, label: item.alt, onClick: () => lightbox.open(i) }, item.src))), lightbox.element] }));
257
+ const lightbox = useMediaViewer(items.map((item) => item.media));
258
+ return (_jsxs(HStack, { gap: 2, wrap: "wrap", children: [items.map(({ media: item }, i) => (_jsx(Thumbnail, { src: item.type === 'image' ? item.src : undefined, alt: item.alt, label: item.alt, onClick: () => lightbox.open(i) }, item.src))), lightbox.element] }));
261
259
  }
262
260
  /** One generated image, framed to its natural ratio once loaded (the pinned ratio until then). */
263
261
  function GeneratedImage(props) {
264
262
  const t = useLabels();
265
263
  const [natural, setNatural] = useState();
266
- return (_jsx(ClickableCard, { label: t('@theorem.transcript.open_generated_image'), onClick: props.onOpen, padding: 0, width: "100%", maxWidth: GENERATED_IMAGE_MAX_WIDTH, children: _jsx(AspectRatio, { ratio: natural ?? props.ratio ?? 1, fit: "cover", children: _jsx("img", { src: props.item.preview, alt: props.item.media.alt, onLoad: (event) => {
264
+ return (_jsx(ClickableCard, { label: t('@theorem.transcript.open_generated_image'), onClick: props.onOpen, padding: 0, width: "100%", maxWidth: GENERATED_IMAGE_MAX_WIDTH, children: _jsx(AspectRatio, { ratio: natural ?? props.ratio ?? 1, fit: "cover", children: _jsx("img", { src: props.item.media.src, alt: props.item.media.alt, onLoad: (event) => {
267
265
  const { naturalWidth, naturalHeight } = event.currentTarget;
268
266
  if (naturalWidth > 0 && naturalHeight > 0)
269
267
  setNatural(naturalWidth / naturalHeight);
@@ -274,7 +272,7 @@ function GeneratedImage(props) {
274
272
  * own ratio. Anything else (video) keeps the square Thumbnail.
275
273
  */
276
274
  function GeneratedGallery({ items, ratio }) {
277
- const lightbox = useLightbox({ media: items.map((item) => item.media), hasZoom: true });
275
+ const lightbox = useMediaViewer(items.map((item) => item.media));
278
276
  return (_jsxs(VStack, { gap: 2, width: "100%", children: [items.map((item, i) => item.media.type === 'image' ? (_jsx(GeneratedImage, { item: item, ratio: ratio, onOpen: () => lightbox.open(i) }, item.media.src)) : (_jsx(Thumbnail, { alt: item.media.alt, label: item.media.alt, onClick: () => lightbox.open(i) }, item.media.src))), lightbox.element] }));
279
277
  }
280
278
  /** An image takes seconds: a slow, smooth breath rather than the Skeleton's quick stepped blink. */
@@ -288,24 +286,52 @@ function GeneratingImage({ ratio }) {
288
286
  return (_jsx(VStack, { width: "100%", maxWidth: GENERATED_IMAGE_MAX_WIDTH, children: _jsx(AspectRatio, { ratio: ratio ?? 1, children: _jsx(Skeleton, { width: "100%", height: "100%", radius: 3, style: GENERATING_PULSE, "aria-label": t('@theorem.transcript.generating_image') }) }) }));
289
287
  }
290
288
  function MediaBlock({ block }) {
289
+ if (block.uri !== undefined) {
290
+ return (_jsx(ReferencedMedia, { reference: {
291
+ type: block.type ?? 'document',
292
+ mimeType: block.mimeType,
293
+ uri: block.uri,
294
+ ...(block.metadata ? { metadata: block.metadata } : {}),
295
+ } }));
296
+ }
291
297
  const src = mediaSrc(block);
292
298
  if (src && block.mimeType.startsWith('audio/')) {
293
299
  return _jsx(VoiceNote, { src: src, mimeType: block.mimeType });
294
300
  }
295
301
  return _jsx(Text, { color: "secondary", children: block.mimeType });
296
302
  }
303
+ /**
304
+ * A reference a tool sent, as the app's resolver shows it: a picture or video in a gallery of its
305
+ * own, a clip to play; the named file while it resolves, or when nothing does.
306
+ */
307
+ export function ReferencedMedia({ reference }) {
308
+ const t = useLabels();
309
+ const src = useResolvedMedia(reference);
310
+ if (src && reference.mimeType.startsWith('audio/')) {
311
+ return _jsx(VoiceNote, { src: src, mimeType: reference.mimeType });
312
+ }
313
+ const media = src ? viewerItem(t, src, reference.mimeType) : undefined;
314
+ if (media)
315
+ return _jsx(MediaGallery, { items: [{ media: { ...media, reference } }] });
316
+ return _jsx(MediaFileToken, { reference: reference });
317
+ }
297
318
  /**
298
319
  * Runs of images/videos become one gallery row; consecutive citation blocks
299
- * become one sources row; everything else is a row of its own.
320
+ * become one sources row; calls side by side become one tools row; everything
321
+ * else is a row of its own.
300
322
  */
301
- function bodyRows(t, body) {
323
+ function bodyRows(t, body, shown) {
302
324
  const rows = [];
303
325
  for (const block of body) {
326
+ if (block.kind === 'media' && !toolMediaShows(block, shown))
327
+ continue;
304
328
  const item = galleryItemOf(t, block);
305
329
  if (item)
306
330
  addToGallery(rows, item);
307
331
  else if (block.kind === 'citation')
308
332
  addToSources(rows, citationsFromBlock(block));
333
+ else if (block.kind === 'tool')
334
+ addToTools(rows, block);
309
335
  else
310
336
  rows.push({ kind: 'block', block });
311
337
  }
@@ -318,6 +344,13 @@ function addToGallery(rows, item) {
318
344
  else
319
345
  rows.push({ kind: 'gallery', items: [item] });
320
346
  }
347
+ function addToTools(rows, block) {
348
+ const last = rows.at(-1);
349
+ if (last?.kind === 'tools')
350
+ last.blocks.push(block);
351
+ else
352
+ rows.push({ kind: 'tools', blocks: [block] });
353
+ }
321
354
  function addToSources(rows, citations) {
322
355
  if (citations.length === 0)
323
356
  return;
@@ -397,8 +430,8 @@ function StreamedMarkdown({ text, streaming, density, components, }) {
397
430
  function BodyBlock({ block, streaming }) {
398
431
  if (block.kind === 'text')
399
432
  return _jsx(StreamedMarkdown, { text: block.text, streaming: streaming });
400
- if (block.kind === 'tool')
401
- return _jsx(ToolCall, { tool: block.tool });
433
+ if (block.kind === 'thought')
434
+ return _jsx(ThoughtLine, { text: block.text, streaming: streaming });
402
435
  return _jsx(ResultBlock, { block: block });
403
436
  }
404
437
  /** Non-streaming answer rows: errors, structured output, and media. Citations coalesce in bodyRows. */
@@ -429,20 +462,33 @@ function toolDetail(t, tool, result) {
429
462
  /** The calls an agent tool's agent made, each a call row of its own. */
430
463
  function ToolSteps({ steps }) {
431
464
  const t = useLabels();
432
- const showUsage = useContext(ShowUsage);
433
- return (_jsxs(VStack, { gap: 2, children: [_jsx(Text, { type: "supporting", color: "secondary", children: t('@theorem.transcript.tool_steps') }), _jsx(ToolCalls, { calls: steps.map((step) => toolCallItem(t, step.operationId ?? step.callId, step, showUsage)) })] }));
465
+ const shows = useToolRowShows();
466
+ return (_jsxs(VStack, { gap: 2, children: [_jsx(Text, { type: "supporting", color: "secondary", children: t('@theorem.transcript.tool_steps') }), _jsx(ToolCalls, { calls: steps.map((step) => toolCallItem(t, step.operationId ?? step.callId, step, shows)) })] }));
434
467
  }
435
- /** How long a finished call ran, when both ends were seen. */
436
- function toolDuration(t, tool) {
437
- if (tool.startedAt === undefined || tool.endedAt === undefined)
468
+ /** How long a finished call ran, when the transcript shows it and both ends were seen. */
469
+ function toolDuration(t, tool, shows) {
470
+ if (!shows.duration || tool.startedAt === undefined || tool.endedAt === undefined)
438
471
  return {};
439
472
  return { duration: workDuration(t, tool.endedAt - tool.startedAt) };
440
473
  }
441
474
  /** What the agent an agent tool ran used, after the call's name. Only agent tools report it. */
442
- function toolUsageStats(state, showUsage) {
443
- return showUsage && state.tokens ? { stats: _jsx(Usage, { tokens: state.tokens }) } : {};
475
+ function toolUsageStats(state, shows) {
476
+ return shows.usage && state.tokens ? { stats: _jsx(Usage, { tokens: state.tokens }) } : {};
477
+ }
478
+ // why: The row already reads the failure's message, and `error` is the person's wording of the
479
+ // same failure, so the detail holds only what the row does not say.
480
+ function failureDetail(failure) {
481
+ return {
482
+ code: failure.code,
483
+ kind: failure.kind,
484
+ ...(failure.details === undefined ? {} : { details: failure.details }),
485
+ };
444
486
  }
445
- function toolCallItem(t, id, tool, showUsage) {
487
+ /** A call's detail as its row takes it: none when the transcript shows no tool detail. */
488
+ function rowDetail(t, tool, shows, result) {
489
+ return shows.detail ? { resultDetail: toolDetail(t, tool, result) } : {};
490
+ }
491
+ function toolCallItem(t, id, tool, shows) {
446
492
  const base = { key: id, name: toolCallLabel(tool) };
447
493
  const { state } = tool;
448
494
  switch (state?.phase) {
@@ -451,29 +497,30 @@ function toolCallItem(t, id, tool, showUsage) {
451
497
  ...base,
452
498
  status: 'error',
453
499
  target: state.failure.message,
454
- ...toolUsageStats(state, showUsage),
500
+ ...toolUsageStats(state, shows),
455
501
  errorMessage: state.failure.message,
456
- resultDetail: toolDetail(t, tool, _jsx(ShapedData, { value: state.failure, title: t('@theorem.transcript.tool_error') })),
502
+ ...rowDetail(t, tool, shows, _jsx(ShapedData, { value: failureDetail(state.failure), title: t('@theorem.transcript.tool_error') })),
457
503
  };
458
504
  case 'complete':
459
505
  return {
460
506
  ...base,
461
507
  status: 'complete',
462
- ...toolDuration(t, tool),
463
- ...toolUsageStats(state, showUsage),
464
- resultDetail: toolDetail(t, tool, state.output === undefined ? undefined : (_jsx(ShapedData, { value: state.output, title: t('@theorem.transcript.tool_output') }))),
508
+ ...toolDuration(t, tool, shows),
509
+ ...toolUsageStats(state, shows),
510
+ ...rowDetail(t, tool, shows, state.output === undefined ? undefined : (_jsx(ShapedData, { value: state.output, title: t('@theorem.transcript.tool_output') }))),
465
511
  };
466
512
  case 'running':
467
513
  case 'background':
468
- return { ...base, status: 'running', resultDetail: toolDetail(t, tool) };
514
+ return { ...base, status: 'running', ...rowDetail(t, tool, shows) };
469
515
  default:
470
- return { ...base, status: 'pending', resultDetail: toolDetail(t, tool) };
516
+ return { ...base, status: 'pending', ...rowDetail(t, tool, shows) };
471
517
  }
472
518
  }
473
- function ToolCall({ tool }) {
519
+ /** Calls side by side in a reply's body: one call's row, or several under their count. */
520
+ function ToolRun({ blocks }) {
474
521
  const t = useLabels();
475
- const showUsage = useContext(ShowUsage);
476
- return _jsx(ToolCalls, { calls: [toolCallItem(t, tool.name, tool, showUsage)] });
522
+ const shows = useToolRowShows();
523
+ return _jsx(ToolCalls, { calls: blocks.map((block) => toolCallItem(t, block.id, block.tool, shows)) });
477
524
  }
478
525
  /**
479
526
  * Thinking reads as quieter text than the reply. Astryx has no reasoning
@@ -489,9 +536,18 @@ const THOUGHT_TEXT = {
489
536
  '--text-body-size': 'var(--text-supporting-size)',
490
537
  '--color-text-primary': 'var(--color-text-secondary)',
491
538
  };
539
+ /**
540
+ * A thought where it came in a reply, folded to one line that opens on the whole of it. It starts
541
+ * folded, streaming too: the reply's words are what is read.
542
+ */
543
+ function ThoughtLine({ text, streaming }) {
544
+ const t = useLabels();
545
+ const trigger = (_jsx(Text, { size: "sm", color: "secondary", maxLines: 1, children: t('@theorem.transcript.thought', { text: text.trim().replace(/\s+/g, ' ') }) }));
546
+ return (_jsx(Collapsible, { trigger: trigger, defaultIsOpen: false, children: _jsx("div", { style: THOUGHT_TEXT, children: _jsx(StreamedMarkdown, { text: text, streaming: streaming, density: "compact", components: THOUGHT_MARKDOWN }) }) }));
547
+ }
492
548
  function TraceList({ items, streaming }) {
493
549
  const t = useLabels();
494
- const showUsage = useContext(ShowUsage);
550
+ const shows = useToolRowShows();
495
551
  const rows = [];
496
552
  let tools = [];
497
553
  const flush = () => {
@@ -502,7 +558,7 @@ function TraceList({ items, streaming }) {
502
558
  };
503
559
  for (const [i, item] of items.entries()) {
504
560
  if (item.kind === 'tool') {
505
- tools.push(toolCallItem(t, item.id, item.block.tool, showUsage));
561
+ tools.push(toolCallItem(t, item.id, item.block.tool, shows));
506
562
  continue;
507
563
  }
508
564
  flush();
@@ -524,6 +580,7 @@ function answerSent(answering, tool) {
524
580
  }
525
581
  function GateCard({ block, handle, handlers, }) {
526
582
  const { tool } = block;
583
+ const shows = useToolRowShows();
527
584
  const gate = personGate(tool);
528
585
  if (!gate)
529
586
  return null;
@@ -532,7 +589,7 @@ function GateCard({ block, handle, handlers, }) {
532
589
  if (gate.kind === 'auth') {
533
590
  return (_jsx(AuthChallengeCard, { gate: gate, toolName: tool.name, submitted: answer === 'auth', onAuthenticated: (secret) => handlers.onAuthenticated?.(index, secret) }));
534
591
  }
535
- return (_jsx(ApprovalCard, { gate: gate, toolName: tool.name, agent: handle, input: tool.arguments, decided: answer === 'auth' ? null : answer, onDecision: (action) => handlers.onToolDecision?.(index, action) }));
592
+ return (_jsx(ApprovalCard, { gate: gate, toolName: tool.name, agent: handle, ...(shows.detail ? { input: tool.arguments } : {}), decided: answer === 'auth' ? null : answer, onDecision: (action) => handlers.onToolDecision?.(index, action) }));
536
593
  }
537
594
  /** Live elapsed time while the turn streams; its final duration once it ends. */
538
595
  /** Live: counted from the start. Stopped: the work its blocks record. */
@@ -545,15 +602,19 @@ function useTurnElapsed(streaming, startedAt, workedMs) {
545
602
  /**
546
603
  * The turn's work status; with a trace, a Collapsible over its thinking and
547
604
  * tool calls, open while the turn runs so they can be followed, folded away
548
- * when it ends.
605
+ * when it ends. invariant: a run's end folds only what the run opened; a trace
606
+ * the person opened before a wake continued the turn stays open.
549
607
  */
550
608
  function TurnStatus(props) {
551
609
  const { status, streaming } = props;
552
610
  const [traceOpen, setTraceOpen] = useState(streaming);
553
611
  const [wasStreaming, setWasStreaming] = useState(streaming);
612
+ const [openBefore, setOpenBefore] = useState(false);
554
613
  if (wasStreaming !== streaming) {
555
614
  setWasStreaming(streaming);
556
- setTraceOpen(streaming);
615
+ if (streaming)
616
+ setOpenBefore(traceOpen);
617
+ setTraceOpen(streaming || (traceOpen && openBefore));
557
618
  }
558
619
  if (!status)
559
620
  return null;
@@ -565,6 +626,8 @@ function TurnStatus(props) {
565
626
  function BodyRowView({ row, streaming, imageOutput, }) {
566
627
  if (row.kind === 'block')
567
628
  return _jsx(BodyBlock, { block: row.block, streaming: streaming });
629
+ if (row.kind === 'tools')
630
+ return _jsx(ToolRun, { blocks: row.blocks });
568
631
  if (row.kind === 'sources')
569
632
  return _jsx(Sources, { citations: row.citations });
570
633
  if (imageOutput)
@@ -582,13 +645,19 @@ function AssistantTurn(props) {
582
645
  const chrome = useChromeReveal(props.isNewest === true);
583
646
  const showUsage = useContext(ShowUsage);
584
647
  const elapsedMs = useTurnElapsed(props.streaming, props.startedAt, props.workedMs);
585
- const { trace, gatedTools, body, hasTrace } = composeAssistantTurn(props.blocks, props.bodyKindPlacement !== undefined
586
- ? { bodyKindPlacement: props.bodyKindPlacement }
587
- : undefined);
588
- const rows = bodyRows(t, body);
589
- const status = workStatusLabel(t, workStatus({ streaming: props.streaming, hasTrace, elapsedMs }));
648
+ const { trace, gatedTools, body, hasTrace, hasSteps } = composeAssistantTurn(props.blocks, {
649
+ ...(props.bodyKindPlacement !== undefined
650
+ ? { bodyKindPlacement: props.bodyKindPlacement }
651
+ : {}),
652
+ ...(props.stepLayout !== undefined ? { stepLayout: props.stepLayout } : {}),
653
+ });
654
+ const { shown } = useToolMedia();
655
+ const rows = bodyRows(t, body, shown);
656
+ const status = workStatusLabel(t, workStatus({ streaming: props.streaming, hasSteps, elapsedMs }));
590
657
  const copyText = assistantTurnCopyText(body.length > 0 ? body : props.blocks);
591
- return (_jsx(ChatMessage, { sender: "assistant", name: props.handle, ...chrome.handlers, metadata: props.streaming ? undefined : (_jsx(MessageChrome, { sender: "assistant", at: props.at, copyText: copyText, error: props.error, stopped: props.stopped, usage: showUsage ? props.usage : undefined, revealed: chrome.revealed })), children: _jsxs(VStack, { gap: 3, width: "100%", children: [_jsx(TurnStatus, { status: status, trace: trace, hasTrace: hasTrace, streaming: props.streaming }), gatedTools.map((block) => (_jsx(GateCard, { block: block, handle: props.handle, handlers: props.handlers }, block.id))), keyedByContent(rows, (row) => row.kind === 'gallery' || row.kind === 'sources' ? row.kind : row.block.kind).map(({ item: row, index: i, key }) => (_jsx(BodyRowView
658
+ return (_jsx(ChatMessage, { sender: "assistant", name: props.handle, ...chrome.handlers, metadata: props.streaming ? undefined : (_jsx(MessageChrome, { sender: "assistant", at: props.at, copyText: copyText, error: props.error, stopped: props.stopped, usage: showUsage ? props.usage : undefined, revealed: chrome.revealed })), children: _jsxs(VStack, { gap: 3, width: "100%", children: [_jsx(TurnStatus, { status: status, trace: trace, hasTrace: hasTrace, streaming: props.streaming }), gatedTools.map((block) => (_jsx(GateCard, { block: block, handle: props.handle, handlers: props.handlers }, block.id))), keyedByContent(rows, (row) => row.kind === 'gallery' || row.kind === 'sources' || row.kind === 'tools'
659
+ ? row.kind
660
+ : row.block.kind).map(({ item: row, index: i, key }) => (_jsx(BodyRowView
592
661
  // why: Not the block id: the committed turn re-mints ids, and a
593
662
  // remount would cut the text reveal short.
594
663
  , { row: row, streaming: props.streaming && i === rows.length - 1, imageOutput: props.imageOutput }, key))), _jsx(PendingImage, { imageOutput: props.imageOutput, streaming: props.streaming, rows: rows })] }) }));
@@ -617,12 +686,12 @@ function isBareFailure(group) {
617
686
  }
618
687
  /** Theorem transcript blocks rendered as Astryx chat messages. */
619
688
  export function ChatTranscript(props) {
620
- return (_jsx(TheoremLabelsProvider, { children: _jsx(ShowUsage.Provider, { value: props.usage === true, children: _jsx(ChatTranscriptBody, { ...props }) }) }));
689
+ return (_jsx(TheoremLabelsProvider, { children: _jsx(ShowUsage.Provider, { value: props.usage === true, children: _jsx(ShowToolData.Provider, { value: props.showToolData !== false, children: _jsx(ShowToolDurations.Provider, { value: props.showToolDurations !== false, children: _jsx(ChatTranscriptBody, { ...props }) }) }) }) }));
621
690
  }
622
- function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToolDecision, answering = null, onAuthenticated, emptyState, dividers, imageOutput, bodyKindPlacement, labels, }) {
691
+ function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToolDecision, answering = null, onAuthenticated, emptyState, dividers, imageOutput, bodyKindPlacement, stepLayout, labels, clock, }) {
623
692
  const groups = useMemo(() => groupTranscriptBlocks(blocks, dividers && new Set(Object.keys(dividers))), [blocks, dividers]);
624
- const timeOf = useFirstSeen(groups.map((group, index) => (group.kind === 'user' ? group.key : replyKey(groups, index))));
625
- const spans = useTurnSpans(streaming, groups.findLast((group) => group.kind === 'user')?.key);
693
+ const own = useTurnClock(groups, streaming);
694
+ const { timeOf, replyStart } = clock ?? own;
626
695
  const pendingPrompt = streaming ? pendingPromptOf(groups) : undefined;
627
696
  const listRef = useRef(null);
628
697
  useDisclosureMotion(listRef);
@@ -632,7 +701,7 @@ function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToo
632
701
  onToolDecision,
633
702
  onAuthenticated,
634
703
  };
635
- const turn = { handle, handlers, imageOutput, bodyKindPlacement };
704
+ const turn = { handle, handlers, imageOutput, bodyKindPlacement, stepLayout };
636
705
  const lastUser = groups.findLastIndex((group) => group.kind === 'user');
637
706
  const userTurn = (group, index) => {
638
707
  const next = groups[index + 1];
@@ -649,8 +718,7 @@ function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToo
649
718
  groups,
650
719
  index,
651
720
  streaming,
652
- timeOf,
653
- spans,
721
+ replyStart,
654
722
  });
655
723
  // why: A reply is dated when it last stopped: a reply that just finished reads "now".
656
724
  const at = endedAt ?? timeOf(key);
@@ -668,7 +736,7 @@ function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToo
668
736
  // why: It sits in the same keyed list as the streamed reply, so the reply stays
669
737
  // one message; a remount would read to the layout as a new message.
670
738
  if (pendingPrompt) {
671
- turns.push(_jsx(AssistantTurn, { ...turn, blocks: [], streaming: true, at: timeOf(pendingPrompt.key), startedAt: timeOf(pendingPrompt.key) }, promptReplyKey(pendingPrompt)));
739
+ turns.push(_jsx(AssistantTurn, { ...turn, blocks: [], streaming: true, at: timeOf(pendingPrompt.key), startedAt: replyStart(pendingPrompt) ?? timeOf(pendingPrompt.key) }, promptReplyKey(pendingPrompt)));
672
740
  }
673
741
  return (_jsx(ChatMessageList, { ref: listRef, isStreaming: streaming, emptyState: emptyState, children: turns }));
674
742
  }
@@ -1,8 +1,8 @@
1
1
  import type { DefinedTheme } from '@astryxdesign/core/theme';
2
2
  import type { HttpOptions } from '@theoremjs/web/client';
3
3
  import { type CSSProperties, type ReactNode } from 'react';
4
- import type { TheoremLabels } from './labels.ts';
5
- import { type TraceInspector } from './TraceInspectorPanel.tsx';
4
+ import type { TheoremLabels } from './labels.js';
5
+ import { type TraceInspector } from './TraceInspectorPanel.js';
6
6
  /** The props a one-call console page shares: its look, its wording, its trace, and its layout. */
7
7
  export type ConsolePageProps = {
8
8
  /** Extra fetch options for the default HTTP transport (auth headers, custom fetch). */
@@ -1,7 +1,7 @@
1
1
  import type { DecisionJson, DecisionResult } from '@theoremjs/agents';
2
2
  import type { DecisionInterface } from '@theoremjs/web/client';
3
3
  import { type ReactNode } from 'react';
4
- import { type DecisionImages } from '../client/decision-images.ts';
4
+ import { type DecisionImages } from '../client/decision-images.js';
5
5
  export type TheoremDecisionAnswersProps = {
6
6
  iface: DecisionInterface;
7
7
  result: DecisionResult;
@@ -4,7 +4,6 @@ import { HStack } from '@astryxdesign/core/HStack';
4
4
  import { Icon } from '@astryxdesign/core/Icon';
5
5
  import { IconButton } from '@astryxdesign/core/IconButton';
6
6
  import { useLocale } from '@astryxdesign/core/i18n';
7
- import { Lightbox } from '@astryxdesign/core/Lightbox';
8
7
  import { Text } from '@astryxdesign/core/Text';
9
8
  import { Tooltip } from '@astryxdesign/core/Tooltip';
10
9
  import { VStack } from '@astryxdesign/core/VStack';
@@ -15,6 +14,7 @@ import { Arrive, Stream } from "./arrive.js";
15
14
  import { CardWall } from "./CardWall.js";
16
15
  import { resultMeta } from "./labels.js";
17
16
  import { useLabels } from "./labels-provider.js";
17
+ import { useMediaViewer } from "./media-viewer.js";
18
18
  import { ChartCard, TRACE_RADIUS, traceFill } from "./trace-patterns.js";
19
19
  const EASE = 'var(--duration-medium) var(--ease-standard)';
20
20
  /** Height of a share bar, as the trace draws one. */
@@ -134,6 +134,9 @@ function BoxCrop({ source, box, caption, }) {
134
134
  const src = imageSrc(source);
135
135
  const size = useImageSize(src);
136
136
  const [marked, setMarked] = useState(null);
137
+ const viewer = useMediaViewer([
138
+ { type: 'image', src: marked ?? src, alt: t('@theorem.decision.box_marked'), caption },
139
+ ]);
137
140
  if (!size)
138
141
  return null;
139
142
  const crop = cropOf(box);
@@ -144,7 +147,10 @@ function BoxCrop({ source, box, caption, }) {
144
147
  outline: themeColor(event.currentTarget, '--color-accent'),
145
148
  shade: themeColor(event.currentTarget, '--color-overlay'),
146
149
  };
147
- void markedBox(src, box, marks).then(setMarked);
150
+ void markedBox(src, box, marks).then((next) => {
151
+ setMarked(next);
152
+ viewer.open();
153
+ });
148
154
  }, children: _jsx("div", { role: "img", "aria-label": t('@theorem.decision.box_in'), style: {
149
155
  position: 'relative',
150
156
  overflow: 'hidden',
@@ -159,10 +165,7 @@ function BoxCrop({ source, box, caption, }) {
159
165
  left: `${String(crop.left)}%`,
160
166
  top: `${String(crop.top)}%`,
161
167
  maxWidth: 'none',
162
- } }) }) }) }), _jsx(Lightbox, { isOpen: marked !== null, onOpenChange: (isOpen) => {
163
- if (!isOpen)
164
- setMarked(null);
165
- }, media: { src: marked ?? src, alt: t('@theorem.decision.box_marked'), caption }, hasZoom: true })] }));
168
+ } }) }) }) }), viewer.element] }));
166
169
  }
167
170
  /** The box cut from its image, or drawn in a frame that stands for the whole image when the page cannot tell which. */
168
171
  function BoxAnswer({ title, aside, detail, answer, image, asked, }) {
@@ -1,12 +1,13 @@
1
- import { type DecisionImages } from '../client/decision-images.ts';
1
+ import type { DecisionAsset } from '@theoremjs/agents';
2
+ import { type DecisionImages } from '../client/decision-images.js';
2
3
  /**
3
4
  * Reads each file as an image and hands over the ones that are, with the name of the first that
4
5
  * is not as the refusal to show.
5
6
  */
6
7
  export declare function useImageReader(): {
7
- read: (files: File | File[] | null) => Promise<[File, import("../../../mod.ts").DecisionAsset][]>;
8
+ read: (files: File | File[] | null) => Promise<[File, DecisionAsset][]>;
8
9
  status: {
9
- type: "error";
10
+ type: 'error';
10
11
  message: string;
11
12
  } | undefined;
12
13
  };
@@ -2,8 +2,8 @@ import { type EmbeddingInput } from '@theoremjs/agents';
2
2
  import type { EmbeddingInterface } from '@theoremjs/web/client';
3
3
  import { type EmbeddingInputCheck, type EmbeddingMediaPart } from '@theoremjs/web/client';
4
4
  import { type ReactNode } from 'react';
5
- import { type ConsoleView } from './ConsoleFrame.tsx';
6
- import type { LabelText } from './labels.ts';
5
+ import { type ConsoleView } from './ConsoleFrame.js';
6
+ import type { LabelText } from './labels.js';
7
7
  /** The profile's `inputs`, which every request is held to. */
8
8
  export type Rules = EmbeddingInterface['inputs'];
9
9
  /** A document as the list shows it: what it sends, and the file it came from. */
@@ -1,7 +1,7 @@
1
1
  import { type EmbeddingInput } from '@theoremjs/agents';
2
2
  import { type EmbeddingFields } from '@theoremjs/web/client';
3
- import { type ConsoleView } from './ConsoleFrame.tsx';
4
- import { type Rules } from './EmbeddingDocuments.tsx';
3
+ import { type ConsoleView } from './ConsoleFrame.js';
4
+ import { type Rules } from './EmbeddingDocuments.js';
5
5
  /** Where the embedded documents stand for a search: as embedded, or changed since. */
6
6
  export type IndexState = 'fresh' | 'stale' | 'model';
7
7
  /** The query, held as the JSON of the one input it sends, and the view it is edited in. */
@@ -1,8 +1,8 @@
1
1
  import type { EmbeddingResult } from '@theoremjs/agents';
2
2
  import type { EmbeddingMatch } from '@theoremjs/web/client';
3
- import type { EmbeddingIndex, IndexProgress } from '../hooks/use-embedding-index.ts';
4
- import type { OneCallState } from '../hooks/use-one-call.ts';
5
- import { type EmbeddingDocument } from './EmbeddingDocuments.tsx';
3
+ import type { EmbeddingIndex, IndexProgress } from '../hooks/use-embedding-index.js';
4
+ import type { OneCallState } from '../hooks/use-one-call.js';
5
+ import { type EmbeddingDocument } from './EmbeddingDocuments.js';
6
6
  /** Which document the space and the matches both point at, and how either changes it. */
7
7
  export type Pointing = {
8
8
  hovered: number | null;
@@ -1,6 +1,6 @@
1
1
  import type { DefinedTheme } from '@astryxdesign/core/theme';
2
- import type { LiveCall } from '../components/live/use-live-call.ts';
3
- import { type TheoremLabels } from './labels.ts';
2
+ import type { LiveCall } from '../components/live/use-live-call.js';
3
+ import { type TheoremLabels } from './labels.js';
4
4
  export type LiveCallTileProps = {
5
5
  /** The call to draw, from `useLiveCall`: the same call `LiveRunner` draws. */
6
6
  call: LiveCall;
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
- import { type LiveCaptionState, type LiveCaptionTurn } from '../client/live/live-captions.ts';
2
+ import { type LiveCaptionState, type LiveCaptionTurn } from '../client/live/live-captions.js';
3
3
  export type LiveCaptionsPanelProps = {
4
4
  /** Profile handle. The transcript shows it as the agent's name. */
5
5
  handle: string;