translation-chat-sdk 0.3.8 → 0.3.10
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 +88 -97
- 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,18 +1,18 @@
|
|
|
1
|
-
import { jsx as l, jsxs as
|
|
1
|
+
import { jsx as l, jsxs as E, Fragment as ve } from "react/jsx-runtime";
|
|
2
2
|
import { createContext as Me, useRef as X, useState as W, useMemo as V, useEffect as xe, useContext as Fe, forwardRef as He, useImperativeHandle as Ve } from "react";
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const L = /* @__PURE__ */ Object.create(null);
|
|
4
|
+
L.open = "0";
|
|
5
|
+
L.close = "1";
|
|
6
|
+
L.ping = "2";
|
|
7
|
+
L.pong = "3";
|
|
8
|
+
L.message = "4";
|
|
9
|
+
L.upgrade = "5";
|
|
10
|
+
L.noop = "6";
|
|
11
11
|
const Q = /* @__PURE__ */ Object.create(null);
|
|
12
|
-
Object.keys(
|
|
13
|
-
Q[
|
|
12
|
+
Object.keys(L).forEach((s) => {
|
|
13
|
+
Q[L[s]] = s;
|
|
14
14
|
});
|
|
15
|
-
const ie = { type: "error", data: "parser error" }, Ee = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", Te = typeof ArrayBuffer == "function", Re = (s) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(s) : s && s.buffer instanceof ArrayBuffer, ue = ({ type: s, data: e }, t, n) => Ee && e instanceof Blob ? t ? n(e) : me(e, n) : Te && (e instanceof ArrayBuffer || Re(e)) ? t ? n(e) : me(new Blob([e]), n) : n(
|
|
15
|
+
const ie = { type: "error", data: "parser error" }, Ee = typeof Blob == "function" || typeof Blob < "u" && Object.prototype.toString.call(Blob) === "[object BlobConstructor]", Te = typeof ArrayBuffer == "function", Re = (s) => typeof ArrayBuffer.isView == "function" ? ArrayBuffer.isView(s) : s && s.buffer instanceof ArrayBuffer, ue = ({ type: s, data: e }, t, n) => Ee && e instanceof Blob ? t ? n(e) : me(e, n) : Te && (e instanceof ArrayBuffer || Re(e)) ? t ? n(e) : me(new Blob([e]), n) : n(L[s] + (e || "")), me = (s, e) => {
|
|
16
16
|
const t = new FileReader();
|
|
17
17
|
return t.onload = function() {
|
|
18
18
|
const n = t.result.split(",")[1];
|
|
@@ -89,7 +89,7 @@ const ze = (s) => {
|
|
|
89
89
|
}
|
|
90
90
|
return n;
|
|
91
91
|
};
|
|
92
|
-
function
|
|
92
|
+
function Je() {
|
|
93
93
|
return new TransformStream({
|
|
94
94
|
transform(s, e) {
|
|
95
95
|
Ke(s, (t) => {
|
|
@@ -124,7 +124,7 @@ function z(s, e) {
|
|
|
124
124
|
t[r] = s[0][n++], n === s[0].length && (s.shift(), n = 0);
|
|
125
125
|
return s.length && n < s[0].length && (s[0] = s[0].slice(n)), t;
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function je(s, e) {
|
|
128
128
|
ne || (ne = new TextDecoder());
|
|
129
129
|
const t = [];
|
|
130
130
|
let n = 0, r = -1, i = !1;
|
|
@@ -444,12 +444,12 @@ class ct extends fe {
|
|
|
444
444
|
return this.opts.timestampRequests !== !1 && (t[this.opts.timestampParam] = Oe()), !this.supportsBinary && !t.sid && (t.b64 = 1), this.createUri(e, t);
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
|
-
let
|
|
447
|
+
let Pe = !1;
|
|
448
448
|
try {
|
|
449
|
-
|
|
449
|
+
Pe = typeof XMLHttpRequest < "u" && "withCredentials" in new XMLHttpRequest();
|
|
450
450
|
} catch {
|
|
451
451
|
}
|
|
452
|
-
const at =
|
|
452
|
+
const at = Pe;
|
|
453
453
|
function ht() {
|
|
454
454
|
}
|
|
455
455
|
class lt extends ct {
|
|
@@ -494,7 +494,7 @@ class lt extends ct {
|
|
|
494
494
|
}), this.pollXhr = e;
|
|
495
495
|
}
|
|
496
496
|
}
|
|
497
|
-
class
|
|
497
|
+
class P extends T {
|
|
498
498
|
/**
|
|
499
499
|
* Request constructor
|
|
500
500
|
*
|
|
@@ -548,7 +548,7 @@ class L extends T {
|
|
|
548
548
|
}, 0);
|
|
549
549
|
return;
|
|
550
550
|
}
|
|
551
|
-
typeof document < "u" && (this._index =
|
|
551
|
+
typeof document < "u" && (this._index = P.requestsCount++, P.requests[this._index] = this);
|
|
552
552
|
}
|
|
553
553
|
/**
|
|
554
554
|
* Called upon error.
|
|
@@ -570,7 +570,7 @@ class L extends T {
|
|
|
570
570
|
this._xhr.abort();
|
|
571
571
|
} catch {
|
|
572
572
|
}
|
|
573
|
-
typeof document < "u" && delete
|
|
573
|
+
typeof document < "u" && delete P.requests[this._index], this._xhr = null;
|
|
574
574
|
}
|
|
575
575
|
}
|
|
576
576
|
/**
|
|
@@ -591,8 +591,8 @@ class L extends T {
|
|
|
591
591
|
this._cleanup();
|
|
592
592
|
}
|
|
593
593
|
}
|
|
594
|
-
|
|
595
|
-
|
|
594
|
+
P.requestsCount = 0;
|
|
595
|
+
P.requests = {};
|
|
596
596
|
if (typeof document < "u") {
|
|
597
597
|
if (typeof attachEvent == "function")
|
|
598
598
|
attachEvent("onunload", be);
|
|
@@ -602,11 +602,11 @@ if (typeof document < "u") {
|
|
|
602
602
|
}
|
|
603
603
|
}
|
|
604
604
|
function be() {
|
|
605
|
-
for (let s in
|
|
606
|
-
|
|
605
|
+
for (let s in P.requests)
|
|
606
|
+
P.requests.hasOwnProperty(s) && P.requests[s].abort();
|
|
607
607
|
}
|
|
608
608
|
const ut = function() {
|
|
609
|
-
const s =
|
|
609
|
+
const s = Le({
|
|
610
610
|
xdomain: !1
|
|
611
611
|
});
|
|
612
612
|
return s && s.responseType !== null;
|
|
@@ -618,10 +618,10 @@ class dt extends lt {
|
|
|
618
618
|
this.supportsBinary = ut && !t;
|
|
619
619
|
}
|
|
620
620
|
request(e = {}) {
|
|
621
|
-
return Object.assign(e, { xd: this.xd }, this.opts), new
|
|
621
|
+
return Object.assign(e, { xd: this.xd }, this.opts), new P(Le, this.uri(), e);
|
|
622
622
|
}
|
|
623
623
|
}
|
|
624
|
-
function
|
|
624
|
+
function Le(s) {
|
|
625
625
|
const e = s.xdomain;
|
|
626
626
|
try {
|
|
627
627
|
if (typeof XMLHttpRequest < "u" && (!e || at))
|
|
@@ -716,7 +716,7 @@ class gt extends fe {
|
|
|
716
716
|
this.onError("webtransport error", e);
|
|
717
717
|
}), this._transport.ready.then(() => {
|
|
718
718
|
this._transport.createBidirectionalStream().then((e) => {
|
|
719
|
-
const t =
|
|
719
|
+
const t = je(Number.MAX_SAFE_INTEGER, this.socket.binaryType), n = e.readable.pipeThrough(t).getReader(), r = Je();
|
|
720
720
|
r.readable.pipeTo(e.writable), this._writer = r.writable.getWriter();
|
|
721
721
|
const i = () => {
|
|
722
722
|
n.read().then(({ done: c, value: u }) => {
|
|
@@ -1149,21 +1149,21 @@ const Et = typeof ArrayBuffer == "function", Tt = (s) => typeof ArrayBuffer.isVi
|
|
|
1149
1149
|
function pe(s) {
|
|
1150
1150
|
return Et && (s instanceof ArrayBuffer || Tt(s)) || Rt && s instanceof Blob || St && s instanceof File;
|
|
1151
1151
|
}
|
|
1152
|
-
function
|
|
1152
|
+
function J(s, e) {
|
|
1153
1153
|
if (!s || typeof s != "object")
|
|
1154
1154
|
return !1;
|
|
1155
1155
|
if (Array.isArray(s)) {
|
|
1156
1156
|
for (let t = 0, n = s.length; t < n; t++)
|
|
1157
|
-
if (
|
|
1157
|
+
if (J(s[t]))
|
|
1158
1158
|
return !0;
|
|
1159
1159
|
return !1;
|
|
1160
1160
|
}
|
|
1161
1161
|
if (pe(s))
|
|
1162
1162
|
return !0;
|
|
1163
1163
|
if (s.toJSON && typeof s.toJSON == "function" && arguments.length === 1)
|
|
1164
|
-
return
|
|
1164
|
+
return J(s.toJSON(), !0);
|
|
1165
1165
|
for (const t in s)
|
|
1166
|
-
if (Object.prototype.hasOwnProperty.call(s, t) &&
|
|
1166
|
+
if (Object.prototype.hasOwnProperty.call(s, t) && J(s[t]))
|
|
1167
1167
|
return !0;
|
|
1168
1168
|
return !1;
|
|
1169
1169
|
}
|
|
@@ -1242,7 +1242,7 @@ class Ot {
|
|
|
1242
1242
|
* @param {Object} obj - packet object
|
|
1243
1243
|
*/
|
|
1244
1244
|
encode(e) {
|
|
1245
|
-
return (e.type === _.EVENT || e.type === _.ACK) &&
|
|
1245
|
+
return (e.type === _.EVENT || e.type === _.ACK) && J(e) ? this.encodeAsBinary({
|
|
1246
1246
|
type: e.type === _.EVENT ? _.BINARY_EVENT : _.BINARY_ACK,
|
|
1247
1247
|
nsp: e.nsp,
|
|
1248
1248
|
data: e.data,
|
|
@@ -1287,7 +1287,7 @@ class ge extends T {
|
|
|
1287
1287
|
throw new Error("got plaintext data when reconstructing a packet");
|
|
1288
1288
|
t = this.decodeString(e);
|
|
1289
1289
|
const n = t.type === _.BINARY_EVENT;
|
|
1290
|
-
n || t.type === _.BINARY_ACK ? (t.type = n ? _.EVENT : _.ACK, this.reconstructor = new
|
|
1290
|
+
n || t.type === _.BINARY_ACK ? (t.type = n ? _.EVENT : _.ACK, this.reconstructor = new Pt(t), t.attachments === 0 && super.emitReserved("decoded", t)) : super.emitReserved("decoded", t);
|
|
1291
1291
|
} else if (pe(e) || e.base64)
|
|
1292
1292
|
if (this.reconstructor)
|
|
1293
1293
|
t = this.reconstructor.takeBinaryData(e), t && (this.reconstructor = null, super.emitReserved("decoded", t));
|
|
@@ -1378,7 +1378,7 @@ class ge extends T {
|
|
|
1378
1378
|
this.reconstructor && (this.reconstructor.finishedReconstruction(), this.reconstructor = null);
|
|
1379
1379
|
}
|
|
1380
1380
|
}
|
|
1381
|
-
class
|
|
1381
|
+
class Pt {
|
|
1382
1382
|
constructor(e) {
|
|
1383
1383
|
this.packet = e, this.buffers = [], this.reconPack = e;
|
|
1384
1384
|
}
|
|
@@ -1404,7 +1404,7 @@ class Lt {
|
|
|
1404
1404
|
this.reconPack = null, this.buffers = [];
|
|
1405
1405
|
}
|
|
1406
1406
|
}
|
|
1407
|
-
function
|
|
1407
|
+
function Lt(s) {
|
|
1408
1408
|
return typeof s == "string";
|
|
1409
1409
|
}
|
|
1410
1410
|
const Bt = Number.isInteger || function(s) {
|
|
@@ -1433,7 +1433,7 @@ function It(s, e) {
|
|
|
1433
1433
|
}
|
|
1434
1434
|
}
|
|
1435
1435
|
function Ut(s) {
|
|
1436
|
-
return
|
|
1436
|
+
return Lt(s.nsp) && Dt(s.id) && It(s.type, s.data);
|
|
1437
1437
|
}
|
|
1438
1438
|
const qt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
1439
1439
|
__proto__: null,
|
|
@@ -2313,17 +2313,17 @@ class le extends T {
|
|
|
2313
2313
|
}
|
|
2314
2314
|
}
|
|
2315
2315
|
const F = {};
|
|
2316
|
-
function
|
|
2316
|
+
function j(s, e) {
|
|
2317
2317
|
typeof s == "object" && (e = s, s = void 0), e = e || {};
|
|
2318
2318
|
const t = xt(s, e.path || "/socket.io"), n = t.source, r = t.id, i = t.path, o = F[r] && i in F[r].nsps, c = e.forceNew || e["force new connection"] || e.multiplex === !1 || o;
|
|
2319
2319
|
let u;
|
|
2320
2320
|
return c ? u = new le(n, e) : (F[r] || (F[r] = new le(n, e)), u = F[r]), t.query && !e.query && (e.query = t.queryKey), u.socket(t.path, e);
|
|
2321
2321
|
}
|
|
2322
|
-
Object.assign(
|
|
2322
|
+
Object.assign(j, {
|
|
2323
2323
|
Manager: le,
|
|
2324
2324
|
Socket: Ue,
|
|
2325
|
-
io:
|
|
2326
|
-
connect:
|
|
2325
|
+
io: j,
|
|
2326
|
+
connect: j
|
|
2327
2327
|
});
|
|
2328
2328
|
function N() {
|
|
2329
2329
|
return `${Date.now().toString(36)}-${Math.random().toString(16).slice(2, 8)}`;
|
|
@@ -2372,7 +2372,7 @@ class Ft {
|
|
|
2372
2372
|
var i;
|
|
2373
2373
|
if ((i = this.socket) != null && i.connected) return;
|
|
2374
2374
|
const e = new URL(this.config.websocketUrl), t = e.pathname === "/" ? "/socket.io" : e.pathname, n = e.origin, r = await this.getToken();
|
|
2375
|
-
return this.socket =
|
|
2375
|
+
return this.socket = j(n, {
|
|
2376
2376
|
path: t,
|
|
2377
2377
|
transports: ["websocket", "polling"],
|
|
2378
2378
|
autoConnect: !1,
|
|
@@ -2625,7 +2625,7 @@ function Ht(s) {
|
|
|
2625
2625
|
}).flat().sort((e, t) => e.timestamp.getTime() - t.timestamp.getTime());
|
|
2626
2626
|
}
|
|
2627
2627
|
const qe = Me(null), Vt = { connected: !1, connecting: !1 };
|
|
2628
|
-
function
|
|
2628
|
+
function tn({ config: s, children: e }) {
|
|
2629
2629
|
const t = X(null), n = X(/* @__PURE__ */ new Map()), [r, i] = W({
|
|
2630
2630
|
messages: [],
|
|
2631
2631
|
connection: Vt,
|
|
@@ -2756,7 +2756,7 @@ function nn({ config: s, children: e }) {
|
|
|
2756
2756
|
}
|
|
2757
2757
|
]
|
|
2758
2758
|
}));
|
|
2759
|
-
}),
|
|
2759
|
+
}), x = h.on("page-translation-response", (a) => {
|
|
2760
2760
|
var p, w, v, R, m, k, S, U;
|
|
2761
2761
|
(w = (p = o.logger) == null ? void 0 : p.log) == null || w.call(p, "[chat-sdk][ChatProvider] Received page-translation-response event:", {
|
|
2762
2762
|
trans_doc_id: a.trans_doc_id,
|
|
@@ -2814,7 +2814,7 @@ function nn({ config: s, children: e }) {
|
|
|
2814
2814
|
var p, w;
|
|
2815
2815
|
return (w = (p = o.logger) == null ? void 0 : p.warn) == null ? void 0 : w.call(p, "chat-sdk connect failed", a);
|
|
2816
2816
|
}), () => {
|
|
2817
|
-
d(), f(), g(), y(), b(),
|
|
2817
|
+
d(), f(), g(), y(), b(), x(), B(), A(), D(), h.disconnect();
|
|
2818
2818
|
};
|
|
2819
2819
|
}, [o]);
|
|
2820
2820
|
const c = V(
|
|
@@ -2887,10 +2887,10 @@ function nn({ config: s, children: e }) {
|
|
|
2887
2887
|
await h.requestChatHistory(d);
|
|
2888
2888
|
},
|
|
2889
2889
|
async sendPatchDecision(h, d, f, g, y) {
|
|
2890
|
-
var
|
|
2890
|
+
var x, B, A, D;
|
|
2891
2891
|
const b = t.current;
|
|
2892
2892
|
if (!b) throw new Error("SDK not ready");
|
|
2893
|
-
(B = (
|
|
2893
|
+
(B = (x = o.logger) == null ? void 0 : x.log) == null || B.call(x, "[chat-sdk][ChatProvider] sendPatchDecision called:", {
|
|
2894
2894
|
trans_doc_id: h,
|
|
2895
2895
|
page_num: d,
|
|
2896
2896
|
instruction_id: f,
|
|
@@ -2899,22 +2899,22 @@ function nn({ config: s, children: e }) {
|
|
|
2899
2899
|
}), await b.sendPatchDecision({ trans_doc_id: h, page_num: d, instruction_id: f, decision: g, remember_this: y }), (D = (A = o.logger) == null ? void 0 : A.log) == null || D.call(A, "[chat-sdk][ChatProvider] sendPatchDecision completed"), i((a) => ({ ...a, latestPatchOffer: null }));
|
|
2900
2900
|
},
|
|
2901
2901
|
async requestPageTranslation(h, d) {
|
|
2902
|
-
var g, y, b,
|
|
2902
|
+
var g, y, b, x;
|
|
2903
2903
|
const f = t.current;
|
|
2904
2904
|
if (!f) throw new Error("SDK not ready");
|
|
2905
2905
|
return (y = (g = o.logger) == null ? void 0 : g.log) == null || y.call(g, "[chat-sdk][ChatProvider] requestPageTranslation called:", {
|
|
2906
2906
|
trans_doc_id: h,
|
|
2907
2907
|
page_num: d
|
|
2908
|
-
}), await f.requestPageTranslation({ trans_doc_id: h, page_num: d }), (
|
|
2908
|
+
}), await f.requestPageTranslation({ trans_doc_id: h, page_num: d }), (x = (b = o.logger) == null ? void 0 : b.log) == null || x.call(b, "[chat-sdk][ChatProvider] requestPageTranslation request sent"), !0;
|
|
2909
2909
|
},
|
|
2910
2910
|
async requestBulkTranslation(h, d) {
|
|
2911
|
-
var g, y, b,
|
|
2911
|
+
var g, y, b, x;
|
|
2912
2912
|
const f = t.current;
|
|
2913
2913
|
if (!f) throw new Error("SDK not ready");
|
|
2914
2914
|
return (y = (g = o.logger) == null ? void 0 : g.log) == null || y.call(g, "[chat-sdk][ChatProvider] requestBulkTranslation called:", {
|
|
2915
2915
|
trans_doc_id: h,
|
|
2916
2916
|
page_list: d
|
|
2917
|
-
}), await f.requestBulkTranslation({ trans_doc_id: h, page_list: d }), (
|
|
2917
|
+
}), await f.requestBulkTranslation({ trans_doc_id: h, page_list: d }), (x = (b = o.logger) == null ? void 0 : b.log) == null || x.call(b, "[chat-sdk][ChatProvider] requestBulkTranslation request sent"), !0;
|
|
2918
2918
|
},
|
|
2919
2919
|
async cancelBulkTranslation(h) {
|
|
2920
2920
|
var f, g, y, b;
|
|
@@ -2933,13 +2933,13 @@ function nn({ config: s, children: e }) {
|
|
|
2933
2933
|
}), await d.requestLearnedRules(h), (b = (y = o.logger) == null ? void 0 : y.log) == null || b.call(y, "[chat-sdk][ChatProvider] requestLearnedRules request sent");
|
|
2934
2934
|
},
|
|
2935
2935
|
async updateRules(h, d) {
|
|
2936
|
-
var g, y, b,
|
|
2936
|
+
var g, y, b, x;
|
|
2937
2937
|
const f = t.current;
|
|
2938
2938
|
if (!f) throw new Error("SDK not ready");
|
|
2939
2939
|
(y = (g = o.logger) == null ? void 0 : g.log) == null || y.call(g, "[chat-sdk][ChatProvider] updateRules called:", {
|
|
2940
2940
|
trans_doc_id: h,
|
|
2941
2941
|
rules_text_length: d.length
|
|
2942
|
-
}), await f.updateRules(h, d), (
|
|
2942
|
+
}), await f.updateRules(h, d), (x = (b = o.logger) == null ? void 0 : b.log) == null || x.call(b, "[chat-sdk][ChatProvider] updateRules request sent");
|
|
2943
2943
|
},
|
|
2944
2944
|
clearMessages() {
|
|
2945
2945
|
i((h) => ({ ...h, messages: [] }));
|
|
@@ -2969,7 +2969,7 @@ function zt() {
|
|
|
2969
2969
|
}
|
|
2970
2970
|
const $t = He(
|
|
2971
2971
|
({ title: s = "AI Assistance", placeholder: e = "Ask anything...", height: t = "500px", onClose: n }, r) => {
|
|
2972
|
-
const { messages: i, connection: o, submitInstruction: c, submitInstructionWithContext: u, isSubmitting: h, clearSelection: d } = zt(), [f, g] = W(""), [y, b] = W(null), [
|
|
2972
|
+
const { messages: i, connection: o, submitInstruction: c, submitInstructionWithContext: u, isSubmitting: h, clearSelection: d } = zt(), [f, g] = W(""), [y, b] = W(null), [x, B] = W(null), A = X(null), D = X(null), a = !o.connected || h;
|
|
2973
2973
|
Ve(r, () => ({
|
|
2974
2974
|
setContext: ({ text: m, context: k }) => {
|
|
2975
2975
|
B(m), b(k), setTimeout(() => {
|
|
@@ -2998,24 +2998,24 @@ const $t = He(
|
|
|
2998
2998
|
}, R = () => {
|
|
2999
2999
|
b(null), B(null), d();
|
|
3000
3000
|
};
|
|
3001
|
-
return /* @__PURE__ */
|
|
3002
|
-
/* @__PURE__ */
|
|
3001
|
+
return /* @__PURE__ */ E("div", { className: "chat-sdk", style: { height: t }, children: [
|
|
3002
|
+
/* @__PURE__ */ E("div", { className: "chat-sdk__header", children: [
|
|
3003
3003
|
/* @__PURE__ */ l("div", { className: "chat-sdk__title", children: s }),
|
|
3004
3004
|
n && /* @__PURE__ */ l("button", { type: "button", onClick: n, className: "chat-sdk__close-btn", children: /* @__PURE__ */ l(Qt, {}) })
|
|
3005
3005
|
] }),
|
|
3006
3006
|
/* @__PURE__ */ l("div", { className: "chat-sdk__messages", ref: A, children: p.length === 0 ? /* @__PURE__ */ l("div", { className: "chat-sdk__empty", children: "Welcome! Ask anything about the translation." }) : p.map((m) => /* @__PURE__ */ l(Wt, { message: m }, m.id)) }),
|
|
3007
|
-
/* @__PURE__ */
|
|
3008
|
-
/* @__PURE__ */
|
|
3009
|
-
|
|
3010
|
-
/* @__PURE__ */ l("span", { className: "chat-sdk__context-text", children:
|
|
3011
|
-
/* @__PURE__ */ l("button", { type: "button", onClick: R, className: "chat-sdk__context-clear", children: /* @__PURE__ */ l(
|
|
3007
|
+
/* @__PURE__ */ E("div", { className: "chat-sdk__composer", children: [
|
|
3008
|
+
/* @__PURE__ */ E("form", { className: "chat-sdk__input-bar", onSubmit: w, children: [
|
|
3009
|
+
x && /* @__PURE__ */ l("div", { className: "chat-sdk__input-context", children: /* @__PURE__ */ E("div", { className: "chat-sdk__context-chip", children: [
|
|
3010
|
+
/* @__PURE__ */ l("span", { className: "chat-sdk__context-text", children: x.length > 40 ? `${x.slice(0, 40)}…` : x }),
|
|
3011
|
+
/* @__PURE__ */ l("button", { type: "button", onClick: R, className: "chat-sdk__context-clear", children: /* @__PURE__ */ l(Xt, {}) })
|
|
3012
3012
|
] }) }),
|
|
3013
3013
|
/* @__PURE__ */ l(
|
|
3014
3014
|
"textarea",
|
|
3015
3015
|
{
|
|
3016
3016
|
ref: D,
|
|
3017
3017
|
className: "chat-sdk__input",
|
|
3018
|
-
placeholder:
|
|
3018
|
+
placeholder: x ? "What would you like to change?" : e,
|
|
3019
3019
|
value: f,
|
|
3020
3020
|
onChange: (m) => g(m.target.value),
|
|
3021
3021
|
onKeyDown: v,
|
|
@@ -3023,12 +3023,9 @@ const $t = He(
|
|
|
3023
3023
|
rows: 1
|
|
3024
3024
|
}
|
|
3025
3025
|
),
|
|
3026
|
-
/* @__PURE__ */
|
|
3027
|
-
/* @__PURE__ */ l("div", { className: "chat-sdk__actions-left", children: /* @__PURE__ */ l("button", { type: "button", className: "chat-sdk__add-btn", disabled: a, children: /* @__PURE__ */ l(Xt, {}) }) }),
|
|
3028
|
-
/* @__PURE__ */ l("button", { className: "chat-sdk__send", type: "submit", disabled: !f.trim() || a, children: /* @__PURE__ */ l(Jt, {}) })
|
|
3029
|
-
] })
|
|
3026
|
+
/* @__PURE__ */ l("div", { className: "chat-sdk__actions", children: /* @__PURE__ */ l("button", { className: "chat-sdk__send", type: "submit", disabled: !f.trim() || a, children: /* @__PURE__ */ l(jt, {}) }) })
|
|
3030
3027
|
] }),
|
|
3031
|
-
o.error && /* @__PURE__ */
|
|
3028
|
+
o.error && /* @__PURE__ */ E("div", { className: "chat-sdk__error", children: [
|
|
3032
3029
|
"⚠️ ",
|
|
3033
3030
|
o.error
|
|
3034
3031
|
] })
|
|
@@ -3041,11 +3038,11 @@ function Wt({ message: s }) {
|
|
|
3041
3038
|
var i;
|
|
3042
3039
|
const e = s.type === "user", t = s.type === "loading", n = s.type === "ai-patch", r = s.type === "rule-learned";
|
|
3043
3040
|
if (e)
|
|
3044
|
-
return /* @__PURE__ */
|
|
3041
|
+
return /* @__PURE__ */ E("div", { className: "chat-sdk__user-container", children: [
|
|
3045
3042
|
s.contextText && /* @__PURE__ */ l("div", { className: "chat-sdk__user-context", children: /* @__PURE__ */ l("div", { className: "chat-sdk__context-chip", children: /* @__PURE__ */ l("span", { className: "chat-sdk__context-text", children: s.contextText.length > 40 ? `${s.contextText.slice(0, 40)}…` : s.contextText }) }) }),
|
|
3046
3043
|
/* @__PURE__ */ l("div", { className: "chat-sdk__bubble user", children: /* @__PURE__ */ l("div", { className: "chat-sdk__bubble-body", children: s.content }) }),
|
|
3047
|
-
/* @__PURE__ */
|
|
3048
|
-
s.pageNum !== void 0 && /* @__PURE__ */
|
|
3044
|
+
/* @__PURE__ */ E("div", { className: "chat-sdk__bubble-meta", children: [
|
|
3045
|
+
s.pageNum !== void 0 && /* @__PURE__ */ E("span", { children: [
|
|
3049
3046
|
"Page ",
|
|
3050
3047
|
s.pageNum
|
|
3051
3048
|
] }),
|
|
@@ -3055,10 +3052,10 @@ function Wt({ message: s }) {
|
|
|
3055
3052
|
] });
|
|
3056
3053
|
if (r) {
|
|
3057
3054
|
const o = s.ruleSummary || s.content, c = o.charAt(0).toUpperCase() + o.slice(1);
|
|
3058
|
-
return /* @__PURE__ */
|
|
3059
|
-
/* @__PURE__ */
|
|
3055
|
+
return /* @__PURE__ */ E("div", { className: "chat-sdk__rule-learned-container", children: [
|
|
3056
|
+
/* @__PURE__ */ E("div", { className: "chat-sdk__rule-learned", children: [
|
|
3060
3057
|
/* @__PURE__ */ l("div", { className: "chat-sdk__rule-learned-icon", children: /* @__PURE__ */ l(Yt, {}) }),
|
|
3061
|
-
/* @__PURE__ */
|
|
3058
|
+
/* @__PURE__ */ E("div", { className: "chat-sdk__rule-learned-body", children: [
|
|
3062
3059
|
/* @__PURE__ */ l("span", { className: "chat-sdk__rule-learned-title", children: "Memory updated" }),
|
|
3063
3060
|
/* @__PURE__ */ l("span", { className: "chat-sdk__rule-learned-text", children: c })
|
|
3064
3061
|
] })
|
|
@@ -3066,17 +3063,17 @@ function Wt({ message: s }) {
|
|
|
3066
3063
|
/* @__PURE__ */ l("div", { className: "chat-sdk__rule-learned-meta", children: we(s.timestamp) })
|
|
3067
3064
|
] });
|
|
3068
3065
|
}
|
|
3069
|
-
return /* @__PURE__ */ l("div", { className: `chat-sdk__bubble ${n ? "ai-patch" : "ai"}`, children: /* @__PURE__ */
|
|
3070
|
-
n && /* @__PURE__ */ l("div", { className: "chat-sdk__suggestion-text", children: /* @__PURE__ */ l(
|
|
3071
|
-
n && ((i = s.patchData) != null && i.originalText) ? /* @__PURE__ */
|
|
3072
|
-
/* @__PURE__ */ l("div", { className: "chat-sdk__patch-label", children: "Original" }),
|
|
3073
|
-
/* @__PURE__ */ l("div", { className: "chat-sdk__patch-block", children: s.patchData.originalText }),
|
|
3074
|
-
/* @__PURE__ */ l("div", { className: "chat-sdk__patch-label", children: "
|
|
3075
|
-
/* @__PURE__ */
|
|
3066
|
+
return /* @__PURE__ */ l("div", { className: `chat-sdk__bubble ${n ? "ai-patch" : "ai"}`, children: /* @__PURE__ */ E("div", { className: `chat-sdk__bubble-body ${s.isStreaming ? "streaming" : ""}`, children: [
|
|
3067
|
+
n && /* @__PURE__ */ l("div", { className: "chat-sdk__suggestion-text", children: /* @__PURE__ */ l(Jt, { instructionId: s.instructionId }) }),
|
|
3068
|
+
n && ((i = s.patchData) != null && i.originalText) ? /* @__PURE__ */ E("div", { className: "chat-sdk__patch", children: [
|
|
3069
|
+
/* @__PURE__ */ l("div", { className: "chat-sdk__patch-label chat-sdk__patch-label--original", children: "Original" }),
|
|
3070
|
+
/* @__PURE__ */ l("div", { className: "chat-sdk__patch-block chat-sdk__patch-block--original", children: s.patchData.originalText }),
|
|
3071
|
+
/* @__PURE__ */ l("div", { className: "chat-sdk__patch-label chat-sdk__patch-label--improved", children: "Suggested" }),
|
|
3072
|
+
/* @__PURE__ */ E("div", { className: "chat-sdk__patch-block chat-sdk__patch-block--improved", children: [
|
|
3076
3073
|
s.patchData.improvedText,
|
|
3077
3074
|
s.isStreaming && /* @__PURE__ */ l(re, {})
|
|
3078
3075
|
] })
|
|
3079
|
-
] }) : /* @__PURE__ */
|
|
3076
|
+
] }) : /* @__PURE__ */ E(ve, { children: [
|
|
3080
3077
|
/* @__PURE__ */ l("div", { children: s.content }),
|
|
3081
3078
|
t && /* @__PURE__ */ l(re, {}),
|
|
3082
3079
|
s.isStreaming && !t && /* @__PURE__ */ l(re, {})
|
|
@@ -3084,14 +3081,14 @@ function Wt({ message: s }) {
|
|
|
3084
3081
|
] }) });
|
|
3085
3082
|
}
|
|
3086
3083
|
function Qt() {
|
|
3087
|
-
return /* @__PURE__ */
|
|
3084
|
+
return /* @__PURE__ */ E("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
3088
3085
|
/* @__PURE__ */ l("circle", { cx: "12", cy: "12", r: "10" }),
|
|
3089
3086
|
/* @__PURE__ */ l("path", { d: "m15 9-6 6" }),
|
|
3090
3087
|
/* @__PURE__ */ l("path", { d: "m9 9 6 6" })
|
|
3091
3088
|
] });
|
|
3092
3089
|
}
|
|
3093
3090
|
function Yt() {
|
|
3094
|
-
return /* @__PURE__ */
|
|
3091
|
+
return /* @__PURE__ */ E("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
3095
3092
|
/* @__PURE__ */ l("path", { d: "M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z" }),
|
|
3096
3093
|
/* @__PURE__ */ l("path", { d: "M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z" }),
|
|
3097
3094
|
/* @__PURE__ */ l("path", { d: "M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4" }),
|
|
@@ -3123,7 +3120,7 @@ const $ = [
|
|
|
3123
3120
|
"Here is something you might like",
|
|
3124
3121
|
"How about this?"
|
|
3125
3122
|
];
|
|
3126
|
-
function
|
|
3123
|
+
function Jt({ instructionId: s }) {
|
|
3127
3124
|
const e = V(() => {
|
|
3128
3125
|
if (s) {
|
|
3129
3126
|
let t = 0;
|
|
@@ -3135,36 +3132,30 @@ function jt({ instructionId: s }) {
|
|
|
3135
3132
|
}, [s]);
|
|
3136
3133
|
return /* @__PURE__ */ l(ve, { children: $[e] });
|
|
3137
3134
|
}
|
|
3138
|
-
function
|
|
3139
|
-
return /* @__PURE__ */
|
|
3135
|
+
function jt() {
|
|
3136
|
+
return /* @__PURE__ */ E("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
3140
3137
|
/* @__PURE__ */ l("line", { x1: "12", y1: "19", x2: "12", y2: "5" }),
|
|
3141
3138
|
/* @__PURE__ */ l("polyline", { points: "5 12 12 5 19 12" })
|
|
3142
3139
|
] });
|
|
3143
3140
|
}
|
|
3144
3141
|
function Xt() {
|
|
3145
|
-
return /* @__PURE__ */
|
|
3146
|
-
/* @__PURE__ */ l("line", { x1: "12", y1: "5", x2: "12", y2: "19" }),
|
|
3147
|
-
/* @__PURE__ */ l("line", { x1: "5", y1: "12", x2: "19", y2: "12" })
|
|
3148
|
-
] });
|
|
3149
|
-
}
|
|
3150
|
-
function Gt() {
|
|
3151
|
-
return /* @__PURE__ */ x("svg", { width: "10", height: "10", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
3142
|
+
return /* @__PURE__ */ E("svg", { width: "10", height: "10", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2.5", strokeLinecap: "round", strokeLinejoin: "round", children: [
|
|
3152
3143
|
/* @__PURE__ */ l("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
3153
3144
|
/* @__PURE__ */ l("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
3154
3145
|
] });
|
|
3155
3146
|
}
|
|
3156
3147
|
function re() {
|
|
3157
|
-
return /* @__PURE__ */
|
|
3148
|
+
return /* @__PURE__ */ E("span", { className: "chat-sdk__stream", children: [
|
|
3158
3149
|
/* @__PURE__ */ l("span", {}),
|
|
3159
3150
|
/* @__PURE__ */ l("span", {}),
|
|
3160
3151
|
/* @__PURE__ */ l("span", {})
|
|
3161
3152
|
] });
|
|
3162
3153
|
}
|
|
3163
|
-
const
|
|
3154
|
+
const nn = ".chat-sdk{--radius-full: 9999px;--radius-large: 20px;--radius-medium: 12px;--spacing-1: 8px;--spacing-2: 16px;--space-20: 20px;--background-primary: #ffffff;--background-secondary: #f5f5f5;--background-tertiary: #f0f0f0;--surface-secondary: #ffffff;--content-primary: #141414;--content-secondary: #666666;--content-tertiary: #999999;--border-secondary: #e6e6e6;--background-brand1-primary: #e8effc;--content-brand1-secondary: #212191;--background-black: #141414;display:flex;flex-direction:column;background:var(--background-primary);border:1px solid var(--border-secondary);border-radius:var(--radius-large);box-shadow:0 8px 30px #0000000f;font-family:Matter,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;overflow:hidden}.chat-sdk__header{padding:14px 20px;display:flex;align-items:center;justify-content:space-between;background:var(--surface-secondary);border-bottom:1px solid var(--border-secondary)}.chat-sdk__title{font-weight:600;font-size:16px;color:var(--content-primary)}.chat-sdk__close-btn{display:flex;align-items:center;justify-content:center;width:20px;height:20px;padding:0;background:transparent;border:none;color:#131313;cursor:pointer;transition:opacity .15s}.chat-sdk__close-btn:hover{opacity:.7}.chat-sdk__messages{flex:1;padding:var(--space-20) 24px;display:flex;flex-direction:column;gap:24px;overflow-y:auto}.chat-sdk__empty{text-align:center;color:var(--content-secondary);font-size:14px;padding:16px}.chat-sdk__user-container{display:flex;flex-direction:column;align-items:flex-end;gap:8px}.chat-sdk__user-context{display:flex;justify-content:flex-end}.chat-sdk__context-chip{background:var(--background-tertiary);padding:8px 12px;border-radius:var(--radius-full);display:inline-flex;align-items:center;gap:8px;max-width:100%}.chat-sdk__context-text{font-size:14px;line-height:1.45;color:var(--content-primary);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:280px}.chat-sdk__bubble.user{background:var(--background-brand1-primary);padding:10px;border-radius:var(--radius-medium);max-width:85%;border:none;color:var(--content-brand1-secondary)}.chat-sdk__bubble-meta{display:flex;align-items:center;justify-content:flex-end;gap:5px;font-size:12px;color:var(--content-tertiary);margin-top:4px}.chat-sdk__meta-dot{font-size:6px}.chat-sdk__bubble.user .chat-sdk__bubble-body{color:var(--content-brand1-secondary);font-size:15px;line-height:1.45;white-space:pre-wrap;overflow-wrap:break-word}.chat-sdk__bubble.ai,.chat-sdk__bubble.ai-patch{align-self:flex-start;max-width:90%;min-width:0;display:flex;flex-direction:column}.chat-sdk__bubble-body{display:flex;flex-direction:column;gap:8px;font-size:15px;color:var(--content-primary);line-height:1.5;overflow-wrap:break-word;word-break:break-word}.chat-sdk__suggestion-text{font-size:13px;color:var(--content-secondary);margin-bottom:0}.chat-sdk__patch{display:flex;flex-direction:column;gap:8px;margin-top:4px}.chat-sdk__patch-label{font-size:12px;color:var(--content-tertiary);font-weight:600}.chat-sdk__patch-block{background:#f3f4f6;border-radius:10px;padding:12px;border:1px solid #e5e7eb;font-size:14px;line-height:1.5;color:var(--content-primary);overflow-wrap:break-word;word-break:break-word;white-space:pre-wrap}.chat-sdk__patch-label--original{color:#b81514}.chat-sdk__patch-label--improved{color:#2d6a1e}.chat-sdk__patch-block--original{background:#fef2f2;border-color:#fde7e2}.chat-sdk__patch-block--improved{background:#f0fdf4;border-color:#dcfce7}.chat-sdk__composer{padding:var(--spacing-1);background:var(--background-primary)}.chat-sdk__input-bar{display:flex;flex-direction:column;background:#fff;border:1px solid var(--border-secondary);border-radius:var(--radius-large);padding:8px;overflow:hidden}.chat-sdk__input-context{padding:0 4px 8px}.chat-sdk__input-context .chat-sdk__context-chip{background:var(--background-tertiary);padding:8px 12px;border-radius:var(--radius-full);display:inline-flex;align-items:center;gap:8px}.chat-sdk__input-context .chat-sdk__context-text{font-size:14px;line-height:1.45;color:var(--content-primary)}.chat-sdk__context-clear{display:flex;align-items:center;justify-content:center;width:16px;height:16px;padding:0;background:transparent;border:none;color:var(--content-secondary);cursor:pointer;transition:color .15s}.chat-sdk__context-clear:hover{color:var(--content-primary)}.chat-sdk__input{width:100%;border:none;background:transparent;resize:none;min-height:72px;max-height:120px;font-size:15px;font-family:inherit;color:var(--content-primary);outline:none;line-height:1.45;padding:4px 8px}.chat-sdk__input::placeholder{color:var(--content-tertiary)}.chat-sdk__actions{display:flex;align-items:center;justify-content:flex-end}.chat-sdk__send{display:flex;align-items:center;justify-content:center;width:28px;height:28px;min-width:28px;min-height:28px;background:var(--background-black);color:#fff;border:none;border-radius:50%;cursor:pointer;transition:opacity .2s}.chat-sdk__send:disabled{opacity:.3;cursor:not-allowed}.chat-sdk__send:not(:disabled):hover{opacity:.8}.chat-sdk__error{font-size:12px;color:#dc2626;padding:4px 8px}.chat-sdk__stream{display:inline-flex;gap:4px;vertical-align:middle}.chat-sdk__stream span{width:4px;height:4px;background:currentColor;border-radius:50%;animation:chat-sdk-pulse 1.4s infinite ease-in-out both}.chat-sdk__stream span:nth-child(1){animation-delay:-.32s}.chat-sdk__stream span:nth-child(2){animation-delay:-.16s}@keyframes chat-sdk-pulse{0%,80%,to{transform:scale(0)}40%{transform:scale(1)}}.chat-sdk__rule-learned-container{display:flex;flex-direction:column;width:100%;animation:chat-sdk-rule-fade-in .5s ease-out}@keyframes chat-sdk-rule-fade-in{0%{opacity:0;transform:translateY(8px) scale(.97)}to{opacity:1;transform:translateY(0) scale(1)}}.chat-sdk__rule-learned{display:flex;align-items:flex-start;gap:6px;padding:8px 12px;background:#9370db2e;border:1px solid rgba(147,112,219,.5);border-radius:var(--radius-medium);width:100%}.chat-sdk__rule-learned-meta{font-size:12px;color:var(--content-tertiary);margin-top:4px;text-align:right}.chat-sdk__rule-learned-icon{flex-shrink:0;color:#9370db;display:flex;align-items:center;height:18px}.chat-sdk__rule-learned-body{display:flex;flex-direction:column;gap:2px;flex:1;min-width:0}.chat-sdk__rule-learned-title{font-size:13px;font-weight:600;color:#7b5cb8;white-space:nowrap;line-height:18px}.chat-sdk__rule-learned-text{font-size:13px;color:var(--content-primary);line-height:1.4;word-wrap:break-word}";
|
|
3164
3155
|
export {
|
|
3165
|
-
|
|
3156
|
+
tn as ChatProvider,
|
|
3166
3157
|
$t as ChatWidget,
|
|
3167
|
-
|
|
3158
|
+
nn as style,
|
|
3168
3159
|
zt as useChat
|
|
3169
3160
|
};
|
|
3170
3161
|
//# sourceMappingURL=translation-chat-sdk.es.js.map
|