@mastra/memory 1.17.1 → 1.17.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agents-background-tasks.md +242 -0
- package/dist/docs/references/docs-agents-supervisor-agents.md +35 -4
- package/dist/docs/references/reference-memory-clone-utilities.md +4 -2
- package/dist/docs/references/reference-memory-cloneThread.md +4 -2
- package/dist/index.cjs +113 -748
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +113 -748
- package/dist/index.js.map +1 -1
- package/dist/tools/om-tools.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -4292,9 +4292,6 @@ var ParseError = class extends Error {
|
|
|
4292
4292
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
4293
4293
|
}
|
|
4294
4294
|
};
|
|
4295
|
-
var LF = 10;
|
|
4296
|
-
var CR = 13;
|
|
4297
|
-
var SPACE = 32;
|
|
4298
4295
|
function noop(_arg) {
|
|
4299
4296
|
}
|
|
4300
4297
|
function createParser(callbacks) {
|
|
@@ -4302,109 +4299,39 @@ function createParser(callbacks) {
|
|
|
4302
4299
|
throw new TypeError(
|
|
4303
4300
|
"`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
|
|
4304
4301
|
);
|
|
4305
|
-
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks
|
|
4306
|
-
let isFirstChunk = true, id, data = "",
|
|
4307
|
-
function feed(
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
pendingFragments.push(chunk);
|
|
4316
|
-
return;
|
|
4317
|
-
}
|
|
4318
|
-
pendingFragments.push(chunk);
|
|
4319
|
-
const input = pendingFragments.join("");
|
|
4320
|
-
pendingFragments.length = 0;
|
|
4321
|
-
const trailing = processLines(input);
|
|
4322
|
-
trailing !== "" && pendingFragments.push(trailing);
|
|
4323
|
-
}
|
|
4324
|
-
function processLines(chunk) {
|
|
4325
|
-
let searchIndex = 0;
|
|
4326
|
-
if (chunk.indexOf("\r") === -1) {
|
|
4327
|
-
let lfIndex = chunk.indexOf(`
|
|
4328
|
-
`, searchIndex);
|
|
4329
|
-
for (; lfIndex !== -1; ) {
|
|
4330
|
-
if (searchIndex === lfIndex) {
|
|
4331
|
-
dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
4332
|
-
`, searchIndex);
|
|
4333
|
-
continue;
|
|
4334
|
-
}
|
|
4335
|
-
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
4336
|
-
if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
|
|
4337
|
-
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
4338
|
-
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
|
|
4339
|
-
onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
4340
|
-
`, searchIndex);
|
|
4341
|
-
continue;
|
|
4342
|
-
}
|
|
4343
|
-
data = dataLines === 0 ? value : `${data}
|
|
4344
|
-
${value}`, dataLines++;
|
|
4345
|
-
} else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
|
|
4346
|
-
chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
|
|
4347
|
-
lfIndex
|
|
4348
|
-
) || void 0 : parseLine(chunk, searchIndex, lfIndex);
|
|
4349
|
-
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
4350
|
-
`, searchIndex);
|
|
4351
|
-
}
|
|
4352
|
-
return chunk.slice(searchIndex);
|
|
4353
|
-
}
|
|
4354
|
-
for (; searchIndex < chunk.length; ) {
|
|
4355
|
-
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
4356
|
-
`, searchIndex);
|
|
4357
|
-
let lineEnd = -1;
|
|
4358
|
-
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
|
|
4359
|
-
break;
|
|
4360
|
-
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
|
|
4361
|
-
}
|
|
4362
|
-
return chunk.slice(searchIndex);
|
|
4363
|
-
}
|
|
4364
|
-
function parseLine(chunk, start, end) {
|
|
4365
|
-
if (start === end) {
|
|
4302
|
+
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
|
|
4303
|
+
let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
|
|
4304
|
+
function feed(newChunk) {
|
|
4305
|
+
const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
|
|
4306
|
+
for (const line of complete)
|
|
4307
|
+
parseLine(line);
|
|
4308
|
+
incompleteLine = incomplete, isFirstChunk = false;
|
|
4309
|
+
}
|
|
4310
|
+
function parseLine(line) {
|
|
4311
|
+
if (line === "") {
|
|
4366
4312
|
dispatchEvent();
|
|
4367
4313
|
return;
|
|
4368
4314
|
}
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
4372
|
-
data = dataLines === 0 ? value2 : `${data}
|
|
4373
|
-
${value2}`, dataLines++;
|
|
4374
|
-
return;
|
|
4375
|
-
}
|
|
4376
|
-
if (isEventPrefix(chunk, start, firstCharCode)) {
|
|
4377
|
-
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
|
|
4378
|
-
return;
|
|
4379
|
-
}
|
|
4380
|
-
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
4381
|
-
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
|
|
4382
|
-
id = value2.includes("\0") ? void 0 : value2;
|
|
4383
|
-
return;
|
|
4384
|
-
}
|
|
4385
|
-
if (firstCharCode === 58) {
|
|
4386
|
-
if (onComment) {
|
|
4387
|
-
const line2 = chunk.slice(start, end);
|
|
4388
|
-
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
|
|
4389
|
-
}
|
|
4315
|
+
if (line.startsWith(":")) {
|
|
4316
|
+
onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
|
|
4390
4317
|
return;
|
|
4391
4318
|
}
|
|
4392
|
-
const
|
|
4393
|
-
if (fieldSeparatorIndex
|
|
4394
|
-
|
|
4319
|
+
const fieldSeparatorIndex = line.indexOf(":");
|
|
4320
|
+
if (fieldSeparatorIndex !== -1) {
|
|
4321
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
4322
|
+
processField(field, value, line);
|
|
4395
4323
|
return;
|
|
4396
4324
|
}
|
|
4397
|
-
|
|
4398
|
-
processField(field, value, line);
|
|
4325
|
+
processField(line, "", line);
|
|
4399
4326
|
}
|
|
4400
4327
|
function processField(field, value, line) {
|
|
4401
4328
|
switch (field) {
|
|
4402
4329
|
case "event":
|
|
4403
|
-
eventType = value
|
|
4330
|
+
eventType = value;
|
|
4404
4331
|
break;
|
|
4405
4332
|
case "data":
|
|
4406
|
-
data =
|
|
4407
|
-
|
|
4333
|
+
data = `${data}${value}
|
|
4334
|
+
`;
|
|
4408
4335
|
break;
|
|
4409
4336
|
case "id":
|
|
4410
4337
|
id = value.includes("\0") ? void 0 : value;
|
|
@@ -4429,26 +4356,37 @@ ${value}`, dataLines++;
|
|
|
4429
4356
|
}
|
|
4430
4357
|
}
|
|
4431
4358
|
function dispatchEvent() {
|
|
4432
|
-
|
|
4359
|
+
data.length > 0 && onEvent({
|
|
4433
4360
|
id,
|
|
4434
|
-
event: eventType,
|
|
4435
|
-
data
|
|
4436
|
-
|
|
4361
|
+
event: eventType || void 0,
|
|
4362
|
+
// If the data buffer's last character is a U+000A LINE FEED (LF) character,
|
|
4363
|
+
// then remove the last character from the data buffer.
|
|
4364
|
+
data: data.endsWith(`
|
|
4365
|
+
`) ? data.slice(0, -1) : data
|
|
4366
|
+
}), id = void 0, data = "", eventType = "";
|
|
4437
4367
|
}
|
|
4438
4368
|
function reset(options = {}) {
|
|
4439
|
-
|
|
4440
|
-
const incompleteLine = pendingFragments.join("");
|
|
4441
|
-
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
4442
|
-
}
|
|
4443
|
-
isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
|
|
4369
|
+
incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
|
|
4444
4370
|
}
|
|
4445
4371
|
return { feed, reset };
|
|
4446
4372
|
}
|
|
4447
|
-
function
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4373
|
+
function splitLines(chunk) {
|
|
4374
|
+
const lines = [];
|
|
4375
|
+
let incompleteLine = "", searchIndex = 0;
|
|
4376
|
+
for (; searchIndex < chunk.length; ) {
|
|
4377
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
4378
|
+
`, searchIndex);
|
|
4379
|
+
let lineEnd = -1;
|
|
4380
|
+
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
4381
|
+
incompleteLine = chunk.slice(searchIndex);
|
|
4382
|
+
break;
|
|
4383
|
+
} else {
|
|
4384
|
+
const line = chunk.slice(searchIndex, lineEnd);
|
|
4385
|
+
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
4386
|
+
` && searchIndex++;
|
|
4387
|
+
}
|
|
4388
|
+
}
|
|
4389
|
+
return [lines, incompleteLine];
|
|
4452
4390
|
}
|
|
4453
4391
|
var EventSourceParserStream = class extends TransformStream {
|
|
4454
4392
|
constructor({ onError, onRetry, onComment } = {}) {
|
|
@@ -4624,7 +4562,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
4624
4562
|
);
|
|
4625
4563
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
4626
4564
|
}
|
|
4627
|
-
var VERSION2 = "3.0.
|
|
4565
|
+
var VERSION2 = "3.0.22";
|
|
4628
4566
|
var getOriginalFetch = () => globalThis.fetch;
|
|
4629
4567
|
var getFromApi = async ({
|
|
4630
4568
|
url,
|
|
@@ -6671,7 +6609,6 @@ async function parseAuthMethod(headers) {
|
|
|
6671
6609
|
var gatewayAuthMethodSchema = lazyValidator(
|
|
6672
6610
|
() => zodSchema2(z$1.union([z$1.literal("api-key"), z$1.literal("oidc")]))
|
|
6673
6611
|
);
|
|
6674
|
-
var KNOWN_MODEL_TYPES = ["embedding", "image", "language"];
|
|
6675
6612
|
var GatewayFetchMetadata = class {
|
|
6676
6613
|
constructor(config) {
|
|
6677
6614
|
this.config = config;
|
|
@@ -6742,12 +6679,8 @@ var gatewayAvailableModelsResponseSchema = lazyValidator(
|
|
|
6742
6679
|
provider: z$1.string(),
|
|
6743
6680
|
modelId: z$1.string()
|
|
6744
6681
|
}),
|
|
6745
|
-
modelType: z$1.
|
|
6682
|
+
modelType: z$1.enum(["language", "embedding", "image"]).nullish()
|
|
6746
6683
|
})
|
|
6747
|
-
).transform(
|
|
6748
|
-
(models) => models.filter(
|
|
6749
|
-
(m) => m.modelType == null || KNOWN_MODEL_TYPES.includes(m.modelType)
|
|
6750
|
-
)
|
|
6751
6684
|
)
|
|
6752
6685
|
})
|
|
6753
6686
|
)
|
|
@@ -6763,187 +6696,6 @@ var gatewayCreditsResponseSchema = lazyValidator(
|
|
|
6763
6696
|
}))
|
|
6764
6697
|
)
|
|
6765
6698
|
);
|
|
6766
|
-
var GatewaySpendReport = class {
|
|
6767
|
-
constructor(config) {
|
|
6768
|
-
this.config = config;
|
|
6769
|
-
}
|
|
6770
|
-
async getSpendReport(params) {
|
|
6771
|
-
try {
|
|
6772
|
-
const baseUrl = new URL(this.config.baseURL);
|
|
6773
|
-
const searchParams = new URLSearchParams();
|
|
6774
|
-
searchParams.set("start_date", params.startDate);
|
|
6775
|
-
searchParams.set("end_date", params.endDate);
|
|
6776
|
-
if (params.groupBy) {
|
|
6777
|
-
searchParams.set("group_by", params.groupBy);
|
|
6778
|
-
}
|
|
6779
|
-
if (params.datePart) {
|
|
6780
|
-
searchParams.set("date_part", params.datePart);
|
|
6781
|
-
}
|
|
6782
|
-
if (params.userId) {
|
|
6783
|
-
searchParams.set("user_id", params.userId);
|
|
6784
|
-
}
|
|
6785
|
-
if (params.model) {
|
|
6786
|
-
searchParams.set("model", params.model);
|
|
6787
|
-
}
|
|
6788
|
-
if (params.provider) {
|
|
6789
|
-
searchParams.set("provider", params.provider);
|
|
6790
|
-
}
|
|
6791
|
-
if (params.credentialType) {
|
|
6792
|
-
searchParams.set("credential_type", params.credentialType);
|
|
6793
|
-
}
|
|
6794
|
-
if (params.tags && params.tags.length > 0) {
|
|
6795
|
-
searchParams.set("tags", params.tags.join(","));
|
|
6796
|
-
}
|
|
6797
|
-
const { value } = await getFromApi({
|
|
6798
|
-
url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
|
|
6799
|
-
headers: await resolve(this.config.headers()),
|
|
6800
|
-
successfulResponseHandler: createJsonResponseHandler(
|
|
6801
|
-
gatewaySpendReportResponseSchema
|
|
6802
|
-
),
|
|
6803
|
-
failedResponseHandler: createJsonErrorResponseHandler({
|
|
6804
|
-
errorSchema: z$1.any(),
|
|
6805
|
-
errorToMessage: (data) => data
|
|
6806
|
-
}),
|
|
6807
|
-
fetch: this.config.fetch
|
|
6808
|
-
});
|
|
6809
|
-
return value;
|
|
6810
|
-
} catch (error) {
|
|
6811
|
-
throw await asGatewayError(error);
|
|
6812
|
-
}
|
|
6813
|
-
}
|
|
6814
|
-
};
|
|
6815
|
-
var gatewaySpendReportResponseSchema = lazySchema(
|
|
6816
|
-
() => zodSchema2(
|
|
6817
|
-
z$1.object({
|
|
6818
|
-
results: z$1.array(
|
|
6819
|
-
z$1.object({
|
|
6820
|
-
day: z$1.string().optional(),
|
|
6821
|
-
hour: z$1.string().optional(),
|
|
6822
|
-
user: z$1.string().optional(),
|
|
6823
|
-
model: z$1.string().optional(),
|
|
6824
|
-
tag: z$1.string().optional(),
|
|
6825
|
-
provider: z$1.string().optional(),
|
|
6826
|
-
credential_type: z$1.enum(["byok", "system"]).optional(),
|
|
6827
|
-
total_cost: z$1.number(),
|
|
6828
|
-
market_cost: z$1.number().optional(),
|
|
6829
|
-
input_tokens: z$1.number().optional(),
|
|
6830
|
-
output_tokens: z$1.number().optional(),
|
|
6831
|
-
cached_input_tokens: z$1.number().optional(),
|
|
6832
|
-
cache_creation_input_tokens: z$1.number().optional(),
|
|
6833
|
-
reasoning_tokens: z$1.number().optional(),
|
|
6834
|
-
request_count: z$1.number().optional()
|
|
6835
|
-
}).transform(
|
|
6836
|
-
({
|
|
6837
|
-
credential_type,
|
|
6838
|
-
total_cost,
|
|
6839
|
-
market_cost,
|
|
6840
|
-
input_tokens,
|
|
6841
|
-
output_tokens,
|
|
6842
|
-
cached_input_tokens,
|
|
6843
|
-
cache_creation_input_tokens,
|
|
6844
|
-
reasoning_tokens,
|
|
6845
|
-
request_count,
|
|
6846
|
-
...rest
|
|
6847
|
-
}) => ({
|
|
6848
|
-
...rest,
|
|
6849
|
-
...credential_type !== void 0 ? { credentialType: credential_type } : {},
|
|
6850
|
-
totalCost: total_cost,
|
|
6851
|
-
...market_cost !== void 0 ? { marketCost: market_cost } : {},
|
|
6852
|
-
...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
|
|
6853
|
-
...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
|
|
6854
|
-
...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
|
|
6855
|
-
...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
|
|
6856
|
-
...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
|
|
6857
|
-
...request_count !== void 0 ? { requestCount: request_count } : {}
|
|
6858
|
-
})
|
|
6859
|
-
)
|
|
6860
|
-
)
|
|
6861
|
-
})
|
|
6862
|
-
)
|
|
6863
|
-
);
|
|
6864
|
-
var GatewayGenerationInfoFetcher = class {
|
|
6865
|
-
constructor(config) {
|
|
6866
|
-
this.config = config;
|
|
6867
|
-
}
|
|
6868
|
-
async getGenerationInfo(params) {
|
|
6869
|
-
try {
|
|
6870
|
-
const baseUrl = new URL(this.config.baseURL);
|
|
6871
|
-
const { value } = await getFromApi({
|
|
6872
|
-
url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
|
|
6873
|
-
headers: await resolve(this.config.headers()),
|
|
6874
|
-
successfulResponseHandler: createJsonResponseHandler(
|
|
6875
|
-
gatewayGenerationInfoResponseSchema
|
|
6876
|
-
),
|
|
6877
|
-
failedResponseHandler: createJsonErrorResponseHandler({
|
|
6878
|
-
errorSchema: z$1.any(),
|
|
6879
|
-
errorToMessage: (data) => data
|
|
6880
|
-
}),
|
|
6881
|
-
fetch: this.config.fetch
|
|
6882
|
-
});
|
|
6883
|
-
return value;
|
|
6884
|
-
} catch (error) {
|
|
6885
|
-
throw await asGatewayError(error);
|
|
6886
|
-
}
|
|
6887
|
-
}
|
|
6888
|
-
};
|
|
6889
|
-
var gatewayGenerationInfoResponseSchema = lazySchema(
|
|
6890
|
-
() => zodSchema2(
|
|
6891
|
-
z$1.object({
|
|
6892
|
-
data: z$1.object({
|
|
6893
|
-
id: z$1.string(),
|
|
6894
|
-
total_cost: z$1.number(),
|
|
6895
|
-
upstream_inference_cost: z$1.number(),
|
|
6896
|
-
usage: z$1.number(),
|
|
6897
|
-
created_at: z$1.string(),
|
|
6898
|
-
model: z$1.string(),
|
|
6899
|
-
is_byok: z$1.boolean(),
|
|
6900
|
-
provider_name: z$1.string(),
|
|
6901
|
-
streamed: z$1.boolean(),
|
|
6902
|
-
finish_reason: z$1.string(),
|
|
6903
|
-
latency: z$1.number(),
|
|
6904
|
-
generation_time: z$1.number(),
|
|
6905
|
-
native_tokens_prompt: z$1.number(),
|
|
6906
|
-
native_tokens_completion: z$1.number(),
|
|
6907
|
-
native_tokens_reasoning: z$1.number(),
|
|
6908
|
-
native_tokens_cached: z$1.number(),
|
|
6909
|
-
native_tokens_cache_creation: z$1.number(),
|
|
6910
|
-
billable_web_search_calls: z$1.number()
|
|
6911
|
-
}).transform(
|
|
6912
|
-
({
|
|
6913
|
-
total_cost,
|
|
6914
|
-
upstream_inference_cost,
|
|
6915
|
-
created_at,
|
|
6916
|
-
is_byok,
|
|
6917
|
-
provider_name,
|
|
6918
|
-
finish_reason,
|
|
6919
|
-
generation_time,
|
|
6920
|
-
native_tokens_prompt,
|
|
6921
|
-
native_tokens_completion,
|
|
6922
|
-
native_tokens_reasoning,
|
|
6923
|
-
native_tokens_cached,
|
|
6924
|
-
native_tokens_cache_creation,
|
|
6925
|
-
billable_web_search_calls,
|
|
6926
|
-
...rest
|
|
6927
|
-
}) => ({
|
|
6928
|
-
...rest,
|
|
6929
|
-
totalCost: total_cost,
|
|
6930
|
-
upstreamInferenceCost: upstream_inference_cost,
|
|
6931
|
-
createdAt: created_at,
|
|
6932
|
-
isByok: is_byok,
|
|
6933
|
-
providerName: provider_name,
|
|
6934
|
-
finishReason: finish_reason,
|
|
6935
|
-
generationTime: generation_time,
|
|
6936
|
-
promptTokens: native_tokens_prompt,
|
|
6937
|
-
completionTokens: native_tokens_completion,
|
|
6938
|
-
reasoningTokens: native_tokens_reasoning,
|
|
6939
|
-
cachedTokens: native_tokens_cached,
|
|
6940
|
-
cacheCreationTokens: native_tokens_cache_creation,
|
|
6941
|
-
billableWebSearchCalls: billable_web_search_calls
|
|
6942
|
-
})
|
|
6943
|
-
)
|
|
6944
|
-
}).transform(({ data }) => data)
|
|
6945
|
-
)
|
|
6946
|
-
);
|
|
6947
6699
|
var GatewayLanguageModel = class {
|
|
6948
6700
|
constructor(modelId, config) {
|
|
6949
6701
|
this.modelId = modelId;
|
|
@@ -7446,7 +7198,7 @@ async function getVercelRequestId() {
|
|
|
7446
7198
|
var _a932;
|
|
7447
7199
|
return (_a932 = getContext().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
7448
7200
|
}
|
|
7449
|
-
var VERSION3 = "2.0.
|
|
7201
|
+
var VERSION3 = "2.0.59";
|
|
7450
7202
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
7451
7203
|
function createGatewayProvider(options = {}) {
|
|
7452
7204
|
var _a932, _b93;
|
|
@@ -7544,30 +7296,6 @@ function createGatewayProvider(options = {}) {
|
|
|
7544
7296
|
);
|
|
7545
7297
|
});
|
|
7546
7298
|
};
|
|
7547
|
-
const getSpendReport = async (params) => {
|
|
7548
|
-
return new GatewaySpendReport({
|
|
7549
|
-
baseURL,
|
|
7550
|
-
headers: getHeaders,
|
|
7551
|
-
fetch: options.fetch
|
|
7552
|
-
}).getSpendReport(params).catch(async (error) => {
|
|
7553
|
-
throw await asGatewayError(
|
|
7554
|
-
error,
|
|
7555
|
-
await parseAuthMethod(await getHeaders())
|
|
7556
|
-
);
|
|
7557
|
-
});
|
|
7558
|
-
};
|
|
7559
|
-
const getGenerationInfo = async (params) => {
|
|
7560
|
-
return new GatewayGenerationInfoFetcher({
|
|
7561
|
-
baseURL,
|
|
7562
|
-
headers: getHeaders,
|
|
7563
|
-
fetch: options.fetch
|
|
7564
|
-
}).getGenerationInfo(params).catch(async (error) => {
|
|
7565
|
-
throw await asGatewayError(
|
|
7566
|
-
error,
|
|
7567
|
-
await parseAuthMethod(await getHeaders())
|
|
7568
|
-
);
|
|
7569
|
-
});
|
|
7570
|
-
};
|
|
7571
7299
|
const provider = function(modelId) {
|
|
7572
7300
|
if (new.target) {
|
|
7573
7301
|
throw new Error(
|
|
@@ -7578,8 +7306,6 @@ function createGatewayProvider(options = {}) {
|
|
|
7578
7306
|
};
|
|
7579
7307
|
provider.getAvailableModels = getAvailableModels;
|
|
7580
7308
|
provider.getCredits = getCredits;
|
|
7581
|
-
provider.getSpendReport = getSpendReport;
|
|
7582
|
-
provider.getGenerationInfo = getGenerationInfo;
|
|
7583
7309
|
provider.imageModel = (modelId) => {
|
|
7584
7310
|
return new GatewayImageModel(modelId, {
|
|
7585
7311
|
provider: "gateway",
|
|
@@ -8433,7 +8159,7 @@ function getGlobalProvider() {
|
|
|
8433
8159
|
var _a163;
|
|
8434
8160
|
return (_a163 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a163 : gateway;
|
|
8435
8161
|
}
|
|
8436
|
-
var VERSION32 = "5.0.
|
|
8162
|
+
var VERSION32 = "5.0.155";
|
|
8437
8163
|
var dataContentSchema2 = z$1.union([
|
|
8438
8164
|
z$1.string(),
|
|
8439
8165
|
z$1.instanceof(Uint8Array),
|
|
@@ -9738,9 +9464,6 @@ var ParseError2 = class extends Error {
|
|
|
9738
9464
|
super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
|
|
9739
9465
|
}
|
|
9740
9466
|
};
|
|
9741
|
-
var LF2 = 10;
|
|
9742
|
-
var CR2 = 13;
|
|
9743
|
-
var SPACE2 = 32;
|
|
9744
9467
|
function noop2(_arg) {
|
|
9745
9468
|
}
|
|
9746
9469
|
function createParser2(callbacks) {
|
|
@@ -9748,109 +9471,39 @@ function createParser2(callbacks) {
|
|
|
9748
9471
|
throw new TypeError(
|
|
9749
9472
|
"`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
|
|
9750
9473
|
);
|
|
9751
|
-
const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks
|
|
9752
|
-
let isFirstChunk = true, id, data = "",
|
|
9753
|
-
function feed(
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
|
|
9758
|
-
|
|
9759
|
-
|
|
9760
|
-
|
|
9761
|
-
pendingFragments.push(chunk);
|
|
9762
|
-
return;
|
|
9763
|
-
}
|
|
9764
|
-
pendingFragments.push(chunk);
|
|
9765
|
-
const input = pendingFragments.join("");
|
|
9766
|
-
pendingFragments.length = 0;
|
|
9767
|
-
const trailing = processLines(input);
|
|
9768
|
-
trailing !== "" && pendingFragments.push(trailing);
|
|
9769
|
-
}
|
|
9770
|
-
function processLines(chunk) {
|
|
9771
|
-
let searchIndex = 0;
|
|
9772
|
-
if (chunk.indexOf("\r") === -1) {
|
|
9773
|
-
let lfIndex = chunk.indexOf(`
|
|
9774
|
-
`, searchIndex);
|
|
9775
|
-
for (; lfIndex !== -1; ) {
|
|
9776
|
-
if (searchIndex === lfIndex) {
|
|
9777
|
-
dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
9778
|
-
`, searchIndex);
|
|
9779
|
-
continue;
|
|
9780
|
-
}
|
|
9781
|
-
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
9782
|
-
if (isDataPrefix2(chunk, searchIndex, firstCharCode)) {
|
|
9783
|
-
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE2 ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
|
|
9784
|
-
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF2) {
|
|
9785
|
-
onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
|
|
9786
|
-
`, searchIndex);
|
|
9787
|
-
continue;
|
|
9788
|
-
}
|
|
9789
|
-
data = dataLines === 0 ? value : `${data}
|
|
9790
|
-
${value}`, dataLines++;
|
|
9791
|
-
} else isEventPrefix2(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
|
|
9792
|
-
chunk.charCodeAt(searchIndex + 6) === SPACE2 ? searchIndex + 7 : searchIndex + 6,
|
|
9793
|
-
lfIndex
|
|
9794
|
-
) || void 0 : parseLine(chunk, searchIndex, lfIndex);
|
|
9795
|
-
searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
|
|
9796
|
-
`, searchIndex);
|
|
9797
|
-
}
|
|
9798
|
-
return chunk.slice(searchIndex);
|
|
9799
|
-
}
|
|
9800
|
-
for (; searchIndex < chunk.length; ) {
|
|
9801
|
-
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
9802
|
-
`, searchIndex);
|
|
9803
|
-
let lineEnd = -1;
|
|
9804
|
-
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
|
|
9805
|
-
break;
|
|
9806
|
-
parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR2 && chunk.charCodeAt(searchIndex) === LF2 && searchIndex++;
|
|
9807
|
-
}
|
|
9808
|
-
return chunk.slice(searchIndex);
|
|
9809
|
-
}
|
|
9810
|
-
function parseLine(chunk, start, end) {
|
|
9811
|
-
if (start === end) {
|
|
9474
|
+
const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks;
|
|
9475
|
+
let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
|
|
9476
|
+
function feed(newChunk) {
|
|
9477
|
+
const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines2(`${incompleteLine}${chunk}`);
|
|
9478
|
+
for (const line of complete)
|
|
9479
|
+
parseLine(line);
|
|
9480
|
+
incompleteLine = incomplete, isFirstChunk = false;
|
|
9481
|
+
}
|
|
9482
|
+
function parseLine(line) {
|
|
9483
|
+
if (line === "") {
|
|
9812
9484
|
dispatchEvent();
|
|
9813
9485
|
return;
|
|
9814
9486
|
}
|
|
9815
|
-
|
|
9816
|
-
|
|
9817
|
-
const valueStart = chunk.charCodeAt(start + 5) === SPACE2 ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
|
|
9818
|
-
data = dataLines === 0 ? value2 : `${data}
|
|
9819
|
-
${value2}`, dataLines++;
|
|
9487
|
+
if (line.startsWith(":")) {
|
|
9488
|
+
onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
|
|
9820
9489
|
return;
|
|
9821
9490
|
}
|
|
9822
|
-
|
|
9823
|
-
|
|
9491
|
+
const fieldSeparatorIndex = line.indexOf(":");
|
|
9492
|
+
if (fieldSeparatorIndex !== -1) {
|
|
9493
|
+
const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
9494
|
+
processField(field, value, line);
|
|
9824
9495
|
return;
|
|
9825
9496
|
}
|
|
9826
|
-
|
|
9827
|
-
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE2 ? start + 4 : start + 3, end);
|
|
9828
|
-
id = value2.includes("\0") ? void 0 : value2;
|
|
9829
|
-
return;
|
|
9830
|
-
}
|
|
9831
|
-
if (firstCharCode === 58) {
|
|
9832
|
-
if (onComment) {
|
|
9833
|
-
const line2 = chunk.slice(start, end);
|
|
9834
|
-
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE2 ? 2 : 1));
|
|
9835
|
-
}
|
|
9836
|
-
return;
|
|
9837
|
-
}
|
|
9838
|
-
const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
|
|
9839
|
-
if (fieldSeparatorIndex === -1) {
|
|
9840
|
-
processField(line, "", line);
|
|
9841
|
-
return;
|
|
9842
|
-
}
|
|
9843
|
-
const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE2 ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
9844
|
-
processField(field, value, line);
|
|
9497
|
+
processField(line, "", line);
|
|
9845
9498
|
}
|
|
9846
9499
|
function processField(field, value, line) {
|
|
9847
9500
|
switch (field) {
|
|
9848
9501
|
case "event":
|
|
9849
|
-
eventType = value
|
|
9502
|
+
eventType = value;
|
|
9850
9503
|
break;
|
|
9851
9504
|
case "data":
|
|
9852
|
-
data =
|
|
9853
|
-
|
|
9505
|
+
data = `${data}${value}
|
|
9506
|
+
`;
|
|
9854
9507
|
break;
|
|
9855
9508
|
case "id":
|
|
9856
9509
|
id = value.includes("\0") ? void 0 : value;
|
|
@@ -9875,26 +9528,37 @@ ${value}`, dataLines++;
|
|
|
9875
9528
|
}
|
|
9876
9529
|
}
|
|
9877
9530
|
function dispatchEvent() {
|
|
9878
|
-
|
|
9531
|
+
data.length > 0 && onEvent({
|
|
9879
9532
|
id,
|
|
9880
|
-
event: eventType,
|
|
9881
|
-
data
|
|
9882
|
-
|
|
9533
|
+
event: eventType || void 0,
|
|
9534
|
+
// If the data buffer's last character is a U+000A LINE FEED (LF) character,
|
|
9535
|
+
// then remove the last character from the data buffer.
|
|
9536
|
+
data: data.endsWith(`
|
|
9537
|
+
`) ? data.slice(0, -1) : data
|
|
9538
|
+
}), id = void 0, data = "", eventType = "";
|
|
9883
9539
|
}
|
|
9884
9540
|
function reset(options = {}) {
|
|
9885
|
-
|
|
9886
|
-
const incompleteLine = pendingFragments.join("");
|
|
9887
|
-
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
9888
|
-
}
|
|
9889
|
-
isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
|
|
9541
|
+
incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
|
|
9890
9542
|
}
|
|
9891
9543
|
return { feed, reset };
|
|
9892
9544
|
}
|
|
9893
|
-
function
|
|
9894
|
-
|
|
9895
|
-
|
|
9896
|
-
|
|
9897
|
-
|
|
9545
|
+
function splitLines2(chunk) {
|
|
9546
|
+
const lines = [];
|
|
9547
|
+
let incompleteLine = "", searchIndex = 0;
|
|
9548
|
+
for (; searchIndex < chunk.length; ) {
|
|
9549
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
9550
|
+
`, searchIndex);
|
|
9551
|
+
let lineEnd = -1;
|
|
9552
|
+
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
9553
|
+
incompleteLine = chunk.slice(searchIndex);
|
|
9554
|
+
break;
|
|
9555
|
+
} else {
|
|
9556
|
+
const line = chunk.slice(searchIndex, lineEnd);
|
|
9557
|
+
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
9558
|
+
` && searchIndex++;
|
|
9559
|
+
}
|
|
9560
|
+
}
|
|
9561
|
+
return [lines, incompleteLine];
|
|
9898
9562
|
}
|
|
9899
9563
|
var EventSourceParserStream2 = class extends TransformStream {
|
|
9900
9564
|
constructor({ onError, onRetry, onComment } = {}) {
|
|
@@ -10106,7 +9770,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
10106
9770
|
);
|
|
10107
9771
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
10108
9772
|
}
|
|
10109
|
-
var VERSION4 = "4.0.
|
|
9773
|
+
var VERSION4 = "4.0.19";
|
|
10110
9774
|
var getOriginalFetch3 = () => globalThis.fetch;
|
|
10111
9775
|
var getFromApi2 = async ({
|
|
10112
9776
|
url,
|
|
@@ -12191,13 +11855,6 @@ async function parseAuthMethod2(headers) {
|
|
|
12191
11855
|
var gatewayAuthMethodSchema2 = lazySchema2(
|
|
12192
11856
|
() => zodSchema3(z$1.union([z$1.literal("api-key"), z$1.literal("oidc")]))
|
|
12193
11857
|
);
|
|
12194
|
-
var KNOWN_MODEL_TYPES2 = [
|
|
12195
|
-
"embedding",
|
|
12196
|
-
"image",
|
|
12197
|
-
"language",
|
|
12198
|
-
"reranking",
|
|
12199
|
-
"video"
|
|
12200
|
-
];
|
|
12201
11858
|
var GatewayFetchMetadata2 = class {
|
|
12202
11859
|
constructor(config) {
|
|
12203
11860
|
this.config = config;
|
|
@@ -12268,12 +11925,8 @@ var gatewayAvailableModelsResponseSchema2 = lazySchema2(
|
|
|
12268
11925
|
provider: z$1.string(),
|
|
12269
11926
|
modelId: z$1.string()
|
|
12270
11927
|
}),
|
|
12271
|
-
modelType: z$1.
|
|
11928
|
+
modelType: z$1.enum(["embedding", "image", "language", "video"]).nullish()
|
|
12272
11929
|
})
|
|
12273
|
-
).transform(
|
|
12274
|
-
(models) => models.filter(
|
|
12275
|
-
(m) => m.modelType == null || KNOWN_MODEL_TYPES2.includes(m.modelType)
|
|
12276
|
-
)
|
|
12277
11930
|
)
|
|
12278
11931
|
})
|
|
12279
11932
|
)
|
|
@@ -12289,187 +11942,6 @@ var gatewayCreditsResponseSchema2 = lazySchema2(
|
|
|
12289
11942
|
}))
|
|
12290
11943
|
)
|
|
12291
11944
|
);
|
|
12292
|
-
var GatewaySpendReport2 = class {
|
|
12293
|
-
constructor(config) {
|
|
12294
|
-
this.config = config;
|
|
12295
|
-
}
|
|
12296
|
-
async getSpendReport(params) {
|
|
12297
|
-
try {
|
|
12298
|
-
const baseUrl = new URL(this.config.baseURL);
|
|
12299
|
-
const searchParams = new URLSearchParams();
|
|
12300
|
-
searchParams.set("start_date", params.startDate);
|
|
12301
|
-
searchParams.set("end_date", params.endDate);
|
|
12302
|
-
if (params.groupBy) {
|
|
12303
|
-
searchParams.set("group_by", params.groupBy);
|
|
12304
|
-
}
|
|
12305
|
-
if (params.datePart) {
|
|
12306
|
-
searchParams.set("date_part", params.datePart);
|
|
12307
|
-
}
|
|
12308
|
-
if (params.userId) {
|
|
12309
|
-
searchParams.set("user_id", params.userId);
|
|
12310
|
-
}
|
|
12311
|
-
if (params.model) {
|
|
12312
|
-
searchParams.set("model", params.model);
|
|
12313
|
-
}
|
|
12314
|
-
if (params.provider) {
|
|
12315
|
-
searchParams.set("provider", params.provider);
|
|
12316
|
-
}
|
|
12317
|
-
if (params.credentialType) {
|
|
12318
|
-
searchParams.set("credential_type", params.credentialType);
|
|
12319
|
-
}
|
|
12320
|
-
if (params.tags && params.tags.length > 0) {
|
|
12321
|
-
searchParams.set("tags", params.tags.join(","));
|
|
12322
|
-
}
|
|
12323
|
-
const { value } = await getFromApi2({
|
|
12324
|
-
url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
|
|
12325
|
-
headers: await resolve2(this.config.headers()),
|
|
12326
|
-
successfulResponseHandler: createJsonResponseHandler2(
|
|
12327
|
-
gatewaySpendReportResponseSchema2
|
|
12328
|
-
),
|
|
12329
|
-
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
12330
|
-
errorSchema: z$1.any(),
|
|
12331
|
-
errorToMessage: (data) => data
|
|
12332
|
-
}),
|
|
12333
|
-
fetch: this.config.fetch
|
|
12334
|
-
});
|
|
12335
|
-
return value;
|
|
12336
|
-
} catch (error) {
|
|
12337
|
-
throw await asGatewayError2(error);
|
|
12338
|
-
}
|
|
12339
|
-
}
|
|
12340
|
-
};
|
|
12341
|
-
var gatewaySpendReportResponseSchema2 = lazySchema2(
|
|
12342
|
-
() => zodSchema3(
|
|
12343
|
-
z$1.object({
|
|
12344
|
-
results: z$1.array(
|
|
12345
|
-
z$1.object({
|
|
12346
|
-
day: z$1.string().optional(),
|
|
12347
|
-
hour: z$1.string().optional(),
|
|
12348
|
-
user: z$1.string().optional(),
|
|
12349
|
-
model: z$1.string().optional(),
|
|
12350
|
-
tag: z$1.string().optional(),
|
|
12351
|
-
provider: z$1.string().optional(),
|
|
12352
|
-
credential_type: z$1.enum(["byok", "system"]).optional(),
|
|
12353
|
-
total_cost: z$1.number(),
|
|
12354
|
-
market_cost: z$1.number().optional(),
|
|
12355
|
-
input_tokens: z$1.number().optional(),
|
|
12356
|
-
output_tokens: z$1.number().optional(),
|
|
12357
|
-
cached_input_tokens: z$1.number().optional(),
|
|
12358
|
-
cache_creation_input_tokens: z$1.number().optional(),
|
|
12359
|
-
reasoning_tokens: z$1.number().optional(),
|
|
12360
|
-
request_count: z$1.number().optional()
|
|
12361
|
-
}).transform(
|
|
12362
|
-
({
|
|
12363
|
-
credential_type,
|
|
12364
|
-
total_cost,
|
|
12365
|
-
market_cost,
|
|
12366
|
-
input_tokens,
|
|
12367
|
-
output_tokens,
|
|
12368
|
-
cached_input_tokens,
|
|
12369
|
-
cache_creation_input_tokens,
|
|
12370
|
-
reasoning_tokens,
|
|
12371
|
-
request_count,
|
|
12372
|
-
...rest
|
|
12373
|
-
}) => ({
|
|
12374
|
-
...rest,
|
|
12375
|
-
...credential_type !== void 0 ? { credentialType: credential_type } : {},
|
|
12376
|
-
totalCost: total_cost,
|
|
12377
|
-
...market_cost !== void 0 ? { marketCost: market_cost } : {},
|
|
12378
|
-
...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
|
|
12379
|
-
...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
|
|
12380
|
-
...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
|
|
12381
|
-
...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
|
|
12382
|
-
...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
|
|
12383
|
-
...request_count !== void 0 ? { requestCount: request_count } : {}
|
|
12384
|
-
})
|
|
12385
|
-
)
|
|
12386
|
-
)
|
|
12387
|
-
})
|
|
12388
|
-
)
|
|
12389
|
-
);
|
|
12390
|
-
var GatewayGenerationInfoFetcher2 = class {
|
|
12391
|
-
constructor(config) {
|
|
12392
|
-
this.config = config;
|
|
12393
|
-
}
|
|
12394
|
-
async getGenerationInfo(params) {
|
|
12395
|
-
try {
|
|
12396
|
-
const baseUrl = new URL(this.config.baseURL);
|
|
12397
|
-
const { value } = await getFromApi2({
|
|
12398
|
-
url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
|
|
12399
|
-
headers: await resolve2(this.config.headers()),
|
|
12400
|
-
successfulResponseHandler: createJsonResponseHandler2(
|
|
12401
|
-
gatewayGenerationInfoResponseSchema2
|
|
12402
|
-
),
|
|
12403
|
-
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
12404
|
-
errorSchema: z$1.any(),
|
|
12405
|
-
errorToMessage: (data) => data
|
|
12406
|
-
}),
|
|
12407
|
-
fetch: this.config.fetch
|
|
12408
|
-
});
|
|
12409
|
-
return value;
|
|
12410
|
-
} catch (error) {
|
|
12411
|
-
throw await asGatewayError2(error);
|
|
12412
|
-
}
|
|
12413
|
-
}
|
|
12414
|
-
};
|
|
12415
|
-
var gatewayGenerationInfoResponseSchema2 = lazySchema2(
|
|
12416
|
-
() => zodSchema3(
|
|
12417
|
-
z$1.object({
|
|
12418
|
-
data: z$1.object({
|
|
12419
|
-
id: z$1.string(),
|
|
12420
|
-
total_cost: z$1.number(),
|
|
12421
|
-
upstream_inference_cost: z$1.number(),
|
|
12422
|
-
usage: z$1.number(),
|
|
12423
|
-
created_at: z$1.string(),
|
|
12424
|
-
model: z$1.string(),
|
|
12425
|
-
is_byok: z$1.boolean(),
|
|
12426
|
-
provider_name: z$1.string(),
|
|
12427
|
-
streamed: z$1.boolean(),
|
|
12428
|
-
finish_reason: z$1.string(),
|
|
12429
|
-
latency: z$1.number(),
|
|
12430
|
-
generation_time: z$1.number(),
|
|
12431
|
-
native_tokens_prompt: z$1.number(),
|
|
12432
|
-
native_tokens_completion: z$1.number(),
|
|
12433
|
-
native_tokens_reasoning: z$1.number(),
|
|
12434
|
-
native_tokens_cached: z$1.number(),
|
|
12435
|
-
native_tokens_cache_creation: z$1.number(),
|
|
12436
|
-
billable_web_search_calls: z$1.number()
|
|
12437
|
-
}).transform(
|
|
12438
|
-
({
|
|
12439
|
-
total_cost,
|
|
12440
|
-
upstream_inference_cost,
|
|
12441
|
-
created_at,
|
|
12442
|
-
is_byok,
|
|
12443
|
-
provider_name,
|
|
12444
|
-
finish_reason,
|
|
12445
|
-
generation_time,
|
|
12446
|
-
native_tokens_prompt,
|
|
12447
|
-
native_tokens_completion,
|
|
12448
|
-
native_tokens_reasoning,
|
|
12449
|
-
native_tokens_cached,
|
|
12450
|
-
native_tokens_cache_creation,
|
|
12451
|
-
billable_web_search_calls,
|
|
12452
|
-
...rest
|
|
12453
|
-
}) => ({
|
|
12454
|
-
...rest,
|
|
12455
|
-
totalCost: total_cost,
|
|
12456
|
-
upstreamInferenceCost: upstream_inference_cost,
|
|
12457
|
-
createdAt: created_at,
|
|
12458
|
-
isByok: is_byok,
|
|
12459
|
-
providerName: provider_name,
|
|
12460
|
-
finishReason: finish_reason,
|
|
12461
|
-
generationTime: generation_time,
|
|
12462
|
-
promptTokens: native_tokens_prompt,
|
|
12463
|
-
completionTokens: native_tokens_completion,
|
|
12464
|
-
reasoningTokens: native_tokens_reasoning,
|
|
12465
|
-
cachedTokens: native_tokens_cached,
|
|
12466
|
-
cacheCreationTokens: native_tokens_cache_creation,
|
|
12467
|
-
billableWebSearchCalls: billable_web_search_calls
|
|
12468
|
-
})
|
|
12469
|
-
)
|
|
12470
|
-
}).transform(({ data }) => data)
|
|
12471
|
-
)
|
|
12472
|
-
);
|
|
12473
11945
|
var GatewayLanguageModel2 = class {
|
|
12474
11946
|
constructor(modelId, config) {
|
|
12475
11947
|
this.modelId = modelId;
|
|
@@ -13017,86 +12489,6 @@ var gatewayVideoEventSchema = z$1.discriminatedUnion("type", [
|
|
|
13017
12489
|
param: z$1.unknown().nullable()
|
|
13018
12490
|
})
|
|
13019
12491
|
]);
|
|
13020
|
-
var GatewayRerankingModel = class {
|
|
13021
|
-
constructor(modelId, config) {
|
|
13022
|
-
this.modelId = modelId;
|
|
13023
|
-
this.config = config;
|
|
13024
|
-
this.specificationVersion = "v3";
|
|
13025
|
-
}
|
|
13026
|
-
get provider() {
|
|
13027
|
-
return this.config.provider;
|
|
13028
|
-
}
|
|
13029
|
-
async doRerank({
|
|
13030
|
-
documents,
|
|
13031
|
-
query,
|
|
13032
|
-
topN,
|
|
13033
|
-
headers,
|
|
13034
|
-
abortSignal,
|
|
13035
|
-
providerOptions
|
|
13036
|
-
}) {
|
|
13037
|
-
const resolvedHeaders = await resolve2(this.config.headers());
|
|
13038
|
-
try {
|
|
13039
|
-
const {
|
|
13040
|
-
responseHeaders,
|
|
13041
|
-
value: responseBody,
|
|
13042
|
-
rawValue
|
|
13043
|
-
} = await postJsonToApi2({
|
|
13044
|
-
url: this.getUrl(),
|
|
13045
|
-
headers: combineHeaders2(
|
|
13046
|
-
resolvedHeaders,
|
|
13047
|
-
headers != null ? headers : {},
|
|
13048
|
-
this.getModelConfigHeaders(),
|
|
13049
|
-
await resolve2(this.config.o11yHeaders)
|
|
13050
|
-
),
|
|
13051
|
-
body: {
|
|
13052
|
-
documents,
|
|
13053
|
-
query,
|
|
13054
|
-
...topN != null ? { topN } : {},
|
|
13055
|
-
...providerOptions ? { providerOptions } : {}
|
|
13056
|
-
},
|
|
13057
|
-
successfulResponseHandler: createJsonResponseHandler2(
|
|
13058
|
-
gatewayRerankingResponseSchema
|
|
13059
|
-
),
|
|
13060
|
-
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
13061
|
-
errorSchema: z$1.any(),
|
|
13062
|
-
errorToMessage: (data) => data
|
|
13063
|
-
}),
|
|
13064
|
-
...abortSignal && { abortSignal },
|
|
13065
|
-
fetch: this.config.fetch
|
|
13066
|
-
});
|
|
13067
|
-
return {
|
|
13068
|
-
ranking: responseBody.ranking,
|
|
13069
|
-
providerMetadata: responseBody.providerMetadata,
|
|
13070
|
-
response: { headers: responseHeaders, body: rawValue },
|
|
13071
|
-
warnings: []
|
|
13072
|
-
};
|
|
13073
|
-
} catch (error) {
|
|
13074
|
-
throw await asGatewayError2(error, await parseAuthMethod2(resolvedHeaders));
|
|
13075
|
-
}
|
|
13076
|
-
}
|
|
13077
|
-
getUrl() {
|
|
13078
|
-
return `${this.config.baseURL}/reranking-model`;
|
|
13079
|
-
}
|
|
13080
|
-
getModelConfigHeaders() {
|
|
13081
|
-
return {
|
|
13082
|
-
"ai-reranking-model-specification-version": "3",
|
|
13083
|
-
"ai-model-id": this.modelId
|
|
13084
|
-
};
|
|
13085
|
-
}
|
|
13086
|
-
};
|
|
13087
|
-
var gatewayRerankingResponseSchema = lazySchema2(
|
|
13088
|
-
() => zodSchema3(
|
|
13089
|
-
z$1.object({
|
|
13090
|
-
ranking: z$1.array(
|
|
13091
|
-
z$1.object({
|
|
13092
|
-
index: z$1.number(),
|
|
13093
|
-
relevanceScore: z$1.number()
|
|
13094
|
-
})
|
|
13095
|
-
),
|
|
13096
|
-
providerMetadata: z$1.record(z$1.string(), z$1.record(z$1.string(), z$1.unknown())).optional()
|
|
13097
|
-
})
|
|
13098
|
-
)
|
|
13099
|
-
);
|
|
13100
12492
|
var parallelSearchInputSchema2 = lazySchema2(
|
|
13101
12493
|
() => zodSchema3(
|
|
13102
12494
|
z.object({
|
|
@@ -13273,7 +12665,7 @@ async function getVercelRequestId2() {
|
|
|
13273
12665
|
var _a932;
|
|
13274
12666
|
return (_a932 = getContext2().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
13275
12667
|
}
|
|
13276
|
-
var VERSION5 = "3.0.
|
|
12668
|
+
var VERSION5 = "3.0.66";
|
|
13277
12669
|
var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
|
|
13278
12670
|
function createGatewayProvider2(options = {}) {
|
|
13279
12671
|
var _a932, _b93;
|
|
@@ -13373,30 +12765,6 @@ function createGatewayProvider2(options = {}) {
|
|
|
13373
12765
|
);
|
|
13374
12766
|
});
|
|
13375
12767
|
};
|
|
13376
|
-
const getSpendReport = async (params) => {
|
|
13377
|
-
return new GatewaySpendReport2({
|
|
13378
|
-
baseURL,
|
|
13379
|
-
headers: getHeaders,
|
|
13380
|
-
fetch: options.fetch
|
|
13381
|
-
}).getSpendReport(params).catch(async (error) => {
|
|
13382
|
-
throw await asGatewayError2(
|
|
13383
|
-
error,
|
|
13384
|
-
await parseAuthMethod2(await getHeaders())
|
|
13385
|
-
);
|
|
13386
|
-
});
|
|
13387
|
-
};
|
|
13388
|
-
const getGenerationInfo = async (params) => {
|
|
13389
|
-
return new GatewayGenerationInfoFetcher2({
|
|
13390
|
-
baseURL,
|
|
13391
|
-
headers: getHeaders,
|
|
13392
|
-
fetch: options.fetch
|
|
13393
|
-
}).getGenerationInfo(params).catch(async (error) => {
|
|
13394
|
-
throw await asGatewayError2(
|
|
13395
|
-
error,
|
|
13396
|
-
await parseAuthMethod2(await getHeaders())
|
|
13397
|
-
);
|
|
13398
|
-
});
|
|
13399
|
-
};
|
|
13400
12768
|
const provider = function(modelId) {
|
|
13401
12769
|
if (new.target) {
|
|
13402
12770
|
throw new Error(
|
|
@@ -13408,8 +12776,6 @@ function createGatewayProvider2(options = {}) {
|
|
|
13408
12776
|
provider.specificationVersion = "v3";
|
|
13409
12777
|
provider.getAvailableModels = getAvailableModels;
|
|
13410
12778
|
provider.getCredits = getCredits;
|
|
13411
|
-
provider.getSpendReport = getSpendReport;
|
|
13412
|
-
provider.getGenerationInfo = getGenerationInfo;
|
|
13413
12779
|
provider.imageModel = (modelId) => {
|
|
13414
12780
|
return new GatewayImageModel2(modelId, {
|
|
13415
12781
|
provider: "gateway",
|
|
@@ -13440,17 +12806,6 @@ function createGatewayProvider2(options = {}) {
|
|
|
13440
12806
|
o11yHeaders: createO11yHeaders()
|
|
13441
12807
|
});
|
|
13442
12808
|
};
|
|
13443
|
-
const createRerankingModel = (modelId) => {
|
|
13444
|
-
return new GatewayRerankingModel(modelId, {
|
|
13445
|
-
provider: "gateway",
|
|
13446
|
-
baseURL,
|
|
13447
|
-
headers: getHeaders,
|
|
13448
|
-
fetch: options.fetch,
|
|
13449
|
-
o11yHeaders: createO11yHeaders()
|
|
13450
|
-
});
|
|
13451
|
-
};
|
|
13452
|
-
provider.rerankingModel = createRerankingModel;
|
|
13453
|
-
provider.reranking = createRerankingModel;
|
|
13454
12809
|
provider.chat = provider.languageModel;
|
|
13455
12810
|
provider.embedding = provider.embeddingModel;
|
|
13456
12811
|
provider.image = provider.imageModel;
|
|
@@ -14383,7 +13738,7 @@ function getTotalTimeoutMs(timeout) {
|
|
|
14383
13738
|
}
|
|
14384
13739
|
return timeout.totalMs;
|
|
14385
13740
|
}
|
|
14386
|
-
var VERSION33 = "6.0.
|
|
13741
|
+
var VERSION33 = "6.0.116";
|
|
14387
13742
|
var dataContentSchema3 = z$1.union([
|
|
14388
13743
|
z$1.string(),
|
|
14389
13744
|
z$1.instanceof(Uint8Array),
|
|
@@ -16594,7 +15949,7 @@ async function recallThreadFromStart({
|
|
|
16594
15949
|
var recallTool = (_memoryConfig, options) => {
|
|
16595
15950
|
const retrievalScope = options?.retrievalScope ?? "thread";
|
|
16596
15951
|
const isResourceScope = retrievalScope === "resource";
|
|
16597
|
-
const description = isResourceScope ? 'Browse conversation history. Use mode="threads" to list all threads for the current user. Use mode="messages" (default) to browse messages in the current thread or pass threadId to browse another thread in the active resource. If you pass only a cursor, it must belong to the current thread. Use mode="search" to find messages by content across all threads.' : `Browse conversation history in the current thread. Use mode="messages" (default) to page through messages near a cursor. Use mode="search" to find messages by content in this thread. Use mode="threads" to get the current thread's ID and title.`;
|
|
15952
|
+
const description = isResourceScope ? 'Browse conversation history. Use mode="threads" to list all threads for the current user. Use mode="messages" (default) to browse messages in the current thread or pass threadId to browse another thread in the active resource. When mode="messages" has no cursor or threadId, it defaults to the current thread and says so at the top of the result. If you pass only a cursor, it must belong to the current thread. Use mode="search" to find messages by content across all threads.' : `Browse conversation history in the current thread. Use mode="messages" (default) to page through messages near a cursor. Use mode="search" to find messages by content in this thread. Use mode="threads" to get the current thread's ID and title.`;
|
|
16598
15953
|
return createTool({
|
|
16599
15954
|
id: "recall",
|
|
16600
15955
|
description,
|
|
@@ -16619,7 +15974,7 @@ var recallTool = (_memoryConfig, options) => {
|
|
|
16619
15974
|
},
|
|
16620
15975
|
query: z.string().min(1).optional().describe('Search query for mode="search". Finds messages semantically similar to this text.'),
|
|
16621
15976
|
cursor: z.string().min(1).optional().describe(
|
|
16622
|
-
'A message ID to use as the pagination cursor. For mode="messages",
|
|
15977
|
+
'A message ID to use as the pagination cursor. For mode="messages", omit both cursor and threadId to browse the current thread. If only cursor is provided, it must belong to the current thread. Extract it from the start or end of an observation group range.'
|
|
16623
15978
|
),
|
|
16624
15979
|
anchor: z.enum(["start", "end"]).optional().describe(
|
|
16625
15980
|
'For mode="messages" without a cursor, page from the start (oldest-first) or end (newest-first) of the thread. Defaults to "start".'
|
|
@@ -16717,7 +16072,13 @@ var recallTool = (_memoryConfig, options) => {
|
|
|
16717
16072
|
after
|
|
16718
16073
|
});
|
|
16719
16074
|
}
|
|
16720
|
-
const
|
|
16075
|
+
const usedDefaultThreadId = isResourceScope && !explicitThreadId && !cursor && Boolean(currentThreadId);
|
|
16076
|
+
const defaultThreadNote = usedDefaultThreadId ? `threadId wasn't passed so used default ${currentThreadId}.
|
|
16077
|
+
|
|
16078
|
+
` : "";
|
|
16079
|
+
const effectiveThreadId = explicitThreadId || (usedDefaultThreadId ? "current" : void 0);
|
|
16080
|
+
const resolvedThreadId = effectiveThreadId === "current" ? currentThreadId : effectiveThreadId;
|
|
16081
|
+
const hasExplicitThreadId = typeof resolvedThreadId === "string" && resolvedThreadId.length > 0;
|
|
16721
16082
|
const hasCursor = typeof cursor === "string" && cursor.length > 0;
|
|
16722
16083
|
if (!hasExplicitThreadId && !hasCursor) {
|
|
16723
16084
|
throw new Error('Either cursor or threadId is required for mode="messages"');
|
|
@@ -16734,7 +16095,7 @@ var recallTool = (_memoryConfig, options) => {
|
|
|
16734
16095
|
if (!memory.getThreadById) {
|
|
16735
16096
|
throw new Error("Memory instance cannot verify thread access for recall");
|
|
16736
16097
|
}
|
|
16737
|
-
const thread = await memory.getThreadById({ threadId:
|
|
16098
|
+
const thread = await memory.getThreadById({ threadId: resolvedThreadId });
|
|
16738
16099
|
if (!thread || thread.resourceId !== resourceId) {
|
|
16739
16100
|
throw new Error("Thread does not belong to the active resource");
|
|
16740
16101
|
}
|
|
@@ -16769,7 +16130,7 @@ var recallTool = (_memoryConfig, options) => {
|
|
|
16769
16130
|
throw new Error("Thread ID is required for recall");
|
|
16770
16131
|
}
|
|
16771
16132
|
if (!cursor) {
|
|
16772
|
-
|
|
16133
|
+
const result = await recallThreadFromStart({
|
|
16773
16134
|
memory,
|
|
16774
16135
|
threadId: targetThreadId,
|
|
16775
16136
|
resourceId: isResourceScope ? resourceId : void 0,
|
|
@@ -16780,6 +16141,10 @@ var recallTool = (_memoryConfig, options) => {
|
|
|
16780
16141
|
toolName,
|
|
16781
16142
|
anchor: anchor ?? "start"
|
|
16782
16143
|
});
|
|
16144
|
+
if (defaultThreadNote) {
|
|
16145
|
+
return { ...result, messages: `${defaultThreadNote}${result.messages}` };
|
|
16146
|
+
}
|
|
16147
|
+
return result;
|
|
16783
16148
|
}
|
|
16784
16149
|
if (partIndex !== void 0 && partIndex !== null) {
|
|
16785
16150
|
return recallPart({
|