@axiom-lattice/core 2.1.43 → 2.1.45
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/dist/index.d.mts +34 -7
- package/dist/index.d.ts +34 -7
- package/dist/index.js +110 -54
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -54
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5017,7 +5017,7 @@ var InMemoryThreadStore = class {
|
|
|
5017
5017
|
/**
|
|
5018
5018
|
* Get all threads for a specific tenant and assistant
|
|
5019
5019
|
*/
|
|
5020
|
-
async getThreadsByAssistantId(tenantId, assistantId) {
|
|
5020
|
+
async getThreadsByAssistantId(tenantId, assistantId, metadataFilter) {
|
|
5021
5021
|
const tenantThreads = this.threads.get(tenantId);
|
|
5022
5022
|
if (!tenantThreads) {
|
|
5023
5023
|
return [];
|
|
@@ -5026,7 +5026,15 @@ var InMemoryThreadStore = class {
|
|
|
5026
5026
|
if (!assistantThreads) {
|
|
5027
5027
|
return [];
|
|
5028
5028
|
}
|
|
5029
|
-
|
|
5029
|
+
let threads = Array.from(assistantThreads.values());
|
|
5030
|
+
if (metadataFilter && Object.keys(metadataFilter).length > 0) {
|
|
5031
|
+
threads = threads.filter(
|
|
5032
|
+
(thread) => Object.entries(metadataFilter).every(
|
|
5033
|
+
([key, value]) => thread.metadata?.[key] === value
|
|
5034
|
+
)
|
|
5035
|
+
);
|
|
5036
|
+
}
|
|
5037
|
+
return threads;
|
|
5030
5038
|
}
|
|
5031
5039
|
/**
|
|
5032
5040
|
* Get a thread by ID for a specific tenant
|
|
@@ -6452,10 +6460,10 @@ var InMemoryThreadMessageQueueStore = class {
|
|
|
6452
6460
|
return this.messages.get(threadId);
|
|
6453
6461
|
}
|
|
6454
6462
|
async addMessage(params) {
|
|
6455
|
-
const { threadId, tenantId, assistantId, content, type = "human", priority = 0, command } = params;
|
|
6463
|
+
const { threadId, tenantId, assistantId, content, type = "human", priority = 0, command, custom_run_config, id } = params;
|
|
6456
6464
|
const threadMessages = this.getMessagesForThread(threadId);
|
|
6457
6465
|
const message = {
|
|
6458
|
-
id: this.generateId(),
|
|
6466
|
+
id: id || this.generateId(),
|
|
6459
6467
|
content,
|
|
6460
6468
|
type,
|
|
6461
6469
|
sequence: threadMessages.length,
|
|
@@ -6464,31 +6472,35 @@ var InMemoryThreadMessageQueueStore = class {
|
|
|
6464
6472
|
tenantId,
|
|
6465
6473
|
assistantId,
|
|
6466
6474
|
priority,
|
|
6467
|
-
command
|
|
6475
|
+
command,
|
|
6476
|
+
custom_run_config
|
|
6468
6477
|
};
|
|
6469
6478
|
threadMessages.push(message);
|
|
6470
6479
|
return message;
|
|
6471
6480
|
}
|
|
6472
|
-
async addMessageAtHead(
|
|
6481
|
+
async addMessageAtHead(params) {
|
|
6482
|
+
const { threadId, tenantId, assistantId, content, type = "system", id, command, custom_run_config } = params;
|
|
6473
6483
|
const threadMessages = this.getMessagesForThread(threadId);
|
|
6474
|
-
let
|
|
6475
|
-
let
|
|
6476
|
-
if (threadMessages.length > 0) {
|
|
6477
|
-
|
|
6478
|
-
|
|
6484
|
+
let resolvedTenantId = tenantId || "default";
|
|
6485
|
+
let resolvedAssistantId = assistantId || "";
|
|
6486
|
+
if (!tenantId && !assistantId && threadMessages.length > 0) {
|
|
6487
|
+
resolvedTenantId = threadMessages[0].tenantId || "default";
|
|
6488
|
+
resolvedAssistantId = threadMessages[0].assistantId || "";
|
|
6479
6489
|
}
|
|
6480
6490
|
const nextSequence = threadMessages.length;
|
|
6481
6491
|
const message = {
|
|
6482
|
-
id: this.generateId(),
|
|
6492
|
+
id: id || this.generateId(),
|
|
6483
6493
|
content,
|
|
6484
6494
|
type,
|
|
6485
6495
|
sequence: nextSequence,
|
|
6486
6496
|
createdAt: /* @__PURE__ */ new Date(),
|
|
6487
6497
|
status: "pending",
|
|
6488
|
-
tenantId,
|
|
6489
|
-
assistantId,
|
|
6490
|
-
priority: 100
|
|
6498
|
+
tenantId: resolvedTenantId,
|
|
6499
|
+
assistantId: resolvedAssistantId,
|
|
6500
|
+
priority: 100,
|
|
6491
6501
|
// High priority for head messages (STEER/Command)
|
|
6502
|
+
command,
|
|
6503
|
+
custom_run_config
|
|
6492
6504
|
};
|
|
6493
6505
|
threadMessages.push(message);
|
|
6494
6506
|
return message;
|
|
@@ -16954,29 +16966,34 @@ var Agent = class {
|
|
|
16954
16966
|
break;
|
|
16955
16967
|
}
|
|
16956
16968
|
const firstMessage = pendings[0];
|
|
16957
|
-
const
|
|
16969
|
+
const files = firstMessage.content?.queueMessage?.input?.files;
|
|
16970
|
+
const hasCommand = firstMessage.command;
|
|
16958
16971
|
if (hasCommand) {
|
|
16959
16972
|
for (const p of pendings) {
|
|
16960
16973
|
if (signal?.aborted) break;
|
|
16961
|
-
if (!p.
|
|
16974
|
+
if (!p.command) break;
|
|
16962
16975
|
await this.queueStore?.markProcessing(p.id);
|
|
16963
16976
|
const startTime = Date.now();
|
|
16964
16977
|
this.publish("message:started", {
|
|
16965
16978
|
type: "message:started",
|
|
16966
|
-
messageId: p.
|
|
16967
|
-
messageContent: p.
|
|
16979
|
+
messageId: this.getHumanPendingContent(p).id,
|
|
16980
|
+
messageContent: this.getHumanPendingContent(p).message,
|
|
16968
16981
|
timestamp: /* @__PURE__ */ new Date(),
|
|
16969
16982
|
queueMode: this.queueMode.mode
|
|
16970
16983
|
});
|
|
16984
|
+
const humanContent = p.content;
|
|
16971
16985
|
const input = {
|
|
16972
|
-
messages: [new HumanMessage2({ id:
|
|
16986
|
+
messages: [new HumanMessage2({ id: humanContent.id, content: humanContent.message })]
|
|
16973
16987
|
};
|
|
16974
|
-
|
|
16988
|
+
if (files) {
|
|
16989
|
+
input.files = files;
|
|
16990
|
+
}
|
|
16991
|
+
const queueMessageData = humanContent.queueMessage;
|
|
16975
16992
|
try {
|
|
16976
16993
|
await this.agentStreamExecutor({
|
|
16977
16994
|
input,
|
|
16978
|
-
command:
|
|
16979
|
-
custom_run_config: queueMessageData.custom_run_config
|
|
16995
|
+
command: p.command,
|
|
16996
|
+
custom_run_config: p.custom_run_config ?? queueMessageData.custom_run_config
|
|
16980
16997
|
}, signal);
|
|
16981
16998
|
await this.queueStore?.markCompleted(p.id);
|
|
16982
16999
|
const runStatus = await this.getRunStatus();
|
|
@@ -16984,7 +17001,7 @@ var Agent = class {
|
|
|
16984
17001
|
if (runStatus === "interrupted" /* INTERRUPTED */) {
|
|
16985
17002
|
this.publish("message:interrupted", {
|
|
16986
17003
|
type: "message:interrupted",
|
|
16987
|
-
messageId:
|
|
17004
|
+
messageId: humanContent.id,
|
|
16988
17005
|
timestamp: /* @__PURE__ */ new Date(),
|
|
16989
17006
|
duration: Date.now() - startTime,
|
|
16990
17007
|
state
|
|
@@ -16993,13 +17010,13 @@ var Agent = class {
|
|
|
16993
17010
|
this.addChunk({
|
|
16994
17011
|
type: "message_completed",
|
|
16995
17012
|
data: {
|
|
16996
|
-
id:
|
|
17013
|
+
id: humanContent.id,
|
|
16997
17014
|
content: ""
|
|
16998
17015
|
}
|
|
16999
17016
|
});
|
|
17000
17017
|
this.publish("message:completed", {
|
|
17001
17018
|
type: "message:completed",
|
|
17002
|
-
messageId:
|
|
17019
|
+
messageId: humanContent.id,
|
|
17003
17020
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17004
17021
|
duration: Date.now() - startTime,
|
|
17005
17022
|
state
|
|
@@ -17010,13 +17027,13 @@ var Agent = class {
|
|
|
17010
17027
|
this.addChunk({
|
|
17011
17028
|
type: "message_failed",
|
|
17012
17029
|
data: {
|
|
17013
|
-
id:
|
|
17030
|
+
id: humanContent.id,
|
|
17014
17031
|
content: error instanceof Error ? error.message : String(error)
|
|
17015
17032
|
}
|
|
17016
17033
|
});
|
|
17017
17034
|
this.publish("message:failed", {
|
|
17018
17035
|
type: "message:failed",
|
|
17019
|
-
messageId:
|
|
17036
|
+
messageId: humanContent.id,
|
|
17020
17037
|
error: error instanceof Error ? error.message : String(error),
|
|
17021
17038
|
timestamp: /* @__PURE__ */ new Date()
|
|
17022
17039
|
});
|
|
@@ -17031,20 +17048,27 @@ var Agent = class {
|
|
|
17031
17048
|
const startTime = Date.now();
|
|
17032
17049
|
remainingPendings.forEach((p) => {
|
|
17033
17050
|
this.queueStore?.markProcessing(p.id);
|
|
17034
|
-
|
|
17051
|
+
const humanContent = p.content;
|
|
17052
|
+
userMessages.push(new HumanMessage2({ id: humanContent.id, content: humanContent.message }));
|
|
17035
17053
|
this.publish("message:started", {
|
|
17036
17054
|
type: "message:started",
|
|
17037
|
-
messageId:
|
|
17038
|
-
messageContent:
|
|
17055
|
+
messageId: humanContent.id,
|
|
17056
|
+
messageContent: humanContent.message,
|
|
17039
17057
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17040
17058
|
queueMode: "collect" /* COLLECT */
|
|
17041
17059
|
});
|
|
17042
17060
|
});
|
|
17043
|
-
const firstQueueMessage = remainingPendings[0]
|
|
17061
|
+
const firstQueueMessage = remainingPendings[0] ? this.getHumanPendingContent(remainingPendings[0]).queueMessage : void 0;
|
|
17062
|
+
const input = {
|
|
17063
|
+
messages: userMessages
|
|
17064
|
+
};
|
|
17065
|
+
if (files) {
|
|
17066
|
+
input.files = files;
|
|
17067
|
+
}
|
|
17044
17068
|
try {
|
|
17045
17069
|
await this.agentStreamExecutor({
|
|
17046
|
-
input
|
|
17047
|
-
custom_run_config: firstQueueMessage
|
|
17070
|
+
input,
|
|
17071
|
+
custom_run_config: remainingPendings[0]?.custom_run_config ?? firstQueueMessage?.custom_run_config
|
|
17048
17072
|
}, signal);
|
|
17049
17073
|
const runStatus = await this.getRunStatus();
|
|
17050
17074
|
const state = await this.getCurrentState();
|
|
@@ -17098,20 +17122,27 @@ var Agent = class {
|
|
|
17098
17122
|
for (const p of remainingPendings) {
|
|
17099
17123
|
if (signal?.aborted) break;
|
|
17100
17124
|
await this.queueStore?.markProcessing(p.id);
|
|
17101
|
-
const
|
|
17125
|
+
const humanContent = p.content;
|
|
17126
|
+
const message = new HumanMessage2({ id: humanContent.id, content: humanContent.message });
|
|
17102
17127
|
const startTime = Date.now();
|
|
17103
17128
|
this.publish("message:started", {
|
|
17104
17129
|
type: "message:started",
|
|
17105
|
-
messageId:
|
|
17106
|
-
messageContent:
|
|
17130
|
+
messageId: humanContent.id,
|
|
17131
|
+
messageContent: humanContent.message,
|
|
17107
17132
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17108
17133
|
queueMode: "followup" /* FOLLOWUP */
|
|
17109
17134
|
});
|
|
17110
|
-
const queueMessageData =
|
|
17135
|
+
const queueMessageData = humanContent.queueMessage || {};
|
|
17136
|
+
const input = {
|
|
17137
|
+
messages: [message]
|
|
17138
|
+
};
|
|
17139
|
+
if (files) {
|
|
17140
|
+
input.files = files;
|
|
17141
|
+
}
|
|
17111
17142
|
try {
|
|
17112
17143
|
await this.agentStreamExecutor({
|
|
17113
|
-
input
|
|
17114
|
-
custom_run_config: queueMessageData.custom_run_config
|
|
17144
|
+
input,
|
|
17145
|
+
custom_run_config: p.custom_run_config ?? queueMessageData.custom_run_config
|
|
17115
17146
|
}, signal);
|
|
17116
17147
|
await this.queueStore?.markCompleted(p.id);
|
|
17117
17148
|
const runStatus = await this.getRunStatus();
|
|
@@ -17119,7 +17150,7 @@ var Agent = class {
|
|
|
17119
17150
|
if (runStatus === "interrupted" /* INTERRUPTED */) {
|
|
17120
17151
|
this.publish("message:interrupted", {
|
|
17121
17152
|
type: "message:interrupted",
|
|
17122
|
-
messageId:
|
|
17153
|
+
messageId: humanContent.id,
|
|
17123
17154
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17124
17155
|
duration: Date.now() - startTime,
|
|
17125
17156
|
state
|
|
@@ -17128,13 +17159,13 @@ var Agent = class {
|
|
|
17128
17159
|
this.addChunk({
|
|
17129
17160
|
type: "message_completed",
|
|
17130
17161
|
data: {
|
|
17131
|
-
id:
|
|
17162
|
+
id: humanContent.id,
|
|
17132
17163
|
content: ""
|
|
17133
17164
|
}
|
|
17134
17165
|
});
|
|
17135
17166
|
this.publish("message:completed", {
|
|
17136
17167
|
type: "message:completed",
|
|
17137
|
-
messageId:
|
|
17168
|
+
messageId: humanContent.id,
|
|
17138
17169
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17139
17170
|
duration: Date.now() - startTime,
|
|
17140
17171
|
state
|
|
@@ -17145,13 +17176,13 @@ var Agent = class {
|
|
|
17145
17176
|
this.addChunk({
|
|
17146
17177
|
type: "message_failed",
|
|
17147
17178
|
data: {
|
|
17148
|
-
id:
|
|
17179
|
+
id: humanContent.id,
|
|
17149
17180
|
content: error instanceof Error ? error.message : String(error)
|
|
17150
17181
|
}
|
|
17151
17182
|
});
|
|
17152
17183
|
this.publish("message:failed", {
|
|
17153
17184
|
type: "message:failed",
|
|
17154
|
-
messageId:
|
|
17185
|
+
messageId: humanContent.id,
|
|
17155
17186
|
error: error instanceof Error ? error.message : String(error),
|
|
17156
17187
|
timestamp: /* @__PURE__ */ new Date()
|
|
17157
17188
|
});
|
|
@@ -17169,6 +17200,12 @@ var Agent = class {
|
|
|
17169
17200
|
this.project_id = project_id;
|
|
17170
17201
|
this.custom_run_config = custom_run_config;
|
|
17171
17202
|
}
|
|
17203
|
+
getHumanPendingContent(message) {
|
|
17204
|
+
if (typeof message.content === "string" || !message.content || !("id" in message.content) || !("message" in message.content)) {
|
|
17205
|
+
throw new Error(`Expected human pending message content for message ${message.id}`);
|
|
17206
|
+
}
|
|
17207
|
+
return message.content;
|
|
17208
|
+
}
|
|
17172
17209
|
/**
|
|
17173
17210
|
* Initialize with message queue store
|
|
17174
17211
|
*/
|
|
@@ -17283,7 +17320,7 @@ var Agent = class {
|
|
|
17283
17320
|
*/
|
|
17284
17321
|
async addMessage(queueMessage, mode) {
|
|
17285
17322
|
const useMode = mode ?? this.queueMode.mode;
|
|
17286
|
-
const messageId = v4();
|
|
17323
|
+
const messageId = queueMessage.input.id || v4();
|
|
17287
17324
|
const isHighPriority = useMode === "steer" /* STEER */ || !!queueMessage.command;
|
|
17288
17325
|
const store = this.getQueueStore();
|
|
17289
17326
|
const currentSize = await store.getQueueSize(this.thread_id);
|
|
@@ -17302,14 +17339,31 @@ var Agent = class {
|
|
|
17302
17339
|
}
|
|
17303
17340
|
};
|
|
17304
17341
|
if (isHighPriority) {
|
|
17305
|
-
await store.addMessageAtHead(
|
|
17342
|
+
await store.addMessageAtHead({
|
|
17343
|
+
threadId: this.thread_id,
|
|
17344
|
+
tenantId: this.tenant_id,
|
|
17345
|
+
assistantId: this.assistant_id,
|
|
17346
|
+
content,
|
|
17347
|
+
type: "human",
|
|
17348
|
+
command: queueMessage.command,
|
|
17349
|
+
custom_run_config: queueMessage.custom_run_config,
|
|
17350
|
+
id: messageId
|
|
17351
|
+
});
|
|
17352
|
+
if (useMode === "steer" /* STEER */) {
|
|
17353
|
+
this.stopQueueProcessor();
|
|
17354
|
+
await store.resetProcessingToPending(this.thread_id);
|
|
17355
|
+
console.log(`[Agent] STEER mode: stopped current processing, reset queue, message ${messageId} will execute next`);
|
|
17356
|
+
}
|
|
17306
17357
|
} else {
|
|
17307
17358
|
await store.addMessage({
|
|
17308
17359
|
threadId: this.thread_id,
|
|
17309
17360
|
tenantId: this.tenant_id,
|
|
17310
17361
|
assistantId: this.assistant_id,
|
|
17311
17362
|
content,
|
|
17312
|
-
type: "human"
|
|
17363
|
+
type: "human",
|
|
17364
|
+
command: queueMessage.command,
|
|
17365
|
+
custom_run_config: queueMessage.custom_run_config,
|
|
17366
|
+
id: messageId
|
|
17313
17367
|
});
|
|
17314
17368
|
}
|
|
17315
17369
|
this.startQueueProcessorIfNeeded().catch((err) => {
|
|
@@ -17342,7 +17396,7 @@ var Agent = class {
|
|
|
17342
17396
|
this.publish("thread:busy", {
|
|
17343
17397
|
type: "thread:busy",
|
|
17344
17398
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17345
|
-
messageId: firstMessage
|
|
17399
|
+
messageId: firstMessage ? this.getHumanPendingContent(firstMessage).id : void 0
|
|
17346
17400
|
});
|
|
17347
17401
|
this.waitingForQueueEnd(this.abortController.signal).catch((error) => {
|
|
17348
17402
|
console.error(`Queue processing error for thread ${this.thread_id}:`, error);
|
|
@@ -17368,11 +17422,13 @@ var Agent = class {
|
|
|
17368
17422
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
17369
17423
|
}
|
|
17370
17424
|
};
|
|
17371
|
-
await this.queueStore.addMessageAtHead(
|
|
17372
|
-
thread.threadId,
|
|
17373
|
-
|
|
17374
|
-
|
|
17375
|
-
|
|
17425
|
+
await this.queueStore.addMessageAtHead({
|
|
17426
|
+
threadId: thread.threadId,
|
|
17427
|
+
tenantId: thread.tenantId,
|
|
17428
|
+
assistantId: thread.assistantId,
|
|
17429
|
+
content: reminderContent,
|
|
17430
|
+
type: "system"
|
|
17431
|
+
});
|
|
17376
17432
|
}
|
|
17377
17433
|
async getCurrentState() {
|
|
17378
17434
|
const { runnable_agent } = await this.getLatticeClientAndRuntimeConfig();
|