@seer-ai/seer-vue 0.1.0-beta.3 → 0.1.0-beta.5

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/README.md CHANGED
@@ -13,6 +13,7 @@ npm install @seer-ai/seer-vue@beta
13
13
  ```ts
14
14
  import { createApp } from 'vue'
15
15
  import { SeerChatPlugin } from '@seer-ai/seer-vue'
16
+ import '@seer-ai/seer-vue/style.css' // 必须:链接的蓝色/下划线样式来自这里
16
17
  import App from './App.vue'
17
18
 
18
19
  createApp(App)
@@ -37,10 +38,14 @@ import { SeerChat } from '@seer-ai/seer-vue'
37
38
 
38
39
  ## Use custom UI
39
40
 
41
+ 自定义 UI 时**不要**直接把 `message.content` 当纯文本渲染——回复里的下载/截图链接是裸
42
+ URL 文本,会原样显示成一长串 url。用导出的 `toContentLines` 把它切成可点链接(这正是
43
+ `<SeerChat>` 内部用的逻辑):
44
+
40
45
  ```vue
41
46
  <script setup lang="ts">
42
47
  import { ref } from 'vue'
43
- import { useSeerChat } from '@seer-ai/seer-vue'
48
+ import { toContentLines, useSeerChat } from '@seer-ai/seer-vue'
44
49
 
45
50
  const input = ref('')
46
51
  const chat = useSeerChat()
@@ -52,6 +57,19 @@ async function submit() {
52
57
  await chat.send(content)
53
58
  }
54
59
  </script>
60
+
61
+ <template>
62
+ <div v-for="(message, i) in chat.messages.value" :key="i">
63
+ <p v-for="(line, li) in toContentLines(message.content)" :key="li">
64
+ <template v-for="(seg, si) in line" :key="si">
65
+ <a v-if="seg.kind === 'link'" :href="seg.href" target="_blank" rel="noopener noreferrer">{{
66
+ seg.label
67
+ }}</a>
68
+ <span v-else>{{ seg.value }}</span>
69
+ </template>
70
+ </p>
71
+ </div>
72
+ </template>
55
73
  ```
56
74
 
57
75
  ## Security
package/dist/client.d.ts CHANGED
@@ -7,8 +7,10 @@ export interface SeerChatMessage {
7
7
  export interface SeerClientOptions {
8
8
  endpoint: string;
9
9
  sessionEndpoint?: string;
10
+ challengeTokenProvider?: () => Promise<string>;
10
11
  model?: string;
11
12
  fetcher?: typeof fetch;
13
+ now?: () => number;
12
14
  }
13
15
  export interface SeerChatRequest {
14
16
  messages: SeerChatMessage[];
@@ -1,9 +1,9 @@
1
- import type { SeerClientOptions } from '../client';
1
+ import type { SeerClientOptions } from "../client";
2
2
  type __VLS_Props = {
3
3
  endpoint?: string;
4
4
  model?: string;
5
5
  stream?: boolean;
6
- fetcher?: SeerClientOptions['fetcher'];
6
+ fetcher?: SeerClientOptions["fetcher"];
7
7
  title?: string;
8
8
  placeholder?: string;
9
9
  };
@@ -0,0 +1,11 @@
1
+ export type ContentSegment = {
2
+ kind: 'text';
3
+ value: string;
4
+ } | {
5
+ kind: 'link';
6
+ href: string;
7
+ label: string;
8
+ };
9
+ export declare function linkAnchorLabel(prefix: string): string | null;
10
+ export declare function toContentSegments(content: string): ContentSegment[];
11
+ export declare function toContentLines(content: string): ContentSegment[][];
package/dist/index.css CHANGED
@@ -1 +1 @@
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}
1
+ .seer-chat[data-v-f2b8b91f]{display:grid;gap:18px;max-width:720px;min-height:640px;padding:0;overflow:hidden;color:#18212f;background:radial-gradient(circle at 18% 0%,rgba(71,106,255,.14),transparent 32%),linear-gradient(180deg,#fff,#f7f9fd);border:1px solid rgba(127,143,170,.28);border-radius:28px;box-shadow:0 24px 70px #151f3429}.seer-chat__header[data-v-f2b8b91f]{display:flex;gap:16px;align-items:flex-start;justify-content:space-between;padding:22px 22px 18px;color:#fff;background:linear-gradient(135deg,#141f34f5,#243f76f0),#172033}.seer-chat__header h2[data-v-f2b8b91f]{margin:0;font-size:22px;letter-spacing:-.03em}.seer-chat__header p[data-v-f2b8b91f],.seer-chat__empty[data-v-f2b8b91f],.seer-chat__status[data-v-f2b8b91f]{margin:4px 0 0;color:#5f6f89;font-size:14px}.seer-chat__header p[data-v-f2b8b91f]{max-width:34ch;color:#ffffffb8}.seer-chat__messages[data-v-f2b8b91f]{display:grid;gap:12px;align-content:start;min-height:330px;max-height:470px;padding:18px 18px 4px;overflow-y:auto}.seer-chat__empty[data-v-f2b8b91f]{display:grid;place-items:center;min-height:260px;padding:0 28px;color:#66748a;text-align:center;border:1px dashed rgba(127,143,170,.38);border-radius:22px;background:#ffffff9e}.seer-chat__message[data-v-f2b8b91f]{display:grid;gap:6px;max-width:min(86%,520px);padding:13px 15px;border:1px solid rgba(127,143,170,.16);border-radius:18px 18px 18px 6px;background:#ffffffe0;box-shadow:0 12px 28px #151f3414}.seer-chat__message--user[data-v-f2b8b91f]{justify-self:end;color:#fff;border-color:transparent;border-radius:18px 18px 6px;background:linear-gradient(135deg,#285cff,#1d45c9);box-shadow:0 14px 30px #1f5eff3d}.seer-chat__role[data-v-f2b8b91f]{font-size:12px;font-weight:700;opacity:.75}.seer-chat__body[data-v-f2b8b91f]{display:flex;flex-direction:column}.seer-chat__line[data-v-f2b8b91f]{margin:0;white-space:pre-wrap;overflow-wrap:anywhere}.seer-chat__line[data-v-f2b8b91f]:not(:last-child){margin-bottom:5px}.seer-chat__line[data-v-f2b8b91f]:empty{height:7px}.seer-chat__link[data-v-f2b8b91f]{color:#1f5eff;font-weight:600;text-decoration:underline;text-underline-offset:2px;overflow-wrap:anywhere}.seer-chat__link[data-v-f2b8b91f]:hover{color:#173fb3}.seer-chat__message--user .seer-chat__link[data-v-f2b8b91f]{color:#fff}.seer-chat__error[data-v-f2b8b91f],.seer-chat__handoff[data-v-f2b8b91f]{margin:0 18px;padding:10px 12px;border-radius:14px}.seer-chat__error[data-v-f2b8b91f]{color:#8a1f11;background:#fff0ed}.seer-chat__handoff[data-v-f2b8b91f]{color:#704600;background:#fff7db}.seer-chat__form[data-v-f2b8b91f]{display:grid;gap:11px;margin:0 18px 18px;padding:14px;background:#fff;border:1px solid rgba(127,143,170,.26);border-radius:22px;box-shadow:0 18px 38px #151f3417}.seer-chat__label[data-v-f2b8b91f]{font-size:13px;font-weight:700}.seer-chat textarea[data-v-f2b8b91f]{width:100%;box-sizing:border-box;min-height:92px;padding:14px;color:inherit;line-height:1.55;background:#f8fafd;border:1px solid transparent;border-radius:16px;outline:none;resize:vertical;transition:background .16s ease,border-color .16s ease,box-shadow .16s ease}.seer-chat button[data-v-f2b8b91f]{color:inherit;font-weight:700;border:0;cursor:pointer;transition:transform .16s ease,box-shadow .16s ease,opacity .16s ease}.seer-chat button[data-v-f2b8b91f]:not(:disabled):hover{transform:translateY(-1px)}.seer-chat button[data-v-f2b8b91f]:disabled{cursor:not-allowed;opacity:.5}.seer-chat button[data-v-f2b8b91f]:focus-visible,.seer-chat textarea[data-v-f2b8b91f]:focus-visible{border-color:#1f5eff6b;box-shadow:0 0 0 4px #1f5eff21}.seer-chat__clear-button[data-v-f2b8b91f]{flex:0 0 auto;padding:8px 11px;color:#ffffffc7;font-size:12px;background:transparent;border:1px solid rgba(255,255,255,.18)!important;border-radius:12px}.seer-chat__clear-button[data-v-f2b8b91f]:not(:disabled):hover{color:#fff;background:#ffffff1a;box-shadow:none}.seer-chat__stop-button[data-v-f2b8b91f]{padding:8px 11px;color:#6c3b12;font-size:12px;background:#fff1df;border-radius:12px}.seer-chat__send-button[data-v-f2b8b91f]{display:inline-flex;gap:8px;align-items:center;justify-content:center;min-width:86px;padding:10px 14px;color:#fff;background:linear-gradient(135deg,#1f5eff,#173fb3);border-radius:14px;box-shadow:0 12px 24px #1f5eff38}.seer-chat__send-button[data-v-f2b8b91f]:not(:disabled):hover{box-shadow:0 14px 28px #1f5eff47}.seer-chat__hint[data-v-f2b8b91f]{margin-right:auto;color:#7a879a;font-size:12px}.seer-chat__composer-footer[data-v-f2b8b91f]{display:flex;gap:8px;align-items:center;justify-content:flex-end}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { createSeerClient } from './client';
2
+ export { linkAnchorLabel, toContentLines, toContentSegments, type ContentSegment, } from './content';
2
3
  export { SeerChatPlugin } from './plugin';
3
4
  export { useSeerChat } from './useSeerChat';
4
5
  export { default as SeerChat } from './components/SeerChat.vue';
package/dist/index.js CHANGED
@@ -1,190 +1,217 @@
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
- function V(n) {
3
- const t = n.fetcher ?? fetch, e = n.model ?? "seer";
4
- let s, c = 0;
1
+ import { hasInjectionContext as N, inject as q, ref as w, defineComponent as L, computed as M, openBlock as v, createElementBlock as m, createElementVNode as u, toDisplayString as C, unref as _, createCommentVNode as E, Fragment as I, renderList as R, normalizeClass as B, withModifiers as O, withDirectives as K, withKeys as D, vModelText as F } from "vue";
2
+ function U(e) {
3
+ const n = e.fetcher ?? fetch, t = e.model ?? "seer", a = e.now ?? (() => Math.floor(Date.now() / 1e3));
4
+ let l, r = 0;
5
5
  return {
6
- async chat(r, a = {}) {
7
- const o = r.stream ?? !1, f = await l(), m = {
6
+ async chat(s, c = {}) {
7
+ const f = s.stream ?? !1, h = await d(), p = {
8
8
  "Content-Type": "application/json"
9
9
  };
10
- f && (m.Authorization = `Bearer ${f}`);
11
- const d = await t(n.endpoint, {
10
+ h && (p.Authorization = `Bearer ${h}`);
11
+ const g = await n(e.endpoint, {
12
12
  method: "POST",
13
- headers: m,
14
- signal: a.signal,
13
+ headers: p,
14
+ signal: c.signal,
15
15
  body: JSON.stringify({
16
- model: r.model ?? e,
17
- messages: r.messages,
18
- stream: o,
19
- conversation_id: r.conversationId,
20
- metadata: r.metadata
16
+ model: s.model ?? t,
17
+ messages: s.messages,
18
+ stream: f,
19
+ conversation_id: s.conversationId,
20
+ metadata: s.metadata
21
21
  })
22
22
  });
23
- if (!d.ok)
24
- throw new Error(await j(d));
25
- if (o)
26
- return z(d, a.onDelta);
27
- const y = await d.json();
28
- return O(y);
23
+ if (!g.ok)
24
+ throw new Error(await j(g));
25
+ if (f)
26
+ return V(g, c.onDelta);
27
+ const b = await g.json();
28
+ return P(b);
29
29
  }
30
30
  };
31
- async function l() {
32
- if (!n.sessionEndpoint)
31
+ async function d() {
32
+ if (!e.sessionEndpoint)
33
33
  return;
34
- const r = Math.floor(Date.now() / 1e3);
35
- if (s && c - 30 > r)
36
- return s;
37
- const a = await t(n.sessionEndpoint, {
38
- method: "GET"
34
+ const s = a();
35
+ if (l && r - 30 > s)
36
+ return l;
37
+ const c = await n(e.sessionEndpoint, {
38
+ method: "GET",
39
+ headers: await o()
39
40
  });
40
- if (!a.ok)
41
- throw new Error(await j(a));
42
- const o = await a.json();
43
- return s = o.token, c = o.expires_at, s;
41
+ if (!c.ok)
42
+ throw new Error(await j(c));
43
+ const f = await c.json();
44
+ return l = f.token, r = f.expires_at, l;
45
+ }
46
+ async function o() {
47
+ const s = {};
48
+ return e.challengeTokenProvider && (s["X-Seer-Challenge-Token"] = await e.challengeTokenProvider()), s;
44
49
  }
45
50
  }
46
- function O(n) {
47
- var e, s, c;
48
- const t = (e = n.choices) == null ? void 0 : e[0];
51
+ function P(e) {
52
+ var t, a, l;
53
+ const n = (t = e.choices) == null ? void 0 : t[0];
49
54
  return {
50
- content: ((s = t == null ? void 0 : t.message) == null ? void 0 : s.content) ?? ((c = t == null ? void 0 : t.delta) == null ? void 0 : c.content) ?? "",
51
- conversationId: n.conversation_id,
52
- citations: n.citations ?? [],
53
- handoffRequested: n.handoff_requested ?? !1,
54
- finishReason: t == null ? void 0 : t.finish_reason
55
+ content: ((a = n == null ? void 0 : n.message) == null ? void 0 : a.content) ?? ((l = n == null ? void 0 : n.delta) == null ? void 0 : l.content) ?? "",
56
+ conversationId: e.conversation_id,
57
+ citations: e.citations ?? [],
58
+ handoffRequested: e.handoff_requested ?? !1,
59
+ finishReason: n == null ? void 0 : n.finish_reason
55
60
  };
56
61
  }
57
- async function z(n, t) {
58
- var m, d, y;
59
- if (!n.body)
60
- return O({});
61
- const e = n.body.getReader(), s = new TextDecoder();
62
- let c = "", l = "", r, a = [], o = !1, f;
62
+ async function V(e, n) {
63
+ var f, h, p;
64
+ if (!e.body)
65
+ return P({});
66
+ const t = e.body.getReader(), a = new TextDecoder();
67
+ let l = "", r = "", d, o = [], s = !1, c;
63
68
  for (; ; ) {
64
- const { done: x, value: I } = await e.read();
65
- if (x)
69
+ const { done: g, value: b } = await t.read();
70
+ if (g)
66
71
  break;
67
- c += s.decode(I, { stream: !0 });
68
- const S = c.split(`
72
+ l += a.decode(b, { stream: !0 });
73
+ const T = l.split(`
69
74
 
70
75
  `);
71
- c = S.pop() ?? "";
72
- for (const C of S) {
73
- const b = J(C);
74
- if (!b || b === "[DONE]")
76
+ l = T.pop() ?? "";
77
+ for (const x of T) {
78
+ const S = z(x);
79
+ if (!S || S === "[DONE]")
75
80
  continue;
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
- 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;
81
+ const y = JSON.parse(S), i = (f = y.choices) == null ? void 0 : f[0], k = ((h = i == null ? void 0 : i.delta) == null ? void 0 : h.content) ?? ((p = i == null ? void 0 : i.message) == null ? void 0 : p.content) ?? "";
82
+ k && (r += k, n == null || n(k)), d = y.conversation_id ?? d, o = y.citations ?? o, s = y.handoff_requested ?? s, c = (i == null ? void 0 : i.finish_reason) ?? c;
78
83
  }
79
84
  }
80
85
  return {
81
- content: l,
82
- conversationId: r,
83
- citations: a,
84
- handoffRequested: o,
85
- finishReason: f
86
+ content: r,
87
+ conversationId: d,
88
+ citations: o,
89
+ handoffRequested: s,
90
+ finishReason: c
86
91
  };
87
92
  }
88
- function J(n) {
89
- const t = n.split(`
90
- `).map((e) => e.trim()).filter((e) => e.startsWith("data:")).map((e) => e.slice(5).trim());
91
- return t.length === 0 ? null : t.join(`
93
+ function z(e) {
94
+ const n = e.split(`
95
+ `).map((t) => t.trim()).filter((t) => t.startsWith("data:")).map((t) => t.slice(5).trim());
96
+ return n.length === 0 ? null : n.join(`
92
97
  `);
93
98
  }
94
- async function j(n) {
95
- let t = n.statusText || "unknown error";
99
+ async function j(e) {
100
+ let n = e.statusText || "unknown error";
96
101
  try {
97
- const e = await n.json();
98
- typeof (e == null ? void 0 : e.detail) == "string" ? t = e.detail : typeof (e == null ? void 0 : e.error) == "string" && (t = e.error);
102
+ const t = await e.json();
103
+ typeof (t == null ? void 0 : t.detail) == "string" ? n = t.detail : typeof (t == null ? void 0 : t.error) == "string" && (n = t.error);
99
104
  } catch {
100
- const e = await n.text().catch(() => "");
101
- e && (t = e);
105
+ const t = await e.text().catch(() => "");
106
+ t && (n = t);
102
107
  }
103
- return `seer chat request failed with status ${n.status}: ${t}`;
108
+ return `seer chat request failed with status ${e.status}: ${n}`;
109
+ }
110
+ const A = /https?:\/\/[^\s)]+/g;
111
+ function J(e) {
112
+ return /标签|箱唛/.test(e) ? "点击下载箱唛" : /入库单|交接单/.test(e) ? "点击下载入库单" : /面单/.test(e) ? "点击下载面单" : /截图/.test(e) ? "点击查看报价截图" : /下载链接|labelUrl|下载/.test(e) ? "点击下载" : /链接/.test(e) ? "点击查看" : null;
113
+ }
114
+ function G(e) {
115
+ const n = [];
116
+ A.lastIndex = 0;
117
+ let t = 0, a;
118
+ for (; (a = A.exec(e)) !== null; ) {
119
+ const l = a[0], r = a.index;
120
+ r > t && n.push({ kind: "text", value: e.slice(t, r) });
121
+ const d = e.lastIndexOf(`
122
+ `, r - 1) + 1, o = J(e.slice(d, r)) ?? l;
123
+ n.push({ kind: "link", href: l, label: o }), t = r + l.length;
124
+ }
125
+ return t < e.length && n.push({ kind: "text", value: e.slice(t) }), n;
126
+ }
127
+ function H(e) {
128
+ return e.split(`
129
+ `).map((n) => G(n));
104
130
  }
105
- const R = Symbol("seer-chat-options"), oe = {
106
- install(n, t) {
107
- n.provide(R, t);
131
+ const $ = Symbol("seer-chat-options"), he = {
132
+ install(e, n) {
133
+ e.provide($, n);
108
134
  }
109
135
  };
110
- function L(n = {}) {
111
- const e = { ...T() ? $(R, void 0) : void 0, ...n };
112
- if (!e.endpoint)
136
+ function W(e = {}) {
137
+ const t = { ...N() ? q($, void 0) : void 0, ...e };
138
+ if (!t.endpoint)
113
139
  throw new Error("Seer chat endpoint is required. Pass it to app.use() or useSeerChat().");
114
- const s = {
115
- endpoint: e.endpoint,
116
- sessionEndpoint: e.sessionEndpoint,
117
- model: e.model,
118
- fetcher: e.fetcher
119
- }, c = V(s), l = w([]), r = w(!1), a = w(null), o = w(), f = w([]), m = w(!1);
120
- let d = null;
121
- async function y(S) {
122
- const C = S.trim();
123
- if (!C || r.value)
140
+ const a = {
141
+ endpoint: t.endpoint,
142
+ sessionEndpoint: t.sessionEndpoint,
143
+ challengeTokenProvider: t.challengeTokenProvider,
144
+ model: t.model,
145
+ fetcher: t.fetcher
146
+ }, l = U(a), r = w([]), d = w(!1), o = w(null), s = w(), c = w([]), f = w(!1);
147
+ let h = null;
148
+ async function p(T) {
149
+ const x = T.trim();
150
+ if (!x || d.value)
124
151
  return;
125
- const b = { role: "user", content: C };
126
- l.value = [...l.value, b], r.value = !0, a.value = null, d = new AbortController();
127
- const _ = { role: "assistant", content: "" };
128
- e.stream && (l.value = [...l.value, _]);
152
+ const S = { role: "user", content: x };
153
+ r.value = [...r.value, S], d.value = !0, o.value = null, h = new AbortController();
154
+ const y = { role: "assistant", content: "" };
155
+ t.stream && (r.value = [...r.value, y]);
129
156
  try {
130
- const i = await c.chat(
157
+ const i = await l.chat(
131
158
  {
132
- messages: l.value.filter((g) => g.content),
133
- stream: e.stream ?? !1,
134
- conversationId: o.value
159
+ messages: r.value.filter((k) => k.content),
160
+ stream: t.stream ?? !1,
161
+ conversationId: s.value
135
162
  },
136
163
  {
137
- signal: d.signal,
138
- onDelta(g) {
139
- _.content += g, l.value = [...l.value];
164
+ signal: h.signal,
165
+ onDelta(k) {
166
+ y.content += k, r.value = [...r.value];
140
167
  }
141
168
  }
142
169
  );
143
- e.stream || (l.value = [...l.value, { role: "assistant", content: i.content }]), o.value = i.conversationId, f.value = i.citations, m.value = i.handoffRequested;
170
+ t.stream || (r.value = [...r.value, { role: "assistant", content: i.content }]), s.value = i.conversationId, c.value = i.citations, f.value = i.handoffRequested;
144
171
  } catch (i) {
145
- i.name !== "AbortError" && (a.value = i instanceof Error ? i.message : String(i));
172
+ i.name !== "AbortError" && (o.value = i instanceof Error ? i.message : String(i));
146
173
  } finally {
147
- r.value = !1, d = null;
174
+ d.value = !1, h = null;
148
175
  }
149
176
  }
150
- function x() {
151
- l.value = [], a.value = null, o.value = void 0, f.value = [], m.value = !1;
177
+ function g() {
178
+ r.value = [], o.value = null, s.value = void 0, c.value = [], f.value = !1;
152
179
  }
153
- function I() {
154
- d == null || d.abort();
180
+ function b() {
181
+ h == null || h.abort();
155
182
  }
156
183
  return {
157
- messages: l,
158
- loading: r,
159
- error: a,
160
- conversationId: o,
161
- citations: f,
162
- handoffRequested: m,
163
- send: y,
164
- reset: x,
165
- abort: I
184
+ messages: r,
185
+ loading: d,
186
+ error: o,
187
+ conversationId: s,
188
+ citations: c,
189
+ handoffRequested: f,
190
+ send: p,
191
+ reset: g,
192
+ abort: b
166
193
  };
167
194
  }
168
- const G = {
195
+ const X = {
169
196
  class: "seer-chat",
170
197
  "aria-label": "多发货 AI 客服聊天"
171
- }, K = { class: "seer-chat__header" }, U = {
198
+ }, Q = { class: "seer-chat__header" }, Y = {
172
199
  class: "seer-chat__messages",
173
200
  "aria-live": "polite"
174
- }, W = {
201
+ }, Z = {
175
202
  key: 0,
176
203
  class: "seer-chat__empty"
177
- }, H = { class: "seer-chat__role" }, Q = {
204
+ }, ee = { class: "seer-chat__role" }, te = { class: "seer-chat__body" }, ne = ["href"], se = { key: 1 }, ae = {
178
205
  key: 0,
179
206
  class: "seer-chat__status"
180
- }, X = {
207
+ }, oe = {
181
208
  key: 1,
182
209
  class: "seer-chat__error",
183
210
  role: "alert"
184
- }, Y = {
211
+ }, re = {
185
212
  key: 2,
186
213
  class: "seer-chat__handoff"
187
- }, Z = ["placeholder", "disabled"], ee = { class: "seer-chat__actions" }, te = ["disabled"], ne = /* @__PURE__ */ A({
214
+ }, le = ["placeholder", "disabled", "onKeydown"], ie = { class: "seer-chat__composer-footer" }, ce = ["disabled"], ue = /* @__PURE__ */ L({
188
215
  __name: "SeerChat",
189
216
  props: {
190
217
  endpoint: {},
@@ -194,85 +221,111 @@ const G = {
194
221
  title: { default: "多发货 AI 客服" },
195
222
  placeholder: { default: "输入你的问题,例如:美国海派怎么报价?" }
196
223
  },
197
- setup(n) {
198
- const t = n, e = w(""), s = L({
199
- endpoint: t.endpoint,
200
- model: t.model,
201
- stream: t.stream,
202
- fetcher: t.fetcher
203
- }), c = q(() => e.value.trim().length > 0 && !s.loading.value);
204
- async function l() {
205
- if (!c.value)
224
+ setup(e) {
225
+ const n = e, t = w(""), a = W({
226
+ endpoint: n.endpoint,
227
+ model: n.model,
228
+ stream: n.stream,
229
+ fetcher: n.fetcher
230
+ }), l = M(
231
+ () => t.value.trim().length > 0 && !a.loading.value
232
+ );
233
+ async function r() {
234
+ if (!l.value)
206
235
  return;
207
- const r = e.value;
208
- e.value = "", await s.send(r);
236
+ const d = t.value;
237
+ t.value = "", await a.send(d);
209
238
  }
210
- return (r, a) => (v(), p("section", G, [
211
- u("header", K, [
239
+ return (d, o) => (v(), m("section", X, [
240
+ u("header", Q, [
212
241
  u("div", null, [
213
- u("h2", null, E(n.title), 1),
214
- a[3] || (a[3] = u("p", null, "可咨询渠道报价、时效、下单资料、入仓和售后问题。", -1))
242
+ u("h2", null, C(e.title), 1),
243
+ o[3] || (o[3] = u("p", null, "可咨询渠道报价、时效、下单资料、入仓和售后问题。", -1))
215
244
  ]),
216
245
  u("button", {
217
246
  type: "button",
218
- class: "seer-chat__ghost-button",
219
- onClick: a[0] || (a[0] = (o) => h(s).reset())
220
- }, "清空")
247
+ class: "seer-chat__clear-button",
248
+ onClick: o[0] || (o[0] = (s) => _(a).reset())
249
+ }, " 清空对话 ")
221
250
  ]),
222
- u("div", U, [
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", {
225
- key: `${o.role}-${f}`,
226
- class: B(["seer-chat__message", `seer-chat__message--${o.role}`])
251
+ u("div", Y, [
252
+ _(a).messages.value.length === 0 ? (v(), m("p", Z, " 直接输入问题即可,复杂查单或赔付问题会提示转人工。 ")) : E("", !0),
253
+ (v(!0), m(I, null, R(_(a).messages.value, (s, c) => (v(), m("article", {
254
+ key: `${s.role}-${c}`,
255
+ class: B(["seer-chat__message", `seer-chat__message--${s.role}`])
227
256
  }, [
228
- u("span", H, E(o.role === "user" ? "你" : "AI 客服"), 1),
229
- u("p", null, E(o.content), 1)
257
+ u("span", ee, C(s.role === "user" ? "你" : "AI 客服"), 1),
258
+ u("div", te, [
259
+ (v(!0), m(I, null, R(_(H)(s.content), (f, h) => (v(), m("p", {
260
+ key: h,
261
+ class: "seer-chat__line"
262
+ }, [
263
+ (v(!0), m(I, null, R(f, (p, g) => (v(), m(I, { key: g }, [
264
+ p.kind === "link" ? (v(), m("a", {
265
+ key: 0,
266
+ class: "seer-chat__link",
267
+ href: p.href,
268
+ target: "_blank",
269
+ rel: "noopener noreferrer"
270
+ }, C(p.label), 9, ne)) : (v(), m("span", se, C(p.value), 1))
271
+ ], 64))), 128))
272
+ ]))), 128))
273
+ ])
230
274
  ], 2))), 128))
231
275
  ]),
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),
276
+ _(a).loading.value ? (v(), m("p", ae, "正在回复...")) : E("", !0),
277
+ _(a).error.value ? (v(), m("p", oe, C(_(a).error.value), 1)) : E("", !0),
278
+ _(a).handoffRequested.value ? (v(), m("p", re, " 建议转人工:请留下联系方式或等待客服接入。 ")) : E("", !0),
235
279
  u("form", {
236
280
  class: "seer-chat__form",
237
- onSubmit: D(l, ["prevent"])
281
+ onSubmit: O(r, ["prevent"])
238
282
  }, [
239
- a[4] || (a[4] = u("label", {
283
+ o[6] || (o[6] = u("label", {
240
284
  class: "seer-chat__label",
241
285
  for: "seer-chat-input"
242
286
  }, "问题", -1)),
243
- F(u("textarea", {
287
+ K(u("textarea", {
244
288
  id: "seer-chat-input",
245
- "onUpdate:modelValue": a[1] || (a[1] = (o) => e.value = o),
246
- placeholder: n.placeholder,
247
- disabled: h(s).loading.value,
248
- rows: "3"
249
- }, null, 8, Z), [
250
- [P, e.value]
289
+ "onUpdate:modelValue": o[1] || (o[1] = (s) => t.value = s),
290
+ placeholder: e.placeholder,
291
+ disabled: _(a).loading.value,
292
+ rows: "3",
293
+ onKeydown: D(O(r, ["exact", "prevent"]), ["enter"])
294
+ }, null, 40, le), [
295
+ [F, t.value]
251
296
  ]),
252
- u("div", ee, [
253
- h(s).loading.value ? (v(), p("button", {
297
+ u("div", ie, [
298
+ o[5] || (o[5] = u("span", { class: "seer-chat__hint" }, "Enter 发送 · Shift+Enter 换行", -1)),
299
+ _(a).loading.value ? (v(), m("button", {
254
300
  key: 0,
255
301
  type: "button",
256
- class: "seer-chat__ghost-button",
257
- onClick: a[2] || (a[2] = (o) => h(s).abort())
258
- }, " 停止 ")) : k("", !0),
302
+ class: "seer-chat__stop-button",
303
+ onClick: o[2] || (o[2] = (s) => _(a).abort())
304
+ }, " 停止 ")) : E("", !0),
259
305
  u("button", {
306
+ class: "seer-chat__send-button",
260
307
  type: "submit",
261
- disabled: !c.value
262
- }, "发送", 8, te)
308
+ disabled: !l.value
309
+ }, [...o[4] || (o[4] = [
310
+ u("span", null, "发送", -1),
311
+ u("span", { "aria-hidden": "true" }, "↵", -1)
312
+ ])], 8, ce)
263
313
  ])
264
314
  ], 32)
265
315
  ]));
266
316
  }
267
- }), se = (n, t) => {
268
- const e = n.__vccOpts || n;
269
- for (const [s, c] of t)
270
- e[s] = c;
271
- return e;
272
- }, re = /* @__PURE__ */ se(ne, [["__scopeId", "data-v-163bc07c"]]);
317
+ }), de = (e, n) => {
318
+ const t = e.__vccOpts || e;
319
+ for (const [a, l] of n)
320
+ t[a] = l;
321
+ return t;
322
+ }, ve = /* @__PURE__ */ de(ue, [["__scopeId", "data-v-f2b8b91f"]]);
273
323
  export {
274
- re as SeerChat,
275
- oe as SeerChatPlugin,
276
- V as createSeerClient,
277
- L as useSeerChat
324
+ ve as SeerChat,
325
+ he as SeerChatPlugin,
326
+ U as createSeerClient,
327
+ J as linkAnchorLabel,
328
+ H as toContentLines,
329
+ G as toContentSegments,
330
+ W as useSeerChat
278
331
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seer-ai/seer-vue",
3
- "version": "0.1.0-beta.3",
3
+ "version": "0.1.0-beta.5",
4
4
  "description": "Vue chat plugin for the seer OpenAI-compatible API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,7 +22,8 @@
22
22
  "scripts": {
23
23
  "test": "vitest run",
24
24
  "typecheck": "vue-tsc --noEmit",
25
- "build": "vite build && vue-tsc -p tsconfig.build.json --declaration --emitDeclarationOnly --outDir dist"
25
+ "build": "vite build && vue-tsc -p tsconfig.build.json --declaration --emitDeclarationOnly --outDir dist",
26
+ "prepublishOnly": "npm run build"
26
27
  },
27
28
  "peerDependencies": {
28
29
  "vue": "^3.5.0"