@axiom-lattice/core 10.0.3 → 10.0.4

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
@@ -39,6 +39,7 @@ import {
39
39
  import {
40
40
  BaseLanguageModel
41
41
  } from "@langchain/core/language_models/base";
42
+ import { ChatGenerationChunk } from "@langchain/core/outputs";
42
43
  var ModelLattice = class extends BaseChatModel {
43
44
  /**
44
45
  * 构造函数
@@ -93,11 +94,33 @@ var ModelLattice = class extends BaseChatModel {
93
94
  * @remarks BaseChatModel's streaming hook is `_streamResponseChunks`. Without
94
95
  * this override the wrapper falls back to `_generate`, losing streaming and
95
96
  * provider-level cancellation.
97
+ *
98
+ * The yielded value MUST be a `ChatGenerationChunk`. Calling
99
+ * `this.llm.stream()` yields bare messages, and LangChain reads
100
+ * `chunk.message.id` from whatever this hook yields — so returning messages
101
+ * throws `Cannot read properties of undefined (reading 'id')` whenever a
102
+ * streaming-preferring callback (for example LangGraph's message stream or
103
+ * the summarization middleware's inherited callbacks) routes `invoke`
104
+ * through this hook.
96
105
  */
97
106
  async *_streamResponseChunks(messages, options, runManager) {
98
- void runManager;
99
- const stream = await this.llm.stream(messages, options);
100
- for await (const chunk of stream) yield chunk;
107
+ const underlying = this.llm;
108
+ const streamResponseChunks = underlying._streamResponseChunks;
109
+ if (typeof streamResponseChunks === "function" && streamResponseChunks !== BaseChatModel.prototype._streamResponseChunks) {
110
+ yield* streamResponseChunks.call(underlying, messages, options, runManager);
111
+ return;
112
+ }
113
+ const stream = await underlying.stream(messages, options);
114
+ for await (const chunk of stream) {
115
+ if (chunk instanceof ChatGenerationChunk) {
116
+ yield chunk;
117
+ continue;
118
+ }
119
+ yield new ChatGenerationChunk({
120
+ message: chunk,
121
+ text: typeof chunk.content === "string" ? chunk.content : ""
122
+ });
123
+ }
101
124
  }
102
125
  /**
103
126
  * Whether the configured model supports vision/image inputs.
@@ -23166,6 +23189,7 @@ import {
23166
23189
  } from "@langchain/langgraph";
23167
23190
 
23168
23191
  // src/agent_worker/delegation_service.ts
23192
+ import { randomUUID as randomUUID10 } from "crypto";
23169
23193
  import { resolveRunScope } from "@axiom-lattice/protocols";
23170
23194
 
23171
23195
  // src/services/Agent.ts
@@ -29571,6 +29595,11 @@ var DELEGATION_LEASE_TTL_MS = (() => {
29571
29595
  const configured2 = Number(process.env.DELEGATION_LEASE_TTL_MS);
29572
29596
  return Number.isFinite(configured2) && configured2 > 0 ? configured2 : 6e4;
29573
29597
  })();
29598
+ function isOfficialResumeMap(value) {
29599
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
29600
+ const keys = Object.keys(value);
29601
+ return keys.length > 0 && keys.every((key5) => isOfficialInterruptId(key5));
29602
+ }
29574
29603
  var DelegatedThreadBusyError = class extends Error {
29575
29604
  constructor(threadId) {
29576
29605
  super(`Delegated thread ${threadId} is already running`);
@@ -29651,12 +29680,27 @@ var DelegationService = class {
29651
29680
  if (cancellation.signal.aborted) onCancel();
29652
29681
  else cancellation.signal.addEventListener("abort", onCancel, { once: true });
29653
29682
  }
29683
+ let command = request.command;
29684
+ if (command) {
29685
+ let state;
29686
+ try {
29687
+ state = await agent.getCurrentState();
29688
+ } catch {
29689
+ state = void 0;
29690
+ }
29691
+ const interrupts = state === void 0 ? [] : normalizeAgentInterrupts(state, request.thread_id);
29692
+ const sole = interrupts.length === 1 ? interrupts[0] : void 0;
29693
+ if (sole !== void 0 && isOfficialInterruptId(sole.interruptId) && !isOfficialResumeMap(command.resume)) {
29694
+ command = { ...command, resume: { [sole.interruptId]: command.resume } };
29695
+ }
29696
+ }
29654
29697
  try {
29655
- const invocation = agent.invokeWithState({
29656
- input: request.input,
29657
- command: request.command,
29658
- custom_run_config: request.runConfig
29659
- }, signal, { allowUnmanagedCommand: true });
29698
+ const invocation = agent.executeRun({
29699
+ runId: randomUUID10(),
29700
+ ...command ? { command } : { input: request.input },
29701
+ config: request.runConfig,
29702
+ signal
29703
+ });
29660
29704
  let rejectAborted;
29661
29705
  const onAbort = () => rejectAborted?.(new Error("Delegated child aborted"));
29662
29706
  const aborted = new Promise((_resolve, reject) => {
@@ -38663,7 +38707,7 @@ async function disconnectAllChannels(getAdapter) {
38663
38707
  }
38664
38708
 
38665
38709
  // src/channel/ChannelConnectionLeader.ts
38666
- import { createHash as createHash5, randomUUID as randomUUID10 } from "crypto";
38710
+ import { createHash as createHash5, randomUUID as randomUUID11 } from "crypto";
38667
38711
  var LEASE_KEY = "leader:channel-connections";
38668
38712
  function channelShardForInstallation(installationId, shardCount) {
38669
38713
  if (!Number.isSafeInteger(shardCount) || shardCount < 1) {
@@ -38811,7 +38855,7 @@ var ChannelConnectionLeader = class {
38811
38855
  await this.tryAcquire();
38812
38856
  }
38813
38857
  async tryAcquire() {
38814
- const holder = `${this.deps.owner}#${randomUUID10()}`;
38858
+ const holder = `${this.deps.owner}#${randomUUID11()}`;
38815
38859
  const acquired = await this.deps.leaseStore.tryAcquire(this.leaseKey, holder, this.ttlMs).catch((error) => {
38816
38860
  this.deps.log?.warn("Channel leader lease acquire failed", {
38817
38861
  error: error instanceof Error ? error.message : String(error)
@@ -40392,7 +40436,7 @@ function getCoordinationLeaseStore() {
40392
40436
  }
40393
40437
 
40394
40438
  // src/services/withLease.ts
40395
- import { randomUUID as randomUUID11 } from "crypto";
40439
+ import { randomUUID as randomUUID12 } from "crypto";
40396
40440
  var LeaseAcquisitionTimeoutError = class extends Error {
40397
40441
  /**
40398
40442
  * @param key Lease key that could not be acquired.
@@ -40417,7 +40461,7 @@ async function withLease(store2, key5, ownerLabel, fn, options = {}) {
40417
40461
  const acquireTimeoutMs = options.acquireTimeoutMs ?? 1e4;
40418
40462
  const retryDelayMs = options.retryDelayMs ?? 50;
40419
40463
  const heartbeatMs = options.heartbeatMs ?? Math.max(1e3, Math.floor(ttlMs / 3));
40420
- const holder = `${ownerLabel}#${randomUUID11()}`;
40464
+ const holder = `${ownerLabel}#${randomUUID12()}`;
40421
40465
  const deadline = Date.now() + acquireTimeoutMs;
40422
40466
  for (; ; ) {
40423
40467
  if (await store2.tryAcquire(key5, holder, ttlMs)) break;
@@ -40524,7 +40568,7 @@ function createTrustedAgentMessageDispatcher(resolve4) {
40524
40568
  }
40525
40569
 
40526
40570
  // src/services/RoomAgentMessageService.ts
40527
- import { randomUUID as randomUUID12 } from "crypto";
40571
+ import { randomUUID as randomUUID13 } from "crypto";
40528
40572
  import { snapshotExactArray, snapshotExactRecord as snapshotExactRecord5 } from "@axiom-lattice/protocols";
40529
40573
  var INPUT_KEYS = [
40530
40574
  "tenantId",
@@ -40614,7 +40658,7 @@ var RoomAgentMessageService = class {
40614
40658
  throw new Error("Invalid project room membership");
40615
40659
  }
40616
40660
  const candidate = {
40617
- id: (this.deps.idFactory ?? randomUUID12)(),
40661
+ id: (this.deps.idFactory ?? randomUUID13)(),
40618
40662
  tenantId: member.tenantId,
40619
40663
  workspaceId: member.workspaceId,
40620
40664
  projectId: member.projectId,
@@ -40657,7 +40701,7 @@ var RoomAgentMessageService = class {
40657
40701
  throw new Error("Invalid project room membership");
40658
40702
  }
40659
40703
  const candidate = {
40660
- id: (this.deps.idFactory ?? randomUUID12)(),
40704
+ id: (this.deps.idFactory ?? randomUUID13)(),
40661
40705
  tenantId: input.tenantId,
40662
40706
  workspaceId: input.workspaceId,
40663
40707
  projectId: input.projectId,
@@ -43549,7 +43593,7 @@ function createTaskLifecycleService(deps) {
43549
43593
  }
43550
43594
 
43551
43595
  // src/services/TaskExecutionService.ts
43552
- import { randomUUID as randomUUID14 } from "crypto";
43596
+ import { randomUUID as randomUUID15 } from "crypto";
43553
43597
  import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
43554
43598
  import { isExecutionResultEventKey as isExecutionResultEventKey2 } from "@axiom-lattice/protocols";
43555
43599
 
@@ -43905,13 +43949,13 @@ async function reconcileAllTenantTaskRuns(input) {
43905
43949
  }
43906
43950
 
43907
43951
  // src/services/taskRunLease.ts
43908
- import { randomUUID as randomUUID13 } from "crypto";
43952
+ import { randomUUID as randomUUID14 } from "crypto";
43909
43953
  function taskRunLeaseKey(taskId) {
43910
43954
  return `task-run:${taskId}`;
43911
43955
  }
43912
43956
  async function tryAcquireTaskRun(input) {
43913
43957
  const key5 = taskRunLeaseKey(input.taskId);
43914
- const holder = `${input.owner}#${randomUUID13()}`;
43958
+ const holder = `${input.owner}#${randomUUID14()}`;
43915
43959
  if (!await input.store.tryAcquire(key5, holder, input.ttlMs)) return null;
43916
43960
  const heartbeatMs = input.heartbeatMs ?? Math.max(1e3, Math.floor(input.ttlMs / 3));
43917
43961
  let released = false;
@@ -44331,11 +44375,11 @@ function createTaskExecutionService(deps) {
44331
44375
  let threadId;
44332
44376
  let runId;
44333
44377
  try {
44334
- threadId = storedThreadId ?? (deps.createThreadId ?? randomUUID14)();
44378
+ threadId = storedThreadId ?? (deps.createThreadId ?? randomUUID15)();
44335
44379
  if (task.status === "interrupted" && reuseCurrentRun) {
44336
44380
  runId = storedRunId;
44337
44381
  } else if (task.status === "interrupted" || task.status === "failed") {
44338
- runId = (deps.createRunId ?? randomUUID14)();
44382
+ runId = (deps.createRunId ?? randomUUID15)();
44339
44383
  }
44340
44384
  } catch (error) {
44341
44385
  return {
@@ -44615,11 +44659,11 @@ function createTaskExecutionService(deps) {
44615
44659
  }
44616
44660
 
44617
44661
  // src/services/leadership.ts
44618
- import { randomUUID as randomUUID15 } from "crypto";
44662
+ import { randomUUID as randomUUID16 } from "crypto";
44619
44663
  async function runAsLeader(store2, name, fn, options = {}) {
44620
44664
  const key5 = `leader:${name}`;
44621
44665
  const owner3 = options.owner ?? getReplicaId();
44622
- const holder = `${owner3}#${randomUUID15()}`;
44666
+ const holder = `${owner3}#${randomUUID16()}`;
44623
44667
  const ttlMs = options.ttlMs ?? 6e4;
44624
44668
  if (!await store2.tryAcquire(key5, holder, ttlMs)) return { ran: false };
44625
44669
  const heartbeat = setInterval(() => {