agent-tool-chat 0.1.1 → 1.0.0

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.js CHANGED
@@ -1,17 +1,16 @@
1
- var re = Object.defineProperty;
2
- var ce = (t, e, s) => e in t ? re(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
- var G = (t, e, s) => (ce(t, typeof e != "symbol" ? e + "" : e, s), s);
4
- import { ref as W, computed as Y, onMounted as de, watch as ee, defineComponent as N, openBlock as a, createElementBlock as m, createElementVNode as f, toDisplayString as V, createCommentVNode as z, createBlock as j, resolveDynamicComponent as me, Fragment as K, renderList as U, resolveComponent as S, createVNode as _, withCtx as v, createTextVNode as R, normalizeClass as ne, unref as A, withKeys as pe, Transition as ge, nextTick as fe } from "vue";
5
- import { ElMessageBox as _e } from "element-plus";
6
- class he {
1
+ var Pe = Object.defineProperty;
2
+ var Te = (t, e, s) => e in t ? Pe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
+ var K = (t, e, s) => Te(t, typeof e != "symbol" ? e + "" : e, s);
4
+ import { ref as W, onUnmounted as ze, computed as te, onMounted as Be, watch as le, defineComponent as F, openBlock as u, createElementBlock as x, createElementVNode as y, resolveComponent as P, toDisplayString as L, createCommentVNode as R, createBlock as D, resolveDynamicComponent as He, Fragment as G, renderList as X, createVNode as p, unref as S, withCtx as v, createTextVNode as O, normalizeClass as ie, withKeys as Ne, withDirectives as Ee, Transition as De, vShow as Fe, nextTick as je } from "vue";
5
+ import { ElTable as Oe, ElTableColumn as _e, ElMessageBox as Ue } from "element-plus";
6
+ class Re {
7
7
  constructor(e) {
8
- G(this, "messages", []);
9
- G(this, "config");
10
- G(this, "listeners", /* @__PURE__ */ new Set());
11
- G(this, "abortController", null);
12
- G(this, "_loading", !1);
13
- var s;
14
- this.config = { ...e, maxToolRounds: (s = e.maxToolRounds) != null ? s : 6 };
8
+ K(this, "messages", []);
9
+ K(this, "config");
10
+ K(this, "listeners", /* @__PURE__ */ new Set());
11
+ K(this, "abortController", null);
12
+ K(this, "_loading", !1);
13
+ this.config = { ...e, maxToolRounds: e.maxToolRounds ?? 6 };
15
14
  }
16
15
  get loading() {
17
16
  return this._loading;
@@ -33,55 +32,54 @@ class he {
33
32
  this.listeners.forEach((s) => s(e));
34
33
  }
35
34
  async sendMessage(e) {
36
- var r;
35
+ var o;
37
36
  const s = e.trim();
38
- if (!s || this._loading)
39
- return;
37
+ if (!s || this._loading) return;
40
38
  this._loading = !0, this.abortController = new AbortController(), this.emit({ type: "status", loading: !0 });
41
- const d = { role: "user", content: s };
42
- this.messages.push(d), this.emit({ type: "message", message: d });
39
+ const i = { role: "user", content: s };
40
+ this.messages.push(i), this.emit({ type: "message", message: i });
43
41
  try {
44
42
  let l = 0;
45
- const p = this.config.maxToolRounds;
46
- for (; l < p; ) {
43
+ const _ = this.config.maxToolRounds;
44
+ for (; l < _; ) {
47
45
  l++;
48
- const E = { role: "assistant", content: "" };
49
- this.messages.push(E), this.emit({ type: "message", message: E });
50
- const u = this.buildApiMessages(), n = await this.config.provider.streamChat({
46
+ const b = { role: "assistant", content: "" };
47
+ this.messages.push(b), this.emit({ type: "message", message: b });
48
+ const a = this.buildApiMessages(), r = await this.config.provider.streamChat({
51
49
  config: this.config.providerConfig,
52
- messages: u,
50
+ messages: a,
53
51
  tools: this.config.tools.getDefinitions(),
54
52
  signal: this.abortController.signal,
55
- onContent: (g) => {
56
- E.content += g, this.emit({ type: "stream:delta", delta: { content: g } });
53
+ onContent: (h) => {
54
+ b.content += h, this.emit({ type: "stream:delta", delta: { content: h } });
57
55
  },
58
- onReasoning: (g) => {
59
- this.emit({ type: "stream:delta", delta: { reasoning: g } });
56
+ onReasoning: (h) => {
57
+ this.emit({ type: "stream:delta", delta: { reasoning: h } });
60
58
  }
61
59
  });
62
- if (E.content = n.content, this.emit({ type: "stream:end", content: n.content, reasoning: n.reasoning }), n.tool_calls.length > 0) {
63
- E.tool_calls = n.tool_calls;
64
- for (const g of n.tool_calls) {
65
- this.emit({ type: "tool:start", call: g });
66
- const y = await this.config.tools.execute(g.function.name, g.function.arguments);
67
- this.emit({ type: "tool:end", call: g, output: y }), this.messages.push({
60
+ if (b.content = r.content, this.emit({ type: "stream:end", content: r.content, reasoning: r.reasoning }), r.tool_calls.length > 0) {
61
+ b.tool_calls = r.tool_calls;
62
+ for (const h of r.tool_calls) {
63
+ this.emit({ type: "tool:start", call: h });
64
+ const m = await this.config.tools.execute(h.function.name, h.function.arguments);
65
+ this.emit({ type: "tool:end", call: h, output: m }), this.messages.push({
68
66
  role: "tool",
69
- tool_call_id: g.id,
70
- content: y.result,
71
- name: g.function.name
67
+ tool_call_id: h.id,
68
+ content: m.result,
69
+ name: h.function.name
72
70
  });
73
71
  }
74
72
  continue;
75
73
  }
76
74
  break;
77
75
  }
78
- await ((r = this.config.storage) == null ? void 0 : r.save(this.messages));
76
+ await ((o = this.config.storage) == null ? void 0 : o.save(this.messages));
79
77
  } catch (l) {
80
78
  if ((l == null ? void 0 : l.name) !== "AbortError")
81
- this.emit({ type: "error", error: (l == null ? void 0 : l.message) || "\u8BF7\u6C42\u51FA\u9519" });
79
+ this.emit({ type: "error", error: (l == null ? void 0 : l.message) || "请求出错" });
82
80
  else {
83
- const p = this.messages[this.messages.length - 1];
84
- (p == null ? void 0 : p.role) === "assistant" && !p.content && (p.content = "\uFF08\u5DF2\u505C\u6B62\u751F\u6210\uFF09");
81
+ const _ = this.messages[this.messages.length - 1];
82
+ (_ == null ? void 0 : _.role) === "assistant" && !_.content && (_.content = "(已停止生成)");
85
83
  }
86
84
  } finally {
87
85
  this._loading = !1, this.abortController = null, this.emit({ type: "status", loading: !1 });
@@ -92,152 +90,351 @@ class he {
92
90
  (e = this.abortController) == null || e.abort();
93
91
  }
94
92
  buildApiMessages() {
95
- const e = this.messages, d = e.length > 0 && e[e.length - 1].role === "assistant" && e[e.length - 1].content === "" && !e[e.length - 1].tool_calls ? e.slice(0, -1) : e;
96
- return this.config.systemPrompt ? [{ role: "system", content: this.config.systemPrompt }, ...d] : [...d];
93
+ const e = this.messages, i = e.length > 0 && e[e.length - 1].role === "assistant" && e[e.length - 1].content === "" && !e[e.length - 1].tool_calls ? e.slice(0, -1) : e;
94
+ return this.config.systemPrompt ? [{ role: "system", content: this.config.systemPrompt }, ...i] : [...i];
97
95
  }
98
96
  }
99
- class ve {
97
+ class Ke {
100
98
  constructor() {
101
- G(this, "_definitions", []);
102
- G(this, "_handlers", /* @__PURE__ */ new Map());
99
+ K(this, "_definitions", []);
100
+ K(this, "_handlers", /* @__PURE__ */ new Map());
103
101
  }
104
102
  register(e, s) {
105
103
  return this._definitions.push(e), this._handlers.set(e.function.name, s), this;
106
104
  }
107
105
  registerBatch(e) {
108
- for (const s of e)
109
- this.register(s.definition, s.handler);
106
+ for (const s of e) this.register(s.definition, s.handler);
110
107
  return this;
111
108
  }
112
109
  getDefinitions() {
113
110
  return [...this._definitions];
114
111
  }
115
112
  async execute(e, s) {
116
- const d = this._handlers.get(e);
117
- if (!d)
118
- return { success: !1, result: `\u672A\u77E5\u5DE5\u5177\uFF1A${e}` };
113
+ const i = this._handlers.get(e);
114
+ if (!i) return { success: !1, result: `未知工具:${e}` };
119
115
  try {
120
- const r = s ? JSON.parse(s) : {};
121
- return await d(r);
122
- } catch (r) {
123
- return { success: !1, result: `\u5DE5\u5177\u6267\u884C\u5F02\u5E38\uFF1A${(r == null ? void 0 : r.message) || String(r)}` };
116
+ const o = s ? JSON.parse(s) : {};
117
+ return await i(o);
118
+ } catch (o) {
119
+ return { success: !1, result: `工具执行异常:${(o == null ? void 0 : o.message) || String(o)}` };
124
120
  }
125
121
  }
126
122
  }
127
- function Fe(t) {
123
+ function Le(t) {
128
124
  let e = t.trim().replace(/\/+$/, "");
129
125
  return e = e.replace(/\/v1$/, ""), e;
130
126
  }
131
- function ye() {
127
+ function Je() {
132
128
  return {
133
129
  async streamChat(t) {
134
- var P;
130
+ var g;
135
131
  const {
136
- config: { baseUrl: e, apiKey: s, model: d, temperature: r },
132
+ config: { baseUrl: e, apiKey: s, model: i, temperature: o },
137
133
  messages: l,
138
- tools: p,
139
- signal: E,
140
- onContent: u,
141
- onReasoning: n
134
+ tools: _,
135
+ signal: b,
136
+ onContent: a,
137
+ onReasoning: r
142
138
  } = t;
143
- if (!s)
144
- throw new Error("\u672A\u914D\u7F6E API Key");
145
- const g = `${Fe(e)}/chat/completions`, y = { model: d, messages: l, stream: !0 };
146
- typeof r == "number" && (y.temperature = r), p != null && p.length && (y.tools = p, y.tool_choice = "auto");
147
- const C = await fetch(g, {
139
+ if (!s) throw new Error("未配置 API Key");
140
+ const h = `${Le(e)}/chat/completions`, m = { model: i, messages: l, stream: !0 };
141
+ typeof o == "number" && (m.temperature = o), _ != null && _.length && (m.tools = _, m.tool_choice = "auto");
142
+ const $ = await fetch(h, {
148
143
  method: "POST",
149
144
  headers: {
150
145
  "Content-Type": "application/json",
151
146
  Authorization: `Bearer ${s}`
152
147
  },
153
- body: JSON.stringify(y),
154
- signal: E
148
+ body: JSON.stringify(m),
149
+ signal: b
150
+ });
151
+ if (!$.ok || !$.body) {
152
+ let f = `请求失败(HTTP ${$.status})`;
153
+ try {
154
+ const d = await $.json();
155
+ (g = d == null ? void 0 : d.error) != null && g.message && (f = d.error.message);
156
+ } catch {
157
+ }
158
+ throw new Error(f);
159
+ }
160
+ const H = $.body.getReader(), I = new TextDecoder("utf-8");
161
+ let A = "", w = "", T = "", z = "stop";
162
+ const j = /* @__PURE__ */ new Map(), J = (f) => {
163
+ if (!f) return;
164
+ const d = f.index ?? 0;
165
+ j.has(d) || j.set(d, { id: "", type: "function", function: { name: "", arguments: "" } });
166
+ const V = j.get(d);
167
+ f.id && (V.id = f.id), f.type && (V.type = f.type), f.function && (f.function.name && (V.function.name += f.function.name), f.function.arguments && (V.function.arguments += f.function.arguments));
168
+ }, U = (f) => {
169
+ var E;
170
+ const d = (E = f == null ? void 0 : f.choices) == null ? void 0 : E[0];
171
+ if (!d) return;
172
+ const V = d.delta || {};
173
+ typeof V.content == "string" && V.content && (w += V.content, a == null || a(V.content)), typeof V.reasoning_content == "string" && V.reasoning_content && (T += V.reasoning_content, r == null || r(V.reasoning_content)), Array.isArray(V.tool_calls) && V.tool_calls.forEach((Y) => J(Y)), d.finish_reason && (z = d.finish_reason);
174
+ };
175
+ for (; ; ) {
176
+ const { done: f, value: d } = await H.read();
177
+ if (f) break;
178
+ A += I.decode(d, { stream: !0 });
179
+ let V;
180
+ for (; (V = A.indexOf(`
181
+ `)) !== -1; ) {
182
+ const E = A.slice(0, V).replace(/\r$/, "").trim();
183
+ if (A = A.slice(V + 1), !E || E.startsWith(":") || !E.startsWith("data:")) continue;
184
+ const Y = E.slice(5).trim();
185
+ if (Y === "[DONE]") return N();
186
+ try {
187
+ U(JSON.parse(Y));
188
+ } catch {
189
+ }
190
+ }
191
+ }
192
+ return N();
193
+ function N() {
194
+ const f = Array.from(j.values()).filter((d) => d.function.name);
195
+ return { content: w, reasoning: T, tool_calls: f, finish_reason: z };
196
+ }
197
+ }
198
+ };
199
+ }
200
+ function We() {
201
+ return {
202
+ async streamChat(t) {
203
+ var N;
204
+ const {
205
+ config: { baseUrl: e, model: s, temperature: i },
206
+ messages: o,
207
+ tools: l,
208
+ signal: _,
209
+ onContent: b,
210
+ onReasoning: a
211
+ } = t, r = `${e.trim().replace(/\/+$/, "")}`, h = { model: s, messages: o, stream: !0 };
212
+ typeof i == "number" && (h.temperature = i), l != null && l.length && (h.tools = l, h.tool_choice = "auto");
213
+ const m = await fetch(r, {
214
+ method: "POST",
215
+ headers: { "Content-Type": "application/json" },
216
+ body: JSON.stringify(h),
217
+ signal: _
155
218
  });
156
- if (!C.ok || !C.body) {
157
- let x = `\u8BF7\u6C42\u5931\u8D25\uFF08HTTP ${C.status}\uFF09`;
219
+ if (!m.ok || !m.body) {
220
+ let g = `请求失败(HTTP ${m.status})`;
158
221
  try {
159
- const I = await C.json();
160
- (P = I == null ? void 0 : I.error) != null && P.message && (x = I.error.message);
222
+ const f = await m.json();
223
+ (N = f == null ? void 0 : f.error) != null && N.message && (g = f.error.message);
161
224
  } catch {
162
225
  }
163
- throw new Error(x);
226
+ throw new Error(g);
164
227
  }
165
- const M = C.body.getReader(), O = new TextDecoder("utf-8");
166
- let T = "", h = "", w = "", F = "stop";
167
- const c = /* @__PURE__ */ new Map(), H = (x) => {
168
- var L;
169
- if (!x)
170
- return;
171
- const I = (L = x.index) != null ? L : 0;
172
- c.has(I) || c.set(I, { id: "", type: "function", function: { name: "", arguments: "" } });
173
- const D = c.get(I);
174
- x.id && (D.id = x.id), x.type && (D.type = x.type), x.function && (x.function.name && (D.function.name += x.function.name), x.function.arguments && (D.function.arguments += x.function.arguments));
175
- }, J = (x) => {
176
- var L;
177
- const I = (L = x == null ? void 0 : x.choices) == null ? void 0 : L[0];
178
- if (!I)
179
- return;
180
- const D = I.delta || {};
181
- typeof D.content == "string" && D.content && (h += D.content, u == null || u(D.content)), typeof D.reasoning_content == "string" && D.reasoning_content && (w += D.reasoning_content, n == null || n(D.reasoning_content)), Array.isArray(D.tool_calls) && D.tool_calls.forEach((X) => H(X)), I.finish_reason && (F = I.finish_reason);
228
+ const $ = m.body.getReader(), H = new TextDecoder("utf-8");
229
+ let I = "", A = "", w = "", T = "stop";
230
+ const z = /* @__PURE__ */ new Map(), j = (g) => {
231
+ if (!g) return;
232
+ const f = g.index ?? 0;
233
+ z.has(f) || z.set(f, { id: "", type: "function", function: { name: "", arguments: "" } });
234
+ const d = z.get(f);
235
+ g.id && (d.id = g.id), g.type && (d.type = g.type), g.function && (g.function.name && (d.function.name += g.function.name), g.function.arguments && (d.function.arguments += g.function.arguments));
236
+ }, J = (g) => {
237
+ var V;
238
+ const f = (V = g == null ? void 0 : g.choices) == null ? void 0 : V[0];
239
+ if (!f) return;
240
+ const d = f.delta || {};
241
+ typeof d.content == "string" && d.content && (A += d.content, b == null || b(d.content)), typeof d.reasoning_content == "string" && d.reasoning_content && (w += d.reasoning_content, a == null || a(d.reasoning_content)), Array.isArray(d.tool_calls) && d.tool_calls.forEach((E) => j(E)), f.finish_reason && (T = f.finish_reason);
182
242
  };
183
243
  for (; ; ) {
184
- const { done: x, value: I } = await M.read();
185
- if (x)
186
- break;
187
- T += O.decode(I, { stream: !0 });
188
- let D;
189
- for (; (D = T.indexOf(`
244
+ const { done: g, value: f } = await $.read();
245
+ if (g) break;
246
+ I += H.decode(f, { stream: !0 });
247
+ let d;
248
+ for (; (d = I.indexOf(`
190
249
  `)) !== -1; ) {
191
- const L = T.slice(0, D).replace(/\r$/, "").trim();
192
- if (T = T.slice(D + 1), !L || L.startsWith(":") || !L.startsWith("data:"))
193
- continue;
194
- const X = L.slice(5).trim();
195
- if (X === "[DONE]")
196
- return q();
250
+ const V = I.slice(0, d).replace(/\r$/, "").trim();
251
+ if (I = I.slice(d + 1), !V || V.startsWith(":") || !V.startsWith("data:")) continue;
252
+ const E = V.slice(5).trim();
253
+ if (E === "[DONE]") return U();
197
254
  try {
198
- J(JSON.parse(X));
255
+ J(JSON.parse(E));
199
256
  } catch {
200
257
  }
201
258
  }
202
259
  }
203
- return q();
204
- function q() {
205
- const x = Array.from(c.values()).filter((I) => I.function.name);
206
- return { content: h, reasoning: w, tool_calls: x, finish_reason: F };
260
+ return U();
261
+ function U() {
262
+ const g = Array.from(z.values()).filter((f) => f.function.name);
263
+ return { content: A, reasoning: w, tool_calls: g, finish_reason: T };
207
264
  }
208
265
  }
209
266
  };
210
267
  }
211
- function Ee(t) {
212
- var s, d, r, l, p;
268
+ function qe(t) {
269
+ var s, i, o, l, _;
213
270
  const e = [];
214
- return (s = t.displayHints) != null && s.suggestComponent && e.push(`\u5C55\u793A\u5EFA\u8BAE: \u4F7F\u7528 ${t.displayHints.suggestComponent} \u7EC4\u4EF6`), (d = t.displayHints) != null && d.resultFormat && e.push(`\u683C\u5F0F: ${t.displayHints.resultFormat}`), (l = (r = t.displayHints) == null ? void 0 : r.previewFields) != null && l.length && e.push(`\u9884\u89C8\u5B57\u6BB5: ${t.displayHints.previewFields.join(", ")}`), (p = t.displayHints) != null && p.summaryTemplate && e.push(`\u6982\u8981\u6A21\u677F: ${t.displayHints.summaryTemplate}`), e.length ? e.join(" | ") : "";
271
+ return (s = t.displayHints) != null && s.suggestComponent && e.push(`展示建议: 使用 ${t.displayHints.suggestComponent} 组件`), (i = t.displayHints) != null && i.resultFormat && e.push(`格式: ${t.displayHints.resultFormat}`), (l = (o = t.displayHints) == null ? void 0 : o.previewFields) != null && l.length && e.push(`预览字段: ${t.displayHints.previewFields.join(", ")}`), (_ = t.displayHints) != null && _.summaryTemplate && e.push(`概要模板: ${t.displayHints.summaryTemplate}`), e.length ? e.join(" | ") : "";
215
272
  }
216
- function Ce(t) {
273
+ function Ge(t) {
217
274
  const e = [
218
- "\u4F60\u662F\u4E00\u4E2A AI \u52A9\u624B\uFF0C\u53EF\u4EE5\u5E2E\u52A9\u7528\u6237\u5B8C\u6210\u5404\u79CD\u64CD\u4F5C\u3002",
275
+ "你是一个 AI 助手,可以帮助用户完成各种操作。",
219
276
  "",
220
- "\u4F60\u53EF\u4EE5\u4F7F\u7528\u4EE5\u4E0B\u5DE5\u5177\u5305\uFF1A",
277
+ "你可以使用以下工具包:",
221
278
  ""
222
279
  ];
223
280
  for (const s of t) {
224
- e.push(`\u3010${s.name}\u3011${s.description}`);
225
- for (const d of s.tools) {
226
- const r = Ee(d);
227
- e.push(` - ${d.name}: ${d.description}`), r && e.push(` ${r}`);
281
+ e.push(`【${s.name}】${s.description}`);
282
+ for (const i of s.tools) {
283
+ const o = qe(i);
284
+ e.push(` - ${i.name}: ${i.description}`), o && e.push(` ${o}`);
228
285
  }
229
286
  e.push("");
230
287
  }
231
- return e.push("\u6CE8\u610F\uFF1A"), e.push("1. \u5F53\u4F60\u9700\u8981\u67E5\u8BE2\u6216\u64CD\u4F5C\u6570\u636E\u65F6\uFF0C\u8C03\u7528\u5BF9\u5E94\u5DE5\u5177\u5305\u4E2D\u7684\u51FD\u6570\u3002"), e.push("2. \u5DE5\u5177\u51FD\u6570\u7531\u5BBF\u4E3B\u7CFB\u7EDF\u6267\u884C\uFF0C\u4F60\u53EA\u9700\u8981\u4F20\u9012\u6B63\u786E\u7684\u53C2\u6570\u3002"), e.push("3. \u83B7\u53D6\u5230\u5DE5\u5177\u7ED3\u679C\u540E\uFF0C\u56DE\u590D\u7528\u6237\u5E76\u544A\u77E5\u7ED3\u679C\u3002"), e.push("4. \u5982\u679C\u5DE5\u5177\u8FD4\u56DE\u4E86\u7ED3\u6784\u5316\u6570\u636E\uFF08\u5982\u8BA2\u5355\u4FE1\u606F\u3001\u7CFB\u7EDF\u72B6\u6001\u7B49\uFF09\uFF0C\u5728\u56DE\u590D\u4E2D\u6E05\u6670\u5730\u5C55\u793A\u7ED9\u7528\u6237\u3002"), e.push("5. \u6839\u636E\u7ED3\u679C\u52A8\u6001\u5EFA\u8BAE\u7528\u6237\u63A5\u4E0B\u6765\u53EF\u4EE5\u505A\u4EC0\u4E48\u3002"), e.push("6. \u5982\u679C\u7528\u6237\u4E0A\u4F20\u4E86\u6587\u4EF6\uFF0C\u6587\u4EF6\u683C\u5F0F\u4E3A\uFF08.txt\u3001.json\u3001.geojson\u7B49\u683C\u5F0F\uFF09\uFF0C\u4F60\u5FC5\u987B\u8C03\u7528 open_mapview_file \u5DE5\u5177\u5728\u5730\u56FE\u4E0A\u5C55\u793A\uFF0C\u4E0D\u8981\u53EA\u56DE\u590D\u6587\u5B57\u3002"), e.push(""), e.push("--- \u6587\u4EF6\u4E0A\u4F20\u89C4\u5219 ---"), e.push("\u7528\u6237\u53EF\u80FD\u4E0A\u4F20\u6587\u4EF6\uFF0C\u6587\u4EF6\u4EE5\u5982\u4E0B\u683C\u5F0F\u51FA\u73B0\u5728\u6D88\u606F\u4E2D\uFF1A"), e.push("[Uploaded file: fileId] \u6587\u4EF6\u540D (\u7C7B\u578B, \u5927\u5C0FKB)"), e.push("\u4F60\u65E0\u6CD5\u67E5\u770B\u6587\u4EF6\u5185\u5BB9\uFF0C\u53EA\u80FD\u770B\u5230\u6587\u4EF6\u540D\u548C\u7C7B\u578B\u3002"), e.push("\u4F60\u5FC5\u987B\u6839\u636E\u6587\u4EF6\u540D\u3001\u6269\u5C55\u540D\u548C\u7528\u6237\u7684\u6587\u5B57\u6307\u4EE4\uFF0C\u8C03\u7528\u5BF9\u5E94\u7684\u5DE5\u5177\u6765\u5904\u7406\u6587\u4EF6\u3002"), e.push("\u5982\u679C\u67D0\u4E2A\u5DE5\u5177\u9700\u8981\u5904\u7406\u8BE5\u6587\u4EF6\uFF0C\u5728\u5DE5\u5177\u53C2\u6570\u4E2D\u4F20\u5165 fileId\u3002"), e.push('\u4E0D\u8981\u56DE\u590D\u5047\u6027\u6210\u529F\u6D88\u606F\uFF08\u5982"\u5DF2\u5728\u5730\u56FE\u4E0A\u663E\u793A"\uFF09\uFF0C\u5982\u679C\u4E0D\u8C03\u7528\u5DE5\u5177\uFF0C\u6587\u4EF6\u4E0D\u4F1A\u88AB\u5B9E\u9645\u5904\u7406\u3002'), e.push("\u4E0D\u8981\u7F16\u9020\u6587\u4EF6\u5185\u5BB9\uFF0C\u4E0D\u8981\u5047\u88C5\u4F60\u770B\u5230\u4E86\u6587\u4EF6\u6570\u636E\u3002"), e.join(`
288
+ return e.push("注意:"), e.push("1. 当你需要查询或操作数据时,调用对应工具包中的函数。"), e.push("2. 工具函数由宿主系统执行,你只需要传递正确的参数。"), e.push("3. 获取到工具结果后,回复用户并告知结果。"), e.push("4. 如果工具返回了结构化数据(如订单信息、系统状态等),在回复中清晰地展示给用户。"), e.push("5. 根据结果动态建议用户接下来可以做什么。"), e.push("6. 如果用户上传了文件,文件格式为(.txt、.json、.geojson等格式),你必须调用 open_mapview_file 工具在地图上展示,不要只回复文字。"), e.push(""), e.push("--- 文件上传规则 ---"), e.push("用户可能上传文件,文件以如下格式出现在消息中:"), e.push("[Uploaded file: fileId] 文件名 (类型, 大小KB)"), e.push("你无法查看文件内容,只能看到文件名和类型。"), e.push("你必须根据文件名、扩展名和用户的文字指令,调用对应的工具来处理文件。"), e.push("如果某个工具需要处理该文件,在工具参数中传入 fileId"), e.push('不要回复假性成功消息(如"已在地图上显示"),如果不调用工具,文件不会被实际处理。'), e.push("不要编造文件内容,不要假装你看到了文件数据。"), e.join(`
289
+ `);
290
+ }
291
+ function zs(t, e, s) {
292
+ var l;
293
+ let i = null;
294
+ if (t.type === "component" && t.componentName) {
295
+ let _;
296
+ t.packageId && (_ = e.find((b) => b.id === t.packageId)), !_ && s && (_ = e.find((b) => b.id === s)), (l = _ == null ? void 0 : _.components) != null && l[t.componentName] && (i = _.components[t.componentName]);
297
+ }
298
+ const o = Ye(t);
299
+ return { component: i, block: t, fallbackText: o };
300
+ }
301
+ function Ye(t) {
302
+ switch (t.type) {
303
+ case "table":
304
+ return Xe(t);
305
+ case "card":
306
+ return Qe(t);
307
+ case "list":
308
+ return Ze(t);
309
+ default:
310
+ return JSON.stringify(t.data, null, 2);
311
+ }
312
+ }
313
+ function re(t) {
314
+ return t == null ? null : Array.isArray(t) ? t : typeof t != "object" ? null : Array.isArray(t.data) ? t.data : Array.isArray(t.list) ? t.list : Array.isArray(t.items) ? t.items : [t];
315
+ }
316
+ function Xe(t) {
317
+ const e = re(t.data);
318
+ if (!(e != null && e.length)) return "(无数据)";
319
+ const s = t.title ? `**${t.title}**
320
+
321
+ ` : "", i = Object.keys(e[0]), o = `| ${i.join(" | ")} |`, l = `| ${i.map(() => "---").join(" | ")} |`, _ = e.map((b) => `| ${i.map((a) => String(b[a] ?? "")).join(" | ")} |`).join(`
322
+ `);
323
+ return `${s}${o}
324
+ ${l}
325
+ ${_}`;
326
+ }
327
+ function Qe(t) {
328
+ const e = re(t.data);
329
+ if (!(e != null && e.length)) return "(无数据)";
330
+ const s = t.title ? `**${t.title}**
331
+
332
+ ` : "", i = e.map((o) => Object.entries(o).map(([_, b]) => `- **${_}**: ${b}`).join(`
333
+ `)).join(`
334
+
335
+ ---
336
+
232
337
  `);
338
+ return `${s}${i}`;
339
+ }
340
+ function Ze(t) {
341
+ const e = re(t.data);
342
+ if (!(e != null && e.length)) return "(无数据)";
343
+ const s = t.title ? `**${t.title}**
344
+
345
+ ` : "", i = e.map((o) => `- ${typeof o == "string" ? o : Object.values(o).join(" - ")}`).join(`
346
+ `);
347
+ return `${s}${i}`;
348
+ }
349
+ class et {
350
+ constructor() {
351
+ K(this, "exactHandlers", /* @__PURE__ */ new Map());
352
+ K(this, "regexHandlers", []);
353
+ K(this, "isChatOpen", () => !0);
354
+ }
355
+ setChatOpenGetter(e) {
356
+ this.isChatOpen = e;
357
+ }
358
+ on(e, s) {
359
+ return typeof e == "string" ? (this.exactHandlers.has(e) || this.exactHandlers.set(e, /* @__PURE__ */ new Set()), this.exactHandlers.get(e).add(s), () => this.off(e, s)) : (this.regexHandlers.push({ pattern: e, handler: s }), () => this.off(e, s));
360
+ }
361
+ off(e, s) {
362
+ var i;
363
+ if (typeof e == "string") {
364
+ (i = this.exactHandlers.get(e)) == null || i.delete(s);
365
+ return;
366
+ }
367
+ this.regexHandlers = this.regexHandlers.filter(
368
+ (o) => o.pattern !== e || o.handler !== s
369
+ );
370
+ }
371
+ dispatch(e, s = !1) {
372
+ var i;
373
+ if (!(s && !this.isChatOpen())) {
374
+ (i = this.exactHandlers.get(e.type)) == null || i.forEach((o) => o(e));
375
+ for (const { pattern: o, handler: l } of this.regexHandlers)
376
+ o.test(e.type) && l(e);
377
+ }
378
+ }
379
+ clear() {
380
+ this.exactHandlers.clear(), this.regexHandlers = [];
381
+ }
382
+ }
383
+ function tt() {
384
+ return new et();
233
385
  }
234
- const ue = {
386
+ class st {
387
+ constructor(e, s) {
388
+ K(this, "bus");
389
+ K(this, "rules");
390
+ K(this, "cooldowns", /* @__PURE__ */ new Map());
391
+ K(this, "unsubscribers", []);
392
+ this.bus = e, this.rules = s;
393
+ }
394
+ start(e) {
395
+ for (const s of this.rules) {
396
+ const i = this.bus.on(s.event, (o) => {
397
+ if (this.isOnCooldown(s) || (this.setCooldown(s), s.autoPopup && e.onAutoPopup(), s.action === "silent")) return;
398
+ const l = this.buildPrompt(s, o);
399
+ l && e.onRespond(l);
400
+ });
401
+ this.unsubscribers.push(i);
402
+ }
403
+ }
404
+ stop() {
405
+ for (const e of this.unsubscribers)
406
+ e();
407
+ this.unsubscribers = [], this.cooldowns.clear();
408
+ }
409
+ getBus() {
410
+ return this.bus;
411
+ }
412
+ isOnCooldown(e) {
413
+ if (!e.cooldown) return !1;
414
+ const s = typeof e.event == "string" ? e.event : e.event.source, i = this.cooldowns.get(s);
415
+ return i ? Date.now() < i : !1;
416
+ }
417
+ setCooldown(e) {
418
+ if (!e.cooldown) return;
419
+ const s = typeof e.event == "string" ? e.event : e.event.source;
420
+ this.cooldowns.set(s, Date.now() + e.cooldown);
421
+ }
422
+ buildPrompt(e, s) {
423
+ return e.prompt ? e.prompt.replace(/\{\{payload\.([^}]+)\}\}/g, (i, o) => {
424
+ const l = s.payload[o];
425
+ return l !== void 0 ? String(l) : `{{payload.${o}}}`;
426
+ }) : "";
427
+ }
428
+ }
429
+ const ve = {
235
430
  apiKey: "",
236
431
  baseUrl: "https://api.deepseek.com",
237
432
  model: "deepseek-chat",
238
- temperature: 0
433
+ temperature: 0,
434
+ providerMode: "direct",
435
+ proxyUrl: "http://localhost:3001/api/chat"
239
436
  };
240
- function xe(t) {
437
+ function nt(t) {
241
438
  return {
242
439
  type: "function",
243
440
  function: {
@@ -247,614 +444,752 @@ function xe(t) {
247
444
  }
248
445
  };
249
446
  }
250
- function se() {
447
+ function ue() {
251
448
  return `m_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
252
449
  }
253
- function ae(t) {
450
+ function ot() {
451
+ let t = [], e = "0123456789abcdef";
452
+ for (let i = 0; i < 36; i++)
453
+ t[i] = e.substr(Math.floor(Math.random() * 16), 1);
454
+ return t[14] = "4", t[19] = e.substr(t[19] & 3 | 8, 1), t[8] = t[13] = t[18] = t[23] = "-", t.join("");
455
+ }
456
+ const ye = "agent_chat_device_id";
457
+ function ae() {
458
+ let t = localStorage.getItem(ye);
459
+ return t || (t = ot(), localStorage.setItem(ye, t)), t;
460
+ }
461
+ function de(t) {
462
+ try {
463
+ return new URL(t).origin;
464
+ } catch {
465
+ return "";
466
+ }
467
+ }
468
+ function pe(t) {
254
469
  const e = [];
255
470
  for (const s of t)
256
471
  if (s.role === "user")
257
472
  e.push({ role: "user", content: s.content });
258
473
  else if (s.role === "assistant" && (e.push({ role: "assistant", content: s.content, tool_calls: s.tool_calls }), s.toolResults))
259
- for (const d of s.toolResults)
260
- e.push({ role: "tool", tool_call_id: d.callId, content: d.result, name: d.name });
474
+ for (const i of s.toolResults)
475
+ e.push({ role: "tool", tool_call_id: i.callId, content: i.result, name: i.name });
261
476
  return e;
262
477
  }
263
- function qt(t) {
478
+ function Bs(t) {
479
+ var fe, ge;
264
480
  const {
265
481
  toolPackages: e,
266
482
  onToolCall: s,
267
- provider: d,
268
- providerConfig: r,
483
+ provider: i,
484
+ providerConfig: o,
269
485
  systemPrompt: l,
270
- storagePrefix: p = "agent_chat_",
271
- sendFileToLLM: E = !1
272
- } = t, u = {
273
- messages: `${p}messages`,
274
- settings: `${p}settings`
275
- }, n = W([]), g = W({ ...ue }), y = W(!1), C = W(""), M = /* @__PURE__ */ new Map(), O = new ve();
276
- for (const i of e)
277
- for (const k of i.tools) {
278
- const b = xe(k);
279
- O.register(b, async (o) => {
280
- const B = { packageId: i.id, toolName: k.name, args: o };
281
- return await F(B, i, k);
486
+ storagePrefix: _ = "agent_chat_",
487
+ sendFileToLLM: b = !1
488
+ } = t, a = {
489
+ messages: `${_}messages`,
490
+ settings: `${_}settings`
491
+ }, r = W([]), h = W({ ...ve }), m = W(!1), $ = W(""), H = /* @__PURE__ */ new Map(), I = W(!1);
492
+ let A = null;
493
+ const w = ((fe = t.businessEvents) == null ? void 0 : fe.bus) || tt();
494
+ w.setChatOpenGetter(() => I.value), (ge = t.businessEvents) != null && ge.rules.length && (A = new st(w, t.businessEvents.rules), A.start({
495
+ onAutoPopup: () => {
496
+ I.value = !0;
497
+ },
498
+ onRespond: (n) => {
499
+ $.value = "", !(!h.value.apiKey && h.value.providerMode !== "proxy") && me(n);
500
+ }
501
+ })), ze(() => {
502
+ A == null || A.stop(), Y();
503
+ });
504
+ const T = new Ke();
505
+ for (const n of e)
506
+ for (const C of n.tools) {
507
+ const M = nt(C);
508
+ T.register(M, async (c) => {
509
+ const k = { packageId: n.id, toolName: C.name, args: c };
510
+ return await d(k, n, C);
282
511
  });
283
512
  }
284
- const T = d || ye(), h = new he({
285
- provider: T,
286
- providerConfig: {
287
- baseUrl: g.value.baseUrl,
288
- apiKey: g.value.apiKey,
289
- model: g.value.model,
290
- temperature: g.value.temperature,
291
- ...r
292
- },
293
- tools: O,
294
- systemPrompt: l || Ce(e)
513
+ const z = Je(), j = We(), J = i || {
514
+ streamChat(n) {
515
+ return (h.value.providerMode === "proxy" ? j : z).streamChat(n);
516
+ }
517
+ };
518
+ function U() {
519
+ const n = { ...o };
520
+ return h.value.providerMode === "proxy" ? {
521
+ ...n,
522
+ baseUrl: h.value.proxyUrl,
523
+ apiKey: "",
524
+ model: h.value.model,
525
+ temperature: h.value.temperature
526
+ } : {
527
+ ...n,
528
+ baseUrl: h.value.baseUrl,
529
+ apiKey: h.value.apiKey,
530
+ model: h.value.model,
531
+ temperature: h.value.temperature
532
+ };
533
+ }
534
+ const N = new Re({
535
+ provider: J,
536
+ providerConfig: U(),
537
+ tools: T,
538
+ systemPrompt: l || Ge(e)
295
539
  });
296
- let w = null;
297
- async function F(i, k, b) {
298
- const o = {
540
+ let g = null;
541
+ const f = [];
542
+ async function d(n, C, M) {
543
+ const c = {
299
544
  toolCallId: `${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
300
- packageId: i.packageId,
301
- toolName: i.toolName,
302
- args: i.args
545
+ packageId: n.packageId,
546
+ toolName: n.toolName,
547
+ args: n.args
303
548
  };
304
549
  try {
305
- const B = await s(o);
306
- return w = { pkg: k, toolDef: b, data: B }, { success: !0, result: typeof B == "string" ? B : JSON.stringify(B) };
307
- } catch (B) {
308
- return { success: !1, result: (B == null ? void 0 : B.message) || "\u5DE5\u5177\u6267\u884C\u5931\u8D25" };
550
+ const k = await s(c);
551
+ return g = { pkg: C, toolDef: M, data: k, args: n.args }, { success: !0, result: typeof k == "string" ? k : JSON.stringify(k) };
552
+ } catch (k) {
553
+ return { success: !1, result: (k == null ? void 0 : k.message) || "工具执行失败" };
309
554
  }
310
555
  }
311
- function c() {
312
- var $;
313
- if (!w)
314
- return;
315
- const { pkg: i, toolDef: k, data: b } = w, o = k.displayHints;
316
- if (!o)
317
- return;
318
- const B = n.value[n.value.length - 1];
556
+ function V() {
557
+ var he;
558
+ if (!g) return;
559
+ const { pkg: n, toolDef: C, data: M, args: c } = g, k = C.displayHints;
560
+ if (!k) return;
561
+ const B = r.value[r.value.length - 1];
319
562
  if (!(!B || B.role !== "assistant")) {
320
- if (o.suggestComponent) {
321
- let te = b;
322
- if (($ = b == null ? void 0 : b.data) != null && $.fileId) {
323
- const Z = M.get(b.data.fileId);
324
- Z && (te = Z.name.endsWith(".geojson") || Z.name.endsWith(".json") ? { data: { wkt: "", geojson: Z.data } } : { data: { wkt: Z.data, geojson: "" } });
563
+ if (k.suggestComponent) {
564
+ let q = M;
565
+ if ((he = M == null ? void 0 : M.data) != null && he.fileId) {
566
+ const ne = H.get(M.data.fileId);
567
+ ne && (q = ne.name.endsWith(".geojson") || ne.name.endsWith(".json") ? { data: { wkt: "", geojson: ne.data } } : { data: { wkt: ne.data, geojson: "" } });
325
568
  }
326
569
  B.renderBlocks = [{
327
570
  type: "component",
328
- packageId: i.id,
329
- componentName: o.suggestComponent,
330
- data: te
331
- }], console.log("resolvedData===", te);
571
+ packageId: n.id,
572
+ componentName: k.suggestComponent,
573
+ data: q
574
+ }], console.log("resolvedData===", q);
575
+ } else if (k.resultFormat === "table" || k.resultFormat === "card" || k.resultFormat === "list") {
576
+ const q = re(M);
577
+ q != null && q.length && (B.renderBlocks = [{
578
+ type: k.resultFormat,
579
+ title: ee(k.summaryTemplate, c),
580
+ data: q,
581
+ fields: k.previewFields,
582
+ labelField: k.labelField,
583
+ selectable: k.selectable
584
+ }]);
332
585
  }
333
- o.suggestedNext && (B.suggestedNext = o.suggestedNext);
586
+ if (k.suggestedNext)
587
+ if (k.suggestedNextEvent) {
588
+ const q = k.suggestedNextEvent, ne = w.on(q, () => E(q));
589
+ f.push({ event: q, text: k.suggestedNext, unsub: ne });
590
+ } else
591
+ B.suggestedNext = k.suggestedNext;
334
592
  }
335
593
  }
336
- const H = /* @__PURE__ */ new Map();
337
- h.on((i) => {
338
- var k, b;
339
- switch (i.type) {
594
+ function E(n) {
595
+ const C = f.findIndex((c) => c.event === n);
596
+ if (C === -1) return;
597
+ const M = f[C];
598
+ M.unsub(), f.splice(C, 1);
599
+ for (let c = r.value.length - 1; c >= 0; c--) {
600
+ const k = r.value[c];
601
+ if (k.role === "assistant") {
602
+ k.suggestedNext = M.text;
603
+ break;
604
+ }
605
+ }
606
+ }
607
+ function Y() {
608
+ for (const n of f)
609
+ n.unsub();
610
+ f.length = 0;
611
+ }
612
+ function ee(n, C) {
613
+ if (n)
614
+ return n.replace(/\{(\w+)\}/g, (M, c) => C[c] !== void 0 ? String(C[c]) : M);
615
+ }
616
+ const Q = /* @__PURE__ */ new Map();
617
+ N.on((n) => {
618
+ var C, M;
619
+ switch (n.type) {
340
620
  case "message": {
341
- if (i.message.role === "tool")
342
- break;
343
- const o = {
344
- id: se(),
345
- role: i.message.role,
346
- content: i.message.content,
621
+ if (n.message.role === "tool") break;
622
+ const c = {
623
+ id: ue(),
624
+ role: n.message.role,
625
+ content: n.message.content,
347
626
  reasoning: "",
348
- status: i.message.role === "assistant" ? "streaming" : "done",
627
+ status: n.message.role === "assistant" ? "streaming" : "done",
349
628
  timestamp: Date.now(),
350
- tool_calls: i.message.tool_calls
629
+ tool_calls: n.message.tool_calls
351
630
  };
352
- n.value.push(o);
631
+ r.value.push(c);
353
632
  break;
354
633
  }
355
634
  case "stream:delta": {
356
- const o = n.value[n.value.length - 1];
357
- (o == null ? void 0 : o.role) === "assistant" && o.status === "streaming" && (i.delta.content && (o.content += i.delta.content), i.delta.reasoning && (o.reasoning = (o.reasoning || "") + i.delta.reasoning));
635
+ const c = r.value[r.value.length - 1];
636
+ (c == null ? void 0 : c.role) === "assistant" && c.status === "streaming" && (n.delta.content && (c.content += n.delta.content), n.delta.reasoning && (c.reasoning = (c.reasoning || "") + n.delta.reasoning));
358
637
  break;
359
638
  }
360
639
  case "stream:end": {
361
- const o = n.value[n.value.length - 1];
362
- (o == null ? void 0 : o.role) === "assistant" && (o.content = i.content, i.reasoning && (o.reasoning = i.reasoning));
640
+ const c = r.value[r.value.length - 1];
641
+ (c == null ? void 0 : c.role) === "assistant" && (c.content = n.content, n.reasoning && (c.reasoning = n.reasoning));
363
642
  break;
364
643
  }
365
644
  case "tool:start": {
366
- const o = n.value[n.value.length - 1];
367
- if (!o || o.role !== "assistant")
368
- break;
369
- o.tool_calls || (o.tool_calls = []), o.toolResults || (o.toolResults = []);
370
- const B = o.toolResults.length;
371
- o.toolResults.push({
372
- callId: i.call.id,
373
- name: i.call.function.name,
374
- arguments: i.call.function.arguments,
645
+ const c = r.value[r.value.length - 1];
646
+ if (!c || c.role !== "assistant") break;
647
+ c.tool_calls || (c.tool_calls = []), c.toolResults || (c.toolResults = []);
648
+ const k = c.toolResults.length;
649
+ c.toolResults.push({
650
+ callId: n.call.id,
651
+ name: n.call.function.name,
652
+ arguments: n.call.function.arguments,
375
653
  result: "",
376
654
  success: !1,
377
655
  status: "running"
378
- }), H.set(i.call.id, { msgIndex: n.value.length - 1, toolIndex: B }), o.tool_calls.find(($) => $.id === i.call.id) || o.tool_calls.push({
379
- id: i.call.id,
656
+ }), Q.set(n.call.id, { msgIndex: r.value.length - 1, toolIndex: k }), c.tool_calls.find((B) => B.id === n.call.id) || c.tool_calls.push({
657
+ id: n.call.id,
380
658
  type: "function",
381
659
  function: {
382
- name: i.call.function.name,
383
- arguments: i.call.function.arguments
660
+ name: n.call.function.name,
661
+ arguments: n.call.function.arguments
384
662
  }
385
663
  });
386
664
  break;
387
665
  }
388
666
  case "tool:end": {
389
- const o = H.get(i.call.id);
390
- if (!o)
391
- break;
392
- const B = (b = (k = n.value[o.msgIndex]) == null ? void 0 : k.toolResults) == null ? void 0 : b[o.toolIndex];
393
- B && (B.result = i.output.result, B.success = i.output.success, B.status = i.output.success ? "success" : "error"), H.delete(i.call.id);
667
+ const c = Q.get(n.call.id);
668
+ if (!c) break;
669
+ const k = (M = (C = r.value[c.msgIndex]) == null ? void 0 : C.toolResults) == null ? void 0 : M[c.toolIndex];
670
+ k && (k.result = n.output.result, k.success = n.output.success, k.status = n.output.success ? "success" : "error"), Q.delete(n.call.id);
394
671
  break;
395
672
  }
396
673
  case "error": {
397
- C.value = i.error;
398
- const o = n.value[n.value.length - 1];
399
- (o == null ? void 0 : o.role) === "assistant" && (o.status = "error", o.error = i.error);
674
+ $.value = n.error;
675
+ const c = r.value[r.value.length - 1];
676
+ (c == null ? void 0 : c.role) === "assistant" && (c.status = "error", c.error = n.error);
400
677
  break;
401
678
  }
402
679
  case "status": {
403
- if (y.value = i.loading, !i.loading) {
404
- const o = n.value[n.value.length - 1];
405
- (o == null ? void 0 : o.role) === "assistant" && o.status === "streaming" && (o.status = "done", o.content || (o.content = "\uFF08\u5DF2\u505C\u6B62\u751F\u6210\uFF09")), c();
680
+ if (m.value = n.loading, !n.loading) {
681
+ const c = r.value[r.value.length - 1];
682
+ (c == null ? void 0 : c.role) === "assistant" && c.status === "streaming" && (c.status = "done", c.content || (c.content = "(已停止生成)")), V();
406
683
  }
407
684
  break;
408
685
  }
409
686
  }
410
687
  });
411
- function J() {
688
+ function ce() {
412
689
  try {
413
- const i = localStorage.getItem(u.settings);
414
- i && (g.value = { ...ue, ...JSON.parse(i) });
690
+ const n = localStorage.getItem(a.settings);
691
+ n && (h.value = { ...ve, ...JSON.parse(n) });
415
692
  } catch {
416
693
  }
417
694
  }
418
- function q() {
695
+ function Z(n) {
696
+ for (const C of n)
697
+ if (C.files)
698
+ for (const M of C.files)
699
+ M.id && H.set(M.id, M);
700
+ }
701
+ async function we() {
702
+ if (h.value.providerMode === "proxy") {
703
+ try {
704
+ const n = de(h.value.proxyUrl);
705
+ if (!n) return;
706
+ const C = await fetch(`${n}/api/messages?device_id=${encodeURIComponent(ae())}`);
707
+ if (!C.ok) return;
708
+ const M = await C.json(), c = M == null ? void 0 : M.messages;
709
+ Array.isArray(c) && (r.value = c, Z(c), N.initialize(pe(c)));
710
+ } catch {
711
+ }
712
+ return;
713
+ }
419
714
  try {
420
- const i = localStorage.getItem(u.messages);
421
- if (i) {
422
- const k = JSON.parse(i);
423
- if (Array.isArray(k)) {
424
- n.value = k;
425
- for (const b of k)
426
- if (b.files)
427
- for (const o of b.files)
428
- o.id && M.set(o.id, o);
429
- h.initialize(ae(k));
430
- }
715
+ const n = localStorage.getItem(a.messages);
716
+ if (n) {
717
+ const C = JSON.parse(n);
718
+ Array.isArray(C) && (r.value = C, Z(C), N.initialize(pe(C)));
431
719
  }
432
720
  } catch {
433
721
  }
434
722
  }
435
- function P(i) {
436
- g.value = { ...i }, localStorage.setItem(u.settings, JSON.stringify(i)), h.updateProviderConfig({
437
- baseUrl: i.baseUrl,
438
- apiKey: i.apiKey,
439
- model: i.model,
440
- temperature: i.temperature
723
+ function ke(n) {
724
+ h.value = { ...n }, localStorage.setItem(a.settings, JSON.stringify(n)), n.providerMode === "proxy" ? N.updateProviderConfig({
725
+ baseUrl: n.proxyUrl,
726
+ apiKey: "",
727
+ model: n.model,
728
+ temperature: n.temperature
729
+ }) : N.updateProviderConfig({
730
+ baseUrl: n.baseUrl,
731
+ apiKey: n.apiKey,
732
+ model: n.model,
733
+ temperature: n.temperature
441
734
  });
442
735
  }
443
- function x() {
736
+ async function Ce() {
737
+ if (h.value.providerMode === "proxy") {
738
+ try {
739
+ const n = de(h.value.proxyUrl);
740
+ if (!n) return;
741
+ await fetch(`${n}/api/messages`, {
742
+ method: "POST",
743
+ headers: { "Content-Type": "application/json" },
744
+ body: JSON.stringify({ device_id: ae(), messages: r.value })
745
+ });
746
+ } catch {
747
+ }
748
+ return;
749
+ }
444
750
  try {
445
- localStorage.setItem(u.messages, JSON.stringify(n.value));
751
+ localStorage.setItem(a.messages, JSON.stringify(r.value));
446
752
  } catch {
447
753
  }
448
754
  }
449
- function I(i) {
450
- return i.startsWith("data:");
755
+ function $e(n) {
756
+ return n.startsWith("data:");
451
757
  }
452
- async function D(i, k) {
453
- const b = i.trim();
454
- if (!b && (!k || k.length === 0))
455
- return;
456
- if (C.value = "", !g.value.apiKey) {
457
- C.value = "\u8BF7\u5148\u914D\u7F6E API Key\u3002";
758
+ async function me(n, C) {
759
+ const M = n.trim();
760
+ if (!M && (!C || C.length === 0)) return;
761
+ if ($.value = "", h.value.providerMode === "direct" && !h.value.apiKey) {
762
+ $.value = "请先配置 API Key。";
458
763
  return;
459
764
  }
460
- if (h.updateProviderConfig({
461
- baseUrl: g.value.baseUrl,
462
- apiKey: g.value.apiKey,
463
- model: g.value.model,
464
- temperature: g.value.temperature
465
- }), w = null, H.clear(), k && k.length > 0) {
466
- for (const $ of k)
467
- $.id = se(), M.set($.id, { ...$ });
468
- const B = {
469
- id: se(),
765
+ if (N.updateProviderConfig(U()), g = null, Q.clear(), C && C.length > 0) {
766
+ for (const B of C)
767
+ B.id = ue(), H.set(B.id, { ...B });
768
+ const k = {
769
+ id: ue(),
470
770
  role: "user",
471
- content: b,
771
+ content: M,
472
772
  status: "done",
473
773
  timestamp: Date.now(),
474
- files: k
774
+ files: C
475
775
  };
476
- n.value.push(B), h.initialize(ae(n.value));
776
+ r.value.push(k), N.initialize(pe(r.value));
477
777
  }
478
- let o = b;
479
- k && k.length > 0 && (E ? o = k.map(($) => I($.data) ? `[File: ${$.name} (${$.type}, ${($.size / 1024).toFixed(1)}KB)]
480
- ${$.data}` : `[File: ${$.name} (${$.type}, ${($.size / 1024).toFixed(1)}KB)]
778
+ let c = M;
779
+ C && C.length > 0 && (b ? c = C.map((B) => $e(B.data) ? `[File: ${B.name} (${B.type}, ${(B.size / 1024).toFixed(1)}KB)]
780
+ ${B.data}` : `[File: ${B.name} (${B.type}, ${(B.size / 1024).toFixed(1)}KB)]
481
781
  \`\`\`
482
- ${$.data}
782
+ ${B.data}
483
783
  \`\`\``).join(`
484
784
 
485
- `) + (b ? `
785
+ `) + (M ? `
486
786
 
487
- ${b}` : "") : o = k.map(
488
- ($) => `[Uploaded file: ${$.id}] ${$.name} (${$.type}, ${($.size / 1024).toFixed(1)}KB)`
787
+ ${M}` : "") : c = C.map(
788
+ (B) => `[Uploaded file: ${B.id}] ${B.name} (${B.type}, ${(B.size / 1024).toFixed(1)}KB)`
489
789
  ).join(`
490
- `) + (b ? `
790
+ `) + (M ? `
491
791
 
492
- ${b}` : "")), await h.sendMessage(o);
493
- }
494
- function L() {
495
- h.stop();
496
- }
497
- function X() {
498
- h.clear(), n.value = [], C.value = "", w = null, M.clear(), localStorage.removeItem(u.messages);
499
- }
500
- const ie = Y(() => !!g.value.apiKey);
501
- return de(() => {
502
- J(), q();
503
- }), ee(n, () => x(), { deep: !0 }), {
504
- messages: n,
505
- settings: g,
506
- loading: y,
507
- errorMsg: C,
508
- hasApiKey: ie,
509
- toolPackages: e,
510
- fileStore: M,
511
- sendMessage: D,
512
- stopGeneration: L,
513
- clearMessages: X,
514
- saveSettings: P
515
- };
516
- }
517
- function Gt(t, e, s) {
518
- var l;
519
- let d = null;
520
- if (t.type === "component" && t.componentName) {
521
- let p;
522
- t.packageId && (p = e.find((E) => E.id === t.packageId)), !p && s && (p = e.find((E) => E.id === s)), (l = p == null ? void 0 : p.components) != null && l[t.componentName] && (d = p.components[t.componentName]);
792
+ ${M}` : "")), await N.sendMessage(c);
523
793
  }
524
- const r = De(t);
525
- return { component: d, block: t, fallbackText: r };
526
- }
527
- function De(t) {
528
- switch (t.type) {
529
- case "table":
530
- return ke(t);
531
- case "card":
532
- return Be(t);
533
- case "list":
534
- return we(t);
535
- default:
536
- return JSON.stringify(t.data, null, 2);
794
+ function Se() {
795
+ N.stop();
537
796
  }
538
- }
539
- function ke(t) {
540
- const e = t.data;
541
- if (!e)
542
- return "";
543
- const s = Array.isArray(e) ? e : e.list || e.items || [e];
544
- if (!s.length)
545
- return "\uFF08\u65E0\u6570\u636E\uFF09";
546
- const d = t.title ? `**${t.title}**
547
-
548
- ` : "", r = Object.keys(s[0]), l = `| ${r.join(" | ")} |`, p = `| ${r.map(() => "---").join(" | ")} |`, E = s.map((u) => `| ${r.map((n) => {
549
- var g;
550
- return String((g = u[n]) != null ? g : "");
551
- }).join(" | ")} |`).join(`
552
- `);
553
- return `${d}${l}
554
- ${p}
555
- ${E}`;
556
- }
557
- function Be(t) {
558
- const e = t.data;
559
- if (!e)
560
- return "";
561
- const s = Array.isArray(e) ? e : e.list || e.items || [e];
562
- if (!s.length)
563
- return "\uFF08\u65E0\u6570\u636E\uFF09";
564
- const d = t.title ? `**${t.title}**
565
-
566
- ` : "", r = s.map((l) => Object.entries(l).map(([E, u]) => `- **${E}**: ${u}`).join(`
567
- `)).join(`
568
-
569
- ---
570
-
571
- `);
572
- return `${d}${r}`;
573
- }
574
- function we(t) {
575
- const e = t.data;
576
- if (!e)
577
- return "";
578
- const s = Array.isArray(e) ? e : e.list || e.items || [e];
579
- if (!s.length)
580
- return "\uFF08\u65E0\u6570\u636E\uFF09";
581
- const d = t.title ? `**${t.title}**
582
-
583
- ` : "", r = s.map((l) => `- ${typeof l == "string" ? l : Object.values(l).join(" - ")}`).join(`
584
- `);
585
- return `${d}${r}`;
797
+ async function Me() {
798
+ if (Ve(), N.clear(), r.value = [], $.value = "", g = null, Y(), H.clear(), h.value.providerMode === "proxy")
799
+ try {
800
+ const n = de(h.value.proxyUrl);
801
+ n && await fetch(`${n}/api/messages?device_id=${encodeURIComponent(ae())}`, { method: "DELETE" });
802
+ } catch {
803
+ }
804
+ else
805
+ localStorage.removeItem(a.messages);
806
+ }
807
+ const Ie = te(() => h.value.providerMode === "proxy" || !!h.value.apiKey);
808
+ Be(() => {
809
+ ce(), we();
810
+ });
811
+ let se = null;
812
+ function Ae() {
813
+ se && clearTimeout(se), se = setTimeout(() => {
814
+ se = null, Ce();
815
+ }, 400);
816
+ }
817
+ function Ve() {
818
+ se && (clearTimeout(se), se = null);
819
+ }
820
+ return le(r, () => Ae(), { deep: !0 }), {
821
+ messages: r,
822
+ settings: h,
823
+ loading: m,
824
+ errorMsg: $,
825
+ hasApiKey: Ie,
826
+ toolPackages: e,
827
+ fileStore: H,
828
+ visible: I,
829
+ eventBus: w,
830
+ deviceId: ae(),
831
+ sendMessage: me,
832
+ stopGeneration: Se,
833
+ clearMessages: Me,
834
+ saveSettings: ke
835
+ };
586
836
  }
587
837
  /*! Element Plus Icons Vue v2.3.2 */
588
- var Ae = /* @__PURE__ */ N({
838
+ var at = /* @__PURE__ */ F({
589
839
  name: "ChatDotRound",
590
840
  __name: "chat-dot-round",
591
841
  setup(t) {
592
- return (e, s) => (a(), m("svg", {
842
+ return (e, s) => (u(), x("svg", {
593
843
  xmlns: "http://www.w3.org/2000/svg",
594
844
  viewBox: "0 0 1024 1024"
595
845
  }, [
596
- f("path", {
846
+ y("path", {
597
847
  fill: "currentColor",
598
848
  d: "m174.72 855.68 135.296-45.12 23.68 11.84C388.096 849.536 448.576 864 512 864c211.84 0 384-166.784 384-352S723.84 160 512 160 128 326.784 128 512c0 69.12 24.96 139.264 70.848 199.232l22.08 28.8-46.272 115.584zm-45.248 82.56A32 32 0 0 1 89.6 896l58.368-145.92C94.72 680.32 64 596.864 64 512 64 299.904 256 96 512 96s448 203.904 448 416-192 416-448 416a461.06 461.06 0 0 1-206.912-48.384l-175.616 58.56z"
599
849
  }),
600
- f("path", {
850
+ y("path", {
601
851
  fill: "currentColor",
602
852
  d: "M512 563.2a51.2 51.2 0 1 1 0-102.4 51.2 51.2 0 0 1 0 102.4m192 0a51.2 51.2 0 1 1 0-102.4 51.2 51.2 0 0 1 0 102.4m-384 0a51.2 51.2 0 1 1 0-102.4 51.2 51.2 0 0 1 0 102.4"
603
853
  })
604
854
  ]));
605
855
  }
606
- }), be = Ae, $e = /* @__PURE__ */ N({
856
+ }), lt = at, it = /* @__PURE__ */ F({
857
+ name: "Close",
858
+ __name: "close",
859
+ setup(t) {
860
+ return (e, s) => (u(), x("svg", {
861
+ xmlns: "http://www.w3.org/2000/svg",
862
+ viewBox: "0 0 1024 1024"
863
+ }, [
864
+ y("path", {
865
+ fill: "currentColor",
866
+ d: "M764.288 214.592 512 466.88 259.712 214.592a31.936 31.936 0 0 0-45.12 45.12L466.752 512 214.528 764.224a31.936 31.936 0 1 0 45.12 45.184L512 557.184l252.288 252.288a31.936 31.936 0 0 0 45.12-45.12L557.12 512.064l252.288-252.352a31.936 31.936 0 1 0-45.12-45.184z"
867
+ })
868
+ ]));
869
+ }
870
+ }), rt = it, ct = /* @__PURE__ */ F({
607
871
  name: "Delete",
608
872
  __name: "delete",
609
873
  setup(t) {
610
- return (e, s) => (a(), m("svg", {
874
+ return (e, s) => (u(), x("svg", {
611
875
  xmlns: "http://www.w3.org/2000/svg",
612
876
  viewBox: "0 0 1024 1024"
613
877
  }, [
614
- f("path", {
878
+ y("path", {
615
879
  fill: "currentColor",
616
880
  d: "M160 256H96a32 32 0 0 1 0-64h256V95.936a32 32 0 0 1 32-32h256a32 32 0 0 1 32 32V192h256a32 32 0 1 1 0 64h-64v672a32 32 0 0 1-32 32H192a32 32 0 0 1-32-32zm448-64v-64H416v64zM224 896h576V256H224zm192-128a32 32 0 0 1-32-32V416a32 32 0 0 1 64 0v320a32 32 0 0 1-32 32m192 0a32 32 0 0 1-32-32V416a32 32 0 0 1 64 0v320a32 32 0 0 1-32 32"
617
881
  })
618
882
  ]));
619
883
  }
620
- }), Se = $e, Ie = /* @__PURE__ */ N({
884
+ }), ut = ct, dt = /* @__PURE__ */ F({
621
885
  name: "Document",
622
886
  __name: "document",
623
887
  setup(t) {
624
- return (e, s) => (a(), m("svg", {
888
+ return (e, s) => (u(), x("svg", {
625
889
  xmlns: "http://www.w3.org/2000/svg",
626
890
  viewBox: "0 0 1024 1024"
627
891
  }, [
628
- f("path", {
892
+ y("path", {
629
893
  fill: "currentColor",
630
894
  d: "M832 384H576V128H192v768h640zm-26.496-64L640 154.496V320zM160 64h480l256 256v608a32 32 0 0 1-32 32H160a32 32 0 0 1-32-32V96a32 32 0 0 1 32-32m160 448h384v64H320zm0-192h160v64H320zm0 384h384v64H320z"
631
895
  })
632
896
  ]));
633
897
  }
634
- }), le = Ie, Me = /* @__PURE__ */ N({
898
+ }), be = dt, pt = /* @__PURE__ */ F({
899
+ name: "FullScreen",
900
+ __name: "full-screen",
901
+ setup(t) {
902
+ return (e, s) => (u(), x("svg", {
903
+ xmlns: "http://www.w3.org/2000/svg",
904
+ viewBox: "0 0 1024 1024"
905
+ }, [
906
+ y("path", {
907
+ fill: "currentColor",
908
+ d: "m160 96.064 192 .192a32 32 0 0 1 0 64l-192-.192V352a32 32 0 0 1-64 0V96h64zm0 831.872V928H96V672a32 32 0 1 1 64 0v191.936l192-.192a32 32 0 1 1 0 64zM864 96.064V96h64v256a32 32 0 1 1-64 0V160.064l-192 .192a32 32 0 1 1 0-64zm0 831.872-192-.192a32 32 0 0 1 0-64l192 .192V672a32 32 0 1 1 64 0v256h-64z"
909
+ })
910
+ ]));
911
+ }
912
+ }), mt = pt, ft = /* @__PURE__ */ F({
913
+ name: "InfoFilled",
914
+ __name: "info-filled",
915
+ setup(t) {
916
+ return (e, s) => (u(), x("svg", {
917
+ xmlns: "http://www.w3.org/2000/svg",
918
+ viewBox: "0 0 1024 1024"
919
+ }, [
920
+ y("path", {
921
+ fill: "currentColor",
922
+ d: "M512 64a448 448 0 1 1 0 896.064A448 448 0 0 1 512 64m67.2 275.072c33.28 0 60.288-23.104 60.288-57.344s-27.072-57.344-60.288-57.344c-33.28 0-60.16 23.104-60.16 57.344s26.88 57.344 60.16 57.344M590.912 699.2c0-6.848 2.368-24.64 1.024-34.752l-52.608 60.544c-10.88 11.456-24.512 19.392-30.912 17.28a12.99 12.99 0 0 1-8.256-14.72l87.68-276.992c7.168-35.136-12.544-67.2-54.336-71.296-44.096 0-108.992 44.736-148.48 101.504 0 6.784-1.28 23.68.064 33.792l52.544-60.608c10.88-11.328 23.552-19.328 29.952-17.152a12.8 12.8 0 0 1 7.808 16.128L388.48 728.576c-10.048 32.256 8.96 63.872 55.04 71.04 67.84 0 107.904-43.648 147.456-100.416z"
923
+ })
924
+ ]));
925
+ }
926
+ }), gt = ft, ht = /* @__PURE__ */ F({
635
927
  name: "Paperclip",
636
928
  __name: "paperclip",
637
929
  setup(t) {
638
- return (e, s) => (a(), m("svg", {
930
+ return (e, s) => (u(), x("svg", {
639
931
  xmlns: "http://www.w3.org/2000/svg",
640
932
  viewBox: "0 0 1024 1024"
641
933
  }, [
642
- f("path", {
934
+ y("path", {
643
935
  fill: "currentColor",
644
936
  d: "M602.496 240.448A192 192 0 1 1 874.048 512l-316.8 316.8A256 256 0 0 1 195.2 466.752L602.496 59.456l45.248 45.248L240.448 512A192 192 0 0 0 512 783.552l316.8-316.8a128 128 0 1 0-181.056-181.056L353.6 579.904a32 32 0 1 0 45.248 45.248l294.144-294.144 45.312 45.248L444.096 670.4a96 96 0 1 1-135.744-135.744z"
645
937
  })
646
938
  ]));
647
939
  }
648
- }), Ve = Me, ze = /* @__PURE__ */ N({
940
+ }), _t = ht, vt = /* @__PURE__ */ F({
649
941
  name: "Picture",
650
942
  __name: "picture",
651
943
  setup(t) {
652
- return (e, s) => (a(), m("svg", {
944
+ return (e, s) => (u(), x("svg", {
653
945
  xmlns: "http://www.w3.org/2000/svg",
654
946
  viewBox: "0 0 1024 1024"
655
947
  }, [
656
- f("path", {
948
+ y("path", {
657
949
  fill: "currentColor",
658
950
  d: "M160 160v704h704V160zm-32-64h768a32 32 0 0 1 32 32v768a32 32 0 0 1-32 32H128a32 32 0 0 1-32-32V128a32 32 0 0 1 32-32"
659
951
  }),
660
- f("path", {
952
+ y("path", {
661
953
  fill: "currentColor",
662
954
  d: "M384 288q64 0 64 64t-64 64-64-64 64-64M185.408 876.992l-50.816-38.912L350.72 556.032a96 96 0 0 1 134.592-17.856l1.856 1.472 122.88 99.136a32 32 0 0 0 44.992-4.864l216-269.888 49.92 39.936-215.808 269.824-.256.32a96 96 0 0 1-135.04 14.464l-122.88-99.072-.64-.512a32 32 0 0 0-44.8 5.952z"
663
955
  })
664
956
  ]));
665
957
  }
666
- }), Te = ze, Pe = /* @__PURE__ */ N({
958
+ }), yt = vt, xt = /* @__PURE__ */ F({
667
959
  name: "Promotion",
668
960
  __name: "promotion",
669
961
  setup(t) {
670
- return (e, s) => (a(), m("svg", {
962
+ return (e, s) => (u(), x("svg", {
671
963
  xmlns: "http://www.w3.org/2000/svg",
672
964
  viewBox: "0 0 1024 1024"
673
965
  }, [
674
- f("path", {
966
+ y("path", {
675
967
  fill: "currentColor",
676
968
  d: "m64 448 832-320-128 704-446.08-243.328L832 192 242.816 545.472zm256 512V657.024L512 768z"
677
969
  })
678
970
  ]));
679
971
  }
680
- }), je = Pe, Ne = /* @__PURE__ */ N({
972
+ }), bt = xt, wt = /* @__PURE__ */ F({
681
973
  name: "Setting",
682
974
  __name: "setting",
683
975
  setup(t) {
684
- return (e, s) => (a(), m("svg", {
976
+ return (e, s) => (u(), x("svg", {
685
977
  xmlns: "http://www.w3.org/2000/svg",
686
978
  viewBox: "0 0 1024 1024"
687
979
  }, [
688
- f("path", {
980
+ y("path", {
689
981
  fill: "currentColor",
690
982
  d: "M600.704 64a32 32 0 0 1 30.464 22.208l35.2 109.376c14.784 7.232 28.928 15.36 42.432 24.512l112.384-24.192a32 32 0 0 1 34.432 15.36L944.32 364.8a32 32 0 0 1-4.032 37.504l-77.12 85.12a357 357 0 0 1 0 49.024l77.12 85.248a32 32 0 0 1 4.032 37.504l-88.704 153.6a32 32 0 0 1-34.432 15.296L708.8 803.904c-13.44 9.088-27.648 17.28-42.368 24.512l-35.264 109.376A32 32 0 0 1 600.704 960H423.296a32 32 0 0 1-30.464-22.208L357.696 828.48a352 352 0 0 1-42.56-24.64l-112.32 24.256a32 32 0 0 1-34.432-15.36L79.68 659.2a32 32 0 0 1 4.032-37.504l77.12-85.248a357 357 0 0 1 0-48.896l-77.12-85.248A32 32 0 0 1 79.68 364.8l88.704-153.6a32 32 0 0 1 34.432-15.296l112.32 24.256c13.568-9.152 27.776-17.408 42.56-24.64l35.2-109.312A32 32 0 0 1 423.232 64H600.64zm-23.424 64H446.72l-36.352 113.088-24.512 11.968a294 294 0 0 0-34.816 20.096l-22.656 15.36-116.224-25.088-65.28 113.152 79.68 88.192-1.92 27.136a293 293 0 0 0 0 40.192l1.92 27.136-79.808 88.192 65.344 113.152 116.224-25.024 22.656 15.296a294 294 0 0 0 34.816 20.096l24.512 11.968L446.72 896h130.688l36.48-113.152 24.448-11.904a288 288 0 0 0 34.752-20.096l22.592-15.296 116.288 25.024 65.28-113.152-79.744-88.192 1.92-27.136a293 293 0 0 0 0-40.256l-1.92-27.136 79.808-88.128-65.344-113.152-116.288 24.96-22.592-15.232a288 288 0 0 0-34.752-20.096l-24.448-11.904L577.344 128zM512 320a192 192 0 1 1 0 384 192 192 0 0 1 0-384m0 64a128 128 0 1 0 0 256 128 128 0 0 0 0-256"
691
983
  })
692
984
  ]));
693
985
  }
694
- }), oe = Ne, Re = /* @__PURE__ */ N({
986
+ }), xe = wt, kt = /* @__PURE__ */ F({
695
987
  name: "UserFilled",
696
988
  __name: "user-filled",
697
989
  setup(t) {
698
- return (e, s) => (a(), m("svg", {
990
+ return (e, s) => (u(), x("svg", {
699
991
  xmlns: "http://www.w3.org/2000/svg",
700
992
  viewBox: "0 0 1024 1024"
701
993
  }, [
702
- f("path", {
994
+ y("path", {
703
995
  fill: "currentColor",
704
996
  d: "M288 320a224 224 0 1 0 448 0 224 224 0 1 0-448 0m544 608H160a32 32 0 0 1-32-32v-96a160 160 0 0 1 160-160h448a160 160 0 0 1 160 160v96a32 32 0 0 1-32 32z"
705
997
  })
706
998
  ]));
707
999
  }
708
- }), He = Re, Ke = /* @__PURE__ */ N({
1000
+ }), Ct = kt, $t = /* @__PURE__ */ F({
709
1001
  name: "VideoPause",
710
1002
  __name: "video-pause",
711
1003
  setup(t) {
712
- return (e, s) => (a(), m("svg", {
1004
+ return (e, s) => (u(), x("svg", {
713
1005
  xmlns: "http://www.w3.org/2000/svg",
714
1006
  viewBox: "0 0 1024 1024"
715
1007
  }, [
716
- f("path", {
1008
+ y("path", {
717
1009
  fill: "currentColor",
718
1010
  d: "M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896m0 832a384 384 0 0 0 0-768 384 384 0 0 0 0 768m-96-544q32 0 32 32v256q0 32-32 32t-32-32V384q0-32 32-32m192 0q32 0 32 32v256q0 32-32 32t-32-32V384q0-32 32-32"
719
1011
  })
720
1012
  ]));
721
1013
  }
722
- }), Le = Ke;
723
- const Ue = { class: "render-block" }, Oe = {
1014
+ }), St = $t;
1015
+ const Mt = { class: "render-block" }, It = {
724
1016
  key: 0,
725
1017
  class: "render-block__title"
726
- }, Je = {
1018
+ }, At = {
727
1019
  key: 2,
728
1020
  class: "render-block__cards"
729
- }, We = { class: "card-item" }, qe = { class: "card-label" }, Ge = { class: "card-value" }, Xe = {
1021
+ }, Vt = { class: "card-item" }, Pt = { class: "card-label" }, Tt = { class: "card-value" }, zt = {
730
1022
  key: 3,
731
1023
  class: "render-block__table"
732
- }, Ye = { key: 0 }, Qe = {
1024
+ }, Bt = {
733
1025
  key: 4,
734
1026
  class: "render-block__cards"
735
- }, Ze = { class: "card-label" }, et = { class: "card-value" }, tt = {
1027
+ }, Ht = { class: "card-label" }, Nt = { class: "card-value" }, Et = {
736
1028
  key: 5,
737
1029
  class: "render-block__list"
738
- }, st = /* @__PURE__ */ N({
1030
+ }, Dt = 400, Ft = /* @__PURE__ */ F({
739
1031
  __name: "RenderBlock",
740
1032
  props: {
741
1033
  block: {},
742
1034
  resolvedComponent: {}
743
1035
  },
744
- setup(t) {
745
- const e = t, s = Y(() => e.block.data || {}), d = Y(() => Array.isArray(s.value) ? s.value : s.value.list ? Array.isArray(s.value.list) ? s.value.list : [] : s.value.items ? Array.isArray(s.value.items) ? s.value.items : [] : [s.value]), r = Y(() => d.value.length ? Object.keys(d.value[0]) : []);
746
- function l(p) {
747
- return typeof p == "string" ? p : Object.values(p).join(" - ");
1036
+ emits: ["select"],
1037
+ setup(t, { emit: e }) {
1038
+ const s = t, i = e, o = te(() => s.block.data || {}), l = te(
1039
+ () => s.block.selectable && _.value.length > 1
1040
+ ), _ = te(() => Array.isArray(o.value) ? o.value : o.value.list ? Array.isArray(o.value.list) ? o.value.list : [] : o.value.items ? Array.isArray(o.value.items) ? o.value.items : [] : [o.value]), b = te(() => {
1041
+ var m;
1042
+ return _.value.length ? (m = s.block.fields) != null && m.length ? s.block.fields : Object.keys(_.value[0]) : [];
1043
+ }), a = te(
1044
+ () => 100
1045
+ // headers.value.length ? Math.floor(100 / headers.value.length) + '%' : undefined,
1046
+ );
1047
+ function r(m) {
1048
+ return typeof m == "string" ? m : Object.values(m).join(" - ");
748
1049
  }
749
- return (p, E) => (a(), m("div", Ue, [
750
- t.block.title ? (a(), m("div", Oe, V(t.block.title), 1)) : z("", !0),
751
- t.resolvedComponent ? (a(), j(me(t.resolvedComponent), {
752
- key: 1,
753
- class: "render-block__component",
754
- data: t.block.data
755
- }, null, 8, ["data"])) : t.block.type === "component" ? (a(), m("div", Je, [
756
- f("div", We, [
757
- (a(!0), m(K, null, U(d.value[0], (u, n) => (a(), m("div", {
758
- key: n,
759
- class: "card-field"
760
- }, [
761
- f("span", qe, V(n) + ":", 1),
762
- f("span", Ge, V(u), 1)
763
- ]))), 128))
764
- ])
765
- ])) : t.block.type === "table" ? (a(), m("div", Xe, [
766
- f("table", null, [
767
- r.value.length ? (a(), m("thead", Ye, [
768
- f("tr", null, [
769
- (a(!0), m(K, null, U(r.value, (u) => (a(), m("th", { key: u }, V(u), 1))), 128))
770
- ])
771
- ])) : z("", !0),
772
- f("tbody", null, [
773
- (a(!0), m(K, null, U(d.value, (u, n) => (a(), m("tr", { key: n }, [
774
- (a(!0), m(K, null, U(r.value, (g) => {
775
- var y;
776
- return a(), m("td", { key: g }, V((y = u[g]) != null ? y : ""), 1);
777
- }), 128))
1050
+ function h(m) {
1051
+ var H;
1052
+ const $ = (s.block.labelField && (m == null ? void 0 : m[s.block.labelField]) != null ? m[s.block.labelField] : (H = s.block.fields) != null && H.length ? m == null ? void 0 : m[s.block.fields[0]] : (m == null ? void 0 : m.name) ?? (m == null ? void 0 : m.title) ?? (m == null ? void 0 : m.id) ?? Object.values(m ?? {})[0]) ?? "";
1053
+ i("select", `我选择 ${$}`);
1054
+ }
1055
+ return (m, $) => {
1056
+ const H = P("el-button");
1057
+ return u(), x("div", Mt, [
1058
+ t.block.title ? (u(), x("div", It, L(t.block.title), 1)) : R("", !0),
1059
+ t.resolvedComponent ? (u(), D(He(t.resolvedComponent), {
1060
+ key: 1,
1061
+ class: "render-block__component",
1062
+ data: t.block.data
1063
+ }, null, 8, ["data"])) : t.block.type === "component" ? (u(), x("div", At, [
1064
+ y("div", Vt, [
1065
+ (u(!0), x(G, null, X(_.value[0], (I, A) => (u(), x("div", {
1066
+ key: A,
1067
+ class: "card-field"
1068
+ }, [
1069
+ y("span", Pt, L(A) + ":", 1),
1070
+ y("span", Tt, L(I), 1)
778
1071
  ]))), 128))
779
1072
  ])
780
- ])
781
- ])) : t.block.type === "card" ? (a(), m("div", Qe, [
782
- (a(!0), m(K, null, U(d.value, (u, n) => (a(), m("div", {
783
- key: n,
784
- class: "card-item"
785
- }, [
786
- (a(!0), m(K, null, U(u, (g, y) => (a(), m("div", {
787
- key: y,
788
- class: "card-field"
1073
+ ])) : t.block.type === "table" ? (u(), x("div", zt, [
1074
+ p(S(Oe), {
1075
+ data: _.value,
1076
+ "max-height": Dt,
1077
+ border: "",
1078
+ stripe: "",
1079
+ size: "small",
1080
+ "table-layout": "fixed",
1081
+ style: { width: "100%" }
1082
+ }, {
1083
+ default: v(() => [
1084
+ (u(!0), x(G, null, X(b.value, (I) => (u(), D(S(_e), {
1085
+ key: I,
1086
+ prop: I,
1087
+ label: I,
1088
+ width: a.value,
1089
+ align: "center",
1090
+ "show-overflow-tooltip": ""
1091
+ }, null, 8, ["prop", "label", "width"]))), 128)),
1092
+ l.value ? (u(), D(S(_e), {
1093
+ key: 0,
1094
+ label: "操作",
1095
+ width: 80,
1096
+ align: "center",
1097
+ fixed: "right"
1098
+ }, {
1099
+ default: v(({ row: I }) => [
1100
+ p(H, {
1101
+ size: "small",
1102
+ type: "primary",
1103
+ plain: "",
1104
+ onClick: (A) => h(I)
1105
+ }, {
1106
+ default: v(() => [...$[0] || ($[0] = [
1107
+ O(" 选择 ", -1)
1108
+ ])]),
1109
+ _: 1
1110
+ }, 8, ["onClick"])
1111
+ ]),
1112
+ _: 1
1113
+ })) : R("", !0)
1114
+ ]),
1115
+ _: 1
1116
+ }, 8, ["data"])
1117
+ ])) : t.block.type === "card" ? (u(), x("div", Bt, [
1118
+ (u(!0), x(G, null, X(_.value, (I, A) => (u(), x("div", {
1119
+ key: A,
1120
+ class: "card-item"
789
1121
  }, [
790
- f("span", Ze, V(y) + ":", 1),
791
- f("span", et, V(g), 1)
1122
+ (u(!0), x(G, null, X(I, (w, T) => (u(), x("div", {
1123
+ key: T,
1124
+ class: "card-field"
1125
+ }, [
1126
+ y("span", Ht, L(T) + ":", 1),
1127
+ y("span", Nt, L(w), 1)
1128
+ ]))), 128))
792
1129
  ]))), 128))
793
- ]))), 128))
794
- ])) : t.block.type === "list" ? (a(), m("div", tt, [
795
- (a(!0), m(K, null, U(d.value, (u, n) => (a(), m("div", {
796
- key: n,
797
- class: "list-item"
798
- }, V(l(u)), 1))), 128))
799
- ])) : z("", !0)
800
- ]));
1130
+ ])) : t.block.type === "list" ? (u(), x("div", Et, [
1131
+ (u(!0), x(G, null, X(_.value, (I, A) => (u(), x("div", {
1132
+ key: A,
1133
+ class: "list-item"
1134
+ }, L(r(I)), 1))), 128))
1135
+ ])) : R("", !0)
1136
+ ]);
1137
+ };
801
1138
  }
802
- });
803
- const Q = (t, e) => {
1139
+ }), oe = (t, e) => {
804
1140
  const s = t.__vccOpts || t;
805
- for (const [d, r] of e)
806
- s[d] = r;
1141
+ for (const [i, o] of e)
1142
+ s[i] = o;
807
1143
  return s;
808
- }, nt = /* @__PURE__ */ Q(st, [["__scopeId", "data-v-89cef1ee"]]), ut = {
1144
+ }, jt = /* @__PURE__ */ oe(Ft, [["__scopeId", "data-v-0cb2fd61"]]), Ot = {
809
1145
  key: 0,
810
1146
  class: "suggested-next"
811
- }, at = { class: "suggested-next__text" }, ot = /* @__PURE__ */ N({
1147
+ }, Ut = { class: "suggested-next__text" }, Rt = /* @__PURE__ */ F({
812
1148
  __name: "SuggestedNext",
813
1149
  props: {
814
1150
  text: {}
815
1151
  },
816
1152
  emits: ["execute"],
817
1153
  setup(t, { emit: e }) {
818
- const s = t, d = e;
819
- function r() {
820
- d("execute", s.text);
1154
+ const s = t, i = e;
1155
+ function o() {
1156
+ i("execute", s.text);
821
1157
  }
822
- return (l, p) => {
823
- const E = S("el-button");
824
- return t.text ? (a(), m("div", ut, [
825
- p[1] || (p[1] = f("span", { class: "suggested-next__icon" }, "\u{1F4A1}", -1)),
826
- f("span", at, V(t.text), 1),
827
- _(E, {
1158
+ return (l, _) => {
1159
+ const b = P("el-button");
1160
+ return t.text ? (u(), x("div", Ot, [
1161
+ _[1] || (_[1] = y("span", { class: "suggested-next__icon" }, "💡", -1)),
1162
+ y("span", Ut, L(t.text), 1),
1163
+ p(b, {
828
1164
  size: "small",
829
1165
  type: "primary",
830
1166
  plain: "",
831
- onClick: r
1167
+ onClick: o
832
1168
  }, {
833
- default: v(() => [...p[0] || (p[0] = [
834
- R("\u53BB\u6267\u884C", -1)
1169
+ default: v(() => [..._[0] || (_[0] = [
1170
+ O("去执行", -1)
835
1171
  ])]),
836
1172
  _: 1
837
1173
  })
838
- ])) : z("", !0);
1174
+ ])) : R("", !0);
839
1175
  };
840
1176
  }
841
- });
842
- const lt = /* @__PURE__ */ Q(ot, [["__scopeId", "data-v-0e0e9b65"]]), it = { class: "message-avatar" }, rt = { class: "message-body" }, ct = {
1177
+ }), Kt = /* @__PURE__ */ oe(Rt, [["__scopeId", "data-v-0e0e9b65"]]), Lt = { class: "message-avatar" }, Jt = { class: "message-body" }, Wt = {
843
1178
  key: 0,
844
1179
  class: "message-files"
845
- }, dt = ["src", "alt"], mt = { class: "file-info" }, pt = { class: "file-name" }, gt = { class: "file-size" }, ft = {
1180
+ }, qt = ["src", "alt"], Gt = { class: "file-info" }, Yt = { class: "file-name" }, Xt = { class: "file-size" }, Qt = {
846
1181
  key: 1,
847
1182
  class: "message-user-text"
848
- }, _t = {
1183
+ }, Zt = {
849
1184
  key: 0,
850
1185
  class: "message-reasoning"
851
- }, ht = ["innerHTML"], vt = {
1186
+ }, es = ["innerHTML"], ts = {
852
1187
  key: 3,
853
1188
  class: "message-cursor"
854
- }, Ft = {
1189
+ }, ss = {
855
1190
  key: 4,
856
1191
  class: "message-error"
857
- }, yt = /* @__PURE__ */ N({
1192
+ }, ns = /* @__PURE__ */ F({
858
1193
  __name: "ChatMessage",
859
1194
  props: {
860
1195
  message: {},
@@ -862,102 +1197,100 @@ const lt = /* @__PURE__ */ Q(ot, [["__scopeId", "data-v-0e0e9b65"]]), it = { cla
862
1197
  },
863
1198
  emits: ["execute"],
864
1199
  setup(t, { emit: e }) {
865
- const s = t, d = e;
866
- function r(u) {
867
- if (!u)
868
- return "";
869
- let n = u.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
870
- return n = n.replace(/`([^`]+)`/g, "<code>$1</code>"), n = n.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>"), n = n.replace(/\*([^*]+)\*/g, "<em>$1</em>"), n = n.replace(/\n/g, "<br>"), n;
1200
+ const s = t, i = e;
1201
+ function o(a) {
1202
+ if (!a) return "";
1203
+ let r = a.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
1204
+ return r = r.replace(/`([^`]+)`/g, "<code>$1</code>"), r = r.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>"), r = r.replace(/\*([^*]+)\*/g, "<em>$1</em>"), r = r.replace(/\n/g, "<br>"), r;
871
1205
  }
872
- const l = Y(() => r(s.message.content));
873
- function p(u) {
874
- var g;
875
- if (u.type !== "component" || !u.componentName)
876
- return null;
877
- let n = u.packageId ? s.toolPackages.find((y) => y.id === u.packageId) : null;
878
- return n || (n = s.toolPackages.find(
879
- (y) => y.components && u.componentName in y.components
880
- )), n || (n = s.toolPackages[s.toolPackages.length - 1]), n && ((g = n.components) == null ? void 0 : g[u.componentName]) || null;
1206
+ const l = te(() => o(s.message.content));
1207
+ function _(a) {
1208
+ var h;
1209
+ if (a.type !== "component" || !a.componentName) return null;
1210
+ let r = a.packageId ? s.toolPackages.find((m) => m.id === a.packageId) : null;
1211
+ return r || (r = s.toolPackages.find(
1212
+ (m) => m.components && a.componentName in m.components
1213
+ )), r || (r = s.toolPackages[s.toolPackages.length - 1]), r && ((h = r.components) == null ? void 0 : h[a.componentName]) || null;
881
1214
  }
882
- function E(u) {
883
- d("execute", u);
1215
+ function b(a) {
1216
+ i("execute", a);
884
1217
  }
885
- return (u, n) => {
886
- var y;
887
- const g = S("el-icon");
888
- return a(), m("div", {
889
- class: ne(["chat-message", [`role-${t.message.role}`, { "is-streaming": t.message.status === "streaming" }]])
1218
+ return (a, r) => {
1219
+ var m;
1220
+ const h = P("el-icon");
1221
+ return u(), x("div", {
1222
+ class: ie(["chat-message", [`role-${t.message.role}`, { "is-streaming": t.message.status === "streaming" }]])
890
1223
  }, [
891
- f("div", it, [
892
- t.message.role === "user" ? (a(), j(g, { key: 0 }, {
1224
+ y("div", Lt, [
1225
+ t.message.role === "user" ? (u(), D(h, { key: 0 }, {
893
1226
  default: v(() => [
894
- _(A(He))
1227
+ p(S(Ct))
895
1228
  ]),
896
1229
  _: 1
897
- })) : (a(), j(g, { key: 1 }, {
1230
+ })) : (u(), D(h, { key: 1 }, {
898
1231
  default: v(() => [
899
- _(A(be))
1232
+ p(S(lt))
900
1233
  ]),
901
1234
  _: 1
902
1235
  }))
903
1236
  ]),
904
- f("div", rt, [
905
- (y = t.message.files) != null && y.length ? (a(), m("div", ct, [
906
- (a(!0), m(K, null, U(t.message.files, (C, M) => (a(), m("div", {
907
- key: M,
908
- class: ne(["message-file", { "is-image": C.type.startsWith("image/") }])
1237
+ y("div", Jt, [
1238
+ (m = t.message.files) != null && m.length ? (u(), x("div", Wt, [
1239
+ (u(!0), x(G, null, X(t.message.files, ($, H) => (u(), x("div", {
1240
+ key: H,
1241
+ class: ie(["message-file", { "is-image": $.type.startsWith("image/") }])
909
1242
  }, [
910
- C.type.startsWith("image/") ? (a(), m("img", {
1243
+ $.type.startsWith("image/") ? (u(), x("img", {
911
1244
  key: 0,
912
- src: C.data,
913
- alt: C.name,
1245
+ src: $.data,
1246
+ alt: $.name,
914
1247
  class: "file-image"
915
- }, null, 8, dt)) : (a(), j(g, { key: 1 }, {
1248
+ }, null, 8, qt)) : (u(), D(h, { key: 1 }, {
916
1249
  default: v(() => [
917
- _(A(le))
1250
+ p(S(be))
918
1251
  ]),
919
1252
  _: 1
920
1253
  })),
921
- f("div", mt, [
922
- f("span", pt, V(C.name), 1),
923
- f("span", gt, V((C.size / 1024).toFixed(1)) + " KB", 1)
1254
+ y("div", Gt, [
1255
+ y("span", Yt, L($.name), 1),
1256
+ y("span", Xt, L(($.size / 1024).toFixed(1)) + " KB", 1)
924
1257
  ])
925
1258
  ], 2))), 128))
926
- ])) : z("", !0),
927
- t.message.role === "user" ? (a(), m("div", ft, V(t.message.content), 1)) : z("", !0),
928
- t.message.role === "assistant" ? (a(), m(K, { key: 2 }, [
929
- t.message.reasoning ? (a(), m("div", _t, [
930
- f("details", null, [
931
- n[0] || (n[0] = f("summary", null, "\u63A8\u7406\u8FC7\u7A0B", -1)),
932
- f("pre", null, V(t.message.reasoning), 1)
1259
+ ])) : R("", !0),
1260
+ t.message.role === "user" ? (u(), x("div", Qt, L(t.message.content), 1)) : R("", !0),
1261
+ t.message.role === "assistant" ? (u(), x(G, { key: 2 }, [
1262
+ t.message.reasoning ? (u(), x("div", Zt, [
1263
+ y("details", null, [
1264
+ r[0] || (r[0] = y("summary", null, "推理过程", -1)),
1265
+ y("pre", null, L(t.message.reasoning), 1)
933
1266
  ])
934
- ])) : z("", !0),
935
- f("div", {
1267
+ ])) : R("", !0),
1268
+ y("div", {
936
1269
  class: "message-content markdown-body",
937
1270
  innerHTML: l.value
938
- }, null, 8, ht),
939
- (a(!0), m(K, null, U(t.message.renderBlocks, (C, M) => (a(), j(nt, {
940
- key: M,
941
- block: C,
942
- "resolved-component": p(C)
1271
+ }, null, 8, es),
1272
+ (u(!0), x(G, null, X(t.message.renderBlocks, ($, H) => (u(), D(jt, {
1273
+ key: H,
1274
+ block: $,
1275
+ "resolved-component": _($),
1276
+ onSelect: b
943
1277
  }, null, 8, ["block", "resolved-component"]))), 128)),
944
- t.message.suggestedNext ? (a(), j(lt, {
1278
+ t.message.suggestedNext ? (u(), D(Kt, {
945
1279
  key: 1,
946
1280
  text: t.message.suggestedNext,
947
- onExecute: E
948
- }, null, 8, ["text"])) : z("", !0)
949
- ], 64)) : z("", !0),
950
- t.message.status === "streaming" ? (a(), m("div", vt, "\u258D")) : z("", !0),
951
- t.message.status === "error" ? (a(), m("div", Ft, V(t.message.error), 1)) : z("", !0)
1281
+ onExecute: b
1282
+ }, null, 8, ["text"])) : R("", !0)
1283
+ ], 64)) : R("", !0),
1284
+ t.message.status === "streaming" ? (u(), x("div", ts, "")) : R("", !0),
1285
+ t.message.status === "error" ? (u(), x("div", ss, L(t.message.error), 1)) : R("", !0)
952
1286
  ])
953
1287
  ], 2);
954
1288
  };
955
1289
  }
956
- });
957
- const Et = /* @__PURE__ */ Q(yt, [["__scopeId", "data-v-fe82b4e5"]]), Ct = { class: "chat-input" }, xt = {
1290
+ }), os = /* @__PURE__ */ oe(ns, [["__scopeId", "data-v-af392c78"]]), as = { class: "chat-input" }, ls = {
958
1291
  key: 0,
959
1292
  class: "chat-input__files"
960
- }, Dt = { class: "chat-input__wrap" }, kt = { class: "chat-input__actions" }, Bt = /* @__PURE__ */ N({
1293
+ }, is = { class: "chat-input__wrap" }, rs = { class: "chat-input__actions" }, cs = /* @__PURE__ */ F({
961
1294
  __name: "ChatInput",
962
1295
  props: {
963
1296
  loading: { type: Boolean },
@@ -966,14 +1299,14 @@ const Et = /* @__PURE__ */ Q(yt, [["__scopeId", "data-v-fe82b4e5"]]), Ct = { cla
966
1299
  },
967
1300
  emits: ["send"],
968
1301
  setup(t, { emit: e }) {
969
- const s = t, d = e, r = W(""), l = W([]), p = W(null), E = Y(
970
- () => (r.value.trim().length > 0 || l.value.length > 0) && !s.disabled
1302
+ const s = t, i = e, o = W(""), l = W([]), _ = W(null), b = te(
1303
+ () => (o.value.trim().length > 0 || l.value.length > 0) && !s.disabled
971
1304
  );
972
- function u() {
973
- var h;
974
- (h = p.value) == null || h.click();
1305
+ function a() {
1306
+ var w;
1307
+ (w = _.value) == null || w.click();
975
1308
  }
976
- const n = /* @__PURE__ */ new Set([
1309
+ const r = /* @__PURE__ */ new Set([
977
1310
  "text/plain",
978
1311
  "text/html",
979
1312
  "text/css",
@@ -989,12 +1322,11 @@ const Et = /* @__PURE__ */ Q(yt, [["__scopeId", "data-v-fe82b4e5"]]), Ct = { cla
989
1322
  "application/yaml",
990
1323
  "application/x-yaml"
991
1324
  ]);
992
- function g(h) {
993
- var w;
994
- if (h.type.startsWith("text/") || n.has(h.type))
995
- return !0;
996
- if (h.type === "" || h.type.startsWith("application/")) {
997
- const F = (w = h.name.split(".").pop()) == null ? void 0 : w.toLowerCase();
1325
+ function h(w) {
1326
+ var T;
1327
+ if (w.type.startsWith("text/") || r.has(w.type)) return !0;
1328
+ if (w.type === "" || w.type.startsWith("application/")) {
1329
+ const z = (T = w.name.split(".").pop()) == null ? void 0 : T.toLowerCase();
998
1330
  return (/* @__PURE__ */ new Set([
999
1331
  "txt",
1000
1332
  "md",
@@ -1043,106 +1375,105 @@ const Et = /* @__PURE__ */ Q(yt, [["__scopeId", "data-v-fe82b4e5"]]), Ct = { cla
1043
1375
  "topojson",
1044
1376
  "xlsx",
1045
1377
  "docx"
1046
- ])).has(F != null ? F : "");
1378
+ ])).has(z ?? "");
1047
1379
  }
1048
1380
  return !1;
1049
1381
  }
1050
- function y(h) {
1051
- return new Promise((w) => {
1052
- const F = new FileReader();
1053
- F.onload = () => {
1054
- w({
1382
+ function m(w) {
1383
+ return new Promise((T) => {
1384
+ const z = new FileReader();
1385
+ z.onload = () => {
1386
+ T({
1055
1387
  id: "",
1056
- name: h.name,
1057
- size: h.size,
1058
- type: h.type,
1059
- data: F.result
1388
+ name: w.name,
1389
+ size: w.size,
1390
+ type: w.type,
1391
+ data: z.result
1060
1392
  });
1061
- }, g(h) ? F.readAsText(h) : F.readAsDataURL(h);
1393
+ }, h(w) ? z.readAsText(w) : z.readAsDataURL(w);
1062
1394
  });
1063
1395
  }
1064
- async function C(h) {
1065
- var F;
1066
- const w = h.target;
1067
- if (!!((F = w.files) != null && F.length)) {
1068
- for (const c of Array.from(w.files)) {
1069
- const H = await y(c);
1070
- l.value.push(H);
1396
+ async function $(w) {
1397
+ var z;
1398
+ const T = w.target;
1399
+ if ((z = T.files) != null && z.length) {
1400
+ for (const j of Array.from(T.files)) {
1401
+ const J = await m(j);
1402
+ l.value.push(J);
1071
1403
  }
1072
- w.value = "";
1404
+ T.value = "";
1073
1405
  }
1074
1406
  }
1075
- function M(h) {
1076
- l.value.splice(h, 1);
1407
+ function H(w) {
1408
+ l.value.splice(w, 1);
1077
1409
  }
1078
- function O(h) {
1079
- h.shiftKey || (h.preventDefault(), T());
1410
+ function I(w) {
1411
+ w.shiftKey || (w.preventDefault(), A());
1080
1412
  }
1081
- function T() {
1082
- if (!E.value || s.loading)
1083
- return;
1084
- const h = r.value.trim();
1085
- d("send", h, l.value), r.value = "", l.value = [];
1413
+ function A() {
1414
+ if (!b.value || s.loading) return;
1415
+ const w = o.value.trim();
1416
+ i("send", w, l.value), o.value = "", l.value = [];
1086
1417
  }
1087
- return (h, w) => {
1088
- const F = S("el-icon"), c = S("el-tag"), H = S("el-input"), J = S("el-button"), q = S("el-tooltip");
1089
- return a(), m("div", Ct, [
1090
- l.value.length ? (a(), m("div", xt, [
1091
- (a(!0), m(K, null, U(l.value, (P, x) => (a(), j(c, {
1092
- key: x,
1418
+ return (w, T) => {
1419
+ const z = P("el-icon"), j = P("el-tag"), J = P("el-input"), U = P("el-button"), N = P("el-tooltip");
1420
+ return u(), x("div", as, [
1421
+ l.value.length ? (u(), x("div", ls, [
1422
+ (u(!0), x(G, null, X(l.value, (g, f) => (u(), D(j, {
1423
+ key: f,
1093
1424
  closable: "",
1094
1425
  size: "small",
1095
- type: P.type.startsWith("image/") ? "success" : "info",
1096
- onClose: (I) => M(x)
1426
+ type: g.type.startsWith("image/") ? "success" : "info",
1427
+ onClose: (d) => H(f)
1097
1428
  }, {
1098
1429
  default: v(() => [
1099
- P.type.startsWith("image/") ? (a(), j(F, {
1430
+ g.type.startsWith("image/") ? (u(), D(z, {
1100
1431
  key: 0,
1101
1432
  style: { "margin-right": "4px" }
1102
1433
  }, {
1103
1434
  default: v(() => [
1104
- _(A(Te))
1435
+ p(S(yt))
1105
1436
  ]),
1106
1437
  _: 1
1107
- })) : (a(), j(F, {
1438
+ })) : (u(), D(z, {
1108
1439
  key: 1,
1109
1440
  style: { "margin-right": "4px" }
1110
1441
  }, {
1111
1442
  default: v(() => [
1112
- _(A(le))
1443
+ p(S(be))
1113
1444
  ]),
1114
1445
  _: 1
1115
1446
  })),
1116
- R(" " + V(P.name), 1)
1447
+ O(" " + L(g.name), 1)
1117
1448
  ]),
1118
1449
  _: 2
1119
1450
  }, 1032, ["type", "onClose"]))), 128))
1120
- ])) : z("", !0),
1121
- f("div", Dt, [
1122
- _(H, {
1123
- modelValue: r.value,
1124
- "onUpdate:modelValue": w[0] || (w[0] = (P) => r.value = P),
1451
+ ])) : R("", !0),
1452
+ y("div", is, [
1453
+ p(J, {
1454
+ modelValue: o.value,
1455
+ "onUpdate:modelValue": T[0] || (T[0] = (g) => o.value = g),
1125
1456
  type: "textarea",
1126
1457
  autosize: { minRows: 1, maxRows: 6 },
1127
1458
  resize: "none",
1128
1459
  placeholder: t.placeholder,
1129
- onKeydown: pe(O, ["enter"])
1460
+ onKeydown: Ne(I, ["enter"])
1130
1461
  }, null, 8, ["modelValue", "placeholder"]),
1131
- f("div", kt, [
1132
- _(q, {
1133
- content: "\u4E0A\u4F20\u6587\u4EF6",
1462
+ y("div", rs, [
1463
+ p(N, {
1464
+ content: "上传文件",
1134
1465
  placement: "top"
1135
1466
  }, {
1136
1467
  default: v(() => [
1137
- _(J, {
1468
+ p(U, {
1138
1469
  text: "",
1139
1470
  circle: "",
1140
- onClick: u
1471
+ onClick: a
1141
1472
  }, {
1142
1473
  default: v(() => [
1143
- _(F, null, {
1474
+ p(z, null, {
1144
1475
  default: v(() => [
1145
- _(A(Ve))
1476
+ p(S(_t))
1146
1477
  ]),
1147
1478
  _: 1
1148
1479
  })
@@ -1152,26 +1483,26 @@ const Et = /* @__PURE__ */ Q(yt, [["__scopeId", "data-v-fe82b4e5"]]), Ct = { cla
1152
1483
  ]),
1153
1484
  _: 1
1154
1485
  }),
1155
- f("input", {
1486
+ y("input", {
1156
1487
  ref_key: "fileInputRef",
1157
- ref: p,
1488
+ ref: _,
1158
1489
  type: "file",
1159
1490
  multiple: "",
1160
1491
  hidden: "",
1161
- onChange: C
1492
+ onChange: $
1162
1493
  }, null, 544),
1163
- _(q, {
1164
- content: "Enter \u53D1\u9001\uFF0CShift+Enter \u6362\u884C",
1494
+ p(N, {
1495
+ content: "Enter 发送,Shift+Enter 换行",
1165
1496
  placement: "top"
1166
1497
  }, {
1167
1498
  default: v(() => [
1168
- _(J, {
1499
+ p(U, {
1169
1500
  type: "primary",
1170
- icon: A(je),
1501
+ icon: S(bt),
1171
1502
  loading: t.loading,
1172
- disabled: !E.value,
1503
+ disabled: !b.value,
1173
1504
  circle: "",
1174
- onClick: T
1505
+ onClick: A
1175
1506
  }, null, 8, ["icon", "loading", "disabled"])
1176
1507
  ]),
1177
1508
  _: 1
@@ -1181,114 +1512,156 @@ const Et = /* @__PURE__ */ Q(yt, [["__scopeId", "data-v-fe82b4e5"]]), Ct = { cla
1181
1512
  ]);
1182
1513
  };
1183
1514
  }
1184
- });
1185
- const wt = /* @__PURE__ */ Q(Bt, [["__scopeId", "data-v-1f9902c6"]]), At = [
1186
- { label: "deepseek-chat (V3 \u6700\u5F3A)", value: "deepseek-chat" },
1187
- { label: "deepseek-reasoner (R1 \u63A8\u7406)", value: "deepseek-reasoner" }
1188
- ], bt = { class: "form-tip" }, $t = { class: "temp-row" }, St = { class: "temp-val" }, It = /* @__PURE__ */ N({
1515
+ }), us = /* @__PURE__ */ oe(cs, [["__scopeId", "data-v-8fcb870c"]]), ds = [
1516
+ { label: "deepseek-chat (V3 最强)", value: "deepseek-chat" },
1517
+ { label: "deepseek-reasoner (R1 推理)", value: "deepseek-reasoner" }
1518
+ ], ps = { class: "form-tip" }, ms = { class: "temp-row" }, fs = { class: "temp-val" }, gs = /* @__PURE__ */ F({
1189
1519
  __name: "ChatSettings",
1190
1520
  props: {
1191
1521
  modelValue: { type: Boolean },
1192
- settings: {}
1522
+ settings: {},
1523
+ deviceId: {}
1193
1524
  },
1194
1525
  emits: ["update:modelValue", "save"],
1195
1526
  setup(t, { emit: e }) {
1196
- const s = t, d = e, r = W(s.modelValue);
1197
- ee(
1527
+ const s = t, i = e, o = W(s.modelValue);
1528
+ le(
1198
1529
  () => s.modelValue,
1199
- (E) => {
1200
- r.value = E, E && (l.value = { ...s.settings });
1530
+ (b) => {
1531
+ o.value = b, b && (l.value = { ...s.settings });
1201
1532
  }
1202
- ), ee(r, (E) => d("update:modelValue", E));
1533
+ ), le(o, (b) => i("update:modelValue", b));
1203
1534
  const l = W({ ...s.settings });
1204
- function p() {
1205
- d("save", { ...l.value }), r.value = !1;
1535
+ function _() {
1536
+ i("save", { ...l.value }), o.value = !1;
1206
1537
  }
1207
- return (E, u) => {
1208
- const n = S("el-input"), g = S("el-link"), y = S("el-form-item"), C = S("el-option"), M = S("el-select"), O = S("el-slider"), T = S("el-switch"), h = S("el-form"), w = S("el-button"), F = S("el-dialog");
1209
- return a(), j(F, {
1210
- modelValue: r.value,
1211
- "onUpdate:modelValue": u[6] || (u[6] = (c) => r.value = c),
1212
- title: "AI \u52A9\u624B\u8BBE\u7F6E",
1538
+ return (b, a) => {
1539
+ const r = P("el-radio"), h = P("el-radio-group"), m = P("el-form-item"), $ = P("el-input"), H = P("el-link"), I = P("el-option"), A = P("el-select"), w = P("el-slider"), T = P("el-icon"), z = P("el-tooltip"), j = P("el-switch"), J = P("el-form"), U = P("el-button"), N = P("el-dialog");
1540
+ return u(), D(N, {
1541
+ modelValue: o.value,
1542
+ "onUpdate:modelValue": a[8] || (a[8] = (g) => o.value = g),
1543
+ title: "AI 助手设置",
1213
1544
  width: "520px",
1214
1545
  "append-to-body": ""
1215
1546
  }, {
1216
1547
  footer: v(() => [
1217
- _(w, {
1218
- onClick: u[5] || (u[5] = (c) => r.value = !1)
1548
+ p(U, {
1549
+ onClick: a[7] || (a[7] = (g) => o.value = !1)
1219
1550
  }, {
1220
- default: v(() => [...u[11] || (u[11] = [
1221
- R("\u53D6\u6D88", -1)
1551
+ default: v(() => [...a[17] || (a[17] = [
1552
+ O("取消", -1)
1222
1553
  ])]),
1223
1554
  _: 1
1224
1555
  }),
1225
- _(w, {
1556
+ p(U, {
1226
1557
  type: "primary",
1227
- onClick: p
1558
+ onClick: _
1228
1559
  }, {
1229
- default: v(() => [...u[12] || (u[12] = [
1230
- R("\u4FDD\u5B58", -1)
1560
+ default: v(() => [...a[18] || (a[18] = [
1561
+ O("保存", -1)
1231
1562
  ])]),
1232
1563
  _: 1
1233
1564
  })
1234
1565
  ]),
1235
1566
  default: v(() => [
1236
- _(h, {
1567
+ p(J, {
1237
1568
  model: l.value,
1238
1569
  "label-width": "110px",
1239
1570
  "label-position": "right"
1240
1571
  }, {
1241
1572
  default: v(() => [
1242
- _(y, { label: "API Key" }, {
1573
+ p(m, { label: "调用模式" }, {
1243
1574
  default: v(() => [
1244
- _(n, {
1245
- modelValue: l.value.apiKey,
1246
- "onUpdate:modelValue": u[0] || (u[0] = (c) => l.value.apiKey = c),
1247
- type: "password",
1248
- "show-password": "",
1249
- placeholder: "sk-xxxxxxxxxxxxxxxx",
1250
- clearable: ""
1251
- }, null, 8, ["modelValue"]),
1252
- f("div", bt, [
1253
- u[8] || (u[8] = R(" \u5728 ", -1)),
1254
- _(g, {
1255
- type: "primary",
1256
- href: "https://platform.deepseek.com/api_keys",
1257
- target: "_blank"
1258
- }, {
1259
- default: v(() => [...u[7] || (u[7] = [
1260
- R(" DeepSeek \u5F00\u653E\u5E73\u53F0 ", -1)
1261
- ])]),
1262
- _: 1
1263
- }),
1264
- u[9] || (u[9] = R(" \u83B7\u53D6\uFF0C\u4EC5\u4FDD\u5B58\u5728\u6D4F\u89C8\u5668\u672C\u5730\u3002 ", -1))
1265
- ])
1575
+ p(h, {
1576
+ modelValue: l.value.providerMode,
1577
+ "onUpdate:modelValue": a[0] || (a[0] = (g) => l.value.providerMode = g)
1578
+ }, {
1579
+ default: v(() => [
1580
+ p(r, { value: "direct" }, {
1581
+ default: v(() => [...a[9] || (a[9] = [
1582
+ O("前端直连", -1)
1583
+ ])]),
1584
+ _: 1
1585
+ }),
1586
+ p(r, { value: "proxy" }, {
1587
+ default: v(() => [...a[10] || (a[10] = [
1588
+ O("后端代理", -1)
1589
+ ])]),
1590
+ _: 1
1591
+ })
1592
+ ]),
1593
+ _: 1
1594
+ }, 8, ["modelValue"]),
1595
+ a[11] || (a[11] = y("div", { class: "form-tip" }, " 前端直连:API Key 保存在浏览器本地,浏览器直接调用模型 API。 后端代理:由你的后端转发请求,API Key 保存在服务端。 ", -1))
1266
1596
  ]),
1267
1597
  _: 1
1268
1598
  }),
1269
- _(y, { label: "\u63A5\u53E3\u5730\u5740" }, {
1599
+ l.value.providerMode === "direct" ? (u(), x(G, { key: 0 }, [
1600
+ p(m, { label: "API Key" }, {
1601
+ default: v(() => [
1602
+ p($, {
1603
+ modelValue: l.value.apiKey,
1604
+ "onUpdate:modelValue": a[1] || (a[1] = (g) => l.value.apiKey = g),
1605
+ type: "password",
1606
+ "show-password": "",
1607
+ placeholder: "sk-xxxxxxxxxxxxxxxx",
1608
+ clearable: ""
1609
+ }, null, 8, ["modelValue"]),
1610
+ y("div", ps, [
1611
+ a[13] || (a[13] = O(" 在 ", -1)),
1612
+ p(H, {
1613
+ type: "primary",
1614
+ href: "https://platform.deepseek.com/api_keys",
1615
+ target: "_blank"
1616
+ }, {
1617
+ default: v(() => [...a[12] || (a[12] = [
1618
+ O(" DeepSeek 开放平台 ", -1)
1619
+ ])]),
1620
+ _: 1
1621
+ }),
1622
+ a[14] || (a[14] = O(" 获取,仅保存在浏览器本地。 ", -1))
1623
+ ])
1624
+ ]),
1625
+ _: 1
1626
+ }),
1627
+ p(m, { label: "接口地址" }, {
1628
+ default: v(() => [
1629
+ p($, {
1630
+ modelValue: l.value.baseUrl,
1631
+ "onUpdate:modelValue": a[2] || (a[2] = (g) => l.value.baseUrl = g),
1632
+ placeholder: "https://api.deepseek.com",
1633
+ clearable: ""
1634
+ }, null, 8, ["modelValue"])
1635
+ ]),
1636
+ _: 1
1637
+ })
1638
+ ], 64)) : (u(), D(m, {
1639
+ key: 1,
1640
+ label: "代理地址"
1641
+ }, {
1270
1642
  default: v(() => [
1271
- _(n, {
1272
- modelValue: l.value.baseUrl,
1273
- "onUpdate:modelValue": u[1] || (u[1] = (c) => l.value.baseUrl = c),
1274
- placeholder: "https://api.deepseek.com",
1643
+ p($, {
1644
+ modelValue: l.value.proxyUrl,
1645
+ "onUpdate:modelValue": a[3] || (a[3] = (g) => l.value.proxyUrl = g),
1646
+ placeholder: "http://localhost:3001/api/chat",
1275
1647
  clearable: ""
1276
- }, null, 8, ["modelValue"])
1648
+ }, null, 8, ["modelValue"]),
1649
+ a[15] || (a[15] = y("div", { class: "form-tip" }, " 你的后端代理服务地址,API Key 配置在服务端环境变量中。 ", -1))
1277
1650
  ]),
1278
1651
  _: 1
1279
- }),
1280
- _(y, { label: "\u6A21\u578B" }, {
1652
+ })),
1653
+ p(m, { label: "模型" }, {
1281
1654
  default: v(() => [
1282
- _(M, {
1655
+ p(A, {
1283
1656
  modelValue: l.value.model,
1284
- "onUpdate:modelValue": u[2] || (u[2] = (c) => l.value.model = c),
1657
+ "onUpdate:modelValue": a[4] || (a[4] = (g) => l.value.model = g),
1285
1658
  style: { width: "100%" }
1286
1659
  }, {
1287
1660
  default: v(() => [
1288
- (a(!0), m(K, null, U(A(At), (c) => (a(), j(C, {
1289
- key: c.value,
1290
- label: c.label,
1291
- value: c.value
1661
+ (u(!0), x(G, null, X(S(ds), (g) => (u(), D(I, {
1662
+ key: g.value,
1663
+ label: g.label,
1664
+ value: g.value
1292
1665
  }, null, 8, ["label", "value"]))), 128))
1293
1666
  ]),
1294
1667
  _: 1
@@ -1296,29 +1669,53 @@ const wt = /* @__PURE__ */ Q(Bt, [["__scopeId", "data-v-1f9902c6"]]), At = [
1296
1669
  ]),
1297
1670
  _: 1
1298
1671
  }),
1299
- _(y, { label: "\u6E29\u5EA6" }, {
1672
+ p(m, { label: "温度" }, {
1300
1673
  default: v(() => [
1301
- f("div", $t, [
1302
- _(O, {
1674
+ y("div", ms, [
1675
+ p(w, {
1303
1676
  modelValue: l.value.temperature,
1304
- "onUpdate:modelValue": u[3] || (u[3] = (c) => l.value.temperature = c),
1677
+ "onUpdate:modelValue": a[5] || (a[5] = (g) => l.value.temperature = g),
1305
1678
  min: 0,
1306
1679
  max: 2,
1307
1680
  step: 0.1,
1308
1681
  style: { flex: "1" }
1309
1682
  }, null, 8, ["modelValue"]),
1310
- f("span", St, V(l.value.temperature.toFixed(1)), 1)
1683
+ y("span", fs, L(l.value.temperature.toFixed(1)), 1)
1311
1684
  ])
1312
1685
  ]),
1313
1686
  _: 1
1314
1687
  }),
1315
- _(y, { label: "\u542F\u7528\u5DE5\u5177" }, {
1688
+ p(m, { label: "设备ID" }, {
1316
1689
  default: v(() => [
1317
- _(T, {
1690
+ p($, {
1691
+ "model-value": t.deviceId,
1692
+ readonly: ""
1693
+ }, {
1694
+ append: v(() => [
1695
+ p(z, { content: "该 ID 用于在服务端区分当前浏览器会话,历史消息按此 ID 保存" }, {
1696
+ default: v(() => [
1697
+ p(T, null, {
1698
+ default: v(() => [
1699
+ p(S(gt))
1700
+ ]),
1701
+ _: 1
1702
+ })
1703
+ ]),
1704
+ _: 1
1705
+ })
1706
+ ]),
1707
+ _: 1
1708
+ }, 8, ["model-value"])
1709
+ ]),
1710
+ _: 1
1711
+ }),
1712
+ p(m, { label: "启用工具" }, {
1713
+ default: v(() => [
1714
+ p(j, {
1318
1715
  modelValue: l.value.useTools,
1319
- "onUpdate:modelValue": u[4] || (u[4] = (c) => l.value.useTools = c)
1716
+ "onUpdate:modelValue": a[6] || (a[6] = (g) => l.value.useTools = g)
1320
1717
  }, null, 8, ["modelValue"]),
1321
- u[10] || (u[10] = f("span", { class: "form-tip-inline" }, "\u5173\u95ED\u540E\u52A9\u624B\u4EC5\u5BF9\u8BDD\uFF0C\u4E0D\u4F1A\u6267\u884C\u9875\u9762\u5BFC\u822A/\u6570\u636E\u67E5\u8BE2\u7B49\u64CD\u4F5C", -1))
1718
+ a[16] || (a[16] = y("span", { class: "form-tip-inline" }, "关闭后助手仅对话,不会执行页面导航/数据查询等操作", -1))
1322
1719
  ]),
1323
1720
  _: 1
1324
1721
  })
@@ -1330,245 +1727,329 @@ const wt = /* @__PURE__ */ Q(Bt, [["__scopeId", "data-v-1f9902c6"]]), At = [
1330
1727
  }, 8, ["modelValue"]);
1331
1728
  };
1332
1729
  }
1333
- });
1334
- const Mt = /* @__PURE__ */ Q(It, [["__scopeId", "data-v-21ad42a2"]]), Vt = { class: "chat-panel" }, zt = {
1335
- key: 0,
1336
- class: "chat-panel__header"
1337
- }, Tt = { class: "chat-panel__title" }, Pt = { class: "chat-panel__ops" }, jt = {
1730
+ }), hs = /* @__PURE__ */ oe(gs, [["__scopeId", "data-v-9634bbdc"]]), _s = { class: "chat-panel-root" }, vs = { class: "ai-fab__label" }, ys = { class: "chat-panel__header" }, xs = { class: "chat-panel__title" }, bs = { class: "chat-panel__ops" }, ws = {
1338
1731
  key: 0,
1339
1732
  class: "chat-empty"
1340
- }, Nt = { class: "chat-empty__logo" }, Rt = {
1733
+ }, ks = { class: "chat-empty__logo" }, Cs = {
1341
1734
  key: 0,
1342
1735
  class: "chat-panel__error"
1343
- }, Ht = { class: "chat-panel__footer" }, Kt = {
1736
+ }, $s = { class: "chat-panel__footer" }, Ss = {
1344
1737
  key: 0,
1345
1738
  class: "chat-panel__stop"
1346
- }, Lt = /* @__PURE__ */ N({
1739
+ }, Ms = /* @__PURE__ */ F({
1347
1740
  __name: "ChatPanel",
1348
1741
  props: {
1349
1742
  chat: {},
1350
- showHeader: { type: Boolean }
1743
+ showFab: { type: Boolean, default: !0 }
1351
1744
  },
1352
1745
  setup(t) {
1353
1746
  const e = t, {
1354
1747
  messages: s,
1355
- settings: d,
1356
- loading: r,
1748
+ settings: i,
1749
+ loading: o,
1357
1750
  errorMsg: l,
1358
- hasApiKey: p,
1359
- toolPackages: E,
1360
- sendMessage: u,
1361
- stopGeneration: n,
1362
- clearMessages: g,
1363
- saveSettings: y
1364
- } = e.chat, C = W(!1), M = W(null);
1365
- function O() {
1366
- fe(() => {
1367
- const F = M.value;
1368
- F && (F.scrollTop = F.scrollHeight);
1751
+ hasApiKey: _,
1752
+ visible: b,
1753
+ toolPackages: a,
1754
+ sendMessage: r,
1755
+ stopGeneration: h,
1756
+ clearMessages: m,
1757
+ saveSettings: $,
1758
+ deviceId: H
1759
+ } = e.chat, I = W(!1), A = W(!1), w = W(null);
1760
+ function T() {
1761
+ b.value = !b.value;
1762
+ }
1763
+ function z() {
1764
+ b.value = !1;
1765
+ }
1766
+ function j() {
1767
+ A.value = !A.value;
1768
+ }
1769
+ function J() {
1770
+ je(() => {
1771
+ const f = w.value;
1772
+ f && (f.scrollTop = f.scrollHeight);
1369
1773
  });
1370
1774
  }
1371
- function T(F, c) {
1372
- u(F, c), O();
1775
+ function U(f, d) {
1776
+ r(f, d), J();
1373
1777
  }
1374
- function h(F) {
1375
- y(F);
1778
+ function N(f) {
1779
+ $(f);
1376
1780
  }
1377
- function w() {
1378
- _e.confirm("\u786E\u5B9A\u8981\u6E05\u7A7A\u6240\u6709\u5BF9\u8BDD\u8BB0\u5F55\u5417\uFF1F", "\u63D0\u793A", {
1781
+ function g() {
1782
+ Ue.confirm("确定要清空所有对话记录吗?", "提示", {
1379
1783
  type: "warning",
1380
- confirmButtonText: "\u6E05\u7A7A",
1381
- cancelButtonText: "\u53D6\u6D88"
1784
+ confirmButtonText: "清空",
1785
+ cancelButtonText: "取消"
1382
1786
  }).then(() => {
1383
- g();
1787
+ m();
1384
1788
  }).catch(() => {
1385
1789
  });
1386
1790
  }
1387
- return ee(
1388
- () => s.value.map((F) => {
1389
- var c;
1390
- return F.content + F.status + (((c = F.renderBlocks) == null ? void 0 : c.length) || 0);
1791
+ return le(
1792
+ () => s.value.map((f) => {
1793
+ var d;
1794
+ return f.content + f.status + (((d = f.renderBlocks) == null ? void 0 : d.length) || 0);
1391
1795
  }).join("|"),
1392
- () => O()
1393
- ), (F, c) => {
1394
- const H = S("ChatDotRound"), J = S("el-icon"), q = S("el-tag"), P = S("el-button"), x = S("el-tooltip"), I = S("el-alert");
1395
- return a(), m("div", Vt, [
1396
- t.showHeader ? (a(), m("div", zt, [
1397
- f("div", Tt, [
1398
- _(J, { class: "title-icon" }, {
1399
- default: v(() => [
1400
- _(H)
1401
- ]),
1402
- _: 1
1403
- }),
1404
- c[5] || (c[5] = f("span", null, "AI \u667A\u80FD\u52A9\u624B", -1)),
1405
- A(p) ? (a(), j(q, {
1406
- key: 0,
1407
- size: "small",
1408
- type: "success",
1409
- effect: "plain"
1410
- }, {
1411
- default: v(() => [...c[3] || (c[3] = [
1412
- R("\u5DF2\u914D\u7F6E", -1)
1413
- ])]),
1414
- _: 1
1415
- })) : (a(), j(q, {
1416
- key: 1,
1417
- size: "small",
1418
- type: "warning",
1419
- effect: "plain"
1420
- }, {
1421
- default: v(() => [...c[4] || (c[4] = [
1422
- R("\u672A\u914D\u7F6E", -1)
1423
- ])]),
1424
- _: 1
1425
- }))
1796
+ () => J()
1797
+ ), (f, d) => {
1798
+ const V = P("ChatDotRound"), E = P("el-icon"), Y = P("el-tag"), ee = P("el-button"), Q = P("el-tooltip"), ce = P("el-alert");
1799
+ return u(), x("div", _s, [
1800
+ t.showFab ? (u(), x("div", {
1801
+ key: 0,
1802
+ class: ie(["ai-fab", { "ai-fab--active": S(b) }]),
1803
+ onClick: T
1804
+ }, [
1805
+ y("span", vs, L(S(b) ? "收起" : "AI 助手"), 1)
1806
+ ], 2)) : R("", !0),
1807
+ Ee(y("div", {
1808
+ class: ie(["chat-panel", { "chat-panel--fullscreen": A.value }])
1809
+ }, [
1810
+ y("div", ys, [
1811
+ y("div", xs, [
1812
+ p(E, { class: "title-icon" }, {
1813
+ default: v(() => [
1814
+ p(V)
1815
+ ]),
1816
+ _: 1
1817
+ }),
1818
+ d[5] || (d[5] = y("span", null, "AI 智能助手", -1)),
1819
+ S(_) ? (u(), D(Y, {
1820
+ key: 0,
1821
+ size: "small",
1822
+ type: "success",
1823
+ effect: "plain"
1824
+ }, {
1825
+ default: v(() => [...d[3] || (d[3] = [
1826
+ O("已配置", -1)
1827
+ ])]),
1828
+ _: 1
1829
+ })) : (u(), D(Y, {
1830
+ key: 1,
1831
+ size: "small",
1832
+ type: "warning",
1833
+ effect: "plain"
1834
+ }, {
1835
+ default: v(() => [...d[4] || (d[4] = [
1836
+ O("未配置", -1)
1837
+ ])]),
1838
+ _: 1
1839
+ }))
1840
+ ]),
1841
+ y("div", bs, [
1842
+ p(Q, {
1843
+ content: "设置",
1844
+ placement: "bottom"
1845
+ }, {
1846
+ default: v(() => [
1847
+ p(ee, {
1848
+ text: "",
1849
+ circle: "",
1850
+ onClick: d[0] || (d[0] = (Z) => I.value = !0)
1851
+ }, {
1852
+ default: v(() => [
1853
+ p(E, null, {
1854
+ default: v(() => [
1855
+ p(S(xe))
1856
+ ]),
1857
+ _: 1
1858
+ })
1859
+ ]),
1860
+ _: 1
1861
+ })
1862
+ ]),
1863
+ _: 1
1864
+ }),
1865
+ p(Q, {
1866
+ content: "清空对话",
1867
+ placement: "bottom"
1868
+ }, {
1869
+ default: v(() => [
1870
+ p(ee, {
1871
+ text: "",
1872
+ circle: "",
1873
+ disabled: !S(s).length,
1874
+ onClick: g
1875
+ }, {
1876
+ default: v(() => [
1877
+ p(E, null, {
1878
+ default: v(() => [
1879
+ p(S(ut))
1880
+ ]),
1881
+ _: 1
1882
+ })
1883
+ ]),
1884
+ _: 1
1885
+ }, 8, ["disabled"])
1886
+ ]),
1887
+ _: 1
1888
+ }),
1889
+ p(Q, {
1890
+ content: A.value ? "退出全屏" : "全屏",
1891
+ placement: "bottom"
1892
+ }, {
1893
+ default: v(() => [
1894
+ p(ee, {
1895
+ text: "",
1896
+ circle: "",
1897
+ onClick: j
1898
+ }, {
1899
+ default: v(() => [
1900
+ p(E, null, {
1901
+ default: v(() => [
1902
+ p(S(mt))
1903
+ ]),
1904
+ _: 1
1905
+ })
1906
+ ]),
1907
+ _: 1
1908
+ })
1909
+ ]),
1910
+ _: 1
1911
+ }, 8, ["content"]),
1912
+ p(Q, {
1913
+ content: "关闭",
1914
+ placement: "bottom"
1915
+ }, {
1916
+ default: v(() => [
1917
+ p(ee, {
1918
+ text: "",
1919
+ circle: "",
1920
+ onClick: z
1921
+ }, {
1922
+ default: v(() => [
1923
+ p(E, null, {
1924
+ default: v(() => [
1925
+ p(S(rt))
1926
+ ]),
1927
+ _: 1
1928
+ })
1929
+ ]),
1930
+ _: 1
1931
+ })
1932
+ ]),
1933
+ _: 1
1934
+ })
1935
+ ])
1426
1936
  ]),
1427
- f("div", Pt, [
1428
- _(x, {
1429
- content: "\u8BBE\u7F6E",
1430
- placement: "bottom"
1431
- }, {
1432
- default: v(() => [
1433
- _(P, {
1434
- text: "",
1435
- circle: "",
1436
- onClick: c[0] || (c[0] = (D) => C.value = !0)
1437
- }, {
1937
+ y("div", {
1938
+ ref_key: "scrollRef",
1939
+ ref: w,
1940
+ class: "chat-panel__body"
1941
+ }, [
1942
+ S(s).length ? (u(!0), x(G, { key: 1 }, X(S(s), (Z) => (u(), D(os, {
1943
+ key: Z.id,
1944
+ message: Z,
1945
+ "tool-packages": S(a),
1946
+ onExecute: U
1947
+ }, null, 8, ["message", "tool-packages"]))), 128)) : (u(), x("div", ws, [
1948
+ y("div", ks, [
1949
+ p(E, null, {
1438
1950
  default: v(() => [
1439
- _(J, null, {
1440
- default: v(() => [
1441
- _(A(oe))
1442
- ]),
1443
- _: 1
1444
- })
1951
+ p(V)
1445
1952
  ]),
1446
1953
  _: 1
1447
1954
  })
1448
1955
  ]),
1449
- _: 1
1450
- }),
1451
- _(x, {
1452
- content: "\u6E05\u7A7A\u5BF9\u8BDD",
1453
- placement: "bottom"
1454
- }, {
1455
- default: v(() => [
1456
- _(P, {
1457
- text: "",
1458
- circle: "",
1459
- disabled: !A(s).length,
1460
- onClick: w
1461
- }, {
1462
- default: v(() => [
1463
- _(J, null, {
1464
- default: v(() => [
1465
- _(A(Se))
1466
- ]),
1467
- _: 1
1468
- })
1469
- ]),
1470
- _: 1
1471
- }, 8, ["disabled"])
1472
- ]),
1473
- _: 1
1474
- })
1475
- ])
1476
- ])) : z("", !0),
1477
- f("div", {
1478
- ref_key: "scrollRef",
1479
- ref: M,
1480
- class: "chat-panel__body"
1481
- }, [
1482
- A(s).length ? (a(!0), m(K, { key: 1 }, U(A(s), (D) => (a(), j(Et, {
1483
- key: D.id,
1484
- message: D,
1485
- "tool-packages": A(E),
1486
- onExecute: T
1487
- }, null, 8, ["message", "tool-packages"]))), 128)) : (a(), m("div", jt, [
1488
- f("div", Nt, [
1489
- _(J, null, {
1490
- default: v(() => [
1491
- _(H)
1492
- ]),
1956
+ d[7] || (d[7] = y("h3", null, "你好,我是系统 AI 助手", -1)),
1957
+ d[8] || (d[8] = y("p", { class: "chat-empty__desc" }, [
1958
+ O(" 我可以帮你"),
1959
+ y("span", { class: "hl" }, "查询数据"),
1960
+ O(""),
1961
+ y("span", { class: "hl" }, "执行操作"),
1962
+ O("。试试输入指令: ")
1963
+ ], -1)),
1964
+ S(_) ? R("", !0) : (u(), D(ee, {
1965
+ key: 0,
1966
+ type: "primary",
1967
+ icon: S(xe),
1968
+ onClick: d[1] || (d[1] = (Z) => I.value = !0)
1969
+ }, {
1970
+ default: v(() => [...d[6] || (d[6] = [
1971
+ O(" 先配置 API Key ", -1)
1972
+ ])]),
1493
1973
  _: 1
1494
- })
1974
+ }, 8, ["icon"]))
1975
+ ]))
1976
+ ], 512),
1977
+ p(De, { name: "fade" }, {
1978
+ default: v(() => [
1979
+ S(l) ? (u(), x("div", Cs, [
1980
+ p(ce, {
1981
+ title: S(l),
1982
+ type: "error",
1983
+ "show-icon": "",
1984
+ closable: !1
1985
+ }, null, 8, ["title"])
1986
+ ])) : R("", !0)
1495
1987
  ]),
1496
- c[7] || (c[7] = f("h3", null, "\u4F60\u597D\uFF0C\u6211\u662F\u7CFB\u7EDF AI \u52A9\u624B", -1)),
1497
- c[8] || (c[8] = f("p", { class: "chat-empty__desc" }, [
1498
- R(" \u6211\u53EF\u4EE5\u5E2E\u4F60"),
1499
- f("span", { class: "hl" }, "\u67E5\u8BE2\u6570\u636E"),
1500
- R("\u3001"),
1501
- f("span", { class: "hl" }, "\u6267\u884C\u64CD\u4F5C"),
1502
- R("\u3002\u8BD5\u8BD5\u8F93\u5165\u6307\u4EE4\uFF1A ")
1503
- ], -1)),
1504
- A(p) ? z("", !0) : (a(), j(P, {
1505
- key: 0,
1506
- type: "primary",
1507
- icon: A(oe),
1508
- onClick: c[1] || (c[1] = (D) => C.value = !0)
1509
- }, {
1510
- default: v(() => [...c[6] || (c[6] = [
1511
- R(" \u5148\u914D\u7F6E API Key ", -1)
1512
- ])]),
1513
- _: 1
1514
- }, 8, ["icon"]))
1515
- ]))
1516
- ], 512),
1517
- _(ge, { name: "fade" }, {
1518
- default: v(() => [
1519
- A(l) ? (a(), m("div", Rt, [
1520
- _(I, {
1521
- title: A(l),
1522
- type: "error",
1523
- "show-icon": "",
1524
- closable: !1
1525
- }, null, 8, ["title"])
1526
- ])) : z("", !0)
1988
+ _: 1
1989
+ }),
1990
+ y("div", $s, [
1991
+ S(o) ? (u(), x("div", Ss, [
1992
+ p(ee, {
1993
+ size: "small",
1994
+ icon: S(St),
1995
+ onClick: S(h)
1996
+ }, {
1997
+ default: v(() => [...d[9] || (d[9] = [
1998
+ O("停止生成", -1)
1999
+ ])]),
2000
+ _: 1
2001
+ }, 8, ["icon", "onClick"])
2002
+ ])) : R("", !0),
2003
+ p(us, {
2004
+ loading: S(o),
2005
+ placeholder: S(_) ? "输入指令..." : "请先配置 API Key",
2006
+ onSend: U
2007
+ }, null, 8, ["loading", "placeholder"])
1527
2008
  ]),
1528
- _: 1
1529
- }),
1530
- f("div", Ht, [
1531
- A(r) ? (a(), m("div", Kt, [
1532
- _(P, {
1533
- size: "small",
1534
- icon: A(Le),
1535
- onClick: A(n)
1536
- }, {
1537
- default: v(() => [...c[9] || (c[9] = [
1538
- R("\u505C\u6B62\u751F\u6210", -1)
1539
- ])]),
1540
- _: 1
1541
- }, 8, ["icon", "onClick"])
1542
- ])) : z("", !0),
1543
- _(wt, {
1544
- loading: A(r),
1545
- placeholder: A(p) ? "\u8F93\u5165\u6307\u4EE4..." : "\u8BF7\u5148\u914D\u7F6E API Key",
1546
- onSend: T
1547
- }, null, 8, ["loading", "placeholder"])
1548
- ]),
1549
- _(Mt, {
1550
- modelValue: C.value,
1551
- "onUpdate:modelValue": c[2] || (c[2] = (D) => C.value = D),
1552
- settings: A(d),
1553
- onSave: h
1554
- }, null, 8, ["modelValue", "settings"])
2009
+ p(hs, {
2010
+ modelValue: I.value,
2011
+ "onUpdate:modelValue": d[2] || (d[2] = (Z) => I.value = Z),
2012
+ settings: S(i),
2013
+ "device-id": S(H),
2014
+ onSave: N
2015
+ }, null, 8, ["modelValue", "settings", "device-id"])
2016
+ ], 2), [
2017
+ [Fe, S(b)]
2018
+ ])
1555
2019
  ]);
1556
2020
  };
1557
2021
  }
1558
- });
1559
- const Xt = /* @__PURE__ */ Q(Lt, [["__scopeId", "data-v-b29b5a67"]]);
2022
+ }), Hs = /* @__PURE__ */ oe(Ms, [["__scopeId", "data-v-57d202bb"]]);
2023
+ function Is(t) {
2024
+ if (typeof t != "string")
2025
+ return t;
2026
+ try {
2027
+ const e = JSON.parse(t);
2028
+ return e !== null && (typeof e == "object" || Array.isArray(e)) ? e : t;
2029
+ } catch {
2030
+ return t;
2031
+ }
2032
+ }
2033
+ const Ns = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2034
+ __proto__: null,
2035
+ parseStringToObject: Is
2036
+ }, Symbol.toStringTag, { value: "Module" }));
1560
2037
  export {
1561
- he as Agent,
1562
- wt as ChatInput,
1563
- Et as ChatMessage,
1564
- Xt as ChatPanel,
1565
- Mt as ChatSettings,
1566
- ue as DEFAULT_SETTINGS,
1567
- nt as RenderBlock,
1568
- lt as SuggestedNext,
1569
- ve as ToolRegistry,
1570
- Ce as buildSystemPrompt,
1571
- ye as createDeepSeekProvider,
1572
- Gt as resolveRenderBlock,
1573
- qt as useAgentChat
2038
+ Re as Agent,
2039
+ us as ChatInput,
2040
+ os as ChatMessageComp,
2041
+ Hs as ChatPanel,
2042
+ hs as ChatSettingsComp,
2043
+ ve as DEFAULT_SETTINGS,
2044
+ et as EventBus,
2045
+ Ns as ParseUtils,
2046
+ jt as RenderBlockComp,
2047
+ Kt as SuggestedNext,
2048
+ Ke as ToolRegistry,
2049
+ Ge as buildSystemPrompt,
2050
+ Je as createDeepSeekProvider,
2051
+ tt as createEventBus,
2052
+ We as createProxyProvider,
2053
+ zs as resolveRenderBlock,
2054
+ Bs as useAgentChat
1574
2055
  };