@mastra/memory 1.17.2 → 1.17.3-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 +6 -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 +6 -6
package/dist/index.cjs
CHANGED
|
@@ -4584,7 +4584,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
|
|
|
4584
4584
|
);
|
|
4585
4585
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
4586
4586
|
}
|
|
4587
|
-
var VERSION2 = "3.0.
|
|
4587
|
+
var VERSION2 = "3.0.23";
|
|
4588
4588
|
var getOriginalFetch = () => globalThis.fetch;
|
|
4589
4589
|
var getFromApi = async ({
|
|
4590
4590
|
url,
|
|
@@ -6631,6 +6631,7 @@ async function parseAuthMethod(headers) {
|
|
|
6631
6631
|
var gatewayAuthMethodSchema = lazyValidator(
|
|
6632
6632
|
() => zodSchema2(z4.z.union([z4.z.literal("api-key"), z4.z.literal("oidc")]))
|
|
6633
6633
|
);
|
|
6634
|
+
var KNOWN_MODEL_TYPES = ["embedding", "image", "language"];
|
|
6634
6635
|
var GatewayFetchMetadata = class {
|
|
6635
6636
|
constructor(config) {
|
|
6636
6637
|
this.config = config;
|
|
@@ -6701,8 +6702,12 @@ var gatewayAvailableModelsResponseSchema = lazyValidator(
|
|
|
6701
6702
|
provider: z4.z.string(),
|
|
6702
6703
|
modelId: z4.z.string()
|
|
6703
6704
|
}),
|
|
6704
|
-
modelType: z4.z.
|
|
6705
|
+
modelType: z4.z.string().nullish()
|
|
6705
6706
|
})
|
|
6707
|
+
).transform(
|
|
6708
|
+
(models) => models.filter(
|
|
6709
|
+
(m) => m.modelType == null || KNOWN_MODEL_TYPES.includes(m.modelType)
|
|
6710
|
+
)
|
|
6706
6711
|
)
|
|
6707
6712
|
})
|
|
6708
6713
|
)
|
|
@@ -6718,6 +6723,187 @@ var gatewayCreditsResponseSchema = lazyValidator(
|
|
|
6718
6723
|
}))
|
|
6719
6724
|
)
|
|
6720
6725
|
);
|
|
6726
|
+
var GatewaySpendReport = class {
|
|
6727
|
+
constructor(config) {
|
|
6728
|
+
this.config = config;
|
|
6729
|
+
}
|
|
6730
|
+
async getSpendReport(params) {
|
|
6731
|
+
try {
|
|
6732
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
6733
|
+
const searchParams = new URLSearchParams();
|
|
6734
|
+
searchParams.set("start_date", params.startDate);
|
|
6735
|
+
searchParams.set("end_date", params.endDate);
|
|
6736
|
+
if (params.groupBy) {
|
|
6737
|
+
searchParams.set("group_by", params.groupBy);
|
|
6738
|
+
}
|
|
6739
|
+
if (params.datePart) {
|
|
6740
|
+
searchParams.set("date_part", params.datePart);
|
|
6741
|
+
}
|
|
6742
|
+
if (params.userId) {
|
|
6743
|
+
searchParams.set("user_id", params.userId);
|
|
6744
|
+
}
|
|
6745
|
+
if (params.model) {
|
|
6746
|
+
searchParams.set("model", params.model);
|
|
6747
|
+
}
|
|
6748
|
+
if (params.provider) {
|
|
6749
|
+
searchParams.set("provider", params.provider);
|
|
6750
|
+
}
|
|
6751
|
+
if (params.credentialType) {
|
|
6752
|
+
searchParams.set("credential_type", params.credentialType);
|
|
6753
|
+
}
|
|
6754
|
+
if (params.tags && params.tags.length > 0) {
|
|
6755
|
+
searchParams.set("tags", params.tags.join(","));
|
|
6756
|
+
}
|
|
6757
|
+
const { value } = await getFromApi({
|
|
6758
|
+
url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
|
|
6759
|
+
headers: await resolve(this.config.headers()),
|
|
6760
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
6761
|
+
gatewaySpendReportResponseSchema
|
|
6762
|
+
),
|
|
6763
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
6764
|
+
errorSchema: z4.z.any(),
|
|
6765
|
+
errorToMessage: (data) => data
|
|
6766
|
+
}),
|
|
6767
|
+
fetch: this.config.fetch
|
|
6768
|
+
});
|
|
6769
|
+
return value;
|
|
6770
|
+
} catch (error) {
|
|
6771
|
+
throw await asGatewayError(error);
|
|
6772
|
+
}
|
|
6773
|
+
}
|
|
6774
|
+
};
|
|
6775
|
+
var gatewaySpendReportResponseSchema = lazySchema(
|
|
6776
|
+
() => zodSchema2(
|
|
6777
|
+
z4.z.object({
|
|
6778
|
+
results: z4.z.array(
|
|
6779
|
+
z4.z.object({
|
|
6780
|
+
day: z4.z.string().optional(),
|
|
6781
|
+
hour: z4.z.string().optional(),
|
|
6782
|
+
user: z4.z.string().optional(),
|
|
6783
|
+
model: z4.z.string().optional(),
|
|
6784
|
+
tag: z4.z.string().optional(),
|
|
6785
|
+
provider: z4.z.string().optional(),
|
|
6786
|
+
credential_type: z4.z.enum(["byok", "system"]).optional(),
|
|
6787
|
+
total_cost: z4.z.number(),
|
|
6788
|
+
market_cost: z4.z.number().optional(),
|
|
6789
|
+
input_tokens: z4.z.number().optional(),
|
|
6790
|
+
output_tokens: z4.z.number().optional(),
|
|
6791
|
+
cached_input_tokens: z4.z.number().optional(),
|
|
6792
|
+
cache_creation_input_tokens: z4.z.number().optional(),
|
|
6793
|
+
reasoning_tokens: z4.z.number().optional(),
|
|
6794
|
+
request_count: z4.z.number().optional()
|
|
6795
|
+
}).transform(
|
|
6796
|
+
({
|
|
6797
|
+
credential_type,
|
|
6798
|
+
total_cost,
|
|
6799
|
+
market_cost,
|
|
6800
|
+
input_tokens,
|
|
6801
|
+
output_tokens,
|
|
6802
|
+
cached_input_tokens,
|
|
6803
|
+
cache_creation_input_tokens,
|
|
6804
|
+
reasoning_tokens,
|
|
6805
|
+
request_count,
|
|
6806
|
+
...rest
|
|
6807
|
+
}) => ({
|
|
6808
|
+
...rest,
|
|
6809
|
+
...credential_type !== void 0 ? { credentialType: credential_type } : {},
|
|
6810
|
+
totalCost: total_cost,
|
|
6811
|
+
...market_cost !== void 0 ? { marketCost: market_cost } : {},
|
|
6812
|
+
...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
|
|
6813
|
+
...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
|
|
6814
|
+
...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
|
|
6815
|
+
...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
|
|
6816
|
+
...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
|
|
6817
|
+
...request_count !== void 0 ? { requestCount: request_count } : {}
|
|
6818
|
+
})
|
|
6819
|
+
)
|
|
6820
|
+
)
|
|
6821
|
+
})
|
|
6822
|
+
)
|
|
6823
|
+
);
|
|
6824
|
+
var GatewayGenerationInfoFetcher = class {
|
|
6825
|
+
constructor(config) {
|
|
6826
|
+
this.config = config;
|
|
6827
|
+
}
|
|
6828
|
+
async getGenerationInfo(params) {
|
|
6829
|
+
try {
|
|
6830
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
6831
|
+
const { value } = await getFromApi({
|
|
6832
|
+
url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
|
|
6833
|
+
headers: await resolve(this.config.headers()),
|
|
6834
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
6835
|
+
gatewayGenerationInfoResponseSchema
|
|
6836
|
+
),
|
|
6837
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
6838
|
+
errorSchema: z4.z.any(),
|
|
6839
|
+
errorToMessage: (data) => data
|
|
6840
|
+
}),
|
|
6841
|
+
fetch: this.config.fetch
|
|
6842
|
+
});
|
|
6843
|
+
return value;
|
|
6844
|
+
} catch (error) {
|
|
6845
|
+
throw await asGatewayError(error);
|
|
6846
|
+
}
|
|
6847
|
+
}
|
|
6848
|
+
};
|
|
6849
|
+
var gatewayGenerationInfoResponseSchema = lazySchema(
|
|
6850
|
+
() => zodSchema2(
|
|
6851
|
+
z4.z.object({
|
|
6852
|
+
data: z4.z.object({
|
|
6853
|
+
id: z4.z.string(),
|
|
6854
|
+
total_cost: z4.z.number(),
|
|
6855
|
+
upstream_inference_cost: z4.z.number(),
|
|
6856
|
+
usage: z4.z.number(),
|
|
6857
|
+
created_at: z4.z.string(),
|
|
6858
|
+
model: z4.z.string(),
|
|
6859
|
+
is_byok: z4.z.boolean(),
|
|
6860
|
+
provider_name: z4.z.string(),
|
|
6861
|
+
streamed: z4.z.boolean(),
|
|
6862
|
+
finish_reason: z4.z.string(),
|
|
6863
|
+
latency: z4.z.number(),
|
|
6864
|
+
generation_time: z4.z.number(),
|
|
6865
|
+
native_tokens_prompt: z4.z.number(),
|
|
6866
|
+
native_tokens_completion: z4.z.number(),
|
|
6867
|
+
native_tokens_reasoning: z4.z.number(),
|
|
6868
|
+
native_tokens_cached: z4.z.number(),
|
|
6869
|
+
native_tokens_cache_creation: z4.z.number(),
|
|
6870
|
+
billable_web_search_calls: z4.z.number()
|
|
6871
|
+
}).transform(
|
|
6872
|
+
({
|
|
6873
|
+
total_cost,
|
|
6874
|
+
upstream_inference_cost,
|
|
6875
|
+
created_at,
|
|
6876
|
+
is_byok,
|
|
6877
|
+
provider_name,
|
|
6878
|
+
finish_reason,
|
|
6879
|
+
generation_time,
|
|
6880
|
+
native_tokens_prompt,
|
|
6881
|
+
native_tokens_completion,
|
|
6882
|
+
native_tokens_reasoning,
|
|
6883
|
+
native_tokens_cached,
|
|
6884
|
+
native_tokens_cache_creation,
|
|
6885
|
+
billable_web_search_calls,
|
|
6886
|
+
...rest
|
|
6887
|
+
}) => ({
|
|
6888
|
+
...rest,
|
|
6889
|
+
totalCost: total_cost,
|
|
6890
|
+
upstreamInferenceCost: upstream_inference_cost,
|
|
6891
|
+
createdAt: created_at,
|
|
6892
|
+
isByok: is_byok,
|
|
6893
|
+
providerName: provider_name,
|
|
6894
|
+
finishReason: finish_reason,
|
|
6895
|
+
generationTime: generation_time,
|
|
6896
|
+
promptTokens: native_tokens_prompt,
|
|
6897
|
+
completionTokens: native_tokens_completion,
|
|
6898
|
+
reasoningTokens: native_tokens_reasoning,
|
|
6899
|
+
cachedTokens: native_tokens_cached,
|
|
6900
|
+
cacheCreationTokens: native_tokens_cache_creation,
|
|
6901
|
+
billableWebSearchCalls: billable_web_search_calls
|
|
6902
|
+
})
|
|
6903
|
+
)
|
|
6904
|
+
}).transform(({ data }) => data)
|
|
6905
|
+
)
|
|
6906
|
+
);
|
|
6721
6907
|
var GatewayLanguageModel = class {
|
|
6722
6908
|
constructor(modelId, config) {
|
|
6723
6909
|
this.modelId = modelId;
|
|
@@ -7220,7 +7406,7 @@ async function getVercelRequestId() {
|
|
|
7220
7406
|
var _a932;
|
|
7221
7407
|
return (_a932 = getContext().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
7222
7408
|
}
|
|
7223
|
-
var VERSION3 = "2.0.
|
|
7409
|
+
var VERSION3 = "2.0.82";
|
|
7224
7410
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
7225
7411
|
function createGatewayProvider(options = {}) {
|
|
7226
7412
|
var _a932, _b93;
|
|
@@ -7318,6 +7504,30 @@ function createGatewayProvider(options = {}) {
|
|
|
7318
7504
|
);
|
|
7319
7505
|
});
|
|
7320
7506
|
};
|
|
7507
|
+
const getSpendReport = async (params) => {
|
|
7508
|
+
return new GatewaySpendReport({
|
|
7509
|
+
baseURL,
|
|
7510
|
+
headers: getHeaders,
|
|
7511
|
+
fetch: options.fetch
|
|
7512
|
+
}).getSpendReport(params).catch(async (error) => {
|
|
7513
|
+
throw await asGatewayError(
|
|
7514
|
+
error,
|
|
7515
|
+
await parseAuthMethod(await getHeaders())
|
|
7516
|
+
);
|
|
7517
|
+
});
|
|
7518
|
+
};
|
|
7519
|
+
const getGenerationInfo = async (params) => {
|
|
7520
|
+
return new GatewayGenerationInfoFetcher({
|
|
7521
|
+
baseURL,
|
|
7522
|
+
headers: getHeaders,
|
|
7523
|
+
fetch: options.fetch
|
|
7524
|
+
}).getGenerationInfo(params).catch(async (error) => {
|
|
7525
|
+
throw await asGatewayError(
|
|
7526
|
+
error,
|
|
7527
|
+
await parseAuthMethod(await getHeaders())
|
|
7528
|
+
);
|
|
7529
|
+
});
|
|
7530
|
+
};
|
|
7321
7531
|
const provider = function(modelId) {
|
|
7322
7532
|
if (new.target) {
|
|
7323
7533
|
throw new Error(
|
|
@@ -7328,6 +7538,8 @@ function createGatewayProvider(options = {}) {
|
|
|
7328
7538
|
};
|
|
7329
7539
|
provider.getAvailableModels = getAvailableModels;
|
|
7330
7540
|
provider.getCredits = getCredits;
|
|
7541
|
+
provider.getSpendReport = getSpendReport;
|
|
7542
|
+
provider.getGenerationInfo = getGenerationInfo;
|
|
7331
7543
|
provider.imageModel = (modelId) => {
|
|
7332
7544
|
return new GatewayImageModel(modelId, {
|
|
7333
7545
|
provider: "gateway",
|
|
@@ -8181,7 +8393,7 @@ function getGlobalProvider() {
|
|
|
8181
8393
|
var _a163;
|
|
8182
8394
|
return (_a163 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a163 : gateway;
|
|
8183
8395
|
}
|
|
8184
|
-
var VERSION32 = "5.0.
|
|
8396
|
+
var VERSION32 = "5.0.179";
|
|
8185
8397
|
var dataContentSchema2 = z4.z.union([
|
|
8186
8398
|
z4.z.string(),
|
|
8187
8399
|
z4.z.instanceof(Uint8Array),
|
|
@@ -9792,7 +10004,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
9792
10004
|
);
|
|
9793
10005
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
9794
10006
|
}
|
|
9795
|
-
var VERSION4 = "4.0.
|
|
10007
|
+
var VERSION4 = "4.0.23";
|
|
9796
10008
|
var getOriginalFetch3 = () => globalThis.fetch;
|
|
9797
10009
|
var getFromApi2 = async ({
|
|
9798
10010
|
url,
|
|
@@ -11877,6 +12089,13 @@ async function parseAuthMethod2(headers) {
|
|
|
11877
12089
|
var gatewayAuthMethodSchema2 = lazySchema2(
|
|
11878
12090
|
() => zodSchema3(z4.z.union([z4.z.literal("api-key"), z4.z.literal("oidc")]))
|
|
11879
12091
|
);
|
|
12092
|
+
var KNOWN_MODEL_TYPES2 = [
|
|
12093
|
+
"embedding",
|
|
12094
|
+
"image",
|
|
12095
|
+
"language",
|
|
12096
|
+
"reranking",
|
|
12097
|
+
"video"
|
|
12098
|
+
];
|
|
11880
12099
|
var GatewayFetchMetadata2 = class {
|
|
11881
12100
|
constructor(config) {
|
|
11882
12101
|
this.config = config;
|
|
@@ -11947,8 +12166,12 @@ var gatewayAvailableModelsResponseSchema2 = lazySchema2(
|
|
|
11947
12166
|
provider: z4.z.string(),
|
|
11948
12167
|
modelId: z4.z.string()
|
|
11949
12168
|
}),
|
|
11950
|
-
modelType: z4.z.
|
|
12169
|
+
modelType: z4.z.string().nullish()
|
|
11951
12170
|
})
|
|
12171
|
+
).transform(
|
|
12172
|
+
(models) => models.filter(
|
|
12173
|
+
(m) => m.modelType == null || KNOWN_MODEL_TYPES2.includes(m.modelType)
|
|
12174
|
+
)
|
|
11952
12175
|
)
|
|
11953
12176
|
})
|
|
11954
12177
|
)
|
|
@@ -11964,6 +12187,187 @@ var gatewayCreditsResponseSchema2 = lazySchema2(
|
|
|
11964
12187
|
}))
|
|
11965
12188
|
)
|
|
11966
12189
|
);
|
|
12190
|
+
var GatewaySpendReport2 = class {
|
|
12191
|
+
constructor(config) {
|
|
12192
|
+
this.config = config;
|
|
12193
|
+
}
|
|
12194
|
+
async getSpendReport(params) {
|
|
12195
|
+
try {
|
|
12196
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
12197
|
+
const searchParams = new URLSearchParams();
|
|
12198
|
+
searchParams.set("start_date", params.startDate);
|
|
12199
|
+
searchParams.set("end_date", params.endDate);
|
|
12200
|
+
if (params.groupBy) {
|
|
12201
|
+
searchParams.set("group_by", params.groupBy);
|
|
12202
|
+
}
|
|
12203
|
+
if (params.datePart) {
|
|
12204
|
+
searchParams.set("date_part", params.datePart);
|
|
12205
|
+
}
|
|
12206
|
+
if (params.userId) {
|
|
12207
|
+
searchParams.set("user_id", params.userId);
|
|
12208
|
+
}
|
|
12209
|
+
if (params.model) {
|
|
12210
|
+
searchParams.set("model", params.model);
|
|
12211
|
+
}
|
|
12212
|
+
if (params.provider) {
|
|
12213
|
+
searchParams.set("provider", params.provider);
|
|
12214
|
+
}
|
|
12215
|
+
if (params.credentialType) {
|
|
12216
|
+
searchParams.set("credential_type", params.credentialType);
|
|
12217
|
+
}
|
|
12218
|
+
if (params.tags && params.tags.length > 0) {
|
|
12219
|
+
searchParams.set("tags", params.tags.join(","));
|
|
12220
|
+
}
|
|
12221
|
+
const { value } = await getFromApi2({
|
|
12222
|
+
url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
|
|
12223
|
+
headers: await resolve2(this.config.headers()),
|
|
12224
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
12225
|
+
gatewaySpendReportResponseSchema2
|
|
12226
|
+
),
|
|
12227
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
12228
|
+
errorSchema: z4.z.any(),
|
|
12229
|
+
errorToMessage: (data) => data
|
|
12230
|
+
}),
|
|
12231
|
+
fetch: this.config.fetch
|
|
12232
|
+
});
|
|
12233
|
+
return value;
|
|
12234
|
+
} catch (error) {
|
|
12235
|
+
throw await asGatewayError2(error);
|
|
12236
|
+
}
|
|
12237
|
+
}
|
|
12238
|
+
};
|
|
12239
|
+
var gatewaySpendReportResponseSchema2 = lazySchema2(
|
|
12240
|
+
() => zodSchema3(
|
|
12241
|
+
z4.z.object({
|
|
12242
|
+
results: z4.z.array(
|
|
12243
|
+
z4.z.object({
|
|
12244
|
+
day: z4.z.string().optional(),
|
|
12245
|
+
hour: z4.z.string().optional(),
|
|
12246
|
+
user: z4.z.string().optional(),
|
|
12247
|
+
model: z4.z.string().optional(),
|
|
12248
|
+
tag: z4.z.string().optional(),
|
|
12249
|
+
provider: z4.z.string().optional(),
|
|
12250
|
+
credential_type: z4.z.enum(["byok", "system"]).optional(),
|
|
12251
|
+
total_cost: z4.z.number(),
|
|
12252
|
+
market_cost: z4.z.number().optional(),
|
|
12253
|
+
input_tokens: z4.z.number().optional(),
|
|
12254
|
+
output_tokens: z4.z.number().optional(),
|
|
12255
|
+
cached_input_tokens: z4.z.number().optional(),
|
|
12256
|
+
cache_creation_input_tokens: z4.z.number().optional(),
|
|
12257
|
+
reasoning_tokens: z4.z.number().optional(),
|
|
12258
|
+
request_count: z4.z.number().optional()
|
|
12259
|
+
}).transform(
|
|
12260
|
+
({
|
|
12261
|
+
credential_type,
|
|
12262
|
+
total_cost,
|
|
12263
|
+
market_cost,
|
|
12264
|
+
input_tokens,
|
|
12265
|
+
output_tokens,
|
|
12266
|
+
cached_input_tokens,
|
|
12267
|
+
cache_creation_input_tokens,
|
|
12268
|
+
reasoning_tokens,
|
|
12269
|
+
request_count,
|
|
12270
|
+
...rest
|
|
12271
|
+
}) => ({
|
|
12272
|
+
...rest,
|
|
12273
|
+
...credential_type !== void 0 ? { credentialType: credential_type } : {},
|
|
12274
|
+
totalCost: total_cost,
|
|
12275
|
+
...market_cost !== void 0 ? { marketCost: market_cost } : {},
|
|
12276
|
+
...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
|
|
12277
|
+
...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
|
|
12278
|
+
...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
|
|
12279
|
+
...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
|
|
12280
|
+
...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
|
|
12281
|
+
...request_count !== void 0 ? { requestCount: request_count } : {}
|
|
12282
|
+
})
|
|
12283
|
+
)
|
|
12284
|
+
)
|
|
12285
|
+
})
|
|
12286
|
+
)
|
|
12287
|
+
);
|
|
12288
|
+
var GatewayGenerationInfoFetcher2 = class {
|
|
12289
|
+
constructor(config) {
|
|
12290
|
+
this.config = config;
|
|
12291
|
+
}
|
|
12292
|
+
async getGenerationInfo(params) {
|
|
12293
|
+
try {
|
|
12294
|
+
const baseUrl = new URL(this.config.baseURL);
|
|
12295
|
+
const { value } = await getFromApi2({
|
|
12296
|
+
url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
|
|
12297
|
+
headers: await resolve2(this.config.headers()),
|
|
12298
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
12299
|
+
gatewayGenerationInfoResponseSchema2
|
|
12300
|
+
),
|
|
12301
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
12302
|
+
errorSchema: z4.z.any(),
|
|
12303
|
+
errorToMessage: (data) => data
|
|
12304
|
+
}),
|
|
12305
|
+
fetch: this.config.fetch
|
|
12306
|
+
});
|
|
12307
|
+
return value;
|
|
12308
|
+
} catch (error) {
|
|
12309
|
+
throw await asGatewayError2(error);
|
|
12310
|
+
}
|
|
12311
|
+
}
|
|
12312
|
+
};
|
|
12313
|
+
var gatewayGenerationInfoResponseSchema2 = lazySchema2(
|
|
12314
|
+
() => zodSchema3(
|
|
12315
|
+
z4.z.object({
|
|
12316
|
+
data: z4.z.object({
|
|
12317
|
+
id: z4.z.string(),
|
|
12318
|
+
total_cost: z4.z.number(),
|
|
12319
|
+
upstream_inference_cost: z4.z.number(),
|
|
12320
|
+
usage: z4.z.number(),
|
|
12321
|
+
created_at: z4.z.string(),
|
|
12322
|
+
model: z4.z.string(),
|
|
12323
|
+
is_byok: z4.z.boolean(),
|
|
12324
|
+
provider_name: z4.z.string(),
|
|
12325
|
+
streamed: z4.z.boolean(),
|
|
12326
|
+
finish_reason: z4.z.string(),
|
|
12327
|
+
latency: z4.z.number(),
|
|
12328
|
+
generation_time: z4.z.number(),
|
|
12329
|
+
native_tokens_prompt: z4.z.number(),
|
|
12330
|
+
native_tokens_completion: z4.z.number(),
|
|
12331
|
+
native_tokens_reasoning: z4.z.number(),
|
|
12332
|
+
native_tokens_cached: z4.z.number(),
|
|
12333
|
+
native_tokens_cache_creation: z4.z.number(),
|
|
12334
|
+
billable_web_search_calls: z4.z.number()
|
|
12335
|
+
}).transform(
|
|
12336
|
+
({
|
|
12337
|
+
total_cost,
|
|
12338
|
+
upstream_inference_cost,
|
|
12339
|
+
created_at,
|
|
12340
|
+
is_byok,
|
|
12341
|
+
provider_name,
|
|
12342
|
+
finish_reason,
|
|
12343
|
+
generation_time,
|
|
12344
|
+
native_tokens_prompt,
|
|
12345
|
+
native_tokens_completion,
|
|
12346
|
+
native_tokens_reasoning,
|
|
12347
|
+
native_tokens_cached,
|
|
12348
|
+
native_tokens_cache_creation,
|
|
12349
|
+
billable_web_search_calls,
|
|
12350
|
+
...rest
|
|
12351
|
+
}) => ({
|
|
12352
|
+
...rest,
|
|
12353
|
+
totalCost: total_cost,
|
|
12354
|
+
upstreamInferenceCost: upstream_inference_cost,
|
|
12355
|
+
createdAt: created_at,
|
|
12356
|
+
isByok: is_byok,
|
|
12357
|
+
providerName: provider_name,
|
|
12358
|
+
finishReason: finish_reason,
|
|
12359
|
+
generationTime: generation_time,
|
|
12360
|
+
promptTokens: native_tokens_prompt,
|
|
12361
|
+
completionTokens: native_tokens_completion,
|
|
12362
|
+
reasoningTokens: native_tokens_reasoning,
|
|
12363
|
+
cachedTokens: native_tokens_cached,
|
|
12364
|
+
cacheCreationTokens: native_tokens_cache_creation,
|
|
12365
|
+
billableWebSearchCalls: billable_web_search_calls
|
|
12366
|
+
})
|
|
12367
|
+
)
|
|
12368
|
+
}).transform(({ data }) => data)
|
|
12369
|
+
)
|
|
12370
|
+
);
|
|
11967
12371
|
var GatewayLanguageModel2 = class {
|
|
11968
12372
|
constructor(modelId, config) {
|
|
11969
12373
|
this.modelId = modelId;
|
|
@@ -12511,6 +12915,86 @@ var gatewayVideoEventSchema = z4.z.discriminatedUnion("type", [
|
|
|
12511
12915
|
param: z4.z.unknown().nullable()
|
|
12512
12916
|
})
|
|
12513
12917
|
]);
|
|
12918
|
+
var GatewayRerankingModel = class {
|
|
12919
|
+
constructor(modelId, config) {
|
|
12920
|
+
this.modelId = modelId;
|
|
12921
|
+
this.config = config;
|
|
12922
|
+
this.specificationVersion = "v3";
|
|
12923
|
+
}
|
|
12924
|
+
get provider() {
|
|
12925
|
+
return this.config.provider;
|
|
12926
|
+
}
|
|
12927
|
+
async doRerank({
|
|
12928
|
+
documents,
|
|
12929
|
+
query,
|
|
12930
|
+
topN,
|
|
12931
|
+
headers,
|
|
12932
|
+
abortSignal,
|
|
12933
|
+
providerOptions
|
|
12934
|
+
}) {
|
|
12935
|
+
const resolvedHeaders = await resolve2(this.config.headers());
|
|
12936
|
+
try {
|
|
12937
|
+
const {
|
|
12938
|
+
responseHeaders,
|
|
12939
|
+
value: responseBody,
|
|
12940
|
+
rawValue
|
|
12941
|
+
} = await postJsonToApi2({
|
|
12942
|
+
url: this.getUrl(),
|
|
12943
|
+
headers: combineHeaders2(
|
|
12944
|
+
resolvedHeaders,
|
|
12945
|
+
headers != null ? headers : {},
|
|
12946
|
+
this.getModelConfigHeaders(),
|
|
12947
|
+
await resolve2(this.config.o11yHeaders)
|
|
12948
|
+
),
|
|
12949
|
+
body: {
|
|
12950
|
+
documents,
|
|
12951
|
+
query,
|
|
12952
|
+
...topN != null ? { topN } : {},
|
|
12953
|
+
...providerOptions ? { providerOptions } : {}
|
|
12954
|
+
},
|
|
12955
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
12956
|
+
gatewayRerankingResponseSchema
|
|
12957
|
+
),
|
|
12958
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
12959
|
+
errorSchema: z4.z.any(),
|
|
12960
|
+
errorToMessage: (data) => data
|
|
12961
|
+
}),
|
|
12962
|
+
...abortSignal && { abortSignal },
|
|
12963
|
+
fetch: this.config.fetch
|
|
12964
|
+
});
|
|
12965
|
+
return {
|
|
12966
|
+
ranking: responseBody.ranking,
|
|
12967
|
+
providerMetadata: responseBody.providerMetadata,
|
|
12968
|
+
response: { headers: responseHeaders, body: rawValue },
|
|
12969
|
+
warnings: []
|
|
12970
|
+
};
|
|
12971
|
+
} catch (error) {
|
|
12972
|
+
throw await asGatewayError2(error, await parseAuthMethod2(resolvedHeaders));
|
|
12973
|
+
}
|
|
12974
|
+
}
|
|
12975
|
+
getUrl() {
|
|
12976
|
+
return `${this.config.baseURL}/reranking-model`;
|
|
12977
|
+
}
|
|
12978
|
+
getModelConfigHeaders() {
|
|
12979
|
+
return {
|
|
12980
|
+
"ai-reranking-model-specification-version": "3",
|
|
12981
|
+
"ai-model-id": this.modelId
|
|
12982
|
+
};
|
|
12983
|
+
}
|
|
12984
|
+
};
|
|
12985
|
+
var gatewayRerankingResponseSchema = lazySchema2(
|
|
12986
|
+
() => zodSchema3(
|
|
12987
|
+
z4.z.object({
|
|
12988
|
+
ranking: z4.z.array(
|
|
12989
|
+
z4.z.object({
|
|
12990
|
+
index: z4.z.number(),
|
|
12991
|
+
relevanceScore: z4.z.number()
|
|
12992
|
+
})
|
|
12993
|
+
),
|
|
12994
|
+
providerMetadata: z4.z.record(z4.z.string(), z4.z.record(z4.z.string(), z4.z.unknown())).optional()
|
|
12995
|
+
})
|
|
12996
|
+
)
|
|
12997
|
+
);
|
|
12514
12998
|
var parallelSearchInputSchema2 = lazySchema2(
|
|
12515
12999
|
() => zodSchema3(
|
|
12516
13000
|
zod.z.object({
|
|
@@ -12687,7 +13171,7 @@ async function getVercelRequestId2() {
|
|
|
12687
13171
|
var _a932;
|
|
12688
13172
|
return (_a932 = getContext2().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
12689
13173
|
}
|
|
12690
|
-
var VERSION5 = "3.0.
|
|
13174
|
+
var VERSION5 = "3.0.104";
|
|
12691
13175
|
var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
|
|
12692
13176
|
function createGatewayProvider2(options = {}) {
|
|
12693
13177
|
var _a932, _b93;
|
|
@@ -12787,6 +13271,30 @@ function createGatewayProvider2(options = {}) {
|
|
|
12787
13271
|
);
|
|
12788
13272
|
});
|
|
12789
13273
|
};
|
|
13274
|
+
const getSpendReport = async (params) => {
|
|
13275
|
+
return new GatewaySpendReport2({
|
|
13276
|
+
baseURL,
|
|
13277
|
+
headers: getHeaders,
|
|
13278
|
+
fetch: options.fetch
|
|
13279
|
+
}).getSpendReport(params).catch(async (error) => {
|
|
13280
|
+
throw await asGatewayError2(
|
|
13281
|
+
error,
|
|
13282
|
+
await parseAuthMethod2(await getHeaders())
|
|
13283
|
+
);
|
|
13284
|
+
});
|
|
13285
|
+
};
|
|
13286
|
+
const getGenerationInfo = async (params) => {
|
|
13287
|
+
return new GatewayGenerationInfoFetcher2({
|
|
13288
|
+
baseURL,
|
|
13289
|
+
headers: getHeaders,
|
|
13290
|
+
fetch: options.fetch
|
|
13291
|
+
}).getGenerationInfo(params).catch(async (error) => {
|
|
13292
|
+
throw await asGatewayError2(
|
|
13293
|
+
error,
|
|
13294
|
+
await parseAuthMethod2(await getHeaders())
|
|
13295
|
+
);
|
|
13296
|
+
});
|
|
13297
|
+
};
|
|
12790
13298
|
const provider = function(modelId) {
|
|
12791
13299
|
if (new.target) {
|
|
12792
13300
|
throw new Error(
|
|
@@ -12798,6 +13306,8 @@ function createGatewayProvider2(options = {}) {
|
|
|
12798
13306
|
provider.specificationVersion = "v3";
|
|
12799
13307
|
provider.getAvailableModels = getAvailableModels;
|
|
12800
13308
|
provider.getCredits = getCredits;
|
|
13309
|
+
provider.getSpendReport = getSpendReport;
|
|
13310
|
+
provider.getGenerationInfo = getGenerationInfo;
|
|
12801
13311
|
provider.imageModel = (modelId) => {
|
|
12802
13312
|
return new GatewayImageModel2(modelId, {
|
|
12803
13313
|
provider: "gateway",
|
|
@@ -12828,6 +13338,17 @@ function createGatewayProvider2(options = {}) {
|
|
|
12828
13338
|
o11yHeaders: createO11yHeaders()
|
|
12829
13339
|
});
|
|
12830
13340
|
};
|
|
13341
|
+
const createRerankingModel = (modelId) => {
|
|
13342
|
+
return new GatewayRerankingModel(modelId, {
|
|
13343
|
+
provider: "gateway",
|
|
13344
|
+
baseURL,
|
|
13345
|
+
headers: getHeaders,
|
|
13346
|
+
fetch: options.fetch,
|
|
13347
|
+
o11yHeaders: createO11yHeaders()
|
|
13348
|
+
});
|
|
13349
|
+
};
|
|
13350
|
+
provider.rerankingModel = createRerankingModel;
|
|
13351
|
+
provider.reranking = createRerankingModel;
|
|
12831
13352
|
provider.chat = provider.languageModel;
|
|
12832
13353
|
provider.embedding = provider.embeddingModel;
|
|
12833
13354
|
provider.image = provider.imageModel;
|
|
@@ -13760,7 +14281,7 @@ function getTotalTimeoutMs(timeout) {
|
|
|
13760
14281
|
}
|
|
13761
14282
|
return timeout.totalMs;
|
|
13762
14283
|
}
|
|
13763
|
-
var VERSION33 = "6.0.
|
|
14284
|
+
var VERSION33 = "6.0.168";
|
|
13764
14285
|
var dataContentSchema3 = z4.z.union([
|
|
13765
14286
|
z4.z.string(),
|
|
13766
14287
|
z4.z.instanceof(Uint8Array),
|
|
@@ -16462,6 +16983,69 @@ var __experimental_updateWorkingMemoryToolVNext = (config) => {
|
|
|
16462
16983
|
}
|
|
16463
16984
|
});
|
|
16464
16985
|
};
|
|
16986
|
+
var WORKING_MEMORY_START_TAG = "<working_memory>";
|
|
16987
|
+
var WORKING_MEMORY_END_TAG = "</working_memory>";
|
|
16988
|
+
var LEGACY_SYSTEM_REMINDER_METADATA_KEY = "dynamicAgentsMdReminder";
|
|
16989
|
+
function isRecord(value) {
|
|
16990
|
+
return typeof value === "object" && value !== null;
|
|
16991
|
+
}
|
|
16992
|
+
function extractWorkingMemoryTags(text4) {
|
|
16993
|
+
const results = [];
|
|
16994
|
+
let pos = 0;
|
|
16995
|
+
while (pos < text4.length) {
|
|
16996
|
+
const start = text4.indexOf(WORKING_MEMORY_START_TAG, pos);
|
|
16997
|
+
if (start === -1) break;
|
|
16998
|
+
const end = text4.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
|
|
16999
|
+
if (end === -1) break;
|
|
17000
|
+
results.push(text4.substring(start, end + WORKING_MEMORY_END_TAG.length));
|
|
17001
|
+
pos = end + WORKING_MEMORY_END_TAG.length;
|
|
17002
|
+
}
|
|
17003
|
+
return results.length > 0 ? results : null;
|
|
17004
|
+
}
|
|
17005
|
+
function removeWorkingMemoryTags(text4) {
|
|
17006
|
+
let result = "";
|
|
17007
|
+
let pos = 0;
|
|
17008
|
+
while (pos < text4.length) {
|
|
17009
|
+
const start = text4.indexOf(WORKING_MEMORY_START_TAG, pos);
|
|
17010
|
+
if (start === -1) {
|
|
17011
|
+
result += text4.substring(pos);
|
|
17012
|
+
break;
|
|
17013
|
+
}
|
|
17014
|
+
result += text4.substring(pos, start);
|
|
17015
|
+
const end = text4.indexOf(WORKING_MEMORY_END_TAG, start + WORKING_MEMORY_START_TAG.length);
|
|
17016
|
+
if (end === -1) {
|
|
17017
|
+
result += text4.substring(start);
|
|
17018
|
+
break;
|
|
17019
|
+
}
|
|
17020
|
+
pos = end + WORKING_MEMORY_END_TAG.length;
|
|
17021
|
+
}
|
|
17022
|
+
return result;
|
|
17023
|
+
}
|
|
17024
|
+
function extractWorkingMemoryContent(text4) {
|
|
17025
|
+
const start = text4.indexOf(WORKING_MEMORY_START_TAG);
|
|
17026
|
+
if (start === -1) return null;
|
|
17027
|
+
const contentStart = start + WORKING_MEMORY_START_TAG.length;
|
|
17028
|
+
const end = text4.indexOf(WORKING_MEMORY_END_TAG, contentStart);
|
|
17029
|
+
if (end === -1) return null;
|
|
17030
|
+
return text4.substring(contentStart, end);
|
|
17031
|
+
}
|
|
17032
|
+
function isSystemReminderMessage(message) {
|
|
17033
|
+
if (message.role !== "user" || !isRecord(message.content)) {
|
|
17034
|
+
return false;
|
|
17035
|
+
}
|
|
17036
|
+
const metadata = message.content.metadata;
|
|
17037
|
+
if (isRecord(metadata) && (isRecord(metadata.systemReminder) || LEGACY_SYSTEM_REMINDER_METADATA_KEY in metadata)) {
|
|
17038
|
+
return true;
|
|
17039
|
+
}
|
|
17040
|
+
const firstTextPart = message.content.parts.find((part) => part.type === "text");
|
|
17041
|
+
return typeof firstTextPart?.text === "string" && firstTextPart.text.startsWith("<system-reminder");
|
|
17042
|
+
}
|
|
17043
|
+
function filterSystemReminderMessages(messages, includeSystemReminders) {
|
|
17044
|
+
if (includeSystemReminders) {
|
|
17045
|
+
return messages;
|
|
17046
|
+
}
|
|
17047
|
+
return messages.filter((message) => !isSystemReminderMessage(message));
|
|
17048
|
+
}
|
|
16465
17049
|
function normalizeObservationalMemoryConfig(config) {
|
|
16466
17050
|
if (config === true) return { model: "google/gemini-2.5-flash" };
|
|
16467
17051
|
if (config === false || config === void 0) return void 0;
|
|
@@ -16661,7 +17245,7 @@ var Memory = class extends memory.MastraMemory {
|
|
|
16661
17245
|
});
|
|
16662
17246
|
const rawMessages = shouldGetNewestAndReverse ? paginatedResult.messages.reverse() : paginatedResult.messages;
|
|
16663
17247
|
const list = new agent.MessageList({ threadId, resourceId }).add(rawMessages, "memory");
|
|
16664
|
-
const messages =
|
|
17248
|
+
const messages = filterSystemReminderMessages(list.get.all.db(), includeSystemReminders);
|
|
16665
17249
|
const { total, page: resultPage, perPage: resultPerPage, hasMore } = paginatedResult;
|
|
16666
17250
|
const recallResult = { messages, usage, total, page: resultPage, perPage: resultPerPage, hasMore };
|
|
16667
17251
|
span?.end({
|
|
@@ -17103,7 +17687,7 @@ ${workingMemory}`;
|
|
|
17103
17687
|
newMessage.content = { ...message.content };
|
|
17104
17688
|
}
|
|
17105
17689
|
if (typeof newMessage.content?.content === "string" && newMessage.content.content.length > 0) {
|
|
17106
|
-
newMessage.content.content =
|
|
17690
|
+
newMessage.content.content = removeWorkingMemoryTags(newMessage.content.content).trim();
|
|
17107
17691
|
}
|
|
17108
17692
|
if (Array.isArray(newMessage.content?.parts)) {
|
|
17109
17693
|
newMessage.content.parts = newMessage.content.parts.filter((part) => {
|
|
@@ -17116,7 +17700,7 @@ ${workingMemory}`;
|
|
|
17116
17700
|
const text4 = typeof part.text === "string" ? part.text : "";
|
|
17117
17701
|
return {
|
|
17118
17702
|
...part,
|
|
17119
|
-
text:
|
|
17703
|
+
text: removeWorkingMemoryTags(text4).trim()
|
|
17120
17704
|
};
|
|
17121
17705
|
}
|
|
17122
17706
|
return part;
|
|
@@ -17132,7 +17716,7 @@ ${workingMemory}`;
|
|
|
17132
17716
|
}
|
|
17133
17717
|
parseWorkingMemory(text4) {
|
|
17134
17718
|
if (!this.threadConfig.workingMemory?.enabled) return null;
|
|
17135
|
-
const content =
|
|
17719
|
+
const content = extractWorkingMemoryContent(text4);
|
|
17136
17720
|
return content?.trim() ?? null;
|
|
17137
17721
|
}
|
|
17138
17722
|
async getWorkingMemory({
|
|
@@ -18307,18 +18891,6 @@ Object.defineProperty(exports, "getObservationsAsOf", {
|
|
|
18307
18891
|
enumerable: true,
|
|
18308
18892
|
get: function () { return chunkJ2XQSPAB_cjs.getObservationsAsOf; }
|
|
18309
18893
|
});
|
|
18310
|
-
Object.defineProperty(exports, "extractWorkingMemoryContent", {
|
|
18311
|
-
enumerable: true,
|
|
18312
|
-
get: function () { return memory.extractWorkingMemoryContent; }
|
|
18313
|
-
});
|
|
18314
|
-
Object.defineProperty(exports, "extractWorkingMemoryTags", {
|
|
18315
|
-
enumerable: true,
|
|
18316
|
-
get: function () { return memory.extractWorkingMemoryTags; }
|
|
18317
|
-
});
|
|
18318
|
-
Object.defineProperty(exports, "removeWorkingMemoryTags", {
|
|
18319
|
-
enumerable: true,
|
|
18320
|
-
get: function () { return memory.removeWorkingMemoryTags; }
|
|
18321
|
-
});
|
|
18322
18894
|
Object.defineProperty(exports, "MessageHistory", {
|
|
18323
18895
|
enumerable: true,
|
|
18324
18896
|
get: function () { return processors.MessageHistory; }
|
|
@@ -18333,5 +18905,8 @@ Object.defineProperty(exports, "WorkingMemory", {
|
|
|
18333
18905
|
});
|
|
18334
18906
|
exports.Memory = Memory;
|
|
18335
18907
|
exports.deepMergeWorkingMemory = deepMergeWorkingMemory;
|
|
18908
|
+
exports.extractWorkingMemoryContent = extractWorkingMemoryContent;
|
|
18909
|
+
exports.extractWorkingMemoryTags = extractWorkingMemoryTags;
|
|
18910
|
+
exports.removeWorkingMemoryTags = removeWorkingMemoryTags;
|
|
18336
18911
|
//# sourceMappingURL=index.cjs.map
|
|
18337
18912
|
//# sourceMappingURL=index.cjs.map
|