@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.
@@ -1,9 +1,13 @@
1
+ import { type ChatComposerInputHandle } from '@astryxdesign/core/Chat';
1
2
  import type { DefinedTheme } from '@astryxdesign/core/theme';
2
- import { type ComposerPendingMessage } from '@theoremjs/agents/interface';
3
+ import { type ComposerPendingMessage, type ComposerProfileInterface } from '@theoremjs/agents/interface';
3
4
  import type { ChatController, PageTools, StatedTurn } from '@theoremjs/web/client';
4
5
  import { type ConversationView, type HttpTransportOptions, type TheoremTransport } from '@theoremjs/web/client';
5
6
  import { type ReactNode, type Ref } from 'react';
6
- import { type SendTextOptions, type SentTurn, type UseTheoremChatOptions } from '../hooks/use-theorem-chat.ts';
7
+ import { type SendTextOptions, type SentTurn, type TheoremChatState, type UseTheoremChatOptions } from '../hooks/use-theorem-chat.ts';
8
+ import { type ComposerLayout } from './ChatComposerBar.tsx';
9
+ import type { ComposerRowIcons } from './ChatComposerRow.tsx';
10
+ import { type ChatTranscriptProps } from './ChatTranscript.tsx';
7
11
  import type { TheoremLabels } from './labels.ts';
8
12
  import type { ResolveMedia, ToolMediaShown } from './tool-media.tsx';
9
13
  export type TheoremChatProps = {
@@ -124,6 +128,18 @@ export type TheoremChatProps = {
124
128
  * through `chatRef`. Gates are still answered in the transcript. Default `true`.
125
129
  */
126
130
  composer?: boolean;
131
+ /**
132
+ * How the composer is laid out: `stacked` (default), Astryx's composer with the field above its
133
+ * controls; or `row`, the field and its buttons on one line, with a pill row above it for the
134
+ * reply in progress and the background jobs. See {@link ComposerLayout}.
135
+ */
136
+ composerLayout?: ComposerLayout;
137
+ /**
138
+ * Glyphs the `row` composer draws: the working pill's, each background job's, and stop's. Each
139
+ * one left out keeps Theorem's. Its text is in `labels`; its look is the
140
+ * `--theorem-composer-*` CSS properties.
141
+ */
142
+ composerIcons?: ComposerRowIcons;
127
143
  };
128
144
  /** What a host can do to a mounted {@link TheoremChat}. */
129
145
  export type TheoremChatHandle = {
@@ -147,6 +163,37 @@ export type TheoremChatHandle = {
147
163
  * whichever is smaller) — so phones and narrow panes get 100%.
148
164
  */
149
165
  export declare const DEFAULT_CHAT_MAX_WIDTH = "max(50%, min(100%, 640px))";
166
+ export type TheoremChatComposerProps = {
167
+ /** The chat it writes to (`useTheoremChat`). */
168
+ chat: TheoremChatState;
169
+ /** The profile's interface (`useTheoremInterface`). */
170
+ iface: ComposerProfileInterface;
171
+ placeholder?: string;
172
+ /** Focus the field from outside. */
173
+ inputRef?: Ref<ChatComposerInputHandle>;
174
+ layout?: ComposerLayout;
175
+ icons?: ComposerRowIcons;
176
+ };
177
+ /**
178
+ * The composer bound to a chat: drafts, files, voice, the pending queue, send and stop, and the
179
+ * working pill on the chat's turn clock. Place it anywhere; `TheoremChat` is built from it and
180
+ * `TheoremChatTranscript`.
181
+ */
182
+ export declare function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, }: TheoremChatComposerProps): import("react").JSX.Element;
183
+ export type TheoremChatTranscriptProps = Omit<ChatTranscriptProps, 'blocks' | 'handle' | 'streaming' | 'delivery' | 'answering' | 'clock' | 'onToolDecision' | 'onAuthenticated' | 'imageOutput' | 'labels'> & {
184
+ /** The chat it shows (`useTheoremChat`). */
185
+ chat: TheoremChatState;
186
+ /** The profile's interface (`useTheoremInterface`). */
187
+ iface: ComposerProfileInterface;
188
+ /** The name over each reply. Default: the profile's handle. */
189
+ handle?: string;
190
+ };
191
+ /**
192
+ * The transcript bound to a chat: its blocks as they stream, its gates answered through the chat,
193
+ * and its times on the chat's turn clock, so they agree with `TheoremChatComposer` wherever each
194
+ * is placed.
195
+ */
196
+ export declare function TheoremChatTranscript({ chat, iface, handle, ...props }: TheoremChatTranscriptProps): import("react").JSX.Element;
150
197
  /**
151
198
  * Drop-in chat for a profile served by `createTheoremHandler`:
152
199
  *
package/ui/TheoremChat.js CHANGED
@@ -28,9 +28,13 @@ export const DEFAULT_CHAT_MAX_WIDTH = 'max(50%, min(100%, 640px))';
28
28
  function ChatColumn({ maxWidth, ref, children, }) {
29
29
  return (_jsx(Center, { axis: "horizontal", width: "100%", children: _jsx(VStack, { ref: ref, width: "100%", maxWidth: maxWidth, children: children }) }));
30
30
  }
31
- /** The composer bar wired to a `useTheoremChat` model. */
32
- function ChatComposerForChat({ chat, iface, placeholder, inputRef, }) {
33
- return (_jsx(ChatComposerBar, { iface: iface, 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, onDraftTextChange: chat.setDraftText, onFilesSelected: (files) => {
31
+ /**
32
+ * The composer bound to a chat: drafts, files, voice, the pending queue, send and stop, and the
33
+ * working pill on the chat's turn clock. Place it anywhere; `TheoremChat` is built from it and
34
+ * `TheoremChatTranscript`.
35
+ */
36
+ export function TheoremChatComposer({ chat, iface, placeholder, inputRef, layout, icons, }) {
37
+ return (_jsx(ChatComposerBar, { iface: iface, layout: layout, icons: icons, 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, onDraftTextChange: chat.setDraftText, onFilesSelected: (files) => {
34
38
  chat.setPendingFiles((prev) => [...prev, ...files]);
35
39
  chat.setIssues([]);
36
40
  }, onAttachmentRemove: (index) => {
@@ -50,7 +54,28 @@ function ChatComposerForChat({ chat, iface, placeholder, inputRef, }) {
50
54
  void chat.handleSendNow(message);
51
55
  } }));
52
56
  }
53
- function ChatBody({ transport, iface, placeholder, emptyState, density, maxWidth = DEFAULT_CHAT_MAX_WIDTH, scrollRef, trace, usage, className, style, conversation, conversationView, initialText, initialFiles, initialVoice, initialPending, onConversationChange, chatRef, composer: hasComposer = true, options, onOptionsChange, stated, context, pageTools, onTurnEvent, }) {
57
+ /** The handle `chatRef` gets: send, stop, focus and the controller. */
58
+ function useChatHandle(chatRef, chat) {
59
+ const { sendText, handleStop, controller } = chat;
60
+ const inputRef = useRef(null);
61
+ useImperativeHandle(chatRef, () => ({
62
+ send: sendText,
63
+ stop: handleStop,
64
+ focus: () => {
65
+ inputRef.current?.focus();
66
+ },
67
+ controller,
68
+ }), [sendText, handleStop, controller]);
69
+ return inputRef;
70
+ }
71
+ /** The composer, or, with none, the failed turn's error where the composer was. */
72
+ function ChatBodyComposer({ hasComposer, ...props }) {
73
+ if (hasComposer)
74
+ return _jsx(TheoremChatComposer, { ...props });
75
+ const failure = props.chat.failure;
76
+ return failure ? _jsx(Banner, { status: "error", role: "alert", title: failure.error }) : null;
77
+ }
78
+ function ChatBody({ transport, iface, placeholder, emptyState, density, maxWidth = DEFAULT_CHAT_MAX_WIDTH, scrollRef, trace, usage, className, style, conversation, conversationView, initialText, initialFiles, initialVoice, initialPending, onConversationChange, chatRef, composer: hasComposer = true, composerLayout, composerIcons, options, onOptionsChange, stated, context, pageTools, onTurnEvent, }) {
54
79
  const t = useLabels();
55
80
  const chat = useTheoremChat({
56
81
  transport,
@@ -69,26 +94,15 @@ function ChatBody({ transport, iface, placeholder, emptyState, density, maxWidth
69
94
  pageTools,
70
95
  onTurnEvent,
71
96
  });
72
- const { sendText, handleStop, controller } = chat;
73
- const blocks = useMemo(() => [...chat.blocks, ...chat.streamBlocks], [chat.blocks, chat.streamBlocks]);
74
97
  const handle = t('@theorem.agent.handle', { handle: iface.identity.handle });
75
- const landing = blocks.length === 0;
76
- const inputRef = useRef(null);
77
- useImperativeHandle(chatRef, () => ({
78
- send: sendText,
79
- stop: handleStop,
80
- focus: () => {
81
- inputRef.current?.focus();
82
- },
83
- controller,
84
- }), [sendText, handleStop, controller]);
98
+ const landing = chat.shownBlocks.length === 0;
99
+ const inputRef = useChatHandle(chatRef, chat);
85
100
  const composerRef = useGlide(landing, () => inputRef.current?.focus());
86
101
  const inspector = useTraceInspector(iface, transport.traces, trace);
87
102
  const header = _jsx(SidePanelHeader, { floating: true, children: inspector.toggle });
88
- // why: the composer says when a turn failed. Without one, the chat says it where the composer was.
89
- const composer = hasComposer ? (_jsx(ChatComposerForChat, { chat: chat, iface: iface, placeholder: placeholder, inputRef: inputRef })) : (chat.failure && _jsx(Banner, { status: "error", role: "alert", title: chat.failure.error }));
103
+ const composer = (_jsx(ChatBodyComposer, { hasComposer: hasComposer, chat: chat, iface: iface, placeholder: placeholder, inputRef: inputRef, layout: composerLayout, icons: composerIcons }));
90
104
  const docked = { composer, composerRef, maxWidth };
91
- return (_jsx(WithTrace, { inspector: inspector, children: _jsx(Layout, { height: "fill", className: className, style: { position: 'relative', ...style }, header: header, content: _jsx(LayoutContent, { padding: 0, isScrollable: landing, children: landing ? (_jsx(ChatLanding, { ...docked, handle: handle, emptyState: emptyState })) : (_jsx(ChatThread, { ...docked, chat: chat, iface: iface, blocks: blocks, handle: handle, density: density, scrollRef: scrollRef, usage: usage })) }) }) }));
105
+ return (_jsx(WithTrace, { inspector: inspector, children: _jsx(Layout, { height: "fill", className: className, style: { position: 'relative', ...style }, header: header, content: _jsx(LayoutContent, { padding: 0, isScrollable: landing, children: landing ? (_jsx(ChatLanding, { ...docked, handle: handle, emptyState: emptyState })) : (_jsx(ChatThread, { ...docked, chat: chat, iface: iface, handle: handle, density: density, scrollRef: scrollRef, usage: usage })) }) }) }));
92
106
  }
93
107
  const CHAT_SCROLL = { overscrollBehavior: 'none' };
94
108
  /**
@@ -104,16 +118,23 @@ function ChatLanding({ composer, composerRef, maxWidth, handle, emptyState, }) {
104
118
  * why: the dock leaves 12px under the composer; paddingBlockEnd={3} adds 12px more for a 24px
105
119
  * bottom margin.
106
120
  */
107
- function ChatThread({ composer, composerRef, maxWidth, chat, iface, blocks, handle, density, scrollRef, usage, }) {
121
+ function ChatThread({ composer, composerRef, maxWidth, chat, iface, handle, density, scrollRef, usage, }) {
108
122
  return (_jsxs(VStack, { height: "100%", children: [_jsx("style", { href: "theorem-chat-thread", precedence: "default", children: '.theorem-chat-thread > :last-child > div:empty { display: none; }' }), _jsx(ChatLayout, { className: "theorem-chat-thread", density: density, scrollRef: scrollRef,
109
123
  // why: Scrolling past either end does not bounce the transcript and its docked composer.
110
- style: CHAT_SCROLL, composer: composer && (_jsx(VStack, { paddingBlockEnd: 3, children: _jsx(ChatColumn, { ref: composerRef, maxWidth: maxWidth, children: composer }) })), children: _jsx(ChatColumn, { maxWidth: maxWidth, children: _jsx(ChatTranscript, { blocks: blocks, handle: handle, streaming: chat.streaming, delivery: chat.delivery, answering: chat.answering, usage: usage, labels: iface.labels, imageOutput: iface.type === 'image'
111
- ? { ratio: parseAspectRatio(iface.image.aspectRatio) }
112
- : undefined, onToolDecision: (index, action) => {
113
- void chat.handleToolDecision(index, action);
114
- }, onAuthenticated: (index, secret) => {
115
- void chat.handleAuthenticated(index, secret);
116
- } }) }) })] }));
124
+ style: CHAT_SCROLL, composer: composer && (_jsx(VStack, { paddingBlockEnd: 3, children: _jsx(ChatColumn, { ref: composerRef, maxWidth: maxWidth, children: composer }) })), children: _jsx(ChatColumn, { maxWidth: maxWidth, children: _jsx(TheoremChatTranscript, { chat: chat, iface: iface, handle: handle, usage: usage }) }) })] }));
125
+ }
126
+ /**
127
+ * The transcript bound to a chat: its blocks as they stream, its gates answered through the chat,
128
+ * and its times on the chat's turn clock, so they agree with `TheoremChatComposer` wherever each
129
+ * is placed.
130
+ */
131
+ export function TheoremChatTranscript({ chat, iface, handle, ...props }) {
132
+ const t = useLabels();
133
+ return (_jsx(ChatTranscript, { ...props, handle: handle ?? t('@theorem.agent.handle', { handle: iface.identity.handle }), blocks: chat.shownBlocks, streaming: chat.streaming, delivery: chat.delivery, answering: chat.answering, clock: chat.turnClock, labels: iface.labels, imageOutput: iface.type === 'image' ? { ratio: parseAspectRatio(iface.image.aspectRatio) } : undefined, onToolDecision: (index, action) => {
134
+ void chat.handleToolDecision(index, action);
135
+ }, onAuthenticated: (index, secret) => {
136
+ void chat.handleAuthenticated(index, secret);
137
+ } }));
117
138
  }
118
139
  function ChatForTransport(props) {
119
140
  const t = useLabels();
package/ui/index.d.ts CHANGED
@@ -14,7 +14,8 @@ export { useLiveCaptionLog } from '../client/live/use-live-caption-log.ts';
14
14
  export { InkWaveform, type InkWaveformProps, type InkWaveLevels, } from '../components/InkWaveform.tsx';
15
15
  export { type LiveCall, type LiveCallInput, useLiveCall, } from '../components/live/use-live-call.ts';
16
16
  export { theoremTheme } from './built/theorem.js';
17
- export { ChatComposerBar, type ChatComposerBarProps, EFFORT_ICON, generationOptions, type LiveComposerBarProps, } from './ChatComposerBar.tsx';
17
+ export { ChatComposerBar, type ChatComposerBarProps, type ComposerLayout, EFFORT_ICON, generationOptions, type LiveComposerBarProps, } from './ChatComposerBar.tsx';
18
+ export type { ComposerRowIcons } from './ChatComposerRow.tsx';
18
19
  export { ChatTranscript, type ChatTranscriptProps } from './ChatTranscript.tsx';
19
20
  export { ConsoleFrame, type ConsoleFrameProps, type ConsolePageProps, RequestCard, ResponseColumn, RunBar, useBytes, } from './ConsoleFrame.tsx';
20
21
  export { TheoremDecisionAnswers, type TheoremDecisionAnswersProps } from './DecisionAnswers.tsx';
@@ -28,7 +29,7 @@ export { PaneFailure, PaneLoading, PaneState } from './PaneState.tsx';
28
29
  export { RadialBars, Sunburst, type SunburstNode } from './RadialCharts.tsx';
29
30
  export { type RankedBar, RankedBars } from './RankedBars.tsx';
30
31
  export { InPlace, PaneLayout, PanePanel, Prose, RaisedPane } from './SidePanel.tsx';
31
- export { DEFAULT_CHAT_MAX_WIDTH, TheoremChat, type TheoremChatHandle, type TheoremChatProps, } from './TheoremChat.tsx';
32
+ export { DEFAULT_CHAT_MAX_WIDTH, TheoremChat, TheoremChatComposer, type TheoremChatComposerProps, type TheoremChatHandle, type TheoremChatProps, TheoremChatTranscript, type TheoremChatTranscriptProps, } from './TheoremChat.tsx';
32
33
  export { TheoremDecision, type TheoremDecisionProps } from './TheoremDecision.tsx';
33
34
  export { TheoremEmbedding, type TheoremEmbeddingProps } from './TheoremEmbedding.tsx';
34
35
  export { TheoremHost, type TheoremHostProps } from './TheoremHost.tsx';
package/ui/index.js CHANGED
@@ -31,7 +31,7 @@ export { PaneFailure, PaneLoading, PaneState } from "./PaneState.js";
31
31
  export { RadialBars, Sunburst } from "./RadialCharts.js";
32
32
  export { RankedBars } from "./RankedBars.js";
33
33
  export { InPlace, PaneLayout, PanePanel, Prose, RaisedPane } from "./SidePanel.js";
34
- export { DEFAULT_CHAT_MAX_WIDTH, TheoremChat, } from "./TheoremChat.js";
34
+ export { DEFAULT_CHAT_MAX_WIDTH, TheoremChat, TheoremChatComposer, TheoremChatTranscript, } from "./TheoremChat.js";
35
35
  export { TheoremDecision } from "./TheoremDecision.js";
36
36
  export { TheoremEmbedding } from "./TheoremEmbedding.js";
37
37
  export { TheoremHost } from "./TheoremHost.js";
package/ui/labels.d.ts CHANGED
@@ -89,6 +89,45 @@ export declare const THEOREM_UI_CATALOG: {
89
89
  readonly defaultMessage: "Set it aside to send later.";
90
90
  readonly description: "Send menu item detail: the message waits in the composer until sent.";
91
91
  };
92
+ readonly '@theorem.composer.menu.queue.gated.description': {
93
+ readonly defaultMessage: "Send it once you answer the waiting step.";
94
+ readonly description: "Send menu item detail while a step waits for approval: the message waits for the answer.";
95
+ };
96
+ readonly '@theorem.composer.menu.send_now.gated.description': {
97
+ readonly defaultMessage: "Cancel the waiting step and send this instead.";
98
+ readonly description: "Send menu item detail while a step waits for approval: ends the wait, then sends.";
99
+ };
100
+ readonly '@theorem.composer.send_menu': {
101
+ readonly defaultMessage: "Send options";
102
+ readonly description: "The row composer's button while a reply runs: it opens the send menu.";
103
+ };
104
+ readonly '@theorem.composer.pill.working': {
105
+ readonly defaultMessage: "Working";
106
+ readonly description: "The row composer's pill while the agent replies, before its start is known.";
107
+ };
108
+ readonly '@theorem.composer.pill.working_for': {
109
+ readonly defaultMessage: "Working for {duration}";
110
+ readonly description: "The row composer's pill while the agent replies, with how long it has run.";
111
+ readonly params: readonly ["duration"];
112
+ };
113
+ readonly '@theorem.composer.tray.expand': {
114
+ readonly defaultMessage: "Expand {label}";
115
+ readonly description: "Names the row composer's tray toggle while the tray is folded.";
116
+ readonly params: readonly ["label"];
117
+ };
118
+ readonly '@theorem.composer.tray.collapse': {
119
+ readonly defaultMessage: "Collapse {label}";
120
+ readonly description: "Names the row composer's tray toggle while the tray is open.";
121
+ readonly params: readonly ["label"];
122
+ };
123
+ readonly '@theorem.composer.pill.stop': {
124
+ readonly defaultMessage: "Stop";
125
+ readonly description: "The stop button on the working pill.";
126
+ };
127
+ readonly '@theorem.composer.pill.background': {
128
+ readonly defaultMessage: "Running in the background";
129
+ readonly description: "Read by screen readers on a background job pill, after its name.";
130
+ };
92
131
  readonly '@theorem.composer.hint.stash-selected-draft.message': {
93
132
  readonly defaultMessage: "Replacing this?";
94
133
  readonly description: "Hint when the whole draft is selected and could be stashed.";
package/ui/labels.js CHANGED
@@ -76,6 +76,45 @@ export const THEOREM_UI_CATALOG = {
76
76
  defaultMessage: 'Set it aside to send later.',
77
77
  description: 'Send menu item detail: the message waits in the composer until sent.',
78
78
  },
79
+ '@theorem.composer.menu.queue.gated.description': {
80
+ defaultMessage: 'Send it once you answer the waiting step.',
81
+ description: 'Send menu item detail while a step waits for approval: the message waits for the answer.',
82
+ },
83
+ '@theorem.composer.menu.send_now.gated.description': {
84
+ defaultMessage: 'Cancel the waiting step and send this instead.',
85
+ description: 'Send menu item detail while a step waits for approval: ends the wait, then sends.',
86
+ },
87
+ '@theorem.composer.send_menu': {
88
+ defaultMessage: 'Send options',
89
+ description: "The row composer's button while a reply runs: it opens the send menu.",
90
+ },
91
+ '@theorem.composer.pill.working': {
92
+ defaultMessage: 'Working',
93
+ description: "The row composer's pill while the agent replies, before its start is known.",
94
+ },
95
+ '@theorem.composer.pill.working_for': {
96
+ defaultMessage: 'Working for {duration}',
97
+ description: "The row composer's pill while the agent replies, with how long it has run.",
98
+ params: ['duration'],
99
+ },
100
+ '@theorem.composer.tray.expand': {
101
+ defaultMessage: 'Expand {label}',
102
+ description: "Names the row composer's tray toggle while the tray is folded.",
103
+ params: ['label'],
104
+ },
105
+ '@theorem.composer.tray.collapse': {
106
+ defaultMessage: 'Collapse {label}',
107
+ description: "Names the row composer's tray toggle while the tray is open.",
108
+ params: ['label'],
109
+ },
110
+ '@theorem.composer.pill.stop': {
111
+ defaultMessage: 'Stop',
112
+ description: 'The stop button on the working pill.',
113
+ },
114
+ '@theorem.composer.pill.background': {
115
+ defaultMessage: 'Running in the background',
116
+ description: 'Read by screen readers on a background job pill, after its name.',
117
+ },
79
118
  '@theorem.composer.hint.stash-selected-draft.message': {
80
119
  defaultMessage: 'Replacing this?',
81
120
  description: 'Hint when the whole draft is selected and could be stashed.',