@amodalai/react 0.2.0 → 0.2.1

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