@qfei-design/make-ai-assistant 0.1.0 → 0.1.2

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.
@@ -0,0 +1,684 @@
1
+ const k = (t, e) => {
2
+ let r = 0;
3
+ for (const a of t)
4
+ if (r += 1, r > e) break;
5
+ return r;
6
+ }, gt = "1.0", o = {
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
+ }, g = {
21
+ artifactsPerRun: 50,
22
+ assistantMessagesPerRun: 20,
23
+ historyArtifacts: 500,
24
+ historyCharacters: 1e6,
25
+ historyMessages: 200,
26
+ identifierCharacters: 1e3,
27
+ messageCharacters: 1e5
28
+ }, P = [
29
+ "metric",
30
+ "comparison",
31
+ "trend",
32
+ "ranking",
33
+ "record-list",
34
+ "notice"
35
+ ], $ = () => ({
36
+ success: !1,
37
+ issues: [{ path: "", message: "could not be safely inspected" }]
38
+ }), V = /* @__PURE__ */ new Set(["navigate", "open-record", "open-list", "invoke"]), D = /* @__PURE__ */ new Set(["decimal", "currency", "percent"]);
39
+ class v extends Array {
40
+ push(...e) {
41
+ const r = o.validationIssues - this.length;
42
+ return r > 0 ? super.push(...e.slice(0, r)) : this.length;
43
+ }
44
+ }
45
+ const c = (t) => (() => {
46
+ if (typeof t != "object" || t === null || Array.isArray(t))
47
+ return !1;
48
+ const e = Object.getPrototypeOf(t);
49
+ return e === Object.prototype || e === null;
50
+ })(), M = (t) => typeof t == "string" && t.trim().length > 0, R = (t, e) => {
51
+ let r = 0;
52
+ for (const a of t)
53
+ if (r += 1, r > e) return r;
54
+ return r;
55
+ }, u = (t) => typeof t == "string" && R(t, o.textCharacters) <= o.textCharacters, b = (t) => typeof t == "number" && Number.isFinite(t), q = (t) => t.length <= 120 ? t : `${t.slice(0, 117)}...`, m = (t, e, r) => {
56
+ M(t) ? u(t) || r.push({
57
+ path: e,
58
+ message: `must contain at most ${o.textCharacters} characters`
59
+ }) : r.push({ path: e, message: "must be a non-empty string" });
60
+ }, I = (t, e, r) => {
61
+ t !== void 0 && typeof t != "string" ? r.push({ path: e, message: "must be a string" }) : typeof t == "string" && !u(t) && r.push({
62
+ path: e,
63
+ message: `must contain at most ${o.textCharacters} characters`
64
+ });
65
+ }, d = (t, e, r, a) => {
66
+ for (const s in t)
67
+ if (Object.prototype.hasOwnProperty.call(t, s)) {
68
+ if (a.length >= o.validationIssues) break;
69
+ e.has(s) || a.push({
70
+ path: q(r ? `${r}.${s}` : s),
71
+ message: "is not supported"
72
+ });
73
+ }
74
+ }, w = (t, e, r, a) => t.length > e ? (a.push({ path: r, message: `must contain at most ${e} items` }), !0) : !1, S = (t, e, r) => {
75
+ for (let a = 0; a < t.length; a += 1)
76
+ if (!Object.prototype.hasOwnProperty.call(t, a))
77
+ return r.push({ path: e, message: "must not contain empty array slots" }), !0;
78
+ return !1;
79
+ }, E = (t, e, r, a) => {
80
+ const s = /* @__PURE__ */ new Set();
81
+ t.forEach((n, f) => {
82
+ if (!c(n) || typeof n[e] != "string") return;
83
+ const i = n[e];
84
+ s.has(i) ? a.push({
85
+ path: `${r}[${f}].${e}`,
86
+ message: "must be unique within the collection"
87
+ }) : s.add(i);
88
+ });
89
+ }, L = /* @__PURE__ */ new Set([
90
+ "schemaVersion",
91
+ "id",
92
+ "kind",
93
+ "title",
94
+ "summary",
95
+ "presentation",
96
+ "actions",
97
+ "meta",
98
+ "data"
99
+ ]), F = /* @__PURE__ */ new Set(["template", "density"]), z = /* @__PURE__ */ new Set(["style", "currency", "precision", "unit"]), J = /* @__PURE__ */ new Set(["id", "label", "intent", "target", "appearance"]), U = /* @__PURE__ */ new Set(["value", "format", "delta", "context"]), B = /* @__PURE__ */ new Set(["value", "format", "direction", "label"]), K = /* @__PURE__ */ new Set(["items"]), W = /* @__PURE__ */ new Set(["id", "label", "value", "format", "hint"]), H = /* @__PURE__ */ new Set(["series"]), G = /* @__PURE__ */ new Set(["id", "label", "points", "format"]), Q = /* @__PURE__ */ new Set(["x", "y"]), X = /* @__PURE__ */ new Set([
100
+ "id",
101
+ "label",
102
+ "value",
103
+ "format",
104
+ "description"
105
+ ]), Z = /* @__PURE__ */ new Set(["entity", "columns", "records", "total"]), tt = /* @__PURE__ */ new Set(["key", "label"]), et = /* @__PURE__ */ new Set(["key", "label", "format"]), rt = /* @__PURE__ */ new Set(["id", "title", "values", "action"]), nt = /* @__PURE__ */ new Set(["tone", "body"]), A = (t, e, r) => c(t) ? (d(t, z, e, r), t.style !== void 0 && (typeof t.style != "string" || !D.has(t.style)) && r.push({ path: `${e}.style`, message: "is not supported" }), t.currency !== void 0 && m(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" }), I(t.unit, `${e}.unit`, r), !0) : (r.push({ path: e, message: "must be an object" }), !1), _ = (t) => {
106
+ const e = [{ kind: "visit", depth: 0, value: t }], r = /* @__PURE__ */ new WeakSet();
107
+ let a = 0, s = 0;
108
+ try {
109
+ for (; e.length > 0; ) {
110
+ const n = e.pop();
111
+ if (!n) break;
112
+ if (n.kind === "leave") {
113
+ r.delete(n.value);
114
+ continue;
115
+ }
116
+ if (s += 1, s > o.jsonNodes || n.depth > o.jsonDepth)
117
+ return !1;
118
+ if (n.value === null || typeof n.value == "boolean")
119
+ continue;
120
+ if (typeof n.value == "string") {
121
+ if (a += R(
122
+ n.value,
123
+ o.textCharacters
124
+ ), !u(n.value) || a > o.jsonCharacters) return !1;
125
+ continue;
126
+ }
127
+ if (typeof n.value == "number") {
128
+ if (!Number.isFinite(n.value)) return !1;
129
+ continue;
130
+ }
131
+ if (!Array.isArray(n.value) && !c(n.value) || r.has(n.value)) return !1;
132
+ r.add(n.value), e.push({ kind: "leave", value: n.value });
133
+ const f = o.jsonNodes - s;
134
+ if (Array.isArray(n.value)) {
135
+ if (n.value.length > f) return !1;
136
+ for (let i = n.value.length - 1; i >= 0; i -= 1)
137
+ e.push({
138
+ kind: "visit",
139
+ depth: n.depth + 1,
140
+ value: n.value[i]
141
+ });
142
+ } else {
143
+ const i = [];
144
+ for (const h in n.value)
145
+ if (Object.prototype.hasOwnProperty.call(n.value, h)) {
146
+ if (!u(h) || (a += R(
147
+ h,
148
+ o.textCharacters
149
+ ), a > o.jsonCharacters) || i.length >= f) return !1;
150
+ i.push(h);
151
+ }
152
+ for (let h = i.length - 1; h >= 0; h -= 1) {
153
+ const y = i[h];
154
+ e.push({
155
+ kind: "visit",
156
+ depth: n.depth + 1,
157
+ value: n.value[y]
158
+ });
159
+ }
160
+ }
161
+ }
162
+ return !0;
163
+ } catch {
164
+ return !1;
165
+ }
166
+ }, at = (t) => t === null || typeof t == "boolean" || u(t) || b(t), x = (t, e, r) => c(t) ? (d(t, J, e, r), m(t.id, `${e}.id`, r), m(t.label, `${e}.label`, r), (typeof t.intent != "string" || !V.has(t.intent)) && r.push({ path: `${e}.intent`, message: "is not supported" }), (!c(t.target) || !_(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), st = (t, e) => {
167
+ if (d(t, L, "", e), t.schemaVersion !== "1.0" && e.push({ path: "schemaVersion", message: "must equal 1.0" }), m(t.id, "id", e), P.includes(t.kind) || e.push({ path: "kind", message: "is not a supported Artifact kind" }), I(t.title, "title", e), I(t.summary, "summary", e), t.presentation !== void 0 && (c(t.presentation) ? (d(t.presentation, F, "presentation", e), t.presentation.template !== void 0 && !M(t.presentation.template) ? e.push({ path: "presentation.template", message: "must be a non-empty string" }) : t.presentation.template !== void 0 && !u(t.presentation.template) && e.push({
168
+ path: "presentation.template",
169
+ message: `must contain at most ${o.textCharacters} characters`
170
+ }), 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) {
171
+ if (!Array.isArray(t.actions))
172
+ e.push({ path: "actions", message: "must be an array" });
173
+ else if (!w(
174
+ t.actions,
175
+ o.actions,
176
+ "actions",
177
+ e
178
+ )) {
179
+ if (S(t.actions, "actions", e)) return;
180
+ E(t.actions, "id", "actions", e), t.actions.forEach(
181
+ (a, s) => x(a, `actions[${s}]`, e)
182
+ );
183
+ }
184
+ }
185
+ t.meta !== void 0 && (!c(t.meta) || !_(t.meta)) && e.push({ path: "meta", message: "must be a JSON object" });
186
+ }, ot = (t, e) => {
187
+ d(t, U, "data", e), !b(t.value) && !u(t.value) && e.push({ path: "data.value", message: "must be a finite number or string" }), t.format !== void 0 && A(t.format, "data.format", e), t.delta !== void 0 && (c(t.delta) ? (d(
188
+ t.delta,
189
+ B,
190
+ "data.delta",
191
+ e
192
+ ), b(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" }), I(t.delta.label, "data.delta.label", e)) : e.push({ path: "data.delta", message: "must be an object" })), I(t.context, "data.context", e);
193
+ }, it = (t, e) => {
194
+ if (d(t, K, "data", e), !Array.isArray(t.items) || t.items.length === 0) {
195
+ e.push({ path: "data.items", message: "must be a non-empty array" });
196
+ return;
197
+ }
198
+ w(
199
+ t.items,
200
+ o.comparisonItems,
201
+ "data.items",
202
+ e
203
+ ) || S(t.items, "data.items", e) || (E(t.items, "id", "data.items", e), t.items.forEach((r, a) => {
204
+ const s = `data.items[${a}]`;
205
+ if (!c(r)) {
206
+ e.push({ path: s, message: "must be an object" });
207
+ return;
208
+ }
209
+ d(
210
+ r,
211
+ W,
212
+ s,
213
+ e
214
+ ), m(r.id, `${s}.id`, e), m(r.label, `${s}.label`, e), !b(r.value) && !u(r.value) && e.push({ path: `${s}.value`, message: "must be a finite number or string" }), r.format !== void 0 && A(r.format, `${s}.format`, e), I(r.hint, `${s}.hint`, e);
215
+ }));
216
+ }, ct = (t, e) => {
217
+ if (d(t, H, "data", e), !Array.isArray(t.series) || t.series.length === 0) {
218
+ e.push({ path: "data.series", message: "must be a non-empty array" });
219
+ return;
220
+ }
221
+ w(
222
+ t.series,
223
+ o.trendSeries,
224
+ "data.series",
225
+ e
226
+ ) || S(t.series, "data.series", e) || (E(t.series, "id", "data.series", e), t.series.forEach((r, a) => {
227
+ const s = `data.series[${a}]`;
228
+ if (!c(r)) {
229
+ e.push({ path: s, message: "must be an object" });
230
+ return;
231
+ }
232
+ if (d(
233
+ r,
234
+ G,
235
+ s,
236
+ e
237
+ ), m(r.id, `${s}.id`, e), m(r.label, `${s}.label`, e), r.format !== void 0 && A(r.format, `${s}.format`, e), !Array.isArray(r.points) || r.points.length === 0) {
238
+ e.push({ path: `${s}.points`, message: "must be a non-empty array" });
239
+ return;
240
+ }
241
+ w(
242
+ r.points,
243
+ o.trendPointsPerSeries,
244
+ `${s}.points`,
245
+ e
246
+ ) || S(r.points, `${s}.points`, e) || r.points.forEach((n, f) => {
247
+ const i = `${s}.points[${f}]`;
248
+ if (!c(n)) {
249
+ e.push({ path: i, message: "must be an object" });
250
+ return;
251
+ }
252
+ d(n, Q, i, e), !b(n.x) && !u(n.x) && e.push({ path: `${i}.x`, message: "must be a finite number or string" }), b(n.y) || e.push({ path: `${i}.y`, message: "must be a finite number" });
253
+ });
254
+ }));
255
+ }, dt = (t, e) => {
256
+ if (d(t, K, "data", e), !Array.isArray(t.items) || t.items.length === 0) {
257
+ e.push({ path: "data.items", message: "must be a non-empty array" });
258
+ return;
259
+ }
260
+ w(
261
+ t.items,
262
+ o.rankingItems,
263
+ "data.items",
264
+ e
265
+ ) || S(t.items, "data.items", e) || (E(t.items, "id", "data.items", e), t.items.forEach((r, a) => {
266
+ const s = `data.items[${a}]`;
267
+ if (!c(r)) {
268
+ e.push({ path: s, message: "must be an object" });
269
+ return;
270
+ }
271
+ d(
272
+ r,
273
+ X,
274
+ s,
275
+ e
276
+ ), m(r.id, `${s}.id`, e), m(r.label, `${s}.label`, e), b(r.value) || e.push({ path: `${s}.value`, message: "must be a finite number" }), r.format !== void 0 && A(r.format, `${s}.format`, e), I(r.description, `${s}.description`, e);
277
+ }));
278
+ }, pt = (t, e) => {
279
+ if (d(
280
+ t,
281
+ Z,
282
+ "data",
283
+ e
284
+ ), c(t.entity) ? (d(t.entity, tt, "data.entity", e), m(t.entity.key, "data.entity.key", e), I(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)
285
+ e.push({ path: "data.columns", message: "must be a non-empty array" });
286
+ else if (!w(
287
+ t.columns,
288
+ o.recordColumns,
289
+ "data.columns",
290
+ e
291
+ )) {
292
+ if (S(t.columns, "data.columns", e)) return;
293
+ E(t.columns, "key", "data.columns", e), t.columns.forEach((a, s) => {
294
+ const n = `data.columns[${s}]`;
295
+ if (!c(a)) {
296
+ e.push({ path: n, message: "must be an object" });
297
+ return;
298
+ }
299
+ d(
300
+ a,
301
+ et,
302
+ n,
303
+ e
304
+ ), m(a.key, `${n}.key`, e), m(a.label, `${n}.label`, e), a.format !== void 0 && A(a.format, `${n}.format`, e);
305
+ });
306
+ }
307
+ if (!Array.isArray(t.records))
308
+ e.push({ path: "data.records", message: "must be an array" });
309
+ else if (!w(
310
+ t.records,
311
+ o.recordListRecords,
312
+ "data.records",
313
+ e
314
+ )) {
315
+ if (S(t.records, "data.records", e)) return;
316
+ E(t.records, "id", "data.records", e), t.records.forEach((a, s) => {
317
+ const n = `data.records[${s}]`;
318
+ if (!c(a)) {
319
+ e.push({ path: n, message: "must be an object" });
320
+ return;
321
+ }
322
+ if (d(
323
+ a,
324
+ rt,
325
+ n,
326
+ e
327
+ ), m(a.id, `${n}.id`, e), I(a.title, `${n}.title`, e), !c(a.values))
328
+ e.push({
329
+ path: `${n}.values`,
330
+ message: "must contain only JSON primitive display values"
331
+ });
332
+ else {
333
+ const f = a.values;
334
+ let i = !1, h = 0;
335
+ for (const y in f)
336
+ if (Object.prototype.hasOwnProperty.call(f, y)) {
337
+ if (h += 1, h > o.recordValues) break;
338
+ i ||= !u(y) || !at(f[y]);
339
+ }
340
+ h > o.recordValues ? e.push({
341
+ path: `${n}.values`,
342
+ message: `must contain at most ${o.recordValues} values`
343
+ }) : i && e.push({
344
+ path: `${n}.values`,
345
+ message: "must contain only JSON primitive display values"
346
+ });
347
+ }
348
+ a.action !== void 0 && x(a.action, `${n}.action`, e);
349
+ });
350
+ }
351
+ t.total !== void 0 && (!Number.isInteger(t.total) || Number(t.total) < 0) && e.push({ path: "data.total", message: "must be a non-negative integer" });
352
+ }, mt = (t, e) => {
353
+ d(t, nt, "data", e), (typeof t.tone != "string" || !["info", "success", "warning", "danger"].includes(t.tone)) && e.push({ path: "data.tone", message: "is not supported" }), m(t.body, "data.body", e);
354
+ }, j = (t, e) => {
355
+ if (st(t, e), !c(t.data)) {
356
+ e.push({ path: "data", message: "must be an object" });
357
+ return;
358
+ }
359
+ switch (t.kind) {
360
+ case "metric":
361
+ ot(t.data, e);
362
+ break;
363
+ case "comparison":
364
+ it(t.data, e);
365
+ break;
366
+ case "trend":
367
+ ct(t.data, e);
368
+ break;
369
+ case "ranking":
370
+ dt(t.data, e);
371
+ break;
372
+ case "record-list":
373
+ pt(t.data, e);
374
+ break;
375
+ case "notice":
376
+ mt(t.data, e);
377
+ break;
378
+ }
379
+ }, ft = (t) => {
380
+ const e = new v();
381
+ try {
382
+ if (!c(t))
383
+ return { success: !1, issues: [{ path: "", message: "must be an object" }] };
384
+ j(t, e);
385
+ } catch {
386
+ return $();
387
+ }
388
+ if (e.length > 0) return { success: !1, issues: e };
389
+ if (!_(t))
390
+ return {
391
+ success: !1,
392
+ issues: [{ path: "", message: "exceeds the Artifact resource budget" }]
393
+ };
394
+ let r;
395
+ try {
396
+ r = structuredClone(t);
397
+ } catch {
398
+ return $();
399
+ }
400
+ const a = new v();
401
+ try {
402
+ if (!c(r)) return $();
403
+ j(r, a);
404
+ } catch {
405
+ return $();
406
+ }
407
+ return a.length === 0 && !_(r) && a.push({
408
+ path: "",
409
+ message: "exceeds the Artifact resource budget"
410
+ }), a.length === 0 ? { success: !0, artifact: r } : { success: !1, issues: a };
411
+ }, Y = (t) => {
412
+ const e = ft(t);
413
+ if (e.success) return e.artifact;
414
+ const r = e.issues.map((a) => `${a.path || "artifact"} ${a.message}`).join(", ");
415
+ throw new Error(`Invalid Make AI Artifact: ${r}`);
416
+ }, N = (t) => typeof t == "object" && t !== null && !Array.isArray(t), l = (t, e) => {
417
+ if (Object.keys(t).some((r) => !e.has(r)))
418
+ throw new Error("Invalid assistant event: unsupported field");
419
+ }, p = (t, e, r = g.identifierCharacters) => {
420
+ const a = typeof t == "string" ? k(t, r) : 0;
421
+ if (typeof t != "string" || !t.trim() || a > r)
422
+ throw new Error(`Invalid assistant event: ${e}`);
423
+ return t;
424
+ }, ht = (t) => {
425
+ if (!N(t) || typeof t.type != "string")
426
+ throw new Error("Invalid assistant event: data");
427
+ switch (t.type) {
428
+ case "message.start":
429
+ return l(t, /* @__PURE__ */ new Set(["type", "runId", "messageId"])), {
430
+ type: t.type,
431
+ runId: p(t.runId, "runId"),
432
+ messageId: p(t.messageId, "messageId")
433
+ };
434
+ case "message.delta":
435
+ if (l(t, /* @__PURE__ */ new Set(["type", "messageId", "delta"])), typeof t.delta != "string")
436
+ throw new Error("Invalid assistant event: delta");
437
+ return {
438
+ type: t.type,
439
+ messageId: p(t.messageId, "messageId"),
440
+ delta: t.delta
441
+ };
442
+ case "message.replace":
443
+ return l(t, /* @__PURE__ */ new Set(["type", "messageId", "content"])), {
444
+ type: t.type,
445
+ messageId: p(t.messageId, "messageId"),
446
+ content: p(
447
+ t.content,
448
+ "content",
449
+ g.messageCharacters
450
+ )
451
+ };
452
+ case "message.complete":
453
+ return l(t, /* @__PURE__ */ new Set(["type", "messageId"])), {
454
+ type: t.type,
455
+ messageId: p(t.messageId, "messageId")
456
+ };
457
+ case "artifact":
458
+ return l(t, /* @__PURE__ */ new Set(["type", "messageId", "artifact"])), {
459
+ type: t.type,
460
+ messageId: p(t.messageId, "messageId"),
461
+ artifact: Y(t.artifact)
462
+ };
463
+ case "run.progress":
464
+ return l(t, /* @__PURE__ */ new Set(["type", "runId", "message"])), {
465
+ type: t.type,
466
+ runId: p(t.runId, "runId"),
467
+ message: p(
468
+ t.message,
469
+ "message",
470
+ g.messageCharacters
471
+ )
472
+ };
473
+ case "error":
474
+ if (l(t, /* @__PURE__ */ new Set([
475
+ "type",
476
+ "code",
477
+ "message",
478
+ "retryable",
479
+ "requestId"
480
+ ])), typeof t.retryable != "boolean")
481
+ throw new Error("Invalid assistant event: retryable");
482
+ return {
483
+ type: t.type,
484
+ code: p(t.code, "code"),
485
+ message: p(
486
+ t.message,
487
+ "message",
488
+ g.messageCharacters
489
+ ),
490
+ retryable: t.retryable,
491
+ requestId: t.requestId === void 0 ? void 0 : p(t.requestId, "requestId")
492
+ };
493
+ case "run.cancelled":
494
+ return l(t, /* @__PURE__ */ new Set(["type", "runId"])), {
495
+ type: t.type,
496
+ runId: t.runId === void 0 ? void 0 : p(t.runId, "runId")
497
+ };
498
+ case "run.complete":
499
+ return l(t, /* @__PURE__ */ new Set(["type", "runId", "threadId"])), {
500
+ type: t.type,
501
+ runId: p(t.runId, "runId"),
502
+ threadId: p(t.threadId, "threadId")
503
+ };
504
+ default:
505
+ throw new Error("Invalid assistant event: unsupported type");
506
+ }
507
+ }, ut = (t) => {
508
+ try {
509
+ return ht(t);
510
+ } catch (e) {
511
+ throw e instanceof Error && (e.message.startsWith("Invalid assistant event:") || e.message.startsWith("Invalid Make AI Artifact:")) ? e : new Error("Invalid assistant event: data");
512
+ }
513
+ }, lt = (t) => {
514
+ if (!N(t))
515
+ throw new Error("Invalid assistant conversation snapshot: data");
516
+ if (l(t, /* @__PURE__ */ new Set(["threadId", "messages"])), !Array.isArray(t.messages) || t.messages.length > g.historyMessages)
517
+ throw new Error("Invalid assistant conversation snapshot: messages");
518
+ const e = /* @__PURE__ */ new Set();
519
+ let r = 0, a = 0;
520
+ return {
521
+ messages: t.messages.map((n) => {
522
+ if (!N(n))
523
+ throw new Error("Invalid assistant conversation snapshot: message");
524
+ l(n, /* @__PURE__ */ new Set(["id", "role", "content", "artifacts"]));
525
+ const f = p(n.id, "messageId");
526
+ if (e.has(f))
527
+ throw new Error("Invalid assistant conversation snapshot: duplicate message id");
528
+ if (e.add(f), n.role !== "assistant" && n.role !== "user")
529
+ throw new Error("Invalid assistant conversation snapshot: role");
530
+ const i = n.role, h = typeof n.content == "string" ? k(
531
+ n.content,
532
+ g.messageCharacters
533
+ ) : 0;
534
+ if (typeof n.content != "string" || h > g.messageCharacters)
535
+ throw new Error("Invalid assistant conversation snapshot: content");
536
+ if (r += k(
537
+ n.content,
538
+ g.historyCharacters - r
539
+ ), r > g.historyCharacters)
540
+ throw new Error("Invalid assistant conversation snapshot: content budget");
541
+ if (n.artifacts !== void 0 && (!Array.isArray(n.artifacts) || n.artifacts.length > g.artifactsPerRun))
542
+ throw new Error("Invalid assistant conversation snapshot: artifacts");
543
+ const y = (n.artifacts ?? []).map(Y), T = /* @__PURE__ */ new Set();
544
+ for (const O of y) {
545
+ if (T.has(O.id))
546
+ throw new Error(
547
+ "Invalid assistant conversation snapshot: duplicate artifact id"
548
+ );
549
+ T.add(O.id);
550
+ }
551
+ if (a += y.length, a > g.historyArtifacts)
552
+ throw new Error("Invalid assistant conversation snapshot: artifact budget");
553
+ return {
554
+ id: f,
555
+ role: i,
556
+ content: n.content,
557
+ artifacts: y,
558
+ status: "complete"
559
+ };
560
+ }),
561
+ status: "idle",
562
+ threadId: t.threadId === void 0 ? void 0 : p(t.threadId, "threadId")
563
+ };
564
+ }, yt = (t) => t === void 0 ? { messages: [], status: "idle" } : lt(t), It = (t, e) => ({
565
+ ...t,
566
+ error: void 0,
567
+ progress: void 0,
568
+ status: "streaming",
569
+ messages: [
570
+ ...t.messages,
571
+ {
572
+ id: e.id,
573
+ role: "user",
574
+ content: e.content,
575
+ artifacts: [],
576
+ status: "complete"
577
+ }
578
+ ]
579
+ }), C = (t, e, r) => ({
580
+ ...t,
581
+ messages: t.messages.map(
582
+ (a) => a.id === e ? r(a) : a
583
+ )
584
+ }), bt = (t, e) => {
585
+ switch (e.type) {
586
+ case "message.start":
587
+ return {
588
+ ...t,
589
+ activeRunId: e.runId,
590
+ error: void 0,
591
+ progress: void 0,
592
+ status: "streaming",
593
+ messages: [
594
+ ...t.messages,
595
+ {
596
+ id: e.messageId,
597
+ role: "assistant",
598
+ content: "",
599
+ artifacts: [],
600
+ status: "streaming"
601
+ }
602
+ ]
603
+ };
604
+ case "message.delta":
605
+ return C(t, e.messageId, (r) => ({
606
+ ...r,
607
+ content: `${r.content}${e.delta}`
608
+ }));
609
+ case "message.replace":
610
+ return C(t, e.messageId, (r) => ({
611
+ ...r,
612
+ content: e.content
613
+ }));
614
+ case "artifact":
615
+ return C(t, e.messageId, (r) => ({
616
+ ...r,
617
+ artifacts: [...r.artifacts, e.artifact]
618
+ }));
619
+ case "message.complete":
620
+ return C(t, e.messageId, (r) => ({
621
+ ...r,
622
+ status: "complete"
623
+ }));
624
+ case "run.progress":
625
+ return {
626
+ ...t,
627
+ progress: {
628
+ runId: e.runId,
629
+ message: e.message
630
+ }
631
+ };
632
+ case "error":
633
+ return {
634
+ ...t,
635
+ activeRunId: void 0,
636
+ error: {
637
+ code: e.code,
638
+ message: e.message,
639
+ retryable: e.retryable,
640
+ requestId: e.requestId
641
+ },
642
+ progress: void 0,
643
+ messages: t.messages.map(
644
+ (r) => r.status === "streaming" ? { ...r, status: "complete" } : r
645
+ ),
646
+ status: "error"
647
+ };
648
+ case "run.cancelled":
649
+ return {
650
+ ...t,
651
+ activeRunId: void 0,
652
+ progress: void 0,
653
+ status: "idle",
654
+ messages: t.messages.map(
655
+ (r) => r.status === "streaming" ? { ...r, status: "complete" } : r
656
+ )
657
+ };
658
+ case "run.complete":
659
+ return {
660
+ ...t,
661
+ activeRunId: void 0,
662
+ error: void 0,
663
+ progress: void 0,
664
+ messages: t.messages.map(
665
+ (r) => r.status === "streaming" ? { ...r, status: "complete" } : r
666
+ ),
667
+ status: "idle",
668
+ threadId: e.threadId
669
+ };
670
+ }
671
+ };
672
+ export {
673
+ g as M,
674
+ yt as a,
675
+ It as b,
676
+ k as c,
677
+ P as d,
678
+ o as e,
679
+ gt as f,
680
+ Y as g,
681
+ ut as p,
682
+ bt as r,
683
+ ft as v
684
+ };