@mastra/core 1.20.0 → 1.21.0-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 +34 -0
- package/dist/_types/@internal_core/dist/index.d.ts +12 -2
- package/dist/agent/agent-legacy.d.ts +2 -1
- package/dist/agent/agent-legacy.d.ts.map +1 -1
- package/dist/agent/agent.d.ts +32 -2
- 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/{chunk-RB7WTRE2.js → chunk-2JJQDDEN.js} +8 -6
- package/dist/chunk-2JJQDDEN.js.map +1 -0
- package/dist/{chunk-2QO3IQWR.cjs → chunk-2STTKMFO.cjs} +82 -82
- package/dist/{chunk-2QO3IQWR.cjs.map → chunk-2STTKMFO.cjs.map} +1 -1
- package/dist/{chunk-3FW24B6P.cjs → chunk-3EPAGV3T.cjs} +4 -4
- package/dist/{chunk-3FW24B6P.cjs.map → chunk-3EPAGV3T.cjs.map} +1 -1
- package/dist/{chunk-F3OO446O.cjs → chunk-3OK3LWP4.cjs} +34 -32
- package/dist/chunk-3OK3LWP4.cjs.map +1 -0
- package/dist/{chunk-7JKIBZI7.js → chunk-5QQZSWLU.js} +4 -4
- package/dist/{chunk-7JKIBZI7.js.map → chunk-5QQZSWLU.js.map} +1 -1
- package/dist/{chunk-7URCVA7N.js → chunk-6PJQGNFV.js} +10 -10
- package/dist/chunk-6PJQGNFV.js.map +1 -0
- package/dist/{chunk-ED6CLXQI.cjs → chunk-75LYWKFT.cjs} +25 -25
- package/dist/chunk-75LYWKFT.cjs.map +1 -0
- package/dist/{chunk-53NCHPV5.cjs → chunk-AL5ACSAH.cjs} +7 -7
- package/dist/{chunk-53NCHPV5.cjs.map → chunk-AL5ACSAH.cjs.map} +1 -1
- package/dist/{chunk-S3JFAGMH.js → chunk-B4KB75RH.js} +67 -21
- package/dist/chunk-B4KB75RH.js.map +1 -0
- package/dist/{chunk-3R4YK3VD.js → chunk-CJA2FWKT.js} +3 -3
- package/dist/{chunk-3R4YK3VD.js.map → chunk-CJA2FWKT.js.map} +1 -1
- package/dist/{chunk-FQCASJGT.js → chunk-D7NEB3NV.js} +5 -5
- package/dist/{chunk-FQCASJGT.js.map → chunk-D7NEB3NV.js.map} +1 -1
- package/dist/{chunk-CRGRF7QL.cjs → chunk-E4TMODUG.cjs} +75 -29
- package/dist/chunk-E4TMODUG.cjs.map +1 -0
- package/dist/{chunk-Q4YIRO5A.js → chunk-ESQI2JRD.js} +5 -3
- package/dist/chunk-ESQI2JRD.js.map +1 -0
- package/dist/{chunk-57OYWNNV.cjs → chunk-EX2LVHTL.cjs} +97 -288
- package/dist/chunk-EX2LVHTL.cjs.map +1 -0
- package/dist/{chunk-J7AHOVB2.cjs → chunk-F6ZURDS4.cjs} +368 -218
- package/dist/chunk-F6ZURDS4.cjs.map +1 -0
- package/dist/chunk-FAULJTC5.js +290 -0
- package/dist/chunk-FAULJTC5.js.map +1 -0
- package/dist/{chunk-T72NHA2O.cjs → chunk-FJT6H2US.cjs} +3 -3
- package/dist/chunk-FJT6H2US.cjs.map +1 -0
- package/dist/{chunk-BCOOJFBB.js → chunk-GGJSRBFY.js} +13 -7
- package/dist/chunk-GGJSRBFY.js.map +1 -0
- package/dist/{chunk-CU6QKXLW.js → chunk-HU6OWHBI.js} +3 -3
- package/dist/{chunk-CU6QKXLW.js.map → chunk-HU6OWHBI.js.map} +1 -1
- package/dist/{chunk-JBOVTCTQ.cjs → chunk-I7AUCCNO.cjs} +69 -69
- package/dist/{chunk-JBOVTCTQ.cjs.map → chunk-I7AUCCNO.cjs.map} +1 -1
- package/dist/{chunk-GFRRPVRL.cjs → chunk-IG6JCDCL.cjs} +185 -185
- package/dist/{chunk-GFRRPVRL.cjs.map → chunk-IG6JCDCL.cjs.map} +1 -1
- package/dist/{chunk-UFXC6VJW.js → chunk-JB7HORUI.js} +3 -3
- package/dist/{chunk-UFXC6VJW.js.map → chunk-JB7HORUI.js.map} +1 -1
- package/dist/{chunk-2H6WEHWI.js → chunk-JBLN5IVV.js} +4 -4
- package/dist/{chunk-2H6WEHWI.js.map → chunk-JBLN5IVV.js.map} +1 -1
- package/dist/{chunk-HOAKFZ6P.js → chunk-JIA3SJK6.js} +198 -48
- package/dist/chunk-JIA3SJK6.js.map +1 -0
- package/dist/{chunk-MIWHSH7L.js → chunk-KLHD3PBK.js} +3 -3
- package/dist/chunk-KLHD3PBK.js.map +1 -0
- package/dist/{chunk-5PAHRQLU.js → chunk-ODUJYYA5.js} +32 -7
- package/dist/chunk-ODUJYYA5.js.map +1 -0
- package/dist/chunk-QRJSP5G2.cjs +300 -0
- package/dist/chunk-QRJSP5G2.cjs.map +1 -0
- package/dist/{chunk-7PYYVPF5.js → chunk-RF42EKVR.js} +6 -6
- package/dist/{chunk-7PYYVPF5.js.map → chunk-RF42EKVR.js.map} +1 -1
- package/dist/{chunk-L6AZQNL2.cjs → chunk-S6B5GIFC.cjs} +31 -25
- package/dist/chunk-S6B5GIFC.cjs.map +1 -0
- package/dist/{chunk-YEQJIM5W.cjs → chunk-TMRHUTY6.cjs} +15 -15
- package/dist/{chunk-YEQJIM5W.cjs.map → chunk-TMRHUTY6.cjs.map} +1 -1
- package/dist/{chunk-BZW4PQNA.cjs → chunk-UUNTJ256.cjs} +9 -7
- package/dist/chunk-UUNTJ256.cjs.map +1 -0
- package/dist/{chunk-RDHIVATT.cjs → chunk-VAACVUEO.cjs} +9 -9
- package/dist/{chunk-RDHIVATT.cjs.map → chunk-VAACVUEO.cjs.map} +1 -1
- package/dist/{chunk-UCCVELTP.js → chunk-VJKW6RRY.js} +7 -7
- package/dist/{chunk-UCCVELTP.js.map → chunk-VJKW6RRY.js.map} +1 -1
- package/dist/{chunk-2NISBCML.js → chunk-WG7QIVL7.js} +92 -280
- package/dist/chunk-WG7QIVL7.js.map +1 -0
- package/dist/{chunk-QG7NJ3JU.cjs → chunk-XANKVDSM.cjs} +10 -10
- package/dist/{chunk-QG7NJ3JU.cjs.map → chunk-XANKVDSM.cjs.map} +1 -1
- package/dist/{chunk-HVVHMUI4.cjs → chunk-Z745DCGY.cjs} +34 -9
- package/dist/chunk-Z745DCGY.cjs.map +1 -0
- package/dist/datasets/experiment/scorer.d.ts.map +1 -1
- package/dist/datasets/index.cjs +17 -17
- package/dist/datasets/index.js +2 -2
- package/dist/docs/SKILL.md +3 -3
- package/dist/docs/assets/SOURCE_MAP.json +522 -522
- package/dist/docs/references/docs-server-mastra-client.md +12 -10
- package/dist/docs/references/docs-server-mastra-server.md +13 -1
- package/dist/docs/references/docs-studio-observability.md +9 -1
- package/dist/docs/references/docs-studio-overview.md +1 -1
- package/dist/docs/references/reference-agents-getLLM.md +9 -3
- package/dist/docs/references/reference.md +2 -0
- package/dist/evals/base.d.ts +29 -6
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/index.cjs +23 -23
- package/dist/evals/index.js +3 -3
- package/dist/evals/scoreTraces/index.cjs +21 -37
- package/dist/evals/scoreTraces/index.cjs.map +1 -1
- package/dist/evals/scoreTraces/index.js +18 -34
- package/dist/evals/scoreTraces/index.js.map +1 -1
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts +2 -3
- package/dist/evals/scoreTraces/scoreTracesWorkflow.d.ts.map +1 -1
- package/dist/evals/types.d.ts.map +1 -1
- package/dist/harness/index.cjs +9 -9
- package/dist/harness/index.js +6 -6
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/llm/index.cjs +16 -16
- package/dist/llm/index.js +5 -5
- package/dist/llm/model/provider-types.generated.d.ts +1 -0
- package/dist/logger/index.cjs +6 -6
- package/dist/logger/index.js +1 -1
- package/dist/loop/index.cjs +14 -14
- package/dist/loop/index.js +1 -1
- package/dist/mastra/hooks.d.ts +3 -0
- package/dist/mastra/hooks.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.d.ts +3 -3
- package/dist/mastra/index.d.ts.map +1 -1
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +14 -14
- package/dist/memory/index.js +1 -1
- package/dist/models-dev-4HBR4MAS.js +3 -0
- package/dist/{models-dev-WTF6UG4D.js.map → models-dev-4HBR4MAS.js.map} +1 -1
- package/dist/models-dev-W2D3QNCX.cjs +12 -0
- package/dist/{models-dev-TKKI7LVH.cjs.map → models-dev-W2D3QNCX.cjs.map} +1 -1
- package/dist/netlify-A6TIZLU7.cjs +12 -0
- package/dist/{netlify-QCPWAYI2.cjs.map → netlify-A6TIZLU7.cjs.map} +1 -1
- package/dist/netlify-YRVEP6E4.js +3 -0
- package/dist/{netlify-V6N4TT4H.js.map → netlify-YRVEP6E4.js.map} +1 -1
- package/dist/observability/index.cjs +36 -32
- package/dist/observability/index.js +2 -2
- package/dist/observability/no-op.d.ts +1 -1
- package/dist/observability/no-op.d.ts.map +1 -1
- package/dist/observability/types/core.d.ts +15 -1
- package/dist/observability/types/core.d.ts.map +1 -1
- package/dist/observability/types/feedback.d.ts +2 -2
- package/dist/observability/types/feedback.d.ts.map +1 -1
- package/dist/observability/types/scores.d.ts +16 -7
- package/dist/observability/types/scores.d.ts.map +1 -1
- package/dist/observability/types/tracing.d.ts +27 -1
- package/dist/observability/types/tracing.d.ts.map +1 -1
- package/dist/observability/utils.d.ts +12 -1
- package/dist/observability/utils.d.ts.map +1 -1
- package/dist/processor-provider/index.cjs +10 -10
- package/dist/processor-provider/index.js +1 -1
- package/dist/processors/index.cjs +44 -44
- package/dist/processors/index.js +1 -1
- package/dist/provider-registry-6ONBOGD7.cjs +40 -0
- package/dist/{provider-registry-C54SHAP6.cjs.map → provider-registry-6ONBOGD7.cjs.map} +1 -1
- package/dist/provider-registry-AIPF3CGZ.js +3 -0
- package/dist/{provider-registry-34O53EL4.js.map → provider-registry-AIPF3CGZ.js.map} +1 -1
- package/dist/provider-registry.json +4 -2
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/storage/constants.cjs +56 -56
- package/dist/storage/constants.js +1 -1
- package/dist/storage/domains/observability/base.d.ts +4 -0
- package/dist/storage/domains/observability/base.d.ts.map +1 -1
- package/dist/storage/domains/observability/record-builders.d.ts.map +1 -1
- package/dist/storage/index.cjs +286 -286
- package/dist/storage/index.js +3 -3
- package/dist/stream/index.cjs +8 -8
- package/dist/stream/index.js +1 -1
- package/dist/test-utils/llm-mock.cjs +4 -4
- package/dist/test-utils/llm-mock.js +1 -1
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/utils.cjs +25 -25
- package/dist/utils.js +1 -1
- package/dist/vector/index.cjs +7 -7
- package/dist/vector/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 +4 -4
- package/src/llm/model/provider-types.generated.d.ts +1 -0
- package/dist/chunk-2NISBCML.js.map +0 -1
- package/dist/chunk-57OYWNNV.cjs.map +0 -1
- package/dist/chunk-5PAHRQLU.js.map +0 -1
- package/dist/chunk-7URCVA7N.js.map +0 -1
- package/dist/chunk-AC5GUOWY.js +0 -72
- package/dist/chunk-AC5GUOWY.js.map +0 -1
- package/dist/chunk-BCOOJFBB.js.map +0 -1
- package/dist/chunk-BZW4PQNA.cjs.map +0 -1
- package/dist/chunk-CRGRF7QL.cjs.map +0 -1
- package/dist/chunk-ED6CLXQI.cjs.map +0 -1
- package/dist/chunk-EZHHTAJU.cjs +0 -78
- package/dist/chunk-EZHHTAJU.cjs.map +0 -1
- package/dist/chunk-F3OO446O.cjs.map +0 -1
- package/dist/chunk-HOAKFZ6P.js.map +0 -1
- package/dist/chunk-HVVHMUI4.cjs.map +0 -1
- package/dist/chunk-J7AHOVB2.cjs.map +0 -1
- package/dist/chunk-L6AZQNL2.cjs.map +0 -1
- package/dist/chunk-MIWHSH7L.js.map +0 -1
- package/dist/chunk-Q4YIRO5A.js.map +0 -1
- package/dist/chunk-RB7WTRE2.js.map +0 -1
- package/dist/chunk-S3JFAGMH.js.map +0 -1
- package/dist/chunk-T72NHA2O.cjs.map +0 -1
- package/dist/models-dev-TKKI7LVH.cjs +0 -12
- package/dist/models-dev-WTF6UG4D.js +0 -3
- package/dist/netlify-QCPWAYI2.cjs +0 -12
- package/dist/netlify-V6N4TT4H.js +0 -3
- package/dist/provider-registry-34O53EL4.js +0 -3
- package/dist/provider-registry-C54SHAP6.cjs +0 -40
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { DefaultVoice } from './chunk-YXGTSH4J.js';
|
|
2
2
|
import { PUBSUB_SYMBOL, STREAM_FORMAT_SYMBOL } from './chunk-2QXNHEDL.js';
|
|
3
3
|
import { createWorkspaceTools, createSkillTools, getTiktoken, BM25Index } from './chunk-5TG6LPAB.js';
|
|
4
|
-
import { InMemoryStore } from './chunk-
|
|
4
|
+
import { InMemoryStore } from './chunk-GGJSRBFY.js';
|
|
5
5
|
import { MessageList, coreContentToString, DefaultGeneratedFile, DefaultGeneratedFileWithType, sanitizeToolName } from './chunk-NRA3BO5W.js';
|
|
6
6
|
import { parsePartialJson, isDeepEqualData, stepCountIs } from './chunk-2PHG443D.js';
|
|
7
7
|
import { generateId, APICallError, tool, asSchema } from './chunk-6PALJNKG.js';
|
|
8
8
|
import { executeHook } from './chunk-L54GIUCB.js';
|
|
9
|
-
import { resolveModelConfig, ModelRouterEmbeddingModel, ModelRouterLanguageModel } from './chunk-
|
|
10
|
-
import { MastraLLMV1 } from './chunk-
|
|
11
|
-
import { noopLogger } from './chunk-
|
|
9
|
+
import { resolveModelConfig, ModelRouterEmbeddingModel, ModelRouterLanguageModel } from './chunk-VJKW6RRY.js';
|
|
10
|
+
import { MastraLLMV1 } from './chunk-D7NEB3NV.js';
|
|
11
|
+
import { noopLogger } from './chunk-CJA2FWKT.js';
|
|
12
12
|
import { EventEmitterPubSub } from './chunk-X2HAI3OX.js';
|
|
13
|
-
import { removeUndefinedValues, safeStringify, ensureToolProperties, makeCoreTool, createMastraProxy, deepMerge, generateEmptyFromSchema, selectFields, ensureSerializable, delay } from './chunk-
|
|
14
|
-
import { resolveObservabilityContext,
|
|
13
|
+
import { removeUndefinedValues, safeStringify, ensureToolProperties, makeCoreTool, createMastraProxy, deepMerge, generateEmptyFromSchema, selectFields, ensureSerializable, delay } from './chunk-JBLN5IVV.js';
|
|
14
|
+
import { resolveObservabilityContext, createObservabilityContext, wrapMastra } from './chunk-FAULJTC5.js';
|
|
15
15
|
import { ToolStream } from './chunk-DD2VNRQM.js';
|
|
16
16
|
import { Tool, createTool, isMastraTool, isProviderTool, getProviderToolName, isProviderDefinedTool } from './chunk-EWPUWV33.js';
|
|
17
17
|
import { toStandardSchema, standardSchemaToJSONSchema, isStandardSchemaWithJSON } from './chunk-6SRTDZ7S.js';
|
|
18
|
-
import { getRootExportSpan, getOrCreateSpan, executeWithContext, executeWithContextSync } from './chunk-
|
|
18
|
+
import { EntityType, getRootExportSpan, getOrCreateSpan, executeWithContext, executeWithContextSync } from './chunk-WG7QIVL7.js';
|
|
19
19
|
import { RequestContext, MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY } from './chunk-JGOH7RWL.js';
|
|
20
20
|
import { MastraError, getErrorFromUnknown } from './chunk-FJEVLHJT.js';
|
|
21
21
|
import { MastraBase } from './chunk-S36QLQEK.js';
|
|
@@ -11190,6 +11190,15 @@ var MastraScorer = class _MastraScorer {
|
|
|
11190
11190
|
get hasGenerateScore() {
|
|
11191
11191
|
return this.steps.some((step) => step.name === "generateScore");
|
|
11192
11192
|
}
|
|
11193
|
+
normalizeRunRequestContext(requestContext) {
|
|
11194
|
+
if (!requestContext) {
|
|
11195
|
+
return void 0;
|
|
11196
|
+
}
|
|
11197
|
+
if (requestContext instanceof RequestContext) {
|
|
11198
|
+
return requestContext;
|
|
11199
|
+
}
|
|
11200
|
+
return new RequestContext(Object.entries(requestContext));
|
|
11201
|
+
}
|
|
11193
11202
|
async run(input) {
|
|
11194
11203
|
if (!this.hasGenerateScore) {
|
|
11195
11204
|
throw new MastraError({
|
|
@@ -11203,21 +11212,70 @@ var MastraScorer = class _MastraScorer {
|
|
|
11203
11212
|
}
|
|
11204
11213
|
});
|
|
11205
11214
|
}
|
|
11206
|
-
const observabilityContext = resolveObservabilityContext(input);
|
|
11207
11215
|
let runId = input.runId;
|
|
11208
11216
|
if (!runId) {
|
|
11209
11217
|
runId = randomUUID();
|
|
11210
11218
|
}
|
|
11211
|
-
const
|
|
11212
|
-
const
|
|
11213
|
-
|
|
11214
|
-
|
|
11215
|
-
|
|
11216
|
-
|
|
11219
|
+
const normalizedRequestContext = this.normalizeRunRequestContext(input.requestContext);
|
|
11220
|
+
const evalSpan = getOrCreateSpan({
|
|
11221
|
+
type: "scorer_run" /* SCORER_RUN */,
|
|
11222
|
+
name: `scorer run: '${this.id}'`,
|
|
11223
|
+
entityType: EntityType.SCORER,
|
|
11224
|
+
entityId: this.id,
|
|
11225
|
+
input: {
|
|
11226
|
+
input: input.input,
|
|
11227
|
+
output: input.output,
|
|
11228
|
+
groundTruth: input.groundTruth,
|
|
11229
|
+
expectedTrajectory: input.expectedTrajectory,
|
|
11230
|
+
requestContext: normalizedRequestContext
|
|
11217
11231
|
},
|
|
11218
|
-
|
|
11232
|
+
attributes: {
|
|
11233
|
+
scorerId: this.id,
|
|
11234
|
+
scorerName: this.name,
|
|
11235
|
+
...input.scoreSource ? { scoreSource: input.scoreSource } : {},
|
|
11236
|
+
...input.targetScope ? { targetScope: input.targetScope } : {},
|
|
11237
|
+
...input.targetEntityType ? { targetEntityType: input.targetEntityType } : {},
|
|
11238
|
+
...this.source ? { scorerDefinition: this.source } : {}
|
|
11239
|
+
},
|
|
11240
|
+
metadata: {
|
|
11241
|
+
...input.targetTraceId ? { targetTraceId: input.targetTraceId } : {},
|
|
11242
|
+
...input.targetSpanId ? { targetSpanId: input.targetSpanId } : {}
|
|
11243
|
+
},
|
|
11244
|
+
mastra: this.#mastra
|
|
11219
11245
|
});
|
|
11246
|
+
const run = {
|
|
11247
|
+
...input,
|
|
11248
|
+
runId,
|
|
11249
|
+
...evalSpan?.traceId ? { scoreTraceId: evalSpan.traceId } : {}
|
|
11250
|
+
};
|
|
11251
|
+
const scorerObservabilityContext = createObservabilityContext({ currentSpan: evalSpan });
|
|
11252
|
+
let workflow;
|
|
11253
|
+
let workflowRun;
|
|
11254
|
+
try {
|
|
11255
|
+
workflow = this.toMastraWorkflow();
|
|
11256
|
+
workflowRun = await workflow.createRun();
|
|
11257
|
+
} catch (error) {
|
|
11258
|
+
evalSpan?.error({ error, endSpan: true });
|
|
11259
|
+
throw error;
|
|
11260
|
+
}
|
|
11261
|
+
let workflowResult;
|
|
11262
|
+
try {
|
|
11263
|
+
workflowResult = await executeWithContext({
|
|
11264
|
+
span: evalSpan,
|
|
11265
|
+
fn: () => workflowRun.start({
|
|
11266
|
+
inputData: {
|
|
11267
|
+
run
|
|
11268
|
+
},
|
|
11269
|
+
...scorerObservabilityContext
|
|
11270
|
+
})
|
|
11271
|
+
});
|
|
11272
|
+
} catch (error) {
|
|
11273
|
+
evalSpan?.error({ error, endSpan: true });
|
|
11274
|
+
throw error;
|
|
11275
|
+
}
|
|
11220
11276
|
if (workflowResult.status === "failed") {
|
|
11277
|
+
const workflowFailure = workflowResult.error instanceof Error ? workflowResult.error : new Error(typeof workflowResult.error === "string" ? workflowResult.error : "Scorer workflow failed");
|
|
11278
|
+
evalSpan?.error({ error: workflowFailure, endSpan: true });
|
|
11221
11279
|
throw new MastraError(
|
|
11222
11280
|
{
|
|
11223
11281
|
id: "MASTR_SCORER_FAILED_TO_RUN_WORKFLOW_FAILED",
|
|
@@ -11232,7 +11290,46 @@ var MastraScorer = class _MastraScorer {
|
|
|
11232
11290
|
workflowResult.error instanceof Error ? workflowResult.error : void 0
|
|
11233
11291
|
);
|
|
11234
11292
|
}
|
|
11235
|
-
|
|
11293
|
+
const scorerResult = this.transformToScorerResult({ workflowResult, originalInput: run });
|
|
11294
|
+
evalSpan?.end({
|
|
11295
|
+
output: {
|
|
11296
|
+
success: true,
|
|
11297
|
+
score: typeof scorerResult.score === "number" ? scorerResult.score : null,
|
|
11298
|
+
reason: typeof scorerResult.reason === "string" ? scorerResult.reason : null
|
|
11299
|
+
}
|
|
11300
|
+
});
|
|
11301
|
+
if (this.#mastra?.observability.addScore && typeof scorerResult.score === "number") {
|
|
11302
|
+
try {
|
|
11303
|
+
if (!input.targetTraceId) {
|
|
11304
|
+
return scorerResult;
|
|
11305
|
+
}
|
|
11306
|
+
await this.#mastra.observability.addScore({
|
|
11307
|
+
traceId: input.targetTraceId,
|
|
11308
|
+
...input.targetSpanId ? { spanId: input.targetSpanId } : {},
|
|
11309
|
+
score: {
|
|
11310
|
+
scorerId: this.id,
|
|
11311
|
+
scorerName: this.name,
|
|
11312
|
+
...input.scoreSource ? { scoreSource: input.scoreSource } : {},
|
|
11313
|
+
score: scorerResult.score,
|
|
11314
|
+
...typeof scorerResult.reason === "string" ? { reason: scorerResult.reason } : {},
|
|
11315
|
+
...typeof scorerResult.scoreTraceId === "string" ? { scoreTraceId: scorerResult.scoreTraceId } : {},
|
|
11316
|
+
...input.targetEntityType ? { targetEntityType: input.targetEntityType } : {},
|
|
11317
|
+
metadata: {
|
|
11318
|
+
hasGroundTruth: input.groundTruth !== void 0,
|
|
11319
|
+
...input.targetScope ? { targetScope: input.targetScope } : {},
|
|
11320
|
+
...this.source ? { scorerDefinition: this.source } : {}
|
|
11321
|
+
}
|
|
11322
|
+
// TODO: Add targetEntityId / targetEntityName once the score event/storage
|
|
11323
|
+
// contract has first-class fields for unanchored score target identity.
|
|
11324
|
+
// TODO: Add any remaining correlation context that is useful when a
|
|
11325
|
+
// score is emitted without a target trace/span anchor.
|
|
11326
|
+
}
|
|
11327
|
+
});
|
|
11328
|
+
} catch (error) {
|
|
11329
|
+
this.#mastra.getLogger()?.warn?.(`Failed to emit score to observability for scorer ${this.id}:`, error);
|
|
11330
|
+
}
|
|
11331
|
+
}
|
|
11332
|
+
return scorerResult;
|
|
11236
11333
|
}
|
|
11237
11334
|
isPromptObject(stepDef) {
|
|
11238
11335
|
if (typeof stepDef === "object" && "description" in stepDef && "createPrompt" in stepDef && !("outputSchema" in stepDef)) {
|
|
@@ -11242,11 +11339,14 @@ var MastraScorer = class _MastraScorer {
|
|
|
11242
11339
|
return isOtherPromptObject;
|
|
11243
11340
|
}
|
|
11244
11341
|
getSteps() {
|
|
11245
|
-
return this.steps.map((step) =>
|
|
11246
|
-
name: step.
|
|
11247
|
-
|
|
11248
|
-
|
|
11249
|
-
|
|
11342
|
+
return this.steps.map((step) => {
|
|
11343
|
+
const description = step.isPromptObject ? this.originalPromptObjects.get(step.name)?.description : step.definition?.description;
|
|
11344
|
+
return {
|
|
11345
|
+
name: step.name,
|
|
11346
|
+
type: step.isPromptObject ? "prompt" : "function",
|
|
11347
|
+
description
|
|
11348
|
+
};
|
|
11349
|
+
});
|
|
11250
11350
|
}
|
|
11251
11351
|
toMastraWorkflow() {
|
|
11252
11352
|
const workflowSteps = this.steps.map((scorerStep) => {
|
|
@@ -11260,18 +11360,62 @@ var MastraScorer = class _MastraScorer {
|
|
|
11260
11360
|
const { accumulatedResults = {}, generatedPrompts = {} } = inputData;
|
|
11261
11361
|
const { run } = getInitData();
|
|
11262
11362
|
const context = this.createScorerContext(scorerStep.name, run, accumulatedResults);
|
|
11363
|
+
const currentSpan = observabilityContext.tracingContext.currentSpan;
|
|
11364
|
+
const scorerRunSpan = currentSpan?.type === "scorer_run" /* SCORER_RUN */ ? currentSpan : currentSpan?.findParent("scorer_run" /* SCORER_RUN */);
|
|
11365
|
+
const stepSpan = scorerRunSpan?.createChildSpan({
|
|
11366
|
+
type: "scorer_step" /* SCORER_STEP */,
|
|
11367
|
+
name: `scorer step: '${scorerStep.name}'`,
|
|
11368
|
+
entityType: EntityType.SCORER,
|
|
11369
|
+
entityId: this.config.id ?? this.config.name,
|
|
11370
|
+
input: context,
|
|
11371
|
+
attributes: {
|
|
11372
|
+
step: scorerStep.name,
|
|
11373
|
+
stepType: scorerStep.isPromptObject ? "prompt" : "function"
|
|
11374
|
+
}
|
|
11375
|
+
});
|
|
11376
|
+
const stepObservabilityContext = createObservabilityContext({ currentSpan: stepSpan });
|
|
11377
|
+
const executionContext = {
|
|
11378
|
+
...context,
|
|
11379
|
+
...stepObservabilityContext
|
|
11380
|
+
};
|
|
11263
11381
|
let stepResult;
|
|
11264
|
-
let
|
|
11265
|
-
|
|
11266
|
-
|
|
11267
|
-
|
|
11268
|
-
|
|
11269
|
-
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
|
|
11273
|
-
|
|
11382
|
+
let prompt;
|
|
11383
|
+
let judgeModel;
|
|
11384
|
+
try {
|
|
11385
|
+
await executeWithContext({
|
|
11386
|
+
span: stepSpan,
|
|
11387
|
+
fn: async () => {
|
|
11388
|
+
if (scorerStep.isPromptObject) {
|
|
11389
|
+
const promptStepResult = await this.executePromptStep(
|
|
11390
|
+
scorerStep,
|
|
11391
|
+
stepObservabilityContext,
|
|
11392
|
+
executionContext
|
|
11393
|
+
);
|
|
11394
|
+
stepResult = promptStepResult.result;
|
|
11395
|
+
prompt = promptStepResult.prompt;
|
|
11396
|
+
judgeModel = promptStepResult.judgeModel;
|
|
11397
|
+
} else {
|
|
11398
|
+
stepResult = await this.executeFunctionStep(scorerStep, executionContext);
|
|
11399
|
+
}
|
|
11400
|
+
}
|
|
11401
|
+
});
|
|
11402
|
+
} catch (error) {
|
|
11403
|
+
stepSpan?.error({ error, endSpan: true });
|
|
11404
|
+
throw error;
|
|
11274
11405
|
}
|
|
11406
|
+
if (prompt !== void 0 || judgeModel !== void 0) {
|
|
11407
|
+
stepSpan?.update({
|
|
11408
|
+
attributes: {
|
|
11409
|
+
...prompt !== void 0 ? { prompt } : {},
|
|
11410
|
+
...judgeModel !== void 0 ? { judgeModel } : {}
|
|
11411
|
+
}
|
|
11412
|
+
});
|
|
11413
|
+
}
|
|
11414
|
+
stepSpan?.end({ output: stepResult });
|
|
11415
|
+
const newGeneratedPrompts = prompt !== void 0 ? {
|
|
11416
|
+
...generatedPrompts,
|
|
11417
|
+
[`${scorerStep.name}Prompt`]: prompt
|
|
11418
|
+
} : generatedPrompts;
|
|
11275
11419
|
const newAccumulatedResults = {
|
|
11276
11420
|
...accumulatedResults,
|
|
11277
11421
|
[`${scorerStep.name}StepResult`]: stepResult
|
|
@@ -11303,10 +11447,6 @@ var MastraScorer = class _MastraScorer {
|
|
|
11303
11447
|
generateReasonPrompt: z.string().optional()
|
|
11304
11448
|
}),
|
|
11305
11449
|
options: {
|
|
11306
|
-
// mark all spans generated as part of the scorer workflow internal
|
|
11307
|
-
tracingPolicy: {
|
|
11308
|
-
internal: 15 /* ALL */
|
|
11309
|
-
},
|
|
11310
11450
|
validateInputs: false
|
|
11311
11451
|
}
|
|
11312
11452
|
});
|
|
@@ -11348,12 +11488,12 @@ var MastraScorer = class _MastraScorer {
|
|
|
11348
11488
|
});
|
|
11349
11489
|
}
|
|
11350
11490
|
const resolvedModel = await resolveModelConfig(modelConfig, void 0, this.#mastra);
|
|
11491
|
+
const judgeModel = resolvedModel.modelId;
|
|
11351
11492
|
const judge = new Agent({
|
|
11352
11493
|
id: "judge",
|
|
11353
11494
|
name: "judge",
|
|
11354
11495
|
model: resolvedModel,
|
|
11355
|
-
instructions
|
|
11356
|
-
options: { tracingPolicy: { internal: 15 /* ALL */ } }
|
|
11496
|
+
instructions
|
|
11357
11497
|
});
|
|
11358
11498
|
if (scorerStep.name === "generateScore") {
|
|
11359
11499
|
let result;
|
|
@@ -11374,7 +11514,7 @@ var MastraScorer = class _MastraScorer {
|
|
|
11374
11514
|
...observabilityContext
|
|
11375
11515
|
});
|
|
11376
11516
|
}
|
|
11377
|
-
return { result: result.object.score, prompt };
|
|
11517
|
+
return { result: result.object.score, prompt, judgeModel };
|
|
11378
11518
|
} else if (scorerStep.name === "generateReason") {
|
|
11379
11519
|
let result;
|
|
11380
11520
|
if (isSupportedLanguageModel(resolvedModel)) {
|
|
@@ -11382,7 +11522,7 @@ var MastraScorer = class _MastraScorer {
|
|
|
11382
11522
|
} else {
|
|
11383
11523
|
result = await judge.generateLegacy(prompt, { ...observabilityContext });
|
|
11384
11524
|
}
|
|
11385
|
-
return { result: result.text, prompt };
|
|
11525
|
+
return { result: result.text, prompt, judgeModel };
|
|
11386
11526
|
} else {
|
|
11387
11527
|
const promptStep = originalStep;
|
|
11388
11528
|
const standardSchema = toStandardSchema(promptStep.outputSchema);
|
|
@@ -11400,7 +11540,7 @@ var MastraScorer = class _MastraScorer {
|
|
|
11400
11540
|
...observabilityContext
|
|
11401
11541
|
});
|
|
11402
11542
|
}
|
|
11403
|
-
return { result: result.object, prompt };
|
|
11543
|
+
return { result: result.object, prompt, judgeModel };
|
|
11404
11544
|
}
|
|
11405
11545
|
}
|
|
11406
11546
|
transformToScorerResult({
|
|
@@ -17564,7 +17704,10 @@ var AgentLegacyHandler = class {
|
|
|
17564
17704
|
resourceId
|
|
17565
17705
|
}) || randomUUID();
|
|
17566
17706
|
const instructions = args.instructions || await this.capabilities.getInstructions({ requestContext });
|
|
17567
|
-
const llm = await this.capabilities.getLLM({
|
|
17707
|
+
const llm = await this.capabilities.getLLM({
|
|
17708
|
+
requestContext,
|
|
17709
|
+
model: args.model
|
|
17710
|
+
});
|
|
17568
17711
|
const memory = await this.capabilities.getMemory({ requestContext });
|
|
17569
17712
|
const { before, after } = this.__primitive({
|
|
17570
17713
|
messages,
|
|
@@ -22089,7 +22232,10 @@ ${effectiveInstructions}`;
|
|
|
22089
22232
|
if (resourceId && threadFromArgs && !this.hasOwnMemory()) {
|
|
22090
22233
|
this.logger.warn("No memory is configured but resourceId and threadId were passed in args", { agent: this.name });
|
|
22091
22234
|
}
|
|
22092
|
-
const llm = await this.getLLM({
|
|
22235
|
+
const llm = await this.getLLM({
|
|
22236
|
+
requestContext,
|
|
22237
|
+
model: options.model
|
|
22238
|
+
});
|
|
22093
22239
|
if ("structuredOutput" in options && options.structuredOutput?.schema && !options.structuredOutput?.model) {
|
|
22094
22240
|
const structuredOutputModel = llm.getModel();
|
|
22095
22241
|
const targetProvider = structuredOutputModel.provider;
|
|
@@ -22502,7 +22648,8 @@ ${effectiveInstructions}`;
|
|
|
22502
22648
|
options ?? {}
|
|
22503
22649
|
);
|
|
22504
22650
|
const llm = await this.getLLM({
|
|
22505
|
-
requestContext: mergedOptions.requestContext
|
|
22651
|
+
requestContext: mergedOptions.requestContext,
|
|
22652
|
+
model: mergedOptions.model
|
|
22506
22653
|
});
|
|
22507
22654
|
const modelInfo = llm.getModel();
|
|
22508
22655
|
if (!isSupportedLanguageModel(modelInfo)) {
|
|
@@ -22572,7 +22719,8 @@ ${effectiveInstructions}`;
|
|
|
22572
22719
|
streamOptions ?? {}
|
|
22573
22720
|
);
|
|
22574
22721
|
const llm = await this.getLLM({
|
|
22575
|
-
requestContext: mergedOptions.requestContext
|
|
22722
|
+
requestContext: mergedOptions.requestContext,
|
|
22723
|
+
model: mergedOptions.model
|
|
22576
22724
|
});
|
|
22577
22725
|
const modelInfo = llm.getModel();
|
|
22578
22726
|
if (!isSupportedLanguageModel(modelInfo)) {
|
|
@@ -22636,7 +22784,8 @@ ${effectiveInstructions}`;
|
|
|
22636
22784
|
streamOptions ?? {}
|
|
22637
22785
|
);
|
|
22638
22786
|
const llm = await this.getLLM({
|
|
22639
|
-
requestContext: mergedStreamOptions.requestContext
|
|
22787
|
+
requestContext: mergedStreamOptions.requestContext,
|
|
22788
|
+
model: mergedStreamOptions.model
|
|
22640
22789
|
});
|
|
22641
22790
|
if (!isSupportedLanguageModel(llm.getModel())) {
|
|
22642
22791
|
const modelInfo = llm.getModel();
|
|
@@ -22701,7 +22850,8 @@ ${effectiveInstructions}`;
|
|
|
22701
22850
|
options ?? {}
|
|
22702
22851
|
);
|
|
22703
22852
|
const llm = await this.getLLM({
|
|
22704
|
-
requestContext: mergedOptions.requestContext
|
|
22853
|
+
requestContext: mergedOptions.requestContext,
|
|
22854
|
+
model: mergedOptions.model
|
|
22705
22855
|
});
|
|
22706
22856
|
const modelInfo = llm.getModel();
|
|
22707
22857
|
if (!isSupportedLanguageModel(modelInfo)) {
|
|
@@ -27354,5 +27504,5 @@ var MockMemory = class extends MastraMemory {
|
|
|
27354
27504
|
};
|
|
27355
27505
|
|
|
27356
27506
|
export { Agent, AgentsMDInjector, BaseProcessor, BatchPartsProcessor, ChunkFrom, DefaultExecutionEngine, ExecutionEngine, FilePartSchema, ImagePartSchema, LanguageDetector, MastraAgentNetworkStream, MastraMemory, MastraModelOutput, MastraScorer, MemoryProcessor, MessageContentSchema, MessageHistory, MessagePartSchema, MockMemory, ModerationProcessor, PIIDetector, ProcessorInputPhaseSchema, ProcessorInputStepPhaseSchema, ProcessorMessageContentSchema, ProcessorMessageSchema, ProcessorOutputResultPhaseSchema, ProcessorOutputStepPhaseSchema, ProcessorOutputStreamPhaseSchema, ProcessorRunner, ProcessorState, ProcessorStepInputSchema, ProcessorStepOutputSchema, ProcessorStepSchema, PromptInjectionDetector, ReasoningPartSchema, Run, 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, formatCheckFeedback, formatCompletionFeedback, formatStreamCompletionFeedback, formatValidationFeedback, forwardAgentStreamChunk, generateFinalResult, generateStructuredFinalResult, getResumeLabelsByStepId, getStepIds, getStepResult, getThreadOMMetadata, globalEmbeddingCache, hydrateSerializedStepErrors, isObservationalMemoryEnabled, isProcessor, isProcessorWorkflow, isSupportedLanguageModel, loop, mapVariable, memoryDefaultOptions, parseMemoryRequestContext, removeWorkingMemoryTags, resolveThreadIdFromArgs, runChecks, runCompletionScorers, runCountDeprecationMessage, runDefaultCompletionCheck, runStreamCompletionScorers, runValidation, setThreadOMMetadata, supportedLanguageModelSpecifications, tryGenerateWithJsonFallback, tryStreamWithJsonFallback, validateStepInput, validateStepRequestContext, validateStepResumeData, validateStepStateData, validateStepSuspendData };
|
|
27357
|
-
//# sourceMappingURL=chunk-
|
|
27358
|
-
//# sourceMappingURL=chunk-
|
|
27507
|
+
//# sourceMappingURL=chunk-JIA3SJK6.js.map
|
|
27508
|
+
//# sourceMappingURL=chunk-JIA3SJK6.js.map
|