@minion-stack/db 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pg/schema/agent-memories.d.ts +281 -0
- package/dist/pg/schema/agent-memories.d.ts.map +1 -0
- package/dist/pg/schema/agent-memories.js +59 -0
- package/dist/pg/schema/agent-memories.js.map +1 -0
- package/dist/pg/schema/index.d.ts +1 -0
- package/dist/pg/schema/index.d.ts.map +1 -1
- package/dist/pg/schema/index.js +2 -0
- package/dist/pg/schema/index.js.map +1 -1
- package/package.json +1 -1
- package/src/pg/schema/agent-memories.ts +73 -0
- package/src/pg/schema/index.ts +2 -0
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Org-scoped agent memory corpus with pgvector embeddings. This is the
|
|
3
|
+
* system-of-record home for agent memories (migrated off the gateway-local
|
|
4
|
+
* LanceDB store): semantic memory, session-memory summaries, and captured
|
|
5
|
+
* facts/preferences/decisions/entities. Both the hub (visualization) and the
|
|
6
|
+
* flow runner (RAG retrieval) read from here.
|
|
7
|
+
*
|
|
8
|
+
* Embedding dimension matches OpenAI `text-embedding-3-small` (1536). If the
|
|
9
|
+
* embedding model changes, add a new column / table rather than mixing
|
|
10
|
+
* dimensions in one column.
|
|
11
|
+
*
|
|
12
|
+
* RLS (org isolation) is added in the hand-written companion migration
|
|
13
|
+
* `<ts>_agent_memories_rls.sql` (role app_ledger + app.current_org_id GUC),
|
|
14
|
+
* mirroring `messages`. Drizzle does not manage roles/policies, the `vector`
|
|
15
|
+
* extension, or the HNSW index — those live in the companion SQL.
|
|
16
|
+
*/
|
|
17
|
+
export declare const agentMemories: import("drizzle-orm/pg-core").PgTableWithColumns<{
|
|
18
|
+
name: "agent_memories";
|
|
19
|
+
schema: undefined;
|
|
20
|
+
columns: {
|
|
21
|
+
id: import("drizzle-orm/pg-core").PgColumn<{
|
|
22
|
+
name: "id";
|
|
23
|
+
tableName: "agent_memories";
|
|
24
|
+
dataType: "string";
|
|
25
|
+
columnType: "PgUUID";
|
|
26
|
+
data: string;
|
|
27
|
+
driverParam: string;
|
|
28
|
+
notNull: true;
|
|
29
|
+
hasDefault: true;
|
|
30
|
+
isPrimaryKey: true;
|
|
31
|
+
isAutoincrement: false;
|
|
32
|
+
hasRuntimeDefault: false;
|
|
33
|
+
enumValues: undefined;
|
|
34
|
+
baseColumn: never;
|
|
35
|
+
identity: undefined;
|
|
36
|
+
generated: undefined;
|
|
37
|
+
}, {}, {}>;
|
|
38
|
+
orgId: import("drizzle-orm/pg-core").PgColumn<{
|
|
39
|
+
name: "org_id";
|
|
40
|
+
tableName: "agent_memories";
|
|
41
|
+
dataType: "string";
|
|
42
|
+
columnType: "PgText";
|
|
43
|
+
data: string;
|
|
44
|
+
driverParam: string;
|
|
45
|
+
notNull: true;
|
|
46
|
+
hasDefault: false;
|
|
47
|
+
isPrimaryKey: false;
|
|
48
|
+
isAutoincrement: false;
|
|
49
|
+
hasRuntimeDefault: false;
|
|
50
|
+
enumValues: [string, ...string[]];
|
|
51
|
+
baseColumn: never;
|
|
52
|
+
identity: undefined;
|
|
53
|
+
generated: undefined;
|
|
54
|
+
}, {}, {}>;
|
|
55
|
+
gatewayId: import("drizzle-orm/pg-core").PgColumn<{
|
|
56
|
+
name: "gateway_id";
|
|
57
|
+
tableName: "agent_memories";
|
|
58
|
+
dataType: "string";
|
|
59
|
+
columnType: "PgText";
|
|
60
|
+
data: string;
|
|
61
|
+
driverParam: string;
|
|
62
|
+
notNull: false;
|
|
63
|
+
hasDefault: false;
|
|
64
|
+
isPrimaryKey: false;
|
|
65
|
+
isAutoincrement: false;
|
|
66
|
+
hasRuntimeDefault: false;
|
|
67
|
+
enumValues: [string, ...string[]];
|
|
68
|
+
baseColumn: never;
|
|
69
|
+
identity: undefined;
|
|
70
|
+
generated: undefined;
|
|
71
|
+
}, {}, {}>;
|
|
72
|
+
agentId: import("drizzle-orm/pg-core").PgColumn<{
|
|
73
|
+
name: "agent_id";
|
|
74
|
+
tableName: "agent_memories";
|
|
75
|
+
dataType: "string";
|
|
76
|
+
columnType: "PgText";
|
|
77
|
+
data: string;
|
|
78
|
+
driverParam: string;
|
|
79
|
+
notNull: true;
|
|
80
|
+
hasDefault: false;
|
|
81
|
+
isPrimaryKey: false;
|
|
82
|
+
isAutoincrement: false;
|
|
83
|
+
hasRuntimeDefault: false;
|
|
84
|
+
enumValues: [string, ...string[]];
|
|
85
|
+
baseColumn: never;
|
|
86
|
+
identity: undefined;
|
|
87
|
+
generated: undefined;
|
|
88
|
+
}, {}, {}>;
|
|
89
|
+
profileId: import("drizzle-orm/pg-core").PgColumn<{
|
|
90
|
+
name: "profile_id";
|
|
91
|
+
tableName: "agent_memories";
|
|
92
|
+
dataType: "string";
|
|
93
|
+
columnType: "PgUUID";
|
|
94
|
+
data: string;
|
|
95
|
+
driverParam: string;
|
|
96
|
+
notNull: false;
|
|
97
|
+
hasDefault: false;
|
|
98
|
+
isPrimaryKey: false;
|
|
99
|
+
isAutoincrement: false;
|
|
100
|
+
hasRuntimeDefault: false;
|
|
101
|
+
enumValues: undefined;
|
|
102
|
+
baseColumn: never;
|
|
103
|
+
identity: undefined;
|
|
104
|
+
generated: undefined;
|
|
105
|
+
}, {}, {}>;
|
|
106
|
+
content: import("drizzle-orm/pg-core").PgColumn<{
|
|
107
|
+
name: "content";
|
|
108
|
+
tableName: "agent_memories";
|
|
109
|
+
dataType: "string";
|
|
110
|
+
columnType: "PgText";
|
|
111
|
+
data: string;
|
|
112
|
+
driverParam: string;
|
|
113
|
+
notNull: true;
|
|
114
|
+
hasDefault: false;
|
|
115
|
+
isPrimaryKey: false;
|
|
116
|
+
isAutoincrement: false;
|
|
117
|
+
hasRuntimeDefault: false;
|
|
118
|
+
enumValues: [string, ...string[]];
|
|
119
|
+
baseColumn: never;
|
|
120
|
+
identity: undefined;
|
|
121
|
+
generated: undefined;
|
|
122
|
+
}, {}, {}>;
|
|
123
|
+
embedding: import("drizzle-orm/pg-core").PgColumn<{
|
|
124
|
+
name: "embedding";
|
|
125
|
+
tableName: "agent_memories";
|
|
126
|
+
dataType: "array";
|
|
127
|
+
columnType: "PgVector";
|
|
128
|
+
data: number[];
|
|
129
|
+
driverParam: string;
|
|
130
|
+
notNull: false;
|
|
131
|
+
hasDefault: false;
|
|
132
|
+
isPrimaryKey: false;
|
|
133
|
+
isAutoincrement: false;
|
|
134
|
+
hasRuntimeDefault: false;
|
|
135
|
+
enumValues: undefined;
|
|
136
|
+
baseColumn: never;
|
|
137
|
+
identity: undefined;
|
|
138
|
+
generated: undefined;
|
|
139
|
+
}, {}, {
|
|
140
|
+
dimensions: 1536;
|
|
141
|
+
}>;
|
|
142
|
+
category: import("drizzle-orm/pg-core").PgColumn<{
|
|
143
|
+
name: "category";
|
|
144
|
+
tableName: "agent_memories";
|
|
145
|
+
dataType: "string";
|
|
146
|
+
columnType: "PgText";
|
|
147
|
+
data: "preference" | "fact" | "decision" | "entity" | "other";
|
|
148
|
+
driverParam: string;
|
|
149
|
+
notNull: true;
|
|
150
|
+
hasDefault: true;
|
|
151
|
+
isPrimaryKey: false;
|
|
152
|
+
isAutoincrement: false;
|
|
153
|
+
hasRuntimeDefault: false;
|
|
154
|
+
enumValues: ["preference", "fact", "decision", "entity", "other"];
|
|
155
|
+
baseColumn: never;
|
|
156
|
+
identity: undefined;
|
|
157
|
+
generated: undefined;
|
|
158
|
+
}, {}, {}>;
|
|
159
|
+
importance: import("drizzle-orm/pg-core").PgColumn<{
|
|
160
|
+
name: "importance";
|
|
161
|
+
tableName: "agent_memories";
|
|
162
|
+
dataType: "number";
|
|
163
|
+
columnType: "PgReal";
|
|
164
|
+
data: number;
|
|
165
|
+
driverParam: string | number;
|
|
166
|
+
notNull: true;
|
|
167
|
+
hasDefault: true;
|
|
168
|
+
isPrimaryKey: false;
|
|
169
|
+
isAutoincrement: false;
|
|
170
|
+
hasRuntimeDefault: false;
|
|
171
|
+
enumValues: undefined;
|
|
172
|
+
baseColumn: never;
|
|
173
|
+
identity: undefined;
|
|
174
|
+
generated: undefined;
|
|
175
|
+
}, {}, {}>;
|
|
176
|
+
source: import("drizzle-orm/pg-core").PgColumn<{
|
|
177
|
+
name: "source";
|
|
178
|
+
tableName: "agent_memories";
|
|
179
|
+
dataType: "string";
|
|
180
|
+
columnType: "PgText";
|
|
181
|
+
data: string;
|
|
182
|
+
driverParam: string;
|
|
183
|
+
notNull: true;
|
|
184
|
+
hasDefault: true;
|
|
185
|
+
isPrimaryKey: false;
|
|
186
|
+
isAutoincrement: false;
|
|
187
|
+
hasRuntimeDefault: false;
|
|
188
|
+
enumValues: [string, ...string[]];
|
|
189
|
+
baseColumn: never;
|
|
190
|
+
identity: undefined;
|
|
191
|
+
generated: undefined;
|
|
192
|
+
}, {}, {}>;
|
|
193
|
+
sourceId: import("drizzle-orm/pg-core").PgColumn<{
|
|
194
|
+
name: "source_id";
|
|
195
|
+
tableName: "agent_memories";
|
|
196
|
+
dataType: "string";
|
|
197
|
+
columnType: "PgText";
|
|
198
|
+
data: string;
|
|
199
|
+
driverParam: string;
|
|
200
|
+
notNull: false;
|
|
201
|
+
hasDefault: false;
|
|
202
|
+
isPrimaryKey: false;
|
|
203
|
+
isAutoincrement: false;
|
|
204
|
+
hasRuntimeDefault: false;
|
|
205
|
+
enumValues: [string, ...string[]];
|
|
206
|
+
baseColumn: never;
|
|
207
|
+
identity: undefined;
|
|
208
|
+
generated: undefined;
|
|
209
|
+
}, {}, {}>;
|
|
210
|
+
occurredAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
211
|
+
name: "occurred_at";
|
|
212
|
+
tableName: "agent_memories";
|
|
213
|
+
dataType: "date";
|
|
214
|
+
columnType: "PgTimestamp";
|
|
215
|
+
data: Date;
|
|
216
|
+
driverParam: string;
|
|
217
|
+
notNull: false;
|
|
218
|
+
hasDefault: false;
|
|
219
|
+
isPrimaryKey: false;
|
|
220
|
+
isAutoincrement: false;
|
|
221
|
+
hasRuntimeDefault: false;
|
|
222
|
+
enumValues: undefined;
|
|
223
|
+
baseColumn: never;
|
|
224
|
+
identity: undefined;
|
|
225
|
+
generated: undefined;
|
|
226
|
+
}, {}, {}>;
|
|
227
|
+
createdAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
228
|
+
name: "created_at";
|
|
229
|
+
tableName: "agent_memories";
|
|
230
|
+
dataType: "date";
|
|
231
|
+
columnType: "PgTimestamp";
|
|
232
|
+
data: Date;
|
|
233
|
+
driverParam: string;
|
|
234
|
+
notNull: true;
|
|
235
|
+
hasDefault: true;
|
|
236
|
+
isPrimaryKey: false;
|
|
237
|
+
isAutoincrement: false;
|
|
238
|
+
hasRuntimeDefault: false;
|
|
239
|
+
enumValues: undefined;
|
|
240
|
+
baseColumn: never;
|
|
241
|
+
identity: undefined;
|
|
242
|
+
generated: undefined;
|
|
243
|
+
}, {}, {}>;
|
|
244
|
+
updatedAt: import("drizzle-orm/pg-core").PgColumn<{
|
|
245
|
+
name: "updated_at";
|
|
246
|
+
tableName: "agent_memories";
|
|
247
|
+
dataType: "date";
|
|
248
|
+
columnType: "PgTimestamp";
|
|
249
|
+
data: Date;
|
|
250
|
+
driverParam: string;
|
|
251
|
+
notNull: true;
|
|
252
|
+
hasDefault: true;
|
|
253
|
+
isPrimaryKey: false;
|
|
254
|
+
isAutoincrement: false;
|
|
255
|
+
hasRuntimeDefault: false;
|
|
256
|
+
enumValues: undefined;
|
|
257
|
+
baseColumn: never;
|
|
258
|
+
identity: undefined;
|
|
259
|
+
generated: undefined;
|
|
260
|
+
}, {}, {}>;
|
|
261
|
+
metadata: import("drizzle-orm/pg-core").PgColumn<{
|
|
262
|
+
name: "metadata";
|
|
263
|
+
tableName: "agent_memories";
|
|
264
|
+
dataType: "json";
|
|
265
|
+
columnType: "PgJsonb";
|
|
266
|
+
data: unknown;
|
|
267
|
+
driverParam: unknown;
|
|
268
|
+
notNull: true;
|
|
269
|
+
hasDefault: true;
|
|
270
|
+
isPrimaryKey: false;
|
|
271
|
+
isAutoincrement: false;
|
|
272
|
+
hasRuntimeDefault: false;
|
|
273
|
+
enumValues: undefined;
|
|
274
|
+
baseColumn: never;
|
|
275
|
+
identity: undefined;
|
|
276
|
+
generated: undefined;
|
|
277
|
+
}, {}, {}>;
|
|
278
|
+
};
|
|
279
|
+
dialect: "pg";
|
|
280
|
+
}>;
|
|
281
|
+
//# sourceMappingURL=agent-memories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-memories.d.ts","sourceRoot":"","sources":["../../../src/pg/schema/agent-memories.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2CzB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import { pgTable, uuid, text, real, timestamp, jsonb, vector, index, uniqueIndex, } from 'drizzle-orm/pg-core';
|
|
3
|
+
/**
|
|
4
|
+
* Org-scoped agent memory corpus with pgvector embeddings. This is the
|
|
5
|
+
* system-of-record home for agent memories (migrated off the gateway-local
|
|
6
|
+
* LanceDB store): semantic memory, session-memory summaries, and captured
|
|
7
|
+
* facts/preferences/decisions/entities. Both the hub (visualization) and the
|
|
8
|
+
* flow runner (RAG retrieval) read from here.
|
|
9
|
+
*
|
|
10
|
+
* Embedding dimension matches OpenAI `text-embedding-3-small` (1536). If the
|
|
11
|
+
* embedding model changes, add a new column / table rather than mixing
|
|
12
|
+
* dimensions in one column.
|
|
13
|
+
*
|
|
14
|
+
* RLS (org isolation) is added in the hand-written companion migration
|
|
15
|
+
* `<ts>_agent_memories_rls.sql` (role app_ledger + app.current_org_id GUC),
|
|
16
|
+
* mirroring `messages`. Drizzle does not manage roles/policies, the `vector`
|
|
17
|
+
* extension, or the HNSW index — those live in the companion SQL.
|
|
18
|
+
*/
|
|
19
|
+
export const agentMemories = pgTable('agent_memories', {
|
|
20
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
21
|
+
// RLS pivot. Better Auth org id (text), matches messages.org_id convention.
|
|
22
|
+
orgId: text('org_id').notNull(),
|
|
23
|
+
// Producing gateway/server id (hub servers.id; text — not a PG uuid).
|
|
24
|
+
gatewayId: text('gateway_id'),
|
|
25
|
+
// Memory is agent-scoped; agentId is the gateway agent id (text).
|
|
26
|
+
agentId: text('agent_id').notNull(),
|
|
27
|
+
// Optional owner for personal memories (profiles.id); null = agent-global.
|
|
28
|
+
profileId: uuid('profile_id'),
|
|
29
|
+
// The memory content (what gets embedded + shown).
|
|
30
|
+
content: text('content').notNull(),
|
|
31
|
+
// OpenAI text-embedding-3-small dimension. Nullable so a row can be inserted
|
|
32
|
+
// before its embedding is computed (async backfill).
|
|
33
|
+
embedding: vector('embedding', { dimensions: 1536 }),
|
|
34
|
+
category: text('category', {
|
|
35
|
+
enum: ['preference', 'fact', 'decision', 'entity', 'other'],
|
|
36
|
+
})
|
|
37
|
+
.notNull()
|
|
38
|
+
.default('other'),
|
|
39
|
+
// 0..1 salience used for ranking + decay.
|
|
40
|
+
importance: real('importance').notNull().default(0.5),
|
|
41
|
+
// Which subsystem produced this row: lancedb | session | manual | kg | ledger.
|
|
42
|
+
source: text('source').notNull().default('manual'),
|
|
43
|
+
// Original id in the source system (e.g. LanceDB MemoryEntry.id) — enables
|
|
44
|
+
// idempotent migration + dedupe.
|
|
45
|
+
sourceId: text('source_id'),
|
|
46
|
+
occurredAt: timestamp('occurred_at', { withTimezone: true }),
|
|
47
|
+
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
|
48
|
+
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
|
49
|
+
metadata: jsonb('metadata').notNull().default({}),
|
|
50
|
+
}, (t) => ({
|
|
51
|
+
// Idempotent migration / cross-source dedupe.
|
|
52
|
+
sourceUnique: uniqueIndex('agent_memories_source_uniq')
|
|
53
|
+
.on(t.orgId, t.source, t.sourceId)
|
|
54
|
+
.where(sql `source_id is not null`),
|
|
55
|
+
orgAgentIdx: index('agent_memories_org_agent_idx').on(t.orgId, t.agentId),
|
|
56
|
+
orgCategoryIdx: index('agent_memories_org_category_idx').on(t.orgId, t.category),
|
|
57
|
+
orgTimeIdx: index('agent_memories_org_time_idx').on(t.orgId, t.createdAt),
|
|
58
|
+
}));
|
|
59
|
+
//# sourceMappingURL=agent-memories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-memories.js","sourceRoot":"","sources":["../../../src/pg/schema/agent-memories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EACL,OAAO,EACP,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,KAAK,EACL,MAAM,EACN,KAAK,EACL,WAAW,GACZ,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAClC,gBAAgB,EAChB;IACE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,aAAa,EAAE;IAC3C,4EAA4E;IAC5E,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,OAAO,EAAE;IAC/B,sEAAsE;IACtE,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC;IAC7B,kEAAkE;IAClE,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE;IACnC,2EAA2E;IAC3E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,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC;SACjC,KAAK,CAAC,GAAG,CAAA,uBAAuB,CAAC;IACpC,WAAW,EAAE,KAAK,CAAC,8BAA8B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC;IACzE,cAAc,EAAE,KAAK,CAAC,iCAAiC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,QAAQ,CAAC;IAChF,UAAU,EAAE,KAAK,CAAC,6BAA6B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,SAAS,CAAC;CAC1E,CAAC,CACH,CAAC"}
|
|
@@ -24,4 +24,5 @@ export { skills, skillExecutionStats } from './skills.js';
|
|
|
24
24
|
export { serverBackups, serverProvisionConfigs, backupConfigs, configSnapshots, } from './server-ops.js';
|
|
25
25
|
export { workspaceMembership } from './workspace-membership.js';
|
|
26
26
|
export type { WorkspaceMembership, NewWorkspaceMembership } from './workspace-membership.js';
|
|
27
|
+
export { agentMemories } from './agent-memories.js';
|
|
27
28
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pg/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,YAAY,EACV,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,O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AChF,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,aAAa,EACb,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,YAAY,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAE7F,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/pg/schema/index.js
CHANGED
|
@@ -25,4 +25,6 @@ export { userAgents } from './user-agents.js';
|
|
|
25
25
|
export { skills, skillExecutionStats } from './skills.js';
|
|
26
26
|
export { serverBackups, serverProvisionConfigs, backupConfigs, configSnapshots, } from './server-ops.js';
|
|
27
27
|
export { workspaceMembership } from './workspace-membership.js';
|
|
28
|
+
// Org-scoped agent memory corpus (pgvector) — RAG retrieval + hub visualization.
|
|
29
|
+
export { agentMemories } from './agent-memories.js';
|
|
28
30
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pg/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAElD,uDAAuD;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO1D,OAAO,EAAE,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Q,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,aAAa,EACb,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAEhE,iFAAiF;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { sql } from 'drizzle-orm';
|
|
2
|
+
import {
|
|
3
|
+
pgTable,
|
|
4
|
+
uuid,
|
|
5
|
+
text,
|
|
6
|
+
real,
|
|
7
|
+
timestamp,
|
|
8
|
+
jsonb,
|
|
9
|
+
vector,
|
|
10
|
+
index,
|
|
11
|
+
uniqueIndex,
|
|
12
|
+
} from 'drizzle-orm/pg-core';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Org-scoped agent memory corpus with pgvector embeddings. This is the
|
|
16
|
+
* system-of-record home for agent memories (migrated off the gateway-local
|
|
17
|
+
* LanceDB store): semantic memory, session-memory summaries, and captured
|
|
18
|
+
* facts/preferences/decisions/entities. Both the hub (visualization) and the
|
|
19
|
+
* flow runner (RAG retrieval) read from here.
|
|
20
|
+
*
|
|
21
|
+
* Embedding dimension matches OpenAI `text-embedding-3-small` (1536). If the
|
|
22
|
+
* embedding model changes, add a new column / table rather than mixing
|
|
23
|
+
* dimensions in one column.
|
|
24
|
+
*
|
|
25
|
+
* RLS (org isolation) is added in the hand-written companion migration
|
|
26
|
+
* `<ts>_agent_memories_rls.sql` (role app_ledger + app.current_org_id GUC),
|
|
27
|
+
* mirroring `messages`. Drizzle does not manage roles/policies, the `vector`
|
|
28
|
+
* extension, or the HNSW index — those live in the companion SQL.
|
|
29
|
+
*/
|
|
30
|
+
export const agentMemories = pgTable(
|
|
31
|
+
'agent_memories',
|
|
32
|
+
{
|
|
33
|
+
id: uuid('id').primaryKey().defaultRandom(),
|
|
34
|
+
// RLS pivot. Better Auth org id (text), matches messages.org_id convention.
|
|
35
|
+
orgId: text('org_id').notNull(),
|
|
36
|
+
// Producing gateway/server id (hub servers.id; text — not a PG uuid).
|
|
37
|
+
gatewayId: text('gateway_id'),
|
|
38
|
+
// Memory is agent-scoped; agentId is the gateway agent id (text).
|
|
39
|
+
agentId: text('agent_id').notNull(),
|
|
40
|
+
// Optional owner for personal memories (profiles.id); null = agent-global.
|
|
41
|
+
profileId: uuid('profile_id'),
|
|
42
|
+
// The memory content (what gets embedded + shown).
|
|
43
|
+
content: text('content').notNull(),
|
|
44
|
+
// OpenAI text-embedding-3-small dimension. Nullable so a row can be inserted
|
|
45
|
+
// before its embedding is computed (async backfill).
|
|
46
|
+
embedding: vector('embedding', { dimensions: 1536 }),
|
|
47
|
+
category: text('category', {
|
|
48
|
+
enum: ['preference', 'fact', 'decision', 'entity', 'other'],
|
|
49
|
+
})
|
|
50
|
+
.notNull()
|
|
51
|
+
.default('other'),
|
|
52
|
+
// 0..1 salience used for ranking + decay.
|
|
53
|
+
importance: real('importance').notNull().default(0.5),
|
|
54
|
+
// Which subsystem produced this row: lancedb | session | manual | kg | ledger.
|
|
55
|
+
source: text('source').notNull().default('manual'),
|
|
56
|
+
// Original id in the source system (e.g. LanceDB MemoryEntry.id) — enables
|
|
57
|
+
// idempotent migration + dedupe.
|
|
58
|
+
sourceId: text('source_id'),
|
|
59
|
+
occurredAt: timestamp('occurred_at', { withTimezone: true }),
|
|
60
|
+
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
|
61
|
+
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
|
|
62
|
+
metadata: jsonb('metadata').notNull().default({}),
|
|
63
|
+
},
|
|
64
|
+
(t) => ({
|
|
65
|
+
// Idempotent migration / cross-source dedupe.
|
|
66
|
+
sourceUnique: uniqueIndex('agent_memories_source_uniq')
|
|
67
|
+
.on(t.orgId, t.source, t.sourceId)
|
|
68
|
+
.where(sql`source_id is not null`),
|
|
69
|
+
orgAgentIdx: index('agent_memories_org_agent_idx').on(t.orgId, t.agentId),
|
|
70
|
+
orgCategoryIdx: index('agent_memories_org_category_idx').on(t.orgId, t.category),
|
|
71
|
+
orgTimeIdx: index('agent_memories_org_time_idx').on(t.orgId, t.createdAt),
|
|
72
|
+
}),
|
|
73
|
+
);
|
package/src/pg/schema/index.ts
CHANGED
|
@@ -48,3 +48,5 @@ export {
|
|
|
48
48
|
} from './server-ops.js';
|
|
49
49
|
export { workspaceMembership } from './workspace-membership.js';
|
|
50
50
|
export type { WorkspaceMembership, NewWorkspaceMembership } from './workspace-membership.js';
|
|
51
|
+
// Org-scoped agent memory corpus (pgvector) — RAG retrieval + hub visualization.
|
|
52
|
+
export { agentMemories } from './agent-memories.js';
|