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