@qfei-design/make-ai-assistant 0.2.12 → 0.2.13

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,11 +1,12 @@
1
- import { jsxs as c, jsx as a, Fragment as Ce } from "react/jsx-runtime";
2
- import { isValidElement as ea, cloneElement as ta, useRef as N, useState as E, useEffect as oe, useLayoutEffect as Ft, useId as aa, useMemo as Ct } from "react";
3
- import { resolveArtifactTemplate as sa, createArtifactTemplateRegistry as Pt, createArtifactCapabilities as na } from "./index.mjs";
4
- import { extendArtifactTemplateRegistry as vs } from "./index.mjs";
5
- import { n as pe, k as ut, r as Ne, l as Bt, o as zt, c as it, M as ue } from "./conversation-CZfbgCXd.js";
6
- import { q as ys, s as bs, t as ks, u as _s, v as ws } from "./conversation-CZfbgCXd.js";
7
- const Wt = (e) => e?.trim() || void 0, _e = (e, t) => Wt(e) ?? t, ft = (e) => {
8
- const t = Wt(e?.primary);
1
+ import { jsxs as l, jsx as a, Fragment as Ne } from "react/jsx-runtime";
2
+ import { isValidElement as na, cloneElement as ra, useRef as S, useState as N, useEffect as ie, useLayoutEffect as gt, useId as ia, useMemo as Rt } from "react";
3
+ import { resolveArtifactTemplate as oa, createArtifactTemplateRegistry as Wt, createArtifactCapabilities as ca } from "./index.mjs";
4
+ import { extendArtifactTemplateRegistry as Cs } from "./index.mjs";
5
+ import { n as fe, k as ht, r as Me, l as Ot, o as Ht, c as it, M as ue } from "./conversation-CZfbgCXd.js";
6
+ import { q as Rs, s as Es, t as Ss, u as Ls, v as $s } from "./conversation-CZfbgCXd.js";
7
+ import { createPortal as la } from "react-dom";
8
+ const qt = (e) => e?.trim() || void 0, _e = (e, t) => qt(e) ?? t, yt = (e) => {
9
+ const t = qt(e?.primary);
9
10
  if (t)
10
11
  return {
11
12
  "--make-ai-theme-primary": t,
@@ -50,72 +51,72 @@ const Wt = (e) => e?.trim() || void 0, _e = (e, t) => Wt(e) ?? t, ft = (e) => {
50
51
  "#fcfcff"
51
52
  )
52
53
  };
53
- }, Tt = (e, t) => !t || !ea(e) || typeof e.type != "string" ? e : ta(e, {
54
+ }, Et = (e, t) => !t || !na(e) || typeof e.type != "string" ? e : ra(e, {
54
55
  style: { ...e.props.style, ...t }
55
56
  });
56
- function ra({
57
+ function da({
57
58
  artifact: e,
58
59
  context: t,
59
60
  fallback: s,
60
61
  onAction: i,
61
- onActionError: r,
62
- registry: o,
62
+ onActionError: o,
63
+ registry: c,
63
64
  theme: d
64
65
  }) {
65
- const p = ft(d), v = sa(o, e, t);
66
- if (!v) {
67
- const F = s ? s(e) : /* @__PURE__ */ c("section", { className: "make-ai-artifact make-ai-artifact--unsupported", role: "status", children: [
66
+ const h = yt(d), b = oa(c, e, t);
67
+ if (!b) {
68
+ const L = s ? s(e) : /* @__PURE__ */ l("section", { className: "make-ai-artifact make-ai-artifact--unsupported", role: "status", children: [
68
69
  /* @__PURE__ */ a("strong", { children: "暂不支持展示此结果" }),
69
- /* @__PURE__ */ c("span", { children: [
70
+ /* @__PURE__ */ l("span", { children: [
70
71
  "结果类型:",
71
72
  e.kind
72
73
  ] })
73
74
  ] });
74
- return Tt(F, p);
75
+ return Et(L, h);
75
76
  }
76
- const h = {
77
+ const f = {
77
78
  context: t,
78
79
  onAction: i,
79
- onActionError: r,
80
+ onActionError: o,
80
81
  theme: d,
81
- themeStyle: p
82
- }, _ = v.template.render(e, t, h);
83
- return Tt(_, p);
82
+ themeStyle: h
83
+ }, $ = b.template.render(e, t, f);
84
+ return Et($, h);
84
85
  }
85
- const Se = (e, t, s) => {
86
+ const $e = (e, t, s) => {
86
87
  if (e == null || e === "") return "—";
87
88
  if (typeof e == "boolean") return e ? "是" : "否";
88
89
  if (typeof e != "number") return `${e}${t?.unit ?? ""}`;
89
- const i = t?.precision, r = {
90
+ const i = t?.precision, o = {
90
91
  maximumFractionDigits: i ?? 2,
91
92
  minimumFractionDigits: i
92
93
  };
93
- t?.style === "currency" && t.currency ? (r.style = "currency", r.currency = t.currency) : t?.style === "percent" && (r.style = "percent");
94
+ t?.style === "currency" && t.currency ? (o.style = "currency", o.currency = t.currency) : t?.style === "percent" && (o.style = "percent");
94
95
  try {
95
- const o = t?.style === "percent" ? e / 100 : e;
96
- return `${new Intl.NumberFormat(s, r).format(o)}${t?.unit ?? ""}`;
96
+ const c = t?.style === "percent" ? e / 100 : e;
97
+ return `${new Intl.NumberFormat(s, o).format(c)}${t?.unit ?? ""}`;
97
98
  } catch {
98
99
  return `${e}${t?.unit ?? ""}`;
99
100
  }
100
- }, Ut = (e) => {
101
+ }, Kt = (e) => {
101
102
  let t = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
102
103
  for (const i of e)
103
104
  t = Math.min(t, i), s = Math.max(s, i);
104
105
  return Number.isFinite(t) && Number.isFinite(s) ? { min: t, max: s } : { min: 0, max: 0 };
105
- }, Ot = (e, t, s) => {
106
+ }, jt = (e, t, s) => {
106
107
  if (!s.onAction) return;
107
- const i = (o) => {
108
+ const i = (c) => {
108
109
  console.error("[make-ai-assistant] host action error handler failed", {
109
110
  actionId: e.id,
110
111
  artifactId: t.artifact.id,
111
- errorType: o instanceof Error ? o.name : typeof o,
112
+ errorType: c instanceof Error ? c.name : typeof c,
112
113
  intent: e.intent
113
114
  });
114
- }, r = (o) => {
115
+ }, o = (c) => {
115
116
  if (s.onActionError) {
116
117
  try {
117
118
  Promise.resolve(
118
- s.onActionError(o, e, t)
119
+ s.onActionError(c, e, t)
119
120
  ).catch(i);
120
121
  } catch (d) {
121
122
  i(d);
@@ -125,28 +126,28 @@ const Se = (e, t, s) => {
125
126
  console.error("[make-ai-assistant] host action failed", {
126
127
  actionId: e.id,
127
128
  artifactId: t.artifact.id,
128
- errorType: o instanceof Error ? o.name : typeof o,
129
+ errorType: c instanceof Error ? c.name : typeof c,
129
130
  intent: e.intent
130
131
  });
131
132
  };
132
133
  try {
133
- Promise.resolve(s.onAction(e, t)).catch(r);
134
- } catch (o) {
135
- r(o);
134
+ Promise.resolve(s.onAction(e, t)).catch(o);
135
+ } catch (c) {
136
+ o(c);
136
137
  }
137
- }, Pe = (e, t) => e.actions?.length && t.onAction ? /* @__PURE__ */ a("div", { className: "make-ai-artifact__actions", children: e.actions.map((s) => /* @__PURE__ */ c(
138
+ }, ze = (e, t) => e.actions?.length && t.onAction ? /* @__PURE__ */ a("div", { className: "make-ai-artifact__actions", children: e.actions.map((s) => /* @__PURE__ */ l(
138
139
  "button",
139
140
  {
140
141
  className: `make-ai-artifact__action make-ai-artifact__action--${s.appearance ?? "link"}`,
141
142
  type: "button",
142
- onClick: () => Ot(s, { artifact: e, context: t.context }, t),
143
+ onClick: () => jt(s, { artifact: e, context: t.context }, t),
143
144
  children: [
144
145
  s.label,
145
146
  /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "→" })
146
147
  ]
147
148
  },
148
149
  s.id
149
- )) }) : null, Be = (e, t, s = "", i) => /* @__PURE__ */ c(
150
+ )) }) : null, We = (e, t, s = "", i) => /* @__PURE__ */ l(
150
151
  "section",
151
152
  {
152
153
  "aria-label": e.title ?? `${e.kind} result`,
@@ -160,24 +161,24 @@ const Se = (e, t, s) => {
160
161
  t
161
162
  ]
162
163
  }
163
- ), ia = ({
164
+ ), ua = ({
164
165
  artifact: e,
165
166
  renderContext: t
166
167
  }) => {
167
- const s = e.data.delta, i = s ? Se(
168
+ const s = e.data.delta, i = s ? $e(
168
169
  s.value,
169
170
  s.format === "percent" ? { style: "percent" } : void 0,
170
171
  t.context.locale
171
172
  ) : void 0;
172
- return Be(
173
+ return We(
173
174
  e,
174
- /* @__PURE__ */ c(Ce, { children: [
175
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__metric-value", children: Se(
175
+ /* @__PURE__ */ l(Ne, { children: [
176
+ /* @__PURE__ */ a("div", { className: "make-ai-artifact__metric-value", children: $e(
176
177
  e.data.value,
177
178
  e.data.format,
178
179
  t.context.locale
179
180
  ) }),
180
- s ? /* @__PURE__ */ c(
181
+ s ? /* @__PURE__ */ l(
181
182
  "div",
182
183
  {
183
184
  className: `make-ai-artifact__delta make-ai-artifact__delta--${s.direction ?? "flat"}`,
@@ -189,112 +190,112 @@ const Se = (e, t, s) => {
189
190
  }
190
191
  ) : null,
191
192
  e.data.context ? /* @__PURE__ */ a("p", { className: "make-ai-artifact__context", children: e.data.context }) : null,
192
- Pe(e, t)
193
+ ze(e, t)
193
194
  ] }),
194
195
  "make-ai-artifact--metric",
195
196
  t.themeStyle
196
197
  );
197
- }, oa = ({
198
+ }, ma = ({
198
199
  artifact: e,
199
200
  renderContext: t
200
- }) => Be(
201
+ }) => We(
201
202
  e,
202
- /* @__PURE__ */ c(Ce, { children: [
203
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__comparison", children: e.data.items.map((s) => /* @__PURE__ */ c("div", { className: "make-ai-artifact__comparison-item", children: [
203
+ /* @__PURE__ */ l(Ne, { children: [
204
+ /* @__PURE__ */ a("div", { className: "make-ai-artifact__comparison", children: e.data.items.map((s) => /* @__PURE__ */ l("div", { className: "make-ai-artifact__comparison-item", children: [
204
205
  /* @__PURE__ */ a("span", { children: s.label }),
205
- /* @__PURE__ */ a("strong", { children: Se(s.value, s.format, t.context.locale) }),
206
+ /* @__PURE__ */ a("strong", { children: $e(s.value, s.format, t.context.locale) }),
206
207
  s.hint ? /* @__PURE__ */ a("small", { children: s.hint }) : null
207
208
  ] }, s.id)) }),
208
- Pe(e, t)
209
+ ze(e, t)
209
210
  ] }),
210
211
  "make-ai-artifact--comparison",
211
212
  t.themeStyle
212
- ), ca = ({
213
+ ), ha = ({
213
214
  artifact: e,
214
215
  renderContext: t
215
216
  }) => {
216
- const s = e.data.series.flatMap((d) => d.points.map((p) => p.y)), { max: i, min: r } = Ut(s), o = i - r || 1;
217
- return Be(
217
+ const s = e.data.series.flatMap((d) => d.points.map((h) => h.y)), { max: i, min: o } = Kt(s), c = i - o || 1;
218
+ return We(
218
219
  e,
219
- /* @__PURE__ */ c(Ce, { children: [
220
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend", children: e.data.series.map((d) => /* @__PURE__ */ c("div", { className: "make-ai-artifact__trend-series", children: [
220
+ /* @__PURE__ */ l(Ne, { children: [
221
+ /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend", children: e.data.series.map((d) => /* @__PURE__ */ l("div", { className: "make-ai-artifact__trend-series", children: [
221
222
  /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-label", children: d.label }),
222
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-bars", children: d.points.map((p, v) => {
223
- const h = 18 + (p.y - r) / o * 70;
224
- return /* @__PURE__ */ c("div", { className: "make-ai-artifact__trend-point", children: [
223
+ /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-bars", children: d.points.map((h, b) => {
224
+ const f = 18 + (h.y - o) / c * 70;
225
+ return /* @__PURE__ */ l("div", { className: "make-ai-artifact__trend-point", children: [
225
226
  /* @__PURE__ */ a(
226
227
  "span",
227
228
  {
228
- "aria-label": `${p.x}: ${Se(
229
- p.y,
229
+ "aria-label": `${h.x}: ${$e(
230
+ h.y,
230
231
  d.format,
231
232
  t.context.locale
232
233
  )}`,
233
234
  className: "make-ai-artifact__trend-bar",
234
235
  role: "img",
235
- style: { height: `${h}%` },
236
- title: `${p.x}: ${Se(
237
- p.y,
236
+ style: { height: `${f}%` },
237
+ title: `${h.x}: ${$e(
238
+ h.y,
238
239
  d.format,
239
240
  t.context.locale
240
241
  )}`
241
242
  }
242
243
  ),
243
- /* @__PURE__ */ a("small", { children: p.x })
244
- ] }, `${p.x}-${v}`);
244
+ /* @__PURE__ */ a("small", { children: h.x })
245
+ ] }, `${h.x}-${b}`);
245
246
  }) })
246
247
  ] }, d.id)) }),
247
- Pe(e, t)
248
+ ze(e, t)
248
249
  ] }),
249
250
  "make-ai-artifact--trend",
250
251
  t.themeStyle
251
252
  );
252
- }, la = ({
253
+ }, pa = ({
253
254
  artifact: e,
254
255
  renderContext: t
255
256
  }) => {
256
- const { max: s } = Ut(
257
- e.data.items.map((r) => Math.abs(r.value))
257
+ const { max: s } = Kt(
258
+ e.data.items.map((o) => Math.abs(o.value))
258
259
  ), i = Math.max(s, 1);
259
- return Be(
260
+ return We(
260
261
  e,
261
- /* @__PURE__ */ c(Ce, { children: [
262
- /* @__PURE__ */ a("ol", { className: "make-ai-artifact__ranking", children: e.data.items.map((r, o) => /* @__PURE__ */ c("li", { children: [
263
- /* @__PURE__ */ a("span", { className: "make-ai-artifact__rank", children: o + 1 }),
264
- /* @__PURE__ */ c("span", { className: "make-ai-artifact__ranking-label", children: [
265
- /* @__PURE__ */ a("span", { children: r.label }),
266
- r.description ? /* @__PURE__ */ a("small", { children: r.description }) : null
262
+ /* @__PURE__ */ l(Ne, { children: [
263
+ /* @__PURE__ */ a("ol", { className: "make-ai-artifact__ranking", children: e.data.items.map((o, c) => /* @__PURE__ */ l("li", { children: [
264
+ /* @__PURE__ */ a("span", { className: "make-ai-artifact__rank", children: c + 1 }),
265
+ /* @__PURE__ */ l("span", { className: "make-ai-artifact__ranking-label", children: [
266
+ /* @__PURE__ */ a("span", { children: o.label }),
267
+ o.description ? /* @__PURE__ */ a("small", { children: o.description }) : null
267
268
  ] }),
268
- /* @__PURE__ */ a("span", { className: "make-ai-artifact__ranking-track", "aria-hidden": "true", children: /* @__PURE__ */ a("span", { style: { width: `${Math.abs(r.value) / i * 100}%` } }) }),
269
- /* @__PURE__ */ a("strong", { children: Se(r.value, r.format, t.context.locale) })
270
- ] }, r.id)) }),
271
- Pe(e, t)
269
+ /* @__PURE__ */ a("span", { className: "make-ai-artifact__ranking-track", "aria-hidden": "true", children: /* @__PURE__ */ a("span", { style: { width: `${Math.abs(o.value) / i * 100}%` } }) }),
270
+ /* @__PURE__ */ a("strong", { children: $e(o.value, o.format, t.context.locale) })
271
+ ] }, o.id)) }),
272
+ ze(e, t)
272
273
  ] }),
273
274
  "make-ai-artifact--ranking",
274
275
  t.themeStyle
275
276
  );
276
- }, da = (e, t) => t.action ?? {
277
+ }, fa = (e, t) => t.action ?? {
277
278
  id: `open-${t.id}`,
278
279
  label: t.title ?? t.id,
279
280
  intent: "open-record",
280
281
  target: { entityKey: e.data.entity.key, recordId: t.id }
281
- }, ua = ({
282
+ }, va = ({
282
283
  artifact: e,
283
284
  renderContext: t
284
- }) => Be(
285
+ }) => We(
285
286
  e,
286
- /* @__PURE__ */ c(Ce, { children: [
287
+ /* @__PURE__ */ l(Ne, { children: [
287
288
  /* @__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) => {
288
- const i = da(e, s), r = /* @__PURE__ */ c(Ce, { children: [
289
+ const i = fa(e, s), o = /* @__PURE__ */ l(Ne, { children: [
289
290
  /* @__PURE__ */ a("strong", { children: s.title ?? s.id }),
290
- /* @__PURE__ */ a("span", { className: "make-ai-artifact__record-values", children: e.data.columns.map((o) => /* @__PURE__ */ c("span", { children: [
291
- /* @__PURE__ */ a("small", { children: o.label }),
292
- Se(
293
- s.values[o.key],
294
- o.format,
291
+ /* @__PURE__ */ a("span", { className: "make-ai-artifact__record-values", children: e.data.columns.map((c) => /* @__PURE__ */ l("span", { children: [
292
+ /* @__PURE__ */ a("small", { children: c.label }),
293
+ $e(
294
+ s.values[c.key],
295
+ c.format,
295
296
  t.context.locale
296
297
  )
297
- ] }, o.key)) }),
298
+ ] }, c.key)) }),
298
299
  t.onAction ? /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "›" }) : null
299
300
  ] });
300
301
  return t.onAction ? /* @__PURE__ */ a(
@@ -302,244 +303,254 @@ const Se = (e, t, s) => {
302
303
  {
303
304
  className: "make-ai-artifact__record",
304
305
  type: "button",
305
- onClick: () => Ot(i, {
306
+ onClick: () => jt(i, {
306
307
  artifact: e,
307
308
  context: t.context
308
309
  }, t),
309
- children: r
310
+ children: o
310
311
  },
311
312
  s.id
312
- ) : /* @__PURE__ */ a("div", { className: "make-ai-artifact__record", children: r }, s.id);
313
+ ) : /* @__PURE__ */ a("div", { className: "make-ai-artifact__record", children: o }, s.id);
313
314
  }) }),
314
- e.data.total !== void 0 ? /* @__PURE__ */ c("p", { className: "make-ai-artifact__record-total", children: [
315
+ e.data.total !== void 0 ? /* @__PURE__ */ l("p", { className: "make-ai-artifact__record-total", children: [
315
316
  "共 ",
316
317
  e.data.total,
317
318
  " 条"
318
319
  ] }) : null,
319
- Pe(e, t)
320
+ ze(e, t)
320
321
  ] }),
321
322
  "make-ai-artifact--record-list",
322
323
  t.themeStyle
323
- ), ma = ({
324
+ ), ga = ({
324
325
  artifact: e,
325
326
  renderContext: t
326
- }) => Be(
327
+ }) => We(
327
328
  e,
328
- /* @__PURE__ */ c(Ce, { children: [
329
- /* @__PURE__ */ c("div", { className: `make-ai-artifact__notice make-ai-artifact__notice--${e.data.tone}`, children: [
329
+ /* @__PURE__ */ l(Ne, { children: [
330
+ /* @__PURE__ */ l("div", { className: `make-ai-artifact__notice make-ai-artifact__notice--${e.data.tone}`, children: [
330
331
  /* @__PURE__ */ a("span", { "aria-hidden": "true", children: e.data.tone === "success" ? "✓" : e.data.tone === "warning" ? "!" : e.data.tone === "danger" ? "×" : "i" }),
331
332
  /* @__PURE__ */ a("p", { children: e.data.body })
332
333
  ] }),
333
- Pe(e, t)
334
+ ze(e, t)
334
335
  ] }),
335
336
  "make-ai-artifact--notice",
336
337
  t.themeStyle
337
- ), xe = (e, t, s) => ({ id: e, kinds: [t], priority: 0, render: s }), ha = [
338
- xe("platform.metric.default", "metric", (e, t, s) => /* @__PURE__ */ a(ia, { artifact: e, renderContext: s })),
339
- xe("platform.comparison.default", "comparison", (e, t, s) => /* @__PURE__ */ a(oa, { artifact: e, renderContext: s })),
340
- xe("platform.trend.default", "trend", (e, t, s) => /* @__PURE__ */ a(ca, { artifact: e, renderContext: s })),
341
- xe("platform.ranking.default", "ranking", (e, t, s) => /* @__PURE__ */ a(la, { artifact: e, renderContext: s })),
342
- xe("platform.record-list.default", "record-list", (e, t, s) => /* @__PURE__ */ a(ua, { artifact: e, renderContext: s })),
343
- xe("platform.notice.default", "notice", (e, t, s) => /* @__PURE__ */ a(ma, { artifact: e, renderContext: s }))
344
- ], pa = Pt(ha).templates, fa = (e = pa) => Pt(e), Fe = () => globalThis.crypto.randomUUID(), vt = (e) => {
338
+ ), Fe = (e, t, s) => ({ id: e, kinds: [t], priority: 0, render: s }), ya = [
339
+ Fe("platform.metric.default", "metric", (e, t, s) => /* @__PURE__ */ a(ua, { artifact: e, renderContext: s })),
340
+ Fe("platform.comparison.default", "comparison", (e, t, s) => /* @__PURE__ */ a(ma, { artifact: e, renderContext: s })),
341
+ Fe("platform.trend.default", "trend", (e, t, s) => /* @__PURE__ */ a(ha, { artifact: e, renderContext: s })),
342
+ Fe("platform.ranking.default", "ranking", (e, t, s) => /* @__PURE__ */ a(pa, { artifact: e, renderContext: s })),
343
+ Fe("platform.record-list.default", "record-list", (e, t, s) => /* @__PURE__ */ a(va, { artifact: e, renderContext: s })),
344
+ Fe("platform.notice.default", "notice", (e, t, s) => /* @__PURE__ */ a(ga, { artifact: e, renderContext: s }))
345
+ ], ba = Wt(ya).templates, ka = (e = ba) => Wt(e), Pe = () => globalThis.crypto.randomUUID(), bt = (e) => {
345
346
  const t = e, s = t?.status ?? t?.response?.status;
346
347
  return s === 409 ? "数据已变化或对话仍在运行,请刷新后重试" : s === 401 || t?.code === "AI_AUTH_REQUIRED" || t?.code === "AI_AUTH_EXPIRED" ? "登录已失效,请重新登录" : s === 403 ? "当前账号无权访问该对话" : s === 404 ? "对话或回答已不可见,请刷新列表" : t?.message?.startsWith("输入内容过长") ? t.message : "操作未完成,请重试或刷新对话";
347
348
  };
348
- function va(e, t) {
349
- const s = t.features?.conversationManagement === !0, i = s ? t.scopeKey?.(e) ?? e.app.id : "", r = N(i);
350
- r.current = i;
351
- const o = N(i), [d, p] = E(pe), v = N(d), h = (n) => {
352
- const m = typeof n == "function" ? n(v.current) : n;
353
- v.current = m, p(m);
354
- }, [_, F] = E([]), [A, X] = E(), C = N(void 0), [B, g] = E(""), [L, U] = E(-1), [f, l] = E(!1), [S, T] = E(!1), [te, R] = E(s), [Z, G] = E(!1), [P, Q] = E(), [fe, ve] = E([]), [z, ne] = E([]), ce = N(/* @__PURE__ */ new Set()), K = N(/* @__PURE__ */ new Map()), x = N(0), w = N(0), O = N(0), ae = N(void 0), ge = N(void 0), Ee = N(/* @__PURE__ */ new Map()), $ = (n, m = i) => w.current === n && r.current === m, ee = () => {
355
- const n = new AbortController();
356
- return ce.current.add(n), n;
357
- }, le = (n) => ce.current.delete(n), de = (n) => {
358
- C.current = n, X(n);
359
- }, ze = () => {
360
- for (const n of K.current.values()) n.abort();
361
- K.current.clear();
362
- }, Y = (n) => {
363
- n instanceof Error && n.name === "AbortError" || (console.warn("[make-ai-assistant] conversation operation failed", {
364
- errorType: n instanceof Error ? n.name : typeof n
365
- }), Q(vt(n)));
366
- }, re = async (n) => {
349
+ function _a(e, t) {
350
+ const s = t.features?.conversationManagement === !0, i = s ? t.scopeKey?.(e) ?? e.app.id : "", o = S(i);
351
+ o.current = i;
352
+ const c = S(i), [d, h] = N(fe), b = S(d), f = (r) => {
353
+ const u = typeof r == "function" ? r(b.current) : r;
354
+ b.current = u, h(u);
355
+ }, [$, L] = N([]), [T, j] = N(), M = S(void 0), [U, g] = N(""), [R, P] = N(-1), [p, n] = N(!1), [v, k] = N(!1), [q, I] = N(s), [G, Y] = N(!1), [z, Q] = N(), [ve, oe] = N([]), [F, ne] = N([]), ce = S(/* @__PURE__ */ new Set()), V = S(/* @__PURE__ */ new Map()), B = S(0), A = S(0), W = S(0), ae = S(void 0), ge = S(void 0), Re = S(/* @__PURE__ */ new Map()), x = (r, u = i) => A.current === r && o.current === u, ee = () => {
356
+ const r = new AbortController();
357
+ return ce.current.add(r), r;
358
+ }, le = (r) => ce.current.delete(r), de = (r) => {
359
+ M.current = r, j(r);
360
+ }, lt = (r) => {
361
+ L(
362
+ (u) => u.map((y) => y.chatId === r.chatId ? r : y)
363
+ );
364
+ }, ye = (r) => {
365
+ L(
366
+ (u) => u.filter((y) => y.chatId !== r)
367
+ );
368
+ }, we = () => {
369
+ W.current += 1;
370
+ }, be = () => {
371
+ for (const r of V.current.values()) r.abort();
372
+ V.current.clear();
373
+ }, te = (r) => {
374
+ r instanceof Error && r.name === "AbortError" || (console.warn("[make-ai-assistant] conversation operation failed", {
375
+ errorType: r instanceof Error ? r.name : typeof r
376
+ }), Q(bt(r)));
377
+ }, Ce = async (r) => {
367
378
  if (!s || !t.listConversations) return;
368
- const m = w.current, y = ++O.current, b = ee();
379
+ const u = A.current, y = ++W.current, w = ee();
369
380
  try {
370
- const I = await t.listConversations(
381
+ const C = await t.listConversations(
371
382
  e,
372
- { cursor: n },
373
- { signal: b.signal }
383
+ { cursor: r },
384
+ { signal: w.signal }
374
385
  );
375
- if (!$(m) || b.signal.aborted || y !== O.current)
386
+ if (!x(u) || w.signal.aborted || y !== W.current)
376
387
  return;
377
- F((D) => [
388
+ L((D) => [
378
389
  ...new Map(
379
- [...n ? D : [], ...I.chats].map((k) => [
380
- k.chatId,
381
- k
390
+ [...r ? D : [], ...C.chats].map((_) => [
391
+ _.chatId,
392
+ _
382
393
  ])
383
394
  ).values()
384
- ]), g(I.nextCursor);
385
- } catch (I) {
386
- $(m) && !b.signal.aborted && Y(I);
395
+ ]), g(C.nextCursor);
396
+ } catch (C) {
397
+ x(u) && !w.signal.aborted && y === W.current && te(C);
387
398
  } finally {
388
- le(b), $(m) && R(!1);
399
+ le(w), x(u) && y === W.current && I(!1);
389
400
  }
390
- }, me = async (n, m, y) => {
391
- const b = w.current, I = x.current;
401
+ }, ke = async (r, u, y) => {
402
+ const w = A.current, C = B.current;
392
403
  let D;
393
404
  try {
394
- for await (const k of n) {
395
- if (!$(b) || m.signal.aborted || I !== x.current || C.current?.chatId !== y)
405
+ for await (const _ of r) {
406
+ if (!x(w) || u.signal.aborted || C !== B.current || M.current?.chatId !== y)
396
407
  return;
397
- const V = Bt(k);
398
- if (V.type === "response.accepted" || V.type === "response.state") {
399
- D = V.responseId;
400
- const q = K.current.get(D);
401
- if (q && q !== m) {
402
- V.type === "response.accepted" && h((W) => Ne(W, V)), m.abort();
408
+ const Z = Ot(_);
409
+ if (Z.type === "response.accepted" || Z.type === "response.state") {
410
+ D = Z.responseId;
411
+ const O = V.current.get(D);
412
+ if (O && O !== u) {
413
+ Z.type === "response.accepted" && f((H) => Me(H, Z)), u.abort();
403
414
  return;
404
415
  }
405
- K.current.set(D, m);
416
+ V.current.set(D, u);
406
417
  }
407
- h((q) => Ne(q, V)), V.type === "response.terminal" && (ve((q) => q.filter((W) => W !== V.responseId)), re());
418
+ f((O) => Me(O, Z)), Z.type === "response.terminal" && (oe((O) => O.filter((H) => H !== Z.responseId)), Ce());
408
419
  }
409
- } catch (k) {
410
- $(b) && !m.signal.aborted && I === x.current && (Y(k), D || h((V) => ({
411
- ...V,
412
- status: Object.values(V.responses ?? {}).some(
413
- (q) => !ut(q.status)
420
+ } catch (_) {
421
+ x(w) && !u.signal.aborted && C === B.current && (te(_), D || f((Z) => ({
422
+ ...Z,
423
+ status: Object.values(Z.responses ?? {}).some(
424
+ (O) => !ht(O.status)
414
425
  ) ? "streaming" : "error"
415
426
  })));
416
427
  } finally {
417
- D && K.current.get(D) === m && K.current.delete(D), le(m);
428
+ D && V.current.get(D) === u && V.current.delete(D), le(u);
418
429
  }
419
- }, we = async (n, m, y, b) => {
430
+ }, Oe = async (r, u, y, w) => {
420
431
  if (!t.getResponse || !t.watchResponse) return;
421
- const I = new Set(
422
- n.filter((k) => k.role === "assistant" && k.persistent).map((k) => k.responseId)
432
+ const C = new Set(
433
+ r.filter((_) => _.role === "assistant" && _.persistent).map((_) => _.responseId)
423
434
  ), D = [
424
435
  ...new Map(
425
- n.filter(
426
- (k) => k.role === "user" && k.responseId && !I.has(k.responseId)
427
- ).map((k) => [k.responseId, k.cursor ?? -1])
436
+ r.filter(
437
+ (_) => _.role === "user" && _.responseId && !C.has(_.responseId)
438
+ ).map((_) => [_.responseId, _.cursor ?? -1])
428
439
  ).entries()
429
440
  ].slice(-20);
430
- for (const [k, V] of D) {
431
- if (!$(b) || y !== x.current) return;
432
- if (K.current.has(k)) continue;
433
- const q = ee();
441
+ for (const [_, Z] of D) {
442
+ if (!x(w) || y !== B.current) return;
443
+ if (V.current.has(_)) continue;
444
+ const O = ee();
434
445
  try {
435
- const W = await t.getResponse(
446
+ const H = await t.getResponse(
436
447
  e,
437
- { chatId: m, responseId: k },
438
- { signal: q.signal }
448
+ { chatId: u, responseId: _ },
449
+ { signal: O.signal }
439
450
  );
440
- if (!$(b) || q.signal.aborted || y !== x.current || K.current.has(k)) continue;
441
- h(
442
- (be) => Ne(
443
- be,
444
- ut(W.status) ? { type: "response.snapshot", snapshot: W } : {
451
+ if (!x(w) || O.signal.aborted || y !== B.current || V.current.has(_)) continue;
452
+ f(
453
+ (Ie) => Me(
454
+ Ie,
455
+ ht(H.status) ? { type: "response.snapshot", snapshot: H } : {
445
456
  type: "response.state",
446
- chatId: m,
447
- responseId: k,
448
- status: W.status
457
+ chatId: u,
458
+ responseId: _,
459
+ status: H.status
449
460
  }
450
461
  )
451
- ), W.status === "failed" || W.status === "cancelled" ? h(
452
- (be) => Ne(be, {
462
+ ), H.status === "failed" || H.status === "cancelled" ? f(
463
+ (Ie) => Me(Ie, {
453
464
  type: "response.terminal",
454
- chatId: m,
455
- responseId: k,
456
- status: W.status
465
+ chatId: u,
466
+ responseId: _,
467
+ status: H.status
457
468
  })
458
- ) : (K.current.set(k, q), me(
469
+ ) : (V.current.set(_, O), ke(
459
470
  t.watchResponse(
460
471
  e,
461
- { chatId: m, responseId: k, historyCursor: V },
462
- { signal: q.signal }
472
+ { chatId: u, responseId: _, historyCursor: Z },
473
+ { signal: O.signal }
463
474
  ),
464
- q,
465
- m
475
+ O,
476
+ u
466
477
  ));
467
- } catch (W) {
468
- $(b) && !q.signal.aborted && Y(W);
478
+ } catch (H) {
479
+ x(w) && !O.signal.aborted && te(H);
469
480
  } finally {
470
- K.current.get(k) !== q && le(q);
481
+ V.current.get(_) !== O && le(O);
471
482
  }
472
483
  }
473
- }, We = async (n) => {
474
- const m = ++x.current, y = w.current, b = ee();
475
- ze(), Q(void 0), R(!0), ve([]), ge.current = void 0, de(n), h({ messages: [], status: "idle", threadId: n.chatId }), U(-1), l(!1), T(!1);
484
+ }, He = async (r) => {
485
+ const u = ++B.current, y = A.current, w = ee();
486
+ be(), Q(void 0), I(!0), oe([]), ge.current = void 0, de(r), f({ messages: [], status: "idle", threadId: r.chatId }), P(-1), n(!1), k(!1);
476
487
  try {
477
- const [I, D] = await Promise.all([
488
+ const [C, D] = await Promise.all([
478
489
  t.getConversation(
479
490
  e,
480
- { chatId: n.chatId },
481
- { signal: b.signal }
491
+ { chatId: r.chatId },
492
+ { signal: w.signal }
482
493
  ),
483
494
  t.loadConversation(e, {
484
- threadId: n.chatId,
495
+ threadId: r.chatId,
485
496
  cursor: -1,
486
- signal: b.signal
497
+ signal: w.signal
487
498
  })
488
499
  ]);
489
- if (!$(y) || b.signal.aborted || m !== x.current)
500
+ if (!x(y) || w.signal.aborted || u !== B.current)
490
501
  return;
491
- if (I.chatId !== n.chatId || D.threadId !== n.chatId)
502
+ if (C.chatId !== r.chatId || D.threadId !== r.chatId)
492
503
  throw new Error("Conversation mismatch");
493
- de(I), h(pe(D)), U(D.nextCursor ?? -1), l(D.hasMore ?? !1), we(D.messages, n.chatId, m, y);
494
- } catch (I) {
495
- $(y) && !b.signal.aborted && m === x.current && Y(I);
504
+ de(C), f(fe(D)), P(D.nextCursor ?? -1), n(D.hasMore ?? !1), Oe(D.messages, r.chatId, u, y);
505
+ } catch (C) {
506
+ x(y) && !w.signal.aborted && u === B.current && te(C);
496
507
  } finally {
497
- le(b), $(y) && m === x.current && R(!1);
508
+ le(w), x(y) && u === B.current && I(!1);
498
509
  }
499
- }, Ie = async () => {
500
- if (C.current) return C.current;
501
- if (ae.current ??= { requestId: Fe() }, ae.current.promise) return ae.current.promise;
502
- const n = w.current, m = x.current, y = ee(), b = ae.current;
503
- return G(!0), b.promise = t.createConversation(
510
+ }, Ee = async () => {
511
+ if (M.current) return M.current;
512
+ if (ae.current ??= { requestId: Pe() }, ae.current.promise) return ae.current.promise;
513
+ const r = A.current, u = B.current, y = ee(), w = ae.current;
514
+ return Y(!0), w.promise = t.createConversation(
504
515
  e,
505
- { requestId: b.requestId },
516
+ { requestId: w.requestId },
506
517
  { signal: y.signal }
507
- ).then((I) => {
508
- if (!$(n) || y.signal.aborted || m !== x.current)
518
+ ).then((C) => {
519
+ if (!x(r) || y.signal.aborted || u !== B.current)
509
520
  throw Object.assign(new Error("Stale create"), {
510
521
  name: "AbortError"
511
522
  });
512
- return ae.current = void 0, de(I), h({ messages: [], status: "idle", threadId: I.chatId }), re(), I;
523
+ return ae.current = void 0, de(C), f({ messages: [], status: "idle", threadId: C.chatId }), Ce(), C;
513
524
  }).finally(() => {
514
- le(y), b.promise = void 0, $(n) && G(!1);
515
- }), b.promise;
516
- }, Ze = async () => {
517
- if (!(Z || ae.current?.promise)) {
518
- x.current += 1, ze(), de(void 0), Q(void 0), ge.current = void 0, h(pe()), l(!1), U(-1);
525
+ le(y), w.promise = void 0, x(r) && Y(!1);
526
+ }), w.promise;
527
+ }, Xe = async () => {
528
+ if (!(G || ae.current?.promise)) {
529
+ B.current += 1, be(), de(void 0), Q(void 0), ge.current = void 0, f(fe()), n(!1), P(-1);
519
530
  try {
520
- await Ie();
521
- } catch (n) {
522
- Y(n);
531
+ await Ee();
532
+ } catch (r) {
533
+ te(r);
523
534
  }
524
535
  }
525
- }, Ue = async (n) => {
526
- const m = ee();
527
- ge.current = n, Q(void 0), v.current.messages.some((y) => y.id === n.message.id) || h((y) => zt(y, n.message)), await me(
528
- t.run(n, { signal: m.signal }),
529
- m,
530
- n.threadId
536
+ }, me = async (r) => {
537
+ const u = ee();
538
+ ge.current = r, Q(void 0), b.current.messages.some((y) => y.id === r.message.id) || f((y) => Ht(y, r.message)), await ke(
539
+ t.run(r, { signal: u.signal }),
540
+ u,
541
+ r.threadId
531
542
  );
532
- }, Oe = async (n, m) => {
533
- if (!(!n.trim() && !m?.length))
543
+ }, Ge = async (r, u) => {
544
+ if (!(!r.trim() && !u?.length))
534
545
  try {
535
- const y = await Ie(), b = {
536
- id: Fe(),
537
- content: n,
538
- ...m ? { parts: m } : {}
546
+ const y = await Ee(), w = {
547
+ id: Pe(),
548
+ content: r,
549
+ ...u ? { parts: u } : {}
539
550
  };
540
- await Ue({
551
+ await me({
541
552
  threadId: y.chatId,
542
- message: b,
553
+ message: w,
543
554
  context: e,
544
555
  capabilities: {
545
556
  artifactSchemaVersions: [],
@@ -548,246 +559,310 @@ function va(e, t) {
548
559
  }
549
560
  });
550
561
  } catch (y) {
551
- Y(y);
562
+ te(y);
552
563
  }
553
- }, Ge = async () => {
554
- const n = ge.current;
555
- if (!n || n.threadId !== C.current?.chatId) {
556
- C.current && await We(C.current);
564
+ }, Ye = async () => {
565
+ const r = ge.current;
566
+ if (!r || r.threadId !== M.current?.chatId) {
567
+ M.current && await He(M.current);
557
568
  return;
558
569
  }
559
- const m = v.current.messages.find(
560
- (y) => y.id === n.message.id
570
+ const u = b.current.messages.find(
571
+ (y) => y.id === r.message.id
561
572
  );
562
- if (m?.responseId && t.watchResponse) {
563
- const y = m.responseId;
564
- if (K.current.has(y)) return;
565
- const b = ee();
566
- K.current.set(y, b), Q(void 0), await me(
573
+ if (u?.responseId && t.watchResponse) {
574
+ const y = u.responseId;
575
+ if (V.current.has(y)) return;
576
+ const w = ee();
577
+ V.current.set(y, w), Q(void 0), await ke(
567
578
  t.watchResponse(
568
579
  e,
569
580
  {
570
- chatId: n.threadId,
581
+ chatId: r.threadId,
571
582
  responseId: y,
572
- historyCursor: m.cursor
583
+ historyCursor: u.cursor
573
584
  },
574
- { signal: b.signal }
585
+ { signal: w.signal }
575
586
  ),
576
- b,
577
- n.threadId
587
+ w,
588
+ r.threadId
578
589
  );
579
- } else await Ue(n);
580
- }, ye = async (n = v.current.activeRunId) => {
581
- const m = C.current;
582
- if (!m || !n || !t.cancelResponse || fe.includes(n))
590
+ } else await me(r);
591
+ }, Je = async (r = b.current.activeRunId) => {
592
+ const u = M.current;
593
+ if (!u || !r || !t.cancelResponse || ve.includes(r))
583
594
  return;
584
- const y = w.current, b = x.current, I = ee();
585
- ve((D) => [...D, n]), Q(void 0);
595
+ const y = A.current, w = B.current, C = ee();
596
+ oe((D) => [...D, r]), Q(void 0);
586
597
  try {
587
598
  const D = await t.cancelResponse(
588
599
  e,
589
- { chatId: m.chatId, responseId: n },
590
- { signal: I.signal }
600
+ { chatId: u.chatId, responseId: r },
601
+ { signal: C.signal }
591
602
  );
592
- if (!$(y) || b !== x.current) return;
593
- if (ut(D.status))
594
- h(
595
- (k) => Ne(k, {
603
+ if (!x(y) || w !== B.current) return;
604
+ if (ht(D.status))
605
+ f(
606
+ (_) => Me(_, {
596
607
  type: "response.snapshot",
597
608
  snapshot: D
598
609
  })
599
- ), ve((k) => k.filter((V) => V !== n));
600
- else if (!K.current.has(n) && t.watchResponse) {
601
- const k = ee();
602
- K.current.set(n, k), me(
610
+ ), oe((_) => _.filter((Z) => Z !== r));
611
+ else if (!V.current.has(r) && t.watchResponse) {
612
+ const _ = ee();
613
+ V.current.set(r, _), ke(
603
614
  t.watchResponse(
604
615
  e,
605
- { chatId: m.chatId, responseId: n },
606
- { signal: k.signal }
616
+ { chatId: u.chatId, responseId: r },
617
+ { signal: _.signal }
607
618
  ),
608
- k,
609
- m.chatId
619
+ _,
620
+ u.chatId
610
621
  );
611
622
  }
612
623
  } catch (D) {
613
- $(y) && b === x.current && (Y(D), ve((k) => k.filter((V) => V !== n)));
624
+ x(y) && w === B.current && (te(D), oe((_) => _.filter((Z) => Z !== r)));
614
625
  } finally {
615
- le(I);
626
+ le(C);
616
627
  }
617
- }, Ye = async (n, m = C.current) => {
618
- if (!m || Z) return;
619
- const y = w.current, b = ee();
620
- G(!0), Q(void 0);
628
+ }, Qe = async (r, u = M.current) => {
629
+ if (!u || G) return !1;
630
+ const y = A.current, w = ee();
631
+ Y(!0), Q(void 0);
621
632
  try {
622
- const I = await t.updateConversation(
633
+ const C = await t.updateConversation(
623
634
  e,
624
- { chatId: m.chatId, expectedRevision: m.revision, ...n },
625
- { signal: b.signal }
635
+ { chatId: u.chatId, expectedRevision: u.revision, ...r },
636
+ { signal: w.signal }
626
637
  );
627
- if (!$(y)) return;
628
- C.current?.chatId === I.chatId && de(I), await re();
629
- } catch (I) {
630
- if ($(y)) {
631
- Y(I);
638
+ return x(y) ? (we(), lt(C), M.current?.chatId === C.chatId && de(C), !0) : !1;
639
+ } catch (C) {
640
+ if (x(y)) {
641
+ te(C);
632
642
  try {
633
643
  const D = await t.getConversation(
634
644
  e,
635
- { chatId: m.chatId },
636
- { signal: b.signal }
645
+ { chatId: u.chatId },
646
+ { signal: w.signal }
637
647
  );
638
- $(y) && C.current?.chatId === m.chatId && de(D);
648
+ x(y) && M.current?.chatId === u.chatId && de(D);
639
649
  } catch {
640
650
  }
641
- re();
651
+ Ce();
642
652
  }
653
+ return !1;
643
654
  } finally {
644
- le(b), $(y) && G(!1);
655
+ le(w), x(y) && Y(!1);
645
656
  }
646
- }, Je = async (n = C.current) => {
647
- if (!n || Z) return;
648
- const m = w.current, y = ee();
649
- G(!0), Q(void 0);
657
+ }, et = async (r = M.current) => {
658
+ if (!r || G) return !1;
659
+ const u = A.current, y = ee();
660
+ Y(!0), Q(void 0);
650
661
  try {
651
- if (await t.deleteConversation(
662
+ return await t.deleteConversation(
652
663
  e,
653
- { chatId: n.chatId, expectedRevision: n.revision },
664
+ { chatId: r.chatId, expectedRevision: r.revision },
654
665
  { signal: y.signal }
655
- ), !$(m)) return;
656
- C.current?.chatId === n.chatId && (x.current += 1, ze(), de(void 0), h(pe())), await re();
657
- } catch (b) {
658
- $(m) && Y(b);
666
+ ), x(u) ? (we(), ye(r.chatId), M.current?.chatId === r.chatId && (B.current += 1, be(), de(void 0), f(fe())), !0) : !1;
667
+ } catch (w) {
668
+ return x(u) && te(w), !1;
659
669
  } finally {
660
- le(y), $(m) && G(!1);
670
+ le(y), x(u) && Y(!1);
661
671
  }
662
- }, Qe = async (n, m, y = "", b = "") => {
663
- const I = C.current;
664
- if (!I || !n.persistent || !t.setFeedback || z.includes(n.id))
672
+ }, xe = async (r, u, y = "", w = "") => {
673
+ const C = M.current;
674
+ if (!C || !r.persistent || !t.setFeedback || F.includes(r.id))
665
675
  return;
666
676
  const D = {
667
- chatId: I.chatId,
668
- messageId: n.id,
669
- rating: m,
677
+ chatId: C.chatId,
678
+ messageId: r.id,
679
+ rating: u,
670
680
  ...y ? { reason: y } : {},
671
- ...b ? { comment: b } : {}
672
- }, k = Ee.current.get(n.id), { requestId: V, ...q } = k ?? {
681
+ ...w ? { comment: w } : {}
682
+ }, _ = Re.current.get(r.id), { requestId: Z, ...O } = _ ?? {
673
683
  requestId: ""
674
- }, W = k && JSON.stringify(q) === JSON.stringify(D) ? k : { ...D, requestId: Fe() };
675
- Ee.current.set(n.id, W);
676
- const be = w.current, qe = x.current, tt = ee();
677
- ne((ke) => [...ke, n.id]), Q(void 0);
684
+ }, H = _ && JSON.stringify(O) === JSON.stringify(D) ? _ : { ...D, requestId: Pe() };
685
+ Re.current.set(r.id, H);
686
+ const Ie = A.current, Le = B.current, tt = ee();
687
+ ne((he) => [...he, r.id]), Q(void 0);
678
688
  try {
679
- const ke = await t.setFeedback(e, W, {
689
+ const he = await t.setFeedback(e, H, {
680
690
  signal: tt.signal
681
691
  });
682
- return !$(be) || qe !== x.current || Ee.current.get(n.id) !== W ? void 0 : (h((Ae) => ({
683
- ...Ae,
684
- messages: Ae.messages.map(
685
- ($e) => $e.id === n.id && ke.revision >= ($e.feedback?.revision ?? 0) ? { ...$e, feedback: ke } : $e
692
+ return !x(Ie) || Le !== B.current || Re.current.get(r.id) !== H ? void 0 : (f((De) => ({
693
+ ...De,
694
+ messages: De.messages.map(
695
+ (m) => m.id === r.id && he.revision >= (m.feedback?.revision ?? 0) ? { ...m, feedback: he } : m
686
696
  )
687
- })), Ee.current.delete(n.id), !0);
688
- } catch (ke) {
689
- return $(be) && qe === x.current && Y(ke), !1;
697
+ })), Re.current.delete(r.id), !0);
698
+ } catch (he) {
699
+ return x(Ie) && Le === B.current && te(he), !1;
690
700
  } finally {
691
- le(tt), $(be) && ne((ke) => ke.filter((Ae) => Ae !== n.id));
701
+ le(tt), x(Ie) && ne((he) => he.filter((De) => De !== r.id));
692
702
  }
693
- }, et = async () => {
694
- if (!C.current || !f || te) return;
695
- const n = w.current, m = x.current, y = C.current, b = ee();
696
- R(!0);
703
+ }, dt = async () => {
704
+ if (!M.current || !p || q) return;
705
+ const r = A.current, u = B.current, y = M.current, w = ee();
706
+ I(!0);
697
707
  try {
698
- const I = await t.loadConversation(e, {
708
+ const C = await t.loadConversation(e, {
699
709
  threadId: y.chatId,
700
- cursor: L,
701
- signal: b.signal
710
+ cursor: R,
711
+ signal: w.signal
702
712
  });
703
- if (!$(n) || m !== x.current) return;
704
- const D = pe(I), k = [
713
+ if (!x(r) || u !== B.current) return;
714
+ const D = fe(C), _ = [
705
715
  ...new Map(
706
- [...v.current.messages, ...D.messages].map((W) => [
707
- W.id,
708
- W
716
+ [...b.current.messages, ...D.messages].map((H) => [
717
+ H.id,
718
+ H
709
719
  ])
710
720
  ).values()
711
721
  ];
712
- let V = 0;
713
- const q = [];
714
- for (const W of k.slice(-200).reverse()) {
715
- if (V += [...W.content].length, V > 1e6) break;
716
- q.unshift(W);
722
+ let Z = 0;
723
+ const O = [];
724
+ for (const H of _.slice(-200).reverse()) {
725
+ if (Z += [...H.content].length, Z > 1e6) break;
726
+ O.unshift(H);
717
727
  }
718
- q.length < k.length && T(!0), h((W) => ({ ...W, messages: q })), U(I.nextCursor ?? L), l(I.hasMore ?? !1), we(I.messages, y.chatId, m, n);
719
- } catch (I) {
720
- $(n) && Y(I);
728
+ O.length < _.length && k(!0), f((H) => ({ ...H, messages: O })), P(C.nextCursor ?? R), n(C.hasMore ?? !1), Oe(C.messages, y.chatId, u, r);
729
+ } catch (C) {
730
+ x(r) && te(C);
721
731
  } finally {
722
- le(b), $(n) && R(!1);
732
+ le(w), x(r) && I(!1);
723
733
  }
724
734
  };
725
- oe(() => (w.current += 1, o.current = i, ae.current = void 0, ge.current = void 0, Ee.current.clear(), de(void 0), F([]), g(""), h(pe()), Q(void 0), R(s), G(!1), ve([]), ne([]), s && re(), () => {
726
- w.current += 1, x.current += 1;
727
- for (const n of ce.current) n.abort();
728
- ce.current.clear(), K.current.clear();
735
+ ie(() => (A.current += 1, c.current = i, ae.current = void 0, ge.current = void 0, Re.current.clear(), de(void 0), L([]), g(""), f(fe()), Q(void 0), I(s), Y(!1), oe([]), ne([]), s && Ce(), () => {
736
+ A.current += 1, B.current += 1;
737
+ for (const r of ce.current) r.abort();
738
+ ce.current.clear(), V.current.clear();
729
739
  }), [s, i, t]);
730
- const Te = o.current === i;
740
+ const Se = c.current === i;
731
741
  return {
732
742
  enabled: s,
733
- state: Te ? d : pe(),
734
- setState: h,
735
- chats: Te ? _ : [],
736
- chat: Te ? A : void 0,
737
- listCursor: B,
738
- historyMore: f,
739
- historyTruncated: S,
740
- loading: !Te || te,
741
- busy: Z,
742
- error: Te ? P : void 0,
743
- cancelling: fe,
744
- feedbackBusy: z,
745
- refresh: re,
746
- select: We,
747
- create: Ze,
748
- ensureChat: Ie,
749
- send: Oe,
750
- retry: Ge,
751
- stop: ye,
752
- update: Ye,
753
- remove: Je,
754
- feedback: Qe,
755
- moreHistory: et,
743
+ state: Se ? d : fe(),
744
+ setState: f,
745
+ chats: Se ? $ : [],
746
+ chat: Se ? T : void 0,
747
+ listCursor: U,
748
+ historyMore: p,
749
+ historyTruncated: v,
750
+ loading: !Se || q,
751
+ busy: G,
752
+ error: Se ? z : void 0,
753
+ cancelling: ve,
754
+ feedbackBusy: F,
755
+ refresh: Ce,
756
+ select: He,
757
+ create: Xe,
758
+ ensureChat: Ee,
759
+ send: Ge,
760
+ retry: Ye,
761
+ stop: Je,
762
+ update: Qe,
763
+ remove: et,
764
+ feedback: xe,
765
+ moreHistory: dt,
756
766
  setError: Q
757
767
  };
758
768
  }
759
- const ga = () => /* @__PURE__ */ c("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
769
+ const wa = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
760
770
  /* @__PURE__ */ a("path", { d: "M5 5.5h14v10H9l-4 3v-13Z" }),
761
771
  /* @__PURE__ */ a("path", { d: "M8 9h8M8 12h6" })
762
- ] }), ya = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "M12 5v14M5 12h14" }) });
763
- function ba({
772
+ ] }), Ia = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "M12 5v14M5 12h14" }) }), Aa = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
773
+ /* @__PURE__ */ a("path", { d: "m4.5 16.8-.7 3.7 3.7-.7L18 9.3l-3-3L4.5 16.8Z" }),
774
+ /* @__PURE__ */ a("path", { d: "m13.8 7.5 3 3" })
775
+ ] }), Ma = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "M5.5 7.5h13M9.5 7.5V5.7h5v1.8M8 10.5v6M12 10.5v6M16 10.5v6M7 7.5l.7 12h8.6l.7-12" }) }), St = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m5 12.5 4.5 4.5L19 7.5" }) }), Lt = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m6 6 12 12M18 6 6 18" }) }), Na = ({
776
+ anchor: e,
777
+ label: t,
778
+ onDismiss: s
779
+ }) => {
780
+ const [i, o] = N();
781
+ if (gt(() => {
782
+ const d = () => {
783
+ if (!e.isConnected) {
784
+ s();
785
+ return;
786
+ }
787
+ const h = e.getBoundingClientRect(), b = h.top >= 48 ? "above" : "below";
788
+ o({
789
+ left: h.left + h.width / 2,
790
+ placement: b,
791
+ top: b === "above" ? h.top - 8 : h.bottom + 8
792
+ });
793
+ };
794
+ return d(), window.addEventListener("resize", d), document.addEventListener("scroll", d, !0), () => {
795
+ window.removeEventListener("resize", d), document.removeEventListener("scroll", d, !0);
796
+ };
797
+ }, [e, s]), !i || typeof document > "u") return null;
798
+ const c = e.closest(".make-ai-assistant") ?? document.body;
799
+ return la(
800
+ /* @__PURE__ */ a(
801
+ "span",
802
+ {
803
+ className: "make-ai-assistant__conversation-tooltip",
804
+ "data-placement": i.placement,
805
+ role: "tooltip",
806
+ style: { left: i.left, top: i.top },
807
+ children: t
808
+ }
809
+ ),
810
+ c
811
+ );
812
+ }, Ca = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
813
+ /* @__PURE__ */ a("path", { d: "M7.5 10.5v9H4.8a1.8 1.8 0 0 1-1.8-1.8v-5.4a1.8 1.8 0 0 1 1.8-1.8h2.7Z" }),
814
+ /* @__PURE__ */ a("path", { d: "M7.5 19.5h8.1a2.4 2.4 0 0 0 2.3-1.8l1.4-5.4a1.5 1.5 0 0 0-1.5-1.8h-4.1l.7-3.4A2.4 2.4 0 0 0 12 4.2L7.5 10.5Z" })
815
+ ] }), Ta = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
816
+ /* @__PURE__ */ a("path", { d: "M7.5 13.5v-9H4.8A1.8 1.8 0 0 0 3 6.3v5.4a1.8 1.8 0 0 0 1.8 1.8h2.7Z" }),
817
+ /* @__PURE__ */ a("path", { d: "M7.5 4.5h8.1a2.4 2.4 0 0 1 2.3 1.8l1.4 5.4a1.5 1.5 0 0 1-1.5 1.8h-4.1l.7 3.4A2.4 2.4 0 0 1 12 19.8l-4.5-6.3Z" })
818
+ ] });
819
+ function Ra({
764
820
  id: e,
765
821
  manager: t,
766
822
  onDismiss: s,
767
823
  onNewConversation: i,
768
- triggerRef: r
824
+ triggerRef: o
769
825
  }) {
770
- const [o, d] = E(""), [p, v] = E(!1), h = N(null);
771
- return oe(() => {
772
- d(t.chat?.title ?? ""), v(!1);
773
- }, [t.chat?.chatId, t.chat?.title]), oe(() => {
774
- const _ = (F) => {
775
- const A = F.target;
776
- A instanceof Node && (h.current?.contains(A) || r.current?.contains(A) || s());
826
+ const [c, d] = N(), [h, b] = N(""), [f, $] = N(), [L, T] = N(), j = S(null), M = (n, v) => {
827
+ T(
828
+ (k) => k?.anchor === v && k.label === n ? k : { anchor: v, label: n }
829
+ );
830
+ }, U = (n) => {
831
+ T(
832
+ (v) => v?.anchor === n ? void 0 : v
833
+ );
834
+ }, g = (n) => ({
835
+ "data-tooltip": n,
836
+ onBlur: (v) => U(v.currentTarget),
837
+ onFocus: (v) => M(n, v.currentTarget),
838
+ onPointerEnter: (v) => M(n, v.currentTarget),
839
+ onPointerLeave: (v) => U(v.currentTarget)
840
+ }), R = () => {
841
+ d(void 0), b("");
842
+ }, P = async (n) => {
843
+ const v = h.trim();
844
+ v && await t.update({ title: v }, n) && R();
845
+ }, p = async (n) => {
846
+ await t.remove(n) && $(void 0);
847
+ };
848
+ return ie(() => {
849
+ const n = (v) => {
850
+ const k = v.target;
851
+ k instanceof Node && (j.current?.contains(k) || o.current?.contains(k) || s());
777
852
  };
778
- return document.addEventListener("pointerdown", _), () => {
779
- document.removeEventListener("pointerdown", _);
853
+ return document.addEventListener("pointerdown", n), () => {
854
+ document.removeEventListener("pointerdown", n);
780
855
  };
781
- }, [s, r]), /* @__PURE__ */ c(
856
+ }, [s, o]), /* @__PURE__ */ l(
782
857
  "div",
783
858
  {
784
859
  "aria-label": "任务列表",
785
860
  className: "make-ai-assistant__conversation-controls",
786
861
  id: e,
787
- ref: h,
862
+ ref: j,
788
863
  role: "dialog",
789
864
  children: [
790
- /* @__PURE__ */ c("div", { className: "make-ai-assistant__conversation-heading", children: [
865
+ /* @__PURE__ */ l("div", { className: "make-ai-assistant__conversation-heading", children: [
791
866
  /* @__PURE__ */ a("span", { children: "最近对话" }),
792
867
  /* @__PURE__ */ a(
793
868
  "button",
@@ -803,47 +878,172 @@ function ba({
803
878
  }
804
879
  )
805
880
  ] }),
806
- /* @__PURE__ */ c(
881
+ /* @__PURE__ */ l(
807
882
  "nav",
808
883
  {
809
884
  "aria-label": "对话列表",
810
885
  className: "make-ai-assistant__conversation-list",
811
886
  children: [
812
- t.chats.map((_) => /* @__PURE__ */ c(
813
- "div",
814
- {
815
- className: "make-ai-assistant__conversation-row",
816
- children: [
817
- /* @__PURE__ */ c(
818
- "button",
819
- {
820
- type: "button",
821
- "aria-pressed": t.chat?.chatId === _.chatId,
822
- onClick: () => {
823
- s(), t.select(_);
824
- },
825
- children: [
826
- /* @__PURE__ */ a(ga, {}),
827
- /* @__PURE__ */ a("span", { children: _.title || "未命名对话" })
828
- ]
829
- }
830
- ),
831
- /* @__PURE__ */ a(
832
- "button",
833
- {
834
- type: "button",
835
- disabled: t.busy,
836
- "aria-label": `${_.pinned ? "取消置顶" : "置顶"} ${_.title}`,
837
- onClick: () => {
838
- t.update({ pinned: !_.pinned }, _);
839
- },
840
- children: _.pinned ? "★" : "☆"
841
- }
842
- )
843
- ]
844
- },
845
- _.chatId
846
- )),
887
+ t.chats.map((n) => {
888
+ const v = c === n.chatId, k = f === n.chatId, q = n.title || "未命名对话";
889
+ return /* @__PURE__ */ l(
890
+ "div",
891
+ {
892
+ className: "make-ai-assistant__conversation-row",
893
+ "data-editing": v || k || void 0,
894
+ children: [
895
+ k ? /* @__PURE__ */ l(
896
+ "div",
897
+ {
898
+ "aria-label": "确认删除对话",
899
+ className: "make-ai-assistant__conversation-delete-confirmation",
900
+ role: "group",
901
+ children: [
902
+ /* @__PURE__ */ l("span", { children: [
903
+ "删除“",
904
+ q,
905
+ "”?"
906
+ ] }),
907
+ /* @__PURE__ */ a(
908
+ "button",
909
+ {
910
+ "aria-label": `确认删除:${q}`,
911
+ className: "make-ai-assistant__conversation-row-action make-ai-assistant__conversation-row-action--danger",
912
+ disabled: t.busy,
913
+ type: "button",
914
+ ...g("确认删除"),
915
+ onClick: () => {
916
+ p(n);
917
+ },
918
+ children: /* @__PURE__ */ a(St, {})
919
+ }
920
+ ),
921
+ /* @__PURE__ */ a(
922
+ "button",
923
+ {
924
+ "aria-label": `取消删除:${q}`,
925
+ className: "make-ai-assistant__conversation-row-action",
926
+ disabled: t.busy,
927
+ type: "button",
928
+ ...g("取消"),
929
+ onClick: () => $(void 0),
930
+ children: /* @__PURE__ */ a(Lt, {})
931
+ }
932
+ )
933
+ ]
934
+ }
935
+ ) : v ? /* @__PURE__ */ a(
936
+ "input",
937
+ {
938
+ "aria-label": "对话标题",
939
+ autoFocus: !0,
940
+ className: "make-ai-assistant__conversation-row-title-input",
941
+ disabled: t.busy,
942
+ maxLength: 255,
943
+ value: h,
944
+ onChange: (I) => b(I.currentTarget.value),
945
+ onKeyDown: (I) => {
946
+ I.nativeEvent.isComposing || (I.key === "Escape" && (I.preventDefault(), R()), I.key === "Enter" && (I.preventDefault(), P(n)));
947
+ }
948
+ }
949
+ ) : /* @__PURE__ */ l(
950
+ "button",
951
+ {
952
+ "aria-pressed": t.chat?.chatId === n.chatId,
953
+ className: "make-ai-assistant__conversation-row-select",
954
+ type: "button",
955
+ onClick: () => {
956
+ s(), t.select(n);
957
+ },
958
+ children: [
959
+ /* @__PURE__ */ a(wa, {}),
960
+ /* @__PURE__ */ a("span", { children: q })
961
+ ]
962
+ }
963
+ ),
964
+ v ? /* @__PURE__ */ l(
965
+ "div",
966
+ {
967
+ "aria-label": "修改标题操作",
968
+ className: "make-ai-assistant__conversation-row-actions",
969
+ role: "group",
970
+ children: [
971
+ /* @__PURE__ */ a(
972
+ "button",
973
+ {
974
+ "aria-label": "确认修改标题",
975
+ className: "make-ai-assistant__conversation-row-action",
976
+ disabled: t.busy || !h.trim(),
977
+ type: "button",
978
+ ...g("保存标题"),
979
+ onClick: () => {
980
+ P(n);
981
+ },
982
+ children: /* @__PURE__ */ a(St, {})
983
+ }
984
+ ),
985
+ /* @__PURE__ */ a(
986
+ "button",
987
+ {
988
+ "aria-label": "取消修改标题",
989
+ className: "make-ai-assistant__conversation-row-action",
990
+ disabled: t.busy,
991
+ type: "button",
992
+ ...g("取消"),
993
+ onClick: R,
994
+ children: /* @__PURE__ */ a(Lt, {})
995
+ }
996
+ )
997
+ ]
998
+ }
999
+ ) : k ? null : /* @__PURE__ */ l("div", { className: "make-ai-assistant__conversation-row-actions", children: [
1000
+ /* @__PURE__ */ a(
1001
+ "button",
1002
+ {
1003
+ "aria-label": `${n.pinned ? "取消置顶" : "置顶"} ${q}`,
1004
+ className: "make-ai-assistant__conversation-row-pin",
1005
+ disabled: t.busy,
1006
+ type: "button",
1007
+ onClick: () => {
1008
+ t.update({ pinned: !n.pinned }, n);
1009
+ },
1010
+ children: n.pinned ? "★" : "☆"
1011
+ }
1012
+ ),
1013
+ /* @__PURE__ */ a(
1014
+ "button",
1015
+ {
1016
+ "aria-label": `修改标题:${q}`,
1017
+ className: "make-ai-assistant__conversation-row-action",
1018
+ disabled: t.busy,
1019
+ type: "button",
1020
+ ...g("修改标题"),
1021
+ onClick: () => {
1022
+ $(void 0), d(n.chatId), b(n.title);
1023
+ },
1024
+ children: /* @__PURE__ */ a(Aa, {})
1025
+ }
1026
+ ),
1027
+ /* @__PURE__ */ a(
1028
+ "button",
1029
+ {
1030
+ "aria-label": `删除:${q}`,
1031
+ className: "make-ai-assistant__conversation-row-action make-ai-assistant__conversation-row-action--danger",
1032
+ disabled: t.busy,
1033
+ type: "button",
1034
+ ...g("删除"),
1035
+ onClick: () => {
1036
+ R(), $(n.chatId);
1037
+ },
1038
+ children: /* @__PURE__ */ a(Ma, {})
1039
+ }
1040
+ )
1041
+ ] })
1042
+ ]
1043
+ },
1044
+ n.chatId
1045
+ );
1046
+ }),
847
1047
  !t.loading && !t.chats.length ? /* @__PURE__ */ a("p", { children: "暂无对话,发送消息即可新建" }) : null,
848
1048
  t.listCursor ? /* @__PURE__ */ a(
849
1049
  "button",
@@ -859,180 +1059,166 @@ function ba({
859
1059
  ]
860
1060
  }
861
1061
  ),
862
- t.chat ? /* @__PURE__ */ c("details", { className: "make-ai-assistant__conversation-management", children: [
863
- /* @__PURE__ */ a("summary", { children: "管理当前对话" }),
864
- /* @__PURE__ */ c("div", { className: "make-ai-assistant__conversation-actions", children: [
865
- /* @__PURE__ */ a(
866
- "input",
867
- {
868
- "aria-label": "对话标题",
869
- maxLength: 255,
870
- value: o,
871
- onChange: (_) => d(_.currentTarget.value)
872
- }
873
- ),
874
- /* @__PURE__ */ a(
875
- "button",
876
- {
877
- type: "button",
878
- disabled: t.busy || !o.trim(),
879
- onClick: () => {
880
- t.update({ title: o });
881
- },
882
- children: "保存标题"
883
- }
884
- ),
885
- /* @__PURE__ */ a(
886
- "button",
887
- {
888
- type: "button",
889
- disabled: t.busy,
890
- onClick: () => v(!0),
891
- children: "删除对话"
892
- }
893
- ),
894
- p ? /* @__PURE__ */ c("div", { role: "group", "aria-label": "确认删除对话", children: [
895
- /* @__PURE__ */ c("span", { children: [
896
- "删除“",
897
- t.chat.title,
898
- "”?"
899
- ] }),
900
- /* @__PURE__ */ a(
901
- "button",
902
- {
903
- type: "button",
904
- disabled: t.busy,
905
- onClick: () => {
906
- v(!1), t.remove();
907
- },
908
- children: "确认删除"
909
- }
910
- ),
911
- /* @__PURE__ */ a("button", { type: "button", onClick: () => v(!1), children: "保留" })
912
- ] }) : null,
913
- t.historyMore ? /* @__PURE__ */ a(
914
- "button",
915
- {
916
- type: "button",
917
- disabled: t.loading,
918
- onClick: () => {
919
- t.moreHistory();
920
- },
921
- children: "继续加载历史"
922
- }
923
- ) : null,
924
- t.historyTruncated || t.state.historyTruncated ? /* @__PURE__ */ a("p", { children: "当前展示有界消息窗口,可重新选择对话从头读取。" }) : null
925
- ] })
1062
+ t.chat && (t.historyMore || t.historyTruncated || t.state.historyTruncated) ? /* @__PURE__ */ l("div", { className: "make-ai-assistant__conversation-history-actions", children: [
1063
+ t.historyMore ? /* @__PURE__ */ a(
1064
+ "button",
1065
+ {
1066
+ type: "button",
1067
+ disabled: t.loading,
1068
+ onClick: () => {
1069
+ t.moreHistory();
1070
+ },
1071
+ children: "继续加载历史"
1072
+ }
1073
+ ) : null,
1074
+ t.historyTruncated || t.state.historyTruncated ? /* @__PURE__ */ a("p", { children: "当前展示有界消息窗口,可重新选择对话从头读取。" }) : null
926
1075
  ] }) : null,
927
- t.error ? /* @__PURE__ */ c("div", { className: "make-ai-assistant__conversation-error", role: "alert", children: [
1076
+ t.error ? /* @__PURE__ */ l("div", { className: "make-ai-assistant__conversation-error", role: "alert", children: [
928
1077
  /* @__PURE__ */ a("span", { children: t.error }),
929
1078
  /* @__PURE__ */ a("button", { type: "button", onClick: () => {
930
1079
  t.retry();
931
1080
  }, children: "恢复对话" })
932
1081
  ] }) : null,
933
- i ? /* @__PURE__ */ c(
1082
+ i ? /* @__PURE__ */ l(
934
1083
  "button",
935
1084
  {
936
1085
  className: "make-ai-assistant__conversation-new",
937
1086
  type: "button",
938
1087
  onClick: i,
939
1088
  children: [
940
- /* @__PURE__ */ a(ya, {}),
1089
+ /* @__PURE__ */ a(Ia, {}),
941
1090
  /* @__PURE__ */ a("span", { children: "新建对话" })
942
1091
  ]
943
1092
  }
1093
+ ) : null,
1094
+ L ? /* @__PURE__ */ a(
1095
+ Na,
1096
+ {
1097
+ anchor: L.anchor,
1098
+ label: L.label,
1099
+ onDismiss: () => T(void 0)
1100
+ }
944
1101
  ) : null
945
1102
  ]
946
1103
  }
947
1104
  );
948
1105
  }
949
- function ka({
1106
+ function Ea({
950
1107
  message: e,
951
1108
  manager: t
952
1109
  }) {
953
- const [s, i] = E(!1), [r, o] = E(""), [d, p] = E(""), v = t.feedbackBusy.includes(e.id);
1110
+ const [s, i] = N(!1), [o, c] = N(""), [d, h] = N(""), b = t.feedbackBusy.includes(e.id);
954
1111
  if (!e.persistent || e.role !== "assistant" || e.intermediate)
955
1112
  return null;
956
- const h = e.feedback?.rating ?? "none";
957
- return /* @__PURE__ */ c("div", { className: "make-ai-assistant__feedback", "aria-label": "回答反馈", children: [
958
- /* @__PURE__ */ a(
959
- "button",
960
- {
961
- type: "button",
962
- "aria-label": "点赞",
963
- "aria-pressed": h === "like",
964
- disabled: v,
965
- onClick: () => {
966
- t.feedback(e, h === "like" ? "none" : "like");
967
- },
968
- children: ""
969
- }
970
- ),
971
- /* @__PURE__ */ a(
972
- "button",
973
- {
974
- type: "button",
975
- "aria-label": "点踩",
976
- "aria-pressed": h === "dislike",
977
- disabled: v,
978
- onClick: () => {
979
- if (h === "dislike") {
980
- t.feedback(e, "none");
981
- return;
1113
+ const f = e.feedback?.rating ?? "none";
1114
+ return /* @__PURE__ */ l(
1115
+ "div",
1116
+ {
1117
+ "aria-label": "回答反馈",
1118
+ className: "make-ai-assistant__feedback",
1119
+ role: "group",
1120
+ children: [
1121
+ /* @__PURE__ */ a(
1122
+ "button",
1123
+ {
1124
+ type: "button",
1125
+ "aria-label": "喜欢",
1126
+ "aria-pressed": f === "like",
1127
+ className: "make-ai-assistant__reply-action make-ai-assistant__reply-feedback-action",
1128
+ "data-tooltip": "喜欢",
1129
+ disabled: b,
1130
+ onClick: () => {
1131
+ t.feedback(e, f === "like" ? "none" : "like");
1132
+ },
1133
+ children: /* @__PURE__ */ a(Ca, {})
982
1134
  }
983
- o(e.feedback?.reason ?? ""), p(e.feedback?.comment ?? ""), i(!0);
984
- },
985
- children: ""
986
- }
987
- ),
988
- h === "dislike" ? /* @__PURE__ */ a(
989
- "button",
990
- {
991
- type: "button",
992
- disabled: v,
993
- onClick: () => {
994
- o(e.feedback?.reason ?? ""), p(e.feedback?.comment ?? ""), i(!0);
995
- },
996
- children: "修改反馈"
997
- }
998
- ) : null,
999
- s ? /* @__PURE__ */ c(
1000
- "form",
1001
- {
1002
- onSubmit: (_) => {
1003
- _.preventDefault(), t.feedback(e, "dislike", r, d).then((F) => {
1004
- F && i(!1);
1005
- });
1006
- },
1007
- children: [
1008
- /* @__PURE__ */ a(
1009
- "input",
1010
- {
1011
- "aria-label": "反馈原因",
1012
- maxLength: 128,
1013
- value: r,
1014
- onChange: (_) => o(_.currentTarget.value),
1015
- placeholder: "原因(可选)"
1016
- }
1017
- ),
1018
- /* @__PURE__ */ a(
1019
- "textarea",
1020
- {
1021
- "aria-label": "反馈说明",
1022
- maxLength: 4e3,
1023
- value: d,
1024
- onChange: (_) => p(_.currentTarget.value),
1025
- placeholder: "补充说明(可选)"
1026
- }
1027
- ),
1028
- /* @__PURE__ */ a("button", { type: "submit", disabled: v, children: "提交反馈" }),
1029
- /* @__PURE__ */ a("button", { type: "button", onClick: () => i(!1), children: "取消" })
1030
- ]
1031
- }
1032
- ) : null
1033
- ] });
1135
+ ),
1136
+ /* @__PURE__ */ a(
1137
+ "button",
1138
+ {
1139
+ type: "button",
1140
+ "aria-label": "不喜欢",
1141
+ "aria-pressed": f === "dislike",
1142
+ className: "make-ai-assistant__reply-action make-ai-assistant__reply-feedback-action",
1143
+ "data-tooltip": "不喜欢",
1144
+ disabled: b,
1145
+ onClick: () => {
1146
+ if (f === "dislike") {
1147
+ t.feedback(e, "none");
1148
+ return;
1149
+ }
1150
+ c(e.feedback?.reason ?? ""), h(e.feedback?.comment ?? ""), i(!0);
1151
+ },
1152
+ children: /* @__PURE__ */ a(Ta, {})
1153
+ }
1154
+ ),
1155
+ f === "dislike" ? /* @__PURE__ */ a(
1156
+ "button",
1157
+ {
1158
+ className: "make-ai-assistant__feedback-text-action",
1159
+ type: "button",
1160
+ disabled: b,
1161
+ onClick: () => {
1162
+ c(e.feedback?.reason ?? ""), h(e.feedback?.comment ?? ""), i(!0);
1163
+ },
1164
+ children: "修改反馈"
1165
+ }
1166
+ ) : null,
1167
+ s ? /* @__PURE__ */ l(
1168
+ "form",
1169
+ {
1170
+ onSubmit: ($) => {
1171
+ $.preventDefault(), t.feedback(e, "dislike", o, d).then((L) => {
1172
+ L && i(!1);
1173
+ });
1174
+ },
1175
+ children: [
1176
+ /* @__PURE__ */ a(
1177
+ "input",
1178
+ {
1179
+ "aria-label": "反馈原因",
1180
+ maxLength: 128,
1181
+ value: o,
1182
+ onChange: ($) => c($.currentTarget.value),
1183
+ placeholder: "原因(可选)"
1184
+ }
1185
+ ),
1186
+ /* @__PURE__ */ a(
1187
+ "textarea",
1188
+ {
1189
+ "aria-label": "反馈说明",
1190
+ maxLength: 4e3,
1191
+ value: d,
1192
+ onChange: ($) => h($.currentTarget.value),
1193
+ placeholder: "补充说明(可选)"
1194
+ }
1195
+ ),
1196
+ /* @__PURE__ */ a(
1197
+ "button",
1198
+ {
1199
+ className: "make-ai-assistant__feedback-text-action",
1200
+ type: "submit",
1201
+ disabled: b,
1202
+ children: "提交反馈"
1203
+ }
1204
+ ),
1205
+ /* @__PURE__ */ a(
1206
+ "button",
1207
+ {
1208
+ className: "make-ai-assistant__feedback-text-action",
1209
+ type: "button",
1210
+ onClick: () => i(!1),
1211
+ children: "取消"
1212
+ }
1213
+ )
1214
+ ]
1215
+ }
1216
+ ) : null
1217
+ ]
1218
+ }
1219
+ );
1034
1220
  }
1035
- const Rt = /* @__PURE__ */ new Set([
1221
+ const $t = /* @__PURE__ */ new Set([
1036
1222
  "image/png",
1037
1223
  "image/jpeg",
1038
1224
  "image/webp",
@@ -1045,259 +1231,268 @@ const Rt = /* @__PURE__ */ new Set([
1045
1231
  "video/webm",
1046
1232
  "video/ogg"
1047
1233
  ]);
1048
- function _a({
1234
+ function Sa({
1049
1235
  part: e,
1050
1236
  context: t,
1051
1237
  transport: s,
1052
1238
  chatId: i
1053
1239
  }) {
1054
- const [r, o] = E(), [d, p] = E(), [v, h] = E(!1), _ = N([]), F = N(void 0);
1055
- oe(
1240
+ const [o, c] = N(), [d, h] = N(), [b, f] = N(!1), $ = S([]), L = S(void 0);
1241
+ ie(
1056
1242
  () => () => {
1057
- F.current?.abort(), _.current.forEach((X) => URL.revokeObjectURL(X));
1243
+ L.current?.abort(), $.current.forEach((j) => URL.revokeObjectURL(j));
1058
1244
  },
1059
1245
  []
1060
1246
  );
1061
- const A = async (X) => {
1062
- if (!s.readContent || v) return;
1063
- const C = new AbortController();
1064
- F.current = C, h(!0), p(void 0);
1247
+ const T = async (j) => {
1248
+ if (!s.readContent || b) return;
1249
+ const M = new AbortController();
1250
+ L.current = M, f(!0), h(void 0);
1065
1251
  try {
1066
- const B = await s.readContent(
1252
+ const U = await s.readContent(
1067
1253
  t,
1068
1254
  { chatId: i, contentRef: e.media.contentRef },
1069
- { signal: C.signal }
1255
+ { signal: M.signal }
1070
1256
  );
1071
- if (C.signal.aborted) return;
1072
- const g = new Blob([new Uint8Array(B).buffer], {
1073
- type: X && Rt.has(e.media.contentType) ? e.media.contentType : "application/octet-stream"
1074
- }), L = URL.createObjectURL(g);
1075
- if (_.current.push(L), X) o(L);
1257
+ if (M.signal.aborted) return;
1258
+ const g = new Blob([new Uint8Array(U).buffer], {
1259
+ type: j && $t.has(e.media.contentType) ? e.media.contentType : "application/octet-stream"
1260
+ }), R = URL.createObjectURL(g);
1261
+ if ($.current.push(R), j) c(R);
1076
1262
  else {
1077
- const U = document.createElement("a");
1078
- U.href = L, U.download = e.name ?? "attachment", U.click();
1263
+ const P = document.createElement("a");
1264
+ P.href = R, P.download = e.name ?? "attachment", P.click();
1079
1265
  }
1080
- } catch (B) {
1081
- C.signal.aborted || p(vt(B));
1266
+ } catch (U) {
1267
+ M.signal.aborted || h(bt(U));
1082
1268
  } finally {
1083
- C.signal.aborted || h(!1);
1269
+ M.signal.aborted || f(!1);
1084
1270
  }
1085
1271
  };
1086
- return /* @__PURE__ */ c("div", { className: "make-ai-assistant__attachment", children: [
1087
- /* @__PURE__ */ c("span", { children: [
1272
+ return /* @__PURE__ */ l("div", { className: "make-ai-assistant__attachment", children: [
1273
+ /* @__PURE__ */ l("span", { children: [
1088
1274
  e.name ?? "附件",
1089
1275
  " · ",
1090
1276
  e.media.sizeBytes,
1091
1277
  " 字节"
1092
1278
  ] }),
1093
- s.readContent ? /* @__PURE__ */ c(Ce, { children: [
1094
- /* @__PURE__ */ a("button", { type: "button", disabled: v, onClick: () => {
1095
- A(!1);
1279
+ s.readContent ? /* @__PURE__ */ l(Ne, { children: [
1280
+ /* @__PURE__ */ a("button", { type: "button", disabled: b, onClick: () => {
1281
+ T(!1);
1096
1282
  }, children: "下载附件" }),
1097
- Rt.has(e.media.contentType) ? /* @__PURE__ */ a("button", { type: "button", disabled: v, onClick: () => {
1098
- A(!0);
1283
+ $t.has(e.media.contentType) ? /* @__PURE__ */ a("button", { type: "button", disabled: b, onClick: () => {
1284
+ T(!0);
1099
1285
  }, children: "预览附件" }) : null
1100
1286
  ] }) : null,
1101
1287
  d ? /* @__PURE__ */ a("span", { role: "alert", children: d }) : null,
1102
- r && e.kind === "image" ? /* @__PURE__ */ a("img", { src: r, alt: e.name ?? "附件图片" }) : null,
1103
- r && e.kind === "audio" ? /* @__PURE__ */ a("audio", { src: r, controls: !0 }) : null,
1104
- r && e.kind === "video" ? /* @__PURE__ */ a("video", { src: r, controls: !0 }) : null
1288
+ o && e.kind === "image" ? /* @__PURE__ */ a("img", { src: o, alt: e.name ?? "附件图片" }) : null,
1289
+ o && e.kind === "audio" ? /* @__PURE__ */ a("audio", { src: o, controls: !0 }) : null,
1290
+ o && e.kind === "video" ? /* @__PURE__ */ a("video", { src: o, controls: !0 }) : null
1105
1291
  ] });
1106
1292
  }
1107
- function wa({
1293
+ function La({
1108
1294
  message: e,
1109
1295
  context: t,
1110
1296
  transport: s,
1111
1297
  chatId: i
1112
1298
  }) {
1113
- return /* @__PURE__ */ a(Ce, { children: e.parts?.map(
1114
- (r, o) => r.kind === "text" ? null : /* @__PURE__ */ a(
1115
- _a,
1299
+ return /* @__PURE__ */ a(Ne, { children: e.parts?.map(
1300
+ (o, c) => o.kind === "text" ? null : /* @__PURE__ */ a(
1301
+ Sa,
1116
1302
  {
1117
- part: r,
1303
+ part: o,
1118
1304
  context: t,
1119
1305
  transport: s,
1120
1306
  chatId: i
1121
1307
  },
1122
- r.id ?? `${e.id}:${o}`
1308
+ o.id ?? `${e.id}:${c}`
1123
1309
  )
1124
1310
  ) });
1125
1311
  }
1126
- const Ia = (e) => e.type.split(";")[0].trim().toLowerCase() || "application/octet-stream", Aa = (e) => e.startsWith("image/") && e !== "image/svg+xml" ? "image" : e.startsWith("audio/") ? "audio" : e.startsWith("video/") ? "video" : "file", Ma = (e, t) => new Promise((s, i) => {
1127
- const r = new FileReader(), o = () => t.removeEventListener("abort", d), d = () => {
1128
- r.abort(), o(), i(Object.assign(new Error("Read aborted"), { name: "AbortError" }));
1312
+ const Vt = (e) => e.type.split(";")[0].trim().toLowerCase() || "application/octet-stream", $a = (e) => e.startsWith("image/") && e !== "image/svg+xml" ? "image" : e.startsWith("audio/") ? "audio" : e.startsWith("video/") ? "video" : "file", xa = (e) => {
1313
+ const t = Vt(e);
1314
+ if (!(!t.startsWith("image/") || t === "image/svg+xml" || typeof URL > "u" || typeof URL.createObjectURL != "function"))
1315
+ return URL.createObjectURL(e);
1316
+ }, xt = (e) => {
1317
+ e && typeof URL < "u" && typeof URL.revokeObjectURL == "function" && URL.revokeObjectURL(e);
1318
+ }, Da = (e, t) => new Promise((s, i) => {
1319
+ const o = new FileReader(), c = () => t.removeEventListener("abort", d), d = () => {
1320
+ o.abort(), c(), i(Object.assign(new Error("Read aborted"), { name: "AbortError" }));
1129
1321
  };
1130
1322
  if (t.aborted) {
1131
1323
  d();
1132
1324
  return;
1133
1325
  }
1134
- t.addEventListener("abort", d, { once: !0 }), r.onload = () => {
1135
- o(), s(new Uint8Array(r.result));
1136
- }, r.onerror = () => {
1137
- o(), i(new Error("无法读取文件"));
1138
- }, r.readAsArrayBuffer(e);
1326
+ t.addEventListener("abort", d, { once: !0 }), o.onload = () => {
1327
+ c(), s(new Uint8Array(o.result));
1328
+ }, o.onerror = () => {
1329
+ c(), i(new Error("无法读取文件"));
1330
+ }, o.readAsArrayBuffer(e);
1139
1331
  });
1140
- function Na(e, t, s) {
1141
- const [i, r] = E([]), o = N(/* @__PURE__ */ new Map()), d = N(Promise.resolve()), p = t.scopeKey?.(e) ?? e.app.id, v = N(p);
1142
- v.current = p;
1143
- const h = N(void 0), _ = s.enabled && t.features?.attachments === !0, F = (f, l) => {
1144
- !o.current.has(f.draft.id) || f.scope !== v.current || (f.draft = { ...f.draft, ...l }, r([...o.current.values()].map((S) => S.draft)));
1145
- }, A = () => {
1146
- for (const f of o.current.values()) f.controller.abort();
1147
- o.current.clear(), r([]), h.current = void 0, d.current = Promise.resolve();
1332
+ function Ba(e, t, s) {
1333
+ const [i, o] = N([]), c = S(/* @__PURE__ */ new Map()), d = S(Promise.resolve()), h = t.scopeKey?.(e) ?? e.app.id, b = S(h);
1334
+ b.current = h;
1335
+ const f = S(void 0), $ = s.enabled && t.features?.attachments === !0, L = (p, n) => {
1336
+ !c.current.has(p.draft.id) || p.scope !== b.current || (p.draft = { ...p.draft, ...n }, o([...c.current.values()].map((v) => v.draft)));
1337
+ }, T = () => {
1338
+ for (const p of c.current.values())
1339
+ p.controller.abort(), xt(p.draft.previewUrl);
1340
+ c.current.clear(), o([]), f.current = void 0, d.current = Promise.resolve();
1148
1341
  };
1149
- oe(() => (A(), A), [p, t]), oe(() => {
1150
- h.current && s.chat?.chatId !== h.current && A();
1342
+ ie(() => (T(), T), [h, t]), ie(() => {
1343
+ f.current && s.chat?.chatId !== f.current && T();
1151
1344
  }, [s.chat?.chatId]);
1152
- const X = async (f) => {
1153
- const l = f.controller.signal, S = () => {
1154
- if (l.aborted || f.scope !== v.current || !o.current.has(f.draft.id))
1345
+ const j = async (p) => {
1346
+ const n = p.controller.signal, v = () => {
1347
+ if (n.aborted || p.scope !== b.current || !c.current.has(p.draft.id))
1155
1348
  throw Object.assign(new Error("Upload aborted"), {
1156
1349
  name: "AbortError"
1157
1350
  });
1158
1351
  };
1159
1352
  try {
1160
- if (S(), f.file.size > 64 << 20) throw new Error("文件不能超过 64 MiB");
1161
- const T = await s.ensureChat();
1162
- S(), h.current = T.chatId;
1163
- const te = Ia(f.file);
1164
- F(f, { status: "uploading", error: void 0 });
1165
- let R = f.draft.upload ? await t.getUpload(
1353
+ if (v(), p.file.size > 64 << 20) throw new Error("文件不能超过 64 MiB");
1354
+ const k = await s.ensureChat();
1355
+ v(), f.current = k.chatId;
1356
+ const q = Vt(p.file);
1357
+ L(p, { status: "uploading", error: void 0 });
1358
+ let I = p.draft.upload ? await t.getUpload(
1166
1359
  e,
1167
- { chatId: T.chatId, uploadId: f.draft.upload.id },
1168
- { signal: l }
1360
+ { chatId: k.chatId, uploadId: p.draft.upload.id },
1361
+ { signal: n }
1169
1362
  ) : await t.startUpload(
1170
1363
  e,
1171
1364
  {
1172
- chatId: T.chatId,
1173
- fileId: f.draft.fileId,
1174
- name: f.file.name,
1175
- contentType: te,
1176
- sizeBytes: f.file.size
1365
+ chatId: k.chatId,
1366
+ fileId: p.draft.fileId,
1367
+ name: p.file.name,
1368
+ contentType: q,
1369
+ sizeBytes: p.file.size
1177
1370
  },
1178
- { signal: l }
1371
+ { signal: n }
1179
1372
  );
1180
- if (S(), F(f, { upload: R }), R.name !== f.file.name || R.contentType !== te || R.sizeBytes !== f.file.size)
1373
+ if (v(), L(p, { upload: I }), I.name !== p.file.name || I.contentType !== q || I.sizeBytes !== p.file.size)
1181
1374
  throw new Error("上传文件身份不一致");
1182
- if (R.status !== "ready") {
1183
- R = await t.getUpload(
1375
+ if (I.status !== "ready") {
1376
+ I = await t.getUpload(
1184
1377
  e,
1185
- { chatId: T.chatId, uploadId: R.id },
1186
- { signal: l }
1187
- ), S();
1188
- const Z = new Set(R.completedParts), G = Math.ceil(f.file.size / R.partSize);
1189
- for (let P = 0; P < G; P += 1) {
1190
- if (S(), !Z.has(P)) {
1191
- const Q = await Ma(
1192
- f.file.slice(
1193
- P * R.partSize,
1194
- Math.min(f.file.size, (P + 1) * R.partSize)
1378
+ { chatId: k.chatId, uploadId: I.id },
1379
+ { signal: n }
1380
+ ), v();
1381
+ const G = new Set(I.completedParts), Y = Math.ceil(p.file.size / I.partSize);
1382
+ for (let z = 0; z < Y; z += 1) {
1383
+ if (v(), !G.has(z)) {
1384
+ const Q = await Da(
1385
+ p.file.slice(
1386
+ z * I.partSize,
1387
+ Math.min(p.file.size, (z + 1) * I.partSize)
1195
1388
  ),
1196
- l
1389
+ n
1197
1390
  );
1198
- S(), await t.uploadPart(
1391
+ v(), await t.uploadPart(
1199
1392
  e,
1200
- { chatId: T.chatId, uploadId: R.id, part: P, bytes: Q },
1201
- { signal: l }
1202
- ), S(), Z.add(P);
1393
+ { chatId: k.chatId, uploadId: I.id, part: z, bytes: Q },
1394
+ { signal: n }
1395
+ ), v(), G.add(z);
1203
1396
  }
1204
- F(f, { progress: Z.size / Math.max(G, 1) });
1397
+ L(p, { progress: G.size / Math.max(Y, 1) });
1205
1398
  }
1206
- F(f, { status: "completing" }), R = await t.completeUpload(
1399
+ L(p, { status: "completing" }), I = await t.completeUpload(
1207
1400
  e,
1208
- { chatId: T.chatId, uploadId: R.id },
1209
- { signal: l }
1210
- ), S();
1401
+ { chatId: k.chatId, uploadId: I.id },
1402
+ { signal: n }
1403
+ ), v();
1211
1404
  }
1212
- if (R.status !== "ready" || !R.content)
1405
+ if (I.status !== "ready" || !I.content)
1213
1406
  throw new Error("上传尚未完成");
1214
- F(f, { status: "ready", progress: 1, upload: R });
1215
- } catch (T) {
1216
- F(f, {
1217
- status: l.aborted ? "paused" : "failed",
1218
- error: l.aborted ? void 0 : vt(T)
1407
+ L(p, { status: "ready", progress: 1, upload: I });
1408
+ } catch (k) {
1409
+ L(p, {
1410
+ status: n.aborted ? "paused" : "failed",
1411
+ error: n.aborted ? void 0 : bt(k)
1219
1412
  });
1220
1413
  }
1221
- }, C = (f) => {
1222
- if (_) {
1223
- if (f.length + o.current.size > 32) {
1414
+ }, M = (p) => {
1415
+ if ($) {
1416
+ if (p.length + c.current.size > 32) {
1224
1417
  s.setError("每条消息最多包含 32 个附件或文本片段");
1225
1418
  return;
1226
1419
  }
1227
- for (const l of f) {
1228
- const S = {
1229
- id: Fe(),
1230
- fileId: Fe(),
1231
- name: l.name,
1232
- size: l.size,
1420
+ for (const n of p) {
1421
+ const v = {
1422
+ id: Pe(),
1423
+ fileId: Pe(),
1424
+ name: n.name,
1425
+ size: n.size,
1233
1426
  status: "queued",
1234
- progress: 0
1235
- }, T = {
1236
- draft: S,
1237
- file: l,
1427
+ progress: 0,
1428
+ previewUrl: xa(n)
1429
+ }, k = {
1430
+ draft: v,
1431
+ file: n,
1238
1432
  controller: new AbortController(),
1239
- scope: p
1433
+ scope: h
1240
1434
  };
1241
- o.current.set(S.id, T), d.current = d.current.then(() => X(T));
1435
+ c.current.set(v.id, k), d.current = d.current.then(() => j(k));
1242
1436
  }
1243
- r([...o.current.values()].map((l) => l.draft));
1437
+ o([...c.current.values()].map((n) => n.draft));
1244
1438
  }
1245
- }, B = (f) => {
1246
- const l = o.current.get(f);
1247
- !l || !["paused", "failed"].includes(l.draft.status) || (l.controller = new AbortController(), F(l, { status: "queued" }), d.current = d.current.then(() => X(l)));
1248
- }, g = (f) => {
1249
- o.current.get(f)?.controller.abort(), o.current.delete(f), r([...o.current.values()].map((S) => S.draft));
1250
- }, L = (f) => o.current.get(f)?.controller.abort(), U = i.flatMap((f) => {
1251
- const l = f.upload;
1252
- if (f.status !== "ready" || !l?.content) return [];
1253
- const S = Aa(l.contentType);
1439
+ }, U = (p) => {
1440
+ const n = c.current.get(p);
1441
+ !n || !["paused", "failed"].includes(n.draft.status) || (n.controller = new AbortController(), L(n, { status: "queued" }), d.current = d.current.then(() => j(n)));
1442
+ }, g = (p) => {
1443
+ const n = c.current.get(p);
1444
+ n?.controller.abort(), xt(n?.draft.previewUrl), c.current.delete(p), o([...c.current.values()].map((v) => v.draft));
1445
+ }, R = (p) => c.current.get(p)?.controller.abort(), P = i.flatMap((p) => {
1446
+ const n = p.upload;
1447
+ if (p.status !== "ready" || !n?.content) return [];
1448
+ const v = $a(n.contentType);
1254
1449
  return [
1255
1450
  {
1256
- id: f.id,
1257
- kind: S,
1258
- name: l.name,
1451
+ id: p.id,
1452
+ kind: v,
1453
+ name: n.name,
1259
1454
  media: {
1260
- contentRef: l.content.contentRef,
1261
- contentType: l.contentType,
1262
- sizeBytes: l.content.sizeBytes,
1263
- digestSha256: l.content.digestSha256
1455
+ contentRef: n.content.contentRef,
1456
+ contentType: n.contentType,
1457
+ sizeBytes: n.content.sizeBytes,
1458
+ digestSha256: n.content.digestSha256
1264
1459
  }
1265
1460
  }
1266
1461
  ];
1267
1462
  });
1268
1463
  return {
1269
- enabled: _,
1464
+ enabled: $,
1270
1465
  drafts: i,
1271
- parts: U,
1272
- pending: i.some((f) => f.status !== "ready"),
1273
- add: C,
1274
- retry: B,
1466
+ parts: P,
1467
+ pending: i.some((p) => p.status !== "ready"),
1468
+ add: M,
1469
+ retry: U,
1275
1470
  remove: g,
1276
- pause: L,
1277
- clear: A
1471
+ pause: R,
1472
+ clear: T
1278
1473
  };
1279
1474
  }
1280
- function Ca({
1475
+ function Ua({
1281
1476
  attachments: e,
1282
1477
  onOpenChange: t,
1283
1478
  open: s,
1284
1479
  triggerRef: i
1285
1480
  }) {
1286
- const r = N(null), o = N(null);
1287
- oe(() => {
1481
+ const o = S(null), c = S(null);
1482
+ ie(() => {
1288
1483
  if (!s) return;
1289
- const p = (v) => {
1290
- const h = v.target;
1291
- h instanceof Node && !r.current?.contains(h) && t(!1);
1484
+ const h = (b) => {
1485
+ const f = b.target;
1486
+ f instanceof Node && !o.current?.contains(f) && t(!1);
1292
1487
  };
1293
- return document.addEventListener("pointerdown", p), () => {
1294
- document.removeEventListener("pointerdown", p);
1488
+ return document.addEventListener("pointerdown", h), () => {
1489
+ document.removeEventListener("pointerdown", h);
1295
1490
  };
1296
1491
  }, [t, s]);
1297
- const d = (p) => {
1298
- e.add(Array.from(p.files ?? [])), p.value = "", t(!1);
1492
+ const d = (h) => {
1493
+ e.add(Array.from(h.files ?? [])), h.value = "", t(!1);
1299
1494
  };
1300
- return /* @__PURE__ */ c("div", { className: "make-ai-assistant__attachment-composer", ref: r, children: [
1495
+ return /* @__PURE__ */ l("div", { className: "make-ai-assistant__attachment-composer", ref: o, children: [
1301
1496
  /* @__PURE__ */ a(
1302
1497
  "button",
1303
1498
  {
@@ -1318,14 +1513,14 @@ function Ca({
1318
1513
  "aria-label": "附件选项",
1319
1514
  className: "make-ai-assistant__attachment-menu",
1320
1515
  role: "menu",
1321
- children: /* @__PURE__ */ c(
1516
+ children: /* @__PURE__ */ l(
1322
1517
  "button",
1323
1518
  {
1324
1519
  role: "menuitem",
1325
1520
  type: "button",
1326
- onClick: () => o.current?.click(),
1521
+ onClick: () => c.current?.click(),
1327
1522
  children: [
1328
- /* @__PURE__ */ c("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1523
+ /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1329
1524
  /* @__PURE__ */ a("path", { d: "M12 15V4M7.5 8.5 12 4l4.5 4.5" }),
1330
1525
  /* @__PURE__ */ a("path", { d: "M5 14v5h14v-5" })
1331
1526
  ] }),
@@ -1341,60 +1536,85 @@ function Ca({
1341
1536
  "aria-label": "上传文件或图片",
1342
1537
  hidden: !0,
1343
1538
  multiple: !0,
1344
- ref: o,
1539
+ ref: c,
1345
1540
  type: "file",
1346
- onChange: (p) => d(p.currentTarget)
1541
+ onChange: (h) => d(h.currentTarget)
1347
1542
  }
1348
1543
  )
1349
1544
  ] });
1350
1545
  }
1351
- function Ta({
1546
+ function Fa({
1352
1547
  attachments: e
1353
1548
  }) {
1354
- return e.drafts.length ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__attachment-drafts", "aria-label": "待发送附件", children: /* @__PURE__ */ a("ul", { children: e.drafts.map((t) => /* @__PURE__ */ c("li", { children: [
1355
- /* @__PURE__ */ c("span", { children: [
1356
- t.name,
1357
- " ·",
1358
- " ",
1359
- t.status === "ready" ? "已上传" : t.status === "completing" ? "校验中" : t.status === "paused" ? "已暂停" : t.status === "failed" ? "上传失败" : `${Math.round(t.progress * 100)}%`
1549
+ return e.drafts.length ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__attachment-drafts", "aria-label": "待发送附件", children: /* @__PURE__ */ a("ul", { children: e.drafts.map((t) => /* @__PURE__ */ l("li", { "data-status": t.status, children: [
1550
+ t.previewUrl ? /* @__PURE__ */ a(
1551
+ "img",
1552
+ {
1553
+ alt: "",
1554
+ className: "make-ai-assistant__attachment-draft-preview",
1555
+ src: t.previewUrl
1556
+ }
1557
+ ) : /* @__PURE__ */ a(
1558
+ "span",
1559
+ {
1560
+ "aria-hidden": "true",
1561
+ className: "make-ai-assistant__attachment-draft-file",
1562
+ children: /* @__PURE__ */ l("svg", { viewBox: "0 0 24 24", children: [
1563
+ /* @__PURE__ */ a("path", { d: "M6 3h8l4 4v14H6z" }),
1564
+ /* @__PURE__ */ a("path", { d: "M14 3v5h5M9 13h6M9 16h6" })
1565
+ ] })
1566
+ }
1567
+ ),
1568
+ /* @__PURE__ */ l("span", { className: "make-ai-assistant__attachment-draft-details", children: [
1569
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__attachment-draft-name", title: t.name, children: t.name }),
1570
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__attachment-draft-status", children: t.status === "ready" ? "已上传" : t.status === "completing" ? "校验中" : t.status === "paused" ? "已暂停" : t.status === "failed" ? "上传失败" : `${Math.round(t.progress * 100)}%` })
1360
1571
  ] }),
1361
1572
  t.error ? /* @__PURE__ */ a("span", { role: "alert", children: t.error }) : null,
1362
1573
  t.status === "failed" || t.status === "paused" ? /* @__PURE__ */ a("button", { type: "button", onClick: () => e.retry(t.id), children: "重试上传" }) : null,
1363
1574
  t.status === "uploading" ? /* @__PURE__ */ a("button", { type: "button", onClick: () => e.pause(t.id), children: "暂停上传" }) : null,
1364
- /* @__PURE__ */ a("button", { type: "button", onClick: () => e.remove(t.id), children: "移除附件" })
1575
+ /* @__PURE__ */ a(
1576
+ "button",
1577
+ {
1578
+ "aria-label": `移除附件 ${t.name}`,
1579
+ className: "make-ai-assistant__attachment-draft-remove",
1580
+ type: "button",
1581
+ onClick: () => e.remove(t.id),
1582
+ children: /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m7 7 10 10M17 7 7 17" }) })
1583
+ }
1584
+ )
1365
1585
  ] }, t.id)) }) }) : null;
1366
1586
  }
1367
- const Ra = (e) => `${e}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, Ea = "Make", Sa = [
1587
+ const Pa = (e) => `${e}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, za = "Make", Wa = [
1368
1588
  "总结当前页面数据",
1369
1589
  "找出需要关注的记录",
1370
1590
  "列出我有权限查看的数据对象"
1371
- ], qt = (e, t) => t ?? `${e?.trim() || Ea} AI 助手`, $a = (e) => e ?? Sa, Da = 480, Ht = 1024, La = 0.72, Et = 16, mt = (e, t, s) => Math.min(Math.max(e, Math.min(t, s)), s), xa = (e) => typeof e == "number" && Number.isFinite(e) && e > 0 ? e : void 0, Fa = (e, t, s) => {
1591
+ ], Zt = (e, t) => t ?? `${e?.trim() || za} AI 助手`, Oa = (e) => e ?? Wa, Ha = 480, Xt = 1024, qa = 0.72, Dt = 16, pt = (e, t, s) => Math.min(Math.max(e, Math.min(t, s)), s), Ka = (e) => typeof e == "number" && Number.isFinite(e) && e > 0 ? e : void 0, ja = (e, t, s) => {
1372
1592
  const i = Math.min(
1373
- Ht,
1374
- s * La
1593
+ Xt,
1594
+ s * qa
1375
1595
  );
1376
1596
  return Math.max(e, Math.min(t ?? i, s));
1377
- }, Pa = (e) => typeof e == "number" ? Number.isFinite(e) ? `${e}px` : void 0 : e?.trim() || void 0;
1597
+ }, Va = (e) => typeof e == "number" ? Number.isFinite(e) ? `${e}px` : void 0 : e?.trim() || void 0;
1378
1598
  class J extends Error {
1379
1599
  }
1380
1600
  const ot = (e, t) => {
1381
1601
  if (!(typeof e != "object" || e === null))
1382
1602
  return e[t];
1383
- }, Ba = (e) => {
1603
+ }, Za = (e) => {
1384
1604
  const t = ot(e, "status");
1385
1605
  return typeof t == "number" ? t : ot(
1386
1606
  ot(e, "response"),
1387
1607
  "status"
1388
1608
  );
1389
- }, za = (e) => {
1390
- const t = ot(e, "code"), s = Ba(e), i = e instanceof Error ? e.message : "", r = [t, i].filter((v) => typeof v == "string").join(" ").toLowerCase(), d = globalThis.navigator?.onLine === !1 || /network|fetch|timeout|offline|connection|网络|连接|超时/.test(r), p = typeof s == "number" && s >= 500 || /server|service|服务器|服务异常/.test(r);
1609
+ }, Xa = (e) => {
1610
+ const t = ot(e, "code"), s = Za(e), i = e instanceof Error ? e.message : "", o = [t, i].filter((b) => typeof b == "string").join(" ").toLowerCase(), d = globalThis.navigator?.onLine === !1 || /network|fetch|timeout|offline|connection|网络|连接|超时/.test(o), h = typeof s == "number" && s >= 500 || /server|service|服务器|服务异常/.test(o);
1391
1611
  return d ? {
1392
1612
  actionLabel: "重新连接",
1393
1613
  description: "请检查网络后再试。",
1394
1614
  kind: "network",
1395
1615
  label: "网络连接",
1396
1616
  title: "网络连接不可用"
1397
- } : p ? {
1617
+ } : h ? {
1398
1618
  actionLabel: "重新加载",
1399
1619
  description: "服务暂时未能响应,请稍后重试。",
1400
1620
  kind: "service",
@@ -1407,7 +1627,7 @@ const ot = (e, t) => {
1407
1627
  label: "加载异常",
1408
1628
  title: "暂时无法加载对话"
1409
1629
  };
1410
- }, St = (e) => {
1630
+ }, Bt = (e) => {
1411
1631
  try {
1412
1632
  const t = e?.return?.();
1413
1633
  if (!t) return;
@@ -1421,7 +1641,7 @@ const ot = (e, t) => {
1421
1641
  errorType: t instanceof Error ? t.name : typeof t
1422
1642
  });
1423
1643
  }
1424
- }, Wa = async (e) => {
1644
+ }, Ga = async (e) => {
1425
1645
  if (globalThis.navigator?.clipboard?.writeText) {
1426
1646
  await globalThis.navigator.clipboard.writeText(e);
1427
1647
  return;
@@ -1433,179 +1653,179 @@ const ot = (e, t) => {
1433
1653
  const s = document.execCommand("copy");
1434
1654
  if (t.remove(), !s)
1435
1655
  throw new Error("Clipboard copy failed");
1436
- }, Kt = () => /* @__PURE__ */ c("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1656
+ }, Gt = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1437
1657
  /* @__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" }),
1438
1658
  /* @__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" })
1439
- ] }), Ua = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m6 6 12 12M18 6 6 18" }) }), Oa = () => /* @__PURE__ */ c("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1659
+ ] }), Ya = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m6 6 12 12M18 6 6 18" }) }), Ja = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1440
1660
  /* @__PURE__ */ a("path", { d: "M8 8h10v12H8z" }),
1441
1661
  /* @__PURE__ */ a("path", { d: "M6 16H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
1442
- ] }), qa = () => /* @__PURE__ */ c("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1662
+ ] }), Qa = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1443
1663
  /* @__PURE__ */ a("path", { d: "M20 11a8 8 0 0 0-14.7-4.4L4 8" }),
1444
1664
  /* @__PURE__ */ a("path", { d: "M4 4v4h4" }),
1445
1665
  /* @__PURE__ */ a("path", { d: "M4 13a8 8 0 0 0 14.7 4.4L20 16" }),
1446
1666
  /* @__PURE__ */ a("path", { d: "M20 20v-4h-4" })
1447
- ] }), Ha = () => /* @__PURE__ */ c("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1667
+ ] }), es = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1448
1668
  /* @__PURE__ */ a("path", { d: "M12 4v11" }),
1449
1669
  /* @__PURE__ */ a("path", { d: "m7 10 5 5 5-5" }),
1450
1670
  /* @__PURE__ */ a("path", { d: "M5 20h14" })
1451
- ] }), Ka = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "M12 5v14M5 12h14" }) }), Va = () => /* @__PURE__ */ c("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1671
+ ] }), ts = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "M12 5v14M5 12h14" }) }), as = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1452
1672
  /* @__PURE__ */ a("path", { d: "M10 6h9M10 12h9M10 18h9" }),
1453
1673
  /* @__PURE__ */ a("path", { d: "M5 6h.01M5 12h.01M5 18h.01" })
1454
- ] }), ja = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m7 10 5 5 5-5" }) }), $t = () => /* @__PURE__ */ c("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1674
+ ] }), ss = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m7 10 5 5 5-5" }) }), Ut = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1455
1675
  /* @__PURE__ */ a("path", { d: "m4 4 17 8-17 8 3-8-3-8Z" }),
1456
1676
  /* @__PURE__ */ a("path", { d: "M7 12h14" })
1457
- ] }), Vt = () => /* @__PURE__ */ c("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1677
+ ] }), Yt = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1458
1678
  /* @__PURE__ */ a("path", { d: "M20 11a8 8 0 0 0-14.7-4.4L4 8" }),
1459
1679
  /* @__PURE__ */ a("path", { d: "M4 4v4h4" }),
1460
1680
  /* @__PURE__ */ a("path", { d: "M4 13a8 8 0 0 0 14.7 4.4L20 16" }),
1461
1681
  /* @__PURE__ */ a("path", { d: "M20 20v-4h-4" })
1462
- ] }), Xa = () => /* @__PURE__ */ c("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1682
+ ] }), ns = () => /* @__PURE__ */ l("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
1463
1683
  /* @__PURE__ */ a("circle", { cx: "12", cy: "12", r: "8" }),
1464
1684
  /* @__PURE__ */ a("path", { d: "M12 8v4.5" }),
1465
1685
  /* @__PURE__ */ a("path", { d: "M12 16h.01" })
1466
- ] }), ct = ({ className: e = "" }) => /* @__PURE__ */ a("span", { className: `make-ai-assistant__avatar ${e}`.trim(), "aria-hidden": "true", children: /* @__PURE__ */ a(Kt, {}) }), Za = ({ src: e }) => e ? /* @__PURE__ */ a("span", { className: "make-ai-assistant__user-avatar", "aria-hidden": "true", children: /* @__PURE__ */ a("img", { alt: "", src: e }) }) : null, Ga = ({
1686
+ ] }), ct = ({ className: e = "" }) => /* @__PURE__ */ a("span", { className: `make-ai-assistant__avatar ${e}`.trim(), "aria-hidden": "true", children: /* @__PURE__ */ a(Gt, {}) }), rs = ({ src: e }) => e ? /* @__PURE__ */ a("span", { className: "make-ai-assistant__user-avatar", "aria-hidden": "true", children: /* @__PURE__ */ a("img", { alt: "", src: e }) }) : null, is = ({
1467
1687
  userAvatarUrl: e,
1468
1688
  userName: t
1469
1689
  }) => {
1470
1690
  const s = t?.trim();
1471
- return !s && !e ? null : /* @__PURE__ */ c("div", { className: "make-ai-assistant__message-identity", children: [
1691
+ return !s && !e ? null : /* @__PURE__ */ l("div", { className: "make-ai-assistant__message-identity", children: [
1472
1692
  s ? /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-sender", children: s }) : null,
1473
- /* @__PURE__ */ a(Za, { src: e })
1693
+ /* @__PURE__ */ a(rs, { src: e })
1474
1694
  ] });
1475
- }, ht = (e) => {
1695
+ }, ft = (e) => {
1476
1696
  const t = e.trim();
1477
1697
  if (!(!t.startsWith("|") || !t.endsWith("|")))
1478
1698
  return t.slice(1, -1).split("|").map((s) => s.trim());
1479
- }, Ya = (e) => e.length > 0 && e.every((t) => /^:?-{3,}:?$/.test(t)), Ja = (e, t) => {
1480
- const s = ht(e[t] ?? ""), i = ht(e[t + 1] ?? "");
1481
- if (!s || !i || s.length !== i.length || !Ya(i))
1699
+ }, os = (e) => e.length > 0 && e.every((t) => /^:?-{3,}:?$/.test(t)), cs = (e, t) => {
1700
+ const s = ft(e[t] ?? ""), i = ft(e[t + 1] ?? "");
1701
+ if (!s || !i || s.length !== i.length || !os(i))
1482
1702
  return;
1483
- const r = [];
1484
- let o = t + 2;
1485
- for (; o < e.length; ) {
1486
- const d = ht(e[o] ?? "");
1703
+ const o = [];
1704
+ let c = t + 2;
1705
+ for (; c < e.length; ) {
1706
+ const d = ft(e[c] ?? "");
1487
1707
  if (!d || d.length !== s.length) break;
1488
- r.push(d), o += 1;
1708
+ o.push(d), c += 1;
1489
1709
  }
1490
- return { headers: s, lastIndex: o - 1, rows: r };
1491
- }, Qa = (e) => {
1492
- const t = [], s = [], i = [], r = [], o = e.replace(/\r\n?/g, `
1710
+ return { headers: s, lastIndex: c - 1, rows: o };
1711
+ }, ls = (e) => {
1712
+ const t = [], s = [], i = [], o = [], c = e.replace(/\r\n?/g, `
1493
1713
  `).split(`
1494
1714
  `), d = () => {
1495
- const h = s.join(`
1715
+ const f = s.join(`
1496
1716
  `).trim();
1497
- s.length = 0, h && t.push({ type: "paragraph", text: h });
1498
- }, p = () => {
1717
+ s.length = 0, f && t.push({ type: "paragraph", text: f });
1718
+ }, h = () => {
1499
1719
  i.length && t.push({ type: "list", items: i.splice(0) });
1500
- }, v = () => {
1501
- const h = r.join(`
1720
+ }, b = () => {
1721
+ const f = o.join(`
1502
1722
  `).trim();
1503
- r.length = 0, h && t.push({ type: "pre", text: h });
1723
+ o.length = 0, f && t.push({ type: "pre", text: f });
1504
1724
  };
1505
- for (let h = 0; h < o.length; h += 1) {
1506
- const _ = o[h] ?? "", F = _.trim();
1507
- if (!F) {
1508
- d(), p(), v();
1725
+ for (let f = 0; f < c.length; f += 1) {
1726
+ const $ = c[f] ?? "", L = $.trim();
1727
+ if (!L) {
1728
+ d(), h(), b();
1509
1729
  continue;
1510
1730
  }
1511
- const A = Ja(o, h);
1512
- if (A) {
1513
- d(), p(), v(), t.push({ headers: A.headers, rows: A.rows, type: "table" }), h = A.lastIndex;
1731
+ const T = cs(c, f);
1732
+ if (T) {
1733
+ d(), h(), b(), t.push({ headers: T.headers, rows: T.rows, type: "table" }), f = T.lastIndex;
1514
1734
  continue;
1515
1735
  }
1516
- const X = /^(#{1,6})\s+(.+)$/.exec(F);
1517
- if (X) {
1518
- d(), p(), v();
1519
- const B = (X[2] ?? "").replace(/\s+#+\s*$/, "").trim();
1520
- B && t.push({
1736
+ const j = /^(#{1,6})\s+(.+)$/.exec(L);
1737
+ if (j) {
1738
+ d(), h(), b();
1739
+ const U = (j[2] ?? "").replace(/\s+#+\s*$/, "").trim();
1740
+ U && t.push({
1521
1741
  type: "heading",
1522
- level: X[1]?.length,
1523
- text: B
1742
+ level: j[1]?.length,
1743
+ text: U
1524
1744
  });
1525
1745
  continue;
1526
1746
  }
1527
- if (/^\s*\|.+\|\s*$/.test(_)) {
1528
- d(), p(), r.push(_.trim());
1747
+ if (/^\s*\|.+\|\s*$/.test($)) {
1748
+ d(), h(), o.push($.trim());
1529
1749
  continue;
1530
1750
  }
1531
- const C = /^\s*[-*]\s+(.+)$/.exec(_);
1532
- if (C) {
1533
- d(), v(), i.push(C[1]?.trim() ?? "");
1751
+ const M = /^\s*[-*]\s+(.+)$/.exec($);
1752
+ if (M) {
1753
+ d(), b(), i.push(M[1]?.trim() ?? "");
1534
1754
  continue;
1535
1755
  }
1536
- p(), v(), s.push(F);
1756
+ h(), b(), s.push(L);
1537
1757
  }
1538
- return d(), p(), v(), t;
1539
- }, Xe = (e) => {
1758
+ return d(), h(), b(), t;
1759
+ }, Ze = (e) => {
1540
1760
  const t = [], s = /(\*\*[^*]+\*\*|`[^`]+`)/g;
1541
1761
  let i = 0;
1542
- for (const r of e.matchAll(s)) {
1543
- const o = r[0], d = r.index ?? 0;
1544
- d > i && t.push(e.slice(i, 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`)), i = d + o.length;
1762
+ for (const o of e.matchAll(s)) {
1763
+ const c = o[0], d = o.index ?? 0;
1764
+ d > i && t.push(e.slice(i, 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`)), i = d + c.length;
1545
1765
  }
1546
1766
  return i < e.length && t.push(e.slice(i)), t;
1547
- }, Dt = ({ content: e }) => {
1548
- const t = Qa(e);
1767
+ }, Ft = ({ content: e }) => {
1768
+ const t = ls(e);
1549
1769
  return t.length ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble make-ai-assistant__assistant-text", children: t.map((s, i) => {
1550
1770
  if (s.type === "heading") {
1551
- const r = s.level <= 2 ? "h3" : "h4";
1771
+ const o = s.level <= 2 ? "h3" : "h4";
1552
1772
  return /* @__PURE__ */ a(
1553
- r,
1773
+ o,
1554
1774
  {
1555
1775
  className: `make-ai-assistant__markdown-heading make-ai-assistant__markdown-heading--${s.level}`,
1556
- children: Xe(s.text)
1776
+ children: Ze(s.text)
1557
1777
  },
1558
1778
  `${i}-heading`
1559
1779
  );
1560
1780
  }
1561
- return s.type === "paragraph" ? /* @__PURE__ */ a("p", { children: Xe(s.text) }, `${i}-paragraph`) : s.type === "pre" ? /* @__PURE__ */ a("pre", { children: /* @__PURE__ */ a("code", { children: s.text }) }, `${i}-pre`) : s.type === "table" ? /* @__PURE__ */ a(
1781
+ return s.type === "paragraph" ? /* @__PURE__ */ a("p", { children: Ze(s.text) }, `${i}-paragraph`) : s.type === "pre" ? /* @__PURE__ */ a("pre", { children: /* @__PURE__ */ a("code", { children: s.text }) }, `${i}-pre`) : s.type === "table" ? /* @__PURE__ */ a(
1562
1782
  "div",
1563
1783
  {
1564
1784
  "aria-label": "表格内容,可横向滚动",
1565
1785
  className: "make-ai-assistant__markdown-table-scroll",
1566
1786
  role: "region",
1567
1787
  tabIndex: 0,
1568
- children: /* @__PURE__ */ c("table", { className: "make-ai-assistant__markdown-table", children: [
1569
- /* @__PURE__ */ a("thead", { children: /* @__PURE__ */ a("tr", { children: s.headers.map((r, o) => /* @__PURE__ */ a("th", { scope: "col", children: Xe(r) }, `${o}-${r}`)) }) }),
1570
- /* @__PURE__ */ a("tbody", { children: s.rows.map((r, o) => /* @__PURE__ */ a("tr", { children: r.map((d, p) => /* @__PURE__ */ a("td", { children: Xe(d) }, `${p}-${d}`)) }, `${o}-${r.join("|")}`)) })
1788
+ children: /* @__PURE__ */ l("table", { className: "make-ai-assistant__markdown-table", children: [
1789
+ /* @__PURE__ */ a("thead", { children: /* @__PURE__ */ a("tr", { children: s.headers.map((o, c) => /* @__PURE__ */ a("th", { scope: "col", children: Ze(o) }, `${c}-${o}`)) }) }),
1790
+ /* @__PURE__ */ a("tbody", { children: s.rows.map((o, c) => /* @__PURE__ */ a("tr", { children: o.map((d, h) => /* @__PURE__ */ a("td", { children: Ze(d) }, `${h}-${d}`)) }, `${c}-${o.join("|")}`)) })
1571
1791
  ] })
1572
1792
  },
1573
1793
  `${i}-table`
1574
- ) : /* @__PURE__ */ a("ul", { children: s.items.map((r, o) => /* @__PURE__ */ a("li", { children: Xe(r) }, `${o}-${r}`)) }, `${i}-list`);
1794
+ ) : /* @__PURE__ */ a("ul", { children: s.items.map((o, c) => /* @__PURE__ */ a("li", { children: Ze(o) }, `${c}-${o}`)) }, `${i}-list`);
1575
1795
  }) }) : null;
1576
- }, jt = ({ assistantName: e }) => /* @__PURE__ */ c("div", { className: "make-ai-assistant__message-identity", children: [
1796
+ }, Jt = ({ assistantName: e }) => /* @__PURE__ */ l("div", { className: "make-ai-assistant__message-identity", children: [
1577
1797
  /* @__PURE__ */ a(ct, { className: "make-ai-assistant__avatar--message" }),
1578
1798
  /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-sender", children: e })
1579
- ] }), Xt = (e) => {
1799
+ ] }), Qt = (e) => {
1580
1800
  for (let t = e.messages.length - 1; t >= 0; t -= 1) {
1581
1801
  const s = e.messages[t];
1582
1802
  if (s.role === "assistant" && s.status === "streaming")
1583
1803
  return s.id;
1584
1804
  }
1585
- }, es = (e) => {
1805
+ }, ds = (e) => {
1586
1806
  for (let t = e.messages.length - 1; t >= 0; t -= 1)
1587
1807
  if (e.messages[t].role === "user") return t;
1588
1808
  return -1;
1589
- }, Zt = (e) => {
1590
- const t = es(e);
1809
+ }, ea = (e) => {
1810
+ const t = ds(e);
1591
1811
  if (!(t < 0))
1592
1812
  for (let s = e.messages.length - 1; s > t; s -= 1) {
1593
1813
  const i = e.messages[s];
1594
1814
  if (i.role === "assistant") return i.id;
1595
1815
  }
1596
- }, ts = (e) => {
1816
+ }, us = (e) => {
1597
1817
  if (e.status === "idle")
1598
1818
  for (let t = e.messages.length - 1; t >= 0; t -= 1) {
1599
1819
  const s = e.messages[t];
1600
1820
  if (s.role === "assistant" && s.status === "complete")
1601
1821
  return s.id;
1602
1822
  }
1603
- }, as = (e) => {
1823
+ }, ms = (e) => {
1604
1824
  for (let t = e.messages.length - 1; t >= 0; t -= 1) {
1605
1825
  const s = e.messages[t];
1606
1826
  if (s.role === "user") return s;
1607
1827
  }
1608
- }, ss = (e, t) => {
1828
+ }, hs = (e, t) => {
1609
1829
  const s = e.messages.findIndex(
1610
1830
  (i) => i.id === t && i.role === "user"
1611
1831
  );
@@ -1616,43 +1836,43 @@ const ot = (e, t) => {
1616
1836
  status: "streaming",
1617
1837
  messages: s < 0 ? e.messages : e.messages.slice(0, s + 1)
1618
1838
  };
1619
- }, ns = (e) => e.scrollHeight - e.scrollTop - e.clientHeight <= 48, Lt = (e = "smooth") => globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : e, pt = (e, t) => {
1839
+ }, ps = (e) => e.scrollHeight - e.scrollTop - e.clientHeight <= 48, Pt = (e = "smooth") => globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : e, vt = (e, t) => {
1620
1840
  typeof e.scrollTo == "function" ? e.scrollTo({ top: e.scrollHeight, behavior: t }) : e.scrollTop = e.scrollHeight;
1621
- }, Gt = ({
1841
+ }, ta = ({
1622
1842
  error: e,
1623
1843
  onRetry: t
1624
- }) => /* @__PURE__ */ c(
1844
+ }) => /* @__PURE__ */ l(
1625
1845
  "div",
1626
1846
  {
1627
1847
  className: "make-ai-assistant__message-status make-ai-assistant__message-status--error",
1628
1848
  "data-error-presentation": "request-failed",
1629
1849
  role: "alert",
1630
1850
  children: [
1631
- /* @__PURE__ */ c("div", { className: "make-ai-assistant__message-status-header", children: [
1632
- /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-status-icon", "aria-hidden": "true", children: /* @__PURE__ */ a(Xa, {}) }),
1851
+ /* @__PURE__ */ l("div", { className: "make-ai-assistant__message-status-header", children: [
1852
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-status-icon", "aria-hidden": "true", children: /* @__PURE__ */ a(ns, {}) }),
1633
1853
  /* @__PURE__ */ a("strong", { children: "请求未完成" })
1634
1854
  ] }),
1635
1855
  /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-status-message", children: e.message }),
1636
- e.retryable && t ? /* @__PURE__ */ c(
1856
+ e.retryable && t ? /* @__PURE__ */ l(
1637
1857
  "button",
1638
1858
  {
1639
1859
  className: "make-ai-assistant__retry",
1640
1860
  type: "button",
1641
1861
  onClick: t,
1642
1862
  children: [
1643
- /* @__PURE__ */ a(Vt, {}),
1863
+ /* @__PURE__ */ a(Yt, {}),
1644
1864
  "重新发送"
1645
1865
  ]
1646
1866
  }
1647
1867
  ) : null
1648
1868
  ]
1649
1869
  }
1650
- ), rs = ({
1870
+ ), fs = ({
1651
1871
  error: e,
1652
1872
  onRetry: t
1653
1873
  }) => {
1654
- const s = za(e);
1655
- return /* @__PURE__ */ c(
1874
+ const s = Xa(e);
1875
+ return /* @__PURE__ */ l(
1656
1876
  "section",
1657
1877
  {
1658
1878
  "aria-live": "assertive",
@@ -1660,23 +1880,23 @@ const ot = (e, t) => {
1660
1880
  "data-load-failure-kind": s.kind,
1661
1881
  role: "alert",
1662
1882
  children: [
1663
- /* @__PURE__ */ a("span", { className: "make-ai-assistant__load-failure-icon", "aria-hidden": "true", children: /* @__PURE__ */ c("svg", { viewBox: "0 0 24 24", children: [
1883
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__load-failure-icon", "aria-hidden": "true", children: /* @__PURE__ */ l("svg", { viewBox: "0 0 24 24", children: [
1664
1884
  /* @__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" }),
1665
1885
  /* @__PURE__ */ a("path", { d: "m9.2 14.8 5.6-5.6M9.2 9.2l5.6 5.6" })
1666
1886
  ] }) }),
1667
- /* @__PURE__ */ c("div", { className: "make-ai-assistant__load-failure-copy", children: [
1887
+ /* @__PURE__ */ l("div", { className: "make-ai-assistant__load-failure-copy", children: [
1668
1888
  /* @__PURE__ */ a("span", { className: "make-ai-assistant__load-failure-label", children: s.label }),
1669
1889
  /* @__PURE__ */ a("h3", { children: s.title }),
1670
1890
  /* @__PURE__ */ a("p", { children: s.description })
1671
1891
  ] }),
1672
- /* @__PURE__ */ c(
1892
+ /* @__PURE__ */ l(
1673
1893
  "button",
1674
1894
  {
1675
1895
  className: "make-ai-assistant__retry make-ai-assistant__retry--primary",
1676
1896
  type: "button",
1677
1897
  onClick: t,
1678
1898
  children: [
1679
- /* @__PURE__ */ a(Vt, {}),
1899
+ /* @__PURE__ */ a(Yt, {}),
1680
1900
  s.actionLabel
1681
1901
  ]
1682
1902
  }
@@ -1684,60 +1904,81 @@ const ot = (e, t) => {
1684
1904
  ]
1685
1905
  }
1686
1906
  );
1687
- }, Yt = ({
1907
+ }, aa = ({
1688
1908
  active: e,
1689
1909
  steps: t
1690
1910
  }) => {
1911
+ const [s, i] = N(!1);
1691
1912
  if (!e || !t?.length) return null;
1692
- const s = t[t.length - 1] ?? "处理中";
1693
- return /* @__PURE__ */ c("details", { className: "make-ai-assistant__process", open: !0, children: [
1694
- /* @__PURE__ */ c("summary", { children: [
1695
- /* @__PURE__ */ c("span", { className: "make-ai-assistant__progress", role: "status", children: [
1696
- /* @__PURE__ */ a("span", { "aria-hidden": "true" }),
1697
- /* @__PURE__ */ a("span", { children: s })
1698
- ] }),
1699
- /* @__PURE__ */ c("span", { className: "make-ai-assistant__process-count", children: [
1700
- t.length,
1701
- " "
1702
- ] })
1703
- ] }),
1704
- /* @__PURE__ */ a("ol", { children: t.map((i, r) => /* @__PURE__ */ c(
1705
- "li",
1706
- {
1707
- "data-step-active": r === t.length - 1 ? !0 : void 0,
1708
- children: [
1709
- /* @__PURE__ */ a("span", { "aria-hidden": "true" }),
1710
- /* @__PURE__ */ a("span", { children: i })
1711
- ]
1712
- },
1713
- `${r}-${i}`
1714
- )) })
1715
- ] });
1716
- }, is = ({
1913
+ const o = t[t.length - 1] ?? "处理中";
1914
+ return /* @__PURE__ */ l(
1915
+ "details",
1916
+ {
1917
+ className: "make-ai-assistant__process",
1918
+ open: s,
1919
+ onToggle: (c) => i(c.currentTarget.open),
1920
+ children: [
1921
+ /* @__PURE__ */ l("summary", { "aria-label": `查看处理过程,共 ${t.length} 步`, children: [
1922
+ /* @__PURE__ */ l("span", { className: "make-ai-assistant__process-summary", children: [
1923
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__process-indicator", "aria-hidden": "true" }),
1924
+ /* @__PURE__ */ l("span", { className: "make-ai-assistant__process-copy", children: [
1925
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__process-title", children: "处理过程" }),
1926
+ /* @__PURE__ */ a(
1927
+ "span",
1928
+ {
1929
+ className: "make-ai-assistant__progress make-ai-assistant__process-latest",
1930
+ role: "status",
1931
+ children: o
1932
+ }
1933
+ )
1934
+ ] })
1935
+ ] }),
1936
+ /* @__PURE__ */ l("span", { className: "make-ai-assistant__process-count", children: [
1937
+ t.length,
1938
+ " 步"
1939
+ ] })
1940
+ ] }),
1941
+ /* @__PURE__ */ a("ol", { children: t.map((c, d) => /* @__PURE__ */ l(
1942
+ "li",
1943
+ {
1944
+ "data-step-active": d === t.length - 1 ? !0 : void 0,
1945
+ children: [
1946
+ /* @__PURE__ */ a("span", { "aria-hidden": "true" }),
1947
+ /* @__PURE__ */ a("span", { children: c })
1948
+ ]
1949
+ },
1950
+ `${d}-${c}`
1951
+ )) })
1952
+ ]
1953
+ }
1954
+ );
1955
+ }, vs = ({
1717
1956
  copyFeedback: e,
1718
- onCopy: t,
1719
- onRegenerate: s
1720
- }) => !t && !s ? null : /* @__PURE__ */ c("div", { className: "make-ai-assistant__reply-actions", "aria-label": "回复操作", children: [
1721
- t ? /* @__PURE__ */ a(
1957
+ feedback: t,
1958
+ onCopy: s,
1959
+ onRegenerate: i
1960
+ }) => !t && !s && !i ? null : /* @__PURE__ */ l("div", { className: "make-ai-assistant__reply-actions", "aria-label": "回复操作", children: [
1961
+ s ? /* @__PURE__ */ a(
1722
1962
  "button",
1723
1963
  {
1724
1964
  "aria-label": "复制回答",
1725
1965
  className: "make-ai-assistant__reply-action make-ai-assistant__reply-copy",
1726
1966
  "data-tooltip": "复制",
1727
1967
  type: "button",
1728
- onClick: t,
1729
- children: /* @__PURE__ */ a(Oa, {})
1968
+ onClick: s,
1969
+ children: /* @__PURE__ */ a(Ja, {})
1730
1970
  }
1731
1971
  ) : null,
1732
- s ? /* @__PURE__ */ a(
1972
+ t,
1973
+ i ? /* @__PURE__ */ a(
1733
1974
  "button",
1734
1975
  {
1735
1976
  "aria-label": "重新生成",
1736
1977
  className: "make-ai-assistant__reply-action make-ai-assistant__reply-regenerate",
1737
1978
  "data-tooltip": "重新生成",
1738
1979
  type: "button",
1739
- onClick: s,
1740
- children: /* @__PURE__ */ a(qa, {})
1980
+ onClick: i,
1981
+ children: /* @__PURE__ */ a(Qa, {})
1741
1982
  }
1742
1983
  ) : null,
1743
1984
  e ? /* @__PURE__ */ a(
@@ -1749,602 +1990,602 @@ const ot = (e, t) => {
1749
1990
  children: e.message
1750
1991
  }
1751
1992
  ) : null
1752
- ] }), xt = ({
1993
+ ] }), zt = ({
1753
1994
  assistantName: e,
1754
1995
  error: t,
1755
1996
  onRetry: s,
1756
1997
  progress: i
1757
1998
  }) => {
1758
- const r = t ? "error" : "progress";
1999
+ const o = t ? "error" : "progress";
1759
2000
  return t?.message ?? i?.message ? /* @__PURE__ */ a(
1760
2001
  "article",
1761
2002
  {
1762
- "aria-label": `${e}的${r === "error" ? "错误消息" : "状态消息"}`,
1763
- className: `make-ai-assistant__message make-ai-assistant__message--assistant make-ai-assistant__message--${r}`,
2003
+ "aria-label": `${e}的${o === "error" ? "错误消息" : "状态消息"}`,
2004
+ className: `make-ai-assistant__message make-ai-assistant__message--assistant make-ai-assistant__message--${o}`,
1764
2005
  "data-message-role": "assistant",
1765
- "data-message-state": r,
1766
- children: /* @__PURE__ */ c("div", { className: "make-ai-assistant__message-turn", children: [
1767
- /* @__PURE__ */ a(jt, { assistantName: e }),
1768
- /* @__PURE__ */ a("div", { className: "make-ai-assistant__message-stack", children: t ? /* @__PURE__ */ a(Gt, { error: t, onRetry: s }) : /* @__PURE__ */ a(Yt, { active: !0, steps: i?.steps }) })
2006
+ "data-message-state": o,
2007
+ children: /* @__PURE__ */ l("div", { className: "make-ai-assistant__message-turn", children: [
2008
+ /* @__PURE__ */ a(Jt, { assistantName: e }),
2009
+ /* @__PURE__ */ a("div", { className: "make-ai-assistant__message-stack", children: t ? /* @__PURE__ */ a(ta, { error: t, onRetry: s }) : /* @__PURE__ */ a(aa, { active: !0, steps: i?.steps }) })
1769
2010
  ] })
1770
2011
  }
1771
2012
  ) : null;
1772
- }, os = (e, t, s, i, r, o, d, p, v, h, _, F, A, X, C, B) => {
1773
- const g = Zt(e), L = Xt(e), U = ts(e);
1774
- let f;
1775
- return e.messages.map((l) => {
1776
- if (l.intermediate) return /* @__PURE__ */ c("details", { className: "make-ai-assistant__process", children: [
2013
+ }, gs = (e, t, s, i, o, c, d, h, b, f, $, L, T, j, M, U) => {
2014
+ const g = ea(e), R = Qt(e), P = us(e);
2015
+ let p;
2016
+ return e.messages.map((n) => {
2017
+ if (n.intermediate) return /* @__PURE__ */ l("details", { className: "make-ai-assistant__process", children: [
1777
2018
  /* @__PURE__ */ a("summary", { children: "处理过程" }),
1778
- /* @__PURE__ */ a(Dt, { content: l.content })
1779
- ] }, l.id);
1780
- const S = l.role === "assistant", T = f;
1781
- S || (f = l);
1782
- const te = l.id === L, R = l.id === g ? e.error : void 0, Z = l.error ?? R, G = !S && !!(v?.trim() || h), P = S ? d : v?.trim() || "用户", Q = S && l.status === "complete" && !Z && (l.content.trim() || l.id === U);
2019
+ /* @__PURE__ */ a(Ft, { content: n.content })
2020
+ ] }, n.id);
2021
+ const v = n.role === "assistant", k = p;
2022
+ v || (p = n);
2023
+ const q = n.id === R, I = n.id === g ? e.error : void 0, G = n.error ?? I, Y = !v && !!(b?.trim() || f), z = v ? d : b?.trim() || "用户", Q = v && n.status === "complete" && !G && (n.content.trim() || n.id === P), ve = !!(M && U?.features?.feedback && v && n.persistent), oe = Q || ve;
1783
2024
  return /* @__PURE__ */ a(
1784
2025
  "article",
1785
2026
  {
1786
- "aria-label": `${P}的消息`,
1787
- className: `make-ai-assistant__message make-ai-assistant__message--${l.role}`,
1788
- "data-message-role": l.role,
1789
- "data-message-state": Z ? "error" : void 0,
1790
- "data-message-status": l.status,
1791
- "data-message-has-identity": S || G ? !0 : void 0,
1792
- children: /* @__PURE__ */ c("div", { className: "make-ai-assistant__message-turn", children: [
1793
- S ? /* @__PURE__ */ a(jt, { assistantName: d }) : G ? /* @__PURE__ */ a(Ga, { userAvatarUrl: h, userName: v }) : null,
1794
- /* @__PURE__ */ c("div", { className: "make-ai-assistant__message-stack", children: [
1795
- S && l.responseId && e.responses?.[l.responseId]?.status === "cancelled" ? /* @__PURE__ */ a("p", { className: "make-ai-assistant__response-status", role: "status", children: "已停止生成" }) : null,
1796
- l.content ? S ? /* @__PURE__ */ a(Dt, { content: l.content }) : /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble", children: l.content }) : l.status === "streaming" ? /* @__PURE__ */ c("div", { className: "make-ai-assistant__typing", "aria-label": `${d}正在思考`, children: [
2027
+ "aria-label": `${z}的消息`,
2028
+ className: `make-ai-assistant__message make-ai-assistant__message--${n.role}`,
2029
+ "data-message-role": n.role,
2030
+ "data-message-state": G ? "error" : void 0,
2031
+ "data-message-status": n.status,
2032
+ "data-message-has-identity": v || Y ? !0 : void 0,
2033
+ children: /* @__PURE__ */ l("div", { className: "make-ai-assistant__message-turn", children: [
2034
+ v ? /* @__PURE__ */ a(Jt, { assistantName: d }) : Y ? /* @__PURE__ */ a(is, { userAvatarUrl: f, userName: b }) : null,
2035
+ /* @__PURE__ */ l("div", { className: "make-ai-assistant__message-stack", children: [
2036
+ v && n.responseId && e.responses?.[n.responseId]?.status === "cancelled" ? /* @__PURE__ */ a("p", { className: "make-ai-assistant__response-status", role: "status", children: "已停止生成" }) : null,
2037
+ n.content ? v ? /* @__PURE__ */ a(Ft, { content: n.content }) : /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble", children: n.content }) : n.status === "streaming" ? /* @__PURE__ */ l("div", { className: "make-ai-assistant__typing", "aria-label": `${d}正在思考`, children: [
1797
2038
  /* @__PURE__ */ a("span", {}),
1798
2039
  /* @__PURE__ */ a("span", {}),
1799
2040
  /* @__PURE__ */ a("span", {})
1800
2041
  ] }) : null,
1801
- S ? /* @__PURE__ */ a(
1802
- Yt,
2042
+ v ? /* @__PURE__ */ a(
2043
+ aa,
1803
2044
  {
1804
- active: te && e.status === "streaming",
1805
- steps: l.progressSteps
2045
+ active: q && e.status === "streaming",
2046
+ steps: n.progressSteps
1806
2047
  }
1807
2048
  ) : null,
1808
- Z ? /* @__PURE__ */ a(
1809
- Gt,
2049
+ G ? /* @__PURE__ */ a(
2050
+ ta,
1810
2051
  {
1811
- error: Z,
1812
- onRetry: R ? p : void 0
2052
+ error: G,
2053
+ onRetry: I ? h : void 0
1813
2054
  }
1814
2055
  ) : null,
1815
- l.artifacts.map((fe) => /* @__PURE__ */ a(
1816
- ra,
2056
+ n.artifacts.map((F) => /* @__PURE__ */ a(
2057
+ da,
1817
2058
  {
1818
- artifact: fe,
2059
+ artifact: F,
1819
2060
  context: t,
1820
- onAction: r,
1821
- onActionError: o,
2061
+ onAction: o,
2062
+ onActionError: c,
1822
2063
  registry: s,
1823
2064
  theme: i
1824
2065
  },
1825
- fe.id
2066
+ F.id
1826
2067
  )),
1827
- C && B && e.threadId ? /* @__PURE__ */ a(wa, { message: l, context: t, transport: B, chatId: e.threadId }) : null,
1828
- C && B?.features?.feedback ? /* @__PURE__ */ a(ka, { message: l, manager: C }) : null,
1829
- Q ? /* @__PURE__ */ a(
1830
- is,
2068
+ M && U && e.threadId ? /* @__PURE__ */ a(La, { message: n, context: t, transport: U, chatId: e.threadId }) : null,
2069
+ oe ? /* @__PURE__ */ a(
2070
+ vs,
1831
2071
  {
1832
- copyFeedback: _?.messageId === l.id ? {
1833
- message: _.message,
1834
- status: _.status
2072
+ copyFeedback: $?.messageId === n.id ? {
2073
+ message: $.message,
2074
+ status: $.status
1835
2075
  } : void 0,
1836
- onCopy: l.content.trim() ? () => A(l.id, l.content) : void 0,
1837
- onRegenerate: F && l.id === U && T ? () => X({
1838
- userMessage: T,
1839
- assistantMessage: l
2076
+ onCopy: n.content.trim() ? () => T(n.id, n.content) : void 0,
2077
+ feedback: M && ve ? /* @__PURE__ */ a(Ea, { message: n, manager: M }) : void 0,
2078
+ onRegenerate: L && n.id === P && k ? () => j({
2079
+ userMessage: k,
2080
+ assistantMessage: n
1840
2081
  }) : void 0
1841
2082
  }
1842
2083
  ) : null
1843
2084
  ] })
1844
2085
  ] })
1845
2086
  },
1846
- `${e.threadId ?? "local"}:${l.id}`
2087
+ `${e.threadId ?? "local"}:${n.id}`
1847
2088
  );
1848
2089
  });
1849
2090
  };
1850
- function Jt({
2091
+ function sa({
1851
2092
  assistantName: e = "AI 助手",
1852
2093
  brandName: t,
1853
2094
  context: s,
1854
2095
  onAction: i,
1855
- onActionError: r,
1856
- onClose: o,
2096
+ onActionError: o,
2097
+ onClose: c,
1857
2098
  onNewConversation: d,
1858
- headerHeight: p,
1859
- registry: v,
1860
- suggestions: h,
1861
- title: _,
1862
- theme: F,
1863
- transport: A,
1864
- userAvatarUrl: X,
1865
- userName: C,
1866
- visible: B
2099
+ headerHeight: h,
2100
+ registry: b,
2101
+ suggestions: f,
2102
+ title: $,
2103
+ theme: L,
2104
+ transport: T,
2105
+ userAvatarUrl: j,
2106
+ userName: M,
2107
+ visible: U
1867
2108
  }) {
1868
- const g = va(s, A), L = Na(s, A, g), U = qt(t, _), f = Pa(p), l = ft(F), S = l || f ? {
1869
- ...l,
1870
- ...f ? { "--make-ai-internal-header-height": f } : {}
1871
- } : void 0, [T, te] = E(""), [R, Z] = E(!1), [G, P] = E(!1), Q = g.enabled ? A.scopeKey?.(s) ?? s.app.id : "";
1872
- Ft(() => {
1873
- g.enabled && te("");
2109
+ const g = _a(s, T), R = Ba(s, T, g), P = Zt(t, $), p = Va(h), n = yt(L), v = n || p ? {
2110
+ ...n,
2111
+ ...p ? { "--make-ai-internal-header-height": p } : {}
2112
+ } : void 0, [k, q] = N(""), [I, G] = N(!1), [Y, z] = N(!1), Q = g.enabled ? T.scopeKey?.(s) ?? s.app.id : "";
2113
+ gt(() => {
2114
+ g.enabled && q("");
1874
2115
  }, [Q, g.enabled]);
1875
- const [fe, ve] = E(pe), z = g.enabled ? g.state : fe, ne = g.enabled ? g.setState : ve, ce = N(z);
1876
- ce.current = z;
1877
- const [K, x] = E(void 0), [w, O] = E(void 0), [ae, ge] = E(0), [Ee, $] = E(() => A.loadConversation ? "loading" : "ready"), ee = g.enabled ? g.loading && !z.messages.length ? "loading" : "ready" : Ee, [le, de] = E(void 0), [ze, Y] = E(!1), re = N(void 0), me = N(void 0), we = N(0), We = N(null), Ie = N(null), Ze = N(null), Ue = N(null), Oe = N(null), Ge = N(null), ye = N(!0), Ye = N(s.app.id), Je = N(B), Qe = aa(), et = Ct(
1878
- () => v ?? fa(),
1879
- [v]
1880
- ), Te = Ct(
1881
- () => $a(h),
1882
- [h]
1883
- ), n = (u) => {
1884
- const H = re.current, j = me.current?.iterator;
1885
- return !H && !j ? !1 : (we.current += 1, re.current = void 0, me.current = void 0, console.info("[make-ai-assistant] local run cancellation requested", { reason: u }), H?.abort(), St(j), !0);
2116
+ const [ve, oe] = N(fe), F = g.enabled ? g.state : ve, ne = g.enabled ? g.setState : oe, ce = S(F);
2117
+ ce.current = F;
2118
+ const [V, B] = N(void 0), [A, W] = N(void 0), [ae, ge] = N(0), [Re, x] = N(() => T.loadConversation ? "loading" : "ready"), ee = g.enabled ? g.loading && !F.messages.length ? "loading" : "ready" : Re, [le, de] = N(void 0), [lt, ye] = N(!1), we = S(void 0), be = S(void 0), te = S(0), Ce = S(null), ke = S(null), Oe = S(null), He = S(null), Ee = S(null), Xe = S(null), me = S(!0), Ge = S(s.app.id), Ye = S(U), Je = ia(), Qe = Rt(
2119
+ () => b ?? ka(),
2120
+ [b]
2121
+ ), et = Rt(
2122
+ () => Oa(f),
2123
+ [f]
2124
+ ), xe = (m) => {
2125
+ const K = we.current, X = be.current?.iterator;
2126
+ return !K && !X ? !1 : (te.current += 1, we.current = void 0, be.current = void 0, console.info("[make-ai-assistant] local run cancellation requested", { reason: m }), K?.abort(), Bt(X), !0);
1886
2127
  };
1887
- oe(() => () => {
1888
- n("unmount");
1889
- }, []), oe(() => {
2128
+ ie(() => () => {
2129
+ xe("unmount");
2130
+ }, []), ie(() => {
1890
2131
  if (g.enabled) return;
1891
- const u = A.loadConversation, H = Ye.current !== s.app.id;
1892
- if (Ye.current = s.app.id, n("reinitialize"), H && (te(""), ye.current = !0), x(void 0), O(void 0), Y(!1), ne(pe()), !u) {
1893
- de(void 0), $("ready");
2132
+ const m = T.loadConversation, K = Ge.current !== s.app.id;
2133
+ if (Ge.current = s.app.id, xe("reinitialize"), K && (q(""), me.current = !0), B(void 0), W(void 0), ye(!1), ne(fe()), !m) {
2134
+ de(void 0), x("ready");
1894
2135
  return;
1895
2136
  }
1896
- const j = new AbortController();
1897
- return de(void 0), $("loading"), console.info("[make-ai-assistant] conversation load start", {
2137
+ const X = new AbortController();
2138
+ return de(void 0), x("loading"), console.info("[make-ai-assistant] conversation load start", {
1898
2139
  appId: s.app.id
1899
- }), u.call(A, s, { signal: j.signal }).then((se) => {
1900
- j.signal.aborted || (ne(pe(se)), $("ready"), console.info("[make-ai-assistant] conversation load success", {
2140
+ }), m.call(T, s, { signal: X.signal }).then((se) => {
2141
+ X.signal.aborted || (ne(fe(se)), x("ready"), console.info("[make-ai-assistant] conversation load success", {
1901
2142
  appId: s.app.id,
1902
2143
  messageCount: se.messages.length
1903
2144
  }));
1904
2145
  }).catch((se) => {
1905
- j.signal.aborted || (console.error("[make-ai-assistant] conversation load failed", {
2146
+ X.signal.aborted || (console.error("[make-ai-assistant] conversation load failed", {
1906
2147
  appId: s.app.id,
1907
2148
  errorType: se instanceof Error ? se.name : typeof se
1908
- }), de(se), $("error"));
1909
- }), () => j.abort();
1910
- }, [s.app.id, ae, A, g.enabled]), oe(() => {
1911
- const u = Ie.current;
1912
- if (!u || !ye.current) return;
1913
- Y(!1);
1914
- const H = requestAnimationFrame(() => {
1915
- if (!ye.current) return;
1916
- const j = z.status === "streaming" || globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
1917
- pt(u, j);
2149
+ }), de(se), x("error"));
2150
+ }), () => X.abort();
2151
+ }, [s.app.id, ae, T, g.enabled]), ie(() => {
2152
+ const m = ke.current;
2153
+ if (!m || !me.current) return;
2154
+ ye(!1);
2155
+ const K = requestAnimationFrame(() => {
2156
+ if (!me.current) return;
2157
+ const X = F.status === "streaming" || globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
2158
+ vt(m, X);
1918
2159
  });
1919
- return () => cancelAnimationFrame(H);
1920
- }, [z.messages, z.progress, z.status]), oe(() => {
1921
- B || (Z(!1), P(!1));
1922
- }, [B]), oe(() => {
1923
- const u = B && !Je.current;
1924
- if (Je.current = B, !u) return;
1925
- const H = requestAnimationFrame(() => {
1926
- const j = Ie.current;
1927
- if (j && ye.current) {
1928
- Y(!1);
1929
- const He = ce.current.status === "streaming" ? "auto" : Lt();
1930
- pt(j, He);
1931
- } else j && Y(ce.current.messages.length > 0);
1932
- const se = Ze.current;
1933
- (se && !se.disabled ? se : Ge.current ?? We.current?.querySelector("button:not(:disabled)"))?.focus();
2160
+ return () => cancelAnimationFrame(K);
2161
+ }, [F.messages, F.progress, F.status]), ie(() => {
2162
+ U || (G(!1), z(!1));
2163
+ }, [U]), ie(() => {
2164
+ const m = U && !Ye.current;
2165
+ if (Ye.current = U, !m) return;
2166
+ const K = requestAnimationFrame(() => {
2167
+ const X = ke.current;
2168
+ if (X && me.current) {
2169
+ ye(!1);
2170
+ const qe = ce.current.status === "streaming" ? "auto" : Pt();
2171
+ vt(X, qe);
2172
+ } else X && ye(ce.current.messages.length > 0);
2173
+ const se = Oe.current;
2174
+ (se && !se.disabled ? se : Xe.current ?? Ce.current?.querySelector("button:not(:disabled)"))?.focus();
1934
2175
  });
1935
- return () => cancelAnimationFrame(H);
1936
- }, [B]);
1937
- const m = () => {
1938
- const u = Ie.current;
1939
- if (!u) return;
1940
- const H = ns(u);
1941
- ye.current = H, Y(!H && ce.current.messages.length > 0);
1942
- }, y = () => {
1943
- const u = Ie.current;
1944
- if (!u) return;
1945
- ye.current = !0, Y(!1);
1946
- const H = Lt();
1947
- pt(u, H);
1948
- }, b = async (u, H) => {
1949
- const j = u.trim(), se = ce.current, Me = H?.regenerateFrom, He = A.regenerate;
1950
- if (!j || ee !== "ready" || se.status === "streaming" || re.current || Me && !He) return;
2176
+ return () => cancelAnimationFrame(K);
2177
+ }, [U]);
2178
+ const dt = () => {
2179
+ const m = ke.current;
2180
+ if (!m) return;
2181
+ const K = ps(m);
2182
+ me.current = K, ye(!K && ce.current.messages.length > 0);
2183
+ }, Se = () => {
2184
+ const m = ke.current;
2185
+ if (!m) return;
2186
+ me.current = !0, ye(!1);
2187
+ const K = Pt();
2188
+ vt(m, K);
2189
+ }, r = async (m, K) => {
2190
+ const X = m.trim(), se = ce.current, Ae = K?.regenerateFrom, qe = T.regenerate;
2191
+ if (!X || ee !== "ready" || se.status === "streaming" || we.current || Ae && !qe) return;
1951
2192
  if (it(
1952
- j,
2193
+ X,
1953
2194
  ue.messageCharacters
1954
2195
  ) > ue.messageCharacters) {
1955
- x(
2196
+ B(
1956
2197
  `输入内容过长,请控制在 ${ue.messageCharacters} 个字符以内`
1957
2198
  );
1958
2199
  return;
1959
2200
  }
1960
2201
  const at = {
1961
- id: Me?.userMessage.id ?? Ra("user"),
1962
- content: j
1963
- }, st = Me ? ss(se, Me.userMessage.id) : zt(se, at), nt = new AbortController(), De = we.current + 1;
1964
- we.current = De, re.current = nt, x(void 0), O(void 0), Y(!ye.current && se.messages.length > 0), Me || te(""), ne(st);
2202
+ id: Ae?.userMessage.id ?? Pa("user"),
2203
+ content: X
2204
+ }, st = Ae ? hs(se, Ae.userMessage.id) : Ht(se, at), nt = new AbortController(), Be = te.current + 1;
2205
+ te.current = Be, we.current = nt, B(void 0), W(void 0), ye(!me.current && se.messages.length > 0), Ae || q(""), ne(st);
1965
2206
  try {
1966
- let Re = !1, ie, yt = 0, bt = 0, kt = 0, lt = 0, Ke = 0;
1967
- const Ve = /* @__PURE__ */ new Map(), _t = /* @__PURE__ */ new Set(), wt = /* @__PURE__ */ new Set(
2207
+ let Te = !1, re, kt = 0, _t = 0, wt = 0, ut = 0, Ke = 0;
2208
+ const je = /* @__PURE__ */ new Map(), It = /* @__PURE__ */ new Set(), At = /* @__PURE__ */ new Set(
1968
2209
  [
1969
2210
  ...st.messages.map((rt) => rt.id),
1970
2211
  at.id
1971
2212
  ]
1972
- ), je = /* @__PURE__ */ new Set(), It = na(et), At = { signal: nt.signal };
1973
- let dt;
1974
- if (Me) {
1975
- if (!He)
2213
+ ), Ve = /* @__PURE__ */ new Set(), Mt = ca(Qe), Nt = { signal: nt.signal };
2214
+ let mt;
2215
+ if (Ae) {
2216
+ if (!qe)
1976
2217
  throw new J("当前 AI 助手不支持重新生成");
1977
- dt = He({
2218
+ mt = qe({
1978
2219
  threadId: st.threadId,
1979
2220
  message: at,
1980
2221
  assistantMessage: {
1981
- id: Me.assistantMessage.id,
1982
- content: Me.assistantMessage.content
2222
+ id: Ae.assistantMessage.id,
2223
+ content: Ae.assistantMessage.content
1983
2224
  },
1984
2225
  context: s,
1985
- capabilities: It
1986
- }, At);
2226
+ capabilities: Mt
2227
+ }, Nt);
1987
2228
  } else
1988
- dt = A.run(
2229
+ mt = T.run(
1989
2230
  {
1990
2231
  threadId: st.threadId,
1991
2232
  message: at,
1992
2233
  context: s,
1993
- capabilities: It
2234
+ capabilities: Mt
1994
2235
  },
1995
- At
2236
+ Nt
1996
2237
  );
1997
- const Mt = dt[Symbol.asyncIterator]();
1998
- for (me.current = { iterator: Mt, requestVersion: De }; ; ) {
1999
- const rt = await Mt.next();
2000
- if (we.current !== De || rt.done) break;
2001
- let M;
2238
+ const Ct = mt[Symbol.asyncIterator]();
2239
+ for (be.current = { iterator: Ct, requestVersion: Be }; ; ) {
2240
+ const rt = await Ct.next();
2241
+ if (te.current !== Be || rt.done) break;
2242
+ let E;
2002
2243
  try {
2003
- M = Bt(rt.value);
2004
- } catch (he) {
2244
+ E = Ot(rt.value);
2245
+ } catch (pe) {
2005
2246
  throw new J(
2006
- he instanceof Error ? he.message : "Invalid assistant event"
2247
+ pe instanceof Error ? pe.message : "Invalid assistant event"
2007
2248
  );
2008
2249
  }
2009
- if (M.type === "message.start") {
2010
- if (ie !== void 0 && ie !== M.runId)
2250
+ if (E.type === "message.start") {
2251
+ if (re !== void 0 && re !== E.runId)
2011
2252
  throw new J("AI 助手响应 run id 不一致");
2012
- if (ie ??= M.runId, bt += 1, bt > ue.assistantMessagesPerRun)
2253
+ if (re ??= E.runId, _t += 1, _t > ue.assistantMessagesPerRun)
2013
2254
  throw new J("AI 助手单次响应消息数量超过限制");
2014
- if (wt.has(M.messageId))
2255
+ if (At.has(E.messageId))
2015
2256
  throw new J("AI 助手响应包含重复的 message id");
2016
- wt.add(M.messageId), je.add(M.messageId), Ve.set(M.messageId, 0);
2257
+ At.add(E.messageId), Ve.add(E.messageId), je.set(E.messageId, 0);
2017
2258
  }
2018
- if (M.type === "message.delta") {
2019
- if (!je.has(M.messageId))
2259
+ if (E.type === "message.delta") {
2260
+ if (!Ve.has(E.messageId))
2020
2261
  throw new J("AI 助手响应事件顺序无效");
2021
- const he = Ve.get(M.messageId) ?? 0, Le = it(
2022
- M.delta,
2262
+ const pe = je.get(E.messageId) ?? 0, Ue = it(
2263
+ E.delta,
2023
2264
  ue.messageCharacters - Ke
2024
2265
  );
2025
- if (Ke + Le > ue.messageCharacters)
2266
+ if (Ke + Ue > ue.messageCharacters)
2026
2267
  throw new J("AI 助手响应文本超过大小限制");
2027
- Ke += Le, Ve.set(
2028
- M.messageId,
2029
- he + Le
2268
+ Ke += Ue, je.set(
2269
+ E.messageId,
2270
+ pe + Ue
2030
2271
  );
2031
2272
  }
2032
- if (M.type === "message.replace") {
2033
- if (!je.has(M.messageId))
2273
+ if (E.type === "message.replace") {
2274
+ if (!Ve.has(E.messageId))
2034
2275
  throw new J("AI 助手响应事件顺序无效");
2035
- const he = Ve.get(M.messageId) ?? 0, Le = it(
2036
- M.content,
2276
+ const pe = je.get(E.messageId) ?? 0, Ue = it(
2277
+ E.content,
2037
2278
  ue.messageCharacters
2038
- ), Nt = Ke - he + Le;
2039
- if (Nt > ue.messageCharacters)
2279
+ ), Tt = Ke - pe + Ue;
2280
+ if (Tt > ue.messageCharacters)
2040
2281
  throw new J("AI 助手响应文本超过大小限制");
2041
- Ke = Nt, Ve.set(M.messageId, Le);
2282
+ Ke = Tt, je.set(E.messageId, Ue);
2042
2283
  }
2043
- if (M.type === "run.progress") {
2044
- if (ie !== void 0 && ie !== M.runId)
2284
+ if (E.type === "run.progress") {
2285
+ if (re !== void 0 && re !== E.runId)
2045
2286
  throw new J("AI 助手响应 run id 不一致");
2046
- if (ie ??= M.runId, kt += 1, kt > ue.progressStepsPerRun)
2287
+ if (re ??= E.runId, wt += 1, wt > ue.progressStepsPerRun)
2047
2288
  throw new J("AI 助手处理过程数量超过限制");
2048
- const he = it(
2049
- M.message,
2050
- ue.progressCharactersPerRun - lt
2289
+ const pe = it(
2290
+ E.message,
2291
+ ue.progressCharactersPerRun - ut
2051
2292
  );
2052
- if (lt + he > ue.progressCharactersPerRun)
2293
+ if (ut + pe > ue.progressCharactersPerRun)
2053
2294
  throw new J("AI 助手处理过程文本超过大小限制");
2054
- lt += he;
2295
+ ut += pe;
2055
2296
  }
2056
- if (M.type === "artifact") {
2057
- if (!je.has(M.messageId))
2297
+ if (E.type === "artifact") {
2298
+ if (!Ve.has(E.messageId))
2058
2299
  throw new J("AI 助手响应事件顺序无效");
2059
- if (yt += 1, yt > ue.artifactsPerRun)
2300
+ if (kt += 1, kt > ue.artifactsPerRun)
2060
2301
  throw new J("AI 助手单次响应 Artifact 数量超过限制");
2061
- if (_t.has(M.artifact.id))
2302
+ if (It.has(E.artifact.id))
2062
2303
  throw new J("AI 助手响应包含重复的 Artifact id");
2063
- _t.add(M.artifact.id);
2304
+ It.add(E.artifact.id);
2064
2305
  }
2065
- if (M.type === "message.complete" && !je.delete(M.messageId))
2306
+ if (E.type === "message.complete" && !Ve.delete(E.messageId))
2066
2307
  throw new J("AI 助手响应事件顺序无效");
2067
- if (M.type === "run.complete" && ie !== void 0 && ie !== M.runId)
2308
+ if (E.type === "run.complete" && re !== void 0 && re !== E.runId)
2068
2309
  throw new J("AI 助手响应 run id 不一致");
2069
- if (M.type === "run.cancelled" && M.runId !== void 0 && ie !== void 0 && ie !== M.runId)
2310
+ if (E.type === "run.cancelled" && E.runId !== void 0 && re !== void 0 && re !== E.runId)
2070
2311
  throw new J("AI 助手响应 run id 不一致");
2071
- if (ne((he) => Ne(he, M)), M.type === "error" || M.type === "run.cancelled" || M.type === "run.complete") {
2072
- Re = !0;
2312
+ if (ne((pe) => Me(pe, E)), E.type === "error" || E.type === "run.cancelled" || E.type === "run.complete") {
2313
+ Te = !0;
2073
2314
  break;
2074
2315
  }
2075
2316
  }
2076
- if (!Re)
2317
+ if (!Te)
2077
2318
  throw new J("AI 助手流式响应在终止事件前结束");
2078
- } catch (Re) {
2079
- if (we.current !== De) return;
2319
+ } catch (Te) {
2320
+ if (te.current !== Be) return;
2080
2321
  if (nt.signal.aborted) {
2081
2322
  ne(
2082
- (ie) => Ne(ie, { type: "run.cancelled" })
2323
+ (re) => Me(re, { type: "run.cancelled" })
2083
2324
  );
2084
2325
  return;
2085
2326
  }
2086
2327
  console.error("[make-ai-assistant] assistant run failed", {
2087
2328
  appId: s.app.id,
2088
- errorType: Re instanceof Error ? Re.name : typeof Re
2329
+ errorType: Te instanceof Error ? Te.name : typeof Te
2089
2330
  }), ne(
2090
- (ie) => Ne(ie, {
2331
+ (re) => Me(re, {
2091
2332
  type: "error",
2092
2333
  code: "TRANSPORT_ERROR",
2093
- message: Re instanceof J ? Re.message : "连接失败,请重试",
2334
+ message: Te instanceof J ? Te.message : "连接失败,请重试",
2094
2335
  retryable: !0
2095
2336
  })
2096
2337
  );
2097
2338
  } finally {
2098
- we.current === De && re.current === nt && (re.current = void 0), me.current?.requestVersion === De && (St(me.current.iterator), me.current = void 0);
2339
+ te.current === Be && we.current === nt && (we.current = void 0), be.current?.requestVersion === Be && (Bt(be.current.iterator), be.current = void 0);
2099
2340
  }
2100
- }, I = (u) => {
2341
+ }, u = (m) => {
2101
2342
  if (g.enabled) {
2102
- if (L.pending)
2103
- return x("请等待附件上传完成,或移除失败的附件"), Promise.resolve();
2104
- const H = u.trim(), j = L.parts.length ? [...H ? [{ id: Fe(), kind: "text", text: H }] : [], ...L.parts] : void 0;
2105
- return te(""), L.clear(), g.send(H, j);
2343
+ if (R.pending)
2344
+ return B("请等待附件上传完成,或移除失败的附件"), Promise.resolve();
2345
+ const K = m.trim(), X = R.parts.length ? [...K ? [{ id: Pe(), kind: "text", text: K }] : [], ...R.parts] : void 0;
2346
+ return q(""), R.clear(), g.send(K, X);
2106
2347
  }
2107
- return b(u);
2108
- }, D = (u) => b(u.userMessage.content, { regenerateFrom: u }), k = async (u, H) => {
2348
+ return r(m);
2349
+ }, y = (m) => r(m.userMessage.content, { regenerateFrom: m }), w = async (m, K) => {
2109
2350
  try {
2110
- await Wa(H), O({ messageId: u, message: "已复制", status: "success" });
2111
- } catch (j) {
2351
+ await Ga(K), W({ messageId: m, message: "已复制", status: "success" });
2352
+ } catch (X) {
2112
2353
  console.error("[make-ai-assistant] copy answer failed", {
2113
- errorType: j instanceof Error ? j.name : typeof j
2114
- }), O({ messageId: u, message: "复制失败", status: "error" });
2354
+ errorType: X instanceof Error ? X.name : typeof X
2355
+ }), W({ messageId: m, message: "复制失败", status: "error" });
2115
2356
  }
2116
- }, V = (u) => {
2117
- u.preventDefault(), I(T);
2118
- }, q = (u) => {
2119
- u.key === "Enter" && !u.shiftKey && !u.nativeEvent.isComposing && (u.preventDefault(), I(T));
2120
- }, W = () => {
2357
+ }, C = (m) => {
2358
+ m.preventDefault(), u(k);
2359
+ }, D = (m) => {
2360
+ m.key === "Enter" && !m.shiftKey && !m.nativeEvent.isComposing && (m.preventDefault(), u(k));
2361
+ }, _ = () => {
2121
2362
  if (g.enabled) {
2122
2363
  g.stop();
2123
2364
  return;
2124
2365
  }
2125
- n("stop") && ne(
2126
- (u) => Ne(u, { type: "run.cancelled" })
2366
+ xe("stop") && ne(
2367
+ (m) => Me(m, { type: "run.cancelled" })
2127
2368
  );
2128
- }, be = () => {
2129
- if (P(!1), g.enabled) {
2130
- te(""), g.create(), d?.();
2369
+ }, Z = () => {
2370
+ if (z(!1), g.enabled) {
2371
+ q(""), g.create(), d?.();
2131
2372
  return;
2132
2373
  }
2133
- n("new-conversation"), te(""), x(void 0), O(void 0), Y(!1), ye.current = !0, ne(pe()), d?.();
2134
- }, qe = g.enabled && g.cancelling.length ? "停止中" : A.features?.remoteCancellation === !1 ? "停止接收" : "停止生成", tt = Xt(z), ke = Zt(z), Ae = as(z), $e = typeof A.regenerate == "function" && A.features?.regeneration !== !1, gt = () => {
2374
+ xe("new-conversation"), q(""), B(void 0), W(void 0), ye(!1), me.current = !0, ne(fe()), d?.();
2375
+ }, O = g.enabled && g.cancelling.length ? "停止中" : T.features?.remoteCancellation === !1 ? "停止接收" : "停止生成", H = Qt(F), Ie = ea(F), Le = ms(F), tt = typeof T.regenerate == "function" && T.features?.regeneration !== !1, he = () => {
2135
2376
  if (g.enabled) {
2136
2377
  g.retry();
2137
2378
  return;
2138
2379
  }
2139
- Ae && I(Ae.content);
2140
- }, Qt = (u) => {
2141
- if (u.key === "Escape" && !(!R && !G)) {
2142
- if (u.preventDefault(), u.stopPropagation(), R) {
2143
- Z(!1), Ue.current?.focus();
2380
+ Le && u(Le.content);
2381
+ }, De = (m) => {
2382
+ if (m.key === "Escape" && !(!I && !Y)) {
2383
+ if (m.preventDefault(), m.stopPropagation(), I) {
2384
+ G(!1), He.current?.focus();
2144
2385
  return;
2145
2386
  }
2146
- P(!1), Oe.current?.focus();
2387
+ z(!1), Ee.current?.focus();
2147
2388
  }
2148
2389
  };
2149
- return /* @__PURE__ */ c(
2390
+ return /* @__PURE__ */ l(
2150
2391
  "section",
2151
2392
  {
2152
2393
  className: `make-ai-assistant make-ai-assistant__panel${g.enabled ? " make-ai-assistant__panel--managed" : ""}`,
2153
- ref: We,
2154
- style: S,
2155
- onKeyDown: Qt,
2156
- onDragOver: (u) => {
2157
- L.enabled && u.dataTransfer.types.includes("Files") && u.preventDefault();
2394
+ ref: Ce,
2395
+ style: v,
2396
+ onKeyDown: De,
2397
+ onDragOver: (m) => {
2398
+ R.enabled && m.dataTransfer.types.includes("Files") && m.preventDefault();
2158
2399
  },
2159
- onDrop: (u) => {
2160
- L.enabled && u.dataTransfer.files.length && (u.preventDefault(), L.add(Array.from(u.dataTransfer.files)));
2400
+ onDrop: (m) => {
2401
+ R.enabled && m.dataTransfer.files.length && (m.preventDefault(), R.add(Array.from(m.dataTransfer.files)));
2161
2402
  },
2162
2403
  children: [
2163
- /* @__PURE__ */ c("header", { className: "make-ai-assistant__header", children: [
2164
- /* @__PURE__ */ a("div", { className: "make-ai-assistant__header-leading", children: g.enabled ? /* @__PURE__ */ c(
2404
+ /* @__PURE__ */ l("header", { className: "make-ai-assistant__header", children: [
2405
+ /* @__PURE__ */ a("div", { className: "make-ai-assistant__header-leading", children: g.enabled ? /* @__PURE__ */ l(
2165
2406
  "button",
2166
2407
  {
2167
- "aria-controls": Qe,
2168
- "aria-expanded": G,
2408
+ "aria-controls": Je,
2409
+ "aria-expanded": Y,
2169
2410
  "aria-haspopup": "dialog",
2170
2411
  "aria-label": "任务列表",
2171
2412
  className: "make-ai-assistant__task-list-trigger",
2172
- ref: Oe,
2413
+ ref: Ee,
2173
2414
  type: "button",
2174
- onClick: () => P((u) => !u),
2415
+ onClick: () => z((m) => !m),
2175
2416
  children: [
2176
- /* @__PURE__ */ a(Va, {}),
2417
+ /* @__PURE__ */ a(as, {}),
2177
2418
  /* @__PURE__ */ a("span", { children: "任务列表" }),
2178
- /* @__PURE__ */ a(ja, {})
2419
+ /* @__PURE__ */ a(ss, {})
2179
2420
  ]
2180
2421
  }
2181
2422
  ) : null }),
2182
- /* @__PURE__ */ c("div", { className: "make-ai-assistant__header-center", children: [
2423
+ /* @__PURE__ */ l("div", { className: "make-ai-assistant__header-center", children: [
2183
2424
  /* @__PURE__ */ a(ct, {}),
2184
- /* @__PURE__ */ a("h2", { className: "make-ai-assistant__header-title", title: U, children: U })
2425
+ /* @__PURE__ */ a("h2", { className: "make-ai-assistant__header-title", title: P, children: P })
2185
2426
  ] }),
2186
- /* @__PURE__ */ c("div", { className: "make-ai-assistant__header-actions", children: [
2187
- A.features?.newConversation !== !1 ? /* @__PURE__ */ a(
2427
+ /* @__PURE__ */ l("div", { className: "make-ai-assistant__header-actions", children: [
2428
+ T.features?.newConversation !== !1 ? /* @__PURE__ */ a(
2188
2429
  "button",
2189
2430
  {
2190
2431
  "aria-label": "新建对话",
2191
2432
  className: "make-ai-assistant__icon-button",
2192
2433
  type: "button",
2193
- onClick: be,
2194
- children: /* @__PURE__ */ a(Ka, {})
2434
+ onClick: Z,
2435
+ children: /* @__PURE__ */ a(ts, {})
2195
2436
  }
2196
2437
  ) : null,
2197
- o ? /* @__PURE__ */ a(
2438
+ c ? /* @__PURE__ */ a(
2198
2439
  "button",
2199
2440
  {
2200
- "aria-label": `关闭 ${U}`,
2441
+ "aria-label": `关闭 ${P}`,
2201
2442
  className: "make-ai-assistant__icon-button",
2202
2443
  type: "button",
2203
- onClick: o,
2204
- children: /* @__PURE__ */ a(Ua, {})
2444
+ onClick: c,
2445
+ children: /* @__PURE__ */ a(Ya, {})
2205
2446
  }
2206
2447
  ) : null
2207
2448
  ] })
2208
2449
  ] }),
2209
- g.enabled && G ? /* @__PURE__ */ a(
2210
- ba,
2450
+ g.enabled && Y ? /* @__PURE__ */ a(
2451
+ Ra,
2211
2452
  {
2212
- id: Qe,
2453
+ id: Je,
2213
2454
  manager: g,
2214
- triggerRef: Oe,
2215
- onDismiss: () => P(!1),
2216
- onNewConversation: A.features?.newConversation !== !1 ? be : void 0
2455
+ triggerRef: Ee,
2456
+ onDismiss: () => z(!1),
2457
+ onNewConversation: T.features?.newConversation !== !1 ? Z : void 0
2217
2458
  }
2218
2459
  ) : null,
2219
- /* @__PURE__ */ c(
2460
+ /* @__PURE__ */ l(
2220
2461
  "div",
2221
2462
  {
2222
2463
  className: "make-ai-assistant__body",
2223
2464
  "aria-live": "polite",
2224
2465
  "aria-relevant": "additions text",
2225
- ref: Ie,
2466
+ ref: ke,
2226
2467
  role: "log",
2227
- onScroll: m,
2468
+ onScroll: dt,
2228
2469
  children: [
2229
- ee === "loading" ? /* @__PURE__ */ c("div", { className: "make-ai-assistant__empty", role: "status", children: [
2470
+ ee === "loading" ? /* @__PURE__ */ l("div", { className: "make-ai-assistant__empty", role: "status", children: [
2230
2471
  /* @__PURE__ */ a(ct, {}),
2231
2472
  /* @__PURE__ */ a("h3", { children: "正在恢复对话" }),
2232
2473
  /* @__PURE__ */ a("p", { children: "正在读取当前 App 的历史消息…" })
2233
2474
  ] }) : ee === "error" ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__empty", children: /* @__PURE__ */ a(
2234
- rs,
2475
+ fs,
2235
2476
  {
2236
2477
  error: le,
2237
- onRetry: () => ge((u) => u + 1)
2478
+ onRetry: () => ge((m) => m + 1)
2238
2479
  }
2239
- ) }) : z.messages.length === 0 ? /* @__PURE__ */ c("div", { className: "make-ai-assistant__empty", children: [
2480
+ ) }) : F.messages.length === 0 ? /* @__PURE__ */ l("div", { className: "make-ai-assistant__empty", children: [
2240
2481
  /* @__PURE__ */ a(ct, {}),
2241
2482
  /* @__PURE__ */ a("h3", { children: "有什么可以帮你?" }),
2242
2483
  /* @__PURE__ */ a("p", { children: "我会结合当前 App、页面位置和宿主允许的上下文回答,并把过程与结果分开展示。" })
2243
- ] }) : os(
2244
- z,
2245
- s,
2246
- et,
2484
+ ] }) : gs(
2247
2485
  F,
2486
+ s,
2487
+ Qe,
2488
+ L,
2248
2489
  i,
2249
- r,
2490
+ o,
2250
2491
  e,
2251
- Ae ? gt : void 0,
2252
- C,
2253
- X,
2254
- w,
2255
- $e,
2256
- (u, H) => {
2257
- k(u, H);
2492
+ Le ? he : void 0,
2493
+ M,
2494
+ j,
2495
+ A,
2496
+ tt,
2497
+ (m, K) => {
2498
+ w(m, K);
2258
2499
  },
2259
- (u) => {
2260
- D(u);
2500
+ (m) => {
2501
+ y(m);
2261
2502
  },
2262
2503
  g.enabled ? g : void 0,
2263
- A
2504
+ T
2264
2505
  ),
2265
- z.progress && !tt ? /* @__PURE__ */ a(
2266
- xt,
2506
+ F.progress && !H ? /* @__PURE__ */ a(
2507
+ zt,
2267
2508
  {
2268
2509
  assistantName: e,
2269
- progress: z.progress
2510
+ progress: F.progress
2270
2511
  }
2271
2512
  ) : null,
2272
- z.error && !ke ? /* @__PURE__ */ a(
2273
- xt,
2513
+ F.error && !Ie ? /* @__PURE__ */ a(
2514
+ zt,
2274
2515
  {
2275
2516
  assistantName: e,
2276
- error: z.error,
2277
- onRetry: Ae ? gt : void 0
2517
+ error: F.error,
2518
+ onRetry: Le ? he : void 0
2278
2519
  }
2279
2520
  ) : null
2280
2521
  ]
2281
2522
  }
2282
2523
  ),
2283
- ze ? /* @__PURE__ */ a(
2524
+ lt ? /* @__PURE__ */ a(
2284
2525
  "button",
2285
2526
  {
2286
2527
  "aria-label": "回到最新消息",
2287
2528
  className: "make-ai-assistant__back-to-latest",
2288
2529
  type: "button",
2289
- onClick: y,
2290
- children: /* @__PURE__ */ a(Ha, {})
2530
+ onClick: Se,
2531
+ children: /* @__PURE__ */ a(es, {})
2291
2532
  }
2292
2533
  ) : null,
2293
- /* @__PURE__ */ c("footer", { className: "make-ai-assistant__composer-region", children: [
2294
- L.enabled ? /* @__PURE__ */ a(Ta, { attachments: L }) : null,
2295
- ee === "ready" && Te.length > 0 && z.messages.length === 0 ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__suggestions", "aria-label": "推荐问题", children: Te.map((u, H) => /* @__PURE__ */ a(
2534
+ /* @__PURE__ */ l("footer", { className: "make-ai-assistant__composer-region", children: [
2535
+ R.enabled ? /* @__PURE__ */ a(Fa, { attachments: R }) : null,
2536
+ ee === "ready" && et.length > 0 && F.messages.length === 0 ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__suggestions", "aria-label": "推荐问题", children: et.map((m, K) => /* @__PURE__ */ a(
2296
2537
  "button",
2297
2538
  {
2298
2539
  type: "button",
2299
2540
  onClick: () => {
2300
- I(u);
2541
+ u(m);
2301
2542
  },
2302
- children: u
2543
+ children: m
2303
2544
  },
2304
- `${H}-${u}`
2545
+ `${K}-${m}`
2305
2546
  )) }) : null,
2306
- /* @__PURE__ */ c("form", { className: "make-ai-assistant__composer", onSubmit: V, children: [
2547
+ /* @__PURE__ */ l("form", { className: "make-ai-assistant__composer", onSubmit: C, children: [
2307
2548
  /* @__PURE__ */ a(
2308
2549
  "textarea",
2309
2550
  {
2310
2551
  "aria-label": `向 ${e} 提问`,
2311
- "aria-describedby": K ? "make-ai-composer-error" : void 0,
2312
- "aria-invalid": K ? !0 : void 0,
2552
+ "aria-describedby": V ? "make-ai-composer-error" : void 0,
2553
+ "aria-invalid": V ? !0 : void 0,
2313
2554
  autoFocus: !0,
2314
- disabled: ee !== "ready" || !g.enabled && z.status === "streaming",
2555
+ disabled: ee !== "ready" || !g.enabled && F.status === "streaming",
2315
2556
  placeholder: `询问当前 ${s.app.name ?? "App"} 中的数据…`,
2316
- ref: Ze,
2557
+ ref: Oe,
2317
2558
  rows: 2,
2318
- value: T,
2319
- onChange: (u) => {
2320
- te(u.currentTarget.value), x(void 0);
2559
+ value: k,
2560
+ onChange: (m) => {
2561
+ q(m.currentTarget.value), B(void 0);
2321
2562
  },
2322
- onKeyDown: q,
2323
- onPaste: (u) => {
2324
- L.enabled && u.clipboardData.files.length && (u.preventDefault(), L.add(Array.from(u.clipboardData.files)));
2563
+ onKeyDown: D,
2564
+ onPaste: (m) => {
2565
+ R.enabled && m.clipboardData.files.length && (m.preventDefault(), R.add(Array.from(m.clipboardData.files)));
2325
2566
  }
2326
2567
  }
2327
2568
  ),
2328
- L.enabled ? /* @__PURE__ */ a(
2329
- Ca,
2569
+ R.enabled ? /* @__PURE__ */ a(
2570
+ Ua,
2330
2571
  {
2331
- attachments: L,
2332
- open: R,
2333
- triggerRef: Ue,
2334
- onOpenChange: Z
2572
+ attachments: R,
2573
+ open: I,
2574
+ triggerRef: He,
2575
+ onOpenChange: G
2335
2576
  }
2336
2577
  ) : null,
2337
- /* @__PURE__ */ c("div", { className: "make-ai-assistant__composer-actions", children: [
2338
- z.status === "streaming" ? /* @__PURE__ */ a(
2578
+ /* @__PURE__ */ l("div", { className: "make-ai-assistant__composer-actions", children: [
2579
+ F.status === "streaming" ? /* @__PURE__ */ a(
2339
2580
  "button",
2340
2581
  {
2341
- "aria-label": qe,
2582
+ "aria-label": O,
2342
2583
  className: "make-ai-assistant__send make-ai-assistant__send--stop",
2343
- "data-tooltip": qe,
2344
- ref: Ge,
2345
- disabled: g.enabled && g.cancelling.includes(z.activeRunId ?? ""),
2584
+ "data-tooltip": O,
2585
+ ref: Xe,
2586
+ disabled: g.enabled && g.cancelling.includes(F.activeRunId ?? ""),
2346
2587
  type: "button",
2347
- onClick: W,
2588
+ onClick: _,
2348
2589
  children: /* @__PURE__ */ a("span", { "aria-hidden": "true" })
2349
2590
  }
2350
2591
  ) : /* @__PURE__ */ a(
@@ -2352,127 +2593,127 @@ function Jt({
2352
2593
  {
2353
2594
  "aria-label": "发送",
2354
2595
  className: "make-ai-assistant__send",
2355
- disabled: ee !== "ready" || L.pending || !T.trim() && !L.parts.length,
2596
+ disabled: ee !== "ready" || R.pending || !k.trim() && !R.parts.length,
2356
2597
  type: "submit",
2357
- children: /* @__PURE__ */ a($t, {})
2598
+ children: /* @__PURE__ */ a(Ut, {})
2358
2599
  }
2359
2600
  ),
2360
- g.enabled && z.status === "streaming" ? /* @__PURE__ */ a("button", { "aria-label": "发送", className: "make-ai-assistant__send", disabled: g.busy || L.pending || !T.trim() && !L.parts.length, type: "submit", children: /* @__PURE__ */ a($t, {}) }) : null
2601
+ g.enabled && F.status === "streaming" ? /* @__PURE__ */ a("button", { "aria-label": "发送", className: "make-ai-assistant__send", disabled: g.busy || R.pending || !k.trim() && !R.parts.length, type: "submit", children: /* @__PURE__ */ a(Ut, {}) }) : null
2361
2602
  ] })
2362
2603
  ] }),
2363
- K ? /* @__PURE__ */ a("p", { id: "make-ai-composer-error", role: "alert", children: K }) : null,
2604
+ V ? /* @__PURE__ */ a("p", { id: "make-ai-composer-error", role: "alert", children: V }) : null,
2364
2605
  /* @__PURE__ */ a("p", { children: "AI 生成的结果可能存在偏差,重要数据请核对明细。" })
2365
2606
  ] })
2366
2607
  ]
2367
2608
  }
2368
2609
  );
2369
2610
  }
2370
- function ms(e) {
2371
- return /* @__PURE__ */ a(Jt, { ...e, visible: !0 });
2611
+ function Is(e) {
2612
+ return /* @__PURE__ */ a(sa, { ...e, visible: !0 });
2372
2613
  }
2373
- function hs({
2614
+ function As({
2374
2615
  defaultOpen: e = !1,
2375
2616
  hideLauncher: t = !1,
2376
2617
  launcher: s,
2377
2618
  launcherPosition: i = "bottom-right",
2378
- maxDrawerWidth: r,
2379
- onOpenChange: o,
2619
+ maxDrawerWidth: o,
2620
+ onOpenChange: c,
2380
2621
  open: d,
2381
- ...p
2622
+ ...h
2382
2623
  }) {
2383
- const v = qt(p.brandName, p.title), [h, _] = E(e), [F, A] = E(
2624
+ const b = Zt(h.brandName, h.title), [f, $] = N(e), [L, T] = N(
2384
2625
  () => e || d === !0
2385
- ), X = N(null), C = N(null), B = N(void 0), [g, L] = E(), [U, f] = E(Da), [l, S] = E(!1), T = d ?? h, te = ft(p.theme), R = xa(r), Z = () => Fa(
2386
- U,
2387
- R,
2388
- typeof window > "u" ? Ht : window.innerWidth
2389
- ), G = Z(), P = g === void 0 ? void 0 : mt(g, U, G), Q = P === void 0 && R === void 0 ? void 0 : {
2390
- ...P === void 0 ? {} : { "--make-ai-internal-drawer-width": `${P}px` },
2391
- ...R === void 0 ? {} : {
2392
- "--make-ai-internal-drawer-max-width": `max(var(--make-ai-internal-drawer-min-width), ${R}px)`
2626
+ ), j = S(null), M = S(null), U = S(void 0), [g, R] = N(), [P, p] = N(Ha), [n, v] = N(!1), k = d ?? f, q = yt(h.theme), I = Ka(o), G = () => ja(
2627
+ P,
2628
+ I,
2629
+ typeof window > "u" ? Xt : window.innerWidth
2630
+ ), Y = G(), z = g === void 0 ? void 0 : pt(g, P, Y), Q = z === void 0 && I === void 0 ? void 0 : {
2631
+ ...z === void 0 ? {} : { "--make-ai-internal-drawer-width": `${z}px` },
2632
+ ...I === void 0 ? {} : {
2633
+ "--make-ai-internal-drawer-max-width": `max(var(--make-ai-internal-drawer-min-width), ${I}px)`
2393
2634
  }
2394
2635
  };
2395
- Ft(() => {
2396
- P !== void 0 && P !== g && L(P);
2397
- }, [P, g]);
2398
- const fe = () => {
2399
- if (P !== void 0) return P;
2400
- const w = C.current?.getBoundingClientRect().width;
2401
- return w && Number.isFinite(w) && w > 0 ? w : U;
2402
- }, ve = (w) => {
2403
- if (w.button !== 0) return;
2404
- const O = fe(), ae = g === void 0 ? O : U;
2405
- f(ae), B.current = {
2636
+ gt(() => {
2637
+ z !== void 0 && z !== g && R(z);
2638
+ }, [z, g]);
2639
+ const ve = () => {
2640
+ if (z !== void 0) return z;
2641
+ const A = M.current?.getBoundingClientRect().width;
2642
+ return A && Number.isFinite(A) && A > 0 ? A : P;
2643
+ }, oe = (A) => {
2644
+ if (A.button !== 0) return;
2645
+ const W = ve(), ae = g === void 0 ? W : P;
2646
+ p(ae), U.current = {
2406
2647
  minimumWidth: ae,
2407
- pointerId: w.pointerId,
2408
- startWidth: O,
2409
- startX: w.clientX
2410
- }, S(!0), typeof w.currentTarget.setPointerCapture == "function" && w.currentTarget.setPointerCapture(w.pointerId), w.preventDefault();
2411
- }, z = (w) => {
2412
- const O = B.current;
2413
- if (!O || O.pointerId !== w.pointerId) return;
2414
- const ae = mt(
2415
- O.startWidth + O.startX - w.clientX,
2416
- O.minimumWidth,
2417
- Z()
2648
+ pointerId: A.pointerId,
2649
+ startWidth: W,
2650
+ startX: A.clientX
2651
+ }, v(!0), typeof A.currentTarget.setPointerCapture == "function" && A.currentTarget.setPointerCapture(A.pointerId), A.preventDefault();
2652
+ }, F = (A) => {
2653
+ const W = U.current;
2654
+ if (!W || W.pointerId !== A.pointerId) return;
2655
+ const ae = pt(
2656
+ W.startWidth + W.startX - A.clientX,
2657
+ W.minimumWidth,
2658
+ G()
2418
2659
  );
2419
- L(ae);
2420
- }, ne = (w) => {
2421
- const O = B.current;
2422
- !O || O.pointerId !== w.pointerId || (B.current = void 0, S(!1));
2423
- }, ce = (w) => {
2424
- const O = w.key === "ArrowLeft" ? Et : w.key === "ArrowRight" ? -Et : void 0;
2425
- if (O === void 0) return;
2426
- w.preventDefault();
2427
- const ae = fe(), ge = g === void 0 ? ae : U;
2428
- f(ge), L(mt(
2429
- ae + O,
2660
+ R(ae);
2661
+ }, ne = (A) => {
2662
+ const W = U.current;
2663
+ !W || W.pointerId !== A.pointerId || (U.current = void 0, v(!1));
2664
+ }, ce = (A) => {
2665
+ const W = A.key === "ArrowLeft" ? Dt : A.key === "ArrowRight" ? -Dt : void 0;
2666
+ if (W === void 0) return;
2667
+ A.preventDefault();
2668
+ const ae = ve(), ge = g === void 0 ? ae : P;
2669
+ p(ge), R(pt(
2670
+ ae + W,
2430
2671
  ge,
2431
- Z()
2672
+ G()
2432
2673
  ));
2433
- }, K = (w) => {
2434
- d === void 0 && _(w), o?.(w), w || requestAnimationFrame(() => X.current?.focus());
2435
- }, x = () => K(!T);
2436
- return oe(() => {
2437
- T && A(!0);
2438
- }, [T]), oe(() => {
2439
- if (!T) return;
2440
- const w = (O) => {
2441
- O.key === "Escape" && (K(!1), requestAnimationFrame(() => X.current?.focus()));
2674
+ }, V = (A) => {
2675
+ d === void 0 && $(A), c?.(A), A || requestAnimationFrame(() => j.current?.focus());
2676
+ }, B = () => V(!k);
2677
+ return ie(() => {
2678
+ k && T(!0);
2679
+ }, [k]), ie(() => {
2680
+ if (!k) return;
2681
+ const A = (W) => {
2682
+ W.key === "Escape" && (V(!1), requestAnimationFrame(() => j.current?.focus()));
2442
2683
  };
2443
- return document.addEventListener("keydown", w), () => document.removeEventListener("keydown", w);
2444
- }, [o, T]), /* @__PURE__ */ c(
2684
+ return document.addEventListener("keydown", A), () => document.removeEventListener("keydown", A);
2685
+ }, [c, k]), /* @__PURE__ */ l(
2445
2686
  "div",
2446
2687
  {
2447
2688
  className: "make-ai-assistant",
2448
- "data-open": T || void 0,
2449
- style: te,
2689
+ "data-open": k || void 0,
2690
+ style: q,
2450
2691
  children: [
2451
- !t && (!T || s) ? s ? s({ open: T, toggle: x }) : /* @__PURE__ */ c(
2692
+ !t && (!k || s) ? s ? s({ open: k, toggle: B }) : /* @__PURE__ */ l(
2452
2693
  "button",
2453
2694
  {
2454
- "aria-label": T ? `关闭 ${v}` : `打开 ${v}`,
2455
- "aria-expanded": T,
2695
+ "aria-label": k ? `关闭 ${b}` : `打开 ${b}`,
2696
+ "aria-expanded": k,
2456
2697
  className: "make-ai-assistant__launcher",
2457
2698
  "data-launcher-position": i,
2458
- ref: X,
2699
+ ref: j,
2459
2700
  type: "button",
2460
- onClick: x,
2701
+ onClick: B,
2461
2702
  children: [
2462
2703
  /* @__PURE__ */ a("span", { className: "make-ai-assistant__launcher-orbit", "aria-hidden": "true" }),
2463
- /* @__PURE__ */ a(Kt, {})
2704
+ /* @__PURE__ */ a(Gt, {})
2464
2705
  ]
2465
2706
  }
2466
2707
  ) : null,
2467
- F ? /* @__PURE__ */ c(
2708
+ L ? /* @__PURE__ */ l(
2468
2709
  "aside",
2469
2710
  {
2470
- "aria-label": v,
2711
+ "aria-label": b,
2471
2712
  "aria-modal": "false",
2472
2713
  className: "make-ai-assistant__drawer",
2473
- "data-resizing": l || void 0,
2474
- hidden: !T,
2475
- ref: C,
2714
+ "data-resizing": n || void 0,
2715
+ hidden: !k,
2716
+ ref: M,
2476
2717
  role: "dialog",
2477
2718
  style: Q,
2478
2719
  children: [
@@ -2481,25 +2722,25 @@ function hs({
2481
2722
  {
2482
2723
  "aria-label": "调整对话框宽度",
2483
2724
  "aria-orientation": "vertical",
2484
- "aria-valuemax": G,
2485
- "aria-valuemin": U,
2486
- "aria-valuenow": P ?? U,
2725
+ "aria-valuemax": Y,
2726
+ "aria-valuemin": P,
2727
+ "aria-valuenow": z ?? P,
2487
2728
  className: "make-ai-assistant__drawer-resize-handle",
2488
2729
  role: "separator",
2489
2730
  tabIndex: 0,
2490
2731
  onKeyDown: ce,
2491
2732
  onPointerCancel: ne,
2492
- onPointerDown: ve,
2493
- onPointerMove: z,
2733
+ onPointerDown: oe,
2734
+ onPointerMove: F,
2494
2735
  onPointerUp: ne
2495
2736
  }
2496
2737
  ),
2497
2738
  /* @__PURE__ */ a(
2498
- Jt,
2739
+ sa,
2499
2740
  {
2500
- ...p,
2501
- onClose: () => K(!1),
2502
- visible: T
2741
+ ...h,
2742
+ onClose: () => V(!1),
2743
+ visible: k
2503
2744
  }
2504
2745
  )
2505
2746
  ]
@@ -2510,24 +2751,24 @@ function hs({
2510
2751
  );
2511
2752
  }
2512
2753
  export {
2513
- ra as ArtifactRenderer,
2514
- ms as AssistantPanel,
2515
- ys as MAKE_AI_ARTIFACT_KINDS,
2516
- bs as MAKE_AI_ARTIFACT_LIMITS,
2517
- ks as MAKE_AI_ARTIFACT_SCHEMA_VERSION,
2754
+ da as ArtifactRenderer,
2755
+ Is as AssistantPanel,
2756
+ Rs as MAKE_AI_ARTIFACT_KINDS,
2757
+ Es as MAKE_AI_ARTIFACT_LIMITS,
2758
+ Ss as MAKE_AI_ARTIFACT_SCHEMA_VERSION,
2518
2759
  ue as MAKE_AI_CONVERSATION_LIMITS,
2519
- hs as MakeAiAssistant,
2520
- zt as appendUserMessage,
2521
- na as createArtifactCapabilities,
2522
- Pt as createArtifactTemplateRegistry,
2523
- pe as createAssistantConversationState,
2524
- fa as createPlatformArtifactRegistry,
2525
- vs as extendArtifactTemplateRegistry,
2526
- Se as formatArtifactValue,
2527
- _s as parseArtifact,
2528
- Bt as parseAssistantEvent,
2529
- pa as platformArtifactTemplates,
2530
- Ne as reduceAssistantEvent,
2531
- sa as resolveArtifactTemplate,
2532
- ws as validateArtifact
2760
+ As as MakeAiAssistant,
2761
+ Ht as appendUserMessage,
2762
+ ca as createArtifactCapabilities,
2763
+ Wt as createArtifactTemplateRegistry,
2764
+ fe as createAssistantConversationState,
2765
+ ka as createPlatformArtifactRegistry,
2766
+ Cs as extendArtifactTemplateRegistry,
2767
+ $e as formatArtifactValue,
2768
+ Ls as parseArtifact,
2769
+ Ot as parseAssistantEvent,
2770
+ ba as platformArtifactTemplates,
2771
+ Me as reduceAssistantEvent,
2772
+ oa as resolveArtifactTemplate,
2773
+ $s as validateArtifact
2533
2774
  };