@aintela/chat 0.2.39 → 0.2.41

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 (28) hide show
  1. package/dist/components.js +6482 -6240
  2. package/dist/components.js.map +1 -1
  3. package/dist/hooks.js +1 -1
  4. package/dist/{httpArtifactService-BpRwcTJp.js → httpArtifactService-DBKIvfSD.js} +159 -154
  5. package/dist/httpArtifactService-DBKIvfSD.js.map +1 -0
  6. package/dist/{httpSessionService-M1IKQIQK.js → httpSessionService-CNzThf-T.js} +85 -80
  7. package/dist/httpSessionService-CNzThf-T.js.map +1 -0
  8. package/dist/index.js +190 -183
  9. package/dist/services.js +7 -6
  10. package/dist/src/components/AiChat/AiChatContext.d.ts +8 -0
  11. package/dist/src/components/AiChat/AiChatTypes.d.ts +29 -0
  12. package/dist/src/components/AiChat/ChatPane/AskUserSheet.d.ts +21 -9
  13. package/dist/src/components/AiChat/ChatPane/CurrentMessage.d.ts +2 -2
  14. package/dist/src/components/AiChat/aiChatEngine.d.ts +89 -0
  15. package/dist/src/components/AiChat/aiChatEngine.test.d.ts +1 -0
  16. package/dist/src/components/AiChat/useLiveSession.d.ts +52 -0
  17. package/dist/src/components/index.d.ts +6 -0
  18. package/dist/src/components/v2/RunProgressStripV2.d.ts +3 -1
  19. package/dist/src/services/accessTokenProvider.d.ts +9 -0
  20. package/dist/src/services/httpArtifactService.d.ts +2 -1
  21. package/dist/src/services/httpPromptAssistService.d.ts +2 -7
  22. package/dist/src/services/httpSessionService.d.ts +2 -1
  23. package/dist/src/services/index.d.ts +2 -0
  24. package/dist/{useChatSessions-C-XVE-h3.js → useChatSessions-mnF6pUGm.js} +2 -2
  25. package/dist/{useChatSessions-C-XVE-h3.js.map → useChatSessions-mnF6pUGm.js.map} +1 -1
  26. package/package.json +1 -1
  27. package/dist/httpArtifactService-BpRwcTJp.js.map +0 -1
  28. package/dist/httpSessionService-M1IKQIQK.js.map +0 -1
@@ -1,15 +1,16 @@
1
- var nt = Object.defineProperty;
2
- var gt = (O, t, e) => t in O ? nt(O, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : O[t] = e;
3
- var f = (O, t) => nt(O, "name", { value: t, configurable: !0 });
4
- var a = (O, t, e) => gt(O, typeof t != "symbol" ? t + "" : t, e);
5
- import { d as L, t as pt, E as I, k as mt, j as St, q as wt, C as B } from "./environmentUtils-CUVZ6Dq1.js";
6
- import { I as _, S as ut, g as yt, L as Tt, P as x, b as It, e as Ct, T as vt, c as Et } from "./serializer-uea8YsIP.js";
7
- import { unified as Mt } from "unified";
8
- import Ot from "remark-parse";
9
- import { toMarkdown as Dt } from "mdast-util-to-markdown";
10
- import { format as At } from "date-fns";
11
- import Nt from "lodash";
12
- import { P as kt, C as R } from "./Prompt-DZb7OaPp.js";
1
+ var rt = Object.defineProperty;
2
+ var St = (O, t, e) => t in O ? rt(O, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : O[t] = e;
3
+ var g = (O, t) => rt(O, "name", { value: t, configurable: !0 });
4
+ var a = (O, t, e) => St(O, typeof t != "symbol" ? t + "" : t, e);
5
+ import { d as L, t as wt, E as C, k as Tt, j as yt, q as It, C as B } from "./environmentUtils-CUVZ6Dq1.js";
6
+ import { I as _, S as gt, g as Ct, L as vt, P as x, b as Et, e as Mt, T as Ot, c as Dt } from "./serializer-uea8YsIP.js";
7
+ import { unified as At } from "unified";
8
+ import Nt from "remark-parse";
9
+ import { toMarkdown as kt } from "mdast-util-to-markdown";
10
+ import { format as Pt } from "date-fns";
11
+ import _t from "lodash";
12
+ import { P as bt, C as R } from "./Prompt-DZb7OaPp.js";
13
+ import { r as Ft } from "./httpSessionService-CNzThf-T.js";
13
14
  const w = {
14
15
  ARTIFACTS: "envision-artifacts",
15
16
  SECTIONS: "envision-sections",
@@ -38,7 +39,7 @@ const w = {
38
39
  }
39
40
  ], K = class K {
40
41
  constructor() {
41
- a(this, "onPromptCreated", /* @__PURE__ */ f(() => {
42
+ a(this, "onPromptCreated", /* @__PURE__ */ g(() => {
42
43
  }, "onPromptCreated"));
43
44
  }
44
45
  getItem(t) {
@@ -196,9 +197,9 @@ const w = {
196
197
  }
197
198
  }
198
199
  };
199
- f(K, "LocalStorageService");
200
- let it = K;
201
- const Yt = /* @__PURE__ */ f((O) => {
200
+ g(K, "LocalStorageService");
201
+ let ot = K;
202
+ const te = /* @__PURE__ */ g((O) => {
202
203
  const t = O.getPrompts(), e = t.length;
203
204
  if (e > 0) {
204
205
  const s = t[0].promptText, i = t[t.length - 1].promptText, n = t[0].created;
@@ -230,7 +231,7 @@ const Yt = /* @__PURE__ */ f((O) => {
230
231
  a(this, "gatewayFirstToken", "gatewayFirstToken");
231
232
  }
232
233
  };
233
- f(z, "EventTypes");
234
+ g(z, "EventTypes");
234
235
  let q = z;
235
236
  const c = new q(), Y = class Y {
236
237
  constructor() {
@@ -483,7 +484,7 @@ const c = new q(), Y = class Y {
483
484
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
484
485
  }
485
486
  };
486
- f(Y, "EventBusService");
487
+ g(Y, "EventBusService");
487
488
  let J = Y;
488
489
  const j = class j extends J {
489
490
  constructor() {
@@ -493,7 +494,7 @@ const j = class j extends J {
493
494
  console.log("MockEventBusService.gatewayEmitConnectionStateChange");
494
495
  }
495
496
  gatewayEmitMessage(t, e) {
496
- pt() ? process.stdout.write(`M${t.version}, `) : console.log("MockEventBusService.gatewayEmitMessage");
497
+ wt() ? process.stdout.write(`M${t.version}, `) : console.log("MockEventBusService.gatewayEmitMessage");
497
498
  }
498
499
  gatewayEmitTurnComplete(t, e) {
499
500
  console.log("MockEventBusService.gatewayEmitTurnComplete");
@@ -511,36 +512,36 @@ const j = class j extends J {
511
512
  console.log("MockEventBusService.gatewayOffFunctionResponse", t);
512
513
  }
513
514
  };
514
- f(j, "MockEventBusService");
515
- let at = j;
516
- const dt = {
515
+ g(j, "MockEventBusService");
516
+ let ct = j;
517
+ const Rt = 2e3, pt = {
517
518
  inline: "inline",
518
519
  block: "block"
519
- }, Q = class Q {
520
+ }, X = class X {
520
521
  constructor() {
521
522
  a(this, "parts", []);
522
523
  a(this, "isLastGroup", !1);
523
524
  a(this, "hasThoughts", !1);
524
525
  a(this, "lastWithThoughts", !1);
525
- a(this, "type", dt.inline);
526
+ a(this, "type", pt.inline);
526
527
  }
527
528
  };
528
- f(Q, "InteractionPartGroup");
529
- let W = Q;
530
- const X = class X {
529
+ g(X, "InteractionPartGroup");
530
+ let W = X;
531
+ const Q = class Q {
531
532
  constructor(t, e) {
532
533
  a(this, "interaction");
533
534
  a(this, "eventBusService");
534
- a(this, "parseTextIntoParts", /* @__PURE__ */ f((t) => {
535
+ a(this, "parseTextIntoParts", /* @__PURE__ */ g((t) => {
535
536
  if (!t || t.trim().length == 0) return [];
536
- const e = Mt().use(Ot).parse(t), s = [];
537
+ const e = At().use(Nt).parse(t), s = [];
537
538
  let i = null;
538
539
  for (const n of e.children)
539
540
  n.type === "code" ? (i && (s.push(i), i = null), n.lang === "htmlCanvas" && s.push(`
540
541
  \`\`\`liveTsx
541
542
  ${n.value}
542
543
  \`\`\`
543
- `)) : (i || (i = ""), i += Dt(n));
544
+ `)) : (i || (i = ""), i += kt(n));
544
545
  return i && s.push(i), s;
545
546
  }, "parseTextIntoParts"));
546
547
  this.interaction = t, this.eventBusService = e;
@@ -560,9 +561,9 @@ ${n.value}
560
561
  let n = new W();
561
562
  for (let o = 0; o < t.length; o++) {
562
563
  const u = t[o];
563
- let h = !(((l = u.functionDetails) == null ? void 0 : l.isUi) ?? !1) && u.eventType !== I.Text && u.eventType !== I.Thought && (u.eventType === I.FunctionCall || u.eventType === I.PartialFunctionCall || u.eventType === I.FunctionResponse) && o < t.length - 1;
564
- !e && h && !s || (h ? (u.eventType == I.Thought && (n.hasThoughts = !0), n.parts.push(u), n.isLastGroup = o === t.length - 1) : (n.parts.length > 0 && (i.push(n), n = new W()), i.push({
565
- type: dt.block,
564
+ let h = !(((l = u.functionDetails) == null ? void 0 : l.isUi) ?? !1) && u.eventType !== C.Text && u.eventType !== C.Thought && (u.eventType === C.FunctionCall || u.eventType === C.PartialFunctionCall || u.eventType === C.FunctionResponse) && o < t.length - 1;
565
+ !e && h && !s || (h ? (u.eventType == C.Thought && (n.hasThoughts = !0), n.parts.push(u), n.isLastGroup = o === t.length - 1) : (n.parts.length > 0 && (i.push(n), n = new W()), i.push({
566
+ type: pt.block,
566
567
  parts: [u],
567
568
  isLastGroup: o === t.length - 1,
568
569
  hasThoughts: !1,
@@ -574,10 +575,10 @@ ${n.value}
574
575
  return r.length > 0 && (r[r.length - 1].lastWithThoughts = !0), i;
575
576
  }
576
577
  isFunctionCall(t) {
577
- return t == I.FunctionCall || t == I.PartialFunctionCall;
578
+ return t == C.FunctionCall || t == C.PartialFunctionCall;
578
579
  }
579
580
  isFunctionResponse(t) {
580
- return t == I.FunctionResponse;
581
+ return t == C.FunctionResponse;
581
582
  }
582
583
  // Computes the next interaction from a server event. Pure with respect to
583
584
  // `prev` — no part or array on the prior tree is mutated; modified entities
@@ -585,47 +586,51 @@ ${n.value}
585
586
  // new tree as the last step, so snapshots already handed out to throttled
586
587
  // subscribers can't diverge from the live state.
587
588
  merge(t) {
588
- var b, T, A, N, et;
589
+ var b, y, A, N, et, st, nt, it;
589
590
  const e = this.interaction, s = [], i = [], n = _.FlatParts(t == null ? void 0 : t.parts), r = e.parts[e.parts.length - 1] ?? null;
590
591
  let l = !1;
591
- n && (l = !r || n.mustPush || n.mustPush === !1 && (n.eventType !== (r == null ? void 0 : r.eventType) || ((b = n == null ? void 0 : n.functionDetails) == null ? void 0 : b.id) !== ((T = r.functionDetails) == null ? void 0 : T.id)));
592
+ n && (l = !r || n.mustPush || n.mustPush === !1 && (n.eventType !== (r == null ? void 0 : r.eventType) || ((b = n == null ? void 0 : n.functionDetails) == null ? void 0 : b.id) !== ((y = r.functionDetails) == null ? void 0 : y.id)));
592
593
  let o = e.parts, u = e.functionMap ?? /* @__PURE__ */ new Map(), d = !e.functionMap;
593
- const h = /* @__PURE__ */ f(() => {
594
+ const h = /* @__PURE__ */ g(() => {
594
595
  d || (u = new Map(u), d = !0);
595
- }, "cloneFunctionMap"), v = /* @__PURE__ */ f(() => {
596
+ }, "cloneFunctionMap"), v = /* @__PURE__ */ g(() => {
596
597
  o === e.parts && (o = e.parts.slice());
597
598
  }, "clonePartsIfShared");
599
+ if (!l && (o == null ? void 0 : o.length) > 0 && (n != null && n.textAppendable)) {
600
+ const f = o[o.length - 1];
601
+ (((N = (A = f.thoughtDetails) == null ? void 0 : A.text) == null ? void 0 : N.length) ?? ((et = f.text) == null ? void 0 : et.length) ?? 0) > Rt && (l = !0);
602
+ }
598
603
  let m = !1;
599
- if ((n == null ? void 0 : n.eventType) === I.FunctionClientOutput && !!((A = n.functionDetails) != null && A.id) && n) {
600
- const g = n.functionDetails.id, C = n.functionDetails.clientOutput, E = o.findIndex((S) => {
604
+ if ((n == null ? void 0 : n.eventType) === C.FunctionClientOutput && !!((st = n.functionDetails) != null && st.id) && n) {
605
+ const f = n.functionDetails.id, I = n.functionDetails.clientOutput, E = o.findIndex((S) => {
601
606
  var p;
602
- return ((p = S.functionDetails) == null ? void 0 : p.id) === g;
607
+ return ((p = S.functionDetails) == null ? void 0 : p.id) === f;
603
608
  });
604
609
  if (E > -1) {
605
610
  const S = o[E], p = {
606
611
  ...S,
607
612
  functionDetails: {
608
613
  ...S.functionDetails,
609
- clientOutput: C ?? S.functionDetails.clientOutput
614
+ clientOutput: I ?? S.functionDetails.clientOutput
610
615
  }
611
616
  };
612
- v(), o[E] = p, h(), u.set(g, p), s.push(p);
617
+ v(), o[E] = p, h(), u.set(f, p), s.push(p);
613
618
  } else {
614
619
  const S = {
615
620
  ...n,
616
621
  id: o.length + 1 + "-" + e.interactionId,
617
622
  functionDetails: { ...n.functionDetails, silent: !0 }
618
623
  };
619
- v(), o = o === e.parts ? e.parts.slice() : o, o.push(S), h(), u.set(g, S);
624
+ v(), o = o === e.parts ? e.parts.slice() : o, o.push(S), h(), u.set(f, S);
620
625
  }
621
626
  } else if (l && n) {
622
- const g = this.isFunctionCall(n.eventType) || this.isFunctionResponse(n.eventType), C = g ? (N = n.functionDetails) == null ? void 0 : N.id : void 0;
623
- g && !C && console.error("Got isCall or isResponse without a callId", n);
624
- const E = C ? u.get(C) : void 0;
625
- if (E && C && n.functionDetails) {
626
- const S = o.findIndex((ft) => {
627
- var st;
628
- return ((st = ft.functionDetails) == null ? void 0 : st.id) === C;
627
+ const f = this.isFunctionCall(n.eventType) || this.isFunctionResponse(n.eventType), I = f ? (nt = n.functionDetails) == null ? void 0 : nt.id : void 0;
628
+ f && !I && console.error("Got isCall or isResponse without a callId", n);
629
+ const E = I ? u.get(I) : void 0;
630
+ if (E && I && n.functionDetails) {
631
+ const S = o.findIndex((mt) => {
632
+ var at;
633
+ return ((at = mt.functionDetails) == null ? void 0 : at.id) === I;
629
634
  }), p = S > -1 ? o[S] : E, F = {
630
635
  ...p,
631
636
  eventType: n.eventType,
@@ -666,9 +671,9 @@ ${n.value}
666
671
  cancelUi: n.functionDetails.cancelUi === !0 || p.functionDetails.cancelUi === !0
667
672
  }
668
673
  };
669
- h(), u.set(C, F), F.eventType === I.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(F.functionDetails), s.push(F), S > -1 && (v(), o[S] = F);
674
+ h(), u.set(I, F), F.eventType === C.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(F.functionDetails), s.push(F), S > -1 && (v(), o[S] = F);
670
675
  } else {
671
- if (C && n.functionDetails && !E && (h(), u.set(C, n)), r && r.textAppendable) {
676
+ if (I && n.functionDetails && !E && (h(), u.set(I, n)), r && r.textAppendable) {
672
677
  const p = {
673
678
  ...r,
674
679
  ended: /* @__PURE__ */ new Date(),
@@ -682,40 +687,40 @@ ${n.value}
682
687
  isStillWriting: n.textAppendable,
683
688
  partial: t.partial
684
689
  };
685
- (et = S.functionDetails) != null && et.silent || s.push(S), o = [...o, S], m = !0;
690
+ (it = S.functionDetails) != null && it.silent || s.push(S), o = [...o, S], m = !0;
686
691
  }
687
692
  }
688
- let y = o[o.length - 1] ?? null;
689
- if (y && n && n.textAppendable) {
690
- const g = {
691
- ...y,
693
+ let T = o[o.length - 1] ?? null;
694
+ if (T && n && n.textAppendable) {
695
+ const f = {
696
+ ...T,
692
697
  partial: t.partial,
693
- textDetails: y.textDetails ? { ...y.textDetails } : { version: 0 }
698
+ textDetails: T.textDetails ? { ...T.textDetails } : { version: 0 }
694
699
  };
695
- let C = !1;
700
+ let I = !1;
696
701
  if (t.partial) {
697
702
  try {
698
- g.textDetails.version++, m || (g.text = (y.text ?? "") + (n.text ?? ""));
703
+ f.textDetails.version++, m || (f.text = (T.text ?? "") + (n.text ?? ""));
699
704
  } catch (E) {
700
705
  console.error("Error here", E.toString());
701
706
  }
702
- g.textLastChunk = n.text ?? "", g.isStillWriting = !0, C = !0, n.thoughtDetails && g.thoughtDetails && n.thoughtDetails.text !== g.thoughtDetails.text && (g.thoughtDetails = {
703
- ...g.thoughtDetails,
704
- text: g.thoughtDetails.text + n.thoughtDetails.text
705
- }, g.thoughtLastChunk = n.thoughtDetails.text);
707
+ f.textLastChunk = n.text ?? "", f.isStillWriting = !0, I = !0, n.thoughtDetails && f.thoughtDetails && (n.thoughtDetails.text.length >= 50 || n.thoughtDetails.text.length < 50 && n.thoughtDetails.text !== f.thoughtDetails.text) && (f.thoughtDetails = {
708
+ ...f.thoughtDetails,
709
+ text: f.thoughtDetails.text + n.thoughtDetails.text
710
+ }, f.thoughtLastChunk = n.thoughtDetails.text);
706
711
  } else
707
- g.isStillWriting = !1, g.text = n.text ?? "", g.textDetails.version++, n.thoughtDetails && (g.thoughtDetails = {
712
+ f.isStillWriting = !1, f.text = n.text ?? "", f.textDetails.version++, n.thoughtDetails && (f.thoughtDetails = {
708
713
  ...n.thoughtDetails,
709
714
  text: n.thoughtDetails.text.trim()
710
- }), C = !l;
711
- v(), o[o.length - 1] = g, y = g, C && s.push(g);
715
+ }), I = !l;
716
+ v(), o[o.length - 1] = f, T = f, I && s.push(f);
712
717
  }
713
718
  let M = e.artifactData ?? [];
714
719
  if (t.llmArtifacts && t.llmArtifacts.length > 0) {
715
- let g = !1;
716
- for (const C of t.llmArtifacts) {
717
- const E = C.toArtifact();
718
- g || (M = M.slice(), g = !0);
720
+ let f = !1;
721
+ for (const I of t.llmArtifacts) {
722
+ const E = I.toArtifact();
723
+ f || (M = M.slice(), f = !0);
719
724
  const S = M.findIndex((p) => p.id === E.id);
720
725
  S === -1 ? M.push(E) : M[S] = E;
721
726
  }
@@ -741,11 +746,11 @@ ${n.value}
741
746
  };
742
747
  }
743
748
  };
744
- f(X, "InteractionService");
745
- let $ = X;
746
- const Pt = 1200 * 1e3, k = class k {
747
- constructor(t, e, s, i, n, r, l, o, u, d = St.Interactive) {
748
- a(this, "base_production_url", mt() ?? "https://agent.tripapi.com.br");
749
+ g(Q, "InteractionService");
750
+ let $ = Q;
751
+ const Ut = 1200 * 1e3, k = class k {
752
+ constructor(t, e, s, i, n, r, l, o, u, d = yt.Interactive) {
753
+ a(this, "base_production_url", Tt() ?? "https://agent.tripapi.com.br");
749
754
  a(this, "base_url_local", "http://localagent:8000");
750
755
  a(this, "base_url");
751
756
  a(this, "isLocal", !1);
@@ -769,46 +774,46 @@ const Pt = 1200 * 1e3, k = class k {
769
774
  //Define all SSEServer methods here, use from SSEServer.ts
770
775
  a(this, "eventBusService");
771
776
  a(this, "artifactService");
772
- a(this, "onTurnOpen", /* @__PURE__ */ f((t) => {
777
+ a(this, "onTurnOpen", /* @__PURE__ */ g((t) => {
773
778
  this.eventBusService.gatewayOnTurnOpen(t);
774
779
  }, "onTurnOpen"));
775
- a(this, "offTurnOpen", /* @__PURE__ */ f((t) => {
780
+ a(this, "offTurnOpen", /* @__PURE__ */ g((t) => {
776
781
  this.eventBusService.gatewayOffTurnOpen(t);
777
782
  }, "offTurnOpen"));
778
- a(this, "onTurnComplete", /* @__PURE__ */ f((t) => {
783
+ a(this, "onTurnComplete", /* @__PURE__ */ g((t) => {
779
784
  this.eventBusService.gatewayOnTurnComplete(t);
780
785
  }, "onTurnComplete"));
781
- a(this, "offTurnComplete", /* @__PURE__ */ f((t) => {
786
+ a(this, "offTurnComplete", /* @__PURE__ */ g((t) => {
782
787
  this.eventBusService.gatewayOffTurnComplete(t);
783
788
  }, "offTurnComplete"));
784
- a(this, "onStreamError", /* @__PURE__ */ f((t) => {
789
+ a(this, "onStreamError", /* @__PURE__ */ g((t) => {
785
790
  this.eventBusService.gatewayOnStreamError(t);
786
791
  }, "onStreamError"));
787
- a(this, "offStreamError", /* @__PURE__ */ f((t) => {
792
+ a(this, "offStreamError", /* @__PURE__ */ g((t) => {
788
793
  this.eventBusService.gatewayOffStreamError(t);
789
794
  }, "offStreamError"));
790
- a(this, "onStreamEnded", /* @__PURE__ */ f((t) => {
795
+ a(this, "onStreamEnded", /* @__PURE__ */ g((t) => {
791
796
  this.eventBusService.gatewayOnStreamEnded(t);
792
797
  }, "onStreamEnded"));
793
- a(this, "offStreamEnded", /* @__PURE__ */ f((t) => {
798
+ a(this, "offStreamEnded", /* @__PURE__ */ g((t) => {
794
799
  this.eventBusService.gatewayOffStreamEnded(t);
795
800
  }, "offStreamEnded"));
796
- a(this, "onMessage", /* @__PURE__ */ f((t) => {
801
+ a(this, "onMessage", /* @__PURE__ */ g((t) => {
797
802
  this.eventBusService.gatewayOnMessage(t);
798
803
  }, "onMessage"));
799
- a(this, "offMessage", /* @__PURE__ */ f((t) => {
804
+ a(this, "offMessage", /* @__PURE__ */ g((t) => {
800
805
  this.eventBusService.gatewayOffMessage(t);
801
806
  }, "offMessage"));
802
- a(this, "onFirstToken", /* @__PURE__ */ f((t) => {
807
+ a(this, "onFirstToken", /* @__PURE__ */ g((t) => {
803
808
  this.eventBusService.gatewayOnFirstToken(t);
804
809
  }, "onFirstToken"));
805
- a(this, "offFirstToken", /* @__PURE__ */ f((t) => {
810
+ a(this, "offFirstToken", /* @__PURE__ */ g((t) => {
806
811
  this.eventBusService.gatewayOffFirstToken(t);
807
812
  }, "offFirstToken"));
808
- a(this, "onFunctionResponse", /* @__PURE__ */ f((t) => {
813
+ a(this, "onFunctionResponse", /* @__PURE__ */ g((t) => {
809
814
  this.eventBusService.gatewayOnFunctionResponse(t);
810
815
  }, "onFunctionResponse"));
811
- a(this, "offFunctionResponse", /* @__PURE__ */ f((t) => {
816
+ a(this, "offFunctionResponse", /* @__PURE__ */ g((t) => {
812
817
  this.eventBusService.gatewayOffFunctionResponse(t);
813
818
  }, "offFunctionResponse"));
814
819
  a(this, "toolSessionId", null);
@@ -1042,7 +1047,7 @@ const Pt = 1200 * 1e3, k = class k {
1042
1047
  }
1043
1048
  } catch (e) {
1044
1049
  if (this.getCurrentInteractionId()) {
1045
- const s = ut.createErrorEvent("OnMessage error: " + e.toString(), this.getCurrentInteractionId() ?? "Empty Current"), i = this.updateMap(s);
1050
+ const s = gt.createErrorEvent("OnMessage error: " + e.toString(), this.getCurrentInteractionId() ?? "Empty Current"), i = this.updateMap(s);
1046
1051
  if (console.error("Error event: ", JSON.stringify(s, void 0, 4)), !i) {
1047
1052
  console.error("Error event, could not update interaction: ", JSON.stringify(s, void 0, 4));
1048
1053
  return;
@@ -1103,7 +1108,7 @@ const Pt = 1200 * 1e3, k = class k {
1103
1108
  }), this.sessionState.setTurnOpen(!1);
1104
1109
  }
1105
1110
  async handlePing() {
1106
- return Date.now() - this.lastPing.getTime() > Pt ? await this.ping() ? (this.lastPing = /* @__PURE__ */ new Date(), this.lastPingStatus = !0, !0) : (this.lastPingStatus = !1, !1) : (this.lastPingStatus = !0, !0);
1111
+ return Date.now() - this.lastPing.getTime() > Ut ? await this.ping() ? (this.lastPing = /* @__PURE__ */ new Date(), this.lastPingStatus = !0, !0) : (this.lastPingStatus = !1, !1) : (this.lastPingStatus = !0, !0);
1107
1112
  }
1108
1113
  async sendMessage(t, e) {
1109
1114
  let s = this.getInteractions().length, i = _.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
@@ -1111,7 +1116,7 @@ const Pt = 1200 * 1e3, k = class k {
1111
1116
  try {
1112
1117
  const { promptAsString: n, json: r } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
1113
1118
  this.sessionState.onRenderPrompt && (t.data = r, t.friendlyMessage = n);
1114
- const l = await this.sendMessageInternal(t, e), o = kt.createPrompt(n ?? "", (r == null ? void 0 : r.toString()) ?? {});
1119
+ const l = await this.sendMessageInternal(t, e), o = bt.createPrompt(n ?? "", (r == null ? void 0 : r.toString()) ?? {});
1115
1120
  this.storageService.storePrompt(o);
1116
1121
  const u = _.fromText("Planejando próximos passos");
1117
1122
  return this.sendStatusMessage(t.data, [i, u], s.toString() + "1"), l != null && l.success ? this.eventBusService.ChatEmitMessageSent(t.data, l.interaction) : this.eventBusService.ChatEmitMessageError((l == null ? void 0 : l.error) ?? ""), l;
@@ -1142,7 +1147,7 @@ const Pt = 1200 * 1e3, k = class k {
1142
1147
  sendStatusMessage(t, e, s) {
1143
1148
  var n, r;
1144
1149
  let i;
1145
- ((r = (n = this.currentIS) == null ? void 0 : n.interaction) == null ? void 0 : r.turn_complete) === !1 ? (i = Nt.cloneDeep(this.currentIS.interaction), i.parts.push(...e)) : i = {
1150
+ ((r = (n = this.currentIS) == null ? void 0 : n.interaction) == null ? void 0 : r.turn_complete) === !1 ? (i = _t.cloneDeep(this.currentIS.interaction), i.parts.push(...e)) : i = {
1146
1151
  interactionId: "tmp" + s,
1147
1152
  created: /* @__PURE__ */ new Date(),
1148
1153
  partial: !0,
@@ -1165,13 +1170,13 @@ const Pt = 1200 * 1e3, k = class k {
1165
1170
  }
1166
1171
  }
1167
1172
  getNewInteractionId() {
1168
- const e = At(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
1173
+ const e = Pt(/* @__PURE__ */ new Date(), "MMM_dd_HH_mm_ss");
1169
1174
  return `${this.msg_order}_${e}`;
1170
1175
  }
1171
1176
  };
1172
- f(k, "AgentGatewayService"), a(k, "SUSPENSION_MSG", "SUSPEND"), a(k, "CURRENT_MSG_THROTTLE_MS", 20);
1177
+ g(k, "AgentGatewayService"), a(k, "SUSPENSION_MSG", "SUSPEND"), a(k, "CURRENT_MSG_THROTTLE_MS", 20);
1173
1178
  let G = k;
1174
- const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2, ot = 2, Z = class Z {
1179
+ const H = 4001, Lt = 4002, lt = 4, xt = 3, Bt = 500, Wt = 3e4, $t = 2, qt = 0.2, ht = 2, Z = class Z {
1175
1180
  constructor(t = "ws://localhost:8000", e) {
1176
1181
  a(this, "ws", null);
1177
1182
  a(this, "stats");
@@ -1261,7 +1266,7 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
1261
1266
  * Cleared by `disconnect()`.
1262
1267
  */
1263
1268
  a(this, "hasEverReceivedPacket", !1);
1264
- this.baseUrl = t, this.getToken = e, this.pingPongStack = [], this.events = [], this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = yt(), console.log("SOCKET INSTACE", wt()), this.stats = {
1269
+ this.baseUrl = t, this.getToken = e, this.pingPongStack = [], this.events = [], this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = Ct(), console.log("SOCKET INSTACE", It()), this.stats = {
1265
1270
  eventCount: 0,
1266
1271
  unknonwCount: 0,
1267
1272
  buffer: [],
@@ -1296,55 +1301,55 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
1296
1301
  let h = !1;
1297
1302
  this.ws.onopen = () => {
1298
1303
  console.log("[WebSocket] Connected");
1299
- const T = this.isReconnecting;
1300
- this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(), T && this.onReconnected && this.onReconnected(t ?? this.lastKnownSessionId ?? ""), this.flushPendingAnswers(t ?? this.lastKnownSessionId);
1301
- }, this.ws.onmessage = (T) => {
1304
+ const y = this.isReconnecting;
1305
+ this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(), y && this.onReconnected && this.onReconnected(t ?? this.lastKnownSessionId ?? ""), this.flushPendingAnswers(t ?? this.lastKnownSessionId);
1306
+ }, this.ws.onmessage = (y) => {
1302
1307
  try {
1303
1308
  this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
1304
- const A = this.streamingResponseSerializer.parse(T.data);
1309
+ const A = this.streamingResponseSerializer.parse(y.data);
1305
1310
  if (!A)
1306
1311
  throw "Error parsing event JSON";
1307
- const N = this.handleMessage(A, T.data);
1312
+ const N = this.handleMessage(A, y.data);
1308
1313
  !h && (N != null && N.timestamp) && (h = !0, this.hasEverReceivedPacket = !0);
1309
1314
  } catch (A) {
1310
1315
  console.error("[WebSocket] Error parsing message:", A);
1311
1316
  }
1312
- }, this.ws.onerror = (T) => {
1313
- console.error("[WebSocket] Error:", T), this.onError && this.onError("WebSocket error");
1314
- }, this.ws.onclose = (T) => {
1315
- console.log("[WebSocket] Closed:", T.code, T.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
1317
+ }, this.ws.onerror = (y) => {
1318
+ console.error("[WebSocket] Error:", y), this.onError && this.onError("WebSocket error");
1319
+ }, this.ws.onclose = (y) => {
1320
+ console.log("[WebSocket] Closed:", y.code, y.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
1316
1321
  const A = this.sessionId ?? this.lastKnownSessionId;
1317
- if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(T.code)) {
1318
- this.scheduleReconnect(A, T.code, T.reason);
1322
+ if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(y.code)) {
1323
+ this.scheduleReconnect(A, y.code, y.reason);
1319
1324
  return;
1320
1325
  }
1321
- this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(T.code, T.reason);
1326
+ this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(y.code, y.reason);
1322
1327
  };
1323
- const v = 200, m = 3e4, D = 8e3, y = this.ws;
1328
+ const v = 200, m = 3e4, D = 8e3, T = this.ws;
1324
1329
  this.sessionId = void 0;
1325
1330
  let M = 0, P = 0;
1326
1331
  for (; !this.sessionId; ) {
1327
- if (this.ws !== y) {
1332
+ if (this.ws !== T) {
1328
1333
  s("Connection attempt superseded by a newer connect()");
1329
1334
  return;
1330
1335
  }
1331
- if (y.readyState === WebSocket.CLOSING || y.readyState === WebSocket.CLOSED) {
1336
+ if (T.readyState === WebSocket.CLOSING || T.readyState === WebSocket.CLOSED) {
1332
1337
  s("Connection closed before a session id was received");
1333
1338
  return;
1334
1339
  }
1335
- if (y.readyState === WebSocket.CONNECTING && M >= m) {
1340
+ if (T.readyState === WebSocket.CONNECTING && M >= m) {
1336
1341
  try {
1337
- y.close();
1342
+ T.close();
1338
1343
  } catch {
1339
1344
  }
1340
1345
  s(`Server did not accept the connection within ${m / 1e3}s`);
1341
1346
  return;
1342
1347
  }
1343
- if (y.readyState === WebSocket.OPEN && P >= D) {
1348
+ if (T.readyState === WebSocket.OPEN && P >= D) {
1344
1349
  s(`Connected but no session id arrived within ${D / 1e3}s`);
1345
1350
  return;
1346
1351
  }
1347
- M % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(v), M += v, y.readyState === WebSocket.OPEN && (P += v);
1352
+ M % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(v), M += v, T.readyState === WebSocket.OPEN && (P += v);
1348
1353
  }
1349
1354
  console.log("SUCCESS - GOT SESSION ID", this.sessionId), this.lastKnownSessionId = this.sessionId, e(this.sessionId);
1350
1355
  });
@@ -1359,19 +1364,19 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
1359
1364
  * - 4000-4099 reserved for app-level fatal codes from the server
1360
1365
  */
1361
1366
  shouldAttemptReconnect(t) {
1362
- return !(this.intentionalDisconnect || t === H || t === _t || t === 1e3 || t === 1008);
1367
+ return !(this.intentionalDisconnect || t === H || t === Lt || t === 1e3 || t === 1008);
1363
1368
  }
1364
1369
  cancelPendingReconnect() {
1365
1370
  this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
1366
1371
  }
1367
1372
  computeBackoffDelay() {
1368
- const t = Ft * Math.pow(Ut, this.reconnectAttempts), e = Math.min(t, Rt), s = e * Lt * (Math.random() * 2 - 1);
1373
+ const t = Bt * Math.pow($t, this.reconnectAttempts), e = Math.min(t, Wt), s = e * qt * (Math.random() * 2 - 1);
1369
1374
  return Math.max(0, Math.round(e + s));
1370
1375
  }
1371
1376
  scheduleReconnect(t, e, s) {
1372
1377
  var n, r;
1373
1378
  if (this.intentionalDisconnect) return;
1374
- if (this.reconnectAttempts >= ot) {
1379
+ if (this.reconnectAttempts >= ht) {
1375
1380
  console.warn(
1376
1381
  `[WebSocket] Reconnect exhausted after ${this.reconnectAttempts} attempts (last code=${e}, reason="${s}"). Handing off to outer state manager.`
1377
1382
  ), this.isReconnecting = !1, this.reconnectAttempts = 0, this.cancelPendingReconnect(), (n = this.onClose) == null || n.call(this, e, s);
@@ -1380,7 +1385,7 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
1380
1385
  this.isReconnecting = !0, this.reconnectAttempts += 1;
1381
1386
  const i = this.computeBackoffDelay();
1382
1387
  console.warn(
1383
- `[WebSocket] Unexpected close (code=${e}, reason="${s}"). Reconnect attempt #${this.reconnectAttempts}/${ot} in ${i}ms (resume sessionId=${t ?? "none"}).`
1388
+ `[WebSocket] Unexpected close (code=${e}, reason="${s}"). Reconnect attempt #${this.reconnectAttempts}/${ht} in ${i}ms (resume sessionId=${t ?? "none"}).`
1384
1389
  ), (r = this.onReconnecting) == null || r.call(this, this.reconnectAttempts, i), this.cancelPendingReconnect(), this.reconnectTimer = setTimeout(async () => {
1385
1390
  if (this.reconnectTimer = null, !this.intentionalDisconnect)
1386
1391
  try {
@@ -1422,27 +1427,27 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
1422
1427
  if (t.partialEvent) {
1423
1428
  const d = t.partialEvent;
1424
1429
  this.emitFirstToken(d == null ? void 0 : d.iteractionId);
1425
- const h = new Tt();
1430
+ const h = new vt();
1426
1431
  if (h.author = "main", h.streamingParts = t.partialEvent.streamingParts, t.partialEvent.partialEventType ? h.eventType = t.partialEvent.partialEventType : h.eventType = d.functionName ? {
1427
1432
  fullName: x.StreamingFunctionCallUpdateContent,
1428
- type: I.PartialFunctionCall
1433
+ type: C.PartialFunctionCall
1429
1434
  } : d.partialReasoning ? {
1430
1435
  fullName: x.StreamingReasoningContent,
1431
- type: I.Thought
1436
+ type: C.Thought
1432
1437
  } : {
1433
1438
  fullName: x.StreamingTextContent,
1434
- type: I.Text
1435
- }, h.interactionId = (d == null ? void 0 : d.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == I.PartialFunctionCall) {
1436
- var s = new It();
1439
+ type: C.Text
1440
+ }, h.interactionId = (d == null ? void 0 : d.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == C.PartialFunctionCall) {
1441
+ var s = new Et();
1437
1442
  s.choiceIndex = 0, s.callId = d.functionCallId, s.arguments = d.partialText, s.name = d.functionName, h.content = {
1438
1443
  items: [s],
1439
1444
  role: {
1440
1445
  label: "Assistant"
1441
1446
  }
1442
1447
  };
1443
- } else if (h.eventType.type == I.Text)
1448
+ } else if (h.eventType.type == C.Text)
1444
1449
  if (h.eventType.fullName == x.StreamingTextContent) {
1445
- var i = new Ct();
1450
+ var i = new Mt();
1446
1451
  i.text = d.partialText, h.content = {
1447
1452
  items: [i],
1448
1453
  role: {
@@ -1450,7 +1455,7 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
1450
1455
  }
1451
1456
  };
1452
1457
  } else {
1453
- var n = new vt();
1458
+ var n = new Ot();
1454
1459
  n.text = d.partialText, h.content = {
1455
1460
  items: [n],
1456
1461
  role: {
@@ -1458,8 +1463,8 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
1458
1463
  }
1459
1464
  };
1460
1465
  }
1461
- else if (h.eventType.type == I.Thought) {
1462
- var r = new Et();
1466
+ else if (h.eventType.type == C.Thought) {
1467
+ var r = new Dt();
1463
1468
  r.text = d.partialReasoning, h.content = {
1464
1469
  items: [r],
1465
1470
  role: {
@@ -1646,12 +1651,12 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
1646
1651
  async handleEvent(t, e) {
1647
1652
  var s;
1648
1653
  try {
1649
- const i = ut.parseFromTypedEvent(t);
1654
+ const i = gt.parseFromTypedEvent(t);
1650
1655
  if (!i)
1651
1656
  throw "Server event was null";
1652
1657
  this.events.push([(/* @__PURE__ */ new Date()).getTime(), ((s = t.text) == null ? void 0 : s.length) ?? 0]), this.stats.eventCount += 1, this.stats.totalTransfered += e.length, i.session_information && !i.subAgentId && (this.stats.sessionInformation = i.session_information), this.stats.elapsed = (Date.now() - this.stats.startTime.getTime()) / 1e3;
1653
- const n = Date.now() - rt * 1e3, l = this.events.filter((o) => o[0] > n).reduce((o, u) => o += u[1], 0) / bt;
1654
- this.stats.tokensPerSecond = l / rt, this.flushStatsCoalesced(), this.onEvent && this.onEvent(i).catch((o) => {
1658
+ const n = Date.now() - lt * 1e3, l = this.events.filter((o) => o[0] > n).reduce((o, u) => o += u[1], 0) / xt;
1659
+ this.stats.tokensPerSecond = l / lt, this.flushStatsCoalesced(), this.onEvent && this.onEvent(i).catch((o) => {
1655
1660
  console.error("Lost error on on-event", o);
1656
1661
  });
1657
1662
  } catch (i) {
@@ -1659,9 +1664,9 @@ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2,
1659
1664
  }
1660
1665
  }
1661
1666
  };
1662
- f(Z, "WebSocketConnecionV2");
1663
- let ct = Z;
1664
- const xt = "envision_agent_sessionId", V = class V extends G {
1667
+ g(Z, "WebSocketConnecionV2");
1668
+ let ut = Z;
1669
+ const Jt = "envision_agent_sessionId", V = class V extends G {
1665
1670
  constructor(e, s, i, n, r, l, o, u, d, h, v) {
1666
1671
  super(e, s, i, n, r, l, o, d, v);
1667
1672
  a(this, "suspendState", !1);
@@ -1716,7 +1721,7 @@ const xt = "envision_agent_sessionId", V = class V extends G {
1716
1721
  return this.suspendState;
1717
1722
  }
1718
1723
  getStoredSessionId() {
1719
- const e = localStorage.getItem(xt);
1724
+ const e = localStorage.getItem(Jt);
1720
1725
  if (e)
1721
1726
  return e;
1722
1727
  }
@@ -1832,7 +1837,7 @@ const xt = "envision_agent_sessionId", V = class V extends G {
1832
1837
  },
1833
1838
  // Forward image attachments as a structured payload (PascalCase
1834
1839
  // keys to match the C# `Message.Images` / `MessageImage` model).
1835
- Images: (m = e.images) != null && m.length ? e.images.map((y) => ({ MimeType: y.mimeType, Data: y.data })) : void 0,
1840
+ Images: (m = e.images) != null && m.length ? e.images.map((T) => ({ MimeType: T.mimeType, Data: T.data })) : void 0,
1836
1841
  // Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
1837
1842
  // model). The server persists it as a UserUiContent sibling and strips it from the model
1838
1843
  // request; Content remains the only model-facing text.
@@ -1843,8 +1848,8 @@ const xt = "envision_agent_sessionId", V = class V extends G {
1843
1848
  });
1844
1849
  }
1845
1850
  };
1846
- f(V, "AgentGatewayWSAsync");
1847
- let lt = V;
1851
+ g(V, "AgentGatewayWSAsync");
1852
+ let dt = V;
1848
1853
  const tt = class tt {
1849
1854
  constructor(t, e) {
1850
1855
  a(this, "cache", /* @__PURE__ */ new Map());
@@ -1853,7 +1858,7 @@ const tt = class tt {
1853
1858
  this.serverBaseUrl = t.replace(/\/$/, ""), this.accessToken = e;
1854
1859
  }
1855
1860
  get headers() {
1856
- return { Authorization: `Bearer ${this.accessToken}` };
1861
+ return { Authorization: `Bearer ${Ft(this.accessToken)}` };
1857
1862
  }
1858
1863
  async init() {
1859
1864
  }
@@ -1900,17 +1905,17 @@ const tt = class tt {
1900
1905
  }
1901
1906
  }
1902
1907
  };
1903
- f(tt, "HttpArtifactService");
1904
- let ht = tt;
1908
+ g(tt, "HttpArtifactService");
1909
+ let ft = tt;
1905
1910
  export {
1906
1911
  G as A,
1907
1912
  J as E,
1908
- ht as H,
1913
+ ft as H,
1909
1914
  $ as I,
1910
- it as L,
1911
- at as M,
1912
- ct as W,
1913
- lt as a,
1914
- Yt as u
1915
+ ot as L,
1916
+ ct as M,
1917
+ ut as W,
1918
+ dt as a,
1919
+ te as u
1915
1920
  };
1916
- //# sourceMappingURL=httpArtifactService-BpRwcTJp.js.map
1921
+ //# sourceMappingURL=httpArtifactService-DBKIvfSD.js.map