@marimo-team/islands 0.21.2-dev87 → 0.21.2-dev89
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.
|
@@ -13,7 +13,7 @@ import { I as X, O as logNever, t as Label } from "./label-e5-84vsp.js";
|
|
|
13
13
|
import { a as NumberField, b as DropdownMenuTrigger, d as DropdownMenuContent, p as DropdownMenuItem, r as Input, u as DropdownMenu } from "./input-B8CM-AuM.js";
|
|
14
14
|
import { g as CircleQuestionMark } from "./toDate-COI3hP-5.js";
|
|
15
15
|
import { d as Objects, f as useEventListener, g as Logger, t as Button, y as cn } from "./button-B1ZgJ7Cc.js";
|
|
16
|
-
import { A as custom, B as record, D as any, E as _null, G as unknown, H as string, I as never, J as toJSONSchema, K as safeParseAsync, L as number, M as lazy, N as literal, O as array, R as object$1, T as _instanceof, V as strictObject, W as union, j as discriminatedUnion, k as boolean, w as _enum } from "./Combination-B_FmEi05.js";
|
|
16
|
+
import { A as custom, B as record, D as any, E as _null, G as unknown, H as string, I as never, J as toJSONSchema, K as safeParseAsync, L as number, M as lazy, N as literal, O as array$1, R as object$1, T as _instanceof, V as strictObject, W as union, j as discriminatedUnion, k as boolean, w as _enum } from "./Combination-B_FmEi05.js";
|
|
17
17
|
import { t as require_jsx_runtime } from "./jsx-runtime-9hcJiI23.js";
|
|
18
18
|
import "./react-dom-BKwCWYPW.js";
|
|
19
19
|
import { t as Tooltip } from "./tooltip-DnI4CwIS.js";
|
|
@@ -87,12 +87,12 @@ var BotMessageSquare = createLucideIcon("bot-message-square", [
|
|
|
87
87
|
key: "1v7zrd"
|
|
88
88
|
}]]);
|
|
89
89
|
require_compiler_runtime();
|
|
90
|
-
var import_react = /* @__PURE__ */ __toESM(require_react(), 1), marker$
|
|
90
|
+
var import_react = /* @__PURE__ */ __toESM(require_react(), 1), marker$2 = "vercel.ai.error", symbol$2 = Symbol.for(marker$2), _a$2, _b$1, AISDKError = class e extends (_b$1 = Error, _a$2 = symbol$2, _b$1) {
|
|
91
91
|
constructor({ name: e18, message: v, cause: y }) {
|
|
92
|
-
super(v), this[_a$
|
|
92
|
+
super(v), this[_a$2] = true, this.name = e18, this.cause = y;
|
|
93
93
|
}
|
|
94
94
|
static isInstance(v) {
|
|
95
|
-
return e.hasMarker(v, marker$
|
|
95
|
+
return e.hasMarker(v, marker$2);
|
|
96
96
|
}
|
|
97
97
|
static hasMarker(e18, v) {
|
|
98
98
|
let y = Symbol.for(v);
|
|
@@ -126,132 +126,29 @@ Error message: ${getErrorMessage$1(v)}`,
|
|
|
126
126
|
return AISDKError.hasMarker(e18, marker7$1);
|
|
127
127
|
}
|
|
128
128
|
}, name12$1 = "AI_TypeValidationError", marker13$1 = `vercel.ai.error.${name12$1}`, symbol13$1 = Symbol.for(marker13$1), _a13$1, _b13, TypeValidationError = class e2 extends (_b13 = AISDKError, _a13$1 = symbol13$1, _b13) {
|
|
129
|
-
constructor({ value: e18, cause: v }) {
|
|
129
|
+
constructor({ value: e18, cause: v, context: y }) {
|
|
130
|
+
let b = "Type validation failed";
|
|
131
|
+
if ((y == null ? void 0 : y.field) && (b += ` for ${y.field}`), (y == null ? void 0 : y.entityName) || (y == null ? void 0 : y.entityId)) {
|
|
132
|
+
b += " (";
|
|
133
|
+
let e19 = [];
|
|
134
|
+
y.entityName && e19.push(y.entityName), y.entityId && e19.push(`id: "${y.entityId}"`), b += e19.join(", "), b += ")";
|
|
135
|
+
}
|
|
130
136
|
super({
|
|
131
137
|
name: name12$1,
|
|
132
|
-
message:
|
|
138
|
+
message: `${b}: Value: ${JSON.stringify(e18)}.
|
|
133
139
|
Error message: ${getErrorMessage$1(v)}`,
|
|
134
140
|
cause: v
|
|
135
|
-
}), this[_a13$1] = true, this.value = e18;
|
|
141
|
+
}), this[_a13$1] = true, this.value = e18, this.context = y;
|
|
136
142
|
}
|
|
137
143
|
static isInstance(e18) {
|
|
138
144
|
return AISDKError.hasMarker(e18, marker13$1);
|
|
139
145
|
}
|
|
140
|
-
static wrap({ value: v, cause: y }) {
|
|
141
|
-
|
|
146
|
+
static wrap({ value: v, cause: y, context: b }) {
|
|
147
|
+
var _a, _b, _c;
|
|
148
|
+
return e2.isInstance(y) && y.value === v && ((_a = y.context) == null ? void 0 : _a.field) === (b == null ? void 0 : b.field) && ((_b = y.context) == null ? void 0 : _b.entityName) === (b == null ? void 0 : b.entityName) && ((_c = y.context) == null ? void 0 : _c.entityId) === (b == null ? void 0 : b.entityId) ? y : new e2({
|
|
142
149
|
value: v,
|
|
143
|
-
cause: y
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
}, ParseError = class extends Error {
|
|
147
|
-
constructor(e18, v) {
|
|
148
|
-
super(e18), this.name = "ParseError", this.type = v.type, this.field = v.field, this.value = v.value, this.line = v.line;
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
function noop(e18) {
|
|
152
|
-
}
|
|
153
|
-
function createParser(e18) {
|
|
154
|
-
if (typeof e18 == "function") throw TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");
|
|
155
|
-
let { onEvent: v = noop, onError: y = noop, onRetry: b = noop, onComment: x } = e18, S = "", C = true, w, T = "", E = "";
|
|
156
|
-
function D(e19) {
|
|
157
|
-
let v2 = C ? e19.replace(/^\xEF\xBB\xBF/, "") : e19, [y2, b2] = splitLines(`${S}${v2}`);
|
|
158
|
-
for (let e20 of y2) O(e20);
|
|
159
|
-
S = b2, C = false;
|
|
160
|
-
}
|
|
161
|
-
function O(e19) {
|
|
162
|
-
if (e19 === "") {
|
|
163
|
-
A();
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
if (e19.startsWith(":")) {
|
|
167
|
-
x && x(e19.slice(e19.startsWith(": ") ? 2 : 1));
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
let v2 = e19.indexOf(":");
|
|
171
|
-
if (v2 !== -1) {
|
|
172
|
-
let y2 = e19.slice(0, v2), b2 = e19[v2 + 1] === " " ? 2 : 1;
|
|
173
|
-
k(y2, e19.slice(v2 + b2), e19);
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
k(e19, "", e19);
|
|
177
|
-
}
|
|
178
|
-
function k(e19, v2, x2) {
|
|
179
|
-
switch (e19) {
|
|
180
|
-
case "event":
|
|
181
|
-
E = v2;
|
|
182
|
-
break;
|
|
183
|
-
case "data":
|
|
184
|
-
T = `${T}${v2}
|
|
185
|
-
`;
|
|
186
|
-
break;
|
|
187
|
-
case "id":
|
|
188
|
-
w = v2.includes("\0") ? void 0 : v2;
|
|
189
|
-
break;
|
|
190
|
-
case "retry":
|
|
191
|
-
/^\d+$/.test(v2) ? b(parseInt(v2, 10)) : y(new ParseError(`Invalid \`retry\` value: "${v2}"`, {
|
|
192
|
-
type: "invalid-retry",
|
|
193
|
-
value: v2,
|
|
194
|
-
line: x2
|
|
195
|
-
}));
|
|
196
|
-
break;
|
|
197
|
-
default:
|
|
198
|
-
y(new ParseError(`Unknown field "${e19.length > 20 ? `${e19.slice(0, 20)}\u2026` : e19}"`, {
|
|
199
|
-
type: "unknown-field",
|
|
200
|
-
field: e19,
|
|
201
|
-
value: v2,
|
|
202
|
-
line: x2
|
|
203
|
-
}));
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
function A() {
|
|
208
|
-
T.length > 0 && v({
|
|
209
|
-
id: w,
|
|
210
|
-
event: E || void 0,
|
|
211
|
-
data: T.endsWith("\n") ? T.slice(0, -1) : T
|
|
212
|
-
}), w = void 0, T = "", E = "";
|
|
213
|
-
}
|
|
214
|
-
function j(e19 = {}) {
|
|
215
|
-
S && e19.consume && O(S), C = true, w = void 0, T = "", E = "", S = "";
|
|
216
|
-
}
|
|
217
|
-
return {
|
|
218
|
-
feed: D,
|
|
219
|
-
reset: j
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
function splitLines(e18) {
|
|
223
|
-
let v = [], y = "", b = 0;
|
|
224
|
-
for (; b < e18.length; ) {
|
|
225
|
-
let x = e18.indexOf("\r", b), S = e18.indexOf("\n", b), C = -1;
|
|
226
|
-
if (x !== -1 && S !== -1 ? C = Math.min(x, S) : x === -1 ? S !== -1 && (C = S) : C = x === e18.length - 1 ? -1 : x, C === -1) {
|
|
227
|
-
y = e18.slice(b);
|
|
228
|
-
break;
|
|
229
|
-
} else {
|
|
230
|
-
let y2 = e18.slice(b, C);
|
|
231
|
-
v.push(y2), b = C + 1, e18[b - 1] === "\r" && e18[b] === "\n" && b++;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return [v, y];
|
|
235
|
-
}
|
|
236
|
-
var EventSourceParserStream = class extends TransformStream {
|
|
237
|
-
constructor({ onError: e18, onRetry: v, onComment: y } = {}) {
|
|
238
|
-
let b;
|
|
239
|
-
super({
|
|
240
|
-
start(x) {
|
|
241
|
-
b = createParser({
|
|
242
|
-
onEvent: (e19) => {
|
|
243
|
-
x.enqueue(e19);
|
|
244
|
-
},
|
|
245
|
-
onError(v2) {
|
|
246
|
-
e18 === "terminate" ? x.error(v2) : typeof e18 == "function" && e18(v2);
|
|
247
|
-
},
|
|
248
|
-
onRetry: v,
|
|
249
|
-
onComment: y
|
|
250
|
-
});
|
|
251
|
-
},
|
|
252
|
-
transform(e19) {
|
|
253
|
-
b.feed(e19);
|
|
254
|
-
}
|
|
150
|
+
cause: y,
|
|
151
|
+
context: b
|
|
255
152
|
});
|
|
256
153
|
}
|
|
257
154
|
}, util;
|
|
@@ -661,7 +558,7 @@ var ZodType = class {
|
|
|
661
558
|
}));
|
|
662
559
|
}
|
|
663
560
|
"~validate"(e18) {
|
|
664
|
-
var _a,
|
|
561
|
+
var _a, _b;
|
|
665
562
|
let v = {
|
|
666
563
|
common: {
|
|
667
564
|
issues: [],
|
|
@@ -681,7 +578,7 @@ var ZodType = class {
|
|
|
681
578
|
});
|
|
682
579
|
return isValid(y) ? { value: y.value } : { issues: v.common.issues };
|
|
683
580
|
} catch (e19) {
|
|
684
|
-
((
|
|
581
|
+
((_b = (_a = e19 == null ? void 0 : e19.message) == null ? void 0 : _a.toLowerCase()) == null ? void 0 : _b.includes("encountered")) && (this["~standard"].async = true), v.common = {
|
|
685
582
|
issues: [],
|
|
686
583
|
async: true
|
|
687
584
|
};
|
|
@@ -1946,8 +1843,8 @@ var ZodObject = class e10 extends ZodType {
|
|
|
1946
1843
|
...this._def,
|
|
1947
1844
|
unknownKeys: "strict",
|
|
1948
1845
|
...v === void 0 ? {} : { errorMap: (e18, y) => {
|
|
1949
|
-
var _a,
|
|
1950
|
-
let b = ((
|
|
1846
|
+
var _a, _b;
|
|
1847
|
+
let b = ((_b = (_a = this._def).errorMap) == null ? void 0 : _b.call(_a, e18, y).message) ?? y.defaultError;
|
|
1951
1848
|
return e18.code === "unrecognized_keys" ? { message: errorUtil.errToObj(v).message ?? b } : { message: b };
|
|
1952
1849
|
} }
|
|
1953
1850
|
});
|
|
@@ -2982,7 +2879,118 @@ var ZodFirstPartyTypeKind;
|
|
|
2982
2879
|
(function(e18) {
|
|
2983
2880
|
e18.ZodString = "ZodString", e18.ZodNumber = "ZodNumber", e18.ZodNaN = "ZodNaN", e18.ZodBigInt = "ZodBigInt", e18.ZodBoolean = "ZodBoolean", e18.ZodDate = "ZodDate", e18.ZodSymbol = "ZodSymbol", e18.ZodUndefined = "ZodUndefined", e18.ZodNull = "ZodNull", e18.ZodAny = "ZodAny", e18.ZodUnknown = "ZodUnknown", e18.ZodNever = "ZodNever", e18.ZodVoid = "ZodVoid", e18.ZodArray = "ZodArray", e18.ZodObject = "ZodObject", e18.ZodUnion = "ZodUnion", e18.ZodDiscriminatedUnion = "ZodDiscriminatedUnion", e18.ZodIntersection = "ZodIntersection", e18.ZodTuple = "ZodTuple", e18.ZodRecord = "ZodRecord", e18.ZodMap = "ZodMap", e18.ZodSet = "ZodSet", e18.ZodFunction = "ZodFunction", e18.ZodLazy = "ZodLazy", e18.ZodLiteral = "ZodLiteral", e18.ZodEnum = "ZodEnum", e18.ZodEffects = "ZodEffects", e18.ZodNativeEnum = "ZodNativeEnum", e18.ZodOptional = "ZodOptional", e18.ZodNullable = "ZodNullable", e18.ZodDefault = "ZodDefault", e18.ZodCatch = "ZodCatch", e18.ZodPromise = "ZodPromise", e18.ZodBranded = "ZodBranded", e18.ZodPipeline = "ZodPipeline", e18.ZodReadonly = "ZodReadonly";
|
|
2984
2881
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {})), ZodString.create, ZodNumber.create, ZodNaN.create, ZodBigInt.create, ZodBoolean.create, ZodDate.create, ZodSymbol.create, ZodUndefined.create, ZodNull.create, ZodAny.create, ZodUnknown.create, ZodNever.create, ZodVoid.create, ZodArray.create, ZodObject.create, ZodObject.strictCreate, ZodUnion.create, ZodDiscriminatedUnion.create, ZodIntersection.create, ZodTuple.create, ZodRecord.create, ZodMap.create, ZodSet.create, ZodFunction.create, ZodLazy.create, ZodLiteral.create, ZodEnum.create, ZodNativeEnum.create, ZodPromise.create, ZodEffects.create, ZodOptional.create, ZodNullable.create, ZodEffects.createWithPreprocess, ZodPipeline.create;
|
|
2985
|
-
var
|
|
2882
|
+
var ParseError = class extends Error {
|
|
2883
|
+
constructor(e18, v) {
|
|
2884
|
+
super(e18), this.name = "ParseError", this.type = v.type, this.field = v.field, this.value = v.value, this.line = v.line;
|
|
2885
|
+
}
|
|
2886
|
+
};
|
|
2887
|
+
function noop(e18) {
|
|
2888
|
+
}
|
|
2889
|
+
function createParser(e18) {
|
|
2890
|
+
if (typeof e18 == "function") throw TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");
|
|
2891
|
+
let { onEvent: v = noop, onError: y = noop, onRetry: b = noop, onComment: x } = e18, S = "", C = true, w, T = "", E = "";
|
|
2892
|
+
function D(e19) {
|
|
2893
|
+
let v2 = C ? e19.replace(/^\xEF\xBB\xBF/, "") : e19, [y2, b2] = splitLines(`${S}${v2}`);
|
|
2894
|
+
for (let e20 of y2) O(e20);
|
|
2895
|
+
S = b2, C = false;
|
|
2896
|
+
}
|
|
2897
|
+
function O(e19) {
|
|
2898
|
+
if (e19 === "") {
|
|
2899
|
+
A();
|
|
2900
|
+
return;
|
|
2901
|
+
}
|
|
2902
|
+
if (e19.startsWith(":")) {
|
|
2903
|
+
x && x(e19.slice(e19.startsWith(": ") ? 2 : 1));
|
|
2904
|
+
return;
|
|
2905
|
+
}
|
|
2906
|
+
let v2 = e19.indexOf(":");
|
|
2907
|
+
if (v2 !== -1) {
|
|
2908
|
+
let y2 = e19.slice(0, v2), b2 = e19[v2 + 1] === " " ? 2 : 1;
|
|
2909
|
+
k(y2, e19.slice(v2 + b2), e19);
|
|
2910
|
+
return;
|
|
2911
|
+
}
|
|
2912
|
+
k(e19, "", e19);
|
|
2913
|
+
}
|
|
2914
|
+
function k(e19, v2, x2) {
|
|
2915
|
+
switch (e19) {
|
|
2916
|
+
case "event":
|
|
2917
|
+
E = v2;
|
|
2918
|
+
break;
|
|
2919
|
+
case "data":
|
|
2920
|
+
T = `${T}${v2}
|
|
2921
|
+
`;
|
|
2922
|
+
break;
|
|
2923
|
+
case "id":
|
|
2924
|
+
w = v2.includes("\0") ? void 0 : v2;
|
|
2925
|
+
break;
|
|
2926
|
+
case "retry":
|
|
2927
|
+
/^\d+$/.test(v2) ? b(parseInt(v2, 10)) : y(new ParseError(`Invalid \`retry\` value: "${v2}"`, {
|
|
2928
|
+
type: "invalid-retry",
|
|
2929
|
+
value: v2,
|
|
2930
|
+
line: x2
|
|
2931
|
+
}));
|
|
2932
|
+
break;
|
|
2933
|
+
default:
|
|
2934
|
+
y(new ParseError(`Unknown field "${e19.length > 20 ? `${e19.slice(0, 20)}\u2026` : e19}"`, {
|
|
2935
|
+
type: "unknown-field",
|
|
2936
|
+
field: e19,
|
|
2937
|
+
value: v2,
|
|
2938
|
+
line: x2
|
|
2939
|
+
}));
|
|
2940
|
+
break;
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2943
|
+
function A() {
|
|
2944
|
+
T.length > 0 && v({
|
|
2945
|
+
id: w,
|
|
2946
|
+
event: E || void 0,
|
|
2947
|
+
data: T.endsWith("\n") ? T.slice(0, -1) : T
|
|
2948
|
+
}), w = void 0, T = "", E = "";
|
|
2949
|
+
}
|
|
2950
|
+
function j(e19 = {}) {
|
|
2951
|
+
S && e19.consume && O(S), C = true, w = void 0, T = "", E = "", S = "";
|
|
2952
|
+
}
|
|
2953
|
+
return {
|
|
2954
|
+
feed: D,
|
|
2955
|
+
reset: j
|
|
2956
|
+
};
|
|
2957
|
+
}
|
|
2958
|
+
function splitLines(e18) {
|
|
2959
|
+
let v = [], y = "", b = 0;
|
|
2960
|
+
for (; b < e18.length; ) {
|
|
2961
|
+
let x = e18.indexOf("\r", b), S = e18.indexOf("\n", b), C = -1;
|
|
2962
|
+
if (x !== -1 && S !== -1 ? C = Math.min(x, S) : x === -1 ? S !== -1 && (C = S) : C = x === e18.length - 1 ? -1 : x, C === -1) {
|
|
2963
|
+
y = e18.slice(b);
|
|
2964
|
+
break;
|
|
2965
|
+
} else {
|
|
2966
|
+
let y2 = e18.slice(b, C);
|
|
2967
|
+
v.push(y2), b = C + 1, e18[b - 1] === "\r" && e18[b] === "\n" && b++;
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
return [v, y];
|
|
2971
|
+
}
|
|
2972
|
+
var EventSourceParserStream = class extends TransformStream {
|
|
2973
|
+
constructor({ onError: e18, onRetry: v, onComment: y } = {}) {
|
|
2974
|
+
let b;
|
|
2975
|
+
super({
|
|
2976
|
+
start(x) {
|
|
2977
|
+
b = createParser({
|
|
2978
|
+
onEvent: (e19) => {
|
|
2979
|
+
x.enqueue(e19);
|
|
2980
|
+
},
|
|
2981
|
+
onError(v2) {
|
|
2982
|
+
e18 === "terminate" ? x.error(v2) : typeof e18 == "function" && e18(v2);
|
|
2983
|
+
},
|
|
2984
|
+
onRetry: v,
|
|
2985
|
+
onComment: y
|
|
2986
|
+
});
|
|
2987
|
+
},
|
|
2988
|
+
transform(e19) {
|
|
2989
|
+
b.feed(e19);
|
|
2990
|
+
}
|
|
2991
|
+
});
|
|
2992
|
+
}
|
|
2993
|
+
}, { btoa, atob: atob$1 } = globalThis, createIdGenerator = ({ prefix: e18, size: v = 16, alphabet: y = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", separator: b = "-" } = {}) => {
|
|
2986
2994
|
let x = () => {
|
|
2987
2995
|
let e19 = y.length, b2 = Array(v);
|
|
2988
2996
|
for (let x2 = 0; x2 < v; x2++) b2[x2] = y[Math.random() * e19 | 0];
|
|
@@ -2995,10 +3003,6 @@ var createIdGenerator = ({ prefix: e18, size: v = 16, alphabet: y = "0123456789A
|
|
|
2995
3003
|
});
|
|
2996
3004
|
return () => `${e18}${b}${x()}`;
|
|
2997
3005
|
}, generateId = createIdGenerator();
|
|
2998
|
-
function getRuntimeEnvironmentUserAgent(e18 = globalThis) {
|
|
2999
|
-
var _a, _b2, _c;
|
|
3000
|
-
return e18.window ? "runtime/browser" : ((_a = e18.navigator) == null ? void 0 : _a.userAgent) ? `runtime/${e18.navigator.userAgent.toLowerCase()}` : ((_c = (_b2 = e18.process) == null ? void 0 : _b2.versions) == null ? void 0 : _c.node) ? `runtime/node.js/${e18.process.version.substring(0)}` : e18.EdgeRuntime ? "runtime/vercel-edge" : "runtime/unknown";
|
|
3001
|
-
}
|
|
3002
3006
|
function normalizeHeaders(e18) {
|
|
3003
3007
|
if (e18 == null) return {};
|
|
3004
3008
|
let v = {};
|
|
@@ -3011,11 +3015,7 @@ function normalizeHeaders(e18) {
|
|
|
3011
3015
|
}
|
|
3012
3016
|
return v;
|
|
3013
3017
|
}
|
|
3014
|
-
|
|
3015
|
-
let y = new Headers(normalizeHeaders(e18)), b = y.get("user-agent") || "";
|
|
3016
|
-
return y.set("user-agent", [b, ...v].filter(Boolean).join(" ")), Object.fromEntries(y.entries());
|
|
3017
|
-
}
|
|
3018
|
-
var suspectProtoRx = /"__proto__"\s*:/, suspectConstructorRx = /"constructor"\s*:/;
|
|
3018
|
+
var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/, suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
|
|
3019
3019
|
function _parse(e18) {
|
|
3020
3020
|
let v = JSON.parse(e18);
|
|
3021
3021
|
return typeof v != "object" || !v || suspectProtoRx.test(e18) === false && suspectConstructorRx.test(e18) === false ? v : filter(v);
|
|
@@ -3026,7 +3026,7 @@ function filter(e18) {
|
|
|
3026
3026
|
let e19 = v;
|
|
3027
3027
|
v = [];
|
|
3028
3028
|
for (let y of e19) {
|
|
3029
|
-
if (Object.prototype.hasOwnProperty.call(y, "__proto__") || Object.prototype.hasOwnProperty.call(y, "constructor") && Object.prototype.hasOwnProperty.call(y.constructor, "prototype")) throw SyntaxError("Object contains forbidden prototype property");
|
|
3029
|
+
if (Object.prototype.hasOwnProperty.call(y, "__proto__") || Object.prototype.hasOwnProperty.call(y, "constructor") && y.constructor !== null && typeof y.constructor == "object" && Object.prototype.hasOwnProperty.call(y.constructor, "prototype")) throw SyntaxError("Object contains forbidden prototype property");
|
|
3030
3030
|
for (let e20 in y) {
|
|
3031
3031
|
let b = y[e20];
|
|
3032
3032
|
b && typeof b == "object" && v.push(b);
|
|
@@ -3048,127 +3048,21 @@ function secureJsonParse(e18) {
|
|
|
3048
3048
|
Error.stackTraceLimit = v;
|
|
3049
3049
|
}
|
|
3050
3050
|
}
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
}
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
function lazyValidator(e18) {
|
|
3062
|
-
let v;
|
|
3063
|
-
return () => (v ?? (v = e18()), v);
|
|
3064
|
-
}
|
|
3065
|
-
function asValidator(e18) {
|
|
3066
|
-
return isValidator(e18) ? e18 : typeof e18 == "function" ? e18() : standardSchemaValidator(e18);
|
|
3067
|
-
}
|
|
3068
|
-
function standardSchemaValidator(e18) {
|
|
3069
|
-
return validator(async (v) => {
|
|
3070
|
-
let y = await e18["~standard"].validate(v);
|
|
3071
|
-
return y.issues == null ? {
|
|
3072
|
-
success: true,
|
|
3073
|
-
value: y.value
|
|
3074
|
-
} : {
|
|
3075
|
-
success: false,
|
|
3076
|
-
error: new TypeValidationError({
|
|
3077
|
-
value: v,
|
|
3078
|
-
cause: y.issues
|
|
3079
|
-
})
|
|
3080
|
-
};
|
|
3081
|
-
});
|
|
3051
|
+
function addAdditionalPropertiesToJsonSchema(e18) {
|
|
3052
|
+
if (e18.type === "object" || Array.isArray(e18.type) && e18.type.includes("object")) {
|
|
3053
|
+
e18.additionalProperties = false;
|
|
3054
|
+
let { properties: v2 } = e18;
|
|
3055
|
+
if (v2 != null) for (let e19 of Object.keys(v2)) v2[e19] = visit(v2[e19]);
|
|
3056
|
+
}
|
|
3057
|
+
e18.items != null && (e18.items = Array.isArray(e18.items) ? e18.items.map(visit) : visit(e18.items)), e18.anyOf != null && (e18.anyOf = e18.anyOf.map(visit)), e18.allOf != null && (e18.allOf = e18.allOf.map(visit)), e18.oneOf != null && (e18.oneOf = e18.oneOf.map(visit));
|
|
3058
|
+
let { definitions: v } = e18;
|
|
3059
|
+
if (v != null) for (let e19 of Object.keys(v)) v[e19] = visit(v[e19]);
|
|
3060
|
+
return e18;
|
|
3082
3061
|
}
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
value: e18,
|
|
3086
|
-
schema: v
|
|
3087
|
-
});
|
|
3088
|
-
if (!y.success) throw TypeValidationError.wrap({
|
|
3089
|
-
value: e18,
|
|
3090
|
-
cause: y.error
|
|
3091
|
-
});
|
|
3092
|
-
return y.value;
|
|
3062
|
+
function visit(e18) {
|
|
3063
|
+
return typeof e18 == "boolean" ? e18 : addAdditionalPropertiesToJsonSchema(e18);
|
|
3093
3064
|
}
|
|
3094
|
-
|
|
3095
|
-
let y = asValidator(v);
|
|
3096
|
-
try {
|
|
3097
|
-
if (y.validate == null) return {
|
|
3098
|
-
success: true,
|
|
3099
|
-
value: e18,
|
|
3100
|
-
rawValue: e18
|
|
3101
|
-
};
|
|
3102
|
-
let v2 = await y.validate(e18);
|
|
3103
|
-
return v2.success ? {
|
|
3104
|
-
success: true,
|
|
3105
|
-
value: v2.value,
|
|
3106
|
-
rawValue: e18
|
|
3107
|
-
} : {
|
|
3108
|
-
success: false,
|
|
3109
|
-
error: TypeValidationError.wrap({
|
|
3110
|
-
value: e18,
|
|
3111
|
-
cause: v2.error
|
|
3112
|
-
}),
|
|
3113
|
-
rawValue: e18
|
|
3114
|
-
};
|
|
3115
|
-
} catch (v2) {
|
|
3116
|
-
return {
|
|
3117
|
-
success: false,
|
|
3118
|
-
error: TypeValidationError.wrap({
|
|
3119
|
-
value: e18,
|
|
3120
|
-
cause: v2
|
|
3121
|
-
}),
|
|
3122
|
-
rawValue: e18
|
|
3123
|
-
};
|
|
3124
|
-
}
|
|
3125
|
-
}
|
|
3126
|
-
async function safeParseJSON({ text: e18, schema: v }) {
|
|
3127
|
-
try {
|
|
3128
|
-
let y = secureJsonParse(e18);
|
|
3129
|
-
return v == null ? {
|
|
3130
|
-
success: true,
|
|
3131
|
-
value: y,
|
|
3132
|
-
rawValue: y
|
|
3133
|
-
} : await safeValidateTypes({
|
|
3134
|
-
value: y,
|
|
3135
|
-
schema: v
|
|
3136
|
-
});
|
|
3137
|
-
} catch (v2) {
|
|
3138
|
-
return {
|
|
3139
|
-
success: false,
|
|
3140
|
-
error: JSONParseError.isInstance(v2) ? v2 : new JSONParseError({
|
|
3141
|
-
text: e18,
|
|
3142
|
-
cause: v2
|
|
3143
|
-
}),
|
|
3144
|
-
rawValue: void 0
|
|
3145
|
-
};
|
|
3146
|
-
}
|
|
3147
|
-
}
|
|
3148
|
-
function parseJsonEventStream({ stream: e18, schema: v }) {
|
|
3149
|
-
return e18.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).pipeThrough(new TransformStream({ async transform({ data: e19 }, y) {
|
|
3150
|
-
e19 !== "[DONE]" && y.enqueue(await safeParseJSON({
|
|
3151
|
-
text: e19,
|
|
3152
|
-
schema: v
|
|
3153
|
-
}));
|
|
3154
|
-
} }));
|
|
3155
|
-
}
|
|
3156
|
-
async function resolve(e18) {
|
|
3157
|
-
return typeof e18 == "function" && (e18 = e18()), Promise.resolve(e18);
|
|
3158
|
-
}
|
|
3159
|
-
function addAdditionalPropertiesToJsonSchema(e18) {
|
|
3160
|
-
if (e18.type === "object") {
|
|
3161
|
-
e18.additionalProperties = false;
|
|
3162
|
-
let v = e18.properties;
|
|
3163
|
-
if (v != null) for (let e19 in v) v[e19] = addAdditionalPropertiesToJsonSchema(v[e19]);
|
|
3164
|
-
}
|
|
3165
|
-
return e18.type === "array" && e18.items != null && (Array.isArray(e18.items) ? e18.items = e18.items.map((e19) => addAdditionalPropertiesToJsonSchema(e19)) : e18.items = addAdditionalPropertiesToJsonSchema(e18.items)), e18;
|
|
3166
|
-
}
|
|
3167
|
-
var getRelativePath = (e18, v) => {
|
|
3168
|
-
let y = 0;
|
|
3169
|
-
for (; y < e18.length && y < v.length && e18[y] === v[y]; y++) ;
|
|
3170
|
-
return [(e18.length - y).toString(), ...v.slice(y)].join("/");
|
|
3171
|
-
}, ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use"), defaultOptions = {
|
|
3065
|
+
var ignoreOverride = /* @__PURE__ */ Symbol("Let zodToJsonSchema decide on which parser to use"), defaultOptions = {
|
|
3172
3066
|
name: void 0,
|
|
3173
3067
|
$refStrategy: "root",
|
|
3174
3068
|
basePath: ["#"],
|
|
@@ -3199,9 +3093,9 @@ function parseAnyDef() {
|
|
|
3199
3093
|
return {};
|
|
3200
3094
|
}
|
|
3201
3095
|
function parseArrayDef(e18, v) {
|
|
3202
|
-
var _a,
|
|
3096
|
+
var _a, _b, _c;
|
|
3203
3097
|
let y = { type: "array" };
|
|
3204
|
-
return ((_a = e18.type) == null ? void 0 : _a._def) && ((_c = (
|
|
3098
|
+
return ((_a = e18.type) == null ? void 0 : _a._def) && ((_c = (_b = e18.type) == null ? void 0 : _b._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny && (y.items = parseDef(e18.type._def, {
|
|
3205
3099
|
...v,
|
|
3206
3100
|
currentPath: [...v.currentPath, "items"]
|
|
3207
3101
|
})), e18.minLength && (y.minItems = e18.minLength.value), e18.maxLength && (y.maxItems = e18.maxLength.value), e18.exactLength && (y.minItems = e18.exactLength.value, y.maxItems = e18.exactLength.value), y;
|
|
@@ -3507,7 +3401,7 @@ function stringifyRegExpWithFlags(e18, v) {
|
|
|
3507
3401
|
return x;
|
|
3508
3402
|
}
|
|
3509
3403
|
function parseRecordDef(e18, v) {
|
|
3510
|
-
var _a,
|
|
3404
|
+
var _a, _b, _c, _d, _e;
|
|
3511
3405
|
let y = {
|
|
3512
3406
|
type: "object",
|
|
3513
3407
|
additionalProperties: parseDef(e18.valueType._def, {
|
|
@@ -3515,7 +3409,7 @@ function parseRecordDef(e18, v) {
|
|
|
3515
3409
|
currentPath: [...v.currentPath, "additionalProperties"]
|
|
3516
3410
|
}) ?? v.allowedAdditionalProperties
|
|
3517
3411
|
};
|
|
3518
|
-
if (((_a = e18.keyType) == null ? void 0 : _a._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((
|
|
3412
|
+
if (((_a = e18.keyType) == null ? void 0 : _a._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_b = e18.keyType._def.checks) == null ? void 0 : _b.length)) {
|
|
3519
3413
|
let { type: b, ...x } = parseStringDef(e18.keyType._def, v);
|
|
3520
3414
|
return {
|
|
3521
3415
|
...y,
|
|
@@ -3873,6 +3767,10 @@ var parseReadonlyDef = (e18, v) => parseDef(e18.innerType._def, v), selectParser
|
|
|
3873
3767
|
default:
|
|
3874
3768
|
return /* @__PURE__ */ ((e19) => void 0)(v);
|
|
3875
3769
|
}
|
|
3770
|
+
}, getRelativePath = (e18, v) => {
|
|
3771
|
+
let y = 0;
|
|
3772
|
+
for (; y < e18.length && y < v.length && e18[y] === v[y]; y++) ;
|
|
3773
|
+
return [(e18.length - y).toString(), ...v.slice(y)].join("/");
|
|
3876
3774
|
};
|
|
3877
3775
|
function parseDef(e18, v, y = false) {
|
|
3878
3776
|
var _a;
|
|
@@ -3928,7 +3826,7 @@ var get$ref = (e18, v) => {
|
|
|
3928
3826
|
jsonSchema: void 0
|
|
3929
3827
|
}]))
|
|
3930
3828
|
};
|
|
3931
|
-
},
|
|
3829
|
+
}, zod3ToJsonSchema = (e18, v) => {
|
|
3932
3830
|
let y = getRefs(v), b = typeof v == "object" && v.definitions ? Object.entries(v.definitions).reduce((e19, [v2, b2]) => ({
|
|
3933
3831
|
...e19,
|
|
3934
3832
|
[v2]: parseDef(b2._def, {
|
|
@@ -3963,10 +3861,48 @@ var get$ref = (e18, v) => {
|
|
|
3963
3861
|
}
|
|
3964
3862
|
};
|
|
3965
3863
|
return w.$schema = "http://json-schema.org/draft-07/schema#", w;
|
|
3966
|
-
};
|
|
3864
|
+
}, schemaSymbol = /* @__PURE__ */ Symbol.for("vercel.ai.schema");
|
|
3865
|
+
function lazySchema(e18) {
|
|
3866
|
+
let v;
|
|
3867
|
+
return () => (v ?? (v = e18()), v);
|
|
3868
|
+
}
|
|
3869
|
+
function jsonSchema(e18, { validate: v } = {}) {
|
|
3870
|
+
return {
|
|
3871
|
+
[schemaSymbol]: true,
|
|
3872
|
+
_type: void 0,
|
|
3873
|
+
get jsonSchema() {
|
|
3874
|
+
return typeof e18 == "function" && (e18 = e18()), e18;
|
|
3875
|
+
},
|
|
3876
|
+
validate: v
|
|
3877
|
+
};
|
|
3878
|
+
}
|
|
3879
|
+
function isSchema(e18) {
|
|
3880
|
+
return typeof e18 == "object" && !!e18 && schemaSymbol in e18 && e18[schemaSymbol] === true && "jsonSchema" in e18 && "validate" in e18;
|
|
3881
|
+
}
|
|
3882
|
+
function asSchema(e18) {
|
|
3883
|
+
return e18 == null ? jsonSchema({
|
|
3884
|
+
properties: {},
|
|
3885
|
+
additionalProperties: false
|
|
3886
|
+
}) : isSchema(e18) ? e18 : "~standard" in e18 ? e18["~standard"].vendor === "zod" ? zodSchema(e18) : standardSchema(e18) : e18();
|
|
3887
|
+
}
|
|
3888
|
+
function standardSchema(e18) {
|
|
3889
|
+
return jsonSchema(() => addAdditionalPropertiesToJsonSchema(e18["~standard"].jsonSchema.input({ target: "draft-07" })), { validate: async (v) => {
|
|
3890
|
+
let y = await e18["~standard"].validate(v);
|
|
3891
|
+
return "value" in y ? {
|
|
3892
|
+
success: true,
|
|
3893
|
+
value: y.value
|
|
3894
|
+
} : {
|
|
3895
|
+
success: false,
|
|
3896
|
+
error: new TypeValidationError({
|
|
3897
|
+
value: v,
|
|
3898
|
+
cause: y.issues
|
|
3899
|
+
})
|
|
3900
|
+
};
|
|
3901
|
+
} });
|
|
3902
|
+
}
|
|
3967
3903
|
function zod3Schema(e18, v) {
|
|
3968
3904
|
let y = (v == null ? void 0 : v.useReferences) ?? false;
|
|
3969
|
-
return jsonSchema(() =>
|
|
3905
|
+
return jsonSchema(() => zod3ToJsonSchema(e18, { $refStrategy: y ? "root" : "none" }), { validate: async (v2) => {
|
|
3970
3906
|
let y2 = await e18.safeParseAsync(v2);
|
|
3971
3907
|
return y2.success ? {
|
|
3972
3908
|
success: true,
|
|
@@ -4000,46 +3936,117 @@ function isZod4Schema(e18) {
|
|
|
4000
3936
|
function zodSchema(e18, v) {
|
|
4001
3937
|
return isZod4Schema(e18) ? zod4Schema(e18, v) : zod3Schema(e18, v);
|
|
4002
3938
|
}
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
};
|
|
3939
|
+
async function validateTypes({ value: e18, schema: v, context: y }) {
|
|
3940
|
+
let b = await safeValidateTypes({
|
|
3941
|
+
value: e18,
|
|
3942
|
+
schema: v,
|
|
3943
|
+
context: y
|
|
3944
|
+
});
|
|
3945
|
+
if (!b.success) throw TypeValidationError.wrap({
|
|
3946
|
+
value: e18,
|
|
3947
|
+
cause: b.error,
|
|
3948
|
+
context: y
|
|
3949
|
+
});
|
|
3950
|
+
return b.value;
|
|
4014
3951
|
}
|
|
4015
|
-
function
|
|
4016
|
-
|
|
3952
|
+
async function safeValidateTypes({ value: e18, schema: v, context: y }) {
|
|
3953
|
+
let b = asSchema(v);
|
|
3954
|
+
try {
|
|
3955
|
+
if (b.validate == null) return {
|
|
3956
|
+
success: true,
|
|
3957
|
+
value: e18,
|
|
3958
|
+
rawValue: e18
|
|
3959
|
+
};
|
|
3960
|
+
let v2 = await b.validate(e18);
|
|
3961
|
+
return v2.success ? {
|
|
3962
|
+
success: true,
|
|
3963
|
+
value: v2.value,
|
|
3964
|
+
rawValue: e18
|
|
3965
|
+
} : {
|
|
3966
|
+
success: false,
|
|
3967
|
+
error: TypeValidationError.wrap({
|
|
3968
|
+
value: e18,
|
|
3969
|
+
cause: v2.error,
|
|
3970
|
+
context: y
|
|
3971
|
+
}),
|
|
3972
|
+
rawValue: e18
|
|
3973
|
+
};
|
|
3974
|
+
} catch (v2) {
|
|
3975
|
+
return {
|
|
3976
|
+
success: false,
|
|
3977
|
+
error: TypeValidationError.wrap({
|
|
3978
|
+
value: e18,
|
|
3979
|
+
cause: v2,
|
|
3980
|
+
context: y
|
|
3981
|
+
}),
|
|
3982
|
+
rawValue: e18
|
|
3983
|
+
};
|
|
3984
|
+
}
|
|
4017
3985
|
}
|
|
4018
|
-
function
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
3986
|
+
async function safeParseJSON({ text: e18, schema: v }) {
|
|
3987
|
+
try {
|
|
3988
|
+
let y = secureJsonParse(e18);
|
|
3989
|
+
return v == null ? {
|
|
3990
|
+
success: true,
|
|
3991
|
+
value: y,
|
|
3992
|
+
rawValue: y
|
|
3993
|
+
} : await safeValidateTypes({
|
|
3994
|
+
value: y,
|
|
3995
|
+
schema: v
|
|
3996
|
+
});
|
|
3997
|
+
} catch (v2) {
|
|
3998
|
+
return {
|
|
3999
|
+
success: false,
|
|
4000
|
+
error: JSONParseError.isInstance(v2) ? v2 : new JSONParseError({
|
|
4001
|
+
text: e18,
|
|
4002
|
+
cause: v2
|
|
4003
|
+
}),
|
|
4004
|
+
rawValue: void 0
|
|
4005
|
+
};
|
|
4006
|
+
}
|
|
4007
|
+
}
|
|
4008
|
+
function parseJsonEventStream({ stream: e18, schema: v }) {
|
|
4009
|
+
return e18.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream()).pipeThrough(new TransformStream({ async transform({ data: e19 }, y) {
|
|
4010
|
+
e19 !== "[DONE]" && y.enqueue(await safeParseJSON({
|
|
4011
|
+
text: e19,
|
|
4012
|
+
schema: v
|
|
4013
|
+
}));
|
|
4014
|
+
} }));
|
|
4023
4015
|
}
|
|
4024
|
-
|
|
4016
|
+
async function resolve(e18) {
|
|
4017
|
+
return typeof e18 == "function" && (e18 = e18()), Promise.resolve(e18);
|
|
4018
|
+
}
|
|
4019
|
+
var __defProp2 = Object.defineProperty, __export = (e18, v) => {
|
|
4025
4020
|
for (var y in v) __defProp2(e18, y, {
|
|
4026
4021
|
get: v[y],
|
|
4027
4022
|
enumerable: true
|
|
4028
4023
|
});
|
|
4029
|
-
},
|
|
4024
|
+
}, name8 = "AI_NoObjectGeneratedError", marker8 = `vercel.ai.error.${name8}`, symbol8 = Symbol.for(marker8), _a8, NoObjectGeneratedError = class extends AISDKError {
|
|
4030
4025
|
constructor({ message: e18 = "No object generated.", cause: v, text: y, response: b, usage: x, finishReason: S }) {
|
|
4031
4026
|
super({
|
|
4032
|
-
name:
|
|
4027
|
+
name: name8,
|
|
4033
4028
|
message: e18,
|
|
4034
4029
|
cause: v
|
|
4035
|
-
}), this[
|
|
4030
|
+
}), this[_a8] = true, this.text = y, this.response = b, this.usage = x, this.finishReason = S;
|
|
4031
|
+
}
|
|
4032
|
+
static isInstance(e18) {
|
|
4033
|
+
return AISDKError.hasMarker(e18, marker8);
|
|
4034
|
+
}
|
|
4035
|
+
};
|
|
4036
|
+
_a8 = symbol8;
|
|
4037
|
+
var name15 = "AI_UIMessageStreamError", marker15 = `vercel.ai.error.${name15}`, symbol15 = Symbol.for(marker15), _a15, UIMessageStreamError = class extends AISDKError {
|
|
4038
|
+
constructor({ chunkType: e18, chunkId: v, message: y }) {
|
|
4039
|
+
super({
|
|
4040
|
+
name: name15,
|
|
4041
|
+
message: y
|
|
4042
|
+
}), this[_a15] = true, this.chunkType = e18, this.chunkId = v;
|
|
4036
4043
|
}
|
|
4037
4044
|
static isInstance(e18) {
|
|
4038
|
-
return AISDKError.hasMarker(e18,
|
|
4045
|
+
return AISDKError.hasMarker(e18, marker15);
|
|
4039
4046
|
}
|
|
4040
4047
|
};
|
|
4041
|
-
|
|
4042
|
-
var
|
|
4048
|
+
_a15 = symbol15;
|
|
4049
|
+
var dataContentSchema = union([
|
|
4043
4050
|
string(),
|
|
4044
4051
|
_instanceof(Uint8Array),
|
|
4045
4052
|
_instanceof(ArrayBuffer),
|
|
@@ -4052,9 +4059,9 @@ var VERSION = "5.0.124", dataContentSchema = union([
|
|
|
4052
4059
|
string(),
|
|
4053
4060
|
number(),
|
|
4054
4061
|
boolean(),
|
|
4055
|
-
record(string(), jsonValueSchema),
|
|
4056
|
-
array(jsonValueSchema)
|
|
4057
|
-
])), providerMetadataSchema = record(string(), record(string(), jsonValueSchema)), textPartSchema = object$1({
|
|
4062
|
+
record(string(), jsonValueSchema.optional()),
|
|
4063
|
+
array$1(jsonValueSchema)
|
|
4064
|
+
])), providerMetadataSchema = record(string(), record(string(), jsonValueSchema.optional())), textPartSchema = object$1({
|
|
4058
4065
|
type: literal("text"),
|
|
4059
4066
|
text: string(),
|
|
4060
4067
|
providerOptions: providerMetadataSchema.optional()
|
|
@@ -4083,30 +4090,80 @@ var VERSION = "5.0.124", dataContentSchema = union([
|
|
|
4083
4090
|
}), outputSchema = discriminatedUnion("type", [
|
|
4084
4091
|
object$1({
|
|
4085
4092
|
type: literal("text"),
|
|
4086
|
-
value: string()
|
|
4093
|
+
value: string(),
|
|
4094
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4087
4095
|
}),
|
|
4088
4096
|
object$1({
|
|
4089
4097
|
type: literal("json"),
|
|
4090
|
-
value: jsonValueSchema
|
|
4098
|
+
value: jsonValueSchema,
|
|
4099
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4100
|
+
}),
|
|
4101
|
+
object$1({
|
|
4102
|
+
type: literal("execution-denied"),
|
|
4103
|
+
reason: string().optional(),
|
|
4104
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4091
4105
|
}),
|
|
4092
4106
|
object$1({
|
|
4093
4107
|
type: literal("error-text"),
|
|
4094
|
-
value: string()
|
|
4108
|
+
value: string(),
|
|
4109
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4095
4110
|
}),
|
|
4096
4111
|
object$1({
|
|
4097
4112
|
type: literal("error-json"),
|
|
4098
|
-
value: jsonValueSchema
|
|
4113
|
+
value: jsonValueSchema,
|
|
4114
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4099
4115
|
}),
|
|
4100
4116
|
object$1({
|
|
4101
4117
|
type: literal("content"),
|
|
4102
|
-
value: array(union([
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4118
|
+
value: array$1(union([
|
|
4119
|
+
object$1({
|
|
4120
|
+
type: literal("text"),
|
|
4121
|
+
text: string(),
|
|
4122
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4123
|
+
}),
|
|
4124
|
+
object$1({
|
|
4125
|
+
type: literal("media"),
|
|
4126
|
+
data: string(),
|
|
4127
|
+
mediaType: string()
|
|
4128
|
+
}),
|
|
4129
|
+
object$1({
|
|
4130
|
+
type: literal("file-data"),
|
|
4131
|
+
data: string(),
|
|
4132
|
+
mediaType: string(),
|
|
4133
|
+
filename: string().optional(),
|
|
4134
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4135
|
+
}),
|
|
4136
|
+
object$1({
|
|
4137
|
+
type: literal("file-url"),
|
|
4138
|
+
url: string(),
|
|
4139
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4140
|
+
}),
|
|
4141
|
+
object$1({
|
|
4142
|
+
type: literal("file-id"),
|
|
4143
|
+
fileId: union([string(), record(string(), string())]),
|
|
4144
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4145
|
+
}),
|
|
4146
|
+
object$1({
|
|
4147
|
+
type: literal("image-data"),
|
|
4148
|
+
data: string(),
|
|
4149
|
+
mediaType: string(),
|
|
4150
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4151
|
+
}),
|
|
4152
|
+
object$1({
|
|
4153
|
+
type: literal("image-url"),
|
|
4154
|
+
url: string(),
|
|
4155
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4156
|
+
}),
|
|
4157
|
+
object$1({
|
|
4158
|
+
type: literal("image-file-id"),
|
|
4159
|
+
fileId: union([string(), record(string(), string())]),
|
|
4160
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4161
|
+
}),
|
|
4162
|
+
object$1({
|
|
4163
|
+
type: literal("custom"),
|
|
4164
|
+
providerOptions: providerMetadataSchema.optional()
|
|
4165
|
+
})
|
|
4166
|
+
]))
|
|
4110
4167
|
})
|
|
4111
4168
|
]), toolResultPartSchema = object$1({
|
|
4112
4169
|
type: literal("tool-result"),
|
|
@@ -4114,6 +4171,15 @@ var VERSION = "5.0.124", dataContentSchema = union([
|
|
|
4114
4171
|
toolName: string(),
|
|
4115
4172
|
output: outputSchema,
|
|
4116
4173
|
providerOptions: providerMetadataSchema.optional()
|
|
4174
|
+
}), toolApprovalRequestSchema = object$1({
|
|
4175
|
+
type: literal("tool-approval-request"),
|
|
4176
|
+
approvalId: string(),
|
|
4177
|
+
toolCallId: string()
|
|
4178
|
+
}), toolApprovalResponseSchema = object$1({
|
|
4179
|
+
type: literal("tool-approval-response"),
|
|
4180
|
+
approvalId: string(),
|
|
4181
|
+
approved: boolean(),
|
|
4182
|
+
reason: string().optional()
|
|
4117
4183
|
});
|
|
4118
4184
|
union([
|
|
4119
4185
|
object$1({
|
|
@@ -4123,7 +4189,7 @@ union([
|
|
|
4123
4189
|
}),
|
|
4124
4190
|
object$1({
|
|
4125
4191
|
role: literal("user"),
|
|
4126
|
-
content: union([string(), array(union([
|
|
4192
|
+
content: union([string(), array$1(union([
|
|
4127
4193
|
textPartSchema,
|
|
4128
4194
|
imagePartSchema,
|
|
4129
4195
|
filePartSchema
|
|
@@ -4132,213 +4198,42 @@ union([
|
|
|
4132
4198
|
}),
|
|
4133
4199
|
object$1({
|
|
4134
4200
|
role: literal("assistant"),
|
|
4135
|
-
content: union([string(), array(union([
|
|
4201
|
+
content: union([string(), array$1(union([
|
|
4136
4202
|
textPartSchema,
|
|
4137
4203
|
filePartSchema,
|
|
4138
4204
|
reasoningPartSchema,
|
|
4139
4205
|
toolCallPartSchema,
|
|
4140
|
-
toolResultPartSchema
|
|
4206
|
+
toolResultPartSchema,
|
|
4207
|
+
toolApprovalRequestSchema
|
|
4141
4208
|
]))]),
|
|
4142
4209
|
providerOptions: providerMetadataSchema.optional()
|
|
4143
4210
|
}),
|
|
4144
4211
|
object$1({
|
|
4145
4212
|
role: literal("tool"),
|
|
4146
|
-
content: array(toolResultPartSchema),
|
|
4213
|
+
content: array$1(union([toolResultPartSchema, toolApprovalResponseSchema])),
|
|
4147
4214
|
providerOptions: providerMetadataSchema.optional()
|
|
4148
4215
|
})
|
|
4149
|
-
])
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
|
|
4154
|
-
let y =
|
|
4155
|
-
for (let
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
super({
|
|
4161
|
-
transform(e18, v) {
|
|
4162
|
-
v.enqueue(`data: ${JSON.stringify(e18)}
|
|
4163
|
-
|
|
4164
|
-
`);
|
|
4165
|
-
},
|
|
4166
|
-
flush(e18) {
|
|
4167
|
-
e18.enqueue("data: [DONE]\n\n");
|
|
4168
|
-
}
|
|
4169
|
-
});
|
|
4170
|
-
}
|
|
4171
|
-
}, UI_MESSAGE_STREAM_HEADERS = {
|
|
4172
|
-
"content-type": "text/event-stream",
|
|
4173
|
-
"cache-control": "no-cache",
|
|
4174
|
-
connection: "keep-alive",
|
|
4175
|
-
"x-vercel-ai-ui-message-stream": "v1",
|
|
4176
|
-
"x-accel-buffering": "no"
|
|
4177
|
-
};
|
|
4178
|
-
function createUIMessageStreamResponse({ status: e18, statusText: v, headers: y, stream: b, consumeSseStream: x }) {
|
|
4179
|
-
let S = b.pipeThrough(new JsonToSseTransformStream());
|
|
4180
|
-
if (x) {
|
|
4181
|
-
let [e19, v2] = S.tee();
|
|
4182
|
-
S = e19, x({ stream: v2 });
|
|
4216
|
+
]);
|
|
4217
|
+
function mergeObjects(e18, v) {
|
|
4218
|
+
if (e18 === void 0 && v === void 0) return;
|
|
4219
|
+
if (e18 === void 0) return v;
|
|
4220
|
+
if (v === void 0) return e18;
|
|
4221
|
+
let y = { ...e18 };
|
|
4222
|
+
for (let b in v) if (Object.prototype.hasOwnProperty.call(v, b)) {
|
|
4223
|
+
let x = v[b];
|
|
4224
|
+
if (x === void 0) continue;
|
|
4225
|
+
let S = b in e18 ? e18[b] : void 0, C = typeof x == "object" && !!x && !Array.isArray(x) && !(x instanceof Date) && !(x instanceof RegExp), w = typeof S == "object" && !!S && !Array.isArray(S) && !(S instanceof Date) && !(S instanceof RegExp);
|
|
4226
|
+
C && w ? y[b] = mergeObjects(S, x) : y[b] = x;
|
|
4183
4227
|
}
|
|
4184
|
-
return
|
|
4185
|
-
status: e18,
|
|
4186
|
-
statusText: v,
|
|
4187
|
-
headers: prepareHeaders(y, UI_MESSAGE_STREAM_HEADERS)
|
|
4188
|
-
});
|
|
4189
|
-
}
|
|
4190
|
-
var uiMessageChunkSchema = lazyValidator(() => zodSchema(union([
|
|
4191
|
-
strictObject({
|
|
4192
|
-
type: literal("text-start"),
|
|
4193
|
-
id: string(),
|
|
4194
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
4195
|
-
}),
|
|
4196
|
-
strictObject({
|
|
4197
|
-
type: literal("text-delta"),
|
|
4198
|
-
id: string(),
|
|
4199
|
-
delta: string(),
|
|
4200
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
4201
|
-
}),
|
|
4202
|
-
strictObject({
|
|
4203
|
-
type: literal("text-end"),
|
|
4204
|
-
id: string(),
|
|
4205
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
4206
|
-
}),
|
|
4207
|
-
strictObject({
|
|
4208
|
-
type: literal("error"),
|
|
4209
|
-
errorText: string()
|
|
4210
|
-
}),
|
|
4211
|
-
strictObject({
|
|
4212
|
-
type: literal("tool-input-start"),
|
|
4213
|
-
toolCallId: string(),
|
|
4214
|
-
toolName: string(),
|
|
4215
|
-
providerExecuted: boolean().optional(),
|
|
4216
|
-
dynamic: boolean().optional()
|
|
4217
|
-
}),
|
|
4218
|
-
strictObject({
|
|
4219
|
-
type: literal("tool-input-delta"),
|
|
4220
|
-
toolCallId: string(),
|
|
4221
|
-
inputTextDelta: string()
|
|
4222
|
-
}),
|
|
4223
|
-
strictObject({
|
|
4224
|
-
type: literal("tool-input-available"),
|
|
4225
|
-
toolCallId: string(),
|
|
4226
|
-
toolName: string(),
|
|
4227
|
-
input: unknown(),
|
|
4228
|
-
providerExecuted: boolean().optional(),
|
|
4229
|
-
providerMetadata: providerMetadataSchema.optional(),
|
|
4230
|
-
dynamic: boolean().optional()
|
|
4231
|
-
}),
|
|
4232
|
-
strictObject({
|
|
4233
|
-
type: literal("tool-input-error"),
|
|
4234
|
-
toolCallId: string(),
|
|
4235
|
-
toolName: string(),
|
|
4236
|
-
input: unknown(),
|
|
4237
|
-
providerExecuted: boolean().optional(),
|
|
4238
|
-
providerMetadata: providerMetadataSchema.optional(),
|
|
4239
|
-
dynamic: boolean().optional(),
|
|
4240
|
-
errorText: string()
|
|
4241
|
-
}),
|
|
4242
|
-
strictObject({
|
|
4243
|
-
type: literal("tool-output-available"),
|
|
4244
|
-
toolCallId: string(),
|
|
4245
|
-
output: unknown(),
|
|
4246
|
-
providerExecuted: boolean().optional(),
|
|
4247
|
-
dynamic: boolean().optional(),
|
|
4248
|
-
preliminary: boolean().optional()
|
|
4249
|
-
}),
|
|
4250
|
-
strictObject({
|
|
4251
|
-
type: literal("tool-output-error"),
|
|
4252
|
-
toolCallId: string(),
|
|
4253
|
-
errorText: string(),
|
|
4254
|
-
providerExecuted: boolean().optional(),
|
|
4255
|
-
dynamic: boolean().optional()
|
|
4256
|
-
}),
|
|
4257
|
-
strictObject({
|
|
4258
|
-
type: literal("reasoning-start"),
|
|
4259
|
-
id: string(),
|
|
4260
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
4261
|
-
}),
|
|
4262
|
-
strictObject({
|
|
4263
|
-
type: literal("reasoning-delta"),
|
|
4264
|
-
id: string(),
|
|
4265
|
-
delta: string(),
|
|
4266
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
4267
|
-
}),
|
|
4268
|
-
strictObject({
|
|
4269
|
-
type: literal("reasoning-end"),
|
|
4270
|
-
id: string(),
|
|
4271
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
4272
|
-
}),
|
|
4273
|
-
strictObject({
|
|
4274
|
-
type: literal("source-url"),
|
|
4275
|
-
sourceId: string(),
|
|
4276
|
-
url: string(),
|
|
4277
|
-
title: string().optional(),
|
|
4278
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
4279
|
-
}),
|
|
4280
|
-
strictObject({
|
|
4281
|
-
type: literal("source-document"),
|
|
4282
|
-
sourceId: string(),
|
|
4283
|
-
mediaType: string(),
|
|
4284
|
-
title: string(),
|
|
4285
|
-
filename: string().optional(),
|
|
4286
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
4287
|
-
}),
|
|
4288
|
-
strictObject({
|
|
4289
|
-
type: literal("file"),
|
|
4290
|
-
url: string(),
|
|
4291
|
-
mediaType: string(),
|
|
4292
|
-
providerMetadata: providerMetadataSchema.optional()
|
|
4293
|
-
}),
|
|
4294
|
-
strictObject({
|
|
4295
|
-
type: custom((e18) => typeof e18 == "string" && e18.startsWith("data-"), { message: 'Type must start with "data-"' }),
|
|
4296
|
-
id: string().optional(),
|
|
4297
|
-
data: unknown(),
|
|
4298
|
-
transient: boolean().optional()
|
|
4299
|
-
}),
|
|
4300
|
-
strictObject({ type: literal("start-step") }),
|
|
4301
|
-
strictObject({ type: literal("finish-step") }),
|
|
4302
|
-
strictObject({
|
|
4303
|
-
type: literal("start"),
|
|
4304
|
-
messageId: string().optional(),
|
|
4305
|
-
messageMetadata: unknown().optional()
|
|
4306
|
-
}),
|
|
4307
|
-
strictObject({
|
|
4308
|
-
type: literal("finish"),
|
|
4309
|
-
finishReason: _enum([
|
|
4310
|
-
"stop",
|
|
4311
|
-
"length",
|
|
4312
|
-
"content-filter",
|
|
4313
|
-
"tool-calls",
|
|
4314
|
-
"error",
|
|
4315
|
-
"other",
|
|
4316
|
-
"unknown"
|
|
4317
|
-
]).optional(),
|
|
4318
|
-
messageMetadata: unknown().optional()
|
|
4319
|
-
}),
|
|
4320
|
-
strictObject({ type: literal("abort") }),
|
|
4321
|
-
strictObject({
|
|
4322
|
-
type: literal("message-metadata"),
|
|
4323
|
-
messageMetadata: unknown()
|
|
4324
|
-
})
|
|
4325
|
-
])));
|
|
4326
|
-
function isDataUIMessageChunk(e18) {
|
|
4327
|
-
return e18.type.startsWith("data-");
|
|
4328
|
-
}
|
|
4329
|
-
function mergeObjects(e18, v) {
|
|
4330
|
-
if (e18 === void 0 && v === void 0) return;
|
|
4331
|
-
if (e18 === void 0) return v;
|
|
4332
|
-
if (v === void 0) return e18;
|
|
4333
|
-
let y = { ...e18 };
|
|
4334
|
-
for (let b in v) if (Object.prototype.hasOwnProperty.call(v, b)) {
|
|
4335
|
-
let x = v[b];
|
|
4336
|
-
if (x === void 0) continue;
|
|
4337
|
-
let S = b in e18 ? e18[b] : void 0, C = typeof x == "object" && !!x && !Array.isArray(x) && !(x instanceof Date) && !(x instanceof RegExp), w = typeof S == "object" && !!S && !Array.isArray(S) && !(S instanceof Date) && !(S instanceof RegExp);
|
|
4338
|
-
C && w ? y[b] = mergeObjects(S, x) : y[b] = x;
|
|
4339
|
-
}
|
|
4340
|
-
return y;
|
|
4228
|
+
return y;
|
|
4341
4229
|
}
|
|
4230
|
+
__export({}, {
|
|
4231
|
+
array: () => array,
|
|
4232
|
+
choice: () => choice,
|
|
4233
|
+
json: () => json,
|
|
4234
|
+
object: () => object,
|
|
4235
|
+
text: () => text
|
|
4236
|
+
});
|
|
4342
4237
|
function fixJson(e18) {
|
|
4343
4238
|
let v = ["ROOT"], y = -1, b = null;
|
|
4344
4239
|
function x(e19, x2, S2) {
|
|
@@ -4560,16 +4455,452 @@ async function parsePartialJson(e18) {
|
|
|
4560
4455
|
state: "failed-parse"
|
|
4561
4456
|
});
|
|
4562
4457
|
}
|
|
4563
|
-
|
|
4458
|
+
var text = () => ({
|
|
4459
|
+
name: "text",
|
|
4460
|
+
responseFormat: Promise.resolve({ type: "text" }),
|
|
4461
|
+
async parseCompleteOutput({ text: e18 }) {
|
|
4462
|
+
return e18;
|
|
4463
|
+
},
|
|
4464
|
+
async parsePartialOutput({ text: e18 }) {
|
|
4465
|
+
return { partial: e18 };
|
|
4466
|
+
},
|
|
4467
|
+
createElementStreamTransform() {
|
|
4468
|
+
}
|
|
4469
|
+
}), object = ({ schema: e18, name: v, description: y }) => {
|
|
4470
|
+
let b = asSchema(e18);
|
|
4471
|
+
return {
|
|
4472
|
+
name: "object",
|
|
4473
|
+
responseFormat: resolve(b.jsonSchema).then((e19) => ({
|
|
4474
|
+
type: "json",
|
|
4475
|
+
schema: e19,
|
|
4476
|
+
...v != null && { name: v },
|
|
4477
|
+
...y != null && { description: y }
|
|
4478
|
+
})),
|
|
4479
|
+
async parseCompleteOutput({ text: e19 }, v2) {
|
|
4480
|
+
let y2 = await safeParseJSON({ text: e19 });
|
|
4481
|
+
if (!y2.success) throw new NoObjectGeneratedError({
|
|
4482
|
+
message: "No object generated: could not parse the response.",
|
|
4483
|
+
cause: y2.error,
|
|
4484
|
+
text: e19,
|
|
4485
|
+
response: v2.response,
|
|
4486
|
+
usage: v2.usage,
|
|
4487
|
+
finishReason: v2.finishReason
|
|
4488
|
+
});
|
|
4489
|
+
let x = await safeValidateTypes({
|
|
4490
|
+
value: y2.value,
|
|
4491
|
+
schema: b
|
|
4492
|
+
});
|
|
4493
|
+
if (!x.success) throw new NoObjectGeneratedError({
|
|
4494
|
+
message: "No object generated: response did not match schema.",
|
|
4495
|
+
cause: x.error,
|
|
4496
|
+
text: e19,
|
|
4497
|
+
response: v2.response,
|
|
4498
|
+
usage: v2.usage,
|
|
4499
|
+
finishReason: v2.finishReason
|
|
4500
|
+
});
|
|
4501
|
+
return x.value;
|
|
4502
|
+
},
|
|
4503
|
+
async parsePartialOutput({ text: e19 }) {
|
|
4504
|
+
let v2 = await parsePartialJson(e19);
|
|
4505
|
+
switch (v2.state) {
|
|
4506
|
+
case "failed-parse":
|
|
4507
|
+
case "undefined-input":
|
|
4508
|
+
return;
|
|
4509
|
+
case "repaired-parse":
|
|
4510
|
+
case "successful-parse":
|
|
4511
|
+
return { partial: v2.value };
|
|
4512
|
+
}
|
|
4513
|
+
},
|
|
4514
|
+
createElementStreamTransform() {
|
|
4515
|
+
}
|
|
4516
|
+
};
|
|
4517
|
+
}, array = ({ element: e18, name: v, description: y }) => {
|
|
4518
|
+
let b = asSchema(e18);
|
|
4519
|
+
return {
|
|
4520
|
+
name: "array",
|
|
4521
|
+
responseFormat: resolve(b.jsonSchema).then((e19) => {
|
|
4522
|
+
let { $schema: b2, ...x } = e19;
|
|
4523
|
+
return {
|
|
4524
|
+
type: "json",
|
|
4525
|
+
schema: {
|
|
4526
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
4527
|
+
type: "object",
|
|
4528
|
+
properties: { elements: {
|
|
4529
|
+
type: "array",
|
|
4530
|
+
items: x
|
|
4531
|
+
} },
|
|
4532
|
+
required: ["elements"],
|
|
4533
|
+
additionalProperties: false
|
|
4534
|
+
},
|
|
4535
|
+
...v != null && { name: v },
|
|
4536
|
+
...y != null && { description: y }
|
|
4537
|
+
};
|
|
4538
|
+
}),
|
|
4539
|
+
async parseCompleteOutput({ text: e19 }, v2) {
|
|
4540
|
+
let y2 = await safeParseJSON({ text: e19 });
|
|
4541
|
+
if (!y2.success) throw new NoObjectGeneratedError({
|
|
4542
|
+
message: "No object generated: could not parse the response.",
|
|
4543
|
+
cause: y2.error,
|
|
4544
|
+
text: e19,
|
|
4545
|
+
response: v2.response,
|
|
4546
|
+
usage: v2.usage,
|
|
4547
|
+
finishReason: v2.finishReason
|
|
4548
|
+
});
|
|
4549
|
+
let x = y2.value;
|
|
4550
|
+
if (typeof x != "object" || !x || !("elements" in x) || !Array.isArray(x.elements)) throw new NoObjectGeneratedError({
|
|
4551
|
+
message: "No object generated: response did not match schema.",
|
|
4552
|
+
cause: new TypeValidationError({
|
|
4553
|
+
value: x,
|
|
4554
|
+
cause: "response must be an object with an elements array"
|
|
4555
|
+
}),
|
|
4556
|
+
text: e19,
|
|
4557
|
+
response: v2.response,
|
|
4558
|
+
usage: v2.usage,
|
|
4559
|
+
finishReason: v2.finishReason
|
|
4560
|
+
});
|
|
4561
|
+
for (let y3 of x.elements) {
|
|
4562
|
+
let x2 = await safeValidateTypes({
|
|
4563
|
+
value: y3,
|
|
4564
|
+
schema: b
|
|
4565
|
+
});
|
|
4566
|
+
if (!x2.success) throw new NoObjectGeneratedError({
|
|
4567
|
+
message: "No object generated: response did not match schema.",
|
|
4568
|
+
cause: x2.error,
|
|
4569
|
+
text: e19,
|
|
4570
|
+
response: v2.response,
|
|
4571
|
+
usage: v2.usage,
|
|
4572
|
+
finishReason: v2.finishReason
|
|
4573
|
+
});
|
|
4574
|
+
}
|
|
4575
|
+
return x.elements;
|
|
4576
|
+
},
|
|
4577
|
+
async parsePartialOutput({ text: e19 }) {
|
|
4578
|
+
let v2 = await parsePartialJson(e19);
|
|
4579
|
+
switch (v2.state) {
|
|
4580
|
+
case "failed-parse":
|
|
4581
|
+
case "undefined-input":
|
|
4582
|
+
return;
|
|
4583
|
+
case "repaired-parse":
|
|
4584
|
+
case "successful-parse": {
|
|
4585
|
+
let e20 = v2.value;
|
|
4586
|
+
if (typeof e20 != "object" || !e20 || !("elements" in e20) || !Array.isArray(e20.elements)) return;
|
|
4587
|
+
let y2 = v2.state === "repaired-parse" && e20.elements.length > 0 ? e20.elements.slice(0, -1) : e20.elements, x = [];
|
|
4588
|
+
for (let e21 of y2) {
|
|
4589
|
+
let v3 = await safeValidateTypes({
|
|
4590
|
+
value: e21,
|
|
4591
|
+
schema: b
|
|
4592
|
+
});
|
|
4593
|
+
v3.success && x.push(v3.value);
|
|
4594
|
+
}
|
|
4595
|
+
return { partial: x };
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
},
|
|
4599
|
+
createElementStreamTransform() {
|
|
4600
|
+
let e19 = 0;
|
|
4601
|
+
return new TransformStream({ transform({ partialOutput: v2 }, y2) {
|
|
4602
|
+
if (v2 != null) for (; e19 < v2.length; e19++) y2.enqueue(v2[e19]);
|
|
4603
|
+
} });
|
|
4604
|
+
}
|
|
4605
|
+
};
|
|
4606
|
+
}, choice = ({ options: e18, name: v, description: y }) => ({
|
|
4607
|
+
name: "choice",
|
|
4608
|
+
responseFormat: Promise.resolve({
|
|
4609
|
+
type: "json",
|
|
4610
|
+
schema: {
|
|
4611
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
4612
|
+
type: "object",
|
|
4613
|
+
properties: { result: {
|
|
4614
|
+
type: "string",
|
|
4615
|
+
enum: e18
|
|
4616
|
+
} },
|
|
4617
|
+
required: ["result"],
|
|
4618
|
+
additionalProperties: false
|
|
4619
|
+
},
|
|
4620
|
+
...v != null && { name: v },
|
|
4621
|
+
...y != null && { description: y }
|
|
4622
|
+
}),
|
|
4623
|
+
async parseCompleteOutput({ text: v2 }, y2) {
|
|
4624
|
+
let b = await safeParseJSON({ text: v2 });
|
|
4625
|
+
if (!b.success) throw new NoObjectGeneratedError({
|
|
4626
|
+
message: "No object generated: could not parse the response.",
|
|
4627
|
+
cause: b.error,
|
|
4628
|
+
text: v2,
|
|
4629
|
+
response: y2.response,
|
|
4630
|
+
usage: y2.usage,
|
|
4631
|
+
finishReason: y2.finishReason
|
|
4632
|
+
});
|
|
4633
|
+
let x = b.value;
|
|
4634
|
+
if (typeof x != "object" || !x || !("result" in x) || typeof x.result != "string" || !e18.includes(x.result)) throw new NoObjectGeneratedError({
|
|
4635
|
+
message: "No object generated: response did not match schema.",
|
|
4636
|
+
cause: new TypeValidationError({
|
|
4637
|
+
value: x,
|
|
4638
|
+
cause: "response must be an object that contains a choice value."
|
|
4639
|
+
}),
|
|
4640
|
+
text: v2,
|
|
4641
|
+
response: y2.response,
|
|
4642
|
+
usage: y2.usage,
|
|
4643
|
+
finishReason: y2.finishReason
|
|
4644
|
+
});
|
|
4645
|
+
return x.result;
|
|
4646
|
+
},
|
|
4647
|
+
async parsePartialOutput({ text: v2 }) {
|
|
4648
|
+
let y2 = await parsePartialJson(v2);
|
|
4649
|
+
switch (y2.state) {
|
|
4650
|
+
case "failed-parse":
|
|
4651
|
+
case "undefined-input":
|
|
4652
|
+
return;
|
|
4653
|
+
case "repaired-parse":
|
|
4654
|
+
case "successful-parse": {
|
|
4655
|
+
let v3 = y2.value;
|
|
4656
|
+
if (typeof v3 != "object" || !v3 || !("result" in v3) || typeof v3.result != "string") return;
|
|
4657
|
+
let b = e18.filter((e19) => e19.startsWith(v3.result));
|
|
4658
|
+
return y2.state === "successful-parse" ? b.includes(v3.result) ? { partial: v3.result } : void 0 : b.length === 1 ? { partial: b[0] } : void 0;
|
|
4659
|
+
}
|
|
4660
|
+
}
|
|
4661
|
+
},
|
|
4662
|
+
createElementStreamTransform() {
|
|
4663
|
+
}
|
|
4664
|
+
}), json = ({ name: e18, description: v } = {}) => ({
|
|
4665
|
+
name: "json",
|
|
4666
|
+
responseFormat: Promise.resolve({
|
|
4667
|
+
type: "json",
|
|
4668
|
+
...e18 != null && { name: e18 },
|
|
4669
|
+
...v != null && { description: v }
|
|
4670
|
+
}),
|
|
4671
|
+
async parseCompleteOutput({ text: e19 }, v2) {
|
|
4672
|
+
let y = await safeParseJSON({ text: e19 });
|
|
4673
|
+
if (!y.success) throw new NoObjectGeneratedError({
|
|
4674
|
+
message: "No object generated: could not parse the response.",
|
|
4675
|
+
cause: y.error,
|
|
4676
|
+
text: e19,
|
|
4677
|
+
response: v2.response,
|
|
4678
|
+
usage: v2.usage,
|
|
4679
|
+
finishReason: v2.finishReason
|
|
4680
|
+
});
|
|
4681
|
+
return y.value;
|
|
4682
|
+
},
|
|
4683
|
+
async parsePartialOutput({ text: e19 }) {
|
|
4684
|
+
let v2 = await parsePartialJson(e19);
|
|
4685
|
+
switch (v2.state) {
|
|
4686
|
+
case "failed-parse":
|
|
4687
|
+
case "undefined-input":
|
|
4688
|
+
return;
|
|
4689
|
+
case "repaired-parse":
|
|
4690
|
+
case "successful-parse":
|
|
4691
|
+
return v2.value === void 0 ? void 0 : { partial: v2.value };
|
|
4692
|
+
}
|
|
4693
|
+
},
|
|
4694
|
+
createElementStreamTransform() {
|
|
4695
|
+
}
|
|
4696
|
+
});
|
|
4697
|
+
createIdGenerator({
|
|
4698
|
+
prefix: "aitxt",
|
|
4699
|
+
size: 24
|
|
4700
|
+
});
|
|
4701
|
+
function prepareHeaders(e18, v) {
|
|
4702
|
+
let y = new Headers(e18 ?? {});
|
|
4703
|
+
for (let [e19, b] of Object.entries(v)) y.has(e19) || y.set(e19, b);
|
|
4704
|
+
return y;
|
|
4705
|
+
}
|
|
4706
|
+
var JsonToSseTransformStream = class extends TransformStream {
|
|
4707
|
+
constructor() {
|
|
4708
|
+
super({
|
|
4709
|
+
transform(e18, v) {
|
|
4710
|
+
v.enqueue(`data: ${JSON.stringify(e18)}
|
|
4711
|
+
|
|
4712
|
+
`);
|
|
4713
|
+
},
|
|
4714
|
+
flush(e18) {
|
|
4715
|
+
e18.enqueue("data: [DONE]\n\n");
|
|
4716
|
+
}
|
|
4717
|
+
});
|
|
4718
|
+
}
|
|
4719
|
+
}, UI_MESSAGE_STREAM_HEADERS = {
|
|
4720
|
+
"content-type": "text/event-stream",
|
|
4721
|
+
"cache-control": "no-cache",
|
|
4722
|
+
connection: "keep-alive",
|
|
4723
|
+
"x-vercel-ai-ui-message-stream": "v1",
|
|
4724
|
+
"x-accel-buffering": "no"
|
|
4725
|
+
};
|
|
4726
|
+
function createUIMessageStreamResponse({ status: e18, statusText: v, headers: y, stream: b, consumeSseStream: x }) {
|
|
4727
|
+
let S = b.pipeThrough(new JsonToSseTransformStream());
|
|
4728
|
+
if (x) {
|
|
4729
|
+
let [e19, v2] = S.tee();
|
|
4730
|
+
S = e19, x({ stream: v2 });
|
|
4731
|
+
}
|
|
4732
|
+
return new Response(S.pipeThrough(new TextEncoderStream()), {
|
|
4733
|
+
status: e18,
|
|
4734
|
+
statusText: v,
|
|
4735
|
+
headers: prepareHeaders(y, UI_MESSAGE_STREAM_HEADERS)
|
|
4736
|
+
});
|
|
4737
|
+
}
|
|
4738
|
+
var uiMessageChunkSchema = lazySchema(() => zodSchema(union([
|
|
4739
|
+
strictObject({
|
|
4740
|
+
type: literal("text-start"),
|
|
4741
|
+
id: string(),
|
|
4742
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
4743
|
+
}),
|
|
4744
|
+
strictObject({
|
|
4745
|
+
type: literal("text-delta"),
|
|
4746
|
+
id: string(),
|
|
4747
|
+
delta: string(),
|
|
4748
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
4749
|
+
}),
|
|
4750
|
+
strictObject({
|
|
4751
|
+
type: literal("text-end"),
|
|
4752
|
+
id: string(),
|
|
4753
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
4754
|
+
}),
|
|
4755
|
+
strictObject({
|
|
4756
|
+
type: literal("error"),
|
|
4757
|
+
errorText: string()
|
|
4758
|
+
}),
|
|
4759
|
+
strictObject({
|
|
4760
|
+
type: literal("tool-input-start"),
|
|
4761
|
+
toolCallId: string(),
|
|
4762
|
+
toolName: string(),
|
|
4763
|
+
providerExecuted: boolean().optional(),
|
|
4764
|
+
providerMetadata: providerMetadataSchema.optional(),
|
|
4765
|
+
dynamic: boolean().optional(),
|
|
4766
|
+
title: string().optional()
|
|
4767
|
+
}),
|
|
4768
|
+
strictObject({
|
|
4769
|
+
type: literal("tool-input-delta"),
|
|
4770
|
+
toolCallId: string(),
|
|
4771
|
+
inputTextDelta: string()
|
|
4772
|
+
}),
|
|
4773
|
+
strictObject({
|
|
4774
|
+
type: literal("tool-input-available"),
|
|
4775
|
+
toolCallId: string(),
|
|
4776
|
+
toolName: string(),
|
|
4777
|
+
input: unknown(),
|
|
4778
|
+
providerExecuted: boolean().optional(),
|
|
4779
|
+
providerMetadata: providerMetadataSchema.optional(),
|
|
4780
|
+
dynamic: boolean().optional(),
|
|
4781
|
+
title: string().optional()
|
|
4782
|
+
}),
|
|
4783
|
+
strictObject({
|
|
4784
|
+
type: literal("tool-input-error"),
|
|
4785
|
+
toolCallId: string(),
|
|
4786
|
+
toolName: string(),
|
|
4787
|
+
input: unknown(),
|
|
4788
|
+
providerExecuted: boolean().optional(),
|
|
4789
|
+
providerMetadata: providerMetadataSchema.optional(),
|
|
4790
|
+
dynamic: boolean().optional(),
|
|
4791
|
+
errorText: string(),
|
|
4792
|
+
title: string().optional()
|
|
4793
|
+
}),
|
|
4794
|
+
strictObject({
|
|
4795
|
+
type: literal("tool-approval-request"),
|
|
4796
|
+
approvalId: string(),
|
|
4797
|
+
toolCallId: string()
|
|
4798
|
+
}),
|
|
4799
|
+
strictObject({
|
|
4800
|
+
type: literal("tool-output-available"),
|
|
4801
|
+
toolCallId: string(),
|
|
4802
|
+
output: unknown(),
|
|
4803
|
+
providerExecuted: boolean().optional(),
|
|
4804
|
+
providerMetadata: providerMetadataSchema.optional(),
|
|
4805
|
+
dynamic: boolean().optional(),
|
|
4806
|
+
preliminary: boolean().optional()
|
|
4807
|
+
}),
|
|
4808
|
+
strictObject({
|
|
4809
|
+
type: literal("tool-output-error"),
|
|
4810
|
+
toolCallId: string(),
|
|
4811
|
+
errorText: string(),
|
|
4812
|
+
providerExecuted: boolean().optional(),
|
|
4813
|
+
providerMetadata: providerMetadataSchema.optional(),
|
|
4814
|
+
dynamic: boolean().optional()
|
|
4815
|
+
}),
|
|
4816
|
+
strictObject({
|
|
4817
|
+
type: literal("tool-output-denied"),
|
|
4818
|
+
toolCallId: string()
|
|
4819
|
+
}),
|
|
4820
|
+
strictObject({
|
|
4821
|
+
type: literal("reasoning-start"),
|
|
4822
|
+
id: string(),
|
|
4823
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
4824
|
+
}),
|
|
4825
|
+
strictObject({
|
|
4826
|
+
type: literal("reasoning-delta"),
|
|
4827
|
+
id: string(),
|
|
4828
|
+
delta: string(),
|
|
4829
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
4830
|
+
}),
|
|
4831
|
+
strictObject({
|
|
4832
|
+
type: literal("reasoning-end"),
|
|
4833
|
+
id: string(),
|
|
4834
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
4835
|
+
}),
|
|
4836
|
+
strictObject({
|
|
4837
|
+
type: literal("source-url"),
|
|
4838
|
+
sourceId: string(),
|
|
4839
|
+
url: string(),
|
|
4840
|
+
title: string().optional(),
|
|
4841
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
4842
|
+
}),
|
|
4843
|
+
strictObject({
|
|
4844
|
+
type: literal("source-document"),
|
|
4845
|
+
sourceId: string(),
|
|
4846
|
+
mediaType: string(),
|
|
4847
|
+
title: string(),
|
|
4848
|
+
filename: string().optional(),
|
|
4849
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
4850
|
+
}),
|
|
4851
|
+
strictObject({
|
|
4852
|
+
type: literal("file"),
|
|
4853
|
+
url: string(),
|
|
4854
|
+
mediaType: string(),
|
|
4855
|
+
providerMetadata: providerMetadataSchema.optional()
|
|
4856
|
+
}),
|
|
4857
|
+
strictObject({
|
|
4858
|
+
type: custom((e18) => typeof e18 == "string" && e18.startsWith("data-"), { message: 'Type must start with "data-"' }),
|
|
4859
|
+
id: string().optional(),
|
|
4860
|
+
data: unknown(),
|
|
4861
|
+
transient: boolean().optional()
|
|
4862
|
+
}),
|
|
4863
|
+
strictObject({ type: literal("start-step") }),
|
|
4864
|
+
strictObject({ type: literal("finish-step") }),
|
|
4865
|
+
strictObject({
|
|
4866
|
+
type: literal("start"),
|
|
4867
|
+
messageId: string().optional(),
|
|
4868
|
+
messageMetadata: unknown().optional()
|
|
4869
|
+
}),
|
|
4870
|
+
strictObject({
|
|
4871
|
+
type: literal("finish"),
|
|
4872
|
+
finishReason: _enum([
|
|
4873
|
+
"stop",
|
|
4874
|
+
"length",
|
|
4875
|
+
"content-filter",
|
|
4876
|
+
"tool-calls",
|
|
4877
|
+
"error",
|
|
4878
|
+
"other"
|
|
4879
|
+
]).optional(),
|
|
4880
|
+
messageMetadata: unknown().optional()
|
|
4881
|
+
}),
|
|
4882
|
+
strictObject({
|
|
4883
|
+
type: literal("abort"),
|
|
4884
|
+
reason: string().optional()
|
|
4885
|
+
}),
|
|
4886
|
+
strictObject({
|
|
4887
|
+
type: literal("message-metadata"),
|
|
4888
|
+
messageMetadata: unknown()
|
|
4889
|
+
})
|
|
4890
|
+
])));
|
|
4891
|
+
function isDataUIMessageChunk(e18) {
|
|
4892
|
+
return e18.type.startsWith("data-");
|
|
4893
|
+
}
|
|
4894
|
+
function isStaticToolUIPart(e18) {
|
|
4564
4895
|
return e18.type.startsWith("tool-");
|
|
4565
4896
|
}
|
|
4566
4897
|
function isDynamicToolUIPart(e18) {
|
|
4567
4898
|
return e18.type === "dynamic-tool";
|
|
4568
4899
|
}
|
|
4569
|
-
function
|
|
4570
|
-
return
|
|
4900
|
+
function isToolUIPart(e18) {
|
|
4901
|
+
return isStaticToolUIPart(e18) || isDynamicToolUIPart(e18);
|
|
4571
4902
|
}
|
|
4572
|
-
function
|
|
4903
|
+
function getStaticToolName(e18) {
|
|
4573
4904
|
return e18.type.split("-").slice(1).join("-");
|
|
4574
4905
|
}
|
|
4575
4906
|
function createStreamingUIMessageState({ lastMessage: e18, messageId: v }) {
|
|
@@ -4590,32 +4921,47 @@ function processUIMessageStream({ stream: e18, messageMetadataSchema: v, dataPar
|
|
|
4590
4921
|
await b(async ({ state: b2, write: T }) => {
|
|
4591
4922
|
function E(e20) {
|
|
4592
4923
|
let v2 = b2.message.parts.filter(isToolUIPart).find((v3) => v3.toolCallId === e20);
|
|
4593
|
-
if (v2 == null) throw
|
|
4924
|
+
if (v2 == null) throw new UIMessageStreamError({
|
|
4925
|
+
chunkType: "tool-invocation",
|
|
4926
|
+
chunkId: e20,
|
|
4927
|
+
message: `No tool invocation found for tool call ID "${e20}".`
|
|
4928
|
+
});
|
|
4594
4929
|
return v2;
|
|
4595
4930
|
}
|
|
4596
4931
|
function D(e20) {
|
|
4597
|
-
let v2 = b2.message.parts.
|
|
4598
|
-
if (v2
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
|
|
4603
|
-
|
|
4932
|
+
let v2 = b2.message.parts.find((v3) => isStaticToolUIPart(v3) && v3.toolCallId === e20.toolCallId), y2 = e20, x2 = v2;
|
|
4933
|
+
if (v2 != null) {
|
|
4934
|
+
v2.state = e20.state, x2.input = y2.input, x2.output = y2.output, x2.errorText = y2.errorText, x2.rawInput = y2.rawInput, x2.preliminary = y2.preliminary, e20.title !== void 0 && (x2.title = e20.title), x2.providerExecuted = y2.providerExecuted ?? v2.providerExecuted;
|
|
4935
|
+
let b3 = y2.providerMetadata;
|
|
4936
|
+
if (b3 != null) if (e20.state === "output-available" || e20.state === "output-error") {
|
|
4937
|
+
let e21 = v2;
|
|
4938
|
+
e21.resultProviderMetadata = b3;
|
|
4939
|
+
} else v2.callProviderMetadata = b3;
|
|
4940
|
+
} else b2.message.parts.push({
|
|
4604
4941
|
type: `tool-${e20.toolName}`,
|
|
4605
4942
|
toolCallId: e20.toolCallId,
|
|
4606
4943
|
state: e20.state,
|
|
4944
|
+
title: e20.title,
|
|
4607
4945
|
input: y2.input,
|
|
4608
4946
|
output: y2.output,
|
|
4609
4947
|
rawInput: y2.rawInput,
|
|
4610
4948
|
errorText: y2.errorText,
|
|
4611
4949
|
providerExecuted: y2.providerExecuted,
|
|
4612
4950
|
preliminary: y2.preliminary,
|
|
4613
|
-
...y2.providerMetadata
|
|
4614
|
-
|
|
4951
|
+
...y2.providerMetadata != null && (e20.state === "output-available" || e20.state === "output-error") ? { resultProviderMetadata: y2.providerMetadata } : {},
|
|
4952
|
+
...y2.providerMetadata != null && !(e20.state === "output-available" || e20.state === "output-error") ? { callProviderMetadata: y2.providerMetadata } : {}
|
|
4953
|
+
});
|
|
4615
4954
|
}
|
|
4616
|
-
function
|
|
4955
|
+
function O(e20) {
|
|
4617
4956
|
let v2 = b2.message.parts.find((v3) => v3.type === "dynamic-tool" && v3.toolCallId === e20.toolCallId), y2 = e20, x2 = v2;
|
|
4618
|
-
v2
|
|
4957
|
+
if (v2 != null) {
|
|
4958
|
+
v2.state = e20.state, x2.toolName = e20.toolName, x2.input = y2.input, x2.output = y2.output, x2.errorText = y2.errorText, x2.rawInput = y2.rawInput ?? x2.rawInput, x2.preliminary = y2.preliminary, e20.title !== void 0 && (x2.title = e20.title), x2.providerExecuted = y2.providerExecuted ?? v2.providerExecuted;
|
|
4959
|
+
let b3 = y2.providerMetadata;
|
|
4960
|
+
if (b3 != null) if (e20.state === "output-available" || e20.state === "output-error") {
|
|
4961
|
+
let e21 = v2;
|
|
4962
|
+
e21.resultProviderMetadata = b3;
|
|
4963
|
+
} else v2.callProviderMetadata = b3;
|
|
4964
|
+
} else b2.message.parts.push({
|
|
4619
4965
|
type: "dynamic-tool",
|
|
4620
4966
|
toolName: e20.toolName,
|
|
4621
4967
|
toolCallId: e20.toolCallId,
|
|
@@ -4625,15 +4971,21 @@ function processUIMessageStream({ stream: e18, messageMetadataSchema: v, dataPar
|
|
|
4625
4971
|
errorText: y2.errorText,
|
|
4626
4972
|
preliminary: y2.preliminary,
|
|
4627
4973
|
providerExecuted: y2.providerExecuted,
|
|
4628
|
-
|
|
4629
|
-
|
|
4974
|
+
title: e20.title,
|
|
4975
|
+
...y2.providerMetadata != null && (e20.state === "output-available" || e20.state === "output-error") ? { resultProviderMetadata: y2.providerMetadata } : {},
|
|
4976
|
+
...y2.providerMetadata != null && !(e20.state === "output-available" || e20.state === "output-error") ? { callProviderMetadata: y2.providerMetadata } : {}
|
|
4977
|
+
});
|
|
4630
4978
|
}
|
|
4631
|
-
async function
|
|
4979
|
+
async function k(e20) {
|
|
4632
4980
|
if (e20 != null) {
|
|
4633
4981
|
let y2 = b2.message.metadata == null ? e20 : mergeObjects(b2.message.metadata, e20);
|
|
4634
4982
|
v != null && await validateTypes({
|
|
4635
4983
|
value: y2,
|
|
4636
|
-
schema: v
|
|
4984
|
+
schema: v,
|
|
4985
|
+
context: {
|
|
4986
|
+
field: "message.metadata",
|
|
4987
|
+
entityId: b2.message.id
|
|
4988
|
+
}
|
|
4637
4989
|
}), b2.message.metadata = y2;
|
|
4638
4990
|
}
|
|
4639
4991
|
}
|
|
@@ -4650,11 +5002,21 @@ function processUIMessageStream({ stream: e18, messageMetadataSchema: v, dataPar
|
|
|
4650
5002
|
}
|
|
4651
5003
|
case "text-delta": {
|
|
4652
5004
|
let v2 = b2.activeTextParts[e19.id];
|
|
5005
|
+
if (v2 == null) throw new UIMessageStreamError({
|
|
5006
|
+
chunkType: "text-delta",
|
|
5007
|
+
chunkId: e19.id,
|
|
5008
|
+
message: `Received text-delta for missing text part with ID "${e19.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`
|
|
5009
|
+
});
|
|
4653
5010
|
v2.text += e19.delta, v2.providerMetadata = e19.providerMetadata ?? v2.providerMetadata, T();
|
|
4654
5011
|
break;
|
|
4655
5012
|
}
|
|
4656
5013
|
case "text-end": {
|
|
4657
5014
|
let v2 = b2.activeTextParts[e19.id];
|
|
5015
|
+
if (v2 == null) throw new UIMessageStreamError({
|
|
5016
|
+
chunkType: "text-end",
|
|
5017
|
+
chunkId: e19.id,
|
|
5018
|
+
message: `Received text-end for missing text part with ID "${e19.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`
|
|
5019
|
+
});
|
|
4658
5020
|
v2.state = "done", v2.providerMetadata = e19.providerMetadata ?? v2.providerMetadata, delete b2.activeTextParts[e19.id], T();
|
|
4659
5021
|
break;
|
|
4660
5022
|
}
|
|
@@ -4670,11 +5032,21 @@ function processUIMessageStream({ stream: e18, messageMetadataSchema: v, dataPar
|
|
|
4670
5032
|
}
|
|
4671
5033
|
case "reasoning-delta": {
|
|
4672
5034
|
let v2 = b2.activeReasoningParts[e19.id];
|
|
5035
|
+
if (v2 == null) throw new UIMessageStreamError({
|
|
5036
|
+
chunkType: "reasoning-delta",
|
|
5037
|
+
chunkId: e19.id,
|
|
5038
|
+
message: `Received reasoning-delta for missing reasoning part with ID "${e19.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`
|
|
5039
|
+
});
|
|
4673
5040
|
v2.text += e19.delta, v2.providerMetadata = e19.providerMetadata ?? v2.providerMetadata, T();
|
|
4674
5041
|
break;
|
|
4675
5042
|
}
|
|
4676
5043
|
case "reasoning-end": {
|
|
4677
5044
|
let v2 = b2.activeReasoningParts[e19.id];
|
|
5045
|
+
if (v2 == null) throw new UIMessageStreamError({
|
|
5046
|
+
chunkType: "reasoning-end",
|
|
5047
|
+
chunkId: e19.id,
|
|
5048
|
+
message: `Received reasoning-end for missing reasoning part with ID "${e19.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`
|
|
5049
|
+
});
|
|
4678
5050
|
v2.providerMetadata = e19.providerMetadata ?? v2.providerMetadata, v2.state = "done", delete b2.activeReasoningParts[e19.id], T();
|
|
4679
5051
|
break;
|
|
4680
5052
|
}
|
|
@@ -4682,7 +5054,8 @@ function processUIMessageStream({ stream: e18, messageMetadataSchema: v, dataPar
|
|
|
4682
5054
|
b2.message.parts.push({
|
|
4683
5055
|
type: "file",
|
|
4684
5056
|
mediaType: e19.mediaType,
|
|
4685
|
-
url: e19.url
|
|
5057
|
+
url: e19.url,
|
|
5058
|
+
...e19.providerMetadata == null ? {} : { providerMetadata: e19.providerMetadata }
|
|
4686
5059
|
}), T();
|
|
4687
5060
|
break;
|
|
4688
5061
|
case "source-url":
|
|
@@ -4705,63 +5078,78 @@ function processUIMessageStream({ stream: e18, messageMetadataSchema: v, dataPar
|
|
|
4705
5078
|
}), T();
|
|
4706
5079
|
break;
|
|
4707
5080
|
case "tool-input-start": {
|
|
4708
|
-
let v2 = b2.message.parts.filter(
|
|
5081
|
+
let v2 = b2.message.parts.filter(isStaticToolUIPart);
|
|
4709
5082
|
b2.partialToolCalls[e19.toolCallId] = {
|
|
4710
5083
|
text: "",
|
|
4711
5084
|
toolName: e19.toolName,
|
|
4712
5085
|
index: v2.length,
|
|
4713
|
-
dynamic: e19.dynamic
|
|
4714
|
-
|
|
5086
|
+
dynamic: e19.dynamic,
|
|
5087
|
+
title: e19.title
|
|
5088
|
+
}, e19.dynamic ? O({
|
|
4715
5089
|
toolCallId: e19.toolCallId,
|
|
4716
5090
|
toolName: e19.toolName,
|
|
4717
5091
|
state: "input-streaming",
|
|
4718
5092
|
input: void 0,
|
|
4719
|
-
providerExecuted: e19.providerExecuted
|
|
4720
|
-
|
|
5093
|
+
providerExecuted: e19.providerExecuted,
|
|
5094
|
+
title: e19.title,
|
|
5095
|
+
providerMetadata: e19.providerMetadata
|
|
5096
|
+
}) : D({
|
|
4721
5097
|
toolCallId: e19.toolCallId,
|
|
4722
5098
|
toolName: e19.toolName,
|
|
4723
5099
|
state: "input-streaming",
|
|
4724
5100
|
input: void 0,
|
|
4725
|
-
providerExecuted: e19.providerExecuted
|
|
5101
|
+
providerExecuted: e19.providerExecuted,
|
|
5102
|
+
title: e19.title,
|
|
5103
|
+
providerMetadata: e19.providerMetadata
|
|
4726
5104
|
}), T();
|
|
4727
5105
|
break;
|
|
4728
5106
|
}
|
|
4729
5107
|
case "tool-input-delta": {
|
|
4730
5108
|
let v2 = b2.partialToolCalls[e19.toolCallId];
|
|
5109
|
+
if (v2 == null) throw new UIMessageStreamError({
|
|
5110
|
+
chunkType: "tool-input-delta",
|
|
5111
|
+
chunkId: e19.toolCallId,
|
|
5112
|
+
message: `Received tool-input-delta for missing tool call with ID "${e19.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`
|
|
5113
|
+
});
|
|
4731
5114
|
v2.text += e19.inputTextDelta;
|
|
4732
5115
|
let { value: y2 } = await parsePartialJson(v2.text);
|
|
4733
|
-
v2.dynamic ?
|
|
5116
|
+
v2.dynamic ? O({
|
|
4734
5117
|
toolCallId: e19.toolCallId,
|
|
4735
5118
|
toolName: v2.toolName,
|
|
4736
5119
|
state: "input-streaming",
|
|
4737
|
-
input: y2
|
|
4738
|
-
|
|
5120
|
+
input: y2,
|
|
5121
|
+
title: v2.title
|
|
5122
|
+
}) : D({
|
|
4739
5123
|
toolCallId: e19.toolCallId,
|
|
4740
5124
|
toolName: v2.toolName,
|
|
4741
5125
|
state: "input-streaming",
|
|
4742
|
-
input: y2
|
|
5126
|
+
input: y2,
|
|
5127
|
+
title: v2.title
|
|
4743
5128
|
}), T();
|
|
4744
5129
|
break;
|
|
4745
5130
|
}
|
|
4746
5131
|
case "tool-input-available":
|
|
4747
|
-
e19.dynamic ?
|
|
5132
|
+
e19.dynamic ? O({
|
|
4748
5133
|
toolCallId: e19.toolCallId,
|
|
4749
5134
|
toolName: e19.toolName,
|
|
4750
5135
|
state: "input-available",
|
|
4751
5136
|
input: e19.input,
|
|
4752
5137
|
providerExecuted: e19.providerExecuted,
|
|
4753
|
-
providerMetadata: e19.providerMetadata
|
|
4754
|
-
|
|
5138
|
+
providerMetadata: e19.providerMetadata,
|
|
5139
|
+
title: e19.title
|
|
5140
|
+
}) : D({
|
|
4755
5141
|
toolCallId: e19.toolCallId,
|
|
4756
5142
|
toolName: e19.toolName,
|
|
4757
5143
|
state: "input-available",
|
|
4758
5144
|
input: e19.input,
|
|
4759
5145
|
providerExecuted: e19.providerExecuted,
|
|
4760
|
-
providerMetadata: e19.providerMetadata
|
|
5146
|
+
providerMetadata: e19.providerMetadata,
|
|
5147
|
+
title: e19.title
|
|
4761
5148
|
}), T(), S && !e19.providerExecuted && await S({ toolCall: e19 });
|
|
4762
5149
|
break;
|
|
4763
|
-
case "tool-input-error":
|
|
4764
|
-
|
|
5150
|
+
case "tool-input-error": {
|
|
5151
|
+
let v2 = b2.message.parts.filter(isToolUIPart).find((v3) => v3.toolCallId === e19.toolCallId);
|
|
5152
|
+
(v2 == null ? e19.dynamic : v2.type === "dynamic-tool") ? O({
|
|
4765
5153
|
toolCallId: e19.toolCallId,
|
|
4766
5154
|
toolName: e19.toolName,
|
|
4767
5155
|
state: "output-error",
|
|
@@ -4769,7 +5157,7 @@ function processUIMessageStream({ stream: e18, messageMetadataSchema: v, dataPar
|
|
|
4769
5157
|
errorText: e19.errorText,
|
|
4770
5158
|
providerExecuted: e19.providerExecuted,
|
|
4771
5159
|
providerMetadata: e19.providerMetadata
|
|
4772
|
-
}) :
|
|
5160
|
+
}) : D({
|
|
4773
5161
|
toolCallId: e19.toolCallId,
|
|
4774
5162
|
toolName: e19.toolName,
|
|
4775
5163
|
state: "output-error",
|
|
@@ -4780,56 +5168,66 @@ function processUIMessageStream({ stream: e18, messageMetadataSchema: v, dataPar
|
|
|
4780
5168
|
providerMetadata: e19.providerMetadata
|
|
4781
5169
|
}), T();
|
|
4782
5170
|
break;
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
toolCallId: e19.toolCallId,
|
|
4788
|
-
toolName: v2.toolName,
|
|
4789
|
-
state: "output-available",
|
|
4790
|
-
input: v2.input,
|
|
4791
|
-
output: e19.output,
|
|
4792
|
-
preliminary: e19.preliminary
|
|
4793
|
-
});
|
|
4794
|
-
} else {
|
|
4795
|
-
let v2 = E(e19.toolCallId);
|
|
4796
|
-
O({
|
|
4797
|
-
toolCallId: e19.toolCallId,
|
|
4798
|
-
toolName: getToolName(v2),
|
|
4799
|
-
state: "output-available",
|
|
4800
|
-
input: v2.input,
|
|
4801
|
-
output: e19.output,
|
|
4802
|
-
providerExecuted: e19.providerExecuted,
|
|
4803
|
-
preliminary: e19.preliminary
|
|
4804
|
-
});
|
|
4805
|
-
}
|
|
4806
|
-
T();
|
|
5171
|
+
}
|
|
5172
|
+
case "tool-approval-request": {
|
|
5173
|
+
let v2 = E(e19.toolCallId);
|
|
5174
|
+
v2.state = "approval-requested", v2.approval = { id: e19.approvalId }, T();
|
|
4807
5175
|
break;
|
|
4808
|
-
|
|
4809
|
-
|
|
4810
|
-
|
|
4811
|
-
|
|
4812
|
-
|
|
4813
|
-
|
|
4814
|
-
|
|
4815
|
-
|
|
4816
|
-
|
|
4817
|
-
|
|
4818
|
-
|
|
4819
|
-
|
|
4820
|
-
|
|
4821
|
-
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
5176
|
+
}
|
|
5177
|
+
case "tool-output-denied": {
|
|
5178
|
+
let v2 = E(e19.toolCallId);
|
|
5179
|
+
v2.state = "output-denied", T();
|
|
5180
|
+
break;
|
|
5181
|
+
}
|
|
5182
|
+
case "tool-output-available": {
|
|
5183
|
+
let v2 = E(e19.toolCallId);
|
|
5184
|
+
v2.type === "dynamic-tool" ? O({
|
|
5185
|
+
toolCallId: e19.toolCallId,
|
|
5186
|
+
toolName: v2.toolName,
|
|
5187
|
+
state: "output-available",
|
|
5188
|
+
input: v2.input,
|
|
5189
|
+
output: e19.output,
|
|
5190
|
+
preliminary: e19.preliminary,
|
|
5191
|
+
providerExecuted: e19.providerExecuted,
|
|
5192
|
+
providerMetadata: e19.providerMetadata,
|
|
5193
|
+
title: v2.title
|
|
5194
|
+
}) : D({
|
|
5195
|
+
toolCallId: e19.toolCallId,
|
|
5196
|
+
toolName: getStaticToolName(v2),
|
|
5197
|
+
state: "output-available",
|
|
5198
|
+
input: v2.input,
|
|
5199
|
+
output: e19.output,
|
|
5200
|
+
providerExecuted: e19.providerExecuted,
|
|
5201
|
+
preliminary: e19.preliminary,
|
|
5202
|
+
providerMetadata: e19.providerMetadata,
|
|
5203
|
+
title: v2.title
|
|
5204
|
+
}), T();
|
|
4832
5205
|
break;
|
|
5206
|
+
}
|
|
5207
|
+
case "tool-output-error": {
|
|
5208
|
+
let v2 = E(e19.toolCallId);
|
|
5209
|
+
v2.type === "dynamic-tool" ? O({
|
|
5210
|
+
toolCallId: e19.toolCallId,
|
|
5211
|
+
toolName: v2.toolName,
|
|
5212
|
+
state: "output-error",
|
|
5213
|
+
input: v2.input,
|
|
5214
|
+
errorText: e19.errorText,
|
|
5215
|
+
providerExecuted: e19.providerExecuted,
|
|
5216
|
+
providerMetadata: e19.providerMetadata,
|
|
5217
|
+
title: v2.title
|
|
5218
|
+
}) : D({
|
|
5219
|
+
toolCallId: e19.toolCallId,
|
|
5220
|
+
toolName: getStaticToolName(v2),
|
|
5221
|
+
state: "output-error",
|
|
5222
|
+
input: v2.input,
|
|
5223
|
+
rawInput: v2.rawInput,
|
|
5224
|
+
errorText: e19.errorText,
|
|
5225
|
+
providerExecuted: e19.providerExecuted,
|
|
5226
|
+
providerMetadata: e19.providerMetadata,
|
|
5227
|
+
title: v2.title
|
|
5228
|
+
}), T();
|
|
5229
|
+
break;
|
|
5230
|
+
}
|
|
4833
5231
|
case "start-step":
|
|
4834
5232
|
b2.message.parts.push({ type: "step-start" });
|
|
4835
5233
|
break;
|
|
@@ -4837,23 +5235,31 @@ function processUIMessageStream({ stream: e18, messageMetadataSchema: v, dataPar
|
|
|
4837
5235
|
b2.activeTextParts = {}, b2.activeReasoningParts = {};
|
|
4838
5236
|
break;
|
|
4839
5237
|
case "start":
|
|
4840
|
-
e19.messageId != null && (b2.message.id = e19.messageId), await
|
|
5238
|
+
e19.messageId != null && (b2.message.id = e19.messageId), await k(e19.messageMetadata), (e19.messageId != null || e19.messageMetadata != null) && T();
|
|
4841
5239
|
break;
|
|
4842
5240
|
case "finish":
|
|
4843
|
-
e19.finishReason != null && (b2.finishReason = e19.finishReason), await
|
|
5241
|
+
e19.finishReason != null && (b2.finishReason = e19.finishReason), await k(e19.messageMetadata), e19.messageMetadata != null && T();
|
|
4844
5242
|
break;
|
|
4845
5243
|
case "message-metadata":
|
|
4846
|
-
await
|
|
5244
|
+
await k(e19.messageMetadata), e19.messageMetadata != null && T();
|
|
4847
5245
|
break;
|
|
4848
5246
|
case "error":
|
|
4849
5247
|
x == null ? void 0 : x(Error(e19.errorText));
|
|
4850
5248
|
break;
|
|
4851
5249
|
default:
|
|
4852
5250
|
if (isDataUIMessageChunk(e19)) {
|
|
4853
|
-
(y == null ? void 0 : y[e19.type]) != null
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
5251
|
+
if ((y == null ? void 0 : y[e19.type]) != null) {
|
|
5252
|
+
let v3 = b2.message.parts.findIndex((v4) => "id" in v4 && "data" in v4 && v4.id === e19.id && v4.type === e19.type), x3 = v3 >= 0 ? v3 : b2.message.parts.length;
|
|
5253
|
+
await validateTypes({
|
|
5254
|
+
value: e19.data,
|
|
5255
|
+
schema: y[e19.type],
|
|
5256
|
+
context: {
|
|
5257
|
+
field: `message.parts[${x3}].data`,
|
|
5258
|
+
entityName: e19.type,
|
|
5259
|
+
entityId: e19.id
|
|
5260
|
+
}
|
|
5261
|
+
});
|
|
5262
|
+
}
|
|
4857
5263
|
let v2 = e19;
|
|
4858
5264
|
if (v2.transient) {
|
|
4859
5265
|
C == null ? void 0 : C(v2);
|
|
@@ -4912,68 +5318,7 @@ var SerialJobExecutor = class {
|
|
|
4912
5318
|
createIdGenerator({
|
|
4913
5319
|
prefix: "aiobj",
|
|
4914
5320
|
size: 24
|
|
4915
|
-
}), __export({}, {
|
|
4916
|
-
object: () => object,
|
|
4917
|
-
text: () => text
|
|
4918
5321
|
});
|
|
4919
|
-
var text = () => ({
|
|
4920
|
-
type: "text",
|
|
4921
|
-
responseFormat: { type: "text" },
|
|
4922
|
-
async parsePartial({ text: e18 }) {
|
|
4923
|
-
return { partial: e18 };
|
|
4924
|
-
},
|
|
4925
|
-
async parseOutput({ text: e18 }) {
|
|
4926
|
-
return e18;
|
|
4927
|
-
}
|
|
4928
|
-
}), object = ({ schema: e18 }) => {
|
|
4929
|
-
let v = asSchema(e18);
|
|
4930
|
-
return {
|
|
4931
|
-
type: "object",
|
|
4932
|
-
responseFormat: {
|
|
4933
|
-
type: "json",
|
|
4934
|
-
schema: v.jsonSchema
|
|
4935
|
-
},
|
|
4936
|
-
async parsePartial({ text: e19 }) {
|
|
4937
|
-
let v2 = await parsePartialJson(e19);
|
|
4938
|
-
switch (v2.state) {
|
|
4939
|
-
case "failed-parse":
|
|
4940
|
-
case "undefined-input":
|
|
4941
|
-
return;
|
|
4942
|
-
case "repaired-parse":
|
|
4943
|
-
case "successful-parse":
|
|
4944
|
-
return { partial: v2.value };
|
|
4945
|
-
default: {
|
|
4946
|
-
let e20 = v2.state;
|
|
4947
|
-
throw Error(`Unsupported parse state: ${e20}`);
|
|
4948
|
-
}
|
|
4949
|
-
}
|
|
4950
|
-
},
|
|
4951
|
-
async parseOutput({ text: e19 }, y) {
|
|
4952
|
-
let b = await safeParseJSON({ text: e19 });
|
|
4953
|
-
if (!b.success) throw new NoObjectGeneratedError({
|
|
4954
|
-
message: "No object generated: could not parse the response.",
|
|
4955
|
-
cause: b.error,
|
|
4956
|
-
text: e19,
|
|
4957
|
-
response: y.response,
|
|
4958
|
-
usage: y.usage,
|
|
4959
|
-
finishReason: y.finishReason
|
|
4960
|
-
});
|
|
4961
|
-
let x = await safeValidateTypes({
|
|
4962
|
-
value: b.value,
|
|
4963
|
-
schema: v
|
|
4964
|
-
});
|
|
4965
|
-
if (!x.success) throw new NoObjectGeneratedError({
|
|
4966
|
-
message: "No object generated: response did not match schema.",
|
|
4967
|
-
cause: x.error,
|
|
4968
|
-
text: e19,
|
|
4969
|
-
response: y.response,
|
|
4970
|
-
usage: y.usage,
|
|
4971
|
-
finishReason: y.finishReason
|
|
4972
|
-
});
|
|
4973
|
-
return x.value;
|
|
4974
|
-
}
|
|
4975
|
-
};
|
|
4976
|
-
};
|
|
4977
5322
|
async function convertFileListToFileUIParts(e18) {
|
|
4978
5323
|
if (e18 == null) return [];
|
|
4979
5324
|
if (!globalThis.FileList || !(e18 instanceof globalThis.FileList)) throw Error("FileList is not supported in the current environment");
|
|
@@ -5024,10 +5369,10 @@ var HttpChatTransport = class {
|
|
|
5024
5369
|
messageId: v.messageId
|
|
5025
5370
|
} : C.body, D = (C == null ? void 0 : C.credentials) ?? x, O = await (this.fetch ?? globalThis.fetch)(w, {
|
|
5026
5371
|
method: "POST",
|
|
5027
|
-
headers:
|
|
5372
|
+
headers: {
|
|
5028
5373
|
"Content-Type": "application/json",
|
|
5029
5374
|
...T
|
|
5030
|
-
},
|
|
5375
|
+
},
|
|
5031
5376
|
body: JSON.stringify(E),
|
|
5032
5377
|
credentials: D,
|
|
5033
5378
|
signal: e18
|
|
@@ -5053,7 +5398,7 @@ var HttpChatTransport = class {
|
|
|
5053
5398
|
requestMetadata: e18.metadata
|
|
5054
5399
|
})), C = (S == null ? void 0 : S.api) ?? `${this.api}/${e18.chatId}/stream`, w = (S == null ? void 0 : S.headers) === void 0 ? x : normalizeHeaders(S.headers), T = (S == null ? void 0 : S.credentials) ?? b, E = await (this.fetch ?? globalThis.fetch)(C, {
|
|
5055
5400
|
method: "GET",
|
|
5056
|
-
headers:
|
|
5401
|
+
headers: w,
|
|
5057
5402
|
credentials: T
|
|
5058
5403
|
});
|
|
5059
5404
|
if (E.status === 204) return null;
|
|
@@ -5126,25 +5471,44 @@ var HttpChatTransport = class {
|
|
|
5126
5471
|
});
|
|
5127
5472
|
}, this.clearError = () => {
|
|
5128
5473
|
this.status === "error" && (this.state.error = void 0, this.setStatus({ status: "ready" }));
|
|
5129
|
-
}, this.
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5474
|
+
}, this.addToolApprovalResponse = async ({ id: e19, approved: v2, reason: y2, options: b2 }) => this.jobExecutor.run(async () => {
|
|
5475
|
+
let x2 = this.state.messages, S2 = x2[x2.length - 1], C2 = (b3) => isToolUIPart(b3) && b3.state === "approval-requested" && b3.approval.id === e19 ? {
|
|
5476
|
+
...b3,
|
|
5477
|
+
state: "approval-responded",
|
|
5478
|
+
approval: {
|
|
5479
|
+
id: e19,
|
|
5480
|
+
approved: v2,
|
|
5481
|
+
reason: y2
|
|
5482
|
+
}
|
|
5483
|
+
} : b3;
|
|
5484
|
+
this.state.replaceMessage(x2.length - 1, {
|
|
5133
5485
|
...S2,
|
|
5134
|
-
parts: S2.parts.map(
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
|
|
5140
|
-
|
|
5141
|
-
|
|
5486
|
+
parts: S2.parts.map(C2)
|
|
5487
|
+
}), this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(C2)), this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen && this.shouldSendAutomatically().then((e20) => {
|
|
5488
|
+
var _a;
|
|
5489
|
+
e20 && this.makeRequest({
|
|
5490
|
+
trigger: "submit-message",
|
|
5491
|
+
messageId: (_a = this.lastMessage) == null ? void 0 : _a.id,
|
|
5492
|
+
...b2
|
|
5493
|
+
});
|
|
5494
|
+
});
|
|
5495
|
+
}), this.addToolOutput = async ({ state: e19 = "output-available", toolCallId: v2, output: y2, errorText: b2, options: x2 }) => this.jobExecutor.run(async () => {
|
|
5496
|
+
let S2 = this.state.messages, C2 = S2[S2.length - 1], w2 = (x3) => isToolUIPart(x3) && x3.toolCallId === v2 ? {
|
|
5497
|
+
...x3,
|
|
5142
5498
|
state: e19,
|
|
5143
|
-
output:
|
|
5144
|
-
errorText:
|
|
5145
|
-
} :
|
|
5146
|
-
|
|
5147
|
-
|
|
5499
|
+
output: y2,
|
|
5500
|
+
errorText: b2
|
|
5501
|
+
} : x3;
|
|
5502
|
+
this.state.replaceMessage(S2.length - 1, {
|
|
5503
|
+
...C2,
|
|
5504
|
+
parts: C2.parts.map(w2)
|
|
5505
|
+
}), this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(w2)), this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen && this.shouldSendAutomatically().then((e20) => {
|
|
5506
|
+
var _a;
|
|
5507
|
+
e20 && this.makeRequest({
|
|
5508
|
+
trigger: "submit-message",
|
|
5509
|
+
messageId: (_a = this.lastMessage) == null ? void 0 : _a.id,
|
|
5510
|
+
...x2
|
|
5511
|
+
});
|
|
5148
5512
|
});
|
|
5149
5513
|
}), this.addToolResult = this.addToolOutput, this.stop = async () => {
|
|
5150
5514
|
var _a;
|
|
@@ -5169,39 +5533,49 @@ var HttpChatTransport = class {
|
|
|
5169
5533
|
set messages(e18) {
|
|
5170
5534
|
this.state.messages = e18;
|
|
5171
5535
|
}
|
|
5536
|
+
async shouldSendAutomatically() {
|
|
5537
|
+
if (!this.sendAutomaticallyWhen) return false;
|
|
5538
|
+
let e18 = this.sendAutomaticallyWhen({ messages: this.state.messages });
|
|
5539
|
+
return e18 && typeof e18 == "object" && "then" in e18 ? await e18 : e18;
|
|
5540
|
+
}
|
|
5172
5541
|
async makeRequest({ trigger: e18, metadata: v, headers: y, body: b, messageId: x }) {
|
|
5173
|
-
var _a,
|
|
5542
|
+
var _a, _b;
|
|
5174
5543
|
var S;
|
|
5544
|
+
let C;
|
|
5545
|
+
if (e18 === "resume-stream") try {
|
|
5546
|
+
let e19 = await this.transport.reconnectToStream({
|
|
5547
|
+
chatId: this.id,
|
|
5548
|
+
metadata: v,
|
|
5549
|
+
headers: y,
|
|
5550
|
+
body: b
|
|
5551
|
+
});
|
|
5552
|
+
if (e19 == null) return;
|
|
5553
|
+
C = e19;
|
|
5554
|
+
} catch (e19) {
|
|
5555
|
+
this.onError && e19 instanceof Error && this.onError(e19), this.setStatus({
|
|
5556
|
+
status: "error",
|
|
5557
|
+
error: e19
|
|
5558
|
+
});
|
|
5559
|
+
return;
|
|
5560
|
+
}
|
|
5175
5561
|
this.setStatus({
|
|
5176
5562
|
status: "submitted",
|
|
5177
5563
|
error: void 0
|
|
5178
5564
|
});
|
|
5179
|
-
let
|
|
5565
|
+
let w = this.lastMessage, T = false, E = false, D = false;
|
|
5180
5566
|
try {
|
|
5181
5567
|
let S2 = {
|
|
5182
5568
|
state: createStreamingUIMessageState({
|
|
5183
|
-
lastMessage: this.state.snapshot(
|
|
5569
|
+
lastMessage: this.state.snapshot(w),
|
|
5184
5570
|
messageId: this.generateId()
|
|
5185
5571
|
}),
|
|
5186
5572
|
abortController: new AbortController()
|
|
5187
5573
|
};
|
|
5188
5574
|
S2.abortController.signal.addEventListener("abort", () => {
|
|
5189
|
-
|
|
5575
|
+
T = true;
|
|
5190
5576
|
}), this.activeResponse = S2;
|
|
5191
|
-
let
|
|
5192
|
-
|
|
5193
|
-
let e19 = await this.transport.reconnectToStream({
|
|
5194
|
-
chatId: this.id,
|
|
5195
|
-
metadata: v,
|
|
5196
|
-
headers: y,
|
|
5197
|
-
body: b
|
|
5198
|
-
});
|
|
5199
|
-
if (e19 == null) {
|
|
5200
|
-
this.setStatus({ status: "ready" });
|
|
5201
|
-
return;
|
|
5202
|
-
}
|
|
5203
|
-
T2 = e19;
|
|
5204
|
-
} else T2 = await this.transport.sendMessages({
|
|
5577
|
+
let E2;
|
|
5578
|
+
E2 = e18 === "resume-stream" ? C : await this.transport.sendMessages({
|
|
5205
5579
|
chatId: this.id,
|
|
5206
5580
|
messages: this.state.messages,
|
|
5207
5581
|
abortSignal: S2.abortController.signal,
|
|
@@ -5210,10 +5584,9 @@ var HttpChatTransport = class {
|
|
|
5210
5584
|
body: b,
|
|
5211
5585
|
trigger: e18,
|
|
5212
5586
|
messageId: x
|
|
5213
|
-
})
|
|
5214
|
-
await consumeStream({
|
|
5587
|
+
}), await consumeStream({
|
|
5215
5588
|
stream: processUIMessageStream({
|
|
5216
|
-
stream:
|
|
5589
|
+
stream: E2,
|
|
5217
5590
|
onToolCall: this.onToolCall,
|
|
5218
5591
|
onData: this.onData,
|
|
5219
5592
|
messageMetadataSchema: this.messageMetadataSchema,
|
|
@@ -5234,8 +5607,8 @@ var HttpChatTransport = class {
|
|
|
5234
5607
|
}
|
|
5235
5608
|
}), this.setStatus({ status: "ready" });
|
|
5236
5609
|
} catch (e19) {
|
|
5237
|
-
if (
|
|
5238
|
-
|
|
5610
|
+
if (T || e19.name === "AbortError") return T = true, this.setStatus({ status: "ready" }), null;
|
|
5611
|
+
D = true, e19 instanceof TypeError && (e19.message.toLowerCase().includes("fetch") || e19.message.toLowerCase().includes("network")) && (E = true), this.onError && e19 instanceof Error && this.onError(e19), this.setStatus({
|
|
5239
5612
|
status: "error",
|
|
5240
5613
|
error: e19
|
|
5241
5614
|
});
|
|
@@ -5244,9 +5617,9 @@ var HttpChatTransport = class {
|
|
|
5244
5617
|
(S = this.onFinish) == null || S.call(this, {
|
|
5245
5618
|
message: this.activeResponse.state.message,
|
|
5246
5619
|
messages: this.state.messages,
|
|
5247
|
-
isAbort:
|
|
5248
|
-
isDisconnect:
|
|
5249
|
-
isError:
|
|
5620
|
+
isAbort: T,
|
|
5621
|
+
isDisconnect: E,
|
|
5622
|
+
isError: D,
|
|
5250
5623
|
finishReason: (_a = this.activeResponse) == null ? void 0 : _a.state.finishReason
|
|
5251
5624
|
});
|
|
5252
5625
|
} catch (e19) {
|
|
@@ -5254,9 +5627,9 @@ var HttpChatTransport = class {
|
|
|
5254
5627
|
}
|
|
5255
5628
|
this.activeResponse = void 0;
|
|
5256
5629
|
}
|
|
5257
|
-
|
|
5630
|
+
!D && await this.shouldSendAutomatically() && await this.makeRequest({
|
|
5258
5631
|
trigger: "submit-message",
|
|
5259
|
-
messageId: (
|
|
5632
|
+
messageId: (_b = this.lastMessage) == null ? void 0 : _b.id,
|
|
5260
5633
|
metadata: v,
|
|
5261
5634
|
headers: y,
|
|
5262
5635
|
body: b
|
|
@@ -5344,26 +5717,68 @@ var _state, Chat = class extends AbstractChat {
|
|
|
5344
5717
|
};
|
|
5345
5718
|
_state = /* @__PURE__ */ new WeakMap();
|
|
5346
5719
|
function useChat({ experimental_throttle: e18, resume: v = false, ...y } = {}) {
|
|
5347
|
-
let b = (0, import_react.useRef)("chat" in y ?
|
|
5348
|
-
|
|
5349
|
-
|
|
5350
|
-
|
|
5351
|
-
|
|
5720
|
+
let b = (0, import_react.useRef)("chat" in y ? {} : {
|
|
5721
|
+
onToolCall: y.onToolCall,
|
|
5722
|
+
onData: y.onData,
|
|
5723
|
+
onFinish: y.onFinish,
|
|
5724
|
+
onError: y.onError,
|
|
5725
|
+
sendAutomaticallyWhen: y.sendAutomaticallyWhen
|
|
5726
|
+
});
|
|
5727
|
+
"chat" in y || (b.current = {
|
|
5728
|
+
onToolCall: y.onToolCall,
|
|
5729
|
+
onData: y.onData,
|
|
5730
|
+
onFinish: y.onFinish,
|
|
5731
|
+
onError: y.onError,
|
|
5732
|
+
sendAutomaticallyWhen: y.sendAutomaticallyWhen
|
|
5733
|
+
});
|
|
5734
|
+
let x = {
|
|
5735
|
+
...y,
|
|
5736
|
+
onToolCall: (e19) => {
|
|
5737
|
+
var _a;
|
|
5738
|
+
var v2;
|
|
5739
|
+
return (_a = (v2 = b.current).onToolCall) == null ? void 0 : _a.call(v2, e19);
|
|
5740
|
+
},
|
|
5741
|
+
onData: (e19) => {
|
|
5742
|
+
var _a;
|
|
5743
|
+
var v2;
|
|
5744
|
+
return (_a = (v2 = b.current).onData) == null ? void 0 : _a.call(v2, e19);
|
|
5745
|
+
},
|
|
5746
|
+
onFinish: (e19) => {
|
|
5747
|
+
var _a;
|
|
5748
|
+
var v2;
|
|
5749
|
+
return (_a = (v2 = b.current).onFinish) == null ? void 0 : _a.call(v2, e19);
|
|
5750
|
+
},
|
|
5751
|
+
onError: (e19) => {
|
|
5752
|
+
var _a;
|
|
5753
|
+
var v2;
|
|
5754
|
+
return (_a = (v2 = b.current).onError) == null ? void 0 : _a.call(v2, e19);
|
|
5755
|
+
},
|
|
5756
|
+
sendAutomaticallyWhen: (e19) => {
|
|
5757
|
+
var _a;
|
|
5758
|
+
var v2;
|
|
5759
|
+
return ((_a = (v2 = b.current).sendAutomaticallyWhen) == null ? void 0 : _a.call(v2, e19)) ?? false;
|
|
5760
|
+
}
|
|
5761
|
+
}, S = (0, import_react.useRef)("chat" in y ? y.chat : new Chat(x));
|
|
5762
|
+
("chat" in y && y.chat !== S.current || "id" in y && S.current.id !== y.id) && (S.current = "chat" in y ? y.chat : new Chat(x));
|
|
5763
|
+
let C = (0, import_react.useSyncExternalStore)((0, import_react.useCallback)((v2) => S.current["~registerMessagesCallback"](v2, e18), [e18, S.current.id]), () => S.current.messages, () => S.current.messages), w = (0, import_react.useSyncExternalStore)(S.current["~registerStatusCallback"], () => S.current.status, () => S.current.status), T = (0, import_react.useSyncExternalStore)(S.current["~registerErrorCallback"], () => S.current.error, () => S.current.error), E = (0, import_react.useCallback)((e19) => {
|
|
5764
|
+
typeof e19 == "function" && (e19 = e19(S.current.messages)), S.current.messages = e19;
|
|
5765
|
+
}, [S]);
|
|
5352
5766
|
return (0, import_react.useEffect)(() => {
|
|
5353
|
-
v &&
|
|
5354
|
-
}, [v,
|
|
5355
|
-
id:
|
|
5356
|
-
messages:
|
|
5357
|
-
setMessages:
|
|
5358
|
-
sendMessage:
|
|
5359
|
-
regenerate:
|
|
5360
|
-
clearError:
|
|
5361
|
-
stop:
|
|
5362
|
-
error:
|
|
5363
|
-
resumeStream:
|
|
5364
|
-
status:
|
|
5365
|
-
addToolResult:
|
|
5366
|
-
addToolOutput:
|
|
5767
|
+
v && S.current.resumeStream();
|
|
5768
|
+
}, [v, S]), {
|
|
5769
|
+
id: S.current.id,
|
|
5770
|
+
messages: C,
|
|
5771
|
+
setMessages: E,
|
|
5772
|
+
sendMessage: S.current.sendMessage,
|
|
5773
|
+
regenerate: S.current.regenerate,
|
|
5774
|
+
clearError: S.current.clearError,
|
|
5775
|
+
stop: S.current.stop,
|
|
5776
|
+
error: T,
|
|
5777
|
+
resumeStream: S.current.resumeStream,
|
|
5778
|
+
status: w,
|
|
5779
|
+
addToolResult: S.current.addToolOutput,
|
|
5780
|
+
addToolOutput: S.current.addToolOutput,
|
|
5781
|
+
addToolApprovalResponse: S.current.addToolApprovalResponse
|
|
5367
5782
|
};
|
|
5368
5783
|
}
|
|
5369
5784
|
function isMediaMimetype(e18, v) {
|
|
@@ -5841,8 +6256,8 @@ var DEFAULT_FILE_SEARCH_CONFIG = {
|
|
|
5841
6256
|
return y;
|
|
5842
6257
|
}
|
|
5843
6258
|
getItemMetadata(e18, v) {
|
|
5844
|
-
var _a,
|
|
5845
|
-
let y = (_a = e18.primary_keys) == null ? void 0 : _a.includes(v.name), b = (
|
|
6259
|
+
var _a, _b;
|
|
6260
|
+
let y = (_a = e18.primary_keys) == null ? void 0 : _a.includes(v.name), b = (_b = e18.indexes) == null ? void 0 : _b.includes(v.name);
|
|
5846
6261
|
if (y || b) {
|
|
5847
6262
|
let e19 = document.createElement("span");
|
|
5848
6263
|
e19.textContent = y ? "PK" : "IDX";
|
|
@@ -6224,12 +6639,12 @@ var storageCallbacks = SingleFacet({}), addPromptEffect = StateEffect.define(),
|
|
|
6224
6639
|
};
|
|
6225
6640
|
},
|
|
6226
6641
|
update(e18, v) {
|
|
6227
|
-
var _a,
|
|
6642
|
+
var _a, _b;
|
|
6228
6643
|
let y = { ...e18 };
|
|
6229
6644
|
v.docChanged && e18.navigationIndex !== -1 && (v.effects.some((e19) => e19.is(setNavigationEffect) || e19.is(addPromptEffect)) || (y.navigationIndex = -1, y.originalText = ""));
|
|
6230
6645
|
for (let b of v.effects) if (b.is(addPromptEffect)) {
|
|
6231
6646
|
let x = b.value.trim();
|
|
6232
|
-
x && (y.prompts = [x, ...e18.prompts.filter((e19) => e19 !== x)].slice(0, MAX_PROMPTS), (
|
|
6647
|
+
x && (y.prompts = [x, ...e18.prompts.filter((e19) => e19 !== x)].slice(0, MAX_PROMPTS), (_b = (_a = v.state.facet(storageCallbacks)).save) == null ? void 0 : _b.call(_a, y.prompts)), y.navigationIndex = -1, y.originalText = "";
|
|
6233
6648
|
} else b.is(setNavigationEffect) && (y.navigationIndex = b.value.index, y.originalText = b.value.originalText);
|
|
6234
6649
|
return y;
|
|
6235
6650
|
}
|
|
@@ -6651,7 +7066,7 @@ function asDom(e18) {
|
|
|
6651
7066
|
}
|
|
6652
7067
|
var import_compiler_runtime$1 = require_compiler_runtime();
|
|
6653
7068
|
atomWithStorage("marimo:ai-language", "python", jotaiJsonStorage);
|
|
6654
|
-
var KEY = "marimo:ai-prompt-history", promptHistoryStorage = new ZodLocalStorage(array(string()), () => []);
|
|
7069
|
+
var KEY = "marimo:ai-prompt-history", promptHistoryStorage = new ZodLocalStorage(array$1(string()), () => []);
|
|
6655
7070
|
const PromptInput = (e18) => {
|
|
6656
7071
|
let v = (0, import_compiler_runtime$1.c)(35), { value: y, placeholder: b, inputRef: x, className: S, onChange: C, onSubmit: w, onKeyDown: T, onClose: E, onAddFiles: D, additionalCompletions: O, maxHeight: k } = e18, A = w, j = E, M = useStore(), { theme: N } = useTheme(), P;
|
|
6657
7072
|
v[0] === O ? P = v[1] : (P = (e19) => O ? mentionsCompletionSource([O.triggerCompletionRegex], O.completions)(e19) : null, v[0] = O, v[1] = P);
|