@arcteninc/core 0.0.157 → 0.0.158

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/index.mjs CHANGED
@@ -448,7 +448,7 @@ function Cc({
448
448
  formMode: m = "auto",
449
449
  // NOTE: systemPrompt is deprecated; prompts are managed server-side per project/agent.
450
450
  systemPrompt: w = "",
451
- agentId: x,
451
+ agentId: v,
452
452
  agentName: T,
453
453
  projectId: b,
454
454
  enableRemoteConfig: M,
@@ -457,12 +457,12 @@ function Cc({
457
457
  conversationId: R,
458
458
  state: L,
459
459
  onStateChange: D,
460
- allowStateEdits: C = !0,
460
+ allowStateEdits: A = !0,
461
461
  onToolCall: j,
462
462
  onFinish: k,
463
463
  sources: N,
464
464
  ragConfig: B,
465
- ragFilters: V,
465
+ ragFilters: I,
466
466
  // Deprecated: use ragConfig or sources instead
467
467
  secureInputHandler: U
468
468
  // Optional: custom secure input handler for React-less usage
@@ -470,20 +470,20 @@ function Cc({
470
470
  const W = e.replace(/\/+$/, ""), [H, G] = O(null), [ae, xe] = O(!1), [He, Ct] = O(null), ot = ee(() => {
471
471
  const p = N || [], g = H?.config?.sources || [];
472
472
  return [.../* @__PURE__ */ new Set([...p, ...g])];
473
- }, [N, H]), Y = ee(() => B !== void 0 ? B : V ? { enabled: !0, filters: V } : ot && ot.length > 0 ? {
473
+ }, [N, H]), Y = ee(() => B !== void 0 ? B : I ? { enabled: !0, filters: I } : ot && ot.length > 0 ? {
474
474
  enabled: !0,
475
475
  organizationId: ot[0],
476
476
  // Use first source as default
477
477
  autoExecute: !0,
478
478
  filters: void 0
479
- } : { enabled: !1 }, [ot, B, V]), Bt = ee(() => M === !1 ? !1 : !!b, [b, M]);
479
+ } : { enabled: !1 }, [ot, B, I]), Bt = ee(() => M === !1 ? !1 : !!b, [b, M]);
480
480
  re(() => {
481
481
  if (!Bt || !le.current)
482
482
  return;
483
483
  (async () => {
484
484
  xe(!0), Ct(null);
485
485
  try {
486
- const y = `${E || W.replace("/chat", "").replace(/\/$/, "")}/convex/api/query`, v = await fetch(y, {
486
+ const y = `${E || W.replace("/chat", "").replace(/\/$/, "")}/convex/api/query`, x = await fetch(y, {
487
487
  method: "POST",
488
488
  headers: {
489
489
  "Content-Type": "application/json",
@@ -491,20 +491,20 @@ function Cc({
491
491
  },
492
492
  body: JSON.stringify({
493
493
  path: "agents:getConfigForClient",
494
- args: { projectId: b, agentName: T, agentId: x },
494
+ args: { projectId: b, agentName: T, agentId: v },
495
495
  format: "json"
496
496
  })
497
497
  });
498
- if (!v.ok) {
499
- if (v.status === 404) {
498
+ if (!x.ok) {
499
+ if (x.status === 404) {
500
500
  console.warn("[useAgent] Remote config endpoint not found (404), using local tools only"), G(null);
501
501
  return;
502
502
  }
503
- const I = await v.text().catch(() => "Unknown error");
504
- throw new Error(`Failed to fetch remote config: ${v.status} ${I}`);
503
+ const V = await x.text().catch(() => "Unknown error");
504
+ throw new Error(`Failed to fetch remote config: ${x.status} ${V}`);
505
505
  }
506
- const A = await v.json();
507
- G(A?.value || null), console.log("[useAgent] Remote config loaded successfully:", A?.value);
506
+ const C = await x.json();
507
+ G(C?.value || null), console.log("[useAgent] Remote config loaded successfully:", C?.value);
508
508
  } catch (g) {
509
509
  console.error("[useAgent] Failed to fetch remote config:", g);
510
510
  const y = g instanceof Error ? g : new Error(String(g));
@@ -513,32 +513,32 @@ function Cc({
513
513
  xe(!1);
514
514
  }
515
515
  })();
516
- }, [Bt, b, T, x, W, E]);
516
+ }, [Bt, b, T, v, W, E]);
517
517
  const Ve = ee(() => {
518
518
  const p = {};
519
519
  if (c)
520
520
  for (const [g, y] of Object.entries(c))
521
521
  if (p[g] = {}, Array.isArray(y))
522
- for (const v of y) {
523
- const A = Mn(v);
524
- p[g][v] = A || "text";
522
+ for (const x of y) {
523
+ const C = Mn(x);
524
+ p[g][x] = C || "text";
525
525
  }
526
526
  else
527
- for (const [v, A] of Object.entries(y))
528
- p[g][v] = A;
527
+ for (const [x, C] of Object.entries(y))
528
+ p[g][x] = C;
529
529
  if (l) {
530
530
  for (const [g, y] of Object.entries(l))
531
531
  if (y && typeof y == "object" && "sensitiveParams" in y) {
532
532
  p[g] || (p[g] = {});
533
- const v = y.sensitiveParams;
534
- if (Array.isArray(v))
535
- for (const A of v) {
536
- const I = Mn(A);
537
- p[g][A] = I || "text";
533
+ const x = y.sensitiveParams;
534
+ if (Array.isArray(x))
535
+ for (const C of x) {
536
+ const V = Mn(C);
537
+ p[g][C] = V || "text";
538
538
  }
539
- else if (v && typeof v == "object")
540
- for (const [A, I] of Object.entries(v))
541
- p[g][A] = I;
539
+ else if (x && typeof x == "object")
540
+ for (const [C, V] of Object.entries(x))
541
+ p[g][C] = V;
542
542
  }
543
543
  }
544
544
  return p;
@@ -551,13 +551,13 @@ function Cc({
551
551
  if (!y) return g;
552
552
  try {
553
553
  return jo(p, g, y);
554
- } catch (v) {
555
- return console.error(`[useAgent] Failed to redact output for ${p}:`, v), {
554
+ } catch (x) {
555
+ return console.error(`[useAgent] Failed to redact output for ${p}:`, x), {
556
556
  value: ds,
557
557
  [us]: {
558
558
  tool: p,
559
559
  redacted: !0,
560
- error: String(v)
560
+ error: String(x)
561
561
  }
562
562
  };
563
563
  }
@@ -571,7 +571,7 @@ function Cc({
571
571
  if (!Oe || !le.current)
572
572
  return;
573
573
  const y = async () => {
574
- const A = `${W.replace("/chat", "").replace(/\/$/, "")}/convex/api/mutation`, I = await fetch(A, {
574
+ const C = `${W.replace("/chat", "").replace(/\/$/, "")}/convex/api/mutation`, V = await fetch(C, {
575
575
  method: "POST",
576
576
  headers: {
577
577
  "Content-Type": "application/json",
@@ -583,25 +583,25 @@ function Cc({
583
583
  format: "json"
584
584
  })
585
585
  });
586
- if (!I.ok) {
587
- if (I.status === 404) {
586
+ if (!V.ok) {
587
+ if (V.status === 404) {
588
588
  console.warn("[useAgent] Convex API endpoint not available (404), state changes will not be persisted");
589
589
  return;
590
590
  }
591
- const $ = await I.text().catch(() => "Unknown error");
592
- throw new Error(`Failed to sync conversation state: ${I.status} ${$}`);
591
+ const $ = await V.text().catch(() => "Unknown error");
592
+ throw new Error(`Failed to sync conversation state: ${V.status} ${$}`);
593
593
  }
594
594
  };
595
- for (let v = 0; v < g; v++)
595
+ for (let x = 0; x < g; x++)
596
596
  try {
597
597
  await y(), Ze(null);
598
598
  return;
599
- } catch (A) {
600
- if (v === g - 1) {
601
- const $ = A instanceof Error ? A : new Error(String(A));
602
- throw Ze($), console.error("Failed to sync state to Convex after retries:", A), $;
599
+ } catch (C) {
600
+ if (x === g - 1) {
601
+ const $ = C instanceof Error ? C : new Error(String(C));
602
+ throw Ze($), console.error("Failed to sync state to Convex after retries:", C), $;
603
603
  }
604
- await new Promise(($) => setTimeout($, Math.pow(2, v) * 100));
604
+ await new Promise(($) => setTimeout($, Math.pow(2, x) * 100));
605
605
  }
606
606
  }, [Oe, W, le]), De = ee(() => function() {
607
607
  return we.current;
@@ -610,8 +610,8 @@ function Cc({
610
610
  we.current = y, de || mt(y), D && D(y);
611
611
  try {
612
612
  await Zn(g);
613
- } catch (v) {
614
- throw v;
613
+ } catch (x) {
614
+ throw x;
615
615
  }
616
616
  }, [Zn, D, de]);
617
617
  re(() => {
@@ -623,12 +623,12 @@ function Cc({
623
623
  if (U)
624
624
  return;
625
625
  const y = Es.get(p);
626
- y && (y(g), at((v) => {
627
- const A = new Map(v);
628
- return A.delete(p), A;
629
- }), Yn((v) => {
630
- const A = new Map(v);
631
- return A.delete(p), A;
626
+ y && (y(g), at((x) => {
627
+ const C = new Map(x);
628
+ return C.delete(p), C;
629
+ }), Yn((x) => {
630
+ const C = new Map(x);
631
+ return C.delete(p), C;
632
632
  }));
633
633
  }, [Es, U]), Wt = ke((p) => U ? U.showSecureForm(p) : new Promise((g) => {
634
634
  Hn((y) => new Map(y).set(p.id, p)), _t((y) => new Map(y).set(p.id, g));
@@ -636,37 +636,37 @@ function Cc({
636
636
  if (U)
637
637
  return;
638
638
  const y = Jn.get(p);
639
- y && (y(g), Hn((v) => {
640
- const A = new Map(v);
641
- return A.delete(p), A;
642
- }), _t((v) => {
643
- const A = new Map(v);
644
- return A.delete(p), A;
639
+ y && (y(g), Hn((x) => {
640
+ const C = new Map(x);
641
+ return C.delete(p), C;
642
+ }), _t((x) => {
643
+ const C = new Map(x);
644
+ return C.delete(p), C;
645
645
  }));
646
646
  }, [Jn, U]), es = ke((p, g) => {
647
- const y = Ve[p] || {}, v = Object.keys(y).length > 0;
647
+ const y = Ve[p] || {}, x = Object.keys(y).length > 0;
648
648
  if (d) {
649
- const A = Object.keys(g).filter((I) => Mn(I) !== null);
650
- return v || A.length > 0;
649
+ const C = Object.keys(g).filter((V) => Mn(V) !== null);
650
+ return x || C.length > 0;
651
651
  }
652
- return v;
652
+ return x;
653
653
  }, [Ve, d]), ts = ke((p, g) => {
654
- const v = { ...Ve[p] || {} };
654
+ const x = { ...Ve[p] || {} };
655
655
  if (d) {
656
- for (const I of Object.keys(g))
657
- if (!(I in v)) {
658
- const $ = Mn(I);
659
- $ && (v[I] = $);
656
+ for (const V of Object.keys(g))
657
+ if (!(V in x)) {
658
+ const $ = Mn(V);
659
+ $ && (x[V] = $);
660
660
  }
661
661
  }
662
- const A = Object.entries(v).filter(
663
- ([I]) => Object.prototype.hasOwnProperty.call(g, I)
662
+ const C = Object.entries(x).filter(
663
+ ([V]) => Object.prototype.hasOwnProperty.call(g, V)
664
664
  );
665
- return A.length > 0 ? Object.fromEntries(A) : v;
666
- }, [Ve, d]), Qe = ee(() => Y?.enabled ? async function(g, y = 20, v) {
667
- const A = {
665
+ return C.length > 0 ? Object.fromEntries(C) : x;
666
+ }, [Ve, d]), Qe = ee(() => Y?.enabled ? async function(g, y = 20, x) {
667
+ const C = {
668
668
  ...Y.filters,
669
- ...v
669
+ ...x
670
670
  };
671
671
  if (N && N.length > 1) {
672
672
  const $ = N.map(
@@ -680,7 +680,7 @@ function Cc({
680
680
  q: g,
681
681
  k: Math.min(y, 100),
682
682
  organizationId: q,
683
- ...Object.keys(A).length > 0 ? { filters: A } : {}
683
+ ...Object.keys(C).length > 0 ? { filters: C } : {}
684
684
  })
685
685
  }).then((oe) => oe.ok ? oe.json() : null)
686
686
  ), ce = await Promise.all($), te = [];
@@ -716,13 +716,13 @@ function Cc({
716
716
  summary: `Found ${te.length} relevant results across ${N.length} source(s) for "${g}". Top result: ${Te[0]?.title || "N/A"}`
717
717
  };
718
718
  }
719
- const I = Y.organizationId && Y.organizationId !== "default" ? Y.organizationId : N && N.length > 0 ? N[0] : void 0;
719
+ const V = Y.organizationId && Y.organizationId !== "default" ? Y.organizationId : N && N.length > 0 ? N[0] : void 0;
720
720
  try {
721
721
  const $ = {
722
722
  q: g,
723
723
  k: Math.min(y, 100)
724
724
  };
725
- I && ($.organizationId = I), Object.keys(A).length > 0 && ($.filters = A);
725
+ V && ($.organizationId = V), Object.keys(C).length > 0 && ($.filters = C);
726
726
  const ce = {
727
727
  "Content-Type": "application/json"
728
728
  };
@@ -771,29 +771,29 @@ function Cc({
771
771
  };
772
772
  }
773
773
  } : null, [Y, W, le]), et = ee(() => Y?.enabled ? async function(g, y) {
774
- const v = Y.organizationId && Y.organizationId !== "default" ? Y.organizationId : N && N.length > 0 ? N[0] : void 0;
774
+ const x = Y.organizationId && Y.organizationId !== "default" ? Y.organizationId : N && N.length > 0 ? N[0] : void 0;
775
775
  try {
776
- const A = {
776
+ const C = {
777
777
  "Content-Type": "application/json"
778
778
  };
779
- le.current && (A.Authorization = `Bearer ${le.current}`);
780
- const I = await fetch(`${W}/fetch`, {
779
+ le.current && (C.Authorization = `Bearer ${le.current}`);
780
+ const V = await fetch(`${W}/fetch`, {
781
781
  method: "POST",
782
- headers: A,
782
+ headers: C,
783
783
  body: JSON.stringify({
784
784
  doc_id: g,
785
785
  block_ids: y,
786
- ...v ? { organizationId: v } : {}
786
+ ...x ? { organizationId: x } : {}
787
787
  })
788
788
  });
789
- if (!I.ok) {
790
- const ce = await I.text();
789
+ if (!V.ok) {
790
+ const ce = await V.text();
791
791
  return {
792
792
  success: !1,
793
- error: `Fetch failed: ${I.status} ${ce}`
793
+ error: `Fetch failed: ${V.status} ${ce}`
794
794
  };
795
795
  }
796
- const $ = await I.json();
796
+ const $ = await V.json();
797
797
  return {
798
798
  success: !0,
799
799
  blocks: $.blocks || [],
@@ -802,10 +802,10 @@ function Cc({
802
802
  pageTitle: $.pageTitle || "",
803
803
  summary: `Fetched ${$.blocks?.length || 0} blocks from ${$.pageTitle || g}`
804
804
  };
805
- } catch (A) {
805
+ } catch (C) {
806
806
  return {
807
807
  success: !1,
808
- error: A instanceof Error ? A.message : "Unknown error occurred"
808
+ error: C instanceof Error ? C.message : "Unknown error occurred"
809
809
  };
810
810
  }
811
811
  } : null, [Y, W, le]), Sn = ee(() => {
@@ -823,24 +823,24 @@ function Cc({
823
823
  ...Sn,
824
824
  ...i
825
825
  ];
826
- return We && (p.push(De), (!de || C) && p.push(pt)), tt && (Qe && p.push(Qe), et && p.push(et)), p;
827
- }, [Sn, i, De, pt, Qe, et, We, tt, de, C]), ss = ee(() => [...Sn, ...i], [Sn, i]), ut = ee(() => Io(ss, l), [ss, l]), Dt = ee(() => {
826
+ return We && (p.push(De), (!de || A) && p.push(pt)), tt && (Qe && p.push(Qe), et && p.push(et)), p;
827
+ }, [Sn, i, De, pt, Qe, et, We, tt, de, A]), ss = ee(() => [...Sn, ...i], [Sn, i]), ut = ee(() => Io(ss, l), [ss, l]), Dt = ee(() => {
828
828
  const p = /* @__PURE__ */ new Map(), g = new Map(ut.map((y) => [y.name, y]));
829
- return p.set("getState", De), (!de || C) && p.set("setState", pt), Y?.enabled && (Qe && p.set("searchDocs", Qe), et && p.set("fetchDocContent", et)), ns.forEach((y) => {
829
+ return p.set("getState", De), (!de || A) && p.set("setState", pt), Y?.enabled && (Qe && p.set("searchDocs", Qe), et && p.set("fetchDocContent", et)), ns.forEach((y) => {
830
830
  if (y === De || y === pt || y === Qe || y === et)
831
831
  return;
832
- const v = y[Ge];
833
- if (v) {
834
- const I = g.get(v);
835
- if (I) {
836
- p.set(I.name, y);
832
+ const x = y[Ge];
833
+ if (x) {
834
+ const V = g.get(x);
835
+ if (V) {
836
+ p.set(V.name, y);
837
837
  return;
838
838
  }
839
839
  }
840
- const A = ut.find((I) => I.name === y.name);
841
- A && p.set(A.name, y);
840
+ const C = ut.find((V) => V.name === y.name);
841
+ C && p.set(C.name, y);
842
842
  }), p;
843
- }, [ns, ut, De, pt, Qe, et, Y, de, C]), rs = ee(() => new Set(ut.map((p) => p.name)), [ut]), Pn = ee(() => {
843
+ }, [ns, ut, De, pt, Qe, et, Y, de, A]), rs = ee(() => new Set(ut.map((p) => p.name)), [ut]), Pn = ee(() => {
844
844
  const p = [];
845
845
  We && (p.push({
846
846
  name: "getState",
@@ -850,7 +850,7 @@ function Cc({
850
850
  properties: {},
851
851
  required: []
852
852
  }
853
- }), (!de || C) && p.push({
853
+ }), (!de || A) && p.push({
854
854
  name: "setState",
855
855
  description: "Update the agent state. Store IDs, workflow state, checklists, context, and other data that must persist across conversations. Merges with existing state.",
856
856
  jsonSchema: {
@@ -917,32 +917,32 @@ function Cc({
917
917
  }
918
918
  );
919
919
  const y = [];
920
- return H?.config?.workflows && H.config.workflows.forEach((v) => {
921
- const A = {}, I = [];
922
- v.parameters && v.parameters.forEach(($) => {
923
- A[$.name] = {
920
+ return H?.config?.workflows && H.config.workflows.forEach((x) => {
921
+ const C = {}, V = [];
922
+ x.parameters && x.parameters.forEach(($) => {
923
+ C[$.name] = {
924
924
  type: $.type || "string",
925
925
  description: $.description
926
- }, $.required && I.push($.name);
926
+ }, $.required && V.push($.name);
927
927
  }), y.push({
928
- name: `workflow_${v.name.replace(/\s+/g, "_").toLowerCase()}`,
929
- description: v.description || `Execute the "${v.name}" workflow. ${v.contentPlaintext?.slice(0, 200) || ""}`,
928
+ name: `workflow_${x.name.replace(/\s+/g, "_").toLowerCase()}`,
929
+ description: x.description || `Execute the "${x.name}" workflow. ${x.contentPlaintext?.slice(0, 200) || ""}`,
930
930
  jsonSchema: {
931
931
  type: "object",
932
- properties: A,
933
- required: I
932
+ properties: C,
933
+ required: V
934
934
  },
935
935
  // Store workflow metadata for execution
936
- _workflow: v
936
+ _workflow: x
937
937
  });
938
938
  }), [...ut, ...p, ...g, ...y];
939
- }, [ut, We, tt, de, C, H]), gt = ee(() => Pn.filter((p) => p.name === "getState" ? We : p.name === "setState" ? We && (!de || C) : p.name === "searchDocs" || p.name === "fetchDocContent" ? tt : p.name.startsWith("workflow_") ? !0 : rs.has(p.name)), [Pn, rs, We, tt, de, C]), Kt = ee(() => {
939
+ }, [ut, We, tt, de, A, H]), gt = ee(() => Pn.filter((p) => p.name === "getState" ? We : p.name === "setState" ? We && (!de || A) : p.name === "searchDocs" || p.name === "fetchDocContent" ? tt : p.name.startsWith("workflow_") ? !0 : rs.has(p.name)), [Pn, rs, We, tt, de, A]), Kt = ee(() => {
940
940
  const p = /* @__PURE__ */ new Set();
941
941
  return We && (p.add("getState"), p.add("setState")), tt && Y?.autoExecute !== !1 && (p.add("searchDocs"), p.add("fetchDocContent")), H?.config?.tools ? H.config.tools.forEach((g) => {
942
942
  g.isEnabled && !g.requiresApproval && p.add(g.name);
943
943
  }) : (i.forEach((g) => {
944
- for (const [y, v] of Dt.entries())
945
- if (v === g) {
944
+ for (const [y, x] of Dt.entries())
945
+ if (x === g) {
946
946
  p.add(y);
947
947
  break;
948
948
  }
@@ -977,10 +977,10 @@ function Cc({
977
977
  if (!bn || s || n)
978
978
  return;
979
979
  Xe.current && clearTimeout(Xe.current);
980
- const p = Math.floor(Date.now() / 1e3), g = bn - p, v = Math.max(0, g - 5);
980
+ const p = Math.floor(Date.now() / 1e3), g = bn - p, x = Math.max(0, g - 5);
981
981
  return Xe.current = setTimeout(async () => {
982
982
  try {
983
- const A = await fetch(t, {
983
+ const C = await fetch(t, {
984
984
  method: "POST",
985
985
  headers: {
986
986
  "Content-Type": "application/json"
@@ -989,14 +989,14 @@ function Cc({
989
989
  user: r
990
990
  })
991
991
  });
992
- if (!A.ok)
992
+ if (!C.ok)
993
993
  throw new Error("Failed to refresh token");
994
- const I = await A.json();
995
- gn(I.clientToken), le.current = I.clientToken, Gn(I.expiresAt), kt(null);
996
- } catch (A) {
997
- console.error("[useAgent] Token refresh failed:", A), kt(A instanceof Error ? A.message : "Failed to refresh token");
994
+ const V = await C.json();
995
+ gn(V.clientToken), le.current = V.clientToken, Gn(V.expiresAt), kt(null);
996
+ } catch (C) {
997
+ console.error("[useAgent] Token refresh failed:", C), kt(C instanceof Error ? C.message : "Failed to refresh token");
998
998
  }
999
- }, v * 1e3), () => {
999
+ }, x * 1e3), () => {
1000
1000
  Xe.current && clearTimeout(Xe.current);
1001
1001
  };
1002
1002
  }, [bn, t, JSON.stringify(r), s, n]);
@@ -1004,18 +1004,18 @@ function Cc({
1004
1004
  const y = g.headers ? new Headers(g.headers) : new Headers();
1005
1005
  y.delete("user-agent"), y.delete("User-Agent"), console.log("[useAgent] Making request to:", p), console.log("[useAgent] Method:", g.method || "GET"), console.log("[useAgent] Has Authorization header:", y.has("Authorization")), console.log("[useAgent] Client token available:", !!le.current);
1006
1006
  try {
1007
- const v = await fetch(p, {
1007
+ const x = await fetch(p, {
1008
1008
  ...g,
1009
1009
  headers: y
1010
1010
  });
1011
- if (!v.ok) {
1012
- console.error("[useAgent] Request failed:", v.status, v.statusText);
1013
- const A = await v.text().catch(() => "Unable to read error response");
1014
- console.error("[useAgent] Error response:", A);
1011
+ if (!x.ok) {
1012
+ console.error("[useAgent] Request failed:", x.status, x.statusText);
1013
+ const C = await x.text().catch(() => "Unable to read error response");
1014
+ console.error("[useAgent] Error response:", C);
1015
1015
  }
1016
- return v;
1017
- } catch (v) {
1018
- throw console.error("[useAgent] Fetch error:", v), v;
1016
+ return x;
1017
+ } catch (x) {
1018
+ throw console.error("[useAgent] Fetch error:", x), x;
1019
1019
  }
1020
1020
  }, Cn = pe(null), An = `${W}/chat`;
1021
1021
  console.log("[useAgent] Chat API URL:", An);
@@ -1031,36 +1031,39 @@ function Cc({
1031
1031
  },
1032
1032
  body: () => {
1033
1033
  console.log("[ArctenAgent] body() agentName =", T);
1034
- const p = gt.map((v) => ({
1035
- name: v.name,
1036
- description: v.description,
1037
- inputSchema: v.jsonSchema
1034
+ const p = gt.map((x) => ({
1035
+ name: x.name,
1036
+ description: x.description,
1037
+ inputSchema: x.jsonSchema
1038
1038
  // JSON Schema format from build-time
1039
- })), g = p.filter((v) => v.name === "getState" || v.name === "setState").map((v) => v.name), y = p.filter((v) => v.name === "searchDocs" || v.name === "fetchDocContent").map((v) => v.name);
1039
+ })), g = p.filter((x) => x.name === "getState" || x.name === "setState").map((x) => x.name), y = p.filter((x) => x.name === "searchDocs" || x.name === "fetchDocContent").map((x) => x.name);
1040
1040
  return g.length > 0 && console.log("[useAgent] State tools included in tools list sent to AI SDK:", g), y.length > 0 ? console.log("[useAgent] RAG tools included in tools list sent to AI SDK:", y) : Y?.enabled && console.warn("[useAgent] RAG is enabled but no RAG tools found in tools list!"), {
1041
1041
  tools: p,
1042
- ...x && { agentId: x },
1042
+ ...v && { agentId: v },
1043
1043
  ...T && { agentName: T },
1044
1044
  state: we.current,
1045
1045
  // Always include current state
1046
- ...V && { ragFilters: V }
1046
+ ...I && { ragFilters: I }
1047
1047
  };
1048
1048
  }
1049
1049
  }),
1050
1050
  sendAutomaticallyWhen: (p) => {
1051
- const g = p.messages, y = g[g.length - 1];
1052
- if (y?.role !== "assistant" || Cn.current === y.id)
1051
+ const g = p.messages;
1052
+ if (g[g.length - 1]?.role !== "assistant")
1053
1053
  return !1;
1054
- const v = nc(p);
1055
- return v && (Cn.current = y.id), v;
1054
+ const C = [...g].reverse().find(($) => $.role === "user")?.id;
1055
+ if (C && Cn.current === C)
1056
+ return !1;
1057
+ const V = nc(p);
1058
+ return V && C && (Cn.current = C), V;
1056
1059
  }
1057
1060
  }), je = S, ie = ke((p) => (Cn.current = null, je(p)), [je]), he = ke(
1058
1061
  (p, g, y) => {
1059
- const v = Ne(p, y);
1062
+ const x = Ne(p, y);
1060
1063
  J({
1061
1064
  toolCallId: g,
1062
1065
  tool: p,
1063
- output: v
1066
+ output: x
1064
1067
  });
1065
1068
  },
1066
1069
  [J, Ne]
@@ -1069,31 +1072,31 @@ function Cc({
1069
1072
  nt.forEach((p) => {
1070
1073
  p.role === "assistant" && p.parts.forEach((g) => {
1071
1074
  if (!g.type?.startsWith("tool-") || g.state !== "input-available") return;
1072
- const y = g.type.replace("tool-", ""), v = g.toolCallId;
1073
- if (xn.current.has(v)) return;
1074
- xn.current.add(v);
1075
- const A = yc(g.input);
1076
- if (es(y, A)) {
1077
- const I = ts(y, A), $ = Object.entries(I).filter(
1078
- ([q]) => A[q] !== void 0
1079
- ), ce = $.length > 0 ? Object.fromEntries($) : I, te = Object.keys(A), Te = gc(A, ce);
1075
+ const y = g.type.replace("tool-", ""), x = g.toolCallId;
1076
+ if (xn.current.has(x)) return;
1077
+ xn.current.add(x);
1078
+ const C = yc(g.input);
1079
+ if (es(y, C)) {
1080
+ const V = ts(y, C), $ = Object.entries(V).filter(
1081
+ ([q]) => C[q] !== void 0
1082
+ ), ce = $.length > 0 ? Object.fromEntries($) : V, te = Object.keys(C), Te = gc(C, ce);
1080
1083
  (async () => {
1081
1084
  try {
1082
1085
  const q = uc(
1083
1086
  y,
1084
1087
  te,
1085
1088
  ce,
1086
- A
1089
+ C
1087
1090
  ), oe = {
1088
- id: `${v}-form`,
1091
+ id: `${x}-form`,
1089
1092
  toolName: y,
1090
- toolCallId: v,
1093
+ toolCallId: x,
1091
1094
  title: q.title,
1092
1095
  description: q.description,
1093
1096
  fields: q.fields
1094
1097
  }, rt = await Wt(oe);
1095
1098
  if (rt === null) {
1096
- he(y, v, "User cancelled secure input");
1099
+ he(y, x, "User cancelled secure input");
1097
1100
  return;
1098
1101
  }
1099
1102
  const kn = { ...Te, ...rt }, Ns = Dt.get(y);
@@ -1106,9 +1109,9 @@ function Cc({
1106
1109
  Ds = await Ns(...Pl);
1107
1110
  } else
1108
1111
  Ds = await Ns(...Object.values(kn));
1109
- he(y, v, Ds);
1112
+ he(y, x, Ds);
1110
1113
  } catch (q) {
1111
- console.error(`[useAgent] Error executing tool with secure input ${y}:`, q), he(y, v, `Error: ${q}`);
1114
+ console.error(`[useAgent] Error executing tool with secure input ${y}:`, q), he(y, x, `Error: ${q}`);
1112
1115
  }
1113
1116
  })();
1114
1117
  return;
@@ -1121,10 +1124,10 @@ function Cc({
1121
1124
  throw new Error(`Workflow metadata not found for ${y}`);
1122
1125
  let ce;
1123
1126
  if ($.webhook?.url) {
1124
- let te = A;
1127
+ let te = C;
1125
1128
  if ($.webhook.bodyTemplate) {
1126
1129
  let q = $.webhook.bodyTemplate;
1127
- Object.entries(A).forEach(([oe, rt]) => {
1130
+ Object.entries(C).forEach(([oe, rt]) => {
1128
1131
  q = q.replace(new RegExp(`\\{\\{${oe}\\}\\}`, "g"), String(rt));
1129
1132
  }), te = JSON.parse(q);
1130
1133
  }
@@ -1148,42 +1151,42 @@ function Cc({
1148
1151
  message: `Workflow "${$.name}" acknowledged. Follow the workflow instructions to proceed.`,
1149
1152
  instructions: $.contentPlaintext
1150
1153
  };
1151
- he(y, v, ce);
1152
- } catch (I) {
1153
- console.error(`[useAgent] Error executing workflow ${y}:`, I), he(y, v, `Error: ${I}`);
1154
+ he(y, x, ce);
1155
+ } catch (V) {
1156
+ console.error(`[useAgent] Error executing workflow ${y}:`, V), he(y, x, `Error: ${V}`);
1154
1157
  }
1155
1158
  })();
1156
1159
  return;
1157
1160
  }
1158
- if (Kt.has(y) && !es(y, A)) {
1159
- const I = Dt.get(y);
1160
- I ? (async () => {
1161
+ if (Kt.has(y) && !es(y, C)) {
1162
+ const V = Dt.get(y);
1163
+ V ? (async () => {
1161
1164
  try {
1162
1165
  const $ = gt.find((te) => te.name === y);
1163
1166
  let ce;
1164
1167
  if ($ && $.jsonSchema?.properties) {
1165
- const Te = Object.keys($.jsonSchema.properties).map((q) => A[q]);
1166
- ce = await I(...Te);
1168
+ const Te = Object.keys($.jsonSchema.properties).map((q) => C[q]);
1169
+ ce = await V(...Te);
1167
1170
  } else if (y === "getState")
1168
- ce = I();
1171
+ ce = V();
1169
1172
  else if (y === "setState") {
1170
- const te = A.updates || A;
1171
- ce = await I(te);
1173
+ const te = C.updates || C;
1174
+ ce = await V(te);
1172
1175
  } else
1173
- ce = await I(...Object.values(A));
1174
- he(y, v, ce);
1176
+ ce = await V(...Object.values(C));
1177
+ he(y, x, ce);
1175
1178
  } catch ($) {
1176
- console.error(`[useAgent] Error executing tool ${y}:`, $), he(y, v, `Error: ${$}`);
1179
+ console.error(`[useAgent] Error executing tool ${y}:`, $), he(y, x, `Error: ${$}`);
1177
1180
  }
1178
1181
  })() : console.warn(`[useAgent] Tool ${y} not found in toolsMap`);
1179
1182
  } else y.startsWith("workflow_") && j ? j({ toolCall: {
1180
- toolCallId: v,
1183
+ toolCallId: x,
1181
1184
  toolName: y,
1182
- args: A
1185
+ args: C
1183
1186
  } }) : j && j({ toolCall: {
1184
- toolCallId: v,
1187
+ toolCallId: x,
1185
1188
  toolName: y,
1186
- args: A
1189
+ args: C
1187
1190
  } });
1188
1191
  });
1189
1192
  });
@@ -1236,11 +1239,11 @@ function Cc({
1236
1239
  })
1237
1240
  });
1238
1241
  if (!g.ok) {
1239
- const A = await g.text().catch(() => "Unknown error");
1240
- throw new Error(`Failed to fetch conversation state: ${g.status} ${A}`);
1242
+ const C = await g.text().catch(() => "Unknown error");
1243
+ throw new Error(`Failed to fetch conversation state: ${g.status} ${C}`);
1241
1244
  }
1242
- const v = (await g.json())?.value || {};
1243
- we.current = v, de || mt(v), D && D(v), Nt.current = !0;
1245
+ const x = (await g.json())?.value || {};
1246
+ we.current = x, de || mt(x), D && D(x), Nt.current = !0;
1244
1247
  } catch (g) {
1245
1248
  console.error("Failed to fetch state:", g);
1246
1249
  const y = g instanceof Error ? g : new Error(String(g));
@@ -1260,8 +1263,8 @@ function Cc({
1260
1263
  });
1261
1264
  if (!g.ok)
1262
1265
  throw new Error(`Failed to fetch messages: ${g.statusText}`);
1263
- const v = (await g.json()).messages || [];
1264
- Z(v);
1266
+ const x = (await g.json()).messages || [];
1267
+ Z(x);
1265
1268
  } catch (g) {
1266
1269
  console.error("Failed to load conversation messages:", g);
1267
1270
  } finally {
@@ -1297,42 +1300,42 @@ function Cc({
1297
1300
  if (!g.startsWith("workflow_"))
1298
1301
  throw new Error(`${g} is not a workflow tool`);
1299
1302
  try {
1300
- const A = gt.find(($) => $.name === g)?._workflow;
1301
- if (!A)
1303
+ const C = gt.find(($) => $.name === g)?._workflow;
1304
+ if (!C)
1302
1305
  throw new Error(`Workflow metadata not found for ${g}`);
1303
- let I;
1304
- if (A.webhook?.url) {
1306
+ let V;
1307
+ if (C.webhook?.url) {
1305
1308
  let $ = y;
1306
- if (A.webhook.bodyTemplate) {
1307
- let te = A.webhook.bodyTemplate;
1309
+ if (C.webhook.bodyTemplate) {
1310
+ let te = C.webhook.bodyTemplate;
1308
1311
  Object.entries(y).forEach(([Te, q]) => {
1309
1312
  te = te.replace(new RegExp(`\\{\\{${Te}\\}\\}`, "g"), String(q));
1310
1313
  }), $ = JSON.parse(te);
1311
1314
  }
1312
- const ce = await fetch(A.webhook.url, {
1313
- method: A.webhook.method || "POST",
1315
+ const ce = await fetch(C.webhook.url, {
1316
+ method: C.webhook.method || "POST",
1314
1317
  headers: {
1315
1318
  "Content-Type": "application/json",
1316
- ...A.webhook.headers || {}
1319
+ ...C.webhook.headers || {}
1317
1320
  },
1318
1321
  body: JSON.stringify($)
1319
1322
  });
1320
1323
  if (ce.ok)
1321
- I = { success: !0, data: await ce.json().catch(() => ({ success: !0 })) };
1324
+ V = { success: !0, data: await ce.json().catch(() => ({ success: !0 })) };
1322
1325
  else {
1323
1326
  const te = await ce.text();
1324
- I = { success: !1, error: `Webhook failed: ${ce.status} ${te}` };
1327
+ V = { success: !1, error: `Webhook failed: ${ce.status} ${te}` };
1325
1328
  }
1326
1329
  } else
1327
- I = {
1330
+ V = {
1328
1331
  success: !0,
1329
- message: `Workflow "${A.name}" acknowledged. Follow the workflow instructions to proceed.`,
1330
- instructions: A.contentPlaintext
1332
+ message: `Workflow "${C.name}" acknowledged. Follow the workflow instructions to proceed.`,
1333
+ instructions: C.contentPlaintext
1331
1334
  };
1332
- return fe({ toolCallId: p, tool: g, output: I }), I;
1333
- } catch (v) {
1334
- const A = { success: !1, error: String(v) };
1335
- throw fe({ toolCallId: p, tool: g, output: A }), v;
1335
+ return fe({ toolCallId: p, tool: g, output: V }), V;
1336
+ } catch (x) {
1337
+ const C = { success: !1, error: String(x) };
1338
+ throw fe({ toolCallId: p, tool: g, output: C }), x;
1336
1339
  }
1337
1340
  }
1338
1341
  async function Pe(p) {
@@ -1734,15 +1737,15 @@ function ea(e, t) {
1734
1737
  delta: 0,
1735
1738
  timestamp: 0,
1736
1739
  isProcessing: !1
1737
- }, o = () => n = !0, i = is.reduce((E, F) => (E[F] = jc(o), E), {}), { setup: a, read: l, resolveKeyframes: c, preUpdate: u, update: d, preRender: f, render: m, postRender: w } = i, x = () => {
1740
+ }, o = () => n = !0, i = is.reduce((E, F) => (E[F] = jc(o), E), {}), { setup: a, read: l, resolveKeyframes: c, preUpdate: u, update: d, preRender: f, render: m, postRender: w } = i, v = () => {
1738
1741
  const E = ft.useManualTiming ? r.timestamp : performance.now();
1739
- n = !1, ft.useManualTiming || (r.delta = s ? 1e3 / 60 : Math.max(Math.min(E - r.timestamp, $c), 1)), r.timestamp = E, r.isProcessing = !0, a.process(r), l.process(r), c.process(r), u.process(r), d.process(r), f.process(r), m.process(r), w.process(r), r.isProcessing = !1, n && t && (s = !1, e(x));
1742
+ n = !1, ft.useManualTiming || (r.delta = s ? 1e3 / 60 : Math.max(Math.min(E - r.timestamp, $c), 1)), r.timestamp = E, r.isProcessing = !0, a.process(r), l.process(r), c.process(r), u.process(r), d.process(r), f.process(r), m.process(r), w.process(r), r.isProcessing = !1, n && t && (s = !1, e(v));
1740
1743
  }, T = () => {
1741
- n = !0, s = !0, r.isProcessing || e(x);
1744
+ n = !0, s = !0, r.isProcessing || e(v);
1742
1745
  };
1743
1746
  return { schedule: is.reduce((E, F) => {
1744
1747
  const R = i[F];
1745
- return E[F] = (L, D = !1, C = !1) => (n || T(), R.schedule(L, D, C)), E;
1748
+ return E[F] = (L, D = !1, A = !1) => (n || T(), R.schedule(L, D, A)), E;
1746
1749
  }, {}), cancel: (E) => {
1747
1750
  for (let F = 0; F < is.length; F++)
1748
1751
  i[is[F]].cancel(E);
@@ -2022,8 +2025,8 @@ function hu({ duration: e = me.duration, bounce: t = me.bounce, velocity: n = me
2022
2025
  const u = c * i, d = u * e, f = u - n, m = tr(c, i), w = Math.exp(-d);
2023
2026
  return $s - f / m * w;
2024
2027
  }, o = (c) => {
2025
- const d = c * i * e, f = d * n + n, m = Math.pow(i, 2) * Math.pow(c, 2) * e, w = Math.exp(-d), x = tr(Math.pow(c, 2), i);
2026
- return (-r(c) + $s > 0 ? -1 : 1) * ((f - m) * w) / x;
2028
+ const d = c * i * e, f = d * n + n, m = Math.pow(i, 2) * Math.pow(c, 2) * e, w = Math.exp(-d), v = tr(Math.pow(c, 2), i);
2029
+ return (-r(c) + $s > 0 ? -1 : 1) * ((f - m) * w) / v;
2027
2030
  }) : (r = (c) => {
2028
2031
  const u = Math.exp(-c * e), d = (c - n) * e + 1;
2029
2032
  return -$s + u * d;
@@ -2099,22 +2102,22 @@ function xs(e = me.visualDuration, t = me.bounce) {
2099
2102
  const o = n.keyframes[0], i = n.keyframes[n.keyframes.length - 1], a = { done: !1, value: o }, { stiffness: l, damping: c, mass: u, duration: d, velocity: f, isResolvedFromDuration: m } = yu({
2100
2103
  ...n,
2101
2104
  velocity: -/* @__PURE__ */ Ue(n.velocity || 0)
2102
- }), w = f || 0, x = c / (2 * Math.sqrt(l * u)), T = i - o, b = /* @__PURE__ */ Ue(Math.sqrt(l / u)), M = Math.abs(T) < 5;
2105
+ }), w = f || 0, v = c / (2 * Math.sqrt(l * u)), T = i - o, b = /* @__PURE__ */ Ue(Math.sqrt(l / u)), M = Math.abs(T) < 5;
2103
2106
  s || (s = M ? me.restSpeed.granular : me.restSpeed.default), r || (r = M ? me.restDelta.granular : me.restDelta.default);
2104
2107
  let E;
2105
- if (x < 1) {
2106
- const R = tr(b, x);
2108
+ if (v < 1) {
2109
+ const R = tr(b, v);
2107
2110
  E = (L) => {
2108
- const D = Math.exp(-x * b * L);
2109
- return i - D * ((w + x * b * T) / R * Math.sin(R * L) + T * Math.cos(R * L));
2111
+ const D = Math.exp(-v * b * L);
2112
+ return i - D * ((w + v * b * T) / R * Math.sin(R * L) + T * Math.cos(R * L));
2110
2113
  };
2111
- } else if (x === 1)
2114
+ } else if (v === 1)
2112
2115
  E = (R) => i - Math.exp(-b * R) * (T + (w + b * T) * R);
2113
2116
  else {
2114
- const R = b * Math.sqrt(x * x - 1);
2117
+ const R = b * Math.sqrt(v * v - 1);
2115
2118
  E = (L) => {
2116
- const D = Math.exp(-x * b * L), C = Math.min(R * L, 300);
2117
- return i - D * ((w + x * b * T) * Math.sinh(C) + R * T * Math.cosh(C)) / R;
2119
+ const D = Math.exp(-v * b * L), A = Math.min(R * L, 300);
2120
+ return i - D * ((w + v * b * T) * Math.sinh(A) + R * T * Math.cosh(A)) / R;
2118
2121
  };
2119
2122
  }
2120
2123
  const F = {
@@ -2125,9 +2128,9 @@ function xs(e = me.visualDuration, t = me.bounce) {
2125
2128
  a.done = R >= d;
2126
2129
  else {
2127
2130
  let D = R === 0 ? w : 0;
2128
- x < 1 && (D = R === 0 ? /* @__PURE__ */ Ye(w) : ua(E, R, L));
2129
- const C = Math.abs(D) <= s, j = Math.abs(i - L) <= r;
2130
- a.done = C && j;
2131
+ v < 1 && (D = R === 0 ? /* @__PURE__ */ Ye(w) : ua(E, R, L));
2132
+ const A = Math.abs(D) <= s, j = Math.abs(i - L) <= r;
2133
+ a.done = A && j;
2131
2134
  }
2132
2135
  return a.value = a.done ? i : L, a;
2133
2136
  },
@@ -2148,19 +2151,19 @@ function nr({ keyframes: e, velocity: t = 0, power: n = 0.8, timeConstant: s = 3
2148
2151
  const d = e[0], f = {
2149
2152
  done: !1,
2150
2153
  value: d
2151
- }, m = (C) => a !== void 0 && C < a || l !== void 0 && C > l, w = (C) => a === void 0 ? l : l === void 0 || Math.abs(a - C) < Math.abs(l - C) ? a : l;
2152
- let x = n * t;
2153
- const T = d + x, b = i === void 0 ? T : i(T);
2154
- b !== T && (x = b - d);
2155
- const M = (C) => -x * Math.exp(-C / s), E = (C) => b + M(C), F = (C) => {
2156
- const j = M(C), k = E(C);
2154
+ }, m = (A) => a !== void 0 && A < a || l !== void 0 && A > l, w = (A) => a === void 0 ? l : l === void 0 || Math.abs(a - A) < Math.abs(l - A) ? a : l;
2155
+ let v = n * t;
2156
+ const T = d + v, b = i === void 0 ? T : i(T);
2157
+ b !== T && (v = b - d);
2158
+ const M = (A) => -v * Math.exp(-A / s), E = (A) => b + M(A), F = (A) => {
2159
+ const j = M(A), k = E(A);
2157
2160
  f.done = Math.abs(j) <= c, f.value = f.done ? b : k;
2158
2161
  };
2159
2162
  let R, L;
2160
- const D = (C) => {
2161
- m(f.value) && (R = C, L = xs({
2163
+ const D = (A) => {
2164
+ m(f.value) && (R = A, L = xs({
2162
2165
  keyframes: [f.value, w(f.value)],
2163
- velocity: ua(E, C, f.value),
2166
+ velocity: ua(E, A, f.value),
2164
2167
  // TODO: This should be passing * 1000
2165
2168
  damping: r,
2166
2169
  stiffness: o,
@@ -2170,9 +2173,9 @@ function nr({ keyframes: e, velocity: t = 0, power: n = 0.8, timeConstant: s = 3
2170
2173
  };
2171
2174
  return D(0), {
2172
2175
  calculatedDuration: null,
2173
- next: (C) => {
2176
+ next: (A) => {
2174
2177
  let j = !1;
2175
- return !L && R === void 0 && (j = !0, F(C), D(C)), R !== void 0 && C >= R ? L.next(C - R) : (!j && F(C), f);
2178
+ return !L && R === void 0 && (j = !0, F(A), D(A)), R !== void 0 && A >= R ? L.next(A - R) : (!j && F(A), f);
2176
2179
  }
2177
2180
  };
2178
2181
  }
@@ -2313,22 +2316,22 @@ class Ur extends Br {
2313
2316
  const { generator: s, totalDuration: r, mixKeyframes: o, mirroredGenerator: i, resolvedDuration: a, calculatedDuration: l } = this;
2314
2317
  if (this.startTime === null)
2315
2318
  return s.next(0);
2316
- const { delay: c = 0, keyframes: u, repeat: d, repeatType: f, repeatDelay: m, type: w, onUpdate: x, finalKeyframe: T } = this.options;
2319
+ const { delay: c = 0, keyframes: u, repeat: d, repeatType: f, repeatDelay: m, type: w, onUpdate: v, finalKeyframe: T } = this.options;
2317
2320
  this.speed > 0 ? this.startTime = Math.min(this.startTime, t) : this.speed < 0 && (this.startTime = Math.min(t - r / this.speed, this.startTime)), n ? this.currentTime = t : this.updateTime(t);
2318
2321
  const b = this.currentTime - c * (this.playbackSpeed >= 0 ? 1 : -1), M = this.playbackSpeed >= 0 ? b < 0 : b > r;
2319
2322
  this.currentTime = Math.max(b, 0), this.state === "finished" && this.holdTime === null && (this.currentTime = r);
2320
2323
  let E = this.currentTime, F = s;
2321
2324
  if (d) {
2322
- const C = Math.min(this.currentTime, r) / a;
2323
- let j = Math.floor(C), k = C % 1;
2324
- !k && C >= 1 && (k = 1), k === 1 && j--, j = Math.min(j, d + 1), !!(j % 2) && (f === "reverse" ? (k = 1 - k, m && (k -= m / a)) : f === "mirror" && (F = i)), E = dt(0, 1, k) * a;
2325
+ const A = Math.min(this.currentTime, r) / a;
2326
+ let j = Math.floor(A), k = A % 1;
2327
+ !k && A >= 1 && (k = 1), k === 1 && j--, j = Math.min(j, d + 1), !!(j % 2) && (f === "reverse" ? (k = 1 - k, m && (k -= m / a)) : f === "mirror" && (F = i)), E = dt(0, 1, k) * a;
2325
2328
  }
2326
2329
  const R = M ? { done: !1, value: u[0] } : F.next(E);
2327
2330
  o && (R.value = o(R.value));
2328
2331
  let { done: L } = R;
2329
2332
  !M && l !== null && (L = this.playbackSpeed >= 0 ? this.currentTime >= r : this.currentTime <= 0);
2330
2333
  const D = this.holdTime === null && (this.state === "finished" || this.state === "running" && L);
2331
- return D && w !== nr && (R.value = Fr(u, this.options, T, this.speed)), x && x(R.value), D && this.finish(), R;
2334
+ return D && w !== nr && (R.value = Fr(u, this.options, T, this.speed)), v && v(R.value), D && this.finish(), R;
2332
2335
  }
2333
2336
  /**
2334
2337
  * Allows the returned animation to be awaited or promise-chained. Currently
@@ -2808,7 +2811,7 @@ class Qu extends Br {
2808
2811
  element: u,
2809
2812
  ...d
2810
2813
  }, m = u?.KeyframeResolver || zr;
2811
- this.keyframeResolver = new m(a, (w, x, T) => this.onKeyframesResolved(w, x, f, !T), l, c, u), this.keyframeResolver?.scheduleResolve();
2814
+ this.keyframeResolver = new m(a, (w, v, T) => this.onKeyframesResolved(w, v, f, !T), l, c, u), this.keyframeResolver?.scheduleResolve();
2812
2815
  }
2813
2816
  onKeyframesResolved(t, n, s, r) {
2814
2817
  this.keyframeResolver = void 0;
@@ -3471,10 +3474,10 @@ function Ed({ children: e, isPresent: t, anchorX: n, root: s }) {
3471
3474
  return;
3472
3475
  const w = n === "left" ? `left: ${f}` : `right: ${m}`;
3473
3476
  o.current.dataset.motionPopId = r;
3474
- const x = document.createElement("style");
3475
- a && (x.nonce = a);
3477
+ const v = document.createElement("style");
3478
+ a && (v.nonce = a);
3476
3479
  const T = s ?? document.head;
3477
- return T.appendChild(x), x.sheet && x.sheet.insertRule(`
3480
+ return T.appendChild(v), v.sheet && v.sheet.insertRule(`
3478
3481
  [data-motion-pop-id="${r}"] {
3479
3482
  position: absolute !important;
3480
3483
  width: ${c}px !important;
@@ -3483,7 +3486,7 @@ function Ed({ children: e, isPresent: t, anchorX: n, root: s }) {
3483
3486
  top: ${d}px !important;
3484
3487
  }
3485
3488
  `), () => {
3486
- T.contains(x) && T.removeChild(x);
3489
+ T.contains(v) && T.removeChild(v);
3487
3490
  };
3488
3491
  }, [t]), h(kd, { isPresent: t, childRef: o, sizeRef: i, children: qe.cloneElement(e, { ref: l }) });
3489
3492
  }
@@ -3532,37 +3535,37 @@ function Di(e) {
3532
3535
  }), t;
3533
3536
  }
3534
3537
  const Dd = ({ children: e, custom: t, initial: n = !0, onExitComplete: s, presenceAffectsLayout: r = !0, mode: o = "sync", propagate: i = !1, anchorX: a = "left", root: l }) => {
3535
- const [c, u] = Na(i), d = ee(() => Di(e), [e]), f = i && !c ? [] : d.map(as), m = pe(!0), w = pe(d), x = Pr(() => /* @__PURE__ */ new Map()), [T, b] = O(d), [M, E] = O(d);
3538
+ const [c, u] = Na(i), d = ee(() => Di(e), [e]), f = i && !c ? [] : d.map(as), m = pe(!0), w = pe(d), v = Pr(() => /* @__PURE__ */ new Map()), [T, b] = O(d), [M, E] = O(d);
3536
3539
  Fo(() => {
3537
3540
  m.current = !1, w.current = d;
3538
3541
  for (let L = 0; L < M.length; L++) {
3539
3542
  const D = as(M[L]);
3540
- f.includes(D) ? x.delete(D) : x.get(D) !== !0 && x.set(D, !1);
3543
+ f.includes(D) ? v.delete(D) : v.get(D) !== !0 && v.set(D, !1);
3541
3544
  }
3542
3545
  }, [M, f.length, f.join("-")]);
3543
3546
  const F = [];
3544
3547
  if (d !== T) {
3545
3548
  let L = [...d];
3546
3549
  for (let D = 0; D < M.length; D++) {
3547
- const C = M[D], j = as(C);
3548
- f.includes(j) || (L.splice(D, 0, C), F.push(C));
3550
+ const A = M[D], j = as(A);
3551
+ f.includes(j) || (L.splice(D, 0, A), F.push(A));
3549
3552
  }
3550
3553
  return o === "wait" && F.length && (L = F), E(Di(L)), b(d), null;
3551
3554
  }
3552
3555
  process.env.NODE_ENV !== "production" && o === "wait" && M.length > 1 && console.warn(`You're attempting to animate multiple children within AnimatePresence, but its mode is set to "wait". This will lead to odd visual behaviour.`);
3553
3556
  const { forceRender: R } = Se(Sr);
3554
3557
  return h(qt, { children: M.map((L) => {
3555
- const D = as(L), C = i && !c ? !1 : d === M || f.includes(D), j = () => {
3556
- if (x.has(D))
3557
- x.set(D, !0);
3558
+ const D = as(L), A = i && !c ? !1 : d === M || f.includes(D), j = () => {
3559
+ if (v.has(D))
3560
+ v.set(D, !0);
3558
3561
  else
3559
3562
  return;
3560
3563
  let k = !0;
3561
- x.forEach((N) => {
3564
+ v.forEach((N) => {
3562
3565
  N || (k = !1);
3563
3566
  }), k && (R?.(), E(w.current), i && u?.(), s && s());
3564
3567
  };
3565
- return h(Md, { isPresent: C, initial: !m.current || n ? void 0 : !1, custom: t, presenceAffectsLayout: r, mode: o, root: l, onExitComplete: C ? void 0 : j, anchorX: a, children: L }, D);
3568
+ return h(Md, { isPresent: A, initial: !m.current || n ? void 0 : !1, custom: t, presenceAffectsLayout: r, mode: o, root: l, onExitComplete: A ? void 0 : j, anchorX: a, children: L }, D);
3566
3569
  }) });
3567
3570
  }, Gr = St({ strict: !1 }), Ri = {
3568
3571
  animation: [
@@ -3922,7 +3925,7 @@ function Zd(e, t, n, s) {
3922
3925
  for (let m = 0; m < f.length; m++) {
3923
3926
  const w = ei(e, f[m]);
3924
3927
  if (w) {
3925
- const { transitionEnd: x, transition: T, ...b } = w;
3928
+ const { transitionEnd: v, transition: T, ...b } = w;
3926
3929
  for (const M in b) {
3927
3930
  let E = b[M];
3928
3931
  if (Array.isArray(E)) {
@@ -3931,8 +3934,8 @@ function Zd(e, t, n, s) {
3931
3934
  }
3932
3935
  E !== null && (r[M] = E);
3933
3936
  }
3934
- for (const M in x)
3935
- r[M] = x[M];
3937
+ for (const M in v)
3938
+ r[M] = v[M];
3936
3939
  }
3937
3940
  }
3938
3941
  }
@@ -4647,15 +4650,15 @@ function Qa(e, t, { delay: n = 0, transitionOverride: s, type: r } = {}) {
4647
4650
  }, w = d.get();
4648
4651
  if (w !== void 0 && !d.isAnimating && !Array.isArray(f) && f === w && !m.velocity)
4649
4652
  continue;
4650
- let x = !1;
4653
+ let v = !1;
4651
4654
  if (window.MotionHandoffAnimation) {
4652
4655
  const b = Za(e);
4653
4656
  if (b) {
4654
4657
  const M = window.MotionHandoffAnimation(b, u, ue);
4655
- M !== null && (m.startTime = M, x = !0);
4658
+ M !== null && (m.startTime = M, v = !0);
4656
4659
  }
4657
4660
  }
4658
- yr(e, u), d.start(si(u, d, f, e.shouldReduceMotion && va.has(u) ? { type: !1 } : m, e, x));
4661
+ yr(e, u), d.start(si(u, d, f, e.shouldReduceMotion && va.has(u) ? { type: !1 } : m, e, v));
4659
4662
  const T = d.animation;
4660
4663
  T && l.push(T);
4661
4664
  }
@@ -4764,30 +4767,30 @@ function Uh(e) {
4764
4767
  Cs(E) || typeof E == "boolean")
4765
4768
  continue;
4766
4769
  const D = zh(M.prevProp, E);
4767
- let C = D || // If we're making this variant active, we want to always make it active
4770
+ let A = D || // If we're making this variant active, we want to always make it active
4768
4771
  b === l && M.isActive && !L && F || // If we removed a higher-priority variant (i is in reverse order)
4769
4772
  T > w && F, j = !1;
4770
4773
  const k = Array.isArray(E) ? E : [E];
4771
4774
  let N = k.reduce(r(b), {});
4772
4775
  R === !1 && (N = {});
4773
- const { prevResolvedValues: B = {} } = M, V = {
4776
+ const { prevResolvedValues: B = {} } = M, I = {
4774
4777
  ...B,
4775
4778
  ...N
4776
4779
  }, U = (G) => {
4777
- C = !0, f.has(G) && (j = !0, f.delete(G)), M.needsAnimating[G] = !0;
4780
+ A = !0, f.has(G) && (j = !0, f.delete(G)), M.needsAnimating[G] = !0;
4778
4781
  const ae = e.getValue(G);
4779
4782
  ae && (ae.liveStyle = !1);
4780
4783
  };
4781
- for (const G in V) {
4784
+ for (const G in I) {
4782
4785
  const ae = N[G], xe = B[G];
4783
4786
  if (m.hasOwnProperty(G))
4784
4787
  continue;
4785
4788
  let He = !1;
4786
4789
  gr(ae) && gr(xe) ? He = !tl(ae, xe) : He = ae !== xe, He ? ae != null ? U(G) : f.add(G) : ae !== void 0 && f.has(G) ? U(G) : M.protectedKeys[G] = !0;
4787
4790
  }
4788
- M.prevProp = E, M.prevResolvedValues = N, M.isActive && (m = { ...m, ...N }), s && e.blockInitialAnimation && (C = !1);
4791
+ M.prevProp = E, M.prevResolvedValues = N, M.isActive && (m = { ...m, ...N }), s && e.blockInitialAnimation && (A = !1);
4789
4792
  const W = L && D;
4790
- C && (!W || j) && d.push(...k.map((G) => {
4793
+ A && (!W || j) && d.push(...k.map((G) => {
4791
4794
  const ae = { type: b };
4792
4795
  if (typeof G == "string" && s && !W && e.manuallyAnimateOnMount && e.parent) {
4793
4796
  const { parent: xe } = e, He = tn(xe, G);
@@ -4813,8 +4816,8 @@ function Uh(e) {
4813
4816
  E && (E.liveStyle = !0), T[b] = M ?? null;
4814
4817
  }), d.push({ animation: T });
4815
4818
  }
4816
- let x = !!d.length;
4817
- return s && (c.initial === !1 || c.initial === c.animate) && !e.manuallyAnimateOnMount && (x = !1), s = !1, x ? t(d) : Promise.resolve();
4819
+ let v = !!d.length;
4820
+ return s && (c.initial === !1 || c.initial === c.animate) && !e.manuallyAnimateOnMount && (v = !1), s = !1, v ? t(d) : Promise.resolve();
4818
4821
  }
4819
4822
  function a(l, c) {
4820
4823
  if (n[l].isActive === c)
@@ -4978,19 +4981,19 @@ class al {
4978
4981
  const f = _s(this.lastMoveEventInfo, this.history), m = this.startEvent !== null, w = Qh(f.offset, { x: 0, y: 0 }) >= this.distanceThreshold;
4979
4982
  if (!m && !w)
4980
4983
  return;
4981
- const { point: x } = f, { timestamp: T } = Ce;
4982
- this.history.push({ ...x, timestamp: T });
4984
+ const { point: v } = f, { timestamp: T } = Ce;
4985
+ this.history.push({ ...v, timestamp: T });
4983
4986
  const { onStart: b, onMove: M } = this.handlers;
4984
4987
  m || (b && b(this.lastMoveEvent, f), this.startEvent = this.lastMoveEvent), M && M(this.lastMoveEvent, f);
4985
4988
  }, this.handlePointerMove = (f, m) => {
4986
4989
  this.lastMoveEvent = f, this.lastMoveEventInfo = zs(m, this.transformPagePoint), ue.update(this.updatePoint, !0);
4987
4990
  }, this.handlePointerUp = (f, m) => {
4988
4991
  this.end();
4989
- const { onEnd: w, onSessionEnd: x, resumeAnimation: T } = this.handlers;
4992
+ const { onEnd: w, onSessionEnd: v, resumeAnimation: T } = this.handlers;
4990
4993
  if (this.dragSnapToOrigin && T && T(), !(this.lastMoveEvent && this.lastMoveEventInfo))
4991
4994
  return;
4992
4995
  const b = _s(f.type === "pointercancel" ? this.lastMoveEventInfo : zs(m, this.transformPagePoint), this.history);
4993
- this.startEvent && w && w(f, b), x && x(f, b);
4996
+ this.startEvent && w && w(f, b), v && v(f, b);
4994
4997
  }, !Kr(t))
4995
4998
  return;
4996
4999
  this.dragSnapToOrigin = o, this.handlers = n, this.transformPagePoint = s, this.distanceThreshold = i, this.contextWindow = r || window;
@@ -5107,7 +5110,7 @@ class uf {
5107
5110
  const { dragSnapToOrigin: f } = this.getProps();
5108
5111
  f ? this.pauseAnimation() : this.stopAnimation(), n && this.snapToCursor(qn(d).point);
5109
5112
  }, i = (d, f) => {
5110
- const { drag: m, dragPropagation: w, onDragStart: x } = this.getProps();
5113
+ const { drag: m, dragPropagation: w, onDragStart: v } = this.getProps();
5111
5114
  if (m && !w && (this.openDragLock && this.openDragLock(), this.openDragLock = gd(m), !this.openDragLock))
5112
5115
  return;
5113
5116
  this.latestPointerEvent = d, this.latestPanInfo = f, this.isDragging = !0, this.currentDirection = null, this.resolveConstraints(), this.visualElement.projection && (this.visualElement.projection.isAnimationBlocked = !0, this.visualElement.projection.target = void 0), Be((b) => {
@@ -5120,17 +5123,17 @@ class uf {
5120
5123
  }
5121
5124
  }
5122
5125
  this.originPoint[b] = M;
5123
- }), x && ue.postRender(() => x(d, f)), yr(this.visualElement, "transform");
5126
+ }), v && ue.postRender(() => v(d, f)), yr(this.visualElement, "transform");
5124
5127
  const { animationState: T } = this.visualElement;
5125
5128
  T && T.setActive("whileDrag", !0);
5126
5129
  }, a = (d, f) => {
5127
5130
  this.latestPointerEvent = d, this.latestPanInfo = f;
5128
- const { dragPropagation: m, dragDirectionLock: w, onDirectionLock: x, onDrag: T } = this.getProps();
5131
+ const { dragPropagation: m, dragDirectionLock: w, onDirectionLock: v, onDrag: T } = this.getProps();
5129
5132
  if (!m && !this.openDragLock)
5130
5133
  return;
5131
5134
  const { offset: b } = f;
5132
5135
  if (w && this.currentDirection === null) {
5133
- this.currentDirection = df(b), this.currentDirection !== null && x && x(this.currentDirection);
5136
+ this.currentDirection = df(b), this.currentDirection !== null && v && v(this.currentDirection);
5134
5137
  return;
5135
5138
  }
5136
5139
  this.updateAxis("x", f.point, b), this.updateAxis("y", f.point, b), this.visualElement.render(), T && T(d, f);
@@ -5697,12 +5700,12 @@ function pl({ attachResizeListener: e, defaultParent: t, measureScroll: n, check
5697
5700
  this.target = void 0, this.relativeTarget = void 0;
5698
5701
  return;
5699
5702
  }
5700
- const w = this.options.transition || c.getDefaultTransition() || Wf, { onLayoutAnimationStart: x, onLayoutAnimationComplete: T } = c.getProps(), b = !this.targetLayout || !fl(this.targetLayout, m), M = !d && f;
5703
+ const w = this.options.transition || c.getDefaultTransition() || Wf, { onLayoutAnimationStart: v, onLayoutAnimationComplete: T } = c.getProps(), b = !this.targetLayout || !fl(this.targetLayout, m), M = !d && f;
5701
5704
  if (this.options.layoutRoot || this.resumeFrom || M || d && (b || !this.currentAnimation)) {
5702
5705
  this.resumeFrom && (this.resumingFrom = this.resumeFrom, this.resumingFrom.resumingFrom = void 0);
5703
5706
  const E = {
5704
5707
  ..._r(w, "layout"),
5705
- onPlay: x,
5708
+ onPlay: v,
5706
5709
  onComplete: T
5707
5710
  };
5708
5711
  (c.shouldReduceMotion || this.options.layoutRoot) && (E.delay = 0, E.type = !1), this.startAnimation(E), this.setAnimationOrigin(u, M);
@@ -5954,12 +5957,12 @@ function pl({ attachResizeListener: e, defaultParent: t, measureScroll: n, check
5954
5957
  setAnimationOrigin(i, a = !1) {
5955
5958
  const l = this.snapshot, c = l ? l.latestValues : {}, u = { ...this.latestValues }, d = Qt();
5956
5959
  (!this.relativeParent || !this.relativeParent.options.layoutRoot) && (this.relativeTarget = this.relativeTargetOrigin = void 0), this.attemptToResolveRelativeTarget = !a;
5957
- const f = be(), m = l ? l.source : void 0, w = this.layout ? this.layout.source : void 0, x = m !== w, T = this.getStack(), b = !T || T.members.length <= 1, M = !!(x && !b && this.options.crossfade === !0 && !this.path.some(Xf));
5960
+ const f = be(), m = l ? l.source : void 0, w = this.layout ? this.layout.source : void 0, v = m !== w, T = this.getStack(), b = !T || T.members.length <= 1, M = !!(v && !b && this.options.crossfade === !0 && !this.path.some(Xf));
5958
5961
  this.animationProgress = 0;
5959
5962
  let E;
5960
5963
  this.mixTargetDelta = (F) => {
5961
5964
  const R = F / 1e3;
5962
- bo(d.x, i.x, R), bo(d.y, i.y, R), this.setTargetDelta(d), this.relativeTarget && this.relativeTargetOrigin && this.layout && this.relativeParent && this.relativeParent.layout && (On(f, this.layout.layoutBox, this.relativeParent.layout.layoutBox), _f(this.relativeTarget, this.relativeTargetOrigin, f, R), E && Ef(this.relativeTarget, E) && (this.isProjectionDirty = !1), E || (E = be()), Fe(E, this.relativeTarget)), x && (this.animationValues = u, Tf(u, c, this.latestValues, R, M, b)), this.root.scheduleUpdateProjection(), this.scheduleRender(), this.animationProgress = R;
5965
+ bo(d.x, i.x, R), bo(d.y, i.y, R), this.setTargetDelta(d), this.relativeTarget && this.relativeTargetOrigin && this.layout && this.relativeParent && this.relativeParent.layout && (On(f, this.layout.layoutBox, this.relativeParent.layout.layoutBox), _f(this.relativeTarget, this.relativeTargetOrigin, f, R), E && Ef(this.relativeTarget, E) && (this.isProjectionDirty = !1), E || (E = be()), Fe(E, this.relativeTarget)), v && (this.animationValues = u, Tf(u, c, this.latestValues, R, M, b)), this.root.scheduleUpdateProjection(), this.scheduleRender(), this.animationProgress = R;
5963
5966
  }, this.mixTargetDelta(this.options.layoutRoot ? 1e3 : 0);
5964
5967
  }
5965
5968
  startAnimation(i) {
@@ -6078,7 +6081,7 @@ function pl({ attachResizeListener: e, defaultParent: t, measureScroll: n, check
6078
6081
  for (const w in Un) {
6079
6082
  if (u[w] === void 0)
6080
6083
  continue;
6081
- const { correct: x, applyTo: T, isCSSVariable: b } = Un[w], M = d === "none" ? u[w] : x(u[w], c);
6084
+ const { correct: v, applyTo: T, isCSSVariable: b } = Un[w], M = d === "none" ? u[w] : v(u[w], c);
6082
6085
  if (T) {
6083
6086
  const E = T.length;
6084
6087
  for (let F = 0; F < E; F++)
@@ -6571,9 +6574,9 @@ const bm = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
6571
6574
  }), [u, d] = ai({
6572
6575
  prop: o,
6573
6576
  defaultProp: 0
6574
- }), [f, m] = O(!1), [w, x] = O(null);
6577
+ }), [f, m] = O(!1), [w, v] = O(null);
6575
6578
  re(() => {
6576
- t ? w === null && x(Date.now()) : w !== null && (d(Math.ceil((Date.now() - w) / Sm)), x(null));
6579
+ t ? w === null && v(Date.now()) : w !== null && (d(Math.ceil((Date.now() - w) / Sm)), v(null));
6577
6580
  }, [t, w, d]), re(() => {
6578
6581
  if (s && !t && l && !f) {
6579
6582
  const b = setTimeout(() => {
@@ -6760,15 +6763,15 @@ function Am({
6760
6763
  const E = /* @__PURE__ */ new WeakSet(), F = () => {
6761
6764
  if (!c.current || M) return;
6762
6765
  M = !0;
6763
- const L = c.current, D = /\[(\d+)\]/g, C = document.createTreeWalker(
6766
+ const L = c.current, D = /\[(\d+)\]/g, A = document.createTreeWalker(
6764
6767
  L,
6765
6768
  NodeFilter.SHOW_TEXT,
6766
6769
  null
6767
6770
  ), j = [];
6768
6771
  let k;
6769
- for (; k = C.nextNode(); )
6772
+ for (; k = A.nextNode(); )
6770
6773
  if (k.nodeType === Node.TEXT_NODE && !E.has(k)) {
6771
- const B = k, V = B.textContent || "";
6774
+ const B = k, I = B.textContent || "";
6772
6775
  let U = B.parentElement, W = !1;
6773
6776
  for (; U && U !== L; ) {
6774
6777
  if (U.tagName === "A" || U.tagName === "CODE" || U.tagName === "PRE") {
@@ -6778,7 +6781,7 @@ function Am({
6778
6781
  U = U.parentElement;
6779
6782
  }
6780
6783
  if (!W) {
6781
- const G = Array.from(V.matchAll(D)).filter((ae) => {
6784
+ const G = Array.from(I.matchAll(D)).filter((ae) => {
6782
6785
  if (!ae[1]) return !1;
6783
6786
  const xe = parseInt(ae[1], 10);
6784
6787
  return n.has(xe);
@@ -6791,11 +6794,11 @@ function Am({
6791
6794
  return;
6792
6795
  }
6793
6796
  const N = [];
6794
- j.forEach(({ node: B, matches: V }) => {
6797
+ j.forEach(({ node: B, matches: I }) => {
6795
6798
  E.add(B);
6796
6799
  const U = B.textContent || "", W = document.createDocumentFragment();
6797
6800
  let H = 0;
6798
- V.forEach((G) => {
6801
+ I.forEach((G) => {
6799
6802
  if (!G[1]) return;
6800
6803
  G.index !== void 0 && G.index > H && W.appendChild(document.createTextNode(U.slice(H, G.index)));
6801
6804
  const ae = document.createElement("span");
@@ -6804,7 +6807,7 @@ function Am({
6804
6807
  ae.setAttribute("data-citation", G[1]), W.appendChild(ae), N.push({ element: ae, citationNum: xe }), H = (G.index || 0) + G[0].length;
6805
6808
  }), H < U.length && W.appendChild(document.createTextNode(U.slice(H))), B.parentNode && B.parentNode.replaceChild(W, B);
6806
6809
  }), N.length > 0 && d((B) => {
6807
- const V = new Set(B.map((H) => H.element)), U = B.filter((H) => H.element.isConnected), W = N.filter((H) => !V.has(H.element));
6810
+ const I = new Set(B.map((H) => H.element)), U = B.filter((H) => H.element.isConnected), W = N.filter((H) => !I.has(H.element));
6808
6811
  return [...U, ...W];
6809
6812
  }), M = !1;
6810
6813
  }, R = new MutationObserver(() => {
@@ -6829,7 +6832,7 @@ function Am({
6829
6832
  return T;
6830
6833
  }
6831
6834
  }
6832
- const x = a && l && f ? /* @__PURE__ */ P("div", { className: "mt-4 pt-4 border-t border-stone-200 dark:border-stone-700", children: [
6835
+ const v = a && l && f ? /* @__PURE__ */ P("div", { className: "mt-4 pt-4 border-t border-stone-200 dark:border-stone-700", children: [
6833
6836
  /* @__PURE__ */ h("div", { className: "text-xs font-semibold text-stone-600 dark:text-stone-400 mb-3", children: "References" }),
6834
6837
  /* @__PURE__ */ h("div", { className: "flex flex-wrap gap-2", children: s && s.length > 0 ? (
6835
6838
  // Use grouped citations if available - show as buttons with favicon + title
@@ -6916,7 +6919,7 @@ function Am({
6916
6919
  const F = Array.from(
6917
6920
  new Map(
6918
6921
  t.map((R) => {
6919
- const L = R.url.replace(/\/+$/, ""), D = s?.find((C) => C.url.replace(/\/+$/, "") === L);
6922
+ const L = R.url.replace(/\/+$/, ""), D = s?.find((A) => A.url.replace(/\/+$/, "") === L);
6920
6923
  return [L, {
6921
6924
  number: R.number,
6922
6925
  url: R.url,
@@ -6939,7 +6942,7 @@ function Am({
6939
6942
  `citation-${b}-${M}`
6940
6943
  );
6941
6944
  }),
6942
- x
6945
+ v
6943
6946
  ] });
6944
6947
  }
6945
6948
  function cn({
@@ -7145,11 +7148,11 @@ function Nm({
7145
7148
  placeholder: s = "Enter email address...",
7146
7149
  onComplete: r
7147
7150
  }) {
7148
- const [o, i] = O(""), [a, l] = O(!0), [c, u] = O(!1), d = (x) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(x), f = (x) => {
7149
- i(x), x.trim() ? l(d(x)) : l(!0);
7151
+ const [o, i] = O(""), [a, l] = O(!0), [c, u] = O(!1), d = (v) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v), f = (v) => {
7152
+ i(v), v.trim() ? l(d(v)) : l(!0);
7150
7153
  };
7151
- return /* @__PURE__ */ h(cn, { open: e, children: /* @__PURE__ */ h(un, { showCloseButton: !1, children: /* @__PURE__ */ P("form", { onSubmit: async (x) => {
7152
- if (x.preventDefault(), !o.trim() || !d(o)) {
7154
+ return /* @__PURE__ */ h(cn, { open: e, children: /* @__PURE__ */ h(un, { showCloseButton: !1, children: /* @__PURE__ */ P("form", { onSubmit: async (v) => {
7155
+ if (v.preventDefault(), !o.trim() || !d(o)) {
7153
7156
  l(!1);
7154
7157
  return;
7155
7158
  }
@@ -7173,7 +7176,7 @@ function Nm({
7173
7176
  {
7174
7177
  type: "email",
7175
7178
  value: o,
7176
- onChange: (x) => f(x.target.value),
7179
+ onChange: (v) => f(v.target.value),
7177
7180
  placeholder: s,
7178
7181
  className: a ? "" : "border-red-500",
7179
7182
  autoFocus: !0,
@@ -7428,44 +7431,44 @@ function Vm({
7428
7431
  return s.forEach((N) => {
7429
7432
  k[N.name] = N.value || "";
7430
7433
  }), k;
7431
- }), [c, u] = O({}), [d, f] = O({}), [m, w] = O(!1), x = (k) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(k) ? null : "Please enter a valid email address", T = (k) => k.replace(/\D/g, "").length === 10 ? null : "Please enter a valid 10-digit phone number", b = (k, N = 4) => k.length === N ? null : `PIN must be ${N} digits`, M = (k) => {
7434
+ }), [c, u] = O({}), [d, f] = O({}), [m, w] = O(!1), v = (k) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(k) ? null : "Please enter a valid email address", T = (k) => k.replace(/\D/g, "").length === 10 ? null : "Please enter a valid 10-digit phone number", b = (k, N = 4) => k.length === N ? null : `PIN must be ${N} digits`, M = (k) => {
7432
7435
  const N = k.replace(/\D/g, "");
7433
7436
  return N.length <= 3 ? N : N.length <= 6 ? `(${N.slice(0, 3)}) ${N.slice(3)}` : `(${N.slice(0, 3)}) ${N.slice(3, 6)}-${N.slice(6, 10)}`;
7434
7437
  }, E = (k, N, B) => {
7435
- let V = N, U = null;
7438
+ let I = N, U = null;
7436
7439
  switch (B.type) {
7437
7440
  case "phone":
7438
- V = M(N), V.trim() && (U = T(V));
7441
+ I = M(N), I.trim() && (U = T(I));
7439
7442
  break;
7440
7443
  case "email":
7441
- N.trim() && (U = x(N));
7444
+ N.trim() && (U = v(N));
7442
7445
  break;
7443
7446
  case "pin":
7444
- V = N.replace(/\D/g, "").slice(0, 6), V.trim() && (U = b(V));
7447
+ I = N.replace(/\D/g, "").slice(0, 6), I.trim() && (U = b(I));
7445
7448
  break;
7446
7449
  }
7447
- !U && B.validation && V.trim() && (U = B.validation(V)), l((W) => ({ ...W, [k]: V })), u((W) => ({ ...W, [k]: U || "" }));
7450
+ !U && B.validation && I.trim() && (U = B.validation(I)), l((W) => ({ ...W, [k]: I })), u((W) => ({ ...W, [k]: U || "" }));
7448
7451
  }, F = () => {
7449
7452
  const k = {};
7450
7453
  let N = !0;
7451
7454
  return s.forEach((B) => {
7452
- const V = a[B.name] || "";
7455
+ const I = a[B.name] || "";
7453
7456
  let U = null;
7454
- if (B.required && !V.trim())
7457
+ if (B.required && !I.trim())
7455
7458
  U = `${B.label} is required`;
7456
- else if (V.trim()) {
7459
+ else if (I.trim()) {
7457
7460
  switch (B.type) {
7458
7461
  case "email":
7459
- U = x(V);
7462
+ U = v(I);
7460
7463
  break;
7461
7464
  case "phone":
7462
- U = T(V);
7465
+ U = T(I);
7463
7466
  break;
7464
7467
  case "pin":
7465
- U = b(V);
7468
+ U = b(I);
7466
7469
  break;
7467
7470
  }
7468
- !U && B.validation && (U = B.validation(V));
7471
+ !U && B.validation && (U = B.validation(I));
7469
7472
  }
7470
7473
  U && (k[B.name] = U, N = !1);
7471
7474
  }), u(k), N;
@@ -7475,8 +7478,8 @@ function Vm({
7475
7478
  try {
7476
7479
  const N = {};
7477
7480
  s.forEach((B) => {
7478
- const V = a[B.name]?.trim();
7479
- V && (B.type === "phone" ? N[B.name] = V.replace(/\D/g, "") : N[B.name] = V);
7481
+ const I = a[B.name]?.trim();
7482
+ I && (B.type === "phone" ? N[B.name] = I.replace(/\D/g, "") : N[B.name] = I);
7480
7483
  }), r(N);
7481
7484
  } finally {
7482
7485
  w(!1);
@@ -7489,7 +7492,7 @@ function Vm({
7489
7492
  ...N,
7490
7493
  [k]: !N[k]
7491
7494
  }));
7492
- }, C = (k) => {
7495
+ }, A = (k) => {
7493
7496
  switch (k.type) {
7494
7497
  case "password":
7495
7498
  return d[k.name] ? "text" : "password";
@@ -7537,7 +7540,7 @@ function Vm({
7537
7540
  /* @__PURE__ */ h(
7538
7541
  pn,
7539
7542
  {
7540
- type: C(k),
7543
+ type: A(k),
7541
7544
  value: a[k.name] || "",
7542
7545
  onChange: (N) => E(k.name, N.target.value, k),
7543
7546
  placeholder: j(k),
@@ -7603,14 +7606,14 @@ function Om({ children: e }) {
7603
7606
  i.current && (i.current(m), i.current = null), r(null);
7604
7607
  }, []), d = () => {
7605
7608
  if (s) {
7606
- const w = s.fields.map((x) => ({
7607
- name: x.name,
7608
- type: x.type === "text" ? "text" : x.type === "password" ? "password" : x.type === "email" ? "email" : x.type === "phone" ? "phone" : x.type === "pin" ? "pin" : x.type === "ssn" ? "ssn" : x.type === "creditCard" ? "creditCard" : "text",
7609
- label: x.label,
7610
- placeholder: x.placeholder,
7611
- required: x.required !== !1,
7609
+ const w = s.fields.map((v) => ({
7610
+ name: v.name,
7611
+ type: v.type === "text" ? "text" : v.type === "password" ? "password" : v.type === "email" ? "email" : v.type === "phone" ? "phone" : v.type === "pin" ? "pin" : v.type === "ssn" ? "ssn" : v.type === "creditCard" ? "creditCard" : "text",
7612
+ label: v.label,
7613
+ placeholder: v.placeholder,
7614
+ required: v.required !== !1,
7612
7615
  // Default to true
7613
- value: x.value
7616
+ value: v.value
7614
7617
  }));
7615
7618
  return /* @__PURE__ */ h(
7616
7619
  Vm,
@@ -7701,26 +7704,26 @@ function Ao(e) {
7701
7704
  let t = e.replace(/_+$/gm, "");
7702
7705
  const n = /(?:^|\n)(?:#+\s*)?(?:References|References:)(?:\*\*)?\s*\n?([\s\S]*?)(?=\n\n|\n#|$)/i, s = t.match(n), r = /* @__PURE__ */ new Map(), o = [], i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Map();
7703
7706
  if (s && s[1]) {
7704
- const C = s[1], j = /\[(\d+)\]\s*(https?:\/\/[^\s\)]+)/g;
7707
+ const A = s[1], j = /\[(\d+)\]\s*(https?:\/\/[^\s\)]+)/g;
7705
7708
  let k;
7706
- for (; (k = j.exec(C)) !== null; )
7709
+ for (; (k = j.exec(A)) !== null; )
7707
7710
  if (k[1] && k[2]) {
7708
- const N = parseInt(k[1], 10), B = k[2].replace(/[.,;:!?]+$/, ""), V = B.replace(/\/+$/, "");
7709
- if (a.has(V) || a.set(V, B), i.has(V) || i.set(V, []), i.get(V).push(N), !l.has(V))
7710
- l.set(V, N);
7711
+ const N = parseInt(k[1], 10), B = k[2].replace(/[.,;:!?]+$/, ""), I = B.replace(/\/+$/, "");
7712
+ if (a.has(I) || a.set(I, B), i.has(I) || i.set(I, []), i.get(I).push(N), !l.has(I))
7713
+ l.set(I, N);
7711
7714
  else {
7712
- const U = l.get(V);
7713
- N < U && l.set(V, N);
7715
+ const U = l.get(I);
7716
+ N < U && l.set(I, N);
7714
7717
  }
7715
7718
  }
7716
7719
  for (const [N, B] of i.entries()) {
7717
- const V = l.get(N);
7720
+ const I = l.get(N);
7718
7721
  for (const U of B)
7719
- U !== V && c.set(U, V);
7722
+ U !== I && c.set(U, I);
7720
7723
  }
7721
7724
  for (const [N, B] of l.entries()) {
7722
- const V = a.get(N) || N;
7723
- r.set(B, V), o.push({ number: B, url: V });
7725
+ const I = a.get(N) || N;
7726
+ r.set(B, I), o.push({ number: B, url: I });
7724
7727
  }
7725
7728
  }
7726
7729
  let u, d = t;
@@ -7728,57 +7731,57 @@ function Ao(e) {
7728
7731
  const f = [];
7729
7732
  let m = 0;
7730
7733
  const w = /```[\s\S]*?```|`[^`]+`/g;
7731
- let x;
7732
- for (; (x = w.exec(d)) !== null; )
7733
- x.index > m && f.push({ type: "text", content: d.slice(m, x.index), start: m, end: x.index }), f.push({ type: "code", content: x[0], start: x.index, end: x.index + x[0].length }), m = x.index + x[0].length;
7734
+ let v;
7735
+ for (; (v = w.exec(d)) !== null; )
7736
+ v.index > m && f.push({ type: "text", content: d.slice(m, v.index), start: m, end: v.index }), f.push({ type: "code", content: v[0], start: v.index, end: v.index + v[0].length }), m = v.index + v[0].length;
7734
7737
  m < d.length && f.push({ type: "text", content: d.slice(m), start: m, end: d.length });
7735
- const T = f.map((C) => {
7736
- if (C.type === "code")
7737
- return C.content;
7738
- let j = C.content;
7739
- return j = j.replace(/\[(\d+)\]\((https?:\/\/[^\)]+)\)/g, (N, B, V) => {
7740
- const U = parseInt(B, 10), W = V.replace(/\/+$/, ""), H = c.get(U) || U;
7741
- return l.has(W) || (l.set(W, H), r.has(H) || (r.set(H, V), o.push({ number: H, url: V }))), `[${H}]`;
7738
+ const T = f.map((A) => {
7739
+ if (A.type === "code")
7740
+ return A.content;
7741
+ let j = A.content;
7742
+ return j = j.replace(/\[(\d+)\]\((https?:\/\/[^\)]+)\)/g, (N, B, I) => {
7743
+ const U = parseInt(B, 10), W = I.replace(/\/+$/, ""), H = c.get(U) || U;
7744
+ return l.has(W) || (l.set(W, H), r.has(H) || (r.set(H, I), o.push({ number: H, url: I }))), `[${H}]`;
7742
7745
  }), j = j.replace(/\[(\d+)\]/g, (N, B) => {
7743
- const V = parseInt(B, 10);
7744
- return `[${c.get(V) || V}]`;
7746
+ const I = parseInt(B, 10);
7747
+ return `[${c.get(I) || I}]`;
7745
7748
  }), j;
7746
7749
  }), b = [];
7747
- for (const [C, j] of l.entries()) {
7748
- const k = a.get(C) || C, { baseUrl: N, anchor: B } = Lm(k), V = jm(k);
7750
+ for (const [A, j] of l.entries()) {
7751
+ const k = a.get(A) || A, { baseUrl: N, anchor: B } = Lm(k), I = jm(k);
7749
7752
  b.push({
7750
7753
  url: k,
7751
7754
  baseUrl: N,
7752
7755
  numbers: [j],
7753
7756
  // Only show primary number
7754
7757
  anchor: B,
7755
- title: V
7758
+ title: I
7756
7759
  });
7757
7760
  }
7758
- b.sort((C, j) => (C.numbers[0] || 0) - (j.numbers[0] || 0));
7761
+ b.sort((A, j) => (A.numbers[0] || 0) - (j.numbers[0] || 0));
7759
7762
  const M = /* @__PURE__ */ new Map();
7760
7763
  let E = 1;
7761
- for (const C of b) {
7762
- const j = C.numbers[0];
7763
- M.set(j, E), C.numbers = [E], E++;
7764
+ for (const A of b) {
7765
+ const j = A.numbers[0];
7766
+ M.set(j, E), A.numbers = [E], E++;
7764
7767
  }
7765
7768
  const F = /* @__PURE__ */ new Map();
7766
- for (const [C, j] of r.entries()) {
7767
- const k = M.get(C);
7769
+ for (const [A, j] of r.entries()) {
7770
+ const k = M.get(A);
7768
7771
  k && F.set(k, j);
7769
7772
  }
7770
- const R = o.map((C) => {
7771
- const j = M.get(C.number);
7772
- return j ? { number: j, url: C.url } : C;
7773
- }).filter((C) => M.has(C.number)), L = Array.from(M.entries()).sort((C, j) => j[0] - C[0]);
7773
+ const R = o.map((A) => {
7774
+ const j = M.get(A.number);
7775
+ return j ? { number: j, url: A.url } : A;
7776
+ }).filter((A) => M.has(A.number)), L = Array.from(M.entries()).sort((A, j) => j[0] - A[0]);
7774
7777
  let D = T.join("");
7775
- for (const [C, j] of L) {
7776
- const k = new RegExp(`\\[${C}\\](?!\\d)`, "g");
7778
+ for (const [A, j] of L) {
7779
+ const k = new RegExp(`\\[${A}\\](?!\\d)`, "g");
7777
7780
  D = D.replace(k, `[${j}]`);
7778
7781
  }
7779
7782
  return {
7780
7783
  processedText: D,
7781
- citations: R.sort((C, j) => C.number - j.number),
7784
+ citations: R.sort((A, j) => A.number - j.number),
7782
7785
  citationMap: F,
7783
7786
  groupedCitations: b,
7784
7787
  referencesText: u
@@ -7831,7 +7834,7 @@ function $m({
7831
7834
  toolMetadata: m,
7832
7835
  // NOTE: systemPrompt is deprecated; configure prompts in the dashboard/agents UI.
7833
7836
  systemPrompt: w = "",
7834
- agentId: x,
7837
+ agentId: v,
7835
7838
  agentName: T,
7836
7839
  tokenEndpoint: b = "/api/arcten/token",
7837
7840
  apiBaseUrl: M = "https://api.arcten.com",
@@ -7840,12 +7843,12 @@ function $m({
7840
7843
  onStateChange: R,
7841
7844
  allowStateEdits: L = !0,
7842
7845
  sources: D,
7843
- ragConfig: C,
7846
+ ragConfig: A,
7844
7847
  showCitations: j = !0,
7845
7848
  sensitiveParams: k,
7846
7849
  autoDetectSensitive: N = !1
7847
7850
  }) {
7848
- const B = M.replace(/\/+$/, ""), { showSecureModal: V } = Im(), U = Cc({
7851
+ const B = M.replace(/\/+$/, ""), { showSecureModal: I } = Im(), U = Cc({
7849
7852
  apiBaseUrl: B,
7850
7853
  tokenEndpoint: b,
7851
7854
  user: E,
@@ -7854,16 +7857,16 @@ function $m({
7854
7857
  toolMetadata: m,
7855
7858
  sensitiveParams: k,
7856
7859
  autoDetectSensitive: N,
7857
- agentId: x,
7860
+ agentId: v,
7858
7861
  agentName: T,
7859
7862
  state: F,
7860
7863
  // controlled state prop
7861
7864
  onStateChange: R,
7862
7865
  allowStateEdits: L,
7863
7866
  sources: D,
7864
- ragConfig: C
7867
+ ragConfig: A
7865
7868
  });
7866
- ee(() => C !== void 0 ? C : D && D.length > 0 ? {
7869
+ ee(() => A !== void 0 ? A : D && D.length > 0 ? {
7867
7870
  enabled: !0,
7868
7871
  organizationId: D[0],
7869
7872
  // Use first source as default
@@ -7871,7 +7874,7 @@ function $m({
7871
7874
  // Default to auto-execute when sources are provided
7872
7875
  filters: void 0
7873
7876
  // Can be extended later if needed
7874
- } : { enabled: !1 }, [D, C]);
7877
+ } : { enabled: !1 }, [D, A]);
7875
7878
  const [W, H] = O(c), [G, ae] = O(i), [xe, He] = O(600), [Ct, ot] = O(!1), [Y, Bt] = O(!1), [Ve, At] = O(!1), [Ne, _e] = O({ x: 100, y: 100 }), [gn, le] = O(!1), [yn, kt] = O({ x: 0, y: 0 }), [bn, Gn] = O(!1), Xe = pe(null), Et = pe(null), [Mt, Oe] = O(""), [vn, ks] = O(null), [Ut, xn] = O("Thinking..."), [zt, at] = O(/* @__PURE__ */ new Set()), [Es, Yn] = O(""), [lt, Hn] = O([]), Jn = pe(/* @__PURE__ */ new Map()), _t = pe(!1), de = pe(""), [Xt, mt] = O(!1), [we, wn] = O(!1), Je = ee(() => [...u, ...d], [u, d]), $e = ee(() => Io(Je, m), [Je, m]), Tn = ee(() => {
7876
7879
  const S = /* @__PURE__ */ new Map(), X = new Map($e.map((_) => [_.name, _]));
7877
7880
  return Je.forEach((_) => {