@seer-ai/seer-vue 0.1.0-beta.2 → 0.1.0-beta.3
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/index.css +1 -1
- package/dist/index.js +53 -62
- package/package.json +1 -1
package/dist/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.seer-chat[data-v-
|
|
1
|
+
.seer-chat[data-v-163bc07c]{display:grid;gap:16px;max-width:720px;padding:20px;color:#172033;background:#fff;border:1px solid #d9e2ef;border-radius:16px}.seer-chat__header[data-v-163bc07c]{display:flex;gap:16px;align-items:flex-start;justify-content:space-between}.seer-chat__header h2[data-v-163bc07c]{margin:0;font-size:20px}.seer-chat__header p[data-v-163bc07c],.seer-chat__empty[data-v-163bc07c],.seer-chat__status[data-v-163bc07c]{margin:4px 0 0;color:#5f6f89;font-size:14px}.seer-chat__messages[data-v-163bc07c]{display:grid;gap:12px;min-height:180px}.seer-chat__message[data-v-163bc07c]{display:grid;gap:4px;max-width:86%;padding:12px 14px;border-radius:14px;background:#f3f6fb}.seer-chat__message--user[data-v-163bc07c]{justify-self:end;color:#fff;background:#1f5eff}.seer-chat__role[data-v-163bc07c]{font-size:12px;font-weight:700;opacity:.75}.seer-chat__message p[data-v-163bc07c]{margin:0;white-space:pre-wrap}.seer-chat__error[data-v-163bc07c],.seer-chat__handoff[data-v-163bc07c]{margin:0;padding:10px 12px;border-radius:10px}.seer-chat__error[data-v-163bc07c]{color:#8a1f11;background:#fff0ed}.seer-chat__handoff[data-v-163bc07c]{color:#704600;background:#fff7db}.seer-chat__form[data-v-163bc07c]{display:grid;gap:10px}.seer-chat__label[data-v-163bc07c]{font-size:13px;font-weight:700}.seer-chat textarea[data-v-163bc07c]{width:100%;box-sizing:border-box;padding:12px;color:inherit;border:1px solid #c8d3e2;border-radius:12px;resize:vertical}.seer-chat button[data-v-163bc07c]{padding:9px 14px;color:#fff;background:#172033;border:0;border-radius:999px;cursor:pointer}.seer-chat button[data-v-163bc07c]:disabled{cursor:not-allowed;opacity:.5}.seer-chat button[data-v-163bc07c]:focus-visible,.seer-chat textarea[data-v-163bc07c]:focus-visible{outline:3px solid #8fb4ff;outline-offset:2px}.seer-chat__ghost-button[data-v-163bc07c]{color:#172033!important;background:#eef3fa!important}.seer-chat__actions[data-v-163bc07c]{display:flex;gap:8px;justify-content:flex-end}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { hasInjectionContext as
|
|
1
|
+
import { hasInjectionContext as T, inject as $, ref as w, defineComponent as A, computed as q, openBlock as v, createElementBlock as p, createElementVNode as u, toDisplayString as E, unref as h, createCommentVNode as k, Fragment as M, renderList as N, normalizeClass as B, withModifiers as D, withDirectives as F, vModelText as P } from "vue";
|
|
2
2
|
function V(n) {
|
|
3
3
|
const t = n.fetcher ?? fetch, e = n.model ?? "seer";
|
|
4
4
|
let s, c = 0;
|
|
5
5
|
return {
|
|
6
6
|
async chat(r, a = {}) {
|
|
7
|
-
const o = r.stream ?? !1, f = await l(),
|
|
7
|
+
const o = r.stream ?? !1, f = await l(), m = {
|
|
8
8
|
"Content-Type": "application/json"
|
|
9
9
|
};
|
|
10
|
-
f && (
|
|
10
|
+
f && (m.Authorization = `Bearer ${f}`);
|
|
11
11
|
const d = await t(n.endpoint, {
|
|
12
12
|
method: "POST",
|
|
13
|
-
headers:
|
|
13
|
+
headers: m,
|
|
14
14
|
signal: a.signal,
|
|
15
15
|
body: JSON.stringify({
|
|
16
16
|
model: r.model ?? e,
|
|
@@ -21,11 +21,11 @@ function V(n) {
|
|
|
21
21
|
})
|
|
22
22
|
});
|
|
23
23
|
if (!d.ok)
|
|
24
|
-
throw new Error(await
|
|
24
|
+
throw new Error(await j(d));
|
|
25
25
|
if (o)
|
|
26
26
|
return z(d, a.onDelta);
|
|
27
|
-
const
|
|
28
|
-
return
|
|
27
|
+
const y = await d.json();
|
|
28
|
+
return O(y);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
async function l() {
|
|
@@ -38,12 +38,12 @@ function V(n) {
|
|
|
38
38
|
method: "GET"
|
|
39
39
|
});
|
|
40
40
|
if (!a.ok)
|
|
41
|
-
throw new Error(await
|
|
41
|
+
throw new Error(await j(a));
|
|
42
42
|
const o = await a.json();
|
|
43
43
|
return s = o.token, c = o.expires_at, s;
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function O(n) {
|
|
47
47
|
var e, s, c;
|
|
48
48
|
const t = (e = n.choices) == null ? void 0 : e[0];
|
|
49
49
|
return {
|
|
@@ -55,9 +55,9 @@ function T(n) {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
async function z(n, t) {
|
|
58
|
-
var
|
|
58
|
+
var m, d, y;
|
|
59
59
|
if (!n.body)
|
|
60
|
-
return
|
|
60
|
+
return O({});
|
|
61
61
|
const e = n.body.getReader(), s = new TextDecoder();
|
|
62
62
|
let c = "", l = "", r, a = [], o = !1, f;
|
|
63
63
|
for (; ; ) {
|
|
@@ -65,15 +65,15 @@ async function z(n, t) {
|
|
|
65
65
|
if (x)
|
|
66
66
|
break;
|
|
67
67
|
c += s.decode(I, { stream: !0 });
|
|
68
|
-
const
|
|
68
|
+
const S = c.split(`
|
|
69
69
|
|
|
70
70
|
`);
|
|
71
|
-
c =
|
|
72
|
-
for (const
|
|
73
|
-
const
|
|
74
|
-
if (!
|
|
71
|
+
c = S.pop() ?? "";
|
|
72
|
+
for (const C of S) {
|
|
73
|
+
const b = J(C);
|
|
74
|
+
if (!b || b === "[DONE]")
|
|
75
75
|
continue;
|
|
76
|
-
const _ = JSON.parse(
|
|
76
|
+
const _ = JSON.parse(b), i = (m = _.choices) == null ? void 0 : m[0], g = ((d = i == null ? void 0 : i.delta) == null ? void 0 : d.content) ?? ((y = i == null ? void 0 : i.message) == null ? void 0 : y.content) ?? "";
|
|
77
77
|
g && (l += g, t == null || t(g)), r = _.conversation_id ?? r, a = _.citations ?? a, o = _.handoff_requested ?? o, f = (i == null ? void 0 : i.finish_reason) ?? f;
|
|
78
78
|
}
|
|
79
79
|
}
|
|
@@ -91,7 +91,7 @@ function J(n) {
|
|
|
91
91
|
return t.length === 0 ? null : t.join(`
|
|
92
92
|
`);
|
|
93
93
|
}
|
|
94
|
-
async function
|
|
94
|
+
async function j(n) {
|
|
95
95
|
let t = n.statusText || "unknown error";
|
|
96
96
|
try {
|
|
97
97
|
const e = await n.json();
|
|
@@ -102,13 +102,13 @@ async function R(n) {
|
|
|
102
102
|
}
|
|
103
103
|
return `seer chat request failed with status ${n.status}: ${t}`;
|
|
104
104
|
}
|
|
105
|
-
const
|
|
105
|
+
const R = Symbol("seer-chat-options"), oe = {
|
|
106
106
|
install(n, t) {
|
|
107
|
-
n.provide(
|
|
107
|
+
n.provide(R, t);
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
110
|
function L(n = {}) {
|
|
111
|
-
const e = { ...
|
|
111
|
+
const e = { ...T() ? $(R, void 0) : void 0, ...n };
|
|
112
112
|
if (!e.endpoint)
|
|
113
113
|
throw new Error("Seer chat endpoint is required. Pass it to app.use() or useSeerChat().");
|
|
114
114
|
const s = {
|
|
@@ -116,14 +116,14 @@ function L(n = {}) {
|
|
|
116
116
|
sessionEndpoint: e.sessionEndpoint,
|
|
117
117
|
model: e.model,
|
|
118
118
|
fetcher: e.fetcher
|
|
119
|
-
}, c = V(s), l =
|
|
119
|
+
}, c = V(s), l = w([]), r = w(!1), a = w(null), o = w(), f = w([]), m = w(!1);
|
|
120
120
|
let d = null;
|
|
121
|
-
async function
|
|
122
|
-
const
|
|
123
|
-
if (!
|
|
121
|
+
async function y(S) {
|
|
122
|
+
const C = S.trim();
|
|
123
|
+
if (!C || r.value)
|
|
124
124
|
return;
|
|
125
|
-
const
|
|
126
|
-
l.value = [...l.value,
|
|
125
|
+
const b = { role: "user", content: C };
|
|
126
|
+
l.value = [...l.value, b], r.value = !0, a.value = null, d = new AbortController();
|
|
127
127
|
const _ = { role: "assistant", content: "" };
|
|
128
128
|
e.stream && (l.value = [...l.value, _]);
|
|
129
129
|
try {
|
|
@@ -140,7 +140,7 @@ function L(n = {}) {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
);
|
|
143
|
-
e.stream || (l.value = [...l.value, { role: "assistant", content: i.content }]), o.value = i.conversationId, f.value = i.citations,
|
|
143
|
+
e.stream || (l.value = [...l.value, { role: "assistant", content: i.content }]), o.value = i.conversationId, f.value = i.citations, m.value = i.handoffRequested;
|
|
144
144
|
} catch (i) {
|
|
145
145
|
i.name !== "AbortError" && (a.value = i instanceof Error ? i.message : String(i));
|
|
146
146
|
} finally {
|
|
@@ -148,7 +148,7 @@ function L(n = {}) {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
function x() {
|
|
151
|
-
l.value = [], a.value = null, o.value = void 0, f.value = [],
|
|
151
|
+
l.value = [], a.value = null, o.value = void 0, f.value = [], m.value = !1;
|
|
152
152
|
}
|
|
153
153
|
function I() {
|
|
154
154
|
d == null || d.abort();
|
|
@@ -159,8 +159,8 @@ function L(n = {}) {
|
|
|
159
159
|
error: a,
|
|
160
160
|
conversationId: o,
|
|
161
161
|
citations: f,
|
|
162
|
-
handoffRequested:
|
|
163
|
-
send:
|
|
162
|
+
handoffRequested: m,
|
|
163
|
+
send: y,
|
|
164
164
|
reset: x,
|
|
165
165
|
abort: I
|
|
166
166
|
};
|
|
@@ -184,10 +184,7 @@ const G = {
|
|
|
184
184
|
}, Y = {
|
|
185
185
|
key: 2,
|
|
186
186
|
class: "seer-chat__handoff"
|
|
187
|
-
}, Z = {
|
|
188
|
-
key: 3,
|
|
189
|
-
class: "seer-chat__citations"
|
|
190
|
-
}, ee = ["placeholder", "disabled"], te = { class: "seer-chat__actions" }, ne = ["disabled"], se = /* @__PURE__ */ M({
|
|
187
|
+
}, Z = ["placeholder", "disabled"], ee = { class: "seer-chat__actions" }, te = ["disabled"], ne = /* @__PURE__ */ A({
|
|
191
188
|
__name: "SeerChat",
|
|
192
189
|
props: {
|
|
193
190
|
endpoint: {},
|
|
@@ -198,22 +195,22 @@ const G = {
|
|
|
198
195
|
placeholder: { default: "输入你的问题,例如:美国海派怎么报价?" }
|
|
199
196
|
},
|
|
200
197
|
setup(n) {
|
|
201
|
-
const t = n, e =
|
|
198
|
+
const t = n, e = w(""), s = L({
|
|
202
199
|
endpoint: t.endpoint,
|
|
203
200
|
model: t.model,
|
|
204
201
|
stream: t.stream,
|
|
205
202
|
fetcher: t.fetcher
|
|
206
|
-
}), c =
|
|
203
|
+
}), c = q(() => e.value.trim().length > 0 && !s.loading.value);
|
|
207
204
|
async function l() {
|
|
208
205
|
if (!c.value)
|
|
209
206
|
return;
|
|
210
207
|
const r = e.value;
|
|
211
208
|
e.value = "", await s.send(r);
|
|
212
209
|
}
|
|
213
|
-
return (r, a) => (
|
|
210
|
+
return (r, a) => (v(), p("section", G, [
|
|
214
211
|
u("header", K, [
|
|
215
212
|
u("div", null, [
|
|
216
|
-
u("h2", null,
|
|
213
|
+
u("h2", null, E(n.title), 1),
|
|
217
214
|
a[3] || (a[3] = u("p", null, "可咨询渠道报价、时效、下单资料、入仓和售后问题。", -1))
|
|
218
215
|
]),
|
|
219
216
|
u("button", {
|
|
@@ -223,29 +220,23 @@ const G = {
|
|
|
223
220
|
}, "清空")
|
|
224
221
|
]),
|
|
225
222
|
u("div", U, [
|
|
226
|
-
h(s).messages.value.length === 0 ? (
|
|
227
|
-
(
|
|
223
|
+
h(s).messages.value.length === 0 ? (v(), p("p", W, " 直接输入问题即可,复杂查单或赔付问题会提示转人工。 ")) : k("", !0),
|
|
224
|
+
(v(!0), p(M, null, N(h(s).messages.value, (o, f) => (v(), p("article", {
|
|
228
225
|
key: `${o.role}-${f}`,
|
|
229
226
|
class: B(["seer-chat__message", `seer-chat__message--${o.role}`])
|
|
230
227
|
}, [
|
|
231
|
-
u("span", H,
|
|
232
|
-
u("p", null,
|
|
228
|
+
u("span", H, E(o.role === "user" ? "你" : "AI 客服"), 1),
|
|
229
|
+
u("p", null, E(o.content), 1)
|
|
233
230
|
], 2))), 128))
|
|
234
231
|
]),
|
|
235
|
-
h(s).loading.value ? (
|
|
236
|
-
h(s).error.value ? (
|
|
237
|
-
h(s).handoffRequested.value ? (
|
|
238
|
-
h(s).citations.value.length > 0 ? (m(), v("footer", Z, [
|
|
239
|
-
a[4] || (a[4] = u("span", null, "参考资料", -1)),
|
|
240
|
-
u("ul", null, [
|
|
241
|
-
(m(!0), v(j, null, O(h(s).citations.value, (o) => (m(), v("li", { key: o }, S(o), 1))), 128))
|
|
242
|
-
])
|
|
243
|
-
])) : b("", !0),
|
|
232
|
+
h(s).loading.value ? (v(), p("p", Q, "正在回复...")) : k("", !0),
|
|
233
|
+
h(s).error.value ? (v(), p("p", X, E(h(s).error.value), 1)) : k("", !0),
|
|
234
|
+
h(s).handoffRequested.value ? (v(), p("p", Y, " 建议转人工:请留下联系方式或等待客服接入。 ")) : k("", !0),
|
|
244
235
|
u("form", {
|
|
245
236
|
class: "seer-chat__form",
|
|
246
237
|
onSubmit: D(l, ["prevent"])
|
|
247
238
|
}, [
|
|
248
|
-
a[
|
|
239
|
+
a[4] || (a[4] = u("label", {
|
|
249
240
|
class: "seer-chat__label",
|
|
250
241
|
for: "seer-chat-input"
|
|
251
242
|
}, "问题", -1)),
|
|
@@ -255,33 +246,33 @@ const G = {
|
|
|
255
246
|
placeholder: n.placeholder,
|
|
256
247
|
disabled: h(s).loading.value,
|
|
257
248
|
rows: "3"
|
|
258
|
-
}, null, 8,
|
|
249
|
+
}, null, 8, Z), [
|
|
259
250
|
[P, e.value]
|
|
260
251
|
]),
|
|
261
|
-
u("div",
|
|
262
|
-
h(s).loading.value ? (
|
|
252
|
+
u("div", ee, [
|
|
253
|
+
h(s).loading.value ? (v(), p("button", {
|
|
263
254
|
key: 0,
|
|
264
255
|
type: "button",
|
|
265
256
|
class: "seer-chat__ghost-button",
|
|
266
257
|
onClick: a[2] || (a[2] = (o) => h(s).abort())
|
|
267
|
-
}, " 停止 ")) :
|
|
258
|
+
}, " 停止 ")) : k("", !0),
|
|
268
259
|
u("button", {
|
|
269
260
|
type: "submit",
|
|
270
261
|
disabled: !c.value
|
|
271
|
-
}, "发送", 8,
|
|
262
|
+
}, "发送", 8, te)
|
|
272
263
|
])
|
|
273
264
|
], 32)
|
|
274
265
|
]));
|
|
275
266
|
}
|
|
276
|
-
}),
|
|
267
|
+
}), se = (n, t) => {
|
|
277
268
|
const e = n.__vccOpts || n;
|
|
278
269
|
for (const [s, c] of t)
|
|
279
270
|
e[s] = c;
|
|
280
271
|
return e;
|
|
281
|
-
},
|
|
272
|
+
}, re = /* @__PURE__ */ se(ne, [["__scopeId", "data-v-163bc07c"]]);
|
|
282
273
|
export {
|
|
283
|
-
|
|
284
|
-
|
|
274
|
+
re as SeerChat,
|
|
275
|
+
oe as SeerChatPlugin,
|
|
285
276
|
V as createSeerClient,
|
|
286
277
|
L as useSeerChat
|
|
287
278
|
};
|