@mastra/cloudflare 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016

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 (72) hide show
  1. package/CHANGELOG.md +2316 -3
  2. package/LICENSE.md +15 -0
  3. package/README.md +38 -16
  4. package/dist/do/index.cjs +9 -0
  5. package/dist/do/index.d.ts +92 -0
  6. package/dist/do/index.d.ts.map +1 -0
  7. package/dist/do/index.js +2 -0
  8. package/dist/do/storage/db/index.d.ts +76 -0
  9. package/dist/do/storage/db/index.d.ts.map +1 -0
  10. package/dist/do/storage/domains/background-tasks/index.d.ts +18 -0
  11. package/dist/do/storage/domains/background-tasks/index.d.ts.map +1 -0
  12. package/dist/do/storage/domains/memory/index.d.ts +61 -0
  13. package/dist/do/storage/domains/memory/index.d.ts.map +1 -0
  14. package/dist/do/storage/domains/scores/index.d.ts +42 -0
  15. package/dist/do/storage/domains/scores/index.d.ts.map +1 -0
  16. package/dist/do/storage/domains/utils.d.ts +3 -0
  17. package/dist/do/storage/domains/utils.d.ts.map +1 -0
  18. package/dist/do/storage/domains/workflows/index.d.ts +46 -0
  19. package/dist/do/storage/domains/workflows/index.d.ts.map +1 -0
  20. package/dist/do/storage/sql-builder.d.ts +128 -0
  21. package/dist/do/storage/sql-builder.d.ts.map +1 -0
  22. package/dist/do-BDZtdsky.js +2272 -0
  23. package/dist/do-BDZtdsky.js.map +1 -0
  24. package/dist/do-BkCQKqjz.cjs +2313 -0
  25. package/dist/do-BkCQKqjz.cjs.map +1 -0
  26. package/dist/docs/SKILL.md +22 -0
  27. package/dist/docs/assets/SOURCE_MAP.json +6 -0
  28. package/dist/docs/references/reference-storage-cloudflare.md +161 -0
  29. package/dist/index.cjs +14 -2523
  30. package/dist/index.d.ts +4 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +3 -2517
  33. package/dist/kv/index.cjs +8 -0
  34. package/dist/kv/index.d.ts +43 -0
  35. package/dist/kv/index.d.ts.map +1 -0
  36. package/dist/kv/index.js +2 -0
  37. package/dist/{storage/domains/operations → kv/storage/db}/index.d.ts +22 -26
  38. package/dist/kv/storage/db/index.d.ts.map +1 -0
  39. package/dist/kv/storage/domains/background-tasks/index.d.ts +17 -0
  40. package/dist/kv/storage/domains/background-tasks/index.d.ts.map +1 -0
  41. package/dist/kv/storage/domains/memory/index.d.ts +128 -0
  42. package/dist/kv/storage/domains/memory/index.d.ts.map +1 -0
  43. package/dist/kv/storage/domains/scores/index.d.ts +42 -0
  44. package/dist/kv/storage/domains/scores/index.d.ts.map +1 -0
  45. package/dist/{storage → kv/storage}/domains/workflows/index.d.ts +18 -24
  46. package/dist/kv/storage/domains/workflows/index.d.ts.map +1 -0
  47. package/dist/kv/storage/test-utils.d.ts.map +1 -0
  48. package/dist/kv/storage/types.d.ts +164 -0
  49. package/dist/kv/storage/types.d.ts.map +1 -0
  50. package/dist/kv-CzXjeoeQ.js +2137 -0
  51. package/dist/kv-CzXjeoeQ.js.map +1 -0
  52. package/dist/kv-DAbAqe-v.cjs +2195 -0
  53. package/dist/kv-DAbAqe-v.cjs.map +1 -0
  54. package/package.json +46 -19
  55. package/dist/index.cjs.map +0 -1
  56. package/dist/index.js.map +0 -1
  57. package/dist/storage/domains/legacy-evals/index.d.ts +0 -21
  58. package/dist/storage/domains/legacy-evals/index.d.ts.map +0 -1
  59. package/dist/storage/domains/memory/index.d.ts +0 -107
  60. package/dist/storage/domains/memory/index.d.ts.map +0 -1
  61. package/dist/storage/domains/operations/index.d.ts.map +0 -1
  62. package/dist/storage/domains/scores/index.d.ts +0 -50
  63. package/dist/storage/domains/scores/index.d.ts.map +0 -1
  64. package/dist/storage/domains/traces/index.d.ts +0 -18
  65. package/dist/storage/domains/traces/index.d.ts.map +0 -1
  66. package/dist/storage/domains/workflows/index.d.ts.map +0 -1
  67. package/dist/storage/index.d.ts +0 -228
  68. package/dist/storage/index.d.ts.map +0 -1
  69. package/dist/storage/test-utils.d.ts.map +0 -1
  70. package/dist/storage/types.d.ts +0 -67
  71. package/dist/storage/types.d.ts.map +0 -1
  72. /package/dist/{storage → kv/storage}/test-utils.d.ts +0 -0
package/LICENSE.md CHANGED
@@ -1,3 +1,18 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named "ee/" within this
4
+ repository, including but not limited to:
5
+ - `packages/core/src/auth/ee/`
6
+ - `packages/server/src/server/auth/ee/`
7
+ is licensed under the license defined in `ee/LICENSE`.
8
+
9
+ - All third-party components incorporated into the Mastra Software are
10
+ licensed under the original license provided by the owner of the
11
+ applicable component.
12
+
13
+ - Content outside of the above-mentioned directories or restrictions is
14
+ available under the "Apache License 2.0" as defined below.
15
+
1
16
  # Apache License 2.0
2
17
 
3
18
  Copyright (c) 2025 Kepler Software, Inc.
package/README.md CHANGED
@@ -11,7 +11,7 @@ npm install @mastra/cloudflare
11
11
  ## Prerequisites
12
12
 
13
13
  - Cloudflare account with KV namespaces set up
14
- - Node.js 16 or higher
14
+ - Node.js 22.13.0 or later
15
15
  - (Optional) Cloudflare Worker for Workers API mode
16
16
 
17
17
  ## Usage
@@ -25,7 +25,6 @@ const store = new CloudflareStore({
25
25
  threads: THREADS_KV_NAMESPACE,
26
26
  messages: MESSAGES_KV_NAMESPACE,
27
27
  workflow_snapshot: WORKFLOW_KV_NAMESPACE,
28
- evals: EVALS_KV_NAMESPACE,
29
28
  traces: TRACES_KV_NAMESPACE,
30
29
  },
31
30
  keyPrefix: 'myapp_', // Optional
@@ -40,12 +39,13 @@ const store = new CloudflareStore({
40
39
 
41
40
  // Save a thread
42
41
  await store.saveThread({
43
- id: 'thread-123',
44
- resourceId: 'resource-456',
45
- title: 'My Thread',
46
- metadata: { key: 'value' },
47
- createdAt: new Date(),
48
- updatedAt: new Date(),
42
+ thread: {
43
+ id: 'thread-123',
44
+ resourceId: 'resource-456',
45
+ title: 'My Thread',
46
+ metadata: { key: 'value' },
47
+ createdAt: new Date(),
48
+ },
49
49
  });
50
50
 
51
51
  // Add messages
@@ -62,7 +62,7 @@ await store.saveMessages({
62
62
  });
63
63
 
64
64
  // Query messages
65
- const messages = await store.getMessages({ threadId: 'thread-123' });
65
+ const messages = await store.listMessages({ threadId: 'thread-123' });
66
66
  ```
67
67
 
68
68
  ## Configuration
@@ -95,25 +95,47 @@ const messages = await store.getMessages({ threadId: 'thread-123' });
95
95
 
96
96
  ### Thread Operations
97
97
 
98
- - `saveThread(thread)`: Create or update a thread
98
+ - `saveThread({ thread })`: Create or update a thread
99
99
  - `getThreadById({ threadId })`: Get a thread by ID
100
- - `getThreadsByResourceId({ resourceId })`: Fetch all threads associated with a resource.
100
+ - `listThreadsByResourceId({ resourceId, offset, limit, orderBy? })`: List paginated threads for a resource
101
101
  - `updateThread({ id, title, metadata })`: Update thread title and metadata
102
102
  - `deleteThread({ threadId })`: Delete a thread and its messages
103
103
 
104
104
  ### Message Operations
105
105
 
106
106
  - `saveMessages({ messages })`: Save multiple messages
107
- - `getMessages({ threadId, selectBy? })`: Get messages for a thread with optional filtering (last N, includes, etc)
107
+ - `listMessages({ threadId, perPage?, page? })`: Get messages for a thread with pagination
108
+ - `listMessagesById({ messageIds })`: Get specific messages by their IDs
109
+ - `updateMessages({ messages })`: Update existing messages
110
+
111
+ ### Resource Operations
112
+
113
+ - `getResourceById({ resourceId })`: Get a resource by ID
114
+ - `saveResource({ resource })`: Create or save a resource
115
+ - `updateResource({ resourceId, workingMemory })`: Update resource working memory
108
116
 
109
117
  ### Workflow Operations
110
118
 
111
- - `persistWorkflowSnapshot({ workflowName, runId, snapshot })`: Save workflow state for a given workflow/run.
112
- - `loadWorkflowSnapshot({ workflowName, runId })`: Load ed workflow state.
119
+ - `persistWorkflowSnapshot({ workflowName, runId, snapshot })`: Save workflow state
120
+ - `loadWorkflowSnapshot({ workflowName, runId })`: Load workflow state
121
+ - `listWorkflowRuns({ workflowName, pagination })`: List workflow runs with pagination
122
+ - `getWorkflowRunById({ workflowName, runId })`: Get a specific workflow run
123
+ - `updateWorkflowState({ workflowName, runId, state })`: Update workflow state
124
+ - `updateWorkflowResults({ workflowName, runId, results })`: Update workflow results
125
+
126
+ ### Evaluation/Scoring Operations
127
+
128
+ - `getScoreById({ id })`: Get a score by ID
129
+ - `saveScore(score)`: Save an evaluation score
130
+ - `listScoresByScorerId({ scorerId, pagination })`: List scores by scorer with pagination
131
+ - `listScoresByRunId({ runId, pagination })`: List scores by run with pagination
132
+ - `listScoresByEntityId({ entityId, entityType, pagination })`: List scores by entity with pagination
133
+ - `listScoresBySpan({ traceId, spanId, pagination })`: List scores by span with pagination
113
134
 
114
- ### Trace Operations
135
+ ### Operations Not Currently Supported
115
136
 
116
- - `getTraces({ name?, scope?, page, perPage, attributes? })`: Query trace records with optional filters and pagination.
137
+ - `deleteMessages(messageIds)`: Message deletion is not currently supported
138
+ - AI Observability (traces/spans): Not currently supported
117
139
 
118
140
  ### Utility
119
141
 
@@ -0,0 +1,9 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_do = require("../do-BkCQKqjz.cjs");
3
+ exports.BackgroundTasksStorageDO = require_do.BackgroundTasksStorageDO;
4
+ exports.CloudflareDOStorage = require_do.CloudflareDOStorage;
5
+ exports.DODB = require_do.DODB;
6
+ exports.DOStore = require_do.DOStore;
7
+ exports.MemoryStorageDO = require_do.MemoryStorageDO;
8
+ exports.ScoresStorageDO = require_do.ScoresStorageDO;
9
+ exports.WorkflowsStorageDO = require_do.WorkflowsStorageDO;
@@ -0,0 +1,92 @@
1
+ import type { SqlStorage } from '@cloudflare/workers-types';
2
+ import { MastraCompositeStore } from '@mastra/core/storage';
3
+ import type { StorageDomains } from '@mastra/core/storage';
4
+ import { BackgroundTasksStorageDO } from './storage/domains/background-tasks/index.js';
5
+ import { MemoryStorageDO } from './storage/domains/memory/index.js';
6
+ import { ScoresStorageDO } from './storage/domains/scores/index.js';
7
+ import { WorkflowsStorageDO } from './storage/domains/workflows/index.js';
8
+ export { BackgroundTasksStorageDO, MemoryStorageDO, ScoresStorageDO, WorkflowsStorageDO };
9
+ export type { DODomainConfig } from './storage/db/index.js';
10
+ export { DODB } from './storage/db/index.js';
11
+ /**
12
+ * Configuration for CloudflareDOStorage using Durable Objects SqlStorage
13
+ */
14
+ export interface CloudflareDOStorageConfig {
15
+ /** SqlStorage instance from Durable Objects ctx.storage.sql */
16
+ sql: SqlStorage;
17
+ /** Optional prefix for table names */
18
+ tablePrefix?: string;
19
+ /**
20
+ * When true, automatic initialization (table creation/migrations) is disabled.
21
+ * This is useful for CI/CD pipelines where you want to:
22
+ * 1. Run migrations explicitly during deployment (not at runtime)
23
+ * 2. Use different credentials for schema changes vs runtime operations
24
+ *
25
+ * When disableInit is true:
26
+ * - The storage will not automatically create/alter tables on first use
27
+ * - You must call `storage.init()` explicitly in your CI/CD scripts
28
+ *
29
+ * @example
30
+ * // In CI/CD script:
31
+ * const storage = new CloudflareDOStorage({ ...config, disableInit: false });
32
+ * await storage.init(); // Explicitly run migrations
33
+ *
34
+ * // In runtime application:
35
+ * const storage = new CloudflareDOStorage({ ...config, disableInit: true });
36
+ * // No auto-init, tables must already exist
37
+ */
38
+ disableInit?: boolean;
39
+ }
40
+ /**
41
+ * Cloudflare Durable Objects storage adapter for Mastra.
42
+ *
43
+ * Uses the synchronous SqlStorage API available in Durable Objects
44
+ * to provide thread-based memory storage, workflow persistence, and scoring.
45
+ *
46
+ * Access domain-specific storage via `getStore()`:
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * import { DurableObject } from 'cloudflare:workers';
51
+ * import { CloudflareDOStorage } from '@mastra/cloudflare/do';
52
+ *
53
+ * class AgentDurableObject extends DurableObject<Env> {
54
+ * private storage: CloudflareDOStorage;
55
+ *
56
+ * constructor(ctx: DurableObjectState, env: Env) {
57
+ * super(ctx, env);
58
+ * this.storage = new CloudflareDOStorage({
59
+ * sql: ctx.storage.sql,
60
+ * tablePrefix: 'mastra_'
61
+ * });
62
+ * }
63
+ *
64
+ * async run() {
65
+ * const memory = await this.storage.getStore('memory');
66
+ * await memory?.saveThread({ thread: { id: 'thread-1', ... } });
67
+ * }
68
+ * }
69
+ * ```
70
+ */
71
+ export declare class CloudflareDOStorage extends MastraCompositeStore {
72
+ stores: StorageDomains;
73
+ /**
74
+ * Creates a new CloudflareDOStorage instance
75
+ * @param config Configuration for Durable Objects SqlStorage access
76
+ */
77
+ constructor(config: CloudflareDOStorageConfig);
78
+ /**
79
+ * Close the database connection
80
+ * No explicit cleanup needed for DO storage
81
+ */
82
+ close(): Promise<void>;
83
+ }
84
+ /**
85
+ * @deprecated Use CloudflareDOStorage instead
86
+ */
87
+ export declare const DOStore: typeof CloudflareDOStorage;
88
+ /**
89
+ * @deprecated Use CloudflareDOStorageConfig instead
90
+ */
91
+ export type DOStoreConfig = CloudflareDOStorageConfig;
92
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/do/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAE5D,OAAO,EAAwB,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAGjE,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,eAAe,EAAE,kBAAkB,EAAE,CAAC;AAC1F,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,+DAA+D;IAC/D,GAAG,EAAE,UAAU,CAAC;IAChB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,mBAAoB,SAAQ,oBAAoB;IAC3D,MAAM,EAAE,cAAc,CAAC;IAEvB;;;OAGG;gBACS,MAAM,EAAE,yBAAyB;IAiC7C;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7B;AAED;;GAEG;AACH,eAAO,MAAM,OAAO,4BAAsB,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,yBAAyB,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { a as MemoryStorageDO, i as ScoresStorageDO, n as DOStore, o as BackgroundTasksStorageDO, r as WorkflowsStorageDO, s as DODB, t as CloudflareDOStorage } from "../do-BDZtdsky.js";
2
+ export { BackgroundTasksStorageDO, CloudflareDOStorage, DODB, DOStore, MemoryStorageDO, ScoresStorageDO, WorkflowsStorageDO };
@@ -0,0 +1,76 @@
1
+ import type { SqlStorage } from '@cloudflare/workers-types';
2
+ import { MastraBase } from '@mastra/core/base';
3
+ import type { TABLE_NAMES, StorageColumn } from '@mastra/core/storage';
4
+ import type { SqlQueryOptions } from '../sql-builder.js';
5
+ export interface DODBConfig {
6
+ sql: SqlStorage;
7
+ tablePrefix?: string;
8
+ }
9
+ /**
10
+ * Configuration for standalone domain usage with Durable Objects.
11
+ */
12
+ export interface DODomainConfig {
13
+ sql: SqlStorage;
14
+ tablePrefix?: string;
15
+ }
16
+ export declare class DODB extends MastraBase {
17
+ private sql;
18
+ private tablePrefix;
19
+ constructor(config: DODBConfig);
20
+ hasColumn(table: string, column: string): Promise<boolean>;
21
+ getTableName(tableName: TABLE_NAMES): string;
22
+ private formatSqlParams;
23
+ /**
24
+ * Execute a SQL query using Durable Objects SqlStorage.
25
+ * SqlStorage.exec() is synchronous but we wrap in Promise for interface compatibility.
26
+ */
27
+ executeQuery(options: SqlQueryOptions): Promise<Record<string, unknown>[] | Record<string, unknown> | null>;
28
+ private getTableColumns;
29
+ private serializeValue;
30
+ protected getSqlType(type: StorageColumn['type']): string;
31
+ protected getDefaultValue(type: StorageColumn['type']): string;
32
+ createTable({ tableName, schema, }: {
33
+ tableName: TABLE_NAMES;
34
+ schema: Record<string, StorageColumn>;
35
+ }): Promise<void>;
36
+ clearTable({ tableName }: {
37
+ tableName: TABLE_NAMES;
38
+ }): Promise<void>;
39
+ dropTable({ tableName }: {
40
+ tableName: TABLE_NAMES;
41
+ }): Promise<void>;
42
+ alterTable(args: {
43
+ tableName: TABLE_NAMES;
44
+ schema: Record<string, StorageColumn>;
45
+ ifNotExists: string[];
46
+ }): Promise<void>;
47
+ insert({ tableName, record }: {
48
+ tableName: TABLE_NAMES;
49
+ record: Record<string, unknown>;
50
+ }): Promise<void>;
51
+ batchInsert({ tableName, records, }: {
52
+ tableName: TABLE_NAMES;
53
+ records: Record<string, unknown>[];
54
+ }): Promise<void>;
55
+ load<R>({ tableName, keys, orderBy, }: {
56
+ tableName: TABLE_NAMES;
57
+ keys: Record<string, string>;
58
+ orderBy?: {
59
+ column: string;
60
+ direction: 'ASC' | 'DESC';
61
+ };
62
+ }): Promise<R | null>;
63
+ processRecord(record: Record<string, unknown>): Promise<Record<string, unknown>>;
64
+ /**
65
+ * Upsert multiple records in a batch operation
66
+ * @param tableName The table to insert into
67
+ * @param records The records to insert
68
+ * @param conflictKeys The columns to use for conflict detection (defaults to ['id'])
69
+ */
70
+ batchUpsert({ tableName, records, conflictKeys, }: {
71
+ tableName: TABLE_NAMES;
72
+ records: Record<string, unknown>[];
73
+ conflictKeys?: string[];
74
+ }): Promise<void>;
75
+ }
76
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceR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AC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAQtF;;;;;OAKG;IACG,WAAW,CAAC,EAChB,SAAS,EACT,OAAO,EACP,YAAqB,GACtB,EAAE;QACD,SAAS,EAAE,WAAW,CAAC;QACvB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;QACnC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;KACzB,GAAG,OAAO,CAAC,IAAI,CAAC;CAyElB"}
@@ -0,0 +1,18 @@
1
+ import type { BackgroundTask, TaskFilter, TaskListResult, UpdateBackgroundTask } from '@mastra/core/background-tasks';
2
+ import { BackgroundTasksStorage } from '@mastra/core/storage';
3
+ import type { DODomainConfig } from '../../db/index.js';
4
+ export declare class BackgroundTasksStorageDO extends BackgroundTasksStorage {
5
+ #private;
6
+ constructor(config: DODomainConfig);
7
+ init(): Promise<void>;
8
+ dangerouslyClearAll(): Promise<void>;
9
+ createTask(task: BackgroundTask): Promise<void>;
10
+ updateTask(taskId: string, update: UpdateBackgroundTask): Promise<void>;
11
+ getTask(taskId: string): Promise<BackgroundTask | null>;
12
+ listTasks(filter: TaskFilter): Promise<TaskListResult>;
13
+ deleteTask(taskId: string): Promise<void>;
14
+ deleteTasks(filter: TaskFilter): Promise<void>;
15
+ getRunningCount(): Promise<number>;
16
+ getRunningCountByAgent(agentId: string): Promise<number>;
17
+ }
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/do/storage/domains/background-tasks/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,UAAU,EACV,cAAc,EACd,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EACL,sBAAsB,EAIvB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAkD/C,qBAAa,wBAAyB,SAAQ,sBAAsB;;gBAGtD,MAAM,EAAE,cAAc;IAK5B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAYrB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC;IAIpC,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAsC/C,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAwDvE,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC;IAyBvD,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,cAAc,CAAC;IAsEtD,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBzC,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAmC9C,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAKlC,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAI/D"}
@@ -0,0 +1,61 @@
1
+ import type { MastraMessageContentV2 } from '@mastra/core/agent';
2
+ import type { MastraDBMessage, StorageThreadType } from '@mastra/core/memory';
3
+ import { MemoryStorage } from '@mastra/core/storage';
4
+ import type { StorageResourceType, StorageListMessagesInput, StorageListMessagesOutput, StorageListThreadsInput, StorageListThreadsOutput } from '@mastra/core/storage';
5
+ import type { DODomainConfig } from '../../db/index.js';
6
+ export declare class MemoryStorageDO extends MemoryStorage {
7
+ #private;
8
+ constructor(config: DODomainConfig);
9
+ init(): Promise<void>;
10
+ dangerouslyClearAll(): Promise<void>;
11
+ getResourceById({ resourceId }: {
12
+ resourceId: string;
13
+ }): Promise<StorageResourceType | null>;
14
+ saveResource({ resource }: {
15
+ resource: StorageResourceType;
16
+ }): Promise<StorageResourceType>;
17
+ updateResource({ resourceId, workingMemory, metadata, }: {
18
+ resourceId: string;
19
+ workingMemory?: string;
20
+ metadata?: Record<string, unknown>;
21
+ }): Promise<StorageResourceType>;
22
+ getThreadById({ threadId, resourceId, }: {
23
+ threadId: string;
24
+ resourceId?: string;
25
+ }): Promise<StorageThreadType | null>;
26
+ listThreads(args: StorageListThreadsInput): Promise<StorageListThreadsOutput>;
27
+ saveThread({ thread }: {
28
+ thread: StorageThreadType;
29
+ }): Promise<StorageThreadType>;
30
+ updateThread({ id, title, metadata, }: {
31
+ id: string;
32
+ title: string;
33
+ metadata: Record<string, unknown>;
34
+ }): Promise<StorageThreadType>;
35
+ deleteThread({ threadId }: {
36
+ threadId: string;
37
+ }): Promise<void>;
38
+ saveMessages(args: {
39
+ messages: MastraDBMessage[];
40
+ }): Promise<{
41
+ messages: MastraDBMessage[];
42
+ }>;
43
+ private _getIncludedMessages;
44
+ listMessagesById({ messageIds }: {
45
+ messageIds: string[];
46
+ }): Promise<{
47
+ messages: MastraDBMessage[];
48
+ }>;
49
+ listMessages(args: StorageListMessagesInput): Promise<StorageListMessagesOutput>;
50
+ updateMessages(args: {
51
+ messages: (Partial<Omit<MastraDBMessage, 'createdAt'>> & {
52
+ id: string;
53
+ content?: {
54
+ metadata?: MastraMessageContentV2['metadata'];
55
+ content?: MastraMessageContentV2['content'];
56
+ };
57
+ })[];
58
+ }): Promise<MastraDBMessage[]>;
59
+ deleteMessages(messageIds: string[]): Promise<void>;
60
+ }
61
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/do/storage/domains/memory/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAEjE,OAAO,KAAK,EAAmB,eAAe,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC/F,OAAO,EAGL,aAAa,EASd,MAAM,sBAAsB,CAA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import type { StoragePagination, ScoreTenancyFilters } from '@mastra/core/storage';
4
+ import type { DODomainConfig } from '../../db/index.js';
5
+ export declare class ScoresStorageDO extends ScoresStorage {
6
+ #private;
7
+ constructor(config: DODomainConfig);
8
+ init(): Promise<void>;
9
+ dangerouslyClearAll(): Promise<void>;
10
+ getScoreById({ id }: {
11
+ id: string;
12
+ }): Promise<ScoreRowData | null>;
13
+ saveScore(score: SaveScorePayload): Promise<{
14
+ score: ScoreRowData;
15
+ }>;
16
+ listScoresByScorerId({ scorerId, entityId, entityType, source, pagination, filters, }: {
17
+ scorerId: string;
18
+ entityId?: string;
19
+ entityType?: string;
20
+ source?: ScoringSource;
21
+ pagination: StoragePagination;
22
+ filters?: ScoreTenancyFilters;
23
+ }): Promise<ListScoresResponse>;
24
+ listScoresByRunId({ runId, pagination, filters, }: {
25
+ runId: string;
26
+ pagination: StoragePagination;
27
+ filters?: ScoreTenancyFilters;
28
+ }): Promise<ListScoresResponse>;
29
+ listScoresByEntityId({ entityId, entityType, pagination, filters, }: {
30
+ pagination: StoragePagination;
31
+ entityId: string;
32
+ entityType: string;
33
+ filters?: ScoreTenancyFilters;
34
+ }): Promise<ListScoresResponse>;
35
+ listScoresBySpan({ traceId, spanId, pagination, filters, }: {
36
+ traceId: string;
37
+ spanId: string;
38
+ pagination: StoragePagination;
39
+ filters?: ScoreTenancyFilters;
40
+ }): Promise<ListScoresResponse>;
41
+ }
42
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/do/storage/domains/scores/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE5G,OAAO,EAEL,aAAa,EAMd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AA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B,CAAC;IAsEzB,gBAAgB,CAAC,EACrB,OAAO,EACP,MAAM,EACN,UAAU,EACV,OAAO,GACR,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,iBAAiB,CAAC;QAC9B,OAAO,CAAC,EAAE,mBAAmB,CAAC;KAC/B,GAAG,OAAO,CAAC,kBAAkB,CAAC;CAoEhC"}
@@ -0,0 +1,3 @@
1
+ export declare function isArrayOfRecords(value: unknown): value is Record<string, unknown>[];
2
+ export declare function deserializeValue(value: unknown, type?: string): unknown;
3
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/do/storage/domains/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAEnF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAwBvE"}
@@ -0,0 +1,46 @@
1
+ import type { WorkflowRun, WorkflowRuns, StorageListWorkflowRunsInput, UpdateWorkflowStateOptions } from '@mastra/core/storage';
2
+ import { WorkflowsStorage } from '@mastra/core/storage';
3
+ import type { StepResult, WorkflowRunState } from '@mastra/core/workflows';
4
+ import type { DODomainConfig } from '../../db/index.js';
5
+ export declare class WorkflowsStorageDO extends WorkflowsStorage {
6
+ #private;
7
+ constructor(config: DODomainConfig);
8
+ supportsConcurrentUpdates(): boolean;
9
+ init(): Promise<void>;
10
+ dangerouslyClearAll(): Promise<void>;
11
+ updateWorkflowResults({}: {
12
+ workflowName: string;
13
+ runId: string;
14
+ stepId: string;
15
+ result: StepResult<unknown, unknown, unknown, unknown>;
16
+ requestContext: Record<string, unknown>;
17
+ }): Promise<Record<string, StepResult<unknown, unknown, unknown, unknown>>>;
18
+ updateWorkflowState({}: {
19
+ workflowName: string;
20
+ runId: string;
21
+ opts: UpdateWorkflowStateOptions;
22
+ }): Promise<WorkflowRunState | undefined>;
23
+ persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot, createdAt, updatedAt, }: {
24
+ workflowName: string;
25
+ runId: string;
26
+ resourceId?: string;
27
+ snapshot: WorkflowRunState;
28
+ createdAt?: Date;
29
+ updatedAt?: Date;
30
+ }): Promise<void>;
31
+ loadWorkflowSnapshot(params: {
32
+ workflowName: string;
33
+ runId: string;
34
+ }): Promise<WorkflowRunState | null>;
35
+ private parseWorkflowRun;
36
+ listWorkflowRuns({ workflowName, fromDate, toDate, page, perPage, resourceId, status, }?: StorageListWorkflowRunsInput): Promise<WorkflowRuns>;
37
+ getWorkflowRunById({ runId, workflowName, }: {
38
+ runId: string;
39
+ workflowName?: string;
40
+ }): Promise<WorkflowRun | null>;
41
+ deleteWorkflowRunById({ runId, workflowName }: {
42
+ runId: string;
43
+ workflowName: string;
44
+ }): Promise<void>;
45
+ }
46
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/do/storage/domains/workflows/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,YAAY,EACZ,4BAA4B,EAC5B,0BAA0B,EAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAKL,gBAAgB,EACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAK/C,qBAAa,kBAAmB,SAAQ,gBAAgB;;gBAG1C,MAAM,EAAE,cAAc;IAKlC,yBAAyB,IAAI,OAAO;IAK9B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC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D,kBAAkB,CAAC,EACvB,KAAK,EACL,YAAY,GACb,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IAgCzB,qBAAqB,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAmB7G"}
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Type definition for SQL query parameters
3
+ */
4
+ export type SqlParam = string | number | boolean | null | undefined;
5
+ /**
6
+ * Interface for SQL query options with generic type support
7
+ */
8
+ export interface SqlQueryOptions {
9
+ /** SQL query to execute */
10
+ sql: string;
11
+ /** Parameters to bind to the query */
12
+ params?: SqlParam[];
13
+ /** Whether to return only the first result */
14
+ first?: boolean;
15
+ }
16
+ /**
17
+ * SQL Builder class for constructing type-safe SQL queries
18
+ * This helps create maintainable and secure SQL queries with proper parameter handling
19
+ */
20
+ export declare class SqlBuilder {
21
+ private sql;
22
+ private params;
23
+ private whereAdded;
24
+ select(columns?: string | string[]): SqlBuilder;
25
+ from(table: string): SqlBuilder;
26
+ /**
27
+ * Add a WHERE clause to the query
28
+ * @param condition The condition to add
29
+ * @param params Parameters to bind to the condition
30
+ */
31
+ where(condition: string, ...params: SqlParam[]): SqlBuilder;
32
+ /**
33
+ * Add a WHERE clause if it hasn't been added yet, otherwise add an AND clause
34
+ * @param condition The condition to add
35
+ * @param params Parameters to bind to the condition
36
+ */
37
+ whereAnd(condition: string, ...params: SqlParam[]): SqlBuilder;
38
+ andWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
39
+ orWhere(condition: string, ...params: SqlParam[]): SqlBuilder;
40
+ orderBy(column: string, direction?: 'ASC' | 'DESC'): SqlBuilder;
41
+ limit(count: number): SqlBuilder;
42
+ offset(count: number): SqlBuilder;
43
+ count(): SqlBuilder;
44
+ /**
45
+ * Insert a row, or update specific columns on conflict (upsert).
46
+ * @param table Table name
47
+ * @param columns Columns to insert
48
+ * @param values Values to insert
49
+ * @param conflictColumns Columns to check for conflict (usually PK or UNIQUE)
50
+ * @param updateMap Object mapping columns to update to their new value (e.g. { name: 'excluded.name' })
51
+ */
52
+ insert(table: string, columns: string[], values: SqlParam[], conflictColumns?: string[], updateMap?: Record<string, string>): SqlBuilder;
53
+ update(table: string, columns: string[], values: SqlParam[]): SqlBuilder;
54
+ delete(table: string): SqlBuilder;
55
+ /**
56
+ * Create a table if it doesn't exist
57
+ * @param table The table name
58
+ * @param columnDefinitions The column definitions as an array of strings
59
+ * @param tableConstraints Optional constraints for the table
60
+ * @returns The builder instance
61
+ */
62
+ createTable(table: string, columnDefinitions: string[], tableConstraints?: string[]): SqlBuilder;
63
+ /**
64
+ * Check if an index exists in the database
65
+ * @param indexName The name of the index to check
66
+ * @param tableName The table the index is on
67
+ * @returns The builder instance
68
+ */
69
+ checkIndexExists(indexName: string, tableName: string): SqlBuilder;
70
+ /**
71
+ * Create an index if it doesn't exist
72
+ * @param indexName The name of the index to create
73
+ * @param tableName The table to create the index on
74
+ * @param columnName The column to index
75
+ * @param indexType Optional index type (e.g., 'UNIQUE')
76
+ * @returns The builder instance
77
+ */
78
+ createIndex(indexName: string, tableName: string, columnName: string, indexType?: string): SqlBuilder;
79
+ /**
80
+ * Add a LIKE condition to the query
81
+ * @param column The column to check
82
+ * @param value The value to match (will be wrapped with % for LIKE)
83
+ * @param exact If true, will not add % wildcards
84
+ */
85
+ like(column: string, value: string, exact?: boolean): SqlBuilder;
86
+ /**
87
+ * Add a JSON LIKE condition for searching in JSON fields
88
+ * @param column The JSON column to search in
89
+ * @param key The JSON key to match
90
+ * @param value The value to match
91
+ */
92
+ jsonLike(column: string, key: string, value: string): SqlBuilder;
93
+ /**
94
+ * Get the built query
95
+ * @returns Object containing the SQL string and parameters array
96
+ */
97
+ build(): {
98
+ sql: string;
99
+ params: SqlParam[];
100
+ };
101
+ /**
102
+ * Reset the builder for reuse
103
+ * @returns The reset builder instance
104
+ */
105
+ reset(): SqlBuilder;
106
+ }
107
+ export declare function createSqlBuilder(): SqlBuilder;
108
+ /** Represents a validated SQL SELECT column identifier (or '*', optionally with 'AS alias'). */
109
+ type SelectIdentifier = string & {
110
+ __brand: 'SelectIdentifier';
111
+ };
112
+ /**
113
+ * Parses and returns a valid SQL SELECT column identifier.
114
+ * Allows a single identifier (letters, numbers, underscores), or '*', optionally with 'AS alias'.
115
+ *
116
+ * @param column - The column identifier string to parse.
117
+ * @returns The validated column identifier as a branded type.
118
+ * @throws {Error} If invalid.
119
+ *
120
+ * @example
121
+ * const col = parseSelectIdentifier('user_id'); // Ok
122
+ * parseSelectIdentifier('user_id AS uid'); // Ok
123
+ * parseSelectIdentifier('*'); // Ok
124
+ * parseSelectIdentifier('user id'); // Throws error
125
+ */
126
+ export declare function parseSelectIdentifier(column: string): SelectIdentifier;
127
+ export {};
128
+ //# sourceMappingURL=sql-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-builder.d.ts","sourceRoot":"","sources":["../../../src/do/storage/sql-builder.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,2BAA2B;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,sCAAsC;IACtC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC;IACpB,8CAA8C;IAC9C,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;GAGG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,GAAG,CAAc;IACzB,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,UAAU,CAAkB;IAGpC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,E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