@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.mjs CHANGED
@@ -10788,13 +10788,13 @@ var StoreBackend = class {
10788
10788
  * @returns List of all items matching the search criteria
10789
10789
  */
10790
10790
  async searchStorePaginated(store, namespace, options = {}) {
10791
- const { query, filter, pageSize = 100 } = options;
10791
+ const { query, filter: filter2, pageSize = 100 } = options;
10792
10792
  const allItems = [];
10793
10793
  let offset = 0;
10794
10794
  while (true) {
10795
10795
  const pageItems = await store.search(namespace, {
10796
10796
  query,
10797
- filter,
10797
+ filter: filter2,
10798
10798
  limit: pageSize,
10799
10799
  offset
10800
10800
  });
@@ -12103,17 +12103,11 @@ ${BASE_PROMPT}` : BASE_PROMPT;
12103
12103
  todoListMiddleware(),
12104
12104
  // Enables filesystem operations and optional long-term memory storage
12105
12105
  createFilesystemMiddleware({ backend: filesystemBackend }),
12106
- createClawMiddleware({
12107
- backend: filesystemBackend
12108
- }),
12109
12106
  // Enables delegation to specialized subagents for complex tasks
12110
12107
  createSubAgentMiddleware({
12111
12108
  defaultModel: model,
12112
12109
  defaultTools: tools,
12113
12110
  defaultMiddleware: [
12114
- createClawMiddleware({
12115
- backend: filesystemBackend
12116
- }),
12117
12111
  // Subagent middleware: Todo list management
12118
12112
  todoListMiddleware(),
12119
12113
  // Subagent middleware: Filesystem operations
@@ -14474,11 +14468,14 @@ var ChunkBuffer = class {
14474
14468
  };
14475
14469
 
14476
14470
  // src/chunk_buffer_lattice/InMemoryChunkBuffer.ts
14471
+ import { MessageChunkTypes } from "@axiom-lattice/protocols";
14477
14472
  import {
14478
14473
  ReplaySubject,
14479
14474
  observeOn,
14480
14475
  asyncScheduler
14481
14476
  } from "rxjs";
14477
+ import { eachValueFrom } from "rxjs-for-await";
14478
+ import { filter, takeWhile } from "rxjs/operators";
14482
14479
  var InMemoryChunkBuffer = class extends ChunkBuffer {
14483
14480
  constructor(config) {
14484
14481
  super();
@@ -14563,7 +14560,7 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
14563
14560
  let chunk;
14564
14561
  if (typeof arg2 === "string" && arg3 !== void 0) {
14565
14562
  chunk = {
14566
- type: "message_chunk",
14563
+ type: MessageChunkTypes.AI,
14567
14564
  data: {
14568
14565
  id: arg2,
14569
14566
  content: arg3
@@ -14677,76 +14674,27 @@ var InMemoryChunkBuffer = class extends ChunkBuffer {
14677
14674
  buffer2.updatedAt = Date.now();
14678
14675
  }
14679
14676
  }
14680
- async *getNewChunksSinceContentIterator(threadId, messageId, knownContent) {
14677
+ async *getNewChunksSinceContentIterator(threadId, messageId, knownContent, stopTypes) {
14681
14678
  const buffer2 = this.getBufferIfValid(threadId);
14682
14679
  if (!buffer2) return;
14683
- let accumulatedContent = "";
14684
- const queue = [];
14685
- let resolveNext = null;
14686
- let errorNext = null;
14687
- let isCompleted = false;
14688
- let pendingError = null;
14689
- const subscription = buffer2.chunks$.pipe(observeOn(asyncScheduler)).subscribe({
14690
- next: (chunk) => {
14691
- queue.push(chunk);
14692
- if (resolveNext) {
14693
- const resolve3 = resolveNext;
14694
- resolveNext = null;
14695
- resolve3();
14696
- }
14697
- },
14698
- error: (err) => {
14699
- pendingError = err;
14700
- if (errorNext) {
14701
- const reject = errorNext;
14702
- errorNext = null;
14703
- reject(err);
14704
- } else if (resolveNext) {
14705
- const resolve3 = resolveNext;
14706
- resolveNext = null;
14707
- resolve3();
14708
- }
14709
- },
14710
- complete: () => {
14711
- isCompleted = true;
14712
- if (resolveNext) {
14713
- const resolve3 = resolveNext;
14714
- resolveNext = null;
14715
- resolve3();
14716
- }
14717
- }
14718
- });
14680
+ const defaultStopTypes = [
14681
+ MessageChunkTypes.MESSAGE_COMPLETED,
14682
+ MessageChunkTypes.THREAD_IDLE
14683
+ ];
14684
+ const typesToStop = stopTypes ?? defaultStopTypes;
14719
14685
  let startYieldChunk = false;
14720
- try {
14721
- while (true) {
14722
- if (pendingError) {
14723
- throw pendingError;
14724
- }
14725
- if (queue.length === 0) {
14726
- if (isCompleted) break;
14727
- await new Promise((resolve3, reject) => {
14728
- resolveNext = resolve3;
14729
- errorNext = reject;
14730
- });
14731
- }
14732
- if (pendingError) {
14733
- throw pendingError;
14734
- }
14735
- while (queue.length > 0) {
14736
- const chunk = queue.shift();
14737
- if (!chunk) continue;
14738
- if (chunk.data?.id === messageId) {
14739
- startYieldChunk = true;
14740
- accumulatedContent += chunk.data?.content || "";
14741
- }
14742
- if (startYieldChunk) {
14743
- yield chunk;
14744
- }
14745
- }
14746
- }
14747
- } finally {
14748
- subscription.unsubscribe();
14749
- }
14686
+ console.log("start from messageId", messageId);
14687
+ const filtered$ = buffer2.chunks$.pipe(
14688
+ observeOn(asyncScheduler),
14689
+ // 1. 从指定 messageId 开始
14690
+ filter((chunk) => {
14691
+ if (chunk.data?.id === messageId) startYieldChunk = true;
14692
+ return startYieldChunk;
14693
+ }),
14694
+ // 2. 包含指定的停止类型,但收到后停止
14695
+ takeWhile((chunk) => !typesToStop.includes(chunk.type), true)
14696
+ );
14697
+ yield* eachValueFrom(filtered$);
14750
14698
  }
14751
14699
  getStats() {
14752
14700
  let activeCount = 0;
@@ -16824,6 +16772,7 @@ var Agent = class {
16824
16772
  this.chunkBuffer = getChunkBuffer("default");
16825
16773
  this.abortController = null;
16826
16774
  this.queueMode = this.getDefaultQueueConfig();
16775
+ this.isWaitingForQueueEnd = false;
16827
16776
  this.agentExecutor = async ({ input, command, custom_run_config }, signal) => {
16828
16777
  const { runnable_agent, runConfig } = await this.getLatticeClientAndRuntimeConfig(custom_run_config);
16829
16778
  const { messages, ...rest } = input;
@@ -16951,9 +16900,7 @@ var Agent = class {
16951
16900
  };
16952
16901
  }
16953
16902
  if (data) {
16954
- if (data.type !== "interrupt") {
16955
- await lifecycleManager.addChunk(data);
16956
- }
16903
+ lifecycleManager.addChunk(data);
16957
16904
  }
16958
16905
  }
16959
16906
  } catch (error) {
@@ -16970,8 +16917,8 @@ var Agent = class {
16970
16917
  while (!signal?.aborted) {
16971
16918
  const pendings = await this.getPendingMessages();
16972
16919
  if (pendings.length === 0) {
16973
- await this.chunkBuffer.completeThread(this.thread_id);
16974
16920
  const state = await this.getCurrentState();
16921
+ const runStatus = await this.getRunStatus();
16975
16922
  const pendingCount = await this.getQueueStore().getQueueSize(this.thread_id);
16976
16923
  this.publish("thread:idle", {
16977
16924
  type: "thread:idle",
@@ -16979,6 +16926,15 @@ var Agent = class {
16979
16926
  pendingCount,
16980
16927
  state
16981
16928
  });
16929
+ if (runStatus === "idle" /* IDLE */) {
16930
+ this.addChunk({
16931
+ type: "thread_idle",
16932
+ data: {
16933
+ id: this.thread_id,
16934
+ content: ""
16935
+ }
16936
+ });
16937
+ }
16982
16938
  break;
16983
16939
  }
16984
16940
  const firstMessage = pendings[0];
@@ -16997,22 +16953,49 @@ var Agent = class {
16997
16953
  queueMode: this.queueMode.mode
16998
16954
  });
16999
16955
  const input = {
17000
- messages: [new HumanMessage2({ id: p.content.id, content: p.content.message })],
17001
- command: p.content.command
16956
+ messages: [new HumanMessage2({ id: p.content.id, content: p.content.message })]
17002
16957
  };
17003
16958
  try {
17004
- await this.agentStreamExecutor({ input }, signal);
16959
+ await this.agentStreamExecutor({
16960
+ input,
16961
+ command: p.content.command
16962
+ }, signal);
17005
16963
  await this.queueStore?.markCompleted(p.id);
16964
+ const runStatus = await this.getRunStatus();
17006
16965
  const state = await this.getCurrentState();
17007
- this.publish("message:completed", {
17008
- type: "message:completed",
17009
- messageId: p.content.id,
17010
- timestamp: /* @__PURE__ */ new Date(),
17011
- duration: Date.now() - startTime,
17012
- state
17013
- });
16966
+ if (runStatus === "interrupted" /* INTERRUPTED */) {
16967
+ this.publish("message:interrupted", {
16968
+ type: "message:interrupted",
16969
+ messageId: p.content.id,
16970
+ timestamp: /* @__PURE__ */ new Date(),
16971
+ duration: Date.now() - startTime,
16972
+ state
16973
+ });
16974
+ } else {
16975
+ this.addChunk({
16976
+ type: "message_completed",
16977
+ data: {
16978
+ id: p.content.id,
16979
+ content: ""
16980
+ }
16981
+ });
16982
+ this.publish("message:completed", {
16983
+ type: "message:completed",
16984
+ messageId: p.content.id,
16985
+ timestamp: /* @__PURE__ */ new Date(),
16986
+ duration: Date.now() - startTime,
16987
+ state
16988
+ });
16989
+ }
17014
16990
  } catch (error) {
17015
16991
  console.error(`STEER/Command message ${p.id} execution failed:`, error);
16992
+ this.addChunk({
16993
+ type: "message_failed",
16994
+ data: {
16995
+ id: p.content.id,
16996
+ content: error instanceof Error ? error.message : String(error)
16997
+ }
16998
+ });
17016
16999
  this.publish("message:failed", {
17017
17000
  type: "message:failed",
17018
17001
  messageId: p.content.id,
@@ -17041,20 +17024,45 @@ var Agent = class {
17041
17024
  });
17042
17025
  try {
17043
17026
  await this.agentStreamExecutor({ input: { messages: userMessages } }, signal);
17027
+ const runStatus = await this.getRunStatus();
17044
17028
  const state = await this.getCurrentState();
17045
17029
  for (const p of remainingPendings) {
17046
17030
  await this.queueStore?.markCompleted(p.id);
17047
- this.publish("message:completed", {
17048
- type: "message:completed",
17049
- messageId: p.content.id,
17050
- timestamp: /* @__PURE__ */ new Date(),
17051
- duration: Date.now() - startTime,
17052
- state
17053
- });
17031
+ if (runStatus === "interrupted" /* INTERRUPTED */) {
17032
+ this.publish("message:interrupted", {
17033
+ type: "message:interrupted",
17034
+ messageId: p.content.id,
17035
+ timestamp: /* @__PURE__ */ new Date(),
17036
+ duration: Date.now() - startTime,
17037
+ state
17038
+ });
17039
+ } else {
17040
+ this.addChunk({
17041
+ type: "message_completed",
17042
+ data: {
17043
+ id: p.content.id,
17044
+ content: ""
17045
+ }
17046
+ });
17047
+ this.publish("message:completed", {
17048
+ type: "message:completed",
17049
+ messageId: p.content.id,
17050
+ timestamp: /* @__PURE__ */ new Date(),
17051
+ duration: Date.now() - startTime,
17052
+ state
17053
+ });
17054
+ }
17054
17055
  }
17055
17056
  } catch (error) {
17056
17057
  console.error(`COLLECT mode execution failed:`, error);
17057
17058
  for (const p of remainingPendings) {
17059
+ this.addChunk({
17060
+ type: "message_failed",
17061
+ data: {
17062
+ id: p.content.id,
17063
+ content: error instanceof Error ? error.message : String(error)
17064
+ }
17065
+ });
17058
17066
  this.publish("message:failed", {
17059
17067
  type: "message:failed",
17060
17068
  messageId: p.content.id,
@@ -17080,16 +17088,41 @@ var Agent = class {
17080
17088
  try {
17081
17089
  await this.agentStreamExecutor({ input: { messages: [message] } }, signal);
17082
17090
  await this.queueStore?.markCompleted(p.id);
17091
+ const runStatus = await this.getRunStatus();
17083
17092
  const state = await this.getCurrentState();
17084
- this.publish("message:completed", {
17085
- type: "message:completed",
17086
- messageId: p.content.id,
17087
- timestamp: /* @__PURE__ */ new Date(),
17088
- duration: Date.now() - startTime,
17089
- state
17090
- });
17093
+ if (runStatus === "interrupted" /* INTERRUPTED */) {
17094
+ this.publish("message:interrupted", {
17095
+ type: "message:interrupted",
17096
+ messageId: p.content.id,
17097
+ timestamp: /* @__PURE__ */ new Date(),
17098
+ duration: Date.now() - startTime,
17099
+ state
17100
+ });
17101
+ } else {
17102
+ this.addChunk({
17103
+ type: "message_completed",
17104
+ data: {
17105
+ id: p.content.id,
17106
+ content: ""
17107
+ }
17108
+ });
17109
+ this.publish("message:completed", {
17110
+ type: "message:completed",
17111
+ messageId: p.content.id,
17112
+ timestamp: /* @__PURE__ */ new Date(),
17113
+ duration: Date.now() - startTime,
17114
+ state
17115
+ });
17116
+ }
17091
17117
  } catch (error) {
17092
17118
  console.error(`FOLLOWUP mode message ${p.id} execution failed:`, error);
17119
+ this.addChunk({
17120
+ type: "message_failed",
17121
+ data: {
17122
+ id: p.content.id,
17123
+ content: error instanceof Error ? error.message : String(error)
17124
+ }
17125
+ });
17093
17126
  this.publish("message:failed", {
17094
17127
  type: "message:failed",
17095
17128
  messageId: p.content.id,
@@ -17119,11 +17152,12 @@ var Agent = class {
17119
17152
  addChunk(content) {
17120
17153
  return this.chunkBuffer.addChunk(this.thread_id, content);
17121
17154
  }
17122
- chunkStream(message_id, known_content = "") {
17155
+ chunkStream(message_id, stopTypes) {
17123
17156
  const stream = this.chunkBuffer.getNewChunksSinceContentIterator(
17124
17157
  this.thread_id,
17125
17158
  message_id,
17126
- known_content
17159
+ "",
17160
+ stopTypes
17127
17161
  );
17128
17162
  return {
17129
17163
  [Symbol.asyncIterator]: async function* () {
@@ -17396,6 +17430,7 @@ var Agent = class {
17396
17430
  */
17397
17431
  publish(eventName, data) {
17398
17432
  const namespacedEvent = `${eventName}:${this.tenant_id}:${this.thread_id}`;
17433
+ console.log(namespacedEvent);
17399
17434
  event_bus_default.publish(namespacedEvent, data);
17400
17435
  }
17401
17436
  };