@qfei-design/make-ai-assistant 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.mjs CHANGED
@@ -1,67 +1,67 @@
1
- import { jsxs as n, jsx as a, Fragment as S } from "react/jsx-runtime";
2
- import { resolveArtifactTemplate as Le, createArtifactTemplateRegistry as ke, createArtifactCapabilities as Pe } from "./index.mjs";
3
- import { extendArtifactTemplateRegistry as _a } from "./index.mjs";
4
- import { useState as U, useRef as R, useMemo as Ve, useEffect as ne } from "react";
5
- import { a as te, c as ie, M as b, b as qe, p as Ue, r as se } from "./conversation-Dy2Sghjv.js";
6
- import { d as ka, e as va, f as ya, g as Aa, v as Ia } from "./conversation-Dy2Sghjv.js";
7
- function ze({
1
+ import { jsxs as n, jsx as t, Fragment as L } from "react/jsx-runtime";
2
+ import { resolveArtifactTemplate as ia, createArtifactTemplateRegistry as Pe, createArtifactCapabilities as oa } from "./index.mjs";
3
+ import { extendArtifactTemplateRegistry as Ga } from "./index.mjs";
4
+ import { useState as E, useRef as S, useMemo as Fe, useEffect as ge } from "react";
5
+ import { a as ue, r as pe, c as he, M as A, b as ca, p as la } from "./conversation-B7eGUXi-.js";
6
+ import { d as ja, e as Ya, f as Ja, g as Qa, v as Wa } from "./conversation-B7eGUXi-.js";
7
+ function da({
8
8
  artifact: e,
9
- context: t,
9
+ context: a,
10
10
  fallback: s,
11
11
  onAction: c,
12
12
  onActionError: o,
13
- registry: r
13
+ registry: d
14
14
  }) {
15
- const m = Le(r, e, t);
15
+ const m = ia(d, e, a);
16
16
  if (!m)
17
17
  return s ? s(e) : /* @__PURE__ */ n("section", { className: "make-ai-artifact make-ai-artifact--unsupported", role: "status", children: [
18
- /* @__PURE__ */ a("strong", { children: "暂不支持展示此结果" }),
18
+ /* @__PURE__ */ t("strong", { children: "暂不支持展示此结果" }),
19
19
  /* @__PURE__ */ n("span", { children: [
20
20
  "结果类型:",
21
21
  e.kind
22
22
  ] })
23
23
  ] });
24
- const u = {
25
- context: t,
24
+ const h = {
25
+ context: a,
26
26
  onAction: c,
27
27
  onActionError: o
28
28
  };
29
- return m.template.render(e, t, u);
29
+ return m.template.render(e, a, h);
30
30
  }
31
- const x = (e, t, s) => {
31
+ const D = (e, a, s) => {
32
32
  if (e == null || e === "") return "—";
33
33
  if (typeof e == "boolean") return e ? "是" : "否";
34
- if (typeof e != "number") return `${e}${t?.unit ?? ""}`;
35
- const c = t?.precision, o = {
34
+ if (typeof e != "number") return `${e}${a?.unit ?? ""}`;
35
+ const c = a?.precision, o = {
36
36
  maximumFractionDigits: c ?? 2,
37
37
  minimumFractionDigits: c
38
38
  };
39
- t?.style === "currency" && t.currency ? (o.style = "currency", o.currency = t.currency) : t?.style === "percent" && (o.style = "percent");
39
+ a?.style === "currency" && a.currency ? (o.style = "currency", o.currency = a.currency) : a?.style === "percent" && (o.style = "percent");
40
40
  try {
41
- const r = t?.style === "percent" ? e / 100 : e;
42
- return `${new Intl.NumberFormat(s, o).format(r)}${t?.unit ?? ""}`;
41
+ const d = a?.style === "percent" ? e / 100 : e;
42
+ return `${new Intl.NumberFormat(s, o).format(d)}${a?.unit ?? ""}`;
43
43
  } catch {
44
- return `${e}${t?.unit ?? ""}`;
44
+ return `${e}${a?.unit ?? ""}`;
45
45
  }
46
- }, ve = (e) => {
47
- let t = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
46
+ }, Ue = (e) => {
47
+ let a = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
48
48
  for (const c of e)
49
- t = Math.min(t, c), s = Math.max(s, c);
50
- return Number.isFinite(t) && Number.isFinite(s) ? { min: t, max: s } : { min: 0, max: 0 };
51
- }, ye = (e, t, s) => {
49
+ a = Math.min(a, c), s = Math.max(s, c);
50
+ return Number.isFinite(a) && Number.isFinite(s) ? { min: a, max: s } : { min: 0, max: 0 };
51
+ }, qe = (e, a, s) => {
52
52
  if (!s.onAction) return;
53
- const c = (r) => {
53
+ const c = (d) => {
54
54
  console.error("[make-ai-assistant] host action error handler failed", {
55
55
  actionId: e.id,
56
- artifactId: t.artifact.id,
57
- errorType: r instanceof Error ? r.name : typeof r,
56
+ artifactId: a.artifact.id,
57
+ errorType: d instanceof Error ? d.name : typeof d,
58
58
  intent: e.intent
59
59
  });
60
- }, o = (r) => {
60
+ }, o = (d) => {
61
61
  if (s.onActionError) {
62
62
  try {
63
63
  Promise.resolve(
64
- s.onActionError(r, e, t)
64
+ s.onActionError(d, e, a)
65
65
  ).catch(c);
66
66
  } catch (m) {
67
67
  c(m);
@@ -70,29 +70,29 @@ const x = (e, t, s) => {
70
70
  }
71
71
  console.error("[make-ai-assistant] host action failed", {
72
72
  actionId: e.id,
73
- artifactId: t.artifact.id,
74
- errorType: r instanceof Error ? r.name : typeof r,
73
+ artifactId: a.artifact.id,
74
+ errorType: d instanceof Error ? d.name : typeof d,
75
75
  intent: e.intent
76
76
  });
77
77
  };
78
78
  try {
79
- Promise.resolve(s.onAction(e, t)).catch(o);
80
- } catch (r) {
81
- o(r);
79
+ Promise.resolve(s.onAction(e, a)).catch(o);
80
+ } catch (d) {
81
+ o(d);
82
82
  }
83
- }, z = (e, t) => e.actions?.length && t.onAction ? /* @__PURE__ */ a("div", { className: "make-ai-artifact__actions", children: e.actions.map((s) => /* @__PURE__ */ n(
83
+ }, J = (e, a) => e.actions?.length && a.onAction ? /* @__PURE__ */ t("div", { className: "make-ai-artifact__actions", children: e.actions.map((s) => /* @__PURE__ */ n(
84
84
  "button",
85
85
  {
86
86
  className: `make-ai-artifact__action make-ai-artifact__action--${s.appearance ?? "link"}`,
87
87
  type: "button",
88
- onClick: () => ye(s, { artifact: e, context: t.context }, t),
88
+ onClick: () => qe(s, { artifact: e, context: a.context }, a),
89
89
  children: [
90
90
  s.label,
91
- /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "→" })
91
+ /* @__PURE__ */ t("span", { "aria-hidden": "true", children: "→" })
92
92
  ]
93
93
  },
94
94
  s.id
95
- )) }) : null, B = (e, t, s = "") => /* @__PURE__ */ n(
95
+ )) }) : null, Q = (e, a, s = "") => /* @__PURE__ */ n(
96
96
  "section",
97
97
  {
98
98
  "aria-label": e.title ?? `${e.kind} result`,
@@ -100,252 +100,336 @@ const x = (e, t, s) => {
100
100
  "data-artifact-density": e.presentation?.density,
101
101
  "data-artifact-kind": e.kind,
102
102
  children: [
103
- e.title ? /* @__PURE__ */ a("h4", { className: "make-ai-artifact__title", children: e.title }) : null,
104
- e.summary ? /* @__PURE__ */ a("p", { className: "make-ai-artifact__summary", children: e.summary }) : null,
105
- t
103
+ e.title ? /* @__PURE__ */ t("h4", { className: "make-ai-artifact__title", children: e.title }) : null,
104
+ e.summary ? /* @__PURE__ */ t("p", { className: "make-ai-artifact__summary", children: e.summary }) : null,
105
+ a
106
106
  ]
107
107
  }
108
- ), Be = ({
108
+ ), ma = ({
109
109
  artifact: e,
110
- renderContext: t
110
+ renderContext: a
111
111
  }) => {
112
- const s = e.data.delta, c = s ? x(
112
+ const s = e.data.delta, c = s ? D(
113
113
  s.value,
114
114
  s.format === "percent" ? { style: "percent" } : void 0,
115
- t.context.locale
115
+ a.context.locale
116
116
  ) : void 0;
117
- return B(
117
+ return Q(
118
118
  e,
119
- /* @__PURE__ */ n(S, { children: [
120
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__metric-value", children: x(
119
+ /* @__PURE__ */ n(L, { children: [
120
+ /* @__PURE__ */ t("div", { className: "make-ai-artifact__metric-value", children: D(
121
121
  e.data.value,
122
122
  e.data.format,
123
- t.context.locale
123
+ a.context.locale
124
124
  ) }),
125
125
  s ? /* @__PURE__ */ n(
126
126
  "div",
127
127
  {
128
128
  className: `make-ai-artifact__delta make-ai-artifact__delta--${s.direction ?? "flat"}`,
129
129
  children: [
130
- /* @__PURE__ */ a("span", { "aria-hidden": "true", children: s.direction === "up" ? "↗" : s.direction === "down" ? "↘" : "→" }),
131
- /* @__PURE__ */ a("span", { children: c }),
132
- s.label ? /* @__PURE__ */ a("span", { children: s.label }) : null
130
+ /* @__PURE__ */ t("span", { "aria-hidden": "true", children: s.direction === "up" ? "↗" : s.direction === "down" ? "↘" : "→" }),
131
+ /* @__PURE__ */ t("span", { children: c }),
132
+ s.label ? /* @__PURE__ */ t("span", { children: s.label }) : null
133
133
  ]
134
134
  }
135
135
  ) : null,
136
- e.data.context ? /* @__PURE__ */ a("p", { className: "make-ai-artifact__context", children: e.data.context }) : null,
137
- z(e, t)
136
+ e.data.context ? /* @__PURE__ */ t("p", { className: "make-ai-artifact__context", children: e.data.context }) : null,
137
+ J(e, a)
138
138
  ] }),
139
139
  "make-ai-artifact--metric"
140
140
  );
141
- }, He = ({
141
+ }, ua = ({
142
142
  artifact: e,
143
- renderContext: t
144
- }) => B(
143
+ renderContext: a
144
+ }) => Q(
145
145
  e,
146
- /* @__PURE__ */ n(S, { children: [
147
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__comparison", children: e.data.items.map((s) => /* @__PURE__ */ n("div", { className: "make-ai-artifact__comparison-item", children: [
148
- /* @__PURE__ */ a("span", { children: s.label }),
149
- /* @__PURE__ */ a("strong", { children: x(s.value, s.format, t.context.locale) }),
150
- s.hint ? /* @__PURE__ */ a("small", { children: s.hint }) : null
146
+ /* @__PURE__ */ n(L, { children: [
147
+ /* @__PURE__ */ t("div", { className: "make-ai-artifact__comparison", children: e.data.items.map((s) => /* @__PURE__ */ n("div", { className: "make-ai-artifact__comparison-item", children: [
148
+ /* @__PURE__ */ t("span", { children: s.label }),
149
+ /* @__PURE__ */ t("strong", { children: D(s.value, s.format, a.context.locale) }),
150
+ s.hint ? /* @__PURE__ */ t("small", { children: s.hint }) : null
151
151
  ] }, s.id)) }),
152
- z(e, t)
152
+ J(e, a)
153
153
  ] }),
154
154
  "make-ai-artifact--comparison"
155
- ), Oe = ({
155
+ ), pa = ({
156
156
  artifact: e,
157
- renderContext: t
157
+ renderContext: a
158
158
  }) => {
159
- const s = e.data.series.flatMap((m) => m.points.map((u) => u.y)), { max: c, min: o } = ve(s), r = c - o || 1;
160
- return B(
159
+ const s = e.data.series.flatMap((m) => m.points.map((h) => h.y)), { max: c, min: o } = Ue(s), d = c - o || 1;
160
+ return Q(
161
161
  e,
162
- /* @__PURE__ */ n(S, { children: [
163
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend", children: e.data.series.map((m) => /* @__PURE__ */ n("div", { className: "make-ai-artifact__trend-series", children: [
164
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-label", children: m.label }),
165
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-bars", children: m.points.map((u, M) => {
166
- const y = 18 + (u.y - o) / r * 70;
162
+ /* @__PURE__ */ n(L, { children: [
163
+ /* @__PURE__ */ t("div", { className: "make-ai-artifact__trend", children: e.data.series.map((m) => /* @__PURE__ */ n("div", { className: "make-ai-artifact__trend-series", children: [
164
+ /* @__PURE__ */ t("div", { className: "make-ai-artifact__trend-label", children: m.label }),
165
+ /* @__PURE__ */ t("div", { className: "make-ai-artifact__trend-bars", children: m.points.map((h, $) => {
166
+ const y = 18 + (h.y - o) / d * 70;
167
167
  return /* @__PURE__ */ n("div", { className: "make-ai-artifact__trend-point", children: [
168
- /* @__PURE__ */ a(
168
+ /* @__PURE__ */ t(
169
169
  "span",
170
170
  {
171
- "aria-label": `${u.x}: ${x(
172
- u.y,
171
+ "aria-label": `${h.x}: ${D(
172
+ h.y,
173
173
  m.format,
174
- t.context.locale
174
+ a.context.locale
175
175
  )}`,
176
176
  className: "make-ai-artifact__trend-bar",
177
177
  role: "img",
178
178
  style: { height: `${y}%` },
179
- title: `${u.x}: ${x(
180
- u.y,
179
+ title: `${h.x}: ${D(
180
+ h.y,
181
181
  m.format,
182
- t.context.locale
182
+ a.context.locale
183
183
  )}`
184
184
  }
185
185
  ),
186
- /* @__PURE__ */ a("small", { children: u.x })
187
- ] }, `${u.x}-${M}`);
186
+ /* @__PURE__ */ t("small", { children: h.x })
187
+ ] }, `${h.x}-${$}`);
188
188
  }) })
189
189
  ] }, m.id)) }),
190
- z(e, t)
190
+ J(e, a)
191
191
  ] }),
192
192
  "make-ai-artifact--trend"
193
193
  );
194
- }, Ze = ({
194
+ }, ha = ({
195
195
  artifact: e,
196
- renderContext: t
196
+ renderContext: a
197
197
  }) => {
198
- const { max: s } = ve(
198
+ const { max: s } = Ue(
199
199
  e.data.items.map((o) => Math.abs(o.value))
200
200
  ), c = Math.max(s, 1);
201
- return B(
201
+ return Q(
202
202
  e,
203
- /* @__PURE__ */ n(S, { children: [
204
- /* @__PURE__ */ a("ol", { className: "make-ai-artifact__ranking", children: e.data.items.map((o, r) => /* @__PURE__ */ n("li", { children: [
205
- /* @__PURE__ */ a("span", { className: "make-ai-artifact__rank", children: r + 1 }),
203
+ /* @__PURE__ */ n(L, { children: [
204
+ /* @__PURE__ */ t("ol", { className: "make-ai-artifact__ranking", children: e.data.items.map((o, d) => /* @__PURE__ */ n("li", { children: [
205
+ /* @__PURE__ */ t("span", { className: "make-ai-artifact__rank", children: d + 1 }),
206
206
  /* @__PURE__ */ n("span", { className: "make-ai-artifact__ranking-label", children: [
207
- /* @__PURE__ */ a("span", { children: o.label }),
208
- o.description ? /* @__PURE__ */ a("small", { children: o.description }) : null
207
+ /* @__PURE__ */ t("span", { children: o.label }),
208
+ o.description ? /* @__PURE__ */ t("small", { children: o.description }) : null
209
209
  ] }),
210
- /* @__PURE__ */ a("span", { className: "make-ai-artifact__ranking-track", "aria-hidden": "true", children: /* @__PURE__ */ a("span", { style: { width: `${Math.abs(o.value) / c * 100}%` } }) }),
211
- /* @__PURE__ */ a("strong", { children: x(o.value, o.format, t.context.locale) })
210
+ /* @__PURE__ */ t("span", { className: "make-ai-artifact__ranking-track", "aria-hidden": "true", children: /* @__PURE__ */ t("span", { style: { width: `${Math.abs(o.value) / c * 100}%` } }) }),
211
+ /* @__PURE__ */ t("strong", { children: D(o.value, o.format, a.context.locale) })
212
212
  ] }, o.id)) }),
213
- z(e, t)
213
+ J(e, a)
214
214
  ] }),
215
215
  "make-ai-artifact--ranking"
216
216
  );
217
- }, je = (e, t) => t.action ?? {
218
- id: `open-${t.id}`,
219
- label: t.title ?? t.id,
217
+ }, ga = (e, a) => a.action ?? {
218
+ id: `open-${a.id}`,
219
+ label: a.title ?? a.id,
220
220
  intent: "open-record",
221
- target: { entityKey: e.data.entity.key, recordId: t.id }
222
- }, Ye = ({
221
+ target: { entityKey: e.data.entity.key, recordId: a.id }
222
+ }, fa = ({
223
223
  artifact: e,
224
- renderContext: t
225
- }) => B(
224
+ renderContext: a
225
+ }) => Q(
226
226
  e,
227
- /* @__PURE__ */ n(S, { children: [
228
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__record-list", children: e.data.records.length === 0 ? /* @__PURE__ */ a("p", { className: "make-ai-artifact__empty", children: "没有符合条件的记录" }) : e.data.records.map((s) => {
229
- const c = je(e, s), o = /* @__PURE__ */ n(S, { children: [
230
- /* @__PURE__ */ a("strong", { children: s.title ?? s.id }),
231
- /* @__PURE__ */ a("span", { className: "make-ai-artifact__record-values", children: e.data.columns.map((r) => /* @__PURE__ */ n("span", { children: [
232
- /* @__PURE__ */ a("small", { children: r.label }),
233
- x(
234
- s.values[r.key],
235
- r.format,
236
- t.context.locale
227
+ /* @__PURE__ */ n(L, { children: [
228
+ /* @__PURE__ */ t("div", { className: "make-ai-artifact__record-list", children: e.data.records.length === 0 ? /* @__PURE__ */ t("p", { className: "make-ai-artifact__empty", children: "没有符合条件的记录" }) : e.data.records.map((s) => {
229
+ const c = ga(e, s), o = /* @__PURE__ */ n(L, { children: [
230
+ /* @__PURE__ */ t("strong", { children: s.title ?? s.id }),
231
+ /* @__PURE__ */ t("span", { className: "make-ai-artifact__record-values", children: e.data.columns.map((d) => /* @__PURE__ */ n("span", { children: [
232
+ /* @__PURE__ */ t("small", { children: d.label }),
233
+ D(
234
+ s.values[d.key],
235
+ d.format,
236
+ a.context.locale
237
237
  )
238
- ] }, r.key)) }),
239
- t.onAction ? /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "›" }) : null
238
+ ] }, d.key)) }),
239
+ a.onAction ? /* @__PURE__ */ t("span", { "aria-hidden": "true", children: "›" }) : null
240
240
  ] });
241
- return t.onAction ? /* @__PURE__ */ a(
241
+ return a.onAction ? /* @__PURE__ */ t(
242
242
  "button",
243
243
  {
244
244
  className: "make-ai-artifact__record",
245
245
  type: "button",
246
- onClick: () => ye(c, {
246
+ onClick: () => qe(c, {
247
247
  artifact: e,
248
- context: t.context
249
- }, t),
248
+ context: a.context
249
+ }, a),
250
250
  children: o
251
251
  },
252
252
  s.id
253
- ) : /* @__PURE__ */ a("div", { className: "make-ai-artifact__record", children: o }, s.id);
253
+ ) : /* @__PURE__ */ t("div", { className: "make-ai-artifact__record", children: o }, s.id);
254
254
  }) }),
255
255
  e.data.total !== void 0 ? /* @__PURE__ */ n("p", { className: "make-ai-artifact__record-total", children: [
256
256
  "共 ",
257
257
  e.data.total,
258
258
  " 条"
259
259
  ] }) : null,
260
- z(e, t)
260
+ J(e, a)
261
261
  ] }),
262
262
  "make-ai-artifact--record-list"
263
- ), Ge = ({
263
+ ), _a = ({
264
264
  artifact: e,
265
- renderContext: t
266
- }) => B(
265
+ renderContext: a
266
+ }) => Q(
267
267
  e,
268
- /* @__PURE__ */ n(S, { children: [
268
+ /* @__PURE__ */ n(L, { children: [
269
269
  /* @__PURE__ */ n("div", { className: `make-ai-artifact__notice make-ai-artifact__notice--${e.data.tone}`, children: [
270
- /* @__PURE__ */ a("span", { "aria-hidden": "true", children: e.data.tone === "success" ? "✓" : e.data.tone === "warning" ? "!" : e.data.tone === "danger" ? "×" : "i" }),
271
- /* @__PURE__ */ a("p", { children: e.data.body })
270
+ /* @__PURE__ */ t("span", { "aria-hidden": "true", children: e.data.tone === "success" ? "✓" : e.data.tone === "warning" ? "!" : e.data.tone === "danger" ? "×" : "i" }),
271
+ /* @__PURE__ */ t("p", { children: e.data.body })
272
272
  ] }),
273
- z(e, t)
273
+ J(e, a)
274
274
  ] }),
275
275
  "make-ai-artifact--notice"
276
- ), q = (e, t, s) => ({ id: e, kinds: [t], priority: 0, render: s }), Je = [
277
- q("platform.metric.default", "metric", (e, t, s) => /* @__PURE__ */ a(Be, { artifact: e, renderContext: s })),
278
- q("platform.comparison.default", "comparison", (e, t, s) => /* @__PURE__ */ a(He, { artifact: e, renderContext: s })),
279
- q("platform.trend.default", "trend", (e, t, s) => /* @__PURE__ */ a(Oe, { artifact: e, renderContext: s })),
280
- q("platform.ranking.default", "ranking", (e, t, s) => /* @__PURE__ */ a(Ze, { artifact: e, renderContext: s })),
281
- q("platform.record-list.default", "record-list", (e, t, s) => /* @__PURE__ */ a(Ye, { artifact: e, renderContext: s })),
282
- q("platform.notice.default", "notice", (e, t, s) => /* @__PURE__ */ a(Ge, { artifact: e, renderContext: s }))
283
- ], Qe = ke(Je).templates, We = (e = Qe) => ke(e), Xe = (e) => `${e}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, ea = "Make", Ae = (e, t) => t ?? `${e?.trim() || ea} AI 助手`;
284
- class h extends Error {
276
+ ), Y = (e, a, s) => ({ id: e, kinds: [a], priority: 0, render: s }), va = [
277
+ Y("platform.metric.default", "metric", (e, a, s) => /* @__PURE__ */ t(ma, { artifact: e, renderContext: s })),
278
+ Y("platform.comparison.default", "comparison", (e, a, s) => /* @__PURE__ */ t(ua, { artifact: e, renderContext: s })),
279
+ Y("platform.trend.default", "trend", (e, a, s) => /* @__PURE__ */ t(pa, { artifact: e, renderContext: s })),
280
+ Y("platform.ranking.default", "ranking", (e, a, s) => /* @__PURE__ */ t(ha, { artifact: e, renderContext: s })),
281
+ Y("platform.record-list.default", "record-list", (e, a, s) => /* @__PURE__ */ t(fa, { artifact: e, renderContext: s })),
282
+ Y("platform.notice.default", "notice", (e, a, s) => /* @__PURE__ */ t(_a, { artifact: e, renderContext: s }))
283
+ ], ka = Pe(va).templates, ya = (e = ka) => Pe(e), Aa = (e) => `${e}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, ba = "Make", Ia = [
284
+ "总结当前页面数据",
285
+ "找出需要关注的记录",
286
+ "列出我有权限查看的数据对象"
287
+ ], Ke = (e, a) => a ?? `${e?.trim() || ba} AI 助手`, Na = (e) => e ?? Ia;
288
+ class u extends Error {
285
289
  }
286
- const _e = (e) => {
290
+ const Le = (e) => {
287
291
  try {
288
- const t = e?.return?.();
289
- if (!t) return;
290
- Promise.resolve(t).catch((s) => {
292
+ const a = e?.return?.();
293
+ if (!a) return;
294
+ Promise.resolve(a).catch((s) => {
291
295
  console.error("[make-ai-assistant] transport iterator close failed", {
292
296
  errorType: s instanceof Error ? s.name : typeof s
293
297
  });
294
298
  });
295
- } catch (t) {
299
+ } catch (a) {
296
300
  console.error("[make-ai-assistant] transport iterator close failed", {
297
- errorType: t instanceof Error ? t.name : typeof t
301
+ errorType: a instanceof Error ? a.name : typeof a
298
302
  });
299
303
  }
300
- }, Ie = () => /* @__PURE__ */ n("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
301
- /* @__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" }),
302
- /* @__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" })
303
- ] }), aa = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m6 6 12 12M18 6 6 18" }) }), ta = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "M12 5v14M5 12h14" }) }), sa = () => /* @__PURE__ */ n("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
304
- /* @__PURE__ */ a("path", { d: "m4 4 17 8-17 8 3-8-3-8Z" }),
305
- /* @__PURE__ */ a("path", { d: "M7 12h14" })
306
- ] }), Y = ({ className: e = "" }) => /* @__PURE__ */ a("span", { className: `make-ai-assistant__avatar ${e}`.trim(), "aria-hidden": "true", children: /* @__PURE__ */ a(Ie, {}) }), na = ({ src: e }) => e ? /* @__PURE__ */ a("span", { className: "make-ai-assistant__user-avatar", "aria-hidden": "true", children: /* @__PURE__ */ a("img", { alt: "", src: e }) }) : null, be = ({ assistantName: e }) => /* @__PURE__ */ n("div", { className: "make-ai-assistant__message-identity", children: [
307
- /* @__PURE__ */ a(Y, { className: "make-ai-assistant__avatar--message" }),
308
- /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-sender", children: e })
309
- ] }), Ne = (e) => {
310
- for (let t = e.messages.length - 1; t >= 0; t -= 1) {
311
- const s = e.messages[t];
304
+ }, wa = async (e) => {
305
+ if (globalThis.navigator?.clipboard?.writeText) {
306
+ await globalThis.navigator.clipboard.writeText(e);
307
+ return;
308
+ }
309
+ if (typeof document > "u" || !document.body)
310
+ throw new Error("Clipboard API is unavailable");
311
+ const a = document.createElement("textarea");
312
+ a.value = e, a.setAttribute("readonly", ""), a.style.position = "fixed", a.style.inset = "0 auto auto 0", a.style.opacity = "0", document.body.append(a), a.select();
313
+ const s = document.execCommand("copy");
314
+ if (a.remove(), !s)
315
+ throw new Error("Clipboard copy failed");
316
+ }, Be = () => /* @__PURE__ */ n("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
317
+ /* @__PURE__ */ t("path", { d: "M12 2.8c.5 4.4 2.8 6.8 7.2 7.2-4.4.5-6.8 2.8-7.2 7.2-.5-4.4-2.8-6.8-7.2-7.2 4.4-.5 6.8-2.8 7.2-7.2Z" }),
318
+ /* @__PURE__ */ t("path", { d: "M18.3 16.1c.2 1.8 1.2 2.8 3 3-1.8.2-2.8 1.2-3 3-.2-1.8-1.2-2.8-3-3 1.8-.2 2.8-1.2 3-3Z" })
319
+ ] }), Ta = () => /* @__PURE__ */ t("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ t("path", { d: "m6 6 12 12M18 6 6 18" }) }), Ma = () => /* @__PURE__ */ t("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ t("path", { d: "M12 5v14M5 12h14" }) }), Ca = () => /* @__PURE__ */ n("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
320
+ /* @__PURE__ */ t("path", { d: "m4 4 17 8-17 8 3-8-3-8Z" }),
321
+ /* @__PURE__ */ t("path", { d: "M7 12h14" })
322
+ ] }), ae = ({ className: e = "" }) => /* @__PURE__ */ t("span", { className: `make-ai-assistant__avatar ${e}`.trim(), "aria-hidden": "true", children: /* @__PURE__ */ t(Be, {}) }), Ea = ({ src: e }) => e ? /* @__PURE__ */ t("span", { className: "make-ai-assistant__user-avatar", "aria-hidden": "true", children: /* @__PURE__ */ t("img", { alt: "", src: e }) }) : null, Ve = ({ assistantName: e }) => /* @__PURE__ */ n("div", { className: "make-ai-assistant__message-identity", children: [
323
+ /* @__PURE__ */ t(ae, { className: "make-ai-assistant__avatar--message" }),
324
+ /* @__PURE__ */ t("span", { className: "make-ai-assistant__message-sender", children: e })
325
+ ] }), He = (e) => {
326
+ for (let a = e.messages.length - 1; a >= 0; a -= 1) {
327
+ const s = e.messages[a];
312
328
  if (s.role === "assistant" && s.status === "streaming")
313
329
  return s.id;
314
330
  }
315
- }, ra = (e) => {
316
- for (let t = e.messages.length - 1; t >= 0; t -= 1)
317
- if (e.messages[t].role === "user") return t;
331
+ }, Sa = (e) => {
332
+ for (let a = e.messages.length - 1; a >= 0; a -= 1)
333
+ if (e.messages[a].role === "user") return a;
318
334
  return -1;
319
- }, we = (e) => {
320
- const t = ra(e);
321
- if (!(t < 0))
322
- for (let s = e.messages.length - 1; s > t; s -= 1) {
335
+ }, Oe = (e) => {
336
+ const a = Sa(e);
337
+ if (!(a < 0))
338
+ for (let s = e.messages.length - 1; s > a; s -= 1) {
323
339
  const c = e.messages[s];
324
340
  if (c.role === "assistant") return c.id;
325
341
  }
326
- }, Te = ({
342
+ }, $a = (e) => {
343
+ if (e.status === "idle")
344
+ for (let a = e.messages.length - 1; a >= 0; a -= 1) {
345
+ const s = e.messages[a];
346
+ if (s.role === "assistant" && s.status === "complete")
347
+ return s.id;
348
+ }
349
+ }, Ra = (e) => {
350
+ for (let a = e.messages.length - 1; a >= 0; a -= 1) {
351
+ const s = e.messages[a];
352
+ if (s.role === "user") return s;
353
+ }
354
+ }, xa = (e, a) => {
355
+ const s = e.messages.findIndex(
356
+ (c) => c.id === a && c.role === "user"
357
+ );
358
+ return {
359
+ ...e,
360
+ error: void 0,
361
+ progress: void 0,
362
+ status: "streaming",
363
+ messages: s < 0 ? e.messages : e.messages.slice(0, s + 1)
364
+ };
365
+ }, Fa = (e) => e.scrollHeight - e.scrollTop - e.clientHeight <= 48, La = (e = "smooth") => globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : e, ze = ({
327
366
  error: e,
328
- onRetry: t
367
+ onRetry: a
329
368
  }) => /* @__PURE__ */ n("div", { className: "make-ai-assistant__message-status make-ai-assistant__message-status--error", role: "alert", children: [
330
- /* @__PURE__ */ a("strong", { children: "本次请求未完成" }),
331
- /* @__PURE__ */ a("span", { children: e.message }),
332
- e.retryable && t ? /* @__PURE__ */ a(
369
+ /* @__PURE__ */ t("strong", { children: "本次请求未完成" }),
370
+ /* @__PURE__ */ t("span", { children: e.message }),
371
+ e.retryable && a ? /* @__PURE__ */ t(
333
372
  "button",
334
373
  {
335
374
  className: "make-ai-assistant__retry",
336
375
  type: "button",
337
- onClick: t,
376
+ onClick: a,
338
377
  children: "重新发送"
339
378
  }
340
379
  ) : null
341
- ] }), ge = ({
380
+ ] }), Ge = ({
381
+ active: e,
382
+ steps: a
383
+ }) => {
384
+ if (!a?.length) return null;
385
+ const s = a[a.length - 1] ?? "处理中";
386
+ return /* @__PURE__ */ n("details", { className: "make-ai-assistant__process", open: e, children: [
387
+ /* @__PURE__ */ n("summary", { children: [
388
+ e ? /* @__PURE__ */ n("span", { className: "make-ai-assistant__progress", role: "status", children: [
389
+ /* @__PURE__ */ t("span", { "aria-hidden": "true" }),
390
+ /* @__PURE__ */ t("span", { children: s })
391
+ ] }) : /* @__PURE__ */ t("span", { className: "make-ai-assistant__process-title", children: "处理过程" }),
392
+ /* @__PURE__ */ n("span", { className: "make-ai-assistant__process-count", children: [
393
+ a.length,
394
+ " 步"
395
+ ] })
396
+ ] }),
397
+ /* @__PURE__ */ t("ol", { children: a.map((c, o) => /* @__PURE__ */ n(
398
+ "li",
399
+ {
400
+ "data-step-active": e && o === a.length - 1 ? !0 : void 0,
401
+ children: [
402
+ /* @__PURE__ */ t("span", { "aria-hidden": "true" }),
403
+ /* @__PURE__ */ t("span", { children: c })
404
+ ]
405
+ },
406
+ `${o}-${c}`
407
+ )) })
408
+ ] });
409
+ }, Da = ({
410
+ copyFeedback: e,
411
+ onCopy: a,
412
+ onRegenerate: s
413
+ }) => !a && !s ? null : /* @__PURE__ */ n("div", { className: "make-ai-assistant__reply-actions", "aria-label": "回复操作", children: [
414
+ a ? /* @__PURE__ */ t("button", { type: "button", onClick: a, children: "复制回答" }) : null,
415
+ s ? /* @__PURE__ */ t("button", { type: "button", onClick: s, children: "重新生成" }) : null,
416
+ e ? /* @__PURE__ */ t(
417
+ "span",
418
+ {
419
+ className: "make-ai-assistant__reply-feedback",
420
+ "data-copy-status": e.status,
421
+ role: "status",
422
+ children: e.message
423
+ }
424
+ ) : null
425
+ ] }), De = ({
342
426
  assistantName: e,
343
- error: t,
427
+ error: a,
344
428
  onRetry: s,
345
429
  progress: c
346
430
  }) => {
347
- const o = t ? "error" : "progress", r = t?.message ?? c;
348
- return r ? /* @__PURE__ */ a(
431
+ const o = a ? "error" : "progress";
432
+ return a?.message ?? c?.message ? /* @__PURE__ */ t(
349
433
  "article",
350
434
  {
351
435
  "aria-label": `${e}的${o === "error" ? "错误消息" : "状态消息"}`,
@@ -353,284 +437,360 @@ const _e = (e) => {
353
437
  "data-message-role": "assistant",
354
438
  "data-message-state": o,
355
439
  children: /* @__PURE__ */ n("div", { className: "make-ai-assistant__message-turn", children: [
356
- /* @__PURE__ */ a(be, { assistantName: e }),
357
- /* @__PURE__ */ a("div", { className: "make-ai-assistant__message-stack", children: t ? /* @__PURE__ */ a(Te, { error: t, onRetry: s }) : /* @__PURE__ */ n("div", { className: "make-ai-assistant__progress", role: "status", children: [
358
- /* @__PURE__ */ a("span", { "aria-hidden": "true" }),
359
- /* @__PURE__ */ a("span", { children: r })
360
- ] }) })
440
+ /* @__PURE__ */ t(Ve, { assistantName: e }),
441
+ /* @__PURE__ */ t("div", { className: "make-ai-assistant__message-stack", children: a ? /* @__PURE__ */ t(ze, { error: a, onRetry: s }) : /* @__PURE__ */ t(Ge, { active: !0, steps: c?.steps }) })
361
442
  ] })
362
443
  }
363
444
  ) : null;
364
- }, ia = (e, t, s, c, o, r, m, u, M) => {
365
- const y = we(e), _ = Ne(e);
366
- return e.messages.map((d) => {
367
- const E = d.role === "assistant", A = d.id === _, N = d.id === y && e.error, $ = E ? r : u;
368
- return /* @__PURE__ */ a(
445
+ }, Pa = (e, a, s, c, o, d, m, h, $, y, k, f, P) => {
446
+ const N = Oe(e), U = He(e), R = $a(e);
447
+ let x;
448
+ return e.messages.map((i) => {
449
+ const _ = i.role === "assistant", q = x;
450
+ _ || (x = i);
451
+ const K = i.id === U, w = i.id === N ? e.error : void 0, B = i.error ?? w, T = _ ? d : h, fe = _ && i.status === "complete" && !B && (i.content.trim() || i.id === R);
452
+ return /* @__PURE__ */ t(
369
453
  "article",
370
454
  {
371
- "aria-label": `${$}的消息`,
372
- className: `make-ai-assistant__message make-ai-assistant__message--${d.role}`,
373
- "data-message-role": d.role,
374
- "data-message-state": N ? "error" : void 0,
375
- "data-message-status": d.status,
455
+ "aria-label": `${T}的消息`,
456
+ className: `make-ai-assistant__message make-ai-assistant__message--${i.role}`,
457
+ "data-message-role": i.role,
458
+ "data-message-state": B ? "error" : void 0,
459
+ "data-message-status": i.status,
376
460
  children: /* @__PURE__ */ n("div", { className: "make-ai-assistant__message-turn", children: [
377
- E ? /* @__PURE__ */ a(be, { assistantName: r }) : /* @__PURE__ */ n("div", { className: "make-ai-assistant__message-identity", children: [
378
- /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-sender", children: $ }),
379
- /* @__PURE__ */ a(na, { src: M })
461
+ _ ? /* @__PURE__ */ t(Ve, { assistantName: d }) : /* @__PURE__ */ n("div", { className: "make-ai-assistant__message-identity", children: [
462
+ /* @__PURE__ */ t("span", { className: "make-ai-assistant__message-sender", children: T }),
463
+ /* @__PURE__ */ t(Ea, { src: $ })
380
464
  ] }),
381
465
  /* @__PURE__ */ n("div", { className: "make-ai-assistant__message-stack", children: [
382
- d.content ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble", children: d.content }) : d.status === "streaming" ? /* @__PURE__ */ n("div", { className: "make-ai-assistant__typing", "aria-label": `${r}正在思考`, children: [
383
- /* @__PURE__ */ a("span", {}),
384
- /* @__PURE__ */ a("span", {}),
385
- /* @__PURE__ */ a("span", {})
386
- ] }) : null,
387
- A && e.progress ? /* @__PURE__ */ n("div", { className: "make-ai-assistant__progress", role: "status", children: [
388
- /* @__PURE__ */ a("span", { "aria-hidden": "true" }),
389
- /* @__PURE__ */ a("span", { children: e.progress.message })
466
+ i.content ? /* @__PURE__ */ t("div", { className: "make-ai-assistant__bubble", children: i.content }) : i.status === "streaming" ? /* @__PURE__ */ n("div", { className: "make-ai-assistant__typing", "aria-label": `${d}正在思考`, children: [
467
+ /* @__PURE__ */ t("span", {}),
468
+ /* @__PURE__ */ t("span", {}),
469
+ /* @__PURE__ */ t("span", {})
390
470
  ] }) : null,
391
- N ? /* @__PURE__ */ a(Te, { error: N, onRetry: m }) : null,
392
- d.artifacts.map((C) => /* @__PURE__ */ a(
471
+ _ ? /* @__PURE__ */ t(
472
+ Ge,
473
+ {
474
+ active: K && e.status === "streaming",
475
+ steps: i.progressSteps
476
+ }
477
+ ) : null,
478
+ B ? /* @__PURE__ */ t(
393
479
  ze,
394
480
  {
395
- artifact: C,
396
- context: t,
481
+ error: B,
482
+ onRetry: w ? m : void 0
483
+ }
484
+ ) : null,
485
+ i.artifacts.map((te) => /* @__PURE__ */ t(
486
+ da,
487
+ {
488
+ artifact: te,
489
+ context: a,
397
490
  onAction: c,
398
491
  onActionError: o,
399
492
  registry: s
400
493
  },
401
- C.id
402
- ))
494
+ te.id
495
+ )),
496
+ fe ? /* @__PURE__ */ t(
497
+ Da,
498
+ {
499
+ copyFeedback: y?.messageId === i.id ? {
500
+ message: y.message,
501
+ status: y.status
502
+ } : void 0,
503
+ onCopy: i.content.trim() ? () => f(i.id, i.content) : void 0,
504
+ onRegenerate: k && i.id === R && q ? () => P({
505
+ userMessage: q,
506
+ assistantMessage: i
507
+ }) : void 0
508
+ }
509
+ ) : null
403
510
  ] })
404
511
  ] })
405
512
  },
406
- d.id
513
+ i.id
407
514
  );
408
515
  });
409
516
  };
410
- function oa({
517
+ function Ua({
411
518
  assistantName: e = "AI 助手",
412
- brandName: t,
519
+ brandName: a,
413
520
  context: s,
414
521
  onAction: c,
415
522
  onActionError: o,
416
- onClose: r,
523
+ onClose: d,
417
524
  onNewConversation: m,
418
- registry: u,
419
- subtitle: M,
420
- suggestions: y = [],
421
- title: _,
422
- transport: d,
423
- userAvatarUrl: E,
424
- userName: A = "你"
525
+ registry: h,
526
+ subtitle: $,
527
+ suggestions: y,
528
+ title: k,
529
+ transport: f,
530
+ userAvatarUrl: P,
531
+ userName: N = "你"
425
532
  }) {
426
- const N = Ae(t, _), [$, C] = U(""), [p, w] = U(te), [G, H] = U(void 0), [Me, Ee] = U(0), [F, J] = U(() => d.loadConversation ? "loading" : "ready"), D = R(void 0), K = R(void 0), L = R(0), re = R(null), Q = R(!0), oe = R(s.app.id), le = Ve(
427
- () => u ?? We(),
428
- [u]
429
- ), W = (i) => {
430
- const k = D.current, g = K.current?.iterator;
431
- return !k && !g ? !1 : (L.current += 1, D.current = void 0, K.current = void 0, console.info("[make-ai-assistant] local run cancellation requested", { reason: i }), k?.abort(), _e(g), !0);
533
+ const U = Ke(a, k), [R, x] = E(""), [i, _] = E(ue), q = S(i);
534
+ q.current = i;
535
+ const [K, w] = E(void 0), [B, T] = E(void 0), [fe, te] = E(0), [V, se] = E(() => f.loadConversation ? "loading" : "ready"), [Ze, H] = E(!1), O = S(void 0), z = S(void 0), G = S(0), re = S(null), F = S(!0), ye = S(s.app.id), Ae = Fe(
536
+ () => h ?? ya(),
537
+ [h]
538
+ ), be = Fe(
539
+ () => Na(y),
540
+ [y]
541
+ ), ne = (r) => {
542
+ const p = O.current, g = z.current?.iterator;
543
+ return !p && !g ? !1 : (G.current += 1, O.current = void 0, z.current = void 0, console.info("[make-ai-assistant] local run cancellation requested", { reason: r }), p?.abort(), Le(g), !0);
432
544
  };
433
- ne(() => () => {
434
- W("unmount");
435
- }, []), ne(() => {
436
- const i = d.loadConversation, k = oe.current !== s.app.id;
437
- if (oe.current = s.app.id, W("reinitialize"), k && (C(""), Q.current = !0), H(void 0), w(te()), !i) {
438
- J("ready");
545
+ ge(() => () => {
546
+ ne("unmount");
547
+ }, []), ge(() => {
548
+ const r = f.loadConversation, p = ye.current !== s.app.id;
549
+ if (ye.current = s.app.id, ne("reinitialize"), p && (x(""), F.current = !0), w(void 0), T(void 0), H(!1), _(ue()), !r) {
550
+ se("ready");
439
551
  return;
440
552
  }
441
553
  const g = new AbortController();
442
- return J("loading"), console.info("[make-ai-assistant] conversation load start", {
554
+ return se("loading"), console.info("[make-ai-assistant] conversation load start", {
443
555
  appId: s.app.id
444
- }), i.call(d, s, { signal: g.signal }).then((v) => {
445
- g.signal.aborted || (w(te(v)), J("ready"), console.info("[make-ai-assistant] conversation load success", {
556
+ }), r.call(f, s, { signal: g.signal }).then((b) => {
557
+ g.signal.aborted || (_(ue(b)), se("ready"), console.info("[make-ai-assistant] conversation load success", {
446
558
  appId: s.app.id,
447
- messageCount: v.messages.length
559
+ messageCount: b.messages.length
448
560
  }));
449
- }).catch((v) => {
561
+ }).catch((b) => {
450
562
  g.signal.aborted || (console.error("[make-ai-assistant] conversation load failed", {
451
563
  appId: s.app.id,
452
- errorType: v instanceof Error ? v.name : typeof v
453
- }), J("error"));
564
+ errorType: b instanceof Error ? b.name : typeof b
565
+ }), se("error"));
454
566
  }), () => g.abort();
455
- }, [s.app.id, Me, d]), ne(() => {
456
- const i = re.current;
457
- if (!i || !Q.current) return;
458
- const k = requestAnimationFrame(() => {
459
- if (!Q.current) return;
460
- const g = p.status === "streaming" || window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
461
- typeof i.scrollTo == "function" ? i.scrollTo({ top: i.scrollHeight, behavior: g }) : i.scrollTop = i.scrollHeight;
567
+ }, [s.app.id, fe, f]), ge(() => {
568
+ const r = re.current;
569
+ if (!r || !F.current) return;
570
+ H(!1);
571
+ const p = requestAnimationFrame(() => {
572
+ if (!F.current) return;
573
+ const g = i.status === "streaming" || globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
574
+ typeof r.scrollTo == "function" ? r.scrollTo({ top: r.scrollHeight, behavior: g }) : r.scrollTop = r.scrollHeight;
462
575
  });
463
- return () => cancelAnimationFrame(k);
464
- }, [p.messages, p.status]);
465
- const $e = () => {
466
- const i = re.current;
467
- i && (Q.current = i.scrollHeight - i.scrollTop - i.clientHeight <= 48);
468
- }, X = async (i) => {
469
- const k = i.trim();
470
- if (!k || F !== "ready" || p.status === "streaming" || D.current) return;
471
- if (ie(
472
- k,
473
- b.messageCharacters
474
- ) > b.messageCharacters) {
475
- H(
476
- `输入内容过长,请控制在 ${b.messageCharacters} 个字符以内`
576
+ return () => cancelAnimationFrame(p);
577
+ }, [i.messages, i.progress, i.status]);
578
+ const je = () => {
579
+ const r = re.current;
580
+ if (!r) return;
581
+ const p = Fa(r);
582
+ F.current = p, H(!p && q.current.messages.length > 0);
583
+ }, Ye = () => {
584
+ const r = re.current;
585
+ if (!r) return;
586
+ F.current = !0, H(!1);
587
+ const p = La();
588
+ typeof r.scrollTo == "function" ? r.scrollTo({ top: r.scrollHeight, behavior: p }) : r.scrollTop = r.scrollHeight;
589
+ }, Ie = async (r, p) => {
590
+ const g = r.trim(), b = q.current, M = p?.regenerateFrom, _e = f.regenerate;
591
+ if (!g || V !== "ready" || b.status === "streaming" || O.current || M && !_e) return;
592
+ if (he(
593
+ g,
594
+ A.messageCharacters
595
+ ) > A.messageCharacters) {
596
+ w(
597
+ `输入内容过长,请控制在 ${A.messageCharacters} 个字符以内`
477
598
  );
478
599
  return;
479
600
  }
480
- const g = { id: Xe("user"), content: k }, v = new AbortController(), P = L.current + 1;
481
- L.current = P, D.current = v, H(void 0), C(""), w((I) => qe(I, g));
601
+ const ce = {
602
+ id: M?.userMessage.id ?? Aa("user"),
603
+ content: g
604
+ }, le = M ? xa(b, M.userMessage.id) : ca(b, ce), de = new AbortController(), Z = G.current + 1;
605
+ G.current = Z, O.current = de, w(void 0), T(void 0), H(!F.current && b.messages.length > 0), M || x(""), _(le);
482
606
  try {
483
- let I = !1, f, de = 0, me = 0, O = 0;
484
- const Z = /* @__PURE__ */ new Map(), ue = /* @__PURE__ */ new Set(), pe = /* @__PURE__ */ new Set(
485
- [...p.messages.map((ae) => ae.id), g.id]
486
- ), j = /* @__PURE__ */ new Set(), he = d.run(
487
- {
488
- threadId: p.threadId,
489
- message: g,
607
+ let C = !1, v, we = 0, Te = 0, Me = 0, ve = 0, W = 0;
608
+ const X = /* @__PURE__ */ new Map(), Ce = /* @__PURE__ */ new Set(), Ee = /* @__PURE__ */ new Set(
609
+ [
610
+ ...le.messages.map((me) => me.id),
611
+ ce.id
612
+ ]
613
+ ), ee = /* @__PURE__ */ new Set(), Se = oa(Ae), $e = { signal: de.signal };
614
+ let ke;
615
+ if (M) {
616
+ if (!_e)
617
+ throw new u("当前 AI 助手不支持重新生成");
618
+ ke = _e({
619
+ threadId: le.threadId,
620
+ message: ce,
621
+ assistantMessage: {
622
+ id: M.assistantMessage.id,
623
+ content: M.assistantMessage.content
624
+ },
490
625
  context: s,
491
- capabilities: Pe(le)
492
- },
493
- { signal: v.signal }
494
- )[Symbol.asyncIterator]();
495
- for (K.current = { iterator: he, requestVersion: P }; ; ) {
496
- const ae = await he.next();
497
- if (L.current !== P || ae.done) break;
626
+ capabilities: Se
627
+ }, $e);
628
+ } else
629
+ ke = f.run(
630
+ {
631
+ threadId: le.threadId,
632
+ message: ce,
633
+ context: s,
634
+ capabilities: Se
635
+ },
636
+ $e
637
+ );
638
+ const Re = ke[Symbol.asyncIterator]();
639
+ for (z.current = { iterator: Re, requestVersion: Z }; ; ) {
640
+ const me = await Re.next();
641
+ if (G.current !== Z || me.done) break;
498
642
  let l;
499
643
  try {
500
- l = Ue(ae.value);
501
- } catch (T) {
502
- throw new h(
503
- T instanceof Error ? T.message : "Invalid assistant event"
644
+ l = la(me.value);
645
+ } catch (I) {
646
+ throw new u(
647
+ I instanceof Error ? I.message : "Invalid assistant event"
504
648
  );
505
649
  }
506
650
  if (l.type === "message.start") {
507
- if (f !== void 0 && f !== l.runId)
508
- throw new h("AI 助手响应 run id 不一致");
509
- if (f ??= l.runId, me += 1, me > b.assistantMessagesPerRun)
510
- throw new h("AI 助手单次响应消息数量超过限制");
511
- if (pe.has(l.messageId))
512
- throw new h("AI 助手响应包含重复的 message id");
513
- pe.add(l.messageId), j.add(l.messageId), Z.set(l.messageId, 0);
651
+ if (v !== void 0 && v !== l.runId)
652
+ throw new u("AI 助手响应 run id 不一致");
653
+ if (v ??= l.runId, Te += 1, Te > A.assistantMessagesPerRun)
654
+ throw new u("AI 助手单次响应消息数量超过限制");
655
+ if (Ee.has(l.messageId))
656
+ throw new u("AI 助手响应包含重复的 message id");
657
+ Ee.add(l.messageId), ee.add(l.messageId), X.set(l.messageId, 0);
514
658
  }
515
659
  if (l.type === "message.delta") {
516
- if (!j.has(l.messageId))
517
- throw new h("AI 助手响应事件顺序无效");
518
- const T = Z.get(l.messageId) ?? 0, V = ie(
660
+ if (!ee.has(l.messageId))
661
+ throw new u("AI 助手响应事件顺序无效");
662
+ const I = X.get(l.messageId) ?? 0, j = he(
519
663
  l.delta,
520
- b.messageCharacters - O
664
+ A.messageCharacters - W
521
665
  );
522
- if (O + V > b.messageCharacters)
523
- throw new h("AI 助手响应文本超过大小限制");
524
- O += V, Z.set(
666
+ if (W + j > A.messageCharacters)
667
+ throw new u("AI 助手响应文本超过大小限制");
668
+ W += j, X.set(
525
669
  l.messageId,
526
- T + V
670
+ I + j
527
671
  );
528
672
  }
529
673
  if (l.type === "message.replace") {
530
- if (!j.has(l.messageId))
531
- throw new h("AI 助手响应事件顺序无效");
532
- const T = Z.get(l.messageId) ?? 0, V = ie(
674
+ if (!ee.has(l.messageId))
675
+ throw new u("AI 助手响应事件顺序无效");
676
+ const I = X.get(l.messageId) ?? 0, j = he(
533
677
  l.content,
534
- b.messageCharacters
535
- ), fe = O - T + V;
536
- if (fe > b.messageCharacters)
537
- throw new h("AI 助手响应文本超过大小限制");
538
- O = fe, Z.set(l.messageId, V);
678
+ A.messageCharacters
679
+ ), xe = W - I + j;
680
+ if (xe > A.messageCharacters)
681
+ throw new u("AI 助手响应文本超过大小限制");
682
+ W = xe, X.set(l.messageId, j);
539
683
  }
540
684
  if (l.type === "run.progress") {
541
- if (f !== void 0 && f !== l.runId)
542
- throw new h("AI 助手响应 run id 不一致");
543
- f ??= l.runId;
685
+ if (v !== void 0 && v !== l.runId)
686
+ throw new u("AI 助手响应 run id 不一致");
687
+ if (v ??= l.runId, Me += 1, Me > A.progressStepsPerRun)
688
+ throw new u("AI 助手处理过程数量超过限制");
689
+ const I = he(
690
+ l.message,
691
+ A.progressCharactersPerRun - ve
692
+ );
693
+ if (ve + I > A.progressCharactersPerRun)
694
+ throw new u("AI 助手处理过程文本超过大小限制");
695
+ ve += I;
544
696
  }
545
697
  if (l.type === "artifact") {
546
- if (!j.has(l.messageId))
547
- throw new h("AI 助手响应事件顺序无效");
548
- if (de += 1, de > b.artifactsPerRun)
549
- throw new h("AI 助手单次响应 Artifact 数量超过限制");
550
- if (ue.has(l.artifact.id))
551
- throw new h("AI 助手响应包含重复的 Artifact id");
552
- ue.add(l.artifact.id);
698
+ if (!ee.has(l.messageId))
699
+ throw new u("AI 助手响应事件顺序无效");
700
+ if (we += 1, we > A.artifactsPerRun)
701
+ throw new u("AI 助手单次响应 Artifact 数量超过限制");
702
+ if (Ce.has(l.artifact.id))
703
+ throw new u("AI 助手响应包含重复的 Artifact id");
704
+ Ce.add(l.artifact.id);
553
705
  }
554
- if (l.type === "message.complete" && !j.delete(l.messageId))
555
- throw new h("AI 助手响应事件顺序无效");
556
- if (l.type === "run.complete" && f !== void 0 && f !== l.runId)
557
- throw new h("AI 助手响应 run id 不一致");
558
- if (l.type === "run.cancelled" && l.runId !== void 0 && f !== void 0 && f !== l.runId)
559
- throw new h("AI 助手响应 run id 不一致");
560
- if (w((T) => se(T, l)), l.type === "error" || l.type === "run.cancelled" || l.type === "run.complete") {
561
- I = !0;
706
+ if (l.type === "message.complete" && !ee.delete(l.messageId))
707
+ throw new u("AI 助手响应事件顺序无效");
708
+ if (l.type === "run.complete" && v !== void 0 && v !== l.runId)
709
+ throw new u("AI 助手响应 run id 不一致");
710
+ if (l.type === "run.cancelled" && l.runId !== void 0 && v !== void 0 && v !== l.runId)
711
+ throw new u("AI 助手响应 run id 不一致");
712
+ if (_((I) => pe(I, l)), l.type === "error" || l.type === "run.cancelled" || l.type === "run.complete") {
713
+ C = !0;
562
714
  break;
563
715
  }
564
716
  }
565
- if (!I)
566
- throw new h("AI 助手流式响应在终止事件前结束");
567
- } catch (I) {
568
- if (L.current !== P) return;
569
- if (v.signal.aborted) {
570
- w(
571
- (f) => se(f, { type: "run.cancelled" })
717
+ if (!C)
718
+ throw new u("AI 助手流式响应在终止事件前结束");
719
+ } catch (C) {
720
+ if (G.current !== Z) return;
721
+ if (de.signal.aborted) {
722
+ _(
723
+ (v) => pe(v, { type: "run.cancelled" })
572
724
  );
573
725
  return;
574
726
  }
575
727
  console.error("[make-ai-assistant] assistant run failed", {
576
728
  appId: s.app.id,
577
- errorType: I instanceof Error ? I.name : typeof I
578
- }), w(
579
- (f) => se(f, {
729
+ errorType: C instanceof Error ? C.name : typeof C
730
+ }), _(
731
+ (v) => pe(v, {
580
732
  type: "error",
581
733
  code: "TRANSPORT_ERROR",
582
- message: I instanceof h ? I.message : "连接失败,请重试",
734
+ message: C instanceof u ? C.message : "连接失败,请重试",
583
735
  retryable: !0
584
736
  })
585
737
  );
586
738
  } finally {
587
- L.current === P && D.current === v && (D.current = void 0), K.current?.requestVersion === P && (_e(K.current.iterator), K.current = void 0);
739
+ G.current === Z && O.current === de && (O.current = void 0), z.current?.requestVersion === Z && (Le(z.current.iterator), z.current = void 0);
740
+ }
741
+ }, ie = (r) => Ie(r), Je = (r) => Ie(r.userMessage.content, { regenerateFrom: r }), Qe = async (r, p) => {
742
+ try {
743
+ await wa(p), T({ messageId: r, message: "已复制", status: "success" });
744
+ } catch (g) {
745
+ console.error("[make-ai-assistant] copy answer failed", {
746
+ errorType: g instanceof Error ? g.name : typeof g
747
+ }), T({ messageId: r, message: "复制失败", status: "error" });
588
748
  }
589
- }, Ce = (i) => {
590
- i.preventDefault(), X($);
591
- }, Re = (i) => {
592
- i.key === "Enter" && !i.shiftKey && !i.nativeEvent.isComposing && (i.preventDefault(), X($));
593
- }, Se = () => {
594
- W("stop") && w(
595
- (i) => se(i, { type: "run.cancelled" })
749
+ }, We = (r) => {
750
+ r.preventDefault(), ie(R);
751
+ }, Xe = (r) => {
752
+ r.key === "Enter" && !r.shiftKey && !r.nativeEvent.isComposing && (r.preventDefault(), ie(R));
753
+ }, ea = () => {
754
+ ne("stop") && _(
755
+ (r) => pe(r, { type: "run.cancelled" })
596
756
  );
597
- }, xe = () => {
598
- W("new-conversation"), C(""), H(void 0), w(te()), m?.();
599
- }, Fe = d.features?.remoteCancellation === !1 ? "停止接收" : "停止生成", De = Ne(p), Ke = we(p), ee = [...p.messages].reverse().find((i) => i.role === "user"), ce = () => {
600
- ee && X(ee.content);
757
+ }, aa = () => {
758
+ ne("new-conversation"), x(""), w(void 0), T(void 0), H(!1), F.current = !0, _(ue()), m?.();
759
+ }, ta = f.features?.remoteCancellation === !1 ? "停止接收" : "停止生成", sa = He(i), ra = Oe(i), oe = Ra(i), na = typeof f.regenerate == "function" && f.features?.regeneration !== !1, Ne = () => {
760
+ oe && ie(oe.content);
601
761
  };
602
762
  return /* @__PURE__ */ n("section", { className: "make-ai-assistant make-ai-assistant__panel", children: [
603
763
  /* @__PURE__ */ n("header", { className: "make-ai-assistant__header", children: [
604
- /* @__PURE__ */ a(Y, {}),
764
+ /* @__PURE__ */ t(ae, {}),
605
765
  /* @__PURE__ */ n("div", { children: [
606
- /* @__PURE__ */ a("h2", { children: N }),
607
- /* @__PURE__ */ a("p", { children: M ?? `当前应用:${s.app.name ?? "未命名应用"}` })
766
+ /* @__PURE__ */ t("h2", { children: U }),
767
+ /* @__PURE__ */ t("p", { children: $ ?? `当前应用:${s.app.name ?? "未命名应用"}` })
608
768
  ] }),
609
769
  /* @__PURE__ */ n("div", { className: "make-ai-assistant__header-actions", children: [
610
- d.features?.newConversation !== !1 ? /* @__PURE__ */ a(
770
+ f.features?.newConversation !== !1 ? /* @__PURE__ */ t(
611
771
  "button",
612
772
  {
613
773
  "aria-label": "新建对话",
614
774
  className: "make-ai-assistant__icon-button",
615
775
  type: "button",
616
- onClick: xe,
617
- children: /* @__PURE__ */ a(ta, {})
776
+ onClick: aa,
777
+ children: /* @__PURE__ */ t(Ma, {})
618
778
  }
619
779
  ) : null,
620
- r ? /* @__PURE__ */ a(
780
+ d ? /* @__PURE__ */ t(
621
781
  "button",
622
782
  {
623
- "aria-label": `关闭 ${N}`,
783
+ "aria-label": `关闭 ${U}`,
624
784
  className: "make-ai-assistant__icon-button",
625
785
  type: "button",
626
- onClick: r,
627
- children: /* @__PURE__ */ a(aa, {})
786
+ onClick: d,
787
+ children: /* @__PURE__ */ t(Ta, {})
628
788
  }
629
789
  ) : null
630
790
  ] })
631
791
  ] }),
632
792
  /* @__PURE__ */ n("div", { className: "make-ai-assistant__privacy-note", role: "note", children: [
633
- /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "◇" }),
793
+ /* @__PURE__ */ t("span", { "aria-hidden": "true", children: "◇" }),
634
794
  "当前页面上下文会随请求发送,数据权限以宿主服务端校验结果为准"
635
795
  ] }),
636
796
  /* @__PURE__ */ n(
@@ -641,177 +801,195 @@ function oa({
641
801
  "aria-relevant": "additions text",
642
802
  ref: re,
643
803
  role: "log",
644
- onScroll: $e,
804
+ onScroll: je,
645
805
  children: [
646
- F === "loading" ? /* @__PURE__ */ n("div", { className: "make-ai-assistant__empty", role: "status", children: [
647
- /* @__PURE__ */ a(Y, {}),
648
- /* @__PURE__ */ a("h3", { children: "正在恢复对话" }),
649
- /* @__PURE__ */ a("p", { children: "正在读取当前 App 的历史消息…" })
650
- ] }) : F === "error" ? /* @__PURE__ */ n("div", { className: "make-ai-assistant__empty", role: "alert", children: [
651
- /* @__PURE__ */ a(Y, {}),
652
- /* @__PURE__ */ a("h3", { children: "暂时无法加载对话" }),
653
- /* @__PURE__ */ a("p", { children: "请检查网络后重试。" }),
654
- /* @__PURE__ */ a(
806
+ V === "loading" ? /* @__PURE__ */ n("div", { className: "make-ai-assistant__empty", role: "status", children: [
807
+ /* @__PURE__ */ t(ae, {}),
808
+ /* @__PURE__ */ t("h3", { children: "正在恢复对话" }),
809
+ /* @__PURE__ */ t("p", { children: "正在读取当前 App 的历史消息…" })
810
+ ] }) : V === "error" ? /* @__PURE__ */ n("div", { className: "make-ai-assistant__empty", role: "alert", children: [
811
+ /* @__PURE__ */ t(ae, {}),
812
+ /* @__PURE__ */ t("h3", { children: "暂时无法加载对话" }),
813
+ /* @__PURE__ */ t("p", { children: "请检查网络后重试。" }),
814
+ /* @__PURE__ */ t(
655
815
  "button",
656
816
  {
657
817
  className: "make-ai-assistant__retry",
658
818
  type: "button",
659
- onClick: () => Ee((i) => i + 1),
819
+ onClick: () => te((r) => r + 1),
660
820
  children: "重新加载"
661
821
  }
662
822
  )
663
- ] }) : p.messages.length === 0 ? /* @__PURE__ */ n("div", { className: "make-ai-assistant__empty", children: [
664
- /* @__PURE__ */ a(Y, {}),
665
- /* @__PURE__ */ a("h3", { children: "有什么可以帮你?" }),
666
- /* @__PURE__ */ a("p", { children: "我会结合当前 App 和页面上下文理解问题,并用适合的方式展示结果。" })
667
- ] }) : ia(
668
- p,
823
+ ] }) : i.messages.length === 0 ? /* @__PURE__ */ n("div", { className: "make-ai-assistant__empty", children: [
824
+ /* @__PURE__ */ t(ae, {}),
825
+ /* @__PURE__ */ t("h3", { children: "有什么可以帮你?" }),
826
+ /* @__PURE__ */ t("p", { children: "我会结合当前 App、页面位置和宿主允许的上下文回答,并把过程与结果分开展示。" })
827
+ ] }) : Pa(
828
+ i,
669
829
  s,
670
- le,
830
+ Ae,
671
831
  c,
672
832
  o,
673
833
  e,
674
- ee ? ce : void 0,
675
- A,
676
- E
834
+ oe ? Ne : void 0,
835
+ N,
836
+ P,
837
+ B,
838
+ na,
839
+ (r, p) => {
840
+ Qe(r, p);
841
+ },
842
+ (r) => {
843
+ Je(r);
844
+ }
677
845
  ),
678
- p.progress && !De ? /* @__PURE__ */ a(
679
- ge,
846
+ i.progress && !sa ? /* @__PURE__ */ t(
847
+ De,
680
848
  {
681
849
  assistantName: e,
682
- progress: p.progress.message
850
+ progress: i.progress
683
851
  }
684
852
  ) : null,
685
- p.error && !Ke ? /* @__PURE__ */ a(
686
- ge,
853
+ i.error && !ra ? /* @__PURE__ */ t(
854
+ De,
687
855
  {
688
856
  assistantName: e,
689
- error: p.error,
690
- onRetry: ee ? ce : void 0
857
+ error: i.error,
858
+ onRetry: oe ? Ne : void 0
691
859
  }
692
860
  ) : null
693
861
  ]
694
862
  }
695
863
  ),
864
+ Ze ? /* @__PURE__ */ t(
865
+ "button",
866
+ {
867
+ "aria-label": "回到最新消息",
868
+ className: "make-ai-assistant__back-to-latest",
869
+ type: "button",
870
+ onClick: Ye,
871
+ children: "回到最新消息"
872
+ }
873
+ ) : null,
696
874
  /* @__PURE__ */ n("footer", { className: "make-ai-assistant__composer-region", children: [
697
- F === "ready" && y.length > 0 && p.messages.length === 0 ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__suggestions", "aria-label": "推荐问题", children: y.map((i, k) => /* @__PURE__ */ a(
875
+ V === "ready" && be.length > 0 && i.messages.length === 0 ? /* @__PURE__ */ t("div", { className: "make-ai-assistant__suggestions", "aria-label": "推荐问题", children: be.map((r, p) => /* @__PURE__ */ t(
698
876
  "button",
699
877
  {
700
878
  type: "button",
701
879
  onClick: () => {
702
- X(i);
880
+ ie(r);
703
881
  },
704
- children: i
882
+ children: r
705
883
  },
706
- `${k}-${i}`
884
+ `${p}-${r}`
707
885
  )) }) : null,
708
- /* @__PURE__ */ n("form", { className: "make-ai-assistant__composer", onSubmit: Ce, children: [
709
- /* @__PURE__ */ a(
886
+ /* @__PURE__ */ n("form", { className: "make-ai-assistant__composer", onSubmit: We, children: [
887
+ /* @__PURE__ */ t(
710
888
  "textarea",
711
889
  {
712
890
  "aria-label": `向 ${e} 提问`,
713
- "aria-describedby": G ? "make-ai-composer-error" : void 0,
714
- "aria-invalid": G ? !0 : void 0,
891
+ "aria-describedby": K ? "make-ai-composer-error" : void 0,
892
+ "aria-invalid": K ? !0 : void 0,
715
893
  autoFocus: !0,
716
- disabled: F !== "ready" || p.status === "streaming",
894
+ disabled: V !== "ready" || i.status === "streaming",
717
895
  placeholder: `询问当前 ${s.app.name ?? "App"} 中的数据…`,
718
896
  rows: 2,
719
- value: $,
720
- onChange: (i) => {
721
- C(i.currentTarget.value), H(void 0);
897
+ value: R,
898
+ onChange: (r) => {
899
+ x(r.currentTarget.value), w(void 0);
722
900
  },
723
- onKeyDown: Re
901
+ onKeyDown: Xe
724
902
  }
725
903
  ),
726
- p.status === "streaming" ? /* @__PURE__ */ a(
904
+ i.status === "streaming" ? /* @__PURE__ */ t(
727
905
  "button",
728
906
  {
729
- "aria-label": Fe,
907
+ "aria-label": ta,
730
908
  className: "make-ai-assistant__send make-ai-assistant__send--stop",
731
909
  type: "button",
732
- onClick: Se,
733
- children: /* @__PURE__ */ a("span", { "aria-hidden": "true" })
910
+ onClick: ea,
911
+ children: /* @__PURE__ */ t("span", { "aria-hidden": "true" })
734
912
  }
735
- ) : /* @__PURE__ */ a(
913
+ ) : /* @__PURE__ */ t(
736
914
  "button",
737
915
  {
738
916
  "aria-label": "发送",
739
917
  className: "make-ai-assistant__send",
740
- disabled: F !== "ready" || !$.trim(),
918
+ disabled: V !== "ready" || !R.trim(),
741
919
  type: "submit",
742
- children: /* @__PURE__ */ a(sa, {})
920
+ children: /* @__PURE__ */ t(Ca, {})
743
921
  }
744
922
  )
745
923
  ] }),
746
- G ? /* @__PURE__ */ a("p", { id: "make-ai-composer-error", role: "alert", children: G }) : null,
747
- /* @__PURE__ */ a("p", { children: "AI 生成的结果可能存在偏差,重要数据请核对明细。" })
924
+ K ? /* @__PURE__ */ t("p", { id: "make-ai-composer-error", role: "alert", children: K }) : null,
925
+ /* @__PURE__ */ t("p", { children: "AI 生成的结果可能存在偏差,重要数据请核对明细。" })
748
926
  ] })
749
927
  ] });
750
928
  }
751
- function pa({
929
+ function Ha({
752
930
  defaultOpen: e = !1,
753
- hideLauncher: t = !1,
931
+ hideLauncher: a = !1,
754
932
  launcher: s,
755
933
  onOpenChange: c,
756
934
  open: o,
757
- ...r
935
+ ...d
758
936
  }) {
759
- const m = Ae(r.brandName, r.title), [u, M] = U(e), y = R(null), _ = o ?? u, d = (A) => {
760
- o === void 0 && M(A), c?.(A), A || requestAnimationFrame(() => y.current?.focus());
761
- }, E = () => d(!_);
762
- return ne(() => {
763
- if (!_) return;
764
- const A = (N) => {
765
- N.key === "Escape" && (d(!1), requestAnimationFrame(() => y.current?.focus()));
937
+ const m = Ke(d.brandName, d.title), [h, $] = E(e), y = S(null), k = o ?? h, f = (N) => {
938
+ o === void 0 && $(N), c?.(N), N || requestAnimationFrame(() => y.current?.focus());
939
+ }, P = () => f(!k);
940
+ return ge(() => {
941
+ if (!k) return;
942
+ const N = (U) => {
943
+ U.key === "Escape" && (f(!1), requestAnimationFrame(() => y.current?.focus()));
766
944
  };
767
- return document.addEventListener("keydown", A), () => document.removeEventListener("keydown", A);
768
- }, [c, _]), /* @__PURE__ */ n("div", { className: "make-ai-assistant", "data-open": _ || void 0, children: [
769
- !t && (!_ || s) ? s ? s({ open: _, toggle: E }) : /* @__PURE__ */ n(
945
+ return document.addEventListener("keydown", N), () => document.removeEventListener("keydown", N);
946
+ }, [c, k]), /* @__PURE__ */ n("div", { className: "make-ai-assistant", "data-open": k || void 0, children: [
947
+ !a && (!k || s) ? s ? s({ open: k, toggle: P }) : /* @__PURE__ */ n(
770
948
  "button",
771
949
  {
772
- "aria-label": _ ? `关闭 ${m}` : `打开 ${m}`,
773
- "aria-expanded": _,
950
+ "aria-label": k ? `关闭 ${m}` : `打开 ${m}`,
951
+ "aria-expanded": k,
774
952
  className: "make-ai-assistant__launcher",
775
953
  ref: y,
776
954
  type: "button",
777
- onClick: E,
955
+ onClick: P,
778
956
  children: [
779
- /* @__PURE__ */ a("span", { className: "make-ai-assistant__launcher-orbit", "aria-hidden": "true" }),
780
- /* @__PURE__ */ a(Ie, {})
957
+ /* @__PURE__ */ t("span", { className: "make-ai-assistant__launcher-orbit", "aria-hidden": "true" }),
958
+ /* @__PURE__ */ t(Be, {})
781
959
  ]
782
960
  }
783
961
  ) : null,
784
- _ ? /* @__PURE__ */ a(
962
+ k ? /* @__PURE__ */ t(
785
963
  "aside",
786
964
  {
787
965
  "aria-label": m,
788
966
  "aria-modal": "false",
789
967
  className: "make-ai-assistant__drawer",
790
968
  role: "dialog",
791
- children: /* @__PURE__ */ a(oa, { ...r, onClose: () => d(!1) })
969
+ children: /* @__PURE__ */ t(Ua, { ...d, onClose: () => f(!1) })
792
970
  }
793
971
  ) : null
794
972
  ] });
795
973
  }
796
974
  export {
797
- ze as ArtifactRenderer,
798
- oa as AssistantPanel,
799
- ka as MAKE_AI_ARTIFACT_KINDS,
800
- va as MAKE_AI_ARTIFACT_LIMITS,
801
- ya as MAKE_AI_ARTIFACT_SCHEMA_VERSION,
802
- b as MAKE_AI_CONVERSATION_LIMITS,
803
- pa as MakeAiAssistant,
804
- qe as appendUserMessage,
805
- Pe as createArtifactCapabilities,
806
- ke as createArtifactTemplateRegistry,
807
- te as createAssistantConversationState,
808
- We as createPlatformArtifactRegistry,
809
- _a as extendArtifactTemplateRegistry,
810
- x as formatArtifactValue,
811
- Aa as parseArtifact,
812
- Ue as parseAssistantEvent,
813
- Qe as platformArtifactTemplates,
814
- se as reduceAssistantEvent,
815
- Le as resolveArtifactTemplate,
816
- Ia as validateArtifact
975
+ da as ArtifactRenderer,
976
+ Ua as AssistantPanel,
977
+ ja as MAKE_AI_ARTIFACT_KINDS,
978
+ Ya as MAKE_AI_ARTIFACT_LIMITS,
979
+ Ja as MAKE_AI_ARTIFACT_SCHEMA_VERSION,
980
+ A as MAKE_AI_CONVERSATION_LIMITS,
981
+ Ha as MakeAiAssistant,
982
+ ca as appendUserMessage,
983
+ oa as createArtifactCapabilities,
984
+ Pe as createArtifactTemplateRegistry,
985
+ ue as createAssistantConversationState,
986
+ ya as createPlatformArtifactRegistry,
987
+ Ga as extendArtifactTemplateRegistry,
988
+ D as formatArtifactValue,
989
+ Qa as parseArtifact,
990
+ la as parseAssistantEvent,
991
+ ka as platformArtifactTemplates,
992
+ pe as reduceAssistantEvent,
993
+ ia as resolveArtifactTemplate,
994
+ Wa as validateArtifact
817
995
  };