@qfei-design/make-ai-assistant 0.1.8 → 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,18 +1,18 @@
1
- import { jsxs as i, jsx as a, Fragment as B } from "react/jsx-runtime";
2
- import { resolveArtifactTemplate as lt, createArtifactTemplateRegistry as Ue, createArtifactCapabilities as dt } from "./index.mjs";
3
- import { extendArtifactTemplateRegistry as ta } from "./index.mjs";
4
- import { useState as R, useRef as x, useMemo as Fe, useEffect as fe } from "react";
5
- import { a as pe, r as he, c as ge, M as I, b as mt, p as ut } from "./conversation-B7eGUXi-.js";
6
- import { d as sa, e as na, f as ra, g as ia, v as oa } from "./conversation-B7eGUXi-.js";
7
- function pt({
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 d = lt(c, e, t);
15
+ const d = _t(o, e, t);
16
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: "暂不支持展示此结果" }),
@@ -21,78 +21,78 @@ function pt({
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 d.template.render(e, t, u);
29
+ return d.template.render(e, t, p);
30
30
  }
31
- const D = (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
- }, Ve = (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
- }, qe = (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);
64
+ s.onActionError(o, e, t)
65
+ ).catch(n);
66
66
  } catch (d) {
67
- r(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
- }, G = (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: () => qe(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, Y = (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 D = (e, t, s) => {
105
105
  t
106
106
  ]
107
107
  }
108
- ), ht = ({
108
+ ), bt = ({
109
109
  artifact: e,
110
110
  renderContext: t
111
111
  }) => {
112
- const s = e.data.delta, r = s ? D(
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 Y(
117
+ return ee(
118
118
  e,
119
- /* @__PURE__ */ i(B, { children: [
120
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__metric-value", children: D(
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 D = (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
- G(e, t)
137
+ X(e, t)
138
138
  ] }),
139
139
  "make-ai-artifact--metric"
140
140
  );
141
- }, gt = ({
141
+ }, It = ({
142
142
  artifact: e,
143
143
  renderContext: t
144
- }) => Y(
144
+ }) => ee(
145
145
  e,
146
- /* @__PURE__ */ i(B, { 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: D(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
- G(e, t)
152
+ X(e, t)
153
153
  ] }),
154
154
  "make-ai-artifact--comparison"
155
- ), ft = ({
155
+ ), Nt = ({
156
156
  artifact: e,
157
157
  renderContext: t
158
158
  }) => {
159
- const s = e.data.series.flatMap((d) => d.points.map((u) => u.y)), { max: r, min: o } = Ve(s), c = r - o || 1;
160
- return Y(
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(B, { children: [
162
+ /* @__PURE__ */ i(H, { children: [
163
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
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((u, h) => {
166
- const k = 18 + (u.y - o) / c * 70;
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}: ${D(
172
- u.y,
171
+ "aria-label": `${p.x}: ${K(
172
+ p.y,
173
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}: ${D(
180
- u.y,
178
+ style: { height: `${b}%` },
179
+ title: `${p.x}: ${K(
180
+ p.y,
181
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
189
  ] }, d.id)) }),
190
- G(e, t)
190
+ X(e, t)
191
191
  ] }),
192
192
  "make-ai-artifact--trend"
193
193
  );
194
- }, _t = ({
194
+ }, wt = ({
195
195
  artifact: e,
196
196
  renderContext: t
197
197
  }) => {
198
- const { max: s } = Ve(
199
- e.data.items.map((o) => Math.abs(o.value))
200
- ), r = Math.max(s, 1);
201
- return Y(
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(B, { 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: D(o.value, o.format, t.context.locale) })
212
- ] }, o.id)) }),
213
- G(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
- }, vt = (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
- }, yt = ({
222
+ }, Tt = ({
223
223
  artifact: e,
224
224
  renderContext: t
225
- }) => Y(
225
+ }) => ee(
226
226
  e,
227
- /* @__PURE__ */ i(B, { 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 = vt(e, s), o = /* @__PURE__ */ i(B, { 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
- D(
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 D = (e, t, s) => {
243
243
  {
244
244
  className: "make-ai-artifact__record",
245
245
  type: "button",
246
- onClick: () => qe(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
- G(e, t)
260
+ X(e, t)
261
261
  ] }),
262
262
  "make-ai-artifact--record-list"
263
- ), kt = ({
263
+ ), Ct = ({
264
264
  artifact: e,
265
265
  renderContext: t
266
- }) => Y(
266
+ }) => ee(
267
267
  e,
268
- /* @__PURE__ */ i(B, { 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
- G(e, t)
273
+ X(e, t)
274
274
  ] }),
275
275
  "make-ai-artifact--notice"
276
- ), Z = (e, t, s) => ({ id: e, kinds: [t], priority: 0, render: s }), At = [
277
- Z("platform.metric.default", "metric", (e, t, s) => /* @__PURE__ */ a(ht, { artifact: e, renderContext: s })),
278
- Z("platform.comparison.default", "comparison", (e, t, s) => /* @__PURE__ */ a(gt, { artifact: e, renderContext: s })),
279
- Z("platform.trend.default", "trend", (e, t, s) => /* @__PURE__ */ a(ft, { artifact: e, renderContext: s })),
280
- Z("platform.ranking.default", "ranking", (e, t, s) => /* @__PURE__ */ a(_t, { artifact: e, renderContext: s })),
281
- Z("platform.record-list.default", "record-list", (e, t, s) => /* @__PURE__ */ a(yt, { artifact: e, renderContext: s })),
282
- Z("platform.notice.default", "notice", (e, t, s) => /* @__PURE__ */ a(kt, { artifact: e, renderContext: s }))
283
- ], bt = Ue(At).templates, It = (e = bt) => Ue(e), Nt = (e) => `${e}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, wt = "Make", Mt = [
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
- ], He = (e, t) => t ?? `${e?.trim() || wt} AI 助手`, Tt = (e) => e ?? Mt;
288
- class g extends Error {
287
+ ], Ye = (e, t) => t ?? `${e?.trim() || xt} AI 助手`, Ft = (e) => e ?? Lt;
288
+ class v extends Error {
289
289
  }
290
- const Pe = (e) => {
290
+ const Ke = (e) => {
291
291
  try {
292
292
  const t = e?.return?.();
293
293
  if (!t) return;
@@ -301,7 +301,7 @@ const Pe = (e) => {
301
301
  errorType: t instanceof Error ? t.name : typeof t
302
302
  });
303
303
  }
304
- }, Ct = 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 Pe = (e) => {
313
313
  const s = document.execCommand("copy");
314
314
  if (t.remove(), !s)
315
315
  throw new Error("Clipboard copy failed");
316
- }, Ke = () => /* @__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
- ] }), $t = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m6 6 12 12M18 6 6 18" }) }), Et = () => /* @__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
- ] }), St = () => /* @__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
- ] }), Rt = () => /* @__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
- ] }), xt = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "M12 5v14M5 12h14" }) }), Lt = () => /* @__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
- ] }), ae = ({ className: e = "" }) => /* @__PURE__ */ a("span", { className: `make-ai-assistant__avatar ${e}`.trim(), "aria-hidden": "true", children: /* @__PURE__ */ a(Ke, {}) }), Ft = ({ src: e }) => e ? /* @__PURE__ */ a("span", { className: "make-ai-assistant__user-avatar", "aria-hidden": "true", children: /* @__PURE__ */ a("img", { alt: "", src: e }) }) : null, Pt = ({
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(Ft, { src: e })
346
+ /* @__PURE__ */ a(zt, { src: e })
342
347
  ] });
343
- }, Bt = (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 });
352
+ s.length = 0, f && t.push({ type: "paragraph", text: f });
348
353
  }, d = () => {
349
- r.length && t.push({ type: "list", items: r.splice(0) });
350
- }, u = () => {
351
- const h = o.join(`
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(), d(), 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(), d(), 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 _ = /^\s*[-*]\s+(.+)$/.exec(h);
368
- if (_) {
369
- c(), u(), r.push(_[1]?.trim() ?? "");
383
+ const $ = /^\s*[-*]\s+(.+)$/.exec(f);
384
+ if ($) {
385
+ o(), p(), n.push($[1]?.trim() ?? "");
370
386
  continue;
371
387
  }
372
- d(), u(), s.push(k);
388
+ d(), p(), s.push(b);
373
389
  }
374
- return c(), d(), u(), t;
375
- }, Be = (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], d = o.index ?? 0;
380
- d > r && t.push(e.slice(r, d)), c.startsWith("**") ? t.push(/* @__PURE__ */ a("strong", { children: c.slice(2, -2) }, `${d}-strong`)) : t.push(/* @__PURE__ */ a("code", { children: c.slice(1, -1) }, `${d}-code`)), r = d + 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
- }, Dt = ({ content: e }) => {
384
- const t = Bt(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: Be(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: Be(o) }, `${c}-${o}`)) }, `${r}-list`)) }) : null;
386
- }, ze = ({ assistantName: e }) => /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-identity", children: [
387
- /* @__PURE__ */ a(ae, { 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
- ] }), Oe = (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
- }, Ut = (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
- }, je = (e) => {
400
- const t = Ut(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
- }, Vt = (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
- }, qt = (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
- }, Ht = (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 Pe = (e) => {
426
455
  status: "streaming",
427
456
  messages: s < 0 ? e.messages : e.messages.slice(0, s + 1)
428
457
  };
429
- }, Kt = (e) => e.scrollHeight - e.scrollTop - e.clientHeight <= 48, zt = (e = "smooth") => globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : e, Ze = ({
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 Pe = (e) => {
441
472
  children: "重新发送"
442
473
  }
443
474
  ) : null
444
- ] }), Ge = ({
475
+ ] }), tt = ({
445
476
  active: e,
446
477
  steps: t
447
478
  }) => {
@@ -458,19 +489,19 @@ const Pe = (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
- }, Ot = ({
504
+ }, Xt = ({
474
505
  copyFeedback: e,
475
506
  onCopy: t,
476
507
  onRegenerate: s
@@ -480,18 +511,21 @@ const Pe = (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(Et, {})
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,573 +537,613 @@ const Pe = (e) => {
503
537
  children: e.message
504
538
  }
505
539
  ) : null
506
- ] }), De = ({
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(ze, { assistantName: e }),
522
- /* @__PURE__ */ a("div", { className: "make-ai-assistant__message-stack", children: t ? /* @__PURE__ */ a(Ze, { error: t, onRetry: s }) : /* @__PURE__ */ a(Ge, { 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
- }, jt = (e, t, s, r, o, c, d, u, h, k, _, L, y) => {
527
- const M = je(e), W = Oe(e), J = Vt(e);
528
- let Q;
529
- return e.messages.map((m) => {
530
- const b = m.role === "assistant", p = Q;
531
- b || (Q = m);
532
- const T = m.id === W, U = m.id === M ? e.error : void 0, C = m.error ?? U, $ = !b && !!(u?.trim() || h), _e = b ? c : u?.trim() || "用户", F = b && m.status === "complete" && !C && (m.content.trim() || m.id === J);
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": `${_e}的消息`,
537
- className: `make-ai-assistant__message make-ai-assistant__message--${m.role}`,
538
- "data-message-role": m.role,
539
- "data-message-state": C ? "error" : void 0,
540
- "data-message-status": m.status,
541
- "data-message-has-identity": b || $ ? !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
- b ? /* @__PURE__ */ a(ze, { assistantName: c }) : $ ? /* @__PURE__ */ a(Pt, { 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
- m.content ? b ? /* @__PURE__ */ a(Dt, { content: m.content }) : /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble", children: m.content }) : m.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
- b ? /* @__PURE__ */ a(
551
- Ge,
584
+ I ? /* @__PURE__ */ a(
585
+ tt,
552
586
  {
553
- active: T && e.status === "streaming",
554
- steps: m.progressSteps
587
+ active: _ && e.status === "streaming",
588
+ steps: u.progressSteps
555
589
  }
556
590
  ) : null,
557
- C ? /* @__PURE__ */ a(
558
- Ze,
591
+ E ? /* @__PURE__ */ a(
592
+ et,
559
593
  {
560
- error: C,
561
- onRetry: U ? d : void 0
594
+ error: E,
595
+ onRetry: M ? d : void 0
562
596
  }
563
597
  ) : null,
564
- m.artifacts.map((se) => /* @__PURE__ */ a(
565
- pt,
598
+ u.artifacts.map((x) => /* @__PURE__ */ a(
599
+ At,
566
600
  {
567
- artifact: se,
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
- se.id
607
+ x.id
574
608
  )),
575
- F ? /* @__PURE__ */ a(
576
- Ot,
609
+ ve ? /* @__PURE__ */ a(
610
+ Xt,
577
611
  {
578
- copyFeedback: k?.messageId === m.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: m.content.trim() ? () => L(m.id, m.content) : void 0,
583
- onRegenerate: _ && m.id === J && p ? () => y({
584
- userMessage: p,
585
- assistantMessage: m
616
+ onCopy: u.content.trim() ? () => $(u.id, u.content) : void 0,
617
+ onRegenerate: C && u.id === k && V ? () => m({
618
+ userMessage: V,
619
+ assistantMessage: u
586
620
  }) : void 0
587
621
  }
588
622
  ) : null
589
623
  ] })
590
624
  ] })
591
625
  },
592
- m.id
626
+ u.id
593
627
  );
594
628
  });
595
629
  };
596
- function Zt({
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,
634
+ onAction: n,
635
+ onActionError: r,
636
+ onClose: o,
603
637
  onNewConversation: d,
604
- privacyNotice: u,
605
- registry: h,
606
- subtitle: k,
607
- suggestions: _,
608
- title: L,
609
- transport: y,
610
- userAvatarUrl: M,
611
- userName: W
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
612
647
  }) {
613
- const J = He(t, L), Q = u?.trim(), [m, b] = R(""), [p, T] = R(pe), U = x(p);
614
- U.current = p;
615
- const [C, $] = R(void 0), [_e, F] = R(void 0), [se, Ye] = R(0), [V, ne] = R(() => y.loadConversation ? "loading" : "ready"), [We, q] = R(!1), H = x(void 0), K = x(void 0), z = x(0), re = x(null), P = x(!0), Ae = x(s.app.id), be = Fe(
616
- () => h ?? It(),
617
- [h]
618
- ), Ie = Fe(
619
- () => Tt(_),
620
- [_]
621
- ), ie = (n) => {
622
- const f = H.current, v = K.current?.iterator;
623
- return !f && !v ? !1 : (z.current += 1, H.current = void 0, K.current = void 0, console.info("[make-ai-assistant] local run cancellation requested", { reason: n }), f?.abort(), Pe(v), !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);
624
659
  };
625
- fe(() => () => {
626
- ie("unmount");
627
- }, []), fe(() => {
628
- const n = y.loadConversation, f = Ae.current !== s.app.id;
629
- if (Ae.current = s.app.id, ie("reinitialize"), f && (b(""), P.current = !0), $(void 0), F(void 0), q(!1), T(pe()), !n) {
630
- ne("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");
631
666
  return;
632
667
  }
633
- const v = new AbortController();
634
- return ne("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", {
635
670
  appId: s.app.id
636
- }), n.call(y, s, { signal: v.signal }).then((N) => {
637
- v.signal.aborted || (T(pe(N)), ne("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", {
638
673
  appId: s.app.id,
639
- messageCount: N.messages.length
674
+ messageCount: y.messages.length
640
675
  }));
641
- }).catch((N) => {
642
- v.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", {
643
678
  appId: s.app.id,
644
- errorType: N instanceof Error ? N.name : typeof N
645
- }), ne("error"));
646
- }), () => v.abort();
647
- }, [s.app.id, se, y]), fe(() => {
648
- const n = re.current;
649
- if (!n || !P.current) return;
650
- q(!1);
651
- const f = requestAnimationFrame(() => {
652
- if (!P.current) return;
653
- const v = p.status === "streaming" || globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
654
- typeof n.scrollTo == "function" ? n.scrollTo({ top: n.scrollHeight, behavior: v }) : n.scrollTop = n.scrollHeight;
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(() => {
687
+ if (!F.current) return;
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();
655
704
  });
656
- return () => cancelAnimationFrame(f);
657
- }, [p.messages, p.progress, p.status]);
658
- const Je = () => {
659
- const n = re.current;
660
- if (!n) return;
661
- const f = Kt(n);
662
- P.current = f, q(!f && U.current.messages.length > 0);
663
- }, Qe = () => {
664
- const n = re.current;
665
- if (!n) return;
666
- P.current = !0, q(!1);
667
- const f = zt();
668
- typeof n.scrollTo == "function" ? n.scrollTo({ top: n.scrollHeight, behavior: f }) : n.scrollTop = n.scrollHeight;
669
- }, Ne = async (n, f) => {
670
- const v = n.trim(), N = U.current, E = f?.regenerateFrom, ve = y.regenerate;
671
- if (!v || V !== "ready" || N.status === "streaming" || H.current || E && !ve) return;
672
- if (ge(
673
- v,
674
- I.messageCharacters
675
- ) > I.messageCharacters) {
676
- $(
677
- `输入内容过长,请控制在 ${I.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} 个字符以内`
678
727
  );
679
728
  return;
680
729
  }
681
- const le = {
682
- id: E?.userMessage.id ?? Nt("user"),
683
- content: v
684
- }, de = E ? Ht(N, E.userMessage.id) : mt(N, le), me = new AbortController(), O = z.current + 1;
685
- z.current = O, H.current = me, $(void 0), F(void 0), q(!P.current && N.messages.length > 0), E || b(""), T(de);
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);
686
735
  try {
687
- let S = !1, A, Me = 0, Te = 0, Ce = 0, ye = 0, X = 0;
688
- const ee = /* @__PURE__ */ new Map(), $e = /* @__PURE__ */ new Set(), Ee = /* @__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(
689
738
  [
690
- ...de.messages.map((ue) => ue.id),
691
- le.id
739
+ ...ue.messages.map((he) => he.id),
740
+ me.id
692
741
  ]
693
- ), te = /* @__PURE__ */ new Set(), Se = dt(be), Re = { signal: me.signal };
742
+ ), re = /* @__PURE__ */ new Set(), De = vt(Ce), Ve = { signal: pe.signal };
694
743
  let ke;
695
- if (E) {
696
- if (!ve)
697
- throw new g("当前 AI 助手不支持重新生成");
698
- ke = ve({
699
- threadId: de.threadId,
700
- message: le,
744
+ if (S) {
745
+ if (!ae)
746
+ throw new v("当前 AI 助手不支持重新生成");
747
+ ke = ae({
748
+ threadId: ue.threadId,
749
+ message: me,
701
750
  assistantMessage: {
702
- id: E.assistantMessage.id,
703
- content: E.assistantMessage.content
751
+ id: S.assistantMessage.id,
752
+ content: S.assistantMessage.content
704
753
  },
705
754
  context: s,
706
- capabilities: Se
707
- }, Re);
755
+ capabilities: De
756
+ }, Ve);
708
757
  } else
709
- ke = y.run(
758
+ ke = m.run(
710
759
  {
711
- threadId: de.threadId,
712
- message: le,
760
+ threadId: ue.threadId,
761
+ message: me,
713
762
  context: s,
714
- capabilities: Se
763
+ capabilities: De
715
764
  },
716
- Re
765
+ Ve
717
766
  );
718
- const xe = ke[Symbol.asyncIterator]();
719
- for (K.current = { iterator: xe, requestVersion: O }; ; ) {
720
- const ue = await xe.next();
721
- if (z.current !== O || ue.done) break;
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;
722
771
  let l;
723
772
  try {
724
- l = ut(ue.value);
725
- } catch (w) {
726
- throw new g(
727
- w instanceof Error ? w.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"
728
777
  );
729
778
  }
730
779
  if (l.type === "message.start") {
731
780
  if (A !== void 0 && A !== l.runId)
732
- throw new g("AI 助手响应 run id 不一致");
733
- if (A ??= l.runId, Te += 1, Te > I.assistantMessagesPerRun)
734
- throw new g("AI 助手单次响应消息数量超过限制");
735
- if (Ee.has(l.messageId))
736
- throw new g("AI 助手响应包含重复的 message id");
737
- Ee.add(l.messageId), te.add(l.messageId), ee.set(l.messageId, 0);
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);
738
787
  }
739
788
  if (l.type === "message.delta") {
740
- if (!te.has(l.messageId))
741
- throw new g("AI 助手响应事件顺序无效");
742
- const w = ee.get(l.messageId) ?? 0, j = ge(
789
+ if (!re.has(l.messageId))
790
+ throw new v("AI 助手响应事件顺序无效");
791
+ const T = ne.get(l.messageId) ?? 0, W = _e(
743
792
  l.delta,
744
- I.messageCharacters - X
793
+ N.messageCharacters - se
745
794
  );
746
- if (X + j > I.messageCharacters)
747
- throw new g("AI 助手响应文本超过大小限制");
748
- X += j, ee.set(
795
+ if (se + W > N.messageCharacters)
796
+ throw new v("AI 助手响应文本超过大小限制");
797
+ se += W, ne.set(
749
798
  l.messageId,
750
- w + j
799
+ T + W
751
800
  );
752
801
  }
753
802
  if (l.type === "message.replace") {
754
- if (!te.has(l.messageId))
755
- throw new g("AI 助手响应事件顺序无效");
756
- const w = ee.get(l.messageId) ?? 0, j = ge(
803
+ if (!re.has(l.messageId))
804
+ throw new v("AI 助手响应事件顺序无效");
805
+ const T = ne.get(l.messageId) ?? 0, W = _e(
757
806
  l.content,
758
- I.messageCharacters
759
- ), Le = X - w + j;
760
- if (Le > I.messageCharacters)
761
- throw new g("AI 助手响应文本超过大小限制");
762
- X = Le, ee.set(l.messageId, j);
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);
763
812
  }
764
813
  if (l.type === "run.progress") {
765
814
  if (A !== void 0 && A !== l.runId)
766
- throw new g("AI 助手响应 run id 不一致");
767
- if (A ??= l.runId, Ce += 1, Ce > I.progressStepsPerRun)
768
- throw new g("AI 助手处理过程数量超过限制");
769
- const w = ge(
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(
770
819
  l.message,
771
- I.progressCharactersPerRun - ye
820
+ N.progressCharactersPerRun - ye
772
821
  );
773
- if (ye + w > I.progressCharactersPerRun)
774
- throw new g("AI 助手处理过程文本超过大小限制");
775
- ye += w;
822
+ if (ye + T > N.progressCharactersPerRun)
823
+ throw new v("AI 助手处理过程文本超过大小限制");
824
+ ye += T;
776
825
  }
777
826
  if (l.type === "artifact") {
778
- if (!te.has(l.messageId))
779
- throw new g("AI 助手响应事件顺序无效");
780
- if (Me += 1, Me > I.artifactsPerRun)
781
- throw new g("AI 助手单次响应 Artifact 数量超过限制");
782
- if ($e.has(l.artifact.id))
783
- throw new g("AI 助手响应包含重复的 Artifact id");
784
- $e.add(l.artifact.id);
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);
785
834
  }
786
- if (l.type === "message.complete" && !te.delete(l.messageId))
787
- throw new g("AI 助手响应事件顺序无效");
835
+ if (l.type === "message.complete" && !re.delete(l.messageId))
836
+ throw new v("AI 助手响应事件顺序无效");
788
837
  if (l.type === "run.complete" && A !== void 0 && A !== l.runId)
789
- throw new g("AI 助手响应 run id 不一致");
838
+ throw new v("AI 助手响应 run id 不一致");
790
839
  if (l.type === "run.cancelled" && l.runId !== void 0 && A !== void 0 && A !== l.runId)
791
- throw new g("AI 助手响应 run id 不一致");
792
- if (T((w) => he(w, l)), l.type === "error" || l.type === "run.cancelled" || l.type === "run.complete") {
793
- S = !0;
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;
794
843
  break;
795
844
  }
796
845
  }
797
- if (!S)
798
- throw new g("AI 助手流式响应在终止事件前结束");
799
- } catch (S) {
800
- if (z.current !== O) return;
801
- if (me.signal.aborted) {
802
- T(
803
- (A) => he(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" })
804
853
  );
805
854
  return;
806
855
  }
807
856
  console.error("[make-ai-assistant] assistant run failed", {
808
857
  appId: s.app.id,
809
- errorType: S instanceof Error ? S.name : typeof S
810
- }), T(
811
- (A) => he(A, {
858
+ errorType: P instanceof Error ? P.name : typeof P
859
+ }), M(
860
+ (A) => fe(A, {
812
861
  type: "error",
813
862
  code: "TRANSPORT_ERROR",
814
- message: S instanceof g ? S.message : "连接失败,请重试",
863
+ message: P instanceof v ? P.message : "连接失败,请重试",
815
864
  retryable: !0
816
865
  })
817
866
  );
818
867
  } finally {
819
- z.current === O && H.current === me && (H.current = void 0), K.current?.requestVersion === O && (Pe(K.current.iterator), K.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);
820
869
  }
821
- }, oe = (n) => Ne(n), Xe = (n) => Ne(n.userMessage.content, { regenerateFrom: n }), et = async (n, f) => {
870
+ }, le = (c) => Ee(c), ct = (c) => Ee(c.userMessage.content, { regenerateFrom: c }), lt = async (c, h) => {
822
871
  try {
823
- await Ct(f), F({ messageId: n, message: "已复制", status: "success" });
824
- } catch (v) {
872
+ await Pt(h), x({ messageId: c, message: "已复制", status: "success" });
873
+ } catch (g) {
825
874
  console.error("[make-ai-assistant] copy answer failed", {
826
- errorType: v instanceof Error ? v.name : typeof v
827
- }), F({ messageId: n, message: "复制失败", status: "error" });
875
+ errorType: g instanceof Error ? g.name : typeof g
876
+ }), x({ messageId: c, message: "复制失败", status: "error" });
828
877
  }
829
- }, tt = (n) => {
830
- n.preventDefault(), oe(m);
831
- }, at = (n) => {
832
- n.key === "Enter" && !n.shiftKey && !n.nativeEvent.isComposing && (n.preventDefault(), oe(m));
833
- }, st = () => {
834
- ie("stop") && T(
835
- (n) => he(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" })
836
885
  );
837
- }, nt = () => {
838
- ie("new-conversation"), b(""), $(void 0), F(void 0), q(!1), P.current = !0, T(pe()), d?.();
839
- }, rt = y.features?.remoteCancellation === !1 ? "停止接收" : "停止生成", it = Oe(p), ot = je(p), ce = qt(p), ct = typeof y.regenerate == "function" && y.features?.regeneration !== !1, we = () => {
840
- ce && oe(ce.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);
841
890
  };
842
- return /* @__PURE__ */ i("section", { className: "make-ai-assistant make-ai-assistant__panel", children: [
843
- /* @__PURE__ */ i("header", { className: "make-ai-assistant__header", children: [
844
- /* @__PURE__ */ a(ae, {}),
845
- /* @__PURE__ */ i("div", { children: [
846
- /* @__PURE__ */ a("h2", { children: J }),
847
- /* @__PURE__ */ a("p", { children: k ?? `当前应用:${s.app.name ?? "未命名应用"}` })
848
- ] }),
849
- /* @__PURE__ */ i("div", { className: "make-ai-assistant__header-actions", children: [
850
- y.features?.newConversation !== !1 ? /* @__PURE__ */ a(
851
- "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",
852
932
  {
853
- "aria-label": "新建对话",
854
- className: "make-ai-assistant__icon-button",
855
- type: "button",
856
- onClick: nt,
857
- children: /* @__PURE__ */ a(xt, {})
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
+ ]
858
996
  }
859
- ) : null,
860
- c ? /* @__PURE__ */ a(
997
+ ),
998
+ rt ? /* @__PURE__ */ a(
861
999
  "button",
862
1000
  {
863
- "aria-label": `关闭 ${J}`,
864
- className: "make-ai-assistant__icon-button",
1001
+ "aria-label": "回到最新消息",
1002
+ className: "make-ai-assistant__back-to-latest",
865
1003
  type: "button",
866
- onClick: c,
867
- children: /* @__PURE__ */ a($t, {})
1004
+ onClick: ot,
1005
+ children: /* @__PURE__ */ a(Ut, {})
868
1006
  }
869
- ) : null
870
- ] })
871
- ] }),
872
- Q ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__privacy-note", role: "note", children: [
873
- /* @__PURE__ */ a("span", { className: "make-ai-assistant__privacy-icon", "aria-hidden": "true", children: /* @__PURE__ */ a(St, {}) }),
874
- /* @__PURE__ */ a("span", { children: Q })
875
- ] }) : null,
876
- /* @__PURE__ */ i(
877
- "div",
878
- {
879
- className: "make-ai-assistant__body",
880
- "aria-live": "polite",
881
- "aria-relevant": "additions text",
882
- ref: re,
883
- role: "log",
884
- onScroll: Je,
885
- children: [
886
- V === "loading" ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__empty", role: "status", children: [
887
- /* @__PURE__ */ a(ae, {}),
888
- /* @__PURE__ */ a("h3", { children: "正在恢复对话" }),
889
- /* @__PURE__ */ a("p", { children: "正在读取当前 App 的历史消息…" })
890
- ] }) : V === "error" ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__empty", role: "alert", children: [
891
- /* @__PURE__ */ a(ae, {}),
892
- /* @__PURE__ */ a("h3", { children: "暂时无法加载对话" }),
893
- /* @__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: [
894
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(
895
1040
  "button",
896
1041
  {
897
- 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,
898
1046
  type: "button",
899
- onClick: () => Ye((n) => n + 1),
900
- 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, {})
901
1058
  }
902
1059
  )
903
- ] }) : p.messages.length === 0 ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__empty", children: [
904
- /* @__PURE__ */ a(ae, {}),
905
- /* @__PURE__ */ a("h3", { children: "有什么可以帮你?" }),
906
- /* @__PURE__ */ a("p", { children: "我会结合当前 App、页面位置和宿主允许的上下文回答,并把过程与结果分开展示。" })
907
- ] }) : jt(
908
- p,
909
- s,
910
- be,
911
- r,
912
- o,
913
- e,
914
- ce ? we : void 0,
915
- W,
916
- M,
917
- _e,
918
- ct,
919
- (n, f) => {
920
- et(n, f);
921
- },
922
- (n) => {
923
- Xe(n);
924
- }
925
- ),
926
- p.progress && !it ? /* @__PURE__ */ a(
927
- De,
928
- {
929
- assistantName: e,
930
- progress: p.progress
931
- }
932
- ) : null,
933
- p.error && !ot ? /* @__PURE__ */ a(
934
- De,
935
- {
936
- assistantName: e,
937
- error: p.error,
938
- onRetry: ce ? we : void 0
939
- }
940
- ) : null
941
- ]
942
- }
943
- ),
944
- We ? /* @__PURE__ */ a(
945
- "button",
946
- {
947
- "aria-label": "回到最新消息",
948
- className: "make-ai-assistant__back-to-latest",
949
- type: "button",
950
- onClick: Qe,
951
- children: /* @__PURE__ */ a(Rt, {})
952
- }
953
- ) : null,
954
- /* @__PURE__ */ i("footer", { className: "make-ai-assistant__composer-region", children: [
955
- V === "ready" && Ie.length > 0 && p.messages.length === 0 ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__suggestions", "aria-label": "推荐问题", children: Ie.map((n, f) => /* @__PURE__ */ a(
956
- "button",
957
- {
958
- type: "button",
959
- onClick: () => {
960
- oe(n);
961
- },
962
- children: n
963
- },
964
- `${f}-${n}`
965
- )) }) : null,
966
- /* @__PURE__ */ i("form", { className: "make-ai-assistant__composer", onSubmit: tt, children: [
967
- /* @__PURE__ */ a(
968
- "textarea",
969
- {
970
- "aria-label": `向 ${e} 提问`,
971
- "aria-describedby": C ? "make-ai-composer-error" : void 0,
972
- "aria-invalid": C ? !0 : void 0,
973
- autoFocus: !0,
974
- disabled: V !== "ready" || p.status === "streaming",
975
- placeholder: `询问当前 ${s.app.name ?? "App"} 中的数据…`,
976
- rows: 2,
977
- value: m,
978
- onChange: (n) => {
979
- b(n.currentTarget.value), $(void 0);
980
- },
981
- onKeyDown: at
982
- }
983
- ),
984
- p.status === "streaming" ? /* @__PURE__ */ a(
985
- "button",
986
- {
987
- "aria-label": rt,
988
- className: "make-ai-assistant__send make-ai-assistant__send--stop",
989
- type: "button",
990
- onClick: st,
991
- children: /* @__PURE__ */ a("span", { "aria-hidden": "true" })
992
- }
993
- ) : /* @__PURE__ */ a(
994
- "button",
995
- {
996
- "aria-label": "发送",
997
- className: "make-ai-assistant__send",
998
- disabled: V !== "ready" || !m.trim(),
999
- type: "submit",
1000
- children: /* @__PURE__ */ a(Lt, {})
1001
- }
1002
- )
1003
- ] }),
1004
- C ? /* @__PURE__ */ a("p", { id: "make-ai-composer-error", role: "alert", children: C }) : null,
1005
- /* @__PURE__ */ a("p", { children: "AI 生成的结果可能存在偏差,重要数据请核对明细。" })
1006
- ] })
1007
- ] });
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
+ );
1008
1067
  }
1009
- function Qt({
1068
+ function ra(e) {
1069
+ return /* @__PURE__ */ a(at, { ...e, visible: !0 });
1070
+ }
1071
+ function ia({
1010
1072
  defaultOpen: e = !1,
1011
1073
  hideLauncher: t = !1,
1012
1074
  launcher: s,
1013
- onOpenChange: r,
1014
- open: o,
1015
- ...c
1075
+ onOpenChange: n,
1076
+ open: r,
1077
+ ...o
1016
1078
  }) {
1017
- const d = He(c.brandName, c.title), [u, h] = R(e), k = x(null), _ = o ?? u, L = (M) => {
1018
- o === void 0 && h(M), r?.(M), M || requestAnimationFrame(() => k.current?.focus());
1019
- }, y = () => L(!_);
1020
- return fe(() => {
1021
- if (!_) return;
1022
- const M = (W) => {
1023
- W.key === "Escape" && (L(!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()));
1024
1090
  };
1025
- return document.addEventListener("keydown", M), () => document.removeEventListener("keydown", M);
1026
- }, [r, _]), /* @__PURE__ */ i("div", { className: "make-ai-assistant", "data-open": _ || void 0, children: [
1027
- !t && (!_ || s) ? s ? s({ open: _, toggle: y }) : /* @__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(
1028
1094
  "button",
1029
1095
  {
1030
- "aria-label": _ ? `关闭 ${d}` : `打开 ${d}`,
1031
- "aria-expanded": _,
1096
+ "aria-label": m ? `关闭 ${d}` : `打开 ${d}`,
1097
+ "aria-expanded": m,
1032
1098
  className: "make-ai-assistant__launcher",
1033
- ref: k,
1099
+ ref: $,
1034
1100
  type: "button",
1035
- onClick: y,
1101
+ onClick: z,
1036
1102
  children: [
1037
1103
  /* @__PURE__ */ a("span", { className: "make-ai-assistant__launcher-orbit", "aria-hidden": "true" }),
1038
- /* @__PURE__ */ a(Ke, {})
1104
+ /* @__PURE__ */ a(We, {})
1039
1105
  ]
1040
1106
  }
1041
1107
  ) : null,
1042
- _ ? /* @__PURE__ */ a(
1108
+ b ? /* @__PURE__ */ a(
1043
1109
  "aside",
1044
1110
  {
1045
1111
  "aria-label": d,
1046
1112
  "aria-modal": "false",
1047
1113
  className: "make-ai-assistant__drawer",
1114
+ hidden: !m,
1048
1115
  role: "dialog",
1049
- children: /* @__PURE__ */ a(Zt, { ...c, onClose: () => L(!1) })
1116
+ children: /* @__PURE__ */ a(
1117
+ at,
1118
+ {
1119
+ ...o,
1120
+ onClose: () => B(!1),
1121
+ visible: m
1122
+ }
1123
+ )
1050
1124
  }
1051
1125
  ) : null
1052
1126
  ] });
1053
1127
  }
1054
1128
  export {
1055
- pt as ArtifactRenderer,
1056
- Zt as AssistantPanel,
1057
- sa as MAKE_AI_ARTIFACT_KINDS,
1058
- na as MAKE_AI_ARTIFACT_LIMITS,
1059
- ra as MAKE_AI_ARTIFACT_SCHEMA_VERSION,
1060
- I as MAKE_AI_CONVERSATION_LIMITS,
1061
- Qt as MakeAiAssistant,
1062
- mt as appendUserMessage,
1063
- dt as createArtifactCapabilities,
1064
- Ue as createArtifactTemplateRegistry,
1065
- pe as createAssistantConversationState,
1066
- It as createPlatformArtifactRegistry,
1067
- ta as extendArtifactTemplateRegistry,
1068
- D as formatArtifactValue,
1069
- ia as parseArtifact,
1070
- ut as parseAssistantEvent,
1071
- bt as platformArtifactTemplates,
1072
- he as reduceAssistantEvent,
1073
- lt as resolveArtifactTemplate,
1074
- oa 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
1075
1149
  };