@mastra/server 1.36.0-alpha.3 → 1.36.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/{chunk-CIBEUC5W.js → chunk-7X6KGLPA.js} +3 -3
- package/dist/{chunk-CIBEUC5W.js.map → chunk-7X6KGLPA.js.map} +1 -1
- package/dist/{chunk-HGAPGNWM.cjs → chunk-L6U4LZZX.cjs} +3 -3
- package/dist/{chunk-HGAPGNWM.cjs.map → chunk-L6U4LZZX.cjs.map} +1 -1
- package/dist/{chunk-IXRARW5C.cjs → chunk-WNPUO7IZ.cjs} +112 -18
- package/dist/chunk-WNPUO7IZ.cjs.map +1 -0
- package/dist/{chunk-UOKSQHJY.js → chunk-ZJVB5TZ4.js} +112 -18
- package/dist/chunk-ZJVB5TZ4.js.map +1 -0
- package/dist/{dist-TXPFV4FE.js → dist-7I6EPNH3.js} +5 -5
- package/dist/{dist-TXPFV4FE.js.map → dist-7I6EPNH3.js.map} +1 -1
- package/dist/{dist-VWAYVM5T.cjs → dist-HR6TOFJM.cjs} +20 -20
- package/dist/{dist-VWAYVM5T.cjs.map → dist-HR6TOFJM.cjs.map} +1 -1
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/{observational-memory-J73GEMRQ-FRFHLHXN.cjs → observational-memory-KFKHBTCB-RMGPISAP.cjs} +26 -26
- package/dist/{observational-memory-J73GEMRQ-FRFHLHXN.cjs.map → observational-memory-KFKHBTCB-RMGPISAP.cjs.map} +1 -1
- package/dist/{observational-memory-J73GEMRQ-KNLGLGBD.js → observational-memory-KFKHBTCB-RX2CEPSU.js} +3 -3
- package/dist/{observational-memory-J73GEMRQ-KNLGLGBD.js.map → observational-memory-KFKHBTCB-RX2CEPSU.js.map} +1 -1
- package/dist/server/handlers/agent-builder.cjs +16 -16
- package/dist/server/handlers/agent-builder.js +1 -1
- package/dist/server/handlers.cjs +2 -2
- package/dist/server/handlers.js +1 -1
- package/package.json +4 -4
- package/dist/chunk-IXRARW5C.cjs.map +0 -1
- package/dist/chunk-UOKSQHJY.js.map +0 -1
|
@@ -1042,7 +1042,47 @@ function imageSize(input) {
|
|
|
1042
1042
|
throw new TypeError(`unsupported file type: ${type}`);
|
|
1043
1043
|
}
|
|
1044
1044
|
|
|
1045
|
-
// ../memory/dist/chunk-
|
|
1045
|
+
// ../memory/dist/chunk-NZXH5WER.js
|
|
1046
|
+
var MINUTE = 6e4;
|
|
1047
|
+
var HOUR = 60 * MINUTE;
|
|
1048
|
+
var SHORT_TTL = 5 * MINUTE;
|
|
1049
|
+
var OPENAI_EXTENDED_TTL = HOUR;
|
|
1050
|
+
var GEMINI_TTL = 24 * HOUR;
|
|
1051
|
+
var DEEPSEEK_TTL = HOUR;
|
|
1052
|
+
var GROQ_TTL = 2 * HOUR;
|
|
1053
|
+
function normalize(value) {
|
|
1054
|
+
return value?.toLowerCase() ?? "";
|
|
1055
|
+
}
|
|
1056
|
+
function isOpenAIShortTtlModel(modelId) {
|
|
1057
|
+
return /^gpt-4/.test(modelId) || /^gpt-5(?:$|-|\.([1-4])(?:$|-))/.test(modelId);
|
|
1058
|
+
}
|
|
1059
|
+
function getOpenAIPromptCacheRetention(providerOptions) {
|
|
1060
|
+
const openaiOptions = providerOptions?.openai;
|
|
1061
|
+
return typeof openaiOptions?.promptCacheRetention === "string" ? openaiOptions.promptCacheRetention.toLowerCase() : void 0;
|
|
1062
|
+
}
|
|
1063
|
+
function resolveActivationTTL(activateAfterIdle, modelContext) {
|
|
1064
|
+
if (activateAfterIdle !== "auto") {
|
|
1065
|
+
return activateAfterIdle;
|
|
1066
|
+
}
|
|
1067
|
+
return resolveAutoActivationTTL(modelContext);
|
|
1068
|
+
}
|
|
1069
|
+
function resolveAutoActivationTTL(modelContext) {
|
|
1070
|
+
const provider = normalize(modelContext?.provider);
|
|
1071
|
+
const modelId = normalize(modelContext?.modelId);
|
|
1072
|
+
if (provider.includes("openai")) {
|
|
1073
|
+
const promptCacheRetention = getOpenAIPromptCacheRetention(modelContext?.providerOptions);
|
|
1074
|
+
if (promptCacheRetention === "24h") return OPENAI_EXTENDED_TTL;
|
|
1075
|
+
if (promptCacheRetention === "in_memory") return SHORT_TTL;
|
|
1076
|
+
return isOpenAIShortTtlModel(modelId) ? SHORT_TTL : OPENAI_EXTENDED_TTL;
|
|
1077
|
+
}
|
|
1078
|
+
if (provider.includes("google") || provider.includes("gemini")) return GEMINI_TTL;
|
|
1079
|
+
if (provider.includes("deepseek")) return DEEPSEEK_TTL;
|
|
1080
|
+
if (provider.includes("groq")) return GROQ_TTL;
|
|
1081
|
+
if (provider.includes("anthropic")) return SHORT_TTL;
|
|
1082
|
+
if (provider.includes("xai") || provider.includes("grok")) return SHORT_TTL;
|
|
1083
|
+
if (provider.includes("openrouter")) return SHORT_TTL;
|
|
1084
|
+
return SHORT_TTL;
|
|
1085
|
+
}
|
|
1046
1086
|
var OM_DEBUG_LOG = process.env.OM_DEBUG ? path.join(process.cwd(), "om-debug.log") : null;
|
|
1047
1087
|
function omDebug(msg) {
|
|
1048
1088
|
if (!OM_DEBUG_LOG) return;
|
|
@@ -4144,6 +4184,35 @@ function isImageLikeObserverFilePart(part) {
|
|
|
4144
4184
|
}
|
|
4145
4185
|
return hasObserverImageFilenameExtension(part.filename);
|
|
4146
4186
|
}
|
|
4187
|
+
function resolveObserverAttachmentMimeType(part) {
|
|
4188
|
+
if (typeof part.mimeType === "string" && part.mimeType.length > 0) {
|
|
4189
|
+
return part.mimeType.toLowerCase();
|
|
4190
|
+
}
|
|
4191
|
+
if (part.type === "image") {
|
|
4192
|
+
return "image/*";
|
|
4193
|
+
}
|
|
4194
|
+
if (isImageLikeObserverFilePart(part)) {
|
|
4195
|
+
return "image/*";
|
|
4196
|
+
}
|
|
4197
|
+
return "application/octet-stream";
|
|
4198
|
+
}
|
|
4199
|
+
function matchObserverMimePattern(mimeType, pattern) {
|
|
4200
|
+
const normalized = pattern.trim().toLowerCase();
|
|
4201
|
+
if (!normalized) return false;
|
|
4202
|
+
if (normalized === "*" || normalized === "*/*") return true;
|
|
4203
|
+
if (normalized.endsWith("/*")) {
|
|
4204
|
+
const prefix = normalized.slice(0, normalized.length - 1);
|
|
4205
|
+
return mimeType.startsWith(prefix);
|
|
4206
|
+
}
|
|
4207
|
+
return mimeType === normalized;
|
|
4208
|
+
}
|
|
4209
|
+
function shouldIncludeObserverAttachment(part, filter) {
|
|
4210
|
+
if (filter === void 0 || filter === true) return true;
|
|
4211
|
+
if (filter === false) return false;
|
|
4212
|
+
if (!Array.isArray(filter) || filter.length === 0) return false;
|
|
4213
|
+
const mimeType = resolveObserverAttachmentMimeType(part);
|
|
4214
|
+
return filter.some((pattern) => matchObserverMimePattern(mimeType, pattern));
|
|
4215
|
+
}
|
|
4147
4216
|
function toObserverInputAttachmentPart(part) {
|
|
4148
4217
|
if (part.type === "image") {
|
|
4149
4218
|
return {
|
|
@@ -4242,22 +4311,26 @@ function mapToolResultBlockToAttachment(block) {
|
|
|
4242
4311
|
return void 0;
|
|
4243
4312
|
}
|
|
4244
4313
|
}
|
|
4245
|
-
function extractToolResultAttachments(result, counter) {
|
|
4314
|
+
function extractToolResultAttachments(result, counter, attachmentFilter) {
|
|
4246
4315
|
if (!isRecord(result) || result.type !== "content" || !Array.isArray(result.value)) {
|
|
4247
4316
|
return { resultWithoutAttachments: result, attachments: [] };
|
|
4248
4317
|
}
|
|
4249
4318
|
const record = result;
|
|
4250
4319
|
const attachments = [];
|
|
4320
|
+
let hadAttachmentBlocks = false;
|
|
4251
4321
|
const newValue = record.value.map((block) => {
|
|
4252
4322
|
const attachment = mapToolResultBlockToAttachment(block);
|
|
4253
4323
|
if (!attachment) {
|
|
4254
4324
|
return block;
|
|
4255
4325
|
}
|
|
4256
|
-
|
|
4326
|
+
hadAttachmentBlocks = true;
|
|
4327
|
+
if (shouldIncludeObserverAttachment(attachment, attachmentFilter)) {
|
|
4328
|
+
attachments.push(toObserverInputAttachmentPart(attachment));
|
|
4329
|
+
}
|
|
4257
4330
|
const placeholder = formatObserverAttachmentPlaceholder(attachment, counter);
|
|
4258
4331
|
return { type: isRecord(block) ? block.type : void 0, placeholder };
|
|
4259
4332
|
});
|
|
4260
|
-
if (
|
|
4333
|
+
if (!hadAttachmentBlocks) {
|
|
4261
4334
|
return { resultWithoutAttachments: result, attachments };
|
|
4262
4335
|
}
|
|
4263
4336
|
return { resultWithoutAttachments: { ...record, value: newValue }, attachments };
|
|
@@ -4316,6 +4389,7 @@ function getTemporalGapMarkerText(msg) {
|
|
|
4316
4389
|
function formatObserverMessage(msg, counter, options) {
|
|
4317
4390
|
const maxLen = options?.maxPartLength;
|
|
4318
4391
|
const maxToolResultTokens = options?.maxToolResultTokens ?? DEFAULT_OBSERVER_TOOL_RESULT_MAX_TOKENS;
|
|
4392
|
+
const attachmentFilter = options?.attachmentFilter;
|
|
4319
4393
|
const role = msg.role.charAt(0).toUpperCase() + msg.role.slice(1);
|
|
4320
4394
|
const attachments = [];
|
|
4321
4395
|
const messageCreatedAt = normalizeObserverCreatedAt(msg.createdAt);
|
|
@@ -4353,7 +4427,8 @@ function formatObserverMessage(msg, counter, options) {
|
|
|
4353
4427
|
);
|
|
4354
4428
|
const { resultWithoutAttachments, attachments: extractedAttachments } = extractToolResultAttachments(
|
|
4355
4429
|
resultForObserver,
|
|
4356
|
-
counter
|
|
4430
|
+
counter,
|
|
4431
|
+
attachmentFilter
|
|
4357
4432
|
);
|
|
4358
4433
|
if (extractedAttachments.length > 0) {
|
|
4359
4434
|
attachments.push(...extractedAttachments);
|
|
@@ -4382,9 +4457,11 @@ function formatObserverMessage(msg, counter, options) {
|
|
|
4382
4457
|
}
|
|
4383
4458
|
if (partType === "image" || partType === "file") {
|
|
4384
4459
|
const attachment = part;
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4460
|
+
if (shouldIncludeObserverAttachment(attachment, attachmentFilter)) {
|
|
4461
|
+
const inputAttachment = toObserverInputAttachmentPart(attachment);
|
|
4462
|
+
if (inputAttachment) {
|
|
4463
|
+
attachments.push(inputAttachment);
|
|
4464
|
+
}
|
|
4388
4465
|
}
|
|
4389
4466
|
pushLine(
|
|
4390
4467
|
partType === "image" ? "Image" : "File",
|
|
@@ -5043,7 +5120,9 @@ var ObserverRunner = class {
|
|
|
5043
5120
|
includeThreadTitle: this.observationConfig.threadTitle
|
|
5044
5121
|
})
|
|
5045
5122
|
},
|
|
5046
|
-
buildObserverHistoryMessage(messagesToObserve
|
|
5123
|
+
buildObserverHistoryMessage(messagesToObserve, {
|
|
5124
|
+
attachmentFilter: this.observationConfig.observeAttachments
|
|
5125
|
+
})
|
|
5047
5126
|
];
|
|
5048
5127
|
const doGenerate = async () => {
|
|
5049
5128
|
return withRetry(
|
|
@@ -5140,7 +5219,9 @@ var ObserverRunner = class {
|
|
|
5140
5219
|
this.observationConfig.threadTitle
|
|
5141
5220
|
)
|
|
5142
5221
|
},
|
|
5143
|
-
buildMultiThreadObserverHistoryMessage(messagesByThread, threadOrder
|
|
5222
|
+
buildMultiThreadObserverHistoryMessage(messagesByThread, threadOrder, {
|
|
5223
|
+
attachmentFilter: this.observationConfig.observeAttachments
|
|
5224
|
+
})
|
|
5144
5225
|
];
|
|
5145
5226
|
for (const msgs of messagesByThread.values()) {
|
|
5146
5227
|
for (const msg of msgs) {
|
|
@@ -5967,7 +6048,10 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5967
6048
|
ttlExpiredMs: activationMetadata?.ttlExpiredMs,
|
|
5968
6049
|
previousModel: activationMetadata?.previousModel,
|
|
5969
6050
|
currentModel: activationMetadata?.currentModel,
|
|
5970
|
-
config:
|
|
6051
|
+
config: {
|
|
6052
|
+
...this.getObservationMarkerConfig(freshRecord),
|
|
6053
|
+
activateAfterIdle: activationMetadata?.activateAfterIdle ?? this.reflectionConfig.activateAfterIdle
|
|
6054
|
+
}
|
|
5971
6055
|
});
|
|
5972
6056
|
void writer.custom({ ...activationMarker, transient: true }).catch(() => {
|
|
5973
6057
|
});
|
|
@@ -6030,7 +6114,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
6030
6114
|
);
|
|
6031
6115
|
}
|
|
6032
6116
|
}
|
|
6033
|
-
const activateAfterIdle = this.reflectionConfig.activateAfterIdle;
|
|
6117
|
+
const activateAfterIdle = resolveActivationTTL(this.reflectionConfig.activateAfterIdle, currentModel);
|
|
6034
6118
|
const ttlExpiredMs = activateAfterIdle !== void 0 && lastActivityAt !== void 0 ? Date.now() - lastActivityAt : void 0;
|
|
6035
6119
|
const ttlExpired = ttlExpiredMs !== void 0 && activateAfterIdle !== void 0 && ttlExpiredMs >= activateAfterIdle;
|
|
6036
6120
|
const actorModel = getCurrentModel(currentModel);
|
|
@@ -6043,6 +6127,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
6043
6127
|
const activationMetadata = {
|
|
6044
6128
|
triggeredBy: activationTriggeredBy,
|
|
6045
6129
|
lastActivityAt: activationTriggeredBy === "ttl" ? lastActivityAt : void 0,
|
|
6130
|
+
activateAfterIdle: activationTriggeredBy === "ttl" ? activateAfterIdle : void 0,
|
|
6046
6131
|
ttlExpiredMs: activationTriggeredBy === "ttl" ? ttlExpiredMs : void 0,
|
|
6047
6132
|
previousModel: activationTriggeredBy === "provider_change" ? lastModel : void 0,
|
|
6048
6133
|
currentModel: activationTriggeredBy === "provider_change" ? actorModel : void 0
|
|
@@ -7881,6 +7966,9 @@ function parseActivationTTL(value, fieldPath) {
|
|
|
7881
7966
|
if (value === void 0 || value === false) {
|
|
7882
7967
|
return void 0;
|
|
7883
7968
|
}
|
|
7969
|
+
if (value === "auto") {
|
|
7970
|
+
return value;
|
|
7971
|
+
}
|
|
7884
7972
|
if (typeof value === "number") {
|
|
7885
7973
|
if (!Number.isFinite(value) || value < 0) {
|
|
7886
7974
|
throw new Error(`${fieldPath} must be a non-negative number of milliseconds or a duration string like "5m".`);
|
|
@@ -8053,7 +8141,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
8053
8141
|
),
|
|
8054
8142
|
previousObserverTokens: config.observation?.previousObserverTokens ?? 2e3,
|
|
8055
8143
|
instruction: config.observation?.instruction,
|
|
8056
|
-
threadTitle: config.observation?.threadTitle ?? false
|
|
8144
|
+
threadTitle: config.observation?.threadTitle ?? false,
|
|
8145
|
+
observeAttachments: config.observation?.observeAttachments ?? true
|
|
8057
8146
|
};
|
|
8058
8147
|
this.reflectionConfig = {
|
|
8059
8148
|
model: reflectionModel,
|
|
@@ -9976,6 +10065,7 @@ ${grouped}` : grouped;
|
|
|
9976
10065
|
}
|
|
9977
10066
|
let activationTriggeredBy = "threshold";
|
|
9978
10067
|
let activationLastActivityAt;
|
|
10068
|
+
let activationActivateAfterIdle;
|
|
9979
10069
|
let activateAfterIdleExpiredMs;
|
|
9980
10070
|
let previousModel;
|
|
9981
10071
|
let currentModel;
|
|
@@ -9985,7 +10075,7 @@ ${grouped}` : grouped;
|
|
|
9985
10075
|
resourceId,
|
|
9986
10076
|
record.lastObservedAt ? new Date(record.lastObservedAt) : void 0
|
|
9987
10077
|
);
|
|
9988
|
-
const activateAfterIdle = this.observationConfig.activateAfterIdle;
|
|
10078
|
+
const activateAfterIdle = resolveActivationTTL(this.observationConfig.activateAfterIdle, opts.currentModel);
|
|
9989
10079
|
const lastActivityAt = getLastActivityFromMessages(thresholdMessages);
|
|
9990
10080
|
const ttlExpiredMs = activateAfterIdle !== void 0 && lastActivityAt !== void 0 ? Date.now() - lastActivityAt : void 0;
|
|
9991
10081
|
const ttlExpired = ttlExpiredMs !== void 0 && activateAfterIdle !== void 0 && ttlExpiredMs >= activateAfterIdle;
|
|
@@ -9999,6 +10089,7 @@ ${grouped}` : grouped;
|
|
|
9999
10089
|
} else if (ttlExpired) {
|
|
10000
10090
|
activationTriggeredBy = "ttl";
|
|
10001
10091
|
activationLastActivityAt = lastActivityAt;
|
|
10092
|
+
activationActivateAfterIdle = activateAfterIdle;
|
|
10002
10093
|
activateAfterIdleExpiredMs = ttlExpiredMs;
|
|
10003
10094
|
} else {
|
|
10004
10095
|
const status = await this.getStatus({ threadId, resourceId, messages: thresholdMessages });
|
|
@@ -10067,7 +10158,10 @@ ${grouped}` : grouped;
|
|
|
10067
10158
|
ttlExpiredMs: activateAfterIdleExpiredMs,
|
|
10068
10159
|
previousModel,
|
|
10069
10160
|
currentModel,
|
|
10070
|
-
config:
|
|
10161
|
+
config: {
|
|
10162
|
+
...this.getObservationMarkerConfig(),
|
|
10163
|
+
activateAfterIdle: activationActivateAfterIdle ?? this.observationConfig.activateAfterIdle
|
|
10164
|
+
}
|
|
10071
10165
|
});
|
|
10072
10166
|
void opts.writer.custom({ ...activationMarker, transient: true }).catch(() => {
|
|
10073
10167
|
});
|
|
@@ -10522,7 +10616,7 @@ var ObservationalMemoryProcessor = class {
|
|
|
10522
10616
|
const { threadId, resourceId } = context;
|
|
10523
10617
|
const memoryContext = memory.parseMemoryRequestContext(requestContext);
|
|
10524
10618
|
const readOnly = memoryContext?.memoryConfig?.readOnly;
|
|
10525
|
-
const actorModelContext = model?.modelId ? { provider: model.provider, modelId: model.modelId } : void 0;
|
|
10619
|
+
const actorModelContext = model?.modelId ? { provider: model.provider, modelId: model.modelId, providerOptions: args.providerOptions } : void 0;
|
|
10526
10620
|
state.__omActorModelContext = actorModelContext;
|
|
10527
10621
|
return this.engine.getTokenCounter().runWithModelContext(actorModelContext, async () => {
|
|
10528
10622
|
const reproCaptureEnabled = isOmReproCaptureEnabled();
|
|
@@ -10736,5 +10830,5 @@ exports.stripEphemeralAnchorIds = stripEphemeralAnchorIds;
|
|
|
10736
10830
|
exports.stripObservationGroups = stripObservationGroups;
|
|
10737
10831
|
exports.truncateStringByTokens = truncateStringByTokens;
|
|
10738
10832
|
exports.wrapInObservationGroup = wrapInObservationGroup;
|
|
10739
|
-
//# sourceMappingURL=chunk-
|
|
10740
|
-
//# sourceMappingURL=chunk-
|
|
10833
|
+
//# sourceMappingURL=chunk-WNPUO7IZ.cjs.map
|
|
10834
|
+
//# sourceMappingURL=chunk-WNPUO7IZ.cjs.map
|