@twentyfourg/chat-kit 1.0.0-beta.1 → 1.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/chat-kit.js CHANGED
@@ -61,10 +61,10 @@ var L = {
61
61
  function R(e, t) {
62
62
  return e.replace(/\{(\w+)\}/g, (e, n) => n in t ? String(t[n]) : e);
63
63
  }
64
- function ee(e) {
64
+ function z(e) {
65
65
  return typeof e == "object" && !!e && !Array.isArray(e);
66
66
  }
67
- var te = /* @__PURE__ */ new Set([
67
+ var ee = /* @__PURE__ */ new Set([
68
68
  "status.rateLimited",
69
69
  "status.thinkingSequence",
70
70
  "sources.introLine",
@@ -80,69 +80,69 @@ var te = /* @__PURE__ */ new Set([
80
80
  "actions.copyLabel",
81
81
  "actions.copiedLabel"
82
82
  ]);
83
- function ne(e) {
84
- let t = [];
85
- function n(e, r, i) {
86
- if (Array.isArray(e)) return Array.isArray(r) ? [...r] : (t.push(i), [...e]);
87
- if (ee(e)) {
88
- let t = {};
83
+ function te(e, t = !0) {
84
+ let n = [];
85
+ function r(e, t, i) {
86
+ if (Array.isArray(e)) return Array.isArray(t) ? [...t] : (n.push(i), [...e]);
87
+ if (z(e)) {
88
+ let n = {};
89
89
  for (let a of Object.keys(e)) {
90
- let o = ee(r) ? r[a] : void 0;
91
- t[a] = n(e[a], o, i ? `${i}.${a}` : a);
90
+ let o = z(t) ? t[a] : void 0;
91
+ n[a] = r(e[a], o, i ? `${i}.${a}` : a);
92
92
  }
93
- return t;
93
+ return n;
94
94
  }
95
- return typeof r == typeof e ? r : (t.push(i), e);
95
+ return typeof t == typeof e ? t : (n.push(i), e);
96
96
  }
97
- let r = n(L, e, "");
98
- return e?.status?.rateLimited === void 0 && (r.status.rateLimited = r.status.error), t.filter((e) => !te.has(e)).length, r;
97
+ let i = r(L, e, "");
98
+ return e?.status?.rateLimited === void 0 && (i.status.rateLimited = i.status.error), n.filter((e) => !ee.has(e)).length, i;
99
99
  }
100
- var re = Symbol("chat-copy");
101
- function ie(e) {
102
- let t = ne(e);
103
- return y(re, t), t;
100
+ var ne = Symbol("chat-copy");
101
+ function re(e) {
102
+ let t = typeof e == "function" ? e : () => e, n = b(te(t()));
103
+ return typeof e == "function" && A(t, (e) => Object.assign(n, te(e, !1)), { deep: !0 }), y(ne, n), n;
104
104
  }
105
- function z() {
106
- return d(re, L);
105
+ function B() {
106
+ return d(ne, L);
107
107
  }
108
108
  //#endregion
109
109
  //#region src/services/anonymous-auth.ts
110
- async function ae(e) {
111
- let t = B(new URL(`${e.lxsApiUrl}/api/v1/directory/authentication`), e), n = await fetch(t.toString(), { headers: {
110
+ async function ie(e) {
111
+ let t = V(new URL(`${e.lxsApiUrl}/api/v1/directory/authentication`), e), n = await fetch(t.toString(), { headers: {
112
112
  Accept: "application/json",
113
113
  "x-tenant-hint": e.tenantNumber
114
114
  } });
115
- if (!n.ok) throw new V(`Could not read the login settings (${n.status}).`);
115
+ if (!n.ok) throw new H(`Could not read the login settings (${n.status}).`);
116
116
  return await n.json();
117
117
  }
118
- function oe() {
118
+ function ae() {
119
119
  let e = /* @__PURE__ */ new Uint8Array(32);
120
120
  return crypto.getRandomValues(e), Array.from(e, (e) => e.toString(16).padStart(2, "0")).join("");
121
121
  }
122
- async function se(e) {
122
+ async function oe(e) {
123
123
  let t = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(e));
124
124
  return Array.from(new Uint8Array(t), (e) => e.toString(16).padStart(2, "0")).join("");
125
125
  }
126
- function B(e, t) {
126
+ function V(e, t) {
127
127
  return t.deployEnv && e.searchParams.set("deployEnv", t.deployEnv), t.jobNumber && e.searchParams.set("jobNumber", t.jobNumber), e;
128
128
  }
129
- var V = class extends Error {
129
+ var H = class extends Error {
130
130
  constructor(e) {
131
131
  super(e), this.name = "AnonymousAuthError";
132
132
  }
133
133
  };
134
- async function H(e) {
134
+ async function se(e) {
135
135
  let { lxsApiUrl: t, tenantNumber: n } = e, r = e.authConfigId;
136
136
  if (!r) {
137
- let t = await ae(e);
138
- if (!t.authenticationStrategies?.find((e) => e.type === "anonymous")?.enabled) throw new V("This tenant does not allow guest sign-in.");
137
+ let t = await ie(e);
138
+ if (!t.authenticationStrategies?.find((e) => e.type === "anonymous")?.enabled) throw new H("This tenant does not allow guest sign-in.");
139
139
  r = t.PK;
140
140
  }
141
- let i = oe(), a = await se(i), o = {
141
+ let i = ae(), a = await oe(i), o = {
142
142
  Accept: "application/json",
143
143
  "Content-Type": "application/json",
144
144
  "x-tenant-hint": n
145
- }, s = B(new URL(`${t}/api/v1/directory/authentication/${r}/anonymous/login`), e);
145
+ }, s = V(new URL(`${t}/api/v1/directory/authentication/${r}/anonymous/login`), e);
146
146
  s.searchParams.set("codeChallenge", a), s.searchParams.set("codeChallengeMethod", "S256");
147
147
  let c = await fetch(s.toString(), {
148
148
  method: "POST",
@@ -152,21 +152,21 @@ async function H(e) {
152
152
  codeChallengeMethod: "S256"
153
153
  })
154
154
  });
155
- if (!c.ok) throw new V(`Anonymous sign-in failed (${c.status}).`);
155
+ if (!c.ok) throw new H(`Anonymous sign-in failed (${c.status}).`);
156
156
  let l = await c.json();
157
- if (!l.loggingInSessionId) throw new V("Anonymous sign-in did not return a session.");
158
- let u = B(new URL(`${t}/api/v1/directory/session/${encodeURIComponent(l.loggingInSessionId)}/sign`), e), d = await fetch(u.toString(), {
157
+ if (!l.loggingInSessionId) throw new H("Anonymous sign-in did not return a session.");
158
+ let u = V(new URL(`${t}/api/v1/directory/session/${encodeURIComponent(l.loggingInSessionId)}/sign`), e), d = await fetch(u.toString(), {
159
159
  method: "POST",
160
160
  headers: o,
161
161
  body: JSON.stringify({ codeVerifier: i })
162
162
  });
163
- if (!d.ok) throw new V(`Could not get a chat token (${d.status}).`);
163
+ if (!d.ok) throw new H(`Could not get a chat token (${d.status}).`);
164
164
  let f = await d.json(), p = f.baseCampAuthToken || f.token;
165
- if (f.success === !1 || !p) throw new V(f.message || "No chat token was returned.");
165
+ if (f.success === !1 || !p) throw new H(f.message || "No chat token was returned.");
166
166
  return p;
167
167
  }
168
168
  function ce(e) {
169
- let t = null, n = (() => (t ||= H(e).catch((e) => {
169
+ let t = null, n = (() => (t ||= se(e).catch((e) => {
170
170
  throw t = null, e;
171
171
  }), t));
172
172
  return n.prefetch = () => {
@@ -191,7 +191,10 @@ var le = class extends Error {
191
191
  }
192
192
  async createThread(e, t) {
193
193
  let { variables: n, customData: r } = t ?? {}, i = await this.request("POST", `/v1/agents/${e}/threads`, n ? { variables: n } : {});
194
- return r && Object.keys(r).length > 0 && await this.request("PATCH", `/v1/agents/${e}/threads/${i.id}`, { customData: r }), i;
194
+ return r && Object.keys(r).length > 0 && await this.updateThread(e, i.id, { customData: r }), i;
195
+ }
196
+ updateThread(e, t, n) {
197
+ return this.request("PATCH", `/v1/agents/${e}/threads/${t}`, n);
195
198
  }
196
199
  async getThreads(e, t) {
197
200
  return (await this.request("GET", `/v1/agents/${e}/threads?limit=${t}`)).threads;
@@ -656,47 +659,47 @@ function K() {
656
659
  return Ze += 1, `local-${Ze}`;
657
660
  }
658
661
  function Qe(e) {
659
- let { transport: t, agentId: r } = e, i = T(null), a = S(null), o = S([]), s = S("idle"), c = S(null), l = T(null), u = T(null);
660
- async function d() {
662
+ let { transport: t, agentId: r } = e, i = T(null), a = S(null), o = S([]), s = S("idle"), c = S(null), l = T(null), u = T(null), d = T(null);
663
+ async function f() {
661
664
  if (t.getQuota) try {
662
- u.value = await t.getQuota(r);
665
+ d.value = await t.getQuota(r);
663
666
  } catch {}
664
667
  }
665
- let f = T(null), p = n(() => s.value === "thinking" ? f.value?.thinking ?? "" : ""), m = n(() => {
668
+ let p = T(null), m = n(() => s.value === "thinking" ? p.value?.thinking ?? "" : ""), h = n(() => {
666
669
  let e = c.value;
667
670
  return e ? e.status === 429 || e.name === "RateLimitError" ? "rate-limited" : "error" : null;
668
- }), h = null, g = null, _ = t.getAgent(r).then((e) => (i.value = e, e)).catch(() => null);
669
- d();
670
- let v = n(() => s.value !== "idle");
671
- function y(e) {
671
+ }), g = null, _ = null, v = t.getAgent(r).then((e) => (i.value = e, e)).catch(() => null);
672
+ f();
673
+ let y = n(() => s.value !== "idle");
674
+ function C(e) {
672
675
  return o.value.find((t) => t.id === e);
673
676
  }
674
- function C(t) {
677
+ function w(t) {
675
678
  try {
676
679
  e.onEvent?.(t);
677
680
  } catch {}
678
681
  }
679
- function w(e) {
682
+ function E(e) {
680
683
  let t = o.value.indexOf(e);
681
684
  return {
682
685
  query: o.value.slice(0, t).reverse().find((e) => e.role === "user")?.text ?? "",
683
686
  response: e.text
684
687
  };
685
688
  }
686
- async function E() {
689
+ async function D() {
687
690
  if (a.value) return a.value;
688
691
  let e = await t.createThread(r);
689
692
  return a.value = e.id, e.id;
690
693
  }
691
- function D(e, t = "typed") {
694
+ function O(e, t = "typed") {
692
695
  let n = e.trim();
693
- if (!n || v.value) return Promise.resolve();
694
- let r = O(n, t);
695
- return g = r, r.finally(() => {
696
- g === r && (g = null);
696
+ if (!n || y.value) return Promise.resolve();
697
+ let r = k(n, t);
698
+ return _ = r, r.finally(() => {
699
+ _ === r && (_ = null);
697
700
  }), r;
698
701
  }
699
- async function O(n, i) {
702
+ async function k(n, i) {
700
703
  c.value = null, s.value = "thinking";
701
704
  let u = b({
702
705
  id: K(),
@@ -714,7 +717,7 @@ function Qe(e) {
714
717
  inputMode: i
715
718
  });
716
719
  o.value.push(u);
717
- let p = b({
720
+ let d = b({
718
721
  id: K(),
719
722
  role: "assistant",
720
723
  text: "",
@@ -728,20 +731,20 @@ function Qe(e) {
728
731
  isReceiving: !1,
729
732
  failed: !1
730
733
  });
731
- f.value = p;
734
+ p.value = d;
732
735
  let m = new AbortController();
733
- h = m;
734
- let g = new Ke((e) => {
735
- p.html = e;
736
+ g = m;
737
+ let h = new Ke((e) => {
738
+ d.html = e;
736
739
  }, 25, e.showMath);
737
740
  function _() {
738
- s.value !== "streaming" && (s.value = "streaming", p.isStreaming = !0, p.isReceiving = !0, o.value.push(p));
741
+ s.value !== "streaming" && (s.value = "streaming", d.isStreaming = !0, d.isReceiving = !0, o.value.push(d));
739
742
  }
740
743
  let v = new Ye((e) => {
741
- _(), p.text += e, g.addChunk(e);
744
+ _(), d.text += e, h.addChunk(e);
742
745
  }, e.typewriter ?? !0), y = null;
743
746
  try {
744
- let o = await E();
747
+ let o = await D();
745
748
  if (await U(await t.sendMessage(r, o, {
746
749
  message: n,
747
750
  stream: !0,
@@ -755,49 +758,49 @@ function Qe(e) {
755
758
  y = e;
756
759
  },
757
760
  onMetadata: (e) => {
758
- e.sources && (p.sources = e.sources);
761
+ e.sources && (d.sources = e.sources);
759
762
  },
760
763
  onThinkingChunk: (e) => {
761
- p.thinking += e;
764
+ d.thinking += e;
762
765
  }
763
766
  }, (e, t) => {
764
- if (e === "citations" && Array.isArray(t)) return p.citations = t, !0;
767
+ if (e === "citations" && Array.isArray(t)) return d.citations = t, !0;
765
768
  let n = t ?? {};
766
- return e === "message_id" && typeof n.messageId == "string" ? (u.basecampMessageId = n.messageId, !0) : e === "assistant_message_id" && typeof n.messageId == "string" ? (p.basecampMessageId = n.messageId, !0) : e === "used_sources" && Array.isArray(t) ? (p.sources = t, !0) : e === "token_usage" && n.thread ? (l.value = n.thread, !0) : !1;
769
+ return e === "message_id" && typeof n.messageId == "string" ? (u.basecampMessageId = n.messageId, !0) : e === "assistant_message_id" && typeof n.messageId == "string" ? (d.basecampMessageId = n.messageId, !0) : e === "used_sources" && Array.isArray(t) ? (d.sources = t, !0) : e === "token_usage" && n.thread ? (l.value = n.thread, !0) : !1;
767
770
  }), y) throw y;
768
771
  if (m.signal.aborted) {
769
- v.flush(), await g.complete(), p.isReceiving = !1, p.isStreaming = !1;
772
+ v.flush(), await h.complete(), d.isReceiving = !1, d.isStreaming = !1;
770
773
  return;
771
774
  }
772
- if (p.isReceiving = !1, await v.finish(), !p.text) throw Error("The response ended without any content.");
773
- await g.complete(), p.isOutOfScope = e.isOutOfScope?.(p.text) ?? !1, p.isStreaming = !1, C({
775
+ if (d.isReceiving = !1, await v.finish(), !d.text) throw Error("The response ended without any content.");
776
+ await h.complete(), d.isOutOfScope = e.isOutOfScope?.(d.text) ?? !1, d.isStreaming = !1, w({
774
777
  type: "turn",
775
778
  query: n,
776
779
  inputMode: i,
777
- response: p.text,
778
- isOutOfScope: p.isOutOfScope,
779
- citations: p.citations,
780
- sources: p.sources,
780
+ response: d.text,
781
+ isOutOfScope: d.isOutOfScope,
782
+ citations: d.citations,
783
+ sources: d.sources,
781
784
  threadId: a.value,
782
785
  userMessageId: u.basecampMessageId,
783
- assistantMessageId: p.basecampMessageId
786
+ assistantMessageId: d.basecampMessageId
784
787
  });
785
788
  } catch (t) {
786
- v.flush(), t?.name !== "AbortError" && (p.text ? p.failed = !0 : c.value = t instanceof Error ? t : Error(String(t))), g.stop(), p.isReceiving = !1, p.isStreaming = !1, p.text && (p.html = await W(p.text, { showMath: e.showMath }));
789
+ v.flush(), t?.name !== "AbortError" && (d.text ? d.failed = !0 : c.value = t instanceof Error ? t : Error(String(t))), h.stop(), d.isReceiving = !1, d.isStreaming = !1, d.text && (d.html = await W(d.text, { showMath: e.showMath }));
787
790
  } finally {
788
- v.destroy(), h = null, f.value = null, s.value = "idle", d();
791
+ v.destroy(), g = null, p.value = null, s.value = "idle", f();
789
792
  }
790
793
  }
791
- async function k() {
792
- let e = g;
794
+ async function A() {
795
+ let e = _;
793
796
  if (!e) return;
794
797
  let n = o.value.find((e) => e.isStreaming)?.basecampMessageId;
795
- h?.abort(), n && a.value && t.stopMessage(r, a.value, n).catch(() => {}), await e;
798
+ g?.abort(), n && a.value && t.stopMessage(r, a.value, n).catch(() => {}), await e;
796
799
  }
797
- async function A() {
798
- await k(), a.value = null, o.value = [], c.value = null;
800
+ async function j() {
801
+ await A(), a.value = null, o.value = [], u.value = null, c.value = null;
799
802
  }
800
- async function j(t) {
803
+ async function M(t) {
801
804
  let n = t.role === "assistant", r = n ? t.text.replace(/\[\^\d+\]/g, "") : t.text;
802
805
  return b({
803
806
  id: K(),
@@ -815,7 +818,7 @@ function Qe(e) {
815
818
  failed: !1
816
819
  });
817
820
  }
818
- async function M(e = Xe) {
821
+ async function N(e = Xe) {
819
822
  if (!t.getThreads) throw Error("This transport does not implement getThreads, so history cannot be listed.");
820
823
  let n = await t.getThreads(r, e);
821
824
  return {
@@ -823,63 +826,88 @@ function Qe(e) {
823
826
  mightHaveMore: n.length >= e
824
827
  };
825
828
  }
826
- async function N(e) {
829
+ async function P(e) {
827
830
  if (!t.getMessages) throw Error("This transport does not implement getMessages, so history cannot be loaded.");
828
- await k();
829
- let n = await t.getMessages(r, e), i = n.messages.filter((e) => !e.metadata?.isWelcomeMessage), s = await Promise.all(i.map((e) => j(e)));
830
- a.value = e, o.value = s, l.value = n.tokenUsage ?? null, c.value = null;
831
+ await A();
832
+ let n = await t.getMessages(r, e), i = n.messages.filter((e) => !e.metadata?.isWelcomeMessage), s = await Promise.all(i.map((e) => M(e)));
833
+ a.value = e, o.value = s, l.value = n.tokenUsage ?? null, u.value = n.customData ?? null, c.value = null;
831
834
  }
832
- async function P(e, n) {
833
- let i = y(e);
835
+ async function F(e, n) {
836
+ let i = C(e);
834
837
  if (!i?.basecampMessageId || !a.value) return;
835
838
  let o = i.feedback, s = o === n ? null : n;
836
839
  i.feedback = s;
837
840
  try {
838
- s ? await t.submitFeedback(r, a.value, i.basecampMessageId, s) : await t.clearFeedback(r, a.value, i.basecampMessageId), C({
841
+ s ? await t.submitFeedback(r, a.value, i.basecampMessageId, s) : await t.clearFeedback(r, a.value, i.basecampMessageId), w({
839
842
  type: "feedback",
840
843
  value: s,
841
844
  assistantMessageId: i.basecampMessageId,
842
845
  threadId: a.value,
843
- ...w(i)
846
+ ...E(i)
844
847
  });
845
848
  } catch {
846
849
  i.feedback = o;
847
850
  }
848
851
  }
849
- function F(e, t) {
850
- let n = y(e);
851
- n && C({
852
+ function I(e, t) {
853
+ let n = C(e);
854
+ n && w({
852
855
  type: "citation-click",
853
856
  citation: t,
854
857
  assistantMessageId: n.basecampMessageId,
855
858
  threadId: a.value,
856
- ...w(n)
859
+ ...E(n)
857
860
  });
858
861
  }
859
- async function I() {
862
+ function L(e = {}, t) {
863
+ let n = b({
864
+ id: K(),
865
+ role: e.role ?? "app",
866
+ text: e.text ?? "",
867
+ html: "",
868
+ thinking: "",
869
+ sources: [],
870
+ citations: [],
871
+ feedback: null,
872
+ isOutOfScope: !1,
873
+ isStreaming: !1,
874
+ isReceiving: !1,
875
+ failed: !1,
876
+ data: e.data
877
+ });
878
+ return t === void 0 || t >= o.value.length ? o.value.push(n) : o.value.splice(Math.max(0, t), 0, n), n;
879
+ }
880
+ function R(e) {
881
+ let t = o.value.findIndex((t) => t.id === e);
882
+ return t !== -1 && (o.value.splice(t, 1), !0);
883
+ }
884
+ async function z() {
860
885
  let e = [...o.value].reverse().find((e) => e.role === "user");
861
- e && !v.value && (o.value = o.value.filter((t) => t !== e && !(t.role === "assistant" && t.failed)), c.value = null, await D(e.text, e.inputMode));
886
+ e && !y.value && (o.value = o.value.filter((t) => t !== e && !(t.role === "assistant" && t.failed)), c.value = null, await O(e.text, e.inputMode));
862
887
  }
863
888
  return {
864
889
  agent: x(i),
865
- agentReady: _,
890
+ agentReady: v,
866
891
  threadId: x(a),
867
892
  messages: o,
868
893
  status: x(s),
869
894
  error: x(c),
870
- errorKind: m,
871
- busy: v,
895
+ errorKind: h,
896
+ busy: y,
872
897
  tokenUsage: x(l),
873
- quota: x(u),
874
- liveThinking: p,
875
- sendMessage: D,
876
- stopGeneration: k,
877
- newConversation: A,
878
- listThreads: M,
879
- loadThread: N,
880
- setFeedback: P,
881
- noteCitationClick: F,
882
- retry: I
898
+ customData: x(u),
899
+ quota: x(d),
900
+ liveThinking: m,
901
+ sendMessage: O,
902
+ stopGeneration: A,
903
+ newConversation: j,
904
+ listThreads: N,
905
+ loadThread: P,
906
+ setFeedback: F,
907
+ noteCitationClick: I,
908
+ insertMessage: L,
909
+ removeMessage: R,
910
+ retry: z
883
911
  };
884
912
  }
885
913
  //#endregion
@@ -1184,33 +1212,33 @@ var it = {
1184
1212
  },
1185
1213
  emits: ["send", "stop"],
1186
1214
  setup(e, { emit: t }) {
1187
- let s = e, c = t, u = z(), d = S(""), f = S(null), { isSupported: m, isListening: _, toggle: y, stop: b } = rt(d), x = n(() => d.value.trim().length > 0 && !s.busy), C = S(!1);
1215
+ let s = e, c = t, u = B(), d = S(""), f = S(null), { isSupported: m, isListening: _, toggle: y, stop: b } = rt(d), x = n(() => d.value.trim().length > 0 && !s.busy), C = S(!1);
1188
1216
  A(d, (e) => {
1189
1217
  e ? _.value && (C.value = !0) : C.value = !1;
1190
1218
  });
1191
- function w() {
1219
+ function T() {
1192
1220
  let e = f.value;
1193
1221
  e && (e.style.height = "auto", e.style.height = `${Math.min(e.scrollHeight, 100)}px`);
1194
1222
  }
1195
- A(d, w, { flush: "post" });
1196
- let T = null;
1223
+ A(d, T, { flush: "post" });
1224
+ let E = null;
1197
1225
  g(() => {
1198
- w(), document.fonts.ready.then(w);
1226
+ T(), document.fonts.ready.then(T);
1199
1227
  let e = f.value;
1200
1228
  if (!e || typeof ResizeObserver > "u") return;
1201
1229
  let t = e.clientWidth;
1202
- T = new ResizeObserver(() => {
1203
- e.clientWidth !== t && (t = e.clientWidth, w());
1204
- }), T.observe(e);
1205
- }), h(() => T?.disconnect());
1206
- function E() {
1230
+ E = new ResizeObserver(() => {
1231
+ e.clientWidth !== t && (t = e.clientWidth, T());
1232
+ }), E.observe(e);
1233
+ }), h(() => E?.disconnect());
1234
+ function O() {
1207
1235
  if (!x.value) return;
1208
1236
  b();
1209
1237
  let e = d.value, t = C.value ? "voice" : "typed";
1210
1238
  d.value = "", C.value = !1, c("send", e, t);
1211
1239
  }
1212
- function O(e) {
1213
- e.key === "Enter" && !e.shiftKey && (e.preventDefault(), E());
1240
+ function N(e) {
1241
+ e.key === "Enter" && !e.shiftKey && (e.preventDefault(), O());
1214
1242
  }
1215
1243
  return (t, n) => (v(), a("div", gt, [o("div", _t, [M(o("textarea", {
1216
1244
  ref_key: "field",
@@ -1219,7 +1247,7 @@ var it = {
1219
1247
  class: "input-bar__textarea",
1220
1248
  rows: "1",
1221
1249
  placeholder: D(u).composer.placeholder,
1222
- onKeydown: O
1250
+ onKeydown: N
1223
1251
  }, null, 40, vt), [[k, d.value]]), o("div", yt, [e.showMic && D(m) ? (v(), r(X, {
1224
1252
  key: 0,
1225
1253
  label: D(u).composer.dictateLabel,
@@ -1248,16 +1276,16 @@ var it = {
1248
1276
  class: "input-bar__send",
1249
1277
  label: D(u).composer.sendLabel,
1250
1278
  disabled: !x.value,
1251
- onClick: E
1279
+ onClick: O
1252
1280
  }, {
1253
1281
  default: j(() => [l(Z, {
1254
1282
  name: "send",
1255
1283
  size: 20
1256
1284
  })]),
1257
1285
  _: 1
1258
- }, 8, ["label", "disabled"]))])])]));
1286
+ }, 8, ["label", "disabled"]))])]), w(t.$slots, "footer", {}, void 0, !0)]));
1259
1287
  }
1260
- }), [["__scopeId", "data-v-752f72a0"]]), St = 20, Ct = 300, wt = .3, Tt = 12, Et = 8;
1288
+ }), [["__scopeId", "data-v-2a67b2cf"]]), St = 20, Ct = 300, wt = .3, Tt = 12, Et = 8;
1261
1289
  function Dt(e, t = {}) {
1262
1290
  let n = S("following"), r = !1, i = 0, a = !1, o = null, s = !1, c = () => t.mode?.() ?? "reply";
1263
1291
  function l(e) {
@@ -1334,15 +1362,15 @@ function kt(e) {
1334
1362
  }
1335
1363
  var At = "<sup class=\"citation-chip citation-chip--pending\">&middot;</sup>";
1336
1364
  function jt(e, t, n = {}) {
1337
- if (!e || t.length === 0 && !n.pendingMarkers) return e;
1338
- let r = new Map(t.map((e) => [e.ref, e]));
1365
+ if (!e) return e;
1366
+ let r = new Map(t.map((e) => [e.ref, e])), i = t.length > 0;
1339
1367
  return e.replace(Ot, (e, t) => {
1340
- let i = r.get(Number(t));
1341
- if (i) {
1342
- let e = kt(G(i.title || "Source"));
1343
- return `<sup class="citation-chip" data-citation-ref="${i.ref}" title="${e}" tabindex="0">${i.label}</sup>`;
1368
+ let a = r.get(Number(t));
1369
+ if (a) {
1370
+ let e = kt(G(a.title || "Source"));
1371
+ return `<sup class="citation-chip" data-citation-ref="${a.ref}" title="${e}" tabindex="0">${a.label}</sup>`;
1344
1372
  }
1345
- return n.pendingMarkers ? At : e;
1373
+ return n.pendingMarkers || !i ? At : "";
1346
1374
  });
1347
1375
  }
1348
1376
  //#endregion
@@ -1361,7 +1389,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1361
1389
  props: { citation: {} },
1362
1390
  emits: ["close"],
1363
1391
  setup(e, { emit: t }) {
1364
- let r = e, s = t, u = z(), d = S(!1);
1392
+ let r = e, s = t, u = B(), d = S(!1);
1365
1393
  A(() => r.citation.screenshotUrl, () => {
1366
1394
  d.value = !1;
1367
1395
  });
@@ -1411,7 +1439,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1411
1439
  props: { feedback: {} },
1412
1440
  emits: ["rate"],
1413
1441
  setup(e, { emit: t }) {
1414
- let n = t, r = z();
1442
+ let n = t, r = B();
1415
1443
  return (t, i) => (v(), a("div", Gt, [o("span", Kt, E(D(r).feedback.question), 1), o("div", qt, [o("button", {
1416
1444
  type: "button",
1417
1445
  class: p(["feedback__thumb", { "is-active": e.feedback === "POSITIVE" }]),
@@ -1434,7 +1462,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1434
1462
  },
1435
1463
  emits: ["close"],
1436
1464
  setup(e, { emit: n }) {
1437
- let s = n, c = z();
1465
+ let s = n, c = B();
1438
1466
  function l(e) {
1439
1467
  e.key === "Escape" && s("close");
1440
1468
  }
@@ -1470,7 +1498,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1470
1498
  },
1471
1499
  emits: ["viewPage"],
1472
1500
  setup(t, { emit: r }) {
1473
- let s = t, u = r, d = z(), f = S(!1), m = n(() => G(s.source.metadata?.title ?? "")), h = n(() => s.source.metadata?.link || null), g = n(() => s.source.metadata?.screenshotUrl || s.source.screenshotUrl || ""), _ = S(!1);
1501
+ let s = t, u = r, d = B(), f = S(!1), m = n(() => G(s.source.metadata?.title ?? "")), h = n(() => s.source.metadata?.link || null), g = n(() => s.source.metadata?.screenshotUrl || s.source.screenshotUrl || ""), _ = S(!1);
1474
1502
  A(g, () => {
1475
1503
  _.value = !1;
1476
1504
  });
@@ -1534,7 +1562,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1534
1562
  __name: "SourceList",
1535
1563
  props: { sources: {} },
1536
1564
  setup(t) {
1537
- let n = z(), o = S(null);
1565
+ let n = B(), o = S(null);
1538
1566
  return (s, c) => t.sources.length > 0 ? (v(), a("div", yn, [
1539
1567
  D(n).sources.introLine ? (v(), a("p", bn, E(D(n).sources.introLine), 1)) : i("", !0),
1540
1568
  (v(!0), a(e, null, C(t.sources, (e, t) => (v(), r(vn, {
@@ -1589,7 +1617,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1589
1617
  streaming: { type: Boolean }
1590
1618
  },
1591
1619
  setup(e) {
1592
- let t = e, n = z(), r = S(t.streaming === !0), s = S(null);
1620
+ let t = e, n = B(), r = S(t.streaming === !0), s = S(null);
1593
1621
  return A(() => t.text, async () => {
1594
1622
  if (!t.streaming || !r.value) return;
1595
1623
  await f();
@@ -1636,7 +1664,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1636
1664
  "citationClick"
1637
1665
  ],
1638
1666
  setup(e, { emit: s }) {
1639
- let c = e, u = s, d = z(), f = O();
1667
+ let c = e, u = s, d = B(), f = O();
1640
1668
  function p() {
1641
1669
  return (c.showCopy === !0 || !!f["message-actions"]) && !c.message.isStreaming && !!c.message.text;
1642
1670
  }
@@ -1737,10 +1765,11 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1737
1765
  key: 1,
1738
1766
  feedback: e.message.feedback,
1739
1767
  onRate: s[2] ||= (t) => u("rate", e.message.id, t)
1740
- }, null, 8, ["feedback"])) : i("", !0)])) : i("", !0)
1768
+ }, null, 8, ["feedback"])) : i("", !0)])) : i("", !0),
1769
+ w(n.$slots, "message-footer", { message: e.message }, void 0, !0)
1741
1770
  ]));
1742
1771
  }
1743
- }), [["__scopeId", "data-v-81f04579"]]), Un = { class: "thinking" }, Wn = {
1772
+ }), [["__scopeId", "data-v-466b7413"]]), Un = { class: "thinking" }, Wn = {
1744
1773
  key: 0,
1745
1774
  class: "thinking__label"
1746
1775
  }, Gn = 2e3, Kn = /*#__PURE__*/ Y(/* @__PURE__ */ u({
@@ -1750,7 +1779,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1750
1779
  rotateLabel: { type: Boolean }
1751
1780
  },
1752
1781
  setup(e) {
1753
- let t = e, r = z(), o = n(() => t.rotateLabel ? r.status.thinkingSequence : []), s = S(0), c = n(() => o.value[s.value] ?? r.status.thinking), u;
1782
+ let t = e, r = B(), o = n(() => t.rotateLabel ? r.status.thinkingSequence : []), s = S(0), c = n(() => o.value[s.value] ?? r.status.thinking), u;
1754
1783
  return g(() => {
1755
1784
  if (o.value.length < 2) return;
1756
1785
  let e = () => {
@@ -1787,7 +1816,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1787
1816
  },
1788
1817
  emits: ["rated"],
1789
1818
  setup(t, { emit: n }) {
1790
- let c = t, l = n, u = z(), d = S(null), { glideToBottom: f, resetToFollowing: p } = Dt(d, {
1819
+ let c = t, l = n, u = B(), d = S(null), { glideToBottom: f, resetToFollowing: p } = Dt(d, {
1791
1820
  mode: () => c.autoScroll ?? "reply",
1792
1821
  anchor: () => {
1793
1822
  if (c.engine.messages.value.at(-1)?.role !== "assistant") return null;
@@ -1800,6 +1829,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1800
1829
  }), A(() => [
1801
1830
  c.engine.messages.value.length,
1802
1831
  c.engine.messages.value.at(-1)?.html,
1832
+ c.engine.messages.value.at(-1)?.text,
1803
1833
  c.engine.status.value
1804
1834
  ], () => f());
1805
1835
  function m(e, t) {
@@ -1821,8 +1851,8 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1821
1851
  (v(!0), a(e, null, C(t.engine.messages.value, (i) => (v(), a(e, { key: i.id }, [i.role === "user" ? (v(), r(Yn, {
1822
1852
  key: 0,
1823
1853
  message: i
1824
- }, null, 8, ["message"])) : (v(), r(Hn, {
1825
- key: 1,
1854
+ }, null, 8, ["message"])) : i.role === "app" ? w(n.$slots, "message", { message: i }, void 0, !0, 1) : (v(), r(Hn, {
1855
+ key: 2,
1826
1856
  message: i,
1827
1857
  "citation-type": t.citationType,
1828
1858
  "show-thinking": t.showThinking,
@@ -1835,6 +1865,10 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1835
1865
  name: "message-actions",
1836
1866
  fn: j(({ message: e }) => [w(n.$slots, "message-actions", { message: e }, void 0, !0)]),
1837
1867
  key: "0"
1868
+ } : void 0, n.$slots["message-footer"] ? {
1869
+ name: "message-footer",
1870
+ fn: j(({ message: e }) => [w(n.$slots, "message-footer", { message: e }, void 0, !0)]),
1871
+ key: "1"
1838
1872
  } : void 0]), 1032, [
1839
1873
  "message",
1840
1874
  "citation-type",
@@ -1859,7 +1893,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1859
1893
  }, E(D(u).status.retryLabel), 1)])) : i("", !0)
1860
1894
  ], 512));
1861
1895
  }
1862
- }), [["__scopeId", "data-v-1e679b5e"]]), rr = { class: "chat" }, ir = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1896
+ }), [["__scopeId", "data-v-2f494fbc"]]), rr = { class: "chat" }, ir = /*#__PURE__*/ Y(/* @__PURE__ */ u({
1863
1897
  __name: "Chat",
1864
1898
  props: {
1865
1899
  engine: {},
@@ -1870,12 +1904,17 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1870
1904
  rotateThinkingLabel: { type: Boolean },
1871
1905
  showThinking: { type: Boolean },
1872
1906
  autoScroll: {},
1873
- showCopy: { type: Boolean }
1907
+ showCopy: { type: Boolean },
1908
+ beforeSend: { type: Function }
1874
1909
  },
1875
1910
  emits: ["rated"],
1876
1911
  setup(e, { emit: t }) {
1877
1912
  let n = e, r = t;
1878
- return ie(n.copy), (t, n) => (v(), a("div", rr, [l(nr, {
1913
+ re(() => n.copy);
1914
+ async function i(e, t) {
1915
+ n.beforeSend && await n.beforeSend(e, t) === !1 || await n.engine.sendMessage(e, t);
1916
+ }
1917
+ return (t, n) => (v(), a("div", rr, [l(nr, {
1879
1918
  engine: e.engine,
1880
1919
  "citation-type": e.citationType ?? "inline",
1881
1920
  "thinking-variant": e.thinkingVariant,
@@ -1884,15 +1923,28 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1884
1923
  "auto-scroll": e.autoScroll,
1885
1924
  "show-copy": e.showCopy,
1886
1925
  onRated: n[0] ||= (e, t) => r("rated", e, t)
1887
- }, s({ _: 2 }, [t.$slots["message-actions"] ? {
1888
- name: "message-actions",
1889
- fn: j(({ message: e }) => [w(t.$slots, "message-actions", { message: e }, void 0, !0)]),
1890
- key: "0"
1891
- } : void 0, t.$slots.welcome ? {
1892
- name: "welcome",
1893
- fn: j(() => [w(t.$slots, "welcome", {}, void 0, !0)]),
1894
- key: "1"
1895
- } : void 0]), 1032, [
1926
+ }, s({ _: 2 }, [
1927
+ t.$slots.message ? {
1928
+ name: "message",
1929
+ fn: j(({ message: e }) => [w(t.$slots, "message", { message: e }, void 0, !0)]),
1930
+ key: "0"
1931
+ } : void 0,
1932
+ t.$slots["message-actions"] ? {
1933
+ name: "message-actions",
1934
+ fn: j(({ message: e }) => [w(t.$slots, "message-actions", { message: e }, void 0, !0)]),
1935
+ key: "1"
1936
+ } : void 0,
1937
+ t.$slots["message-footer"] ? {
1938
+ name: "message-footer",
1939
+ fn: j(({ message: e }) => [w(t.$slots, "message-footer", { message: e }, void 0, !0)]),
1940
+ key: "2"
1941
+ } : void 0,
1942
+ t.$slots.welcome ? {
1943
+ name: "welcome",
1944
+ fn: j(() => [w(t.$slots, "welcome", {}, void 0, !0)]),
1945
+ key: "3"
1946
+ } : void 0
1947
+ ]), 1032, [
1896
1948
  "engine",
1897
1949
  "citation-type",
1898
1950
  "thinking-variant",
@@ -1900,15 +1952,19 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1900
1952
  "show-thinking",
1901
1953
  "auto-scroll",
1902
1954
  "show-copy"
1903
- ]), l(xt, {
1955
+ ]), w(t.$slots, "composer", {}, () => [l(xt, {
1904
1956
  busy: e.engine.busy.value,
1905
1957
  "show-mic": e.showMic,
1906
- onSend: n[1] ||= (t, n) => e.engine.sendMessage(t, n),
1907
- onStop: n[2] ||= () => e.engine.stopGeneration()
1908
- }, null, 8, ["busy", "show-mic"])]));
1958
+ onSend: i,
1959
+ onStop: n[1] ||= () => e.engine.stopGeneration()
1960
+ }, s({ _: 2 }, [t.$slots["composer-footer"] ? {
1961
+ name: "footer",
1962
+ fn: j(() => [w(t.$slots, "composer-footer", {}, void 0, !0)]),
1963
+ key: "0"
1964
+ } : void 0]), 1032, ["busy", "show-mic"])], !0)]));
1909
1965
  }
1910
- }), [["__scopeId", "data-v-f63ed144"]]);
1966
+ }), [["__scopeId", "data-v-7ad4b6f4"]]);
1911
1967
  //#endregion
1912
- export { V as AnonymousAuthError, ue as BaseCampClient, le as BaseCampError, ir as Chat, X as IconButton, et as MockTransport, fe as RateLimitError, Ke as StreamingMessage, U as consumeSSEResponse, ce as createAnonymousTokenProvider, G as decodeHtmlEntities, L as defaultChatCopy, ae as fetchAuthConfig, R as formatCopy, ie as provideChatCopy, W as renderMarkdownSafe, Ve as renderMarkdownStreaming, ne as resolveChatCopy, H as signInAnonymously, Se as streamSSE, Ge as stripHtmlTags, z as useChatCopy, Qe as useChatEngine };
1968
+ export { H as AnonymousAuthError, ue as BaseCampClient, le as BaseCampError, ir as Chat, X as IconButton, et as MockTransport, fe as RateLimitError, Ke as StreamingMessage, Ye as Typewriter, U as consumeSSEResponse, ce as createAnonymousTokenProvider, G as decodeHtmlEntities, L as defaultChatCopy, ie as fetchAuthConfig, R as formatCopy, re as provideChatCopy, W as renderMarkdownSafe, Ve as renderMarkdownStreaming, te as resolveChatCopy, se as signInAnonymously, Se as streamSSE, Ge as stripHtmlTags, B as useChatCopy, Qe as useChatEngine };
1913
1969
 
1914
1970
  //# sourceMappingURL=chat-kit.js.map