@qfei-design/make-ai-assistant 0.1.0 → 0.1.3

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,520 +1,632 @@
1
- import { jsxs as r, jsx as a, Fragment as N } from "react/jsx-runtime";
2
- import { resolveArtifactTemplate as pe, createArtifactTemplateRegistry as re, createArtifactCapabilities as he } from "./index.mjs";
3
- import { extendArtifactTemplateRegistry as Oe } from "./index.mjs";
4
- import { useState as L, useRef as S, useMemo as fe, useEffect as Y } from "react";
5
- import { c as ae, a as te, M as b, b as _e, p as ke, r as B } from "./conversation-B5kECJz8.js";
6
- import { d as je, e as Ue, f as Ye, g as ze, v as Ge } from "./conversation-B5kECJz8.js";
7
- function ve({
1
+ import { jsxs as r, jsx as t, Fragment as C } from "react/jsx-runtime";
2
+ import { resolveArtifactTemplate as Se, createArtifactTemplateRegistry as fe, createArtifactCapabilities as xe } from "./index.mjs";
3
+ import { extendArtifactTemplateRegistry as ca } from "./index.mjs";
4
+ import { useState as V, useRef as E, useMemo as Fe, useEffect as ae } from "react";
5
+ import { a as X, c as se, M as w, b as De, p as Pe, r as ee } from "./conversation-Dy2Sghjv.js";
6
+ import { d as ma, e as ua, f as pa, g as ha, v as fa } from "./conversation-Dy2Sghjv.js";
7
+ function Ke({
8
8
  artifact: e,
9
- context: t,
10
- fallback: n,
9
+ context: a,
10
+ fallback: s,
11
11
  onAction: c,
12
- onActionError: i,
13
- registry: s
12
+ onActionError: n,
13
+ registry: l
14
14
  }) {
15
- const m = pe(s, e, t);
16
- if (!m)
17
- return n ? n(e) : /* @__PURE__ */ r("section", { className: "make-ai-artifact make-ai-artifact--unsupported", role: "status", children: [
18
- /* @__PURE__ */ a("strong", { children: "暂不支持展示此结果" }),
15
+ const u = Se(l, e, a);
16
+ if (!u)
17
+ return s ? s(e) : /* @__PURE__ */ r("section", { className: "make-ai-artifact make-ai-artifact--unsupported", role: "status", children: [
18
+ /* @__PURE__ */ t("strong", { children: "暂不支持展示此结果" }),
19
19
  /* @__PURE__ */ r("span", { children: [
20
20
  "结果类型:",
21
21
  e.kind
22
22
  ] })
23
23
  ] });
24
- const u = {
25
- context: t,
24
+ const p = {
25
+ context: a,
26
26
  onAction: c,
27
- onActionError: i
27
+ onActionError: n
28
28
  };
29
- return m.template.render(e, t, u);
29
+ return u.template.render(e, a, p);
30
30
  }
31
- const w = (e, t, n) => {
31
+ const $ = (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, i = {
34
+ if (typeof e != "number") return `${e}${a?.unit ?? ""}`;
35
+ const c = a?.precision, n = {
36
36
  maximumFractionDigits: c ?? 2,
37
37
  minimumFractionDigits: c
38
38
  };
39
- t?.style === "currency" && t.currency ? (i.style = "currency", i.currency = t.currency) : t?.style === "percent" && (i.style = "percent");
39
+ a?.style === "currency" && a.currency ? (n.style = "currency", n.currency = a.currency) : a?.style === "percent" && (n.style = "percent");
40
40
  try {
41
- const s = t?.style === "percent" ? e / 100 : e;
42
- return `${new Intl.NumberFormat(n, i).format(s)}${t?.unit ?? ""}`;
41
+ const l = a?.style === "percent" ? e / 100 : e;
42
+ return `${new Intl.NumberFormat(s, n).format(l)}${a?.unit ?? ""}`;
43
43
  } catch {
44
- return `${e}${t?.unit ?? ""}`;
44
+ return `${e}${a?.unit ?? ""}`;
45
45
  }
46
- }, se = (e) => {
47
- let t = Number.POSITIVE_INFINITY, n = Number.NEGATIVE_INFINITY;
46
+ }, ge = (e) => {
47
+ let a = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
48
48
  for (const c of e)
49
- t = Math.min(t, c), n = Math.max(n, c);
50
- return Number.isFinite(t) && Number.isFinite(n) ? { min: t, max: n } : { min: 0, max: 0 };
51
- }, ie = (e, t, n) => {
52
- if (!n.onAction) return;
53
- const c = (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
+ }, _e = (e, a, s) => {
52
+ if (!s.onAction) return;
53
+ const c = (l) => {
54
54
  console.error("[make-ai-assistant] host action error handler failed", {
55
55
  actionId: e.id,
56
- artifactId: t.artifact.id,
57
- errorType: s instanceof Error ? s.name : typeof s,
56
+ artifactId: a.artifact.id,
57
+ errorType: l instanceof Error ? l.name : typeof l,
58
58
  intent: e.intent
59
59
  });
60
- }, i = (s) => {
61
- if (n.onActionError) {
60
+ }, n = (l) => {
61
+ if (s.onActionError) {
62
62
  try {
63
63
  Promise.resolve(
64
- n.onActionError(s, e, t)
64
+ s.onActionError(l, e, a)
65
65
  ).catch(c);
66
- } catch (m) {
67
- c(m);
66
+ } catch (u) {
67
+ c(u);
68
68
  }
69
69
  return;
70
70
  }
71
71
  console.error("[make-ai-assistant] host action failed", {
72
72
  actionId: e.id,
73
- artifactId: t.artifact.id,
74
- errorType: s instanceof Error ? s.name : typeof s,
73
+ artifactId: a.artifact.id,
74
+ errorType: l instanceof Error ? l.name : typeof l,
75
75
  intent: e.intent
76
76
  });
77
77
  };
78
78
  try {
79
- Promise.resolve(n.onAction(e, t)).catch(i);
80
- } catch (s) {
81
- i(s);
79
+ Promise.resolve(s.onAction(e, a)).catch(n);
80
+ } catch (l) {
81
+ n(l);
82
82
  }
83
- }, C = (e, t) => e.actions?.length && t.onAction ? /* @__PURE__ */ a("div", { className: "make-ai-artifact__actions", children: e.actions.map((n) => /* @__PURE__ */ r(
83
+ }, L = (e, a) => e.actions?.length && a.onAction ? /* @__PURE__ */ t("div", { className: "make-ai-artifact__actions", children: e.actions.map((s) => /* @__PURE__ */ r(
84
84
  "button",
85
85
  {
86
- className: `make-ai-artifact__action make-ai-artifact__action--${n.appearance ?? "link"}`,
86
+ className: `make-ai-artifact__action make-ai-artifact__action--${s.appearance ?? "link"}`,
87
87
  type: "button",
88
- onClick: () => ie(n, { artifact: e, context: t.context }, t),
88
+ onClick: () => _e(s, { artifact: e, context: a.context }, a),
89
89
  children: [
90
- n.label,
91
- /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "→" })
90
+ s.label,
91
+ /* @__PURE__ */ t("span", { "aria-hidden": "true", children: "→" })
92
92
  ]
93
93
  },
94
- n.id
95
- )) }) : null, F = (e, t, n = "") => /* @__PURE__ */ r(
94
+ s.id
95
+ )) }) : null, z = (e, a, s = "") => /* @__PURE__ */ r(
96
96
  "section",
97
97
  {
98
98
  "aria-label": e.title ?? `${e.kind} result`,
99
- className: `make-ai-artifact ${n}`.trim(),
99
+ className: `make-ai-artifact ${s}`.trim(),
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
- ), ye = ({
108
+ ), Ve = ({
109
109
  artifact: e,
110
- renderContext: t
110
+ renderContext: a
111
111
  }) => {
112
- const n = e.data.delta, c = n ? w(
113
- n.value,
114
- n.format === "percent" ? { style: "percent" } : void 0,
115
- t.context.locale
112
+ const s = e.data.delta, c = s ? $(
113
+ s.value,
114
+ s.format === "percent" ? { style: "percent" } : void 0,
115
+ a.context.locale
116
116
  ) : void 0;
117
- return F(
117
+ return z(
118
118
  e,
119
- /* @__PURE__ */ r(N, { children: [
120
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__metric-value", children: w(
119
+ /* @__PURE__ */ r(C, { children: [
120
+ /* @__PURE__ */ t("div", { className: "make-ai-artifact__metric-value", children: $(
121
121
  e.data.value,
122
122
  e.data.format,
123
- t.context.locale
123
+ a.context.locale
124
124
  ) }),
125
- n ? /* @__PURE__ */ r(
125
+ s ? /* @__PURE__ */ r(
126
126
  "div",
127
127
  {
128
- className: `make-ai-artifact__delta make-ai-artifact__delta--${n.direction ?? "flat"}`,
128
+ className: `make-ai-artifact__delta make-ai-artifact__delta--${s.direction ?? "flat"}`,
129
129
  children: [
130
- /* @__PURE__ */ a("span", { "aria-hidden": "true", children: n.direction === "up" ? "↗" : n.direction === "down" ? "↘" : "→" }),
131
- /* @__PURE__ */ a("span", { children: c }),
132
- n.label ? /* @__PURE__ */ a("span", { children: n.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
- C(e, t)
136
+ e.data.context ? /* @__PURE__ */ t("p", { className: "make-ai-artifact__context", children: e.data.context }) : null,
137
+ L(e, a)
138
138
  ] }),
139
139
  "make-ai-artifact--metric"
140
140
  );
141
- }, ge = ({
141
+ }, qe = ({
142
142
  artifact: e,
143
- renderContext: t
144
- }) => F(
143
+ renderContext: a
144
+ }) => z(
145
145
  e,
146
- /* @__PURE__ */ r(N, { children: [
147
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__comparison", children: e.data.items.map((n) => /* @__PURE__ */ r("div", { className: "make-ai-artifact__comparison-item", children: [
148
- /* @__PURE__ */ a("span", { children: n.label }),
149
- /* @__PURE__ */ a("strong", { children: w(n.value, n.format, t.context.locale) }),
150
- n.hint ? /* @__PURE__ */ a("small", { children: n.hint }) : null
151
- ] }, n.id)) }),
152
- C(e, t)
146
+ /* @__PURE__ */ r(C, { children: [
147
+ /* @__PURE__ */ t("div", { className: "make-ai-artifact__comparison", children: e.data.items.map((s) => /* @__PURE__ */ r("div", { className: "make-ai-artifact__comparison-item", children: [
148
+ /* @__PURE__ */ t("span", { children: s.label }),
149
+ /* @__PURE__ */ t("strong", { children: $(s.value, s.format, a.context.locale) }),
150
+ s.hint ? /* @__PURE__ */ t("small", { children: s.hint }) : null
151
+ ] }, s.id)) }),
152
+ L(e, a)
153
153
  ] }),
154
154
  "make-ai-artifact--comparison"
155
- ), be = ({
155
+ ), Le = ({
156
156
  artifact: e,
157
- renderContext: t
157
+ renderContext: a
158
158
  }) => {
159
- const n = e.data.series.flatMap((m) => m.points.map((u) => u.y)), { max: c, min: i } = se(n), s = c - i || 1;
160
- return F(
159
+ const s = e.data.series.flatMap((u) => u.points.map((p) => p.y)), { max: c, min: n } = ge(s), l = c - n || 1;
160
+ return z(
161
161
  e,
162
- /* @__PURE__ */ r(N, { children: [
163
- /* @__PURE__ */ a("div", { className: "make-ai-artifact__trend", children: e.data.series.map((m) => /* @__PURE__ */ r("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, A) => {
166
- const h = 18 + (u.y - i) / s * 70;
162
+ /* @__PURE__ */ r(C, { children: [
163
+ /* @__PURE__ */ t("div", { className: "make-ai-artifact__trend", children: e.data.series.map((u) => /* @__PURE__ */ r("div", { className: "make-ai-artifact__trend-series", children: [
164
+ /* @__PURE__ */ t("div", { className: "make-ai-artifact__trend-label", children: u.label }),
165
+ /* @__PURE__ */ t("div", { className: "make-ai-artifact__trend-bars", children: u.points.map((p, A) => {
166
+ const f = 18 + (p.y - n) / l * 70;
167
167
  return /* @__PURE__ */ r("div", { className: "make-ai-artifact__trend-point", children: [
168
- /* @__PURE__ */ a(
168
+ /* @__PURE__ */ t(
169
169
  "span",
170
170
  {
171
- "aria-label": `${u.x}: ${w(
172
- u.y,
173
- m.format,
174
- t.context.locale
171
+ "aria-label": `${p.x}: ${$(
172
+ p.y,
173
+ u.format,
174
+ a.context.locale
175
175
  )}`,
176
176
  className: "make-ai-artifact__trend-bar",
177
177
  role: "img",
178
- style: { height: `${h}%` },
179
- title: `${u.x}: ${w(
180
- u.y,
181
- m.format,
182
- t.context.locale
178
+ style: { height: `${f}%` },
179
+ title: `${p.x}: ${$(
180
+ p.y,
181
+ u.format,
182
+ a.context.locale
183
183
  )}`
184
184
  }
185
185
  ),
186
- /* @__PURE__ */ a("small", { children: u.x })
187
- ] }, `${u.x}-${A}`);
186
+ /* @__PURE__ */ t("small", { children: p.x })
187
+ ] }, `${p.x}-${A}`);
188
188
  }) })
189
- ] }, m.id)) }),
190
- C(e, t)
189
+ ] }, u.id)) }),
190
+ L(e, a)
191
191
  ] }),
192
192
  "make-ai-artifact--trend"
193
193
  );
194
- }, Ae = ({
194
+ }, ze = ({
195
195
  artifact: e,
196
- renderContext: t
196
+ renderContext: a
197
197
  }) => {
198
- const { max: n } = se(
199
- e.data.items.map((i) => Math.abs(i.value))
200
- ), c = Math.max(n, 1);
201
- return F(
198
+ const { max: s } = ge(
199
+ e.data.items.map((n) => Math.abs(n.value))
200
+ ), c = Math.max(s, 1);
201
+ return z(
202
202
  e,
203
- /* @__PURE__ */ r(N, { children: [
204
- /* @__PURE__ */ a("ol", { className: "make-ai-artifact__ranking", children: e.data.items.map((i, s) => /* @__PURE__ */ r("li", { children: [
205
- /* @__PURE__ */ a("span", { className: "make-ai-artifact__rank", children: s + 1 }),
203
+ /* @__PURE__ */ r(C, { children: [
204
+ /* @__PURE__ */ t("ol", { className: "make-ai-artifact__ranking", children: e.data.items.map((n, l) => /* @__PURE__ */ r("li", { children: [
205
+ /* @__PURE__ */ t("span", { className: "make-ai-artifact__rank", children: l + 1 }),
206
206
  /* @__PURE__ */ r("span", { className: "make-ai-artifact__ranking-label", children: [
207
- /* @__PURE__ */ a("span", { children: i.label }),
208
- i.description ? /* @__PURE__ */ a("small", { children: i.description }) : null
207
+ /* @__PURE__ */ t("span", { children: n.label }),
208
+ n.description ? /* @__PURE__ */ t("small", { children: n.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(i.value) / c * 100}%` } }) }),
211
- /* @__PURE__ */ a("strong", { children: w(i.value, i.format, t.context.locale) })
212
- ] }, i.id)) }),
213
- C(e, t)
210
+ /* @__PURE__ */ t("span", { className: "make-ai-artifact__ranking-track", "aria-hidden": "true", children: /* @__PURE__ */ t("span", { style: { width: `${Math.abs(n.value) / c * 100}%` } }) }),
211
+ /* @__PURE__ */ t("strong", { children: $(n.value, n.format, a.context.locale) })
212
+ ] }, n.id)) }),
213
+ L(e, a)
214
214
  ] }),
215
215
  "make-ai-artifact--ranking"
216
216
  );
217
- }, Ie = (e, t) => t.action ?? {
218
- id: `open-${t.id}`,
219
- label: t.title ?? t.id,
217
+ }, He = (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
- }, Ne = ({
221
+ target: { entityKey: e.data.entity.key, recordId: a.id }
222
+ }, Be = ({
223
223
  artifact: e,
224
- renderContext: t
225
- }) => F(
224
+ renderContext: a
225
+ }) => z(
226
226
  e,
227
- /* @__PURE__ */ r(N, { 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((n) => {
229
- const c = Ie(e, n), i = /* @__PURE__ */ r(N, { children: [
230
- /* @__PURE__ */ a("strong", { children: n.title ?? n.id }),
231
- /* @__PURE__ */ a("span", { className: "make-ai-artifact__record-values", children: e.data.columns.map((s) => /* @__PURE__ */ r("span", { children: [
232
- /* @__PURE__ */ a("small", { children: s.label }),
233
- w(
234
- n.values[s.key],
235
- s.format,
236
- t.context.locale
227
+ /* @__PURE__ */ r(C, { 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 = He(e, s), n = /* @__PURE__ */ r(C, { 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((l) => /* @__PURE__ */ r("span", { children: [
232
+ /* @__PURE__ */ t("small", { children: l.label }),
233
+ $(
234
+ s.values[l.key],
235
+ l.format,
236
+ a.context.locale
237
237
  )
238
- ] }, s.key)) }),
239
- t.onAction ? /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "›" }) : null
238
+ ] }, l.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: () => ie(c, {
246
+ onClick: () => _e(c, {
247
247
  artifact: e,
248
- context: t.context
249
- }, t),
250
- children: i
248
+ context: a.context
249
+ }, a),
250
+ children: n
251
251
  },
252
- n.id
253
- ) : /* @__PURE__ */ a("div", { className: "make-ai-artifact__record", children: i }, n.id);
252
+ s.id
253
+ ) : /* @__PURE__ */ t("div", { className: "make-ai-artifact__record", children: n }, s.id);
254
254
  }) }),
255
255
  e.data.total !== void 0 ? /* @__PURE__ */ r("p", { className: "make-ai-artifact__record-total", children: [
256
256
  "共 ",
257
257
  e.data.total,
258
258
  " 条"
259
259
  ] }) : null,
260
- C(e, t)
260
+ L(e, a)
261
261
  ] }),
262
262
  "make-ai-artifact--record-list"
263
- ), we = ({
263
+ ), Oe = ({
264
264
  artifact: e,
265
- renderContext: t
266
- }) => F(
265
+ renderContext: a
266
+ }) => z(
267
267
  e,
268
- /* @__PURE__ */ r(N, { children: [
268
+ /* @__PURE__ */ r(C, { children: [
269
269
  /* @__PURE__ */ r("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
- C(e, t)
273
+ L(e, a)
274
274
  ] }),
275
275
  "make-ai-artifact--notice"
276
- ), x = (e, t, n) => ({ id: e, kinds: [t], priority: 0, render: n }), Te = [
277
- x("platform.metric.default", "metric", (e, t, n) => /* @__PURE__ */ a(ye, { artifact: e, renderContext: n })),
278
- x("platform.comparison.default", "comparison", (e, t, n) => /* @__PURE__ */ a(ge, { artifact: e, renderContext: n })),
279
- x("platform.trend.default", "trend", (e, t, n) => /* @__PURE__ */ a(be, { artifact: e, renderContext: n })),
280
- x("platform.ranking.default", "ranking", (e, t, n) => /* @__PURE__ */ a(Ae, { artifact: e, renderContext: n })),
281
- x("platform.record-list.default", "record-list", (e, t, n) => /* @__PURE__ */ a(Ne, { artifact: e, renderContext: n })),
282
- x("platform.notice.default", "notice", (e, t, n) => /* @__PURE__ */ a(we, { artifact: e, renderContext: n }))
283
- ], Me = re(Te).templates, Ee = (e = Me) => re(e), $e = (e) => `${e}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
284
- class p extends Error {
276
+ ), K = (e, a, s) => ({ id: e, kinds: [a], priority: 0, render: s }), Ue = [
277
+ K("platform.metric.default", "metric", (e, a, s) => /* @__PURE__ */ t(Ve, { artifact: e, renderContext: s })),
278
+ K("platform.comparison.default", "comparison", (e, a, s) => /* @__PURE__ */ t(qe, { artifact: e, renderContext: s })),
279
+ K("platform.trend.default", "trend", (e, a, s) => /* @__PURE__ */ t(Le, { artifact: e, renderContext: s })),
280
+ K("platform.ranking.default", "ranking", (e, a, s) => /* @__PURE__ */ t(ze, { artifact: e, renderContext: s })),
281
+ K("platform.record-list.default", "record-list", (e, a, s) => /* @__PURE__ */ t(Be, { artifact: e, renderContext: s })),
282
+ K("platform.notice.default", "notice", (e, a, s) => /* @__PURE__ */ t(Oe, { artifact: e, renderContext: s }))
283
+ ], Ze = fe(Ue).templates, je = (e = Ze) => fe(e), Ye = (e) => `${e}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
284
+ class h extends Error {
285
285
  }
286
- const ne = (e) => {
286
+ const pe = (e) => {
287
287
  try {
288
- const t = e?.return?.();
289
- if (!t) return;
290
- Promise.resolve(t).catch((n) => {
288
+ const a = e?.return?.();
289
+ if (!a) return;
290
+ Promise.resolve(a).catch((s) => {
291
291
  console.error("[make-ai-assistant] transport iterator close failed", {
292
- errorType: n instanceof Error ? n.name : typeof n
292
+ errorType: s instanceof Error ? s.name : typeof s
293
293
  });
294
294
  });
295
- } catch (t) {
295
+ } catch (a) {
296
296
  console.error("[make-ai-assistant] transport iterator close failed", {
297
- errorType: t instanceof Error ? t.name : typeof t
297
+ errorType: a instanceof Error ? a.name : typeof a
298
298
  });
299
299
  }
300
- }, oe = () => /* @__PURE__ */ r("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
- ] }), Re = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m6 6 12 12M18 6 6 18" }) }), xe = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "M12 5v14M5 12h14" }) }), Se = () => /* @__PURE__ */ r("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
- ] }), z = () => /* @__PURE__ */ a("span", { className: "make-ai-assistant__avatar", "aria-hidden": "true", children: /* @__PURE__ */ a(oe, {}) }), Ce = (e, t, n, c, i) => e.messages.map((s) => /* @__PURE__ */ r(
307
- "article",
308
- {
309
- className: `make-ai-assistant__message make-ai-assistant__message--${s.role}`,
310
- children: [
311
- s.role === "assistant" ? /* @__PURE__ */ a(z, {}) : null,
312
- /* @__PURE__ */ r("div", { className: "make-ai-assistant__message-stack", children: [
313
- s.content ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble", children: s.content }) : s.status === "streaming" ? /* @__PURE__ */ r("div", { className: "make-ai-assistant__typing", "aria-label": "AI 正在思考", children: [
314
- /* @__PURE__ */ a("span", {}),
315
- /* @__PURE__ */ a("span", {}),
316
- /* @__PURE__ */ a("span", {})
317
- ] }) : null,
318
- s.artifacts.map((m) => /* @__PURE__ */ a(
319
- ve,
320
- {
321
- artifact: m,
322
- context: t,
323
- onAction: c,
324
- onActionError: i,
325
- registry: n
326
- },
327
- m.id
328
- ))
329
- ] })
330
- ]
331
- },
332
- s.id
333
- ));
334
- function Fe({
335
- context: e,
336
- onAction: t,
337
- onActionError: n,
338
- onClose: c,
339
- onNewConversation: i,
340
- registry: s,
341
- subtitle: m,
342
- suggestions: u = [],
343
- title: A = "Make AI 助手",
344
- transport: h
300
+ }, ke = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
301
+ /* @__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" }),
302
+ /* @__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" })
303
+ ] }), Ge = () => /* @__PURE__ */ t("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ t("path", { d: "m6 6 12 12M18 6 6 18" }) }), Je = () => /* @__PURE__ */ t("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ t("path", { d: "M12 5v14M5 12h14" }) }), Qe = () => /* @__PURE__ */ r("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
304
+ /* @__PURE__ */ t("path", { d: "m4 4 17 8-17 8 3-8-3-8Z" }),
305
+ /* @__PURE__ */ t("path", { d: "M7 12h14" })
306
+ ] }), q = () => /* @__PURE__ */ t("span", { className: "make-ai-assistant__avatar", "aria-hidden": "true", children: /* @__PURE__ */ t(ke, {}) }), ve = (e) => {
307
+ for (let a = e.messages.length - 1; a >= 0; a -= 1) {
308
+ const s = e.messages[a];
309
+ if (s.role === "assistant" && s.status === "streaming")
310
+ return s.id;
311
+ }
312
+ }, We = (e) => {
313
+ for (let a = e.messages.length - 1; a >= 0; a -= 1)
314
+ if (e.messages[a].role === "user") return a;
315
+ return -1;
316
+ }, ye = (e) => {
317
+ const a = We(e);
318
+ if (!(a < 0))
319
+ for (let s = e.messages.length - 1; s > a; s -= 1) {
320
+ const c = e.messages[s];
321
+ if (c.role === "assistant") return c.id;
322
+ }
323
+ }, Ie = ({
324
+ error: e,
325
+ onRetry: a
326
+ }) => /* @__PURE__ */ r("div", { className: "make-ai-assistant__message-status make-ai-assistant__message-status--error", role: "alert", children: [
327
+ /* @__PURE__ */ t("strong", { children: "本次请求未完成" }),
328
+ /* @__PURE__ */ t("span", { children: e.message }),
329
+ e.retryable && a ? /* @__PURE__ */ t(
330
+ "button",
331
+ {
332
+ className: "make-ai-assistant__retry",
333
+ type: "button",
334
+ onClick: a,
335
+ children: "重新发送"
336
+ }
337
+ ) : null
338
+ ] }), he = ({
339
+ assistantName: e,
340
+ error: a,
341
+ onRetry: s,
342
+ progress: c
343
+ }) => {
344
+ const n = a ? "error" : "progress", l = a?.message ?? c;
345
+ return l ? /* @__PURE__ */ r(
346
+ "article",
347
+ {
348
+ "aria-label": `${e}的${n === "error" ? "错误消息" : "状态消息"}`,
349
+ className: `make-ai-assistant__message make-ai-assistant__message--assistant make-ai-assistant__message--${n}`,
350
+ "data-message-role": "assistant",
351
+ "data-message-state": n,
352
+ children: [
353
+ /* @__PURE__ */ t(q, {}),
354
+ /* @__PURE__ */ r("div", { className: "make-ai-assistant__message-stack", children: [
355
+ /* @__PURE__ */ t("span", { className: "make-ai-assistant__message-sender", children: e }),
356
+ a ? /* @__PURE__ */ t(Ie, { error: a, onRetry: s }) : /* @__PURE__ */ r("div", { className: "make-ai-assistant__progress", role: "status", children: [
357
+ /* @__PURE__ */ t("span", { "aria-hidden": "true" }),
358
+ /* @__PURE__ */ t("span", { children: l })
359
+ ] })
360
+ ] })
361
+ ]
362
+ }
363
+ ) : null;
364
+ }, Xe = (e, a, s, c, n, l, u, p) => {
365
+ const A = ye(e), f = ve(e);
366
+ return e.messages.map((d) => {
367
+ const T = d.role === "assistant", _ = d.id === f, b = d.id === A && e.error, m = T ? l : p;
368
+ return /* @__PURE__ */ r(
369
+ "article",
370
+ {
371
+ "aria-label": `${m}的消息`,
372
+ className: `make-ai-assistant__message make-ai-assistant__message--${d.role}`,
373
+ "data-message-role": d.role,
374
+ "data-message-state": b ? "error" : void 0,
375
+ "data-message-status": d.status,
376
+ children: [
377
+ T ? /* @__PURE__ */ t(q, {}) : null,
378
+ /* @__PURE__ */ r("div", { className: "make-ai-assistant__message-stack", children: [
379
+ /* @__PURE__ */ t("span", { className: "make-ai-assistant__message-sender", children: m }),
380
+ d.content ? /* @__PURE__ */ t("div", { className: "make-ai-assistant__bubble", children: d.content }) : d.status === "streaming" ? /* @__PURE__ */ r("div", { className: "make-ai-assistant__typing", "aria-label": `${l}正在思考`, children: [
381
+ /* @__PURE__ */ t("span", {}),
382
+ /* @__PURE__ */ t("span", {}),
383
+ /* @__PURE__ */ t("span", {})
384
+ ] }) : null,
385
+ _ && e.progress ? /* @__PURE__ */ r("div", { className: "make-ai-assistant__progress", role: "status", children: [
386
+ /* @__PURE__ */ t("span", { "aria-hidden": "true" }),
387
+ /* @__PURE__ */ t("span", { children: e.progress.message })
388
+ ] }) : null,
389
+ b ? /* @__PURE__ */ t(Ie, { error: b, onRetry: u }) : null,
390
+ d.artifacts.map((y) => /* @__PURE__ */ t(
391
+ Ke,
392
+ {
393
+ artifact: y,
394
+ context: a,
395
+ onAction: c,
396
+ onActionError: n,
397
+ registry: s
398
+ },
399
+ y.id
400
+ ))
401
+ ] })
402
+ ]
403
+ },
404
+ d.id
405
+ );
406
+ });
407
+ };
408
+ function ea({
409
+ assistantName: e = "AI 助手",
410
+ context: a,
411
+ onAction: s,
412
+ onActionError: c,
413
+ onClose: n,
414
+ onNewConversation: l,
415
+ registry: u,
416
+ subtitle: p,
417
+ suggestions: A = [],
418
+ title: f = "Make AI 助手",
419
+ transport: d,
420
+ userName: T = "你"
345
421
  }) {
346
- const [v, T] = L(""), [d, y] = L(ae), [D, P] = L(void 0), M = S(void 0), E = S(void 0), $ = S(0), O = S(null), Z = S(!0), G = fe(
347
- () => s ?? Ee(),
348
- [s]
349
- ), j = (o) => {
350
- $.current += 1;
351
- const _ = M.current, g = E.current?.iterator;
352
- return M.current = void 0, E.current = void 0, !_ && !g ? !1 : (console.info("[make-ai-assistant] local run cancellation requested", { reason: o }), _?.abort(), ne(g), !0);
422
+ const [_, b] = V(""), [m, y] = V(X), [Z, H] = V(void 0), [Ae, be] = V(0), [R, j] = V(() => d.loadConversation ? "loading" : "ready"), S = E(void 0), x = E(void 0), F = E(0), te = E(null), Y = E(!0), re = E(a.app.id), ne = Fe(
423
+ () => u ?? je(),
424
+ [u]
425
+ ), G = (i) => {
426
+ const v = S.current, k = x.current?.iterator;
427
+ return !v && !k ? !1 : (F.current += 1, S.current = void 0, x.current = void 0, console.info("[make-ai-assistant] local run cancellation requested", { reason: i }), v?.abort(), pe(k), !0);
353
428
  };
354
- Y(() => () => {
355
- j("unmount");
356
- }, []), Y(() => {
357
- const o = O.current;
358
- if (!o || !Z.current) return;
359
- const _ = requestAnimationFrame(() => {
360
- if (!Z.current) return;
361
- const g = d.status === "streaming" || window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
362
- typeof o.scrollTo == "function" ? o.scrollTo({ top: o.scrollHeight, behavior: g }) : o.scrollTop = o.scrollHeight;
429
+ ae(() => () => {
430
+ G("unmount");
431
+ }, []), ae(() => {
432
+ const i = d.loadConversation, v = re.current !== a.app.id;
433
+ if (re.current = a.app.id, G("reinitialize"), v && (b(""), Y.current = !0), H(void 0), y(X()), !i) {
434
+ j("ready");
435
+ return;
436
+ }
437
+ const k = new AbortController();
438
+ return j("loading"), console.info("[make-ai-assistant] conversation load start", {
439
+ appId: a.app.id
440
+ }), i.call(d, a, { signal: k.signal }).then((I) => {
441
+ k.signal.aborted || (y(X(I)), j("ready"), console.info("[make-ai-assistant] conversation load success", {
442
+ appId: a.app.id,
443
+ messageCount: I.messages.length
444
+ }));
445
+ }).catch((I) => {
446
+ k.signal.aborted || (console.error("[make-ai-assistant] conversation load failed", {
447
+ appId: a.app.id,
448
+ errorType: I instanceof Error ? I.name : typeof I
449
+ }), j("error"));
450
+ }), () => k.abort();
451
+ }, [a.app.id, Ae, d]), ae(() => {
452
+ const i = te.current;
453
+ if (!i || !Y.current) return;
454
+ const v = requestAnimationFrame(() => {
455
+ if (!Y.current) return;
456
+ const k = m.status === "streaming" || window.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
457
+ typeof i.scrollTo == "function" ? i.scrollTo({ top: i.scrollHeight, behavior: k }) : i.scrollTop = i.scrollHeight;
363
458
  });
364
- return () => cancelAnimationFrame(_);
365
- }, [d.messages, d.status]);
366
- const ce = () => {
367
- const o = O.current;
368
- o && (Z.current = o.scrollHeight - o.scrollTop - o.clientHeight <= 48);
369
- }, U = async (o) => {
370
- const _ = o.trim();
371
- if (!_ || d.status === "streaming" || M.current) return;
372
- if (te(
373
- _,
374
- b.messageCharacters
375
- ) > b.messageCharacters) {
376
- P(
377
- `输入内容过长,请控制在 ${b.messageCharacters} 个字符以内`
459
+ return () => cancelAnimationFrame(v);
460
+ }, [m.messages, m.status]);
461
+ const Ne = () => {
462
+ const i = te.current;
463
+ i && (Y.current = i.scrollHeight - i.scrollTop - i.clientHeight <= 48);
464
+ }, J = async (i) => {
465
+ const v = i.trim();
466
+ if (!v || R !== "ready" || m.status === "streaming" || S.current) return;
467
+ if (se(
468
+ v,
469
+ w.messageCharacters
470
+ ) > w.messageCharacters) {
471
+ H(
472
+ `输入内容过长,请控制在 ${w.messageCharacters} 个字符以内`
378
473
  );
379
474
  return;
380
475
  }
381
- const g = { id: $e("user"), content: _ }, K = new AbortController(), R = $.current + 1;
382
- $.current = R, M.current = K, P(void 0), T(""), y((k) => _e(k, g));
476
+ const k = { id: Ye("user"), content: v }, I = new AbortController(), D = F.current + 1;
477
+ F.current = D, S.current = I, H(void 0), b(""), y((N) => De(N, k));
383
478
  try {
384
- let k = !1, f, J = 0, Q = 0, V = 0;
385
- const W = /* @__PURE__ */ new Set(), X = /* @__PURE__ */ new Set(
386
- [...d.messages.map((H) => H.id), g.id]
387
- ), q = /* @__PURE__ */ new Set(), ee = h.run(
479
+ let N = !1, g, oe = 0, le = 0, B = 0;
480
+ const O = /* @__PURE__ */ new Map(), ce = /* @__PURE__ */ new Set(), de = /* @__PURE__ */ new Set(
481
+ [...m.messages.map((W) => W.id), k.id]
482
+ ), U = /* @__PURE__ */ new Set(), me = d.run(
388
483
  {
389
- threadId: d.threadId,
390
- message: g,
391
- context: e,
392
- capabilities: he(G)
484
+ threadId: m.threadId,
485
+ message: k,
486
+ context: a,
487
+ capabilities: xe(ne)
393
488
  },
394
- { signal: K.signal }
489
+ { signal: I.signal }
395
490
  )[Symbol.asyncIterator]();
396
- for (E.current = { iterator: ee, requestVersion: R }; ; ) {
397
- const H = await ee.next();
398
- if ($.current !== R || H.done) break;
399
- let l;
491
+ for (x.current = { iterator: me, requestVersion: D }; ; ) {
492
+ const W = await me.next();
493
+ if (F.current !== D || W.done) break;
494
+ let o;
400
495
  try {
401
- l = ke(H.value);
402
- } catch (I) {
403
- throw new p(
404
- I instanceof Error ? I.message : "Invalid assistant event"
496
+ o = Pe(W.value);
497
+ } catch (M) {
498
+ throw new h(
499
+ M instanceof Error ? M.message : "Invalid assistant event"
405
500
  );
406
501
  }
407
- if (l.type === "message.start") {
408
- if (f !== void 0 && f !== l.runId)
409
- throw new p("AI 助手响应 run id 不一致");
410
- if (f ??= l.runId, Q += 1, Q > b.assistantMessagesPerRun)
411
- throw new p("AI 助手单次响应消息数量超过限制");
412
- if (X.has(l.messageId))
413
- throw new p("AI 助手响应包含重复的 message id");
414
- X.add(l.messageId), q.add(l.messageId);
502
+ if (o.type === "message.start") {
503
+ if (g !== void 0 && g !== o.runId)
504
+ throw new h("AI 助手响应 run id 不一致");
505
+ if (g ??= o.runId, le += 1, le > w.assistantMessagesPerRun)
506
+ throw new h("AI 助手单次响应消息数量超过限制");
507
+ if (de.has(o.messageId))
508
+ throw new h("AI 助手响应包含重复的 message id");
509
+ de.add(o.messageId), U.add(o.messageId), O.set(o.messageId, 0);
415
510
  }
416
- if (l.type === "message.delta") {
417
- if (!q.has(l.messageId))
418
- throw new p("AI 助手响应事件顺序无效");
419
- const I = te(
420
- l.delta,
421
- b.messageCharacters - V
511
+ if (o.type === "message.delta") {
512
+ if (!U.has(o.messageId))
513
+ throw new h("AI 助手响应事件顺序无效");
514
+ const M = O.get(o.messageId) ?? 0, P = se(
515
+ o.delta,
516
+ w.messageCharacters - B
422
517
  );
423
- if (V + I > b.messageCharacters)
424
- throw new p("AI 助手响应文本超过大小限制");
425
- if (V += I, V > b.messageCharacters)
426
- throw new p("AI 助手响应文本超过大小限制");
518
+ if (B + P > w.messageCharacters)
519
+ throw new h("AI 助手响应文本超过大小限制");
520
+ B += P, O.set(
521
+ o.messageId,
522
+ M + P
523
+ );
524
+ }
525
+ if (o.type === "message.replace") {
526
+ if (!U.has(o.messageId))
527
+ throw new h("AI 助手响应事件顺序无效");
528
+ const M = O.get(o.messageId) ?? 0, P = se(
529
+ o.content,
530
+ w.messageCharacters
531
+ ), ue = B - M + P;
532
+ if (ue > w.messageCharacters)
533
+ throw new h("AI 助手响应文本超过大小限制");
534
+ B = ue, O.set(o.messageId, P);
427
535
  }
428
- if (l.type === "artifact") {
429
- if (!q.has(l.messageId))
430
- throw new p("AI 助手响应事件顺序无效");
431
- if (J += 1, J > b.artifactsPerRun)
432
- throw new p("AI 助手单次响应 Artifact 数量超过限制");
433
- if (W.has(l.artifact.id))
434
- throw new p("AI 助手响应包含重复的 Artifact id");
435
- W.add(l.artifact.id);
536
+ if (o.type === "run.progress") {
537
+ if (g !== void 0 && g !== o.runId)
538
+ throw new h("AI 助手响应 run id 不一致");
539
+ g ??= o.runId;
436
540
  }
437
- if (l.type === "message.complete" && !q.delete(l.messageId))
438
- throw new p("AI 助手响应事件顺序无效");
439
- if (l.type === "run.complete" && f !== void 0 && f !== l.runId)
440
- throw new p("AI 助手响应 run id 不一致");
441
- if (l.type === "run.cancelled" && l.runId !== void 0 && f !== void 0 && f !== l.runId)
442
- throw new p("AI 助手响应 run id 不一致");
443
- if (y((I) => B(I, l)), l.type === "error" || l.type === "run.cancelled" || l.type === "run.complete") {
444
- k = !0;
541
+ if (o.type === "artifact") {
542
+ if (!U.has(o.messageId))
543
+ throw new h("AI 助手响应事件顺序无效");
544
+ if (oe += 1, oe > w.artifactsPerRun)
545
+ throw new h("AI 助手单次响应 Artifact 数量超过限制");
546
+ if (ce.has(o.artifact.id))
547
+ throw new h("AI 助手响应包含重复的 Artifact id");
548
+ ce.add(o.artifact.id);
549
+ }
550
+ if (o.type === "message.complete" && !U.delete(o.messageId))
551
+ throw new h("AI 助手响应事件顺序无效");
552
+ if (o.type === "run.complete" && g !== void 0 && g !== o.runId)
553
+ throw new h("AI 助手响应 run id 不一致");
554
+ if (o.type === "run.cancelled" && o.runId !== void 0 && g !== void 0 && g !== o.runId)
555
+ throw new h("AI 助手响应 run id 不一致");
556
+ if (y((M) => ee(M, o)), o.type === "error" || o.type === "run.cancelled" || o.type === "run.complete") {
557
+ N = !0;
445
558
  break;
446
559
  }
447
560
  }
448
- if (!k)
449
- throw new p("AI 助手流式响应在终止事件前结束");
450
- } catch (k) {
451
- if ($.current !== R) return;
452
- if (K.signal.aborted) {
561
+ if (!N)
562
+ throw new h("AI 助手流式响应在终止事件前结束");
563
+ } catch (N) {
564
+ if (F.current !== D) return;
565
+ if (I.signal.aborted) {
453
566
  y(
454
- (f) => B(f, { type: "run.cancelled" })
567
+ (g) => ee(g, { type: "run.cancelled" })
455
568
  );
456
569
  return;
457
570
  }
458
571
  console.error("[make-ai-assistant] assistant run failed", {
459
- appId: e.app.id,
460
- errorType: k instanceof Error ? k.name : typeof k
572
+ appId: a.app.id,
573
+ errorType: N instanceof Error ? N.name : typeof N
461
574
  }), y(
462
- (f) => B(f, {
575
+ (g) => ee(g, {
463
576
  type: "error",
464
577
  code: "TRANSPORT_ERROR",
465
- message: k instanceof p ? k.message : "连接失败,请重试",
578
+ message: N instanceof h ? N.message : "连接失败,请重试",
466
579
  retryable: !0
467
580
  })
468
581
  );
469
582
  } finally {
470
- $.current === R && M.current === K && (M.current = void 0), E.current?.requestVersion === R && (ne(E.current.iterator), E.current = void 0);
583
+ F.current === D && S.current === I && (S.current = void 0), x.current?.requestVersion === D && (pe(x.current.iterator), x.current = void 0);
471
584
  }
472
- }, le = (o) => {
473
- o.preventDefault(), U(v);
474
- }, de = (o) => {
475
- o.key === "Enter" && !o.shiftKey && !o.nativeEvent.isComposing && (o.preventDefault(), U(v));
476
- }, me = () => {
477
- j("stop") && y(
478
- (o) => B(o, { type: "run.cancelled" })
585
+ }, we = (i) => {
586
+ i.preventDefault(), J(_);
587
+ }, Me = (i) => {
588
+ i.key === "Enter" && !i.shiftKey && !i.nativeEvent.isComposing && (i.preventDefault(), J(_));
589
+ }, Te = () => {
590
+ G("stop") && y(
591
+ (i) => ee(i, { type: "run.cancelled" })
479
592
  );
480
- }, ue = () => {
481
- j("new-conversation"), T(""), P(void 0), y(ae()), i?.();
593
+ }, Ee = () => {
594
+ G("new-conversation"), b(""), H(void 0), y(X()), l?.();
595
+ }, Ce = d.features?.remoteCancellation === !1 ? "停止接收" : "停止生成", $e = ve(m), Re = ye(m), Q = [...m.messages].reverse().find((i) => i.role === "user"), ie = () => {
596
+ Q && J(Q.content);
482
597
  };
483
598
  return /* @__PURE__ */ r("section", { className: "make-ai-assistant make-ai-assistant__panel", children: [
484
599
  /* @__PURE__ */ r("header", { className: "make-ai-assistant__header", children: [
485
- /* @__PURE__ */ a(z, {}),
600
+ /* @__PURE__ */ t(q, {}),
486
601
  /* @__PURE__ */ r("div", { children: [
487
- /* @__PURE__ */ a("h2", { children: A }),
488
- /* @__PURE__ */ r("p", { children: [
489
- /* @__PURE__ */ a("span", { className: "make-ai-assistant__online-dot" }),
490
- m ?? e.app.name ?? "当前应用"
491
- ] })
602
+ /* @__PURE__ */ t("h2", { children: f }),
603
+ /* @__PURE__ */ t("p", { children: p ?? `当前应用:${a.app.name ?? "未命名应用"}` })
492
604
  ] }),
493
605
  /* @__PURE__ */ r("div", { className: "make-ai-assistant__header-actions", children: [
494
- /* @__PURE__ */ a(
606
+ d.features?.newConversation !== !1 ? /* @__PURE__ */ t(
495
607
  "button",
496
608
  {
497
609
  "aria-label": "新建对话",
498
610
  className: "make-ai-assistant__icon-button",
499
611
  type: "button",
500
- onClick: ue,
501
- children: /* @__PURE__ */ a(xe, {})
612
+ onClick: Ee,
613
+ children: /* @__PURE__ */ t(Je, {})
502
614
  }
503
- ),
504
- c ? /* @__PURE__ */ a(
615
+ ) : null,
616
+ n ? /* @__PURE__ */ t(
505
617
  "button",
506
618
  {
507
619
  "aria-label": "关闭 Make AI 助手",
508
620
  className: "make-ai-assistant__icon-button",
509
621
  type: "button",
510
- onClick: c,
511
- children: /* @__PURE__ */ a(Re, {})
622
+ onClick: n,
623
+ children: /* @__PURE__ */ t(Ge, {})
512
624
  }
513
625
  ) : null
514
626
  ] })
515
627
  ] }),
516
628
  /* @__PURE__ */ r("div", { className: "make-ai-assistant__privacy-note", role: "note", children: [
517
- /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "◇" }),
629
+ /* @__PURE__ */ t("span", { "aria-hidden": "true", children: "◇" }),
518
630
  "当前页面上下文会随请求发送,数据权限以宿主服务端校验结果为准"
519
631
  ] }),
520
632
  /* @__PURE__ */ r(
@@ -522,140 +634,179 @@ function Fe({
522
634
  {
523
635
  className: "make-ai-assistant__body",
524
636
  "aria-live": "polite",
525
- ref: O,
526
- onScroll: ce,
637
+ "aria-relevant": "additions text",
638
+ ref: te,
639
+ role: "log",
640
+ onScroll: Ne,
527
641
  children: [
528
- d.messages.length === 0 ? /* @__PURE__ */ r("div", { className: "make-ai-assistant__empty", children: [
529
- /* @__PURE__ */ a(z, {}),
530
- /* @__PURE__ */ a("h3", { children: "有什么可以帮你?" }),
531
- /* @__PURE__ */ a("p", { children: "我会结合当前 App 和页面上下文理解问题,并用适合的方式展示结果。" })
532
- ] }) : Ce(d, e, G, t, n),
533
- d.error ? /* @__PURE__ */ r("div", { className: "make-ai-assistant__error", role: "alert", children: [
534
- /* @__PURE__ */ a("strong", { children: "暂时无法完成" }),
535
- /* @__PURE__ */ a("span", { children: d.error.message })
536
- ] }) : null
642
+ R === "loading" ? /* @__PURE__ */ r("div", { className: "make-ai-assistant__empty", role: "status", children: [
643
+ /* @__PURE__ */ t(q, {}),
644
+ /* @__PURE__ */ t("h3", { children: "正在恢复对话" }),
645
+ /* @__PURE__ */ t("p", { children: "正在读取当前 App 的历史消息…" })
646
+ ] }) : R === "error" ? /* @__PURE__ */ r("div", { className: "make-ai-assistant__empty", role: "alert", children: [
647
+ /* @__PURE__ */ t(q, {}),
648
+ /* @__PURE__ */ t("h3", { children: "暂时无法加载对话" }),
649
+ /* @__PURE__ */ t("p", { children: "请检查网络后重试。" }),
650
+ /* @__PURE__ */ t(
651
+ "button",
652
+ {
653
+ className: "make-ai-assistant__retry",
654
+ type: "button",
655
+ onClick: () => be((i) => i + 1),
656
+ children: "重新加载"
657
+ }
658
+ )
659
+ ] }) : m.messages.length === 0 ? /* @__PURE__ */ r("div", { className: "make-ai-assistant__empty", children: [
660
+ /* @__PURE__ */ t(q, {}),
661
+ /* @__PURE__ */ t("h3", { children: "有什么可以帮你?" }),
662
+ /* @__PURE__ */ t("p", { children: "我会结合当前 App 和页面上下文理解问题,并用适合的方式展示结果。" })
663
+ ] }) : Xe(
664
+ m,
665
+ a,
666
+ ne,
667
+ s,
668
+ c,
669
+ e,
670
+ Q ? ie : void 0,
671
+ T
672
+ ),
673
+ m.progress && !$e ? /* @__PURE__ */ t(
674
+ he,
675
+ {
676
+ assistantName: e,
677
+ progress: m.progress.message
678
+ }
679
+ ) : null,
680
+ m.error && !Re ? /* @__PURE__ */ t(
681
+ he,
682
+ {
683
+ assistantName: e,
684
+ error: m.error,
685
+ onRetry: Q ? ie : void 0
686
+ }
687
+ ) : null
537
688
  ]
538
689
  }
539
690
  ),
540
691
  /* @__PURE__ */ r("footer", { className: "make-ai-assistant__composer-region", children: [
541
- u.length > 0 && d.messages.length === 0 ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__suggestions", "aria-label": "推荐问题", children: u.map((o, _) => /* @__PURE__ */ a(
692
+ R === "ready" && A.length > 0 && m.messages.length === 0 ? /* @__PURE__ */ t("div", { className: "make-ai-assistant__suggestions", "aria-label": "推荐问题", children: A.map((i, v) => /* @__PURE__ */ t(
542
693
  "button",
543
694
  {
544
695
  type: "button",
545
696
  onClick: () => {
546
- U(o);
697
+ J(i);
547
698
  },
548
- children: o
699
+ children: i
549
700
  },
550
- `${_}-${o}`
701
+ `${v}-${i}`
551
702
  )) }) : null,
552
- /* @__PURE__ */ r("form", { className: "make-ai-assistant__composer", onSubmit: le, children: [
553
- /* @__PURE__ */ a(
703
+ /* @__PURE__ */ r("form", { className: "make-ai-assistant__composer", onSubmit: we, children: [
704
+ /* @__PURE__ */ t(
554
705
  "textarea",
555
706
  {
556
- "aria-label": "向 Make AI 助手提问",
557
- "aria-describedby": D ? "make-ai-composer-error" : void 0,
558
- "aria-invalid": D ? !0 : void 0,
707
+ "aria-label": `向 ${e} 提问`,
708
+ "aria-describedby": Z ? "make-ai-composer-error" : void 0,
709
+ "aria-invalid": Z ? !0 : void 0,
559
710
  autoFocus: !0,
560
- disabled: d.status === "streaming",
561
- placeholder: `询问当前 ${e.app.name ?? "App"} 中的数据…`,
711
+ disabled: R !== "ready" || m.status === "streaming",
712
+ placeholder: `询问当前 ${a.app.name ?? "App"} 中的数据…`,
562
713
  rows: 2,
563
- value: v,
564
- onChange: (o) => {
565
- T(o.currentTarget.value), P(void 0);
714
+ value: _,
715
+ onChange: (i) => {
716
+ b(i.currentTarget.value), H(void 0);
566
717
  },
567
- onKeyDown: de
718
+ onKeyDown: Me
568
719
  }
569
720
  ),
570
- d.status === "streaming" ? /* @__PURE__ */ a(
721
+ m.status === "streaming" ? /* @__PURE__ */ t(
571
722
  "button",
572
723
  {
573
- "aria-label": "停止生成",
724
+ "aria-label": Ce,
574
725
  className: "make-ai-assistant__send make-ai-assistant__send--stop",
575
726
  type: "button",
576
- onClick: me,
577
- children: /* @__PURE__ */ a("span", { "aria-hidden": "true" })
727
+ onClick: Te,
728
+ children: /* @__PURE__ */ t("span", { "aria-hidden": "true" })
578
729
  }
579
- ) : /* @__PURE__ */ a(
730
+ ) : /* @__PURE__ */ t(
580
731
  "button",
581
732
  {
582
733
  "aria-label": "发送",
583
734
  className: "make-ai-assistant__send",
584
- disabled: !v.trim(),
735
+ disabled: R !== "ready" || !_.trim(),
585
736
  type: "submit",
586
- children: /* @__PURE__ */ a(Se, {})
737
+ children: /* @__PURE__ */ t(Qe, {})
587
738
  }
588
739
  )
589
740
  ] }),
590
- D ? /* @__PURE__ */ a("p", { id: "make-ai-composer-error", role: "alert", children: D }) : null,
591
- /* @__PURE__ */ a("p", { children: "AI 生成的结果可能存在偏差,重要数据请核对明细。" })
741
+ Z ? /* @__PURE__ */ t("p", { id: "make-ai-composer-error", role: "alert", children: Z }) : null,
742
+ /* @__PURE__ */ t("p", { children: "AI 生成的结果可能存在偏差,重要数据请核对明细。" })
592
743
  ] })
593
744
  ] });
594
745
  }
595
- function He({
746
+ function ia({
596
747
  defaultOpen: e = !1,
597
- hideLauncher: t = !1,
598
- launcher: n,
748
+ hideLauncher: a = !1,
749
+ launcher: s,
599
750
  onOpenChange: c,
600
- open: i,
601
- ...s
751
+ open: n,
752
+ ...l
602
753
  }) {
603
- const [m, u] = L(e), A = S(null), h = i ?? m, v = (d) => {
604
- i === void 0 && u(d), c?.(d), d || requestAnimationFrame(() => A.current?.focus());
605
- }, T = () => v(!h);
606
- return Y(() => {
607
- if (!h) return;
608
- const d = (y) => {
609
- y.key === "Escape" && (v(!1), requestAnimationFrame(() => A.current?.focus()));
754
+ const [u, p] = V(e), A = E(null), f = n ?? u, d = (_) => {
755
+ n === void 0 && p(_), c?.(_), _ || requestAnimationFrame(() => A.current?.focus());
756
+ }, T = () => d(!f);
757
+ return ae(() => {
758
+ if (!f) return;
759
+ const _ = (b) => {
760
+ b.key === "Escape" && (d(!1), requestAnimationFrame(() => A.current?.focus()));
610
761
  };
611
- return document.addEventListener("keydown", d), () => document.removeEventListener("keydown", d);
612
- }, [c, h]), /* @__PURE__ */ r("div", { className: "make-ai-assistant", "data-open": h || void 0, children: [
613
- !t && (!h || n) ? n ? n({ open: h, toggle: T }) : /* @__PURE__ */ r(
762
+ return document.addEventListener("keydown", _), () => document.removeEventListener("keydown", _);
763
+ }, [c, f]), /* @__PURE__ */ r("div", { className: "make-ai-assistant", "data-open": f || void 0, children: [
764
+ !a && (!f || s) ? s ? s({ open: f, toggle: T }) : /* @__PURE__ */ r(
614
765
  "button",
615
766
  {
616
- "aria-label": h ? "关闭 Make AI 助手" : "打开 Make AI 助手",
617
- "aria-expanded": h,
767
+ "aria-label": f ? "关闭 Make AI 助手" : "打开 Make AI 助手",
768
+ "aria-expanded": f,
618
769
  className: "make-ai-assistant__launcher",
619
770
  ref: A,
620
771
  type: "button",
621
772
  onClick: T,
622
773
  children: [
623
- /* @__PURE__ */ a("span", { className: "make-ai-assistant__launcher-orbit", "aria-hidden": "true" }),
624
- /* @__PURE__ */ a(oe, {})
774
+ /* @__PURE__ */ t("span", { className: "make-ai-assistant__launcher-orbit", "aria-hidden": "true" }),
775
+ /* @__PURE__ */ t(ke, {})
625
776
  ]
626
777
  }
627
778
  ) : null,
628
- h ? /* @__PURE__ */ a(
779
+ f ? /* @__PURE__ */ t(
629
780
  "aside",
630
781
  {
631
782
  "aria-label": "Make AI 助手",
632
783
  "aria-modal": "false",
633
784
  className: "make-ai-assistant__drawer",
634
785
  role: "dialog",
635
- children: /* @__PURE__ */ a(Fe, { ...s, onClose: () => v(!1) })
786
+ children: /* @__PURE__ */ t(ea, { ...l, onClose: () => d(!1) })
636
787
  }
637
788
  ) : null
638
789
  ] });
639
790
  }
640
791
  export {
641
- ve as ArtifactRenderer,
642
- Fe as AssistantPanel,
643
- je as MAKE_AI_ARTIFACT_KINDS,
644
- Ue as MAKE_AI_ARTIFACT_LIMITS,
645
- Ye as MAKE_AI_ARTIFACT_SCHEMA_VERSION,
646
- b as MAKE_AI_CONVERSATION_LIMITS,
647
- He as MakeAiAssistant,
648
- _e as appendUserMessage,
649
- he as createArtifactCapabilities,
650
- re as createArtifactTemplateRegistry,
651
- ae as createAssistantConversationState,
652
- Ee as createPlatformArtifactRegistry,
653
- Oe as extendArtifactTemplateRegistry,
654
- w as formatArtifactValue,
655
- ze as parseArtifact,
656
- ke as parseAssistantEvent,
657
- Me as platformArtifactTemplates,
658
- B as reduceAssistantEvent,
659
- pe as resolveArtifactTemplate,
660
- Ge as validateArtifact
792
+ Ke as ArtifactRenderer,
793
+ ea as AssistantPanel,
794
+ ma as MAKE_AI_ARTIFACT_KINDS,
795
+ ua as MAKE_AI_ARTIFACT_LIMITS,
796
+ pa as MAKE_AI_ARTIFACT_SCHEMA_VERSION,
797
+ w as MAKE_AI_CONVERSATION_LIMITS,
798
+ ia as MakeAiAssistant,
799
+ De as appendUserMessage,
800
+ xe as createArtifactCapabilities,
801
+ fe as createArtifactTemplateRegistry,
802
+ X as createAssistantConversationState,
803
+ je as createPlatformArtifactRegistry,
804
+ ca as extendArtifactTemplateRegistry,
805
+ $ as formatArtifactValue,
806
+ ha as parseArtifact,
807
+ Pe as parseAssistantEvent,
808
+ Ze as platformArtifactTemplates,
809
+ ee as reduceAssistantEvent,
810
+ Se as resolveArtifactTemplate,
811
+ fa as validateArtifact
661
812
  };