@theoremjs/react 0.3.4 → 0.3.5-next.1001.g68d8dcf
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 +136 -6
- package/client/live/use-live-caption-log.d.ts +1 -1
- package/client/trace-story.d.ts +1 -1
- package/client/transcript-groups.d.ts +27 -4
- package/client/transcript-groups.js +45 -7
- package/components/InkWaveform.d.ts +1 -1
- package/components/live/use-live-call.d.ts +3 -3
- package/components/live/use-live-runner-controls.d.ts +2 -2
- package/components/live/use-live-runner-ui.d.ts +3 -3
- package/components/live/use-live-session-client.d.ts +2 -2
- package/components/use-composer-voice.d.ts +1 -1
- package/components/use-voice-playback.d.ts +1 -1
- package/hooks/use-embedding-index.d.ts +1 -1
- package/hooks/use-theorem-chat.d.ts +45 -44
- package/hooks/use-theorem-chat.js +10 -1
- package/hooks/use-theorem-decision.d.ts +1 -1
- package/hooks/use-theorem-embedding.d.ts +1 -1
- package/hooks/use-theorem-host.d.ts +1 -1
- package/hooks/use-turn-clock.d.ts +19 -0
- package/hooks/use-turn-clock.js +71 -0
- package/index.d.ts +8 -6
- package/index.js +1 -0
- package/live.d.ts +4 -4
- package/package.json +5 -5
- package/ui/ChatComposerBar.d.ts +19 -0
- package/ui/ChatComposerBar.js +141 -50
- package/ui/ChatComposerRow.d.ts +66 -0
- package/ui/ChatComposerRow.js +196 -0
- package/ui/ChatTranscript.d.ts +31 -2
- package/ui/ChatTranscript.js +165 -90
- package/ui/ConsoleFrame.d.ts +2 -2
- package/ui/DecisionAnswers.d.ts +1 -1
- package/ui/DecisionAnswers.js +9 -6
- package/ui/DecisionImages.d.ts +4 -3
- package/ui/EmbeddingDocuments.d.ts +2 -2
- package/ui/EmbeddingQuery.d.ts +2 -2
- package/ui/EmbeddingResults.d.ts +3 -3
- package/ui/LiveCallTile.d.ts +2 -2
- package/ui/LiveCaptionsPanel.d.ts +1 -1
- package/ui/LiveRunner.d.ts +6 -4
- package/ui/LiveRunner.js +4 -4
- package/ui/LiveToolGateDialog.d.ts +1 -1
- package/ui/LiveVideoPreview.d.ts +1 -1
- package/ui/RadialCharts.d.ts +2 -2
- package/ui/RankedBars.d.ts +1 -1
- package/ui/SchemaFields.d.ts +1 -1
- package/ui/SchemaFields.js +56 -3
- package/ui/ShapedData.js +4 -4
- package/ui/StateFields.d.ts +1 -1
- package/ui/StateFields.js +3 -3
- package/ui/TheoremChat.d.ts +74 -4
- package/ui/TheoremChat.js +53 -33
- package/ui/TheoremDecision.d.ts +3 -3
- package/ui/TheoremEmbedding.d.ts +2 -2
- package/ui/TheoremHost.d.ts +16 -2
- package/ui/TheoremHost.js +6 -6
- package/ui/TheoremSurface.d.ts +22 -0
- package/ui/TheoremSurface.js +13 -0
- package/ui/ToolResult.js +8 -6
- package/ui/TraceCharts.d.ts +2 -2
- package/ui/TraceGuardrails.d.ts +2 -2
- package/ui/TraceInspectorPanel.d.ts +1 -1
- package/ui/TraceOverview.d.ts +2 -2
- package/ui/TraceSpanDetail.d.ts +1 -1
- package/ui/TraceStory.d.ts +2 -2
- package/ui/TraceValues.d.ts +2 -2
- package/ui/TraceWaterfall.d.ts +1 -1
- package/ui/approval-heading.d.ts +1 -1
- package/ui/built/theme.css +91 -41
- package/ui/built/theme.css.d.ts +2 -2
- package/ui/built/theorem.d.ts +2 -2
- package/ui/built/theorem.js +41 -19
- package/ui/built/theorem.variants.d.ts +2 -2
- package/ui/embedding-space-view.d.ts +1 -1
- package/ui/index.d.ts +33 -28
- package/ui/index.js +4 -1
- package/ui/labels-provider.d.ts +1 -1
- package/ui/labels.d.ts +70 -2
- package/ui/labels.js +68 -0
- package/ui/media-viewer.d.ts +34 -0
- package/ui/media-viewer.js +27 -0
- package/ui/tool-media-shown.d.ts +13 -0
- package/ui/tool-media-shown.js +15 -0
- package/ui/tool-media.d.ts +34 -0
- package/ui/tool-media.js +52 -0
- package/ui/trace-patterns.d.ts +1 -1
- package/ui/transcript-copy-text.d.ts +1 -1
- package/ui/transcript-copy-text.js +1 -1
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ npm install @astryxdesign/core @stylexjs/stylex
|
|
|
65
65
|
|
|
66
66
|
To build your own theme from the Theorem theme (`/ui/theme`), also install `@astryxdesign/theme-neutral`.
|
|
67
67
|
|
|
68
|
-
Use the versions that this package lists in `peerDependencies`. Install `@theoremjs/react`, `@theoremjs/web`, and `@theoremjs/agents` at the same version. The Astryx and StyleX peers are optional. The hooks work without them.
|
|
68
|
+
Use the versions that this package lists in `peerDependencies`. The Astryx peers are pinned to one exact version, because the ready-made theme is built with that version of Astryx. Install `@theoremjs/react`, `@theoremjs/web`, and `@theoremjs/agents` at the same version. The Astryx and StyleX peers are optional. The hooks work without them.
|
|
69
69
|
|
|
70
70
|
When a chat turn, a call, a host request, or a decision fails, the ready-made UI shows the error in a banner that screen readers announce at once. The end of a live call is announced when the reader is next idle.
|
|
71
71
|
|
|
@@ -176,6 +176,93 @@ To draw your own figures like the trace panel does, `@theoremjs/react/ui` also e
|
|
|
176
176
|
| `initialPending` | The messages that the composer starts with set aside: queued, stashed, or steering, as `createComposerPendingMessage` from `@theoremjs/agents/interface` makes them. The component reads them once, when it mounts. |
|
|
177
177
|
| `chatRef` | Sends a message, stops a reply, or focuses the composer from your code. See below. |
|
|
178
178
|
| `composer` | `false` leaves the composer out. The chat is the transcript alone, and your own control sends through `chatRef`. Default: `true`. |
|
|
179
|
+
| `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'`. |
|
|
180
|
+
| `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). |
|
|
181
|
+
| `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). |
|
|
182
|
+
| `resolveMedia` | Turns a tool's reference into an address the page can load. See [Tool media](#tool-media). |
|
|
183
|
+
| `mediaViewer` | The viewer every picture and video opens in. Default: Astryx's Lightbox, with zoom. See [Your own media viewer](#your-own-media-viewer). |
|
|
184
|
+
|
|
185
|
+
### The row composer's look
|
|
186
|
+
|
|
187
|
+
The `'row'` composer has three parts: the pill row, the tray of what waits to send, and the surface with the field. The working pill reads "Working for 12s". It counts from the time the reply started and leaves out the time a step waited for approval, the same as the transcript's status line.
|
|
188
|
+
|
|
189
|
+
Each part of the look is a CSS custom property. Set it on any element above the composer, in your stylesheet or in `style`, or in your Astryx theme's `localTokens`. A property you do not set keeps Theorem's value.
|
|
190
|
+
|
|
191
|
+
| Property | What it sets | Default |
|
|
192
|
+
| --- | --- | --- |
|
|
193
|
+
| `--theorem-composer-radius` | The surface's corner radius. Send and the send menu follow its curve. | `var(--radius-chat)` |
|
|
194
|
+
| `--theorem-composer-fill` | The fill of the surface and the tray. | `var(--color-background-popover)` |
|
|
195
|
+
| `--theorem-composer-shadow` | The shadow of the surface and the tray. | `var(--shadow-low)` |
|
|
196
|
+
| `--theorem-composer-padding` | The space inside the surface. | `var(--spacing-3)` |
|
|
197
|
+
| `--theorem-composer-gap` | The space between the pill row, the tray and the surface. | `var(--spacing-2)` |
|
|
198
|
+
| `--theorem-composer-inset` | How far the pill row and the tray sit in from the surface's sides. | `0px` |
|
|
199
|
+
| `--theorem-composer-tray-radius` | The open tray's corner radius. | the surface's radius |
|
|
200
|
+
| `--theorem-composer-tray-folded-radius` | The folded tray's corner radius. | half the folded tray's height, so its ends are round |
|
|
201
|
+
| `--theorem-composer-tray-padding` | The space inside the tray. | `var(--spacing-3)` |
|
|
202
|
+
| `--theorem-composer-pill-height` | The height of each pill. | `var(--size-element-lg)` |
|
|
203
|
+
| `--theorem-composer-pill-radius` | The corner radius of each pill and of the stop button. | `var(--radius-full)` |
|
|
204
|
+
| `--theorem-composer-pill-fill` | The fill of each pill. | the surface's fill |
|
|
205
|
+
| `--theorem-composer-pill-shadow` | The shadow of each pill. | the surface's shadow |
|
|
206
|
+
| `--theorem-composer-pill-align` | Where one pill sits in the row, as `justify-content`. Two or more pills start at the row's start, and scroll once they do not fit. | `center` |
|
|
207
|
+
|
|
208
|
+
```tsx
|
|
209
|
+
<TheoremChat
|
|
210
|
+
endpoint="/api/theorem"
|
|
211
|
+
composerLayout="row"
|
|
212
|
+
composerIcons={{ working: <LeafSpinner /> }}
|
|
213
|
+
labels={{ en: { '@theorem.composer.pill.working_for': 'Thinking · {duration}' } }}
|
|
214
|
+
className="chat"
|
|
215
|
+
/>
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
```css
|
|
219
|
+
.chat {
|
|
220
|
+
--theorem-composer-radius: 22px;
|
|
221
|
+
--theorem-composer-pill-align: start;
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The words are labels: `@theorem.composer.pill.working_for`, `@theorem.composer.pill.working` (before the start is known), `@theorem.composer.pill.stop`, `@theorem.composer.pill.background`, `@theorem.composer.tray.expand` and `@theorem.composer.tray.collapse`. See [Wording](#wording). For a rule that no property covers, each part has a class: `theorem-composer-row`, `theorem-composer-pills`, `theorem-composer-pill` (with `data-pill="working"`, `"background"` or `"app"`), `theorem-composer-tray` (with `data-open`) and `theorem-composer-surface`.
|
|
226
|
+
|
|
227
|
+
### Tool media
|
|
228
|
+
|
|
229
|
+
A tool can return media for the model, for the person, or for both. The chat shows media from a tool only when the tool marked it `sent`, unless you pass `media="all"`. Media that a model generated and files that the user attached always show.
|
|
230
|
+
|
|
231
|
+
A tool can also return a **reference**: `{ type, mimeType, uri }`, such as a `gs://` object. The model never reads it, and the page cannot load its `uri` as it stands. Pass `resolveMedia` to turn it into an address the page can load, under the viewer's own sign-in:
|
|
232
|
+
|
|
233
|
+
```tsx
|
|
234
|
+
<TheoremChat
|
|
235
|
+
endpoint="/api/theorem"
|
|
236
|
+
resolveMedia={async (reference) => {
|
|
237
|
+
const res = await fetch(`/api/files/sign?uri=${encodeURIComponent(reference.uri)}`);
|
|
238
|
+
return res.ok ? (await res.json()).url : null;
|
|
239
|
+
}}
|
|
240
|
+
/>
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`resolveMedia` returns a string, `null`, or a promise of either. While it works, and when it returns `null` or throws, the chat shows the file name from the `uri`. `TheoremHost` takes the same `resolveMedia`, and always shows all the media of a call.
|
|
244
|
+
|
|
245
|
+
A file the person sent works the same way after your app saves it. When you load a saved conversation, give the person's file as a `user-attachment` or `user-voice` block with `uri` and `type` in place of `data`, and your own values for the file in `metadata` if you need them. The chat shows it on the person's side through `resolveMedia`: a picture, a voice note to play, or the file name.
|
|
246
|
+
|
|
247
|
+
### Your own media viewer
|
|
248
|
+
|
|
249
|
+
A picture or a video opens in a viewer when the person clicks it: in the transcript, in a tool's result, in a decision's answer, and in a form field. Pass `mediaViewer` to open them all in your own:
|
|
250
|
+
|
|
251
|
+
```tsx
|
|
252
|
+
import type { MediaViewerProps } from '@theoremjs/react/ui';
|
|
253
|
+
|
|
254
|
+
function MyViewer({ isOpen, onOpenChange, media, index }: MediaViewerProps) {
|
|
255
|
+
const item = media[index]; // { type, src, alt, caption?, reference? }
|
|
256
|
+
if (!isOpen || !item) return null;
|
|
257
|
+
return <MyDialog item={item} onClose={() => onOpenChange(false)} />;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
<TheoremChat endpoint="/api/theorem" profile="assistant" mediaViewer={MyViewer} />;
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Declare the viewer once, outside your components, as the example does. A function made again on each render is a new component each time, so the open viewer starts over and loses what it holds.
|
|
264
|
+
|
|
265
|
+
The viewer is given the items, the one shown, and whether it is open. Call `onOpenChange(false)` to close it and `onIndexChange` to show another. An item's `src` is the address the page loads. When the app saved the file, the item also has `reference`, the `{ type, mimeType, uri }` that `resolveMedia` was given, since `src` can be a link that expires. `TheoremHost`, `LiveRunner`, and `TheoremSurface` take the same `mediaViewer`. Without it, they open Astryx's Lightbox, with zoom, as `AstryxMediaViewer` does. To open the page's viewer from your own component inside the surface, call `useMediaViewer(items)` and render its `element`.
|
|
179
266
|
|
|
180
267
|
### Resume a conversation
|
|
181
268
|
|
|
@@ -255,7 +342,7 @@ The handler accepts these requests:
|
|
|
255
342
|
- `POST /call` with `{ name, input }` streams the events of the call.
|
|
256
343
|
- `POST /invoke` answers a gate that paused a call.
|
|
257
344
|
|
|
258
|
-
The console builds a form from the input schema. It shows the result as figures, charts, tables, images, audio, or Markdown, with the raw JSON beside it. If the data renderer fails, the view switches to JSON so the selected view matches what is shown. For your own UI, use `createHostTransport` and `useTheoremHost`.
|
|
345
|
+
The console builds a form from the input schema. It shows the result as figures, charts, tables, images, audio, or Markdown, with the raw JSON beside it. It shows every piece of media the call returned, and a reference through `resolveMedia` (see [Tool media](#tool-media)). If the data renderer fails, the view switches to JSON so the selected view matches what is shown. For your own UI, use `createHostTransport` and `useTheoremHost`.
|
|
259
346
|
|
|
260
347
|
#### Serve a host profile over MCP
|
|
261
348
|
|
|
@@ -361,7 +448,7 @@ const call = useLiveCall({ iface, connection: () => ({ profile: 'support.voice'
|
|
|
361
448
|
|
|
362
449
|
This code opens `wss://<your host>/api/live/relay?profile=<id>`. To send your own message to the relay, add `openMessage`. To use your own socket, add `createSocket`.
|
|
363
450
|
|
|
364
|
-
`LiveRunner` also accepts `theme`, `mode`, `labels`, and `trace`. Tool gates in a call appear in a dialog over the call.
|
|
451
|
+
`LiveRunner` also accepts `theme`, `mode`, `labels`, `media`, `resolveMedia`, `mediaViewer`, and `trace`. Its captions show the media a tool returns as the chat does: see [Tool media](#tool-media). Tool gates in a call appear in a dialog over the call.
|
|
365
452
|
|
|
366
453
|
### A call across pages
|
|
367
454
|
|
|
@@ -391,7 +478,7 @@ Three more values for `useLiveCall` come from the page. The profile declares eac
|
|
|
391
478
|
|
|
392
479
|
`stated` is a fourth value, for a page you trust as yourself. It says the `path` and the `options` from `identity.options` that choose the call's prompt lines, and the server reads it only with `pageStatesTurn` set. A change during a call takes the call up again, as an option does. `TheoremChat` takes the same prop, on each turn.
|
|
393
480
|
|
|
394
|
-
`model` and `effort` pick the call's model
|
|
481
|
+
`model` and `effort` pick the call's model and effort. The host refuses them unless the profile sets `allowModelSelect` (and the binding `allowEffortSelect`). They are read when the call starts.
|
|
395
482
|
|
|
396
483
|
```tsx
|
|
397
484
|
const call = useLiveCall({
|
|
@@ -475,16 +562,59 @@ function MyChat() {
|
|
|
475
562
|
}
|
|
476
563
|
```
|
|
477
564
|
|
|
478
|
-
`chat.phase` is `'idle'`, `'streaming'`, or `'gated'`. The actions are `handleSubmit`, `handleStop`, `handleSendNow`, and `handleToolDecision`.
|
|
565
|
+
`chat.phase` is `'idle'`, `'streaming'`, or `'gated'`. `chat.waitingGate` is the gate that waits for the person, and `null` when none waits. A page gate is never one, because the page answers it. The actions are `handleSubmit`, `handleStop`, `handleSendNow`, and `handleToolDecision`.
|
|
566
|
+
|
|
567
|
+
`chat.backgroundJobs` lists the tool calls that still run in the background, each as `{ callId, label }`. A call leaves the list when its late result lands. `backgroundJobs(blocks)` gives the same list from a transcript. `ChatComposerBar` takes `layout` and `backgroundJobs`, as `TheoremChat` takes `composerLayout`.
|
|
479
568
|
|
|
480
569
|
`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.
|
|
481
570
|
|
|
482
|
-
|
|
571
|
+
A pending message with `saved` set is one the host saved itself (`intake` on `createTheoremHandler`). `ChatComposerBar` draws it with the label `@theorem.composer.pending.saved`, "Sent", and no actions, because the page cannot change it. It leaves the list when a reply reads it.
|
|
572
|
+
|
|
573
|
+
### Place the pieces yourself
|
|
574
|
+
|
|
575
|
+
`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.
|
|
576
|
+
|
|
577
|
+
```tsx
|
|
578
|
+
import { TheoremChatComposer, TheoremChatTranscript, TheoremSurface } from '@theoremjs/react/ui';
|
|
579
|
+
|
|
580
|
+
function Dock({ chat, iface }) {
|
|
581
|
+
const [open, setOpen] = useState(false);
|
|
582
|
+
return (
|
|
583
|
+
<TheoremSurface>
|
|
584
|
+
<div onFocus={() => setOpen(true)}>
|
|
585
|
+
{open && <TheoremChatTranscript chat={chat} iface={iface} />}
|
|
586
|
+
<TheoremChatComposer chat={chat} iface={iface} layout="row" />
|
|
587
|
+
</div>
|
|
588
|
+
</TheoremSurface>
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
`TheoremChatComposer` takes `layout`, `icons`, `pills`, `placeholder`, and `inputRef`. `TheoremChatTranscript` takes the props of `ChatTranscript` that the chat does not give: `handle`, `emptyState`, `dividers`, `usage`, `bodyKindPlacement`, `stepLayout`, and `showToolDurations`. 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`.
|
|
594
|
+
|
|
595
|
+
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, onSelect? }`. It comes after the working pill and the background calls, and looks like them. A click calls `onSelect`. A pill without `onSelect` only shows.
|
|
596
|
+
|
|
597
|
+
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. For a reply that runs elsewhere, it is `chat.runningElsewhere.since`. `chat.shownBlocks` is what the transcript shows: `chat.blocks`, then `chat.streamBlocks`.
|
|
598
|
+
|
|
599
|
+
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.
|
|
483
600
|
|
|
484
601
|
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.
|
|
485
602
|
|
|
603
|
+
A tool call that runs on in the background after its reply ends shows as running, with a "Background task" badge (`@theorem.transcript.tool_background`). The badge goes when the call's end reaches the transcript.
|
|
604
|
+
|
|
605
|
+
A failed tool call in `ChatTranscript` shows its failure once: the row shows the message the model read, and the details show its `code`, `kind`, and `details`.
|
|
606
|
+
|
|
486
607
|
`ChatTranscript` places `citation` blocks after the answer text by default (the Sources strip under the prose). Pass `bodyKindPlacement={{}}` when citations must stay in stream order between text segments (inline citations).
|
|
487
608
|
|
|
609
|
+
`ChatTranscript` folds a reply's thoughts and tool calls, with the words the reply wrote between them, under its work status ("Worked for 22s"). Pass `stepLayout="inline"` to keep each where it came. A channel that sends each piece of words as its own message, as a text message does, then reads the same as the page:
|
|
610
|
+
|
|
611
|
+
- All the words show in the open.
|
|
612
|
+
- Calls side by side are one row. One call shows its own label. Several show their count and open to each call.
|
|
613
|
+
- Each thought is one folded line, "Thought: …", that opens to the whole of it.
|
|
614
|
+
- The work status is a line with nothing under it.
|
|
615
|
+
|
|
616
|
+
Pass `showToolDurations={false}` to leave out how long each call ran.
|
|
617
|
+
|
|
488
618
|
The hooks and the client write no English text. They return kinds, codes, and states. You write the words.
|
|
489
619
|
|
|
490
620
|
- 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.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TurnEvent } from '@theoremjs/agents';
|
|
2
|
-
import { type LiveCaptionState, type LiveCaptionTurn } from './live-captions.
|
|
2
|
+
import { type LiveCaptionState, type LiveCaptionTurn } from './live-captions.js';
|
|
3
3
|
/**
|
|
4
4
|
* The captions a live call shows: this call's lines, and earlier calls kept
|
|
5
5
|
* when it is started again. Speech arrives through `applyTranscript`, and the
|
package/client/trace-story.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TraceNode, type TraceTotals } from './trace-view.
|
|
1
|
+
import { type TraceNode, type TraceTotals } from './trace-view.js';
|
|
2
2
|
/**
|
|
3
3
|
* The trace panel's story of a turn: who acted, in what order, and where the
|
|
4
4
|
* time went, read from the span tree. The words still come from the trace
|
|
@@ -57,7 +57,16 @@ export type ComposedAssistantTurn = {
|
|
|
57
57
|
body: TranscriptBlock[];
|
|
58
58
|
/** True when the disclosure control should appear. */
|
|
59
59
|
hasTrace: boolean;
|
|
60
|
+
/** True when the reply thought or called a tool, folded or in place. */
|
|
61
|
+
hasSteps: boolean;
|
|
60
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* Where a reply's steps (its thoughts and tool calls) sit.
|
|
65
|
+
*
|
|
66
|
+
* - `trace`: under the work status, folded, with the words written between them.
|
|
67
|
+
* - `inline`: each where it came, beside the words, which all show. The work status is a line.
|
|
68
|
+
*/
|
|
69
|
+
export type StepLayout = 'trace' | 'inline';
|
|
61
70
|
/** Pin a body kind before or after kinds with no placement (stream order among peers). */
|
|
62
71
|
export type BodyKindPlacement = 'first' | 'last';
|
|
63
72
|
export type ComposeAssistantTurnOptions = {
|
|
@@ -67,6 +76,8 @@ export type ComposeAssistantTurnOptions = {
|
|
|
67
76
|
* When the option is omitted entirely, {@link DEFAULT_BODY_KIND_PLACEMENT} applies.
|
|
68
77
|
*/
|
|
69
78
|
bodyKindPlacement?: Partial<Record<TranscriptBlock['kind'], BodyKindPlacement | null | undefined>>;
|
|
79
|
+
/** Where the reply's steps sit. Default: `trace`. */
|
|
80
|
+
stepLayout?: StepLayout;
|
|
70
81
|
};
|
|
71
82
|
/**
|
|
72
83
|
* Blocks as turns: neighbours from the same side share one, unless a block is
|
|
@@ -81,10 +92,10 @@ export type WorkStatus = {
|
|
|
81
92
|
phase: 'working' | 'worked';
|
|
82
93
|
elapsedMs?: number;
|
|
83
94
|
};
|
|
84
|
-
/** Working while streaming; worked after, when it has a duration or
|
|
95
|
+
/** Working while streaming; worked after, when it has a duration or steps; else nothing to show. */
|
|
85
96
|
export declare function workStatus(args: {
|
|
86
97
|
streaming: boolean;
|
|
87
|
-
|
|
98
|
+
hasSteps: boolean;
|
|
88
99
|
elapsedMs?: number;
|
|
89
100
|
}): WorkStatus | null;
|
|
90
101
|
/**
|
|
@@ -96,6 +107,8 @@ export declare function workStatus(args: {
|
|
|
96
107
|
* - `text` before/between tools → narration; text and answer kinds after the
|
|
97
108
|
* latest tool → body (while streaming too, so the answer streams formatted)
|
|
98
109
|
* - No tools: thoughts still go to trace; remaining kinds → body
|
|
110
|
+
* - Under `stepLayout: 'inline'`, nothing is traced: every block but the first gate is body, in
|
|
111
|
+
* stream order; thoughts, and words before a call, that say nothing are dropped
|
|
99
112
|
* - Body kinds then follow {@link ComposeAssistantTurnOptions.bodyKindPlacement}
|
|
100
113
|
* (default: citations last)
|
|
101
114
|
*/
|
|
@@ -144,9 +157,19 @@ export declare function assistantTurnTiming(args: {
|
|
|
144
157
|
groups: readonly TranscriptTurnGroup[];
|
|
145
158
|
index: number;
|
|
146
159
|
streaming: boolean;
|
|
147
|
-
|
|
148
|
-
|
|
160
|
+
/** When the reply to a prompt started, its approval waits skipped (`TurnClock.replyStart`). */
|
|
161
|
+
replyStart: (prompt: TranscriptTurnGroup) => number | undefined;
|
|
149
162
|
}): AssistantTurnTiming;
|
|
150
163
|
export declare function toolCallLabel(tool: Extract<TranscriptBlock, {
|
|
151
164
|
kind: 'tool';
|
|
152
165
|
}>['tool']): string;
|
|
166
|
+
/** A tool call still running in the background, as the composer's pill row shows it. */
|
|
167
|
+
export type BackgroundJob = {
|
|
168
|
+
callId: string;
|
|
169
|
+
label: string;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* The calls still running in the background, oldest first: each tool call whose last phase is
|
|
173
|
+
* `background`, until a late-results message carries its result.
|
|
174
|
+
*/
|
|
175
|
+
export declare function backgroundJobs(blocks: readonly TranscriptBlock[]): BackgroundJob[];
|
|
@@ -108,14 +108,14 @@ export function assistantTurnCopyText(blocks) {
|
|
|
108
108
|
.filter(Boolean)
|
|
109
109
|
.join('\n\n');
|
|
110
110
|
}
|
|
111
|
-
/** Working while streaming; worked after, when it has a duration or
|
|
111
|
+
/** Working while streaming; worked after, when it has a duration or steps; else nothing to show. */
|
|
112
112
|
export function workStatus(args) {
|
|
113
113
|
const elapsed = args.elapsedMs !== undefined ? { elapsedMs: args.elapsedMs } : {};
|
|
114
114
|
if (args.streaming)
|
|
115
115
|
return { phase: 'working', ...elapsed };
|
|
116
116
|
if (args.elapsedMs !== undefined && args.elapsedMs > 0)
|
|
117
117
|
return { phase: 'worked', elapsedMs: args.elapsedMs };
|
|
118
|
-
return args.
|
|
118
|
+
return args.hasSteps ? { phase: 'worked' } : null;
|
|
119
119
|
}
|
|
120
120
|
function isGatedTool(block) {
|
|
121
121
|
return block.kind === 'tool' && block.tool.state?.phase === 'gate';
|
|
@@ -164,6 +164,8 @@ function classifyNonGateBlock(block, args, trace, body) {
|
|
|
164
164
|
* - `text` before/between tools → narration; text and answer kinds after the
|
|
165
165
|
* latest tool → body (while streaming too, so the answer streams formatted)
|
|
166
166
|
* - No tools: thoughts still go to trace; remaining kinds → body
|
|
167
|
+
* - Under `stepLayout: 'inline'`, nothing is traced: every block but the first gate is body, in
|
|
168
|
+
* stream order; thoughts, and words before a call, that say nothing are dropped
|
|
167
169
|
* - Body kinds then follow {@link ComposeAssistantTurnOptions.bodyKindPlacement}
|
|
168
170
|
* (default: citations last)
|
|
169
171
|
*/
|
|
@@ -173,6 +175,22 @@ export function composeAssistantTurn(blocks, options) {
|
|
|
173
175
|
const nextGate = visible.find(isGatedTool);
|
|
174
176
|
const gatedTools = nextGate ? [nextGate] : [];
|
|
175
177
|
const nonGate = visible.filter((block) => block !== nextGate);
|
|
178
|
+
const placement = options?.bodyKindPlacement ?? DEFAULT_BODY_KIND_PLACEMENT;
|
|
179
|
+
if (options?.stepLayout === 'inline') {
|
|
180
|
+
// why: In place, a step is a body row like the words around it. As in the trace, a thought or
|
|
181
|
+
// the words before a call that say nothing are dropped; the answer after the last call stays,
|
|
182
|
+
// empty while it starts streaming.
|
|
183
|
+
const lastToolIndex = lastToolIndexOf(nonGate);
|
|
184
|
+
const body = nonGate.filter((block, index) => !(block.kind === 'thought' || (block.kind === 'text' && index < lastToolIndex)) ||
|
|
185
|
+
block.text.trim());
|
|
186
|
+
return {
|
|
187
|
+
trace: [],
|
|
188
|
+
gatedTools,
|
|
189
|
+
body: placeBodyBlocks(body, placement),
|
|
190
|
+
hasTrace: false,
|
|
191
|
+
hasSteps: body.some((block) => block.kind === 'tool' || block.kind === 'thought'),
|
|
192
|
+
};
|
|
193
|
+
}
|
|
176
194
|
const lastToolIndex = lastToolIndexOf(nonGate);
|
|
177
195
|
const hasTools = lastToolIndex >= 0;
|
|
178
196
|
const trace = [];
|
|
@@ -180,12 +198,12 @@ export function composeAssistantTurn(blocks, options) {
|
|
|
180
198
|
for (const [index, block] of nonGate.entries()) {
|
|
181
199
|
classifyNonGateBlock(block, { hasTools, index, lastToolIndex }, trace, body);
|
|
182
200
|
}
|
|
183
|
-
const placement = options?.bodyKindPlacement ?? DEFAULT_BODY_KIND_PLACEMENT;
|
|
184
201
|
return {
|
|
185
202
|
trace,
|
|
186
203
|
gatedTools,
|
|
187
204
|
body: placeBodyBlocks(body, placement),
|
|
188
205
|
hasTrace: trace.length > 0,
|
|
206
|
+
hasSteps: trace.length > 0,
|
|
189
207
|
};
|
|
190
208
|
}
|
|
191
209
|
/** The trailing user group while its reply has not started streaming back. */
|
|
@@ -231,10 +249,8 @@ export function assistantTurnTiming(args) {
|
|
|
231
249
|
: { key, live };
|
|
232
250
|
}
|
|
233
251
|
const prompt = args.groups[args.index - 1];
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
return { key, live };
|
|
237
|
-
return { key, live, startedAt: args.timeOf(prompt.key) + span.pausedMs };
|
|
252
|
+
const startedAt = prompt?.kind === 'user' ? args.replyStart(prompt) : undefined;
|
|
253
|
+
return startedAt === undefined ? { key, live } : { key, live, startedAt };
|
|
238
254
|
}
|
|
239
255
|
export function toolCallLabel(tool) {
|
|
240
256
|
const phase = tool.state?.phase;
|
|
@@ -243,3 +259,25 @@ export function toolCallLabel(tool) {
|
|
|
243
259
|
const settled = phase === 'complete' || phase === 'error';
|
|
244
260
|
return (settled ? tool.activityPast : tool.activity) ?? humanize(tool.name);
|
|
245
261
|
}
|
|
262
|
+
/**
|
|
263
|
+
* The calls still running in the background, oldest first: each tool call whose last phase is
|
|
264
|
+
* `background`, until a late-results message carries its result.
|
|
265
|
+
*/
|
|
266
|
+
export function backgroundJobs(blocks) {
|
|
267
|
+
const landed = new Set();
|
|
268
|
+
for (const block of blocks) {
|
|
269
|
+
if (block.kind === 'late-results')
|
|
270
|
+
for (const id of block.operationIds)
|
|
271
|
+
landed.add(id);
|
|
272
|
+
}
|
|
273
|
+
const jobs = [];
|
|
274
|
+
for (const block of blocks) {
|
|
275
|
+
if (block.kind !== 'tool' || block.tool.state?.phase !== 'background')
|
|
276
|
+
continue;
|
|
277
|
+
const { operationId } = block.tool;
|
|
278
|
+
if (operationId && landed.has(operationId))
|
|
279
|
+
continue;
|
|
280
|
+
jobs.push({ callId: block.tool.callId, label: toolCallLabel(block.tool) });
|
|
281
|
+
}
|
|
282
|
+
return jobs;
|
|
283
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RefObject } from 'react';
|
|
2
|
-
import { type InkWaveStatus } from '../client/ink-waveform.
|
|
2
|
+
import { type InkWaveStatus } from '../client/ink-waveform.js';
|
|
3
3
|
/** Mic and speaker levels. A host on the audio clock writes this; the bars read it each frame. */
|
|
4
4
|
export type InkWaveLevels = {
|
|
5
5
|
input: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { LiveProfileInterface } from '@theoremjs/agents/interface';
|
|
2
2
|
import type { LiveCallOptions, LiveConnection } from '@theoremjs/web/client';
|
|
3
|
-
import { type LiveCaptionState, type LiveCaptionTurn } from '../../client/live/live-captions.
|
|
3
|
+
import { type LiveCaptionState, type LiveCaptionTurn } from '../../client/live/live-captions.js';
|
|
4
4
|
/** What `useLiveCall` takes: the profile, what the call opens, and the host's part in the call. */
|
|
5
5
|
export type LiveCallInput = {
|
|
6
6
|
iface: LiveProfileInterface;
|
|
@@ -35,13 +35,13 @@ export declare function useLiveCall({ iface, connection, ...options }: LiveCallI
|
|
|
35
35
|
isVideoOn: boolean;
|
|
36
36
|
sessionActive: boolean;
|
|
37
37
|
liveState: import("@theoremjs/web/client").LiveState;
|
|
38
|
-
activeTool: import("../../client/live/apply-live-turn-tool-event.
|
|
38
|
+
activeTool: import("../../client/live/apply-live-turn-tool-event.js").LiveActiveTool | null;
|
|
39
39
|
status: import("@theoremjs/web/client").LiveSessionStatus;
|
|
40
40
|
textAvailable: boolean;
|
|
41
41
|
textDraft: string;
|
|
42
42
|
toolActive: boolean;
|
|
43
43
|
videoAvailable: boolean;
|
|
44
|
-
videoFacingMode: import("../../client/live/live-video.
|
|
44
|
+
videoFacingMode: import("../../client/live/live-video.js").LiveFacingMode;
|
|
45
45
|
videoPreview: HTMLVideoElement | null;
|
|
46
46
|
voiceAvailable: boolean;
|
|
47
47
|
canRestart: boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { LiveConnection, LiveConnectPhase, LiveSessionClient, LiveSessionStatus } from '@theoremjs/web/client';
|
|
2
2
|
import { type Dispatch, type MutableRefObject, type SetStateAction } from 'react';
|
|
3
|
-
import { type LiveCaptionState } from '../../client/live/live-captions.
|
|
4
|
-
import { type LiveFacingMode, type LiveVideoCapture } from '../../client/live/live-video.
|
|
3
|
+
import { type LiveCaptionState } from '../../client/live/live-captions.js';
|
|
4
|
+
import { type LiveFacingMode, type LiveVideoCapture } from '../../client/live/live-video.js';
|
|
5
5
|
/** Media + session lifecycle handlers for LiveRunner. */
|
|
6
6
|
export declare function useLiveRunnerControls(args: {
|
|
7
7
|
clientRef: MutableRefObject<LiveSessionClient | null>;
|
|
@@ -2,9 +2,9 @@ import { type LabelOverrides, type SessionEventOf } from '@theoremjs/agents';
|
|
|
2
2
|
import type { LiveConnectPhase, LiveGateAnswer, LiveSessionStatus, LiveToolGatePrompt, ToolGateResolution } from '@theoremjs/web/client';
|
|
3
3
|
import { type ClientFailure } from '@theoremjs/web/client';
|
|
4
4
|
import { type Dispatch, type SetStateAction } from 'react';
|
|
5
|
-
import { applyLiveTurnToolEvent, type LiveActiveTool } from '../../client/live/apply-live-turn-tool-event.
|
|
6
|
-
import { type LiveCaptionState } from '../../client/live/live-captions.
|
|
7
|
-
import type { LiveFacingMode, LiveVideoCapture } from '../../client/live/live-video.
|
|
5
|
+
import { applyLiveTurnToolEvent, type LiveActiveTool } from '../../client/live/apply-live-turn-tool-event.js';
|
|
6
|
+
import { type LiveCaptionState } from '../../client/live/live-captions.js';
|
|
7
|
+
import type { LiveFacingMode, LiveVideoCapture } from '../../client/live/live-video.js';
|
|
8
8
|
/** UI + media state bag for the live runner. `labels` is the interface's: the profile's wording. */
|
|
9
9
|
export declare function useLiveRunnerUiState(labels: LabelOverrides): {
|
|
10
10
|
status: LiveSessionStatus;
|
|
@@ -2,8 +2,8 @@ import type { SessionEventOf, TurnEvent } from '@theoremjs/agents';
|
|
|
2
2
|
import type { LiveCallOptions, LiveConnectPhase, LiveGateAnswer, LiveSessionStatus, LiveToolGatePrompt, TraceFeed } from '@theoremjs/web/client';
|
|
3
3
|
import { type LiveConnection, LiveSessionClient } from '@theoremjs/web/client';
|
|
4
4
|
import { type Dispatch, type MutableRefObject, type SetStateAction } from 'react';
|
|
5
|
-
import { type LiveCaptionState } from '../../client/live/live-captions.
|
|
6
|
-
import type { LiveFacingMode, LiveVideoCapture } from '../../client/live/live-video.
|
|
5
|
+
import { type LiveCaptionState } from '../../client/live/live-captions.js';
|
|
6
|
+
import type { LiveFacingMode, LiveVideoCapture } from '../../client/live/live-video.js';
|
|
7
7
|
export type LiveClientBindings = LiveCallOptions & {
|
|
8
8
|
voiceAvailable: boolean;
|
|
9
9
|
/** Where the session's trace records go, when the relay delivers them. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type LabelOverrides } from '@theoremjs/agents';
|
|
2
2
|
import type { ProfileInputsInterface } from '@theoremjs/agents/interface';
|
|
3
|
-
import { type VoiceRecorderFailureCode } from '../client/voice-recorder.
|
|
3
|
+
import { type VoiceRecorderFailureCode } from '../client/voice-recorder.js';
|
|
4
4
|
/** A voice note that could not be recorded or staged. */
|
|
5
5
|
export type VoiceFailure = {
|
|
6
6
|
/** A recorder failure, or `too_many_files` when the message is already full. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EmbeddingInput, EmbeddingUsage } from '@theoremjs/agents';
|
|
2
2
|
import type { EmbeddingInterface, EmbeddingTransport } from '@theoremjs/web/client';
|
|
3
|
-
import { type OneCallState } from './use-one-call.
|
|
3
|
+
import { type OneCallState } from './use-one-call.js';
|
|
4
4
|
/** Documents embedded for search: each one's vector, in the order given. */
|
|
5
5
|
export type EmbeddingIndex = {
|
|
6
6
|
inputs: readonly EmbeddingInput[];
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { TranscriptBlock } from '@theoremjs/agents/interface';
|
|
2
|
+
import { type ChatController, type ChatOptionPicks, type ChatOptions, type ChatState, type SendTextOptions, type SentTurn, type ToolDecisionAction } from '@theoremjs/web/client';
|
|
3
|
+
import { type BackgroundJob } from '../client/transcript-groups.js';
|
|
4
|
+
import { type TurnClock } from './use-turn-clock.js';
|
|
2
5
|
export type { SendTextOptions, SentTurn };
|
|
3
6
|
export type UseTheoremChatOptions = ChatOptions;
|
|
4
7
|
/**
|
|
@@ -7,48 +10,46 @@ export type UseTheoremChatOptions = ChatOptions;
|
|
|
7
10
|
* your own components. A React binding of `createChatController` from
|
|
8
11
|
* `@theoremjs/web/client`, which works with no framework.
|
|
9
12
|
*/
|
|
10
|
-
export declare function useTheoremChat(options: UseTheoremChatOptions):
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
export declare function useTheoremChat(options: UseTheoremChatOptions): TheoremChatState;
|
|
14
|
+
/** What `useTheoremChat` returns: the chat's state and its actions. */
|
|
15
|
+
export type TheoremChatState = ChatState & {
|
|
16
|
+
/** The profile's options with their values, and the setter; `undefined` when it declares none. */
|
|
17
|
+
optionChoices: (ChatOptionPicks & {
|
|
18
|
+
onChange: ChatController['pickOption'];
|
|
19
|
+
}) | undefined;
|
|
20
|
+
/** What the transcript shows: the committed blocks, then the reply streaming in. */
|
|
21
|
+
shownBlocks: TranscriptBlock[];
|
|
22
|
+
/**
|
|
23
|
+
* When each turn started and how long it waited on approvals. Pass it to `ChatTranscript`'s
|
|
24
|
+
* `clock` so its times agree with the composer's working pill.
|
|
25
|
+
*/
|
|
26
|
+
turnClock: TurnClock;
|
|
27
|
+
/**
|
|
28
|
+
* When the reply in progress started: one this page runs, its approval waits skipped, or one
|
|
29
|
+
* that runs elsewhere (`runningElsewhere.since`); `undefined` when none runs.
|
|
30
|
+
*/
|
|
31
|
+
workingSince: number | undefined;
|
|
32
|
+
/** The tool calls still running in the background, oldest first, until their results land. */
|
|
33
|
+
backgroundJobs: BackgroundJob[];
|
|
34
|
+
setDraftText: ChatController['setDraftText'];
|
|
35
|
+
setPendingFiles: ChatController['setPendingFiles'];
|
|
36
|
+
setPendingVoice: ChatController['setPendingVoice'];
|
|
37
|
+
setPendingMessages: ChatController['setPendingMessages'];
|
|
38
|
+
setIssues: ChatController['setIssues'];
|
|
39
|
+
/** Answers the sign-in gate; the index is the gate's place in the transcript. */
|
|
40
|
+
handleAuthenticated: (index: number, secret?: string) => Promise<void>;
|
|
41
|
+
handleBranch: ChatController['branch'];
|
|
42
|
+
handleSubmit: ChatController['submit'];
|
|
43
|
+
handleStop: ChatController['stop'];
|
|
44
|
+
handleMenuAction: ChatController['menuAction'];
|
|
45
|
+
handlePendingQueue: ChatController['queuePending'];
|
|
46
|
+
handlePendingMove: ChatController['movePending'];
|
|
47
|
+
handlePendingRestore: ChatController['restorePending'];
|
|
48
|
+
handleSendNow: ChatController['sendNow'];
|
|
49
|
+
/** Answers the approval gate; the index is the gate's place in the transcript. */
|
|
50
|
+
handleToolDecision: (index: number, action: ToolDecisionAction) => Promise<void>;
|
|
51
|
+
handleGenerationChange: ChatController['setGeneration'];
|
|
52
|
+
sendText: ChatController['sendText'];
|
|
36
53
|
/** The controller under it all, for a host that drives the chat from outside. */
|
|
37
|
-
controller:
|
|
38
|
-
iface: import("../../../src/interface/types").ComposerProfileInterface | null;
|
|
39
|
-
blocks: import("../../../src/interface/types").TranscriptBlock[];
|
|
40
|
-
streamBlocks: import("../../../src/interface/types").TranscriptBlock[];
|
|
41
|
-
chatStarted: boolean;
|
|
42
|
-
draftText: string;
|
|
43
|
-
pendingFiles: File[];
|
|
44
|
-
pendingVoice: File[];
|
|
45
|
-
pendingMessages: import("../../../src/interface/pending").ComposerPendingMessage[];
|
|
46
|
-
issues: import("../../../mod").AttachmentValidationIssue[];
|
|
47
|
-
failure: import("@theoremjs/web/client").ClientFailure | null;
|
|
48
|
-
answering: import("@theoremjs/web/client").AnsweringGate | null;
|
|
49
|
-
phase: import("../../../src/interface/composer-actions").ComposerRunPhase;
|
|
50
|
-
session: import("../../../src/interface/session").InterfaceTurnSession;
|
|
51
|
-
delivery: import("@theoremjs/web/client").MessageDelivery | null;
|
|
52
|
-
streaming: boolean;
|
|
53
|
-
options: import("@theoremjs/web/client").ChatOptionPicks | undefined;
|
|
54
|
+
controller: ChatController;
|
|
54
55
|
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { createChatController, } from '@theoremjs/web/client';
|
|
2
2
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useState, useSyncExternalStore, } from 'react';
|
|
3
|
+
import { backgroundJobs, groupTranscriptBlocks, } from "../client/transcript-groups.js";
|
|
4
|
+
import { liveTurnStart, useTurnClock } from "./use-turn-clock.js";
|
|
3
5
|
// why: Options reach the chat before the browser paints, and before a line can arrive; a server render runs no effects.
|
|
4
6
|
const useOptionsEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
5
7
|
/**
|
|
@@ -13,12 +15,20 @@ export function useTheoremChat(options) {
|
|
|
13
15
|
useOptionsEffect(() => chat.update(options));
|
|
14
16
|
const state = useSyncExternalStore(chat.subscribe, chat.getState, chat.getState);
|
|
15
17
|
const optionChoices = useMemo(() => (state.options ? { ...state.options, onChange: chat.pickOption } : undefined), [chat, state.options]);
|
|
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);
|
|
16
22
|
// why: The transcript draws each gate by its index; the chat answers the one gate that waits.
|
|
17
23
|
const handleAuthenticated = useCallback((_index, secret) => chat.authenticate(secret), [chat]);
|
|
18
24
|
const handleToolDecision = useCallback((_index, action) => chat.decide(action), [chat]);
|
|
19
25
|
return {
|
|
20
26
|
...state,
|
|
21
27
|
optionChoices,
|
|
28
|
+
shownBlocks,
|
|
29
|
+
turnClock,
|
|
30
|
+
workingSince: state.runningElsewhere?.since ?? liveTurnStart(groups, turnClock, state.streaming),
|
|
31
|
+
backgroundJobs: jobs,
|
|
22
32
|
setDraftText: chat.setDraftText,
|
|
23
33
|
setPendingFiles: chat.setPendingFiles,
|
|
24
34
|
setPendingVoice: chat.setPendingVoice,
|
|
@@ -36,7 +46,6 @@ export function useTheoremChat(options) {
|
|
|
36
46
|
handleToolDecision,
|
|
37
47
|
handleGenerationChange: chat.setGeneration,
|
|
38
48
|
sendText: chat.sendText,
|
|
39
|
-
/** The controller under it all, for a host that drives the chat from outside. */
|
|
40
49
|
controller: chat,
|
|
41
50
|
};
|
|
42
51
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DecisionAsset, DecisionJson } from '@theoremjs/agents';
|
|
2
2
|
import type { ClientFailure, DecisionInterface, DecisionReplyResult, DecisionTransport } from '@theoremjs/web/client';
|
|
3
|
-
import { type OneCallState } from './use-one-call.
|
|
3
|
+
import { type OneCallState } from './use-one-call.js';
|
|
4
4
|
export type TheoremDecisionState = {
|
|
5
5
|
/** The profile as the page sees it; null until the host describes it. */
|
|
6
6
|
iface: DecisionInterface | null;
|