@theoremjs/react 0.3.5-next.978.g2ef222f → 0.3.5-next.979.g76aac35

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
@@ -550,20 +550,22 @@ function MyChat() {
550
550
  `TheoremChat` is built from two pieces in `/ui` that you can place apart: `TheoremChatComposer` and `TheoremChatTranscript`. Each takes the `chat` from `useTheoremChat` (its type is `TheoremChatState`) and the `iface` from `useTheoremInterface`. You decide where each one sits and when each one shows. Theorem moves neither of them.
551
551
 
552
552
  ```tsx
553
- import { TheoremChatComposer, TheoremChatTranscript } from '@theoremjs/react/ui';
553
+ import { TheoremChatComposer, TheoremChatTranscript, TheoremSurface } from '@theoremjs/react/ui';
554
554
 
555
555
  function Dock({ chat, iface }) {
556
556
  const [open, setOpen] = useState(false);
557
557
  return (
558
- <div onFocus={() => setOpen(true)}>
559
- {open && <TheoremChatTranscript chat={chat} iface={iface} />}
560
- <TheoremChatComposer chat={chat} iface={iface} layout="row" />
561
- </div>
558
+ <TheoremSurface>
559
+ <div onFocus={() => setOpen(true)}>
560
+ {open && <TheoremChatTranscript chat={chat} iface={iface} />}
561
+ <TheoremChatComposer chat={chat} iface={iface} layout="row" />
562
+ </div>
563
+ </TheoremSurface>
562
564
  );
563
565
  }
564
566
  ```
565
567
 
566
- `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 `TheoremThemeProvider`, as for `ChatTranscript`.
568
+ `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`.
567
569
 
568
570
  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`.
569
571
 
@@ -144,8 +144,8 @@ export declare function assistantTurnTiming(args: {
144
144
  groups: readonly TranscriptTurnGroup[];
145
145
  index: number;
146
146
  streaming: boolean;
147
- timeOf: (key: string) => number;
148
- spans: ReadonlyMap<string, TurnSpan>;
147
+ /** When the reply to a prompt started, its approval waits skipped (`TurnClock.replyStart`). */
148
+ replyStart: (prompt: TranscriptTurnGroup) => number | undefined;
149
149
  }): AssistantTurnTiming;
150
150
  export declare function toolCallLabel(tool: Extract<TranscriptBlock, {
151
151
  kind: 'tool';
@@ -231,10 +231,8 @@ export function assistantTurnTiming(args) {
231
231
  : { key, live };
232
232
  }
233
233
  const prompt = args.groups[args.index - 1];
234
- const span = prompt?.kind === 'user' ? args.spans.get(prompt.key) : undefined;
235
- if (!prompt || !span)
236
- return { key, live };
237
- return { key, live, startedAt: args.timeOf(prompt.key) + span.pausedMs };
234
+ const startedAt = prompt?.kind === 'user' ? args.replyStart(prompt) : undefined;
235
+ return startedAt === undefined ? { key, live } : { key, live, startedAt };
238
236
  }
239
237
  export function toolCallLabel(tool) {
240
238
  const phase = tool.state?.phase;
@@ -1,12 +1,17 @@
1
- import { type TranscriptTurnGroup, type TurnSpan } from '../client/transcript-groups.ts';
1
+ import { type TranscriptTurnGroup } from '../client/transcript-groups.ts';
2
2
  /**
3
3
  * When each turn was first seen, and how long each sat paused on approvals.
4
4
  * invariant: One clock per chat: the transcript's status line and the composer's working pill
5
5
  * read the same one, so they show the same time.
6
6
  */
7
7
  export type TurnClock = {
8
+ /** When the turn with this key was first seen. */
8
9
  timeOf: (key: string) => number;
9
- spans: ReadonlyMap<string, TurnSpan>;
10
+ /**
11
+ * When the reply to `prompt` started, its approval waits skipped; `undefined` until it runs in
12
+ * this session. A prompt split by a divider still finds its turn.
13
+ */
14
+ replyStart: (prompt: TranscriptTurnGroup) => number | undefined;
10
15
  };
11
16
  /** The chat's turn clock over its grouped transcript. */
12
17
  export declare function useTurnClock(groups: readonly TranscriptTurnGroup[], streaming: boolean): TurnClock;
@@ -43,17 +43,29 @@ function useTurnSpans(streaming, lastUserKey) {
43
43
  }
44
44
  /** The chat's turn clock over its grouped transcript. */
45
45
  export function useTurnClock(groups, streaming) {
46
- const timeOf = useFirstSeen(groups.map((group, index) => (group.kind === 'user' ? group.key : replyKey(groups, index))));
46
+ // why: Every block's id is seen now, so a transcript that groups with dividers finds its times.
47
+ const timeOf = useFirstSeen(groups.flatMap((group, index) => [
48
+ group.kind === 'user' ? group.key : replyKey(groups, index),
49
+ ...group.blocks.flatMap((block) => group.kind === 'user' ? [block.id, `${block.id}:reply`] : [block.id]),
50
+ ]));
47
51
  const spans = useTurnSpans(streaming, groups.findLast((group) => group.kind === 'user')?.key);
48
- return { timeOf, spans };
52
+ const turnKey = new Map();
53
+ for (const group of groups) {
54
+ if (group.kind === 'user')
55
+ for (const block of group.blocks)
56
+ turnKey.set(block.id, group.key);
57
+ }
58
+ const replyStart = (prompt) => {
59
+ const key = turnKey.get(prompt.blocks[0]?.id ?? '') ?? prompt.key;
60
+ const span = spans.get(key);
61
+ return span ? timeOf(key) + span.pausedMs : undefined;
62
+ };
63
+ return { timeOf, replyStart };
49
64
  }
50
65
  /** When the reply in progress started, its approval waits skipped; `undefined` when none runs. */
51
66
  export function liveTurnStart(groups, clock, streaming) {
52
67
  if (!streaming)
53
68
  return undefined;
54
69
  const prompt = groups.findLast((group) => group.kind === 'user');
55
- if (!prompt)
56
- return undefined;
57
- const span = clock.spans.get(prompt.key);
58
- return span ? clock.timeOf(prompt.key) + span.pausedMs : undefined;
70
+ return prompt ? clock.replyStart(prompt) : undefined;
59
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/react",
3
- "version": "0.3.5-next.978.g2ef222f",
3
+ "version": "0.3.5-next.979.g76aac35",
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.978.g2ef222f",
64
- "@theoremjs/web": "^0.3.5-next.978.g2ef222f"
63
+ "@theoremjs/agents": "^0.3.5-next.979.g76aac35",
64
+ "@theoremjs/web": "^0.3.5-next.979.g76aac35"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@astryxdesign/core": {
@@ -630,7 +630,7 @@ export function ChatTranscript(props) {
630
630
  function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToolDecision, answering = null, onAuthenticated, emptyState, dividers, imageOutput, bodyKindPlacement, labels, clock, }) {
631
631
  const groups = useMemo(() => groupTranscriptBlocks(blocks, dividers && new Set(Object.keys(dividers))), [blocks, dividers]);
632
632
  const own = useTurnClock(groups, streaming);
633
- const { timeOf, spans } = clock ?? own;
633
+ const { timeOf, replyStart } = clock ?? own;
634
634
  const pendingPrompt = streaming ? pendingPromptOf(groups) : undefined;
635
635
  const listRef = useRef(null);
636
636
  useDisclosureMotion(listRef);
@@ -657,8 +657,7 @@ function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToo
657
657
  groups,
658
658
  index,
659
659
  streaming,
660
- timeOf,
661
- spans,
660
+ replyStart,
662
661
  });
663
662
  // why: A reply is dated when it last stopped: a reply that just finished reads "now".
664
663
  const at = endedAt ?? timeOf(key);
@@ -676,7 +675,7 @@ function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToo
676
675
  // why: It sits in the same keyed list as the streamed reply, so the reply stays
677
676
  // one message; a remount would read to the layout as a new message.
678
677
  if (pendingPrompt) {
679
- turns.push(_jsx(AssistantTurn, { ...turn, blocks: [], streaming: true, at: timeOf(pendingPrompt.key), startedAt: timeOf(pendingPrompt.key) }, promptReplyKey(pendingPrompt)));
678
+ turns.push(_jsx(AssistantTurn, { ...turn, blocks: [], streaming: true, at: timeOf(pendingPrompt.key), startedAt: replyStart(pendingPrompt) ?? timeOf(pendingPrompt.key) }, promptReplyKey(pendingPrompt)));
680
679
  }
681
680
  return (_jsx(ChatMessageList, { ref: listRef, isStreaming: streaming, emptyState: emptyState, children: turns }));
682
681
  }
package/ui/LiveRunner.js CHANGED
@@ -20,8 +20,8 @@ import { LiveVideoPreview } from "./LiveVideoPreview.js";
20
20
  import { liveStateLabel } from "./labels.js";
21
21
  import { useLabels } from "./labels-provider.js";
22
22
  import { PANEL_EDGE, SidePanel, SidePanelHeader, SidePanelToggle, useSidePanel, } from "./SidePanel.js";
23
- import { SurfaceProviders } from "./surface-providers.js";
24
23
  import { DEFAULT_CHAT_MAX_WIDTH } from "./TheoremChat.js";
24
+ import { TheoremSurface } from "./TheoremSurface.js";
25
25
  import { useTraceInspector, WithTrace } from "./TraceInspectorPanel.js";
26
26
  /** The waveform's box: it rests on the stage floor rather than filling the stage. */
27
27
  const WAVE_MAX_WIDTH = 720;
@@ -34,7 +34,7 @@ const WAVE_HEIGHT = 320;
34
34
  * the profile records traces.
35
35
  */
36
36
  export function LiveRunner({ theme, mode, labels, media, resolveMedia, ...props }) {
37
- return (_jsx(SurfaceProviders, { theme: theme, mode: mode, labels: labels, detectCodeLanguage: undefined, media: media, resolveMedia: resolveMedia, children: _jsx(LiveRunnerBody, { ...props }) }));
37
+ return (_jsx(TheoremSurface, { theme: theme, mode: mode, labels: labels, detectCodeLanguage: undefined, media: media, resolveMedia: resolveMedia, children: _jsx(LiveRunnerBody, { ...props }) }));
38
38
  }
39
39
  function LiveRunnerBody({ call, trace, onMinimize, }) {
40
40
  const t = useLabels();
package/ui/TheoremChat.js CHANGED
@@ -17,7 +17,7 @@ import { useGlide } from "./glide.js";
17
17
  import { useLabels } from "./labels-provider.js";
18
18
  import { PaneFailure, PaneLoading } from "./PaneState.js";
19
19
  import { SidePanelHeader } from "./SidePanel.js";
20
- import { SurfaceProviders } from "./surface-providers.js";
20
+ import { TheoremSurface } from "./TheoremSurface.js";
21
21
  import { useTraceInspector, WithTrace } from "./TraceInspectorPanel.js";
22
22
  /**
23
23
  * 50% of the chat's width, but never narrower than 640px (or the full width,
@@ -159,5 +159,5 @@ export function TheoremChat({ endpoint, http, transport, theme, mode, labels, de
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(SurfaceProviders, { 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, children: _jsx(ChatForTransport, { ...rest, transport: resolved }) }));
163
163
  }
package/ui/TheoremHost.js CHANGED
@@ -23,7 +23,7 @@ import { useLabels } from "./labels-provider.js";
23
23
  import { IconMcp } from "./mcp-icon.js";
24
24
  import { PaneFailure, PaneLoading } from "./PaneState.js";
25
25
  import { SchemaFields } from "./SchemaFields.js";
26
- import { SurfaceProviders } from "./surface-providers.js";
26
+ import { TheoremSurface } from "./TheoremSurface.js";
27
27
  import { ApprovalCard, AuthChallengeCard } from "./ToolGateCard.js";
28
28
  import { ToolResult } from "./ToolResult.js";
29
29
  import { useTraceInspector } from "./TraceInspectorPanel.js";
@@ -235,5 +235,5 @@ export function TheoremHost({ endpoint, http, transport, theme, mode, labels, de
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(SurfaceProviders, { 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, children: _jsx(HostForTransport, { ...rest, transport: resolved }) }));
239
239
  }
@@ -0,0 +1,20 @@
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
+ /** What `TheoremSurface` takes: each is the `TheoremChat` prop of the same name. */
6
+ export type TheoremSurfaceProps = {
7
+ theme?: DefinedTheme;
8
+ mode?: 'system' | 'light' | 'dark';
9
+ labels?: TheoremLabels;
10
+ detectCodeLanguage?: boolean;
11
+ media?: ToolMediaShown;
12
+ resolveMedia?: ResolveMedia;
13
+ children: ReactNode;
14
+ };
15
+ /**
16
+ * The theme, labels, Markdown plugins, and tool media a chat or a host page draws with. Wrap
17
+ * `TheoremChatComposer` and `TheoremChatTranscript` in it when you place them yourself; it takes
18
+ * what `TheoremChat` takes for each.
19
+ */
20
+ export declare function TheoremSurface({ theme, mode, labels, detectCodeLanguage, media, resolveMedia, children, }: TheoremSurfaceProps): import("react").JSX.Element;
@@ -3,7 +3,11 @@ import { TheoremLabelsProvider } from "./labels-provider.js";
3
3
  import { MarkdownPluginsProvider } from "./markdown-plugins.js";
4
4
  import { TheoremThemeProvider } from "./theme.js";
5
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, }) {
6
+ /**
7
+ * The theme, labels, Markdown plugins, and tool media a chat or a host page draws with. Wrap
8
+ * `TheoremChatComposer` and `TheoremChatTranscript` in it when you place them yourself; it takes
9
+ * what `TheoremChat` takes for each.
10
+ */
11
+ export function TheoremSurface({ theme, mode, labels, detectCodeLanguage, media, resolveMedia, children, }) {
8
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 }) }) }) }));
9
13
  }
package/ui/index.d.ts CHANGED
@@ -33,6 +33,7 @@ export { DEFAULT_CHAT_MAX_WIDTH, TheoremChat, TheoremChatComposer, type TheoremC
33
33
  export { TheoremDecision, type TheoremDecisionProps } from './TheoremDecision.tsx';
34
34
  export { TheoremEmbedding, type TheoremEmbeddingProps } from './TheoremEmbedding.tsx';
35
35
  export { TheoremHost, type TheoremHostProps } from './TheoremHost.tsx';
36
+ export { TheoremSurface, type TheoremSurfaceProps } from './TheoremSurface.tsx';
36
37
  export { ApprovalCard, type ApprovalCardProps, AuthChallengeCard, type AuthChallengeCardProps, type ToolDecision, } from './ToolGateCard.tsx';
37
38
  export { ToolResult } from './ToolResult.tsx';
38
39
  export { TraceGuardrailsView, TracePlacement, useTraceInspector } from './TraceInspectorPanel.tsx';
package/ui/index.js CHANGED
@@ -35,6 +35,7 @@ export { DEFAULT_CHAT_MAX_WIDTH, TheoremChat, TheoremChatComposer, TheoremChatTr
35
35
  export { TheoremDecision } from "./TheoremDecision.js";
36
36
  export { TheoremEmbedding } from "./TheoremEmbedding.js";
37
37
  export { TheoremHost } from "./TheoremHost.js";
38
+ export { TheoremSurface } from "./TheoremSurface.js";
38
39
  export { ApprovalCard, AuthChallengeCard, } from "./ToolGateCard.js";
39
40
  export { ToolResult } from "./ToolResult.js";
40
41
  export { TraceGuardrailsView, TracePlacement, useTraceInspector } from "./TraceInspectorPanel.js";
@@ -1,14 +0,0 @@
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;