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