@theoremjs/react 0.3.5-next.945.g127cfdd → 0.3.5-next.948.g1059790

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/react",
3
- "version": "0.3.5-next.945.g127cfdd",
3
+ "version": "0.3.5-next.948.g1059790",
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.945.g127cfdd",
64
- "@theoremjs/web": "^0.3.5-next.945.g127cfdd"
63
+ "@theoremjs/agents": "^0.3.5-next.948.g1059790",
64
+ "@theoremjs/web": "^0.3.5-next.948.g1059790"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@astryxdesign/core": {
@@ -290,7 +290,12 @@ function GeneratingImage({ ratio }) {
290
290
  }
291
291
  function MediaBlock({ block }) {
292
292
  if (block.uri !== undefined) {
293
- return (_jsx(ReferencedMedia, { reference: { type: block.type ?? 'document', mimeType: block.mimeType, uri: block.uri } }));
293
+ return (_jsx(ReferencedMedia, { reference: {
294
+ type: block.type ?? 'document',
295
+ mimeType: block.mimeType,
296
+ uri: block.uri,
297
+ ...(block.metadata ? { metadata: block.metadata } : {}),
298
+ } }));
294
299
  }
295
300
  const src = mediaSrc(block);
296
301
  if (src && block.mimeType.startsWith('audio/')) {
@@ -1,9 +1,9 @@
1
- import type { InteractionMediaRefPart } from '@theoremjs/agents';
1
+ import type { ToolOutputRefPart } from '@theoremjs/agents';
2
2
  import { type ReactNode } from 'react';
3
3
  import { type ToolMediaShown } from './tool-media-shown.ts';
4
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;
5
+ /** A reference a tool returned, with the tool's own `metadata`: the person is shown it, the model never read it. */
6
+ export type MediaReference = ToolOutputRefPart;
7
7
  /**
8
8
  * Turns a tool's reference into an address the page may load, under the viewer's own sign-in, or
9
9
  * `null` when there is none. Without it, a reference shows as a named file.
package/ui/tool-media.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { Token } from '@astryxdesign/core/Token';
3
- import { createContext, use, useEffect, useState } from 'react';
3
+ 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' });
@@ -16,23 +16,26 @@ export function useToolMedia() {
16
16
  */
17
17
  export function useResolvedMedia(reference) {
18
18
  const { resolve } = useToolMedia();
19
+ const latest = useRef(reference);
20
+ latest.current = reference;
19
21
  const type = reference?.type;
20
22
  const mimeType = reference?.mimeType;
21
23
  const uri = reference?.uri;
22
24
  const [resolved, setResolved] = useState();
23
25
  useEffect(() => {
24
- if (type === undefined || mimeType === undefined || uri === undefined)
26
+ const current = latest.current;
27
+ if (current === undefined || type === undefined || mimeType === undefined || uri === undefined)
25
28
  return;
26
29
  if (!resolve) {
27
30
  setResolved({ uri, src: null });
28
31
  return;
29
32
  }
30
- let current = true;
33
+ let live = true;
31
34
  Promise.resolve()
32
- .then(() => resolve({ type, mimeType, uri }))
33
- .then((src) => current && setResolved({ uri, src: src ?? null }), () => current && setResolved({ uri, src: null }));
35
+ .then(() => resolve(current))
36
+ .then((src) => live && setResolved({ uri, src: src ?? null }), () => live && setResolved({ uri, src: null }));
34
37
  return () => {
35
- current = false;
38
+ live = false;
36
39
  };
37
40
  }, [resolve, type, mimeType, uri]);
38
41
  if (uri === undefined)