@mastra/pg 1.0.0-beta.10 → 1.0.0-beta.12

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/CHANGELOG.md CHANGED
@@ -1,5 +1,148 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.0.0-beta.12
4
+
5
+ ### Patch Changes
6
+
7
+ - Add embedded documentation support for Mastra packages ([#11472](https://github.com/mastra-ai/mastra/pull/11472))
8
+
9
+ Mastra packages now include embedded documentation in the published npm package under `dist/docs/`. This enables coding agents and AI assistants to understand and use the framework by reading documentation directly from `node_modules`.
10
+
11
+ Each package includes:
12
+ - **SKILL.md** - Entry point explaining the package's purpose and capabilities
13
+ - **SOURCE_MAP.json** - Machine-readable index mapping exports to types and implementation files
14
+ - **Topic folders** - Conceptual documentation organized by feature area
15
+
16
+ Documentation is driven by the `packages` frontmatter field in MDX files, which maps docs to their corresponding packages. CI validation ensures all docs include this field.
17
+
18
+ - Added `startExclusive` and `endExclusive` options to `dateRange` filter for message queries. ([#11479](https://github.com/mastra-ai/mastra/pull/11479))
19
+
20
+ **What changed:** The `filter.dateRange` parameter in `listMessages()` and `Memory.recall()` now supports `startExclusive` and `endExclusive` boolean options. When set to `true`, messages with timestamps exactly matching the boundary are excluded from results.
21
+
22
+ **Why this matters:** Enables cursor-based pagination for chat applications. When new messages arrive during a session, offset-based pagination can skip or duplicate messages. Using `endExclusive: true` with the oldest message's timestamp as a cursor ensures consistent pagination without gaps or duplicates.
23
+
24
+ **Example:**
25
+
26
+ ```typescript
27
+ // Get first page
28
+ const page1 = await memory.recall({
29
+ threadId: 'thread-123',
30
+ perPage: 10,
31
+ orderBy: { field: 'createdAt', direction: 'DESC' },
32
+ });
33
+
34
+ // Get next page using cursor-based pagination
35
+ const oldestMessage = page1.messages[page1.messages.length - 1];
36
+ const page2 = await memory.recall({
37
+ threadId: 'thread-123',
38
+ perPage: 10,
39
+ orderBy: { field: 'createdAt', direction: 'DESC' },
40
+ filter: {
41
+ dateRange: {
42
+ end: oldestMessage.createdAt,
43
+ endExclusive: true, // Excludes the cursor message
44
+ },
45
+ },
46
+ });
47
+ ```
48
+
49
+ - Fix thread timestamps being returned in incorrect timezone from listThreadsByResourceId ([#11498](https://github.com/mastra-ai/mastra/pull/11498))
50
+
51
+ The method was not using the timezone-aware columns (createdAtZ/updatedAtZ), causing timestamps to be interpreted in local timezone instead of UTC. Now correctly uses TIMESTAMPTZ columns with fallback for legacy data.
52
+
53
+ - Adds thread cloning to create independent copies of conversations that can diverge. ([#11517](https://github.com/mastra-ai/mastra/pull/11517))
54
+
55
+ ```typescript
56
+ // Clone a thread
57
+ const { thread, clonedMessages } = await memory.cloneThread({
58
+ sourceThreadId: 'thread-123',
59
+ title: 'My Clone',
60
+ options: {
61
+ messageLimit: 10, // optional: only copy last N messages
62
+ },
63
+ });
64
+
65
+ // Check if a thread is a clone
66
+ if (memory.isClone(thread)) {
67
+ const source = await memory.getSourceThread(thread.id);
68
+ }
69
+
70
+ // List all clones of a thread
71
+ const clones = await memory.listClones('thread-123');
72
+ ```
73
+
74
+ Includes:
75
+ - Storage implementations for InMemory, PostgreSQL, LibSQL, Upstash
76
+ - API endpoint: `POST /api/memory/threads/:threadId/clone`
77
+ - Embeddings created for cloned messages (semantic recall)
78
+ - Clone button in playground UI Memory tab
79
+
80
+ - Updated dependencies [[`d2d3e22`](https://github.com/mastra-ai/mastra/commit/d2d3e22a419ee243f8812a84e3453dd44365ecb0), [`bc72b52`](https://github.com/mastra-ai/mastra/commit/bc72b529ee4478fe89ecd85a8be47ce0127b82a0), [`05b8bee`](https://github.com/mastra-ai/mastra/commit/05b8bee9e50e6c2a4a2bf210eca25ee212ca24fa), [`c042bd0`](https://github.com/mastra-ai/mastra/commit/c042bd0b743e0e86199d0cb83344ca7690e34a9c), [`940a2b2`](https://github.com/mastra-ai/mastra/commit/940a2b27480626ed7e74f55806dcd2181c1dd0c2), [`e0941c3`](https://github.com/mastra-ai/mastra/commit/e0941c3d7fc75695d5d258e7008fd5d6e650800c), [`0c0580a`](https://github.com/mastra-ai/mastra/commit/0c0580a42f697cd2a7d5973f25bfe7da9055038a), [`28f5f89`](https://github.com/mastra-ai/mastra/commit/28f5f89705f2409921e3c45178796c0e0d0bbb64), [`e601b27`](https://github.com/mastra-ai/mastra/commit/e601b272c70f3a5ecca610373aa6223012704892), [`3d3366f`](https://github.com/mastra-ai/mastra/commit/3d3366f31683e7137d126a3a57174a222c5801fb), [`5a4953f`](https://github.com/mastra-ai/mastra/commit/5a4953f7d25bb15ca31ed16038092a39cb3f98b3), [`eb9e522`](https://github.com/mastra-ai/mastra/commit/eb9e522ce3070a405e5b949b7bf5609ca51d7fe2), [`20e6f19`](https://github.com/mastra-ai/mastra/commit/20e6f1971d51d3ff6dd7accad8aaaae826d540ed), [`4f0b3c6`](https://github.com/mastra-ai/mastra/commit/4f0b3c66f196c06448487f680ccbb614d281e2f7), [`74c4f22`](https://github.com/mastra-ai/mastra/commit/74c4f22ed4c71e72598eacc346ba95cdbc00294f), [`81b6a8f`](https://github.com/mastra-ai/mastra/commit/81b6a8ff79f49a7549d15d66624ac1a0b8f5f971), [`e4d366a`](https://github.com/mastra-ai/mastra/commit/e4d366aeb500371dd4210d6aa8361a4c21d87034), [`a4f010b`](https://github.com/mastra-ai/mastra/commit/a4f010b22e4355a5fdee70a1fe0f6e4a692cc29e), [`73b0bb3`](https://github.com/mastra-ai/mastra/commit/73b0bb394dba7c9482eb467a97ab283dbc0ef4db), [`5627a8c`](https://github.com/mastra-ai/mastra/commit/5627a8c6dc11fe3711b3fa7a6ffd6eb34100a306), [`3ff45d1`](https://github.com/mastra-ai/mastra/commit/3ff45d10e0c80c5335a957ab563da72feb623520), [`251df45`](https://github.com/mastra-ai/mastra/commit/251df4531407dfa46d805feb40ff3fb49769f455), [`f894d14`](https://github.com/mastra-ai/mastra/commit/f894d148946629af7b1f452d65a9cf864cec3765), [`c2b9547`](https://github.com/mastra-ai/mastra/commit/c2b9547bf435f56339f23625a743b2147ab1c7a6), [`580b592`](https://github.com/mastra-ai/mastra/commit/580b5927afc82fe460dfdf9a38a902511b6b7e7f), [`58e3931`](https://github.com/mastra-ai/mastra/commit/58e3931af9baa5921688566210f00fb0c10479fa), [`08bb631`](https://github.com/mastra-ai/mastra/commit/08bb631ae2b14684b2678e3549d0b399a6f0561e), [`4fba91b`](https://github.com/mastra-ai/mastra/commit/4fba91bec7c95911dc28e369437596b152b04cd0), [`12b0cc4`](https://github.com/mastra-ai/mastra/commit/12b0cc4077d886b1a552637dedb70a7ade93528c)]:
81
+ - @mastra/core@1.0.0-beta.20
82
+
83
+ ## 1.0.0-beta.11
84
+
85
+ ### Minor Changes
86
+
87
+ - Remove pg-promise dependency and use pg.Pool directly ([#11450](https://github.com/mastra-ai/mastra/pull/11450))
88
+
89
+ **BREAKING CHANGE**: This release replaces pg-promise with vanilla node-postgres (`pg`).
90
+
91
+ ### Breaking Changes
92
+ - **Removed `store.pgp`**: The pg-promise library instance is no longer exposed
93
+ - **Config change**: `{ client: pgPromiseDb }` is no longer supported. Use `{ pool: pgPool }` instead
94
+ - **Cloud SQL config**: `max` and `idleTimeoutMillis` must now be passed via `pgPoolOptions`
95
+
96
+ ### New Features
97
+ - **`store.pool`**: Exposes the underlying `pg.Pool` for direct database access or ORM integration (e.g., Drizzle)
98
+ - **`store.db`**: Provides a `DbClient` interface with methods like `one()`, `any()`, `tx()`, etc.
99
+ - **`store.db.connect()`**: Acquire a client for session-level operations
100
+
101
+ ### Migration
102
+
103
+ ```typescript
104
+ // Before (pg-promise)
105
+ import pgPromise from 'pg-promise';
106
+ const pgp = pgPromise();
107
+ const client = pgp(connectionString);
108
+ const store = new PostgresStore({ id: 'my-store', client });
109
+
110
+ // After (pg.Pool)
111
+ import { Pool } from 'pg';
112
+ const pool = new Pool({ connectionString });
113
+ const store = new PostgresStore({ id: 'my-store', pool });
114
+
115
+ // Use store.pool with any library that accepts a pg.Pool
116
+ ```
117
+
118
+ ### Patch Changes
119
+
120
+ - Added `exportSchemas()` function to generate Mastra database schema as SQL DDL without a database connection. ([#11448](https://github.com/mastra-ai/mastra/pull/11448))
121
+
122
+ **What's New**
123
+
124
+ You can now export your Mastra database schema as SQL DDL statements without connecting to a database. This is useful for:
125
+ - Generating migration scripts
126
+ - Reviewing the schema before deployment
127
+ - Creating database schemas in environments where the application doesn't have CREATE privileges
128
+
129
+ **Example**
130
+
131
+ ```typescript
132
+ import { exportSchemas } from '@mastra/pg';
133
+
134
+ // Export schema for default 'public' schema
135
+ const ddl = exportSchemas();
136
+ console.log(ddl);
137
+
138
+ // Export schema for a custom schema
139
+ const customDdl = exportSchemas('my_schema');
140
+ // Creates: CREATE SCHEMA IF NOT EXISTS "my_schema"; and all tables within it
141
+ ```
142
+
143
+ - Updated dependencies [[`e54953e`](https://github.com/mastra-ai/mastra/commit/e54953ed8ce1b28c0d62a19950163039af7834b4), [`7d56d92`](https://github.com/mastra-ai/mastra/commit/7d56d9213886e8353956d7d40df10045fd12b299), [`fdac646`](https://github.com/mastra-ai/mastra/commit/fdac646033a0930a1a4e00d13aa64c40bb7f1e02), [`d07b568`](https://github.com/mastra-ai/mastra/commit/d07b5687819ea8cb1dffa776d0c1765faf4aa1ae), [`68ec97d`](https://github.com/mastra-ai/mastra/commit/68ec97d4c07c6393fcf95c2481fc5d73da99f8c8), [`4aa55b3`](https://github.com/mastra-ai/mastra/commit/4aa55b383cf06043943359ea316572fd969861a7)]:
144
+ - @mastra/core@1.0.0-beta.19
145
+
3
146
  ## 1.0.0-beta.10
4
147
 
5
148
  ### Patch Changes
@@ -0,0 +1,36 @@
1
+ # @mastra/pg Documentation
2
+
3
+ > Embedded documentation for coding agents
4
+
5
+ ## Quick Start
6
+
7
+ ```bash
8
+ # Read the skill overview
9
+ cat docs/SKILL.md
10
+
11
+ # Get the source map
12
+ cat docs/SOURCE_MAP.json
13
+
14
+ # Read topic documentation
15
+ cat docs/<topic>/01-overview.md
16
+ ```
17
+
18
+ ## Structure
19
+
20
+ ```
21
+ docs/
22
+ ├── SKILL.md # Entry point
23
+ ├── README.md # This file
24
+ ├── SOURCE_MAP.json # Export index
25
+ ├── memory/ (4 files)
26
+ ├── processors/ (3 files)
27
+ ├── rag/ (4 files)
28
+ ├── storage/ (3 files)
29
+ ├── tools/ (1 files)
30
+ ├── vectors/ (1 files)
31
+ ```
32
+
33
+ ## Version
34
+
35
+ Package: @mastra/pg
36
+ Version: 1.0.0-beta.12
@@ -0,0 +1,37 @@
1
+ ---
2
+ name: mastra-pg-docs
3
+ description: Documentation for @mastra/pg. Includes links to type definitions and readable implementation code in dist/.
4
+ ---
5
+
6
+ # @mastra/pg Documentation
7
+
8
+ > **Version**: 1.0.0-beta.12
9
+ > **Package**: @mastra/pg
10
+
11
+ ## Quick Navigation
12
+
13
+ Use SOURCE_MAP.json to find any export:
14
+
15
+ ```bash
16
+ cat docs/SOURCE_MAP.json
17
+ ```
18
+
19
+ Each export maps to:
20
+ - **types**: `.d.ts` file with JSDoc and API signatures
21
+ - **implementation**: `.js` chunk file with readable source
22
+ - **docs**: Conceptual documentation in `docs/`
23
+
24
+ ## Top Exports
25
+
26
+
27
+
28
+ See SOURCE_MAP.json for the complete list.
29
+
30
+ ## Available Topics
31
+
32
+ - [Memory](memory/) - 4 file(s)
33
+ - [Processors](processors/) - 3 file(s)
34
+ - [Rag](rag/) - 4 file(s)
35
+ - [Storage](storage/) - 3 file(s)
36
+ - [Tools](tools/) - 1 file(s)
37
+ - [Vectors](vectors/) - 1 file(s)
@@ -0,0 +1,6 @@
1
+ {
2
+ "version": "1.0.0-beta.12",
3
+ "package": "@mastra/pg",
4
+ "exports": {},
5
+ "modules": {}
6
+ }
@@ -0,0 +1,181 @@
1
+ > Configure storage for Mastra
2
+
3
+ # Storage
4
+
5
+ For Mastra to remember previous interactions, you must configure a storage adapter. Mastra is designed to work with your preferred database provider - choose from the [supported providers](#supported-providers) and pass it to your Mastra instance.
6
+
7
+ ```typescript
8
+ import { Mastra } from "@mastra/core";
9
+ import { LibSQLStore } from "@mastra/libsql";
10
+
11
+ const mastra = new Mastra({
12
+ storage: new LibSQLStore({
13
+ id: 'mastra-storage',
14
+ url: "file:./mastra.db",
15
+ }),
16
+ });
17
+ ```
18
+ On first interaction, Mastra automatically creates the necessary tables following the [core schema](https://mastra.ai/reference/v1/storage/overview#core-schema). This includes tables for messages, threads, resources, workflows, traces, and evaluation datasets.
19
+
20
+ ## Supported Providers
21
+
22
+ Each provider page includes installation instructions, configuration parameters, and usage examples:
23
+
24
+ - [libSQL Storage](https://mastra.ai/reference/v1/storage/libsql)
25
+ - [PostgreSQL Storage](https://mastra.ai/reference/v1/storage/postgresql)
26
+ - [MongoDB Storage](https://mastra.ai/reference/v1/storage/mongodb)
27
+ - [Upstash Storage](https://mastra.ai/reference/v1/storage/upstash)
28
+ - [Cloudflare D1](https://mastra.ai/reference/v1/storage/cloudflare-d1)
29
+ - [Cloudflare Durable Objects](https://mastra.ai/reference/v1/storage/cloudflare)
30
+ - [Convex](https://mastra.ai/reference/v1/storage/convex)
31
+ - [DynamoDB](https://mastra.ai/reference/v1/storage/dynamodb)
32
+ - [LanceDB](https://mastra.ai/reference/v1/storage/lance)
33
+ - [Microsoft SQL Server](https://mastra.ai/reference/v1/storage/mssql)
34
+
35
+ > **Note:**
36
+ libSQL is the easiest way to get started because it doesn’t require running a separate database server
37
+
38
+ ## Configuration Scope
39
+
40
+ You can configure storage at two different scopes:
41
+
42
+ ### Instance-level storage
43
+
44
+ Add storage to your Mastra instance so all agents share the same memory provider:
45
+
46
+ ```typescript
47
+ import { Mastra } from "@mastra/core";
48
+ import { PostgresStore } from "@mastra/pg";
49
+
50
+ const mastra = new Mastra({
51
+ storage: new PostgresStore({
52
+ id: 'mastra-storage',
53
+ connectionString: process.env.DATABASE_URL,
54
+ }),
55
+ });
56
+
57
+ // All agents automatically use this storage
58
+ const agent1 = new Agent({ memory: new Memory() });
59
+ const agent2 = new Agent({ memory: new Memory() });
60
+ ```
61
+
62
+ ### Agent-level storage
63
+
64
+ Add storage to a specific agent when you need data boundaries or compliance requirements:
65
+
66
+ ```typescript
67
+ import { Agent } from "@mastra/core/agent";
68
+ import { Memory } from "@mastra/memory";
69
+ import { PostgresStore } from "@mastra/pg";
70
+
71
+ const agent = new Agent({
72
+ memory: new Memory({
73
+ storage: new PostgresStore({
74
+ id: 'agent-storage',
75
+ connectionString: process.env.AGENT_DATABASE_URL,
76
+ }),
77
+ }),
78
+ });
79
+ ```
80
+
81
+ This is useful when different agents need to store data in separate databases for security, compliance, or organizational reasons.
82
+
83
+ ## Threads and Resources
84
+
85
+ Mastra organizes memory into threads using two identifiers:
86
+
87
+ - **Thread**: A conversation session containing a sequence of messages (e.g., `convo_123`)
88
+ - **Resource**: An identifier for the entity the thread belongs to, typically a user (e.g., `user_123`)
89
+
90
+ Both identifiers are required for agents to store and recall information:
91
+
92
+ ```typescript
93
+ const stream = await agent.stream("message for agent", {
94
+ memory: {
95
+ thread: "convo_123",
96
+ resource: "user_123",
97
+ },
98
+ });
99
+ ```
100
+
101
+ > **Note:**
102
+ [Studio](https://mastra.ai/docs/v1/getting-started/studio) automatically generates a thread and resource ID for you. Remember to to pass these explicitly when calling `stream` or `generate` yourself.
103
+
104
+ ### Thread title generation
105
+
106
+ Mastra can automatically generate descriptive thread titles based on the user's first message.
107
+
108
+ Use this option when implementing a ChatGPT-style chat interface to render a title alongside each thread in the conversation list (for example, in a sidebar) derived from the thread’s initial user message.
109
+
110
+ ```typescript
111
+ export const testAgent = new Agent({
112
+ memory: new Memory({
113
+ options: {
114
+ generateTitle: true,
115
+ },
116
+ }),
117
+ });
118
+ ```
119
+
120
+ Title generation runs asynchronously after the agent responds and does not affect response time.
121
+
122
+ To optimize cost or behavior, provide a smaller `model` and custom `instructions`:
123
+
124
+ ```typescript
125
+ export const testAgent = new Agent({
126
+ memory: new Memory({
127
+ options: {
128
+ threads: {
129
+ generateTitle: {
130
+ model: "openai/gpt-4o-mini",
131
+ instructions: "Generate a concise title based on the user's first message",
132
+ },
133
+ },
134
+ },
135
+ }),
136
+ });
137
+ ```
138
+
139
+ ## Semantic recall
140
+
141
+ Semantic recall uses vector embeddings to retrieve relevant past messages based on meaning rather than recency. This requires a vector database instance, which can be configured at the instance or agent level.
142
+
143
+ The vector database doesn't have to be the same as your storage provider. For example, you might use PostgreSQL for storage and Pinecone for vectors:
144
+
145
+ ```typescript
146
+ import { Mastra } from "@mastra/core";
147
+ import { Agent } from "@mastra/core/agent";
148
+ import { Memory } from "@mastra/memory";
149
+ import { PostgresStore } from "@mastra/pg";
150
+ import { PineconeVector } from "@mastra/pinecone";
151
+
152
+ // Instance-level vector configuration
153
+ const mastra = new Mastra({
154
+ storage: new PostgresStore({
155
+ id: 'mastra-storage',
156
+ connectionString: process.env.DATABASE_URL,
157
+ }),
158
+ });
159
+
160
+ // Agent-level vector configuration
161
+ const agent = new Agent({
162
+ memory: new Memory({
163
+ vector: new PineconeVector({
164
+ id: 'agent-vector',
165
+ apiKey: process.env.PINECONE_API_KEY,
166
+ environment: process.env.PINECONE_ENVIRONMENT,
167
+ indexName: 'agent-embeddings',
168
+ }),
169
+ options: {
170
+ semanticRecall: {
171
+ topK: 5,
172
+ messageRange: 2,
173
+ },
174
+ },
175
+ }),
176
+ });
177
+ ```
178
+
179
+ We support all popular vector providers including [Pinecone](https://mastra.ai/reference/v1/vectors/pinecone), [Chroma](https://mastra.ai/reference/v1/vectors/chroma), [Qdrant](https://mastra.ai/reference/v1/vectors/qdrant), and many more.
180
+
181
+ For more information on configuring semantic recall, see the [Semantic Recall](./semantic-recall) documentation.