@qfei-design/make-ai-assistant 0.1.7 → 0.1.9

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