@mastra/core 0.2.0-alpha.99 → 0.2.1-alpha.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.
- package/dist/agent/index.d.ts +6 -8
- package/dist/agent/index.js +1 -7
- package/dist/{telemetry-oCUM52DG.d.ts → base-BbtPAA6f.d.ts} +50 -8
- package/dist/{index-Cwb-5AzX.d.ts → base-C7R9FwZ6.d.ts} +450 -403
- package/dist/base.d.ts +3 -43
- package/dist/base.js +1 -3
- package/dist/bundler/index.d.ts +3 -4
- package/dist/bundler/index.js +1 -4
- package/dist/{chunk-MCB4M5W4.js → chunk-22LC46YN.js} +3 -9
- package/dist/chunk-4ZRHVG25.js +402 -0
- package/dist/{chunk-KNPBNSJ7.js → chunk-55GTEVHJ.js} +13 -14
- package/dist/chunk-5HXXWLRX.js +626 -0
- package/dist/chunk-6TCTOQ3G.js +1204 -0
- package/dist/{chunk-ZJOMHCWE.js → chunk-AN562ICT.js} +98 -151
- package/dist/chunk-AWEACB2T.js +66 -0
- package/dist/chunk-BB4KXGBU.js +83 -0
- package/dist/chunk-C6A6W6XS.js +77 -0
- package/dist/{chunk-EO3TIPGQ.js → chunk-CUIUUULJ.js} +375 -254
- package/dist/chunk-HT63PEVD.js +37 -0
- package/dist/chunk-K36NSQWH.js +10 -0
- package/dist/chunk-NUDAZEOG.js +35 -0
- package/dist/{chunk-ICMEXHKD.js → chunk-O2VP5JBC.js} +48 -55
- package/dist/{chunk-42DYOLDV.js → chunk-PNZK456O.js} +13 -21
- package/dist/chunk-RG66XEJT.js +8 -0
- package/dist/chunk-SIFBBGY6.js +190 -0
- package/dist/{chunk-A7SNFYQB.js → chunk-V4WSAQOP.js} +7 -15
- package/dist/chunk-V5UMPUKC.js +218 -0
- package/dist/{chunk-DHCULRJM.js → chunk-VE4JJJSW.js} +126 -78
- package/dist/chunk-ZINPRHAN.js +22 -0
- package/dist/{chunk-C55JWGDU.js → chunk-ZJOXJFJI.js} +42 -15
- package/dist/deployer/index.d.ts +3 -5
- package/dist/deployer/index.js +1 -5
- package/dist/eval/index.d.ts +8 -13
- package/dist/eval/index.js +1 -3
- package/dist/filter/index.js +1 -2
- package/dist/hooks/index.d.ts +13 -18
- package/dist/hooks/index.js +1 -2
- package/dist/{index-CBZ2mk2H.d.ts → index-B2JCcAQt.d.ts} +1 -1
- package/dist/index.d.ts +16 -16
- package/dist/index.js +37 -67
- package/dist/integration/index.d.ts +8 -10
- package/dist/integration/index.js +1 -3
- package/dist/llm/index.d.ts +6 -8
- package/dist/llm/index.js +1 -1
- package/dist/logger/index.d.ts +1 -1
- package/dist/logger/index.js +1 -2
- package/dist/mastra/index.d.ts +23 -25
- package/dist/mastra/index.js +1 -9
- package/dist/memory/index.d.ts +8 -10
- package/dist/memory/index.js +1 -9
- package/dist/relevance/index.js +1 -8
- package/dist/storage/index.d.ts +21 -10
- package/dist/storage/index.js +3 -7
- package/dist/telemetry/index.d.ts +35 -5
- package/dist/telemetry/index.js +1 -2
- package/dist/telemetry/otel-vendor.d.ts +7 -0
- package/dist/telemetry/otel-vendor.js +7 -0
- package/dist/tools/index.d.ts +6 -8
- package/dist/tools/index.js +1 -2
- package/dist/tts/index.d.ts +2 -4
- package/dist/tts/index.js +1 -5
- package/dist/{metric-BWeQNZt6.d.ts → types-m9RryK9a.d.ts} +6 -1
- package/dist/utils.js +1 -2
- package/dist/vector/index.d.ts +4 -6
- package/dist/vector/index.js +1 -4
- package/dist/vector/libsql/index.d.ts +2 -4
- package/dist/vector/libsql/index.js +1 -6
- package/dist/{workflow-DTtv7_Eq.d.ts → workflow-7xHmmFH5.d.ts} +3 -6
- package/dist/workflows/index.d.ts +7 -9
- package/dist/workflows/index.js +1 -4
- package/package.json +22 -18
- package/dist/chunk-4LJFWC2Q.js +0 -216
- package/dist/chunk-4ZUSEHLH.js +0 -285
- package/dist/chunk-AJJZUHB4.js +0 -14
- package/dist/chunk-G4MCO7XF.js +0 -70
- package/dist/chunk-HBTQNIAX.js +0 -90
- package/dist/chunk-HPXWJBQK.js +0 -222
- package/dist/chunk-JJ57BXQR.js +0 -16
- package/dist/chunk-JP37ODNX.js +0 -36
- package/dist/chunk-K3N7KJHH.js +0 -52
- package/dist/chunk-MDM2JS2U.js +0 -1288
- package/dist/chunk-VOUPGVRD.js +0 -27
- package/dist/chunk-Z7JFMQZZ.js +0 -551
- /package/dist/{chunk-AE3H2QEY.js → chunk-ZDWFBE5L.js} +0 -0
|
@@ -1,14 +1,138 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { a as Metric } from './metric-BWeQNZt6.js';
|
|
6
|
-
import { T as Telemetry } from './telemetry-oCUM52DG.js';
|
|
1
|
+
import * as ai from 'ai';
|
|
2
|
+
import { EmbeddingModel, CoreMessage as CoreMessage$1, Message, UserContent, AssistantContent, LanguageModelV1, GenerateTextResult, GenerateObjectResult, 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, T as Telemetry } from './base-BbtPAA6f.js';
|
|
4
|
+
import { a as Metric, M as MetricResult, T as TestInfo } from './types-m9RryK9a.js';
|
|
7
5
|
import { Query } from 'sift';
|
|
8
|
-
import {
|
|
6
|
+
import { z, ZodSchema } from 'zod';
|
|
7
|
+
import { JSONSchema7 } from 'json-schema';
|
|
9
8
|
import { MastraVector } from './vector/index.js';
|
|
9
|
+
import { B as BaseLogMessage, R as RegisteredLogger, L as Logger, d as Run } from './index-B2JCcAQt.js';
|
|
10
10
|
import { MastraTTS } from './tts/index.js';
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Abstract Memory class that defines the interface for storing and retrieving
|
|
14
|
+
* conversation threads and messages.
|
|
15
|
+
*/
|
|
16
|
+
declare abstract class MastraMemory extends MastraBase {
|
|
17
|
+
MAX_CONTEXT_TOKENS?: number;
|
|
18
|
+
storage: MastraStorage;
|
|
19
|
+
vector: MastraVector;
|
|
20
|
+
embedder: EmbeddingModel<string>;
|
|
21
|
+
protected threadConfig: MemoryConfig;
|
|
22
|
+
constructor(config: {
|
|
23
|
+
name: string;
|
|
24
|
+
} & SharedMemoryConfig);
|
|
25
|
+
setStorage(storage: MastraStorage): void;
|
|
26
|
+
setVector(vector: MastraVector): void;
|
|
27
|
+
setEmbedder(embedder: EmbeddingModel<string>): void;
|
|
28
|
+
/**
|
|
29
|
+
* Get a system message to inject into the conversation.
|
|
30
|
+
* This will be called before each conversation turn.
|
|
31
|
+
* Implementations can override this to inject custom system messages.
|
|
32
|
+
*/
|
|
33
|
+
getSystemMessage(_input: {
|
|
34
|
+
threadId: string;
|
|
35
|
+
memoryConfig?: MemoryConfig;
|
|
36
|
+
}): Promise<string | null>;
|
|
37
|
+
protected createEmbeddingIndex(): Promise<{
|
|
38
|
+
indexName: string;
|
|
39
|
+
}>;
|
|
40
|
+
protected getMergedThreadConfig(config?: MemoryConfig): MemoryConfig;
|
|
41
|
+
abstract rememberMessages({ threadId, vectorMessageSearch, config, }: {
|
|
42
|
+
threadId: string;
|
|
43
|
+
vectorMessageSearch?: string;
|
|
44
|
+
config?: MemoryConfig;
|
|
45
|
+
}): Promise<{
|
|
46
|
+
messages: CoreMessage$1[];
|
|
47
|
+
uiMessages: Message[];
|
|
48
|
+
}>;
|
|
49
|
+
estimateTokens(text: string): number;
|
|
50
|
+
protected parseMessages(messages: MessageType[]): CoreMessage$1[];
|
|
51
|
+
protected convertToUIMessages(messages: MessageType[]): Message[];
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves a specific thread by its ID
|
|
54
|
+
* @param threadId - The unique identifier of the thread
|
|
55
|
+
* @returns Promise resolving to the thread or null if not found
|
|
56
|
+
*/
|
|
57
|
+
abstract getThreadById({ threadId }: {
|
|
58
|
+
threadId: string;
|
|
59
|
+
}): Promise<StorageThreadType | null>;
|
|
60
|
+
abstract getThreadsByResourceId({ resourceId }: {
|
|
61
|
+
resourceId: string;
|
|
62
|
+
}): Promise<StorageThreadType[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Saves or updates a thread
|
|
65
|
+
* @param thread - The thread data to save
|
|
66
|
+
* @returns Promise resolving to the saved thread
|
|
67
|
+
*/
|
|
68
|
+
abstract saveThread({ thread, memoryConfig, }: {
|
|
69
|
+
thread: StorageThreadType;
|
|
70
|
+
memoryConfig?: MemoryConfig;
|
|
71
|
+
}): Promise<StorageThreadType>;
|
|
72
|
+
/**
|
|
73
|
+
* Saves messages to a thread
|
|
74
|
+
* @param messages - Array of messages to save
|
|
75
|
+
* @returns Promise resolving to the saved messages
|
|
76
|
+
*/
|
|
77
|
+
abstract saveMessages({ messages, memoryConfig, }: {
|
|
78
|
+
messages: MessageType[];
|
|
79
|
+
memoryConfig: MemoryConfig | undefined;
|
|
80
|
+
}): Promise<MessageType[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Retrieves all messages for a specific thread
|
|
83
|
+
* @param threadId - The unique identifier of the thread
|
|
84
|
+
* @returns Promise resolving to array of messages and uiMessages
|
|
85
|
+
*/
|
|
86
|
+
abstract query({ threadId, selectBy, }: StorageGetMessagesArg): Promise<{
|
|
87
|
+
messages: CoreMessage$1[];
|
|
88
|
+
uiMessages: Message[];
|
|
89
|
+
}>;
|
|
90
|
+
/**
|
|
91
|
+
* Helper method to create a new thread
|
|
92
|
+
* @param title - Optional title for the thread
|
|
93
|
+
* @param metadata - Optional metadata for the thread
|
|
94
|
+
* @returns Promise resolving to the created thread
|
|
95
|
+
*/
|
|
96
|
+
createThread({ threadId, resourceId, title, metadata, memoryConfig, }: {
|
|
97
|
+
resourceId: string;
|
|
98
|
+
threadId?: string;
|
|
99
|
+
title?: string;
|
|
100
|
+
metadata?: Record<string, unknown>;
|
|
101
|
+
memoryConfig?: MemoryConfig;
|
|
102
|
+
}): Promise<StorageThreadType>;
|
|
103
|
+
/**
|
|
104
|
+
* Helper method to delete a thread
|
|
105
|
+
* @param threadId - the id of the thread to delete
|
|
106
|
+
*/
|
|
107
|
+
abstract deleteThread(threadId: string): Promise<void>;
|
|
108
|
+
/**
|
|
109
|
+
* Helper method to add a single message to a thread
|
|
110
|
+
* @param threadId - The thread to add the message to
|
|
111
|
+
* @param content - The message content
|
|
112
|
+
* @param role - The role of the message sender
|
|
113
|
+
* @param type - The type of the message
|
|
114
|
+
* @param toolNames - Optional array of tool names that were called
|
|
115
|
+
* @param toolCallArgs - Optional array of tool call arguments
|
|
116
|
+
* @param toolCallIds - Optional array of tool call ids
|
|
117
|
+
* @returns Promise resolving to the saved message
|
|
118
|
+
*/
|
|
119
|
+
addMessage({ threadId, config, content, role, type, toolNames, toolCallArgs, toolCallIds, }: {
|
|
120
|
+
threadId: string;
|
|
121
|
+
config?: MemoryConfig;
|
|
122
|
+
content: UserContent | AssistantContent;
|
|
123
|
+
role: 'user' | 'assistant';
|
|
124
|
+
type: 'text' | 'tool-call' | 'tool-result';
|
|
125
|
+
toolNames?: string[];
|
|
126
|
+
toolCallArgs?: Record<string, unknown>[];
|
|
127
|
+
toolCallIds?: string[];
|
|
128
|
+
}): Promise<MessageType>;
|
|
129
|
+
/**
|
|
130
|
+
* Generates a unique identifier
|
|
131
|
+
* @returns A unique string ID
|
|
132
|
+
*/
|
|
133
|
+
generateId(): string;
|
|
134
|
+
}
|
|
135
|
+
|
|
12
136
|
interface WorkflowOptions<TTriggerSchema extends z.ZodType<any> = any> {
|
|
13
137
|
name: string;
|
|
14
138
|
triggerSchema?: TTriggerSchema;
|
|
@@ -288,402 +412,122 @@ interface WorkflowRunState {
|
|
|
288
412
|
timestamp: number;
|
|
289
413
|
}
|
|
290
414
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
415
|
+
type MastraPrimitives = {
|
|
416
|
+
logger?: Logger;
|
|
417
|
+
telemetry?: Telemetry;
|
|
418
|
+
storage?: MastraStorage;
|
|
419
|
+
agents?: Record<string, Agent>;
|
|
420
|
+
tts?: Record<string, MastraTTS>;
|
|
421
|
+
vectors?: Record<string, MastraVector>;
|
|
422
|
+
memory?: MastraMemory;
|
|
423
|
+
};
|
|
424
|
+
interface IExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> {
|
|
425
|
+
context: TSchemaIn extends z.ZodSchema ? z.infer<TSchemaIn> & TContext : TContext;
|
|
426
|
+
runId?: string;
|
|
427
|
+
mastra?: MastraPrimitives;
|
|
428
|
+
suspend: () => Promise<void>;
|
|
299
429
|
}
|
|
300
|
-
interface
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
430
|
+
interface IAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends IExecutionContext<TSchemaIn>> {
|
|
431
|
+
id: TId;
|
|
432
|
+
description?: string;
|
|
433
|
+
inputSchema?: TSchemaIn;
|
|
434
|
+
outputSchema?: TSchemaOut;
|
|
435
|
+
mastra?: MastraPrimitives;
|
|
436
|
+
payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
|
|
437
|
+
execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
|
|
438
|
+
[key: string]: any;
|
|
306
439
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
440
|
+
|
|
441
|
+
type CoreTool = {
|
|
442
|
+
description?: string;
|
|
443
|
+
parameters: ZodSchema;
|
|
444
|
+
execute: (params: any) => Promise<any>;
|
|
445
|
+
};
|
|
446
|
+
interface ToolExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn, TContext> {
|
|
447
|
+
}
|
|
448
|
+
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> {
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
type ToolsetsInput = Record<string, Record<string, ToolAction<any, any, any, any>>>;
|
|
452
|
+
type ToolsInput = Record<string, ToolAction<any, any, any, any>>;
|
|
453
|
+
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>> {
|
|
454
|
+
name: string;
|
|
455
|
+
instructions: string;
|
|
456
|
+
model: LanguageModelV1;
|
|
457
|
+
tools?: TTools;
|
|
458
|
+
mastra?: MastraPrimitives;
|
|
459
|
+
/** @deprecated This property is deprecated. Use evals instead to add evaluation metrics. */
|
|
460
|
+
metrics?: TMetrics;
|
|
461
|
+
evals?: TMetrics;
|
|
462
|
+
memory?: MastraMemory;
|
|
463
|
+
}
|
|
464
|
+
interface AgentGenerateOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> {
|
|
465
|
+
toolsets?: ToolsetsInput;
|
|
466
|
+
resourceId?: string;
|
|
467
|
+
context?: CoreMessage[];
|
|
468
|
+
threadId?: string;
|
|
469
|
+
memoryOptions?: MemoryConfig;
|
|
470
|
+
runId?: string;
|
|
471
|
+
onStepFinish?: (step: string) => void;
|
|
472
|
+
maxSteps?: number;
|
|
473
|
+
output?: OutputType | Z;
|
|
474
|
+
temperature?: number;
|
|
475
|
+
toolChoice?: 'auto' | 'required';
|
|
476
|
+
}
|
|
477
|
+
interface AgentStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> {
|
|
478
|
+
toolsets?: ToolsetsInput;
|
|
479
|
+
resourceId?: string;
|
|
480
|
+
context?: CoreMessage[];
|
|
481
|
+
threadId?: string;
|
|
482
|
+
memoryOptions?: MemoryConfig;
|
|
483
|
+
runId?: string;
|
|
484
|
+
onFinish?: (result: string) => unknown;
|
|
485
|
+
onStepFinish?: (step: string) => unknown;
|
|
486
|
+
maxSteps?: number;
|
|
487
|
+
output?: OutputType | Z;
|
|
488
|
+
temperature?: number;
|
|
489
|
+
toolChoice?: 'auto' | 'required';
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
type LanguageModel = LanguageModelV1;
|
|
493
|
+
type CoreMessage = CoreMessage$1;
|
|
494
|
+
type CoreSystemMessage = CoreSystemMessage$1;
|
|
495
|
+
type CoreAssistantMessage = CoreAssistantMessage$1;
|
|
496
|
+
type CoreUserMessage = CoreUserMessage$1;
|
|
497
|
+
type CoreToolMessage = CoreToolMessage$1;
|
|
498
|
+
type EmbedResult<T> = EmbedResult$1<T>;
|
|
499
|
+
type EmbedManyResult<T> = EmbedManyResult$1<T>;
|
|
500
|
+
type BaseStructuredOutputType = 'string' | 'number' | 'boolean' | 'date';
|
|
501
|
+
type StructuredOutputType = 'array' | 'string' | 'number' | 'object' | 'boolean' | 'date';
|
|
502
|
+
type StructuredOutputArrayItem = {
|
|
503
|
+
type: BaseStructuredOutputType;
|
|
504
|
+
} | {
|
|
505
|
+
type: 'object';
|
|
506
|
+
items: StructuredOutput;
|
|
507
|
+
};
|
|
508
|
+
type StructuredOutput = {
|
|
509
|
+
[key: string]: {
|
|
510
|
+
type: BaseStructuredOutputType;
|
|
511
|
+
} | {
|
|
512
|
+
type: 'object';
|
|
513
|
+
items: StructuredOutput;
|
|
514
|
+
} | {
|
|
515
|
+
type: 'array';
|
|
516
|
+
items: StructuredOutputArrayItem;
|
|
317
517
|
};
|
|
318
|
-
threadConfig?: MemoryConfig;
|
|
319
518
|
};
|
|
320
|
-
type
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
static readonly TABLE_MESSAGES = "mastra_messages";
|
|
333
|
-
static readonly TABLE_THREADS = "mastra_threads";
|
|
334
|
-
hasInit: boolean;
|
|
335
|
-
constructor({ name }: {
|
|
336
|
-
name: string;
|
|
337
|
-
});
|
|
338
|
-
abstract createTable({ tableName }: {
|
|
339
|
-
tableName: TABLE_NAMES;
|
|
340
|
-
schema: Record<string, StorageColumn>;
|
|
341
|
-
}): Promise<void>;
|
|
342
|
-
abstract clearTable({ tableName }: {
|
|
343
|
-
tableName: TABLE_NAMES;
|
|
344
|
-
}): Promise<void>;
|
|
345
|
-
abstract insert({ tableName, record }: {
|
|
346
|
-
tableName: TABLE_NAMES;
|
|
347
|
-
record: Record<string, any>;
|
|
348
|
-
}): Promise<void>;
|
|
349
|
-
abstract load<R>({ tableName, keys }: {
|
|
350
|
-
tableName: TABLE_NAMES;
|
|
351
|
-
keys: Record<string, string>;
|
|
352
|
-
}): Promise<R | null>;
|
|
353
|
-
abstract getThreadById({ threadId }: {
|
|
354
|
-
threadId: string;
|
|
355
|
-
}): Promise<StorageThreadType | null>;
|
|
356
|
-
__getThreadById({ threadId }: {
|
|
357
|
-
threadId: string;
|
|
358
|
-
}): Promise<StorageThreadType | null>;
|
|
359
|
-
abstract getThreadsByResourceId({ resourceId }: {
|
|
360
|
-
resourceId: string;
|
|
361
|
-
}): Promise<StorageThreadType[]>;
|
|
362
|
-
__getThreadsByResourceId({ resourceId }: {
|
|
363
|
-
resourceId: string;
|
|
364
|
-
}): Promise<StorageThreadType[]>;
|
|
365
|
-
abstract saveThread({ thread }: {
|
|
366
|
-
thread: StorageThreadType;
|
|
367
|
-
}): Promise<StorageThreadType>;
|
|
368
|
-
__saveThread({ thread }: {
|
|
369
|
-
thread: StorageThreadType;
|
|
370
|
-
}): Promise<StorageThreadType>;
|
|
371
|
-
abstract updateThread({ id, title, metadata, }: {
|
|
372
|
-
id: string;
|
|
373
|
-
title: string;
|
|
374
|
-
metadata: Record<string, unknown>;
|
|
375
|
-
}): Promise<StorageThreadType>;
|
|
376
|
-
__updateThread({ id, title, metadata, }: {
|
|
377
|
-
id: string;
|
|
378
|
-
title: string;
|
|
379
|
-
metadata: Record<string, unknown>;
|
|
380
|
-
}): Promise<StorageThreadType>;
|
|
381
|
-
abstract deleteThread({ threadId }: {
|
|
382
|
-
threadId: string;
|
|
383
|
-
}): Promise<void>;
|
|
384
|
-
__deleteThread({ threadId }: {
|
|
385
|
-
threadId: string;
|
|
386
|
-
}): Promise<void>;
|
|
387
|
-
abstract getMessages({ threadId, selectBy, threadConfig }: StorageGetMessagesArg): Promise<MessageType[]>;
|
|
388
|
-
__getMessages({ threadId, selectBy, threadConfig }: StorageGetMessagesArg): Promise<MessageType[]>;
|
|
389
|
-
abstract saveMessages({ messages }: {
|
|
390
|
-
messages: MessageType[];
|
|
391
|
-
}): Promise<MessageType[]>;
|
|
392
|
-
__saveMessages({ messages }: {
|
|
393
|
-
messages: MessageType[];
|
|
394
|
-
}): Promise<MessageType[]>;
|
|
395
|
-
init(): Promise<void>;
|
|
396
|
-
persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
|
|
397
|
-
workflowName: string;
|
|
398
|
-
runId: string;
|
|
399
|
-
snapshot: WorkflowRunState;
|
|
400
|
-
}): Promise<void>;
|
|
401
|
-
loadWorkflowSnapshot({ workflowName, runId, }: {
|
|
402
|
-
workflowName: string;
|
|
403
|
-
runId: string;
|
|
404
|
-
}): Promise<WorkflowRunState | null>;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
type AiMessageType = Message;
|
|
408
|
-
type MessageType = {
|
|
409
|
-
id: string;
|
|
410
|
-
content: UserContent | AssistantContent | ToolContent;
|
|
411
|
-
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
412
|
-
createdAt: Date;
|
|
413
|
-
threadId: string;
|
|
414
|
-
toolCallIds?: string[];
|
|
415
|
-
toolCallArgs?: Record<string, unknown>[];
|
|
416
|
-
toolNames?: string[];
|
|
417
|
-
type: 'text' | 'tool-call' | 'tool-result';
|
|
418
|
-
};
|
|
419
|
-
type StorageThreadType = {
|
|
420
|
-
id: string;
|
|
421
|
-
title?: string;
|
|
422
|
-
resourceId: string;
|
|
423
|
-
createdAt: Date;
|
|
424
|
-
updatedAt: Date;
|
|
425
|
-
metadata?: Record<string, unknown>;
|
|
426
|
-
};
|
|
427
|
-
type MessageResponse<T extends 'raw' | 'core_message'> = {
|
|
428
|
-
raw: MessageType[];
|
|
429
|
-
core_message: CoreMessage$1[];
|
|
430
|
-
}[T];
|
|
431
|
-
type MemoryConfig = {
|
|
432
|
-
lastMessages?: number | false;
|
|
433
|
-
semanticRecall?: boolean | {
|
|
434
|
-
topK: number;
|
|
435
|
-
messageRange: number | {
|
|
436
|
-
before: number;
|
|
437
|
-
after: number;
|
|
438
|
-
};
|
|
439
|
-
};
|
|
440
|
-
workingMemory?: {
|
|
441
|
-
enabled: boolean;
|
|
442
|
-
template?: string;
|
|
443
|
-
};
|
|
444
|
-
};
|
|
445
|
-
type SharedMemoryConfig = {
|
|
446
|
-
storage?: MastraStorage;
|
|
447
|
-
options?: MemoryConfig;
|
|
448
|
-
vector?: MastraVector;
|
|
449
|
-
embedder?: EmbeddingModel<string>;
|
|
450
|
-
};
|
|
451
|
-
/**
|
|
452
|
-
* Abstract Memory class that defines the interface for storing and retrieving
|
|
453
|
-
* conversation threads and messages.
|
|
454
|
-
*/
|
|
455
|
-
declare abstract class MastraMemory extends MastraBase {
|
|
456
|
-
MAX_CONTEXT_TOKENS?: number;
|
|
457
|
-
storage: MastraStorage;
|
|
458
|
-
vector?: MastraVector;
|
|
459
|
-
embedder?: EmbeddingModel<string>;
|
|
460
|
-
protected threadConfig: MemoryConfig;
|
|
461
|
-
constructor(config: {
|
|
462
|
-
name: string;
|
|
463
|
-
} & SharedMemoryConfig);
|
|
464
|
-
/**
|
|
465
|
-
* Get a system message to inject into the conversation.
|
|
466
|
-
* This will be called before each conversation turn.
|
|
467
|
-
* Implementations can override this to inject custom system messages.
|
|
468
|
-
*/
|
|
469
|
-
getSystemMessage(_input: {
|
|
470
|
-
threadId: string;
|
|
471
|
-
memoryConfig?: MemoryConfig;
|
|
472
|
-
}): Promise<string | null>;
|
|
473
|
-
protected createEmbeddingIndex(): Promise<{
|
|
474
|
-
indexName: string;
|
|
475
|
-
}>;
|
|
476
|
-
protected getEmbedder(): EmbeddingModel<string>;
|
|
477
|
-
protected getMergedThreadConfig(config?: MemoryConfig): MemoryConfig;
|
|
478
|
-
abstract rememberMessages({ threadId, vectorMessageSearch, config, }: {
|
|
479
|
-
threadId: string;
|
|
480
|
-
vectorMessageSearch?: string;
|
|
481
|
-
config?: MemoryConfig;
|
|
482
|
-
}): Promise<{
|
|
483
|
-
messages: CoreMessage$1[];
|
|
484
|
-
uiMessages: AiMessageType[];
|
|
485
|
-
}>;
|
|
486
|
-
estimateTokens(text: string): number;
|
|
487
|
-
protected parseMessages(messages: MessageType[]): CoreMessage$1[];
|
|
488
|
-
protected convertToUIMessages(messages: MessageType[]): AiMessageType[];
|
|
489
|
-
/**
|
|
490
|
-
* Retrieves a specific thread by its ID
|
|
491
|
-
* @param threadId - The unique identifier of the thread
|
|
492
|
-
* @returns Promise resolving to the thread or null if not found
|
|
493
|
-
*/
|
|
494
|
-
abstract getThreadById({ threadId }: {
|
|
495
|
-
threadId: string;
|
|
496
|
-
}): Promise<StorageThreadType | null>;
|
|
497
|
-
abstract getThreadsByResourceId({ resourceId }: {
|
|
498
|
-
resourceId: string;
|
|
499
|
-
}): Promise<StorageThreadType[]>;
|
|
500
|
-
/**
|
|
501
|
-
* Saves or updates a thread
|
|
502
|
-
* @param thread - The thread data to save
|
|
503
|
-
* @returns Promise resolving to the saved thread
|
|
504
|
-
*/
|
|
505
|
-
abstract saveThread({ thread, memoryConfig, }: {
|
|
506
|
-
thread: StorageThreadType;
|
|
507
|
-
memoryConfig?: MemoryConfig;
|
|
508
|
-
}): Promise<StorageThreadType>;
|
|
509
|
-
/**
|
|
510
|
-
* Saves messages to a thread
|
|
511
|
-
* @param messages - Array of messages to save
|
|
512
|
-
* @returns Promise resolving to the saved messages
|
|
513
|
-
*/
|
|
514
|
-
abstract saveMessages({ messages, memoryConfig, }: {
|
|
515
|
-
messages: MessageType[];
|
|
516
|
-
memoryConfig: MemoryConfig | undefined;
|
|
517
|
-
}): Promise<MessageType[]>;
|
|
518
|
-
/**
|
|
519
|
-
* Retrieves all messages for a specific thread
|
|
520
|
-
* @param threadId - The unique identifier of the thread
|
|
521
|
-
* @returns Promise resolving to array of messages and uiMessages
|
|
522
|
-
*/
|
|
523
|
-
abstract query({ threadId, selectBy, }: StorageGetMessagesArg): Promise<{
|
|
524
|
-
messages: CoreMessage$1[];
|
|
525
|
-
uiMessages: AiMessageType[];
|
|
526
|
-
}>;
|
|
527
|
-
/**
|
|
528
|
-
* Helper method to create a new thread
|
|
529
|
-
* @param title - Optional title for the thread
|
|
530
|
-
* @param metadata - Optional metadata for the thread
|
|
531
|
-
* @returns Promise resolving to the created thread
|
|
532
|
-
*/
|
|
533
|
-
createThread({ threadId, resourceId, title, metadata, memoryConfig, }: {
|
|
534
|
-
resourceId: string;
|
|
535
|
-
threadId?: string;
|
|
536
|
-
title?: string;
|
|
537
|
-
metadata?: Record<string, unknown>;
|
|
538
|
-
memoryConfig?: MemoryConfig;
|
|
539
|
-
}): Promise<StorageThreadType>;
|
|
540
|
-
/**
|
|
541
|
-
* Helper method to delete a thread
|
|
542
|
-
* @param threadId - the id of the thread to delete
|
|
543
|
-
*/
|
|
544
|
-
abstract deleteThread(threadId: string): Promise<void>;
|
|
545
|
-
/**
|
|
546
|
-
* Helper method to add a single message to a thread
|
|
547
|
-
* @param threadId - The thread to add the message to
|
|
548
|
-
* @param content - The message content
|
|
549
|
-
* @param role - The role of the message sender
|
|
550
|
-
* @param type - The type of the message
|
|
551
|
-
* @param toolNames - Optional array of tool names that were called
|
|
552
|
-
* @param toolCallArgs - Optional array of tool call arguments
|
|
553
|
-
* @param toolCallIds - Optional array of tool call ids
|
|
554
|
-
* @returns Promise resolving to the saved message
|
|
555
|
-
*/
|
|
556
|
-
addMessage({ threadId, config, content, role, type, toolNames, toolCallArgs, toolCallIds, }: {
|
|
557
|
-
threadId: string;
|
|
558
|
-
config?: MemoryConfig;
|
|
559
|
-
content: UserContent | AssistantContent;
|
|
560
|
-
role: 'user' | 'assistant';
|
|
561
|
-
type: 'text' | 'tool-call' | 'tool-result';
|
|
562
|
-
toolNames?: string[];
|
|
563
|
-
toolCallArgs?: Record<string, unknown>[];
|
|
564
|
-
toolCallIds?: string[];
|
|
565
|
-
}): Promise<MessageType>;
|
|
566
|
-
/**
|
|
567
|
-
* Generates a unique identifier
|
|
568
|
-
* @returns A unique string ID
|
|
569
|
-
*/
|
|
570
|
-
generateId(): string;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
type MastraPrimitives = {
|
|
574
|
-
logger?: Logger;
|
|
575
|
-
telemetry?: Telemetry;
|
|
576
|
-
storage?: MastraStorage;
|
|
577
|
-
agents?: Record<string, Agent>;
|
|
578
|
-
tts?: Record<string, MastraTTS>;
|
|
579
|
-
vectors?: Record<string, MastraVector>;
|
|
580
|
-
memory?: MastraMemory;
|
|
581
|
-
};
|
|
582
|
-
interface IExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> {
|
|
583
|
-
context: TSchemaIn extends z.ZodSchema ? z.infer<TSchemaIn> & TContext : TContext;
|
|
584
|
-
runId?: string;
|
|
585
|
-
mastra?: MastraPrimitives;
|
|
586
|
-
suspend: () => Promise<void>;
|
|
587
|
-
}
|
|
588
|
-
interface IAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined, TSchemaOut extends z.ZodSchema | undefined, TContext extends IExecutionContext<TSchemaIn>> {
|
|
589
|
-
id: TId;
|
|
590
|
-
description?: string;
|
|
591
|
-
inputSchema?: TSchemaIn;
|
|
592
|
-
outputSchema?: TSchemaOut;
|
|
593
|
-
mastra?: MastraPrimitives;
|
|
594
|
-
payload?: TSchemaIn extends z.ZodSchema ? Partial<z.infer<TSchemaIn>> : unknown;
|
|
595
|
-
execute: (context: TContext) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
|
|
596
|
-
[key: string]: any;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
type CoreTool = {
|
|
600
|
-
description?: string;
|
|
601
|
-
parameters: ZodSchema;
|
|
602
|
-
execute: (params: any) => Promise<any>;
|
|
603
|
-
};
|
|
604
|
-
interface ToolExecutionContext<TSchemaIn extends z.ZodSchema | undefined = undefined, TContext extends WorkflowContext = WorkflowContext> extends IExecutionContext<TSchemaIn, TContext> {
|
|
605
|
-
}
|
|
606
|
-
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> {
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
type ToolsetsInput = Record<string, Record<string, ToolAction<any, any, any, any>>>;
|
|
610
|
-
type ToolsInput = Record<string, ToolAction<any, any, any, any>>;
|
|
611
|
-
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>> {
|
|
612
|
-
name: string;
|
|
613
|
-
instructions: string;
|
|
614
|
-
model: LanguageModelV1;
|
|
615
|
-
tools?: TTools;
|
|
616
|
-
mastra?: MastraPrimitives;
|
|
617
|
-
metrics?: TMetrics;
|
|
618
|
-
memory?: MastraMemory;
|
|
619
|
-
}
|
|
620
|
-
interface AgentGenerateOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> {
|
|
621
|
-
toolsets?: ToolsetsInput;
|
|
622
|
-
resourceId?: string;
|
|
623
|
-
context?: CoreMessage[];
|
|
624
|
-
threadId?: string;
|
|
625
|
-
memoryOptions?: MemoryConfig;
|
|
626
|
-
runId?: string;
|
|
627
|
-
onStepFinish?: (step: string) => void;
|
|
628
|
-
maxSteps?: number;
|
|
629
|
-
output?: OutputType | Z;
|
|
630
|
-
temperature?: number;
|
|
631
|
-
toolChoice?: 'auto' | 'required';
|
|
632
|
-
}
|
|
633
|
-
interface AgentStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> {
|
|
634
|
-
toolsets?: ToolsetsInput;
|
|
635
|
-
resourceId?: string;
|
|
636
|
-
context?: CoreMessage[];
|
|
637
|
-
threadId?: string;
|
|
638
|
-
memoryOptions?: MemoryConfig;
|
|
639
|
-
runId?: string;
|
|
640
|
-
onFinish?: (result: string) => Promise<void> | void;
|
|
641
|
-
onStepFinish?: (step: string) => void;
|
|
642
|
-
maxSteps?: number;
|
|
643
|
-
output?: OutputType | Z;
|
|
644
|
-
temperature?: number;
|
|
645
|
-
toolChoice?: 'auto' | 'required';
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
type LanguageModel = LanguageModelV1;
|
|
649
|
-
type CoreMessage = CoreMessage$1;
|
|
650
|
-
type CoreSystemMessage = CoreSystemMessage$1;
|
|
651
|
-
type CoreAssistantMessage = CoreAssistantMessage$1;
|
|
652
|
-
type CoreUserMessage = CoreUserMessage$1;
|
|
653
|
-
type CoreToolMessage = CoreToolMessage$1;
|
|
654
|
-
type EmbedResult<T> = EmbedResult$1<T>;
|
|
655
|
-
type EmbedManyResult<T> = EmbedManyResult$1<T>;
|
|
656
|
-
type BaseStructuredOutputType = 'string' | 'number' | 'boolean' | 'date';
|
|
657
|
-
type StructuredOutputType = 'array' | 'string' | 'number' | 'object' | 'boolean' | 'date';
|
|
658
|
-
type StructuredOutputArrayItem = {
|
|
659
|
-
type: BaseStructuredOutputType;
|
|
660
|
-
} | {
|
|
661
|
-
type: 'object';
|
|
662
|
-
items: StructuredOutput;
|
|
663
|
-
};
|
|
664
|
-
type StructuredOutput = {
|
|
665
|
-
[key: string]: {
|
|
666
|
-
type: BaseStructuredOutputType;
|
|
667
|
-
} | {
|
|
668
|
-
type: 'object';
|
|
669
|
-
items: StructuredOutput;
|
|
670
|
-
} | {
|
|
671
|
-
type: 'array';
|
|
672
|
-
items: StructuredOutputArrayItem;
|
|
673
|
-
};
|
|
674
|
-
};
|
|
675
|
-
type GenerateReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? GenerateTextResult<any, any> : GenerateObjectResult<any>;
|
|
676
|
-
type StreamReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? StreamTextResult<any, any> : StreamObjectResult<any, any, any>;
|
|
677
|
-
type OutputType = 'text' | StructuredOutput;
|
|
678
|
-
type LLMStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
679
|
-
runId?: string;
|
|
680
|
-
onFinish?: (result: string) => Promise<void> | void;
|
|
681
|
-
onStepFinish?: (step: string) => void;
|
|
682
|
-
maxSteps?: number;
|
|
683
|
-
tools?: ToolsInput;
|
|
684
|
-
convertedTools?: Record<string, CoreTool>;
|
|
685
|
-
output?: OutputType | Z;
|
|
686
|
-
temperature?: number;
|
|
519
|
+
type GenerateReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? GenerateTextResult<any, any> : GenerateObjectResult<any>;
|
|
520
|
+
type StreamReturn<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = Z extends undefined ? StreamTextResult<any, any> : StreamObjectResult<any, any, any>;
|
|
521
|
+
type OutputType = 'text' | StructuredOutput;
|
|
522
|
+
type LLMStreamOptions<Z extends ZodSchema | JSONSchema7 | undefined = undefined> = {
|
|
523
|
+
runId?: string;
|
|
524
|
+
onFinish?: (result: string) => Promise<void> | void;
|
|
525
|
+
onStepFinish?: (step: string) => void;
|
|
526
|
+
maxSteps?: number;
|
|
527
|
+
tools?: ToolsInput;
|
|
528
|
+
convertedTools?: Record<string, CoreTool>;
|
|
529
|
+
output?: OutputType | Z;
|
|
530
|
+
temperature?: number;
|
|
687
531
|
};
|
|
688
532
|
type LLMTextOptions = {
|
|
689
533
|
tools?: ToolsInput;
|
|
@@ -701,8 +545,8 @@ type LLMInnerStreamOptions = {
|
|
|
701
545
|
tools?: ToolsInput;
|
|
702
546
|
convertedTools?: Record<string, CoreTool>;
|
|
703
547
|
messages: CoreMessage[];
|
|
704
|
-
onStepFinish?: (step: string) =>
|
|
705
|
-
onFinish?: (result: string) =>
|
|
548
|
+
onStepFinish?: (step: string) => unknown;
|
|
549
|
+
onFinish?: (result: string) => unknown;
|
|
706
550
|
maxSteps?: number;
|
|
707
551
|
temperature?: number;
|
|
708
552
|
toolChoice?: 'auto' | 'required';
|
|
@@ -719,6 +563,7 @@ declare class MastraLLMBase extends MastraBase {
|
|
|
719
563
|
});
|
|
720
564
|
getProvider(): string;
|
|
721
565
|
getModelId(): string;
|
|
566
|
+
getModel(): ai.LanguageModelV1;
|
|
722
567
|
convertToMessages(messages: string | string[] | CoreMessage$1[]): CoreMessage$1[];
|
|
723
568
|
__registerPrimitives(p: MastraPrimitives): void;
|
|
724
569
|
__text(input: LLMTextOptions): Promise<GenerateTextResult<any, any>>;
|
|
@@ -736,7 +581,9 @@ declare class Agent<TTools extends Record<string, ToolAction<any, any, any, any>
|
|
|
736
581
|
instructions: string;
|
|
737
582
|
readonly model?: LanguageModelV1;
|
|
738
583
|
tools: TTools;
|
|
584
|
+
/** @deprecated This property is deprecated. Use evals instead. */
|
|
739
585
|
metrics: TMetrics;
|
|
586
|
+
evals: TMetrics;
|
|
740
587
|
constructor(config: AgentConfig<TTools, TMetrics>);
|
|
741
588
|
hasOwnMemory(): boolean;
|
|
742
589
|
getMemory(): MastraMemory | undefined;
|
|
@@ -771,7 +618,7 @@ declare class Agent<TTools extends Record<string, ToolAction<any, any, any, any>
|
|
|
771
618
|
threadId: string;
|
|
772
619
|
memoryConfig: MemoryConfig | undefined;
|
|
773
620
|
}): Promise<void>;
|
|
774
|
-
sanitizeResponseMessages(messages: Array<
|
|
621
|
+
sanitizeResponseMessages(messages: Array<CoreMessage$1>): Array<CoreMessage$1>;
|
|
775
622
|
convertTools({ toolsets, runId, }: {
|
|
776
623
|
toolsets?: ToolsetsInput;
|
|
777
624
|
threadId?: string;
|
|
@@ -813,4 +660,204 @@ declare class Agent<TTools extends Record<string, ToolAction<any, any, any, any>
|
|
|
813
660
|
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>>;
|
|
814
661
|
}
|
|
815
662
|
|
|
816
|
-
|
|
663
|
+
interface StorageColumn {
|
|
664
|
+
type: 'text' | 'timestamp' | 'uuid' | 'jsonb' | 'integer' | 'bigint';
|
|
665
|
+
primaryKey?: boolean;
|
|
666
|
+
nullable?: boolean;
|
|
667
|
+
references?: {
|
|
668
|
+
table: string;
|
|
669
|
+
column: string;
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
interface WorkflowRow {
|
|
673
|
+
workflow_name: string;
|
|
674
|
+
run_id: string;
|
|
675
|
+
snapshot: WorkflowRunState;
|
|
676
|
+
created_at: Date;
|
|
677
|
+
updated_at: Date;
|
|
678
|
+
}
|
|
679
|
+
type StorageGetMessagesArg = {
|
|
680
|
+
threadId: string;
|
|
681
|
+
selectBy?: {
|
|
682
|
+
vectorSearchString?: string;
|
|
683
|
+
last?: number | false;
|
|
684
|
+
include?: {
|
|
685
|
+
id: string;
|
|
686
|
+
withPreviousMessages?: number;
|
|
687
|
+
withNextMessages?: number;
|
|
688
|
+
}[];
|
|
689
|
+
};
|
|
690
|
+
threadConfig?: MemoryConfig;
|
|
691
|
+
};
|
|
692
|
+
type EvalRow = {
|
|
693
|
+
input: string;
|
|
694
|
+
output: string;
|
|
695
|
+
result: MetricResult;
|
|
696
|
+
agentName: string;
|
|
697
|
+
createdAt: string;
|
|
698
|
+
metricName: string;
|
|
699
|
+
instructions: string;
|
|
700
|
+
runId: string;
|
|
701
|
+
globalRunId: string;
|
|
702
|
+
testInfo?: TestInfo;
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
declare const TABLE_WORKFLOW_SNAPSHOT = "mastra_workflow_snapshot";
|
|
706
|
+
declare const TABLE_EVALS = "mastra_evals";
|
|
707
|
+
declare const TABLE_MESSAGES = "mastra_messages";
|
|
708
|
+
declare const TABLE_THREADS = "mastra_threads";
|
|
709
|
+
declare const TABLE_TRACES = "mastra_traces";
|
|
710
|
+
type TABLE_NAMES = typeof TABLE_WORKFLOW_SNAPSHOT | typeof TABLE_EVALS | typeof TABLE_MESSAGES | typeof TABLE_THREADS | typeof TABLE_TRACES;
|
|
711
|
+
|
|
712
|
+
type MessageType = {
|
|
713
|
+
id: string;
|
|
714
|
+
content: UserContent | AssistantContent | ToolContent;
|
|
715
|
+
role: 'system' | 'user' | 'assistant' | 'tool';
|
|
716
|
+
createdAt: Date;
|
|
717
|
+
threadId: string;
|
|
718
|
+
toolCallIds?: string[];
|
|
719
|
+
toolCallArgs?: Record<string, unknown>[];
|
|
720
|
+
toolNames?: string[];
|
|
721
|
+
type: 'text' | 'tool-call' | 'tool-result';
|
|
722
|
+
};
|
|
723
|
+
type StorageThreadType = {
|
|
724
|
+
id: string;
|
|
725
|
+
title?: string;
|
|
726
|
+
resourceId: string;
|
|
727
|
+
createdAt: Date;
|
|
728
|
+
updatedAt: Date;
|
|
729
|
+
metadata?: Record<string, unknown>;
|
|
730
|
+
};
|
|
731
|
+
type MessageResponse<T extends 'raw' | 'core_message'> = {
|
|
732
|
+
raw: MessageType[];
|
|
733
|
+
core_message: CoreMessage$1[];
|
|
734
|
+
}[T];
|
|
735
|
+
type MemoryConfig = {
|
|
736
|
+
lastMessages?: number | false;
|
|
737
|
+
semanticRecall?: boolean | {
|
|
738
|
+
topK: number;
|
|
739
|
+
messageRange: number | {
|
|
740
|
+
before: number;
|
|
741
|
+
after: number;
|
|
742
|
+
};
|
|
743
|
+
};
|
|
744
|
+
workingMemory?: {
|
|
745
|
+
enabled: boolean;
|
|
746
|
+
template?: string;
|
|
747
|
+
};
|
|
748
|
+
};
|
|
749
|
+
type SharedMemoryConfig = {
|
|
750
|
+
storage?: MastraStorage;
|
|
751
|
+
options?: MemoryConfig;
|
|
752
|
+
vector?: MastraVector;
|
|
753
|
+
embedder?: EmbeddingModel<string>;
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
declare abstract class MastraStorage extends MastraBase {
|
|
757
|
+
/** @deprecated import from { TABLE_WORKFLOW_SNAPSHOT } '@mastra/core/storage' instead */
|
|
758
|
+
static readonly TABLE_WORKFLOW_SNAPSHOT = "mastra_workflow_snapshot";
|
|
759
|
+
/** @deprecated import from { TABLE_EVALS } '@mastra/core/storage' instead */
|
|
760
|
+
static readonly TABLE_EVALS = "mastra_evals";
|
|
761
|
+
/** @deprecated import from { TABLE_MESSAGES } '@mastra/core/storage' instead */
|
|
762
|
+
static readonly TABLE_MESSAGES = "mastra_messages";
|
|
763
|
+
/** @deprecated import from { TABLE_THREADS } '@mastra/core/storage' instead */
|
|
764
|
+
static readonly TABLE_THREADS = "mastra_threads";
|
|
765
|
+
/** @deprecated import { TABLE_TRACES } from '@mastra/core/storage' instead */
|
|
766
|
+
static readonly TABLE_TRACES = "mastra_traces";
|
|
767
|
+
protected hasInitialized: null | Promise<boolean>;
|
|
768
|
+
constructor({ name }: {
|
|
769
|
+
name: string;
|
|
770
|
+
});
|
|
771
|
+
abstract createTable({ tableName }: {
|
|
772
|
+
tableName: TABLE_NAMES;
|
|
773
|
+
schema: Record<string, StorageColumn>;
|
|
774
|
+
}): Promise<void>;
|
|
775
|
+
abstract clearTable({ tableName }: {
|
|
776
|
+
tableName: TABLE_NAMES;
|
|
777
|
+
}): Promise<void>;
|
|
778
|
+
abstract insert({ tableName, record }: {
|
|
779
|
+
tableName: TABLE_NAMES;
|
|
780
|
+
record: Record<string, any>;
|
|
781
|
+
}): Promise<void>;
|
|
782
|
+
abstract batchInsert({ tableName, records, }: {
|
|
783
|
+
tableName: TABLE_NAMES;
|
|
784
|
+
records: Record<string, any>[];
|
|
785
|
+
}): Promise<void>;
|
|
786
|
+
__batchInsert({ tableName, records, }: {
|
|
787
|
+
tableName: TABLE_NAMES;
|
|
788
|
+
records: Record<string, any>[];
|
|
789
|
+
}): Promise<void>;
|
|
790
|
+
abstract load<R>({ tableName, keys }: {
|
|
791
|
+
tableName: TABLE_NAMES;
|
|
792
|
+
keys: Record<string, string>;
|
|
793
|
+
}): Promise<R | null>;
|
|
794
|
+
abstract getThreadById({ threadId }: {
|
|
795
|
+
threadId: string;
|
|
796
|
+
}): Promise<StorageThreadType | null>;
|
|
797
|
+
__getThreadById({ threadId }: {
|
|
798
|
+
threadId: string;
|
|
799
|
+
}): Promise<StorageThreadType | null>;
|
|
800
|
+
abstract getThreadsByResourceId({ resourceId }: {
|
|
801
|
+
resourceId: string;
|
|
802
|
+
}): Promise<StorageThreadType[]>;
|
|
803
|
+
__getThreadsByResourceId({ resourceId }: {
|
|
804
|
+
resourceId: string;
|
|
805
|
+
}): Promise<StorageThreadType[]>;
|
|
806
|
+
abstract saveThread({ thread }: {
|
|
807
|
+
thread: StorageThreadType;
|
|
808
|
+
}): Promise<StorageThreadType>;
|
|
809
|
+
__saveThread({ thread }: {
|
|
810
|
+
thread: StorageThreadType;
|
|
811
|
+
}): Promise<StorageThreadType>;
|
|
812
|
+
abstract updateThread({ id, title, metadata, }: {
|
|
813
|
+
id: string;
|
|
814
|
+
title: string;
|
|
815
|
+
metadata: Record<string, unknown>;
|
|
816
|
+
}): Promise<StorageThreadType>;
|
|
817
|
+
__updateThread({ id, title, metadata, }: {
|
|
818
|
+
id: string;
|
|
819
|
+
title: string;
|
|
820
|
+
metadata: Record<string, unknown>;
|
|
821
|
+
}): Promise<StorageThreadType>;
|
|
822
|
+
abstract deleteThread({ threadId }: {
|
|
823
|
+
threadId: string;
|
|
824
|
+
}): Promise<void>;
|
|
825
|
+
__deleteThread({ threadId }: {
|
|
826
|
+
threadId: string;
|
|
827
|
+
}): Promise<void>;
|
|
828
|
+
abstract getMessages({ threadId, selectBy, threadConfig }: StorageGetMessagesArg): Promise<MessageType[]>;
|
|
829
|
+
__getMessages({ threadId, selectBy, threadConfig }: StorageGetMessagesArg): Promise<MessageType[]>;
|
|
830
|
+
abstract saveMessages({ messages }: {
|
|
831
|
+
messages: MessageType[];
|
|
832
|
+
}): Promise<MessageType[]>;
|
|
833
|
+
__saveMessages({ messages }: {
|
|
834
|
+
messages: MessageType[];
|
|
835
|
+
}): Promise<MessageType[]>;
|
|
836
|
+
abstract getTraces({ name, scope, page, perPage, attributes, }: {
|
|
837
|
+
name?: string;
|
|
838
|
+
scope?: string;
|
|
839
|
+
page: number;
|
|
840
|
+
perPage: number;
|
|
841
|
+
attributes?: Record<string, string>;
|
|
842
|
+
}): Promise<any[]>;
|
|
843
|
+
__getTraces({ scope, page, perPage, attributes, }: {
|
|
844
|
+
scope?: string;
|
|
845
|
+
page: number;
|
|
846
|
+
perPage: number;
|
|
847
|
+
attributes?: Record<string, string>;
|
|
848
|
+
}): Promise<any[]>;
|
|
849
|
+
init(): Promise<void>;
|
|
850
|
+
persistWorkflowSnapshot({ workflowName, runId, snapshot, }: {
|
|
851
|
+
workflowName: string;
|
|
852
|
+
runId: string;
|
|
853
|
+
snapshot: WorkflowRunState;
|
|
854
|
+
}): Promise<void>;
|
|
855
|
+
loadWorkflowSnapshot({ workflowName, runId, }: {
|
|
856
|
+
workflowName: string;
|
|
857
|
+
runId: string;
|
|
858
|
+
}): Promise<WorkflowRunState | null>;
|
|
859
|
+
abstract getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
|
|
860
|
+
__getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
export { type WorkflowContext as $, Agent as A, type BaseStructuredOutputType as B, type CoreMessage as C, type LLMInnerStreamOptions as D, type EvalRow as E, type LLMStreamObjectOptions as F, type GenerateReturn as G, type MessageType as H, type IAction as I, type StorageThreadType as J, type MessageResponse as K, type LanguageModel as L, MastraMemory as M, type MemoryConfig as N, type OutputType as O, type SharedMemoryConfig as P, type CoreTool as Q, type RetryConfig as R, type StepExecutionContext as S, type ToolAction as T, type StepNode as U, type VariableReference as V, type WorkflowOptions as W, type BaseCondition as X, type ActionContext as Y, type StepDef as Z, type StepCondition as _, MastraStorage as a, type WorkflowLogMessage as a0, type WorkflowEvent as a1, type ResolverFunctionInput as a2, type ResolverFunctionOutput as a3, type SubscriberFunctionOutput as a4, type DependencyCheckOutput as a5, type WorkflowActors as a6, type WorkflowActionParams as a7, type WorkflowActions as a8, type WorkflowState as a9, type StepId as aa, type ExtractSchemaFromStep as ab, type ExtractStepResult as ac, type StepInputType as ad, type ExtractSchemaType as ae, type PathsToStringProps as af, type TABLE_NAMES as ag, TABLE_WORKFLOW_SNAPSHOT as ah, TABLE_EVALS as ai, TABLE_MESSAGES as aj, TABLE_THREADS as ak, TABLE_TRACES as al, 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 StorageColumn as k, type WorkflowRow as l, type StorageGetMessagesArg 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 LLMStreamOptions as x, type LLMTextOptions as y, type LLMTextObjectOptions as z };
|