@qfei-design/make-ai-assistant 0.2.9 → 0.2.10

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