@theoremjs/react 0.3.5-next.1035.g7656c60 → 0.3.5-next.1037.g9282f21
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 +7 -1
- package/components/live/use-live-call.d.ts +1 -0
- package/components/live/use-live-call.js +6 -0
- package/components/live/use-live-runner-controls.d.ts +4 -1
- package/components/live/use-live-runner-controls.js +71 -3
- package/components/live/use-live-session-client.js +3 -0
- package/live.d.ts +1 -1
- package/package.json +3 -3
- package/ui/ChatComposerBar.d.ts +7 -1
- package/ui/ChatComposerBar.js +8 -3
- package/ui/ChatComposerRow.d.ts +2 -0
- package/ui/ChatComposerRow.js +4 -2
- package/ui/TheoremChat.d.ts +6 -2
- package/ui/TheoremChat.js +3 -3
package/README.md
CHANGED
|
@@ -179,6 +179,7 @@ To draw your own figures like the trace panel does, `@theoremjs/react/ui` also e
|
|
|
179
179
|
| `composer` | `false` leaves the composer out. The chat is the transcript alone, and your own control sends through `chatRef`. Default: `true`. |
|
|
180
180
|
| `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'`. |
|
|
181
181
|
| `composerEmptyAction` | Shows in place of the send button while the composer has nothing to send, for example a button that starts a call. It never replaces stop or the send menu. `TheoremChatComposer` and `ChatComposerBar` take it as `emptyAction`. Default: the send button. |
|
|
182
|
+
| `renderComposerStatus` | Draws the composer's problem: a send that failed (`type: 'error'`), or files or a voice note it could not take (`type: 'warning'`), with its `message`. Give what you draw its own `role`: `alert` for an error, `status` for a warning. `TheoremChatComposer` and `ChatComposerBar` take it as `renderStatus`. Default: Astryx's status, in the status colour. |
|
|
182
183
|
| `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). |
|
|
183
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). |
|
|
184
185
|
| `resolveMedia` | Turns a tool's reference into an address the page can load. See [Tool media](#tool-media). |
|
|
@@ -500,6 +501,10 @@ This code opens `wss://<your host>/api/live/relay?profile=<id>`. To send your ow
|
|
|
500
501
|
|
|
501
502
|
To get the messages your relay sends with `liveHostEnvelope`, give `useLiveCall` an `onHostMessage`. See [Send the page your own messages](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#send-the-page-your-own-messages).
|
|
502
503
|
|
|
504
|
+
`startCall`, and the start buttons of `LiveRunner`, open the call's audio inside the press, before `connection` is called. When your own press waits before it calls `startCall`, call `call.prepareAudio()` first in that press: the call then uses that audio and does not open another. See [Open the audio in the press](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#open-the-audio-in-the-press).
|
|
505
|
+
|
|
506
|
+
To know when a call ends, and why, give `useLiveCall` an `onCallEnded`. It is called once for each call the person starts, with a `LiveCallEnd`: `cancelled` when the person ends the call before it connects, `user` after it connects, `agent` when the other side closes it, and `failed` with the error. A call whose component unmounts ends as `user`, or `cancelled` before it connects. See [Know when the call ended](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#know-when-the-call-ended).
|
|
507
|
+
|
|
503
508
|
`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.
|
|
504
509
|
|
|
505
510
|
### A call across pages
|
|
@@ -570,6 +575,7 @@ The relay receives the absence duration. If the profile sets `live.resumed`, the
|
|
|
570
575
|
The kernel validates native state before resumption. A protocol, provider, model, connection, key slot, or history mismatch rebuilds from portable history.
|
|
571
576
|
It emits `provider_warning`. The client then discards the incompatible checkpoint and retains the history.
|
|
572
577
|
A rebuilt session with history does not repeat the initial greeting.
|
|
578
|
+
When your relay knows that the call is new, for example a new call for a person who has history, set `opens: 'new'` on the `runSession` request, and the agent greets. `opens: 'continuing'` gives the resumed prompt after `afterMs`, as a reconnect does.
|
|
573
579
|
|
|
574
580
|
A failed call does not reconnect. Without `live.sessionResumption`, a provider-ended call is complete.
|
|
575
581
|
|
|
@@ -734,7 +740,7 @@ function Dock({ chat, iface }) {
|
|
|
734
740
|
}
|
|
735
741
|
```
|
|
736
742
|
|
|
737
|
-
`TheoremChatComposer` takes `layout`, `icons`, `pills`, `placeholder`, `inputRef`, `inputComponent`, `triggers`, `refText`, and `
|
|
743
|
+
`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`, 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`.
|
|
738
744
|
|
|
739
745
|
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.
|
|
740
746
|
|
|
@@ -60,6 +60,7 @@ export declare function useLiveCall({ iface, connection, video, ...options }: Li
|
|
|
60
60
|
gatePrompt: import("@theoremjs/web/client").LiveToolGatePrompt | null;
|
|
61
61
|
setTextDraft: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
62
62
|
handleEnd: () => void;
|
|
63
|
+
prepareAudio: () => void;
|
|
63
64
|
startCall: (options: {
|
|
64
65
|
video: boolean;
|
|
65
66
|
}) => void;
|
|
@@ -84,6 +84,9 @@ export function useLiveCall({ iface, connection, video, ...options }) {
|
|
|
84
84
|
isMuted: ui.isMuted,
|
|
85
85
|
voiceEnabled: voiceAvailable,
|
|
86
86
|
}), [ui.activeTool, ui.connectPhase, ui.isMuted, ui.status, voiceAvailable]);
|
|
87
|
+
const onCallEndedRef = useRef(options.onCallEnded);
|
|
88
|
+
onCallEndedRef.current = options.onCallEnded;
|
|
89
|
+
const callEnded = useCallback((end) => onCallEndedRef.current?.(end), []);
|
|
87
90
|
// why: One feed per call: every session it opens adds its records.
|
|
88
91
|
const traces = useMemo(createTraceFeed, []);
|
|
89
92
|
const { clientRef, ensureClient, clearClient } = useLiveSessionClient({
|
|
@@ -100,6 +103,7 @@ export function useLiveCall({ iface, connection, video, ...options }) {
|
|
|
100
103
|
onTurnEvent: options.onTurnEvent,
|
|
101
104
|
onSessionClosing: options.onSessionClosing,
|
|
102
105
|
onSessionReady: options.onSessionReady,
|
|
106
|
+
onCallEnded: options.onCallEnded,
|
|
103
107
|
onHostMessage: options.onHostMessage,
|
|
104
108
|
voiceAvailable,
|
|
105
109
|
traces,
|
|
@@ -134,6 +138,7 @@ export function useLiveCall({ iface, connection, video, ...options }) {
|
|
|
134
138
|
sessionPermissionsRef: ui.sessionPermissionsRef,
|
|
135
139
|
ensureClient,
|
|
136
140
|
clearClient,
|
|
141
|
+
callEnded,
|
|
137
142
|
cancelGateDecision: gate.cancelGateDecision,
|
|
138
143
|
stopVideo: ui.stopVideo,
|
|
139
144
|
resetCaptions: ui.resetCaptions,
|
|
@@ -225,6 +230,7 @@ export function useLiveCall({ iface, connection, video, ...options }) {
|
|
|
225
230
|
gatePrompt: gate.gatePrompt,
|
|
226
231
|
setTextDraft: ui.setTextDraft,
|
|
227
232
|
handleEnd,
|
|
233
|
+
prepareAudio: controls.prepareAudio,
|
|
228
234
|
startCall,
|
|
229
235
|
handleRestart,
|
|
230
236
|
handleSendText: controls.handleSendText,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LiveConnection, LiveConnectPhase, LiveSessionClient, LiveSessionStatus } from '@theoremjs/web/client';
|
|
1
|
+
import type { LiveCallEnd, LiveConnection, LiveConnectPhase, LiveSessionClient, LiveSessionStatus } from '@theoremjs/web/client';
|
|
2
2
|
import { type Dispatch, type MutableRefObject, type SetStateAction } from 'react';
|
|
3
3
|
import { type LiveCaptionState } from '../../client/live/live-captions.js';
|
|
4
4
|
import { type LiveFacingMode, type LiveVideoCapture, type LiveVideoOptions } from '../../client/live/live-video.js';
|
|
@@ -14,6 +14,8 @@ export declare function useLiveRunnerControls(args: {
|
|
|
14
14
|
sessionPermissionsRef: MutableRefObject<string[]>;
|
|
15
15
|
ensureClient: (connection: LiveConnection) => LiveSessionClient;
|
|
16
16
|
clearClient: () => void;
|
|
17
|
+
/** The host's `onCallEnded`, for a call that ends before its client exists. */
|
|
18
|
+
callEnded: (end: LiveCallEnd) => void;
|
|
17
19
|
cancelGateDecision: (reason?: string) => void;
|
|
18
20
|
stopVideo: () => void;
|
|
19
21
|
resetCaptions: () => void;
|
|
@@ -38,6 +40,7 @@ export declare function useLiveRunnerControls(args: {
|
|
|
38
40
|
setVideoFacingMode: Dispatch<SetStateAction<LiveFacingMode>>;
|
|
39
41
|
setIsVideoOn: Dispatch<SetStateAction<boolean>>;
|
|
40
42
|
}): {
|
|
43
|
+
prepareAudio: () => void;
|
|
41
44
|
teardownSession: () => void;
|
|
42
45
|
startSession: () => Promise<void>;
|
|
43
46
|
handleSendText: (text?: string) => void;
|
|
@@ -1,9 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { prepareLiveAudio } from '@theoremjs/web/client';
|
|
2
|
+
import { useCallback, useEffect, useRef, } from 'react';
|
|
2
3
|
import { applyLiveTranscript } from "../../client/live/live-captions.js";
|
|
3
4
|
import { startLiveVideoCapture, } from "../../client/live/live-video.js";
|
|
4
5
|
/** Media + session lifecycle handlers for LiveRunner. */
|
|
5
6
|
export function useLiveRunnerControls(args) {
|
|
7
|
+
// invariant: A start still waiting on its connection is the open call: ending it ends that call.
|
|
8
|
+
const startingRef = useRef(null);
|
|
9
|
+
/** The audio output `prepareAudio` opened, until a start takes it. */
|
|
10
|
+
const preparedAudioRef = useRef(null);
|
|
11
|
+
const prepareAudio = useCallback(() => {
|
|
12
|
+
const held = preparedAudioRef.current;
|
|
13
|
+
if (held && held.state !== 'closed')
|
|
14
|
+
return;
|
|
15
|
+
preparedAudioRef.current = prepareLiveAudio();
|
|
16
|
+
}, []);
|
|
17
|
+
useEffect(() => () => {
|
|
18
|
+
releaseAudio(preparedAudioRef.current);
|
|
19
|
+
preparedAudioRef.current = null;
|
|
20
|
+
}, []);
|
|
6
21
|
const teardownSession = useCallback(() => {
|
|
22
|
+
const starting = startingRef.current;
|
|
23
|
+
startingRef.current = null;
|
|
24
|
+
if (starting) {
|
|
25
|
+
starting.ended = true;
|
|
26
|
+
releaseAudio(starting.audio);
|
|
27
|
+
args.callEnded({ cause: 'cancelled' });
|
|
28
|
+
}
|
|
7
29
|
args.cancelGateDecision();
|
|
8
30
|
args.clearClient();
|
|
9
31
|
args.stopVideo();
|
|
@@ -19,15 +41,53 @@ export function useLiveRunnerControls(args) {
|
|
|
19
41
|
args.setOutputLevel(0);
|
|
20
42
|
}, [args]);
|
|
21
43
|
const startSession = useCallback(async () => {
|
|
44
|
+
// invariant: The audio opens before the first await, inside the press that started the call.
|
|
45
|
+
const held = preparedAudioRef.current;
|
|
46
|
+
preparedAudioRef.current = null;
|
|
22
47
|
args.clearFailure();
|
|
23
48
|
args.resetCaptions();
|
|
49
|
+
const failStart = (err) => {
|
|
50
|
+
args.reportFailure(err);
|
|
51
|
+
args.callEnded({
|
|
52
|
+
cause: 'failed',
|
|
53
|
+
error: err instanceof Error ? err : new Error(String(err)),
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
let audio;
|
|
57
|
+
try {
|
|
58
|
+
audio = held && held.state !== 'closed' ? held : prepareLiveAudio();
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
failStart(err);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const starting = { ended: false, audio };
|
|
65
|
+
startingRef.current = starting;
|
|
66
|
+
let connection;
|
|
67
|
+
try {
|
|
68
|
+
connection = await args.connectionRef.current();
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
if (starting.ended)
|
|
72
|
+
return;
|
|
73
|
+
startingRef.current = null;
|
|
74
|
+
releaseAudio(audio);
|
|
75
|
+
failStart(err);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (starting.ended)
|
|
79
|
+
return;
|
|
80
|
+
startingRef.current = null;
|
|
24
81
|
try {
|
|
25
|
-
const liveClient = args.ensureClient(
|
|
82
|
+
const liveClient = args.ensureClient(connection);
|
|
26
83
|
if (args.statusRef.current === 'disconnected' || args.statusRef.current === 'error') {
|
|
27
|
-
await liveClient.connect();
|
|
84
|
+
await liveClient.connect({ audio });
|
|
28
85
|
}
|
|
86
|
+
else
|
|
87
|
+
releaseAudio(audio);
|
|
29
88
|
}
|
|
30
89
|
catch (err) {
|
|
90
|
+
releaseAudio(audio);
|
|
31
91
|
args.reportFailure(err);
|
|
32
92
|
}
|
|
33
93
|
}, [args]);
|
|
@@ -86,6 +146,7 @@ export function useLiveRunnerControls(args) {
|
|
|
86
146
|
await startSession();
|
|
87
147
|
}, [startSession, teardownSession]);
|
|
88
148
|
return {
|
|
149
|
+
prepareAudio,
|
|
89
150
|
teardownSession,
|
|
90
151
|
startSession,
|
|
91
152
|
handleSendText,
|
|
@@ -95,3 +156,10 @@ export function useLiveRunnerControls(args) {
|
|
|
95
156
|
handleRestart,
|
|
96
157
|
};
|
|
97
158
|
}
|
|
159
|
+
function releaseAudio(audio) {
|
|
160
|
+
if (!audio || audio.state === 'closed')
|
|
161
|
+
return;
|
|
162
|
+
audio.close().catch(() => {
|
|
163
|
+
// why: a context that closed meanwhile has nothing left to release.
|
|
164
|
+
});
|
|
165
|
+
}
|
|
@@ -68,6 +68,9 @@ export function useLiveSessionClient(bindings) {
|
|
|
68
68
|
onSessionReady: (info) => {
|
|
69
69
|
bindingsRef.current.onSessionReady?.(info);
|
|
70
70
|
},
|
|
71
|
+
onCallEnded: (end) => {
|
|
72
|
+
bindingsRef.current.onCallEnded?.(end);
|
|
73
|
+
},
|
|
71
74
|
...(b.onHostMessage
|
|
72
75
|
? {
|
|
73
76
|
onHostMessage: (message) => {
|
package/live.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
export type { LiveAudioOptions, LiveCallOptions, LiveClientTuning, LiveConnection, PageTool, PageToolAnswer, PageTools, } from '@theoremjs/web/client';
|
|
6
|
+
export type { LiveAudioOptions, LiveCallEnd, LiveCallOptions, LiveClientTuning, LiveConnection, PageTool, PageToolAnswer, PageTools, } from '@theoremjs/web/client';
|
|
7
7
|
export type { LiveFacingMode, LiveVideoFrame, LiveVideoOptions, } from './client/live/live-video.js';
|
|
8
8
|
export { type LiveVideoFit, type LiveVideoOverlay, type LiveVideoView, liveFramePointInPreview, } from './client/live/live-video-view.js';
|
|
9
9
|
export { type LiveCall, type LiveCallInput, useLiveCall, } from './components/live/use-live-call.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.1037.g9282f21",
|
|
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.1037.g9282f21",
|
|
64
|
+
"@theoremjs/web": "^0.3.5-next.1037.g9282f21"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@astryxdesign/core": {
|
package/ui/ChatComposerBar.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChatComposerInput, type ChatComposerInputHandle, type ChatComposerTrigger } from '@astryxdesign/core/Chat';
|
|
1
|
+
import { ChatComposerInput, type ChatComposerInputHandle, type ChatComposerStatus, type ChatComposerTrigger } from '@astryxdesign/core/Chat';
|
|
2
2
|
import type { RefText, UserPart, UserRef } from '@theoremjs/agents/interface';
|
|
3
3
|
import { type AttachmentValidationIssue, type ComposerMenuAction, type ComposerPendingMessage, type ComposerProfileInterface, type ComposerRunPhase, type LiveProfileInterface } from '@theoremjs/agents/interface';
|
|
4
4
|
import type { ClientFailure } from '@theoremjs/web/client';
|
|
@@ -93,6 +93,12 @@ export type ChatComposerBarProps = {
|
|
|
93
93
|
* starts a call. Never replaces stop or the send menu. Omit to keep the send button.
|
|
94
94
|
*/
|
|
95
95
|
emptyAction?: ReactNode;
|
|
96
|
+
/**
|
|
97
|
+
* Draws the composer's problem: a send that failed (`error`), or files and a voice note it
|
|
98
|
+
* could not take (`warning`). Give the node its own `role`: `alert` for an error, `status` for
|
|
99
|
+
* a warning. Omit to keep Astryx's.
|
|
100
|
+
*/
|
|
101
|
+
renderStatus?: (status: ChatComposerStatus) => ReactNode;
|
|
96
102
|
};
|
|
97
103
|
/** A Live call's text line: it is sent as typed, so there is nothing to attach, queue, or stop. */
|
|
98
104
|
export type LiveComposerBarProps = Omit<Pick<ChatComposerBarProps, 'draftText' | 'placeholder' | 'inputRef' | 'inputComponent' | 'triggers' | 'draftParts' | 'onDraftPartsChange' | 'refText' | 'renderRef' | 'onDraftTextChange' | 'onSubmit' | 'emptyAction'>, 'onSubmit'> & {
|
package/ui/ChatComposerBar.js
CHANGED
|
@@ -453,12 +453,13 @@ function RowComposerBar({ props, parts, }) {
|
|
|
453
453
|
hasPayload: parts.hasPayload,
|
|
454
454
|
primary: parts.primary,
|
|
455
455
|
opensMenu,
|
|
456
|
-
}) ? (props.emptyAction) : opensMenu ? (_jsx(SendMenu, { actions: parts.menuActions, phase: props.phase, onAction: props.onMenuAction, trigger: "send" })) : (_jsx(ChatSendButton, { isDisabled: parts.primaryDisabled || parts.primary === 'stop', onSend: parts.runPrimary })), status: parts.status }));
|
|
456
|
+
}) ? (props.emptyAction) : opensMenu ? (_jsx(SendMenu, { actions: parts.menuActions, phase: props.phase, onAction: props.onMenuAction, trigger: "send" })) : (_jsx(ChatSendButton, { isDisabled: parts.primaryDisabled || parts.primary === 'stop', onSend: parts.runPrimary })), status: parts.status, renderStatus: props.renderStatus }));
|
|
457
457
|
}
|
|
458
458
|
/** Today's layout: Astryx's ChatComposer. */
|
|
459
459
|
function StackedComposerBar({ props, parts, }) {
|
|
460
460
|
const isStopShown = parts.primary === 'stop';
|
|
461
|
-
|
|
461
|
+
const hostStatus = parts.status && props.renderStatus?.(parts.status);
|
|
462
|
+
const composer = (_jsx(ChatComposer
|
|
462
463
|
// why: No keyboard focus ring on the composer (product choice): zero Astryx's
|
|
463
464
|
// focus-outline token for this subtree. The editor still shows its caret.
|
|
464
465
|
, {
|
|
@@ -471,5 +472,9 @@ function StackedComposerBar({ props, parts, }) {
|
|
|
471
472
|
hasPayload: parts.hasPayload,
|
|
472
473
|
primary: parts.primary,
|
|
473
474
|
opensMenu: false,
|
|
474
|
-
}) ? (props.emptyAction) : (_jsx(ChatSendButton, { isStopShown: isStopShown, isDisabled: parts.primaryDisabled, onSend: parts.runPrimary, onStop: props.onStop })), status: parts.status }));
|
|
475
|
+
}) ? (props.emptyAction) : (_jsx(ChatSendButton, { isStopShown: isStopShown, isDisabled: parts.primaryDisabled, onSend: parts.runPrimary, onStop: props.onStop })), status: props.renderStatus ? undefined : parts.status }));
|
|
476
|
+
// why: Astryx's composer draws only its own status, so the host's goes under it, where Astryx's sits.
|
|
477
|
+
if (!hostStatus)
|
|
478
|
+
return composer;
|
|
479
|
+
return (_jsxs(VStack, { gap: 2, width: "100%", children: [composer, hostStatus] }));
|
|
475
480
|
}
|
package/ui/ChatComposerRow.d.ts
CHANGED
|
@@ -57,6 +57,8 @@ export type ComposerRowParts = {
|
|
|
57
57
|
/** The send button, or the send menu while a reply runs. */
|
|
58
58
|
action: ReactNode;
|
|
59
59
|
status?: ChatComposerStatus;
|
|
60
|
+
/** Draws the status in place of Astryx's Banner. */
|
|
61
|
+
renderStatus?: (status: ChatComposerStatus) => ReactNode;
|
|
60
62
|
};
|
|
61
63
|
/**
|
|
62
64
|
* Theorem's one-row composer: the field, then the controls, the mic, and send, on one line.
|
package/ui/ChatComposerRow.js
CHANGED
|
@@ -181,9 +181,11 @@ function RowSurface(props) {
|
|
|
181
181
|
const attach = props.attach ? _jsx(StackItem, { children: props.attach }) : null;
|
|
182
182
|
return (_jsx(Card, { elevation: "none", className: "theorem-composer-surface", style: ROW_SURFACE, children: _jsxs(HStack, { gap: 1, wrap: "wrap", vAlign: "end", children: [props.stacked ? null : attach, _jsx(RowField, { input: props.input, stacked: props.stacked }), props.stacked ? attach : null, _jsx(StackItem, { size: props.stacked ? 'fill' : 'static', children: _jsxs(HStack, { gap: 1, vAlign: "center", hAlign: "end", children: [props.controls, props.record, props.action] }) })] }) }));
|
|
183
183
|
}
|
|
184
|
-
function RowStatus({ status }) {
|
|
184
|
+
function RowStatus({ status, renderStatus }) {
|
|
185
185
|
if (!status)
|
|
186
186
|
return null;
|
|
187
|
+
if (renderStatus)
|
|
188
|
+
return renderStatus(status);
|
|
187
189
|
return (_jsx(Banner, { status: status.type, role: status.type === 'error' ? 'alert' : 'status', title: status.message }));
|
|
188
190
|
}
|
|
189
191
|
/**
|
|
@@ -194,5 +196,5 @@ function RowStatus({ status }) {
|
|
|
194
196
|
*/
|
|
195
197
|
export function ChatComposerRow(props) {
|
|
196
198
|
const stacked = useWrapped(props.editorRef, props.draftText);
|
|
197
|
-
return (_jsxs(VStack, { gap: 0, width: "100%", className: "theorem-composer-row", style: { gap: GAP }, children: [_jsx(PillRow, { isWorking: props.isWorking, workingSince: props.workingSince, icons: props.icons, backgroundJobs: props.backgroundJobs, pills: props.pills, onStop: props.onStop, hint: props.hint }), props.tray ? _jsx(RowTray, { tray: props.tray }) : null, _jsx(RowSurface, { stacked: stacked, attach: props.attach, input: props.input, controls: props.controls, record: props.record, action: props.action }), _jsx(RowStatus, { status: props.status })] }));
|
|
199
|
+
return (_jsxs(VStack, { gap: 0, width: "100%", className: "theorem-composer-row", style: { gap: GAP }, children: [_jsx(PillRow, { isWorking: props.isWorking, workingSince: props.workingSince, icons: props.icons, backgroundJobs: props.backgroundJobs, pills: props.pills, onStop: props.onStop, hint: props.hint }), props.tray ? _jsx(RowTray, { tray: props.tray }) : null, _jsx(RowSurface, { stacked: stacked, attach: props.attach, input: props.input, controls: props.controls, record: props.record, action: props.action }), _jsx(RowStatus, { status: props.status, renderStatus: props.renderStatus })] }));
|
|
198
200
|
}
|
package/ui/TheoremChat.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ChatComposerInputHandle, type ChatComposerTrigger } from '@astryxdesign/core/Chat';
|
|
1
|
+
import { type ChatComposerInputHandle, type ChatComposerStatus, type ChatComposerTrigger } from '@astryxdesign/core/Chat';
|
|
2
2
|
import type { DefinedTheme } from '@astryxdesign/core/theme';
|
|
3
3
|
import type { RefText, UserRef } from '@theoremjs/agents/interface';
|
|
4
4
|
import { type ComposerPendingMessage, type ComposerProfileInterface } from '@theoremjs/agents/interface';
|
|
@@ -160,6 +160,8 @@ export type TheoremChatProps<Host extends JsonObject = JsonObject> = {
|
|
|
160
160
|
renderRef?: (ref: UserRef) => ReactNode;
|
|
161
161
|
/** Stands in for the send button while the composer is empty; see `ChatComposerBarProps.emptyAction`. */
|
|
162
162
|
composerEmptyAction?: ReactNode;
|
|
163
|
+
/** Draws the composer's problem in place of Astryx's; see `ChatComposerBarProps.renderStatus`. */
|
|
164
|
+
renderComposerStatus?: (status: ChatComposerStatus) => ReactNode;
|
|
163
165
|
/**
|
|
164
166
|
* The transcript's own options, given to {@link TheoremChatTranscript} as they are: its `slots`,
|
|
165
167
|
* such as the `reply` slot, and how it lays out a reply. `Host` is the type of the values your
|
|
@@ -216,13 +218,15 @@ export type TheoremChatComposerProps = {
|
|
|
216
218
|
pills?: readonly ComposerPill[];
|
|
217
219
|
/** Stands in for the send button while the composer is empty; see `ChatComposerBarProps.emptyAction`. */
|
|
218
220
|
emptyAction?: ReactNode;
|
|
221
|
+
/** Draws the composer's problem in place of Astryx's; see `ChatComposerBarProps.renderStatus`. */
|
|
222
|
+
renderStatus?: (status: ChatComposerStatus) => ReactNode;
|
|
219
223
|
};
|
|
220
224
|
/**
|
|
221
225
|
* The composer bound to a chat: drafts, files, voice, the pending queue, send and stop, and the
|
|
222
226
|
* working pill on the chat's turn clock. Place it anywhere; `TheoremChat` is built from it and
|
|
223
227
|
* `TheoremChatTranscript`.
|
|
224
228
|
*/
|
|
225
|
-
export declare function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, pills, inputComponent, triggers, refText, renderRef, emptyAction, }: TheoremChatComposerProps): import("react").JSX.Element;
|
|
229
|
+
export declare function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, pills, inputComponent, triggers, refText, renderRef, emptyAction, renderStatus, }: TheoremChatComposerProps): import("react").JSX.Element;
|
|
226
230
|
export type TheoremChatTranscriptProps<Host extends JsonObject = JsonObject> = Omit<ChatTranscriptProps<Host>, 'blocks' | 'handle' | 'streaming' | 'delivery' | 'answering' | 'clock' | 'onToolDecision' | 'onAuthenticated' | 'imageOutput' | 'labels' | 'showToolData'> & {
|
|
227
231
|
/** The chat it shows (`useTheoremChat`). */
|
|
228
232
|
chat: TheoremChatState;
|
package/ui/TheoremChat.js
CHANGED
|
@@ -33,8 +33,8 @@ function ChatColumn({ maxWidth, ref, children, }) {
|
|
|
33
33
|
* working pill on the chat's turn clock. Place it anywhere; `TheoremChat` is built from it and
|
|
34
34
|
* `TheoremChatTranscript`.
|
|
35
35
|
*/
|
|
36
|
-
export function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, pills, inputComponent, triggers, refText, renderRef, emptyAction, }) {
|
|
37
|
-
return (_jsx(ChatComposerBar, { emptyAction: emptyAction, iface: iface, layout: layout, icons: icons, pills: pills, workingSince: chat.workingSince, backgroundJobs: chat.backgroundJobs, draftText: chat.draftText, pendingFiles: chat.pendingFiles, pendingVoice: chat.pendingVoice, pendingMessages: chat.pendingMessages, issues: chat.issues, phase: chat.phase, failure: chat.failure, selectedModel: chat.session.selectedModel, selectedEffort: chat.session.selectedEffort, placeholder: placeholder, inputRef: inputRef, inputComponent: inputComponent, triggers: triggers, refText: refText, renderRef: renderRef, draftParts: chat.draftParts, onDraftPartsChange: chat.setDraftParts, onDraftTextChange: chat.setDraftText, onFilesSelected: (files) => {
|
|
36
|
+
export function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, pills, inputComponent, triggers, refText, renderRef, emptyAction, renderStatus, }) {
|
|
37
|
+
return (_jsx(ChatComposerBar, { emptyAction: emptyAction, renderStatus: renderStatus, iface: iface, layout: layout, icons: icons, pills: pills, workingSince: chat.workingSince, backgroundJobs: chat.backgroundJobs, draftText: chat.draftText, pendingFiles: chat.pendingFiles, pendingVoice: chat.pendingVoice, pendingMessages: chat.pendingMessages, issues: chat.issues, phase: chat.phase, failure: chat.failure, selectedModel: chat.session.selectedModel, selectedEffort: chat.session.selectedEffort, placeholder: placeholder, inputRef: inputRef, inputComponent: inputComponent, triggers: triggers, refText: refText, renderRef: renderRef, draftParts: chat.draftParts, onDraftPartsChange: chat.setDraftParts, onDraftTextChange: chat.setDraftText, onFilesSelected: (files) => {
|
|
38
38
|
chat.setPendingFiles((prev) => [...prev, ...files]);
|
|
39
39
|
chat.setIssues([]);
|
|
40
40
|
}, onAttachmentRemove: (index) => {
|
|
@@ -71,7 +71,7 @@ function useChatHandle(chatRef, chat) {
|
|
|
71
71
|
/** The composer, or, with none, the failed turn's error where the composer was. */
|
|
72
72
|
function ChatBodyComposer({ body, chat, inputRef, }) {
|
|
73
73
|
if (body.composer ?? true)
|
|
74
|
-
return (_jsx(TheoremChatComposer, { chat: chat, iface: body.iface, placeholder: body.placeholder, inputRef: inputRef, layout: body.composerLayout, icons: body.composerIcons, inputComponent: body.composerInput, triggers: body.composerTriggers, refText: body.refText, renderRef: body.renderRef, emptyAction: body.composerEmptyAction }));
|
|
74
|
+
return (_jsx(TheoremChatComposer, { chat: chat, iface: body.iface, placeholder: body.placeholder, inputRef: inputRef, layout: body.composerLayout, icons: body.composerIcons, inputComponent: body.composerInput, triggers: body.composerTriggers, refText: body.refText, renderRef: body.renderRef, emptyAction: body.composerEmptyAction, renderStatus: body.renderComposerStatus }));
|
|
75
75
|
const failure = chat.failure;
|
|
76
76
|
return failure ? _jsx(Banner, { status: "error", role: "alert", title: failure.error }) : null;
|
|
77
77
|
}
|