@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.d.mts
CHANGED
|
@@ -2253,21 +2253,46 @@ interface ThreadQueueConfig {
|
|
|
2253
2253
|
}
|
|
2254
2254
|
interface PendingMessage {
|
|
2255
2255
|
id: string;
|
|
2256
|
-
content:
|
|
2256
|
+
content: PendingMessageContent;
|
|
2257
2257
|
type: "human" | "system";
|
|
2258
2258
|
sequence: number;
|
|
2259
2259
|
createdAt: Date;
|
|
2260
2260
|
priority?: number;
|
|
2261
|
-
command?:
|
|
2261
|
+
command?: CommandParams<unknown>;
|
|
2262
|
+
custom_run_config?: unknown;
|
|
2262
2263
|
}
|
|
2264
|
+
interface PendingQueueMessageInput {
|
|
2265
|
+
message: string;
|
|
2266
|
+
id?: string;
|
|
2267
|
+
messages?: unknown[];
|
|
2268
|
+
[key: string]: unknown;
|
|
2269
|
+
}
|
|
2270
|
+
interface PendingQueueMessage {
|
|
2271
|
+
input: PendingQueueMessageInput;
|
|
2272
|
+
command?: CommandParams<unknown>;
|
|
2273
|
+
custom_run_config?: unknown;
|
|
2274
|
+
}
|
|
2275
|
+
interface HumanPendingMessageContent {
|
|
2276
|
+
id: string;
|
|
2277
|
+
message: string;
|
|
2278
|
+
queueMessage: PendingQueueMessage;
|
|
2279
|
+
}
|
|
2280
|
+
interface SystemPendingMessageContent {
|
|
2281
|
+
role: "system";
|
|
2282
|
+
content: string;
|
|
2283
|
+
metadata?: Record<string, unknown>;
|
|
2284
|
+
}
|
|
2285
|
+
type PendingMessageContent = HumanPendingMessageContent | SystemPendingMessageContent | string;
|
|
2263
2286
|
interface AddMessageParams {
|
|
2264
2287
|
threadId: string;
|
|
2265
2288
|
tenantId: string;
|
|
2266
2289
|
assistantId: string;
|
|
2267
|
-
content:
|
|
2290
|
+
content: PendingMessageContent;
|
|
2268
2291
|
type?: "human" | "system";
|
|
2269
2292
|
priority?: number;
|
|
2270
|
-
command?:
|
|
2293
|
+
command?: CommandParams<unknown>;
|
|
2294
|
+
custom_run_config?: unknown;
|
|
2295
|
+
id?: string;
|
|
2271
2296
|
}
|
|
2272
2297
|
interface ThreadInfo {
|
|
2273
2298
|
tenantId: string;
|
|
@@ -2280,7 +2305,7 @@ interface ThreadInfo {
|
|
|
2280
2305
|
*/
|
|
2281
2306
|
interface IMessageQueueStore {
|
|
2282
2307
|
addMessage(params: AddMessageParams): Promise<PendingMessage>;
|
|
2283
|
-
addMessageAtHead(
|
|
2308
|
+
addMessageAtHead(params: AddMessageParams): Promise<PendingMessage>;
|
|
2284
2309
|
getPendingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
2285
2310
|
getProcessingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
2286
2311
|
getQueueSize(threadId: string): Promise<number>;
|
|
@@ -2441,7 +2466,7 @@ declare class InMemoryThreadStore implements ThreadStore {
|
|
|
2441
2466
|
/**
|
|
2442
2467
|
* Get all threads for a specific tenant and assistant
|
|
2443
2468
|
*/
|
|
2444
|
-
getThreadsByAssistantId(tenantId: string, assistantId: string): Promise<Thread[]>;
|
|
2469
|
+
getThreadsByAssistantId(tenantId: string, assistantId: string, metadataFilter?: Record<string, string>): Promise<Thread[]>;
|
|
2445
2470
|
/**
|
|
2446
2471
|
* Get a thread by ID for a specific tenant
|
|
2447
2472
|
*/
|
|
@@ -2848,7 +2873,7 @@ declare class InMemoryThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
2848
2873
|
private generateId;
|
|
2849
2874
|
private getMessagesForThread;
|
|
2850
2875
|
addMessage(params: AddMessageParams): Promise<PendingMessage>;
|
|
2851
|
-
addMessageAtHead(
|
|
2876
|
+
addMessageAtHead(params: AddMessageParams): Promise<PendingMessage>;
|
|
2852
2877
|
getPendingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
2853
2878
|
getProcessingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
2854
2879
|
getQueueSize(threadId: string): Promise<number>;
|
|
@@ -4928,6 +4953,7 @@ interface ThreadState {
|
|
|
4928
4953
|
interface QueueMessage {
|
|
4929
4954
|
input: {
|
|
4930
4955
|
message: string;
|
|
4956
|
+
id?: string;
|
|
4931
4957
|
};
|
|
4932
4958
|
command?: CommandParams<any>;
|
|
4933
4959
|
custom_run_config?: any;
|
|
@@ -5009,6 +5035,7 @@ declare class Agent {
|
|
|
5009
5035
|
queueMode: ThreadQueueConfig;
|
|
5010
5036
|
private isWaitingForQueueEnd;
|
|
5011
5037
|
constructor({ assistant_id, thread_id, tenant_id, workspace_id, project_id, custom_run_config, }: AgentThreadInterface);
|
|
5038
|
+
private getHumanPendingContent;
|
|
5012
5039
|
/**
|
|
5013
5040
|
* Initialize with message queue store
|
|
5014
5041
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -2253,21 +2253,46 @@ interface ThreadQueueConfig {
|
|
|
2253
2253
|
}
|
|
2254
2254
|
interface PendingMessage {
|
|
2255
2255
|
id: string;
|
|
2256
|
-
content:
|
|
2256
|
+
content: PendingMessageContent;
|
|
2257
2257
|
type: "human" | "system";
|
|
2258
2258
|
sequence: number;
|
|
2259
2259
|
createdAt: Date;
|
|
2260
2260
|
priority?: number;
|
|
2261
|
-
command?:
|
|
2261
|
+
command?: CommandParams<unknown>;
|
|
2262
|
+
custom_run_config?: unknown;
|
|
2262
2263
|
}
|
|
2264
|
+
interface PendingQueueMessageInput {
|
|
2265
|
+
message: string;
|
|
2266
|
+
id?: string;
|
|
2267
|
+
messages?: unknown[];
|
|
2268
|
+
[key: string]: unknown;
|
|
2269
|
+
}
|
|
2270
|
+
interface PendingQueueMessage {
|
|
2271
|
+
input: PendingQueueMessageInput;
|
|
2272
|
+
command?: CommandParams<unknown>;
|
|
2273
|
+
custom_run_config?: unknown;
|
|
2274
|
+
}
|
|
2275
|
+
interface HumanPendingMessageContent {
|
|
2276
|
+
id: string;
|
|
2277
|
+
message: string;
|
|
2278
|
+
queueMessage: PendingQueueMessage;
|
|
2279
|
+
}
|
|
2280
|
+
interface SystemPendingMessageContent {
|
|
2281
|
+
role: "system";
|
|
2282
|
+
content: string;
|
|
2283
|
+
metadata?: Record<string, unknown>;
|
|
2284
|
+
}
|
|
2285
|
+
type PendingMessageContent = HumanPendingMessageContent | SystemPendingMessageContent | string;
|
|
2263
2286
|
interface AddMessageParams {
|
|
2264
2287
|
threadId: string;
|
|
2265
2288
|
tenantId: string;
|
|
2266
2289
|
assistantId: string;
|
|
2267
|
-
content:
|
|
2290
|
+
content: PendingMessageContent;
|
|
2268
2291
|
type?: "human" | "system";
|
|
2269
2292
|
priority?: number;
|
|
2270
|
-
command?:
|
|
2293
|
+
command?: CommandParams<unknown>;
|
|
2294
|
+
custom_run_config?: unknown;
|
|
2295
|
+
id?: string;
|
|
2271
2296
|
}
|
|
2272
2297
|
interface ThreadInfo {
|
|
2273
2298
|
tenantId: string;
|
|
@@ -2280,7 +2305,7 @@ interface ThreadInfo {
|
|
|
2280
2305
|
*/
|
|
2281
2306
|
interface IMessageQueueStore {
|
|
2282
2307
|
addMessage(params: AddMessageParams): Promise<PendingMessage>;
|
|
2283
|
-
addMessageAtHead(
|
|
2308
|
+
addMessageAtHead(params: AddMessageParams): Promise<PendingMessage>;
|
|
2284
2309
|
getPendingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
2285
2310
|
getProcessingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
2286
2311
|
getQueueSize(threadId: string): Promise<number>;
|
|
@@ -2441,7 +2466,7 @@ declare class InMemoryThreadStore implements ThreadStore {
|
|
|
2441
2466
|
/**
|
|
2442
2467
|
* Get all threads for a specific tenant and assistant
|
|
2443
2468
|
*/
|
|
2444
|
-
getThreadsByAssistantId(tenantId: string, assistantId: string): Promise<Thread[]>;
|
|
2469
|
+
getThreadsByAssistantId(tenantId: string, assistantId: string, metadataFilter?: Record<string, string>): Promise<Thread[]>;
|
|
2445
2470
|
/**
|
|
2446
2471
|
* Get a thread by ID for a specific tenant
|
|
2447
2472
|
*/
|
|
@@ -2848,7 +2873,7 @@ declare class InMemoryThreadMessageQueueStore implements IMessageQueueStore {
|
|
|
2848
2873
|
private generateId;
|
|
2849
2874
|
private getMessagesForThread;
|
|
2850
2875
|
addMessage(params: AddMessageParams): Promise<PendingMessage>;
|
|
2851
|
-
addMessageAtHead(
|
|
2876
|
+
addMessageAtHead(params: AddMessageParams): Promise<PendingMessage>;
|
|
2852
2877
|
getPendingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
2853
2878
|
getProcessingMessages(threadId: string): Promise<PendingMessage[]>;
|
|
2854
2879
|
getQueueSize(threadId: string): Promise<number>;
|
|
@@ -4928,6 +4953,7 @@ interface ThreadState {
|
|
|
4928
4953
|
interface QueueMessage {
|
|
4929
4954
|
input: {
|
|
4930
4955
|
message: string;
|
|
4956
|
+
id?: string;
|
|
4931
4957
|
};
|
|
4932
4958
|
command?: CommandParams<any>;
|
|
4933
4959
|
custom_run_config?: any;
|
|
@@ -5009,6 +5035,7 @@ declare class Agent {
|
|
|
5009
5035
|
queueMode: ThreadQueueConfig;
|
|
5010
5036
|
private isWaitingForQueueEnd;
|
|
5011
5037
|
constructor({ assistant_id, thread_id, tenant_id, workspace_id, project_id, custom_run_config, }: AgentThreadInterface);
|
|
5038
|
+
private getHumanPendingContent;
|
|
5012
5039
|
/**
|
|
5013
5040
|
* Initialize with message queue store
|
|
5014
5041
|
*/
|
package/dist/index.js
CHANGED
|
@@ -5200,7 +5200,7 @@ var InMemoryThreadStore = class {
|
|
|
5200
5200
|
/**
|
|
5201
5201
|
* Get all threads for a specific tenant and assistant
|
|
5202
5202
|
*/
|
|
5203
|
-
async getThreadsByAssistantId(tenantId, assistantId) {
|
|
5203
|
+
async getThreadsByAssistantId(tenantId, assistantId, metadataFilter) {
|
|
5204
5204
|
const tenantThreads = this.threads.get(tenantId);
|
|
5205
5205
|
if (!tenantThreads) {
|
|
5206
5206
|
return [];
|
|
@@ -5209,7 +5209,15 @@ var InMemoryThreadStore = class {
|
|
|
5209
5209
|
if (!assistantThreads) {
|
|
5210
5210
|
return [];
|
|
5211
5211
|
}
|
|
5212
|
-
|
|
5212
|
+
let threads = Array.from(assistantThreads.values());
|
|
5213
|
+
if (metadataFilter && Object.keys(metadataFilter).length > 0) {
|
|
5214
|
+
threads = threads.filter(
|
|
5215
|
+
(thread) => Object.entries(metadataFilter).every(
|
|
5216
|
+
([key, value]) => thread.metadata?.[key] === value
|
|
5217
|
+
)
|
|
5218
|
+
);
|
|
5219
|
+
}
|
|
5220
|
+
return threads;
|
|
5213
5221
|
}
|
|
5214
5222
|
/**
|
|
5215
5223
|
* Get a thread by ID for a specific tenant
|
|
@@ -6635,10 +6643,10 @@ var InMemoryThreadMessageQueueStore = class {
|
|
|
6635
6643
|
return this.messages.get(threadId);
|
|
6636
6644
|
}
|
|
6637
6645
|
async addMessage(params) {
|
|
6638
|
-
const { threadId, tenantId, assistantId, content, type = "human", priority = 0, command } = params;
|
|
6646
|
+
const { threadId, tenantId, assistantId, content, type = "human", priority = 0, command, custom_run_config, id } = params;
|
|
6639
6647
|
const threadMessages = this.getMessagesForThread(threadId);
|
|
6640
6648
|
const message = {
|
|
6641
|
-
id: this.generateId(),
|
|
6649
|
+
id: id || this.generateId(),
|
|
6642
6650
|
content,
|
|
6643
6651
|
type,
|
|
6644
6652
|
sequence: threadMessages.length,
|
|
@@ -6647,31 +6655,35 @@ var InMemoryThreadMessageQueueStore = class {
|
|
|
6647
6655
|
tenantId,
|
|
6648
6656
|
assistantId,
|
|
6649
6657
|
priority,
|
|
6650
|
-
command
|
|
6658
|
+
command,
|
|
6659
|
+
custom_run_config
|
|
6651
6660
|
};
|
|
6652
6661
|
threadMessages.push(message);
|
|
6653
6662
|
return message;
|
|
6654
6663
|
}
|
|
6655
|
-
async addMessageAtHead(
|
|
6664
|
+
async addMessageAtHead(params) {
|
|
6665
|
+
const { threadId, tenantId, assistantId, content, type = "system", id, command, custom_run_config } = params;
|
|
6656
6666
|
const threadMessages = this.getMessagesForThread(threadId);
|
|
6657
|
-
let
|
|
6658
|
-
let
|
|
6659
|
-
if (threadMessages.length > 0) {
|
|
6660
|
-
|
|
6661
|
-
|
|
6667
|
+
let resolvedTenantId = tenantId || "default";
|
|
6668
|
+
let resolvedAssistantId = assistantId || "";
|
|
6669
|
+
if (!tenantId && !assistantId && threadMessages.length > 0) {
|
|
6670
|
+
resolvedTenantId = threadMessages[0].tenantId || "default";
|
|
6671
|
+
resolvedAssistantId = threadMessages[0].assistantId || "";
|
|
6662
6672
|
}
|
|
6663
6673
|
const nextSequence = threadMessages.length;
|
|
6664
6674
|
const message = {
|
|
6665
|
-
id: this.generateId(),
|
|
6675
|
+
id: id || this.generateId(),
|
|
6666
6676
|
content,
|
|
6667
6677
|
type,
|
|
6668
6678
|
sequence: nextSequence,
|
|
6669
6679
|
createdAt: /* @__PURE__ */ new Date(),
|
|
6670
6680
|
status: "pending",
|
|
6671
|
-
tenantId,
|
|
6672
|
-
assistantId,
|
|
6673
|
-
priority: 100
|
|
6681
|
+
tenantId: resolvedTenantId,
|
|
6682
|
+
assistantId: resolvedAssistantId,
|
|
6683
|
+
priority: 100,
|
|
6674
6684
|
// High priority for head messages (STEER/Command)
|
|
6685
|
+
command,
|
|
6686
|
+
custom_run_config
|
|
6675
6687
|
};
|
|
6676
6688
|
threadMessages.push(message);
|
|
6677
6689
|
return message;
|
|
@@ -17098,29 +17110,34 @@ var Agent = class {
|
|
|
17098
17110
|
break;
|
|
17099
17111
|
}
|
|
17100
17112
|
const firstMessage = pendings[0];
|
|
17101
|
-
const
|
|
17113
|
+
const files = firstMessage.content?.queueMessage?.input?.files;
|
|
17114
|
+
const hasCommand = firstMessage.command;
|
|
17102
17115
|
if (hasCommand) {
|
|
17103
17116
|
for (const p of pendings) {
|
|
17104
17117
|
if (signal?.aborted) break;
|
|
17105
|
-
if (!p.
|
|
17118
|
+
if (!p.command) break;
|
|
17106
17119
|
await this.queueStore?.markProcessing(p.id);
|
|
17107
17120
|
const startTime = Date.now();
|
|
17108
17121
|
this.publish("message:started", {
|
|
17109
17122
|
type: "message:started",
|
|
17110
|
-
messageId: p.
|
|
17111
|
-
messageContent: p.
|
|
17123
|
+
messageId: this.getHumanPendingContent(p).id,
|
|
17124
|
+
messageContent: this.getHumanPendingContent(p).message,
|
|
17112
17125
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17113
17126
|
queueMode: this.queueMode.mode
|
|
17114
17127
|
});
|
|
17128
|
+
const humanContent = p.content;
|
|
17115
17129
|
const input = {
|
|
17116
|
-
messages: [new import_langchain61.HumanMessage({ id:
|
|
17130
|
+
messages: [new import_langchain61.HumanMessage({ id: humanContent.id, content: humanContent.message })]
|
|
17117
17131
|
};
|
|
17118
|
-
|
|
17132
|
+
if (files) {
|
|
17133
|
+
input.files = files;
|
|
17134
|
+
}
|
|
17135
|
+
const queueMessageData = humanContent.queueMessage;
|
|
17119
17136
|
try {
|
|
17120
17137
|
await this.agentStreamExecutor({
|
|
17121
17138
|
input,
|
|
17122
|
-
command:
|
|
17123
|
-
custom_run_config: queueMessageData.custom_run_config
|
|
17139
|
+
command: p.command,
|
|
17140
|
+
custom_run_config: p.custom_run_config ?? queueMessageData.custom_run_config
|
|
17124
17141
|
}, signal);
|
|
17125
17142
|
await this.queueStore?.markCompleted(p.id);
|
|
17126
17143
|
const runStatus = await this.getRunStatus();
|
|
@@ -17128,7 +17145,7 @@ var Agent = class {
|
|
|
17128
17145
|
if (runStatus === "interrupted" /* INTERRUPTED */) {
|
|
17129
17146
|
this.publish("message:interrupted", {
|
|
17130
17147
|
type: "message:interrupted",
|
|
17131
|
-
messageId:
|
|
17148
|
+
messageId: humanContent.id,
|
|
17132
17149
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17133
17150
|
duration: Date.now() - startTime,
|
|
17134
17151
|
state
|
|
@@ -17137,13 +17154,13 @@ var Agent = class {
|
|
|
17137
17154
|
this.addChunk({
|
|
17138
17155
|
type: "message_completed",
|
|
17139
17156
|
data: {
|
|
17140
|
-
id:
|
|
17157
|
+
id: humanContent.id,
|
|
17141
17158
|
content: ""
|
|
17142
17159
|
}
|
|
17143
17160
|
});
|
|
17144
17161
|
this.publish("message:completed", {
|
|
17145
17162
|
type: "message:completed",
|
|
17146
|
-
messageId:
|
|
17163
|
+
messageId: humanContent.id,
|
|
17147
17164
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17148
17165
|
duration: Date.now() - startTime,
|
|
17149
17166
|
state
|
|
@@ -17154,13 +17171,13 @@ var Agent = class {
|
|
|
17154
17171
|
this.addChunk({
|
|
17155
17172
|
type: "message_failed",
|
|
17156
17173
|
data: {
|
|
17157
|
-
id:
|
|
17174
|
+
id: humanContent.id,
|
|
17158
17175
|
content: error instanceof Error ? error.message : String(error)
|
|
17159
17176
|
}
|
|
17160
17177
|
});
|
|
17161
17178
|
this.publish("message:failed", {
|
|
17162
17179
|
type: "message:failed",
|
|
17163
|
-
messageId:
|
|
17180
|
+
messageId: humanContent.id,
|
|
17164
17181
|
error: error instanceof Error ? error.message : String(error),
|
|
17165
17182
|
timestamp: /* @__PURE__ */ new Date()
|
|
17166
17183
|
});
|
|
@@ -17175,20 +17192,27 @@ var Agent = class {
|
|
|
17175
17192
|
const startTime = Date.now();
|
|
17176
17193
|
remainingPendings.forEach((p) => {
|
|
17177
17194
|
this.queueStore?.markProcessing(p.id);
|
|
17178
|
-
|
|
17195
|
+
const humanContent = p.content;
|
|
17196
|
+
userMessages.push(new import_langchain61.HumanMessage({ id: humanContent.id, content: humanContent.message }));
|
|
17179
17197
|
this.publish("message:started", {
|
|
17180
17198
|
type: "message:started",
|
|
17181
|
-
messageId:
|
|
17182
|
-
messageContent:
|
|
17199
|
+
messageId: humanContent.id,
|
|
17200
|
+
messageContent: humanContent.message,
|
|
17183
17201
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17184
17202
|
queueMode: "collect" /* COLLECT */
|
|
17185
17203
|
});
|
|
17186
17204
|
});
|
|
17187
|
-
const firstQueueMessage = remainingPendings[0]
|
|
17205
|
+
const firstQueueMessage = remainingPendings[0] ? this.getHumanPendingContent(remainingPendings[0]).queueMessage : void 0;
|
|
17206
|
+
const input = {
|
|
17207
|
+
messages: userMessages
|
|
17208
|
+
};
|
|
17209
|
+
if (files) {
|
|
17210
|
+
input.files = files;
|
|
17211
|
+
}
|
|
17188
17212
|
try {
|
|
17189
17213
|
await this.agentStreamExecutor({
|
|
17190
|
-
input
|
|
17191
|
-
custom_run_config: firstQueueMessage
|
|
17214
|
+
input,
|
|
17215
|
+
custom_run_config: remainingPendings[0]?.custom_run_config ?? firstQueueMessage?.custom_run_config
|
|
17192
17216
|
}, signal);
|
|
17193
17217
|
const runStatus = await this.getRunStatus();
|
|
17194
17218
|
const state = await this.getCurrentState();
|
|
@@ -17242,20 +17266,27 @@ var Agent = class {
|
|
|
17242
17266
|
for (const p of remainingPendings) {
|
|
17243
17267
|
if (signal?.aborted) break;
|
|
17244
17268
|
await this.queueStore?.markProcessing(p.id);
|
|
17245
|
-
const
|
|
17269
|
+
const humanContent = p.content;
|
|
17270
|
+
const message = new import_langchain61.HumanMessage({ id: humanContent.id, content: humanContent.message });
|
|
17246
17271
|
const startTime = Date.now();
|
|
17247
17272
|
this.publish("message:started", {
|
|
17248
17273
|
type: "message:started",
|
|
17249
|
-
messageId:
|
|
17250
|
-
messageContent:
|
|
17274
|
+
messageId: humanContent.id,
|
|
17275
|
+
messageContent: humanContent.message,
|
|
17251
17276
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17252
17277
|
queueMode: "followup" /* FOLLOWUP */
|
|
17253
17278
|
});
|
|
17254
|
-
const queueMessageData =
|
|
17279
|
+
const queueMessageData = humanContent.queueMessage || {};
|
|
17280
|
+
const input = {
|
|
17281
|
+
messages: [message]
|
|
17282
|
+
};
|
|
17283
|
+
if (files) {
|
|
17284
|
+
input.files = files;
|
|
17285
|
+
}
|
|
17255
17286
|
try {
|
|
17256
17287
|
await this.agentStreamExecutor({
|
|
17257
|
-
input
|
|
17258
|
-
custom_run_config: queueMessageData.custom_run_config
|
|
17288
|
+
input,
|
|
17289
|
+
custom_run_config: p.custom_run_config ?? queueMessageData.custom_run_config
|
|
17259
17290
|
}, signal);
|
|
17260
17291
|
await this.queueStore?.markCompleted(p.id);
|
|
17261
17292
|
const runStatus = await this.getRunStatus();
|
|
@@ -17263,7 +17294,7 @@ var Agent = class {
|
|
|
17263
17294
|
if (runStatus === "interrupted" /* INTERRUPTED */) {
|
|
17264
17295
|
this.publish("message:interrupted", {
|
|
17265
17296
|
type: "message:interrupted",
|
|
17266
|
-
messageId:
|
|
17297
|
+
messageId: humanContent.id,
|
|
17267
17298
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17268
17299
|
duration: Date.now() - startTime,
|
|
17269
17300
|
state
|
|
@@ -17272,13 +17303,13 @@ var Agent = class {
|
|
|
17272
17303
|
this.addChunk({
|
|
17273
17304
|
type: "message_completed",
|
|
17274
17305
|
data: {
|
|
17275
|
-
id:
|
|
17306
|
+
id: humanContent.id,
|
|
17276
17307
|
content: ""
|
|
17277
17308
|
}
|
|
17278
17309
|
});
|
|
17279
17310
|
this.publish("message:completed", {
|
|
17280
17311
|
type: "message:completed",
|
|
17281
|
-
messageId:
|
|
17312
|
+
messageId: humanContent.id,
|
|
17282
17313
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17283
17314
|
duration: Date.now() - startTime,
|
|
17284
17315
|
state
|
|
@@ -17289,13 +17320,13 @@ var Agent = class {
|
|
|
17289
17320
|
this.addChunk({
|
|
17290
17321
|
type: "message_failed",
|
|
17291
17322
|
data: {
|
|
17292
|
-
id:
|
|
17323
|
+
id: humanContent.id,
|
|
17293
17324
|
content: error instanceof Error ? error.message : String(error)
|
|
17294
17325
|
}
|
|
17295
17326
|
});
|
|
17296
17327
|
this.publish("message:failed", {
|
|
17297
17328
|
type: "message:failed",
|
|
17298
|
-
messageId:
|
|
17329
|
+
messageId: humanContent.id,
|
|
17299
17330
|
error: error instanceof Error ? error.message : String(error),
|
|
17300
17331
|
timestamp: /* @__PURE__ */ new Date()
|
|
17301
17332
|
});
|
|
@@ -17313,6 +17344,12 @@ var Agent = class {
|
|
|
17313
17344
|
this.project_id = project_id;
|
|
17314
17345
|
this.custom_run_config = custom_run_config;
|
|
17315
17346
|
}
|
|
17347
|
+
getHumanPendingContent(message) {
|
|
17348
|
+
if (typeof message.content === "string" || !message.content || !("id" in message.content) || !("message" in message.content)) {
|
|
17349
|
+
throw new Error(`Expected human pending message content for message ${message.id}`);
|
|
17350
|
+
}
|
|
17351
|
+
return message.content;
|
|
17352
|
+
}
|
|
17316
17353
|
/**
|
|
17317
17354
|
* Initialize with message queue store
|
|
17318
17355
|
*/
|
|
@@ -17427,7 +17464,7 @@ var Agent = class {
|
|
|
17427
17464
|
*/
|
|
17428
17465
|
async addMessage(queueMessage, mode) {
|
|
17429
17466
|
const useMode = mode ?? this.queueMode.mode;
|
|
17430
|
-
const messageId = (0, import_uuid2.v4)();
|
|
17467
|
+
const messageId = queueMessage.input.id || (0, import_uuid2.v4)();
|
|
17431
17468
|
const isHighPriority = useMode === "steer" /* STEER */ || !!queueMessage.command;
|
|
17432
17469
|
const store = this.getQueueStore();
|
|
17433
17470
|
const currentSize = await store.getQueueSize(this.thread_id);
|
|
@@ -17446,14 +17483,31 @@ var Agent = class {
|
|
|
17446
17483
|
}
|
|
17447
17484
|
};
|
|
17448
17485
|
if (isHighPriority) {
|
|
17449
|
-
await store.addMessageAtHead(
|
|
17486
|
+
await store.addMessageAtHead({
|
|
17487
|
+
threadId: this.thread_id,
|
|
17488
|
+
tenantId: this.tenant_id,
|
|
17489
|
+
assistantId: this.assistant_id,
|
|
17490
|
+
content,
|
|
17491
|
+
type: "human",
|
|
17492
|
+
command: queueMessage.command,
|
|
17493
|
+
custom_run_config: queueMessage.custom_run_config,
|
|
17494
|
+
id: messageId
|
|
17495
|
+
});
|
|
17496
|
+
if (useMode === "steer" /* STEER */) {
|
|
17497
|
+
this.stopQueueProcessor();
|
|
17498
|
+
await store.resetProcessingToPending(this.thread_id);
|
|
17499
|
+
console.log(`[Agent] STEER mode: stopped current processing, reset queue, message ${messageId} will execute next`);
|
|
17500
|
+
}
|
|
17450
17501
|
} else {
|
|
17451
17502
|
await store.addMessage({
|
|
17452
17503
|
threadId: this.thread_id,
|
|
17453
17504
|
tenantId: this.tenant_id,
|
|
17454
17505
|
assistantId: this.assistant_id,
|
|
17455
17506
|
content,
|
|
17456
|
-
type: "human"
|
|
17507
|
+
type: "human",
|
|
17508
|
+
command: queueMessage.command,
|
|
17509
|
+
custom_run_config: queueMessage.custom_run_config,
|
|
17510
|
+
id: messageId
|
|
17457
17511
|
});
|
|
17458
17512
|
}
|
|
17459
17513
|
this.startQueueProcessorIfNeeded().catch((err) => {
|
|
@@ -17486,7 +17540,7 @@ var Agent = class {
|
|
|
17486
17540
|
this.publish("thread:busy", {
|
|
17487
17541
|
type: "thread:busy",
|
|
17488
17542
|
timestamp: /* @__PURE__ */ new Date(),
|
|
17489
|
-
messageId: firstMessage
|
|
17543
|
+
messageId: firstMessage ? this.getHumanPendingContent(firstMessage).id : void 0
|
|
17490
17544
|
});
|
|
17491
17545
|
this.waitingForQueueEnd(this.abortController.signal).catch((error) => {
|
|
17492
17546
|
console.error(`Queue processing error for thread ${this.thread_id}:`, error);
|
|
@@ -17512,11 +17566,13 @@ var Agent = class {
|
|
|
17512
17566
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
17513
17567
|
}
|
|
17514
17568
|
};
|
|
17515
|
-
await this.queueStore.addMessageAtHead(
|
|
17516
|
-
thread.threadId,
|
|
17517
|
-
|
|
17518
|
-
|
|
17519
|
-
|
|
17569
|
+
await this.queueStore.addMessageAtHead({
|
|
17570
|
+
threadId: thread.threadId,
|
|
17571
|
+
tenantId: thread.tenantId,
|
|
17572
|
+
assistantId: thread.assistantId,
|
|
17573
|
+
content: reminderContent,
|
|
17574
|
+
type: "system"
|
|
17575
|
+
});
|
|
17520
17576
|
}
|
|
17521
17577
|
async getCurrentState() {
|
|
17522
17578
|
const { runnable_agent } = await this.getLatticeClientAndRuntimeConfig();
|