@mastra/core 0.2.0-alpha.108 → 0.2.0-alpha.110
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.d.ts +2 -3
- package/dist/agent/index.js +7 -7
- package/dist/{base-DAc1ytq3.d.ts → base-BbtPAA6f.d.ts} +5 -6
- package/dist/{base--m8Grk5r.d.ts → base-Bpb7Dmwe.d.ts} +11 -2
- package/dist/base.d.ts +1 -2
- package/dist/base.js +1 -1
- package/dist/bundler/index.d.ts +2 -2
- package/dist/bundler/index.js +2 -2
- package/dist/{chunk-VCVLH453.js → chunk-22LC46YN.js} +1 -1
- package/dist/{chunk-W5VWYN5Z.js → chunk-2KPUTKGW.js} +1 -1
- package/dist/{chunk-264HTEWA.js → chunk-65VPTVVP.js} +13 -4
- package/dist/{chunk-D6RHRYQ7.js → chunk-AWEACB2T.js} +2 -2
- package/dist/{chunk-N7KCML45.js → chunk-FGZVE4CM.js} +22 -73
- package/dist/{chunk-JVJYHOKI.js → chunk-J3W3IHDO.js} +3 -3
- package/dist/{chunk-MPEWMN7X.js → chunk-K36NSQWH.js} +1 -1
- package/dist/{chunk-VHGB3TPS.js → chunk-NQSNACFJ.js} +70 -21
- package/dist/{chunk-WB5OEAWD.js → chunk-OJ26F3J4.js} +1 -1
- package/dist/{chunk-5WOXVYCZ.js → chunk-SB37QG7O.js} +103 -103
- package/dist/{chunk-ZL23TPCY.js → chunk-SDBM53G4.js} +2 -2
- package/dist/{chunk-MVMR4OSN.js → chunk-U6J2FOU4.js} +3 -3
- package/dist/{chunk-6MKKSWBC.js → chunk-ZJOXJFJI.js} +39 -3
- package/dist/deployer/index.d.ts +1 -2
- package/dist/deployer/index.js +3 -3
- package/dist/eval/index.d.ts +2 -3
- package/dist/index.d.ts +6 -7
- package/dist/index.js +16 -16
- package/dist/integration/index.d.ts +3 -4
- package/dist/integration/index.js +2 -2
- package/dist/llm/index.d.ts +2 -3
- package/dist/mastra/index.d.ts +3 -4
- package/dist/mastra/index.js +12 -12
- package/dist/memory/index.d.ts +2 -3
- package/dist/memory/index.js +5 -5
- package/dist/relevance/index.js +8 -8
- package/dist/storage/index.d.ts +3 -4
- package/dist/storage/index.js +4 -4
- package/dist/telemetry/index.d.ts +2 -3
- package/dist/telemetry/index.js +1 -1
- package/dist/telemetry/otel-vendor.d.ts +7 -0
- package/dist/telemetry/otel-vendor.js +8 -0
- package/dist/tools/index.d.ts +3 -4
- package/dist/tts/index.d.ts +1 -2
- package/dist/tts/index.js +3 -3
- package/dist/vector/index.d.ts +1 -2
- package/dist/vector/index.js +2 -2
- package/dist/vector/libsql/index.d.ts +1 -2
- package/dist/vector/libsql/index.js +3 -3
- package/dist/{workflow-C_6Wde8H.d.ts → workflow-Cy8UTGCt.d.ts} +3 -6
- package/dist/workflows/index.d.ts +4 -5
- package/dist/workflows/index.js +2 -2
- package/package.json +9 -3
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import 'ai';
|
|
2
2
|
import 'json-schema';
|
|
3
3
|
import 'zod';
|
|
4
|
-
export { A as Agent } from '../base
|
|
5
|
-
import '../base-
|
|
4
|
+
export { A as Agent } from '../base-Bpb7Dmwe.js';
|
|
5
|
+
import '../base-BbtPAA6f.js';
|
|
6
6
|
import '../types-m9RryK9a.js';
|
|
7
7
|
import 'sift';
|
|
8
8
|
import '../vector/index.js';
|
|
@@ -10,6 +10,5 @@ import '@opentelemetry/api';
|
|
|
10
10
|
import '../index-B2JCcAQt.js';
|
|
11
11
|
import 'pino';
|
|
12
12
|
import 'stream';
|
|
13
|
-
import '@opentelemetry/sdk-node';
|
|
14
13
|
import '@opentelemetry/sdk-trace-base';
|
|
15
14
|
import '../tts/index.js';
|
package/dist/agent/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export { Agent } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { Agent } from '../chunk-NQSNACFJ.js';
|
|
2
|
+
import '../chunk-FGZVE4CM.js';
|
|
3
3
|
import '../chunk-2SAHBQEF.js';
|
|
4
|
-
import '../chunk-
|
|
5
|
-
import '../chunk-
|
|
4
|
+
import '../chunk-65VPTVVP.js';
|
|
5
|
+
import '../chunk-U6J2FOU4.js';
|
|
6
6
|
import '../chunk-RG66XEJT.js';
|
|
7
|
-
import '../chunk-
|
|
8
|
-
import '../chunk-
|
|
7
|
+
import '../chunk-OJ26F3J4.js';
|
|
8
|
+
import '../chunk-ZJOXJFJI.js';
|
|
9
9
|
import '../chunk-55GTEVHJ.js';
|
|
10
10
|
import '../chunk-VB7CO5ND.js';
|
|
11
11
|
import '../chunk-MLWGYRJR.js';
|
|
12
|
-
import '../chunk-
|
|
12
|
+
import '../chunk-AWEACB2T.js';
|
|
13
13
|
import '../chunk-O2VP5JBC.js';
|
|
14
14
|
import '../chunk-SIFBBGY6.js';
|
|
15
15
|
import '../chunk-C6A6W6XS.js';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as _opentelemetry_api from '@opentelemetry/api';
|
|
2
|
-
import { Tracer } from '@opentelemetry/api';
|
|
2
|
+
import { Tracer, Span } from '@opentelemetry/api';
|
|
3
3
|
import { R as RegisteredLogger, L as Logger, a as LogLevel } from './index-B2JCcAQt.js';
|
|
4
|
-
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
5
4
|
import { SpanExporter } from '@opentelemetry/sdk-trace-base';
|
|
6
5
|
|
|
7
6
|
/** Sampling strategy configuration for OpenTelemetry */
|
|
@@ -54,16 +53,15 @@ type OtelConfig = {
|
|
|
54
53
|
};
|
|
55
54
|
|
|
56
55
|
declare global {
|
|
57
|
-
var __OTEL_SDK__: NodeSDK | undefined;
|
|
58
56
|
var __TELEMETRY__: Telemetry | undefined;
|
|
59
57
|
}
|
|
60
58
|
declare class Telemetry {
|
|
61
|
-
private sdk;
|
|
62
59
|
tracer: Tracer;
|
|
63
60
|
name: string;
|
|
64
|
-
private static isInitialized;
|
|
65
|
-
private getSampler;
|
|
66
61
|
private constructor();
|
|
62
|
+
/**
|
|
63
|
+
* @deprecated This method does not do anything
|
|
64
|
+
*/
|
|
67
65
|
shutdown(): Promise<void>;
|
|
68
66
|
/**
|
|
69
67
|
* Initialize telemetry with the given configuration
|
|
@@ -103,6 +101,7 @@ declare class Telemetry {
|
|
|
103
101
|
spanName: string;
|
|
104
102
|
attributes?: Record<string, string>;
|
|
105
103
|
skipIfNoTelemetry?: boolean;
|
|
104
|
+
parentSpan?: Span;
|
|
106
105
|
}): TMethod;
|
|
107
106
|
getBaggageTracer(): Tracer;
|
|
108
107
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import * as ai from 'ai';
|
|
1
2
|
import { EmbeddingModel, CoreMessage as CoreMessage$1, Message, UserContent, AssistantContent, LanguageModelV1, CoreSystemMessage as CoreSystemMessage$1, CoreAssistantMessage as CoreAssistantMessage$1, CoreUserMessage as CoreUserMessage$1, CoreToolMessage as CoreToolMessage$1, EmbedResult as EmbedResult$1, EmbedManyResult as EmbedManyResult$1, GenerateTextResult, GenerateObjectResult, StreamTextResult, StreamObjectResult, LanguageModel as LanguageModel$1, DeepPartial, ToolContent } from 'ai';
|
|
2
|
-
import { M as MastraBase, T as Telemetry } from './base-
|
|
3
|
+
import { M as MastraBase, T as Telemetry } from './base-BbtPAA6f.js';
|
|
3
4
|
import { a as Metric, M as MetricResult, T as TestInfo } from './types-m9RryK9a.js';
|
|
4
5
|
import { Query } from 'sift';
|
|
5
6
|
import { z, ZodSchema } from 'zod';
|
|
@@ -21,6 +22,9 @@ declare abstract class MastraMemory extends MastraBase {
|
|
|
21
22
|
constructor(config: {
|
|
22
23
|
name: string;
|
|
23
24
|
} & SharedMemoryConfig);
|
|
25
|
+
setStorage(storage: MastraStorage): void;
|
|
26
|
+
setVector(vector: MastraVector): void;
|
|
27
|
+
setEmbedder(embedder: EmbeddingModel<string>): void;
|
|
24
28
|
/**
|
|
25
29
|
* Get a system message to inject into the conversation.
|
|
26
30
|
* This will be called before each conversation turn.
|
|
@@ -452,7 +456,9 @@ interface AgentConfig<TTools extends Record<string, ToolAction<any, any, any, an
|
|
|
452
456
|
model: LanguageModelV1;
|
|
453
457
|
tools?: TTools;
|
|
454
458
|
mastra?: MastraPrimitives;
|
|
459
|
+
/** @deprecated This property is deprecated. Use evals instead to add evaluation metrics. */
|
|
455
460
|
metrics?: TMetrics;
|
|
461
|
+
evals?: TMetrics;
|
|
456
462
|
memory?: MastraMemory;
|
|
457
463
|
}
|
|
458
464
|
interface AgentGenerateOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> {
|
|
@@ -557,6 +563,7 @@ declare class MastraLLMBase extends MastraBase {
|
|
|
557
563
|
});
|
|
558
564
|
getProvider(): string;
|
|
559
565
|
getModelId(): string;
|
|
566
|
+
getModel(): ai.LanguageModelV1;
|
|
560
567
|
convertToMessages(messages: string | string[] | CoreMessage$1[]): CoreMessage$1[];
|
|
561
568
|
__registerPrimitives(p: MastraPrimitives): void;
|
|
562
569
|
__text(input: LLMTextOptions): Promise<GenerateTextResult<any, any>>;
|
|
@@ -574,7 +581,9 @@ declare class Agent<TTools extends Record<string, ToolAction<any, any, any, any>
|
|
|
574
581
|
instructions: string;
|
|
575
582
|
readonly model?: LanguageModelV1;
|
|
576
583
|
tools: TTools;
|
|
584
|
+
/** @deprecated This property is deprecated. Use evals instead. */
|
|
577
585
|
metrics: TMetrics;
|
|
586
|
+
evals: TMetrics;
|
|
578
587
|
constructor(config: AgentConfig<TTools, TMetrics>);
|
|
579
588
|
hasOwnMemory(): boolean;
|
|
580
589
|
getMemory(): MastraMemory | undefined;
|
|
@@ -609,7 +618,7 @@ declare class Agent<TTools extends Record<string, ToolAction<any, any, any, any>
|
|
|
609
618
|
threadId: string;
|
|
610
619
|
memoryConfig: MemoryConfig | undefined;
|
|
611
620
|
}): Promise<void>;
|
|
612
|
-
sanitizeResponseMessages(messages: Array<
|
|
621
|
+
sanitizeResponseMessages(messages: Array<CoreMessage$1>): Array<CoreMessage$1>;
|
|
613
622
|
convertTools({ toolsets, runId, }: {
|
|
614
623
|
toolsets?: ToolsetsInput;
|
|
615
624
|
threadId?: string;
|
package/dist/base.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import '@opentelemetry/api';
|
|
2
2
|
import './index-B2JCcAQt.js';
|
|
3
|
-
export { M as MastraBase } from './base-
|
|
3
|
+
export { M as MastraBase } from './base-BbtPAA6f.js';
|
|
4
4
|
import 'pino';
|
|
5
5
|
import 'stream';
|
|
6
|
-
import '@opentelemetry/sdk-node';
|
|
7
6
|
import '@opentelemetry/sdk-trace-base';
|
package/dist/base.js
CHANGED
package/dist/bundler/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { M as MastraBase } from '../base-
|
|
1
|
+
import { M as MastraBase } from '../base-BbtPAA6f.js';
|
|
2
2
|
import '@opentelemetry/api';
|
|
3
3
|
import '../index-B2JCcAQt.js';
|
|
4
4
|
import 'pino';
|
|
5
5
|
import 'stream';
|
|
6
|
-
import '@opentelemetry/sdk-node';
|
|
7
6
|
import '@opentelemetry/sdk-trace-base';
|
|
8
7
|
|
|
9
8
|
interface IBundler {
|
|
@@ -21,6 +20,7 @@ declare abstract class MastraBundler extends MastraBase implements IBundler {
|
|
|
21
20
|
loadEnvVars(): Promise<Map<string, string>>;
|
|
22
21
|
abstract prepare(outputDirectory: string): Promise<void>;
|
|
23
22
|
abstract writePackageJson(outputDirectory: string, dependencies: Map<string, string>): Promise<void>;
|
|
23
|
+
abstract writeInstrumentationFile(outputDirectory: string): Promise<void>;
|
|
24
24
|
abstract getEnvFiles(): Promise<string[]>;
|
|
25
25
|
abstract bundle(entryFile: string, outputDirectory: string): Promise<void>;
|
|
26
26
|
}
|
package/dist/bundler/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DefaultStorage } from './chunk-
|
|
2
|
-
import { DefaultVectorDB } from './chunk-
|
|
3
|
-
import { defaultEmbedder } from './chunk-
|
|
1
|
+
import { DefaultStorage } from './chunk-U6J2FOU4.js';
|
|
2
|
+
import { DefaultVectorDB } from './chunk-OJ26F3J4.js';
|
|
3
|
+
import { defaultEmbedder } from './chunk-ZJOXJFJI.js';
|
|
4
4
|
import { deepMerge } from './chunk-55GTEVHJ.js';
|
|
5
|
-
import { MastraBase } from './chunk-
|
|
5
|
+
import { MastraBase } from './chunk-AWEACB2T.js';
|
|
6
6
|
|
|
7
7
|
// src/memory/memory.ts
|
|
8
8
|
var MastraMemory = class extends MastraBase {
|
|
@@ -38,6 +38,15 @@ var MastraMemory = class extends MastraBase {
|
|
|
38
38
|
this.threadConfig = this.getMergedThreadConfig(config.options);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
+
setStorage(storage) {
|
|
42
|
+
this.storage = storage;
|
|
43
|
+
}
|
|
44
|
+
setVector(vector) {
|
|
45
|
+
this.vector = vector;
|
|
46
|
+
}
|
|
47
|
+
setEmbedder(embedder) {
|
|
48
|
+
this.embedder = embedder;
|
|
49
|
+
}
|
|
41
50
|
/**
|
|
42
51
|
* Get a system message to inject into the conversation.
|
|
43
52
|
* This will be called before each conversation turn.
|
|
@@ -17,7 +17,7 @@ var MastraBase = class {
|
|
|
17
17
|
*/
|
|
18
18
|
__setLogger(logger) {
|
|
19
19
|
this.logger = logger;
|
|
20
|
-
this.logger.debug(`Logger updated
|
|
20
|
+
this.logger.debug(`Logger updated [component=${this.component}] [name=${this.name}]`);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* Internal logging helper that formats and sends logs to the configured logger
|
|
@@ -42,7 +42,7 @@ var MastraBase = class {
|
|
|
42
42
|
*/
|
|
43
43
|
__setTelemetry(telemetry) {
|
|
44
44
|
this.telemetry = telemetry;
|
|
45
|
-
this.logger.debug(`Telemetry updated
|
|
45
|
+
this.logger.debug(`Telemetry updated [component=${this.component}] [tracer=${this.telemetry.tracer}]`);
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Get the telemetry on the vector
|
|
@@ -2,12 +2,7 @@ import { TABLE_TRACES } from './chunk-RG66XEJT.js';
|
|
|
2
2
|
import { trace, context, propagation, SpanStatusCode, SpanKind } from '@opentelemetry/api';
|
|
3
3
|
import { ExportResultCode } from '@opentelemetry/core';
|
|
4
4
|
import { JsonTraceSerializer } from '@opentelemetry/otlp-transformer';
|
|
5
|
-
import
|
|
6
|
-
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
7
|
-
import { OTLPTraceExporter as OTLPTraceExporter$1 } from '@opentelemetry/exporter-trace-otlp-http';
|
|
8
|
-
import { Resource } from '@opentelemetry/resources';
|
|
9
|
-
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
10
|
-
import { ATTR_SERVICE_NAME } from '@opentelemetry/semantic-conventions';
|
|
5
|
+
import '@opentelemetry/sdk-trace-base';
|
|
11
6
|
|
|
12
7
|
function hasActiveTelemetry(tracerName = "default-tracer") {
|
|
13
8
|
try {
|
|
@@ -50,9 +45,11 @@ function withSpan(options) {
|
|
|
50
45
|
const currentBaggage = propagation.getBaggage(ctx);
|
|
51
46
|
if (currentBaggage?.componentName) {
|
|
52
47
|
span.setAttribute("componentName", currentBaggage?.componentName);
|
|
48
|
+
span.setAttribute("runId", currentBaggage?.runId);
|
|
53
49
|
} else if (this && this.name) {
|
|
54
50
|
span.setAttribute("componentName", this.name);
|
|
55
|
-
|
|
51
|
+
span.setAttribute("runId", this.runId);
|
|
52
|
+
ctx = propagation.setBaggage(ctx, { componentName: this.name, runId: this.runId });
|
|
56
53
|
}
|
|
57
54
|
let result;
|
|
58
55
|
try {
|
|
@@ -129,7 +126,7 @@ var OTLPTraceExporter = class {
|
|
|
129
126
|
const serializedRequest = this.serializer.serializeRequest(internalRepresentation);
|
|
130
127
|
const payload = JSON.parse(Buffer.from(serializedRequest.buffer, "utf8"));
|
|
131
128
|
const items = payload?.resourceSpans?.[0]?.scopeSpans;
|
|
132
|
-
this.logger.debug(
|
|
129
|
+
this.logger.debug(`Exporting telemetry: ${items.length} scope spans to be processed [trace batch]`);
|
|
133
130
|
this.queue.push({ data: items, resultCallback });
|
|
134
131
|
if (!this.activeFlush) {
|
|
135
132
|
this.activeFlush = this.flush();
|
|
@@ -218,75 +215,17 @@ var OTLPTraceExporter = class {
|
|
|
218
215
|
this.logger = logger;
|
|
219
216
|
}
|
|
220
217
|
};
|
|
221
|
-
var sdkInstance = null;
|
|
222
218
|
var Telemetry = class _Telemetry {
|
|
223
|
-
sdk = null;
|
|
224
219
|
tracer = trace.getTracer("default");
|
|
225
220
|
name = "default-service";
|
|
226
|
-
static isInitialized = false;
|
|
227
|
-
getSampler(config) {
|
|
228
|
-
if (!config.sampling) {
|
|
229
|
-
return new AlwaysOnSampler();
|
|
230
|
-
}
|
|
231
|
-
if (!config.enabled) {
|
|
232
|
-
return new AlwaysOffSampler();
|
|
233
|
-
}
|
|
234
|
-
switch (config.sampling.type) {
|
|
235
|
-
case "ratio":
|
|
236
|
-
return new TraceIdRatioBasedSampler(config.sampling.probability);
|
|
237
|
-
case "always_on":
|
|
238
|
-
return new AlwaysOnSampler();
|
|
239
|
-
case "always_off":
|
|
240
|
-
return new AlwaysOffSampler();
|
|
241
|
-
case "parent_based":
|
|
242
|
-
const rootSampler = new TraceIdRatioBasedSampler(config.sampling.root?.probability || 1);
|
|
243
|
-
return new ParentBasedSampler({ root: rootSampler });
|
|
244
|
-
default:
|
|
245
|
-
return new AlwaysOnSampler();
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
221
|
constructor(config) {
|
|
249
222
|
this.name = config.serviceName ?? "default-service";
|
|
250
|
-
if (typeof window === "undefined") {
|
|
251
|
-
if (process.env.NODE_ENV === "development" || !sdkInstance) {
|
|
252
|
-
if (sdkInstance) {
|
|
253
|
-
this.shutdown();
|
|
254
|
-
}
|
|
255
|
-
const exporter = config.export?.type === "otlp" ? new OTLPTraceExporter$1({
|
|
256
|
-
url: config.export.endpoint,
|
|
257
|
-
headers: config.export.headers
|
|
258
|
-
}) : config.export?.type === "custom" ? config.export.exporter : new ConsoleSpanExporter();
|
|
259
|
-
const sampler = this.getSampler(config);
|
|
260
|
-
sdkInstance = new NodeSDK({
|
|
261
|
-
resource: new Resource({
|
|
262
|
-
[ATTR_SERVICE_NAME]: this.name
|
|
263
|
-
}),
|
|
264
|
-
traceExporter: exporter,
|
|
265
|
-
sampler,
|
|
266
|
-
instrumentations: [getNodeAutoInstrumentations()]
|
|
267
|
-
});
|
|
268
|
-
try {
|
|
269
|
-
sdkInstance.start();
|
|
270
|
-
this.sdk = sdkInstance;
|
|
271
|
-
_Telemetry.isInitialized = true;
|
|
272
|
-
} catch (error) {
|
|
273
|
-
console.warn("Failed to initialize OpenTelemetry:", error);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
223
|
this.tracer = trace.getTracer(this.name);
|
|
278
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* @deprecated This method does not do anything
|
|
227
|
+
*/
|
|
279
228
|
async shutdown() {
|
|
280
|
-
if (this.sdk && _Telemetry.isInitialized) {
|
|
281
|
-
try {
|
|
282
|
-
await this.sdk.shutdown();
|
|
283
|
-
_Telemetry.isInitialized = false;
|
|
284
|
-
global.__OTEL_SDK__ = void 0;
|
|
285
|
-
global.__TELEMETRY__ = void 0;
|
|
286
|
-
} catch (error) {
|
|
287
|
-
console.warn("Error shutting down OpenTelemetry:", error);
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
229
|
}
|
|
291
230
|
/**
|
|
292
231
|
* Initialize telemetry with the given configuration
|
|
@@ -351,6 +290,7 @@ var Telemetry = class _Telemetry {
|
|
|
351
290
|
* @returns Wrapped method with tracing
|
|
352
291
|
*/
|
|
353
292
|
traceMethod(method, context3) {
|
|
293
|
+
let ctx = context.active();
|
|
354
294
|
const { skipIfNoTelemetry = true } = context3;
|
|
355
295
|
if (skipIfNoTelemetry && !hasActiveTelemetry()) {
|
|
356
296
|
return method;
|
|
@@ -380,16 +320,21 @@ var Telemetry = class _Telemetry {
|
|
|
380
320
|
if (context3.attributes) {
|
|
381
321
|
span.setAttributes(context3.attributes);
|
|
382
322
|
}
|
|
383
|
-
let ctx = context.active();
|
|
384
323
|
if (context3.attributes?.componentName) {
|
|
385
|
-
ctx = propagation.setBaggage(ctx, {
|
|
324
|
+
ctx = propagation.setBaggage(ctx, {
|
|
325
|
+
// @ts-ignore
|
|
326
|
+
componentName: context3.attributes.componentName,
|
|
327
|
+
runId: context3.attributes.runId
|
|
328
|
+
});
|
|
386
329
|
} else {
|
|
387
330
|
const currentBaggage = propagation.getBaggage(ctx);
|
|
388
331
|
if (currentBaggage?.componentName) {
|
|
389
332
|
span.setAttribute("componentName", currentBaggage?.componentName);
|
|
333
|
+
span.setAttribute("runId", currentBaggage?.runId);
|
|
390
334
|
} else if (this && this.name) {
|
|
391
335
|
span.setAttribute("componentName", this.name);
|
|
392
|
-
|
|
336
|
+
span.setAttribute("runId", this.runId);
|
|
337
|
+
ctx = propagation.setBaggage(ctx, { componentName: this.name, runId: this.runId });
|
|
393
338
|
}
|
|
394
339
|
}
|
|
395
340
|
args.forEach((arg, index) => {
|
|
@@ -399,7 +344,10 @@ var Telemetry = class _Telemetry {
|
|
|
399
344
|
span.setAttribute(`${context3.spanName}.argument.${index}`, "[Not Serializable]");
|
|
400
345
|
}
|
|
401
346
|
});
|
|
402
|
-
|
|
347
|
+
let result;
|
|
348
|
+
context.with(trace.setSpan(ctx, span), () => {
|
|
349
|
+
result = method(...args);
|
|
350
|
+
});
|
|
403
351
|
if (result instanceof Promise) {
|
|
404
352
|
return result.then(recordResult2).catch(handleError);
|
|
405
353
|
} else {
|
|
@@ -424,6 +372,7 @@ var BaggageTracer = class {
|
|
|
424
372
|
const span = this._tracer.startSpan(name, options, ctx);
|
|
425
373
|
const currentBaggage = propagation.getBaggage(ctx);
|
|
426
374
|
span.setAttribute("componentName", currentBaggage?.componentName);
|
|
375
|
+
span.setAttribute("runId", currentBaggage?.runId);
|
|
427
376
|
return span;
|
|
428
377
|
}
|
|
429
378
|
startActiveSpan(name, optionsOrFn, ctxOrFn, fn) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InstrumentClass, OTLPTraceExporter, Telemetry } from './chunk-
|
|
2
|
-
import { DefaultStorage } from './chunk-
|
|
1
|
+
import { InstrumentClass, OTLPTraceExporter, Telemetry } from './chunk-FGZVE4CM.js';
|
|
2
|
+
import { DefaultStorage } from './chunk-U6J2FOU4.js';
|
|
3
3
|
import { LogLevel, createLogger, noopLogger } from './chunk-O2VP5JBC.js';
|
|
4
4
|
import { __decoratorStart, __decorateElement, __runInitializers } from './chunk-C6A6W6XS.js';
|
|
5
5
|
|
|
@@ -36,7 +36,7 @@ var Mastra = class {
|
|
|
36
36
|
if (!storage) {
|
|
37
37
|
storage = new DefaultStorage({
|
|
38
38
|
config: {
|
|
39
|
-
url:
|
|
39
|
+
url: process.env.MASTRA_DEFAULT_STORAGE_URL || `:memory:`
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { InstrumentClass } from './chunk-
|
|
1
|
+
import { InstrumentClass } from './chunk-FGZVE4CM.js';
|
|
2
2
|
import { delay } from './chunk-55GTEVHJ.js';
|
|
3
3
|
import { executeHook } from './chunk-MLWGYRJR.js';
|
|
4
|
-
import { MastraBase } from './chunk-
|
|
4
|
+
import { MastraBase } from './chunk-AWEACB2T.js';
|
|
5
5
|
import { RegisteredLogger, LogLevel } from './chunk-O2VP5JBC.js';
|
|
6
6
|
import { __decoratorStart, __decorateElement, __runInitializers } from './chunk-C6A6W6XS.js';
|
|
7
7
|
import { generateText, jsonSchema, generateObject, streamText, streamObject } from 'ai';
|
|
@@ -26,6 +26,9 @@ var MastraLLMBase = class extends MastraBase {
|
|
|
26
26
|
getModelId() {
|
|
27
27
|
return this.#model.modelId;
|
|
28
28
|
}
|
|
29
|
+
getModel() {
|
|
30
|
+
return this.#model;
|
|
31
|
+
}
|
|
29
32
|
convertToMessages(messages) {
|
|
30
33
|
if (Array.isArray(messages)) {
|
|
31
34
|
return messages.map((m) => {
|
|
@@ -107,7 +110,10 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
107
110
|
getModelId() {
|
|
108
111
|
return this.#model.modelId;
|
|
109
112
|
}
|
|
110
|
-
|
|
113
|
+
getModel() {
|
|
114
|
+
return this.#model;
|
|
115
|
+
}
|
|
116
|
+
convertTools({ tools, runId } = {}) {
|
|
111
117
|
this.logger.debug("Starting tool conversion for LLM");
|
|
112
118
|
const converted = Object.entries(tools || {}).reduce(
|
|
113
119
|
(memo, value) => {
|
|
@@ -125,7 +131,8 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
125
131
|
});
|
|
126
132
|
return tool.execute({
|
|
127
133
|
context: props,
|
|
128
|
-
mastra: this.#mastra
|
|
134
|
+
mastra: this.#mastra,
|
|
135
|
+
runId
|
|
129
136
|
});
|
|
130
137
|
} catch (error) {
|
|
131
138
|
this.logger.error("Error executing tool", {
|
|
@@ -162,7 +169,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
162
169
|
maxSteps,
|
|
163
170
|
tools: Object.keys(tools || convertedTools || {})
|
|
164
171
|
});
|
|
165
|
-
const finalTools = convertedTools || this.convertTools(tools);
|
|
172
|
+
const finalTools = convertedTools || this.convertTools({ tools, runId });
|
|
166
173
|
const argsForExecute = {
|
|
167
174
|
model,
|
|
168
175
|
temperature,
|
|
@@ -206,7 +213,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
206
213
|
}) {
|
|
207
214
|
const model = this.#model;
|
|
208
215
|
this.logger.debug(`[LLM] - Generating a text object`, { runId });
|
|
209
|
-
const finalTools = convertedTools || this.convertTools(tools);
|
|
216
|
+
const finalTools = convertedTools || this.convertTools({ tools, runId });
|
|
210
217
|
const argsForExecute = {
|
|
211
218
|
model,
|
|
212
219
|
temperature,
|
|
@@ -268,7 +275,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
268
275
|
maxSteps,
|
|
269
276
|
tools: Object.keys(tools || convertedTools || {})
|
|
270
277
|
});
|
|
271
|
-
const finalTools = convertedTools || this.convertTools(tools);
|
|
278
|
+
const finalTools = convertedTools || this.convertTools({ tools, runId });
|
|
272
279
|
const argsForExecute = {
|
|
273
280
|
model,
|
|
274
281
|
temperature,
|
|
@@ -329,7 +336,7 @@ var MastraLLM = class extends MastraLLMBase {
|
|
|
329
336
|
maxSteps,
|
|
330
337
|
tools: Object.keys(tools || convertedTools || {})
|
|
331
338
|
});
|
|
332
|
-
const finalTools = convertedTools || this.convertTools(tools);
|
|
339
|
+
const finalTools = convertedTools || this.convertTools({ tools, runId });
|
|
333
340
|
const argsForExecute = {
|
|
334
341
|
model,
|
|
335
342
|
temperature,
|
|
@@ -466,7 +473,9 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
466
473
|
#mastra;
|
|
467
474
|
#memory;
|
|
468
475
|
tools;
|
|
476
|
+
/** @deprecated This property is deprecated. Use evals instead. */
|
|
469
477
|
metrics;
|
|
478
|
+
evals;
|
|
470
479
|
constructor(config) {
|
|
471
480
|
super({ component: RegisteredLogger.AGENT });
|
|
472
481
|
this.name = config.name;
|
|
@@ -477,6 +486,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
477
486
|
this.llm = new MastraLLM({ model: config.model });
|
|
478
487
|
this.tools = {};
|
|
479
488
|
this.metrics = {};
|
|
489
|
+
this.evals = {};
|
|
480
490
|
if (config.tools) {
|
|
481
491
|
this.tools = config.tools;
|
|
482
492
|
}
|
|
@@ -484,7 +494,12 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
484
494
|
this.#mastra = config.mastra;
|
|
485
495
|
}
|
|
486
496
|
if (config.metrics) {
|
|
497
|
+
this.logger.warn("The metrics property is deprecated. Please use evals instead to add evaluation metrics.");
|
|
487
498
|
this.metrics = config.metrics;
|
|
499
|
+
this.evals = config.metrics;
|
|
500
|
+
}
|
|
501
|
+
if (config.evals) {
|
|
502
|
+
this.evals = config.evals;
|
|
488
503
|
}
|
|
489
504
|
if (config.memory) {
|
|
490
505
|
this.#memory = config.memory;
|
|
@@ -645,7 +660,7 @@ var Agent = class extends (_a = MastraBase) {
|
|
|
645
660
|
|
|
646
661
|
${memorySystemMessage}` : ""}`
|
|
647
662
|
},
|
|
648
|
-
...memoryMessages,
|
|
663
|
+
...this.sanitizeResponseMessages(memoryMessages),
|
|
649
664
|
...newMessages
|
|
650
665
|
]
|
|
651
666
|
};
|
|
@@ -733,6 +748,7 @@ ${memorySystemMessage}` : ""}`
|
|
|
733
748
|
}
|
|
734
749
|
sanitizeResponseMessages(messages) {
|
|
735
750
|
let toolResultIds = [];
|
|
751
|
+
let toolCallIds = [];
|
|
736
752
|
for (const message of messages) {
|
|
737
753
|
if (message.role === "tool") {
|
|
738
754
|
for (const content of message.content) {
|
|
@@ -741,19 +757,50 @@ ${memorySystemMessage}` : ""}`
|
|
|
741
757
|
}
|
|
742
758
|
}
|
|
743
759
|
}
|
|
760
|
+
if (message.role === "assistant" || message.role === "user") {
|
|
761
|
+
for (const content of message.content) {
|
|
762
|
+
if (typeof content !== `string`) {
|
|
763
|
+
if (content.type === `tool-call`) {
|
|
764
|
+
toolCallIds.push(content.toolCallId);
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
744
769
|
}
|
|
745
770
|
const messagesBySanitizedContent = messages.map((message) => {
|
|
746
|
-
if (message.role !== "assistant") return message;
|
|
771
|
+
if (message.role !== "assistant" && message.role !== `tool` && message.role !== `user`) return message;
|
|
747
772
|
if (typeof message.content === "string") return message;
|
|
748
|
-
const sanitizedContent = message.content.filter(
|
|
749
|
-
(content
|
|
750
|
-
|
|
773
|
+
const sanitizedContent = message.content.filter((content) => {
|
|
774
|
+
if (content.type === `tool-call`) {
|
|
775
|
+
return toolResultIds.includes(content.toolCallId);
|
|
776
|
+
}
|
|
777
|
+
if (content.type === `text`) {
|
|
778
|
+
return content.text.trim() !== ``;
|
|
779
|
+
}
|
|
780
|
+
if (content.type === `tool-result`) {
|
|
781
|
+
return toolCallIds.includes(content.toolCallId);
|
|
782
|
+
}
|
|
783
|
+
return true;
|
|
784
|
+
});
|
|
751
785
|
return {
|
|
752
786
|
...message,
|
|
753
787
|
content: sanitizedContent
|
|
754
788
|
};
|
|
755
789
|
});
|
|
756
|
-
return messagesBySanitizedContent.filter((message) =>
|
|
790
|
+
return messagesBySanitizedContent.filter((message) => {
|
|
791
|
+
if (typeof message.content === `string`) {
|
|
792
|
+
return message.content !== "";
|
|
793
|
+
}
|
|
794
|
+
if (Array.isArray(message.content)) {
|
|
795
|
+
return message.content.length && message.content.every((c) => {
|
|
796
|
+
if (c.type === `text`) {
|
|
797
|
+
return c.text && c.text !== "";
|
|
798
|
+
}
|
|
799
|
+
return true;
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
return true;
|
|
803
|
+
});
|
|
757
804
|
}
|
|
758
805
|
convertTools({
|
|
759
806
|
toolsets,
|
|
@@ -778,7 +825,8 @@ ${memorySystemMessage}` : ""}`
|
|
|
778
825
|
});
|
|
779
826
|
return tool.execute({
|
|
780
827
|
context: args,
|
|
781
|
-
mastra: this.#mastra
|
|
828
|
+
mastra: this.#mastra,
|
|
829
|
+
runId
|
|
782
830
|
});
|
|
783
831
|
} catch (err) {
|
|
784
832
|
this.logger.error(`[Agent:${this.name}] - Failed execution`, {
|
|
@@ -816,7 +864,8 @@ ${memorySystemMessage}` : ""}`
|
|
|
816
864
|
args
|
|
817
865
|
});
|
|
818
866
|
return toolObj.execute({
|
|
819
|
-
context: args
|
|
867
|
+
context: args,
|
|
868
|
+
runId
|
|
820
869
|
});
|
|
821
870
|
} catch (err) {
|
|
822
871
|
this.logger.error(`[Agent:${this.name}] - Failed toolset execution`, {
|
|
@@ -841,7 +890,7 @@ ${memorySystemMessage}` : ""}`
|
|
|
841
890
|
}) {
|
|
842
891
|
let coreMessages = [];
|
|
843
892
|
let threadIdToUse = threadId;
|
|
844
|
-
this.log(LogLevel.
|
|
893
|
+
this.log(LogLevel.DEBUG, `Saving user messages in memory for agent ${this.name}`, { runId });
|
|
845
894
|
const saveMessageResponse = await this.saveMemory({
|
|
846
895
|
threadId,
|
|
847
896
|
resourceId,
|
|
@@ -963,10 +1012,10 @@ ${memorySystemMessage}` : ""}`
|
|
|
963
1012
|
});
|
|
964
1013
|
}
|
|
965
1014
|
}
|
|
966
|
-
if (Object.keys(this.
|
|
1015
|
+
if (Object.keys(this.evals || {}).length > 0) {
|
|
967
1016
|
const input = messages.map((message) => message.content).join("\n");
|
|
968
1017
|
const runIdToUse = runId2 || crypto.randomUUID();
|
|
969
|
-
for (const metric of Object.values(this.
|
|
1018
|
+
for (const metric of Object.values(this.evals || {})) {
|
|
970
1019
|
executeHook("onGeneration" /* ON_GENERATION */, {
|
|
971
1020
|
input,
|
|
972
1021
|
output: outputText,
|
|
@@ -1121,7 +1170,7 @@ ${memorySystemMessage}` : ""}`
|
|
|
1121
1170
|
onFinish?.(result);
|
|
1122
1171
|
},
|
|
1123
1172
|
maxSteps,
|
|
1124
|
-
runId,
|
|
1173
|
+
runId: runIdToUse,
|
|
1125
1174
|
toolChoice
|
|
1126
1175
|
});
|
|
1127
1176
|
}
|
|
@@ -1149,7 +1198,7 @@ ${memorySystemMessage}` : ""}`
|
|
|
1149
1198
|
onFinish?.(result);
|
|
1150
1199
|
},
|
|
1151
1200
|
maxSteps,
|
|
1152
|
-
runId,
|
|
1201
|
+
runId: runIdToUse,
|
|
1153
1202
|
toolChoice
|
|
1154
1203
|
});
|
|
1155
1204
|
}
|