@qfei-design/make-ai-assistant 0.2.3 → 0.2.5

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