@mastra/core 1.26.0-alpha.11 → 1.26.0-alpha.13
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 +16 -0
- package/dist/agent/agent.d.ts.map +1 -1
- package/dist/agent/index.cjs +8 -8
- package/dist/agent/index.js +1 -1
- package/dist/agent/types.d.ts +7 -1
- package/dist/agent/types.d.ts.map +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 +1 -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-CXIQCUHL.js → chunk-24FTWXDR.js} +3 -3
- package/dist/{chunk-CXIQCUHL.js.map → chunk-24FTWXDR.js.map} +1 -1
- package/dist/{chunk-RSFZN7OV.cjs → chunk-2NQ2TF5F.cjs} +389 -316
- package/dist/chunk-2NQ2TF5F.cjs.map +1 -0
- package/dist/{chunk-ECT5553H.cjs → chunk-34M2QMAZ.cjs} +292 -292
- package/dist/{chunk-ECT5553H.cjs.map → chunk-34M2QMAZ.cjs.map} +1 -1
- package/dist/{chunk-BJCPVJJV.js → chunk-37OQ7B3U.js} +3 -3
- package/dist/{chunk-BJCPVJJV.js.map → chunk-37OQ7B3U.js.map} +1 -1
- package/dist/{chunk-TER3JXU5.cjs → chunk-4MLJKGJI.cjs} +52 -22
- package/dist/chunk-4MLJKGJI.cjs.map +1 -0
- package/dist/{chunk-WBPTY4Y7.cjs → chunk-7IMHDDED.cjs} +57 -57
- package/dist/{chunk-WBPTY4Y7.cjs.map → chunk-7IMHDDED.cjs.map} +1 -1
- package/dist/{chunk-2QPYXXQP.js → chunk-DHKEEJPE.js} +3 -3
- package/dist/{chunk-2QPYXXQP.js.map → chunk-DHKEEJPE.js.map} +1 -1
- package/dist/{chunk-72TFCXLB.js → chunk-DLDGEMBE.js} +381 -308
- package/dist/chunk-DLDGEMBE.js.map +1 -0
- package/dist/{chunk-IFMX323P.cjs → chunk-ER7WPKHP.cjs} +7 -7
- package/dist/{chunk-IFMX323P.cjs.map → chunk-ER7WPKHP.cjs.map} +1 -1
- package/dist/{chunk-5EU2N7AI.js → chunk-FE3JBPGZ.js} +9 -9
- package/dist/{chunk-5EU2N7AI.js.map → chunk-FE3JBPGZ.js.map} +1 -1
- package/dist/{chunk-TJ4FSWVQ.js → chunk-GDUBYVBH.js} +4 -4
- package/dist/{chunk-TJ4FSWVQ.js.map → chunk-GDUBYVBH.js.map} +1 -1
- package/dist/{chunk-6SZ4HY7N.cjs → chunk-GSJT6X23.cjs} +10 -9
- package/dist/chunk-GSJT6X23.cjs.map +1 -0
- package/dist/{chunk-HGZ5C3XG.cjs → chunk-KEXLOZNA.cjs} +17 -17
- package/dist/{chunk-HGZ5C3XG.cjs.map → chunk-KEXLOZNA.cjs.map} +1 -1
- package/dist/{chunk-MT2NFL3T.js → chunk-NTGYHDWA.js} +40 -10
- package/dist/chunk-NTGYHDWA.js.map +1 -0
- package/dist/{chunk-KSTYF5BD.js → chunk-SQAGQFGX.js} +3 -3
- package/dist/{chunk-KSTYF5BD.js.map → chunk-SQAGQFGX.js.map} +1 -1
- package/dist/{chunk-BQN6OA5U.js → chunk-T5WE2PEP.js} +6 -6
- package/dist/{chunk-BQN6OA5U.js.map → chunk-T5WE2PEP.js.map} +1 -1
- package/dist/{chunk-SLO7BNJL.cjs → chunk-TITDW65H.cjs} +9 -9
- package/dist/{chunk-SLO7BNJL.cjs.map → chunk-TITDW65H.cjs.map} +1 -1
- package/dist/{chunk-M7NIAKE6.cjs → chunk-WBZ5SRGR.cjs} +3 -3
- package/dist/{chunk-M7NIAKE6.cjs.map → chunk-WBZ5SRGR.cjs.map} +1 -1
- package/dist/{chunk-B3A3OLBO.cjs → chunk-WDJZB44P.cjs} +224 -224
- package/dist/{chunk-B3A3OLBO.cjs.map → chunk-WDJZB44P.cjs.map} +1 -1
- package/dist/{chunk-HTSHN5E4.js → chunk-WSVLXQT6.js} +8 -7
- package/dist/chunk-WSVLXQT6.js.map +1 -0
- package/dist/{chunk-DELWJ5NK.js → chunk-WYPOS74A.js} +3 -3
- package/dist/{chunk-DELWJ5NK.js.map → chunk-WYPOS74A.js.map} +1 -1
- package/dist/{chunk-5IIRXFH2.cjs → chunk-YQ5QJC3S.cjs} +5 -5
- package/dist/{chunk-5IIRXFH2.cjs.map → chunk-YQ5QJC3S.cjs.map} +1 -1
- package/dist/datasets/experiment/index.d.ts.map +1 -1
- package/dist/datasets/index.cjs +11 -11
- package/dist/datasets/index.js +1 -1
- package/dist/docs/SKILL.md +3 -1
- package/dist/docs/assets/SOURCE_MAP.json +191 -191
- package/dist/docs/references/docs-agents-structured-output.md +22 -0
- package/dist/docs/references/docs-memory-storage.md +1 -0
- package/dist/docs/references/reference-storage-redis.md +266 -0
- package/dist/docs/references/reference-tools-tavily.md +307 -0
- package/dist/docs/references/reference.md +2 -0
- package/dist/evals/index.cjs +5 -5
- 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/index.cjs +7 -7
- package/dist/harness/index.js +5 -5
- 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/provider-types.generated.d.ts +15 -0
- package/dist/loop/index.cjs +14 -14
- package/dist/loop/index.js +1 -1
- package/dist/loop/workflows/agentic-execution/build-messages-from-chunks.d.ts +32 -0
- package/dist/loop/workflows/agentic-execution/build-messages-from-chunks.d.ts.map +1 -0
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/run-state.d.ts +0 -9
- package/dist/loop/workflows/run-state.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/mastra-47JQIPP2.cjs +12 -0
- package/dist/{mastra-UBXRRSVL.cjs.map → mastra-47JQIPP2.cjs.map} +1 -1
- package/dist/mastra-MEZUGGZZ.js +3 -0
- package/dist/{mastra-YR56DXR7.js.map → mastra-MEZUGGZZ.js.map} +1 -1
- package/dist/memory/index.cjs +19 -19
- package/dist/memory/index.js +1 -1
- package/dist/models-dev-BUQGQZCQ.js +3 -0
- package/dist/{models-dev-B24Y4NYV.js.map → models-dev-BUQGQZCQ.js.map} +1 -1
- package/dist/models-dev-INA3VBAK.cjs +12 -0
- package/dist/{models-dev-EMLWCDMI.cjs.map → models-dev-INA3VBAK.cjs.map} +1 -1
- package/dist/netlify-BW7IYASM.cjs +12 -0
- package/dist/{netlify-BFZBVACL.cjs.map → netlify-BW7IYASM.cjs.map} +1 -1
- package/dist/netlify-EQPVEYNW.js +3 -0
- package/dist/{netlify-W7DGKAGR.js.map → netlify-EQPVEYNW.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 +45 -45
- package/dist/processors/index.js +1 -1
- package/dist/processors/processors/structured-output.d.ts +13 -12
- package/dist/processors/processors/structured-output.d.ts.map +1 -1
- package/dist/provider-registry-4FV6CXQI.cjs +44 -0
- package/dist/{provider-registry-OLA6QVLP.cjs.map → provider-registry-4FV6CXQI.cjs.map} +1 -1
- package/dist/provider-registry-EAKPPU44.js +3 -0
- package/dist/{provider-registry-LGHC4U7P.js.map → provider-registry-EAKPPU44.js.map} +1 -1
- package/dist/provider-registry.json +32 -2
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +8 -8
- 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 +24 -24
- package/dist/workflows/index.js +1 -1
- package/package.json +2 -2
- package/src/llm/model/provider-types.generated.d.ts +15 -0
- package/dist/chunk-6SZ4HY7N.cjs.map +0 -1
- package/dist/chunk-72TFCXLB.js.map +0 -1
- package/dist/chunk-HTSHN5E4.js.map +0 -1
- package/dist/chunk-MT2NFL3T.js.map +0 -1
- package/dist/chunk-RSFZN7OV.cjs.map +0 -1
- package/dist/chunk-TER3JXU5.cjs.map +0 -1
- package/dist/mastra-UBXRRSVL.cjs +0 -12
- package/dist/mastra-YR56DXR7.js +0 -3
- package/dist/models-dev-B24Y4NYV.js +0 -3
- package/dist/models-dev-EMLWCDMI.cjs +0 -12
- package/dist/netlify-BFZBVACL.cjs +0 -12
- package/dist/netlify-W7DGKAGR.js +0 -3
- package/dist/provider-registry-LGHC4U7P.js +0 -3
- package/dist/provider-registry-OLA6QVLP.cjs +0 -44
|
@@ -8,7 +8,7 @@ import { generateId, APICallError, tool, asSchema } from './chunk-6PALJNKG.js';
|
|
|
8
8
|
import { noopLogger } from './chunk-7BVF2WMQ.js';
|
|
9
9
|
import { EventEmitterPubSub } from './chunk-II5FASYS.js';
|
|
10
10
|
import { executeHook } from './chunk-L54GIUCB.js';
|
|
11
|
-
import { resolveModelConfig, ModelRouterEmbeddingModel, ModelRouterLanguageModel } from './chunk-
|
|
11
|
+
import { resolveModelConfig, ModelRouterEmbeddingModel, ModelRouterLanguageModel } from './chunk-T5WE2PEP.js';
|
|
12
12
|
import { MastraLLMV1 } from './chunk-YHOV4F62.js';
|
|
13
13
|
import { removeUndefinedValues, safeStringify, ensureToolProperties, makeCoreTool, createMastraProxy, deepMerge, generateEmptyFromSchema, selectFields, ensureSerializable, delay } from './chunk-XYWVTGZY.js';
|
|
14
14
|
import { resolveObservabilityContext, createObservabilityContext, wrapMastra } from './chunk-WA5YOVRJ.js';
|
|
@@ -18,7 +18,7 @@ import { MastraError, getErrorFromUnknown } from './chunk-FJEVLHJT.js';
|
|
|
18
18
|
import { ToolStream } from './chunk-DD2VNRQM.js';
|
|
19
19
|
import { createTool, Tool, isProviderTool, isMastraTool, getProviderToolName, isProviderDefinedTool } from './chunk-O3JJ5ZPY.js';
|
|
20
20
|
import { toStandardSchema, standardSchemaToJSONSchema, isStandardSchemaWithJSON } from './chunk-6SRTDZ7S.js';
|
|
21
|
-
import {
|
|
21
|
+
import { MASTRA_THREAD_ID_KEY, MASTRA_RESOURCE_ID_KEY, RequestContext, MASTRA_VERSIONS_KEY, mergeVersionOverrides } from './chunk-AJVVIFTH.js';
|
|
22
22
|
import { MastraBase } from './chunk-WENZPAHS.js';
|
|
23
23
|
import { RegisteredLogger, ConsoleLogger } from './chunk-DBBWTK24.js';
|
|
24
24
|
import { generateBackgroundTaskSystemPrompt, resolveBackgroundConfig, createBackgroundTask } from './chunk-VMEECRDJ.js';
|
|
@@ -749,6 +749,10 @@ var StructuredOutputProcessor = class {
|
|
|
749
749
|
name = "Structured Output";
|
|
750
750
|
schema;
|
|
751
751
|
structuringAgent;
|
|
752
|
+
structuringModel;
|
|
753
|
+
structuringInstructions;
|
|
754
|
+
agent;
|
|
755
|
+
useAgent = false;
|
|
752
756
|
errorStrategy;
|
|
753
757
|
fallbackValue;
|
|
754
758
|
isStructuringAgentStreamStarted = false;
|
|
@@ -773,49 +777,56 @@ var StructuredOutputProcessor = class {
|
|
|
773
777
|
});
|
|
774
778
|
}
|
|
775
779
|
this.schema = options.schema;
|
|
780
|
+
this.structuringModel = options.model;
|
|
781
|
+
this.useAgent = options.useAgent ?? false;
|
|
776
782
|
this.errorStrategy = options.errorStrategy ?? "strict";
|
|
777
783
|
this.fallbackValue = options.fallbackValue;
|
|
778
784
|
this.jsonPromptInjection = options.jsonPromptInjection;
|
|
779
785
|
this.providerOptions = options.providerOptions;
|
|
780
786
|
this.logger = options.logger;
|
|
787
|
+
this.structuringInstructions = options.instructions || this.generateInstructions();
|
|
781
788
|
this.structuringAgent = new Agent({
|
|
782
789
|
id: "structured-output-structurer",
|
|
783
790
|
name: "structured-output-structurer",
|
|
784
|
-
instructions:
|
|
791
|
+
instructions: this.structuringInstructions,
|
|
785
792
|
model: options.model
|
|
786
793
|
});
|
|
787
794
|
}
|
|
788
795
|
__registerMastra(mastra) {
|
|
789
796
|
this.structuringAgent.__registerMastra(mastra);
|
|
790
797
|
}
|
|
798
|
+
setAgent(agent) {
|
|
799
|
+
this.agent = agent;
|
|
800
|
+
}
|
|
791
801
|
async processOutputStream(args) {
|
|
792
|
-
const { part, state, streamParts, abort, ...rest } = args;
|
|
802
|
+
const { part, state, streamParts, abort, requestContext, messageList, ...rest } = args;
|
|
793
803
|
const observabilityContext = resolveObservabilityContext(rest);
|
|
794
804
|
const controller = state.controller;
|
|
795
805
|
switch (part.type) {
|
|
796
806
|
case "finish":
|
|
797
|
-
await this.processAndEmitStructuredOutput(
|
|
807
|
+
await this.processAndEmitStructuredOutput(
|
|
808
|
+
streamParts,
|
|
809
|
+
controller,
|
|
810
|
+
abort,
|
|
811
|
+
observabilityContext,
|
|
812
|
+
requestContext,
|
|
813
|
+
messageList
|
|
814
|
+
);
|
|
798
815
|
return part;
|
|
799
816
|
default:
|
|
800
817
|
return part;
|
|
801
818
|
}
|
|
802
819
|
}
|
|
803
|
-
async processAndEmitStructuredOutput(streamParts, controller, abort, observabilityContext) {
|
|
820
|
+
async processAndEmitStructuredOutput(streamParts, controller, abort, observabilityContext, requestContext, messageList) {
|
|
804
821
|
if (this.isStructuringAgentStreamStarted) return;
|
|
805
822
|
this.isStructuringAgentStreamStarted = true;
|
|
806
823
|
try {
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
schema: this.schema,
|
|
814
|
-
jsonPromptInjection: this.jsonPromptInjection
|
|
815
|
-
},
|
|
816
|
-
providerOptions: this.providerOptions,
|
|
817
|
-
...observabilityContext
|
|
818
|
-
});
|
|
824
|
+
const structuringAgentStream = await this.getStructuringStream(
|
|
825
|
+
streamParts,
|
|
826
|
+
requestContext,
|
|
827
|
+
messageList,
|
|
828
|
+
observabilityContext
|
|
829
|
+
);
|
|
819
830
|
const excludedChunkTypes = [
|
|
820
831
|
"start",
|
|
821
832
|
"finish",
|
|
@@ -845,7 +856,7 @@ ${structuringPrompt}`;
|
|
|
845
856
|
fallback: true
|
|
846
857
|
}
|
|
847
858
|
};
|
|
848
|
-
controller
|
|
859
|
+
controller?.enqueue(fallbackChunk);
|
|
849
860
|
break;
|
|
850
861
|
}
|
|
851
862
|
}
|
|
@@ -855,12 +866,69 @@ ${structuringPrompt}`;
|
|
|
855
866
|
from: "structured-output"
|
|
856
867
|
}
|
|
857
868
|
};
|
|
858
|
-
controller
|
|
869
|
+
controller?.enqueue(newChunk);
|
|
859
870
|
}
|
|
860
871
|
} catch (error) {
|
|
861
872
|
this.handleError("Structured output processing failed", error, abort);
|
|
862
873
|
}
|
|
863
874
|
}
|
|
875
|
+
/**
|
|
876
|
+
* Get the structuring stream, using the explicit agent with model override and
|
|
877
|
+
* read-only memory when request context provides thread info, falling back to the bare internal agent.
|
|
878
|
+
*/
|
|
879
|
+
async getStructuringStream(streamParts, requestContext, messageList, observabilityContext) {
|
|
880
|
+
const requestThreadId = requestContext?.get(MASTRA_THREAD_ID_KEY);
|
|
881
|
+
const requestResourceId = requestContext?.get(MASTRA_RESOURCE_ID_KEY);
|
|
882
|
+
const serializedMemoryInfo = messageList?.serialize().memoryInfo;
|
|
883
|
+
const threadId = typeof requestThreadId === "string" ? requestThreadId : typeof serializedMemoryInfo?.threadId === "string" ? serializedMemoryInfo.threadId : void 0;
|
|
884
|
+
const resourceId = typeof requestResourceId === "string" ? requestResourceId : typeof serializedMemoryInfo?.resourceId === "string" ? serializedMemoryInfo.resourceId : void 0;
|
|
885
|
+
if (this.useAgent && this.agent && threadId) {
|
|
886
|
+
const promptMessage = {
|
|
887
|
+
role: "user",
|
|
888
|
+
content: [
|
|
889
|
+
{
|
|
890
|
+
type: "text",
|
|
891
|
+
text: `Extract and structure information from the conversation so far. keep the original meaning and details. Rely on the provided text and conversation history`
|
|
892
|
+
}
|
|
893
|
+
]
|
|
894
|
+
};
|
|
895
|
+
const messages = [
|
|
896
|
+
...messageList?.get?.input?.db() || [],
|
|
897
|
+
...messageList?.get?.response?.db() || [],
|
|
898
|
+
promptMessage
|
|
899
|
+
];
|
|
900
|
+
const structuringRequestContext = requestContext ? new RequestContext(requestContext.entries()) : void 0;
|
|
901
|
+
return this.agent.stream(messages, {
|
|
902
|
+
model: this.structuringModel,
|
|
903
|
+
requestContext: structuringRequestContext,
|
|
904
|
+
toolChoice: "none",
|
|
905
|
+
structuredOutput: {
|
|
906
|
+
schema: this.schema,
|
|
907
|
+
jsonPromptInjection: this.jsonPromptInjection
|
|
908
|
+
},
|
|
909
|
+
memory: {
|
|
910
|
+
thread: threadId,
|
|
911
|
+
...resourceId ? { resource: resourceId } : {},
|
|
912
|
+
options: { readOnly: true }
|
|
913
|
+
},
|
|
914
|
+
providerOptions: this.providerOptions,
|
|
915
|
+
...observabilityContext
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
return this.structuringAgent.stream(
|
|
919
|
+
`Extract and structure the key information from the following text according to the specified schema. Keep the original meaning and details. Rely on the provided text and conversation history.
|
|
920
|
+
|
|
921
|
+
${this.buildStructuringPrompt(streamParts)}`,
|
|
922
|
+
{
|
|
923
|
+
structuredOutput: {
|
|
924
|
+
schema: this.schema,
|
|
925
|
+
jsonPromptInjection: this.jsonPromptInjection
|
|
926
|
+
},
|
|
927
|
+
providerOptions: this.providerOptions,
|
|
928
|
+
...observabilityContext
|
|
929
|
+
}
|
|
930
|
+
);
|
|
931
|
+
}
|
|
864
932
|
/**
|
|
865
933
|
* Build a structured markdown prompt from stream parts
|
|
866
934
|
* Collects chunks by type and formats them in a consistent structure
|
|
@@ -3231,11 +3299,12 @@ var MastraModelOutput = class extends MastraBase {
|
|
|
3231
3299
|
} else {
|
|
3232
3300
|
if (!processorStates.has(STRUCTURED_OUTPUT_PROCESSOR_NAME)) {
|
|
3233
3301
|
const processorIndex = processorRunner.outputProcessors.findIndex(
|
|
3234
|
-
(p) => p.
|
|
3302
|
+
(p) => p.id === STRUCTURED_OUTPUT_PROCESSOR_NAME
|
|
3235
3303
|
);
|
|
3236
3304
|
if (processorIndex !== -1) {
|
|
3305
|
+
const structuredOutputProcessor = processorRunner.outputProcessors[processorIndex];
|
|
3237
3306
|
const structuredOutputProcessorState = new ProcessorState({
|
|
3238
|
-
processorName: STRUCTURED_OUTPUT_PROCESSOR_NAME,
|
|
3307
|
+
processorName: structuredOutputProcessor?.name ?? STRUCTURED_OUTPUT_PROCESSOR_NAME,
|
|
3239
3308
|
tracingContext: options.tracingContext,
|
|
3240
3309
|
processorIndex,
|
|
3241
3310
|
createSpan: true
|
|
@@ -14166,7 +14235,7 @@ function execute({
|
|
|
14166
14235
|
schema: responseFormat.schema
|
|
14167
14236
|
});
|
|
14168
14237
|
}
|
|
14169
|
-
if (structuredOutputMode === "processor" && responseFormat?.type === "json" && responseFormat?.schema) {
|
|
14238
|
+
if (structuredOutputMode === "processor" && responseFormat?.type === "json" && responseFormat?.schema && !structuredOutput?.useAgent) {
|
|
14170
14239
|
prompt = injectJsonInstructionIntoMessages({
|
|
14171
14240
|
messages: inputMessages,
|
|
14172
14241
|
schema: responseFormat.schema,
|
|
@@ -14346,15 +14415,10 @@ var AgenticRunState = class {
|
|
|
14346
14415
|
modelVersion: model.specificationVersion,
|
|
14347
14416
|
modelProvider: model.provider
|
|
14348
14417
|
},
|
|
14349
|
-
isReasoning: false,
|
|
14350
|
-
isStreaming: false,
|
|
14351
14418
|
providerOptions: void 0,
|
|
14352
|
-
hasToolCallStreaming: false,
|
|
14353
14419
|
hasErrored: false,
|
|
14354
14420
|
apiError: void 0,
|
|
14355
14421
|
deferredErrorChunk: void 0,
|
|
14356
|
-
reasoningBuffers: /* @__PURE__ */ new Map(),
|
|
14357
|
-
textDeltas: [],
|
|
14358
14422
|
stepResult: void 0
|
|
14359
14423
|
};
|
|
14360
14424
|
}
|
|
@@ -14369,6 +14433,265 @@ var AgenticRunState = class {
|
|
|
14369
14433
|
}
|
|
14370
14434
|
};
|
|
14371
14435
|
|
|
14436
|
+
// src/loop/workflows/agentic-execution/build-messages-from-chunks.ts
|
|
14437
|
+
function buildMessagesFromChunks({
|
|
14438
|
+
chunks,
|
|
14439
|
+
messageId,
|
|
14440
|
+
responseModelMetadata,
|
|
14441
|
+
tools
|
|
14442
|
+
}) {
|
|
14443
|
+
const parts = [];
|
|
14444
|
+
const toolResults = /* @__PURE__ */ new Map();
|
|
14445
|
+
for (const chunk of chunks) {
|
|
14446
|
+
if (chunk.type === "tool-result" && chunk.payload.result != null) {
|
|
14447
|
+
const p = chunk.payload;
|
|
14448
|
+
toolResults.set(p.toolCallId, {
|
|
14449
|
+
result: p.result,
|
|
14450
|
+
args: p.args,
|
|
14451
|
+
providerMetadata: p.providerMetadata,
|
|
14452
|
+
providerExecuted: p.providerExecuted,
|
|
14453
|
+
toolName: p.toolName
|
|
14454
|
+
});
|
|
14455
|
+
}
|
|
14456
|
+
}
|
|
14457
|
+
const textSpans = /* @__PURE__ */ new Map();
|
|
14458
|
+
const reasoningSpans = /* @__PURE__ */ new Map();
|
|
14459
|
+
for (const chunk of chunks) {
|
|
14460
|
+
switch (chunk.type) {
|
|
14461
|
+
// ── Text span ──────────────────────────────────────────────
|
|
14462
|
+
case "text-start": {
|
|
14463
|
+
const p = chunk.payload;
|
|
14464
|
+
if (!textSpans.has(p.id)) {
|
|
14465
|
+
textSpans.set(p.id, {
|
|
14466
|
+
deltas: [],
|
|
14467
|
+
providerMetadata: p.providerMetadata
|
|
14468
|
+
});
|
|
14469
|
+
} else {
|
|
14470
|
+
const existing = textSpans.get(p.id);
|
|
14471
|
+
if (p.providerMetadata) {
|
|
14472
|
+
existing.providerMetadata = p.providerMetadata;
|
|
14473
|
+
}
|
|
14474
|
+
}
|
|
14475
|
+
break;
|
|
14476
|
+
}
|
|
14477
|
+
case "text-delta": {
|
|
14478
|
+
const p = chunk.payload;
|
|
14479
|
+
let span = textSpans.get(p.id);
|
|
14480
|
+
if (!span) {
|
|
14481
|
+
span = { deltas: [], providerMetadata: p.providerMetadata };
|
|
14482
|
+
textSpans.set(p.id, span);
|
|
14483
|
+
}
|
|
14484
|
+
span.deltas.push(p.text);
|
|
14485
|
+
if (p.providerMetadata) {
|
|
14486
|
+
span.providerMetadata = p.providerMetadata;
|
|
14487
|
+
}
|
|
14488
|
+
break;
|
|
14489
|
+
}
|
|
14490
|
+
case "text-end": {
|
|
14491
|
+
const pEnd = chunk.payload;
|
|
14492
|
+
const span = textSpans.get(pEnd.id);
|
|
14493
|
+
if (span) {
|
|
14494
|
+
if (pEnd.providerMetadata) {
|
|
14495
|
+
span.providerMetadata = pEnd.providerMetadata;
|
|
14496
|
+
}
|
|
14497
|
+
const text = span.deltas.join("");
|
|
14498
|
+
if (text.length > 0) {
|
|
14499
|
+
parts.push({
|
|
14500
|
+
type: "text",
|
|
14501
|
+
text,
|
|
14502
|
+
...span.providerMetadata ? { providerMetadata: span.providerMetadata } : {}
|
|
14503
|
+
});
|
|
14504
|
+
}
|
|
14505
|
+
textSpans.delete(pEnd.id);
|
|
14506
|
+
}
|
|
14507
|
+
break;
|
|
14508
|
+
}
|
|
14509
|
+
// ── Reasoning span ─────────────────────────────────────────
|
|
14510
|
+
case "reasoning-start": {
|
|
14511
|
+
const p = chunk.payload;
|
|
14512
|
+
const isRedacted = Object.values(p.providerMetadata || {}).some((v) => v?.redactedData);
|
|
14513
|
+
if (!reasoningSpans.has(p.id)) {
|
|
14514
|
+
reasoningSpans.set(p.id, {
|
|
14515
|
+
deltas: [],
|
|
14516
|
+
providerMetadata: p.providerMetadata,
|
|
14517
|
+
redacted: isRedacted
|
|
14518
|
+
});
|
|
14519
|
+
} else {
|
|
14520
|
+
const existing = reasoningSpans.get(p.id);
|
|
14521
|
+
if (p.providerMetadata) {
|
|
14522
|
+
existing.providerMetadata = p.providerMetadata;
|
|
14523
|
+
}
|
|
14524
|
+
if (isRedacted) {
|
|
14525
|
+
existing.redacted = true;
|
|
14526
|
+
}
|
|
14527
|
+
}
|
|
14528
|
+
break;
|
|
14529
|
+
}
|
|
14530
|
+
case "reasoning-delta": {
|
|
14531
|
+
const p = chunk.payload;
|
|
14532
|
+
let span = reasoningSpans.get(p.id);
|
|
14533
|
+
if (!span) {
|
|
14534
|
+
span = { deltas: [], providerMetadata: p.providerMetadata, redacted: false };
|
|
14535
|
+
reasoningSpans.set(p.id, span);
|
|
14536
|
+
}
|
|
14537
|
+
span.deltas.push(p.text);
|
|
14538
|
+
if (p.providerMetadata) {
|
|
14539
|
+
span.providerMetadata = p.providerMetadata;
|
|
14540
|
+
}
|
|
14541
|
+
break;
|
|
14542
|
+
}
|
|
14543
|
+
case "reasoning-end": {
|
|
14544
|
+
const p = chunk.payload;
|
|
14545
|
+
const span = reasoningSpans.get(p.id);
|
|
14546
|
+
if (span) {
|
|
14547
|
+
if (p.providerMetadata) {
|
|
14548
|
+
span.providerMetadata = p.providerMetadata;
|
|
14549
|
+
}
|
|
14550
|
+
if (span.redacted) {
|
|
14551
|
+
parts.push({
|
|
14552
|
+
type: "reasoning",
|
|
14553
|
+
reasoning: "",
|
|
14554
|
+
details: [{ type: "redacted", data: "" }],
|
|
14555
|
+
providerMetadata: span.providerMetadata
|
|
14556
|
+
});
|
|
14557
|
+
} else {
|
|
14558
|
+
parts.push({
|
|
14559
|
+
type: "reasoning",
|
|
14560
|
+
reasoning: "",
|
|
14561
|
+
details: [{ type: "text", text: span.deltas.join("") }],
|
|
14562
|
+
providerMetadata: span.providerMetadata
|
|
14563
|
+
});
|
|
14564
|
+
}
|
|
14565
|
+
reasoningSpans.delete(p.id);
|
|
14566
|
+
}
|
|
14567
|
+
break;
|
|
14568
|
+
}
|
|
14569
|
+
// Redacted reasoning can appear as a standalone chunk (not wrapped in start/end)
|
|
14570
|
+
case "redacted-reasoning": {
|
|
14571
|
+
const p = chunk.payload;
|
|
14572
|
+
parts.push({
|
|
14573
|
+
type: "reasoning",
|
|
14574
|
+
reasoning: "",
|
|
14575
|
+
details: [{ type: "redacted", data: "" }],
|
|
14576
|
+
providerMetadata: p.providerMetadata
|
|
14577
|
+
});
|
|
14578
|
+
break;
|
|
14579
|
+
}
|
|
14580
|
+
// ── Source ──────────────────────────────────────────────────
|
|
14581
|
+
case "source": {
|
|
14582
|
+
const p = chunk.payload;
|
|
14583
|
+
parts.push({
|
|
14584
|
+
type: "source",
|
|
14585
|
+
source: {
|
|
14586
|
+
sourceType: "url",
|
|
14587
|
+
id: p.id,
|
|
14588
|
+
url: p.url || "",
|
|
14589
|
+
title: p.title,
|
|
14590
|
+
providerMetadata: p.providerMetadata
|
|
14591
|
+
}
|
|
14592
|
+
});
|
|
14593
|
+
break;
|
|
14594
|
+
}
|
|
14595
|
+
// ── File ───────────────────────────────────────────────────
|
|
14596
|
+
case "file": {
|
|
14597
|
+
const p = chunk.payload;
|
|
14598
|
+
parts.push({
|
|
14599
|
+
type: "file",
|
|
14600
|
+
data: p.data,
|
|
14601
|
+
mimeType: p.mimeType,
|
|
14602
|
+
...p.providerMetadata ? { providerMetadata: p.providerMetadata } : {}
|
|
14603
|
+
});
|
|
14604
|
+
break;
|
|
14605
|
+
}
|
|
14606
|
+
// ── Tool call ──────────────────────────────────────────────
|
|
14607
|
+
case "tool-call": {
|
|
14608
|
+
const p = chunk.payload;
|
|
14609
|
+
const toolDef = tools?.[p.toolName] || findProviderToolByName(tools, p.toolName);
|
|
14610
|
+
const providerExecuted = inferProviderExecuted(p.providerExecuted, toolDef);
|
|
14611
|
+
const result = toolResults.get(p.toolCallId);
|
|
14612
|
+
if (result) {
|
|
14613
|
+
const resultProviderExecuted = inferProviderExecuted(result.providerExecuted, toolDef);
|
|
14614
|
+
parts.push({
|
|
14615
|
+
type: "tool-invocation",
|
|
14616
|
+
toolInvocation: {
|
|
14617
|
+
state: "result",
|
|
14618
|
+
toolCallId: p.toolCallId,
|
|
14619
|
+
toolName: p.toolName,
|
|
14620
|
+
args: p.args,
|
|
14621
|
+
result: result.result
|
|
14622
|
+
},
|
|
14623
|
+
providerMetadata: result.providerMetadata ?? p.providerMetadata,
|
|
14624
|
+
providerExecuted: resultProviderExecuted
|
|
14625
|
+
});
|
|
14626
|
+
} else {
|
|
14627
|
+
parts.push({
|
|
14628
|
+
type: "tool-invocation",
|
|
14629
|
+
toolInvocation: {
|
|
14630
|
+
state: "call",
|
|
14631
|
+
toolCallId: p.toolCallId,
|
|
14632
|
+
toolName: p.toolName,
|
|
14633
|
+
args: p.args
|
|
14634
|
+
},
|
|
14635
|
+
providerMetadata: p.providerMetadata,
|
|
14636
|
+
providerExecuted
|
|
14637
|
+
});
|
|
14638
|
+
}
|
|
14639
|
+
break;
|
|
14640
|
+
}
|
|
14641
|
+
}
|
|
14642
|
+
}
|
|
14643
|
+
for (const [_id, span] of reasoningSpans) {
|
|
14644
|
+
if (span.redacted) {
|
|
14645
|
+
parts.push({
|
|
14646
|
+
type: "reasoning",
|
|
14647
|
+
reasoning: "",
|
|
14648
|
+
details: [{ type: "redacted", data: "" }],
|
|
14649
|
+
providerMetadata: span.providerMetadata
|
|
14650
|
+
});
|
|
14651
|
+
} else {
|
|
14652
|
+
const text = span.deltas.join("");
|
|
14653
|
+
parts.push({
|
|
14654
|
+
type: "reasoning",
|
|
14655
|
+
reasoning: "",
|
|
14656
|
+
details: [{ type: "text", text }],
|
|
14657
|
+
providerMetadata: span.providerMetadata
|
|
14658
|
+
});
|
|
14659
|
+
}
|
|
14660
|
+
}
|
|
14661
|
+
for (const [, span] of textSpans) {
|
|
14662
|
+
const text = span.deltas.join("");
|
|
14663
|
+
if (text.length > 0) {
|
|
14664
|
+
parts.push({
|
|
14665
|
+
type: "text",
|
|
14666
|
+
text,
|
|
14667
|
+
...span.providerMetadata ? { providerMetadata: span.providerMetadata } : {}
|
|
14668
|
+
});
|
|
14669
|
+
}
|
|
14670
|
+
}
|
|
14671
|
+
const finalParts = [];
|
|
14672
|
+
for (let i = 0; i < parts.length; i++) {
|
|
14673
|
+
const part = parts[i];
|
|
14674
|
+
if (part.type === "text" && finalParts.length > 0 && finalParts[finalParts.length - 1]?.type === "tool-invocation") {
|
|
14675
|
+
finalParts.push({ type: "step-start" });
|
|
14676
|
+
}
|
|
14677
|
+
finalParts.push(part);
|
|
14678
|
+
}
|
|
14679
|
+
if (finalParts.length === 0) {
|
|
14680
|
+
return [];
|
|
14681
|
+
}
|
|
14682
|
+
const message = {
|
|
14683
|
+
id: messageId,
|
|
14684
|
+
role: "assistant",
|
|
14685
|
+
content: {
|
|
14686
|
+
format: 2,
|
|
14687
|
+
parts: finalParts,
|
|
14688
|
+
...responseModelMetadata
|
|
14689
|
+
},
|
|
14690
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
14691
|
+
};
|
|
14692
|
+
return [message];
|
|
14693
|
+
}
|
|
14694
|
+
|
|
14372
14695
|
// src/loop/workflows/agentic-execution/llm-execution-step.ts
|
|
14373
14696
|
function buildResponseModelMetadata(runState, model) {
|
|
14374
14697
|
const metadata = {};
|
|
@@ -14381,39 +14704,12 @@ function buildResponseModelMetadata(runState, model) {
|
|
|
14381
14704
|
}
|
|
14382
14705
|
return Object.keys(metadata).length > 0 ? { metadata } : void 0;
|
|
14383
14706
|
}
|
|
14384
|
-
function flushReasoningBuffer({
|
|
14385
|
-
buffer,
|
|
14386
|
-
messageId,
|
|
14387
|
-
messageList,
|
|
14388
|
-
runState,
|
|
14389
|
-
model
|
|
14390
|
-
}) {
|
|
14391
|
-
const message = {
|
|
14392
|
-
id: messageId,
|
|
14393
|
-
role: "assistant",
|
|
14394
|
-
content: {
|
|
14395
|
-
format: 2,
|
|
14396
|
-
parts: [
|
|
14397
|
-
{
|
|
14398
|
-
type: "reasoning",
|
|
14399
|
-
reasoning: "",
|
|
14400
|
-
details: [{ type: "text", text: buffer.deltas.join("") }],
|
|
14401
|
-
providerMetadata: buffer.providerMetadata
|
|
14402
|
-
}
|
|
14403
|
-
],
|
|
14404
|
-
...buildResponseModelMetadata(runState, model)
|
|
14405
|
-
},
|
|
14406
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
14407
|
-
};
|
|
14408
|
-
messageList.add(message, "response");
|
|
14409
|
-
}
|
|
14410
14707
|
async function processOutputStream({
|
|
14411
14708
|
tools,
|
|
14412
14709
|
messageId,
|
|
14413
14710
|
messageList,
|
|
14414
14711
|
outputStream,
|
|
14415
14712
|
runState,
|
|
14416
|
-
model,
|
|
14417
14713
|
options,
|
|
14418
14714
|
controller,
|
|
14419
14715
|
responseFromModel,
|
|
@@ -14423,6 +14719,7 @@ async function processOutputStream({
|
|
|
14423
14719
|
transportResolver
|
|
14424
14720
|
}) {
|
|
14425
14721
|
let transportSet = false;
|
|
14722
|
+
const collectedChunks = [];
|
|
14426
14723
|
for await (const chunk of outputStream._getBaseStream()) {
|
|
14427
14724
|
if (options?.abortSignal?.aborted) {
|
|
14428
14725
|
break;
|
|
@@ -14441,60 +14738,7 @@ async function processOutputStream({
|
|
|
14441
14738
|
controller.enqueue(chunk);
|
|
14442
14739
|
continue;
|
|
14443
14740
|
}
|
|
14444
|
-
|
|
14445
|
-
// basically for some llm providers they add response-metadata after each text-delta
|
|
14446
|
-
// we then flush the chunks by calling messageList.add (a few lines down)
|
|
14447
|
-
// this results in a bunch of weird separated text chunks on the message instead of combined chunks
|
|
14448
|
-
// easiest solution here is to just not flush for response-metadata
|
|
14449
|
-
// BUT does this cause other issues?
|
|
14450
|
-
// Alternative solution: in message list allow combining text deltas together when the message source is "response" and the text parts are directly next to each other
|
|
14451
|
-
// simple solution for now is to not flush text deltas on response-metadata
|
|
14452
|
-
chunk.type !== "response-metadata" && // Don't flush on source chunks - OpenAI web search interleaves source citations
|
|
14453
|
-
// with text-deltas, all sharing the same itemId. Flushing creates multiple parts
|
|
14454
|
-
// with duplicate itemIds, causing "Duplicate item found" errors on the next request.
|
|
14455
|
-
chunk.type !== "source" && runState.state.isStreaming) {
|
|
14456
|
-
if (runState.state.textDeltas.length) {
|
|
14457
|
-
const textStartPayload = chunk.payload;
|
|
14458
|
-
const providerMetadata = textStartPayload.providerMetadata ?? runState.state.providerOptions;
|
|
14459
|
-
const message = {
|
|
14460
|
-
id: messageId,
|
|
14461
|
-
role: "assistant",
|
|
14462
|
-
content: {
|
|
14463
|
-
format: 2,
|
|
14464
|
-
parts: [
|
|
14465
|
-
{
|
|
14466
|
-
type: "text",
|
|
14467
|
-
text: runState.state.textDeltas.join(""),
|
|
14468
|
-
...providerMetadata ? { providerMetadata } : {}
|
|
14469
|
-
}
|
|
14470
|
-
],
|
|
14471
|
-
...buildResponseModelMetadata(runState, model)
|
|
14472
|
-
},
|
|
14473
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
14474
|
-
};
|
|
14475
|
-
messageList.add(message, "response");
|
|
14476
|
-
}
|
|
14477
|
-
runState.setState({
|
|
14478
|
-
isStreaming: false,
|
|
14479
|
-
textDeltas: []
|
|
14480
|
-
});
|
|
14481
|
-
}
|
|
14482
|
-
if (chunk.type !== "reasoning-start" && chunk.type !== "reasoning-delta" && chunk.type !== "reasoning-end" && chunk.type !== "redacted-reasoning" && chunk.type !== "reasoning-signature" && chunk.type !== "response-metadata" && chunk.type !== "text-start" && runState.state.isReasoning) {
|
|
14483
|
-
for (const buffer of runState.state.reasoningBuffers.values()) {
|
|
14484
|
-
flushReasoningBuffer({
|
|
14485
|
-
buffer,
|
|
14486
|
-
messageId,
|
|
14487
|
-
messageList,
|
|
14488
|
-
runState,
|
|
14489
|
-
model
|
|
14490
|
-
});
|
|
14491
|
-
}
|
|
14492
|
-
runState.setState({
|
|
14493
|
-
isReasoning: false,
|
|
14494
|
-
reasoningBuffers: /* @__PURE__ */ new Map(),
|
|
14495
|
-
providerOptions: void 0
|
|
14496
|
-
});
|
|
14497
|
-
}
|
|
14741
|
+
collectedChunks.push({ type: chunk.type, payload: chunk.payload });
|
|
14498
14742
|
switch (chunk.type) {
|
|
14499
14743
|
case "response-metadata":
|
|
14500
14744
|
runState.setState({
|
|
@@ -14506,32 +14750,6 @@ async function processOutputStream({
|
|
|
14506
14750
|
}
|
|
14507
14751
|
});
|
|
14508
14752
|
break;
|
|
14509
|
-
case "text-start": {
|
|
14510
|
-
if (chunk.payload.providerMetadata) {
|
|
14511
|
-
runState.setState({
|
|
14512
|
-
providerOptions: chunk.payload.providerMetadata
|
|
14513
|
-
});
|
|
14514
|
-
}
|
|
14515
|
-
safeEnqueue(controller, chunk);
|
|
14516
|
-
break;
|
|
14517
|
-
}
|
|
14518
|
-
case "text-delta": {
|
|
14519
|
-
const textDeltasFromState = runState.state.textDeltas;
|
|
14520
|
-
textDeltasFromState.push(chunk.payload.text);
|
|
14521
|
-
runState.setState({
|
|
14522
|
-
textDeltas: textDeltasFromState,
|
|
14523
|
-
isStreaming: true
|
|
14524
|
-
});
|
|
14525
|
-
safeEnqueue(controller, chunk);
|
|
14526
|
-
break;
|
|
14527
|
-
}
|
|
14528
|
-
case "text-end": {
|
|
14529
|
-
runState.setState({
|
|
14530
|
-
providerOptions: void 0
|
|
14531
|
-
});
|
|
14532
|
-
safeEnqueue(controller, chunk);
|
|
14533
|
-
break;
|
|
14534
|
-
}
|
|
14535
14753
|
case "tool-call-input-streaming-start": {
|
|
14536
14754
|
const tool2 = tools?.[chunk.payload.toolName] || Object.values(tools || {})?.find((tool3) => `id` in tool3 && tool3.id === chunk.payload.toolName);
|
|
14537
14755
|
if (tool2 && "onInputStart" in tool2) {
|
|
@@ -14565,145 +14783,6 @@ async function processOutputStream({
|
|
|
14565
14783
|
safeEnqueue(controller, chunk);
|
|
14566
14784
|
break;
|
|
14567
14785
|
}
|
|
14568
|
-
case "tool-call-input-streaming-end": {
|
|
14569
|
-
safeEnqueue(controller, chunk);
|
|
14570
|
-
break;
|
|
14571
|
-
}
|
|
14572
|
-
case "reasoning-start": {
|
|
14573
|
-
const reasoningBuffers = new Map(runState.state.reasoningBuffers);
|
|
14574
|
-
reasoningBuffers.set(chunk.payload.id, {
|
|
14575
|
-
deltas: reasoningBuffers.get(chunk.payload.id)?.deltas ?? [],
|
|
14576
|
-
providerMetadata: chunk.payload.providerMetadata ?? reasoningBuffers.get(chunk.payload.id)?.providerMetadata
|
|
14577
|
-
});
|
|
14578
|
-
runState.setState({
|
|
14579
|
-
isReasoning: true,
|
|
14580
|
-
reasoningBuffers,
|
|
14581
|
-
providerOptions: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
14582
|
-
});
|
|
14583
|
-
if (Object.values(chunk.payload.providerMetadata || {}).find((v) => v?.redactedData)) {
|
|
14584
|
-
const message = {
|
|
14585
|
-
id: messageId,
|
|
14586
|
-
role: "assistant",
|
|
14587
|
-
content: {
|
|
14588
|
-
format: 2,
|
|
14589
|
-
parts: [
|
|
14590
|
-
{
|
|
14591
|
-
type: "reasoning",
|
|
14592
|
-
reasoning: "",
|
|
14593
|
-
details: [{ type: "redacted", data: "" }],
|
|
14594
|
-
providerMetadata: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
14595
|
-
}
|
|
14596
|
-
],
|
|
14597
|
-
...buildResponseModelMetadata(runState, model)
|
|
14598
|
-
},
|
|
14599
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
14600
|
-
};
|
|
14601
|
-
messageList.add(message, "response");
|
|
14602
|
-
safeEnqueue(controller, chunk);
|
|
14603
|
-
break;
|
|
14604
|
-
}
|
|
14605
|
-
safeEnqueue(controller, chunk);
|
|
14606
|
-
break;
|
|
14607
|
-
}
|
|
14608
|
-
case "reasoning-delta": {
|
|
14609
|
-
const reasoningBuffers = new Map(runState.state.reasoningBuffers);
|
|
14610
|
-
const existingBuffer = reasoningBuffers.get(chunk.payload.id);
|
|
14611
|
-
const buffer = {
|
|
14612
|
-
deltas: [...existingBuffer?.deltas ?? [], chunk.payload.text],
|
|
14613
|
-
providerMetadata: chunk.payload.providerMetadata ?? existingBuffer?.providerMetadata
|
|
14614
|
-
};
|
|
14615
|
-
reasoningBuffers.set(chunk.payload.id, buffer);
|
|
14616
|
-
runState.setState({
|
|
14617
|
-
isReasoning: true,
|
|
14618
|
-
reasoningBuffers,
|
|
14619
|
-
providerOptions: chunk.payload.providerMetadata ?? runState.state.providerOptions
|
|
14620
|
-
});
|
|
14621
|
-
safeEnqueue(controller, chunk);
|
|
14622
|
-
break;
|
|
14623
|
-
}
|
|
14624
|
-
case "reasoning-end": {
|
|
14625
|
-
if (!runState.state.isReasoning) {
|
|
14626
|
-
safeEnqueue(controller, chunk);
|
|
14627
|
-
break;
|
|
14628
|
-
}
|
|
14629
|
-
const reasoningBuffers = new Map(runState.state.reasoningBuffers);
|
|
14630
|
-
const buffer = reasoningBuffers.get(chunk.payload.id);
|
|
14631
|
-
if (!buffer) {
|
|
14632
|
-
safeEnqueue(controller, chunk);
|
|
14633
|
-
break;
|
|
14634
|
-
}
|
|
14635
|
-
flushReasoningBuffer({
|
|
14636
|
-
buffer: {
|
|
14637
|
-
deltas: buffer.deltas,
|
|
14638
|
-
providerMetadata: chunk.payload.providerMetadata ?? buffer.providerMetadata
|
|
14639
|
-
},
|
|
14640
|
-
messageId,
|
|
14641
|
-
messageList,
|
|
14642
|
-
runState,
|
|
14643
|
-
model
|
|
14644
|
-
});
|
|
14645
|
-
reasoningBuffers.delete(chunk.payload.id);
|
|
14646
|
-
const nextProviderOptions = Array.from(reasoningBuffers.values()).at(-1)?.providerMetadata;
|
|
14647
|
-
runState.setState({
|
|
14648
|
-
isReasoning: reasoningBuffers.size > 0,
|
|
14649
|
-
reasoningBuffers,
|
|
14650
|
-
providerOptions: nextProviderOptions
|
|
14651
|
-
});
|
|
14652
|
-
safeEnqueue(controller, chunk);
|
|
14653
|
-
break;
|
|
14654
|
-
}
|
|
14655
|
-
case "file":
|
|
14656
|
-
{
|
|
14657
|
-
const message = {
|
|
14658
|
-
id: messageId,
|
|
14659
|
-
role: "assistant",
|
|
14660
|
-
content: {
|
|
14661
|
-
format: 2,
|
|
14662
|
-
parts: [
|
|
14663
|
-
{
|
|
14664
|
-
type: "file",
|
|
14665
|
-
// @ts-expect-error - data type mismatch, see TODO
|
|
14666
|
-
data: chunk.payload.data,
|
|
14667
|
-
// TODO: incorrect string type
|
|
14668
|
-
mimeType: chunk.payload.mimeType,
|
|
14669
|
-
...chunk.payload.providerMetadata ? { providerMetadata: chunk.payload.providerMetadata } : {}
|
|
14670
|
-
}
|
|
14671
|
-
],
|
|
14672
|
-
...buildResponseModelMetadata(runState, model)
|
|
14673
|
-
},
|
|
14674
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
14675
|
-
};
|
|
14676
|
-
messageList.add(message, "response");
|
|
14677
|
-
safeEnqueue(controller, chunk);
|
|
14678
|
-
}
|
|
14679
|
-
break;
|
|
14680
|
-
case "source":
|
|
14681
|
-
{
|
|
14682
|
-
const message = {
|
|
14683
|
-
id: messageId,
|
|
14684
|
-
role: "assistant",
|
|
14685
|
-
content: {
|
|
14686
|
-
format: 2,
|
|
14687
|
-
parts: [
|
|
14688
|
-
{
|
|
14689
|
-
type: "source",
|
|
14690
|
-
source: {
|
|
14691
|
-
sourceType: "url",
|
|
14692
|
-
id: chunk.payload.id,
|
|
14693
|
-
url: chunk.payload.url || "",
|
|
14694
|
-
title: chunk.payload.title,
|
|
14695
|
-
providerMetadata: chunk.payload.providerMetadata
|
|
14696
|
-
}
|
|
14697
|
-
}
|
|
14698
|
-
],
|
|
14699
|
-
...buildResponseModelMetadata(runState, model)
|
|
14700
|
-
},
|
|
14701
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
14702
|
-
};
|
|
14703
|
-
messageList.add(message, "response");
|
|
14704
|
-
safeEnqueue(controller, chunk);
|
|
14705
|
-
}
|
|
14706
|
-
break;
|
|
14707
14786
|
case "finish":
|
|
14708
14787
|
runState.setState({
|
|
14709
14788
|
providerOptions: chunk.payload.metadata?.providerMetadata ?? chunk.payload.providerMetadata,
|
|
@@ -14737,8 +14816,6 @@ async function processOutputStream({
|
|
|
14737
14816
|
deferredErrorChunk: chunk
|
|
14738
14817
|
});
|
|
14739
14818
|
break;
|
|
14740
|
-
// Provider-executed tool results (e.g. web_search). Client tool results
|
|
14741
|
-
// are handled by llm-mapping-step after execution.
|
|
14742
14819
|
case "tool-result": {
|
|
14743
14820
|
if (chunk.payload.result != null) {
|
|
14744
14821
|
const resultToolDef = tools?.[chunk.payload.toolName] || findProviderToolByName(tools, chunk.payload.toolName);
|
|
@@ -14758,34 +14835,6 @@ async function processOutputStream({
|
|
|
14758
14835
|
safeEnqueue(controller, chunk);
|
|
14759
14836
|
break;
|
|
14760
14837
|
}
|
|
14761
|
-
case "tool-call": {
|
|
14762
|
-
const toolDef = tools?.[chunk.payload.toolName] || findProviderToolByName(tools, chunk.payload.toolName);
|
|
14763
|
-
const inferredProviderExecuted = inferProviderExecuted(chunk.payload.providerExecuted, toolDef);
|
|
14764
|
-
const toolCallPart = {
|
|
14765
|
-
type: "tool-invocation",
|
|
14766
|
-
toolInvocation: {
|
|
14767
|
-
state: "call",
|
|
14768
|
-
toolCallId: chunk.payload.toolCallId,
|
|
14769
|
-
toolName: chunk.payload.toolName,
|
|
14770
|
-
args: chunk.payload.args
|
|
14771
|
-
},
|
|
14772
|
-
providerMetadata: chunk.payload.providerMetadata,
|
|
14773
|
-
providerExecuted: inferredProviderExecuted
|
|
14774
|
-
};
|
|
14775
|
-
const message = {
|
|
14776
|
-
id: messageId,
|
|
14777
|
-
role: "assistant",
|
|
14778
|
-
content: {
|
|
14779
|
-
format: 2,
|
|
14780
|
-
parts: [toolCallPart],
|
|
14781
|
-
...buildResponseModelMetadata(runState, model)
|
|
14782
|
-
},
|
|
14783
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
14784
|
-
};
|
|
14785
|
-
messageList.add(message, "response");
|
|
14786
|
-
safeEnqueue(controller, chunk);
|
|
14787
|
-
break;
|
|
14788
|
-
}
|
|
14789
14838
|
default:
|
|
14790
14839
|
safeEnqueue(controller, chunk);
|
|
14791
14840
|
}
|
|
@@ -14808,6 +14857,7 @@ async function processOutputStream({
|
|
|
14808
14857
|
break;
|
|
14809
14858
|
}
|
|
14810
14859
|
}
|
|
14860
|
+
return collectedChunks;
|
|
14811
14861
|
}
|
|
14812
14862
|
function executeStreamWithFallbackModels(models, logger, startIndex = 0) {
|
|
14813
14863
|
return async (callback) => {
|
|
@@ -15244,14 +15294,13 @@ ${bgPrompt}`;
|
|
|
15244
15294
|
transportResolver = () => routerModel._getStreamTransport();
|
|
15245
15295
|
}
|
|
15246
15296
|
try {
|
|
15247
|
-
await processOutputStream({
|
|
15297
|
+
const collectedChunks = await processOutputStream({
|
|
15248
15298
|
outputStream: outputStream2,
|
|
15249
15299
|
includeRawChunks,
|
|
15250
15300
|
tools: currentStep.tools,
|
|
15251
15301
|
messageId: currentStep.messageId,
|
|
15252
15302
|
messageList,
|
|
15253
15303
|
runState: runState2,
|
|
15254
|
-
model: currentStep.model,
|
|
15255
15304
|
options,
|
|
15256
15305
|
controller,
|
|
15257
15306
|
responseFromModel: {
|
|
@@ -15263,6 +15312,26 @@ ${bgPrompt}`;
|
|
|
15263
15312
|
transportRef: _internal?.transportRef,
|
|
15264
15313
|
transportResolver
|
|
15265
15314
|
});
|
|
15315
|
+
const builtMessages = buildMessagesFromChunks({
|
|
15316
|
+
chunks: collectedChunks,
|
|
15317
|
+
messageId: currentStep.messageId,
|
|
15318
|
+
responseModelMetadata: buildResponseModelMetadata(runState2, currentStep.model),
|
|
15319
|
+
tools: currentStep.tools
|
|
15320
|
+
});
|
|
15321
|
+
for (const msg of builtMessages) {
|
|
15322
|
+
messageList.add(msg, "response");
|
|
15323
|
+
}
|
|
15324
|
+
const bufferedObject = outputStream2._getImmediateObject();
|
|
15325
|
+
if (bufferedObject !== void 0) {
|
|
15326
|
+
const responseMessages = messageList.get.response.db();
|
|
15327
|
+
const lastAssistant = [...responseMessages].reverse().find((m) => m.role === "assistant");
|
|
15328
|
+
if (lastAssistant) {
|
|
15329
|
+
if (!lastAssistant.content.metadata) {
|
|
15330
|
+
lastAssistant.content.metadata = {};
|
|
15331
|
+
}
|
|
15332
|
+
lastAssistant.content.metadata.structuredOutput = bufferedObject;
|
|
15333
|
+
}
|
|
15334
|
+
}
|
|
15266
15335
|
} catch (error) {
|
|
15267
15336
|
const provider = model?.provider;
|
|
15268
15337
|
const modelIdStr = model?.modelId;
|
|
@@ -20928,6 +20997,9 @@ function createMapResultsStep({
|
|
|
20928
20997
|
if (capabilities.mastra) {
|
|
20929
20998
|
structuredProcessor.__registerMastra(capabilities.mastra);
|
|
20930
20999
|
}
|
|
21000
|
+
if (options.structuredOutput.useAgent) {
|
|
21001
|
+
structuredProcessor.setAgent(capabilities.agent);
|
|
21002
|
+
}
|
|
20931
21003
|
effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
|
|
20932
21004
|
}
|
|
20933
21005
|
const effectiveInputProcessors = capabilities.inputProcessors ? typeof capabilities.inputProcessors === "function" ? await capabilities.inputProcessors({
|
|
@@ -25183,6 +25255,7 @@ ${effectiveInstructions}`;
|
|
|
25183
25255
|
memory
|
|
25184
25256
|
});
|
|
25185
25257
|
const capabilities = {
|
|
25258
|
+
agent: this,
|
|
25186
25259
|
agentName: this.name,
|
|
25187
25260
|
logger: this.logger,
|
|
25188
25261
|
getMemory: this.getMemory.bind(this),
|
|
@@ -30656,5 +30729,5 @@ var MockMemory = class extends MastraMemory {
|
|
|
30656
30729
|
};
|
|
30657
30730
|
|
|
30658
30731
|
export { Agent, AgentChannels, AgentsMDInjector, BaseProcessor, BatchPartsProcessor, ChatChannelProcessor, ChunkFrom, 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, ReasoningPartSchema, Run, SYSTEM_REMINDER_END_TAG, SYSTEM_REMINDER_START_TAG, SemanticRecall, SkillSearchProcessor, SkillsProcessor, SourcePartSchema, StepStartPartSchema, StructuredOutputProcessor, SystemPromptScrubber, TextPartSchema, TokenLimiterProcessor, ToolCallFilter, ToolInvocationPartSchema, ToolSearchProcessor, TripWire, UnicodeNormalizer, WORKING_MEMORY_END_TAG, WORKING_MEMORY_START_TAG, Workflow, WorkflowRunOutput, WorkingMemory, WorkspaceInstructionsProcessor, augmentWithInit, cleanStepResult, cloneStep, cloneWorkflow, convertFullStreamChunkToMastra, convertFullStreamChunkToUIMessageStream, convertMastraChunkToAISDKv5, createDeprecationProxy, createScorer, createStep, createTimeTravelExecutionParams, createWorkflow, extractWorkingMemoryContent, extractWorkingMemoryTags, filterSystemReminderMessages, formatCheckFeedback, formatCompletionFeedback, formatStreamCompletionFeedback, formatValidationFeedback, forwardAgentStreamChunk, generateFinalResult, generateStructuredFinalResult, getResumeLabelsByStepId, getStepIds, getStepResult, getThreadOMMetadata, globalEmbeddingCache, hydrateSerializedStepErrors, isObservationalMemoryEnabled, isProcessor, isProcessorWorkflow, isSupportedLanguageModel, isSystemReminderMessage, loop, mapVariable, memoryDefaultOptions, parseMemoryRequestContext, removeSystemReminderTags, removeWorkingMemoryTags, resolveThreadIdFromArgs, runChecks, runCompletionScorers, runCountDeprecationMessage, runDefaultCompletionCheck, runStreamCompletionScorers, runValidation, setThreadOMMetadata, summarizeActiveToolsForSpan, summarizeProcessorModelForSpan, summarizeProcessorResultForSpan, summarizeProcessorToolsForSpan, summarizeToolChoiceForSpan, supportedLanguageModelSpecifications, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepRequestContext, validateStepResumeData, validateStepStateData, validateStepSuspendData };
|
|
30659
|
-
//# sourceMappingURL=chunk-
|
|
30660
|
-
//# sourceMappingURL=chunk-
|
|
30732
|
+
//# sourceMappingURL=chunk-DLDGEMBE.js.map
|
|
30733
|
+
//# sourceMappingURL=chunk-DLDGEMBE.js.map
|