@mastra/core 0.16.0 → 0.16.1-alpha.1
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 +40 -0
- package/dist/agent/index.cjs +11 -11
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/agent/input-processor/index.cjs +6 -6
- package/dist/agent/input-processor/index.js +1 -1
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/image-utils.d.ts +30 -0
- package/dist/agent/message-list/prompt/image-utils.d.ts.map +1 -1
- package/dist/agent/types.d.ts +2 -2
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/ai-tracing/context.d.ts +7 -13
- package/dist/ai-tracing/context.d.ts.map +1 -1
- package/dist/ai-tracing/index.cjs +32 -36
- package/dist/ai-tracing/index.js +1 -1
- package/dist/{chunk-WEPWZHE4.js → chunk-2NKNTPFR.js} +49 -5
- package/dist/chunk-2NKNTPFR.js.map +1 -0
- package/dist/{chunk-DRMT4EQA.cjs → chunk-2PWFUEQA.cjs} +4 -4
- package/dist/{chunk-DRMT4EQA.cjs.map → chunk-2PWFUEQA.cjs.map} +1 -1
- package/dist/{chunk-3CJXUAA2.cjs → chunk-33GDW3SI.cjs} +2 -4
- package/dist/chunk-33GDW3SI.cjs.map +1 -0
- package/dist/{chunk-HGYL2SSF.js → chunk-BQ43NQXK.js} +3 -3
- package/dist/{chunk-HGYL2SSF.js.map → chunk-BQ43NQXK.js.map} +1 -1
- package/dist/{chunk-7GYN2OE3.cjs → chunk-C3R2Q3NN.cjs} +153 -101
- package/dist/chunk-C3R2Q3NN.cjs.map +1 -0
- package/dist/{chunk-JTU7FZ5O.js → chunk-CWK46GAF.js} +2 -4
- package/dist/chunk-CWK46GAF.js.map +1 -0
- package/dist/{chunk-SIKEQ32R.cjs → chunk-D3UG2YLU.cjs} +137 -33
- package/dist/chunk-D3UG2YLU.cjs.map +1 -0
- package/dist/{chunk-EU3ADOKK.js → chunk-DUABZASJ.js} +4 -4
- package/dist/{chunk-EU3ADOKK.js.map → chunk-DUABZASJ.js.map} +1 -1
- package/dist/{chunk-YEZD4ZLX.cjs → chunk-DYLYA6HQ.cjs} +12 -12
- package/dist/{chunk-YEZD4ZLX.cjs.map → chunk-DYLYA6HQ.cjs.map} +1 -1
- package/dist/{chunk-JT2QXHUD.js → chunk-GJKJXY3K.js} +3 -3
- package/dist/{chunk-JT2QXHUD.js.map → chunk-GJKJXY3K.js.map} +1 -1
- package/dist/chunk-GXSERFAG.js +3 -0
- package/dist/{chunk-S43VACTO.js.map → chunk-GXSERFAG.js.map} +1 -1
- package/dist/{chunk-TCYQAAIT.cjs → chunk-IMDDMIVR.cjs} +6 -6
- package/dist/{chunk-TCYQAAIT.cjs.map → chunk-IMDDMIVR.cjs.map} +1 -1
- package/dist/{chunk-LVGGMWSE.cjs → chunk-KB4IEMPV.cjs} +6 -4
- package/dist/chunk-KB4IEMPV.cjs.map +1 -0
- package/dist/{chunk-SLDGELU7.cjs → chunk-LZWM7RVY.cjs} +7 -7
- package/dist/{chunk-SLDGELU7.cjs.map → chunk-LZWM7RVY.cjs.map} +1 -1
- package/dist/{chunk-MMYGYTJK.js → chunk-OF4TXRIV.js} +3 -3
- package/dist/{chunk-MMYGYTJK.js.map → chunk-OF4TXRIV.js.map} +1 -1
- package/dist/{chunk-MNDKBEEQ.cjs → chunk-SJO2HEVU.cjs} +6 -6
- package/dist/{chunk-MNDKBEEQ.cjs.map → chunk-SJO2HEVU.cjs.map} +1 -1
- package/dist/{chunk-WWQ3QRPF.js → chunk-TDLB5JKT.js} +6 -4
- package/dist/chunk-TDLB5JKT.js.map +1 -0
- package/dist/{chunk-D2Y5SXZN.js → chunk-U2RCB3FQ.js} +5 -5
- package/dist/{chunk-D2Y5SXZN.js.map → chunk-U2RCB3FQ.js.map} +1 -1
- package/dist/{chunk-A5VGUE2H.js → chunk-U3OYPZHX.js} +3 -3
- package/dist/{chunk-A5VGUE2H.js.map → chunk-U3OYPZHX.js.map} +1 -1
- package/dist/{chunk-UFCYMOYH.cjs → chunk-UGCG7DI3.cjs} +49 -6
- package/dist/chunk-UGCG7DI3.cjs.map +1 -0
- package/dist/{chunk-YILDTNQM.js → chunk-UM4XJM3Y.js} +118 -66
- package/dist/chunk-UM4XJM3Y.js.map +1 -0
- package/dist/{chunk-2BFCQRWV.cjs → chunk-WGX5V6DE.cjs} +7 -7
- package/dist/{chunk-2BFCQRWV.cjs.map → chunk-WGX5V6DE.cjs.map} +1 -1
- package/dist/chunk-X4RMXTXF.cjs +4 -0
- package/dist/{chunk-IHVB4C5U.cjs.map → chunk-X4RMXTXF.cjs.map} +1 -1
- package/dist/{chunk-HF7HXOCC.js → chunk-YI3AIJJL.js} +136 -32
- package/dist/chunk-YI3AIJJL.js.map +1 -0
- package/dist/index.cjs +43 -43
- package/dist/index.js +9 -9
- package/dist/llm/model/model.loop.d.ts.map +1 -1
- package/dist/loop/index.cjs +2 -2
- package/dist/loop/index.js +1 -1
- package/dist/loop/test-utils/streamObject.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/mcp/index.cjs +4 -0
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.d.ts +3 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +4 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.js +1 -1
- package/dist/network/index.cjs +2 -2
- package/dist/network/index.js +1 -1
- package/dist/network/vNext/index.cjs +14 -14
- package/dist/network/vNext/index.js +2 -2
- package/dist/processors/index.cjs +8 -8
- package/dist/processors/index.js +2 -2
- package/dist/processors/processors/structured-output.d.ts +2 -1
- package/dist/processors/processors/structured-output.d.ts.map +1 -1
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.js +1 -1
- package/dist/scores/index.cjs +8 -8
- package/dist/scores/index.js +1 -1
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/domains/observability/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +11 -9
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.js +5 -3
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/types.d.ts +2 -0
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/execute.d.ts.map +1 -1
- package/dist/stream/aisdk/v5/model-supports.d.ts +25 -0
- package/dist/stream/aisdk/v5/model-supports.d.ts.map +1 -0
- package/dist/stream/base/output-format-handlers.d.ts.map +1 -1
- package/dist/stream/index.cjs +3 -3
- package/dist/stream/index.js +1 -1
- package/dist/test-utils/llm-mock.cjs +2 -2
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tools/index.cjs +0 -4
- package/dist/tools/index.d.ts +0 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/tool-builder/builder.d.ts.map +1 -1
- package/dist/tools/types.d.ts +1 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils.cjs +17 -17
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/workflows/default.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/index.cjs +10 -10
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/legacy/index.cjs +22 -22
- package/dist/workflows/legacy/index.js +1 -1
- package/dist/workflows/types.d.ts +3 -0
- package/dist/workflows/types.d.ts.map +1 -1
- package/dist/workflows/workflow.d.ts +4 -2
- package/dist/workflows/workflow.d.ts.map +1 -1
- package/package.json +3 -2
- package/dist/chunk-3CJXUAA2.cjs.map +0 -1
- package/dist/chunk-7GYN2OE3.cjs.map +0 -1
- package/dist/chunk-HF7HXOCC.js.map +0 -1
- package/dist/chunk-IHVB4C5U.cjs +0 -4
- package/dist/chunk-JTU7FZ5O.js.map +0 -1
- package/dist/chunk-LVGGMWSE.cjs.map +0 -1
- package/dist/chunk-S43VACTO.js +0 -3
- package/dist/chunk-SIKEQ32R.cjs.map +0 -1
- package/dist/chunk-UFCYMOYH.cjs.map +0 -1
- package/dist/chunk-WEPWZHE4.js.map +0 -1
- package/dist/chunk-WWQ3QRPF.js.map +0 -1
- package/dist/chunk-YILDTNQM.js.map +0 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { DefaultVoice } from './chunk-QQIBOVFQ.js';
|
|
2
2
|
import { STREAM_FORMAT_SYMBOL, EMITTER_SYMBOL } from './chunk-NLNKQD2T.js';
|
|
3
3
|
import { InstrumentClass, Telemetry } from './chunk-TLJPVRO5.js';
|
|
4
|
-
import { MastraLLMV1 } from './chunk-
|
|
5
|
-
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-
|
|
4
|
+
import { MastraLLMV1 } from './chunk-BQ43NQXK.js';
|
|
5
|
+
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-YI3AIJJL.js';
|
|
6
6
|
import { executeHook } from './chunk-TTELJD4F.js';
|
|
7
|
-
import { ensureToolProperties, makeCoreTool, createMastraProxy, delay } from './chunk-
|
|
7
|
+
import { ensureToolProperties, makeCoreTool, createMastraProxy, delay } from './chunk-TDLB5JKT.js';
|
|
8
8
|
import { RuntimeContext } from './chunk-HLRWYUFN.js';
|
|
9
9
|
import { ToolStream } from './chunk-YW7UILPE.js';
|
|
10
10
|
import { createTool, Tool } from './chunk-BJGHUKKM.js';
|
|
11
|
-
import { getOrCreateSpan, wrapMastra, selectFields } from './chunk-
|
|
11
|
+
import { getOrCreateSpan, wrapMastra, selectFields } from './chunk-2NKNTPFR.js';
|
|
12
12
|
import { MastraError } from './chunk-MCOVMKIS.js';
|
|
13
13
|
import { MastraBase } from './chunk-6GF5M4GX.js';
|
|
14
14
|
import { ConsoleLogger, RegisteredLogger } from './chunk-X3GXU6TZ.js';
|
|
@@ -22,7 +22,7 @@ import { OpenAIReasoningSchemaCompatLayer, OpenAISchemaCompatLayer, GoogleSchema
|
|
|
22
22
|
import { createTextStreamResponse, createUIMessageStreamResponse, createUIMessageStream, consumeStream, generateId, asSchema, parsePartialJson, isDeepEqualData, tool, stepCountIs } from 'ai-v5';
|
|
23
23
|
import { getErrorMessage, TypeValidationError } from '@ai-sdk/provider-v5';
|
|
24
24
|
import { context, trace } from '@opentelemetry/api';
|
|
25
|
-
import { isAbortError } from '@ai-sdk/provider-utils-v5';
|
|
25
|
+
import { isAbortError, injectJsonInstructionIntoMessages } from '@ai-sdk/provider-utils-v5';
|
|
26
26
|
import { isAbortError as isAbortError$1 } from '@ai-sdk/provider-utils';
|
|
27
27
|
import { get } from 'radash';
|
|
28
28
|
import sift from 'sift';
|
|
@@ -1615,22 +1615,32 @@ var ObjectFormatHandler = class extends BaseFormatHandler {
|
|
|
1615
1615
|
shouldEmit: false
|
|
1616
1616
|
};
|
|
1617
1617
|
}
|
|
1618
|
-
async validateAndTransformFinal(
|
|
1619
|
-
if (!
|
|
1618
|
+
async validateAndTransformFinal(finalRawValue) {
|
|
1619
|
+
if (!finalRawValue) {
|
|
1620
1620
|
return {
|
|
1621
1621
|
success: false,
|
|
1622
1622
|
error: new Error("No object generated: could not parse the response.")
|
|
1623
1623
|
};
|
|
1624
1624
|
}
|
|
1625
|
+
let rawValue = finalRawValue;
|
|
1626
|
+
if (typeof finalRawValue === "string" && finalRawValue?.includes?.("```json")) {
|
|
1627
|
+
const match = finalRawValue.match(/```json\s*\n?([\s\S]*?)\n?\s*```/);
|
|
1628
|
+
if (match && match[1]) {
|
|
1629
|
+
rawValue = match[1].trim();
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
const {
|
|
1633
|
+
value
|
|
1634
|
+
} = await parsePartialJson(rawValue);
|
|
1625
1635
|
if (!this.schema) {
|
|
1626
1636
|
return {
|
|
1627
1637
|
success: true,
|
|
1628
|
-
value
|
|
1638
|
+
value
|
|
1629
1639
|
};
|
|
1630
1640
|
}
|
|
1631
1641
|
try {
|
|
1632
1642
|
const result = await safeValidateTypes({
|
|
1633
|
-
value
|
|
1643
|
+
value,
|
|
1634
1644
|
schema: this.schema
|
|
1635
1645
|
});
|
|
1636
1646
|
if (result.success) {
|
|
@@ -1796,7 +1806,17 @@ var EnumFormatHandler = class extends BaseFormatHandler {
|
|
|
1796
1806
|
shouldEmit: false
|
|
1797
1807
|
};
|
|
1798
1808
|
}
|
|
1799
|
-
async validateAndTransformFinal(
|
|
1809
|
+
async validateAndTransformFinal(rawFinalValue) {
|
|
1810
|
+
const {
|
|
1811
|
+
value
|
|
1812
|
+
} = await parsePartialJson(rawFinalValue);
|
|
1813
|
+
if (!(typeof value === "object" && value !== null && "result" in value)) {
|
|
1814
|
+
return {
|
|
1815
|
+
success: false,
|
|
1816
|
+
error: new Error("Invalid enum format: expected object with result property")
|
|
1817
|
+
};
|
|
1818
|
+
}
|
|
1819
|
+
const finalValue = value.result;
|
|
1800
1820
|
if (!finalValue || typeof finalValue !== "object" || typeof finalValue.result !== "string") {
|
|
1801
1821
|
return {
|
|
1802
1822
|
success: false,
|
|
@@ -1902,7 +1922,7 @@ function createObjectStreamTransformer({
|
|
|
1902
1922
|
onFinish(void 0);
|
|
1903
1923
|
return;
|
|
1904
1924
|
}
|
|
1905
|
-
const finalResult = await handler.validateAndTransformFinal(
|
|
1925
|
+
const finalResult = await handler.validateAndTransformFinal(accumulatedText);
|
|
1906
1926
|
if (!finalResult.success) {
|
|
1907
1927
|
controller.enqueue({
|
|
1908
1928
|
from: "AGENT" /* AGENT */,
|
|
@@ -2929,6 +2949,12 @@ var AISDKV5InputStream = class extends MastraModelInput {
|
|
|
2929
2949
|
}
|
|
2930
2950
|
};
|
|
2931
2951
|
|
|
2952
|
+
// src/stream/aisdk/v5/model-supports.ts
|
|
2953
|
+
function getModelSupport(modelId, provider) {
|
|
2954
|
+
return modelSupports.find(m => m.modelId === modelId && m.provider === provider);
|
|
2955
|
+
}
|
|
2956
|
+
var modelSupports = [];
|
|
2957
|
+
|
|
2932
2958
|
// src/stream/aisdk/v5/execute.ts
|
|
2933
2959
|
function execute({
|
|
2934
2960
|
runId,
|
|
@@ -2960,6 +2986,16 @@ function execute({
|
|
|
2960
2986
|
"stream.prompt.tools": toolsAndToolChoice?.tools?.map(tool => JSON.stringify(tool))
|
|
2961
2987
|
});
|
|
2962
2988
|
}
|
|
2989
|
+
const modelSupports2 = getModelSupport(model.modelId, model.provider);
|
|
2990
|
+
const modelSupportsResponseFormat = modelSupports2?.capabilities.responseFormat?.support === "full";
|
|
2991
|
+
const responseFormat = output ? getResponseFormat(output) : void 0;
|
|
2992
|
+
let prompt = inputMessages;
|
|
2993
|
+
if (output && responseFormat?.type === "json" && !modelSupportsResponseFormat) {
|
|
2994
|
+
prompt = injectJsonInstructionIntoMessages({
|
|
2995
|
+
messages: inputMessages,
|
|
2996
|
+
schema: responseFormat.schema
|
|
2997
|
+
});
|
|
2998
|
+
}
|
|
2963
2999
|
const stream = v5.initialize({
|
|
2964
3000
|
runId,
|
|
2965
3001
|
onResult,
|
|
@@ -2967,11 +3003,11 @@ function execute({
|
|
|
2967
3003
|
try {
|
|
2968
3004
|
const stream2 = await model.doStream({
|
|
2969
3005
|
...toolsAndToolChoice,
|
|
2970
|
-
prompt
|
|
3006
|
+
prompt,
|
|
2971
3007
|
providerOptions,
|
|
2972
3008
|
abortSignal: options?.abortSignal,
|
|
2973
3009
|
includeRawChunks,
|
|
2974
|
-
responseFormat:
|
|
3010
|
+
responseFormat: modelSupportsResponseFormat ? responseFormat : void 0,
|
|
2975
3011
|
...(modelSettings ?? {}),
|
|
2976
3012
|
headers
|
|
2977
3013
|
});
|
|
@@ -3769,7 +3805,9 @@ function createOuterLLMWorkflow({
|
|
|
3769
3805
|
})));
|
|
3770
3806
|
}
|
|
3771
3807
|
return inputData.output.toolCalls || [];
|
|
3772
|
-
}).foreach(toolCallStep
|
|
3808
|
+
}).foreach(toolCallStep, {
|
|
3809
|
+
concurrency: 10
|
|
3810
|
+
}).then(llmMappingStep).commit();
|
|
3773
3811
|
}
|
|
3774
3812
|
|
|
3775
3813
|
// src/loop/workflow/stream.ts
|
|
@@ -4124,9 +4162,6 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
4124
4162
|
messages,
|
|
4125
4163
|
tools: Object.keys(tools || {})
|
|
4126
4164
|
});
|
|
4127
|
-
if (output) {
|
|
4128
|
-
output = this._applySchemaCompat(output);
|
|
4129
|
-
}
|
|
4130
4165
|
const llmAISpan = tracingContext?.currentSpan?.createChildSpan({
|
|
4131
4166
|
name: `llm stream: '${model.modelId}'`,
|
|
4132
4167
|
type: "llm_generation" /* LLM_GENERATION */,
|
|
@@ -4278,14 +4313,18 @@ var StructuredOutputProcessor = class {
|
|
|
4278
4313
|
structuringAgent;
|
|
4279
4314
|
errorStrategy;
|
|
4280
4315
|
fallbackValue;
|
|
4281
|
-
constructor(options) {
|
|
4316
|
+
constructor(options, fallbackModel) {
|
|
4282
4317
|
this.schema = options.schema;
|
|
4283
4318
|
this.errorStrategy = options.errorStrategy ?? "strict";
|
|
4284
4319
|
this.fallbackValue = options.fallbackValue;
|
|
4320
|
+
const modelToUse = options.model || fallbackModel;
|
|
4321
|
+
if (!modelToUse) {
|
|
4322
|
+
throw new Error("StructuredOutputProcessor requires a model to be provided either in options or as fallback");
|
|
4323
|
+
}
|
|
4285
4324
|
this.structuringAgent = new Agent({
|
|
4286
4325
|
name: "structured-output-structurer",
|
|
4287
4326
|
instructions: options.instructions || this.generateInstructions(),
|
|
4288
|
-
model:
|
|
4327
|
+
model: modelToUse
|
|
4289
4328
|
});
|
|
4290
4329
|
}
|
|
4291
4330
|
async processOutputResult(args) {
|
|
@@ -9910,8 +9949,8 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
9910
9949
|
threadId,
|
|
9911
9950
|
resourceId,
|
|
9912
9951
|
runtimeContext,
|
|
9913
|
-
methodType,
|
|
9914
9952
|
tracingContext,
|
|
9953
|
+
methodType,
|
|
9915
9954
|
format
|
|
9916
9955
|
}) {
|
|
9917
9956
|
const convertedWorkflowTools = {};
|
|
@@ -9930,17 +9969,9 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
9930
9969
|
// current tool span onto the workflow to maintain continuity of the trace
|
|
9931
9970
|
execute: async ({
|
|
9932
9971
|
context,
|
|
9933
|
-
writer
|
|
9972
|
+
writer,
|
|
9973
|
+
tracingContext: innerTracingContext
|
|
9934
9974
|
}) => {
|
|
9935
|
-
const toolAISpan = tracingContext.currentSpan?.createChildSpan({
|
|
9936
|
-
type: "tool_call" /* TOOL_CALL */,
|
|
9937
|
-
name: `tool: '${workflowName}'`,
|
|
9938
|
-
input: context,
|
|
9939
|
-
attributes: {
|
|
9940
|
-
toolId: workflowName,
|
|
9941
|
-
toolType: "workflow"
|
|
9942
|
-
}
|
|
9943
|
-
});
|
|
9944
9975
|
try {
|
|
9945
9976
|
this.logger.debug(`[Agent:${this.name}] - Executing workflow as tool ${workflowName}`, {
|
|
9946
9977
|
name: workflowName,
|
|
@@ -9956,16 +9987,13 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
9956
9987
|
result = await run.start({
|
|
9957
9988
|
inputData: context,
|
|
9958
9989
|
runtimeContext,
|
|
9959
|
-
tracingContext:
|
|
9960
|
-
currentSpan: toolAISpan
|
|
9961
|
-
}
|
|
9990
|
+
tracingContext: innerTracingContext
|
|
9962
9991
|
});
|
|
9963
9992
|
} else if (methodType === "stream") {
|
|
9964
|
-
const streamResult =
|
|
9993
|
+
const streamResult = run.stream({
|
|
9965
9994
|
inputData: context,
|
|
9966
|
-
runtimeContext
|
|
9967
|
-
|
|
9968
|
-
//currentSpan: toolAISpan,
|
|
9995
|
+
runtimeContext,
|
|
9996
|
+
tracingContext: innerTracingContext
|
|
9969
9997
|
});
|
|
9970
9998
|
if (writer) {
|
|
9971
9999
|
await streamResult.stream.pipeTo(writer);
|
|
@@ -9977,6 +10005,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
9977
10005
|
const streamResult = run.streamVNext({
|
|
9978
10006
|
inputData: context,
|
|
9979
10007
|
runtimeContext,
|
|
10008
|
+
tracingContext: innerTracingContext,
|
|
9980
10009
|
format
|
|
9981
10010
|
});
|
|
9982
10011
|
if (writer) {
|
|
@@ -9984,9 +10013,6 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
9984
10013
|
}
|
|
9985
10014
|
result = await streamResult.result;
|
|
9986
10015
|
}
|
|
9987
|
-
toolAISpan?.end({
|
|
9988
|
-
output: result
|
|
9989
|
-
});
|
|
9990
10016
|
return {
|
|
9991
10017
|
result,
|
|
9992
10018
|
runId: run.runId
|
|
@@ -10006,9 +10032,6 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
10006
10032
|
}, err);
|
|
10007
10033
|
this.logger.trackException(mastraError);
|
|
10008
10034
|
this.logger.error(mastraError.toString());
|
|
10009
|
-
toolAISpan?.error({
|
|
10010
|
-
error: mastraError
|
|
10011
|
-
});
|
|
10012
10035
|
throw mastraError;
|
|
10013
10036
|
}
|
|
10014
10037
|
}
|
|
@@ -10324,7 +10347,9 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
10324
10347
|
saveThread: false
|
|
10325
10348
|
});
|
|
10326
10349
|
}
|
|
10327
|
-
|
|
10350
|
+
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
10351
|
+
const hasResourceScopeSemanticRecall = typeof config?.semanticRecall === "object" && config?.semanticRecall?.scope === "resource";
|
|
10352
|
+
let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread || hasResourceScopeSemanticRecall ? this.getMemoryMessages({
|
|
10328
10353
|
resourceId,
|
|
10329
10354
|
threadId: threadObject.id,
|
|
10330
10355
|
vectorMessageSearch: new MessageList().add(messages, `user`).getLatestUserContent() || "",
|
|
@@ -10993,12 +11018,12 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
10993
11018
|
resourceId,
|
|
10994
11019
|
runId,
|
|
10995
11020
|
runtimeContext,
|
|
10996
|
-
writableStream: options.writableStream,
|
|
10997
|
-
methodType,
|
|
10998
|
-
format,
|
|
10999
11021
|
tracingContext: {
|
|
11000
11022
|
currentSpan: agentAISpan
|
|
11001
|
-
}
|
|
11023
|
+
},
|
|
11024
|
+
writableStream: options.writableStream,
|
|
11025
|
+
methodType,
|
|
11026
|
+
format
|
|
11002
11027
|
});
|
|
11003
11028
|
return {
|
|
11004
11029
|
convertedTools
|
|
@@ -11100,7 +11125,9 @@ Message ${msg.threadId && msg.threadId !== threadObject.id ? "from previous conv
|
|
|
11100
11125
|
saveThread: false
|
|
11101
11126
|
});
|
|
11102
11127
|
}
|
|
11103
|
-
|
|
11128
|
+
const config = memory.getMergedThreadConfig(memoryConfig || {});
|
|
11129
|
+
const hasResourceScopeSemanticRecall = typeof config?.semanticRecall === "object" && config?.semanticRecall?.scope === "resource";
|
|
11130
|
+
let [memoryMessages, memorySystemMessage] = await Promise.all([existingThread || hasResourceScopeSemanticRecall ? this.getMemoryMessages({
|
|
11104
11131
|
resourceId,
|
|
11105
11132
|
threadId: threadObject.id,
|
|
11106
11133
|
vectorMessageSearch: new MessageList().add(options.messages, `user`).getLatestUserContent() || "",
|
|
@@ -11331,7 +11358,10 @@ the following messages are from ${ymd}
|
|
|
11331
11358
|
runtimeContext: result2.runtimeContext
|
|
11332
11359
|
}) : this.#outputProcessors : []);
|
|
11333
11360
|
if (options.structuredOutput) {
|
|
11334
|
-
const
|
|
11361
|
+
const agentModel = await this.getModel({
|
|
11362
|
+
runtimeContext: result2.runtimeContext
|
|
11363
|
+
});
|
|
11364
|
+
const structuredProcessor = new StructuredOutputProcessor(options.structuredOutput, agentModel);
|
|
11335
11365
|
effectiveOutputProcessors = effectiveOutputProcessors ? [...effectiveOutputProcessors, structuredProcessor] : [structuredProcessor];
|
|
11336
11366
|
}
|
|
11337
11367
|
const loopOptions = {
|
|
@@ -11388,7 +11418,9 @@ the following messages are from ${ymd}
|
|
|
11388
11418
|
await options?.onFinish?.({
|
|
11389
11419
|
...result2,
|
|
11390
11420
|
runId,
|
|
11391
|
-
messages: messageList.get.response.aiV5.model()
|
|
11421
|
+
messages: messageList.get.response.aiV5.model(),
|
|
11422
|
+
usage: payload.usage,
|
|
11423
|
+
totalUsage: payload.totalUsage
|
|
11392
11424
|
});
|
|
11393
11425
|
},
|
|
11394
11426
|
onStepFinish: result2.onStepFinish
|
|
@@ -11699,7 +11731,10 @@ the following messages are from ${ymd}
|
|
|
11699
11731
|
};
|
|
11700
11732
|
let finalOutputProcessors = mergedGenerateOptions.outputProcessors;
|
|
11701
11733
|
if (mergedGenerateOptions.structuredOutput) {
|
|
11702
|
-
const
|
|
11734
|
+
const agentModel = await this.getModel({
|
|
11735
|
+
runtimeContext: mergedGenerateOptions.runtimeContext
|
|
11736
|
+
});
|
|
11737
|
+
const structuredProcessor = new StructuredOutputProcessor(mergedGenerateOptions.structuredOutput, agentModel);
|
|
11703
11738
|
finalOutputProcessors = finalOutputProcessors ? [...finalOutputProcessors, structuredProcessor] : [structuredProcessor];
|
|
11704
11739
|
}
|
|
11705
11740
|
if (!output || experimental_output) {
|
|
@@ -12265,9 +12300,9 @@ var MastraWorkflowStream = class extends ReadableStream$1 {
|
|
|
12265
12300
|
deferredPromise.reject = reject;
|
|
12266
12301
|
});
|
|
12267
12302
|
const updateUsageCount = usage => {
|
|
12268
|
-
this.#usageCount.promptTokens += parseInt(usage
|
|
12269
|
-
this.#usageCount.completionTokens += parseInt(usage
|
|
12270
|
-
this.#usageCount.totalTokens += parseInt(usage
|
|
12303
|
+
this.#usageCount.promptTokens += parseInt(usage?.promptTokens?.toString() ?? "0", 10);
|
|
12304
|
+
this.#usageCount.completionTokens += parseInt(usage?.completionTokens?.toString() ?? "0", 10);
|
|
12305
|
+
this.#usageCount.totalTokens += parseInt(usage?.totalTokens?.toString() ?? "0", 10);
|
|
12271
12306
|
};
|
|
12272
12307
|
super({
|
|
12273
12308
|
start: async controller => {
|
|
@@ -12275,7 +12310,9 @@ var MastraWorkflowStream = class extends ReadableStream$1 {
|
|
|
12275
12310
|
write: chunk => {
|
|
12276
12311
|
if (chunk.type === "step-output" && chunk.payload?.output?.from === "AGENT" && chunk.payload?.output?.type === "finish" || chunk.type === "step-output" && chunk.payload?.output?.from === "WORKFLOW" && chunk.payload?.output?.type === "finish") {
|
|
12277
12312
|
const finishPayload = chunk.payload?.output.payload;
|
|
12278
|
-
|
|
12313
|
+
if (finishPayload) {
|
|
12314
|
+
updateUsageCount(finishPayload.usage);
|
|
12315
|
+
}
|
|
12279
12316
|
}
|
|
12280
12317
|
controller.enqueue(chunk);
|
|
12281
12318
|
}
|
|
@@ -12287,9 +12324,14 @@ var MastraWorkflowStream = class extends ReadableStream$1 {
|
|
|
12287
12324
|
payload: {}
|
|
12288
12325
|
});
|
|
12289
12326
|
const stream = await createStream(writer);
|
|
12327
|
+
let workflowStatus = "success";
|
|
12290
12328
|
for await (const chunk of stream) {
|
|
12291
|
-
if (chunk.type === "step-finish") {
|
|
12329
|
+
if (chunk.type === "step-finish" && chunk.payload.usage) {
|
|
12292
12330
|
updateUsageCount(chunk.payload.usage);
|
|
12331
|
+
} else if (chunk.type === "workflow-canceled") {
|
|
12332
|
+
workflowStatus = "canceled";
|
|
12333
|
+
} else if (chunk.type === "workflow-step-result" && chunk.payload.status === "failed") {
|
|
12334
|
+
workflowStatus = "failed";
|
|
12293
12335
|
}
|
|
12294
12336
|
controller.enqueue(chunk);
|
|
12295
12337
|
}
|
|
@@ -12298,9 +12340,7 @@ var MastraWorkflowStream = class extends ReadableStream$1 {
|
|
|
12298
12340
|
runId: run.runId,
|
|
12299
12341
|
from: "WORKFLOW" /* WORKFLOW */,
|
|
12300
12342
|
payload: {
|
|
12301
|
-
|
|
12302
|
-
reason: "stop"
|
|
12303
|
-
},
|
|
12343
|
+
workflowStatus,
|
|
12304
12344
|
output: {
|
|
12305
12345
|
usage: this.#usageCount
|
|
12306
12346
|
},
|
|
@@ -14434,6 +14474,12 @@ var DefaultExecutionEngine = class extends ExecutionEngine {
|
|
|
14434
14474
|
workflowStatus: execResults.status === "success" ? "running" : execResults.status,
|
|
14435
14475
|
runtimeContext
|
|
14436
14476
|
});
|
|
14477
|
+
if (execResults.status === "canceled") {
|
|
14478
|
+
await emitter.emit("watch-v2", {
|
|
14479
|
+
type: "workflow-canceled",
|
|
14480
|
+
payload: {}
|
|
14481
|
+
});
|
|
14482
|
+
}
|
|
14437
14483
|
return {
|
|
14438
14484
|
result: execResults,
|
|
14439
14485
|
stepResults,
|
|
@@ -15138,6 +15184,8 @@ var Workflow = class extends MastraBase {
|
|
|
15138
15184
|
}
|
|
15139
15185
|
return scorers;
|
|
15140
15186
|
}
|
|
15187
|
+
// This method should only be called internally for nested workflow execution, as well as from mastra server handlers
|
|
15188
|
+
// To run a workflow use `.createRunAsync` and then `.start` or `.resume`
|
|
15141
15189
|
async execute({
|
|
15142
15190
|
runId,
|
|
15143
15191
|
inputData,
|
|
@@ -15475,7 +15523,8 @@ var Run = class {
|
|
|
15475
15523
|
*/
|
|
15476
15524
|
stream({
|
|
15477
15525
|
inputData,
|
|
15478
|
-
runtimeContext
|
|
15526
|
+
runtimeContext,
|
|
15527
|
+
tracingContext
|
|
15479
15528
|
} = {}) {
|
|
15480
15529
|
const {
|
|
15481
15530
|
readable,
|
|
@@ -15540,7 +15589,8 @@ var Run = class {
|
|
|
15540
15589
|
this.executionResults = this._start({
|
|
15541
15590
|
inputData,
|
|
15542
15591
|
runtimeContext,
|
|
15543
|
-
format: "aisdk"
|
|
15592
|
+
format: "aisdk",
|
|
15593
|
+
tracingContext
|
|
15544
15594
|
}).then(result => {
|
|
15545
15595
|
if (result.status !== "suspended") {
|
|
15546
15596
|
this.closeStreamAction?.().catch(() => {});
|
|
@@ -15569,12 +15619,13 @@ var Run = class {
|
|
|
15569
15619
|
streamVNext({
|
|
15570
15620
|
inputData,
|
|
15571
15621
|
runtimeContext,
|
|
15622
|
+
tracingContext,
|
|
15572
15623
|
format
|
|
15573
15624
|
} = {}) {
|
|
15574
15625
|
this.closeStreamAction = async () => {};
|
|
15575
15626
|
return new MastraWorkflowStream({
|
|
15576
15627
|
run: this,
|
|
15577
|
-
createStream:
|
|
15628
|
+
createStream: () => {
|
|
15578
15629
|
const {
|
|
15579
15630
|
readable,
|
|
15580
15631
|
writable
|
|
@@ -15592,7 +15643,7 @@ var Run = class {
|
|
|
15592
15643
|
return;
|
|
15593
15644
|
}
|
|
15594
15645
|
isWriting = true;
|
|
15595
|
-
let watchWriter =
|
|
15646
|
+
let watchWriter = writable.getWriter();
|
|
15596
15647
|
try {
|
|
15597
15648
|
for (const chunk of chunkToWrite) {
|
|
15598
15649
|
await watchWriter.write(chunk);
|
|
@@ -15630,6 +15681,7 @@ var Run = class {
|
|
|
15630
15681
|
const executionResults = this._start({
|
|
15631
15682
|
inputData,
|
|
15632
15683
|
runtimeContext,
|
|
15684
|
+
tracingContext,
|
|
15633
15685
|
writableStream: writable,
|
|
15634
15686
|
format
|
|
15635
15687
|
}).then(result => {
|
|
@@ -15869,5 +15921,5 @@ function deepMergeWorkflowState(a, b) {
|
|
|
15869
15921
|
}
|
|
15870
15922
|
|
|
15871
15923
|
export { AISDKV5OutputStream, Agent, DefaultExecutionEngine, ExecutionEngine, LanguageDetector, LanguageDetectorInputProcessor, LegacyStep, LegacyWorkflow, MastraModelOutput, ModerationInputProcessor, ModerationProcessor, PIIDetector, PIIDetectorInputProcessor, PromptInjectionDetector, PromptInjectionDetectorInputProcessor, Run, StructuredOutputProcessor, TripWire, UnicodeNormalizer, UnicodeNormalizerInputProcessor, WhenConditionReturnValue, Workflow, agentToStep, cloneStep, cloneWorkflow, createStep, createWorkflow, getActivePathsAndStatus, getResultActivePaths, getStepResult, getSuspendedPaths, isAgent, isConditionalKey, isErrorEvent, isFinalState, isLimboState, isTransitionEvent, isVariableReference, isWorkflow, loop, mapVariable, mergeChildValue, recursivelyCheckForFinalState, resolveVariables, updateStepInHierarchy, workflowToStep };
|
|
15872
|
-
//# sourceMappingURL=chunk-
|
|
15873
|
-
//# sourceMappingURL=chunk-
|
|
15924
|
+
//# sourceMappingURL=chunk-UM4XJM3Y.js.map
|
|
15925
|
+
//# sourceMappingURL=chunk-UM4XJM3Y.js.map
|