@theoremjs/react 0.3.5-next.975.g3529c32 → 0.3.5-next.978.g2ef222f
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 +70 -2
- package/client/transcript-groups.d.ts +10 -0
- package/client/transcript-groups.js +22 -0
- package/hooks/use-theorem-chat.d.ts +25 -12
- package/hooks/use-theorem-chat.js +17 -0
- package/hooks/use-turn-clock.d.ts +14 -0
- package/hooks/use-turn-clock.js +59 -0
- package/index.d.ts +3 -1
- package/index.js +1 -0
- package/package.json +3 -3
- package/ui/ChatComposerBar.d.ts +17 -0
- package/ui/ChatComposerBar.js +129 -48
- package/ui/ChatComposerRow.d.ts +54 -0
- package/ui/ChatComposerRow.js +194 -0
- package/ui/ChatTranscript.d.ts +6 -0
- package/ui/ChatTranscript.js +5 -37
- package/ui/TheoremChat.d.ts +49 -2
- package/ui/TheoremChat.js +48 -27
- package/ui/index.d.ts +3 -2
- package/ui/index.js +1 -1
- package/ui/labels.d.ts +39 -0
- package/ui/labels.js +39 -0
package/README.md
CHANGED
|
@@ -176,9 +176,53 @@ 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). |
|
|
179
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). |
|
|
180
182
|
| `resolveMedia` | Turns a tool's reference into an address the page can load. See [Tool media](#tool-media). |
|
|
181
183
|
|
|
184
|
+
### The row composer's look
|
|
185
|
+
|
|
186
|
+
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.
|
|
187
|
+
|
|
188
|
+
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.
|
|
189
|
+
|
|
190
|
+
| Property | What it sets | Default |
|
|
191
|
+
| --- | --- | --- |
|
|
192
|
+
| `--theorem-composer-radius` | The surface's corner radius. Send and the send menu follow its curve. | `var(--radius-chat)` |
|
|
193
|
+
| `--theorem-composer-fill` | The fill of the surface and the tray. | `var(--color-background-popover)` |
|
|
194
|
+
| `--theorem-composer-shadow` | The shadow of the surface and the tray. | `var(--shadow-low)` |
|
|
195
|
+
| `--theorem-composer-padding` | The space inside the surface. | `var(--spacing-3)` |
|
|
196
|
+
| `--theorem-composer-gap` | The space between the pill row, the tray and the surface. | `var(--spacing-2)` |
|
|
197
|
+
| `--theorem-composer-inset` | How far the pill row and the tray sit in from the surface's sides. | `0px` |
|
|
198
|
+
| `--theorem-composer-tray-radius` | The open tray's corner radius. | the surface's radius |
|
|
199
|
+
| `--theorem-composer-tray-folded-radius` | The folded tray's corner radius. | half the folded tray's height, so its ends are round |
|
|
200
|
+
| `--theorem-composer-tray-padding` | The space inside the tray. | `var(--spacing-3)` |
|
|
201
|
+
| `--theorem-composer-pill-height` | The height of each pill. | `var(--size-element-lg)` |
|
|
202
|
+
| `--theorem-composer-pill-radius` | The corner radius of each pill and of the stop button. | `var(--radius-full)` |
|
|
203
|
+
| `--theorem-composer-pill-fill` | The fill of each pill. | the surface's fill |
|
|
204
|
+
| `--theorem-composer-pill-shadow` | The shadow of each pill. | the surface's shadow |
|
|
205
|
+
| `--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` |
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
<TheoremChat
|
|
209
|
+
endpoint="/api/theorem"
|
|
210
|
+
composerLayout="row"
|
|
211
|
+
composerIcons={{ working: <LeafSpinner /> }}
|
|
212
|
+
labels={{ en: { '@theorem.composer.pill.working_for': 'Thinking · {duration}' } }}
|
|
213
|
+
className="chat"
|
|
214
|
+
/>
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
```css
|
|
218
|
+
.chat {
|
|
219
|
+
--theorem-composer-radius: 22px;
|
|
220
|
+
--theorem-composer-pill-align: start;
|
|
221
|
+
}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
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"` or `"background"`), `theorem-composer-tray` (with `data-open`) and `theorem-composer-surface`.
|
|
225
|
+
|
|
182
226
|
### Tool media
|
|
183
227
|
|
|
184
228
|
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.
|
|
@@ -411,7 +455,7 @@ Three more values for `useLiveCall` come from the page. The profile declares eac
|
|
|
411
455
|
|
|
412
456
|
`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.
|
|
413
457
|
|
|
414
|
-
`model` and `effort` pick the call's model
|
|
458
|
+
`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.
|
|
415
459
|
|
|
416
460
|
```tsx
|
|
417
461
|
const call = useLiveCall({
|
|
@@ -497,9 +541,33 @@ function MyChat() {
|
|
|
497
541
|
|
|
498
542
|
`chat.phase` is `'idle'`, `'streaming'`, or `'gated'`. The actions are `handleSubmit`, `handleStop`, `handleSendNow`, and `handleToolDecision`.
|
|
499
543
|
|
|
544
|
+
`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`.
|
|
545
|
+
|
|
500
546
|
`handlePendingMove(id, direction)` moves a pending message among those of its kind. `ChatComposerBar` draws a move only when `composerPendingMoves` from `@theoremjs/agents/interface` says the message can go that way: a message alone in its kind has none.
|
|
501
547
|
|
|
502
|
-
|
|
548
|
+
### Place the pieces yourself
|
|
549
|
+
|
|
550
|
+
`TheoremChat` is built from two pieces in `/ui` that you can place apart: `TheoremChatComposer` and `TheoremChatTranscript`. Each takes the `chat` from `useTheoremChat` (its type is `TheoremChatState`) and the `iface` from `useTheoremInterface`. You decide where each one sits and when each one shows. Theorem moves neither of them.
|
|
551
|
+
|
|
552
|
+
```tsx
|
|
553
|
+
import { TheoremChatComposer, TheoremChatTranscript } from '@theoremjs/react/ui';
|
|
554
|
+
|
|
555
|
+
function Dock({ chat, iface }) {
|
|
556
|
+
const [open, setOpen] = useState(false);
|
|
557
|
+
return (
|
|
558
|
+
<div onFocus={() => setOpen(true)}>
|
|
559
|
+
{open && <TheoremChatTranscript chat={chat} iface={iface} />}
|
|
560
|
+
<TheoremChatComposer chat={chat} iface={iface} layout="row" />
|
|
561
|
+
</div>
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
```
|
|
565
|
+
|
|
566
|
+
`TheoremChatComposer` takes `layout`, `icons`, `placeholder`, and `inputRef`. `TheoremChatTranscript` takes the props of `ChatTranscript` that the chat does not give: `handle`, `emptyState`, `dividers`, `usage`, and `bodyKindPlacement`. Its `handle` is the handle of the profile when you leave it out. Put both pieces inside `TheoremThemeProvider`, as for `ChatTranscript`.
|
|
567
|
+
|
|
568
|
+
The two pieces read one clock: `chat.turnClock`. So the working pill of the composer and the status line of the transcript show the same time. `chat.workingSince` is when the reply in progress started, less its waits for approval. `chat.shownBlocks` is what the transcript shows: `chat.blocks`, then `chat.streamBlocks`.
|
|
569
|
+
|
|
570
|
+
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.
|
|
503
571
|
|
|
504
572
|
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.
|
|
505
573
|
|
|
@@ -150,3 +150,13 @@ export declare function assistantTurnTiming(args: {
|
|
|
150
150
|
export declare function toolCallLabel(tool: Extract<TranscriptBlock, {
|
|
151
151
|
kind: 'tool';
|
|
152
152
|
}>['tool']): string;
|
|
153
|
+
/** A tool call still running in the background, as the composer's pill row shows it. */
|
|
154
|
+
export type BackgroundJob = {
|
|
155
|
+
callId: string;
|
|
156
|
+
label: string;
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* The calls still running in the background, oldest first: each tool call whose last phase is
|
|
160
|
+
* `background`, until a late-results message carries its result.
|
|
161
|
+
*/
|
|
162
|
+
export declare function backgroundJobs(blocks: readonly TranscriptBlock[]): BackgroundJob[];
|
|
@@ -243,3 +243,25 @@ export function toolCallLabel(tool) {
|
|
|
243
243
|
const settled = phase === 'complete' || phase === 'error';
|
|
244
244
|
return (settled ? tool.activityPast : tool.activity) ?? humanize(tool.name);
|
|
245
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* The calls still running in the background, oldest first: each tool call whose last phase is
|
|
248
|
+
* `background`, until a late-results message carries its result.
|
|
249
|
+
*/
|
|
250
|
+
export function backgroundJobs(blocks) {
|
|
251
|
+
const landed = new Set();
|
|
252
|
+
for (const block of blocks) {
|
|
253
|
+
if (block.kind === 'late-results')
|
|
254
|
+
for (const id of block.operationIds)
|
|
255
|
+
landed.add(id);
|
|
256
|
+
}
|
|
257
|
+
const jobs = [];
|
|
258
|
+
for (const block of blocks) {
|
|
259
|
+
if (block.kind !== 'tool' || block.tool.state?.phase !== 'background')
|
|
260
|
+
continue;
|
|
261
|
+
const { operationId } = block.tool;
|
|
262
|
+
if (operationId && landed.has(operationId))
|
|
263
|
+
continue;
|
|
264
|
+
jobs.push({ callId: block.tool.callId, label: toolCallLabel(block.tool) });
|
|
265
|
+
}
|
|
266
|
+
return jobs;
|
|
267
|
+
}
|
|
@@ -10,23 +10,34 @@ export type UseTheoremChatOptions = ChatOptions;
|
|
|
10
10
|
export declare function useTheoremChat(options: UseTheoremChatOptions): {
|
|
11
11
|
optionChoices: {
|
|
12
12
|
onChange: (name: string, value: string) => void;
|
|
13
|
-
declared: import("../../../mod").ProfileOptions;
|
|
13
|
+
declared: import("../../../mod.ts").ProfileOptions;
|
|
14
14
|
values: Record<string, string>;
|
|
15
15
|
} | undefined;
|
|
16
|
+
/** What the transcript shows: the committed blocks, then the reply streaming in. */
|
|
17
|
+
shownBlocks: import("../../../src/interface/types.ts").TranscriptBlock[];
|
|
18
|
+
/**
|
|
19
|
+
* When each turn started and how long it waited on approvals. Pass it to `ChatTranscript`'s
|
|
20
|
+
* `clock` so its times agree with the composer's working pill.
|
|
21
|
+
*/
|
|
22
|
+
turnClock: import("./use-turn-clock.ts").TurnClock;
|
|
23
|
+
/** When the reply in progress started, its approval waits skipped; `undefined` when none runs. */
|
|
24
|
+
workingSince: number | undefined;
|
|
25
|
+
/** The tool calls still running in the background, oldest first, until their results land. */
|
|
26
|
+
backgroundJobs: import("../index.ts").BackgroundJob[];
|
|
16
27
|
setDraftText: (value: import("@theoremjs/web/client").ChatUpdate<string>) => void;
|
|
17
28
|
setPendingFiles: (value: import("@theoremjs/web/client").ChatUpdate<File[]>) => void;
|
|
18
29
|
setPendingVoice: (value: import("@theoremjs/web/client").ChatUpdate<File[]>) => void;
|
|
19
|
-
setPendingMessages: (value: import("@theoremjs/web/client").ChatUpdate<import("../../../src/interface/pending").ComposerPendingMessage[]>) => void;
|
|
20
|
-
setIssues: (value: import("@theoremjs/web/client").ChatUpdate<import("../../../mod").AttachmentValidationIssue[]>) => void;
|
|
30
|
+
setPendingMessages: (value: import("@theoremjs/web/client").ChatUpdate<import("../../../src/interface/pending.ts").ComposerPendingMessage[]>) => void;
|
|
31
|
+
setIssues: (value: import("@theoremjs/web/client").ChatUpdate<import("../../../mod.ts").AttachmentValidationIssue[]>) => void;
|
|
21
32
|
handleAuthenticated: (_index: number, secret?: string) => Promise<void>;
|
|
22
33
|
handleBranch: (index: number) => Promise<void>;
|
|
23
34
|
handleSubmit: () => Promise<void>;
|
|
24
35
|
handleStop: () => void;
|
|
25
|
-
handleMenuAction: (action: import("../../../src/interface/composer-actions").ComposerMenuAction) => void;
|
|
36
|
+
handleMenuAction: (action: import("../../../src/interface/composer-actions.ts").ComposerMenuAction) => void;
|
|
26
37
|
handlePendingQueue: (id: string) => void;
|
|
27
38
|
handlePendingMove: (id: string, direction: "up" | "down") => void;
|
|
28
39
|
handlePendingRestore: (id: string) => Promise<void>;
|
|
29
|
-
handleSendNow: (source?: import("../../../src/interface/pending").ComposerPendingMessage) => Promise<void>;
|
|
40
|
+
handleSendNow: (source?: import("../../../src/interface/pending.ts").ComposerPendingMessage) => Promise<void>;
|
|
30
41
|
handleToolDecision: (_index: number, action: ToolDecisionAction) => Promise<void>;
|
|
31
42
|
handleGenerationChange: (next: {
|
|
32
43
|
modelId: string;
|
|
@@ -35,20 +46,22 @@ export declare function useTheoremChat(options: UseTheoremChatOptions): {
|
|
|
35
46
|
sendText: (text: string, options?: SendTextOptions) => Promise<SentTurn | null>;
|
|
36
47
|
/** The controller under it all, for a host that drives the chat from outside. */
|
|
37
48
|
controller: import("@theoremjs/web/client").ChatController;
|
|
38
|
-
iface: import("../../../src/interface/types").ComposerProfileInterface | null;
|
|
39
|
-
blocks: import("../../../src/interface/types").TranscriptBlock[];
|
|
40
|
-
streamBlocks: import("../../../src/interface/types").TranscriptBlock[];
|
|
49
|
+
iface: import("../../../src/interface/types.ts").ComposerProfileInterface | null;
|
|
50
|
+
blocks: import("../../../src/interface/types.ts").TranscriptBlock[];
|
|
51
|
+
streamBlocks: import("../../../src/interface/types.ts").TranscriptBlock[];
|
|
41
52
|
chatStarted: boolean;
|
|
42
53
|
draftText: string;
|
|
43
54
|
pendingFiles: File[];
|
|
44
55
|
pendingVoice: File[];
|
|
45
|
-
pendingMessages: import("../../../src/interface/pending").ComposerPendingMessage[];
|
|
46
|
-
issues: import("../../../mod").AttachmentValidationIssue[];
|
|
56
|
+
pendingMessages: import("../../../src/interface/pending.ts").ComposerPendingMessage[];
|
|
57
|
+
issues: import("../../../mod.ts").AttachmentValidationIssue[];
|
|
47
58
|
failure: import("@theoremjs/web/client").ClientFailure | null;
|
|
48
59
|
answering: import("@theoremjs/web/client").AnsweringGate | null;
|
|
49
|
-
phase: import("../../../src/interface/composer-actions").ComposerRunPhase;
|
|
50
|
-
session: import("../../../src/interface/session").InterfaceTurnSession;
|
|
60
|
+
phase: import("../../../src/interface/composer-actions.ts").ComposerRunPhase;
|
|
61
|
+
session: import("../../../src/interface/session.ts").InterfaceTurnSession;
|
|
51
62
|
delivery: import("@theoremjs/web/client").MessageDelivery | null;
|
|
52
63
|
streaming: boolean;
|
|
53
64
|
options: import("@theoremjs/web/client").ChatOptionPicks | undefined;
|
|
54
65
|
};
|
|
66
|
+
/** What `useTheoremChat` returns: the chat's state and its actions. */
|
|
67
|
+
export type TheoremChatState = ReturnType<typeof useTheoremChat>;
|
|
@@ -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,27 @@ 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
|
+
/** What the transcript shows: the committed blocks, then the reply streaming in. */
|
|
29
|
+
shownBlocks,
|
|
30
|
+
/**
|
|
31
|
+
* When each turn started and how long it waited on approvals. Pass it to `ChatTranscript`'s
|
|
32
|
+
* `clock` so its times agree with the composer's working pill.
|
|
33
|
+
*/
|
|
34
|
+
turnClock,
|
|
35
|
+
/** When the reply in progress started, its approval waits skipped; `undefined` when none runs. */
|
|
36
|
+
workingSince: liveTurnStart(groups, turnClock, state.streaming),
|
|
37
|
+
/** The tool calls still running in the background, oldest first, until their results land. */
|
|
38
|
+
backgroundJobs: jobs,
|
|
22
39
|
setDraftText: chat.setDraftText,
|
|
23
40
|
setPendingFiles: chat.setPendingFiles,
|
|
24
41
|
setPendingVoice: chat.setPendingVoice,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type TranscriptTurnGroup, type TurnSpan } from '../client/transcript-groups.ts';
|
|
2
|
+
/**
|
|
3
|
+
* When each turn was first seen, and how long each sat paused on approvals.
|
|
4
|
+
* invariant: One clock per chat: the transcript's status line and the composer's working pill
|
|
5
|
+
* read the same one, so they show the same time.
|
|
6
|
+
*/
|
|
7
|
+
export type TurnClock = {
|
|
8
|
+
timeOf: (key: string) => number;
|
|
9
|
+
spans: ReadonlyMap<string, TurnSpan>;
|
|
10
|
+
};
|
|
11
|
+
/** The chat's turn clock over its grouped transcript. */
|
|
12
|
+
export declare function useTurnClock(groups: readonly TranscriptTurnGroup[], streaming: boolean): TurnClock;
|
|
13
|
+
/** When the reply in progress started, its approval waits skipped; `undefined` when none runs. */
|
|
14
|
+
export declare function liveTurnStart(groups: readonly TranscriptTurnGroup[], clock: TurnClock, streaming: boolean): number | undefined;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { replyKey } from "../client/transcript-groups.js";
|
|
3
|
+
/** First-seen time per group key, so timestamps don't jump while streaming. */
|
|
4
|
+
function useFirstSeen(keys) {
|
|
5
|
+
const times = useRef(new Map());
|
|
6
|
+
const now = Date.now();
|
|
7
|
+
for (const key of keys) {
|
|
8
|
+
if (!times.current.has(key))
|
|
9
|
+
times.current.set(key, now);
|
|
10
|
+
}
|
|
11
|
+
// why: A key first asked for later (a divider's group) keeps the time it was first asked for.
|
|
12
|
+
return (key) => {
|
|
13
|
+
const known = times.current.get(key);
|
|
14
|
+
if (known !== undefined)
|
|
15
|
+
return known;
|
|
16
|
+
const at = Date.now();
|
|
17
|
+
times.current.set(key, at);
|
|
18
|
+
return at;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Each turn's span, keyed by the user group that started it. A turn stops at
|
|
23
|
+
* a gate and streams again under the same prompt once it's answered; the wait
|
|
24
|
+
* in between counts as paused, not worked.
|
|
25
|
+
*/
|
|
26
|
+
function useTurnSpans(streaming, lastUserKey) {
|
|
27
|
+
const spans = useRef(new Map());
|
|
28
|
+
// why: A transcript can mount already streaming, on the first send; that's the start.
|
|
29
|
+
const wasStreaming = useRef(false);
|
|
30
|
+
if (lastUserKey && streaming !== wasStreaming.current) {
|
|
31
|
+
const now = Date.now();
|
|
32
|
+
const span = spans.current.get(lastUserKey);
|
|
33
|
+
if (streaming) {
|
|
34
|
+
const pausedMs = span?.endedAt === undefined ? 0 : span.pausedMs + now - span.endedAt;
|
|
35
|
+
spans.current.set(lastUserKey, { pausedMs });
|
|
36
|
+
}
|
|
37
|
+
else if (span) {
|
|
38
|
+
spans.current.set(lastUserKey, { ...span, endedAt: now });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
wasStreaming.current = streaming;
|
|
42
|
+
return spans.current;
|
|
43
|
+
}
|
|
44
|
+
/** The chat's turn clock over its grouped transcript. */
|
|
45
|
+
export function useTurnClock(groups, streaming) {
|
|
46
|
+
const timeOf = useFirstSeen(groups.map((group, index) => (group.kind === 'user' ? group.key : replyKey(groups, index))));
|
|
47
|
+
const spans = useTurnSpans(streaming, groups.findLast((group) => group.kind === 'user')?.key);
|
|
48
|
+
return { timeOf, spans };
|
|
49
|
+
}
|
|
50
|
+
/** When the reply in progress started, its approval waits skipped; `undefined` when none runs. */
|
|
51
|
+
export function liveTurnStart(groups, clock, streaming) {
|
|
52
|
+
if (!streaming)
|
|
53
|
+
return undefined;
|
|
54
|
+
const prompt = groups.findLast((group) => group.kind === 'user');
|
|
55
|
+
if (!prompt)
|
|
56
|
+
return undefined;
|
|
57
|
+
const span = clock.spans.get(prompt.key);
|
|
58
|
+
return span ? clock.timeOf(prompt.key) + span.pausedMs : undefined;
|
|
59
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -8,9 +8,11 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
export * from '@theoremjs/web/client';
|
|
11
|
+
export { type BackgroundJob, backgroundJobs } from './client/transcript-groups.ts';
|
|
11
12
|
export { type EmbeddingIndex, type IndexProgress, useEmbeddingIndex, } from './hooks/use-embedding-index.ts';
|
|
12
|
-
export { type SendTextOptions, type SentTurn, type UseTheoremChatOptions, useTheoremChat, } from './hooks/use-theorem-chat.ts';
|
|
13
|
+
export { type SendTextOptions, type SentTurn, type TheoremChatState, type UseTheoremChatOptions, useTheoremChat, } from './hooks/use-theorem-chat.ts';
|
|
13
14
|
export { type TheoremDecisionState, useTheoremDecision } from './hooks/use-theorem-decision.ts';
|
|
14
15
|
export { type TheoremEmbeddingState, useTheoremEmbedding, } from './hooks/use-theorem-embedding.ts';
|
|
15
16
|
export { type TheoremHostCall, type TheoremHostState, useTheoremHost, } from './hooks/use-theorem-host.ts';
|
|
16
17
|
export { type TheoremInterfaceState, useTheoremInterface } from './hooks/use-theorem-interface.ts';
|
|
18
|
+
export type { TurnClock } from './hooks/use-turn-clock.ts';
|
package/index.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
export * from '@theoremjs/web/client';
|
|
11
|
+
export { backgroundJobs } from "./client/transcript-groups.js";
|
|
11
12
|
export { useEmbeddingIndex, } from "./hooks/use-embedding-index.js";
|
|
12
13
|
export { useTheoremChat, } from "./hooks/use-theorem-chat.js";
|
|
13
14
|
export { useTheoremDecision } from "./hooks/use-theorem-decision.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoremjs/react",
|
|
3
|
-
"version": "0.3.5-next.
|
|
3
|
+
"version": "0.3.5-next.978.g2ef222f",
|
|
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.
|
|
64
|
-
"@theoremjs/web": "^0.3.5-next.
|
|
63
|
+
"@theoremjs/agents": "^0.3.5-next.978.g2ef222f",
|
|
64
|
+
"@theoremjs/web": "^0.3.5-next.978.g2ef222f"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@astryxdesign/core": {
|
package/ui/ChatComposerBar.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { type ChatComposerInputHandle } from '@astryxdesign/core/Chat';
|
|
|
2
2
|
import { type AttachmentValidationIssue, type ComposerMenuAction, type ComposerPendingMessage, type ComposerProfileInterface, type ComposerRunPhase, type LiveProfileInterface } from '@theoremjs/agents/interface';
|
|
3
3
|
import type { ClientFailure } from '@theoremjs/web/client';
|
|
4
4
|
import { type ReactNode } from 'react';
|
|
5
|
+
import type { BackgroundJob } from '../client/transcript-groups.ts';
|
|
6
|
+
import { type ComposerRowIcons } from './ChatComposerRow.tsx';
|
|
5
7
|
/** An option the profile declares: its allowed values, the one chosen, and how to choose another. */
|
|
6
8
|
/** The effort selector's icon. The studio's Agents list shows the same one. */
|
|
7
9
|
export declare const EFFORT_ICON: import("react").ForwardRefExoticComponent<import("@tabler/icons-react").IconProps & import("react").RefAttributes<SVGSVGElement>>;
|
|
@@ -18,8 +20,23 @@ export type OptionChoices = {
|
|
|
18
20
|
values: Readonly<Record<string, string>>;
|
|
19
21
|
onChange: (name: string, value: string) => void;
|
|
20
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* How the composer is laid out. `stacked` (default): Astryx's composer, the field above a row of
|
|
25
|
+
* controls, with stop on the send button. `row`: the field and its buttons on one line, which
|
|
26
|
+
* stacks once the text wraps; a pill row above it shows the reply in progress, with stop on its
|
|
27
|
+
* pill, and the background jobs; while a reply runs the one button opens the send menu.
|
|
28
|
+
*/
|
|
29
|
+
export type ComposerLayout = 'stacked' | 'row';
|
|
21
30
|
export type ChatComposerBarProps = {
|
|
22
31
|
iface: ComposerProfileInterface;
|
|
32
|
+
/** Default `stacked`. */
|
|
33
|
+
layout?: ComposerLayout;
|
|
34
|
+
/** The tool calls running in the background; the `row` layout shows each as a pill. */
|
|
35
|
+
backgroundJobs?: readonly BackgroundJob[];
|
|
36
|
+
/** When the reply in progress started, its approval waits skipped; the `row` layout's working pill counts from it. */
|
|
37
|
+
workingSince?: number;
|
|
38
|
+
/** Glyphs the `row` layout draws; each one left out keeps Theorem's. See {@link ComposerRowIcons}. */
|
|
39
|
+
icons?: ComposerRowIcons;
|
|
23
40
|
draftText: string;
|
|
24
41
|
pendingFiles: readonly File[];
|
|
25
42
|
pendingVoice: readonly File[];
|