@axiom-lattice/gateway 2.1.82 → 2.1.84
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 +32 -0
- package/CHANGELOG.md +22 -0
- package/dist/index.d.mts +0 -2
- package/dist/index.d.ts +0 -2
- package/dist/index.js +27 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +3 -3
- package/src/router/MessageRouter.ts +19 -23
- package/src/router/middlewares/deduplication.ts +1 -2
- package/src/router/middlewares/rateLimit.ts +1 -2
- package/src/routes/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@axiom-lattice/gateway",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.84",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"redis": "^5.0.1",
|
|
41
41
|
"uuid": "^9.0.1",
|
|
42
42
|
"zod": "3.25.76",
|
|
43
|
-
"@axiom-lattice/agent-eval": "2.1.
|
|
44
|
-
"@axiom-lattice/core": "2.1.
|
|
45
|
-
"@axiom-lattice/pg-stores": "1.0.
|
|
46
|
-
"@axiom-lattice/protocols": "2.1.
|
|
47
|
-
"@axiom-lattice/queue-redis": "1.0.
|
|
43
|
+
"@axiom-lattice/agent-eval": "2.1.67",
|
|
44
|
+
"@axiom-lattice/core": "2.1.73",
|
|
45
|
+
"@axiom-lattice/pg-stores": "1.0.63",
|
|
46
|
+
"@axiom-lattice/protocols": "2.1.37",
|
|
47
|
+
"@axiom-lattice/queue-redis": "1.0.36"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/jest": "^29.5.14",
|
package/src/index.ts
CHANGED
|
@@ -287,14 +287,14 @@ const start = async (config?: LatticeGatewayConfig) => {
|
|
|
287
287
|
|
|
288
288
|
const router = new MessageRouter({
|
|
289
289
|
middlewares: [
|
|
290
|
-
createDeduplicationMiddleware(
|
|
291
|
-
createRateLimitMiddleware(
|
|
290
|
+
createDeduplicationMiddleware(),
|
|
291
|
+
createRateLimitMiddleware(),
|
|
292
292
|
createAuditLoggerMiddleware(),
|
|
293
293
|
],
|
|
294
294
|
bindingRegistry: bindingStore,
|
|
295
295
|
adapterRegistry,
|
|
296
296
|
installationStore,
|
|
297
|
-
|
|
297
|
+
|
|
298
298
|
});
|
|
299
299
|
|
|
300
300
|
channelDeps = { router, installationStore };
|
|
@@ -24,7 +24,6 @@ export interface MessageRouterConfig {
|
|
|
24
24
|
bindingRegistry: BindingRegistry;
|
|
25
25
|
adapterRegistry: ChannelAdapterRegistry;
|
|
26
26
|
installationStore: ChannelInstallationStore;
|
|
27
|
-
logger?: any;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
export class MessageRouter {
|
|
@@ -32,14 +31,12 @@ export class MessageRouter {
|
|
|
32
31
|
private bindingRegistry: BindingRegistry;
|
|
33
32
|
private adapterRegistry: ChannelAdapterRegistry;
|
|
34
33
|
private installationStore: ChannelInstallationStore;
|
|
35
|
-
private logger?: any;
|
|
36
34
|
|
|
37
35
|
constructor(config: MessageRouterConfig) {
|
|
38
36
|
this.middlewares = [...config.middlewares];
|
|
39
37
|
this.bindingRegistry = config.bindingRegistry;
|
|
40
38
|
this.adapterRegistry = config.adapterRegistry;
|
|
41
39
|
this.installationStore = config.installationStore;
|
|
42
|
-
this.logger = config.logger;
|
|
43
40
|
}
|
|
44
41
|
|
|
45
42
|
use(middleware: MessageMiddleware): void {
|
|
@@ -59,7 +56,7 @@ export class MessageRouter {
|
|
|
59
56
|
|| (await this.installationStore.getInstallationById(message.channelInstallationId))?.tenantId;
|
|
60
57
|
|
|
61
58
|
if (!tenantId) {
|
|
62
|
-
|
|
59
|
+
console.error({
|
|
63
60
|
event: "dispatch:error",
|
|
64
61
|
error: "tenantId missing",
|
|
65
62
|
channel: message.channel,
|
|
@@ -71,7 +68,7 @@ export class MessageRouter {
|
|
|
71
68
|
);
|
|
72
69
|
}
|
|
73
70
|
|
|
74
|
-
|
|
71
|
+
console.log({ event: "dispatch:start", channel: message.channel, senderId: message.sender.id, tenantId }, "Message dispatch started");
|
|
75
72
|
|
|
76
73
|
let binding = await this.bindingRegistry.resolve({
|
|
77
74
|
channel: message.channel,
|
|
@@ -86,7 +83,7 @@ export class MessageRouter {
|
|
|
86
83
|
);
|
|
87
84
|
|
|
88
85
|
if (installation?.rejectWhenNoBinding) {
|
|
89
|
-
|
|
86
|
+
console.warn({
|
|
90
87
|
event: "dispatch:no_binding",
|
|
91
88
|
channel: message.channel,
|
|
92
89
|
senderId: message.sender.id,
|
|
@@ -99,7 +96,7 @@ export class MessageRouter {
|
|
|
99
96
|
}
|
|
100
97
|
|
|
101
98
|
if (installation?.fallbackAgentId) {
|
|
102
|
-
|
|
99
|
+
console.warn({
|
|
103
100
|
event: "dispatch:fallback",
|
|
104
101
|
channel: message.channel,
|
|
105
102
|
senderId: message.sender.id,
|
|
@@ -119,7 +116,7 @@ export class MessageRouter {
|
|
|
119
116
|
updatedAt: new Date(),
|
|
120
117
|
};
|
|
121
118
|
} else {
|
|
122
|
-
|
|
119
|
+
console.error({
|
|
123
120
|
event: "dispatch:no_fallback",
|
|
124
121
|
channel: message.channel,
|
|
125
122
|
senderId: message.sender.id,
|
|
@@ -133,7 +130,7 @@ export class MessageRouter {
|
|
|
133
130
|
|
|
134
131
|
ctx.binding = binding;
|
|
135
132
|
|
|
136
|
-
|
|
133
|
+
console.log({
|
|
137
134
|
event: "dispatch:binding",
|
|
138
135
|
bindingId: binding.id,
|
|
139
136
|
agentId: binding.agentId,
|
|
@@ -143,16 +140,8 @@ export class MessageRouter {
|
|
|
143
140
|
projectId: binding.projectId,
|
|
144
141
|
}, "Binding resolved");
|
|
145
142
|
|
|
146
|
-
if (binding.threadMode === "per_conversation") {
|
|
147
|
-
this.logger?.warn({
|
|
148
|
-
event: "dispatch:per_conversation",
|
|
149
|
-
bindingId: binding.id,
|
|
150
|
-
conversationId: message.conversation?.id,
|
|
151
|
-
}, "per_conversation mode active — thread lookup by conversation not yet implemented, using binding.threadId");
|
|
152
|
-
}
|
|
153
|
-
|
|
154
143
|
if (!binding.enabled) {
|
|
155
|
-
|
|
144
|
+
console.warn({
|
|
156
145
|
event: "dispatch:binding_disabled",
|
|
157
146
|
bindingId: binding.id,
|
|
158
147
|
agentId: binding.agentId,
|
|
@@ -163,11 +152,14 @@ export class MessageRouter {
|
|
|
163
152
|
);
|
|
164
153
|
}
|
|
165
154
|
|
|
166
|
-
let threadId = ctx.binding.
|
|
155
|
+
let threadId: string | undefined = ctx.binding.threadMode === "per_conversation"
|
|
156
|
+
? undefined // always create new thread for per_conversation
|
|
157
|
+
: ctx.binding.threadId;
|
|
158
|
+
|
|
167
159
|
if (!threadId) {
|
|
168
160
|
const threadStore = getStoreLattice("default", "thread").store;
|
|
169
161
|
const newThreadId = randomUUID();
|
|
170
|
-
|
|
162
|
+
console.log({
|
|
171
163
|
event: "dispatch:thread:create",
|
|
172
164
|
agentId: ctx.binding.agentId,
|
|
173
165
|
newThreadId,
|
|
@@ -183,6 +175,10 @@ export class MessageRouter {
|
|
|
183
175
|
channelInstallationId: message.channelInstallationId,
|
|
184
176
|
senderId: message.sender.id,
|
|
185
177
|
bindingId: ctx.binding.id,
|
|
178
|
+
...(message.conversation ? {
|
|
179
|
+
conversationId: message.conversation.id,
|
|
180
|
+
conversationType: message.conversation.type,
|
|
181
|
+
} : {}),
|
|
186
182
|
},
|
|
187
183
|
},
|
|
188
184
|
);
|
|
@@ -195,7 +191,7 @@ export class MessageRouter {
|
|
|
195
191
|
}
|
|
196
192
|
}
|
|
197
193
|
|
|
198
|
-
|
|
194
|
+
console.log({
|
|
199
195
|
event: "dispatch:agent",
|
|
200
196
|
agentId: ctx.binding.agentId,
|
|
201
197
|
threadId,
|
|
@@ -217,7 +213,7 @@ export class MessageRouter {
|
|
|
217
213
|
custom_run_config: message.content.metadata || {},
|
|
218
214
|
});
|
|
219
215
|
|
|
220
|
-
|
|
216
|
+
console.log({
|
|
221
217
|
event: "dispatch:complete",
|
|
222
218
|
agentId: ctx.binding.agentId,
|
|
223
219
|
threadId,
|
|
@@ -250,7 +246,7 @@ export class MessageRouter {
|
|
|
250
246
|
};
|
|
251
247
|
} catch (error) {
|
|
252
248
|
ctx.error = error instanceof Error ? error : new Error(String(error));
|
|
253
|
-
|
|
249
|
+
console.error({ event: "dispatch:error", error: ctx.error.message, channel: message.channel, senderId: message.sender.id }, "Message dispatch failed");
|
|
254
250
|
return {
|
|
255
251
|
success: false,
|
|
256
252
|
bindingId: ctx.binding?.id,
|
|
@@ -4,7 +4,6 @@ const processedMessages = new Map<string, number>();
|
|
|
4
4
|
|
|
5
5
|
export function createDeduplicationMiddleware(
|
|
6
6
|
ttlMs: number = 5 * 60 * 1000,
|
|
7
|
-
logger?: any,
|
|
8
7
|
): MessageMiddleware {
|
|
9
8
|
return async (ctx, next) => {
|
|
10
9
|
const msg = ctx.inboundMessage;
|
|
@@ -17,7 +16,7 @@ export function createDeduplicationMiddleware(
|
|
|
17
16
|
const now = Date.now();
|
|
18
17
|
const lastProcessed = processedMessages.get(key);
|
|
19
18
|
if (lastProcessed && (now - lastProcessed) < ttlMs) {
|
|
20
|
-
|
|
19
|
+
console.warn({
|
|
21
20
|
event: "dedup:blocked",
|
|
22
21
|
channel: msg.channel,
|
|
23
22
|
senderId: msg.sender.id,
|
|
@@ -14,7 +14,6 @@ export function createRateLimitMiddleware(
|
|
|
14
14
|
maxRequests: number = 10,
|
|
15
15
|
windowMs: number = 60 * 1000,
|
|
16
16
|
maxEntries: number = 10000,
|
|
17
|
-
logger?: any,
|
|
18
17
|
): MessageMiddleware {
|
|
19
18
|
return async (ctx, next) => {
|
|
20
19
|
const senderKey = `${ctx.inboundMessage.channel}:${ctx.inboundMessage.sender.id}`;
|
|
@@ -33,7 +32,7 @@ export function createRateLimitMiddleware(
|
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
if (counter.count > maxRequests) {
|
|
36
|
-
|
|
35
|
+
console.warn({
|
|
37
36
|
event: "ratelimit:blocked",
|
|
38
37
|
channel: ctx.inboundMessage.channel,
|
|
39
38
|
senderId: ctx.inboundMessage.sender.id,
|
package/src/routes/index.ts
CHANGED
|
@@ -385,7 +385,9 @@ export const registerLatticeRoutes = (app: FastifyInstance, channelDeps?: { rout
|
|
|
385
385
|
},
|
|
386
386
|
content: {
|
|
387
387
|
text: (msg.content as Record<string, unknown>).text as string,
|
|
388
|
+
metadata: (msg.content as Record<string, unknown>).metadata as Record<string, unknown> | undefined,
|
|
388
389
|
},
|
|
390
|
+
conversation: msg.conversation as { id: string; type: string } | undefined,
|
|
389
391
|
replyTarget: msg.replyTarget as Record<string, unknown> | undefined,
|
|
390
392
|
} as Parameters<typeof router.dispatch>[0];
|
|
391
393
|
|