@axiom-lattice/pg-stores 1.0.34 → 1.0.36
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 +16 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +41 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/ThreadMessageQueueStore.test.ts +61 -2
- package/src/migrations/add_custom_run_config_column.ts +25 -0
- package/src/stores/PostgreSQLThreadStore.ts +17 -2
- package/src/stores/ThreadMessageQueueStore.ts +18 -30
package/dist/index.mjs
CHANGED
|
@@ -336,7 +336,7 @@ var PostgreSQLThreadStore = class {
|
|
|
336
336
|
/**
|
|
337
337
|
* Get all threads for a specific tenant and assistant
|
|
338
338
|
*/
|
|
339
|
-
async getThreadsByAssistantId(tenantId, assistantId) {
|
|
339
|
+
async getThreadsByAssistantId(tenantId, assistantId, metadataFilter) {
|
|
340
340
|
await this.ensureInitialized();
|
|
341
341
|
const result = await this.pool.query(
|
|
342
342
|
`
|
|
@@ -347,7 +347,15 @@ var PostgreSQLThreadStore = class {
|
|
|
347
347
|
`,
|
|
348
348
|
[tenantId, assistantId]
|
|
349
349
|
);
|
|
350
|
-
|
|
350
|
+
let threads = result.rows.map(this.mapRowToThread);
|
|
351
|
+
if (metadataFilter && Object.keys(metadataFilter).length > 0) {
|
|
352
|
+
threads = threads.filter(
|
|
353
|
+
(thread) => Object.entries(metadataFilter).every(
|
|
354
|
+
([key, value]) => thread.metadata?.[key] === value
|
|
355
|
+
)
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
return threads;
|
|
351
359
|
}
|
|
352
360
|
/**
|
|
353
361
|
* Get a thread by ID for a specific tenant
|
|
@@ -4039,6 +4047,23 @@ var addPriorityAndCommandColumns = {
|
|
|
4039
4047
|
}
|
|
4040
4048
|
};
|
|
4041
4049
|
|
|
4050
|
+
// src/migrations/add_custom_run_config_column.ts
|
|
4051
|
+
var addCustomRunConfigColumn = {
|
|
4052
|
+
version: 102,
|
|
4053
|
+
name: "add_custom_run_config_column",
|
|
4054
|
+
up: async (client) => {
|
|
4055
|
+
await client.query(`
|
|
4056
|
+
ALTER TABLE lattice_thread_message_queue
|
|
4057
|
+
ADD COLUMN IF NOT EXISTS custom_run_config JSONB
|
|
4058
|
+
`);
|
|
4059
|
+
},
|
|
4060
|
+
down: async (client) => {
|
|
4061
|
+
await client.query(
|
|
4062
|
+
"ALTER TABLE lattice_thread_message_queue DROP COLUMN IF EXISTS custom_run_config"
|
|
4063
|
+
);
|
|
4064
|
+
}
|
|
4065
|
+
};
|
|
4066
|
+
|
|
4042
4067
|
// src/migrations/alter_message_queue_id_column.ts
|
|
4043
4068
|
var alterMessageQueueIdColumn = {
|
|
4044
4069
|
version: 102,
|
|
@@ -4087,6 +4112,7 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4087
4112
|
const migrationManager = new MigrationManager(pool);
|
|
4088
4113
|
migrationManager.register(createThreadMessageQueueTable);
|
|
4089
4114
|
migrationManager.register(addPriorityAndCommandColumns);
|
|
4115
|
+
migrationManager.register(addCustomRunConfigColumn);
|
|
4090
4116
|
migrationManager.register(alterMessageQueueIdColumn);
|
|
4091
4117
|
await migrationManager.migrate();
|
|
4092
4118
|
this.initialized = true;
|
|
@@ -4103,7 +4129,7 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4103
4129
|
*/
|
|
4104
4130
|
async addMessage(params) {
|
|
4105
4131
|
const pool = this.getPool();
|
|
4106
|
-
const { threadId, tenantId, assistantId, content, type = "human", priority = 0, command, id } = params;
|
|
4132
|
+
const { threadId, tenantId, assistantId, content, type = "human", priority = 0, command, custom_run_config, id } = params;
|
|
4107
4133
|
const seqResult = await pool.query(
|
|
4108
4134
|
`SELECT COALESCE(MAX(sequence_order), 0) + 1 as next_seq
|
|
4109
4135
|
FROM lattice_thread_message_queue
|
|
@@ -4113,10 +4139,10 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4113
4139
|
const nextSeq = seqResult.rows[0].next_seq;
|
|
4114
4140
|
const result = await pool.query(
|
|
4115
4141
|
`INSERT INTO lattice_thread_message_queue
|
|
4116
|
-
(id, thread_id, tenant_id, assistant_id, message_content, message_type, sequence_order, priority, command)
|
|
4117
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
4142
|
+
(id, thread_id, tenant_id, assistant_id, message_content, message_type, sequence_order, priority, command, custom_run_config)
|
|
4143
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
|
4118
4144
|
RETURNING *`,
|
|
4119
|
-
[id || crypto.randomUUID(), threadId, tenantId, assistantId, JSON.stringify(content), type, nextSeq, priority, command ? JSON.stringify(command) : null]
|
|
4145
|
+
[id || crypto.randomUUID(), threadId, tenantId, assistantId, JSON.stringify(content), type, nextSeq, priority, command ? JSON.stringify(command) : null, custom_run_config ? JSON.stringify(custom_run_config) : null]
|
|
4120
4146
|
);
|
|
4121
4147
|
return this.rowToMessage(result.rows[0]);
|
|
4122
4148
|
}
|
|
@@ -4124,21 +4150,11 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4124
4150
|
* Add message at head of queue (high priority, e.g., STEER/Command messages)
|
|
4125
4151
|
* Uses priority=100 to ensure message is processed first
|
|
4126
4152
|
*/
|
|
4127
|
-
async addMessageAtHead(
|
|
4153
|
+
async addMessageAtHead(params) {
|
|
4128
4154
|
const pool = this.getPool();
|
|
4129
|
-
const
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
WHERE thread_id = $1
|
|
4133
|
-
LIMIT 1`,
|
|
4134
|
-
[threadId]
|
|
4135
|
-
);
|
|
4136
|
-
let tenantId = "default";
|
|
4137
|
-
let assistantId = "";
|
|
4138
|
-
if (threadResult.rows.length > 0) {
|
|
4139
|
-
tenantId = threadResult.rows[0].tenant_id;
|
|
4140
|
-
assistantId = threadResult.rows[0].assistant_id;
|
|
4141
|
-
}
|
|
4155
|
+
const { threadId, tenantId, assistantId, content, type = "human", command, custom_run_config, id } = params;
|
|
4156
|
+
const resolvedTenantId = tenantId;
|
|
4157
|
+
const resolvedAssistantId = assistantId;
|
|
4142
4158
|
const seqResult = await pool.query(
|
|
4143
4159
|
`SELECT COALESCE(MAX(sequence_order), 0) + 1 as next_seq
|
|
4144
4160
|
FROM lattice_thread_message_queue
|
|
@@ -4148,10 +4164,10 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4148
4164
|
const nextSeq = seqResult.rows[0].next_seq;
|
|
4149
4165
|
const result = await pool.query(
|
|
4150
4166
|
`INSERT INTO lattice_thread_message_queue
|
|
4151
|
-
(id, thread_id, tenant_id, assistant_id, message_content, message_type, sequence_order, priority, command)
|
|
4152
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, 100, $8)
|
|
4167
|
+
(id, thread_id, tenant_id, assistant_id, message_content, message_type, sequence_order, priority, command, custom_run_config)
|
|
4168
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, 100, $8, $9)
|
|
4153
4169
|
RETURNING *`,
|
|
4154
|
-
[id || crypto.randomUUID(), threadId,
|
|
4170
|
+
[id || crypto.randomUUID(), threadId, resolvedTenantId, resolvedAssistantId, JSON.stringify(content), type, nextSeq, command ? JSON.stringify(command) : null, custom_run_config ? JSON.stringify(custom_run_config) : null]
|
|
4155
4171
|
);
|
|
4156
4172
|
return this.rowToMessage(result.rows[0]);
|
|
4157
4173
|
}
|
|
@@ -4285,7 +4301,8 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4285
4301
|
sequence: row.sequence_order,
|
|
4286
4302
|
createdAt: new Date(row.created_at),
|
|
4287
4303
|
priority: row.priority || 0,
|
|
4288
|
-
command: row.command ? typeof row.command === "string" ? JSON.parse(row.command) : row.command : void 0
|
|
4304
|
+
command: row.command ? typeof row.command === "string" ? JSON.parse(row.command) : row.command : void 0,
|
|
4305
|
+
custom_run_config: row.custom_run_config ? typeof row.custom_run_config === "string" ? JSON.parse(row.custom_run_config) : row.custom_run_config : void 0
|
|
4289
4306
|
};
|
|
4290
4307
|
}
|
|
4291
4308
|
};
|