@amodalai/react 0.1.6 → 0.1.9
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/hooks/useAmodalChat.d.ts +6 -0
- package/dist/hooks/useAmodalChat.d.ts.map +1 -1
- package/dist/react.js +214 -208
- package/dist/react.js.map +1 -1
- package/dist/{theme-BaBR_tym.js → theme-VAUsolBG.js} +5 -3
- package/dist/theme-VAUsolBG.js.map +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/widget.js +2 -2
- package/package.json +1 -1
- package/dist/theme-BaBR_tym.js.map +0 -1
package/dist/react.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsx as v, jsxs as w } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as F, useMemo as B, useContext as
|
|
2
|
+
import { createContext as F, useMemo as B, useContext as U, useReducer as Q, useRef as N, useCallback as A, useEffect as R, useState as y } from "react";
|
|
3
3
|
import { RuntimeClient as V } from "./client.js";
|
|
4
4
|
import { ChatClient as me, ChatStream as fe } 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-
|
|
6
|
-
import { T as be, W as Te, c as Ae, a as Ne, d as xe, g as Ce, l as we, p as Re, s as
|
|
7
|
-
const
|
|
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 we, p as Re, s as ke, b as Ie, e as De, u as Me } from "./event-bus-h26clqbZ.js";
|
|
7
|
+
const j = F(null);
|
|
8
8
|
function Z({ runtimeUrl: s, tenantId: r, getToken: t, children: e }) {
|
|
9
9
|
const n = B(
|
|
10
10
|
() => new V({ runtimeUrl: s, tenantId: r, getToken: t }),
|
|
@@ -13,10 +13,10 @@ function Z({ runtimeUrl: s, tenantId: r, getToken: t, children: e }) {
|
|
|
13
13
|
() => ({ client: n, runtimeUrl: s, tenantId: r }),
|
|
14
14
|
[n, s, r]
|
|
15
15
|
);
|
|
16
|
-
return /* @__PURE__ */ v(
|
|
16
|
+
return /* @__PURE__ */ v(j.Provider, { value: a, children: e });
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
const s = j
|
|
18
|
+
function k() {
|
|
19
|
+
const s = U(j);
|
|
20
20
|
if (!s)
|
|
21
21
|
throw new Error("useAmodalContext must be used within an <AmodalProvider>");
|
|
22
22
|
return s;
|
|
@@ -32,7 +32,8 @@ const G = {
|
|
|
32
32
|
isStreaming: !1,
|
|
33
33
|
error: null,
|
|
34
34
|
activeToolCalls: [],
|
|
35
|
-
isHistorical: !1
|
|
35
|
+
isHistorical: !1,
|
|
36
|
+
usage: { inputTokens: 0, outputTokens: 0 }
|
|
36
37
|
};
|
|
37
38
|
let $ = 0;
|
|
38
39
|
function P() {
|
|
@@ -84,8 +85,8 @@ function X(s, r) {
|
|
|
84
85
|
status: "running"
|
|
85
86
|
};
|
|
86
87
|
if (e && e.type === "assistant_text") {
|
|
87
|
-
const a = [...e.toolCalls, n], c = [...e.contentBlocks],
|
|
88
|
-
|
|
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 };
|
|
89
90
|
}
|
|
90
91
|
return {
|
|
91
92
|
...s,
|
|
@@ -96,16 +97,16 @@ function X(s, r) {
|
|
|
96
97
|
case "STREAM_TOOL_CALL_RESULT": {
|
|
97
98
|
const t = [...s.messages], e = t[t.length - 1];
|
|
98
99
|
if (e && e.type === "assistant_text") {
|
|
99
|
-
const a = (
|
|
100
|
-
...
|
|
100
|
+
const a = (i) => i.toolId === r.toolId ? {
|
|
101
|
+
...i,
|
|
101
102
|
status: r.status,
|
|
102
103
|
result: r.result,
|
|
103
104
|
duration_ms: r.duration_ms,
|
|
104
105
|
error: r.error
|
|
105
|
-
} :
|
|
106
|
-
(
|
|
106
|
+
} : i, c = e.toolCalls.map(a), u = e.contentBlocks.map(
|
|
107
|
+
(i) => i.type === "tool_calls" ? { ...i, calls: i.calls.map(a) } : i
|
|
107
108
|
);
|
|
108
|
-
t[t.length - 1] = { ...e, toolCalls: c, contentBlocks:
|
|
109
|
+
t[t.length - 1] = { ...e, toolCalls: c, contentBlocks: u };
|
|
109
110
|
}
|
|
110
111
|
const n = s.activeToolCalls.filter(
|
|
111
112
|
(a) => a.toolId !== r.toolId
|
|
@@ -115,8 +116,8 @@ function X(s, r) {
|
|
|
115
116
|
case "STREAM_SUBAGENT_EVENT": {
|
|
116
117
|
const t = [...s.messages], e = t[t.length - 1];
|
|
117
118
|
if (e && e.type === "assistant_text") {
|
|
118
|
-
const n = (
|
|
119
|
-
(
|
|
119
|
+
const n = (u) => u.toolId === r.parentToolId ? { ...u, subagentEvents: [...u.subagentEvents ?? [], r.event] } : u, a = e.toolCalls.map(n), c = e.contentBlocks.map(
|
|
120
|
+
(u) => u.type === "tool_calls" ? { ...u, calls: u.calls.map(n) } : u
|
|
120
121
|
);
|
|
121
122
|
t[t.length - 1] = { ...e, toolCalls: a, contentBlocks: c };
|
|
122
123
|
}
|
|
@@ -169,12 +170,13 @@ function X(s, r) {
|
|
|
169
170
|
case "STREAM_DONE": {
|
|
170
171
|
const t = [...s.messages], e = t[t.length - 1];
|
|
171
172
|
if (e && e.type === "assistant_text") {
|
|
172
|
-
const
|
|
173
|
-
(i) => i.type === "tool_calls" ? { ...i, calls: i.calls.map(
|
|
173
|
+
const a = (i) => i.status === "running" ? { ...i, status: "error", error: "Stopped" } : i, c = e.toolCalls.map(a), u = e.contentBlocks.map(
|
|
174
|
+
(i) => i.type === "tool_calls" ? { ...i, calls: i.calls.map(a) } : i
|
|
174
175
|
);
|
|
175
|
-
t[t.length - 1] = { ...e, toolCalls:
|
|
176
|
+
t[t.length - 1] = { ...e, toolCalls: c, contentBlocks: u };
|
|
176
177
|
}
|
|
177
|
-
|
|
178
|
+
const n = r.usage ? { inputTokens: s.usage.inputTokens + r.usage.inputTokens, outputTokens: s.usage.outputTokens + r.usage.outputTokens } : s.usage;
|
|
179
|
+
return { ...s, messages: t, isStreaming: !1, activeToolCalls: [], usage: n };
|
|
178
180
|
}
|
|
179
181
|
case "RESET":
|
|
180
182
|
return { ...G };
|
|
@@ -183,124 +185,127 @@ function X(s, r) {
|
|
|
183
185
|
}
|
|
184
186
|
}
|
|
185
187
|
function W(s) {
|
|
186
|
-
const { client: r } =
|
|
187
|
-
c.current = s, n.current = t.sessionId;
|
|
188
|
-
const
|
|
189
|
-
(
|
|
188
|
+
const { client: r } = k(), [t, e] = Q(X, G), n = N((s == null ? void 0 : s.initialSessionId) ?? null), a = N(null), c = N(s);
|
|
189
|
+
c.current = s, n.current = t.sessionId ?? n.current;
|
|
190
|
+
const u = A(
|
|
191
|
+
(_) => {
|
|
190
192
|
if (t.isStreaming) return;
|
|
191
|
-
e({ type: "SEND_MESSAGE", text:
|
|
192
|
-
const
|
|
193
|
-
a.current =
|
|
194
|
-
var o, d,
|
|
195
|
-
let
|
|
193
|
+
e({ type: "SEND_MESSAGE", text: _ });
|
|
194
|
+
const h = new AbortController();
|
|
195
|
+
a.current = h, (async () => {
|
|
196
|
+
var o, d, p, l, b, T, x, C, M, D, O;
|
|
197
|
+
let f = !1;
|
|
196
198
|
try {
|
|
197
|
-
const
|
|
199
|
+
const I = r.chatStream(_, {
|
|
198
200
|
sessionId: n.current ?? void 0,
|
|
199
201
|
context: (o = c.current) == null ? void 0 : o.context,
|
|
200
|
-
signal:
|
|
202
|
+
signal: h.signal
|
|
201
203
|
});
|
|
202
|
-
for await (const
|
|
203
|
-
switch (
|
|
204
|
+
for await (const g of I)
|
|
205
|
+
switch (g.type) {
|
|
204
206
|
case "init":
|
|
205
|
-
e({ type: "STREAM_INIT", sessionId:
|
|
207
|
+
e({ type: "STREAM_INIT", sessionId: g.session_id }), (p = (d = c.current) == null ? void 0 : d.onSessionCreated) == null || p.call(d, g.session_id);
|
|
206
208
|
break;
|
|
207
209
|
case "text_delta":
|
|
208
|
-
e({ type: "STREAM_TEXT_DELTA", content:
|
|
210
|
+
e({ type: "STREAM_TEXT_DELTA", content: g.content });
|
|
209
211
|
break;
|
|
210
212
|
case "tool_call_start":
|
|
211
213
|
e({
|
|
212
214
|
type: "STREAM_TOOL_CALL_START",
|
|
213
|
-
toolId:
|
|
214
|
-
toolName:
|
|
215
|
-
parameters:
|
|
215
|
+
toolId: g.tool_id,
|
|
216
|
+
toolName: g.tool_name,
|
|
217
|
+
parameters: g.parameters
|
|
216
218
|
});
|
|
217
219
|
break;
|
|
218
220
|
case "tool_call_result":
|
|
219
221
|
e({
|
|
220
222
|
type: "STREAM_TOOL_CALL_RESULT",
|
|
221
|
-
toolId:
|
|
222
|
-
status:
|
|
223
|
-
result:
|
|
224
|
-
duration_ms:
|
|
225
|
-
error:
|
|
223
|
+
toolId: g.tool_id,
|
|
224
|
+
status: g.status,
|
|
225
|
+
result: g.result,
|
|
226
|
+
duration_ms: g.duration_ms,
|
|
227
|
+
error: g.error
|
|
226
228
|
}), (b = (l = c.current) == null ? void 0 : l.onToolCall) == null || b.call(l, {
|
|
227
|
-
toolId:
|
|
229
|
+
toolId: g.tool_id,
|
|
228
230
|
toolName: "",
|
|
229
231
|
parameters: {},
|
|
230
|
-
status:
|
|
231
|
-
result:
|
|
232
|
-
duration_ms:
|
|
233
|
-
error:
|
|
232
|
+
status: g.status,
|
|
233
|
+
result: g.result,
|
|
234
|
+
duration_ms: g.duration_ms,
|
|
235
|
+
error: g.error
|
|
234
236
|
});
|
|
235
237
|
break;
|
|
236
238
|
case "subagent_event":
|
|
237
239
|
e({
|
|
238
240
|
type: "STREAM_SUBAGENT_EVENT",
|
|
239
|
-
parentToolId:
|
|
241
|
+
parentToolId: g.parent_tool_id,
|
|
240
242
|
event: {
|
|
241
|
-
agentName:
|
|
242
|
-
eventType:
|
|
243
|
-
toolName:
|
|
244
|
-
toolArgs:
|
|
245
|
-
result:
|
|
246
|
-
text:
|
|
247
|
-
error:
|
|
248
|
-
timestamp:
|
|
243
|
+
agentName: g.agent_name,
|
|
244
|
+
eventType: g.event_type,
|
|
245
|
+
toolName: g.tool_name,
|
|
246
|
+
toolArgs: g.tool_args,
|
|
247
|
+
result: g.result,
|
|
248
|
+
text: g.text,
|
|
249
|
+
error: g.error,
|
|
250
|
+
timestamp: g.timestamp
|
|
249
251
|
}
|
|
250
252
|
});
|
|
251
253
|
break;
|
|
252
254
|
case "widget":
|
|
253
255
|
e({
|
|
254
256
|
type: "STREAM_WIDGET",
|
|
255
|
-
widgetType:
|
|
256
|
-
data:
|
|
257
|
+
widgetType: g.widget_type,
|
|
258
|
+
data: g.data
|
|
257
259
|
});
|
|
258
260
|
break;
|
|
259
261
|
case "confirmation_required": {
|
|
260
262
|
const L = {
|
|
261
|
-
endpoint:
|
|
262
|
-
method:
|
|
263
|
-
reason:
|
|
264
|
-
escalated:
|
|
265
|
-
params:
|
|
266
|
-
connectionName:
|
|
267
|
-
correlationId:
|
|
263
|
+
endpoint: g.endpoint,
|
|
264
|
+
method: g.method,
|
|
265
|
+
reason: g.reason,
|
|
266
|
+
escalated: g.escalated,
|
|
267
|
+
params: g.params,
|
|
268
|
+
connectionName: g.connection_name,
|
|
269
|
+
correlationId: g.correlation_id,
|
|
268
270
|
status: "pending"
|
|
269
271
|
};
|
|
270
272
|
e({ type: "STREAM_CONFIRMATION_REQUIRED", confirmation: L }), (x = (T = c.current) == null ? void 0 : T.onConfirmation) == null || x.call(T, L);
|
|
271
273
|
break;
|
|
272
274
|
}
|
|
273
275
|
case "error":
|
|
274
|
-
e({ type: "STREAM_ERROR", message:
|
|
276
|
+
e({ type: "STREAM_ERROR", message: g.message });
|
|
275
277
|
break;
|
|
276
278
|
case "done":
|
|
277
|
-
|
|
279
|
+
f = !0, e({
|
|
280
|
+
type: "STREAM_DONE",
|
|
281
|
+
usage: g.usage ? { inputTokens: g.usage.input_tokens, outputTokens: g.usage.output_tokens } : void 0
|
|
282
|
+
}), (M = (C = c.current) == null ? void 0 : C.onStreamEnd) == null || M.call(C);
|
|
278
283
|
break;
|
|
279
284
|
default:
|
|
280
285
|
break;
|
|
281
286
|
}
|
|
282
|
-
} catch (
|
|
283
|
-
|
|
287
|
+
} catch (I) {
|
|
288
|
+
I instanceof DOMException && I.name === "AbortError" || e({
|
|
284
289
|
type: "STREAM_ERROR",
|
|
285
|
-
message:
|
|
290
|
+
message: I instanceof Error ? I.message : "Unknown error"
|
|
286
291
|
});
|
|
287
292
|
} finally {
|
|
288
|
-
a.current = null, !
|
|
293
|
+
a.current = null, !f && !h.signal.aborted && (e({ type: "STREAM_DONE" }), (O = (D = c.current) == null ? void 0 : D.onStreamEnd) == null || O.call(D));
|
|
289
294
|
}
|
|
290
295
|
})();
|
|
291
296
|
},
|
|
292
297
|
[r, t.isStreaming]
|
|
293
|
-
),
|
|
298
|
+
), i = A(() => {
|
|
294
299
|
a.current && (a.current.abort(), a.current = null), e({ type: "STREAM_DONE" });
|
|
295
300
|
}, []), S = A(() => {
|
|
296
301
|
a.current && (a.current.abort(), a.current = null), e({ type: "RESET" });
|
|
297
302
|
}, []), E = A(
|
|
298
|
-
(
|
|
299
|
-
e({ type: "CONFIRMATION_RESPONDED", correlationId:
|
|
300
|
-
const
|
|
301
|
-
t.isStreaming ||
|
|
303
|
+
(_, h) => {
|
|
304
|
+
e({ type: "CONFIRMATION_RESPONDED", correlationId: _, approved: h });
|
|
305
|
+
const m = h ? `I approve the action (correlation: ${_})` : `I deny the action (correlation: ${_})`;
|
|
306
|
+
t.isStreaming || u(m);
|
|
302
307
|
},
|
|
303
|
-
[
|
|
308
|
+
[u, t.isStreaming]
|
|
304
309
|
);
|
|
305
310
|
return R(
|
|
306
311
|
() => () => {
|
|
@@ -309,12 +314,13 @@ function W(s) {
|
|
|
309
314
|
[]
|
|
310
315
|
), {
|
|
311
316
|
messages: t.messages,
|
|
312
|
-
send:
|
|
313
|
-
stop:
|
|
317
|
+
send: u,
|
|
318
|
+
stop: i,
|
|
314
319
|
isStreaming: t.isStreaming,
|
|
315
320
|
activeToolCalls: t.activeToolCalls,
|
|
316
321
|
sessionId: t.sessionId,
|
|
317
322
|
error: t.error,
|
|
323
|
+
usage: t.usage,
|
|
318
324
|
reset: S,
|
|
319
325
|
respondToConfirmation: E
|
|
320
326
|
};
|
|
@@ -406,42 +412,42 @@ function ee({
|
|
|
406
412
|
className: n,
|
|
407
413
|
...a
|
|
408
414
|
}) {
|
|
409
|
-
const { messages: c, send:
|
|
415
|
+
const { messages: c, send: u, isStreaming: i, respondToConfirmation: S } = W(a), [E, _] = y(""), h = N(null), m = A(
|
|
410
416
|
(o) => {
|
|
411
417
|
o.preventDefault();
|
|
412
418
|
const d = E.trim();
|
|
413
|
-
d.length === 0 ||
|
|
419
|
+
d.length === 0 || i || (_(""), u(d));
|
|
414
420
|
},
|
|
415
|
-
[E,
|
|
416
|
-
),
|
|
417
|
-
return /* @__PURE__ */ w("div", { className:
|
|
421
|
+
[E, i, u]
|
|
422
|
+
), f = ["amodal-chat", n].filter(Boolean).join(" ");
|
|
423
|
+
return /* @__PURE__ */ w("div", { className: f, "data-testid": "amodal-chat", children: [
|
|
418
424
|
/* @__PURE__ */ w("div", { className: "amodal-chat__messages", "data-testid": "message-list", children: [
|
|
419
425
|
c.map((o) => {
|
|
420
426
|
switch (o.type) {
|
|
421
427
|
case "user":
|
|
422
428
|
return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--user", "data-testid": "user-message", children: o.text }, o.id);
|
|
423
429
|
case "assistant_text":
|
|
424
|
-
return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--assistant", "data-testid": "assistant-message", children: o.contentBlocks.map((d,
|
|
430
|
+
return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--assistant", "data-testid": "assistant-message", children: o.contentBlocks.map((d, p) => {
|
|
425
431
|
switch (d.type) {
|
|
426
432
|
case "text":
|
|
427
|
-
return /* @__PURE__ */ v("div", { className: "amodal-chat__text", children: r ? r(d.text) : d.text }, `text-${String(
|
|
433
|
+
return /* @__PURE__ */ v("div", { className: "amodal-chat__text", children: r ? r(d.text) : d.text }, `text-${String(p)}`);
|
|
428
434
|
case "tool_calls":
|
|
429
435
|
return /* @__PURE__ */ v("div", { className: "amodal-chat__tool-calls", children: d.calls.map(
|
|
430
436
|
(l) => t ? /* @__PURE__ */ v("div", { children: t(l) }, l.toolId) : /* @__PURE__ */ w("div", { className: "amodal-chat__tool-call", "data-testid": "tool-call", children: [
|
|
431
437
|
/* @__PURE__ */ v("span", { className: "amodal-chat__tool-name", children: l.toolName }),
|
|
432
438
|
/* @__PURE__ */ v("span", { className: "amodal-chat__tool-status", children: l.status })
|
|
433
439
|
] }, l.toolId)
|
|
434
|
-
) }, `tools-${String(
|
|
440
|
+
) }, `tools-${String(p)}`);
|
|
435
441
|
case "confirmation": {
|
|
436
442
|
const l = d.confirmation, b = () => {
|
|
437
443
|
l.correlationId && S(l.correlationId, !0);
|
|
438
444
|
}, T = () => {
|
|
439
445
|
l.correlationId && S(l.correlationId, !1);
|
|
440
446
|
};
|
|
441
|
-
return e ? /* @__PURE__ */ v("div", { children: e(l, b, T) }, `conf-${String(
|
|
447
|
+
return e ? /* @__PURE__ */ v("div", { children: e(l, b, T) }, `conf-${String(p)}`) : l.escalated || l.params && Object.keys(l.params).length > 0 ? /* @__PURE__ */ v(J, { confirmation: l, onApprove: b, onDeny: T }, `conf-${String(p)}`) : /* @__PURE__ */ v(H, { confirmation: l, onApprove: b, onDeny: T }, `conf-${String(p)}`);
|
|
442
448
|
}
|
|
443
449
|
case "widget":
|
|
444
|
-
return /* @__PURE__ */ v("div", { className: "amodal-chat__widget", "data-testid": "widget", children: d.widgetType }, `widget-${String(
|
|
450
|
+
return /* @__PURE__ */ v("div", { className: "amodal-chat__widget", "data-testid": "widget", children: d.widgetType }, `widget-${String(p)}`);
|
|
445
451
|
default:
|
|
446
452
|
return null;
|
|
447
453
|
}
|
|
@@ -452,17 +458,17 @@ function ee({
|
|
|
452
458
|
return null;
|
|
453
459
|
}
|
|
454
460
|
}),
|
|
455
|
-
/* @__PURE__ */ v("div", { ref:
|
|
461
|
+
/* @__PURE__ */ v("div", { ref: h })
|
|
456
462
|
] }),
|
|
457
|
-
/* @__PURE__ */ w("form", { className: "amodal-chat__input-bar", onSubmit:
|
|
463
|
+
/* @__PURE__ */ w("form", { className: "amodal-chat__input-bar", onSubmit: m, "data-testid": "input-bar", children: [
|
|
458
464
|
/* @__PURE__ */ v(
|
|
459
465
|
"input",
|
|
460
466
|
{
|
|
461
467
|
className: "amodal-chat__input",
|
|
462
468
|
value: E,
|
|
463
|
-
onChange: (o) =>
|
|
469
|
+
onChange: (o) => _(o.target.value),
|
|
464
470
|
placeholder: s,
|
|
465
|
-
disabled:
|
|
471
|
+
disabled: i,
|
|
466
472
|
"data-testid": "chat-input"
|
|
467
473
|
}
|
|
468
474
|
),
|
|
@@ -471,7 +477,7 @@ function ee({
|
|
|
471
477
|
{
|
|
472
478
|
className: "amodal-chat__send",
|
|
473
479
|
type: "submit",
|
|
474
|
-
disabled:
|
|
480
|
+
disabled: i || E.trim().length === 0,
|
|
475
481
|
"data-testid": "send-button",
|
|
476
482
|
children: "Send"
|
|
477
483
|
}
|
|
@@ -480,16 +486,16 @@ function ee({
|
|
|
480
486
|
] });
|
|
481
487
|
}
|
|
482
488
|
function te({ prompt: s, label: r, context: t, onComplete: e, onError: n }) {
|
|
483
|
-
const [a, c] = y(!1), { messages:
|
|
489
|
+
const [a, c] = y(!1), { messages: u, send: i, isStreaming: S, respondToConfirmation: E } = W({
|
|
484
490
|
context: t,
|
|
485
491
|
onStreamEnd: () => {
|
|
486
|
-
const o =
|
|
492
|
+
const o = u[u.length - 1];
|
|
487
493
|
o && o.type === "assistant_text" ? e == null || e(o.text) : o && o.type === "error" && (n == null || n(o.message));
|
|
488
494
|
}
|
|
489
|
-
}),
|
|
490
|
-
a || S || (c(!0),
|
|
491
|
-
}, [a, S,
|
|
492
|
-
const
|
|
495
|
+
}), _ = A(() => {
|
|
496
|
+
a || S || (c(!0), i(s));
|
|
497
|
+
}, [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") : [], f = (o, d) => {
|
|
498
|
+
const p = () => {
|
|
493
499
|
o.correlationId && E(o.correlationId, !0);
|
|
494
500
|
}, l = () => {
|
|
495
501
|
o.correlationId && E(o.correlationId, !1);
|
|
@@ -498,7 +504,7 @@ function te({ prompt: s, label: r, context: t, onComplete: e, onError: n }) {
|
|
|
498
504
|
J,
|
|
499
505
|
{
|
|
500
506
|
confirmation: o,
|
|
501
|
-
onApprove:
|
|
507
|
+
onApprove: p,
|
|
502
508
|
onDeny: l
|
|
503
509
|
},
|
|
504
510
|
o.correlationId ?? String(d)
|
|
@@ -506,7 +512,7 @@ function te({ prompt: s, label: r, context: t, onComplete: e, onError: n }) {
|
|
|
506
512
|
H,
|
|
507
513
|
{
|
|
508
514
|
confirmation: o,
|
|
509
|
-
onApprove:
|
|
515
|
+
onApprove: p,
|
|
510
516
|
onDeny: l
|
|
511
517
|
},
|
|
512
518
|
o.correlationId ?? String(d)
|
|
@@ -514,13 +520,13 @@ function te({ prompt: s, label: r, context: t, onComplete: e, onError: n }) {
|
|
|
514
520
|
};
|
|
515
521
|
return a ? /* @__PURE__ */ w("div", { className: "amodal-action", "data-testid": "action-container", children: [
|
|
516
522
|
S && /* @__PURE__ */ v("div", { className: "amodal-action__loading", "data-testid": "action-loading", children: "Processing..." }),
|
|
517
|
-
|
|
518
|
-
|
|
523
|
+
h && h.type === "assistant_text" && h.text && /* @__PURE__ */ v("div", { className: "amodal-action__result", "data-testid": "action-result", children: h.text }),
|
|
524
|
+
m.map(f)
|
|
519
525
|
] }) : /* @__PURE__ */ v(
|
|
520
526
|
"button",
|
|
521
527
|
{
|
|
522
528
|
className: "amodal-action__trigger",
|
|
523
|
-
onClick:
|
|
529
|
+
onClick: _,
|
|
524
530
|
"data-testid": "action-trigger",
|
|
525
531
|
children: r ?? "Run"
|
|
526
532
|
}
|
|
@@ -532,20 +538,20 @@ function te({ prompt: s, label: r, context: t, onComplete: e, onError: n }) {
|
|
|
532
538
|
* SPDX-License-Identifier: MIT
|
|
533
539
|
*/
|
|
534
540
|
function se(s) {
|
|
535
|
-
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client: n } =
|
|
536
|
-
|
|
541
|
+
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client: n } = k(), [a, c] = y(null), [u, i] = y(!1), [S, E] = y(null), _ = N(null), h = N(!1), m = A(async () => {
|
|
542
|
+
_.current && _.current.abort();
|
|
537
543
|
const o = new AbortController();
|
|
538
|
-
|
|
544
|
+
_.current = o, i(!0), E(null);
|
|
539
545
|
try {
|
|
540
546
|
let d = "";
|
|
541
|
-
const
|
|
547
|
+
const p = [];
|
|
542
548
|
for await (const l of n.chatStream(r, { context: t, signal: o.signal }))
|
|
543
549
|
switch (l.type) {
|
|
544
550
|
case "text_delta":
|
|
545
551
|
d += l.content;
|
|
546
552
|
break;
|
|
547
553
|
case "tool_call_start":
|
|
548
|
-
|
|
554
|
+
p.push({
|
|
549
555
|
toolId: l.tool_id,
|
|
550
556
|
toolName: l.tool_name,
|
|
551
557
|
parameters: l.parameters,
|
|
@@ -553,7 +559,7 @@ function se(s) {
|
|
|
553
559
|
});
|
|
554
560
|
break;
|
|
555
561
|
case "tool_call_result": {
|
|
556
|
-
const b =
|
|
562
|
+
const b = p.find((T) => T.toolId === l.tool_id);
|
|
557
563
|
b && (b.status = l.status, b.result = l.result, b.duration_ms = l.duration_ms, b.error = l.error);
|
|
558
564
|
break;
|
|
559
565
|
}
|
|
@@ -563,18 +569,18 @@ function se(s) {
|
|
|
563
569
|
default:
|
|
564
570
|
break;
|
|
565
571
|
}
|
|
566
|
-
c({ text: d, toolCalls:
|
|
572
|
+
c({ text: d, toolCalls: p });
|
|
567
573
|
} catch (d) {
|
|
568
574
|
d instanceof DOMException && d.name === "AbortError" || E(d instanceof Error ? d.message : "Unknown error");
|
|
569
575
|
} finally {
|
|
570
|
-
|
|
576
|
+
i(!1), _.current = null;
|
|
571
577
|
}
|
|
572
|
-
}, [n, r, t]),
|
|
573
|
-
|
|
574
|
-
}, [
|
|
575
|
-
return R(() => (e && !
|
|
576
|
-
|
|
577
|
-
}), [e,
|
|
578
|
+
}, [n, r, t]), f = A(() => {
|
|
579
|
+
m();
|
|
580
|
+
}, [m]);
|
|
581
|
+
return R(() => (e && !h.current && (h.current = !0, m()), () => {
|
|
582
|
+
_.current && _.current.abort();
|
|
583
|
+
}), [e, m]), { brief: a, isLoading: u, error: S, refresh: f };
|
|
578
584
|
}
|
|
579
585
|
/**
|
|
580
586
|
* @license
|
|
@@ -582,19 +588,19 @@ function se(s) {
|
|
|
582
588
|
* SPDX-License-Identifier: MIT
|
|
583
589
|
*/
|
|
584
590
|
function re(s) {
|
|
585
|
-
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client: n } =
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
|
|
591
|
+
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client: n } = k(), [a, c] = y("idle"), [u, i] = y(""), [S, E] = y(""), [_, h] = y(null), m = N(null), f = N(!1), o = A(async () => {
|
|
592
|
+
m.current && m.current.abort();
|
|
593
|
+
const p = new AbortController();
|
|
594
|
+
m.current = p, c("loading"), h(null), i(""), E("");
|
|
589
595
|
try {
|
|
590
596
|
let l = "";
|
|
591
|
-
for await (const T of n.chatStream(r, { context: t, signal:
|
|
597
|
+
for await (const T of n.chatStream(r, { context: t, signal: p.signal }))
|
|
592
598
|
switch (T.type) {
|
|
593
599
|
case "text_delta":
|
|
594
600
|
l += T.content;
|
|
595
601
|
break;
|
|
596
602
|
case "error":
|
|
597
|
-
|
|
603
|
+
h(T.message), c("error");
|
|
598
604
|
return;
|
|
599
605
|
default:
|
|
600
606
|
break;
|
|
@@ -602,18 +608,18 @@ function re(s) {
|
|
|
602
608
|
const b = l.indexOf(`
|
|
603
609
|
|
|
604
610
|
`);
|
|
605
|
-
b >= 0 ? (
|
|
611
|
+
b >= 0 ? (i(l.slice(0, b).trim()), E(l.slice(b + 2).trim())) : i(l.trim()), c("done");
|
|
606
612
|
} catch (l) {
|
|
607
|
-
l instanceof DOMException && l.name === "AbortError" || (
|
|
613
|
+
l instanceof DOMException && l.name === "AbortError" || (h(l instanceof Error ? l.message : "Unknown error"), c("error"));
|
|
608
614
|
} finally {
|
|
609
|
-
|
|
615
|
+
m.current = null;
|
|
610
616
|
}
|
|
611
617
|
}, [n, r, t]), d = A(() => {
|
|
612
618
|
o();
|
|
613
619
|
}, [o]);
|
|
614
|
-
return R(() => (e && !
|
|
615
|
-
|
|
616
|
-
}), [e, o]), { status: a, summary:
|
|
620
|
+
return R(() => (e && !f.current && (f.current = !0, o()), () => {
|
|
621
|
+
m.current && m.current.abort();
|
|
622
|
+
}), [e, o]), { status: a, summary: u, details: S, isLoading: a === "loading", error: _, refresh: d };
|
|
617
623
|
}
|
|
618
624
|
/**
|
|
619
625
|
* @license
|
|
@@ -621,25 +627,25 @@ function re(s) {
|
|
|
621
627
|
* SPDX-License-Identifier: MIT
|
|
622
628
|
*/
|
|
623
629
|
function ae(s) {
|
|
624
|
-
const { taskId: r, autoStream: t = !0 } = s, { client: e } =
|
|
625
|
-
|
|
630
|
+
const { taskId: r, autoStream: t = !0 } = s, { client: e } = k(), [n, a] = y("idle"), [c, u] = y(""), [i, S] = y(""), [E, _] = y([]), [h, m] = y(null), f = N(null), o = N(!1), d = A(async () => {
|
|
631
|
+
f.current && f.current.abort();
|
|
626
632
|
const b = new AbortController();
|
|
627
|
-
|
|
633
|
+
f.current = b, a("running"), m(null), _([]), S(""), u("");
|
|
628
634
|
try {
|
|
629
635
|
let T = "";
|
|
630
636
|
for await (const x of e.streamTask(r, b.signal))
|
|
631
|
-
switch (
|
|
637
|
+
switch (_((C) => [...C, x]), x.type) {
|
|
632
638
|
case "text_delta":
|
|
633
639
|
T += x.content, S(T);
|
|
634
640
|
break;
|
|
635
641
|
case "tool_call_start":
|
|
636
|
-
|
|
642
|
+
u(`Running ${x.tool_name}...`);
|
|
637
643
|
break;
|
|
638
644
|
case "tool_call_result":
|
|
639
|
-
|
|
645
|
+
u("");
|
|
640
646
|
break;
|
|
641
647
|
case "error":
|
|
642
|
-
|
|
648
|
+
m(x.message), a("error");
|
|
643
649
|
return;
|
|
644
650
|
case "done":
|
|
645
651
|
a("completed");
|
|
@@ -649,23 +655,23 @@ function ae(s) {
|
|
|
649
655
|
}
|
|
650
656
|
n === "running" && a("completed");
|
|
651
657
|
} catch (T) {
|
|
652
|
-
T instanceof DOMException && T.name === "AbortError" || (
|
|
658
|
+
T instanceof DOMException && T.name === "AbortError" || (m(T instanceof Error ? T.message : "Unknown error"), a("error"));
|
|
653
659
|
} finally {
|
|
654
|
-
|
|
660
|
+
f.current = null;
|
|
655
661
|
}
|
|
656
|
-
}, [e, r, n]),
|
|
657
|
-
|
|
662
|
+
}, [e, r, n]), p = A(() => {
|
|
663
|
+
f.current && (f.current.abort(), f.current = null);
|
|
658
664
|
}, []), l = N(d);
|
|
659
665
|
return l.current = d, R(() => (t && !o.current && (o.current = !0, l.current()), () => {
|
|
660
|
-
|
|
666
|
+
f.current && f.current.abort();
|
|
661
667
|
}), [t]), {
|
|
662
668
|
status: n,
|
|
663
669
|
progress: c,
|
|
664
|
-
result:
|
|
670
|
+
result: i,
|
|
665
671
|
events: E,
|
|
666
|
-
error:
|
|
672
|
+
error: h,
|
|
667
673
|
start: () => void d(),
|
|
668
|
-
stop:
|
|
674
|
+
stop: p
|
|
669
675
|
};
|
|
670
676
|
}
|
|
671
677
|
/**
|
|
@@ -674,19 +680,19 @@ function ae(s) {
|
|
|
674
680
|
* SPDX-License-Identifier: MIT
|
|
675
681
|
*/
|
|
676
682
|
function ne(s) {
|
|
677
|
-
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client: n } =
|
|
678
|
-
|
|
683
|
+
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client: n } = k(), [a, c] = y(null), [u, i] = y(!1), [S, E] = y(null), _ = N(null), h = N(!1), m = A(async () => {
|
|
684
|
+
_.current && _.current.abort();
|
|
679
685
|
const o = new AbortController();
|
|
680
|
-
|
|
686
|
+
_.current = o, i(!0), E(null);
|
|
681
687
|
try {
|
|
682
688
|
let d = "";
|
|
683
|
-
for await (const
|
|
684
|
-
switch (
|
|
689
|
+
for await (const p of n.chatStream(r, { context: t, signal: o.signal }))
|
|
690
|
+
switch (p.type) {
|
|
685
691
|
case "text_delta":
|
|
686
|
-
d +=
|
|
692
|
+
d += p.content;
|
|
687
693
|
break;
|
|
688
694
|
case "error":
|
|
689
|
-
E(
|
|
695
|
+
E(p.message);
|
|
690
696
|
break;
|
|
691
697
|
default:
|
|
692
698
|
break;
|
|
@@ -695,14 +701,14 @@ function ne(s) {
|
|
|
695
701
|
} catch (d) {
|
|
696
702
|
d instanceof DOMException && d.name === "AbortError" || E(d instanceof Error ? d.message : "Unknown error");
|
|
697
703
|
} finally {
|
|
698
|
-
|
|
704
|
+
i(!1), _.current = null;
|
|
699
705
|
}
|
|
700
|
-
}, [n, r, t]),
|
|
701
|
-
|
|
702
|
-
}, [
|
|
703
|
-
return R(() => (e && !
|
|
704
|
-
|
|
705
|
-
}), [e,
|
|
706
|
+
}, [n, r, t]), f = A(() => {
|
|
707
|
+
m();
|
|
708
|
+
}, [m]);
|
|
709
|
+
return R(() => (e && !h.current && (h.current = !0, m()), () => {
|
|
710
|
+
_.current && _.current.abort();
|
|
711
|
+
}), [e, m]), { data: a, isLoading: u, error: S, refetch: f };
|
|
706
712
|
}
|
|
707
713
|
/**
|
|
708
714
|
* @license
|
|
@@ -710,36 +716,36 @@ function ne(s) {
|
|
|
710
716
|
* SPDX-License-Identifier: MIT
|
|
711
717
|
*/
|
|
712
718
|
function oe(s, r) {
|
|
713
|
-
const { key: t, refreshInterval: e = 3e4 } = r, { client: n } =
|
|
714
|
-
|
|
719
|
+
const { key: t, refreshInterval: e = 3e4 } = r, { client: n } = k(), [a, c] = y(null), [u, i] = y([]), [S, E] = y(!0), [_, h] = y(null), m = N(null), f = A(async () => {
|
|
720
|
+
m.current && m.current.abort();
|
|
715
721
|
const d = new AbortController();
|
|
716
|
-
|
|
722
|
+
m.current = d;
|
|
717
723
|
try {
|
|
718
|
-
const
|
|
719
|
-
c(
|
|
720
|
-
} catch (
|
|
721
|
-
|
|
724
|
+
const p = await n.getStoreDocument(s, t, d.signal);
|
|
725
|
+
c(p.document), i(p.history), h(null);
|
|
726
|
+
} catch (p) {
|
|
727
|
+
p instanceof DOMException && p.name === "AbortError" || h(p instanceof Error ? p.message : "Failed to fetch document");
|
|
722
728
|
} finally {
|
|
723
|
-
E(!1),
|
|
729
|
+
E(!1), m.current = null;
|
|
724
730
|
}
|
|
725
731
|
}, [n, s, t]), o = A(() => {
|
|
726
|
-
|
|
727
|
-
}, [
|
|
728
|
-
return R(() => (E(!0),
|
|
729
|
-
|
|
730
|
-
}), [
|
|
732
|
+
f();
|
|
733
|
+
}, [f]);
|
|
734
|
+
return R(() => (E(!0), f(), () => {
|
|
735
|
+
m.current && m.current.abort();
|
|
736
|
+
}), [f]), R(() => {
|
|
731
737
|
if (e <= 0) return;
|
|
732
738
|
const d = setInterval(() => {
|
|
733
|
-
|
|
739
|
+
f();
|
|
734
740
|
}, e);
|
|
735
741
|
return () => clearInterval(d);
|
|
736
|
-
}, [
|
|
742
|
+
}, [f, e]), {
|
|
737
743
|
data: (a == null ? void 0 : a.payload) ?? null,
|
|
738
744
|
meta: (a == null ? void 0 : a.meta) ?? null,
|
|
739
745
|
document: a,
|
|
740
|
-
history:
|
|
746
|
+
history: u,
|
|
741
747
|
isLoading: S,
|
|
742
|
-
error:
|
|
748
|
+
error: _,
|
|
743
749
|
refetch: o
|
|
744
750
|
};
|
|
745
751
|
}
|
|
@@ -749,10 +755,10 @@ function oe(s, r) {
|
|
|
749
755
|
* SPDX-License-Identifier: MIT
|
|
750
756
|
*/
|
|
751
757
|
function le(s, r = {}) {
|
|
752
|
-
const { filter: t, sort: e, limit: n = 20, refreshInterval: a = 3e4 } = r, { client: c } =
|
|
753
|
-
|
|
758
|
+
const { filter: t, sort: e, limit: n = 20, refreshInterval: a = 3e4 } = r, { client: c } = k(), [u, i] = y([]), [S, E] = y(0), [_, h] = y(!1), [m, f] = y(!0), [o, d] = y(null), p = N(null), l = t ? JSON.stringify(t) : "", b = A(async () => {
|
|
759
|
+
p.current && p.current.abort();
|
|
754
760
|
const x = new AbortController();
|
|
755
|
-
|
|
761
|
+
p.current = x;
|
|
756
762
|
try {
|
|
757
763
|
const C = await c.getStoreDocuments(s, {
|
|
758
764
|
filter: l ? JSON.parse(l) : void 0,
|
|
@@ -760,17 +766,17 @@ function le(s, r = {}) {
|
|
|
760
766
|
limit: n,
|
|
761
767
|
signal: x.signal
|
|
762
768
|
});
|
|
763
|
-
|
|
769
|
+
i(C.documents), E(C.total), h(C.hasMore), d(null);
|
|
764
770
|
} catch (C) {
|
|
765
771
|
C instanceof DOMException && C.name === "AbortError" || d(C instanceof Error ? C.message : "Failed to fetch store list");
|
|
766
772
|
} finally {
|
|
767
|
-
|
|
773
|
+
f(!1), p.current = null;
|
|
768
774
|
}
|
|
769
775
|
}, [c, s, l, e, n]), T = A(() => {
|
|
770
776
|
b();
|
|
771
777
|
}, [b]);
|
|
772
|
-
return R(() => (
|
|
773
|
-
|
|
778
|
+
return R(() => (f(!0), b(), () => {
|
|
779
|
+
p.current && p.current.abort();
|
|
774
780
|
}), [b]), R(() => {
|
|
775
781
|
if (a <= 0) return;
|
|
776
782
|
const x = setInterval(() => {
|
|
@@ -778,11 +784,11 @@ function le(s, r = {}) {
|
|
|
778
784
|
}, a);
|
|
779
785
|
return () => clearInterval(x);
|
|
780
786
|
}, [b, a]), {
|
|
781
|
-
data:
|
|
782
|
-
documents:
|
|
787
|
+
data: u.map((x) => x.payload),
|
|
788
|
+
documents: u,
|
|
783
789
|
total: S,
|
|
784
|
-
hasMore:
|
|
785
|
-
isLoading:
|
|
790
|
+
hasMore: _,
|
|
791
|
+
isLoading: m,
|
|
786
792
|
error: o,
|
|
787
793
|
refetch: T
|
|
788
794
|
};
|
|
@@ -793,37 +799,37 @@ function le(s, r = {}) {
|
|
|
793
799
|
* SPDX-License-Identifier: MIT
|
|
794
800
|
*/
|
|
795
801
|
function ce(s, r = {}) {
|
|
796
|
-
const { client: t } =
|
|
802
|
+
const { client: t } = k(), [e, n] = y(!1), [a, c] = y(null), [u, i] = y(null), S = N(null);
|
|
797
803
|
return { execute: A(
|
|
798
|
-
(
|
|
804
|
+
(_) => {
|
|
799
805
|
S.current && S.current.abort();
|
|
800
|
-
const
|
|
801
|
-
S.current =
|
|
802
|
-
let
|
|
803
|
-
|
|
806
|
+
const h = new AbortController();
|
|
807
|
+
S.current = h, n(!0), c(null), i(null);
|
|
808
|
+
let m = `Run skill "${s}"`;
|
|
809
|
+
_ && 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 () => {
|
|
804
810
|
try {
|
|
805
|
-
let
|
|
806
|
-
for await (const o of t.chatStream(
|
|
811
|
+
let f = "";
|
|
812
|
+
for await (const o of t.chatStream(m, { signal: h.signal }))
|
|
807
813
|
switch (o.type) {
|
|
808
814
|
case "text_delta":
|
|
809
|
-
|
|
815
|
+
f += o.content;
|
|
810
816
|
break;
|
|
811
817
|
case "error":
|
|
812
|
-
|
|
818
|
+
i(o.message);
|
|
813
819
|
break;
|
|
814
820
|
default:
|
|
815
821
|
break;
|
|
816
822
|
}
|
|
817
|
-
c(
|
|
818
|
-
} catch (
|
|
819
|
-
|
|
823
|
+
c(f);
|
|
824
|
+
} catch (f) {
|
|
825
|
+
f instanceof DOMException && f.name === "AbortError" || i(f instanceof Error ? f.message : "Skill execution failed");
|
|
820
826
|
} finally {
|
|
821
827
|
n(!1), S.current = null;
|
|
822
828
|
}
|
|
823
829
|
})();
|
|
824
830
|
},
|
|
825
831
|
[t, s, r.stores, r.confirm]
|
|
826
|
-
), loading: e, result: a, error:
|
|
832
|
+
), loading: e, result: a, error: u };
|
|
827
833
|
}
|
|
828
834
|
/**
|
|
829
835
|
* @license
|
|
@@ -832,7 +838,7 @@ function ce(s, r = {}) {
|
|
|
832
838
|
*/
|
|
833
839
|
const q = F(null);
|
|
834
840
|
function ie() {
|
|
835
|
-
const s =
|
|
841
|
+
const s = U(q), r = A((t, e) => {
|
|
836
842
|
}, []);
|
|
837
843
|
return s ?? r;
|
|
838
844
|
}
|
|
@@ -857,13 +863,13 @@ export {
|
|
|
857
863
|
we as listSessions,
|
|
858
864
|
he as mergeTheme,
|
|
859
865
|
Re as parseSSELine,
|
|
860
|
-
|
|
861
|
-
|
|
866
|
+
ke as streamChat,
|
|
867
|
+
Ie as streamSSE,
|
|
862
868
|
De as streamSSEGet,
|
|
863
869
|
Me as updateSession,
|
|
864
870
|
se as useAmodalBrief,
|
|
865
871
|
W as useAmodalChat,
|
|
866
|
-
|
|
872
|
+
k as useAmodalContext,
|
|
867
873
|
re as useAmodalInsight,
|
|
868
874
|
ne as useAmodalQuery,
|
|
869
875
|
ae as useAmodalTask,
|