@qfei-design/make-ai-assistant 0.2.13 → 0.2.14
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 -19
- package/README.md +18 -12
- package/capabilities.json +2 -1
- package/dist/client-protocol.d.ts +24 -0
- package/dist/client-types.d.ts +420 -0
- package/dist/client.cjs +2 -0
- package/dist/client.d.ts +18 -0
- package/dist/client.mjs +1154 -0
- package/dist/conversation-BpmWa2VL.cjs +1 -0
- package/dist/conversation-DuqMadaQ.js +888 -0
- package/dist/conversation-management-DZROhXyK.js +229 -0
- package/dist/conversation-management-f1y0yRvt.cjs +1 -0
- package/dist/core/conversation-management.d.ts +15 -5
- package/dist/core/conversation.d.ts +6 -5
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +4 -4
- package/dist/make-app.cjs +1 -1
- package/dist/make-app.d.ts +8 -69
- package/dist/make-app.mjs +236 -703
- package/dist/make-console.cjs +1 -1
- package/dist/make-console.mjs +1 -1
- package/dist/react/make-ai-assistant.d.ts +1 -2
- package/dist/react/use-attachments.d.ts +2 -1
- package/dist/react/use-conversation-manager.d.ts +1 -0
- package/dist/react.cjs +62 -4
- package/dist/react.mjs +3048 -1815
- package/dist/sse.cjs +1 -1
- package/dist/sse.mjs +1 -1
- package/dist/styles.css +288 -105
- package/docs/backend-contract.md +3 -7
- package/docs/make-app-integration.md +23 -68
- package/examples/make-app/main.tsx +1 -1
- package/examples/make-app/transport.ts +36 -146
- package/package.ai.json +9 -6
- package/package.json +11 -3
- package/recipes.json +4 -3
- package/dist/conversation-CZfbgCXd.js +0 -1111
- package/dist/conversation-Cvh-IVRV.cjs +0 -1
- package/dist/make-app/protocol.d.ts +0 -27
- package/dist/make-app/stream.d.ts +0 -20
|
@@ -1,1111 +0,0 @@
|
|
|
1
|
-
const j = (t, e) => {
|
|
2
|
-
let s = 0;
|
|
3
|
-
for (const n of t)
|
|
4
|
-
if (s += 1, s > e) break;
|
|
5
|
-
return s;
|
|
6
|
-
}, Pt = "1.0", m = {
|
|
7
|
-
actions: 10,
|
|
8
|
-
comparisonItems: 24,
|
|
9
|
-
jsonCharacters: 1e6,
|
|
10
|
-
jsonDepth: 64,
|
|
11
|
-
jsonNodes: 1e4,
|
|
12
|
-
rankingItems: 50,
|
|
13
|
-
recordColumns: 20,
|
|
14
|
-
recordListRecords: 100,
|
|
15
|
-
recordValues: 100,
|
|
16
|
-
textCharacters: 2e4,
|
|
17
|
-
trendPointsPerSeries: 120,
|
|
18
|
-
trendSeries: 8,
|
|
19
|
-
validationIssues: 100
|
|
20
|
-
}, f = {
|
|
21
|
-
artifactsPerRun: 50,
|
|
22
|
-
assistantMessagesPerRun: 20,
|
|
23
|
-
historyArtifacts: 500,
|
|
24
|
-
historyCharacters: 1e6,
|
|
25
|
-
historyMessages: 200,
|
|
26
|
-
identifierCharacters: 1e3,
|
|
27
|
-
messageCharacters: 1e5,
|
|
28
|
-
progressCharactersPerRun: 2e4,
|
|
29
|
-
progressStepsPerRun: 50
|
|
30
|
-
}, Z = [
|
|
31
|
-
"metric",
|
|
32
|
-
"comparison",
|
|
33
|
-
"trend",
|
|
34
|
-
"ranking",
|
|
35
|
-
"record-list",
|
|
36
|
-
"notice"
|
|
37
|
-
], M = () => ({
|
|
38
|
-
success: !1,
|
|
39
|
-
issues: [{ path: "", message: "could not be safely inspected" }]
|
|
40
|
-
}), tt = /* @__PURE__ */ new Set(["navigate", "open-record", "open-list", "invoke"]), et = /* @__PURE__ */ new Set(["decimal", "currency", "percent"]);
|
|
41
|
-
class z extends Array {
|
|
42
|
-
push(...e) {
|
|
43
|
-
const s = m.validationIssues - this.length;
|
|
44
|
-
return s > 0 ? super.push(...e.slice(0, s)) : this.length;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const u = (t) => (() => {
|
|
48
|
-
if (typeof t != "object" || t === null || Array.isArray(t))
|
|
49
|
-
return !1;
|
|
50
|
-
const e = Object.getPrototypeOf(t);
|
|
51
|
-
return e === Object.prototype || e === null;
|
|
52
|
-
})(), U = (t) => typeof t == "string" && t.trim().length > 0, Y = (t, e) => {
|
|
53
|
-
let s = 0;
|
|
54
|
-
for (const n of t)
|
|
55
|
-
if (s += 1, s > e) return s;
|
|
56
|
-
return s;
|
|
57
|
-
}, A = (t) => typeof t == "string" && Y(t, m.textCharacters) <= m.textCharacters, R = (t) => typeof t == "number" && Number.isFinite(t), st = (t) => t.length <= 120 ? t : `${t.slice(0, 117)}...`, b = (t, e, s) => {
|
|
58
|
-
U(t) ? A(t) || s.push({
|
|
59
|
-
path: e,
|
|
60
|
-
message: `must contain at most ${m.textCharacters} characters`
|
|
61
|
-
}) : s.push({ path: e, message: "must be a non-empty string" });
|
|
62
|
-
}, C = (t, e, s) => {
|
|
63
|
-
t !== void 0 && typeof t != "string" ? s.push({ path: e, message: "must be a string" }) : typeof t == "string" && !A(t) && s.push({
|
|
64
|
-
path: e,
|
|
65
|
-
message: `must contain at most ${m.textCharacters} characters`
|
|
66
|
-
});
|
|
67
|
-
}, I = (t, e, s, n) => {
|
|
68
|
-
for (const a in t)
|
|
69
|
-
if (Object.prototype.hasOwnProperty.call(t, a)) {
|
|
70
|
-
if (n.length >= m.validationIssues) break;
|
|
71
|
-
e.has(a) || n.push({
|
|
72
|
-
path: st(s ? `${s}.${a}` : a),
|
|
73
|
-
message: "is not supported"
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}, $ = (t, e, s, n) => t.length > e ? (n.push({ path: s, message: `must contain at most ${e} items` }), !0) : !1, _ = (t, e, s) => {
|
|
77
|
-
for (let n = 0; n < t.length; n += 1)
|
|
78
|
-
if (!Object.prototype.hasOwnProperty.call(t, n))
|
|
79
|
-
return s.push({ path: e, message: "must not contain empty array slots" }), !0;
|
|
80
|
-
return !1;
|
|
81
|
-
}, T = (t, e, s, n) => {
|
|
82
|
-
const a = /* @__PURE__ */ new Set();
|
|
83
|
-
t.forEach((r, o) => {
|
|
84
|
-
if (!u(r) || typeof r[e] != "string") return;
|
|
85
|
-
const d = r[e];
|
|
86
|
-
a.has(d) ? n.push({
|
|
87
|
-
path: `${s}[${o}].${e}`,
|
|
88
|
-
message: "must be unique within the collection"
|
|
89
|
-
}) : a.add(d);
|
|
90
|
-
});
|
|
91
|
-
}, rt = /* @__PURE__ */ new Set([
|
|
92
|
-
"schemaVersion",
|
|
93
|
-
"id",
|
|
94
|
-
"kind",
|
|
95
|
-
"title",
|
|
96
|
-
"summary",
|
|
97
|
-
"presentation",
|
|
98
|
-
"actions",
|
|
99
|
-
"meta",
|
|
100
|
-
"data"
|
|
101
|
-
]), nt = /* @__PURE__ */ new Set(["template", "density"]), at = /* @__PURE__ */ new Set(["style", "currency", "precision", "unit"]), ot = /* @__PURE__ */ new Set(["id", "label", "intent", "target", "appearance"]), it = /* @__PURE__ */ new Set(["value", "format", "delta", "context"]), ct = /* @__PURE__ */ new Set(["value", "format", "direction", "label"]), W = /* @__PURE__ */ new Set(["items"]), dt = /* @__PURE__ */ new Set(["id", "label", "value", "format", "hint"]), pt = /* @__PURE__ */ new Set(["series"]), mt = /* @__PURE__ */ new Set(["id", "label", "points", "format"]), lt = /* @__PURE__ */ new Set(["x", "y"]), ft = /* @__PURE__ */ new Set([
|
|
102
|
-
"id",
|
|
103
|
-
"label",
|
|
104
|
-
"value",
|
|
105
|
-
"format",
|
|
106
|
-
"description"
|
|
107
|
-
]), ut = /* @__PURE__ */ new Set(["entity", "columns", "records", "total"]), ht = /* @__PURE__ */ new Set(["key", "label"]), It = /* @__PURE__ */ new Set(["key", "label", "format"]), gt = /* @__PURE__ */ new Set(["id", "title", "values", "action"]), yt = /* @__PURE__ */ new Set(["tone", "body"]), v = (t, e, s) => u(t) ? (I(t, at, e, s), t.style !== void 0 && (typeof t.style != "string" || !et.has(t.style)) && s.push({ path: `${e}.style`, message: "is not supported" }), t.currency !== void 0 && b(t.currency, `${e}.currency`, s), t.precision !== void 0 && (!Number.isInteger(t.precision) || Number(t.precision) < 0 || Number(t.precision) > 20) && s.push({ path: `${e}.precision`, message: "must be an integer between 0 and 20" }), C(t.unit, `${e}.unit`, s), !0) : (s.push({ path: e, message: "must be an object" }), !1), P = (t) => {
|
|
108
|
-
const e = [{ kind: "visit", depth: 0, value: t }], s = /* @__PURE__ */ new WeakSet();
|
|
109
|
-
let n = 0, a = 0;
|
|
110
|
-
try {
|
|
111
|
-
for (; e.length > 0; ) {
|
|
112
|
-
const r = e.pop();
|
|
113
|
-
if (!r) break;
|
|
114
|
-
if (r.kind === "leave") {
|
|
115
|
-
s.delete(r.value);
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
if (a += 1, a > m.jsonNodes || r.depth > m.jsonDepth)
|
|
119
|
-
return !1;
|
|
120
|
-
if (r.value === null || typeof r.value == "boolean")
|
|
121
|
-
continue;
|
|
122
|
-
if (typeof r.value == "string") {
|
|
123
|
-
if (n += Y(
|
|
124
|
-
r.value,
|
|
125
|
-
m.textCharacters
|
|
126
|
-
), !A(r.value) || n > m.jsonCharacters) return !1;
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
if (typeof r.value == "number") {
|
|
130
|
-
if (!Number.isFinite(r.value)) return !1;
|
|
131
|
-
continue;
|
|
132
|
-
}
|
|
133
|
-
if (!Array.isArray(r.value) && !u(r.value) || s.has(r.value)) return !1;
|
|
134
|
-
s.add(r.value), e.push({ kind: "leave", value: r.value });
|
|
135
|
-
const o = m.jsonNodes - a;
|
|
136
|
-
if (Array.isArray(r.value)) {
|
|
137
|
-
if (r.value.length > o) return !1;
|
|
138
|
-
for (let d = r.value.length - 1; d >= 0; d -= 1)
|
|
139
|
-
e.push({
|
|
140
|
-
kind: "visit",
|
|
141
|
-
depth: r.depth + 1,
|
|
142
|
-
value: r.value[d]
|
|
143
|
-
});
|
|
144
|
-
} else {
|
|
145
|
-
const d = [];
|
|
146
|
-
for (const p in r.value)
|
|
147
|
-
if (Object.prototype.hasOwnProperty.call(r.value, p)) {
|
|
148
|
-
if (!A(p) || (n += Y(
|
|
149
|
-
p,
|
|
150
|
-
m.textCharacters
|
|
151
|
-
), n > m.jsonCharacters) || d.length >= o) return !1;
|
|
152
|
-
d.push(p);
|
|
153
|
-
}
|
|
154
|
-
for (let p = d.length - 1; p >= 0; p -= 1) {
|
|
155
|
-
const i = d[p];
|
|
156
|
-
e.push({
|
|
157
|
-
kind: "visit",
|
|
158
|
-
depth: r.depth + 1,
|
|
159
|
-
value: r.value[i]
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return !0;
|
|
165
|
-
} catch {
|
|
166
|
-
return !1;
|
|
167
|
-
}
|
|
168
|
-
}, bt = (t) => t === null || typeof t == "boolean" || A(t) || R(t), G = (t, e, s) => u(t) ? (I(t, ot, e, s), b(t.id, `${e}.id`, s), b(t.label, `${e}.label`, s), (typeof t.intent != "string" || !tt.has(t.intent)) && s.push({ path: `${e}.intent`, message: "is not supported" }), (!u(t.target) || !P(t.target)) && s.push({ path: `${e}.target`, message: "must be a JSON object" }), t.appearance !== void 0 && (typeof t.appearance != "string" || !["primary", "secondary", "link"].includes(t.appearance)) && s.push({ path: `${e}.appearance`, message: "is not supported" }), !0) : (s.push({ path: e, message: "must be an object" }), !1), wt = (t, e) => {
|
|
169
|
-
if (I(t, rt, "", e), t.schemaVersion !== "1.0" && e.push({ path: "schemaVersion", message: "must equal 1.0" }), b(t.id, "id", e), Z.includes(t.kind) || e.push({ path: "kind", message: "is not a supported Artifact kind" }), C(t.title, "title", e), C(t.summary, "summary", e), t.presentation !== void 0 && (u(t.presentation) ? (I(t.presentation, nt, "presentation", e), t.presentation.template !== void 0 && !U(t.presentation.template) ? e.push({ path: "presentation.template", message: "must be a non-empty string" }) : t.presentation.template !== void 0 && !A(t.presentation.template) && e.push({
|
|
170
|
-
path: "presentation.template",
|
|
171
|
-
message: `must contain at most ${m.textCharacters} characters`
|
|
172
|
-
}), t.presentation.density !== void 0 && (typeof t.presentation.density != "string" || !["compact", "comfortable"].includes(t.presentation.density)) && e.push({ path: "presentation.density", message: "is not supported" })) : e.push({ path: "presentation", message: "must be an object" })), t.actions !== void 0) {
|
|
173
|
-
if (!Array.isArray(t.actions))
|
|
174
|
-
e.push({ path: "actions", message: "must be an array" });
|
|
175
|
-
else if (!$(
|
|
176
|
-
t.actions,
|
|
177
|
-
m.actions,
|
|
178
|
-
"actions",
|
|
179
|
-
e
|
|
180
|
-
)) {
|
|
181
|
-
if (_(t.actions, "actions", e)) return;
|
|
182
|
-
T(t.actions, "id", "actions", e), t.actions.forEach(
|
|
183
|
-
(n, a) => G(n, `actions[${a}]`, e)
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
t.meta !== void 0 && (!u(t.meta) || !P(t.meta)) && e.push({ path: "meta", message: "must be a JSON object" });
|
|
188
|
-
}, St = (t, e) => {
|
|
189
|
-
I(t, it, "data", e), !R(t.value) && !A(t.value) && e.push({ path: "data.value", message: "must be a finite number or string" }), t.format !== void 0 && v(t.format, "data.format", e), t.delta !== void 0 && (u(t.delta) ? (I(
|
|
190
|
-
t.delta,
|
|
191
|
-
ct,
|
|
192
|
-
"data.delta",
|
|
193
|
-
e
|
|
194
|
-
), R(t.delta.value) || e.push({ path: "data.delta.value", message: "must be a finite number" }), t.delta.direction !== void 0 && (typeof t.delta.direction != "string" || !["up", "down", "flat"].includes(t.delta.direction)) && e.push({ path: "data.delta.direction", message: "is not supported" }), t.delta.format !== void 0 && (typeof t.delta.format != "string" || !["decimal", "percent"].includes(t.delta.format)) && e.push({ path: "data.delta.format", message: "is not supported" }), C(t.delta.label, "data.delta.label", e)) : e.push({ path: "data.delta", message: "must be an object" })), C(t.context, "data.context", e);
|
|
195
|
-
}, Et = (t, e) => {
|
|
196
|
-
if (I(t, W, "data", e), !Array.isArray(t.items) || t.items.length === 0) {
|
|
197
|
-
e.push({ path: "data.items", message: "must be a non-empty array" });
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
$(
|
|
201
|
-
t.items,
|
|
202
|
-
m.comparisonItems,
|
|
203
|
-
"data.items",
|
|
204
|
-
e
|
|
205
|
-
) || _(t.items, "data.items", e) || (T(t.items, "id", "data.items", e), t.items.forEach((s, n) => {
|
|
206
|
-
const a = `data.items[${n}]`;
|
|
207
|
-
if (!u(s)) {
|
|
208
|
-
e.push({ path: a, message: "must be an object" });
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
I(
|
|
212
|
-
s,
|
|
213
|
-
dt,
|
|
214
|
-
a,
|
|
215
|
-
e
|
|
216
|
-
), b(s.id, `${a}.id`, e), b(s.label, `${a}.label`, e), !R(s.value) && !A(s.value) && e.push({ path: `${a}.value`, message: "must be a finite number or string" }), s.format !== void 0 && v(s.format, `${a}.format`, e), C(s.hint, `${a}.hint`, e);
|
|
217
|
-
}));
|
|
218
|
-
}, At = (t, e) => {
|
|
219
|
-
if (I(t, pt, "data", e), !Array.isArray(t.series) || t.series.length === 0) {
|
|
220
|
-
e.push({ path: "data.series", message: "must be a non-empty array" });
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
$(
|
|
224
|
-
t.series,
|
|
225
|
-
m.trendSeries,
|
|
226
|
-
"data.series",
|
|
227
|
-
e
|
|
228
|
-
) || _(t.series, "data.series", e) || (T(t.series, "id", "data.series", e), t.series.forEach((s, n) => {
|
|
229
|
-
const a = `data.series[${n}]`;
|
|
230
|
-
if (!u(s)) {
|
|
231
|
-
e.push({ path: a, message: "must be an object" });
|
|
232
|
-
return;
|
|
233
|
-
}
|
|
234
|
-
if (I(
|
|
235
|
-
s,
|
|
236
|
-
mt,
|
|
237
|
-
a,
|
|
238
|
-
e
|
|
239
|
-
), b(s.id, `${a}.id`, e), b(s.label, `${a}.label`, e), s.format !== void 0 && v(s.format, `${a}.format`, e), !Array.isArray(s.points) || s.points.length === 0) {
|
|
240
|
-
e.push({ path: `${a}.points`, message: "must be a non-empty array" });
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
$(
|
|
244
|
-
s.points,
|
|
245
|
-
m.trendPointsPerSeries,
|
|
246
|
-
`${a}.points`,
|
|
247
|
-
e
|
|
248
|
-
) || _(s.points, `${a}.points`, e) || s.points.forEach((r, o) => {
|
|
249
|
-
const d = `${a}.points[${o}]`;
|
|
250
|
-
if (!u(r)) {
|
|
251
|
-
e.push({ path: d, message: "must be an object" });
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
I(r, lt, d, e), !R(r.x) && !A(r.x) && e.push({ path: `${d}.x`, message: "must be a finite number or string" }), R(r.y) || e.push({ path: `${d}.y`, message: "must be a finite number" });
|
|
255
|
-
});
|
|
256
|
-
}));
|
|
257
|
-
}, kt = (t, e) => {
|
|
258
|
-
if (I(t, W, "data", e), !Array.isArray(t.items) || t.items.length === 0) {
|
|
259
|
-
e.push({ path: "data.items", message: "must be a non-empty array" });
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
$(
|
|
263
|
-
t.items,
|
|
264
|
-
m.rankingItems,
|
|
265
|
-
"data.items",
|
|
266
|
-
e
|
|
267
|
-
) || _(t.items, "data.items", e) || (T(t.items, "id", "data.items", e), t.items.forEach((s, n) => {
|
|
268
|
-
const a = `data.items[${n}]`;
|
|
269
|
-
if (!u(s)) {
|
|
270
|
-
e.push({ path: a, message: "must be an object" });
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
I(
|
|
274
|
-
s,
|
|
275
|
-
ft,
|
|
276
|
-
a,
|
|
277
|
-
e
|
|
278
|
-
), b(s.id, `${a}.id`, e), b(s.label, `${a}.label`, e), R(s.value) || e.push({ path: `${a}.value`, message: "must be a finite number" }), s.format !== void 0 && v(s.format, `${a}.format`, e), C(s.description, `${a}.description`, e);
|
|
279
|
-
}));
|
|
280
|
-
}, Ct = (t, e) => {
|
|
281
|
-
if (I(
|
|
282
|
-
t,
|
|
283
|
-
ut,
|
|
284
|
-
"data",
|
|
285
|
-
e
|
|
286
|
-
), u(t.entity) ? (I(t.entity, ht, "data.entity", e), b(t.entity.key, "data.entity.key", e), C(t.entity.label, "data.entity.label", e)) : e.push({ path: "data.entity", message: "must be an object" }), !Array.isArray(t.columns) || t.columns.length === 0)
|
|
287
|
-
e.push({ path: "data.columns", message: "must be a non-empty array" });
|
|
288
|
-
else if (!$(
|
|
289
|
-
t.columns,
|
|
290
|
-
m.recordColumns,
|
|
291
|
-
"data.columns",
|
|
292
|
-
e
|
|
293
|
-
)) {
|
|
294
|
-
if (_(t.columns, "data.columns", e)) return;
|
|
295
|
-
T(t.columns, "key", "data.columns", e), t.columns.forEach((n, a) => {
|
|
296
|
-
const r = `data.columns[${a}]`;
|
|
297
|
-
if (!u(n)) {
|
|
298
|
-
e.push({ path: r, message: "must be an object" });
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
I(
|
|
302
|
-
n,
|
|
303
|
-
It,
|
|
304
|
-
r,
|
|
305
|
-
e
|
|
306
|
-
), b(n.key, `${r}.key`, e), b(n.label, `${r}.label`, e), n.format !== void 0 && v(n.format, `${r}.format`, e);
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
if (!Array.isArray(t.records))
|
|
310
|
-
e.push({ path: "data.records", message: "must be an array" });
|
|
311
|
-
else if (!$(
|
|
312
|
-
t.records,
|
|
313
|
-
m.recordListRecords,
|
|
314
|
-
"data.records",
|
|
315
|
-
e
|
|
316
|
-
)) {
|
|
317
|
-
if (_(t.records, "data.records", e)) return;
|
|
318
|
-
T(t.records, "id", "data.records", e), t.records.forEach((n, a) => {
|
|
319
|
-
const r = `data.records[${a}]`;
|
|
320
|
-
if (!u(n)) {
|
|
321
|
-
e.push({ path: r, message: "must be an object" });
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
if (I(
|
|
325
|
-
n,
|
|
326
|
-
gt,
|
|
327
|
-
r,
|
|
328
|
-
e
|
|
329
|
-
), b(n.id, `${r}.id`, e), C(n.title, `${r}.title`, e), !u(n.values))
|
|
330
|
-
e.push({
|
|
331
|
-
path: `${r}.values`,
|
|
332
|
-
message: "must contain only JSON primitive display values"
|
|
333
|
-
});
|
|
334
|
-
else {
|
|
335
|
-
const o = n.values;
|
|
336
|
-
let d = !1, p = 0;
|
|
337
|
-
for (const i in o)
|
|
338
|
-
if (Object.prototype.hasOwnProperty.call(o, i)) {
|
|
339
|
-
if (p += 1, p > m.recordValues) break;
|
|
340
|
-
d ||= !A(i) || !bt(o[i]);
|
|
341
|
-
}
|
|
342
|
-
p > m.recordValues ? e.push({
|
|
343
|
-
path: `${r}.values`,
|
|
344
|
-
message: `must contain at most ${m.recordValues} values`
|
|
345
|
-
}) : d && e.push({
|
|
346
|
-
path: `${r}.values`,
|
|
347
|
-
message: "must contain only JSON primitive display values"
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
n.action !== void 0 && G(n.action, `${r}.action`, e);
|
|
351
|
-
});
|
|
352
|
-
}
|
|
353
|
-
t.total !== void 0 && (!Number.isInteger(t.total) || Number(t.total) < 0) && e.push({ path: "data.total", message: "must be a non-negative integer" });
|
|
354
|
-
}, Rt = (t, e) => {
|
|
355
|
-
I(t, yt, "data", e), (typeof t.tone != "string" || !["info", "success", "warning", "danger"].includes(t.tone)) && e.push({ path: "data.tone", message: "is not supported" }), b(t.body, "data.body", e);
|
|
356
|
-
}, B = (t, e) => {
|
|
357
|
-
if (wt(t, e), !u(t.data)) {
|
|
358
|
-
e.push({ path: "data", message: "must be an object" });
|
|
359
|
-
return;
|
|
360
|
-
}
|
|
361
|
-
switch (t.kind) {
|
|
362
|
-
case "metric":
|
|
363
|
-
St(t.data, e);
|
|
364
|
-
break;
|
|
365
|
-
case "comparison":
|
|
366
|
-
Et(t.data, e);
|
|
367
|
-
break;
|
|
368
|
-
case "trend":
|
|
369
|
-
At(t.data, e);
|
|
370
|
-
break;
|
|
371
|
-
case "ranking":
|
|
372
|
-
kt(t.data, e);
|
|
373
|
-
break;
|
|
374
|
-
case "record-list":
|
|
375
|
-
Ct(t.data, e);
|
|
376
|
-
break;
|
|
377
|
-
case "notice":
|
|
378
|
-
Rt(t.data, e);
|
|
379
|
-
break;
|
|
380
|
-
}
|
|
381
|
-
}, $t = (t) => {
|
|
382
|
-
const e = new z();
|
|
383
|
-
try {
|
|
384
|
-
if (!u(t))
|
|
385
|
-
return { success: !1, issues: [{ path: "", message: "must be an object" }] };
|
|
386
|
-
B(t, e);
|
|
387
|
-
} catch {
|
|
388
|
-
return M();
|
|
389
|
-
}
|
|
390
|
-
if (e.length > 0) return { success: !1, issues: e };
|
|
391
|
-
if (!P(t))
|
|
392
|
-
return {
|
|
393
|
-
success: !1,
|
|
394
|
-
issues: [{ path: "", message: "exceeds the Artifact resource budget" }]
|
|
395
|
-
};
|
|
396
|
-
let s;
|
|
397
|
-
try {
|
|
398
|
-
s = structuredClone(t);
|
|
399
|
-
} catch {
|
|
400
|
-
return M();
|
|
401
|
-
}
|
|
402
|
-
const n = new z();
|
|
403
|
-
try {
|
|
404
|
-
if (!u(s)) return M();
|
|
405
|
-
B(s, n);
|
|
406
|
-
} catch {
|
|
407
|
-
return M();
|
|
408
|
-
}
|
|
409
|
-
return n.length === 0 && !P(s) && n.push({
|
|
410
|
-
path: "",
|
|
411
|
-
message: "exceeds the Artifact resource budget"
|
|
412
|
-
}), n.length === 0 ? { success: !0, artifact: s } : { success: !1, issues: n };
|
|
413
|
-
}, H = (t) => {
|
|
414
|
-
const e = $t(t);
|
|
415
|
-
if (e.success) return e.artifact;
|
|
416
|
-
const s = e.issues.map((n) => `${n.path || "artifact"} ${n.message}`).join(", ");
|
|
417
|
-
throw new Error(`Invalid Make AI Artifact: ${s}`);
|
|
418
|
-
}, k = (t) => t === "completed" || t === "failed" || t === "cancelled", x = (t) => {
|
|
419
|
-
if (!t || typeof t != "object" || Array.isArray(t))
|
|
420
|
-
throw new Error("Invalid assistant data: object");
|
|
421
|
-
return t;
|
|
422
|
-
}, S = (t, e = 256, s = !1) => {
|
|
423
|
-
if (typeof t != "string" || t.length > e * 2 || !s && !t.trim() || t.includes("\0") || [...t].length > e)
|
|
424
|
-
throw new Error("Invalid assistant data: text");
|
|
425
|
-
return t;
|
|
426
|
-
}, h = (t) => {
|
|
427
|
-
const e = S(t);
|
|
428
|
-
if (["__proto__", "constructor", "prototype"].includes(e))
|
|
429
|
-
throw new Error("Invalid assistant data: identifier");
|
|
430
|
-
return e;
|
|
431
|
-
}, N = (t, e = 0, s = Number.MAX_SAFE_INTEGER) => {
|
|
432
|
-
if (!Number.isSafeInteger(t) || Number(t) < e || Number(t) > s)
|
|
433
|
-
throw new Error("Invalid assistant data: integer");
|
|
434
|
-
return t;
|
|
435
|
-
}, q = (t) => {
|
|
436
|
-
if (typeof t != "boolean")
|
|
437
|
-
throw new Error("Invalid assistant data: boolean");
|
|
438
|
-
return t;
|
|
439
|
-
}, F = (t, e) => {
|
|
440
|
-
if (!Array.isArray(t) || t.length > e)
|
|
441
|
-
throw new Error("Invalid assistant data: array");
|
|
442
|
-
return t;
|
|
443
|
-
}, y = (t, e) => {
|
|
444
|
-
if (Object.keys(t).some((s) => !e.includes(s)))
|
|
445
|
-
throw new Error("Invalid assistant data: unknown field");
|
|
446
|
-
}, V = (t) => {
|
|
447
|
-
if (![
|
|
448
|
-
"queued",
|
|
449
|
-
"dispatched",
|
|
450
|
-
"running",
|
|
451
|
-
"completed",
|
|
452
|
-
"failed",
|
|
453
|
-
"cancelled"
|
|
454
|
-
].includes(String(t)))
|
|
455
|
-
throw new Error("Invalid assistant data: status");
|
|
456
|
-
return t;
|
|
457
|
-
}, L = (t) => F(t, 32).map((e) => {
|
|
458
|
-
const s = x(e), n = s.id === void 0 ? {} : { id: h(s.id) };
|
|
459
|
-
if (s.kind === "text")
|
|
460
|
-
return y(s, ["id", "kind", "text"]), {
|
|
461
|
-
...n,
|
|
462
|
-
kind: "text",
|
|
463
|
-
text: S(s.text, 1e5, !0)
|
|
464
|
-
};
|
|
465
|
-
if (!["image", "file", "audio", "video"].includes(String(s.kind)))
|
|
466
|
-
throw new Error("Invalid assistant data: part kind");
|
|
467
|
-
y(s, ["id", "kind", "name", "media"]);
|
|
468
|
-
const a = x(s.media);
|
|
469
|
-
y(a, [
|
|
470
|
-
"contentRef",
|
|
471
|
-
"contentType",
|
|
472
|
-
"sizeBytes",
|
|
473
|
-
"digestSha256"
|
|
474
|
-
]);
|
|
475
|
-
const r = S(a.digestSha256, 64);
|
|
476
|
-
if (!/^[0-9a-f]{64}$/.test(r))
|
|
477
|
-
throw new Error("Invalid assistant data: digest");
|
|
478
|
-
return {
|
|
479
|
-
...n,
|
|
480
|
-
kind: s.kind,
|
|
481
|
-
...s.name === void 0 ? {} : { name: S(s.name, 512, !0) },
|
|
482
|
-
media: {
|
|
483
|
-
contentRef: h(a.contentRef),
|
|
484
|
-
contentType: S(a.contentType, 256),
|
|
485
|
-
sizeBytes: N(a.sizeBytes, 0, 64 << 20),
|
|
486
|
-
digestSha256: r
|
|
487
|
-
}
|
|
488
|
-
};
|
|
489
|
-
}), X = (t) => {
|
|
490
|
-
const e = x(t);
|
|
491
|
-
if (y(e, ["id", "rating", "revision", "reason", "comment"]), !["like", "dislike", "none"].includes(String(e.rating)))
|
|
492
|
-
throw new Error("Invalid assistant data: rating");
|
|
493
|
-
return {
|
|
494
|
-
id: h(e.id),
|
|
495
|
-
rating: e.rating,
|
|
496
|
-
revision: N(e.revision, 1),
|
|
497
|
-
...e.reason === void 0 ? {} : { reason: S(e.reason, 128, !0) },
|
|
498
|
-
...e.comment === void 0 ? {} : { comment: S(e.comment, 4e3, !0) }
|
|
499
|
-
};
|
|
500
|
-
}, _t = (t) => {
|
|
501
|
-
const e = x(t);
|
|
502
|
-
return y(e, [
|
|
503
|
-
"itemId",
|
|
504
|
-
"partId",
|
|
505
|
-
"text",
|
|
506
|
-
"final",
|
|
507
|
-
"revision",
|
|
508
|
-
"parts"
|
|
509
|
-
]), {
|
|
510
|
-
itemId: h(e.itemId),
|
|
511
|
-
partId: h(e.partId),
|
|
512
|
-
text: S(e.text, 1e5, !0),
|
|
513
|
-
final: q(e.final),
|
|
514
|
-
revision: N(e.revision, 1),
|
|
515
|
-
...e.parts === void 0 ? {} : { parts: L(e.parts) }
|
|
516
|
-
};
|
|
517
|
-
}, xt = (t) => {
|
|
518
|
-
const e = x(t);
|
|
519
|
-
y(e, [
|
|
520
|
-
"chatId",
|
|
521
|
-
"responseId",
|
|
522
|
-
"status",
|
|
523
|
-
"items",
|
|
524
|
-
"cancelRequested"
|
|
525
|
-
]);
|
|
526
|
-
const s = F(e.items, 20).map(_t);
|
|
527
|
-
if (new Set(s.map((n) => n.itemId)).size !== s.length || s.reduce((n, a) => n + [...a.text].length, 0) > 1e5)
|
|
528
|
-
throw new Error("Invalid assistant data: output budget or identity");
|
|
529
|
-
return {
|
|
530
|
-
chatId: h(e.chatId),
|
|
531
|
-
responseId: h(e.responseId),
|
|
532
|
-
status: V(e.status),
|
|
533
|
-
items: s,
|
|
534
|
-
...e.cancelRequested === void 0 ? {} : { cancelRequested: q(e.cancelRequested) }
|
|
535
|
-
};
|
|
536
|
-
}, Nt = (t) => {
|
|
537
|
-
const e = x(t);
|
|
538
|
-
if (y(e, [
|
|
539
|
-
"id",
|
|
540
|
-
"role",
|
|
541
|
-
"content",
|
|
542
|
-
"persistent",
|
|
543
|
-
"responseId",
|
|
544
|
-
"cursor",
|
|
545
|
-
"createdAt",
|
|
546
|
-
"parts",
|
|
547
|
-
"feedback"
|
|
548
|
-
]), e.role !== "assistant" && e.role !== "user" || e.persistent !== !0)
|
|
549
|
-
throw new Error("Invalid assistant data: persisted message");
|
|
550
|
-
return {
|
|
551
|
-
id: h(e.id),
|
|
552
|
-
role: e.role,
|
|
553
|
-
content: S(e.content, 1e5, !0),
|
|
554
|
-
persistent: !0,
|
|
555
|
-
cursor: N(e.cursor),
|
|
556
|
-
createdAt: S(e.createdAt, 64),
|
|
557
|
-
...e.responseId === void 0 ? {} : { responseId: h(e.responseId) },
|
|
558
|
-
...e.parts === void 0 ? {} : { parts: L(e.parts) },
|
|
559
|
-
...e.feedback === void 0 ? {} : { feedback: X(e.feedback) }
|
|
560
|
-
};
|
|
561
|
-
}, Ot = (t) => {
|
|
562
|
-
const e = x(t), s = e.type;
|
|
563
|
-
if (s === "response.snapshot")
|
|
564
|
-
return y(e, ["type", "snapshot"]), { type: s, snapshot: xt(e.snapshot) };
|
|
565
|
-
const n = h(e.responseId);
|
|
566
|
-
if (s === "response.accepted")
|
|
567
|
-
return y(e, [
|
|
568
|
-
"type",
|
|
569
|
-
"chatId",
|
|
570
|
-
"responseId",
|
|
571
|
-
"messageId",
|
|
572
|
-
"acceptedCursor"
|
|
573
|
-
]), {
|
|
574
|
-
type: s,
|
|
575
|
-
responseId: n,
|
|
576
|
-
chatId: h(e.chatId),
|
|
577
|
-
messageId: h(e.messageId),
|
|
578
|
-
acceptedCursor: N(e.acceptedCursor)
|
|
579
|
-
};
|
|
580
|
-
if (s === "response.state")
|
|
581
|
-
return y(e, ["type", "chatId", "responseId", "status"]), {
|
|
582
|
-
type: s,
|
|
583
|
-
responseId: n,
|
|
584
|
-
chatId: h(e.chatId),
|
|
585
|
-
status: V(e.status)
|
|
586
|
-
};
|
|
587
|
-
if (s === "response.terminal") {
|
|
588
|
-
y(e, ["type", "chatId", "responseId", "status", "code"]);
|
|
589
|
-
const p = V(e.status);
|
|
590
|
-
if (!k(p))
|
|
591
|
-
throw new Error("Invalid assistant data: terminal");
|
|
592
|
-
return {
|
|
593
|
-
type: s,
|
|
594
|
-
responseId: n,
|
|
595
|
-
chatId: h(e.chatId),
|
|
596
|
-
status: p,
|
|
597
|
-
...e.code === void 0 ? {} : { code: h(e.code) }
|
|
598
|
-
};
|
|
599
|
-
}
|
|
600
|
-
if (s === "response.reconciled") {
|
|
601
|
-
y(e, ["type", "chatId", "responseId", "messages"]);
|
|
602
|
-
const p = F(e.messages, 200).map(Nt);
|
|
603
|
-
if (p.some((i) => i.responseId !== n) || new Set(p.map((i) => i.id)).size !== p.length || p.reduce((i, c) => i + [...c.content].length, 0) > 1e6)
|
|
604
|
-
throw new Error("Invalid assistant data: response history");
|
|
605
|
-
return { type: s, responseId: n, chatId: h(e.chatId), messages: p };
|
|
606
|
-
}
|
|
607
|
-
const a = h(e.itemId), r = h(e.partId), o = N(e.sequence, 1), d = ["type", "responseId", "itemId", "partId", "sequence"];
|
|
608
|
-
if (s === "response.output_item.added")
|
|
609
|
-
return y(e, d), { type: s, responseId: n, itemId: a, partId: r, sequence: o };
|
|
610
|
-
if (s === "response.output_text.delta")
|
|
611
|
-
return y(e, [...d, "delta"]), {
|
|
612
|
-
type: s,
|
|
613
|
-
responseId: n,
|
|
614
|
-
itemId: a,
|
|
615
|
-
partId: r,
|
|
616
|
-
sequence: o,
|
|
617
|
-
delta: S(e.delta, 1e5, !0)
|
|
618
|
-
};
|
|
619
|
-
if (s === "response.output_item.done")
|
|
620
|
-
return y(e, [...d, "text", "final"]), {
|
|
621
|
-
type: s,
|
|
622
|
-
responseId: n,
|
|
623
|
-
itemId: a,
|
|
624
|
-
partId: r,
|
|
625
|
-
sequence: o,
|
|
626
|
-
text: S(e.text, 1e5, !0),
|
|
627
|
-
final: q(e.final)
|
|
628
|
-
};
|
|
629
|
-
throw new Error("Invalid assistant data: event type");
|
|
630
|
-
}, O = (t, e, s = t.messages) => {
|
|
631
|
-
const n = { ...t.responses, [e.responseId]: e };
|
|
632
|
-
let a = s;
|
|
633
|
-
if (s.length > f.historyMessages || s.reduce((i, c) => i + c.content.length, 0) > f.historyCharacters) {
|
|
634
|
-
a = [];
|
|
635
|
-
let i = 0;
|
|
636
|
-
for (let c = s.length - 1; c >= 0 && a.length < f.historyMessages; c -= 1) {
|
|
637
|
-
const g = s[c];
|
|
638
|
-
if (i += j(
|
|
639
|
-
g.content,
|
|
640
|
-
f.historyCharacters - i
|
|
641
|
-
), i > f.historyCharacters) break;
|
|
642
|
-
a.unshift(g);
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
const r = new Set(a.map((i) => i.responseId)), o = new Set(
|
|
646
|
-
Object.values(n).filter((i) => k(i.status)).slice(-20).map((i) => i.responseId)
|
|
647
|
-
), d = Object.fromEntries(
|
|
648
|
-
Object.entries(n).filter(
|
|
649
|
-
([i, c]) => !k(c.status) || r.has(i) || o.has(i)
|
|
650
|
-
)
|
|
651
|
-
), p = Object.values(d).filter(
|
|
652
|
-
(i) => !k(i.status)
|
|
653
|
-
);
|
|
654
|
-
return {
|
|
655
|
-
...t,
|
|
656
|
-
threadId: e.chatId,
|
|
657
|
-
messages: a,
|
|
658
|
-
responses: d,
|
|
659
|
-
...a.length < s.length ? { historyTruncated: !0 } : {},
|
|
660
|
-
activeRunId: p.at(-1)?.responseId,
|
|
661
|
-
status: p.length ? "streaming" : "idle"
|
|
662
|
-
};
|
|
663
|
-
}, Tt = (t, e) => ({
|
|
664
|
-
id: e.itemId,
|
|
665
|
-
role: "assistant",
|
|
666
|
-
content: e.text,
|
|
667
|
-
artifacts: [],
|
|
668
|
-
responseId: t.responseId,
|
|
669
|
-
partId: e.partId,
|
|
670
|
-
parts: e.parts,
|
|
671
|
-
persistent: !1,
|
|
672
|
-
intermediate: !!t.completedItems[e.itemId] && !e.final,
|
|
673
|
-
status: t.completedItems[e.itemId] || k(t.status) ? "complete" : "streaming"
|
|
674
|
-
}), J = (t, e) => {
|
|
675
|
-
const s = t.findIndex(
|
|
676
|
-
(o) => o.responseId === e.responseId && !o.persistent
|
|
677
|
-
), n = t.filter(
|
|
678
|
-
(o) => o.responseId !== e.responseId || o.persistent
|
|
679
|
-
);
|
|
680
|
-
if (e.reconciled) return n;
|
|
681
|
-
const a = e.items.map(
|
|
682
|
-
(o) => Tt(e, o)
|
|
683
|
-
), r = s < 0 ? n.length : Math.min(s, n.length);
|
|
684
|
-
return [...n.slice(0, r), ...a, ...n.slice(r)];
|
|
685
|
-
}, jt = (t, e) => {
|
|
686
|
-
const s = e.type === "response.snapshot" ? e.snapshot.responseId : e.responseId, n = t.responses && Object.hasOwn(t.responses, s) ? t.responses[s] : void 0, a = e.type === "response.snapshot" ? e.snapshot.chatId : "chatId" in e ? e.chatId : n?.chatId;
|
|
687
|
-
if (!a || t.threadId && t.threadId !== a)
|
|
688
|
-
throw new Error("Invalid assistant response: conversation mismatch");
|
|
689
|
-
const r = n ?? {
|
|
690
|
-
chatId: a,
|
|
691
|
-
responseId: s,
|
|
692
|
-
status: "queued",
|
|
693
|
-
items: [],
|
|
694
|
-
lastSequence: 0,
|
|
695
|
-
completedItems: {}
|
|
696
|
-
};
|
|
697
|
-
if (e.type === "response.accepted")
|
|
698
|
-
return O(
|
|
699
|
-
t,
|
|
700
|
-
r,
|
|
701
|
-
t.messages.map(
|
|
702
|
-
(c) => c.id === e.messageId ? { ...c, responseId: s, cursor: e.acceptedCursor, persistent: !0 } : c
|
|
703
|
-
)
|
|
704
|
-
);
|
|
705
|
-
if (e.type === "response.reconciled") {
|
|
706
|
-
const c = t.messages.filter(
|
|
707
|
-
(w) => w.responseId !== s || w.persistent
|
|
708
|
-
), g = new Map(c.map((w) => [w.id, w]));
|
|
709
|
-
for (const w of e.messages)
|
|
710
|
-
g.set(w.id, { ...w, artifacts: [], status: "complete" });
|
|
711
|
-
return O(t, { ...r, reconciled: !0 }, [
|
|
712
|
-
...g.values()
|
|
713
|
-
]);
|
|
714
|
-
}
|
|
715
|
-
if (e.type === "response.snapshot") {
|
|
716
|
-
if (k(r.status) && r.status !== e.snapshot.status)
|
|
717
|
-
return t;
|
|
718
|
-
const c = {
|
|
719
|
-
...r,
|
|
720
|
-
...e.snapshot,
|
|
721
|
-
completedItems: Object.fromEntries(
|
|
722
|
-
e.snapshot.items.map((g) => [g.itemId, !0])
|
|
723
|
-
)
|
|
724
|
-
};
|
|
725
|
-
return O(t, c, J(t.messages, c));
|
|
726
|
-
}
|
|
727
|
-
if (e.type === "response.state")
|
|
728
|
-
return k(r.status) ? t : O(t, { ...r, status: e.status });
|
|
729
|
-
if (e.type === "response.terminal") {
|
|
730
|
-
if (k(r.status) && r.status !== e.status)
|
|
731
|
-
return t;
|
|
732
|
-
const c = { ...r, status: e.status }, g = t.messages.map(
|
|
733
|
-
(w) => w.responseId !== s ? w : {
|
|
734
|
-
...w,
|
|
735
|
-
status: "complete",
|
|
736
|
-
...e.status === "failed" ? {
|
|
737
|
-
error: {
|
|
738
|
-
code: e.code ?? "AI_RUN_FAILED",
|
|
739
|
-
message: "本次处理失败,请重试",
|
|
740
|
-
retryable: !0
|
|
741
|
-
}
|
|
742
|
-
} : {}
|
|
743
|
-
}
|
|
744
|
-
);
|
|
745
|
-
return O(t, c, g);
|
|
746
|
-
}
|
|
747
|
-
if (k(r.status) || e.sequence <= r.lastSequence)
|
|
748
|
-
return t;
|
|
749
|
-
const o = r.items.findIndex((c) => c.itemId === e.itemId);
|
|
750
|
-
let d;
|
|
751
|
-
if (e.type === "response.output_item.added") {
|
|
752
|
-
if (o >= 0 || r.items.length >= 20)
|
|
753
|
-
throw new Error(
|
|
754
|
-
"Invalid assistant response: duplicate item or item budget"
|
|
755
|
-
);
|
|
756
|
-
d = {
|
|
757
|
-
itemId: e.itemId,
|
|
758
|
-
partId: e.partId,
|
|
759
|
-
text: "",
|
|
760
|
-
final: !1,
|
|
761
|
-
revision: 1
|
|
762
|
-
};
|
|
763
|
-
} else {
|
|
764
|
-
const c = r.items[o];
|
|
765
|
-
if (!c || c.partId !== e.partId || r.completedItems[e.itemId])
|
|
766
|
-
throw new Error("Invalid assistant response: item order");
|
|
767
|
-
d = e.type === "response.output_text.delta" ? { ...c, text: c.text + e.delta } : { ...c, text: e.text, final: e.final };
|
|
768
|
-
}
|
|
769
|
-
const p = o < 0 ? [...r.items, d] : r.items.map((c, g) => g === o ? d : c);
|
|
770
|
-
if (p.reduce((c, g) => c + [...g.text].length, 0) > 1e5)
|
|
771
|
-
throw new Error("Invalid assistant response: text budget");
|
|
772
|
-
const i = {
|
|
773
|
-
...r,
|
|
774
|
-
status: "running",
|
|
775
|
-
lastSequence: e.sequence,
|
|
776
|
-
items: p,
|
|
777
|
-
completedItems: e.type === "response.output_item.done" ? { ...r.completedItems, [e.itemId]: !0 } : r.completedItems
|
|
778
|
-
};
|
|
779
|
-
return O(t, i, J(t.messages, i));
|
|
780
|
-
}, D = (t) => typeof t == "object" && t !== null && !Array.isArray(t), E = (t, e) => {
|
|
781
|
-
if (Object.keys(t).some((s) => !e.has(s)))
|
|
782
|
-
throw new Error("Invalid assistant event: unsupported field");
|
|
783
|
-
}, l = (t, e, s = f.identifierCharacters) => {
|
|
784
|
-
const n = typeof t == "string" ? j(t, s) : 0;
|
|
785
|
-
if (typeof t != "string" || !t.trim() || n > s)
|
|
786
|
-
throw new Error(`Invalid assistant event: ${e}`);
|
|
787
|
-
return t;
|
|
788
|
-
}, vt = (t) => {
|
|
789
|
-
if (!D(t) || typeof t.type != "string")
|
|
790
|
-
throw new Error("Invalid assistant event: data");
|
|
791
|
-
if (t.type.startsWith("response.")) return Ot(t);
|
|
792
|
-
switch (t.type) {
|
|
793
|
-
case "message.start":
|
|
794
|
-
return E(t, /* @__PURE__ */ new Set(["type", "runId", "messageId"])), {
|
|
795
|
-
type: t.type,
|
|
796
|
-
runId: l(t.runId, "runId"),
|
|
797
|
-
messageId: l(t.messageId, "messageId")
|
|
798
|
-
};
|
|
799
|
-
case "message.delta":
|
|
800
|
-
if (E(t, /* @__PURE__ */ new Set(["type", "messageId", "delta"])), typeof t.delta != "string")
|
|
801
|
-
throw new Error("Invalid assistant event: delta");
|
|
802
|
-
return {
|
|
803
|
-
type: t.type,
|
|
804
|
-
messageId: l(t.messageId, "messageId"),
|
|
805
|
-
delta: t.delta
|
|
806
|
-
};
|
|
807
|
-
case "message.replace":
|
|
808
|
-
return E(t, /* @__PURE__ */ new Set(["type", "messageId", "content"])), {
|
|
809
|
-
type: t.type,
|
|
810
|
-
messageId: l(t.messageId, "messageId"),
|
|
811
|
-
content: l(
|
|
812
|
-
t.content,
|
|
813
|
-
"content",
|
|
814
|
-
f.messageCharacters
|
|
815
|
-
)
|
|
816
|
-
};
|
|
817
|
-
case "message.complete":
|
|
818
|
-
return E(t, /* @__PURE__ */ new Set(["type", "messageId"])), {
|
|
819
|
-
type: t.type,
|
|
820
|
-
messageId: l(t.messageId, "messageId")
|
|
821
|
-
};
|
|
822
|
-
case "artifact":
|
|
823
|
-
return E(t, /* @__PURE__ */ new Set(["type", "messageId", "artifact"])), {
|
|
824
|
-
type: t.type,
|
|
825
|
-
messageId: l(t.messageId, "messageId"),
|
|
826
|
-
artifact: H(t.artifact)
|
|
827
|
-
};
|
|
828
|
-
case "run.progress":
|
|
829
|
-
return E(t, /* @__PURE__ */ new Set(["type", "runId", "message"])), {
|
|
830
|
-
type: t.type,
|
|
831
|
-
runId: l(t.runId, "runId"),
|
|
832
|
-
message: l(
|
|
833
|
-
t.message,
|
|
834
|
-
"message",
|
|
835
|
-
f.messageCharacters
|
|
836
|
-
)
|
|
837
|
-
};
|
|
838
|
-
case "error":
|
|
839
|
-
if (E(t, /* @__PURE__ */ new Set([
|
|
840
|
-
"type",
|
|
841
|
-
"code",
|
|
842
|
-
"message",
|
|
843
|
-
"retryable",
|
|
844
|
-
"requestId"
|
|
845
|
-
])), typeof t.retryable != "boolean")
|
|
846
|
-
throw new Error("Invalid assistant event: retryable");
|
|
847
|
-
return {
|
|
848
|
-
type: t.type,
|
|
849
|
-
code: l(t.code, "code"),
|
|
850
|
-
message: l(
|
|
851
|
-
t.message,
|
|
852
|
-
"message",
|
|
853
|
-
f.messageCharacters
|
|
854
|
-
),
|
|
855
|
-
retryable: t.retryable,
|
|
856
|
-
requestId: t.requestId === void 0 ? void 0 : l(t.requestId, "requestId")
|
|
857
|
-
};
|
|
858
|
-
case "run.cancelled":
|
|
859
|
-
return E(t, /* @__PURE__ */ new Set(["type", "runId"])), {
|
|
860
|
-
type: t.type,
|
|
861
|
-
runId: t.runId === void 0 ? void 0 : l(t.runId, "runId")
|
|
862
|
-
};
|
|
863
|
-
case "run.complete":
|
|
864
|
-
return E(t, /* @__PURE__ */ new Set(["type", "runId", "threadId"])), {
|
|
865
|
-
type: t.type,
|
|
866
|
-
runId: l(t.runId, "runId"),
|
|
867
|
-
threadId: l(t.threadId, "threadId")
|
|
868
|
-
};
|
|
869
|
-
default:
|
|
870
|
-
throw new Error("Invalid assistant event: unsupported type");
|
|
871
|
-
}
|
|
872
|
-
}, qt = (t) => {
|
|
873
|
-
try {
|
|
874
|
-
return vt(t);
|
|
875
|
-
} catch (e) {
|
|
876
|
-
throw e instanceof Error && (e.message.startsWith("Invalid assistant event:") || e.message.startsWith("Invalid Make AI Artifact:")) ? e : new Error("Invalid assistant event: data");
|
|
877
|
-
}
|
|
878
|
-
}, Mt = (t) => {
|
|
879
|
-
if (!D(t))
|
|
880
|
-
throw new Error("Invalid assistant conversation snapshot: data");
|
|
881
|
-
if (E(t, /* @__PURE__ */ new Set(["threadId", "messages", "nextCursor", "hasMore"])), !Array.isArray(t.messages) || t.messages.length > f.historyMessages)
|
|
882
|
-
throw new Error("Invalid assistant conversation snapshot: messages");
|
|
883
|
-
const e = /* @__PURE__ */ new Set();
|
|
884
|
-
let s = 0, n = 0;
|
|
885
|
-
return {
|
|
886
|
-
messages: t.messages.map((r) => {
|
|
887
|
-
if (!D(r))
|
|
888
|
-
throw new Error("Invalid assistant conversation snapshot: message");
|
|
889
|
-
E(r, /* @__PURE__ */ new Set(["id", "role", "content", "artifacts", "responseId", "parts", "persistent", "cursor", "createdAt", "feedback"]));
|
|
890
|
-
const o = l(r.id, "messageId");
|
|
891
|
-
if (e.has(o))
|
|
892
|
-
throw new Error("Invalid assistant conversation snapshot: duplicate message id");
|
|
893
|
-
if (e.add(o), r.role !== "assistant" && r.role !== "user")
|
|
894
|
-
throw new Error("Invalid assistant conversation snapshot: role");
|
|
895
|
-
const d = r.role, p = typeof r.content == "string" ? j(
|
|
896
|
-
r.content,
|
|
897
|
-
f.messageCharacters
|
|
898
|
-
) : 0;
|
|
899
|
-
if (typeof r.content != "string" || p > f.messageCharacters)
|
|
900
|
-
throw new Error("Invalid assistant conversation snapshot: content");
|
|
901
|
-
if (s += j(
|
|
902
|
-
r.content,
|
|
903
|
-
f.historyCharacters - s
|
|
904
|
-
), s > f.historyCharacters)
|
|
905
|
-
throw new Error("Invalid assistant conversation snapshot: content budget");
|
|
906
|
-
if (r.artifacts !== void 0 && (!Array.isArray(r.artifacts) || r.artifacts.length > f.artifactsPerRun))
|
|
907
|
-
throw new Error("Invalid assistant conversation snapshot: artifacts");
|
|
908
|
-
const i = (r.artifacts ?? []).map(H), c = /* @__PURE__ */ new Set();
|
|
909
|
-
for (const g of i) {
|
|
910
|
-
if (c.has(g.id))
|
|
911
|
-
throw new Error(
|
|
912
|
-
"Invalid assistant conversation snapshot: duplicate artifact id"
|
|
913
|
-
);
|
|
914
|
-
c.add(g.id);
|
|
915
|
-
}
|
|
916
|
-
if (n += i.length, n > f.historyArtifacts)
|
|
917
|
-
throw new Error("Invalid assistant conversation snapshot: artifact budget");
|
|
918
|
-
return {
|
|
919
|
-
id: o,
|
|
920
|
-
role: d,
|
|
921
|
-
content: r.content,
|
|
922
|
-
artifacts: i,
|
|
923
|
-
status: "complete",
|
|
924
|
-
...r.responseId === void 0 ? {} : { responseId: l(r.responseId, "responseId") },
|
|
925
|
-
...r.parts === void 0 ? {} : { parts: L(r.parts) },
|
|
926
|
-
...r.feedback === void 0 ? {} : { feedback: X(r.feedback) },
|
|
927
|
-
...r.persistent === void 0 ? {} : { persistent: q(r.persistent) },
|
|
928
|
-
...r.cursor === void 0 ? {} : { cursor: N(r.cursor) },
|
|
929
|
-
...r.createdAt === void 0 ? {} : { createdAt: l(r.createdAt, "createdAt") }
|
|
930
|
-
};
|
|
931
|
-
}),
|
|
932
|
-
status: "idle",
|
|
933
|
-
threadId: t.threadId === void 0 ? void 0 : l(t.threadId, "threadId")
|
|
934
|
-
};
|
|
935
|
-
}, Yt = (t) => t === void 0 ? { messages: [], status: "idle" } : Mt(t), Vt = (t, e) => ({
|
|
936
|
-
...t,
|
|
937
|
-
error: void 0,
|
|
938
|
-
progress: void 0,
|
|
939
|
-
status: "streaming",
|
|
940
|
-
messages: [
|
|
941
|
-
...t.messages,
|
|
942
|
-
{
|
|
943
|
-
id: e.id,
|
|
944
|
-
role: "user",
|
|
945
|
-
content: e.content,
|
|
946
|
-
...e.parts === void 0 ? {} : { parts: e.parts },
|
|
947
|
-
artifacts: [],
|
|
948
|
-
status: "complete"
|
|
949
|
-
}
|
|
950
|
-
]
|
|
951
|
-
}), K = (t, e, s) => ({
|
|
952
|
-
...t,
|
|
953
|
-
messages: t.messages.map(
|
|
954
|
-
(n) => n.id === e ? s(n) : n
|
|
955
|
-
)
|
|
956
|
-
}), Q = (t) => {
|
|
957
|
-
const e = t.slice(-f.progressStepsPerRun), s = [];
|
|
958
|
-
let n = 0;
|
|
959
|
-
for (let a = e.length - 1; a >= 0; a -= 1) {
|
|
960
|
-
const r = e[a], o = j(
|
|
961
|
-
r,
|
|
962
|
-
f.progressCharactersPerRun - n
|
|
963
|
-
);
|
|
964
|
-
if (n + o > f.progressCharactersPerRun) break;
|
|
965
|
-
n += o, s.unshift(r);
|
|
966
|
-
}
|
|
967
|
-
return s;
|
|
968
|
-
}, Kt = (t, e) => {
|
|
969
|
-
let s = -1;
|
|
970
|
-
for (let n = t.length - 1; n >= 0; n -= 1) {
|
|
971
|
-
const a = t[n];
|
|
972
|
-
if (a.role === "assistant" && a.status === "streaming") {
|
|
973
|
-
s = n;
|
|
974
|
-
break;
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
return s < 0 ? t : t.map(
|
|
978
|
-
(n, a) => a === s ? {
|
|
979
|
-
...n,
|
|
980
|
-
progressSteps: Q([...n.progressSteps ?? [], e])
|
|
981
|
-
} : n
|
|
982
|
-
);
|
|
983
|
-
}, Dt = (t, e) => {
|
|
984
|
-
if (e.type.startsWith("response.")) return jt(t, e);
|
|
985
|
-
switch (e.type) {
|
|
986
|
-
case "message.start": {
|
|
987
|
-
const s = t.progress?.runId === e.runId ? t.progress.steps : void 0;
|
|
988
|
-
return {
|
|
989
|
-
...t,
|
|
990
|
-
activeRunId: e.runId,
|
|
991
|
-
error: void 0,
|
|
992
|
-
progress: t.progress?.runId === e.runId ? t.progress : void 0,
|
|
993
|
-
status: "streaming",
|
|
994
|
-
messages: [
|
|
995
|
-
...t.messages,
|
|
996
|
-
{
|
|
997
|
-
id: e.messageId,
|
|
998
|
-
role: "assistant",
|
|
999
|
-
content: "",
|
|
1000
|
-
artifacts: [],
|
|
1001
|
-
progressSteps: s,
|
|
1002
|
-
status: "streaming"
|
|
1003
|
-
}
|
|
1004
|
-
]
|
|
1005
|
-
};
|
|
1006
|
-
}
|
|
1007
|
-
case "message.delta":
|
|
1008
|
-
return K(t, e.messageId, (s) => ({
|
|
1009
|
-
...s,
|
|
1010
|
-
content: `${s.content}${e.delta}`
|
|
1011
|
-
}));
|
|
1012
|
-
case "message.replace":
|
|
1013
|
-
return K(t, e.messageId, (s) => ({
|
|
1014
|
-
...s,
|
|
1015
|
-
content: e.content
|
|
1016
|
-
}));
|
|
1017
|
-
case "artifact":
|
|
1018
|
-
return K(t, e.messageId, (s) => ({
|
|
1019
|
-
...s,
|
|
1020
|
-
artifacts: [...s.artifacts, e.artifact]
|
|
1021
|
-
}));
|
|
1022
|
-
case "message.complete":
|
|
1023
|
-
return K(t, e.messageId, (s) => ({
|
|
1024
|
-
...s,
|
|
1025
|
-
status: "complete"
|
|
1026
|
-
}));
|
|
1027
|
-
case "run.progress": {
|
|
1028
|
-
const s = Q(
|
|
1029
|
-
t.progress?.runId === e.runId ? [...t.progress.steps, e.message] : [e.message]
|
|
1030
|
-
);
|
|
1031
|
-
return {
|
|
1032
|
-
...t,
|
|
1033
|
-
messages: Kt(
|
|
1034
|
-
t.messages,
|
|
1035
|
-
e.message
|
|
1036
|
-
),
|
|
1037
|
-
progress: {
|
|
1038
|
-
runId: e.runId,
|
|
1039
|
-
message: e.message,
|
|
1040
|
-
steps: s
|
|
1041
|
-
}
|
|
1042
|
-
};
|
|
1043
|
-
}
|
|
1044
|
-
case "error": {
|
|
1045
|
-
const s = {
|
|
1046
|
-
code: e.code,
|
|
1047
|
-
message: e.message,
|
|
1048
|
-
retryable: e.retryable,
|
|
1049
|
-
requestId: e.requestId
|
|
1050
|
-
};
|
|
1051
|
-
return {
|
|
1052
|
-
...t,
|
|
1053
|
-
activeRunId: void 0,
|
|
1054
|
-
error: s,
|
|
1055
|
-
progress: void 0,
|
|
1056
|
-
messages: t.messages.map(
|
|
1057
|
-
(n) => n.status === "streaming" ? { ...n, error: s, status: "complete" } : n
|
|
1058
|
-
),
|
|
1059
|
-
status: "error"
|
|
1060
|
-
};
|
|
1061
|
-
}
|
|
1062
|
-
case "run.cancelled":
|
|
1063
|
-
return {
|
|
1064
|
-
...t,
|
|
1065
|
-
activeRunId: void 0,
|
|
1066
|
-
progress: void 0,
|
|
1067
|
-
status: "idle",
|
|
1068
|
-
messages: t.messages.map(
|
|
1069
|
-
(s) => s.status === "streaming" ? { ...s, status: "complete" } : s
|
|
1070
|
-
)
|
|
1071
|
-
};
|
|
1072
|
-
case "run.complete":
|
|
1073
|
-
return {
|
|
1074
|
-
...t,
|
|
1075
|
-
activeRunId: void 0,
|
|
1076
|
-
error: void 0,
|
|
1077
|
-
progress: void 0,
|
|
1078
|
-
messages: t.messages.map(
|
|
1079
|
-
(s) => s.status === "streaming" ? { ...s, status: "complete" } : s
|
|
1080
|
-
),
|
|
1081
|
-
status: "idle",
|
|
1082
|
-
threadId: e.threadId
|
|
1083
|
-
};
|
|
1084
|
-
}
|
|
1085
|
-
return t;
|
|
1086
|
-
};
|
|
1087
|
-
export {
|
|
1088
|
-
f as M,
|
|
1089
|
-
L as a,
|
|
1090
|
-
S as b,
|
|
1091
|
-
j as c,
|
|
1092
|
-
x as d,
|
|
1093
|
-
N as e,
|
|
1094
|
-
F as f,
|
|
1095
|
-
xt as g,
|
|
1096
|
-
y as h,
|
|
1097
|
-
q as i,
|
|
1098
|
-
X as j,
|
|
1099
|
-
k,
|
|
1100
|
-
qt as l,
|
|
1101
|
-
Nt as m,
|
|
1102
|
-
Yt as n,
|
|
1103
|
-
Vt as o,
|
|
1104
|
-
h as p,
|
|
1105
|
-
Z as q,
|
|
1106
|
-
Dt as r,
|
|
1107
|
-
m as s,
|
|
1108
|
-
Pt as t,
|
|
1109
|
-
H as u,
|
|
1110
|
-
$t as v
|
|
1111
|
-
};
|