@aintela/chat 0.2.32 → 0.2.34

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 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-uea8YsIP.js";
5
+ import { d as L, t as mt, E as I, k as pt, j as St, q as wt, C as $ } 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
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 _ } from "./Prompt-DZb7OaPp.js";
13
- const T = {
12
+ import { P as Pt, C as R } from "./Prompt-DZb7OaPp.js";
13
+ const w = {
14
14
  ARTIFACTS: "envision-artifacts",
15
15
  SECTIONS: "envision-sections",
16
16
  PROMPTS: "envision-prompts"
17
- }, F = [
17
+ }, U = [
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
- ], q = class q {
39
+ ], K = class K {
40
40
  constructor() {
41
41
  a(this, "onPromptCreated", /* @__PURE__ */ f(() => {
42
42
  }, "onPromptCreated"));
@@ -52,21 +52,21 @@ const T = {
52
52
  }
53
53
  initializeStorage() {
54
54
  try {
55
- const t = localStorage.getItem(T.SECTIONS);
55
+ const t = localStorage.getItem(w.SECTIONS);
56
56
  if (!t)
57
- localStorage.setItem(T.SECTIONS, JSON.stringify(F));
57
+ localStorage.setItem(w.SECTIONS, JSON.stringify(U));
58
58
  else {
59
59
  const s = JSON.parse(t);
60
- if (F.some(
60
+ if (U.some(
61
61
  (n) => !s.find((r) => r.id === n.id)
62
62
  )) {
63
63
  const n = [...s];
64
- F.forEach((r) => {
64
+ U.forEach((r) => {
65
65
  s.find((l) => l.id === r.id) || n.push(r);
66
- }), localStorage.setItem(T.SECTIONS, JSON.stringify(n));
66
+ }), localStorage.setItem(w.SECTIONS, JSON.stringify(n));
67
67
  }
68
68
  }
69
- const e = localStorage.getItem(T.ARTIFACTS);
69
+ const e = localStorage.getItem(w.ARTIFACTS);
70
70
  if (e) {
71
71
  const s = JSON.parse(e);
72
72
  let i = !1;
@@ -74,14 +74,14 @@ const T = {
74
74
  if (!r.sectionId) {
75
75
  i = !0;
76
76
  let l = "data-analytics";
77
- return r.type === R.Dashboard ? l = "dashboards" : r.type === R.Chart && (l = "charts"), {
77
+ return r.type === L.Dashboard ? l = "dashboards" : r.type === L.Chart && (l = "charts"), {
78
78
  ...r,
79
79
  sectionId: l
80
80
  };
81
81
  }
82
82
  return r;
83
83
  });
84
- i && localStorage.setItem(T.ARTIFACTS, JSON.stringify(n));
84
+ i && localStorage.setItem(w.ARTIFACTS, JSON.stringify(n));
85
85
  }
86
86
  } catch (t) {
87
87
  console.error("Error initializing storage:", t);
@@ -89,15 +89,15 @@ const T = {
89
89
  }
90
90
  getSections() {
91
91
  try {
92
- const t = localStorage.getItem(T.SECTIONS);
93
- return t ? JSON.parse(t) : F;
92
+ const t = localStorage.getItem(w.SECTIONS);
93
+ return t ? JSON.parse(t) : U;
94
94
  } catch (t) {
95
- return console.error("Error loading sections:", t), F;
95
+ return console.error("Error loading sections:", t), U;
96
96
  }
97
97
  }
98
98
  getArtifacts() {
99
99
  try {
100
- const t = localStorage.getItem(T.ARTIFACTS);
100
+ const t = localStorage.getItem(w.ARTIFACTS);
101
101
  return t ? JSON.parse(t) : [];
102
102
  } catch (t) {
103
103
  return console.error("Error loading artifacts:", t), [];
@@ -111,19 +111,19 @@ const T = {
111
111
  created: (/* @__PURE__ */ new Date()).toISOString(),
112
112
  iconType: e
113
113
  }, i = this.getSections();
114
- return i.push(s), localStorage.setItem(T.SECTIONS, JSON.stringify(i)), s;
114
+ return i.push(s), localStorage.setItem(w.SECTIONS, JSON.stringify(i)), s;
115
115
  }
116
116
  updateSection(t, e) {
117
117
  const s = this.getSections(), i = s.findIndex((n) => n.id === t);
118
- i >= 0 && (s[i] = { ...s[i], ...e }, localStorage.setItem(T.SECTIONS, JSON.stringify(s)));
118
+ i >= 0 && (s[i] = { ...s[i], ...e }, localStorage.setItem(w.SECTIONS, JSON.stringify(s)));
119
119
  }
120
120
  deleteSection(t) {
121
121
  const e = this.getSections(), s = e.find((i) => i.id === t);
122
122
  if (s && !s.isDefault) {
123
123
  const i = this.getArtifacts(), n = s.iconType === "dashboard" ? "dashboards" : s.iconType === "chart" ? "charts" : "data-analytics", r = i.map((o) => o.sectionId === t ? { ...o, sectionId: n } : o);
124
- localStorage.setItem(T.ARTIFACTS, JSON.stringify(r));
124
+ localStorage.setItem(w.ARTIFACTS, JSON.stringify(r));
125
125
  const l = e.filter((o) => o.id !== t);
126
- localStorage.setItem(T.SECTIONS, JSON.stringify(l));
126
+ localStorage.setItem(w.SECTIONS, JSON.stringify(l));
127
127
  }
128
128
  }
129
129
  storeArtifact(t) {
@@ -133,7 +133,7 @@ const T = {
133
133
  e[s] = t;
134
134
  else {
135
135
  let i = "data-analytics";
136
- t.type === R.Dashboard ? i = "dashboards" : t.type === R.Chart && (i = "charts");
136
+ t.type === L.Dashboard ? i = "dashboards" : t.type === L.Chart && (i = "charts");
137
137
  const n = {
138
138
  ...t,
139
139
  created: t.created || (/* @__PURE__ */ new Date()).toISOString(),
@@ -141,22 +141,22 @@ const T = {
141
141
  };
142
142
  e.push(n);
143
143
  }
144
- localStorage.setItem(T.ARTIFACTS, JSON.stringify(e));
144
+ localStorage.setItem(w.ARTIFACTS, JSON.stringify(e));
145
145
  } catch (e) {
146
146
  console.error("Error storing artifact:", e);
147
147
  }
148
148
  }
149
149
  moveArtifact(t, e) {
150
150
  const s = this.getArtifacts(), i = s.findIndex((n) => n.id === t);
151
- i >= 0 && (s[i] = { ...s[i], sectionId: e }, localStorage.setItem(T.ARTIFACTS, JSON.stringify(s)));
151
+ i >= 0 && (s[i] = { ...s[i], sectionId: e }, localStorage.setItem(w.ARTIFACTS, JSON.stringify(s)));
152
152
  }
153
153
  deleteArtifact(t) {
154
154
  const s = this.getArtifacts().filter((i) => i.id !== t);
155
- localStorage.setItem(T.ARTIFACTS, JSON.stringify(s));
155
+ localStorage.setItem(w.ARTIFACTS, JSON.stringify(s));
156
156
  }
157
157
  updateArtifact(t, e) {
158
158
  const s = this.getArtifacts(), i = s.findIndex((n) => n.id === t);
159
- i >= 0 && (s[i] = { ...s[i], ...e }, localStorage.setItem(T.ARTIFACTS, JSON.stringify(s)));
159
+ i >= 0 && (s[i] = { ...s[i], ...e }, localStorage.setItem(w.ARTIFACTS, JSON.stringify(s)));
160
160
  }
161
161
  getArtifactsBySection(t) {
162
162
  return this.getArtifacts().filter((s) => s.sectionId === t);
@@ -164,7 +164,7 @@ const T = {
164
164
  // Prompt management methods
165
165
  getPrompts() {
166
166
  try {
167
- const t = localStorage.getItem(T.PROMPTS);
167
+ const t = localStorage.getItem(w.PROMPTS);
168
168
  return t ? JSON.parse(t).sort((s, i) => new Date(i.created).getTime() - new Date(s.created).getTime()) : [];
169
169
  } catch (t) {
170
170
  return console.error("Error loading prompts:", t), [];
@@ -175,7 +175,7 @@ const T = {
175
175
  const e = this.getPrompts();
176
176
  e.length > 0 && e[0].promptText === t.promptText && (e[0].created = t.created, e[0].id = t.id), e.unshift(t);
177
177
  const s = e.slice(0, 50);
178
- localStorage.setItem(T.PROMPTS, JSON.stringify(s));
178
+ localStorage.setItem(w.PROMPTS, JSON.stringify(s));
179
179
  } catch (e) {
180
180
  console.error("Error storing prompt:", e);
181
181
  }
@@ -183,29 +183,29 @@ const T = {
183
183
  deletePrompt(t) {
184
184
  try {
185
185
  const s = this.getPrompts().filter((i) => i.id !== t);
186
- localStorage.setItem(T.PROMPTS, JSON.stringify(s));
186
+ localStorage.setItem(w.PROMPTS, JSON.stringify(s));
187
187
  } catch (e) {
188
188
  console.error("Error deleting prompt:", e);
189
189
  }
190
190
  }
191
191
  clearAllPrompts() {
192
192
  try {
193
- localStorage.removeItem(T.PROMPTS);
193
+ localStorage.removeItem(w.PROMPTS);
194
194
  } catch (t) {
195
195
  console.error("Error clearing prompts:", t);
196
196
  }
197
197
  }
198
198
  };
199
- f(q, "LocalStorageService");
200
- let it = q;
201
- const jt = /* @__PURE__ */ f((O) => {
199
+ f(K, "LocalStorageService");
200
+ let it = K;
201
+ const Yt = /* @__PURE__ */ f((O) => {
202
202
  const t = O.getPrompts(), e = t.length;
203
203
  if (e > 0) {
204
204
  const s = t[0].promptText, i = t[t.length - 1].promptText, n = t[0].created;
205
205
  return { promptState: e + "_" + s + "_" + i + "_" + n };
206
206
  } else
207
207
  return { promptState: "0" };
208
- }, "usePromptState"), G = class G {
208
+ }, "usePromptState"), z = class z {
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(G, "EventTypes");
234
- let B = G;
235
- const c = new B(), H = class H {
233
+ f(z, "EventTypes");
234
+ let J = z;
235
+ const c = new J(), Y = class Y {
236
236
  constructor() {
237
237
  a(this, "listeners", {});
238
238
  a(this, "listenersCount", {});
@@ -483,9 +483,9 @@ const c = new B(), H = class H {
483
483
  this.listeners[e] && (this.listeners[e] = this.listeners[e].filter((s) => s !== t));
484
484
  }
485
485
  };
486
- f(H, "EventBusService");
487
- let $ = H;
488
- const K = class K extends $ {
486
+ f(Y, "EventBusService");
487
+ let q = Y;
488
+ const j = class j extends q {
489
489
  constructor() {
490
490
  super();
491
491
  }
@@ -511,12 +511,12 @@ const K = class K extends $ {
511
511
  console.log("MockEventBusService.gatewayOffFunctionResponse", t);
512
512
  }
513
513
  };
514
- f(K, "MockEventBusService");
515
- let at = K;
514
+ f(j, "MockEventBusService");
515
+ let at = j;
516
516
  const dt = {
517
517
  inline: "inline",
518
518
  block: "block"
519
- }, z = class z {
519
+ }, Q = class Q {
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(z, "InteractionPartGroup");
529
- let b = z;
530
- const j = class j {
528
+ f(Q, "InteractionPartGroup");
529
+ let B = Q;
530
+ const X = class X {
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 = P.fromText(r);
552
+ const l = _.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 b();
560
+ let n = new B();
561
561
  for (let o = 0; o < t.length; o++) {
562
562
  const u = t[o];
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 b()), i.push({
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 B()), i.push({
565
565
  type: dt.block,
566
566
  parts: [u],
567
567
  isLastGroup: o === t.length - 1,
@@ -574,10 +574,10 @@ ${n.value}
574
574
  return r.length > 0 && (r[r.length - 1].lastWithThoughts = !0), i;
575
575
  }
576
576
  isFunctionCall(t) {
577
- return t == y.FunctionCall || t == y.PartialFunctionCall;
577
+ return t == I.FunctionCall || t == I.PartialFunctionCall;
578
578
  }
579
579
  isFunctionResponse(t) {
580
- return t == y.FunctionResponse;
580
+ return t == I.FunctionResponse;
581
581
  }
582
582
  // Computes the next interaction from a server event. Pure with respect to
583
583
  // `prev` — no part or array on the prior tree is mutated; modified entities
@@ -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 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;
588
+ var b, T, A, N, et;
589
+ const e = this.interaction, s = [], i = [], n = _.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) || ((A = n == null ? void 0 : n.functionDetails) == null ? void 0 : A.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) || ((b = n == null ? void 0 : n.functionDetails) == null ? void 0 : b.id) !== ((T = r.functionDetails) == null ? void 0 : T.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"), C = /* @__PURE__ */ f(() => {
595
+ }, "cloneFunctionMap"), v = /* @__PURE__ */ f(() => {
596
596
  o === e.parts && (o = e.parts.slice());
597
597
  }, "clonePartsIfShared");
598
598
  let p = !1;
599
- if ((n == null ? void 0 : n.eventType) === y.FunctionClientOutput && !!((V = n.functionDetails) != null && V.id) && n) {
600
- const g = n.functionDetails.id, I = n.functionDetails.clientOutput, v = o.findIndex((w) => {
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) => {
601
601
  var m;
602
- return ((m = w.functionDetails) == null ? void 0 : m.id) === g;
602
+ return ((m = S.functionDetails) == null ? void 0 : m.id) === g;
603
603
  });
604
- if (v > -1) {
605
- const w = o[v], m = {
606
- ...w,
604
+ if (E > -1) {
605
+ const S = o[E], m = {
606
+ ...S,
607
607
  functionDetails: {
608
- ...w.functionDetails,
609
- clientOutput: I ?? w.functionDetails.clientOutput
608
+ ...S.functionDetails,
609
+ clientOutput: C ?? S.functionDetails.clientOutput
610
610
  }
611
611
  };
612
- C(), o[v] = m, h(), u.set(g, m), s.push(m);
612
+ v(), o[E] = m, h(), u.set(g, m), s.push(m);
613
613
  } else {
614
- const w = {
614
+ const S = {
615
615
  ...n,
616
616
  id: o.length + 1 + "-" + e.interactionId,
617
617
  functionDetails: { ...n.functionDetails, silent: !0 }
618
618
  };
619
- C(), o = o === e.parts ? e.parts.slice() : o, o.push(w), h(), u.set(g, w);
619
+ v(), o = o === e.parts ? e.parts.slice() : o, o.push(S), h(), u.set(g, S);
620
620
  }
621
621
  } else if (l && n) {
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
- const w = o.findIndex((ft) => {
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
627
  var st;
628
- return ((st = ft.functionDetails) == null ? void 0 : st.id) === I;
629
- }), m = w > -1 ? o[w] : v, k = {
628
+ return ((st = ft.functionDetails) == null ? void 0 : st.id) === C;
629
+ }), m = S > -1 ? o[S] : E, F = {
630
630
  ...m,
631
631
  eventType: n.eventType,
632
632
  functionDetails: {
@@ -666,40 +666,40 @@ ${n.value}
666
666
  cancelUi: n.functionDetails.cancelUi === !0 || m.functionDetails.cancelUi === !0
667
667
  }
668
668
  };
669
- h(), u.set(I, k), k.eventType === y.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(k.functionDetails), s.push(k), w > -1 && (C(), o[w] = k);
669
+ h(), u.set(C, F), F.eventType === I.FunctionResponse && this.eventBusService.gatewayEmitFunctionResponse(F.functionDetails), s.push(F), S > -1 && (v(), o[S] = F);
670
670
  } else {
671
- if (I && n.functionDetails && !v && (h(), u.set(I, n)), r && r.textAppendable) {
671
+ if (C && n.functionDetails && !E && (h(), u.set(C, n)), r && r.textAppendable) {
672
672
  const m = {
673
673
  ...r,
674
674
  ended: /* @__PURE__ */ new Date(),
675
675
  isStillWriting: !1
676
676
  };
677
- C(), o[o.length - 1] = m, s.push(m);
677
+ v(), o[o.length - 1] = m, s.push(m);
678
678
  }
679
- const w = {
679
+ const S = {
680
680
  ...n,
681
681
  id: o.length + 1 + "-" + e.interactionId,
682
682
  isStillWriting: n.textAppendable,
683
683
  partial: t.partial
684
684
  };
685
- (et = w.functionDetails) != null && et.silent || s.push(w), o = [...o, w], p = !0;
685
+ (et = S.functionDetails) != null && et.silent || s.push(S), o = [...o, S], p = !0;
686
686
  }
687
687
  }
688
- let E = o[o.length - 1] ?? null;
689
- if (E && n && n.textAppendable) {
688
+ let y = o[o.length - 1] ?? null;
689
+ if (y && n && n.textAppendable) {
690
690
  const g = {
691
- ...E,
691
+ ...y,
692
692
  partial: t.partial,
693
- textDetails: E.textDetails ? { ...E.textDetails } : { version: 0 }
693
+ textDetails: y.textDetails ? { ...y.textDetails } : { version: 0 }
694
694
  };
695
- let I = !1;
695
+ let C = !1;
696
696
  if (t.partial) {
697
697
  try {
698
- g.textDetails.version++, p || (g.text = (E.text ?? "") + (n.text ?? ""));
699
- } catch (v) {
700
- console.error("Error here", v.toString());
698
+ g.textDetails.version++, p || (g.text = (y.text ?? "") + (n.text ?? ""));
699
+ } catch (E) {
700
+ console.error("Error here", E.toString());
701
701
  }
702
- g.textLastChunk = n.text ?? "", g.isStillWriting = !0, I = !0, n.thoughtDetails && g.thoughtDetails && n.thoughtDetails.text !== g.thoughtDetails.text && (g.thoughtDetails = {
702
+ g.textLastChunk = n.text ?? "", g.isStillWriting = !0, C = !0, n.thoughtDetails && g.thoughtDetails && n.thoughtDetails.text !== g.thoughtDetails.text && (g.thoughtDetails = {
703
703
  ...g.thoughtDetails,
704
704
  text: g.thoughtDetails.text + n.thoughtDetails.text
705
705
  }, g.thoughtLastChunk = n.thoughtDetails.text);
@@ -707,43 +707,43 @@ ${n.value}
707
707
  g.isStillWriting = !1, g.text = n.text ?? "", g.textDetails.version++, n.thoughtDetails && (g.thoughtDetails = {
708
708
  ...n.thoughtDetails,
709
709
  text: n.thoughtDetails.text.trim()
710
- }), I = !l;
711
- C(), o[o.length - 1] = g, E = g, I && s.push(g);
710
+ }), C = !l;
711
+ v(), o[o.length - 1] = g, y = g, C && s.push(g);
712
712
  }
713
- let S = e.artifactData ?? [];
713
+ let M = e.artifactData ?? [];
714
714
  if (t.llmArtifacts && t.llmArtifacts.length > 0) {
715
715
  let g = !1;
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;
716
+ for (const C of t.llmArtifacts) {
717
+ const E = C.toArtifact();
718
+ g || (M = M.slice(), g = !0);
719
+ const S = M.findIndex((m) => m.id === E.id);
720
+ S === -1 ? M.push(E) : M[S] = E;
721
721
  }
722
722
  }
723
- const M = {
723
+ const k = {
724
724
  ...e,
725
725
  version: e.version + 1,
726
726
  parts: o,
727
- artifactData: S,
727
+ artifactData: M,
728
728
  functionMap: u,
729
729
  turn_complete: t.turn_complete,
730
730
  partial: t.partial,
731
731
  asyncFinalResponse: t.asyncFinalResponse
732
732
  };
733
- return this.interaction = M, {
734
- updatedInteraction: M,
733
+ return this.interaction = k, {
734
+ updatedInteraction: k,
735
735
  updatedParts: s,
736
736
  newArtifacts: i,
737
- mainBranch: M,
737
+ mainBranch: k,
738
738
  analyticsBranch: null,
739
739
  analyticsBranchPartsChanged: null,
740
740
  mainBranchPartsChanged: s
741
741
  };
742
742
  }
743
743
  };
744
- f(j, "InteractionService");
745
- let L = j;
746
- const kt = 1200 * 1e3, N = class N {
744
+ f(X, "InteractionService");
745
+ let W = X;
746
+ const kt = 1200 * 1e3, P = class P {
747
747
  constructor(t, e, s, i, n, r, l, o, u, d = St.Interactive) {
748
748
  a(this, "base_production_url", pt() ?? "https://agent.tripapi.com.br");
749
749
  a(this, "base_url_local", "http://localagent:8000");
@@ -820,7 +820,7 @@ const kt = 1200 * 1e3, N = class N {
820
820
  a(this, "subAgentInteractionServices", /* @__PURE__ */ new Map());
821
821
  a(this, "lastThorttledTimeout", null);
822
822
  a(this, "lastPingStatus", !1);
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) => {
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, v) => {
824
824
  this.sessionState = h;
825
825
  });
826
826
  }
@@ -905,7 +905,7 @@ const kt = 1200 * 1e3, N = class N {
905
905
  functionMap: /* @__PURE__ */ new Map(),
906
906
  interactionQuestion: t
907
907
  };
908
- return this.interactionsMap.set(n.interactionId, n), this.currentIS = new L(n, this.eventBusService), this.interactionsServiceMap.set(n.interactionId, this.currentIS), n;
908
+ return this.interactionsMap.set(n.interactionId, n), this.currentIS = new W(n, this.eventBusService), this.interactionsServiceMap.set(n.interactionId, this.currentIS), n;
909
909
  }
910
910
  getInteractions() {
911
911
  return Array.from(this.interactionsMap.values());
@@ -981,7 +981,7 @@ const kt = 1200 * 1e3, N = class N {
981
981
  version: 0,
982
982
  functionMap: /* @__PURE__ */ new Map(),
983
983
  interactionQuestion: s ?? t
984
- }, n = new L(i, this.eventBusService), this.subAgentInteractions.set(t, i), this.subAgentInteractionServices.set(t, n)), { interaction: i, service: n };
984
+ }, n = new W(i, this.eventBusService), this.subAgentInteractions.set(t, i), this.subAgentInteractionServices.set(t, n)), { interaction: i, service: n };
985
985
  }
986
986
  handleSubAgentEvent(t) {
987
987
  const e = t.subAgentId, { service: s } = this.getOrCreateSubAgentInteraction(e, t.interactionId, t.subAgentName);
@@ -1071,10 +1071,10 @@ const kt = 1200 * 1e3, N = class N {
1071
1071
  }
1072
1072
  localEmitMessage(t, e) {
1073
1073
  const s = (/* @__PURE__ */ new Date()).getTime(), i = s - this.lastCurrentMessageUpdate;
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(() => {
1074
+ t.partial === !1 || i >= P.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(() => {
1075
1075
  var r, l;
1076
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);
1077
- }, N.CURRENT_MSG_THROTTLE_MS * 2));
1077
+ }, P.CURRENT_MSG_THROTTLE_MS * 2));
1078
1078
  }
1079
1079
  localOpen(t, e) {
1080
1080
  this.sessionState.setTurnOpen(!0), this.eventBusService.gatewayEmitTurnOpen(t ?? "");
@@ -1105,14 +1105,14 @@ const kt = 1200 * 1e3, N = class N {
1105
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);
1106
1106
  }
1107
1107
  async sendMessage(t, e) {
1108
- let s = this.getInteractions().length, i = P.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
1108
+ let s = this.getInteractions().length, i = _.createWaiting(!0, !0, "Overall", /* @__PURE__ */ new Date());
1109
1109
  this.sendStatusMessage(t.data, [i], s.toString() + "1");
1110
1110
  try {
1111
1111
  const { promptAsString: n, json: r } = this.sessionState.onRenderPrompt ? this.sessionState.onRenderPrompt(t.data) : { promptAsString: t.data, json: void 0 };
1112
1112
  this.sessionState.onRenderPrompt && (t.data = r, t.friendlyMessage = n);
1113
1113
  const l = await this.sendMessageInternal(t, e), o = Pt.createPrompt(n ?? "", (r == null ? void 0 : r.toString()) ?? {});
1114
1114
  this.storageService.storePrompt(o);
1115
- const u = P.fromText("Planejando próximos passos");
1115
+ const u = _.fromText("Planejando próximos passos");
1116
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;
1117
1117
  } catch (n) {
1118
1118
  return this.eventBusService.ChatEmitMessageError((n == null ? void 0 : n.toString()) ?? ""), {
@@ -1122,7 +1122,7 @@ const kt = 1200 * 1e3, N = class N {
1122
1122
  created: /* @__PURE__ */ new Date(),
1123
1123
  interactionId: "",
1124
1124
  partial: !1,
1125
- parts: [P.fromError((n == null ? void 0 : n.toString()) ?? "")],
1125
+ parts: [_.fromError((n == null ? void 0 : n.toString()) ?? "")],
1126
1126
  version: 0
1127
1127
  }
1128
1128
  };
@@ -1168,9 +1168,9 @@ const kt = 1200 * 1e3, N = class N {
1168
1168
  return `${this.msg_order}_${e}`;
1169
1169
  }
1170
1170
  };
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
+ f(P, "AgentGatewayService"), a(P, "SUSPENSION_MSG", "SUSPEND"), a(P, "CURRENT_MSG_THROTTLE_MS", 20);
1172
+ let G = P;
1173
+ const H = 4001, _t = 4002, rt = 4, bt = 3, Ft = 500, Rt = 3e4, Ut = 2, Lt = 0.2, ot = 2, Z = class Z {
1174
1174
  constructor(t = "ws://localhost:8000", e) {
1175
1175
  a(this, "ws", null);
1176
1176
  a(this, "stats");
@@ -1251,7 +1251,7 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1251
1251
  * Cleared by `disconnect()`.
1252
1252
  */
1253
1253
  a(this, "hasEverReceivedPacket", !1);
1254
- this.baseUrl = t, this.getToken = e, this.pingPongStack = [], this.events = [], this.firstTokenInteractions = /* @__PURE__ */ new Set(), this.streamingResponseSerializer = Tt(), console.log("SOCKET INSTACE", wt()), this.stats = {
1254
+ 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 = {
1255
1255
  eventCount: 0,
1256
1256
  unknonwCount: 0,
1257
1257
  buffer: [],
@@ -1267,11 +1267,11 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1267
1267
  */
1268
1268
  connect(t) {
1269
1269
  return new Promise(async (e, s) => {
1270
- var E;
1270
+ var b;
1271
1271
  this.intentionalDisconnect = !1;
1272
1272
  const i = this._internalReconnect;
1273
1273
  i || (this.cancelPendingReconnect(), this.isReconnecting = !1, this.reconnectAttempts = 0, this.lastSeq = -1), this._internalReconnect = !1;
1274
- const n = (E = this.getToken) == null ? void 0 : E.call(this), r = [];
1274
+ const n = (b = this.getToken) == null ? void 0 : b.call(this), r = [];
1275
1275
  n && r.push(`access_token=${encodeURIComponent(n)}`), t && this.lastSeq >= 0 && r.push(`lastSeq=${this.lastSeq}`);
1276
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})` : "");
1277
1277
  if (console.log("Connecting to ", d), this.ws) {
@@ -1286,35 +1286,57 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1286
1286
  let h = !1;
1287
1287
  this.ws.onopen = () => {
1288
1288
  console.log("[WebSocket] Connected");
1289
- const S = this.isReconnecting;
1290
- this.isReconnecting = !1, this.reconnectAttempts = 0, this.pingPongStack.push((/* @__PURE__ */ new Date()).getTime()), this.ping(), this.monitor(), this.onOpen && this.onOpen(), S && this.onReconnected && this.onReconnected(t ?? this.lastKnownSessionId ?? "");
1291
- }, this.ws.onmessage = (S) => {
1289
+ const T = this.isReconnecting;
1290
+ 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 ?? "");
1291
+ }, this.ws.onmessage = (T) => {
1292
1292
  try {
1293
1293
  this.lastActivity = (/* @__PURE__ */ new Date()).getTime();
1294
- const M = this.streamingResponseSerializer.parse(S.data);
1295
- if (!M)
1294
+ const A = this.streamingResponseSerializer.parse(T.data);
1295
+ if (!A)
1296
1296
  throw "Error parsing event JSON";
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);
1297
+ const N = this.handleMessage(A, T.data);
1298
+ !h && (N != null && N.timestamp) && (h = !0, this.hasEverReceivedPacket = !0);
1299
+ } catch (A) {
1300
+ console.error("[WebSocket] Error parsing message:", A);
1301
1301
  }
1302
- }, this.ws.onerror = (S) => {
1303
- console.error("[WebSocket] Error:", S), this.onError && this.onError("WebSocket error");
1304
- }, this.ws.onclose = (S) => {
1305
- console.log("[WebSocket] Closed:", S.code, S.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
1306
- const M = this.sessionId ?? this.lastKnownSessionId;
1307
- if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(S.code)) {
1308
- this.scheduleReconnect(M, S.code, S.reason);
1302
+ }, this.ws.onerror = (T) => {
1303
+ console.error("[WebSocket] Error:", T), this.onError && this.onError("WebSocket error");
1304
+ }, this.ws.onclose = (T) => {
1305
+ console.log("[WebSocket] Closed:", T.code, T.reason), this.monitorInterval && (clearInterval(this.monitorInterval), this.monitorInterval = null), this.pingPongStack = [];
1306
+ const A = this.sessionId ?? this.lastKnownSessionId;
1307
+ if (this.sessionId = void 0, (h || this.hasEverReceivedPacket) && this.shouldAttemptReconnect(T.code)) {
1308
+ this.scheduleReconnect(A, T.code, T.reason);
1309
1309
  return;
1310
1310
  }
1311
- this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(S.code, S.reason);
1311
+ this.isReconnecting = !1, this.reconnectAttempts = 0, this.onClose && this.onClose(T.code, T.reason);
1312
1312
  };
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++;
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");
1313
+ const v = 200, p = 3e4, D = 8e3, y = this.ws;
1314
+ this.sessionId = void 0;
1315
+ let M = 0, k = 0;
1316
+ for (; !this.sessionId; ) {
1317
+ if (this.ws !== y) {
1318
+ s("Connection attempt superseded by a newer connect()");
1319
+ return;
1320
+ }
1321
+ if (y.readyState === WebSocket.CLOSING || y.readyState === WebSocket.CLOSED) {
1322
+ s("Connection closed before a session id was received");
1323
+ return;
1324
+ }
1325
+ if (y.readyState === WebSocket.CONNECTING && M >= p) {
1326
+ try {
1327
+ y.close();
1328
+ } catch {
1329
+ }
1330
+ s(`Server did not accept the connection within ${p / 1e3}s`);
1331
+ return;
1332
+ }
1333
+ if (y.readyState === WebSocket.OPEN && k >= D) {
1334
+ s(`Connected but no session id arrived within ${D / 1e3}s`);
1335
+ return;
1336
+ }
1337
+ M % 2e3 === 0 && console.log("Aguardando session Id"), await this.sleep(v), M += v, y.readyState === WebSocket.OPEN && (k += v);
1338
+ }
1339
+ console.log("SUCCESS - GOT SESSION ID", this.sessionId), this.lastKnownSessionId = this.sessionId, e(this.sessionId);
1318
1340
  });
1319
1341
  }
1320
1342
  /**
@@ -1327,13 +1349,13 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1327
1349
  * - 4000-4099 reserved for app-level fatal codes from the server
1328
1350
  */
1329
1351
  shouldAttemptReconnect(t) {
1330
- return !(this.intentionalDisconnect || t === J || t === _t || t === 1e3 || t === 1008);
1352
+ return !(this.intentionalDisconnect || t === H || t === _t || t === 1e3 || t === 1008);
1331
1353
  }
1332
1354
  cancelPendingReconnect() {
1333
1355
  this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
1334
1356
  }
1335
1357
  computeBackoffDelay() {
1336
- const t = Rt * Math.pow(bt, this.reconnectAttempts), e = Math.min(t, Ut), s = e * Lt * (Math.random() * 2 - 1);
1358
+ const t = Ft * Math.pow(Ut, this.reconnectAttempts), e = Math.min(t, Rt), s = e * Lt * (Math.random() * 2 - 1);
1337
1359
  return Math.max(0, Math.round(e + s));
1338
1360
  }
1339
1361
  scheduleReconnect(t, e, s) {
@@ -1390,17 +1412,17 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1390
1412
  if (t.partialEvent) {
1391
1413
  const d = t.partialEvent;
1392
1414
  this.emitFirstToken(d == null ? void 0 : d.iteractionId);
1393
- const h = new yt();
1415
+ const h = new Tt();
1394
1416
  if (h.author = "main", h.streamingParts = t.partialEvent.streamingParts, t.partialEvent.partialEventType ? h.eventType = t.partialEvent.partialEventType : h.eventType = d.functionName ? {
1395
- fullName: U.StreamingFunctionCallUpdateContent,
1396
- type: y.PartialFunctionCall
1417
+ fullName: x.StreamingFunctionCallUpdateContent,
1418
+ type: I.PartialFunctionCall
1397
1419
  } : d.partialReasoning ? {
1398
- fullName: U.StreamingReasoningContent,
1399
- type: y.Thought
1420
+ fullName: x.StreamingReasoningContent,
1421
+ type: I.Thought
1400
1422
  } : {
1401
- fullName: U.StreamingTextContent,
1402
- type: y.Text
1403
- }, h.interactionId = (d == null ? void 0 : d.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == y.PartialFunctionCall) {
1423
+ fullName: x.StreamingTextContent,
1424
+ type: I.Text
1425
+ }, h.interactionId = (d == null ? void 0 : d.iteractionId) ?? "", h.mimeType = "text/plain", h.partial = !0, h.eventType.type == I.PartialFunctionCall) {
1404
1426
  var s = new It();
1405
1427
  s.choiceIndex = 0, s.callId = d.functionCallId, s.arguments = d.partialText, s.name = d.functionName, h.content = {
1406
1428
  items: [s],
@@ -1408,8 +1430,8 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1408
1430
  label: "Assistant"
1409
1431
  }
1410
1432
  };
1411
- } else if (h.eventType.type == y.Text)
1412
- if (h.eventType.fullName == U.StreamingTextContent) {
1433
+ } else if (h.eventType.type == I.Text)
1434
+ if (h.eventType.fullName == x.StreamingTextContent) {
1413
1435
  var i = new Ct();
1414
1436
  i.text = d.partialText, h.content = {
1415
1437
  items: [i],
@@ -1426,7 +1448,7 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1426
1448
  }
1427
1449
  };
1428
1450
  }
1429
- else if (h.eventType.type == y.Thought) {
1451
+ else if (h.eventType.type == I.Thought) {
1430
1452
  var r = new Et();
1431
1453
  r.text = d.partialReasoning, h.content = {
1432
1454
  items: [r],
@@ -1488,7 +1510,7 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1488
1510
  }
1489
1511
  suspendStream() {
1490
1512
  this.sendBaseMessage({
1491
- Action: x.Suspend,
1513
+ Action: $.Suspend,
1492
1514
  AgentId: "",
1493
1515
  InteractionId: "",
1494
1516
  ModelId: ""
@@ -1497,7 +1519,7 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1497
1519
  /** Send the user's answer to a parked ask_user tool call (ChatAction.AnswerHumanTool). */
1498
1520
  answerHumanTool(t, e) {
1499
1521
  this.sendBaseMessage({
1500
- Action: x.AnswerHumanTool,
1522
+ Action: $.AnswerHumanTool,
1501
1523
  AgentId: "",
1502
1524
  InteractionId: "",
1503
1525
  ToolCallId: t,
@@ -1544,7 +1566,7 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1544
1566
  * Disconnect the WebSocket
1545
1567
  */
1546
1568
  disconnect() {
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);
1569
+ 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(H, "Intentional disconnect"), this.ws = null);
1548
1570
  }
1549
1571
  /**
1550
1572
  * Check if connected
@@ -1577,7 +1599,7 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1577
1599
  if (!i)
1578
1600
  throw "Server event was null";
1579
1601
  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;
1580
- const n = Date.now() - rt * 1e3, l = this.events.filter((o) => o[0] > n).reduce((o, u) => o += u[1], 0) / Ft;
1602
+ const n = Date.now() - rt * 1e3, l = this.events.filter((o) => o[0] > n).reduce((o, u) => o += u[1], 0) / bt;
1581
1603
  this.stats.tokensPerSecond = l / rt, this.flushStatsCoalesced(), this.onEvent && this.onEvent(i).catch((o) => {
1582
1604
  console.error("Lost error on on-event", o);
1583
1605
  });
@@ -1586,19 +1608,26 @@ const J = 4001, _t = 4002, rt = 4, Ft = 3, Rt = 500, Ut = 3e4, bt = 2, Lt = 0.2,
1586
1608
  }
1587
1609
  }
1588
1610
  };
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);
1611
+ f(Z, "WebSocketConnecionV2");
1612
+ let ct = Z;
1613
+ const xt = "envision_agent_sessionId", V = class V extends G {
1614
+ constructor(e, s, i, n, r, l, o, u, d, h, v) {
1615
+ super(e, s, i, n, r, l, o, d, v);
1594
1616
  a(this, "suspendState", !1);
1595
1617
  a(this, "wsService");
1596
1618
  a(this, "root_url", "");
1597
1619
  a(this, "hearBeatPort");
1598
1620
  a(this, "connectionAttempts", 0);
1621
+ /**
1622
+ * True once a WS has successfully opened at least once in this gateway's
1623
+ * lifetime. Gates the "Reiniciando a conexão" toast: a drop of a working
1624
+ * connection is worth telling the user about, a failed initial dial is not
1625
+ * (the Connecting state already covers it).
1626
+ */
1627
+ a(this, "everConnected", !1);
1599
1628
  a(this, "statuses", ["CONNECTING", "OPEN", "CLOSED", "UNKNOWN"]);
1600
1629
  a(this, "lastConnectionPromise", null);
1601
- a(this, "socketState", _.Disconnected);
1630
+ a(this, "socketState", R.Disconnected);
1602
1631
  a(this, "streamOpened", !1);
1603
1632
  this.hearBeatPort = h, this.root_url = this.base_url, this.wsService = u, this.wsService.onEvent = async (p) => {
1604
1633
  await super.Message(p);
@@ -1612,18 +1641,18 @@ const xt = "envision_agent_sessionId", Q = class Q extends W {
1612
1641
  lastEventId: (/* @__PURE__ */ new Date()).getTime().toString(),
1613
1642
  origin: "gatewayService"
1614
1643
  };
1615
- console.error("Stream error:", p), this.notificationPort.pushNotification({
1644
+ console.error("Stream error:", p), this.everConnected && this.notificationPort.pushNotification({
1616
1645
  message: "Reiniciando a conexão com o servidor",
1617
1646
  type: "info"
1618
1647
  }), super.Message(D);
1619
1648
  }, this.wsService.onOpen = () => {
1620
- this.sessionState.setConnectionStatus(_.Connected);
1649
+ this.everConnected = !0, this.sessionState.setConnectionStatus(R.Connected);
1621
1650
  }, this.wsService.onReconnected = (p) => {
1622
- this.sessionState.setConnectionStatus(_.Connected);
1651
+ this.sessionState.setConnectionStatus(R.Connected);
1623
1652
  }, this.wsService.onFirstToken = (p) => {
1624
1653
  this.localEmitFirstToken(p);
1625
1654
  }, this.wsService.onClose = (p, D) => {
1626
- p != J && this.sessionState.setConnectionStatus(_.Disconnected);
1655
+ p != H && this.sessionState.setConnectionStatus(R.Disconnected);
1627
1656
  };
1628
1657
  }
1629
1658
  reset(e, s) {
@@ -1690,7 +1719,7 @@ const xt = "envision_agent_sessionId", Q = class Q extends W {
1690
1719
  return !0;
1691
1720
  }
1692
1721
  async openConnection(e) {
1693
- return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == _.Disconnected ? (this.lastConnectionPromise = new Promise((s, i) => {
1722
+ return this.lastConnectionPromise ? this.lastConnectionPromise : this.socketState == R.Disconnected ? (this.lastConnectionPromise = new Promise((s, i) => {
1694
1723
  this.wsService.connect(e).then((n) => {
1695
1724
  this.sessionId = n, s(n);
1696
1725
  }).catch((n) => {
@@ -1722,11 +1751,11 @@ const xt = "envision_agent_sessionId", Q = class Q extends W {
1722
1751
  }
1723
1752
  // Send a message to the server via HTTP POST
1724
1753
  async sendMessageInternal(e, s, i) {
1725
- var l, o, u, d, h, C, p, D;
1754
+ var l, o, u, d, h, v, p, D;
1726
1755
  const n = this.suspendState;
1727
1756
  this.suspendState = !1;
1728
1757
  const r = this.startInteraction(e.friendlyMessage ?? e.data, n);
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)
1758
+ if (this.registerInteractionCallId(r.interactionId, s), (l = e.userUi) != null && l.name && r.parts.push(_.fromUserUi(e.userUi.name, e.userUi.args)), !this.wsService)
1730
1759
  throw "no wsService created";
1731
1760
  if (!this.sessionId)
1732
1761
  throw "no session id set";
@@ -1735,7 +1764,7 @@ const xt = "envision_agent_sessionId", Q = class Q extends W {
1735
1764
  return this.wsService.sendMessage({
1736
1765
  Content: e.data,
1737
1766
  SessionId: this.sessionId,
1738
- Action: x.SendMessage,
1767
+ Action: $.SendMessage,
1739
1768
  ModelId: this.config.model,
1740
1769
  InteractionId: r.interactionId,
1741
1770
  AgentId: (u = this.config.agentConfig) == null ? void 0 : u.id,
@@ -1747,11 +1776,11 @@ const xt = "envision_agent_sessionId", Q = class Q extends W {
1747
1776
  AgentImplementation: (d = this.config.agentConfig) == null ? void 0 : d.agentImplementation,
1748
1777
  Parameters: {
1749
1778
  CustomerName: ((h = this.config.customer) == null ? void 0 : h.name) ?? "",
1750
- DataSet: ((C = this.config.customer) == null ? void 0 : C.dataSetId) ?? ""
1779
+ DataSet: ((v = this.config.customer) == null ? void 0 : v.dataSetId) ?? ""
1751
1780
  },
1752
1781
  // Forward image attachments as a structured payload (PascalCase
1753
1782
  // keys to match the C# `Message.Images` / `MessageImage` model).
1754
- Images: (p = e.images) != null && p.length ? e.images.map((E) => ({ MimeType: E.mimeType, Data: E.data })) : void 0,
1783
+ Images: (p = e.images) != null && p.length ? e.images.map((y) => ({ MimeType: y.mimeType, Data: y.data })) : void 0,
1755
1784
  // Client-only UI representation for this turn (PascalCase to match the C# `Message.UserUi`
1756
1785
  // model). The server persists it as a UserUiContent sibling and strips it from the model
1757
1786
  // request; Content remains the only model-facing text.
@@ -1762,9 +1791,9 @@ const xt = "envision_agent_sessionId", Q = class Q extends W {
1762
1791
  });
1763
1792
  }
1764
1793
  };
1765
- f(Q, "AgentGatewayWSAsync");
1766
- let lt = Q;
1767
- const X = class X {
1794
+ f(V, "AgentGatewayWSAsync");
1795
+ let lt = V;
1796
+ const tt = class tt {
1768
1797
  constructor(t, e) {
1769
1798
  a(this, "cache", /* @__PURE__ */ new Map());
1770
1799
  a(this, "serverBaseUrl");
@@ -1819,17 +1848,17 @@ const X = class X {
1819
1848
  }
1820
1849
  }
1821
1850
  };
1822
- f(X, "HttpArtifactService");
1823
- let ht = X;
1851
+ f(tt, "HttpArtifactService");
1852
+ let ht = tt;
1824
1853
  export {
1825
- W as A,
1826
- $ as E,
1854
+ G as A,
1855
+ q as E,
1827
1856
  ht as H,
1828
- L as I,
1857
+ W as I,
1829
1858
  it as L,
1830
1859
  at as M,
1831
1860
  ct as W,
1832
1861
  lt as a,
1833
- jt as u
1862
+ Yt as u
1834
1863
  };
1835
- //# sourceMappingURL=httpArtifactService-hGsIslw7.js.map
1864
+ //# sourceMappingURL=httpArtifactService-3J9rNvgw.js.map