@qfei-design/make-ai-assistant 0.2.1 → 0.2.2

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/react.mjs CHANGED
@@ -1,70 +1,70 @@
1
- import { jsxs as i, jsx as a, Fragment as H } from "react/jsx-runtime";
2
- import { resolveArtifactTemplate as _t, createArtifactTemplateRegistry as je, createArtifactCapabilities as vt } from "./index.mjs";
3
- import { extendArtifactTemplateRegistry as la } from "./index.mjs";
4
- import { useState as R, useRef as w, useEffect as Q, useMemo as He } from "react";
5
- import { a as ge, r as fe, c as _e, M as N, b as yt, p as kt } from "./conversation-B7eGUXi-.js";
6
- import { d as ma, e as ua, f as pa, g as ha, v as ga } from "./conversation-B7eGUXi-.js";
7
- function At({
1
+ import { jsxs as r, jsx as a, Fragment as K } from "react/jsx-runtime";
2
+ import { resolveArtifactTemplate as At, createArtifactTemplateRegistry as We, createArtifactCapabilities as It } from "./index.mjs";
3
+ import { extendArtifactTemplateRegistry as ya } from "./index.mjs";
4
+ import { useState as x, useRef as N, useEffect as Q, useMemo as Oe } from "react";
5
+ import { a as fe, r as ge, c as _e, M as w, b as wt, p as Nt } from "./conversation-B7eGUXi-.js";
6
+ import { d as Aa, e as Ia, f as wa, g as Na, v as Ma } from "./conversation-B7eGUXi-.js";
7
+ function Mt({
8
8
  artifact: e,
9
9
  context: t,
10
10
  fallback: s,
11
- onAction: n,
12
- onActionError: r,
11
+ onAction: i,
12
+ onActionError: n,
13
13
  registry: o
14
14
  }) {
15
- const d = _t(o, e, t);
16
- if (!d)
17
- return s ? s(e) : /* @__PURE__ */ i("section", { className: "make-ai-artifact make-ai-artifact--unsupported", role: "status", children: [
15
+ const l = At(o, e, t);
16
+ if (!l)
17
+ return s ? s(e) : /* @__PURE__ */ r("section", { className: "make-ai-artifact make-ai-artifact--unsupported", role: "status", children: [
18
18
  /* @__PURE__ */ a("strong", { children: "暂不支持展示此结果" }),
19
- /* @__PURE__ */ i("span", { children: [
19
+ /* @__PURE__ */ r("span", { children: [
20
20
  "结果类型:",
21
21
  e.kind
22
22
  ] })
23
23
  ] });
24
- const p = {
24
+ const m = {
25
25
  context: t,
26
- onAction: n,
27
- onActionError: r
26
+ onAction: i,
27
+ onActionError: n
28
28
  };
29
- return d.template.render(e, t, p);
29
+ return l.template.render(e, t, m);
30
30
  }
31
- const K = (e, t, s) => {
31
+ const z = (e, t, s) => {
32
32
  if (e == null || e === "") return "—";
33
33
  if (typeof e == "boolean") return e ? "是" : "否";
34
34
  if (typeof e != "number") return `${e}${t?.unit ?? ""}`;
35
- const n = t?.precision, r = {
36
- maximumFractionDigits: n ?? 2,
37
- minimumFractionDigits: n
35
+ const i = t?.precision, n = {
36
+ maximumFractionDigits: i ?? 2,
37
+ minimumFractionDigits: i
38
38
  };
39
- t?.style === "currency" && t.currency ? (r.style = "currency", r.currency = t.currency) : t?.style === "percent" && (r.style = "percent");
39
+ t?.style === "currency" && t.currency ? (n.style = "currency", n.currency = t.currency) : t?.style === "percent" && (n.style = "percent");
40
40
  try {
41
41
  const o = t?.style === "percent" ? e / 100 : e;
42
- return `${new Intl.NumberFormat(s, r).format(o)}${t?.unit ?? ""}`;
42
+ return `${new Intl.NumberFormat(s, n).format(o)}${t?.unit ?? ""}`;
43
43
  } catch {
44
44
  return `${e}${t?.unit ?? ""}`;
45
45
  }
46
- }, Ze = (e) => {
46
+ }, Ye = (e) => {
47
47
  let t = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
48
- for (const n of e)
49
- t = Math.min(t, n), s = Math.max(s, n);
48
+ for (const i of e)
49
+ t = Math.min(t, i), s = Math.max(s, i);
50
50
  return Number.isFinite(t) && Number.isFinite(s) ? { min: t, max: s } : { min: 0, max: 0 };
51
- }, Ge = (e, t, s) => {
51
+ }, Je = (e, t, s) => {
52
52
  if (!s.onAction) return;
53
- const n = (o) => {
53
+ const i = (o) => {
54
54
  console.error("[make-ai-assistant] host action error handler failed", {
55
55
  actionId: e.id,
56
56
  artifactId: t.artifact.id,
57
57
  errorType: o instanceof Error ? o.name : typeof o,
58
58
  intent: e.intent
59
59
  });
60
- }, r = (o) => {
60
+ }, n = (o) => {
61
61
  if (s.onActionError) {
62
62
  try {
63
63
  Promise.resolve(
64
64
  s.onActionError(o, e, t)
65
- ).catch(n);
66
- } catch (d) {
67
- n(d);
65
+ ).catch(i);
66
+ } catch (l) {
67
+ i(l);
68
68
  }
69
69
  return;
70
70
  }
@@ -76,23 +76,23 @@ const K = (e, t, s) => {
76
76
  });
77
77
  };
78
78
  try {
79
- Promise.resolve(s.onAction(e, t)).catch(r);
79
+ Promise.resolve(s.onAction(e, t)).catch(n);
80
80
  } catch (o) {
81
- r(o);
81
+ n(o);
82
82
  }
83
- }, X = (e, t) => e.actions?.length && t.onAction ? /* @__PURE__ */ a("div", { className: "make-ai-artifact__actions", children: e.actions.map((s) => /* @__PURE__ */ i(
83
+ }, X = (e, t) => e.actions?.length && t.onAction ? /* @__PURE__ */ a("div", { className: "make-ai-artifact__actions", children: e.actions.map((s) => /* @__PURE__ */ r(
84
84
  "button",
85
85
  {
86
86
  className: `make-ai-artifact__action make-ai-artifact__action--${s.appearance ?? "link"}`,
87
87
  type: "button",
88
- onClick: () => Ge(s, { artifact: e, context: t.context }, t),
88
+ onClick: () => Je(s, { artifact: e, context: t.context }, t),
89
89
  children: [
90
90
  s.label,
91
91
  /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "→" })
92
92
  ]
93
93
  },
94
94
  s.id
95
- )) }) : null, ee = (e, t, s = "") => /* @__PURE__ */ i(
95
+ )) }) : null, ee = (e, t, s = "") => /* @__PURE__ */ r(
96
96
  "section",
97
97
  {
98
98
  "aria-label": e.title ?? `${e.kind} result`,
@@ -105,30 +105,30 @@ const K = (e, t, s) => {
105
105
  t
106
106
  ]
107
107
  }
108
- ), bt = ({
108
+ ), Tt = ({
109
109
  artifact: e,
110
110
  renderContext: t
111
111
  }) => {
112
- const s = e.data.delta, n = s ? K(
112
+ const s = e.data.delta, i = s ? z(
113
113
  s.value,
114
114
  s.format === "percent" ? { style: "percent" } : void 0,
115
115
  t.context.locale
116
116
  ) : void 0;
117
117
  return ee(
118
118
  e,
119
- /* @__PURE__ */ i(H, { children: [
120
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__metric-value", children: K(
119
+ /* @__PURE__ */ r(K, { children: [
120
+ /* @__PURE__ */ a("div", { className: "make-ai-artifact__metric-value", children: z(
121
121
  e.data.value,
122
122
  e.data.format,
123
123
  t.context.locale
124
124
  ) }),
125
- s ? /* @__PURE__ */ i(
125
+ s ? /* @__PURE__ */ r(
126
126
  "div",
127
127
  {
128
128
  className: `make-ai-artifact__delta make-ai-artifact__delta--${s.direction ?? "flat"}`,
129
129
  children: [
130
130
  /* @__PURE__ */ a("span", { "aria-hidden": "true", children: s.direction === "up" ? "↗" : s.direction === "down" ? "↘" : "→" }),
131
- /* @__PURE__ */ a("span", { children: n }),
131
+ /* @__PURE__ */ a("span", { children: i }),
132
132
  s.label ? /* @__PURE__ */ a("span", { children: s.label }) : null
133
133
  ]
134
134
  }
@@ -138,99 +138,99 @@ const K = (e, t, s) => {
138
138
  ] }),
139
139
  "make-ai-artifact--metric"
140
140
  );
141
- }, It = ({
141
+ }, $t = ({
142
142
  artifact: e,
143
143
  renderContext: t
144
144
  }) => ee(
145
145
  e,
146
- /* @__PURE__ */ i(H, { children: [
147
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__comparison", children: e.data.items.map((s) => /* @__PURE__ */ i("div", { className: "make-ai-artifact__comparison-item", children: [
146
+ /* @__PURE__ */ r(K, { children: [
147
+ /* @__PURE__ */ a("div", { className: "make-ai-artifact__comparison", children: e.data.items.map((s) => /* @__PURE__ */ r("div", { className: "make-ai-artifact__comparison-item", children: [
148
148
  /* @__PURE__ */ a("span", { children: s.label }),
149
- /* @__PURE__ */ a("strong", { children: K(s.value, s.format, t.context.locale) }),
149
+ /* @__PURE__ */ a("strong", { children: z(s.value, s.format, t.context.locale) }),
150
150
  s.hint ? /* @__PURE__ */ a("small", { children: s.hint }) : null
151
151
  ] }, s.id)) }),
152
152
  X(e, t)
153
153
  ] }),
154
154
  "make-ai-artifact--comparison"
155
- ), Nt = ({
155
+ ), Ct = ({
156
156
  artifact: e,
157
157
  renderContext: t
158
158
  }) => {
159
- const s = e.data.series.flatMap((d) => d.points.map((p) => p.y)), { max: n, min: r } = Ze(s), o = n - r || 1;
159
+ const s = e.data.series.flatMap((l) => l.points.map((m) => m.y)), { max: i, min: n } = Ye(s), o = i - n || 1;
160
160
  return ee(
161
161
  e,
162
- /* @__PURE__ */ i(H, { children: [
163
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend", children: e.data.series.map((d) => /* @__PURE__ */ i("div", { className: "make-ai-artifact__trend-series", children: [
164
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-label", children: d.label }),
165
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-bars", children: d.points.map((p, f) => {
166
- const b = 18 + (p.y - r) / o * 70;
167
- return /* @__PURE__ */ i("div", { className: "make-ai-artifact__trend-point", children: [
162
+ /* @__PURE__ */ r(K, { children: [
163
+ /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend", children: e.data.series.map((l) => /* @__PURE__ */ r("div", { className: "make-ai-artifact__trend-series", children: [
164
+ /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-label", children: l.label }),
165
+ /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-bars", children: l.points.map((m, k) => {
166
+ const p = 18 + (m.y - n) / o * 70;
167
+ return /* @__PURE__ */ r("div", { className: "make-ai-artifact__trend-point", children: [
168
168
  /* @__PURE__ */ a(
169
169
  "span",
170
170
  {
171
- "aria-label": `${p.x}: ${K(
172
- p.y,
173
- d.format,
171
+ "aria-label": `${m.x}: ${z(
172
+ m.y,
173
+ l.format,
174
174
  t.context.locale
175
175
  )}`,
176
176
  className: "make-ai-artifact__trend-bar",
177
177
  role: "img",
178
- style: { height: `${b}%` },
179
- title: `${p.x}: ${K(
180
- p.y,
181
- d.format,
178
+ style: { height: `${p}%` },
179
+ title: `${m.x}: ${z(
180
+ m.y,
181
+ l.format,
182
182
  t.context.locale
183
183
  )}`
184
184
  }
185
185
  ),
186
- /* @__PURE__ */ a("small", { children: p.x })
187
- ] }, `${p.x}-${f}`);
186
+ /* @__PURE__ */ a("small", { children: m.x })
187
+ ] }, `${m.x}-${k}`);
188
188
  }) })
189
- ] }, d.id)) }),
189
+ ] }, l.id)) }),
190
190
  X(e, t)
191
191
  ] }),
192
192
  "make-ai-artifact--trend"
193
193
  );
194
- }, wt = ({
194
+ }, Et = ({
195
195
  artifact: e,
196
196
  renderContext: t
197
197
  }) => {
198
- const { max: s } = Ze(
199
- e.data.items.map((r) => Math.abs(r.value))
200
- ), n = Math.max(s, 1);
198
+ const { max: s } = Ye(
199
+ e.data.items.map((n) => Math.abs(n.value))
200
+ ), i = Math.max(s, 1);
201
201
  return ee(
202
202
  e,
203
- /* @__PURE__ */ i(H, { children: [
204
- /* @__PURE__ */ a("ol", { className: "make-ai-artifact__ranking", children: e.data.items.map((r, o) => /* @__PURE__ */ i("li", { children: [
203
+ /* @__PURE__ */ r(K, { children: [
204
+ /* @__PURE__ */ a("ol", { className: "make-ai-artifact__ranking", children: e.data.items.map((n, o) => /* @__PURE__ */ r("li", { children: [
205
205
  /* @__PURE__ */ a("span", { className: "make-ai-artifact__rank", children: o + 1 }),
206
- /* @__PURE__ */ i("span", { className: "make-ai-artifact__ranking-label", children: [
207
- /* @__PURE__ */ a("span", { children: r.label }),
208
- r.description ? /* @__PURE__ */ a("small", { children: r.description }) : null
206
+ /* @__PURE__ */ r("span", { className: "make-ai-artifact__ranking-label", children: [
207
+ /* @__PURE__ */ a("span", { children: n.label }),
208
+ n.description ? /* @__PURE__ */ a("small", { children: n.description }) : null
209
209
  ] }),
210
- /* @__PURE__ */ a("span", { className: "make-ai-artifact__ranking-track", "aria-hidden": "true", children: /* @__PURE__ */ a("span", { style: { width: `${Math.abs(r.value) / n * 100}%` } }) }),
211
- /* @__PURE__ */ a("strong", { children: K(r.value, r.format, t.context.locale) })
212
- ] }, r.id)) }),
210
+ /* @__PURE__ */ a("span", { className: "make-ai-artifact__ranking-track", "aria-hidden": "true", children: /* @__PURE__ */ a("span", { style: { width: `${Math.abs(n.value) / i * 100}%` } }) }),
211
+ /* @__PURE__ */ a("strong", { children: z(n.value, n.format, t.context.locale) })
212
+ ] }, n.id)) }),
213
213
  X(e, t)
214
214
  ] }),
215
215
  "make-ai-artifact--ranking"
216
216
  );
217
- }, Mt = (e, t) => t.action ?? {
217
+ }, St = (e, t) => t.action ?? {
218
218
  id: `open-${t.id}`,
219
219
  label: t.title ?? t.id,
220
220
  intent: "open-record",
221
221
  target: { entityKey: e.data.entity.key, recordId: t.id }
222
- }, Tt = ({
222
+ }, xt = ({
223
223
  artifact: e,
224
224
  renderContext: t
225
225
  }) => ee(
226
226
  e,
227
- /* @__PURE__ */ i(H, { children: [
227
+ /* @__PURE__ */ r(K, { children: [
228
228
  /* @__PURE__ */ a("div", { className: "make-ai-artifact__record-list", children: e.data.records.length === 0 ? /* @__PURE__ */ a("p", { className: "make-ai-artifact__empty", children: "没有符合条件的记录" }) : e.data.records.map((s) => {
229
- const n = Mt(e, s), r = /* @__PURE__ */ i(H, { children: [
229
+ const i = St(e, s), n = /* @__PURE__ */ r(K, { children: [
230
230
  /* @__PURE__ */ a("strong", { children: s.title ?? s.id }),
231
- /* @__PURE__ */ a("span", { className: "make-ai-artifact__record-values", children: e.data.columns.map((o) => /* @__PURE__ */ i("span", { children: [
231
+ /* @__PURE__ */ a("span", { className: "make-ai-artifact__record-values", children: e.data.columns.map((o) => /* @__PURE__ */ r("span", { children: [
232
232
  /* @__PURE__ */ a("small", { children: o.label }),
233
- K(
233
+ z(
234
234
  s.values[o.key],
235
235
  o.format,
236
236
  t.context.locale
@@ -243,16 +243,16 @@ const K = (e, t, s) => {
243
243
  {
244
244
  className: "make-ai-artifact__record",
245
245
  type: "button",
246
- onClick: () => Ge(n, {
246
+ onClick: () => Je(i, {
247
247
  artifact: e,
248
248
  context: t.context
249
249
  }, t),
250
- children: r
250
+ children: n
251
251
  },
252
252
  s.id
253
- ) : /* @__PURE__ */ a("div", { className: "make-ai-artifact__record", children: r }, s.id);
253
+ ) : /* @__PURE__ */ a("div", { className: "make-ai-artifact__record", children: n }, s.id);
254
254
  }) }),
255
- e.data.total !== void 0 ? /* @__PURE__ */ i("p", { className: "make-ai-artifact__record-total", children: [
255
+ e.data.total !== void 0 ? /* @__PURE__ */ r("p", { className: "make-ai-artifact__record-total", children: [
256
256
  "共 ",
257
257
  e.data.total,
258
258
  " 条"
@@ -260,34 +260,64 @@ const K = (e, t, s) => {
260
260
  X(e, t)
261
261
  ] }),
262
262
  "make-ai-artifact--record-list"
263
- ), Ct = ({
263
+ ), Rt = ({
264
264
  artifact: e,
265
265
  renderContext: t
266
266
  }) => ee(
267
267
  e,
268
- /* @__PURE__ */ i(H, { children: [
269
- /* @__PURE__ */ i("div", { className: `make-ai-artifact__notice make-ai-artifact__notice--${e.data.tone}`, children: [
268
+ /* @__PURE__ */ r(K, { children: [
269
+ /* @__PURE__ */ r("div", { className: `make-ai-artifact__notice make-ai-artifact__notice--${e.data.tone}`, children: [
270
270
  /* @__PURE__ */ a("span", { "aria-hidden": "true", children: e.data.tone === "success" ? "✓" : e.data.tone === "warning" ? "!" : e.data.tone === "danger" ? "×" : "i" }),
271
271
  /* @__PURE__ */ a("p", { children: e.data.body })
272
272
  ] }),
273
273
  X(e, t)
274
274
  ] }),
275
275
  "make-ai-artifact--notice"
276
- ), J = (e, t, s) => ({ id: e, kinds: [t], priority: 0, render: s }), $t = [
277
- J("platform.metric.default", "metric", (e, t, s) => /* @__PURE__ */ a(bt, { artifact: e, renderContext: s })),
278
- J("platform.comparison.default", "comparison", (e, t, s) => /* @__PURE__ */ a(It, { artifact: e, renderContext: s })),
279
- J("platform.trend.default", "trend", (e, t, s) => /* @__PURE__ */ a(Nt, { artifact: e, renderContext: s })),
280
- J("platform.ranking.default", "ranking", (e, t, s) => /* @__PURE__ */ a(wt, { artifact: e, renderContext: s })),
281
- J("platform.record-list.default", "record-list", (e, t, s) => /* @__PURE__ */ a(Tt, { artifact: e, renderContext: s })),
282
- J("platform.notice.default", "notice", (e, t, s) => /* @__PURE__ */ a(Ct, { artifact: e, renderContext: s }))
283
- ], Et = je($t).templates, St = (e = Et) => je(e), Rt = (e) => `${e}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, xt = "Make", Lt = [
276
+ ), J = (e, t, s) => ({ id: e, kinds: [t], priority: 0, render: s }), Lt = [
277
+ J("platform.metric.default", "metric", (e, t, s) => /* @__PURE__ */ a(Tt, { artifact: e, renderContext: s })),
278
+ J("platform.comparison.default", "comparison", (e, t, s) => /* @__PURE__ */ a($t, { artifact: e, renderContext: s })),
279
+ J("platform.trend.default", "trend", (e, t, s) => /* @__PURE__ */ a(Ct, { artifact: e, renderContext: s })),
280
+ J("platform.ranking.default", "ranking", (e, t, s) => /* @__PURE__ */ a(Et, { artifact: e, renderContext: s })),
281
+ J("platform.record-list.default", "record-list", (e, t, s) => /* @__PURE__ */ a(xt, { artifact: e, renderContext: s })),
282
+ J("platform.notice.default", "notice", (e, t, s) => /* @__PURE__ */ a(Rt, { artifact: e, renderContext: s }))
283
+ ], Ft = We(Lt).templates, Pt = (e = Ft) => We(e), Bt = (e) => `${e}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, Dt = "Make", qt = [
284
284
  "总结当前页面数据",
285
285
  "找出需要关注的记录",
286
286
  "列出我有权限查看的数据对象"
287
- ], Ye = (e, t) => t ?? `${e?.trim() || xt} AI 助手`, Ft = (e) => e ?? Lt;
287
+ ], Qe = (e, t) => t ?? `${e?.trim() || Dt} AI 助手`, Vt = (e) => e ?? qt;
288
288
  class v extends Error {
289
289
  }
290
- const Ke = (e) => {
290
+ const ve = (e, t) => {
291
+ if (!(typeof e != "object" || e === null))
292
+ return e[t];
293
+ }, Ht = (e) => {
294
+ const t = ve(e, "status");
295
+ return typeof t == "number" ? t : ve(
296
+ ve(e, "response"),
297
+ "status"
298
+ );
299
+ }, Ut = (e) => {
300
+ const t = ve(e, "code"), s = Ht(e), i = e instanceof Error ? e.message : "", n = [t, i].filter((k) => typeof k == "string").join(" ").toLowerCase(), l = globalThis.navigator?.onLine === !1 || /network|fetch|timeout|offline|connection|网络|连接|超时/.test(n), m = typeof s == "number" && s >= 500 || /server|service|服务器|服务异常/.test(n);
301
+ return l ? {
302
+ actionLabel: "重新连接",
303
+ description: "请检查网络后再试。",
304
+ kind: "network",
305
+ label: "网络连接",
306
+ title: "网络连接不可用"
307
+ } : m ? {
308
+ actionLabel: "重新加载",
309
+ description: "服务暂时未能响应,请稍后重试。",
310
+ kind: "service",
311
+ label: "服务异常",
312
+ title: "服务暂时不可用"
313
+ } : {
314
+ actionLabel: "重新加载",
315
+ description: "请稍后重试;若问题持续出现,请联系管理员。",
316
+ kind: "unknown",
317
+ label: "加载异常",
318
+ title: "暂时无法加载对话"
319
+ };
320
+ }, je = (e) => {
291
321
  try {
292
322
  const t = e?.return?.();
293
323
  if (!t) return;
@@ -301,7 +331,7 @@ const Ke = (e) => {
301
331
  errorType: t instanceof Error ? t.name : typeof t
302
332
  });
303
333
  }
304
- }, Pt = async (e) => {
334
+ }, Kt = async (e) => {
305
335
  if (globalThis.navigator?.clipboard?.writeText) {
306
336
  await globalThis.navigator.clipboard.writeText(e);
307
337
  return;
@@ -313,140 +343,183 @@ const Ke = (e) => {
313
343
  const s = document.execCommand("copy");
314
344
  if (t.remove(), !s)
315
345
  throw new Error("Clipboard copy failed");
316
- }, We = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
346
+ }, Xe = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
317
347
  /* @__PURE__ */ a("path", { d: "M12 2.8c.5 4.4 2.8 6.8 7.2 7.2-4.4.5-6.8 2.8-7.2 7.2-.5-4.4-2.8-6.8-7.2-7.2 4.4-.5 6.8-2.8 7.2-7.2Z" }),
318
348
  /* @__PURE__ */ a("path", { d: "M18.3 16.1c.2 1.8 1.2 2.8 3 3-1.8.2-2.8 1.2-3 3-.2-1.8-1.2-2.8-3-3 1.8-.2 2.8-1.2 3-3Z" })
319
- ] }), Bt = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m6 6 12 12M18 6 6 18" }) }), Dt = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
349
+ ] }), zt = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m6 6 12 12M18 6 6 18" }) }), Ot = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
320
350
  /* @__PURE__ */ a("path", { d: "M8 8h10v12H8z" }),
321
351
  /* @__PURE__ */ a("path", { d: "M6 16H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
322
- ] }), Vt = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
352
+ ] }), jt = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
323
353
  /* @__PURE__ */ a("path", { d: "M20 11a8 8 0 0 0-14.7-4.4L4 8" }),
324
354
  /* @__PURE__ */ a("path", { d: "M4 4v4h4" }),
325
355
  /* @__PURE__ */ a("path", { d: "M4 13a8 8 0 0 0 14.7 4.4L20 16" }),
326
356
  /* @__PURE__ */ a("path", { d: "M20 20v-4h-4" })
327
- ] }), qt = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
357
+ ] }), Zt = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
328
358
  /* @__PURE__ */ a("path", { d: "M5 10v4" }),
329
359
  /* @__PURE__ */ a("path", { d: "M8 9v6l6 3V6L8 9Z" }),
330
360
  /* @__PURE__ */ a("path", { d: "M17 9.2a4.2 4.2 0 0 1 0 5.6" }),
331
361
  /* @__PURE__ */ a("path", { d: "M19.4 6.8a7.6 7.6 0 0 1 0 10.4" })
332
- ] }), Ut = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
362
+ ] }), Gt = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
333
363
  /* @__PURE__ */ a("path", { d: "M12 4v11" }),
334
364
  /* @__PURE__ */ a("path", { d: "m7 10 5 5 5-5" }),
335
365
  /* @__PURE__ */ a("path", { d: "M5 20h14" })
336
- ] }), Ht = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "M12 5v14M5 12h14" }) }), Kt = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
366
+ ] }), Wt = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "M12 5v14M5 12h14" }) }), Yt = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
337
367
  /* @__PURE__ */ a("path", { d: "m4 4 17 8-17 8 3-8-3-8Z" }),
338
368
  /* @__PURE__ */ a("path", { d: "M7 12h14" })
339
- ] }), ie = ({ className: e = "" }) => /* @__PURE__ */ a("span", { className: `make-ai-assistant__avatar ${e}`.trim(), "aria-hidden": "true", children: /* @__PURE__ */ a(We, {}) }), zt = ({ src: e }) => e ? /* @__PURE__ */ a("span", { className: "make-ai-assistant__user-avatar", "aria-hidden": "true", children: /* @__PURE__ */ a("img", { alt: "", src: e }) }) : null, Ot = ({
369
+ ] }), et = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
370
+ /* @__PURE__ */ a("path", { d: "M20 11a8 8 0 0 0-14.7-4.4L4 8" }),
371
+ /* @__PURE__ */ a("path", { d: "M4 4v4h4" }),
372
+ /* @__PURE__ */ a("path", { d: "M4 13a8 8 0 0 0 14.7 4.4L20 16" }),
373
+ /* @__PURE__ */ a("path", { d: "M20 20v-4h-4" })
374
+ ] }), Jt = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
375
+ /* @__PURE__ */ a("circle", { cx: "12", cy: "12", r: "8" }),
376
+ /* @__PURE__ */ a("path", { d: "M12 8v4.5" }),
377
+ /* @__PURE__ */ a("path", { d: "M12 16h.01" })
378
+ ] }), ke = ({ className: e = "" }) => /* @__PURE__ */ a("span", { className: `make-ai-assistant__avatar ${e}`.trim(), "aria-hidden": "true", children: /* @__PURE__ */ a(Xe, {}) }), Qt = ({ src: e }) => e ? /* @__PURE__ */ a("span", { className: "make-ai-assistant__user-avatar", "aria-hidden": "true", children: /* @__PURE__ */ a("img", { alt: "", src: e }) }) : null, Xt = ({
340
379
  userAvatarUrl: e,
341
380
  userName: t
342
381
  }) => {
343
382
  const s = t?.trim();
344
- return !s && !e ? null : /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-identity", children: [
383
+ return !s && !e ? null : /* @__PURE__ */ r("div", { className: "make-ai-assistant__message-identity", children: [
345
384
  s ? /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-sender", children: s }) : null,
346
- /* @__PURE__ */ a(zt, { src: e })
385
+ /* @__PURE__ */ a(Qt, { src: e })
347
386
  ] });
348
- }, jt = (e) => {
349
- const t = [], s = [], n = [], r = [], o = () => {
350
- const f = s.join(`
387
+ }, we = (e) => {
388
+ const t = e.trim();
389
+ if (!(!t.startsWith("|") || !t.endsWith("|")))
390
+ return t.slice(1, -1).split("|").map((s) => s.trim());
391
+ }, ea = (e) => e.length > 0 && e.every((t) => /^:?-{3,}:?$/.test(t)), ta = (e, t) => {
392
+ const s = we(e[t] ?? ""), i = we(e[t + 1] ?? "");
393
+ if (!s || !i || s.length !== i.length || !ea(i))
394
+ return;
395
+ const n = [];
396
+ let o = t + 2;
397
+ for (; o < e.length; ) {
398
+ const l = we(e[o] ?? "");
399
+ if (!l || l.length !== s.length) break;
400
+ n.push(l), o += 1;
401
+ }
402
+ return { headers: s, lastIndex: o - 1, rows: n };
403
+ }, aa = (e) => {
404
+ const t = [], s = [], i = [], n = [], o = e.replace(/\r\n?/g, `
405
+ `).split(`
406
+ `), l = () => {
407
+ const p = s.join(`
351
408
  `).trim();
352
- s.length = 0, f && t.push({ type: "paragraph", text: f });
353
- }, d = () => {
354
- n.length && t.push({ type: "list", items: n.splice(0) });
355
- }, p = () => {
356
- const f = r.join(`
409
+ s.length = 0, p && t.push({ type: "paragraph", text: p });
410
+ }, m = () => {
411
+ i.length && t.push({ type: "list", items: i.splice(0) });
412
+ }, k = () => {
413
+ const p = n.join(`
357
414
  `).trim();
358
- r.length = 0, f && t.push({ type: "pre", text: f });
415
+ n.length = 0, p && t.push({ type: "pre", text: p });
359
416
  };
360
- for (const f of e.replace(/\r\n?/g, `
361
- `).split(`
362
- `)) {
363
- const b = f.trim();
364
- if (!b) {
365
- o(), d(), p();
417
+ for (let p = 0; p < o.length; p += 1) {
418
+ const M = o[p] ?? "", T = M.trim();
419
+ if (!T) {
420
+ l(), m(), k();
421
+ continue;
422
+ }
423
+ const u = ta(o, p);
424
+ if (u) {
425
+ l(), m(), k(), t.push({ headers: u.headers, rows: u.rows, type: "table" }), p = u.lastIndex;
366
426
  continue;
367
427
  }
368
- const C = /^(#{1,6})\s+(.+)$/.exec(b);
369
- if (C) {
370
- o(), d(), p();
371
- const m = (C[2] ?? "").replace(/\s+#+\s*$/, "").trim();
372
- m && t.push({
428
+ const $ = /^(#{1,6})\s+(.+)$/.exec(T);
429
+ if ($) {
430
+ l(), m(), k();
431
+ const y = ($[2] ?? "").replace(/\s+#+\s*$/, "").trim();
432
+ y && t.push({
373
433
  type: "heading",
374
- level: C[1]?.length,
375
- text: m
434
+ level: $[1]?.length,
435
+ text: y
376
436
  });
377
437
  continue;
378
438
  }
379
- if (/^\s*\|.+\|\s*$/.test(f)) {
380
- o(), d(), r.push(f.trim());
439
+ if (/^\s*\|.+\|\s*$/.test(M)) {
440
+ l(), m(), n.push(M.trim());
381
441
  continue;
382
442
  }
383
- const $ = /^\s*[-*]\s+(.+)$/.exec(f);
384
- if ($) {
385
- o(), p(), n.push($[1]?.trim() ?? "");
443
+ const R = /^\s*[-*]\s+(.+)$/.exec(M);
444
+ if (R) {
445
+ l(), k(), i.push(R[1]?.trim() ?? "");
386
446
  continue;
387
447
  }
388
- d(), p(), s.push(b);
448
+ m(), k(), s.push(T);
389
449
  }
390
- return o(), d(), p(), t;
391
- }, Ae = (e) => {
450
+ return l(), m(), k(), t;
451
+ }, ie = (e) => {
392
452
  const t = [], s = /(\*\*[^*]+\*\*|`[^`]+`)/g;
393
- let n = 0;
394
- for (const r of e.matchAll(s)) {
395
- const o = r[0], d = r.index ?? 0;
396
- d > n && t.push(e.slice(n, d)), o.startsWith("**") ? t.push(/* @__PURE__ */ a("strong", { children: o.slice(2, -2) }, `${d}-strong`)) : t.push(/* @__PURE__ */ a("code", { children: o.slice(1, -1) }, `${d}-code`)), n = d + o.length;
453
+ let i = 0;
454
+ for (const n of e.matchAll(s)) {
455
+ const o = n[0], l = n.index ?? 0;
456
+ l > i && t.push(e.slice(i, l)), o.startsWith("**") ? t.push(/* @__PURE__ */ a("strong", { children: o.slice(2, -2) }, `${l}-strong`)) : t.push(/* @__PURE__ */ a("code", { children: o.slice(1, -1) }, `${l}-code`)), i = l + o.length;
397
457
  }
398
- return n < e.length && t.push(e.slice(n)), t;
399
- }, Zt = ({ content: e }) => {
400
- const t = jt(e);
401
- return t.length ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble make-ai-assistant__assistant-text", children: t.map((s, n) => {
458
+ return i < e.length && t.push(e.slice(i)), t;
459
+ }, sa = ({ content: e }) => {
460
+ const t = aa(e);
461
+ return t.length ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble make-ai-assistant__assistant-text", children: t.map((s, i) => {
402
462
  if (s.type === "heading") {
403
- const r = s.level <= 2 ? "h3" : "h4";
463
+ const n = s.level <= 2 ? "h3" : "h4";
404
464
  return /* @__PURE__ */ a(
405
- r,
465
+ n,
406
466
  {
407
467
  className: `make-ai-assistant__markdown-heading make-ai-assistant__markdown-heading--${s.level}`,
408
- children: Ae(s.text)
468
+ children: ie(s.text)
409
469
  },
410
- `${n}-heading`
470
+ `${i}-heading`
411
471
  );
412
472
  }
413
- return s.type === "paragraph" ? /* @__PURE__ */ a("p", { children: Ae(s.text) }, `${n}-paragraph`) : s.type === "pre" ? /* @__PURE__ */ a("pre", { children: /* @__PURE__ */ a("code", { children: s.text }) }, `${n}-pre`) : /* @__PURE__ */ a("ul", { children: s.items.map((r, o) => /* @__PURE__ */ a("li", { children: Ae(r) }, `${o}-${r}`)) }, `${n}-list`);
473
+ return s.type === "paragraph" ? /* @__PURE__ */ a("p", { children: ie(s.text) }, `${i}-paragraph`) : s.type === "pre" ? /* @__PURE__ */ a("pre", { children: /* @__PURE__ */ a("code", { children: s.text }) }, `${i}-pre`) : s.type === "table" ? /* @__PURE__ */ a(
474
+ "div",
475
+ {
476
+ "aria-label": "表格内容,可横向滚动",
477
+ className: "make-ai-assistant__markdown-table-scroll",
478
+ role: "region",
479
+ tabIndex: 0,
480
+ children: /* @__PURE__ */ r("table", { className: "make-ai-assistant__markdown-table", children: [
481
+ /* @__PURE__ */ a("thead", { children: /* @__PURE__ */ a("tr", { children: s.headers.map((n, o) => /* @__PURE__ */ a("th", { scope: "col", children: ie(n) }, `${o}-${n}`)) }) }),
482
+ /* @__PURE__ */ a("tbody", { children: s.rows.map((n, o) => /* @__PURE__ */ a("tr", { children: n.map((l, m) => /* @__PURE__ */ a("td", { children: ie(l) }, `${m}-${l}`)) }, `${o}-${n.join("|")}`)) })
483
+ ] })
484
+ },
485
+ `${i}-table`
486
+ ) : /* @__PURE__ */ a("ul", { children: s.items.map((n, o) => /* @__PURE__ */ a("li", { children: ie(n) }, `${o}-${n}`)) }, `${i}-list`);
414
487
  }) }) : null;
415
- }, Je = ({ assistantName: e }) => /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-identity", children: [
416
- /* @__PURE__ */ a(ie, { className: "make-ai-assistant__avatar--message" }),
488
+ }, tt = ({ assistantName: e }) => /* @__PURE__ */ r("div", { className: "make-ai-assistant__message-identity", children: [
489
+ /* @__PURE__ */ a(ke, { className: "make-ai-assistant__avatar--message" }),
417
490
  /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-sender", children: e })
418
- ] }), Qe = (e) => {
491
+ ] }), at = (e) => {
419
492
  for (let t = e.messages.length - 1; t >= 0; t -= 1) {
420
493
  const s = e.messages[t];
421
494
  if (s.role === "assistant" && s.status === "streaming")
422
495
  return s.id;
423
496
  }
424
- }, Gt = (e) => {
497
+ }, na = (e) => {
425
498
  for (let t = e.messages.length - 1; t >= 0; t -= 1)
426
499
  if (e.messages[t].role === "user") return t;
427
500
  return -1;
428
- }, Xe = (e) => {
429
- const t = Gt(e);
501
+ }, st = (e) => {
502
+ const t = na(e);
430
503
  if (!(t < 0))
431
504
  for (let s = e.messages.length - 1; s > t; s -= 1) {
432
- const n = e.messages[s];
433
- if (n.role === "assistant") return n.id;
505
+ const i = e.messages[s];
506
+ if (i.role === "assistant") return i.id;
434
507
  }
435
- }, Yt = (e) => {
508
+ }, ra = (e) => {
436
509
  if (e.status === "idle")
437
510
  for (let t = e.messages.length - 1; t >= 0; t -= 1) {
438
511
  const s = e.messages[t];
439
512
  if (s.role === "assistant" && s.status === "complete")
440
513
  return s.id;
441
514
  }
442
- }, Wt = (e) => {
515
+ }, ia = (e) => {
443
516
  for (let t = e.messages.length - 1; t >= 0; t -= 1) {
444
517
  const s = e.messages[t];
445
518
  if (s.role === "user") return s;
446
519
  }
447
- }, Jt = (e, t) => {
520
+ }, oa = (e, t) => {
448
521
  const s = e.messages.findIndex(
449
- (n) => n.id === t && n.role === "user"
522
+ (i) => i.id === t && i.role === "user"
450
523
  );
451
524
  return {
452
525
  ...e,
@@ -455,57 +528,108 @@ const Ke = (e) => {
455
528
  status: "streaming",
456
529
  messages: s < 0 ? e.messages : e.messages.slice(0, s + 1)
457
530
  };
458
- }, Qt = (e) => e.scrollHeight - e.scrollTop - e.clientHeight <= 48, ze = (e = "smooth") => globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : e, be = (e, t) => {
531
+ }, ca = (e) => e.scrollHeight - e.scrollTop - e.clientHeight <= 48, Ze = (e = "smooth") => globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : e, Ne = (e, t) => {
459
532
  typeof e.scrollTo == "function" ? e.scrollTo({ top: e.scrollHeight, behavior: t }) : e.scrollTop = e.scrollHeight;
460
- }, et = ({
533
+ }, nt = ({
461
534
  error: e,
462
535
  onRetry: t
463
- }) => /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-status make-ai-assistant__message-status--error", role: "alert", children: [
464
- /* @__PURE__ */ a("strong", { children: "本次请求未完成" }),
465
- /* @__PURE__ */ a("span", { children: e.message }),
466
- e.retryable && t ? /* @__PURE__ */ a(
467
- "button",
536
+ }) => /* @__PURE__ */ r(
537
+ "div",
538
+ {
539
+ className: "make-ai-assistant__message-status make-ai-assistant__message-status--error",
540
+ "data-error-presentation": "request-failed",
541
+ role: "alert",
542
+ children: [
543
+ /* @__PURE__ */ r("div", { className: "make-ai-assistant__message-status-header", children: [
544
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-status-icon", "aria-hidden": "true", children: /* @__PURE__ */ a(Jt, {}) }),
545
+ /* @__PURE__ */ a("strong", { children: "请求未完成" })
546
+ ] }),
547
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-status-message", children: e.message }),
548
+ e.retryable && t ? /* @__PURE__ */ r(
549
+ "button",
550
+ {
551
+ className: "make-ai-assistant__retry",
552
+ type: "button",
553
+ onClick: t,
554
+ children: [
555
+ /* @__PURE__ */ a(et, {}),
556
+ "重新发送"
557
+ ]
558
+ }
559
+ ) : null
560
+ ]
561
+ }
562
+ ), la = ({
563
+ error: e,
564
+ onRetry: t
565
+ }) => {
566
+ const s = Ut(e);
567
+ return /* @__PURE__ */ r(
568
+ "section",
468
569
  {
469
- className: "make-ai-assistant__retry",
470
- type: "button",
471
- onClick: t,
472
- children: "重新发送"
570
+ "aria-live": "assertive",
571
+ className: "make-ai-assistant__load-failure",
572
+ "data-load-failure-kind": s.kind,
573
+ role: "alert",
574
+ children: [
575
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__load-failure-icon", "aria-hidden": "true", children: /* @__PURE__ */ r("svg", { viewBox: "0 0 24 24", children: [
576
+ /* @__PURE__ */ a("path", { d: "M5 12a7 7 0 0 1 13.4-2.8A4.5 4.5 0 0 1 18 18H7.5A4.5 4.5 0 0 1 5 12Z" }),
577
+ /* @__PURE__ */ a("path", { d: "m9.2 14.8 5.6-5.6M9.2 9.2l5.6 5.6" })
578
+ ] }) }),
579
+ /* @__PURE__ */ r("div", { className: "make-ai-assistant__load-failure-copy", children: [
580
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__load-failure-label", children: s.label }),
581
+ /* @__PURE__ */ a("h3", { children: s.title }),
582
+ /* @__PURE__ */ a("p", { children: s.description })
583
+ ] }),
584
+ /* @__PURE__ */ r(
585
+ "button",
586
+ {
587
+ className: "make-ai-assistant__retry make-ai-assistant__retry--primary",
588
+ type: "button",
589
+ onClick: t,
590
+ children: [
591
+ /* @__PURE__ */ a(et, {}),
592
+ s.actionLabel
593
+ ]
594
+ }
595
+ )
596
+ ]
473
597
  }
474
- ) : null
475
- ] }), tt = ({
598
+ );
599
+ }, rt = ({
476
600
  active: e,
477
601
  steps: t
478
602
  }) => {
479
- if (!t?.length) return null;
603
+ if (!e || !t?.length) return null;
480
604
  const s = t[t.length - 1] ?? "处理中";
481
- return /* @__PURE__ */ i("details", { className: "make-ai-assistant__process", open: e, children: [
482
- /* @__PURE__ */ i("summary", { children: [
483
- e ? /* @__PURE__ */ i("span", { className: "make-ai-assistant__progress", role: "status", children: [
605
+ return /* @__PURE__ */ r("details", { className: "make-ai-assistant__process", open: !0, children: [
606
+ /* @__PURE__ */ r("summary", { children: [
607
+ /* @__PURE__ */ r("span", { className: "make-ai-assistant__progress", role: "status", children: [
484
608
  /* @__PURE__ */ a("span", { "aria-hidden": "true" }),
485
609
  /* @__PURE__ */ a("span", { children: s })
486
- ] }) : /* @__PURE__ */ a("span", { className: "make-ai-assistant__process-title", children: "处理过程" }),
487
- /* @__PURE__ */ i("span", { className: "make-ai-assistant__process-count", children: [
610
+ ] }),
611
+ /* @__PURE__ */ r("span", { className: "make-ai-assistant__process-count", children: [
488
612
  t.length,
489
613
  " 步"
490
614
  ] })
491
615
  ] }),
492
- /* @__PURE__ */ a("ol", { children: t.map((n, r) => /* @__PURE__ */ i(
616
+ /* @__PURE__ */ a("ol", { children: t.map((i, n) => /* @__PURE__ */ r(
493
617
  "li",
494
618
  {
495
- "data-step-active": e && r === t.length - 1 ? !0 : void 0,
619
+ "data-step-active": n === t.length - 1 ? !0 : void 0,
496
620
  children: [
497
621
  /* @__PURE__ */ a("span", { "aria-hidden": "true" }),
498
- /* @__PURE__ */ a("span", { children: n })
622
+ /* @__PURE__ */ a("span", { children: i })
499
623
  ]
500
624
  },
501
- `${r}-${n}`
625
+ `${n}-${i}`
502
626
  )) })
503
627
  ] });
504
- }, Xt = ({
628
+ }, da = ({
505
629
  copyFeedback: e,
506
630
  onCopy: t,
507
631
  onRegenerate: s
508
- }) => !t && !s ? null : /* @__PURE__ */ i("div", { className: "make-ai-assistant__reply-actions", "aria-label": "回复操作", children: [
632
+ }) => !t && !s ? null : /* @__PURE__ */ r("div", { className: "make-ai-assistant__reply-actions", "aria-label": "回复操作", children: [
509
633
  t ? /* @__PURE__ */ a(
510
634
  "button",
511
635
  {
@@ -514,7 +638,7 @@ const Ke = (e) => {
514
638
  "data-tooltip": "复制",
515
639
  type: "button",
516
640
  onClick: t,
517
- children: /* @__PURE__ */ a(Dt, {})
641
+ children: /* @__PURE__ */ a(Ot, {})
518
642
  }
519
643
  ) : null,
520
644
  s ? /* @__PURE__ */ a(
@@ -525,7 +649,7 @@ const Ke = (e) => {
525
649
  "data-tooltip": "重新生成",
526
650
  type: "button",
527
651
  onClick: s,
528
- children: /* @__PURE__ */ a(Vt, {})
652
+ children: /* @__PURE__ */ a(jt, {})
529
653
  }
530
654
  ) : null,
531
655
  e ? /* @__PURE__ */ a(
@@ -537,476 +661,469 @@ const Ke = (e) => {
537
661
  children: e.message
538
662
  }
539
663
  ) : null
540
- ] }), Oe = ({
664
+ ] }), Ge = ({
541
665
  assistantName: e,
542
666
  error: t,
543
667
  onRetry: s,
544
- progress: n
668
+ progress: i
545
669
  }) => {
546
- const r = t ? "error" : "progress";
547
- return t?.message ?? n?.message ? /* @__PURE__ */ a(
670
+ const n = t ? "error" : "progress";
671
+ return t?.message ?? i?.message ? /* @__PURE__ */ a(
548
672
  "article",
549
673
  {
550
- "aria-label": `${e}的${r === "error" ? "错误消息" : "状态消息"}`,
551
- className: `make-ai-assistant__message make-ai-assistant__message--assistant make-ai-assistant__message--${r}`,
674
+ "aria-label": `${e}的${n === "error" ? "错误消息" : "状态消息"}`,
675
+ className: `make-ai-assistant__message make-ai-assistant__message--assistant make-ai-assistant__message--${n}`,
552
676
  "data-message-role": "assistant",
553
- "data-message-state": r,
554
- children: /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-turn", children: [
555
- /* @__PURE__ */ a(Je, { assistantName: e }),
556
- /* @__PURE__ */ a("div", { className: "make-ai-assistant__message-stack", children: t ? /* @__PURE__ */ a(et, { error: t, onRetry: s }) : /* @__PURE__ */ a(tt, { active: !0, steps: n?.steps }) })
677
+ "data-message-state": n,
678
+ children: /* @__PURE__ */ r("div", { className: "make-ai-assistant__message-turn", children: [
679
+ /* @__PURE__ */ a(tt, { assistantName: e }),
680
+ /* @__PURE__ */ a("div", { className: "make-ai-assistant__message-stack", children: t ? /* @__PURE__ */ a(nt, { error: t, onRetry: s }) : /* @__PURE__ */ a(rt, { active: !0, steps: i?.steps }) })
557
681
  ] })
558
682
  }
559
683
  ) : null;
560
- }, ea = (e, t, s, n, r, o, d, p, f, b, C, $, m) => {
561
- const B = Xe(e), z = Qe(e), k = Yt(e);
562
- let D;
563
- return e.messages.map((u) => {
564
- const I = u.role === "assistant", V = D;
565
- I || (D = u);
566
- const _ = u.id === z, M = u.id === B ? e.error : void 0, E = u.error ?? M, q = !I && !!(p?.trim() || f), U = I ? o : p?.trim() || "用户", ve = I && u.status === "complete" && !E && (u.content.trim() || u.id === k);
684
+ }, ma = (e, t, s, i, n, o, l, m, k, p, M, T, u) => {
685
+ const $ = st(e), R = at(e), y = ra(e);
686
+ let q;
687
+ return e.messages.map((h) => {
688
+ const I = h.role === "assistant", V = q;
689
+ I || (q = h);
690
+ const _ = h.id === R, C = h.id === $ ? e.error : void 0, S = h.error ?? C, H = !I && !!(m?.trim() || k), U = I ? o : m?.trim() || "用户", ye = I && h.status === "complete" && !S && (h.content.trim() || h.id === y);
567
691
  return /* @__PURE__ */ a(
568
692
  "article",
569
693
  {
570
694
  "aria-label": `${U}的消息`,
571
- className: `make-ai-assistant__message make-ai-assistant__message--${u.role}`,
572
- "data-message-role": u.role,
573
- "data-message-state": E ? "error" : void 0,
574
- "data-message-status": u.status,
575
- "data-message-has-identity": I || q ? !0 : void 0,
576
- children: /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-turn", children: [
577
- I ? /* @__PURE__ */ a(Je, { assistantName: o }) : q ? /* @__PURE__ */ a(Ot, { userAvatarUrl: f, userName: p }) : null,
578
- /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-stack", children: [
579
- u.content ? I ? /* @__PURE__ */ a(Zt, { content: u.content }) : /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble", children: u.content }) : u.status === "streaming" ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__typing", "aria-label": `${o}正在思考`, children: [
695
+ className: `make-ai-assistant__message make-ai-assistant__message--${h.role}`,
696
+ "data-message-role": h.role,
697
+ "data-message-state": S ? "error" : void 0,
698
+ "data-message-status": h.status,
699
+ "data-message-has-identity": I || H ? !0 : void 0,
700
+ children: /* @__PURE__ */ r("div", { className: "make-ai-assistant__message-turn", children: [
701
+ I ? /* @__PURE__ */ a(tt, { assistantName: o }) : H ? /* @__PURE__ */ a(Xt, { userAvatarUrl: k, userName: m }) : null,
702
+ /* @__PURE__ */ r("div", { className: "make-ai-assistant__message-stack", children: [
703
+ h.content ? I ? /* @__PURE__ */ a(sa, { content: h.content }) : /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble", children: h.content }) : h.status === "streaming" ? /* @__PURE__ */ r("div", { className: "make-ai-assistant__typing", "aria-label": `${o}正在思考`, children: [
580
704
  /* @__PURE__ */ a("span", {}),
581
705
  /* @__PURE__ */ a("span", {}),
582
706
  /* @__PURE__ */ a("span", {})
583
707
  ] }) : null,
584
708
  I ? /* @__PURE__ */ a(
585
- tt,
709
+ rt,
586
710
  {
587
711
  active: _ && e.status === "streaming",
588
- steps: u.progressSteps
712
+ steps: h.progressSteps
589
713
  }
590
714
  ) : null,
591
- E ? /* @__PURE__ */ a(
592
- et,
715
+ S ? /* @__PURE__ */ a(
716
+ nt,
593
717
  {
594
- error: E,
595
- onRetry: M ? d : void 0
718
+ error: S,
719
+ onRetry: C ? l : void 0
596
720
  }
597
721
  ) : null,
598
- u.artifacts.map((x) => /* @__PURE__ */ a(
599
- At,
722
+ h.artifacts.map((F) => /* @__PURE__ */ a(
723
+ Mt,
600
724
  {
601
- artifact: x,
725
+ artifact: F,
602
726
  context: t,
603
- onAction: n,
604
- onActionError: r,
727
+ onAction: i,
728
+ onActionError: n,
605
729
  registry: s
606
730
  },
607
- x.id
731
+ F.id
608
732
  )),
609
- ve ? /* @__PURE__ */ a(
610
- Xt,
733
+ ye ? /* @__PURE__ */ a(
734
+ da,
611
735
  {
612
- copyFeedback: b?.messageId === u.id ? {
613
- message: b.message,
614
- status: b.status
736
+ copyFeedback: p?.messageId === h.id ? {
737
+ message: p.message,
738
+ status: p.status
615
739
  } : void 0,
616
- onCopy: u.content.trim() ? () => $(u.id, u.content) : void 0,
617
- onRegenerate: C && u.id === k && V ? () => m({
740
+ onCopy: h.content.trim() ? () => T(h.id, h.content) : void 0,
741
+ onRegenerate: M && h.id === y && V ? () => u({
618
742
  userMessage: V,
619
- assistantMessage: u
743
+ assistantMessage: h
620
744
  }) : void 0
621
745
  }
622
746
  ) : null
623
747
  ] })
624
748
  ] })
625
749
  },
626
- u.id
750
+ h.id
627
751
  );
628
752
  });
629
753
  };
630
- function at({
754
+ function it({
631
755
  assistantName: e = "AI 助手",
632
756
  brandName: t,
633
757
  context: s,
634
- onAction: n,
635
- onActionError: r,
758
+ onAction: i,
759
+ onActionError: n,
636
760
  onClose: o,
637
- onNewConversation: d,
638
- privacyNotice: p,
639
- registry: f,
640
- subtitle: b,
641
- suggestions: C,
642
- title: $,
643
- transport: m,
644
- userAvatarUrl: B,
645
- userName: z,
646
- visible: k
761
+ onNewConversation: l,
762
+ privacyNotice: m,
763
+ registry: k,
764
+ subtitle: p,
765
+ suggestions: M,
766
+ title: T,
767
+ transport: u,
768
+ userAvatarUrl: $,
769
+ userName: R,
770
+ visible: y
647
771
  }) {
648
- const D = Ye(t, $), u = p?.trim(), [I, V] = R(""), [_, M] = R(ge), E = w(_);
649
- E.current = _;
650
- const [q, U] = R(void 0), [ve, x] = R(void 0), [st, nt] = R(0), [O, oe] = R(() => m.loadConversation ? "loading" : "ready"), [rt, L] = R(!1), j = w(void 0), Z = w(void 0), G = w(0), Ie = w(null), te = w(null), Ne = w(null), we = w(null), F = w(!0), Me = w(s.app.id), Te = w(k), Ce = He(
651
- () => f ?? St(),
652
- [f]
653
- ), $e = He(
654
- () => Ft(C),
655
- [C]
772
+ const q = Qe(t, T), h = m?.trim(), [I, V] = x(""), [_, C] = x(fe), S = N(_);
773
+ S.current = _;
774
+ const [H, U] = x(void 0), [ye, F] = x(void 0), [ot, ct] = x(0), [O, oe] = x(() => u.loadConversation ? "loading" : "ready"), [lt, be] = x(void 0), [dt, P] = x(!1), j = N(void 0), Z = N(void 0), G = N(0), Me = N(null), te = N(null), Te = N(null), $e = N(null), B = N(!0), Ce = N(s.app.id), Ee = N(y), Se = Oe(
775
+ () => k ?? Pt(),
776
+ [k]
777
+ ), xe = Oe(
778
+ () => Vt(M),
779
+ [M]
656
780
  ), ce = (c) => {
657
- const h = j.current, g = Z.current?.iterator;
658
- return !h && !g ? !1 : (G.current += 1, j.current = void 0, Z.current = void 0, console.info("[make-ai-assistant] local run cancellation requested", { reason: c }), h?.abort(), Ke(g), !0);
781
+ const f = j.current, g = Z.current?.iterator;
782
+ return !f && !g ? !1 : (G.current += 1, j.current = void 0, Z.current = void 0, console.info("[make-ai-assistant] local run cancellation requested", { reason: c }), f?.abort(), je(g), !0);
659
783
  };
660
784
  Q(() => () => {
661
785
  ce("unmount");
662
786
  }, []), Q(() => {
663
- const c = m.loadConversation, h = Me.current !== s.app.id;
664
- if (Me.current = s.app.id, ce("reinitialize"), h && (V(""), F.current = !0), U(void 0), x(void 0), L(!1), M(ge()), !c) {
665
- oe("ready");
787
+ const c = u.loadConversation, f = Ce.current !== s.app.id;
788
+ if (Ce.current = s.app.id, ce("reinitialize"), f && (V(""), B.current = !0), U(void 0), F(void 0), P(!1), C(fe()), !c) {
789
+ be(void 0), oe("ready");
666
790
  return;
667
791
  }
668
792
  const g = new AbortController();
669
- return oe("loading"), console.info("[make-ai-assistant] conversation load start", {
793
+ return be(void 0), oe("loading"), console.info("[make-ai-assistant] conversation load start", {
670
794
  appId: s.app.id
671
- }), c.call(m, s, { signal: g.signal }).then((y) => {
672
- g.signal.aborted || (M(ge(y)), oe("ready"), console.info("[make-ai-assistant] conversation load success", {
795
+ }), c.call(u, s, { signal: g.signal }).then((b) => {
796
+ g.signal.aborted || (C(fe(b)), oe("ready"), console.info("[make-ai-assistant] conversation load success", {
673
797
  appId: s.app.id,
674
- messageCount: y.messages.length
798
+ messageCount: b.messages.length
675
799
  }));
676
- }).catch((y) => {
800
+ }).catch((b) => {
677
801
  g.signal.aborted || (console.error("[make-ai-assistant] conversation load failed", {
678
802
  appId: s.app.id,
679
- errorType: y instanceof Error ? y.name : typeof y
680
- }), oe("error"));
803
+ errorType: b instanceof Error ? b.name : typeof b
804
+ }), be(b), oe("error"));
681
805
  }), () => g.abort();
682
- }, [s.app.id, st, m]), Q(() => {
806
+ }, [s.app.id, ot, u]), Q(() => {
683
807
  const c = te.current;
684
- if (!c || !F.current) return;
685
- L(!1);
686
- const h = requestAnimationFrame(() => {
687
- if (!F.current) return;
808
+ if (!c || !B.current) return;
809
+ P(!1);
810
+ const f = requestAnimationFrame(() => {
811
+ if (!B.current) return;
688
812
  const g = _.status === "streaming" || globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
689
- be(c, g);
813
+ Ne(c, g);
690
814
  });
691
- return () => cancelAnimationFrame(h);
815
+ return () => cancelAnimationFrame(f);
692
816
  }, [_.messages, _.progress, _.status]), Q(() => {
693
- const c = k && !Te.current;
694
- if (Te.current = k, !c) return;
695
- const h = requestAnimationFrame(() => {
817
+ const c = y && !Ee.current;
818
+ if (Ee.current = y, !c) return;
819
+ const f = requestAnimationFrame(() => {
696
820
  const g = te.current;
697
- if (g && F.current) {
698
- L(!1);
699
- const ae = E.current.status === "streaming" ? "auto" : ze();
700
- be(g, ae);
701
- } else g && L(E.current.messages.length > 0);
702
- const y = Ne.current;
703
- (y && !y.disabled ? y : we.current ?? Ie.current?.querySelector("button:not(:disabled)"))?.focus();
821
+ if (g && B.current) {
822
+ P(!1);
823
+ const ae = S.current.status === "streaming" ? "auto" : Ze();
824
+ Ne(g, ae);
825
+ } else g && P(S.current.messages.length > 0);
826
+ const b = Te.current;
827
+ (b && !b.disabled ? b : $e.current ?? Me.current?.querySelector("button:not(:disabled)"))?.focus();
704
828
  });
705
- return () => cancelAnimationFrame(h);
706
- }, [k]);
707
- const it = () => {
829
+ return () => cancelAnimationFrame(f);
830
+ }, [y]);
831
+ const mt = () => {
708
832
  const c = te.current;
709
833
  if (!c) return;
710
- const h = Qt(c);
711
- F.current = h, L(!h && E.current.messages.length > 0);
712
- }, ot = () => {
834
+ const f = ca(c);
835
+ B.current = f, P(!f && S.current.messages.length > 0);
836
+ }, ut = () => {
713
837
  const c = te.current;
714
838
  if (!c) return;
715
- F.current = !0, L(!1);
716
- const h = ze();
717
- be(c, h);
718
- }, Ee = async (c, h) => {
719
- const g = c.trim(), y = E.current, S = h?.regenerateFrom, ae = m.regenerate;
720
- if (!g || O !== "ready" || y.status === "streaming" || j.current || S && !ae) return;
839
+ B.current = !0, P(!1);
840
+ const f = Ze();
841
+ Ne(c, f);
842
+ }, Re = async (c, f) => {
843
+ const g = c.trim(), b = S.current, L = f?.regenerateFrom, ae = u.regenerate;
844
+ if (!g || O !== "ready" || b.status === "streaming" || j.current || L && !ae) return;
721
845
  if (_e(
722
846
  g,
723
- N.messageCharacters
724
- ) > N.messageCharacters) {
847
+ w.messageCharacters
848
+ ) > w.messageCharacters) {
725
849
  U(
726
- `输入内容过长,请控制在 ${N.messageCharacters} 个字符以内`
850
+ `输入内容过长,请控制在 ${w.messageCharacters} 个字符以内`
727
851
  );
728
852
  return;
729
853
  }
730
854
  const me = {
731
- id: S?.userMessage.id ?? Rt("user"),
855
+ id: L?.userMessage.id ?? Bt("user"),
732
856
  content: g
733
- }, ue = S ? Jt(y, S.userMessage.id) : yt(y, me), pe = new AbortController(), Y = G.current + 1;
734
- G.current = Y, j.current = pe, U(void 0), x(void 0), L(!F.current && y.messages.length > 0), S || V(""), M(ue);
857
+ }, ue = L ? oa(b, L.userMessage.id) : wt(b, me), he = new AbortController(), W = G.current + 1;
858
+ G.current = W, j.current = he, U(void 0), F(void 0), P(!B.current && b.messages.length > 0), L || V(""), C(ue);
735
859
  try {
736
- let P = !1, A, xe = 0, Le = 0, Fe = 0, ye = 0, se = 0;
737
- const ne = /* @__PURE__ */ new Map(), Pe = /* @__PURE__ */ new Set(), Be = /* @__PURE__ */ new Set(
860
+ let D = !1, A, Pe = 0, Be = 0, De = 0, Ae = 0, se = 0;
861
+ const ne = /* @__PURE__ */ new Map(), qe = /* @__PURE__ */ new Set(), Ve = /* @__PURE__ */ new Set(
738
862
  [
739
- ...ue.messages.map((he) => he.id),
863
+ ...ue.messages.map((pe) => pe.id),
740
864
  me.id
741
865
  ]
742
- ), re = /* @__PURE__ */ new Set(), De = vt(Ce), Ve = { signal: pe.signal };
743
- let ke;
744
- if (S) {
866
+ ), re = /* @__PURE__ */ new Set(), He = It(Se), Ue = { signal: he.signal };
867
+ let Ie;
868
+ if (L) {
745
869
  if (!ae)
746
870
  throw new v("当前 AI 助手不支持重新生成");
747
- ke = ae({
871
+ Ie = ae({
748
872
  threadId: ue.threadId,
749
873
  message: me,
750
874
  assistantMessage: {
751
- id: S.assistantMessage.id,
752
- content: S.assistantMessage.content
875
+ id: L.assistantMessage.id,
876
+ content: L.assistantMessage.content
753
877
  },
754
878
  context: s,
755
- capabilities: De
756
- }, Ve);
879
+ capabilities: He
880
+ }, Ue);
757
881
  } else
758
- ke = m.run(
882
+ Ie = u.run(
759
883
  {
760
884
  threadId: ue.threadId,
761
885
  message: me,
762
886
  context: s,
763
- capabilities: De
887
+ capabilities: He
764
888
  },
765
- Ve
889
+ Ue
766
890
  );
767
- const qe = ke[Symbol.asyncIterator]();
768
- for (Z.current = { iterator: qe, requestVersion: Y }; ; ) {
769
- const he = await qe.next();
770
- if (G.current !== Y || he.done) break;
771
- let l;
891
+ const Ke = Ie[Symbol.asyncIterator]();
892
+ for (Z.current = { iterator: Ke, requestVersion: W }; ; ) {
893
+ const pe = await Ke.next();
894
+ if (G.current !== W || pe.done) break;
895
+ let d;
772
896
  try {
773
- l = kt(he.value);
774
- } catch (T) {
897
+ d = Nt(pe.value);
898
+ } catch (E) {
775
899
  throw new v(
776
- T instanceof Error ? T.message : "Invalid assistant event"
900
+ E instanceof Error ? E.message : "Invalid assistant event"
777
901
  );
778
902
  }
779
- if (l.type === "message.start") {
780
- if (A !== void 0 && A !== l.runId)
903
+ if (d.type === "message.start") {
904
+ if (A !== void 0 && A !== d.runId)
781
905
  throw new v("AI 助手响应 run id 不一致");
782
- if (A ??= l.runId, Le += 1, Le > N.assistantMessagesPerRun)
906
+ if (A ??= d.runId, Be += 1, Be > w.assistantMessagesPerRun)
783
907
  throw new v("AI 助手单次响应消息数量超过限制");
784
- if (Be.has(l.messageId))
908
+ if (Ve.has(d.messageId))
785
909
  throw new v("AI 助手响应包含重复的 message id");
786
- Be.add(l.messageId), re.add(l.messageId), ne.set(l.messageId, 0);
910
+ Ve.add(d.messageId), re.add(d.messageId), ne.set(d.messageId, 0);
787
911
  }
788
- if (l.type === "message.delta") {
789
- if (!re.has(l.messageId))
912
+ if (d.type === "message.delta") {
913
+ if (!re.has(d.messageId))
790
914
  throw new v("AI 助手响应事件顺序无效");
791
- const T = ne.get(l.messageId) ?? 0, W = _e(
792
- l.delta,
793
- N.messageCharacters - se
915
+ const E = ne.get(d.messageId) ?? 0, Y = _e(
916
+ d.delta,
917
+ w.messageCharacters - se
794
918
  );
795
- if (se + W > N.messageCharacters)
919
+ if (se + Y > w.messageCharacters)
796
920
  throw new v("AI 助手响应文本超过大小限制");
797
- se += W, ne.set(
798
- l.messageId,
799
- T + W
921
+ se += Y, ne.set(
922
+ d.messageId,
923
+ E + Y
800
924
  );
801
925
  }
802
- if (l.type === "message.replace") {
803
- if (!re.has(l.messageId))
926
+ if (d.type === "message.replace") {
927
+ if (!re.has(d.messageId))
804
928
  throw new v("AI 助手响应事件顺序无效");
805
- const T = ne.get(l.messageId) ?? 0, W = _e(
806
- l.content,
807
- N.messageCharacters
808
- ), Ue = se - T + W;
809
- if (Ue > N.messageCharacters)
929
+ const E = ne.get(d.messageId) ?? 0, Y = _e(
930
+ d.content,
931
+ w.messageCharacters
932
+ ), ze = se - E + Y;
933
+ if (ze > w.messageCharacters)
810
934
  throw new v("AI 助手响应文本超过大小限制");
811
- se = Ue, ne.set(l.messageId, W);
935
+ se = ze, ne.set(d.messageId, Y);
812
936
  }
813
- if (l.type === "run.progress") {
814
- if (A !== void 0 && A !== l.runId)
937
+ if (d.type === "run.progress") {
938
+ if (A !== void 0 && A !== d.runId)
815
939
  throw new v("AI 助手响应 run id 不一致");
816
- if (A ??= l.runId, Fe += 1, Fe > N.progressStepsPerRun)
940
+ if (A ??= d.runId, De += 1, De > w.progressStepsPerRun)
817
941
  throw new v("AI 助手处理过程数量超过限制");
818
- const T = _e(
819
- l.message,
820
- N.progressCharactersPerRun - ye
942
+ const E = _e(
943
+ d.message,
944
+ w.progressCharactersPerRun - Ae
821
945
  );
822
- if (ye + T > N.progressCharactersPerRun)
946
+ if (Ae + E > w.progressCharactersPerRun)
823
947
  throw new v("AI 助手处理过程文本超过大小限制");
824
- ye += T;
948
+ Ae += E;
825
949
  }
826
- if (l.type === "artifact") {
827
- if (!re.has(l.messageId))
950
+ if (d.type === "artifact") {
951
+ if (!re.has(d.messageId))
828
952
  throw new v("AI 助手响应事件顺序无效");
829
- if (xe += 1, xe > N.artifactsPerRun)
953
+ if (Pe += 1, Pe > w.artifactsPerRun)
830
954
  throw new v("AI 助手单次响应 Artifact 数量超过限制");
831
- if (Pe.has(l.artifact.id))
955
+ if (qe.has(d.artifact.id))
832
956
  throw new v("AI 助手响应包含重复的 Artifact id");
833
- Pe.add(l.artifact.id);
957
+ qe.add(d.artifact.id);
834
958
  }
835
- if (l.type === "message.complete" && !re.delete(l.messageId))
959
+ if (d.type === "message.complete" && !re.delete(d.messageId))
836
960
  throw new v("AI 助手响应事件顺序无效");
837
- if (l.type === "run.complete" && A !== void 0 && A !== l.runId)
961
+ if (d.type === "run.complete" && A !== void 0 && A !== d.runId)
838
962
  throw new v("AI 助手响应 run id 不一致");
839
- if (l.type === "run.cancelled" && l.runId !== void 0 && A !== void 0 && A !== l.runId)
963
+ if (d.type === "run.cancelled" && d.runId !== void 0 && A !== void 0 && A !== d.runId)
840
964
  throw new v("AI 助手响应 run id 不一致");
841
- if (M((T) => fe(T, l)), l.type === "error" || l.type === "run.cancelled" || l.type === "run.complete") {
842
- P = !0;
965
+ if (C((E) => ge(E, d)), d.type === "error" || d.type === "run.cancelled" || d.type === "run.complete") {
966
+ D = !0;
843
967
  break;
844
968
  }
845
969
  }
846
- if (!P)
970
+ if (!D)
847
971
  throw new v("AI 助手流式响应在终止事件前结束");
848
- } catch (P) {
849
- if (G.current !== Y) return;
850
- if (pe.signal.aborted) {
851
- M(
852
- (A) => fe(A, { type: "run.cancelled" })
972
+ } catch (D) {
973
+ if (G.current !== W) return;
974
+ if (he.signal.aborted) {
975
+ C(
976
+ (A) => ge(A, { type: "run.cancelled" })
853
977
  );
854
978
  return;
855
979
  }
856
980
  console.error("[make-ai-assistant] assistant run failed", {
857
981
  appId: s.app.id,
858
- errorType: P instanceof Error ? P.name : typeof P
859
- }), M(
860
- (A) => fe(A, {
982
+ errorType: D instanceof Error ? D.name : typeof D
983
+ }), C(
984
+ (A) => ge(A, {
861
985
  type: "error",
862
986
  code: "TRANSPORT_ERROR",
863
- message: P instanceof v ? P.message : "连接失败,请重试",
987
+ message: D instanceof v ? D.message : "连接失败,请重试",
864
988
  retryable: !0
865
989
  })
866
990
  );
867
991
  } finally {
868
- G.current === Y && j.current === pe && (j.current = void 0), Z.current?.requestVersion === Y && (Ke(Z.current.iterator), Z.current = void 0);
992
+ G.current === W && j.current === he && (j.current = void 0), Z.current?.requestVersion === W && (je(Z.current.iterator), Z.current = void 0);
869
993
  }
870
- }, le = (c) => Ee(c), ct = (c) => Ee(c.userMessage.content, { regenerateFrom: c }), lt = async (c, h) => {
994
+ }, le = (c) => Re(c), ht = (c) => Re(c.userMessage.content, { regenerateFrom: c }), pt = async (c, f) => {
871
995
  try {
872
- await Pt(h), x({ messageId: c, message: "已复制", status: "success" });
996
+ await Kt(f), F({ messageId: c, message: "已复制", status: "success" });
873
997
  } catch (g) {
874
998
  console.error("[make-ai-assistant] copy answer failed", {
875
999
  errorType: g instanceof Error ? g.name : typeof g
876
- }), x({ messageId: c, message: "复制失败", status: "error" });
1000
+ }), F({ messageId: c, message: "复制失败", status: "error" });
877
1001
  }
878
- }, dt = (c) => {
1002
+ }, ft = (c) => {
879
1003
  c.preventDefault(), le(I);
880
- }, mt = (c) => {
1004
+ }, gt = (c) => {
881
1005
  c.key === "Enter" && !c.shiftKey && !c.nativeEvent.isComposing && (c.preventDefault(), le(I));
882
- }, ut = () => {
883
- ce("stop") && M(
884
- (c) => fe(c, { type: "run.cancelled" })
1006
+ }, _t = () => {
1007
+ ce("stop") && C(
1008
+ (c) => ge(c, { type: "run.cancelled" })
885
1009
  );
886
- }, pt = () => {
887
- ce("new-conversation"), V(""), U(void 0), x(void 0), L(!1), F.current = !0, M(ge()), d?.();
888
- }, Se = m.features?.remoteCancellation === !1 ? "停止接收" : "停止生成", ht = Qe(_), gt = Xe(_), de = Wt(_), ft = typeof m.regenerate == "function" && m.features?.regeneration !== !1, Re = () => {
1010
+ }, vt = () => {
1011
+ ce("new-conversation"), V(""), U(void 0), F(void 0), P(!1), B.current = !0, C(fe()), l?.();
1012
+ }, Le = u.features?.remoteCancellation === !1 ? "停止接收" : "停止生成", kt = at(_), yt = st(_), de = ia(_), bt = typeof u.regenerate == "function" && u.features?.regeneration !== !1, Fe = () => {
889
1013
  de && le(de.content);
890
1014
  };
891
- return /* @__PURE__ */ i(
1015
+ return /* @__PURE__ */ r(
892
1016
  "section",
893
1017
  {
894
1018
  className: "make-ai-assistant make-ai-assistant__panel",
895
- ref: Ie,
1019
+ ref: Me,
896
1020
  children: [
897
- /* @__PURE__ */ i("header", { className: "make-ai-assistant__header", children: [
898
- /* @__PURE__ */ a(ie, {}),
899
- /* @__PURE__ */ i("div", { children: [
900
- /* @__PURE__ */ a("h2", { children: D }),
901
- /* @__PURE__ */ a("p", { children: b ?? `当前应用:${s.app.name ?? "未命名应用"}` })
1021
+ /* @__PURE__ */ r("header", { className: "make-ai-assistant__header", children: [
1022
+ /* @__PURE__ */ a(ke, {}),
1023
+ /* @__PURE__ */ r("div", { children: [
1024
+ /* @__PURE__ */ a("h2", { children: q }),
1025
+ /* @__PURE__ */ a("p", { children: p ?? `当前应用:${s.app.name ?? "未命名应用"}` })
902
1026
  ] }),
903
- /* @__PURE__ */ i("div", { className: "make-ai-assistant__header-actions", children: [
904
- m.features?.newConversation !== !1 ? /* @__PURE__ */ a(
1027
+ /* @__PURE__ */ r("div", { className: "make-ai-assistant__header-actions", children: [
1028
+ u.features?.newConversation !== !1 ? /* @__PURE__ */ a(
905
1029
  "button",
906
1030
  {
907
1031
  "aria-label": "新建对话",
908
1032
  className: "make-ai-assistant__icon-button",
909
1033
  type: "button",
910
- onClick: pt,
911
- children: /* @__PURE__ */ a(Ht, {})
1034
+ onClick: vt,
1035
+ children: /* @__PURE__ */ a(Wt, {})
912
1036
  }
913
1037
  ) : null,
914
1038
  o ? /* @__PURE__ */ a(
915
1039
  "button",
916
1040
  {
917
- "aria-label": `关闭 ${D}`,
1041
+ "aria-label": `关闭 ${q}`,
918
1042
  className: "make-ai-assistant__icon-button",
919
1043
  type: "button",
920
1044
  onClick: o,
921
- children: /* @__PURE__ */ a(Bt, {})
1045
+ children: /* @__PURE__ */ a(zt, {})
922
1046
  }
923
1047
  ) : null
924
1048
  ] })
925
1049
  ] }),
926
- u ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__privacy-note", role: "note", children: [
927
- /* @__PURE__ */ a("span", { className: "make-ai-assistant__privacy-icon", "aria-hidden": "true", children: /* @__PURE__ */ a(qt, {}) }),
928
- /* @__PURE__ */ a("span", { children: u })
929
- ] }) : null,
930
- /* @__PURE__ */ i(
1050
+ h ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__notice-region", children: /* @__PURE__ */ r("div", { className: "make-ai-assistant__privacy-note", role: "note", children: [
1051
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__privacy-icon", "aria-hidden": "true", children: /* @__PURE__ */ a(Zt, {}) }),
1052
+ /* @__PURE__ */ a("span", { children: h })
1053
+ ] }) }) : null,
1054
+ /* @__PURE__ */ r(
931
1055
  "div",
932
1056
  {
933
- className: "make-ai-assistant__body",
1057
+ className: `make-ai-assistant__body${h ? " make-ai-assistant__body--with-notice" : ""}`,
934
1058
  "aria-live": "polite",
935
1059
  "aria-relevant": "additions text",
936
1060
  ref: te,
937
1061
  role: "log",
938
- onScroll: it,
1062
+ onScroll: mt,
939
1063
  children: [
940
- O === "loading" ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__empty", role: "status", children: [
941
- /* @__PURE__ */ a(ie, {}),
1064
+ O === "loading" ? /* @__PURE__ */ r("div", { className: "make-ai-assistant__empty", role: "status", children: [
1065
+ /* @__PURE__ */ a(ke, {}),
942
1066
  /* @__PURE__ */ a("h3", { children: "正在恢复对话" }),
943
1067
  /* @__PURE__ */ a("p", { children: "正在读取当前 App 的历史消息…" })
944
- ] }) : O === "error" ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__empty", role: "alert", children: [
945
- /* @__PURE__ */ a(ie, {}),
946
- /* @__PURE__ */ a("h3", { children: "暂时无法加载对话" }),
947
- /* @__PURE__ */ a("p", { children: "请检查网络后重试。" }),
948
- /* @__PURE__ */ a(
949
- "button",
950
- {
951
- className: "make-ai-assistant__retry",
952
- type: "button",
953
- onClick: () => nt((c) => c + 1),
954
- children: "重新加载"
955
- }
956
- )
957
- ] }) : _.messages.length === 0 ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__empty", children: [
958
- /* @__PURE__ */ a(ie, {}),
1068
+ ] }) : O === "error" ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__empty", children: /* @__PURE__ */ a(
1069
+ la,
1070
+ {
1071
+ error: lt,
1072
+ onRetry: () => ct((c) => c + 1)
1073
+ }
1074
+ ) }) : _.messages.length === 0 ? /* @__PURE__ */ r("div", { className: "make-ai-assistant__empty", children: [
1075
+ /* @__PURE__ */ a(ke, {}),
959
1076
  /* @__PURE__ */ a("h3", { children: "有什么可以帮你?" }),
960
1077
  /* @__PURE__ */ a("p", { children: "我会结合当前 App、页面位置和宿主允许的上下文回答,并把过程与结果分开展示。" })
961
- ] }) : ea(
1078
+ ] }) : ma(
962
1079
  _,
963
1080
  s,
964
- Ce,
1081
+ Se,
1082
+ i,
965
1083
  n,
966
- r,
967
1084
  e,
968
- de ? Re : void 0,
969
- z,
970
- B,
971
- ve,
972
- ft,
973
- (c, h) => {
974
- lt(c, h);
1085
+ de ? Fe : void 0,
1086
+ R,
1087
+ $,
1088
+ ye,
1089
+ bt,
1090
+ (c, f) => {
1091
+ pt(c, f);
975
1092
  },
976
1093
  (c) => {
977
- ct(c);
1094
+ ht(c);
978
1095
  }
979
1096
  ),
980
- _.progress && !ht ? /* @__PURE__ */ a(
981
- Oe,
1097
+ _.progress && !kt ? /* @__PURE__ */ a(
1098
+ Ge,
982
1099
  {
983
1100
  assistantName: e,
984
1101
  progress: _.progress
985
1102
  }
986
1103
  ) : null,
987
- _.error && !gt ? /* @__PURE__ */ a(
988
- Oe,
1104
+ _.error && !yt ? /* @__PURE__ */ a(
1105
+ Ge,
989
1106
  {
990
1107
  assistantName: e,
991
1108
  error: _.error,
992
- onRetry: de ? Re : void 0
1109
+ onRetry: de ? Fe : void 0
993
1110
  }
994
1111
  ) : null
995
1112
  ]
996
1113
  }
997
1114
  ),
998
- rt ? /* @__PURE__ */ a(
1115
+ dt ? /* @__PURE__ */ a(
999
1116
  "button",
1000
1117
  {
1001
1118
  "aria-label": "回到最新消息",
1002
1119
  className: "make-ai-assistant__back-to-latest",
1003
1120
  type: "button",
1004
- onClick: ot,
1005
- children: /* @__PURE__ */ a(Ut, {})
1121
+ onClick: ut,
1122
+ children: /* @__PURE__ */ a(Gt, {})
1006
1123
  }
1007
1124
  ) : null,
1008
- /* @__PURE__ */ i("footer", { className: "make-ai-assistant__composer-region", children: [
1009
- O === "ready" && $e.length > 0 && _.messages.length === 0 ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__suggestions", "aria-label": "推荐问题", children: $e.map((c, h) => /* @__PURE__ */ a(
1125
+ /* @__PURE__ */ r("footer", { className: "make-ai-assistant__composer-region", children: [
1126
+ O === "ready" && xe.length > 0 && _.messages.length === 0 ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__suggestions", "aria-label": "推荐问题", children: xe.map((c, f) => /* @__PURE__ */ a(
1010
1127
  "button",
1011
1128
  {
1012
1129
  type: "button",
@@ -1015,36 +1132,36 @@ function at({
1015
1132
  },
1016
1133
  children: c
1017
1134
  },
1018
- `${h}-${c}`
1135
+ `${f}-${c}`
1019
1136
  )) }) : null,
1020
- /* @__PURE__ */ i("form", { className: "make-ai-assistant__composer", onSubmit: dt, children: [
1137
+ /* @__PURE__ */ r("form", { className: "make-ai-assistant__composer", onSubmit: ft, children: [
1021
1138
  /* @__PURE__ */ a(
1022
1139
  "textarea",
1023
1140
  {
1024
1141
  "aria-label": `向 ${e} 提问`,
1025
- "aria-describedby": q ? "make-ai-composer-error" : void 0,
1026
- "aria-invalid": q ? !0 : void 0,
1142
+ "aria-describedby": H ? "make-ai-composer-error" : void 0,
1143
+ "aria-invalid": H ? !0 : void 0,
1027
1144
  autoFocus: !0,
1028
1145
  disabled: O !== "ready" || _.status === "streaming",
1029
1146
  placeholder: `询问当前 ${s.app.name ?? "App"} 中的数据…`,
1030
- ref: Ne,
1147
+ ref: Te,
1031
1148
  rows: 2,
1032
1149
  value: I,
1033
1150
  onChange: (c) => {
1034
1151
  V(c.currentTarget.value), U(void 0);
1035
1152
  },
1036
- onKeyDown: mt
1153
+ onKeyDown: gt
1037
1154
  }
1038
1155
  ),
1039
1156
  _.status === "streaming" ? /* @__PURE__ */ a(
1040
1157
  "button",
1041
1158
  {
1042
- "aria-label": Se,
1159
+ "aria-label": Le,
1043
1160
  className: "make-ai-assistant__send make-ai-assistant__send--stop",
1044
- "data-tooltip": Se,
1045
- ref: we,
1161
+ "data-tooltip": Le,
1162
+ ref: $e,
1046
1163
  type: "button",
1047
- onClick: ut,
1164
+ onClick: _t,
1048
1165
  children: /* @__PURE__ */ a("span", { "aria-hidden": "true" })
1049
1166
  }
1050
1167
  ) : /* @__PURE__ */ a(
@@ -1054,71 +1171,71 @@ function at({
1054
1171
  className: "make-ai-assistant__send",
1055
1172
  disabled: O !== "ready" || !I.trim(),
1056
1173
  type: "submit",
1057
- children: /* @__PURE__ */ a(Kt, {})
1174
+ children: /* @__PURE__ */ a(Yt, {})
1058
1175
  }
1059
1176
  )
1060
1177
  ] }),
1061
- q ? /* @__PURE__ */ a("p", { id: "make-ai-composer-error", role: "alert", children: q }) : null,
1178
+ H ? /* @__PURE__ */ a("p", { id: "make-ai-composer-error", role: "alert", children: H }) : null,
1062
1179
  /* @__PURE__ */ a("p", { children: "AI 生成的结果可能存在偏差,重要数据请核对明细。" })
1063
1180
  ] })
1064
1181
  ]
1065
1182
  }
1066
1183
  );
1067
1184
  }
1068
- function ra(e) {
1069
- return /* @__PURE__ */ a(at, { ...e, visible: !0 });
1185
+ function ga(e) {
1186
+ return /* @__PURE__ */ a(it, { ...e, visible: !0 });
1070
1187
  }
1071
- function ia({
1188
+ function _a({
1072
1189
  defaultOpen: e = !1,
1073
1190
  hideLauncher: t = !1,
1074
1191
  launcher: s,
1075
- onOpenChange: n,
1076
- open: r,
1192
+ onOpenChange: i,
1193
+ open: n,
1077
1194
  ...o
1078
1195
  }) {
1079
- const d = Ye(o.brandName, o.title), [p, f] = R(e), [b, C] = R(
1080
- () => e || r === !0
1081
- ), $ = w(null), m = r ?? p, B = (k) => {
1082
- r === void 0 && f(k), n?.(k), k || requestAnimationFrame(() => $.current?.focus());
1083
- }, z = () => B(!m);
1196
+ const l = Qe(o.brandName, o.title), [m, k] = x(e), [p, M] = x(
1197
+ () => e || n === !0
1198
+ ), T = N(null), u = n ?? m, $ = (y) => {
1199
+ n === void 0 && k(y), i?.(y), y || requestAnimationFrame(() => T.current?.focus());
1200
+ }, R = () => $(!u);
1084
1201
  return Q(() => {
1085
- m && C(!0);
1086
- }, [m]), Q(() => {
1087
- if (!m) return;
1088
- const k = (D) => {
1089
- D.key === "Escape" && (B(!1), requestAnimationFrame(() => $.current?.focus()));
1202
+ u && M(!0);
1203
+ }, [u]), Q(() => {
1204
+ if (!u) return;
1205
+ const y = (q) => {
1206
+ q.key === "Escape" && ($(!1), requestAnimationFrame(() => T.current?.focus()));
1090
1207
  };
1091
- return document.addEventListener("keydown", k), () => document.removeEventListener("keydown", k);
1092
- }, [n, m]), /* @__PURE__ */ i("div", { className: "make-ai-assistant", "data-open": m || void 0, children: [
1093
- !t && (!m || s) ? s ? s({ open: m, toggle: z }) : /* @__PURE__ */ i(
1208
+ return document.addEventListener("keydown", y), () => document.removeEventListener("keydown", y);
1209
+ }, [i, u]), /* @__PURE__ */ r("div", { className: "make-ai-assistant", "data-open": u || void 0, children: [
1210
+ !t && (!u || s) ? s ? s({ open: u, toggle: R }) : /* @__PURE__ */ r(
1094
1211
  "button",
1095
1212
  {
1096
- "aria-label": m ? `关闭 ${d}` : `打开 ${d}`,
1097
- "aria-expanded": m,
1213
+ "aria-label": u ? `关闭 ${l}` : `打开 ${l}`,
1214
+ "aria-expanded": u,
1098
1215
  className: "make-ai-assistant__launcher",
1099
- ref: $,
1216
+ ref: T,
1100
1217
  type: "button",
1101
- onClick: z,
1218
+ onClick: R,
1102
1219
  children: [
1103
1220
  /* @__PURE__ */ a("span", { className: "make-ai-assistant__launcher-orbit", "aria-hidden": "true" }),
1104
- /* @__PURE__ */ a(We, {})
1221
+ /* @__PURE__ */ a(Xe, {})
1105
1222
  ]
1106
1223
  }
1107
1224
  ) : null,
1108
- b ? /* @__PURE__ */ a(
1225
+ p ? /* @__PURE__ */ a(
1109
1226
  "aside",
1110
1227
  {
1111
- "aria-label": d,
1228
+ "aria-label": l,
1112
1229
  "aria-modal": "false",
1113
1230
  className: "make-ai-assistant__drawer",
1114
- hidden: !m,
1231
+ hidden: !u,
1115
1232
  role: "dialog",
1116
1233
  children: /* @__PURE__ */ a(
1117
- at,
1234
+ it,
1118
1235
  {
1119
1236
  ...o,
1120
- onClose: () => B(!1),
1121
- visible: m
1237
+ onClose: () => $(!1),
1238
+ visible: u
1122
1239
  }
1123
1240
  )
1124
1241
  }
@@ -1126,24 +1243,24 @@ function ia({
1126
1243
  ] });
1127
1244
  }
1128
1245
  export {
1129
- At as ArtifactRenderer,
1130
- ra as AssistantPanel,
1131
- ma as MAKE_AI_ARTIFACT_KINDS,
1132
- ua as MAKE_AI_ARTIFACT_LIMITS,
1133
- pa as MAKE_AI_ARTIFACT_SCHEMA_VERSION,
1134
- N as MAKE_AI_CONVERSATION_LIMITS,
1135
- ia as MakeAiAssistant,
1136
- yt as appendUserMessage,
1137
- vt as createArtifactCapabilities,
1138
- je as createArtifactTemplateRegistry,
1139
- ge as createAssistantConversationState,
1140
- St as createPlatformArtifactRegistry,
1141
- la as extendArtifactTemplateRegistry,
1142
- K as formatArtifactValue,
1143
- ha as parseArtifact,
1144
- kt as parseAssistantEvent,
1145
- Et as platformArtifactTemplates,
1146
- fe as reduceAssistantEvent,
1147
- _t as resolveArtifactTemplate,
1148
- ga as validateArtifact
1246
+ Mt as ArtifactRenderer,
1247
+ ga as AssistantPanel,
1248
+ Aa as MAKE_AI_ARTIFACT_KINDS,
1249
+ Ia as MAKE_AI_ARTIFACT_LIMITS,
1250
+ wa as MAKE_AI_ARTIFACT_SCHEMA_VERSION,
1251
+ w as MAKE_AI_CONVERSATION_LIMITS,
1252
+ _a as MakeAiAssistant,
1253
+ wt as appendUserMessage,
1254
+ It as createArtifactCapabilities,
1255
+ We as createArtifactTemplateRegistry,
1256
+ fe as createAssistantConversationState,
1257
+ Pt as createPlatformArtifactRegistry,
1258
+ ya as extendArtifactTemplateRegistry,
1259
+ z as formatArtifactValue,
1260
+ Na as parseArtifact,
1261
+ Nt as parseAssistantEvent,
1262
+ Ft as platformArtifactTemplates,
1263
+ ge as reduceAssistantEvent,
1264
+ At as resolveArtifactTemplate,
1265
+ Ma as validateArtifact
1149
1266
  };