@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
|
@@ -9,7 +9,7 @@ import { APICallError, generateId, tool, asSchema } from './chunk-32WQTREY.js';
|
|
|
9
9
|
import { noopLogger } from './chunk-YBJX7SPB.js';
|
|
10
10
|
import { EventEmitterPubSub } from './chunk-4E5FOY4E.js';
|
|
11
11
|
import { executeHook } from './chunk-L54GIUCB.js';
|
|
12
|
-
import { ModelRouterEmbeddingModel, resolveModelConfig, ModelRouterLanguageModel } from './chunk-
|
|
12
|
+
import { ModelRouterEmbeddingModel, resolveModelConfig, ModelRouterLanguageModel } from './chunk-7L4SZOZX.js';
|
|
13
13
|
import { MastraLLMV1 } from './chunk-YVDKR35H.js';
|
|
14
14
|
import { deepMerge, generateEmptyFromSchema, removeUndefinedValues, safeStringify, ensureToolProperties, makeCoreTool, createMastraProxy, selectFields, ensureSerializable, delay } from './chunk-O5LXE6TX.js';
|
|
15
15
|
import { resolveObservabilityContext, createObservabilityContext, wrapMastra } from './chunk-2NDJVX5U.js';
|
|
@@ -4597,107 +4597,6 @@ var PrefillErrorHandler = class {
|
|
|
4597
4597
|
}
|
|
4598
4598
|
};
|
|
4599
4599
|
|
|
4600
|
-
// src/processors/stream-error-retry-processor.ts
|
|
4601
|
-
var DEFAULT_MAX_RETRIES = 1;
|
|
4602
|
-
var RETRYABLE_OPENAI_ERROR_CODES = [
|
|
4603
|
-
"rate_limit",
|
|
4604
|
-
"server_error",
|
|
4605
|
-
"internal_error",
|
|
4606
|
-
"timeout",
|
|
4607
|
-
"temporarily_unavailable",
|
|
4608
|
-
"service_unavailable",
|
|
4609
|
-
"overloaded"
|
|
4610
|
-
];
|
|
4611
|
-
var OPENAI_RETRY_MESSAGE_PATTERN = /you can retry your request/i;
|
|
4612
|
-
var DEFAULT_MATCHERS = [isRetryableOpenAIResponsesStreamError];
|
|
4613
|
-
function isRecord2(value) {
|
|
4614
|
-
return typeof value === "object" && value !== null;
|
|
4615
|
-
}
|
|
4616
|
-
function getStringProperty(value, key) {
|
|
4617
|
-
const property = value[key];
|
|
4618
|
-
return typeof property === "string" ? property : void 0;
|
|
4619
|
-
}
|
|
4620
|
-
function getObjectCause(error) {
|
|
4621
|
-
if (error instanceof Error) {
|
|
4622
|
-
return error.cause;
|
|
4623
|
-
}
|
|
4624
|
-
if (!isRecord2(error)) {
|
|
4625
|
-
return void 0;
|
|
4626
|
-
}
|
|
4627
|
-
return error.cause;
|
|
4628
|
-
}
|
|
4629
|
-
function getOpenAIErrorPayload(error) {
|
|
4630
|
-
if (!isRecord2(error)) {
|
|
4631
|
-
return void 0;
|
|
4632
|
-
}
|
|
4633
|
-
if (error.type === "error" && isRecord2(error.error)) {
|
|
4634
|
-
return error.error;
|
|
4635
|
-
}
|
|
4636
|
-
if (error.type === "response.failed" && isRecord2(error.response)) {
|
|
4637
|
-
const responseError = error.response.error;
|
|
4638
|
-
return isRecord2(responseError) ? responseError : void 0;
|
|
4639
|
-
}
|
|
4640
|
-
return void 0;
|
|
4641
|
-
}
|
|
4642
|
-
function hasRetryableOpenAIErrorCode(payload) {
|
|
4643
|
-
const code = getStringProperty(payload, "code") ?? getStringProperty(payload, "type");
|
|
4644
|
-
if (!code) {
|
|
4645
|
-
return false;
|
|
4646
|
-
}
|
|
4647
|
-
const normalizedCode = code.toLowerCase();
|
|
4648
|
-
return RETRYABLE_OPENAI_ERROR_CODES.some((retryableCode) => normalizedCode.includes(retryableCode));
|
|
4649
|
-
}
|
|
4650
|
-
function hasExplicitRetryMessage(payload) {
|
|
4651
|
-
const message = getStringProperty(payload, "message");
|
|
4652
|
-
return message !== void 0 && OPENAI_RETRY_MESSAGE_PATTERN.test(message);
|
|
4653
|
-
}
|
|
4654
|
-
function isRetryableOpenAIResponsesStreamError(error) {
|
|
4655
|
-
const payload = getOpenAIErrorPayload(error);
|
|
4656
|
-
if (!payload) {
|
|
4657
|
-
return false;
|
|
4658
|
-
}
|
|
4659
|
-
return hasRetryableOpenAIErrorCode(payload) || hasExplicitRetryMessage(payload);
|
|
4660
|
-
}
|
|
4661
|
-
function isRetryableProviderMetadata(error) {
|
|
4662
|
-
const retryable = APICallError.isInstance(error) ? error.isRetryable : isRecord2(error) && typeof error.isRetryable === "boolean" ? error.isRetryable : void 0;
|
|
4663
|
-
return retryable === true;
|
|
4664
|
-
}
|
|
4665
|
-
function isRetryableStreamError(error, matchers) {
|
|
4666
|
-
const visited = /* @__PURE__ */ new WeakSet();
|
|
4667
|
-
function visit(candidate) {
|
|
4668
|
-
if (isRecord2(candidate)) {
|
|
4669
|
-
if (visited.has(candidate)) {
|
|
4670
|
-
return false;
|
|
4671
|
-
}
|
|
4672
|
-
visited.add(candidate);
|
|
4673
|
-
}
|
|
4674
|
-
if (isRetryableProviderMetadata(candidate)) {
|
|
4675
|
-
return true;
|
|
4676
|
-
}
|
|
4677
|
-
if (matchers.some((matcher) => matcher(candidate))) {
|
|
4678
|
-
return true;
|
|
4679
|
-
}
|
|
4680
|
-
const cause = getObjectCause(candidate);
|
|
4681
|
-
return cause !== void 0 && visit(cause);
|
|
4682
|
-
}
|
|
4683
|
-
return visit(error);
|
|
4684
|
-
}
|
|
4685
|
-
var StreamErrorRetryProcessor = class {
|
|
4686
|
-
id = "stream-error-retry-processor";
|
|
4687
|
-
name = "Stream Error Retry Processor";
|
|
4688
|
-
#maxRetries;
|
|
4689
|
-
#matchers;
|
|
4690
|
-
constructor(options = {}) {
|
|
4691
|
-
this.#maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
4692
|
-
this.#matchers = [...DEFAULT_MATCHERS, ...options.matchers ?? []];
|
|
4693
|
-
}
|
|
4694
|
-
async processAPIError({ error, retryCount }) {
|
|
4695
|
-
if (retryCount >= this.#maxRetries) return;
|
|
4696
|
-
if (!isRetryableStreamError(error, this.#matchers)) return;
|
|
4697
|
-
return { retry: true };
|
|
4698
|
-
}
|
|
4699
|
-
};
|
|
4700
|
-
|
|
4701
4600
|
// src/processors/provider-history-compat.ts
|
|
4702
4601
|
function getErrorCandidates2(error) {
|
|
4703
4602
|
const candidates = [error.message];
|
|
@@ -4707,6 +4606,7 @@ function getErrorCandidates2(error) {
|
|
|
4707
4606
|
return candidates.filter(Boolean);
|
|
4708
4607
|
}
|
|
4709
4608
|
function matchesRule(error, rule) {
|
|
4609
|
+
if (!rule.errorPatterns?.length) return false;
|
|
4710
4610
|
const matches = (text) => rule.errorPatterns.some((p) => p.test(text));
|
|
4711
4611
|
if (APICallError.isInstance(error)) {
|
|
4712
4612
|
return getErrorCandidates2(error).some(matches);
|
|
@@ -4780,7 +4680,69 @@ var anthropicToolIdFormat = {
|
|
|
4780
4680
|
return true;
|
|
4781
4681
|
}
|
|
4782
4682
|
};
|
|
4783
|
-
|
|
4683
|
+
function matchesProviderPrefix(model, providerPrefix) {
|
|
4684
|
+
if (model == null) return false;
|
|
4685
|
+
if (typeof model === "function") return false;
|
|
4686
|
+
if (Array.isArray(model)) {
|
|
4687
|
+
return model.some((m) => matchesProviderPrefix(m.model ?? m, providerPrefix));
|
|
4688
|
+
}
|
|
4689
|
+
const gatewayPattern = new RegExp(`^${providerPrefix}[/:]`, "i");
|
|
4690
|
+
const providerPattern = new RegExp(`^${providerPrefix}($|[.\\-])`, "i");
|
|
4691
|
+
if (typeof model === "string") {
|
|
4692
|
+
return gatewayPattern.test(model);
|
|
4693
|
+
}
|
|
4694
|
+
if (typeof model === "object") {
|
|
4695
|
+
const { provider, modelId } = model;
|
|
4696
|
+
if (typeof provider === "string" && providerPattern.test(provider)) return true;
|
|
4697
|
+
if (typeof modelId === "string") return gatewayPattern.test(modelId);
|
|
4698
|
+
}
|
|
4699
|
+
return false;
|
|
4700
|
+
}
|
|
4701
|
+
function isMaybeCerebras(model) {
|
|
4702
|
+
return matchesProviderPrefix(model, "cerebras");
|
|
4703
|
+
}
|
|
4704
|
+
function isMaybeAnthropic(model) {
|
|
4705
|
+
return matchesProviderPrefix(model, "anthropic");
|
|
4706
|
+
}
|
|
4707
|
+
function stripReasoningFromPrompt(prompt, shouldStrip = () => true) {
|
|
4708
|
+
let mutated = false;
|
|
4709
|
+
const next = prompt.map((message) => {
|
|
4710
|
+
if (message.role !== "assistant") return message;
|
|
4711
|
+
if (typeof message.content === "string") return message;
|
|
4712
|
+
if (!Array.isArray(message.content)) return message;
|
|
4713
|
+
const filtered = message.content.filter((part) => part.type !== "reasoning" || !shouldStrip(part));
|
|
4714
|
+
if (filtered.length === message.content.length) return message;
|
|
4715
|
+
mutated = true;
|
|
4716
|
+
return { ...message, content: filtered };
|
|
4717
|
+
});
|
|
4718
|
+
return mutated ? next : void 0;
|
|
4719
|
+
}
|
|
4720
|
+
function isAnthropicReasoningPart(part) {
|
|
4721
|
+
const providerOptions = part.providerOptions;
|
|
4722
|
+
if (providerOptions && typeof providerOptions === "object" && "anthropic" in providerOptions) return true;
|
|
4723
|
+
const providerMetadata = part.providerMetadata;
|
|
4724
|
+
if (providerMetadata && typeof providerMetadata === "object" && "anthropic" in providerMetadata) return true;
|
|
4725
|
+
return false;
|
|
4726
|
+
}
|
|
4727
|
+
var cerebrasStripReasoningContent = {
|
|
4728
|
+
name: "cerebras-strip-reasoning-content",
|
|
4729
|
+
applyToPrompt({ prompt, model }) {
|
|
4730
|
+
if (!isMaybeCerebras(model)) return void 0;
|
|
4731
|
+
return stripReasoningFromPrompt(prompt);
|
|
4732
|
+
}
|
|
4733
|
+
};
|
|
4734
|
+
var anthropicStripForeignReasoningContent = {
|
|
4735
|
+
name: "anthropic-strip-foreign-reasoning-content",
|
|
4736
|
+
applyToPrompt({ prompt, model }) {
|
|
4737
|
+
if (!isMaybeAnthropic(model)) return void 0;
|
|
4738
|
+
return stripReasoningFromPrompt(prompt, (part) => !isAnthropicReasoningPart(part));
|
|
4739
|
+
}
|
|
4740
|
+
};
|
|
4741
|
+
var DEFAULT_COMPAT_RULES = [
|
|
4742
|
+
anthropicToolIdFormat,
|
|
4743
|
+
cerebrasStripReasoningContent,
|
|
4744
|
+
anthropicStripForeignReasoningContent
|
|
4745
|
+
];
|
|
4784
4746
|
var ProviderHistoryCompat = class {
|
|
4785
4747
|
id = "provider-history-compat";
|
|
4786
4748
|
name = "Provider History Compat";
|
|
@@ -4788,6 +4750,19 @@ var ProviderHistoryCompat = class {
|
|
|
4788
4750
|
constructor(opts) {
|
|
4789
4751
|
this.rules = [...DEFAULT_COMPAT_RULES, ...opts?.additionalRules ?? []];
|
|
4790
4752
|
}
|
|
4753
|
+
processLLMRequest({ prompt, model }) {
|
|
4754
|
+
let current = prompt;
|
|
4755
|
+
let mutated = false;
|
|
4756
|
+
for (const rule of this.rules) {
|
|
4757
|
+
if (!rule.applyToPrompt) continue;
|
|
4758
|
+
const next = rule.applyToPrompt({ prompt: current, model });
|
|
4759
|
+
if (next) {
|
|
4760
|
+
current = next;
|
|
4761
|
+
mutated = true;
|
|
4762
|
+
}
|
|
4763
|
+
}
|
|
4764
|
+
return mutated ? { prompt: current } : void 0;
|
|
4765
|
+
}
|
|
4791
4766
|
async processAPIError({
|
|
4792
4767
|
error,
|
|
4793
4768
|
messageList,
|
|
@@ -4796,6 +4771,7 @@ var ProviderHistoryCompat = class {
|
|
|
4796
4771
|
if (retryCount > 0) return;
|
|
4797
4772
|
const messages = messageList.get.all.db();
|
|
4798
4773
|
for (const rule of this.rules) {
|
|
4774
|
+
if (!rule.fix) continue;
|
|
4799
4775
|
if (matchesRule(error, rule)) {
|
|
4800
4776
|
const changed = rule.fix(messages);
|
|
4801
4777
|
if (changed) {
|
|
@@ -4806,6 +4782,107 @@ var ProviderHistoryCompat = class {
|
|
|
4806
4782
|
}
|
|
4807
4783
|
};
|
|
4808
4784
|
|
|
4785
|
+
// src/processors/stream-error-retry-processor.ts
|
|
4786
|
+
var DEFAULT_MAX_RETRIES = 1;
|
|
4787
|
+
var RETRYABLE_OPENAI_ERROR_CODES = [
|
|
4788
|
+
"rate_limit",
|
|
4789
|
+
"server_error",
|
|
4790
|
+
"internal_error",
|
|
4791
|
+
"timeout",
|
|
4792
|
+
"temporarily_unavailable",
|
|
4793
|
+
"service_unavailable",
|
|
4794
|
+
"overloaded"
|
|
4795
|
+
];
|
|
4796
|
+
var OPENAI_RETRY_MESSAGE_PATTERN = /you can retry your request/i;
|
|
4797
|
+
var DEFAULT_MATCHERS = [isRetryableOpenAIResponsesStreamError];
|
|
4798
|
+
function isRecord2(value) {
|
|
4799
|
+
return typeof value === "object" && value !== null;
|
|
4800
|
+
}
|
|
4801
|
+
function getStringProperty(value, key) {
|
|
4802
|
+
const property = value[key];
|
|
4803
|
+
return typeof property === "string" ? property : void 0;
|
|
4804
|
+
}
|
|
4805
|
+
function getObjectCause(error) {
|
|
4806
|
+
if (error instanceof Error) {
|
|
4807
|
+
return error.cause;
|
|
4808
|
+
}
|
|
4809
|
+
if (!isRecord2(error)) {
|
|
4810
|
+
return void 0;
|
|
4811
|
+
}
|
|
4812
|
+
return error.cause;
|
|
4813
|
+
}
|
|
4814
|
+
function getOpenAIErrorPayload(error) {
|
|
4815
|
+
if (!isRecord2(error)) {
|
|
4816
|
+
return void 0;
|
|
4817
|
+
}
|
|
4818
|
+
if (error.type === "error" && isRecord2(error.error)) {
|
|
4819
|
+
return error.error;
|
|
4820
|
+
}
|
|
4821
|
+
if (error.type === "response.failed" && isRecord2(error.response)) {
|
|
4822
|
+
const responseError = error.response.error;
|
|
4823
|
+
return isRecord2(responseError) ? responseError : void 0;
|
|
4824
|
+
}
|
|
4825
|
+
return void 0;
|
|
4826
|
+
}
|
|
4827
|
+
function hasRetryableOpenAIErrorCode(payload) {
|
|
4828
|
+
const code = getStringProperty(payload, "code") ?? getStringProperty(payload, "type");
|
|
4829
|
+
if (!code) {
|
|
4830
|
+
return false;
|
|
4831
|
+
}
|
|
4832
|
+
const normalizedCode = code.toLowerCase();
|
|
4833
|
+
return RETRYABLE_OPENAI_ERROR_CODES.some((retryableCode) => normalizedCode.includes(retryableCode));
|
|
4834
|
+
}
|
|
4835
|
+
function hasExplicitRetryMessage(payload) {
|
|
4836
|
+
const message = getStringProperty(payload, "message");
|
|
4837
|
+
return message !== void 0 && OPENAI_RETRY_MESSAGE_PATTERN.test(message);
|
|
4838
|
+
}
|
|
4839
|
+
function isRetryableOpenAIResponsesStreamError(error) {
|
|
4840
|
+
const payload = getOpenAIErrorPayload(error);
|
|
4841
|
+
if (!payload) {
|
|
4842
|
+
return false;
|
|
4843
|
+
}
|
|
4844
|
+
return hasRetryableOpenAIErrorCode(payload) || hasExplicitRetryMessage(payload);
|
|
4845
|
+
}
|
|
4846
|
+
function isRetryableProviderMetadata(error) {
|
|
4847
|
+
const retryable = APICallError.isInstance(error) ? error.isRetryable : isRecord2(error) && typeof error.isRetryable === "boolean" ? error.isRetryable : void 0;
|
|
4848
|
+
return retryable === true;
|
|
4849
|
+
}
|
|
4850
|
+
function isRetryableStreamError(error, matchers) {
|
|
4851
|
+
const visited = /* @__PURE__ */ new WeakSet();
|
|
4852
|
+
function visit(candidate) {
|
|
4853
|
+
if (isRecord2(candidate)) {
|
|
4854
|
+
if (visited.has(candidate)) {
|
|
4855
|
+
return false;
|
|
4856
|
+
}
|
|
4857
|
+
visited.add(candidate);
|
|
4858
|
+
}
|
|
4859
|
+
if (isRetryableProviderMetadata(candidate)) {
|
|
4860
|
+
return true;
|
|
4861
|
+
}
|
|
4862
|
+
if (matchers.some((matcher) => matcher(candidate))) {
|
|
4863
|
+
return true;
|
|
4864
|
+
}
|
|
4865
|
+
const cause = getObjectCause(candidate);
|
|
4866
|
+
return cause !== void 0 && visit(cause);
|
|
4867
|
+
}
|
|
4868
|
+
return visit(error);
|
|
4869
|
+
}
|
|
4870
|
+
var StreamErrorRetryProcessor = class {
|
|
4871
|
+
id = "stream-error-retry-processor";
|
|
4872
|
+
name = "Stream Error Retry Processor";
|
|
4873
|
+
#maxRetries;
|
|
4874
|
+
#matchers;
|
|
4875
|
+
constructor(options = {}) {
|
|
4876
|
+
this.#maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES;
|
|
4877
|
+
this.#matchers = [...DEFAULT_MATCHERS, ...options.matchers ?? []];
|
|
4878
|
+
}
|
|
4879
|
+
async processAPIError({ error, retryCount }) {
|
|
4880
|
+
if (retryCount >= this.#maxRetries) return;
|
|
4881
|
+
if (!isRetryableStreamError(error, this.#matchers)) return;
|
|
4882
|
+
return { retry: true };
|
|
4883
|
+
}
|
|
4884
|
+
};
|
|
4885
|
+
|
|
4809
4886
|
// src/memory/types.ts
|
|
4810
4887
|
function isPlainObject(value) {
|
|
4811
4888
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -6849,7 +6926,7 @@ var BaseProcessor = class {
|
|
|
6849
6926
|
};
|
|
6850
6927
|
function isProcessorWorkflow(obj) {
|
|
6851
6928
|
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)
|
|
6852
|
-
!("processInput" in obj) && !("processInputStep" in obj) && !("processOutputStream" in obj) && !("processOutputResult" in obj) && !("processOutputStep" in obj) && !("processAPIError" in obj);
|
|
6929
|
+
!("processInput" in obj) && !("processInputStep" in obj) && !("processOutputStream" in obj) && !("processOutputResult" in obj) && !("processOutputStep" in obj) && !("processLLMRequest" in obj) && !("processAPIError" in obj);
|
|
6853
6930
|
}
|
|
6854
6931
|
|
|
6855
6932
|
// src/channels/chat-lazy.ts
|
|
@@ -17758,6 +17835,24 @@ function updateToolCallForeachConcurrency(options, args) {
|
|
|
17758
17835
|
}
|
|
17759
17836
|
|
|
17760
17837
|
// src/loop/workflows/agentic-execution/llm-execution-step.ts
|
|
17838
|
+
function getRequestInputProcessors({
|
|
17839
|
+
inputProcessors,
|
|
17840
|
+
llmRequestInputProcessors
|
|
17841
|
+
}) {
|
|
17842
|
+
if (!llmRequestInputProcessors?.length) {
|
|
17843
|
+
return inputProcessors || [];
|
|
17844
|
+
}
|
|
17845
|
+
if (!inputProcessors?.length) {
|
|
17846
|
+
return llmRequestInputProcessors;
|
|
17847
|
+
}
|
|
17848
|
+
const requestProcessorIds = new Set(
|
|
17849
|
+
llmRequestInputProcessors.filter((processor) => !isProcessorWorkflow(processor)).map((processor) => processor.id)
|
|
17850
|
+
);
|
|
17851
|
+
const additionalInputProcessors = inputProcessors.filter(
|
|
17852
|
+
(processor) => !isProcessorWorkflow(processor) && !requestProcessorIds.has(processor.id)
|
|
17853
|
+
);
|
|
17854
|
+
return additionalInputProcessors.length ? [...llmRequestInputProcessors, ...additionalInputProcessors] : llmRequestInputProcessors;
|
|
17855
|
+
}
|
|
17761
17856
|
function buildResponseModelMetadata(runState, model) {
|
|
17762
17857
|
const metadata = {};
|
|
17763
17858
|
const modelId = model?.modelId ?? runState.state.responseMetadata?.modelId;
|
|
@@ -17769,6 +17864,54 @@ function buildResponseModelMetadata(runState, model) {
|
|
|
17769
17864
|
}
|
|
17770
17865
|
return Object.keys(metadata).length > 0 ? { metadata } : void 0;
|
|
17771
17866
|
}
|
|
17867
|
+
function buildTripWireBailResponse({
|
|
17868
|
+
error,
|
|
17869
|
+
controller,
|
|
17870
|
+
runId,
|
|
17871
|
+
model,
|
|
17872
|
+
messageList,
|
|
17873
|
+
messageId,
|
|
17874
|
+
stepTools,
|
|
17875
|
+
_internal
|
|
17876
|
+
}) {
|
|
17877
|
+
const tripwireChunk = {
|
|
17878
|
+
type: "tripwire",
|
|
17879
|
+
runId,
|
|
17880
|
+
from: "AGENT" /* AGENT */,
|
|
17881
|
+
payload: {
|
|
17882
|
+
reason: error.message,
|
|
17883
|
+
retry: error.options?.retry,
|
|
17884
|
+
metadata: error.options?.metadata,
|
|
17885
|
+
processorId: error.processorId
|
|
17886
|
+
}
|
|
17887
|
+
};
|
|
17888
|
+
safeEnqueue(controller, tripwireChunk);
|
|
17889
|
+
const runState = new AgenticRunState({
|
|
17890
|
+
_internal,
|
|
17891
|
+
model
|
|
17892
|
+
});
|
|
17893
|
+
return {
|
|
17894
|
+
callBail: true,
|
|
17895
|
+
outputStream: new MastraModelOutput({
|
|
17896
|
+
model: {
|
|
17897
|
+
modelId: model.modelId,
|
|
17898
|
+
provider: model.provider,
|
|
17899
|
+
version: model.specificationVersion
|
|
17900
|
+
},
|
|
17901
|
+
stream: new ReadableStream$1({
|
|
17902
|
+
start(c) {
|
|
17903
|
+
c.enqueue(tripwireChunk);
|
|
17904
|
+
c.close();
|
|
17905
|
+
}
|
|
17906
|
+
}),
|
|
17907
|
+
messageList,
|
|
17908
|
+
messageId,
|
|
17909
|
+
options: { runId }
|
|
17910
|
+
}),
|
|
17911
|
+
runState,
|
|
17912
|
+
stepTools
|
|
17913
|
+
};
|
|
17914
|
+
}
|
|
17772
17915
|
async function processOutputStream({
|
|
17773
17916
|
tools,
|
|
17774
17917
|
messageId,
|
|
@@ -17975,6 +18118,7 @@ function createLLMExecutionStep({
|
|
|
17975
18118
|
structuredOutput,
|
|
17976
18119
|
outputProcessors,
|
|
17977
18120
|
inputProcessors,
|
|
18121
|
+
llmRequestInputProcessors,
|
|
17978
18122
|
errorProcessors,
|
|
17979
18123
|
logger,
|
|
17980
18124
|
agentId,
|
|
@@ -18153,41 +18297,16 @@ function createLLMExecutionStep({
|
|
|
18153
18297
|
processorId: error.processorId,
|
|
18154
18298
|
retry: error.options?.retry
|
|
18155
18299
|
});
|
|
18156
|
-
|
|
18157
|
-
|
|
18300
|
+
return buildTripWireBailResponse({
|
|
18301
|
+
error,
|
|
18302
|
+
controller,
|
|
18158
18303
|
runId,
|
|
18159
|
-
|
|
18160
|
-
|
|
18161
|
-
|
|
18162
|
-
|
|
18163
|
-
|
|
18164
|
-
processorId: error.processorId
|
|
18165
|
-
}
|
|
18166
|
-
});
|
|
18167
|
-
const runState3 = new AgenticRunState({
|
|
18168
|
-
_internal,
|
|
18169
|
-
model
|
|
18304
|
+
model,
|
|
18305
|
+
messageList,
|
|
18306
|
+
messageId: currentStep.messageId,
|
|
18307
|
+
stepTools: tools,
|
|
18308
|
+
_internal
|
|
18170
18309
|
});
|
|
18171
|
-
return {
|
|
18172
|
-
callBail: true,
|
|
18173
|
-
outputStream: new MastraModelOutput({
|
|
18174
|
-
model: {
|
|
18175
|
-
modelId: model.modelId,
|
|
18176
|
-
provider: model.provider,
|
|
18177
|
-
version: model.specificationVersion
|
|
18178
|
-
},
|
|
18179
|
-
stream: new ReadableStream$1({
|
|
18180
|
-
start(c) {
|
|
18181
|
-
c.close();
|
|
18182
|
-
}
|
|
18183
|
-
}),
|
|
18184
|
-
messageList,
|
|
18185
|
-
messageId: currentStep.messageId,
|
|
18186
|
-
options: { runId }
|
|
18187
|
-
}),
|
|
18188
|
-
runState: runState3,
|
|
18189
|
-
stepTools: tools
|
|
18190
|
-
};
|
|
18191
18310
|
}
|
|
18192
18311
|
logger?.error("Error in processInputStep processors:", error);
|
|
18193
18312
|
throw error;
|
|
@@ -18284,6 +18403,52 @@ ${bgPrompt}`;
|
|
|
18284
18403
|
return message;
|
|
18285
18404
|
});
|
|
18286
18405
|
}
|
|
18406
|
+
{
|
|
18407
|
+
const requestStepRunner = new ProcessorRunner({
|
|
18408
|
+
inputProcessors: getRequestInputProcessors({ inputProcessors, llmRequestInputProcessors }),
|
|
18409
|
+
outputProcessors: [],
|
|
18410
|
+
logger: logger || new ConsoleLogger({ level: "error" }),
|
|
18411
|
+
agentName: agentId || "unknown",
|
|
18412
|
+
processorStates
|
|
18413
|
+
});
|
|
18414
|
+
const requestStepWriter = outputWriter ? {
|
|
18415
|
+
custom: async (data, options2) => outputWriter(data, { ...options2, messageId: currentStep.messageId })
|
|
18416
|
+
} : void 0;
|
|
18417
|
+
try {
|
|
18418
|
+
const requestStepResult = await requestStepRunner.runProcessLLMRequest({
|
|
18419
|
+
prompt: inputMessages,
|
|
18420
|
+
model: currentStep.model,
|
|
18421
|
+
stepNumber: inputData.output?.steps?.length || 0,
|
|
18422
|
+
steps: inputData.output?.steps || [],
|
|
18423
|
+
retryCount: inputData.processorRetryCount || 0,
|
|
18424
|
+
requestContext,
|
|
18425
|
+
tracingContext: modelSpanTracker?.getTracingContext() ?? tracingContext,
|
|
18426
|
+
writer: requestStepWriter,
|
|
18427
|
+
abortSignal: options?.abortSignal
|
|
18428
|
+
});
|
|
18429
|
+
inputMessages = requestStepResult.prompt;
|
|
18430
|
+
} catch (error) {
|
|
18431
|
+
if (error instanceof TripWire) {
|
|
18432
|
+
logger?.warn("Streaming request processor tripwire triggered", {
|
|
18433
|
+
reason: error.message,
|
|
18434
|
+
processorId: error.processorId,
|
|
18435
|
+
retry: error.options?.retry
|
|
18436
|
+
});
|
|
18437
|
+
return buildTripWireBailResponse({
|
|
18438
|
+
error,
|
|
18439
|
+
controller,
|
|
18440
|
+
runId,
|
|
18441
|
+
model: currentStep.model,
|
|
18442
|
+
messageList,
|
|
18443
|
+
messageId: currentStep.messageId,
|
|
18444
|
+
stepTools: currentStep.tools,
|
|
18445
|
+
_internal
|
|
18446
|
+
});
|
|
18447
|
+
}
|
|
18448
|
+
logger?.error("Error in processLLMRequest processors:", error);
|
|
18449
|
+
throw error;
|
|
18450
|
+
}
|
|
18451
|
+
}
|
|
18287
18452
|
if (isSupportedLanguageModel(currentStep.model)) {
|
|
18288
18453
|
modelResult = executeWithContextSync({
|
|
18289
18454
|
span: modelSpanTracker?.getTracingContext()?.currentSpan,
|
|
@@ -20437,6 +20602,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
20437
20602
|
structuredOutput,
|
|
20438
20603
|
options,
|
|
20439
20604
|
inputProcessors,
|
|
20605
|
+
llmRequestInputProcessors,
|
|
20440
20606
|
outputProcessors,
|
|
20441
20607
|
errorProcessors,
|
|
20442
20608
|
returnScorerData,
|
|
@@ -20519,6 +20685,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
20519
20685
|
_internal,
|
|
20520
20686
|
structuredOutput,
|
|
20521
20687
|
inputProcessors,
|
|
20688
|
+
llmRequestInputProcessors,
|
|
20522
20689
|
outputProcessors,
|
|
20523
20690
|
errorProcessors,
|
|
20524
20691
|
returnScorerData,
|
|
@@ -24815,6 +24982,10 @@ function createMapResultsStep({
|
|
|
24815
24982
|
requestContext: result.requestContext,
|
|
24816
24983
|
overrides: options.inputProcessors
|
|
24817
24984
|
}) : options.inputProcessors || capabilities.inputProcessors : options.inputProcessors || [];
|
|
24985
|
+
const effectiveLLMRequestInputProcessors = capabilities.llmRequestInputProcessors ? typeof capabilities.llmRequestInputProcessors === "function" ? await capabilities.llmRequestInputProcessors({
|
|
24986
|
+
requestContext: result.requestContext,
|
|
24987
|
+
overrides: options.inputProcessors
|
|
24988
|
+
}) : options.inputProcessors || capabilities.llmRequestInputProcessors : effectiveInputProcessors;
|
|
24818
24989
|
const effectiveErrorProcessors = capabilities.errorProcessors ? typeof capabilities.errorProcessors === "function" ? await capabilities.errorProcessors({
|
|
24819
24990
|
requestContext: result.requestContext,
|
|
24820
24991
|
overrides: options.errorProcessors
|
|
@@ -24930,6 +25101,7 @@ function createMapResultsStep({
|
|
|
24930
25101
|
activeTools: options.activeTools,
|
|
24931
25102
|
structuredOutput: options.structuredOutput,
|
|
24932
25103
|
inputProcessors: effectiveInputProcessors,
|
|
25104
|
+
llmRequestInputProcessors: effectiveLLMRequestInputProcessors,
|
|
24933
25105
|
outputProcessors: effectiveOutputProcessors,
|
|
24934
25106
|
errorProcessors: effectiveErrorProcessors,
|
|
24935
25107
|
modelSettings: {
|
|
@@ -25880,11 +26052,10 @@ ${errorMessages}`,
|
|
|
25880
26052
|
return this.combineProcessorsIntoWorkflow(allProcessors, `${this.id}-output-processor`);
|
|
25881
26053
|
}
|
|
25882
26054
|
/**
|
|
25883
|
-
* Resolves
|
|
25884
|
-
* All processors are combined into a single workflow for consistency.
|
|
26055
|
+
* Resolves input processors from agent configuration in execution order.
|
|
25885
26056
|
* @internal
|
|
25886
26057
|
*/
|
|
25887
|
-
async
|
|
26058
|
+
async resolveInputProcessors(requestContext, configuredProcessorOverrides) {
|
|
25888
26059
|
const configuredProcessors = configuredProcessorOverrides ? configuredProcessorOverrides : this.#inputProcessors ? typeof this.#inputProcessors === "function" ? await this.#inputProcessors({
|
|
25889
26060
|
requestContext: requestContext || new RequestContext()
|
|
25890
26061
|
}) : this.#inputProcessors : [];
|
|
@@ -25894,7 +26065,7 @@ ${errorMessages}`,
|
|
|
25894
26065
|
const skillsProcessors = await this.getSkillsProcessors(configuredProcessors, requestContext);
|
|
25895
26066
|
const channelProcessors = this.#agentChannels ? this.#agentChannels.getInputProcessors(configuredProcessors) : [];
|
|
25896
26067
|
const browserProcessors = this.#browser ? this.#browser.getInputProcessors(configuredProcessors) : [];
|
|
25897
|
-
|
|
26068
|
+
return [
|
|
25898
26069
|
...memoryProcessors,
|
|
25899
26070
|
...workspaceProcessors,
|
|
25900
26071
|
...skillsProcessors,
|
|
@@ -25902,7 +26073,23 @@ ${errorMessages}`,
|
|
|
25902
26073
|
...browserProcessors,
|
|
25903
26074
|
...configuredProcessors
|
|
25904
26075
|
];
|
|
25905
|
-
|
|
26076
|
+
}
|
|
26077
|
+
/**
|
|
26078
|
+
* Resolves and returns input processors from agent configuration.
|
|
26079
|
+
* All processors are combined into a single workflow for consistency.
|
|
26080
|
+
* @internal
|
|
26081
|
+
*/
|
|
26082
|
+
async listResolvedInputProcessors(requestContext, configuredProcessorOverrides) {
|
|
26083
|
+
const processors = await this.resolveInputProcessors(requestContext, configuredProcessorOverrides);
|
|
26084
|
+
return this.combineProcessorsIntoWorkflow(processors, `${this.id}-input-processor`);
|
|
26085
|
+
}
|
|
26086
|
+
/**
|
|
26087
|
+
* Resolves and returns input processors for the provider-boundary LLM request hook.
|
|
26088
|
+
* These processors stay uncombined because processLLMRequest runs after conversion to model prompt format.
|
|
26089
|
+
* @internal
|
|
26090
|
+
*/
|
|
26091
|
+
async listResolvedLLMRequestProcessors(requestContext, configuredProcessorOverrides) {
|
|
26092
|
+
return this.resolveInputProcessors(requestContext, configuredProcessorOverrides);
|
|
25906
26093
|
}
|
|
25907
26094
|
/**
|
|
25908
26095
|
* Returns the input processors for this agent, resolving function-based processors if necessary.
|
|
@@ -29285,6 +29472,10 @@ ${effectiveInstructions}`;
|
|
|
29285
29472
|
requestContext: requestContext2,
|
|
29286
29473
|
overrides
|
|
29287
29474
|
}) => this.listResolvedInputProcessors(requestContext2, overrides),
|
|
29475
|
+
llmRequestInputProcessors: async ({
|
|
29476
|
+
requestContext: requestContext2,
|
|
29477
|
+
overrides
|
|
29478
|
+
}) => this.listResolvedLLMRequestProcessors(requestContext2, overrides),
|
|
29288
29479
|
outputProcessors: async ({
|
|
29289
29480
|
requestContext: requestContext2,
|
|
29290
29481
|
overrides
|
|
@@ -32414,6 +32605,55 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
32414
32605
|
}
|
|
32415
32606
|
return stepInput;
|
|
32416
32607
|
}
|
|
32608
|
+
/**
|
|
32609
|
+
* Run processLLMRequest for all processors that implement it.
|
|
32610
|
+
*
|
|
32611
|
+
* Called *after* `MessageList` has been converted to `LanguageModelV2Prompt`
|
|
32612
|
+
* and immediately *before* the prompt is forwarded to the provider.
|
|
32613
|
+
* Mutations are scoped to this single call — they do not affect the
|
|
32614
|
+
* persisted message list, memory, UI, or future model swaps.
|
|
32615
|
+
*/
|
|
32616
|
+
async runProcessLLMRequest(args) {
|
|
32617
|
+
resolveObservabilityContext({ tracingContext: args.tracingContext });
|
|
32618
|
+
let currentPrompt = args.prompt;
|
|
32619
|
+
for (const processorOrWorkflow of this.inputProcessors) {
|
|
32620
|
+
if (isProcessorWorkflow(processorOrWorkflow)) continue;
|
|
32621
|
+
const processor = processorOrWorkflow;
|
|
32622
|
+
const processMethod = processor.processLLMRequest?.bind(processor);
|
|
32623
|
+
if (!processMethod) continue;
|
|
32624
|
+
const abort = (reason, options) => {
|
|
32625
|
+
throw new TripWire(reason || `Tripwire triggered by ${processor.id}`, options, processor.id);
|
|
32626
|
+
};
|
|
32627
|
+
try {
|
|
32628
|
+
const processorState = this.getProcessorState(processor.id);
|
|
32629
|
+
const result = await processMethod({
|
|
32630
|
+
prompt: currentPrompt,
|
|
32631
|
+
// The Processor interface types `model` as `MastraLanguageModel`, but
|
|
32632
|
+
// the runner accepts the looser `unknown` to match other call paths
|
|
32633
|
+
// (e.g. unresolved string ids or function-typed dynamic models).
|
|
32634
|
+
model: args.model,
|
|
32635
|
+
stepNumber: args.stepNumber,
|
|
32636
|
+
steps: args.steps,
|
|
32637
|
+
state: processorState.customState,
|
|
32638
|
+
retryCount: args.retryCount ?? 0,
|
|
32639
|
+
requestContext: args.requestContext,
|
|
32640
|
+
abort,
|
|
32641
|
+
abortSignal: args.abortSignal,
|
|
32642
|
+
writer: args.writer,
|
|
32643
|
+
...createObservabilityContext(args.tracingContext)
|
|
32644
|
+
});
|
|
32645
|
+
if (result && typeof result === "object" && result.prompt) {
|
|
32646
|
+
currentPrompt = result.prompt;
|
|
32647
|
+
}
|
|
32648
|
+
} catch (error) {
|
|
32649
|
+
if (error instanceof TripWire) {
|
|
32650
|
+
await invokeOnViolation(processor, error);
|
|
32651
|
+
}
|
|
32652
|
+
throw error;
|
|
32653
|
+
}
|
|
32654
|
+
}
|
|
32655
|
+
return { prompt: currentPrompt };
|
|
32656
|
+
}
|
|
32417
32657
|
/**
|
|
32418
32658
|
* Type guard to check if result is { messages, systemMessages }
|
|
32419
32659
|
*/
|
|
@@ -32792,6 +33032,6 @@ var ProcessorRunner = class _ProcessorRunner {
|
|
|
32792
33032
|
}
|
|
32793
33033
|
};
|
|
32794
33034
|
|
|
32795
|
-
export { Agent, AgentChannels, AgentsMDInjector, BaseProcessor, BatchPartsProcessor, ChatChannelProcessor, ChunkFrom, CostGuardProcessor, DefaultExecutionEngine, ExecutionEngine, FilePartSchema, ImagePartSchema, LanguageDetector, MastraAgentNetworkStream, MastraMemory, MastraModelOutput, MastraScorer, MastraStateAdapter, MemoryProcessor, MessageContentSchema, MessageHistory, MessagePartSchema, MockMemory, ModerationProcessor, PIIDetector, PrefillErrorHandler, ProcessorInputPhaseSchema, ProcessorInputStepPhaseSchema, ProcessorMessageContentSchema, ProcessorMessageSchema, ProcessorOutputResultPhaseSchema, ProcessorOutputStepPhaseSchema, ProcessorOutputStreamPhaseSchema, ProcessorRunner, ProcessorState, ProcessorStepInputSchema, ProcessorStepOutputSchema, ProcessorStepSchema, PromptInjectionDetector, ProviderHistoryCompat, ReasoningPartSchema, RegexFilterProcessor, Run, SYSTEM_REMINDER_END_TAG, SYSTEM_REMINDER_START_TAG, SaveQueueManager, SemanticRecall, SkillSearchProcessor, SkillsProcessor, SourcePartSchema, StepStartPartSchema, StreamErrorRetryProcessor, StructuredOutputProcessor, SystemPromptScrubber, TextPartSchema, TokenLimiterProcessor, ToolCallFilter, ToolInvocationPartSchema, ToolSearchProcessor, TripWire, UnicodeNormalizer, WORKING_MEMORY_END_TAG, WORKING_MEMORY_START_TAG, Workflow, WorkflowRunOutput, WorkflowScheduler, WorkingMemory, WorkspaceInstructionsProcessor, __registerEventedCreateWorkflow, anthropicToolIdFormat, augmentWithInit, cleanStepResult, cloneStep, cloneWorkflow, computeNextFireAt, convertFullStreamChunkToMastra, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createCachingTransformStream, createDeprecationProxy, createReplayStream, createScorer, createStep, createTimeTravelExecutionParams, createWorkflow, execute, extractWorkingMemoryContent, extractWorkingMemoryTags, filterRun, filterSystemReminderMessages, formatCheckFeedback, formatCompletionFeedback, formatStreamCompletionFeedback, formatValidationFeedback, forwardAgentStreamChunk, generateFinalResult, generateStructuredFinalResult, getResumeLabelsByStepId, getStepIds, getStepResult, getThreadOMMetadata, globalEmbeddingCache, hydrateSerializedStepErrors, isDurableAgentLike, isObservationalMemoryEnabled, isProcessor, isProcessorWorkflow, isRetryableOpenAIResponsesStreamError, isSupportedLanguageModel, isSystemReminderMessage, loop, mapVariable, memoryDefaultOptions, parseMemoryRequestContext, removeSystemReminderTags, removeWorkingMemoryTags, resolveThreadIdFromArgs, runChecks, runCompletionScorers, runCountDeprecationMessage, runDefaultCompletionCheck, runScorer, runStreamCompletionScorers, runValidation, setThreadOMMetadata, summarizeActiveToolsForSpan, summarizeProcessorModelForSpan, summarizeProcessorResultForSpan, summarizeProcessorToolsForSpan, summarizeToolChoiceForSpan, supportedLanguageModelSpecifications, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateCron, validateStepInput, validateStepRequestContext, validateStepResumeData, validateStepStateData, validateStepSuspendData, withStreamCaching };
|
|
32796
|
-
//# sourceMappingURL=chunk-
|
|
32797
|
-
//# sourceMappingURL=chunk-
|
|
33035
|
+
export { Agent, AgentChannels, AgentsMDInjector, BaseProcessor, BatchPartsProcessor, ChatChannelProcessor, ChunkFrom, CostGuardProcessor, DefaultExecutionEngine, ExecutionEngine, FilePartSchema, ImagePartSchema, LanguageDetector, MastraAgentNetworkStream, MastraMemory, MastraModelOutput, MastraScorer, MastraStateAdapter, MemoryProcessor, MessageContentSchema, MessageHistory, MessagePartSchema, MockMemory, ModerationProcessor, PIIDetector, PrefillErrorHandler, ProcessorInputPhaseSchema, ProcessorInputStepPhaseSchema, ProcessorMessageContentSchema, ProcessorMessageSchema, ProcessorOutputResultPhaseSchema, ProcessorOutputStepPhaseSchema, ProcessorOutputStreamPhaseSchema, ProcessorRunner, ProcessorState, ProcessorStepInputSchema, ProcessorStepOutputSchema, ProcessorStepSchema, PromptInjectionDetector, ProviderHistoryCompat, ReasoningPartSchema, RegexFilterProcessor, Run, SYSTEM_REMINDER_END_TAG, SYSTEM_REMINDER_START_TAG, SaveQueueManager, SemanticRecall, SkillSearchProcessor, SkillsProcessor, SourcePartSchema, StepStartPartSchema, StreamErrorRetryProcessor, StructuredOutputProcessor, SystemPromptScrubber, TextPartSchema, TokenLimiterProcessor, ToolCallFilter, ToolInvocationPartSchema, ToolSearchProcessor, TripWire, UnicodeNormalizer, WORKING_MEMORY_END_TAG, WORKING_MEMORY_START_TAG, Workflow, WorkflowRunOutput, WorkflowScheduler, WorkingMemory, WorkspaceInstructionsProcessor, __registerEventedCreateWorkflow, anthropicToolIdFormat, augmentWithInit, cerebrasStripReasoningContent, cleanStepResult, cloneStep, cloneWorkflow, computeNextFireAt, convertFullStreamChunkToMastra, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createCachingTransformStream, createDeprecationProxy, createReplayStream, createScorer, createStep, createTimeTravelExecutionParams, createWorkflow, execute, extractWorkingMemoryContent, extractWorkingMemoryTags, filterRun, filterSystemReminderMessages, formatCheckFeedback, formatCompletionFeedback, formatStreamCompletionFeedback, formatValidationFeedback, forwardAgentStreamChunk, generateFinalResult, generateStructuredFinalResult, getResumeLabelsByStepId, getStepIds, getStepResult, getThreadOMMetadata, globalEmbeddingCache, hydrateSerializedStepErrors, isDurableAgentLike, isObservationalMemoryEnabled, isProcessor, isProcessorWorkflow, isRetryableOpenAIResponsesStreamError, isSupportedLanguageModel, isSystemReminderMessage, loop, mapVariable, memoryDefaultOptions, parseMemoryRequestContext, removeSystemReminderTags, removeWorkingMemoryTags, resolveThreadIdFromArgs, runChecks, runCompletionScorers, runCountDeprecationMessage, runDefaultCompletionCheck, runScorer, runStreamCompletionScorers, runValidation, setThreadOMMetadata, summarizeActiveToolsForSpan, summarizeProcessorModelForSpan, summarizeProcessorResultForSpan, summarizeProcessorToolsForSpan, summarizeToolChoiceForSpan, supportedLanguageModelSpecifications, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateCron, validateStepInput, validateStepRequestContext, validateStepResumeData, validateStepStateData, validateStepSuspendData, withStreamCaching };
|
|
33036
|
+
//# sourceMappingURL=chunk-VQ5BAIDK.js.map
|
|
33037
|
+
//# sourceMappingURL=chunk-VQ5BAIDK.js.map
|