@mastra/core 0.5.0-alpha.8 → 0.5.0

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 (91) hide show
  1. package/dist/agent/index.cjs +3 -2100
  2. package/dist/agent/index.d.cts +1 -1
  3. package/dist/agent/index.d.ts +1 -1
  4. package/dist/agent/index.js +1 -1
  5. package/dist/{base-CTdONy0_.d.cts → base-CIPKleAU.d.cts} +103 -70
  6. package/dist/{base-DIn_km7X.d.ts → base-C_Oq53qk.d.ts} +103 -70
  7. package/dist/base.cjs +5 -140
  8. package/dist/bundler/index.cjs +5 -160
  9. package/dist/chunk-2W2GYEYQ.cjs +25 -0
  10. package/dist/chunk-3ASEZT7U.cjs +1586 -0
  11. package/dist/chunk-43Y7WG5W.cjs +335 -0
  12. package/dist/{chunk-HBHPTMAC.js → chunk-4Y74D74B.js} +46 -6
  13. package/dist/chunk-ENT7U27Y.cjs +37 -0
  14. package/dist/chunk-F5UYWPV4.cjs +14 -0
  15. package/dist/chunk-FL3GQXQ2.cjs +218 -0
  16. package/dist/chunk-FRQFWZDN.cjs +2 -0
  17. package/dist/chunk-GXQRMKSN.cjs +367 -0
  18. package/dist/chunk-HJPMYDWO.cjs +37 -0
  19. package/dist/chunk-IIWRJFLQ.cjs +51 -0
  20. package/dist/chunk-KFQ7Z3PO.cjs +347 -0
  21. package/dist/{chunk-SWDQYPJS.js → chunk-KP5UAFLN.js} +3 -2
  22. package/dist/chunk-KPKFLQFR.cjs +12 -0
  23. package/dist/{chunk-RRJB4TCC.js → chunk-MLFXOST6.js} +1 -1
  24. package/dist/{chunk-KBSR2LLT.js → chunk-OD7ZMKHY.js} +176 -63
  25. package/dist/chunk-OTFLHXHZ.cjs +65 -0
  26. package/dist/chunk-RWTSGWWL.cjs +81 -0
  27. package/dist/chunk-ST5RMVLG.cjs +87 -0
  28. package/dist/chunk-SYQ7NK2E.cjs +24 -0
  29. package/dist/chunk-UZNQG7QO.cjs +1868 -0
  30. package/dist/chunk-V5ORZPFW.cjs +38 -0
  31. package/dist/chunk-VA4P7QJT.cjs +443 -0
  32. package/dist/chunk-WB2HREXE.cjs +166 -0
  33. package/dist/chunk-WOMOGDGR.cjs +691 -0
  34. package/dist/chunk-XB2TJ7LX.cjs +408 -0
  35. package/dist/{chunk-QABMKXI3.js → chunk-XF2FMJYK.js} +1 -1
  36. package/dist/chunk-XLSROQ26.cjs +91 -0
  37. package/dist/chunk-YK3XJ52U.cjs +192 -0
  38. package/dist/{chunk-SF5GHHOQ.js → chunk-YPD6BQIM.js} +121 -93
  39. package/dist/deployer/index.cjs +5 -167
  40. package/dist/eval/index.cjs +9 -105
  41. package/dist/eval/index.d.cts +1 -1
  42. package/dist/eval/index.d.ts +1 -1
  43. package/dist/hooks/index.cjs +14 -83
  44. package/dist/index.cjs +253 -7470
  45. package/dist/index.d.cts +4 -4
  46. package/dist/index.d.ts +4 -4
  47. package/dist/index.js +7 -7
  48. package/dist/integration/index.cjs +9 -108
  49. package/dist/integration/index.d.cts +1 -1
  50. package/dist/integration/index.d.ts +1 -1
  51. package/dist/llm/index.d.cts +1 -1
  52. package/dist/llm/index.d.ts +1 -1
  53. package/dist/logger/index.cjs +33 -161
  54. package/dist/mastra/index.cjs +3 -1755
  55. package/dist/mastra/index.d.cts +1 -1
  56. package/dist/mastra/index.d.ts +1 -1
  57. package/dist/mastra/index.js +1 -1
  58. package/dist/memory/index.cjs +4 -2050
  59. package/dist/memory/index.d.cts +1 -1
  60. package/dist/memory/index.d.ts +1 -1
  61. package/dist/memory/index.js +1 -1
  62. package/dist/relevance/index.cjs +10 -2161
  63. package/dist/relevance/index.d.cts +19 -2
  64. package/dist/relevance/index.d.ts +19 -2
  65. package/dist/relevance/index.js +1 -1
  66. package/dist/storage/index.cjs +29 -367
  67. package/dist/storage/index.d.cts +1 -1
  68. package/dist/storage/index.d.ts +1 -1
  69. package/dist/storage/libsql/index.cjs +9 -798
  70. package/dist/storage/libsql/index.d.cts +1 -1
  71. package/dist/storage/libsql/index.d.ts +1 -1
  72. package/dist/telemetry/index.cjs +21 -408
  73. package/dist/telemetry/index.d.cts +1 -1
  74. package/dist/telemetry/index.d.ts +1 -1
  75. package/dist/tools/index.cjs +11 -22
  76. package/dist/tools/index.d.cts +3 -3
  77. package/dist/tools/index.d.ts +3 -3
  78. package/dist/tts/index.cjs +3 -328
  79. package/dist/utils.cjs +41 -309
  80. package/dist/utils.d.cts +10 -4
  81. package/dist/utils.d.ts +10 -4
  82. package/dist/utils.js +1 -1
  83. package/dist/vector/filter/index.cjs +7 -189
  84. package/dist/vector/index.cjs +5 -172
  85. package/dist/vector/libsql/index.cjs +9 -1047
  86. package/dist/voice/index.cjs +8 -306
  87. package/dist/workflows/index.cjs +65 -1925
  88. package/dist/workflows/index.d.cts +4 -3
  89. package/dist/workflows/index.d.ts +4 -3
  90. package/dist/workflows/index.js +1 -1
  91. package/package.json +27 -27
@@ -1,6 +1,6 @@
1
1
  import * as ai from 'ai';
2
2
  import { Tool, ToolExecutionOptions, EmbeddingModel, CoreMessage as CoreMessage$1, Message, UserContent, AssistantContent, LanguageModelV1, TelemetrySettings, generateText, generateObject, streamText, GenerateTextResult, GenerateObjectResult, streamObject, StreamTextResult, StreamObjectResult, CoreSystemMessage as CoreSystemMessage$1, CoreAssistantMessage as CoreAssistantMessage$1, CoreUserMessage as CoreUserMessage$1, CoreToolMessage as CoreToolMessage$1, EmbedResult as EmbedResult$1, EmbedManyResult as EmbedManyResult$1, LanguageModel as LanguageModel$1, DeepPartial, ToolContent } from 'ai';
3
- import { M as MastraBase, O as OtelConfig, T as Telemetry } from './base-BZViaFTt.js';
3
+ import { M as MastraBase, T as Telemetry, O as OtelConfig } from './base-BZViaFTt.js';
4
4
  import { Query } from 'sift';
5
5
  import { z, ZodSchema } from 'zod';
6
6
  import { JSONSchema7 } from 'json-schema';
@@ -23,7 +23,7 @@ interface ToolExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undef
23
23
  }
24
24
  interface ToolAction<TSchemaIn extends z.ZodSchema | undefined = undefined, TSchemaOut extends z.ZodSchema | undefined = undefined, TContext extends ToolExecutionContext<TSchemaIn> = ToolExecutionContext<TSchemaIn>, TOptions extends unknown = unknown> extends IAction<string, TSchemaIn, TSchemaOut, TContext, TOptions> {
25
25
  description: string;
26
- execute: (context: TContext, options?: TOptions) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
26
+ execute?: (context: TContext, options?: TOptions) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
27
27
  mastra?: Mastra;
28
28
  }
29
29
 
@@ -62,8 +62,9 @@ declare abstract class MastraMemory extends MastraBase {
62
62
  indexName: string;
63
63
  }>;
64
64
  getMergedThreadConfig(config?: MemoryConfig): MemoryConfig;
65
- abstract rememberMessages({ threadId, vectorMessageSearch, config, }: {
65
+ abstract rememberMessages({ threadId, resourceId, vectorMessageSearch, config, }: {
66
66
  threadId: string;
67
+ resourceId?: string;
67
68
  vectorMessageSearch?: string;
68
69
  config?: MemoryConfig;
69
70
  }): Promise<{
@@ -108,7 +109,7 @@ declare abstract class MastraMemory extends MastraBase {
108
109
  * @param threadId - The unique identifier of the thread
109
110
  * @returns Promise resolving to array of messages and uiMessages
110
111
  */
111
- abstract query({ threadId, selectBy, }: StorageGetMessagesArg): Promise<{
112
+ abstract query({ threadId, resourceId, selectBy, }: StorageGetMessagesArg): Promise<{
112
113
  messages: CoreMessage$1[];
113
114
  uiMessages: Message[];
114
115
  }>;
@@ -158,6 +159,19 @@ declare abstract class MastraMemory extends MastraBase {
158
159
  generateId(): string;
159
160
  }
160
161
 
162
+ declare class Step<TStepId extends string = any, TSchemaIn extends z.ZodSchema | undefined = undefined, TSchemaOut extends z.ZodSchema | undefined = undefined, TContext extends StepExecutionContext<TSchemaIn> = StepExecutionContext<TSchemaIn>> implements StepAction<TStepId, TSchemaIn, TSchemaOut, TContext> {
163
+ id: TStepId;
164
+ description?: string;
165
+ inputSchema?: TSchemaIn;
166
+ outputSchema?: TSchemaOut;
167
+ payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
168
+ execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
169
+ retryConfig?: RetryConfig;
170
+ mastra?: Mastra;
171
+ constructor({ id, description, execute, payload, outputSchema, inputSchema, retryConfig, }: StepAction<TStepId, TSchemaIn, TSchemaOut, TContext>);
172
+ }
173
+ declare function createStep<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends StepExecutionContext<TSchemaIn>>(opts: StepAction<TId, TSchemaIn, TSchemaOut, TContext>): Step<TId, TSchemaIn, TSchemaOut, TContext>;
174
+
161
175
  interface WorkflowOptions<TTriggerSchema extends z.ZodObject<any> = any> {
162
176
  name: string;
163
177
  triggerSchema?: TTriggerSchema;
@@ -166,13 +180,14 @@ interface WorkflowOptions<TTriggerSchema extends z.ZodObject<any> = any> {
166
180
  }
167
181
  interface StepExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn> {
168
182
  context: TSchemaIn extends z.ZodSchema ? z.infer<TSchemaIn> & TContext : TContext;
169
- suspend: () => Promise<void>;
183
+ suspend: (payload?: unknown) => Promise<void>;
170
184
  runId: string;
171
185
  mastra?: MastraUnion;
172
186
  }
173
187
  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> {
174
188
  mastra?: Mastra;
175
189
  payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
190
+ execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
176
191
  retryConfig?: RetryConfig;
177
192
  }
178
193
  interface SimpleConditionalType {
@@ -224,14 +239,15 @@ type ActionContext<TSchemaIn extends z.ZodType<any>> = StepExecutionContext<z.in
224
239
  declare enum WhenConditionReturnValue {
225
240
  CONTINUE = "continue",
226
241
  CONTINUE_FAILED = "continue_failed",
227
- ABORT = "abort"
242
+ ABORT = "abort",
243
+ LIMBO = "limbo"
228
244
  }
229
245
  type StepDef<TStepId extends TSteps[number]['id'], TSteps extends StepAction<any, any, any, any>[], TSchemaIn extends z.ZodType<any>, TSchemaOut extends z.ZodType<any>> = Record<TStepId, {
230
- snapshotOnTimeout?: boolean;
231
246
  when?: Condition<any, any> | ((args: {
232
247
  context: WorkflowContext;
233
248
  mastra?: Mastra;
234
249
  }) => Promise<boolean | WhenConditionReturnValue>);
250
+ serializedWhen?: Condition<any, any> | string;
235
251
  data: TSchemaIn;
236
252
  handler: (args: ActionContext<TSchemaIn>) => Promise<z.infer<TSchemaOut>>;
237
253
  }>;
@@ -249,10 +265,9 @@ type Condition<TStep extends StepVariableType<any, any, any, any>, TTriggerSchem
249
265
  } | {
250
266
  not: Condition<TStep, TTriggerSchema>;
251
267
  };
252
- interface StepConfig<TStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>> {
253
- snapshotOnTimeout?: boolean;
268
+ interface StepConfig<TStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>, TTriggerSchema extends z.ZodObject<any>, TSteps extends Step<string, any, any, any>[] = Step<string, any, any, any>[]> {
254
269
  when?: Condition<CondStep, TTriggerSchema> | ((args: {
255
- context: WorkflowContext<TTriggerSchema>;
270
+ context: WorkflowContext<TTriggerSchema, TSteps>;
256
271
  mastra?: Mastra;
257
272
  }) => Promise<boolean | WhenConditionReturnValue>);
258
273
  variables?: StepInputType<TStep, 'inputSchema'> extends never ? Record<string, VariableReference<VarStep, TTriggerSchema>> : {
@@ -274,13 +289,35 @@ type StepFailure = {
274
289
  status: 'failed';
275
290
  error: string;
276
291
  };
277
- type StepResult<T> = StepSuccess<T> | StepFailure | StepSuspended | StepWaiting;
278
- interface WorkflowContext<TTrigger extends z.ZodObject<any> = any> {
292
+ type StepSkipped = {
293
+ status: 'skipped';
294
+ };
295
+ type StepResult<T> = StepSuccess<T> | StepFailure | StepSuspended | StepWaiting | StepSkipped;
296
+ type StepsRecord<T extends readonly Step<any, any, z.ZodType<any> | undefined>[]> = {
297
+ [K in T[number]['id']]: Extract<T[number], {
298
+ id: K;
299
+ }>;
300
+ };
301
+ interface WorkflowRunResult<T extends z.ZodType<any>, TSteps extends Step<string, any, z.ZodType<any> | undefined>[]> {
302
+ triggerData?: z.infer<T>;
303
+ results: {
304
+ [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
305
+ };
306
+ runId: string;
307
+ activePaths: Map<string, {
308
+ status: string;
309
+ suspendPayload?: any;
310
+ }>;
311
+ }
312
+ interface WorkflowContext<TTrigger extends z.ZodObject<any> = any, TSteps extends Step<string, any, any, any>[] = Step<string, any, any, any>[]> {
279
313
  mastra?: MastraUnion;
280
- steps: Record<string, StepResult<any>>;
314
+ steps: {
315
+ [K in keyof StepsRecord<TSteps>]: StepsRecord<TSteps>[K]['outputSchema'] extends undefined ? StepResult<unknown> : StepResult<z.infer<NonNullable<StepsRecord<TSteps>[K]['outputSchema']>>>;
316
+ };
281
317
  triggerData: z.infer<TTrigger>;
282
318
  attempts: Record<string, number>;
283
- getStepResult: <T = unknown>(stepId: string) => T | undefined;
319
+ getStepResult<T extends keyof StepsRecord<TSteps> | unknown>(stepId: T extends keyof StepsRecord<TSteps> ? T : string): T extends keyof StepsRecord<TSteps> ? StepsRecord<TSteps>[T]['outputSchema'] extends undefined ? unknown : z.infer<NonNullable<StepsRecord<TSteps>[T]['outputSchema']>> : T;
320
+ getStepResult<T extends Step<any, any, any, any>>(stepId: T): T['outputSchema'] extends undefined ? unknown : z.infer<NonNullable<T['outputSchema']>>;
284
321
  }
285
322
  interface WorkflowLogMessage extends BaseLogMessage {
286
323
  type: typeof RegisteredLogger.WORKFLOW;
@@ -336,11 +373,22 @@ type DependencyCheckOutput = {
336
373
  type: 'SUSPENDED';
337
374
  } | {
338
375
  type: 'WAITING';
376
+ } | {
377
+ type: 'CONDITIONS_LIMBO';
378
+ };
379
+ type StepResolverOutput = {
380
+ type: 'STEP_SUCCESS';
381
+ output: unknown;
382
+ } | {
383
+ type: 'STEP_FAILED';
384
+ error: string;
385
+ } | {
386
+ type: 'STEP_WAITING';
339
387
  };
340
388
  type WorkflowActors = {
341
389
  resolverFunction: {
342
390
  input: ResolverFunctionInput;
343
- output: ResolverFunctionOutput;
391
+ output: StepResolverOutput;
344
392
  };
345
393
  conditionCheck: {
346
394
  input: {
@@ -442,7 +490,7 @@ interface WorkflowRunState {
442
490
  value: Record<string, string>;
443
491
  context: {
444
492
  steps: Record<string, {
445
- status: 'success' | 'failed' | 'suspended' | 'waiting';
493
+ status: 'success' | 'failed' | 'suspended' | 'waiting' | 'skipped';
446
494
  payload?: any;
447
495
  error?: string;
448
496
  }>;
@@ -464,35 +512,14 @@ type WorkflowResumeResult<TTriggerSchema extends z.ZodObject<any>> = {
464
512
  results: Record<string, StepResult<any>>;
465
513
  };
466
514
 
467
- declare class Step<TStepId extends string = any, TSchemaIn extends z.ZodSchema | undefined = undefined, TSchemaOut extends z.ZodSchema | undefined = undefined, TContext extends StepExecutionContext<TSchemaIn> = StepExecutionContext<TSchemaIn>> implements StepAction<TStepId, TSchemaIn, TSchemaOut, TContext> {
468
- id: TStepId;
469
- description?: string;
470
- inputSchema?: TSchemaIn;
471
- outputSchema?: TSchemaOut;
472
- payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
473
- execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
474
- retryConfig?: RetryConfig;
475
- mastra?: Mastra;
476
- constructor({ id, description, execute, payload, outputSchema, inputSchema, retryConfig, }: StepAction<TStepId, TSchemaIn, TSchemaOut, TContext>);
477
- }
478
- declare function createStep<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends StepExecutionContext<TSchemaIn>>(opts: StepAction<TId, TSchemaIn, TSchemaOut, TContext>): Step<TId, TSchemaIn, TSchemaOut, TContext>;
479
-
480
- interface WorkflowResultReturn<T extends z.ZodType<any>> {
515
+ interface WorkflowResultReturn<T extends z.ZodType<any>, TSteps extends Step<any, any, any>[]> {
481
516
  runId: string;
482
517
  start: (props?: {
483
518
  triggerData?: z.infer<T>;
484
- } | undefined) => Promise<{
485
- triggerData?: z.infer<T>;
486
- results: Record<string, StepResult<any>>;
487
- runId: string;
488
- activePaths: Map<string, {
489
- status: string;
490
- suspendPayload?: any;
491
- }>;
492
- }>;
519
+ } | undefined) => Promise<WorkflowRunResult<T, TSteps>>;
493
520
  }
494
521
 
495
- declare class Workflow<TSteps extends Step<any, any, any>[] = any, TTriggerSchema extends z.ZodObject<any> = any> extends MastraBase {
522
+ declare class Workflow<TSteps extends Step<string, any, any>[] = Step<string, any, any>[], TTriggerSchema extends z.ZodObject<any> = any> extends MastraBase {
496
523
  #private;
497
524
  name: string;
498
525
  triggerSchema?: TTriggerSchema;
@@ -506,7 +533,7 @@ declare class Workflow<TSteps extends Step<any, any, any>[] = any, TTriggerSchem
506
533
  then<TStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(step: TStep, config?: StepConfig<TStep, CondStep, VarStep, TTriggerSchema>): this;
507
534
  private loop;
508
535
  while<FallbackStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(condition: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema>['when'], fallbackStep: FallbackStep): this;
509
- until<FallbackStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(condition: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema>['when'], fallbackStep: FallbackStep): this;
536
+ until<FallbackStep extends StepAction<any, any, any, any>, CondStep extends StepVariableType<any, any, any, any>, VarStep extends StepVariableType<any, any, any, any>>(condition: StepConfig<FallbackStep, CondStep, VarStep, TTriggerSchema, TSteps>['when'], fallbackStep: FallbackStep): this;
510
537
  if<TStep extends StepAction<any, any, any, any>>(condition: StepConfig<TStep, any, any, TTriggerSchema>['when']): this;
511
538
  else(): this;
512
539
  after<TStep extends StepAction<any, any, any, any>>(steps: TStep | TStep[]): Omit<typeof this, "then" | "after">;
@@ -516,7 +543,7 @@ declare class Workflow<TSteps extends Step<any, any, any>[] = any, TTriggerSchem
516
543
  * @returns Promise resolving to workflow results or rejecting with error
517
544
  * @throws Error if trigger schema validation fails
518
545
  */
519
- createRun(): WorkflowResultReturn<TTriggerSchema>;
546
+ createRun(): WorkflowResultReturn<TTriggerSchema, TSteps>;
520
547
  /**
521
548
  * Rebuilds the machine with the current steps configuration and validates the workflow
522
549
  *
@@ -533,26 +560,12 @@ declare class Workflow<TSteps extends Step<any, any, any>[] = any, TTriggerSchem
533
560
  runId: string;
534
561
  stepId: string;
535
562
  context?: Record<string, any>;
536
- }): Promise<{
537
- triggerData?: z.TypeOf<TTriggerSchema> | undefined;
538
- results: Record<string, StepResult<any>>;
539
- activePaths: Map<string, {
540
- status: string;
541
- suspendPayload?: any;
542
- }>;
543
- } | undefined>;
563
+ }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
544
564
  _resume({ runId, stepId, context: resumeContext, }: {
545
565
  runId: string;
546
566
  stepId: string;
547
567
  context?: Record<string, any>;
548
- }): Promise<{
549
- triggerData?: z.TypeOf<TTriggerSchema> | undefined;
550
- results: Record<string, StepResult<any>>;
551
- activePaths: Map<string, {
552
- status: string;
553
- suspendPayload?: any;
554
- }>;
555
- } | undefined>;
568
+ }): Promise<Omit<WorkflowRunResult<TTriggerSchema, TSteps>, "runId"> | undefined>;
556
569
  __registerMastra(mastra: Mastra): void;
557
570
  __registerPrimitives(p: MastraPrimitives): void;
558
571
  get stepGraph(): StepGraph;
@@ -569,18 +582,30 @@ interface Config<TAgents extends Record<string, Agent<any>> = Record<string, Age
569
582
  tts?: TTTS;
570
583
  telemetry?: OtelConfig;
571
584
  deployer?: MastraDeployer;
585
+ /**
586
+ * Server middleware functions to be applied to API routes
587
+ * Each middleware can specify a path pattern (defaults to '/api/*')
588
+ */
589
+ serverMiddleware?: Array<{
590
+ handler: (c: any, next: () => Promise<void>) => Promise<Response | void>;
591
+ path?: string;
592
+ }>;
572
593
  memory?: MastraMemory;
573
594
  }
574
595
  declare class Mastra<TAgents extends Record<string, Agent<any>> = Record<string, Agent<any>>, TWorkflows extends Record<string, Workflow> = Record<string, Workflow>, TVectors extends Record<string, MastraVector> = Record<string, MastraVector>, TTTS extends Record<string, MastraTTS> = Record<string, MastraTTS>, TLogger extends Logger = Logger> {
575
- private vectors?;
576
- private agents;
577
- private logger;
578
- private workflows;
579
- private telemetry?;
580
- private tts?;
581
- private deployer?;
596
+ #private;
597
+ /**
598
+ * @deprecated use getStorage() instead
599
+ */
582
600
  storage?: MastraStorage;
601
+ /**
602
+ * @deprecated use getMemory() instead
603
+ */
583
604
  memory?: MastraMemory;
605
+ /**
606
+ * @deprecated use getTelemetry() instead
607
+ */
608
+ get telemetry(): Telemetry | undefined;
584
609
  constructor(config?: Config<TAgents, TWorkflows, TVectors, TTTS, TLogger>);
585
610
  getAgent<TAgentName extends keyof TAgents>(name: TAgentName): TAgents[TAgentName];
586
611
  getAgents(): TAgents;
@@ -601,6 +626,12 @@ declare class Mastra<TAgents extends Record<string, Agent<any>> = Record<string,
601
626
  getTTS(): TTTS | undefined;
602
627
  getLogger(): TLogger;
603
628
  getTelemetry(): Telemetry | undefined;
629
+ getMemory(): MastraMemory | undefined;
630
+ getStorage(): MastraStorage | undefined;
631
+ getServerMiddleware(): {
632
+ handler: (c: any, next: () => Promise<void>) => Promise<Response | void>;
633
+ path: string;
634
+ }[];
604
635
  getLogsByRunId({ runId, transportId }: {
605
636
  runId: string;
606
637
  transportId: string;
@@ -631,15 +662,16 @@ interface IAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined,
631
662
  description?: string;
632
663
  inputSchema?: TSchemaIn;
633
664
  outputSchema?: TSchemaOut;
634
- execute: (context: TContext, options?: TOptions) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
665
+ execute?: (context: TContext, options?: TOptions) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
635
666
  }
636
667
 
637
668
  type ToolsInput = Record<string, ToolAction<any, any, any> | VercelTool>;
638
669
  type ToolsetsInput = Record<string, ToolsInput>;
670
+ type MastraLanguageModel = LanguageModelV1;
639
671
  interface AgentConfig<TTools extends ToolsInput = ToolsInput, TMetrics extends Record<string, Metric> = Record<string, Metric>> {
640
672
  name: string;
641
673
  instructions: string;
642
- model: LanguageModelV1;
674
+ model: MastraLanguageModel;
643
675
  tools?: TTools;
644
676
  mastra?: Mastra;
645
677
  /** @deprecated This property is deprecated. Use evals instead to add evaluation metrics. */
@@ -693,7 +725,7 @@ type AgentStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefine
693
725
  threadId: string;
694
726
  }) & (Z extends undefined ? DefaultLLMStreamOptions : DefaultLLMStreamObjectOptions);
695
727
 
696
- type LanguageModel = LanguageModelV1;
728
+ type LanguageModel = MastraLanguageModel;
697
729
  type CoreMessage = CoreMessage$1;
698
730
  type CoreSystemMessage = CoreSystemMessage$1;
699
731
  type CoreAssistantMessage = CoreAssistantMessage$1;
@@ -783,7 +815,7 @@ declare class Agent<TTools extends ToolsInput = ToolsInput, TMetrics extends Rec
783
815
  name: string;
784
816
  readonly llm: MastraLLMBase;
785
817
  instructions: string;
786
- readonly model?: LanguageModelV1;
818
+ readonly model?: MastraLanguageModel;
787
819
  tools: TTools;
788
820
  /** @deprecated This property is deprecated. Use evals instead. */
789
821
  metrics: TMetrics;
@@ -933,6 +965,7 @@ interface WorkflowRow {
933
965
  }
934
966
  type StorageGetMessagesArg = {
935
967
  threadId: string;
968
+ resourceId?: string;
936
969
  selectBy?: {
937
970
  vectorSearchString?: string;
938
971
  last?: number | false;
@@ -1120,4 +1153,4 @@ declare abstract class MastraStorage extends MastraBase {
1120
1153
  __getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
1121
1154
  }
1122
1155
 
1123
- export { type RetryConfig as $, Agent as A, type BaseStructuredOutputType as B, type CoreTool as C, type DefaultLLMTextOptions as D, type EvalRow as E, type LLMTextOptions as F, type GenerateReturn as G, type LLMTextObjectOptions as H, type LLMStreamOptions as I, type LLMInnerStreamOptions as J, type LLMStreamObjectOptions as K, type LanguageModel as L, Mastra as M, type Config as N, type OutputType as O, type MessageResponse as P, type MemoryConfig as Q, type SharedMemoryConfig as R, type StorageColumn as S, type ToolAction as T, type StepExecutionContext as U, type VercelTool as V, Workflow as W, type StepAction as X, type StepVariableType as Y, type StepNode as Z, type StepGraph as _, type MastraPrimitives as a, type VariableReference as a0, type BaseCondition as a1, type ActionContext as a2, WhenConditionReturnValue as a3, type StepDef as a4, type StepCondition as a5, type StepConfig as a6, type StepResult as a7, type WorkflowContext as a8, type WorkflowLogMessage as a9, TABLE_TRACES as aA, type WorkflowEvent as aa, type ResolverFunctionInput as ab, type ResolverFunctionOutput as ac, type SubscriberFunctionOutput as ad, type DependencyCheckOutput as ae, type WorkflowActors as af, type WorkflowActionParams as ag, type WorkflowActions as ah, type WorkflowState as ai, type StepId as aj, type ExtractSchemaFromStep as ak, type ExtractStepResult as al, type StepInputType as am, type ExtractSchemaType as an, type PathsToStringProps as ao, type WorkflowRunState as ap, type WorkflowResumeResult as aq, createStep as ar, type ToolsInput as as, type ToolsetsInput as at, type AgentGenerateOptions as au, type AgentStreamOptions as av, TABLE_WORKFLOW_SNAPSHOT as aw, TABLE_EVALS as ax, TABLE_MESSAGES as ay, TABLE_THREADS as az, MastraMemory as b, MastraStorage as c, type TABLE_NAMES as d, type StorageThreadType as e, type MessageType as f, type StorageGetMessagesArg as g, type AgentConfig as h, type ToolExecutionContext as i, Step as j, type WorkflowOptions as k, type WorkflowRow as l, type CoreMessage as m, type CoreSystemMessage as n, type CoreAssistantMessage as o, type CoreUserMessage as p, type CoreToolMessage as q, type EmbedResult as r, type EmbedManyResult as s, type StructuredOutputType as t, type StructuredOutputArrayItem as u, type StructuredOutput as v, type StreamReturn as w, type DefaultLLMTextObjectOptions as x, type DefaultLLMStreamOptions as y, type DefaultLLMStreamObjectOptions as z };
1156
+ export { type StepNode as $, Agent as A, type BaseStructuredOutputType as B, type CoreTool as C, type DefaultLLMTextOptions as D, type EvalRow as E, type DefaultLLMTextObjectOptions as F, type GenerateReturn as G, type DefaultLLMStreamOptions as H, type DefaultLLMStreamObjectOptions as I, type LLMTextOptions as J, type LLMTextObjectOptions as K, type LanguageModel as L, Mastra as M, type LLMStreamOptions as N, type OutputType as O, type LLMInnerStreamOptions as P, type LLMStreamObjectOptions as Q, type Config as R, Step as S, type ToolAction as T, type MessageResponse as U, type VercelTool as V, Workflow as W, type MemoryConfig as X, type SharedMemoryConfig as Y, type StepAction as Z, type StepVariableType as _, type ToolsInput as a, type StepGraph as a0, type RetryConfig as a1, type VariableReference as a2, type BaseCondition as a3, type ActionContext as a4, WhenConditionReturnValue as a5, type StepDef as a6, type StepCondition as a7, type StepConfig as a8, type StepResult as a9, TABLE_WORKFLOW_SNAPSHOT as aA, TABLE_EVALS as aB, TABLE_MESSAGES as aC, TABLE_THREADS as aD, TABLE_TRACES as aE, type StepsRecord as aa, type WorkflowRunResult as ab, type WorkflowLogMessage as ac, type WorkflowEvent as ad, type ResolverFunctionInput as ae, type ResolverFunctionOutput as af, type SubscriberFunctionOutput as ag, type DependencyCheckOutput as ah, type StepResolverOutput as ai, type WorkflowActors as aj, type WorkflowActionParams as ak, type WorkflowActions as al, type WorkflowState as am, type StepId as an, type ExtractSchemaFromStep as ao, type ExtractStepResult as ap, type StepInputType as aq, type ExtractSchemaType as ar, type PathsToStringProps as as, type WorkflowRunState as at, type WorkflowResumeResult as au, createStep as av, type MastraLanguageModel as aw, type ToolsetsInput as ax, type AgentGenerateOptions as ay, type AgentStreamOptions as az, type MastraPrimitives as b, MastraMemory as c, type StepExecutionContext as d, type WorkflowContext as e, MastraStorage as f, type TABLE_NAMES as g, type StorageColumn as h, type StorageThreadType as i, type MessageType as j, type StorageGetMessagesArg as k, type AgentConfig as l, type ToolExecutionContext as m, type WorkflowOptions as n, type WorkflowRow as o, type CoreMessage as p, type CoreSystemMessage as q, type CoreAssistantMessage as r, type CoreUserMessage as s, type CoreToolMessage as t, type EmbedResult as u, type EmbedManyResult as v, type StructuredOutputType as w, type StructuredOutputArrayItem as x, type StructuredOutput as y, type StreamReturn as z };
package/dist/base.cjs CHANGED
@@ -1,145 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var stream = require('stream');
4
- var pino = require('pino');
5
- var pretty = require('pino-pretty');
3
+ var chunkIIWRJFLQ_cjs = require('./chunk-IIWRJFLQ.cjs');
6
4
 
7
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
5
 
9
- var pino__default = /*#__PURE__*/_interopDefault(pino);
10
- var pretty__default = /*#__PURE__*/_interopDefault(pretty);
11
6
 
12
- // src/logger/index.ts
13
- var RegisteredLogger = {
14
- LLM: "LLM"};
15
- var LogLevel = {
16
- INFO: "info"};
17
- var Logger = class {
18
- logger;
19
- transports;
20
- constructor(options = {}) {
21
- this.transports = options.transports || {};
22
- const transportsAry = Object.entries(this.transports);
23
- this.logger = pino__default.default(
24
- {
25
- name: options.name || "app",
26
- level: options.level || LogLevel.INFO,
27
- formatters: {
28
- level: (label) => {
29
- return {
30
- level: label
31
- };
32
- }
33
- }
34
- },
35
- options.overrideDefaultTransports ? options?.transports?.default : transportsAry.length === 0 ? pretty__default.default({
36
- colorize: true,
37
- levelFirst: true,
38
- ignore: "pid,hostname",
39
- colorizeObjects: true,
40
- translateTime: "SYS:standard",
41
- singleLine: false
42
- }) : pino__default.default.multistream([
43
- ...transportsAry.map(([_, transport]) => ({
44
- stream: transport,
45
- level: options.level || LogLevel.INFO
46
- })),
47
- {
48
- stream: pretty__default.default({
49
- colorize: true,
50
- levelFirst: true,
51
- ignore: "pid,hostname",
52
- colorizeObjects: true,
53
- translateTime: "SYS:standard",
54
- singleLine: false
55
- }),
56
- level: options.level || LogLevel.INFO
57
- }
58
- ])
59
- );
60
- }
61
- debug(message, args = {}) {
62
- this.logger.debug(args, message);
63
- }
64
- info(message, args = {}) {
65
- this.logger.info(args, message);
66
- }
67
- warn(message, args = {}) {
68
- this.logger.warn(args, message);
69
- }
70
- error(message, args = {}) {
71
- this.logger.error(args, message);
72
- }
73
- // Stream creation for process output handling
74
- createStream() {
75
- return new stream.Transform({
76
- transform: (chunk, _encoding, callback) => {
77
- const line = chunk.toString().trim();
78
- if (line) {
79
- this.info(line);
80
- }
81
- callback(null, chunk);
82
- }
83
- });
84
- }
85
- async getLogs(transportId) {
86
- if (!transportId || !this.transports[transportId]) {
87
- return [];
88
- }
89
- return this.transports[transportId].getLogs();
90
- }
91
- async getLogsByRunId({ runId, transportId }) {
92
- return this.transports[transportId]?.getLogsByRunId({ runId });
93
- }
94
- };
95
- function createLogger(options) {
96
- return new Logger(options);
97
- }
98
-
99
- // src/base.ts
100
- var MastraBase = class {
101
- component = RegisteredLogger.LLM;
102
- logger;
103
- name;
104
- telemetry;
105
- constructor({ component, name }) {
106
- this.component = component || RegisteredLogger.LLM;
107
- this.name = name;
108
- this.logger = createLogger({ name: `${this.component} - ${this.name}` });
109
- }
110
- /**
111
- * Set the logger for the agent
112
- * @param logger
113
- */
114
- __setLogger(logger) {
115
- this.logger = logger;
116
- this.logger.debug(`Logger updated [component=${this.component}] [name=${this.name}]`);
117
- }
118
- /**
119
- * Set the telemetry for the
120
- * @param telemetry
121
- */
122
- __setTelemetry(telemetry) {
123
- this.telemetry = telemetry;
124
- this.logger.debug(`Telemetry updated [component=${this.component}] [tracer=${this.telemetry.tracer}]`);
125
- }
126
- /**
127
- * Get the telemetry on the vector
128
- * @returns telemetry
129
- */
130
- __getTelemetry() {
131
- return this.telemetry;
132
- }
133
- /*
134
- get experimental_telemetry config
135
- */
136
- get experimental_telemetry() {
137
- return this.telemetry ? {
138
- // tracer: this.telemetry.tracer,
139
- tracer: this.telemetry.getBaggageTracer(),
140
- isEnabled: !!this.telemetry.tracer
141
- } : void 0;
142
- }
143
- };
144
-
145
- exports.MastraBase = MastraBase;
7
+ Object.defineProperty(exports, "MastraBase", {
8
+ enumerable: true,
9
+ get: function () { return chunkIIWRJFLQ_cjs.MastraBase; }
10
+ });