@mastra/memory 1.4.0-alpha.0 → 1.4.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 +63 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +288 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +288 -57
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
1
|
# @mastra/memory
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Update peer dependencies to match core package version bump (1.5.0) ([#13245](https://github.com/mastra-ai/mastra/pull/13245))
|
|
8
|
+
|
|
9
|
+
- Update peer dependencies to match core package version bump (1.4.1) ([#13151](https://github.com/mastra-ai/mastra/pull/13151))
|
|
10
|
+
|
|
11
|
+
- Update peer dependencies to match core package version bump (1.4.1) ([#13245](https://github.com/mastra-ai/mastra/pull/13245))
|
|
12
|
+
|
|
13
|
+
- Add `instruction` property to observational memory configs ([#13240](https://github.com/mastra-ai/mastra/pull/13240))
|
|
14
|
+
|
|
15
|
+
Adds optional `instruction` field to `ObservationConfig` and `ReflectionConfig` that allows users to extend the built-in observer/reflector system prompts with custom guidance.
|
|
16
|
+
|
|
17
|
+
Example:
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
const memory = new ObservationalMemory({
|
|
21
|
+
model: openai('gpt-4'),
|
|
22
|
+
observation: {
|
|
23
|
+
instruction: 'Focus on user preferences about food and dietary restrictions.',
|
|
24
|
+
},
|
|
25
|
+
reflection: {
|
|
26
|
+
instruction: 'Prioritize consolidating health-related observations together.',
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- dependencies updates: ([#13167](https://github.com/mastra-ai/mastra/pull/13167))
|
|
34
|
+
- Updated dependency [`lru-cache@^11.2.6` ↗︎](https://www.npmjs.com/package/lru-cache/v/11.2.6) (from `^11.2.2`, in `dependencies`)
|
|
35
|
+
|
|
36
|
+
- Added generic Harness class to @mastra/core for orchestrating agents with modes, state management, built-in tools (ask_user, submit_plan), subagent support, Observational Memory integration, model discovery, and permission-aware tool approval. The Harness provides a reusable foundation for building agent-powered applications with features like thread management, heartbeat monitoring, and event-driven architecture. ([#13245](https://github.com/mastra-ai/mastra/pull/13245))
|
|
37
|
+
|
|
38
|
+
- - Reflection retry logic now attempts compression up to level 3, so reflections more consistently shrink to meet token limits ([#13170](https://github.com/mastra-ai/mastra/pull/13170))
|
|
39
|
+
- Default target compression reduced from 50% to 25% (`sliceTokenEstimate * 0.75`), making automatic trimming less aggressive
|
|
40
|
+
- `tokensBuffered` marker now reports the actual slice size rather than total observation tokens, giving accurate size monitoring
|
|
41
|
+
|
|
42
|
+
These changes reduce failed reflections and make reported metrics match what is actually being processed.
|
|
43
|
+
|
|
44
|
+
- Fixed a bug where the OM context window would jump to extremely high token counts (e.g. 16k → 114k) after observation activation. Two issues were causing this: ([#13070](https://github.com/mastra-ai/mastra/pull/13070))
|
|
45
|
+
- **Token counter included OM metadata parts**: `data-om-activation` marker parts (which contain the full observation text, up to 150k+ characters) were being counted as message tokens when loaded from the database. These parts are never sent to the LLM and are now skipped during token counting.
|
|
46
|
+
- **Marker duplication on messages**: Activation markers were being added to assistant messages twice — once by the AI SDK stream and once by the persistence layer — doubling every marker and compounding the token inflation. Both `persistMarkerToMessage` and `persistMarkerToStorage` now deduplicate by `type + cycleId` before adding a marker.
|
|
47
|
+
|
|
48
|
+
- Fixed thread title not being generated for pre-created threads. When threads were created before starting a conversation (e.g., for URL routing or storing metadata), the title stayed as a placeholder because the title generation condition checked whether the thread existed rather than whether it had a title. Threads created without an explicit title now get an empty title instead of a placeholder, and title generation fires whenever a thread has no title. Resolves #13145. ([#13151](https://github.com/mastra-ai/mastra/pull/13151))
|
|
49
|
+
|
|
50
|
+
- Migrated MastraCode from the prototype harness to the generic CoreHarness from @mastra/core. The createMastraCode function is now fully configurable with optional parameters for modes, subagents, storage, tools, and more. Removed the deprecated prototype harness implementation. ([#13245](https://github.com/mastra-ai/mastra/pull/13245))
|
|
51
|
+
|
|
52
|
+
- Fixed sub-agent memory context pollution that caused 'Exhausted all fallback models' errors when using Observational Memory with sub-agents. The parent agent's memory context is now preserved across sub-agent tool execution. ([#13051](https://github.com/mastra-ai/mastra/pull/13051))
|
|
53
|
+
|
|
54
|
+
- Updated dependencies [[`252580a`](https://github.com/mastra-ai/mastra/commit/252580a71feb0e46d0ccab04a70a79ff6a2ee0ab), [`f8e819f`](https://github.com/mastra-ai/mastra/commit/f8e819fabdfdc43d2da546a3ad81ba23685f603d), [`5c75261`](https://github.com/mastra-ai/mastra/commit/5c7526120d936757d4ffb7b82232e1641ebd45cb), [`e27d832`](https://github.com/mastra-ai/mastra/commit/e27d83281b5e166fd63a13969689e928d8605944), [`e37ef84`](https://github.com/mastra-ai/mastra/commit/e37ef8404043c94ca0c8e35ecdedb093b8087878), [`6fdd3d4`](https://github.com/mastra-ai/mastra/commit/6fdd3d451a07a8e7e216c62ac364f8dd8e36c2af), [`10cf521`](https://github.com/mastra-ai/mastra/commit/10cf52183344743a0d7babe24cd24fd78870c354), [`efdb682`](https://github.com/mastra-ai/mastra/commit/efdb682887f6522149769383908f9790c188ab88), [`0dee7a0`](https://github.com/mastra-ai/mastra/commit/0dee7a0ff4c2507e6eb6e6ee5f9738877ebd4ad1), [`04c2c8e`](https://github.com/mastra-ai/mastra/commit/04c2c8e888984364194131aecb490a3d6e920e61), [`02dc07a`](https://github.com/mastra-ai/mastra/commit/02dc07acc4ad42d93335825e3308f5b42266eba2), [`bb7262b`](https://github.com/mastra-ai/mastra/commit/bb7262b7c0ca76320d985b40510b6ffbbb936582), [`1415bcd`](https://github.com/mastra-ai/mastra/commit/1415bcd894baba03e07640b3b1986037db49559d), [`cf1c6e7`](https://github.com/mastra-ai/mastra/commit/cf1c6e789b131f55638fed52183a89d5078b4876), [`5ffadfe`](https://github.com/mastra-ai/mastra/commit/5ffadfefb1468ac2612b20bb84d24c39de6961c0), [`1e1339c`](https://github.com/mastra-ai/mastra/commit/1e1339cc276e571a48cfff5014487877086bfe68), [`d03df73`](https://github.com/mastra-ai/mastra/commit/d03df73f8fe9496064a33e1c3b74ba0479bf9ee6), [`79b8f45`](https://github.com/mastra-ai/mastra/commit/79b8f45a6767e1a5c3d56cd3c5b1214326b81661), [`9bbf08e`](https://github.com/mastra-ai/mastra/commit/9bbf08e3c20731c79dea13a765895b9fcf29cbf1), [`0a25952`](https://github.com/mastra-ai/mastra/commit/0a259526b5e1ac11e6efa53db1f140272962af2d), [`ffa5468`](https://github.com/mastra-ai/mastra/commit/ffa546857fc4821753979b3a34e13b4d76fbbcd4), [`3264a04`](https://github.com/mastra-ai/mastra/commit/3264a04e30340c3c5447433300a035ea0878df85), [`6fdd3d4`](https://github.com/mastra-ai/mastra/commit/6fdd3d451a07a8e7e216c62ac364f8dd8e36c2af), [`088d9ba`](https://github.com/mastra-ai/mastra/commit/088d9ba2577518703c52b0dccd617178d9ee6b0d), [`74fbebd`](https://github.com/mastra-ai/mastra/commit/74fbebd918a03832a2864965a8bea59bf617d3a2), [`aea6217`](https://github.com/mastra-ai/mastra/commit/aea621790bfb2291431b08da0cc5e6e150303ae7), [`b6a855e`](https://github.com/mastra-ai/mastra/commit/b6a855edc056e088279075506442ba1d6fa6def9), [`ae408ea`](https://github.com/mastra-ai/mastra/commit/ae408ea7128f0d2710b78d8623185198e7cb19c1), [`17e942e`](https://github.com/mastra-ai/mastra/commit/17e942eee2ba44985b1f807e6208cdde672f82f9), [`2015cf9`](https://github.com/mastra-ai/mastra/commit/2015cf921649f44c3f5bcd32a2c052335f8e49b4), [`7ef454e`](https://github.com/mastra-ai/mastra/commit/7ef454eaf9dcec6de60021c8f42192052dd490d6), [`2be1d99`](https://github.com/mastra-ai/mastra/commit/2be1d99564ce79acc4846071082bff353035a87a), [`2708fa1`](https://github.com/mastra-ai/mastra/commit/2708fa1055ac91c03e08b598869f6b8fb51fa37f), [`ba74aef`](https://github.com/mastra-ai/mastra/commit/ba74aef5716142dbbe931351f5243c9c6e4128a9), [`ba74aef`](https://github.com/mastra-ai/mastra/commit/ba74aef5716142dbbe931351f5243c9c6e4128a9), [`ec53e89`](https://github.com/mastra-ai/mastra/commit/ec53e8939c76c638991e21af762e51378eff7543), [`9b5a8cb`](https://github.com/mastra-ai/mastra/commit/9b5a8cb13e120811b0bf14140ada314f1c067894), [`607e66b`](https://github.com/mastra-ai/mastra/commit/607e66b02dc7f531ee37799f3456aa2dc0ca7ac5), [`a215d06`](https://github.com/mastra-ai/mastra/commit/a215d06758dcf590eabfe0b7afd4ae39bdbf082c), [`6909c74`](https://github.com/mastra-ai/mastra/commit/6909c74a7781e0447d475e9dbc1dc871b700f426), [`192438f`](https://github.com/mastra-ai/mastra/commit/192438f8a90c4f375e955f8ff179bf8dc6821a83)]:
|
|
55
|
+
- @mastra/core@1.5.0
|
|
56
|
+
- @mastra/schema-compat@1.1.1
|
|
57
|
+
|
|
58
|
+
## 1.4.0-alpha.1
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- Updated dependencies [[`1415bcd`](https://github.com/mastra-ai/mastra/commit/1415bcd894baba03e07640b3b1986037db49559d)]:
|
|
63
|
+
- @mastra/schema-compat@1.1.1-alpha.0
|
|
64
|
+
- @mastra/core@1.5.0-alpha.1
|
|
65
|
+
|
|
3
66
|
## 1.4.0-alpha.0
|
|
4
67
|
|
|
5
68
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -7024,12 +7024,12 @@ async function getVercelRequestId() {
|
|
|
7024
7024
|
var VERSION3 = "2.0.15";
|
|
7025
7025
|
var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
|
|
7026
7026
|
function createGatewayProvider(options = {}) {
|
|
7027
|
-
var _a832,
|
|
7027
|
+
var _a832, _b84;
|
|
7028
7028
|
let pendingMetadata = null;
|
|
7029
7029
|
let metadataCache = null;
|
|
7030
7030
|
const cacheRefreshMillis = (_a832 = options.metadataCacheRefreshMillis) != null ? _a832 : 1e3 * 60 * 5;
|
|
7031
7031
|
let lastFetchTime = 0;
|
|
7032
|
-
const baseURL = (
|
|
7032
|
+
const baseURL = (_b84 = withoutTrailingSlash(options.baseURL)) != null ? _b84 : "https://ai-gateway.vercel.sh/v1/ai";
|
|
7033
7033
|
const getHeaders = async () => {
|
|
7034
7034
|
const auth = await getGatewayAuthToken(options);
|
|
7035
7035
|
if (auth) {
|
|
@@ -7082,8 +7082,8 @@ function createGatewayProvider(options = {}) {
|
|
|
7082
7082
|
});
|
|
7083
7083
|
};
|
|
7084
7084
|
const getAvailableModels = async () => {
|
|
7085
|
-
var
|
|
7086
|
-
const now2 = (_c = (_b92 = (
|
|
7085
|
+
var _a923, _b92, _c;
|
|
7086
|
+
const now2 = (_c = (_b92 = (_a923 = options._internal) == null ? void 0 : _a923.currentDate) == null ? void 0 : _b92.call(_a923).getTime()) != null ? _c : Date.now();
|
|
7087
7087
|
if (!pendingMetadata || now2 - lastFetchTime > cacheRefreshMillis) {
|
|
7088
7088
|
lastFetchTime = now2;
|
|
7089
7089
|
pendingMetadata = new GatewayFetchMetadata({
|
|
@@ -7260,12 +7260,12 @@ function registerGlobal2(type, instance, diag, allowOverride) {
|
|
|
7260
7260
|
return true;
|
|
7261
7261
|
}
|
|
7262
7262
|
function getGlobal2(type) {
|
|
7263
|
-
var _a163,
|
|
7263
|
+
var _a163, _b84;
|
|
7264
7264
|
var globalVersion = (_a163 = _global2[GLOBAL_OPENTELEMETRY_API_KEY2]) === null || _a163 === void 0 ? void 0 : _a163.version;
|
|
7265
7265
|
if (!globalVersion || !isCompatible2(globalVersion)) {
|
|
7266
7266
|
return;
|
|
7267
7267
|
}
|
|
7268
|
-
return (
|
|
7268
|
+
return (_b84 = _global2[GLOBAL_OPENTELEMETRY_API_KEY2]) === null || _b84 === void 0 ? void 0 : _b84[type];
|
|
7269
7269
|
}
|
|
7270
7270
|
function unregisterGlobal2(type, diag) {
|
|
7271
7271
|
diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION22 + ".");
|
|
@@ -7430,7 +7430,7 @@ var DiagAPI2 = (
|
|
|
7430
7430
|
}
|
|
7431
7431
|
var self = this;
|
|
7432
7432
|
var setLogger = function(logger, optionsOrLogLevel) {
|
|
7433
|
-
var _a163,
|
|
7433
|
+
var _a163, _b84, _c;
|
|
7434
7434
|
if (optionsOrLogLevel === void 0) {
|
|
7435
7435
|
optionsOrLogLevel = { logLevel: DiagLogLevel2.INFO };
|
|
7436
7436
|
}
|
|
@@ -7445,7 +7445,7 @@ var DiagAPI2 = (
|
|
|
7445
7445
|
};
|
|
7446
7446
|
}
|
|
7447
7447
|
var oldLogger = getGlobal2("diag");
|
|
7448
|
-
var newLogger = createLogLevelDiagLogger2((
|
|
7448
|
+
var newLogger = createLogLevelDiagLogger2((_b84 = optionsOrLogLevel.logLevel) !== null && _b84 !== void 0 ? _b84 : DiagLogLevel2.INFO, logger);
|
|
7449
7449
|
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
|
7450
7450
|
var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
|
|
7451
7451
|
oldLogger.warn("Current logger will be overwritten from " + stack);
|
|
@@ -7984,8 +7984,8 @@ var dataContentSchema2 = z4.z.union([
|
|
|
7984
7984
|
z4.z.custom(
|
|
7985
7985
|
// Buffer might not be available in some environments such as CloudFlare:
|
|
7986
7986
|
(value) => {
|
|
7987
|
-
var _a163,
|
|
7988
|
-
return (
|
|
7987
|
+
var _a163, _b84;
|
|
7988
|
+
return (_b84 = (_a163 = globalThis.Buffer) == null ? void 0 : _a163.isBuffer(value)) != null ? _b84 : false;
|
|
7989
7989
|
},
|
|
7990
7990
|
{ message: "Must be a Buffer" }
|
|
7991
7991
|
)
|
|
@@ -9587,7 +9587,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
|
|
|
9587
9587
|
);
|
|
9588
9588
|
return Object.fromEntries(normalizedHeaders.entries());
|
|
9589
9589
|
}
|
|
9590
|
-
var VERSION4 = "4.0.
|
|
9590
|
+
var VERSION4 = "4.0.15";
|
|
9591
9591
|
var getOriginalFetch3 = () => globalThis.fetch;
|
|
9592
9592
|
var getFromApi2 = async ({
|
|
9593
9593
|
url,
|
|
@@ -11595,7 +11595,7 @@ async function createGatewayErrorFromResponse2({
|
|
|
11595
11595
|
cause,
|
|
11596
11596
|
authMethod
|
|
11597
11597
|
}) {
|
|
11598
|
-
var
|
|
11598
|
+
var _a932;
|
|
11599
11599
|
const parseResult = await safeValidateTypes3({
|
|
11600
11600
|
value: response,
|
|
11601
11601
|
schema: gatewayErrorResponseSchema2
|
|
@@ -11614,7 +11614,7 @@ async function createGatewayErrorFromResponse2({
|
|
|
11614
11614
|
const validatedResponse = parseResult.value;
|
|
11615
11615
|
const errorType = validatedResponse.error.type;
|
|
11616
11616
|
const message = validatedResponse.error.message;
|
|
11617
|
-
const generationId = (
|
|
11617
|
+
const generationId = (_a932 = validatedResponse.generationId) != null ? _a932 : void 0;
|
|
11618
11618
|
switch (errorType) {
|
|
11619
11619
|
case "authentication_error":
|
|
11620
11620
|
return GatewayAuthenticationError2.createContextualError({
|
|
@@ -11680,21 +11680,88 @@ var gatewayErrorResponseSchema2 = lazySchema(
|
|
|
11680
11680
|
})
|
|
11681
11681
|
)
|
|
11682
11682
|
);
|
|
11683
|
-
|
|
11684
|
-
|
|
11683
|
+
var name76 = "GatewayTimeoutError";
|
|
11684
|
+
var marker86 = `vercel.ai.gateway.error.${name76}`;
|
|
11685
|
+
var symbol86 = Symbol.for(marker86);
|
|
11686
|
+
var _a86;
|
|
11687
|
+
var _b83;
|
|
11688
|
+
var GatewayTimeoutError = class _GatewayTimeoutError extends (_b83 = GatewayError2, _a86 = symbol86, _b83) {
|
|
11689
|
+
constructor({
|
|
11690
|
+
message = "Request timed out",
|
|
11691
|
+
statusCode = 408,
|
|
11692
|
+
cause,
|
|
11693
|
+
generationId
|
|
11694
|
+
} = {}) {
|
|
11695
|
+
super({ message, statusCode, cause, generationId });
|
|
11696
|
+
this[_a86] = true;
|
|
11697
|
+
this.name = name76;
|
|
11698
|
+
this.type = "timeout_error";
|
|
11699
|
+
}
|
|
11700
|
+
static isInstance(error) {
|
|
11701
|
+
return GatewayError2.hasMarker(error) && symbol86 in error;
|
|
11702
|
+
}
|
|
11703
|
+
/**
|
|
11704
|
+
* Creates a helpful timeout error message with troubleshooting guidance
|
|
11705
|
+
*/
|
|
11706
|
+
static createTimeoutError({
|
|
11707
|
+
originalMessage,
|
|
11708
|
+
statusCode = 408,
|
|
11709
|
+
cause,
|
|
11710
|
+
generationId
|
|
11711
|
+
}) {
|
|
11712
|
+
const message = `Gateway request timed out: ${originalMessage}
|
|
11713
|
+
|
|
11714
|
+
This is a client-side timeout. To resolve this, increase your timeout configuration: https://vercel.com/docs/ai-gateway/capabilities/video-generation#extending-timeouts-for-node.js`;
|
|
11715
|
+
return new _GatewayTimeoutError({
|
|
11716
|
+
message,
|
|
11717
|
+
statusCode,
|
|
11718
|
+
cause,
|
|
11719
|
+
generationId
|
|
11720
|
+
});
|
|
11721
|
+
}
|
|
11722
|
+
};
|
|
11723
|
+
function isTimeoutError(error) {
|
|
11724
|
+
if (!(error instanceof Error)) {
|
|
11725
|
+
return false;
|
|
11726
|
+
}
|
|
11727
|
+
const errorCode = error.code;
|
|
11728
|
+
if (typeof errorCode === "string") {
|
|
11729
|
+
const undiciTimeoutCodes = [
|
|
11730
|
+
"UND_ERR_HEADERS_TIMEOUT",
|
|
11731
|
+
"UND_ERR_BODY_TIMEOUT",
|
|
11732
|
+
"UND_ERR_CONNECT_TIMEOUT"
|
|
11733
|
+
];
|
|
11734
|
+
return undiciTimeoutCodes.includes(errorCode);
|
|
11735
|
+
}
|
|
11736
|
+
return false;
|
|
11737
|
+
}
|
|
11738
|
+
async function asGatewayError2(error, authMethod) {
|
|
11739
|
+
var _a932;
|
|
11685
11740
|
if (GatewayError2.isInstance(error)) {
|
|
11686
11741
|
return error;
|
|
11687
11742
|
}
|
|
11743
|
+
if (isTimeoutError(error)) {
|
|
11744
|
+
return GatewayTimeoutError.createTimeoutError({
|
|
11745
|
+
originalMessage: error instanceof Error ? error.message : "Unknown error",
|
|
11746
|
+
cause: error
|
|
11747
|
+
});
|
|
11748
|
+
}
|
|
11688
11749
|
if (APICallError3.isInstance(error)) {
|
|
11689
|
-
|
|
11750
|
+
if (error.cause && isTimeoutError(error.cause)) {
|
|
11751
|
+
return GatewayTimeoutError.createTimeoutError({
|
|
11752
|
+
originalMessage: error.message,
|
|
11753
|
+
cause: error
|
|
11754
|
+
});
|
|
11755
|
+
}
|
|
11756
|
+
return await createGatewayErrorFromResponse2({
|
|
11690
11757
|
response: extractApiCallResponse2(error),
|
|
11691
|
-
statusCode: (
|
|
11758
|
+
statusCode: (_a932 = error.statusCode) != null ? _a932 : 500,
|
|
11692
11759
|
defaultMessage: "Gateway request failed",
|
|
11693
11760
|
cause: error,
|
|
11694
11761
|
authMethod
|
|
11695
11762
|
});
|
|
11696
11763
|
}
|
|
11697
|
-
return createGatewayErrorFromResponse2({
|
|
11764
|
+
return await createGatewayErrorFromResponse2({
|
|
11698
11765
|
response: {},
|
|
11699
11766
|
statusCode: 500,
|
|
11700
11767
|
defaultMessage: error instanceof Error ? `Gateway request failed: ${error.message}` : "Unknown Gateway error",
|
|
@@ -11796,7 +11863,7 @@ var gatewayAvailableModelsResponseSchema2 = lazySchema(
|
|
|
11796
11863
|
provider: z4.z.string(),
|
|
11797
11864
|
modelId: z4.z.string()
|
|
11798
11865
|
}),
|
|
11799
|
-
modelType: z4.z.enum(["
|
|
11866
|
+
modelType: z4.z.enum(["embedding", "image", "language", "video"]).nullish()
|
|
11800
11867
|
})
|
|
11801
11868
|
)
|
|
11802
11869
|
})
|
|
@@ -11975,7 +12042,7 @@ var GatewayEmbeddingModel2 = class {
|
|
|
11975
12042
|
abortSignal,
|
|
11976
12043
|
providerOptions
|
|
11977
12044
|
}) {
|
|
11978
|
-
var
|
|
12045
|
+
var _a932;
|
|
11979
12046
|
const resolvedHeaders = await resolve2(this.config.headers());
|
|
11980
12047
|
try {
|
|
11981
12048
|
const {
|
|
@@ -12006,7 +12073,7 @@ var GatewayEmbeddingModel2 = class {
|
|
|
12006
12073
|
});
|
|
12007
12074
|
return {
|
|
12008
12075
|
embeddings: responseBody.embeddings,
|
|
12009
|
-
usage: (
|
|
12076
|
+
usage: (_a932 = responseBody.usage) != null ? _a932 : void 0,
|
|
12010
12077
|
providerMetadata: responseBody.providerMetadata,
|
|
12011
12078
|
response: { headers: responseHeaders, body: rawValue },
|
|
12012
12079
|
warnings: []
|
|
@@ -12056,7 +12123,7 @@ var GatewayImageModel2 = class {
|
|
|
12056
12123
|
headers,
|
|
12057
12124
|
abortSignal
|
|
12058
12125
|
}) {
|
|
12059
|
-
var
|
|
12126
|
+
var _a932, _b92, _c, _d;
|
|
12060
12127
|
const resolvedHeaders = await resolve2(this.config.headers());
|
|
12061
12128
|
try {
|
|
12062
12129
|
const {
|
|
@@ -12095,16 +12162,23 @@ var GatewayImageModel2 = class {
|
|
|
12095
12162
|
return {
|
|
12096
12163
|
images: responseBody.images,
|
|
12097
12164
|
// Always base64 strings from server
|
|
12098
|
-
warnings: (
|
|
12165
|
+
warnings: (_a932 = responseBody.warnings) != null ? _a932 : [],
|
|
12099
12166
|
providerMetadata: responseBody.providerMetadata,
|
|
12100
12167
|
response: {
|
|
12101
12168
|
timestamp: /* @__PURE__ */ new Date(),
|
|
12102
12169
|
modelId: this.modelId,
|
|
12103
12170
|
headers: responseHeaders
|
|
12171
|
+
},
|
|
12172
|
+
...responseBody.usage != null && {
|
|
12173
|
+
usage: {
|
|
12174
|
+
inputTokens: (_b92 = responseBody.usage.inputTokens) != null ? _b92 : void 0,
|
|
12175
|
+
outputTokens: (_c = responseBody.usage.outputTokens) != null ? _c : void 0,
|
|
12176
|
+
totalTokens: (_d = responseBody.usage.totalTokens) != null ? _d : void 0
|
|
12177
|
+
}
|
|
12104
12178
|
}
|
|
12105
12179
|
};
|
|
12106
12180
|
} catch (error) {
|
|
12107
|
-
throw asGatewayError2(error, await parseAuthMethod2(resolvedHeaders));
|
|
12181
|
+
throw await asGatewayError2(error, await parseAuthMethod2(resolvedHeaders));
|
|
12108
12182
|
}
|
|
12109
12183
|
}
|
|
12110
12184
|
getUrl() {
|
|
@@ -12129,16 +12203,160 @@ function maybeEncodeImageFile(file) {
|
|
|
12129
12203
|
var providerMetadataEntrySchema2 = z4.z.object({
|
|
12130
12204
|
images: z4.z.array(z4.z.unknown()).optional()
|
|
12131
12205
|
}).catchall(z4.z.unknown());
|
|
12206
|
+
var gatewayImageWarningSchema = z4.z.discriminatedUnion("type", [
|
|
12207
|
+
z4.z.object({
|
|
12208
|
+
type: z4.z.literal("unsupported"),
|
|
12209
|
+
feature: z4.z.string(),
|
|
12210
|
+
details: z4.z.string().optional()
|
|
12211
|
+
}),
|
|
12212
|
+
z4.z.object({
|
|
12213
|
+
type: z4.z.literal("compatibility"),
|
|
12214
|
+
feature: z4.z.string(),
|
|
12215
|
+
details: z4.z.string().optional()
|
|
12216
|
+
}),
|
|
12217
|
+
z4.z.object({
|
|
12218
|
+
type: z4.z.literal("other"),
|
|
12219
|
+
message: z4.z.string()
|
|
12220
|
+
})
|
|
12221
|
+
]);
|
|
12222
|
+
var gatewayImageUsageSchema = z4.z.object({
|
|
12223
|
+
inputTokens: z4.z.number().nullish(),
|
|
12224
|
+
outputTokens: z4.z.number().nullish(),
|
|
12225
|
+
totalTokens: z4.z.number().nullish()
|
|
12226
|
+
});
|
|
12132
12227
|
var gatewayImageResponseSchema2 = z4.z.object({
|
|
12133
12228
|
images: z4.z.array(z4.z.string()),
|
|
12134
12229
|
// Always base64 strings over the wire
|
|
12135
|
-
warnings: z4.z.array(
|
|
12136
|
-
|
|
12137
|
-
|
|
12138
|
-
|
|
12139
|
-
|
|
12140
|
-
|
|
12141
|
-
|
|
12230
|
+
warnings: z4.z.array(gatewayImageWarningSchema).optional(),
|
|
12231
|
+
providerMetadata: z4.z.record(z4.z.string(), providerMetadataEntrySchema2).optional(),
|
|
12232
|
+
usage: gatewayImageUsageSchema.optional()
|
|
12233
|
+
});
|
|
12234
|
+
var GatewayVideoModel = class {
|
|
12235
|
+
constructor(modelId, config) {
|
|
12236
|
+
this.modelId = modelId;
|
|
12237
|
+
this.config = config;
|
|
12238
|
+
this.specificationVersion = "v3";
|
|
12239
|
+
this.maxVideosPerCall = Number.MAX_SAFE_INTEGER;
|
|
12240
|
+
}
|
|
12241
|
+
get provider() {
|
|
12242
|
+
return this.config.provider;
|
|
12243
|
+
}
|
|
12244
|
+
async doGenerate({
|
|
12245
|
+
prompt,
|
|
12246
|
+
n,
|
|
12247
|
+
aspectRatio,
|
|
12248
|
+
resolution,
|
|
12249
|
+
duration,
|
|
12250
|
+
fps,
|
|
12251
|
+
seed,
|
|
12252
|
+
image,
|
|
12253
|
+
providerOptions,
|
|
12254
|
+
headers,
|
|
12255
|
+
abortSignal
|
|
12256
|
+
}) {
|
|
12257
|
+
var _a932;
|
|
12258
|
+
const resolvedHeaders = await resolve2(this.config.headers());
|
|
12259
|
+
try {
|
|
12260
|
+
const {
|
|
12261
|
+
responseHeaders,
|
|
12262
|
+
value: responseBody
|
|
12263
|
+
} = await postJsonToApi2({
|
|
12264
|
+
url: this.getUrl(),
|
|
12265
|
+
headers: combineHeaders2(
|
|
12266
|
+
resolvedHeaders,
|
|
12267
|
+
headers != null ? headers : {},
|
|
12268
|
+
this.getModelConfigHeaders(),
|
|
12269
|
+
await resolve2(this.config.o11yHeaders)
|
|
12270
|
+
),
|
|
12271
|
+
body: {
|
|
12272
|
+
prompt,
|
|
12273
|
+
n,
|
|
12274
|
+
...aspectRatio && { aspectRatio },
|
|
12275
|
+
...resolution && { resolution },
|
|
12276
|
+
...duration && { duration },
|
|
12277
|
+
...fps && { fps },
|
|
12278
|
+
...seed && { seed },
|
|
12279
|
+
...providerOptions && { providerOptions },
|
|
12280
|
+
...image && { image: maybeEncodeVideoFile(image) }
|
|
12281
|
+
},
|
|
12282
|
+
successfulResponseHandler: createJsonResponseHandler2(
|
|
12283
|
+
gatewayVideoResponseSchema
|
|
12284
|
+
),
|
|
12285
|
+
failedResponseHandler: createJsonErrorResponseHandler2({
|
|
12286
|
+
errorSchema: z4.z.any(),
|
|
12287
|
+
errorToMessage: (data) => data
|
|
12288
|
+
}),
|
|
12289
|
+
...abortSignal && { abortSignal },
|
|
12290
|
+
fetch: this.config.fetch
|
|
12291
|
+
});
|
|
12292
|
+
return {
|
|
12293
|
+
videos: responseBody.videos,
|
|
12294
|
+
warnings: (_a932 = responseBody.warnings) != null ? _a932 : [],
|
|
12295
|
+
providerMetadata: responseBody.providerMetadata,
|
|
12296
|
+
response: {
|
|
12297
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
12298
|
+
modelId: this.modelId,
|
|
12299
|
+
headers: responseHeaders
|
|
12300
|
+
}
|
|
12301
|
+
};
|
|
12302
|
+
} catch (error) {
|
|
12303
|
+
throw await asGatewayError2(error, await parseAuthMethod2(resolvedHeaders));
|
|
12304
|
+
}
|
|
12305
|
+
}
|
|
12306
|
+
getUrl() {
|
|
12307
|
+
return `${this.config.baseURL}/video-model`;
|
|
12308
|
+
}
|
|
12309
|
+
getModelConfigHeaders() {
|
|
12310
|
+
return {
|
|
12311
|
+
"ai-video-model-specification-version": "3",
|
|
12312
|
+
"ai-model-id": this.modelId
|
|
12313
|
+
};
|
|
12314
|
+
}
|
|
12315
|
+
};
|
|
12316
|
+
function maybeEncodeVideoFile(file) {
|
|
12317
|
+
if (file.type === "file" && file.data instanceof Uint8Array) {
|
|
12318
|
+
return {
|
|
12319
|
+
...file,
|
|
12320
|
+
data: convertUint8ArrayToBase643(file.data)
|
|
12321
|
+
};
|
|
12322
|
+
}
|
|
12323
|
+
return file;
|
|
12324
|
+
}
|
|
12325
|
+
var providerMetadataEntrySchema22 = z4.z.object({
|
|
12326
|
+
videos: z4.z.array(z4.z.unknown()).optional()
|
|
12327
|
+
}).catchall(z4.z.unknown());
|
|
12328
|
+
var gatewayVideoDataSchema = z4.z.union([
|
|
12329
|
+
z4.z.object({
|
|
12330
|
+
type: z4.z.literal("url"),
|
|
12331
|
+
url: z4.z.string(),
|
|
12332
|
+
mediaType: z4.z.string()
|
|
12333
|
+
}),
|
|
12334
|
+
z4.z.object({
|
|
12335
|
+
type: z4.z.literal("base64"),
|
|
12336
|
+
data: z4.z.string(),
|
|
12337
|
+
mediaType: z4.z.string()
|
|
12338
|
+
})
|
|
12339
|
+
]);
|
|
12340
|
+
var gatewayVideoWarningSchema = z4.z.discriminatedUnion("type", [
|
|
12341
|
+
z4.z.object({
|
|
12342
|
+
type: z4.z.literal("unsupported"),
|
|
12343
|
+
feature: z4.z.string(),
|
|
12344
|
+
details: z4.z.string().optional()
|
|
12345
|
+
}),
|
|
12346
|
+
z4.z.object({
|
|
12347
|
+
type: z4.z.literal("compatibility"),
|
|
12348
|
+
feature: z4.z.string(),
|
|
12349
|
+
details: z4.z.string().optional()
|
|
12350
|
+
}),
|
|
12351
|
+
z4.z.object({
|
|
12352
|
+
type: z4.z.literal("other"),
|
|
12353
|
+
message: z4.z.string()
|
|
12354
|
+
})
|
|
12355
|
+
]);
|
|
12356
|
+
var gatewayVideoResponseSchema = z4.z.object({
|
|
12357
|
+
videos: z4.z.array(gatewayVideoDataSchema),
|
|
12358
|
+
warnings: z4.z.array(gatewayVideoWarningSchema).optional(),
|
|
12359
|
+
providerMetadata: z4.z.record(z4.z.string(), providerMetadataEntrySchema22).optional()
|
|
12142
12360
|
});
|
|
12143
12361
|
var parallelSearchInputSchema = lazySchema(
|
|
12144
12362
|
() => zodSchema3(
|
|
@@ -12313,18 +12531,18 @@ var gatewayTools = {
|
|
|
12313
12531
|
perplexitySearch
|
|
12314
12532
|
};
|
|
12315
12533
|
async function getVercelRequestId2() {
|
|
12316
|
-
var
|
|
12317
|
-
return (
|
|
12534
|
+
var _a932;
|
|
12535
|
+
return (_a932 = (0, import_oidc3.getContext)().headers) == null ? void 0 : _a932["x-vercel-id"];
|
|
12318
12536
|
}
|
|
12319
|
-
var VERSION5 = "3.0.
|
|
12537
|
+
var VERSION5 = "3.0.50";
|
|
12320
12538
|
var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
|
|
12321
12539
|
function createGatewayProvider2(options = {}) {
|
|
12322
|
-
var
|
|
12540
|
+
var _a932, _b92;
|
|
12323
12541
|
let pendingMetadata = null;
|
|
12324
12542
|
let metadataCache = null;
|
|
12325
|
-
const cacheRefreshMillis = (
|
|
12543
|
+
const cacheRefreshMillis = (_a932 = options.metadataCacheRefreshMillis) != null ? _a932 : 1e3 * 60 * 5;
|
|
12326
12544
|
let lastFetchTime = 0;
|
|
12327
|
-
const baseURL = (
|
|
12545
|
+
const baseURL = (_b92 = withoutTrailingSlash2(options.baseURL)) != null ? _b92 : "https://ai-gateway.vercel.sh/v3/ai";
|
|
12328
12546
|
const getHeaders = async () => {
|
|
12329
12547
|
try {
|
|
12330
12548
|
const auth = await getGatewayAuthToken2(options);
|
|
@@ -12379,8 +12597,8 @@ function createGatewayProvider2(options = {}) {
|
|
|
12379
12597
|
});
|
|
12380
12598
|
};
|
|
12381
12599
|
const getAvailableModels = async () => {
|
|
12382
|
-
var
|
|
12383
|
-
const now2 = (_c = (
|
|
12600
|
+
var _a1022, _b102, _c;
|
|
12601
|
+
const now2 = (_c = (_b102 = (_a1022 = options._internal) == null ? void 0 : _a1022.currentDate) == null ? void 0 : _b102.call(_a1022).getTime()) != null ? _c : Date.now();
|
|
12384
12602
|
if (!pendingMetadata || now2 - lastFetchTime > cacheRefreshMillis) {
|
|
12385
12603
|
lastFetchTime = now2;
|
|
12386
12604
|
pendingMetadata = new GatewayFetchMetadata2({
|
|
@@ -12443,6 +12661,19 @@ function createGatewayProvider2(options = {}) {
|
|
|
12443
12661
|
};
|
|
12444
12662
|
provider.embeddingModel = createEmbeddingModel;
|
|
12445
12663
|
provider.textEmbeddingModel = createEmbeddingModel;
|
|
12664
|
+
provider.videoModel = (modelId) => {
|
|
12665
|
+
return new GatewayVideoModel(modelId, {
|
|
12666
|
+
provider: "gateway",
|
|
12667
|
+
baseURL,
|
|
12668
|
+
headers: getHeaders,
|
|
12669
|
+
fetch: options.fetch,
|
|
12670
|
+
o11yHeaders: createO11yHeaders()
|
|
12671
|
+
});
|
|
12672
|
+
};
|
|
12673
|
+
provider.chat = provider.languageModel;
|
|
12674
|
+
provider.embedding = provider.embeddingModel;
|
|
12675
|
+
provider.image = provider.imageModel;
|
|
12676
|
+
provider.video = provider.videoModel;
|
|
12446
12677
|
provider.tools = gatewayTools;
|
|
12447
12678
|
return provider;
|
|
12448
12679
|
}
|
|
@@ -12557,12 +12788,12 @@ function registerGlobal3(type, instance, diag, allowOverride) {
|
|
|
12557
12788
|
return true;
|
|
12558
12789
|
}
|
|
12559
12790
|
function getGlobal3(type) {
|
|
12560
|
-
var _a21,
|
|
12791
|
+
var _a21, _b92;
|
|
12561
12792
|
var globalVersion = (_a21 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) === null || _a21 === void 0 ? void 0 : _a21.version;
|
|
12562
12793
|
if (!globalVersion || !isCompatible3(globalVersion)) {
|
|
12563
12794
|
return;
|
|
12564
12795
|
}
|
|
12565
|
-
return (
|
|
12796
|
+
return (_b92 = _global3[GLOBAL_OPENTELEMETRY_API_KEY3]) === null || _b92 === void 0 ? void 0 : _b92[type];
|
|
12566
12797
|
}
|
|
12567
12798
|
function unregisterGlobal3(type, diag) {
|
|
12568
12799
|
diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION23 + ".");
|
|
@@ -12727,7 +12958,7 @@ var DiagAPI3 = (
|
|
|
12727
12958
|
}
|
|
12728
12959
|
var self = this;
|
|
12729
12960
|
var setLogger = function(logger, optionsOrLogLevel) {
|
|
12730
|
-
var _a21,
|
|
12961
|
+
var _a21, _b92, _c;
|
|
12731
12962
|
if (optionsOrLogLevel === void 0) {
|
|
12732
12963
|
optionsOrLogLevel = { logLevel: DiagLogLevel3.INFO };
|
|
12733
12964
|
}
|
|
@@ -12742,7 +12973,7 @@ var DiagAPI3 = (
|
|
|
12742
12973
|
};
|
|
12743
12974
|
}
|
|
12744
12975
|
var oldLogger = getGlobal3("diag");
|
|
12745
|
-
var newLogger = createLogLevelDiagLogger3((
|
|
12976
|
+
var newLogger = createLogLevelDiagLogger3((_b92 = optionsOrLogLevel.logLevel) !== null && _b92 !== void 0 ? _b92 : DiagLogLevel3.INFO, logger);
|
|
12746
12977
|
if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
|
|
12747
12978
|
var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
|
|
12748
12979
|
oldLogger.warn("Current logger will be overwritten from " + stack);
|
|
@@ -13175,10 +13406,10 @@ var __export3 = (target, all) => {
|
|
|
13175
13406
|
for (var name21 in all)
|
|
13176
13407
|
__defProp4(target, name21, { get: all[name21], enumerable: true });
|
|
13177
13408
|
};
|
|
13178
|
-
var
|
|
13179
|
-
var
|
|
13180
|
-
var
|
|
13181
|
-
var
|
|
13409
|
+
var name86 = "AI_InvalidArgumentError";
|
|
13410
|
+
var marker96 = `vercel.ai.error.${name86}`;
|
|
13411
|
+
var symbol96 = Symbol.for(marker96);
|
|
13412
|
+
var _a96;
|
|
13182
13413
|
var InvalidArgumentError23 = class extends AISDKError3 {
|
|
13183
13414
|
constructor({
|
|
13184
13415
|
parameter,
|
|
@@ -13186,20 +13417,20 @@ var InvalidArgumentError23 = class extends AISDKError3 {
|
|
|
13186
13417
|
message
|
|
13187
13418
|
}) {
|
|
13188
13419
|
super({
|
|
13189
|
-
name:
|
|
13420
|
+
name: name86,
|
|
13190
13421
|
message: `Invalid argument for parameter ${parameter}: ${message}`
|
|
13191
13422
|
});
|
|
13192
|
-
this[
|
|
13423
|
+
this[_a96] = true;
|
|
13193
13424
|
this.parameter = parameter;
|
|
13194
13425
|
this.value = value;
|
|
13195
13426
|
}
|
|
13196
13427
|
static isInstance(error) {
|
|
13197
|
-
return AISDKError3.hasMarker(error,
|
|
13428
|
+
return AISDKError3.hasMarker(error, marker96);
|
|
13198
13429
|
}
|
|
13199
13430
|
};
|
|
13200
|
-
|
|
13201
|
-
var
|
|
13202
|
-
var marker823 = `vercel.ai.error.${
|
|
13431
|
+
_a96 = symbol96;
|
|
13432
|
+
var name822 = "AI_NoObjectGeneratedError";
|
|
13433
|
+
var marker823 = `vercel.ai.error.${name822}`;
|
|
13203
13434
|
var symbol823 = Symbol.for(marker823);
|
|
13204
13435
|
var _a823;
|
|
13205
13436
|
var NoObjectGeneratedError3 = class extends AISDKError3 {
|
|
@@ -13211,7 +13442,7 @@ var NoObjectGeneratedError3 = class extends AISDKError3 {
|
|
|
13211
13442
|
usage,
|
|
13212
13443
|
finishReason
|
|
13213
13444
|
}) {
|
|
13214
|
-
super({ name:
|
|
13445
|
+
super({ name: name822, message, cause });
|
|
13215
13446
|
this[_a823] = true;
|
|
13216
13447
|
this.text = text22;
|
|
13217
13448
|
this.response = response;
|
|
@@ -13371,7 +13602,7 @@ function getTotalTimeoutMs(timeout) {
|
|
|
13371
13602
|
}
|
|
13372
13603
|
return timeout.totalMs;
|
|
13373
13604
|
}
|
|
13374
|
-
var VERSION33 = "6.0.
|
|
13605
|
+
var VERSION33 = "6.0.91";
|
|
13375
13606
|
var dataContentSchema3 = z4.z.union([
|
|
13376
13607
|
z4.z.string(),
|
|
13377
13608
|
z4.z.instanceof(Uint8Array),
|
|
@@ -13379,8 +13610,8 @@ var dataContentSchema3 = z4.z.union([
|
|
|
13379
13610
|
z4.z.custom(
|
|
13380
13611
|
// Buffer might not be available in some environments such as CloudFlare:
|
|
13381
13612
|
(value) => {
|
|
13382
|
-
var _a21,
|
|
13383
|
-
return (
|
|
13613
|
+
var _a21, _b92;
|
|
13614
|
+
return (_b92 = (_a21 = globalThis.Buffer) == null ? void 0 : _a21.isBuffer(value)) != null ? _b92 : false;
|
|
13384
13615
|
},
|
|
13385
13616
|
{ message: "Must be a Buffer" }
|
|
13386
13617
|
)
|