@mastra/memory 1.17.2 → 1.17.3
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 +15 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -13
- package/dist/docs/references/docs-agents-background-tasks.md +1 -1
- package/dist/index.cjs +599 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +594 -11
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -6,8 +6,7 @@ import * as z4 from 'zod/v4';
|
|
|
6
6
|
import { z as z$1 } from 'zod/v4';
|
|
7
7
|
import { MessageList } from '@mastra/core/agent';
|
|
8
8
|
import { coreFeatures } from '@mastra/core/features';
|
|
9
|
-
import { MastraMemory
|
|
10
|
-
export { extractWorkingMemoryContent, extractWorkingMemoryTags, removeWorkingMemoryTags } from '@mastra/core/memory';
|
|
9
|
+
import { MastraMemory } from '@mastra/core/memory';
|
|
11
10
|
import { EntityType, SpanType } from '@mastra/core/observability';
|
|
12
11
|
import { generateEmptyFromSchema } from '@mastra/core/utils';
|
|
13
12
|
import { isStandardSchemaWithJSON, toStandardSchema, standardSchemaToJSONSchema } from '@mastra/schema-compat/schema';
|
|
@@ -4562,7 +4561,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
4562
4561
|
);
|
|
4563
4562
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
4564
4563
|
}
|
|
4565
|
-
var VERSION2 = "3.0.
|
|
4564
|
+
var VERSION2 = "3.0.23";
|
|
4566
4565
|
var getOriginalFetch = () => globalThis.fetch;
|
|
4567
4566
|
var getFromApi = async ({
|
|
4568
4567
|
url,
|
|
@@ -6609,6 +6608,7 @@ async function parseAuthMethod(headers) {
|
|
|
6609
6608
|
var gatewayAuthMethodSchema = lazyValidator(
|
|
6610
6609
|
() => zodSchema2(z$1.union([z$1.literal("api-key"), z$1.literal("oidc")]))
|
|
6611
6610
|
);
|
|
6611
|
+
var KNOWN_MODEL_TYPES = ["embedding", "image", "language"];
|
|
6612
6612
|
var GatewayFetchMetadata = class {
|
|
6613
6613
|
constructor(config) {
|
|
6614
6614
|
this.config = config;
|
|
@@ -6679,8 +6679,12 @@ var gatewayAvailableModelsResponseSchema = lazyValidator(
|
|
|
6679
6679
|
provider: z$1.string(),
|
|
6680
6680
|
modelId: z$1.string()
|
|
6681
6681
|
}),
|
|
6682
|
-
modelType: z$1.
|
|
6682
|
+
modelType: z$1.string().nullish()
|
|
6683
6683
|
})
|
|
6684
|
+
).transform(
|
|
6685
|
+
(models) => models.filter(
|
|
6686
|
+
(m) => m.modelType == null || KNOWN_MODEL_TYPES.includes(m.modelType)
|
|
6687
|
+
)
|
|
6684
6688
|
)
|
|
6685
6689
|
})
|
|
6686
6690
|
)
|
|
@@ -6696,6 +6700,187 @@ var gatewayCreditsResponseSchema = lazyValidator(
|
|
|
6696
6700
|
}))
|
|
6697
6701
|
)
|
|
6698
6702
|
);
|
|
6703
|
+
var GatewaySpendReport = class {
|
|
6704
|
+
constructor(config) {
|
|
6705
|
+
this.config = config;
|
|
6706
|
+
}
|
|
6707
|
+
async getSpendReport(params) {
|
|
6708
|
+
try {
|
|
6709
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
6710
|
+
const searchParams = new URLSearchParams();
|
|
6711
|
+
searchParams.set("start_date", params.startDate);
|
|
6712
|
+
searchParams.set("end_date", params.endDate);
|
|
6713
|
+
if (params.groupBy) {
|
|
6714
|
+
searchParams.set("group_by", params.groupBy);
|
|
6715
|
+
}
|
|
6716
|
+
if (params.datePart) {
|
|
6717
|
+
searchParams.set("date_part", params.datePart);
|
|
6718
|
+
}
|
|
6719
|
+
if (params.userId) {
|
|
6720
|
+
searchParams.set("user_id", params.userId);
|
|
6721
|
+
}
|
|
6722
|
+
if (params.model) {
|
|
6723
|
+
searchParams.set("model", params.model);
|
|
6724
|
+
}
|
|
6725
|
+
if (params.provider) {
|
|
6726
|
+
searchParams.set("provider", params.provider);
|
|
6727
|
+
}
|
|
6728
|
+
if (params.credentialType) {
|
|
6729
|
+
searchParams.set("credential_type", params.credentialType);
|
|
6730
|
+
}
|
|
6731
|
+
if (params.tags && params.tags.length > 0) {
|
|
6732
|
+
searchParams.set("tags", params.tags.join(","));
|
|
6733
|
+
}
|
|
6734
|
+
const { value } = await getFromApi({
|
|
6735
|
+
url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
|
|
6736
|
+
headers: await resolve(this.config.headers()),
|
|
6737
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
6738
|
+
gatewaySpendReportResponseSchema
|
|
6739
|
+
),
|
|
6740
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
6741
|
+
errorSchema: z$1.any(),
|
|
6742
|
+
errorToMessage: (data) => data
|
|
6743
|
+
}),
|
|
6744
|
+
fetch: this.config.fetch
|
|
6745
|
+
});
|
|
6746
|
+
return value;
|
|
6747
|
+
} catch (error) {
|
|
6748
|
+
throw await asGatewayError(error);
|
|
6749
|
+
}
|
|
6750
|
+
}
|
|
6751
|
+
};
|
|
6752
|
+
var gatewaySpendReportResponseSchema = lazySchema(
|
|
6753
|
+
() => zodSchema2(
|
|
6754
|
+
z$1.object({
|
|
6755
|
+
results: z$1.array(
|
|
6756
|
+
z$1.object({
|
|
6757
|
+
day: z$1.string().optional(),
|
|
6758
|
+
hour: z$1.string().optional(),
|
|
6759
|
+
user: z$1.string().optional(),
|
|
6760
|
+
model: z$1.string().optional(),
|
|
6761
|
+
tag: z$1.string().optional(),
|
|
6762
|
+
provider: z$1.string().optional(),
|
|
6763
|
+
credential_type: z$1.enum(["byok", "system"]).optional(),
|
|
6764
|
+
total_cost: z$1.number(),
|
|
6765
|
+
market_cost: z$1.number().optional(),
|
|
6766
|
+
input_tokens: z$1.number().optional(),
|
|
6767
|
+
output_tokens: z$1.number().optional(),
|
|
6768
|
+
cached_input_tokens: z$1.number().optional(),
|
|
6769
|
+
cache_creation_input_tokens: z$1.number().optional(),
|
|
6770
|
+
reasoning_tokens: z$1.number().optional(),
|
|
6771
|
+
request_count: z$1.number().optional()
|
|
6772
|
+
}).transform(
|
|
6773
|
+
({
|
|
6774
|
+
credential_type,
|
|
6775
|
+
total_cost,
|
|
6776
|
+
market_cost,
|
|
6777
|
+
input_tokens,
|
|
6778
|
+
output_tokens,
|
|
6779
|
+
cached_input_tokens,
|
|
6780
|
+
cache_creation_input_tokens,
|
|
6781
|
+
reasoning_tokens,
|
|
6782
|
+
request_count,
|
|
6783
|
+
...rest
|
|
6784
|
+
}) => ({
|
|
6785
|
+
...rest,
|
|
6786
|
+
...credential_type !== void 0 ? { credentialType: credential_type } : {},
|
|
6787
|
+
totalCost: total_cost,
|
|
6788
|
+
...market_cost !== void 0 ? { marketCost: market_cost } : {},
|
|
6789
|
+
...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
|
|
6790
|
+
...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
|
|
6791
|
+
...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
|
|
6792
|
+
...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
|
|
6793
|
+
...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
|
|
6794
|
+
...request_count !== void 0 ? { requestCount: request_count } : {}
|
|
6795
|
+
})
|
|
6796
|
+
)
|
|
6797
|
+
)
|
|
6798
|
+
})
|
|
6799
|
+
)
|
|
6800
|
+
);
|
|
6801
|
+
var GatewayGenerationInfoFetcher = class {
|
|
6802
|
+
constructor(config) {
|
|
6803
|
+
this.config = config;
|
|
6804
|
+
}
|
|
6805
|
+
async getGenerationInfo(params) {
|
|
6806
|
+
try {
|
|
6807
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
6808
|
+
const { value } = await getFromApi({
|
|
6809
|
+
url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
|
|
6810
|
+
headers: await resolve(this.config.headers()),
|
|
6811
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
6812
|
+
gatewayGenerationInfoResponseSchema
|
|
6813
|
+
),
|
|
6814
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
6815
|
+
errorSchema: z$1.any(),
|
|
6816
|
+
errorToMessage: (data) => data
|
|
6817
|
+
}),
|
|
6818
|
+
fetch: this.config.fetch
|
|
6819
|
+
});
|
|
6820
|
+
return value;
|
|
6821
|
+
} catch (error) {
|
|
6822
|
+
throw await asGatewayError(error);
|
|
6823
|
+
}
|
|
6824
|
+
}
|
|
6825
|
+
};
|
|
6826
|
+
var gatewayGenerationInfoResponseSchema = lazySchema(
|
|
6827
|
+
() => zodSchema2(
|
|
6828
|
+
z$1.object({
|
|
6829
|
+
data: z$1.object({
|
|
6830
|
+
id: z$1.string(),
|
|
6831
|
+
total_cost: z$1.number(),
|
|
6832
|
+
upstream_inference_cost: z$1.number(),
|
|
6833
|
+
usage: z$1.number(),
|
|
6834
|
+
created_at: z$1.string(),
|
|
6835
|
+
model: z$1.string(),
|
|
6836
|
+
is_byok: z$1.boolean(),
|
|
6837
|
+
provider_name: z$1.string(),
|
|
6838
|
+
streamed: z$1.boolean(),
|
|
6839
|
+
finish_reason: z$1.string(),
|
|
6840
|
+
latency: z$1.number(),
|
|
6841
|
+
generation_time: z$1.number(),
|
|
6842
|
+
native_tokens_prompt: z$1.number(),
|
|
6843
|
+
native_tokens_completion: z$1.number(),
|
|
6844
|
+
native_tokens_reasoning: z$1.number(),
|
|
6845
|
+
native_tokens_cached: z$1.number(),
|
|
6846
|
+
native_tokens_cache_creation: z$1.number(),
|
|
6847
|
+
billable_web_search_calls: z$1.number()
|
|
6848
|
+
}).transform(
|
|
6849
|
+
({
|
|
6850
|
+
total_cost,
|
|
6851
|
+
upstream_inference_cost,
|
|
6852
|
+
created_at,
|
|
6853
|
+
is_byok,
|
|
6854
|
+
provider_name,
|
|
6855
|
+
finish_reason,
|
|
6856
|
+
generation_time,
|
|
6857
|
+
native_tokens_prompt,
|
|
6858
|
+
native_tokens_completion,
|
|
6859
|
+
native_tokens_reasoning,
|
|
6860
|
+
native_tokens_cached,
|
|
6861
|
+
native_tokens_cache_creation,
|
|
6862
|
+
billable_web_search_calls,
|
|
6863
|
+
...rest
|
|
6864
|
+
}) => ({
|
|
6865
|
+
...rest,
|
|
6866
|
+
totalCost: total_cost,
|
|
6867
|
+
upstreamInferenceCost: upstream_inference_cost,
|
|
6868
|
+
createdAt: created_at,
|
|
6869
|
+
isByok: is_byok,
|
|
6870
|
+
providerName: provider_name,
|
|
6871
|
+
finishReason: finish_reason,
|
|
6872
|
+
generationTime: generation_time,
|
|
6873
|
+
promptTokens: native_tokens_prompt,
|
|
6874
|
+
completionTokens: native_tokens_completion,
|
|
6875
|
+
reasoningTokens: native_tokens_reasoning,
|
|
6876
|
+
cachedTokens: native_tokens_cached,
|
|
6877
|
+
cacheCreationTokens: native_tokens_cache_creation,
|
|
6878
|
+
billableWebSearchCalls: billable_web_search_calls
|
|
6879
|
+
})
|
|
6880
|
+
)
|
|
6881
|
+
}).transform(({ data }) => data)
|
|
6882
|
+
)
|
|
6883
|
+
);
|
|
6699
6884
|
var GatewayLanguageModel = class {
|
|
6700
6885
|
constructor(modelId, config) {
|
|
6701
6886
|
this.modelId = modelId;
|
|
@@ -7198,7 +7383,7 @@ async function getVercelRequestId() {
|
|
|
7198
7383
|
var _a932;
|
|
7199
7384
|
return (_a932 = getContext().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
7200
7385
|
}
|
|
7201
|
-
var VERSION3 = "2.0.
|
|
7386
|
+
var VERSION3 = "2.0.82";
|
|
7202
7387
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
7203
7388
|
function createGatewayProvider(options = {}) {
|
|
7204
7389
|
var _a932, _b93;
|
|
@@ -7296,6 +7481,30 @@ function createGatewayProvider(options = {}) {
|
|
|
7296
7481
|
);
|
|
7297
7482
|
});
|
|
7298
7483
|
};
|
|
7484
|
+
const getSpendReport = async (params) => {
|
|
7485
|
+
return new GatewaySpendReport({
|
|
7486
|
+
baseURL,
|
|
7487
|
+
headers: getHeaders,
|
|
7488
|
+
fetch: options.fetch
|
|
7489
|
+
}).getSpendReport(params).catch(async (error) => {
|
|
7490
|
+
throw await asGatewayError(
|
|
7491
|
+
error,
|
|
7492
|
+
await parseAuthMethod(await getHeaders())
|
|
7493
|
+
);
|
|
7494
|
+
});
|
|
7495
|
+
};
|
|
7496
|
+
const getGenerationInfo = async (params) => {
|
|
7497
|
+
return new GatewayGenerationInfoFetcher({
|
|
7498
|
+
baseURL,
|
|
7499
|
+
headers: getHeaders,
|
|
7500
|
+
fetch: options.fetch
|
|
7501
|
+
}).getGenerationInfo(params).catch(async (error) => {
|
|
7502
|
+
throw await asGatewayError(
|
|
7503
|
+
error,
|
|
7504
|
+
await parseAuthMethod(await getHeaders())
|
|
7505
|
+
);
|
|
7506
|
+
});
|
|
7507
|
+
};
|
|
7299
7508
|
const provider = function(modelId) {
|
|
7300
7509
|
if (new.target) {
|
|
7301
7510
|
throw new Error(
|
|
@@ -7306,6 +7515,8 @@ function createGatewayProvider(options = {}) {
|
|
|
7306
7515
|
};
|
|
7307
7516
|
provider.getAvailableModels = getAvailableModels;
|
|
7308
7517
|
provider.getCredits = getCredits;
|
|
7518
|
+
provider.getSpendReport = getSpendReport;
|
|
7519
|
+
provider.getGenerationInfo = getGenerationInfo;
|
|
7309
7520
|
provider.imageModel = (modelId) => {
|
|
7310
7521
|
return new GatewayImageModel(modelId, {
|
|
7311
7522
|
provider: "gateway",
|
|
@@ -8159,7 +8370,7 @@ function getGlobalProvider() {
|
|
|
8159
8370
|
var _a163;
|
|
8160
8371
|
return (_a163 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a163 : gateway;
|
|
8161
8372
|
}
|
|
8162
|
-
var VERSION32 = "5.0.
|
|
8373
|
+
var VERSION32 = "5.0.179";
|
|
8163
8374
|
var dataContentSchema2 = z$1.union([
|
|
8164
8375
|
z$1.string(),
|
|
8165
8376
|
z$1.instanceof(Uint8Array),
|
|
@@ -9770,7 +9981,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
9770
9981
|
);
|
|
9771
9982
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
9772
9983
|
}
|
|
9773
|
-
var VERSION4 = "4.0.
|
|
9984
|
+
var VERSION4 = "4.0.23";
|
|
9774
9985
|
var getOriginalFetch3 = () => globalThis.fetch;
|
|
9775
9986
|
var getFromApi2 = async ({
|
|
9776
9987
|
url,
|
|
@@ -11855,6 +12066,13 @@ async function parseAuthMethod2(headers) {
|
|
|
11855
12066
|
var gatewayAuthMethodSchema2 = lazySchema2(
|
|
11856
12067
|
() => zodSchema3(z$1.union([z$1.literal("api-key"), z$1.literal("oidc")]))
|
|
11857
12068
|
);
|
|
12069
|
+
var KNOWN_MODEL_TYPES2 = [
|
|
12070
|
+
"embedding",
|
|
12071
|
+
"image",
|
|
12072
|
+
"language",
|
|
12073
|
+
"reranking",
|
|
12074
|
+
"video"
|
|
12075
|
+
];
|
|
11858
12076
|
var GatewayFetchMetadata2 = class {
|
|
11859
12077
|
constructor(config) {
|
|
11860
12078
|
this.config = config;
|
|
@@ -11925,8 +12143,12 @@ var gatewayAvailableModelsResponseSchema2 = lazySchema2(
|
|
|
11925
12143
|
provider: z$1.string(),
|
|
11926
12144
|
modelId: z$1.string()
|
|
11927
12145
|
}),
|
|
11928
|
-
modelType: z$1.
|
|
12146
|
+
modelType: z$1.string().nullish()
|
|
11929
12147
|
})
|
|
12148
|
+
).transform(
|
|
12149
|
+
(models) => models.filter(
|
|
12150
|
+
(m) => m.modelType == null || KNOWN_MODEL_TYPES2.includes(m.modelType)
|
|
12151
|
+
)
|
|
11930
12152
|
)
|
|
11931
12153
|
})
|
|
11932
12154
|
)
|
|
@@ -11942,6 +12164,187 @@ var gatewayCreditsResponseSchema2 = lazySchema2(
|
|
|
11942
12164
|
}))
|
|
11943
12165
|
)
|
|
11944
12166
|
);
|
|
12167
|
+
var GatewaySpendReport2 = class {
|
|
12168
|
+
constructor(config) {
|
|
12169
|
+
this.config = config;
|
|
12170
|
+
}
|
|
12171
|
+
async getSpendReport(params) {
|
|
12172
|
+
try {
|
|
12173
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
12174
|
+
const searchParams = new URLSearchParams();
|
|
12175
|
+
searchParams.set("start_date", params.startDate);
|
|
12176
|
+
searchParams.set("end_date", params.endDate);
|
|
12177
|
+
if (params.groupBy) {
|
|
12178
|
+
searchParams.set("group_by", params.groupBy);
|
|
12179
|
+
}
|
|
12180
|
+
if (params.datePart) {
|
|
12181
|
+
searchParams.set("date_part", params.datePart);
|
|
12182
|
+
}
|
|
12183
|
+
if (params.userId) {
|
|
12184
|
+
searchParams.set("user_id", params.userId);
|
|
12185
|
+
}
|
|
12186
|
+
if (params.model) {
|
|
12187
|
+
searchParams.set("model", params.model);
|
|
12188
|
+
}
|
|
12189
|
+
if (params.provider) {
|
|
12190
|
+
searchParams.set("provider", params.provider);
|
|
12191
|
+
}
|
|
12192
|
+
if (params.credentialType) {
|
|
12193
|
+
searchParams.set("credential_type", params.credentialType);
|
|
12194
|
+
}
|
|
12195
|
+
if (params.tags && params.tags.length > 0) {
|
|
12196
|
+
searchParams.set("tags", params.tags.join(","));
|
|
12197
|
+
}
|
|
12198
|
+
const { value } = await getFromApi2({
|
|
12199
|
+
url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
|
|
12200
|
+
headers: await resolve2(this.config.headers()),
|
|
12201
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
12202
|
+
gatewaySpendReportResponseSchema2
|
|
12203
|
+
),
|
|
12204
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
12205
|
+
errorSchema: z$1.any(),
|
|
12206
|
+
errorToMessage: (data) => data
|
|
12207
|
+
}),
|
|
12208
|
+
fetch: this.config.fetch
|
|
12209
|
+
});
|
|
12210
|
+
return value;
|
|
12211
|
+
} catch (error) {
|
|
12212
|
+
throw await asGatewayError2(error);
|
|
12213
|
+
}
|
|
12214
|
+
}
|
|
12215
|
+
};
|
|
12216
|
+
var gatewaySpendReportResponseSchema2 = lazySchema2(
|
|
12217
|
+
() => zodSchema3(
|
|
12218
|
+
z$1.object({
|
|
12219
|
+
results: z$1.array(
|
|
12220
|
+
z$1.object({
|
|
12221
|
+
day: z$1.string().optional(),
|
|
12222
|
+
hour: z$1.string().optional(),
|
|
12223
|
+
user: z$1.string().optional(),
|
|
12224
|
+
model: z$1.string().optional(),
|
|
12225
|
+
tag: z$1.string().optional(),
|
|
12226
|
+
provider: z$1.string().optional(),
|
|
12227
|
+
credential_type: z$1.enum(["byok", "system"]).optional(),
|
|
12228
|
+
total_cost: z$1.number(),
|
|
12229
|
+
market_cost: z$1.number().optional(),
|
|
12230
|
+
input_tokens: z$1.number().optional(),
|
|
12231
|
+
output_tokens: z$1.number().optional(),
|
|
12232
|
+
cached_input_tokens: z$1.number().optional(),
|
|
12233
|
+
cache_creation_input_tokens: z$1.number().optional(),
|
|
12234
|
+
reasoning_tokens: z$1.number().optional(),
|
|
12235
|
+
request_count: z$1.number().optional()
|
|
12236
|
+
}).transform(
|
|
12237
|
+
({
|
|
12238
|
+
credential_type,
|
|
12239
|
+
total_cost,
|
|
12240
|
+
market_cost,
|
|
12241
|
+
input_tokens,
|
|
12242
|
+
output_tokens,
|
|
12243
|
+
cached_input_tokens,
|
|
12244
|
+
cache_creation_input_tokens,
|
|
12245
|
+
reasoning_tokens,
|
|
12246
|
+
request_count,
|
|
12247
|
+
...rest
|
|
12248
|
+
}) => ({
|
|
12249
|
+
...rest,
|
|
12250
|
+
...credential_type !== void 0 ? { credentialType: credential_type } : {},
|
|
12251
|
+
totalCost: total_cost,
|
|
12252
|
+
...market_cost !== void 0 ? { marketCost: market_cost } : {},
|
|
12253
|
+
...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
|
|
12254
|
+
...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
|
|
12255
|
+
...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
|
|
12256
|
+
...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
|
|
12257
|
+
...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
|
|
12258
|
+
...request_count !== void 0 ? { requestCount: request_count } : {}
|
|
12259
|
+
})
|
|
12260
|
+
)
|
|
12261
|
+
)
|
|
12262
|
+
})
|
|
12263
|
+
)
|
|
12264
|
+
);
|
|
12265
|
+
var GatewayGenerationInfoFetcher2 = class {
|
|
12266
|
+
constructor(config) {
|
|
12267
|
+
this.config = config;
|
|
12268
|
+
}
|
|
12269
|
+
async getGenerationInfo(params) {
|
|
12270
|
+
try {
|
|
12271
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
12272
|
+
const { value } = await getFromApi2({
|
|
12273
|
+
url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
|
|
12274
|
+
headers: await resolve2(this.config.headers()),
|
|
12275
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
12276
|
+
gatewayGenerationInfoResponseSchema2
|
|
12277
|
+
),
|
|
12278
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
12279
|
+
errorSchema: z$1.any(),
|
|
12280
|
+
errorToMessage: (data) => data
|
|
12281
|
+
}),
|
|
12282
|
+
fetch: this.config.fetch
|
|
12283
|
+
});
|
|
12284
|
+
return value;
|
|
12285
|
+
} catch (error) {
|
|
12286
|
+
throw await asGatewayError2(error);
|
|
12287
|
+
}
|
|
12288
|
+
}
|
|
12289
|
+
};
|
|
12290
|
+
var gatewayGenerationInfoResponseSchema2 = lazySchema2(
|
|
12291
|
+
() => zodSchema3(
|
|
12292
|
+
z$1.object({
|
|
12293
|
+
data: z$1.object({
|
|
12294
|
+
id: z$1.string(),
|
|
12295
|
+
total_cost: z$1.number(),
|
|
12296
|
+
upstream_inference_cost: z$1.number(),
|
|
12297
|
+
usage: z$1.number(),
|
|
12298
|
+
created_at: z$1.string(),
|
|
12299
|
+
model: z$1.string(),
|
|
12300
|
+
is_byok: z$1.boolean(),
|
|
12301
|
+
provider_name: z$1.string(),
|
|
12302
|
+
streamed: z$1.boolean(),
|
|
12303
|
+
finish_reason: z$1.string(),
|
|
12304
|
+
latency: z$1.number(),
|
|
12305
|
+
generation_time: z$1.number(),
|
|
12306
|
+
native_tokens_prompt: z$1.number(),
|
|
12307
|
+
native_tokens_completion: z$1.number(),
|
|
12308
|
+
native_tokens_reasoning: z$1.number(),
|
|
12309
|
+
native_tokens_cached: z$1.number(),
|
|
12310
|
+
native_tokens_cache_creation: z$1.number(),
|
|
12311
|
+
billable_web_search_calls: z$1.number()
|
|
12312
|
+
}).transform(
|
|
12313
|
+
({
|
|
12314
|
+
total_cost,
|
|
12315
|
+
upstream_inference_cost,
|
|
12316
|
+
created_at,
|
|
12317
|
+
is_byok,
|
|
12318
|
+
provider_name,
|
|
12319
|
+
finish_reason,
|
|
12320
|
+
generation_time,
|
|
12321
|
+
native_tokens_prompt,
|
|
12322
|
+
native_tokens_completion,
|
|
12323
|
+
native_tokens_reasoning,
|
|
12324
|
+
native_tokens_cached,
|
|
12325
|
+
native_tokens_cache_creation,
|
|
12326
|
+
billable_web_search_calls,
|
|
12327
|
+
...rest
|
|
12328
|
+
}) => ({
|
|
12329
|
+
...rest,
|
|
12330
|
+
totalCost: total_cost,
|
|
12331
|
+
upstreamInferenceCost: upstream_inference_cost,
|
|
12332
|
+
createdAt: created_at,
|
|
12333
|
+
isByok: is_byok,
|
|
12334
|
+
providerName: provider_name,
|
|
12335
|
+
finishReason: finish_reason,
|
|
12336
|
+
generationTime: generation_time,
|
|
12337
|
+
promptTokens: native_tokens_prompt,
|
|
12338
|
+
completionTokens: native_tokens_completion,
|
|
12339
|
+
reasoningTokens: native_tokens_reasoning,
|
|
12340
|
+
cachedTokens: native_tokens_cached,
|
|
12341
|
+
cacheCreationTokens: native_tokens_cache_creation,
|
|
12342
|
+
billableWebSearchCalls: billable_web_search_calls
|
|
12343
|
+
})
|
|
12344
|
+
)
|
|
12345
|
+
}).transform(({ data }) => data)
|
|
12346
|
+
)
|
|
12347
|
+
);
|
|
11945
12348
|
var GatewayLanguageModel2 = class {
|
|
11946
12349
|
constructor(modelId, config) {
|
|
11947
12350
|
this.modelId = modelId;
|
|
@@ -12489,6 +12892,86 @@ var gatewayVideoEventSchema = z$1.discriminatedUnion("type", [
|
|
|
12489
12892
|
param: z$1.unknown().nullable()
|
|
12490
12893
|
})
|
|
12491
12894
|
]);
|
|
12895
|
+
var GatewayRerankingModel = class {
|
|
12896
|
+
constructor(modelId, config) {
|
|
12897
|
+
this.modelId = modelId;
|
|
12898
|
+
this.config = config;
|
|
12899
|
+
this.specificationVersion = "v3";
|
|
12900
|
+
}
|
|
12901
|
+
get provider() {
|
|
12902
|
+
return this.config.provider;
|
|
12903
|
+
}
|
|
12904
|
+
async doRerank({
|
|
12905
|
+
documents,
|
|
12906
|
+
query,
|
|
12907
|
+
topN,
|
|
12908
|
+
headers,
|
|
12909
|
+
abortSignal,
|
|
12910
|
+
providerOptions
|
|
12911
|
+
}) {
|
|
12912
|
+
const resolvedHeaders = await resolve2(this.config.headers());
|
|
12913
|
+
try {
|
|
12914
|
+
const {
|
|
12915
|
+
responseHeaders,
|
|
12916
|
+
value: responseBody,
|
|
12917
|
+
rawValue
|
|
12918
|
+
} = await postJsonToApi2({
|
|
12919
|
+
url: this.getUrl(),
|
|
12920
|
+
headers: combineHeaders2(
|
|
12921
|
+
resolvedHeaders,
|
|
12922
|
+
headers != null ? headers : {},
|
|
12923
|
+
this.getModelConfigHeaders(),
|
|
12924
|
+
await resolve2(this.config.o11yHeaders)
|
|
12925
|
+
),
|
|
12926
|
+
body: {
|
|
12927
|
+
documents,
|
|
12928
|
+
query,
|
|
12929
|
+
...topN != null ? { topN } : {},
|
|
12930
|
+
...providerOptions ? { providerOptions } : {}
|
|
12931
|
+
},
|
|
12932
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
12933
|
+
gatewayRerankingResponseSchema
|
|
12934
|
+
),
|
|
12935
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
12936
|
+
errorSchema: z$1.any(),
|
|
12937
|
+
errorToMessage: (data) => data
|
|
12938
|
+
}),
|
|
12939
|
+
...abortSignal && { abortSignal },
|
|
12940
|
+
fetch: this.config.fetch
|
|
12941
|
+
});
|
|
12942
|
+
return {
|
|
12943
|
+
ranking: responseBody.ranking,
|
|
12944
|
+
providerMetadata: responseBody.providerMetadata,
|
|
12945
|
+
response: { headers: responseHeaders, body: rawValue },
|
|
12946
|
+
warnings: []
|
|
12947
|
+
};
|
|
12948
|
+
} catch (error) {
|
|
12949
|
+
throw await asGatewayError2(error, await parseAuthMethod2(resolvedHeaders));
|
|
12950
|
+
}
|
|
12951
|
+
}
|
|
12952
|
+
getUrl() {
|
|
12953
|
+
return `${this.config.baseURL}/reranking-model`;
|
|
12954
|
+
}
|
|
12955
|
+
getModelConfigHeaders() {
|
|
12956
|
+
return {
|
|
12957
|
+
"ai-reranking-model-specification-version": "3",
|
|
12958
|
+
"ai-model-id": this.modelId
|
|
12959
|
+
};
|
|
12960
|
+
}
|
|
12961
|
+
};
|
|
12962
|
+
var gatewayRerankingResponseSchema = lazySchema2(
|
|
12963
|
+
() => zodSchema3(
|
|
12964
|
+
z$1.object({
|
|
12965
|
+
ranking: z$1.array(
|
|
12966
|
+
z$1.object({
|
|
12967
|
+
index: z$1.number(),
|
|
12968
|
+
relevanceScore: z$1.number()
|
|
12969
|
+
})
|
|
12970
|
+
),
|
|
12971
|
+
providerMetadata: z$1.record(z$1.string(), z$1.record(z$1.string(), z$1.unknown())).optional()
|
|
12972
|
+
})
|
|
12973
|
+
)
|
|
12974
|
+
);
|
|
12492
12975
|
var parallelSearchInputSchema2 = lazySchema2(
|
|
12493
12976
|
() => zodSchema3(
|
|
12494
12977
|
z.object({
|
|
@@ -12665,7 +13148,7 @@ async function getVercelRequestId2() {
|
|
|
12665
13148
|
var _a932;
|
|
12666
13149
|
return (_a932 = getContext2().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
12667
13150
|
}
|
|
12668
|
-
var VERSION5 = "3.0.
|
|
13151
|
+
var VERSION5 = "3.0.104";
|
|
12669
13152
|
var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
|
|
12670
13153
|
function createGatewayProvider2(options = {}) {
|
|
12671
13154
|
var _a932, _b93;
|
|
@@ -12765,6 +13248,30 @@ function createGatewayProvider2(options = {}) {
|
|
|
12765
13248
|
);
|
|
12766
13249
|
});
|
|
12767
13250
|
};
|
|
13251
|
+
const getSpendReport = async (params) => {
|
|
13252
|
+
return new GatewaySpendReport2({
|
|
13253
|
+
baseURL,
|
|
13254
|
+
headers: getHeaders,
|
|
13255
|
+
fetch: options.fetch
|
|
13256
|
+
}).getSpendReport(params).catch(async (error) => {
|
|
13257
|
+
throw await asGatewayError2(
|
|
13258
|
+
error,
|
|
13259
|
+
await parseAuthMethod2(await getHeaders())
|
|
13260
|
+
);
|
|
13261
|
+
});
|
|
13262
|
+
};
|
|
13263
|
+
const getGenerationInfo = async (params) => {
|
|
13264
|
+
return new GatewayGenerationInfoFetcher2({
|
|
13265
|
+
baseURL,
|
|
13266
|
+
headers: getHeaders,
|
|
13267
|
+
fetch: options.fetch
|
|
13268
|
+
}).getGenerationInfo(params).catch(async (error) => {
|
|
13269
|
+
throw await asGatewayError2(
|
|
13270
|
+
error,
|
|
13271
|
+
await parseAuthMethod2(await getHeaders())
|
|
13272
|
+
);
|
|
13273
|
+
});
|
|
13274
|
+
};
|
|
12768
13275
|
const provider = function(modelId) {
|
|
12769
13276
|
if (new.target) {
|
|
12770
13277
|
throw new Error(
|
|
@@ -12776,6 +13283,8 @@ function createGatewayProvider2(options = {}) {
|
|
|
12776
13283
|
provider.specificationVersion = "v3";
|
|
12777
13284
|
provider.getAvailableModels = getAvailableModels;
|
|
12778
13285
|
provider.getCredits = getCredits;
|
|
13286
|
+
provider.getSpendReport = getSpendReport;
|
|
13287
|
+
provider.getGenerationInfo = getGenerationInfo;
|
|
12779
13288
|
provider.imageModel = (modelId) => {
|
|
12780
13289
|
return new GatewayImageModel2(modelId, {
|
|
12781
13290
|
provider: "gateway",
|
|
@@ -12806,6 +13315,17 @@ function createGatewayProvider2(options = {}) {
|
|
|
12806
13315
|
o11yHeaders: createO11yHeaders()
|
|
12807
13316
|
});
|
|
12808
13317
|
};
|
|
13318
|
+
const createRerankingModel = (modelId) => {
|
|
13319
|
+
return new GatewayRerankingModel(modelId, {
|
|
13320
|
+
provider: "gateway",
|
|
13321
|
+
baseURL,
|
|
13322
|
+
headers: getHeaders,
|
|
13323
|
+
fetch: options.fetch,
|
|
13324
|
+
o11yHeaders: createO11yHeaders()
|
|
13325
|
+
});
|
|
13326
|
+
};
|
|
13327
|
+
provider.rerankingModel = createRerankingModel;
|
|
13328
|
+
provider.reranking = createRerankingModel;
|
|
12809
13329
|
provider.chat = provider.languageModel;
|
|
12810
13330
|
provider.embedding = provider.embeddingModel;
|
|
12811
13331
|
provider.image = provider.imageModel;
|
|
@@ -13738,7 +14258,7 @@ function getTotalTimeoutMs(timeout) {
|
|
|
13738
14258
|
}
|
|
13739
14259
|
return timeout.totalMs;
|
|
13740
14260
|
}
|
|
13741
|
-
var VERSION33 = "6.0.
|
|
14261
|
+
var VERSION33 = "6.0.168";
|
|
13742
14262
|
var dataContentSchema3 = z$1.union([
|
|
13743
14263
|
z$1.string(),
|
|
13744
14264
|
z$1.instanceof(Uint8Array),
|
|
@@ -16440,6 +16960,69 @@ var __experimental_updateWorkingMemoryToolVNext = (config) => {
|
|
|
16440
16960
|
}
|
|
16441
16961
|
});
|
|
16442
16962
|
};
|
|
16963
|
+
var WORKING_MEMORY_START_TAG = "<working_memory>";
|
|
16964
|
+
var WORKING_MEMORY_END_TAG = "</working_memory>";
|
|
16965
|
+
var LEGACY_SYSTEM_REMINDER_METADATA_KEY = "dynamicAgentsMdReminder";
|
|
16966
|
+
function isRecord(value) {
|
|
16967
|
+
return typeof value === "object" && value !== null;
|
|
16968
|
+
}
|
|
16969
|
+
function extractWorkingMemoryTags(text4) {
|
|
16970
|
+
const results = [];
|
|
16971
|
+
let pos = 0;
|
|
16972
|
+
while (pos < text4.length) {
|
|
16973
|
+
const start = text4.indexOf(WORKING_MEMORY_START_TAG, pos);
|
|
16974
|
+
if (start === -1) break;
|
|
16975
|
+
const end = text4.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
|
|
16976
|
+
if (end === -1) break;
|
|
16977
|
+
results.push(text4.substring(start, end + WORKING_MEMORY_END_TAG.length));
|
|
16978
|
+
pos = end + WORKING_MEMORY_END_TAG.length;
|
|
16979
|
+
}
|
|
16980
|
+
return results.length > 0 ? results : null;
|
|
16981
|
+
}
|
|
16982
|
+
function removeWorkingMemoryTags(text4) {
|
|
16983
|
+
let result = "";
|
|
16984
|
+
let pos = 0;
|
|
16985
|
+
while (pos < text4.length) {
|
|
16986
|
+
const start = text4.indexOf(WORKING_MEMORY_START_TAG, pos);
|
|
16987
|
+
if (start === -1) {
|
|
16988
|
+
result += text4.substring(pos);
|
|
16989
|
+
break;
|
|
16990
|
+
}
|
|
16991
|
+
result += text4.substring(pos, start);
|
|
16992
|
+
const end = text4.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
|
|
16993
|
+
if (end === -1) {
|
|
16994
|
+
result += text4.substring(start);
|
|
16995
|
+
break;
|
|
16996
|
+
}
|
|
16997
|
+
pos = end + WORKING_MEMORY_END_TAG.length;
|
|
16998
|
+
}
|
|
16999
|
+
return result;
|
|
17000
|
+
}
|
|
17001
|
+
function extractWorkingMemoryContent(text4) {
|
|
17002
|
+
const start = text4.indexOf(WORKING_MEMORY_START_TAG);
|
|
17003
|
+
if (start === -1) return null;
|
|
17004
|
+
const contentStart = start + WORKING_MEMORY_START_TAG.length;
|
|
17005
|
+
const end = text4.indexOf(WORKING_MEMORY_END_TAG, contentStart);
|
|
17006
|
+
if (end === -1) return null;
|
|
17007
|
+
return text4.substring(contentStart, end);
|
|
17008
|
+
}
|
|
17009
|
+
function isSystemReminderMessage(message) {
|
|
17010
|
+
if (message.role !== "user" || !isRecord(message.content)) {
|
|
17011
|
+
return false;
|
|
17012
|
+
}
|
|
17013
|
+
const metadata = message.content.metadata;
|
|
17014
|
+
if (isRecord(metadata) && (isRecord(metadata.systemReminder) || LEGACY_SYSTEM_REMINDER_METADATA_KEY in metadata)) {
|
|
17015
|
+
return true;
|
|
17016
|
+
}
|
|
17017
|
+
const firstTextPart = message.content.parts.find((part) => part.type === "text");
|
|
17018
|
+
return typeof firstTextPart?.text === "string" && firstTextPart.text.startsWith("<system-reminder");
|
|
17019
|
+
}
|
|
17020
|
+
function filterSystemReminderMessages(messages, includeSystemReminders) {
|
|
17021
|
+
if (includeSystemReminders) {
|
|
17022
|
+
return messages;
|
|
17023
|
+
}
|
|
17024
|
+
return messages.filter((message) => !isSystemReminderMessage(message));
|
|
17025
|
+
}
|
|
16443
17026
|
function normalizeObservationalMemoryConfig(config) {
|
|
16444
17027
|
if (config === true) return { model: "google/gemini-2.5-flash" };
|
|
16445
17028
|
if (config === false || config === void 0) return void 0;
|
|
@@ -18277,6 +18860,6 @@ Notes:
|
|
|
18277
18860
|
}
|
|
18278
18861
|
};
|
|
18279
18862
|
|
|
18280
|
-
export { Memory, deepMergeWorkingMemory };
|
|
18863
|
+
export { Memory, deepMergeWorkingMemory, extractWorkingMemoryContent, extractWorkingMemoryTags, removeWorkingMemoryTags };
|
|
18281
18864
|
//# sourceMappingURL=index.js.map
|
|
18282
18865
|
//# sourceMappingURL=index.js.map
|