reifyui 0.13.9 → 0.15.0

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.
@@ -0,0 +1,190 @@
1
+ // Types for reifyui/agent-chat. Hand-written (the source is JSX), kept beside the source.
2
+ import type { ReactNode, ReactElement, RefObject } from 'react';
3
+
4
+ export type TurnStatus = 'running' | 'done' | 'failed' | 'cancelled' | 'incomplete';
5
+ export type CallStatus = 'running' | 'done' | 'failed' | 'stopped';
6
+
7
+ export interface TextItem { kind: 'text'; id: string; text: string; closed?: boolean }
8
+ export interface ThinkingItem { kind: 'thinking'; id: string; text: string; startedAt: number | null; endedAt: number | null; open?: boolean }
9
+ export interface ToolItem {
10
+ kind: 'tool'; id: string; itemId?: string | null; name: string; args: string;
11
+ output?: string; status: CallStatus; startedAt: number | null; endedAt: number | null;
12
+ /** the whole output's length when the record keeps only its start */
13
+ truncated?: number | null;
14
+ }
15
+ export type TurnItem = TextItem | ThinkingItem | ToolItem;
16
+
17
+ export interface TurnFile { container_id: string; file_id: string; filename: string; download_url?: string }
18
+ export interface TurnUser { text: string; files?: { name: string; size?: number; src?: string }[] }
19
+ export interface Usage { input_tokens?: number; output_tokens?: number; total_tokens?: number; [k: string]: unknown }
20
+
21
+ export interface Turn {
22
+ id: string | null;
23
+ sessionId: string | null;
24
+ status: TurnStatus;
25
+ user: TurnUser | null;
26
+ items: TurnItem[];
27
+ files: TurnFile[];
28
+ /** epoch ms the turn was sent or first observed; null when nobody observed it */
29
+ startedAt: number | null;
30
+ endedAt: number | null;
31
+ /** a measured length from a record (seconds × 1000), used when the two ends were not observed */
32
+ elapsedMs?: number | null;
33
+ lastEventAt: number | null;
34
+ usage: Usage | null;
35
+ error: string | null;
36
+ incomplete: { reason: string; detail: string } | null;
37
+ model: string | null;
38
+ }
39
+
40
+ /** Any Responses stream event, an `error` event, or the broadcast feed's `harness.turn.started`. */
41
+ export interface AgentEvent { type: string; [k: string]: unknown }
42
+
43
+ export function newTurn(opts?: { id?: string; sessionId?: string; status?: TurnStatus; user?: TurnUser | null; startedAt?: number | null; model?: string }): Turn;
44
+ /** Fold one event in. `at`: receive time (epoch ms) for a live event, null for a replayed one. */
45
+ export function reduceTurn(turn: Turn | null | undefined, ev: AgentEvent, at?: number | null): Turn;
46
+ export function finish(turn: Turn, status: TurnStatus | string, at?: number | null, response?: Record<string, unknown> | null): Turn;
47
+ export function turnFromEvents(events: AgentEvent[], opts?: Parameters<typeof newTurn>[0] & { at?: number | null }): Turn;
48
+ export function turnFromResponse(resp: Record<string, unknown>, opts?: Parameters<typeof newTurn>[0] & { startedAt?: number | null; endedAt?: number | null }): Turn;
49
+ /** One entry of GET /v1/sessions/{sid}/turns. */
50
+ export function turnFromHistory(h: Record<string, unknown>): Turn;
51
+ /** A blocks-model message ({blocks, status, files, elapsed}) as a turn, timed from `clock` when given. */
52
+ export function turnFromMessage(msg: { blocks?: unknown[]; status?: string; files?: TurnFile[]; elapsed?: number; incompleteReason?: string; incompleteDetail?: string; id?: string },
53
+ clock?: Turn | null, user?: TurnUser | null): Turn;
54
+ export function liveState(turn: Turn | null | undefined): { phase: 'starting' | 'thinking' | 'tool' | 'writing'; tool: ToolItem | null } | null;
55
+ export function segments(turn: Turn): ({ type: 'text'; item: TextItem } | { type: 'work'; items: (ToolItem | ThinkingItem)[] })[];
56
+ export function latestPlan(turn: Turn, describe: typeof describeTool): TodoEntry[] | null;
57
+ export function isTerminal(status: string): boolean;
58
+
59
+ export type ToolKind = 'shell' | 'shell_output' | 'read' | 'write' | 'edit' | 'search' | 'glob' | 'list' | 'web_search' | 'web_fetch'
60
+ | 'agent' | 'todo' | 'skill' | 'think' | 'toolsearch' | 'browser' | 'mcp' | 'tool';
61
+ export interface TodoEntry { text: string; status: 'pending' | 'in_progress' | 'completed' | 'cancelled' }
62
+ export interface ToolDescription {
63
+ kind: ToolKind; target: string; targetFull: string; mono: boolean; note: string;
64
+ running: string; done: string;
65
+ diff: { added: number; removed: number } | null;
66
+ todos: TodoEntry[] | null;
67
+ }
68
+ export function describeTool(name: string, args: unknown): ToolDescription;
69
+ export function toolKind(name: string): ToolKind;
70
+ export function toolLine(d: ToolDescription, state: 'running' | 'done'): string;
71
+ export function summarizeCalls(calls: { name: string; args?: unknown }[]): string;
72
+ export function resultNote(kind: ToolKind, output: unknown): string;
73
+ export function parseToolArgs(args: unknown): Record<string, unknown>;
74
+ export function todosOf(args: Record<string, unknown>): TodoEntry[] | null;
75
+ export function diffOf(kind: ToolKind, args: Record<string, unknown>): { added: number; removed: number } | null;
76
+ export function patchStats(patch: string): { added: number; removed: number };
77
+ export function commandText(args: Record<string, unknown>): string;
78
+ export function baseNameOf(path: unknown): string;
79
+ export function lineCount(s: unknown): number;
80
+
81
+ export function formatElapsed(ms: number | null | undefined): string;
82
+ export function formatDuration(ms: number | null | undefined): string;
83
+ export function formatTokens(n: number | null | undefined): string;
84
+ export function useNow(on: boolean, everyMs?: number): number;
85
+ export function useElapsed(start: number | null | undefined, end?: number | null): number | null;
86
+
87
+ export type Motion = 'bloom' | 'sheen' | 'glint' | 'flutter' | 'glide' | 'blink' | 'flip' | 'swim' | 'spin' | 'wave'
88
+ | 'dash' | 'scuttle' | 'equalize' | 'bob' | 'pulse' | 'dots';
89
+ export const MARK_MOTIONS: Record<string, Motion>;
90
+ export const MOTIONS: Motion[];
91
+ export function motionFor(base: string | null | undefined): Motion;
92
+
93
+ export interface AgentLabels {
94
+ starting: string; thinking: string; writing: string; tool: string; thought: string;
95
+ thoughtFor: (t: string) => string; workedFor: (t: string) => string; worked: string; tokens: (n: string) => string;
96
+ stopped: string; stoppedAfter: (t: string) => string; failed: string; failedAfter: (t: string) => string; incomplete: string;
97
+ input: string; output: string; noOutput: string; copy: string; copied: string; copyFailed: string;
98
+ moreLines: (n: number) => string; fewerLines: string; failedCalls: (n: number) => string; stoppedCall: string;
99
+ plan: string; jump: string; send: string; stop: string; stopping: string; attach: string; remove: (name: string) => string; working: string;
100
+ }
101
+ export const DEFAULT_AGENT_LABELS: AgentLabels;
102
+
103
+ export interface MarkProps { mark?: ReactNode; motion?: Motion | string }
104
+
105
+ export function WorkingMark(props: MarkProps & { size?: number; still?: boolean }): ReactElement;
106
+ export function WorkingIndicator(props: MarkProps & {
107
+ start?: number | null; end?: number | null; label: string; onToggle?: () => void; expanded?: boolean; controls?: string;
108
+ className?: string; shimmer?: boolean; size?: number;
109
+ }): ReactElement;
110
+ export function CopyButton(props: { text: string; labels?: AgentLabels; label?: string }): ReactElement;
111
+ export function DiffBadge(props: { diff: { added: number; removed: number } | null }): ReactElement | null;
112
+ export function LinesBlock(props: { lines: { text: string; cls?: string }[]; limit?: number; labels?: AgentLabels; className?: string; numbered?: boolean }): ReactElement;
113
+ export function StepRow(props: { item: ToolItem; labels?: AgentLabels; defaultOpen?: boolean }): ReactElement;
114
+ export function ThinkingRow(props: { item: ThinkingItem; labels?: AgentLabels }): ReactElement;
115
+ export function WorkGroup(props: MarkProps & { items: (ToolItem | ThinkingItem)[]; live?: boolean; liveLabel?: string; start?: number | null;
116
+ labels?: AgentLabels; defaultOpen?: boolean }): ReactElement | null;
117
+ export function TodoCard(props: { todos: TodoEntry[] | null; labels?: AgentLabels; running?: boolean }): ReactElement | null;
118
+ export function StreamingText(props: { text: string; active?: boolean; render?: (text: string) => ReactNode }): ReactElement;
119
+ export function UserBubble(props: { user: TurnUser | null; renderFile?: (f: { name: string; src?: string }, i: number) => ReactNode; extra?: ReactNode }): ReactElement | null;
120
+ export function TurnOutcome(props: { turn: Turn; labels?: AgentLabels; describeIncomplete?: (i: { reason?: string; detail?: string }) => string }): ReactElement | null;
121
+
122
+ export interface AgentTurnViewProps extends MarkProps {
123
+ turn: Turn | null;
124
+ /** markdown renderer for prose (inject yours); default is plain pre-wrapped text */
125
+ renderMarkdown?: (text: string) => ReactNode;
126
+ labels?: Partial<AgentLabels>;
127
+ showUser?: boolean;
128
+ renderUserFile?: (f: { name: string; src?: string }, i: number) => ReactNode;
129
+ userExtra?: ReactNode;
130
+ /** a line above the agent's part (who answered, on which model) */
131
+ meta?: ReactNode;
132
+ /** the turn's produced files, drawn by the host (it owns their fetching) */
133
+ renderFiles?: (turn: Turn) => ReactNode;
134
+ /** under a finished turn: copy, retry, open the trace */
135
+ actions?: ReactNode;
136
+ describeIncomplete?: (i: { reason?: string; detail?: string }) => string;
137
+ /** the epoch ms the live clock counts from, when it is not the turn's own startedAt */
138
+ liveStart?: number | null;
139
+ }
140
+ export function AgentTurnView(props: AgentTurnViewProps): ReactElement | null;
141
+
142
+ export interface ComposerAttachment { id?: string; name: string; src?: string; size?: number; status?: 'uploading' | 'ready' | 'error' }
143
+ export interface AgentComposerProps {
144
+ value: string;
145
+ onChange: (v: string) => void;
146
+ onSend: () => void;
147
+ onStop?: () => void;
148
+ running?: boolean;
149
+ stopping?: boolean;
150
+ disabled?: boolean;
151
+ /** overrides the default (empty box, no attachment) */
152
+ sendDisabled?: boolean;
153
+ placeholder?: string;
154
+ runningPlaceholder?: string;
155
+ attachments?: ComposerAttachment[];
156
+ onRemoveAttachment?: (index: number) => void;
157
+ /** shows the attach button, takes dropped and pasted files */
158
+ onAttachFiles?: (files: FileList) => void;
159
+ accept?: string;
160
+ multiple?: boolean;
161
+ left?: ReactNode;
162
+ right?: ReactNode;
163
+ footer?: ReactNode;
164
+ inputId?: string;
165
+ inputRef?: RefObject<HTMLTextAreaElement | null>;
166
+ autoFocus?: boolean;
167
+ maxRows?: number;
168
+ labels?: Partial<AgentLabels>;
169
+ ariaLabel?: string;
170
+ className?: string;
171
+ }
172
+ export function AgentComposer(props: AgentComposerProps): ReactElement;
173
+
174
+ export function useStickToBottom(contentRef: RefObject<HTMLElement | null>, opts?: { scroller?: HTMLElement | null; anchorRef?: RefObject<HTMLElement | null> | null; followKey?: unknown; threshold?: number; enabled?: boolean }):
175
+ { atBottom: boolean; toBottom: () => void };
176
+
177
+ export interface AgentConversationProps extends MarkProps {
178
+ children?: ReactNode;
179
+ composer?: ReactNode;
180
+ notice?: ReactNode;
181
+ running?: boolean;
182
+ /** 'pane' fills a fixed-height box and scrolls in it; 'page' lives in a scrolling page */
183
+ mode?: 'pane' | 'page';
184
+ /** change it (a new turn sent) to return to the bottom */
185
+ followKey?: unknown;
186
+ labels?: Partial<AgentLabels>;
187
+ className?: string;
188
+ empty?: ReactNode;
189
+ }
190
+ export function AgentConversation(props: AgentConversationProps): ReactElement;
@@ -0,0 +1,24 @@
1
+ // reifyui/agent-chat: an agent's turn the way Claude Code shows it.
2
+ //
3
+ // the data newTurn, reduceTurn, finish, turnFromEvents, turnFromResponse, turnFromHistory,
4
+ // turnFromMessage, liveState, segments, latestPlan, isTerminal
5
+ // the words describeTool, toolKind, toolLine, summarizeCalls, resultNote, parseToolArgs,
6
+ // todosOf, diffOf, patchStats, commandText
7
+ // the clocks formatElapsed, formatDuration, formatTokens, useElapsed, useNow
8
+ // the marks MARK_MOTIONS, MOTIONS, motionFor
9
+ // the views AgentConversation, AgentTurnView, WorkGroup, StepRow, ThinkingRow, TodoCard,
10
+ // WorkingIndicator, WorkingMark, StreamingText, TurnOutcome, UserBubble,
11
+ // AgentComposer, CopyButton, DiffBadge, LinesBlock, useStickToBottom,
12
+ // DEFAULT_AGENT_LABELS
13
+ //
14
+ // Styles: reifyui/styles/agent-chat.css. A separate entry so a host that renders a Button never
15
+ // pulls in a conversation, and so nothing here changes what the root ChatMessages/ChatPanel do.
16
+ export { newTurn, reduceTurn, finish, turnFromEvents, turnFromResponse, turnFromHistory, turnFromMessage,
17
+ liveState, segments, latestPlan, isTerminal } from './turn.js';
18
+ export { describeTool, toolKind, toolLine, summarizeCalls, resultNote, parseToolArgs, todosOf, diffOf, patchStats,
19
+ commandText, baseNameOf, lineCount } from './tools.js';
20
+ export { formatElapsed, formatDuration, formatTokens, useElapsed, useNow } from './time.js';
21
+ export { MARK_MOTIONS, MOTIONS, motionFor } from './marks.js';
22
+ export { AgentConversation, AgentTurnView, WorkGroup, StepRow, ThinkingRow, TodoCard, WorkingIndicator, WorkingMark,
23
+ StreamingText, TurnOutcome, UserBubble, AgentComposer, CopyButton, DiffBadge, LinesBlock, useStickToBottom,
24
+ DEFAULT_AGENT_LABELS } from './components.jsx';
@@ -0,0 +1,51 @@
1
+ // The working mark: each harness's own logo, moving the way that logo suggests.
2
+ //
3
+ // The package ships the MOTIONS (CSS keyframes in styles/agent-chat.css), never the logos: a
4
+ // host passes its official mark as a node and names a motion. motionFor(base) is the house
5
+ // choice for the harnesses we know, picked by looking at each mark:
6
+ //
7
+ // bloom the Claude starburst turns a quarter and breathes, like the CLI's ✻ ✽ ✶ spinner
8
+ // sheen a light passes across the tile (Codex's prompt, Kimi's K, Kilo's grid)
9
+ // glint brightens and swells, a spark catching light (Gemini)
10
+ // flutter a quick wing beat, tilt and lift (Hermes, the messenger)
11
+ // glide a bird's lift and settle (Goose)
12
+ // blink the tile blinks shut and open, a terminal cursor (OpenCode)
13
+ // flip a coin turning on its vertical axis (pi, omp)
14
+ // swim a short wave from nose to tail (DeepSeek's whale)
15
+ // spin a steady revolution, for round marks (Qwen, Grok, System One, OpenSquilla)
16
+ // wave hands waving from the wrist (OpenHands)
17
+ // dash a sprint forward and back (CheetahClaws)
18
+ // scuttle a sideways skitter (ZeroClaw's crab)
19
+ // equalize a level meter rising and falling (MiniMax's waveform)
20
+ // bob a soft hop (robots and app tiles: Cline, Agent Zero, Qoder, nanobot)
21
+ // pulse the default: scale and opacity breathing
22
+ //
23
+ // Every motion stops under prefers-reduced-motion; the mark then stands still and the line's
24
+ // words alone say the work is going on.
25
+
26
+ export const MARK_MOTIONS = {
27
+ 'claude-code': 'bloom', claude: 'bloom', anthropic: 'bloom',
28
+ codex: 'sheen', openai: 'sheen',
29
+ gemini: 'glint', 'gemini-cli': 'glint',
30
+ hermes: 'flutter',
31
+ goose: 'glide',
32
+ opencode: 'blink',
33
+ pi: 'flip', omp: 'flip',
34
+ dsh: 'swim', deepseek: 'swim',
35
+ qwen: 'spin', grok: 'spin', systemone: 'spin', opensquilla: 'spin',
36
+ openhands: 'wave',
37
+ cheetahclaws: 'dash',
38
+ zeroclaw: 'scuttle',
39
+ minimax: 'equalize',
40
+ cline: 'bob', agentzero: 'bob', qoder: 'bob', nanobot: 'bob',
41
+ kimi: 'sheen', kilo: 'sheen', jcode: 'pulse', mimo: 'pulse', aider: 'pulse',
42
+ };
43
+
44
+ export const MOTIONS = ['bloom', 'sheen', 'glint', 'flutter', 'glide', 'blink', 'flip', 'swim', 'spin', 'wave',
45
+ 'dash', 'scuttle', 'equalize', 'bob', 'pulse', 'dots'];
46
+
47
+ /** The motion for a base harness id, 'pulse' for one we do not know. */
48
+ export function motionFor(base) {
49
+ const k = String(base || '').toLowerCase().trim();
50
+ return MARK_MOTIONS[k] || 'pulse';
51
+ }
@@ -0,0 +1,55 @@
1
+ // Clocks for the live line. Every figure here is the difference between two observed moments; a
2
+ // missing end means "still going" (counted against now), a missing start means nothing is shown.
3
+ import { useEffect, useState } from 'react';
4
+
5
+ /** 9s, 1m 4s, 1h 2m. Under a second reads "0s": a clock that has just started, not a measurement. */
6
+ export function formatElapsed(ms) {
7
+ if (ms == null || !isFinite(ms) || ms < 0) return '';
8
+ const s = Math.floor(ms / 1000);
9
+ if (s < 60) return `${s}s`;
10
+ const m = Math.floor(s / 60);
11
+ if (m < 60) return `${m}m ${s % 60}s`;
12
+ const h = Math.floor(m / 60);
13
+ return `${h}h ${m % 60}m`;
14
+ }
15
+
16
+ /** A finished span, read once: 1.2s under ten seconds (the tenths mean something there), else as above. */
17
+ export function formatDuration(ms) {
18
+ if (ms == null || !isFinite(ms) || ms < 0) return '';
19
+ if (ms < 1000) return `${Math.max(0.1, Math.round(ms / 100) / 10).toFixed(1)}s`;
20
+ if (ms < 10000) return `${(Math.round(ms / 100) / 10).toFixed(1)}s`;
21
+ return formatElapsed(ms);
22
+ }
23
+
24
+ /** 950, 12.3k, 1.2M tokens. */
25
+ export function formatTokens(n) {
26
+ if (n == null || !isFinite(n)) return '';
27
+ if (n < 1000) return String(Math.round(n));
28
+ if (n < 1e6) return `${(n / 1000).toFixed(1).replace(/\.0$/, '')}k`;
29
+ return `${(Math.round(n / 1e5) / 10).toFixed(1).replace(/\.0$/, '')}M`;
30
+ }
31
+
32
+ /** Now, re-read every `everyMs` while `on`; frozen when off. */
33
+ export function useNow(on, everyMs = 1000) {
34
+ const [now, setNow] = useState(() => Date.now());
35
+ useEffect(() => {
36
+ if (!on) return undefined;
37
+ setNow(Date.now());
38
+ // tick on the second boundary of the wall clock so several timers on a page change together
39
+ let iv = null;
40
+ const t0 = setTimeout(() => {
41
+ setNow(Date.now());
42
+ iv = setInterval(() => setNow(Date.now()), everyMs);
43
+ }, everyMs - (Date.now() % everyMs));
44
+ return () => { clearTimeout(t0); if (iv) clearInterval(iv); };
45
+ }, [on, everyMs]);
46
+ return now;
47
+ }
48
+
49
+ /** Milliseconds from `start` to `end` (or to now while `end` is null), or null without a start. */
50
+ export function useElapsed(start, end = null) {
51
+ const live = start != null && end == null;
52
+ const now = useNow(live);
53
+ if (start == null) return null;
54
+ return Math.max(0, (end ?? now) - start);
55
+ }