@theoremjs/react 0.3.5-next.977.g42c51f5 → 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
@@ -545,7 +545,31 @@ function MyChat() {
545
545
 
546
546
  `handlePendingMove(id, direction)` moves a pending message among those of its kind. `ChatComposerBar` draws a move only when `composerPendingMoves` from `@theoremjs/agents/interface` says the message can go that way: a message alone in its kind has none.
547
547
 
548
- To show the transcript and the composer, use `ChatTranscript` and `ChatComposerBar` from `/ui`. You can also draw your own from `chat.blocks`.
548
+ ### Place the pieces yourself
549
+
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
+
552
+ ```tsx
553
+ import { TheoremChatComposer, TheoremChatTranscript, TheoremSurface } from '@theoremjs/react/ui';
554
+
555
+ function Dock({ chat, iface }) {
556
+ const [open, setOpen] = useState(false);
557
+ return (
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>
564
+ );
565
+ }
566
+ ```
567
+
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`.
569
+
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`.
571
+
572
+ To draw one piece in your own way, use `ChatTranscript` and `ChatComposerBar` from `/ui`, or draw from `chat.shownBlocks`. Pass `clock={chat.turnClock}` to `ChatTranscript` and `workingSince={chat.workingSince}` to `ChatComposerBar` so their times agree.
549
573
 
550
574
  The composer bar has a selector for the model, its effort, and each option. When their values do not fit the bar, each selector shows only its icon, and a tooltip gives its name and value. When the icons do not fit either, the row scrolls inside the composer. A control you pass as `generationSelect` keeps its own look and scrolls with the row.
551
575
 
@@ -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;
@@ -13,6 +13,15 @@ export declare function useTheoremChat(options: UseTheoremChatOptions): {
13
13
  declared: import("../../../mod.ts").ProfileOptions;
14
14
  values: Record<string, string>;
15
15
  } | undefined;
16
+ /** What the transcript shows: the committed blocks, then the reply streaming in. */
17
+ shownBlocks: import("../../../src/interface/types.ts").TranscriptBlock[];
18
+ /**
19
+ * When each turn started and how long it waited on approvals. Pass it to `ChatTranscript`'s
20
+ * `clock` so its times agree with the composer's working pill.
21
+ */
22
+ turnClock: import("./use-turn-clock.ts").TurnClock;
23
+ /** When the reply in progress started, its approval waits skipped; `undefined` when none runs. */
24
+ workingSince: number | undefined;
16
25
  /** The tool calls still running in the background, oldest first, until their results land. */
17
26
  backgroundJobs: import("../index.ts").BackgroundJob[];
18
27
  setDraftText: (value: import("@theoremjs/web/client").ChatUpdate<string>) => void;
@@ -54,3 +63,5 @@ export declare function useTheoremChat(options: UseTheoremChatOptions): {
54
63
  streaming: boolean;
55
64
  options: import("@theoremjs/web/client").ChatOptionPicks | undefined;
56
65
  };
66
+ /** What `useTheoremChat` returns: the chat's state and its actions. */
67
+ export type TheoremChatState = ReturnType<typeof useTheoremChat>;
@@ -1,6 +1,7 @@
1
1
  import { createChatController, } from '@theoremjs/web/client';
2
2
  import { useCallback, useEffect, useLayoutEffect, useMemo, useState, useSyncExternalStore, } from 'react';
3
- import { backgroundJobs } from "../client/transcript-groups.js";
3
+ import { backgroundJobs, groupTranscriptBlocks } from "../client/transcript-groups.js";
4
+ import { liveTurnStart, useTurnClock } from "./use-turn-clock.js";
4
5
  // why: Options reach the chat before the browser paints, and before a line can arrive; a server render runs no effects.
5
6
  const useOptionsEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
6
7
  /**
@@ -14,13 +15,25 @@ export function useTheoremChat(options) {
14
15
  useOptionsEffect(() => chat.update(options));
15
16
  const state = useSyncExternalStore(chat.subscribe, chat.getState, chat.getState);
16
17
  const optionChoices = useMemo(() => (state.options ? { ...state.options, onChange: chat.pickOption } : undefined), [chat, state.options]);
17
- const jobs = useMemo(() => backgroundJobs([...state.blocks, ...state.streamBlocks]), [state.blocks, state.streamBlocks]);
18
+ const shownBlocks = useMemo(() => [...state.blocks, ...state.streamBlocks], [state.blocks, state.streamBlocks]);
19
+ const jobs = useMemo(() => backgroundJobs(shownBlocks), [shownBlocks]);
20
+ const groups = useMemo(() => groupTranscriptBlocks(shownBlocks), [shownBlocks]);
21
+ const turnClock = useTurnClock(groups, state.streaming);
18
22
  // why: The transcript draws each gate by its index; the chat answers the one gate that waits.
19
23
  const handleAuthenticated = useCallback((_index, secret) => chat.authenticate(secret), [chat]);
20
24
  const handleToolDecision = useCallback((_index, action) => chat.decide(action), [chat]);
21
25
  return {
22
26
  ...state,
23
27
  optionChoices,
28
+ /** What the transcript shows: the committed blocks, then the reply streaming in. */
29
+ shownBlocks,
30
+ /**
31
+ * When each turn started and how long it waited on approvals. Pass it to `ChatTranscript`'s
32
+ * `clock` so its times agree with the composer's working pill.
33
+ */
34
+ turnClock,
35
+ /** When the reply in progress started, its approval waits skipped; `undefined` when none runs. */
36
+ workingSince: liveTurnStart(groups, turnClock, state.streaming),
24
37
  /** The tool calls still running in the background, oldest first, until their results land. */
25
38
  backgroundJobs: jobs,
26
39
  setDraftText: chat.setDraftText,
@@ -1,18 +1,19 @@
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;
13
18
  /** When the reply in progress started, its approval waits skipped; `undefined` when none runs. */
14
19
  export declare function liveTurnStart(groups: readonly TranscriptTurnGroup[], clock: TurnClock, streaming: boolean): number | undefined;
15
- /** The clock a chat shares with its transcript; a transcript on its own keeps its own. */
16
- export declare const TurnClockContext: import("react").Context<TurnClock | null>;
17
- /** The shared clock when a chat provides one, else this transcript's own. */
18
- export declare function useSharedTurnClock(groups: readonly TranscriptTurnGroup[], streaming: boolean): TurnClock;
@@ -1,4 +1,4 @@
1
- import { createContext, useContext, useRef } from 'react';
1
+ import { useRef } from 'react';
2
2
  import { replyKey } from "../client/transcript-groups.js";
3
3
  /** First-seen time per group key, so timestamps don't jump while streaming. */
4
4
  function useFirstSeen(keys) {
@@ -8,7 +8,15 @@ function useFirstSeen(keys) {
8
8
  if (!times.current.has(key))
9
9
  times.current.set(key, now);
10
10
  }
11
- return (key) => times.current.get(key) ?? now;
11
+ // why: A key first asked for later (a divider's group) keeps the time it was first asked for.
12
+ return (key) => {
13
+ const known = times.current.get(key);
14
+ if (known !== undefined)
15
+ return known;
16
+ const at = Date.now();
17
+ times.current.set(key, at);
18
+ return at;
19
+ };
12
20
  }
13
21
  /**
14
22
  * Each turn's span, keyed by the user group that started it. A turn stops at
@@ -35,25 +43,29 @@ function useTurnSpans(streaming, lastUserKey) {
35
43
  }
36
44
  /** The chat's turn clock over its grouped transcript. */
37
45
  export function useTurnClock(groups, streaming) {
38
- 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
+ ]));
39
51
  const spans = useTurnSpans(streaming, groups.findLast((group) => group.kind === 'user')?.key);
40
- 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 };
41
64
  }
42
65
  /** When the reply in progress started, its approval waits skipped; `undefined` when none runs. */
43
66
  export function liveTurnStart(groups, clock, streaming) {
44
67
  if (!streaming)
45
68
  return undefined;
46
69
  const prompt = groups.findLast((group) => group.kind === 'user');
47
- if (!prompt)
48
- return undefined;
49
- const span = clock.spans.get(prompt.key);
50
- return span ? clock.timeOf(prompt.key) + span.pausedMs : undefined;
51
- }
52
- /** The clock a chat shares with its transcript; a transcript on its own keeps its own. */
53
- export const TurnClockContext = createContext(null);
54
- /** The shared clock when a chat provides one, else this transcript's own. */
55
- export function useSharedTurnClock(groups, streaming) {
56
- const shared = useContext(TurnClockContext);
57
- const own = useTurnClock(groups, streaming);
58
- return shared ?? own;
70
+ return prompt ? clock.replyStart(prompt) : undefined;
59
71
  }
package/index.d.ts CHANGED
@@ -10,8 +10,9 @@
10
10
  export * from '@theoremjs/web/client';
11
11
  export { type BackgroundJob, backgroundJobs } from './client/transcript-groups.ts';
12
12
  export { type EmbeddingIndex, type IndexProgress, useEmbeddingIndex, } from './hooks/use-embedding-index.ts';
13
- export { type SendTextOptions, type SentTurn, type UseTheoremChatOptions, useTheoremChat, } from './hooks/use-theorem-chat.ts';
13
+ export { type SendTextOptions, type SentTurn, type TheoremChatState, type UseTheoremChatOptions, useTheoremChat, } from './hooks/use-theorem-chat.ts';
14
14
  export { type TheoremDecisionState, useTheoremDecision } from './hooks/use-theorem-decision.ts';
15
15
  export { type TheoremEmbeddingState, useTheoremEmbedding, } from './hooks/use-theorem-embedding.ts';
16
16
  export { type TheoremHostCall, type TheoremHostState, useTheoremHost, } from './hooks/use-theorem-host.ts';
17
17
  export { type TheoremInterfaceState, useTheoremInterface } from './hooks/use-theorem-interface.ts';
18
+ export type { TurnClock } from './hooks/use-turn-clock.ts';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/react",
3
- "version": "0.3.5-next.977.g42c51f5",
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.977.g42c51f5",
64
- "@theoremjs/web": "^0.3.5-next.977.g42c51f5"
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": {
@@ -4,6 +4,7 @@ import { type TranscriptBlock } from '@theoremjs/agents/interface';
4
4
  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
+ import { type TurnClock } from '../hooks/use-turn-clock.ts';
7
8
  import { type ToolDecision } from './ToolGateCard.tsx';
8
9
  import { type MediaReference } from './tool-media.tsx';
9
10
  export type ChatTranscriptProps = {
@@ -24,6 +25,11 @@ export type ChatTranscriptProps = {
24
25
  * starts at its block, and that block always starts a turn of its own.
25
26
  */
26
27
  dividers?: Readonly<Record<string, string>>;
28
+ /**
29
+ * The chat's turn clock (`useTheoremChat().turnClock`), so the times here agree with the
30
+ * composer's working pill. Without it the transcript keeps its own.
31
+ */
32
+ clock?: TurnClock;
27
33
  /**
28
34
  * Set for image profiles: generated images show large, framed to their own
29
35
  * aspect ratio, with a matching skeleton while one generates.
@@ -25,7 +25,7 @@ import { citationsFromBlock } from '@theoremjs/web/client';
25
25
  import { createContext, useContext, useEffect, useMemo, useRef, useState, } from 'react';
26
26
  import { assistantTurnCopyText, assistantTurnTiming, composeAssistantTurn, groupTranscriptBlocks, pendingPromptOf, promptReplyKey, promptTime, toolCallLabel, workStatus, } from "../client/transcript-groups.js";
27
27
  import { useSecondTicker } from "../hooks/use-second-ticker.js";
28
- import { useSharedTurnClock } from "../hooks/use-turn-clock.js";
28
+ import { useTurnClock } from "../hooks/use-turn-clock.js";
29
29
  import { useDisclosureMotion } from "./disclosure-motion.js";
30
30
  import { usageLine, workDuration, workStatusLabel } from "./labels.js";
31
31
  import { TheoremLabelsProvider, useLabels } from "./labels-provider.js";
@@ -627,9 +627,10 @@ function isBareFailure(group) {
627
627
  export function ChatTranscript(props) {
628
628
  return (_jsx(TheoremLabelsProvider, { children: _jsx(ShowUsage.Provider, { value: props.usage === true, children: _jsx(ChatTranscriptBody, { ...props }) }) }));
629
629
  }
630
- function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToolDecision, answering = null, onAuthenticated, emptyState, dividers, imageOutput, bodyKindPlacement, labels, }) {
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
- const { timeOf, spans } = useSharedTurnClock(groups, streaming);
632
+ const own = useTurnClock(groups, streaming);
633
+ const { timeOf, replyStart } = clock ?? own;
633
634
  const pendingPrompt = streaming ? pendingPromptOf(groups) : undefined;
634
635
  const listRef = useRef(null);
635
636
  useDisclosureMotion(listRef);
@@ -656,8 +657,7 @@ function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToo
656
657
  groups,
657
658
  index,
658
659
  streaming,
659
- timeOf,
660
- spans,
660
+ replyStart,
661
661
  });
662
662
  // why: A reply is dated when it last stopped: a reply that just finished reads "now".
663
663
  const at = endedAt ?? timeOf(key);
@@ -675,7 +675,7 @@ function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToo
675
675
  // why: It sits in the same keyed list as the streamed reply, so the reply stays
676
676
  // one message; a remount would read to the layout as a new message.
677
677
  if (pendingPrompt) {
678
- 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)));
679
679
  }
680
680
  return (_jsx(ChatMessageList, { ref: listRef, isStreaming: streaming, emptyState: emptyState, children: turns }));
681
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();
@@ -1,11 +1,13 @@
1
+ import { type ChatComposerInputHandle } from '@astryxdesign/core/Chat';
1
2
  import type { DefinedTheme } from '@astryxdesign/core/theme';
2
- import { type ComposerPendingMessage } from '@theoremjs/agents/interface';
3
+ import { type ComposerPendingMessage, type ComposerProfileInterface } from '@theoremjs/agents/interface';
3
4
  import type { ChatController, PageTools, StatedTurn } from '@theoremjs/web/client';
4
5
  import { type ConversationView, type HttpTransportOptions, type TheoremTransport } from '@theoremjs/web/client';
5
6
  import { type ReactNode, type Ref } from 'react';
6
- import { type SendTextOptions, type SentTurn, type UseTheoremChatOptions } from '../hooks/use-theorem-chat.ts';
7
+ import { type SendTextOptions, type SentTurn, type TheoremChatState, type UseTheoremChatOptions } from '../hooks/use-theorem-chat.ts';
7
8
  import { type ComposerLayout } from './ChatComposerBar.tsx';
8
9
  import type { ComposerRowIcons } from './ChatComposerRow.tsx';
10
+ import { type ChatTranscriptProps } from './ChatTranscript.tsx';
9
11
  import type { TheoremLabels } from './labels.ts';
10
12
  import type { ResolveMedia, ToolMediaShown } from './tool-media.tsx';
11
13
  export type TheoremChatProps = {
@@ -161,6 +163,37 @@ export type TheoremChatHandle = {
161
163
  * whichever is smaller) — so phones and narrow panes get 100%.
162
164
  */
163
165
  export declare const DEFAULT_CHAT_MAX_WIDTH = "max(50%, min(100%, 640px))";
166
+ export type TheoremChatComposerProps = {
167
+ /** The chat it writes to (`useTheoremChat`). */
168
+ chat: TheoremChatState;
169
+ /** The profile's interface (`useTheoremInterface`). */
170
+ iface: ComposerProfileInterface;
171
+ placeholder?: string;
172
+ /** Focus the field from outside. */
173
+ inputRef?: Ref<ChatComposerInputHandle>;
174
+ layout?: ComposerLayout;
175
+ icons?: ComposerRowIcons;
176
+ };
177
+ /**
178
+ * The composer bound to a chat: drafts, files, voice, the pending queue, send and stop, and the
179
+ * working pill on the chat's turn clock. Place it anywhere; `TheoremChat` is built from it and
180
+ * `TheoremChatTranscript`.
181
+ */
182
+ export declare function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, }: TheoremChatComposerProps): import("react").JSX.Element;
183
+ export type TheoremChatTranscriptProps = Omit<ChatTranscriptProps, 'blocks' | 'handle' | 'streaming' | 'delivery' | 'answering' | 'clock' | 'onToolDecision' | 'onAuthenticated' | 'imageOutput' | 'labels'> & {
184
+ /** The chat it shows (`useTheoremChat`). */
185
+ chat: TheoremChatState;
186
+ /** The profile's interface (`useTheoremInterface`). */
187
+ iface: ComposerProfileInterface;
188
+ /** The name over each reply. Default: the profile's handle. */
189
+ handle?: string;
190
+ };
191
+ /**
192
+ * The transcript bound to a chat: its blocks as they stream, its gates answered through the chat,
193
+ * and its times on the chat's turn clock, so they agree with `TheoremChatComposer` wherever each
194
+ * is placed.
195
+ */
196
+ export declare function TheoremChatTranscript({ chat, iface, handle, ...props }: TheoremChatTranscriptProps): import("react").JSX.Element;
164
197
  /**
165
198
  * Drop-in chat for a profile served by `createTheoremHandler`:
166
199
  *
package/ui/TheoremChat.js CHANGED
@@ -9,17 +9,15 @@ import { removeComposerPendingMessage, } from '@theoremjs/agents/interface';
9
9
  import { createHttpTransport, } from '@theoremjs/web/client';
10
10
  import { useImperativeHandle, useMemo, useRef, } from 'react';
11
11
  import { parseAspectRatio } from "../client/image-output.js";
12
- import { groupTranscriptBlocks } from "../client/transcript-groups.js";
13
12
  import { useTheoremChat, } from "../hooks/use-theorem-chat.js";
14
13
  import { useTheoremInterface } from "../hooks/use-theorem-interface.js";
15
- import { liveTurnStart, TurnClockContext, useTurnClock } from "../hooks/use-turn-clock.js";
16
14
  import { ChatComposerBar } from "./ChatComposerBar.js";
17
15
  import { ChatTranscript } from "./ChatTranscript.js";
18
16
  import { useGlide } from "./glide.js";
19
17
  import { useLabels } from "./labels-provider.js";
20
18
  import { PaneFailure, PaneLoading } from "./PaneState.js";
21
19
  import { SidePanelHeader } from "./SidePanel.js";
22
- import { SurfaceProviders } from "./surface-providers.js";
20
+ import { TheoremSurface } from "./TheoremSurface.js";
23
21
  import { useTraceInspector, WithTrace } from "./TraceInspectorPanel.js";
24
22
  /**
25
23
  * 50% of the chat's width, but never narrower than 640px (or the full width,
@@ -30,9 +28,13 @@ export const DEFAULT_CHAT_MAX_WIDTH = 'max(50%, min(100%, 640px))';
30
28
  function ChatColumn({ maxWidth, ref, children, }) {
31
29
  return (_jsx(Center, { axis: "horizontal", width: "100%", children: _jsx(VStack, { ref: ref, width: "100%", maxWidth: maxWidth, children: children }) }));
32
30
  }
33
- /** The composer bar wired to a `useTheoremChat` model. */
34
- function ChatComposerForChat({ chat, iface, placeholder, inputRef, layout, icons, workingSince, }) {
35
- return (_jsx(ChatComposerBar, { iface: iface, layout: layout, icons: icons, workingSince: workingSince, backgroundJobs: chat.backgroundJobs, draftText: chat.draftText, pendingFiles: chat.pendingFiles, pendingVoice: chat.pendingVoice, pendingMessages: chat.pendingMessages, issues: chat.issues, phase: chat.phase, failure: chat.failure, selectedModel: chat.session.selectedModel, selectedEffort: chat.session.selectedEffort, placeholder: placeholder, inputRef: inputRef, onDraftTextChange: chat.setDraftText, onFilesSelected: (files) => {
31
+ /**
32
+ * The composer bound to a chat: drafts, files, voice, the pending queue, send and stop, and the
33
+ * working pill on the chat's turn clock. Place it anywhere; `TheoremChat` is built from it and
34
+ * `TheoremChatTranscript`.
35
+ */
36
+ export function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, }) {
37
+ return (_jsx(ChatComposerBar, { iface: iface, layout: layout, icons: icons, workingSince: chat.workingSince, backgroundJobs: chat.backgroundJobs, draftText: chat.draftText, pendingFiles: chat.pendingFiles, pendingVoice: chat.pendingVoice, pendingMessages: chat.pendingMessages, issues: chat.issues, phase: chat.phase, failure: chat.failure, selectedModel: chat.session.selectedModel, selectedEffort: chat.session.selectedEffort, placeholder: placeholder, inputRef: inputRef, onDraftTextChange: chat.setDraftText, onFilesSelected: (files) => {
36
38
  chat.setPendingFiles((prev) => [...prev, ...files]);
37
39
  chat.setIssues([]);
38
40
  }, onAttachmentRemove: (index) => {
@@ -69,7 +71,7 @@ function useChatHandle(chatRef, chat) {
69
71
  /** The composer, or, with none, the failed turn's error where the composer was. */
70
72
  function ChatBodyComposer({ hasComposer, ...props }) {
71
73
  if (hasComposer)
72
- return _jsx(ChatComposerForChat, { ...props });
74
+ return _jsx(TheoremChatComposer, { ...props });
73
75
  const failure = props.chat.failure;
74
76
  return failure ? _jsx(Banner, { status: "error", role: "alert", title: failure.error }) : null;
75
77
  }
@@ -92,18 +94,15 @@ function ChatBody({ transport, iface, placeholder, emptyState, density, maxWidth
92
94
  pageTools,
93
95
  onTurnEvent,
94
96
  });
95
- const blocks = useMemo(() => [...chat.blocks, ...chat.streamBlocks], [chat.blocks, chat.streamBlocks]);
96
- const groups = useMemo(() => groupTranscriptBlocks(blocks), [blocks]);
97
- const clock = useTurnClock(groups, chat.streaming);
98
97
  const handle = t('@theorem.agent.handle', { handle: iface.identity.handle });
99
- const landing = blocks.length === 0;
98
+ const landing = chat.shownBlocks.length === 0;
100
99
  const inputRef = useChatHandle(chatRef, chat);
101
100
  const composerRef = useGlide(landing, () => inputRef.current?.focus());
102
101
  const inspector = useTraceInspector(iface, transport.traces, trace);
103
102
  const header = _jsx(SidePanelHeader, { floating: true, children: inspector.toggle });
104
- const composer = (_jsx(ChatBodyComposer, { hasComposer: hasComposer, chat: chat, iface: iface, placeholder: placeholder, inputRef: inputRef, layout: composerLayout, icons: composerIcons, workingSince: liveTurnStart(groups, clock, chat.streaming) }));
103
+ const composer = (_jsx(ChatBodyComposer, { hasComposer: hasComposer, chat: chat, iface: iface, placeholder: placeholder, inputRef: inputRef, layout: composerLayout, icons: composerIcons }));
105
104
  const docked = { composer, composerRef, maxWidth };
106
- return (_jsx(TurnClockContext, { value: clock, children: _jsx(WithTrace, { inspector: inspector, children: _jsx(Layout, { height: "fill", className: className, style: { position: 'relative', ...style }, header: header, content: _jsx(LayoutContent, { padding: 0, isScrollable: landing, children: landing ? (_jsx(ChatLanding, { ...docked, handle: handle, emptyState: emptyState })) : (_jsx(ChatThread, { ...docked, chat: chat, iface: iface, blocks: blocks, handle: handle, density: density, scrollRef: scrollRef, usage: usage })) }) }) }) }));
105
+ return (_jsx(WithTrace, { inspector: inspector, children: _jsx(Layout, { height: "fill", className: className, style: { position: 'relative', ...style }, header: header, content: _jsx(LayoutContent, { padding: 0, isScrollable: landing, children: landing ? (_jsx(ChatLanding, { ...docked, handle: handle, emptyState: emptyState })) : (_jsx(ChatThread, { ...docked, chat: chat, iface: iface, handle: handle, density: density, scrollRef: scrollRef, usage: usage })) }) }) }));
107
106
  }
108
107
  const CHAT_SCROLL = { overscrollBehavior: 'none' };
109
108
  /**
@@ -119,16 +118,23 @@ function ChatLanding({ composer, composerRef, maxWidth, handle, emptyState, }) {
119
118
  * why: the dock leaves 12px under the composer; paddingBlockEnd={3} adds 12px more for a 24px
120
119
  * bottom margin.
121
120
  */
122
- function ChatThread({ composer, composerRef, maxWidth, chat, iface, blocks, handle, density, scrollRef, usage, }) {
121
+ function ChatThread({ composer, composerRef, maxWidth, chat, iface, handle, density, scrollRef, usage, }) {
123
122
  return (_jsxs(VStack, { height: "100%", children: [_jsx("style", { href: "theorem-chat-thread", precedence: "default", children: '.theorem-chat-thread > :last-child > div:empty { display: none; }' }), _jsx(ChatLayout, { className: "theorem-chat-thread", density: density, scrollRef: scrollRef,
124
123
  // why: Scrolling past either end does not bounce the transcript and its docked composer.
125
- style: CHAT_SCROLL, composer: composer && (_jsx(VStack, { paddingBlockEnd: 3, children: _jsx(ChatColumn, { ref: composerRef, maxWidth: maxWidth, children: composer }) })), children: _jsx(ChatColumn, { maxWidth: maxWidth, children: _jsx(ChatTranscript, { blocks: blocks, handle: handle, streaming: chat.streaming, delivery: chat.delivery, answering: chat.answering, usage: usage, labels: iface.labels, imageOutput: iface.type === 'image'
126
- ? { ratio: parseAspectRatio(iface.image.aspectRatio) }
127
- : undefined, onToolDecision: (index, action) => {
128
- void chat.handleToolDecision(index, action);
129
- }, onAuthenticated: (index, secret) => {
130
- void chat.handleAuthenticated(index, secret);
131
- } }) }) })] }));
124
+ style: CHAT_SCROLL, composer: composer && (_jsx(VStack, { paddingBlockEnd: 3, children: _jsx(ChatColumn, { ref: composerRef, maxWidth: maxWidth, children: composer }) })), children: _jsx(ChatColumn, { maxWidth: maxWidth, children: _jsx(TheoremChatTranscript, { chat: chat, iface: iface, handle: handle, usage: usage }) }) })] }));
125
+ }
126
+ /**
127
+ * The transcript bound to a chat: its blocks as they stream, its gates answered through the chat,
128
+ * and its times on the chat's turn clock, so they agree with `TheoremChatComposer` wherever each
129
+ * is placed.
130
+ */
131
+ export function TheoremChatTranscript({ chat, iface, handle, ...props }) {
132
+ const t = useLabels();
133
+ return (_jsx(ChatTranscript, { ...props, handle: handle ?? t('@theorem.agent.handle', { handle: iface.identity.handle }), blocks: chat.shownBlocks, streaming: chat.streaming, delivery: chat.delivery, answering: chat.answering, clock: chat.turnClock, labels: iface.labels, imageOutput: iface.type === 'image' ? { ratio: parseAspectRatio(iface.image.aspectRatio) } : undefined, onToolDecision: (index, action) => {
134
+ void chat.handleToolDecision(index, action);
135
+ }, onAuthenticated: (index, secret) => {
136
+ void chat.handleAuthenticated(index, secret);
137
+ } }));
132
138
  }
133
139
  function ChatForTransport(props) {
134
140
  const t = useLabels();
@@ -153,5 +159,5 @@ export function TheoremChat({ endpoint, http, transport, theme, mode, labels, de
153
159
  const httpRef = useRef(http);
154
160
  httpRef.current = http;
155
161
  const resolved = useMemo(() => transport ?? createHttpTransport({ ...httpRef.current, endpoint }), [transport, endpoint]);
156
- 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 }) }));
157
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
@@ -29,10 +29,11 @@ export { PaneFailure, PaneLoading, PaneState } from './PaneState.tsx';
29
29
  export { RadialBars, Sunburst, type SunburstNode } from './RadialCharts.tsx';
30
30
  export { type RankedBar, RankedBars } from './RankedBars.tsx';
31
31
  export { InPlace, PaneLayout, PanePanel, Prose, RaisedPane } from './SidePanel.tsx';
32
- export { DEFAULT_CHAT_MAX_WIDTH, TheoremChat, type TheoremChatHandle, type TheoremChatProps, } from './TheoremChat.tsx';
32
+ export { DEFAULT_CHAT_MAX_WIDTH, TheoremChat, TheoremChatComposer, type TheoremChatComposerProps, type TheoremChatHandle, type TheoremChatProps, TheoremChatTranscript, type TheoremChatTranscriptProps, } from './TheoremChat.tsx';
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
@@ -31,10 +31,11 @@ export { PaneFailure, PaneLoading, PaneState } from "./PaneState.js";
31
31
  export { RadialBars, Sunburst } from "./RadialCharts.js";
32
32
  export { RankedBars } from "./RankedBars.js";
33
33
  export { InPlace, PaneLayout, PanePanel, Prose, RaisedPane } from "./SidePanel.js";
34
- export { DEFAULT_CHAT_MAX_WIDTH, TheoremChat, } from "./TheoremChat.js";
34
+ export { DEFAULT_CHAT_MAX_WIDTH, TheoremChat, TheoremChatComposer, TheoremChatTranscript, } from "./TheoremChat.js";
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;