@theoremjs/react 0.3.5-next.1041.gcd563a8 → 0.3.5-next.1042.gfa994b5
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 +19 -2
- package/client/transcript-groups.d.ts +4 -0
- package/client/transcript-groups.js +6 -0
- package/package.json +3 -3
- package/ui/ChatTranscript.d.ts +7 -0
- package/ui/ChatTranscript.js +7 -5
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
|
|
|
@@ -744,7 +744,7 @@ function Dock({ chat, iface }) {
|
|
|
744
744
|
}
|
|
745
745
|
```
|
|
746
746
|
|
|
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`.
|
|
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`, `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
748
|
|
|
749
749
|
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
750
|
|
|
@@ -857,6 +857,23 @@ These rules apply:
|
|
|
857
857
|
- A reply on its way has no details row yet.
|
|
858
858
|
- Without `slots.details`, the row is unchanged. Without `turnKeyOf`, messages join as before.
|
|
859
859
|
|
|
860
|
+
### Date messages by your own record
|
|
861
|
+
|
|
862
|
+
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`.
|
|
863
|
+
|
|
864
|
+
```tsx
|
|
865
|
+
type Said = { writtenAt?: number };
|
|
866
|
+
|
|
867
|
+
<ChatTranscript<Said>
|
|
868
|
+
blocks={blocks}
|
|
869
|
+
handle="Harbor"
|
|
870
|
+
turnTimeOf={(host) => host.writtenAt}
|
|
871
|
+
/>;
|
|
872
|
+
```
|
|
873
|
+
|
|
874
|
+
- The user's message takes the first time its blocks give, and a reply takes the last.
|
|
875
|
+
- Your time replaces Theorem's. A message whose blocks give none keeps Theorem's.
|
|
876
|
+
|
|
860
877
|
`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
878
|
|
|
862
879
|
## 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.
|
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.1042.gfa994b5",
|
|
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.1042.gfa994b5",
|
|
64
|
+
"@theoremjs/web": "^0.3.5-next.1042.gfa994b5"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@astryxdesign/core": {
|
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) => {
|