@mastra/memory 1.23.0-alpha.2 → 1.23.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/{chunk-2ZR7CKDV.cjs → chunk-42LZUXJ3.cjs} +1985 -1149
- package/dist/chunk-42LZUXJ3.cjs.map +1 -0
- package/dist/{chunk-GHFCSEEP.js → chunk-6ACCFKAN.js} +1985 -1149
- package/dist/chunk-6ACCFKAN.js.map +1 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +57 -57
- package/dist/docs/references/docs-agents-supervisor-agents.md +1 -3
- package/dist/docs/references/docs-evals-evals-with-memory.md +1 -3
- package/dist/docs/references/docs-long-running-agents-background-tasks.md +1 -1
- package/dist/docs/references/docs-long-running-agents-goals.md +1 -3
- package/dist/docs/references/docs-memory-overview.md +4 -4
- package/dist/index.cjs +15 -15
- package/dist/index.js +1 -1
- package/dist/{observational-memory-RJL2PW6O.cjs → observational-memory-2F4GJOP2.cjs} +29 -29
- package/dist/{observational-memory-RJL2PW6O.cjs.map → observational-memory-2F4GJOP2.cjs.map} +1 -1
- package/dist/{observational-memory-HUPMKPOX.js → observational-memory-OJN26RQ4.js} +3 -3
- package/dist/{observational-memory-HUPMKPOX.js.map → observational-memory-OJN26RQ4.js.map} +1 -1
- package/dist/processors/index.cjs +27 -27
- package/dist/processors/index.js +1 -1
- package/dist/processors/observational-memory/observation-turn/step.d.ts +13 -0
- package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
- package/dist/processors/observational-memory/observation-turn/turn.d.ts +25 -0
- package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
- package/dist/processors/observational-memory/processor.d.ts.map +1 -1
- package/package.json +9 -9
- package/dist/chunk-2ZR7CKDV.cjs.map +0 -1
- package/dist/chunk-GHFCSEEP.js.map +0 -1
|
@@ -275,10 +275,10 @@ var BUILT_IN_EXTRACTOR_SLUGS = [...BUILT_IN_SLUGS];
|
|
|
275
275
|
function isBuiltInExtractorSlug(slug) {
|
|
276
276
|
return BUILT_IN_SLUGS.has(slug);
|
|
277
277
|
}
|
|
278
|
-
function slugifyExtractorName(
|
|
278
|
+
function slugifyExtractorName(name28) {
|
|
279
279
|
let normalized = "";
|
|
280
280
|
let previousWasSeparator = false;
|
|
281
|
-
for (const char of
|
|
281
|
+
for (const char of name28.trim().toLowerCase()) {
|
|
282
282
|
const code = char.charCodeAt(0);
|
|
283
283
|
const isLetter = code >= 97 && code <= 122;
|
|
284
284
|
const isNumber = code >= 48 && code <= 57;
|
|
@@ -297,9 +297,9 @@ function slugifyExtractorName(name21) {
|
|
|
297
297
|
}
|
|
298
298
|
return normalized.endsWith("-") ? normalized.slice(0, -1) : normalized;
|
|
299
299
|
}
|
|
300
|
-
function assertValidSlug(slug,
|
|
300
|
+
function assertValidSlug(slug, name28) {
|
|
301
301
|
if (!slug) {
|
|
302
|
-
throw new Error(`Extractor name "${
|
|
302
|
+
throw new Error(`Extractor name "${name28}" must produce a non-empty slug.`);
|
|
303
303
|
}
|
|
304
304
|
const first = slug.charCodeAt(0);
|
|
305
305
|
const last = slug.charCodeAt(slug.length - 1);
|
|
@@ -310,7 +310,7 @@ function assertValidSlug(slug, name21) {
|
|
|
310
310
|
return code >= 97 && code <= 122 || code >= 48 && code <= 57 || char === "-";
|
|
311
311
|
});
|
|
312
312
|
if (!startsWithLetter || !endsWithLetterOrNumber || !hasOnlySlugCharacters) {
|
|
313
|
-
throw new Error(`Extractor name "${
|
|
313
|
+
throw new Error(`Extractor name "${name28}" produced invalid slug "${slug}".`);
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
var Extractor = class _Extractor {
|
|
@@ -327,20 +327,20 @@ var Extractor = class _Extractor {
|
|
|
327
327
|
instructionsConfig;
|
|
328
328
|
schemaConfig;
|
|
329
329
|
constructor(config, internal = false) {
|
|
330
|
-
const
|
|
330
|
+
const name28 = config.name.trim();
|
|
331
331
|
const instructions = typeof config.instructions === "string" ? config.instructions.trim() : void 0;
|
|
332
|
-
const slug = slugifyExtractorName(
|
|
333
|
-
if (!
|
|
332
|
+
const slug = slugifyExtractorName(name28);
|
|
333
|
+
if (!name28) {
|
|
334
334
|
throw new Error("Extractor name is required.");
|
|
335
335
|
}
|
|
336
336
|
if (instructions !== void 0 && !instructions) {
|
|
337
|
-
throw new Error(`Extractor "${
|
|
337
|
+
throw new Error(`Extractor "${name28}" must include instructions.`);
|
|
338
338
|
}
|
|
339
|
-
assertValidSlug(slug,
|
|
339
|
+
assertValidSlug(slug, name28);
|
|
340
340
|
if (!internal && RESERVED_XML_TAGS.has(slug)) {
|
|
341
341
|
throw new Error(`Extractor slug "${slug}" is reserved by Observational Memory.`);
|
|
342
342
|
}
|
|
343
|
-
this.name =
|
|
343
|
+
this.name = name28;
|
|
344
344
|
this.slug = slug;
|
|
345
345
|
this.instructionsConfig = config.instructions;
|
|
346
346
|
this.schemaConfig = config.schema;
|
|
@@ -1697,13 +1697,13 @@ var ObservationStrategy = class _ObservationStrategy {
|
|
|
1697
1697
|
generateCycleId() {
|
|
1698
1698
|
return crypto.randomUUID();
|
|
1699
1699
|
}
|
|
1700
|
-
async streamMarker(
|
|
1700
|
+
async streamMarker(marker28) {
|
|
1701
1701
|
if (this.opts.writer) {
|
|
1702
|
-
await this.opts.writer.custom({ ...
|
|
1702
|
+
await this.opts.writer.custom({ ...marker28, transient: true }).catch(() => {
|
|
1703
1703
|
});
|
|
1704
1704
|
}
|
|
1705
|
-
const markerThreadId =
|
|
1706
|
-
await this.persistMarkerToStorage(
|
|
1705
|
+
const markerThreadId = marker28.data?.threadId ?? this.opts.threadId;
|
|
1706
|
+
await this.persistMarkerToStorage(marker28, markerThreadId, this.opts.resourceId);
|
|
1707
1707
|
}
|
|
1708
1708
|
getObservationMarkerConfig() {
|
|
1709
1709
|
return {
|
|
@@ -1841,7 +1841,7 @@ ${threadClose}`;
|
|
|
1841
1841
|
* Fetches messages directly from the DB so it works even when
|
|
1842
1842
|
* no MessageList is available (e.g. async buffering ops).
|
|
1843
1843
|
*/
|
|
1844
|
-
async persistMarkerToStorage(
|
|
1844
|
+
async persistMarkerToStorage(marker28, threadId, resourceId) {
|
|
1845
1845
|
try {
|
|
1846
1846
|
const result = await this.storage.listMessages({
|
|
1847
1847
|
threadId,
|
|
@@ -1851,10 +1851,10 @@ ${threadClose}`;
|
|
|
1851
1851
|
const messages = result?.messages ?? [];
|
|
1852
1852
|
for (const msg of messages) {
|
|
1853
1853
|
if (msg?.role === "assistant" && msg.content?.parts && Array.isArray(msg.content.parts)) {
|
|
1854
|
-
const markerData =
|
|
1855
|
-
const alreadyPresent = markerData?.cycleId && msg.content.parts.some((p) => p?.type ===
|
|
1854
|
+
const markerData = marker28.data;
|
|
1855
|
+
const alreadyPresent = markerData?.cycleId && msg.content.parts.some((p) => p?.type === marker28.type && p?.data?.cycleId === markerData.cycleId);
|
|
1856
1856
|
if (!alreadyPresent) {
|
|
1857
|
-
msg.content.parts.push(
|
|
1857
|
+
msg.content.parts.push(marker28);
|
|
1858
1858
|
}
|
|
1859
1859
|
await this.messageHistory.persistMessages({
|
|
1860
1860
|
messages: [msg],
|
|
@@ -1872,16 +1872,16 @@ ${threadClose}`;
|
|
|
1872
1872
|
* Persist a marker part on the last assistant message in a MessageList
|
|
1873
1873
|
* AND save the updated message to the DB.
|
|
1874
1874
|
*/
|
|
1875
|
-
async persistMarkerToMessage(
|
|
1875
|
+
async persistMarkerToMessage(marker28, messageList, threadId, resourceId) {
|
|
1876
1876
|
if (!messageList) return;
|
|
1877
1877
|
const allMsgs = messageList.get.all.db();
|
|
1878
1878
|
for (let i = allMsgs.length - 1; i >= 0; i--) {
|
|
1879
1879
|
const msg = allMsgs[i];
|
|
1880
1880
|
if (msg?.role === "assistant" && msg.content?.parts && Array.isArray(msg.content.parts)) {
|
|
1881
|
-
const markerData =
|
|
1882
|
-
const alreadyPresent = markerData?.cycleId && msg.content.parts.some((p) => p?.type ===
|
|
1881
|
+
const markerData = marker28.data;
|
|
1882
|
+
const alreadyPresent = markerData?.cycleId && msg.content.parts.some((p) => p?.type === marker28.type && p?.data?.cycleId === markerData.cycleId);
|
|
1883
1883
|
if (!alreadyPresent) {
|
|
1884
|
-
msg.content.parts.push(
|
|
1884
|
+
msg.content.parts.push(marker28);
|
|
1885
1885
|
}
|
|
1886
1886
|
try {
|
|
1887
1887
|
await this.messageHistory.persistMessages({
|
|
@@ -2275,13 +2275,13 @@ var AsyncBufferObservationStrategy = class extends ObservationStrategy {
|
|
|
2275
2275
|
metadata: newMetadata
|
|
2276
2276
|
});
|
|
2277
2277
|
if (shouldUpdateThreadTitle) {
|
|
2278
|
-
const
|
|
2278
|
+
const marker28 = createThreadUpdateMarker({
|
|
2279
2279
|
cycleId: this.cycleId,
|
|
2280
2280
|
threadId,
|
|
2281
2281
|
oldTitle,
|
|
2282
2282
|
newTitle
|
|
2283
2283
|
});
|
|
2284
|
-
await this.streamMarker(
|
|
2284
|
+
await this.streamMarker(marker28);
|
|
2285
2285
|
}
|
|
2286
2286
|
}
|
|
2287
2287
|
}
|
|
@@ -2665,8 +2665,8 @@ var ResourceScopedObservationStrategy = class extends ObservationStrategy {
|
|
|
2665
2665
|
}
|
|
2666
2666
|
}
|
|
2667
2667
|
}
|
|
2668
|
-
for (const
|
|
2669
|
-
await this.streamMarker(
|
|
2668
|
+
for (const marker28 of threadUpdateMarkers) {
|
|
2669
|
+
await this.streamMarker(marker28);
|
|
2670
2670
|
}
|
|
2671
2671
|
await this.storage.updateActiveObservations({
|
|
2672
2672
|
id: record.id,
|
|
@@ -2783,6 +2783,18 @@ var ObservationStep = class {
|
|
|
2783
2783
|
get prepared() {
|
|
2784
2784
|
return this._prepared;
|
|
2785
2785
|
}
|
|
2786
|
+
/**
|
|
2787
|
+
* Serialize to a minimal, acyclic snapshot.
|
|
2788
|
+
*
|
|
2789
|
+
* The `turn` back-reference exists only so a step can read context off its parent turn at
|
|
2790
|
+
* runtime. It closes the `ObservationTurn._currentStep -> ObservationStep.turn` cycle, so
|
|
2791
|
+
* serializing it throws "Converting circular structure to JSON" (e.g. when a turn is stashed
|
|
2792
|
+
* in processor state that flows into a processor-workflow snapshot). The parent turn fully
|
|
2793
|
+
* owns the step, so omitting the back-reference is lossless.
|
|
2794
|
+
*/
|
|
2795
|
+
toJSON() {
|
|
2796
|
+
return { stepNumber: this.stepNumber, prepared: this._prepared };
|
|
2797
|
+
}
|
|
2786
2798
|
/** Step context from prepare(). Throws if prepare() hasn't been called. */
|
|
2787
2799
|
get context() {
|
|
2788
2800
|
if (!this._context) throw new Error("Step not prepared yet \u2014 call prepare() first");
|
|
@@ -3246,6 +3258,33 @@ var ObservationTurn = class {
|
|
|
3246
3258
|
}
|
|
3247
3259
|
return this._context?.otherThreadsContext;
|
|
3248
3260
|
}
|
|
3261
|
+
/**
|
|
3262
|
+
* Serialize to a minimal, acyclic snapshot of the turn's identity and lifecycle.
|
|
3263
|
+
*
|
|
3264
|
+
* `ObservationTurn` is a request-scoped runtime orchestration object: it holds live
|
|
3265
|
+
* references (the `ObservationalMemory` engine, the `MessageList`, the stream writer, the
|
|
3266
|
+
* memory provider, lifecycle hooks) and a back-reference to its current `ObservationStep`,
|
|
3267
|
+
* which points back at the turn — a cycle. None of that is persistable state. The turn is
|
|
3268
|
+
* stashed in the shared processor-state map (`state.__omTurn`) only so the input and output
|
|
3269
|
+
* OM processor instances can reach the *live* object within a single request; that map is
|
|
3270
|
+
* also threaded into processor workflows, whose snapshots the storage layer serializes with
|
|
3271
|
+
* `JSON.stringify`. Without this projection, that serialization throws "Converting circular
|
|
3272
|
+
* structure to JSON" via `_currentStep` <-> `turn`.
|
|
3273
|
+
*
|
|
3274
|
+
* The projection is lossless: the dropped fields are live runtime objects that cannot and
|
|
3275
|
+
* should not round-trip through storage, and OM never reads the turn back from a snapshot —
|
|
3276
|
+
* it always reads the live `__omTurn` from the in-memory map and re-establishes a fresh turn
|
|
3277
|
+
* when a deserialized `MessageList` no longer matches (see the processor's turn handling).
|
|
3278
|
+
*/
|
|
3279
|
+
toJSON() {
|
|
3280
|
+
return {
|
|
3281
|
+
threadId: this.threadId,
|
|
3282
|
+
resourceId: this.resourceId,
|
|
3283
|
+
started: this._started,
|
|
3284
|
+
ended: this._ended,
|
|
3285
|
+
currentStepNumber: this._currentStep?.stepNumber
|
|
3286
|
+
};
|
|
3287
|
+
}
|
|
3249
3288
|
};
|
|
3250
3289
|
|
|
3251
3290
|
// src/processors/observational-memory/anchor-ids.ts
|
|
@@ -4821,7 +4860,7 @@ async function withRetry(fn, opts) {
|
|
|
4821
4860
|
}
|
|
4822
4861
|
}
|
|
4823
4862
|
|
|
4824
|
-
// ../_vendored/ai_v4/dist/chunk-
|
|
4863
|
+
// ../_vendored/ai_v4/dist/chunk-SJKFJOR6.js
|
|
4825
4864
|
var __create = Object.create;
|
|
4826
4865
|
var __defProp = Object.defineProperty;
|
|
4827
4866
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7329,15 +7368,15 @@ var DiagAPI = (
|
|
|
7329
7368
|
return logger[funcName].apply(logger, __spreadArray2([], __read2(args), false));
|
|
7330
7369
|
};
|
|
7331
7370
|
}
|
|
7332
|
-
var
|
|
7371
|
+
var self2 = this;
|
|
7333
7372
|
var setLogger = function(logger, optionsOrLogLevel) {
|
|
7334
7373
|
var _a173, _b19, _c;
|
|
7335
7374
|
if (optionsOrLogLevel === void 0) {
|
|
7336
7375
|
optionsOrLogLevel = { logLevel: DiagLogLevel.INFO };
|
|
7337
7376
|
}
|
|
7338
|
-
if (logger ===
|
|
7377
|
+
if (logger === self2) {
|
|
7339
7378
|
var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
|
|
7340
|
-
|
|
7379
|
+
self2.error((_a173 = err.stack) !== null && _a173 !== void 0 ? _a173 : err.message);
|
|
7341
7380
|
return false;
|
|
7342
7381
|
}
|
|
7343
7382
|
if (typeof optionsOrLogLevel === "number") {
|
|
@@ -7352,20 +7391,20 @@ var DiagAPI = (
|
|
|
7352
7391
|
oldLogger.warn("Current logger will be overwritten from " + stack);
|
|
7353
7392
|
newLogger.warn("Current logger will overwrite one already registered from " + stack);
|
|
7354
7393
|
}
|
|
7355
|
-
return registerGlobal("diag", newLogger,
|
|
7394
|
+
return registerGlobal("diag", newLogger, self2, true);
|
|
7356
7395
|
};
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
unregisterGlobal(API_NAME,
|
|
7396
|
+
self2.setLogger = setLogger;
|
|
7397
|
+
self2.disable = function() {
|
|
7398
|
+
unregisterGlobal(API_NAME, self2);
|
|
7360
7399
|
};
|
|
7361
|
-
|
|
7400
|
+
self2.createComponentLogger = function(options) {
|
|
7362
7401
|
return new DiagComponentLogger(options);
|
|
7363
7402
|
};
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7403
|
+
self2.verbose = _logProxy("verbose");
|
|
7404
|
+
self2.debug = _logProxy("debug");
|
|
7405
|
+
self2.info = _logProxy("info");
|
|
7406
|
+
self2.warn = _logProxy("warn");
|
|
7407
|
+
self2.error = _logProxy("error");
|
|
7369
7408
|
}
|
|
7370
7409
|
DiagAPI22.instance = function() {
|
|
7371
7410
|
if (!this._instance) {
|
|
@@ -7383,18 +7422,18 @@ var BaseContext = (
|
|
|
7383
7422
|
/** @class */
|
|
7384
7423
|
/* @__PURE__ */ (function() {
|
|
7385
7424
|
function BaseContext22(parentContext) {
|
|
7386
|
-
var
|
|
7387
|
-
|
|
7388
|
-
|
|
7389
|
-
return
|
|
7425
|
+
var self2 = this;
|
|
7426
|
+
self2._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
|
|
7427
|
+
self2.getValue = function(key) {
|
|
7428
|
+
return self2._currentContext.get(key);
|
|
7390
7429
|
};
|
|
7391
|
-
|
|
7392
|
-
var context2 = new BaseContext22(
|
|
7430
|
+
self2.setValue = function(key, value) {
|
|
7431
|
+
var context2 = new BaseContext22(self2._currentContext);
|
|
7393
7432
|
context2._currentContext.set(key, value);
|
|
7394
7433
|
return context2;
|
|
7395
7434
|
};
|
|
7396
|
-
|
|
7397
|
-
var context2 = new BaseContext22(
|
|
7435
|
+
self2.deleteValue = function(key) {
|
|
7436
|
+
var context2 = new BaseContext22(self2._currentContext);
|
|
7398
7437
|
context2._currentContext.delete(key);
|
|
7399
7438
|
return context2;
|
|
7400
7439
|
};
|
|
@@ -9315,6 +9354,90 @@ function createAbortError() {
|
|
|
9315
9354
|
function extractResponseHeaders(response) {
|
|
9316
9355
|
return Object.fromEntries([...response.headers]);
|
|
9317
9356
|
}
|
|
9357
|
+
var name142 = "AI_DownloadError";
|
|
9358
|
+
var marker152 = `vercel.ai.error.${name142}`;
|
|
9359
|
+
var symbol152 = Symbol.for(marker152);
|
|
9360
|
+
var _a152;
|
|
9361
|
+
var _b15;
|
|
9362
|
+
var DownloadError = class extends (_b15 = AISDKError2, _a152 = symbol152, _b15) {
|
|
9363
|
+
constructor({
|
|
9364
|
+
url,
|
|
9365
|
+
statusCode,
|
|
9366
|
+
statusText,
|
|
9367
|
+
cause,
|
|
9368
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
9369
|
+
}) {
|
|
9370
|
+
super({ name: name142, message, cause });
|
|
9371
|
+
this[_a152] = true;
|
|
9372
|
+
this.url = url;
|
|
9373
|
+
this.statusCode = statusCode;
|
|
9374
|
+
this.statusText = statusText;
|
|
9375
|
+
}
|
|
9376
|
+
static isInstance(error) {
|
|
9377
|
+
return AISDKError2.hasMarker(error, marker152);
|
|
9378
|
+
}
|
|
9379
|
+
};
|
|
9380
|
+
async function cancelResponseBody(response) {
|
|
9381
|
+
var _a223;
|
|
9382
|
+
try {
|
|
9383
|
+
await ((_a223 = response.body) == null ? void 0 : _a223.cancel());
|
|
9384
|
+
} catch (e) {
|
|
9385
|
+
}
|
|
9386
|
+
}
|
|
9387
|
+
var DEFAULT_MAX_DOWNLOAD_SIZE = 2 * 1024 * 1024 * 1024;
|
|
9388
|
+
async function readResponseWithSizeLimit({
|
|
9389
|
+
response,
|
|
9390
|
+
url,
|
|
9391
|
+
maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE
|
|
9392
|
+
}) {
|
|
9393
|
+
const contentLength = response.headers.get("content-length");
|
|
9394
|
+
if (contentLength != null) {
|
|
9395
|
+
const length = parseInt(contentLength, 10);
|
|
9396
|
+
if (!isNaN(length) && length > maxBytes) {
|
|
9397
|
+
await cancelResponseBody(response);
|
|
9398
|
+
throw new DownloadError({
|
|
9399
|
+
url,
|
|
9400
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
|
|
9401
|
+
});
|
|
9402
|
+
}
|
|
9403
|
+
}
|
|
9404
|
+
const body = response.body;
|
|
9405
|
+
if (body == null) {
|
|
9406
|
+
return new Uint8Array(0);
|
|
9407
|
+
}
|
|
9408
|
+
const reader = body.getReader();
|
|
9409
|
+
const chunks = [];
|
|
9410
|
+
let totalBytes = 0;
|
|
9411
|
+
try {
|
|
9412
|
+
while (true) {
|
|
9413
|
+
const { done, value } = await reader.read();
|
|
9414
|
+
if (done) {
|
|
9415
|
+
break;
|
|
9416
|
+
}
|
|
9417
|
+
totalBytes += value.length;
|
|
9418
|
+
if (totalBytes > maxBytes) {
|
|
9419
|
+
throw new DownloadError({
|
|
9420
|
+
url,
|
|
9421
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
9422
|
+
});
|
|
9423
|
+
}
|
|
9424
|
+
chunks.push(value);
|
|
9425
|
+
}
|
|
9426
|
+
} finally {
|
|
9427
|
+
try {
|
|
9428
|
+
await reader.cancel();
|
|
9429
|
+
} finally {
|
|
9430
|
+
reader.releaseLock();
|
|
9431
|
+
}
|
|
9432
|
+
}
|
|
9433
|
+
const result = new Uint8Array(totalBytes);
|
|
9434
|
+
let offset = 0;
|
|
9435
|
+
for (const chunk of chunks) {
|
|
9436
|
+
result.set(chunk, offset);
|
|
9437
|
+
offset += chunk.length;
|
|
9438
|
+
}
|
|
9439
|
+
return result;
|
|
9440
|
+
}
|
|
9318
9441
|
var createIdGenerator2 = ({
|
|
9319
9442
|
prefix,
|
|
9320
9443
|
size = 16,
|
|
@@ -9382,11 +9505,11 @@ function handleFetchError({
|
|
|
9382
9505
|
return error;
|
|
9383
9506
|
}
|
|
9384
9507
|
function getRuntimeEnvironmentUserAgent(globalThisAny = globalThis) {
|
|
9385
|
-
var
|
|
9508
|
+
var _a223, _b222, _c;
|
|
9386
9509
|
if (globalThisAny.window) {
|
|
9387
9510
|
return `runtime/browser`;
|
|
9388
9511
|
}
|
|
9389
|
-
if ((
|
|
9512
|
+
if ((_a223 = globalThisAny.navigator) == null ? void 0 : _a223.userAgent) {
|
|
9390
9513
|
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
9391
9514
|
}
|
|
9392
9515
|
if ((_c = (_b222 = globalThisAny.process) == null ? void 0 : _b222.versions) == null ? void 0 : _c.node) {
|
|
@@ -9427,7 +9550,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
9427
9550
|
);
|
|
9428
9551
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
9429
9552
|
}
|
|
9430
|
-
var VERSION2 = "3.0.
|
|
9553
|
+
var VERSION2 = "3.0.28";
|
|
9431
9554
|
var getOriginalFetch = () => globalThis.fetch;
|
|
9432
9555
|
var getFromApi = async ({
|
|
9433
9556
|
url,
|
|
@@ -9774,7 +9897,7 @@ function tool(tool22) {
|
|
|
9774
9897
|
}
|
|
9775
9898
|
function createProviderDefinedToolFactoryWithOutputSchema({
|
|
9776
9899
|
id,
|
|
9777
|
-
name:
|
|
9900
|
+
name: name223,
|
|
9778
9901
|
inputSchema,
|
|
9779
9902
|
outputSchema: outputSchema3
|
|
9780
9903
|
}) {
|
|
@@ -9788,7 +9911,7 @@ function createProviderDefinedToolFactoryWithOutputSchema({
|
|
|
9788
9911
|
}) => tool({
|
|
9789
9912
|
type: "provider-defined",
|
|
9790
9913
|
id,
|
|
9791
|
-
name:
|
|
9914
|
+
name: name223,
|
|
9792
9915
|
args,
|
|
9793
9916
|
inputSchema,
|
|
9794
9917
|
outputSchema: outputSchema3,
|
|
@@ -9805,12 +9928,24 @@ async function resolve(value) {
|
|
|
9805
9928
|
}
|
|
9806
9929
|
return Promise.resolve(value);
|
|
9807
9930
|
}
|
|
9931
|
+
var textDecoder = new TextDecoder();
|
|
9932
|
+
async function readResponseBodyAsText({
|
|
9933
|
+
response,
|
|
9934
|
+
url
|
|
9935
|
+
}) {
|
|
9936
|
+
return textDecoder.decode(
|
|
9937
|
+
await readResponseWithSizeLimit({
|
|
9938
|
+
response,
|
|
9939
|
+
url
|
|
9940
|
+
})
|
|
9941
|
+
);
|
|
9942
|
+
}
|
|
9808
9943
|
var createJsonErrorResponseHandler = ({
|
|
9809
9944
|
errorSchema,
|
|
9810
9945
|
errorToMessage,
|
|
9811
9946
|
isRetryable
|
|
9812
9947
|
}) => async ({ response, url, requestBodyValues }) => {
|
|
9813
|
-
const responseBody = await response
|
|
9948
|
+
const responseBody = await readResponseBodyAsText({ response, url });
|
|
9814
9949
|
const responseHeaders = extractResponseHeaders(response);
|
|
9815
9950
|
if (responseBody.trim() === "") {
|
|
9816
9951
|
return {
|
|
@@ -9873,7 +10008,7 @@ var createEventSourceResponseHandler = (chunkSchema) => async ({ response }) =>
|
|
|
9873
10008
|
};
|
|
9874
10009
|
};
|
|
9875
10010
|
var createJsonResponseHandler = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
9876
|
-
const responseBody = await response
|
|
10011
|
+
const responseBody = await readResponseBodyAsText({ response, url });
|
|
9877
10012
|
const parsedResult = await safeParseJSON2({
|
|
9878
10013
|
text: responseBody,
|
|
9879
10014
|
schema: responseSchema
|
|
@@ -9983,11 +10118,11 @@ function parseAnyDef2() {
|
|
|
9983
10118
|
return {};
|
|
9984
10119
|
}
|
|
9985
10120
|
function parseArrayDef2(def, refs) {
|
|
9986
|
-
var
|
|
10121
|
+
var _a223, _b222, _c;
|
|
9987
10122
|
const res = {
|
|
9988
10123
|
type: "array"
|
|
9989
10124
|
};
|
|
9990
|
-
if (((
|
|
10125
|
+
if (((_a223 = def.type) == null ? void 0 : _a223._def) && ((_c = (_b222 = def.type) == null ? void 0 : _b222._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
|
|
9991
10126
|
res.items = parseDef2(def.type._def, {
|
|
9992
10127
|
...refs,
|
|
9993
10128
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -10346,8 +10481,8 @@ function escapeNonAlphaNumeric2(source) {
|
|
|
10346
10481
|
return result;
|
|
10347
10482
|
}
|
|
10348
10483
|
function addFormat2(schema, value, message, refs) {
|
|
10349
|
-
var
|
|
10350
|
-
if (schema.format || ((
|
|
10484
|
+
var _a223;
|
|
10485
|
+
if (schema.format || ((_a223 = schema.anyOf) == null ? void 0 : _a223.some((x) => x.format))) {
|
|
10351
10486
|
if (!schema.anyOf) {
|
|
10352
10487
|
schema.anyOf = [];
|
|
10353
10488
|
}
|
|
@@ -10366,8 +10501,8 @@ function addFormat2(schema, value, message, refs) {
|
|
|
10366
10501
|
}
|
|
10367
10502
|
}
|
|
10368
10503
|
function addPattern2(schema, regex, message, refs) {
|
|
10369
|
-
var
|
|
10370
|
-
if (schema.pattern || ((
|
|
10504
|
+
var _a223;
|
|
10505
|
+
if (schema.pattern || ((_a223 = schema.allOf) == null ? void 0 : _a223.some((x) => x.pattern))) {
|
|
10371
10506
|
if (!schema.allOf) {
|
|
10372
10507
|
schema.allOf = [];
|
|
10373
10508
|
}
|
|
@@ -10386,7 +10521,7 @@ function addPattern2(schema, regex, message, refs) {
|
|
|
10386
10521
|
}
|
|
10387
10522
|
}
|
|
10388
10523
|
function stringifyRegExpWithFlags2(regex, refs) {
|
|
10389
|
-
var
|
|
10524
|
+
var _a223;
|
|
10390
10525
|
if (!refs.applyRegexFlags || !regex.flags) {
|
|
10391
10526
|
return regex.source;
|
|
10392
10527
|
}
|
|
@@ -10416,7 +10551,7 @@ function stringifyRegExpWithFlags2(regex, refs) {
|
|
|
10416
10551
|
pattern += source[i];
|
|
10417
10552
|
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
10418
10553
|
inCharRange = false;
|
|
10419
|
-
} else if (source[i + 1] === "-" && ((
|
|
10554
|
+
} else if (source[i + 1] === "-" && ((_a223 = source[i + 2]) == null ? void 0 : _a223.match(/[a-z]/))) {
|
|
10420
10555
|
pattern += source[i];
|
|
10421
10556
|
inCharRange = true;
|
|
10422
10557
|
} else {
|
|
@@ -10458,13 +10593,13 @@ function stringifyRegExpWithFlags2(regex, refs) {
|
|
|
10458
10593
|
return pattern;
|
|
10459
10594
|
}
|
|
10460
10595
|
function parseRecordDef2(def, refs) {
|
|
10461
|
-
var
|
|
10596
|
+
var _a223, _b222, _c, _d, _e, _f;
|
|
10462
10597
|
const schema = {
|
|
10463
10598
|
type: "object",
|
|
10464
|
-
additionalProperties: (
|
|
10599
|
+
additionalProperties: (_a223 = parseDef2(def.valueType._def, {
|
|
10465
10600
|
...refs,
|
|
10466
10601
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
10467
|
-
})) != null ?
|
|
10602
|
+
})) != null ? _a223 : refs.allowedAdditionalProperties
|
|
10468
10603
|
};
|
|
10469
10604
|
if (((_b222 = def.keyType) == null ? void 0 : _b222._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
10470
10605
|
const { type, ...keyType } = parseStringDef2(def.keyType._def, refs);
|
|
@@ -10721,8 +10856,8 @@ function safeIsOptional2(schema) {
|
|
|
10721
10856
|
}
|
|
10722
10857
|
}
|
|
10723
10858
|
var parseOptionalDef2 = (def, refs) => {
|
|
10724
|
-
var
|
|
10725
|
-
if (refs.currentPath.toString() === ((
|
|
10859
|
+
var _a223;
|
|
10860
|
+
if (refs.currentPath.toString() === ((_a223 = refs.propertyPath) == null ? void 0 : _a223.toString())) {
|
|
10726
10861
|
return parseDef2(def.innerType._def, refs);
|
|
10727
10862
|
}
|
|
10728
10863
|
const innerSchema = parseDef2(def.innerType._def, {
|
|
@@ -10899,10 +11034,10 @@ var getRelativePath2 = (pathA, pathB) => {
|
|
|
10899
11034
|
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
10900
11035
|
};
|
|
10901
11036
|
function parseDef2(def, refs, forceResolution = false) {
|
|
10902
|
-
var
|
|
11037
|
+
var _a223;
|
|
10903
11038
|
const seenItem = refs.seen.get(def);
|
|
10904
11039
|
if (refs.override) {
|
|
10905
|
-
const overrideResult = (
|
|
11040
|
+
const overrideResult = (_a223 = refs.override) == null ? void 0 : _a223.call(
|
|
10906
11041
|
refs,
|
|
10907
11042
|
def,
|
|
10908
11043
|
refs,
|
|
@@ -10968,11 +11103,11 @@ var getRefs2 = (options) => {
|
|
|
10968
11103
|
currentPath,
|
|
10969
11104
|
propertyPath: void 0,
|
|
10970
11105
|
seen: new Map(
|
|
10971
|
-
Object.entries(_options.definitions).map(([
|
|
11106
|
+
Object.entries(_options.definitions).map(([name223, def]) => [
|
|
10972
11107
|
def._def,
|
|
10973
11108
|
{
|
|
10974
11109
|
def: def._def,
|
|
10975
|
-
path: [..._options.basePath, _options.definitionPath,
|
|
11110
|
+
path: [..._options.basePath, _options.definitionPath, name223],
|
|
10976
11111
|
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
10977
11112
|
jsonSchema: void 0
|
|
10978
11113
|
}
|
|
@@ -10981,50 +11116,50 @@ var getRefs2 = (options) => {
|
|
|
10981
11116
|
};
|
|
10982
11117
|
};
|
|
10983
11118
|
var zodToJsonSchema2 = (schema, options) => {
|
|
10984
|
-
var
|
|
11119
|
+
var _a223;
|
|
10985
11120
|
const refs = getRefs2(options);
|
|
10986
11121
|
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
10987
|
-
(acc, [
|
|
10988
|
-
var
|
|
11122
|
+
(acc, [name323, schema2]) => {
|
|
11123
|
+
var _a323;
|
|
10989
11124
|
return {
|
|
10990
11125
|
...acc,
|
|
10991
|
-
[
|
|
11126
|
+
[name323]: (_a323 = parseDef2(
|
|
10992
11127
|
schema2._def,
|
|
10993
11128
|
{
|
|
10994
11129
|
...refs,
|
|
10995
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
11130
|
+
currentPath: [...refs.basePath, refs.definitionPath, name323]
|
|
10996
11131
|
},
|
|
10997
11132
|
true
|
|
10998
|
-
)) != null ?
|
|
11133
|
+
)) != null ? _a323 : parseAnyDef2()
|
|
10999
11134
|
};
|
|
11000
11135
|
},
|
|
11001
11136
|
{}
|
|
11002
11137
|
) : void 0;
|
|
11003
|
-
const
|
|
11004
|
-
const main = (
|
|
11138
|
+
const name223 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
11139
|
+
const main = (_a223 = parseDef2(
|
|
11005
11140
|
schema._def,
|
|
11006
|
-
|
|
11141
|
+
name223 === void 0 ? refs : {
|
|
11007
11142
|
...refs,
|
|
11008
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
11143
|
+
currentPath: [...refs.basePath, refs.definitionPath, name223]
|
|
11009
11144
|
},
|
|
11010
11145
|
false
|
|
11011
|
-
)) != null ?
|
|
11146
|
+
)) != null ? _a223 : parseAnyDef2();
|
|
11012
11147
|
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
11013
11148
|
if (title !== void 0) {
|
|
11014
11149
|
main.title = title;
|
|
11015
11150
|
}
|
|
11016
|
-
const combined =
|
|
11151
|
+
const combined = name223 === void 0 ? definitions ? {
|
|
11017
11152
|
...main,
|
|
11018
11153
|
[refs.definitionPath]: definitions
|
|
11019
11154
|
} : main : {
|
|
11020
11155
|
$ref: [
|
|
11021
11156
|
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
11022
11157
|
refs.definitionPath,
|
|
11023
|
-
|
|
11158
|
+
name223
|
|
11024
11159
|
].join("/"),
|
|
11025
11160
|
[refs.definitionPath]: {
|
|
11026
11161
|
...definitions,
|
|
11027
|
-
[
|
|
11162
|
+
[name223]: main
|
|
11028
11163
|
}
|
|
11029
11164
|
};
|
|
11030
11165
|
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
@@ -11032,8 +11167,8 @@ var zodToJsonSchema2 = (schema, options) => {
|
|
|
11032
11167
|
};
|
|
11033
11168
|
var zod_to_json_schema_default = zodToJsonSchema2;
|
|
11034
11169
|
function zod3Schema(zodSchema22, options) {
|
|
11035
|
-
var
|
|
11036
|
-
const useReferences = (
|
|
11170
|
+
var _a223;
|
|
11171
|
+
const useReferences = (_a223 = void 0 ) != null ? _a223 : false;
|
|
11037
11172
|
return jsonSchema2(
|
|
11038
11173
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
11039
11174
|
() => zod_to_json_schema_default(zodSchema22, {
|
|
@@ -11048,8 +11183,8 @@ function zod3Schema(zodSchema22, options) {
|
|
|
11048
11183
|
);
|
|
11049
11184
|
}
|
|
11050
11185
|
function zod4Schema(zodSchema22, options) {
|
|
11051
|
-
var
|
|
11052
|
-
const useReferences = (
|
|
11186
|
+
var _a223;
|
|
11187
|
+
const useReferences = (_a223 = void 0 ) != null ? _a223 : false;
|
|
11053
11188
|
return jsonSchema2(
|
|
11054
11189
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
11055
11190
|
() => addAdditionalPropertiesToJsonSchema(
|
|
@@ -11186,101 +11321,121 @@ Run 'npx vercel link' to link your project, then 'vc env pull' to fetch the toke
|
|
|
11186
11321
|
});
|
|
11187
11322
|
}
|
|
11188
11323
|
};
|
|
11189
|
-
var name24 = "
|
|
11324
|
+
var name24 = "GatewayForbiddenError";
|
|
11190
11325
|
var marker34 = `vercel.ai.gateway.error.${name24}`;
|
|
11191
11326
|
var symbol34 = Symbol.for(marker34);
|
|
11192
11327
|
var _a34;
|
|
11193
11328
|
var _b32;
|
|
11194
|
-
var
|
|
11329
|
+
var GatewayForbiddenError = class extends (_b32 = GatewayError, _a34 = symbol34, _b32) {
|
|
11195
11330
|
constructor({
|
|
11196
|
-
message = "
|
|
11197
|
-
statusCode =
|
|
11331
|
+
message = "Forbidden",
|
|
11332
|
+
statusCode = 403,
|
|
11198
11333
|
cause
|
|
11199
11334
|
} = {}) {
|
|
11200
11335
|
super({ message, statusCode, cause });
|
|
11201
11336
|
this[_a34] = true;
|
|
11202
11337
|
this.name = name24;
|
|
11203
|
-
this.type = "
|
|
11338
|
+
this.type = "forbidden";
|
|
11204
11339
|
}
|
|
11205
11340
|
static isInstance(error) {
|
|
11206
11341
|
return GatewayError.hasMarker(error) && symbol34 in error;
|
|
11207
11342
|
}
|
|
11208
11343
|
};
|
|
11209
|
-
var name34 = "
|
|
11344
|
+
var name34 = "GatewayInvalidRequestError";
|
|
11210
11345
|
var marker44 = `vercel.ai.gateway.error.${name34}`;
|
|
11211
11346
|
var symbol44 = Symbol.for(marker44);
|
|
11212
11347
|
var _a44;
|
|
11213
11348
|
var _b42;
|
|
11214
|
-
var
|
|
11349
|
+
var GatewayInvalidRequestError = class extends (_b42 = GatewayError, _a44 = symbol44, _b42) {
|
|
11215
11350
|
constructor({
|
|
11216
|
-
message = "
|
|
11217
|
-
statusCode =
|
|
11351
|
+
message = "Invalid request",
|
|
11352
|
+
statusCode = 400,
|
|
11218
11353
|
cause
|
|
11219
11354
|
} = {}) {
|
|
11220
11355
|
super({ message, statusCode, cause });
|
|
11221
11356
|
this[_a44] = true;
|
|
11222
11357
|
this.name = name34;
|
|
11223
|
-
this.type = "
|
|
11358
|
+
this.type = "invalid_request_error";
|
|
11224
11359
|
}
|
|
11225
11360
|
static isInstance(error) {
|
|
11226
11361
|
return GatewayError.hasMarker(error) && symbol44 in error;
|
|
11227
11362
|
}
|
|
11228
11363
|
};
|
|
11229
|
-
var name44 = "
|
|
11364
|
+
var name44 = "GatewayRateLimitError";
|
|
11230
11365
|
var marker54 = `vercel.ai.gateway.error.${name44}`;
|
|
11231
11366
|
var symbol54 = Symbol.for(marker54);
|
|
11232
|
-
var modelNotFoundParamSchema = lazyValidator(
|
|
11233
|
-
() => zodSchema2(
|
|
11234
|
-
z$1.object({
|
|
11235
|
-
modelId: z$1.string()
|
|
11236
|
-
})
|
|
11237
|
-
)
|
|
11238
|
-
);
|
|
11239
11367
|
var _a54;
|
|
11240
11368
|
var _b52;
|
|
11241
|
-
var
|
|
11369
|
+
var GatewayRateLimitError = class extends (_b52 = GatewayError, _a54 = symbol54, _b52) {
|
|
11242
11370
|
constructor({
|
|
11243
|
-
message = "
|
|
11244
|
-
statusCode =
|
|
11245
|
-
modelId,
|
|
11371
|
+
message = "Rate limit exceeded",
|
|
11372
|
+
statusCode = 429,
|
|
11246
11373
|
cause
|
|
11247
11374
|
} = {}) {
|
|
11248
11375
|
super({ message, statusCode, cause });
|
|
11249
11376
|
this[_a54] = true;
|
|
11250
11377
|
this.name = name44;
|
|
11251
|
-
this.type = "
|
|
11252
|
-
this.modelId = modelId;
|
|
11378
|
+
this.type = "rate_limit_exceeded";
|
|
11253
11379
|
}
|
|
11254
11380
|
static isInstance(error) {
|
|
11255
11381
|
return GatewayError.hasMarker(error) && symbol54 in error;
|
|
11256
11382
|
}
|
|
11257
11383
|
};
|
|
11258
|
-
var name54 = "
|
|
11384
|
+
var name54 = "GatewayModelNotFoundError";
|
|
11259
11385
|
var marker64 = `vercel.ai.gateway.error.${name54}`;
|
|
11260
11386
|
var symbol64 = Symbol.for(marker64);
|
|
11387
|
+
var modelNotFoundParamSchema = lazyValidator(
|
|
11388
|
+
() => zodSchema2(
|
|
11389
|
+
z$1.object({
|
|
11390
|
+
modelId: z$1.string()
|
|
11391
|
+
})
|
|
11392
|
+
)
|
|
11393
|
+
);
|
|
11261
11394
|
var _a64;
|
|
11262
11395
|
var _b62;
|
|
11263
|
-
var
|
|
11396
|
+
var GatewayModelNotFoundError = class extends (_b62 = GatewayError, _a64 = symbol64, _b62) {
|
|
11264
11397
|
constructor({
|
|
11265
|
-
message = "
|
|
11266
|
-
statusCode =
|
|
11398
|
+
message = "Model not found",
|
|
11399
|
+
statusCode = 404,
|
|
11400
|
+
modelId,
|
|
11267
11401
|
cause
|
|
11268
11402
|
} = {}) {
|
|
11269
11403
|
super({ message, statusCode, cause });
|
|
11270
11404
|
this[_a64] = true;
|
|
11271
11405
|
this.name = name54;
|
|
11272
|
-
this.type = "
|
|
11406
|
+
this.type = "model_not_found";
|
|
11407
|
+
this.modelId = modelId;
|
|
11273
11408
|
}
|
|
11274
11409
|
static isInstance(error) {
|
|
11275
11410
|
return GatewayError.hasMarker(error) && symbol64 in error;
|
|
11276
11411
|
}
|
|
11277
11412
|
};
|
|
11278
|
-
var name64 = "
|
|
11413
|
+
var name64 = "GatewayInternalServerError";
|
|
11279
11414
|
var marker74 = `vercel.ai.gateway.error.${name64}`;
|
|
11280
11415
|
var symbol74 = Symbol.for(marker74);
|
|
11281
11416
|
var _a74;
|
|
11282
11417
|
var _b72;
|
|
11283
|
-
var
|
|
11418
|
+
var GatewayInternalServerError = class extends (_b72 = GatewayError, _a74 = symbol74, _b72) {
|
|
11419
|
+
constructor({
|
|
11420
|
+
message = "Internal server error",
|
|
11421
|
+
statusCode = 500,
|
|
11422
|
+
cause
|
|
11423
|
+
} = {}) {
|
|
11424
|
+
super({ message, statusCode, cause });
|
|
11425
|
+
this[_a74] = true;
|
|
11426
|
+
this.name = name64;
|
|
11427
|
+
this.type = "internal_server_error";
|
|
11428
|
+
}
|
|
11429
|
+
static isInstance(error) {
|
|
11430
|
+
return GatewayError.hasMarker(error) && symbol74 in error;
|
|
11431
|
+
}
|
|
11432
|
+
};
|
|
11433
|
+
var name74 = "GatewayResponseError";
|
|
11434
|
+
var marker84 = `vercel.ai.gateway.error.${name74}`;
|
|
11435
|
+
var symbol84 = Symbol.for(marker84);
|
|
11436
|
+
var _a84;
|
|
11437
|
+
var _b82;
|
|
11438
|
+
var GatewayResponseError = class extends (_b82 = GatewayError, _a84 = symbol84, _b82) {
|
|
11284
11439
|
constructor({
|
|
11285
11440
|
message = "Invalid response from Gateway",
|
|
11286
11441
|
statusCode = 502,
|
|
@@ -11289,14 +11444,14 @@ var GatewayResponseError = class extends (_b72 = GatewayError, _a74 = symbol74,
|
|
|
11289
11444
|
cause
|
|
11290
11445
|
} = {}) {
|
|
11291
11446
|
super({ message, statusCode, cause });
|
|
11292
|
-
this[
|
|
11293
|
-
this.name =
|
|
11447
|
+
this[_a84] = true;
|
|
11448
|
+
this.name = name74;
|
|
11294
11449
|
this.type = "response_error";
|
|
11295
11450
|
this.response = response;
|
|
11296
11451
|
this.validationError = validationError;
|
|
11297
11452
|
}
|
|
11298
11453
|
static isInstance(error) {
|
|
11299
|
-
return GatewayError.hasMarker(error) &&
|
|
11454
|
+
return GatewayError.hasMarker(error) && symbol84 in error;
|
|
11300
11455
|
}
|
|
11301
11456
|
};
|
|
11302
11457
|
async function createGatewayErrorFromResponse({
|
|
@@ -11348,6 +11503,8 @@ async function createGatewayErrorFromResponse({
|
|
|
11348
11503
|
}
|
|
11349
11504
|
case "internal_server_error":
|
|
11350
11505
|
return new GatewayInternalServerError({ message, statusCode, cause });
|
|
11506
|
+
case "forbidden":
|
|
11507
|
+
return new GatewayForbiddenError({ message, statusCode, cause });
|
|
11351
11508
|
default:
|
|
11352
11509
|
return new GatewayInternalServerError({ message, statusCode, cause });
|
|
11353
11510
|
}
|
|
@@ -11377,24 +11534,24 @@ function extractApiCallResponse(error) {
|
|
|
11377
11534
|
}
|
|
11378
11535
|
return {};
|
|
11379
11536
|
}
|
|
11380
|
-
var
|
|
11381
|
-
var
|
|
11382
|
-
var
|
|
11383
|
-
var
|
|
11384
|
-
var
|
|
11385
|
-
var GatewayTimeoutError = class _GatewayTimeoutError extends (
|
|
11537
|
+
var name84 = "GatewayTimeoutError";
|
|
11538
|
+
var marker94 = `vercel.ai.gateway.error.${name84}`;
|
|
11539
|
+
var symbol94 = Symbol.for(marker94);
|
|
11540
|
+
var _a94;
|
|
11541
|
+
var _b92;
|
|
11542
|
+
var GatewayTimeoutError = class _GatewayTimeoutError extends (_b92 = GatewayError, _a94 = symbol94, _b92) {
|
|
11386
11543
|
constructor({
|
|
11387
11544
|
message = "Request timed out",
|
|
11388
11545
|
statusCode = 408,
|
|
11389
11546
|
cause
|
|
11390
11547
|
} = {}) {
|
|
11391
11548
|
super({ message, statusCode, cause });
|
|
11392
|
-
this[
|
|
11393
|
-
this.name =
|
|
11549
|
+
this[_a94] = true;
|
|
11550
|
+
this.name = name84;
|
|
11394
11551
|
this.type = "timeout_error";
|
|
11395
11552
|
}
|
|
11396
11553
|
static isInstance(error) {
|
|
11397
|
-
return GatewayError.hasMarker(error) &&
|
|
11554
|
+
return GatewayError.hasMarker(error) && symbol94 in error;
|
|
11398
11555
|
}
|
|
11399
11556
|
/**
|
|
11400
11557
|
* Creates a helpful timeout error message with troubleshooting guidance
|
|
@@ -11430,7 +11587,7 @@ function isTimeoutError(error) {
|
|
|
11430
11587
|
return false;
|
|
11431
11588
|
}
|
|
11432
11589
|
async function asGatewayError(error, authMethod) {
|
|
11433
|
-
var
|
|
11590
|
+
var _a1032;
|
|
11434
11591
|
if (GatewayError.isInstance(error)) {
|
|
11435
11592
|
return error;
|
|
11436
11593
|
}
|
|
@@ -11449,7 +11606,7 @@ async function asGatewayError(error, authMethod) {
|
|
|
11449
11606
|
}
|
|
11450
11607
|
return await createGatewayErrorFromResponse({
|
|
11451
11608
|
response: extractApiCallResponse(error),
|
|
11452
|
-
statusCode: (
|
|
11609
|
+
statusCode: (_a1032 = error.statusCode) != null ? _a1032 : 500,
|
|
11453
11610
|
defaultMessage: "Gateway request failed",
|
|
11454
11611
|
cause: error,
|
|
11455
11612
|
authMethod
|
|
@@ -11909,7 +12066,7 @@ var GatewayEmbeddingModel = class {
|
|
|
11909
12066
|
abortSignal,
|
|
11910
12067
|
providerOptions
|
|
11911
12068
|
}) {
|
|
11912
|
-
var
|
|
12069
|
+
var _a1032;
|
|
11913
12070
|
const resolvedHeaders = await resolve(this.config.headers());
|
|
11914
12071
|
try {
|
|
11915
12072
|
const {
|
|
@@ -11940,7 +12097,7 @@ var GatewayEmbeddingModel = class {
|
|
|
11940
12097
|
});
|
|
11941
12098
|
return {
|
|
11942
12099
|
embeddings: responseBody.embeddings,
|
|
11943
|
-
usage: (
|
|
12100
|
+
usage: (_a1032 = responseBody.usage) != null ? _a1032 : void 0,
|
|
11944
12101
|
providerMetadata: responseBody.providerMetadata,
|
|
11945
12102
|
response: { headers: responseHeaders, body: rawValue }
|
|
11946
12103
|
};
|
|
@@ -11987,7 +12144,7 @@ var GatewayImageModel = class {
|
|
|
11987
12144
|
headers,
|
|
11988
12145
|
abortSignal
|
|
11989
12146
|
}) {
|
|
11990
|
-
var
|
|
12147
|
+
var _a1032, _b104, _c, _d;
|
|
11991
12148
|
const resolvedHeaders = await resolve(this.config.headers());
|
|
11992
12149
|
try {
|
|
11993
12150
|
const {
|
|
@@ -12022,7 +12179,7 @@ var GatewayImageModel = class {
|
|
|
12022
12179
|
return {
|
|
12023
12180
|
images: responseBody.images,
|
|
12024
12181
|
// Always base64 strings from server
|
|
12025
|
-
warnings: (
|
|
12182
|
+
warnings: (_a1032 = responseBody.warnings) != null ? _a1032 : [],
|
|
12026
12183
|
providerMetadata: responseBody.providerMetadata,
|
|
12027
12184
|
response: {
|
|
12028
12185
|
timestamp: /* @__PURE__ */ new Date(),
|
|
@@ -12031,7 +12188,7 @@ var GatewayImageModel = class {
|
|
|
12031
12188
|
},
|
|
12032
12189
|
...responseBody.usage != null && {
|
|
12033
12190
|
usage: {
|
|
12034
|
-
inputTokens: (
|
|
12191
|
+
inputTokens: (_b104 = responseBody.usage.inputTokens) != null ? _b104 : void 0,
|
|
12035
12192
|
outputTokens: (_c = responseBody.usage.outputTokens) != null ? _c : void 0,
|
|
12036
12193
|
totalTokens: (_d = responseBody.usage.totalTokens) != null ? _d : void 0
|
|
12037
12194
|
}
|
|
@@ -12246,18 +12403,18 @@ var gatewayTools = {
|
|
|
12246
12403
|
perplexitySearch
|
|
12247
12404
|
};
|
|
12248
12405
|
async function getVercelRequestId() {
|
|
12249
|
-
var
|
|
12250
|
-
return (
|
|
12406
|
+
var _a1032;
|
|
12407
|
+
return (_a1032 = getContext().headers) == null ? void 0 : _a1032["x-vercel-id"];
|
|
12251
12408
|
}
|
|
12252
|
-
var VERSION3 = "2.0.
|
|
12409
|
+
var VERSION3 = "2.0.109";
|
|
12253
12410
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
12254
12411
|
function createGatewayProvider(options = {}) {
|
|
12255
|
-
var
|
|
12412
|
+
var _a1032, _b104;
|
|
12256
12413
|
let pendingMetadata = null;
|
|
12257
12414
|
let metadataCache = null;
|
|
12258
|
-
const cacheRefreshMillis = (
|
|
12415
|
+
const cacheRefreshMillis = (_a1032 = options.metadataCacheRefreshMillis) != null ? _a1032 : 1e3 * 60 * 5;
|
|
12259
12416
|
let lastFetchTime = 0;
|
|
12260
|
-
const baseURL = (
|
|
12417
|
+
const baseURL = (_b104 = withoutTrailingSlash(options.baseURL)) != null ? _b104 : "https://ai-gateway.vercel.sh/v1/ai";
|
|
12261
12418
|
const getHeaders = async () => {
|
|
12262
12419
|
const auth = await getGatewayAuthToken(options);
|
|
12263
12420
|
if (auth) {
|
|
@@ -12315,8 +12472,8 @@ function createGatewayProvider(options = {}) {
|
|
|
12315
12472
|
});
|
|
12316
12473
|
};
|
|
12317
12474
|
const getAvailableModels = async () => {
|
|
12318
|
-
var
|
|
12319
|
-
const now2 = (_c = (
|
|
12475
|
+
var _a1122, _b113, _c;
|
|
12476
|
+
const now2 = (_c = (_b113 = (_a1122 = options._internal) == null ? void 0 : _a1122.currentDate) == null ? void 0 : _b113.call(_a1122).getTime()) != null ? _c : Date.now();
|
|
12320
12477
|
if (!pendingMetadata || now2 - lastFetchTime > cacheRefreshMillis) {
|
|
12321
12478
|
lastFetchTime = now2;
|
|
12322
12479
|
pendingMetadata = new GatewayFetchMetadata({
|
|
@@ -12520,12 +12677,12 @@ function registerGlobal2(type, instance, diag, allowOverride) {
|
|
|
12520
12677
|
return true;
|
|
12521
12678
|
}
|
|
12522
12679
|
function getGlobal2(type) {
|
|
12523
|
-
var _a163,
|
|
12680
|
+
var _a163, _b104;
|
|
12524
12681
|
var globalVersion = (_a163 = _global2[GLOBAL_OPENTELEMETRY_API_KEY2]) === null || _a163 === void 0 ? void 0 : _a163.version;
|
|
12525
12682
|
if (!globalVersion || !isCompatible2(globalVersion)) {
|
|
12526
12683
|
return;
|
|
12527
12684
|
}
|
|
12528
|
-
return (
|
|
12685
|
+
return (_b104 = _global2[GLOBAL_OPENTELEMETRY_API_KEY2]) === null || _b104 === void 0 ? void 0 : _b104[type];
|
|
12529
12686
|
}
|
|
12530
12687
|
function unregisterGlobal2(type, diag) {
|
|
12531
12688
|
diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION22 + ".");
|
|
@@ -12688,15 +12845,15 @@ var DiagAPI2 = (
|
|
|
12688
12845
|
return logger[funcName].apply(logger, __spreadArray22([], __read22(args), false));
|
|
12689
12846
|
};
|
|
12690
12847
|
}
|
|
12691
|
-
var
|
|
12848
|
+
var self2 = this;
|
|
12692
12849
|
var setLogger = function(logger, optionsOrLogLevel) {
|
|
12693
|
-
var _a163,
|
|
12850
|
+
var _a163, _b104, _c;
|
|
12694
12851
|
if (optionsOrLogLevel === void 0) {
|
|
12695
12852
|
optionsOrLogLevel = { logLevel: DiagLogLevel2.INFO };
|
|
12696
12853
|
}
|
|
12697
|
-
if (logger ===
|
|
12854
|
+
if (logger === self2) {
|
|
12698
12855
|
var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
|
|
12699
|
-
|
|
12856
|
+
self2.error((_a163 = err.stack) !== null && _a163 !== void 0 ? _a163 : err.message);
|
|
12700
12857
|
return false;
|
|
12701
12858
|
}
|
|
12702
12859
|
if (typeof optionsOrLogLevel === "number") {
|
|
@@ -12705,26 +12862,26 @@ var DiagAPI2 = (
|
|
|
12705
12862
|
};
|
|
12706
12863
|
}
|
|
12707
12864
|
var oldLogger = getGlobal2("diag");
|
|
12708
|
-
var newLogger = createLogLevelDiagLogger2((
|
|
12865
|
+
var newLogger = createLogLevelDiagLogger2((_b104 = optionsOrLogLevel.logLevel) !== null && _b104 !== void 0 ? _b104 : DiagLogLevel2.INFO, logger);
|
|
12709
12866
|
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
|
12710
12867
|
var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
|
|
12711
12868
|
oldLogger.warn("Current logger will be overwritten from " + stack);
|
|
12712
12869
|
newLogger.warn("Current logger will overwrite one already registered from " + stack);
|
|
12713
12870
|
}
|
|
12714
|
-
return registerGlobal2("diag", newLogger,
|
|
12871
|
+
return registerGlobal2("diag", newLogger, self2, true);
|
|
12715
12872
|
};
|
|
12716
|
-
|
|
12717
|
-
|
|
12718
|
-
unregisterGlobal2(API_NAME4,
|
|
12873
|
+
self2.setLogger = setLogger;
|
|
12874
|
+
self2.disable = function() {
|
|
12875
|
+
unregisterGlobal2(API_NAME4, self2);
|
|
12719
12876
|
};
|
|
12720
|
-
|
|
12877
|
+
self2.createComponentLogger = function(options) {
|
|
12721
12878
|
return new DiagComponentLogger2(options);
|
|
12722
12879
|
};
|
|
12723
|
-
|
|
12724
|
-
|
|
12725
|
-
|
|
12726
|
-
|
|
12727
|
-
|
|
12880
|
+
self2.verbose = _logProxy("verbose");
|
|
12881
|
+
self2.debug = _logProxy("debug");
|
|
12882
|
+
self2.info = _logProxy("info");
|
|
12883
|
+
self2.warn = _logProxy("warn");
|
|
12884
|
+
self2.error = _logProxy("error");
|
|
12728
12885
|
}
|
|
12729
12886
|
DiagAPI22.instance = function() {
|
|
12730
12887
|
if (!this._instance) {
|
|
@@ -12742,18 +12899,18 @@ var BaseContext2 = (
|
|
|
12742
12899
|
/** @class */
|
|
12743
12900
|
/* @__PURE__ */ (function() {
|
|
12744
12901
|
function BaseContext22(parentContext) {
|
|
12745
|
-
var
|
|
12746
|
-
|
|
12747
|
-
|
|
12748
|
-
return
|
|
12902
|
+
var self2 = this;
|
|
12903
|
+
self2._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
|
|
12904
|
+
self2.getValue = function(key) {
|
|
12905
|
+
return self2._currentContext.get(key);
|
|
12749
12906
|
};
|
|
12750
|
-
|
|
12751
|
-
var context2 = new BaseContext22(
|
|
12907
|
+
self2.setValue = function(key, value) {
|
|
12908
|
+
var context2 = new BaseContext22(self2._currentContext);
|
|
12752
12909
|
context2._currentContext.set(key, value);
|
|
12753
12910
|
return context2;
|
|
12754
12911
|
};
|
|
12755
|
-
|
|
12756
|
-
var context2 = new BaseContext22(
|
|
12912
|
+
self2.deleteValue = function(key) {
|
|
12913
|
+
var context2 = new BaseContext22(self2._currentContext);
|
|
12757
12914
|
context2._currentContext.delete(key);
|
|
12758
12915
|
return context2;
|
|
12759
12916
|
};
|
|
@@ -13236,7 +13393,7 @@ function getGlobalProvider() {
|
|
|
13236
13393
|
var _a163;
|
|
13237
13394
|
return (_a163 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a163 : gateway;
|
|
13238
13395
|
}
|
|
13239
|
-
var VERSION32 = "5.0.
|
|
13396
|
+
var VERSION32 = "5.0.210";
|
|
13240
13397
|
var dataContentSchema2 = z$1.union([
|
|
13241
13398
|
z$1.string(),
|
|
13242
13399
|
z$1.instanceof(Uint8Array),
|
|
@@ -13244,8 +13401,8 @@ var dataContentSchema2 = z$1.union([
|
|
|
13244
13401
|
z$1.custom(
|
|
13245
13402
|
// Buffer might not be available in some environments such as CloudFlare:
|
|
13246
13403
|
(value) => {
|
|
13247
|
-
var _a163,
|
|
13248
|
-
return (
|
|
13404
|
+
var _a163, _b104;
|
|
13405
|
+
return (_b104 = (_a163 = globalThis.Buffer) == null ? void 0 : _a163.isBuffer(value)) != null ? _b104 : false;
|
|
13249
13406
|
},
|
|
13250
13407
|
{ message: "Must be a Buffer" }
|
|
13251
13408
|
)
|
|
@@ -14769,6 +14926,90 @@ function convertUint8ArrayToBase643(array2) {
|
|
|
14769
14926
|
}
|
|
14770
14927
|
return btoa3(latin1string);
|
|
14771
14928
|
}
|
|
14929
|
+
async function cancelResponseBody2(response) {
|
|
14930
|
+
var _a223;
|
|
14931
|
+
try {
|
|
14932
|
+
await ((_a223 = response.body) == null ? void 0 : _a223.cancel());
|
|
14933
|
+
} catch (e) {
|
|
14934
|
+
}
|
|
14935
|
+
}
|
|
14936
|
+
var name144 = "AI_DownloadError";
|
|
14937
|
+
var marker154 = `vercel.ai.error.${name144}`;
|
|
14938
|
+
var symbol154 = Symbol.for(marker154);
|
|
14939
|
+
var _a154;
|
|
14940
|
+
var _b152;
|
|
14941
|
+
var DownloadError2 = class extends (_b152 = AISDKError3, _a154 = symbol154, _b152) {
|
|
14942
|
+
constructor({
|
|
14943
|
+
url,
|
|
14944
|
+
statusCode,
|
|
14945
|
+
statusText,
|
|
14946
|
+
cause,
|
|
14947
|
+
message = cause == null ? `Failed to download ${url}: ${statusCode} ${statusText}` : `Failed to download ${url}: ${cause}`
|
|
14948
|
+
}) {
|
|
14949
|
+
super({ name: name144, message, cause });
|
|
14950
|
+
this[_a154] = true;
|
|
14951
|
+
this.url = url;
|
|
14952
|
+
this.statusCode = statusCode;
|
|
14953
|
+
this.statusText = statusText;
|
|
14954
|
+
}
|
|
14955
|
+
static isInstance(error) {
|
|
14956
|
+
return AISDKError3.hasMarker(error, marker154);
|
|
14957
|
+
}
|
|
14958
|
+
};
|
|
14959
|
+
var DEFAULT_MAX_DOWNLOAD_SIZE2 = 2 * 1024 * 1024 * 1024;
|
|
14960
|
+
async function readResponseWithSizeLimit2({
|
|
14961
|
+
response,
|
|
14962
|
+
url,
|
|
14963
|
+
maxBytes = DEFAULT_MAX_DOWNLOAD_SIZE2
|
|
14964
|
+
}) {
|
|
14965
|
+
const contentLength = response.headers.get("content-length");
|
|
14966
|
+
if (contentLength != null) {
|
|
14967
|
+
const length = parseInt(contentLength, 10);
|
|
14968
|
+
if (!isNaN(length) && length > maxBytes) {
|
|
14969
|
+
await cancelResponseBody2(response);
|
|
14970
|
+
throw new DownloadError2({
|
|
14971
|
+
url,
|
|
14972
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes (Content-Length: ${length}).`
|
|
14973
|
+
});
|
|
14974
|
+
}
|
|
14975
|
+
}
|
|
14976
|
+
const body = response.body;
|
|
14977
|
+
if (body == null) {
|
|
14978
|
+
return new Uint8Array(0);
|
|
14979
|
+
}
|
|
14980
|
+
const reader = body.getReader();
|
|
14981
|
+
const chunks = [];
|
|
14982
|
+
let totalBytes = 0;
|
|
14983
|
+
try {
|
|
14984
|
+
while (true) {
|
|
14985
|
+
const { done, value } = await reader.read();
|
|
14986
|
+
if (done) {
|
|
14987
|
+
break;
|
|
14988
|
+
}
|
|
14989
|
+
totalBytes += value.length;
|
|
14990
|
+
if (totalBytes > maxBytes) {
|
|
14991
|
+
throw new DownloadError2({
|
|
14992
|
+
url,
|
|
14993
|
+
message: `Download of ${url} exceeded maximum size of ${maxBytes} bytes.`
|
|
14994
|
+
});
|
|
14995
|
+
}
|
|
14996
|
+
chunks.push(value);
|
|
14997
|
+
}
|
|
14998
|
+
} finally {
|
|
14999
|
+
try {
|
|
15000
|
+
await reader.cancel();
|
|
15001
|
+
} finally {
|
|
15002
|
+
reader.releaseLock();
|
|
15003
|
+
}
|
|
15004
|
+
}
|
|
15005
|
+
const result = new Uint8Array(totalBytes);
|
|
15006
|
+
let offset = 0;
|
|
15007
|
+
for (const chunk of chunks) {
|
|
15008
|
+
result.set(chunk, offset);
|
|
15009
|
+
offset += chunk.length;
|
|
15010
|
+
}
|
|
15011
|
+
return result;
|
|
15012
|
+
}
|
|
14772
15013
|
var createIdGenerator3 = ({
|
|
14773
15014
|
prefix,
|
|
14774
15015
|
size = 16,
|
|
@@ -14864,11 +15105,11 @@ function handleFetchError2({
|
|
|
14864
15105
|
return error;
|
|
14865
15106
|
}
|
|
14866
15107
|
function getRuntimeEnvironmentUserAgent2(globalThisAny = globalThis) {
|
|
14867
|
-
var
|
|
15108
|
+
var _a223, _b222, _c;
|
|
14868
15109
|
if (globalThisAny.window) {
|
|
14869
15110
|
return `runtime/browser`;
|
|
14870
15111
|
}
|
|
14871
|
-
if ((
|
|
15112
|
+
if ((_a223 = globalThisAny.navigator) == null ? void 0 : _a223.userAgent) {
|
|
14872
15113
|
return `runtime/${globalThisAny.navigator.userAgent.toLowerCase()}`;
|
|
14873
15114
|
}
|
|
14874
15115
|
if ((_c = (_b222 = globalThisAny.process) == null ? void 0 : _b222.versions) == null ? void 0 : _c.node) {
|
|
@@ -14909,7 +15150,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
14909
15150
|
);
|
|
14910
15151
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
14911
15152
|
}
|
|
14912
|
-
var VERSION4 = "4.0.
|
|
15153
|
+
var VERSION4 = "4.0.38";
|
|
14913
15154
|
var getOriginalFetch3 = () => globalThis.fetch;
|
|
14914
15155
|
var getFromApi2 = async ({
|
|
14915
15156
|
url,
|
|
@@ -15110,11 +15351,11 @@ function parseAnyDef3() {
|
|
|
15110
15351
|
return {};
|
|
15111
15352
|
}
|
|
15112
15353
|
function parseArrayDef3(def, refs) {
|
|
15113
|
-
var
|
|
15354
|
+
var _a223, _b222, _c;
|
|
15114
15355
|
const res = {
|
|
15115
15356
|
type: "array"
|
|
15116
15357
|
};
|
|
15117
|
-
if (((
|
|
15358
|
+
if (((_a223 = def.type) == null ? void 0 : _a223._def) && ((_c = (_b222 = def.type) == null ? void 0 : _b222._def) == null ? void 0 : _c.typeName) !== ZodFirstPartyTypeKind.ZodAny) {
|
|
15118
15359
|
res.items = parseDef3(def.type._def, {
|
|
15119
15360
|
...refs,
|
|
15120
15361
|
currentPath: [...refs.currentPath, "items"]
|
|
@@ -15473,8 +15714,8 @@ function escapeNonAlphaNumeric3(source) {
|
|
|
15473
15714
|
return result;
|
|
15474
15715
|
}
|
|
15475
15716
|
function addFormat3(schema, value, message, refs) {
|
|
15476
|
-
var
|
|
15477
|
-
if (schema.format || ((
|
|
15717
|
+
var _a223;
|
|
15718
|
+
if (schema.format || ((_a223 = schema.anyOf) == null ? void 0 : _a223.some((x) => x.format))) {
|
|
15478
15719
|
if (!schema.anyOf) {
|
|
15479
15720
|
schema.anyOf = [];
|
|
15480
15721
|
}
|
|
@@ -15493,8 +15734,8 @@ function addFormat3(schema, value, message, refs) {
|
|
|
15493
15734
|
}
|
|
15494
15735
|
}
|
|
15495
15736
|
function addPattern3(schema, regex, message, refs) {
|
|
15496
|
-
var
|
|
15497
|
-
if (schema.pattern || ((
|
|
15737
|
+
var _a223;
|
|
15738
|
+
if (schema.pattern || ((_a223 = schema.allOf) == null ? void 0 : _a223.some((x) => x.pattern))) {
|
|
15498
15739
|
if (!schema.allOf) {
|
|
15499
15740
|
schema.allOf = [];
|
|
15500
15741
|
}
|
|
@@ -15513,7 +15754,7 @@ function addPattern3(schema, regex, message, refs) {
|
|
|
15513
15754
|
}
|
|
15514
15755
|
}
|
|
15515
15756
|
function stringifyRegExpWithFlags3(regex, refs) {
|
|
15516
|
-
var
|
|
15757
|
+
var _a223;
|
|
15517
15758
|
if (!refs.applyRegexFlags || !regex.flags) {
|
|
15518
15759
|
return regex.source;
|
|
15519
15760
|
}
|
|
@@ -15543,7 +15784,7 @@ function stringifyRegExpWithFlags3(regex, refs) {
|
|
|
15543
15784
|
pattern += source[i];
|
|
15544
15785
|
pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
|
|
15545
15786
|
inCharRange = false;
|
|
15546
|
-
} else if (source[i + 1] === "-" && ((
|
|
15787
|
+
} else if (source[i + 1] === "-" && ((_a223 = source[i + 2]) == null ? void 0 : _a223.match(/[a-z]/))) {
|
|
15547
15788
|
pattern += source[i];
|
|
15548
15789
|
inCharRange = true;
|
|
15549
15790
|
} else {
|
|
@@ -15585,13 +15826,13 @@ function stringifyRegExpWithFlags3(regex, refs) {
|
|
|
15585
15826
|
return pattern;
|
|
15586
15827
|
}
|
|
15587
15828
|
function parseRecordDef3(def, refs) {
|
|
15588
|
-
var
|
|
15829
|
+
var _a223, _b222, _c, _d, _e, _f;
|
|
15589
15830
|
const schema = {
|
|
15590
15831
|
type: "object",
|
|
15591
|
-
additionalProperties: (
|
|
15832
|
+
additionalProperties: (_a223 = parseDef3(def.valueType._def, {
|
|
15592
15833
|
...refs,
|
|
15593
15834
|
currentPath: [...refs.currentPath, "additionalProperties"]
|
|
15594
|
-
})) != null ?
|
|
15835
|
+
})) != null ? _a223 : refs.allowedAdditionalProperties
|
|
15595
15836
|
};
|
|
15596
15837
|
if (((_b222 = def.keyType) == null ? void 0 : _b222._def.typeName) === ZodFirstPartyTypeKind.ZodString && ((_c = def.keyType._def.checks) == null ? void 0 : _c.length)) {
|
|
15597
15838
|
const { type, ...keyType } = parseStringDef3(def.keyType._def, refs);
|
|
@@ -15848,8 +16089,8 @@ function safeIsOptional3(schema) {
|
|
|
15848
16089
|
}
|
|
15849
16090
|
}
|
|
15850
16091
|
var parseOptionalDef3 = (def, refs) => {
|
|
15851
|
-
var
|
|
15852
|
-
if (refs.currentPath.toString() === ((
|
|
16092
|
+
var _a223;
|
|
16093
|
+
if (refs.currentPath.toString() === ((_a223 = refs.propertyPath) == null ? void 0 : _a223.toString())) {
|
|
15853
16094
|
return parseDef3(def.innerType._def, refs);
|
|
15854
16095
|
}
|
|
15855
16096
|
const innerSchema = parseDef3(def.innerType._def, {
|
|
@@ -16026,10 +16267,10 @@ var getRelativePath3 = (pathA, pathB) => {
|
|
|
16026
16267
|
return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
|
|
16027
16268
|
};
|
|
16028
16269
|
function parseDef3(def, refs, forceResolution = false) {
|
|
16029
|
-
var
|
|
16270
|
+
var _a223;
|
|
16030
16271
|
const seenItem = refs.seen.get(def);
|
|
16031
16272
|
if (refs.override) {
|
|
16032
|
-
const overrideResult = (
|
|
16273
|
+
const overrideResult = (_a223 = refs.override) == null ? void 0 : _a223.call(
|
|
16033
16274
|
refs,
|
|
16034
16275
|
def,
|
|
16035
16276
|
refs,
|
|
@@ -16095,11 +16336,11 @@ var getRefs3 = (options) => {
|
|
|
16095
16336
|
currentPath,
|
|
16096
16337
|
propertyPath: void 0,
|
|
16097
16338
|
seen: new Map(
|
|
16098
|
-
Object.entries(_options.definitions).map(([
|
|
16339
|
+
Object.entries(_options.definitions).map(([name223, def]) => [
|
|
16099
16340
|
def._def,
|
|
16100
16341
|
{
|
|
16101
16342
|
def: def._def,
|
|
16102
|
-
path: [..._options.basePath, _options.definitionPath,
|
|
16343
|
+
path: [..._options.basePath, _options.definitionPath, name223],
|
|
16103
16344
|
// Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
|
|
16104
16345
|
jsonSchema: void 0
|
|
16105
16346
|
}
|
|
@@ -16108,50 +16349,50 @@ var getRefs3 = (options) => {
|
|
|
16108
16349
|
};
|
|
16109
16350
|
};
|
|
16110
16351
|
var zod3ToJsonSchema = (schema, options) => {
|
|
16111
|
-
var
|
|
16352
|
+
var _a223;
|
|
16112
16353
|
const refs = getRefs3(options);
|
|
16113
16354
|
let definitions = typeof options === "object" && options.definitions ? Object.entries(options.definitions).reduce(
|
|
16114
|
-
(acc, [
|
|
16115
|
-
var
|
|
16355
|
+
(acc, [name323, schema2]) => {
|
|
16356
|
+
var _a323;
|
|
16116
16357
|
return {
|
|
16117
16358
|
...acc,
|
|
16118
|
-
[
|
|
16359
|
+
[name323]: (_a323 = parseDef3(
|
|
16119
16360
|
schema2._def,
|
|
16120
16361
|
{
|
|
16121
16362
|
...refs,
|
|
16122
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
16363
|
+
currentPath: [...refs.basePath, refs.definitionPath, name323]
|
|
16123
16364
|
},
|
|
16124
16365
|
true
|
|
16125
|
-
)) != null ?
|
|
16366
|
+
)) != null ? _a323 : parseAnyDef3()
|
|
16126
16367
|
};
|
|
16127
16368
|
},
|
|
16128
16369
|
{}
|
|
16129
16370
|
) : void 0;
|
|
16130
|
-
const
|
|
16131
|
-
const main = (
|
|
16371
|
+
const name223 = typeof options === "string" ? options : (options == null ? void 0 : options.nameStrategy) === "title" ? void 0 : options == null ? void 0 : options.name;
|
|
16372
|
+
const main = (_a223 = parseDef3(
|
|
16132
16373
|
schema._def,
|
|
16133
|
-
|
|
16374
|
+
name223 === void 0 ? refs : {
|
|
16134
16375
|
...refs,
|
|
16135
|
-
currentPath: [...refs.basePath, refs.definitionPath,
|
|
16376
|
+
currentPath: [...refs.basePath, refs.definitionPath, name223]
|
|
16136
16377
|
},
|
|
16137
16378
|
false
|
|
16138
|
-
)) != null ?
|
|
16379
|
+
)) != null ? _a223 : parseAnyDef3();
|
|
16139
16380
|
const title = typeof options === "object" && options.name !== void 0 && options.nameStrategy === "title" ? options.name : void 0;
|
|
16140
16381
|
if (title !== void 0) {
|
|
16141
16382
|
main.title = title;
|
|
16142
16383
|
}
|
|
16143
|
-
const combined =
|
|
16384
|
+
const combined = name223 === void 0 ? definitions ? {
|
|
16144
16385
|
...main,
|
|
16145
16386
|
[refs.definitionPath]: definitions
|
|
16146
16387
|
} : main : {
|
|
16147
16388
|
$ref: [
|
|
16148
16389
|
...refs.$refStrategy === "relative" ? [] : refs.basePath,
|
|
16149
16390
|
refs.definitionPath,
|
|
16150
|
-
|
|
16391
|
+
name223
|
|
16151
16392
|
].join("/"),
|
|
16152
16393
|
[refs.definitionPath]: {
|
|
16153
16394
|
...definitions,
|
|
16154
|
-
[
|
|
16395
|
+
[name223]: main
|
|
16155
16396
|
}
|
|
16156
16397
|
};
|
|
16157
16398
|
combined.$schema = "http://json-schema.org/draft-07/schema#";
|
|
@@ -16187,7 +16428,11 @@ function isSchema3(value) {
|
|
|
16187
16428
|
return typeof value === "object" && value !== null && schemaSymbol3 in value && value[schemaSymbol3] === true && "jsonSchema" in value && "validate" in value;
|
|
16188
16429
|
}
|
|
16189
16430
|
function asSchema3(schema) {
|
|
16190
|
-
return schema == null ? jsonSchema3({
|
|
16431
|
+
return schema == null ? jsonSchema3({
|
|
16432
|
+
type: "object",
|
|
16433
|
+
properties: {},
|
|
16434
|
+
additionalProperties: false
|
|
16435
|
+
}) : isSchema3(schema) ? schema : "~standard" in schema ? schema["~standard"].vendor === "zod" ? zodSchema3(schema) : standardSchema(schema) : schema();
|
|
16191
16436
|
}
|
|
16192
16437
|
function standardSchema(standardSchema2) {
|
|
16193
16438
|
return jsonSchema3(
|
|
@@ -16211,8 +16456,8 @@ function standardSchema(standardSchema2) {
|
|
|
16211
16456
|
);
|
|
16212
16457
|
}
|
|
16213
16458
|
function zod3Schema2(zodSchema22, options) {
|
|
16214
|
-
var
|
|
16215
|
-
const useReferences = (
|
|
16459
|
+
var _a223;
|
|
16460
|
+
const useReferences = (_a223 = void 0 ) != null ? _a223 : false;
|
|
16216
16461
|
return jsonSchema3(
|
|
16217
16462
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
16218
16463
|
() => zod3ToJsonSchema(zodSchema22, {
|
|
@@ -16227,8 +16472,8 @@ function zod3Schema2(zodSchema22, options) {
|
|
|
16227
16472
|
);
|
|
16228
16473
|
}
|
|
16229
16474
|
function zod4Schema2(zodSchema22, options) {
|
|
16230
|
-
var
|
|
16231
|
-
const useReferences = (
|
|
16475
|
+
var _a223;
|
|
16476
|
+
const useReferences = (_a223 = void 0 ) != null ? _a223 : false;
|
|
16232
16477
|
return jsonSchema3(
|
|
16233
16478
|
// defer json schema creation to avoid unnecessary computation when only validation is needed
|
|
16234
16479
|
() => addAdditionalPropertiesToJsonSchema2(
|
|
@@ -16475,12 +16720,101 @@ async function resolve2(value) {
|
|
|
16475
16720
|
}
|
|
16476
16721
|
return Promise.resolve(value);
|
|
16477
16722
|
}
|
|
16723
|
+
var retryWithExponentialBackoff2 = ({
|
|
16724
|
+
maxRetries = 2,
|
|
16725
|
+
initialDelayInMs = 2e3,
|
|
16726
|
+
backoffFactor = 2,
|
|
16727
|
+
abortSignal,
|
|
16728
|
+
shouldRetry,
|
|
16729
|
+
getDelayInMs = ({ exponentialBackoffDelay }) => exponentialBackoffDelay,
|
|
16730
|
+
createRetryError = ({ message }) => new Error(message)
|
|
16731
|
+
}) => async (f) => retryWithExponentialBackoffInternal(f, {
|
|
16732
|
+
maxRetries,
|
|
16733
|
+
delayInMs: initialDelayInMs,
|
|
16734
|
+
backoffFactor,
|
|
16735
|
+
abortSignal,
|
|
16736
|
+
shouldRetry,
|
|
16737
|
+
getDelayInMs,
|
|
16738
|
+
createRetryError
|
|
16739
|
+
});
|
|
16740
|
+
async function retryWithExponentialBackoffInternal(f, {
|
|
16741
|
+
maxRetries,
|
|
16742
|
+
delayInMs,
|
|
16743
|
+
backoffFactor,
|
|
16744
|
+
abortSignal,
|
|
16745
|
+
shouldRetry,
|
|
16746
|
+
getDelayInMs,
|
|
16747
|
+
createRetryError
|
|
16748
|
+
}, errors = []) {
|
|
16749
|
+
try {
|
|
16750
|
+
return await f();
|
|
16751
|
+
} catch (error) {
|
|
16752
|
+
if (isAbortError5(error)) {
|
|
16753
|
+
throw error;
|
|
16754
|
+
}
|
|
16755
|
+
if (maxRetries === 0) {
|
|
16756
|
+
throw error;
|
|
16757
|
+
}
|
|
16758
|
+
const errorMessage = getErrorMessage23(error);
|
|
16759
|
+
const newErrors = [...errors, error];
|
|
16760
|
+
const tryNumber = newErrors.length;
|
|
16761
|
+
if (tryNumber > maxRetries) {
|
|
16762
|
+
throw createRetryError({
|
|
16763
|
+
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
|
16764
|
+
reason: "maxRetriesExceeded",
|
|
16765
|
+
errors: newErrors
|
|
16766
|
+
});
|
|
16767
|
+
}
|
|
16768
|
+
if (await shouldRetry(error) && tryNumber <= maxRetries) {
|
|
16769
|
+
await delay3(
|
|
16770
|
+
getDelayInMs({
|
|
16771
|
+
error,
|
|
16772
|
+
exponentialBackoffDelay: delayInMs
|
|
16773
|
+
}),
|
|
16774
|
+
{ abortSignal }
|
|
16775
|
+
);
|
|
16776
|
+
return retryWithExponentialBackoffInternal(
|
|
16777
|
+
f,
|
|
16778
|
+
{
|
|
16779
|
+
maxRetries,
|
|
16780
|
+
delayInMs: backoffFactor * delayInMs,
|
|
16781
|
+
backoffFactor,
|
|
16782
|
+
abortSignal,
|
|
16783
|
+
shouldRetry,
|
|
16784
|
+
getDelayInMs,
|
|
16785
|
+
createRetryError
|
|
16786
|
+
},
|
|
16787
|
+
newErrors
|
|
16788
|
+
);
|
|
16789
|
+
}
|
|
16790
|
+
if (tryNumber === 1) {
|
|
16791
|
+
throw error;
|
|
16792
|
+
}
|
|
16793
|
+
throw createRetryError({
|
|
16794
|
+
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
|
16795
|
+
reason: "errorNotRetryable",
|
|
16796
|
+
errors: newErrors
|
|
16797
|
+
});
|
|
16798
|
+
}
|
|
16799
|
+
}
|
|
16800
|
+
var textDecoder2 = new TextDecoder();
|
|
16801
|
+
async function readResponseBodyAsText2({
|
|
16802
|
+
response,
|
|
16803
|
+
url
|
|
16804
|
+
}) {
|
|
16805
|
+
return textDecoder2.decode(
|
|
16806
|
+
await readResponseWithSizeLimit2({
|
|
16807
|
+
response,
|
|
16808
|
+
url
|
|
16809
|
+
})
|
|
16810
|
+
);
|
|
16811
|
+
}
|
|
16478
16812
|
var createJsonErrorResponseHandler2 = ({
|
|
16479
16813
|
errorSchema,
|
|
16480
16814
|
errorToMessage,
|
|
16481
16815
|
isRetryable
|
|
16482
16816
|
}) => async ({ response, url, requestBodyValues }) => {
|
|
16483
|
-
const responseBody = await response
|
|
16817
|
+
const responseBody = await readResponseBodyAsText2({ response, url });
|
|
16484
16818
|
const responseHeaders = extractResponseHeaders2(response);
|
|
16485
16819
|
if (responseBody.trim() === "") {
|
|
16486
16820
|
return {
|
|
@@ -16543,7 +16877,7 @@ var createEventSourceResponseHandler2 = (chunkSchema) => async ({ response }) =>
|
|
|
16543
16877
|
};
|
|
16544
16878
|
};
|
|
16545
16879
|
var createJsonResponseHandler2 = (responseSchema) => async ({ response, url, requestBodyValues }) => {
|
|
16546
|
-
const responseBody = await response
|
|
16880
|
+
const responseBody = await readResponseBodyAsText2({ response, url });
|
|
16547
16881
|
const parsedResult = await safeParseJSON3({
|
|
16548
16882
|
text: responseBody,
|
|
16549
16883
|
schema: responseSchema
|
|
@@ -16589,13 +16923,19 @@ var GatewayError2 = class _GatewayError2 extends (_b18 = Error, _a20 = symbol20,
|
|
|
16589
16923
|
message,
|
|
16590
16924
|
statusCode = 500,
|
|
16591
16925
|
cause,
|
|
16592
|
-
generationId
|
|
16926
|
+
generationId,
|
|
16927
|
+
isRetryable = statusCode != null && (statusCode === 408 || // request timeout
|
|
16928
|
+
statusCode === 409 || // conflict
|
|
16929
|
+
statusCode === 429 || // too many requests
|
|
16930
|
+
statusCode >= 500)
|
|
16931
|
+
// server error
|
|
16593
16932
|
}) {
|
|
16594
16933
|
super(generationId ? `${message} [${generationId}]` : message);
|
|
16595
16934
|
this[_a20] = true;
|
|
16596
16935
|
this.statusCode = statusCode;
|
|
16597
16936
|
this.cause = cause;
|
|
16598
16937
|
this.generationId = generationId;
|
|
16938
|
+
this.isRetryable = isRetryable;
|
|
16599
16939
|
}
|
|
16600
16940
|
/**
|
|
16601
16941
|
* Checks if the given error is a Gateway Error.
|
|
@@ -16764,41 +17104,92 @@ var GatewayInternalServerError2 = class extends (_b64 = GatewayError2, _a66 = sy
|
|
|
16764
17104
|
return GatewayError2.hasMarker(error) && symbol66 in error;
|
|
16765
17105
|
}
|
|
16766
17106
|
};
|
|
16767
|
-
var name66 = "
|
|
17107
|
+
var name66 = "GatewayFailedDependencyError";
|
|
16768
17108
|
var marker76 = `vercel.ai.gateway.error.${name66}`;
|
|
16769
17109
|
var symbol76 = Symbol.for(marker76);
|
|
16770
17110
|
var _a76;
|
|
16771
17111
|
var _b74;
|
|
16772
|
-
var
|
|
17112
|
+
var GatewayFailedDependencyError = class extends (_b74 = GatewayError2, _a76 = symbol76, _b74) {
|
|
16773
17113
|
constructor({
|
|
16774
|
-
message = "
|
|
16775
|
-
statusCode =
|
|
16776
|
-
response,
|
|
16777
|
-
validationError,
|
|
17114
|
+
message = "Failed dependency",
|
|
17115
|
+
statusCode = 424,
|
|
16778
17116
|
cause,
|
|
16779
17117
|
generationId
|
|
16780
17118
|
} = {}) {
|
|
16781
17119
|
super({ message, statusCode, cause, generationId });
|
|
16782
17120
|
this[_a76] = true;
|
|
16783
17121
|
this.name = name66;
|
|
16784
|
-
this.type = "
|
|
16785
|
-
this.response = response;
|
|
16786
|
-
this.validationError = validationError;
|
|
17122
|
+
this.type = "failed_dependency";
|
|
16787
17123
|
}
|
|
16788
17124
|
static isInstance(error) {
|
|
16789
17125
|
return GatewayError2.hasMarker(error) && symbol76 in error;
|
|
16790
17126
|
}
|
|
16791
17127
|
};
|
|
16792
|
-
|
|
16793
|
-
|
|
16794
|
-
|
|
16795
|
-
|
|
16796
|
-
|
|
16797
|
-
|
|
16798
|
-
|
|
16799
|
-
|
|
16800
|
-
|
|
16801
|
-
|
|
17128
|
+
var name76 = "GatewayForbiddenError";
|
|
17129
|
+
var marker86 = `vercel.ai.gateway.error.${name76}`;
|
|
17130
|
+
var symbol86 = Symbol.for(marker86);
|
|
17131
|
+
var forbiddenParamSchema = lazySchema2(
|
|
17132
|
+
() => zodSchema3(
|
|
17133
|
+
z$1.object({
|
|
17134
|
+
ruleId: z$1.string()
|
|
17135
|
+
})
|
|
17136
|
+
)
|
|
17137
|
+
);
|
|
17138
|
+
var _a86;
|
|
17139
|
+
var _b84;
|
|
17140
|
+
var GatewayForbiddenError2 = class extends (_b84 = GatewayError2, _a86 = symbol86, _b84) {
|
|
17141
|
+
constructor({
|
|
17142
|
+
message = "Forbidden",
|
|
17143
|
+
statusCode = 403,
|
|
17144
|
+
cause,
|
|
17145
|
+
generationId,
|
|
17146
|
+
ruleId
|
|
17147
|
+
} = {}) {
|
|
17148
|
+
super({ message, statusCode, cause, generationId });
|
|
17149
|
+
this[_a86] = true;
|
|
17150
|
+
this.name = name76;
|
|
17151
|
+
this.type = "forbidden";
|
|
17152
|
+
this.ruleId = ruleId;
|
|
17153
|
+
}
|
|
17154
|
+
static isInstance(error) {
|
|
17155
|
+
return GatewayError2.hasMarker(error) && symbol86 in error;
|
|
17156
|
+
}
|
|
17157
|
+
};
|
|
17158
|
+
var name86 = "GatewayResponseError";
|
|
17159
|
+
var marker96 = `vercel.ai.gateway.error.${name86}`;
|
|
17160
|
+
var symbol96 = Symbol.for(marker96);
|
|
17161
|
+
var _a96;
|
|
17162
|
+
var _b94;
|
|
17163
|
+
var GatewayResponseError2 = class extends (_b94 = GatewayError2, _a96 = symbol96, _b94) {
|
|
17164
|
+
constructor({
|
|
17165
|
+
message = "Invalid response from Gateway",
|
|
17166
|
+
statusCode = 502,
|
|
17167
|
+
response,
|
|
17168
|
+
validationError,
|
|
17169
|
+
cause,
|
|
17170
|
+
generationId
|
|
17171
|
+
} = {}) {
|
|
17172
|
+
super({ message, statusCode, cause, generationId });
|
|
17173
|
+
this[_a96] = true;
|
|
17174
|
+
this.name = name86;
|
|
17175
|
+
this.type = "response_error";
|
|
17176
|
+
this.response = response;
|
|
17177
|
+
this.validationError = validationError;
|
|
17178
|
+
}
|
|
17179
|
+
static isInstance(error) {
|
|
17180
|
+
return GatewayError2.hasMarker(error) && symbol96 in error;
|
|
17181
|
+
}
|
|
17182
|
+
};
|
|
17183
|
+
async function createGatewayErrorFromResponse2({
|
|
17184
|
+
response,
|
|
17185
|
+
statusCode,
|
|
17186
|
+
defaultMessage = "Gateway request failed",
|
|
17187
|
+
cause,
|
|
17188
|
+
authMethod
|
|
17189
|
+
}) {
|
|
17190
|
+
var _a117;
|
|
17191
|
+
const parseResult = await safeValidateTypes3({
|
|
17192
|
+
value: response,
|
|
16802
17193
|
schema: gatewayErrorResponseSchema2
|
|
16803
17194
|
});
|
|
16804
17195
|
if (!parseResult.success) {
|
|
@@ -16815,7 +17206,7 @@ async function createGatewayErrorFromResponse2({
|
|
|
16815
17206
|
const validatedResponse = parseResult.value;
|
|
16816
17207
|
const errorType = validatedResponse.error.type;
|
|
16817
17208
|
const message = validatedResponse.error.message;
|
|
16818
|
-
const generationId = (
|
|
17209
|
+
const generationId = (_a117 = validatedResponse.generationId) != null ? _a117 : void 0;
|
|
16819
17210
|
switch (errorType) {
|
|
16820
17211
|
case "authentication_error":
|
|
16821
17212
|
return GatewayAuthenticationError2.createContextualError({
|
|
@@ -16859,6 +17250,26 @@ async function createGatewayErrorFromResponse2({
|
|
|
16859
17250
|
cause,
|
|
16860
17251
|
generationId
|
|
16861
17252
|
});
|
|
17253
|
+
case "failed_dependency":
|
|
17254
|
+
return new GatewayFailedDependencyError({
|
|
17255
|
+
message,
|
|
17256
|
+
statusCode,
|
|
17257
|
+
cause,
|
|
17258
|
+
generationId
|
|
17259
|
+
});
|
|
17260
|
+
case "forbidden": {
|
|
17261
|
+
const ruleResult = await safeValidateTypes3({
|
|
17262
|
+
value: validatedResponse.error.param,
|
|
17263
|
+
schema: forbiddenParamSchema
|
|
17264
|
+
});
|
|
17265
|
+
return new GatewayForbiddenError2({
|
|
17266
|
+
message,
|
|
17267
|
+
statusCode,
|
|
17268
|
+
cause,
|
|
17269
|
+
generationId,
|
|
17270
|
+
ruleId: ruleResult.success ? ruleResult.value.ruleId : void 0
|
|
17271
|
+
});
|
|
17272
|
+
}
|
|
16862
17273
|
default:
|
|
16863
17274
|
return new GatewayInternalServerError2({
|
|
16864
17275
|
message,
|
|
@@ -16887,19 +17298,19 @@ function extractApiCallResponse2(error) {
|
|
|
16887
17298
|
}
|
|
16888
17299
|
if (error.responseBody != null) {
|
|
16889
17300
|
try {
|
|
16890
|
-
return
|
|
17301
|
+
return secureJsonParse2(error.responseBody);
|
|
16891
17302
|
} catch (e) {
|
|
16892
17303
|
return error.responseBody;
|
|
16893
17304
|
}
|
|
16894
17305
|
}
|
|
16895
17306
|
return {};
|
|
16896
17307
|
}
|
|
16897
|
-
var
|
|
16898
|
-
var
|
|
16899
|
-
var
|
|
16900
|
-
var
|
|
16901
|
-
var
|
|
16902
|
-
var GatewayTimeoutError2 = class _GatewayTimeoutError2 extends (
|
|
17308
|
+
var name96 = "GatewayTimeoutError";
|
|
17309
|
+
var marker106 = `vercel.ai.gateway.error.${name96}`;
|
|
17310
|
+
var symbol106 = Symbol.for(marker106);
|
|
17311
|
+
var _a106;
|
|
17312
|
+
var _b103;
|
|
17313
|
+
var GatewayTimeoutError2 = class _GatewayTimeoutError2 extends (_b103 = GatewayError2, _a106 = symbol106, _b103) {
|
|
16903
17314
|
constructor({
|
|
16904
17315
|
message = "Request timed out",
|
|
16905
17316
|
statusCode = 408,
|
|
@@ -16907,12 +17318,12 @@ var GatewayTimeoutError2 = class _GatewayTimeoutError2 extends (_b84 = GatewayEr
|
|
|
16907
17318
|
generationId
|
|
16908
17319
|
} = {}) {
|
|
16909
17320
|
super({ message, statusCode, cause, generationId });
|
|
16910
|
-
this[
|
|
16911
|
-
this.name =
|
|
17321
|
+
this[_a106] = true;
|
|
17322
|
+
this.name = name96;
|
|
16912
17323
|
this.type = "timeout_error";
|
|
16913
17324
|
}
|
|
16914
17325
|
static isInstance(error) {
|
|
16915
|
-
return GatewayError2.hasMarker(error) &&
|
|
17326
|
+
return GatewayError2.hasMarker(error) && symbol106 in error;
|
|
16916
17327
|
}
|
|
16917
17328
|
/**
|
|
16918
17329
|
* Creates a helpful timeout error message with troubleshooting guidance
|
|
@@ -16950,7 +17361,7 @@ function isTimeoutError2(error) {
|
|
|
16950
17361
|
return false;
|
|
16951
17362
|
}
|
|
16952
17363
|
async function asGatewayError2(error, authMethod) {
|
|
16953
|
-
var
|
|
17364
|
+
var _a117;
|
|
16954
17365
|
if (GatewayError2.isInstance(error)) {
|
|
16955
17366
|
return error;
|
|
16956
17367
|
}
|
|
@@ -16969,7 +17380,7 @@ async function asGatewayError2(error, authMethod) {
|
|
|
16969
17380
|
}
|
|
16970
17381
|
return await createGatewayErrorFromResponse2({
|
|
16971
17382
|
response: extractApiCallResponse2(error),
|
|
16972
|
-
statusCode: (
|
|
17383
|
+
statusCode: (_a117 = error.statusCode) != null ? _a117 : 500,
|
|
16973
17384
|
defaultMessage: "Gateway request failed",
|
|
16974
17385
|
cause: error,
|
|
16975
17386
|
authMethod
|
|
@@ -16999,6 +17410,8 @@ var KNOWN_MODEL_TYPES2 = [
|
|
|
16999
17410
|
"image",
|
|
17000
17411
|
"language",
|
|
17001
17412
|
"reranking",
|
|
17413
|
+
"speech",
|
|
17414
|
+
"transcription",
|
|
17002
17415
|
"video"
|
|
17003
17416
|
];
|
|
17004
17417
|
var GatewayFetchMetadata2 = class {
|
|
@@ -17435,7 +17848,7 @@ var GatewayEmbeddingModel2 = class {
|
|
|
17435
17848
|
abortSignal,
|
|
17436
17849
|
providerOptions
|
|
17437
17850
|
}) {
|
|
17438
|
-
var
|
|
17851
|
+
var _a117, _b113;
|
|
17439
17852
|
const resolvedHeaders = await resolve2(this.config.headers());
|
|
17440
17853
|
try {
|
|
17441
17854
|
const {
|
|
@@ -17466,10 +17879,10 @@ var GatewayEmbeddingModel2 = class {
|
|
|
17466
17879
|
});
|
|
17467
17880
|
return {
|
|
17468
17881
|
embeddings: responseBody.embeddings,
|
|
17469
|
-
usage: (
|
|
17882
|
+
usage: (_a117 = responseBody.usage) != null ? _a117 : void 0,
|
|
17470
17883
|
providerMetadata: responseBody.providerMetadata,
|
|
17471
17884
|
response: { headers: responseHeaders, body: rawValue },
|
|
17472
|
-
warnings: []
|
|
17885
|
+
warnings: (_b113 = responseBody.warnings) != null ? _b113 : []
|
|
17473
17886
|
};
|
|
17474
17887
|
} catch (error) {
|
|
17475
17888
|
throw await asGatewayError2(error, await parseAuthMethod2(resolvedHeaders));
|
|
@@ -17485,15 +17898,37 @@ var GatewayEmbeddingModel2 = class {
|
|
|
17485
17898
|
};
|
|
17486
17899
|
}
|
|
17487
17900
|
};
|
|
17901
|
+
var gatewayEmbeddingWarningSchema = z$1.discriminatedUnion("type", [
|
|
17902
|
+
z$1.object({
|
|
17903
|
+
type: z$1.literal("unsupported"),
|
|
17904
|
+
feature: z$1.string(),
|
|
17905
|
+
details: z$1.string().optional()
|
|
17906
|
+
}),
|
|
17907
|
+
z$1.object({
|
|
17908
|
+
type: z$1.literal("compatibility"),
|
|
17909
|
+
feature: z$1.string(),
|
|
17910
|
+
details: z$1.string().optional()
|
|
17911
|
+
}),
|
|
17912
|
+
z$1.object({
|
|
17913
|
+
type: z$1.literal("other"),
|
|
17914
|
+
message: z$1.string()
|
|
17915
|
+
})
|
|
17916
|
+
]);
|
|
17488
17917
|
var gatewayEmbeddingResponseSchema2 = lazySchema2(
|
|
17489
17918
|
() => zodSchema3(
|
|
17490
17919
|
z$1.object({
|
|
17491
17920
|
embeddings: z$1.array(z$1.array(z$1.number())),
|
|
17492
17921
|
usage: z$1.object({ tokens: z$1.number() }).nullish(),
|
|
17922
|
+
warnings: z$1.array(gatewayEmbeddingWarningSchema).optional(),
|
|
17493
17923
|
providerMetadata: z$1.record(z$1.string(), z$1.record(z$1.string(), z$1.unknown())).optional()
|
|
17494
17924
|
})
|
|
17495
17925
|
)
|
|
17496
17926
|
);
|
|
17927
|
+
function mapGatewayWarnings(warnings) {
|
|
17928
|
+
return (warnings != null ? warnings : []).map(
|
|
17929
|
+
(warning) => warning.type === "deprecated" ? { type: "other", message: warning.message } : warning
|
|
17930
|
+
);
|
|
17931
|
+
}
|
|
17497
17932
|
var GatewayImageModel2 = class {
|
|
17498
17933
|
constructor(modelId, config) {
|
|
17499
17934
|
this.modelId = modelId;
|
|
@@ -17516,7 +17951,7 @@ var GatewayImageModel2 = class {
|
|
|
17516
17951
|
headers,
|
|
17517
17952
|
abortSignal
|
|
17518
17953
|
}) {
|
|
17519
|
-
var
|
|
17954
|
+
var _a117, _b113, _c;
|
|
17520
17955
|
const resolvedHeaders = await resolve2(this.config.headers());
|
|
17521
17956
|
try {
|
|
17522
17957
|
const {
|
|
@@ -17555,7 +17990,7 @@ var GatewayImageModel2 = class {
|
|
|
17555
17990
|
return {
|
|
17556
17991
|
images: responseBody.images,
|
|
17557
17992
|
// Always base64 strings from server
|
|
17558
|
-
warnings: (
|
|
17993
|
+
warnings: mapGatewayWarnings(responseBody.warnings),
|
|
17559
17994
|
providerMetadata: responseBody.providerMetadata,
|
|
17560
17995
|
response: {
|
|
17561
17996
|
timestamp: /* @__PURE__ */ new Date(),
|
|
@@ -17564,9 +17999,9 @@ var GatewayImageModel2 = class {
|
|
|
17564
17999
|
},
|
|
17565
18000
|
...responseBody.usage != null && {
|
|
17566
18001
|
usage: {
|
|
17567
|
-
inputTokens: (
|
|
17568
|
-
outputTokens: (
|
|
17569
|
-
totalTokens: (
|
|
18002
|
+
inputTokens: (_a117 = responseBody.usage.inputTokens) != null ? _a117 : void 0,
|
|
18003
|
+
outputTokens: (_b113 = responseBody.usage.outputTokens) != null ? _b113 : void 0,
|
|
18004
|
+
totalTokens: (_c = responseBody.usage.totalTokens) != null ? _c : void 0
|
|
17570
18005
|
}
|
|
17571
18006
|
}
|
|
17572
18007
|
};
|
|
@@ -17607,6 +18042,11 @@ var gatewayImageWarningSchema = z$1.discriminatedUnion("type", [
|
|
|
17607
18042
|
feature: z$1.string(),
|
|
17608
18043
|
details: z$1.string().optional()
|
|
17609
18044
|
}),
|
|
18045
|
+
z$1.object({
|
|
18046
|
+
type: z$1.literal("deprecated"),
|
|
18047
|
+
setting: z$1.string(),
|
|
18048
|
+
message: z$1.string()
|
|
18049
|
+
}),
|
|
17610
18050
|
z$1.object({
|
|
17611
18051
|
type: z$1.literal("other"),
|
|
17612
18052
|
message: z$1.string()
|
|
@@ -17642,12 +18082,14 @@ var GatewayVideoModel = class {
|
|
|
17642
18082
|
duration,
|
|
17643
18083
|
fps,
|
|
17644
18084
|
seed,
|
|
18085
|
+
generateAudio,
|
|
17645
18086
|
image,
|
|
18087
|
+
frameImages,
|
|
18088
|
+
inputReferences,
|
|
17646
18089
|
providerOptions,
|
|
17647
18090
|
headers,
|
|
17648
18091
|
abortSignal
|
|
17649
18092
|
}) {
|
|
17650
|
-
var _a932;
|
|
17651
18093
|
const resolvedHeaders = await resolve2(this.config.headers());
|
|
17652
18094
|
try {
|
|
17653
18095
|
const { responseHeaders, value: responseBody } = await postJsonToApi2({
|
|
@@ -17667,8 +18109,20 @@ var GatewayVideoModel = class {
|
|
|
17667
18109
|
...duration && { duration },
|
|
17668
18110
|
...fps && { fps },
|
|
17669
18111
|
...seed && { seed },
|
|
18112
|
+
...generateAudio !== void 0 && { generateAudio },
|
|
17670
18113
|
...providerOptions && { providerOptions },
|
|
17671
|
-
...image && { image: maybeEncodeVideoFile(image) }
|
|
18114
|
+
...image && { image: maybeEncodeVideoFile(image) },
|
|
18115
|
+
...frameImages && {
|
|
18116
|
+
frameImages: frameImages.map((frame) => ({
|
|
18117
|
+
...frame,
|
|
18118
|
+
image: maybeEncodeVideoFile(frame.image)
|
|
18119
|
+
}))
|
|
18120
|
+
},
|
|
18121
|
+
...inputReferences && {
|
|
18122
|
+
inputReferences: inputReferences.map(
|
|
18123
|
+
(reference) => maybeEncodeVideoFile(reference)
|
|
18124
|
+
)
|
|
18125
|
+
}
|
|
17672
18126
|
},
|
|
17673
18127
|
successfulResponseHandler: async ({
|
|
17674
18128
|
response,
|
|
@@ -17743,7 +18197,7 @@ var GatewayVideoModel = class {
|
|
|
17743
18197
|
});
|
|
17744
18198
|
return {
|
|
17745
18199
|
videos: responseBody.videos,
|
|
17746
|
-
warnings: (
|
|
18200
|
+
warnings: mapGatewayWarnings(responseBody.warnings),
|
|
17747
18201
|
providerMetadata: responseBody.providerMetadata,
|
|
17748
18202
|
response: {
|
|
17749
18203
|
timestamp: /* @__PURE__ */ new Date(),
|
|
@@ -17800,6 +18254,11 @@ var gatewayVideoWarningSchema = z$1.discriminatedUnion("type", [
|
|
|
17800
18254
|
feature: z$1.string(),
|
|
17801
18255
|
details: z$1.string().optional()
|
|
17802
18256
|
}),
|
|
18257
|
+
z$1.object({
|
|
18258
|
+
type: z$1.literal("deprecated"),
|
|
18259
|
+
setting: z$1.string(),
|
|
18260
|
+
message: z$1.string()
|
|
18261
|
+
}),
|
|
17803
18262
|
z$1.object({
|
|
17804
18263
|
type: z$1.literal("other"),
|
|
17805
18264
|
message: z$1.string()
|
|
@@ -17837,6 +18296,7 @@ var GatewayRerankingModel = class {
|
|
|
17837
18296
|
abortSignal,
|
|
17838
18297
|
providerOptions
|
|
17839
18298
|
}) {
|
|
18299
|
+
var _a117;
|
|
17840
18300
|
const resolvedHeaders = await resolve2(this.config.headers());
|
|
17841
18301
|
try {
|
|
17842
18302
|
const {
|
|
@@ -17871,7 +18331,7 @@ var GatewayRerankingModel = class {
|
|
|
17871
18331
|
ranking: responseBody.ranking,
|
|
17872
18332
|
providerMetadata: responseBody.providerMetadata,
|
|
17873
18333
|
response: { headers: responseHeaders, body: rawValue },
|
|
17874
|
-
warnings: []
|
|
18334
|
+
warnings: (_a117 = responseBody.warnings) != null ? _a117 : []
|
|
17875
18335
|
};
|
|
17876
18336
|
} catch (error) {
|
|
17877
18337
|
throw await asGatewayError2(error, await parseAuthMethod2(resolvedHeaders));
|
|
@@ -17887,6 +18347,22 @@ var GatewayRerankingModel = class {
|
|
|
17887
18347
|
};
|
|
17888
18348
|
}
|
|
17889
18349
|
};
|
|
18350
|
+
var gatewayRerankingWarningSchema = z$1.discriminatedUnion("type", [
|
|
18351
|
+
z$1.object({
|
|
18352
|
+
type: z$1.literal("unsupported"),
|
|
18353
|
+
feature: z$1.string(),
|
|
18354
|
+
details: z$1.string().optional()
|
|
18355
|
+
}),
|
|
18356
|
+
z$1.object({
|
|
18357
|
+
type: z$1.literal("compatibility"),
|
|
18358
|
+
feature: z$1.string(),
|
|
18359
|
+
details: z$1.string().optional()
|
|
18360
|
+
}),
|
|
18361
|
+
z$1.object({
|
|
18362
|
+
type: z$1.literal("other"),
|
|
18363
|
+
message: z$1.string()
|
|
18364
|
+
})
|
|
18365
|
+
]);
|
|
17890
18366
|
var gatewayRerankingResponseSchema = lazySchema2(
|
|
17891
18367
|
() => zodSchema3(
|
|
17892
18368
|
z$1.object({
|
|
@@ -17896,156 +18372,507 @@ var gatewayRerankingResponseSchema = lazySchema2(
|
|
|
17896
18372
|
relevanceScore: z$1.number()
|
|
17897
18373
|
})
|
|
17898
18374
|
),
|
|
18375
|
+
warnings: z$1.array(gatewayRerankingWarningSchema).optional(),
|
|
17899
18376
|
providerMetadata: z$1.record(z$1.string(), z$1.record(z$1.string(), z$1.unknown())).optional()
|
|
17900
18377
|
})
|
|
17901
18378
|
)
|
|
17902
18379
|
);
|
|
17903
|
-
var
|
|
17904
|
-
()
|
|
17905
|
-
|
|
17906
|
-
|
|
17907
|
-
|
|
17908
|
-
|
|
17909
|
-
|
|
17910
|
-
|
|
17911
|
-
|
|
17912
|
-
|
|
17913
|
-
|
|
17914
|
-
|
|
17915
|
-
|
|
17916
|
-
|
|
17917
|
-
|
|
17918
|
-
|
|
17919
|
-
|
|
17920
|
-
|
|
17921
|
-
|
|
17922
|
-
|
|
17923
|
-
|
|
17924
|
-
|
|
17925
|
-
|
|
17926
|
-
|
|
17927
|
-
|
|
17928
|
-
|
|
17929
|
-
|
|
17930
|
-
|
|
17931
|
-
|
|
17932
|
-
|
|
17933
|
-
|
|
17934
|
-
|
|
17935
|
-
|
|
17936
|
-
|
|
17937
|
-
|
|
17938
|
-
|
|
17939
|
-
|
|
17940
|
-
|
|
17941
|
-
|
|
17942
|
-
|
|
17943
|
-
|
|
17944
|
-
|
|
17945
|
-
|
|
17946
|
-
|
|
17947
|
-
|
|
17948
|
-
|
|
17949
|
-
|
|
17950
|
-
|
|
17951
|
-
|
|
17952
|
-
|
|
17953
|
-
|
|
17954
|
-
|
|
17955
|
-
|
|
17956
|
-
|
|
17957
|
-
|
|
17958
|
-
|
|
17959
|
-
|
|
17960
|
-
|
|
17961
|
-
|
|
17962
|
-
|
|
17963
|
-
|
|
17964
|
-
|
|
17965
|
-
|
|
17966
|
-
|
|
17967
|
-
|
|
17968
|
-
|
|
17969
|
-
|
|
17970
|
-
)
|
|
17971
|
-
|
|
17972
|
-
|
|
17973
|
-
|
|
17974
|
-
|
|
17975
|
-
}
|
|
17976
|
-
|
|
17977
|
-
|
|
17978
|
-
|
|
17979
|
-
|
|
17980
|
-
|
|
17981
|
-
|
|
17982
|
-
|
|
17983
|
-
|
|
17984
|
-
|
|
17985
|
-
|
|
17986
|
-
|
|
17987
|
-
|
|
17988
|
-
|
|
17989
|
-
|
|
17990
|
-
|
|
17991
|
-
|
|
17992
|
-
|
|
17993
|
-
|
|
17994
|
-
|
|
17995
|
-
|
|
17996
|
-
|
|
17997
|
-
|
|
17998
|
-
|
|
17999
|
-
|
|
18000
|
-
|
|
18001
|
-
|
|
18002
|
-
|
|
18003
|
-
|
|
18004
|
-
|
|
18005
|
-
|
|
18006
|
-
|
|
18007
|
-
|
|
18008
|
-
|
|
18009
|
-
|
|
18010
|
-
|
|
18011
|
-
|
|
18012
|
-
|
|
18013
|
-
|
|
18014
|
-
|
|
18015
|
-
|
|
18016
|
-
|
|
18017
|
-
)
|
|
18018
|
-
|
|
18019
|
-
|
|
18020
|
-
|
|
18021
|
-
|
|
18022
|
-
|
|
18023
|
-
|
|
18024
|
-
|
|
18025
|
-
|
|
18026
|
-
|
|
18027
|
-
|
|
18028
|
-
|
|
18029
|
-
|
|
18030
|
-
|
|
18031
|
-
|
|
18032
|
-
|
|
18033
|
-
|
|
18034
|
-
}
|
|
18035
|
-
|
|
18036
|
-
|
|
18037
|
-
|
|
18038
|
-
|
|
18039
|
-
|
|
18040
|
-
|
|
18041
|
-
|
|
18042
|
-
|
|
18043
|
-
|
|
18044
|
-
|
|
18045
|
-
|
|
18046
|
-
|
|
18047
|
-
|
|
18048
|
-
|
|
18380
|
+
var GatewaySpeechModel = class {
|
|
18381
|
+
constructor(modelId, config) {
|
|
18382
|
+
this.modelId = modelId;
|
|
18383
|
+
this.config = config;
|
|
18384
|
+
this.specificationVersion = "v3";
|
|
18385
|
+
}
|
|
18386
|
+
get provider() {
|
|
18387
|
+
return this.config.provider;
|
|
18388
|
+
}
|
|
18389
|
+
async doGenerate({
|
|
18390
|
+
text: text4,
|
|
18391
|
+
voice,
|
|
18392
|
+
outputFormat,
|
|
18393
|
+
instructions,
|
|
18394
|
+
speed,
|
|
18395
|
+
language,
|
|
18396
|
+
providerOptions,
|
|
18397
|
+
headers,
|
|
18398
|
+
abortSignal
|
|
18399
|
+
}) {
|
|
18400
|
+
const resolvedHeaders = await resolve2(this.config.headers());
|
|
18401
|
+
try {
|
|
18402
|
+
const {
|
|
18403
|
+
responseHeaders,
|
|
18404
|
+
value: responseBody,
|
|
18405
|
+
rawValue
|
|
18406
|
+
} = await postJsonToApi2({
|
|
18407
|
+
url: this.getUrl(),
|
|
18408
|
+
headers: combineHeaders2(
|
|
18409
|
+
resolvedHeaders,
|
|
18410
|
+
headers != null ? headers : {},
|
|
18411
|
+
this.getModelConfigHeaders(),
|
|
18412
|
+
await resolve2(this.config.o11yHeaders)
|
|
18413
|
+
),
|
|
18414
|
+
body: {
|
|
18415
|
+
text: text4,
|
|
18416
|
+
...voice && { voice },
|
|
18417
|
+
...outputFormat && { outputFormat },
|
|
18418
|
+
...instructions && { instructions },
|
|
18419
|
+
...speed != null && { speed },
|
|
18420
|
+
...language && { language },
|
|
18421
|
+
...providerOptions && { providerOptions }
|
|
18422
|
+
},
|
|
18423
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
18424
|
+
gatewaySpeechResponseSchema
|
|
18425
|
+
),
|
|
18426
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
18427
|
+
errorSchema: z$1.any(),
|
|
18428
|
+
errorToMessage: (data) => data
|
|
18429
|
+
}),
|
|
18430
|
+
...abortSignal && { abortSignal },
|
|
18431
|
+
fetch: this.config.fetch
|
|
18432
|
+
});
|
|
18433
|
+
return {
|
|
18434
|
+
audio: responseBody.audio,
|
|
18435
|
+
warnings: mapGatewayWarnings(responseBody.warnings),
|
|
18436
|
+
providerMetadata: responseBody.providerMetadata,
|
|
18437
|
+
response: {
|
|
18438
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
18439
|
+
modelId: this.modelId,
|
|
18440
|
+
headers: responseHeaders,
|
|
18441
|
+
body: rawValue
|
|
18442
|
+
}
|
|
18443
|
+
};
|
|
18444
|
+
} catch (error) {
|
|
18445
|
+
throw await asGatewayError2(
|
|
18446
|
+
error,
|
|
18447
|
+
await parseAuthMethod2(resolvedHeaders != null ? resolvedHeaders : {})
|
|
18448
|
+
);
|
|
18449
|
+
}
|
|
18450
|
+
}
|
|
18451
|
+
getUrl() {
|
|
18452
|
+
return `${this.config.baseURL}/speech-model`;
|
|
18453
|
+
}
|
|
18454
|
+
getModelConfigHeaders() {
|
|
18455
|
+
return {
|
|
18456
|
+
"ai-speech-model-specification-version": "3",
|
|
18457
|
+
"ai-model-id": this.modelId
|
|
18458
|
+
};
|
|
18459
|
+
}
|
|
18460
|
+
};
|
|
18461
|
+
var providerMetadataEntrySchema3 = z$1.object({}).catchall(z$1.unknown());
|
|
18462
|
+
var gatewaySpeechWarningSchema = z$1.discriminatedUnion("type", [
|
|
18463
|
+
z$1.object({
|
|
18464
|
+
type: z$1.literal("unsupported"),
|
|
18465
|
+
feature: z$1.string(),
|
|
18466
|
+
details: z$1.string().optional()
|
|
18467
|
+
}),
|
|
18468
|
+
z$1.object({
|
|
18469
|
+
type: z$1.literal("compatibility"),
|
|
18470
|
+
feature: z$1.string(),
|
|
18471
|
+
details: z$1.string().optional()
|
|
18472
|
+
}),
|
|
18473
|
+
z$1.object({
|
|
18474
|
+
type: z$1.literal("deprecated"),
|
|
18475
|
+
setting: z$1.string(),
|
|
18476
|
+
message: z$1.string()
|
|
18477
|
+
}),
|
|
18478
|
+
z$1.object({
|
|
18479
|
+
type: z$1.literal("other"),
|
|
18480
|
+
message: z$1.string()
|
|
18481
|
+
})
|
|
18482
|
+
]);
|
|
18483
|
+
var gatewaySpeechResponseSchema = z$1.object({
|
|
18484
|
+
audio: z$1.string(),
|
|
18485
|
+
warnings: z$1.array(gatewaySpeechWarningSchema).optional(),
|
|
18486
|
+
providerMetadata: z$1.record(z$1.string(), providerMetadataEntrySchema3).optional()
|
|
18487
|
+
});
|
|
18488
|
+
var GatewayTranscriptionModel = class {
|
|
18489
|
+
constructor(modelId, config) {
|
|
18490
|
+
this.modelId = modelId;
|
|
18491
|
+
this.config = config;
|
|
18492
|
+
this.specificationVersion = "v3";
|
|
18493
|
+
}
|
|
18494
|
+
get provider() {
|
|
18495
|
+
return this.config.provider;
|
|
18496
|
+
}
|
|
18497
|
+
async doGenerate({
|
|
18498
|
+
audio,
|
|
18499
|
+
mediaType,
|
|
18500
|
+
providerOptions,
|
|
18501
|
+
headers,
|
|
18502
|
+
abortSignal
|
|
18503
|
+
}) {
|
|
18504
|
+
var _a117, _b113, _c;
|
|
18505
|
+
const resolvedHeaders = await resolve2(this.config.headers());
|
|
18506
|
+
try {
|
|
18507
|
+
const {
|
|
18508
|
+
responseHeaders,
|
|
18509
|
+
value: responseBody,
|
|
18510
|
+
rawValue
|
|
18511
|
+
} = await postJsonToApi2({
|
|
18512
|
+
url: this.getUrl(),
|
|
18513
|
+
headers: combineHeaders2(
|
|
18514
|
+
resolvedHeaders,
|
|
18515
|
+
headers != null ? headers : {},
|
|
18516
|
+
this.getModelConfigHeaders(),
|
|
18517
|
+
await resolve2(this.config.o11yHeaders)
|
|
18518
|
+
),
|
|
18519
|
+
body: {
|
|
18520
|
+
audio: audio instanceof Uint8Array ? convertUint8ArrayToBase643(audio) : audio,
|
|
18521
|
+
mediaType,
|
|
18522
|
+
...providerOptions && { providerOptions }
|
|
18523
|
+
},
|
|
18524
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
18525
|
+
gatewayTranscriptionResponseSchema
|
|
18526
|
+
),
|
|
18527
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
18528
|
+
errorSchema: z$1.any(),
|
|
18529
|
+
errorToMessage: (data) => data
|
|
18530
|
+
}),
|
|
18531
|
+
...abortSignal && { abortSignal },
|
|
18532
|
+
fetch: this.config.fetch
|
|
18533
|
+
});
|
|
18534
|
+
return {
|
|
18535
|
+
text: responseBody.text,
|
|
18536
|
+
segments: (_a117 = responseBody.segments) != null ? _a117 : [],
|
|
18537
|
+
language: (_b113 = responseBody.language) != null ? _b113 : void 0,
|
|
18538
|
+
durationInSeconds: (_c = responseBody.durationInSeconds) != null ? _c : void 0,
|
|
18539
|
+
warnings: mapGatewayWarnings(responseBody.warnings),
|
|
18540
|
+
providerMetadata: responseBody.providerMetadata,
|
|
18541
|
+
response: {
|
|
18542
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
18543
|
+
modelId: this.modelId,
|
|
18544
|
+
headers: responseHeaders,
|
|
18545
|
+
body: rawValue
|
|
18546
|
+
}
|
|
18547
|
+
};
|
|
18548
|
+
} catch (error) {
|
|
18549
|
+
throw await asGatewayError2(
|
|
18550
|
+
error,
|
|
18551
|
+
await parseAuthMethod2(resolvedHeaders != null ? resolvedHeaders : {})
|
|
18552
|
+
);
|
|
18553
|
+
}
|
|
18554
|
+
}
|
|
18555
|
+
getUrl() {
|
|
18556
|
+
return `${this.config.baseURL}/transcription-model`;
|
|
18557
|
+
}
|
|
18558
|
+
getModelConfigHeaders() {
|
|
18559
|
+
return {
|
|
18560
|
+
"ai-transcription-model-specification-version": "3",
|
|
18561
|
+
"ai-model-id": this.modelId
|
|
18562
|
+
};
|
|
18563
|
+
}
|
|
18564
|
+
};
|
|
18565
|
+
var providerMetadataEntrySchema4 = z$1.object({}).catchall(z$1.unknown());
|
|
18566
|
+
var gatewayTranscriptionWarningSchema = z$1.discriminatedUnion("type", [
|
|
18567
|
+
z$1.object({
|
|
18568
|
+
type: z$1.literal("unsupported"),
|
|
18569
|
+
feature: z$1.string(),
|
|
18570
|
+
details: z$1.string().optional()
|
|
18571
|
+
}),
|
|
18572
|
+
z$1.object({
|
|
18573
|
+
type: z$1.literal("compatibility"),
|
|
18574
|
+
feature: z$1.string(),
|
|
18575
|
+
details: z$1.string().optional()
|
|
18576
|
+
}),
|
|
18577
|
+
z$1.object({
|
|
18578
|
+
type: z$1.literal("deprecated"),
|
|
18579
|
+
setting: z$1.string(),
|
|
18580
|
+
message: z$1.string()
|
|
18581
|
+
}),
|
|
18582
|
+
z$1.object({
|
|
18583
|
+
type: z$1.literal("other"),
|
|
18584
|
+
message: z$1.string()
|
|
18585
|
+
})
|
|
18586
|
+
]);
|
|
18587
|
+
var gatewayTranscriptionResponseSchema = z$1.object({
|
|
18588
|
+
text: z$1.string(),
|
|
18589
|
+
segments: z$1.array(
|
|
18590
|
+
z$1.object({
|
|
18591
|
+
text: z$1.string(),
|
|
18592
|
+
startSecond: z$1.number(),
|
|
18593
|
+
endSecond: z$1.number()
|
|
18594
|
+
})
|
|
18595
|
+
).optional(),
|
|
18596
|
+
language: z$1.string().nullish(),
|
|
18597
|
+
durationInSeconds: z$1.number().nullish(),
|
|
18598
|
+
warnings: z$1.array(gatewayTranscriptionWarningSchema).optional(),
|
|
18599
|
+
providerMetadata: z$1.record(z$1.string(), providerMetadataEntrySchema4).optional()
|
|
18600
|
+
});
|
|
18601
|
+
var exaSearchInputSchema = lazySchema2(
|
|
18602
|
+
() => zodSchema3(
|
|
18603
|
+
z.object({
|
|
18604
|
+
query: z.string().describe("Natural-language web search query. This is required."),
|
|
18605
|
+
type: z.enum(["auto", "fast", "instant"]).optional().describe(
|
|
18606
|
+
"Search method. Use auto for the default balance of speed and quality."
|
|
18607
|
+
),
|
|
18608
|
+
num_results: z.number().optional().describe("Maximum number of results to return (1-100, default: 10)."),
|
|
18609
|
+
category: z.enum([
|
|
18610
|
+
"company",
|
|
18611
|
+
"people",
|
|
18612
|
+
"research paper",
|
|
18613
|
+
"news",
|
|
18614
|
+
"personal site",
|
|
18615
|
+
"financial report"
|
|
18616
|
+
]).optional().describe("Optional content category to focus results."),
|
|
18617
|
+
user_location: z.string().optional().describe("Two-letter ISO country code such as 'US'."),
|
|
18618
|
+
include_domains: z.array(z.string()).optional().describe("Only return results from these domains."),
|
|
18619
|
+
exclude_domains: z.array(z.string()).optional().describe("Exclude results from these domains."),
|
|
18620
|
+
start_published_date: z.string().optional().describe("Only return links published after this ISO 8601 date."),
|
|
18621
|
+
end_published_date: z.string().optional().describe("Only return links published before this ISO 8601 date."),
|
|
18622
|
+
contents: z.object({
|
|
18623
|
+
text: z.union([
|
|
18624
|
+
z.boolean(),
|
|
18625
|
+
z.object({
|
|
18626
|
+
max_characters: z.number().optional(),
|
|
18627
|
+
include_html_tags: z.boolean().optional(),
|
|
18628
|
+
verbosity: z.enum(["compact", "standard", "full"]).optional(),
|
|
18629
|
+
include_sections: z.array(
|
|
18630
|
+
z.enum([
|
|
18631
|
+
"header",
|
|
18632
|
+
"navigation",
|
|
18633
|
+
"banner",
|
|
18634
|
+
"body",
|
|
18635
|
+
"sidebar",
|
|
18636
|
+
"footer",
|
|
18637
|
+
"metadata"
|
|
18638
|
+
])
|
|
18639
|
+
).optional(),
|
|
18640
|
+
exclude_sections: z.array(
|
|
18641
|
+
z.enum([
|
|
18642
|
+
"header",
|
|
18643
|
+
"navigation",
|
|
18644
|
+
"banner",
|
|
18645
|
+
"body",
|
|
18646
|
+
"sidebar",
|
|
18647
|
+
"footer",
|
|
18648
|
+
"metadata"
|
|
18649
|
+
])
|
|
18650
|
+
).optional()
|
|
18651
|
+
})
|
|
18652
|
+
]).optional(),
|
|
18653
|
+
highlights: z.union([
|
|
18654
|
+
z.boolean(),
|
|
18655
|
+
z.object({
|
|
18656
|
+
query: z.string().optional(),
|
|
18657
|
+
max_characters: z.number().optional()
|
|
18658
|
+
})
|
|
18659
|
+
]).optional(),
|
|
18660
|
+
max_age_hours: z.number().optional(),
|
|
18661
|
+
livecrawl_timeout: z.number().optional(),
|
|
18662
|
+
subpages: z.number().optional(),
|
|
18663
|
+
subpage_target: z.union([z.string(), z.array(z.string())]).optional(),
|
|
18664
|
+
extras: z.object({
|
|
18665
|
+
links: z.number().optional(),
|
|
18666
|
+
image_links: z.number().optional()
|
|
18667
|
+
}).optional()
|
|
18668
|
+
}).optional().describe("Controls extracted page content and freshness.")
|
|
18669
|
+
})
|
|
18670
|
+
)
|
|
18671
|
+
);
|
|
18672
|
+
var exaSearchOutputSchema = lazySchema2(
|
|
18673
|
+
() => zodSchema3(
|
|
18674
|
+
z.union([
|
|
18675
|
+
z.object({
|
|
18676
|
+
requestId: z.string(),
|
|
18677
|
+
searchType: z.string().optional(),
|
|
18678
|
+
resolvedSearchType: z.string().optional(),
|
|
18679
|
+
results: z.array(
|
|
18680
|
+
z.object({
|
|
18681
|
+
title: z.string(),
|
|
18682
|
+
url: z.string(),
|
|
18683
|
+
id: z.string(),
|
|
18684
|
+
publishedDate: z.string().nullable().optional(),
|
|
18685
|
+
author: z.string().nullable().optional(),
|
|
18686
|
+
image: z.string().nullable().optional(),
|
|
18687
|
+
favicon: z.string().nullable().optional(),
|
|
18688
|
+
text: z.string().optional(),
|
|
18689
|
+
highlights: z.array(z.string()).optional(),
|
|
18690
|
+
highlightScores: z.array(z.number()).optional(),
|
|
18691
|
+
summary: z.string().optional(),
|
|
18692
|
+
subpages: z.array(z.any()).optional(),
|
|
18693
|
+
extras: z.object({
|
|
18694
|
+
links: z.array(z.string()).optional(),
|
|
18695
|
+
imageLinks: z.array(z.string()).optional()
|
|
18696
|
+
}).optional()
|
|
18697
|
+
})
|
|
18698
|
+
),
|
|
18699
|
+
costDollars: z.object({
|
|
18700
|
+
total: z.number().optional(),
|
|
18701
|
+
search: z.record(z.number()).optional()
|
|
18702
|
+
}).optional()
|
|
18703
|
+
}),
|
|
18704
|
+
z.object({
|
|
18705
|
+
error: z.enum([
|
|
18706
|
+
"api_error",
|
|
18707
|
+
"rate_limit",
|
|
18708
|
+
"timeout",
|
|
18709
|
+
"invalid_input",
|
|
18710
|
+
"configuration_error",
|
|
18711
|
+
"execution_error",
|
|
18712
|
+
"unknown"
|
|
18713
|
+
]),
|
|
18714
|
+
statusCode: z.number().optional(),
|
|
18715
|
+
message: z.string()
|
|
18716
|
+
})
|
|
18717
|
+
])
|
|
18718
|
+
)
|
|
18719
|
+
);
|
|
18720
|
+
var exaSearchToolFactory = createProviderToolFactoryWithOutputSchema({
|
|
18721
|
+
id: "gateway.exa_search",
|
|
18722
|
+
inputSchema: exaSearchInputSchema,
|
|
18723
|
+
outputSchema: exaSearchOutputSchema
|
|
18724
|
+
});
|
|
18725
|
+
var exaSearch = (config = {}) => exaSearchToolFactory(config);
|
|
18726
|
+
var parallelSearchInputSchema2 = lazySchema2(
|
|
18727
|
+
() => zodSchema3(
|
|
18728
|
+
z.object({
|
|
18729
|
+
objective: z.string().describe(
|
|
18730
|
+
"Natural-language description of the web research goal, including source or freshness guidance and broader context from the task. Maximum 5000 characters."
|
|
18731
|
+
),
|
|
18732
|
+
search_queries: z.array(z.string()).optional().describe(
|
|
18733
|
+
"Optional search queries to supplement the objective. Maximum 200 characters per query."
|
|
18734
|
+
),
|
|
18735
|
+
mode: z.enum(["one-shot", "agentic"]).optional().describe(
|
|
18736
|
+
'Mode preset: "one-shot" for comprehensive results with longer excerpts (default), "agentic" for concise, token-efficient results for multi-step workflows.'
|
|
18737
|
+
),
|
|
18738
|
+
max_results: z.number().optional().describe(
|
|
18739
|
+
"Maximum number of results to return (1-20). Defaults to 10 if not specified."
|
|
18740
|
+
),
|
|
18741
|
+
source_policy: z.object({
|
|
18742
|
+
include_domains: z.array(z.string()).optional().describe(
|
|
18743
|
+
"Limit results to these domains. Use plain domain names only \u2014 e.g. example.com or sub.example.gov, or a bare extension like .edu. Do not include a scheme, path, or port (e.g. not https://example.com/page)."
|
|
18744
|
+
),
|
|
18745
|
+
exclude_domains: z.array(z.string()).optional().describe(
|
|
18746
|
+
"Exclude results from these domains. Use plain domain names only \u2014 e.g. example.com or sub.example.gov, or a bare extension like .edu. Do not include a scheme, path, or port (e.g. not https://example.com/page)."
|
|
18747
|
+
),
|
|
18748
|
+
after_date: z.string().optional().describe(
|
|
18749
|
+
"Only include results published after this date. Use an ISO 8601 calendar date formatted YYYY-MM-DD (e.g. 2025-01-01); do not include a time."
|
|
18750
|
+
)
|
|
18751
|
+
}).optional().describe(
|
|
18752
|
+
"Source policy for controlling which domains to include/exclude and freshness."
|
|
18753
|
+
),
|
|
18754
|
+
excerpts: z.object({
|
|
18755
|
+
max_chars_per_result: z.number().optional().describe("Maximum characters per result."),
|
|
18756
|
+
max_chars_total: z.number().optional().describe("Maximum total characters across all results.")
|
|
18757
|
+
}).optional().describe("Excerpt configuration for controlling result length."),
|
|
18758
|
+
fetch_policy: z.object({
|
|
18759
|
+
max_age_seconds: z.number().optional().describe(
|
|
18760
|
+
"Maximum age in seconds for cached content. Set to 0 to always fetch fresh content."
|
|
18761
|
+
)
|
|
18762
|
+
}).optional().describe("Fetch policy for controlling content freshness.")
|
|
18763
|
+
})
|
|
18764
|
+
)
|
|
18765
|
+
);
|
|
18766
|
+
var parallelSearchOutputSchema2 = lazySchema2(
|
|
18767
|
+
() => zodSchema3(
|
|
18768
|
+
z.union([
|
|
18769
|
+
// Success response
|
|
18770
|
+
z.object({
|
|
18771
|
+
searchId: z.string(),
|
|
18772
|
+
results: z.array(
|
|
18773
|
+
z.object({
|
|
18774
|
+
url: z.string(),
|
|
18775
|
+
title: z.string(),
|
|
18776
|
+
excerpt: z.string(),
|
|
18777
|
+
publishDate: z.string().nullable().optional(),
|
|
18778
|
+
relevanceScore: z.number().optional()
|
|
18779
|
+
})
|
|
18780
|
+
)
|
|
18781
|
+
}),
|
|
18782
|
+
// Error response
|
|
18783
|
+
z.object({
|
|
18784
|
+
error: z.enum([
|
|
18785
|
+
"api_error",
|
|
18786
|
+
"rate_limit",
|
|
18787
|
+
"timeout",
|
|
18788
|
+
"invalid_input",
|
|
18789
|
+
"configuration_error",
|
|
18790
|
+
"unknown"
|
|
18791
|
+
]),
|
|
18792
|
+
statusCode: z.number().optional(),
|
|
18793
|
+
message: z.string()
|
|
18794
|
+
})
|
|
18795
|
+
])
|
|
18796
|
+
)
|
|
18797
|
+
);
|
|
18798
|
+
var parallelSearchToolFactory2 = createProviderToolFactoryWithOutputSchema({
|
|
18799
|
+
id: "gateway.parallel_search",
|
|
18800
|
+
inputSchema: parallelSearchInputSchema2,
|
|
18801
|
+
outputSchema: parallelSearchOutputSchema2
|
|
18802
|
+
});
|
|
18803
|
+
var parallelSearch2 = (config = {}) => parallelSearchToolFactory2(config);
|
|
18804
|
+
var perplexitySearchInputSchema2 = lazySchema2(
|
|
18805
|
+
() => zodSchema3(
|
|
18806
|
+
z.object({
|
|
18807
|
+
query: z.union([z.string(), z.array(z.string())]).describe(
|
|
18808
|
+
"Search query (string) or multiple queries (array of up to 5 strings). Multi-query searches return combined results from all queries."
|
|
18809
|
+
),
|
|
18810
|
+
max_results: z.number().optional().describe(
|
|
18811
|
+
"Maximum number of search results to return (1-20, default: 10)"
|
|
18812
|
+
),
|
|
18813
|
+
max_tokens_per_page: z.number().optional().describe(
|
|
18814
|
+
"Maximum number of tokens to extract per search result page (256-2048, default: 2048)"
|
|
18815
|
+
),
|
|
18816
|
+
max_tokens: z.number().optional().describe(
|
|
18817
|
+
"Maximum total tokens across all search results (default: 25000, max: 1000000)"
|
|
18818
|
+
),
|
|
18819
|
+
country: z.string().optional().describe(
|
|
18820
|
+
"Two-letter ISO 3166-1 alpha-2 country code for regional search results (e.g., 'US', 'GB', 'FR')"
|
|
18821
|
+
),
|
|
18822
|
+
search_domain_filter: z.array(z.string()).optional().describe(
|
|
18823
|
+
"List of domains to include or exclude from search results (max 20). To include: ['nature.com', 'science.org']. To exclude: ['-example.com', '-spam.net']"
|
|
18824
|
+
),
|
|
18825
|
+
search_language_filter: z.array(z.string()).optional().describe(
|
|
18826
|
+
"List of ISO 639-1 language codes to filter results (max 10, lowercase). Examples: ['en', 'fr', 'de']"
|
|
18827
|
+
),
|
|
18828
|
+
search_after_date: z.string().optional().describe(
|
|
18829
|
+
"Include only results published after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
|
|
18830
|
+
),
|
|
18831
|
+
search_before_date: z.string().optional().describe(
|
|
18832
|
+
"Include only results published before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
|
|
18833
|
+
),
|
|
18834
|
+
last_updated_after_filter: z.string().optional().describe(
|
|
18835
|
+
"Include only results last updated after this date. Format: 'MM/DD/YYYY' (e.g., '3/1/2025'). Cannot be used with search_recency_filter."
|
|
18836
|
+
),
|
|
18837
|
+
last_updated_before_filter: z.string().optional().describe(
|
|
18838
|
+
"Include only results last updated before this date. Format: 'MM/DD/YYYY' (e.g., '3/15/2025'). Cannot be used with search_recency_filter."
|
|
18839
|
+
),
|
|
18840
|
+
search_recency_filter: z.enum(["day", "week", "month", "year"]).optional().describe(
|
|
18841
|
+
"Filter results by relative time period. Cannot be used with search_after_date or search_before_date."
|
|
18842
|
+
)
|
|
18843
|
+
})
|
|
18844
|
+
)
|
|
18845
|
+
);
|
|
18846
|
+
var perplexitySearchOutputSchema2 = lazySchema2(
|
|
18847
|
+
() => zodSchema3(
|
|
18848
|
+
z.union([
|
|
18849
|
+
// Success response
|
|
18850
|
+
z.object({
|
|
18851
|
+
results: z.array(
|
|
18852
|
+
z.object({
|
|
18853
|
+
title: z.string(),
|
|
18854
|
+
url: z.string(),
|
|
18855
|
+
snippet: z.string(),
|
|
18856
|
+
date: z.string().optional(),
|
|
18857
|
+
lastUpdated: z.string().optional()
|
|
18858
|
+
})
|
|
18859
|
+
),
|
|
18860
|
+
id: z.string()
|
|
18861
|
+
}),
|
|
18862
|
+
// Error response
|
|
18863
|
+
z.object({
|
|
18864
|
+
error: z.enum([
|
|
18865
|
+
"api_error",
|
|
18866
|
+
"rate_limit",
|
|
18867
|
+
"timeout",
|
|
18868
|
+
"invalid_input",
|
|
18869
|
+
"unknown"
|
|
18870
|
+
]),
|
|
18871
|
+
statusCode: z.number().optional(),
|
|
18872
|
+
message: z.string()
|
|
18873
|
+
})
|
|
18874
|
+
])
|
|
18875
|
+
)
|
|
18049
18876
|
);
|
|
18050
18877
|
var perplexitySearchToolFactory2 = createProviderToolFactoryWithOutputSchema({
|
|
18051
18878
|
id: "gateway.perplexity_search",
|
|
@@ -18054,6 +18881,14 @@ var perplexitySearchToolFactory2 = createProviderToolFactoryWithOutputSchema({
|
|
|
18054
18881
|
});
|
|
18055
18882
|
var perplexitySearch2 = (config = {}) => perplexitySearchToolFactory2(config);
|
|
18056
18883
|
var gatewayTools2 = {
|
|
18884
|
+
/**
|
|
18885
|
+
* Search the web using Exa for current information and token-efficient
|
|
18886
|
+
* excerpts optimized for agent workflows.
|
|
18887
|
+
*
|
|
18888
|
+
* Supports search type, category, domain, date, location, and content
|
|
18889
|
+
* extraction controls.
|
|
18890
|
+
*/
|
|
18891
|
+
exaSearch,
|
|
18057
18892
|
/**
|
|
18058
18893
|
* Search the web using Parallel AI's Search API for LLM-optimized excerpts.
|
|
18059
18894
|
*
|
|
@@ -18073,18 +18908,18 @@ var gatewayTools2 = {
|
|
|
18073
18908
|
perplexitySearch: perplexitySearch2
|
|
18074
18909
|
};
|
|
18075
18910
|
async function getVercelRequestId2() {
|
|
18076
|
-
var
|
|
18077
|
-
return (
|
|
18911
|
+
var _a117;
|
|
18912
|
+
return (_a117 = getContext2().headers) == null ? void 0 : _a117["x-vercel-id"];
|
|
18078
18913
|
}
|
|
18079
|
-
var VERSION5 = "3.0.
|
|
18914
|
+
var VERSION5 = "3.0.148";
|
|
18080
18915
|
var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
|
|
18081
18916
|
function createGatewayProvider2(options = {}) {
|
|
18082
|
-
var
|
|
18917
|
+
var _a117, _b113;
|
|
18083
18918
|
let pendingMetadata = null;
|
|
18084
18919
|
let metadataCache = null;
|
|
18085
|
-
const cacheRefreshMillis = (
|
|
18920
|
+
const cacheRefreshMillis = (_a117 = options.metadataCacheRefreshMillis) != null ? _a117 : 1e3 * 60 * 5;
|
|
18086
18921
|
let lastFetchTime = 0;
|
|
18087
|
-
const baseURL = (
|
|
18922
|
+
const baseURL = (_b113 = withoutTrailingSlash2(options.baseURL)) != null ? _b113 : "https://ai-gateway.vercel.sh/v3/ai";
|
|
18088
18923
|
const getHeaders = async () => {
|
|
18089
18924
|
try {
|
|
18090
18925
|
const auth = await getGatewayAuthToken2(options);
|
|
@@ -18144,10 +18979,10 @@ function createGatewayProvider2(options = {}) {
|
|
|
18144
18979
|
});
|
|
18145
18980
|
};
|
|
18146
18981
|
const getAvailableModels = async () => {
|
|
18147
|
-
var
|
|
18148
|
-
const
|
|
18149
|
-
if (!pendingMetadata ||
|
|
18150
|
-
lastFetchTime =
|
|
18982
|
+
var _a126, _b123, _c;
|
|
18983
|
+
const now = (_c = (_b123 = (_a126 = options._internal) == null ? void 0 : _a126.currentDate) == null ? void 0 : _b123.call(_a126).getTime()) != null ? _c : Date.now();
|
|
18984
|
+
if (!pendingMetadata || now - lastFetchTime > cacheRefreshMillis) {
|
|
18985
|
+
lastFetchTime = now;
|
|
18151
18986
|
pendingMetadata = new GatewayFetchMetadata2({
|
|
18152
18987
|
baseURL,
|
|
18153
18988
|
headers: getHeaders,
|
|
@@ -18254,6 +19089,28 @@ function createGatewayProvider2(options = {}) {
|
|
|
18254
19089
|
};
|
|
18255
19090
|
provider.rerankingModel = createRerankingModel;
|
|
18256
19091
|
provider.reranking = createRerankingModel;
|
|
19092
|
+
const createSpeechModel = (modelId) => {
|
|
19093
|
+
return new GatewaySpeechModel(modelId, {
|
|
19094
|
+
provider: "gateway",
|
|
19095
|
+
baseURL,
|
|
19096
|
+
headers: getHeaders,
|
|
19097
|
+
fetch: options.fetch,
|
|
19098
|
+
o11yHeaders: createO11yHeaders()
|
|
19099
|
+
});
|
|
19100
|
+
};
|
|
19101
|
+
provider.speechModel = createSpeechModel;
|
|
19102
|
+
provider.speech = createSpeechModel;
|
|
19103
|
+
const createTranscriptionModel = (modelId) => {
|
|
19104
|
+
return new GatewayTranscriptionModel(modelId, {
|
|
19105
|
+
provider: "gateway",
|
|
19106
|
+
baseURL,
|
|
19107
|
+
headers: getHeaders,
|
|
19108
|
+
fetch: options.fetch,
|
|
19109
|
+
o11yHeaders: createO11yHeaders()
|
|
19110
|
+
});
|
|
19111
|
+
};
|
|
19112
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
19113
|
+
provider.transcription = createTranscriptionModel;
|
|
18257
19114
|
provider.chat = provider.languageModel;
|
|
18258
19115
|
provider.embedding = provider.embeddingModel;
|
|
18259
19116
|
provider.image = provider.imageModel;
|
|
@@ -18279,19 +19136,16 @@ async function getGatewayAuthToken2(options) {
|
|
|
18279
19136
|
authMethod: "oidc"
|
|
18280
19137
|
};
|
|
18281
19138
|
}
|
|
18282
|
-
var
|
|
18283
|
-
var VERSION23 = "1.9.0";
|
|
19139
|
+
var VERSION6 = "1.9.1";
|
|
18284
19140
|
var re3 = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
|
|
18285
19141
|
function _makeCompatibilityCheck3(ownVersion) {
|
|
18286
|
-
|
|
18287
|
-
|
|
18288
|
-
|
|
19142
|
+
const acceptedVersions = /* @__PURE__ */ new Set([ownVersion]);
|
|
19143
|
+
const rejectedVersions = /* @__PURE__ */ new Set();
|
|
19144
|
+
const myVersionMatch = ownVersion.match(re3);
|
|
18289
19145
|
if (!myVersionMatch) {
|
|
18290
|
-
return
|
|
18291
|
-
return false;
|
|
18292
|
-
};
|
|
19146
|
+
return () => false;
|
|
18293
19147
|
}
|
|
18294
|
-
|
|
19148
|
+
const ownVersionParsed = {
|
|
18295
19149
|
major: +myVersionMatch[1],
|
|
18296
19150
|
minor: +myVersionMatch[2],
|
|
18297
19151
|
patch: +myVersionMatch[3],
|
|
@@ -18317,11 +19171,11 @@ function _makeCompatibilityCheck3(ownVersion) {
|
|
|
18317
19171
|
if (rejectedVersions.has(globalVersion)) {
|
|
18318
19172
|
return false;
|
|
18319
19173
|
}
|
|
18320
|
-
|
|
19174
|
+
const globalVersionMatch = globalVersion.match(re3);
|
|
18321
19175
|
if (!globalVersionMatch) {
|
|
18322
19176
|
return _reject(globalVersion);
|
|
18323
19177
|
}
|
|
18324
|
-
|
|
19178
|
+
const globalVersionParsed = {
|
|
18325
19179
|
major: +globalVersionMatch[1],
|
|
18326
19180
|
minor: +globalVersionMatch[2],
|
|
18327
19181
|
patch: +globalVersionMatch[3],
|
|
@@ -18339,455 +19193,324 @@ function _makeCompatibilityCheck3(ownVersion) {
|
|
|
18339
19193
|
}
|
|
18340
19194
|
return _reject(globalVersion);
|
|
18341
19195
|
}
|
|
18342
|
-
if (ownVersionParsed.minor <= globalVersionParsed.minor) {
|
|
18343
|
-
return _accept(globalVersion);
|
|
18344
|
-
}
|
|
18345
|
-
return _reject(globalVersion);
|
|
18346
|
-
};
|
|
18347
|
-
}
|
|
18348
|
-
var isCompatible3 = _makeCompatibilityCheck3(VERSION23);
|
|
18349
|
-
var major3 = VERSION23.split(".")[0];
|
|
18350
|
-
var GLOBAL_OPENTELEMETRY_API_KEY3 = /* @__PURE__ */ Symbol.for("opentelemetry.js.api." + major3);
|
|
18351
|
-
var _global3 = _globalThis3;
|
|
18352
|
-
function registerGlobal3(type, instance, diag, allowOverride) {
|
|
18353
|
-
var _a21;
|
|
18354
|
-
if (allowOverride === void 0) {
|
|
18355
|
-
allowOverride = false;
|
|
18356
|
-
}
|
|
18357
|
-
var api = _global3[GLOBAL_OPENTELEMETRY_API_KEY3] = (_a21 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) !== null && _a21 !== void 0 ? _a21 : {
|
|
18358
|
-
version: VERSION23
|
|
18359
|
-
};
|
|
18360
|
-
if (!allowOverride && api[type]) {
|
|
18361
|
-
var err = new Error("@opentelemetry/api: Attempted duplicate registration of API: " + type);
|
|
18362
|
-
diag.error(err.stack || err.message);
|
|
18363
|
-
return false;
|
|
18364
|
-
}
|
|
18365
|
-
if (api.version !== VERSION23) {
|
|
18366
|
-
var err = new Error("@opentelemetry/api: Registration of version v" + api.version + " for " + type + " does not match previously registered API v" + VERSION23);
|
|
18367
|
-
diag.error(err.stack || err.message);
|
|
18368
|
-
return false;
|
|
18369
|
-
}
|
|
18370
|
-
api[type] = instance;
|
|
18371
|
-
diag.debug("@opentelemetry/api: Registered a global for " + type + " v" + VERSION23 + ".");
|
|
18372
|
-
return true;
|
|
18373
|
-
}
|
|
18374
|
-
function getGlobal3(type) {
|
|
18375
|
-
var _a21, _b93;
|
|
18376
|
-
var globalVersion = (_a21 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) === null || _a21 === void 0 ? void 0 : _a21.version;
|
|
18377
|
-
if (!globalVersion || !isCompatible3(globalVersion)) {
|
|
18378
|
-
return;
|
|
18379
|
-
}
|
|
18380
|
-
return (_b93 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) === null || _b93 === void 0 ? void 0 : _b93[type];
|
|
18381
|
-
}
|
|
18382
|
-
function unregisterGlobal3(type, diag) {
|
|
18383
|
-
diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION23 + ".");
|
|
18384
|
-
var api = _global3[GLOBAL_OPENTELEMETRY_API_KEY3];
|
|
18385
|
-
if (api) {
|
|
18386
|
-
delete api[type];
|
|
18387
|
-
}
|
|
18388
|
-
}
|
|
18389
|
-
var __read6 = function(o, n) {
|
|
18390
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
18391
|
-
if (!m) return o;
|
|
18392
|
-
var i = m.call(o), r, ar = [], e;
|
|
18393
|
-
try {
|
|
18394
|
-
while (!(r = i.next()).done) ar.push(r.value);
|
|
18395
|
-
} catch (error) {
|
|
18396
|
-
e = { error };
|
|
18397
|
-
} finally {
|
|
18398
|
-
try {
|
|
18399
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
18400
|
-
} finally {
|
|
18401
|
-
if (e) throw e.error;
|
|
18402
|
-
}
|
|
18403
|
-
}
|
|
18404
|
-
return ar;
|
|
18405
|
-
};
|
|
18406
|
-
var __spreadArray6 = function(to, from, pack) {
|
|
18407
|
-
if (arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
18408
|
-
if (ar || !(i in from)) {
|
|
18409
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
18410
|
-
ar[i] = from[i];
|
|
18411
|
-
}
|
|
18412
|
-
}
|
|
18413
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
18414
|
-
};
|
|
18415
|
-
var DiagComponentLogger3 = (
|
|
18416
|
-
/** @class */
|
|
18417
|
-
(function() {
|
|
18418
|
-
function DiagComponentLogger22(props) {
|
|
18419
|
-
this._namespace = props.namespace || "DiagComponentLogger";
|
|
18420
|
-
}
|
|
18421
|
-
DiagComponentLogger22.prototype.debug = function() {
|
|
18422
|
-
var args = [];
|
|
18423
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18424
|
-
args[_i] = arguments[_i];
|
|
18425
|
-
}
|
|
18426
|
-
return logProxy3("debug", this._namespace, args);
|
|
18427
|
-
};
|
|
18428
|
-
DiagComponentLogger22.prototype.error = function() {
|
|
18429
|
-
var args = [];
|
|
18430
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18431
|
-
args[_i] = arguments[_i];
|
|
18432
|
-
}
|
|
18433
|
-
return logProxy3("error", this._namespace, args);
|
|
18434
|
-
};
|
|
18435
|
-
DiagComponentLogger22.prototype.info = function() {
|
|
18436
|
-
var args = [];
|
|
18437
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18438
|
-
args[_i] = arguments[_i];
|
|
18439
|
-
}
|
|
18440
|
-
return logProxy3("info", this._namespace, args);
|
|
18441
|
-
};
|
|
18442
|
-
DiagComponentLogger22.prototype.warn = function() {
|
|
18443
|
-
var args = [];
|
|
18444
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18445
|
-
args[_i] = arguments[_i];
|
|
18446
|
-
}
|
|
18447
|
-
return logProxy3("warn", this._namespace, args);
|
|
18448
|
-
};
|
|
18449
|
-
DiagComponentLogger22.prototype.verbose = function() {
|
|
18450
|
-
var args = [];
|
|
18451
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18452
|
-
args[_i] = arguments[_i];
|
|
18453
|
-
}
|
|
18454
|
-
return logProxy3("verbose", this._namespace, args);
|
|
18455
|
-
};
|
|
18456
|
-
return DiagComponentLogger22;
|
|
18457
|
-
})()
|
|
18458
|
-
);
|
|
18459
|
-
function logProxy3(funcName, namespace, args) {
|
|
18460
|
-
var logger = getGlobal3("diag");
|
|
18461
|
-
if (!logger) {
|
|
18462
|
-
return;
|
|
18463
|
-
}
|
|
18464
|
-
args.unshift(namespace);
|
|
18465
|
-
return logger[funcName].apply(logger, __spreadArray6([], __read6(args), false));
|
|
18466
|
-
}
|
|
18467
|
-
var DiagLogLevel3;
|
|
18468
|
-
(function(DiagLogLevel22) {
|
|
18469
|
-
DiagLogLevel22[DiagLogLevel22["NONE"] = 0] = "NONE";
|
|
18470
|
-
DiagLogLevel22[DiagLogLevel22["ERROR"] = 30] = "ERROR";
|
|
18471
|
-
DiagLogLevel22[DiagLogLevel22["WARN"] = 50] = "WARN";
|
|
18472
|
-
DiagLogLevel22[DiagLogLevel22["INFO"] = 60] = "INFO";
|
|
18473
|
-
DiagLogLevel22[DiagLogLevel22["DEBUG"] = 70] = "DEBUG";
|
|
18474
|
-
DiagLogLevel22[DiagLogLevel22["VERBOSE"] = 80] = "VERBOSE";
|
|
18475
|
-
DiagLogLevel22[DiagLogLevel22["ALL"] = 9999] = "ALL";
|
|
18476
|
-
})(DiagLogLevel3 || (DiagLogLevel3 = {}));
|
|
18477
|
-
function createLogLevelDiagLogger3(maxLevel, logger) {
|
|
18478
|
-
if (maxLevel < DiagLogLevel3.NONE) {
|
|
18479
|
-
maxLevel = DiagLogLevel3.NONE;
|
|
18480
|
-
} else if (maxLevel > DiagLogLevel3.ALL) {
|
|
18481
|
-
maxLevel = DiagLogLevel3.ALL;
|
|
18482
|
-
}
|
|
18483
|
-
logger = logger || {};
|
|
18484
|
-
function _filterFunc(funcName, theLevel) {
|
|
18485
|
-
var theFunc = logger[funcName];
|
|
18486
|
-
if (typeof theFunc === "function" && maxLevel >= theLevel) {
|
|
18487
|
-
return theFunc.bind(logger);
|
|
18488
|
-
}
|
|
18489
|
-
return function() {
|
|
18490
|
-
};
|
|
18491
|
-
}
|
|
18492
|
-
return {
|
|
18493
|
-
error: _filterFunc("error", DiagLogLevel3.ERROR),
|
|
18494
|
-
warn: _filterFunc("warn", DiagLogLevel3.WARN),
|
|
18495
|
-
info: _filterFunc("info", DiagLogLevel3.INFO),
|
|
18496
|
-
debug: _filterFunc("debug", DiagLogLevel3.DEBUG),
|
|
18497
|
-
verbose: _filterFunc("verbose", DiagLogLevel3.VERBOSE)
|
|
18498
|
-
};
|
|
18499
|
-
}
|
|
18500
|
-
var __read23 = function(o, n) {
|
|
18501
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
18502
|
-
if (!m) return o;
|
|
18503
|
-
var i = m.call(o), r, ar = [], e;
|
|
18504
|
-
try {
|
|
18505
|
-
while (!(r = i.next()).done) ar.push(r.value);
|
|
18506
|
-
} catch (error) {
|
|
18507
|
-
e = { error };
|
|
18508
|
-
} finally {
|
|
18509
|
-
try {
|
|
18510
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
18511
|
-
} finally {
|
|
18512
|
-
if (e) throw e.error;
|
|
18513
|
-
}
|
|
18514
|
-
}
|
|
18515
|
-
return ar;
|
|
18516
|
-
};
|
|
18517
|
-
var __spreadArray23 = function(to, from, pack) {
|
|
18518
|
-
if (arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
18519
|
-
if (ar || !(i in from)) {
|
|
18520
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
18521
|
-
ar[i] = from[i];
|
|
18522
|
-
}
|
|
18523
|
-
}
|
|
18524
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
18525
|
-
};
|
|
18526
|
-
var API_NAME5 = "diag";
|
|
18527
|
-
var DiagAPI3 = (
|
|
18528
|
-
/** @class */
|
|
18529
|
-
(function() {
|
|
18530
|
-
function DiagAPI22() {
|
|
18531
|
-
function _logProxy(funcName) {
|
|
18532
|
-
return function() {
|
|
18533
|
-
var args = [];
|
|
18534
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
18535
|
-
args[_i] = arguments[_i];
|
|
18536
|
-
}
|
|
18537
|
-
var logger = getGlobal3("diag");
|
|
18538
|
-
if (!logger)
|
|
18539
|
-
return;
|
|
18540
|
-
return logger[funcName].apply(logger, __spreadArray23([], __read23(args), false));
|
|
18541
|
-
};
|
|
18542
|
-
}
|
|
18543
|
-
var self = this;
|
|
18544
|
-
var setLogger = function(logger, optionsOrLogLevel) {
|
|
18545
|
-
var _a21, _b93, _c;
|
|
18546
|
-
if (optionsOrLogLevel === void 0) {
|
|
18547
|
-
optionsOrLogLevel = { logLevel: DiagLogLevel3.INFO };
|
|
18548
|
-
}
|
|
18549
|
-
if (logger === self) {
|
|
18550
|
-
var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
|
|
18551
|
-
self.error((_a21 = err.stack) !== null && _a21 !== void 0 ? _a21 : err.message);
|
|
18552
|
-
return false;
|
|
18553
|
-
}
|
|
18554
|
-
if (typeof optionsOrLogLevel === "number") {
|
|
18555
|
-
optionsOrLogLevel = {
|
|
18556
|
-
logLevel: optionsOrLogLevel
|
|
18557
|
-
};
|
|
18558
|
-
}
|
|
18559
|
-
var oldLogger = getGlobal3("diag");
|
|
18560
|
-
var newLogger = createLogLevelDiagLogger3((_b93 = optionsOrLogLevel.logLevel) !== null && _b93 !== void 0 ? _b93 : DiagLogLevel3.INFO, logger);
|
|
18561
|
-
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
|
18562
|
-
var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
|
|
18563
|
-
oldLogger.warn("Current logger will be overwritten from " + stack);
|
|
18564
|
-
newLogger.warn("Current logger will overwrite one already registered from " + stack);
|
|
18565
|
-
}
|
|
18566
|
-
return registerGlobal3("diag", newLogger, self, true);
|
|
18567
|
-
};
|
|
18568
|
-
self.setLogger = setLogger;
|
|
18569
|
-
self.disable = function() {
|
|
18570
|
-
unregisterGlobal3(API_NAME5, self);
|
|
18571
|
-
};
|
|
18572
|
-
self.createComponentLogger = function(options) {
|
|
18573
|
-
return new DiagComponentLogger3(options);
|
|
18574
|
-
};
|
|
18575
|
-
self.verbose = _logProxy("verbose");
|
|
18576
|
-
self.debug = _logProxy("debug");
|
|
18577
|
-
self.info = _logProxy("info");
|
|
18578
|
-
self.warn = _logProxy("warn");
|
|
18579
|
-
self.error = _logProxy("error");
|
|
18580
|
-
}
|
|
18581
|
-
DiagAPI22.instance = function() {
|
|
18582
|
-
if (!this._instance) {
|
|
18583
|
-
this._instance = new DiagAPI22();
|
|
18584
|
-
}
|
|
18585
|
-
return this._instance;
|
|
18586
|
-
};
|
|
18587
|
-
return DiagAPI22;
|
|
18588
|
-
})()
|
|
18589
|
-
);
|
|
18590
|
-
function createContextKey3(description) {
|
|
18591
|
-
return Symbol.for(description);
|
|
18592
|
-
}
|
|
18593
|
-
var BaseContext3 = (
|
|
18594
|
-
/** @class */
|
|
18595
|
-
/* @__PURE__ */ (function() {
|
|
18596
|
-
function BaseContext22(parentContext) {
|
|
18597
|
-
var self = this;
|
|
18598
|
-
self._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
|
|
18599
|
-
self.getValue = function(key) {
|
|
18600
|
-
return self._currentContext.get(key);
|
|
18601
|
-
};
|
|
18602
|
-
self.setValue = function(key, value) {
|
|
18603
|
-
var context2 = new BaseContext22(self._currentContext);
|
|
18604
|
-
context2._currentContext.set(key, value);
|
|
18605
|
-
return context2;
|
|
18606
|
-
};
|
|
18607
|
-
self.deleteValue = function(key) {
|
|
18608
|
-
var context2 = new BaseContext22(self._currentContext);
|
|
18609
|
-
context2._currentContext.delete(key);
|
|
18610
|
-
return context2;
|
|
18611
|
-
};
|
|
18612
|
-
}
|
|
18613
|
-
return BaseContext22;
|
|
18614
|
-
})()
|
|
18615
|
-
);
|
|
18616
|
-
var ROOT_CONTEXT3 = new BaseContext3();
|
|
18617
|
-
var __read33 = function(o, n) {
|
|
18618
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
18619
|
-
if (!m) return o;
|
|
18620
|
-
var i = m.call(o), r, ar = [], e;
|
|
18621
|
-
try {
|
|
18622
|
-
while (!(r = i.next()).done) ar.push(r.value);
|
|
18623
|
-
} catch (error) {
|
|
18624
|
-
e = { error };
|
|
18625
|
-
} finally {
|
|
18626
|
-
try {
|
|
18627
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
18628
|
-
} finally {
|
|
18629
|
-
if (e) throw e.error;
|
|
19196
|
+
if (ownVersionParsed.minor <= globalVersionParsed.minor) {
|
|
19197
|
+
return _accept(globalVersion);
|
|
18630
19198
|
}
|
|
19199
|
+
return _reject(globalVersion);
|
|
19200
|
+
};
|
|
19201
|
+
}
|
|
19202
|
+
var isCompatible3 = _makeCompatibilityCheck3(VERSION6);
|
|
19203
|
+
var major3 = VERSION6.split(".")[0];
|
|
19204
|
+
var GLOBAL_OPENTELEMETRY_API_KEY3 = /* @__PURE__ */ Symbol.for(`opentelemetry.js.api.${major3}`);
|
|
19205
|
+
var _global3 = typeof globalThis === "object" ? globalThis : typeof self === "object" ? self : typeof window === "object" ? window : typeof global === "object" ? global : {};
|
|
19206
|
+
function registerGlobal3(type, instance, diag, allowOverride = false) {
|
|
19207
|
+
var _a223;
|
|
19208
|
+
const api = _global3[GLOBAL_OPENTELEMETRY_API_KEY3] = (_a223 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) !== null && _a223 !== void 0 ? _a223 : {
|
|
19209
|
+
version: VERSION6
|
|
19210
|
+
};
|
|
19211
|
+
if (!allowOverride && api[type]) {
|
|
19212
|
+
const err = new Error(`@opentelemetry/api: Attempted duplicate registration of API: ${type}`);
|
|
19213
|
+
diag.error(err.stack || err.message);
|
|
19214
|
+
return false;
|
|
18631
19215
|
}
|
|
18632
|
-
|
|
18633
|
-
};
|
|
18634
|
-
|
|
18635
|
-
|
|
18636
|
-
|
|
18637
|
-
|
|
18638
|
-
|
|
18639
|
-
|
|
19216
|
+
if (api.version !== VERSION6) {
|
|
19217
|
+
const err = new Error(`@opentelemetry/api: Registration of version v${api.version} for ${type} does not match previously registered API v${VERSION6}`);
|
|
19218
|
+
diag.error(err.stack || err.message);
|
|
19219
|
+
return false;
|
|
19220
|
+
}
|
|
19221
|
+
api[type] = instance;
|
|
19222
|
+
diag.debug(`@opentelemetry/api: Registered a global for ${type} v${VERSION6}.`);
|
|
19223
|
+
return true;
|
|
19224
|
+
}
|
|
19225
|
+
function getGlobal3(type) {
|
|
19226
|
+
var _a223, _b19;
|
|
19227
|
+
const globalVersion = (_a223 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) === null || _a223 === void 0 ? void 0 : _a223.version;
|
|
19228
|
+
if (!globalVersion || !isCompatible3(globalVersion)) {
|
|
19229
|
+
return;
|
|
19230
|
+
}
|
|
19231
|
+
return (_b19 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) === null || _b19 === void 0 ? void 0 : _b19[type];
|
|
19232
|
+
}
|
|
19233
|
+
function unregisterGlobal3(type, diag) {
|
|
19234
|
+
diag.debug(`@opentelemetry/api: Unregistering a global for ${type} v${VERSION6}.`);
|
|
19235
|
+
const api = _global3[GLOBAL_OPENTELEMETRY_API_KEY3];
|
|
19236
|
+
if (api) {
|
|
19237
|
+
delete api[type];
|
|
19238
|
+
}
|
|
19239
|
+
}
|
|
19240
|
+
var DiagComponentLogger3 = class {
|
|
19241
|
+
constructor(props) {
|
|
19242
|
+
this._namespace = props.namespace || "DiagComponentLogger";
|
|
19243
|
+
}
|
|
19244
|
+
debug(...args) {
|
|
19245
|
+
return logProxy3("debug", this._namespace, args);
|
|
19246
|
+
}
|
|
19247
|
+
error(...args) {
|
|
19248
|
+
return logProxy3("error", this._namespace, args);
|
|
19249
|
+
}
|
|
19250
|
+
info(...args) {
|
|
19251
|
+
return logProxy3("info", this._namespace, args);
|
|
19252
|
+
}
|
|
19253
|
+
warn(...args) {
|
|
19254
|
+
return logProxy3("warn", this._namespace, args);
|
|
19255
|
+
}
|
|
19256
|
+
verbose(...args) {
|
|
19257
|
+
return logProxy3("verbose", this._namespace, args);
|
|
18640
19258
|
}
|
|
18641
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
18642
19259
|
};
|
|
18643
|
-
|
|
18644
|
-
|
|
18645
|
-
(
|
|
18646
|
-
|
|
19260
|
+
function logProxy3(funcName, namespace, args) {
|
|
19261
|
+
const logger = getGlobal3("diag");
|
|
19262
|
+
if (!logger) {
|
|
19263
|
+
return;
|
|
19264
|
+
}
|
|
19265
|
+
return logger[funcName](namespace, ...args);
|
|
19266
|
+
}
|
|
19267
|
+
var DiagLogLevel3;
|
|
19268
|
+
(function(DiagLogLevel22) {
|
|
19269
|
+
DiagLogLevel22[DiagLogLevel22["NONE"] = 0] = "NONE";
|
|
19270
|
+
DiagLogLevel22[DiagLogLevel22["ERROR"] = 30] = "ERROR";
|
|
19271
|
+
DiagLogLevel22[DiagLogLevel22["WARN"] = 50] = "WARN";
|
|
19272
|
+
DiagLogLevel22[DiagLogLevel22["INFO"] = 60] = "INFO";
|
|
19273
|
+
DiagLogLevel22[DiagLogLevel22["DEBUG"] = 70] = "DEBUG";
|
|
19274
|
+
DiagLogLevel22[DiagLogLevel22["VERBOSE"] = 80] = "VERBOSE";
|
|
19275
|
+
DiagLogLevel22[DiagLogLevel22["ALL"] = 9999] = "ALL";
|
|
19276
|
+
})(DiagLogLevel3 || (DiagLogLevel3 = {}));
|
|
19277
|
+
function createLogLevelDiagLogger3(maxLevel, logger) {
|
|
19278
|
+
if (maxLevel < DiagLogLevel3.NONE) {
|
|
19279
|
+
maxLevel = DiagLogLevel3.NONE;
|
|
19280
|
+
} else if (maxLevel > DiagLogLevel3.ALL) {
|
|
19281
|
+
maxLevel = DiagLogLevel3.ALL;
|
|
19282
|
+
}
|
|
19283
|
+
logger = logger || {};
|
|
19284
|
+
function _filterFunc(funcName, theLevel) {
|
|
19285
|
+
const theFunc = logger[funcName];
|
|
19286
|
+
if (typeof theFunc === "function" && maxLevel >= theLevel) {
|
|
19287
|
+
return theFunc.bind(logger);
|
|
18647
19288
|
}
|
|
18648
|
-
|
|
18649
|
-
return ROOT_CONTEXT3;
|
|
18650
|
-
};
|
|
18651
|
-
NoopContextManager22.prototype.with = function(_context, fn, thisArg) {
|
|
18652
|
-
var args = [];
|
|
18653
|
-
for (var _i = 3; _i < arguments.length; _i++) {
|
|
18654
|
-
args[_i - 3] = arguments[_i];
|
|
18655
|
-
}
|
|
18656
|
-
return fn.call.apply(fn, __spreadArray33([thisArg], __read33(args), false));
|
|
18657
|
-
};
|
|
18658
|
-
NoopContextManager22.prototype.bind = function(_context, target) {
|
|
18659
|
-
return target;
|
|
18660
|
-
};
|
|
18661
|
-
NoopContextManager22.prototype.enable = function() {
|
|
18662
|
-
return this;
|
|
18663
|
-
};
|
|
18664
|
-
NoopContextManager22.prototype.disable = function() {
|
|
18665
|
-
return this;
|
|
19289
|
+
return function() {
|
|
18666
19290
|
};
|
|
18667
|
-
return NoopContextManager22;
|
|
18668
|
-
})()
|
|
18669
|
-
);
|
|
18670
|
-
var __read43 = function(o, n) {
|
|
18671
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
18672
|
-
if (!m) return o;
|
|
18673
|
-
var i = m.call(o), r, ar = [], e;
|
|
18674
|
-
try {
|
|
18675
|
-
while (!(r = i.next()).done) ar.push(r.value);
|
|
18676
|
-
} catch (error) {
|
|
18677
|
-
e = { error };
|
|
18678
|
-
} finally {
|
|
18679
|
-
try {
|
|
18680
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
18681
|
-
} finally {
|
|
18682
|
-
if (e) throw e.error;
|
|
18683
|
-
}
|
|
18684
19291
|
}
|
|
18685
|
-
return
|
|
18686
|
-
|
|
18687
|
-
|
|
18688
|
-
|
|
18689
|
-
|
|
18690
|
-
|
|
18691
|
-
|
|
19292
|
+
return {
|
|
19293
|
+
error: _filterFunc("error", DiagLogLevel3.ERROR),
|
|
19294
|
+
warn: _filterFunc("warn", DiagLogLevel3.WARN),
|
|
19295
|
+
info: _filterFunc("info", DiagLogLevel3.INFO),
|
|
19296
|
+
debug: _filterFunc("debug", DiagLogLevel3.DEBUG),
|
|
19297
|
+
verbose: _filterFunc("verbose", DiagLogLevel3.VERBOSE)
|
|
19298
|
+
};
|
|
19299
|
+
}
|
|
19300
|
+
var API_NAME5 = "diag";
|
|
19301
|
+
var DiagAPI3 = class _DiagAPI {
|
|
19302
|
+
/** Get the singleton instance of the DiagAPI API */
|
|
19303
|
+
static instance() {
|
|
19304
|
+
if (!this._instance) {
|
|
19305
|
+
this._instance = new _DiagAPI();
|
|
18692
19306
|
}
|
|
19307
|
+
return this._instance;
|
|
18693
19308
|
}
|
|
18694
|
-
|
|
18695
|
-
|
|
18696
|
-
|
|
18697
|
-
|
|
18698
|
-
|
|
18699
|
-
|
|
18700
|
-
|
|
18701
|
-
|
|
19309
|
+
/**
|
|
19310
|
+
* Private internal constructor
|
|
19311
|
+
* @private
|
|
19312
|
+
*/
|
|
19313
|
+
constructor() {
|
|
19314
|
+
function _logProxy(funcName) {
|
|
19315
|
+
return function(...args) {
|
|
19316
|
+
const logger = getGlobal3("diag");
|
|
19317
|
+
if (!logger)
|
|
19318
|
+
return;
|
|
19319
|
+
return logger[funcName](...args);
|
|
19320
|
+
};
|
|
18702
19321
|
}
|
|
18703
|
-
|
|
18704
|
-
|
|
18705
|
-
|
|
19322
|
+
const self2 = this;
|
|
19323
|
+
const setLogger = (logger, optionsOrLogLevel = { logLevel: DiagLogLevel3.INFO }) => {
|
|
19324
|
+
var _a223, _b19, _c;
|
|
19325
|
+
if (logger === self2) {
|
|
19326
|
+
const err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
|
|
19327
|
+
self2.error((_a223 = err.stack) !== null && _a223 !== void 0 ? _a223 : err.message);
|
|
19328
|
+
return false;
|
|
19329
|
+
}
|
|
19330
|
+
if (typeof optionsOrLogLevel === "number") {
|
|
19331
|
+
optionsOrLogLevel = {
|
|
19332
|
+
logLevel: optionsOrLogLevel
|
|
19333
|
+
};
|
|
18706
19334
|
}
|
|
18707
|
-
|
|
18708
|
-
|
|
18709
|
-
|
|
18710
|
-
|
|
18711
|
-
|
|
18712
|
-
|
|
18713
|
-
return this._getContextManager().active();
|
|
18714
|
-
};
|
|
18715
|
-
ContextAPI22.prototype.with = function(context2, fn, thisArg) {
|
|
18716
|
-
var _a21;
|
|
18717
|
-
var args = [];
|
|
18718
|
-
for (var _i = 3; _i < arguments.length; _i++) {
|
|
18719
|
-
args[_i - 3] = arguments[_i];
|
|
19335
|
+
const oldLogger = getGlobal3("diag");
|
|
19336
|
+
const newLogger = createLogLevelDiagLogger3((_b19 = optionsOrLogLevel.logLevel) !== null && _b19 !== void 0 ? _b19 : DiagLogLevel3.INFO, logger);
|
|
19337
|
+
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
|
19338
|
+
const stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
|
|
19339
|
+
oldLogger.warn(`Current logger will be overwritten from ${stack}`);
|
|
19340
|
+
newLogger.warn(`Current logger will overwrite one already registered from ${stack}`);
|
|
18720
19341
|
}
|
|
18721
|
-
return (
|
|
18722
|
-
};
|
|
18723
|
-
ContextAPI22.prototype.bind = function(context2, target) {
|
|
18724
|
-
return this._getContextManager().bind(context2, target);
|
|
19342
|
+
return registerGlobal3("diag", newLogger, self2, true);
|
|
18725
19343
|
};
|
|
18726
|
-
|
|
18727
|
-
|
|
19344
|
+
self2.setLogger = setLogger;
|
|
19345
|
+
self2.disable = () => {
|
|
19346
|
+
unregisterGlobal3(API_NAME5, self2);
|
|
18728
19347
|
};
|
|
18729
|
-
|
|
18730
|
-
|
|
18731
|
-
unregisterGlobal3(API_NAME23, DiagAPI3.instance());
|
|
19348
|
+
self2.createComponentLogger = (options) => {
|
|
19349
|
+
return new DiagComponentLogger3(options);
|
|
18732
19350
|
};
|
|
18733
|
-
|
|
18734
|
-
|
|
18735
|
-
);
|
|
18736
|
-
|
|
18737
|
-
(
|
|
18738
|
-
|
|
18739
|
-
TraceFlags22[TraceFlags22["SAMPLED"] = 1] = "SAMPLED";
|
|
18740
|
-
})(TraceFlags3 || (TraceFlags3 = {}));
|
|
18741
|
-
var INVALID_SPANID3 = "0000000000000000";
|
|
18742
|
-
var INVALID_TRACEID3 = "00000000000000000000000000000000";
|
|
18743
|
-
var INVALID_SPAN_CONTEXT3 = {
|
|
18744
|
-
traceId: INVALID_TRACEID3,
|
|
18745
|
-
spanId: INVALID_SPANID3,
|
|
18746
|
-
traceFlags: TraceFlags3.NONE
|
|
19351
|
+
self2.verbose = _logProxy("verbose");
|
|
19352
|
+
self2.debug = _logProxy("debug");
|
|
19353
|
+
self2.info = _logProxy("info");
|
|
19354
|
+
self2.warn = _logProxy("warn");
|
|
19355
|
+
self2.error = _logProxy("error");
|
|
19356
|
+
}
|
|
18747
19357
|
};
|
|
18748
|
-
|
|
18749
|
-
|
|
18750
|
-
|
|
18751
|
-
|
|
18752
|
-
|
|
18753
|
-
|
|
18754
|
-
|
|
18755
|
-
|
|
18756
|
-
|
|
18757
|
-
|
|
18758
|
-
|
|
18759
|
-
|
|
18760
|
-
|
|
18761
|
-
|
|
18762
|
-
|
|
18763
|
-
|
|
18764
|
-
return
|
|
18765
|
-
};
|
|
18766
|
-
NonRecordingSpan22.prototype.addEvent = function(_name, _attributes) {
|
|
18767
|
-
return this;
|
|
18768
|
-
};
|
|
18769
|
-
NonRecordingSpan22.prototype.addLink = function(_link) {
|
|
18770
|
-
return this;
|
|
18771
|
-
};
|
|
18772
|
-
NonRecordingSpan22.prototype.addLinks = function(_links) {
|
|
18773
|
-
return this;
|
|
18774
|
-
};
|
|
18775
|
-
NonRecordingSpan22.prototype.setStatus = function(_status) {
|
|
18776
|
-
return this;
|
|
18777
|
-
};
|
|
18778
|
-
NonRecordingSpan22.prototype.updateName = function(_name) {
|
|
18779
|
-
return this;
|
|
18780
|
-
};
|
|
18781
|
-
NonRecordingSpan22.prototype.end = function(_endTime) {
|
|
18782
|
-
};
|
|
18783
|
-
NonRecordingSpan22.prototype.isRecording = function() {
|
|
18784
|
-
return false;
|
|
19358
|
+
function createContextKey3(description) {
|
|
19359
|
+
return Symbol.for(description);
|
|
19360
|
+
}
|
|
19361
|
+
var BaseContext3 = class _BaseContext {
|
|
19362
|
+
/**
|
|
19363
|
+
* Construct a new context which inherits values from an optional parent context.
|
|
19364
|
+
*
|
|
19365
|
+
* @param parentContext a context from which to inherit values
|
|
19366
|
+
*/
|
|
19367
|
+
constructor(parentContext) {
|
|
19368
|
+
const self2 = this;
|
|
19369
|
+
self2._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
|
|
19370
|
+
self2.getValue = (key) => self2._currentContext.get(key);
|
|
19371
|
+
self2.setValue = (key, value) => {
|
|
19372
|
+
const context2 = new _BaseContext(self2._currentContext);
|
|
19373
|
+
context2._currentContext.set(key, value);
|
|
19374
|
+
return context2;
|
|
18785
19375
|
};
|
|
18786
|
-
|
|
19376
|
+
self2.deleteValue = (key) => {
|
|
19377
|
+
const context2 = new _BaseContext(self2._currentContext);
|
|
19378
|
+
context2._currentContext.delete(key);
|
|
19379
|
+
return context2;
|
|
18787
19380
|
};
|
|
18788
|
-
|
|
18789
|
-
|
|
18790
|
-
);
|
|
19381
|
+
}
|
|
19382
|
+
};
|
|
19383
|
+
var ROOT_CONTEXT3 = new BaseContext3();
|
|
19384
|
+
var NoopContextManager3 = class {
|
|
19385
|
+
active() {
|
|
19386
|
+
return ROOT_CONTEXT3;
|
|
19387
|
+
}
|
|
19388
|
+
with(_context, fn, thisArg, ...args) {
|
|
19389
|
+
return fn.call(thisArg, ...args);
|
|
19390
|
+
}
|
|
19391
|
+
bind(_context, target) {
|
|
19392
|
+
return target;
|
|
19393
|
+
}
|
|
19394
|
+
enable() {
|
|
19395
|
+
return this;
|
|
19396
|
+
}
|
|
19397
|
+
disable() {
|
|
19398
|
+
return this;
|
|
19399
|
+
}
|
|
19400
|
+
};
|
|
19401
|
+
var API_NAME23 = "context";
|
|
19402
|
+
var NOOP_CONTEXT_MANAGER3 = new NoopContextManager3();
|
|
19403
|
+
var ContextAPI3 = class _ContextAPI {
|
|
19404
|
+
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
19405
|
+
constructor() {
|
|
19406
|
+
}
|
|
19407
|
+
/** Get the singleton instance of the Context API */
|
|
19408
|
+
static getInstance() {
|
|
19409
|
+
if (!this._instance) {
|
|
19410
|
+
this._instance = new _ContextAPI();
|
|
19411
|
+
}
|
|
19412
|
+
return this._instance;
|
|
19413
|
+
}
|
|
19414
|
+
/**
|
|
19415
|
+
* Set the current context manager.
|
|
19416
|
+
*
|
|
19417
|
+
* @returns true if the context manager was successfully registered, else false
|
|
19418
|
+
*/
|
|
19419
|
+
setGlobalContextManager(contextManager) {
|
|
19420
|
+
return registerGlobal3(API_NAME23, contextManager, DiagAPI3.instance());
|
|
19421
|
+
}
|
|
19422
|
+
/**
|
|
19423
|
+
* Get the currently active context
|
|
19424
|
+
*/
|
|
19425
|
+
active() {
|
|
19426
|
+
return this._getContextManager().active();
|
|
19427
|
+
}
|
|
19428
|
+
/**
|
|
19429
|
+
* Execute a function with an active context
|
|
19430
|
+
*
|
|
19431
|
+
* @param context context to be active during function execution
|
|
19432
|
+
* @param fn function to execute in a context
|
|
19433
|
+
* @param thisArg optional receiver to be used for calling fn
|
|
19434
|
+
* @param args optional arguments forwarded to fn
|
|
19435
|
+
*/
|
|
19436
|
+
with(context2, fn, thisArg, ...args) {
|
|
19437
|
+
return this._getContextManager().with(context2, fn, thisArg, ...args);
|
|
19438
|
+
}
|
|
19439
|
+
/**
|
|
19440
|
+
* Bind a context to a target function or event emitter
|
|
19441
|
+
*
|
|
19442
|
+
* @param context context to bind to the event emitter or function. Defaults to the currently active context
|
|
19443
|
+
* @param target function or event emitter to bind
|
|
19444
|
+
*/
|
|
19445
|
+
bind(context2, target) {
|
|
19446
|
+
return this._getContextManager().bind(context2, target);
|
|
19447
|
+
}
|
|
19448
|
+
_getContextManager() {
|
|
19449
|
+
return getGlobal3(API_NAME23) || NOOP_CONTEXT_MANAGER3;
|
|
19450
|
+
}
|
|
19451
|
+
/** Disable and remove the global context manager */
|
|
19452
|
+
disable() {
|
|
19453
|
+
this._getContextManager().disable();
|
|
19454
|
+
unregisterGlobal3(API_NAME23, DiagAPI3.instance());
|
|
19455
|
+
}
|
|
19456
|
+
};
|
|
19457
|
+
var TraceFlags3;
|
|
19458
|
+
(function(TraceFlags22) {
|
|
19459
|
+
TraceFlags22[TraceFlags22["NONE"] = 0] = "NONE";
|
|
19460
|
+
TraceFlags22[TraceFlags22["SAMPLED"] = 1] = "SAMPLED";
|
|
19461
|
+
})(TraceFlags3 || (TraceFlags3 = {}));
|
|
19462
|
+
var INVALID_SPANID3 = "0000000000000000";
|
|
19463
|
+
var INVALID_TRACEID3 = "00000000000000000000000000000000";
|
|
19464
|
+
var INVALID_SPAN_CONTEXT3 = {
|
|
19465
|
+
traceId: INVALID_TRACEID3,
|
|
19466
|
+
spanId: INVALID_SPANID3,
|
|
19467
|
+
traceFlags: TraceFlags3.NONE
|
|
19468
|
+
};
|
|
19469
|
+
var NonRecordingSpan3 = class {
|
|
19470
|
+
constructor(spanContext = INVALID_SPAN_CONTEXT3) {
|
|
19471
|
+
this._spanContext = spanContext;
|
|
19472
|
+
}
|
|
19473
|
+
// Returns a SpanContext.
|
|
19474
|
+
spanContext() {
|
|
19475
|
+
return this._spanContext;
|
|
19476
|
+
}
|
|
19477
|
+
// By default does nothing
|
|
19478
|
+
setAttribute(_key, _value) {
|
|
19479
|
+
return this;
|
|
19480
|
+
}
|
|
19481
|
+
// By default does nothing
|
|
19482
|
+
setAttributes(_attributes) {
|
|
19483
|
+
return this;
|
|
19484
|
+
}
|
|
19485
|
+
// By default does nothing
|
|
19486
|
+
addEvent(_name, _attributes) {
|
|
19487
|
+
return this;
|
|
19488
|
+
}
|
|
19489
|
+
addLink(_link) {
|
|
19490
|
+
return this;
|
|
19491
|
+
}
|
|
19492
|
+
addLinks(_links) {
|
|
19493
|
+
return this;
|
|
19494
|
+
}
|
|
19495
|
+
// By default does nothing
|
|
19496
|
+
setStatus(_status) {
|
|
19497
|
+
return this;
|
|
19498
|
+
}
|
|
19499
|
+
// By default does nothing
|
|
19500
|
+
updateName(_name) {
|
|
19501
|
+
return this;
|
|
19502
|
+
}
|
|
19503
|
+
// By default does nothing
|
|
19504
|
+
end(_endTime) {
|
|
19505
|
+
}
|
|
19506
|
+
// isRecording always returns false for NonRecordingSpan.
|
|
19507
|
+
isRecording() {
|
|
19508
|
+
return false;
|
|
19509
|
+
}
|
|
19510
|
+
// By default does nothing
|
|
19511
|
+
recordException(_exception, _time) {
|
|
19512
|
+
}
|
|
19513
|
+
};
|
|
18791
19514
|
var SPAN_KEY3 = createContextKey3("OpenTelemetry Context Key SPAN");
|
|
18792
19515
|
function getSpan3(context2) {
|
|
18793
19516
|
return context2.getValue(SPAN_KEY3) || void 0;
|
|
@@ -18805,16 +19528,128 @@ function setSpanContext3(context2, spanContext) {
|
|
|
18805
19528
|
return setSpan3(context2, new NonRecordingSpan3(spanContext));
|
|
18806
19529
|
}
|
|
18807
19530
|
function getSpanContext3(context2) {
|
|
18808
|
-
var
|
|
18809
|
-
return (
|
|
19531
|
+
var _a223;
|
|
19532
|
+
return (_a223 = getSpan3(context2)) === null || _a223 === void 0 ? void 0 : _a223.spanContext();
|
|
19533
|
+
}
|
|
19534
|
+
var isHex = new Uint8Array([
|
|
19535
|
+
0,
|
|
19536
|
+
0,
|
|
19537
|
+
0,
|
|
19538
|
+
0,
|
|
19539
|
+
0,
|
|
19540
|
+
0,
|
|
19541
|
+
0,
|
|
19542
|
+
0,
|
|
19543
|
+
0,
|
|
19544
|
+
0,
|
|
19545
|
+
0,
|
|
19546
|
+
0,
|
|
19547
|
+
0,
|
|
19548
|
+
0,
|
|
19549
|
+
0,
|
|
19550
|
+
0,
|
|
19551
|
+
0,
|
|
19552
|
+
0,
|
|
19553
|
+
0,
|
|
19554
|
+
0,
|
|
19555
|
+
0,
|
|
19556
|
+
0,
|
|
19557
|
+
0,
|
|
19558
|
+
0,
|
|
19559
|
+
0,
|
|
19560
|
+
0,
|
|
19561
|
+
0,
|
|
19562
|
+
0,
|
|
19563
|
+
0,
|
|
19564
|
+
0,
|
|
19565
|
+
0,
|
|
19566
|
+
0,
|
|
19567
|
+
0,
|
|
19568
|
+
0,
|
|
19569
|
+
0,
|
|
19570
|
+
0,
|
|
19571
|
+
0,
|
|
19572
|
+
0,
|
|
19573
|
+
0,
|
|
19574
|
+
0,
|
|
19575
|
+
0,
|
|
19576
|
+
0,
|
|
19577
|
+
0,
|
|
19578
|
+
0,
|
|
19579
|
+
0,
|
|
19580
|
+
0,
|
|
19581
|
+
0,
|
|
19582
|
+
0,
|
|
19583
|
+
1,
|
|
19584
|
+
1,
|
|
19585
|
+
1,
|
|
19586
|
+
1,
|
|
19587
|
+
1,
|
|
19588
|
+
1,
|
|
19589
|
+
1,
|
|
19590
|
+
1,
|
|
19591
|
+
1,
|
|
19592
|
+
1,
|
|
19593
|
+
0,
|
|
19594
|
+
0,
|
|
19595
|
+
0,
|
|
19596
|
+
0,
|
|
19597
|
+
0,
|
|
19598
|
+
0,
|
|
19599
|
+
0,
|
|
19600
|
+
1,
|
|
19601
|
+
1,
|
|
19602
|
+
1,
|
|
19603
|
+
1,
|
|
19604
|
+
1,
|
|
19605
|
+
1,
|
|
19606
|
+
0,
|
|
19607
|
+
0,
|
|
19608
|
+
0,
|
|
19609
|
+
0,
|
|
19610
|
+
0,
|
|
19611
|
+
0,
|
|
19612
|
+
0,
|
|
19613
|
+
0,
|
|
19614
|
+
0,
|
|
19615
|
+
0,
|
|
19616
|
+
0,
|
|
19617
|
+
0,
|
|
19618
|
+
0,
|
|
19619
|
+
0,
|
|
19620
|
+
0,
|
|
19621
|
+
0,
|
|
19622
|
+
0,
|
|
19623
|
+
0,
|
|
19624
|
+
0,
|
|
19625
|
+
0,
|
|
19626
|
+
0,
|
|
19627
|
+
0,
|
|
19628
|
+
0,
|
|
19629
|
+
0,
|
|
19630
|
+
0,
|
|
19631
|
+
0,
|
|
19632
|
+
1,
|
|
19633
|
+
1,
|
|
19634
|
+
1,
|
|
19635
|
+
1,
|
|
19636
|
+
1,
|
|
19637
|
+
1
|
|
19638
|
+
]);
|
|
19639
|
+
function isValidHex(id, length) {
|
|
19640
|
+
if (typeof id !== "string" || id.length !== length)
|
|
19641
|
+
return false;
|
|
19642
|
+
let r = 0;
|
|
19643
|
+
for (let i = 0; i < id.length; i += 4) {
|
|
19644
|
+
r += (isHex[id.charCodeAt(i)] | 0) + (isHex[id.charCodeAt(i + 1)] | 0) + (isHex[id.charCodeAt(i + 2)] | 0) + (isHex[id.charCodeAt(i + 3)] | 0);
|
|
19645
|
+
}
|
|
19646
|
+
return r === length;
|
|
18810
19647
|
}
|
|
18811
|
-
var VALID_TRACEID_REGEX3 = /^([0-9a-f]{32})$/i;
|
|
18812
|
-
var VALID_SPANID_REGEX3 = /^[0-9a-f]{16}$/i;
|
|
18813
19648
|
function isValidTraceId3(traceId) {
|
|
18814
|
-
return
|
|
19649
|
+
return isValidHex(traceId, 32) && traceId !== INVALID_TRACEID3;
|
|
18815
19650
|
}
|
|
18816
19651
|
function isValidSpanId3(spanId) {
|
|
18817
|
-
return
|
|
19652
|
+
return isValidHex(spanId, 16) && spanId !== INVALID_SPANID3;
|
|
18818
19653
|
}
|
|
18819
19654
|
function isSpanContextValid3(spanContext) {
|
|
18820
19655
|
return isValidTraceId3(spanContext.traceId) && isValidSpanId3(spanContext.spanId);
|
|
@@ -18823,119 +19658,105 @@ function wrapSpanContext3(spanContext) {
|
|
|
18823
19658
|
return new NonRecordingSpan3(spanContext);
|
|
18824
19659
|
}
|
|
18825
19660
|
var contextApi3 = ContextAPI3.getInstance();
|
|
18826
|
-
var NoopTracer3 =
|
|
18827
|
-
|
|
18828
|
-
(
|
|
18829
|
-
|
|
19661
|
+
var NoopTracer3 = class {
|
|
19662
|
+
// startSpan starts a noop span.
|
|
19663
|
+
startSpan(name223, options, context2 = contextApi3.active()) {
|
|
19664
|
+
const root = Boolean(options === null || options === void 0 ? void 0 : options.root);
|
|
19665
|
+
if (root) {
|
|
19666
|
+
return new NonRecordingSpan3();
|
|
19667
|
+
}
|
|
19668
|
+
const parentFromContext = context2 && getSpanContext3(context2);
|
|
19669
|
+
if (isSpanContext3(parentFromContext) && isSpanContextValid3(parentFromContext)) {
|
|
19670
|
+
return new NonRecordingSpan3(parentFromContext);
|
|
19671
|
+
} else {
|
|
19672
|
+
return new NonRecordingSpan3();
|
|
18830
19673
|
}
|
|
18831
|
-
|
|
18832
|
-
|
|
18833
|
-
|
|
18834
|
-
|
|
18835
|
-
|
|
18836
|
-
|
|
18837
|
-
|
|
18838
|
-
|
|
18839
|
-
|
|
18840
|
-
|
|
18841
|
-
|
|
18842
|
-
|
|
18843
|
-
|
|
18844
|
-
|
|
18845
|
-
|
|
18846
|
-
|
|
18847
|
-
|
|
18848
|
-
|
|
18849
|
-
|
|
18850
|
-
|
|
18851
|
-
|
|
18852
|
-
|
|
18853
|
-
|
|
18854
|
-
} else if (arguments.length === 3) {
|
|
18855
|
-
opts = arg2;
|
|
18856
|
-
fn = arg3;
|
|
18857
|
-
} else {
|
|
18858
|
-
opts = arg2;
|
|
18859
|
-
ctx = arg3;
|
|
18860
|
-
fn = arg4;
|
|
18861
|
-
}
|
|
18862
|
-
var parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi3.active();
|
|
18863
|
-
var span = this.startSpan(name21, opts, parentContext);
|
|
18864
|
-
var contextWithSpanSet = setSpan3(parentContext, span);
|
|
18865
|
-
return contextApi3.with(contextWithSpanSet, fn, void 0, span);
|
|
18866
|
-
};
|
|
18867
|
-
return NoopTracer22;
|
|
18868
|
-
})()
|
|
18869
|
-
);
|
|
19674
|
+
}
|
|
19675
|
+
startActiveSpan(name223, arg2, arg3, arg4) {
|
|
19676
|
+
let opts;
|
|
19677
|
+
let ctx;
|
|
19678
|
+
let fn;
|
|
19679
|
+
if (arguments.length < 2) {
|
|
19680
|
+
return;
|
|
19681
|
+
} else if (arguments.length === 2) {
|
|
19682
|
+
fn = arg2;
|
|
19683
|
+
} else if (arguments.length === 3) {
|
|
19684
|
+
opts = arg2;
|
|
19685
|
+
fn = arg3;
|
|
19686
|
+
} else {
|
|
19687
|
+
opts = arg2;
|
|
19688
|
+
ctx = arg3;
|
|
19689
|
+
fn = arg4;
|
|
19690
|
+
}
|
|
19691
|
+
const parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi3.active();
|
|
19692
|
+
const span = this.startSpan(name223, opts, parentContext);
|
|
19693
|
+
const contextWithSpanSet = setSpan3(parentContext, span);
|
|
19694
|
+
return contextApi3.with(contextWithSpanSet, fn, void 0, span);
|
|
19695
|
+
}
|
|
19696
|
+
};
|
|
18870
19697
|
function isSpanContext3(spanContext) {
|
|
18871
|
-
return typeof spanContext === "object" && typeof spanContext["spanId"] === "string" && typeof spanContext["traceId"] === "string" && typeof spanContext["traceFlags"] === "number";
|
|
19698
|
+
return spanContext !== null && typeof spanContext === "object" && "spanId" in spanContext && typeof spanContext["spanId"] === "string" && "traceId" in spanContext && typeof spanContext["traceId"] === "string" && "traceFlags" in spanContext && typeof spanContext["traceFlags"] === "number";
|
|
18872
19699
|
}
|
|
18873
19700
|
var NOOP_TRACER3 = new NoopTracer3();
|
|
18874
|
-
var ProxyTracer3 =
|
|
18875
|
-
|
|
18876
|
-
|
|
18877
|
-
|
|
18878
|
-
|
|
18879
|
-
|
|
18880
|
-
|
|
18881
|
-
|
|
18882
|
-
|
|
18883
|
-
|
|
18884
|
-
|
|
18885
|
-
|
|
18886
|
-
|
|
18887
|
-
|
|
18888
|
-
|
|
18889
|
-
|
|
18890
|
-
|
|
18891
|
-
|
|
18892
|
-
|
|
18893
|
-
|
|
18894
|
-
var tracer = this._provider.getDelegateTracer(this.name, this.version, this.options);
|
|
18895
|
-
if (!tracer) {
|
|
18896
|
-
return NOOP_TRACER3;
|
|
18897
|
-
}
|
|
18898
|
-
this._delegate = tracer;
|
|
19701
|
+
var ProxyTracer3 = class {
|
|
19702
|
+
constructor(provider, name223, version, options) {
|
|
19703
|
+
this._provider = provider;
|
|
19704
|
+
this.name = name223;
|
|
19705
|
+
this.version = version;
|
|
19706
|
+
this.options = options;
|
|
19707
|
+
}
|
|
19708
|
+
startSpan(name223, options, context2) {
|
|
19709
|
+
return this._getTracer().startSpan(name223, options, context2);
|
|
19710
|
+
}
|
|
19711
|
+
startActiveSpan(_name, _options, _context, _fn) {
|
|
19712
|
+
const tracer = this._getTracer();
|
|
19713
|
+
return Reflect.apply(tracer.startActiveSpan, tracer, arguments);
|
|
19714
|
+
}
|
|
19715
|
+
/**
|
|
19716
|
+
* Try to get a tracer from the proxy tracer provider.
|
|
19717
|
+
* If the proxy tracer provider has no delegate, return a noop tracer.
|
|
19718
|
+
*/
|
|
19719
|
+
_getTracer() {
|
|
19720
|
+
if (this._delegate) {
|
|
18899
19721
|
return this._delegate;
|
|
18900
|
-
};
|
|
18901
|
-
return ProxyTracer22;
|
|
18902
|
-
})()
|
|
18903
|
-
);
|
|
18904
|
-
var NoopTracerProvider3 = (
|
|
18905
|
-
/** @class */
|
|
18906
|
-
(function() {
|
|
18907
|
-
function NoopTracerProvider22() {
|
|
18908
19722
|
}
|
|
18909
|
-
|
|
18910
|
-
|
|
18911
|
-
|
|
18912
|
-
return NoopTracerProvider22;
|
|
18913
|
-
})()
|
|
18914
|
-
);
|
|
18915
|
-
var NOOP_TRACER_PROVIDER3 = new NoopTracerProvider3();
|
|
18916
|
-
var ProxyTracerProvider3 = (
|
|
18917
|
-
/** @class */
|
|
18918
|
-
(function() {
|
|
18919
|
-
function ProxyTracerProvider22() {
|
|
19723
|
+
const tracer = this._provider.getDelegateTracer(this.name, this.version, this.options);
|
|
19724
|
+
if (!tracer) {
|
|
19725
|
+
return NOOP_TRACER3;
|
|
18920
19726
|
}
|
|
18921
|
-
|
|
18922
|
-
|
|
18923
|
-
|
|
18924
|
-
|
|
18925
|
-
|
|
18926
|
-
|
|
18927
|
-
|
|
18928
|
-
|
|
18929
|
-
|
|
18930
|
-
|
|
18931
|
-
|
|
18932
|
-
|
|
18933
|
-
|
|
18934
|
-
|
|
18935
|
-
|
|
18936
|
-
|
|
18937
|
-
|
|
18938
|
-
|
|
19727
|
+
this._delegate = tracer;
|
|
19728
|
+
return this._delegate;
|
|
19729
|
+
}
|
|
19730
|
+
};
|
|
19731
|
+
var NoopTracerProvider3 = class {
|
|
19732
|
+
getTracer(_name, _version, _options) {
|
|
19733
|
+
return new NoopTracer3();
|
|
19734
|
+
}
|
|
19735
|
+
};
|
|
19736
|
+
var NOOP_TRACER_PROVIDER3 = new NoopTracerProvider3();
|
|
19737
|
+
var ProxyTracerProvider3 = class {
|
|
19738
|
+
/**
|
|
19739
|
+
* Get a {@link ProxyTracer}
|
|
19740
|
+
*/
|
|
19741
|
+
getTracer(name223, version, options) {
|
|
19742
|
+
var _a223;
|
|
19743
|
+
return (_a223 = this.getDelegateTracer(name223, version, options)) !== null && _a223 !== void 0 ? _a223 : new ProxyTracer3(this, name223, version, options);
|
|
19744
|
+
}
|
|
19745
|
+
getDelegate() {
|
|
19746
|
+
var _a223;
|
|
19747
|
+
return (_a223 = this._delegate) !== null && _a223 !== void 0 ? _a223 : NOOP_TRACER_PROVIDER3;
|
|
19748
|
+
}
|
|
19749
|
+
/**
|
|
19750
|
+
* Set the delegate tracer provider
|
|
19751
|
+
*/
|
|
19752
|
+
setDelegate(delegate) {
|
|
19753
|
+
this._delegate = delegate;
|
|
19754
|
+
}
|
|
19755
|
+
getDelegateTracer(name223, version, options) {
|
|
19756
|
+
var _a223;
|
|
19757
|
+
return (_a223 = this._delegate) === null || _a223 === void 0 ? void 0 : _a223.getTracer(name223, version, options);
|
|
19758
|
+
}
|
|
19759
|
+
};
|
|
18939
19760
|
var SpanStatusCode3;
|
|
18940
19761
|
(function(SpanStatusCode22) {
|
|
18941
19762
|
SpanStatusCode22[SpanStatusCode22["UNSET"] = 0] = "UNSET";
|
|
@@ -18944,56 +19765,66 @@ var SpanStatusCode3;
|
|
|
18944
19765
|
})(SpanStatusCode3 || (SpanStatusCode3 = {}));
|
|
18945
19766
|
var context = ContextAPI3.getInstance();
|
|
18946
19767
|
var API_NAME33 = "trace";
|
|
18947
|
-
var TraceAPI3 =
|
|
18948
|
-
/**
|
|
18949
|
-
(
|
|
18950
|
-
|
|
18951
|
-
|
|
18952
|
-
|
|
18953
|
-
|
|
18954
|
-
|
|
18955
|
-
|
|
18956
|
-
|
|
18957
|
-
|
|
18958
|
-
|
|
18959
|
-
|
|
19768
|
+
var TraceAPI3 = class _TraceAPI {
|
|
19769
|
+
/** Empty private constructor prevents end users from constructing a new instance of the API */
|
|
19770
|
+
constructor() {
|
|
19771
|
+
this._proxyTracerProvider = new ProxyTracerProvider3();
|
|
19772
|
+
this.wrapSpanContext = wrapSpanContext3;
|
|
19773
|
+
this.isSpanContextValid = isSpanContextValid3;
|
|
19774
|
+
this.deleteSpan = deleteSpan3;
|
|
19775
|
+
this.getSpan = getSpan3;
|
|
19776
|
+
this.getActiveSpan = getActiveSpan3;
|
|
19777
|
+
this.getSpanContext = getSpanContext3;
|
|
19778
|
+
this.setSpan = setSpan3;
|
|
19779
|
+
this.setSpanContext = setSpanContext3;
|
|
19780
|
+
}
|
|
19781
|
+
/** Get the singleton instance of the Trace API */
|
|
19782
|
+
static getInstance() {
|
|
19783
|
+
if (!this._instance) {
|
|
19784
|
+
this._instance = new _TraceAPI();
|
|
19785
|
+
}
|
|
19786
|
+
return this._instance;
|
|
19787
|
+
}
|
|
19788
|
+
/**
|
|
19789
|
+
* Set the current global tracer.
|
|
19790
|
+
*
|
|
19791
|
+
* @returns true if the tracer provider was successfully registered, else false
|
|
19792
|
+
*/
|
|
19793
|
+
setGlobalTracerProvider(provider) {
|
|
19794
|
+
const success = registerGlobal3(API_NAME33, this._proxyTracerProvider, DiagAPI3.instance());
|
|
19795
|
+
if (success) {
|
|
19796
|
+
this._proxyTracerProvider.setDelegate(provider);
|
|
18960
19797
|
}
|
|
18961
|
-
|
|
18962
|
-
|
|
18963
|
-
|
|
18964
|
-
|
|
18965
|
-
|
|
18966
|
-
|
|
18967
|
-
|
|
18968
|
-
|
|
18969
|
-
|
|
18970
|
-
|
|
18971
|
-
|
|
18972
|
-
|
|
18973
|
-
|
|
18974
|
-
|
|
18975
|
-
|
|
18976
|
-
|
|
18977
|
-
|
|
18978
|
-
|
|
18979
|
-
|
|
18980
|
-
|
|
18981
|
-
unregisterGlobal3(API_NAME33, DiagAPI3.instance());
|
|
18982
|
-
this._proxyTracerProvider = new ProxyTracerProvider3();
|
|
18983
|
-
};
|
|
18984
|
-
return TraceAPI22;
|
|
18985
|
-
})()
|
|
18986
|
-
);
|
|
19798
|
+
return success;
|
|
19799
|
+
}
|
|
19800
|
+
/**
|
|
19801
|
+
* Returns the global tracer provider.
|
|
19802
|
+
*/
|
|
19803
|
+
getTracerProvider() {
|
|
19804
|
+
return getGlobal3(API_NAME33) || this._proxyTracerProvider;
|
|
19805
|
+
}
|
|
19806
|
+
/**
|
|
19807
|
+
* Returns a tracer from the global tracer provider.
|
|
19808
|
+
*/
|
|
19809
|
+
getTracer(name223, version) {
|
|
19810
|
+
return this.getTracerProvider().getTracer(name223, version);
|
|
19811
|
+
}
|
|
19812
|
+
/** Remove the global tracer provider */
|
|
19813
|
+
disable() {
|
|
19814
|
+
unregisterGlobal3(API_NAME33, DiagAPI3.instance());
|
|
19815
|
+
this._proxyTracerProvider = new ProxyTracerProvider3();
|
|
19816
|
+
}
|
|
19817
|
+
};
|
|
18987
19818
|
var trace3 = TraceAPI3.getInstance();
|
|
18988
19819
|
var __defProp4 = Object.defineProperty;
|
|
18989
19820
|
var __export3 = (target, all) => {
|
|
18990
|
-
for (var
|
|
18991
|
-
__defProp4(target,
|
|
19821
|
+
for (var name223 in all)
|
|
19822
|
+
__defProp4(target, name223, { get: all[name223], enumerable: true });
|
|
18992
19823
|
};
|
|
18993
|
-
var
|
|
18994
|
-
var
|
|
18995
|
-
var
|
|
18996
|
-
var
|
|
19824
|
+
var name21 = "AI_InvalidArgumentError";
|
|
19825
|
+
var marker21 = `vercel.ai.error.${name21}`;
|
|
19826
|
+
var symbol21 = Symbol.for(marker21);
|
|
19827
|
+
var _a21;
|
|
18997
19828
|
var InvalidArgumentError23 = class extends AISDKError3 {
|
|
18998
19829
|
constructor({
|
|
18999
19830
|
parameter,
|
|
@@ -19001,22 +19832,22 @@ var InvalidArgumentError23 = class extends AISDKError3 {
|
|
|
19001
19832
|
message
|
|
19002
19833
|
}) {
|
|
19003
19834
|
super({
|
|
19004
|
-
name:
|
|
19835
|
+
name: name21,
|
|
19005
19836
|
message: `Invalid argument for parameter ${parameter}: ${message}`
|
|
19006
19837
|
});
|
|
19007
|
-
this[
|
|
19838
|
+
this[_a21] = true;
|
|
19008
19839
|
this.parameter = parameter;
|
|
19009
19840
|
this.value = value;
|
|
19010
19841
|
}
|
|
19011
19842
|
static isInstance(error) {
|
|
19012
|
-
return AISDKError3.hasMarker(error,
|
|
19843
|
+
return AISDKError3.hasMarker(error, marker21);
|
|
19013
19844
|
}
|
|
19014
19845
|
};
|
|
19015
|
-
|
|
19016
|
-
var
|
|
19017
|
-
var
|
|
19018
|
-
var
|
|
19019
|
-
var
|
|
19846
|
+
_a21 = symbol21;
|
|
19847
|
+
var name97 = "AI_NoObjectGeneratedError";
|
|
19848
|
+
var marker97 = `vercel.ai.error.${name97}`;
|
|
19849
|
+
var symbol97 = Symbol.for(marker97);
|
|
19850
|
+
var _a97;
|
|
19020
19851
|
var NoObjectGeneratedError3 = class extends AISDKError3 {
|
|
19021
19852
|
constructor({
|
|
19022
19853
|
message = "No object generated.",
|
|
@@ -19026,18 +19857,18 @@ var NoObjectGeneratedError3 = class extends AISDKError3 {
|
|
|
19026
19857
|
usage,
|
|
19027
19858
|
finishReason
|
|
19028
19859
|
}) {
|
|
19029
|
-
super({ name:
|
|
19030
|
-
this[
|
|
19860
|
+
super({ name: name97, message, cause });
|
|
19861
|
+
this[_a97] = true;
|
|
19031
19862
|
this.text = text22;
|
|
19032
19863
|
this.response = response;
|
|
19033
19864
|
this.usage = usage;
|
|
19034
19865
|
this.finishReason = finishReason;
|
|
19035
19866
|
}
|
|
19036
19867
|
static isInstance(error) {
|
|
19037
|
-
return AISDKError3.hasMarker(error,
|
|
19868
|
+
return AISDKError3.hasMarker(error, marker97);
|
|
19038
19869
|
}
|
|
19039
19870
|
};
|
|
19040
|
-
|
|
19871
|
+
_a97 = symbol97;
|
|
19041
19872
|
var UnsupportedModelVersionError3 = class extends AISDKError3 {
|
|
19042
19873
|
constructor(options) {
|
|
19043
19874
|
super({
|
|
@@ -19049,27 +19880,27 @@ var UnsupportedModelVersionError3 = class extends AISDKError3 {
|
|
|
19049
19880
|
this.modelId = options.modelId;
|
|
19050
19881
|
}
|
|
19051
19882
|
};
|
|
19052
|
-
var
|
|
19053
|
-
var
|
|
19054
|
-
var
|
|
19055
|
-
var
|
|
19883
|
+
var name202 = "AI_RetryError";
|
|
19884
|
+
var marker202 = `vercel.ai.error.${name202}`;
|
|
19885
|
+
var symbol202 = Symbol.for(marker202);
|
|
19886
|
+
var _a202;
|
|
19056
19887
|
var RetryError3 = class extends AISDKError3 {
|
|
19057
19888
|
constructor({
|
|
19058
19889
|
message,
|
|
19059
19890
|
reason,
|
|
19060
19891
|
errors
|
|
19061
19892
|
}) {
|
|
19062
|
-
super({ name:
|
|
19063
|
-
this[
|
|
19893
|
+
super({ name: name202, message });
|
|
19894
|
+
this[_a202] = true;
|
|
19064
19895
|
this.reason = reason;
|
|
19065
19896
|
this.errors = errors;
|
|
19066
19897
|
this.lastError = errors[errors.length - 1];
|
|
19067
19898
|
}
|
|
19068
19899
|
static isInstance(error) {
|
|
19069
|
-
return AISDKError3.hasMarker(error,
|
|
19900
|
+
return AISDKError3.hasMarker(error, marker202);
|
|
19070
19901
|
}
|
|
19071
19902
|
};
|
|
19072
|
-
|
|
19903
|
+
_a202 = symbol202;
|
|
19073
19904
|
function formatWarning({
|
|
19074
19905
|
warning,
|
|
19075
19906
|
provider,
|
|
@@ -19174,8 +20005,8 @@ function resolveEmbeddingModel2(model) {
|
|
|
19174
20005
|
return getGlobalProvider2().embeddingModel(model);
|
|
19175
20006
|
}
|
|
19176
20007
|
function getGlobalProvider2() {
|
|
19177
|
-
var
|
|
19178
|
-
return (
|
|
20008
|
+
var _a223;
|
|
20009
|
+
return (_a223 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a223 : gateway2;
|
|
19179
20010
|
}
|
|
19180
20011
|
function getTotalTimeoutMs(timeout) {
|
|
19181
20012
|
if (timeout == null) {
|
|
@@ -19186,7 +20017,7 @@ function getTotalTimeoutMs(timeout) {
|
|
|
19186
20017
|
}
|
|
19187
20018
|
return timeout.totalMs;
|
|
19188
20019
|
}
|
|
19189
|
-
var
|
|
20020
|
+
var VERSION23 = "6.0.224";
|
|
19190
20021
|
var dataContentSchema3 = z$1.union([
|
|
19191
20022
|
z$1.string(),
|
|
19192
20023
|
z$1.instanceof(Uint8Array),
|
|
@@ -19194,8 +20025,8 @@ var dataContentSchema3 = z$1.union([
|
|
|
19194
20025
|
z$1.custom(
|
|
19195
20026
|
// Buffer might not be available in some environments such as CloudFlare:
|
|
19196
20027
|
(value) => {
|
|
19197
|
-
var
|
|
19198
|
-
return (
|
|
20028
|
+
var _a223, _b19;
|
|
20029
|
+
return (_b19 = (_a223 = globalThis.Buffer) == null ? void 0 : _a223.isBuffer(value)) != null ? _b19 : false;
|
|
19199
20030
|
},
|
|
19200
20031
|
{ message: "Must be a Buffer" }
|
|
19201
20032
|
)
|
|
@@ -19409,7 +20240,7 @@ function getBaseTelemetryAttributes3({
|
|
|
19409
20240
|
telemetry,
|
|
19410
20241
|
headers
|
|
19411
20242
|
}) {
|
|
19412
|
-
var
|
|
20243
|
+
var _a223;
|
|
19413
20244
|
return {
|
|
19414
20245
|
"ai.model.provider": model.provider,
|
|
19415
20246
|
"ai.model.id": model.modelId,
|
|
@@ -19428,7 +20259,7 @@ function getBaseTelemetryAttributes3({
|
|
|
19428
20259
|
return attributes;
|
|
19429
20260
|
}, {}),
|
|
19430
20261
|
// add metadata as attributes:
|
|
19431
|
-
...Object.entries((
|
|
20262
|
+
...Object.entries((_a223 = telemetry == null ? void 0 : telemetry.metadata) != null ? _a223 : {}).reduce(
|
|
19432
20263
|
(attributes, [key, value]) => {
|
|
19433
20264
|
attributes[`ai.telemetry.metadata.${key}`] = value;
|
|
19434
20265
|
return attributes;
|
|
@@ -19448,7 +20279,7 @@ var noopTracer3 = {
|
|
|
19448
20279
|
startSpan() {
|
|
19449
20280
|
return noopSpan3;
|
|
19450
20281
|
},
|
|
19451
|
-
startActiveSpan(
|
|
20282
|
+
startActiveSpan(name223, arg1, arg2, arg3) {
|
|
19452
20283
|
if (typeof arg1 === "function") {
|
|
19453
20284
|
return arg1(noopSpan3);
|
|
19454
20285
|
}
|
|
@@ -19513,14 +20344,14 @@ function getTracer3({
|
|
|
19513
20344
|
return trace3.getTracer("ai");
|
|
19514
20345
|
}
|
|
19515
20346
|
async function recordSpan3({
|
|
19516
|
-
name:
|
|
20347
|
+
name: name223,
|
|
19517
20348
|
tracer,
|
|
19518
20349
|
attributes,
|
|
19519
20350
|
fn,
|
|
19520
20351
|
endWhenDone = true
|
|
19521
20352
|
}) {
|
|
19522
20353
|
return tracer.startActiveSpan(
|
|
19523
|
-
|
|
20354
|
+
name223,
|
|
19524
20355
|
{ attributes: await attributes },
|
|
19525
20356
|
async (span) => {
|
|
19526
20357
|
const ctx = context.active();
|
|
@@ -19556,6 +20387,28 @@ function recordErrorOnSpan3(span, error) {
|
|
|
19556
20387
|
span.setStatus({ code: SpanStatusCode3.ERROR });
|
|
19557
20388
|
}
|
|
19558
20389
|
}
|
|
20390
|
+
function isPrimitiveAttributeValue(value) {
|
|
20391
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
20392
|
+
}
|
|
20393
|
+
function sanitizeAttributeValue(value) {
|
|
20394
|
+
if (!Array.isArray(value)) {
|
|
20395
|
+
return value;
|
|
20396
|
+
}
|
|
20397
|
+
const primitiveTypes = new Set(
|
|
20398
|
+
value.filter(isPrimitiveAttributeValue).map((item) => typeof item)
|
|
20399
|
+
);
|
|
20400
|
+
if (primitiveTypes.size !== 1) {
|
|
20401
|
+
return void 0;
|
|
20402
|
+
}
|
|
20403
|
+
const [primitiveType] = primitiveTypes;
|
|
20404
|
+
if (primitiveType === "string") {
|
|
20405
|
+
return value.filter((item) => typeof item === "string");
|
|
20406
|
+
}
|
|
20407
|
+
if (primitiveType === "number") {
|
|
20408
|
+
return value.filter((item) => typeof item === "number");
|
|
20409
|
+
}
|
|
20410
|
+
return value.filter((item) => typeof item === "boolean");
|
|
20411
|
+
}
|
|
19559
20412
|
async function selectTelemetryAttributes3({
|
|
19560
20413
|
telemetry,
|
|
19561
20414
|
attributes
|
|
@@ -19574,7 +20427,9 @@ async function selectTelemetryAttributes3({
|
|
|
19574
20427
|
}
|
|
19575
20428
|
const result = await value.input();
|
|
19576
20429
|
if (result != null) {
|
|
19577
|
-
|
|
20430
|
+
const sanitized2 = sanitizeAttributeValue(result);
|
|
20431
|
+
if (sanitized2 != null)
|
|
20432
|
+
resultAttributes[key] = sanitized2;
|
|
19578
20433
|
}
|
|
19579
20434
|
continue;
|
|
19580
20435
|
}
|
|
@@ -19584,11 +20439,15 @@ async function selectTelemetryAttributes3({
|
|
|
19584
20439
|
}
|
|
19585
20440
|
const result = await value.output();
|
|
19586
20441
|
if (result != null) {
|
|
19587
|
-
|
|
20442
|
+
const sanitized2 = sanitizeAttributeValue(result);
|
|
20443
|
+
if (sanitized2 != null)
|
|
20444
|
+
resultAttributes[key] = sanitized2;
|
|
19588
20445
|
}
|
|
19589
20446
|
continue;
|
|
19590
20447
|
}
|
|
19591
|
-
|
|
20448
|
+
const sanitized = sanitizeAttributeValue(value);
|
|
20449
|
+
if (sanitized != null)
|
|
20450
|
+
resultAttributes[key] = sanitized;
|
|
19592
20451
|
}
|
|
19593
20452
|
return resultAttributes;
|
|
19594
20453
|
}
|
|
@@ -19596,7 +20455,7 @@ function getRetryDelayInMs2({
|
|
|
19596
20455
|
error,
|
|
19597
20456
|
exponentialBackoffDelay
|
|
19598
20457
|
}) {
|
|
19599
|
-
const headers = error.responseHeaders;
|
|
20458
|
+
const headers = APICallError3.isInstance(error) ? error.responseHeaders : APICallError3.isInstance(error.cause) ? error.cause.responseHeaders : void 0;
|
|
19600
20459
|
if (!headers)
|
|
19601
20460
|
return exponentialBackoffDelay;
|
|
19602
20461
|
let ms;
|
|
@@ -19626,66 +20485,18 @@ var retryWithExponentialBackoffRespectingRetryHeaders2 = ({
|
|
|
19626
20485
|
initialDelayInMs = 2e3,
|
|
19627
20486
|
backoffFactor = 2,
|
|
19628
20487
|
abortSignal
|
|
19629
|
-
} = {}) =>
|
|
20488
|
+
} = {}) => retryWithExponentialBackoff2({
|
|
19630
20489
|
maxRetries,
|
|
19631
|
-
|
|
20490
|
+
initialDelayInMs,
|
|
19632
20491
|
backoffFactor,
|
|
19633
|
-
abortSignal
|
|
20492
|
+
abortSignal,
|
|
20493
|
+
shouldRetry: (error) => error instanceof Error && (APICallError3.isInstance(error) && error.isRetryable === true || GatewayError2.isInstance(error) && error.isRetryable === true),
|
|
20494
|
+
getDelayInMs: ({ error, exponentialBackoffDelay }) => getRetryDelayInMs2({
|
|
20495
|
+
error,
|
|
20496
|
+
exponentialBackoffDelay
|
|
20497
|
+
}),
|
|
20498
|
+
createRetryError: ({ message, reason, errors }) => new RetryError3({ message, reason, errors })
|
|
19634
20499
|
});
|
|
19635
|
-
async function _retryWithExponentialBackoff3(f, {
|
|
19636
|
-
maxRetries,
|
|
19637
|
-
delayInMs,
|
|
19638
|
-
backoffFactor,
|
|
19639
|
-
abortSignal
|
|
19640
|
-
}, errors = []) {
|
|
19641
|
-
try {
|
|
19642
|
-
return await f();
|
|
19643
|
-
} catch (error) {
|
|
19644
|
-
if (isAbortError5(error)) {
|
|
19645
|
-
throw error;
|
|
19646
|
-
}
|
|
19647
|
-
if (maxRetries === 0) {
|
|
19648
|
-
throw error;
|
|
19649
|
-
}
|
|
19650
|
-
const errorMessage = getErrorMessage23(error);
|
|
19651
|
-
const newErrors = [...errors, error];
|
|
19652
|
-
const tryNumber = newErrors.length;
|
|
19653
|
-
if (tryNumber > maxRetries) {
|
|
19654
|
-
throw new RetryError3({
|
|
19655
|
-
message: `Failed after ${tryNumber} attempts. Last error: ${errorMessage}`,
|
|
19656
|
-
reason: "maxRetriesExceeded",
|
|
19657
|
-
errors: newErrors
|
|
19658
|
-
});
|
|
19659
|
-
}
|
|
19660
|
-
if (error instanceof Error && APICallError3.isInstance(error) && error.isRetryable === true && tryNumber <= maxRetries) {
|
|
19661
|
-
await delay3(
|
|
19662
|
-
getRetryDelayInMs2({
|
|
19663
|
-
error,
|
|
19664
|
-
exponentialBackoffDelay: delayInMs
|
|
19665
|
-
}),
|
|
19666
|
-
{ abortSignal }
|
|
19667
|
-
);
|
|
19668
|
-
return _retryWithExponentialBackoff3(
|
|
19669
|
-
f,
|
|
19670
|
-
{
|
|
19671
|
-
maxRetries,
|
|
19672
|
-
delayInMs: backoffFactor * delayInMs,
|
|
19673
|
-
backoffFactor,
|
|
19674
|
-
abortSignal
|
|
19675
|
-
},
|
|
19676
|
-
newErrors
|
|
19677
|
-
);
|
|
19678
|
-
}
|
|
19679
|
-
if (tryNumber === 1) {
|
|
19680
|
-
throw error;
|
|
19681
|
-
}
|
|
19682
|
-
throw new RetryError3({
|
|
19683
|
-
message: `Failed after ${tryNumber} attempts with non-retryable error: '${errorMessage}'`,
|
|
19684
|
-
reason: "errorNotRetryable",
|
|
19685
|
-
errors: newErrors
|
|
19686
|
-
});
|
|
19687
|
-
}
|
|
19688
|
-
}
|
|
19689
20500
|
function prepareRetries3({
|
|
19690
20501
|
maxRetries,
|
|
19691
20502
|
abortSignal
|
|
@@ -19715,6 +20526,7 @@ function prepareRetries3({
|
|
|
19715
20526
|
})
|
|
19716
20527
|
};
|
|
19717
20528
|
}
|
|
20529
|
+
new TextEncoder();
|
|
19718
20530
|
var output_exports3 = {};
|
|
19719
20531
|
__export3(output_exports3, {
|
|
19720
20532
|
array: () => array,
|
|
@@ -19727,6 +20539,10 @@ function fixJson3(input) {
|
|
|
19727
20539
|
const stack = ["ROOT"];
|
|
19728
20540
|
let lastValidIndex = -1;
|
|
19729
20541
|
let literalStart = null;
|
|
20542
|
+
let unicodeEscapeDigits = 0;
|
|
20543
|
+
function isHexDigit(char) {
|
|
20544
|
+
return char >= "0" && char <= "9" || char >= "A" && char <= "F" || char >= "a" && char <= "f";
|
|
20545
|
+
}
|
|
19730
20546
|
function processValueStart(char, i, swapState) {
|
|
19731
20547
|
{
|
|
19732
20548
|
switch (char) {
|
|
@@ -19931,7 +20747,22 @@ function fixJson3(input) {
|
|
|
19931
20747
|
}
|
|
19932
20748
|
case "INSIDE_STRING_ESCAPE": {
|
|
19933
20749
|
stack.pop();
|
|
19934
|
-
|
|
20750
|
+
if (char === "u") {
|
|
20751
|
+
unicodeEscapeDigits = 0;
|
|
20752
|
+
stack.push("INSIDE_STRING_UNICODE_ESCAPE");
|
|
20753
|
+
} else {
|
|
20754
|
+
lastValidIndex = i;
|
|
20755
|
+
}
|
|
20756
|
+
break;
|
|
20757
|
+
}
|
|
20758
|
+
case "INSIDE_STRING_UNICODE_ESCAPE": {
|
|
20759
|
+
if (isHexDigit(char)) {
|
|
20760
|
+
unicodeEscapeDigits++;
|
|
20761
|
+
if (unicodeEscapeDigits === 4) {
|
|
20762
|
+
stack.pop();
|
|
20763
|
+
lastValidIndex = i;
|
|
20764
|
+
}
|
|
20765
|
+
}
|
|
19935
20766
|
break;
|
|
19936
20767
|
}
|
|
19937
20768
|
case "INSIDE_NUMBER": {
|
|
@@ -20068,7 +20899,7 @@ var text3 = () => ({
|
|
|
20068
20899
|
});
|
|
20069
20900
|
var object3 = ({
|
|
20070
20901
|
schema: inputSchema,
|
|
20071
|
-
name:
|
|
20902
|
+
name: name223,
|
|
20072
20903
|
description
|
|
20073
20904
|
}) => {
|
|
20074
20905
|
const schema = asSchema3(inputSchema);
|
|
@@ -20077,7 +20908,7 @@ var object3 = ({
|
|
|
20077
20908
|
responseFormat: resolve2(schema.jsonSchema).then((jsonSchema22) => ({
|
|
20078
20909
|
type: "json",
|
|
20079
20910
|
schema: jsonSchema22,
|
|
20080
|
-
...
|
|
20911
|
+
...name223 != null && { name: name223 },
|
|
20081
20912
|
...description != null && { description }
|
|
20082
20913
|
})),
|
|
20083
20914
|
async parseCompleteOutput({ text: text22 }, context2) {
|
|
@@ -20131,7 +20962,7 @@ var object3 = ({
|
|
|
20131
20962
|
};
|
|
20132
20963
|
var array = ({
|
|
20133
20964
|
element: inputElementSchema,
|
|
20134
|
-
name:
|
|
20965
|
+
name: name223,
|
|
20135
20966
|
description
|
|
20136
20967
|
}) => {
|
|
20137
20968
|
const elementSchema = asSchema3(inputElementSchema);
|
|
@@ -20151,7 +20982,7 @@ var array = ({
|
|
|
20151
20982
|
required: ["elements"],
|
|
20152
20983
|
additionalProperties: false
|
|
20153
20984
|
},
|
|
20154
|
-
...
|
|
20985
|
+
...name223 != null && { name: name223 },
|
|
20155
20986
|
...description != null && { description }
|
|
20156
20987
|
};
|
|
20157
20988
|
}),
|
|
@@ -20181,6 +21012,7 @@ var array = ({
|
|
|
20181
21012
|
finishReason: context2.finishReason
|
|
20182
21013
|
});
|
|
20183
21014
|
}
|
|
21015
|
+
const validatedElements = [];
|
|
20184
21016
|
for (const element of outerValue.elements) {
|
|
20185
21017
|
const validationResult = await safeValidateTypes3({
|
|
20186
21018
|
value: element,
|
|
@@ -20196,8 +21028,9 @@ var array = ({
|
|
|
20196
21028
|
finishReason: context2.finishReason
|
|
20197
21029
|
});
|
|
20198
21030
|
}
|
|
21031
|
+
validatedElements.push(validationResult.value);
|
|
20199
21032
|
}
|
|
20200
|
-
return
|
|
21033
|
+
return validatedElements;
|
|
20201
21034
|
},
|
|
20202
21035
|
async parsePartialOutput({ text: text22 }) {
|
|
20203
21036
|
const result = await parsePartialJson3(text22);
|
|
@@ -20243,7 +21076,7 @@ var array = ({
|
|
|
20243
21076
|
};
|
|
20244
21077
|
var choice = ({
|
|
20245
21078
|
options: choiceOptions,
|
|
20246
|
-
name:
|
|
21079
|
+
name: name223,
|
|
20247
21080
|
description
|
|
20248
21081
|
}) => {
|
|
20249
21082
|
return {
|
|
@@ -20260,7 +21093,7 @@ var choice = ({
|
|
|
20260
21093
|
required: ["result"],
|
|
20261
21094
|
additionalProperties: false
|
|
20262
21095
|
},
|
|
20263
|
-
...
|
|
21096
|
+
...name223 != null && { name: name223 },
|
|
20264
21097
|
...description != null && { description }
|
|
20265
21098
|
}),
|
|
20266
21099
|
async parseCompleteOutput({ text: text22 }, context2) {
|
|
@@ -20321,14 +21154,14 @@ var choice = ({
|
|
|
20321
21154
|
};
|
|
20322
21155
|
};
|
|
20323
21156
|
var json = ({
|
|
20324
|
-
name:
|
|
21157
|
+
name: name223,
|
|
20325
21158
|
description
|
|
20326
21159
|
} = {}) => {
|
|
20327
21160
|
return {
|
|
20328
21161
|
name: "json",
|
|
20329
21162
|
responseFormat: Promise.resolve({
|
|
20330
21163
|
type: "json",
|
|
20331
|
-
...
|
|
21164
|
+
...name223 != null && { name: name223 },
|
|
20332
21165
|
...description != null && { description }
|
|
20333
21166
|
}),
|
|
20334
21167
|
async parseCompleteOutput({ text: text22 }, context2) {
|
|
@@ -20406,7 +21239,7 @@ async function embedMany3({
|
|
|
20406
21239
|
});
|
|
20407
21240
|
const headersWithUserAgent = withUserAgentSuffix2(
|
|
20408
21241
|
headers != null ? headers : {},
|
|
20409
|
-
`ai/${
|
|
21242
|
+
`ai/${VERSION23}`
|
|
20410
21243
|
);
|
|
20411
21244
|
const baseTelemetryAttributes = getBaseTelemetryAttributes3({
|
|
20412
21245
|
model,
|
|
@@ -20430,7 +21263,7 @@ async function embedMany3({
|
|
|
20430
21263
|
}),
|
|
20431
21264
|
tracer,
|
|
20432
21265
|
fn: async (span) => {
|
|
20433
|
-
var
|
|
21266
|
+
var _a223;
|
|
20434
21267
|
const [maxEmbeddingsPerCall, supportsParallelCalls] = await Promise.all([
|
|
20435
21268
|
model.maxEmbeddingsPerCall,
|
|
20436
21269
|
model.supportsParallelCalls
|
|
@@ -20455,7 +21288,7 @@ async function embedMany3({
|
|
|
20455
21288
|
}),
|
|
20456
21289
|
tracer,
|
|
20457
21290
|
fn: async (doEmbedSpan) => {
|
|
20458
|
-
var
|
|
21291
|
+
var _a232, _b19;
|
|
20459
21292
|
const modelResponse = await model.doEmbed({
|
|
20460
21293
|
values,
|
|
20461
21294
|
abortSignal,
|
|
@@ -20463,7 +21296,7 @@ async function embedMany3({
|
|
|
20463
21296
|
providerOptions
|
|
20464
21297
|
});
|
|
20465
21298
|
const embeddings3 = modelResponse.embeddings;
|
|
20466
|
-
const usage2 = (
|
|
21299
|
+
const usage2 = (_a232 = modelResponse.usage) != null ? _a232 : { tokens: NaN };
|
|
20467
21300
|
doEmbedSpan.setAttributes(
|
|
20468
21301
|
await selectTelemetryAttributes3({
|
|
20469
21302
|
telemetry,
|
|
@@ -20480,7 +21313,7 @@ async function embedMany3({
|
|
|
20480
21313
|
return {
|
|
20481
21314
|
embeddings: embeddings3,
|
|
20482
21315
|
usage: usage2,
|
|
20483
|
-
warnings: modelResponse.warnings,
|
|
21316
|
+
warnings: (_b19 = modelResponse.warnings) != null ? _b19 : [],
|
|
20484
21317
|
providerMetadata: modelResponse.providerMetadata,
|
|
20485
21318
|
response: modelResponse.response
|
|
20486
21319
|
};
|
|
@@ -20544,7 +21377,7 @@ async function embedMany3({
|
|
|
20544
21377
|
}),
|
|
20545
21378
|
tracer,
|
|
20546
21379
|
fn: async (doEmbedSpan) => {
|
|
20547
|
-
var
|
|
21380
|
+
var _a232, _b19;
|
|
20548
21381
|
const modelResponse = await model.doEmbed({
|
|
20549
21382
|
values: chunk,
|
|
20550
21383
|
abortSignal,
|
|
@@ -20552,7 +21385,7 @@ async function embedMany3({
|
|
|
20552
21385
|
providerOptions
|
|
20553
21386
|
});
|
|
20554
21387
|
const embeddings2 = modelResponse.embeddings;
|
|
20555
|
-
const usage = (
|
|
21388
|
+
const usage = (_a232 = modelResponse.usage) != null ? _a232 : { tokens: NaN };
|
|
20556
21389
|
doEmbedSpan.setAttributes(
|
|
20557
21390
|
await selectTelemetryAttributes3({
|
|
20558
21391
|
telemetry,
|
|
@@ -20569,7 +21402,7 @@ async function embedMany3({
|
|
|
20569
21402
|
return {
|
|
20570
21403
|
embeddings: embeddings2,
|
|
20571
21404
|
usage,
|
|
20572
|
-
warnings: modelResponse.warnings,
|
|
21405
|
+
warnings: (_b19 = modelResponse.warnings) != null ? _b19 : [],
|
|
20573
21406
|
providerMetadata: modelResponse.providerMetadata,
|
|
20574
21407
|
response: modelResponse.response
|
|
20575
21408
|
};
|
|
@@ -20591,7 +21424,7 @@ async function embedMany3({
|
|
|
20591
21424
|
result.providerMetadata
|
|
20592
21425
|
)) {
|
|
20593
21426
|
providerMetadata[providerName] = {
|
|
20594
|
-
...(
|
|
21427
|
+
...(_a223 = providerMetadata[providerName]) != null ? _a223 : {},
|
|
20595
21428
|
...metadata
|
|
20596
21429
|
};
|
|
20597
21430
|
}
|
|
@@ -22310,8 +23143,8 @@ async function listThreadsForResource({
|
|
|
22310
23143
|
const title = thread.title || "(untitled)";
|
|
22311
23144
|
const updated = formatTimestamp(thread.updatedAt);
|
|
22312
23145
|
const created = formatTimestamp(thread.createdAt);
|
|
22313
|
-
const
|
|
22314
|
-
lines.push(`- **${title}**${
|
|
23146
|
+
const marker28 = isCurrent ? " \u2190 current" : "";
|
|
23147
|
+
lines.push(`- **${title}**${marker28}`);
|
|
22315
23148
|
lines.push(` id: ${thread.id}`);
|
|
22316
23149
|
lines.push(` updated: ${updated} | created: ${created}`);
|
|
22317
23150
|
}
|
|
@@ -23470,8 +24303,8 @@ var __experimental_updateWorkingMemoryToolVNext = (config) => {
|
|
|
23470
24303
|
function createWorkingMemoryTool(config, options = {}) {
|
|
23471
24304
|
const useStateSignals = config.workingMemory?.useStateSignals === true;
|
|
23472
24305
|
const tool3 = options.vNext ? __experimental_updateWorkingMemoryToolVNext(config) : updateWorkingMemoryTool(config);
|
|
23473
|
-
const
|
|
23474
|
-
return { name:
|
|
24306
|
+
const name28 = useStateSignals ? SET_WORKING_MEMORY_TOOL_NAME : UPDATE_WORKING_MEMORY_TOOL_NAME;
|
|
24307
|
+
return { name: name28, tool: tool3 };
|
|
23475
24308
|
}
|
|
23476
24309
|
var WORKING_MEMORY_START_TAG = "<working_memory>";
|
|
23477
24310
|
var WORKING_MEMORY_END_TAG = "</working_memory>";
|
|
@@ -23896,7 +24729,7 @@ var Memory = class extends MastraMemory {
|
|
|
23896
24729
|
const separator = this.vector.indexSeparator ?? "_";
|
|
23897
24730
|
const prefix = `memory${separator}messages`;
|
|
23898
24731
|
const indexes = await this.vector.listIndexes();
|
|
23899
|
-
return indexes.filter((
|
|
24732
|
+
return indexes.filter((name28) => name28.startsWith(prefix));
|
|
23900
24733
|
}
|
|
23901
24734
|
/**
|
|
23902
24735
|
* Deletes all vector embeddings associated with a thread.
|
|
@@ -24560,7 +25393,7 @@ ${workingMemory}`;
|
|
|
24560
25393
|
"Observational memory requires @mastra/core support for request-response-id-rotation. Please bump @mastra/core to a newer version."
|
|
24561
25394
|
);
|
|
24562
25395
|
}
|
|
24563
|
-
const { ObservationalMemory: OMClass } = await import('./observational-memory-
|
|
25396
|
+
const { ObservationalMemory: OMClass } = await import('./observational-memory-OJN26RQ4.js');
|
|
24564
25397
|
const onIndexObservations = this.hasRetrievalSearch(omConfig.retrieval) ? async (observation) => {
|
|
24565
25398
|
await this.indexObservation(observation);
|
|
24566
25399
|
} : void 0;
|
|
@@ -25018,10 +25851,10 @@ Notes:
|
|
|
25018
25851
|
const tools = {};
|
|
25019
25852
|
const workingMemoryConfig = mergedConfig.workingMemory;
|
|
25020
25853
|
if (workingMemoryConfig?.enabled && workingMemoryConfig.agentManaged !== false && !mergedConfig.readOnly) {
|
|
25021
|
-
const { name:
|
|
25854
|
+
const { name: name28, tool: tool3 } = createWorkingMemoryTool(mergedConfig, {
|
|
25022
25855
|
vNext: this.isVNextWorkingMemoryConfig(mergedConfig)
|
|
25023
25856
|
});
|
|
25024
|
-
tools[
|
|
25857
|
+
tools[name28] = tool3;
|
|
25025
25858
|
}
|
|
25026
25859
|
const omConfig = normalizeObservationalMemoryConfig(mergedConfig.observationalMemory);
|
|
25027
25860
|
if (omConfig?.retrieval) {
|
|
@@ -25608,7 +26441,7 @@ Notes:
|
|
|
25608
26441
|
if (!effectiveConfig) return null;
|
|
25609
26442
|
const engine = await this.omEngine;
|
|
25610
26443
|
if (!engine) return null;
|
|
25611
|
-
const { ObservationalMemoryProcessor: ObservationalMemoryProcessor2 } = await import('./observational-memory-
|
|
26444
|
+
const { ObservationalMemoryProcessor: ObservationalMemoryProcessor2 } = await import('./observational-memory-OJN26RQ4.js');
|
|
25612
26445
|
return new ObservationalMemoryProcessor2(engine, this, {
|
|
25613
26446
|
temporalMarkers: effectiveConfig.temporalMarkers
|
|
25614
26447
|
});
|
|
@@ -28265,16 +29098,16 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
28265
29098
|
* (data-* parts are filtered out before sending to the LLM, so they don't affect model calls.)
|
|
28266
29099
|
* @internal Used by ReflectorRunner. Do not call directly.
|
|
28267
29100
|
*/
|
|
28268
|
-
async persistMarkerToMessage(
|
|
29101
|
+
async persistMarkerToMessage(marker28, messageList, threadId, resourceId) {
|
|
28269
29102
|
if (!messageList) return;
|
|
28270
29103
|
const allMsgs = messageList.get.all.db();
|
|
28271
29104
|
for (let i = allMsgs.length - 1; i >= 0; i--) {
|
|
28272
29105
|
const msg = allMsgs[i];
|
|
28273
29106
|
if (msg?.role === "assistant" && msg.content?.parts && Array.isArray(msg.content.parts)) {
|
|
28274
|
-
const markerData =
|
|
28275
|
-
const alreadyPresent = markerData?.cycleId && msg.content.parts.some((p) => p?.type ===
|
|
29107
|
+
const markerData = marker28.data;
|
|
29108
|
+
const alreadyPresent = markerData?.cycleId && msg.content.parts.some((p) => p?.type === marker28.type && p?.data?.cycleId === markerData.cycleId);
|
|
28276
29109
|
if (!alreadyPresent) {
|
|
28277
|
-
msg.content.parts.push(
|
|
29110
|
+
msg.content.parts.push(marker28);
|
|
28278
29111
|
}
|
|
28279
29112
|
try {
|
|
28280
29113
|
await this.messageHistory.persistMessages({
|
|
@@ -28295,7 +29128,7 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
28295
29128
|
* so it works even when no MessageList is available (e.g. async buffering ops).
|
|
28296
29129
|
* @internal Used by observation strategies. Do not call directly.
|
|
28297
29130
|
*/
|
|
28298
|
-
async persistMarkerToStorage(
|
|
29131
|
+
async persistMarkerToStorage(marker28, threadId, resourceId) {
|
|
28299
29132
|
try {
|
|
28300
29133
|
const result = await this.storage.listMessages({
|
|
28301
29134
|
threadId,
|
|
@@ -28305,10 +29138,10 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
28305
29138
|
const messages = result?.messages ?? [];
|
|
28306
29139
|
for (const msg of messages) {
|
|
28307
29140
|
if (msg?.role === "assistant" && msg.content?.parts && Array.isArray(msg.content.parts)) {
|
|
28308
|
-
const markerData =
|
|
28309
|
-
const alreadyPresent = markerData?.cycleId && msg.content.parts.some((p) => p?.type ===
|
|
29141
|
+
const markerData = marker28.data;
|
|
29142
|
+
const alreadyPresent = markerData?.cycleId && msg.content.parts.some((p) => p?.type === marker28.type && p?.data?.cycleId === markerData.cycleId);
|
|
28310
29143
|
if (!alreadyPresent) {
|
|
28311
|
-
msg.content.parts.push(
|
|
29144
|
+
msg.content.parts.push(marker28);
|
|
28312
29145
|
}
|
|
28313
29146
|
await this.messageHistory.persistMessages({
|
|
28314
29147
|
messages: [msg],
|
|
@@ -30271,6 +31104,9 @@ async function insertTemporalGapMarkers({
|
|
|
30271
31104
|
}
|
|
30272
31105
|
|
|
30273
31106
|
// src/processors/observational-memory/processor.ts
|
|
31107
|
+
function asLiveTurn(value) {
|
|
31108
|
+
return value && typeof value.end === "function" ? value : void 0;
|
|
31109
|
+
}
|
|
30274
31110
|
function getOmObservabilityContext(args) {
|
|
30275
31111
|
if (!args.tracing || !args.tracingContext || !args.loggerVNext || !args.metrics) {
|
|
30276
31112
|
return void 0;
|
|
@@ -30388,7 +31224,7 @@ var ObservationalMemoryProcessor = class {
|
|
|
30388
31224
|
});
|
|
30389
31225
|
return messageList;
|
|
30390
31226
|
}
|
|
30391
|
-
const activeTurn = state.__omTurn ?? this.turn;
|
|
31227
|
+
const activeTurn = asLiveTurn(state.__omTurn) ?? this.turn;
|
|
30392
31228
|
if (activeTurn && activeTurn.messageList !== messageList) {
|
|
30393
31229
|
await activeTurn.end().catch(() => {
|
|
30394
31230
|
});
|
|
@@ -30505,7 +31341,7 @@ var ObservationalMemoryProcessor = class {
|
|
|
30505
31341
|
return this.engine.getTokenCounter().runWithModelContext(state.__omActorModelContext, async () => {
|
|
30506
31342
|
const memoryContext = parseMemoryRequestContext(requestContext);
|
|
30507
31343
|
if (memoryContext?.memoryConfig?.readOnly) return messageList;
|
|
30508
|
-
const turn = state.__omTurn ?? this.turn;
|
|
31344
|
+
const turn = asLiveTurn(state.__omTurn) ?? this.turn;
|
|
30509
31345
|
if (turn) {
|
|
30510
31346
|
await turn.end();
|
|
30511
31347
|
this.turn = void 0;
|
|
@@ -30558,5 +31394,5 @@ function getObservationsAsOf(activeObservations, asOf) {
|
|
|
30558
31394
|
}
|
|
30559
31395
|
|
|
30560
31396
|
export { Extractor, Memory, ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, SUMMARIZE_THREAD_DEFAULTS, TokenCounter, WorkingMemoryExtractor, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deepMergeWorkingMemory, deriveObservationGroupProvenance, extractCurrentTask, extractWorkingMemoryContent, extractWorkingMemoryTags, formatMessagesForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, removeWorkingMemoryTags, renderObservationGroupsForReflection, stripEphemeralAnchorIds, stripObservationGroups, summarizeConversation, wrapInObservationGroup };
|
|
30561
|
-
//# sourceMappingURL=chunk-
|
|
30562
|
-
//# sourceMappingURL=chunk-
|
|
31397
|
+
//# sourceMappingURL=chunk-6ACCFKAN.js.map
|
|
31398
|
+
//# sourceMappingURL=chunk-6ACCFKAN.js.map
|