@theoremjs/react 0.3.5-next.988.gb2d8ffd → 0.3.5-next.991.gbf33030

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
@@ -180,6 +180,7 @@ To draw your own figures like the trace panel does, `@theoremjs/react/ui` also e
180
180
  | `composerIcons` | The glyphs the `'row'` composer draws: `working`, before the working pill's text; `backgroundJob`, before each background call's name; `stop`, in the working pill's stop button. Each one you leave out keeps Theorem's. See [The row composer's look](#the-row-composers-look). |
181
181
  | `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). |
182
182
  | `resolveMedia` | Turns a tool's reference into an address the page can load. See [Tool media](#tool-media). |
183
+ | `mediaViewer` | The viewer every picture and video opens in. Default: Astryx's Lightbox, with zoom. See [Your own media viewer](#your-own-media-viewer). |
183
184
 
184
185
  ### The row composer's look
185
186
 
@@ -241,6 +242,28 @@ A tool can also return a **reference**: `{ type, mimeType, uri }`, such as a `gs
241
242
 
242
243
  `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.
243
244
 
245
+ A file the person sent works the same way after your app saves it. When you load a saved conversation, give the person's file as a `user-attachment` or `user-voice` block with `uri` and `type` in place of `data`, and your own values for the file in `metadata` if you need them. The chat shows it on the person's side through `resolveMedia`: a picture, a voice note to play, or the file name.
246
+
247
+ ### Your own media viewer
248
+
249
+ A picture or a video opens in a viewer when the person clicks it: in the transcript, in a tool's result, in a decision's answer, and in a form field. Pass `mediaViewer` to open them all in your own:
250
+
251
+ ```tsx
252
+ import type { MediaViewerProps } from '@theoremjs/react/ui';
253
+
254
+ function MyViewer({ isOpen, onOpenChange, media, index }: MediaViewerProps) {
255
+ const item = media[index]; // { type, src, alt, caption?, reference? }
256
+ if (!isOpen || !item) return null;
257
+ return <MyDialog item={item} onClose={() => onOpenChange(false)} />;
258
+ }
259
+
260
+ <TheoremChat endpoint="/api/theorem" profile="assistant" mediaViewer={MyViewer} />;
261
+ ```
262
+
263
+ Declare the viewer once, outside your components, as the example does. A function made again on each render is a new component each time, so the open viewer starts over and loses what it holds.
264
+
265
+ The viewer is given the items, the one shown, and whether it is open. Call `onOpenChange(false)` to close it and `onIndexChange` to show another. An item's `src` is the address the page loads. When the app saved the file, the item also has `reference`, the `{ type, mimeType, uri }` that `resolveMedia` was given, since `src` can be a link that expires. `TheoremHost`, `LiveRunner`, and `TheoremSurface` take the same `mediaViewer`. Without it, they open Astryx's Lightbox, with zoom, as `AstryxMediaViewer` does. To open the page's viewer from your own component inside the surface, call `useMediaViewer(items)` and render its `element`.
266
+
244
267
  ### Resume a conversation
245
268
 
246
269
  The server keeps the conversation in its `conversationStore`. The browser never sends the history. It holds only a ref that the store issued.
@@ -425,7 +448,7 @@ const call = useLiveCall({ iface, connection: () => ({ profile: 'support.voice'
425
448
 
426
449
  This code opens `wss://<your host>/api/live/relay?profile=<id>`. To send your own message to the relay, add `openMessage`. To use your own socket, add `createSocket`.
427
450
 
428
- `LiveRunner` also accepts `theme`, `mode`, `labels`, `media`, `resolveMedia`, and `trace`. Its captions show the media a tool returns as the chat does: see [Tool media](#tool-media). Tool gates in a call appear in a dialog over the call.
451
+ `LiveRunner` also accepts `theme`, `mode`, `labels`, `media`, `resolveMedia`, `mediaViewer`, and `trace`. Its captions show the media a tool returns as the chat does: see [Tool media](#tool-media). Tool gates in a call appear in a dialog over the call.
429
452
 
430
453
  ### A call across pages
431
454
 
@@ -567,7 +590,7 @@ function Dock({ chat, iface }) {
567
590
  }
568
591
  ```
569
592
 
570
- `TheoremChatComposer` takes `layout`, `icons`, `placeholder`, and `inputRef`. `TheoremChatTranscript` takes the props of `ChatTranscript` that the chat does not give: `handle`, `emptyState`, `dividers`, `usage`, and `bodyKindPlacement`. Its `handle` is the handle of the profile when you leave it out. Put both pieces inside one `TheoremSurface`. It takes what `TheoremChat` takes for the look and the media: `theme`, `mode`, `labels`, `detectCodeLanguage`, `media`, and `resolveMedia`.
593
+ `TheoremChatComposer` takes `layout`, `icons`, `placeholder`, and `inputRef`. `TheoremChatTranscript` takes the props of `ChatTranscript` that the chat does not give: `handle`, `emptyState`, `dividers`, `usage`, and `bodyKindPlacement`. Its `handle` is the handle of the profile when you leave it out. Put both pieces inside one `TheoremSurface`. It takes what `TheoremChat` takes for the look and the media: `theme`, `mode`, `labels`, `detectCodeLanguage`, `media`, `resolveMedia`, and `mediaViewer`.
571
594
 
572
595
  The two pieces read one clock: `chat.turnClock`. So the working pill of the composer and the status line of the transcript show the same time. `chat.workingSince` is when the reply in progress started, less its waits for approval. `chat.shownBlocks` is what the transcript shows: `chat.blocks`, then `chat.streamBlocks`.
573
596
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/react",
3
- "version": "0.3.5-next.988.gb2d8ffd",
3
+ "version": "0.3.5-next.991.gbf33030",
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.988.gb2d8ffd",
64
- "@theoremjs/web": "^0.3.5-next.988.gb2d8ffd"
63
+ "@theoremjs/agents": "^0.3.5-next.991.gbf33030",
64
+ "@theoremjs/web": "^0.3.5-next.991.gbf33030"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@astryxdesign/core": {
@@ -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';
@@ -30,6 +29,7 @@ import { useDisclosureMotion } from "./disclosure-motion.js";
30
29
  import { usageLine, workDuration, workStatusLabel } from "./labels.js";
31
30
  import { TheoremLabelsProvider, useLabels } from "./labels-provider.js";
32
31
  import { useMarkdownPlugins } from "./markdown-plugins.js";
32
+ import { useMediaViewer } from "./media-viewer.js";
33
33
  import { keyedByContent } from "./row-keys.js";
34
34
  import { ShapedData } from "./ShapedData.js";
35
35
  import { ApprovalCard, AuthChallengeCard } from "./ToolGateCard.js";
@@ -186,9 +186,11 @@ function turnNotice(error, stopped) {
186
186
  function dataUrl(mimeType, data) {
187
187
  return data === undefined ? undefined : `data:${mimeType};base64,${data}`;
188
188
  }
189
- function ImageAttachment({ src, name }) {
190
- const lightbox = useLightbox({ media: { src, alt: name, caption: name }, hasZoom: true });
191
- return (_jsxs(_Fragment, { children: [_jsx(Thumbnail, { src: src, alt: name, label: name, onClick: () => lightbox.open() }), lightbox.element] }));
189
+ function ImageAttachment({ src, name, reference, }) {
190
+ const viewer = useMediaViewer([
191
+ { type: 'image', src, alt: name, caption: name, ...(reference ? { reference } : {}) },
192
+ ]);
193
+ return (_jsxs(_Fragment, { children: [_jsx(Thumbnail, { src: src, alt: name, label: name, onClick: () => viewer.open() }), viewer.element] }));
192
194
  }
193
195
  function UserBlock({ block, metadata }) {
194
196
  if (block.kind === 'user-text')
@@ -199,9 +201,24 @@ function UserBlock({ block, metadata }) {
199
201
  }
200
202
  /** An attached image or voice note inline; any other file as a Token. */
201
203
  function UserFile({ block }) {
202
- const src = dataUrl(block.mimeType, block.data);
204
+ if (block.uri !== undefined)
205
+ return _jsx(SavedUserFile, { block: block, uri: block.uri });
206
+ return _jsx(UserFileView, { block: block, src: dataUrl(block.mimeType, block.data) });
207
+ }
208
+ /** A file the app saved, as its resolver shows it; the named file while it resolves, or when nothing does. */
209
+ function SavedUserFile({ block, uri }) {
210
+ const reference = {
211
+ type: block.type ?? (block.kind === 'user-voice' ? 'audio' : 'document'),
212
+ mimeType: block.mimeType,
213
+ uri,
214
+ ...(block.metadata ? { metadata: block.metadata } : {}),
215
+ };
216
+ const src = useResolvedMedia(reference);
217
+ return _jsx(UserFileView, { block: block, src: src ?? undefined, reference: reference });
218
+ }
219
+ function UserFileView({ block, src, reference, }) {
203
220
  if (src && block.mimeType.startsWith('image/')) {
204
- return _jsx(ImageAttachment, { src: src, name: block.name });
221
+ return _jsx(ImageAttachment, { src: src, name: block.name, ...(reference ? { reference } : {}) });
205
222
  }
206
223
  if (src && block.mimeType.startsWith('audio/')) {
207
224
  return _jsx(VoiceNote, { src: src, mimeType: block.mimeType });
@@ -211,7 +228,7 @@ function UserFile({ block }) {
211
228
  function mediaSrc(block) {
212
229
  return dataUrl(block.mimeType, block.data);
213
230
  }
214
- function lightboxMedia(t, src, mimeType) {
231
+ function viewerItem(t, src, mimeType) {
215
232
  if (mimeType.startsWith('image/'))
216
233
  return { src, alt: t('@theorem.transcript.generated_image'), type: 'image' };
217
234
  if (mimeType.startsWith('video/'))
@@ -223,15 +240,15 @@ function galleryItemOf(t, block) {
223
240
  if (block.kind !== 'media')
224
241
  return undefined;
225
242
  const src = mediaSrc(block);
226
- const media = src ? lightboxMedia(t, src, block.mimeType) : undefined;
243
+ const media = src ? viewerItem(t, src, block.mimeType) : undefined;
227
244
  return media ? { media } : undefined;
228
245
  }
229
246
  /**
230
247
  * Consecutive images and videos as one wrapping row of Astryx Thumbnails that
231
- * share a Lightbox gallery (Astryx's `useLightbox({ media: [...] })` pattern).
248
+ * share one viewer, so its arrows walk them all.
232
249
  */
233
250
  function MediaGallery({ items }) {
234
- const lightbox = useLightbox({ media: items.map((item) => item.media), hasZoom: true });
251
+ const lightbox = useMediaViewer(items.map((item) => item.media));
235
252
  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] }));
236
253
  }
237
254
  /** One generated image, framed to its natural ratio once loaded (the pinned ratio until then). */
@@ -249,7 +266,7 @@ function GeneratedImage(props) {
249
266
  * own ratio. Anything else (video) keeps the square Thumbnail.
250
267
  */
251
268
  function GeneratedGallery({ items, ratio }) {
252
- const lightbox = useLightbox({ media: items.map((item) => item.media), hasZoom: true });
269
+ const lightbox = useMediaViewer(items.map((item) => item.media));
253
270
  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] }));
254
271
  }
255
272
  /** An image takes seconds: a slow, smooth breath rather than the Skeleton's quick stepped blink. */
@@ -287,9 +304,9 @@ export function ReferencedMedia({ reference }) {
287
304
  if (src && reference.mimeType.startsWith('audio/')) {
288
305
  return _jsx(VoiceNote, { src: src, mimeType: reference.mimeType });
289
306
  }
290
- const media = src ? lightboxMedia(t, src, reference.mimeType) : undefined;
307
+ const media = src ? viewerItem(t, src, reference.mimeType) : undefined;
291
308
  if (media)
292
- return _jsx(MediaGallery, { items: [{ media }] });
309
+ return _jsx(MediaGallery, { items: [{ media: { ...media, reference } }] });
293
310
  return _jsx(MediaFileToken, { reference: reference });
294
311
  }
295
312
  /**
@@ -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, }) {
@@ -2,8 +2,8 @@ import type { DefinedTheme } from '@astryxdesign/core/theme';
2
2
  import type { LiveCall } from '../components/live/use-live-call.js';
3
3
  import { type TheoremLabels } from './labels.js';
4
4
  import { type TheoremChatProps } from './TheoremChat.js';
5
- /** `media` and `resolveMedia` are the chat's: the captions show a tool's media as the chat does. */
6
- export type LiveRunnerProps = Pick<TheoremChatProps, 'media' | 'resolveMedia'> & {
5
+ /** `media`, `resolveMedia` and `mediaViewer` are the chat's: the captions show a tool's media as the chat does. */
6
+ export type LiveRunnerProps = Pick<TheoremChatProps, 'media' | 'resolveMedia' | 'mediaViewer'> & {
7
7
  /** The call to draw, from `useLiveCall`. The call outlives the runner: it ends when its owner unmounts. */
8
8
  call: LiveCall;
9
9
  /** Astryx theme, as on `TheoremChat`. Omit to inherit the host's `<Theme>` or use `theoremTheme`. */
@@ -32,4 +32,4 @@ export type LiveRunnerProps = Pick<TheoremChatProps, 'media' | 'resolveMedia'> &
32
32
  * in a toolbar, and tool gates in a dialog. Offers the trace inspector when
33
33
  * the profile records traces.
34
34
  */
35
- export declare function LiveRunner({ theme, mode, labels, media, resolveMedia, ...props }: LiveRunnerProps): import("react").JSX.Element;
35
+ export declare function LiveRunner({ theme, mode, labels, media, resolveMedia, mediaViewer, ...props }: LiveRunnerProps): import("react").JSX.Element;
package/ui/LiveRunner.js CHANGED
@@ -33,8 +33,8 @@ const WAVE_HEIGHT = 320;
33
33
  * in a toolbar, and tool gates in a dialog. Offers the trace inspector when
34
34
  * the profile records traces.
35
35
  */
36
- export function LiveRunner({ theme, mode, labels, media, resolveMedia, ...props }) {
37
- return (_jsx(TheoremSurface, { theme: theme, mode: mode, labels: labels, detectCodeLanguage: undefined, media: media, resolveMedia: resolveMedia, children: _jsx(LiveRunnerBody, { ...props }) }));
36
+ export function LiveRunner({ theme, mode, labels, media, resolveMedia, mediaViewer, ...props }) {
37
+ return (_jsx(TheoremSurface, { theme: theme, mode: mode, labels: labels, detectCodeLanguage: undefined, media: media, resolveMedia: resolveMedia, mediaViewer: mediaViewer, children: _jsx(LiveRunnerBody, { ...props }) }));
38
38
  }
39
39
  function LiveRunnerBody({ call, trace, onMinimize, }) {
40
40
  const t = useLabels();
package/ui/ShapedData.js CHANGED
@@ -4,7 +4,6 @@ import { Collapsible, CollapsibleGroup } from '@astryxdesign/core/Collapsible';
4
4
  import { HStack } from '@astryxdesign/core/HStack';
5
5
  import { Icon } from '@astryxdesign/core/Icon';
6
6
  import { useLocale } from '@astryxdesign/core/i18n';
7
- import { useLightbox } from '@astryxdesign/core/Lightbox';
8
7
  import { Link } from '@astryxdesign/core/Link';
9
8
  import { List, ListItem } from '@astryxdesign/core/List';
10
9
  import { Markdown } from '@astryxdesign/core/Markdown';
@@ -21,6 +20,7 @@ import { Component, useMemo, useState } from 'react';
21
20
  import { Arrive, useArrive } from "./arrive.js";
22
21
  import { useLabels } from "./labels-provider.js";
23
22
  import { useMarkdownPlugins } from "./markdown-plugins.js";
23
+ import { useMediaViewer } from "./media-viewer.js";
24
24
  import { keyedByContent } from "./row-keys.js";
25
25
  import { VoiceNote } from "./VoiceNote.js";
26
26
  /** Each way a plain value reads, drawn. */
@@ -140,12 +140,12 @@ function partSrc(part) {
140
140
  function viewable(part) {
141
141
  return part.type === 'image' || part.type === 'video';
142
142
  }
143
- /** A list of parts in its own order; every image and video opens in one Lightbox, so the arrows walk them all. */
143
+ /** A list of parts in its own order; every image and video opens in one viewer, so the arrows walk them all. */
144
144
  function Parts({ parts }) {
145
145
  const t = useLabels();
146
146
  const shown = parts.slice(0, MAX_ROWS);
147
147
  const media = [];
148
- /** Each viewable part's place in the Lightbox, by its place in the list. */
148
+ /** Each viewable part's place in the viewer, by its place in the list. */
149
149
  const slides = new Map();
150
150
  shown.forEach((part, index) => {
151
151
  if (!viewable(part))
@@ -156,7 +156,7 @@ function Parts({ parts }) {
156
156
  });
157
157
  media.push({ src: partSrc(part), alt, type: part.type });
158
158
  });
159
- const lightbox = useLightbox({ media, hasZoom: true });
159
+ const lightbox = useMediaViewer(media);
160
160
  return (_jsxs(VStack, { gap: 2, children: [shown.map((part, index) => {
161
161
  const key = String(index);
162
162
  if (part.type === 'text')
package/ui/StateFields.js CHANGED
@@ -4,7 +4,6 @@ import { FieldLabel } from '@astryxdesign/core/Field';
4
4
  import { FileInput } from '@astryxdesign/core/FileInput';
5
5
  import { HStack } from '@astryxdesign/core/HStack';
6
6
  import { IconButton } from '@astryxdesign/core/IconButton';
7
- import { Lightbox } from '@astryxdesign/core/Lightbox';
8
7
  import { NumberInput } from '@astryxdesign/core/NumberInput';
9
8
  import { StackItem } from '@astryxdesign/core/Stack';
10
9
  import { Switch } from '@astryxdesign/core/Switch';
@@ -21,6 +20,7 @@ import { IMAGE_ACCEPT, imageSrc } from "../client/decision-images.js";
21
20
  import { blankLike, isWordList, tableColumns } from "../client/state-fields.js";
22
21
  import { useImageReader } from "./DecisionImages.js";
23
22
  import { useLabels } from "./labels-provider.js";
23
+ import { useMediaViewer } from "./media-viewer.js";
24
24
  import { useKeyedRows } from "./row-keys.js";
25
25
  const NO_SUGGESTIONS = { search: () => [], bootstrap: () => [] };
26
26
  /** Text this long, or on several lines, gets a text area. */
@@ -36,9 +36,9 @@ function ImageField({ value, label, isLabelHidden, }) {
36
36
  const t = useLabels();
37
37
  const { images, onImages } = useContext(StateImages);
38
38
  const { read, status } = useImageReader();
39
- const [isOpen, setOpen] = useState(false);
40
39
  const src = Object.hasOwn(images, value) ? imageSrc(images[value]) : undefined;
41
- return (_jsxs(HStack, { gap: 2, vAlign: "center", children: [_jsx(Thumbnail, { src: src, alt: label, label: value, onClick: src ? () => setOpen(true) : undefined }), src ? (_jsx(Lightbox, { isOpen: isOpen, onOpenChange: setOpen, media: { src, alt: label, caption: value }, hasZoom: true })) : null, _jsx(StackItem, { size: "fill", children: _jsx(FileInput, { label: label, isLabelHidden: isLabelHidden, accept: IMAGE_ACCEPT, value: null, placeholder: t('@theorem.decision.replace_image'), status: status, statusVariant: "detached", onChange: (files) => {
40
+ const viewer = useMediaViewer(src ? [{ type: 'image', src, alt: label, caption: value }] : []);
41
+ return (_jsxs(HStack, { gap: 2, vAlign: "center", children: [_jsx(Thumbnail, { src: src, alt: label, label: value, onClick: src ? () => viewer.open() : undefined }), viewer.element, _jsx(StackItem, { size: "fill", children: _jsx(FileInput, { label: label, isLabelHidden: isLabelHidden, accept: IMAGE_ACCEPT, value: null, placeholder: t('@theorem.decision.replace_image'), status: status, statusVariant: "detached", onChange: (files) => {
42
42
  void read(files).then(([first]) => {
43
43
  if (first)
44
44
  onImages({ ...images, [value]: first[1] });
@@ -9,6 +9,7 @@ import { type ComposerLayout } from './ChatComposerBar.js';
9
9
  import type { ComposerRowIcons } from './ChatComposerRow.js';
10
10
  import { type ChatTranscriptProps } from './ChatTranscript.js';
11
11
  import type { TheoremLabels } from './labels.js';
12
+ import type { MediaViewer } from './media-viewer.js';
12
13
  import type { ResolveMedia, ToolMediaShown } from './tool-media.js';
13
14
  export type TheoremChatProps = {
14
15
  /** Where `createTheoremHandler` is mounted. Default `/api/theorem`. Ignored when `transport` is set. */
@@ -45,6 +46,12 @@ export type TheoremChatProps = {
45
46
  * named file. The model never reads a reference.
46
47
  */
47
48
  resolveMedia?: ResolveMedia;
49
+ /**
50
+ * The viewer every picture and video opens in: the transcript's, a tool's, a decision's and a
51
+ * form field's. It is given the items, which one shows, and whether it is open; each item names
52
+ * the saved file it came from, when there is one. Default: Astryx's Lightbox, with zoom.
53
+ */
54
+ mediaViewer?: MediaViewer;
48
55
  /**
49
56
  * The value chosen for each of the profile's `inputs.options`, sent with every turn. An option you
50
57
  * name is fixed to that value; one you leave out gets a selector in the composer bar, beside
@@ -201,4 +208,4 @@ export declare function TheoremChatTranscript({ chat, iface, handle, ...props }:
201
208
  * <TheoremChat endpoint="/api/theorem" />
202
209
  * ```
203
210
  */
204
- export declare function TheoremChat({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, media, resolveMedia, ...rest }: TheoremChatProps): import("react").JSX.Element;
211
+ export declare function TheoremChat({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, media, resolveMedia, mediaViewer, ...rest }: TheoremChatProps): import("react").JSX.Element;
package/ui/TheoremChat.js CHANGED
@@ -155,9 +155,9 @@ function ChatForTransport(props) {
155
155
  * <TheoremChat endpoint="/api/theorem" />
156
156
  * ```
157
157
  */
158
- export function TheoremChat({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, media, resolveMedia, ...rest }) {
158
+ export function TheoremChat({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, media, resolveMedia, mediaViewer, ...rest }) {
159
159
  const httpRef = useRef(http);
160
160
  httpRef.current = http;
161
161
  const resolved = useMemo(() => transport ?? createHttpTransport({ ...httpRef.current, endpoint }), [transport, endpoint]);
162
- return (_jsx(TheoremSurface, { theme: theme, mode: mode, labels: labels, detectCodeLanguage: detectCodeLanguage, media: media, resolveMedia: resolveMedia, children: _jsx(ChatForTransport, { ...rest, transport: resolved }) }));
162
+ return (_jsx(TheoremSurface, { theme: theme, mode: mode, labels: labels, detectCodeLanguage: detectCodeLanguage, media: media, resolveMedia: resolveMedia, mediaViewer: mediaViewer, children: _jsx(ChatForTransport, { ...rest, transport: resolved }) }));
163
163
  }
@@ -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.js';
6
+ import type { MediaViewer } from './media-viewer.js';
6
7
  import type { ResolveMedia } from './tool-media.js';
7
8
  export type TheoremHostProps = {
8
9
  /** Where `createTheoremHostHandler` is mounted. Default `/api/host`. Ignored when `transport` is set. */
@@ -29,6 +30,12 @@ export type TheoremHostProps = {
29
30
  * as a named file.
30
31
  */
31
32
  resolveMedia?: ResolveMedia;
33
+ /**
34
+ * The viewer every picture and video opens in: the transcript's, a tool's, a decision's and a
35
+ * form field's. It is given the items, which one shows, and whether it is open; each item names
36
+ * the saved file it came from, when there is one. Default: Astryx's Lightbox, with zoom.
37
+ */
38
+ mediaViewer?: MediaViewer;
32
39
  /** Widest the column may grow, as a CSS length. Default `960px`. */
33
40
  maxWidth?: string;
34
41
  /**
@@ -58,4 +65,4 @@ export type TheoremHostProps = {
58
65
  * <TheoremHost endpoint="/api/host" />
59
66
  * ```
60
67
  */
61
- export declare function TheoremHost({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, resolveMedia, ...rest }: TheoremHostProps): import("react").JSX.Element;
68
+ export declare function TheoremHost({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, resolveMedia, mediaViewer, ...rest }: TheoremHostProps): import("react").JSX.Element;
package/ui/TheoremHost.js CHANGED
@@ -231,9 +231,9 @@ function HostForTransport(props) {
231
231
  * <TheoremHost endpoint="/api/host" />
232
232
  * ```
233
233
  */
234
- export function TheoremHost({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, resolveMedia, ...rest }) {
234
+ export function TheoremHost({ endpoint, http, transport, theme, mode, labels, detectCodeLanguage, resolveMedia, mediaViewer, ...rest }) {
235
235
  const httpRef = useRef(http);
236
236
  httpRef.current = http;
237
237
  const resolved = useMemo(() => transport ?? createHostTransport({ ...httpRef.current, endpoint }), [transport, endpoint]);
238
- return (_jsx(TheoremSurface, { theme: theme, mode: mode, labels: labels, detectCodeLanguage: detectCodeLanguage, media: "all", resolveMedia: resolveMedia, children: _jsx(HostForTransport, { ...rest, transport: resolved }) }));
238
+ return (_jsx(TheoremSurface, { theme: theme, mode: mode, labels: labels, detectCodeLanguage: detectCodeLanguage, media: "all", resolveMedia: resolveMedia, mediaViewer: mediaViewer, children: _jsx(HostForTransport, { ...rest, transport: resolved }) }));
239
239
  }
@@ -1,6 +1,7 @@
1
1
  import type { DefinedTheme } from '@astryxdesign/core/theme';
2
2
  import type { ReactNode } from 'react';
3
3
  import type { TheoremLabels } from './labels.js';
4
+ import type { MediaViewer } from './media-viewer.js';
4
5
  import { type ResolveMedia, type ToolMediaShown } from './tool-media.js';
5
6
  /** What `TheoremSurface` takes: each is the `TheoremChat` prop of the same name. */
6
7
  export type TheoremSurfaceProps = {
@@ -10,6 +11,7 @@ export type TheoremSurfaceProps = {
10
11
  detectCodeLanguage?: boolean;
11
12
  media?: ToolMediaShown;
12
13
  resolveMedia?: ResolveMedia;
14
+ mediaViewer?: MediaViewer;
13
15
  children: ReactNode;
14
16
  };
15
17
  /**
@@ -17,4 +19,4 @@ export type TheoremSurfaceProps = {
17
19
  * `TheoremChatComposer` and `TheoremChatTranscript` in it when you place them yourself; it takes
18
20
  * what `TheoremChat` takes for each.
19
21
  */
20
- export declare function TheoremSurface({ theme, mode, labels, detectCodeLanguage, media, resolveMedia, children, }: TheoremSurfaceProps): import("react").JSX.Element;
22
+ export declare function TheoremSurface({ theme, mode, labels, detectCodeLanguage, media, resolveMedia, mediaViewer, children, }: TheoremSurfaceProps): import("react").JSX.Element;
@@ -8,6 +8,6 @@ import { ToolMediaProvider } from "./tool-media.js";
8
8
  * `TheoremChatComposer` and `TheoremChatTranscript` in it when you place them yourself; it takes
9
9
  * what `TheoremChat` takes for each.
10
10
  */
11
- export function TheoremSurface({ theme, mode, labels, detectCodeLanguage, media, resolveMedia, children, }) {
12
- 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 }) }) }) }));
11
+ export function TheoremSurface({ theme, mode, labels, detectCodeLanguage, media, resolveMedia, mediaViewer, children, }) {
12
+ return (_jsx(TheoremThemeProvider, { theme: theme, mode: mode, children: _jsx(TheoremLabelsProvider, { labels: labels, children: _jsx(MarkdownPluginsProvider, { detectCodeLanguage: detectCodeLanguage, children: _jsx(ToolMediaProvider, { media: media, resolveMedia: resolveMedia, mediaViewer: mediaViewer, children: children }) }) }) }));
13
13
  }
package/ui/ToolResult.js CHANGED
@@ -2,7 +2,6 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { AspectRatio } from '@astryxdesign/core/AspectRatio';
3
3
  import { ClickableCard } from '@astryxdesign/core/ClickableCard';
4
4
  import { useLocale } from '@astryxdesign/core/i18n';
5
- import { Lightbox } from '@astryxdesign/core/Lightbox';
6
5
  import { Skeleton } from '@astryxdesign/core/Skeleton';
7
6
  import { VStack } from '@astryxdesign/core/VStack';
8
7
  import { hasLead, layoutResult, referencesIn, returnedMedia, withUnit, } from '@theoremjs/web/client';
@@ -11,6 +10,7 @@ import { Arrive } from "./arrive.js";
11
10
  import { CardWall } from "./CardWall.js";
12
11
  import { ReferencedMedia } from "./ChatTranscript.js";
13
12
  import { useLabels } from "./labels-provider.js";
13
+ import { PageMediaViewer } from "./media-viewer.js";
14
14
  import { keyedByContent } from "./row-keys.js";
15
15
  import { ShapedData } from "./ShapedData.js";
16
16
  import { ChartCard } from "./trace-patterns.js";
@@ -34,10 +34,10 @@ function ResultLead({ layout, parts = [], }) {
34
34
  if (!hasLead(layout, media) && references.length === 0)
35
35
  return null;
36
36
  const { images, audio } = media;
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) => {
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(PageMediaViewer, { isOpen: open !== null, onOpenChange: (isOpen) => {
38
38
  if (!isOpen)
39
39
  setOpen(null);
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}`)))] }));
40
+ }, media: images.map((image) => ({ type: '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}`)))] }));
41
41
  }
42
42
  /**
43
43
  * A tool's output under one Response heading, led by what answers it (figures,
package/ui/index.d.ts CHANGED
@@ -25,6 +25,7 @@ export { tablerIcons } from './icons.js';
25
25
  export { LiveCaptionsPanel, type LiveCaptionsPanelProps } from './LiveCaptionsPanel.js';
26
26
  export { composerDrawerLabel, type LabelText, liveStateLabel, THEOREM_UI_CATALOG, type TheoremLabelKey, type TheoremLabelOverrides, type TheoremLabels, type TheoremLabelValues, type TheoremUiCatalog, voiceNoteName, workStatusLabel, } from './labels.js';
27
27
  export { TheoremLabelsProvider, type TheoremLabelsProviderProps, useLabels, } from './labels-provider.js';
28
+ export { AstryxMediaViewer, type MediaViewer, type MediaViewerItem, type MediaViewerProps, useMediaViewer, } from './media-viewer.js';
28
29
  export { PaneFailure, PaneLoading, PaneState } from './PaneState.js';
29
30
  export { RadialBars, Sunburst, type SunburstNode } from './RadialCharts.js';
30
31
  export { type RankedBar, RankedBars } from './RankedBars.js';
package/ui/index.js CHANGED
@@ -27,6 +27,7 @@ export { tablerIcons } from "./icons.js";
27
27
  export { LiveCaptionsPanel } from "./LiveCaptionsPanel.js";
28
28
  export { composerDrawerLabel, liveStateLabel, THEOREM_UI_CATALOG, voiceNoteName, workStatusLabel, } from "./labels.js";
29
29
  export { TheoremLabelsProvider, useLabels, } from "./labels-provider.js";
30
+ export { AstryxMediaViewer, useMediaViewer, } from "./media-viewer.js";
30
31
  export { PaneFailure, PaneLoading, PaneState } from "./PaneState.js";
31
32
  export { RadialBars, Sunburst } from "./RadialCharts.js";
32
33
  export { RankedBars } from "./RankedBars.js";
@@ -0,0 +1,31 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type MediaReference } from './tool-media.js';
3
+ /** One picture or video the viewer shows. */
4
+ export type MediaViewerItem = {
5
+ type: 'image' | 'video';
6
+ /** The address the page loads it from. */
7
+ src: string;
8
+ alt: string;
9
+ caption?: ReactNode;
10
+ /** The saved file it was loaded from, when the app saved it: `src` may be a link that expires. */
11
+ reference?: MediaReference;
12
+ };
13
+ /** What a viewer is given: it is open or closed, and shows `media[index]`. */
14
+ export type MediaViewerProps = {
15
+ isOpen: boolean;
16
+ onOpenChange: (isOpen: boolean) => void;
17
+ media: readonly MediaViewerItem[];
18
+ index: number;
19
+ onIndexChange: (index: number) => void;
20
+ };
21
+ /** The viewer every picture and video in Theorem opens in. Astryx's Lightbox, with zoom, unless the page gives its own. */
22
+ export type MediaViewer = (props: MediaViewerProps) => ReactNode;
23
+ /** Astryx's Lightbox, with zoom: the viewer when the page gives none. */
24
+ export declare function AstryxMediaViewer({ isOpen, onOpenChange, media, index, onIndexChange, }: MediaViewerProps): import("react").JSX.Element;
25
+ /** The page's viewer, held open or closed by its caller. */
26
+ export declare function PageMediaViewer(props: MediaViewerProps): import("react").JSX.Element;
27
+ /** The page's viewer over `media`, closed until `open`; render `element` where the viewer belongs. */
28
+ export declare function useMediaViewer(media: readonly MediaViewerItem[]): {
29
+ open: (index?: number) => void;
30
+ element: ReactNode;
31
+ };
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Lightbox } from '@astryxdesign/core/Lightbox';
3
+ import { useState } from 'react';
4
+ import { useToolMedia } from "./tool-media.js";
5
+ /** Astryx's Lightbox, with zoom: the viewer when the page gives none. */
6
+ export function AstryxMediaViewer({ isOpen, onOpenChange, media, index, onIndexChange, }) {
7
+ return (_jsx(Lightbox, { isOpen: isOpen, onOpenChange: onOpenChange, media: media.map(({ src, alt, caption, type }) => ({ src, alt, caption, type })), index: index, onIndexChange: onIndexChange, hasZoom: true }));
8
+ }
9
+ /** The page's viewer, held open or closed by its caller. */
10
+ export function PageMediaViewer(props) {
11
+ const Viewer = useToolMedia().viewer ?? AstryxMediaViewer;
12
+ return _jsx(Viewer, { ...props });
13
+ }
14
+ /** The page's viewer over `media`, closed until `open`; render `element` where the viewer belongs. */
15
+ export function useMediaViewer(media) {
16
+ const [shown, setShown] = useState({
17
+ isOpen: false,
18
+ index: 0,
19
+ });
20
+ return {
21
+ open: (index = 0) => setShown({ isOpen: true, index }),
22
+ element: media.length > 0 ? (_jsx(PageMediaViewer, { isOpen: shown.isOpen, onOpenChange: (isOpen) => setShown((current) => ({ ...current, isOpen })), media: media, index: shown.index, onIndexChange: (index) => setShown((current) => ({ ...current, index })) })) : null,
23
+ };
24
+ }
@@ -1,5 +1,6 @@
1
1
  import type { ToolOutputRefPart } from '@theoremjs/agents';
2
2
  import { type ReactNode } from 'react';
3
+ import type { MediaViewer } from './media-viewer.js';
3
4
  import { type ToolMediaShown } from './tool-media-shown.js';
4
5
  export { type ToolMediaShown, toolMediaShows } from './tool-media-shown.js';
5
6
  /** A reference a tool returned, with the tool's own `metadata`: the person is shown it, the model never read it. */
@@ -9,14 +10,16 @@ export type MediaReference = ToolOutputRefPart;
9
10
  * `null` when there is none. Without it, a reference shows as a named file.
10
11
  */
11
12
  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
+ /** What a page shows of tool media, how it loads a reference, and the viewer its pictures open in. */
13
14
  export type ToolMediaView = {
14
15
  shown: ToolMediaShown;
15
16
  resolve?: ResolveMedia;
17
+ viewer?: MediaViewer;
16
18
  };
17
- export declare function ToolMediaProvider({ media, resolveMedia, children, }: {
19
+ export declare function ToolMediaProvider({ media, resolveMedia, mediaViewer, children, }: {
18
20
  media?: ToolMediaShown;
19
21
  resolveMedia?: ResolveMedia;
22
+ mediaViewer?: MediaViewer;
20
23
  children: ReactNode;
21
24
  }): import("react").JSX.Element;
22
25
  export declare function useToolMedia(): ToolMediaView;
package/ui/tool-media.js CHANGED
@@ -4,8 +4,12 @@ import { createContext, use, useEffect, useRef, useState } from 'react';
4
4
  import { mediaFileName } from "./tool-media-shown.js";
5
5
  export { toolMediaShows } from "./tool-media-shown.js";
6
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 }));
7
+ export function ToolMediaProvider({ media = 'sent', resolveMedia, mediaViewer, children, }) {
8
+ return (_jsx(ToolMediaContext, { value: {
9
+ shown: media,
10
+ ...(resolveMedia ? { resolve: resolveMedia } : {}),
11
+ ...(mediaViewer ? { viewer: mediaViewer } : {}),
12
+ }, children: children }));
9
13
  }
10
14
  export function useToolMedia() {
11
15
  return use(ToolMediaContext);