@amodalai/react 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.js CHANGED
@@ -2,15 +2,15 @@ import { jsx as v, jsxs as w } from "react/jsx-runtime";
2
2
  import { createContext as F, useMemo as B, useContext as U, useReducer as Q, useRef as N, useCallback as A, useEffect as R, useState as y } from "react";
3
3
  import { RuntimeClient as V } from "./client.js";
4
4
  import { ChatClient as me, ChatStream as fe } from "./client.js";
5
- import { a as ge, d as _e, m as he, u as ve, b as ye, c as Ee } from "./theme-VAUsolBG.js";
5
+ import { a as pe, d as _e, m as he, u as ve, b as ye, c as Ee } from "./theme-VAUsolBG.js";
6
6
  import { T as be, W as Te, c as Ae, a as Ne, d as xe, g as Ce, l as we, p as Re, s as ke, b as Ie, e as De, u as Me } from "./event-bus-h26clqbZ.js";
7
7
  const j = F(null);
8
- function Z({ runtimeUrl: s, tenantId: r, getToken: t, children: e }) {
8
+ function Z({ runtimeUrl: s, appId: r, getToken: t, children: e }) {
9
9
  const n = B(
10
- () => new V({ runtimeUrl: s, tenantId: r, getToken: t }),
10
+ () => new V({ runtimeUrl: s, appId: r, getToken: t }),
11
11
  [s, r, t]
12
12
  ), a = B(
13
- () => ({ client: n, runtimeUrl: s, tenantId: r }),
13
+ () => ({ client: n, runtimeUrl: s, appId: r }),
14
14
  [n, s, r]
15
15
  );
16
16
  return /* @__PURE__ */ v(j.Provider, { value: a, children: e });
@@ -193,7 +193,7 @@ function W(s) {
193
193
  e({ type: "SEND_MESSAGE", text: _ });
194
194
  const h = new AbortController();
195
195
  a.current = h, (async () => {
196
- var o, d, p, l, b, T, x, C, M, D, O;
196
+ var o, d, g, l, b, T, x, C, M, D, O;
197
197
  let f = !1;
198
198
  try {
199
199
  const I = r.chatStream(_, {
@@ -201,84 +201,84 @@ function W(s) {
201
201
  context: (o = c.current) == null ? void 0 : o.context,
202
202
  signal: h.signal
203
203
  });
204
- for await (const g of I)
205
- switch (g.type) {
204
+ for await (const p of I)
205
+ switch (p.type) {
206
206
  case "init":
207
- e({ type: "STREAM_INIT", sessionId: g.session_id }), (p = (d = c.current) == null ? void 0 : d.onSessionCreated) == null || p.call(d, g.session_id);
207
+ e({ type: "STREAM_INIT", sessionId: p.session_id }), (g = (d = c.current) == null ? void 0 : d.onSessionCreated) == null || g.call(d, p.session_id);
208
208
  break;
209
209
  case "text_delta":
210
- e({ type: "STREAM_TEXT_DELTA", content: g.content });
210
+ e({ type: "STREAM_TEXT_DELTA", content: p.content });
211
211
  break;
212
212
  case "tool_call_start":
213
213
  e({
214
214
  type: "STREAM_TOOL_CALL_START",
215
- toolId: g.tool_id,
216
- toolName: g.tool_name,
217
- parameters: g.parameters
215
+ toolId: p.tool_id,
216
+ toolName: p.tool_name,
217
+ parameters: p.parameters
218
218
  });
219
219
  break;
220
220
  case "tool_call_result":
221
221
  e({
222
222
  type: "STREAM_TOOL_CALL_RESULT",
223
- toolId: g.tool_id,
224
- status: g.status,
225
- result: g.result,
226
- duration_ms: g.duration_ms,
227
- error: g.error
223
+ toolId: p.tool_id,
224
+ status: p.status,
225
+ result: p.result,
226
+ duration_ms: p.duration_ms,
227
+ error: p.error
228
228
  }), (b = (l = c.current) == null ? void 0 : l.onToolCall) == null || b.call(l, {
229
- toolId: g.tool_id,
229
+ toolId: p.tool_id,
230
230
  toolName: "",
231
231
  parameters: {},
232
- status: g.status,
233
- result: g.result,
234
- duration_ms: g.duration_ms,
235
- error: g.error
232
+ status: p.status,
233
+ result: p.result,
234
+ duration_ms: p.duration_ms,
235
+ error: p.error
236
236
  });
237
237
  break;
238
238
  case "subagent_event":
239
239
  e({
240
240
  type: "STREAM_SUBAGENT_EVENT",
241
- parentToolId: g.parent_tool_id,
241
+ parentToolId: p.parent_tool_id,
242
242
  event: {
243
- agentName: g.agent_name,
244
- eventType: g.event_type,
245
- toolName: g.tool_name,
246
- toolArgs: g.tool_args,
247
- result: g.result,
248
- text: g.text,
249
- error: g.error,
250
- timestamp: g.timestamp
243
+ agentName: p.agent_name,
244
+ eventType: p.event_type,
245
+ toolName: p.tool_name,
246
+ toolArgs: p.tool_args,
247
+ result: p.result,
248
+ text: p.text,
249
+ error: p.error,
250
+ timestamp: p.timestamp
251
251
  }
252
252
  });
253
253
  break;
254
254
  case "widget":
255
255
  e({
256
256
  type: "STREAM_WIDGET",
257
- widgetType: g.widget_type,
258
- data: g.data
257
+ widgetType: p.widget_type,
258
+ data: p.data
259
259
  });
260
260
  break;
261
261
  case "confirmation_required": {
262
262
  const L = {
263
- endpoint: g.endpoint,
264
- method: g.method,
265
- reason: g.reason,
266
- escalated: g.escalated,
267
- params: g.params,
268
- connectionName: g.connection_name,
269
- correlationId: g.correlation_id,
263
+ endpoint: p.endpoint,
264
+ method: p.method,
265
+ reason: p.reason,
266
+ escalated: p.escalated,
267
+ params: p.params,
268
+ connectionName: p.connection_name,
269
+ correlationId: p.correlation_id,
270
270
  status: "pending"
271
271
  };
272
272
  e({ type: "STREAM_CONFIRMATION_REQUIRED", confirmation: L }), (x = (T = c.current) == null ? void 0 : T.onConfirmation) == null || x.call(T, L);
273
273
  break;
274
274
  }
275
275
  case "error":
276
- e({ type: "STREAM_ERROR", message: g.message });
276
+ e({ type: "STREAM_ERROR", message: p.message });
277
277
  break;
278
278
  case "done":
279
279
  f = !0, e({
280
280
  type: "STREAM_DONE",
281
- usage: g.usage ? { inputTokens: g.usage.input_tokens, outputTokens: g.usage.output_tokens } : void 0
281
+ usage: p.usage ? { inputTokens: p.usage.input_tokens, outputTokens: p.usage.output_tokens } : void 0
282
282
  }), (M = (C = c.current) == null ? void 0 : C.onStreamEnd) == null || M.call(C);
283
283
  break;
284
284
  default:
@@ -427,27 +427,27 @@ function ee({
427
427
  case "user":
428
428
  return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--user", "data-testid": "user-message", children: o.text }, o.id);
429
429
  case "assistant_text":
430
- return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--assistant", "data-testid": "assistant-message", children: o.contentBlocks.map((d, p) => {
430
+ return /* @__PURE__ */ v("div", { className: "amodal-chat__message amodal-chat__message--assistant", "data-testid": "assistant-message", children: o.contentBlocks.map((d, g) => {
431
431
  switch (d.type) {
432
432
  case "text":
433
- return /* @__PURE__ */ v("div", { className: "amodal-chat__text", children: r ? r(d.text) : d.text }, `text-${String(p)}`);
433
+ return /* @__PURE__ */ v("div", { className: "amodal-chat__text", children: r ? r(d.text) : d.text }, `text-${String(g)}`);
434
434
  case "tool_calls":
435
435
  return /* @__PURE__ */ v("div", { className: "amodal-chat__tool-calls", children: d.calls.map(
436
436
  (l) => t ? /* @__PURE__ */ v("div", { children: t(l) }, l.toolId) : /* @__PURE__ */ w("div", { className: "amodal-chat__tool-call", "data-testid": "tool-call", children: [
437
437
  /* @__PURE__ */ v("span", { className: "amodal-chat__tool-name", children: l.toolName }),
438
438
  /* @__PURE__ */ v("span", { className: "amodal-chat__tool-status", children: l.status })
439
439
  ] }, l.toolId)
440
- ) }, `tools-${String(p)}`);
440
+ ) }, `tools-${String(g)}`);
441
441
  case "confirmation": {
442
442
  const l = d.confirmation, b = () => {
443
443
  l.correlationId && S(l.correlationId, !0);
444
444
  }, T = () => {
445
445
  l.correlationId && S(l.correlationId, !1);
446
446
  };
447
- return e ? /* @__PURE__ */ v("div", { children: e(l, b, T) }, `conf-${String(p)}`) : l.escalated || l.params && Object.keys(l.params).length > 0 ? /* @__PURE__ */ v(J, { confirmation: l, onApprove: b, onDeny: T }, `conf-${String(p)}`) : /* @__PURE__ */ v(H, { confirmation: l, onApprove: b, onDeny: T }, `conf-${String(p)}`);
447
+ return e ? /* @__PURE__ */ v("div", { children: e(l, b, T) }, `conf-${String(g)}`) : l.escalated || l.params && Object.keys(l.params).length > 0 ? /* @__PURE__ */ v(J, { confirmation: l, onApprove: b, onDeny: T }, `conf-${String(g)}`) : /* @__PURE__ */ v(H, { confirmation: l, onApprove: b, onDeny: T }, `conf-${String(g)}`);
448
448
  }
449
449
  case "widget":
450
- return /* @__PURE__ */ v("div", { className: "amodal-chat__widget", "data-testid": "widget", children: d.widgetType }, `widget-${String(p)}`);
450
+ return /* @__PURE__ */ v("div", { className: "amodal-chat__widget", "data-testid": "widget", children: d.widgetType }, `widget-${String(g)}`);
451
451
  default:
452
452
  return null;
453
453
  }
@@ -495,7 +495,7 @@ function te({ prompt: s, label: r, context: t, onComplete: e, onError: n }) {
495
495
  }), _ = A(() => {
496
496
  a || S || (c(!0), i(s));
497
497
  }, [a, S, i, s]), h = [...u].reverse().find((o) => o.type === "assistant_text"), m = h && h.type === "assistant_text" ? h.confirmations.filter((o) => o.status === "pending") : [], f = (o, d) => {
498
- const p = () => {
498
+ const g = () => {
499
499
  o.correlationId && E(o.correlationId, !0);
500
500
  }, l = () => {
501
501
  o.correlationId && E(o.correlationId, !1);
@@ -504,7 +504,7 @@ function te({ prompt: s, label: r, context: t, onComplete: e, onError: n }) {
504
504
  J,
505
505
  {
506
506
  confirmation: o,
507
- onApprove: p,
507
+ onApprove: g,
508
508
  onDeny: l
509
509
  },
510
510
  o.correlationId ?? String(d)
@@ -512,7 +512,7 @@ function te({ prompt: s, label: r, context: t, onComplete: e, onError: n }) {
512
512
  H,
513
513
  {
514
514
  confirmation: o,
515
- onApprove: p,
515
+ onApprove: g,
516
516
  onDeny: l
517
517
  },
518
518
  o.correlationId ?? String(d)
@@ -544,14 +544,14 @@ function se(s) {
544
544
  _.current = o, i(!0), E(null);
545
545
  try {
546
546
  let d = "";
547
- const p = [];
547
+ const g = [];
548
548
  for await (const l of n.chatStream(r, { context: t, signal: o.signal }))
549
549
  switch (l.type) {
550
550
  case "text_delta":
551
551
  d += l.content;
552
552
  break;
553
553
  case "tool_call_start":
554
- p.push({
554
+ g.push({
555
555
  toolId: l.tool_id,
556
556
  toolName: l.tool_name,
557
557
  parameters: l.parameters,
@@ -559,7 +559,7 @@ function se(s) {
559
559
  });
560
560
  break;
561
561
  case "tool_call_result": {
562
- const b = p.find((T) => T.toolId === l.tool_id);
562
+ const b = g.find((T) => T.toolId === l.tool_id);
563
563
  b && (b.status = l.status, b.result = l.result, b.duration_ms = l.duration_ms, b.error = l.error);
564
564
  break;
565
565
  }
@@ -569,7 +569,7 @@ function se(s) {
569
569
  default:
570
570
  break;
571
571
  }
572
- c({ text: d, toolCalls: p });
572
+ c({ text: d, toolCalls: g });
573
573
  } catch (d) {
574
574
  d instanceof DOMException && d.name === "AbortError" || E(d instanceof Error ? d.message : "Unknown error");
575
575
  } finally {
@@ -590,11 +590,11 @@ function se(s) {
590
590
  function re(s) {
591
591
  const { prompt: r, context: t, autoFetch: e = !0 } = s, { client: n } = k(), [a, c] = y("idle"), [u, i] = y(""), [S, E] = y(""), [_, h] = y(null), m = N(null), f = N(!1), o = A(async () => {
592
592
  m.current && m.current.abort();
593
- const p = new AbortController();
594
- m.current = p, c("loading"), h(null), i(""), E("");
593
+ const g = new AbortController();
594
+ m.current = g, c("loading"), h(null), i(""), E("");
595
595
  try {
596
596
  let l = "";
597
- for await (const T of n.chatStream(r, { context: t, signal: p.signal }))
597
+ for await (const T of n.chatStream(r, { context: t, signal: g.signal }))
598
598
  switch (T.type) {
599
599
  case "text_delta":
600
600
  l += T.content;
@@ -659,7 +659,7 @@ function ae(s) {
659
659
  } finally {
660
660
  f.current = null;
661
661
  }
662
- }, [e, r, n]), p = A(() => {
662
+ }, [e, r, n]), g = A(() => {
663
663
  f.current && (f.current.abort(), f.current = null);
664
664
  }, []), l = N(d);
665
665
  return l.current = d, R(() => (t && !o.current && (o.current = !0, l.current()), () => {
@@ -671,7 +671,7 @@ function ae(s) {
671
671
  events: E,
672
672
  error: h,
673
673
  start: () => void d(),
674
- stop: p
674
+ stop: g
675
675
  };
676
676
  }
677
677
  /**
@@ -686,13 +686,13 @@ function ne(s) {
686
686
  _.current = o, i(!0), E(null);
687
687
  try {
688
688
  let d = "";
689
- for await (const p of n.chatStream(r, { context: t, signal: o.signal }))
690
- switch (p.type) {
689
+ for await (const g of n.chatStream(r, { context: t, signal: o.signal }))
690
+ switch (g.type) {
691
691
  case "text_delta":
692
- d += p.content;
692
+ d += g.content;
693
693
  break;
694
694
  case "error":
695
- E(p.message);
695
+ E(g.message);
696
696
  break;
697
697
  default:
698
698
  break;
@@ -721,10 +721,10 @@ function oe(s, r) {
721
721
  const d = new AbortController();
722
722
  m.current = d;
723
723
  try {
724
- const p = await n.getStoreDocument(s, t, d.signal);
725
- c(p.document), i(p.history), h(null);
726
- } catch (p) {
727
- p instanceof DOMException && p.name === "AbortError" || h(p instanceof Error ? p.message : "Failed to fetch document");
724
+ const g = await n.getStoreDocument(s, t, d.signal);
725
+ c(g.document), i(g.history), h(null);
726
+ } catch (g) {
727
+ g instanceof DOMException && g.name === "AbortError" || h(g instanceof Error ? g.message : "Failed to fetch document");
728
728
  } finally {
729
729
  E(!1), m.current = null;
730
730
  }
@@ -755,10 +755,10 @@ function oe(s, r) {
755
755
  * SPDX-License-Identifier: MIT
756
756
  */
757
757
  function le(s, r = {}) {
758
- const { filter: t, sort: e, limit: n = 20, refreshInterval: a = 3e4 } = r, { client: c } = k(), [u, i] = y([]), [S, E] = y(0), [_, h] = y(!1), [m, f] = y(!0), [o, d] = y(null), p = N(null), l = t ? JSON.stringify(t) : "", b = A(async () => {
759
- p.current && p.current.abort();
758
+ const { filter: t, sort: e, limit: n = 20, refreshInterval: a = 3e4 } = r, { client: c } = k(), [u, i] = y([]), [S, E] = y(0), [_, h] = y(!1), [m, f] = y(!0), [o, d] = y(null), g = N(null), l = t ? JSON.stringify(t) : "", b = A(async () => {
759
+ g.current && g.current.abort();
760
760
  const x = new AbortController();
761
- p.current = x;
761
+ g.current = x;
762
762
  try {
763
763
  const C = await c.getStoreDocuments(s, {
764
764
  filter: l ? JSON.parse(l) : void 0,
@@ -770,13 +770,13 @@ function le(s, r = {}) {
770
770
  } catch (C) {
771
771
  C instanceof DOMException && C.name === "AbortError" || d(C instanceof Error ? C.message : "Failed to fetch store list");
772
772
  } finally {
773
- f(!1), p.current = null;
773
+ f(!1), g.current = null;
774
774
  }
775
775
  }, [c, s, l, e, n]), T = A(() => {
776
776
  b();
777
777
  }, [b]);
778
778
  return R(() => (f(!0), b(), () => {
779
- p.current && p.current.abort();
779
+ g.current && g.current.abort();
780
780
  }), [b]), R(() => {
781
781
  if (a <= 0) return;
782
782
  const x = setInterval(() => {
@@ -854,7 +854,7 @@ export {
854
854
  V as RuntimeClient,
855
855
  be as TypedEventEmitter,
856
856
  Te as WidgetEventBus,
857
- ge as applyTheme,
857
+ pe as applyTheme,
858
858
  Ae as createChatClient,
859
859
  Ne as createSession,
860
860
  xe as defaultEntityExtractor,