translation-chat-sdk 0.1.0 → 0.1.1
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/style.css +1 -1
- package/dist/translation-chat-sdk.cjs.js +1 -1
- package/dist/translation-chat-sdk.cjs.js.map +1 -1
- package/dist/translation-chat-sdk.es.js +50 -43
- package/dist/translation-chat-sdk.es.js.map +1 -1
- package/dist/translation-chat-sdk.umd.js +1 -1
- package/dist/translation-chat-sdk.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as g, jsxs as
|
|
1
|
+
import { jsx as g, jsxs as b, Fragment as Le } from "react/jsx-runtime";
|
|
2
2
|
import { createContext as De, useRef as X, useState as de, useMemo as U, useEffect as pe, useContext as Ie } from "react";
|
|
3
3
|
const S = /* @__PURE__ */ Object.create(null);
|
|
4
4
|
S.open = "0";
|
|
@@ -214,13 +214,13 @@ m.prototype.listeners = function(n) {
|
|
|
214
214
|
m.prototype.hasListeners = function(n) {
|
|
215
215
|
return !!this.listeners(n).length;
|
|
216
216
|
};
|
|
217
|
-
const $ = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0),
|
|
217
|
+
const $ = typeof Promise == "function" && typeof Promise.resolve == "function" ? (e) => Promise.resolve().then(e) : (e, t) => t(e, 0), E = typeof self < "u" ? self : typeof window < "u" ? window : Function("return this")(), Ye = "arraybuffer";
|
|
218
218
|
function be(n, ...e) {
|
|
219
219
|
return e.reduce((t, s) => (n.hasOwnProperty(s) && (t[s] = n[s]), t), {});
|
|
220
220
|
}
|
|
221
|
-
const ze =
|
|
221
|
+
const ze = E.setTimeout, Je = E.clearTimeout;
|
|
222
222
|
function W(n, e) {
|
|
223
|
-
e.useNativeTimers ? (n.setTimeoutFn = ze.bind(
|
|
223
|
+
e.useNativeTimers ? (n.setTimeoutFn = ze.bind(E), n.clearTimeoutFn = Je.bind(E)) : (n.setTimeoutFn = E.setTimeout.bind(E), n.clearTimeoutFn = E.clearTimeout.bind(E));
|
|
224
224
|
}
|
|
225
225
|
const Qe = 1.33;
|
|
226
226
|
function Xe(n) {
|
|
@@ -597,7 +597,7 @@ if (typeof document < "u") {
|
|
|
597
597
|
if (typeof attachEvent == "function")
|
|
598
598
|
attachEvent("onunload", fe);
|
|
599
599
|
else if (typeof addEventListener == "function") {
|
|
600
|
-
const n = "onpagehide" in
|
|
600
|
+
const n = "onpagehide" in E ? "pagehide" : "unload";
|
|
601
601
|
addEventListener(n, fe, !1);
|
|
602
602
|
}
|
|
603
603
|
}
|
|
@@ -630,7 +630,7 @@ function Te(n) {
|
|
|
630
630
|
}
|
|
631
631
|
if (!e)
|
|
632
632
|
try {
|
|
633
|
-
return new
|
|
633
|
+
return new E[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP");
|
|
634
634
|
} catch {
|
|
635
635
|
}
|
|
636
636
|
}
|
|
@@ -691,7 +691,7 @@ class ct extends re {
|
|
|
691
691
|
return this.opts.timestampRequests && (t[this.opts.timestampParam] = Ee()), this.supportsBinary || (t.b64 = 1), this.createUri(e, t);
|
|
692
692
|
}
|
|
693
693
|
}
|
|
694
|
-
const J =
|
|
694
|
+
const J = E.WebSocket || E.MozWebSocket;
|
|
695
695
|
class at extends ct {
|
|
696
696
|
createSocket(e, t, s) {
|
|
697
697
|
return Se ? new J(e, t, s) : t ? new J(e, t) : new J(e);
|
|
@@ -1445,7 +1445,7 @@ const Bt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
1445
1445
|
isPacketValid: Ot,
|
|
1446
1446
|
protocol: Tt
|
|
1447
1447
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
1448
|
-
function
|
|
1448
|
+
function v(n, e, t) {
|
|
1449
1449
|
return n.on(e, t), function() {
|
|
1450
1450
|
n.off(e, t);
|
|
1451
1451
|
};
|
|
@@ -1493,10 +1493,10 @@ class Re extends m {
|
|
|
1493
1493
|
return;
|
|
1494
1494
|
const e = this.io;
|
|
1495
1495
|
this.subs = [
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1496
|
+
v(e, "open", this.onopen.bind(this)),
|
|
1497
|
+
v(e, "packet", this.onpacket.bind(this)),
|
|
1498
|
+
v(e, "error", this.onerror.bind(this)),
|
|
1499
|
+
v(e, "close", this.onclose.bind(this))
|
|
1500
1500
|
];
|
|
1501
1501
|
}
|
|
1502
1502
|
/**
|
|
@@ -2128,11 +2128,11 @@ class se extends m {
|
|
|
2128
2128
|
this.engine = new mt(this.uri, this.opts);
|
|
2129
2129
|
const t = this.engine, s = this;
|
|
2130
2130
|
this._readyState = "opening", this.skipReconnect = !1;
|
|
2131
|
-
const i =
|
|
2131
|
+
const i = v(t, "open", function() {
|
|
2132
2132
|
s.onopen(), e && e();
|
|
2133
2133
|
}), r = (h) => {
|
|
2134
2134
|
this.cleanup(), this._readyState = "closed", this.emitReserved("error", h), e ? e(h) : this.maybeReconnectOnOpen();
|
|
2135
|
-
}, o =
|
|
2135
|
+
}, o = v(t, "error", r);
|
|
2136
2136
|
if (this._timeout !== !1) {
|
|
2137
2137
|
const h = this._timeout, l = this.setTimeoutFn(() => {
|
|
2138
2138
|
i(), r(new Error("timeout")), t.close();
|
|
@@ -2161,12 +2161,12 @@ class se extends m {
|
|
|
2161
2161
|
this.cleanup(), this._readyState = "open", this.emitReserved("open");
|
|
2162
2162
|
const e = this.engine;
|
|
2163
2163
|
this.subs.push(
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2164
|
+
v(e, "ping", this.onping.bind(this)),
|
|
2165
|
+
v(e, "data", this.ondata.bind(this)),
|
|
2166
|
+
v(e, "error", this.onerror.bind(this)),
|
|
2167
|
+
v(e, "close", this.onclose.bind(this)),
|
|
2168
2168
|
// @ts-ignore
|
|
2169
|
-
|
|
2169
|
+
v(this.decoder, "decoded", this.ondecoded.bind(this))
|
|
2170
2170
|
);
|
|
2171
2171
|
}
|
|
2172
2172
|
/**
|
|
@@ -2791,7 +2791,7 @@ function qt() {
|
|
|
2791
2791
|
function Ut() {
|
|
2792
2792
|
return qt();
|
|
2793
2793
|
}
|
|
2794
|
-
function $t({ title: n = "AI Assistance", placeholder: e = "Ask anything...", height: t = "
|
|
2794
|
+
function $t({ title: n = "AI Assistance", placeholder: e = "Ask anything...", height: t = "500px" }) {
|
|
2795
2795
|
const { messages: s, connection: i, submitInstruction: r, isSubmitting: o } = Ut(), [h, l] = de(""), c = X(null), f = !i.connected || o, d = U(
|
|
2796
2796
|
() => [...s].sort((y, x) => y.timestamp.getTime() - x.timestamp.getTime()),
|
|
2797
2797
|
[s]
|
|
@@ -2804,47 +2804,54 @@ function $t({ title: n = "AI Assistance", placeholder: e = "Ask anything...", he
|
|
|
2804
2804
|
const x = h.trim();
|
|
2805
2805
|
x && (await r(x), l(""));
|
|
2806
2806
|
};
|
|
2807
|
-
return /* @__PURE__ */
|
|
2808
|
-
/* @__PURE__ */
|
|
2807
|
+
return /* @__PURE__ */ b("div", { className: "chat-sdk", style: { height: t }, children: [
|
|
2808
|
+
/* @__PURE__ */ b("div", { className: "chat-sdk__header", children: [
|
|
2809
2809
|
/* @__PURE__ */ g("div", { className: "chat-sdk__title", children: n }),
|
|
2810
|
-
/* @__PURE__ */
|
|
2810
|
+
/* @__PURE__ */ b("div", { className: "chat-sdk__status", children: [
|
|
2811
2811
|
/* @__PURE__ */ g("span", { className: `chat-sdk__status-dot ${i.connected ? "connected" : "disconnected"}` }),
|
|
2812
2812
|
i.connected ? "Connected" : i.connecting ? "Connecting..." : "Disconnected"
|
|
2813
2813
|
] })
|
|
2814
|
-
] })
|
|
2815
|
-
/* @__PURE__ */ g("div", { className: "chat-sdk__messages", ref: c, children: d.length === 0 ? /* @__PURE__ */ g("div", { className: "chat-sdk__empty", children: "
|
|
2816
|
-
/* @__PURE__ */
|
|
2817
|
-
/* @__PURE__ */
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2814
|
+
] }),
|
|
2815
|
+
/* @__PURE__ */ g("div", { className: "chat-sdk__messages", ref: c, children: d.length === 0 ? /* @__PURE__ */ g("div", { className: "chat-sdk__empty", children: "Welcome! Ask anything about the translation." }) : d.map((y) => /* @__PURE__ */ g(Mt, { message: y }, y.id)) }),
|
|
2816
|
+
/* @__PURE__ */ b("div", { className: "chat-sdk__composer", children: [
|
|
2817
|
+
/* @__PURE__ */ b("form", { className: "chat-sdk__input-bar", onSubmit: _, children: [
|
|
2818
|
+
/* @__PURE__ */ g(
|
|
2819
|
+
"textarea",
|
|
2820
|
+
{
|
|
2821
|
+
className: "chat-sdk__input",
|
|
2822
|
+
placeholder: e,
|
|
2823
|
+
value: h,
|
|
2824
|
+
onChange: (y) => l(y.target.value),
|
|
2825
|
+
disabled: f,
|
|
2826
|
+
rows: 1
|
|
2827
|
+
}
|
|
2828
|
+
),
|
|
2829
|
+
/* @__PURE__ */ g("button", { className: "chat-sdk__send", type: "submit", disabled: !h.trim() || f, children: "Send" })
|
|
2830
|
+
] }),
|
|
2831
|
+
i.error && /* @__PURE__ */ b("div", { className: "chat-sdk__error", children: [
|
|
2832
|
+
"⚠️ ",
|
|
2833
|
+
i.error
|
|
2834
|
+
] })
|
|
2828
2835
|
] })
|
|
2829
2836
|
] });
|
|
2830
2837
|
}
|
|
2831
2838
|
function Mt({ message: n }) {
|
|
2832
2839
|
var i;
|
|
2833
2840
|
const e = n.type === "user", t = n.type === "loading", s = n.type === "ai-patch";
|
|
2834
|
-
return /* @__PURE__ */
|
|
2835
|
-
/* @__PURE__ */
|
|
2841
|
+
return /* @__PURE__ */ b("div", { className: `chat-sdk__bubble ${e ? "user" : "ai"}`, children: [
|
|
2842
|
+
/* @__PURE__ */ b("div", { className: "chat-sdk__bubble-meta", children: [
|
|
2836
2843
|
/* @__PURE__ */ g("span", { children: e ? "You" : s ? "Patch" : "Assistant" }),
|
|
2837
2844
|
/* @__PURE__ */ g("span", { children: n.timestamp.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) })
|
|
2838
2845
|
] }),
|
|
2839
|
-
/* @__PURE__ */ g("div", { className: `chat-sdk__bubble-body ${n.isStreaming ? "streaming" : ""}`, children: s && ((i = n.patchData) != null && i.originalText) ? /* @__PURE__ */
|
|
2846
|
+
/* @__PURE__ */ g("div", { className: `chat-sdk__bubble-body ${n.isStreaming ? "streaming" : ""}`, children: s && ((i = n.patchData) != null && i.originalText) ? /* @__PURE__ */ b("div", { className: "chat-sdk__patch", children: [
|
|
2840
2847
|
/* @__PURE__ */ g("div", { className: "chat-sdk__patch-label", children: "Original" }),
|
|
2841
2848
|
/* @__PURE__ */ g("div", { className: "chat-sdk__patch-block", children: n.patchData.originalText }),
|
|
2842
2849
|
/* @__PURE__ */ g("div", { className: "chat-sdk__patch-label", children: "Improved" }),
|
|
2843
|
-
/* @__PURE__ */
|
|
2850
|
+
/* @__PURE__ */ b("div", { className: "chat-sdk__patch-block", children: [
|
|
2844
2851
|
n.patchData.improvedText,
|
|
2845
2852
|
n.isStreaming && /* @__PURE__ */ g(Q, {})
|
|
2846
2853
|
] })
|
|
2847
|
-
] }) : /* @__PURE__ */
|
|
2854
|
+
] }) : /* @__PURE__ */ b(Le, { children: [
|
|
2848
2855
|
/* @__PURE__ */ g("div", { children: n.content }),
|
|
2849
2856
|
t && /* @__PURE__ */ g(Q, {}),
|
|
2850
2857
|
n.isStreaming && !t && /* @__PURE__ */ g(Q, {})
|
|
@@ -2853,7 +2860,7 @@ function Mt({ message: n }) {
|
|
|
2853
2860
|
] });
|
|
2854
2861
|
}
|
|
2855
2862
|
function Q() {
|
|
2856
|
-
return /* @__PURE__ */
|
|
2863
|
+
return /* @__PURE__ */ b("span", { className: "chat-sdk__stream", children: [
|
|
2857
2864
|
/* @__PURE__ */ g("span", {}),
|
|
2858
2865
|
/* @__PURE__ */ g("span", {}),
|
|
2859
2866
|
/* @__PURE__ */ g("span", {})
|