@axiom-lattice/core 2.1.40 → 2.1.42
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 +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +180 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +141 -106
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -10949,13 +10949,13 @@ var StoreBackend = class {
|
|
|
10949
10949
|
* @returns List of all items matching the search criteria
|
|
10950
10950
|
*/
|
|
10951
10951
|
async searchStorePaginated(store, namespace, options = {}) {
|
|
10952
|
-
const { query, filter, pageSize = 100 } = options;
|
|
10952
|
+
const { query, filter: filter2, pageSize = 100 } = options;
|
|
10953
10953
|
const allItems = [];
|
|
10954
10954
|
let offset = 0;
|
|
10955
10955
|
while (true) {
|
|
10956
10956
|
const pageItems = await store.search(namespace, {
|
|
10957
10957
|
query,
|
|
10958
|
-
filter,
|
|
10958
|
+
filter: filter2,
|
|
10959
10959
|
limit: pageSize,
|
|
10960
10960
|
offset
|
|
10961
10961
|
});
|
|
@@ -12264,17 +12264,11 @@ ${BASE_PROMPT}` : BASE_PROMPT;
|
|
|
12264
12264
|
todoListMiddleware(),
|
|
12265
12265
|
// Enables filesystem operations and optional long-term memory storage
|
|
12266
12266
|
createFilesystemMiddleware({ backend: filesystemBackend }),
|
|
12267
|
-
createClawMiddleware({
|
|
12268
|
-
backend: filesystemBackend
|
|
12269
|
-
}),
|
|
12270
12267
|
// Enables delegation to specialized subagents for complex tasks
|
|
12271
12268
|
createSubAgentMiddleware({
|
|
12272
12269
|
defaultModel: model,
|
|
12273
12270
|
defaultTools: tools,
|
|
12274
12271
|
defaultMiddleware: [
|
|
12275
|
-
createClawMiddleware({
|
|
12276
|
-
backend: filesystemBackend
|
|
12277
|
-
}),
|
|
12278
12272
|
// Subagent middleware: Todo list management
|
|
12279
12273
|
todoListMiddleware(),
|
|
12280
12274
|
// Subagent middleware: Filesystem operations
|
|
@@ -14631,7 +14625,10 @@ var ChunkBuffer = class {
|
|
|
14631
14625
|
};
|
|
14632
14626
|
|
|
14633
14627
|
// src/chunk_buffer_lattice/InMemoryChunkBuffer.ts
|
|
14628
|
+
var import_protocols5 = require("@axiom-lattice/protocols");
|
|
14634
14629
|
var import_rxjs = require("rxjs");
|
|
14630
|
+
var import_rxjs_for_await = require("rxjs-for-await");
|
|
14631
|
+
var import_operators = require("rxjs/operators");
|
|
14635
14632
|
var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
14636
14633
|
constructor(config) {
|
|
14637
14634
|
super();
|
|
@@ -14716,7 +14713,7 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
14716
14713
|
let chunk;
|
|
14717
14714
|
if (typeof arg2 === "string" && arg3 !== void 0) {
|
|
14718
14715
|
chunk = {
|
|
14719
|
-
type:
|
|
14716
|
+
type: import_protocols5.MessageChunkTypes.AI,
|
|
14720
14717
|
data: {
|
|
14721
14718
|
id: arg2,
|
|
14722
14719
|
content: arg3
|
|
@@ -14830,76 +14827,27 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
|
|
|
14830
14827
|
buffer2.updatedAt = Date.now();
|
|
14831
14828
|
}
|
|
14832
14829
|
}
|
|
14833
|
-
async *getNewChunksSinceContentIterator(threadId, messageId, knownContent) {
|
|
14830
|
+
async *getNewChunksSinceContentIterator(threadId, messageId, knownContent, stopTypes) {
|
|
14834
14831
|
const buffer2 = this.getBufferIfValid(threadId);
|
|
14835
14832
|
if (!buffer2) return;
|
|
14836
|
-
|
|
14837
|
-
|
|
14838
|
-
|
|
14839
|
-
|
|
14840
|
-
|
|
14841
|
-
let pendingError = null;
|
|
14842
|
-
const subscription = buffer2.chunks$.pipe((0, import_rxjs.observeOn)(import_rxjs.asyncScheduler)).subscribe({
|
|
14843
|
-
next: (chunk) => {
|
|
14844
|
-
queue.push(chunk);
|
|
14845
|
-
if (resolveNext) {
|
|
14846
|
-
const resolve3 = resolveNext;
|
|
14847
|
-
resolveNext = null;
|
|
14848
|
-
resolve3();
|
|
14849
|
-
}
|
|
14850
|
-
},
|
|
14851
|
-
error: (err) => {
|
|
14852
|
-
pendingError = err;
|
|
14853
|
-
if (errorNext) {
|
|
14854
|
-
const reject = errorNext;
|
|
14855
|
-
errorNext = null;
|
|
14856
|
-
reject(err);
|
|
14857
|
-
} else if (resolveNext) {
|
|
14858
|
-
const resolve3 = resolveNext;
|
|
14859
|
-
resolveNext = null;
|
|
14860
|
-
resolve3();
|
|
14861
|
-
}
|
|
14862
|
-
},
|
|
14863
|
-
complete: () => {
|
|
14864
|
-
isCompleted = true;
|
|
14865
|
-
if (resolveNext) {
|
|
14866
|
-
const resolve3 = resolveNext;
|
|
14867
|
-
resolveNext = null;
|
|
14868
|
-
resolve3();
|
|
14869
|
-
}
|
|
14870
|
-
}
|
|
14871
|
-
});
|
|
14833
|
+
const defaultStopTypes = [
|
|
14834
|
+
import_protocols5.MessageChunkTypes.MESSAGE_COMPLETED,
|
|
14835
|
+
import_protocols5.MessageChunkTypes.THREAD_IDLE
|
|
14836
|
+
];
|
|
14837
|
+
const typesToStop = stopTypes ?? defaultStopTypes;
|
|
14872
14838
|
let startYieldChunk = false;
|
|
14873
|
-
|
|
14874
|
-
|
|
14875
|
-
|
|
14876
|
-
|
|
14877
|
-
|
|
14878
|
-
if (
|
|
14879
|
-
|
|
14880
|
-
|
|
14881
|
-
|
|
14882
|
-
|
|
14883
|
-
|
|
14884
|
-
|
|
14885
|
-
if (pendingError) {
|
|
14886
|
-
throw pendingError;
|
|
14887
|
-
}
|
|
14888
|
-
while (queue.length > 0) {
|
|
14889
|
-
const chunk = queue.shift();
|
|
14890
|
-
if (!chunk) continue;
|
|
14891
|
-
if (chunk.data?.id === messageId) {
|
|
14892
|
-
startYieldChunk = true;
|
|
14893
|
-
accumulatedContent += chunk.data?.content || "";
|
|
14894
|
-
}
|
|
14895
|
-
if (startYieldChunk) {
|
|
14896
|
-
yield chunk;
|
|
14897
|
-
}
|
|
14898
|
-
}
|
|
14899
|
-
}
|
|
14900
|
-
} finally {
|
|
14901
|
-
subscription.unsubscribe();
|
|
14902
|
-
}
|
|
14839
|
+
console.log("start from messageId", messageId);
|
|
14840
|
+
const filtered$ = buffer2.chunks$.pipe(
|
|
14841
|
+
(0, import_rxjs.observeOn)(import_rxjs.asyncScheduler),
|
|
14842
|
+
// 1. 从指定 messageId 开始
|
|
14843
|
+
(0, import_operators.filter)((chunk) => {
|
|
14844
|
+
if (chunk.data?.id === messageId) startYieldChunk = true;
|
|
14845
|
+
return startYieldChunk;
|
|
14846
|
+
}),
|
|
14847
|
+
// 2. 包含指定的停止类型,但收到后停止
|
|
14848
|
+
(0, import_operators.takeWhile)((chunk) => !typesToStop.includes(chunk.type), true)
|
|
14849
|
+
);
|
|
14850
|
+
yield* (0, import_rxjs_for_await.eachValueFrom)(filtered$);
|
|
14903
14851
|
}
|
|
14904
14852
|
getStats() {
|
|
14905
14853
|
let activeCount = 0;
|
|
@@ -14979,13 +14927,13 @@ var buffer = new InMemoryChunkBuffer({
|
|
|
14979
14927
|
registerChunkBuffer("default", buffer);
|
|
14980
14928
|
|
|
14981
14929
|
// src/schedule_lattice/ScheduleLatticeManager.ts
|
|
14982
|
-
var
|
|
14930
|
+
var import_protocols8 = require("@axiom-lattice/protocols");
|
|
14983
14931
|
|
|
14984
14932
|
// src/schedule_lattice/DefaultScheduleClient.ts
|
|
14985
|
-
var
|
|
14933
|
+
var import_protocols7 = require("@axiom-lattice/protocols");
|
|
14986
14934
|
|
|
14987
14935
|
// src/schedule_lattice/MemoryScheduleStorage.ts
|
|
14988
|
-
var
|
|
14936
|
+
var import_protocols6 = require("@axiom-lattice/protocols");
|
|
14989
14937
|
var MemoryScheduleStorage = class {
|
|
14990
14938
|
constructor() {
|
|
14991
14939
|
this.tasks = /* @__PURE__ */ new Map();
|
|
@@ -15028,7 +14976,7 @@ var MemoryScheduleStorage = class {
|
|
|
15028
14976
|
async getActiveTasks() {
|
|
15029
14977
|
const result = [];
|
|
15030
14978
|
for (const task of this.tasks.values()) {
|
|
15031
|
-
if (task.status ===
|
|
14979
|
+
if (task.status === import_protocols6.ScheduledTaskStatus.PENDING || task.status === import_protocols6.ScheduledTaskStatus.PAUSED) {
|
|
15032
14980
|
result.push({ ...task });
|
|
15033
14981
|
}
|
|
15034
14982
|
}
|
|
@@ -15171,7 +15119,7 @@ var MemoryScheduleStorage = class {
|
|
|
15171
15119
|
const cutoff = Date.now() - olderThanMs;
|
|
15172
15120
|
let deleted = 0;
|
|
15173
15121
|
for (const [taskId, task] of this.tasks.entries()) {
|
|
15174
|
-
if ((task.status ===
|
|
15122
|
+
if ((task.status === import_protocols6.ScheduledTaskStatus.COMPLETED || task.status === import_protocols6.ScheduledTaskStatus.CANCELLED || task.status === import_protocols6.ScheduledTaskStatus.FAILED) && task.updatedAt < cutoff) {
|
|
15175
15123
|
this.tasks.delete(taskId);
|
|
15176
15124
|
deleted++;
|
|
15177
15125
|
}
|
|
@@ -15452,10 +15400,10 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15452
15400
|
tenantId: options.tenantId ?? "default",
|
|
15453
15401
|
assistantId: options.assistantId,
|
|
15454
15402
|
threadId: options.threadId,
|
|
15455
|
-
executionType:
|
|
15403
|
+
executionType: import_protocols7.ScheduleExecutionType.ONCE,
|
|
15456
15404
|
executeAt,
|
|
15457
15405
|
delayMs: options.delayMs,
|
|
15458
|
-
status:
|
|
15406
|
+
status: import_protocols7.ScheduledTaskStatus.PENDING,
|
|
15459
15407
|
runCount: 0,
|
|
15460
15408
|
retryCount: 0,
|
|
15461
15409
|
maxRetries: options.maxRetries ?? 0,
|
|
@@ -15498,11 +15446,11 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15498
15446
|
tenantId: options.tenantId ?? "default",
|
|
15499
15447
|
assistantId: options.assistantId,
|
|
15500
15448
|
threadId: options.threadId,
|
|
15501
|
-
executionType:
|
|
15449
|
+
executionType: import_protocols7.ScheduleExecutionType.CRON,
|
|
15502
15450
|
cronExpression: options.cronExpression,
|
|
15503
15451
|
timezone: options.timezone,
|
|
15504
15452
|
nextRunAt: nextRunAt.getTime(),
|
|
15505
|
-
status:
|
|
15453
|
+
status: import_protocols7.ScheduledTaskStatus.PENDING,
|
|
15506
15454
|
runCount: 0,
|
|
15507
15455
|
maxRuns: options.maxRuns,
|
|
15508
15456
|
retryCount: 0,
|
|
@@ -15529,7 +15477,7 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15529
15477
|
const task = await this.storage.get(taskId);
|
|
15530
15478
|
if (task) {
|
|
15531
15479
|
await this.storage.update(taskId, {
|
|
15532
|
-
status:
|
|
15480
|
+
status: import_protocols7.ScheduledTaskStatus.CANCELLED
|
|
15533
15481
|
});
|
|
15534
15482
|
console.log(`[Scheduler] Task cancelled: ${taskId}`);
|
|
15535
15483
|
return true;
|
|
@@ -15538,11 +15486,11 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15538
15486
|
}
|
|
15539
15487
|
async pause(taskId) {
|
|
15540
15488
|
const task = await this.storage.get(taskId);
|
|
15541
|
-
if (!task || task.executionType !==
|
|
15489
|
+
if (!task || task.executionType !== import_protocols7.ScheduleExecutionType.CRON) {
|
|
15542
15490
|
console.error(`[Scheduler] Can only pause CRON tasks: ${taskId}`);
|
|
15543
15491
|
return false;
|
|
15544
15492
|
}
|
|
15545
|
-
if (task.status !==
|
|
15493
|
+
if (task.status !== import_protocols7.ScheduledTaskStatus.PENDING) {
|
|
15546
15494
|
console.error(`[Scheduler] Can only pause PENDING tasks: ${taskId}`);
|
|
15547
15495
|
return false;
|
|
15548
15496
|
}
|
|
@@ -15552,24 +15500,24 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15552
15500
|
this.timers.delete(taskId);
|
|
15553
15501
|
}
|
|
15554
15502
|
await this.storage.update(taskId, {
|
|
15555
|
-
status:
|
|
15503
|
+
status: import_protocols7.ScheduledTaskStatus.PAUSED
|
|
15556
15504
|
});
|
|
15557
15505
|
console.log(`[Scheduler] Task paused: ${taskId}`);
|
|
15558
15506
|
return true;
|
|
15559
15507
|
}
|
|
15560
15508
|
async resume(taskId) {
|
|
15561
15509
|
const task = await this.storage.get(taskId);
|
|
15562
|
-
if (!task || task.executionType !==
|
|
15510
|
+
if (!task || task.executionType !== import_protocols7.ScheduleExecutionType.CRON) {
|
|
15563
15511
|
console.error(`[Scheduler] Can only resume CRON tasks: ${taskId}`);
|
|
15564
15512
|
return false;
|
|
15565
15513
|
}
|
|
15566
|
-
if (task.status !==
|
|
15514
|
+
if (task.status !== import_protocols7.ScheduledTaskStatus.PAUSED) {
|
|
15567
15515
|
console.error(`[Scheduler] Can only resume PAUSED tasks: ${taskId}`);
|
|
15568
15516
|
return false;
|
|
15569
15517
|
}
|
|
15570
15518
|
const nextRunAt = getNextCronTime(task.cronExpression);
|
|
15571
15519
|
await this.storage.update(taskId, {
|
|
15572
|
-
status:
|
|
15520
|
+
status: import_protocols7.ScheduledTaskStatus.PENDING,
|
|
15573
15521
|
nextRunAt: nextRunAt.getTime()
|
|
15574
15522
|
});
|
|
15575
15523
|
const updatedTask = await this.storage.get(taskId);
|
|
@@ -15591,7 +15539,7 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15591
15539
|
if (!task) {
|
|
15592
15540
|
return -1;
|
|
15593
15541
|
}
|
|
15594
|
-
const targetTime = task.executionType ===
|
|
15542
|
+
const targetTime = task.executionType === import_protocols7.ScheduleExecutionType.CRON ? task.nextRunAt : task.executeAt;
|
|
15595
15543
|
if (targetTime === void 0) {
|
|
15596
15544
|
return -1;
|
|
15597
15545
|
}
|
|
@@ -15613,7 +15561,7 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15613
15561
|
const activeTasks = await this.storage.getActiveTasks();
|
|
15614
15562
|
for (const task of activeTasks) {
|
|
15615
15563
|
await this.storage.update(task.taskId, {
|
|
15616
|
-
status:
|
|
15564
|
+
status: import_protocols7.ScheduledTaskStatus.CANCELLED
|
|
15617
15565
|
});
|
|
15618
15566
|
}
|
|
15619
15567
|
console.log(`[Scheduler] All tasks cancelled`);
|
|
@@ -15629,10 +15577,10 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15629
15577
|
);
|
|
15630
15578
|
continue;
|
|
15631
15579
|
}
|
|
15632
|
-
if (task.status ===
|
|
15580
|
+
if (task.status === import_protocols7.ScheduledTaskStatus.PAUSED) {
|
|
15633
15581
|
continue;
|
|
15634
15582
|
}
|
|
15635
|
-
if (task.executionType ===
|
|
15583
|
+
if (task.executionType === import_protocols7.ScheduleExecutionType.ONCE) {
|
|
15636
15584
|
if (task.executeAt && task.executeAt <= Date.now()) {
|
|
15637
15585
|
console.log(
|
|
15638
15586
|
`[Scheduler] Executing overdue one-time task: ${task.taskId}`
|
|
@@ -15641,7 +15589,7 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15641
15589
|
} else {
|
|
15642
15590
|
this.scheduleTimer(task);
|
|
15643
15591
|
}
|
|
15644
|
-
} else if (task.executionType ===
|
|
15592
|
+
} else if (task.executionType === import_protocols7.ScheduleExecutionType.CRON) {
|
|
15645
15593
|
const nextRunAt = getNextCronTime(task.cronExpression);
|
|
15646
15594
|
await this.storage.update(task.taskId, {
|
|
15647
15595
|
nextRunAt: nextRunAt.getTime()
|
|
@@ -15665,7 +15613,7 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15665
15613
|
}
|
|
15666
15614
|
// ===== Private Methods =====
|
|
15667
15615
|
scheduleTimer(task) {
|
|
15668
|
-
const targetTime = task.executionType ===
|
|
15616
|
+
const targetTime = task.executionType === import_protocols7.ScheduleExecutionType.CRON ? task.nextRunAt : task.executeAt;
|
|
15669
15617
|
if (targetTime === void 0) {
|
|
15670
15618
|
console.error(`[Scheduler] No execution time for task: ${task.taskId}`);
|
|
15671
15619
|
return;
|
|
@@ -15686,13 +15634,13 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15686
15634
|
`[Scheduler] No handler for task type: ${task.taskType}, task: ${task.taskId}`
|
|
15687
15635
|
);
|
|
15688
15636
|
await this.storage.update(task.taskId, {
|
|
15689
|
-
status:
|
|
15637
|
+
status: import_protocols7.ScheduledTaskStatus.FAILED,
|
|
15690
15638
|
lastError: `No handler registered for task type: ${task.taskType}`
|
|
15691
15639
|
});
|
|
15692
15640
|
return;
|
|
15693
15641
|
}
|
|
15694
15642
|
await this.storage.update(task.taskId, {
|
|
15695
|
-
status:
|
|
15643
|
+
status: import_protocols7.ScheduledTaskStatus.RUNNING
|
|
15696
15644
|
});
|
|
15697
15645
|
console.log(`[Scheduler] Executing task: ${task.taskId}`);
|
|
15698
15646
|
try {
|
|
@@ -15704,17 +15652,17 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15704
15652
|
await handler(latestTask.payload, latestTask);
|
|
15705
15653
|
const newRunCount = latestTask.runCount + 1;
|
|
15706
15654
|
console.log(`[Scheduler] Task completed: ${task.taskId}`);
|
|
15707
|
-
if (task.executionType ===
|
|
15655
|
+
if (task.executionType === import_protocols7.ScheduleExecutionType.ONCE) {
|
|
15708
15656
|
await this.storage.update(task.taskId, {
|
|
15709
|
-
status:
|
|
15657
|
+
status: import_protocols7.ScheduledTaskStatus.COMPLETED,
|
|
15710
15658
|
runCount: newRunCount,
|
|
15711
15659
|
lastRunAt: Date.now()
|
|
15712
15660
|
});
|
|
15713
15661
|
this.timers.delete(task.taskId);
|
|
15714
|
-
} else if (task.executionType ===
|
|
15662
|
+
} else if (task.executionType === import_protocols7.ScheduleExecutionType.CRON) {
|
|
15715
15663
|
if (task.maxRuns !== void 0 && newRunCount >= task.maxRuns) {
|
|
15716
15664
|
await this.storage.update(task.taskId, {
|
|
15717
|
-
status:
|
|
15665
|
+
status: import_protocols7.ScheduledTaskStatus.COMPLETED,
|
|
15718
15666
|
runCount: newRunCount,
|
|
15719
15667
|
lastRunAt: Date.now()
|
|
15720
15668
|
});
|
|
@@ -15726,7 +15674,7 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15726
15674
|
}
|
|
15727
15675
|
if (task.expiresAt !== void 0 && Date.now() >= task.expiresAt) {
|
|
15728
15676
|
await this.storage.update(task.taskId, {
|
|
15729
|
-
status:
|
|
15677
|
+
status: import_protocols7.ScheduledTaskStatus.COMPLETED,
|
|
15730
15678
|
runCount: newRunCount,
|
|
15731
15679
|
lastRunAt: Date.now()
|
|
15732
15680
|
});
|
|
@@ -15738,7 +15686,7 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15738
15686
|
}
|
|
15739
15687
|
const nextRunAt = getNextCronTime(task.cronExpression);
|
|
15740
15688
|
await this.storage.update(task.taskId, {
|
|
15741
|
-
status:
|
|
15689
|
+
status: import_protocols7.ScheduledTaskStatus.PENDING,
|
|
15742
15690
|
runCount: newRunCount,
|
|
15743
15691
|
lastRunAt: Date.now(),
|
|
15744
15692
|
nextRunAt: nextRunAt.getTime(),
|
|
@@ -15764,7 +15712,7 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15764
15712
|
`[Scheduler] Retrying task: ${task.taskId} (attempt ${newRetryCount}/${latestTask.maxRetries})`
|
|
15765
15713
|
);
|
|
15766
15714
|
await this.storage.update(task.taskId, {
|
|
15767
|
-
status:
|
|
15715
|
+
status: import_protocols7.ScheduledTaskStatus.PENDING,
|
|
15768
15716
|
retryCount: newRetryCount,
|
|
15769
15717
|
lastError: errorMessage
|
|
15770
15718
|
});
|
|
@@ -15774,7 +15722,7 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15774
15722
|
);
|
|
15775
15723
|
const retryTask = await this.storage.get(task.taskId);
|
|
15776
15724
|
if (retryTask) {
|
|
15777
|
-
if (task.executionType ===
|
|
15725
|
+
if (task.executionType === import_protocols7.ScheduleExecutionType.ONCE) {
|
|
15778
15726
|
retryTask.executeAt = Date.now() + retryDelay;
|
|
15779
15727
|
} else {
|
|
15780
15728
|
retryTask.nextRunAt = Date.now() + retryDelay;
|
|
@@ -15787,7 +15735,7 @@ var _DefaultScheduleClient = class _DefaultScheduleClient {
|
|
|
15787
15735
|
}
|
|
15788
15736
|
} else {
|
|
15789
15737
|
await this.storage.update(task.taskId, {
|
|
15790
|
-
status:
|
|
15738
|
+
status: import_protocols7.ScheduledTaskStatus.FAILED,
|
|
15791
15739
|
retryCount: newRetryCount,
|
|
15792
15740
|
lastError: errorMessage
|
|
15793
15741
|
});
|
|
@@ -15839,9 +15787,9 @@ var ScheduleLatticeManager = class _ScheduleLatticeManager extends BaseLatticeMa
|
|
|
15839
15787
|
} else {
|
|
15840
15788
|
storage = new MemoryScheduleStorage();
|
|
15841
15789
|
}
|
|
15842
|
-
if (config.type ===
|
|
15790
|
+
if (config.type === import_protocols8.ScheduleType.MEMORY) {
|
|
15843
15791
|
scheduleClient = new DefaultScheduleClient(storage);
|
|
15844
|
-
} else if (config.type ===
|
|
15792
|
+
} else if (config.type === import_protocols8.ScheduleType.POSTGRES) {
|
|
15845
15793
|
if (!config.storage) {
|
|
15846
15794
|
throw new Error(
|
|
15847
15795
|
`PostgreSQL schedule storage must be provided. Please install @axiom-lattice/pg-stores and pass the storage in config.storage.`
|
|
@@ -16151,7 +16099,7 @@ var getVectorStoreLattice = (key) => vectorStoreLatticeManager.getVectorStoreLat
|
|
|
16151
16099
|
var getVectorStoreClient = (key) => vectorStoreLatticeManager.getVectorStoreClient(key);
|
|
16152
16100
|
|
|
16153
16101
|
// src/logger_lattice/LoggerLatticeManager.ts
|
|
16154
|
-
var
|
|
16102
|
+
var import_protocols9 = require("@axiom-lattice/protocols");
|
|
16155
16103
|
|
|
16156
16104
|
// src/logger_lattice/PinoLoggerClient.ts
|
|
16157
16105
|
var import_pino = __toESM(require("pino"));
|
|
@@ -16373,11 +16321,11 @@ var LoggerLatticeManager = class _LoggerLatticeManager extends BaseLatticeManage
|
|
|
16373
16321
|
if (client) {
|
|
16374
16322
|
loggerClient = client;
|
|
16375
16323
|
} else {
|
|
16376
|
-
if (config.type ===
|
|
16324
|
+
if (config.type === import_protocols9.LoggerType.PINO) {
|
|
16377
16325
|
loggerClient = new PinoLoggerClient(config);
|
|
16378
|
-
} else if (config.type ===
|
|
16326
|
+
} else if (config.type === import_protocols9.LoggerType.CONSOLE) {
|
|
16379
16327
|
loggerClient = new ConsoleLoggerClient(config);
|
|
16380
|
-
} else if (config.type ===
|
|
16328
|
+
} else if (config.type === import_protocols9.LoggerType.CUSTOM) {
|
|
16381
16329
|
throw new Error(
|
|
16382
16330
|
`Custom logger client must be provided. Please pass the client to registerLattice.`
|
|
16383
16331
|
);
|
|
@@ -16968,6 +16916,7 @@ var Agent = class {
|
|
|
16968
16916
|
this.chunkBuffer = getChunkBuffer("default");
|
|
16969
16917
|
this.abortController = null;
|
|
16970
16918
|
this.queueMode = this.getDefaultQueueConfig();
|
|
16919
|
+
this.isWaitingForQueueEnd = false;
|
|
16971
16920
|
this.agentExecutor = async ({ input, command, custom_run_config }, signal) => {
|
|
16972
16921
|
const { runnable_agent, runConfig } = await this.getLatticeClientAndRuntimeConfig(custom_run_config);
|
|
16973
16922
|
const { messages, ...rest } = input;
|
|
@@ -17095,9 +17044,7 @@ var Agent = class {
|
|
|
17095
17044
|
};
|
|
17096
17045
|
}
|
|
17097
17046
|
if (data) {
|
|
17098
|
-
|
|
17099
|
-
await lifecycleManager.addChunk(data);
|
|
17100
|
-
}
|
|
17047
|
+
lifecycleManager.addChunk(data);
|
|
17101
17048
|
}
|
|
17102
17049
|
}
|
|
17103
17050
|
} catch (error) {
|
|
@@ -17114,8 +17061,8 @@ var Agent = class {
|
|
|
17114
17061
|
while (!signal?.aborted) {
|
|
17115
17062
|
const pendings = await this.getPendingMessages();
|
|
17116
17063
|
if (pendings.length === 0) {
|
|
17117
|
-
await this.chunkBuffer.completeThread(this.thread_id);
|
|
17118
17064
|
const state = await this.getCurrentState();
|
|
17065
|
+
const runStatus = await this.getRunStatus();
|
|
17119
17066
|
const pendingCount = await this.getQueueStore().getQueueSize(this.thread_id);
|
|
17120
17067
|
this.publish("thread:idle", {
|
|
17121
17068
|
type: "thread:idle",
|
|
@@ -17123,6 +17070,15 @@ var Agent = class {
|
|
|
17123
17070
|
pendingCount,
|
|
17124
17071
|
state
|
|
17125
17072
|
});
|
|
17073
|
+
if (runStatus === "idle" /* IDLE */) {
|
|
17074
|
+
this.addChunk({
|
|
17075
|
+
type: "thread_idle",
|
|
17076
|
+
data: {
|
|
17077
|
+
id: this.thread_id,
|
|
17078
|
+
content: ""
|
|
17079
|
+
}
|
|
17080
|
+
});
|
|
17081
|
+
}
|
|
17126
17082
|
break;
|
|
17127
17083
|
}
|
|
17128
17084
|
const firstMessage = pendings[0];
|
|
@@ -17141,22 +17097,49 @@ var Agent = class {
|
|
|
17141
17097
|
queueMode: this.queueMode.mode
|
|
17142
17098
|
});
|
|
17143
17099
|
const input = {
|
|
17144
|
-
messages: [new import_langchain61.HumanMessage({ id: p.content.id, content: p.content.message })]
|
|
17145
|
-
command: p.content.command
|
|
17100
|
+
messages: [new import_langchain61.HumanMessage({ id: p.content.id, content: p.content.message })]
|
|
17146
17101
|
};
|
|
17147
17102
|
try {
|
|
17148
|
-
await this.agentStreamExecutor({
|
|
17103
|
+
await this.agentStreamExecutor({
|
|
17104
|
+
input,
|
|
17105
|
+
command: p.content.command
|
|
17106
|
+
}, signal);
|
|
17149
17107
|
await this.queueStore?.markCompleted(p.id);
|
|
17108
|
+
const runStatus = await this.getRunStatus();
|
|
17150
17109
|
const state = await this.getCurrentState();
|
|
17151
|
-
|
|
17152
|
-
|
|
17153
|
-
|
|
17154
|
-
|
|
17155
|
-
|
|
17156
|
-
|
|
17157
|
-
|
|
17110
|
+
if (runStatus === "interrupted" /* INTERRUPTED */) {
|
|
17111
|
+
this.publish("message:interrupted", {
|
|
17112
|
+
type: "message:interrupted",
|
|
17113
|
+
messageId: p.content.id,
|
|
17114
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
17115
|
+
duration: Date.now() - startTime,
|
|
17116
|
+
state
|
|
17117
|
+
});
|
|
17118
|
+
} else {
|
|
17119
|
+
this.addChunk({
|
|
17120
|
+
type: "message_completed",
|
|
17121
|
+
data: {
|
|
17122
|
+
id: p.content.id,
|
|
17123
|
+
content: ""
|
|
17124
|
+
}
|
|
17125
|
+
});
|
|
17126
|
+
this.publish("message:completed", {
|
|
17127
|
+
type: "message:completed",
|
|
17128
|
+
messageId: p.content.id,
|
|
17129
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
17130
|
+
duration: Date.now() - startTime,
|
|
17131
|
+
state
|
|
17132
|
+
});
|
|
17133
|
+
}
|
|
17158
17134
|
} catch (error) {
|
|
17159
17135
|
console.error(`STEER/Command message ${p.id} execution failed:`, error);
|
|
17136
|
+
this.addChunk({
|
|
17137
|
+
type: "message_failed",
|
|
17138
|
+
data: {
|
|
17139
|
+
id: p.content.id,
|
|
17140
|
+
content: error instanceof Error ? error.message : String(error)
|
|
17141
|
+
}
|
|
17142
|
+
});
|
|
17160
17143
|
this.publish("message:failed", {
|
|
17161
17144
|
type: "message:failed",
|
|
17162
17145
|
messageId: p.content.id,
|
|
@@ -17185,20 +17168,45 @@ var Agent = class {
|
|
|
17185
17168
|
});
|
|
17186
17169
|
try {
|
|
17187
17170
|
await this.agentStreamExecutor({ input: { messages: userMessages } }, signal);
|
|
17171
|
+
const runStatus = await this.getRunStatus();
|
|
17188
17172
|
const state = await this.getCurrentState();
|
|
17189
17173
|
for (const p of remainingPendings) {
|
|
17190
17174
|
await this.queueStore?.markCompleted(p.id);
|
|
17191
|
-
|
|
17192
|
-
|
|
17193
|
-
|
|
17194
|
-
|
|
17195
|
-
|
|
17196
|
-
|
|
17197
|
-
|
|
17175
|
+
if (runStatus === "interrupted" /* INTERRUPTED */) {
|
|
17176
|
+
this.publish("message:interrupted", {
|
|
17177
|
+
type: "message:interrupted",
|
|
17178
|
+
messageId: p.content.id,
|
|
17179
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
17180
|
+
duration: Date.now() - startTime,
|
|
17181
|
+
state
|
|
17182
|
+
});
|
|
17183
|
+
} else {
|
|
17184
|
+
this.addChunk({
|
|
17185
|
+
type: "message_completed",
|
|
17186
|
+
data: {
|
|
17187
|
+
id: p.content.id,
|
|
17188
|
+
content: ""
|
|
17189
|
+
}
|
|
17190
|
+
});
|
|
17191
|
+
this.publish("message:completed", {
|
|
17192
|
+
type: "message:completed",
|
|
17193
|
+
messageId: p.content.id,
|
|
17194
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
17195
|
+
duration: Date.now() - startTime,
|
|
17196
|
+
state
|
|
17197
|
+
});
|
|
17198
|
+
}
|
|
17198
17199
|
}
|
|
17199
17200
|
} catch (error) {
|
|
17200
17201
|
console.error(`COLLECT mode execution failed:`, error);
|
|
17201
17202
|
for (const p of remainingPendings) {
|
|
17203
|
+
this.addChunk({
|
|
17204
|
+
type: "message_failed",
|
|
17205
|
+
data: {
|
|
17206
|
+
id: p.content.id,
|
|
17207
|
+
content: error instanceof Error ? error.message : String(error)
|
|
17208
|
+
}
|
|
17209
|
+
});
|
|
17202
17210
|
this.publish("message:failed", {
|
|
17203
17211
|
type: "message:failed",
|
|
17204
17212
|
messageId: p.content.id,
|
|
@@ -17224,16 +17232,41 @@ var Agent = class {
|
|
|
17224
17232
|
try {
|
|
17225
17233
|
await this.agentStreamExecutor({ input: { messages: [message] } }, signal);
|
|
17226
17234
|
await this.queueStore?.markCompleted(p.id);
|
|
17235
|
+
const runStatus = await this.getRunStatus();
|
|
17227
17236
|
const state = await this.getCurrentState();
|
|
17228
|
-
|
|
17229
|
-
|
|
17230
|
-
|
|
17231
|
-
|
|
17232
|
-
|
|
17233
|
-
|
|
17234
|
-
|
|
17237
|
+
if (runStatus === "interrupted" /* INTERRUPTED */) {
|
|
17238
|
+
this.publish("message:interrupted", {
|
|
17239
|
+
type: "message:interrupted",
|
|
17240
|
+
messageId: p.content.id,
|
|
17241
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
17242
|
+
duration: Date.now() - startTime,
|
|
17243
|
+
state
|
|
17244
|
+
});
|
|
17245
|
+
} else {
|
|
17246
|
+
this.addChunk({
|
|
17247
|
+
type: "message_completed",
|
|
17248
|
+
data: {
|
|
17249
|
+
id: p.content.id,
|
|
17250
|
+
content: ""
|
|
17251
|
+
}
|
|
17252
|
+
});
|
|
17253
|
+
this.publish("message:completed", {
|
|
17254
|
+
type: "message:completed",
|
|
17255
|
+
messageId: p.content.id,
|
|
17256
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
17257
|
+
duration: Date.now() - startTime,
|
|
17258
|
+
state
|
|
17259
|
+
});
|
|
17260
|
+
}
|
|
17235
17261
|
} catch (error) {
|
|
17236
17262
|
console.error(`FOLLOWUP mode message ${p.id} execution failed:`, error);
|
|
17263
|
+
this.addChunk({
|
|
17264
|
+
type: "message_failed",
|
|
17265
|
+
data: {
|
|
17266
|
+
id: p.content.id,
|
|
17267
|
+
content: error instanceof Error ? error.message : String(error)
|
|
17268
|
+
}
|
|
17269
|
+
});
|
|
17237
17270
|
this.publish("message:failed", {
|
|
17238
17271
|
type: "message:failed",
|
|
17239
17272
|
messageId: p.content.id,
|
|
@@ -17263,11 +17296,12 @@ var Agent = class {
|
|
|
17263
17296
|
addChunk(content) {
|
|
17264
17297
|
return this.chunkBuffer.addChunk(this.thread_id, content);
|
|
17265
17298
|
}
|
|
17266
|
-
chunkStream(message_id,
|
|
17299
|
+
chunkStream(message_id, stopTypes) {
|
|
17267
17300
|
const stream = this.chunkBuffer.getNewChunksSinceContentIterator(
|
|
17268
17301
|
this.thread_id,
|
|
17269
17302
|
message_id,
|
|
17270
|
-
|
|
17303
|
+
"",
|
|
17304
|
+
stopTypes
|
|
17271
17305
|
);
|
|
17272
17306
|
return {
|
|
17273
17307
|
[Symbol.asyncIterator]: async function* () {
|
|
@@ -17540,6 +17574,7 @@ var Agent = class {
|
|
|
17540
17574
|
*/
|
|
17541
17575
|
publish(eventName, data) {
|
|
17542
17576
|
const namespacedEvent = `${eventName}:${this.tenant_id}:${this.thread_id}`;
|
|
17577
|
+
console.log(namespacedEvent);
|
|
17543
17578
|
event_bus_default.publish(namespacedEvent, data);
|
|
17544
17579
|
}
|
|
17545
17580
|
};
|