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