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

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