@theoremjs/react 0.3.5-next.985.g0bae771 → 0.3.5-next.986.g09d7a13

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
@@ -567,7 +567,7 @@ function Dock({ chat, iface }) {
567
567
  }
568
568
  ```
569
569
 
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`.
570
+ `TheoremChatComposer` takes `layout`, `icons`, `placeholder`, and `inputRef`. `TheoremChatTranscript` takes the props of `ChatTranscript` that the chat does not give: `handle`, `emptyState`, `dividers`, `usage`, `toolDetail`, and `bodyKindPlacement`. Set `toolDetail={false}` when the people in the chat must not read what a tool ran with and what it returned: each call then shows only its labelled row. 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`.
571
571
 
572
572
  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
573
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/react",
3
- "version": "0.3.5-next.985.g0bae771",
3
+ "version": "0.3.5-next.986.g09d7a13",
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.985.g0bae771",
64
- "@theoremjs/web": "^0.3.5-next.985.g0bae771"
63
+ "@theoremjs/agents": "^0.3.5-next.986.g09d7a13",
64
+ "@theoremjs/web": "^0.3.5-next.986.g09d7a13"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@astryxdesign/core": {
@@ -40,6 +40,12 @@ export type ChatTranscriptProps = {
40
40
  * on an agent tool's call row what the agent it ran used. Off by default.
41
41
  */
42
42
  usage?: boolean;
43
+ /**
44
+ * Show a tool call's detail when its row is opened: what it ran with, the calls its agent made,
45
+ * and what came back. On by default. Off, each call is its labelled row only, for a chat whose
46
+ * people should not read a tool's arguments and results.
47
+ */
48
+ toolDetail?: boolean;
43
49
  /**
44
50
  * Where body kinds sit in a reply. Default puts `citation` last (Sources under
45
51
  * the prose). Pass `{}` to keep stream order for inline citations.
@@ -38,6 +38,12 @@ import { transcriptBlockCopyText } from "./transcript-copy-text.js";
38
38
  import { VoiceNote } from "./VoiceNote.js";
39
39
  /** Whether the transcript shows usage (`ChatTranscriptProps.usage`). */
40
40
  const ShowUsage = createContext(false);
41
+ /** Whether a tool call's row opens on its detail (`ChatTranscriptProps.toolDetail`). */
42
+ const ShowToolDetail = createContext(true);
43
+ /** What the transcript's props say a tool call's row shows. */
44
+ function useToolRowShows() {
45
+ return { usage: useContext(ShowUsage), detail: useContext(ShowToolDetail) };
46
+ }
41
47
  /** Largest a generated image renders in the transcript. */
42
48
  const GENERATED_IMAGE_MAX_WIDTH = 512;
43
49
  function CopyButton({ text }) {
@@ -423,8 +429,8 @@ function toolDetail(t, tool, result) {
423
429
  /** The calls an agent tool's agent made, each a call row of its own. */
424
430
  function ToolSteps({ steps }) {
425
431
  const t = useLabels();
426
- const showUsage = useContext(ShowUsage);
427
- return (_jsxs(VStack, { gap: 2, children: [_jsx(Text, { type: "supporting", color: "secondary", children: t('@theorem.transcript.tool_steps') }), _jsx(ToolCalls, { calls: steps.map((step) => toolCallItem(t, step.operationId ?? step.callId, step, showUsage)) })] }));
432
+ const shows = useToolRowShows();
433
+ return (_jsxs(VStack, { gap: 2, children: [_jsx(Text, { type: "supporting", color: "secondary", children: t('@theorem.transcript.tool_steps') }), _jsx(ToolCalls, { calls: steps.map((step) => toolCallItem(t, step.operationId ?? step.callId, step, shows)) })] }));
428
434
  }
429
435
  /** How long a finished call ran, when both ends were seen. */
430
436
  function toolDuration(t, tool) {
@@ -433,8 +439,8 @@ function toolDuration(t, tool) {
433
439
  return { duration: workDuration(t, tool.endedAt - tool.startedAt) };
434
440
  }
435
441
  /** What the agent an agent tool ran used, after the call's name. Only agent tools report it. */
436
- function toolUsageStats(state, showUsage) {
437
- return showUsage && state.tokens ? { stats: _jsx(Usage, { tokens: state.tokens }) } : {};
442
+ function toolUsageStats(state, shows) {
443
+ return shows.usage && state.tokens ? { stats: _jsx(Usage, { tokens: state.tokens }) } : {};
438
444
  }
439
445
  // why: The row already reads the failure's message, and `error` is the person's wording of the
440
446
  // same failure, so the detail holds only what the row does not say.
@@ -445,7 +451,11 @@ function failureDetail(failure) {
445
451
  ...(failure.details === undefined ? {} : { details: failure.details }),
446
452
  };
447
453
  }
448
- function toolCallItem(t, id, tool, showUsage) {
454
+ /** A call's detail as its row takes it: none when the transcript shows no tool detail. */
455
+ function rowDetail(t, tool, shows, result) {
456
+ return shows.detail ? { resultDetail: toolDetail(t, tool, result) } : {};
457
+ }
458
+ function toolCallItem(t, id, tool, shows) {
449
459
  const base = { key: id, name: toolCallLabel(tool) };
450
460
  const { state } = tool;
451
461
  switch (state?.phase) {
@@ -454,29 +464,29 @@ function toolCallItem(t, id, tool, showUsage) {
454
464
  ...base,
455
465
  status: 'error',
456
466
  target: state.failure.message,
457
- ...toolUsageStats(state, showUsage),
467
+ ...toolUsageStats(state, shows),
458
468
  errorMessage: state.failure.message,
459
- resultDetail: toolDetail(t, tool, _jsx(ShapedData, { value: failureDetail(state.failure), title: t('@theorem.transcript.tool_error') })),
469
+ ...rowDetail(t, tool, shows, _jsx(ShapedData, { value: failureDetail(state.failure), title: t('@theorem.transcript.tool_error') })),
460
470
  };
461
471
  case 'complete':
462
472
  return {
463
473
  ...base,
464
474
  status: 'complete',
465
475
  ...toolDuration(t, tool),
466
- ...toolUsageStats(state, showUsage),
467
- resultDetail: toolDetail(t, tool, state.output === undefined ? undefined : (_jsx(ShapedData, { value: state.output, title: t('@theorem.transcript.tool_output') }))),
476
+ ...toolUsageStats(state, shows),
477
+ ...rowDetail(t, tool, shows, state.output === undefined ? undefined : (_jsx(ShapedData, { value: state.output, title: t('@theorem.transcript.tool_output') }))),
468
478
  };
469
479
  case 'running':
470
480
  case 'background':
471
- return { ...base, status: 'running', resultDetail: toolDetail(t, tool) };
481
+ return { ...base, status: 'running', ...rowDetail(t, tool, shows) };
472
482
  default:
473
- return { ...base, status: 'pending', resultDetail: toolDetail(t, tool) };
483
+ return { ...base, status: 'pending', ...rowDetail(t, tool, shows) };
474
484
  }
475
485
  }
476
486
  function ToolCall({ tool }) {
477
487
  const t = useLabels();
478
- const showUsage = useContext(ShowUsage);
479
- return _jsx(ToolCalls, { calls: [toolCallItem(t, tool.name, tool, showUsage)] });
488
+ const shows = useToolRowShows();
489
+ return _jsx(ToolCalls, { calls: [toolCallItem(t, tool.name, tool, shows)] });
480
490
  }
481
491
  /**
482
492
  * Thinking reads as quieter text than the reply. Astryx has no reasoning
@@ -494,7 +504,7 @@ const THOUGHT_TEXT = {
494
504
  };
495
505
  function TraceList({ items, streaming }) {
496
506
  const t = useLabels();
497
- const showUsage = useContext(ShowUsage);
507
+ const shows = useToolRowShows();
498
508
  const rows = [];
499
509
  let tools = [];
500
510
  const flush = () => {
@@ -505,7 +515,7 @@ function TraceList({ items, streaming }) {
505
515
  };
506
516
  for (const [i, item] of items.entries()) {
507
517
  if (item.kind === 'tool') {
508
- tools.push(toolCallItem(t, item.id, item.block.tool, showUsage));
518
+ tools.push(toolCallItem(t, item.id, item.block.tool, shows));
509
519
  continue;
510
520
  }
511
521
  flush();
@@ -625,7 +635,7 @@ function isBareFailure(group) {
625
635
  }
626
636
  /** Theorem transcript blocks rendered as Astryx chat messages. */
627
637
  export function ChatTranscript(props) {
628
- return (_jsx(TheoremLabelsProvider, { children: _jsx(ShowUsage.Provider, { value: props.usage === true, children: _jsx(ChatTranscriptBody, { ...props }) }) }));
638
+ return (_jsx(TheoremLabelsProvider, { children: _jsx(ShowUsage.Provider, { value: props.usage === true, children: _jsx(ShowToolDetail.Provider, { value: props.toolDetail !== false, children: _jsx(ChatTranscriptBody, { ...props }) }) }) }));
629
639
  }
630
640
  function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToolDecision, answering = null, onAuthenticated, emptyState, dividers, imageOutput, bodyKindPlacement, labels, clock, }) {
631
641
  const groups = useMemo(() => groupTranscriptBlocks(blocks, dividers && new Set(Object.keys(dividers))), [blocks, dividers]);
@@ -90,6 +90,11 @@ export type TheoremChatProps = {
90
90
  * on an agent tool's call row what the agent it ran used. Off by default.
91
91
  */
92
92
  usage?: boolean;
93
+ /**
94
+ * Show a tool call's detail when its row is opened: what it ran with, the calls its agent made,
95
+ * and what came back. On by default. Off, each call is its labelled row only.
96
+ */
97
+ toolDetail?: boolean;
93
98
  className?: string;
94
99
  style?: React.CSSProperties;
95
100
  /**
package/ui/TheoremChat.js CHANGED
@@ -75,7 +75,7 @@ function ChatBodyComposer({ hasComposer, ...props }) {
75
75
  const failure = props.chat.failure;
76
76
  return failure ? _jsx(Banner, { status: "error", role: "alert", title: failure.error }) : null;
77
77
  }
78
- function ChatBody({ transport, iface, placeholder, emptyState, density, maxWidth = DEFAULT_CHAT_MAX_WIDTH, scrollRef, trace, usage, className, style, conversation, conversationView, initialText, initialFiles, initialVoice, initialPending, onConversationChange, chatRef, composer: hasComposer = true, composerLayout, composerIcons, options, onOptionsChange, stated, context, pageTools, onTurnEvent, }) {
78
+ function ChatBody({ transport, iface, placeholder, emptyState, density, maxWidth = DEFAULT_CHAT_MAX_WIDTH, scrollRef, trace, usage, toolDetail, className, style, conversation, conversationView, initialText, initialFiles, initialVoice, initialPending, onConversationChange, chatRef, composer: hasComposer = true, composerLayout, composerIcons, options, onOptionsChange, stated, context, pageTools, onTurnEvent, }) {
79
79
  const t = useLabels();
80
80
  const chat = useTheoremChat({
81
81
  transport,
@@ -102,7 +102,7 @@ function ChatBody({ transport, iface, placeholder, emptyState, density, maxWidth
102
102
  const header = _jsx(SidePanelHeader, { floating: true, children: inspector.toggle });
103
103
  const composer = (_jsx(ChatBodyComposer, { hasComposer: hasComposer, chat: chat, iface: iface, placeholder: placeholder, inputRef: inputRef, layout: composerLayout, icons: composerIcons }));
104
104
  const docked = { composer, composerRef, maxWidth };
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 })) }) }) }));
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, toolDetail: toolDetail })) }) }) }));
106
106
  }
107
107
  const CHAT_SCROLL = { overscrollBehavior: 'none' };
108
108
  /**
@@ -118,10 +118,10 @@ function ChatLanding({ composer, composerRef, maxWidth, handle, emptyState, }) {
118
118
  * why: the dock leaves 12px under the composer; paddingBlockEnd={3} adds 12px more for a 24px
119
119
  * bottom margin.
120
120
  */
121
- function ChatThread({ composer, composerRef, maxWidth, chat, iface, handle, density, scrollRef, usage, }) {
121
+ function ChatThread({ composer, composerRef, maxWidth, chat, iface, handle, density, scrollRef, usage, toolDetail, }) {
122
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,
123
123
  // why: Scrolling past either end does not bounce the transcript and its docked composer.
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 }) }) })] }));
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, toolDetail: toolDetail }) }) })] }));
125
125
  }
126
126
  /**
127
127
  * The transcript bound to a chat: its blocks as they stream, its gates answered through the chat,