@theoremjs/react 0.3.5-next.1044.gd446ce7 → 0.3.5-next.1045.gcc305fe

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,7 +180,8 @@ To draw your own figures like the trace panel does, `@theoremjs/react/ui` also e
180
180
  | `composerLayout` | `'stacked'` or `'row'`. In `'row'`, the field, the mic and send share one line, and text that wraps moves the field onto its own line. Above them, a pill shows the reply in progress, with its stop button, and a pill shows each background call. While a reply runs or a step waits, Enter queues a draft and send opens the send menu. Default: `'stacked'`. |
181
181
  | `composerEmptyAction` | Shows in place of the send button while the composer has nothing to send, for example a button that starts a call. It never replaces stop or the send menu. `TheoremChatComposer` and `ChatComposerBar` take it as `emptyAction`. Default: the send button. |
182
182
  | `renderComposerStatus` | Draws the composer's problem: a send that failed (`type: 'error'`), or files or a voice note it could not take (`type: 'warning'`), with its `message`. Give what you draw its own `role`: `alert` for an error, `status` for a warning. `TheoremChatComposer` and `ChatComposerBar` take it as `renderStatus`. Default: in `'row'`, Theorem's card over the surface (see [The row composer's look](#the-row-composers-look)); in `'stacked'`, Astryx's status, in the status colour. |
183
- | `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). |
183
+ | `renderComposerPillWords` | Draws the words of the working pill and of each background call's pill in the `'row'` composer, from `{ pill, words }`. `pill` is `'working'` or `'background'`. The pill keeps its words for screen readers. `TheoremChatComposer` and `ChatComposerBar` take it as `renderPillWords`. Default: Theorem's words. |
184
+ | `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; `null` draws none. See [The row composer's look](#the-row-composers-look). |
184
185
  | `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). |
185
186
  | `resolveMedia` | Turns a tool's reference into an address the page can load. See [Tool media](#tool-media). |
186
187
  | `mediaViewer` | The viewer every picture and video opens in. Default: Astryx's Lightbox, with zoom. See [Your own media viewer](#your-own-media-viewer). |
@@ -745,7 +746,7 @@ function Dock({ chat, iface }) {
745
746
  }
746
747
  ```
747
748
 
748
- `TheoremChatComposer` takes `layout`, `icons`, `pills`, `placeholder`, `inputRef`, `inputComponent`, `triggers`, `refText`, `renderRef`, `emptyAction`, and `renderStatus`. Pass it the `refText` you gave `useTheoremChat`. `TheoremChatTranscript` takes the props of `ChatTranscript` that the chat does not give: `handle`, `emptyState`, `dividers`, `usage`, `bodyKindPlacement`, `stepLayout`, `showToolDurations`, `toolFailureReasonKinds`, `showWorkStatus`, `showResumedNotice`, `nameAppears`, `renderRef`, `turnKeyOf`, `turnTimeOf`, and `slots`. 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`.
749
+ `TheoremChatComposer` takes `layout`, `icons`, `pills`, `placeholder`, `inputRef`, `inputComponent`, `triggers`, `refText`, `renderRef`, `emptyAction`, `renderStatus`, and `renderPillWords`. Pass it the `refText` you gave `useTheoremChat`. `TheoremChatTranscript` takes the props of `ChatTranscript` that the chat does not give: `handle`, `emptyState`, `dividers`, `usage`, `bodyKindPlacement`, `stepLayout`, `showToolDurations`, `toolFailureReasonKinds`, `showWorkStatus`, `showResumedNotice`, `nameAppears`, `renderRef`, `turnKeyOf`, `turnTimeOf`, and `slots`. 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`.
749
750
 
750
751
  Use `pills` to show your own notice in the pill row of the `row` layout, for example "New from your agent" while the chat is closed. Each pill is `{ id, label, icon?, onSelect? }`. It comes after the working pill and the background calls, and looks like them. The icon goes before the words. A click calls `onSelect`. A pill without `onSelect` only shows.
751
752
 
@@ -862,6 +863,28 @@ These rules apply:
862
863
  - A reply on its way has no details row yet.
863
864
  - Without `slots.details`, the row is unchanged. Without `turnKeyOf`, messages join as before.
864
865
 
866
+ ### Draw the name, the calls, and the words yourself
867
+
868
+ Three more `slots` stand in for parts the transcript draws. Use them to change how a part looks or moves. Each one you leave out keeps the transcript's own.
869
+
870
+ | Slot | Stands in for | Receives |
871
+ | --- | --- | --- |
872
+ | `name` | A reply's name, where the name shows (`nameAppears`). | `{ handle, streaming }` |
873
+ | `toolCalls` | Each list of tool calls: in a reply, in its trace, and in an agent call's detail. | `{ list, streaming }`. `list` is what the transcript gives Astryx's `ChatToolCalls`. |
874
+ | `markdown` | The Markdown of a reply's words and thoughts. | What the transcript gives Astryx's `Markdown`, its `children` and `isStreaming` among them. |
875
+
876
+ `streaming` is `true` while the reply is on its way. A call's `key` is its operation id, or its call id. It stays the same from the live reply to the saved one.
877
+
878
+ ```tsx
879
+ <ChatTranscript
880
+ blocks={blocks}
881
+ handle="Harbor"
882
+ slots={{
883
+ toolCalls: ({ list }) => <ChatToolCalls {...list} isDefaultExpanded />,
884
+ }}
885
+ />;
886
+ ```
887
+
865
888
  ### Date messages by your own record
866
889
 
867
890
  A reply is dated from its end, and any other message from when the page first showed it. To date messages by your own record, pass `turnTimeOf`: it takes a block's `host` value and returns when the block was written, in milliseconds since the epoch, or `undefined`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/react",
3
- "version": "0.3.5-next.1044.gd446ce7",
3
+ "version": "0.3.5-next.1045.gcc305fe",
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.1044.gd446ce7",
64
- "@theoremjs/web": "^0.3.5-next.1044.gd446ce7"
63
+ "@theoremjs/agents": "^0.3.5-next.1045.gcc305fe",
64
+ "@theoremjs/web": "^0.3.5-next.1045.gcc305fe"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@astryxdesign/core": {
@@ -4,7 +4,7 @@ import { type AttachmentValidationIssue, type ComposerMenuAction, type ComposerP
4
4
  import type { ClientFailure } from '@theoremjs/web/client';
5
5
  import { type ComponentProps, type ComponentType, type ReactNode } from 'react';
6
6
  import type { BackgroundJob } from '../client/transcript-groups.js';
7
- import { type ComposerPill, type ComposerRowIcons } from './ChatComposerRow.js';
7
+ import { type ComposerPill, type ComposerPillWords, type ComposerRowIcons } from './ChatComposerRow.js';
8
8
  /** An option the profile declares: its allowed values, the one chosen, and how to choose another. */
9
9
  /** The effort selector's icon. The studio's Agents list shows the same one. */
10
10
  export declare const EFFORT_ICON: import("react").ForwardRefExoticComponent<import("@tabler/icons-react").IconProps & import("react").RefAttributes<SVGSVGElement>>;
@@ -99,6 +99,11 @@ export type ChatComposerBarProps = {
99
99
  * a warning. Omit to keep Theorem's: in `row`, a card over the surface; in `stacked`, Astryx's.
100
100
  */
101
101
  renderStatus?: (status: ChatComposerStatus) => ReactNode;
102
+ /**
103
+ * Draws the words of the working pill and of each background job's, in the `row` layout. The
104
+ * pill keeps its words for screen readers. Omit to keep Theorem's.
105
+ */
106
+ renderPillWords?: (said: ComposerPillWords) => ReactNode;
102
107
  };
103
108
  /** A Live call's text line: it is sent as typed, so there is nothing to attach, queue, or stop. */
104
109
  export type LiveComposerBarProps = Omit<Pick<ChatComposerBarProps, 'draftText' | 'placeholder' | 'inputRef' | 'inputComponent' | 'triggers' | 'draftParts' | 'onDraftPartsChange' | 'refText' | 'renderRef' | 'onDraftTextChange' | 'onSubmit' | 'emptyAction'>, 'onSubmit'> & {
@@ -448,7 +448,7 @@ function RowComposerBar({ props, parts, }) {
448
448
  // why: Stop lives on the working pill, so the button only sends; while a reply runs or a
449
449
  // step waits, a draft opens the send menu instead (Enter still queues).
450
450
  const opensMenu = props.phase !== 'idle' && parts.menuActions.length > 0;
451
- return (_jsx(ChatComposerRow, { isWorking: props.phase === 'streaming', workingSince: props.workingSince, icons: props.icons, backgroundJobs: props.backgroundJobs ?? [], pills: props.pills, onStop: props.onStop, hint: parts.hintNode, tray: parts.tray, attach: parts.attach, input: parts.input, editorRef: parts.editorRef, draftText: props.draftText, controls: parts.controls, record: parts.record, action: props.emptyAction !== undefined &&
451
+ return (_jsx(ChatComposerRow, { isWorking: props.phase === 'streaming', workingSince: props.workingSince, icons: props.icons, backgroundJobs: props.backgroundJobs ?? [], pills: props.pills, renderPillWords: props.renderPillWords, onStop: props.onStop, hint: parts.hintNode, tray: parts.tray, attach: parts.attach, input: parts.input, editorRef: parts.editorRef, draftText: props.draftText, controls: parts.controls, record: parts.record, action: props.emptyAction !== undefined &&
452
452
  composerShowsEmptyAction({
453
453
  hasPayload: parts.hasPayload,
454
454
  primary: parts.primary,
@@ -2,7 +2,7 @@ import type { ChatComposerStatus } from '@astryxdesign/core/Chat';
2
2
  import { type ReactNode, type RefObject } from 'react';
3
3
  import type { BackgroundJob } from '../client/transcript-groups.js';
4
4
  /**
5
- * The glyphs the row composer draws. Each one left out keeps Theorem's.
5
+ * The glyphs the row composer draws. Each one left out keeps Theorem's; `null` draws none.
6
6
  * Text is in the labels (`@theorem.composer.pill.*`, `@theorem.composer.tray.*`); sizes, colours,
7
7
  * radii and spacing are the `--theorem-composer-*` CSS properties.
8
8
  */
@@ -14,6 +14,12 @@ export type ComposerRowIcons = {
14
14
  /** In the working pill's stop button. Default: a filled square. */
15
15
  stop?: ReactNode;
16
16
  };
17
+ /** The words of one of Theorem's pills, as `renderPillWords` is given them. */
18
+ export type ComposerPillWords = {
19
+ /** Whose words: the working pill's, or a background job's. */
20
+ pill: 'working' | 'background';
21
+ words: string;
22
+ };
17
23
  /**
18
24
  * A pill the app puts in the pill row after Theorem's own, drawn as they are: its icon, its words,
19
25
  * and what a click does. One without `icon` has words only; one without `onSelect` only shows.
@@ -40,6 +46,8 @@ export type ComposerRowParts = {
40
46
  backgroundJobs: readonly BackgroundJob[];
41
47
  /** The app's own pills, after the background jobs. */
42
48
  pills?: readonly ComposerPill[];
49
+ /** Draws the words of the working pill and of each background job's. */
50
+ renderPillWords?: (said: ComposerPillWords) => ReactNode;
43
51
  onStop: () => void;
44
52
  /** Contextual hint, at the end of the pill row. */
45
53
  hint?: ReactNode;
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Badge } from '@astryxdesign/core/Badge';
3
3
  import { Card } from '@astryxdesign/core/Card';
4
4
  import { useCollapsible } from '@astryxdesign/core/Collapsible';
@@ -15,6 +15,20 @@ import { useId, useLayoutEffect, useState, } from 'react';
15
15
  import { useSecondTicker } from "../hooks/use-second-ticker.js";
16
16
  import { liveDuration, toolNameLabel } from "./labels.js";
17
17
  import { useLabels } from "./labels-provider.js";
18
+ /** The words of a pill the app draws, and the pill's own label for screen readers. */
19
+ function pillWords(said, render, after) {
20
+ if (!render)
21
+ return { label: said.words, endContent: after };
22
+ return {
23
+ label: said.words,
24
+ isLabelHidden: true,
25
+ endContent: (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", children: render(said) }), after] })),
26
+ };
27
+ }
28
+ /** An icon the host left out is Theorem's; `null` is none. */
29
+ function pillIcon(icon, fallback) {
30
+ return icon === undefined ? fallback : icon;
31
+ }
18
32
  /**
19
33
  * A `--theorem-composer-*` property, or Theorem's value when the page sets none.
20
34
  * why: Inline styles beat Astryx's own, so every look the row has goes through one of these and
@@ -93,14 +107,14 @@ const TRAY_CONTENT = {
93
107
  * why: It counts from the chat's turn clock, the one the transcript's status line reads, so the
94
108
  * two agree and a wait on approval does not count.
95
109
  */
96
- function WorkingPill({ since, icons, onStop, }) {
110
+ function WorkingPill({ since, icons, renderPillWords, onStop, }) {
97
111
  const t = useLabels();
98
112
  const now = useSecondTicker(since !== undefined);
99
113
  const stop = t('@theorem.composer.pill.stop');
100
114
  const label = since === undefined
101
115
  ? t('@theorem.composer.pill.working')
102
116
  : t('@theorem.composer.pill.working_for', { duration: liveDuration(t, now - since) });
103
- return (_jsx(Token, { size: "lg", className: "theorem-composer-pill", "data-pill": "working", style: WORKING_PILL, label: label, icon: icons?.working ?? _jsx(Spinner, { size: "sm", shade: "inherit", "aria-label": label }), endContent: _jsx(IconButton, { label: stop, tooltip: stop, size: "sm", variant: "secondary", icon: icons?.stop ?? _jsx(IconPlayerStopFilled, { size: 12 }), onClick: onStop }) }));
117
+ return (_jsx(Token, { size: "lg", className: "theorem-composer-pill", "data-pill": "working", style: WORKING_PILL, ...pillWords({ pill: 'working', words: label }, renderPillWords, _jsx(IconButton, { label: stop, tooltip: stop, size: "sm", variant: "secondary", icon: icons?.stop ?? _jsx(IconPlayerStopFilled, { size: 12 }), onClick: onStop })), icon: pillIcon(icons?.working, _jsx(Spinner, { size: "sm", shade: "inherit", "aria-label": label })) }));
104
118
  }
105
119
  /**
106
120
  * The pill row. One pill sits centred over the composer (see `pill-align`); with more, the working
@@ -109,10 +123,13 @@ function WorkingPill({ since, icons, onStop, }) {
109
123
  function PillRow(props) {
110
124
  const t = useLabels();
111
125
  const pills = [
112
- props.isWorking ? (_jsx(WorkingPill, { since: props.workingSince, icons: props.icons, onStop: props.onStop }, "working")) : null,
113
- ...props.backgroundJobs.map((job) => (_jsx(Token, { size: "lg", className: "theorem-composer-pill", "data-pill": "background", style: PILL, label: job.unlabelledTool === undefined
114
- ? job.label
115
- : toolNameLabel(t, job.unlabelledTool, job.label), description: t('@theorem.composer.pill.background'), icon: props.icons?.backgroundJob ?? (_jsx(Spinner, { size: "sm", shade: "inherit", "aria-label": t('@theorem.composer.pill.background') })) }, job.callId))),
126
+ props.isWorking ? (_jsx(WorkingPill, { since: props.workingSince, icons: props.icons, renderPillWords: props.renderPillWords, onStop: props.onStop }, "working")) : null,
127
+ ...props.backgroundJobs.map((job) => (_jsx(Token, { size: "lg", className: "theorem-composer-pill", "data-pill": "background", style: PILL, ...pillWords({
128
+ pill: 'background',
129
+ words: job.unlabelledTool === undefined
130
+ ? job.label
131
+ : toolNameLabel(t, job.unlabelledTool, job.label),
132
+ }, props.renderPillWords), description: t('@theorem.composer.pill.background'), icon: pillIcon(props.icons?.backgroundJob, _jsx(Spinner, { size: "sm", shade: "inherit", "aria-label": t('@theorem.composer.pill.background') })) }, job.callId))),
116
133
  ...(props.pills ?? []).map((pill) => (_jsx(Token, { size: "lg", className: "theorem-composer-pill", "data-pill": "app", style: PILL, label: pill.label, icon: pill.icon, onClick: pill.onSelect }, pill.id))),
117
134
  ].filter(Boolean);
118
135
  if (pills.length === 0 && !props.hint)
@@ -216,5 +233,5 @@ function RowStatus({ status, renderStatus }) {
216
233
  */
217
234
  export function ChatComposerRow(props) {
218
235
  const stacked = useWrapped(props.editorRef, props.draftText);
219
- return (_jsxs(VStack, { gap: 0, width: "100%", className: "theorem-composer-row", style: { gap: GAP }, children: [_jsx(PillRow, { isWorking: props.isWorking, workingSince: props.workingSince, icons: props.icons, backgroundJobs: props.backgroundJobs, pills: props.pills, onStop: props.onStop, hint: props.hint }), props.tray ? _jsx(RowTray, { tray: props.tray }) : null, _jsx(RowStatus, { status: props.status, renderStatus: props.renderStatus }), _jsx(RowSurface, { stacked: stacked, attach: props.attach, input: props.input, controls: props.controls, record: props.record, action: props.action })] }));
236
+ return (_jsxs(VStack, { gap: 0, width: "100%", className: "theorem-composer-row", style: { gap: GAP }, children: [_jsx(PillRow, { isWorking: props.isWorking, workingSince: props.workingSince, icons: props.icons, backgroundJobs: props.backgroundJobs, pills: props.pills, renderPillWords: props.renderPillWords, onStop: props.onStop, hint: props.hint }), props.tray ? _jsx(RowTray, { tray: props.tray }) : null, _jsx(RowStatus, { status: props.status, renderStatus: props.renderStatus }), _jsx(RowSurface, { stacked: stacked, attach: props.attach, input: props.input, controls: props.controls, record: props.record, action: props.action })] }));
220
237
  }
@@ -50,6 +50,10 @@ const ShowWorkStatus = createContext(true);
50
50
  const ShowResumedNotice = createContext(true);
51
51
  /** When a reply shows its name (`ChatTranscriptProps.nameAppears`). */
52
52
  const NameTiming = createContext('at-start');
53
+ /** The app's stand-ins for what the transcript draws (`ChatTranscriptProps.slots`). */
54
+ const AppSlots = createContext({});
55
+ /** Whether the reply being drawn is on its way. */
56
+ const ReplyStreaming = createContext(false);
53
57
  /** What the app draws under each reply (`ChatTranscriptProps.slots.reply`). */
54
58
  const ReplySlot = createContext(undefined);
55
59
  /** What the app draws in each message's details (`ChatTranscriptProps.slots.details`). */
@@ -465,7 +469,9 @@ function Sources({ citations }) {
465
469
  */
466
470
  function StreamedMarkdown({ text, streaming, density, components, }) {
467
471
  const plugins = useMarkdownPlugins();
468
- return (_jsx(Markdown, { isStreaming: streaming, density: density, components: components, plugins: plugins, children: text }));
472
+ const draw = useContext(AppSlots).markdown;
473
+ const markdown = { isStreaming: streaming, density, components, plugins, children: text };
474
+ return draw ? draw(markdown) : _jsx(Markdown, { ...markdown });
469
475
  }
470
476
  function BodyBlock({ block, streaming }) {
471
477
  if (block.kind === 'text')
@@ -496,7 +502,10 @@ function ResultBlock({ block }) {
496
502
  // whole tool call (row and expanded detail) uses the body font instead.
497
503
  const CODE_FONT_AS_BODY = { '--font-family-code': 'var(--font-family-body)' };
498
504
  function ToolCalls({ calls }) {
499
- return _jsx(ChatToolCalls, { calls: calls, style: CODE_FONT_AS_BODY });
505
+ const draw = useContext(AppSlots).toolCalls;
506
+ const streaming = useContext(ReplyStreaming);
507
+ const list = { calls, style: CODE_FONT_AS_BODY };
508
+ return draw ? draw({ list, streaming }) : _jsx(ChatToolCalls, { ...list });
500
509
  }
501
510
  /** A call's detail: what it ran with, then what came back. */
502
511
  function toolDetail(t, tool, result) {
@@ -507,7 +516,7 @@ function toolDetail(t, tool, result) {
507
516
  function ToolSteps({ steps }) {
508
517
  const t = useLabels();
509
518
  const shows = useToolRowShows();
510
- 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)) })] }));
519
+ 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, shows)) })] }));
511
520
  }
512
521
  /** How long a finished call ran, when the transcript shows it and both ends were seen. */
513
522
  function toolDuration(t, tool, shows) {
@@ -548,8 +557,12 @@ function failedToolItem(t, base, tool, state, shows) {
548
557
  ...rowDetail(t, tool, shows, _jsx(ShapedData, { value: failureDetail(state.failure), title: t('@theorem.transcript.tool_error') })),
549
558
  };
550
559
  }
551
- function toolCallItem(t, id, tool, shows) {
552
- const base = { key: id, name: toolCallLabel(tool, (name) => toolNameLabel(t, name)) };
560
+ function toolCallItem(t, tool, shows) {
561
+ // why: Not the block id: the saved reply re-mints those, and a row would be drawn anew.
562
+ const base = {
563
+ key: tool.operationId ?? tool.callId,
564
+ name: toolCallLabel(tool, (name) => toolNameLabel(t, name)),
565
+ };
553
566
  const { state } = tool;
554
567
  switch (state?.phase) {
555
568
  case 'error':
@@ -580,7 +593,7 @@ function toolCallItem(t, id, tool, shows) {
580
593
  function ToolRun({ blocks }) {
581
594
  const t = useLabels();
582
595
  const shows = useToolRowShows();
583
- return _jsx(ToolCalls, { calls: blocks.map((block) => toolCallItem(t, block.id, block.tool, shows)) });
596
+ return _jsx(ToolCalls, { calls: blocks.map((block) => toolCallItem(t, block.tool, shows)) });
584
597
  }
585
598
  /**
586
599
  * Thinking reads as quieter text than the reply. Astryx has no reasoning
@@ -618,7 +631,7 @@ function TraceList({ items, streaming }) {
618
631
  };
619
632
  for (const [i, item] of items.entries()) {
620
633
  if (item.kind === 'tool') {
621
- tools.push(toolCallItem(t, item.id, item.block.tool, shows));
634
+ tools.push(toolCallItem(t, item.block.tool, shows));
622
635
  continue;
623
636
  }
624
637
  flush();
@@ -723,6 +736,7 @@ function useNameShown(reply) {
723
736
  function AssistantTurn(props) {
724
737
  const t = useLabels();
725
738
  const replySlot = useContext(ReplySlot);
739
+ const drawName = useContext(AppSlots).name;
726
740
  const chrome = useChromeReveal(props.isNewest === true);
727
741
  const showUsage = useContext(ShowUsage);
728
742
  const showResumed = useContext(ShowResumedNotice);
@@ -752,12 +766,18 @@ function AssistantTurn(props) {
752
766
  rows,
753
767
  imageOutput: props.imageOutput,
754
768
  });
755
- return (_jsx(ChatMessage, { sender: "assistant", name: named ? props.handle : undefined, ...chrome.handlers, metadata: props.streaming ? undefined : (_jsx(MessageChrome, { sender: "assistant", blocks: props.blocks, host: props.host ?? [], at: props.at, copyText: copyText, error: props.error, stopped: props.stopped, resumed: resumed, usage: showUsage ? props.usage : undefined, revealed: chrome.revealed })), children: _jsxs(VStack, { gap: 3, width: "100%", children: [_jsx(TurnStatus, { status: status, trace: trace, hasTrace: hasTrace, streaming: props.streaming }), gatedTools.map((block) => (_jsx(GateCard, { block: block, handle: props.handle, handlers: props.handlers }, block.id))), keyedByContent(rows, (row) => row.kind === 'gallery' || row.kind === 'sources' || row.kind === 'tools'
756
- ? row.kind
757
- : row.block.kind).map(({ item: row, index: i, key }) => (_jsx(BodyRowView
758
- // why: Not the block id: the committed turn re-mints ids, and a
759
- // remount would cut the text reveal short.
760
- , { row: row, streaming: props.streaming && i === rows.length - 1, imageOutput: props.imageOutput }, key))), _jsx(PendingImage, { imageOutput: props.imageOutput, streaming: props.streaming, rows: rows }), replySlot?.({ blocks: props.blocks, host: props.host ?? [], streaming: props.streaming })] }) }));
769
+ return (_jsx(ChatMessage, { sender: "assistant", name: named
770
+ ? (drawName?.({ handle: props.handle, streaming: props.streaming }) ?? props.handle)
771
+ : undefined, ...chrome.handlers, metadata: props.streaming ? undefined : (_jsx(MessageChrome, { sender: "assistant", blocks: props.blocks, host: props.host ?? [], at: props.at, copyText: copyText, error: props.error, stopped: props.stopped, resumed: resumed, usage: showUsage ? props.usage : undefined, revealed: chrome.revealed })), children: _jsx(ReplyStreaming.Provider, { value: props.streaming, children: _jsxs(VStack, { gap: 3, width: "100%", children: [_jsx(TurnStatus, { status: status, trace: trace, hasTrace: hasTrace, streaming: props.streaming }), gatedTools.map((block) => (_jsx(GateCard, { block: block, handle: props.handle, handlers: props.handlers }, block.id))), keyedByContent(rows, (row) => row.kind === 'gallery' || row.kind === 'sources' || row.kind === 'tools'
772
+ ? row.kind
773
+ : row.block.kind).map(({ item: row, index: i, key }) => (_jsx(BodyRowView
774
+ // why: Not the block id: the committed turn re-mints ids, and a
775
+ // remount would cut the text reveal short.
776
+ , { row: row, streaming: props.streaming && i === rows.length - 1, imageOutput: props.imageOutput }, key))), _jsx(PendingImage, { imageOutput: props.imageOutput, streaming: props.streaming, rows: rows }), replySlot?.({
777
+ blocks: props.blocks,
778
+ host: props.host ?? [],
779
+ streaming: props.streaming,
780
+ })] }) }) }));
761
781
  }
762
782
  /** The notice of a reply that went on after its model call failed part-way, if it did. */
763
783
  function resumedNotice(blocks) {
@@ -801,7 +821,7 @@ export function ChatTranscript(props) {
801
821
  const turnKeyOf = keyOf ? (host) => keyOf(host) : undefined;
802
822
  const dateOf = props.turnTimeOf;
803
823
  const turnTimeOf = dateOf ? (host) => dateOf(host) : undefined;
804
- return (_jsx(TheoremLabelsProvider, { children: _jsx(ReplySlot.Provider, { value: replySlot, children: _jsx(DetailsSlot.Provider, { value: detailsSlot, children: _jsx(ShowUsage.Provider, { value: props.usage === true, children: _jsx(RenderRef.Provider, { value: props.renderRef, children: _jsx(ShowToolData.Provider, { value: props.showToolData !== false, children: _jsx(ShowToolDurations.Provider, { value: props.showToolDurations !== false, children: _jsx(ToolFailureReasonKinds.Provider, { value: props.toolFailureReasonKinds, children: _jsx(ShowWorkStatus.Provider, { value: props.showWorkStatus !== false, children: _jsx(ShowResumedNotice.Provider, { value: props.showResumedNotice !== false, children: _jsx(NameTiming.Provider, { value: props.nameAppears ?? 'at-start', children: _jsx(ChatTranscriptBody, { ...props, turnKeyOf: turnKeyOf, turnTimeOf: turnTimeOf }) }) }) }) }) }) }) }) }) }) }) }));
824
+ return (_jsx(TheoremLabelsProvider, { children: _jsx(AppSlots.Provider, { value: props.slots ?? {}, children: _jsx(ReplySlot.Provider, { value: replySlot, children: _jsx(DetailsSlot.Provider, { value: detailsSlot, children: _jsx(ShowUsage.Provider, { value: props.usage === true, children: _jsx(RenderRef.Provider, { value: props.renderRef, children: _jsx(ShowToolData.Provider, { value: props.showToolData !== false, children: _jsx(ShowToolDurations.Provider, { value: props.showToolDurations !== false, children: _jsx(ToolFailureReasonKinds.Provider, { value: props.toolFailureReasonKinds, children: _jsx(ShowWorkStatus.Provider, { value: props.showWorkStatus !== false, children: _jsx(ShowResumedNotice.Provider, { value: props.showResumedNotice !== false, children: _jsx(NameTiming.Provider, { value: props.nameAppears ?? 'at-start', children: _jsx(ChatTranscriptBody, { ...props, turnKeyOf: turnKeyOf, turnTimeOf: turnTimeOf }) }) }) }) }) }) }) }) }) }) }) }) }));
805
825
  }
806
826
  function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToolDecision, answering = null, onAuthenticated, emptyState, dividers, imageOutput, bodyKindPlacement, stepLayout, labels, clock, turnKeyOf, turnTimeOf, }) {
807
827
  const groups = useMemo(() => groupTranscriptBlocks(blocks, dividers && new Set(Object.keys(dividers)), turnKeyOf), [blocks, dividers, turnKeyOf]);
@@ -9,7 +9,7 @@ import { type ReactNode, type Ref } from 'react';
9
9
  import { type SendTextOptions, type SentTurn, type TheoremChatState, type UseTheoremChatOptions } from '../hooks/use-theorem-chat.js';
10
10
  import type { ComposerInputComponent } from './ChatComposerBar.js';
11
11
  import { type ComposerLayout } from './ChatComposerBar.js';
12
- import type { ComposerPill, ComposerRowIcons } from './ChatComposerRow.js';
12
+ import type { ComposerPill, ComposerPillWords, ComposerRowIcons } from './ChatComposerRow.js';
13
13
  import { type ChatTranscriptProps } from './ChatTranscript.js';
14
14
  import type { TheoremLabels } from './labels.js';
15
15
  import type { MediaViewer } from './media-viewer.js';
@@ -162,6 +162,8 @@ export type TheoremChatProps<Host extends JsonObject = JsonObject> = {
162
162
  composerEmptyAction?: ReactNode;
163
163
  /** Draws the composer's problem in place of Theorem's; see `ChatComposerBarProps.renderStatus`. */
164
164
  renderComposerStatus?: (status: ChatComposerStatus) => ReactNode;
165
+ /** Draws the words of the composer's pills; see `ChatComposerBarProps.renderPillWords`. */
166
+ renderComposerPillWords?: (said: ComposerPillWords) => ReactNode;
165
167
  /**
166
168
  * The transcript's own options, given to {@link TheoremChatTranscript} as they are: its `slots`,
167
169
  * such as the `reply` slot, its `turnKeyOf`, and how it lays out a reply. `Host` is the type of
@@ -220,13 +222,15 @@ export type TheoremChatComposerProps = {
220
222
  emptyAction?: ReactNode;
221
223
  /** Draws the composer's problem in place of Theorem's; see `ChatComposerBarProps.renderStatus`. */
222
224
  renderStatus?: (status: ChatComposerStatus) => ReactNode;
225
+ /** Draws the words of the composer's pills; see `ChatComposerBarProps.renderPillWords`. */
226
+ renderPillWords?: (said: ComposerPillWords) => ReactNode;
223
227
  };
224
228
  /**
225
229
  * The composer bound to a chat: drafts, files, voice, the pending queue, send and stop, and the
226
230
  * working pill on the chat's turn clock. Place it anywhere; `TheoremChat` is built from it and
227
231
  * `TheoremChatTranscript`.
228
232
  */
229
- export declare function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, pills, inputComponent, triggers, refText, renderRef, emptyAction, renderStatus, }: TheoremChatComposerProps): import("react").JSX.Element;
233
+ export declare function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, pills, inputComponent, triggers, refText, renderRef, emptyAction, renderStatus, renderPillWords, }: TheoremChatComposerProps): import("react").JSX.Element;
230
234
  export type TheoremChatTranscriptProps<Host extends JsonObject = JsonObject> = Omit<ChatTranscriptProps<Host>, 'blocks' | 'handle' | 'streaming' | 'delivery' | 'answering' | 'clock' | 'onToolDecision' | 'onAuthenticated' | 'imageOutput' | 'labels' | 'showToolData'> & {
231
235
  /** The chat it shows (`useTheoremChat`). */
232
236
  chat: TheoremChatState;
package/ui/TheoremChat.js CHANGED
@@ -33,8 +33,8 @@ function ChatColumn({ maxWidth, ref, children, }) {
33
33
  * working pill on the chat's turn clock. Place it anywhere; `TheoremChat` is built from it and
34
34
  * `TheoremChatTranscript`.
35
35
  */
36
- export function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, pills, inputComponent, triggers, refText, renderRef, emptyAction, renderStatus, }) {
37
- return (_jsx(ChatComposerBar, { emptyAction: emptyAction, renderStatus: renderStatus, iface: iface, layout: layout, icons: icons, pills: pills, 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, inputComponent: inputComponent, triggers: triggers, refText: refText, renderRef: renderRef, draftParts: chat.draftParts, onDraftPartsChange: chat.setDraftParts, onDraftTextChange: chat.setDraftText, onFilesSelected: (files) => {
36
+ export function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, pills, inputComponent, triggers, refText, renderRef, emptyAction, renderStatus, renderPillWords, }) {
37
+ return (_jsx(ChatComposerBar, { emptyAction: emptyAction, renderStatus: renderStatus, renderPillWords: renderPillWords, iface: iface, layout: layout, icons: icons, pills: pills, 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, inputComponent: inputComponent, triggers: triggers, refText: refText, renderRef: renderRef, draftParts: chat.draftParts, onDraftPartsChange: chat.setDraftParts, onDraftTextChange: chat.setDraftText, onFilesSelected: (files) => {
38
38
  chat.setPendingFiles((prev) => [...prev, ...files]);
39
39
  chat.setIssues([]);
40
40
  }, onAttachmentRemove: (index) => {
@@ -71,7 +71,7 @@ function useChatHandle(chatRef, chat) {
71
71
  /** The composer, or, with none, the failed turn's error where the composer was. */
72
72
  function ChatBodyComposer({ body, chat, inputRef, }) {
73
73
  if (body.composer ?? true)
74
- return (_jsx(TheoremChatComposer, { chat: chat, iface: body.iface, placeholder: body.placeholder, inputRef: inputRef, layout: body.composerLayout, icons: body.composerIcons, inputComponent: body.composerInput, triggers: body.composerTriggers, refText: body.refText, renderRef: body.renderRef, emptyAction: body.composerEmptyAction, renderStatus: body.renderComposerStatus }));
74
+ return (_jsx(TheoremChatComposer, { chat: chat, iface: body.iface, placeholder: body.placeholder, inputRef: inputRef, layout: body.composerLayout, icons: body.composerIcons, inputComponent: body.composerInput, triggers: body.composerTriggers, refText: body.refText, renderRef: body.renderRef, emptyAction: body.composerEmptyAction, renderStatus: body.renderComposerStatus, renderPillWords: body.renderComposerPillWords }));
75
75
  const failure = chat.failure;
76
76
  return failure ? _jsx(Banner, { status: "error", role: "alert", title: failure.error }) : null;
77
77
  }
package/ui/index.d.ts CHANGED
@@ -16,7 +16,7 @@ export { InkWaveform, type InkWaveformProps, type InkWaveLevels, } from '../comp
16
16
  export { type LiveCall, type LiveCallInput, useLiveCall, } from '../components/live/use-live-call.js';
17
17
  export { theoremTheme } from './built/theorem.js';
18
18
  export { ChatComposerBar, type ChatComposerBarProps, type ComposerInputComponent, type ComposerLayout, EFFORT_ICON, generationOptions, type LiveComposerBarProps, } from './ChatComposerBar.js';
19
- export type { ComposerPill, ComposerRowIcons } from './ChatComposerRow.js';
19
+ export type { ComposerPill, ComposerPillWords, ComposerRowIcons } from './ChatComposerRow.js';
20
20
  export { ChatTranscript, type ChatTranscriptProps, type NameAppears, } from './ChatTranscript.js';
21
21
  export { ConsoleFrame, type ConsoleFrameProps, type ConsolePageProps, RequestCard, ResponseColumn, RunBar, useBytes, } from './ConsoleFrame.js';
22
22
  export { type RefTokenOptions, refToken } from './composer-refs.js';
@@ -31,7 +31,7 @@ export { AstryxMediaViewer, type MediaViewer, type MediaViewerItem, type MediaVi
31
31
  export { PaneFailure, PaneLoading, PaneState } from './PaneState.js';
32
32
  export { RadialBars, Sunburst, type SunburstNode } from './RadialCharts.js';
33
33
  export { type RankedBar, RankedBars } from './RankedBars.js';
34
- export type { ChatDetailsSlot, ChatMessageDetails, ChatReply, ChatReplySlot, ChatTranscriptSlots, } from './reply-slot.js';
34
+ export type { ChatDetailsSlot, ChatMarkdownSlot, ChatMessageDetails, ChatNameSlot, ChatReply, ChatReplyName, ChatReplySlot, ChatToolCallList, ChatToolCallsSlot, ChatTranscriptSlots, } from './reply-slot.js';
35
35
  export { InPlace, PaneLayout, PanePanel, Prose, RaisedPane } from './SidePanel.js';
36
36
  export { DEFAULT_CHAT_MAX_WIDTH, TheoremChat, TheoremChatComposer, type TheoremChatComposerProps, type TheoremChatHandle, type TheoremChatProps, TheoremChatTranscript, type TheoremChatTranscriptOptions, type TheoremChatTranscriptProps, } from './TheoremChat.js';
37
37
  export { TheoremDecision, type TheoremDecisionProps } from './TheoremDecision.js';
@@ -1,3 +1,6 @@
1
+ import type { ChatToolCallsProps } from '@astryxdesign/core/Chat';
2
+ import type { MarkdownProps } from '@astryxdesign/core/Markdown';
3
+ import type { MarkdownPluginEntry } from '@astryxdesign/core/Markdown/plugins';
1
4
  import type { TranscriptBlock } from '@theoremjs/agents/interface';
2
5
  import type { JsonObject } from '@theoremjs/agents/kernel';
3
6
  import type { ReactNode } from 'react';
@@ -30,6 +33,31 @@ export type ChatMessageDetails<Host extends JsonObject = JsonObject> = {
30
33
  };
31
34
  /** Drawn in each message's details, right after its time. Unset or `null` draws nothing. */
32
35
  export type ChatDetailsSlot<Host extends JsonObject = JsonObject> = null | ((message: ChatMessageDetails<Host>) => ReactNode);
36
+ /** A reply's name as the transcript's `name` slot is given it. */
37
+ export type ChatReplyName = {
38
+ handle: string;
39
+ /** `true` while the reply is on its way. */
40
+ streaming: boolean;
41
+ };
42
+ /** Draws a reply's name. Unset draws the handle. */
43
+ export type ChatNameSlot = (name: ChatReplyName) => ReactNode;
44
+ /** A list of tool calls as the transcript's `toolCalls` slot is given it. */
45
+ export type ChatToolCallList = {
46
+ /**
47
+ * What the transcript gives Astryx's `ChatToolCalls`. A call's `key` is its operation id, or its
48
+ * call id, so it stays the same from the live reply to the saved one.
49
+ */
50
+ list: ChatToolCallsProps;
51
+ /** `true` while the reply the calls belong to is on its way. */
52
+ streaming: boolean;
53
+ };
54
+ /** Draws a list of tool calls. Unset draws Astryx's `ChatToolCalls`. */
55
+ export type ChatToolCallsSlot = (calls: ChatToolCallList) => ReactNode;
56
+ /**
57
+ * Draws the words of a reply and of its thoughts, from what the transcript gives Astryx's
58
+ * `Markdown`. Unset draws Astryx's `Markdown`.
59
+ */
60
+ export type ChatMarkdownSlot = (markdown: MarkdownProps<readonly MarkdownPluginEntry[]>) => ReactNode;
33
61
  /** What the app draws in the transcript's slots. */
34
62
  export type ChatTranscriptSlots<Host extends JsonObject = JsonObject> = {
35
63
  /** Under each reply, inside its message. */
@@ -39,4 +67,10 @@ export type ChatTranscriptSlots<Host extends JsonObject = JsonObject> = {
39
67
  * details show with the message's time and copy button; a reply on its way has none yet.
40
68
  */
41
69
  details?: ChatDetailsSlot<Host>;
70
+ /** In place of a reply's name, where the name shows (`nameAppears`). */
71
+ name?: ChatNameSlot;
72
+ /** In place of each list of tool calls: in a reply, in its trace, and in an agent call's detail. */
73
+ toolCalls?: ChatToolCallsSlot;
74
+ /** In place of the Markdown of a reply's words and thoughts. */
75
+ markdown?: ChatMarkdownSlot;
42
76
  };