@axiom-lattice/gateway 2.1.15 → 2.1.16
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 +8 -8
- package/CHANGELOG.md +10 -0
- package/dist/index.js +64 -193
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -169
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/controllers/assistant.ts +26 -9
- package/src/controllers/run.ts +1 -0
- package/src/controllers/threads.ts +22 -8
- package/src/types/index.ts +7 -29
- package/src/stores/assistant_store.ts +0 -83
- package/src/stores/thread_store.ts +0 -115
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axiom-lattice/gateway",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.16",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"pino-roll": "^3.1.0",
|
|
33
33
|
"redis": "^5.0.1",
|
|
34
34
|
"uuid": "^9.0.1",
|
|
35
|
-
"@axiom-lattice/core": "2.1.
|
|
36
|
-
"@axiom-lattice/
|
|
37
|
-
"@axiom-lattice/
|
|
35
|
+
"@axiom-lattice/core": "2.1.12",
|
|
36
|
+
"@axiom-lattice/protocols": "2.1.6",
|
|
37
|
+
"@axiom-lattice/queue-redis": "1.0.5"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/jest": "^29.5.14",
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { FastifyRequest, FastifyReply } from "fastify";
|
|
2
2
|
import { draw_graph } from "../services/agent_service";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { getStoreLattice } from "@axiom-lattice/core";
|
|
4
|
+
import type {
|
|
5
|
+
Assistant,
|
|
6
|
+
CreateAssistantRequest,
|
|
7
|
+
} from "@axiom-lattice/protocols";
|
|
5
8
|
import { randomUUID } from "crypto";
|
|
6
9
|
import { AgentConfig, getAllAgentConfigs } from "@axiom-lattice/core";
|
|
7
10
|
|
|
@@ -72,7 +75,9 @@ export async function getAssistantList(
|
|
|
72
75
|
);
|
|
73
76
|
|
|
74
77
|
// Get stored assistants
|
|
75
|
-
const
|
|
78
|
+
const storeLattice = getStoreLattice("default", "assistant");
|
|
79
|
+
const assistantStore = storeLattice.store;
|
|
80
|
+
const storedAssistants = await assistantStore.getAllAssistants();
|
|
76
81
|
|
|
77
82
|
// Merge both sources, stored assistants take precedence if ID conflicts
|
|
78
83
|
const assistantMap = new Map<string, Assistant>();
|
|
@@ -110,7 +115,9 @@ export async function getAssistant(
|
|
|
110
115
|
const { id } = request.params;
|
|
111
116
|
|
|
112
117
|
// First check stored assistants
|
|
113
|
-
|
|
118
|
+
const storeLattice = getStoreLattice("default", "assistant");
|
|
119
|
+
const assistantStore = storeLattice.store;
|
|
120
|
+
let assistant = await assistantStore.getAssistantById(id);
|
|
114
121
|
|
|
115
122
|
// If not found in store, check code-configured agents
|
|
116
123
|
if (!assistant) {
|
|
@@ -163,7 +170,9 @@ export async function createAssistant(
|
|
|
163
170
|
const id = randomUUID();
|
|
164
171
|
|
|
165
172
|
// Create assistant
|
|
166
|
-
const
|
|
173
|
+
const storeLattice = getStoreLattice("default", "assistant");
|
|
174
|
+
const assistantStore = storeLattice.store;
|
|
175
|
+
const newAssistant = await assistantStore.createAssistant(id, data);
|
|
167
176
|
|
|
168
177
|
return reply.status(201).send({
|
|
169
178
|
success: true,
|
|
@@ -198,8 +207,12 @@ export async function updateAssistant(
|
|
|
198
207
|
});
|
|
199
208
|
}
|
|
200
209
|
|
|
210
|
+
const storeLattice = getStoreLattice("default", "assistant");
|
|
211
|
+
const assistantStore = storeLattice.store;
|
|
212
|
+
|
|
201
213
|
// Check if assistant exists in store
|
|
202
|
-
|
|
214
|
+
const exists = await assistantStore.hasAssistant(id);
|
|
215
|
+
if (!exists) {
|
|
203
216
|
return reply.status(404).send({
|
|
204
217
|
success: false,
|
|
205
218
|
message: "Assistant not found",
|
|
@@ -207,7 +220,7 @@ export async function updateAssistant(
|
|
|
207
220
|
}
|
|
208
221
|
|
|
209
222
|
// Update assistant
|
|
210
|
-
const updatedAssistant = assistantStore.updateAssistant(id, updates);
|
|
223
|
+
const updatedAssistant = await assistantStore.updateAssistant(id, updates);
|
|
211
224
|
|
|
212
225
|
if (!updatedAssistant) {
|
|
213
226
|
return reply.status(500).send({
|
|
@@ -245,8 +258,12 @@ export async function deleteAssistant(
|
|
|
245
258
|
});
|
|
246
259
|
}
|
|
247
260
|
|
|
261
|
+
const storeLattice = getStoreLattice("default", "assistant");
|
|
262
|
+
const assistantStore = storeLattice.store;
|
|
263
|
+
|
|
248
264
|
// Check if assistant exists in store
|
|
249
|
-
|
|
265
|
+
const exists = await assistantStore.hasAssistant(id);
|
|
266
|
+
if (!exists) {
|
|
250
267
|
return reply.status(404).send({
|
|
251
268
|
success: false,
|
|
252
269
|
message: "Assistant not found",
|
|
@@ -254,7 +271,7 @@ export async function deleteAssistant(
|
|
|
254
271
|
}
|
|
255
272
|
|
|
256
273
|
// Delete the assistant
|
|
257
|
-
const deleted = assistantStore.deleteAssistant(id);
|
|
274
|
+
const deleted = await assistantStore.deleteAssistant(id);
|
|
258
275
|
|
|
259
276
|
if (!deleted) {
|
|
260
277
|
return reply.status(500).send({
|
package/src/controllers/run.ts
CHANGED
|
@@ -129,6 +129,7 @@ export const resumeStream = async (
|
|
|
129
129
|
|
|
130
130
|
// Stream the chunks to the client
|
|
131
131
|
for await (const chunk of stream) {
|
|
132
|
+
// console.log("resume stream raw.write", chunk);
|
|
132
133
|
reply.raw.write(`data: ${JSON.stringify(chunk)}\n\n`);
|
|
133
134
|
}
|
|
134
135
|
} catch (error) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FastifyRequest, FastifyReply } from "fastify";
|
|
2
|
-
import {
|
|
2
|
+
import { getStoreLattice } from "@axiom-lattice/core";
|
|
3
3
|
import { Thread, CreateThreadRequest } from "../types";
|
|
4
4
|
import { randomUUID } from "crypto";
|
|
5
5
|
|
|
@@ -46,7 +46,9 @@ export async function getThreadList(
|
|
|
46
46
|
): Promise<ThreadListResponse> {
|
|
47
47
|
const { assistantId } = request.params;
|
|
48
48
|
|
|
49
|
-
const
|
|
49
|
+
const storeLattice = getStoreLattice("default", "thread");
|
|
50
|
+
const threadStore = storeLattice.store;
|
|
51
|
+
const threads = await threadStore.getThreadsByAssistantId(assistantId);
|
|
50
52
|
|
|
51
53
|
return {
|
|
52
54
|
success: true,
|
|
@@ -69,7 +71,9 @@ export async function getThread(
|
|
|
69
71
|
): Promise<ThreadResponse> {
|
|
70
72
|
const { assistantId, threadId } = request.params;
|
|
71
73
|
|
|
72
|
-
const
|
|
74
|
+
const storeLattice = getStoreLattice("default", "thread");
|
|
75
|
+
const threadStore = storeLattice.store;
|
|
76
|
+
const thread = await threadStore.getThreadById(assistantId, threadId);
|
|
73
77
|
|
|
74
78
|
if (!thread) {
|
|
75
79
|
return reply.status(404).send({
|
|
@@ -102,7 +106,9 @@ export async function createThread(
|
|
|
102
106
|
const threadId = randomUUID();
|
|
103
107
|
|
|
104
108
|
// Create thread
|
|
105
|
-
const
|
|
109
|
+
const storeLattice = getStoreLattice("default", "thread");
|
|
110
|
+
const threadStore = storeLattice.store;
|
|
111
|
+
const newThread = await threadStore.createThread(assistantId, threadId, data);
|
|
106
112
|
|
|
107
113
|
return reply.status(201).send({
|
|
108
114
|
success: true,
|
|
@@ -124,8 +130,12 @@ export async function updateThread(
|
|
|
124
130
|
const { assistantId, threadId } = request.params;
|
|
125
131
|
const updates = request.body;
|
|
126
132
|
|
|
133
|
+
const storeLattice = getStoreLattice("default", "thread");
|
|
134
|
+
const threadStore = storeLattice.store;
|
|
135
|
+
|
|
127
136
|
// Check if thread exists
|
|
128
|
-
|
|
137
|
+
const exists = await threadStore.hasThread(assistantId, threadId);
|
|
138
|
+
if (!exists) {
|
|
129
139
|
return reply.status(404).send({
|
|
130
140
|
success: false,
|
|
131
141
|
message: "Thread not found",
|
|
@@ -133,7 +143,7 @@ export async function updateThread(
|
|
|
133
143
|
}
|
|
134
144
|
|
|
135
145
|
// Update thread
|
|
136
|
-
const updatedThread = threadStore.updateThread(
|
|
146
|
+
const updatedThread = await threadStore.updateThread(
|
|
137
147
|
assistantId,
|
|
138
148
|
threadId,
|
|
139
149
|
updates
|
|
@@ -164,8 +174,12 @@ export async function deleteThread(
|
|
|
164
174
|
): Promise<{ success: boolean; message: string }> {
|
|
165
175
|
const { assistantId, threadId } = request.params;
|
|
166
176
|
|
|
177
|
+
const storeLattice = getStoreLattice("default", "thread");
|
|
178
|
+
const threadStore = storeLattice.store;
|
|
179
|
+
|
|
167
180
|
// Check if thread exists
|
|
168
|
-
|
|
181
|
+
const exists = await threadStore.hasThread(assistantId, threadId);
|
|
182
|
+
if (!exists) {
|
|
169
183
|
return reply.status(404).send({
|
|
170
184
|
success: false,
|
|
171
185
|
message: "Thread not found",
|
|
@@ -173,7 +187,7 @@ export async function deleteThread(
|
|
|
173
187
|
}
|
|
174
188
|
|
|
175
189
|
// Delete the thread
|
|
176
|
-
const deleted = threadStore.deleteThread(assistantId, threadId);
|
|
190
|
+
const deleted = await threadStore.deleteThread(assistantId, threadId);
|
|
177
191
|
|
|
178
192
|
if (!deleted) {
|
|
179
193
|
return reply.status(500).send({
|
package/src/types/index.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
//
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
graphDefinition: any;
|
|
7
|
-
createdAt: Date;
|
|
8
|
-
updatedAt: Date;
|
|
9
|
-
}
|
|
1
|
+
// Re-export Assistant types from protocols package
|
|
2
|
+
export type {
|
|
3
|
+
Assistant,
|
|
4
|
+
CreateAssistantRequest,
|
|
5
|
+
} from "@axiom-lattice/protocols";
|
|
10
6
|
|
|
11
7
|
// 运行状态枚举
|
|
12
8
|
export enum RunStatus {
|
|
@@ -75,13 +71,6 @@ export interface Webhook {
|
|
|
75
71
|
updatedAt: Date;
|
|
76
72
|
}
|
|
77
73
|
|
|
78
|
-
// 创建助手请求类型
|
|
79
|
-
export interface CreateAssistantRequest {
|
|
80
|
-
name: string;
|
|
81
|
-
description?: string;
|
|
82
|
-
graphDefinition: any;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
74
|
// 创建运行请求类型
|
|
86
75
|
export interface CreateRunRequest {
|
|
87
76
|
tenant_id: string;
|
|
@@ -122,16 +111,5 @@ export interface ServiceResponse<T = any> {
|
|
|
122
111
|
error?: string;
|
|
123
112
|
}
|
|
124
113
|
|
|
125
|
-
// Thread
|
|
126
|
-
export
|
|
127
|
-
id: string;
|
|
128
|
-
assistantId: string;
|
|
129
|
-
metadata?: Record<string, any>;
|
|
130
|
-
createdAt: Date;
|
|
131
|
-
updatedAt: Date;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Create thread request type
|
|
135
|
-
export interface CreateThreadRequest {
|
|
136
|
-
metadata?: Record<string, any>;
|
|
137
|
-
}
|
|
114
|
+
// Re-export Thread types from protocols package
|
|
115
|
+
export type { Thread, CreateThreadRequest } from "@axiom-lattice/protocols";
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { Assistant, CreateAssistantRequest } from "../types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* In-memory store for assistants
|
|
5
|
-
* Provides CRUD operations for assistant data
|
|
6
|
-
*/
|
|
7
|
-
class AssistantStore {
|
|
8
|
-
private assistants: Map<string, Assistant> = new Map();
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get all assistants
|
|
12
|
-
*/
|
|
13
|
-
getAllAssistants(): Assistant[] {
|
|
14
|
-
return Array.from(this.assistants.values());
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Get assistant by ID
|
|
19
|
-
*/
|
|
20
|
-
getAssistantById(id: string): Assistant | undefined {
|
|
21
|
-
return this.assistants.get(id);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Create a new assistant
|
|
26
|
-
*/
|
|
27
|
-
createAssistant(
|
|
28
|
-
id: string,
|
|
29
|
-
data: CreateAssistantRequest
|
|
30
|
-
): Assistant {
|
|
31
|
-
const now = new Date();
|
|
32
|
-
const assistant: Assistant = {
|
|
33
|
-
id,
|
|
34
|
-
name: data.name,
|
|
35
|
-
description: data.description,
|
|
36
|
-
graphDefinition: data.graphDefinition,
|
|
37
|
-
createdAt: now,
|
|
38
|
-
updatedAt: now,
|
|
39
|
-
};
|
|
40
|
-
this.assistants.set(id, assistant);
|
|
41
|
-
return assistant;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Update an existing assistant
|
|
46
|
-
*/
|
|
47
|
-
updateAssistant(
|
|
48
|
-
id: string,
|
|
49
|
-
updates: Partial<CreateAssistantRequest>
|
|
50
|
-
): Assistant | null {
|
|
51
|
-
const existing = this.assistants.get(id);
|
|
52
|
-
if (!existing) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const updated: Assistant = {
|
|
57
|
-
...existing,
|
|
58
|
-
...updates,
|
|
59
|
-
updatedAt: new Date(),
|
|
60
|
-
};
|
|
61
|
-
this.assistants.set(id, updated);
|
|
62
|
-
return updated;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Delete an assistant by ID
|
|
67
|
-
*/
|
|
68
|
-
deleteAssistant(id: string): boolean {
|
|
69
|
-
return this.assistants.delete(id);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Check if assistant exists
|
|
74
|
-
*/
|
|
75
|
-
hasAssistant(id: string): boolean {
|
|
76
|
-
return this.assistants.has(id);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Export singleton instance
|
|
81
|
-
export const assistantStore = new AssistantStore();
|
|
82
|
-
|
|
83
|
-
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { Thread, CreateThreadRequest } from "../types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* In-memory store for threads
|
|
5
|
-
* Provides CRUD operations for thread data
|
|
6
|
-
* Threads are organized by assistant ID
|
|
7
|
-
*/
|
|
8
|
-
class ThreadStore {
|
|
9
|
-
// Map<assistantId, Map<threadId, Thread>>
|
|
10
|
-
private threads: Map<string, Map<string, Thread>> = new Map();
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Get all threads for a specific assistant
|
|
14
|
-
*/
|
|
15
|
-
getThreadsByAssistantId(assistantId: string): Thread[] {
|
|
16
|
-
const assistantThreads = this.threads.get(assistantId);
|
|
17
|
-
if (!assistantThreads) {
|
|
18
|
-
return [];
|
|
19
|
-
}
|
|
20
|
-
return Array.from(assistantThreads.values());
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get a thread by ID for a specific assistant
|
|
25
|
-
*/
|
|
26
|
-
getThreadById(assistantId: string, threadId: string): Thread | undefined {
|
|
27
|
-
const assistantThreads = this.threads.get(assistantId);
|
|
28
|
-
if (!assistantThreads) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
return assistantThreads.get(threadId);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Create a new thread for an assistant
|
|
36
|
-
*/
|
|
37
|
-
createThread(
|
|
38
|
-
assistantId: string,
|
|
39
|
-
threadId: string,
|
|
40
|
-
data: CreateThreadRequest
|
|
41
|
-
): Thread {
|
|
42
|
-
const now = new Date();
|
|
43
|
-
const thread: Thread = {
|
|
44
|
-
id: threadId,
|
|
45
|
-
assistantId,
|
|
46
|
-
metadata: data.metadata || {},
|
|
47
|
-
createdAt: now,
|
|
48
|
-
updatedAt: now,
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// Initialize assistant's thread map if it doesn't exist
|
|
52
|
-
if (!this.threads.has(assistantId)) {
|
|
53
|
-
this.threads.set(assistantId, new Map());
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const assistantThreads = this.threads.get(assistantId)!;
|
|
57
|
-
assistantThreads.set(threadId, thread);
|
|
58
|
-
return thread;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Update an existing thread
|
|
63
|
-
*/
|
|
64
|
-
updateThread(
|
|
65
|
-
assistantId: string,
|
|
66
|
-
threadId: string,
|
|
67
|
-
updates: Partial<CreateThreadRequest>
|
|
68
|
-
): Thread | null {
|
|
69
|
-
const assistantThreads = this.threads.get(assistantId);
|
|
70
|
-
if (!assistantThreads) {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const existing = assistantThreads.get(threadId);
|
|
75
|
-
if (!existing) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const updated: Thread = {
|
|
80
|
-
...existing,
|
|
81
|
-
metadata: {
|
|
82
|
-
...existing.metadata,
|
|
83
|
-
...(updates.metadata || {}),
|
|
84
|
-
},
|
|
85
|
-
updatedAt: new Date(),
|
|
86
|
-
};
|
|
87
|
-
assistantThreads.set(threadId, updated);
|
|
88
|
-
return updated;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Delete a thread by ID
|
|
93
|
-
*/
|
|
94
|
-
deleteThread(assistantId: string, threadId: string): boolean {
|
|
95
|
-
const assistantThreads = this.threads.get(assistantId);
|
|
96
|
-
if (!assistantThreads) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
return assistantThreads.delete(threadId);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Check if thread exists
|
|
104
|
-
*/
|
|
105
|
-
hasThread(assistantId: string, threadId: string): boolean {
|
|
106
|
-
const assistantThreads = this.threads.get(assistantId);
|
|
107
|
-
if (!assistantThreads) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
return assistantThreads.has(threadId);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Export singleton instance
|
|
115
|
-
export const threadStore = new ThreadStore();
|