@mastra/server 1.36.0-alpha.3 → 1.36.0-alpha.5
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 +14 -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 +3 -3
- package/dist/chunk-IXRARW5C.cjs.map +0 -1
- package/dist/chunk-UOKSQHJY.js.map +0 -1
|
@@ -1040,7 +1040,47 @@ function imageSize(input) {
|
|
|
1040
1040
|
throw new TypeError(`unsupported file type: ${type}`);
|
|
1041
1041
|
}
|
|
1042
1042
|
|
|
1043
|
-
// ../memory/dist/chunk-
|
|
1043
|
+
// ../memory/dist/chunk-NZXH5WER.js
|
|
1044
|
+
var MINUTE = 6e4;
|
|
1045
|
+
var HOUR = 60 * MINUTE;
|
|
1046
|
+
var SHORT_TTL = 5 * MINUTE;
|
|
1047
|
+
var OPENAI_EXTENDED_TTL = HOUR;
|
|
1048
|
+
var GEMINI_TTL = 24 * HOUR;
|
|
1049
|
+
var DEEPSEEK_TTL = HOUR;
|
|
1050
|
+
var GROQ_TTL = 2 * HOUR;
|
|
1051
|
+
function normalize(value) {
|
|
1052
|
+
return value?.toLowerCase() ?? "";
|
|
1053
|
+
}
|
|
1054
|
+
function isOpenAIShortTtlModel(modelId) {
|
|
1055
|
+
return /^gpt-4/.test(modelId) || /^gpt-5(?:$|-|\.([1-4])(?:$|-))/.test(modelId);
|
|
1056
|
+
}
|
|
1057
|
+
function getOpenAIPromptCacheRetention(providerOptions) {
|
|
1058
|
+
const openaiOptions = providerOptions?.openai;
|
|
1059
|
+
return typeof openaiOptions?.promptCacheRetention === "string" ? openaiOptions.promptCacheRetention.toLowerCase() : void 0;
|
|
1060
|
+
}
|
|
1061
|
+
function resolveActivationTTL(activateAfterIdle, modelContext) {
|
|
1062
|
+
if (activateAfterIdle !== "auto") {
|
|
1063
|
+
return activateAfterIdle;
|
|
1064
|
+
}
|
|
1065
|
+
return resolveAutoActivationTTL(modelContext);
|
|
1066
|
+
}
|
|
1067
|
+
function resolveAutoActivationTTL(modelContext) {
|
|
1068
|
+
const provider = normalize(modelContext?.provider);
|
|
1069
|
+
const modelId = normalize(modelContext?.modelId);
|
|
1070
|
+
if (provider.includes("openai")) {
|
|
1071
|
+
const promptCacheRetention = getOpenAIPromptCacheRetention(modelContext?.providerOptions);
|
|
1072
|
+
if (promptCacheRetention === "24h") return OPENAI_EXTENDED_TTL;
|
|
1073
|
+
if (promptCacheRetention === "in_memory") return SHORT_TTL;
|
|
1074
|
+
return isOpenAIShortTtlModel(modelId) ? SHORT_TTL : OPENAI_EXTENDED_TTL;
|
|
1075
|
+
}
|
|
1076
|
+
if (provider.includes("google") || provider.includes("gemini")) return GEMINI_TTL;
|
|
1077
|
+
if (provider.includes("deepseek")) return DEEPSEEK_TTL;
|
|
1078
|
+
if (provider.includes("groq")) return GROQ_TTL;
|
|
1079
|
+
if (provider.includes("anthropic")) return SHORT_TTL;
|
|
1080
|
+
if (provider.includes("xai") || provider.includes("grok")) return SHORT_TTL;
|
|
1081
|
+
if (provider.includes("openrouter")) return SHORT_TTL;
|
|
1082
|
+
return SHORT_TTL;
|
|
1083
|
+
}
|
|
1044
1084
|
var OM_DEBUG_LOG = process.env.OM_DEBUG ? join(process.cwd(), "om-debug.log") : null;
|
|
1045
1085
|
function omDebug(msg) {
|
|
1046
1086
|
if (!OM_DEBUG_LOG) return;
|
|
@@ -4142,6 +4182,35 @@ function isImageLikeObserverFilePart(part) {
|
|
|
4142
4182
|
}
|
|
4143
4183
|
return hasObserverImageFilenameExtension(part.filename);
|
|
4144
4184
|
}
|
|
4185
|
+
function resolveObserverAttachmentMimeType(part) {
|
|
4186
|
+
if (typeof part.mimeType === "string" && part.mimeType.length > 0) {
|
|
4187
|
+
return part.mimeType.toLowerCase();
|
|
4188
|
+
}
|
|
4189
|
+
if (part.type === "image") {
|
|
4190
|
+
return "image/*";
|
|
4191
|
+
}
|
|
4192
|
+
if (isImageLikeObserverFilePart(part)) {
|
|
4193
|
+
return "image/*";
|
|
4194
|
+
}
|
|
4195
|
+
return "application/octet-stream";
|
|
4196
|
+
}
|
|
4197
|
+
function matchObserverMimePattern(mimeType, pattern) {
|
|
4198
|
+
const normalized = pattern.trim().toLowerCase();
|
|
4199
|
+
if (!normalized) return false;
|
|
4200
|
+
if (normalized === "*" || normalized === "*/*") return true;
|
|
4201
|
+
if (normalized.endsWith("/*")) {
|
|
4202
|
+
const prefix = normalized.slice(0, normalized.length - 1);
|
|
4203
|
+
return mimeType.startsWith(prefix);
|
|
4204
|
+
}
|
|
4205
|
+
return mimeType === normalized;
|
|
4206
|
+
}
|
|
4207
|
+
function shouldIncludeObserverAttachment(part, filter) {
|
|
4208
|
+
if (filter === void 0 || filter === true) return true;
|
|
4209
|
+
if (filter === false) return false;
|
|
4210
|
+
if (!Array.isArray(filter) || filter.length === 0) return false;
|
|
4211
|
+
const mimeType = resolveObserverAttachmentMimeType(part);
|
|
4212
|
+
return filter.some((pattern) => matchObserverMimePattern(mimeType, pattern));
|
|
4213
|
+
}
|
|
4145
4214
|
function toObserverInputAttachmentPart(part) {
|
|
4146
4215
|
if (part.type === "image") {
|
|
4147
4216
|
return {
|
|
@@ -4240,22 +4309,26 @@ function mapToolResultBlockToAttachment(block) {
|
|
|
4240
4309
|
return void 0;
|
|
4241
4310
|
}
|
|
4242
4311
|
}
|
|
4243
|
-
function extractToolResultAttachments(result, counter) {
|
|
4312
|
+
function extractToolResultAttachments(result, counter, attachmentFilter) {
|
|
4244
4313
|
if (!isRecord(result) || result.type !== "content" || !Array.isArray(result.value)) {
|
|
4245
4314
|
return { resultWithoutAttachments: result, attachments: [] };
|
|
4246
4315
|
}
|
|
4247
4316
|
const record = result;
|
|
4248
4317
|
const attachments = [];
|
|
4318
|
+
let hadAttachmentBlocks = false;
|
|
4249
4319
|
const newValue = record.value.map((block) => {
|
|
4250
4320
|
const attachment = mapToolResultBlockToAttachment(block);
|
|
4251
4321
|
if (!attachment) {
|
|
4252
4322
|
return block;
|
|
4253
4323
|
}
|
|
4254
|
-
|
|
4324
|
+
hadAttachmentBlocks = true;
|
|
4325
|
+
if (shouldIncludeObserverAttachment(attachment, attachmentFilter)) {
|
|
4326
|
+
attachments.push(toObserverInputAttachmentPart(attachment));
|
|
4327
|
+
}
|
|
4255
4328
|
const placeholder = formatObserverAttachmentPlaceholder(attachment, counter);
|
|
4256
4329
|
return { type: isRecord(block) ? block.type : void 0, placeholder };
|
|
4257
4330
|
});
|
|
4258
|
-
if (
|
|
4331
|
+
if (!hadAttachmentBlocks) {
|
|
4259
4332
|
return { resultWithoutAttachments: result, attachments };
|
|
4260
4333
|
}
|
|
4261
4334
|
return { resultWithoutAttachments: { ...record, value: newValue }, attachments };
|
|
@@ -4314,6 +4387,7 @@ function getTemporalGapMarkerText(msg) {
|
|
|
4314
4387
|
function formatObserverMessage(msg, counter, options) {
|
|
4315
4388
|
const maxLen = options?.maxPartLength;
|
|
4316
4389
|
const maxToolResultTokens = options?.maxToolResultTokens ?? DEFAULT_OBSERVER_TOOL_RESULT_MAX_TOKENS;
|
|
4390
|
+
const attachmentFilter = options?.attachmentFilter;
|
|
4317
4391
|
const role = msg.role.charAt(0).toUpperCase() + msg.role.slice(1);
|
|
4318
4392
|
const attachments = [];
|
|
4319
4393
|
const messageCreatedAt = normalizeObserverCreatedAt(msg.createdAt);
|
|
@@ -4351,7 +4425,8 @@ function formatObserverMessage(msg, counter, options) {
|
|
|
4351
4425
|
);
|
|
4352
4426
|
const { resultWithoutAttachments, attachments: extractedAttachments } = extractToolResultAttachments(
|
|
4353
4427
|
resultForObserver,
|
|
4354
|
-
counter
|
|
4428
|
+
counter,
|
|
4429
|
+
attachmentFilter
|
|
4355
4430
|
);
|
|
4356
4431
|
if (extractedAttachments.length > 0) {
|
|
4357
4432
|
attachments.push(...extractedAttachments);
|
|
@@ -4380,9 +4455,11 @@ function formatObserverMessage(msg, counter, options) {
|
|
|
4380
4455
|
}
|
|
4381
4456
|
if (partType === "image" || partType === "file") {
|
|
4382
4457
|
const attachment = part;
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4458
|
+
if (shouldIncludeObserverAttachment(attachment, attachmentFilter)) {
|
|
4459
|
+
const inputAttachment = toObserverInputAttachmentPart(attachment);
|
|
4460
|
+
if (inputAttachment) {
|
|
4461
|
+
attachments.push(inputAttachment);
|
|
4462
|
+
}
|
|
4386
4463
|
}
|
|
4387
4464
|
pushLine(
|
|
4388
4465
|
partType === "image" ? "Image" : "File",
|
|
@@ -5041,7 +5118,9 @@ var ObserverRunner = class {
|
|
|
5041
5118
|
includeThreadTitle: this.observationConfig.threadTitle
|
|
5042
5119
|
})
|
|
5043
5120
|
},
|
|
5044
|
-
buildObserverHistoryMessage(messagesToObserve
|
|
5121
|
+
buildObserverHistoryMessage(messagesToObserve, {
|
|
5122
|
+
attachmentFilter: this.observationConfig.observeAttachments
|
|
5123
|
+
})
|
|
5045
5124
|
];
|
|
5046
5125
|
const doGenerate = async () => {
|
|
5047
5126
|
return withRetry(
|
|
@@ -5138,7 +5217,9 @@ var ObserverRunner = class {
|
|
|
5138
5217
|
this.observationConfig.threadTitle
|
|
5139
5218
|
)
|
|
5140
5219
|
},
|
|
5141
|
-
buildMultiThreadObserverHistoryMessage(messagesByThread, threadOrder
|
|
5220
|
+
buildMultiThreadObserverHistoryMessage(messagesByThread, threadOrder, {
|
|
5221
|
+
attachmentFilter: this.observationConfig.observeAttachments
|
|
5222
|
+
})
|
|
5142
5223
|
];
|
|
5143
5224
|
for (const msgs of messagesByThread.values()) {
|
|
5144
5225
|
for (const msg of msgs) {
|
|
@@ -5965,7 +6046,10 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
5965
6046
|
ttlExpiredMs: activationMetadata?.ttlExpiredMs,
|
|
5966
6047
|
previousModel: activationMetadata?.previousModel,
|
|
5967
6048
|
currentModel: activationMetadata?.currentModel,
|
|
5968
|
-
config:
|
|
6049
|
+
config: {
|
|
6050
|
+
...this.getObservationMarkerConfig(freshRecord),
|
|
6051
|
+
activateAfterIdle: activationMetadata?.activateAfterIdle ?? this.reflectionConfig.activateAfterIdle
|
|
6052
|
+
}
|
|
5969
6053
|
});
|
|
5970
6054
|
void writer.custom({ ...activationMarker, transient: true }).catch(() => {
|
|
5971
6055
|
});
|
|
@@ -6028,7 +6112,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
6028
6112
|
);
|
|
6029
6113
|
}
|
|
6030
6114
|
}
|
|
6031
|
-
const activateAfterIdle = this.reflectionConfig.activateAfterIdle;
|
|
6115
|
+
const activateAfterIdle = resolveActivationTTL(this.reflectionConfig.activateAfterIdle, currentModel);
|
|
6032
6116
|
const ttlExpiredMs = activateAfterIdle !== void 0 && lastActivityAt !== void 0 ? Date.now() - lastActivityAt : void 0;
|
|
6033
6117
|
const ttlExpired = ttlExpiredMs !== void 0 && activateAfterIdle !== void 0 && ttlExpiredMs >= activateAfterIdle;
|
|
6034
6118
|
const actorModel = getCurrentModel(currentModel);
|
|
@@ -6041,6 +6125,7 @@ ${unreflectedContent}` : freshRecord.bufferedReflection;
|
|
|
6041
6125
|
const activationMetadata = {
|
|
6042
6126
|
triggeredBy: activationTriggeredBy,
|
|
6043
6127
|
lastActivityAt: activationTriggeredBy === "ttl" ? lastActivityAt : void 0,
|
|
6128
|
+
activateAfterIdle: activationTriggeredBy === "ttl" ? activateAfterIdle : void 0,
|
|
6044
6129
|
ttlExpiredMs: activationTriggeredBy === "ttl" ? ttlExpiredMs : void 0,
|
|
6045
6130
|
previousModel: activationTriggeredBy === "provider_change" ? lastModel : void 0,
|
|
6046
6131
|
currentModel: activationTriggeredBy === "provider_change" ? actorModel : void 0
|
|
@@ -7879,6 +7964,9 @@ function parseActivationTTL(value, fieldPath) {
|
|
|
7879
7964
|
if (value === void 0 || value === false) {
|
|
7880
7965
|
return void 0;
|
|
7881
7966
|
}
|
|
7967
|
+
if (value === "auto") {
|
|
7968
|
+
return value;
|
|
7969
|
+
}
|
|
7882
7970
|
if (typeof value === "number") {
|
|
7883
7971
|
if (!Number.isFinite(value) || value < 0) {
|
|
7884
7972
|
throw new Error(`${fieldPath} must be a non-negative number of milliseconds or a duration string like "5m".`);
|
|
@@ -8051,7 +8139,8 @@ Async buffering is enabled by default \u2014 this opt-out is only needed when us
|
|
|
8051
8139
|
),
|
|
8052
8140
|
previousObserverTokens: config.observation?.previousObserverTokens ?? 2e3,
|
|
8053
8141
|
instruction: config.observation?.instruction,
|
|
8054
|
-
threadTitle: config.observation?.threadTitle ?? false
|
|
8142
|
+
threadTitle: config.observation?.threadTitle ?? false,
|
|
8143
|
+
observeAttachments: config.observation?.observeAttachments ?? true
|
|
8055
8144
|
};
|
|
8056
8145
|
this.reflectionConfig = {
|
|
8057
8146
|
model: reflectionModel,
|
|
@@ -9974,6 +10063,7 @@ ${grouped}` : grouped;
|
|
|
9974
10063
|
}
|
|
9975
10064
|
let activationTriggeredBy = "threshold";
|
|
9976
10065
|
let activationLastActivityAt;
|
|
10066
|
+
let activationActivateAfterIdle;
|
|
9977
10067
|
let activateAfterIdleExpiredMs;
|
|
9978
10068
|
let previousModel;
|
|
9979
10069
|
let currentModel;
|
|
@@ -9983,7 +10073,7 @@ ${grouped}` : grouped;
|
|
|
9983
10073
|
resourceId,
|
|
9984
10074
|
record.lastObservedAt ? new Date(record.lastObservedAt) : void 0
|
|
9985
10075
|
);
|
|
9986
|
-
const activateAfterIdle = this.observationConfig.activateAfterIdle;
|
|
10076
|
+
const activateAfterIdle = resolveActivationTTL(this.observationConfig.activateAfterIdle, opts.currentModel);
|
|
9987
10077
|
const lastActivityAt = getLastActivityFromMessages(thresholdMessages);
|
|
9988
10078
|
const ttlExpiredMs = activateAfterIdle !== void 0 && lastActivityAt !== void 0 ? Date.now() - lastActivityAt : void 0;
|
|
9989
10079
|
const ttlExpired = ttlExpiredMs !== void 0 && activateAfterIdle !== void 0 && ttlExpiredMs >= activateAfterIdle;
|
|
@@ -9997,6 +10087,7 @@ ${grouped}` : grouped;
|
|
|
9997
10087
|
} else if (ttlExpired) {
|
|
9998
10088
|
activationTriggeredBy = "ttl";
|
|
9999
10089
|
activationLastActivityAt = lastActivityAt;
|
|
10090
|
+
activationActivateAfterIdle = activateAfterIdle;
|
|
10000
10091
|
activateAfterIdleExpiredMs = ttlExpiredMs;
|
|
10001
10092
|
} else {
|
|
10002
10093
|
const status = await this.getStatus({ threadId, resourceId, messages: thresholdMessages });
|
|
@@ -10065,7 +10156,10 @@ ${grouped}` : grouped;
|
|
|
10065
10156
|
ttlExpiredMs: activateAfterIdleExpiredMs,
|
|
10066
10157
|
previousModel,
|
|
10067
10158
|
currentModel,
|
|
10068
|
-
config:
|
|
10159
|
+
config: {
|
|
10160
|
+
...this.getObservationMarkerConfig(),
|
|
10161
|
+
activateAfterIdle: activationActivateAfterIdle ?? this.observationConfig.activateAfterIdle
|
|
10162
|
+
}
|
|
10069
10163
|
});
|
|
10070
10164
|
void opts.writer.custom({ ...activationMarker, transient: true }).catch(() => {
|
|
10071
10165
|
});
|
|
@@ -10520,7 +10614,7 @@ var ObservationalMemoryProcessor = class {
|
|
|
10520
10614
|
const { threadId, resourceId } = context;
|
|
10521
10615
|
const memoryContext = parseMemoryRequestContext(requestContext);
|
|
10522
10616
|
const readOnly = memoryContext?.memoryConfig?.readOnly;
|
|
10523
|
-
const actorModelContext = model?.modelId ? { provider: model.provider, modelId: model.modelId } : void 0;
|
|
10617
|
+
const actorModelContext = model?.modelId ? { provider: model.provider, modelId: model.modelId, providerOptions: args.providerOptions } : void 0;
|
|
10524
10618
|
state.__omActorModelContext = actorModelContext;
|
|
10525
10619
|
return this.engine.getTokenCounter().runWithModelContext(actorModelContext, async () => {
|
|
10526
10620
|
const reproCaptureEnabled = isOmReproCaptureEnabled();
|
|
@@ -10707,5 +10801,5 @@ function getObservationsAsOf(activeObservations, asOf) {
|
|
|
10707
10801
|
}
|
|
10708
10802
|
|
|
10709
10803
|
export { ModelByInputTokens, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, TokenCounter, buildObserverPrompt, buildObserverSystemPrompt, combineObservationGroupRanges, deriveObservationGroupProvenance, e, estimateTokenCount, extractCurrentTask, formatMessagesForObserver, formatToolResultForObserver, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, resolveToolResultValue, stripEphemeralAnchorIds, stripObservationGroups, truncateStringByTokens, wrapInObservationGroup };
|
|
10710
|
-
//# sourceMappingURL=chunk-
|
|
10711
|
-
//# sourceMappingURL=chunk-
|
|
10804
|
+
//# sourceMappingURL=chunk-ZJVB5TZ4.js.map
|
|
10805
|
+
//# sourceMappingURL=chunk-ZJVB5TZ4.js.map
|