@axiom-lattice/pg-stores 1.0.32 → 1.0.34
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 +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +128 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +118 -79
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/ThreadMessageQueueStore.test.ts +61 -26
- package/src/index.ts +3 -0
- package/src/migrations/add_priority_command_columns.ts +7 -7
- package/src/migrations/alter_message_queue_id_column.ts +41 -0
- package/src/migrations/thread_message_queue_migrations.ts +16 -16
- package/src/stores/ThreadMessageQueueStore.ts +83 -68
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @axiom-lattice/pg-stores@1.0.
|
|
2
|
+
> @axiom-lattice/pg-stores@1.0.34 build /home/runner/work/agentic/agentic/packages/pg-stores
|
|
3
3
|
> tsup src/index.ts --format cjs,esm --dts --sourcemap
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
[34mCLI[39m Target: es2020
|
|
9
9
|
[34mCJS[39m Build start
|
|
10
10
|
[34mESM[39m Build start
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m132.35 KB[39m
|
|
12
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m245.86 KB[39m
|
|
13
|
+
[32mCJS[39m ⚡️ Build success in 373ms
|
|
14
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m128.40 KB[39m
|
|
15
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m245.79 KB[39m
|
|
16
|
+
[32mESM[39m ⚡️ Build success in 377ms
|
|
17
17
|
[34mDTS[39m Build start
|
|
18
|
-
[32mDTS[39m ⚡️ Build success in
|
|
19
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m34.
|
|
20
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m34.
|
|
18
|
+
[32mDTS[39m ⚡️ Build success in 11712ms
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m34.60 KB[39m
|
|
20
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m34.60 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @axiom-lattice/pg-stores
|
|
2
2
|
|
|
3
|
+
## 1.0.34
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e8fc7ec: fix subagent issue
|
|
8
|
+
- Updated dependencies [e8fc7ec]
|
|
9
|
+
- @axiom-lattice/core@2.1.44
|
|
10
|
+
|
|
11
|
+
## 1.0.33
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 21052a9: update issues
|
|
16
|
+
- Updated dependencies [21052a9]
|
|
17
|
+
- @axiom-lattice/core@2.1.43
|
|
18
|
+
|
|
3
19
|
## 1.0.32
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PoolConfig, PoolClient, Pool } from 'pg';
|
|
2
|
+
export { Pool, PoolConfig } from 'pg';
|
|
2
3
|
import { ThreadStore, Thread, CreateThreadRequest, AssistantStore, Assistant, CreateAssistantRequest, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, ScheduleExecutionType, SkillStore, Skill, CreateSkillRequest, DatabaseConfigStore, DatabaseConfigEntry, CreateDatabaseConfigRequest, UpdateDatabaseConfigRequest, MetricsServerConfigStore, MetricsServerConfigEntry, CreateMetricsServerConfigRequest, UpdateMetricsServerConfigRequest, McpServerConfigStore, McpServerConfigEntry, CreateMcpServerConfigRequest, UpdateMcpServerConfigRequest, WorkspaceStore, Workspace, CreateWorkspaceRequest, UpdateWorkspaceRequest, ProjectStore, Project, CreateProjectRequest, UpdateProjectRequest, UserStore, User, CreateUserRequest, UpdateUserRequest, TenantStore, Tenant, CreateTenantRequest, UpdateTenantRequest, UserTenantLinkStore, UserTenantLink, CreateUserTenantLinkRequest, UpdateUserTenantLinkRequest } from '@axiom-lattice/protocols';
|
|
3
4
|
export { Assistant, AssistantStore, CreateAssistantRequest, CreateDatabaseConfigRequest, CreateMcpServerConfigRequest, CreateMetricsServerConfigRequest, CreateProjectRequest, CreateSkillRequest, CreateTenantRequest, CreateThreadRequest, CreateUserRequest, CreateUserTenantLinkRequest, CreateWorkspaceRequest, DatabaseConfig, DatabaseConfigEntry, DatabaseConfigStore, DatabaseType, McpServerConfigEntry, McpServerConfigStore, MetricsServerConfig, MetricsServerConfigEntry, MetricsServerConfigStore, Project, ProjectStore, ScheduleExecutionType, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, Skill, SkillStore, StorageType, Tenant, TenantStatus, TenantStore, Thread, ThreadStore, UpdateDatabaseConfigRequest, UpdateMcpServerConfigRequest, UpdateMetricsServerConfigRequest, UpdateProjectRequest, UpdateTenantRequest, UpdateUserRequest, UpdateUserTenantLinkRequest, UpdateWorkspaceRequest, User, UserStore, UserTenantLink, UserTenantLinkStore, UserTenantRole, Workspace, WorkspaceStore } from '@axiom-lattice/protocols';
|
|
4
5
|
import { IMessageQueueStore, AddMessageParams, PendingMessage, ThreadInfo } from '@axiom-lattice/core';
|
|
@@ -1109,9 +1110,10 @@ declare class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
1109
1110
|
*/
|
|
1110
1111
|
addMessage(params: AddMessageParams): Promise<PendingMessage>;
|
|
1111
1112
|
/**
|
|
1112
|
-
* Add message at head of queue (
|
|
1113
|
+
* Add message at head of queue (high priority, e.g., STEER/Command messages)
|
|
1114
|
+
* Uses priority=100 to ensure message is processed first
|
|
1113
1115
|
*/
|
|
1114
|
-
addMessageAtHead(threadId: string, content:
|
|
1116
|
+
addMessageAtHead(threadId: string, content: PendingMessage["content"], type?: "human" | "system", id?: string, command?: PendingMessage["command"]): Promise<PendingMessage>;
|
|
1115
1117
|
/**
|
|
1116
1118
|
* Get pending messages for thread
|
|
1117
1119
|
*/
|
|
@@ -1125,7 +1127,7 @@ declare class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
1125
1127
|
*/
|
|
1126
1128
|
getQueueSize(threadId: string): Promise<number>;
|
|
1127
1129
|
/**
|
|
1128
|
-
* Get all threads with pending messages
|
|
1130
|
+
* Get all threads with pending or processing messages
|
|
1129
1131
|
*/
|
|
1130
1132
|
getThreadsWithPendingMessages(): Promise<ThreadInfo[]>;
|
|
1131
1133
|
/**
|
|
@@ -1148,6 +1150,11 @@ declare class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
1148
1150
|
* Clear completed messages for thread
|
|
1149
1151
|
*/
|
|
1150
1152
|
clearCompletedMessages(threadId: string): Promise<void>;
|
|
1153
|
+
/**
|
|
1154
|
+
* Reset all processing messages to pending state for a thread
|
|
1155
|
+
* Returns the number of messages reset
|
|
1156
|
+
*/
|
|
1157
|
+
resetProcessingToPending(threadId: string): Promise<number>;
|
|
1151
1158
|
private rowToMessage;
|
|
1152
1159
|
}
|
|
1153
1160
|
declare const getThreadMessageQueueStore: () => ThreadMessageQueueStore;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PoolConfig, PoolClient, Pool } from 'pg';
|
|
2
|
+
export { Pool, PoolConfig } from 'pg';
|
|
2
3
|
import { ThreadStore, Thread, CreateThreadRequest, AssistantStore, Assistant, CreateAssistantRequest, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, ScheduleExecutionType, SkillStore, Skill, CreateSkillRequest, DatabaseConfigStore, DatabaseConfigEntry, CreateDatabaseConfigRequest, UpdateDatabaseConfigRequest, MetricsServerConfigStore, MetricsServerConfigEntry, CreateMetricsServerConfigRequest, UpdateMetricsServerConfigRequest, McpServerConfigStore, McpServerConfigEntry, CreateMcpServerConfigRequest, UpdateMcpServerConfigRequest, WorkspaceStore, Workspace, CreateWorkspaceRequest, UpdateWorkspaceRequest, ProjectStore, Project, CreateProjectRequest, UpdateProjectRequest, UserStore, User, CreateUserRequest, UpdateUserRequest, TenantStore, Tenant, CreateTenantRequest, UpdateTenantRequest, UserTenantLinkStore, UserTenantLink, CreateUserTenantLinkRequest, UpdateUserTenantLinkRequest } from '@axiom-lattice/protocols';
|
|
3
4
|
export { Assistant, AssistantStore, CreateAssistantRequest, CreateDatabaseConfigRequest, CreateMcpServerConfigRequest, CreateMetricsServerConfigRequest, CreateProjectRequest, CreateSkillRequest, CreateTenantRequest, CreateThreadRequest, CreateUserRequest, CreateUserTenantLinkRequest, CreateWorkspaceRequest, DatabaseConfig, DatabaseConfigEntry, DatabaseConfigStore, DatabaseType, McpServerConfigEntry, McpServerConfigStore, MetricsServerConfig, MetricsServerConfigEntry, MetricsServerConfigStore, Project, ProjectStore, ScheduleExecutionType, ScheduleStorage, ScheduledTaskDefinition, ScheduledTaskStatus, Skill, SkillStore, StorageType, Tenant, TenantStatus, TenantStore, Thread, ThreadStore, UpdateDatabaseConfigRequest, UpdateMcpServerConfigRequest, UpdateMetricsServerConfigRequest, UpdateProjectRequest, UpdateTenantRequest, UpdateUserRequest, UpdateUserTenantLinkRequest, UpdateWorkspaceRequest, User, UserStore, UserTenantLink, UserTenantLinkStore, UserTenantRole, Workspace, WorkspaceStore } from '@axiom-lattice/protocols';
|
|
4
5
|
import { IMessageQueueStore, AddMessageParams, PendingMessage, ThreadInfo } from '@axiom-lattice/core';
|
|
@@ -1109,9 +1110,10 @@ declare class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
1109
1110
|
*/
|
|
1110
1111
|
addMessage(params: AddMessageParams): Promise<PendingMessage>;
|
|
1111
1112
|
/**
|
|
1112
|
-
* Add message at head of queue (
|
|
1113
|
+
* Add message at head of queue (high priority, e.g., STEER/Command messages)
|
|
1114
|
+
* Uses priority=100 to ensure message is processed first
|
|
1113
1115
|
*/
|
|
1114
|
-
addMessageAtHead(threadId: string, content:
|
|
1116
|
+
addMessageAtHead(threadId: string, content: PendingMessage["content"], type?: "human" | "system", id?: string, command?: PendingMessage["command"]): Promise<PendingMessage>;
|
|
1115
1117
|
/**
|
|
1116
1118
|
* Get pending messages for thread
|
|
1117
1119
|
*/
|
|
@@ -1125,7 +1127,7 @@ declare class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
1125
1127
|
*/
|
|
1126
1128
|
getQueueSize(threadId: string): Promise<number>;
|
|
1127
1129
|
/**
|
|
1128
|
-
* Get all threads with pending messages
|
|
1130
|
+
* Get all threads with pending or processing messages
|
|
1129
1131
|
*/
|
|
1130
1132
|
getThreadsWithPendingMessages(): Promise<ThreadInfo[]>;
|
|
1131
1133
|
/**
|
|
@@ -1148,6 +1150,11 @@ declare class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
1148
1150
|
* Clear completed messages for thread
|
|
1149
1151
|
*/
|
|
1150
1152
|
clearCompletedMessages(threadId: string): Promise<void>;
|
|
1153
|
+
/**
|
|
1154
|
+
* Reset all processing messages to pending state for a thread
|
|
1155
|
+
* Returns the number of messages reset
|
|
1156
|
+
*/
|
|
1157
|
+
resetProcessingToPending(threadId: string): Promise<number>;
|
|
1151
1158
|
private rowToMessage;
|
|
1152
1159
|
}
|
|
1153
1160
|
declare const getThreadMessageQueueStore: () => ThreadMessageQueueStore;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -23,6 +33,8 @@ __export(index_exports, {
|
|
|
23
33
|
AddMessageParams: () => import_core4.AddMessageParams,
|
|
24
34
|
MigrationManager: () => MigrationManager,
|
|
25
35
|
PendingMessage: () => import_core4.PendingMessage,
|
|
36
|
+
Pool: () => import_pg13.Pool,
|
|
37
|
+
PoolConfig: () => import_pg13.PoolConfig,
|
|
26
38
|
PostgreSQLAssistantStore: () => PostgreSQLAssistantStore,
|
|
27
39
|
PostgreSQLDatabaseConfigStore: () => PostgreSQLDatabaseConfigStore,
|
|
28
40
|
PostgreSQLMcpServerConfigStore: () => PostgreSQLMcpServerConfigStore,
|
|
@@ -59,6 +71,7 @@ __export(index_exports, {
|
|
|
59
71
|
getThreadMessageQueueStore: () => getThreadMessageQueueStore
|
|
60
72
|
});
|
|
61
73
|
module.exports = __toCommonJS(index_exports);
|
|
74
|
+
var import_pg13 = require("pg");
|
|
62
75
|
|
|
63
76
|
// src/stores/PostgreSQLThreadStore.ts
|
|
64
77
|
var import_pg = require("pg");
|
|
@@ -4022,10 +4035,10 @@ var PostgreSQLUserTenantLinkStore = class {
|
|
|
4022
4035
|
// src/migrations/thread_message_queue_migrations.ts
|
|
4023
4036
|
var createThreadMessageQueueTable = {
|
|
4024
4037
|
version: 100,
|
|
4025
|
-
name: "
|
|
4038
|
+
name: "create_lattice_thread_message_queue_table",
|
|
4026
4039
|
up: async (client) => {
|
|
4027
4040
|
await client.query(`
|
|
4028
|
-
CREATE TABLE IF NOT EXISTS
|
|
4041
|
+
CREATE TABLE IF NOT EXISTS lattice_thread_message_queue (
|
|
4029
4042
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
4030
4043
|
thread_id VARCHAR(255) NOT NULL,
|
|
4031
4044
|
tenant_id VARCHAR(255) NOT NULL,
|
|
@@ -4038,32 +4051,33 @@ var createThreadMessageQueueTable = {
|
|
|
4038
4051
|
)
|
|
4039
4052
|
`);
|
|
4040
4053
|
await client.query(`
|
|
4041
|
-
CREATE INDEX IF NOT EXISTS
|
|
4042
|
-
ON
|
|
4054
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_thread_message_queue_thread
|
|
4055
|
+
ON lattice_thread_message_queue(thread_id, status)
|
|
4043
4056
|
`);
|
|
4044
4057
|
await client.query(`
|
|
4045
|
-
CREATE INDEX IF NOT EXISTS
|
|
4046
|
-
ON
|
|
4058
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_thread_message_queue_tenant
|
|
4059
|
+
ON lattice_thread_message_queue(tenant_id, thread_id, status)
|
|
4047
4060
|
`);
|
|
4048
4061
|
await client.query(`
|
|
4049
|
-
CREATE INDEX IF NOT EXISTS
|
|
4050
|
-
ON
|
|
4062
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_thread_message_queue_status
|
|
4063
|
+
ON lattice_thread_message_queue(status, created_at)
|
|
4051
4064
|
`);
|
|
4052
4065
|
await client.query(`
|
|
4053
|
-
CREATE
|
|
4054
|
-
ON
|
|
4066
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_thread_message_queue_sequence
|
|
4067
|
+
ON lattice_thread_message_queue(thread_id, sequence_order)
|
|
4055
4068
|
`);
|
|
4056
4069
|
},
|
|
4057
4070
|
down: async (client) => {
|
|
4058
|
-
await client.query("DROP INDEX IF EXISTS
|
|
4059
|
-
await client.query("DROP INDEX IF EXISTS
|
|
4060
|
-
await client.query("DROP INDEX IF EXISTS
|
|
4061
|
-
await client.query("DROP INDEX IF EXISTS
|
|
4062
|
-
await client.query("DROP TABLE IF EXISTS
|
|
4071
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_thread_message_queue_sequence");
|
|
4072
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_thread_message_queue_status");
|
|
4073
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_thread_message_queue_tenant");
|
|
4074
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_thread_message_queue_thread");
|
|
4075
|
+
await client.query("DROP TABLE IF EXISTS lattice_thread_message_queue");
|
|
4063
4076
|
}
|
|
4064
4077
|
};
|
|
4065
4078
|
|
|
4066
4079
|
// src/stores/ThreadMessageQueueStore.ts
|
|
4080
|
+
var import_crypto = __toESM(require("crypto"));
|
|
4067
4081
|
var import_core4 = require("@axiom-lattice/core");
|
|
4068
4082
|
|
|
4069
4083
|
// src/migrations/add_priority_command_columns.ts
|
|
@@ -4072,22 +4086,47 @@ var addPriorityAndCommandColumns = {
|
|
|
4072
4086
|
name: "add_priority_and_command_columns",
|
|
4073
4087
|
up: async (client) => {
|
|
4074
4088
|
await client.query(`
|
|
4075
|
-
ALTER TABLE
|
|
4089
|
+
ALTER TABLE lattice_thread_message_queue
|
|
4076
4090
|
ADD COLUMN IF NOT EXISTS priority INTEGER DEFAULT 0
|
|
4077
4091
|
`);
|
|
4078
4092
|
await client.query(`
|
|
4079
|
-
ALTER TABLE
|
|
4093
|
+
ALTER TABLE lattice_thread_message_queue
|
|
4080
4094
|
ADD COLUMN IF NOT EXISTS command JSONB
|
|
4081
4095
|
`);
|
|
4082
4096
|
await client.query(`
|
|
4083
|
-
CREATE INDEX IF NOT EXISTS
|
|
4084
|
-
ON
|
|
4097
|
+
CREATE INDEX IF NOT EXISTS idx_lattice_thread_message_queue_priority
|
|
4098
|
+
ON lattice_thread_message_queue(thread_id, priority DESC, sequence_order ASC)
|
|
4085
4099
|
`);
|
|
4086
4100
|
},
|
|
4087
4101
|
down: async (client) => {
|
|
4088
|
-
await client.query("DROP INDEX IF EXISTS
|
|
4089
|
-
await client.query("ALTER TABLE
|
|
4090
|
-
await client.query("ALTER TABLE
|
|
4102
|
+
await client.query("DROP INDEX IF EXISTS idx_lattice_thread_message_queue_priority");
|
|
4103
|
+
await client.query("ALTER TABLE lattice_thread_message_queue DROP COLUMN IF EXISTS command");
|
|
4104
|
+
await client.query("ALTER TABLE lattice_thread_message_queue DROP COLUMN IF EXISTS priority");
|
|
4105
|
+
}
|
|
4106
|
+
};
|
|
4107
|
+
|
|
4108
|
+
// src/migrations/alter_message_queue_id_column.ts
|
|
4109
|
+
var alterMessageQueueIdColumn = {
|
|
4110
|
+
version: 102,
|
|
4111
|
+
name: "alter_message_queue_id_column",
|
|
4112
|
+
up: async (client) => {
|
|
4113
|
+
await client.query(`
|
|
4114
|
+
ALTER TABLE lattice_thread_message_queue
|
|
4115
|
+
ALTER COLUMN id DROP DEFAULT
|
|
4116
|
+
`);
|
|
4117
|
+
await client.query(`
|
|
4118
|
+
COMMENT ON COLUMN lattice_thread_message_queue.id IS
|
|
4119
|
+
'Message ID - must be provided explicitly (UUID format). Used for consistent ID across client and server.'
|
|
4120
|
+
`);
|
|
4121
|
+
},
|
|
4122
|
+
down: async (client) => {
|
|
4123
|
+
await client.query(`
|
|
4124
|
+
ALTER TABLE lattice_thread_message_queue
|
|
4125
|
+
ALTER COLUMN id SET DEFAULT gen_random_uuid()
|
|
4126
|
+
`);
|
|
4127
|
+
await client.query(`
|
|
4128
|
+
COMMENT ON COLUMN lattice_thread_message_queue.id IS NULL
|
|
4129
|
+
`);
|
|
4091
4130
|
}
|
|
4092
4131
|
};
|
|
4093
4132
|
|
|
@@ -4114,6 +4153,7 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4114
4153
|
const migrationManager = new MigrationManager(pool);
|
|
4115
4154
|
migrationManager.register(createThreadMessageQueueTable);
|
|
4116
4155
|
migrationManager.register(addPriorityAndCommandColumns);
|
|
4156
|
+
migrationManager.register(alterMessageQueueIdColumn);
|
|
4117
4157
|
await migrationManager.migrate();
|
|
4118
4158
|
this.initialized = true;
|
|
4119
4159
|
}
|
|
@@ -4129,65 +4169,57 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4129
4169
|
*/
|
|
4130
4170
|
async addMessage(params) {
|
|
4131
4171
|
const pool = this.getPool();
|
|
4132
|
-
const { threadId, tenantId, assistantId, content, type = "human", priority = 0, command } = params;
|
|
4172
|
+
const { threadId, tenantId, assistantId, content, type = "human", priority = 0, command, id } = params;
|
|
4133
4173
|
const seqResult = await pool.query(
|
|
4134
4174
|
`SELECT COALESCE(MAX(sequence_order), 0) + 1 as next_seq
|
|
4135
|
-
FROM
|
|
4175
|
+
FROM lattice_thread_message_queue
|
|
4136
4176
|
WHERE thread_id = $1`,
|
|
4137
4177
|
[threadId]
|
|
4138
4178
|
);
|
|
4139
4179
|
const nextSeq = seqResult.rows[0].next_seq;
|
|
4140
4180
|
const result = await pool.query(
|
|
4141
|
-
`INSERT INTO
|
|
4142
|
-
(thread_id, tenant_id, assistant_id, message_content, message_type, sequence_order, priority, command)
|
|
4143
|
-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
4181
|
+
`INSERT INTO lattice_thread_message_queue
|
|
4182
|
+
(id, thread_id, tenant_id, assistant_id, message_content, message_type, sequence_order, priority, command)
|
|
4183
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
|
|
4144
4184
|
RETURNING *`,
|
|
4145
|
-
[threadId, tenantId, assistantId, JSON.stringify(content), type, nextSeq, priority, command ? JSON.stringify(command) : null]
|
|
4185
|
+
[id || import_crypto.default.randomUUID(), threadId, tenantId, assistantId, JSON.stringify(content), type, nextSeq, priority, command ? JSON.stringify(command) : null]
|
|
4146
4186
|
);
|
|
4147
4187
|
return this.rowToMessage(result.rows[0]);
|
|
4148
4188
|
}
|
|
4149
4189
|
/**
|
|
4150
|
-
* Add message at head of queue (
|
|
4190
|
+
* Add message at head of queue (high priority, e.g., STEER/Command messages)
|
|
4191
|
+
* Uses priority=100 to ensure message is processed first
|
|
4151
4192
|
*/
|
|
4152
|
-
async addMessageAtHead(threadId, content, type = "system") {
|
|
4193
|
+
async addMessageAtHead(threadId, content, type = "system", id, command) {
|
|
4153
4194
|
const pool = this.getPool();
|
|
4154
|
-
const
|
|
4155
|
-
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
|
|
4166
|
-
WHERE thread_id = $1
|
|
4167
|
-
LIMIT 1`,
|
|
4168
|
-
[threadId]
|
|
4169
|
-
);
|
|
4170
|
-
let tenantId = "default";
|
|
4171
|
-
let assistantId = "";
|
|
4172
|
-
if (threadResult.rows.length > 0) {
|
|
4173
|
-
tenantId = threadResult.rows[0].tenant_id;
|
|
4174
|
-
assistantId = threadResult.rows[0].assistant_id;
|
|
4175
|
-
}
|
|
4176
|
-
const result = await client.query(
|
|
4177
|
-
`INSERT INTO thread_message_queue
|
|
4178
|
-
(thread_id, tenant_id, assistant_id, message_content, message_type, sequence_order)
|
|
4179
|
-
VALUES ($1, $2, $3, $4, $5, 0)
|
|
4180
|
-
RETURNING *`,
|
|
4181
|
-
[threadId, tenantId, assistantId, JSON.stringify(content), type]
|
|
4182
|
-
);
|
|
4183
|
-
await client.query("COMMIT");
|
|
4184
|
-
return this.rowToMessage(result.rows[0]);
|
|
4185
|
-
} catch (error) {
|
|
4186
|
-
await client.query("ROLLBACK");
|
|
4187
|
-
throw error;
|
|
4188
|
-
} finally {
|
|
4189
|
-
client.release();
|
|
4195
|
+
const threadResult = await pool.query(
|
|
4196
|
+
`SELECT tenant_id, assistant_id
|
|
4197
|
+
FROM lattice_thread_message_queue
|
|
4198
|
+
WHERE thread_id = $1
|
|
4199
|
+
LIMIT 1`,
|
|
4200
|
+
[threadId]
|
|
4201
|
+
);
|
|
4202
|
+
let tenantId = "default";
|
|
4203
|
+
let assistantId = "";
|
|
4204
|
+
if (threadResult.rows.length > 0) {
|
|
4205
|
+
tenantId = threadResult.rows[0].tenant_id;
|
|
4206
|
+
assistantId = threadResult.rows[0].assistant_id;
|
|
4190
4207
|
}
|
|
4208
|
+
const seqResult = await pool.query(
|
|
4209
|
+
`SELECT COALESCE(MAX(sequence_order), 0) + 1 as next_seq
|
|
4210
|
+
FROM lattice_thread_message_queue
|
|
4211
|
+
WHERE thread_id = $1`,
|
|
4212
|
+
[threadId]
|
|
4213
|
+
);
|
|
4214
|
+
const nextSeq = seqResult.rows[0].next_seq;
|
|
4215
|
+
const result = await pool.query(
|
|
4216
|
+
`INSERT INTO lattice_thread_message_queue
|
|
4217
|
+
(id, thread_id, tenant_id, assistant_id, message_content, message_type, sequence_order, priority, command)
|
|
4218
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, 100, $8)
|
|
4219
|
+
RETURNING *`,
|
|
4220
|
+
[id || import_crypto.default.randomUUID(), threadId, tenantId, assistantId, JSON.stringify(content), type, nextSeq, command ? JSON.stringify(command) : null]
|
|
4221
|
+
);
|
|
4222
|
+
return this.rowToMessage(result.rows[0]);
|
|
4191
4223
|
}
|
|
4192
4224
|
/**
|
|
4193
4225
|
* Get pending messages for thread
|
|
@@ -4195,9 +4227,9 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4195
4227
|
async getPendingMessages(threadId) {
|
|
4196
4228
|
const pool = this.getPool();
|
|
4197
4229
|
const result = await pool.query(
|
|
4198
|
-
`SELECT * FROM
|
|
4230
|
+
`SELECT * FROM lattice_thread_message_queue
|
|
4199
4231
|
WHERE thread_id = $1 AND status = 'pending'
|
|
4200
|
-
ORDER BY sequence_order ASC`,
|
|
4232
|
+
ORDER BY priority DESC, sequence_order ASC`,
|
|
4201
4233
|
[threadId]
|
|
4202
4234
|
);
|
|
4203
4235
|
return result.rows.map((row) => this.rowToMessage(row));
|
|
@@ -4208,9 +4240,9 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4208
4240
|
async getProcessingMessages(threadId) {
|
|
4209
4241
|
const pool = this.getPool();
|
|
4210
4242
|
const result = await pool.query(
|
|
4211
|
-
`SELECT * FROM
|
|
4243
|
+
`SELECT * FROM lattice_thread_message_queue
|
|
4212
4244
|
WHERE thread_id = $1 AND status = 'processing'
|
|
4213
|
-
ORDER BY sequence_order ASC`,
|
|
4245
|
+
ORDER BY priority DESC, sequence_order ASC`,
|
|
4214
4246
|
[threadId]
|
|
4215
4247
|
);
|
|
4216
4248
|
return result.rows.map((row) => this.rowToMessage(row));
|
|
@@ -4221,21 +4253,21 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4221
4253
|
async getQueueSize(threadId) {
|
|
4222
4254
|
const pool = this.getPool();
|
|
4223
4255
|
const result = await pool.query(
|
|
4224
|
-
`SELECT COUNT(*) as count FROM
|
|
4256
|
+
`SELECT COUNT(*) as count FROM lattice_thread_message_queue
|
|
4225
4257
|
WHERE thread_id = $1 AND status = 'pending'`,
|
|
4226
4258
|
[threadId]
|
|
4227
4259
|
);
|
|
4228
4260
|
return parseInt(result.rows[0].count, 10);
|
|
4229
4261
|
}
|
|
4230
4262
|
/**
|
|
4231
|
-
* Get all threads with pending messages
|
|
4263
|
+
* Get all threads with pending or processing messages
|
|
4232
4264
|
*/
|
|
4233
4265
|
async getThreadsWithPendingMessages() {
|
|
4234
4266
|
const pool = this.getPool();
|
|
4235
4267
|
const result = await pool.query(
|
|
4236
4268
|
`SELECT DISTINCT tenant_id, assistant_id, thread_id
|
|
4237
|
-
FROM
|
|
4238
|
-
WHERE status
|
|
4269
|
+
FROM lattice_thread_message_queue
|
|
4270
|
+
WHERE status IN ('pending', 'processing')
|
|
4239
4271
|
ORDER BY thread_id`
|
|
4240
4272
|
);
|
|
4241
4273
|
return result.rows.map((row) => ({
|
|
@@ -4250,7 +4282,7 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4250
4282
|
async removeMessage(messageId) {
|
|
4251
4283
|
const pool = this.getPool();
|
|
4252
4284
|
const result = await pool.query(
|
|
4253
|
-
`DELETE FROM
|
|
4285
|
+
`DELETE FROM lattice_thread_message_queue WHERE id = $1 RETURNING id`,
|
|
4254
4286
|
[messageId]
|
|
4255
4287
|
);
|
|
4256
4288
|
return (result.rowCount ?? 0) > 0;
|
|
@@ -4261,7 +4293,7 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4261
4293
|
async clearMessages(threadId) {
|
|
4262
4294
|
const pool = this.getPool();
|
|
4263
4295
|
await pool.query(
|
|
4264
|
-
`DELETE FROM
|
|
4296
|
+
`DELETE FROM lattice_thread_message_queue WHERE thread_id = $1`,
|
|
4265
4297
|
[threadId]
|
|
4266
4298
|
);
|
|
4267
4299
|
}
|
|
@@ -4271,7 +4303,7 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4271
4303
|
async markProcessing(messageId) {
|
|
4272
4304
|
const pool = this.getPool();
|
|
4273
4305
|
await pool.query(
|
|
4274
|
-
`UPDATE
|
|
4306
|
+
`UPDATE lattice_thread_message_queue SET status = 'processing' WHERE id = $1`,
|
|
4275
4307
|
[messageId]
|
|
4276
4308
|
);
|
|
4277
4309
|
}
|
|
@@ -4281,7 +4313,7 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4281
4313
|
async markCompleted(messageId) {
|
|
4282
4314
|
const pool = this.getPool();
|
|
4283
4315
|
await pool.query(
|
|
4284
|
-
`UPDATE
|
|
4316
|
+
`UPDATE lattice_thread_message_queue SET status = 'completed' WHERE id = $1`,
|
|
4285
4317
|
[messageId]
|
|
4286
4318
|
);
|
|
4287
4319
|
}
|
|
@@ -4291,11 +4323,26 @@ var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
|
4291
4323
|
async clearCompletedMessages(threadId) {
|
|
4292
4324
|
const pool = this.getPool();
|
|
4293
4325
|
await pool.query(
|
|
4294
|
-
`DELETE FROM
|
|
4326
|
+
`DELETE FROM lattice_thread_message_queue
|
|
4295
4327
|
WHERE thread_id = $1 AND status = 'completed'`,
|
|
4296
4328
|
[threadId]
|
|
4297
4329
|
);
|
|
4298
4330
|
}
|
|
4331
|
+
/**
|
|
4332
|
+
* Reset all processing messages to pending state for a thread
|
|
4333
|
+
* Returns the number of messages reset
|
|
4334
|
+
*/
|
|
4335
|
+
async resetProcessingToPending(threadId) {
|
|
4336
|
+
const pool = this.getPool();
|
|
4337
|
+
const result = await pool.query(
|
|
4338
|
+
`UPDATE lattice_thread_message_queue
|
|
4339
|
+
SET status = 'pending'
|
|
4340
|
+
WHERE thread_id = $1 AND status = 'processing'
|
|
4341
|
+
RETURNING id`,
|
|
4342
|
+
[threadId]
|
|
4343
|
+
);
|
|
4344
|
+
return result.rowCount ?? 0;
|
|
4345
|
+
}
|
|
4299
4346
|
rowToMessage(row) {
|
|
4300
4347
|
return {
|
|
4301
4348
|
id: row.id,
|
|
@@ -4314,6 +4361,8 @@ var getThreadMessageQueueStore = () => ThreadMessageQueueStore.getInstance();
|
|
|
4314
4361
|
AddMessageParams,
|
|
4315
4362
|
MigrationManager,
|
|
4316
4363
|
PendingMessage,
|
|
4364
|
+
Pool,
|
|
4365
|
+
PoolConfig,
|
|
4317
4366
|
PostgreSQLAssistantStore,
|
|
4318
4367
|
PostgreSQLDatabaseConfigStore,
|
|
4319
4368
|
PostgreSQLMcpServerConfigStore,
|