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