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