@twentyfourg/chat-kit 1.0.0-beta.3 → 1.0.0-beta.4

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
@@ -717,7 +717,7 @@ function Qe(e) {
717
717
  inputMode: i
718
718
  });
719
719
  o.value.push(u);
720
- let d = b({
720
+ let m = b({
721
721
  id: K(),
722
722
  role: "assistant",
723
723
  text: "",
@@ -731,64 +731,71 @@ function Qe(e) {
731
731
  isReceiving: !1,
732
732
  failed: !1
733
733
  });
734
- p.value = d;
735
- let m = new AbortController();
736
- g = m;
737
- let h = new Ke((e) => {
738
- d.html = e;
734
+ p.value = m;
735
+ let h = new AbortController();
736
+ g = h;
737
+ let _ = new Ke((e) => {
738
+ m.html = e;
739
739
  }, 25, e.showMath);
740
- function _() {
741
- s.value !== "streaming" && (s.value = "streaming", d.isStreaming = !0, d.isReceiving = !0, o.value.push(d));
740
+ function v() {
741
+ s.value !== "streaming" && (s.value = "streaming", m.isStreaming = !0, m.isReceiving = !0, o.value.push(m));
742
742
  }
743
- let v = new Ye((e) => {
744
- _(), d.text += e, h.addChunk(e);
745
- }, e.typewriter ?? !0), y = null;
743
+ let y = new Ye((e) => {
744
+ v(), m.text += e, _.addChunk(e);
745
+ }, e.typewriter ?? !0), x = null, S = null;
746
746
  try {
747
747
  let o = await D();
748
748
  if (await U(await t.sendMessage(r, o, {
749
749
  message: n,
750
750
  stream: !0,
751
751
  ...i === "voice" && { inputMode: "dictation" }
752
- }, { signal: m.signal }), {
752
+ }, { signal: h.signal }), {
753
753
  onChunk: (e) => {
754
- v.push(e);
754
+ y.push(e);
755
755
  },
756
756
  onComplete: () => {},
757
757
  onError: (e) => {
758
- y = e;
758
+ x = e;
759
759
  },
760
760
  onMetadata: (e) => {
761
- e.sources && (d.sources = e.sources);
761
+ e.sources && (m.sources = e.sources);
762
+ },
763
+ onRateLimit: ({ limit: e, remaining: t, resetSeconds: n }) => {
764
+ S = {
765
+ limit: e,
766
+ remaining: t,
767
+ resetAt: Number.isFinite(n) ? (/* @__PURE__ */ new Date(n * 1e3)).toISOString() : ""
768
+ };
762
769
  },
763
770
  onThinkingChunk: (e) => {
764
- d.thinking += e;
771
+ m.thinking += e;
765
772
  }
766
773
  }, (e, t) => {
767
- if (e === "citations" && Array.isArray(t)) return d.citations = t, !0;
774
+ if (e === "citations" && Array.isArray(t)) return m.citations = t, !0;
768
775
  let n = t ?? {};
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;
770
- }), y) throw y;
771
- if (m.signal.aborted) {
772
- v.flush(), await h.complete(), d.isReceiving = !1, d.isStreaming = !1;
776
+ return e === "message_id" && typeof n.messageId == "string" ? (u.basecampMessageId = n.messageId, !0) : e === "assistant_message_id" && typeof n.messageId == "string" ? (m.basecampMessageId = n.messageId, !0) : e === "used_sources" && Array.isArray(t) ? (m.sources = t, !0) : e === "token_usage" && n.thread ? (l.value = n.thread, !0) : !1;
777
+ }), x) throw x;
778
+ if (h.signal.aborted) {
779
+ y.flush(), await _.complete(), m.isReceiving = !1, m.isStreaming = !1;
773
780
  return;
774
781
  }
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({
782
+ if (m.isReceiving = !1, await y.finish(), !m.text) throw Error("The response ended without any content.");
783
+ await _.complete(), m.isOutOfScope = e.isOutOfScope?.(m.text) ?? !1, m.isStreaming = !1, w({
777
784
  type: "turn",
778
785
  query: n,
779
786
  inputMode: i,
780
- response: d.text,
781
- isOutOfScope: d.isOutOfScope,
782
- citations: d.citations,
783
- sources: d.sources,
787
+ response: m.text,
788
+ isOutOfScope: m.isOutOfScope,
789
+ citations: m.citations,
790
+ sources: m.sources,
784
791
  threadId: a.value,
785
792
  userMessageId: u.basecampMessageId,
786
- assistantMessageId: d.basecampMessageId
793
+ assistantMessageId: m.basecampMessageId
787
794
  });
788
795
  } catch (t) {
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 }));
796
+ y.flush(), t?.name !== "AbortError" && (m.text ? m.failed = !0 : c.value = t instanceof Error ? t : Error(String(t))), _.stop(), m.isReceiving = !1, m.isStreaming = !1, m.text && (m.html = await W(m.text, { showMath: e.showMath }));
790
797
  } finally {
791
- v.destroy(), g = null, p.value = null, s.value = "idle", f();
798
+ y.destroy(), g = null, p.value = null, s.value = "idle", S ? d.value = S : f();
792
799
  }
793
800
  }
794
801
  async function A() {
@@ -1034,9 +1041,22 @@ var J = (e) => new Promise((t) => setTimeout(t, e)), et = class {
1034
1041
  } });
1035
1042
  return new Response(m, {
1036
1043
  status: 200,
1037
- headers: { "Content-Type": "text/event-stream" }
1044
+ headers: {
1045
+ "Content-Type": "text/event-stream",
1046
+ ...this.rateLimitHeaders()
1047
+ }
1038
1048
  });
1039
1049
  }
1050
+ rateLimitHeaders() {
1051
+ let e = this.options.messageLimit;
1052
+ if (e === void 0) return { "X-RateLimit-Limit": "unlimited" };
1053
+ let t = Math.ceil(this.messageCount / 2);
1054
+ return {
1055
+ "X-RateLimit-Limit": String(e),
1056
+ "X-RateLimit-Remaining": String(Math.max(0, e - t)),
1057
+ "X-RateLimit-Reset": String(Math.floor(new Date(this.quotaResetAt).getTime() / 1e3))
1058
+ };
1059
+ }
1040
1060
  async stopMessage() {
1041
1061
  return {
1042
1062
  success: !0,
@@ -1730,6 +1750,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1730
1750
  e.message.isOutOfScope ? (v(), a("div", Nn, [l(Z, { name: "warning" }), o("span", null, E(D(d).outOfScope.label), 1)])) : i("", !0),
1731
1751
  e.showThinking && e.message.thinking ? (v(), r(On, {
1732
1752
  key: 1,
1753
+ class: "assistant-message__reasoning",
1733
1754
  text: e.message.thinking
1734
1755
  }, null, 8, ["text"])) : i("", !0),
1735
1756
  o("div", Pn, [o("div", {
@@ -1771,7 +1792,7 @@ var Mt = { class: "citation-popover__source" }, Nt = ["src"], Pt = { class: "cit
1771
1792
  w(n.$slots, "message-footer", { message: e.message }, void 0, !0)
1772
1793
  ]));
1773
1794
  }
1774
- }), [["__scopeId", "data-v-466b7413"]]), Un = { class: "thinking" }, Wn = {
1795
+ }), [["__scopeId", "data-v-0cff2e6c"]]), Un = { class: "thinking" }, Wn = {
1775
1796
  key: 0,
1776
1797
  class: "thinking__label"
1777
1798
  }, Gn = 2e3, Kn = /*#__PURE__*/ Y(/* @__PURE__ */ u({