@axiom-lattice/pg-stores 3.1.1 → 3.1.2
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +9 -0
- package/dist/index.d.mts +195 -15
- package/dist/index.d.ts +195 -15
- package/dist/index.js +1309 -199
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1295 -191
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/ChannelBindingStore.test.ts +122 -0
- package/src/__tests__/PostgreSQLChannelInstallationStore.test.ts +16 -0
- package/src/__tests__/PostgreSQLProjectBotMembershipStore.test.ts +117 -0
- package/src/__tests__/PostgreSQLProjectMembershipStore.test.ts +235 -0
- package/src/__tests__/PostgreSQLProjectRoomMessageStore.test.ts +103 -0
- package/src/__tests__/PostgreSQLProjectRoomStore.migrations.test.ts +114 -0
- package/src/__tests__/PostgreSQLProjectRoomStore.test.ts +48 -0
- package/src/__tests__/PostgreSQLTaskStore.integration.test.ts +27 -0
- package/src/__tests__/PostgreSQLTaskStore.test.ts +57 -0
- package/src/__tests__/PostgreSQLTaskWorkItemStore.integration.test.ts +74 -0
- package/src/__tests__/PostgreSQLTaskWorkItemStore.migrations.test.ts +62 -0
- package/src/__tests__/PostgreSQLTaskWorkItemStore.test.ts +96 -0
- package/src/__tests__/ThreadMessageQueueStore.migrations.test.ts +63 -0
- package/src/__tests__/ThreadMessageQueueStore.test.ts +113 -0
- package/src/__tests__/migration-name-version-compatibility.test.ts +67 -0
- package/src/__tests__/task-files.test.ts +4 -3
- package/src/createPgStoreConfig.ts +14 -0
- package/src/index.ts +7 -0
- package/src/migrations/add_trusted_run_context_column.ts +18 -0
- package/src/migrations/migration.ts +2 -1
- package/src/migrations/project_room_migration.ts +128 -0
- package/src/migrations/task_migration.ts +15 -0
- package/src/migrations/task_work_items_migration.ts +29 -1
- package/src/stores/ChannelBindingStore.ts +99 -59
- package/src/stores/PostgreSQLChannelInstallationStore.ts +12 -30
- package/src/stores/PostgreSQLProjectBotMembershipStore.ts +199 -0
- package/src/stores/PostgreSQLProjectMembershipStore.ts +140 -0
- package/src/stores/PostgreSQLProjectRoomMessageStore.ts +177 -0
- package/src/stores/PostgreSQLProjectRoomStore.ts +57 -0
- package/src/stores/PostgreSQLTaskStore.ts +89 -3
- package/src/stores/PostgreSQLTaskWorkItemStore.ts +159 -8
- package/src/stores/ThreadMessageQueueStore.ts +38 -9
|
@@ -13,12 +13,19 @@ import type {
|
|
|
13
13
|
ThreadInfo,
|
|
14
14
|
QueueScope,
|
|
15
15
|
} from "@axiom-lattice/core";
|
|
16
|
+
import {
|
|
17
|
+
parseQueuedExecutionMode,
|
|
18
|
+
parseTrustedRunContext,
|
|
19
|
+
type QueuedExecutionMode,
|
|
20
|
+
type TrustedRunContext,
|
|
21
|
+
} from "@axiom-lattice/protocols";
|
|
16
22
|
import { MigrationManager } from "../migrations/migration";
|
|
17
23
|
import { createThreadMessageQueueTable } from "../migrations/thread_message_queue_migrations";
|
|
18
24
|
import { addPriorityAndCommandColumns } from "../migrations/add_priority_command_columns";
|
|
19
25
|
import { addCustomRunConfigColumn } from "../migrations/add_custom_run_config_column";
|
|
20
26
|
import { alterMessageQueueIdColumn } from "../migrations/alter_message_queue_id_column";
|
|
21
27
|
import { addWorkspaceProjectToQueue } from "../migrations/add_workspace_project_to_queue";
|
|
28
|
+
import { addTrustedRunContextColumn } from "../migrations/add_trusted_run_context_column";
|
|
22
29
|
|
|
23
30
|
export type { PendingMessage, AddMessageParams, ThreadInfo };
|
|
24
31
|
|
|
@@ -59,6 +66,7 @@ export class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
59
66
|
this.migrationManager.register(addCustomRunConfigColumn);
|
|
60
67
|
this.migrationManager.register(alterMessageQueueIdColumn);
|
|
61
68
|
this.migrationManager.register(addWorkspaceProjectToQueue);
|
|
69
|
+
this.migrationManager.register(addTrustedRunContextColumn);
|
|
62
70
|
|
|
63
71
|
if (options.autoMigrate !== false) {
|
|
64
72
|
this.initialize().catch((error) => {
|
|
@@ -93,6 +101,7 @@ export class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
93
101
|
* Add message to queue
|
|
94
102
|
*/
|
|
95
103
|
async addMessage(params: AddMessageParams): Promise<PendingMessage> {
|
|
104
|
+
const trusted = validateQueueTrust(params);
|
|
96
105
|
const { threadId, tenantId, assistantId, workspaceId, projectId, content, type = "human", priority = 0, command, custom_run_config, id } = params;
|
|
97
106
|
|
|
98
107
|
// Get current max sequence (no lock needed without unique constraint)
|
|
@@ -106,16 +115,17 @@ export class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
106
115
|
|
|
107
116
|
const result = await this.pool.query(
|
|
108
117
|
`INSERT INTO lattice_thread_message_queue
|
|
109
|
-
(id, thread_id, tenant_id, assistant_id, workspace_id, project_id, message_content, message_type, sequence_order, priority, command, custom_run_config)
|
|
110
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
|
118
|
+
(id, thread_id, tenant_id, assistant_id, workspace_id, project_id, message_content, message_type, sequence_order, priority, command, custom_run_config, trusted_run_context, execution_mode)
|
|
119
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
|
|
111
120
|
RETURNING *`,
|
|
112
|
-
[id || crypto.randomUUID(), threadId, tenantId, assistantId, workspaceId ?? null, projectId ?? null, JSON.stringify(content), type, nextSeq, priority, command ? JSON.stringify(command) : null, custom_run_config ? JSON.stringify(custom_run_config) : null]
|
|
121
|
+
[id || crypto.randomUUID(), threadId, tenantId, assistantId, workspaceId ?? null, projectId ?? null, JSON.stringify(content), type, nextSeq, priority, command ? JSON.stringify(command) : null, custom_run_config ? JSON.stringify(custom_run_config) : null, trusted.trustedRunContext ? JSON.stringify(trusted.trustedRunContext) : null, trusted.executionMode ?? null]
|
|
113
122
|
);
|
|
114
123
|
|
|
115
124
|
return this.rowToMessage(result.rows[0]);
|
|
116
125
|
}
|
|
117
126
|
|
|
118
127
|
async addMessageIfCapacity(params: AddMessageParams, maxSize: number): Promise<boolean> {
|
|
128
|
+
const trusted = validateQueueTrust(params);
|
|
119
129
|
if (maxSize === Infinity) {
|
|
120
130
|
await this.addMessage(params);
|
|
121
131
|
return true;
|
|
@@ -140,9 +150,9 @@ export class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
140
150
|
[params.threadId],
|
|
141
151
|
);
|
|
142
152
|
const result = await client.query(
|
|
143
|
-
`INSERT INTO lattice_thread_message_queue (id, thread_id, tenant_id, assistant_id, workspace_id, project_id, message_content, message_type, sequence_order, priority, command, custom_run_config)
|
|
144
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *`,
|
|
145
|
-
[params.id || crypto.randomUUID(), params.threadId, params.tenantId, params.assistantId, params.workspaceId ?? null, params.projectId ?? null, JSON.stringify(params.content), params.type || "human", seq.rows[0].next_seq, params.priority ?? 0, params.command ? JSON.stringify(params.command) : null, params.custom_run_config ? JSON.stringify(params.custom_run_config) : null],
|
|
153
|
+
`INSERT INTO lattice_thread_message_queue (id, thread_id, tenant_id, assistant_id, workspace_id, project_id, message_content, message_type, sequence_order, priority, command, custom_run_config, trusted_run_context, execution_mode)
|
|
154
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING *`,
|
|
155
|
+
[params.id || crypto.randomUUID(), params.threadId, params.tenantId, params.assistantId, params.workspaceId ?? null, params.projectId ?? null, JSON.stringify(params.content), params.type || "human", seq.rows[0].next_seq, params.priority ?? 0, params.command ? JSON.stringify(params.command) : null, params.custom_run_config ? JSON.stringify(params.custom_run_config) : null, trusted.trustedRunContext ? JSON.stringify(trusted.trustedRunContext) : null, trusted.executionMode ?? null],
|
|
146
156
|
);
|
|
147
157
|
await client.query("COMMIT");
|
|
148
158
|
return Boolean(result.rows[0]);
|
|
@@ -159,6 +169,7 @@ export class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
159
169
|
* Uses priority=100 to ensure message is processed first
|
|
160
170
|
*/
|
|
161
171
|
async addMessageAtHead(params: AddMessageParams): Promise<PendingMessage> {
|
|
172
|
+
const trusted = validateQueueTrust(params);
|
|
162
173
|
const { threadId, tenantId, assistantId, workspaceId, projectId, content, type = "human", command, custom_run_config, id } = params;
|
|
163
174
|
|
|
164
175
|
const resolvedTenantId = tenantId!;
|
|
@@ -176,10 +187,10 @@ export class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
176
187
|
// Insert with high priority (100)
|
|
177
188
|
const result = await this.pool.query(
|
|
178
189
|
`INSERT INTO lattice_thread_message_queue
|
|
179
|
-
(id, thread_id, tenant_id, assistant_id, workspace_id, project_id, message_content, message_type, sequence_order, priority, command, custom_run_config)
|
|
180
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, 100, $10, $11)
|
|
190
|
+
(id, thread_id, tenant_id, assistant_id, workspace_id, project_id, message_content, message_type, sequence_order, priority, command, custom_run_config, trusted_run_context, execution_mode)
|
|
191
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, 100, $10, $11, $12, $13)
|
|
181
192
|
RETURNING *`,
|
|
182
|
-
[id || crypto.randomUUID(), threadId, resolvedTenantId, resolvedAssistantId, workspaceId ?? null, projectId ?? null, JSON.stringify(content), type, nextSeq, command ? JSON.stringify(command) : null, custom_run_config ? JSON.stringify(custom_run_config) : null]
|
|
193
|
+
[id || crypto.randomUUID(), threadId, resolvedTenantId, resolvedAssistantId, workspaceId ?? null, projectId ?? null, JSON.stringify(content), type, nextSeq, command ? JSON.stringify(command) : null, custom_run_config ? JSON.stringify(custom_run_config) : null, trusted.trustedRunContext ? JSON.stringify(trusted.trustedRunContext) : null, trusted.executionMode ?? null]
|
|
183
194
|
);
|
|
184
195
|
|
|
185
196
|
return this.rowToMessage(result.rows[0]);
|
|
@@ -322,10 +333,28 @@ export class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
322
333
|
custom_run_config: row.custom_run_config
|
|
323
334
|
? (typeof row.custom_run_config === "string" ? JSON.parse(row.custom_run_config) : row.custom_run_config)
|
|
324
335
|
: undefined,
|
|
336
|
+
trusted_run_context: row.trusted_run_context
|
|
337
|
+
? parseTrustedRunContext(typeof row.trusted_run_context === "string" ? JSON.parse(row.trusted_run_context) : row.trusted_run_context)
|
|
338
|
+
: undefined,
|
|
339
|
+
execution_mode: row.execution_mode == null ? undefined : parseQueuedExecutionMode(row.execution_mode),
|
|
325
340
|
};
|
|
326
341
|
}
|
|
327
342
|
}
|
|
328
343
|
|
|
344
|
+
function validateQueueTrust(params: AddMessageParams): {
|
|
345
|
+
trustedRunContext: TrustedRunContext | undefined;
|
|
346
|
+
executionMode: QueuedExecutionMode | undefined;
|
|
347
|
+
} {
|
|
348
|
+
return {
|
|
349
|
+
trustedRunContext: params.trusted_run_context === undefined
|
|
350
|
+
? undefined
|
|
351
|
+
: parseTrustedRunContext(params.trusted_run_context),
|
|
352
|
+
executionMode: params.execution_mode === undefined
|
|
353
|
+
? undefined
|
|
354
|
+
: parseQueuedExecutionMode(params.execution_mode),
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
329
358
|
function scopeClause(scope: QueueScope | undefined, start: number): { sql: string; params: unknown[] } {
|
|
330
359
|
if (!scope) return { sql: "", params: [] };
|
|
331
360
|
const params: unknown[] = [];
|