@theoremjs/react 0.3.5-next.919.gc55551d → 0.3.5-next.927.g1f89ea0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -176,6 +176,26 @@ To draw your own figures like the trace panel does, `@theoremjs/react/ui` also e
176
176
  | `initialPending` | The messages that the composer starts with set aside: queued, stashed, or steering, as `createComposerPendingMessage` from `@theoremjs/agents/interface` makes them. The component reads them once, when it mounts. |
177
177
  | `chatRef` | Sends a message, stops a reply, or focuses the composer from your code. See below. |
178
178
  | `composer` | `false` leaves the composer out. The chat is the transcript alone, and your own control sends through `chatRef`. Default: `true`. |
179
+ | `media` | Which media from tools the chat shows. `'sent'` shows only what a tool sent to the person. `'all'` also shows what only the model read, for an evaluation view. Default: `'sent'`. See [Tool media](#tool-media). |
180
+ | `resolveMedia` | Turns a tool's reference into an address the page can load. See [Tool media](#tool-media). |
181
+
182
+ ### Tool media
183
+
184
+ A tool can return media for the model, for the person, or for both. The chat shows media from a tool only when the tool marked it `sent`, unless you pass `media="all"`. Media that a model generated and files that the user attached always show.
185
+
186
+ A tool can also return a **reference**: `{ type, mimeType, uri }`, such as a `gs://` object. The model never reads it, and the page cannot load its `uri` as it stands. Pass `resolveMedia` to turn it into an address the page can load, under the viewer's own sign-in:
187
+
188
+ ```tsx
189
+ <TheoremChat
190
+ endpoint="/api/theorem"
191
+ resolveMedia={async (reference) => {
192
+ const res = await fetch(`/api/files/sign?uri=${encodeURIComponent(reference.uri)}`);
193
+ return res.ok ? (await res.json()).url : null;
194
+ }}
195
+ />
196
+ ```
197
+
198
+ `resolveMedia` returns a string, `null`, or a promise of either. While it works, and when it returns `null` or throws, the chat shows the file name from the `uri`. `TheoremHost` takes the same `resolveMedia`, and always shows all the media of a call.
179
199
 
180
200
  ### Resume a conversation
181
201
 
@@ -255,7 +275,7 @@ The handler accepts these requests:
255
275
  - `POST /call` with `{ name, input }` streams the events of the call.
256
276
  - `POST /invoke` answers a gate that paused a call.
257
277
 
258
- The console builds a form from the input schema. It shows the result as figures, charts, tables, images, audio, or Markdown, with the raw JSON beside it. If the data renderer fails, the view switches to JSON so the selected view matches what is shown. For your own UI, use `createHostTransport` and `useTheoremHost`.
278
+ The console builds a form from the input schema. It shows the result as figures, charts, tables, images, audio, or Markdown, with the raw JSON beside it. It shows every piece of media the call returned, and a reference through `resolveMedia` (see [Tool media](#tool-media)). If the data renderer fails, the view switches to JSON so the selected view matches what is shown. For your own UI, use `createHostTransport` and `useTheoremHost`.
259
279
 
260
280
  #### Serve a host profile over MCP
261
281
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/react",
3
- "version": "0.3.5-next.919.gc55551d",
3
+ "version": "0.3.5-next.927.g1f89ea0",
4
4
  "description": "React bindings for Theorem: headless hooks + transport, an Astryx chat UI, and a Web-standard server handler.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -60,8 +60,8 @@
60
60
  "@stylexjs/stylex": "0.19.0",
61
61
  "react": "^19.0.0",
62
62
  "react-dom": "^19.0.0",
63
- "@theoremjs/agents": "^0.3.5-next.919.gc55551d",
64
- "@theoremjs/web": "^0.3.5-next.919.gc55551d"
63
+ "@theoremjs/agents": "^0.3.5-next.927.g1f89ea0",
64
+ "@theoremjs/web": "^0.3.5-next.927.g1f89ea0"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@astryxdesign/core": {
@@ -5,6 +5,7 @@ import type { AnsweringGate } from '@theoremjs/web/client';
5
5
  import { type ReactNode } from 'react';
6
6
  import { type ComposeAssistantTurnOptions } from '../client/transcript-groups.ts';
7
7
  import { type ToolDecision } from './ToolGateCard.tsx';
8
+ import { type MediaReference } from './tool-media.tsx';
8
9
  export type ChatTranscriptProps = {
9
10
  blocks: readonly TranscriptBlock[];
10
11
  /** Assistant display name (profile handle). */
@@ -45,5 +46,12 @@ export type ChatTranscriptProps = {
45
46
  export type ImageOutput = {
46
47
  ratio?: number;
47
48
  };
49
+ /**
50
+ * A reference a tool sent, as the app's resolver shows it: a picture or video in a gallery of its
51
+ * own, a clip to play; the named file while it resolves, or when nothing does.
52
+ */
53
+ export declare function ReferencedMedia({ reference }: {
54
+ reference: MediaReference;
55
+ }): import("react").JSX.Element;
48
56
  /** Theorem transcript blocks rendered as Astryx chat messages. */
49
57
  export declare function ChatTranscript(props: ChatTranscriptProps): import("react").JSX.Element;
@@ -32,6 +32,7 @@ import { useMarkdownPlugins } from "./markdown-plugins.js";
32
32
  import { keyedByContent } from "./row-keys.js";
33
33
  import { ShapedData } from "./ShapedData.js";
34
34
  import { ApprovalCard, AuthChallengeCard } from "./ToolGateCard.js";
35
+ import { MediaFileToken, toolMediaShows, useResolvedMedia, useToolMedia, } from "./tool-media.js";
35
36
  import { transcriptBlockCopyText } from "./transcript-copy-text.js";
36
37
  import { VoiceNote } from "./VoiceNote.js";
37
38
  /** Whether the transcript shows usage (`ChatTranscriptProps.usage`). */
@@ -234,7 +235,7 @@ function UserFile({ block }) {
234
235
  return _jsx(Token, { label: block.name, description: block.mimeType });
235
236
  }
236
237
  function mediaSrc(block) {
237
- return block.url ?? dataUrl(block.mimeType, block.data);
238
+ return dataUrl(block.mimeType, block.data);
238
239
  }
239
240
  function lightboxMedia(t, src, mimeType) {
240
241
  if (mimeType.startsWith('image/'))
@@ -249,7 +250,7 @@ function galleryItemOf(t, block) {
249
250
  return undefined;
250
251
  const src = mediaSrc(block);
251
252
  const media = src ? lightboxMedia(t, src, block.mimeType) : undefined;
252
- return media ? { media, preview: block.previewUrl ?? media.src } : undefined;
253
+ return media ? { media } : undefined;
253
254
  }
254
255
  /**
255
256
  * Consecutive images and videos as one wrapping row of Astryx Thumbnails that
@@ -257,13 +258,13 @@ function galleryItemOf(t, block) {
257
258
  */
258
259
  function MediaGallery({ items }) {
259
260
  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] }));
261
+ 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
262
  }
262
263
  /** One generated image, framed to its natural ratio once loaded (the pinned ratio until then). */
263
264
  function GeneratedImage(props) {
264
265
  const t = useLabels();
265
266
  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) => {
267
+ 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
268
  const { naturalWidth, naturalHeight } = event.currentTarget;
268
269
  if (naturalWidth > 0 && naturalHeight > 0)
269
270
  setNatural(naturalWidth / naturalHeight);
@@ -288,19 +289,39 @@ function GeneratingImage({ ratio }) {
288
289
  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
290
  }
290
291
  function MediaBlock({ block }) {
292
+ if (block.uri !== undefined) {
293
+ return (_jsx(ReferencedMedia, { reference: { type: block.type ?? 'document', mimeType: block.mimeType, uri: block.uri } }));
294
+ }
291
295
  const src = mediaSrc(block);
292
296
  if (src && block.mimeType.startsWith('audio/')) {
293
297
  return _jsx(VoiceNote, { src: src, mimeType: block.mimeType });
294
298
  }
295
299
  return _jsx(Text, { color: "secondary", children: block.mimeType });
296
300
  }
301
+ /**
302
+ * A reference a tool sent, as the app's resolver shows it: a picture or video in a gallery of its
303
+ * own, a clip to play; the named file while it resolves, or when nothing does.
304
+ */
305
+ export function ReferencedMedia({ reference }) {
306
+ const t = useLabels();
307
+ const src = useResolvedMedia(reference);
308
+ if (src && reference.mimeType.startsWith('audio/')) {
309
+ return _jsx(VoiceNote, { src: src, mimeType: reference.mimeType });
310
+ }
311
+ const media = src ? lightboxMedia(t, src, reference.mimeType) : undefined;
312
+ if (media)
313
+ return _jsx(MediaGallery, { items: [{ media }] });
314
+ return _jsx(MediaFileToken, { reference: reference });
315
+ }
297
316
  /**
298
317
  * Runs of images/videos become one gallery row; consecutive citation blocks
299
318
  * become one sources row; everything else is a row of its own.
300
319
  */
301
- function bodyRows(t, body) {
320
+ function bodyRows(t, body, shown) {
302
321
  const rows = [];
303
322
  for (const block of body) {
323
+ if (block.kind === 'media' && !toolMediaShows(block, shown))
324
+ continue;
304
325
  const item = galleryItemOf(t, block);
305
326
  if (item)
306
327
  addToGallery(rows, item);
@@ -594,7 +615,8 @@ function AssistantTurn(props) {
594
615
  const { trace, gatedTools, body, hasTrace } = composeAssistantTurn(props.blocks, props.bodyKindPlacement !== undefined
595
616
  ? { bodyKindPlacement: props.bodyKindPlacement }
596
617
  : undefined);
597
- const rows = bodyRows(t, body);
618
+ const { shown } = useToolMedia();
619
+ const rows = bodyRows(t, body, shown);
598
620
  const status = workStatusLabel(t, workStatus({ streaming: props.streaming, hasTrace, elapsedMs }));
599
621
  const copyText = assistantTurnCopyText(body.length > 0 ? body : props.blocks);
600
622
  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
@@ -5,6 +5,7 @@ import { type ConversationView, type HttpTransportOptions, type TheoremTransport
5
5
  import { type ReactNode, type Ref } from 'react';
6
6
  import { type SendTextOptions, type SentTurn, type UseTheoremChatOptions } from '../hooks/use-theorem-chat.ts';
7
7
  import type { TheoremLabels } from './labels.ts';
8
+ import type { ResolveMedia, ToolMediaShown } from './tool-media.tsx';
8
9
  export type TheoremChatProps = {
9
10
  /** Where `createTheoremHandler` is mounted. Default `/api/theorem`. Ignored when `transport` is set. */
10
11
  endpoint?: string;
@@ -27,6 +28,19 @@ export type TheoremChatProps = {
27
28
  * A fence with a language is never changed. Off by default.
28
29
  */
29
30
  detectCodeLanguage?: boolean;
31
+ /**
32
+ * The media a tool returned that the transcript shows: `sent` (default), only what the tool sent
33
+ * to the person; `all`, every piece the model read as well, for an evaluation view. Media a model
34
+ * generated and files a person attached always show. Hiding is not withholding: the page still
35
+ * receives every piece.
36
+ */
37
+ media?: ToolMediaShown;
38
+ /**
39
+ * Turns a reference a tool sent (`{ type, mimeType, uri }`) into an address the page may load,
40
+ * under the viewer's own sign-in, or `null`. Without it, or on `null`, the reference shows as a
41
+ * named file. The model never reads a reference.
42
+ */
43
+ resolveMedia?: ResolveMedia;
30
44
  /**
31
45
  * The value chosen for each of the profile's `inputs.options`, sent with every turn. An option you
32
46
  * name is fixed to that value; one you leave out gets a selector in the composer bar, beside
@@ -140,4 +154,4 @@ export declare const DEFAULT_CHAT_MAX_WIDTH = "max(50%, min(100%, 640px))";
140
154
  * <TheoremChat endpoint="/api/theorem" />
141
155
  * ```
142
156
  */
143
- export declare function TheoremChat({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, ...rest }: TheoremChatProps): import("react").JSX.Element;
157
+ export declare function TheoremChat({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, media, resolveMedia, ...rest }: TheoremChatProps): import("react").JSX.Element;
package/ui/TheoremChat.js CHANGED
@@ -14,12 +14,11 @@ import { useTheoremInterface } from "../hooks/use-theorem-interface.js";
14
14
  import { ChatComposerBar } from "./ChatComposerBar.js";
15
15
  import { ChatTranscript } from "./ChatTranscript.js";
16
16
  import { useGlide } from "./glide.js";
17
- import { TheoremLabelsProvider, useLabels } from "./labels-provider.js";
18
- import { MarkdownPluginsProvider } from "./markdown-plugins.js";
17
+ import { useLabels } from "./labels-provider.js";
19
18
  import { PaneFailure, PaneLoading } from "./PaneState.js";
20
19
  import { SidePanelHeader } from "./SidePanel.js";
20
+ import { SurfaceProviders } from "./surface-providers.js";
21
21
  import { useTraceInspector, WithTrace } from "./TraceInspectorPanel.js";
22
- import { TheoremThemeProvider } from "./theme.js";
23
22
  /**
24
23
  * 50% of the chat's width, but never narrower than 640px (or the full width,
25
24
  * whichever is smaller) — so phones and narrow panes get 100%.
@@ -135,9 +134,9 @@ function ChatForTransport(props) {
135
134
  * <TheoremChat endpoint="/api/theorem" />
136
135
  * ```
137
136
  */
138
- export function TheoremChat({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, ...rest }) {
137
+ export function TheoremChat({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, media, resolveMedia, ...rest }) {
139
138
  const httpRef = useRef(http);
140
139
  httpRef.current = http;
141
140
  const resolved = useMemo(() => transport ?? createHttpTransport({ ...httpRef.current, endpoint }), [transport, endpoint]);
142
- return (_jsx(TheoremThemeProvider, { theme: theme, mode: mode, children: _jsx(TheoremLabelsProvider, { labels: labels, children: _jsx(MarkdownPluginsProvider, { detectCodeLanguage: detectCodeLanguage, children: _jsx(ChatForTransport, { ...rest, transport: resolved }) }) }) }));
141
+ return (_jsx(SurfaceProviders, { theme: theme, mode: mode, labels: labels, detectCodeLanguage: detectCodeLanguage, media: media, resolveMedia: resolveMedia, children: _jsx(ChatForTransport, { ...rest, transport: resolved }) }));
143
142
  }
@@ -3,6 +3,7 @@ import type { HttpOptions, PageTools } from '@theoremjs/web/client';
3
3
  import { type HostTransport } from '@theoremjs/web/client';
4
4
  import { type CSSProperties } from 'react';
5
5
  import { type TheoremLabels } from './labels.ts';
6
+ import type { ResolveMedia } from './tool-media.tsx';
6
7
  export type TheoremHostProps = {
7
8
  /** Where `createTheoremHostHandler` is mounted. Default `/api/host`. Ignored when `transport` is set. */
8
9
  endpoint?: string;
@@ -22,6 +23,12 @@ export type TheoremHostProps = {
22
23
  * A fence with a language is never changed. Off by default.
23
24
  */
24
25
  detectCodeLanguage?: boolean;
26
+ /**
27
+ * Turns a reference a tool returned (`{ type, mimeType, uri }`) into an address the page may
28
+ * load, under the viewer's own sign-in, or `null`. Without it, or on `null`, the reference shows
29
+ * as a named file.
30
+ */
31
+ resolveMedia?: ResolveMedia;
25
32
  /** Widest the column may grow, as a CSS length. Default `960px`. */
26
33
  maxWidth?: string;
27
34
  /**
@@ -51,4 +58,4 @@ export type TheoremHostProps = {
51
58
  * <TheoremHost endpoint="/api/host" />
52
59
  * ```
53
60
  */
54
- export declare function TheoremHost({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, ...rest }: TheoremHostProps): import("react").JSX.Element;
61
+ export declare function TheoremHost({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, resolveMedia, ...rest }: TheoremHostProps): import("react").JSX.Element;
package/ui/TheoremHost.js CHANGED
@@ -19,15 +19,14 @@ import { useTheoremHost } from "../hooks/use-theorem-host.js";
19
19
  import { Arrive, Stream } from "./arrive.js";
20
20
  import { ConsoleFrame, JsonRequest, RequestCard, ResponseColumn, RunBar, } from "./ConsoleFrame.js";
21
21
  import { liveDuration, workDuration } from "./labels.js";
22
- import { TheoremLabelsProvider, useLabels } from "./labels-provider.js";
23
- import { MarkdownPluginsProvider } from "./markdown-plugins.js";
22
+ import { useLabels } from "./labels-provider.js";
24
23
  import { IconMcp } from "./mcp-icon.js";
25
24
  import { PaneFailure, PaneLoading } from "./PaneState.js";
26
25
  import { SchemaFields } from "./SchemaFields.js";
26
+ import { SurfaceProviders } from "./surface-providers.js";
27
27
  import { ApprovalCard, AuthChallengeCard } from "./ToolGateCard.js";
28
28
  import { ToolResult } from "./ToolResult.js";
29
29
  import { useTraceInspector } from "./TraceInspectorPanel.js";
30
- import { TheoremThemeProvider } from "./theme.js";
31
30
  /** Calls listed under the console before older ones drop off the page. */
32
31
  const MAX_EARLIER = 8;
33
32
  const STATUS_DOT = {
@@ -232,9 +231,9 @@ function HostForTransport(props) {
232
231
  * <TheoremHost endpoint="/api/host" />
233
232
  * ```
234
233
  */
235
- export function TheoremHost({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, ...rest }) {
234
+ export function TheoremHost({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, resolveMedia, ...rest }) {
236
235
  const httpRef = useRef(http);
237
236
  httpRef.current = http;
238
237
  const resolved = useMemo(() => transport ?? createHostTransport({ ...httpRef.current, endpoint }), [transport, endpoint]);
239
- return (_jsx(TheoremThemeProvider, { theme: theme, mode: mode, children: _jsx(TheoremLabelsProvider, { labels: labels, children: _jsx(MarkdownPluginsProvider, { detectCodeLanguage: detectCodeLanguage, children: _jsx(HostForTransport, { ...rest, transport: resolved }) }) }) }));
238
+ return (_jsx(SurfaceProviders, { theme: theme, mode: mode, labels: labels, detectCodeLanguage: detectCodeLanguage, media: "all", resolveMedia: resolveMedia, children: _jsx(HostForTransport, { ...rest, transport: resolved }) }));
240
239
  }
package/ui/ToolResult.js CHANGED
@@ -5,10 +5,11 @@ import { useLocale } from '@astryxdesign/core/i18n';
5
5
  import { Lightbox } from '@astryxdesign/core/Lightbox';
6
6
  import { Skeleton } from '@astryxdesign/core/Skeleton';
7
7
  import { VStack } from '@astryxdesign/core/VStack';
8
- import { hasLead, layoutResult, returnedMedia, withUnit, } from '@theoremjs/web/client';
8
+ import { hasLead, layoutResult, referencesIn, returnedMedia, withUnit, } from '@theoremjs/web/client';
9
9
  import { lazy, Suspense, useMemo, useState } from 'react';
10
10
  import { Arrive } from "./arrive.js";
11
11
  import { CardWall } from "./CardWall.js";
12
+ import { ReferencedMedia } from "./ChatTranscript.js";
12
13
  import { useLabels } from "./labels-provider.js";
13
14
  import { keyedByContent } from "./row-keys.js";
14
15
  import { ShapedData } from "./ShapedData.js";
@@ -27,15 +28,16 @@ function ResultLead({ layout, parts = [], }) {
27
28
  const t = useLabels();
28
29
  const locale = useLocale();
29
30
  const decimal = useMemo(() => new Intl.NumberFormat(locale, { maximumFractionDigits: 2 }), [locale]);
30
- const media = useMemo(() => returnedMedia(layout, parts, t('@theorem.host.image')), [layout, parts, t]);
31
+ const media = useMemo(() => returnedMedia(parts, t('@theorem.host.image')), [parts, t]);
32
+ const references = useMemo(() => referencesIn(parts), [parts]);
31
33
  const [open, setOpen] = useState(null);
32
- if (!hasLead(layout, media))
34
+ if (!hasLead(layout, media) && references.length === 0)
33
35
  return null;
34
36
  const { images, audio } = media;
35
37
  return (_jsxs(VStack, { gap: 3, children: [_jsxs(CardWall, { minWidth: CARD_PX, children: [layout.figures.map((figure) => (_jsx(Arrive, { children: _jsx(ChartCard, { title: figure.label, value: withUnit(decimal.format(figure.value), figure.unit) }) }, `figure:${figure.key}`))), layout.charts.map((chart) => (_jsx(Suspense, { fallback: _jsx(Arrive, { children: _jsx(Skeleton, { height: CHART_CARD_PX }) }), children: _jsx(Arrive, { children: _jsx(ToolResultChart, { chart: chart }) }) }, `chart:${chart.key}`))), images.map((image, index) => (_jsx(Arrive, { children: _jsx(ClickableCard, { label: image.alt || 'Open image', padding: 0, onClick: () => setOpen(index), children: _jsx(AspectRatio, { ratio: 4 / 3, fit: "cover", children: _jsx("img", { src: image.src, alt: image.alt, loading: "lazy" }) }) }) }, `image:${image.src}`)))] }), images.length > 0 ? (_jsx(Lightbox, { isOpen: open !== null, onOpenChange: (isOpen) => {
36
38
  if (!isOpen)
37
39
  setOpen(null);
38
- }, media: images.map((image) => ({ src: image.src, alt: image.alt })), index: open ?? 0, onIndexChange: setOpen })) : null, keyedByContent(audio, (clip) => clip.src).map(({ item: clip, key }) => (_jsx(Arrive, { children: _jsx(VoiceNote, { src: clip.src, mimeType: clip.mimeType }) }, key)))] }));
40
+ }, media: images.map((image) => ({ src: image.src, alt: image.alt })), index: open ?? 0, onIndexChange: setOpen })) : null, keyedByContent(audio, (clip) => clip.src).map(({ item: clip, key }) => (_jsx(Arrive, { children: _jsx(VoiceNote, { src: clip.src, mimeType: clip.mimeType }) }, key))), references.map((reference) => (_jsx(Arrive, { children: _jsx(ReferencedMedia, { reference: reference }) }, `reference:${reference.uri}`)))] }));
39
41
  }
40
42
  /**
41
43
  * A tool's output under one Response heading, led by what answers it (figures,
package/ui/index.d.ts CHANGED
@@ -37,4 +37,5 @@ export { ToolResult } from './ToolResult.tsx';
37
37
  export { TraceGuardrailsView, TracePlacement, useTraceInspector } from './TraceInspectorPanel.tsx';
38
38
  export { ChartStat } from './TraceOverview.tsx';
39
39
  export { TheoremThemeProvider, type TheoremThemeProviderProps } from './theme.tsx';
40
+ export { type MediaReference, type ResolveMedia, ToolMediaProvider, type ToolMediaShown, } from './tool-media.tsx';
40
41
  export { ChartCard, type TraceFill } from './trace-patterns.tsx';
package/ui/index.js CHANGED
@@ -40,4 +40,5 @@ export { ToolResult } from "./ToolResult.js";
40
40
  export { TraceGuardrailsView, TracePlacement, useTraceInspector } from "./TraceInspectorPanel.js";
41
41
  export { ChartStat } from "./TraceOverview.js";
42
42
  export { TheoremThemeProvider } from "./theme.js";
43
+ export { ToolMediaProvider, } from "./tool-media.js";
43
44
  export { ChartCard } from "./trace-patterns.js";
@@ -0,0 +1,14 @@
1
+ import type { DefinedTheme } from '@astryxdesign/core/theme';
2
+ import type { ReactNode } from 'react';
3
+ import type { TheoremLabels } from './labels.ts';
4
+ import { type ResolveMedia, type ToolMediaShown } from './tool-media.tsx';
5
+ /** The theme, labels, Markdown plugins, and tool media a chat or a host page draws with. */
6
+ export declare function SurfaceProviders({ theme, mode, labels, detectCodeLanguage, media, resolveMedia, children, }: {
7
+ theme: DefinedTheme | undefined;
8
+ mode: 'system' | 'light' | 'dark' | undefined;
9
+ labels: TheoremLabels | undefined;
10
+ detectCodeLanguage: boolean | undefined;
11
+ media: ToolMediaShown | undefined;
12
+ resolveMedia: ResolveMedia | undefined;
13
+ children: ReactNode;
14
+ }): import("react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { TheoremLabelsProvider } from "./labels-provider.js";
3
+ import { MarkdownPluginsProvider } from "./markdown-plugins.js";
4
+ import { TheoremThemeProvider } from "./theme.js";
5
+ import { ToolMediaProvider } from "./tool-media.js";
6
+ /** The theme, labels, Markdown plugins, and tool media a chat or a host page draws with. */
7
+ export function SurfaceProviders({ theme, mode, labels, detectCodeLanguage, media, resolveMedia, children, }) {
8
+ return (_jsx(TheoremThemeProvider, { theme: theme, mode: mode, children: _jsx(TheoremLabelsProvider, { labels: labels, children: _jsx(MarkdownPluginsProvider, { detectCodeLanguage: detectCodeLanguage, children: _jsx(ToolMediaProvider, { media: media, resolveMedia: resolveMedia, children: children }) }) }) }));
9
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The media a tool returned that the chat shows: `sent`, what the tool sent to the person (a
3
+ * consumer chat); `all`, every piece the model read as well (an evaluation view). Media a model
4
+ * generated and files a person attached always show.
5
+ */
6
+ export type ToolMediaShown = 'sent' | 'all';
7
+ /** Whether a tool's piece of media shows under `shown`: under `sent`, only what the tool sent. */
8
+ export declare function toolMediaShows(block: {
9
+ fromTool?: true;
10
+ sent?: true;
11
+ }, shown: ToolMediaShown): boolean;
12
+ /** The last segment of a reference, the name it reads as; the whole reference when it has none. */
13
+ export declare function mediaFileName(uri: string): string;
@@ -0,0 +1,15 @@
1
+ /** Whether a tool's piece of media shows under `shown`: under `sent`, only what the tool sent. */
2
+ export function toolMediaShows(block, shown) {
3
+ return shown === 'all' || !block.fromTool || block.sent === true;
4
+ }
5
+ /** The last segment of a reference, the name it reads as; the whole reference when it has none. */
6
+ export function mediaFileName(uri) {
7
+ const path = uri.split(/[?#]/)[0] ?? uri;
8
+ const last = path.split('/').filter(Boolean).at(-1);
9
+ try {
10
+ return last ? decodeURIComponent(last) : uri;
11
+ }
12
+ catch {
13
+ return last ?? uri;
14
+ }
15
+ }
@@ -0,0 +1,31 @@
1
+ import type { InteractionMediaRefPart } from '@theoremjs/agents';
2
+ import { type ReactNode } from 'react';
3
+ import { type ToolMediaShown } from './tool-media-shown.ts';
4
+ export { type ToolMediaShown, toolMediaShows } from './tool-media-shown.ts';
5
+ /** A reference a tool returned: the person is shown it, the model never read it. */
6
+ export type MediaReference = InteractionMediaRefPart;
7
+ /**
8
+ * Turns a tool's reference into an address the page may load, under the viewer's own sign-in, or
9
+ * `null` when there is none. Without it, a reference shows as a named file.
10
+ */
11
+ export type ResolveMedia = (reference: MediaReference) => string | null | Promise<string | null>;
12
+ /** What a page shows of tool media, and how it loads a reference. */
13
+ export type ToolMediaView = {
14
+ shown: ToolMediaShown;
15
+ resolve?: ResolveMedia;
16
+ };
17
+ export declare function ToolMediaProvider({ media, resolveMedia, children, }: {
18
+ media?: ToolMediaShown;
19
+ resolveMedia?: ResolveMedia;
20
+ children: ReactNode;
21
+ }): import("react").JSX.Element;
22
+ export declare function useToolMedia(): ToolMediaView;
23
+ /**
24
+ * What the resolver makes of `reference`: `undefined` while it works, `null` when it gives no
25
+ * address (or there is no resolver, or it throws).
26
+ */
27
+ export declare function useResolvedMedia(reference: MediaReference | undefined): string | null | undefined;
28
+ /** A reference shown as the file it names, when nothing resolves it to show. */
29
+ export declare function MediaFileToken({ reference }: {
30
+ reference: MediaReference;
31
+ }): import("react").JSX.Element;
@@ -0,0 +1,45 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Token } from '@astryxdesign/core/Token';
3
+ import { createContext, use, useEffect, useState } from 'react';
4
+ import { mediaFileName } from "./tool-media-shown.js";
5
+ export { toolMediaShows } from "./tool-media-shown.js";
6
+ const ToolMediaContext = createContext({ shown: 'sent' });
7
+ export function ToolMediaProvider({ media = 'sent', resolveMedia, children, }) {
8
+ return (_jsx(ToolMediaContext, { value: { shown: media, ...(resolveMedia ? { resolve: resolveMedia } : {}) }, children: children }));
9
+ }
10
+ export function useToolMedia() {
11
+ return use(ToolMediaContext);
12
+ }
13
+ /**
14
+ * What the resolver makes of `reference`: `undefined` while it works, `null` when it gives no
15
+ * address (or there is no resolver, or it throws).
16
+ */
17
+ export function useResolvedMedia(reference) {
18
+ const { resolve } = useToolMedia();
19
+ const type = reference?.type;
20
+ const mimeType = reference?.mimeType;
21
+ const uri = reference?.uri;
22
+ const [resolved, setResolved] = useState();
23
+ useEffect(() => {
24
+ if (type === undefined || mimeType === undefined || uri === undefined)
25
+ return;
26
+ if (!resolve) {
27
+ setResolved({ uri, src: null });
28
+ return;
29
+ }
30
+ let current = true;
31
+ Promise.resolve()
32
+ .then(() => resolve({ type, mimeType, uri }))
33
+ .then((src) => current && setResolved({ uri, src: src ?? null }), () => current && setResolved({ uri, src: null }));
34
+ return () => {
35
+ current = false;
36
+ };
37
+ }, [resolve, type, mimeType, uri]);
38
+ if (uri === undefined)
39
+ return null;
40
+ return resolved?.uri === uri ? resolved.src : undefined;
41
+ }
42
+ /** A reference shown as the file it names, when nothing resolves it to show. */
43
+ export function MediaFileToken({ reference }) {
44
+ return _jsx(Token, { label: mediaFileName(reference.uri), description: reference.mimeType });
45
+ }
@@ -24,7 +24,7 @@ export function transcriptBlockCopyText(t, block) {
24
24
  case 'structured':
25
25
  return JSON.stringify(block.value, null, 2);
26
26
  case 'media':
27
- return block.url ?? t('@theorem.transcript.copy_text.media', { mimeType: block.mimeType });
27
+ return t('@theorem.transcript.copy_text.media', { mimeType: block.mimeType });
28
28
  case 'grounding':
29
29
  return JSON.stringify(block.grounding, null, 2);
30
30
  case 'citation':