@theoremjs/react 0.3.5-next.1041.gcd563a8 → 0.3.5-next.1043.ge9acd49
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`, `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`, `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). |
|
|
188
188
|
|
|
189
189
|
### The row composer's look
|
|
190
190
|
|
|
@@ -211,6 +211,7 @@ Each part of the look is a CSS custom property. Set it on any element above the
|
|
|
211
211
|
| `--theorem-composer-pill-radius` | The corner radius of each pill and of the stop button. | `var(--radius-full)` |
|
|
212
212
|
| `--theorem-composer-pill-fill` | The fill of each pill. | the surface's fill |
|
|
213
213
|
| `--theorem-composer-pill-shadow` | The shadow of each pill. | the surface's shadow |
|
|
214
|
+
| `--theorem-composer-pill-end-padding` | The space between the working pill's stop button and the pill's end. | half the pill's height less the stop button's, so the same ring of space goes round the button |
|
|
214
215
|
| `--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` |
|
|
215
216
|
|
|
216
217
|
```tsx
|
|
@@ -744,7 +745,7 @@ function Dock({ chat, iface }) {
|
|
|
744
745
|
}
|
|
745
746
|
```
|
|
746
747
|
|
|
747
|
-
`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`, 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`, `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
749
|
|
|
749
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.
|
|
750
751
|
|
|
@@ -857,6 +858,23 @@ These rules apply:
|
|
|
857
858
|
- A reply on its way has no details row yet.
|
|
858
859
|
- Without `slots.details`, the row is unchanged. Without `turnKeyOf`, messages join as before.
|
|
859
860
|
|
|
861
|
+
### Date messages by your own record
|
|
862
|
+
|
|
863
|
+
A reply is dated from its end, and any other message from when the page first showed it. To date messages by your own record, pass `turnTimeOf`: it takes a block's `host` value and returns when the block was written, in milliseconds since the epoch, or `undefined`.
|
|
864
|
+
|
|
865
|
+
```tsx
|
|
866
|
+
type Said = { writtenAt?: number };
|
|
867
|
+
|
|
868
|
+
<ChatTranscript<Said>
|
|
869
|
+
blocks={blocks}
|
|
870
|
+
handle="Harbor"
|
|
871
|
+
turnTimeOf={(host) => host.writtenAt}
|
|
872
|
+
/>;
|
|
873
|
+
```
|
|
874
|
+
|
|
875
|
+
- The user's message takes the first time its blocks give, and a reply takes the last.
|
|
876
|
+
- Your time replaces Theorem's. A message whose blocks give none keeps Theorem's.
|
|
877
|
+
|
|
860
878
|
`ActionCard` is the frame of the gate cards: their width, a title with an `icon` before it and a `tag` at its end, the body (`children`), and a row of buttons (`actions`) at the end. `ApprovalCard` and `AuthChallengeCard` are built on it. Build your own cards on it so that they look like the gate cards.
|
|
861
879
|
|
|
862
880
|
## Panes, motion and trace charts
|
|
@@ -86,6 +86,10 @@ export type ComposeAssistantTurnOptions = {
|
|
|
86
86
|
};
|
|
87
87
|
/** The app's key for the turn a block's `host` value belongs to. */
|
|
88
88
|
export type TurnKeyOf = (host: JsonObject) => string;
|
|
89
|
+
/** When the app says a block's `host` value was written, in milliseconds since the epoch. */
|
|
90
|
+
export type TurnTimeOf = (host: JsonObject) => number | undefined;
|
|
91
|
+
/** The times the app gives a message's `host` values, in block order. */
|
|
92
|
+
export declare function hostTimes(host: readonly JsonObject[] | undefined, timeOf: TurnTimeOf | undefined): number[];
|
|
89
93
|
/**
|
|
90
94
|
* Blocks as turns: neighbours from the same side share one, unless a block is
|
|
91
95
|
* in `breaks`, which always starts its own, or `keyOf` gives them different
|
|
@@ -74,6 +74,12 @@ function joinsTurn(last, isUser) {
|
|
|
74
74
|
return false;
|
|
75
75
|
return !(last.kind === 'user' && last.stop);
|
|
76
76
|
}
|
|
77
|
+
/** The times the app gives a message's `host` values, in block order. */
|
|
78
|
+
export function hostTimes(host, timeOf) {
|
|
79
|
+
if (!timeOf)
|
|
80
|
+
return [];
|
|
81
|
+
return (host ?? []).flatMap((value) => timeOf(value) ?? []);
|
|
82
|
+
}
|
|
77
83
|
/**
|
|
78
84
|
* Whether the app lets two neighbouring blocks share a turn: their keys are equal. A block with no
|
|
79
85
|
* `host` value has no key, and shares a turn only with another that has none.
|
|
@@ -34,8 +34,8 @@ const WAVE_CONFIG = {
|
|
|
34
34
|
};
|
|
35
35
|
function resolveWaveDimensions(variant) {
|
|
36
36
|
const cfg = WAVE_CONFIG[variant] ?? WAVE_CONFIG.default;
|
|
37
|
-
const
|
|
38
|
-
return { ...cfg,
|
|
37
|
+
const barGap = (cfg.viewWidth - cfg.strokeWidth * cfg.barCount) / (cfg.barCount + 1);
|
|
38
|
+
return { ...cfg, barGap };
|
|
39
39
|
}
|
|
40
40
|
/** One frame's bar targets. The live ref's levels win over the last render's; a frozen wave moves to none. */
|
|
41
41
|
function frameTargets(snap, phases, timeMs) {
|
|
@@ -90,15 +90,15 @@ function usePaintedWave(svgRef, snapRef, phases, barCount, viewHeight) {
|
|
|
90
90
|
}, [svgRef, snapRef, phases, barCount, viewHeight]);
|
|
91
91
|
}
|
|
92
92
|
export function InkWaveform({ status = 'disconnected', inputLevel = 0, outputLevel = 0, levelsRef, toolActive = false, frozen = false, variant = 'default', }) {
|
|
93
|
-
const { viewWidth, viewHeight, preserveAspect, strokeWidth, barCount,
|
|
93
|
+
const { viewWidth, viewHeight, preserveAspect, strokeWidth, barCount, barGap } = resolveWaveDimensions(variant);
|
|
94
94
|
const phases = useMemo(() => inkWavePhases(barCount), [barCount]);
|
|
95
95
|
const xs = useMemo(() => {
|
|
96
96
|
const next = new Array(barCount);
|
|
97
97
|
for (let index = 0; index < barCount; index++) {
|
|
98
|
-
next[index] =
|
|
98
|
+
next[index] = barGap + index * (strokeWidth + barGap) + strokeWidth / 2;
|
|
99
99
|
}
|
|
100
100
|
return next;
|
|
101
|
-
}, [barCount,
|
|
101
|
+
}, [barCount, barGap, strokeWidth]);
|
|
102
102
|
const svgRef = useRef(null);
|
|
103
103
|
const snapRef = useRef({
|
|
104
104
|
status,
|
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.1043.ge9acd49",
|
|
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.1043.ge9acd49",
|
|
64
|
+
"@theoremjs/web": "^0.3.5-next.1043.ge9acd49"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@astryxdesign/core": {
|
package/ui/ChatComposerRow.js
CHANGED
|
@@ -54,7 +54,7 @@ const PILL = {
|
|
|
54
54
|
/** why: The stop button sits in the pill's end with the same ring of space all round it. */
|
|
55
55
|
const WORKING_PILL = {
|
|
56
56
|
...PILL,
|
|
57
|
-
paddingInlineEnd: `calc((${PILL_HEIGHT} - var(--size-element-sm)) / 2)
|
|
57
|
+
paddingInlineEnd: knob('pill-end-padding', `calc((${PILL_HEIGHT} - var(--size-element-sm)) / 2)`),
|
|
58
58
|
};
|
|
59
59
|
/** invariant: The pill row keeps one pill's height whatever it holds, so the composer never moves. */
|
|
60
60
|
const PILL_ROW = { paddingInline: INSET, minHeight: PILL_HEIGHT };
|
package/ui/ChatTranscript.d.ts
CHANGED
|
@@ -88,6 +88,13 @@ export type ChatTranscriptProps<Host extends JsonObject = JsonObject> = {
|
|
|
88
88
|
* never reads what a key means. Without it, neighbours from one side share a message.
|
|
89
89
|
*/
|
|
90
90
|
turnKeyOf?: (host: Host) => string;
|
|
91
|
+
/**
|
|
92
|
+
* Dates messages by the app's own record: given a block's `host`, return when the block was
|
|
93
|
+
* written, in milliseconds since the epoch, or `undefined` when the value holds no time. The
|
|
94
|
+
* person's message takes the first time its blocks give, a reply the last. A message with no
|
|
95
|
+
* time from the app keeps Theorem's: from the reply's end, or from when the page first showed it.
|
|
96
|
+
*/
|
|
97
|
+
turnTimeOf?: (host: Host) => number | undefined;
|
|
91
98
|
};
|
|
92
99
|
/** Image-profile display: `ratio` is the profile's pinned aspect ratio, if any. */
|
|
93
100
|
export type ImageOutput = {
|
package/ui/ChatTranscript.js
CHANGED
|
@@ -22,7 +22,7 @@ import { IconCheck, IconCopy } from '@tabler/icons-react';
|
|
|
22
22
|
import { stopText } from '@theoremjs/agents/interface';
|
|
23
23
|
import { citationsFromBlock } from '@theoremjs/web/client';
|
|
24
24
|
import { createContext, Fragment, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
25
|
-
import { assistantTurnCopyText, assistantTurnTiming, composeAssistantTurn, groupTranscriptBlocks, pendingPromptOf, promptReplyKey, promptTime, toolCallLabel, workStatus, } from "../client/transcript-groups.js";
|
|
25
|
+
import { assistantTurnCopyText, assistantTurnTiming, composeAssistantTurn, groupTranscriptBlocks, hostTimes, pendingPromptOf, promptReplyKey, promptTime, toolCallLabel, workStatus, } from "../client/transcript-groups.js";
|
|
26
26
|
import { useSecondTicker } from "../hooks/use-second-ticker.js";
|
|
27
27
|
import { useTurnClock } from "../hooks/use-turn-clock.js";
|
|
28
28
|
import { useDisclosureMotion } from "./disclosure-motion.js";
|
|
@@ -766,9 +766,11 @@ export function ChatTranscript(props) {
|
|
|
766
766
|
: undefined;
|
|
767
767
|
const keyOf = props.turnKeyOf;
|
|
768
768
|
const turnKeyOf = keyOf ? (host) => keyOf(host) : undefined;
|
|
769
|
-
|
|
769
|
+
const dateOf = props.turnTimeOf;
|
|
770
|
+
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 }) }) }) }) }) }) }) }) }) }));
|
|
770
772
|
}
|
|
771
|
-
function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToolDecision, answering = null, onAuthenticated, emptyState, dividers, imageOutput, bodyKindPlacement, stepLayout, labels, clock, turnKeyOf, }) {
|
|
773
|
+
function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToolDecision, answering = null, onAuthenticated, emptyState, dividers, imageOutput, bodyKindPlacement, stepLayout, labels, clock, turnKeyOf, turnTimeOf, }) {
|
|
772
774
|
const groups = useMemo(() => groupTranscriptBlocks(blocks, dividers && new Set(Object.keys(dividers)), turnKeyOf), [blocks, dividers, turnKeyOf]);
|
|
773
775
|
const own = useTurnClock(groups, streaming);
|
|
774
776
|
const { timeOf, replyStart } = clock ?? own;
|
|
@@ -787,7 +789,7 @@ function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToo
|
|
|
787
789
|
const next = groups[index + 1];
|
|
788
790
|
const error = isBareFailure(next) ? failureOf(next) : undefined;
|
|
789
791
|
const status = index === lastUser ? (delivery ?? undefined) : undefined;
|
|
790
|
-
return (_jsx(UserTurn, { blocks: group.blocks, host: group.host, at: promptTime(groups, index, timeOf), status: status, stopped: stopText(group.stop, group.blocks, labels), error: error, isNewest: index === groups.length - 1 }, group.key));
|
|
792
|
+
return (_jsx(UserTurn, { blocks: group.blocks, host: group.host, at: hostTimes(group.host, turnTimeOf)[0] ?? promptTime(groups, index, timeOf), status: status, stopped: stopText(group.stop, group.blocks, labels), error: error, isNewest: index === groups.length - 1 }, group.key));
|
|
791
793
|
};
|
|
792
794
|
const turnOf = (group, index) => {
|
|
793
795
|
if (group.kind === 'user')
|
|
@@ -801,7 +803,7 @@ function ChatTranscriptBody({ blocks, handle, streaming = false, delivery, onToo
|
|
|
801
803
|
replyStart,
|
|
802
804
|
});
|
|
803
805
|
// why: A reply is dated when it last stopped: a reply that just finished reads "now".
|
|
804
|
-
const at = endedAt ?? timeOf(key);
|
|
806
|
+
const at = hostTimes(group.host, turnTimeOf).at(-1) ?? endedAt ?? timeOf(key);
|
|
805
807
|
return (_jsx(AssistantTurn, { ...turn, ...timing, blocks: group.blocks, streaming: live, at: at, error: failureOf(group), stopped: stopText(group.stop, group.blocks, labels), usage: group.usage, host: group.host, isNewest: index === groups.length - 1 }, key));
|
|
806
808
|
};
|
|
807
809
|
const turns = groups.flatMap((group, index) => {
|