@mastra/core 0.15.3-alpha.2 → 0.15.3-alpha.3
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/dist/agent/index.cjs +11 -11
- 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 +5 -1
- package/dist/agent/message-list/index.d.ts.map +1 -1
- package/dist/agent/message-list/prompt/convert-file.d.ts +7 -0
- package/dist/agent/message-list/prompt/convert-file.d.ts.map +1 -0
- package/dist/agent/message-list/prompt/download-assets.d.ts +15 -0
- package/dist/agent/message-list/prompt/download-assets.d.ts.map +1 -0
- package/dist/{chunk-6VROHRAR.cjs → chunk-24TFSB6Z.cjs} +30 -7
- package/dist/chunk-24TFSB6Z.cjs.map +1 -0
- package/dist/{chunk-BRNBKCHE.js → chunk-5TFCIXWE.js} +10 -8
- package/dist/chunk-5TFCIXWE.js.map +1 -0
- package/dist/{chunk-UT6KEZRF.js → chunk-APVV75XG.js} +3 -3
- package/dist/{chunk-UT6KEZRF.js.map → chunk-APVV75XG.js.map} +1 -1
- package/dist/{chunk-HHLPYCQG.cjs → chunk-AYFN43FB.cjs} +4 -4
- package/dist/{chunk-HHLPYCQG.cjs.map → chunk-AYFN43FB.cjs.map} +1 -1
- package/dist/{chunk-5NGEKEU7.js → chunk-BGOXFBFK.js} +288 -275
- package/dist/chunk-BGOXFBFK.js.map +1 -0
- package/dist/{chunk-HXYE4EJA.cjs → chunk-D2GH2HAK.cjs} +9 -9
- package/dist/{chunk-HXYE4EJA.cjs.map → chunk-D2GH2HAK.cjs.map} +1 -1
- package/dist/{chunk-7OSUKFNG.cjs → chunk-DJKIK6ZB.cjs} +319 -306
- package/dist/chunk-DJKIK6ZB.cjs.map +1 -0
- package/dist/{chunk-XOZ737RO.js → chunk-EMAAAVRA.js} +3 -3
- package/dist/{chunk-XOZ737RO.js.map → chunk-EMAAAVRA.js.map} +1 -1
- package/dist/chunk-GOG77M6R.js +103 -0
- package/dist/chunk-GOG77M6R.js.map +1 -0
- package/dist/{chunk-UG3KS3XV.cjs → chunk-HXEHQLBD.cjs} +4 -4
- package/dist/{chunk-UG3KS3XV.cjs.map → chunk-HXEHQLBD.cjs.map} +1 -1
- package/dist/{chunk-IYCG5OVT.js → chunk-MEROMP3Z.js} +3 -3
- package/dist/{chunk-IYCG5OVT.js.map → chunk-MEROMP3Z.js.map} +1 -1
- package/dist/{chunk-C5C4PN54.js → chunk-O7IQL4DX.js} +288 -5
- package/dist/chunk-O7IQL4DX.js.map +1 -0
- package/dist/{chunk-VBAWR62U.cjs → chunk-QHEB6ZLO.cjs} +13 -11
- package/dist/chunk-QHEB6ZLO.cjs.map +1 -0
- package/dist/{chunk-T64BA34G.js → chunk-TQRLZH64.js} +4 -4
- package/dist/{chunk-T64BA34G.js.map → chunk-TQRLZH64.js.map} +1 -1
- package/dist/{chunk-QA2TWVUS.cjs → chunk-TWNFR6MQ.cjs} +288 -5
- package/dist/chunk-TWNFR6MQ.cjs.map +1 -0
- package/dist/{chunk-WHEH32QU.cjs → chunk-UGN2UU3K.cjs} +4 -4
- package/dist/{chunk-WHEH32QU.cjs.map → chunk-UGN2UU3K.cjs.map} +1 -1
- package/dist/{chunk-E3LAPNKY.js → chunk-WUQSFK7W.js} +4 -4
- package/dist/{chunk-E3LAPNKY.js.map → chunk-WUQSFK7W.js.map} +1 -1
- package/dist/{chunk-QBNRMJAN.cjs → chunk-YTVX52NU.cjs} +6 -6
- package/dist/{chunk-QBNRMJAN.cjs.map → chunk-YTVX52NU.cjs.map} +1 -1
- package/dist/chunk-ZAJTIZZF.cjs +108 -0
- package/dist/chunk-ZAJTIZZF.cjs.map +1 -0
- package/dist/{chunk-FLXWZUIG.js → chunk-ZC64CG7J.js} +26 -4
- package/dist/chunk-ZC64CG7J.js.map +1 -0
- package/dist/index.cjs +47 -43
- package/dist/index.js +10 -10
- package/dist/integration/index.cjs +3 -3
- package/dist/integration/index.js +1 -1
- package/dist/llm/model/model.d.ts.map +1 -1
- package/dist/llm/model/model.loop.d.ts +1 -1
- 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/types.d.ts +2 -0
- package/dist/loop/types.d.ts.map +1 -1
- package/dist/loop/workflow/llm-execution.d.ts +1 -1
- package/dist/loop/workflow/llm-execution.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.js +1 -1
- package/dist/network/index.cjs +4 -4
- package/dist/network/index.js +2 -2
- 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/relevance/index.cjs +4 -4
- package/dist/relevance/index.js +1 -1
- package/dist/scores/index.cjs +5 -5
- package/dist/scores/index.js +1 -1
- package/dist/storage/index.cjs +3 -3
- package/dist/storage/index.js +1 -1
- package/dist/stream/aisdk/v5/compat/consume-stream.d.ts +8 -0
- package/dist/stream/aisdk/v5/compat/consume-stream.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/compat/content.d.ts +7 -0
- package/dist/stream/aisdk/v5/compat/content.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/compat/delayed-promise.d.ts +23 -0
- package/dist/stream/aisdk/v5/compat/delayed-promise.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/compat/index.d.ts +8 -0
- package/dist/stream/aisdk/v5/compat/index.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/compat/media.d.ts +91 -0
- package/dist/stream/aisdk/v5/compat/media.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts +11 -0
- package/dist/stream/aisdk/v5/compat/prepare-tools.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/compat/ui-message.d.ts +20 -0
- package/dist/stream/aisdk/v5/compat/ui-message.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/compat/validation.d.ts +17 -0
- package/dist/stream/aisdk/v5/compat/validation.d.ts.map +1 -0
- package/dist/stream/aisdk/v5/output.d.ts +1 -1
- package/dist/stream/base/output.d.ts +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 +4 -4
- package/dist/tools/index.js +1 -1
- package/dist/tools/is-vercel-tool.cjs +2 -2
- package/dist/tools/is-vercel-tool.js +1 -1
- package/dist/tools/validation.d.ts.map +1 -1
- package/dist/utils.cjs +20 -16
- package/dist/utils.d.ts +9 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +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/package.json +1 -1
- package/dist/chunk-5NGEKEU7.js.map +0 -1
- package/dist/chunk-6VROHRAR.cjs.map +0 -1
- package/dist/chunk-7OSUKFNG.cjs.map +0 -1
- package/dist/chunk-BRNBKCHE.js.map +0 -1
- package/dist/chunk-C5C4PN54.js.map +0 -1
- package/dist/chunk-E4XQMNEI.cjs +0 -77
- package/dist/chunk-E4XQMNEI.cjs.map +0 -1
- package/dist/chunk-FLXWZUIG.js.map +0 -1
- package/dist/chunk-IVGAHFAJ.js +0 -72
- package/dist/chunk-IVGAHFAJ.js.map +0 -1
- package/dist/chunk-QA2TWVUS.cjs.map +0 -1
- package/dist/chunk-VBAWR62U.cjs.map +0 -1
- package/dist/stream/aisdk/v5/compat.d.ts +0 -73
- package/dist/stream/aisdk/v5/compat.d.ts.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { DefaultVoice } from './chunk-XM2ASGWH.js';
|
|
2
2
|
import { EMITTER_SYMBOL } from './chunk-GK5V7YTQ.js';
|
|
3
3
|
import { InstrumentClass, Telemetry } from './chunk-76MWMAR7.js';
|
|
4
|
-
import { MastraLLMV1 } from './chunk-
|
|
5
|
-
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-
|
|
4
|
+
import { MastraLLMV1 } from './chunk-5TFCIXWE.js';
|
|
5
|
+
import { MessageList, DefaultGeneratedFile, DefaultGeneratedFileWithType } from './chunk-O7IQL4DX.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-ZC64CG7J.js';
|
|
8
8
|
import { RuntimeContext } from './chunk-HLRWYUFN.js';
|
|
9
9
|
import { ToolStream } from './chunk-YW7UILPE.js';
|
|
10
|
-
import { Tool } from './chunk-
|
|
10
|
+
import { Tool } from './chunk-GOG77M6R.js';
|
|
11
11
|
import { getSelectedAITracing, wrapMastra } from './chunk-WOTBMZCN.js';
|
|
12
12
|
import { MastraError } from './chunk-MCOVMKIS.js';
|
|
13
13
|
import { MastraBase } from './chunk-6GF5M4GX.js';
|
|
@@ -64,230 +64,17 @@ var require_fast_deep_equal = __commonJS({
|
|
|
64
64
|
// src/agent/index.ts
|
|
65
65
|
var import_fast_deep_equal = __toESM(require_fast_deep_equal(), 1);
|
|
66
66
|
|
|
67
|
-
// src/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// src/processors/runner.ts
|
|
76
|
-
var ProcessorState = class {
|
|
77
|
-
constructor(processorName) {
|
|
78
|
-
this.processorName = processorName;
|
|
79
|
-
}
|
|
80
|
-
accumulatedText = "";
|
|
81
|
-
customState = {};
|
|
82
|
-
streamParts = [];
|
|
83
|
-
// Internal methods for the runner
|
|
84
|
-
addPart(part) {
|
|
85
|
-
if (part.type === "text-delta") {
|
|
86
|
-
this.accumulatedText += part.payload.text;
|
|
87
|
-
}
|
|
88
|
-
this.streamParts.push(part);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
var ProcessorRunner = class {
|
|
92
|
-
inputProcessors;
|
|
93
|
-
outputProcessors;
|
|
94
|
-
logger;
|
|
95
|
-
agentName;
|
|
96
|
-
constructor({
|
|
97
|
-
inputProcessors,
|
|
98
|
-
outputProcessors,
|
|
99
|
-
logger,
|
|
100
|
-
agentName
|
|
101
|
-
}) {
|
|
102
|
-
this.inputProcessors = inputProcessors ?? [];
|
|
103
|
-
this.outputProcessors = outputProcessors ?? [];
|
|
104
|
-
this.logger = logger;
|
|
105
|
-
this.agentName = agentName;
|
|
106
|
-
}
|
|
107
|
-
async runOutputProcessors(messageList, telemetry) {
|
|
108
|
-
const responseMessages = messageList.clear.response.v2();
|
|
109
|
-
let processableMessages = [...responseMessages];
|
|
110
|
-
const ctx = {
|
|
111
|
-
abort: () => {
|
|
112
|
-
throw new TripWire("Tripwire triggered");
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
for (const [index, processor] of this.outputProcessors.entries()) {
|
|
116
|
-
const abort = reason => {
|
|
117
|
-
throw new TripWire(reason || `Tripwire triggered by ${processor.name}`);
|
|
118
|
-
};
|
|
119
|
-
ctx.abort = abort;
|
|
120
|
-
const processMethod = processor.processOutputResult?.bind(processor);
|
|
121
|
-
if (!processMethod) {
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
|
-
if (!telemetry) {
|
|
125
|
-
processableMessages = await processMethod({
|
|
126
|
-
messages: processableMessages,
|
|
127
|
-
abort: ctx.abort
|
|
128
|
-
});
|
|
129
|
-
} else {
|
|
130
|
-
await telemetry.traceMethod(async () => {
|
|
131
|
-
processableMessages = await processMethod({
|
|
132
|
-
messages: processableMessages,
|
|
133
|
-
abort: ctx.abort
|
|
134
|
-
});
|
|
135
|
-
return processableMessages;
|
|
136
|
-
}, {
|
|
137
|
-
spanName: `agent.outputProcessor.${processor.name}`,
|
|
138
|
-
attributes: {
|
|
139
|
-
"processor.name": processor.name,
|
|
140
|
-
"processor.index": index.toString(),
|
|
141
|
-
"processor.total": this.outputProcessors.length.toString()
|
|
142
|
-
}
|
|
143
|
-
})();
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (processableMessages.length > 0) {
|
|
147
|
-
messageList.add(processableMessages, "response");
|
|
148
|
-
}
|
|
149
|
-
return messageList;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Process a stream part through all output processors with state management
|
|
153
|
-
*/
|
|
154
|
-
async processPart(part, processorStates) {
|
|
155
|
-
if (!this.outputProcessors.length) {
|
|
156
|
-
return {
|
|
157
|
-
part,
|
|
158
|
-
blocked: false
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
try {
|
|
162
|
-
let processedPart = part;
|
|
163
|
-
for (const processor of this.outputProcessors) {
|
|
164
|
-
try {
|
|
165
|
-
if (processor.processOutputStream && processedPart) {
|
|
166
|
-
let state = processorStates.get(processor.name);
|
|
167
|
-
if (!state) {
|
|
168
|
-
state = new ProcessorState(processor.name);
|
|
169
|
-
processorStates.set(processor.name, state);
|
|
170
|
-
}
|
|
171
|
-
state.addPart(processedPart);
|
|
172
|
-
const result = await processor.processOutputStream({
|
|
173
|
-
part: processedPart,
|
|
174
|
-
streamParts: state.streamParts,
|
|
175
|
-
state: state.customState,
|
|
176
|
-
abort: reason => {
|
|
177
|
-
throw new TripWire(reason || `Stream part blocked by ${processor.name}`);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
processedPart = result;
|
|
181
|
-
}
|
|
182
|
-
} catch (error) {
|
|
183
|
-
if (error instanceof TripWire) {
|
|
184
|
-
return {
|
|
185
|
-
part: null,
|
|
186
|
-
blocked: true,
|
|
187
|
-
reason: error.message
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
this.logger.error(`[Agent:${this.agentName}] - Output processor ${processor.name} failed:`, error);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return {
|
|
194
|
-
part: processedPart,
|
|
195
|
-
blocked: false
|
|
196
|
-
};
|
|
197
|
-
} catch (error) {
|
|
198
|
-
this.logger.error(`[Agent:${this.agentName}] - Stream part processing failed:`, error);
|
|
199
|
-
return {
|
|
200
|
-
part,
|
|
201
|
-
blocked: false
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
async runOutputProcessorsForStream(streamResult) {
|
|
206
|
-
return new ReadableStream({
|
|
207
|
-
start: async controller => {
|
|
208
|
-
const reader = streamResult.fullStream.getReader();
|
|
209
|
-
const processorStates = /* @__PURE__ */new Map();
|
|
210
|
-
try {
|
|
211
|
-
while (true) {
|
|
212
|
-
const {
|
|
213
|
-
done,
|
|
214
|
-
value
|
|
215
|
-
} = await reader.read();
|
|
216
|
-
if (done) {
|
|
217
|
-
controller.close();
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
const {
|
|
221
|
-
part: processedPart,
|
|
222
|
-
blocked,
|
|
223
|
-
reason
|
|
224
|
-
} = await this.processPart(value, processorStates);
|
|
225
|
-
if (blocked) {
|
|
226
|
-
void this.logger.debug(`[Agent:${this.agentName}] - Stream part blocked by output processor`, {
|
|
227
|
-
reason,
|
|
228
|
-
originalPart: value
|
|
229
|
-
});
|
|
230
|
-
controller.enqueue({
|
|
231
|
-
type: "tripwire",
|
|
232
|
-
tripwireReason: reason || "Output processor blocked content"
|
|
233
|
-
});
|
|
234
|
-
controller.close();
|
|
235
|
-
break;
|
|
236
|
-
} else if (processedPart !== null) {
|
|
237
|
-
controller.enqueue(processedPart);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
} catch (error) {
|
|
241
|
-
controller.error(error);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
async runInputProcessors(messageList, telemetry) {
|
|
247
|
-
const userMessages = messageList.clear.input.v2();
|
|
248
|
-
let processableMessages = [...userMessages];
|
|
249
|
-
const ctx = {
|
|
250
|
-
abort: () => {
|
|
251
|
-
throw new TripWire("Tripwire triggered");
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
for (const [index, processor] of this.inputProcessors.entries()) {
|
|
255
|
-
const abort = reason => {
|
|
256
|
-
throw new TripWire(reason || `Tripwire triggered by ${processor.name}`);
|
|
257
|
-
};
|
|
258
|
-
ctx.abort = abort;
|
|
259
|
-
const processMethod = processor.processInput?.bind(processor);
|
|
260
|
-
if (!processMethod) {
|
|
261
|
-
continue;
|
|
262
|
-
}
|
|
263
|
-
if (!telemetry) {
|
|
264
|
-
processableMessages = await processMethod({
|
|
265
|
-
messages: processableMessages,
|
|
266
|
-
abort: ctx.abort
|
|
267
|
-
});
|
|
268
|
-
} else {
|
|
269
|
-
await telemetry.traceMethod(async () => {
|
|
270
|
-
processableMessages = await processMethod({
|
|
271
|
-
messages: processableMessages,
|
|
272
|
-
abort: ctx.abort
|
|
273
|
-
});
|
|
274
|
-
return processableMessages;
|
|
275
|
-
}, {
|
|
276
|
-
spanName: `agent.inputProcessor.${processor.name}`,
|
|
277
|
-
attributes: {
|
|
278
|
-
"processor.name": processor.name,
|
|
279
|
-
"processor.index": index.toString(),
|
|
280
|
-
"processor.total": this.inputProcessors.length.toString()
|
|
281
|
-
}
|
|
282
|
-
})();
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
if (processableMessages.length > 0) {
|
|
286
|
-
messageList.add(processableMessages, "user");
|
|
287
|
-
}
|
|
288
|
-
return messageList;
|
|
67
|
+
// src/stream/aisdk/v5/compat/ui-message.ts
|
|
68
|
+
function getResponseUIMessageId({
|
|
69
|
+
originalMessages,
|
|
70
|
+
responseMessageId
|
|
71
|
+
}) {
|
|
72
|
+
if (originalMessages == null) {
|
|
73
|
+
return void 0;
|
|
289
74
|
}
|
|
290
|
-
|
|
75
|
+
const lastMessage = originalMessages[originalMessages.length - 1];
|
|
76
|
+
return lastMessage?.role === "assistant" ? lastMessage.id : typeof responseMessageId === "function" ? responseMessageId() : responseMessageId;
|
|
77
|
+
}
|
|
291
78
|
function convertFullStreamChunkToUIMessageStream({
|
|
292
79
|
part,
|
|
293
80
|
messageMetadataValue,
|
|
@@ -540,16 +327,6 @@ function convertFullStreamChunkToUIMessageStream({
|
|
|
540
327
|
}
|
|
541
328
|
}
|
|
542
329
|
}
|
|
543
|
-
function getResponseUIMessageId({
|
|
544
|
-
originalMessages,
|
|
545
|
-
responseMessageId
|
|
546
|
-
}) {
|
|
547
|
-
if (originalMessages == null) {
|
|
548
|
-
return void 0;
|
|
549
|
-
}
|
|
550
|
-
const lastMessage = originalMessages[originalMessages.length - 1];
|
|
551
|
-
return lastMessage?.role === "assistant" ? lastMessage.id : typeof responseMessageId === "function" ? responseMessageId() : responseMessageId;
|
|
552
|
-
}
|
|
553
330
|
async function safeValidateTypes({
|
|
554
331
|
value,
|
|
555
332
|
schema
|
|
@@ -581,7 +358,50 @@ async function safeValidateTypes({
|
|
|
581
358
|
error: error instanceof Error ? error : new Error(String(error))
|
|
582
359
|
};
|
|
583
360
|
}
|
|
584
|
-
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/stream/aisdk/v5/compat/delayed-promise.ts
|
|
364
|
+
var DelayedPromise = class {
|
|
365
|
+
status = {
|
|
366
|
+
type: "pending"
|
|
367
|
+
};
|
|
368
|
+
_promise;
|
|
369
|
+
_resolve = void 0;
|
|
370
|
+
_reject = void 0;
|
|
371
|
+
get promise() {
|
|
372
|
+
if (this._promise) {
|
|
373
|
+
return this._promise;
|
|
374
|
+
}
|
|
375
|
+
this._promise = new Promise((resolve, reject) => {
|
|
376
|
+
if (this.status.type === "resolved") {
|
|
377
|
+
resolve(this.status.value);
|
|
378
|
+
} else if (this.status.type === "rejected") {
|
|
379
|
+
reject(this.status.error);
|
|
380
|
+
}
|
|
381
|
+
this._resolve = resolve;
|
|
382
|
+
this._reject = reject;
|
|
383
|
+
});
|
|
384
|
+
return this._promise;
|
|
385
|
+
}
|
|
386
|
+
resolve(value) {
|
|
387
|
+
this.status = {
|
|
388
|
+
type: "resolved",
|
|
389
|
+
value
|
|
390
|
+
};
|
|
391
|
+
if (this._promise) {
|
|
392
|
+
this._resolve?.(value);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
reject(error) {
|
|
396
|
+
this.status = {
|
|
397
|
+
type: "rejected",
|
|
398
|
+
error
|
|
399
|
+
};
|
|
400
|
+
if (this._promise) {
|
|
401
|
+
this._reject?.(error);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
};
|
|
585
405
|
function prepareToolsAndToolChoice({
|
|
586
406
|
tools,
|
|
587
407
|
toolChoice,
|
|
@@ -649,45 +469,229 @@ function prepareToolsAndToolChoice({
|
|
|
649
469
|
}
|
|
650
470
|
};
|
|
651
471
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
472
|
+
|
|
473
|
+
// src/agent/trip-wire.ts
|
|
474
|
+
var TripWire = class extends Error {
|
|
475
|
+
constructor(reason) {
|
|
476
|
+
super(reason);
|
|
477
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
// src/processors/runner.ts
|
|
482
|
+
var ProcessorState = class {
|
|
483
|
+
constructor(processorName) {
|
|
484
|
+
this.processorName = processorName;
|
|
485
|
+
}
|
|
486
|
+
accumulatedText = "";
|
|
487
|
+
customState = {};
|
|
488
|
+
streamParts = [];
|
|
489
|
+
// Internal methods for the runner
|
|
490
|
+
addPart(part) {
|
|
491
|
+
if (part.type === "text-delta") {
|
|
492
|
+
this.accumulatedText += part.payload.text;
|
|
662
493
|
}
|
|
663
|
-
this.
|
|
664
|
-
if (this.status.type === "resolved") {
|
|
665
|
-
resolve(this.status.value);
|
|
666
|
-
} else if (this.status.type === "rejected") {
|
|
667
|
-
reject(this.status.error);
|
|
668
|
-
}
|
|
669
|
-
this._resolve = resolve;
|
|
670
|
-
this._reject = reject;
|
|
671
|
-
});
|
|
672
|
-
return this._promise;
|
|
494
|
+
this.streamParts.push(part);
|
|
673
495
|
}
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
496
|
+
};
|
|
497
|
+
var ProcessorRunner = class {
|
|
498
|
+
inputProcessors;
|
|
499
|
+
outputProcessors;
|
|
500
|
+
logger;
|
|
501
|
+
agentName;
|
|
502
|
+
constructor({
|
|
503
|
+
inputProcessors,
|
|
504
|
+
outputProcessors,
|
|
505
|
+
logger,
|
|
506
|
+
agentName
|
|
507
|
+
}) {
|
|
508
|
+
this.inputProcessors = inputProcessors ?? [];
|
|
509
|
+
this.outputProcessors = outputProcessors ?? [];
|
|
510
|
+
this.logger = logger;
|
|
511
|
+
this.agentName = agentName;
|
|
512
|
+
}
|
|
513
|
+
async runOutputProcessors(messageList, telemetry) {
|
|
514
|
+
const responseMessages = messageList.clear.response.v2();
|
|
515
|
+
let processableMessages = [...responseMessages];
|
|
516
|
+
const ctx = {
|
|
517
|
+
abort: () => {
|
|
518
|
+
throw new TripWire("Tripwire triggered");
|
|
519
|
+
}
|
|
678
520
|
};
|
|
679
|
-
|
|
680
|
-
|
|
521
|
+
for (const [index, processor] of this.outputProcessors.entries()) {
|
|
522
|
+
const abort = reason => {
|
|
523
|
+
throw new TripWire(reason || `Tripwire triggered by ${processor.name}`);
|
|
524
|
+
};
|
|
525
|
+
ctx.abort = abort;
|
|
526
|
+
const processMethod = processor.processOutputResult?.bind(processor);
|
|
527
|
+
if (!processMethod) {
|
|
528
|
+
continue;
|
|
529
|
+
}
|
|
530
|
+
if (!telemetry) {
|
|
531
|
+
processableMessages = await processMethod({
|
|
532
|
+
messages: processableMessages,
|
|
533
|
+
abort: ctx.abort
|
|
534
|
+
});
|
|
535
|
+
} else {
|
|
536
|
+
await telemetry.traceMethod(async () => {
|
|
537
|
+
processableMessages = await processMethod({
|
|
538
|
+
messages: processableMessages,
|
|
539
|
+
abort: ctx.abort
|
|
540
|
+
});
|
|
541
|
+
return processableMessages;
|
|
542
|
+
}, {
|
|
543
|
+
spanName: `agent.outputProcessor.${processor.name}`,
|
|
544
|
+
attributes: {
|
|
545
|
+
"processor.name": processor.name,
|
|
546
|
+
"processor.index": index.toString(),
|
|
547
|
+
"processor.total": this.outputProcessors.length.toString()
|
|
548
|
+
}
|
|
549
|
+
})();
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
if (processableMessages.length > 0) {
|
|
553
|
+
messageList.add(processableMessages, "response");
|
|
681
554
|
}
|
|
555
|
+
return messageList;
|
|
682
556
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
557
|
+
/**
|
|
558
|
+
* Process a stream part through all output processors with state management
|
|
559
|
+
*/
|
|
560
|
+
async processPart(part, processorStates) {
|
|
561
|
+
if (!this.outputProcessors.length) {
|
|
562
|
+
return {
|
|
563
|
+
part,
|
|
564
|
+
blocked: false
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
try {
|
|
568
|
+
let processedPart = part;
|
|
569
|
+
for (const processor of this.outputProcessors) {
|
|
570
|
+
try {
|
|
571
|
+
if (processor.processOutputStream && processedPart) {
|
|
572
|
+
let state = processorStates.get(processor.name);
|
|
573
|
+
if (!state) {
|
|
574
|
+
state = new ProcessorState(processor.name);
|
|
575
|
+
processorStates.set(processor.name, state);
|
|
576
|
+
}
|
|
577
|
+
state.addPart(processedPart);
|
|
578
|
+
const result = await processor.processOutputStream({
|
|
579
|
+
part: processedPart,
|
|
580
|
+
streamParts: state.streamParts,
|
|
581
|
+
state: state.customState,
|
|
582
|
+
abort: reason => {
|
|
583
|
+
throw new TripWire(reason || `Stream part blocked by ${processor.name}`);
|
|
584
|
+
}
|
|
585
|
+
});
|
|
586
|
+
processedPart = result;
|
|
587
|
+
}
|
|
588
|
+
} catch (error) {
|
|
589
|
+
if (error instanceof TripWire) {
|
|
590
|
+
return {
|
|
591
|
+
part: null,
|
|
592
|
+
blocked: true,
|
|
593
|
+
reason: error.message
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
this.logger.error(`[Agent:${this.agentName}] - Output processor ${processor.name} failed:`, error);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return {
|
|
600
|
+
part: processedPart,
|
|
601
|
+
blocked: false
|
|
602
|
+
};
|
|
603
|
+
} catch (error) {
|
|
604
|
+
this.logger.error(`[Agent:${this.agentName}] - Stream part processing failed:`, error);
|
|
605
|
+
return {
|
|
606
|
+
part,
|
|
607
|
+
blocked: false
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
async runOutputProcessorsForStream(streamResult) {
|
|
612
|
+
return new ReadableStream({
|
|
613
|
+
start: async controller => {
|
|
614
|
+
const reader = streamResult.fullStream.getReader();
|
|
615
|
+
const processorStates = /* @__PURE__ */new Map();
|
|
616
|
+
try {
|
|
617
|
+
while (true) {
|
|
618
|
+
const {
|
|
619
|
+
done,
|
|
620
|
+
value
|
|
621
|
+
} = await reader.read();
|
|
622
|
+
if (done) {
|
|
623
|
+
controller.close();
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
const {
|
|
627
|
+
part: processedPart,
|
|
628
|
+
blocked,
|
|
629
|
+
reason
|
|
630
|
+
} = await this.processPart(value, processorStates);
|
|
631
|
+
if (blocked) {
|
|
632
|
+
void this.logger.debug(`[Agent:${this.agentName}] - Stream part blocked by output processor`, {
|
|
633
|
+
reason,
|
|
634
|
+
originalPart: value
|
|
635
|
+
});
|
|
636
|
+
controller.enqueue({
|
|
637
|
+
type: "tripwire",
|
|
638
|
+
tripwireReason: reason || "Output processor blocked content"
|
|
639
|
+
});
|
|
640
|
+
controller.close();
|
|
641
|
+
break;
|
|
642
|
+
} else if (processedPart !== null) {
|
|
643
|
+
controller.enqueue(processedPart);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
} catch (error) {
|
|
647
|
+
controller.error(error);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
async runInputProcessors(messageList, telemetry) {
|
|
653
|
+
const userMessages = messageList.clear.input.v2();
|
|
654
|
+
let processableMessages = [...userMessages];
|
|
655
|
+
const ctx = {
|
|
656
|
+
abort: () => {
|
|
657
|
+
throw new TripWire("Tripwire triggered");
|
|
658
|
+
}
|
|
687
659
|
};
|
|
688
|
-
|
|
689
|
-
|
|
660
|
+
for (const [index, processor] of this.inputProcessors.entries()) {
|
|
661
|
+
const abort = reason => {
|
|
662
|
+
throw new TripWire(reason || `Tripwire triggered by ${processor.name}`);
|
|
663
|
+
};
|
|
664
|
+
ctx.abort = abort;
|
|
665
|
+
const processMethod = processor.processInput?.bind(processor);
|
|
666
|
+
if (!processMethod) {
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
if (!telemetry) {
|
|
670
|
+
processableMessages = await processMethod({
|
|
671
|
+
messages: processableMessages,
|
|
672
|
+
abort: ctx.abort
|
|
673
|
+
});
|
|
674
|
+
} else {
|
|
675
|
+
await telemetry.traceMethod(async () => {
|
|
676
|
+
processableMessages = await processMethod({
|
|
677
|
+
messages: processableMessages,
|
|
678
|
+
abort: ctx.abort
|
|
679
|
+
});
|
|
680
|
+
return processableMessages;
|
|
681
|
+
}, {
|
|
682
|
+
spanName: `agent.inputProcessor.${processor.name}`,
|
|
683
|
+
attributes: {
|
|
684
|
+
"processor.name": processor.name,
|
|
685
|
+
"processor.index": index.toString(),
|
|
686
|
+
"processor.total": this.inputProcessors.length.toString()
|
|
687
|
+
}
|
|
688
|
+
})();
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
if (processableMessages.length > 0) {
|
|
692
|
+
messageList.add(processableMessages, "user");
|
|
690
693
|
}
|
|
694
|
+
return messageList;
|
|
691
695
|
}
|
|
692
696
|
};
|
|
693
697
|
function getTransformedSchema(schema) {
|
|
@@ -3285,7 +3289,9 @@ function createLLMExecutionStep({
|
|
|
3285
3289
|
toolCallStreaming,
|
|
3286
3290
|
controller,
|
|
3287
3291
|
output,
|
|
3288
|
-
headers
|
|
3292
|
+
headers,
|
|
3293
|
+
downloadRetries,
|
|
3294
|
+
downloadConcurrency
|
|
3289
3295
|
}) {
|
|
3290
3296
|
return createStep({
|
|
3291
3297
|
id: "llm-execution",
|
|
@@ -3306,11 +3312,16 @@ function createLLMExecutionStep({
|
|
|
3306
3312
|
switch (model.specificationVersion) {
|
|
3307
3313
|
case "v2":
|
|
3308
3314
|
{
|
|
3315
|
+
const inputMessages = await messageList.get.all.aiV5.llmPrompt({
|
|
3316
|
+
downloadRetries,
|
|
3317
|
+
downloadConcurrency,
|
|
3318
|
+
supportedUrls: model?.supportedUrls
|
|
3319
|
+
});
|
|
3309
3320
|
modelResult = execute({
|
|
3310
3321
|
runId,
|
|
3311
3322
|
model,
|
|
3312
3323
|
providerOptions,
|
|
3313
|
-
inputMessages
|
|
3324
|
+
inputMessages,
|
|
3314
3325
|
tools,
|
|
3315
3326
|
toolChoice,
|
|
3316
3327
|
options,
|
|
@@ -4043,7 +4054,8 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
4043
4054
|
resourceId,
|
|
4044
4055
|
output,
|
|
4045
4056
|
options,
|
|
4046
|
-
outputProcessors
|
|
4057
|
+
outputProcessors,
|
|
4058
|
+
providerOptions
|
|
4047
4059
|
// ...rest
|
|
4048
4060
|
}) {
|
|
4049
4061
|
let stopWhenToUse;
|
|
@@ -4076,6 +4088,7 @@ var MastraLLMVNext = class extends MastraBase {
|
|
|
4076
4088
|
stopWhen: stopWhenToUse,
|
|
4077
4089
|
toolChoice,
|
|
4078
4090
|
modelSettings,
|
|
4091
|
+
providerOptions,
|
|
4079
4092
|
telemetry_settings: {
|
|
4080
4093
|
...this.experimental_telemetry,
|
|
4081
4094
|
...telemetry_settings
|
|
@@ -15467,5 +15480,5 @@ function deepMergeWorkflowState(a, b) {
|
|
|
15467
15480
|
}
|
|
15468
15481
|
|
|
15469
15482
|
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 };
|
|
15470
|
-
//# sourceMappingURL=chunk-
|
|
15471
|
-
//# sourceMappingURL=chunk-
|
|
15483
|
+
//# sourceMappingURL=chunk-BGOXFBFK.js.map
|
|
15484
|
+
//# sourceMappingURL=chunk-BGOXFBFK.js.map
|