@axiom-lattice/pg-stores 1.0.27 → 1.0.29
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 +79 -1
- package/dist/index.d.ts +79 -1
- package/dist/index.js +305 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +302 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/ThreadMessageQueueStore.test.ts +299 -0
- package/src/index.ts +2 -0
- package/src/migrations/add_priority_command_columns.ts +38 -0
- package/src/migrations/thread_message_queue_migrations.ts +58 -0
- package/src/stores/ThreadMessageQueueStore.ts +276 -0
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.29 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
|
-
[32mESM[39m [1mdist/index.mjs [22m[
|
|
12
|
-
[32mESM[39m [1mdist/index.mjs.map [22m[
|
|
13
|
-
[32mESM[39m ⚡️ Build success in
|
|
14
|
-
[32mCJS[39m [1mdist/index.js [22m[
|
|
15
|
-
[32mCJS[39m [1mdist/index.js.map [22m[
|
|
16
|
-
[32mCJS[39m ⚡️ Build success in
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m126.55 KB[39m
|
|
12
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m238.36 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 350ms
|
|
14
|
+
[32mCJS[39m [1mdist/index.js [22m[32m129.87 KB[39m
|
|
15
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m242.52 KB[39m
|
|
16
|
+
[32mCJS[39m ⚡️ Build success in 353ms
|
|
17
17
|
[34mDTS[39m Build start
|
|
18
|
-
[32mDTS[39m ⚡️ Build success in
|
|
19
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
18
|
+
[32mDTS[39m ⚡️ Build success in 11601ms
|
|
19
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m34.21 KB[39m
|
|
20
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m34.21 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @axiom-lattice/pg-stores
|
|
2
2
|
|
|
3
|
+
## 1.0.29
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1502b21: update all
|
|
8
|
+
- Updated dependencies [1502b21]
|
|
9
|
+
- @axiom-lattice/core@2.1.39
|
|
10
|
+
- @axiom-lattice/protocols@2.1.21
|
|
11
|
+
|
|
12
|
+
## 1.0.28
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [defd326]
|
|
17
|
+
- @axiom-lattice/core@2.1.38
|
|
18
|
+
|
|
3
19
|
## 1.0.27
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PoolConfig, PoolClient, Pool } from 'pg';
|
|
2
2
|
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
3
|
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
|
+
import { IMessageQueueStore, AddMessageParams, PendingMessage, ThreadInfo } from '@axiom-lattice/core';
|
|
5
|
+
export { AddMessageParams, PendingMessage, ThreadInfo } from '@axiom-lattice/core';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* PostgreSQL implementation of ThreadStore
|
|
@@ -1074,4 +1076,80 @@ declare const createUsersTable: Migration;
|
|
|
1074
1076
|
*/
|
|
1075
1077
|
declare const createTenantsTable: Migration;
|
|
1076
1078
|
|
|
1077
|
-
|
|
1079
|
+
/**
|
|
1080
|
+
* Thread message queue migrations
|
|
1081
|
+
*/
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* Migration: Create thread message queue table
|
|
1085
|
+
*/
|
|
1086
|
+
declare const createThreadMessageQueueTable: Migration;
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Thread Message Queue Store
|
|
1090
|
+
*
|
|
1091
|
+
* Provides PostgreSQL storage for thread message queues
|
|
1092
|
+
*/
|
|
1093
|
+
|
|
1094
|
+
declare class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
1095
|
+
private static _instance;
|
|
1096
|
+
private pool;
|
|
1097
|
+
private initialized;
|
|
1098
|
+
static getInstance(): ThreadMessageQueueStore;
|
|
1099
|
+
private constructor();
|
|
1100
|
+
/**
|
|
1101
|
+
* Initialize with PostgreSQL pool
|
|
1102
|
+
* @param pool - PostgreSQL connection pool
|
|
1103
|
+
* @param autoMigrate - Whether to run migrations automatically (default: true)
|
|
1104
|
+
*/
|
|
1105
|
+
initialize(pool: Pool, autoMigrate?: boolean): Promise<void>;
|
|
1106
|
+
private getPool;
|
|
1107
|
+
/**
|
|
1108
|
+
* Add message to queue
|
|
1109
|
+
*/
|
|
1110
|
+
addMessage(params: AddMessageParams): Promise<PendingMessage>;
|
|
1111
|
+
/**
|
|
1112
|
+
* Add message at head of queue (sequence = 0, shift others)
|
|
1113
|
+
*/
|
|
1114
|
+
addMessageAtHead(threadId: string, content: any, type?: "human" | "system"): Promise<PendingMessage>;
|
|
1115
|
+
/**
|
|
1116
|
+
* Get pending messages for thread
|
|
1117
|
+
*/
|
|
1118
|
+
getPendingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Get processing messages for a thread
|
|
1121
|
+
*/
|
|
1122
|
+
getProcessingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Get queue size
|
|
1125
|
+
*/
|
|
1126
|
+
getQueueSize(threadId: string): Promise<number>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Get all threads with pending messages
|
|
1129
|
+
*/
|
|
1130
|
+
getThreadsWithPendingMessages(): Promise<ThreadInfo[]>;
|
|
1131
|
+
/**
|
|
1132
|
+
* Remove message
|
|
1133
|
+
*/
|
|
1134
|
+
removeMessage(messageId: string): Promise<boolean>;
|
|
1135
|
+
/**
|
|
1136
|
+
* Clear all messages for thread
|
|
1137
|
+
*/
|
|
1138
|
+
clearMessages(threadId: string): Promise<void>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Mark message as processing
|
|
1141
|
+
*/
|
|
1142
|
+
markProcessing(messageId: string): Promise<void>;
|
|
1143
|
+
/**
|
|
1144
|
+
* Mark message as completed
|
|
1145
|
+
*/
|
|
1146
|
+
markCompleted(messageId: string): Promise<void>;
|
|
1147
|
+
/**
|
|
1148
|
+
* Clear completed messages for thread
|
|
1149
|
+
*/
|
|
1150
|
+
clearCompletedMessages(threadId: string): Promise<void>;
|
|
1151
|
+
private rowToMessage;
|
|
1152
|
+
}
|
|
1153
|
+
declare const getThreadMessageQueueStore: () => ThreadMessageQueueStore;
|
|
1154
|
+
|
|
1155
|
+
export { type Migration, MigrationManager, PostgreSQLAssistantStore, type PostgreSQLAssistantStoreOptions, PostgreSQLDatabaseConfigStore, type PostgreSQLDatabaseConfigStoreOptions, PostgreSQLMcpServerConfigStore, type PostgreSQLMcpServerConfigStoreOptions, PostgreSQLMetricsServerConfigStore, type PostgreSQLMetricsServerConfigStoreOptions, PostgreSQLProjectStore, type PostgreSQLProjectStoreOptions, PostgreSQLScheduleStorage, type PostgreSQLScheduleStorageOptions, PostgreSQLSkillStore, type PostgreSQLSkillStoreOptions, PostgreSQLTenantStore, type PostgreSQLTenantStoreOptions, PostgreSQLThreadStore, type PostgreSQLThreadStoreOptions, PostgreSQLUserStore, type PostgreSQLUserStoreOptions, PostgreSQLUserTenantLinkStore, type PostgreSQLUserTenantLinkStoreOptions, PostgreSQLWorkspaceStore, type PostgreSQLWorkspaceStoreOptions, ThreadMessageQueueStore, addAssistantTenantId, addScheduleTenantId, addSkillTenantId, addThreadTenantId, changeAssistantPrimaryKey, changeSkillPrimaryKey, changeThreadPrimaryKey, createAssistantsTable, createDatabaseConfigsTable, createMcpServerConfigsTable, createMetricsConfigsTable, createProjectsTable, createScheduledTasksTable, createSkillsTable, createTenantsTable, createThreadMessageQueueTable, createThreadsTable, createUsersTable, createWorkspacesTable, getThreadMessageQueueStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { PoolConfig, PoolClient, Pool } from 'pg';
|
|
2
2
|
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
3
|
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
|
+
import { IMessageQueueStore, AddMessageParams, PendingMessage, ThreadInfo } from '@axiom-lattice/core';
|
|
5
|
+
export { AddMessageParams, PendingMessage, ThreadInfo } from '@axiom-lattice/core';
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* PostgreSQL implementation of ThreadStore
|
|
@@ -1074,4 +1076,80 @@ declare const createUsersTable: Migration;
|
|
|
1074
1076
|
*/
|
|
1075
1077
|
declare const createTenantsTable: Migration;
|
|
1076
1078
|
|
|
1077
|
-
|
|
1079
|
+
/**
|
|
1080
|
+
* Thread message queue migrations
|
|
1081
|
+
*/
|
|
1082
|
+
|
|
1083
|
+
/**
|
|
1084
|
+
* Migration: Create thread message queue table
|
|
1085
|
+
*/
|
|
1086
|
+
declare const createThreadMessageQueueTable: Migration;
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Thread Message Queue Store
|
|
1090
|
+
*
|
|
1091
|
+
* Provides PostgreSQL storage for thread message queues
|
|
1092
|
+
*/
|
|
1093
|
+
|
|
1094
|
+
declare class ThreadMessageQueueStore implements IMessageQueueStore {
|
|
1095
|
+
private static _instance;
|
|
1096
|
+
private pool;
|
|
1097
|
+
private initialized;
|
|
1098
|
+
static getInstance(): ThreadMessageQueueStore;
|
|
1099
|
+
private constructor();
|
|
1100
|
+
/**
|
|
1101
|
+
* Initialize with PostgreSQL pool
|
|
1102
|
+
* @param pool - PostgreSQL connection pool
|
|
1103
|
+
* @param autoMigrate - Whether to run migrations automatically (default: true)
|
|
1104
|
+
*/
|
|
1105
|
+
initialize(pool: Pool, autoMigrate?: boolean): Promise<void>;
|
|
1106
|
+
private getPool;
|
|
1107
|
+
/**
|
|
1108
|
+
* Add message to queue
|
|
1109
|
+
*/
|
|
1110
|
+
addMessage(params: AddMessageParams): Promise<PendingMessage>;
|
|
1111
|
+
/**
|
|
1112
|
+
* Add message at head of queue (sequence = 0, shift others)
|
|
1113
|
+
*/
|
|
1114
|
+
addMessageAtHead(threadId: string, content: any, type?: "human" | "system"): Promise<PendingMessage>;
|
|
1115
|
+
/**
|
|
1116
|
+
* Get pending messages for thread
|
|
1117
|
+
*/
|
|
1118
|
+
getPendingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
1119
|
+
/**
|
|
1120
|
+
* Get processing messages for a thread
|
|
1121
|
+
*/
|
|
1122
|
+
getProcessingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
1123
|
+
/**
|
|
1124
|
+
* Get queue size
|
|
1125
|
+
*/
|
|
1126
|
+
getQueueSize(threadId: string): Promise<number>;
|
|
1127
|
+
/**
|
|
1128
|
+
* Get all threads with pending messages
|
|
1129
|
+
*/
|
|
1130
|
+
getThreadsWithPendingMessages(): Promise<ThreadInfo[]>;
|
|
1131
|
+
/**
|
|
1132
|
+
* Remove message
|
|
1133
|
+
*/
|
|
1134
|
+
removeMessage(messageId: string): Promise<boolean>;
|
|
1135
|
+
/**
|
|
1136
|
+
* Clear all messages for thread
|
|
1137
|
+
*/
|
|
1138
|
+
clearMessages(threadId: string): Promise<void>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Mark message as processing
|
|
1141
|
+
*/
|
|
1142
|
+
markProcessing(messageId: string): Promise<void>;
|
|
1143
|
+
/**
|
|
1144
|
+
* Mark message as completed
|
|
1145
|
+
*/
|
|
1146
|
+
markCompleted(messageId: string): Promise<void>;
|
|
1147
|
+
/**
|
|
1148
|
+
* Clear completed messages for thread
|
|
1149
|
+
*/
|
|
1150
|
+
clearCompletedMessages(threadId: string): Promise<void>;
|
|
1151
|
+
private rowToMessage;
|
|
1152
|
+
}
|
|
1153
|
+
declare const getThreadMessageQueueStore: () => ThreadMessageQueueStore;
|
|
1154
|
+
|
|
1155
|
+
export { type Migration, MigrationManager, PostgreSQLAssistantStore, type PostgreSQLAssistantStoreOptions, PostgreSQLDatabaseConfigStore, type PostgreSQLDatabaseConfigStoreOptions, PostgreSQLMcpServerConfigStore, type PostgreSQLMcpServerConfigStoreOptions, PostgreSQLMetricsServerConfigStore, type PostgreSQLMetricsServerConfigStoreOptions, PostgreSQLProjectStore, type PostgreSQLProjectStoreOptions, PostgreSQLScheduleStorage, type PostgreSQLScheduleStorageOptions, PostgreSQLSkillStore, type PostgreSQLSkillStoreOptions, PostgreSQLTenantStore, type PostgreSQLTenantStoreOptions, PostgreSQLThreadStore, type PostgreSQLThreadStoreOptions, PostgreSQLUserStore, type PostgreSQLUserStoreOptions, PostgreSQLUserTenantLinkStore, type PostgreSQLUserTenantLinkStoreOptions, PostgreSQLWorkspaceStore, type PostgreSQLWorkspaceStoreOptions, ThreadMessageQueueStore, addAssistantTenantId, addScheduleTenantId, addSkillTenantId, addThreadTenantId, changeAssistantPrimaryKey, changeSkillPrimaryKey, changeThreadPrimaryKey, createAssistantsTable, createDatabaseConfigsTable, createMcpServerConfigsTable, createMetricsConfigsTable, createProjectsTable, createScheduledTasksTable, createSkillsTable, createTenantsTable, createThreadMessageQueueTable, createThreadsTable, createUsersTable, createWorkspacesTable, getThreadMessageQueueStore };
|
package/dist/index.js
CHANGED
|
@@ -20,7 +20,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
AddMessageParams: () => import_core4.AddMessageParams,
|
|
23
24
|
MigrationManager: () => MigrationManager,
|
|
25
|
+
PendingMessage: () => import_core4.PendingMessage,
|
|
24
26
|
PostgreSQLAssistantStore: () => PostgreSQLAssistantStore,
|
|
25
27
|
PostgreSQLDatabaseConfigStore: () => PostgreSQLDatabaseConfigStore,
|
|
26
28
|
PostgreSQLMcpServerConfigStore: () => PostgreSQLMcpServerConfigStore,
|
|
@@ -33,6 +35,8 @@ __export(index_exports, {
|
|
|
33
35
|
PostgreSQLUserStore: () => PostgreSQLUserStore,
|
|
34
36
|
PostgreSQLUserTenantLinkStore: () => PostgreSQLUserTenantLinkStore,
|
|
35
37
|
PostgreSQLWorkspaceStore: () => PostgreSQLWorkspaceStore,
|
|
38
|
+
ThreadInfo: () => import_core4.ThreadInfo,
|
|
39
|
+
ThreadMessageQueueStore: () => ThreadMessageQueueStore,
|
|
36
40
|
addAssistantTenantId: () => addAssistantTenantId,
|
|
37
41
|
addScheduleTenantId: () => addScheduleTenantId,
|
|
38
42
|
addSkillTenantId: () => addSkillTenantId,
|
|
@@ -48,9 +52,11 @@ __export(index_exports, {
|
|
|
48
52
|
createScheduledTasksTable: () => createScheduledTasksTable,
|
|
49
53
|
createSkillsTable: () => createSkillsTable,
|
|
50
54
|
createTenantsTable: () => createTenantsTable,
|
|
55
|
+
createThreadMessageQueueTable: () => createThreadMessageQueueTable,
|
|
51
56
|
createThreadsTable: () => createThreadsTable,
|
|
52
57
|
createUsersTable: () => createUsersTable,
|
|
53
|
-
createWorkspacesTable: () => createWorkspacesTable
|
|
58
|
+
createWorkspacesTable: () => createWorkspacesTable,
|
|
59
|
+
getThreadMessageQueueStore: () => getThreadMessageQueueStore
|
|
54
60
|
});
|
|
55
61
|
module.exports = __toCommonJS(index_exports);
|
|
56
62
|
|
|
@@ -4009,9 +4015,302 @@ var PostgreSQLUserTenantLinkStore = class {
|
|
|
4009
4015
|
return result.rows.length > 0;
|
|
4010
4016
|
}
|
|
4011
4017
|
};
|
|
4018
|
+
|
|
4019
|
+
// src/migrations/thread_message_queue_migrations.ts
|
|
4020
|
+
var createThreadMessageQueueTable = {
|
|
4021
|
+
version: 100,
|
|
4022
|
+
name: "create_thread_message_queue_table",
|
|
4023
|
+
up: async (client) => {
|
|
4024
|
+
await client.query(`
|
|
4025
|
+
CREATE TABLE IF NOT EXISTS thread_message_queue (
|
|
4026
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
4027
|
+
thread_id VARCHAR(255) NOT NULL,
|
|
4028
|
+
tenant_id VARCHAR(255) NOT NULL,
|
|
4029
|
+
assistant_id VARCHAR(255) NOT NULL,
|
|
4030
|
+
message_content JSONB NOT NULL,
|
|
4031
|
+
message_type VARCHAR(50) DEFAULT 'human',
|
|
4032
|
+
sequence_order INTEGER NOT NULL,
|
|
4033
|
+
status VARCHAR(50) DEFAULT 'pending',
|
|
4034
|
+
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
4035
|
+
)
|
|
4036
|
+
`);
|
|
4037
|
+
await client.query(`
|
|
4038
|
+
CREATE INDEX IF NOT EXISTS idx_thread_message_queue_thread
|
|
4039
|
+
ON thread_message_queue(thread_id, status)
|
|
4040
|
+
`);
|
|
4041
|
+
await client.query(`
|
|
4042
|
+
CREATE INDEX IF NOT EXISTS idx_thread_message_queue_tenant
|
|
4043
|
+
ON thread_message_queue(tenant_id, thread_id, status)
|
|
4044
|
+
`);
|
|
4045
|
+
await client.query(`
|
|
4046
|
+
CREATE INDEX IF NOT EXISTS idx_thread_message_queue_status
|
|
4047
|
+
ON thread_message_queue(status, created_at)
|
|
4048
|
+
`);
|
|
4049
|
+
await client.query(`
|
|
4050
|
+
CREATE UNIQUE INDEX IF NOT EXISTS idx_thread_message_queue_sequence
|
|
4051
|
+
ON thread_message_queue(thread_id, sequence_order)
|
|
4052
|
+
`);
|
|
4053
|
+
},
|
|
4054
|
+
down: async (client) => {
|
|
4055
|
+
await client.query("DROP INDEX IF EXISTS idx_thread_message_queue_sequence");
|
|
4056
|
+
await client.query("DROP INDEX IF EXISTS idx_thread_message_queue_status");
|
|
4057
|
+
await client.query("DROP INDEX IF EXISTS idx_thread_message_queue_tenant");
|
|
4058
|
+
await client.query("DROP INDEX IF EXISTS idx_thread_message_queue_thread");
|
|
4059
|
+
await client.query("DROP TABLE IF EXISTS thread_message_queue");
|
|
4060
|
+
}
|
|
4061
|
+
};
|
|
4062
|
+
|
|
4063
|
+
// src/stores/ThreadMessageQueueStore.ts
|
|
4064
|
+
var import_core4 = require("@axiom-lattice/core");
|
|
4065
|
+
|
|
4066
|
+
// src/migrations/add_priority_command_columns.ts
|
|
4067
|
+
var addPriorityAndCommandColumns = {
|
|
4068
|
+
version: 101,
|
|
4069
|
+
name: "add_priority_and_command_columns",
|
|
4070
|
+
up: async (client) => {
|
|
4071
|
+
await client.query(`
|
|
4072
|
+
ALTER TABLE thread_message_queue
|
|
4073
|
+
ADD COLUMN IF NOT EXISTS priority INTEGER DEFAULT 0
|
|
4074
|
+
`);
|
|
4075
|
+
await client.query(`
|
|
4076
|
+
ALTER TABLE thread_message_queue
|
|
4077
|
+
ADD COLUMN IF NOT EXISTS command JSONB
|
|
4078
|
+
`);
|
|
4079
|
+
await client.query(`
|
|
4080
|
+
CREATE INDEX IF NOT EXISTS idx_thread_message_queue_priority
|
|
4081
|
+
ON thread_message_queue(thread_id, priority DESC, sequence_order ASC)
|
|
4082
|
+
`);
|
|
4083
|
+
},
|
|
4084
|
+
down: async (client) => {
|
|
4085
|
+
await client.query("DROP INDEX IF EXISTS idx_thread_message_queue_priority");
|
|
4086
|
+
await client.query("ALTER TABLE thread_message_queue DROP COLUMN IF EXISTS command");
|
|
4087
|
+
await client.query("ALTER TABLE thread_message_queue DROP COLUMN IF EXISTS priority");
|
|
4088
|
+
}
|
|
4089
|
+
};
|
|
4090
|
+
|
|
4091
|
+
// src/stores/ThreadMessageQueueStore.ts
|
|
4092
|
+
var ThreadMessageQueueStore = class _ThreadMessageQueueStore {
|
|
4093
|
+
constructor() {
|
|
4094
|
+
this.pool = null;
|
|
4095
|
+
this.initialized = false;
|
|
4096
|
+
}
|
|
4097
|
+
static getInstance() {
|
|
4098
|
+
if (!_ThreadMessageQueueStore._instance) {
|
|
4099
|
+
_ThreadMessageQueueStore._instance = new _ThreadMessageQueueStore();
|
|
4100
|
+
}
|
|
4101
|
+
return _ThreadMessageQueueStore._instance;
|
|
4102
|
+
}
|
|
4103
|
+
/**
|
|
4104
|
+
* Initialize with PostgreSQL pool
|
|
4105
|
+
* @param pool - PostgreSQL connection pool
|
|
4106
|
+
* @param autoMigrate - Whether to run migrations automatically (default: true)
|
|
4107
|
+
*/
|
|
4108
|
+
async initialize(pool, autoMigrate = true) {
|
|
4109
|
+
this.pool = pool;
|
|
4110
|
+
if (autoMigrate && !this.initialized) {
|
|
4111
|
+
const migrationManager = new MigrationManager(pool);
|
|
4112
|
+
migrationManager.register(createThreadMessageQueueTable);
|
|
4113
|
+
migrationManager.register(addPriorityAndCommandColumns);
|
|
4114
|
+
await migrationManager.migrate();
|
|
4115
|
+
this.initialized = true;
|
|
4116
|
+
}
|
|
4117
|
+
}
|
|
4118
|
+
getPool() {
|
|
4119
|
+
if (!this.pool) {
|
|
4120
|
+
throw new Error("ThreadMessageQueueStore not initialized. Call initialize() first.");
|
|
4121
|
+
}
|
|
4122
|
+
return this.pool;
|
|
4123
|
+
}
|
|
4124
|
+
/**
|
|
4125
|
+
* Add message to queue
|
|
4126
|
+
*/
|
|
4127
|
+
async addMessage(params) {
|
|
4128
|
+
const pool = this.getPool();
|
|
4129
|
+
const { threadId, tenantId, assistantId, content, type = "human", priority = 0, command } = params;
|
|
4130
|
+
const seqResult = await pool.query(
|
|
4131
|
+
`SELECT COALESCE(MAX(sequence_order), 0) + 1 as next_seq
|
|
4132
|
+
FROM thread_message_queue
|
|
4133
|
+
WHERE thread_id = $1`,
|
|
4134
|
+
[threadId]
|
|
4135
|
+
);
|
|
4136
|
+
const nextSeq = seqResult.rows[0].next_seq;
|
|
4137
|
+
const result = await pool.query(
|
|
4138
|
+
`INSERT INTO thread_message_queue
|
|
4139
|
+
(thread_id, tenant_id, assistant_id, message_content, message_type, sequence_order, priority, command)
|
|
4140
|
+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
|
4141
|
+
RETURNING *`,
|
|
4142
|
+
[threadId, tenantId, assistantId, JSON.stringify(content), type, nextSeq, priority, command ? JSON.stringify(command) : null]
|
|
4143
|
+
);
|
|
4144
|
+
return this.rowToMessage(result.rows[0]);
|
|
4145
|
+
}
|
|
4146
|
+
/**
|
|
4147
|
+
* Add message at head of queue (sequence = 0, shift others)
|
|
4148
|
+
*/
|
|
4149
|
+
async addMessageAtHead(threadId, content, type = "system") {
|
|
4150
|
+
const pool = this.getPool();
|
|
4151
|
+
const client = await pool.connect();
|
|
4152
|
+
try {
|
|
4153
|
+
await client.query("BEGIN");
|
|
4154
|
+
await client.query(
|
|
4155
|
+
`UPDATE thread_message_queue
|
|
4156
|
+
SET sequence_order = sequence_order + 1
|
|
4157
|
+
WHERE thread_id = $1`,
|
|
4158
|
+
[threadId]
|
|
4159
|
+
);
|
|
4160
|
+
const threadResult = await client.query(
|
|
4161
|
+
`SELECT tenant_id, assistant_id
|
|
4162
|
+
FROM thread_message_queue
|
|
4163
|
+
WHERE thread_id = $1
|
|
4164
|
+
LIMIT 1`,
|
|
4165
|
+
[threadId]
|
|
4166
|
+
);
|
|
4167
|
+
let tenantId = "default";
|
|
4168
|
+
let assistantId = "";
|
|
4169
|
+
if (threadResult.rows.length > 0) {
|
|
4170
|
+
tenantId = threadResult.rows[0].tenant_id;
|
|
4171
|
+
assistantId = threadResult.rows[0].assistant_id;
|
|
4172
|
+
}
|
|
4173
|
+
const result = await client.query(
|
|
4174
|
+
`INSERT INTO thread_message_queue
|
|
4175
|
+
(thread_id, tenant_id, assistant_id, message_content, message_type, sequence_order)
|
|
4176
|
+
VALUES ($1, $2, $3, $4, $5, 0)
|
|
4177
|
+
RETURNING *`,
|
|
4178
|
+
[threadId, tenantId, assistantId, JSON.stringify(content), type]
|
|
4179
|
+
);
|
|
4180
|
+
await client.query("COMMIT");
|
|
4181
|
+
return this.rowToMessage(result.rows[0]);
|
|
4182
|
+
} catch (error) {
|
|
4183
|
+
await client.query("ROLLBACK");
|
|
4184
|
+
throw error;
|
|
4185
|
+
} finally {
|
|
4186
|
+
client.release();
|
|
4187
|
+
}
|
|
4188
|
+
}
|
|
4189
|
+
/**
|
|
4190
|
+
* Get pending messages for thread
|
|
4191
|
+
*/
|
|
4192
|
+
async getPendingMessages(threadId) {
|
|
4193
|
+
const pool = this.getPool();
|
|
4194
|
+
const result = await pool.query(
|
|
4195
|
+
`SELECT * FROM thread_message_queue
|
|
4196
|
+
WHERE thread_id = $1 AND status = 'pending'
|
|
4197
|
+
ORDER BY sequence_order ASC`,
|
|
4198
|
+
[threadId]
|
|
4199
|
+
);
|
|
4200
|
+
return result.rows.map((row) => this.rowToMessage(row));
|
|
4201
|
+
}
|
|
4202
|
+
/**
|
|
4203
|
+
* Get processing messages for a thread
|
|
4204
|
+
*/
|
|
4205
|
+
async getProcessingMessages(threadId) {
|
|
4206
|
+
const pool = this.getPool();
|
|
4207
|
+
const result = await pool.query(
|
|
4208
|
+
`SELECT * FROM thread_message_queue
|
|
4209
|
+
WHERE thread_id = $1 AND status = 'processing'
|
|
4210
|
+
ORDER BY sequence_order ASC`,
|
|
4211
|
+
[threadId]
|
|
4212
|
+
);
|
|
4213
|
+
return result.rows.map((row) => this.rowToMessage(row));
|
|
4214
|
+
}
|
|
4215
|
+
/**
|
|
4216
|
+
* Get queue size
|
|
4217
|
+
*/
|
|
4218
|
+
async getQueueSize(threadId) {
|
|
4219
|
+
const pool = this.getPool();
|
|
4220
|
+
const result = await pool.query(
|
|
4221
|
+
`SELECT COUNT(*) as count FROM thread_message_queue
|
|
4222
|
+
WHERE thread_id = $1 AND status = 'pending'`,
|
|
4223
|
+
[threadId]
|
|
4224
|
+
);
|
|
4225
|
+
return parseInt(result.rows[0].count, 10);
|
|
4226
|
+
}
|
|
4227
|
+
/**
|
|
4228
|
+
* Get all threads with pending messages
|
|
4229
|
+
*/
|
|
4230
|
+
async getThreadsWithPendingMessages() {
|
|
4231
|
+
const pool = this.getPool();
|
|
4232
|
+
const result = await pool.query(
|
|
4233
|
+
`SELECT DISTINCT tenant_id, assistant_id, thread_id
|
|
4234
|
+
FROM thread_message_queue
|
|
4235
|
+
WHERE status = 'pending'
|
|
4236
|
+
ORDER BY thread_id`
|
|
4237
|
+
);
|
|
4238
|
+
return result.rows.map((row) => ({
|
|
4239
|
+
tenantId: row.tenant_id,
|
|
4240
|
+
assistantId: row.assistant_id,
|
|
4241
|
+
threadId: row.thread_id
|
|
4242
|
+
}));
|
|
4243
|
+
}
|
|
4244
|
+
/**
|
|
4245
|
+
* Remove message
|
|
4246
|
+
*/
|
|
4247
|
+
async removeMessage(messageId) {
|
|
4248
|
+
const pool = this.getPool();
|
|
4249
|
+
const result = await pool.query(
|
|
4250
|
+
`DELETE FROM thread_message_queue WHERE id = $1 RETURNING id`,
|
|
4251
|
+
[messageId]
|
|
4252
|
+
);
|
|
4253
|
+
return (result.rowCount ?? 0) > 0;
|
|
4254
|
+
}
|
|
4255
|
+
/**
|
|
4256
|
+
* Clear all messages for thread
|
|
4257
|
+
*/
|
|
4258
|
+
async clearMessages(threadId) {
|
|
4259
|
+
const pool = this.getPool();
|
|
4260
|
+
await pool.query(
|
|
4261
|
+
`DELETE FROM thread_message_queue WHERE thread_id = $1`,
|
|
4262
|
+
[threadId]
|
|
4263
|
+
);
|
|
4264
|
+
}
|
|
4265
|
+
/**
|
|
4266
|
+
* Mark message as processing
|
|
4267
|
+
*/
|
|
4268
|
+
async markProcessing(messageId) {
|
|
4269
|
+
const pool = this.getPool();
|
|
4270
|
+
await pool.query(
|
|
4271
|
+
`UPDATE thread_message_queue SET status = 'processing' WHERE id = $1`,
|
|
4272
|
+
[messageId]
|
|
4273
|
+
);
|
|
4274
|
+
}
|
|
4275
|
+
/**
|
|
4276
|
+
* Mark message as completed
|
|
4277
|
+
*/
|
|
4278
|
+
async markCompleted(messageId) {
|
|
4279
|
+
const pool = this.getPool();
|
|
4280
|
+
await pool.query(
|
|
4281
|
+
`UPDATE thread_message_queue SET status = 'completed' WHERE id = $1`,
|
|
4282
|
+
[messageId]
|
|
4283
|
+
);
|
|
4284
|
+
}
|
|
4285
|
+
/**
|
|
4286
|
+
* Clear completed messages for thread
|
|
4287
|
+
*/
|
|
4288
|
+
async clearCompletedMessages(threadId) {
|
|
4289
|
+
const pool = this.getPool();
|
|
4290
|
+
await pool.query(
|
|
4291
|
+
`DELETE FROM thread_message_queue
|
|
4292
|
+
WHERE thread_id = $1 AND status = 'completed'`,
|
|
4293
|
+
[threadId]
|
|
4294
|
+
);
|
|
4295
|
+
}
|
|
4296
|
+
rowToMessage(row) {
|
|
4297
|
+
return {
|
|
4298
|
+
id: row.id,
|
|
4299
|
+
content: typeof row.message_content === "string" ? JSON.parse(row.message_content) : row.message_content,
|
|
4300
|
+
type: row.message_type,
|
|
4301
|
+
sequence: row.sequence_order,
|
|
4302
|
+
createdAt: new Date(row.created_at),
|
|
4303
|
+
priority: row.priority || 0,
|
|
4304
|
+
command: row.command ? typeof row.command === "string" ? JSON.parse(row.command) : row.command : void 0
|
|
4305
|
+
};
|
|
4306
|
+
}
|
|
4307
|
+
};
|
|
4308
|
+
var getThreadMessageQueueStore = () => ThreadMessageQueueStore.getInstance();
|
|
4012
4309
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4013
4310
|
0 && (module.exports = {
|
|
4311
|
+
AddMessageParams,
|
|
4014
4312
|
MigrationManager,
|
|
4313
|
+
PendingMessage,
|
|
4015
4314
|
PostgreSQLAssistantStore,
|
|
4016
4315
|
PostgreSQLDatabaseConfigStore,
|
|
4017
4316
|
PostgreSQLMcpServerConfigStore,
|
|
@@ -4024,6 +4323,8 @@ var PostgreSQLUserTenantLinkStore = class {
|
|
|
4024
4323
|
PostgreSQLUserStore,
|
|
4025
4324
|
PostgreSQLUserTenantLinkStore,
|
|
4026
4325
|
PostgreSQLWorkspaceStore,
|
|
4326
|
+
ThreadInfo,
|
|
4327
|
+
ThreadMessageQueueStore,
|
|
4027
4328
|
addAssistantTenantId,
|
|
4028
4329
|
addScheduleTenantId,
|
|
4029
4330
|
addSkillTenantId,
|
|
@@ -4039,8 +4340,10 @@ var PostgreSQLUserTenantLinkStore = class {
|
|
|
4039
4340
|
createScheduledTasksTable,
|
|
4040
4341
|
createSkillsTable,
|
|
4041
4342
|
createTenantsTable,
|
|
4343
|
+
createThreadMessageQueueTable,
|
|
4042
4344
|
createThreadsTable,
|
|
4043
4345
|
createUsersTable,
|
|
4044
|
-
createWorkspacesTable
|
|
4346
|
+
createWorkspacesTable,
|
|
4347
|
+
getThreadMessageQueueStore
|
|
4045
4348
|
});
|
|
4046
4349
|
//# sourceMappingURL=index.js.map
|