@mastra/core 0.1.27-alpha.32 → 0.1.27-alpha.35

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.
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod';
2
+ export interface IExecutionContext<TPayload, TContext> {
3
+ context: TPayload & {
4
+ machineContext?: TContext;
5
+ };
6
+ runId?: string;
7
+ }
8
+ export interface IAction<TId extends string, TSchemaIn extends z.ZodSchema, TSchemaOut extends z.ZodSchema, TContext extends IExecutionContext<z.infer<TSchemaIn>, any>> {
9
+ id: TId;
10
+ description?: string;
11
+ inputSchema?: TSchemaIn;
12
+ outputSchema?: TSchemaOut;
13
+ payload?: Partial<z.infer<TSchemaIn>>;
14
+ execute: (context: TContext) => Promise<z.infer<TSchemaOut>>;
15
+ [key: string]: any;
16
+ }
@@ -1,43 +1,31 @@
1
1
  import { CoreAssistantMessage, CoreMessage, CoreToolMessage, CoreUserMessage, UserContent } from 'ai';
2
2
  import { ZodSchema } from 'zod';
3
- import { Integration } from '../integration';
3
+ import { MastraBase } from '../base';
4
4
  import { LLM } from '../llm';
5
5
  import { GenerateReturn, ModelConfig, StructuredOutput } from '../llm/types';
6
- import { Logger } from '../logger';
7
6
  import { MastraMemory } from '../memory';
8
7
  import { Run } from '../run/types';
9
- import { Telemetry } from '../telemetry';
10
- import { AllTools, CoreTool, ToolApi } from '../tools/types';
11
- export declare class Agent<TTools, TIntegrations extends Integration[] | undefined = undefined, TKeys extends keyof AllTools<TTools, TIntegrations> = keyof AllTools<TTools, TIntegrations>> {
8
+ import { CoreTool, ToolAction } from '../tools/types';
9
+ import { ToolsetsInput } from './types';
10
+ export declare class Agent<TTools extends Record<string, ToolAction<any, any, any, any>> = Record<string, ToolAction<any, any, any, any>>> extends MastraBase {
12
11
  #private;
13
12
  name: string;
14
13
  private memory?;
15
- readonly llm: LLM<TTools, TIntegrations, TKeys>;
14
+ readonly llm: LLM;
16
15
  readonly instructions: string;
17
16
  readonly model: ModelConfig;
18
- readonly enabledTools: Partial<Record<TKeys, boolean>>;
19
17
  constructor(config: {
20
18
  name: string;
21
19
  instructions: string;
22
20
  model: ModelConfig;
23
- enabledTools?: Partial<Record<TKeys, boolean>>;
21
+ tools?: TTools;
24
22
  });
25
23
  /**
26
24
  * Set the concrete tools for the agent
27
25
  * @param tools
28
26
  */
29
- __setTools(tools: Record<TKeys, ToolApi>): void;
30
- /**
31
- * Set the logger for the agent
32
- * @param logger
33
- */
34
- __setLogger(logger: Logger): void;
27
+ __setTools(tools: TTools): void;
35
28
  __setMemory(memory: MastraMemory): void;
36
- /**
37
- * Set the telemetry for the agent
38
- * @param telemetry
39
- */
40
- __setTelemetry(telemetry: Telemetry): void;
41
29
  generateTitleFromUserMessage({ message }: {
42
30
  message: CoreUserMessage;
43
31
  }): Promise<any>;
@@ -58,12 +46,11 @@ export declare class Agent<TTools, TIntegrations extends Integration[] | undefin
58
46
  threadId: string;
59
47
  }): Promise<void>;
60
48
  sanitizeResponseMessages(messages: Array<CoreToolMessage | CoreAssistantMessage>): Array<CoreToolMessage | CoreAssistantMessage>;
61
- convertTools({ enabledTools, toolsets, threadId, runId, }: {
62
- toolsets?: Record<string, Record<TKeys, ToolApi>>;
63
- enabledTools?: Partial<Record<TKeys, boolean>>;
49
+ convertTools({ toolsets, threadId, runId, }: {
50
+ toolsets?: ToolsetsInput;
64
51
  threadId?: string;
65
52
  runId?: string;
66
- }): Record<TKeys, CoreTool>;
53
+ }): Record<string, CoreTool>;
67
54
  preExecute({ resourceid, runId, threadId, messages, }: {
68
55
  runId?: string;
69
56
  threadId?: string;
@@ -74,7 +61,7 @@ export declare class Agent<TTools, TIntegrations extends Integration[] | undefin
74
61
  threadIdToUse: string;
75
62
  }>;
76
63
  __primitive({ messages, context, threadId, resourceid, runId, toolsets, }: {
77
- toolsets?: Record<string, Record<TKeys, ToolApi>>;
64
+ toolsets?: ToolsetsInput;
78
65
  resourceid?: string;
79
66
  threadId?: string;
80
67
  context?: CoreMessage[];
@@ -83,7 +70,7 @@ export declare class Agent<TTools, TIntegrations extends Integration[] | undefin
83
70
  }): {
84
71
  before: () => Promise<{
85
72
  messageObjects: CoreMessage[];
86
- convertedTools: Record<TKeys, CoreTool> | undefined;
73
+ convertedTools: Record<string, CoreTool> | undefined;
87
74
  threadId: string;
88
75
  }>;
89
76
  after: ({ result, threadId }: {
@@ -92,7 +79,7 @@ export declare class Agent<TTools, TIntegrations extends Integration[] | undefin
92
79
  }) => Promise<void>;
93
80
  };
94
81
  generate<S extends boolean = false, Z extends ZodSchema | undefined = undefined>(messages: string | string[] | CoreMessage[], { schema, stream, context, threadId: threadIdInFn, resourceid, maxSteps, onFinish, onStepFinish, runId, toolsets, }?: {
95
- toolsets?: Record<string, Record<TKeys, ToolApi>>;
82
+ toolsets?: ToolsetsInput;
96
83
  resourceid?: string;
97
84
  context?: CoreMessage[];
98
85
  threadId?: string;
@@ -104,7 +91,7 @@ export declare class Agent<TTools, TIntegrations extends Integration[] | undefin
104
91
  maxSteps?: number;
105
92
  }): Promise<GenerateReturn<S, Z>>;
106
93
  text({ messages, context, onStepFinish, maxSteps, threadId: threadIdInFn, resourceid, runId, toolsets, }: {
107
- toolsets?: Record<string, Record<TKeys, ToolApi>>;
94
+ toolsets?: ToolsetsInput;
108
95
  resourceid?: string;
109
96
  threadId?: string;
110
97
  context?: CoreMessage[];
@@ -113,7 +100,7 @@ export declare class Agent<TTools, TIntegrations extends Integration[] | undefin
113
100
  maxSteps?: number;
114
101
  } & Run): Promise<import("ai").GenerateTextResult<{}, never>>;
115
102
  textObject({ messages, context, structuredOutput, onStepFinish, maxSteps, threadId: threadIdInFn, resourceid, runId, toolsets, }: {
116
- toolsets?: Record<string, Record<TKeys, ToolApi>>;
103
+ toolsets?: ToolsetsInput;
117
104
  context?: CoreMessage[];
118
105
  resourceid?: string;
119
106
  threadId?: string;
@@ -123,7 +110,7 @@ export declare class Agent<TTools, TIntegrations extends Integration[] | undefin
123
110
  maxSteps?: number;
124
111
  } & Run): Promise<import("ai").GenerateObjectResult<any>>;
125
112
  stream({ messages, context, onStepFinish, onFinish, maxSteps, threadId: threadIdInFn, resourceid, runId, toolsets, }: {
126
- toolsets?: Record<string, Record<TKeys, ToolApi>>;
113
+ toolsets?: ToolsetsInput;
127
114
  resourceid?: string;
128
115
  threadId?: string;
129
116
  messages: UserContent[];
@@ -133,7 +120,7 @@ export declare class Agent<TTools, TIntegrations extends Integration[] | undefin
133
120
  maxSteps?: number;
134
121
  } & Run): Promise<import("ai").StreamTextResult<{}>>;
135
122
  streamObject({ messages, context, structuredOutput, onStepFinish, onFinish, maxSteps, threadId: threadIdInFn, resourceid, runId, toolsets, }: {
136
- toolsets?: Record<string, Record<TKeys, ToolApi>>;
123
+ toolsets?: ToolsetsInput;
137
124
  resourceid?: string;
138
125
  threadId?: string;
139
126
  messages: UserContent[];
@@ -0,0 +1,3 @@
1
+ import { ToolAction } from '../tools';
2
+ export type ToolsetsInput = Record<string, Record<string, ToolAction<any, any, any, any>>>;
3
+ export type ToolsInput = Record<string, ToolAction<any, any, any, any>>;
package/dist/base.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { Logger, LogLevel, RegisteredLogger } from './logger';
2
+ import { Telemetry } from './telemetry';
3
+ export declare class MastraBase {
4
+ component: RegisteredLogger;
5
+ logger: Logger;
6
+ telemetry?: Telemetry;
7
+ constructor({ component }: {
8
+ component: RegisteredLogger;
9
+ });
10
+ /**
11
+ * Set the logger for the agent
12
+ * @param logger
13
+ */
14
+ __setLogger(logger: Logger): void;
15
+ /**
16
+ * Internal logging helper that formats and sends logs to the configured logger
17
+ * @param level - Severity level of the log
18
+ * @param message - Main log message
19
+ * @param runId - Optional runId for the log
20
+ */
21
+ log(level: LogLevel, message: string, runId?: string): void;
22
+ /**
23
+ * Set the telemetry for the agent
24
+ * @param telemetry
25
+ */
26
+ __setTelemetry(telemetry: Telemetry): void;
27
+ get experimental_telemetry(): {
28
+ tracer: import("@opentelemetry/api").Tracer;
29
+ isEnabled: boolean;
30
+ } | undefined;
31
+ }