@paddockai/react 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ui.cjs ADDED
@@ -0,0 +1,586 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/ui/index.ts
21
+ var ui_exports = {};
22
+ __export(ui_exports, {
23
+ Author: () => Author,
24
+ Composer: () => Composer,
25
+ Conversation: () => Conversation,
26
+ Message: () => Message,
27
+ Part: () => Part,
28
+ Session: () => Session,
29
+ SessionPeek: () => SessionPeek,
30
+ SessionStatus: () => SessionStatus,
31
+ ToolCall: () => ToolCall,
32
+ Turn: () => Turn,
33
+ UIProvider: () => UIProvider
34
+ });
35
+ module.exports = __toCommonJS(ui_exports);
36
+
37
+ // src/ui/context.tsx
38
+ var import_react = require("react");
39
+ var import_jsx_runtime = require("react/jsx-runtime");
40
+ var noTools = {};
41
+ function defaultResolver(participant) {
42
+ return (author) => ({
43
+ name: author.name ?? author.id,
44
+ role: "person",
45
+ self: participant !== void 0 && author.kind === "participant" && author.id === participant.id
46
+ });
47
+ }
48
+ var unknownAuthor = { name: "Unknown", role: "person", self: false };
49
+ function value(props) {
50
+ const resolve = props.resolveAuthor ?? defaultResolver(props.participant);
51
+ const agent = props.agent ?? { name: "Agent" };
52
+ return {
53
+ markdown: props.markdown,
54
+ tools: props.tools ?? noTools,
55
+ resolveAuthor: (author) => author ? resolve(author) : unknownAuthor,
56
+ agent: { ...agent, role: "agent", self: false }
57
+ };
58
+ }
59
+ var UI = (0, import_react.createContext)(value({}));
60
+ function UIProvider({ markdown, tools, resolveAuthor, participant, agent, children }) {
61
+ const participantId = participant?.id;
62
+ const agentName = agent?.name;
63
+ const agentAvatar = agent?.avatarUrl;
64
+ const v = (0, import_react.useMemo)(
65
+ () => value({
66
+ markdown,
67
+ tools,
68
+ resolveAuthor,
69
+ participant: participantId === void 0 ? void 0 : { id: participantId },
70
+ agent: agentName === void 0 ? void 0 : { name: agentName, ...agentAvatar ? { avatarUrl: agentAvatar } : {} }
71
+ }),
72
+ [markdown, tools, resolveAuthor, participantId, agentName, agentAvatar]
73
+ );
74
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(UI.Provider, { value: v, children });
75
+ }
76
+ var useUI = () => (0, import_react.useContext)(UI);
77
+ var SessionContext = (0, import_react.createContext)(null);
78
+ function useSessionContext(component) {
79
+ const v = (0, import_react.useContext)(SessionContext);
80
+ if (!v) throw new Error(`paddock: ${component} must be inside Session.Root`);
81
+ return v;
82
+ }
83
+
84
+ // src/ui/session.tsx
85
+ var import_react3 = require("@paddockai/react");
86
+
87
+ // src/ui/slot.tsx
88
+ var import_react2 = require("react");
89
+ function mergeRefs(...refs) {
90
+ return (node) => {
91
+ for (const r of refs) {
92
+ if (typeof r === "function") r(node);
93
+ else if (r && typeof r === "object") r.current = node;
94
+ }
95
+ };
96
+ }
97
+ function merge(slot, child) {
98
+ const out = { ...slot, ...child };
99
+ for (const key of Object.keys(slot)) {
100
+ const a = slot[key];
101
+ const b = child[key];
102
+ if (key === "className" && a && b) out[key] = `${String(a)} ${String(b)}`;
103
+ else if (key === "style" && a && b) out[key] = { ...a, ...b };
104
+ else if (key === "ref" && a && b) out[key] = mergeRefs(a, b);
105
+ else if (/^on[A-Z]/.test(key) && typeof a === "function" && typeof b === "function")
106
+ out[key] = (...args) => {
107
+ b(...args);
108
+ a(...args);
109
+ };
110
+ }
111
+ return out;
112
+ }
113
+ function render(tag, asChild, props, children, content) {
114
+ if (asChild && (0, import_react2.isValidElement)(children) && children.type !== import_react2.Fragment) {
115
+ const childProps = children.props;
116
+ const childRef = children.ref ?? childProps.ref;
117
+ const merged = merge(props, childRef ? { ...childProps, ref: childRef } : childProps);
118
+ if (childProps.children === void 0 && content !== void 0) merged.children = content;
119
+ return (0, import_react2.cloneElement)(children, merged);
120
+ }
121
+ return (0, import_react2.createElement)(tag, props, children ?? content);
122
+ }
123
+ function flag(on) {
124
+ return on ? "" : void 0;
125
+ }
126
+
127
+ // src/ui/session.tsx
128
+ var import_jsx_runtime2 = require("react/jsx-runtime");
129
+ function SessionRoot({ session, mode = null, asChild, children, ...rest }) {
130
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SessionContext.Provider, { value: { session, mode }, children: render(
131
+ "div",
132
+ asChild,
133
+ { "data-status": session.status, "data-connected": flag(session.connection === "open"), ...rest },
134
+ children
135
+ ) });
136
+ }
137
+ var Session = { Root: SessionRoot };
138
+ function SessionStatus({ children, asChild, ...rest }) {
139
+ const { session, mode } = useSessionContext("SessionStatus");
140
+ const info = (0, import_react3.useSessionStatus)(session, { mode });
141
+ const detail = {
142
+ ...info,
143
+ connection: session.connection,
144
+ connectionError: session.connectionError,
145
+ error: session.error,
146
+ retryAt: session.session?.retryAt ?? null
147
+ };
148
+ const text = info.connected ? info.status : `${info.status} \xB7 ${session.connection}`;
149
+ return render(
150
+ "div",
151
+ asChild,
152
+ { "data-status": info.status, "data-connected": flag(info.connected), ...rest },
153
+ children ? children(detail) : text
154
+ );
155
+ }
156
+ function runningTool(parts) {
157
+ for (let i = parts.length - 1; i >= 0; i--) {
158
+ const p = parts[i];
159
+ if (!p) continue;
160
+ const inner = runningTool(p.children.filter((c) => c.kind === "tool"));
161
+ if (inner) return inner;
162
+ if (p.status === "running") return p;
163
+ }
164
+ return null;
165
+ }
166
+ function Peek({
167
+ part,
168
+ latest,
169
+ ...props
170
+ }) {
171
+ const summary = (0, import_react3.useToolCall)(part ?? emptyTool);
172
+ const { session, children, asChild, ...rest } = props;
173
+ const status = (0, import_react3.useSessionStatus)(session);
174
+ const detail = {
175
+ status: status.status,
176
+ connected: status.connected,
177
+ activity: part ? summary.title : latest
178
+ };
179
+ return render(
180
+ "div",
181
+ asChild,
182
+ { "data-status": status.status, "data-connected": flag(status.connected), ...rest },
183
+ children ? children(detail) : detail.activity ? `${detail.status}: ${detail.activity}` : detail.status
184
+ );
185
+ }
186
+ var emptyTool = {
187
+ kind: "tool",
188
+ id: "",
189
+ callId: "",
190
+ call: null,
191
+ result: null,
192
+ status: "done",
193
+ children: []
194
+ };
195
+ function SessionPeek({ sessionId, token, baseUrl, ...rest }) {
196
+ const session = (0, import_react3.useSession)(sessionId, baseUrl === void 0 ? { token } : { token, baseUrl });
197
+ const items = (0, import_react3.useConversation)(session);
198
+ const turn = [...items].reverse().find((i) => i.kind === "turn");
199
+ const parts = turn?.kind === "turn" ? turn.parts : [];
200
+ const part = turn?.kind === "turn" && turn.status === "running" ? runningTool(parts.filter((p) => p.kind === "tool")) : null;
201
+ const text = [...parts].reverse().find((p) => p.kind === "text");
202
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Peek, { ...rest, session, part, latest: text?.kind === "text" ? text.text : null });
203
+ }
204
+
205
+ // src/ui/conversation.tsx
206
+ var import_react4 = require("react");
207
+ var import_client = require("@paddockai/client");
208
+ var import_react5 = require("@paddockai/react");
209
+ var import_jsx_runtime3 = require("react/jsx-runtime");
210
+ var noAction = () => Promise.reject(new Error("paddock: no session"));
211
+ var noSession = { ...import_client.initialState, send: noAction, stop: noAction };
212
+ var ConversationContext = (0, import_react4.createContext)({ items: [] });
213
+ var bottomSlack = 8;
214
+ function ConversationRoot({ items, notices, asChild, children, onScroll, ...rest }) {
215
+ const session = (0, import_react4.useContext)(SessionContext);
216
+ const own = (0, import_react5.useConversation)(session?.session ?? noSession, { notices: notices ?? [] });
217
+ const shown = items ?? own;
218
+ const ref = (0, import_react4.useRef)(null);
219
+ const [atBottom, setAtBottom] = (0, import_react4.useState)(true);
220
+ const stick = (0, import_react4.useRef)(true);
221
+ const handleScroll = (0, import_react4.useCallback)(
222
+ (e) => {
223
+ const el = e.currentTarget;
224
+ const bottom = el.scrollHeight - el.scrollTop - el.clientHeight <= bottomSlack;
225
+ stick.current = bottom;
226
+ setAtBottom(bottom);
227
+ onScroll?.(e);
228
+ },
229
+ [onScroll]
230
+ );
231
+ (0, import_react4.useLayoutEffect)(() => {
232
+ const el = ref.current;
233
+ if (el && stick.current) el.scrollTop = el.scrollHeight;
234
+ }, [shown]);
235
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConversationContext.Provider, { value: { items: shown }, children: render(
236
+ "div",
237
+ asChild,
238
+ {
239
+ role: "log",
240
+ "aria-live": "polite",
241
+ "data-at-bottom": flag(atBottom),
242
+ ...rest,
243
+ ref,
244
+ onScroll: handleScroll
245
+ },
246
+ children,
247
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConversationItems, {})
248
+ ) });
249
+ }
250
+ function keyOf(item, index) {
251
+ const id = typeof item === "object" && item !== null ? item.id : void 0;
252
+ return typeof id === "string" || typeof id === "number" ? id : index;
253
+ }
254
+ function ConversationItems({ children, asChild, ...rest }) {
255
+ const { items } = (0, import_react4.useContext)(ConversationContext);
256
+ const renderItem = children ?? ((item) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DefaultItem, { item }));
257
+ return render(
258
+ "div",
259
+ asChild,
260
+ rest,
261
+ items.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ItemSlot, { children: renderItem(item, i) }, keyOf(item, i)))
262
+ );
263
+ }
264
+ function ItemSlot({ children }) {
265
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children });
266
+ }
267
+ function ConversationEmpty({ asChild, children, ...rest }) {
268
+ const { items } = (0, import_react4.useContext)(ConversationContext);
269
+ if (items.length > 0) return null;
270
+ return render("div", asChild, rest, children);
271
+ }
272
+ var Conversation = { Root: ConversationRoot, Items: ConversationItems, Empty: ConversationEmpty };
273
+ function DefaultItem({ item }) {
274
+ const ui = useUI();
275
+ switch (item.kind) {
276
+ case "user": {
277
+ const author = ui.resolveAuthor(item.author);
278
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(MessageRoot, { role: author.role, author, delivery: item.delivery, children: [
279
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Author, {}),
280
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MessageContent, { children: item.text })
281
+ ] });
282
+ }
283
+ case "turn":
284
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(TurnRoot, { turn: item, children: [
285
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Author, { author: ui.agent }),
286
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TurnParts, {}),
287
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TurnStatus, {})
288
+ ] });
289
+ case "notice":
290
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MessageRoot, { role: "system", "data-notice": item.event.type, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MessageContent, { children: item.event.type }) });
291
+ default:
292
+ return null;
293
+ }
294
+ }
295
+ var MessageContext = (0, import_react4.createContext)(null);
296
+ function MessageRoot({ role, author = null, delivery, asChild, children, ...rest }) {
297
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MessageContext.Provider, { value: { role, author }, children: render(
298
+ "div",
299
+ asChild,
300
+ { "data-role": role, "data-self": flag(author?.self ?? false), "data-delivery": delivery, ...rest },
301
+ children
302
+ ) });
303
+ }
304
+ function MessageContent({ asChild, children, ...rest }) {
305
+ return render("div", asChild, rest, children);
306
+ }
307
+ var Message = { Root: MessageRoot, Content: MessageContent };
308
+ function Author({ author, asChild, children, ...rest }) {
309
+ const message = (0, import_react4.useContext)(MessageContext);
310
+ const shown = author ?? message?.author ?? null;
311
+ if (!shown && children === void 0) return null;
312
+ return render(
313
+ "span",
314
+ asChild,
315
+ { "data-role": shown?.role, "data-self": flag(shown?.self ?? false), ...rest },
316
+ children,
317
+ shown?.name
318
+ );
319
+ }
320
+ var TurnContext = (0, import_react4.createContext)(null);
321
+ function useTurn(component) {
322
+ const t = (0, import_react4.useContext)(TurnContext);
323
+ if (!t) throw new Error(`paddock: ${component} must be inside Turn.Root`);
324
+ return t;
325
+ }
326
+ function TurnRoot({ turn, asChild, children, ...rest }) {
327
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(TurnContext.Provider, { value: turn, children: render("div", asChild, { "data-status": turn.status, "data-origin": turn.origin, ...rest }, children) });
328
+ }
329
+ function TurnParts({ children, asChild, ...rest }) {
330
+ const turn = useTurn("Turn.Parts");
331
+ const renderPart = children ?? ((p) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Part, { part: p }));
332
+ return render(
333
+ "div",
334
+ asChild,
335
+ rest,
336
+ turn.parts.map((p) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ItemSlot, { children: renderPart(p) }, p.id))
337
+ );
338
+ }
339
+ function turnEnd(turn) {
340
+ switch (turn.status) {
341
+ case "running":
342
+ case "completed":
343
+ return null;
344
+ case "stopped":
345
+ return "Stopped";
346
+ case "discarded":
347
+ return "Discarded";
348
+ case "failed": {
349
+ const what = turn.error ? `Failed: ${turn.error.message}` : "Failed";
350
+ if (turn.retryAt) return `${what}. Retrying at ${turn.retryAt}`;
351
+ if (turn.gaveUp) return `${what}. Gave up`;
352
+ return what;
353
+ }
354
+ default:
355
+ return turn.status;
356
+ }
357
+ }
358
+ function TurnStatus({ children, asChild, ...rest }) {
359
+ const turn = useTurn("Turn.Status");
360
+ const content = children ? children(turn) : turnEnd(turn);
361
+ if (content === null || content === void 0) return null;
362
+ return render(
363
+ "div",
364
+ asChild,
365
+ {
366
+ "data-status": turn.status,
367
+ "data-gave-up": flag(turn.gaveUp),
368
+ "data-retry-at": turn.retryAt ?? void 0,
369
+ ...rest
370
+ },
371
+ content
372
+ );
373
+ }
374
+ var Turn = { Root: TurnRoot, Parts: TurnParts, Status: TurnStatus };
375
+ function lookupTool(tools, part, summary) {
376
+ const keys = [];
377
+ if (summary.mcp) keys.push(`mcp:${summary.mcp.server}/${summary.mcp.tool}`, `mcp:${summary.mcp.server}`);
378
+ if (part.call) keys.push(`raw:${part.call.rawName}`);
379
+ keys.push(summary.kind);
380
+ for (const k of keys) if (Object.hasOwn(tools, k)) return tools[k];
381
+ return void 0;
382
+ }
383
+ function ToolPartView({ part }) {
384
+ const summary = (0, import_react5.useToolCall)(part);
385
+ const { tools } = useUI();
386
+ const Card = lookupTool(tools, part, summary);
387
+ return Card ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Card, { part, summary }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolCallRoot, { part });
388
+ }
389
+ function Part({ part, asChild, children, ...rest }) {
390
+ const { markdown: Markdown } = useUI();
391
+ const attrs = { "data-kind": part.kind, ...rest };
392
+ switch (part.kind) {
393
+ case "text":
394
+ return render(
395
+ "div",
396
+ asChild,
397
+ { ...attrs, "data-streaming": flag(part.streaming) },
398
+ children,
399
+ Markdown ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Markdown, { children: part.text }) : part.text
400
+ );
401
+ case "reasoning":
402
+ return render(
403
+ "details",
404
+ asChild,
405
+ attrs,
406
+ children,
407
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
408
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("summary", { children: "Reasoning" }),
409
+ part.text
410
+ ] })
411
+ );
412
+ case "tool":
413
+ return render("div", asChild, attrs, children, /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolPartView, { part }));
414
+ default:
415
+ return render(
416
+ "details",
417
+ asChild,
418
+ { ...attrs, "data-harness": part.harness ?? void 0, "data-type": part.type },
419
+ children,
420
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
421
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("summary", { children: `${part.harness ?? "unknown"} \xB7 ${part.type}` }),
422
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { children: JSON.stringify(part.raw, null, 2) })
423
+ ] })
424
+ );
425
+ }
426
+ }
427
+ var ToolContext = (0, import_react4.createContext)(null);
428
+ function useTool(component) {
429
+ const t = (0, import_react4.useContext)(ToolContext);
430
+ if (!t) throw new Error(`paddock: ${component} must be inside ToolCall.Root`);
431
+ return t;
432
+ }
433
+ function ToolCallRoot({ part, asChild, children, ...rest }) {
434
+ const summary = (0, import_react5.useToolCall)(part);
435
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolContext.Provider, { value: { part, summary }, children: render(
436
+ "div",
437
+ asChild,
438
+ { "data-tool": summary.kind, "data-status": summary.status, ...rest },
439
+ children,
440
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
441
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolCallTitle, {}),
442
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolCallDetail, {}),
443
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ToolCallChildren, {})
444
+ ] })
445
+ ) });
446
+ }
447
+ function ToolCallTitle({ asChild, children, ...rest }) {
448
+ const { summary } = useTool("ToolCall.Title");
449
+ return render("span", asChild, rest, children, summary.title);
450
+ }
451
+ function detailOf(s) {
452
+ if (s.shell) {
453
+ const lines = [`$ ${s.shell.command}`];
454
+ if (s.shell.output) lines.push(s.shell.output);
455
+ if (s.shell.exitCode !== null) lines.push(`exit ${s.shell.exitCode}`);
456
+ return lines.join("\n");
457
+ }
458
+ if (s.diff)
459
+ return s.diff.map(
460
+ (d) => d.unified ?? [d.before === null ? null : `- ${d.before}`, d.after === null ? null : `+ ${d.after}`].filter((l) => l !== null).join("\n")
461
+ ).join("\n");
462
+ if (s.mcp) {
463
+ const content = s.mcp.content?.map(
464
+ (c) => typeof c === "object" && c !== null && c.type === "text" ? String(c.text) : JSON.stringify(c)
465
+ ).join("\n");
466
+ return [JSON.stringify(s.mcp.arguments, null, 2), content].filter((x) => x).join("\n");
467
+ }
468
+ if ("text" in s) return s.text ?? null;
469
+ return JSON.stringify({ input: s.call?.input ?? null, output: s.result?.output ?? null }, null, 2);
470
+ }
471
+ function ToolCallDetail({ asChild, children, ...rest }) {
472
+ const { summary } = useTool("ToolCall.Detail");
473
+ if (children) return render("div", asChild, rest, children(summary));
474
+ const text = detailOf(summary);
475
+ if (text === null || text === "") return null;
476
+ return render("pre", asChild, rest, text);
477
+ }
478
+ function ToolCallChildren({ asChild, children, ...rest }) {
479
+ const { part } = useTool("ToolCall.Children");
480
+ if (part.children.length === 0 && children === void 0) return null;
481
+ return render(
482
+ "div",
483
+ asChild,
484
+ rest,
485
+ children,
486
+ part.children.map((p) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Part, { part: p }, p.id))
487
+ );
488
+ }
489
+ var ToolCall = {
490
+ Root: ToolCallRoot,
491
+ Title: ToolCallTitle,
492
+ Detail: ToolCallDetail,
493
+ Children: ToolCallChildren
494
+ };
495
+
496
+ // src/ui/composer.tsx
497
+ var import_react6 = require("react");
498
+ var import_react7 = require("@paddockai/react");
499
+ var import_jsx_runtime4 = require("react/jsx-runtime");
500
+ var ComposerContext = (0, import_react6.createContext)(null);
501
+ function useComposerContext(component) {
502
+ const v = (0, import_react6.useContext)(ComposerContext);
503
+ if (!v) throw new Error(`paddock: ${component} must be inside Composer.Root`);
504
+ return v;
505
+ }
506
+ function ComposerRoot({ onError, asChild, children, ...rest }) {
507
+ const { session, mode } = useSessionContext("Composer.Root");
508
+ const composer = (0, import_react7.useComposer)(session, onError ? { mode, onError } : { mode });
509
+ const status = (0, import_react7.useSessionStatus)(session, { mode });
510
+ const disabled = !status.canSend;
511
+ const onSubmit = (e) => {
512
+ e.preventDefault();
513
+ void composer.submit();
514
+ };
515
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ComposerContext.Provider, { value: { ...composer, disabled }, children: render(
516
+ "form",
517
+ asChild,
518
+ { "data-pending": flag(composer.pending), "data-disabled": flag(disabled), ...rest, onSubmit },
519
+ children,
520
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
521
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ComposerInput, {}),
522
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ComposerSend, {}),
523
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ComposerStop, {})
524
+ ] })
525
+ ) });
526
+ }
527
+ function ComposerInput({ asChild, children, onKeyDown, ...rest }) {
528
+ const c = useComposerContext("Composer.Input");
529
+ return render(
530
+ "textarea",
531
+ asChild,
532
+ {
533
+ ...rest,
534
+ ...c.inputProps,
535
+ onKeyDown: (e) => {
536
+ onKeyDown?.(e);
537
+ c.inputProps.onKeyDown(e);
538
+ },
539
+ disabled: c.disabled || rest.disabled
540
+ },
541
+ children
542
+ );
543
+ }
544
+ function ComposerSend({ asChild, children, ...rest }) {
545
+ const c = useComposerContext("Composer.Send");
546
+ return render(
547
+ "button",
548
+ asChild,
549
+ { type: "submit", ...rest, disabled: !c.canSend || rest.disabled },
550
+ children,
551
+ "Send"
552
+ );
553
+ }
554
+ function ComposerStop({ asChild, children, onClick, ...rest }) {
555
+ const c = useComposerContext("Composer.Stop");
556
+ return render(
557
+ "button",
558
+ asChild,
559
+ {
560
+ type: "button",
561
+ ...rest,
562
+ disabled: !c.canStop || rest.disabled,
563
+ onClick: (e) => {
564
+ onClick?.(e);
565
+ void c.stop();
566
+ }
567
+ },
568
+ children,
569
+ "Stop"
570
+ );
571
+ }
572
+ var Composer = { Root: ComposerRoot, Input: ComposerInput, Send: ComposerSend, Stop: ComposerStop };
573
+ // Annotate the CommonJS export names for ESM import in node:
574
+ 0 && (module.exports = {
575
+ Author,
576
+ Composer,
577
+ Conversation,
578
+ Message,
579
+ Part,
580
+ Session,
581
+ SessionPeek,
582
+ SessionStatus,
583
+ ToolCall,
584
+ Turn,
585
+ UIProvider
586
+ });