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