@axiom-lattice/gateway 2.1.47 → 2.1.49
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 +7 -7
- package/CHANGELOG.md +20 -0
- package/dist/index.js +26 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/controllers/memory.ts +9 -1
- package/src/controllers/run.ts +4 -4
- package/src/index.ts +11 -0
- package/src/services/agent_task_consumer.ts +9 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axiom-lattice/gateway",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.49",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"pg": "^8.11.0",
|
|
39
39
|
"redis": "^5.0.1",
|
|
40
40
|
"uuid": "^9.0.1",
|
|
41
|
-
"@axiom-lattice/core": "2.1.
|
|
42
|
-
"@axiom-lattice/pg-stores": "1.0.
|
|
43
|
-
"@axiom-lattice/protocols": "2.1.
|
|
44
|
-
"@axiom-lattice/queue-redis": "1.0.
|
|
41
|
+
"@axiom-lattice/core": "2.1.43",
|
|
42
|
+
"@axiom-lattice/pg-stores": "1.0.33",
|
|
43
|
+
"@axiom-lattice/protocols": "2.1.23",
|
|
44
|
+
"@axiom-lattice/queue-redis": "1.0.22"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/jest": "^29.5.14",
|
|
@@ -167,9 +167,17 @@ export const getAgentState = async (
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
// 3. 合并返回
|
|
170
|
+
// Normalize pendingMessages content to string for consistent frontend format
|
|
171
|
+
const normalizedPendingMessages = pendingMessages.map(msg => ({
|
|
172
|
+
...msg,
|
|
173
|
+
content: typeof msg.content === 'object' && msg.content !== null
|
|
174
|
+
? (msg.content.message || JSON.stringify(msg.content))
|
|
175
|
+
: String(msg.content || '')
|
|
176
|
+
}));
|
|
177
|
+
|
|
170
178
|
const mergedResult = {
|
|
171
179
|
...result,
|
|
172
|
-
pendingMessages
|
|
180
|
+
pendingMessages: normalizedPendingMessages
|
|
173
181
|
};
|
|
174
182
|
|
|
175
183
|
reply.send(mergedResult);
|
package/src/controllers/run.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
agentLatticeManager,
|
|
8
8
|
agentInstanceManager,
|
|
9
9
|
} from "@axiom-lattice/core";
|
|
10
|
+
import { MessageChunkTypes } from "@axiom-lattice/protocols";
|
|
10
11
|
|
|
11
12
|
interface ResumeStreamRequest {
|
|
12
13
|
thread_id: string;
|
|
@@ -87,11 +88,10 @@ export const createRun = async (
|
|
|
87
88
|
// return
|
|
88
89
|
// }
|
|
89
90
|
|
|
90
|
-
const stream = agent.chunkStream((result).messageId)
|
|
91
|
+
const stream = agent.chunkStream((result).messageId, [MessageChunkTypes.MESSAGE_COMPLETED])
|
|
91
92
|
|
|
92
93
|
// Forward all chunks to SSE
|
|
93
94
|
for await (const chunk of stream) {
|
|
94
|
-
console.log(input.message, chunk.data.content);
|
|
95
95
|
const success = reply.raw.write(`data: ${JSON.stringify(chunk)}\n\n`);
|
|
96
96
|
if (!success) {
|
|
97
97
|
await new Promise(resolve => reply.raw.once('drain', resolve));
|
|
@@ -169,7 +169,6 @@ export const resumeStream = async (
|
|
|
169
169
|
|
|
170
170
|
try {
|
|
171
171
|
// Create Agent instance for accessing chunk buffer
|
|
172
|
-
// Note: assistant_id, tenant_id are not required for chunkStream
|
|
173
172
|
// Get or create Agent instance (ensures single instance per thread)
|
|
174
173
|
const agent = agentInstanceManager.getAgent({
|
|
175
174
|
assistant_id,
|
|
@@ -180,10 +179,11 @@ export const resumeStream = async (
|
|
|
180
179
|
});
|
|
181
180
|
|
|
182
181
|
// Get the stream from agent's chunk buffer
|
|
183
|
-
const stream = agent.chunkStream(message_id,
|
|
182
|
+
const stream = agent.chunkStream(message_id, [MessageChunkTypes.THREAD_IDLE]);
|
|
184
183
|
|
|
185
184
|
// Stream the chunks to the client
|
|
186
185
|
for await (const chunk of stream) {
|
|
186
|
+
// console.log(chunk);
|
|
187
187
|
reply.raw.write(`data: ${JSON.stringify(chunk)}\n\n`);
|
|
188
188
|
}
|
|
189
189
|
} catch (error: any) {
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
sandboxLatticeManager,
|
|
20
20
|
sqlDatabaseManager,
|
|
21
21
|
getStoreLattice,
|
|
22
|
+
agentInstanceManager,
|
|
22
23
|
} from "@axiom-lattice/core";
|
|
23
24
|
import type { DatabaseConfigStore } from "@axiom-lattice/protocols";
|
|
24
25
|
import {
|
|
@@ -260,6 +261,16 @@ const start = async (config?: LatticeGatewayConfig) => {
|
|
|
260
261
|
agentTaskConsumer.startPollingQueue();
|
|
261
262
|
}
|
|
262
263
|
}
|
|
264
|
+
|
|
265
|
+
// Restore agent instances with pending messages
|
|
266
|
+
try {
|
|
267
|
+
logger.info("Starting agent instance recovery...");
|
|
268
|
+
const restoreStats = await agentInstanceManager.restore();
|
|
269
|
+
logger.info(`Agent recovery complete: ${restoreStats.restored} threads restored, ${restoreStats.errors} errors`);
|
|
270
|
+
} catch (error) {
|
|
271
|
+
logger.error("Agent recovery failed", { error });
|
|
272
|
+
// Don't exit - server can still function even if recovery fails
|
|
273
|
+
}
|
|
263
274
|
} catch (err) {
|
|
264
275
|
logger.error("Server start failed", { error: err });
|
|
265
276
|
process.exit(1);
|
|
@@ -38,9 +38,9 @@ const handleAgentTask = async (
|
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
// 检查API服务器是否可用
|
|
41
|
-
const apiUrl = AgentTaskConsumer.agent_run_endpoint;
|
|
41
|
+
// const apiUrl = AgentTaskConsumer.agent_run_endpoint;
|
|
42
42
|
|
|
43
|
-
console.log(`apiUrl: ${apiUrl}`);
|
|
43
|
+
// console.log(`apiUrl: ${apiUrl}`);
|
|
44
44
|
const agent = agentInstanceManager.getAgent({ assistant_id, thread_id, tenant_id, workspace_id: runConfig?.workspaceId, project_id: runConfig?.projectId, custom_run_config: runConfig })
|
|
45
45
|
await agent.addMessage({ input, command }, QueueMode.STEER);
|
|
46
46
|
if (callback_event) {
|
|
@@ -51,6 +51,13 @@ const handleAgentTask = async (
|
|
|
51
51
|
config: { assistant_id, thread_id, tenant_id },
|
|
52
52
|
});
|
|
53
53
|
})
|
|
54
|
+
agent.subscribeOnce("message:interrupted", (evt) => {
|
|
55
|
+
eventBus.publish(callback_event, {
|
|
56
|
+
success: true,
|
|
57
|
+
state: evt.state,
|
|
58
|
+
config: { assistant_id, thread_id, tenant_id },
|
|
59
|
+
});
|
|
60
|
+
})
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
return true;
|