@mastra/core 0.10.10 → 0.10.11-alpha.1
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.cjs +4 -4
- package/dist/agent/index.d.cts +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.js +2 -2
- package/dist/{base-D6PagN3X.d.ts → base-CDtRsAmk.d.ts} +113 -14
- package/dist/{base-Bu9IeyHt.d.cts → base-WzKVgsC3.d.cts} +113 -14
- package/dist/{chunk-RL7RV3SN.cjs → chunk-CVOB5DQ2.cjs} +2 -2
- package/dist/{chunk-2H5YEBCO.js → chunk-DPPWAOCI.js} +5 -0
- package/dist/{chunk-LYF7XPUM.cjs → chunk-GCB3FMQA.cjs} +289 -36
- package/dist/{chunk-UPIUWMJV.cjs → chunk-KEQ2YD65.cjs} +2 -2
- package/dist/{chunk-3YFMBYQ2.js → chunk-LILRY4UH.js} +125 -19
- package/dist/{chunk-YNUNDIES.cjs → chunk-N2LZKFEP.cjs} +5 -0
- package/dist/{chunk-VXYIQRX4.js → chunk-OEYYMXRD.js} +1 -1
- package/dist/{chunk-XC44YAIK.js → chunk-QA6VZ6JZ.js} +1 -1
- package/dist/{chunk-26QYW6NW.cjs → chunk-RLK4L7YK.cjs} +126 -20
- package/dist/{chunk-377IVDXZ.js → chunk-W3OZTB37.js} +280 -27
- package/dist/eval/index.d.cts +1 -1
- package/dist/eval/index.d.ts +1 -1
- package/dist/index.cjs +20 -20
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/integration/index.d.cts +1 -1
- package/dist/integration/index.d.ts +1 -1
- package/dist/llm/index.d.cts +1 -1
- package/dist/llm/index.d.ts +1 -1
- package/dist/mastra/index.d.cts +1 -1
- package/dist/mastra/index.d.ts +1 -1
- package/dist/mcp/index.d.cts +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/memory/index.cjs +4 -4
- package/dist/memory/index.d.cts +1 -1
- package/dist/memory/index.d.ts +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/network/index.cjs +2 -2
- package/dist/network/index.d.cts +1 -1
- package/dist/network/index.d.ts +1 -1
- package/dist/network/index.js +1 -1
- package/dist/network/vNext/index.cjs +13 -13
- package/dist/network/vNext/index.d.cts +1 -1
- package/dist/network/vNext/index.d.ts +1 -1
- package/dist/network/vNext/index.js +2 -2
- package/dist/relevance/index.cjs +4 -4
- package/dist/relevance/index.d.cts +1 -1
- package/dist/relevance/index.d.ts +1 -1
- package/dist/relevance/index.js +1 -1
- package/dist/server/index.d.cts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/storage/index.cjs +2 -2
- package/dist/storage/index.d.cts +2 -2
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.js +1 -1
- package/dist/telemetry/index.d.cts +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/tools/index.d.cts +2 -2
- package/dist/tools/index.d.ts +2 -2
- package/dist/utils.d.cts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/voice/index.d.cts +1 -1
- package/dist/voice/index.d.ts +1 -1
- package/dist/workflows/index.cjs +10 -10
- package/dist/workflows/index.d.cts +49 -5
- package/dist/workflows/index.d.ts +49 -5
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/legacy/index.cjs +22 -22
- package/dist/workflows/legacy/index.d.cts +2 -2
- package/dist/workflows/legacy/index.d.ts +2 -2
- package/dist/workflows/legacy/index.js +1 -1
- package/package.json +2 -2
package/dist/agent/index.cjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkGCB3FMQA_cjs = require('../chunk-GCB3FMQA.cjs');
|
|
4
|
+
var chunkN2LZKFEP_cjs = require('../chunk-N2LZKFEP.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "Agent", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkGCB3FMQA_cjs.Agent; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "MessageList", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkN2LZKFEP_cjs.MessageList; }
|
|
15
15
|
});
|
package/dist/agent/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Message as AiMessageType } from 'ai';
|
|
2
2
|
import 'json-schema';
|
|
3
3
|
import 'zod';
|
|
4
|
-
export { A as Agent, av as AgentConfig, c6 as AgentGenerateOptions, c5 as AgentMemoryOption, c7 as AgentStreamOptions, aZ as DynamicArgument, aY as MastraLanguageModel, c8 as MastraMessageContentV2, t as MastraMessageV2, c3 as MessageList, T as ToolsInput, c4 as ToolsetsInput } from '../base-
|
|
4
|
+
export { A as Agent, av as AgentConfig, c6 as AgentGenerateOptions, c5 as AgentMemoryOption, c7 as AgentStreamOptions, aZ as DynamicArgument, aY as MastraLanguageModel, c8 as MastraMessageContentV2, t as MastraMessageV2, c3 as MessageList, T as ToolsInput, c4 as ToolsetsInput } from '../base-WzKVgsC3.cjs';
|
|
5
5
|
import '../base-B_y9sMg0.cjs';
|
|
6
6
|
import '../types-Bo1uigWx.cjs';
|
|
7
7
|
import '../runtime-context/index.cjs';
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Message as AiMessageType } from 'ai';
|
|
2
2
|
import 'json-schema';
|
|
3
3
|
import 'zod';
|
|
4
|
-
export { A as Agent, av as AgentConfig, c6 as AgentGenerateOptions, c5 as AgentMemoryOption, c7 as AgentStreamOptions, aZ as DynamicArgument, aY as MastraLanguageModel, c8 as MastraMessageContentV2, t as MastraMessageV2, c3 as MessageList, T as ToolsInput, c4 as ToolsetsInput } from '../base-
|
|
4
|
+
export { A as Agent, av as AgentConfig, c6 as AgentGenerateOptions, c5 as AgentMemoryOption, c7 as AgentStreamOptions, aZ as DynamicArgument, aY as MastraLanguageModel, c8 as MastraMessageContentV2, t as MastraMessageV2, c3 as MessageList, T as ToolsInput, c4 as ToolsetsInput } from '../base-CDtRsAmk.js';
|
|
5
5
|
import '../base-ClrXcCRx.js';
|
|
6
6
|
import '../types-Bo1uigWx.js';
|
|
7
7
|
import '../runtime-context/index.js';
|
package/dist/agent/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Agent } from '../chunk-
|
|
2
|
-
export { MessageList } from '../chunk-
|
|
1
|
+
export { Agent } from '../chunk-W3OZTB37.js';
|
|
2
|
+
export { MessageList } from '../chunk-DPPWAOCI.js';
|
|
@@ -1326,9 +1326,9 @@ interface WorkflowRunState {
|
|
|
1326
1326
|
/**
|
|
1327
1327
|
* Represents an execution graph for a workflow
|
|
1328
1328
|
*/
|
|
1329
|
-
interface ExecutionGraph {
|
|
1329
|
+
interface ExecutionGraph<TEngineType = any> {
|
|
1330
1330
|
id: string;
|
|
1331
|
-
steps: StepFlowEntry[];
|
|
1331
|
+
steps: StepFlowEntry<TEngineType>[];
|
|
1332
1332
|
}
|
|
1333
1333
|
/**
|
|
1334
1334
|
* Execution engine abstract class for building and executing workflow graphs
|
|
@@ -1375,11 +1375,13 @@ type StepFlowEntry<TEngineType = DefaultEngineType> = {
|
|
|
1375
1375
|
} | {
|
|
1376
1376
|
type: 'sleep';
|
|
1377
1377
|
id: string;
|
|
1378
|
-
duration
|
|
1378
|
+
duration?: number;
|
|
1379
|
+
fn?: ExecuteFunction<any, any, any, any, TEngineType>;
|
|
1379
1380
|
} | {
|
|
1380
1381
|
type: 'sleepUntil';
|
|
1381
1382
|
id: string;
|
|
1382
|
-
date
|
|
1383
|
+
date?: Date;
|
|
1384
|
+
fn?: ExecuteFunction<any, any, any, any, TEngineType>;
|
|
1383
1385
|
} | {
|
|
1384
1386
|
type: 'waitForEvent';
|
|
1385
1387
|
event: string;
|
|
@@ -1423,11 +1425,13 @@ type SerializedStepFlowEntry = {
|
|
|
1423
1425
|
} | {
|
|
1424
1426
|
type: 'sleep';
|
|
1425
1427
|
id: string;
|
|
1426
|
-
duration
|
|
1428
|
+
duration?: number;
|
|
1429
|
+
fn?: string;
|
|
1427
1430
|
} | {
|
|
1428
1431
|
type: 'sleepUntil';
|
|
1429
1432
|
id: string;
|
|
1430
|
-
date
|
|
1433
|
+
date?: Date;
|
|
1434
|
+
fn?: string;
|
|
1431
1435
|
} | {
|
|
1432
1436
|
type: 'waitForEvent';
|
|
1433
1437
|
event: string;
|
|
@@ -1552,7 +1556,7 @@ declare class Workflow<TEngineType = any, TSteps extends Step<string, any, any,
|
|
|
1552
1556
|
outputSchema: TOutput;
|
|
1553
1557
|
steps: Record<string, StepWithComponent>;
|
|
1554
1558
|
stepDefs?: TSteps;
|
|
1555
|
-
protected stepFlow: StepFlowEntry[];
|
|
1559
|
+
protected stepFlow: StepFlowEntry<TEngineType>[];
|
|
1556
1560
|
protected serializedStepFlow: SerializedStepFlowEntry[];
|
|
1557
1561
|
protected executionEngine: ExecutionEngine;
|
|
1558
1562
|
protected executionGraph: ExecutionGraph;
|
|
@@ -1565,7 +1569,7 @@ declare class Workflow<TEngineType = any, TSteps extends Step<string, any, any,
|
|
|
1565
1569
|
get mastra(): Mastra<Record<string, Agent<any, ToolsInput, Record<string, Metric>>>, Record<string, LegacyWorkflow<LegacyStep<string, any, any, StepExecutionContext<any, WorkflowContext<any, LegacyStep<string, any, any, any>[], Record<string, any>>>>[], string, any, any>>, Record<string, Workflow<any, Step<string, any, any, any, any, any>[], string, z.ZodType<any, z.ZodTypeDef, any>, z.ZodType<any, z.ZodTypeDef, any>, z.ZodType<any, z.ZodTypeDef, any>>>, Record<string, MastraVector<VectorFilter>>, Record<string, MastraTTS>, IMastraLogger, Record<string, AgentNetwork>, Record<string, NewAgentNetwork>, Record<string, MCPServerBase>> | undefined;
|
|
1566
1570
|
__registerMastra(mastra: Mastra): void;
|
|
1567
1571
|
__registerPrimitives(p: MastraPrimitives): void;
|
|
1568
|
-
setStepFlow(stepFlow: StepFlowEntry[]): void;
|
|
1572
|
+
setStepFlow(stepFlow: StepFlowEntry<TEngineType>[]): void;
|
|
1569
1573
|
/**
|
|
1570
1574
|
* Adds a step to the workflow
|
|
1571
1575
|
* @param step The step to add to the workflow
|
|
@@ -1577,13 +1581,13 @@ declare class Workflow<TEngineType = any, TSteps extends Step<string, any, any,
|
|
|
1577
1581
|
* @param duration The duration to sleep for
|
|
1578
1582
|
* @returns The workflow instance for chaining
|
|
1579
1583
|
*/
|
|
1580
|
-
sleep(duration: number): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema>;
|
|
1584
|
+
sleep(duration: number | ExecuteFunction<z.infer<TPrevSchema>, number, any, any, TEngineType>): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema>;
|
|
1581
1585
|
/**
|
|
1582
1586
|
* Adds a sleep until step to the workflow
|
|
1583
1587
|
* @param date The date to sleep until
|
|
1584
1588
|
* @returns The workflow instance for chaining
|
|
1585
1589
|
*/
|
|
1586
|
-
sleepUntil(date: Date): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema>;
|
|
1590
|
+
sleepUntil(date: Date | ExecuteFunction<z.infer<TPrevSchema>, Date, any, any, TEngineType>): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema>;
|
|
1587
1591
|
waitForEvent<TStepInputSchema extends TPrevSchema, TStepId extends string, TSchemaOut extends z.ZodType<any>>(event: string, step: Step<TStepId, TStepInputSchema, TSchemaOut, any, any, TEngineType>, opts?: {
|
|
1588
1592
|
timeout?: number;
|
|
1589
1593
|
}): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TSchemaOut>;
|
|
@@ -1623,7 +1627,7 @@ declare class Workflow<TEngineType = any, TSteps extends Step<string, any, any,
|
|
|
1623
1627
|
* @returns A built workflow instance ready for execution
|
|
1624
1628
|
*/
|
|
1625
1629
|
commit(): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TOutput>;
|
|
1626
|
-
get stepGraph(): StepFlowEntry<
|
|
1630
|
+
get stepGraph(): StepFlowEntry<TEngineType>[];
|
|
1627
1631
|
get serializedStepGraph(): SerializedStepFlowEntry[];
|
|
1628
1632
|
/**
|
|
1629
1633
|
* Creates a new workflow run instance
|
|
@@ -1926,6 +1930,7 @@ type MemoryConfig = {
|
|
|
1926
1930
|
threads?: {
|
|
1927
1931
|
generateTitle?: boolean | {
|
|
1928
1932
|
model: DynamicArgument<MastraLanguageModel>;
|
|
1933
|
+
instructions?: DynamicArgument<string>;
|
|
1929
1934
|
};
|
|
1930
1935
|
};
|
|
1931
1936
|
};
|
|
@@ -2025,6 +2030,7 @@ declare class MessageList {
|
|
|
2025
2030
|
private input;
|
|
2026
2031
|
private response;
|
|
2027
2032
|
drainUnsavedMessages(): MastraMessageV2[];
|
|
2033
|
+
getEarliestUnsavedMessageTimestamp(): number | undefined;
|
|
2028
2034
|
getSystemMessages(tag?: string): CoreMessage$1[];
|
|
2029
2035
|
addSystem(messages: CoreSystemMessage$1 | CoreSystemMessage$1[] | string | string[] | null, tag?: string): this;
|
|
2030
2036
|
private convertToCoreMessages;
|
|
@@ -2633,6 +2639,11 @@ type AgentGenerateOptions<OUTPUT extends ZodSchema | JSONSchema7 | undefined = u
|
|
|
2633
2639
|
telemetry?: TelemetrySettings;
|
|
2634
2640
|
/** RuntimeContext for dependency injection */
|
|
2635
2641
|
runtimeContext?: RuntimeContext;
|
|
2642
|
+
/**
|
|
2643
|
+
* Whether to save messages incrementally on step finish
|
|
2644
|
+
* @default false
|
|
2645
|
+
*/
|
|
2646
|
+
savePerStep?: boolean;
|
|
2636
2647
|
} & ({
|
|
2637
2648
|
/**
|
|
2638
2649
|
* @deprecated Use the `memory` property instead for all memory-related options.
|
|
@@ -2694,6 +2705,11 @@ type AgentStreamOptions<OUTPUT extends ZodSchema | JSONSchema7 | undefined = und
|
|
|
2694
2705
|
telemetry?: TelemetrySettings;
|
|
2695
2706
|
/** RuntimeContext for dependency injection */
|
|
2696
2707
|
runtimeContext?: RuntimeContext;
|
|
2708
|
+
/**
|
|
2709
|
+
* Whether to save messages incrementally on step finish
|
|
2710
|
+
* @default false
|
|
2711
|
+
*/
|
|
2712
|
+
savePerStep?: boolean;
|
|
2697
2713
|
} & ({
|
|
2698
2714
|
/**
|
|
2699
2715
|
* @deprecated Use the `memory` property instead for all memory-related options.
|
|
@@ -3661,6 +3677,70 @@ interface IAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined,
|
|
|
3661
3677
|
execute?: (context: TContext, options?: TOptions) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
|
|
3662
3678
|
}
|
|
3663
3679
|
|
|
3680
|
+
declare class SaveQueueManager {
|
|
3681
|
+
private logger?;
|
|
3682
|
+
private debounceMs;
|
|
3683
|
+
private memory?;
|
|
3684
|
+
private static MAX_STALENESS_MS;
|
|
3685
|
+
constructor({ logger, debounceMs, memory }: {
|
|
3686
|
+
logger?: IMastraLogger;
|
|
3687
|
+
debounceMs?: number;
|
|
3688
|
+
memory?: MastraMemory;
|
|
3689
|
+
});
|
|
3690
|
+
private saveQueues;
|
|
3691
|
+
private saveDebounceTimers;
|
|
3692
|
+
/**
|
|
3693
|
+
* Debounces save operations for a thread, ensuring that consecutive save requests
|
|
3694
|
+
* are batched and only the latest is executed after a short delay.
|
|
3695
|
+
* @param threadId - The ID of the thread to debounce saves for.
|
|
3696
|
+
* @param saveFn - The save function to debounce.
|
|
3697
|
+
*/
|
|
3698
|
+
private debounceSave;
|
|
3699
|
+
/**
|
|
3700
|
+
* Enqueues a save operation for a thread, ensuring that saves are executed in order and
|
|
3701
|
+
* only one save runs at a time per thread. If a save is already in progress for the thread,
|
|
3702
|
+
* the new save is queued to run after the previous completes.
|
|
3703
|
+
*
|
|
3704
|
+
* @param threadId - The ID of the thread whose messages should be saved.
|
|
3705
|
+
* @param messageList - The MessageList instance containing unsaved messages.
|
|
3706
|
+
* @param memoryConfig - Optional memory configuration to use for saving.
|
|
3707
|
+
*/
|
|
3708
|
+
private enqueueSave;
|
|
3709
|
+
/**
|
|
3710
|
+
* Clears any pending debounced save for a thread, preventing the scheduled save
|
|
3711
|
+
* from executing if it hasn't already fired.
|
|
3712
|
+
*
|
|
3713
|
+
* @param threadId - The ID of the thread whose debounced save should be cleared.
|
|
3714
|
+
*/
|
|
3715
|
+
clearDebounce(threadId: string): void;
|
|
3716
|
+
/**
|
|
3717
|
+
* Persists any unsaved messages from the MessageList to memory storage.
|
|
3718
|
+
* Drains the list of unsaved messages and writes them using the memory backend.
|
|
3719
|
+
* @param messageList - The MessageList instance for the current thread.
|
|
3720
|
+
* @param memoryConfig - The memory configuration for saving.
|
|
3721
|
+
*/
|
|
3722
|
+
private persistUnsavedMessages;
|
|
3723
|
+
/**
|
|
3724
|
+
* Batches a save of unsaved messages for a thread, using debouncing to batch rapid updates.
|
|
3725
|
+
* If the oldest unsaved message is stale (older than MAX_STALENESS_MS), the save is performed immediately.
|
|
3726
|
+
* Otherwise, the save is delayed to batch multiple updates and reduce redundant writes.
|
|
3727
|
+
*
|
|
3728
|
+
* @param messageList - The MessageList instance containing unsaved messages.
|
|
3729
|
+
* @param threadId - The ID of the thread whose messages are being saved.
|
|
3730
|
+
* @param memoryConfig - Optional memory configuration for saving.
|
|
3731
|
+
*/
|
|
3732
|
+
batchMessages(messageList: MessageList, threadId?: string, memoryConfig?: MemoryConfig): Promise<void>;
|
|
3733
|
+
/**
|
|
3734
|
+
* Forces an immediate save of unsaved messages for a thread, bypassing any debounce delay.
|
|
3735
|
+
* This is used when a flush to persistent storage is required (e.g., on shutdown or critical transitions).
|
|
3736
|
+
*
|
|
3737
|
+
* @param messageList - The MessageList instance containing unsaved messages.
|
|
3738
|
+
* @param threadId - The ID of the thread whose messages are being saved.
|
|
3739
|
+
* @param memoryConfig - Optional memory configuration for saving.
|
|
3740
|
+
*/
|
|
3741
|
+
flushMessages(messageList: MessageList, threadId?: string, memoryConfig?: MemoryConfig): Promise<void>;
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3664
3744
|
type IDGenerator = () => string;
|
|
3665
3745
|
declare class Agent<TAgentId extends string = string, TTools extends ToolsInput = ToolsInput, TMetrics extends Record<string, Metric> = Record<string, Metric>> extends MastraBase {
|
|
3666
3746
|
#private;
|
|
@@ -3721,13 +3801,14 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
3721
3801
|
* @param tools
|
|
3722
3802
|
*/
|
|
3723
3803
|
__setTools(tools: TTools): void;
|
|
3724
|
-
generateTitleFromUserMessage({ message, runtimeContext, model, }: {
|
|
3804
|
+
generateTitleFromUserMessage({ message, runtimeContext, model, instructions, }: {
|
|
3725
3805
|
message: string | MessageInput;
|
|
3726
3806
|
runtimeContext?: RuntimeContext;
|
|
3727
3807
|
model?: DynamicArgument<MastraLanguageModel>;
|
|
3808
|
+
instructions?: DynamicArgument<string>;
|
|
3728
3809
|
}): Promise<string>;
|
|
3729
3810
|
getMostRecentUserMessage(messages: Array<UIMessage>): UIMessage | undefined;
|
|
3730
|
-
genTitle(userMessage: string | MessageInput | undefined, runtimeContext: RuntimeContext, model?: DynamicArgument<MastraLanguageModel>): Promise<string | undefined>;
|
|
3811
|
+
genTitle(userMessage: string | MessageInput | undefined, runtimeContext: RuntimeContext, model?: DynamicArgument<MastraLanguageModel>, instructions?: DynamicArgument<string>): Promise<string | undefined>;
|
|
3731
3812
|
fetchMemory({ threadId, thread: passedThread, memoryConfig, resourceId, runId, userMessages, systemMessage, messageList, }: {
|
|
3732
3813
|
resourceId: string;
|
|
3733
3814
|
threadId: string;
|
|
@@ -3747,7 +3828,19 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
3747
3828
|
private getClientTools;
|
|
3748
3829
|
private getWorkflowTools;
|
|
3749
3830
|
private convertTools;
|
|
3750
|
-
|
|
3831
|
+
/**
|
|
3832
|
+
* Adds response messages from a step to the MessageList and schedules persistence.
|
|
3833
|
+
* This is used for incremental saving: after each agent step, messages are added to a save queue
|
|
3834
|
+
* and a debounced save operation is triggered to avoid redundant writes.
|
|
3835
|
+
*
|
|
3836
|
+
* @param result - The step result containing response messages.
|
|
3837
|
+
* @param messageList - The MessageList instance for the current thread.
|
|
3838
|
+
* @param threadId - The thread ID.
|
|
3839
|
+
* @param memoryConfig - The memory configuration for saving.
|
|
3840
|
+
* @param runId - (Optional) The run ID for logging.
|
|
3841
|
+
*/
|
|
3842
|
+
private saveStepMessages;
|
|
3843
|
+
__primitive({ instructions, messages, context, thread, memoryConfig, resourceId, runId, toolsets, clientTools, runtimeContext, generateMessageId, saveQueueManager, }: {
|
|
3751
3844
|
instructions?: string;
|
|
3752
3845
|
toolsets?: ToolsetsInput;
|
|
3753
3846
|
clientTools?: ToolsInput;
|
|
@@ -3761,6 +3854,7 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
3761
3854
|
messages: string | string[] | CoreMessage$1[] | Message[];
|
|
3762
3855
|
runtimeContext: RuntimeContext;
|
|
3763
3856
|
generateMessageId: undefined | IDGenerator;
|
|
3857
|
+
saveQueueManager: SaveQueueManager;
|
|
3764
3858
|
}): {
|
|
3765
3859
|
before: () => Promise<{
|
|
3766
3860
|
messageObjects: CoreMessage$1[];
|
|
@@ -3851,6 +3945,11 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
3851
3945
|
* @private
|
|
3852
3946
|
*/
|
|
3853
3947
|
private resolveTitleGenerationConfig;
|
|
3948
|
+
/**
|
|
3949
|
+
* Resolves title generation instructions, handling both static strings and dynamic functions
|
|
3950
|
+
* @private
|
|
3951
|
+
*/
|
|
3952
|
+
private resolveTitleInstructions;
|
|
3854
3953
|
}
|
|
3855
3954
|
|
|
3856
3955
|
declare abstract class MastraStorage extends MastraBase {
|
|
@@ -1326,9 +1326,9 @@ interface WorkflowRunState {
|
|
|
1326
1326
|
/**
|
|
1327
1327
|
* Represents an execution graph for a workflow
|
|
1328
1328
|
*/
|
|
1329
|
-
interface ExecutionGraph {
|
|
1329
|
+
interface ExecutionGraph<TEngineType = any> {
|
|
1330
1330
|
id: string;
|
|
1331
|
-
steps: StepFlowEntry[];
|
|
1331
|
+
steps: StepFlowEntry<TEngineType>[];
|
|
1332
1332
|
}
|
|
1333
1333
|
/**
|
|
1334
1334
|
* Execution engine abstract class for building and executing workflow graphs
|
|
@@ -1375,11 +1375,13 @@ type StepFlowEntry<TEngineType = DefaultEngineType> = {
|
|
|
1375
1375
|
} | {
|
|
1376
1376
|
type: 'sleep';
|
|
1377
1377
|
id: string;
|
|
1378
|
-
duration
|
|
1378
|
+
duration?: number;
|
|
1379
|
+
fn?: ExecuteFunction<any, any, any, any, TEngineType>;
|
|
1379
1380
|
} | {
|
|
1380
1381
|
type: 'sleepUntil';
|
|
1381
1382
|
id: string;
|
|
1382
|
-
date
|
|
1383
|
+
date?: Date;
|
|
1384
|
+
fn?: ExecuteFunction<any, any, any, any, TEngineType>;
|
|
1383
1385
|
} | {
|
|
1384
1386
|
type: 'waitForEvent';
|
|
1385
1387
|
event: string;
|
|
@@ -1423,11 +1425,13 @@ type SerializedStepFlowEntry = {
|
|
|
1423
1425
|
} | {
|
|
1424
1426
|
type: 'sleep';
|
|
1425
1427
|
id: string;
|
|
1426
|
-
duration
|
|
1428
|
+
duration?: number;
|
|
1429
|
+
fn?: string;
|
|
1427
1430
|
} | {
|
|
1428
1431
|
type: 'sleepUntil';
|
|
1429
1432
|
id: string;
|
|
1430
|
-
date
|
|
1433
|
+
date?: Date;
|
|
1434
|
+
fn?: string;
|
|
1431
1435
|
} | {
|
|
1432
1436
|
type: 'waitForEvent';
|
|
1433
1437
|
event: string;
|
|
@@ -1552,7 +1556,7 @@ declare class Workflow<TEngineType = any, TSteps extends Step<string, any, any,
|
|
|
1552
1556
|
outputSchema: TOutput;
|
|
1553
1557
|
steps: Record<string, StepWithComponent>;
|
|
1554
1558
|
stepDefs?: TSteps;
|
|
1555
|
-
protected stepFlow: StepFlowEntry[];
|
|
1559
|
+
protected stepFlow: StepFlowEntry<TEngineType>[];
|
|
1556
1560
|
protected serializedStepFlow: SerializedStepFlowEntry[];
|
|
1557
1561
|
protected executionEngine: ExecutionEngine;
|
|
1558
1562
|
protected executionGraph: ExecutionGraph;
|
|
@@ -1565,7 +1569,7 @@ declare class Workflow<TEngineType = any, TSteps extends Step<string, any, any,
|
|
|
1565
1569
|
get mastra(): Mastra<Record<string, Agent<any, ToolsInput, Record<string, Metric>>>, Record<string, LegacyWorkflow<LegacyStep<string, any, any, StepExecutionContext<any, WorkflowContext<any, LegacyStep<string, any, any, any>[], Record<string, any>>>>[], string, any, any>>, Record<string, Workflow<any, Step<string, any, any, any, any, any>[], string, z.ZodType<any, z.ZodTypeDef, any>, z.ZodType<any, z.ZodTypeDef, any>, z.ZodType<any, z.ZodTypeDef, any>>>, Record<string, MastraVector<VectorFilter>>, Record<string, MastraTTS>, IMastraLogger, Record<string, AgentNetwork>, Record<string, NewAgentNetwork>, Record<string, MCPServerBase>> | undefined;
|
|
1566
1570
|
__registerMastra(mastra: Mastra): void;
|
|
1567
1571
|
__registerPrimitives(p: MastraPrimitives): void;
|
|
1568
|
-
setStepFlow(stepFlow: StepFlowEntry[]): void;
|
|
1572
|
+
setStepFlow(stepFlow: StepFlowEntry<TEngineType>[]): void;
|
|
1569
1573
|
/**
|
|
1570
1574
|
* Adds a step to the workflow
|
|
1571
1575
|
* @param step The step to add to the workflow
|
|
@@ -1577,13 +1581,13 @@ declare class Workflow<TEngineType = any, TSteps extends Step<string, any, any,
|
|
|
1577
1581
|
* @param duration The duration to sleep for
|
|
1578
1582
|
* @returns The workflow instance for chaining
|
|
1579
1583
|
*/
|
|
1580
|
-
sleep(duration: number): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema>;
|
|
1584
|
+
sleep(duration: number | ExecuteFunction<z.infer<TPrevSchema>, number, any, any, TEngineType>): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema>;
|
|
1581
1585
|
/**
|
|
1582
1586
|
* Adds a sleep until step to the workflow
|
|
1583
1587
|
* @param date The date to sleep until
|
|
1584
1588
|
* @returns The workflow instance for chaining
|
|
1585
1589
|
*/
|
|
1586
|
-
sleepUntil(date: Date): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema>;
|
|
1590
|
+
sleepUntil(date: Date | ExecuteFunction<z.infer<TPrevSchema>, Date, any, any, TEngineType>): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TPrevSchema>;
|
|
1587
1591
|
waitForEvent<TStepInputSchema extends TPrevSchema, TStepId extends string, TSchemaOut extends z.ZodType<any>>(event: string, step: Step<TStepId, TStepInputSchema, TSchemaOut, any, any, TEngineType>, opts?: {
|
|
1588
1592
|
timeout?: number;
|
|
1589
1593
|
}): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TSchemaOut>;
|
|
@@ -1623,7 +1627,7 @@ declare class Workflow<TEngineType = any, TSteps extends Step<string, any, any,
|
|
|
1623
1627
|
* @returns A built workflow instance ready for execution
|
|
1624
1628
|
*/
|
|
1625
1629
|
commit(): Workflow<TEngineType, TSteps, TWorkflowId, TInput, TOutput, TOutput>;
|
|
1626
|
-
get stepGraph(): StepFlowEntry<
|
|
1630
|
+
get stepGraph(): StepFlowEntry<TEngineType>[];
|
|
1627
1631
|
get serializedStepGraph(): SerializedStepFlowEntry[];
|
|
1628
1632
|
/**
|
|
1629
1633
|
* Creates a new workflow run instance
|
|
@@ -1926,6 +1930,7 @@ type MemoryConfig = {
|
|
|
1926
1930
|
threads?: {
|
|
1927
1931
|
generateTitle?: boolean | {
|
|
1928
1932
|
model: DynamicArgument<MastraLanguageModel>;
|
|
1933
|
+
instructions?: DynamicArgument<string>;
|
|
1929
1934
|
};
|
|
1930
1935
|
};
|
|
1931
1936
|
};
|
|
@@ -2025,6 +2030,7 @@ declare class MessageList {
|
|
|
2025
2030
|
private input;
|
|
2026
2031
|
private response;
|
|
2027
2032
|
drainUnsavedMessages(): MastraMessageV2[];
|
|
2033
|
+
getEarliestUnsavedMessageTimestamp(): number | undefined;
|
|
2028
2034
|
getSystemMessages(tag?: string): CoreMessage$1[];
|
|
2029
2035
|
addSystem(messages: CoreSystemMessage$1 | CoreSystemMessage$1[] | string | string[] | null, tag?: string): this;
|
|
2030
2036
|
private convertToCoreMessages;
|
|
@@ -2633,6 +2639,11 @@ type AgentGenerateOptions<OUTPUT extends ZodSchema | JSONSchema7 | undefined = u
|
|
|
2633
2639
|
telemetry?: TelemetrySettings;
|
|
2634
2640
|
/** RuntimeContext for dependency injection */
|
|
2635
2641
|
runtimeContext?: RuntimeContext;
|
|
2642
|
+
/**
|
|
2643
|
+
* Whether to save messages incrementally on step finish
|
|
2644
|
+
* @default false
|
|
2645
|
+
*/
|
|
2646
|
+
savePerStep?: boolean;
|
|
2636
2647
|
} & ({
|
|
2637
2648
|
/**
|
|
2638
2649
|
* @deprecated Use the `memory` property instead for all memory-related options.
|
|
@@ -2694,6 +2705,11 @@ type AgentStreamOptions<OUTPUT extends ZodSchema | JSONSchema7 | undefined = und
|
|
|
2694
2705
|
telemetry?: TelemetrySettings;
|
|
2695
2706
|
/** RuntimeContext for dependency injection */
|
|
2696
2707
|
runtimeContext?: RuntimeContext;
|
|
2708
|
+
/**
|
|
2709
|
+
* Whether to save messages incrementally on step finish
|
|
2710
|
+
* @default false
|
|
2711
|
+
*/
|
|
2712
|
+
savePerStep?: boolean;
|
|
2697
2713
|
} & ({
|
|
2698
2714
|
/**
|
|
2699
2715
|
* @deprecated Use the `memory` property instead for all memory-related options.
|
|
@@ -3661,6 +3677,70 @@ interface IAction<TId extends string, TSchemaIn extends z.ZodSchema | undefined,
|
|
|
3661
3677
|
execute?: (context: TContext, options?: TOptions) => Promise<TSchemaOut extends z.ZodSchema ? z.infer<TSchemaOut> : unknown>;
|
|
3662
3678
|
}
|
|
3663
3679
|
|
|
3680
|
+
declare class SaveQueueManager {
|
|
3681
|
+
private logger?;
|
|
3682
|
+
private debounceMs;
|
|
3683
|
+
private memory?;
|
|
3684
|
+
private static MAX_STALENESS_MS;
|
|
3685
|
+
constructor({ logger, debounceMs, memory }: {
|
|
3686
|
+
logger?: IMastraLogger;
|
|
3687
|
+
debounceMs?: number;
|
|
3688
|
+
memory?: MastraMemory;
|
|
3689
|
+
});
|
|
3690
|
+
private saveQueues;
|
|
3691
|
+
private saveDebounceTimers;
|
|
3692
|
+
/**
|
|
3693
|
+
* Debounces save operations for a thread, ensuring that consecutive save requests
|
|
3694
|
+
* are batched and only the latest is executed after a short delay.
|
|
3695
|
+
* @param threadId - The ID of the thread to debounce saves for.
|
|
3696
|
+
* @param saveFn - The save function to debounce.
|
|
3697
|
+
*/
|
|
3698
|
+
private debounceSave;
|
|
3699
|
+
/**
|
|
3700
|
+
* Enqueues a save operation for a thread, ensuring that saves are executed in order and
|
|
3701
|
+
* only one save runs at a time per thread. If a save is already in progress for the thread,
|
|
3702
|
+
* the new save is queued to run after the previous completes.
|
|
3703
|
+
*
|
|
3704
|
+
* @param threadId - The ID of the thread whose messages should be saved.
|
|
3705
|
+
* @param messageList - The MessageList instance containing unsaved messages.
|
|
3706
|
+
* @param memoryConfig - Optional memory configuration to use for saving.
|
|
3707
|
+
*/
|
|
3708
|
+
private enqueueSave;
|
|
3709
|
+
/**
|
|
3710
|
+
* Clears any pending debounced save for a thread, preventing the scheduled save
|
|
3711
|
+
* from executing if it hasn't already fired.
|
|
3712
|
+
*
|
|
3713
|
+
* @param threadId - The ID of the thread whose debounced save should be cleared.
|
|
3714
|
+
*/
|
|
3715
|
+
clearDebounce(threadId: string): void;
|
|
3716
|
+
/**
|
|
3717
|
+
* Persists any unsaved messages from the MessageList to memory storage.
|
|
3718
|
+
* Drains the list of unsaved messages and writes them using the memory backend.
|
|
3719
|
+
* @param messageList - The MessageList instance for the current thread.
|
|
3720
|
+
* @param memoryConfig - The memory configuration for saving.
|
|
3721
|
+
*/
|
|
3722
|
+
private persistUnsavedMessages;
|
|
3723
|
+
/**
|
|
3724
|
+
* Batches a save of unsaved messages for a thread, using debouncing to batch rapid updates.
|
|
3725
|
+
* If the oldest unsaved message is stale (older than MAX_STALENESS_MS), the save is performed immediately.
|
|
3726
|
+
* Otherwise, the save is delayed to batch multiple updates and reduce redundant writes.
|
|
3727
|
+
*
|
|
3728
|
+
* @param messageList - The MessageList instance containing unsaved messages.
|
|
3729
|
+
* @param threadId - The ID of the thread whose messages are being saved.
|
|
3730
|
+
* @param memoryConfig - Optional memory configuration for saving.
|
|
3731
|
+
*/
|
|
3732
|
+
batchMessages(messageList: MessageList, threadId?: string, memoryConfig?: MemoryConfig): Promise<void>;
|
|
3733
|
+
/**
|
|
3734
|
+
* Forces an immediate save of unsaved messages for a thread, bypassing any debounce delay.
|
|
3735
|
+
* This is used when a flush to persistent storage is required (e.g., on shutdown or critical transitions).
|
|
3736
|
+
*
|
|
3737
|
+
* @param messageList - The MessageList instance containing unsaved messages.
|
|
3738
|
+
* @param threadId - The ID of the thread whose messages are being saved.
|
|
3739
|
+
* @param memoryConfig - Optional memory configuration for saving.
|
|
3740
|
+
*/
|
|
3741
|
+
flushMessages(messageList: MessageList, threadId?: string, memoryConfig?: MemoryConfig): Promise<void>;
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3664
3744
|
type IDGenerator = () => string;
|
|
3665
3745
|
declare class Agent<TAgentId extends string = string, TTools extends ToolsInput = ToolsInput, TMetrics extends Record<string, Metric> = Record<string, Metric>> extends MastraBase {
|
|
3666
3746
|
#private;
|
|
@@ -3721,13 +3801,14 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
3721
3801
|
* @param tools
|
|
3722
3802
|
*/
|
|
3723
3803
|
__setTools(tools: TTools): void;
|
|
3724
|
-
generateTitleFromUserMessage({ message, runtimeContext, model, }: {
|
|
3804
|
+
generateTitleFromUserMessage({ message, runtimeContext, model, instructions, }: {
|
|
3725
3805
|
message: string | MessageInput;
|
|
3726
3806
|
runtimeContext?: RuntimeContext;
|
|
3727
3807
|
model?: DynamicArgument<MastraLanguageModel>;
|
|
3808
|
+
instructions?: DynamicArgument<string>;
|
|
3728
3809
|
}): Promise<string>;
|
|
3729
3810
|
getMostRecentUserMessage(messages: Array<UIMessage>): UIMessage | undefined;
|
|
3730
|
-
genTitle(userMessage: string | MessageInput | undefined, runtimeContext: RuntimeContext, model?: DynamicArgument<MastraLanguageModel>): Promise<string | undefined>;
|
|
3811
|
+
genTitle(userMessage: string | MessageInput | undefined, runtimeContext: RuntimeContext, model?: DynamicArgument<MastraLanguageModel>, instructions?: DynamicArgument<string>): Promise<string | undefined>;
|
|
3731
3812
|
fetchMemory({ threadId, thread: passedThread, memoryConfig, resourceId, runId, userMessages, systemMessage, messageList, }: {
|
|
3732
3813
|
resourceId: string;
|
|
3733
3814
|
threadId: string;
|
|
@@ -3747,7 +3828,19 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
3747
3828
|
private getClientTools;
|
|
3748
3829
|
private getWorkflowTools;
|
|
3749
3830
|
private convertTools;
|
|
3750
|
-
|
|
3831
|
+
/**
|
|
3832
|
+
* Adds response messages from a step to the MessageList and schedules persistence.
|
|
3833
|
+
* This is used for incremental saving: after each agent step, messages are added to a save queue
|
|
3834
|
+
* and a debounced save operation is triggered to avoid redundant writes.
|
|
3835
|
+
*
|
|
3836
|
+
* @param result - The step result containing response messages.
|
|
3837
|
+
* @param messageList - The MessageList instance for the current thread.
|
|
3838
|
+
* @param threadId - The thread ID.
|
|
3839
|
+
* @param memoryConfig - The memory configuration for saving.
|
|
3840
|
+
* @param runId - (Optional) The run ID for logging.
|
|
3841
|
+
*/
|
|
3842
|
+
private saveStepMessages;
|
|
3843
|
+
__primitive({ instructions, messages, context, thread, memoryConfig, resourceId, runId, toolsets, clientTools, runtimeContext, generateMessageId, saveQueueManager, }: {
|
|
3751
3844
|
instructions?: string;
|
|
3752
3845
|
toolsets?: ToolsetsInput;
|
|
3753
3846
|
clientTools?: ToolsInput;
|
|
@@ -3761,6 +3854,7 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
3761
3854
|
messages: string | string[] | CoreMessage$1[] | Message[];
|
|
3762
3855
|
runtimeContext: RuntimeContext;
|
|
3763
3856
|
generateMessageId: undefined | IDGenerator;
|
|
3857
|
+
saveQueueManager: SaveQueueManager;
|
|
3764
3858
|
}): {
|
|
3765
3859
|
before: () => Promise<{
|
|
3766
3860
|
messageObjects: CoreMessage$1[];
|
|
@@ -3851,6 +3945,11 @@ declare class Agent<TAgentId extends string = string, TTools extends ToolsInput
|
|
|
3851
3945
|
* @private
|
|
3852
3946
|
*/
|
|
3853
3947
|
private resolveTitleGenerationConfig;
|
|
3948
|
+
/**
|
|
3949
|
+
* Resolves title generation instructions, handling both static strings and dynamic functions
|
|
3950
|
+
* @private
|
|
3951
|
+
*/
|
|
3952
|
+
private resolveTitleInstructions;
|
|
3854
3953
|
}
|
|
3855
3954
|
|
|
3856
3955
|
declare abstract class MastraStorage extends MastraBase {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkGCB3FMQA_cjs = require('./chunk-GCB3FMQA.cjs');
|
|
4
4
|
var cohereAi = require('cohere-ai');
|
|
5
5
|
|
|
6
6
|
var CohereRelevanceScorer = class {
|
|
@@ -38,7 +38,7 @@ Relevance score (0-1):`;
|
|
|
38
38
|
var MastraAgentRelevanceScorer = class {
|
|
39
39
|
agent;
|
|
40
40
|
constructor(name, model) {
|
|
41
|
-
this.agent = new
|
|
41
|
+
this.agent = new chunkGCB3FMQA_cjs.Agent({
|
|
42
42
|
name: `Relevance Scorer ${name}`,
|
|
43
43
|
instructions: `You are a specialized agent for evaluating the relevance of text to queries.
|
|
44
44
|
Your task is to rate how well a text passage answers a given query.
|
|
@@ -438,6 +438,11 @@ var MessageList = class _MessageList {
|
|
|
438
438
|
this.newResponseMessages.clear();
|
|
439
439
|
return messages;
|
|
440
440
|
}
|
|
441
|
+
getEarliestUnsavedMessageTimestamp() {
|
|
442
|
+
const unsavedMessages = this.messages.filter((m) => this.newUserMessages.has(m) || this.newResponseMessages.has(m));
|
|
443
|
+
if (unsavedMessages.length === 0) return void 0;
|
|
444
|
+
return Math.min(...unsavedMessages.map((m) => new Date(m.createdAt).getTime()));
|
|
445
|
+
}
|
|
441
446
|
getSystemMessages(tag) {
|
|
442
447
|
if (tag) {
|
|
443
448
|
return this.taggedSystemMessages[tag] || [];
|