@theoremjs/react 0.3.4 → 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
@@ -1,7 +1,7 @@
1
1
  import type { TurnEvent } from '@theoremjs/agents';
2
2
  import type { HostInterface, HostTransport, PageTools } from '@theoremjs/web/client';
3
3
  import { type ClientFailure, type PersonGateResolution } from '@theoremjs/web/client';
4
- import type { ToolCall } from '../client/host-call.ts';
4
+ import type { ToolCall } from '../client/host-call.js';
5
5
  export type { ToolCall };
6
6
  /** One call of one of the host's tools, as it streams. */
7
7
  export type TheoremHostCall = {
@@ -0,0 +1,19 @@
1
+ import { type TranscriptTurnGroup } from '../client/transcript-groups.js';
2
+ /**
3
+ * When each turn was first seen, and how long each sat paused on approvals.
4
+ * invariant: One clock per chat: the transcript's status line and the composer's working pill
5
+ * read the same one, so they show the same time.
6
+ */
7
+ export type TurnClock = {
8
+ /** When the turn with this key was first seen. */
9
+ timeOf: (key: string) => number;
10
+ /**
11
+ * When the reply to `prompt` started, its approval waits skipped; `undefined` until it runs in
12
+ * this session. A prompt split by a divider still finds its turn.
13
+ */
14
+ replyStart: (prompt: TranscriptTurnGroup) => number | undefined;
15
+ };
16
+ /** The chat's turn clock over its grouped transcript. */
17
+ export declare function useTurnClock(groups: readonly TranscriptTurnGroup[], streaming: boolean): TurnClock;
18
+ /** When the reply in progress started, its approval waits skipped; `undefined` when none runs. */
19
+ export declare function liveTurnStart(groups: readonly TranscriptTurnGroup[], clock: TurnClock, streaming: boolean): number | undefined;
@@ -0,0 +1,71 @@
1
+ import { useRef } from 'react';
2
+ import { replyKey } from "../client/transcript-groups.js";
3
+ /** First-seen time per group key, so timestamps don't jump while streaming. */
4
+ function useFirstSeen(keys) {
5
+ const times = useRef(new Map());
6
+ const now = Date.now();
7
+ for (const key of keys) {
8
+ if (!times.current.has(key))
9
+ times.current.set(key, now);
10
+ }
11
+ // why: A key first asked for later (a divider's group) keeps the time it was first asked for.
12
+ return (key) => {
13
+ const known = times.current.get(key);
14
+ if (known !== undefined)
15
+ return known;
16
+ const at = Date.now();
17
+ times.current.set(key, at);
18
+ return at;
19
+ };
20
+ }
21
+ /**
22
+ * Each turn's span, keyed by the user group that started it. A turn stops at
23
+ * a gate and streams again under the same prompt once it's answered; the wait
24
+ * in between counts as paused, not worked.
25
+ */
26
+ function useTurnSpans(streaming, lastUserKey) {
27
+ const spans = useRef(new Map());
28
+ // why: A transcript can mount already streaming, on the first send; that's the start.
29
+ const wasStreaming = useRef(false);
30
+ if (lastUserKey && streaming !== wasStreaming.current) {
31
+ const now = Date.now();
32
+ const span = spans.current.get(lastUserKey);
33
+ if (streaming) {
34
+ const pausedMs = span?.endedAt === undefined ? 0 : span.pausedMs + now - span.endedAt;
35
+ spans.current.set(lastUserKey, { pausedMs });
36
+ }
37
+ else if (span) {
38
+ spans.current.set(lastUserKey, { ...span, endedAt: now });
39
+ }
40
+ }
41
+ wasStreaming.current = streaming;
42
+ return spans.current;
43
+ }
44
+ /** The chat's turn clock over its grouped transcript. */
45
+ export function useTurnClock(groups, streaming) {
46
+ // why: Every block's id is seen now, so a transcript that groups with dividers finds its times.
47
+ const timeOf = useFirstSeen(groups.flatMap((group, index) => [
48
+ group.kind === 'user' ? group.key : replyKey(groups, index),
49
+ ...group.blocks.flatMap((block) => group.kind === 'user' ? [block.id, `${block.id}:reply`] : [block.id]),
50
+ ]));
51
+ const spans = useTurnSpans(streaming, groups.findLast((group) => group.kind === 'user')?.key);
52
+ const turnKey = new Map();
53
+ for (const group of groups) {
54
+ if (group.kind === 'user')
55
+ for (const block of group.blocks)
56
+ turnKey.set(block.id, group.key);
57
+ }
58
+ const replyStart = (prompt) => {
59
+ const key = turnKey.get(prompt.blocks[0]?.id ?? '') ?? prompt.key;
60
+ const span = spans.get(key);
61
+ return span ? timeOf(key) + span.pausedMs : undefined;
62
+ };
63
+ return { timeOf, replyStart };
64
+ }
65
+ /** When the reply in progress started, its approval waits skipped; `undefined` when none runs. */
66
+ export function liveTurnStart(groups, clock, streaming) {
67
+ if (!streaming)
68
+ return undefined;
69
+ const prompt = groups.findLast((group) => group.kind === 'user');
70
+ return prompt ? clock.replyStart(prompt) : undefined;
71
+ }
package/index.d.ts CHANGED
@@ -8,9 +8,11 @@
8
8
  * @module
9
9
  */
10
10
  export * from '@theoremjs/web/client';
11
- export { type EmbeddingIndex, type IndexProgress, useEmbeddingIndex, } from './hooks/use-embedding-index.ts';
12
- export { type SendTextOptions, type SentTurn, type UseTheoremChatOptions, useTheoremChat, } from './hooks/use-theorem-chat.ts';
13
- export { type TheoremDecisionState, useTheoremDecision } from './hooks/use-theorem-decision.ts';
14
- export { type TheoremEmbeddingState, useTheoremEmbedding, } from './hooks/use-theorem-embedding.ts';
15
- export { type TheoremHostCall, type TheoremHostState, useTheoremHost, } from './hooks/use-theorem-host.ts';
16
- export { type TheoremInterfaceState, useTheoremInterface } from './hooks/use-theorem-interface.ts';
11
+ export { type BackgroundJob, backgroundJobs } from './client/transcript-groups.js';
12
+ export { type EmbeddingIndex, type IndexProgress, useEmbeddingIndex, } from './hooks/use-embedding-index.js';
13
+ export { type SendTextOptions, type SentTurn, type TheoremChatState, type UseTheoremChatOptions, useTheoremChat, } from './hooks/use-theorem-chat.js';
14
+ export { type TheoremDecisionState, useTheoremDecision } from './hooks/use-theorem-decision.js';
15
+ export { type TheoremEmbeddingState, useTheoremEmbedding, } from './hooks/use-theorem-embedding.js';
16
+ export { type TheoremHostCall, type TheoremHostState, useTheoremHost, } from './hooks/use-theorem-host.js';
17
+ export { type TheoremInterfaceState, useTheoremInterface } from './hooks/use-theorem-interface.js';
18
+ export type { TurnClock } from './hooks/use-turn-clock.js';
package/index.js CHANGED
@@ -8,6 +8,7 @@
8
8
  * @module
9
9
  */
10
10
  export * from '@theoremjs/web/client';
11
+ export { backgroundJobs } from "./client/transcript-groups.js";
11
12
  export { useEmbeddingIndex, } from "./hooks/use-embedding-index.js";
12
13
  export { useTheoremChat, } from "./hooks/use-theorem-chat.js";
13
14
  export { useTheoremDecision } from "./hooks/use-theorem-decision.js";
package/live.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * @module
5
5
  */
6
6
  export type { LiveCallOptions, LiveConnection, PageTool, PageToolAnswer, PageTools, } from '@theoremjs/web/client';
7
- export { type LiveCall, type LiveCallInput, useLiveCall, } from './components/live/use-live-call.ts';
8
- export { LiveCallTile, type LiveCallTileProps } from './ui/LiveCallTile.tsx';
9
- export type { LiveRunnerProps } from './ui/LiveRunner.tsx';
10
- export { LiveRunner } from './ui/LiveRunner.tsx';
7
+ export { type LiveCall, type LiveCallInput, useLiveCall, } from './components/live/use-live-call.js';
8
+ export { LiveCallTile, type LiveCallTileProps } from './ui/LiveCallTile.js';
9
+ export type { LiveRunnerProps } from './ui/LiveRunner.js';
10
+ export { LiveRunner } from './ui/LiveRunner.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/react",
3
- "version": "0.3.4",
3
+ "version": "0.3.5-next.1000.g569f044",
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",
@@ -55,13 +55,13 @@
55
55
  "recharts": "^3.10.1"
56
56
  },
57
57
  "peerDependencies": {
58
- "@astryxdesign/core": "0.7.7",
59
- "@astryxdesign/theme-neutral": "0.7.7",
58
+ "@astryxdesign/core": "0.7.16",
59
+ "@astryxdesign/theme-neutral": "0.7.16",
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.4",
64
- "@theoremjs/web": "^0.3.4"
63
+ "@theoremjs/agents": "^0.3.5-next.1000.g569f044",
64
+ "@theoremjs/web": "^0.3.5-next.1000.g569f044"
65
65
  },
66
66
  "peerDependenciesMeta": {
67
67
  "@astryxdesign/core": {
@@ -2,6 +2,8 @@ import { type ChatComposerInputHandle } from '@astryxdesign/core/Chat';
2
2
  import { type AttachmentValidationIssue, type ComposerMenuAction, type ComposerPendingMessage, type ComposerProfileInterface, type ComposerRunPhase, type LiveProfileInterface } from '@theoremjs/agents/interface';
3
3
  import type { ClientFailure } from '@theoremjs/web/client';
4
4
  import { type ReactNode } from 'react';
5
+ import type { BackgroundJob } from '../client/transcript-groups.js';
6
+ import { type ComposerRowIcons } from './ChatComposerRow.js';
5
7
  /** An option the profile declares: its allowed values, the one chosen, and how to choose another. */
6
8
  /** The effort selector's icon. The studio's Agents list shows the same one. */
7
9
  export declare const EFFORT_ICON: import("react").ForwardRefExoticComponent<import("@tabler/icons-react").IconProps & import("react").RefAttributes<SVGSVGElement>>;
@@ -18,8 +20,23 @@ export type OptionChoices = {
18
20
  values: Readonly<Record<string, string>>;
19
21
  onChange: (name: string, value: string) => void;
20
22
  };
23
+ /**
24
+ * How the composer is laid out. `stacked` (default): Astryx's composer, the field above a row of
25
+ * controls, with stop on the send button. `row`: the field and its buttons on one line, which
26
+ * stacks once the text wraps; a pill row above it shows the reply in progress, with stop on its
27
+ * pill, and the background jobs; while a reply runs the one button opens the send menu.
28
+ */
29
+ export type ComposerLayout = 'stacked' | 'row';
21
30
  export type ChatComposerBarProps = {
22
31
  iface: ComposerProfileInterface;
32
+ /** Default `stacked`. */
33
+ layout?: ComposerLayout;
34
+ /** The tool calls running in the background; the `row` layout shows each as a pill. */
35
+ backgroundJobs?: readonly BackgroundJob[];
36
+ /** When the reply in progress started, its approval waits skipped; the `row` layout's working pill counts from it. */
37
+ workingSince?: number;
38
+ /** Glyphs the `row` layout draws; each one left out keeps Theorem's. See {@link ComposerRowIcons}. */
39
+ icons?: ComposerRowIcons;
23
40
  draftText: string;
24
41
  pendingFiles: readonly File[];
25
42
  pendingVoice: readonly File[];
@@ -14,16 +14,19 @@ import { VStack } from '@astryxdesign/core/VStack';
14
14
  import { IconAdjustmentsHorizontal, IconArchive, IconArrowBigRightLines, IconArrowDown, IconArrowUp, IconBrain, IconCornerDownLeft, IconInputAi, IconListNumbers, IconMicrophone, IconPaperclip, IconPencil, IconPlayerRecordFilled, IconSend, IconStack2, IconSteeringWheel, IconX, } from '@tabler/icons-react';
15
15
  import { attachmentIssueText, labelText } from '@theoremjs/agents';
16
16
  import { composerPendingMoves, composerPendingPreview, effortSelectEnabled, interfaceEffortOptions, interfaceModelOptions, modelSelectEnabled, } from '@theoremjs/agents/interface';
17
- import { composerActionState, composerDrawerSummary, isStashShortcut, resolveComposerHint, STASH_SHORTCUT, } from '@theoremjs/web/client';
17
+ import { COMPOSER_SHORTCUTS, composerActionState, composerDrawerSummary, composerShortcut, resolveComposerHint, } from '@theoremjs/web/client';
18
18
  import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
19
19
  import { stageComposerFiles } from "../client/composer-attachments.js";
20
20
  import { useComposerVoice } from "../components/use-composer-voice.js";
21
21
  import { useEditorSelection } from "../components/use-editor-selection.js";
22
+ import { ChatComposerRow } from "./ChatComposerRow.js";
22
23
  import { ComposerControls, ComposerSelector } from "./ComposerControls.js";
23
24
  import { composerDrawerLabel } from "./labels.js";
24
25
  import { TheoremLabelsProvider, useLabels } from "./labels-provider.js";
25
26
  import { VoiceNote } from "./VoiceNote.js";
26
27
  const NO_FOCUS_RING = { '--focus-outline-width': '0px' };
28
+ /** why: A hint stays one line; the pill row scrolls its pills instead. */
29
+ const NO_WRAP = { whiteSpace: 'nowrap', flexShrink: 0 };
27
30
  /** An option the profile declares: its allowed values, the one chosen, and how to choose another. */
28
31
  /** The effort selector's icon. The studio's Agents list shows the same one. */
29
32
  export const EFFORT_ICON = IconBrain;
@@ -55,6 +58,15 @@ const SEND_ICON = {
55
58
  stash: IconArchive,
56
59
  };
57
60
  function PendingRow(props) {
61
+ const { message } = props;
62
+ const t = useLabels();
63
+ // why: The host saved the message, so the page has no action left on it.
64
+ const state = message.saved ? 'saved' : message.kind;
65
+ const Kind = message.saved ? IconSend : SEND_ICON[message.kind];
66
+ return (_jsxs(HStack, { gap: 1, align: "center", width: "100%", children: [_jsx(HoverTip, { content: t(`@theorem.composer.pending.${state}.description`), children: _jsx(Token, { label: t(`@theorem.composer.pending.${state}`), isLabelHidden: true, color: message.kind === 'steer' ? 'blue' : 'default', icon: _jsx(Kind, { size: 14 }) }) }), _jsx(StackItem, { size: "fill", style: { width: 0 }, children: _jsx(Text, { size: "sm", maxLines: 1, hasTruncateTooltip: true, children: composerPendingPreview(message) }) }), message.saved ? null : _jsx(PendingActions, { ...props })] }));
67
+ }
68
+ /** A waiting message's actions. A message the host saved has none. */
69
+ function PendingActions(props) {
58
70
  const { message } = props;
59
71
  const t = useLabels();
60
72
  const icon = (Glyph) => _jsx(Glyph, { size: 14 });
@@ -64,8 +76,7 @@ function PendingRow(props) {
64
76
  const moveUp = t('@theorem.composer.pending.move_up');
65
77
  const moveDown = t('@theorem.composer.pending.move_down');
66
78
  const remove = t('@theorem.composer.pending.remove');
67
- const Kind = SEND_ICON[message.kind];
68
- return (_jsxs(HStack, { gap: 1, align: "center", width: "100%", children: [_jsx(HoverTip, { content: t(`@theorem.composer.pending.${message.kind}.description`), children: _jsx(Token, { label: t(`@theorem.composer.pending.${message.kind}`), isLabelHidden: true, color: message.kind === 'steer' ? 'blue' : 'default', icon: _jsx(Kind, { size: 14 }) }) }), _jsx(StackItem, { size: "fill", style: { width: 0 }, children: _jsx(Text, { size: "sm", maxLines: 1, hasTruncateTooltip: true, children: composerPendingPreview(message) }) }), _jsxs(HStack, { gap: 0.5, children: [_jsx(IconButton, { label: edit, tooltip: edit, size: "sm", variant: "ghost", icon: icon(IconPencil), onClick: () => props.onRestore(message.id) }), message.kind === 'stash' ? (_jsx(IconButton, { label: queue, tooltip: queue, size: "sm", variant: "ghost", icon: icon(IconCornerDownLeft), onClick: () => props.onQueue(message.id) })) : null, _jsx(IconButton, { label: sendNow, tooltip: sendNow, size: "sm", variant: "ghost", icon: icon(IconSend), onClick: () => props.onSendNow(message.id) }), props.moves.up ? (_jsx(IconButton, { label: moveUp, tooltip: moveUp, size: "sm", variant: "ghost", icon: icon(IconArrowUp), onClick: () => props.onMove(message.id, 'up') })) : null, props.moves.down ? (_jsx(IconButton, { label: moveDown, tooltip: moveDown, size: "sm", variant: "ghost", icon: icon(IconArrowDown), onClick: () => props.onMove(message.id, 'down') })) : null, _jsx(IconButton, { label: remove, tooltip: remove, size: "sm", variant: "ghost", icon: icon(IconX), onClick: () => props.onRemove(message.id) })] })] }));
79
+ return (_jsxs(HStack, { gap: 0.5, children: [_jsx(IconButton, { label: edit, tooltip: edit, size: "sm", variant: "ghost", icon: icon(IconPencil), onClick: () => props.onRestore(message.id) }), message.kind === 'stash' ? (_jsx(IconButton, { label: queue, tooltip: queue, size: "sm", variant: "ghost", icon: icon(IconCornerDownLeft), onClick: () => props.onQueue(message.id) })) : null, _jsx(IconButton, { label: sendNow, tooltip: sendNow, size: "sm", variant: "ghost", icon: icon(IconSend), onClick: () => props.onSendNow(message.id) }), props.moves.up ? (_jsx(IconButton, { label: moveUp, tooltip: moveUp, size: "sm", variant: "ghost", icon: icon(IconArrowUp), onClick: () => props.onMove(message.id, 'up') })) : null, props.moves.down ? (_jsx(IconButton, { label: moveDown, tooltip: moveDown, size: "sm", variant: "ghost", icon: icon(IconArrowDown), onClick: () => props.onMove(message.id, 'down') })) : null, _jsx(IconButton, { label: remove, tooltip: remove, size: "sm", variant: "ghost", icon: icon(IconX), onClick: () => props.onRemove(message.id) })] }));
69
80
  }
70
81
  /** The model and effort choices this profile offers; efforts only for a chosen model. */
71
82
  export function generationOptions(iface, selectedModel) {
@@ -138,16 +149,15 @@ function composerStatus(args) {
138
149
  return warning ? { type: 'warning', message: warning } : undefined;
139
150
  }
140
151
  /** Pending messages, then two uniform rows: 64px tiles (images, voice notes), then file tokens. */
141
- function PendingDrawer(props) {
142
- const t = useLabels();
143
- return (_jsx(ChatComposerDrawer, { count: props.summary.count, label: composerDrawerLabel(t, props.summary), children: _jsxs(VStack, { gap: 2, width: "100%", children: [props.messages.map((message) => (_jsx(PendingRow, { message: message, moves: composerPendingMoves(props.messages, message.id), ...props.pendingActions }, message.id))), props.imageFiles.length + props.voiceFiles.length > 0 ? (_jsxs(HStack, { gap: 2, wrap: "wrap", vAlign: "center", children: [props.imageFiles.map(({ file, index, preview }) => (_jsx(Thumbnail, { src: preview, alt: file.name, label: file.name, onRemove: () => props.onAttachmentRemove(index) }, `${file.name}:${String(index)}`))), props.voiceFiles.map((file, index) => {
144
- const src = props.voiceUrls[index];
145
- // why: An empty src makes the browser fetch the page again; a note draws once it has its URL.
146
- return src === undefined ? null : (_jsx(VoiceNote, { src: src, mimeType: file.type || undefined, onRemove: props.onVoiceRemove }, `voice:${file.name}`));
147
- })] })) : null, props.otherFiles.length > 0 ? (_jsx(HStack, { gap: 2, wrap: "wrap", children: props.otherFiles.map(({ file, index }) => (_jsx(Token, { label: file.name, onRemove: () => props.onAttachmentRemove(index) }, `${file.name}:${String(index)}`))) })) : null] }) }));
152
+ function PendingDrawerContent(props) {
153
+ return (_jsxs(VStack, { gap: 2, width: "100%", children: [props.messages.map((message) => (_jsx(PendingRow, { message: message, moves: composerPendingMoves(props.messages, message.id), ...props.pendingActions }, message.id))), props.imageFiles.length + props.voiceFiles.length > 0 ? (_jsxs(HStack, { gap: 2, wrap: "wrap", vAlign: "center", children: [props.imageFiles.map(({ file, index, preview }) => (_jsx(Thumbnail, { src: preview, alt: file.name, label: file.name, onRemove: () => props.onAttachmentRemove(index) }, `${file.name}:${String(index)}`))), props.voiceFiles.map((file, index) => {
154
+ const src = props.voiceUrls[index];
155
+ // why: An empty src makes the browser fetch the page again; a note draws once it has its URL.
156
+ return src === undefined ? null : (_jsx(VoiceNote, { src: src, mimeType: file.type || undefined, onRemove: props.onVoiceRemove }, `voice:${file.name}`));
157
+ })] })) : null, props.otherFiles.length > 0 ? (_jsx(HStack, { gap: 2, wrap: "wrap", children: props.otherFiles.map(({ file, index }) => (_jsx(Token, { label: file.name, onRemove: () => props.onAttachmentRemove(index) }, `${file.name}:${String(index)}`))) })) : null] }));
148
158
  }
149
159
  /** A hidden file input behind the paperclip button. */
150
- function AttachFilesButton({ accept, onFiles, }) {
160
+ function AttachFilesButton({ accept, size, onFiles, }) {
151
161
  const t = useLabels();
152
162
  const label = t('@theorem.composer.attach');
153
163
  const fileInputRef = useRef(null);
@@ -158,25 +168,38 @@ function AttachFilesButton({ accept, onFiles, }) {
158
168
  if (incoming.length > 0)
159
169
  onFiles(incoming);
160
170
  }
161
- return (_jsxs(_Fragment, { children: [_jsx("input", { ref: fileInputRef, type: "file", multiple: true, hidden: true, accept: accept, onChange: handleChange }), _jsx(IconButton, { label: label, tooltip: label, size: "sm", variant: "ghost", icon: _jsx(IconPaperclip, { size: 16 }), onClick: () => fileInputRef.current?.click() })] }));
171
+ return (_jsxs(_Fragment, { children: [_jsx("input", { ref: fileInputRef, type: "file", multiple: true, hidden: true, accept: accept, onChange: handleChange }), _jsx(IconButton, { label: label, tooltip: label, size: size, variant: "ghost", icon: _jsx(IconPaperclip, { size: 16 }), onClick: () => fileInputRef.current?.click() })] }));
172
+ }
173
+ /** What a send-menu item says it does; while a step waits, queue and send now are about the step. */
174
+ function menuDescriptionKey(action, phase) {
175
+ if (phase === 'gated' && (action === 'queue' || action === 'send_now'))
176
+ return `@theorem.composer.menu.${action}.gated.description`;
177
+ return `@theorem.composer.menu.${action}.description`;
162
178
  }
163
- function SendMenu({ actions, onAction, }) {
179
+ function SendMenu({ actions, phase, onAction, trigger = 'more', }) {
164
180
  const t = useLabels();
165
181
  if (actions.length === 0)
166
182
  return null;
167
- return (_jsx(DropdownMenu, { button: {
168
- label: t('@theorem.composer.send_options'),
169
- isIconOnly: true,
170
- icon: _jsx(IconStack2, { size: 16 }),
171
- variant: 'ghost',
172
- }, hasChevron: false, placement: "above", items: actions.map((action) => {
183
+ return (_jsx(DropdownMenu, { button: trigger === 'send'
184
+ ? {
185
+ label: t('@theorem.composer.send_menu'),
186
+ isIconOnly: true,
187
+ icon: _jsx(IconListNumbers, { size: 16 }),
188
+ variant: 'primary',
189
+ }
190
+ : {
191
+ label: t('@theorem.composer.send_options'),
192
+ isIconOnly: true,
193
+ icon: _jsx(IconStack2, { size: 16 }),
194
+ variant: 'ghost',
195
+ }, hasChevron: false, placement: "above", alignment: "end", items: actions.map((action) => {
173
196
  const Glyph = SEND_ICON[action];
174
197
  return {
175
198
  id: action,
176
199
  label: t(`@theorem.composer.menu.${action}`),
177
- description: t(`@theorem.composer.menu.${action}.description`),
200
+ description: t(menuDescriptionKey(action, phase)),
178
201
  icon: _jsx(Glyph, { size: 16 }),
179
- ...(action === 'stash' ? { endContent: _jsx(Kbd, { keys: STASH_SHORTCUT }) } : {}),
202
+ endContent: _jsx(ShortcutKeys, { keys: COMPOSER_SHORTCUTS[action] }),
180
203
  onClick: () => onAction(action),
181
204
  };
182
205
  }) }));
@@ -186,10 +209,23 @@ function RecordButton({ recording, onToggle }) {
186
209
  const label = t(recording ? '@theorem.composer.stop_recording' : '@theorem.composer.record');
187
210
  return (_jsx(IconButton, { label: label, tooltip: label, size: "md", variant: recording ? 'destructive' : 'ghost', icon: recording ? _jsx(IconPlayerRecordFilled, { size: 16 }) : _jsx(IconMicrophone, { size: 16 }), onClick: onToggle }));
188
211
  }
212
+ /**
213
+ * A shortcut, worded and named as Astryx's Kbd does it, drawn with the ghost look: no key fill
214
+ * and no key edge, in secondary text.
215
+ * why: Kbd paints its keys from these tokens, so setting them here restyles only these keys.
216
+ */
217
+ const GHOST_KEYS = {
218
+ '--color-neutral': 'transparent',
219
+ '--color-border-emphasized': 'transparent',
220
+ '--color-text-primary': 'var(--color-text-secondary)',
221
+ };
222
+ function ShortcutKeys({ keys }) {
223
+ return _jsx(Kbd, { keys: keys, className: "theorem-composer-shortcut", style: GHOST_KEYS });
224
+ }
189
225
  /** Astryx's slot for contextual info (header, right side). */
190
226
  function ComposerHint({ hint, onAction }) {
191
227
  const t = useLabels();
192
- return (_jsxs(HStack, { gap: 2, vAlign: "center", children: [_jsx(Text, { size: "sm", color: "secondary", children: t(`@theorem.composer.hint.${hint.id}.message`) }), _jsx(Button, { label: t(`@theorem.composer.hint.${hint.id}.action`), size: "sm", variant: "ghost", onClick: onAction }), _jsx(Kbd, { keys: hint.shortcut })] }));
228
+ return (_jsxs(HStack, { gap: 2, vAlign: "center", style: NO_WRAP, children: [_jsx(Text, { size: "sm", color: "secondary", children: t(`@theorem.composer.hint.${hint.id}.message`) }), _jsx(Button, { label: t(`@theorem.composer.hint.${hint.id}.action`), size: "sm", variant: "ghost", onClick: onAction }), _jsx(ShortcutKeys, { keys: hint.shortcut })] }));
193
229
  }
194
230
  /** Staged files split into image tiles and file tokens, with object URLs for previews and voice notes. */
195
231
  function useStagedFiles(pendingFiles, pendingVoice) {
@@ -229,29 +265,41 @@ function ComposerRecordButton({ hasVoice, voice, }) {
229
265
  return null;
230
266
  return _jsx(RecordButton, { recording: voice.recording, onToggle: () => void voice.toggleRecording() });
231
267
  }
232
- /** The drawer of messages and files waiting to send; absent while nothing waits. */
233
- function composerDrawer(props, stagedFiles, onVoiceRemove) {
268
+ /** The tray of messages and files waiting to send; absent while nothing waits. */
269
+ function composerTray(t, props, stagedFiles, onVoiceRemove) {
234
270
  const summary = composerDrawerSummary({
235
271
  pendingMessages: props.pendingMessages,
236
272
  attachmentCount: props.pendingFiles.length + props.pendingVoice.length,
237
273
  });
238
274
  if (!summary)
239
275
  return undefined;
240
- return (_jsx(PendingDrawer, { summary: summary, messages: props.pendingMessages, ...stagedFiles, voiceFiles: props.pendingVoice, pendingActions: {
276
+ const content = (_jsx(PendingDrawerContent, { messages: props.pendingMessages, ...stagedFiles, voiceFiles: props.pendingVoice, pendingActions: {
241
277
  onMove: props.onPendingMove,
242
278
  onRemove: props.onPendingRemove,
243
279
  onQueue: props.onPendingQueue,
244
280
  onRestore: props.onPendingRestore,
245
281
  onSendNow: props.onPendingSendNow,
246
282
  }, onAttachmentRemove: props.onAttachmentRemove, onVoiceRemove: onVoiceRemove }));
283
+ return { count: summary.count, label: composerDrawerLabel(t, summary), content };
247
284
  }
248
- /** The text field, with Seance's stash shortcut while it has focus; `onStash` is absent when there is nothing to stash. */
249
- function ComposerTextInput({ editorRef, handleRef, onStash, }) {
250
- return (_jsx(ChatComposerInput, { ref: editorRef, handleRef: handleRef, onKeyDown: (event) => {
251
- if (!isStashShortcut(event))
285
+ /**
286
+ * The text field, with the send menu's shortcuts while it has focus: each acts only when the
287
+ * menu offers it. `field` wires it up when it stands outside Astryx's composer (the row layout).
288
+ */
289
+ function ComposerTextInput({ editorRef, handleRef, menuActions, onMenuAction, onFiles, field, }) {
290
+ return (_jsx(ChatComposerInput, { ref: editorRef, handleRef: handleRef, onFiles: onFiles, ...(field
291
+ ? {
292
+ value: field.value,
293
+ onChange: field.onChange,
294
+ onSubmit: field.onSubmit,
295
+ placeholder: field.placeholder,
296
+ }
297
+ : {}), onKeyDown: (event) => {
298
+ const action = composerShortcut(event);
299
+ if (!action || !menuActions.includes(action))
252
300
  return;
253
301
  event.preventDefault();
254
- onStash?.();
302
+ onMenuAction(action);
255
303
  } }));
256
304
  }
257
305
  function isLiveComposer(props) {
@@ -290,8 +338,20 @@ function LiveComposerBarBody(props) {
290
338
  }), input: _jsx(ChatComposerInput, { handleRef: setEditor }), sendButton: _jsx(ChatSendButton, { isDisabled: props.isDisabled, onSend: submitTyped }) }));
291
339
  }
292
340
  function ChatComposerBarBody(props) {
293
- const { iface, phase } = props;
341
+ const parts = useComposerParts(props);
342
+ return props.layout === 'row' ? (_jsx(RowComposerBar, { props: props, parts: parts })) : (_jsx(StackedComposerBar, { props: props, parts: parts }));
343
+ }
344
+ /** What the field shows: listening while it records, else the builder's text or the default. */
345
+ function useComposerPlaceholder(props, recording) {
294
346
  const t = useLabels();
347
+ if (recording)
348
+ return t('@theorem.composer.listening');
349
+ return (props.placeholder ?? t('@theorem.composer.placeholder', { handle: props.iface.identity.handle }));
350
+ }
351
+ /** Everything both layouts draw, worked out once so the two cannot drift. */
352
+ function useComposerParts(props) {
353
+ const t = useLabels();
354
+ const { iface, phase } = props;
295
355
  const inputs = iface.inputs;
296
356
  const pendingFiles = useMemo(() => [...props.pendingFiles], [props.pendingFiles]);
297
357
  const voice = useComposerVoice({
@@ -303,7 +363,7 @@ function ChatComposerBarBody(props) {
303
363
  });
304
364
  const stagedFiles = useStagedFiles(props.pendingFiles, props.pendingVoice);
305
365
  useEffect(() => () => voice.disposeRecorder(), [voice.disposeRecorder]);
306
- const { primary, menuActions, primaryDisabled } = composerActionState({
366
+ const actions = composerActionState({
307
367
  iface,
308
368
  phase,
309
369
  draftText: props.draftText,
@@ -311,39 +371,70 @@ function ChatComposerBarBody(props) {
311
371
  pendingVoice: props.pendingVoice,
312
372
  recording: voice.recording,
313
373
  });
314
- const canStash = menuActions.includes('stash');
315
374
  const editorRef = useRef(null);
316
375
  const hint = resolveComposerHint({
317
376
  draftText: props.draftText,
318
377
  selectedText: useEditorSelection(editorRef),
319
- canStash,
378
+ canStash: actions.menuActions.includes('stash'),
320
379
  });
321
- function runPrimary() {
322
- if (primaryDisabled)
380
+ const runPrimary = () => {
381
+ if (actions.primaryDisabled)
323
382
  return;
324
- if (primary === 'stop')
383
+ if (actions.primary === 'stop')
325
384
  props.onStop();
326
385
  else
327
386
  props.onSubmit();
328
- }
387
+ };
329
388
  const { stageFiles, stagingIssues } = useFileStaging(pendingFiles, inputs.maxFiles, props);
389
+ const placeholder = useComposerPlaceholder(props, voice.recording);
390
+ return {
391
+ ...actions,
392
+ runPrimary,
393
+ editorRef,
394
+ placeholder,
395
+ // why: A profile that takes no text has no text field (false, not null: null gets Astryx's default one).
396
+ input: inputs.text && (_jsx(ComposerTextInput, { editorRef: editorRef, handleRef: props.inputRef, menuActions: actions.menuActions, onMenuAction: props.onMenuAction,
397
+ // why: A pasted or dropped file goes through the same staging and limits as the attach button.
398
+ onFiles: inputs.attachments ? stageFiles : undefined,
399
+ // why: The row draws its own surface, outside Astryx's ChatComposer, so the field takes its value here.
400
+ field: props.layout === 'row'
401
+ ? {
402
+ value: props.draftText,
403
+ onChange: props.onDraftTextChange,
404
+ onSubmit: runPrimary,
405
+ placeholder,
406
+ }
407
+ : undefined })),
408
+ tray: composerTray(t, props, stagedFiles, () => voice.discardRecordingOrVoice()),
409
+ attach: inputs.attachments ? (_jsx(AttachFilesButton, { accept: inputs.attachments.acceptAttr, size: props.layout === 'row' ? 'md' : 'sm', onFiles: stageFiles })) : undefined,
410
+ hintNode: hint ? (_jsx(ComposerHint, { hint: hint, onAction: () => props.onMenuAction('stash') })) : undefined,
411
+ controls: (_jsx(GenerationSelect, { iface: iface, optionChoices: props.optionChoices, selectedModel: props.selectedModel, selectedEffort: props.selectedEffort, isDisabled: phase === 'streaming', onChange: props.onGenerationChange, control: props.generationSelect })),
412
+ record: _jsx(ComposerRecordButton, { hasVoice: Boolean(inputs.voice), voice: voice }),
413
+ status: composerStatus({
414
+ failure: props.failure,
415
+ issues: [...props.issues, ...stagingIssues],
416
+ voiceFailure: voice.failure,
417
+ labels: iface.labels,
418
+ }),
419
+ };
420
+ }
421
+ /** The one-row layout. */
422
+ function RowComposerBar({ props, parts, }) {
423
+ // why: Stop lives on the working pill, so the button only sends; while a reply runs or a
424
+ // step waits, a draft opens the send menu instead (Enter still queues).
425
+ const opensMenu = props.phase !== 'idle' && parts.menuActions.length > 0;
426
+ return (_jsx(ChatComposerRow, { isWorking: props.phase === 'streaming', workingSince: props.workingSince, icons: props.icons, backgroundJobs: props.backgroundJobs ?? [], onStop: props.onStop, hint: parts.hintNode, tray: parts.tray, attach: parts.attach, input: parts.input, editorRef: parts.editorRef, draftText: props.draftText, controls: parts.controls, record: parts.record, action: 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 }));
427
+ }
428
+ /** Today's layout: Astryx's ChatComposer. */
429
+ function StackedComposerBar({ props, parts, }) {
430
+ const isStopShown = parts.primary === 'stop';
330
431
  return (_jsx(ChatComposer
331
432
  // why: No keyboard focus ring on the composer (product choice): zero Astryx's
332
433
  // focus-outline token for this subtree. The editor still shows its caret.
333
434
  , {
334
435
  // why: No keyboard focus ring on the composer (product choice): zero Astryx's
335
436
  // focus-outline token for this subtree. The editor still shows its caret.
336
- style: NO_FOCUS_RING, value: props.draftText, onChange: props.onDraftTextChange, onSubmit: runPrimary, onStop: props.onStop, isStopShown: primary === 'stop', placeholder: voice.recording
337
- ? t('@theorem.composer.listening')
338
- : (props.placeholder ??
339
- t('@theorem.composer.placeholder', { handle: iface.identity.handle })),
340
- // why: A profile that takes no text has no text field (false, not null: null gets Astryx's default one).
341
- input: inputs.text && (_jsx(ComposerTextInput, { editorRef: editorRef, handleRef: props.inputRef, onStash: canStash ? () => props.onMenuAction('stash') : undefined })), drawer: composerDrawer(props, stagedFiles, () => voice.discardRecordingOrVoice()), headerActions: inputs.attachments ? (_jsx(AttachFilesButton, { accept: inputs.attachments.acceptAttr, onFiles: stageFiles })) : undefined, headerContext: hint ? _jsx(ComposerHint, { hint: hint, onAction: () => props.onMenuAction('stash') }) : undefined, footerActions: _jsx(GenerationSelect, { iface: iface, optionChoices: props.optionChoices, selectedModel: props.selectedModel, selectedEffort: props.selectedEffort, isDisabled: phase === 'streaming', onChange: props.onGenerationChange, control: props.generationSelect }),
437
+ style: NO_FOCUS_RING, value: props.draftText, onChange: props.onDraftTextChange, onSubmit: parts.runPrimary, onStop: props.onStop, isStopShown: isStopShown, placeholder: parts.placeholder, input: parts.input, drawer: parts.tray && (_jsx(ChatComposerDrawer, { count: parts.tray.count, label: parts.tray.label, children: parts.tray.content })), headerActions: parts.attach, headerContext: parts.hintNode, footerActions: parts.controls,
342
438
  // why: Astryx: sendActions render to the left of the send button, at size="md".
343
- sendActions: _jsxs(_Fragment, { children: [_jsx(SendMenu, { actions: menuActions, onAction: props.onMenuAction }), _jsx(ComposerRecordButton, { hasVoice: Boolean(inputs.voice), voice: voice })] }), sendButton: _jsx(ChatSendButton, { isStopShown: primary === 'stop', isDisabled: primaryDisabled, onSend: runPrimary, onStop: props.onStop }), status: composerStatus({
344
- failure: props.failure,
345
- issues: [...props.issues, ...stagingIssues],
346
- voiceFailure: voice.failure,
347
- labels: iface.labels,
348
- }) }));
439
+ sendActions: _jsxs(_Fragment, { children: [_jsx(SendMenu, { actions: parts.menuActions, phase: props.phase, onAction: props.onMenuAction }), parts.record] }), sendButton: _jsx(ChatSendButton, { isStopShown: isStopShown, isDisabled: parts.primaryDisabled, onSend: parts.runPrimary, onStop: props.onStop }), status: parts.status }));
349
440
  }
@@ -0,0 +1,54 @@
1
+ import type { ChatComposerStatus } from '@astryxdesign/core/Chat';
2
+ import { type ReactNode, type RefObject } from 'react';
3
+ import type { BackgroundJob } from '../client/transcript-groups.js';
4
+ /**
5
+ * The glyphs the row composer draws. Each one left out keeps Theorem's.
6
+ * Text is in the labels (`@theorem.composer.pill.*`, `@theorem.composer.tray.*`); sizes, colours,
7
+ * radii and spacing are the `--theorem-composer-*` CSS properties.
8
+ */
9
+ export type ComposerRowIcons = {
10
+ /** Before the working pill's text. Default: Astryx's Spinner. */
11
+ working?: ReactNode;
12
+ /** Before each background job's name. Default: Astryx's Spinner. */
13
+ backgroundJob?: ReactNode;
14
+ /** In the working pill's stop button. Default: a filled square. */
15
+ stop?: ReactNode;
16
+ };
17
+ /** What waits to send: the count and label for the tray's header, and the content it folds. */
18
+ export type ComposerTray = {
19
+ count: number;
20
+ label: string;
21
+ content: ReactNode;
22
+ };
23
+ /** What the row composer draws; the bar works each piece out, so both layouts share it. */
24
+ export type ComposerRowParts = {
25
+ /** The pill row: the working pill while a reply runs, then the background jobs. */
26
+ isWorking: boolean;
27
+ /** When the reply in progress started; the working pill counts from it. */
28
+ workingSince?: number;
29
+ icons?: ComposerRowIcons;
30
+ backgroundJobs: readonly BackgroundJob[];
31
+ onStop: () => void;
32
+ /** Contextual hint, at the end of the pill row. */
33
+ hint?: ReactNode;
34
+ /** What waits to send, in the tray above the surface. */
35
+ tray?: ComposerTray;
36
+ attach?: ReactNode;
37
+ /** The text field; `false` when the profile takes no text. */
38
+ input: ReactNode;
39
+ /** The field's root, measured to know when the text wraps. */
40
+ editorRef: RefObject<HTMLDivElement | null>;
41
+ /** The draft; when it empties the row comes back from the stacked layout. */
42
+ draftText: string;
43
+ controls?: ReactNode;
44
+ record?: ReactNode;
45
+ /** The send button, or the send menu while a reply runs. */
46
+ action: ReactNode;
47
+ status?: ChatComposerStatus;
48
+ };
49
+ /**
50
+ * Theorem's one-row composer: the field, then the controls, the mic, and send, on one line.
51
+ * Text that wraps moves the field onto its own line above them, the stacked layout. Above
52
+ * it, the pill row: the reply in progress (stop is on its pill) and the background jobs.
53
+ */
54
+ export declare function ChatComposerRow(props: ComposerRowParts): import("react").JSX.Element;