@aintela/chat 0.2.29 → 0.2.31

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.
@@ -2,19 +2,19 @@ var nt = Object.defineProperty;
2
2
  var gt = (O, t, e) => t in O ? nt(O, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : O[t] = e;
3
3
  var f = (O, t) => nt(O, "name", { value: t, configurable: !0 });
4
4
  var a = (O, t, e) => gt(O, typeof t != "symbol" ? t + "" : t, e);
5
- import { d as _, t as mt, E as y, k as pt, j as St, q as wt, C as L } from "./environmentUtils-CUVZ6Dq1.js";
6
- import { I as A, S as ut, g as Tt, L as yt, P as F, b as It, e as Ct, T as vt, c as Et } from "./serializer-BPina6fX.js";
5
+ import { d as R, t as mt, E as y, k as pt, j as St, q as wt, C as x } from "./environmentUtils-CUVZ6Dq1.js";
6
+ import { I as P, S as ut, g as Tt, L as yt, P as U, b as It, e as Ct, T as vt, c as Et } from "./serializer-DTyYgExG.js";
7
7
  import { unified as Mt } from "unified";
8
8
  import Ot from "remark-parse";
9
9
  import { toMarkdown as Dt } from "mdast-util-to-markdown";
10
10
  import { format as At } from "date-fns";
11
11
  import Nt from "lodash";
12
- import { P as Pt, C as P } from "./Prompt-DZb7OaPp.js";
12
+ import { P as Pt, C as _ } from "./Prompt-DZb7OaPp.js";
13
13
  const T = {
14
14
  ARTIFACTS: "envision-artifacts",
15
15
  SECTIONS: "envision-sections",
16
16
  PROMPTS: "envision-prompts"
17
- }, k = [
17
+ }, F = [
18
18
  {
19
19
  id: "dashboards",
20
20
  name: "Dashboards",
@@ -36,7 +36,7 @@ const T = {
36
36
  created: (/* @__PURE__ */ new Date()).toISOString(),
37
37
  iconType: "folder"
38
38
  }
39
- ], J = class J {
39
+ ], q = class q {
40
40
  constructor() {
41
41
  a(this, "onPromptCreated", /* @__PURE__ */ f(() => {
42
42
  }, "onPromptCreated"));
@@ -54,14 +54,14 @@ const T = {
54
54
  try {
55
55
  const t = localStorage.getItem(T.SECTIONS);
56
56
  if (!t)
57
- localStorage.setItem(T.SECTIONS, JSON.stringify(k));
57
+ localStorage.setItem(T.SECTIONS, JSON.stringify(F));
58
58
  else {
59
59
  const s = JSON.parse(t);
60
- if (k.some(
60
+ if (F.some(
61
61
  (n) => !s.find((r) => r.id === n.id)
62
62
  )) {
63
63
  const n = [...s];
64
- k.forEach((r) => {
64
+ F.forEach((r) => {
65
65
  s.find((l) => l.id === r.id) || n.push(r);
66
66
  }), localStorage.setItem(T.SECTIONS, JSON.stringify(n));
67
67
  }
@@ -74,7 +74,7 @@ const T = {
74
74
  if (!r.sectionId) {
75
75
  i = !0;
76
76
  let l = "data-analytics";
77
- return r.type === _.Dashboard ? l = "dashboards" : r.type === _.Chart && (l = "charts"), {
77
+ return r.type === R.Dashboard ? l = "dashboards" : r.type === R.Chart && (l = "charts"), {
78
78
  ...r,
79
79
  sectionId: l
80
80
  };
@@ -90,9 +90,9 @@ const T = {
90
90
  getSections() {
91
91
  try {
92
92
  const t = localStorage.getItem(T.SECTIONS);
93
- return t ? JSON.parse(t) : k;
93
+ return t ? JSON.parse(t) : F;
94
94
  } catch (t) {
95
- return console.error("Error loading sections:", t), k;
95
+ return console.error("Error loading sections:", t), F;
96
96
  }
97
97
  }
98
98
  getArtifacts() {
@@ -133,7 +133,7 @@ const T = {
133
133
  e[s] = t;
134
134
  else {
135
135
  let i = "data-analytics";
136
- t.type === _.Dashboard ? i = "dashboards" : t.type === _.Chart && (i = "charts");
136
+ t.type === R.Dashboard ? i = "dashboards" : t.type === R.Chart && (i = "charts");
137
137
  const n = {
138
138
  ...t,
139
139
  created: t.created || (/* @__PURE__ */ new Date()).toISOString(),
@@ -196,8 +196,8 @@ const T = {
196
196
  }
197
197
  }
198
198
  };
199
- f(J, "LocalStorageService");
200
- let it = J;
199
+ f(q, "LocalStorageService");
200
+ let it = q;
201
201
  const jt = /* @__PURE__ */ f((O) => {
202
202
  const t = O.getPrompts(), e = t.length;
203
203
  if (e > 0) {
@@ -205,7 +205,7 @@ const jt = /* @__PURE__ */ f((O) => {
205
205
  return { promptState: e + "_" + s + "_" + i + "_" + n };
206
206
  } else
207
207
  return { promptState: "0" };
208
- }, "usePromptState"), q = class q {
208
+ }, "usePromptState"), G = class G {
209
209
  constructor() {
210
210
  a(this, "activityLost", "activityLost");
211
211
  a(this, "artifactGenerated", "artifactGenerated");
@@ -230,9 +230,9 @@ const jt = /* @__PURE__ */ f((O) => {
230
230
  a(this, "gatewayFirstToken", "gatewayFirstToken");
231
231
  }
232
232
  };
233
- f(q, "EventTypes");
234
- let x = q;
235
- const c = new x(), G = class G {
233
+ f(G, "EventTypes");
234
+ let B = G;
235
+ const c = new B(), H = class H {
236
236
  constructor() {
237
237
  a(this, "listeners", {});
238
238
  a(this, "listenersCount", {});
@@ -483,9 +483,9 @@ const c = new x(), G = class G {
483
483
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
484
484
  }
485
485
  };
486
- f(G, "EventBusService");
487
- let B = G;
488
- const H = class H extends B {
486
+ f(H, "EventBusService");
487
+ let $ = H;
488
+ const K = class K extends $ {
489
489
  constructor() {
490
490
  super();
491
491
  }
@@ -511,12 +511,12 @@ const H = class H extends B {
511
511
  console.log("MockEventBusService.gatewayOffFunctionResponse", t);
512
512
  }
513
513
  };
514
- f(H, "MockEventBusService");
515
- let at = H;
514
+ f(K, "MockEventBusService");
515
+ let at = K;
516
516
  const dt = {
517
517
  inline: "inline",
518
518
  block: "block"
519
- }, K = class K {
519
+ }, z = class z {
520
520
  constructor() {
521
521
  a(this, "parts", []);
522
522
  a(this, "isLastGroup", !1);
@@ -525,9 +525,9 @@ const dt = {
525
525
  a(this, "type", dt.inline);
526
526
  }
527
527
  };
528
- f(K, "InteractionPartGroup");
529
- let R = K;
530
- const z = class z {
528
+ f(z, "InteractionPartGroup");
529
+ let b = z;
530
+ const j = class j {
531
531
  constructor(t, e) {
532
532
  a(this, "interaction");
533
533
  a(this, "eventBusService");
@@ -549,7 +549,7 @@ ${n.value}
549
549
  const s = this.parseTextIntoParts(t), i = [];
550
550
  let n = 0;
551
551
  for (const r of s) {
552
- const l = A.fromText(r);
552
+ const l = P.fromText(r);
553
553
  l.id = n + "_" + e, i.push(l), n++;
554
554
  }
555
555
  return i;
@@ -557,11 +557,11 @@ ${n.value}
557
557
  groupPartsByDisplayType(t, e = !0, s = !1) {
558
558
  var l;
559
559
  const i = [];
560
- let n = new R();
560
+ let n = new b();
561
561
  for (let o = 0; o < t.length; o++) {
562
562
  const u = t[o];
563
563
  let h = !(((l = u.functionDetails) == null ? void 0 : l.isUi) ?? !1) && u.eventType !== y.Text && u.eventType !== y.Thought && (u.eventType === y.FunctionCall || u.eventType === y.PartialFunctionCall || u.eventType === y.FunctionResponse) && o < t.length - 1;
564
- !e && h && !s || (h ? (u.eventType == y.Thought && (n.hasThoughts = !0), n.parts.push(u), n.isLastGroup = o === t.length - 1) : (n.parts.length > 0 && (i.push(n), n = new R()), i.push({
564
+ !e && h && !s || (h ? (u.eventType == y.Thought && (n.hasThoughts = !0), n.parts.push(u), n.isLastGroup = o === t.length - 1) : (n.parts.length > 0 && (i.push(n), n = new b()), i.push({
565
565
  type: dt.block,
566
566
  parts: [u],
567
567
  isLastGroup: o === t.length - 1,
@@ -585,48 +585,48 @@ ${n.value}
585
585
  // new tree as the last step, so snapshots already handed out to throttled
586
586
  // subscribers can't diverge from the live state.
587
587
  merge(t) {
588
- var X, Z, V, tt, et;
589
- const e = this.interaction, s = [], i = [], n = A.FlatParts(t == null ? void 0 : t.parts), r = e.parts[e.parts.length - 1] ?? null;
588
+ var A, Z, V, tt, et;
589
+ const e = this.interaction, s = [], i = [], n = P.FlatParts(t == null ? void 0 : t.parts), r = e.parts[e.parts.length - 1] ?? null;
590
590
  let l = !1;
591
- n && (l = !r || n.mustPush || n.mustPush === !1 && (n.eventType !== (r == null ? void 0 : r.eventType) || ((X = n == null ? void 0 : n.functionDetails) == null ? void 0 : X.id) !== ((Z = r.functionDetails) == null ? void 0 : Z.id)));
591
+ n && (l = !r || n.mustPush || n.mustPush === !1 && (n.eventType !== (r == null ? void 0 : r.eventType) || ((A = n == null ? void 0 : n.functionDetails) == null ? void 0 : A.id) !== ((Z = r.functionDetails) == null ? void 0 : Z.id)));
592
592
  let o = e.parts, u = e.functionMap ?? /* @__PURE__ */ new Map(), d = !e.functionMap;
593
593
  const h = /* @__PURE__ */ f(() => {
594
594
  d || (u = new Map(u), d = !0);
595
- }, "cloneFunctionMap"), v = /* @__PURE__ */ f(() => {
595
+ }, "cloneFunctionMap"), C = /* @__PURE__ */ f(() => {
596
596
  o === e.parts && (o = e.parts.slice());
597
597
  }, "clonePartsIfShared");
598
598
  let p = !1;
599
599
  if ((n == null ? void 0 : n.eventType) === y.FunctionClientOutput && !!((V = n.functionDetails) != null && V.id) && n) {
600
- const g = n.functionDetails.id, C = n.functionDetails.clientOutput, E = o.findIndex((w) => {
600
+ const g = n.functionDetails.id, I = n.functionDetails.clientOutput, v = o.findIndex((w) => {
601
601
  var m;
602
602
  return ((m = w.functionDetails) == null ? void 0 : m.id) === g;
603
603
  });
604
- if (E > -1) {
605
- const w = o[E], m = {
604
+ if (v > -1) {
605
+ const w = o[v], m = {
606
606
  ...w,
607
607
  functionDetails: {
608
608
  ...w.functionDetails,
609
- clientOutput: C ?? w.functionDetails.clientOutput
609
+ clientOutput: I ?? w.functionDetails.clientOutput
610
610
  }
611
611
  };
612
- v(), o[E] = m, h(), u.set(g, m), s.push(m);
612
+ C(), o[v] = m, h(), u.set(g, m), s.push(m);
613
613
  } else {
614
614
  const w = {
615
615
  ...n,
616
616
  id: o.length + 1 + "-" + e.interactionId,
617
617
  functionDetails: { ...n.functionDetails, silent: !0 }
618
618
  };
619
- v(), o = o === e.parts ? e.parts.slice() : o, o.push(w), h(), u.set(g, w);
619
+ C(), o = o === e.parts ? e.parts.slice() : o, o.push(w), h(), u.set(g, w);
620
620
  }
621
621
  } else if (l && n) {
622
- const g = this.isFunctionCall(n.eventType) || this.isFunctionResponse(n.eventType), C = g ? (tt = n.functionDetails) == null ? void 0 : tt.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) {
622
+ const g = this.isFunctionCall(n.eventType) || this.isFunctionResponse(n.eventType), I = g ? (tt = n.functionDetails) == null ? void 0 : tt.id : void 0;
623
+ g && !I && console.error("Got isCall or isResponse without a callId", n);
624
+ const v = I ? u.get(I) : void 0;
625
+ if (v && I && n.functionDetails) {
626
626
  const w = o.findIndex((ft) => {
627
627
  var st;
628
- return ((st = ft.functionDetails) == null ? void 0 : st.id) === C;
629
- }), m = w > -1 ? o[w] : E, N = {
628
+ return ((st = ft.functionDetails) == null ? void 0 : st.id) === I;
629
+ }), m = w > -1 ? o[w] : v, k = {
630
630
  ...m,
631
631
  eventType: n.eventType,
632
632
  functionDetails: {
@@ -660,18 +660,21 @@ ${n.value}
660
660
  // the docked drawer never surfaces (issue #60 — esp. a no-arg tool like update_profile,
661
661
  // which has no name match to fall back on the way ask_user/askauth do).
662
662
  askUserComponent: n.functionDetails.askUserComponent ?? m.functionDetails.askUserComponent,
663
- isAskUser: n.functionDetails.isAskUser || m.functionDetails.isAskUser || !!(n.functionDetails.askUserComponent ?? m.functionDetails.askUserComponent)
663
+ isAskUser: n.functionDetails.isAskUser || m.functionDetails.isAskUser || !!(n.functionDetails.askUserComponent ?? m.functionDetails.askUserComponent),
664
+ // Runtime "don't render" override rides the RESULT; true-wins sticky like isUi so it
665
+ // survives folding onto the earlier call rep and suppresses drawer/uiTool classification.
666
+ cancelUi: n.functionDetails.cancelUi === !0 || m.functionDetails.cancelUi === !0
664
667
  }
665
668
  };
666
- h(), u.set(C, N), N.eventType === y.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(N.functionDetails), s.push(N), w > -1 && (v(), o[w] = N);
669
+ h(), u.set(I, k), k.eventType === y.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(k.functionDetails), s.push(k), w > -1 && (C(), o[w] = k);
667
670
  } else {
668
- if (C && n.functionDetails && !E && (h(), u.set(C, n)), r && r.textAppendable) {
671
+ if (I && n.functionDetails && !v && (h(), u.set(I, n)), r && r.textAppendable) {
669
672
  const m = {
670
673
  ...r,
671
674
  ended: /* @__PURE__ */ new Date(),
672
675
  isStillWriting: !1
673
676
  };
674
- v(), o[o.length - 1] = m, s.push(m);
677
+ C(), o[o.length - 1] = m, s.push(m);
675
678
  }
676
679
  const w = {
677
680
  ...n,
@@ -682,21 +685,21 @@ ${n.value}
682
685
  (et = w.functionDetails) != null && et.silent || s.push(w), o = [...o, w], p = !0;
683
686
  }
684
687
  }
685
- let I = o[o.length - 1] ?? null;
686
- if (I && n && n.textAppendable) {
688
+ let E = o[o.length - 1] ?? null;
689
+ if (E && n && n.textAppendable) {
687
690
  const g = {
688
- ...I,
691
+ ...E,
689
692
  partial: t.partial,
690
- textDetails: I.textDetails ? { ...I.textDetails } : { version: 0 }
693
+ textDetails: E.textDetails ? { ...E.textDetails } : { version: 0 }
691
694
  };
692
- let C = !1;
695
+ let I = !1;
693
696
  if (t.partial) {
694
697
  try {
695
- g.textDetails.version++, p || (g.text = (I.text ?? "") + (n.text ?? ""));
696
- } catch (E) {
697
- console.error("Error here", E.toString());
698
+ g.textDetails.version++, p || (g.text = (E.text ?? "") + (n.text ?? ""));
699
+ } catch (v) {
700
+ console.error("Error here", v.toString());
698
701
  }
699
- g.textLastChunk = n.text ?? "", g.isStillWriting = !0, C = !0, n.thoughtDetails && g.thoughtDetails && n.thoughtDetails.text !== g.thoughtDetails.text && (g.thoughtDetails = {
702
+ g.textLastChunk = n.text ?? "", g.isStillWriting = !0, I = !0, n.thoughtDetails && g.thoughtDetails && n.thoughtDetails.text !== g.thoughtDetails.text && (g.thoughtDetails = {
700
703
  ...g.thoughtDetails,
701
704
  text: g.thoughtDetails.text + n.thoughtDetails.text
702
705
  }, g.thoughtLastChunk = n.thoughtDetails.text);
@@ -704,43 +707,43 @@ ${n.value}
704
707
  g.isStillWriting = !1, g.text = n.text ?? "", g.textDetails.version++, n.thoughtDetails && (g.thoughtDetails = {
705
708
  ...n.thoughtDetails,
706
709
  text: n.thoughtDetails.text.trim()
707
- }), C = !l;
708
- v(), o[o.length - 1] = g, I = g, C && s.push(g);
710
+ }), I = !l;
711
+ C(), o[o.length - 1] = g, E = g, I && s.push(g);
709
712
  }
710
- let M = e.artifactData ?? [];
713
+ let S = e.artifactData ?? [];
711
714
  if (t.llmArtifacts && t.llmArtifacts.length > 0) {
712
715
  let g = !1;
713
- for (const C of t.llmArtifacts) {
714
- const E = C.toArtifact();
715
- g || (M = M.slice(), g = !0);
716
- const w = M.findIndex((m) => m.id === E.id);
717
- w === -1 ? M.push(E) : M[w] = E;
716
+ for (const I of t.llmArtifacts) {
717
+ const v = I.toArtifact();
718
+ g || (S = S.slice(), g = !0);
719
+ const w = S.findIndex((m) => m.id === v.id);
720
+ w === -1 ? S.push(v) : S[w] = v;
718
721
  }
719
722
  }
720
- const U = {
723
+ const M = {
721
724
  ...e,
722
725
  version: e.version + 1,
723
726
  parts: o,
724
- artifactData: M,
727
+ artifactData: S,
725
728
  functionMap: u,
726
729
  turn_complete: t.turn_complete,
727
730
  partial: t.partial,
728
731
  asyncFinalResponse: t.asyncFinalResponse
729
732
  };
730
- return this.interaction = U, {
731
- updatedInteraction: U,
733
+ return this.interaction = M, {
734
+ updatedInteraction: M,
732
735
  updatedParts: s,
733
736
  newArtifacts: i,
734
- mainBranch: U,
737
+ mainBranch: M,
735
738
  analyticsBranch: null,
736
739
  analyticsBranchPartsChanged: null,
737
740
  mainBranchPartsChanged: s
738
741
  };
739
742
  }
740
743
  };
741
- f(z, "InteractionService");
742
- let b = z;
743
- const kt = 1200 * 1e3, D = class D {
744
+ f(j, "InteractionService");
745
+ let L = j;
746
+ const kt = 1200 * 1e3, N = class N {
744
747
  constructor(t, e, s, i, n, r, l, o, u, d = St.Interactive) {
745
748
  a(this, "base_production_url", pt() ?? "https://agent.tripapi.com.br");
746
749
  a(this, "base_url_local", "http://localagent:8000");
@@ -817,7 +820,7 @@ const kt = 1200 * 1e3, D = class D {
817
820
  a(this, "subAgentInteractionServices", /* @__PURE__ */ new Map());
818
821
  a(this, "lastThorttledTimeout", null);
819
822
  a(this, "lastPingStatus", !1);
820
- this.user = t, this.config = n, this.rawJwt = t.access_token, this.base_url = i, this.eventBusService = e, this.sessionId = u, this.runMode = d, this.artifactService = s, this.sessionState = r.getState(), this.notificationPort = l, this.storageService = o, r.subscribe((h, v) => {
823
+ this.user = t, this.config = n, this.rawJwt = t.access_token, this.base_url = i, this.eventBusService = e, this.sessionId = u, this.runMode = d, this.artifactService = s, this.sessionState = r.getState(), this.notificationPort = l, this.storageService = o, r.subscribe((h, C) => {
821
824
  this.sessionState = h;
822
825
  });
823
826
  }
@@ -902,7 +905,7 @@ const kt = 1200 * 1e3, D = class D {
902
905
  functionMap: /* @__PURE__ */ new Map(),
903
906
  interactionQuestion: t
904
907
  };
905
- return this.interactionsMap.set(n.interactionId, n), this.currentIS = new b(n, this.eventBusService), this.interactionsServiceMap.set(n.interactionId, this.currentIS), n;
908
+ return this.interactionsMap.set(n.interactionId, n), this.currentIS = new L(n, this.eventBusService), this.interactionsServiceMap.set(n.interactionId, this.currentIS), n;
906
909
  }
907
910
  getInteractions() {
908
911
  return Array.from(this.interactionsMap.values());
@@ -978,7 +981,7 @@ const kt = 1200 * 1e3, D = class D {
978
981
  version: 0,
979
982
  functionMap: /* @__PURE__ */ new Map(),
980
983
  interactionQuestion: s ?? t
981
- }, n = new b(i, this.eventBusService), this.subAgentInteractions.set(t, i), this.subAgentInteractionServices.set(t, n)), { interaction: i, service: n };
984
+ }, n = new L(i, this.eventBusService), this.subAgentInteractions.set(t, i), this.subAgentInteractionServices.set(t, n)), { interaction: i, service: n };
982
985
  }
983
986
  handleSubAgentEvent(t) {
984
987
  const e = t.subAgentId, { service: s } = this.getOrCreateSubAgentInteraction(e, t.interactionId, t.subAgentName);
@@ -1068,10 +1071,10 @@ const kt = 1200 * 1e3, D = class D {
1068
1071
  }
1069
1072
  localEmitMessage(t, e) {
1070
1073
  const s = (/* @__PURE__ */ new Date()).getTime(), i = s - this.lastCurrentMessageUpdate;
1071
- t.partial === !1 || i >= D.CURRENT_MSG_THROTTLE_MS ? (this.lastThorttledTimeout && (clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = null), this.doEmitMessage(t, s, e), this.pendingCurrentMessage = null) : (this.pendingCurrentMessage = t, this.lastThorttledTimeout && clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = setTimeout(() => {
1074
+ t.partial === !1 || i >= N.CURRENT_MSG_THROTTLE_MS ? (this.lastThorttledTimeout && (clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = null), this.doEmitMessage(t, s, e), this.pendingCurrentMessage = null) : (this.pendingCurrentMessage = t, this.lastThorttledTimeout && clearTimeout(this.lastThorttledTimeout), this.lastThorttledTimeout = setTimeout(() => {
1072
1075
  var r, l;
1073
1076
  this.pendingCurrentMessage && (((r = this.pendingCurrentMessage) == null ? void 0 : r.version) ?? 0) > (((l = this.sessionState.currentMessage) == null ? void 0 : l.version) ?? 0) && (this.doEmitMessage(this.pendingCurrentMessage, s, e), this.lastThorttledTimeout = null);
1074
- }, D.CURRENT_MSG_THROTTLE_MS * 2));
1077
+ }, N.CURRENT_MSG_THROTTLE_MS * 2));
1075
1078
  }
1076
1079
  localOpen(t, e) {
1077
1080
  this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(t ?? "");
@@ -1102,14 +1105,14 @@ const kt = 1200 * 1e3, D = class D {
1102
1105
  return Date.now() - this.lastPing.getTime() > kt ? await this.ping() ? (this.lastPing = /* @__PURE__ */ new Date(), this.lastPingStatus = !0, !0) : (this.lastPingStatus = !1, !1) : (this.lastPingStatus = !0, !0);
1103
1106
  }
1104
1107
  async sendMessage(t, e) {
1105
- let s = this.getInteractions().length, i = A.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
1108
+ let s = this.getInteractions().length, i = P.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
1106
1109
  this.sendStatusMessage(t.data, [i], s.toString() + "1");
1107
1110
  try {
1108
1111
  const { promptAsString: n, json: r } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
1109
1112
  this.sessionState.onRenderPrompt && (t.data = r, t.friendlyMessage = n);
1110
1113
  const l = await this.sendMessageInternal(t, e), o = Pt.createPrompt(n ?? "", (r == null ? void 0 : r.toString()) ?? {});
1111
1114
  this.storageService.storePrompt(o);
1112
- const u = A.fromText("Planejando próximos passos");
1115
+ const u = P.fromText("Planejando próximos passos");
1113
1116
  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;
1114
1117
  } catch (n) {
1115
1118
  return this.eventBusService.ChatEmitMessageError((n == null ? void 0 : n.toString()) ?? ""), {
@@ -1119,7 +1122,7 @@ const kt = 1200 * 1e3, D = class D {
1119
1122
  created: /* @__PURE__ */ new Date(),
1120
1123
  interactionId: "",
1121
1124
  partial: !1,
1122
- parts: [A.fromError((n == null ? void 0 : n.toString()) ?? "")],
1125
+ parts: [P.fromError((n == null ? void 0 : n.toString()) ?? "")],
1123
1126
  version: 0
1124
1127
  }
1125
1128
  };
@@ -1165,9 +1168,9 @@ const kt = 1200 * 1e3, D = class D {
1165
1168
  return `${this.msg_order}_${e}`;
1166
1169
  }
1167
1170
  };
1168
- f(D, "AgentGatewayService"), a(D, "SUSPENSION_MSG", "SUSPEND"), a(D, "CURRENT_MSG_THROTTLE_MS", 20);
1169
- let $ = D;
1170
- const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Ut = 2, Lt = 0.2, ot = 2, j = class j {
1171
+ f(N, "AgentGatewayService"), a(N, "SUSPENSION_MSG", "SUSPEND"), a(N, "CURRENT_MSG_THROTTLE_MS", 20);
1172
+ let W = N;
1173
+ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2, ot = 2, Y = class Y {
1171
1174
  constructor(t = "ws://localhost:8000", e) {
1172
1175
  a(this, "ws", null);
1173
1176
  a(this, "stats");
@@ -1264,11 +1267,11 @@ const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Ut = 2, Lt = 0.2,
1264
1267
  */
1265
1268
  connect(t) {
1266
1269
  return new Promise(async (e, s) => {
1267
- var p;
1270
+ var E;
1268
1271
  this.intentionalDisconnect = !1;
1269
1272
  const i = this._internalReconnect;
1270
1273
  i || (this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.lastSeq = -1), this._internalReconnect = !1;
1271
- const n = (p = this.getToken) == null ? void 0 : p.call(this), r = [];
1274
+ const n = (E = this.getToken) == null ? void 0 : E.call(this), r = [];
1272
1275
  n && r.push(`access_token=${encodeURIComponent(n)}`), t && this.lastSeq >= 0 && r.push(`lastSeq=${this.lastSeq}`);
1273
1276
  const l = r.length > 0 ? `?${r.join("&")}` : "", o = this.baseUrl.replace(/^http:\/\//, "ws://").replace(/^https:\/\//, "wss://"), u = `${o}/ws/connect/${t ?? ""}${l}`, d = `${o}/ws/connect/${t ?? ""}` + (i && t && this.lastSeq >= 0 ? ` (resume lastSeq=${this.lastSeq})` : "");
1274
1277
  if (console.log("Connecting to ", d), this.ws) {
@@ -1288,28 +1291,29 @@ const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Ut = 2, Lt = 0.2,
1288
1291
  }, this.ws.onmessage = (S) => {
1289
1292
  try {
1290
1293
  this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
1291
- const I = this.streamingResponseSerializer.parse(S.data);
1292
- if (!I)
1294
+ const M = this.streamingResponseSerializer.parse(S.data);
1295
+ if (!M)
1293
1296
  throw "Error parsing event JSON";
1294
- const M = this.handleMessage(I, S.data);
1295
- !h && (M != null && M.timestamp) && (h = !0, this.hasEverReceivedPacket = !0);
1296
- } catch (I) {
1297
- console.error("[WebSocket] Error parsing message:", I);
1297
+ const A = this.handleMessage(M, S.data);
1298
+ !h && (A != null && A.timestamp) && (h = !0, this.hasEverReceivedPacket = !0);
1299
+ } catch (M) {
1300
+ console.error("[WebSocket] Error parsing message:", M);
1298
1301
  }
1299
1302
  }, this.ws.onerror = (S) => {
1300
1303
  console.error("[WebSocket] Error:", S), this.onError && this.onError("WebSocket error");
1301
1304
  }, this.ws.onclose = (S) => {
1302
1305
  console.log("[WebSocket] Closed:", S.code, S.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
1303
- const I = this.sessionId ?? this.lastKnownSessionId;
1306
+ const M = this.sessionId ?? this.lastKnownSessionId;
1304
1307
  if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(S.code)) {
1305
- this.scheduleReconnect(I, S.code, S.reason);
1308
+ this.scheduleReconnect(M, S.code, S.reason);
1306
1309
  return;
1307
1310
  }
1308
1311
  this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(S.code, S.reason);
1309
1312
  };
1310
- let v = 0;
1311
- for (this.sessionId = void 0; !this.sessionId && v < 30; )
1312
- console.log("Aguardando session Id"), await this.sleep(400), v++;
1313
+ let C = 0;
1314
+ const p = 4 * 1e3, D = 400;
1315
+ for (this.sessionId = void 0; !this.sessionId && C * D < p; )
1316
+ console.log("Aguardando session Id"), await this.sleep(D), C++;
1313
1317
  this.sessionId ? (console.log("SUCCESS - GOT SESSION ID", this.sessionId), this.lastKnownSessionId = this.sessionId, e(this.sessionId)) : s("After 12 seconds no session id was generated");
1314
1318
  });
1315
1319
  }
@@ -1323,13 +1327,13 @@ const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Ut = 2, Lt = 0.2,
1323
1327
  * - 4000-4099 reserved for app-level fatal codes from the server
1324
1328
  */
1325
1329
  shouldAttemptReconnect(t) {
1326
- return !(this.intentionalDisconnect || t === W || t === _t || t === 1e3 || t === 1008);
1330
+ return !(this.intentionalDisconnect || t === J || t === _t || t === 1e3 || t === 1008);
1327
1331
  }
1328
1332
  cancelPendingReconnect() {
1329
1333
  this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
1330
1334
  }
1331
1335
  computeBackoffDelay() {
1332
- const t = Rt * Math.pow(Ut, this.reconnectAttempts), e = Math.min(t, bt), s = e * Lt * (Math.random() * 2 - 1);
1336
+ const t = Rt * Math.pow(bt, this.reconnectAttempts), e = Math.min(t, Ut), s = e * Lt * (Math.random() * 2 - 1);
1333
1337
  return Math.max(0, Math.round(e + s));
1334
1338
  }
1335
1339
  scheduleReconnect(t, e, s) {
@@ -1388,13 +1392,13 @@ const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Ut = 2, Lt = 0.2,
1388
1392
  this.emitFirstToken(d == null ? void 0 : d.iteractionId);
1389
1393
  const h = new yt();
1390
1394
  if (h.author = "main", h.streamingParts = t.partialEvent.streamingParts, t.partialEvent.partialEventType ? h.eventType = t.partialEvent.partialEventType : h.eventType = d.functionName ? {
1391
- fullName: F.StreamingFunctionCallUpdateContent,
1395
+ fullName: U.StreamingFunctionCallUpdateContent,
1392
1396
  type: y.PartialFunctionCall
1393
1397
  } : d.partialReasoning ? {
1394
- fullName: F.StreamingReasoningContent,
1398
+ fullName: U.StreamingReasoningContent,
1395
1399
  type: y.Thought
1396
1400
  } : {
1397
- fullName: F.StreamingTextContent,
1401
+ fullName: U.StreamingTextContent,
1398
1402
  type: y.Text
1399
1403
  }, h.interactionId = (d == null ? void 0 : d.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == y.PartialFunctionCall) {
1400
1404
  var s = new It();
@@ -1405,7 +1409,7 @@ const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Ut = 2, Lt = 0.2,
1405
1409
  }
1406
1410
  };
1407
1411
  } else if (h.eventType.type == y.Text)
1408
- if (h.eventType.fullName == F.StreamingTextContent) {
1412
+ if (h.eventType.fullName == U.StreamingTextContent) {
1409
1413
  var i = new Ct();
1410
1414
  i.text = d.partialText, h.content = {
1411
1415
  items: [i],
@@ -1484,7 +1488,7 @@ const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Ut = 2, Lt = 0.2,
1484
1488
  }
1485
1489
  suspendStream() {
1486
1490
  this.sendBaseMessage({
1487
- Action: L.Suspend,
1491
+ Action: x.Suspend,
1488
1492
  AgentId: "",
1489
1493
  InteractionId: "",
1490
1494
  ModelId: ""
@@ -1493,7 +1497,7 @@ const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Ut = 2, Lt = 0.2,
1493
1497
  /** Send the user's answer to a parked ask_user tool call (ChatAction.AnswerHumanTool). */
1494
1498
  answerHumanTool(t, e) {
1495
1499
  this.sendBaseMessage({
1496
- Action: L.AnswerHumanTool,
1500
+ Action: x.AnswerHumanTool,
1497
1501
  AgentId: "",
1498
1502
  InteractionId: "",
1499
1503
  ToolCallId: t,
@@ -1540,7 +1544,7 @@ const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Ut = 2, Lt = 0.2,
1540
1544
  * Disconnect the WebSocket
1541
1545
  */
1542
1546
  disconnect() {
1543
- console.warn("Chamou DISCONNECT!!!"), this.intentionalDisconnect = !0, this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [], this.firstTokenInteractions.clear(), this.lastKnownSessionId = void 0, this.lastSeq = -1, this.hasEverReceivedPacket = !1, this.ws && (this.ws.close(W, "Intentional disconnect"), this.ws = null);
1547
+ console.warn("Chamou DISCONNECT!!!"), this.intentionalDisconnect = !0, this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [], this.firstTokenInteractions.clear(), this.lastKnownSessionId = void 0, this.lastSeq = -1, this.hasEverReceivedPacket = !1, this.ws && (this.ws.close(J, "Intentional disconnect"), this.ws = null);
1544
1548
  }
1545
1549
  /**
1546
1550
  * Check if connected
@@ -1582,11 +1586,11 @@ const W = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, bt = 3e4, Ut = 2, Lt = 0.2,
1582
1586
  }
1583
1587
  }
1584
1588
  };
1585
- f(j, "WebSocketConnecionV2");
1586
- let ct = j;
1587
- const xt = "envision_agent_sessionId", Y = class Y extends $ {
1588
- constructor(e, s, i, n, r, l, o, u, d, h, v) {
1589
- super(e, s, i, n, r, l, o, d, v);
1589
+ f(Y, "WebSocketConnecionV2");
1590
+ let ct = Y;
1591
+ const xt = "envision_agent_sessionId", Q = class Q extends W {
1592
+ constructor(e, s, i, n, r, l, o, u, d, h, C) {
1593
+ super(e, s, i, n, r, l, o, d, C);
1590
1594
  a(this, "suspendState", !1);
1591
1595
  a(this, "wsService");
1592
1596
  a(this, "root_url", "");
@@ -1594,7 +1598,7 @@ const xt = "envision_agent_sessionId", Y = class Y extends $ {
1594
1598
  a(this, "connectionAttempts", 0);
1595
1599
  a(this, "statuses", ["CONNECTING", "OPEN", "CLOSED", "UNKNOWN"]);
1596
1600
  a(this, "lastConnectionPromise", null);
1597
- a(this, "socketState", P.Disconnected);
1601
+ a(this, "socketState", _.Disconnected);
1598
1602
  a(this, "streamOpened", !1);
1599
1603
  this.hearBeatPort = h, this.root_url = this.base_url, this.wsService = u, this.wsService.onEvent = async (p) => {
1600
1604
  await super.Message(p);
@@ -1603,23 +1607,23 @@ const xt = "envision_agent_sessionId", Y = class Y extends $ {
1603
1607
  }, this.wsService.onPong = (p) => {
1604
1608
  }, this.wsService.onError = (p) => {
1605
1609
  this.streamOpened = !1;
1606
- const S = {
1610
+ const D = {
1607
1611
  data: this.getErrorEvent(p),
1608
1612
  lastEventId: (/* @__PURE__ */ new Date()).getTime().toString(),
1609
1613
  origin: "gatewayService"
1610
1614
  };
1611
1615
  console.error("Stream error:", p), this.notificationPort.pushNotification({
1612
- message: "Stream error" + p,
1613
- type: "warning"
1614
- }), super.Message(S);
1616
+ message: "Reiniciando a conexão com o servidor",
1617
+ type: "info"
1618
+ }), super.Message(D);
1615
1619
  }, this.wsService.onOpen = () => {
1616
- this.sessionState.setConnectionStatus(P.Connected);
1620
+ this.sessionState.setConnectionStatus(_.Connected);
1617
1621
  }, this.wsService.onReconnected = (p) => {
1618
- this.sessionState.setConnectionStatus(P.Connected);
1622
+ this.sessionState.setConnectionStatus(_.Connected);
1619
1623
  }, this.wsService.onFirstToken = (p) => {
1620
1624
  this.localEmitFirstToken(p);
1621
- }, this.wsService.onClose = (p, S) => {
1622
- p != W && this.sessionState.setConnectionStatus(P.Disconnected);
1625
+ }, this.wsService.onClose = (p, D) => {
1626
+ p != J && this.sessionState.setConnectionStatus(_.Disconnected);
1623
1627
  };
1624
1628
  }
1625
1629
  reset(e, s) {
@@ -1686,7 +1690,7 @@ const xt = "envision_agent_sessionId", Y = class Y extends $ {
1686
1690
  return !0;
1687
1691
  }
1688
1692
  async openConnection(e) {
1689
- return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == P.Disconnected ? (this.lastConnectionPromise = new Promise((s, i) => {
1693
+ return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == _.Disconnected ? (this.lastConnectionPromise = new Promise((s, i) => {
1690
1694
  this.wsService.connect(e).then((n) => {
1691
1695
  this.sessionId = n, s(n);
1692
1696
  }).catch((n) => {
@@ -1718,11 +1722,11 @@ const xt = "envision_agent_sessionId", Y = class Y extends $ {
1718
1722
  }
1719
1723
  // Send a message to the server via HTTP POST
1720
1724
  async sendMessageInternal(e, s, i) {
1721
- var l, o, u, d, h, v, p, S;
1725
+ var l, o, u, d, h, C, p, D;
1722
1726
  const n = this.suspendState;
1723
1727
  this.suspendState = !1;
1724
1728
  const r = this.startInteraction(e.friendlyMessage ?? e.data, n);
1725
- if (this.registerInteractionCallId(r.interactionId, s), (l = e.userUi) != null && l.name && r.parts.push(A.fromUserUi(e.userUi.name, e.userUi.args)), !this.wsService)
1729
+ if (this.registerInteractionCallId(r.interactionId, s), (l = e.userUi) != null && l.name && r.parts.push(P.fromUserUi(e.userUi.name, e.userUi.args)), !this.wsService)
1726
1730
  throw "no wsService created";
1727
1731
  if (!this.sessionId)
1728
1732
  throw "no session id set";
@@ -1731,7 +1735,7 @@ const xt = "envision_agent_sessionId", Y = class Y extends $ {
1731
1735
  return this.wsService.sendMessage({
1732
1736
  Content: e.data,
1733
1737
  SessionId: this.sessionId,
1734
- Action: L.SendMessage,
1738
+ Action: x.SendMessage,
1735
1739
  ModelId: this.config.model,
1736
1740
  InteractionId: r.interactionId,
1737
1741
  AgentId: (u = this.config.agentConfig) == null ? void 0 : u.id,
@@ -1743,24 +1747,24 @@ const xt = "envision_agent_sessionId", Y = class Y extends $ {
1743
1747
  AgentImplementation: (d = this.config.agentConfig) == null ? void 0 : d.agentImplementation,
1744
1748
  Parameters: {
1745
1749
  CustomerName: ((h = this.config.customer) == null ? void 0 : h.name) ?? "",
1746
- DataSet: ((v = this.config.customer) == null ? void 0 : v.dataSetId) ?? ""
1750
+ DataSet: ((C = this.config.customer) == null ? void 0 : C.dataSetId) ?? ""
1747
1751
  },
1748
1752
  // Forward image attachments as a structured payload (PascalCase
1749
1753
  // keys to match the C# `Message.Images` / `MessageImage` model).
1750
- Images: (p = e.images) != null && p.length ? e.images.map((I) => ({ MimeType: I.mimeType, Data: I.data })) : void 0,
1754
+ Images: (p = e.images) != null && p.length ? e.images.map((E) => ({ MimeType: E.mimeType, Data: E.data })) : void 0,
1751
1755
  // Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
1752
1756
  // model). The server persists it as a UserUiContent sibling and strips it from the model
1753
1757
  // request; Content remains the only model-facing text.
1754
- UserUi: (S = e.userUi) != null && S.name ? { Name: e.userUi.name, Args: e.userUi.args } : void 0
1758
+ UserUi: (D = e.userUi) != null && D.name ? { Name: e.userUi.name, Args: e.userUi.args } : void 0
1755
1759
  }), this.localOpen(r.interactionId, "system"), Promise.resolve({
1756
1760
  interaction: r,
1757
1761
  success: !0
1758
1762
  });
1759
1763
  }
1760
1764
  };
1761
- f(Y, "AgentGatewayWSAsync");
1762
- let lt = Y;
1763
- const Q = class Q {
1765
+ f(Q, "AgentGatewayWSAsync");
1766
+ let lt = Q;
1767
+ const X = class X {
1764
1768
  constructor(t, e) {
1765
1769
  a(this, "cache", /* @__PURE__ */ new Map());
1766
1770
  a(this, "serverBaseUrl");
@@ -1815,17 +1819,17 @@ const Q = class Q {
1815
1819
  }
1816
1820
  }
1817
1821
  };
1818
- f(Q, "HttpArtifactService");
1819
- let ht = Q;
1822
+ f(X, "HttpArtifactService");
1823
+ let ht = X;
1820
1824
  export {
1821
- $ as A,
1822
- B as E,
1825
+ W as A,
1826
+ $ as E,
1823
1827
  ht as H,
1824
- b as I,
1828
+ L as I,
1825
1829
  it as L,
1826
1830
  at as M,
1827
1831
  ct as W,
1828
1832
  lt as a,
1829
1833
  jt as u
1830
1834
  };
1831
- //# sourceMappingURL=httpArtifactService-B668XBHO.js.map
1835
+ //# sourceMappingURL=httpArtifactService-RtW5tek8.js.map