@mastra/core 0.2.0-alpha.93 → 0.2.0-alpha.95

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.
Files changed (137) hide show
  1. package/README.md +11 -8
  2. package/dist/action/index.d.ts +1 -3
  3. package/dist/agent/index.d.ts +2 -4
  4. package/dist/agent/index.js +3 -5
  5. package/dist/{chunk-SDKEPBBH.js → chunk-4ZUSEHLH.js} +109 -12
  6. package/dist/{chunk-F7ILHRX5.js → chunk-5DZIXJRV.js} +1 -1
  7. package/dist/chunk-AE3H2QEY.js +1 -0
  8. package/dist/{chunk-IE37CBXB.js → chunk-G4LP2IJU.js} +1 -3
  9. package/dist/{chunk-JWVCENG2.js → chunk-JY322VLW.js} +445 -32
  10. package/dist/{chunk-ECUVL2G5.js → chunk-K3N7KJHH.js} +1 -1
  11. package/dist/chunk-MBOUQZQT.js +16 -0
  12. package/dist/{chunk-GGYXCZUW.js → chunk-N44BCOWP.js} +4 -12
  13. package/dist/{chunk-WBPDZBUT.js → chunk-TYIBRZOY.js} +2 -17
  14. package/dist/eval/index.d.ts +1 -3
  15. package/dist/index-CBxGSZZE.d.ts +808 -0
  16. package/dist/index.d.ts +6 -12
  17. package/dist/index.js +12 -26
  18. package/dist/integration/index.d.ts +5 -7
  19. package/dist/llm/index.d.ts +4 -6
  20. package/dist/llm/index.js +1 -6
  21. package/dist/mastra/index.d.ts +2 -5
  22. package/dist/mastra/index.js +2 -6
  23. package/dist/memory/index.d.ts +1 -3
  24. package/dist/memory/index.js +1 -1
  25. package/dist/relevance/index.d.ts +2 -19
  26. package/dist/relevance/index.js +4 -6
  27. package/dist/storage/index.d.ts +2 -4
  28. package/dist/storage/index.js +2 -3
  29. package/dist/telemetry/index.js +1 -2
  30. package/dist/tools/index.d.ts +2 -4
  31. package/dist/tts/index.js +2 -3
  32. package/dist/vector/index.d.ts +0 -7
  33. package/dist/vector/index.js +1 -2
  34. package/dist/vector/libsql/index.d.ts +0 -1
  35. package/dist/vector/libsql/index.js +2 -3
  36. package/dist/{workflow-CSwxE-4q.d.ts → workflow-BA2Pnq90.d.ts} +1 -1
  37. package/dist/workflows/index.d.ts +3 -5
  38. package/package.json +20 -56
  39. package/dist/chunk-5DYJZVB7.js +0 -66
  40. package/dist/chunk-6ZVFVYLE.js +0 -101
  41. package/dist/chunk-AD6IIOCI.js +0 -11
  42. package/dist/chunk-BOS3IA23.js +0 -76
  43. package/dist/chunk-CQU72KBX.js +0 -54
  44. package/dist/chunk-HH5JIATB.js +0 -36
  45. package/dist/chunk-IEFQZ3IL.js +0 -78
  46. package/dist/chunk-IJ55HGH4.js +0 -24
  47. package/dist/chunk-NNNAWW2H.js +0 -66
  48. package/dist/chunk-NYBGZL6Z.js +0 -30
  49. package/dist/chunk-QX2CHXA7.js +0 -408
  50. package/dist/chunk-RAR7V3E3.js +0 -66
  51. package/dist/chunk-RI3ECMVF.js +0 -636
  52. package/dist/chunk-VPSYTVWP.js +0 -66
  53. package/dist/chunk-ZA7MIXNW.js +0 -66
  54. package/dist/embeddings/index.d.ts +0 -8
  55. package/dist/embeddings/index.js +0 -2
  56. package/dist/embeddings/model/providers/bedrock.d.ts +0 -42
  57. package/dist/embeddings/model/providers/bedrock.js +0 -3
  58. package/dist/embeddings/model/providers/bedrock.test.d.ts +0 -2
  59. package/dist/embeddings/model/providers/bedrock.test.js +0 -37
  60. package/dist/embeddings/model/providers/cohere.d.ts +0 -34
  61. package/dist/embeddings/model/providers/cohere.js +0 -3
  62. package/dist/embeddings/model/providers/cohere.test.d.ts +0 -2
  63. package/dist/embeddings/model/providers/cohere.test.js +0 -37
  64. package/dist/embeddings/model/providers/embedder.d.ts +0 -28
  65. package/dist/embeddings/model/providers/embedder.js +0 -2
  66. package/dist/embeddings/model/providers/google.d.ts +0 -34
  67. package/dist/embeddings/model/providers/google.js +0 -3
  68. package/dist/embeddings/model/providers/google.test.d.ts +0 -2
  69. package/dist/embeddings/model/providers/google.test.js +0 -37
  70. package/dist/embeddings/model/providers/mistral.d.ts +0 -34
  71. package/dist/embeddings/model/providers/mistral.js +0 -3
  72. package/dist/embeddings/model/providers/mistral.test.d.ts +0 -2
  73. package/dist/embeddings/model/providers/mistral.test.js +0 -37
  74. package/dist/embeddings/model/providers/mock.d.ts +0 -20
  75. package/dist/embeddings/model/providers/mock.js +0 -3
  76. package/dist/embeddings/model/providers/mock.test.d.ts +0 -2
  77. package/dist/embeddings/model/providers/mock.test.js +0 -29
  78. package/dist/embeddings/model/providers/openai.d.ts +0 -34
  79. package/dist/embeddings/model/providers/openai.js +0 -3
  80. package/dist/embeddings/model/providers/openai.test.d.ts +0 -2
  81. package/dist/embeddings/model/providers/openai.test.js +0 -37
  82. package/dist/embeddings/model/providers/voyage.d.ts +0 -34
  83. package/dist/embeddings/model/providers/voyage.js +0 -3
  84. package/dist/embeddings/model/providers/voyage.test.d.ts +0 -2
  85. package/dist/embeddings/model/providers/voyage.test.js +0 -37
  86. package/dist/index-B48181D5.d.ts +0 -1070
  87. package/dist/llm/model/index.d.ts +0 -45
  88. package/dist/llm/model/index.js +0 -5
  89. package/dist/llm/model/providers/anthropic-vertex.d.ts +0 -31
  90. package/dist/llm/model/providers/anthropic-vertex.js +0 -23
  91. package/dist/llm/model/providers/anthropic.d.ts +0 -29
  92. package/dist/llm/model/providers/anthropic.js +0 -21
  93. package/dist/llm/model/providers/azure.d.ts +0 -48
  94. package/dist/llm/model/providers/azure.js +0 -50
  95. package/dist/llm/model/providers/baseten.d.ts +0 -33
  96. package/dist/llm/model/providers/baseten.js +0 -29
  97. package/dist/llm/model/providers/bedrock.d.ts +0 -32
  98. package/dist/llm/model/providers/bedrock.js +0 -24
  99. package/dist/llm/model/providers/cerebras.d.ts +0 -30
  100. package/dist/llm/model/providers/cerebras.js +0 -22
  101. package/dist/llm/model/providers/cohere.d.ts +0 -30
  102. package/dist/llm/model/providers/cohere.js +0 -22
  103. package/dist/llm/model/providers/deepinfra.d.ts +0 -30
  104. package/dist/llm/model/providers/deepinfra.js +0 -22
  105. package/dist/llm/model/providers/deepseek.d.ts +0 -30
  106. package/dist/llm/model/providers/deepseek.js +0 -22
  107. package/dist/llm/model/providers/fireworks.d.ts +0 -35
  108. package/dist/llm/model/providers/fireworks.js +0 -40
  109. package/dist/llm/model/providers/google-vertex.d.ts +0 -48
  110. package/dist/llm/model/providers/google-vertex.js +0 -22
  111. package/dist/llm/model/providers/google.d.ts +0 -54
  112. package/dist/llm/model/providers/google.js +0 -23
  113. package/dist/llm/model/providers/grok.d.ts +0 -32
  114. package/dist/llm/model/providers/grok.js +0 -22
  115. package/dist/llm/model/providers/groq.d.ts +0 -37
  116. package/dist/llm/model/providers/groq.js +0 -42
  117. package/dist/llm/model/providers/lmstudio.d.ts +0 -29
  118. package/dist/llm/model/providers/lmstudio.js +0 -22
  119. package/dist/llm/model/providers/mistral.d.ts +0 -30
  120. package/dist/llm/model/providers/mistral.js +0 -22
  121. package/dist/llm/model/providers/mock.d.ts +0 -30
  122. package/dist/llm/model/providers/mock.js +0 -83
  123. package/dist/llm/model/providers/ollama.d.ts +0 -31
  124. package/dist/llm/model/providers/ollama.js +0 -23
  125. package/dist/llm/model/providers/openai-compat.d.ts +0 -39
  126. package/dist/llm/model/providers/openai-compat.js +0 -6
  127. package/dist/llm/model/providers/openai.d.ts +0 -34
  128. package/dist/llm/model/providers/openai.js +0 -6
  129. package/dist/llm/model/providers/openai.test.d.ts +0 -2
  130. package/dist/llm/model/providers/openai.test.js +0 -220
  131. package/dist/llm/model/providers/perplexity.d.ts +0 -30
  132. package/dist/llm/model/providers/perplexity.js +0 -22
  133. package/dist/llm/model/providers/portkey.d.ts +0 -34
  134. package/dist/llm/model/providers/portkey.js +0 -22
  135. package/dist/llm/model/providers/togetherai.d.ts +0 -30
  136. package/dist/llm/model/providers/togetherai.js +0 -22
  137. package/dist/types-M16hSruO.d.ts +0 -40
@@ -0,0 +1,808 @@
1
+ import { Message, UserContent, AssistantContent, ToolContent, CoreMessage as CoreMessage$1, EmbeddingModel, 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 } from 'ai';
2
+ import { JSONSchema7 } from 'json-schema';
3
+ import { z, ZodSchema } from 'zod';
4
+ import { MastraBase } from './base.js';
5
+ import { M as Metric } from './metric-D2V4CR8D.js';
6
+ import { T as Telemetry } from './telemetry-oCUM52DG.js';
7
+ import { Query } from 'sift';
8
+ import { B as BaseLogMessage, R as RegisteredLogger, L as Logger, b as Run } from './index-CBZ2mk2H.js';
9
+ import { MastraVector } from './vector/index.js';
10
+ import { MastraTTS } from './tts/index.js';
11
+
12
+ interface WorkflowOptions<TTriggerSchema extends z.ZodType<any> = any> {
13
+ name: string;
14
+ triggerSchema?: TTriggerSchema;
15
+ retryConfig?: RetryConfig;
16
+ mastra?: MastraPrimitives;
17
+ }
18
+ interface StepExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn, TContext> {
19
+ runId: string;
20
+ }
21
+ interface StepAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends StepExecutionContext<TSchemaIn>> extends IAction<TId, TSchemaIn, TSchemaOut, TContext> {
22
+ retryConfig?: RetryConfig;
23
+ }
24
+ interface SimpleConditionalType {
25
+ [key: `${string}.${string}`]: string | Query<any>;
26
+ }
27
+ type StepVariableType<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends IExecutionContext<TSchemaIn>> = IAction<TId, TSchemaIn, TSchemaOut, TContext> | 'trigger' | {
28
+ id: string;
29
+ };
30
+ type StepNode = {
31
+ step: IAction<any, any, any, any>;
32
+ config: StepDef<any, any, any, any>[any];
33
+ };
34
+ type StepGraph = {
35
+ initial: StepNode[];
36
+ [key: string]: StepNode[];
37
+ };
38
+ type RetryConfig = {
39
+ attempts?: number;
40
+ delay?: number;
41
+ };
42
+ type VariableReference<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodType<any>> = TStep extends IAction<any, any, any, any> ? {
43
+ step: TStep;
44
+ path: PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TStep, 'outputSchema'>>> | '' | '.';
45
+ } : TStep extends 'trigger' ? {
46
+ step: 'trigger';
47
+ path: PathsToStringProps<ExtractSchemaType<TTriggerSchema>> | '.' | '';
48
+ } : {
49
+ step: {
50
+ id: string;
51
+ };
52
+ path: string;
53
+ };
54
+ interface BaseCondition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodType<any>> {
55
+ ref: TStep extends IAction<any, any, any, any> ? {
56
+ step: TStep;
57
+ path: PathsToStringProps<ExtractSchemaType<ExtractSchemaFromStep<TStep, 'outputSchema'>>> | '' | '.' | 'status';
58
+ } : TStep extends 'trigger' ? {
59
+ step: 'trigger';
60
+ path: PathsToStringProps<ExtractSchemaType<TTriggerSchema>> | '.' | '';
61
+ } : {
62
+ step: {
63
+ id: string;
64
+ };
65
+ path: string;
66
+ };
67
+ query: Query<any>;
68
+ }
69
+ type ActionContext<TSchemaIn extends z.ZodType<any>> = IExecutionContext<z.infer<TSchemaIn>, WorkflowContext>;
70
+ type StepDef<TStepId extends TSteps[number]['id'], TSteps extends IAction<any, any, any, any>[], TSchemaIn extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>> = Record<TStepId, {
71
+ snapshotOnTimeout?: boolean;
72
+ when?: Condition<any, any> | ((args: {
73
+ context: WorkflowContext;
74
+ }) => Promise<boolean>);
75
+ data: TSchemaIn;
76
+ handler: (args: ActionContext<TSchemaIn>) => Promise<z.infer<TSchemaOut>>;
77
+ }>;
78
+ type StepCondition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodType<any>> = BaseCondition<TStep, TTriggerSchema> | SimpleConditionalType | {
79
+ and: StepCondition<TStep, TTriggerSchema>[];
80
+ } | {
81
+ or: StepCondition<TStep, TTriggerSchema>[];
82
+ };
83
+ type Condition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodType<any>> = BaseCondition<TStep, TTriggerSchema> | SimpleConditionalType | {
84
+ and: Condition<TStep, TTriggerSchema>[];
85
+ } | {
86
+ or: Condition<TStep, TTriggerSchema>[];
87
+ };
88
+ interface StepConfig<TStep extends IAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodType<any>> {
89
+ snapshotOnTimeout?: boolean;
90
+ when?: Condition<CondStep, TTriggerSchema> | ((args: {
91
+ context: WorkflowContext<TTriggerSchema>;
92
+ }) => Promise<boolean>);
93
+ variables?: StepInputType<TStep, 'inputSchema'> extends never ? Record<string, VariableReference<VarStep, TTriggerSchema>> : {
94
+ [K in keyof StepInputType<TStep, 'inputSchema'>]?: VariableReference<VarStep, TTriggerSchema>;
95
+ };
96
+ }
97
+ type StepSuccess<T> = {
98
+ status: 'success';
99
+ payload: T;
100
+ };
101
+ type StepSuspended = {
102
+ status: 'suspended';
103
+ };
104
+ type StepWaiting = {
105
+ status: 'waiting';
106
+ };
107
+ type StepFailure = {
108
+ status: 'failed';
109
+ error: string;
110
+ };
111
+ type StepResult<T> = StepSuccess<T> | StepFailure | StepSuspended | StepWaiting;
112
+ interface WorkflowContext<TTrigger extends z.ZodType<any> = any> {
113
+ stepResults: Record<string, StepResult<any>>;
114
+ triggerData: z.infer<TTrigger>;
115
+ attempts: Record<string, number>;
116
+ getStepPayload: <T = unknown>(stepId: string) => T | undefined;
117
+ }
118
+ interface WorkflowLogMessage extends BaseLogMessage {
119
+ type: typeof RegisteredLogger.WORKFLOW;
120
+ workflowName: string;
121
+ stepId?: StepId;
122
+ data?: unknown;
123
+ runId?: string;
124
+ }
125
+ type WorkflowEvent = {
126
+ type: 'RESET_TO_PENDING';
127
+ stepId: string;
128
+ } | {
129
+ type: 'CONDITIONS_MET';
130
+ stepId: string;
131
+ } | {
132
+ type: 'CONDITION_FAILED';
133
+ stepId: string;
134
+ error: string;
135
+ } | {
136
+ type: 'SUSPENDED';
137
+ stepId: string;
138
+ } | {
139
+ type: 'WAITING';
140
+ stepId: string;
141
+ } | {
142
+ type: `xstate.error.actor.${string}`;
143
+ error: Error;
144
+ } | {
145
+ type: `xstate.done.actor.${string}`;
146
+ output: ResolverFunctionOutput;
147
+ };
148
+ type ResolverFunctionInput = {
149
+ stepNode: StepNode;
150
+ context: WorkflowContext;
151
+ };
152
+ type ResolverFunctionOutput = {
153
+ stepId: StepId;
154
+ result: unknown;
155
+ };
156
+ type SubscriberFunctionOutput = {
157
+ stepId: StepId;
158
+ result: unknown;
159
+ };
160
+ type DependencyCheckOutput = {
161
+ type: 'CONDITIONS_MET';
162
+ } | {
163
+ type: 'CONDITION_FAILED';
164
+ error: string;
165
+ } | {
166
+ type: 'SUSPENDED';
167
+ } | {
168
+ type: 'WAITING';
169
+ };
170
+ type WorkflowActors = {
171
+ resolverFunction: {
172
+ input: ResolverFunctionInput;
173
+ output: ResolverFunctionOutput;
174
+ };
175
+ conditionCheck: {
176
+ input: {
177
+ context: WorkflowContext;
178
+ stepId: string;
179
+ };
180
+ output: DependencyCheckOutput;
181
+ };
182
+ spawnSubscriberFunction: {
183
+ input: {
184
+ context: WorkflowContext;
185
+ stepId: string;
186
+ };
187
+ output: SubscriberFunctionOutput;
188
+ };
189
+ };
190
+ type WorkflowActionParams = {
191
+ stepId: string;
192
+ };
193
+ type WorkflowActions = {
194
+ type: 'updateStepResult' | 'setStepError' | 'notifyStepCompletion' | 'decrementAttemptCount';
195
+ params: WorkflowActionParams;
196
+ };
197
+ type WorkflowState = {
198
+ [key: string]: {
199
+ initial: 'pending';
200
+ states: {
201
+ pending: {
202
+ invoke: {
203
+ src: 'conditionCheck';
204
+ input: ({ context }: {
205
+ context: WorkflowContext;
206
+ }) => {
207
+ context: WorkflowContext;
208
+ stepId: string;
209
+ };
210
+ onDone: [
211
+ {
212
+ guard: (_: any, event: {
213
+ output: DependencyCheckOutput;
214
+ }) => boolean;
215
+ target: 'executing';
216
+ },
217
+ {
218
+ guard: (_: any, event: {
219
+ output: DependencyCheckOutput;
220
+ }) => boolean;
221
+ target: 'waiting';
222
+ }
223
+ ];
224
+ };
225
+ };
226
+ waiting: {
227
+ after: {
228
+ CHECK_INTERVAL: {
229
+ target: 'pending';
230
+ };
231
+ };
232
+ };
233
+ executing: {
234
+ invoke: {
235
+ src: 'resolverFunction';
236
+ input: ({ context }: {
237
+ context: WorkflowContext;
238
+ }) => ResolverFunctionInput;
239
+ onDone: {
240
+ target: 'completed';
241
+ actions: ['updateStepResult'];
242
+ };
243
+ onError: {
244
+ target: 'failed';
245
+ actions: ['setStepError'];
246
+ };
247
+ };
248
+ };
249
+ completed: {
250
+ type: 'final';
251
+ entry: ['notifyStepCompletion'];
252
+ };
253
+ failed: {
254
+ type: 'final';
255
+ entry: ['notifyStepCompletion'];
256
+ };
257
+ };
258
+ };
259
+ };
260
+ declare const StepIdBrand: unique symbol;
261
+ type StepId = string & {
262
+ readonly [StepIdBrand]: typeof StepIdBrand;
263
+ };
264
+ type ExtractSchemaFromStep<TStep extends IAction<any, any, any, any>, TKey extends 'inputSchema' | 'outputSchema'> = TStep[TKey];
265
+ type ExtractStepResult<T> = T extends (data: any) => Promise<infer R> ? R : never;
266
+ type StepInputType<TStep extends IAction<any, any, any, any>, TKey extends 'inputSchema' | 'outputSchema'> = ExtractSchemaFromStep<TStep, TKey> extends infer Schema ? Schema extends z.ZodType<any> ? z.infer<Schema> : never : never;
267
+ type ExtractSchemaType<T extends z.ZodSchema> = T extends z.ZodSchema<infer V> ? V : never;
268
+ type PathsToStringProps<T> = T extends object ? {
269
+ [K in keyof T]: T[K] extends object ? K extends string ? K | `${K}.${PathsToStringProps<T[K]>}` : never : K extends string ? K : never;
270
+ }[keyof T] : never;
271
+ interface WorkflowRunState {
272
+ value: Record<string, string>;
273
+ context: {
274
+ stepResults: Record<string, {
275
+ status: 'success' | 'failed' | 'suspended' | 'waiting';
276
+ payload?: any;
277
+ error?: string;
278
+ }>;
279
+ triggerData: Record<string, any>;
280
+ attempts: Record<string, number>;
281
+ };
282
+ activePaths: Array<{
283
+ stepPath: string[];
284
+ stepId: string;
285
+ status: string;
286
+ }>;
287
+ runId: string;
288
+ timestamp: number;
289
+ }
290
+
291
+ interface StorageColumn {
292
+ type: 'text' | 'timestamp' | 'uuid' | 'jsonb' | 'integer';
293
+ primaryKey?: boolean;
294
+ nullable?: boolean;
295
+ references?: {
296
+ table: string;
297
+ column: string;
298
+ };
299
+ }
300
+ interface WorkflowRow {
301
+ workflow_name: string;
302
+ run_id: string;
303
+ snapshot: WorkflowRunState;
304
+ created_at: Date;
305
+ updated_at: Date;
306
+ }
307
+ type StorageGetMessagesArg = {
308
+ threadId: string;
309
+ selectBy?: {
310
+ vectorSearchString?: string;
311
+ last?: number | false;
312
+ include?: {
313
+ id: string;
314
+ withPreviousMessages?: number;
315
+ withNextMessages?: number;
316
+ }[];
317
+ };
318
+ threadConfig?: MemoryConfig;
319
+ };
320
+
321
+ type TABLE_NAMES = typeof MastraStorage.TABLE_WORKFLOW_SNAPSHOT | typeof MastraStorage.TABLE_EVALS | typeof MastraStorage.TABLE_MESSAGES | typeof MastraStorage.TABLE_THREADS;
322
+ declare abstract class MastraStorage extends MastraBase {
323
+ static readonly TABLE_WORKFLOW_SNAPSHOT = "mastra_workflow_snapshot";
324
+ static readonly TABLE_EVALS = "mastra_evals";
325
+ static readonly TABLE_MESSAGES = "mastra_messages";
326
+ static readonly TABLE_THREADS = "mastra_threads";
327
+ hasInit: boolean;
328
+ constructor({ name }: {
329
+ name: string;
330
+ });
331
+ abstract createTable({ tableName }: {
332
+ tableName: TABLE_NAMES;
333
+ schema: Record<string, StorageColumn>;
334
+ }): Promise<void>;
335
+ abstract clearTable({ tableName }: {
336
+ tableName: TABLE_NAMES;
337
+ }): Promise<void>;
338
+ abstract insert({ tableName, record }: {
339
+ tableName: TABLE_NAMES;
340
+ record: Record<string, any>;
341
+ }): Promise<void>;
342
+ abstract load<R>({ tableName, keys }: {
343
+ tableName: TABLE_NAMES;
344
+ keys: Record<string, string>;
345
+ }): Promise<R | null>;
346
+ abstract getThreadById({ threadId }: {
347
+ threadId: string;
348
+ }): Promise<StorageThreadType | null>;
349
+ __getThreadById({ threadId }: {
350
+ threadId: string;
351
+ }): Promise<StorageThreadType | null>;
352
+ abstract getThreadsByResourceId({ resourceId }: {
353
+ resourceId: string;
354
+ }): Promise<StorageThreadType[]>;
355
+ __getThreadsByResourceId({ resourceId }: {
356
+ resourceId: string;
357
+ }): Promise<StorageThreadType[]>;
358
+ abstract saveThread({ thread }: {
359
+ thread: StorageThreadType;
360
+ }): Promise<StorageThreadType>;
361
+ __saveThread({ thread }: {
362
+ thread: StorageThreadType;
363
+ }): Promise<StorageThreadType>;
364
+ abstract updateThread({ id, title, metadata, }: {
365
+ id: string;
366
+ title: string;
367
+ metadata: Record<string, unknown>;
368
+ }): Promise<StorageThreadType>;
369
+ __updateThread({ id, title, metadata, }: {
370
+ id: string;
371
+ title: string;
372
+ metadata: Record<string, unknown>;
373
+ }): Promise<StorageThreadType>;
374
+ abstract deleteThread({ threadId }: {
375
+ threadId: string;
376
+ }): Promise<void>;
377
+ __deleteThread({ threadId }: {
378
+ threadId: string;
379
+ }): Promise<void>;
380
+ abstract getMessages({ threadId, selectBy, threadConfig }: StorageGetMessagesArg): Promise<MessageType[]>;
381
+ __getMessages({ threadId, selectBy, threadConfig }: StorageGetMessagesArg): Promise<MessageType[]>;
382
+ abstract saveMessages({ messages }: {
383
+ messages: MessageType[];
384
+ }): Promise<MessageType[]>;
385
+ __saveMessages({ messages }: {
386
+ messages: MessageType[];
387
+ }): Promise<MessageType[]>;
388
+ init(): Promise<void>;
389
+ persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
390
+ workflowName: string;
391
+ runId: string;
392
+ snapshot: WorkflowRunState;
393
+ }): Promise<void>;
394
+ loadWorkflowSnapshot({ workflowName, runId, }: {
395
+ workflowName: string;
396
+ runId: string;
397
+ }): Promise<WorkflowRunState | null>;
398
+ }
399
+
400
+ type AiMessageType = Message;
401
+ type MessageType = {
402
+ id: string;
403
+ content: UserContent | AssistantContent | ToolContent;
404
+ role: 'system' | 'user' | 'assistant' | 'tool';
405
+ createdAt: Date;
406
+ threadId: string;
407
+ toolCallIds?: string[];
408
+ toolCallArgs?: Record<string, unknown>[];
409
+ toolNames?: string[];
410
+ type: 'text' | 'tool-call' | 'tool-result';
411
+ };
412
+ type StorageThreadType = {
413
+ id: string;
414
+ title?: string;
415
+ resourceId: string;
416
+ createdAt: Date;
417
+ updatedAt: Date;
418
+ metadata?: Record<string, unknown>;
419
+ };
420
+ type MessageResponse<T extends 'raw' | 'core_message'> = {
421
+ raw: MessageType[];
422
+ core_message: CoreMessage$1[];
423
+ }[T];
424
+ type MemoryConfig = {
425
+ lastMessages?: number | false;
426
+ semanticRecall?: boolean | {
427
+ topK: number;
428
+ messageRange: number | {
429
+ before: number;
430
+ after: number;
431
+ };
432
+ };
433
+ workingMemory?: {
434
+ enabled: boolean;
435
+ template?: string;
436
+ };
437
+ };
438
+ type SharedMemoryConfig = {
439
+ storage: MastraStorage;
440
+ options?: MemoryConfig;
441
+ vector?: MastraVector;
442
+ embedder?: EmbeddingModel<string>;
443
+ };
444
+ /**
445
+ * Abstract Memory class that defines the interface for storing and retrieving
446
+ * conversation threads and messages.
447
+ */
448
+ declare abstract class MastraMemory extends MastraBase {
449
+ MAX_CONTEXT_TOKENS?: number;
450
+ storage: MastraStorage;
451
+ vector?: MastraVector;
452
+ embedder?: EmbeddingModel<string>;
453
+ protected threadConfig: MemoryConfig;
454
+ constructor(config: {
455
+ name: string;
456
+ } & SharedMemoryConfig);
457
+ /**
458
+ * Get a system message to inject into the conversation.
459
+ * This will be called before each conversation turn.
460
+ * Implementations can override this to inject custom system messages.
461
+ */
462
+ getSystemMessage(_input: {
463
+ threadId: string;
464
+ memoryConfig?: MemoryConfig;
465
+ }): Promise<string | null>;
466
+ protected getEmbedder(): EmbeddingModel<string>;
467
+ protected getMergedThreadConfig(config?: MemoryConfig): MemoryConfig;
468
+ abstract rememberMessages({ threadId, vectorMessageSearch, config, }: {
469
+ threadId: string;
470
+ vectorMessageSearch?: string;
471
+ config?: MemoryConfig;
472
+ }): Promise<{
473
+ messages: CoreMessage$1[];
474
+ uiMessages: AiMessageType[];
475
+ }>;
476
+ estimateTokens(text: string): number;
477
+ protected parseMessages(messages: MessageType[]): CoreMessage$1[];
478
+ protected convertToUIMessages(messages: MessageType[]): AiMessageType[];
479
+ /**
480
+ * Retrieves a specific thread by its ID
481
+ * @param threadId - The unique identifier of the thread
482
+ * @returns Promise resolving to the thread or null if not found
483
+ */
484
+ abstract getThreadById({ threadId }: {
485
+ threadId: string;
486
+ }): Promise<StorageThreadType | null>;
487
+ abstract getThreadsByResourceId({ resourceId }: {
488
+ resourceId: string;
489
+ }): Promise<StorageThreadType[]>;
490
+ /**
491
+ * Saves or updates a thread
492
+ * @param thread - The thread data to save
493
+ * @returns Promise resolving to the saved thread
494
+ */
495
+ abstract saveThread({ thread, memoryConfig, }: {
496
+ thread: StorageThreadType;
497
+ memoryConfig?: MemoryConfig;
498
+ }): Promise<StorageThreadType>;
499
+ /**
500
+ * Saves messages to a thread
501
+ * @param messages - Array of messages to save
502
+ * @returns Promise resolving to the saved messages
503
+ */
504
+ abstract saveMessages({ messages, memoryConfig, }: {
505
+ messages: MessageType[];
506
+ memoryConfig: MemoryConfig | undefined;
507
+ }): Promise<MessageType[]>;
508
+ /**
509
+ * Retrieves all messages for a specific thread
510
+ * @param threadId - The unique identifier of the thread
511
+ * @returns Promise resolving to array of messages and uiMessages
512
+ */
513
+ abstract query({ threadId, selectBy, }: StorageGetMessagesArg): Promise<{
514
+ messages: CoreMessage$1[];
515
+ uiMessages: AiMessageType[];
516
+ }>;
517
+ /**
518
+ * Helper method to create a new thread
519
+ * @param title - Optional title for the thread
520
+ * @param metadata - Optional metadata for the thread
521
+ * @returns Promise resolving to the created thread
522
+ */
523
+ createThread({ threadId, resourceId, title, metadata, memoryConfig, }: {
524
+ resourceId: string;
525
+ threadId?: string;
526
+ title?: string;
527
+ metadata?: Record<string, unknown>;
528
+ memoryConfig?: MemoryConfig;
529
+ }): Promise<StorageThreadType>;
530
+ /**
531
+ * Helper method to delete a thread
532
+ * @param threadId - the id of the thread to delete
533
+ */
534
+ abstract deleteThread(threadId: string): Promise<void>;
535
+ /**
536
+ * Helper method to add a single message to a thread
537
+ * @param threadId - The thread to add the message to
538
+ * @param content - The message content
539
+ * @param role - The role of the message sender
540
+ * @param type - The type of the message
541
+ * @param toolNames - Optional array of tool names that were called
542
+ * @param toolCallArgs - Optional array of tool call arguments
543
+ * @param toolCallIds - Optional array of tool call ids
544
+ * @returns Promise resolving to the saved message
545
+ */
546
+ addMessage({ threadId, config, content, role, type, toolNames, toolCallArgs, toolCallIds, }: {
547
+ threadId: string;
548
+ config?: MemoryConfig;
549
+ content: UserContent | AssistantContent;
550
+ role: 'user' | 'assistant';
551
+ type: 'text' | 'tool-call' | 'tool-result';
552
+ toolNames?: string[];
553
+ toolCallArgs?: Record<string, unknown>[];
554
+ toolCallIds?: string[];
555
+ }): Promise<MessageType>;
556
+ /**
557
+ * Generates a unique identifier
558
+ * @returns A unique string ID
559
+ */
560
+ generateId(): string;
561
+ }
562
+
563
+ type MastraPrimitives = {
564
+ logger?: Logger;
565
+ telemetry?: Telemetry;
566
+ storage?: MastraStorage;
567
+ agents?: Record<string, Agent>;
568
+ tts?: Record<string, MastraTTS>;
569
+ vectors?: Record<string, MastraVector>;
570
+ memory?: MastraMemory;
571
+ };
572
+ interface IExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> {
573
+ context: TSchemaIn extends z.ZodSchema ? z.infer<TSchemaIn> & {
574
+ machineContext?: TContext;
575
+ } : {
576
+ machineContext?: TContext;
577
+ };
578
+ runId?: string;
579
+ mastra?: MastraPrimitives;
580
+ suspend: () => Promise<void>;
581
+ }
582
+ interface IAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends IExecutionContext<TSchemaIn>> {
583
+ id: TId;
584
+ description?: string;
585
+ inputSchema?: TSchemaIn;
586
+ outputSchema?: TSchemaOut;
587
+ mastra?: MastraPrimitives;
588
+ payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
589
+ execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
590
+ [key: string]: any;
591
+ }
592
+
593
+ type CoreTool = {
594
+ description?: string;
595
+ parameters: ZodSchema;
596
+ execute: (params: any) => Promise<any>;
597
+ };
598
+ interface ToolExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn, TContext> {
599
+ }
600
+ interface ToolAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined = undefined, TSchemaOut extends z.ZodSchema | undefined = undefined, TContext extends ToolExecutionContext<TSchemaIn> = ToolExecutionContext<TSchemaIn>> extends IAction<TId, TSchemaIn, TSchemaOut, TContext> {
601
+ }
602
+
603
+ type ToolsetsInput = Record<string, Record<string, ToolAction<any, any, any, any>>>;
604
+ type ToolsInput = Record<string, ToolAction<any, any, any, any>>;
605
+ interface AgentConfig<TTools extends Record<string, ToolAction<any, any, any, any>> = Record<string, ToolAction<any, any, any, any>>, TMetrics extends Record<string, Metric> = Record<string, Metric>> {
606
+ name: string;
607
+ instructions: string;
608
+ model: LanguageModelV1;
609
+ tools?: TTools;
610
+ mastra?: MastraPrimitives;
611
+ metrics?: TMetrics;
612
+ memory?: MastraMemory;
613
+ }
614
+ interface AgentGenerateOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> {
615
+ toolsets?: ToolsetsInput;
616
+ resourceId?: string;
617
+ context?: CoreMessage[];
618
+ threadId?: string;
619
+ memoryOptions?: MemoryConfig;
620
+ runId?: string;
621
+ onStepFinish?: (step: string) => void;
622
+ maxSteps?: number;
623
+ output?: OutputType | Z;
624
+ temperature?: number;
625
+ toolChoice?: 'auto' | 'required';
626
+ }
627
+ interface AgentStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> {
628
+ toolsets?: ToolsetsInput;
629
+ resourceId?: string;
630
+ context?: CoreMessage[];
631
+ threadId?: string;
632
+ memoryOptions?: MemoryConfig;
633
+ runId?: string;
634
+ onFinish?: (result: string) => Promise<void> | void;
635
+ onStepFinish?: (step: string) => void;
636
+ maxSteps?: number;
637
+ output?: OutputType | Z;
638
+ temperature?: number;
639
+ toolChoice?: 'auto' | 'required';
640
+ }
641
+
642
+ type LanguageModel = LanguageModelV1;
643
+ type CoreMessage = CoreMessage$1;
644
+ type CoreSystemMessage = CoreSystemMessage$1;
645
+ type CoreAssistantMessage = CoreAssistantMessage$1;
646
+ type CoreUserMessage = CoreUserMessage$1;
647
+ type CoreToolMessage = CoreToolMessage$1;
648
+ type EmbedResult<T> = EmbedResult$1<T>;
649
+ type EmbedManyResult<T> = EmbedManyResult$1<T>;
650
+ type BaseStructuredOutputType = 'string' | 'number' | 'boolean' | 'date';
651
+ type StructuredOutputType = 'array' | 'string' | 'number' | 'object' | 'boolean' | 'date';
652
+ type StructuredOutputArrayItem = {
653
+ type: BaseStructuredOutputType;
654
+ } | {
655
+ type: 'object';
656
+ items: StructuredOutput;
657
+ };
658
+ type StructuredOutput = {
659
+ [key: string]: {
660
+ type: BaseStructuredOutputType;
661
+ } | {
662
+ type: 'object';
663
+ items: StructuredOutput;
664
+ } | {
665
+ type: 'array';
666
+ items: StructuredOutputArrayItem;
667
+ };
668
+ };
669
+ type GenerateReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? GenerateTextResult<any, any> : GenerateObjectResult<any>;
670
+ type StreamReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? StreamTextResult<any, any> : StreamObjectResult<any, any, any>;
671
+ type OutputType = 'text' | StructuredOutput;
672
+ type LLMStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
673
+ runId?: string;
674
+ onFinish?: (result: string) => Promise<void> | void;
675
+ onStepFinish?: (step: string) => void;
676
+ maxSteps?: number;
677
+ tools?: ToolsInput;
678
+ convertedTools?: Record<string, CoreTool>;
679
+ output?: OutputType | Z;
680
+ temperature?: number;
681
+ };
682
+ type LLMTextOptions = {
683
+ tools?: ToolsInput;
684
+ convertedTools?: Record<string, CoreTool>;
685
+ messages: CoreMessage[];
686
+ onStepFinish?: (step: string) => void;
687
+ toolChoice?: 'auto' | 'required';
688
+ maxSteps?: number;
689
+ temperature?: number;
690
+ } & Run;
691
+ type LLMTextObjectOptions<T> = LLMTextOptions & {
692
+ structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
693
+ };
694
+ type LLMInnerStreamOptions = {
695
+ tools?: ToolsInput;
696
+ convertedTools?: Record<string, CoreTool>;
697
+ messages: CoreMessage[];
698
+ onStepFinish?: (step: string) => void;
699
+ onFinish?: (result: string) => Promise<void> | void;
700
+ maxSteps?: number;
701
+ temperature?: number;
702
+ toolChoice?: 'auto' | 'required';
703
+ } & Run;
704
+ type LLMStreamObjectOptions<T> = LLMInnerStreamOptions & {
705
+ structuredOutput: JSONSchema7 | z.ZodType<T> | StructuredOutput;
706
+ };
707
+
708
+ declare class MastraLLMBase extends MastraBase {
709
+ #private;
710
+ constructor({ name, model }: {
711
+ name: string;
712
+ model: LanguageModel$1;
713
+ });
714
+ getProvider(): string;
715
+ convertToMessages(messages: string | string[] | CoreMessage$1[]): CoreMessage$1[];
716
+ __registerPrimitives(p: MastraPrimitives): void;
717
+ __text(input: LLMTextOptions): Promise<GenerateTextResult<any, any>>;
718
+ __textObject<T>(input: LLMTextObjectOptions<T>): Promise<GenerateObjectResult<T>>;
719
+ generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], options?: LLMStreamOptions<Z>): Promise<GenerateReturn<Z>>;
720
+ __stream(input: LLMInnerStreamOptions): Promise<StreamTextResult<any, any>>;
721
+ __streamObject<T>(input: LLMStreamObjectOptions<T>): Promise<StreamObjectResult<DeepPartial<T>, T, never>>;
722
+ stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], options?: LLMStreamOptions<Z>): Promise<StreamReturn<Z>>;
723
+ }
724
+
725
+ declare class Agent<TTools extends Record<string, ToolAction<any, any, any, any>> = Record<string, ToolAction<any, any, any, any>>, TMetrics extends Record<string, Metric> = Record<string, Metric>> extends MastraBase {
726
+ #private;
727
+ name: string;
728
+ readonly llm: MastraLLMBase;
729
+ readonly instructions: string;
730
+ readonly model?: LanguageModelV1;
731
+ tools: TTools;
732
+ metrics: TMetrics;
733
+ constructor(config: AgentConfig<TTools, TMetrics>);
734
+ hasOwnMemory(): boolean;
735
+ getMemory(): MastraMemory | undefined;
736
+ __registerPrimitives(p: MastraPrimitives): void;
737
+ /**
738
+ * Set the concrete tools for the agent
739
+ * @param tools
740
+ */
741
+ __setTools(tools: TTools): void;
742
+ generateTitleFromUserMessage({ message }: {
743
+ message: CoreUserMessage$1;
744
+ }): Promise<string>;
745
+ getMostRecentUserMessage(messages: Array<CoreMessage$1>): CoreUserMessage$1 | undefined;
746
+ genTitle(userMessage: CoreUserMessage$1 | undefined): Promise<string>;
747
+ saveMemory({ threadId, memoryConfig, resourceId, userMessages, runId, }: {
748
+ resourceId: string;
749
+ threadId?: string;
750
+ memoryConfig?: MemoryConfig;
751
+ userMessages: CoreMessage$1[];
752
+ time?: Date;
753
+ keyword?: string;
754
+ runId?: string;
755
+ }): Promise<{
756
+ threadId: string;
757
+ messages: any[];
758
+ }>;
759
+ saveResponse({ result, threadId, resourceId, runId, memoryConfig, }: {
760
+ runId: string;
761
+ resourceId: string;
762
+ result: Record<string, any>;
763
+ threadId: string;
764
+ memoryConfig: MemoryConfig | undefined;
765
+ }): Promise<void>;
766
+ sanitizeResponseMessages(messages: Array<CoreToolMessage$1 | CoreAssistantMessage$1>): Array<CoreToolMessage$1 | CoreAssistantMessage$1>;
767
+ convertTools({ toolsets, runId, }: {
768
+ toolsets?: ToolsetsInput;
769
+ threadId?: string;
770
+ runId?: string;
771
+ }): Record<string, CoreTool>;
772
+ preExecute({ resourceId, runId, threadId, memoryConfig, messages, }: {
773
+ runId?: string;
774
+ threadId?: string;
775
+ memoryConfig?: MemoryConfig;
776
+ messages: CoreMessage$1[];
777
+ resourceId: string;
778
+ }): Promise<{
779
+ coreMessages: CoreMessage$1[];
780
+ threadIdToUse: string;
781
+ }>;
782
+ __primitive({ messages, context, threadId, memoryConfig, resourceId, runId, toolsets, }: {
783
+ toolsets?: ToolsetsInput;
784
+ resourceId?: string;
785
+ threadId?: string;
786
+ memoryConfig?: MemoryConfig;
787
+ context?: CoreMessage$1[];
788
+ runId?: string;
789
+ messages: CoreMessage$1[];
790
+ }): {
791
+ before: () => Promise<{
792
+ messageObjects: CoreMessage$1[];
793
+ convertedTools: Record<string, CoreTool> | undefined;
794
+ threadId: string;
795
+ }>;
796
+ after: ({ result, threadId, memoryConfig, outputText, runId, }: {
797
+ runId: string;
798
+ result: Record<string, any>;
799
+ threadId: string;
800
+ memoryConfig: MemoryConfig | undefined;
801
+ outputText: string;
802
+ }) => Promise<void>;
803
+ };
804
+ generate<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], { context, threadId: threadIdInFn, memoryOptions, resourceId, maxSteps, onStepFinish, runId, toolsets, output, temperature, toolChoice, }?: AgentGenerateOptions<Z>): Promise<GenerateReturn<Z>>;
805
+ stream<Z extends ZodSchema | JSONSchema7 | undefined = undefined>(messages: string | string[] | CoreMessage$1[], { context, threadId: threadIdInFn, memoryOptions, resourceId, maxSteps, onFinish, onStepFinish, runId, toolsets, output, temperature, toolChoice, }?: AgentStreamOptions<Z>): Promise<StreamReturn<Z>>;
806
+ }
807
+
808
+ export { type StepCondition as $, Agent as A, type BaseStructuredOutputType as B, type CoreMessage as C, type LLMInnerStreamOptions as D, type EmbedResult as E, type LLMStreamObjectOptions as F, type GenerateReturn as G, type AiMessageType as H, type IAction as I, type MessageType as J, type StorageThreadType as K, type LanguageModel as L, MastraStorage as M, type MessageResponse as N, type OutputType as O, type MemoryConfig as P, type SharedMemoryConfig as Q, type RetryConfig as R, type StepExecutionContext as S, type ToolAction as T, type CoreTool as U, type StepNode as V, type WorkflowOptions as W, type VariableReference as X, type BaseCondition as Y, type ActionContext as Z, type StepDef as _, MastraMemory as a, type WorkflowContext as a0, type WorkflowLogMessage as a1, type WorkflowEvent as a2, type ResolverFunctionInput as a3, type ResolverFunctionOutput as a4, type SubscriberFunctionOutput as a5, type DependencyCheckOutput as a6, type WorkflowActors as a7, type WorkflowActionParams as a8, type WorkflowActions as a9, type WorkflowState as aa, type StepId as ab, type ExtractSchemaFromStep as ac, type ExtractStepResult as ad, type StepInputType as ae, type ExtractSchemaType as af, type PathsToStringProps as ag, type IExecutionContext as ah, type StepAction as b, type MastraPrimitives as c, type StepVariableType as d, type StepConfig as e, type StepResult as f, type WorkflowRunState as g, type StepGraph as h, type AgentConfig as i, type ToolExecutionContext as j, type TABLE_NAMES as k, type StorageColumn as l, type WorkflowRow as m, type StorageGetMessagesArg as n, type CoreSystemMessage as o, type CoreAssistantMessage as p, type CoreUserMessage as q, type CoreToolMessage as r, type EmbedManyResult as s, type StructuredOutputType as t, type StructuredOutputArrayItem as u, type StructuredOutput as v, type StreamReturn as w, type LLMStreamOptions as x, type LLMTextOptions as y, type LLMTextObjectOptions as z };