@theoremjs/react 0.3.4-next.881.gf46821d → 0.3.5-next.1000.g569f044

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.
Files changed (88) hide show
  1. package/README.md +132 -6
  2. package/client/live/use-live-caption-log.d.ts +1 -1
  3. package/client/trace-story.d.ts +1 -1
  4. package/client/transcript-groups.d.ts +27 -4
  5. package/client/transcript-groups.js +45 -7
  6. package/components/InkWaveform.d.ts +1 -1
  7. package/components/live/use-live-call.d.ts +3 -3
  8. package/components/live/use-live-runner-controls.d.ts +2 -2
  9. package/components/live/use-live-runner-ui.d.ts +3 -3
  10. package/components/live/use-live-session-client.d.ts +2 -2
  11. package/components/use-composer-voice.d.ts +1 -1
  12. package/components/use-voice-playback.d.ts +1 -1
  13. package/hooks/use-embedding-index.d.ts +1 -1
  14. package/hooks/use-theorem-chat.d.ts +45 -44
  15. package/hooks/use-theorem-chat.js +10 -1
  16. package/hooks/use-theorem-decision.d.ts +1 -1
  17. package/hooks/use-theorem-embedding.d.ts +1 -1
  18. package/hooks/use-theorem-host.d.ts +1 -1
  19. package/hooks/use-turn-clock.d.ts +19 -0
  20. package/hooks/use-turn-clock.js +71 -0
  21. package/index.d.ts +8 -6
  22. package/index.js +1 -0
  23. package/live.d.ts +4 -4
  24. package/package.json +5 -5
  25. package/ui/ChatComposerBar.d.ts +17 -0
  26. package/ui/ChatComposerBar.js +141 -50
  27. package/ui/ChatComposerRow.d.ts +54 -0
  28. package/ui/ChatComposerRow.js +194 -0
  29. package/ui/ChatTranscript.d.ts +31 -2
  30. package/ui/ChatTranscript.js +158 -90
  31. package/ui/ConsoleFrame.d.ts +2 -2
  32. package/ui/DecisionAnswers.d.ts +1 -1
  33. package/ui/DecisionAnswers.js +9 -6
  34. package/ui/DecisionImages.d.ts +4 -3
  35. package/ui/EmbeddingDocuments.d.ts +2 -2
  36. package/ui/EmbeddingQuery.d.ts +2 -2
  37. package/ui/EmbeddingResults.d.ts +3 -3
  38. package/ui/LiveCallTile.d.ts +2 -2
  39. package/ui/LiveCaptionsPanel.d.ts +1 -1
  40. package/ui/LiveRunner.d.ts +6 -4
  41. package/ui/LiveRunner.js +4 -4
  42. package/ui/LiveToolGateDialog.d.ts +1 -1
  43. package/ui/LiveVideoPreview.d.ts +1 -1
  44. package/ui/RadialCharts.d.ts +2 -2
  45. package/ui/RankedBars.d.ts +1 -1
  46. package/ui/SchemaFields.d.ts +1 -1
  47. package/ui/SchemaFields.js +56 -3
  48. package/ui/ShapedData.js +4 -4
  49. package/ui/StateFields.d.ts +1 -1
  50. package/ui/StateFields.js +3 -3
  51. package/ui/TheoremChat.d.ts +72 -4
  52. package/ui/TheoremChat.js +53 -33
  53. package/ui/TheoremDecision.d.ts +3 -3
  54. package/ui/TheoremEmbedding.d.ts +2 -2
  55. package/ui/TheoremHost.d.ts +16 -2
  56. package/ui/TheoremHost.js +6 -6
  57. package/ui/TheoremSurface.d.ts +22 -0
  58. package/ui/TheoremSurface.js +13 -0
  59. package/ui/ToolResult.js +8 -6
  60. package/ui/TraceCharts.d.ts +2 -2
  61. package/ui/TraceGuardrails.d.ts +2 -2
  62. package/ui/TraceInspectorPanel.d.ts +1 -1
  63. package/ui/TraceOverview.d.ts +2 -2
  64. package/ui/TraceSpanDetail.d.ts +1 -1
  65. package/ui/TraceStory.d.ts +2 -2
  66. package/ui/TraceValues.d.ts +2 -2
  67. package/ui/TraceWaterfall.d.ts +1 -1
  68. package/ui/approval-heading.d.ts +1 -1
  69. package/ui/built/theme.css +91 -41
  70. package/ui/built/theme.css.d.ts +2 -2
  71. package/ui/built/theorem.d.ts +2 -2
  72. package/ui/built/theorem.js +41 -19
  73. package/ui/built/theorem.variants.d.ts +2 -2
  74. package/ui/embedding-space-view.d.ts +1 -1
  75. package/ui/index.d.ts +33 -28
  76. package/ui/index.js +4 -1
  77. package/ui/labels-provider.d.ts +1 -1
  78. package/ui/labels.d.ts +66 -2
  79. package/ui/labels.js +64 -0
  80. package/ui/media-viewer.d.ts +34 -0
  81. package/ui/media-viewer.js +27 -0
  82. package/ui/tool-media-shown.d.ts +13 -0
  83. package/ui/tool-media-shown.js +15 -0
  84. package/ui/tool-media.d.ts +34 -0
  85. package/ui/tool-media.js +52 -0
  86. package/ui/trace-patterns.d.ts +1 -1
  87. package/ui/transcript-copy-text.d.ts +1 -1
  88. package/ui/transcript-copy-text.js +1 -1
@@ -0,0 +1,194 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Badge } from '@astryxdesign/core/Badge';
3
+ import { Banner } from '@astryxdesign/core/Banner';
4
+ import { Card } from '@astryxdesign/core/Card';
5
+ import { useCollapsible } from '@astryxdesign/core/Collapsible';
6
+ import { HStack } from '@astryxdesign/core/HStack';
7
+ import { IconButton } from '@astryxdesign/core/IconButton';
8
+ import { Spinner } from '@astryxdesign/core/Spinner';
9
+ import { StackItem } from '@astryxdesign/core/Stack';
10
+ import { Text } from '@astryxdesign/core/Text';
11
+ import { Token } from '@astryxdesign/core/Token';
12
+ import { VStack } from '@astryxdesign/core/VStack';
13
+ import { IconChevronDown, IconChevronUp, IconPlayerStopFilled } from '@tabler/icons-react';
14
+ import { useId, useLayoutEffect, useState, } from 'react';
15
+ import { useSecondTicker } from "../hooks/use-second-ticker.js";
16
+ import { liveDuration } from "./labels.js";
17
+ import { useLabels } from "./labels-provider.js";
18
+ /**
19
+ * A `--theorem-composer-*` property, or Theorem's value when the page sets none.
20
+ * why: Inline styles beat Astryx's own, so every look the row has goes through one of these and
21
+ * a builder sets it in CSS, on any element above the composer, or in their Astryx theme's
22
+ * `localTokens`.
23
+ */
24
+ const knob = (name, fallback) => `var(--theorem-composer-${name}, ${fallback})`;
25
+ const RADIUS = knob('radius', 'var(--radius-chat)');
26
+ const FILL = knob('fill', 'var(--color-background-popover)');
27
+ const SHADOW = knob('shadow', 'var(--shadow-low)');
28
+ const PADDING = knob('padding', 'var(--spacing-3)');
29
+ const GAP = knob('gap', 'var(--spacing-2)');
30
+ const INSET = knob('inset', '0px');
31
+ const TRAY_RADIUS = knob('tray-radius', RADIUS);
32
+ const TRAY_PADDING = knob('tray-padding', 'var(--spacing-3)');
33
+ const TRAY_HEADER_HEIGHT = 'var(--size-element-sm)';
34
+ /** why: Half the folded height, so the folded tray is round at both ends. */
35
+ const TRAY_FOLDED_RADIUS = knob('tray-folded-radius', `calc(${TRAY_PADDING} + ${TRAY_HEADER_HEIGHT} / 2)`);
36
+ const PILL_HEIGHT = knob('pill-height', 'var(--size-element-lg)');
37
+ const PILL_RADIUS = knob('pill-radius', 'var(--radius-full)');
38
+ const PILL_FILL = knob('pill-fill', FILL);
39
+ const PILL_SHADOW = knob('pill-shadow', SHADOW);
40
+ const PILL_ALIGN = knob('pill-align', 'center');
41
+ /** The pill shape, kept whole when the row scrolls. */
42
+ const PILL = {
43
+ height: PILL_HEIGHT,
44
+ flexShrink: 0,
45
+ border: 'none',
46
+ borderRadius: PILL_RADIUS,
47
+ background: PILL_FILL,
48
+ boxShadow: PILL_SHADOW,
49
+ '--_button-radius': PILL_RADIUS,
50
+ };
51
+ /** why: The stop button sits in the pill's end with the same ring of space all round it. */
52
+ const WORKING_PILL = {
53
+ ...PILL,
54
+ paddingInlineEnd: `calc((${PILL_HEIGHT} - var(--size-element-sm)) / 2)`,
55
+ };
56
+ /** invariant: The pill row keeps one pill's height whatever it holds, so the composer never moves. */
57
+ const PILL_ROW = { paddingInline: INSET, minHeight: PILL_HEIGHT };
58
+ /** why: One pill sits where `pill-align` puts it; more start at the edge and scroll sideways. */
59
+ const PILLS_ONE = { display: 'flex', justifyContent: PILL_ALIGN };
60
+ const PILLS_MANY = {
61
+ overflowX: 'auto',
62
+ scrollbarWidth: 'none',
63
+ // why: Pills that scroll fade out at the end instead of being cut against the hint.
64
+ maskImage: 'linear-gradient(to right, black calc(100% - var(--spacing-6)), transparent)',
65
+ };
66
+ /** The tray: a card of its own over the surface, a gap between them. */
67
+ /** why: The radius moves with the height, so the tray's ends stay round as it folds. */
68
+ const trayStyle = (open) => ({
69
+ marginInline: INSET,
70
+ border: 'none',
71
+ borderRadius: open ? TRAY_RADIUS : TRAY_FOLDED_RADIUS,
72
+ background: FILL,
73
+ boxShadow: SHADOW,
74
+ padding: TRAY_PADDING,
75
+ transition: 'border-radius var(--duration-medium) var(--ease-standard)',
76
+ });
77
+ const TRAY_HEADER = { cursor: 'pointer', minHeight: TRAY_HEADER_HEIGHT };
78
+ /** why: Folding animates the row's height to zero, so the tray closes in place. */
79
+ const trayBody = (open) => ({
80
+ display: 'grid',
81
+ gridTemplateRows: open ? '1fr' : '0fr',
82
+ transition: 'grid-template-rows var(--duration-medium) var(--ease-standard)',
83
+ });
84
+ const TRAY_BODY_INNER = { overflow: 'hidden', minHeight: 0 };
85
+ const TRAY_CONTENT = { paddingBlockStart: 'var(--spacing-3)' };
86
+ /**
87
+ * The working pill: what runs and for how long, and its stop button.
88
+ * why: It counts from the chat's turn clock, the one the transcript's status line reads, so the
89
+ * two agree and a wait on approval does not count.
90
+ */
91
+ function WorkingPill({ since, icons, onStop, }) {
92
+ const t = useLabels();
93
+ const now = useSecondTicker(since !== undefined);
94
+ const stop = t('@theorem.composer.pill.stop');
95
+ const label = since === undefined
96
+ ? t('@theorem.composer.pill.working')
97
+ : t('@theorem.composer.pill.working_for', { duration: liveDuration(t, now - since) });
98
+ return (_jsx(Token, { size: "lg", className: "theorem-composer-pill", "data-pill": "working", style: WORKING_PILL, label: label, icon: icons?.working ?? _jsx(Spinner, { size: "sm", shade: "inherit", "aria-label": label }), endContent: _jsx(IconButton, { label: stop, tooltip: stop, size: "sm", variant: "secondary", icon: icons?.stop ?? _jsx(IconPlayerStopFilled, { size: 12 }), onClick: onStop }) }));
99
+ }
100
+ /**
101
+ * The pill row. One pill sits centred over the composer (see `pill-align`); with more, the working
102
+ * pill leads and the rest follow it, scrolling sideways once they outgrow the row.
103
+ */
104
+ function PillRow(props) {
105
+ const t = useLabels();
106
+ const pills = [
107
+ props.isWorking ? (_jsx(WorkingPill, { since: props.workingSince, icons: props.icons, onStop: props.onStop }, "working")) : null,
108
+ ...props.backgroundJobs.map((job) => (_jsx(Token, { size: "lg", className: "theorem-composer-pill", "data-pill": "background", style: PILL, label: job.label, description: t('@theorem.composer.pill.background'), icon: props.icons?.backgroundJob ?? (_jsx(Spinner, { size: "sm", shade: "inherit", "aria-label": t('@theorem.composer.pill.background') })) }, job.callId))),
109
+ ].filter(Boolean);
110
+ if (pills.length === 0 && !props.hint)
111
+ return null;
112
+ return (_jsxs(HStack, { gap: 2, vAlign: "center", className: "theorem-composer-pills", style: PILL_ROW, children: [_jsx(StackItem, { size: "fill", style: pills.length > 1 ? PILLS_MANY : PILLS_ONE, children: _jsx(HStack, { gap: 1, vAlign: "center", children: pills }) }), props.hint] }));
113
+ }
114
+ /**
115
+ * What waits to send, on a card of its own above the surface: a header with the count, then the
116
+ * content, which folds away under the header.
117
+ */
118
+ function RowTray({ tray }) {
119
+ const t = useLabels();
120
+ const { isOpen, toggle } = useCollapsible({ isCollapsible: true });
121
+ const contentId = useId();
122
+ const Chevron = isOpen ? IconChevronDown : IconChevronUp;
123
+ return (_jsxs(Card, { elevation: "none", className: "theorem-composer-tray", "data-open": isOpen, style: trayStyle(isOpen), children: [_jsxs(HStack, { gap: 2, vAlign: "center", role: "button", tabIndex: 0, "aria-expanded": isOpen, "aria-controls": contentId, "aria-label": t(isOpen ? '@theorem.composer.tray.collapse' : '@theorem.composer.tray.expand', {
124
+ label: tray.label,
125
+ }), style: TRAY_HEADER, onClick: toggle, onKeyDown: (event) => {
126
+ if (event.key !== 'Enter' && event.key !== ' ')
127
+ return;
128
+ event.preventDefault();
129
+ toggle();
130
+ }, children: [_jsx(Badge, { variant: "neutral", label: tray.count }), _jsx(StackItem, { size: "fill", children: _jsx(Text, { size: "sm", color: "secondary", children: tray.label }) }), _jsx(Chevron, { size: 16, "aria-hidden": true })] }), _jsx("div", { id: contentId, style: trayBody(isOpen), inert: !isOpen, children: _jsx("div", { style: TRAY_BODY_INNER, children: _jsx("div", { style: TRAY_CONTENT, children: tray.content }) }) })] }));
131
+ }
132
+ /**
133
+ * Whether the field's text has wrapped past one line. Once it has, the row stays stacked until
134
+ * the draft empties.
135
+ * why: In the stacked layout the field is wider, so the same text may fit one line again; going
136
+ * back then would flip the layout on every keystroke.
137
+ */
138
+ function useWrapped(editorRef, draftText) {
139
+ const [wrapped, setWrapped] = useState(false);
140
+ const empty = draftText.trim() === '' && !draftText.includes('\n');
141
+ if (empty && wrapped)
142
+ setWrapped(false);
143
+ useLayoutEffect(() => {
144
+ const root = editorRef.current;
145
+ if (!root || wrapped)
146
+ return;
147
+ const field = root.querySelector('[contenteditable]') ?? root;
148
+ const measure = () => {
149
+ const line = Number.parseFloat(getComputedStyle(field).lineHeight);
150
+ if (Number.isFinite(line) && field.scrollHeight > line * 1.5)
151
+ setWrapped(true);
152
+ };
153
+ measure();
154
+ const observer = new ResizeObserver(measure);
155
+ observer.observe(field);
156
+ return () => observer.disconnect();
157
+ }, [editorRef, wrapped]);
158
+ return wrapped && !empty;
159
+ }
160
+ /** The field's slot: it shares the row, or takes a line of its own once the text wraps. */
161
+ function RowField({ input, stacked }) {
162
+ if (!input)
163
+ return null;
164
+ return (_jsx(StackItem, { size: "fill", crossAlignSelf: "center", style: stacked ? { flexBasis: '100%' } : { width: 0 }, children: input }));
165
+ }
166
+ /** The surface: Astryx's composer body, its look from the knobs above. */
167
+ const ROW_SURFACE = {
168
+ border: 'none',
169
+ borderRadius: RADIUS,
170
+ background: FILL,
171
+ boxShadow: SHADOW,
172
+ padding: PADDING,
173
+ // why: As in ChatComposer: buttons follow the shell's curve, so send and the send menu are round.
174
+ '--_button-radius': `max(var(--radius-element), calc(${RADIUS} - ${PADDING}))`,
175
+ };
176
+ /** The surface: attach, the field, then the controls, the mic, and send. */
177
+ function RowSurface(props) {
178
+ const attach = props.attach ? _jsx(StackItem, { children: props.attach }) : null;
179
+ 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] }) })] }) }));
180
+ }
181
+ function RowStatus({ status }) {
182
+ if (!status)
183
+ return null;
184
+ return (_jsx(Banner, { status: status.type, role: status.type === 'error' ? 'alert' : 'status', title: status.message }));
185
+ }
186
+ /**
187
+ * Theorem's one-row composer: the field, then the controls, the mic, and send, on one line.
188
+ * Text that wraps moves the field onto its own line above them, the stacked layout. Above
189
+ * it, the pill row: the reply in progress (stop is on its pill) and the background jobs.
190
+ */
191
+ export function ChatComposerRow(props) {
192
+ const stacked = useWrapped(props.editorRef, props.draftText);
193
+ 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, 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 })] }));
194
+ }
@@ -3,8 +3,10 @@ import type { LabelOverrides } from '@theoremjs/agents';
3
3
  import { type TranscriptBlock } from '@theoremjs/agents/interface';
4
4
  import type { AnsweringGate } from '@theoremjs/web/client';
5
5
  import { type ReactNode } from 'react';
6
- import { type ComposeAssistantTurnOptions } from '../client/transcript-groups.ts';
7
- import { type ToolDecision } from './ToolGateCard.tsx';
6
+ import { type ComposeAssistantTurnOptions, type StepLayout } from '../client/transcript-groups.js';
7
+ import { type TurnClock } from '../hooks/use-turn-clock.js';
8
+ import { type ToolDecision } from './ToolGateCard.js';
9
+ import { type MediaReference } from './tool-media.js';
8
10
  export type ChatTranscriptProps = {
9
11
  blocks: readonly TranscriptBlock[];
10
12
  /** Assistant display name (profile handle). */
@@ -23,6 +25,11 @@ export type ChatTranscriptProps = {
23
25
  * starts at its block, and that block always starts a turn of its own.
24
26
  */
25
27
  dividers?: Readonly<Record<string, string>>;
28
+ /**
29
+ * The chat's turn clock (`useTheoremChat().turnClock`), so the times here agree with the
30
+ * composer's working pill. Without it the transcript keeps its own.
31
+ */
32
+ clock?: TurnClock;
26
33
  /**
27
34
  * Set for image profiles: generated images show large, framed to their own
28
35
  * aspect ratio, with a matching skeleton while one generates.
@@ -33,11 +40,26 @@ export type ChatTranscriptProps = {
33
40
  * on an agent tool's call row what the agent it ran used. Off by default.
34
41
  */
35
42
  usage?: boolean;
43
+ /**
44
+ * The profile's `tools.showData` (`iface.tools.showData`): whether a tool call's row opens on its
45
+ * detail, what it ran with, the calls its agent made, and what came back. On by default. Off, each
46
+ * call is its labelled row only, and an approval shows no input: the server sent none.
47
+ */
48
+ showToolData?: boolean;
36
49
  /**
37
50
  * Where body kinds sit in a reply. Default puts `citation` last (Sources under
38
51
  * the prose). Pass `{}` to keep stream order for inline citations.
39
52
  */
40
53
  bodyKindPlacement?: ComposeAssistantTurnOptions['bodyKindPlacement'];
54
+ /**
55
+ * Where a reply's thoughts and tool calls sit. `trace` (default) folds them, with the words
56
+ * written between them, under the work status. `inline` shows each where it came: every word in
57
+ * the open, calls side by side as one row that opens from its count, and each thought a folded
58
+ * line. The work status is then a line of its own.
59
+ */
60
+ stepLayout?: StepLayout;
61
+ /** Whether a finished tool call's row shows how long it ran. Default: true. */
62
+ showToolDurations?: boolean;
41
63
  /** The profile's labels (`iface.labels`): a stopped turn says why in its words. */
42
64
  labels?: LabelOverrides;
43
65
  };
@@ -45,5 +67,12 @@ export type ChatTranscriptProps = {
45
67
  export type ImageOutput = {
46
68
  ratio?: number;
47
69
  };
70
+ /**
71
+ * A reference a tool sent, as the app's resolver shows it: a picture or video in a gallery of its
72
+ * own, a clip to play; the named file while it resolves, or when nothing does.
73
+ */
74
+ export declare function ReferencedMedia({ reference }: {
75
+ reference: MediaReference;
76
+ }): import("react").JSX.Element;
48
77
  /** Theorem transcript blocks rendered as Astryx chat messages. */
49
78
  export declare function ChatTranscript(props: ChatTranscriptProps): import("react").JSX.Element;