@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/{event-bus-h26clqbZ.js → chat-api-CqMQa8r3.js} +85 -85
- package/dist/chat-api-CqMQa8r3.js.map +1 -0
- package/dist/client.js +2 -2
- package/dist/hooks/useAmodalChat.d.ts +2 -2
- package/dist/hooks/useAmodalChat.d.ts.map +1 -1
- package/dist/hooks/useChat.d.ts +2 -2
- package/dist/hooks/useChat.d.ts.map +1 -1
- package/dist/hooks/useChatStream.d.ts +47 -0
- package/dist/hooks/useChatStream.d.ts.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/react.js +373 -638
- package/dist/react.js.map +1 -1
- package/dist/theme-C051UgQ1.js +801 -0
- package/dist/theme-C051UgQ1.js.map +1 -0
- package/dist/types.d.ts +19 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/widget.js +3 -3
- package/package.json +1 -1
- package/dist/event-bus-h26clqbZ.js.map +0 -1
- package/dist/theme-VAUsolBG.js +0 -693
- package/dist/theme-VAUsolBG.js.map +0 -1
|
@@ -0,0 +1,801 @@
|
|
|
1
|
+
import { useReducer as V, useRef as S, useCallback as R, useEffect as M, useState as L } from "react";
|
|
2
|
+
import { W as G, s as $, g as q, l as W, u as U } from "./chat-api-CqMQa8r3.js";
|
|
3
|
+
/**
|
|
4
|
+
* @license
|
|
5
|
+
* Copyright 2026 Amodal Labs, Inc.
|
|
6
|
+
* SPDX-License-Identifier: MIT
|
|
7
|
+
*/
|
|
8
|
+
const k = {
|
|
9
|
+
messages: [],
|
|
10
|
+
sessionId: null,
|
|
11
|
+
isStreaming: !1,
|
|
12
|
+
error: null,
|
|
13
|
+
activeToolCalls: [],
|
|
14
|
+
isHistorical: !1,
|
|
15
|
+
usage: { inputTokens: 0, outputTokens: 0 }
|
|
16
|
+
};
|
|
17
|
+
let P = 0;
|
|
18
|
+
function F() {
|
|
19
|
+
return P++, `msg-${Date.now()}-${String(P)}`;
|
|
20
|
+
}
|
|
21
|
+
function z(t, o) {
|
|
22
|
+
switch (o.type) {
|
|
23
|
+
case "SEND_MESSAGE": {
|
|
24
|
+
const s = {
|
|
25
|
+
type: "user",
|
|
26
|
+
id: F(),
|
|
27
|
+
text: o.text,
|
|
28
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
29
|
+
}, e = {
|
|
30
|
+
type: "assistant_text",
|
|
31
|
+
id: F(),
|
|
32
|
+
text: "",
|
|
33
|
+
toolCalls: [],
|
|
34
|
+
confirmations: [],
|
|
35
|
+
skillActivations: [],
|
|
36
|
+
kbProposals: [],
|
|
37
|
+
widgets: [],
|
|
38
|
+
contentBlocks: [],
|
|
39
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
...t,
|
|
43
|
+
messages: [...t.messages, s, e],
|
|
44
|
+
isStreaming: !0,
|
|
45
|
+
error: null,
|
|
46
|
+
activeToolCalls: [],
|
|
47
|
+
isHistorical: !1
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
case "STREAM_INIT":
|
|
51
|
+
return { ...t, sessionId: o.sessionId };
|
|
52
|
+
case "STREAM_TEXT_DELTA": {
|
|
53
|
+
const s = [...t.messages], e = s[s.length - 1];
|
|
54
|
+
if (e && e.type === "assistant_text") {
|
|
55
|
+
const r = [...e.contentBlocks], a = r[r.length - 1];
|
|
56
|
+
a && a.type === "text" ? r[r.length - 1] = { type: "text", text: a.text + o.content } : r.push({ type: "text", text: o.content }), s[s.length - 1] = { ...e, text: e.text + o.content, contentBlocks: r };
|
|
57
|
+
}
|
|
58
|
+
return { ...t, messages: s };
|
|
59
|
+
}
|
|
60
|
+
case "STREAM_TOOL_CALL_START": {
|
|
61
|
+
const s = [...t.messages], e = s[s.length - 1], r = {
|
|
62
|
+
toolId: o.toolId,
|
|
63
|
+
toolName: o.toolName,
|
|
64
|
+
parameters: o.parameters,
|
|
65
|
+
status: "running"
|
|
66
|
+
};
|
|
67
|
+
if (e && e.type === "assistant_text") {
|
|
68
|
+
const a = [...e.toolCalls, r], l = [...e.contentBlocks], n = l[l.length - 1];
|
|
69
|
+
n && n.type === "tool_calls" ? l[l.length - 1] = { type: "tool_calls", calls: [...n.calls, r] } : l.push({ type: "tool_calls", calls: [r] }), s[s.length - 1] = { ...e, toolCalls: a, contentBlocks: l };
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
...t,
|
|
73
|
+
messages: s,
|
|
74
|
+
activeToolCalls: [...t.activeToolCalls, r]
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
case "STREAM_TOOL_CALL_RESULT": {
|
|
78
|
+
const s = [...t.messages], e = s[s.length - 1];
|
|
79
|
+
if (e && e.type === "assistant_text") {
|
|
80
|
+
const a = (u) => u.toolId === o.toolId ? {
|
|
81
|
+
...u,
|
|
82
|
+
status: o.status,
|
|
83
|
+
result: o.result,
|
|
84
|
+
parameters: o.parameters ?? u.parameters,
|
|
85
|
+
duration_ms: o.duration_ms,
|
|
86
|
+
error: o.error
|
|
87
|
+
} : u, l = e.toolCalls.map(a), n = e.contentBlocks.map(
|
|
88
|
+
(u) => u.type === "tool_calls" ? { ...u, calls: u.calls.map(a) } : u
|
|
89
|
+
);
|
|
90
|
+
s[s.length - 1] = { ...e, toolCalls: l, contentBlocks: n };
|
|
91
|
+
}
|
|
92
|
+
const r = t.activeToolCalls.filter((a) => a.toolId !== o.toolId);
|
|
93
|
+
return { ...t, messages: s, activeToolCalls: r };
|
|
94
|
+
}
|
|
95
|
+
case "STREAM_SUBAGENT_EVENT": {
|
|
96
|
+
const s = [...t.messages], e = s[s.length - 1];
|
|
97
|
+
if (e && e.type === "assistant_text") {
|
|
98
|
+
const r = (n) => n.toolId === o.parentToolId ? { ...n, subagentEvents: [...n.subagentEvents ?? [], o.event] } : n, a = e.toolCalls.map(r), l = e.contentBlocks.map(
|
|
99
|
+
(n) => n.type === "tool_calls" ? { ...n, calls: n.calls.map(r) } : n
|
|
100
|
+
);
|
|
101
|
+
s[s.length - 1] = { ...e, toolCalls: a, contentBlocks: l };
|
|
102
|
+
}
|
|
103
|
+
return { ...t, messages: s };
|
|
104
|
+
}
|
|
105
|
+
case "STREAM_SKILL_ACTIVATED": {
|
|
106
|
+
const s = [...t.messages], e = s[s.length - 1];
|
|
107
|
+
return e && e.type === "assistant_text" && (s[s.length - 1] = {
|
|
108
|
+
...e,
|
|
109
|
+
skillActivations: [...e.skillActivations, o.skill]
|
|
110
|
+
}), { ...t, messages: s };
|
|
111
|
+
}
|
|
112
|
+
case "STREAM_KB_PROPOSAL": {
|
|
113
|
+
const s = [...t.messages], e = s[s.length - 1], r = {
|
|
114
|
+
scope: o.scope,
|
|
115
|
+
title: o.title,
|
|
116
|
+
reasoning: o.reasoning
|
|
117
|
+
};
|
|
118
|
+
return e && e.type === "assistant_text" && (s[s.length - 1] = {
|
|
119
|
+
...e,
|
|
120
|
+
kbProposals: [...e.kbProposals, r]
|
|
121
|
+
}), { ...t, messages: s };
|
|
122
|
+
}
|
|
123
|
+
case "STREAM_WIDGET": {
|
|
124
|
+
const s = [...t.messages], e = s[s.length - 1];
|
|
125
|
+
if (e && e.type === "assistant_text") {
|
|
126
|
+
const r = {
|
|
127
|
+
widgetType: o.widgetType,
|
|
128
|
+
data: o.data
|
|
129
|
+
}, a = {
|
|
130
|
+
type: "widget",
|
|
131
|
+
widgetType: o.widgetType,
|
|
132
|
+
data: o.data
|
|
133
|
+
};
|
|
134
|
+
s[s.length - 1] = {
|
|
135
|
+
...e,
|
|
136
|
+
widgets: [...e.widgets, r],
|
|
137
|
+
contentBlocks: [...e.contentBlocks, a]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return { ...t, messages: s };
|
|
141
|
+
}
|
|
142
|
+
case "STREAM_ASK_USER": {
|
|
143
|
+
const s = [...t.messages], e = s[s.length - 1];
|
|
144
|
+
if (e && e.type === "assistant_text") {
|
|
145
|
+
const r = {
|
|
146
|
+
type: "ask_user",
|
|
147
|
+
askId: o.askId,
|
|
148
|
+
questions: o.questions,
|
|
149
|
+
status: "pending"
|
|
150
|
+
};
|
|
151
|
+
s[s.length - 1] = {
|
|
152
|
+
...e,
|
|
153
|
+
contentBlocks: [...e.contentBlocks, r]
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return { ...t, messages: s };
|
|
157
|
+
}
|
|
158
|
+
case "ASK_USER_SUBMITTED": {
|
|
159
|
+
const s = [...t.messages], e = s[s.length - 1];
|
|
160
|
+
if (e && e.type === "assistant_text") {
|
|
161
|
+
const r = e.contentBlocks.map(
|
|
162
|
+
(a) => a.type === "ask_user" && a.askId === o.askId ? { ...a, status: "submitted", answers: o.answers } : a
|
|
163
|
+
);
|
|
164
|
+
s[s.length - 1] = { ...e, contentBlocks: r };
|
|
165
|
+
}
|
|
166
|
+
return { ...t, messages: s };
|
|
167
|
+
}
|
|
168
|
+
case "STREAM_CONFIRMATION_REQUIRED": {
|
|
169
|
+
const s = [...t.messages], e = s[s.length - 1];
|
|
170
|
+
if (e && e.type === "assistant_text") {
|
|
171
|
+
const r = {
|
|
172
|
+
type: "confirmation",
|
|
173
|
+
confirmation: o.confirmation
|
|
174
|
+
};
|
|
175
|
+
s[s.length - 1] = {
|
|
176
|
+
...e,
|
|
177
|
+
confirmations: [...e.confirmations, o.confirmation],
|
|
178
|
+
contentBlocks: [...e.contentBlocks, r]
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return { ...t, messages: s };
|
|
182
|
+
}
|
|
183
|
+
case "CONFIRMATION_RESPONDED": {
|
|
184
|
+
const s = [...t.messages], e = s[s.length - 1];
|
|
185
|
+
if (e && e.type === "assistant_text") {
|
|
186
|
+
const r = o.approved ? "approved" : "denied", a = e.confirmations.map(
|
|
187
|
+
(n) => n.correlationId === o.correlationId ? { ...n, status: r } : n
|
|
188
|
+
), l = e.contentBlocks.map(
|
|
189
|
+
(n) => n.type === "confirmation" && n.confirmation.correlationId === o.correlationId ? { ...n, confirmation: { ...n.confirmation, status: r } } : n
|
|
190
|
+
);
|
|
191
|
+
s[s.length - 1] = { ...e, confirmations: a, contentBlocks: l };
|
|
192
|
+
}
|
|
193
|
+
return { ...t, messages: s };
|
|
194
|
+
}
|
|
195
|
+
case "STREAM_TOOL_LOG": {
|
|
196
|
+
const s = [...t.messages], e = s[s.length - 1];
|
|
197
|
+
if (e && e.type === "assistant_text") {
|
|
198
|
+
const r = (n) => n.toolName === o.toolName && n.status === "running" ? { ...n, logMessage: o.message } : n, a = e.toolCalls.map(r), l = e.contentBlocks.map(
|
|
199
|
+
(n) => n.type === "tool_calls" ? { ...n, calls: n.calls.map(r) } : n
|
|
200
|
+
);
|
|
201
|
+
s[s.length - 1] = { ...e, toolCalls: a, contentBlocks: l };
|
|
202
|
+
}
|
|
203
|
+
return { ...t, messages: s };
|
|
204
|
+
}
|
|
205
|
+
case "STREAM_CREDENTIAL_SAVED":
|
|
206
|
+
case "STREAM_APPROVED":
|
|
207
|
+
return t;
|
|
208
|
+
case "STREAM_ERROR":
|
|
209
|
+
return { ...t, isStreaming: !1, error: o.message, activeToolCalls: [] };
|
|
210
|
+
case "STREAM_DONE": {
|
|
211
|
+
const s = [...t.messages], e = s[s.length - 1];
|
|
212
|
+
if (e && e.type === "assistant_text") {
|
|
213
|
+
const a = (u) => u.status === "running" ? { ...u, status: "error", error: "Stopped" } : u, l = e.toolCalls.map(a), n = e.contentBlocks.map(
|
|
214
|
+
(u) => u.type === "tool_calls" ? { ...u, calls: u.calls.map(a) } : u
|
|
215
|
+
);
|
|
216
|
+
s[s.length - 1] = {
|
|
217
|
+
...e,
|
|
218
|
+
toolCalls: l,
|
|
219
|
+
contentBlocks: n,
|
|
220
|
+
...o.usage ? { usage: o.usage } : {}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
const r = o.usage ? {
|
|
224
|
+
inputTokens: t.usage.inputTokens + o.usage.inputTokens,
|
|
225
|
+
outputTokens: t.usage.outputTokens + o.usage.outputTokens
|
|
226
|
+
} : t.usage;
|
|
227
|
+
return {
|
|
228
|
+
...t,
|
|
229
|
+
messages: s,
|
|
230
|
+
isStreaming: !1,
|
|
231
|
+
activeToolCalls: [],
|
|
232
|
+
usage: r
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
case "LOAD_HISTORY":
|
|
236
|
+
return {
|
|
237
|
+
...k,
|
|
238
|
+
messages: o.messages,
|
|
239
|
+
sessionId: o.sessionId,
|
|
240
|
+
isHistorical: !0
|
|
241
|
+
};
|
|
242
|
+
case "RESET":
|
|
243
|
+
return { ...k };
|
|
244
|
+
default:
|
|
245
|
+
return t;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
function b(t) {
|
|
249
|
+
const { entityExtractors: o } = t, [s, e] = V(z, k), r = S(null), a = S(t);
|
|
250
|
+
a.current = t;
|
|
251
|
+
const l = S(null);
|
|
252
|
+
l.current || (l.current = new G(), o && l.current.setExtractors(o));
|
|
253
|
+
const n = l.current, u = S(null);
|
|
254
|
+
u.current || (u.current = (i) => {
|
|
255
|
+
var c, m;
|
|
256
|
+
(m = (c = a.current).onEvent) == null || m.call(c, i);
|
|
257
|
+
}, n.on("entity_referenced", u.current));
|
|
258
|
+
const g = S(/* @__PURE__ */ new Map()), d = R(
|
|
259
|
+
(i) => {
|
|
260
|
+
if (s.isStreaming) return;
|
|
261
|
+
e({ type: "SEND_MESSAGE", text: i });
|
|
262
|
+
const c = new AbortController();
|
|
263
|
+
r.current = c, (async () => {
|
|
264
|
+
var f, E;
|
|
265
|
+
let p = !1;
|
|
266
|
+
try {
|
|
267
|
+
const y = a.current.streamFn(i, c.signal);
|
|
268
|
+
for await (const T of y)
|
|
269
|
+
j(T, e, g.current, a.current, n), T.type === "done" && (p = !0);
|
|
270
|
+
} catch (y) {
|
|
271
|
+
y instanceof DOMException && y.name === "AbortError" || e({
|
|
272
|
+
type: "STREAM_ERROR",
|
|
273
|
+
message: y instanceof Error ? y.message : "Unknown error"
|
|
274
|
+
});
|
|
275
|
+
} finally {
|
|
276
|
+
r.current = null, !p && !c.signal.aborted && (e({ type: "STREAM_DONE" }), (E = (f = a.current).onStreamEnd) == null || E.call(f));
|
|
277
|
+
}
|
|
278
|
+
})();
|
|
279
|
+
},
|
|
280
|
+
// streamFn is read via callbacksRef on each call, so it doesn't need
|
|
281
|
+
// to be a dep here. Keeping send() identity stable across streamFn
|
|
282
|
+
// changes prevents downstream consumers from re-running effects.
|
|
283
|
+
[s.isStreaming, n]
|
|
284
|
+
), _ = R(() => {
|
|
285
|
+
r.current && (r.current.abort(), r.current = null), e({ type: "STREAM_DONE" });
|
|
286
|
+
}, []), h = R(() => {
|
|
287
|
+
r.current && (r.current.abort(), r.current = null), g.current.clear(), e({ type: "RESET" });
|
|
288
|
+
}, []), I = R(
|
|
289
|
+
(i, c) => {
|
|
290
|
+
if (e({ type: "CONFIRMATION_RESPONDED", correlationId: i, approved: c }), !s.isStreaming) {
|
|
291
|
+
const m = c ? `I approve the action (correlation: ${i})` : `I deny the action (correlation: ${i})`;
|
|
292
|
+
d(m);
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
[d, s.isStreaming]
|
|
296
|
+
);
|
|
297
|
+
return M(
|
|
298
|
+
() => () => {
|
|
299
|
+
r.current && r.current.abort();
|
|
300
|
+
},
|
|
301
|
+
[]
|
|
302
|
+
), {
|
|
303
|
+
messages: s.messages,
|
|
304
|
+
isStreaming: s.isStreaming,
|
|
305
|
+
activeToolCalls: s.activeToolCalls,
|
|
306
|
+
sessionId: s.sessionId,
|
|
307
|
+
error: s.error,
|
|
308
|
+
usage: s.usage,
|
|
309
|
+
isHistorical: s.isHistorical,
|
|
310
|
+
send: d,
|
|
311
|
+
stop: _,
|
|
312
|
+
reset: h,
|
|
313
|
+
respondToConfirmation: I,
|
|
314
|
+
dispatch: e,
|
|
315
|
+
eventBus: n
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
function j(t, o, s, e, r) {
|
|
319
|
+
var a, l, n, u, g, d, _, h, I;
|
|
320
|
+
switch (t.type) {
|
|
321
|
+
case "init":
|
|
322
|
+
o({ type: "STREAM_INIT", sessionId: t.session_id }), (a = e.onSessionCreated) == null || a.call(e, t.session_id);
|
|
323
|
+
return;
|
|
324
|
+
case "text_delta":
|
|
325
|
+
o({ type: "STREAM_TEXT_DELTA", content: t.content });
|
|
326
|
+
return;
|
|
327
|
+
case "tool_call_start":
|
|
328
|
+
o({
|
|
329
|
+
type: "STREAM_TOOL_CALL_START",
|
|
330
|
+
toolId: t.tool_id,
|
|
331
|
+
toolName: t.tool_name,
|
|
332
|
+
parameters: t.parameters
|
|
333
|
+
}), s.set(t.tool_id, {
|
|
334
|
+
toolName: t.tool_name,
|
|
335
|
+
parameters: t.parameters
|
|
336
|
+
});
|
|
337
|
+
return;
|
|
338
|
+
case "tool_call_result": {
|
|
339
|
+
const i = s.get(t.tool_id), c = {
|
|
340
|
+
toolId: t.tool_id,
|
|
341
|
+
toolName: (i == null ? void 0 : i.toolName) ?? "",
|
|
342
|
+
parameters: (i == null ? void 0 : i.parameters) ?? {},
|
|
343
|
+
status: t.status,
|
|
344
|
+
result: t.result,
|
|
345
|
+
duration_ms: t.duration_ms,
|
|
346
|
+
error: t.error
|
|
347
|
+
};
|
|
348
|
+
s.delete(t.tool_id), o({
|
|
349
|
+
type: "STREAM_TOOL_CALL_RESULT",
|
|
350
|
+
toolId: t.tool_id,
|
|
351
|
+
status: t.status,
|
|
352
|
+
result: t.result,
|
|
353
|
+
duration_ms: t.duration_ms,
|
|
354
|
+
error: t.error
|
|
355
|
+
}), (l = e.onToolCall) == null || l.call(e, c);
|
|
356
|
+
const m = {
|
|
357
|
+
type: "tool_executed",
|
|
358
|
+
toolName: c.toolName,
|
|
359
|
+
toolId: c.toolId,
|
|
360
|
+
parameters: c.parameters,
|
|
361
|
+
status: t.status,
|
|
362
|
+
result: t.result,
|
|
363
|
+
duration_ms: t.duration_ms,
|
|
364
|
+
error: t.error,
|
|
365
|
+
timestamp: t.timestamp
|
|
366
|
+
};
|
|
367
|
+
r.processEvent(m), (n = e.onEvent) == null || n.call(e, m);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
case "subagent_event":
|
|
371
|
+
o({
|
|
372
|
+
type: "STREAM_SUBAGENT_EVENT",
|
|
373
|
+
parentToolId: t.parent_tool_id,
|
|
374
|
+
event: {
|
|
375
|
+
agentName: t.agent_name,
|
|
376
|
+
eventType: t.event_type,
|
|
377
|
+
toolName: t.tool_name,
|
|
378
|
+
toolArgs: t.tool_args,
|
|
379
|
+
result: t.result,
|
|
380
|
+
text: t.text,
|
|
381
|
+
error: t.error,
|
|
382
|
+
timestamp: t.timestamp
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
return;
|
|
386
|
+
case "skill_activated": {
|
|
387
|
+
o({ type: "STREAM_SKILL_ACTIVATED", skill: t.skill });
|
|
388
|
+
const i = {
|
|
389
|
+
type: "skill_activated",
|
|
390
|
+
skill: t.skill,
|
|
391
|
+
timestamp: t.timestamp
|
|
392
|
+
};
|
|
393
|
+
r.processEvent(i), (u = e.onEvent) == null || u.call(e, i);
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
case "kb_proposal": {
|
|
397
|
+
const i = {
|
|
398
|
+
scope: t.scope,
|
|
399
|
+
title: t.title,
|
|
400
|
+
reasoning: t.reasoning
|
|
401
|
+
};
|
|
402
|
+
o({
|
|
403
|
+
type: "STREAM_KB_PROPOSAL",
|
|
404
|
+
scope: t.scope,
|
|
405
|
+
title: t.title,
|
|
406
|
+
reasoning: t.reasoning
|
|
407
|
+
}), (g = e.onKBProposal) == null || g.call(e, i);
|
|
408
|
+
const c = {
|
|
409
|
+
type: "kb_proposal",
|
|
410
|
+
proposal: i,
|
|
411
|
+
timestamp: t.timestamp
|
|
412
|
+
};
|
|
413
|
+
r.processEvent(c), (d = e.onEvent) == null || d.call(e, c);
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
case "widget": {
|
|
417
|
+
o({ type: "STREAM_WIDGET", widgetType: t.widget_type, data: t.data });
|
|
418
|
+
const i = {
|
|
419
|
+
type: "widget_rendered",
|
|
420
|
+
widgetType: t.widget_type,
|
|
421
|
+
data: t.data,
|
|
422
|
+
timestamp: t.timestamp
|
|
423
|
+
};
|
|
424
|
+
r.processEvent(i), (_ = e.onEvent) == null || _.call(e, i);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
case "ask_user":
|
|
428
|
+
o({
|
|
429
|
+
type: "STREAM_ASK_USER",
|
|
430
|
+
askId: t.ask_id,
|
|
431
|
+
questions: t.questions
|
|
432
|
+
});
|
|
433
|
+
return;
|
|
434
|
+
case "credential_saved":
|
|
435
|
+
o({ type: "STREAM_CREDENTIAL_SAVED", connectionName: t.connection_name });
|
|
436
|
+
return;
|
|
437
|
+
case "approved":
|
|
438
|
+
o({
|
|
439
|
+
type: "STREAM_APPROVED",
|
|
440
|
+
resourceType: t.resource_type,
|
|
441
|
+
previewId: t.preview_id
|
|
442
|
+
});
|
|
443
|
+
return;
|
|
444
|
+
case "confirmation_required": {
|
|
445
|
+
const i = {
|
|
446
|
+
endpoint: t.endpoint,
|
|
447
|
+
method: t.method,
|
|
448
|
+
reason: t.reason,
|
|
449
|
+
escalated: t.escalated,
|
|
450
|
+
params: t.params,
|
|
451
|
+
connectionName: t.connection_name,
|
|
452
|
+
correlationId: t.correlation_id,
|
|
453
|
+
status: "pending"
|
|
454
|
+
};
|
|
455
|
+
o({ type: "STREAM_CONFIRMATION_REQUIRED", confirmation: i }), (h = e.onConfirmation) == null || h.call(e, i);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
case "tool_log":
|
|
459
|
+
o({ type: "STREAM_TOOL_LOG", toolName: t.tool_name, message: t.message });
|
|
460
|
+
return;
|
|
461
|
+
case "error":
|
|
462
|
+
o({ type: "STREAM_ERROR", message: t.message });
|
|
463
|
+
return;
|
|
464
|
+
case "done":
|
|
465
|
+
o({
|
|
466
|
+
type: "STREAM_DONE",
|
|
467
|
+
usage: t.usage ? { inputTokens: t.usage.input_tokens, outputTokens: t.usage.output_tokens } : void 0
|
|
468
|
+
}), (I = e.onStreamEnd) == null || I.call(e);
|
|
469
|
+
return;
|
|
470
|
+
case "explore_start":
|
|
471
|
+
case "explore_end":
|
|
472
|
+
case "plan_mode":
|
|
473
|
+
case "field_scrub":
|
|
474
|
+
return;
|
|
475
|
+
default:
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* @license
|
|
481
|
+
* Copyright 2025 Amodal Labs, Inc.
|
|
482
|
+
* SPDX-License-Identifier: MIT
|
|
483
|
+
*/
|
|
484
|
+
function Z(t) {
|
|
485
|
+
const {
|
|
486
|
+
serverUrl: o,
|
|
487
|
+
user: s,
|
|
488
|
+
getToken: e,
|
|
489
|
+
onToolCall: r,
|
|
490
|
+
onKBProposal: a,
|
|
491
|
+
onEvent: l,
|
|
492
|
+
entityExtractors: n,
|
|
493
|
+
sessionType: u,
|
|
494
|
+
deployId: g,
|
|
495
|
+
initialMessage: d,
|
|
496
|
+
resumeSessionId: _,
|
|
497
|
+
onStreamEnd: h,
|
|
498
|
+
onSessionCreated: I
|
|
499
|
+
} = t, i = S({ getToken: e, user: s, sessionType: u, deployId: g });
|
|
500
|
+
i.current = { getToken: e, user: s, sessionType: u, deployId: g };
|
|
501
|
+
const c = S(null), m = R(
|
|
502
|
+
(C, O) => {
|
|
503
|
+
var x, A;
|
|
504
|
+
const w = ((A = (x = i.current).getToken) == null ? void 0 : A.call(x)) ?? void 0;
|
|
505
|
+
return $(
|
|
506
|
+
o,
|
|
507
|
+
{
|
|
508
|
+
message: C,
|
|
509
|
+
session_id: c.current ?? void 0,
|
|
510
|
+
role: i.current.user.role,
|
|
511
|
+
session_type: i.current.sessionType,
|
|
512
|
+
deploy_id: i.current.deployId
|
|
513
|
+
},
|
|
514
|
+
O,
|
|
515
|
+
w
|
|
516
|
+
);
|
|
517
|
+
},
|
|
518
|
+
[o]
|
|
519
|
+
), p = b({
|
|
520
|
+
streamFn: m,
|
|
521
|
+
...r ? { onToolCall: r } : {},
|
|
522
|
+
...a ? { onKBProposal: a } : {},
|
|
523
|
+
...l ? { onEvent: l } : {},
|
|
524
|
+
...h ? { onStreamEnd: h } : {},
|
|
525
|
+
...I ? { onSessionCreated: I } : {},
|
|
526
|
+
...n ? { entityExtractors: n } : {}
|
|
527
|
+
});
|
|
528
|
+
c.current = p.sessionId;
|
|
529
|
+
const f = S(!1), E = S(!1), y = S(!1), T = R(
|
|
530
|
+
(C) => {
|
|
531
|
+
E.current = !0, (async () => {
|
|
532
|
+
var w, x;
|
|
533
|
+
try {
|
|
534
|
+
const A = ((x = (w = i.current).getToken) == null ? void 0 : x.call(w)) ?? void 0, N = await q(o, C, A), B = Q(N.messages);
|
|
535
|
+
p.dispatch({ type: "LOAD_HISTORY", sessionId: C, messages: B });
|
|
536
|
+
} catch (A) {
|
|
537
|
+
p.dispatch({
|
|
538
|
+
type: "STREAM_ERROR",
|
|
539
|
+
message: A instanceof Error ? A.message : "Failed to load session"
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
})();
|
|
543
|
+
},
|
|
544
|
+
// stream.dispatch is stable (React guarantees); serverUrl is the real dep.
|
|
545
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
546
|
+
[o]
|
|
547
|
+
);
|
|
548
|
+
M(() => {
|
|
549
|
+
!_ || y.current || (y.current = !0, E.current = !0, T(_));
|
|
550
|
+
}, [_]), M(() => {
|
|
551
|
+
if (_ || p.sessionId && !d || !d || E.current) return;
|
|
552
|
+
f.current = !1;
|
|
553
|
+
const C = setTimeout(() => {
|
|
554
|
+
!f.current && !E.current && (f.current = !0, p.send(d));
|
|
555
|
+
}, 0);
|
|
556
|
+
return () => {
|
|
557
|
+
clearTimeout(C);
|
|
558
|
+
};
|
|
559
|
+
}, [d]), M(() => {
|
|
560
|
+
d && f.current && !p.isStreaming && p.messages.length > 0 && (E.current = !0);
|
|
561
|
+
}, [d, p.isStreaming, p.messages.length]);
|
|
562
|
+
const K = R(
|
|
563
|
+
(C, O) => {
|
|
564
|
+
const w = c.current;
|
|
565
|
+
if (!w) return;
|
|
566
|
+
p.dispatch({ type: "ASK_USER_SUBMITTED", askId: C, answers: O }), (async () => {
|
|
567
|
+
var A, N;
|
|
568
|
+
try {
|
|
569
|
+
const B = ((N = (A = i.current).getToken) == null ? void 0 : N.call(A)) ?? void 0, D = { "Content-Type": "application/json" };
|
|
570
|
+
B && (D.Authorization = `Bearer ${B}`), await fetch(`${o}/chat/sessions/${w}/ask-user-response`, {
|
|
571
|
+
method: "POST",
|
|
572
|
+
headers: D,
|
|
573
|
+
body: JSON.stringify({ ask_id: C, answers: O })
|
|
574
|
+
});
|
|
575
|
+
} catch {
|
|
576
|
+
}
|
|
577
|
+
})();
|
|
578
|
+
},
|
|
579
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
580
|
+
[o]
|
|
581
|
+
);
|
|
582
|
+
return {
|
|
583
|
+
messages: p.messages,
|
|
584
|
+
send: p.send,
|
|
585
|
+
stop: p.stop,
|
|
586
|
+
isStreaming: p.isStreaming,
|
|
587
|
+
activeToolCalls: p.activeToolCalls,
|
|
588
|
+
session: { id: p.sessionId, role: s.role },
|
|
589
|
+
error: p.error,
|
|
590
|
+
reset: p.reset,
|
|
591
|
+
eventBus: p.eventBus,
|
|
592
|
+
submitAskUserResponse: K,
|
|
593
|
+
loadSession: T,
|
|
594
|
+
isHistorical: p.isHistorical
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function Q(t) {
|
|
598
|
+
return t.map((o) => {
|
|
599
|
+
if (o.type === "assistant_text") {
|
|
600
|
+
const s = (o.toolCalls ?? []).map((l) => ({
|
|
601
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- stored field
|
|
602
|
+
toolId: l.toolId ?? "",
|
|
603
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- stored field
|
|
604
|
+
toolName: l.toolName ?? "",
|
|
605
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- stored field
|
|
606
|
+
parameters: l.args ?? {},
|
|
607
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- stored field
|
|
608
|
+
status: l.status ?? "success",
|
|
609
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- stored field
|
|
610
|
+
duration_ms: l.duration_ms,
|
|
611
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- stored field
|
|
612
|
+
error: l.error,
|
|
613
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- stored field
|
|
614
|
+
result: l.result
|
|
615
|
+
})), e = o.widgets ?? [], r = o.contentBlocks, a = [];
|
|
616
|
+
if (r && r.length > 0) {
|
|
617
|
+
const l = new Map(s.map((n) => [n.toolId, n]));
|
|
618
|
+
for (const n of r) {
|
|
619
|
+
const u = n.type;
|
|
620
|
+
if (u === "text") {
|
|
621
|
+
const g = n.text;
|
|
622
|
+
g.length > 0 && a.push({ type: "text", text: g });
|
|
623
|
+
} else if (u === "tool_calls") {
|
|
624
|
+
const g = n.callIds, d = g ? g.map((_) => l.get(_)).filter((_) => _ != null) : s;
|
|
625
|
+
d.length > 0 && a.push({ type: "tool_calls", calls: d });
|
|
626
|
+
} else u === "widget" && a.push({
|
|
627
|
+
type: "widget",
|
|
628
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- stored field
|
|
629
|
+
widgetType: n.widgetType,
|
|
630
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- stored field
|
|
631
|
+
data: n.data ?? {}
|
|
632
|
+
});
|
|
633
|
+
}
|
|
634
|
+
} else {
|
|
635
|
+
s.length > 0 && a.push({ type: "tool_calls", calls: s }), o.text.length > 0 && a.push({ type: "text", text: o.text });
|
|
636
|
+
for (const l of e)
|
|
637
|
+
a.push({ type: "widget", widgetType: l.widgetType, data: l.data });
|
|
638
|
+
}
|
|
639
|
+
return {
|
|
640
|
+
type: "assistant_text",
|
|
641
|
+
id: o.id,
|
|
642
|
+
text: o.text,
|
|
643
|
+
toolCalls: s,
|
|
644
|
+
confirmations: [],
|
|
645
|
+
skillActivations: o.skillActivations ?? [],
|
|
646
|
+
kbProposals: [],
|
|
647
|
+
widgets: e,
|
|
648
|
+
contentBlocks: a,
|
|
649
|
+
timestamp: o.timestamp
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
return o.type === "error" ? { type: "error", id: o.id, message: o.text, timestamp: o.timestamp } : { type: "user", id: o.id, text: o.text, timestamp: o.timestamp };
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* @license
|
|
657
|
+
* Copyright 2025 Amodal Labs, Inc.
|
|
658
|
+
* SPDX-License-Identifier: MIT
|
|
659
|
+
*/
|
|
660
|
+
function v(t) {
|
|
661
|
+
const o = S([]);
|
|
662
|
+
M(
|
|
663
|
+
() => () => {
|
|
664
|
+
for (const r of o.current)
|
|
665
|
+
r();
|
|
666
|
+
o.current = [];
|
|
667
|
+
},
|
|
668
|
+
[]
|
|
669
|
+
);
|
|
670
|
+
const s = R(
|
|
671
|
+
(r, a) => {
|
|
672
|
+
if (!t)
|
|
673
|
+
return () => {
|
|
674
|
+
};
|
|
675
|
+
t.on(r, a);
|
|
676
|
+
const l = () => {
|
|
677
|
+
t.off(r, a);
|
|
678
|
+
};
|
|
679
|
+
return o.current.push(l), l;
|
|
680
|
+
},
|
|
681
|
+
[t]
|
|
682
|
+
), e = R(
|
|
683
|
+
(r) => {
|
|
684
|
+
if (!t)
|
|
685
|
+
return () => {
|
|
686
|
+
};
|
|
687
|
+
t.on("*", r);
|
|
688
|
+
const a = () => {
|
|
689
|
+
t.off("*", r);
|
|
690
|
+
};
|
|
691
|
+
return o.current.push(a), a;
|
|
692
|
+
},
|
|
693
|
+
[t]
|
|
694
|
+
);
|
|
695
|
+
return { on: s, onAny: e };
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* @license
|
|
699
|
+
* Copyright 2025 Amodal Labs, Inc.
|
|
700
|
+
* SPDX-License-Identifier: MIT
|
|
701
|
+
*/
|
|
702
|
+
function tt(t) {
|
|
703
|
+
const { serverUrl: o, getToken: s, enabled: e } = t, [r, a] = L([]), [l, n] = L(!1), [u, g] = L(null), d = S(s);
|
|
704
|
+
d.current = s;
|
|
705
|
+
const _ = R(() => {
|
|
706
|
+
if (!e) return;
|
|
707
|
+
n(!0), g(null), (async () => {
|
|
708
|
+
var m;
|
|
709
|
+
try {
|
|
710
|
+
const p = ((m = d.current) == null ? void 0 : m.call(d)) ?? void 0, f = await W(o, p);
|
|
711
|
+
a(f);
|
|
712
|
+
} catch (p) {
|
|
713
|
+
g(p instanceof Error ? p.message : "Failed to load sessions");
|
|
714
|
+
} finally {
|
|
715
|
+
n(!1);
|
|
716
|
+
}
|
|
717
|
+
})();
|
|
718
|
+
}, [o, e]), h = R(
|
|
719
|
+
(c, m) => {
|
|
720
|
+
(async () => {
|
|
721
|
+
var f;
|
|
722
|
+
try {
|
|
723
|
+
const E = ((f = d.current) == null ? void 0 : f.call(d)) ?? void 0;
|
|
724
|
+
await U(o, c, { tags: m }, E), a(
|
|
725
|
+
(y) => y.map((T) => T.id === c ? { ...T, tags: m } : T)
|
|
726
|
+
);
|
|
727
|
+
} catch {
|
|
728
|
+
}
|
|
729
|
+
})();
|
|
730
|
+
},
|
|
731
|
+
[o]
|
|
732
|
+
), I = R(
|
|
733
|
+
(c, m) => {
|
|
734
|
+
(async () => {
|
|
735
|
+
var f;
|
|
736
|
+
try {
|
|
737
|
+
const E = ((f = d.current) == null ? void 0 : f.call(d)) ?? void 0;
|
|
738
|
+
await U(o, c, { title: m }, E), a(
|
|
739
|
+
(y) => y.map((T) => T.id === c ? { ...T, title: m } : T)
|
|
740
|
+
);
|
|
741
|
+
} catch {
|
|
742
|
+
}
|
|
743
|
+
})();
|
|
744
|
+
},
|
|
745
|
+
[o]
|
|
746
|
+
), i = [...new Set(r.flatMap((c) => c.tags))].sort();
|
|
747
|
+
return M(() => {
|
|
748
|
+
e && _();
|
|
749
|
+
}, [e, _]), { sessions: r, isLoading: l, error: u, refresh: _, updateTags: h, updateTitle: I, allTags: i };
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* @license
|
|
753
|
+
* Copyright 2025 Amodal Labs, Inc.
|
|
754
|
+
* SPDX-License-Identifier: MIT
|
|
755
|
+
*/
|
|
756
|
+
const H = {
|
|
757
|
+
primaryColor: "#1e40af",
|
|
758
|
+
backgroundColor: "#ffffff",
|
|
759
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
760
|
+
fontSize: "14px",
|
|
761
|
+
borderRadius: "8px",
|
|
762
|
+
userBubbleColor: "#1e40af",
|
|
763
|
+
agentBubbleColor: "#f3f4f6",
|
|
764
|
+
toolCallColor: "#f9fafb",
|
|
765
|
+
headerText: "AI Assistant",
|
|
766
|
+
placeholder: "Type a message...",
|
|
767
|
+
emptyStateText: "Send a message to start a conversation."
|
|
768
|
+
}, X = {
|
|
769
|
+
primaryColor: "--pcw-primary",
|
|
770
|
+
backgroundColor: "--pcw-bg",
|
|
771
|
+
fontFamily: "--pcw-font",
|
|
772
|
+
fontSize: "--pcw-font-size",
|
|
773
|
+
borderRadius: "--pcw-radius",
|
|
774
|
+
userBubbleColor: "--pcw-user-bubble",
|
|
775
|
+
agentBubbleColor: "--pcw-agent-bubble",
|
|
776
|
+
toolCallColor: "--pcw-tool-call-bg",
|
|
777
|
+
headerText: "--pcw-header-text",
|
|
778
|
+
placeholder: "--pcw-placeholder",
|
|
779
|
+
emptyStateText: "--pcw-empty-state-text"
|
|
780
|
+
};
|
|
781
|
+
function et(t, o) {
|
|
782
|
+
const s = { ...H, ...o };
|
|
783
|
+
for (const [e, r] of Object.entries(X)) {
|
|
784
|
+
const a = s[e];
|
|
785
|
+
a !== void 0 && t.style.setProperty(r, a);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
function st(t) {
|
|
789
|
+
return { ...H, ...t };
|
|
790
|
+
}
|
|
791
|
+
export {
|
|
792
|
+
et as a,
|
|
793
|
+
Z as b,
|
|
794
|
+
z as c,
|
|
795
|
+
H as d,
|
|
796
|
+
tt as e,
|
|
797
|
+
v as f,
|
|
798
|
+
st as m,
|
|
799
|
+
b as u
|
|
800
|
+
};
|
|
801
|
+
//# sourceMappingURL=theme-C051UgQ1.js.map
|