@mastra/core 1.33.0-alpha.1 → 1.33.0-alpha.2
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/agent/agent.d.ts +11 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/durable/index.cjs +22 -22
- package/dist/agent/durable/index.js +4 -4
- package/dist/agent/index.cjs +9 -9
- package/dist/agent/index.js +1 -1
- package/dist/agent/workflows/prepare-stream/map-results-step.d.ts.map +1 -1
- package/dist/agent/workflows/prepare-stream/schema.d.ts +4 -0
- package/dist/agent/workflows/prepare-stream/schema.d.ts.map +1 -1
- package/dist/browser/index.cjs +2 -2
- package/dist/browser/index.js +1 -1
- package/dist/channels/index.cjs +4 -4
- package/dist/channels/index.js +1 -1
- package/dist/{chunk-7M65H4UA.js → chunk-7DU5ZEI7.js} +3 -3
- package/dist/{chunk-7M65H4UA.js.map → chunk-7DU5ZEI7.js.map} +1 -1
- package/dist/{chunk-GQDJFBVF.js → chunk-7L4SZOZX.js} +6 -6
- package/dist/{chunk-GQDJFBVF.js.map → chunk-7L4SZOZX.js.map} +1 -1
- package/dist/{chunk-C6M5HBBX.cjs → chunk-7UVX6QCQ.cjs} +57 -24
- package/dist/chunk-7UVX6QCQ.cjs.map +1 -0
- package/dist/{chunk-L4Q63LCX.js → chunk-BTELIKVV.js} +45 -12
- package/dist/chunk-BTELIKVV.js.map +1 -0
- package/dist/{chunk-VUY4QAW4.cjs → chunk-CBVQV2MC.cjs} +224 -224
- package/dist/{chunk-VUY4QAW4.cjs.map → chunk-CBVQV2MC.cjs.map} +1 -1
- package/dist/{chunk-PA73DY5B.cjs → chunk-DIXS2HEO.cjs} +394 -153
- package/dist/chunk-DIXS2HEO.cjs.map +1 -0
- package/dist/{chunk-3OIXD6QZ.js → chunk-DNMUSSVS.js} +3 -3
- package/dist/{chunk-3OIXD6QZ.js.map → chunk-DNMUSSVS.js.map} +1 -1
- package/dist/{chunk-CHGGDYI6.cjs → chunk-HKAOLV6C.cjs} +389 -389
- package/dist/{chunk-CHGGDYI6.cjs.map → chunk-HKAOLV6C.cjs.map} +1 -1
- package/dist/{chunk-PBD75KII.js → chunk-KKVJWLOG.js} +4 -4
- package/dist/{chunk-PBD75KII.js.map → chunk-KKVJWLOG.js.map} +1 -1
- package/dist/{chunk-OPMKAUNT.js → chunk-LI47CL4R.js} +3 -3
- package/dist/{chunk-OPMKAUNT.js.map → chunk-LI47CL4R.js.map} +1 -1
- package/dist/{chunk-IFWVHG2M.cjs → chunk-MA5KNDJ7.cjs} +59 -59
- package/dist/{chunk-IFWVHG2M.cjs.map → chunk-MA5KNDJ7.cjs.map} +1 -1
- package/dist/{chunk-5AFWTTES.js → chunk-N3FYHMZR.js} +4 -4
- package/dist/{chunk-5AFWTTES.js.map → chunk-N3FYHMZR.js.map} +1 -1
- package/dist/{chunk-JOA5YBHN.js → chunk-NM4SFK6O.js} +3 -3
- package/dist/{chunk-JOA5YBHN.js.map → chunk-NM4SFK6O.js.map} +1 -1
- package/dist/{chunk-GB2CQKRS.cjs → chunk-RLC5SIPH.cjs} +9 -9
- package/dist/{chunk-GB2CQKRS.cjs.map → chunk-RLC5SIPH.cjs.map} +1 -1
- package/dist/{chunk-2YN2GWML.cjs → chunk-RQY43SKV.cjs} +3 -3
- package/dist/{chunk-2YN2GWML.cjs.map → chunk-RQY43SKV.cjs.map} +1 -1
- package/dist/{chunk-YXEOBUUH.js → chunk-SP4J4UBB.js} +9 -9
- package/dist/{chunk-YXEOBUUH.js.map → chunk-SP4J4UBB.js.map} +1 -1
- package/dist/{chunk-UGRXTMCT.js → chunk-UFQBQAMW.js} +3 -3
- package/dist/{chunk-UGRXTMCT.js.map → chunk-UFQBQAMW.js.map} +1 -1
- package/dist/{chunk-5LXIX7FZ.js → chunk-VQ5BAIDK.js} +385 -145
- package/dist/chunk-VQ5BAIDK.js.map +1 -0
- package/dist/{chunk-BSC4D3AA.cjs → chunk-X4CVAUMI.cjs} +22 -22
- package/dist/{chunk-BSC4D3AA.cjs.map → chunk-X4CVAUMI.cjs.map} +1 -1
- package/dist/{chunk-GVVA4JRD.cjs → chunk-XHA64NGS.cjs} +5 -5
- package/dist/{chunk-GVVA4JRD.cjs.map → chunk-XHA64NGS.cjs.map} +1 -1
- package/dist/{chunk-KE7K677R.cjs → chunk-XWQANVQ2.cjs} +7 -7
- package/dist/{chunk-KE7K677R.cjs.map → chunk-XWQANVQ2.cjs.map} +1 -1
- package/dist/{chunk-QBT4WKAU.cjs → chunk-XWRGP5O4.cjs} +7 -7
- package/dist/{chunk-QBT4WKAU.cjs.map → chunk-XWRGP5O4.cjs.map} +1 -1
- package/dist/datasets/index.cjs +11 -11
- package/dist/datasets/index.js +1 -1
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +211 -207
- package/dist/docs/references/docs-agents-processors.md +26 -2
- package/dist/docs/references/reference-processors-processor-interface.md +74 -12
- package/dist/docs/references/reference-processors-provider-history-compat.md +132 -0
- package/dist/docs/references/reference.md +1 -0
- package/dist/evals/index.cjs +6 -6
- package/dist/evals/index.js +2 -2
- package/dist/evals/scoreTraces/index.cjs +3 -3
- package/dist/evals/scoreTraces/index.js +1 -1
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/index.cjs +27 -22
- package/dist/harness/index.cjs.map +1 -1
- package/dist/harness/index.js +25 -20
- package/dist/harness/index.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/llm/index.cjs +20 -20
- package/dist/llm/index.js +5 -5
- package/dist/llm/model/model.loop.d.ts +1 -1
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/llm/model/provider-types.generated.d.ts +14 -2
- package/dist/loop/index.cjs +14 -14
- package/dist/loop/index.js +1 -1
- package/dist/loop/types.d.ts +1 -0
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +1 -1
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/mastra-LYBVVAEM.js +3 -0
- package/dist/{mastra-TBJEDBDE.js.map → mastra-LYBVVAEM.js.map} +1 -1
- package/dist/mastra-SAWYVVAO.cjs +12 -0
- package/dist/{mastra-XZZ5PGRE.cjs.map → mastra-SAWYVVAO.cjs.map} +1 -1
- package/dist/memory/index.cjs +19 -19
- package/dist/memory/index.js +1 -1
- package/dist/models-dev-GR4H4HSO.js +3 -0
- package/dist/{models-dev-NBPBZGNU.js.map → models-dev-GR4H4HSO.js.map} +1 -1
- package/dist/models-dev-S7CNVODQ.cjs +12 -0
- package/dist/{models-dev-VYQYBTPH.cjs.map → models-dev-S7CNVODQ.cjs.map} +1 -1
- package/dist/netlify-SHROXKV7.cjs +12 -0
- package/dist/{netlify-B4ALATN2.cjs.map → netlify-SHROXKV7.cjs.map} +1 -1
- package/dist/netlify-TR7QGCG5.js +3 -0
- package/dist/{netlify-AHTOWHQ3.js.map → netlify-TR7QGCG5.js.map} +1 -1
- package/dist/processor-provider/index.cjs +10 -10
- package/dist/processor-provider/index.js +1 -1
- package/dist/processors/index.cjs +55 -51
- package/dist/processors/index.d.ts +51 -3
- package/dist/processors/index.d.ts.map +1 -1
- package/dist/processors/index.js +1 -1
- package/dist/processors/provider-history-compat.d.ts +97 -17
- package/dist/processors/provider-history-compat.d.ts.map +1 -1
- package/dist/processors/runner.d.ts +23 -0
- package/dist/processors/runner.d.ts.map +1 -1
- package/dist/provider-registry-MCPX3HYB.cjs +44 -0
- package/dist/{provider-registry-5MSQZY5O.cjs.map → provider-registry-MCPX3HYB.cjs.map} +1 -1
- package/dist/provider-registry-NDEFG4LF.js +3 -0
- package/dist/{provider-registry-GPH6SHFV.js.map → provider-registry-NDEFG4LF.js.map} +1 -1
- package/dist/provider-registry.json +37 -4
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/runner-OTR5L3EM.js +3 -0
- package/dist/{runner-LF2L47BX.js.map → runner-OTR5L3EM.js.map} +1 -1
- package/dist/runner-YBVW5BC2.cjs +16 -0
- package/dist/{runner-HODGJLIH.cjs.map → runner-YBVW5BC2.cjs.map} +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +1 -1
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/index.cjs +28 -28
- package/dist/workflows/index.js +1 -1
- package/package.json +5 -5
- package/src/llm/model/provider-types.generated.d.ts +14 -2
- package/dist/chunk-5LXIX7FZ.js.map +0 -1
- package/dist/chunk-C6M5HBBX.cjs.map +0 -1
- package/dist/chunk-L4Q63LCX.js.map +0 -1
- package/dist/chunk-PA73DY5B.cjs.map +0 -1
- package/dist/mastra-TBJEDBDE.js +0 -3
- package/dist/mastra-XZZ5PGRE.cjs +0 -12
- package/dist/models-dev-NBPBZGNU.js +0 -3
- package/dist/models-dev-VYQYBTPH.cjs +0 -12
- package/dist/netlify-AHTOWHQ3.js +0 -3
- package/dist/netlify-B4ALATN2.cjs +0 -12
- package/dist/provider-registry-5MSQZY5O.cjs +0 -44
- package/dist/provider-registry-GPH6SHFV.js +0 -3
- package/dist/runner-HODGJLIH.cjs +0 -16
- package/dist/runner-LF2L47BX.js +0 -3
|
@@ -11,7 +11,7 @@ var chunkQPFIMRQM_cjs = require('./chunk-QPFIMRQM.cjs');
|
|
|
11
11
|
var chunkSQXMPXUI_cjs = require('./chunk-SQXMPXUI.cjs');
|
|
12
12
|
var chunkHM6XXOV2_cjs = require('./chunk-HM6XXOV2.cjs');
|
|
13
13
|
var chunkMR7ZWBL6_cjs = require('./chunk-MR7ZWBL6.cjs');
|
|
14
|
-
var
|
|
14
|
+
var chunkHKAOLV6C_cjs = require('./chunk-HKAOLV6C.cjs');
|
|
15
15
|
var chunkY73X6U5P_cjs = require('./chunk-Y73X6U5P.cjs');
|
|
16
16
|
var chunkAX6D722J_cjs = require('./chunk-AX6D722J.cjs');
|
|
17
17
|
var chunkCDN65CUN_cjs = require('./chunk-CDN65CUN.cjs');
|
|
@@ -4622,107 +4622,6 @@ var PrefillErrorHandler = class {
|
|
|
4622
4622
|
}
|
|
4623
4623
|
};
|
|
4624
4624
|
|
|
4625
|
-
// src/processors/stream-error-retry-processor.ts
|
|
4626
|
-
var DEFAULT_MAX_RETRIES = 1;
|
|
4627
|
-
var RETRYABLE_OPENAI_ERROR_CODES = [
|
|
4628
|
-
"rate_limit",
|
|
4629
|
-
"server_error",
|
|
4630
|
-
"internal_error",
|
|
4631
|
-
"timeout",
|
|
4632
|
-
"temporarily_unavailable",
|
|
4633
|
-
"service_unavailable",
|
|
4634
|
-
"overloaded"
|
|
4635
|
-
];
|
|
4636
|
-
var OPENAI_RETRY_MESSAGE_PATTERN = /you can retry your request/i;
|
|
4637
|
-
var DEFAULT_MATCHERS = [isRetryableOpenAIResponsesStreamError];
|
|
4638
|
-
function isRecord2(value) {
|
|
4639
|
-
return typeof value === "object" && value !== null;
|
|
4640
|
-
}
|
|
4641
|
-
function getStringProperty(value, key) {
|
|
4642
|
-
const property = value[key];
|
|
4643
|
-
return typeof property === "string" ? property : void 0;
|
|
4644
|
-
}
|
|
4645
|
-
function getObjectCause(error) {
|
|
4646
|
-
if (error instanceof Error) {
|
|
4647
|
-
return error.cause;
|
|
4648
|
-
}
|
|
4649
|
-
if (!isRecord2(error)) {
|
|
4650
|
-
return void 0;
|
|
4651
|
-
}
|
|
4652
|
-
return error.cause;
|
|
4653
|
-
}
|
|
4654
|
-
function getOpenAIErrorPayload(error) {
|
|
4655
|
-
if (!isRecord2(error)) {
|
|
4656
|
-
return void 0;
|
|
4657
|
-
}
|
|
4658
|
-
if (error.type === "error" && isRecord2(error.error)) {
|
|
4659
|
-
return error.error;
|
|
4660
|
-
}
|
|
4661
|
-
if (error.type === "response.failed" && isRecord2(error.response)) {
|
|
4662
|
-
const responseError = error.response.error;
|
|
4663
|
-
return isRecord2(responseError) ? responseError : void 0;
|
|
4664
|
-
}
|
|
4665
|
-
return void 0;
|
|
4666
|
-
}
|
|
4667
|
-
function hasRetryableOpenAIErrorCode(payload) {
|
|
4668
|
-
const code = getStringProperty(payload, "code") ?? getStringProperty(payload, "type");
|
|
4669
|
-
if (!code) {
|
|
4670
|
-
return false;
|
|
4671
|
-
}
|
|
4672
|
-
const normalizedCode = code.toLowerCase();
|
|
4673
|
-
return RETRYABLE_OPENAI_ERROR_CODES.some((retryableCode) => normalizedCode.includes(retryableCode));
|
|
4674
|
-
}
|
|
4675
|
-
function hasExplicitRetryMessage(payload) {
|
|
4676
|
-
const message = getStringProperty(payload, "message");
|
|
4677
|
-
return message !== void 0 && OPENAI_RETRY_MESSAGE_PATTERN.test(message);
|
|
4678
|
-
}
|
|
4679
|
-
function isRetryableOpenAIResponsesStreamError(error) {
|
|
4680
|
-
const payload = getOpenAIErrorPayload(error);
|
|
4681
|
-
if (!payload) {
|
|
4682
|
-
return false;
|
|
4683
|
-
}
|
|
4684
|
-
return hasRetryableOpenAIErrorCode(payload) || hasExplicitRetryMessage(payload);
|
|
4685
|
-
}
|
|
4686
|
-
function isRetryableProviderMetadata(error) {
|
|
4687
|
-
const retryable = chunkQPFIMRQM_cjs.APICallError.isInstance(error) ? error.isRetryable : isRecord2(error) && typeof error.isRetryable === "boolean" ? error.isRetryable : void 0;
|
|
4688
|
-
return retryable === true;
|
|
4689
|
-
}
|
|
4690
|
-
function isRetryableStreamError(error, matchers) {
|
|
4691
|
-
const visited = /* @__PURE__ */ new WeakSet();
|
|
4692
|
-
function visit(candidate) {
|
|
4693
|
-
if (isRecord2(candidate)) {
|
|
4694
|
-
if (visited.has(candidate)) {
|
|
4695
|
-
return false;
|
|
4696
|
-
}
|
|
4697
|
-
visited.add(candidate);
|
|
4698
|
-
}
|
|
4699
|
-
if (isRetryableProviderMetadata(candidate)) {
|
|
4700
|
-
return true;
|
|
4701
|
-
}
|
|
4702
|
-
if (matchers.some((matcher) => matcher(candidate))) {
|
|
4703
|
-
return true;
|
|
4704
|
-
}
|
|
4705
|
-
const cause = getObjectCause(candidate);
|
|
4706
|
-
return cause !== void 0 && visit(cause);
|
|
4707
|
-
}
|
|
4708
|
-
return visit(error);
|
|
4709
|
-
}
|
|
4710
|
-
var StreamErrorRetryProcessor = class {
|
|
4711
|
-
id = "stream-error-retry-processor";
|
|
4712
|
-
name = "Stream Error Retry Processor";
|
|
4713
|
-
#maxRetries;
|
|
4714
|
-
#matchers;
|
|
4715
|
-
constructor(options = {}) {
|
|
4716
|
-
this.#maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
4717
|
-
this.#matchers = [...DEFAULT_MATCHERS, ...options.matchers ?? []];
|
|
4718
|
-
}
|
|
4719
|
-
async processAPIError({ error, retryCount }) {
|
|
4720
|
-
if (retryCount >= this.#maxRetries) return;
|
|
4721
|
-
if (!isRetryableStreamError(error, this.#matchers)) return;
|
|
4722
|
-
return { retry: true };
|
|
4723
|
-
}
|
|
4724
|
-
};
|
|
4725
|
-
|
|
4726
4625
|
// src/processors/provider-history-compat.ts
|
|
4727
4626
|
function getErrorCandidates2(error) {
|
|
4728
4627
|
const candidates = [error.message];
|
|
@@ -4732,6 +4631,7 @@ function getErrorCandidates2(error) {
|
|
|
4732
4631
|
return candidates.filter(Boolean);
|
|
4733
4632
|
}
|
|
4734
4633
|
function matchesRule(error, rule) {
|
|
4634
|
+
if (!rule.errorPatterns?.length) return false;
|
|
4735
4635
|
const matches = (text) => rule.errorPatterns.some((p) => p.test(text));
|
|
4736
4636
|
if (chunkQPFIMRQM_cjs.APICallError.isInstance(error)) {
|
|
4737
4637
|
return getErrorCandidates2(error).some(matches);
|
|
@@ -4805,7 +4705,69 @@ var anthropicToolIdFormat = {
|
|
|
4805
4705
|
return true;
|
|
4806
4706
|
}
|
|
4807
4707
|
};
|
|
4808
|
-
|
|
4708
|
+
function matchesProviderPrefix(model, providerPrefix) {
|
|
4709
|
+
if (model == null) return false;
|
|
4710
|
+
if (typeof model === "function") return false;
|
|
4711
|
+
if (Array.isArray(model)) {
|
|
4712
|
+
return model.some((m) => matchesProviderPrefix(m.model ?? m, providerPrefix));
|
|
4713
|
+
}
|
|
4714
|
+
const gatewayPattern = new RegExp(`^${providerPrefix}[/:]`, "i");
|
|
4715
|
+
const providerPattern = new RegExp(`^${providerPrefix}($|[.\\-])`, "i");
|
|
4716
|
+
if (typeof model === "string") {
|
|
4717
|
+
return gatewayPattern.test(model);
|
|
4718
|
+
}
|
|
4719
|
+
if (typeof model === "object") {
|
|
4720
|
+
const { provider, modelId } = model;
|
|
4721
|
+
if (typeof provider === "string" && providerPattern.test(provider)) return true;
|
|
4722
|
+
if (typeof modelId === "string") return gatewayPattern.test(modelId);
|
|
4723
|
+
}
|
|
4724
|
+
return false;
|
|
4725
|
+
}
|
|
4726
|
+
function isMaybeCerebras(model) {
|
|
4727
|
+
return matchesProviderPrefix(model, "cerebras");
|
|
4728
|
+
}
|
|
4729
|
+
function isMaybeAnthropic(model) {
|
|
4730
|
+
return matchesProviderPrefix(model, "anthropic");
|
|
4731
|
+
}
|
|
4732
|
+
function stripReasoningFromPrompt(prompt, shouldStrip = () => true) {
|
|
4733
|
+
let mutated = false;
|
|
4734
|
+
const next = prompt.map((message) => {
|
|
4735
|
+
if (message.role !== "assistant") return message;
|
|
4736
|
+
if (typeof message.content === "string") return message;
|
|
4737
|
+
if (!Array.isArray(message.content)) return message;
|
|
4738
|
+
const filtered = message.content.filter((part) => part.type !== "reasoning" || !shouldStrip(part));
|
|
4739
|
+
if (filtered.length === message.content.length) return message;
|
|
4740
|
+
mutated = true;
|
|
4741
|
+
return { ...message, content: filtered };
|
|
4742
|
+
});
|
|
4743
|
+
return mutated ? next : void 0;
|
|
4744
|
+
}
|
|
4745
|
+
function isAnthropicReasoningPart(part) {
|
|
4746
|
+
const providerOptions = part.providerOptions;
|
|
4747
|
+
if (providerOptions && typeof providerOptions === "object" && "anthropic" in providerOptions) return true;
|
|
4748
|
+
const providerMetadata = part.providerMetadata;
|
|
4749
|
+
if (providerMetadata && typeof providerMetadata === "object" && "anthropic" in providerMetadata) return true;
|
|
4750
|
+
return false;
|
|
4751
|
+
}
|
|
4752
|
+
var cerebrasStripReasoningContent = {
|
|
4753
|
+
name: "cerebras-strip-reasoning-content",
|
|
4754
|
+
applyToPrompt({ prompt, model }) {
|
|
4755
|
+
if (!isMaybeCerebras(model)) return void 0;
|
|
4756
|
+
return stripReasoningFromPrompt(prompt);
|
|
4757
|
+
}
|
|
4758
|
+
};
|
|
4759
|
+
var anthropicStripForeignReasoningContent = {
|
|
4760
|
+
name: "anthropic-strip-foreign-reasoning-content",
|
|
4761
|
+
applyToPrompt({ prompt, model }) {
|
|
4762
|
+
if (!isMaybeAnthropic(model)) return void 0;
|
|
4763
|
+
return stripReasoningFromPrompt(prompt, (part) => !isAnthropicReasoningPart(part));
|
|
4764
|
+
}
|
|
4765
|
+
};
|
|
4766
|
+
var DEFAULT_COMPAT_RULES = [
|
|
4767
|
+
anthropicToolIdFormat,
|
|
4768
|
+
cerebrasStripReasoningContent,
|
|
4769
|
+
anthropicStripForeignReasoningContent
|
|
4770
|
+
];
|
|
4809
4771
|
var ProviderHistoryCompat = class {
|
|
4810
4772
|
id = "provider-history-compat";
|
|
4811
4773
|
name = "Provider History Compat";
|
|
@@ -4813,6 +4775,19 @@ var ProviderHistoryCompat = class {
|
|
|
4813
4775
|
constructor(opts) {
|
|
4814
4776
|
this.rules = [...DEFAULT_COMPAT_RULES, ...opts?.additionalRules ?? []];
|
|
4815
4777
|
}
|
|
4778
|
+
processLLMRequest({ prompt, model }) {
|
|
4779
|
+
let current = prompt;
|
|
4780
|
+
let mutated = false;
|
|
4781
|
+
for (const rule of this.rules) {
|
|
4782
|
+
if (!rule.applyToPrompt) continue;
|
|
4783
|
+
const next = rule.applyToPrompt({ prompt: current, model });
|
|
4784
|
+
if (next) {
|
|
4785
|
+
current = next;
|
|
4786
|
+
mutated = true;
|
|
4787
|
+
}
|
|
4788
|
+
}
|
|
4789
|
+
return mutated ? { prompt: current } : void 0;
|
|
4790
|
+
}
|
|
4816
4791
|
async processAPIError({
|
|
4817
4792
|
error,
|
|
4818
4793
|
messageList,
|
|
@@ -4821,6 +4796,7 @@ var ProviderHistoryCompat = class {
|
|
|
4821
4796
|
if (retryCount > 0) return;
|
|
4822
4797
|
const messages = messageList.get.all.db();
|
|
4823
4798
|
for (const rule of this.rules) {
|
|
4799
|
+
if (!rule.fix) continue;
|
|
4824
4800
|
if (matchesRule(error, rule)) {
|
|
4825
4801
|
const changed = rule.fix(messages);
|
|
4826
4802
|
if (changed) {
|
|
@@ -4831,6 +4807,107 @@ var ProviderHistoryCompat = class {
|
|
|
4831
4807
|
}
|
|
4832
4808
|
};
|
|
4833
4809
|
|
|
4810
|
+
// src/processors/stream-error-retry-processor.ts
|
|
4811
|
+
var DEFAULT_MAX_RETRIES = 1;
|
|
4812
|
+
var RETRYABLE_OPENAI_ERROR_CODES = [
|
|
4813
|
+
"rate_limit",
|
|
4814
|
+
"server_error",
|
|
4815
|
+
"internal_error",
|
|
4816
|
+
"timeout",
|
|
4817
|
+
"temporarily_unavailable",
|
|
4818
|
+
"service_unavailable",
|
|
4819
|
+
"overloaded"
|
|
4820
|
+
];
|
|
4821
|
+
var OPENAI_RETRY_MESSAGE_PATTERN = /you can retry your request/i;
|
|
4822
|
+
var DEFAULT_MATCHERS = [isRetryableOpenAIResponsesStreamError];
|
|
4823
|
+
function isRecord2(value) {
|
|
4824
|
+
return typeof value === "object" && value !== null;
|
|
4825
|
+
}
|
|
4826
|
+
function getStringProperty(value, key) {
|
|
4827
|
+
const property = value[key];
|
|
4828
|
+
return typeof property === "string" ? property : void 0;
|
|
4829
|
+
}
|
|
4830
|
+
function getObjectCause(error) {
|
|
4831
|
+
if (error instanceof Error) {
|
|
4832
|
+
return error.cause;
|
|
4833
|
+
}
|
|
4834
|
+
if (!isRecord2(error)) {
|
|
4835
|
+
return void 0;
|
|
4836
|
+
}
|
|
4837
|
+
return error.cause;
|
|
4838
|
+
}
|
|
4839
|
+
function getOpenAIErrorPayload(error) {
|
|
4840
|
+
if (!isRecord2(error)) {
|
|
4841
|
+
return void 0;
|
|
4842
|
+
}
|
|
4843
|
+
if (error.type === "error" && isRecord2(error.error)) {
|
|
4844
|
+
return error.error;
|
|
4845
|
+
}
|
|
4846
|
+
if (error.type === "response.failed" && isRecord2(error.response)) {
|
|
4847
|
+
const responseError = error.response.error;
|
|
4848
|
+
return isRecord2(responseError) ? responseError : void 0;
|
|
4849
|
+
}
|
|
4850
|
+
return void 0;
|
|
4851
|
+
}
|
|
4852
|
+
function hasRetryableOpenAIErrorCode(payload) {
|
|
4853
|
+
const code = getStringProperty(payload, "code") ?? getStringProperty(payload, "type");
|
|
4854
|
+
if (!code) {
|
|
4855
|
+
return false;
|
|
4856
|
+
}
|
|
4857
|
+
const normalizedCode = code.toLowerCase();
|
|
4858
|
+
return RETRYABLE_OPENAI_ERROR_CODES.some((retryableCode) => normalizedCode.includes(retryableCode));
|
|
4859
|
+
}
|
|
4860
|
+
function hasExplicitRetryMessage(payload) {
|
|
4861
|
+
const message = getStringProperty(payload, "message");
|
|
4862
|
+
return message !== void 0 && OPENAI_RETRY_MESSAGE_PATTERN.test(message);
|
|
4863
|
+
}
|
|
4864
|
+
function isRetryableOpenAIResponsesStreamError(error) {
|
|
4865
|
+
const payload = getOpenAIErrorPayload(error);
|
|
4866
|
+
if (!payload) {
|
|
4867
|
+
return false;
|
|
4868
|
+
}
|
|
4869
|
+
return hasRetryableOpenAIErrorCode(payload) || hasExplicitRetryMessage(payload);
|
|
4870
|
+
}
|
|
4871
|
+
function isRetryableProviderMetadata(error) {
|
|
4872
|
+
const retryable = chunkQPFIMRQM_cjs.APICallError.isInstance(error) ? error.isRetryable : isRecord2(error) && typeof error.isRetryable === "boolean" ? error.isRetryable : void 0;
|
|
4873
|
+
return retryable === true;
|
|
4874
|
+
}
|
|
4875
|
+
function isRetryableStreamError(error, matchers) {
|
|
4876
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
4877
|
+
function visit(candidate) {
|
|
4878
|
+
if (isRecord2(candidate)) {
|
|
4879
|
+
if (visited.has(candidate)) {
|
|
4880
|
+
return false;
|
|
4881
|
+
}
|
|
4882
|
+
visited.add(candidate);
|
|
4883
|
+
}
|
|
4884
|
+
if (isRetryableProviderMetadata(candidate)) {
|
|
4885
|
+
return true;
|
|
4886
|
+
}
|
|
4887
|
+
if (matchers.some((matcher) => matcher(candidate))) {
|
|
4888
|
+
return true;
|
|
4889
|
+
}
|
|
4890
|
+
const cause = getObjectCause(candidate);
|
|
4891
|
+
return cause !== void 0 && visit(cause);
|
|
4892
|
+
}
|
|
4893
|
+
return visit(error);
|
|
4894
|
+
}
|
|
4895
|
+
var StreamErrorRetryProcessor = class {
|
|
4896
|
+
id = "stream-error-retry-processor";
|
|
4897
|
+
name = "Stream Error Retry Processor";
|
|
4898
|
+
#maxRetries;
|
|
4899
|
+
#matchers;
|
|
4900
|
+
constructor(options = {}) {
|
|
4901
|
+
this.#maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
4902
|
+
this.#matchers = [...DEFAULT_MATCHERS, ...options.matchers ?? []];
|
|
4903
|
+
}
|
|
4904
|
+
async processAPIError({ error, retryCount }) {
|
|
4905
|
+
if (retryCount >= this.#maxRetries) return;
|
|
4906
|
+
if (!isRetryableStreamError(error, this.#matchers)) return;
|
|
4907
|
+
return { retry: true };
|
|
4908
|
+
}
|
|
4909
|
+
};
|
|
4910
|
+
|
|
4834
4911
|
// src/memory/types.ts
|
|
4835
4912
|
function isPlainObject(value) {
|
|
4836
4913
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -5063,7 +5140,7 @@ https://mastra.ai/en/docs/memory/semantic-recall`
|
|
|
5063
5140
|
);
|
|
5064
5141
|
}
|
|
5065
5142
|
if (typeof config.embedder === "string") {
|
|
5066
|
-
this.embedder = new
|
|
5143
|
+
this.embedder = new chunkHKAOLV6C_cjs.ModelRouterEmbeddingModel(config.embedder);
|
|
5067
5144
|
} else {
|
|
5068
5145
|
this.embedder = config.embedder;
|
|
5069
5146
|
}
|
|
@@ -5076,7 +5153,7 @@ https://mastra.ai/en/docs/memory/semantic-recall`
|
|
|
5076
5153
|
}
|
|
5077
5154
|
if (config.embedder) {
|
|
5078
5155
|
if (typeof config.embedder === "string") {
|
|
5079
|
-
this.embedder = new
|
|
5156
|
+
this.embedder = new chunkHKAOLV6C_cjs.ModelRouterEmbeddingModel(config.embedder);
|
|
5080
5157
|
} else {
|
|
5081
5158
|
this.embedder = config.embedder;
|
|
5082
5159
|
}
|
|
@@ -5116,7 +5193,7 @@ https://mastra.ai/en/docs/memory/overview`
|
|
|
5116
5193
|
}
|
|
5117
5194
|
setEmbedder(embedder, embedderOptions) {
|
|
5118
5195
|
if (typeof embedder === "string") {
|
|
5119
|
-
this.embedder = new
|
|
5196
|
+
this.embedder = new chunkHKAOLV6C_cjs.ModelRouterEmbeddingModel(embedder);
|
|
5120
5197
|
} else {
|
|
5121
5198
|
this.embedder = embedder;
|
|
5122
5199
|
}
|
|
@@ -6874,7 +6951,7 @@ var BaseProcessor = class {
|
|
|
6874
6951
|
};
|
|
6875
6952
|
function isProcessorWorkflow(obj) {
|
|
6876
6953
|
return obj !== null && typeof obj === "object" && "id" in obj && typeof obj.id === "string" && "inputSchema" in obj && "outputSchema" in obj && "execute" in obj && typeof obj.execute === "function" && // Must NOT have processor-specific methods (to distinguish from Processor)
|
|
6877
|
-
!("processInput" in obj) && !("processInputStep" in obj) && !("processOutputStream" in obj) && !("processOutputResult" in obj) && !("processOutputStep" in obj) && !("processAPIError" in obj);
|
|
6954
|
+
!("processInput" in obj) && !("processInputStep" in obj) && !("processOutputStream" in obj) && !("processOutputResult" in obj) && !("processOutputStep" in obj) && !("processLLMRequest" in obj) && !("processAPIError" in obj);
|
|
6878
6955
|
}
|
|
6879
6956
|
|
|
6880
6957
|
// src/channels/chat-lazy.ts
|
|
@@ -15884,7 +15961,7 @@ var MastraScorer = class _MastraScorer {
|
|
|
15884
15961
|
}
|
|
15885
15962
|
});
|
|
15886
15963
|
}
|
|
15887
|
-
const resolvedModel = await
|
|
15964
|
+
const resolvedModel = await chunkHKAOLV6C_cjs.resolveModelConfig(modelConfig, void 0, this.#mastra);
|
|
15888
15965
|
const judgeModel = resolvedModel.modelId;
|
|
15889
15966
|
const judge = new Agent({
|
|
15890
15967
|
id: "judge",
|
|
@@ -17783,6 +17860,24 @@ function updateToolCallForeachConcurrency(options, args) {
|
|
|
17783
17860
|
}
|
|
17784
17861
|
|
|
17785
17862
|
// src/loop/workflows/agentic-execution/llm-execution-step.ts
|
|
17863
|
+
function getRequestInputProcessors({
|
|
17864
|
+
inputProcessors,
|
|
17865
|
+
llmRequestInputProcessors
|
|
17866
|
+
}) {
|
|
17867
|
+
if (!llmRequestInputProcessors?.length) {
|
|
17868
|
+
return inputProcessors || [];
|
|
17869
|
+
}
|
|
17870
|
+
if (!inputProcessors?.length) {
|
|
17871
|
+
return llmRequestInputProcessors;
|
|
17872
|
+
}
|
|
17873
|
+
const requestProcessorIds = new Set(
|
|
17874
|
+
llmRequestInputProcessors.filter((processor) => !isProcessorWorkflow(processor)).map((processor) => processor.id)
|
|
17875
|
+
);
|
|
17876
|
+
const additionalInputProcessors = inputProcessors.filter(
|
|
17877
|
+
(processor) => !isProcessorWorkflow(processor) && !requestProcessorIds.has(processor.id)
|
|
17878
|
+
);
|
|
17879
|
+
return additionalInputProcessors.length ? [...llmRequestInputProcessors, ...additionalInputProcessors] : llmRequestInputProcessors;
|
|
17880
|
+
}
|
|
17786
17881
|
function buildResponseModelMetadata(runState, model) {
|
|
17787
17882
|
const metadata = {};
|
|
17788
17883
|
const modelId = model?.modelId ?? runState.state.responseMetadata?.modelId;
|
|
@@ -17794,6 +17889,54 @@ function buildResponseModelMetadata(runState, model) {
|
|
|
17794
17889
|
}
|
|
17795
17890
|
return Object.keys(metadata).length > 0 ? { metadata } : void 0;
|
|
17796
17891
|
}
|
|
17892
|
+
function buildTripWireBailResponse({
|
|
17893
|
+
error,
|
|
17894
|
+
controller,
|
|
17895
|
+
runId,
|
|
17896
|
+
model,
|
|
17897
|
+
messageList,
|
|
17898
|
+
messageId,
|
|
17899
|
+
stepTools,
|
|
17900
|
+
_internal
|
|
17901
|
+
}) {
|
|
17902
|
+
const tripwireChunk = {
|
|
17903
|
+
type: "tripwire",
|
|
17904
|
+
runId,
|
|
17905
|
+
from: "AGENT" /* AGENT */,
|
|
17906
|
+
payload: {
|
|
17907
|
+
reason: error.message,
|
|
17908
|
+
retry: error.options?.retry,
|
|
17909
|
+
metadata: error.options?.metadata,
|
|
17910
|
+
processorId: error.processorId
|
|
17911
|
+
}
|
|
17912
|
+
};
|
|
17913
|
+
safeEnqueue(controller, tripwireChunk);
|
|
17914
|
+
const runState = new AgenticRunState({
|
|
17915
|
+
_internal,
|
|
17916
|
+
model
|
|
17917
|
+
});
|
|
17918
|
+
return {
|
|
17919
|
+
callBail: true,
|
|
17920
|
+
outputStream: new MastraModelOutput({
|
|
17921
|
+
model: {
|
|
17922
|
+
modelId: model.modelId,
|
|
17923
|
+
provider: model.provider,
|
|
17924
|
+
version: model.specificationVersion
|
|
17925
|
+
},
|
|
17926
|
+
stream: new web.ReadableStream({
|
|
17927
|
+
start(c) {
|
|
17928
|
+
c.enqueue(tripwireChunk);
|
|
17929
|
+
c.close();
|
|
17930
|
+
}
|
|
17931
|
+
}),
|
|
17932
|
+
messageList,
|
|
17933
|
+
messageId,
|
|
17934
|
+
options: { runId }
|
|
17935
|
+
}),
|
|
17936
|
+
runState,
|
|
17937
|
+
stepTools
|
|
17938
|
+
};
|
|
17939
|
+
}
|
|
17797
17940
|
async function processOutputStream({
|
|
17798
17941
|
tools,
|
|
17799
17942
|
messageId,
|
|
@@ -18000,6 +18143,7 @@ function createLLMExecutionStep({
|
|
|
18000
18143
|
structuredOutput,
|
|
18001
18144
|
outputProcessors,
|
|
18002
18145
|
inputProcessors,
|
|
18146
|
+
llmRequestInputProcessors,
|
|
18003
18147
|
errorProcessors,
|
|
18004
18148
|
logger,
|
|
18005
18149
|
agentId,
|
|
@@ -18178,41 +18322,16 @@ function createLLMExecutionStep({
|
|
|
18178
18322
|
processorId: error.processorId,
|
|
18179
18323
|
retry: error.options?.retry
|
|
18180
18324
|
});
|
|
18181
|
-
|
|
18182
|
-
|
|
18325
|
+
return buildTripWireBailResponse({
|
|
18326
|
+
error,
|
|
18327
|
+
controller,
|
|
18183
18328
|
runId,
|
|
18184
|
-
|
|
18185
|
-
|
|
18186
|
-
|
|
18187
|
-
|
|
18188
|
-
|
|
18189
|
-
processorId: error.processorId
|
|
18190
|
-
}
|
|
18191
|
-
});
|
|
18192
|
-
const runState3 = new AgenticRunState({
|
|
18193
|
-
_internal,
|
|
18194
|
-
model
|
|
18329
|
+
model,
|
|
18330
|
+
messageList,
|
|
18331
|
+
messageId: currentStep.messageId,
|
|
18332
|
+
stepTools: tools,
|
|
18333
|
+
_internal
|
|
18195
18334
|
});
|
|
18196
|
-
return {
|
|
18197
|
-
callBail: true,
|
|
18198
|
-
outputStream: new MastraModelOutput({
|
|
18199
|
-
model: {
|
|
18200
|
-
modelId: model.modelId,
|
|
18201
|
-
provider: model.provider,
|
|
18202
|
-
version: model.specificationVersion
|
|
18203
|
-
},
|
|
18204
|
-
stream: new web.ReadableStream({
|
|
18205
|
-
start(c) {
|
|
18206
|
-
c.close();
|
|
18207
|
-
}
|
|
18208
|
-
}),
|
|
18209
|
-
messageList,
|
|
18210
|
-
messageId: currentStep.messageId,
|
|
18211
|
-
options: { runId }
|
|
18212
|
-
}),
|
|
18213
|
-
runState: runState3,
|
|
18214
|
-
stepTools: tools
|
|
18215
|
-
};
|
|
18216
18335
|
}
|
|
18217
18336
|
logger?.error("Error in processInputStep processors:", error);
|
|
18218
18337
|
throw error;
|
|
@@ -18309,6 +18428,52 @@ ${bgPrompt}`;
|
|
|
18309
18428
|
return message;
|
|
18310
18429
|
});
|
|
18311
18430
|
}
|
|
18431
|
+
{
|
|
18432
|
+
const requestStepRunner = new ProcessorRunner({
|
|
18433
|
+
inputProcessors: getRequestInputProcessors({ inputProcessors, llmRequestInputProcessors }),
|
|
18434
|
+
outputProcessors: [],
|
|
18435
|
+
logger: logger || new chunk7GW2TQXP_cjs.ConsoleLogger({ level: "error" }),
|
|
18436
|
+
agentName: agentId || "unknown",
|
|
18437
|
+
processorStates
|
|
18438
|
+
});
|
|
18439
|
+
const requestStepWriter = outputWriter ? {
|
|
18440
|
+
custom: async (data, options2) => outputWriter(data, { ...options2, messageId: currentStep.messageId })
|
|
18441
|
+
} : void 0;
|
|
18442
|
+
try {
|
|
18443
|
+
const requestStepResult = await requestStepRunner.runProcessLLMRequest({
|
|
18444
|
+
prompt: inputMessages,
|
|
18445
|
+
model: currentStep.model,
|
|
18446
|
+
stepNumber: inputData.output?.steps?.length || 0,
|
|
18447
|
+
steps: inputData.output?.steps || [],
|
|
18448
|
+
retryCount: inputData.processorRetryCount || 0,
|
|
18449
|
+
requestContext,
|
|
18450
|
+
tracingContext: modelSpanTracker?.getTracingContext() ?? tracingContext,
|
|
18451
|
+
writer: requestStepWriter,
|
|
18452
|
+
abortSignal: options?.abortSignal
|
|
18453
|
+
});
|
|
18454
|
+
inputMessages = requestStepResult.prompt;
|
|
18455
|
+
} catch (error) {
|
|
18456
|
+
if (error instanceof TripWire) {
|
|
18457
|
+
logger?.warn("Streaming request processor tripwire triggered", {
|
|
18458
|
+
reason: error.message,
|
|
18459
|
+
processorId: error.processorId,
|
|
18460
|
+
retry: error.options?.retry
|
|
18461
|
+
});
|
|
18462
|
+
return buildTripWireBailResponse({
|
|
18463
|
+
error,
|
|
18464
|
+
controller,
|
|
18465
|
+
runId,
|
|
18466
|
+
model: currentStep.model,
|
|
18467
|
+
messageList,
|
|
18468
|
+
messageId: currentStep.messageId,
|
|
18469
|
+
stepTools: currentStep.tools,
|
|
18470
|
+
_internal
|
|
18471
|
+
});
|
|
18472
|
+
}
|
|
18473
|
+
logger?.error("Error in processLLMRequest processors:", error);
|
|
18474
|
+
throw error;
|
|
18475
|
+
}
|
|
18476
|
+
}
|
|
18312
18477
|
if (isSupportedLanguageModel(currentStep.model)) {
|
|
18313
18478
|
modelResult = chunk5IS5R433_cjs.executeWithContextSync({
|
|
18314
18479
|
span: modelSpanTracker?.getTracingContext()?.currentSpan,
|
|
@@ -18401,7 +18566,7 @@ ${bgPrompt}`;
|
|
|
18401
18566
|
}
|
|
18402
18567
|
});
|
|
18403
18568
|
let transportResolver;
|
|
18404
|
-
if (currentStep.model instanceof
|
|
18569
|
+
if (currentStep.model instanceof chunkHKAOLV6C_cjs.ModelRouterLanguageModel) {
|
|
18405
18570
|
const routerModel = currentStep.model;
|
|
18406
18571
|
transportResolver = () => routerModel._getStreamTransport();
|
|
18407
18572
|
}
|
|
@@ -20462,6 +20627,7 @@ var MastraLLMVNext = class extends chunkFCQNDFEW_cjs.MastraBase {
|
|
|
20462
20627
|
structuredOutput,
|
|
20463
20628
|
options,
|
|
20464
20629
|
inputProcessors,
|
|
20630
|
+
llmRequestInputProcessors,
|
|
20465
20631
|
outputProcessors,
|
|
20466
20632
|
errorProcessors,
|
|
20467
20633
|
returnScorerData,
|
|
@@ -20544,6 +20710,7 @@ var MastraLLMVNext = class extends chunkFCQNDFEW_cjs.MastraBase {
|
|
|
20544
20710
|
_internal,
|
|
20545
20711
|
structuredOutput,
|
|
20546
20712
|
inputProcessors,
|
|
20713
|
+
llmRequestInputProcessors,
|
|
20547
20714
|
outputProcessors,
|
|
20548
20715
|
errorProcessors,
|
|
20549
20716
|
returnScorerData,
|
|
@@ -24840,6 +25007,10 @@ function createMapResultsStep({
|
|
|
24840
25007
|
requestContext: result.requestContext,
|
|
24841
25008
|
overrides: options.inputProcessors
|
|
24842
25009
|
}) : options.inputProcessors || capabilities.inputProcessors : options.inputProcessors || [];
|
|
25010
|
+
const effectiveLLMRequestInputProcessors = capabilities.llmRequestInputProcessors ? typeof capabilities.llmRequestInputProcessors === "function" ? await capabilities.llmRequestInputProcessors({
|
|
25011
|
+
requestContext: result.requestContext,
|
|
25012
|
+
overrides: options.inputProcessors
|
|
25013
|
+
}) : options.inputProcessors || capabilities.llmRequestInputProcessors : effectiveInputProcessors;
|
|
24843
25014
|
const effectiveErrorProcessors = capabilities.errorProcessors ? typeof capabilities.errorProcessors === "function" ? await capabilities.errorProcessors({
|
|
24844
25015
|
requestContext: result.requestContext,
|
|
24845
25016
|
overrides: options.errorProcessors
|
|
@@ -24955,6 +25126,7 @@ function createMapResultsStep({
|
|
|
24955
25126
|
activeTools: options.activeTools,
|
|
24956
25127
|
structuredOutput: options.structuredOutput,
|
|
24957
25128
|
inputProcessors: effectiveInputProcessors,
|
|
25129
|
+
llmRequestInputProcessors: effectiveLLMRequestInputProcessors,
|
|
24958
25130
|
outputProcessors: effectiveOutputProcessors,
|
|
24959
25131
|
errorProcessors: effectiveErrorProcessors,
|
|
24960
25132
|
modelSettings: {
|
|
@@ -25905,11 +26077,10 @@ ${errorMessages}`,
|
|
|
25905
26077
|
return this.combineProcessorsIntoWorkflow(allProcessors, `${this.id}-output-processor`);
|
|
25906
26078
|
}
|
|
25907
26079
|
/**
|
|
25908
|
-
* Resolves
|
|
25909
|
-
* All processors are combined into a single workflow for consistency.
|
|
26080
|
+
* Resolves input processors from agent configuration in execution order.
|
|
25910
26081
|
* @internal
|
|
25911
26082
|
*/
|
|
25912
|
-
async
|
|
26083
|
+
async resolveInputProcessors(requestContext, configuredProcessorOverrides) {
|
|
25913
26084
|
const configuredProcessors = configuredProcessorOverrides ? configuredProcessorOverrides : this.#inputProcessors ? typeof this.#inputProcessors === "function" ? await this.#inputProcessors({
|
|
25914
26085
|
requestContext: requestContext || new chunkKF4FCWWL_cjs.RequestContext()
|
|
25915
26086
|
}) : this.#inputProcessors : [];
|
|
@@ -25919,7 +26090,7 @@ ${errorMessages}`,
|
|
|
25919
26090
|
const skillsProcessors = await this.getSkillsProcessors(configuredProcessors, requestContext);
|
|
25920
26091
|
const channelProcessors = this.#agentChannels ? this.#agentChannels.getInputProcessors(configuredProcessors) : [];
|
|
25921
26092
|
const browserProcessors = this.#browser ? this.#browser.getInputProcessors(configuredProcessors) : [];
|
|
25922
|
-
|
|
26093
|
+
return [
|
|
25923
26094
|
...memoryProcessors,
|
|
25924
26095
|
...workspaceProcessors,
|
|
25925
26096
|
...skillsProcessors,
|
|
@@ -25927,7 +26098,23 @@ ${errorMessages}`,
|
|
|
25927
26098
|
...browserProcessors,
|
|
25928
26099
|
...configuredProcessors
|
|
25929
26100
|
];
|
|
25930
|
-
|
|
26101
|
+
}
|
|
26102
|
+
/**
|
|
26103
|
+
* Resolves and returns input processors from agent configuration.
|
|
26104
|
+
* All processors are combined into a single workflow for consistency.
|
|
26105
|
+
* @internal
|
|
26106
|
+
*/
|
|
26107
|
+
async listResolvedInputProcessors(requestContext, configuredProcessorOverrides) {
|
|
26108
|
+
const processors = await this.resolveInputProcessors(requestContext, configuredProcessorOverrides);
|
|
26109
|
+
return this.combineProcessorsIntoWorkflow(processors, `${this.id}-input-processor`);
|
|
26110
|
+
}
|
|
26111
|
+
/**
|
|
26112
|
+
* Resolves and returns input processors for the provider-boundary LLM request hook.
|
|
26113
|
+
* These processors stay uncombined because processLLMRequest runs after conversion to model prompt format.
|
|
26114
|
+
* @internal
|
|
26115
|
+
*/
|
|
26116
|
+
async listResolvedLLMRequestProcessors(requestContext, configuredProcessorOverrides) {
|
|
26117
|
+
return this.resolveInputProcessors(requestContext, configuredProcessorOverrides);
|
|
25931
26118
|
}
|
|
25932
26119
|
/**
|
|
25933
26120
|
* Returns the input processors for this agent, resolving function-based processors if necessary.
|
|
@@ -26656,7 +26843,7 @@ ${errorMessages}`,
|
|
|
26656
26843
|
*/
|
|
26657
26844
|
async resolveModelConfig(modelConfig, requestContext) {
|
|
26658
26845
|
try {
|
|
26659
|
-
return await
|
|
26846
|
+
return await chunkHKAOLV6C_cjs.resolveModelConfig(modelConfig, requestContext, this.#mastra);
|
|
26660
26847
|
} catch (error) {
|
|
26661
26848
|
const mastraError = new chunk4U7ZLI36_cjs.MastraError({
|
|
26662
26849
|
id: "AGENT_GET_MODEL_MISSING_MODEL_INSTANCE",
|
|
@@ -29082,7 +29269,7 @@ ${effectiveInstructions}`;
|
|
|
29082
29269
|
const resolvedModel = await this.resolveModelConfig(selection, requestContext);
|
|
29083
29270
|
this.assertSupportsPreparedModels(resolvedModel);
|
|
29084
29271
|
let headers;
|
|
29085
|
-
if (resolvedModel instanceof
|
|
29272
|
+
if (resolvedModel instanceof chunkHKAOLV6C_cjs.ModelRouterLanguageModel) {
|
|
29086
29273
|
headers = resolvedModel.config?.headers;
|
|
29087
29274
|
}
|
|
29088
29275
|
return [
|
|
@@ -29114,7 +29301,7 @@ ${effectiveInstructions}`;
|
|
|
29114
29301
|
throw mastraError;
|
|
29115
29302
|
}
|
|
29116
29303
|
let routerHeaders;
|
|
29117
|
-
if (model instanceof
|
|
29304
|
+
if (model instanceof chunkHKAOLV6C_cjs.ModelRouterLanguageModel) {
|
|
29118
29305
|
routerHeaders = model.config?.headers;
|
|
29119
29306
|
}
|
|
29120
29307
|
const isEnabled = modelConfig.enabled ?? true;
|
|
@@ -29310,6 +29497,10 @@ ${effectiveInstructions}`;
|
|
|
29310
29497
|
requestContext: requestContext2,
|
|
29311
29498
|
overrides
|
|
29312
29499
|
}) => this.listResolvedInputProcessors(requestContext2, overrides),
|
|
29500
|
+
llmRequestInputProcessors: async ({
|
|
29501
|
+
requestContext: requestContext2,
|
|
29502
|
+
overrides
|
|
29503
|
+
}) => this.listResolvedLLMRequestProcessors(requestContext2, overrides),
|
|
29313
29504
|
outputProcessors: async ({
|
|
29314
29505
|
requestContext: requestContext2,
|
|
29315
29506
|
overrides
|
|
@@ -32439,6 +32630,55 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
32439
32630
|
}
|
|
32440
32631
|
return stepInput;
|
|
32441
32632
|
}
|
|
32633
|
+
/**
|
|
32634
|
+
* Run processLLMRequest for all processors that implement it.
|
|
32635
|
+
*
|
|
32636
|
+
* Called *after* `MessageList` has been converted to `LanguageModelV2Prompt`
|
|
32637
|
+
* and immediately *before* the prompt is forwarded to the provider.
|
|
32638
|
+
* Mutations are scoped to this single call — they do not affect the
|
|
32639
|
+
* persisted message list, memory, UI, or future model swaps.
|
|
32640
|
+
*/
|
|
32641
|
+
async runProcessLLMRequest(args) {
|
|
32642
|
+
chunkCDN65CUN_cjs.resolveObservabilityContext({ tracingContext: args.tracingContext });
|
|
32643
|
+
let currentPrompt = args.prompt;
|
|
32644
|
+
for (const processorOrWorkflow of this.inputProcessors) {
|
|
32645
|
+
if (isProcessorWorkflow(processorOrWorkflow)) continue;
|
|
32646
|
+
const processor = processorOrWorkflow;
|
|
32647
|
+
const processMethod = processor.processLLMRequest?.bind(processor);
|
|
32648
|
+
if (!processMethod) continue;
|
|
32649
|
+
const abort = (reason, options) => {
|
|
32650
|
+
throw new TripWire(reason || `Tripwire triggered by ${processor.id}`, options, processor.id);
|
|
32651
|
+
};
|
|
32652
|
+
try {
|
|
32653
|
+
const processorState = this.getProcessorState(processor.id);
|
|
32654
|
+
const result = await processMethod({
|
|
32655
|
+
prompt: currentPrompt,
|
|
32656
|
+
// The Processor interface types `model` as `MastraLanguageModel`, but
|
|
32657
|
+
// the runner accepts the looser `unknown` to match other call paths
|
|
32658
|
+
// (e.g. unresolved string ids or function-typed dynamic models).
|
|
32659
|
+
model: args.model,
|
|
32660
|
+
stepNumber: args.stepNumber,
|
|
32661
|
+
steps: args.steps,
|
|
32662
|
+
state: processorState.customState,
|
|
32663
|
+
retryCount: args.retryCount ?? 0,
|
|
32664
|
+
requestContext: args.requestContext,
|
|
32665
|
+
abort,
|
|
32666
|
+
abortSignal: args.abortSignal,
|
|
32667
|
+
writer: args.writer,
|
|
32668
|
+
...chunkCDN65CUN_cjs.createObservabilityContext(args.tracingContext)
|
|
32669
|
+
});
|
|
32670
|
+
if (result && typeof result === "object" && result.prompt) {
|
|
32671
|
+
currentPrompt = result.prompt;
|
|
32672
|
+
}
|
|
32673
|
+
} catch (error) {
|
|
32674
|
+
if (error instanceof TripWire) {
|
|
32675
|
+
await invokeOnViolation(processor, error);
|
|
32676
|
+
}
|
|
32677
|
+
throw error;
|
|
32678
|
+
}
|
|
32679
|
+
}
|
|
32680
|
+
return { prompt: currentPrompt };
|
|
32681
|
+
}
|
|
32442
32682
|
/**
|
|
32443
32683
|
* Type guard to check if result is { messages, systemMessages }
|
|
32444
32684
|
*/
|
|
@@ -32796,7 +33036,7 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
32796
33036
|
}
|
|
32797
33037
|
const { model: _model, ...rest } = result;
|
|
32798
33038
|
if (result.model) {
|
|
32799
|
-
const resolvedModel = await
|
|
33039
|
+
const resolvedModel = await chunkHKAOLV6C_cjs.resolveModelConfig(result.model);
|
|
32800
33040
|
const isSupported = isSupportedLanguageModel(resolvedModel);
|
|
32801
33041
|
if (!isSupported) {
|
|
32802
33042
|
throw new chunk4U7ZLI36_cjs.MastraError({
|
|
@@ -32888,6 +33128,7 @@ exports.WorkspaceInstructionsProcessor = WorkspaceInstructionsProcessor;
|
|
|
32888
33128
|
exports.__registerEventedCreateWorkflow = __registerEventedCreateWorkflow;
|
|
32889
33129
|
exports.anthropicToolIdFormat = anthropicToolIdFormat;
|
|
32890
33130
|
exports.augmentWithInit = augmentWithInit;
|
|
33131
|
+
exports.cerebrasStripReasoningContent = cerebrasStripReasoningContent;
|
|
32891
33132
|
exports.cleanStepResult = cleanStepResult;
|
|
32892
33133
|
exports.cloneStep = cloneStep;
|
|
32893
33134
|
exports.cloneWorkflow = cloneWorkflow;
|
|
@@ -32957,5 +33198,5 @@ exports.validateStepResumeData = validateStepResumeData;
|
|
|
32957
33198
|
exports.validateStepStateData = validateStepStateData;
|
|
32958
33199
|
exports.validateStepSuspendData = validateStepSuspendData;
|
|
32959
33200
|
exports.withStreamCaching = withStreamCaching;
|
|
32960
|
-
//# sourceMappingURL=chunk-
|
|
32961
|
-
//# sourceMappingURL=chunk-
|
|
33201
|
+
//# sourceMappingURL=chunk-DIXS2HEO.cjs.map
|
|
33202
|
+
//# sourceMappingURL=chunk-DIXS2HEO.cjs.map
|