@amodalai/react 0.1.16 → 0.1.18
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/client/runtime-client.d.ts +1 -13
- package/dist/client/runtime-client.d.ts.map +1 -1
- package/dist/client.js +23 -42
- package/dist/client.js.map +1 -1
- package/dist/provider.d.ts +2 -5
- package/dist/provider.d.ts.map +1 -1
- package/dist/react.css +1 -1
- package/dist/react.js +170 -170
- package/dist/react.js.map +1 -1
- package/dist/widget/MessageList.d.ts +2 -1
- package/dist/widget/MessageList.d.ts.map +1 -1
- package/dist/widget.js +563 -507
- package/dist/widget.js.map +1 -1
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { jsx as v, jsxs as
|
|
2
|
-
import { createContext as F, useMemo as B, useContext as U, useReducer as Q, useRef as N, useCallback as A, useEffect as
|
|
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
3
|
import { RuntimeClient as V } from "./client.js";
|
|
4
|
-
import { ChatClient as me, ChatStream as
|
|
4
|
+
import { ChatClient as me, ChatStream as pe } from "./client.js";
|
|
5
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
|
|
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
7
|
const j = F(null);
|
|
8
|
-
function Z({ runtimeUrl: s,
|
|
9
|
-
const
|
|
10
|
-
() => new V({ runtimeUrl: s,
|
|
11
|
-
[s, r
|
|
12
|
-
),
|
|
13
|
-
() => ({ client:
|
|
14
|
-
[
|
|
8
|
+
function Z({ runtimeUrl: s, getToken: r, children: t }) {
|
|
9
|
+
const e = B(
|
|
10
|
+
() => new V({ runtimeUrl: s, getToken: r }),
|
|
11
|
+
[s, r]
|
|
12
|
+
), o = B(
|
|
13
|
+
() => ({ client: e, runtimeUrl: s }),
|
|
14
|
+
[e, s]
|
|
15
15
|
);
|
|
16
|
-
return /* @__PURE__ */ v(j.Provider, { value:
|
|
16
|
+
return /* @__PURE__ */ v(j.Provider, { value: o, children: t });
|
|
17
17
|
}
|
|
18
|
-
function
|
|
18
|
+
function R() {
|
|
19
19
|
const s = U(j);
|
|
20
20
|
if (!s)
|
|
21
21
|
throw new Error("useAmodalContext must be used within an <AmodalProvider>");
|
|
@@ -72,26 +72,26 @@ function X(s, r) {
|
|
|
72
72
|
case "STREAM_TEXT_DELTA": {
|
|
73
73
|
const t = [...s.messages], e = t[t.length - 1];
|
|
74
74
|
if (e && e.type === "assistant_text") {
|
|
75
|
-
const
|
|
76
|
-
a && a.type === "text" ?
|
|
75
|
+
const o = [...e.contentBlocks], a = o[o.length - 1];
|
|
76
|
+
a && a.type === "text" ? o[o.length - 1] = { type: "text", text: a.text + r.content } : o.push({ type: "text", text: r.content }), t[t.length - 1] = { ...e, text: e.text + r.content, contentBlocks: o };
|
|
77
77
|
}
|
|
78
78
|
return { ...s, messages: t };
|
|
79
79
|
}
|
|
80
80
|
case "STREAM_TOOL_CALL_START": {
|
|
81
|
-
const t = [...s.messages], e = t[t.length - 1],
|
|
81
|
+
const t = [...s.messages], e = t[t.length - 1], o = {
|
|
82
82
|
toolId: r.toolId,
|
|
83
83
|
toolName: r.toolName,
|
|
84
84
|
parameters: r.parameters,
|
|
85
85
|
status: "running"
|
|
86
86
|
};
|
|
87
87
|
if (e && e.type === "assistant_text") {
|
|
88
|
-
const a = [...e.toolCalls,
|
|
89
|
-
u && u.type === "tool_calls" ? c[c.length - 1] = { type: "tool_calls", calls: [...u.calls,
|
|
88
|
+
const a = [...e.toolCalls, o], c = [...e.contentBlocks], u = c[c.length - 1];
|
|
89
|
+
u && u.type === "tool_calls" ? c[c.length - 1] = { type: "tool_calls", calls: [...u.calls, o] } : c.push({ type: "tool_calls", calls: [o] }), t[t.length - 1] = { ...e, toolCalls: a, contentBlocks: c };
|
|
90
90
|
}
|
|
91
91
|
return {
|
|
92
92
|
...s,
|
|
93
93
|
messages: t,
|
|
94
|
-
activeToolCalls: [...s.activeToolCalls,
|
|
94
|
+
activeToolCalls: [...s.activeToolCalls, o]
|
|
95
95
|
};
|
|
96
96
|
}
|
|
97
97
|
case "STREAM_TOOL_CALL_RESULT": {
|
|
@@ -109,16 +109,16 @@ function X(s, r) {
|
|
|
109
109
|
);
|
|
110
110
|
t[t.length - 1] = { ...e, toolCalls: c, contentBlocks: u };
|
|
111
111
|
}
|
|
112
|
-
const
|
|
112
|
+
const o = s.activeToolCalls.filter(
|
|
113
113
|
(a) => a.toolId !== r.toolId
|
|
114
114
|
);
|
|
115
|
-
return { ...s, messages: t, activeToolCalls:
|
|
115
|
+
return { ...s, messages: t, activeToolCalls: o };
|
|
116
116
|
}
|
|
117
117
|
case "STREAM_SUBAGENT_EVENT": {
|
|
118
118
|
const t = [...s.messages], e = t[t.length - 1];
|
|
119
119
|
if (e && e.type === "assistant_text") {
|
|
120
|
-
const
|
|
121
|
-
(u) => u.type === "tool_calls" ? { ...u, calls: u.calls.map(
|
|
120
|
+
const o = (u) => u.toolId === r.parentToolId ? { ...u, subagentEvents: [...u.subagentEvents ?? [], r.event] } : u, a = e.toolCalls.map(o), c = e.contentBlocks.map(
|
|
121
|
+
(u) => u.type === "tool_calls" ? { ...u, calls: u.calls.map(o) } : u
|
|
122
122
|
);
|
|
123
123
|
t[t.length - 1] = { ...e, toolCalls: a, contentBlocks: c };
|
|
124
124
|
}
|
|
@@ -127,14 +127,14 @@ function X(s, r) {
|
|
|
127
127
|
case "STREAM_WIDGET": {
|
|
128
128
|
const t = [...s.messages], e = t[t.length - 1];
|
|
129
129
|
if (e && e.type === "assistant_text") {
|
|
130
|
-
const
|
|
130
|
+
const o = {
|
|
131
131
|
type: "widget",
|
|
132
132
|
widgetType: r.widgetType,
|
|
133
133
|
data: r.data
|
|
134
134
|
};
|
|
135
135
|
t[t.length - 1] = {
|
|
136
136
|
...e,
|
|
137
|
-
contentBlocks: [...e.contentBlocks,
|
|
137
|
+
contentBlocks: [...e.contentBlocks, o]
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
140
|
return { ...s, messages: t };
|
|
@@ -142,14 +142,14 @@ function X(s, r) {
|
|
|
142
142
|
case "STREAM_CONFIRMATION_REQUIRED": {
|
|
143
143
|
const t = [...s.messages], e = t[t.length - 1];
|
|
144
144
|
if (e && e.type === "assistant_text") {
|
|
145
|
-
const
|
|
145
|
+
const o = {
|
|
146
146
|
type: "confirmation",
|
|
147
147
|
confirmation: r.confirmation
|
|
148
148
|
};
|
|
149
149
|
t[t.length - 1] = {
|
|
150
150
|
...e,
|
|
151
151
|
confirmations: [...e.confirmations, r.confirmation],
|
|
152
|
-
contentBlocks: [...e.contentBlocks,
|
|
152
|
+
contentBlocks: [...e.contentBlocks, o]
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
return { ...s, messages: t };
|
|
@@ -157,12 +157,12 @@ function X(s, r) {
|
|
|
157
157
|
case "CONFIRMATION_RESPONDED": {
|
|
158
158
|
const t = [...s.messages], e = t[t.length - 1];
|
|
159
159
|
if (e && e.type === "assistant_text") {
|
|
160
|
-
const
|
|
160
|
+
const o = e.confirmations.map(
|
|
161
161
|
(c) => c.correlationId === r.correlationId ? { ...c, status: r.approved ? "approved" : "denied" } : c
|
|
162
162
|
), a = e.contentBlocks.map(
|
|
163
163
|
(c) => c.type === "confirmation" && c.confirmation.correlationId === r.correlationId ? { ...c, confirmation: { ...c.confirmation, status: r.approved ? "approved" : "denied" } } : c
|
|
164
164
|
);
|
|
165
|
-
t[t.length - 1] = { ...e, confirmations:
|
|
165
|
+
t[t.length - 1] = { ...e, confirmations: o, contentBlocks: a };
|
|
166
166
|
}
|
|
167
167
|
return { ...s, messages: t };
|
|
168
168
|
}
|
|
@@ -176,8 +176,8 @@ function X(s, r) {
|
|
|
176
176
|
);
|
|
177
177
|
t[t.length - 1] = { ...e, toolCalls: c, contentBlocks: u };
|
|
178
178
|
}
|
|
179
|
-
const
|
|
180
|
-
return { ...s, messages: t, isStreaming: !1, activeToolCalls: [], usage:
|
|
179
|
+
const o = 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: o };
|
|
181
181
|
}
|
|
182
182
|
case "RESET":
|
|
183
183
|
return { ...G };
|
|
@@ -186,26 +186,26 @@ function X(s, r) {
|
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
function W(s) {
|
|
189
|
-
const { client: r } =
|
|
190
|
-
c.current = s,
|
|
189
|
+
const { client: r } = R(), [t, e] = Q(X, G), o = N((s == null ? void 0 : s.initialSessionId) ?? null), a = N(null), c = N(s);
|
|
190
|
+
c.current = s, o.current = t.sessionId ?? o.current;
|
|
191
191
|
const u = A(
|
|
192
192
|
(_) => {
|
|
193
193
|
if (t.isStreaming) return;
|
|
194
194
|
e({ type: "SEND_MESSAGE", text: _ });
|
|
195
195
|
const h = new AbortController();
|
|
196
196
|
a.current = h, (async () => {
|
|
197
|
-
var
|
|
198
|
-
let
|
|
197
|
+
var n, d, f, l, b, T, x, C, M, D, O;
|
|
198
|
+
let p = !1;
|
|
199
199
|
try {
|
|
200
|
-
const
|
|
201
|
-
sessionId:
|
|
202
|
-
context: (
|
|
200
|
+
const k = r.chatStream(_, {
|
|
201
|
+
sessionId: o.current ?? void 0,
|
|
202
|
+
context: (n = c.current) == null ? void 0 : n.context,
|
|
203
203
|
signal: h.signal
|
|
204
204
|
});
|
|
205
|
-
for await (const g of
|
|
205
|
+
for await (const g of k)
|
|
206
206
|
switch (g.type) {
|
|
207
207
|
case "init":
|
|
208
|
-
e({ type: "STREAM_INIT", sessionId: g.session_id }), (
|
|
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
209
|
break;
|
|
210
210
|
case "text_delta":
|
|
211
211
|
e({ type: "STREAM_TEXT_DELTA", content: g.content });
|
|
@@ -278,7 +278,7 @@ function W(s) {
|
|
|
278
278
|
e({ type: "STREAM_ERROR", message: g.message });
|
|
279
279
|
break;
|
|
280
280
|
case "done":
|
|
281
|
-
|
|
281
|
+
p = !0, e({
|
|
282
282
|
type: "STREAM_DONE",
|
|
283
283
|
usage: g.usage ? { inputTokens: g.usage.input_tokens, outputTokens: g.usage.output_tokens } : void 0
|
|
284
284
|
}), (M = (C = c.current) == null ? void 0 : C.onStreamEnd) == null || M.call(C);
|
|
@@ -286,13 +286,13 @@ function W(s) {
|
|
|
286
286
|
default:
|
|
287
287
|
break;
|
|
288
288
|
}
|
|
289
|
-
} catch (
|
|
290
|
-
|
|
289
|
+
} catch (k) {
|
|
290
|
+
k instanceof DOMException && k.name === "AbortError" || e({
|
|
291
291
|
type: "STREAM_ERROR",
|
|
292
|
-
message:
|
|
292
|
+
message: k instanceof Error ? k.message : "Unknown error"
|
|
293
293
|
});
|
|
294
294
|
} finally {
|
|
295
|
-
a.current = null, !
|
|
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
296
|
}
|
|
297
297
|
})();
|
|
298
298
|
},
|
|
@@ -309,7 +309,7 @@ function W(s) {
|
|
|
309
309
|
},
|
|
310
310
|
[u, t.isStreaming]
|
|
311
311
|
);
|
|
312
|
-
return
|
|
312
|
+
return w(
|
|
313
313
|
() => () => {
|
|
314
314
|
a.current && a.current.abort();
|
|
315
315
|
},
|
|
@@ -334,13 +334,13 @@ function W(s) {
|
|
|
334
334
|
*/
|
|
335
335
|
function H({ confirmation: s, onApprove: r, onDeny: t }) {
|
|
336
336
|
const e = s.status === "pending";
|
|
337
|
-
return /* @__PURE__ */
|
|
338
|
-
/* @__PURE__ */
|
|
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
339
|
/* @__PURE__ */ v("span", { className: "amodal-confirm-card__method", children: s.method }),
|
|
340
340
|
/* @__PURE__ */ v("span", { className: "amodal-confirm-card__endpoint", children: s.endpoint })
|
|
341
341
|
] }),
|
|
342
342
|
/* @__PURE__ */ v("p", { className: "amodal-confirm-card__reason", children: s.reason }),
|
|
343
|
-
e ? /* @__PURE__ */
|
|
343
|
+
e ? /* @__PURE__ */ I("div", { className: "amodal-confirm-card__actions", children: [
|
|
344
344
|
/* @__PURE__ */ v(
|
|
345
345
|
"button",
|
|
346
346
|
{
|
|
@@ -369,22 +369,22 @@ function H({ confirmation: s, onApprove: r, onDeny: t }) {
|
|
|
369
369
|
*/
|
|
370
370
|
function J({ confirmation: s, onApprove: r, onDeny: t }) {
|
|
371
371
|
const e = s.status === "pending";
|
|
372
|
-
return /* @__PURE__ */
|
|
373
|
-
/* @__PURE__ */
|
|
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
374
|
/* @__PURE__ */ v("span", { className: "amodal-review-card__method", children: s.method }),
|
|
375
375
|
/* @__PURE__ */ v("span", { className: "amodal-review-card__endpoint", children: s.endpoint }),
|
|
376
376
|
s.escalated && /* @__PURE__ */ v("span", { className: "amodal-review-card__badge", "data-testid": "escalation-badge", children: "Escalated" })
|
|
377
377
|
] }),
|
|
378
|
-
s.connectionName && /* @__PURE__ */
|
|
378
|
+
s.connectionName && /* @__PURE__ */ I("div", { className: "amodal-review-card__connection", children: [
|
|
379
379
|
"Connection: ",
|
|
380
380
|
s.connectionName
|
|
381
381
|
] }),
|
|
382
382
|
/* @__PURE__ */ v("p", { className: "amodal-review-card__reason", children: s.reason }),
|
|
383
|
-
s.params && Object.keys(s.params).length > 0 && /* @__PURE__ */
|
|
383
|
+
s.params && Object.keys(s.params).length > 0 && /* @__PURE__ */ I("div", { className: "amodal-review-card__params", "data-testid": "review-params", children: [
|
|
384
384
|
/* @__PURE__ */ v("div", { className: "amodal-review-card__params-title", children: "Parameters" }),
|
|
385
385
|
/* @__PURE__ */ v("pre", { className: "amodal-review-card__params-body", children: JSON.stringify(s.params, null, 2) })
|
|
386
386
|
] }),
|
|
387
|
-
e ? /* @__PURE__ */
|
|
387
|
+
e ? /* @__PURE__ */ I("div", { className: "amodal-review-card__actions", children: [
|
|
388
388
|
/* @__PURE__ */ v(
|
|
389
389
|
"button",
|
|
390
390
|
{
|
|
@@ -411,64 +411,64 @@ function ee({
|
|
|
411
411
|
renderText: r,
|
|
412
412
|
renderToolCall: t,
|
|
413
413
|
renderConfirmation: e,
|
|
414
|
-
className:
|
|
414
|
+
className: o,
|
|
415
415
|
...a
|
|
416
416
|
}) {
|
|
417
417
|
const { messages: c, send: u, isStreaming: i, respondToConfirmation: S } = W(a), [E, _] = y(""), h = N(null), m = A(
|
|
418
|
-
(
|
|
419
|
-
|
|
418
|
+
(n) => {
|
|
419
|
+
n.preventDefault();
|
|
420
420
|
const d = E.trim();
|
|
421
421
|
d.length === 0 || i || (_(""), u(d));
|
|
422
422
|
},
|
|
423
423
|
[E, i, u]
|
|
424
|
-
),
|
|
425
|
-
return /* @__PURE__ */
|
|
426
|
-
/* @__PURE__ */
|
|
427
|
-
c.map((
|
|
428
|
-
switch (
|
|
424
|
+
), p = ["amodal-chat", o].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((n) => {
|
|
428
|
+
switch (n.type) {
|
|
429
429
|
case "user":
|
|
430
|
-
return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--user", "data-testid": "user-message", children:
|
|
430
|
+
return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--user", "data-testid": "user-message", children: n.text }, n.id);
|
|
431
431
|
case "assistant_text":
|
|
432
|
-
return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--assistant", "data-testid": "assistant-message", children:
|
|
432
|
+
return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--assistant", "data-testid": "assistant-message", children: n.contentBlocks.map((d, f) => {
|
|
433
433
|
switch (d.type) {
|
|
434
434
|
case "text":
|
|
435
|
-
return /* @__PURE__ */ v("div", { className: "amodal-chat__text", children: r ? r(d.text) : d.text }, `text-${String(
|
|
435
|
+
return /* @__PURE__ */ v("div", { className: "amodal-chat__text", children: r ? r(d.text) : d.text }, `text-${String(f)}`);
|
|
436
436
|
case "tool_calls":
|
|
437
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__ */
|
|
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
439
|
/* @__PURE__ */ v("span", { className: "amodal-chat__tool-name", children: l.toolName }),
|
|
440
440
|
/* @__PURE__ */ v("span", { className: "amodal-chat__tool-status", children: l.status })
|
|
441
441
|
] }, l.toolId)
|
|
442
|
-
) }, `tools-${String(
|
|
442
|
+
) }, `tools-${String(f)}`);
|
|
443
443
|
case "confirmation": {
|
|
444
444
|
const l = d.confirmation, b = () => {
|
|
445
445
|
l.correlationId && S(l.correlationId, !0);
|
|
446
446
|
}, T = () => {
|
|
447
447
|
l.correlationId && S(l.correlationId, !1);
|
|
448
448
|
};
|
|
449
|
-
return e ? /* @__PURE__ */ v("div", { children: e(l, b, T) }, `conf-${String(
|
|
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)}`);
|
|
450
450
|
}
|
|
451
451
|
case "widget":
|
|
452
|
-
return /* @__PURE__ */ v("div", { className: "amodal-chat__widget", "data-testid": "widget", children: d.widgetType }, `widget-${String(
|
|
452
|
+
return /* @__PURE__ */ v("div", { className: "amodal-chat__widget", "data-testid": "widget", children: d.widgetType }, `widget-${String(f)}`);
|
|
453
453
|
default:
|
|
454
454
|
return null;
|
|
455
455
|
}
|
|
456
|
-
}) },
|
|
456
|
+
}) }, n.id);
|
|
457
457
|
case "error":
|
|
458
|
-
return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--error", "data-testid": "error-message", children:
|
|
458
|
+
return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--error", "data-testid": "error-message", children: n.message }, n.id);
|
|
459
459
|
default:
|
|
460
460
|
return null;
|
|
461
461
|
}
|
|
462
462
|
}),
|
|
463
463
|
/* @__PURE__ */ v("div", { ref: h })
|
|
464
464
|
] }),
|
|
465
|
-
/* @__PURE__ */
|
|
465
|
+
/* @__PURE__ */ I("form", { className: "amodal-chat__input-bar", onSubmit: m, "data-testid": "input-bar", children: [
|
|
466
466
|
/* @__PURE__ */ v(
|
|
467
467
|
"input",
|
|
468
468
|
{
|
|
469
469
|
className: "amodal-chat__input",
|
|
470
470
|
value: E,
|
|
471
|
-
onChange: (
|
|
471
|
+
onChange: (n) => _(n.target.value),
|
|
472
472
|
placeholder: s,
|
|
473
473
|
disabled: i,
|
|
474
474
|
"data-testid": "chat-input"
|
|
@@ -487,43 +487,43 @@ function ee({
|
|
|
487
487
|
] })
|
|
488
488
|
] });
|
|
489
489
|
}
|
|
490
|
-
function te({ prompt: s, label: r, context: t, onComplete: e, onError:
|
|
490
|
+
function te({ prompt: s, label: r, context: t, onComplete: e, onError: o }) {
|
|
491
491
|
const [a, c] = y(!1), { messages: u, send: i, isStreaming: S, respondToConfirmation: E } = W({
|
|
492
492
|
context: t,
|
|
493
493
|
onStreamEnd: () => {
|
|
494
|
-
const
|
|
495
|
-
|
|
494
|
+
const n = u[u.length - 1];
|
|
495
|
+
n && n.type === "assistant_text" ? e == null || e(n.text) : n && n.type === "error" && (o == null || o(n.message));
|
|
496
496
|
}
|
|
497
497
|
}), _ = A(() => {
|
|
498
498
|
a || S || (c(!0), i(s));
|
|
499
|
-
}, [a, S, i, s]), h = [...u].reverse().find((
|
|
500
|
-
const
|
|
501
|
-
|
|
499
|
+
}, [a, S, i, s]), h = [...u].reverse().find((n) => n.type === "assistant_text"), m = h && h.type === "assistant_text" ? h.confirmations.filter((n) => n.status === "pending") : [], p = (n, d) => {
|
|
500
|
+
const f = () => {
|
|
501
|
+
n.correlationId && E(n.correlationId, !0);
|
|
502
502
|
}, l = () => {
|
|
503
|
-
|
|
503
|
+
n.correlationId && E(n.correlationId, !1);
|
|
504
504
|
};
|
|
505
|
-
return
|
|
505
|
+
return n.escalated || n.params && Object.keys(n.params).length > 0 ? /* @__PURE__ */ v(
|
|
506
506
|
J,
|
|
507
507
|
{
|
|
508
|
-
confirmation:
|
|
509
|
-
onApprove:
|
|
508
|
+
confirmation: n,
|
|
509
|
+
onApprove: f,
|
|
510
510
|
onDeny: l
|
|
511
511
|
},
|
|
512
|
-
|
|
512
|
+
n.correlationId ?? String(d)
|
|
513
513
|
) : /* @__PURE__ */ v(
|
|
514
514
|
H,
|
|
515
515
|
{
|
|
516
|
-
confirmation:
|
|
517
|
-
onApprove:
|
|
516
|
+
confirmation: n,
|
|
517
|
+
onApprove: f,
|
|
518
518
|
onDeny: l
|
|
519
519
|
},
|
|
520
|
-
|
|
520
|
+
n.correlationId ?? String(d)
|
|
521
521
|
);
|
|
522
522
|
};
|
|
523
|
-
return a ? /* @__PURE__ */
|
|
523
|
+
return a ? /* @__PURE__ */ I("div", { className: "amodal-action", "data-testid": "action-container", children: [
|
|
524
524
|
S && /* @__PURE__ */ v("div", { className: "amodal-action__loading", "data-testid": "action-loading", children: "Processing..." }),
|
|
525
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(
|
|
526
|
+
m.map(p)
|
|
527
527
|
] }) : /* @__PURE__ */ v(
|
|
528
528
|
"button",
|
|
529
529
|
{
|
|
@@ -540,20 +540,20 @@ function te({ prompt: s, label: r, context: t, onComplete: e, onError: n }) {
|
|
|
540
540
|
* SPDX-License-Identifier: MIT
|
|
541
541
|
*/
|
|
542
542
|
function se(s) {
|
|
543
|
-
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client:
|
|
543
|
+
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client: o } = R(), [a, c] = y(null), [u, i] = y(!1), [S, E] = y(null), _ = N(null), h = N(!1), m = A(async () => {
|
|
544
544
|
_.current && _.current.abort();
|
|
545
|
-
const
|
|
546
|
-
_.current =
|
|
545
|
+
const n = new AbortController();
|
|
546
|
+
_.current = n, i(!0), E(null);
|
|
547
547
|
try {
|
|
548
548
|
let d = "";
|
|
549
|
-
const
|
|
550
|
-
for await (const l of
|
|
549
|
+
const f = [];
|
|
550
|
+
for await (const l of o.chatStream(r, { context: t, signal: n.signal }))
|
|
551
551
|
switch (l.type) {
|
|
552
552
|
case "text_delta":
|
|
553
553
|
d += l.content;
|
|
554
554
|
break;
|
|
555
555
|
case "tool_call_start":
|
|
556
|
-
|
|
556
|
+
f.push({
|
|
557
557
|
toolId: l.tool_id,
|
|
558
558
|
toolName: l.tool_name,
|
|
559
559
|
parameters: l.parameters,
|
|
@@ -561,7 +561,7 @@ function se(s) {
|
|
|
561
561
|
});
|
|
562
562
|
break;
|
|
563
563
|
case "tool_call_result": {
|
|
564
|
-
const b =
|
|
564
|
+
const b = f.find((T) => T.toolId === l.tool_id);
|
|
565
565
|
b && (b.status = l.status, b.result = l.result, b.duration_ms = l.duration_ms, b.error = l.error);
|
|
566
566
|
break;
|
|
567
567
|
}
|
|
@@ -571,18 +571,18 @@ function se(s) {
|
|
|
571
571
|
default:
|
|
572
572
|
break;
|
|
573
573
|
}
|
|
574
|
-
c({ text: d, toolCalls:
|
|
574
|
+
c({ text: d, toolCalls: f });
|
|
575
575
|
} catch (d) {
|
|
576
576
|
d instanceof DOMException && d.name === "AbortError" || E(d instanceof Error ? d.message : "Unknown error");
|
|
577
577
|
} finally {
|
|
578
578
|
i(!1), _.current = null;
|
|
579
579
|
}
|
|
580
|
-
}, [
|
|
580
|
+
}, [o, r, t]), p = A(() => {
|
|
581
581
|
m();
|
|
582
582
|
}, [m]);
|
|
583
|
-
return
|
|
583
|
+
return w(() => (e && !h.current && (h.current = !0, m()), () => {
|
|
584
584
|
_.current && _.current.abort();
|
|
585
|
-
}), [e, m]), { brief: a, isLoading: u, error: S, refresh:
|
|
585
|
+
}), [e, m]), { brief: a, isLoading: u, error: S, refresh: p };
|
|
586
586
|
}
|
|
587
587
|
/**
|
|
588
588
|
* @license
|
|
@@ -590,13 +590,13 @@ function se(s) {
|
|
|
590
590
|
* SPDX-License-Identifier: MIT
|
|
591
591
|
*/
|
|
592
592
|
function re(s) {
|
|
593
|
-
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client:
|
|
593
|
+
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client: o } = R(), [a, c] = y("idle"), [u, i] = y(""), [S, E] = y(""), [_, h] = y(null), m = N(null), p = N(!1), n = A(async () => {
|
|
594
594
|
m.current && m.current.abort();
|
|
595
|
-
const
|
|
596
|
-
m.current =
|
|
595
|
+
const f = new AbortController();
|
|
596
|
+
m.current = f, c("loading"), h(null), i(""), E("");
|
|
597
597
|
try {
|
|
598
598
|
let l = "";
|
|
599
|
-
for await (const T of
|
|
599
|
+
for await (const T of o.chatStream(r, { context: t, signal: f.signal }))
|
|
600
600
|
switch (T.type) {
|
|
601
601
|
case "text_delta":
|
|
602
602
|
l += T.content;
|
|
@@ -616,12 +616,12 @@ function re(s) {
|
|
|
616
616
|
} finally {
|
|
617
617
|
m.current = null;
|
|
618
618
|
}
|
|
619
|
-
}, [
|
|
620
|
-
|
|
621
|
-
}, [
|
|
622
|
-
return
|
|
619
|
+
}, [o, r, t]), d = A(() => {
|
|
620
|
+
n();
|
|
621
|
+
}, [n]);
|
|
622
|
+
return w(() => (e && !p.current && (p.current = !0, n()), () => {
|
|
623
623
|
m.current && m.current.abort();
|
|
624
|
-
}), [e,
|
|
624
|
+
}), [e, n]), { status: a, summary: u, details: S, isLoading: a === "loading", error: _, refresh: d };
|
|
625
625
|
}
|
|
626
626
|
/**
|
|
627
627
|
* @license
|
|
@@ -629,10 +629,10 @@ function re(s) {
|
|
|
629
629
|
* SPDX-License-Identifier: MIT
|
|
630
630
|
*/
|
|
631
631
|
function ae(s) {
|
|
632
|
-
const { taskId: r, autoStream: t = !0 } = s, { client: e } =
|
|
633
|
-
|
|
632
|
+
const { taskId: r, autoStream: t = !0 } = s, { client: e } = R(), [o, a] = y("idle"), [c, u] = y(""), [i, S] = y(""), [E, _] = y([]), [h, m] = y(null), p = N(null), n = N(!1), d = A(async () => {
|
|
633
|
+
p.current && p.current.abort();
|
|
634
634
|
const b = new AbortController();
|
|
635
|
-
|
|
635
|
+
p.current = b, a("running"), m(null), _([]), S(""), u("");
|
|
636
636
|
try {
|
|
637
637
|
let T = "";
|
|
638
638
|
for await (const x of e.streamTask(r, b.signal))
|
|
@@ -655,25 +655,25 @@ function ae(s) {
|
|
|
655
655
|
default:
|
|
656
656
|
break;
|
|
657
657
|
}
|
|
658
|
-
|
|
658
|
+
o === "running" && a("completed");
|
|
659
659
|
} catch (T) {
|
|
660
660
|
T instanceof DOMException && T.name === "AbortError" || (m(T instanceof Error ? T.message : "Unknown error"), a("error"));
|
|
661
661
|
} finally {
|
|
662
|
-
|
|
662
|
+
p.current = null;
|
|
663
663
|
}
|
|
664
|
-
}, [e, r,
|
|
665
|
-
|
|
664
|
+
}, [e, r, o]), f = A(() => {
|
|
665
|
+
p.current && (p.current.abort(), p.current = null);
|
|
666
666
|
}, []), l = N(d);
|
|
667
|
-
return l.current = d,
|
|
668
|
-
|
|
667
|
+
return l.current = d, w(() => (t && !n.current && (n.current = !0, l.current()), () => {
|
|
668
|
+
p.current && p.current.abort();
|
|
669
669
|
}), [t]), {
|
|
670
|
-
status:
|
|
670
|
+
status: o,
|
|
671
671
|
progress: c,
|
|
672
672
|
result: i,
|
|
673
673
|
events: E,
|
|
674
674
|
error: h,
|
|
675
675
|
start: () => void d(),
|
|
676
|
-
stop:
|
|
676
|
+
stop: f
|
|
677
677
|
};
|
|
678
678
|
}
|
|
679
679
|
/**
|
|
@@ -682,19 +682,19 @@ function ae(s) {
|
|
|
682
682
|
* SPDX-License-Identifier: MIT
|
|
683
683
|
*/
|
|
684
684
|
function ne(s) {
|
|
685
|
-
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client:
|
|
685
|
+
const { prompt: r, context: t, autoFetch: e = !0 } = s, { client: o } = R(), [a, c] = y(null), [u, i] = y(!1), [S, E] = y(null), _ = N(null), h = N(!1), m = A(async () => {
|
|
686
686
|
_.current && _.current.abort();
|
|
687
|
-
const
|
|
688
|
-
_.current =
|
|
687
|
+
const n = new AbortController();
|
|
688
|
+
_.current = n, i(!0), E(null);
|
|
689
689
|
try {
|
|
690
690
|
let d = "";
|
|
691
|
-
for await (const
|
|
692
|
-
switch (
|
|
691
|
+
for await (const f of o.chatStream(r, { context: t, signal: n.signal }))
|
|
692
|
+
switch (f.type) {
|
|
693
693
|
case "text_delta":
|
|
694
|
-
d +=
|
|
694
|
+
d += f.content;
|
|
695
695
|
break;
|
|
696
696
|
case "error":
|
|
697
|
-
E(
|
|
697
|
+
E(f.message);
|
|
698
698
|
break;
|
|
699
699
|
default:
|
|
700
700
|
break;
|
|
@@ -705,12 +705,12 @@ function ne(s) {
|
|
|
705
705
|
} finally {
|
|
706
706
|
i(!1), _.current = null;
|
|
707
707
|
}
|
|
708
|
-
}, [
|
|
708
|
+
}, [o, r, t]), p = A(() => {
|
|
709
709
|
m();
|
|
710
710
|
}, [m]);
|
|
711
|
-
return
|
|
711
|
+
return w(() => (e && !h.current && (h.current = !0, m()), () => {
|
|
712
712
|
_.current && _.current.abort();
|
|
713
|
-
}), [e, m]), { data: a, isLoading: u, error: S, refetch:
|
|
713
|
+
}), [e, m]), { data: a, isLoading: u, error: S, refetch: p };
|
|
714
714
|
}
|
|
715
715
|
/**
|
|
716
716
|
* @license
|
|
@@ -718,37 +718,37 @@ function ne(s) {
|
|
|
718
718
|
* SPDX-License-Identifier: MIT
|
|
719
719
|
*/
|
|
720
720
|
function oe(s, r) {
|
|
721
|
-
const { key: t, refreshInterval: e = 3e4 } = r, { client:
|
|
721
|
+
const { key: t, refreshInterval: e = 3e4 } = r, { client: o } = R(), [a, c] = y(null), [u, i] = y([]), [S, E] = y(!0), [_, h] = y(null), m = N(null), p = A(async () => {
|
|
722
722
|
m.current && m.current.abort();
|
|
723
723
|
const d = new AbortController();
|
|
724
724
|
m.current = d;
|
|
725
725
|
try {
|
|
726
|
-
const
|
|
727
|
-
c(
|
|
728
|
-
} catch (
|
|
729
|
-
|
|
726
|
+
const f = await o.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");
|
|
730
730
|
} finally {
|
|
731
731
|
E(!1), m.current = null;
|
|
732
732
|
}
|
|
733
|
-
}, [
|
|
734
|
-
|
|
735
|
-
}, [
|
|
736
|
-
return
|
|
733
|
+
}, [o, s, t]), n = A(() => {
|
|
734
|
+
p();
|
|
735
|
+
}, [p]);
|
|
736
|
+
return w(() => (E(!0), p(), () => {
|
|
737
737
|
m.current && m.current.abort();
|
|
738
|
-
}), [
|
|
738
|
+
}), [p]), w(() => {
|
|
739
739
|
if (e <= 0) return;
|
|
740
740
|
const d = setInterval(() => {
|
|
741
|
-
|
|
741
|
+
p();
|
|
742
742
|
}, e);
|
|
743
743
|
return () => clearInterval(d);
|
|
744
|
-
}, [
|
|
744
|
+
}, [p, e]), {
|
|
745
745
|
data: (a == null ? void 0 : a.payload) ?? null,
|
|
746
746
|
meta: (a == null ? void 0 : a.meta) ?? null,
|
|
747
747
|
document: a,
|
|
748
748
|
history: u,
|
|
749
749
|
isLoading: S,
|
|
750
750
|
error: _,
|
|
751
|
-
refetch:
|
|
751
|
+
refetch: n
|
|
752
752
|
};
|
|
753
753
|
}
|
|
754
754
|
/**
|
|
@@ -757,29 +757,29 @@ function oe(s, r) {
|
|
|
757
757
|
* SPDX-License-Identifier: MIT
|
|
758
758
|
*/
|
|
759
759
|
function le(s, r = {}) {
|
|
760
|
-
const { filter: t, sort: e, limit:
|
|
761
|
-
|
|
760
|
+
const { filter: t, sort: e, limit: o = 20, refreshInterval: a = 3e4 } = r, { client: c } = R(), [u, i] = y([]), [S, E] = y(0), [_, h] = y(!1), [m, p] = y(!0), [n, d] = y(null), f = N(null), l = t ? JSON.stringify(t) : "", b = A(async () => {
|
|
761
|
+
f.current && f.current.abort();
|
|
762
762
|
const x = new AbortController();
|
|
763
|
-
|
|
763
|
+
f.current = x;
|
|
764
764
|
try {
|
|
765
765
|
const C = await c.getStoreDocuments(s, {
|
|
766
766
|
filter: l ? JSON.parse(l) : void 0,
|
|
767
767
|
sort: e,
|
|
768
|
-
limit:
|
|
768
|
+
limit: o,
|
|
769
769
|
signal: x.signal
|
|
770
770
|
});
|
|
771
771
|
i(C.documents), E(C.total), h(C.hasMore), d(null);
|
|
772
772
|
} catch (C) {
|
|
773
773
|
C instanceof DOMException && C.name === "AbortError" || d(C instanceof Error ? C.message : "Failed to fetch store list");
|
|
774
774
|
} finally {
|
|
775
|
-
|
|
775
|
+
p(!1), f.current = null;
|
|
776
776
|
}
|
|
777
|
-
}, [c, s, l, e,
|
|
777
|
+
}, [c, s, l, e, o]), T = A(() => {
|
|
778
778
|
b();
|
|
779
779
|
}, [b]);
|
|
780
|
-
return
|
|
781
|
-
|
|
782
|
-
}), [b]),
|
|
780
|
+
return w(() => (p(!0), b(), () => {
|
|
781
|
+
f.current && f.current.abort();
|
|
782
|
+
}), [b]), w(() => {
|
|
783
783
|
if (a <= 0) return;
|
|
784
784
|
const x = setInterval(() => {
|
|
785
785
|
b();
|
|
@@ -791,7 +791,7 @@ function le(s, r = {}) {
|
|
|
791
791
|
total: S,
|
|
792
792
|
hasMore: _,
|
|
793
793
|
isLoading: m,
|
|
794
|
-
error:
|
|
794
|
+
error: n,
|
|
795
795
|
refetch: T
|
|
796
796
|
};
|
|
797
797
|
}
|
|
@@ -801,32 +801,32 @@ function le(s, r = {}) {
|
|
|
801
801
|
* SPDX-License-Identifier: MIT
|
|
802
802
|
*/
|
|
803
803
|
function ce(s, r = {}) {
|
|
804
|
-
const { client: t } =
|
|
804
|
+
const { client: t } = R(), [e, o] = y(!1), [a, c] = y(null), [u, i] = y(null), S = N(null);
|
|
805
805
|
return { execute: A(
|
|
806
806
|
(_) => {
|
|
807
807
|
S.current && S.current.abort();
|
|
808
808
|
const h = new AbortController();
|
|
809
|
-
S.current = h,
|
|
809
|
+
S.current = h, o(!0), c(null), i(null);
|
|
810
810
|
let m = `Run skill "${s}"`;
|
|
811
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 () => {
|
|
812
812
|
try {
|
|
813
|
-
let
|
|
814
|
-
for await (const
|
|
815
|
-
switch (
|
|
813
|
+
let p = "";
|
|
814
|
+
for await (const n of t.chatStream(m, { signal: h.signal }))
|
|
815
|
+
switch (n.type) {
|
|
816
816
|
case "text_delta":
|
|
817
|
-
|
|
817
|
+
p += n.content;
|
|
818
818
|
break;
|
|
819
819
|
case "error":
|
|
820
|
-
i(
|
|
820
|
+
i(n.message);
|
|
821
821
|
break;
|
|
822
822
|
default:
|
|
823
823
|
break;
|
|
824
824
|
}
|
|
825
|
-
c(
|
|
826
|
-
} catch (
|
|
827
|
-
|
|
825
|
+
c(p);
|
|
826
|
+
} catch (p) {
|
|
827
|
+
p instanceof DOMException && p.name === "AbortError" || i(p instanceof Error ? p.message : "Skill execution failed");
|
|
828
828
|
} finally {
|
|
829
|
-
|
|
829
|
+
o(!1), S.current = null;
|
|
830
830
|
}
|
|
831
831
|
})();
|
|
832
832
|
},
|
|
@@ -849,7 +849,7 @@ export {
|
|
|
849
849
|
ee as AmodalChat,
|
|
850
850
|
Z as AmodalProvider,
|
|
851
851
|
me as ChatClient,
|
|
852
|
-
|
|
852
|
+
pe as ChatStream,
|
|
853
853
|
H as ConfirmCard,
|
|
854
854
|
q as NavigateContext,
|
|
855
855
|
J as ReviewCard,
|
|
@@ -862,16 +862,16 @@ export {
|
|
|
862
862
|
xe as defaultEntityExtractor,
|
|
863
863
|
_e as defaultTheme,
|
|
864
864
|
Ce as getSessionHistory,
|
|
865
|
-
|
|
865
|
+
Ie as listSessions,
|
|
866
866
|
he as mergeTheme,
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
867
|
+
we as parseSSELine,
|
|
868
|
+
Re as streamChat,
|
|
869
|
+
ke as streamSSE,
|
|
870
870
|
De as streamSSEGet,
|
|
871
871
|
Me as updateSession,
|
|
872
872
|
se as useAmodalBrief,
|
|
873
873
|
W as useAmodalChat,
|
|
874
|
-
|
|
874
|
+
R as useAmodalContext,
|
|
875
875
|
re as useAmodalInsight,
|
|
876
876
|
ne as useAmodalQuery,
|
|
877
877
|
ae as useAmodalTask,
|