@qfei-design/make-ai-assistant 0.1.7 → 0.1.9
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 +18 -9
- package/README.md +21 -8
- package/dist/react/make-ai-assistant.d.ts +2 -1
- package/dist/react.cjs +4 -4
- package/dist/react.mjs +679 -604
- package/dist/styles.css +155 -28
- package/package.ai.json +4 -4
- package/package.json +1 -1
package/dist/react.mjs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { jsxs as i, 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 i, jsx as a, Fragment as H } from "react/jsx-runtime";
|
|
2
|
+
import { resolveArtifactTemplate as _t, createArtifactTemplateRegistry as je, createArtifactCapabilities as vt } from "./index.mjs";
|
|
3
|
+
import { extendArtifactTemplateRegistry as la } from "./index.mjs";
|
|
4
|
+
import { useState as R, useRef as w, useEffect as Q, useMemo as He } from "react";
|
|
5
|
+
import { a as ge, r as fe, c as _e, M as N, b as yt, p as kt } from "./conversation-B7eGUXi-.js";
|
|
6
|
+
import { d as ma, e as ua, f as pa, g as ha, v as ga } from "./conversation-B7eGUXi-.js";
|
|
7
|
+
function At({
|
|
8
8
|
artifact: e,
|
|
9
9
|
context: t,
|
|
10
10
|
fallback: s,
|
|
11
|
-
onAction:
|
|
12
|
-
onActionError:
|
|
13
|
-
registry:
|
|
11
|
+
onAction: n,
|
|
12
|
+
onActionError: r,
|
|
13
|
+
registry: o
|
|
14
14
|
}) {
|
|
15
|
-
const
|
|
16
|
-
if (!
|
|
15
|
+
const d = _t(o, e, t);
|
|
16
|
+
if (!d)
|
|
17
17
|
return s ? s(e) : /* @__PURE__ */ i("section", { className: "make-ai-artifact make-ai-artifact--unsupported", role: "status", children: [
|
|
18
18
|
/* @__PURE__ */ a("strong", { children: "暂不支持展示此结果" }),
|
|
19
19
|
/* @__PURE__ */ i("span", { children: [
|
|
@@ -21,78 +21,78 @@ function mt({
|
|
|
21
21
|
e.kind
|
|
22
22
|
] })
|
|
23
23
|
] });
|
|
24
|
-
const
|
|
24
|
+
const p = {
|
|
25
25
|
context: t,
|
|
26
|
-
onAction:
|
|
27
|
-
onActionError:
|
|
26
|
+
onAction: n,
|
|
27
|
+
onActionError: r
|
|
28
28
|
};
|
|
29
|
-
return
|
|
29
|
+
return d.template.render(e, t, p);
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const K = (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 n = t?.precision, r = {
|
|
36
|
+
maximumFractionDigits: n ?? 2,
|
|
37
|
+
minimumFractionDigits: n
|
|
38
38
|
};
|
|
39
|
-
t?.style === "currency" && t.currency ? (
|
|
39
|
+
t?.style === "currency" && t.currency ? (r.style = "currency", r.currency = t.currency) : t?.style === "percent" && (r.style = "percent");
|
|
40
40
|
try {
|
|
41
|
-
const
|
|
42
|
-
return `${new Intl.NumberFormat(s,
|
|
41
|
+
const o = t?.style === "percent" ? e / 100 : e;
|
|
42
|
+
return `${new Intl.NumberFormat(s, r).format(o)}${t?.unit ?? ""}`;
|
|
43
43
|
} catch {
|
|
44
44
|
return `${e}${t?.unit ?? ""}`;
|
|
45
45
|
}
|
|
46
|
-
},
|
|
46
|
+
}, Ze = (e) => {
|
|
47
47
|
let t = Number.POSITIVE_INFINITY, s = Number.NEGATIVE_INFINITY;
|
|
48
|
-
for (const
|
|
49
|
-
t = Math.min(t,
|
|
48
|
+
for (const n of e)
|
|
49
|
+
t = Math.min(t, n), s = Math.max(s, n);
|
|
50
50
|
return Number.isFinite(t) && Number.isFinite(s) ? { min: t, max: s } : { min: 0, max: 0 };
|
|
51
|
-
},
|
|
51
|
+
}, Ge = (e, t, s) => {
|
|
52
52
|
if (!s.onAction) return;
|
|
53
|
-
const
|
|
53
|
+
const n = (o) => {
|
|
54
54
|
console.error("[make-ai-assistant] host action error handler failed", {
|
|
55
55
|
actionId: e.id,
|
|
56
56
|
artifactId: t.artifact.id,
|
|
57
|
-
errorType:
|
|
57
|
+
errorType: o instanceof Error ? o.name : typeof o,
|
|
58
58
|
intent: e.intent
|
|
59
59
|
});
|
|
60
|
-
},
|
|
60
|
+
}, r = (o) => {
|
|
61
61
|
if (s.onActionError) {
|
|
62
62
|
try {
|
|
63
63
|
Promise.resolve(
|
|
64
|
-
s.onActionError(
|
|
65
|
-
).catch(
|
|
66
|
-
} catch (
|
|
67
|
-
|
|
64
|
+
s.onActionError(o, e, t)
|
|
65
|
+
).catch(n);
|
|
66
|
+
} catch (d) {
|
|
67
|
+
n(d);
|
|
68
68
|
}
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
71
|
console.error("[make-ai-assistant] host action failed", {
|
|
72
72
|
actionId: e.id,
|
|
73
73
|
artifactId: t.artifact.id,
|
|
74
|
-
errorType:
|
|
74
|
+
errorType: o instanceof Error ? o.name : typeof o,
|
|
75
75
|
intent: e.intent
|
|
76
76
|
});
|
|
77
77
|
};
|
|
78
78
|
try {
|
|
79
|
-
Promise.resolve(s.onAction(e, t)).catch(
|
|
80
|
-
} catch (
|
|
81
|
-
o
|
|
79
|
+
Promise.resolve(s.onAction(e, t)).catch(r);
|
|
80
|
+
} catch (o) {
|
|
81
|
+
r(o);
|
|
82
82
|
}
|
|
83
|
-
},
|
|
83
|
+
}, X = (e, t) => e.actions?.length && t.onAction ? /* @__PURE__ */ a("div", { className: "make-ai-artifact__actions", children: e.actions.map((s) => /* @__PURE__ */ i(
|
|
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: () => Ge(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, ee = (e, t, s = "") => /* @__PURE__ */ i(
|
|
96
96
|
"section",
|
|
97
97
|
{
|
|
98
98
|
"aria-label": e.title ?? `${e.kind} result`,
|
|
@@ -105,19 +105,19 @@ const B = (e, t, s) => {
|
|
|
105
105
|
t
|
|
106
106
|
]
|
|
107
107
|
}
|
|
108
|
-
),
|
|
108
|
+
), bt = ({
|
|
109
109
|
artifact: e,
|
|
110
110
|
renderContext: t
|
|
111
111
|
}) => {
|
|
112
|
-
const s = e.data.delta,
|
|
112
|
+
const s = e.data.delta, n = s ? K(
|
|
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 ee(
|
|
118
118
|
e,
|
|
119
|
-
/* @__PURE__ */ i(
|
|
120
|
-
/* @__PURE__ */ a("div", { className: "make-ai-artifact__metric-value", children:
|
|
119
|
+
/* @__PURE__ */ i(H, { children: [
|
|
120
|
+
/* @__PURE__ */ a("div", { className: "make-ai-artifact__metric-value", children: K(
|
|
121
121
|
e.data.value,
|
|
122
122
|
e.data.format,
|
|
123
123
|
t.context.locale
|
|
@@ -128,114 +128,114 @@ const B = (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: n }),
|
|
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
|
+
X(e, t)
|
|
138
138
|
] }),
|
|
139
139
|
"make-ai-artifact--metric"
|
|
140
140
|
);
|
|
141
|
-
},
|
|
141
|
+
}, It = ({
|
|
142
142
|
artifact: e,
|
|
143
143
|
renderContext: t
|
|
144
|
-
}) =>
|
|
144
|
+
}) => ee(
|
|
145
145
|
e,
|
|
146
|
-
/* @__PURE__ */ i(
|
|
146
|
+
/* @__PURE__ */ i(H, { children: [
|
|
147
147
|
/* @__PURE__ */ a("div", { className: "make-ai-artifact__comparison", children: e.data.items.map((s) => /* @__PURE__ */ i("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: K(s.value, s.format, t.context.locale) }),
|
|
150
150
|
s.hint ? /* @__PURE__ */ a("small", { children: s.hint }) : null
|
|
151
151
|
] }, s.id)) }),
|
|
152
|
-
|
|
152
|
+
X(e, t)
|
|
153
153
|
] }),
|
|
154
154
|
"make-ai-artifact--comparison"
|
|
155
|
-
),
|
|
155
|
+
), Nt = ({
|
|
156
156
|
artifact: e,
|
|
157
157
|
renderContext: t
|
|
158
158
|
}) => {
|
|
159
|
-
const s = e.data.series.flatMap((
|
|
160
|
-
return
|
|
159
|
+
const s = e.data.series.flatMap((d) => d.points.map((p) => p.y)), { max: n, min: r } = Ze(s), o = n - r || 1;
|
|
160
|
+
return ee(
|
|
161
161
|
e,
|
|
162
|
-
/* @__PURE__ */ i(
|
|
163
|
-
/* @__PURE__ */ a("div", { className: "make-ai-artifact__trend", children: e.data.series.map((
|
|
164
|
-
/* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-label", children:
|
|
165
|
-
/* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-bars", children:
|
|
166
|
-
const
|
|
162
|
+
/* @__PURE__ */ i(H, { children: [
|
|
163
|
+
/* @__PURE__ */ a("div", { className: "make-ai-artifact__trend", children: e.data.series.map((d) => /* @__PURE__ */ i("div", { className: "make-ai-artifact__trend-series", children: [
|
|
164
|
+
/* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-label", children: d.label }),
|
|
165
|
+
/* @__PURE__ */ a("div", { className: "make-ai-artifact__trend-bars", children: d.points.map((p, f) => {
|
|
166
|
+
const b = 18 + (p.y - r) / o * 70;
|
|
167
167
|
return /* @__PURE__ */ i("div", { className: "make-ai-artifact__trend-point", children: [
|
|
168
168
|
/* @__PURE__ */ a(
|
|
169
169
|
"span",
|
|
170
170
|
{
|
|
171
|
-
"aria-label": `${
|
|
172
|
-
|
|
173
|
-
|
|
171
|
+
"aria-label": `${p.x}: ${K(
|
|
172
|
+
p.y,
|
|
173
|
+
d.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
|
-
|
|
181
|
-
|
|
178
|
+
style: { height: `${b}%` },
|
|
179
|
+
title: `${p.x}: ${K(
|
|
180
|
+
p.y,
|
|
181
|
+
d.format,
|
|
182
182
|
t.context.locale
|
|
183
183
|
)}`
|
|
184
184
|
}
|
|
185
185
|
),
|
|
186
|
-
/* @__PURE__ */ a("small", { children:
|
|
187
|
-
] }, `${
|
|
186
|
+
/* @__PURE__ */ a("small", { children: p.x })
|
|
187
|
+
] }, `${p.x}-${f}`);
|
|
188
188
|
}) })
|
|
189
|
-
] },
|
|
190
|
-
|
|
189
|
+
] }, d.id)) }),
|
|
190
|
+
X(e, t)
|
|
191
191
|
] }),
|
|
192
192
|
"make-ai-artifact--trend"
|
|
193
193
|
);
|
|
194
|
-
},
|
|
194
|
+
}, wt = ({
|
|
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 } = Ze(
|
|
199
|
+
e.data.items.map((r) => Math.abs(r.value))
|
|
200
|
+
), n = Math.max(s, 1);
|
|
201
|
+
return ee(
|
|
202
202
|
e,
|
|
203
|
-
/* @__PURE__ */ i(
|
|
204
|
-
/* @__PURE__ */ a("ol", { className: "make-ai-artifact__ranking", children: e.data.items.map((
|
|
205
|
-
/* @__PURE__ */ a("span", { className: "make-ai-artifact__rank", children:
|
|
203
|
+
/* @__PURE__ */ i(H, { children: [
|
|
204
|
+
/* @__PURE__ */ a("ol", { className: "make-ai-artifact__ranking", children: e.data.items.map((r, o) => /* @__PURE__ */ i("li", { children: [
|
|
205
|
+
/* @__PURE__ */ a("span", { className: "make-ai-artifact__rank", children: o + 1 }),
|
|
206
206
|
/* @__PURE__ */ i("span", { className: "make-ai-artifact__ranking-label", children: [
|
|
207
|
-
/* @__PURE__ */ a("span", { children:
|
|
208
|
-
|
|
207
|
+
/* @__PURE__ */ a("span", { children: r.label }),
|
|
208
|
+
r.description ? /* @__PURE__ */ a("small", { children: r.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(r.value) / n * 100}%` } }) }),
|
|
211
|
+
/* @__PURE__ */ a("strong", { children: K(r.value, r.format, t.context.locale) })
|
|
212
|
+
] }, r.id)) }),
|
|
213
|
+
X(e, t)
|
|
214
214
|
] }),
|
|
215
215
|
"make-ai-artifact--ranking"
|
|
216
216
|
);
|
|
217
|
-
},
|
|
217
|
+
}, Mt = (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
|
+
}, Tt = ({
|
|
223
223
|
artifact: e,
|
|
224
224
|
renderContext: t
|
|
225
|
-
}) =>
|
|
225
|
+
}) => ee(
|
|
226
226
|
e,
|
|
227
|
-
/* @__PURE__ */ i(
|
|
227
|
+
/* @__PURE__ */ i(H, { 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 n = Mt(e, s), r = /* @__PURE__ */ i(H, { children: [
|
|
230
230
|
/* @__PURE__ */ a("strong", { children: s.title ?? s.id }),
|
|
231
|
-
/* @__PURE__ */ a("span", { className: "make-ai-artifact__record-values", children: e.data.columns.map((
|
|
232
|
-
/* @__PURE__ */ a("small", { children:
|
|
233
|
-
|
|
234
|
-
s.values[
|
|
235
|
-
|
|
231
|
+
/* @__PURE__ */ a("span", { className: "make-ai-artifact__record-values", children: e.data.columns.map((o) => /* @__PURE__ */ i("span", { children: [
|
|
232
|
+
/* @__PURE__ */ a("small", { children: o.label }),
|
|
233
|
+
K(
|
|
234
|
+
s.values[o.key],
|
|
235
|
+
o.format,
|
|
236
236
|
t.context.locale
|
|
237
237
|
)
|
|
238
|
-
] },
|
|
238
|
+
] }, o.key)) }),
|
|
239
239
|
t.onAction ? /* @__PURE__ */ a("span", { "aria-hidden": "true", children: "›" }) : null
|
|
240
240
|
] });
|
|
241
241
|
return t.onAction ? /* @__PURE__ */ a(
|
|
@@ -243,51 +243,51 @@ const B = (e, t, s) => {
|
|
|
243
243
|
{
|
|
244
244
|
className: "make-ai-artifact__record",
|
|
245
245
|
type: "button",
|
|
246
|
-
onClick: () =>
|
|
246
|
+
onClick: () => Ge(n, {
|
|
247
247
|
artifact: e,
|
|
248
248
|
context: t.context
|
|
249
249
|
}, t),
|
|
250
|
-
children:
|
|
250
|
+
children: r
|
|
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: r }, s.id);
|
|
254
254
|
}) }),
|
|
255
255
|
e.data.total !== void 0 ? /* @__PURE__ */ i("p", { className: "make-ai-artifact__record-total", children: [
|
|
256
256
|
"共 ",
|
|
257
257
|
e.data.total,
|
|
258
258
|
" 条"
|
|
259
259
|
] }) : null,
|
|
260
|
-
|
|
260
|
+
X(e, t)
|
|
261
261
|
] }),
|
|
262
262
|
"make-ai-artifact--record-list"
|
|
263
|
-
),
|
|
263
|
+
), Ct = ({
|
|
264
264
|
artifact: e,
|
|
265
265
|
renderContext: t
|
|
266
|
-
}) =>
|
|
266
|
+
}) => ee(
|
|
267
267
|
e,
|
|
268
|
-
/* @__PURE__ */ i(
|
|
268
|
+
/* @__PURE__ */ i(H, { children: [
|
|
269
269
|
/* @__PURE__ */ i("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
|
+
X(e, t)
|
|
274
274
|
] }),
|
|
275
275
|
"make-ai-artifact--notice"
|
|
276
|
-
),
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
],
|
|
276
|
+
), J = (e, t, s) => ({ id: e, kinds: [t], priority: 0, render: s }), $t = [
|
|
277
|
+
J("platform.metric.default", "metric", (e, t, s) => /* @__PURE__ */ a(bt, { artifact: e, renderContext: s })),
|
|
278
|
+
J("platform.comparison.default", "comparison", (e, t, s) => /* @__PURE__ */ a(It, { artifact: e, renderContext: s })),
|
|
279
|
+
J("platform.trend.default", "trend", (e, t, s) => /* @__PURE__ */ a(Nt, { artifact: e, renderContext: s })),
|
|
280
|
+
J("platform.ranking.default", "ranking", (e, t, s) => /* @__PURE__ */ a(wt, { artifact: e, renderContext: s })),
|
|
281
|
+
J("platform.record-list.default", "record-list", (e, t, s) => /* @__PURE__ */ a(Tt, { artifact: e, renderContext: s })),
|
|
282
|
+
J("platform.notice.default", "notice", (e, t, s) => /* @__PURE__ */ a(Ct, { artifact: e, renderContext: s }))
|
|
283
|
+
], Et = je($t).templates, St = (e = Et) => je(e), Rt = (e) => `${e}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, xt = "Make", Lt = [
|
|
284
284
|
"总结当前页面数据",
|
|
285
285
|
"找出需要关注的记录",
|
|
286
286
|
"列出我有权限查看的数据对象"
|
|
287
|
-
],
|
|
288
|
-
class
|
|
287
|
+
], Ye = (e, t) => t ?? `${e?.trim() || xt} AI 助手`, Ft = (e) => e ?? Lt;
|
|
288
|
+
class v extends Error {
|
|
289
289
|
}
|
|
290
|
-
const
|
|
290
|
+
const Ke = (e) => {
|
|
291
291
|
try {
|
|
292
292
|
const t = e?.return?.();
|
|
293
293
|
if (!t) return;
|
|
@@ -301,7 +301,7 @@ const Fe = (e) => {
|
|
|
301
301
|
errorType: t instanceof Error ? t.name : typeof t
|
|
302
302
|
});
|
|
303
303
|
}
|
|
304
|
-
},
|
|
304
|
+
}, Pt = async (e) => {
|
|
305
305
|
if (globalThis.navigator?.clipboard?.writeText) {
|
|
306
306
|
await globalThis.navigator.clipboard.writeText(e);
|
|
307
307
|
return;
|
|
@@ -313,111 +313,140 @@ const Fe = (e) => {
|
|
|
313
313
|
const s = document.execCommand("copy");
|
|
314
314
|
if (t.remove(), !s)
|
|
315
315
|
throw new Error("Clipboard copy failed");
|
|
316
|
-
},
|
|
316
|
+
}, We = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
|
|
317
317
|
/* @__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" }),
|
|
318
318
|
/* @__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" })
|
|
319
|
-
] }),
|
|
319
|
+
] }), Bt = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "m6 6 12 12M18 6 6 18" }) }), Dt = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
|
|
320
320
|
/* @__PURE__ */ a("path", { d: "M8 8h10v12H8z" }),
|
|
321
321
|
/* @__PURE__ */ a("path", { d: "M6 16H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })
|
|
322
|
-
] }),
|
|
322
|
+
] }), Vt = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
|
|
323
|
+
/* @__PURE__ */ a("path", { d: "M20 11a8 8 0 0 0-14.7-4.4L4 8" }),
|
|
324
|
+
/* @__PURE__ */ a("path", { d: "M4 4v4h4" }),
|
|
325
|
+
/* @__PURE__ */ a("path", { d: "M4 13a8 8 0 0 0 14.7 4.4L20 16" }),
|
|
326
|
+
/* @__PURE__ */ a("path", { d: "M20 20v-4h-4" })
|
|
327
|
+
] }), qt = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
|
|
323
328
|
/* @__PURE__ */ a("path", { d: "M5 10v4" }),
|
|
324
329
|
/* @__PURE__ */ a("path", { d: "M8 9v6l6 3V6L8 9Z" }),
|
|
325
330
|
/* @__PURE__ */ a("path", { d: "M17 9.2a4.2 4.2 0 0 1 0 5.6" }),
|
|
326
331
|
/* @__PURE__ */ a("path", { d: "M19.4 6.8a7.6 7.6 0 0 1 0 10.4" })
|
|
327
|
-
] }),
|
|
332
|
+
] }), Ut = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
|
|
328
333
|
/* @__PURE__ */ a("path", { d: "M12 4v11" }),
|
|
329
334
|
/* @__PURE__ */ a("path", { d: "m7 10 5 5 5-5" }),
|
|
330
335
|
/* @__PURE__ */ a("path", { d: "M5 20h14" })
|
|
331
|
-
] }),
|
|
336
|
+
] }), Ht = () => /* @__PURE__ */ a("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: /* @__PURE__ */ a("path", { d: "M12 5v14M5 12h14" }) }), Kt = () => /* @__PURE__ */ i("svg", { "aria-hidden": "true", viewBox: "0 0 24 24", children: [
|
|
332
337
|
/* @__PURE__ */ a("path", { d: "m4 4 17 8-17 8 3-8-3-8Z" }),
|
|
333
338
|
/* @__PURE__ */ a("path", { d: "M7 12h14" })
|
|
334
|
-
] }),
|
|
339
|
+
] }), ie = ({ className: e = "" }) => /* @__PURE__ */ a("span", { className: `make-ai-assistant__avatar ${e}`.trim(), "aria-hidden": "true", children: /* @__PURE__ */ a(We, {}) }), zt = ({ src: e }) => e ? /* @__PURE__ */ a("span", { className: "make-ai-assistant__user-avatar", "aria-hidden": "true", children: /* @__PURE__ */ a("img", { alt: "", src: e }) }) : null, Ot = ({
|
|
335
340
|
userAvatarUrl: e,
|
|
336
341
|
userName: t
|
|
337
342
|
}) => {
|
|
338
343
|
const s = t?.trim();
|
|
339
344
|
return !s && !e ? null : /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-identity", children: [
|
|
340
345
|
s ? /* @__PURE__ */ a("span", { className: "make-ai-assistant__message-sender", children: s }) : null,
|
|
341
|
-
/* @__PURE__ */ a(
|
|
346
|
+
/* @__PURE__ */ a(zt, { src: e })
|
|
342
347
|
] });
|
|
343
|
-
},
|
|
344
|
-
const t = [], s = [],
|
|
345
|
-
const
|
|
348
|
+
}, jt = (e) => {
|
|
349
|
+
const t = [], s = [], n = [], r = [], o = () => {
|
|
350
|
+
const f = s.join(`
|
|
346
351
|
`).trim();
|
|
347
|
-
s.length = 0,
|
|
348
|
-
},
|
|
349
|
-
|
|
350
|
-
},
|
|
351
|
-
const
|
|
352
|
+
s.length = 0, f && t.push({ type: "paragraph", text: f });
|
|
353
|
+
}, d = () => {
|
|
354
|
+
n.length && t.push({ type: "list", items: n.splice(0) });
|
|
355
|
+
}, p = () => {
|
|
356
|
+
const f = r.join(`
|
|
352
357
|
`).trim();
|
|
353
|
-
|
|
358
|
+
r.length = 0, f && t.push({ type: "pre", text: f });
|
|
354
359
|
};
|
|
355
|
-
for (const
|
|
360
|
+
for (const f of e.replace(/\r\n?/g, `
|
|
356
361
|
`).split(`
|
|
357
362
|
`)) {
|
|
358
|
-
const
|
|
359
|
-
if (!
|
|
360
|
-
|
|
363
|
+
const b = f.trim();
|
|
364
|
+
if (!b) {
|
|
365
|
+
o(), d(), p();
|
|
361
366
|
continue;
|
|
362
367
|
}
|
|
363
|
-
|
|
364
|
-
|
|
368
|
+
const C = /^(#{1,6})\s+(.+)$/.exec(b);
|
|
369
|
+
if (C) {
|
|
370
|
+
o(), d(), p();
|
|
371
|
+
const m = (C[2] ?? "").replace(/\s+#+\s*$/, "").trim();
|
|
372
|
+
m && t.push({
|
|
373
|
+
type: "heading",
|
|
374
|
+
level: C[1]?.length,
|
|
375
|
+
text: m
|
|
376
|
+
});
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
if (/^\s*\|.+\|\s*$/.test(f)) {
|
|
380
|
+
o(), d(), r.push(f.trim());
|
|
365
381
|
continue;
|
|
366
382
|
}
|
|
367
|
-
const
|
|
368
|
-
if (
|
|
369
|
-
|
|
383
|
+
const $ = /^\s*[-*]\s+(.+)$/.exec(f);
|
|
384
|
+
if ($) {
|
|
385
|
+
o(), p(), n.push($[1]?.trim() ?? "");
|
|
370
386
|
continue;
|
|
371
387
|
}
|
|
372
|
-
|
|
388
|
+
d(), p(), s.push(b);
|
|
373
389
|
}
|
|
374
|
-
return
|
|
375
|
-
},
|
|
390
|
+
return o(), d(), p(), t;
|
|
391
|
+
}, Ae = (e) => {
|
|
376
392
|
const t = [], s = /(\*\*[^*]+\*\*|`[^`]+`)/g;
|
|
377
|
-
let
|
|
378
|
-
for (const
|
|
379
|
-
const
|
|
380
|
-
|
|
393
|
+
let n = 0;
|
|
394
|
+
for (const r of e.matchAll(s)) {
|
|
395
|
+
const o = r[0], d = r.index ?? 0;
|
|
396
|
+
d > n && t.push(e.slice(n, d)), o.startsWith("**") ? t.push(/* @__PURE__ */ a("strong", { children: o.slice(2, -2) }, `${d}-strong`)) : t.push(/* @__PURE__ */ a("code", { children: o.slice(1, -1) }, `${d}-code`)), n = d + o.length;
|
|
381
397
|
}
|
|
382
|
-
return
|
|
383
|
-
},
|
|
384
|
-
const t =
|
|
385
|
-
return t.length ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble make-ai-assistant__assistant-text", children: t.map((s,
|
|
386
|
-
|
|
387
|
-
|
|
398
|
+
return n < e.length && t.push(e.slice(n)), t;
|
|
399
|
+
}, Zt = ({ content: e }) => {
|
|
400
|
+
const t = jt(e);
|
|
401
|
+
return t.length ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble make-ai-assistant__assistant-text", children: t.map((s, n) => {
|
|
402
|
+
if (s.type === "heading") {
|
|
403
|
+
const r = s.level <= 2 ? "h3" : "h4";
|
|
404
|
+
return /* @__PURE__ */ a(
|
|
405
|
+
r,
|
|
406
|
+
{
|
|
407
|
+
className: `make-ai-assistant__markdown-heading make-ai-assistant__markdown-heading--${s.level}`,
|
|
408
|
+
children: Ae(s.text)
|
|
409
|
+
},
|
|
410
|
+
`${n}-heading`
|
|
411
|
+
);
|
|
412
|
+
}
|
|
413
|
+
return s.type === "paragraph" ? /* @__PURE__ */ a("p", { children: Ae(s.text) }, `${n}-paragraph`) : s.type === "pre" ? /* @__PURE__ */ a("pre", { children: /* @__PURE__ */ a("code", { children: s.text }) }, `${n}-pre`) : /* @__PURE__ */ a("ul", { children: s.items.map((r, o) => /* @__PURE__ */ a("li", { children: Ae(r) }, `${o}-${r}`)) }, `${n}-list`);
|
|
414
|
+
}) }) : null;
|
|
415
|
+
}, Je = ({ assistantName: e }) => /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-identity", children: [
|
|
416
|
+
/* @__PURE__ */ a(ie, { className: "make-ai-assistant__avatar--message" }),
|
|
388
417
|
/* @__PURE__ */ a("span", { className: "make-ai-assistant__message-sender", children: e })
|
|
389
|
-
] }),
|
|
418
|
+
] }), Qe = (e) => {
|
|
390
419
|
for (let t = e.messages.length - 1; t >= 0; t -= 1) {
|
|
391
420
|
const s = e.messages[t];
|
|
392
421
|
if (s.role === "assistant" && s.status === "streaming")
|
|
393
422
|
return s.id;
|
|
394
423
|
}
|
|
395
|
-
},
|
|
424
|
+
}, Gt = (e) => {
|
|
396
425
|
for (let t = e.messages.length - 1; t >= 0; t -= 1)
|
|
397
426
|
if (e.messages[t].role === "user") return t;
|
|
398
427
|
return -1;
|
|
399
|
-
},
|
|
400
|
-
const t =
|
|
428
|
+
}, Xe = (e) => {
|
|
429
|
+
const t = Gt(e);
|
|
401
430
|
if (!(t < 0))
|
|
402
431
|
for (let s = e.messages.length - 1; s > t; s -= 1) {
|
|
403
|
-
const
|
|
404
|
-
if (
|
|
432
|
+
const n = e.messages[s];
|
|
433
|
+
if (n.role === "assistant") return n.id;
|
|
405
434
|
}
|
|
406
|
-
},
|
|
435
|
+
}, Yt = (e) => {
|
|
407
436
|
if (e.status === "idle")
|
|
408
437
|
for (let t = e.messages.length - 1; t >= 0; t -= 1) {
|
|
409
438
|
const s = e.messages[t];
|
|
410
439
|
if (s.role === "assistant" && s.status === "complete")
|
|
411
440
|
return s.id;
|
|
412
441
|
}
|
|
413
|
-
},
|
|
442
|
+
}, Wt = (e) => {
|
|
414
443
|
for (let t = e.messages.length - 1; t >= 0; t -= 1) {
|
|
415
444
|
const s = e.messages[t];
|
|
416
445
|
if (s.role === "user") return s;
|
|
417
446
|
}
|
|
418
|
-
},
|
|
447
|
+
}, Jt = (e, t) => {
|
|
419
448
|
const s = e.messages.findIndex(
|
|
420
|
-
(
|
|
449
|
+
(n) => n.id === t && n.role === "user"
|
|
421
450
|
);
|
|
422
451
|
return {
|
|
423
452
|
...e,
|
|
@@ -426,7 +455,9 @@ const Fe = (e) => {
|
|
|
426
455
|
status: "streaming",
|
|
427
456
|
messages: s < 0 ? e.messages : e.messages.slice(0, s + 1)
|
|
428
457
|
};
|
|
429
|
-
},
|
|
458
|
+
}, Qt = (e) => e.scrollHeight - e.scrollTop - e.clientHeight <= 48, ze = (e = "smooth") => globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : e, be = (e, t) => {
|
|
459
|
+
typeof e.scrollTo == "function" ? e.scrollTo({ top: e.scrollHeight, behavior: t }) : e.scrollTop = e.scrollHeight;
|
|
460
|
+
}, et = ({
|
|
430
461
|
error: e,
|
|
431
462
|
onRetry: t
|
|
432
463
|
}) => /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-status make-ai-assistant__message-status--error", role: "alert", children: [
|
|
@@ -441,7 +472,7 @@ const Fe = (e) => {
|
|
|
441
472
|
children: "重新发送"
|
|
442
473
|
}
|
|
443
474
|
) : null
|
|
444
|
-
] }),
|
|
475
|
+
] }), tt = ({
|
|
445
476
|
active: e,
|
|
446
477
|
steps: t
|
|
447
478
|
}) => {
|
|
@@ -458,19 +489,19 @@ const Fe = (e) => {
|
|
|
458
489
|
" 步"
|
|
459
490
|
] })
|
|
460
491
|
] }),
|
|
461
|
-
/* @__PURE__ */ a("ol", { children: t.map((
|
|
492
|
+
/* @__PURE__ */ a("ol", { children: t.map((n, r) => /* @__PURE__ */ i(
|
|
462
493
|
"li",
|
|
463
494
|
{
|
|
464
|
-
"data-step-active": e &&
|
|
495
|
+
"data-step-active": e && r === t.length - 1 ? !0 : void 0,
|
|
465
496
|
children: [
|
|
466
497
|
/* @__PURE__ */ a("span", { "aria-hidden": "true" }),
|
|
467
|
-
/* @__PURE__ */ a("span", { children:
|
|
498
|
+
/* @__PURE__ */ a("span", { children: n })
|
|
468
499
|
]
|
|
469
500
|
},
|
|
470
|
-
`${
|
|
501
|
+
`${r}-${n}`
|
|
471
502
|
)) })
|
|
472
503
|
] });
|
|
473
|
-
},
|
|
504
|
+
}, Xt = ({
|
|
474
505
|
copyFeedback: e,
|
|
475
506
|
onCopy: t,
|
|
476
507
|
onRegenerate: s
|
|
@@ -480,18 +511,21 @@ const Fe = (e) => {
|
|
|
480
511
|
{
|
|
481
512
|
"aria-label": "复制回答",
|
|
482
513
|
className: "make-ai-assistant__reply-action make-ai-assistant__reply-copy",
|
|
514
|
+
"data-tooltip": "复制",
|
|
483
515
|
type: "button",
|
|
484
516
|
onClick: t,
|
|
485
|
-
children: /* @__PURE__ */ a(
|
|
517
|
+
children: /* @__PURE__ */ a(Dt, {})
|
|
486
518
|
}
|
|
487
519
|
) : null,
|
|
488
520
|
s ? /* @__PURE__ */ a(
|
|
489
521
|
"button",
|
|
490
522
|
{
|
|
523
|
+
"aria-label": "重新生成",
|
|
491
524
|
className: "make-ai-assistant__reply-action make-ai-assistant__reply-regenerate",
|
|
525
|
+
"data-tooltip": "重新生成",
|
|
492
526
|
type: "button",
|
|
493
527
|
onClick: s,
|
|
494
|
-
children:
|
|
528
|
+
children: /* @__PURE__ */ a(Vt, {})
|
|
495
529
|
}
|
|
496
530
|
) : null,
|
|
497
531
|
e ? /* @__PURE__ */ a(
|
|
@@ -503,572 +537,613 @@ const Fe = (e) => {
|
|
|
503
537
|
children: e.message
|
|
504
538
|
}
|
|
505
539
|
) : null
|
|
506
|
-
] }),
|
|
540
|
+
] }), Oe = ({
|
|
507
541
|
assistantName: e,
|
|
508
542
|
error: t,
|
|
509
543
|
onRetry: s,
|
|
510
|
-
progress:
|
|
544
|
+
progress: n
|
|
511
545
|
}) => {
|
|
512
|
-
const
|
|
513
|
-
return t?.message ??
|
|
546
|
+
const r = t ? "error" : "progress";
|
|
547
|
+
return t?.message ?? n?.message ? /* @__PURE__ */ a(
|
|
514
548
|
"article",
|
|
515
549
|
{
|
|
516
|
-
"aria-label": `${e}的${
|
|
517
|
-
className: `make-ai-assistant__message make-ai-assistant__message--assistant make-ai-assistant__message--${
|
|
550
|
+
"aria-label": `${e}的${r === "error" ? "错误消息" : "状态消息"}`,
|
|
551
|
+
className: `make-ai-assistant__message make-ai-assistant__message--assistant make-ai-assistant__message--${r}`,
|
|
518
552
|
"data-message-role": "assistant",
|
|
519
|
-
"data-message-state":
|
|
553
|
+
"data-message-state": r,
|
|
520
554
|
children: /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-turn", children: [
|
|
521
|
-
/* @__PURE__ */ a(
|
|
522
|
-
/* @__PURE__ */ a("div", { className: "make-ai-assistant__message-stack", children: t ? /* @__PURE__ */ a(
|
|
555
|
+
/* @__PURE__ */ a(Je, { assistantName: e }),
|
|
556
|
+
/* @__PURE__ */ a("div", { className: "make-ai-assistant__message-stack", children: t ? /* @__PURE__ */ a(et, { error: t, onRetry: s }) : /* @__PURE__ */ a(tt, { active: !0, steps: n?.steps }) })
|
|
523
557
|
] })
|
|
524
558
|
}
|
|
525
559
|
) : null;
|
|
526
|
-
},
|
|
527
|
-
const
|
|
528
|
-
let
|
|
529
|
-
return e.messages.map((
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
const
|
|
560
|
+
}, ea = (e, t, s, n, r, o, d, p, f, b, C, $, m) => {
|
|
561
|
+
const B = Xe(e), z = Qe(e), k = Yt(e);
|
|
562
|
+
let D;
|
|
563
|
+
return e.messages.map((u) => {
|
|
564
|
+
const I = u.role === "assistant", V = D;
|
|
565
|
+
I || (D = u);
|
|
566
|
+
const _ = u.id === z, M = u.id === B ? e.error : void 0, E = u.error ?? M, q = !I && !!(p?.trim() || f), U = I ? o : p?.trim() || "用户", ve = I && u.status === "complete" && !E && (u.content.trim() || u.id === k);
|
|
533
567
|
return /* @__PURE__ */ a(
|
|
534
568
|
"article",
|
|
535
569
|
{
|
|
536
|
-
"aria-label": `${
|
|
537
|
-
className: `make-ai-assistant__message make-ai-assistant__message--${
|
|
538
|
-
"data-message-role":
|
|
539
|
-
"data-message-state":
|
|
540
|
-
"data-message-status":
|
|
541
|
-
"data-message-has-identity":
|
|
570
|
+
"aria-label": `${U}的消息`,
|
|
571
|
+
className: `make-ai-assistant__message make-ai-assistant__message--${u.role}`,
|
|
572
|
+
"data-message-role": u.role,
|
|
573
|
+
"data-message-state": E ? "error" : void 0,
|
|
574
|
+
"data-message-status": u.status,
|
|
575
|
+
"data-message-has-identity": I || q ? !0 : void 0,
|
|
542
576
|
children: /* @__PURE__ */ i("div", { className: "make-ai-assistant__message-turn", children: [
|
|
543
|
-
|
|
577
|
+
I ? /* @__PURE__ */ a(Je, { assistantName: o }) : q ? /* @__PURE__ */ a(Ot, { userAvatarUrl: f, userName: p }) : null,
|
|
544
578
|
/* @__PURE__ */ i("div", { className: "make-ai-assistant__message-stack", children: [
|
|
545
|
-
|
|
579
|
+
u.content ? I ? /* @__PURE__ */ a(Zt, { content: u.content }) : /* @__PURE__ */ a("div", { className: "make-ai-assistant__bubble", children: u.content }) : u.status === "streaming" ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__typing", "aria-label": `${o}正在思考`, children: [
|
|
546
580
|
/* @__PURE__ */ a("span", {}),
|
|
547
581
|
/* @__PURE__ */ a("span", {}),
|
|
548
582
|
/* @__PURE__ */ a("span", {})
|
|
549
583
|
] }) : null,
|
|
550
|
-
|
|
551
|
-
|
|
584
|
+
I ? /* @__PURE__ */ a(
|
|
585
|
+
tt,
|
|
552
586
|
{
|
|
553
|
-
active:
|
|
554
|
-
steps:
|
|
587
|
+
active: _ && e.status === "streaming",
|
|
588
|
+
steps: u.progressSteps
|
|
555
589
|
}
|
|
556
590
|
) : null,
|
|
557
|
-
|
|
558
|
-
|
|
591
|
+
E ? /* @__PURE__ */ a(
|
|
592
|
+
et,
|
|
559
593
|
{
|
|
560
|
-
error:
|
|
561
|
-
onRetry:
|
|
594
|
+
error: E,
|
|
595
|
+
onRetry: M ? d : void 0
|
|
562
596
|
}
|
|
563
597
|
) : null,
|
|
564
|
-
|
|
565
|
-
|
|
598
|
+
u.artifacts.map((x) => /* @__PURE__ */ a(
|
|
599
|
+
At,
|
|
566
600
|
{
|
|
567
|
-
artifact:
|
|
601
|
+
artifact: x,
|
|
568
602
|
context: t,
|
|
569
|
-
onAction:
|
|
570
|
-
onActionError:
|
|
603
|
+
onAction: n,
|
|
604
|
+
onActionError: r,
|
|
571
605
|
registry: s
|
|
572
606
|
},
|
|
573
|
-
|
|
607
|
+
x.id
|
|
574
608
|
)),
|
|
575
|
-
|
|
576
|
-
|
|
609
|
+
ve ? /* @__PURE__ */ a(
|
|
610
|
+
Xt,
|
|
577
611
|
{
|
|
578
|
-
copyFeedback:
|
|
579
|
-
message:
|
|
580
|
-
status:
|
|
612
|
+
copyFeedback: b?.messageId === u.id ? {
|
|
613
|
+
message: b.message,
|
|
614
|
+
status: b.status
|
|
581
615
|
} : void 0,
|
|
582
|
-
onCopy:
|
|
583
|
-
onRegenerate:
|
|
616
|
+
onCopy: u.content.trim() ? () => $(u.id, u.content) : void 0,
|
|
617
|
+
onRegenerate: C && u.id === k && V ? () => m({
|
|
584
618
|
userMessage: V,
|
|
585
|
-
assistantMessage:
|
|
619
|
+
assistantMessage: u
|
|
586
620
|
}) : void 0
|
|
587
621
|
}
|
|
588
622
|
) : null
|
|
589
623
|
] })
|
|
590
624
|
] })
|
|
591
625
|
},
|
|
592
|
-
|
|
626
|
+
u.id
|
|
593
627
|
);
|
|
594
628
|
});
|
|
595
629
|
};
|
|
596
|
-
function
|
|
630
|
+
function at({
|
|
597
631
|
assistantName: e = "AI 助手",
|
|
598
632
|
brandName: t,
|
|
599
633
|
context: s,
|
|
600
|
-
onAction:
|
|
601
|
-
onActionError:
|
|
602
|
-
onClose:
|
|
603
|
-
onNewConversation:
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
634
|
+
onAction: n,
|
|
635
|
+
onActionError: r,
|
|
636
|
+
onClose: o,
|
|
637
|
+
onNewConversation: d,
|
|
638
|
+
privacyNotice: p,
|
|
639
|
+
registry: f,
|
|
640
|
+
subtitle: b,
|
|
641
|
+
suggestions: C,
|
|
642
|
+
title: $,
|
|
643
|
+
transport: m,
|
|
644
|
+
userAvatarUrl: B,
|
|
645
|
+
userName: z,
|
|
646
|
+
visible: k
|
|
611
647
|
}) {
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
const [q,
|
|
615
|
-
() =>
|
|
616
|
-
[
|
|
617
|
-
),
|
|
618
|
-
() =>
|
|
619
|
-
[
|
|
620
|
-
),
|
|
621
|
-
const
|
|
622
|
-
return !
|
|
648
|
+
const D = Ye(t, $), u = p?.trim(), [I, V] = R(""), [_, M] = R(ge), E = w(_);
|
|
649
|
+
E.current = _;
|
|
650
|
+
const [q, U] = R(void 0), [ve, x] = R(void 0), [st, nt] = R(0), [O, oe] = R(() => m.loadConversation ? "loading" : "ready"), [rt, L] = R(!1), j = w(void 0), Z = w(void 0), G = w(0), Ie = w(null), te = w(null), Ne = w(null), we = w(null), F = w(!0), Me = w(s.app.id), Te = w(k), Ce = He(
|
|
651
|
+
() => f ?? St(),
|
|
652
|
+
[f]
|
|
653
|
+
), $e = He(
|
|
654
|
+
() => Ft(C),
|
|
655
|
+
[C]
|
|
656
|
+
), ce = (c) => {
|
|
657
|
+
const h = j.current, g = Z.current?.iterator;
|
|
658
|
+
return !h && !g ? !1 : (G.current += 1, j.current = void 0, Z.current = void 0, console.info("[make-ai-assistant] local run cancellation requested", { reason: c }), h?.abort(), Ke(g), !0);
|
|
623
659
|
};
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
}, []),
|
|
627
|
-
const
|
|
628
|
-
if (
|
|
629
|
-
|
|
660
|
+
Q(() => () => {
|
|
661
|
+
ce("unmount");
|
|
662
|
+
}, []), Q(() => {
|
|
663
|
+
const c = m.loadConversation, h = Me.current !== s.app.id;
|
|
664
|
+
if (Me.current = s.app.id, ce("reinitialize"), h && (V(""), F.current = !0), U(void 0), x(void 0), L(!1), M(ge()), !c) {
|
|
665
|
+
oe("ready");
|
|
630
666
|
return;
|
|
631
667
|
}
|
|
632
|
-
const
|
|
633
|
-
return
|
|
668
|
+
const g = new AbortController();
|
|
669
|
+
return oe("loading"), console.info("[make-ai-assistant] conversation load start", {
|
|
634
670
|
appId: s.app.id
|
|
635
|
-
}),
|
|
636
|
-
|
|
671
|
+
}), c.call(m, s, { signal: g.signal }).then((y) => {
|
|
672
|
+
g.signal.aborted || (M(ge(y)), oe("ready"), console.info("[make-ai-assistant] conversation load success", {
|
|
637
673
|
appId: s.app.id,
|
|
638
|
-
messageCount:
|
|
674
|
+
messageCount: y.messages.length
|
|
639
675
|
}));
|
|
640
|
-
}).catch((
|
|
641
|
-
|
|
676
|
+
}).catch((y) => {
|
|
677
|
+
g.signal.aborted || (console.error("[make-ai-assistant] conversation load failed", {
|
|
642
678
|
appId: s.app.id,
|
|
643
|
-
errorType:
|
|
644
|
-
}),
|
|
645
|
-
}), () =>
|
|
646
|
-
}, [s.app.id,
|
|
647
|
-
const
|
|
648
|
-
if (!
|
|
649
|
-
|
|
650
|
-
const
|
|
679
|
+
errorType: y instanceof Error ? y.name : typeof y
|
|
680
|
+
}), oe("error"));
|
|
681
|
+
}), () => g.abort();
|
|
682
|
+
}, [s.app.id, st, m]), Q(() => {
|
|
683
|
+
const c = te.current;
|
|
684
|
+
if (!c || !F.current) return;
|
|
685
|
+
L(!1);
|
|
686
|
+
const h = requestAnimationFrame(() => {
|
|
651
687
|
if (!F.current) return;
|
|
652
|
-
const
|
|
653
|
-
|
|
688
|
+
const g = _.status === "streaming" || globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ? "auto" : "smooth";
|
|
689
|
+
be(c, g);
|
|
690
|
+
});
|
|
691
|
+
return () => cancelAnimationFrame(h);
|
|
692
|
+
}, [_.messages, _.progress, _.status]), Q(() => {
|
|
693
|
+
const c = k && !Te.current;
|
|
694
|
+
if (Te.current = k, !c) return;
|
|
695
|
+
const h = requestAnimationFrame(() => {
|
|
696
|
+
const g = te.current;
|
|
697
|
+
if (g && F.current) {
|
|
698
|
+
L(!1);
|
|
699
|
+
const ae = E.current.status === "streaming" ? "auto" : ze();
|
|
700
|
+
be(g, ae);
|
|
701
|
+
} else g && L(E.current.messages.length > 0);
|
|
702
|
+
const y = Ne.current;
|
|
703
|
+
(y && !y.disabled ? y : we.current ?? Ie.current?.querySelector("button:not(:disabled)"))?.focus();
|
|
654
704
|
});
|
|
655
|
-
return () => cancelAnimationFrame(
|
|
656
|
-
}, [
|
|
657
|
-
const
|
|
658
|
-
const
|
|
659
|
-
if (!
|
|
660
|
-
const
|
|
661
|
-
F.current =
|
|
662
|
-
},
|
|
663
|
-
const
|
|
664
|
-
if (!
|
|
665
|
-
F.current = !0,
|
|
666
|
-
const
|
|
667
|
-
|
|
668
|
-
},
|
|
669
|
-
const
|
|
670
|
-
if (!
|
|
671
|
-
if (
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
) >
|
|
675
|
-
|
|
676
|
-
`输入内容过长,请控制在 ${
|
|
705
|
+
return () => cancelAnimationFrame(h);
|
|
706
|
+
}, [k]);
|
|
707
|
+
const it = () => {
|
|
708
|
+
const c = te.current;
|
|
709
|
+
if (!c) return;
|
|
710
|
+
const h = Qt(c);
|
|
711
|
+
F.current = h, L(!h && E.current.messages.length > 0);
|
|
712
|
+
}, ot = () => {
|
|
713
|
+
const c = te.current;
|
|
714
|
+
if (!c) return;
|
|
715
|
+
F.current = !0, L(!1);
|
|
716
|
+
const h = ze();
|
|
717
|
+
be(c, h);
|
|
718
|
+
}, Ee = async (c, h) => {
|
|
719
|
+
const g = c.trim(), y = E.current, S = h?.regenerateFrom, ae = m.regenerate;
|
|
720
|
+
if (!g || O !== "ready" || y.status === "streaming" || j.current || S && !ae) return;
|
|
721
|
+
if (_e(
|
|
722
|
+
g,
|
|
723
|
+
N.messageCharacters
|
|
724
|
+
) > N.messageCharacters) {
|
|
725
|
+
U(
|
|
726
|
+
`输入内容过长,请控制在 ${N.messageCharacters} 个字符以内`
|
|
677
727
|
);
|
|
678
728
|
return;
|
|
679
729
|
}
|
|
680
|
-
const
|
|
681
|
-
id:
|
|
682
|
-
content:
|
|
683
|
-
},
|
|
684
|
-
|
|
730
|
+
const me = {
|
|
731
|
+
id: S?.userMessage.id ?? Rt("user"),
|
|
732
|
+
content: g
|
|
733
|
+
}, ue = S ? Jt(y, S.userMessage.id) : yt(y, me), pe = new AbortController(), Y = G.current + 1;
|
|
734
|
+
G.current = Y, j.current = pe, U(void 0), x(void 0), L(!F.current && y.messages.length > 0), S || V(""), M(ue);
|
|
685
735
|
try {
|
|
686
|
-
let
|
|
687
|
-
const
|
|
736
|
+
let P = !1, A, xe = 0, Le = 0, Fe = 0, ye = 0, se = 0;
|
|
737
|
+
const ne = /* @__PURE__ */ new Map(), Pe = /* @__PURE__ */ new Set(), Be = /* @__PURE__ */ new Set(
|
|
688
738
|
[
|
|
689
|
-
...
|
|
690
|
-
|
|
739
|
+
...ue.messages.map((he) => he.id),
|
|
740
|
+
me.id
|
|
691
741
|
]
|
|
692
|
-
),
|
|
693
|
-
let
|
|
694
|
-
if (
|
|
695
|
-
if (!
|
|
696
|
-
throw new
|
|
697
|
-
|
|
698
|
-
threadId:
|
|
699
|
-
message:
|
|
742
|
+
), re = /* @__PURE__ */ new Set(), De = vt(Ce), Ve = { signal: pe.signal };
|
|
743
|
+
let ke;
|
|
744
|
+
if (S) {
|
|
745
|
+
if (!ae)
|
|
746
|
+
throw new v("当前 AI 助手不支持重新生成");
|
|
747
|
+
ke = ae({
|
|
748
|
+
threadId: ue.threadId,
|
|
749
|
+
message: me,
|
|
700
750
|
assistantMessage: {
|
|
701
|
-
id:
|
|
702
|
-
content:
|
|
751
|
+
id: S.assistantMessage.id,
|
|
752
|
+
content: S.assistantMessage.content
|
|
703
753
|
},
|
|
704
754
|
context: s,
|
|
705
|
-
capabilities:
|
|
706
|
-
},
|
|
755
|
+
capabilities: De
|
|
756
|
+
}, Ve);
|
|
707
757
|
} else
|
|
708
|
-
|
|
758
|
+
ke = m.run(
|
|
709
759
|
{
|
|
710
|
-
threadId:
|
|
711
|
-
message:
|
|
760
|
+
threadId: ue.threadId,
|
|
761
|
+
message: me,
|
|
712
762
|
context: s,
|
|
713
|
-
capabilities:
|
|
763
|
+
capabilities: De
|
|
714
764
|
},
|
|
715
|
-
|
|
765
|
+
Ve
|
|
716
766
|
);
|
|
717
|
-
const
|
|
718
|
-
for (
|
|
719
|
-
const
|
|
720
|
-
if (
|
|
721
|
-
let
|
|
767
|
+
const qe = ke[Symbol.asyncIterator]();
|
|
768
|
+
for (Z.current = { iterator: qe, requestVersion: Y }; ; ) {
|
|
769
|
+
const he = await qe.next();
|
|
770
|
+
if (G.current !== Y || he.done) break;
|
|
771
|
+
let l;
|
|
722
772
|
try {
|
|
723
|
-
|
|
724
|
-
} catch (
|
|
725
|
-
throw new
|
|
726
|
-
|
|
773
|
+
l = kt(he.value);
|
|
774
|
+
} catch (T) {
|
|
775
|
+
throw new v(
|
|
776
|
+
T instanceof Error ? T.message : "Invalid assistant event"
|
|
727
777
|
);
|
|
728
778
|
}
|
|
729
|
-
if (
|
|
730
|
-
if (A !== void 0 && A !==
|
|
731
|
-
throw new
|
|
732
|
-
if (A ??=
|
|
733
|
-
throw new
|
|
734
|
-
if (
|
|
735
|
-
throw new
|
|
736
|
-
|
|
779
|
+
if (l.type === "message.start") {
|
|
780
|
+
if (A !== void 0 && A !== l.runId)
|
|
781
|
+
throw new v("AI 助手响应 run id 不一致");
|
|
782
|
+
if (A ??= l.runId, Le += 1, Le > N.assistantMessagesPerRun)
|
|
783
|
+
throw new v("AI 助手单次响应消息数量超过限制");
|
|
784
|
+
if (Be.has(l.messageId))
|
|
785
|
+
throw new v("AI 助手响应包含重复的 message id");
|
|
786
|
+
Be.add(l.messageId), re.add(l.messageId), ne.set(l.messageId, 0);
|
|
737
787
|
}
|
|
738
|
-
if (
|
|
739
|
-
if (!
|
|
740
|
-
throw new
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
788
|
+
if (l.type === "message.delta") {
|
|
789
|
+
if (!re.has(l.messageId))
|
|
790
|
+
throw new v("AI 助手响应事件顺序无效");
|
|
791
|
+
const T = ne.get(l.messageId) ?? 0, W = _e(
|
|
792
|
+
l.delta,
|
|
793
|
+
N.messageCharacters - se
|
|
744
794
|
);
|
|
745
|
-
if (
|
|
746
|
-
throw new
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
795
|
+
if (se + W > N.messageCharacters)
|
|
796
|
+
throw new v("AI 助手响应文本超过大小限制");
|
|
797
|
+
se += W, ne.set(
|
|
798
|
+
l.messageId,
|
|
799
|
+
T + W
|
|
750
800
|
);
|
|
751
801
|
}
|
|
752
|
-
if (
|
|
753
|
-
if (!
|
|
754
|
-
throw new
|
|
755
|
-
const
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
),
|
|
759
|
-
if (
|
|
760
|
-
throw new
|
|
761
|
-
|
|
802
|
+
if (l.type === "message.replace") {
|
|
803
|
+
if (!re.has(l.messageId))
|
|
804
|
+
throw new v("AI 助手响应事件顺序无效");
|
|
805
|
+
const T = ne.get(l.messageId) ?? 0, W = _e(
|
|
806
|
+
l.content,
|
|
807
|
+
N.messageCharacters
|
|
808
|
+
), Ue = se - T + W;
|
|
809
|
+
if (Ue > N.messageCharacters)
|
|
810
|
+
throw new v("AI 助手响应文本超过大小限制");
|
|
811
|
+
se = Ue, ne.set(l.messageId, W);
|
|
762
812
|
}
|
|
763
|
-
if (
|
|
764
|
-
if (A !== void 0 && A !==
|
|
765
|
-
throw new
|
|
766
|
-
if (A ??=
|
|
767
|
-
throw new
|
|
768
|
-
const
|
|
769
|
-
|
|
770
|
-
|
|
813
|
+
if (l.type === "run.progress") {
|
|
814
|
+
if (A !== void 0 && A !== l.runId)
|
|
815
|
+
throw new v("AI 助手响应 run id 不一致");
|
|
816
|
+
if (A ??= l.runId, Fe += 1, Fe > N.progressStepsPerRun)
|
|
817
|
+
throw new v("AI 助手处理过程数量超过限制");
|
|
818
|
+
const T = _e(
|
|
819
|
+
l.message,
|
|
820
|
+
N.progressCharactersPerRun - ye
|
|
771
821
|
);
|
|
772
|
-
if (
|
|
773
|
-
throw new
|
|
774
|
-
|
|
822
|
+
if (ye + T > N.progressCharactersPerRun)
|
|
823
|
+
throw new v("AI 助手处理过程文本超过大小限制");
|
|
824
|
+
ye += T;
|
|
775
825
|
}
|
|
776
|
-
if (
|
|
777
|
-
if (!
|
|
778
|
-
throw new
|
|
779
|
-
if (
|
|
780
|
-
throw new
|
|
781
|
-
if (
|
|
782
|
-
throw new
|
|
783
|
-
|
|
826
|
+
if (l.type === "artifact") {
|
|
827
|
+
if (!re.has(l.messageId))
|
|
828
|
+
throw new v("AI 助手响应事件顺序无效");
|
|
829
|
+
if (xe += 1, xe > N.artifactsPerRun)
|
|
830
|
+
throw new v("AI 助手单次响应 Artifact 数量超过限制");
|
|
831
|
+
if (Pe.has(l.artifact.id))
|
|
832
|
+
throw new v("AI 助手响应包含重复的 Artifact id");
|
|
833
|
+
Pe.add(l.artifact.id);
|
|
784
834
|
}
|
|
785
|
-
if (
|
|
786
|
-
throw new
|
|
787
|
-
if (
|
|
788
|
-
throw new
|
|
789
|
-
if (
|
|
790
|
-
throw new
|
|
791
|
-
if (
|
|
792
|
-
|
|
835
|
+
if (l.type === "message.complete" && !re.delete(l.messageId))
|
|
836
|
+
throw new v("AI 助手响应事件顺序无效");
|
|
837
|
+
if (l.type === "run.complete" && A !== void 0 && A !== l.runId)
|
|
838
|
+
throw new v("AI 助手响应 run id 不一致");
|
|
839
|
+
if (l.type === "run.cancelled" && l.runId !== void 0 && A !== void 0 && A !== l.runId)
|
|
840
|
+
throw new v("AI 助手响应 run id 不一致");
|
|
841
|
+
if (M((T) => fe(T, l)), l.type === "error" || l.type === "run.cancelled" || l.type === "run.complete") {
|
|
842
|
+
P = !0;
|
|
793
843
|
break;
|
|
794
844
|
}
|
|
795
845
|
}
|
|
796
|
-
if (!
|
|
797
|
-
throw new
|
|
798
|
-
} catch (
|
|
799
|
-
if (
|
|
800
|
-
if (
|
|
801
|
-
|
|
802
|
-
(A) =>
|
|
846
|
+
if (!P)
|
|
847
|
+
throw new v("AI 助手流式响应在终止事件前结束");
|
|
848
|
+
} catch (P) {
|
|
849
|
+
if (G.current !== Y) return;
|
|
850
|
+
if (pe.signal.aborted) {
|
|
851
|
+
M(
|
|
852
|
+
(A) => fe(A, { type: "run.cancelled" })
|
|
803
853
|
);
|
|
804
854
|
return;
|
|
805
855
|
}
|
|
806
856
|
console.error("[make-ai-assistant] assistant run failed", {
|
|
807
857
|
appId: s.app.id,
|
|
808
|
-
errorType:
|
|
809
|
-
}),
|
|
810
|
-
(A) =>
|
|
858
|
+
errorType: P instanceof Error ? P.name : typeof P
|
|
859
|
+
}), M(
|
|
860
|
+
(A) => fe(A, {
|
|
811
861
|
type: "error",
|
|
812
862
|
code: "TRANSPORT_ERROR",
|
|
813
|
-
message:
|
|
863
|
+
message: P instanceof v ? P.message : "连接失败,请重试",
|
|
814
864
|
retryable: !0
|
|
815
865
|
})
|
|
816
866
|
);
|
|
817
867
|
} finally {
|
|
818
|
-
|
|
868
|
+
G.current === Y && j.current === pe && (j.current = void 0), Z.current?.requestVersion === Y && (Ke(Z.current.iterator), Z.current = void 0);
|
|
819
869
|
}
|
|
820
|
-
},
|
|
870
|
+
}, le = (c) => Ee(c), ct = (c) => Ee(c.userMessage.content, { regenerateFrom: c }), lt = async (c, h) => {
|
|
821
871
|
try {
|
|
822
|
-
await
|
|
823
|
-
} catch (
|
|
872
|
+
await Pt(h), x({ messageId: c, message: "已复制", status: "success" });
|
|
873
|
+
} catch (g) {
|
|
824
874
|
console.error("[make-ai-assistant] copy answer failed", {
|
|
825
|
-
errorType:
|
|
826
|
-
}),
|
|
875
|
+
errorType: g instanceof Error ? g.name : typeof g
|
|
876
|
+
}), x({ messageId: c, message: "复制失败", status: "error" });
|
|
827
877
|
}
|
|
828
|
-
},
|
|
829
|
-
|
|
830
|
-
},
|
|
831
|
-
|
|
832
|
-
},
|
|
833
|
-
|
|
834
|
-
(
|
|
878
|
+
}, dt = (c) => {
|
|
879
|
+
c.preventDefault(), le(I);
|
|
880
|
+
}, mt = (c) => {
|
|
881
|
+
c.key === "Enter" && !c.shiftKey && !c.nativeEvent.isComposing && (c.preventDefault(), le(I));
|
|
882
|
+
}, ut = () => {
|
|
883
|
+
ce("stop") && M(
|
|
884
|
+
(c) => fe(c, { type: "run.cancelled" })
|
|
835
885
|
);
|
|
836
|
-
},
|
|
837
|
-
|
|
838
|
-
},
|
|
839
|
-
|
|
886
|
+
}, pt = () => {
|
|
887
|
+
ce("new-conversation"), V(""), U(void 0), x(void 0), L(!1), F.current = !0, M(ge()), d?.();
|
|
888
|
+
}, Se = m.features?.remoteCancellation === !1 ? "停止接收" : "停止生成", ht = Qe(_), gt = Xe(_), de = Wt(_), ft = typeof m.regenerate == "function" && m.features?.regeneration !== !1, Re = () => {
|
|
889
|
+
de && le(de.content);
|
|
840
890
|
};
|
|
841
|
-
return /* @__PURE__ */ i(
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
891
|
+
return /* @__PURE__ */ i(
|
|
892
|
+
"section",
|
|
893
|
+
{
|
|
894
|
+
className: "make-ai-assistant make-ai-assistant__panel",
|
|
895
|
+
ref: Ie,
|
|
896
|
+
children: [
|
|
897
|
+
/* @__PURE__ */ i("header", { className: "make-ai-assistant__header", children: [
|
|
898
|
+
/* @__PURE__ */ a(ie, {}),
|
|
899
|
+
/* @__PURE__ */ i("div", { children: [
|
|
900
|
+
/* @__PURE__ */ a("h2", { children: D }),
|
|
901
|
+
/* @__PURE__ */ a("p", { children: b ?? `当前应用:${s.app.name ?? "未命名应用"}` })
|
|
902
|
+
] }),
|
|
903
|
+
/* @__PURE__ */ i("div", { className: "make-ai-assistant__header-actions", children: [
|
|
904
|
+
m.features?.newConversation !== !1 ? /* @__PURE__ */ a(
|
|
905
|
+
"button",
|
|
906
|
+
{
|
|
907
|
+
"aria-label": "新建对话",
|
|
908
|
+
className: "make-ai-assistant__icon-button",
|
|
909
|
+
type: "button",
|
|
910
|
+
onClick: pt,
|
|
911
|
+
children: /* @__PURE__ */ a(Ht, {})
|
|
912
|
+
}
|
|
913
|
+
) : null,
|
|
914
|
+
o ? /* @__PURE__ */ a(
|
|
915
|
+
"button",
|
|
916
|
+
{
|
|
917
|
+
"aria-label": `关闭 ${D}`,
|
|
918
|
+
className: "make-ai-assistant__icon-button",
|
|
919
|
+
type: "button",
|
|
920
|
+
onClick: o,
|
|
921
|
+
children: /* @__PURE__ */ a(Bt, {})
|
|
922
|
+
}
|
|
923
|
+
) : null
|
|
924
|
+
] })
|
|
925
|
+
] }),
|
|
926
|
+
u ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__privacy-note", role: "note", children: [
|
|
927
|
+
/* @__PURE__ */ a("span", { className: "make-ai-assistant__privacy-icon", "aria-hidden": "true", children: /* @__PURE__ */ a(qt, {}) }),
|
|
928
|
+
/* @__PURE__ */ a("span", { children: u })
|
|
929
|
+
] }) : null,
|
|
930
|
+
/* @__PURE__ */ i(
|
|
931
|
+
"div",
|
|
851
932
|
{
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
933
|
+
className: "make-ai-assistant__body",
|
|
934
|
+
"aria-live": "polite",
|
|
935
|
+
"aria-relevant": "additions text",
|
|
936
|
+
ref: te,
|
|
937
|
+
role: "log",
|
|
938
|
+
onScroll: it,
|
|
939
|
+
children: [
|
|
940
|
+
O === "loading" ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__empty", role: "status", children: [
|
|
941
|
+
/* @__PURE__ */ a(ie, {}),
|
|
942
|
+
/* @__PURE__ */ a("h3", { children: "正在恢复对话" }),
|
|
943
|
+
/* @__PURE__ */ a("p", { children: "正在读取当前 App 的历史消息…" })
|
|
944
|
+
] }) : O === "error" ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__empty", role: "alert", children: [
|
|
945
|
+
/* @__PURE__ */ a(ie, {}),
|
|
946
|
+
/* @__PURE__ */ a("h3", { children: "暂时无法加载对话" }),
|
|
947
|
+
/* @__PURE__ */ a("p", { children: "请检查网络后重试。" }),
|
|
948
|
+
/* @__PURE__ */ a(
|
|
949
|
+
"button",
|
|
950
|
+
{
|
|
951
|
+
className: "make-ai-assistant__retry",
|
|
952
|
+
type: "button",
|
|
953
|
+
onClick: () => nt((c) => c + 1),
|
|
954
|
+
children: "重新加载"
|
|
955
|
+
}
|
|
956
|
+
)
|
|
957
|
+
] }) : _.messages.length === 0 ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__empty", children: [
|
|
958
|
+
/* @__PURE__ */ a(ie, {}),
|
|
959
|
+
/* @__PURE__ */ a("h3", { children: "有什么可以帮你?" }),
|
|
960
|
+
/* @__PURE__ */ a("p", { children: "我会结合当前 App、页面位置和宿主允许的上下文回答,并把过程与结果分开展示。" })
|
|
961
|
+
] }) : ea(
|
|
962
|
+
_,
|
|
963
|
+
s,
|
|
964
|
+
Ce,
|
|
965
|
+
n,
|
|
966
|
+
r,
|
|
967
|
+
e,
|
|
968
|
+
de ? Re : void 0,
|
|
969
|
+
z,
|
|
970
|
+
B,
|
|
971
|
+
ve,
|
|
972
|
+
ft,
|
|
973
|
+
(c, h) => {
|
|
974
|
+
lt(c, h);
|
|
975
|
+
},
|
|
976
|
+
(c) => {
|
|
977
|
+
ct(c);
|
|
978
|
+
}
|
|
979
|
+
),
|
|
980
|
+
_.progress && !ht ? /* @__PURE__ */ a(
|
|
981
|
+
Oe,
|
|
982
|
+
{
|
|
983
|
+
assistantName: e,
|
|
984
|
+
progress: _.progress
|
|
985
|
+
}
|
|
986
|
+
) : null,
|
|
987
|
+
_.error && !gt ? /* @__PURE__ */ a(
|
|
988
|
+
Oe,
|
|
989
|
+
{
|
|
990
|
+
assistantName: e,
|
|
991
|
+
error: _.error,
|
|
992
|
+
onRetry: de ? Re : void 0
|
|
993
|
+
}
|
|
994
|
+
) : null
|
|
995
|
+
]
|
|
857
996
|
}
|
|
858
|
-
)
|
|
859
|
-
|
|
997
|
+
),
|
|
998
|
+
rt ? /* @__PURE__ */ a(
|
|
860
999
|
"button",
|
|
861
1000
|
{
|
|
862
|
-
"aria-label":
|
|
863
|
-
className: "make-ai-
|
|
1001
|
+
"aria-label": "回到最新消息",
|
|
1002
|
+
className: "make-ai-assistant__back-to-latest",
|
|
864
1003
|
type: "button",
|
|
865
|
-
onClick:
|
|
866
|
-
children: /* @__PURE__ */ a(
|
|
1004
|
+
onClick: ot,
|
|
1005
|
+
children: /* @__PURE__ */ a(Ut, {})
|
|
867
1006
|
}
|
|
868
|
-
) : null
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
role: "log",
|
|
883
|
-
onScroll: Ye,
|
|
884
|
-
children: [
|
|
885
|
-
M === "loading" ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__empty", role: "status", children: [
|
|
886
|
-
/* @__PURE__ */ a(te, {}),
|
|
887
|
-
/* @__PURE__ */ a("h3", { children: "正在恢复对话" }),
|
|
888
|
-
/* @__PURE__ */ a("p", { children: "正在读取当前 App 的历史消息…" })
|
|
889
|
-
] }) : M === "error" ? /* @__PURE__ */ i("div", { className: "make-ai-assistant__empty", role: "alert", children: [
|
|
890
|
-
/* @__PURE__ */ a(te, {}),
|
|
891
|
-
/* @__PURE__ */ a("h3", { children: "暂时无法加载对话" }),
|
|
892
|
-
/* @__PURE__ */ a("p", { children: "请检查网络后重试。" }),
|
|
1007
|
+
) : null,
|
|
1008
|
+
/* @__PURE__ */ i("footer", { className: "make-ai-assistant__composer-region", children: [
|
|
1009
|
+
O === "ready" && $e.length > 0 && _.messages.length === 0 ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__suggestions", "aria-label": "推荐问题", children: $e.map((c, h) => /* @__PURE__ */ a(
|
|
1010
|
+
"button",
|
|
1011
|
+
{
|
|
1012
|
+
type: "button",
|
|
1013
|
+
onClick: () => {
|
|
1014
|
+
le(c);
|
|
1015
|
+
},
|
|
1016
|
+
children: c
|
|
1017
|
+
},
|
|
1018
|
+
`${h}-${c}`
|
|
1019
|
+
)) }) : null,
|
|
1020
|
+
/* @__PURE__ */ i("form", { className: "make-ai-assistant__composer", onSubmit: dt, children: [
|
|
893
1021
|
/* @__PURE__ */ a(
|
|
1022
|
+
"textarea",
|
|
1023
|
+
{
|
|
1024
|
+
"aria-label": `向 ${e} 提问`,
|
|
1025
|
+
"aria-describedby": q ? "make-ai-composer-error" : void 0,
|
|
1026
|
+
"aria-invalid": q ? !0 : void 0,
|
|
1027
|
+
autoFocus: !0,
|
|
1028
|
+
disabled: O !== "ready" || _.status === "streaming",
|
|
1029
|
+
placeholder: `询问当前 ${s.app.name ?? "App"} 中的数据…`,
|
|
1030
|
+
ref: Ne,
|
|
1031
|
+
rows: 2,
|
|
1032
|
+
value: I,
|
|
1033
|
+
onChange: (c) => {
|
|
1034
|
+
V(c.currentTarget.value), U(void 0);
|
|
1035
|
+
},
|
|
1036
|
+
onKeyDown: mt
|
|
1037
|
+
}
|
|
1038
|
+
),
|
|
1039
|
+
_.status === "streaming" ? /* @__PURE__ */ a(
|
|
894
1040
|
"button",
|
|
895
1041
|
{
|
|
896
|
-
|
|
1042
|
+
"aria-label": Se,
|
|
1043
|
+
className: "make-ai-assistant__send make-ai-assistant__send--stop",
|
|
1044
|
+
"data-tooltip": Se,
|
|
1045
|
+
ref: we,
|
|
897
1046
|
type: "button",
|
|
898
|
-
onClick:
|
|
899
|
-
children: "
|
|
1047
|
+
onClick: ut,
|
|
1048
|
+
children: /* @__PURE__ */ a("span", { "aria-hidden": "true" })
|
|
1049
|
+
}
|
|
1050
|
+
) : /* @__PURE__ */ a(
|
|
1051
|
+
"button",
|
|
1052
|
+
{
|
|
1053
|
+
"aria-label": "发送",
|
|
1054
|
+
className: "make-ai-assistant__send",
|
|
1055
|
+
disabled: O !== "ready" || !I.trim(),
|
|
1056
|
+
type: "submit",
|
|
1057
|
+
children: /* @__PURE__ */ a(Kt, {})
|
|
900
1058
|
}
|
|
901
1059
|
)
|
|
902
|
-
] })
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
Ae,
|
|
910
|
-
r,
|
|
911
|
-
o,
|
|
912
|
-
e,
|
|
913
|
-
ie ? Ne : void 0,
|
|
914
|
-
w,
|
|
915
|
-
D,
|
|
916
|
-
H,
|
|
917
|
-
it,
|
|
918
|
-
(n, g) => {
|
|
919
|
-
Qe(n, g);
|
|
920
|
-
},
|
|
921
|
-
(n) => {
|
|
922
|
-
Je(n);
|
|
923
|
-
}
|
|
924
|
-
),
|
|
925
|
-
l.progress && !nt ? /* @__PURE__ */ a(
|
|
926
|
-
Be,
|
|
927
|
-
{
|
|
928
|
-
assistantName: e,
|
|
929
|
-
progress: l.progress
|
|
930
|
-
}
|
|
931
|
-
) : null,
|
|
932
|
-
l.error && !rt ? /* @__PURE__ */ a(
|
|
933
|
-
Be,
|
|
934
|
-
{
|
|
935
|
-
assistantName: e,
|
|
936
|
-
error: l.error,
|
|
937
|
-
onRetry: ie ? Ne : void 0
|
|
938
|
-
}
|
|
939
|
-
) : null
|
|
940
|
-
]
|
|
941
|
-
}
|
|
942
|
-
),
|
|
943
|
-
Ge ? /* @__PURE__ */ a(
|
|
944
|
-
"button",
|
|
945
|
-
{
|
|
946
|
-
"aria-label": "回到最新消息",
|
|
947
|
-
className: "make-ai-assistant__back-to-latest",
|
|
948
|
-
type: "button",
|
|
949
|
-
onClick: We,
|
|
950
|
-
children: /* @__PURE__ */ a(Et, {})
|
|
951
|
-
}
|
|
952
|
-
) : null,
|
|
953
|
-
/* @__PURE__ */ i("footer", { className: "make-ai-assistant__composer-region", children: [
|
|
954
|
-
M === "ready" && be.length > 0 && l.messages.length === 0 ? /* @__PURE__ */ a("div", { className: "make-ai-assistant__suggestions", "aria-label": "推荐问题", children: be.map((n, g) => /* @__PURE__ */ a(
|
|
955
|
-
"button",
|
|
956
|
-
{
|
|
957
|
-
type: "button",
|
|
958
|
-
onClick: () => {
|
|
959
|
-
re(n);
|
|
960
|
-
},
|
|
961
|
-
children: n
|
|
962
|
-
},
|
|
963
|
-
`${g}-${n}`
|
|
964
|
-
)) }) : null,
|
|
965
|
-
/* @__PURE__ */ i("form", { className: "make-ai-assistant__composer", onSubmit: Xe, children: [
|
|
966
|
-
/* @__PURE__ */ a(
|
|
967
|
-
"textarea",
|
|
968
|
-
{
|
|
969
|
-
"aria-label": `向 ${e} 提问`,
|
|
970
|
-
"aria-describedby": q ? "make-ai-composer-error" : void 0,
|
|
971
|
-
"aria-invalid": q ? !0 : void 0,
|
|
972
|
-
autoFocus: !0,
|
|
973
|
-
disabled: M !== "ready" || l.status === "streaming",
|
|
974
|
-
placeholder: `询问当前 ${s.app.name ?? "App"} 中的数据…`,
|
|
975
|
-
rows: 2,
|
|
976
|
-
value: x,
|
|
977
|
-
onChange: (n) => {
|
|
978
|
-
L(n.currentTarget.value), T(void 0);
|
|
979
|
-
},
|
|
980
|
-
onKeyDown: et
|
|
981
|
-
}
|
|
982
|
-
),
|
|
983
|
-
l.status === "streaming" ? /* @__PURE__ */ a(
|
|
984
|
-
"button",
|
|
985
|
-
{
|
|
986
|
-
"aria-label": st,
|
|
987
|
-
className: "make-ai-assistant__send make-ai-assistant__send--stop",
|
|
988
|
-
type: "button",
|
|
989
|
-
onClick: tt,
|
|
990
|
-
children: /* @__PURE__ */ a("span", { "aria-hidden": "true" })
|
|
991
|
-
}
|
|
992
|
-
) : /* @__PURE__ */ a(
|
|
993
|
-
"button",
|
|
994
|
-
{
|
|
995
|
-
"aria-label": "发送",
|
|
996
|
-
className: "make-ai-assistant__send",
|
|
997
|
-
disabled: M !== "ready" || !x.trim(),
|
|
998
|
-
type: "submit",
|
|
999
|
-
children: /* @__PURE__ */ a(Rt, {})
|
|
1000
|
-
}
|
|
1001
|
-
)
|
|
1002
|
-
] }),
|
|
1003
|
-
q ? /* @__PURE__ */ a("p", { id: "make-ai-composer-error", role: "alert", children: q }) : null,
|
|
1004
|
-
/* @__PURE__ */ a("p", { children: "AI 生成的结果可能存在偏差,重要数据请核对明细。" })
|
|
1005
|
-
] })
|
|
1006
|
-
] });
|
|
1060
|
+
] }),
|
|
1061
|
+
q ? /* @__PURE__ */ a("p", { id: "make-ai-composer-error", role: "alert", children: q }) : null,
|
|
1062
|
+
/* @__PURE__ */ a("p", { children: "AI 生成的结果可能存在偏差,重要数据请核对明细。" })
|
|
1063
|
+
] })
|
|
1064
|
+
]
|
|
1065
|
+
}
|
|
1066
|
+
);
|
|
1007
1067
|
}
|
|
1008
|
-
function
|
|
1068
|
+
function ra(e) {
|
|
1069
|
+
return /* @__PURE__ */ a(at, { ...e, visible: !0 });
|
|
1070
|
+
}
|
|
1071
|
+
function ia({
|
|
1009
1072
|
defaultOpen: e = !1,
|
|
1010
1073
|
hideLauncher: t = !1,
|
|
1011
1074
|
launcher: s,
|
|
1012
|
-
onOpenChange:
|
|
1013
|
-
open:
|
|
1014
|
-
...
|
|
1075
|
+
onOpenChange: n,
|
|
1076
|
+
open: r,
|
|
1077
|
+
...o
|
|
1015
1078
|
}) {
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1079
|
+
const d = Ye(o.brandName, o.title), [p, f] = R(e), [b, C] = R(
|
|
1080
|
+
() => e || r === !0
|
|
1081
|
+
), $ = w(null), m = r ?? p, B = (k) => {
|
|
1082
|
+
r === void 0 && f(k), n?.(k), k || requestAnimationFrame(() => $.current?.focus());
|
|
1083
|
+
}, z = () => B(!m);
|
|
1084
|
+
return Q(() => {
|
|
1085
|
+
m && C(!0);
|
|
1086
|
+
}, [m]), Q(() => {
|
|
1087
|
+
if (!m) return;
|
|
1088
|
+
const k = (D) => {
|
|
1089
|
+
D.key === "Escape" && (B(!1), requestAnimationFrame(() => $.current?.focus()));
|
|
1023
1090
|
};
|
|
1024
|
-
return document.addEventListener("keydown",
|
|
1025
|
-
}, [
|
|
1026
|
-
!t && (!
|
|
1091
|
+
return document.addEventListener("keydown", k), () => document.removeEventListener("keydown", k);
|
|
1092
|
+
}, [n, m]), /* @__PURE__ */ i("div", { className: "make-ai-assistant", "data-open": m || void 0, children: [
|
|
1093
|
+
!t && (!m || s) ? s ? s({ open: m, toggle: z }) : /* @__PURE__ */ i(
|
|
1027
1094
|
"button",
|
|
1028
1095
|
{
|
|
1029
|
-
"aria-label":
|
|
1030
|
-
"aria-expanded":
|
|
1096
|
+
"aria-label": m ? `关闭 ${d}` : `打开 ${d}`,
|
|
1097
|
+
"aria-expanded": m,
|
|
1031
1098
|
className: "make-ai-assistant__launcher",
|
|
1032
|
-
ref:
|
|
1099
|
+
ref: $,
|
|
1033
1100
|
type: "button",
|
|
1034
|
-
onClick:
|
|
1101
|
+
onClick: z,
|
|
1035
1102
|
children: [
|
|
1036
1103
|
/* @__PURE__ */ a("span", { className: "make-ai-assistant__launcher-orbit", "aria-hidden": "true" }),
|
|
1037
|
-
/* @__PURE__ */ a(
|
|
1104
|
+
/* @__PURE__ */ a(We, {})
|
|
1038
1105
|
]
|
|
1039
1106
|
}
|
|
1040
1107
|
) : null,
|
|
1041
|
-
|
|
1108
|
+
b ? /* @__PURE__ */ a(
|
|
1042
1109
|
"aside",
|
|
1043
1110
|
{
|
|
1044
|
-
"aria-label":
|
|
1111
|
+
"aria-label": d,
|
|
1045
1112
|
"aria-modal": "false",
|
|
1046
1113
|
className: "make-ai-assistant__drawer",
|
|
1114
|
+
hidden: !m,
|
|
1047
1115
|
role: "dialog",
|
|
1048
|
-
children: /* @__PURE__ */ a(
|
|
1116
|
+
children: /* @__PURE__ */ a(
|
|
1117
|
+
at,
|
|
1118
|
+
{
|
|
1119
|
+
...o,
|
|
1120
|
+
onClose: () => B(!1),
|
|
1121
|
+
visible: m
|
|
1122
|
+
}
|
|
1123
|
+
)
|
|
1049
1124
|
}
|
|
1050
1125
|
) : null
|
|
1051
1126
|
] });
|
|
1052
1127
|
}
|
|
1053
1128
|
export {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1129
|
+
At as ArtifactRenderer,
|
|
1130
|
+
ra as AssistantPanel,
|
|
1131
|
+
ma as MAKE_AI_ARTIFACT_KINDS,
|
|
1132
|
+
ua as MAKE_AI_ARTIFACT_LIMITS,
|
|
1133
|
+
pa as MAKE_AI_ARTIFACT_SCHEMA_VERSION,
|
|
1134
|
+
N as MAKE_AI_CONVERSATION_LIMITS,
|
|
1135
|
+
ia as MakeAiAssistant,
|
|
1136
|
+
yt as appendUserMessage,
|
|
1137
|
+
vt as createArtifactCapabilities,
|
|
1138
|
+
je as createArtifactTemplateRegistry,
|
|
1139
|
+
ge as createAssistantConversationState,
|
|
1140
|
+
St as createPlatformArtifactRegistry,
|
|
1141
|
+
la as extendArtifactTemplateRegistry,
|
|
1142
|
+
K as formatArtifactValue,
|
|
1143
|
+
ha as parseArtifact,
|
|
1144
|
+
kt as parseAssistantEvent,
|
|
1145
|
+
Et as platformArtifactTemplates,
|
|
1146
|
+
fe as reduceAssistantEvent,
|
|
1147
|
+
_t as resolveArtifactTemplate,
|
|
1148
|
+
ga as validateArtifact
|
|
1074
1149
|
};
|