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

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,98 +1,98 @@
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({
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({
8
8
  artifact: e,
9
- context: a,
9
+ context: t,
10
10
  fallback: s,
11
11
  onAction: c,
12
- onActionError: n,
13
- registry: l
12
+ onActionError: o,
13
+ registry: r
14
14
  }) {
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
- /* @__PURE__ */ r("span", { children: [
15
+ const m = Le(r, e, t);
16
+ if (!m)
17
+ return s ? s(e) : /* @__PURE__ */ n("section", { className: "make-ai-artifact make-ai-artifact--unsupported", role: "status", children: [
18
+ /* @__PURE__ */ a("strong", { children: "暂不支持展示此结果" }),
19
+ /* @__PURE__ */ n("span", { children: [
20
20
  "结果类型:",
21
21
  e.kind
22
22
  ] })
23
23
  ] });
24
- const p = {
25
- context: a,
24
+ const u = {
25
+ context: t,
26
26
  onAction: c,
27
- onActionError: n
27
+ onActionError: o
28
28
  };
29
- return u.template.render(e, a, p);
29
+ return m.template.render(e, t, u);
30
30
  }
31
- const $ = (e, a, s) => {
31
+ const x = (e, t, s) => {
32
32
  if (e == null || e === "") return "—";
33
33
  if (typeof e == "boolean") return e ? "是" : "否";
34
- if (typeof e != "number") return `${e}${a?.unit ?? ""}`;
35
- const c = a?.precision, n = {
34
+ if (typeof e != "number") return `${e}${t?.unit ?? ""}`;
35
+ const c = t?.precision, o = {
36
36
  maximumFractionDigits: c ?? 2,
37
37
  minimumFractionDigits: c
38
38
  };
39
- a?.style === "currency" && a.currency ? (n.style = "currency", n.currency = a.currency) : a?.style === "percent" && (n.style = "percent");
39
+ t?.style === "currency" && t.currency ? (o.style = "currency", o.currency = t.currency) : t?.style === "percent" && (o.style = "percent");
40
40
  try {
41
- const l = a?.style === "percent" ? e / 100 : e;
42
- return `${new Intl.NumberFormat(s, n).format(l)}${a?.unit ?? ""}`;
41
+ const r = t?.style === "percent" ? e / 100 : e;
42
+ return `${new Intl.NumberFormat(s, o).format(r)}${t?.unit ?? ""}`;
43
43
  } catch {
44
- return `${e}${a?.unit ?? ""}`;
44
+ return `${e}${t?.unit ?? ""}`;
45
45
  }
46
- }, ge = (e) => {
47
- let a = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
46
+ }, ve = (e) => {
47
+ let t = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
48
48
  for (const c of e)
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) => {
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) => {
52
52
  if (!s.onAction) return;
53
- const c = (l) => {
53
+ const c = (r) => {
54
54
  console.error("[make-ai-assistant] host action error handler failed", {
55
55
  actionId: e.id,
56
- artifactId: a.artifact.id,
57
- errorType: l instanceof Error ? l.name : typeof l,
56
+ artifactId: t.artifact.id,
57
+ errorType: r instanceof Error ? r.name : typeof r,
58
58
  intent: e.intent
59
59
  });
60
- }, n = (l) => {
60
+ }, o = (r) => {
61
61
  if (s.onActionError) {
62
62
  try {
63
63
  Promise.resolve(
64
- s.onActionError(l, e, a)
64
+ s.onActionError(r, e, t)
65
65
  ).catch(c);
66
- } catch (u) {
67
- c(u);
66
+ } catch (m) {
67
+ c(m);
68
68
  }
69
69
  return;
70
70
  }
71
71
  console.error("[make-ai-assistant] host action failed", {
72
72
  actionId: e.id,
73
- artifactId: a.artifact.id,
74
- errorType: l instanceof Error ? l.name : typeof l,
73
+ artifactId: t.artifact.id,
74
+ errorType: r instanceof Error ? r.name : typeof r,
75
75
  intent: e.intent
76
76
  });
77
77
  };
78
78
  try {
79
- Promise.resolve(s.onAction(e, a)).catch(n);
80
- } catch (l) {
81
- n(l);
79
+ Promise.resolve(s.onAction(e, t)).catch(o);
80
+ } catch (r) {
81
+ o(r);
82
82
  }
83
- }, L = (e, a) => e.actions?.length && a.onAction ? /* @__PURE__ */ t("div", { className: "make-ai-artifact__actions", children: e.actions.map((s) => /* @__PURE__ */ r(
83
+ }, z = (e, t) => e.actions?.length && t.onAction ? /* @__PURE__ */ a("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: () => _e(s, { artifact: e, context: a.context }, a),
88
+ onClick: () => ye(s, { artifact: e, context: t.context }, t),
89
89
  children: [
90
90
  s.label,
91
- /* @__PURE__ */ t("span", { "aria-hidden": "true", children: "→" })
91
+ /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "→" })
92
92
  ]
93
93
  },
94
94
  s.id
95
- )) }) : null, z = (e, a, s = "") => /* @__PURE__ */ r(
95
+ )) }) : null, B = (e, t, s = "") => /* @__PURE__ */ n(
96
96
  "section",
97
97
  {
98
98
  "aria-label": e.title ?? `${e.kind} result`,
@@ -100,713 +100,718 @@ const $ = (e, a, s) => {
100
100
  "data-artifact-density": e.presentation?.density,
101
101
  "data-artifact-kind": e.kind,
102
102
  children: [
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
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
106
106
  ]
107
107
  }
108
- ), Ve = ({
108
+ ), Be = ({
109
109
  artifact: e,
110
- renderContext: a
110
+ renderContext: t
111
111
  }) => {
112
- const s = e.data.delta, c = s ? $(
112
+ const s = e.data.delta, c = s ? x(
113
113
  s.value,
114
114
  s.format === "percent" ? { style: "percent" } : void 0,
115
- a.context.locale
115
+ t.context.locale
116
116
  ) : void 0;
117
- return z(
117
+ return B(
118
118
  e,
119
- /* @__PURE__ */ r(C, { children: [
120
- /* @__PURE__ */ t("div", { className: "make-ai-artifact__metric-value", children: $(
119
+ /* @__PURE__ */ n(S, { children: [
120
+ /* @__PURE__ */ a("div", { className: "make-ai-artifact__metric-value", children: x(
121
121
  e.data.value,
122
122
  e.data.format,
123
- a.context.locale
123
+ t.context.locale
124
124
  ) }),
125
- s ? /* @__PURE__ */ r(
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__ */ 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
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
133
133
  ]
134
134
  }
135
135
  ) : null,
136
- e.data.context ? /* @__PURE__ */ t("p", { className: "make-ai-artifact__context", children: e.data.context }) : null,
137
- L(e, a)
136
+ e.data.context ? /* @__PURE__ */ a("p", { className: "make-ai-artifact__context", children: e.data.context }) : null,
137
+ z(e, t)
138
138
  ] }),
139
139
  "make-ai-artifact--metric"
140
140
  );
141
- }, qe = ({
141
+ }, He = ({
142
142
  artifact: e,
143
- renderContext: a
144
- }) => z(
143
+ renderContext: t
144
+ }) => B(
145
145
  e,
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
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
151
151
  ] }, s.id)) }),
152
- L(e, a)
152
+ z(e, t)
153
153
  ] }),
154
154
  "make-ai-artifact--comparison"
155
- ), Le = ({
155
+ ), Oe = ({
156
156
  artifact: e,
157
- renderContext: a
157
+ renderContext: t
158
158
  }) => {
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(
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(
161
161
  e,
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
- return /* @__PURE__ */ r("div", { className: "make-ai-artifact__trend-point", children: [
168
- /* @__PURE__ */ t(
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;
167
+ return /* @__PURE__ */ n("div", { className: "make-ai-artifact__trend-point", children: [
168
+ /* @__PURE__ */ a(
169
169
  "span",
170
170
  {
171
- "aria-label": `${p.x}: ${$(
172
- p.y,
173
- u.format,
174
- a.context.locale
171
+ "aria-label": `${u.x}: ${x(
172
+ u.y,
173
+ m.format,
174
+ t.context.locale
175
175
  )}`,
176
176
  className: "make-ai-artifact__trend-bar",
177
177
  role: "img",
178
- style: { height: `${f}%` },
179
- title: `${p.x}: ${$(
180
- p.y,
181
- u.format,
182
- a.context.locale
178
+ style: { height: `${y}%` },
179
+ title: `${u.x}: ${x(
180
+ u.y,
181
+ m.format,
182
+ t.context.locale
183
183
  )}`
184
184
  }
185
185
  ),
186
- /* @__PURE__ */ t("small", { children: p.x })
187
- ] }, `${p.x}-${A}`);
186
+ /* @__PURE__ */ a("small", { children: u.x })
187
+ ] }, `${u.x}-${M}`);
188
188
  }) })
189
- ] }, u.id)) }),
190
- L(e, a)
189
+ ] }, m.id)) }),
190
+ z(e, t)
191
191
  ] }),
192
192
  "make-ai-artifact--trend"
193
193
  );
194
- }, ze = ({
194
+ }, Ze = ({
195
195
  artifact: e,
196
- renderContext: a
196
+ renderContext: t
197
197
  }) => {
198
- const { max: s } = ge(
199
- e.data.items.map((n) => Math.abs(n.value))
198
+ const { max: s } = ve(
199
+ e.data.items.map((o) => Math.abs(o.value))
200
200
  ), c = Math.max(s, 1);
201
- return z(
201
+ return B(
202
202
  e,
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
- /* @__PURE__ */ r("span", { className: "make-ai-artifact__ranking-label", children: [
207
- /* @__PURE__ */ t("span", { children: n.label }),
208
- n.description ? /* @__PURE__ */ t("small", { children: n.description }) : null
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 }),
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
209
209
  ] }),
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)
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) })
212
+ ] }, o.id)) }),
213
+ z(e, t)
214
214
  ] }),
215
215
  "make-ai-artifact--ranking"
216
216
  );
217
- }, He = (e, a) => a.action ?? {
218
- id: `open-${a.id}`,
219
- label: a.title ?? a.id,
217
+ }, je = (e, t) => t.action ?? {
218
+ id: `open-${t.id}`,
219
+ label: t.title ?? t.id,
220
220
  intent: "open-record",
221
- target: { entityKey: e.data.entity.key, recordId: a.id }
222
- }, Be = ({
221
+ target: { entityKey: e.data.entity.key, recordId: t.id }
222
+ }, Ye = ({
223
223
  artifact: e,
224
- renderContext: a
225
- }) => z(
224
+ renderContext: t
225
+ }) => B(
226
226
  e,
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
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
237
237
  )
238
- ] }, l.key)) }),
239
- a.onAction ? /* @__PURE__ */ t("span", { "aria-hidden": "true", children: "›" }) : null
238
+ ] }, r.key)) }),
239
+ t.onAction ? /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "›" }) : null
240
240
  ] });
241
- return a.onAction ? /* @__PURE__ */ t(
241
+ return t.onAction ? /* @__PURE__ */ a(
242
242
  "button",
243
243
  {
244
244
  className: "make-ai-artifact__record",
245
245
  type: "button",
246
- onClick: () => _e(c, {
246
+ onClick: () => ye(c, {
247
247
  artifact: e,
248
- context: a.context
249
- }, a),
250
- children: n
248
+ context: t.context
249
+ }, t),
250
+ children: o
251
251
  },
252
252
  s.id
253
- ) : /* @__PURE__ */ t("div", { className: "make-ai-artifact__record", children: n }, s.id);
253
+ ) : /* @__PURE__ */ a("div", { className: "make-ai-artifact__record", children: o }, s.id);
254
254
  }) }),
255
- e.data.total !== void 0 ? /* @__PURE__ */ r("p", { className: "make-ai-artifact__record-total", children: [
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
- L(e, a)
260
+ z(e, t)
261
261
  ] }),
262
262
  "make-ai-artifact--record-list"
263
- ), Oe = ({
263
+ ), Ge = ({
264
264
  artifact: e,
265
- renderContext: a
266
- }) => z(
265
+ renderContext: t
266
+ }) => B(
267
267
  e,
268
- /* @__PURE__ */ r(C, { children: [
269
- /* @__PURE__ */ r("div", { className: `make-ai-artifact__notice make-ai-artifact__notice--${e.data.tone}`, children: [
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 })
268
+ /* @__PURE__ */ n(S, { children: [
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 })
272
272
  ] }),
273
- L(e, a)
273
+ z(e, t)
274
274
  ] }),
275
275
  "make-ai-artifact--notice"
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)}`;
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
284
  class h extends Error {
285
285
  }
286
- const pe = (e) => {
286
+ const _e = (e) => {
287
287
  try {
288
- const a = e?.return?.();
289
- if (!a) return;
290
- Promise.resolve(a).catch((s) => {
288
+ const t = e?.return?.();
289
+ if (!t) return;
290
+ Promise.resolve(t).catch((s) => {
291
291
  console.error("[make-ai-assistant] transport iterator close failed", {
292
292
  errorType: s instanceof Error ? s.name : typeof s
293
293
  });
294
294
  });
295
- } catch (a) {
295
+ } catch (t) {
296
296
  console.error("[make-ai-assistant] transport iterator close failed", {
297
- errorType: a instanceof Error ? a.name : typeof a
297
+ errorType: t instanceof Error ? t.name : typeof t
298
298
  });
299
299
  }
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];
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];
309
312
  if (s.role === "assistant" && s.status === "streaming")
310
313
  return s.id;
311
314
  }
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
+ }, ra = (e) => {
316
+ for (let t = e.messages.length - 1; t >= 0; t -= 1)
317
+ if (e.messages[t].role === "user") return t;
315
318
  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) {
319
+ }, we = (e) => {
320
+ const t = ra(e);
321
+ if (!(t < 0))
322
+ for (let s = e.messages.length - 1; s > t; s -= 1) {
320
323
  const c = e.messages[s];
321
324
  if (c.role === "assistant") return c.id;
322
325
  }
323
- }, Ie = ({
326
+ }, Te = ({
324
327
  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(
328
+ onRetry: t
329
+ }) => /* @__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(
330
333
  "button",
331
334
  {
332
335
  className: "make-ai-assistant__retry",
333
336
  type: "button",
334
- onClick: a,
337
+ onClick: t,
335
338
  children: "重新发送"
336
339
  }
337
340
  ) : null
338
- ] }), he = ({
341
+ ] }), ge = ({
339
342
  assistantName: e,
340
- error: a,
343
+ error: t,
341
344
  onRetry: s,
342
345
  progress: c
343
346
  }) => {
344
- const n = a ? "error" : "progress", l = a?.message ?? c;
345
- return l ? /* @__PURE__ */ r(
347
+ const o = t ? "error" : "progress", r = t?.message ?? c;
348
+ return r ? /* @__PURE__ */ a(
346
349
  "article",
347
350
  {
348
- "aria-label": `${e}的${n === "error" ? "错误消息" : "状态消息"}`,
349
- className: `make-ai-assistant__message make-ai-assistant__message--assistant make-ai-assistant__message--${n}`,
351
+ "aria-label": `${e}的${o === "error" ? "错误消息" : "状态消息"}`,
352
+ className: `make-ai-assistant__message make-ai-assistant__message--assistant make-ai-assistant__message--${o}`,
350
353
  "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
- ]
354
+ "data-message-state": o,
355
+ 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
+ ] }) })
361
+ ] })
362
362
  }
363
363
  ) : null;
364
- }, Xe = (e, a, s, c, n, l, u, p) => {
365
- const A = ye(e), f = ve(e);
364
+ }, ia = (e, t, s, c, o, r, m, u, M) => {
365
+ const y = we(e), _ = Ne(e);
366
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(
367
+ const E = d.role === "assistant", A = d.id === _, N = d.id === y && e.error, $ = E ? r : u;
368
+ return /* @__PURE__ */ a(
369
369
  "article",
370
370
  {
371
- "aria-label": `${m}的消息`,
371
+ "aria-label": `${$}的消息`,
372
372
  className: `make-ai-assistant__message make-ai-assistant__message--${d.role}`,
373
373
  "data-message-role": d.role,
374
- "data-message-state": b ? "error" : void 0,
374
+ "data-message-state": N ? "error" : void 0,
375
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", {})
376
+ 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 })
380
+ ] }),
381
+ /* @__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", {})
384
386
  ] }) : 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 })
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 })
388
390
  ] }) : null,
389
- b ? /* @__PURE__ */ t(Ie, { error: b, onRetry: u }) : null,
390
- d.artifacts.map((y) => /* @__PURE__ */ t(
391
- Ke,
391
+ N ? /* @__PURE__ */ a(Te, { error: N, onRetry: m }) : null,
392
+ d.artifacts.map((C) => /* @__PURE__ */ a(
393
+ ze,
392
394
  {
393
- artifact: y,
394
- context: a,
395
+ artifact: C,
396
+ context: t,
395
397
  onAction: c,
396
- onActionError: n,
398
+ onActionError: o,
397
399
  registry: s
398
400
  },
399
- y.id
401
+ C.id
400
402
  ))
401
403
  ] })
402
- ]
404
+ ] })
403
405
  },
404
406
  d.id
405
407
  );
406
408
  });
407
409
  };
408
- function ea({
410
+ function oa({
409
411
  assistantName: e = "AI 助手",
410
- context: a,
411
- onAction: s,
412
- onActionError: c,
413
- onClose: n,
414
- onNewConversation: l,
412
+ brandName: t,
413
+ context: s,
414
+ onAction: c,
415
+ onActionError: o,
416
+ onClose: r,
417
+ onNewConversation: m,
415
418
  registry: u,
416
- subtitle: p,
417
- suggestions: A = [],
418
- title: f = "Make AI 助手",
419
+ subtitle: M,
420
+ suggestions: y = [],
421
+ title: _,
419
422
  transport: d,
420
- userName: T = "你"
423
+ userAvatarUrl: E,
424
+ userName: A = "你"
421
425
  }) {
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(),
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(),
424
428
  [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);
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);
428
432
  };
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");
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");
435
439
  return;
436
440
  }
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
441
+ const g = new AbortController();
442
+ return J("loading"), console.info("[make-ai-assistant] conversation load start", {
443
+ 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", {
446
+ appId: s.app.id,
447
+ messageCount: v.messages.length
444
448
  }));
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;
449
+ }).catch((v) => {
450
+ g.signal.aborted || (console.error("[make-ai-assistant] conversation load failed", {
451
+ appId: s.app.id,
452
+ errorType: v instanceof Error ? v.name : typeof v
453
+ }), J("error"));
454
+ }), () => 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;
458
462
  });
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) {
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) {
471
475
  H(
472
- `输入内容过长,请控制在 ${w.messageCharacters} 个字符以内`
476
+ `输入内容过长,请控制在 ${b.messageCharacters} 个字符以内`
473
477
  );
474
478
  return;
475
479
  }
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));
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));
478
482
  try {
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(
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(
483
487
  {
484
- threadId: m.threadId,
485
- message: k,
486
- context: a,
487
- capabilities: xe(ne)
488
+ threadId: p.threadId,
489
+ message: g,
490
+ context: s,
491
+ capabilities: Pe(le)
488
492
  },
489
- { signal: I.signal }
493
+ { signal: v.signal }
490
494
  )[Symbol.asyncIterator]();
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;
495
+ for (K.current = { iterator: he, requestVersion: P }; ; ) {
496
+ const ae = await he.next();
497
+ if (L.current !== P || ae.done) break;
498
+ let l;
495
499
  try {
496
- o = Pe(W.value);
497
- } catch (M) {
500
+ l = Ue(ae.value);
501
+ } catch (T) {
498
502
  throw new h(
499
- M instanceof Error ? M.message : "Invalid assistant event"
503
+ T instanceof Error ? T.message : "Invalid assistant event"
500
504
  );
501
505
  }
502
- if (o.type === "message.start") {
503
- if (g !== void 0 && g !== o.runId)
506
+ if (l.type === "message.start") {
507
+ if (f !== void 0 && f !== l.runId)
504
508
  throw new h("AI 助手响应 run id 不一致");
505
- if (g ??= o.runId, le += 1, le > w.assistantMessagesPerRun)
509
+ if (f ??= l.runId, me += 1, me > b.assistantMessagesPerRun)
506
510
  throw new h("AI 助手单次响应消息数量超过限制");
507
- if (de.has(o.messageId))
511
+ if (pe.has(l.messageId))
508
512
  throw new h("AI 助手响应包含重复的 message id");
509
- de.add(o.messageId), U.add(o.messageId), O.set(o.messageId, 0);
513
+ pe.add(l.messageId), j.add(l.messageId), Z.set(l.messageId, 0);
510
514
  }
511
- if (o.type === "message.delta") {
512
- if (!U.has(o.messageId))
515
+ if (l.type === "message.delta") {
516
+ if (!j.has(l.messageId))
513
517
  throw new h("AI 助手响应事件顺序无效");
514
- const M = O.get(o.messageId) ?? 0, P = se(
515
- o.delta,
516
- w.messageCharacters - B
518
+ const T = Z.get(l.messageId) ?? 0, V = ie(
519
+ l.delta,
520
+ b.messageCharacters - O
517
521
  );
518
- if (B + P > w.messageCharacters)
522
+ if (O + V > b.messageCharacters)
519
523
  throw new h("AI 助手响应文本超过大小限制");
520
- B += P, O.set(
521
- o.messageId,
522
- M + P
524
+ O += V, Z.set(
525
+ l.messageId,
526
+ T + V
523
527
  );
524
528
  }
525
- if (o.type === "message.replace") {
526
- if (!U.has(o.messageId))
529
+ if (l.type === "message.replace") {
530
+ if (!j.has(l.messageId))
527
531
  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)
532
+ const T = Z.get(l.messageId) ?? 0, V = ie(
533
+ l.content,
534
+ b.messageCharacters
535
+ ), fe = O - T + V;
536
+ if (fe > b.messageCharacters)
533
537
  throw new h("AI 助手响应文本超过大小限制");
534
- B = ue, O.set(o.messageId, P);
538
+ O = fe, Z.set(l.messageId, V);
535
539
  }
536
- if (o.type === "run.progress") {
537
- if (g !== void 0 && g !== o.runId)
540
+ if (l.type === "run.progress") {
541
+ if (f !== void 0 && f !== l.runId)
538
542
  throw new h("AI 助手响应 run id 不一致");
539
- g ??= o.runId;
543
+ f ??= l.runId;
540
544
  }
541
- if (o.type === "artifact") {
542
- if (!U.has(o.messageId))
545
+ if (l.type === "artifact") {
546
+ if (!j.has(l.messageId))
543
547
  throw new h("AI 助手响应事件顺序无效");
544
- if (oe += 1, oe > w.artifactsPerRun)
548
+ if (de += 1, de > b.artifactsPerRun)
545
549
  throw new h("AI 助手单次响应 Artifact 数量超过限制");
546
- if (ce.has(o.artifact.id))
550
+ if (ue.has(l.artifact.id))
547
551
  throw new h("AI 助手响应包含重复的 Artifact id");
548
- ce.add(o.artifact.id);
552
+ ue.add(l.artifact.id);
549
553
  }
550
- if (o.type === "message.complete" && !U.delete(o.messageId))
554
+ if (l.type === "message.complete" && !j.delete(l.messageId))
551
555
  throw new h("AI 助手响应事件顺序无效");
552
- if (o.type === "run.complete" && g !== void 0 && g !== o.runId)
556
+ if (l.type === "run.complete" && f !== void 0 && f !== l.runId)
553
557
  throw new h("AI 助手响应 run id 不一致");
554
- if (o.type === "run.cancelled" && o.runId !== void 0 && g !== void 0 && g !== o.runId)
558
+ if (l.type === "run.cancelled" && l.runId !== void 0 && f !== void 0 && f !== l.runId)
555
559
  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;
560
+ if (w((T) => se(T, l)), l.type === "error" || l.type === "run.cancelled" || l.type === "run.complete") {
561
+ I = !0;
558
562
  break;
559
563
  }
560
564
  }
561
- if (!N)
565
+ if (!I)
562
566
  throw new h("AI 助手流式响应在终止事件前结束");
563
- } catch (N) {
564
- if (F.current !== D) return;
565
- if (I.signal.aborted) {
566
- y(
567
- (g) => ee(g, { type: "run.cancelled" })
567
+ } catch (I) {
568
+ if (L.current !== P) return;
569
+ if (v.signal.aborted) {
570
+ w(
571
+ (f) => se(f, { type: "run.cancelled" })
568
572
  );
569
573
  return;
570
574
  }
571
575
  console.error("[make-ai-assistant] assistant run failed", {
572
- appId: a.app.id,
573
- errorType: N instanceof Error ? N.name : typeof N
574
- }), y(
575
- (g) => ee(g, {
576
+ appId: s.app.id,
577
+ errorType: I instanceof Error ? I.name : typeof I
578
+ }), w(
579
+ (f) => se(f, {
576
580
  type: "error",
577
581
  code: "TRANSPORT_ERROR",
578
- message: N instanceof h ? N.message : "连接失败,请重试",
582
+ message: I instanceof h ? I.message : "连接失败,请重试",
579
583
  retryable: !0
580
584
  })
581
585
  );
582
586
  } finally {
583
- F.current === D && S.current === I && (S.current = void 0), x.current?.requestVersion === D && (pe(x.current.iterator), x.current = void 0);
587
+ L.current === P && D.current === v && (D.current = void 0), K.current?.requestVersion === P && (_e(K.current.iterator), K.current = void 0);
584
588
  }
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" })
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" })
592
596
  );
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);
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);
597
601
  };
598
- return /* @__PURE__ */ r("section", { className: "make-ai-assistant make-ai-assistant__panel", children: [
599
- /* @__PURE__ */ r("header", { className: "make-ai-assistant__header", children: [
600
- /* @__PURE__ */ t(q, {}),
601
- /* @__PURE__ */ r("div", { children: [
602
- /* @__PURE__ */ t("h2", { children: f }),
603
- /* @__PURE__ */ t("p", { children: p ?? `当前应用:${a.app.name ?? "未命名应用"}` })
602
+ return /* @__PURE__ */ n("section", { className: "make-ai-assistant make-ai-assistant__panel", children: [
603
+ /* @__PURE__ */ n("header", { className: "make-ai-assistant__header", children: [
604
+ /* @__PURE__ */ a(Y, {}),
605
+ /* @__PURE__ */ n("div", { children: [
606
+ /* @__PURE__ */ a("h2", { children: N }),
607
+ /* @__PURE__ */ a("p", { children: M ?? `当前应用:${s.app.name ?? "未命名应用"}` })
604
608
  ] }),
605
- /* @__PURE__ */ r("div", { className: "make-ai-assistant__header-actions", children: [
606
- d.features?.newConversation !== !1 ? /* @__PURE__ */ t(
609
+ /* @__PURE__ */ n("div", { className: "make-ai-assistant__header-actions", children: [
610
+ d.features?.newConversation !== !1 ? /* @__PURE__ */ a(
607
611
  "button",
608
612
  {
609
613
  "aria-label": "新建对话",
610
614
  className: "make-ai-assistant__icon-button",
611
615
  type: "button",
612
- onClick: Ee,
613
- children: /* @__PURE__ */ t(Je, {})
616
+ onClick: xe,
617
+ children: /* @__PURE__ */ a(ta, {})
614
618
  }
615
619
  ) : null,
616
- n ? /* @__PURE__ */ t(
620
+ r ? /* @__PURE__ */ a(
617
621
  "button",
618
622
  {
619
- "aria-label": "关闭 Make AI 助手",
623
+ "aria-label": `关闭 ${N}`,
620
624
  className: "make-ai-assistant__icon-button",
621
625
  type: "button",
622
- onClick: n,
623
- children: /* @__PURE__ */ t(Ge, {})
626
+ onClick: r,
627
+ children: /* @__PURE__ */ a(aa, {})
624
628
  }
625
629
  ) : null
626
630
  ] })
627
631
  ] }),
628
- /* @__PURE__ */ r("div", { className: "make-ai-assistant__privacy-note", role: "note", children: [
629
- /* @__PURE__ */ t("span", { "aria-hidden": "true", children: "◇" }),
632
+ /* @__PURE__ */ n("div", { className: "make-ai-assistant__privacy-note", role: "note", children: [
633
+ /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "◇" }),
630
634
  "当前页面上下文会随请求发送,数据权限以宿主服务端校验结果为准"
631
635
  ] }),
632
- /* @__PURE__ */ r(
636
+ /* @__PURE__ */ n(
633
637
  "div",
634
638
  {
635
639
  className: "make-ai-assistant__body",
636
640
  "aria-live": "polite",
637
641
  "aria-relevant": "additions text",
638
- ref: te,
642
+ ref: re,
639
643
  role: "log",
640
- onScroll: Ne,
644
+ onScroll: $e,
641
645
  children: [
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(
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(
651
655
  "button",
652
656
  {
653
657
  className: "make-ai-assistant__retry",
654
658
  type: "button",
655
- onClick: () => be((i) => i + 1),
659
+ onClick: () => Ee((i) => i + 1),
656
660
  children: "重新加载"
657
661
  }
658
662
  )
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,
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,
667
669
  s,
670
+ le,
668
671
  c,
672
+ o,
669
673
  e,
670
- Q ? ie : void 0,
671
- T
674
+ ee ? ce : void 0,
675
+ A,
676
+ E
672
677
  ),
673
- m.progress && !$e ? /* @__PURE__ */ t(
674
- he,
678
+ p.progress && !De ? /* @__PURE__ */ a(
679
+ ge,
675
680
  {
676
681
  assistantName: e,
677
- progress: m.progress.message
682
+ progress: p.progress.message
678
683
  }
679
684
  ) : null,
680
- m.error && !Re ? /* @__PURE__ */ t(
681
- he,
685
+ p.error && !Ke ? /* @__PURE__ */ a(
686
+ ge,
682
687
  {
683
688
  assistantName: e,
684
- error: m.error,
685
- onRetry: Q ? ie : void 0
689
+ error: p.error,
690
+ onRetry: ee ? ce : void 0
686
691
  }
687
692
  ) : null
688
693
  ]
689
694
  }
690
695
  ),
691
- /* @__PURE__ */ r("footer", { className: "make-ai-assistant__composer-region", children: [
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(
696
+ /* @__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(
693
698
  "button",
694
699
  {
695
700
  type: "button",
696
701
  onClick: () => {
697
- J(i);
702
+ X(i);
698
703
  },
699
704
  children: i
700
705
  },
701
- `${v}-${i}`
706
+ `${k}-${i}`
702
707
  )) }) : null,
703
- /* @__PURE__ */ r("form", { className: "make-ai-assistant__composer", onSubmit: we, children: [
704
- /* @__PURE__ */ t(
708
+ /* @__PURE__ */ n("form", { className: "make-ai-assistant__composer", onSubmit: Ce, children: [
709
+ /* @__PURE__ */ a(
705
710
  "textarea",
706
711
  {
707
712
  "aria-label": `向 ${e} 提问`,
708
- "aria-describedby": Z ? "make-ai-composer-error" : void 0,
709
- "aria-invalid": Z ? !0 : void 0,
713
+ "aria-describedby": G ? "make-ai-composer-error" : void 0,
714
+ "aria-invalid": G ? !0 : void 0,
710
715
  autoFocus: !0,
711
- disabled: R !== "ready" || m.status === "streaming",
712
- placeholder: `询问当前 ${a.app.name ?? "App"} 中的数据…`,
716
+ disabled: F !== "ready" || p.status === "streaming",
717
+ placeholder: `询问当前 ${s.app.name ?? "App"} 中的数据…`,
713
718
  rows: 2,
714
- value: _,
719
+ value: $,
715
720
  onChange: (i) => {
716
- b(i.currentTarget.value), H(void 0);
721
+ C(i.currentTarget.value), H(void 0);
717
722
  },
718
- onKeyDown: Me
723
+ onKeyDown: Re
719
724
  }
720
725
  ),
721
- m.status === "streaming" ? /* @__PURE__ */ t(
726
+ p.status === "streaming" ? /* @__PURE__ */ a(
722
727
  "button",
723
728
  {
724
- "aria-label": Ce,
729
+ "aria-label": Fe,
725
730
  className: "make-ai-assistant__send make-ai-assistant__send--stop",
726
731
  type: "button",
727
- onClick: Te,
728
- children: /* @__PURE__ */ t("span", { "aria-hidden": "true" })
732
+ onClick: Se,
733
+ children: /* @__PURE__ */ a("span", { "aria-hidden": "true" })
729
734
  }
730
- ) : /* @__PURE__ */ t(
735
+ ) : /* @__PURE__ */ a(
731
736
  "button",
732
737
  {
733
738
  "aria-label": "发送",
734
739
  className: "make-ai-assistant__send",
735
- disabled: R !== "ready" || !_.trim(),
740
+ disabled: F !== "ready" || !$.trim(),
736
741
  type: "submit",
737
- children: /* @__PURE__ */ t(Qe, {})
742
+ children: /* @__PURE__ */ a(sa, {})
738
743
  }
739
744
  )
740
745
  ] }),
741
- Z ? /* @__PURE__ */ t("p", { id: "make-ai-composer-error", role: "alert", children: Z }) : null,
742
- /* @__PURE__ */ t("p", { children: "AI 生成的结果可能存在偏差,重要数据请核对明细。" })
746
+ G ? /* @__PURE__ */ a("p", { id: "make-ai-composer-error", role: "alert", children: G }) : null,
747
+ /* @__PURE__ */ a("p", { children: "AI 生成的结果可能存在偏差,重要数据请核对明细。" })
743
748
  ] })
744
749
  ] });
745
750
  }
746
- function ia({
751
+ function pa({
747
752
  defaultOpen: e = !1,
748
- hideLauncher: a = !1,
753
+ hideLauncher: t = !1,
749
754
  launcher: s,
750
755
  onOpenChange: c,
751
- open: n,
752
- ...l
756
+ open: o,
757
+ ...r
753
758
  }) {
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()));
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()));
761
766
  };
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(
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(
765
770
  "button",
766
771
  {
767
- "aria-label": f ? "关闭 Make AI 助手" : "打开 Make AI 助手",
768
- "aria-expanded": f,
772
+ "aria-label": _ ? `关闭 ${m}` : `打开 ${m}`,
773
+ "aria-expanded": _,
769
774
  className: "make-ai-assistant__launcher",
770
- ref: A,
775
+ ref: y,
771
776
  type: "button",
772
- onClick: T,
777
+ onClick: E,
773
778
  children: [
774
- /* @__PURE__ */ t("span", { className: "make-ai-assistant__launcher-orbit", "aria-hidden": "true" }),
775
- /* @__PURE__ */ t(ke, {})
779
+ /* @__PURE__ */ a("span", { className: "make-ai-assistant__launcher-orbit", "aria-hidden": "true" }),
780
+ /* @__PURE__ */ a(Ie, {})
776
781
  ]
777
782
  }
778
783
  ) : null,
779
- f ? /* @__PURE__ */ t(
784
+ _ ? /* @__PURE__ */ a(
780
785
  "aside",
781
786
  {
782
- "aria-label": "Make AI 助手",
787
+ "aria-label": m,
783
788
  "aria-modal": "false",
784
789
  className: "make-ai-assistant__drawer",
785
790
  role: "dialog",
786
- children: /* @__PURE__ */ t(ea, { ...l, onClose: () => d(!1) })
791
+ children: /* @__PURE__ */ a(oa, { ...r, onClose: () => d(!1) })
787
792
  }
788
793
  ) : null
789
794
  ] });
790
795
  }
791
796
  export {
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
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
812
817
  };