@theoremjs/react 0.3.5-next.1043.ge9acd49 → 0.3.5-next.1044.gd446ce7

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
@@ -184,7 +184,7 @@ To draw your own figures like the trace panel does, `@theoremjs/react/ui` also e
184
184
  | `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
185
  | `resolveMedia` | Turns a tool's reference into an address the page can load. See [Tool media](#tool-media). |
186
186
  | `mediaViewer` | The viewer every picture and video opens in. Default: Astryx's Lightbox, with zoom. See [Your own media viewer](#your-own-media-viewer). |
187
- | `transcript` | The options of `TheoremChatTranscript` that the chat does not set itself, given to its transcript as they are: `slots`, `turnKeyOf`, `turnTimeOf`, `dividers`, `bodyKindPlacement`, `stepLayout`, `showToolDurations`, `showWorkStatus`, and `showResumedNotice`. Its type is `TheoremChatTranscriptOptions`. See [Draw under a reply](#draw-under-a-reply) and [Draw beside a message's time](#draw-beside-a-messages-time). |
187
+ | `transcript` | The options of `TheoremChatTranscript` that the chat does not set itself, given to its transcript as they are: `slots`, `turnKeyOf`, `turnTimeOf`, `dividers`, `bodyKindPlacement`, `stepLayout`, `showToolDurations`, `toolFailureReasonKinds`, `showWorkStatus`, `showResumedNotice`, and `nameAppears`. Its type is `TheoremChatTranscriptOptions`. See [Draw under a reply](#draw-under-a-reply) and [Draw beside a message's time](#draw-beside-a-messages-time). |
188
188
 
189
189
  ### The row composer's look
190
190
 
@@ -745,7 +745,7 @@ function Dock({ chat, iface }) {
745
745
  }
746
746
  ```
747
747
 
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`, `showWorkStatus`, `showResumedNotice`, `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`.
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
749
 
750
750
  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
751
 
@@ -770,8 +770,12 @@ A failed tool call in `ChatTranscript` shows its failure in the person's wording
770
770
 
771
771
  Pass `showToolDurations={false}` to leave out how long each call ran.
772
772
 
773
+ A failed call's row shows the call's failed label and then a sentence on why it failed. Pass `toolFailureReasonKinds` to keep that sentence only for the failure kinds you name, such as `['cancelled', 'declined']`; `[]` leaves it out of every row. The model still reads the failure, and the call's detail still holds it.
774
+
773
775
  Pass `showWorkStatus={false}` to leave out a reply's work status ("Working for 12s", "Worked for 3.5s"). A reply whose steps fold under the status keeps it as the fold's trigger, without the time ("Worked"). Any other reply shows none.
774
776
 
777
+ Pass `nameAppears="with-content"` to keep a reply's name back until the reply has something to show: its work status, a call, a gate, words, media, or an image's placeholder. By default the name shows as soon as the reply starts.
778
+
775
779
  The hooks and the client write no English text. They return kinds, codes, and states. You write the words.
776
780
 
777
781
  - A failure is a `ClientFailure`: `{ error, errorKind, errorInternal? }`. Show `error` to the user. It is the wording of the profile. `errorKind` and `errorInternal` are for your code.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/react",
3
- "version": "0.3.5-next.1043.ge9acd49",
3
+ "version": "0.3.5-next.1044.gd446ce7",
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.1043.ge9acd49",
64
- "@theoremjs/web": "^0.3.5-next.1043.ge9acd49"
63
+ "@theoremjs/agents": "^0.3.5-next.1044.gd446ce7",
64
+ "@theoremjs/web": "^0.3.5-next.1044.gd446ce7"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@astryxdesign/core": {
@@ -1,5 +1,5 @@
1
1
  import { type ChatMessageStatus } from '@astryxdesign/core/Chat';
2
- import type { LabelOverrides } from '@theoremjs/agents';
2
+ import type { ErrorKind, LabelOverrides } from '@theoremjs/agents';
3
3
  import type { UserRef } from '@theoremjs/agents/interface';
4
4
  import { type TranscriptBlock } from '@theoremjs/agents/interface';
5
5
  import type { JsonObject } from '@theoremjs/agents/kernel';
@@ -67,6 +67,11 @@ export type ChatTranscriptProps<Host extends JsonObject = JsonObject> = {
67
67
  stepLayout?: StepLayout;
68
68
  /** Whether a finished tool call's row shows how long it ran. Default: true. */
69
69
  showToolDurations?: boolean;
70
+ /**
71
+ * The failure kinds whose failed tool call row says why, after the call's failed label. Default:
72
+ * every kind. Leave a kind out when the label says enough and the person has nothing to do.
73
+ */
74
+ toolFailureReasonKinds?: readonly ErrorKind[];
70
75
  /**
71
76
  * Whether a reply shows its work status ("Working for 12s", "Worked for 3.5s"). Default: true.
72
77
  * With `false`, a reply whose steps fold under the status keeps it as the fold's trigger, without
@@ -79,6 +84,8 @@ export type ChatTranscriptProps<Host extends JsonObject = JsonObject> = {
79
84
  * picked up where it left off."). Default: true.
80
85
  */
81
86
  showResumedNotice?: boolean;
87
+ /** When a reply shows its name. Default: `'at-start'`. */
88
+ nameAppears?: NameAppears;
82
89
  /** The profile's labels (`iface.labels`): a stopped turn says why in its words. */
83
90
  labels?: LabelOverrides;
84
91
  /**
@@ -96,6 +103,11 @@ export type ChatTranscriptProps<Host extends JsonObject = JsonObject> = {
96
103
  */
97
104
  turnTimeOf?: (host: Host) => number | undefined;
98
105
  };
106
+ /**
107
+ * `'at-start'`: as soon as the reply starts. `'with-content'`: once the reply has something to
108
+ * show: its work status, a call, a gate, words, media, or an image's placeholder.
109
+ */
110
+ export type NameAppears = 'at-start' | 'with-content';
99
111
  /** Image-profile display: `ratio` is the profile's pinned aspect ratio, if any. */
100
112
  export type ImageOutput = {
101
113
  ratio?: number;
@@ -42,10 +42,14 @@ const ShowUsage = createContext(false);
42
42
  const ShowToolData = createContext(true);
43
43
  /** Whether a finished tool call's row shows how long it ran (`ChatTranscriptProps.showToolDurations`). */
44
44
  const ShowToolDurations = createContext(true);
45
+ /** The kinds whose failed row says why; every kind when none are named (`toolFailureReasonKinds`). */
46
+ const ToolFailureReasonKinds = createContext(undefined);
45
47
  /** Whether a reply shows its work status (`ChatTranscriptProps.showWorkStatus`). */
46
48
  const ShowWorkStatus = createContext(true);
47
49
  /** Whether a reply that went on after its call failed shows its notice (`ChatTranscriptProps.showResumedNotice`). */
48
50
  const ShowResumedNotice = createContext(true);
51
+ /** When a reply shows its name (`ChatTranscriptProps.nameAppears`). */
52
+ const NameTiming = createContext('at-start');
49
53
  /** What the app draws under each reply (`ChatTranscriptProps.slots.reply`). */
50
54
  const ReplySlot = createContext(undefined);
51
55
  /** What the app draws in each message's details (`ChatTranscriptProps.slots.details`). */
@@ -56,6 +60,7 @@ function useToolRowShows() {
56
60
  usage: useContext(ShowUsage),
57
61
  detail: useContext(ShowToolData),
58
62
  duration: useContext(ShowToolDurations),
63
+ reasonKinds: useContext(ToolFailureReasonKinds),
59
64
  };
60
65
  }
61
66
  /** Largest a generated image renders in the transcript. */
@@ -536,9 +541,10 @@ function failedToolItem(t, base, tool, state, shows) {
536
541
  return {
537
542
  ...base,
538
543
  status: 'error',
539
- target: said,
544
+ ...(shows.reasonKinds?.includes(state.failure.kind) === false
545
+ ? {}
546
+ : { target: said, errorMessage: said }),
540
547
  ...toolUsageStats(state, shows),
541
- errorMessage: said,
542
548
  ...rowDetail(t, tool, shows, _jsx(ShapedData, { value: failureDetail(state.failure), title: t('@theorem.transcript.tool_error') })),
543
549
  };
544
550
  }
@@ -694,6 +700,26 @@ function PendingImage(props) {
694
700
  return null;
695
701
  return _jsx(GeneratingImage, { ratio: props.imageOutput.ratio });
696
702
  }
703
+ /** Whether a body row puts anything on screen: words that are still empty do not. */
704
+ function rowDraws(row) {
705
+ if (row.kind !== 'block')
706
+ return true;
707
+ const { block } = row;
708
+ return !(block.kind === 'text' || block.kind === 'thought') || block.text.trim() !== '';
709
+ }
710
+ /**
711
+ * Whether a reply shows its name yet. A reply that has stopped always does: its notice, time,
712
+ * or the app's part under it belongs to a named message.
713
+ */
714
+ function useNameShown(reply) {
715
+ const appears = useContext(NameTiming);
716
+ if (appears === 'at-start' || !reply.streaming)
717
+ return true;
718
+ return (reply.status !== '' ||
719
+ reply.gated ||
720
+ reply.imageOutput !== undefined ||
721
+ reply.rows.some(rowDraws));
722
+ }
697
723
  function AssistantTurn(props) {
698
724
  const t = useLabels();
699
725
  const replySlot = useContext(ReplySlot);
@@ -719,7 +745,14 @@ function AssistantTurn(props) {
719
745
  folds: hasTrace,
720
746
  }));
721
747
  const copyText = assistantTurnCopyText(body.length > 0 ? body : props.blocks);
722
- return (_jsx(ChatMessage, { sender: "assistant", name: props.handle, ...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'
748
+ const named = useNameShown({
749
+ streaming: props.streaming,
750
+ status,
751
+ gated: gatedTools.length > 0,
752
+ rows,
753
+ imageOutput: props.imageOutput,
754
+ });
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'
723
756
  ? row.kind
724
757
  : row.block.kind).map(({ item: row, index: i, key }) => (_jsx(BodyRowView
725
758
  // why: Not the block id: the committed turn re-mints ids, and a
@@ -768,7 +801,7 @@ export function ChatTranscript(props) {
768
801
  const turnKeyOf = keyOf ? (host) => keyOf(host) : undefined;
769
802
  const dateOf = props.turnTimeOf;
770
803
  const turnTimeOf = dateOf ? (host) => dateOf(host) : undefined;
771
- 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(ShowWorkStatus.Provider, { value: props.showWorkStatus !== false, children: _jsx(ShowResumedNotice.Provider, { value: props.showResumedNotice !== false, children: _jsx(ChatTranscriptBody, { ...props, turnKeyOf: turnKeyOf, turnTimeOf: turnTimeOf }) }) }) }) }) }) }) }) }) }));
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 }) }) }) }) }) }) }) }) }) }) }) }));
772
805
  }
773
806
  function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToolDecision, answering = null, onAuthenticated, emptyState, dividers, imageOutput, bodyKindPlacement, stepLayout, labels, clock, turnKeyOf, turnTimeOf, }) {
774
807
  const groups = useMemo(() => groupTranscriptBlocks(blocks, dividers && new Set(Object.keys(dividers)), turnKeyOf), [blocks, dividers, turnKeyOf]);
package/ui/index.d.ts CHANGED
@@ -17,7 +17,7 @@ export { type LiveCall, type LiveCallInput, useLiveCall, } from '../components/l
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
19
  export type { ComposerPill, ComposerRowIcons } from './ChatComposerRow.js';
20
- export { ChatTranscript, type ChatTranscriptProps } from './ChatTranscript.js';
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';
23
23
  export { TheoremDecisionAnswers, type TheoremDecisionAnswersProps } from './DecisionAnswers.js';
package/ui/index.js CHANGED
@@ -18,7 +18,7 @@ export { InkWaveform, } from "../components/InkWaveform.js";
18
18
  export { useLiveCall, } from "../components/live/use-live-call.js";
19
19
  export { theoremTheme } from './built/theorem.js';
20
20
  export { ChatComposerBar, EFFORT_ICON, generationOptions, } from "./ChatComposerBar.js";
21
- export { ChatTranscript } from "./ChatTranscript.js";
21
+ export { ChatTranscript, } from "./ChatTranscript.js";
22
22
  export { ConsoleFrame, RequestCard, ResponseColumn, RunBar, useBytes, } from "./ConsoleFrame.js";
23
23
  export { refToken } from "./composer-refs.js";
24
24
  export { TheoremDecisionAnswers } from "./DecisionAnswers.js";