chat-agent-toolkit 1.2.367 → 1.2.368

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 (47) hide show
  1. package/package.json +2 -2
  2. package/src/config/config-manager.d.ts +29 -0
  3. package/src/config/config-types.d.ts +58 -0
  4. package/src/config/environment-variables.d.ts +6 -0
  5. package/src/config/index.d.ts +18 -0
  6. package/src/config/language-models-database.d.ts +95 -0
  7. package/src/config/model-registry.d.ts +70 -0
  8. package/src/config/model-tester.d.ts +51 -0
  9. package/src/config/model-utils.d.ts +44 -0
  10. package/src/config/provider-ui-config.d.ts +13 -0
  11. package/src/connectors/index.d.ts +84 -0
  12. package/src/index.d.ts +27 -0
  13. package/src/mastra/agents.d.ts +78 -0
  14. package/src/mastra/evals.d.ts +63 -0
  15. package/src/mastra/index.d.ts +15 -0
  16. package/src/mastra/model-routing.d.ts +71 -0
  17. package/src/mastra/rag.d.ts +83 -0
  18. package/src/mastra/telemetry.d.ts +41 -0
  19. package/src/mastra/workflows.d.ts +85 -0
  20. package/src/memory/agent-memory-manager.d.ts +135 -0
  21. package/src/memory/index.d.ts +18 -0
  22. package/src/memory/mastra-integration.d.ts +161 -0
  23. package/src/memory/storage/drizzle-storage.d.ts +87 -0
  24. package/src/memory/storage/in-memory-storage.d.ts +86 -0
  25. package/src/memory/storage/storage-interface.d.ts +43 -0
  26. package/src/memory/types.d.ts +122 -0
  27. package/src/models/registry.d.ts +4 -0
  28. package/src/models/types.d.ts +4 -0
  29. package/src/prompts/index.d.ts +5 -0
  30. package/src/prompts/meta-search-types.d.ts +6 -0
  31. package/src/prompts/search-prompts.d.ts +25 -0
  32. package/src/tools/index.d.ts +13 -0
  33. package/src/tools/qwksearch-api-tools.d.ts +106 -0
  34. package/src/tools/qwksearch-mcp-tools.d.ts +26 -0
  35. package/src/tools/search/doc-utils.d.ts +49 -0
  36. package/src/tools/search/document.d.ts +14 -0
  37. package/src/tools/search/index.d.ts +13 -0
  38. package/src/tools/search/link-summarizer.d.ts +11 -0
  39. package/src/tools/search/meta-search-types.d.ts +56 -0
  40. package/src/tools/search/metaSearchAgent.d.ts +26 -0
  41. package/src/tools/search/search-handlers.d.ts +34 -0
  42. package/src/tools/search/suggestionGeneratorAgent.d.ts +19 -0
  43. package/src/tools/search/titleGeneratorAgent.d.ts +13 -0
  44. package/src/utils/chat-helpers.d.ts +10 -0
  45. package/src/utils/index.d.ts +5 -0
  46. package/src/utils/outputParser.d.ts +22 -0
  47. package/src/utils/provider-image-cropper.d.ts +127 -0
@@ -0,0 +1,71 @@
1
+ /**
2
+ * @fileoverview Mastra Model Routing
3
+ *
4
+ * Multi-provider model routing with strategy selection:
5
+ * cost-optimized, latency-optimized, capability-based, or round-robin.
6
+ */
7
+ import { Agent } from "@mastra/core/agent";
8
+ export type RoutingStrategy = "cost" | "latency" | "capability" | "round-robin";
9
+ export interface ModelRouterConfig {
10
+ providers: Array<{
11
+ id: string;
12
+ model: any;
13
+ costPer1kTokens?: number;
14
+ avgLatencyMs?: number;
15
+ capabilities?: string[];
16
+ priority?: number;
17
+ }>;
18
+ strategy: RoutingStrategy;
19
+ fallbackProviderId?: string;
20
+ }
21
+ /**
22
+ * Model router that selects providers based on configurable strategies.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { createModelRouter } from "chat-agent-toolkit/mastra";
27
+ * import { openai } from "@ai-sdk/openai";
28
+ * import { anthropic } from "@ai-sdk/anthropic";
29
+ *
30
+ * const router = createModelRouter({
31
+ * providers: [
32
+ * { id: "openai", model: openai("gpt-4o"), costPer1kTokens: 0.005 },
33
+ * { id: "anthropic", model: anthropic("claude-sonnet-4-20250514"), costPer1kTokens: 0.003 },
34
+ * { id: "fast", model: openai("gpt-4o-mini"), costPer1kTokens: 0.0002, avgLatencyMs: 200 },
35
+ * ],
36
+ * strategy: "cost",
37
+ * });
38
+ *
39
+ * const model = router.select(); // cheapest provider
40
+ * const model2 = router.select({ capabilities: ["vision"] }); // capability match
41
+ * ```
42
+ */
43
+ export declare function createModelRouter(config: ModelRouterConfig): {
44
+ select(options?: {
45
+ capabilities?: string[];
46
+ maxCost?: number;
47
+ maxLatency?: number;
48
+ }): any;
49
+ createAgent(agentConfig: {
50
+ id: string;
51
+ name: string;
52
+ instructions: string;
53
+ tools?: Record<string, any>;
54
+ }, routingOptions?: {
55
+ capabilities?: string[];
56
+ maxCost?: number;
57
+ maxLatency?: number;
58
+ }): Agent;
59
+ };
60
+ /**
61
+ * Load a Mastra-compatible model from a provider string.
62
+ * Convenience wrapper around Vercel AI SDK provider imports.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const model = await loadMastraModel("openai", "gpt-4o");
67
+ * const model2 = await loadMastraModel("anthropic", "claude-sonnet-4-20250514");
68
+ * const model3 = await loadMastraModel("groq", "llama-3.3-70b-versatile");
69
+ * ```
70
+ */
71
+ export declare function loadMastraModel(provider: "openai" | "anthropic" | "groq" | "google", modelId: string): Promise<any>;
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @fileoverview Mastra RAG (Retrieval-Augmented Generation)
3
+ *
4
+ * Document processing, chunking, embedding, and vector-store retrieval.
5
+ * Uses Vercel AI SDK embeddings with pluggable vector backends.
6
+ */
7
+ export interface RAGConfig {
8
+ embeddingModel: any;
9
+ chunkSize?: number;
10
+ chunkOverlap?: number;
11
+ topK?: number;
12
+ }
13
+ export interface RAGDocument {
14
+ id: string;
15
+ content: string;
16
+ metadata?: Record<string, any>;
17
+ }
18
+ export interface RAGChunk {
19
+ id: string;
20
+ documentId: string;
21
+ text: string;
22
+ embedding: number[];
23
+ metadata?: Record<string, any>;
24
+ }
25
+ export interface RAGRetrievalResult {
26
+ chunk: RAGChunk;
27
+ score: number;
28
+ }
29
+ /**
30
+ * In-memory RAG pipeline with document chunking, embedding, and retrieval.
31
+ * For production, swap the vector store with Pinecone, Qdrant, or pgvector.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { MastraRAG } from "chat-agent-toolkit/mastra";
36
+ * import { openai } from "@ai-sdk/openai";
37
+ *
38
+ * const rag = new MastraRAG({
39
+ * embeddingModel: openai.embedding("text-embedding-3-small"),
40
+ * chunkSize: 512,
41
+ * topK: 5,
42
+ * });
43
+ *
44
+ * await rag.ingest([
45
+ * { id: "doc1", content: "Long document text..." },
46
+ * ]);
47
+ *
48
+ * const results = await rag.retrieve("What is the main topic?");
49
+ * ```
50
+ */
51
+ export declare class MastraRAG {
52
+ private config;
53
+ private chunks;
54
+ constructor(config: RAGConfig);
55
+ /**
56
+ * Split text into overlapping chunks of configured size.
57
+ */
58
+ private splitIntoChunks;
59
+ /**
60
+ * Ingest documents: chunk, embed, and store.
61
+ */
62
+ ingest(documents: RAGDocument[]): Promise<number>;
63
+ /**
64
+ * Retrieve relevant chunks for a query using cosine similarity.
65
+ */
66
+ retrieve(query: string): Promise<RAGRetrievalResult[]>;
67
+ /**
68
+ * Retrieve and format context string for LLM consumption.
69
+ */
70
+ getContext(query: string): Promise<string>;
71
+ /**
72
+ * Get total chunk count in the store.
73
+ */
74
+ get size(): number;
75
+ /**
76
+ * Clear all stored chunks.
77
+ */
78
+ clear(): void;
79
+ }
80
+ /**
81
+ * Factory for creating a configured RAG pipeline.
82
+ */
83
+ export declare function createRAGPipeline(config: RAGConfig): MastraRAG;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @fileoverview Mastra Telemetry & Instance Factory
3
+ *
4
+ * Creates configured Mastra instances with OpenTelemetry-compatible
5
+ * tracing, logging, and agent registration.
6
+ */
7
+ import { Mastra } from "@mastra/core";
8
+ export interface TelemetryConfig {
9
+ serviceName: string;
10
+ enabled?: boolean;
11
+ sampling?: number;
12
+ exporterUrl?: string;
13
+ }
14
+ export interface MastraInstanceConfig {
15
+ agents?: Record<string, any>;
16
+ workflows?: Record<string, any>;
17
+ telemetry?: TelemetryConfig;
18
+ storage?: any;
19
+ }
20
+ /**
21
+ * Create a fully configured Mastra instance with agents, workflows,
22
+ * and telemetry. Central entry point for Mastra framework setup.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { createMastraInstance } from "chat-agent-toolkit/mastra";
27
+ *
28
+ * const mastra = createMastraInstance({
29
+ * agents: { assistant, researcher },
30
+ * workflows: { researchWorkflow },
31
+ * telemetry: {
32
+ * serviceName: "my-app",
33
+ * enabled: true,
34
+ * },
35
+ * });
36
+ *
37
+ * const agent = mastra.getAgent("assistant");
38
+ * const result = await agent.generate("Hello");
39
+ * ```
40
+ */
41
+ export declare function createMastraInstance(config: MastraInstanceConfig): Mastra;
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @fileoverview Mastra Workflow Builder
3
+ *
4
+ * Graph-based deterministic workflows with typed steps, chaining,
5
+ * branching, and parallel execution support.
6
+ */
7
+ import { z } from "zod";
8
+ export interface WorkflowStepConfig<TInput = any, TOutput = any> {
9
+ id: string;
10
+ inputSchema: z.ZodType<TInput>;
11
+ outputSchema: z.ZodType<TOutput>;
12
+ execute: (params: {
13
+ inputData: TInput;
14
+ }) => Promise<TOutput>;
15
+ }
16
+ /**
17
+ * Create a typed workflow step.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * const fetchStep = createWorkflowStep({
22
+ * id: "fetch-sources",
23
+ * inputSchema: z.object({ query: z.string() }),
24
+ * outputSchema: z.object({ sources: z.array(z.string()) }),
25
+ * execute: async ({ inputData }) => {
26
+ * const sources = await searchWeb(inputData.query);
27
+ * return { sources };
28
+ * },
29
+ * });
30
+ * ```
31
+ */
32
+ export declare function createWorkflowStep<TInput, TOutput>(config: WorkflowStepConfig<TInput, TOutput>): import("@mastra/core/workflows").Step<string, unknown, TInput, TOutput, unknown, unknown, import("@mastra/core/workflows").DefaultEngineType, unknown>;
33
+ /**
34
+ * Create a research workflow: fetch → analyze → summarize.
35
+ * Pre-built pipeline for common research tasks.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * const workflow = createResearchWorkflow({
40
+ * fetchFn: async (topic) => fetchSources(topic),
41
+ * analyzeFn: async (sources) => analyzeContent(sources),
42
+ * summarizeFn: async (analysis) => generateSummary(analysis),
43
+ * });
44
+ *
45
+ * const run = await workflow.createRunAsync();
46
+ * const result = await run.start({ inputData: { topic: "quantum computing" } });
47
+ * ```
48
+ */
49
+ export declare function createResearchWorkflow(handlers: {
50
+ fetchFn: (topic: string) => Promise<string[]>;
51
+ analyzeFn: (sources: string[]) => Promise<string>;
52
+ summarizeFn: (analysis: string) => Promise<string>;
53
+ }): import("@mastra/core/workflows").Workflow<import("@mastra/core/workflows").DefaultEngineType, import("@mastra/core/workflows").Step<string, unknown, unknown, unknown, unknown, unknown, any, unknown>[], "research-workflow", unknown, {
54
+ topic: string;
55
+ }, {
56
+ summary: string;
57
+ }, {
58
+ summary: string;
59
+ }, unknown>;
60
+ /**
61
+ * Create a RAG workflow: chunk → embed → retrieve → generate.
62
+ * End-to-end retrieval-augmented generation pipeline.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * const workflow = createRAGWorkflow({
67
+ * chunkFn: async (doc) => splitIntoChunks(doc),
68
+ * embedFn: async (chunks) => embedChunks(chunks),
69
+ * retrieveFn: async (query) => findRelevant(query),
70
+ * generateFn: async (context, query) => llmGenerate(context, query),
71
+ * });
72
+ * ```
73
+ */
74
+ export declare function createRAGWorkflow(handlers: {
75
+ chunkFn: (document: string) => Promise<string[]>;
76
+ embedFn: (chunks: string[]) => Promise<number[][]>;
77
+ retrieveFn: (query: string) => Promise<string[]>;
78
+ generateFn: (context: string[], query: string) => Promise<string>;
79
+ }): import("@mastra/core/workflows").Workflow<import("@mastra/core/workflows").DefaultEngineType, import("@mastra/core/workflows").Step<string, unknown, unknown, unknown, unknown, unknown, any, unknown>[], "rag-workflow", unknown, {
80
+ query: string;
81
+ }, {
82
+ answer: string;
83
+ }, {
84
+ answer: string;
85
+ }, unknown>;
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Memory Agent
3
+ *
4
+ * Enhanced Memory Agent with:
5
+ * - Rate limiting
6
+ * - Multiple LLM provider support
7
+ * - Health monitoring
8
+ * - Conversation management
9
+ * - Memory analytics
10
+ */
11
+ import type { IMemoryStorage } from "./storage/storage-interface";
12
+ import type { MemoryType, MemorySearchOptions } from "./types";
13
+ /**
14
+ * LLM provider interface
15
+ */
16
+ interface LLMProvider {
17
+ invoke: (prompt: string) => Promise<{
18
+ content: string;
19
+ tokensUsed: number;
20
+ }>;
21
+ }
22
+ /**
23
+ * Chat options
24
+ */
25
+ interface ChatOptions {
26
+ provider?: string;
27
+ apiKey?: string;
28
+ model?: string;
29
+ temperature?: number;
30
+ systemPrompt?: string;
31
+ includeHistory?: boolean;
32
+ maxMemories?: number;
33
+ minImportance?: number;
34
+ }
35
+ /**
36
+ * Chat response
37
+ */
38
+ interface ChatResponse {
39
+ content?: string;
40
+ memoryContext?: string;
41
+ success: boolean;
42
+ tokensUsed?: number;
43
+ responseTime?: number;
44
+ sessionId?: string;
45
+ timestamp: string;
46
+ error?: string;
47
+ }
48
+ /**
49
+ * Rate limit configuration
50
+ */
51
+ interface RateLimitConfig {
52
+ requests: number;
53
+ windowMs: number;
54
+ }
55
+ /**
56
+ * Agent options
57
+ */
58
+ export interface MemoryAgentOptions {
59
+ memoryOptions?: any;
60
+ defaultProvider?: string;
61
+ defaultApiKey?: string;
62
+ defaultModel?: string;
63
+ rateLimit?: RateLimitConfig;
64
+ providers?: Record<string, (apiKey: string, model: string, temperature: number) => LLMProvider>;
65
+ }
66
+ export declare class MemoryAgent {
67
+ private memory;
68
+ private defaultProvider;
69
+ private defaultApiKey?;
70
+ private defaultModel?;
71
+ private rateLimiter;
72
+ private rateLimitConfig;
73
+ private providers;
74
+ private sessionId;
75
+ private conversationHistory;
76
+ private analytics;
77
+ private userId;
78
+ /**
79
+ * Initialize memory agent
80
+ */
81
+ constructor(userId: string, storage: IMemoryStorage, options?: MemoryAgentOptions);
82
+ /**
83
+ * Get default LLM providers
84
+ */
85
+ private getDefaultProviders;
86
+ /**
87
+ * Generate unique session ID
88
+ */
89
+ private generateSessionId;
90
+ /**
91
+ * Rate limiting check with sliding window
92
+ */
93
+ private checkRateLimit;
94
+ /**
95
+ * Main chat method with comprehensive error handling
96
+ */
97
+ chat(message: string, options?: ChatOptions): Promise<ChatResponse>;
98
+ /**
99
+ * Generate LLM response with timeout and error handling
100
+ */
101
+ private generateResponse;
102
+ /**
103
+ * Build enhanced prompt with context
104
+ */
105
+ private buildPrompt;
106
+ /**
107
+ * Update analytics
108
+ */
109
+ private updateAnalytics;
110
+ /**
111
+ * Remember a fact manually
112
+ */
113
+ remember(fact: string, importance?: number, category?: MemoryType, metadata?: Record<string, any>): Promise<string>;
114
+ /**
115
+ * Get memories with filtering
116
+ */
117
+ getMemories(query?: string, limit?: number, options?: MemorySearchOptions): Promise<any[]>;
118
+ /**
119
+ * Force store summary of current conversation
120
+ */
121
+ forceStoreSummary(): Promise<boolean>;
122
+ /**
123
+ * Health check for the agent
124
+ */
125
+ healthCheck(): Promise<any>;
126
+ /**
127
+ * Get analytics and performance metrics
128
+ */
129
+ getAnalytics(): any;
130
+ /**
131
+ * Reset session and clear conversation history
132
+ */
133
+ resetSession(): void;
134
+ }
135
+ export {};
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @fileoverview Memory Management System
3
+ *
4
+ * Intelligent long-term memory for AI agents with persistent storage,
5
+ * vector-based relevance search, and automatic conversation summarization.
6
+ * Supports in-memory and Drizzle ORM-backed persistence.
7
+ *
8
+ * @module memory
9
+ * @author ai-research-agent contributors
10
+ */
11
+ export { MemoryAgent } from "./agent-memory-manager";
12
+ export type { MemoryAgentOptions } from "./agent-memory-manager";
13
+ export { SimpleMemory } from "./storage/in-memory-storage";
14
+ export { DrizzleMemoryStorage, createMemorySchema } from "./storage/drizzle-storage";
15
+ export type { IMemoryStorage } from "./storage/storage-interface";
16
+ export { MEMORY_CONFIG, MEMORY_TYPES, type MemoryType, type MemoryRecord, type Message, type MemorySearchOptions, type MemoryUpdate, type MemoryContextOptions, type MemoryMetrics, type MemoryOptions, type ExtractedFact, } from "./types";
17
+ export { MastraMemoryManager, MastraD1MemoryStorage, MastraKVMemoryStorage, createMastraMemory, } from "./mastra-integration";
18
+ export type { CloudflareEnv, MastraStorageBackend, MastraMemoryConfig, } from "./mastra-integration";
@@ -0,0 +1,161 @@
1
+ /**
2
+ * @fileoverview Mastra Memory Integration for Cloudflare Workers
3
+ *
4
+ * Integrates Mastra's memory system with Cloudflare Workers environment.
5
+ * Provides persistent conversation memory using D1, KV, or Durable Objects.
6
+ *
7
+ * Features:
8
+ * - Multi-storage backend support (D1, KV, Durable Objects)
9
+ * - Thread-based conversation management
10
+ * - Resource scoping for multi-user scenarios
11
+ * - Cloudflare Workers optimized (edge-ready)
12
+ * - Compatible with existing MemoryAgent architecture
13
+ *
14
+ * @see https://docs.mastra.ai/core/memory
15
+ */
16
+ import { Mastra } from '@mastra/core';
17
+ import { Agent } from '@mastra/core/agent';
18
+ import type { D1Database, KVNamespace } from '@cloudflare/workers-types';
19
+ import type { IMemoryStorage } from './storage/storage-interface';
20
+ import type { MemoryRecord, MemoryType, MemorySearchOptions, MemoryUpdate } from './types';
21
+ /**
22
+ * Cloudflare Workers environment bindings
23
+ */
24
+ export interface CloudflareEnv {
25
+ DB?: D1Database;
26
+ KV?: KVNamespace;
27
+ OPENAI_API_KEY?: string;
28
+ ANTHROPIC_API_KEY?: string;
29
+ GROQ_API_KEY?: string;
30
+ }
31
+ /**
32
+ * Storage backend types for Mastra memory
33
+ */
34
+ export type MastraStorageBackend = 'memory' | 'd1' | 'kv';
35
+ /**
36
+ * Configuration for Mastra memory integration
37
+ */
38
+ export interface MastraMemoryConfig {
39
+ /** Storage backend (memory, d1, or kv) */
40
+ storage: MastraStorageBackend;
41
+ /** Cloudflare environment bindings */
42
+ env?: CloudflareEnv;
43
+ /** D1 table name (for d1 storage) */
44
+ tableName?: string;
45
+ /** KV key prefix (for kv storage) */
46
+ kvPrefix?: string;
47
+ /** Enable debug logging */
48
+ debug?: boolean;
49
+ }
50
+ /**
51
+ * D1-based storage adapter for Mastra Memory
52
+ * Implements IMemoryStorage using Cloudflare D1
53
+ */
54
+ export declare class MastraD1MemoryStorage implements IMemoryStorage {
55
+ private db;
56
+ private tableName;
57
+ constructor(db: D1Database, tableName?: string);
58
+ /**
59
+ * Initialize D1 schema for Mastra memory
60
+ */
61
+ initSchema(): Promise<void>;
62
+ insertMemory(userId: string, memoryType: MemoryType, content: string, importance: number, metadata?: Record<string, any>): Promise<string>;
63
+ findMemories(userId: string, query?: string, limit?: number, options?: MemorySearchOptions): Promise<MemoryRecord[]>;
64
+ findSimilarMemories(userId: string, content: string, limit?: number): Promise<MemoryRecord[]>;
65
+ updateMemory(id: string, updates: MemoryUpdate): Promise<void>;
66
+ deleteMemory(id: string): Promise<void>;
67
+ getMemoryById(id: string): Promise<MemoryRecord | null>;
68
+ batchUpdateMemories(updates: Array<{
69
+ id: string;
70
+ updates: MemoryUpdate;
71
+ }>): Promise<void>;
72
+ }
73
+ /**
74
+ * KV-based storage adapter for Mastra Memory
75
+ * Uses Cloudflare KV for simple key-value storage
76
+ */
77
+ export declare class MastraKVMemoryStorage implements IMemoryStorage {
78
+ private kv;
79
+ private prefix;
80
+ constructor(kv: KVNamespace, prefix?: string);
81
+ private getUserKey;
82
+ private getMemoryKey;
83
+ insertMemory(userId: string, memoryType: MemoryType, content: string, importance: number, metadata?: Record<string, any>): Promise<string>;
84
+ findMemories(userId: string, query?: string, limit?: number, options?: MemorySearchOptions): Promise<MemoryRecord[]>;
85
+ findSimilarMemories(userId: string, content: string, limit?: number): Promise<MemoryRecord[]>;
86
+ updateMemory(id: string, updates: MemoryUpdate): Promise<void>;
87
+ deleteMemory(id: string): Promise<void>;
88
+ getMemoryById(id: string): Promise<MemoryRecord | null>;
89
+ batchUpdateMemories(updates: Array<{
90
+ id: string;
91
+ updates: MemoryUpdate;
92
+ }>): Promise<void>;
93
+ }
94
+ /**
95
+ * Mastra Memory Manager for Cloudflare Workers
96
+ * Wraps Mastra's memory system with Cloudflare-compatible storage
97
+ */
98
+ export declare class MastraMemoryManager {
99
+ private mastra;
100
+ private storage;
101
+ private config;
102
+ constructor(config: MastraMemoryConfig);
103
+ /**
104
+ * Initialize Mastra instance with memory
105
+ */
106
+ initialize(): Promise<Mastra>;
107
+ /**
108
+ * Get storage instance (for direct access)
109
+ */
110
+ getStorage(): IMemoryStorage;
111
+ /**
112
+ * Create an agent with memory
113
+ */
114
+ createAgent(config: {
115
+ id: string;
116
+ name: string;
117
+ instructions: string;
118
+ model: any;
119
+ tools?: Record<string, any>;
120
+ userId: string;
121
+ threadId?: string;
122
+ resourceId?: string;
123
+ }): Promise<Agent>;
124
+ /**
125
+ * Store a message in memory
126
+ */
127
+ storeMessage(userId: string, threadId: string, role: 'user' | 'assistant', content: string, metadata?: Record<string, any>): Promise<string>;
128
+ /**
129
+ * Recall conversation history
130
+ */
131
+ recallConversation(userId: string, threadId: string, limit?: number): Promise<Array<{
132
+ role: 'user' | 'assistant';
133
+ content: string;
134
+ timestamp: Date;
135
+ }>>;
136
+ /**
137
+ * Get relevant context for a query
138
+ */
139
+ getRelevantContext(userId: string, query: string, limit?: number): Promise<string>;
140
+ }
141
+ /**
142
+ * Quick helper to create Mastra memory manager for Cloudflare Workers
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * const memoryManager = createMastraMemory({
147
+ * storage: 'd1',
148
+ * env: env, // Cloudflare env bindings
149
+ * });
150
+ *
151
+ * const agent = await memoryManager.createAgent({
152
+ * id: 'assistant',
153
+ * name: 'AI Assistant',
154
+ * instructions: 'Help users with their questions',
155
+ * model: openai('gpt-4o'),
156
+ * userId: 'user-123',
157
+ * threadId: 'conversation-1',
158
+ * });
159
+ * ```
160
+ */
161
+ export declare function createMastraMemory(config: MastraMemoryConfig): MastraMemoryManager;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Drizzle Storage Adapter
3
+ *
4
+ * Implementation of IMemoryStorage using Drizzle ORM
5
+ */
6
+ import type { IMemoryStorage } from "./storage-interface";
7
+ import type { MemoryRecord, MemoryType, MemorySearchOptions, MemoryUpdate } from "../types";
8
+ /**
9
+ * The Drizzle table passed to {@link DrizzleMemoryStorage} must expose these
10
+ * columns (see {@link createMemorySchema} for the expected shape).
11
+ */
12
+ export interface MemoryTable {
13
+ id: any;
14
+ user_id: any;
15
+ memory_type: any;
16
+ content: any;
17
+ importance: any;
18
+ access_count: any;
19
+ metadata: any;
20
+ created_at: any;
21
+ updated_at: any;
22
+ }
23
+ /**
24
+ * Drizzle-based storage adapter.
25
+ *
26
+ * Pass the Drizzle database instance and the memory table object defined in
27
+ * your schema (not a table-name string) so queries reference real columns:
28
+ *
29
+ * ```ts
30
+ * import { sqliteTable, text, integer, real } from "drizzle-orm/sqlite-core";
31
+ * const userMemories = sqliteTable("user_memories", { ... });
32
+ * const storage = new DrizzleMemoryStorage(db, userMemories);
33
+ * ```
34
+ */
35
+ export declare class DrizzleMemoryStorage implements IMemoryStorage {
36
+ private db;
37
+ private table;
38
+ constructor(db: any, table: MemoryTable & Record<string, any>);
39
+ /**
40
+ * Insert a new memory record
41
+ */
42
+ insertMemory(userId: string, memoryType: MemoryType, content: string, importance: number, metadata?: Record<string, any>): Promise<string>;
43
+ /**
44
+ * Find memories by user ID and optional filters
45
+ */
46
+ findMemories(userId: string, query?: string, limit?: number, options?: MemorySearchOptions): Promise<MemoryRecord[]>;
47
+ /**
48
+ * Find similar memories based on content
49
+ */
50
+ findSimilarMemories(userId: string, content: string, limit?: number): Promise<MemoryRecord[]>;
51
+ /**
52
+ * Update a memory record
53
+ */
54
+ updateMemory(id: string, updates: MemoryUpdate): Promise<void>;
55
+ /**
56
+ * Delete a memory record
57
+ */
58
+ deleteMemory(id: string): Promise<void>;
59
+ /**
60
+ * Get memory by ID
61
+ */
62
+ getMemoryById(id: string): Promise<MemoryRecord | null>;
63
+ /**
64
+ * Batch update memories
65
+ */
66
+ batchUpdateMemories(updates: Array<{
67
+ id: string;
68
+ updates: MemoryUpdate;
69
+ }>): Promise<void>;
70
+ }
71
+ /**
72
+ * Database schema for memory system
73
+ * This is kept here for reference but should be managed by your migration system
74
+ */
75
+ export declare function createMemorySchema(db: any): {
76
+ user_memories: {
77
+ id: string;
78
+ user_id: string;
79
+ memory_type: string;
80
+ content: string;
81
+ importance: string;
82
+ access_count: string;
83
+ metadata: string;
84
+ created_at: string;
85
+ updated_at: string;
86
+ };
87
+ };