@amodalai/react 0.1.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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/dist/chat.d.ts +19 -0
  3. package/dist/chat.d.ts.map +1 -0
  4. package/dist/client/index.d.ts +10 -0
  5. package/dist/client/index.d.ts.map +1 -0
  6. package/dist/client/runtime-client.d.ts +58 -0
  7. package/dist/client/runtime-client.d.ts.map +1 -0
  8. package/dist/client/sse-client.d.ts +20 -0
  9. package/dist/client/sse-client.d.ts.map +1 -0
  10. package/dist/client.js +181 -0
  11. package/dist/client.js.map +1 -0
  12. package/dist/components/AmodalAction.d.ts +22 -0
  13. package/dist/components/AmodalAction.d.ts.map +1 -0
  14. package/dist/components/ConfirmCard.d.ts +11 -0
  15. package/dist/components/ConfirmCard.d.ts.map +1 -0
  16. package/dist/components/ReviewCard.d.ts +11 -0
  17. package/dist/components/ReviewCard.d.ts.map +1 -0
  18. package/dist/hooks/useAmodalBrief.d.ts +20 -0
  19. package/dist/hooks/useAmodalBrief.d.ts.map +1 -0
  20. package/dist/hooks/useAmodalChat.d.ts +27 -0
  21. package/dist/hooks/useAmodalChat.d.ts.map +1 -0
  22. package/dist/hooks/useAmodalInsight.d.ts +23 -0
  23. package/dist/hooks/useAmodalInsight.d.ts.map +1 -0
  24. package/dist/hooks/useAmodalQuery.d.ts +17 -0
  25. package/dist/hooks/useAmodalQuery.d.ts.map +1 -0
  26. package/dist/hooks/useAmodalTask.d.ts +21 -0
  27. package/dist/hooks/useAmodalTask.d.ts.map +1 -0
  28. package/dist/hooks/useNavigate.d.ts +32 -0
  29. package/dist/hooks/useNavigate.d.ts.map +1 -0
  30. package/dist/hooks/useSkillAction.d.ts +40 -0
  31. package/dist/hooks/useSkillAction.d.ts.map +1 -0
  32. package/dist/hooks/useStore.d.ts +36 -0
  33. package/dist/hooks/useStore.d.ts.map +1 -0
  34. package/dist/hooks/useStoreList.d.ts +41 -0
  35. package/dist/hooks/useStoreList.d.ts.map +1 -0
  36. package/dist/index.d.ts +39 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/provider.d.ts +27 -0
  39. package/dist/provider.d.ts.map +1 -0
  40. package/dist/react.js +855 -0
  41. package/dist/react.js.map +1 -0
  42. package/dist/types.d.ts +339 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/package.json +62 -0
package/dist/react.js ADDED
@@ -0,0 +1,855 @@
1
+ import { jsx as v, jsxs as w } from "react/jsx-runtime";
2
+ import { createContext as P, useMemo as B, useContext as j, useReducer as H, useRef as T, useCallback as N, useEffect as I, useState as y } from "react";
3
+ import { RuntimeClient as V } from "./client.js";
4
+ import { parseSSELine as me, streamSSE as fe, streamSSEGet as pe } from "./client.js";
5
+ const U = P(null);
6
+ function Z({ runtimeUrl: r, tenantId: s, getToken: t, children: e }) {
7
+ const a = B(
8
+ () => new V({ runtimeUrl: r, tenantId: s, getToken: t }),
9
+ [r, s, t]
10
+ ), n = B(
11
+ () => ({ client: a, runtimeUrl: r, tenantId: s }),
12
+ [a, r, s]
13
+ );
14
+ return /* @__PURE__ */ v(U.Provider, { value: n, children: e });
15
+ }
16
+ function C() {
17
+ const r = j(U);
18
+ if (!r)
19
+ throw new Error("useAmodalContext must be used within an <AmodalProvider>");
20
+ return r;
21
+ }
22
+ /**
23
+ * @license
24
+ * Copyright 2025 Amodal Labs, Inc.
25
+ * SPDX-License-Identifier: MIT
26
+ */
27
+ const G = {
28
+ messages: [],
29
+ sessionId: null,
30
+ isStreaming: !1,
31
+ error: null,
32
+ activeToolCalls: []
33
+ };
34
+ let $ = 0;
35
+ function F() {
36
+ return $++, `msg-${Date.now()}-${String($)}`;
37
+ }
38
+ function X(r, s) {
39
+ switch (s.type) {
40
+ case "SEND_MESSAGE": {
41
+ const t = {
42
+ type: "user",
43
+ id: F(),
44
+ text: s.text,
45
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
46
+ }, e = {
47
+ type: "assistant_text",
48
+ id: F(),
49
+ text: "",
50
+ toolCalls: [],
51
+ confirmations: [],
52
+ contentBlocks: [],
53
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
54
+ };
55
+ return {
56
+ ...r,
57
+ messages: [...r.messages, t, e],
58
+ isStreaming: !0,
59
+ error: null,
60
+ activeToolCalls: []
61
+ };
62
+ }
63
+ case "STREAM_INIT":
64
+ return { ...r, sessionId: s.sessionId };
65
+ case "STREAM_TEXT_DELTA": {
66
+ const t = [...r.messages], e = t[t.length - 1];
67
+ if (e && e.type === "assistant_text") {
68
+ const a = [...e.contentBlocks], n = a[a.length - 1];
69
+ n && n.type === "text" ? a[a.length - 1] = { type: "text", text: n.text + s.content } : a.push({ type: "text", text: s.content }), t[t.length - 1] = { ...e, text: e.text + s.content, contentBlocks: a };
70
+ }
71
+ return { ...r, messages: t };
72
+ }
73
+ case "STREAM_TOOL_CALL_START": {
74
+ const t = [...r.messages], e = t[t.length - 1], a = {
75
+ toolId: s.toolId,
76
+ toolName: s.toolName,
77
+ parameters: s.parameters,
78
+ status: "running"
79
+ };
80
+ if (e && e.type === "assistant_text") {
81
+ const n = [...e.toolCalls, a], c = [...e.contentBlocks], i = c[c.length - 1];
82
+ i && i.type === "tool_calls" ? c[c.length - 1] = { type: "tool_calls", calls: [...i.calls, a] } : c.push({ type: "tool_calls", calls: [a] }), t[t.length - 1] = { ...e, toolCalls: n, contentBlocks: c };
83
+ }
84
+ return {
85
+ ...r,
86
+ messages: t,
87
+ activeToolCalls: [...r.activeToolCalls, a]
88
+ };
89
+ }
90
+ case "STREAM_TOOL_CALL_RESULT": {
91
+ const t = [...r.messages], e = t[t.length - 1];
92
+ if (e && e.type === "assistant_text") {
93
+ const n = (p) => p.toolId === s.toolId ? {
94
+ ...p,
95
+ status: s.status,
96
+ result: s.result,
97
+ duration_ms: s.duration_ms,
98
+ error: s.error
99
+ } : p, c = e.toolCalls.map(n), i = e.contentBlocks.map(
100
+ (p) => p.type === "tool_calls" ? { ...p, calls: p.calls.map(n) } : p
101
+ );
102
+ t[t.length - 1] = { ...e, toolCalls: c, contentBlocks: i };
103
+ }
104
+ const a = r.activeToolCalls.filter(
105
+ (n) => n.toolId !== s.toolId
106
+ );
107
+ return { ...r, messages: t, activeToolCalls: a };
108
+ }
109
+ case "STREAM_SUBAGENT_EVENT": {
110
+ const t = [...r.messages], e = t[t.length - 1];
111
+ if (e && e.type === "assistant_text") {
112
+ const a = (i) => i.toolId === s.parentToolId ? { ...i, subagentEvents: [...i.subagentEvents ?? [], s.event] } : i, n = e.toolCalls.map(a), c = e.contentBlocks.map(
113
+ (i) => i.type === "tool_calls" ? { ...i, calls: i.calls.map(a) } : i
114
+ );
115
+ t[t.length - 1] = { ...e, toolCalls: n, contentBlocks: c };
116
+ }
117
+ return { ...r, messages: t };
118
+ }
119
+ case "STREAM_WIDGET": {
120
+ const t = [...r.messages], e = t[t.length - 1];
121
+ if (e && e.type === "assistant_text") {
122
+ const a = {
123
+ type: "widget",
124
+ widgetType: s.widgetType,
125
+ data: s.data
126
+ };
127
+ t[t.length - 1] = {
128
+ ...e,
129
+ contentBlocks: [...e.contentBlocks, a]
130
+ };
131
+ }
132
+ return { ...r, messages: t };
133
+ }
134
+ case "STREAM_CONFIRMATION_REQUIRED": {
135
+ const t = [...r.messages], e = t[t.length - 1];
136
+ if (e && e.type === "assistant_text") {
137
+ const a = {
138
+ type: "confirmation",
139
+ confirmation: s.confirmation
140
+ };
141
+ t[t.length - 1] = {
142
+ ...e,
143
+ confirmations: [...e.confirmations, s.confirmation],
144
+ contentBlocks: [...e.contentBlocks, a]
145
+ };
146
+ }
147
+ return { ...r, messages: t };
148
+ }
149
+ case "CONFIRMATION_RESPONDED": {
150
+ const t = [...r.messages], e = t[t.length - 1];
151
+ if (e && e.type === "assistant_text") {
152
+ const a = e.confirmations.map(
153
+ (c) => c.correlationId === s.correlationId ? { ...c, status: s.approved ? "approved" : "denied" } : c
154
+ ), n = e.contentBlocks.map(
155
+ (c) => c.type === "confirmation" && c.confirmation.correlationId === s.correlationId ? { ...c, confirmation: { ...c.confirmation, status: s.approved ? "approved" : "denied" } } : c
156
+ );
157
+ t[t.length - 1] = { ...e, confirmations: a, contentBlocks: n };
158
+ }
159
+ return { ...r, messages: t };
160
+ }
161
+ case "STREAM_ERROR":
162
+ return { ...r, isStreaming: !1, error: s.message, activeToolCalls: [] };
163
+ case "STREAM_DONE": {
164
+ const t = [...r.messages], e = t[t.length - 1];
165
+ if (e && e.type === "assistant_text") {
166
+ const a = (i) => i.status === "running" ? { ...i, status: "error", error: "Stopped" } : i, n = e.toolCalls.map(a), c = e.contentBlocks.map(
167
+ (i) => i.type === "tool_calls" ? { ...i, calls: i.calls.map(a) } : i
168
+ );
169
+ t[t.length - 1] = { ...e, toolCalls: n, contentBlocks: c };
170
+ }
171
+ return { ...r, messages: t, isStreaming: !1, activeToolCalls: [] };
172
+ }
173
+ case "RESET":
174
+ return { ...G };
175
+ default:
176
+ return r;
177
+ }
178
+ }
179
+ function J(r) {
180
+ const { client: s } = C(), [t, e] = H(X, G), a = T(null), n = T(null), c = T(r);
181
+ c.current = r, a.current = t.sessionId;
182
+ const i = N(
183
+ (g) => {
184
+ if (t.isStreaming) return;
185
+ e({ type: "SEND_MESSAGE", text: g });
186
+ const _ = new AbortController();
187
+ n.current = _, (async () => {
188
+ var o, d, f, l, b, A, x, R, M, D, O;
189
+ let m = !1;
190
+ try {
191
+ const k = s.chatStream(g, {
192
+ sessionId: a.current ?? void 0,
193
+ context: (o = c.current) == null ? void 0 : o.context,
194
+ signal: _.signal
195
+ });
196
+ for await (const h of k)
197
+ switch (h.type) {
198
+ case "init":
199
+ e({ type: "STREAM_INIT", sessionId: h.session_id }), (f = (d = c.current) == null ? void 0 : d.onSessionCreated) == null || f.call(d, h.session_id);
200
+ break;
201
+ case "text_delta":
202
+ e({ type: "STREAM_TEXT_DELTA", content: h.content });
203
+ break;
204
+ case "tool_call_start":
205
+ e({
206
+ type: "STREAM_TOOL_CALL_START",
207
+ toolId: h.tool_id,
208
+ toolName: h.tool_name,
209
+ parameters: h.parameters
210
+ });
211
+ break;
212
+ case "tool_call_result":
213
+ e({
214
+ type: "STREAM_TOOL_CALL_RESULT",
215
+ toolId: h.tool_id,
216
+ status: h.status,
217
+ result: h.result,
218
+ duration_ms: h.duration_ms,
219
+ error: h.error
220
+ }), (b = (l = c.current) == null ? void 0 : l.onToolCall) == null || b.call(l, {
221
+ toolId: h.tool_id,
222
+ toolName: "",
223
+ parameters: {},
224
+ status: h.status,
225
+ result: h.result,
226
+ duration_ms: h.duration_ms,
227
+ error: h.error
228
+ });
229
+ break;
230
+ case "subagent_event":
231
+ e({
232
+ type: "STREAM_SUBAGENT_EVENT",
233
+ parentToolId: h.parent_tool_id,
234
+ event: {
235
+ agentName: h.agent_name,
236
+ eventType: h.event_type,
237
+ toolName: h.tool_name,
238
+ toolArgs: h.tool_args,
239
+ result: h.result,
240
+ text: h.text,
241
+ error: h.error,
242
+ timestamp: h.timestamp
243
+ }
244
+ });
245
+ break;
246
+ case "widget":
247
+ e({
248
+ type: "STREAM_WIDGET",
249
+ widgetType: h.widget_type,
250
+ data: h.data
251
+ });
252
+ break;
253
+ case "confirmation_required": {
254
+ const L = {
255
+ endpoint: h.endpoint,
256
+ method: h.method,
257
+ reason: h.reason,
258
+ escalated: h.escalated,
259
+ params: h.params,
260
+ connectionName: h.connection_name,
261
+ correlationId: h.correlation_id,
262
+ status: "pending"
263
+ };
264
+ e({ type: "STREAM_CONFIRMATION_REQUIRED", confirmation: L }), (x = (A = c.current) == null ? void 0 : A.onConfirmation) == null || x.call(A, L);
265
+ break;
266
+ }
267
+ case "error":
268
+ e({ type: "STREAM_ERROR", message: h.message });
269
+ break;
270
+ case "done":
271
+ m = !0, e({ type: "STREAM_DONE" }), (M = (R = c.current) == null ? void 0 : R.onStreamEnd) == null || M.call(R);
272
+ break;
273
+ default:
274
+ break;
275
+ }
276
+ } catch (k) {
277
+ k instanceof DOMException && k.name === "AbortError" || e({
278
+ type: "STREAM_ERROR",
279
+ message: k instanceof Error ? k.message : "Unknown error"
280
+ });
281
+ } finally {
282
+ n.current = null, !m && !_.signal.aborted && (e({ type: "STREAM_DONE" }), (O = (D = c.current) == null ? void 0 : D.onStreamEnd) == null || O.call(D));
283
+ }
284
+ })();
285
+ },
286
+ [s, t.isStreaming]
287
+ ), p = N(() => {
288
+ n.current && (n.current.abort(), n.current = null), e({ type: "STREAM_DONE" });
289
+ }, []), S = N(() => {
290
+ n.current && (n.current.abort(), n.current = null), e({ type: "RESET" });
291
+ }, []), E = N(
292
+ (g, _) => {
293
+ e({ type: "CONFIRMATION_RESPONDED", correlationId: g, approved: _ });
294
+ const u = _ ? `I approve the action (correlation: ${g})` : `I deny the action (correlation: ${g})`;
295
+ t.isStreaming || i(u);
296
+ },
297
+ [i, t.isStreaming]
298
+ );
299
+ return I(
300
+ () => () => {
301
+ n.current && n.current.abort();
302
+ },
303
+ []
304
+ ), {
305
+ messages: t.messages,
306
+ send: i,
307
+ stop: p,
308
+ isStreaming: t.isStreaming,
309
+ activeToolCalls: t.activeToolCalls,
310
+ sessionId: t.sessionId,
311
+ error: t.error,
312
+ reset: S,
313
+ respondToConfirmation: E
314
+ };
315
+ }
316
+ /**
317
+ * @license
318
+ * Copyright 2025 Amodal Labs, Inc.
319
+ * SPDX-License-Identifier: MIT
320
+ */
321
+ function Q({ confirmation: r, onApprove: s, onDeny: t }) {
322
+ const e = r.status === "pending";
323
+ return /* @__PURE__ */ w("div", { className: "amodal-confirm-card", "data-testid": "confirm-card", children: [
324
+ /* @__PURE__ */ w("div", { className: "amodal-confirm-card__header", children: [
325
+ /* @__PURE__ */ v("span", { className: "amodal-confirm-card__method", children: r.method }),
326
+ /* @__PURE__ */ v("span", { className: "amodal-confirm-card__endpoint", children: r.endpoint })
327
+ ] }),
328
+ /* @__PURE__ */ v("p", { className: "amodal-confirm-card__reason", children: r.reason }),
329
+ e ? /* @__PURE__ */ w("div", { className: "amodal-confirm-card__actions", children: [
330
+ /* @__PURE__ */ v(
331
+ "button",
332
+ {
333
+ className: "amodal-confirm-card__btn amodal-confirm-card__btn--approve",
334
+ onClick: s,
335
+ "data-testid": "confirm-approve",
336
+ children: "Approve"
337
+ }
338
+ ),
339
+ /* @__PURE__ */ v(
340
+ "button",
341
+ {
342
+ className: "amodal-confirm-card__btn amodal-confirm-card__btn--deny",
343
+ onClick: t,
344
+ "data-testid": "confirm-deny",
345
+ children: "Deny"
346
+ }
347
+ )
348
+ ] }) : /* @__PURE__ */ v("div", { className: "amodal-confirm-card__status", "data-testid": "confirm-status", children: r.status === "approved" ? "Approved" : "Denied" })
349
+ ] });
350
+ }
351
+ /**
352
+ * @license
353
+ * Copyright 2025 Amodal Labs, Inc.
354
+ * SPDX-License-Identifier: MIT
355
+ */
356
+ function W({ confirmation: r, onApprove: s, onDeny: t }) {
357
+ const e = r.status === "pending";
358
+ return /* @__PURE__ */ w("div", { className: "amodal-review-card", "data-testid": "review-card", children: [
359
+ /* @__PURE__ */ w("div", { className: "amodal-review-card__header", children: [
360
+ /* @__PURE__ */ v("span", { className: "amodal-review-card__method", children: r.method }),
361
+ /* @__PURE__ */ v("span", { className: "amodal-review-card__endpoint", children: r.endpoint }),
362
+ r.escalated && /* @__PURE__ */ v("span", { className: "amodal-review-card__badge", "data-testid": "escalation-badge", children: "Escalated" })
363
+ ] }),
364
+ r.connectionName && /* @__PURE__ */ w("div", { className: "amodal-review-card__connection", children: [
365
+ "Connection: ",
366
+ r.connectionName
367
+ ] }),
368
+ /* @__PURE__ */ v("p", { className: "amodal-review-card__reason", children: r.reason }),
369
+ r.params && Object.keys(r.params).length > 0 && /* @__PURE__ */ w("div", { className: "amodal-review-card__params", "data-testid": "review-params", children: [
370
+ /* @__PURE__ */ v("div", { className: "amodal-review-card__params-title", children: "Parameters" }),
371
+ /* @__PURE__ */ v("pre", { className: "amodal-review-card__params-body", children: JSON.stringify(r.params, null, 2) })
372
+ ] }),
373
+ e ? /* @__PURE__ */ w("div", { className: "amodal-review-card__actions", children: [
374
+ /* @__PURE__ */ v(
375
+ "button",
376
+ {
377
+ className: "amodal-review-card__btn amodal-review-card__btn--approve",
378
+ onClick: s,
379
+ "data-testid": "review-approve",
380
+ children: "Approve"
381
+ }
382
+ ),
383
+ /* @__PURE__ */ v(
384
+ "button",
385
+ {
386
+ className: "amodal-review-card__btn amodal-review-card__btn--deny",
387
+ onClick: t,
388
+ "data-testid": "review-deny",
389
+ children: "Deny"
390
+ }
391
+ )
392
+ ] }) : /* @__PURE__ */ v("div", { className: "amodal-review-card__status", "data-testid": "review-status", children: r.status === "approved" ? "Approved" : "Denied" })
393
+ ] });
394
+ }
395
+ function ee({
396
+ placeholder: r = "Type a message...",
397
+ renderText: s,
398
+ renderToolCall: t,
399
+ renderConfirmation: e,
400
+ className: a,
401
+ ...n
402
+ }) {
403
+ const { messages: c, send: i, isStreaming: p, respondToConfirmation: S } = J(n), [E, g] = y(""), _ = T(null), u = N(
404
+ (o) => {
405
+ o.preventDefault();
406
+ const d = E.trim();
407
+ d.length === 0 || p || (g(""), i(d));
408
+ },
409
+ [E, p, i]
410
+ ), m = ["amodal-chat", a].filter(Boolean).join(" ");
411
+ return /* @__PURE__ */ w("div", { className: m, "data-testid": "amodal-chat", children: [
412
+ /* @__PURE__ */ w("div", { className: "amodal-chat__messages", "data-testid": "message-list", children: [
413
+ c.map((o) => {
414
+ switch (o.type) {
415
+ case "user":
416
+ return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--user", "data-testid": "user-message", children: o.text }, o.id);
417
+ case "assistant_text":
418
+ return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--assistant", "data-testid": "assistant-message", children: o.contentBlocks.map((d, f) => {
419
+ switch (d.type) {
420
+ case "text":
421
+ return /* @__PURE__ */ v("div", { className: "amodal-chat__text", children: s ? s(d.text) : d.text }, `text-${String(f)}`);
422
+ case "tool_calls":
423
+ return /* @__PURE__ */ v("div", { className: "amodal-chat__tool-calls", children: d.calls.map(
424
+ (l) => t ? /* @__PURE__ */ v("div", { children: t(l) }, l.toolId) : /* @__PURE__ */ w("div", { className: "amodal-chat__tool-call", "data-testid": "tool-call", children: [
425
+ /* @__PURE__ */ v("span", { className: "amodal-chat__tool-name", children: l.toolName }),
426
+ /* @__PURE__ */ v("span", { className: "amodal-chat__tool-status", children: l.status })
427
+ ] }, l.toolId)
428
+ ) }, `tools-${String(f)}`);
429
+ case "confirmation": {
430
+ const l = d.confirmation, b = () => {
431
+ l.correlationId && S(l.correlationId, !0);
432
+ }, A = () => {
433
+ l.correlationId && S(l.correlationId, !1);
434
+ };
435
+ return e ? /* @__PURE__ */ v("div", { children: e(l, b, A) }, `conf-${String(f)}`) : l.escalated || l.params && Object.keys(l.params).length > 0 ? /* @__PURE__ */ v(W, { confirmation: l, onApprove: b, onDeny: A }, `conf-${String(f)}`) : /* @__PURE__ */ v(Q, { confirmation: l, onApprove: b, onDeny: A }, `conf-${String(f)}`);
436
+ }
437
+ case "widget":
438
+ return /* @__PURE__ */ v("div", { className: "amodal-chat__widget", "data-testid": "widget", children: d.widgetType }, `widget-${String(f)}`);
439
+ default:
440
+ return null;
441
+ }
442
+ }) }, o.id);
443
+ case "error":
444
+ return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--error", "data-testid": "error-message", children: o.message }, o.id);
445
+ default:
446
+ return null;
447
+ }
448
+ }),
449
+ /* @__PURE__ */ v("div", { ref: _ })
450
+ ] }),
451
+ /* @__PURE__ */ w("form", { className: "amodal-chat__input-bar", onSubmit: u, "data-testid": "input-bar", children: [
452
+ /* @__PURE__ */ v(
453
+ "input",
454
+ {
455
+ className: "amodal-chat__input",
456
+ value: E,
457
+ onChange: (o) => g(o.target.value),
458
+ placeholder: r,
459
+ disabled: p,
460
+ "data-testid": "chat-input"
461
+ }
462
+ ),
463
+ /* @__PURE__ */ v(
464
+ "button",
465
+ {
466
+ className: "amodal-chat__send",
467
+ type: "submit",
468
+ disabled: p || E.trim().length === 0,
469
+ "data-testid": "send-button",
470
+ children: "Send"
471
+ }
472
+ )
473
+ ] })
474
+ ] });
475
+ }
476
+ function te({ prompt: r, label: s, context: t, onComplete: e, onError: a }) {
477
+ const [n, c] = y(!1), { messages: i, send: p, isStreaming: S, respondToConfirmation: E } = J({
478
+ context: t,
479
+ onStreamEnd: () => {
480
+ const o = i[i.length - 1];
481
+ o && o.type === "assistant_text" ? e == null || e(o.text) : o && o.type === "error" && (a == null || a(o.message));
482
+ }
483
+ }), g = N(() => {
484
+ n || S || (c(!0), p(r));
485
+ }, [n, S, p, r]), _ = [...i].reverse().find((o) => o.type === "assistant_text"), u = _ && _.type === "assistant_text" ? _.confirmations.filter((o) => o.status === "pending") : [], m = (o, d) => {
486
+ const f = () => {
487
+ o.correlationId && E(o.correlationId, !0);
488
+ }, l = () => {
489
+ o.correlationId && E(o.correlationId, !1);
490
+ };
491
+ return o.escalated || o.params && Object.keys(o.params).length > 0 ? /* @__PURE__ */ v(
492
+ W,
493
+ {
494
+ confirmation: o,
495
+ onApprove: f,
496
+ onDeny: l
497
+ },
498
+ o.correlationId ?? String(d)
499
+ ) : /* @__PURE__ */ v(
500
+ Q,
501
+ {
502
+ confirmation: o,
503
+ onApprove: f,
504
+ onDeny: l
505
+ },
506
+ o.correlationId ?? String(d)
507
+ );
508
+ };
509
+ return n ? /* @__PURE__ */ w("div", { className: "amodal-action", "data-testid": "action-container", children: [
510
+ S && /* @__PURE__ */ v("div", { className: "amodal-action__loading", "data-testid": "action-loading", children: "Processing..." }),
511
+ _ && _.type === "assistant_text" && _.text && /* @__PURE__ */ v("div", { className: "amodal-action__result", "data-testid": "action-result", children: _.text }),
512
+ u.map(m)
513
+ ] }) : /* @__PURE__ */ v(
514
+ "button",
515
+ {
516
+ className: "amodal-action__trigger",
517
+ onClick: g,
518
+ "data-testid": "action-trigger",
519
+ children: s ?? "Run"
520
+ }
521
+ );
522
+ }
523
+ /**
524
+ * @license
525
+ * Copyright 2025 Amodal Labs, Inc.
526
+ * SPDX-License-Identifier: MIT
527
+ */
528
+ function re(r) {
529
+ const { prompt: s, context: t, autoFetch: e = !0 } = r, { client: a } = C(), [n, c] = y(null), [i, p] = y(!1), [S, E] = y(null), g = T(null), _ = T(!1), u = N(async () => {
530
+ g.current && g.current.abort();
531
+ const o = new AbortController();
532
+ g.current = o, p(!0), E(null);
533
+ try {
534
+ let d = "";
535
+ const f = [];
536
+ for await (const l of a.chatStream(s, { context: t, signal: o.signal }))
537
+ switch (l.type) {
538
+ case "text_delta":
539
+ d += l.content;
540
+ break;
541
+ case "tool_call_start":
542
+ f.push({
543
+ toolId: l.tool_id,
544
+ toolName: l.tool_name,
545
+ parameters: l.parameters,
546
+ status: "running"
547
+ });
548
+ break;
549
+ case "tool_call_result": {
550
+ const b = f.find((A) => A.toolId === l.tool_id);
551
+ b && (b.status = l.status, b.result = l.result, b.duration_ms = l.duration_ms, b.error = l.error);
552
+ break;
553
+ }
554
+ case "error":
555
+ E(l.message);
556
+ break;
557
+ default:
558
+ break;
559
+ }
560
+ c({ text: d, toolCalls: f });
561
+ } catch (d) {
562
+ d instanceof DOMException && d.name === "AbortError" || E(d instanceof Error ? d.message : "Unknown error");
563
+ } finally {
564
+ p(!1), g.current = null;
565
+ }
566
+ }, [a, s, t]), m = N(() => {
567
+ u();
568
+ }, [u]);
569
+ return I(() => (e && !_.current && (_.current = !0, u()), () => {
570
+ g.current && g.current.abort();
571
+ }), [e, u]), { brief: n, isLoading: i, error: S, refresh: m };
572
+ }
573
+ /**
574
+ * @license
575
+ * Copyright 2025 Amodal Labs, Inc.
576
+ * SPDX-License-Identifier: MIT
577
+ */
578
+ function se(r) {
579
+ const { prompt: s, context: t, autoFetch: e = !0 } = r, { client: a } = C(), [n, c] = y("idle"), [i, p] = y(""), [S, E] = y(""), [g, _] = y(null), u = T(null), m = T(!1), o = N(async () => {
580
+ u.current && u.current.abort();
581
+ const f = new AbortController();
582
+ u.current = f, c("loading"), _(null), p(""), E("");
583
+ try {
584
+ let l = "";
585
+ for await (const A of a.chatStream(s, { context: t, signal: f.signal }))
586
+ switch (A.type) {
587
+ case "text_delta":
588
+ l += A.content;
589
+ break;
590
+ case "error":
591
+ _(A.message), c("error");
592
+ return;
593
+ default:
594
+ break;
595
+ }
596
+ const b = l.indexOf(`
597
+
598
+ `);
599
+ b >= 0 ? (p(l.slice(0, b).trim()), E(l.slice(b + 2).trim())) : p(l.trim()), c("done");
600
+ } catch (l) {
601
+ l instanceof DOMException && l.name === "AbortError" || (_(l instanceof Error ? l.message : "Unknown error"), c("error"));
602
+ } finally {
603
+ u.current = null;
604
+ }
605
+ }, [a, s, t]), d = N(() => {
606
+ o();
607
+ }, [o]);
608
+ return I(() => (e && !m.current && (m.current = !0, o()), () => {
609
+ u.current && u.current.abort();
610
+ }), [e, o]), { status: n, summary: i, details: S, isLoading: n === "loading", error: g, refresh: d };
611
+ }
612
+ /**
613
+ * @license
614
+ * Copyright 2025 Amodal Labs, Inc.
615
+ * SPDX-License-Identifier: MIT
616
+ */
617
+ function ne(r) {
618
+ const { taskId: s, autoStream: t = !0 } = r, { client: e } = C(), [a, n] = y("idle"), [c, i] = y(""), [p, S] = y(""), [E, g] = y([]), [_, u] = y(null), m = T(null), o = T(!1), d = N(async () => {
619
+ m.current && m.current.abort();
620
+ const b = new AbortController();
621
+ m.current = b, n("running"), u(null), g([]), S(""), i("");
622
+ try {
623
+ let A = "";
624
+ for await (const x of e.streamTask(s, b.signal))
625
+ switch (g((R) => [...R, x]), x.type) {
626
+ case "text_delta":
627
+ A += x.content, S(A);
628
+ break;
629
+ case "tool_call_start":
630
+ i(`Running ${x.tool_name}...`);
631
+ break;
632
+ case "tool_call_result":
633
+ i("");
634
+ break;
635
+ case "error":
636
+ u(x.message), n("error");
637
+ return;
638
+ case "done":
639
+ n("completed");
640
+ return;
641
+ default:
642
+ break;
643
+ }
644
+ a === "running" && n("completed");
645
+ } catch (A) {
646
+ A instanceof DOMException && A.name === "AbortError" || (u(A instanceof Error ? A.message : "Unknown error"), n("error"));
647
+ } finally {
648
+ m.current = null;
649
+ }
650
+ }, [e, s, a]), f = N(() => {
651
+ m.current && (m.current.abort(), m.current = null);
652
+ }, []), l = T(d);
653
+ return l.current = d, I(() => (t && !o.current && (o.current = !0, l.current()), () => {
654
+ m.current && m.current.abort();
655
+ }), [t]), {
656
+ status: a,
657
+ progress: c,
658
+ result: p,
659
+ events: E,
660
+ error: _,
661
+ start: () => void d(),
662
+ stop: f
663
+ };
664
+ }
665
+ /**
666
+ * @license
667
+ * Copyright 2025 Amodal Labs, Inc.
668
+ * SPDX-License-Identifier: MIT
669
+ */
670
+ function ae(r) {
671
+ const { prompt: s, context: t, autoFetch: e = !0 } = r, { client: a } = C(), [n, c] = y(null), [i, p] = y(!1), [S, E] = y(null), g = T(null), _ = T(!1), u = N(async () => {
672
+ g.current && g.current.abort();
673
+ const o = new AbortController();
674
+ g.current = o, p(!0), E(null);
675
+ try {
676
+ let d = "";
677
+ for await (const f of a.chatStream(s, { context: t, signal: o.signal }))
678
+ switch (f.type) {
679
+ case "text_delta":
680
+ d += f.content;
681
+ break;
682
+ case "error":
683
+ E(f.message);
684
+ break;
685
+ default:
686
+ break;
687
+ }
688
+ c(d);
689
+ } catch (d) {
690
+ d instanceof DOMException && d.name === "AbortError" || E(d instanceof Error ? d.message : "Unknown error");
691
+ } finally {
692
+ p(!1), g.current = null;
693
+ }
694
+ }, [a, s, t]), m = N(() => {
695
+ u();
696
+ }, [u]);
697
+ return I(() => (e && !_.current && (_.current = !0, u()), () => {
698
+ g.current && g.current.abort();
699
+ }), [e, u]), { data: n, isLoading: i, error: S, refetch: m };
700
+ }
701
+ /**
702
+ * @license
703
+ * Copyright 2025 Amodal Labs, Inc.
704
+ * SPDX-License-Identifier: MIT
705
+ */
706
+ function oe(r, s) {
707
+ const { key: t, refreshInterval: e = 3e4 } = s, { client: a } = C(), [n, c] = y(null), [i, p] = y([]), [S, E] = y(!0), [g, _] = y(null), u = T(null), m = N(async () => {
708
+ u.current && u.current.abort();
709
+ const d = new AbortController();
710
+ u.current = d;
711
+ try {
712
+ const f = await a.getStoreDocument(r, t, d.signal);
713
+ c(f.document), p(f.history), _(null);
714
+ } catch (f) {
715
+ f instanceof DOMException && f.name === "AbortError" || _(f instanceof Error ? f.message : "Failed to fetch document");
716
+ } finally {
717
+ E(!1), u.current = null;
718
+ }
719
+ }, [a, r, t]), o = N(() => {
720
+ m();
721
+ }, [m]);
722
+ return I(() => (E(!0), m(), () => {
723
+ u.current && u.current.abort();
724
+ }), [m]), I(() => {
725
+ if (e <= 0) return;
726
+ const d = setInterval(() => {
727
+ m();
728
+ }, e);
729
+ return () => clearInterval(d);
730
+ }, [m, e]), {
731
+ data: (n == null ? void 0 : n.payload) ?? null,
732
+ meta: (n == null ? void 0 : n.meta) ?? null,
733
+ document: n,
734
+ history: i,
735
+ isLoading: S,
736
+ error: g,
737
+ refetch: o
738
+ };
739
+ }
740
+ /**
741
+ * @license
742
+ * Copyright 2025 Amodal Labs, Inc.
743
+ * SPDX-License-Identifier: MIT
744
+ */
745
+ function le(r, s = {}) {
746
+ const { filter: t, sort: e, limit: a = 20, refreshInterval: n = 3e4 } = s, { client: c } = C(), [i, p] = y([]), [S, E] = y(0), [g, _] = y(!1), [u, m] = y(!0), [o, d] = y(null), f = T(null), l = t ? JSON.stringify(t) : "", b = N(async () => {
747
+ f.current && f.current.abort();
748
+ const x = new AbortController();
749
+ f.current = x;
750
+ try {
751
+ const R = await c.getStoreDocuments(r, {
752
+ filter: l ? JSON.parse(l) : void 0,
753
+ sort: e,
754
+ limit: a,
755
+ signal: x.signal
756
+ });
757
+ p(R.documents), E(R.total), _(R.hasMore), d(null);
758
+ } catch (R) {
759
+ R instanceof DOMException && R.name === "AbortError" || d(R instanceof Error ? R.message : "Failed to fetch store list");
760
+ } finally {
761
+ m(!1), f.current = null;
762
+ }
763
+ }, [c, r, l, e, a]), A = N(() => {
764
+ b();
765
+ }, [b]);
766
+ return I(() => (m(!0), b(), () => {
767
+ f.current && f.current.abort();
768
+ }), [b]), I(() => {
769
+ if (n <= 0) return;
770
+ const x = setInterval(() => {
771
+ b();
772
+ }, n);
773
+ return () => clearInterval(x);
774
+ }, [b, n]), {
775
+ data: i.map((x) => x.payload),
776
+ documents: i,
777
+ total: S,
778
+ hasMore: g,
779
+ isLoading: u,
780
+ error: o,
781
+ refetch: A
782
+ };
783
+ }
784
+ /**
785
+ * @license
786
+ * Copyright 2025 Amodal Labs, Inc.
787
+ * SPDX-License-Identifier: MIT
788
+ */
789
+ function ce(r, s = {}) {
790
+ const { client: t } = C(), [e, a] = y(!1), [n, c] = y(null), [i, p] = y(null), S = T(null);
791
+ return { execute: N(
792
+ (g) => {
793
+ S.current && S.current.abort();
794
+ const _ = new AbortController();
795
+ S.current = _, a(!0), c(null), p(null);
796
+ let u = `Run skill "${r}"`;
797
+ g && Object.keys(g).length > 0 && (u += ` with parameters: ${JSON.stringify(g)}`), s.stores && s.stores.length > 0 && (u += `. Write results to stores: ${s.stores.join(", ")}`), s.confirm && (u += ". Confirm before writing."), (async () => {
798
+ try {
799
+ let m = "";
800
+ for await (const o of t.chatStream(u, { signal: _.signal }))
801
+ switch (o.type) {
802
+ case "text_delta":
803
+ m += o.content;
804
+ break;
805
+ case "error":
806
+ p(o.message);
807
+ break;
808
+ default:
809
+ break;
810
+ }
811
+ c(m);
812
+ } catch (m) {
813
+ m instanceof DOMException && m.name === "AbortError" || p(m instanceof Error ? m.message : "Skill execution failed");
814
+ } finally {
815
+ a(!1), S.current = null;
816
+ }
817
+ })();
818
+ },
819
+ [t, r, s.stores, s.confirm]
820
+ ), loading: e, result: n, error: i };
821
+ }
822
+ /**
823
+ * @license
824
+ * Copyright 2025 Amodal Labs, Inc.
825
+ * SPDX-License-Identifier: MIT
826
+ */
827
+ const q = P(null);
828
+ function ie() {
829
+ const r = j(q), s = N((t, e) => {
830
+ }, []);
831
+ return r ?? s;
832
+ }
833
+ export {
834
+ te as AmodalAction,
835
+ ee as AmodalChat,
836
+ Z as AmodalProvider,
837
+ Q as ConfirmCard,
838
+ q as NavigateContext,
839
+ W as ReviewCard,
840
+ V as RuntimeClient,
841
+ me as parseSSELine,
842
+ fe as streamSSE,
843
+ pe as streamSSEGet,
844
+ re as useAmodalBrief,
845
+ J as useAmodalChat,
846
+ C as useAmodalContext,
847
+ se as useAmodalInsight,
848
+ ae as useAmodalQuery,
849
+ ne as useAmodalTask,
850
+ ie as useNavigate,
851
+ ce as useSkillAction,
852
+ oe as useStore,
853
+ le as useStoreList
854
+ };
855
+ //# sourceMappingURL=react.js.map