@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.d.mts CHANGED
@@ -213,6 +213,14 @@ declare class ModelLattice extends BaseChatModel {
213
213
  * @remarks BaseChatModel's streaming hook is `_streamResponseChunks`. Without
214
214
  * this override the wrapper falls back to `_generate`, losing streaming and
215
215
  * provider-level cancellation.
216
+ *
217
+ * The yielded value MUST be a `ChatGenerationChunk`. Calling
218
+ * `this.llm.stream()` yields bare messages, and LangChain reads
219
+ * `chunk.message.id` from whatever this hook yields — so returning messages
220
+ * throws `Cannot read properties of undefined (reading 'id')` whenever a
221
+ * streaming-preferring callback (for example LangGraph's message stream or
222
+ * the summarization middleware's inherited callbacks) routes `invoke`
223
+ * through this hook.
216
224
  */
217
225
  _streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
218
226
  /**
package/dist/index.d.ts CHANGED
@@ -213,6 +213,14 @@ declare class ModelLattice extends BaseChatModel {
213
213
  * @remarks BaseChatModel's streaming hook is `_streamResponseChunks`. Without
214
214
  * this override the wrapper falls back to `_generate`, losing streaming and
215
215
  * provider-level cancellation.
216
+ *
217
+ * The yielded value MUST be a `ChatGenerationChunk`. Calling
218
+ * `this.llm.stream()` yields bare messages, and LangChain reads
219
+ * `chunk.message.id` from whatever this hook yields — so returning messages
220
+ * throws `Cannot read properties of undefined (reading 'id')` whenever a
221
+ * streaming-preferring callback (for example LangGraph's message stream or
222
+ * the summarization middleware's inherited callbacks) routes `invoke`
223
+ * through this hook.
216
224
  */
217
225
  _streamResponseChunks(messages: BaseMessage[], options: this["ParsedCallOptions"], runManager?: CallbackManagerForLLMRun): AsyncGenerator<ChatGenerationChunk>;
218
226
  /**
package/dist/index.js CHANGED
@@ -2137,6 +2137,7 @@ var import_deepseek = require("@langchain/deepseek");
2137
2137
  var import_openai = require("@langchain/openai");
2138
2138
  var import_chat_models = require("@langchain/core/language_models/chat_models");
2139
2139
  var import_base = require("@langchain/core/language_models/base");
2140
+ var import_outputs = require("@langchain/core/outputs");
2140
2141
  var ModelLattice = class extends import_chat_models.BaseChatModel {
2141
2142
  /**
2142
2143
  * 构造函数
@@ -2191,11 +2192,33 @@ var ModelLattice = class extends import_chat_models.BaseChatModel {
2191
2192
  * @remarks BaseChatModel's streaming hook is `_streamResponseChunks`. Without
2192
2193
  * this override the wrapper falls back to `_generate`, losing streaming and
2193
2194
  * provider-level cancellation.
2195
+ *
2196
+ * The yielded value MUST be a `ChatGenerationChunk`. Calling
2197
+ * `this.llm.stream()` yields bare messages, and LangChain reads
2198
+ * `chunk.message.id` from whatever this hook yields — so returning messages
2199
+ * throws `Cannot read properties of undefined (reading 'id')` whenever a
2200
+ * streaming-preferring callback (for example LangGraph's message stream or
2201
+ * the summarization middleware's inherited callbacks) routes `invoke`
2202
+ * through this hook.
2194
2203
  */
2195
2204
  async *_streamResponseChunks(messages, options, runManager) {
2196
- void runManager;
2197
- const stream = await this.llm.stream(messages, options);
2198
- for await (const chunk2 of stream) yield chunk2;
2205
+ const underlying = this.llm;
2206
+ const streamResponseChunks = underlying._streamResponseChunks;
2207
+ if (typeof streamResponseChunks === "function" && streamResponseChunks !== import_chat_models.BaseChatModel.prototype._streamResponseChunks) {
2208
+ yield* streamResponseChunks.call(underlying, messages, options, runManager);
2209
+ return;
2210
+ }
2211
+ const stream = await underlying.stream(messages, options);
2212
+ for await (const chunk2 of stream) {
2213
+ if (chunk2 instanceof import_outputs.ChatGenerationChunk) {
2214
+ yield chunk2;
2215
+ continue;
2216
+ }
2217
+ yield new import_outputs.ChatGenerationChunk({
2218
+ message: chunk2,
2219
+ text: typeof chunk2.content === "string" ? chunk2.content : ""
2220
+ });
2221
+ }
2199
2222
  }
2200
2223
  /**
2201
2224
  * Whether the configured model supports vision/image inputs.
@@ -25221,6 +25244,7 @@ var import_langgraph7 = require("@langchain/langgraph");
25221
25244
  var import_langgraph6 = require("@langchain/langgraph");
25222
25245
 
25223
25246
  // src/agent_worker/delegation_service.ts
25247
+ var import_node_crypto8 = require("crypto");
25224
25248
  var import_protocols22 = require("@axiom-lattice/protocols");
25225
25249
 
25226
25250
  // src/services/Agent.ts
@@ -31623,6 +31647,11 @@ var DELEGATION_LEASE_TTL_MS = (() => {
31623
31647
  const configured2 = Number(process.env.DELEGATION_LEASE_TTL_MS);
31624
31648
  return Number.isFinite(configured2) && configured2 > 0 ? configured2 : 6e4;
31625
31649
  })();
31650
+ function isOfficialResumeMap(value) {
31651
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
31652
+ const keys = Object.keys(value);
31653
+ return keys.length > 0 && keys.every((key5) => isOfficialInterruptId(key5));
31654
+ }
31626
31655
  var DelegatedThreadBusyError = class extends Error {
31627
31656
  constructor(threadId) {
31628
31657
  super(`Delegated thread ${threadId} is already running`);
@@ -31703,12 +31732,27 @@ var DelegationService = class {
31703
31732
  if (cancellation.signal.aborted) onCancel();
31704
31733
  else cancellation.signal.addEventListener("abort", onCancel, { once: true });
31705
31734
  }
31735
+ let command = request.command;
31736
+ if (command) {
31737
+ let state;
31738
+ try {
31739
+ state = await agent.getCurrentState();
31740
+ } catch {
31741
+ state = void 0;
31742
+ }
31743
+ const interrupts = state === void 0 ? [] : normalizeAgentInterrupts(state, request.thread_id);
31744
+ const sole = interrupts.length === 1 ? interrupts[0] : void 0;
31745
+ if (sole !== void 0 && isOfficialInterruptId(sole.interruptId) && !isOfficialResumeMap(command.resume)) {
31746
+ command = { ...command, resume: { [sole.interruptId]: command.resume } };
31747
+ }
31748
+ }
31706
31749
  try {
31707
- const invocation = agent.invokeWithState({
31708
- input: request.input,
31709
- command: request.command,
31710
- custom_run_config: request.runConfig
31711
- }, signal, { allowUnmanagedCommand: true });
31750
+ const invocation = agent.executeRun({
31751
+ runId: (0, import_node_crypto8.randomUUID)(),
31752
+ ...command ? { command } : { input: request.input },
31753
+ config: request.runConfig,
31754
+ signal
31755
+ });
31712
31756
  let rejectAborted;
31713
31757
  const onAbort = () => rejectAborted?.(new Error("Delegated child aborted"));
31714
31758
  const aborted = new Promise((_resolve, reject) => {
@@ -38383,7 +38427,7 @@ function parseRecursiveGrepOutput(output) {
38383
38427
  }
38384
38428
 
38385
38429
  // src/sandbox_lattice/packDirectory.ts
38386
- var import_node_crypto8 = require("crypto");
38430
+ var import_node_crypto9 = require("crypto");
38387
38431
  var posix2 = __toESM(require("path/posix"));
38388
38432
  var MAX_PACK_ENTRIES = 1e4;
38389
38433
  var MAX_PACK_FILE_BYTES = 100 * 1024 * 1024;
@@ -38409,7 +38453,7 @@ function buildRemotePackDirectoryCommand(parentDir, sourceName, archiveName) {
38409
38453
  const parent = quotePosixShellArg(parentDir);
38410
38454
  const name = quotePosixShellArg(sourceName);
38411
38455
  const lock = quotePosixShellArg(`.${archiveName}.lock`);
38412
- const tempDir = quotePosixShellArg(`.${archiveName}.tmp-${(0, import_node_crypto8.randomBytes)(16).toString("hex")}`);
38456
+ const tempDir = quotePosixShellArg(`.${archiveName}.tmp-${(0, import_node_crypto9.randomBytes)(16).toString("hex")}`);
38413
38457
  const archivePath = joinPhysicalPath(parentDir, archiveName);
38414
38458
  const archive = quotePosixShellArg(archivePath);
38415
38459
  return [
@@ -39993,7 +40037,7 @@ var fs4 = __toESM(require("fs/promises"));
39993
40037
 
39994
40038
  // src/sandbox_lattice/LocalSandboxInstance.ts
39995
40039
  var import_node_child_process = require("child_process");
39996
- var import_node_crypto9 = require("crypto");
40040
+ var import_node_crypto10 = require("crypto");
39997
40041
  var fs3 = __toESM(require("fs/promises"));
39998
40042
  var path5 = __toESM(require("path"));
39999
40043
  var posix5 = __toESM(require("path/posix"));
@@ -40340,7 +40384,7 @@ ${errOut}`.trim() : out.trim();
40340
40384
  };
40341
40385
  await preflight(sourceHost);
40342
40386
  const lockName = `.${filename}.lock`;
40343
- const tempDirectoryName = `.${filename}.tmp-${(0, import_node_crypto9.randomBytes)(16).toString("hex")}`;
40387
+ const tempDirectoryName = `.${filename}.tmp-${(0, import_node_crypto10.randomBytes)(16).toString("hex")}`;
40344
40388
  const sourceOperand = `./${rootName}`;
40345
40389
  tempDirectoryHost = path5.join(realArchiveDirectory, tempDirectoryName);
40346
40390
  tempHost = path5.join(tempDirectoryHost, "archive.zip");
@@ -40720,14 +40764,14 @@ async function disconnectAllChannels(getAdapter) {
40720
40764
  }
40721
40765
 
40722
40766
  // src/channel/ChannelConnectionLeader.ts
40723
- var import_node_crypto10 = require("crypto");
40767
+ var import_node_crypto11 = require("crypto");
40724
40768
  var LEASE_KEY = "leader:channel-connections";
40725
40769
  function channelShardForInstallation(installationId, shardCount) {
40726
40770
  if (!Number.isSafeInteger(shardCount) || shardCount < 1) {
40727
40771
  throw new RangeError("shardCount must be a positive integer");
40728
40772
  }
40729
40773
  if (shardCount === 1) return 0;
40730
- return (0, import_node_crypto10.createHash)("sha256").update(installationId).digest().readUInt32BE(0) % shardCount;
40774
+ return (0, import_node_crypto11.createHash)("sha256").update(installationId).digest().readUInt32BE(0) % shardCount;
40731
40775
  }
40732
40776
  var ChannelConnectionLeader = class {
40733
40777
  constructor(deps) {
@@ -40868,7 +40912,7 @@ var ChannelConnectionLeader = class {
40868
40912
  await this.tryAcquire();
40869
40913
  }
40870
40914
  async tryAcquire() {
40871
- const holder = `${this.deps.owner}#${(0, import_node_crypto10.randomUUID)()}`;
40915
+ const holder = `${this.deps.owner}#${(0, import_node_crypto11.randomUUID)()}`;
40872
40916
  const acquired = await this.deps.leaseStore.tryAcquire(this.leaseKey, holder, this.ttlMs).catch((error) => {
40873
40917
  this.deps.log?.warn("Channel leader lease acquire failed", {
40874
40918
  error: error instanceof Error ? error.message : String(error)
@@ -42449,7 +42493,7 @@ function getCoordinationLeaseStore() {
42449
42493
  }
42450
42494
 
42451
42495
  // src/services/withLease.ts
42452
- var import_node_crypto11 = require("crypto");
42496
+ var import_node_crypto12 = require("crypto");
42453
42497
  var LeaseAcquisitionTimeoutError = class extends Error {
42454
42498
  /**
42455
42499
  * @param key Lease key that could not be acquired.
@@ -42474,7 +42518,7 @@ async function withLease(store2, key5, ownerLabel, fn, options = {}) {
42474
42518
  const acquireTimeoutMs = options.acquireTimeoutMs ?? 1e4;
42475
42519
  const retryDelayMs = options.retryDelayMs ?? 50;
42476
42520
  const heartbeatMs = options.heartbeatMs ?? Math.max(1e3, Math.floor(ttlMs / 3));
42477
- const holder = `${ownerLabel}#${(0, import_node_crypto11.randomUUID)()}`;
42521
+ const holder = `${ownerLabel}#${(0, import_node_crypto12.randomUUID)()}`;
42478
42522
  const deadline = Date.now() + acquireTimeoutMs;
42479
42523
  for (; ; ) {
42480
42524
  if (await store2.tryAcquire(key5, holder, ttlMs)) break;
@@ -43306,11 +43350,11 @@ function describe(error) {
43306
43350
  }
43307
43351
 
43308
43352
  // src/services/TaskLifecycleService.ts
43309
- var import_node_crypto13 = require("crypto");
43353
+ var import_node_crypto14 = require("crypto");
43310
43354
  var import_protocols40 = require("@axiom-lattice/protocols");
43311
43355
 
43312
43356
  // src/middlewares/taskBelief.ts
43313
- var import_node_crypto12 = require("crypto");
43357
+ var import_node_crypto13 = require("crypto");
43314
43358
  function buildBeliefCompletionEventKey(taskId, result, impacts) {
43315
43359
  const canonical = JSON.stringify({
43316
43360
  beliefImpact: impacts.map((impact) => ({
@@ -43321,7 +43365,7 @@ function buildBeliefCompletionEventKey(taskId, result, impacts) {
43321
43365
  })),
43322
43366
  result: result.trim()
43323
43367
  });
43324
- return (0, import_node_crypto12.createHash)("sha256").update(canonical).digest("hex");
43368
+ return (0, import_node_crypto13.createHash)("sha256").update(canonical).digest("hex");
43325
43369
  }
43326
43370
  function buildCompletionEvidenceDetail(result, impacts, eventKey) {
43327
43371
  return { result, beliefImpact: impacts, eventKey };
@@ -43524,7 +43568,7 @@ function canonicalJson(value) {
43524
43568
  return JSON.stringify(value);
43525
43569
  }
43526
43570
  function sha256(value) {
43527
- return (0, import_node_crypto13.createHash)("sha256").update(canonicalJson(value)).digest("hex");
43571
+ return (0, import_node_crypto14.createHash)("sha256").update(canonicalJson(value)).digest("hex");
43528
43572
  }
43529
43573
  function sameEvidenceDetail(detail, taskId, result, impacts, eventKey, beliefOwner) {
43530
43574
  const storedOwner = detail.beliefOwner;
@@ -45606,7 +45650,7 @@ function createTaskLifecycleService(deps) {
45606
45650
  }
45607
45651
 
45608
45652
  // src/services/TaskExecutionService.ts
45609
- var import_node_crypto15 = require("crypto");
45653
+ var import_node_crypto16 = require("crypto");
45610
45654
  var import_node_util3 = require("util");
45611
45655
  var import_protocols41 = require("@axiom-lattice/protocols");
45612
45656
 
@@ -45962,13 +46006,13 @@ async function reconcileAllTenantTaskRuns(input) {
45962
46006
  }
45963
46007
 
45964
46008
  // src/services/taskRunLease.ts
45965
- var import_node_crypto14 = require("crypto");
46009
+ var import_node_crypto15 = require("crypto");
45966
46010
  function taskRunLeaseKey(taskId) {
45967
46011
  return `task-run:${taskId}`;
45968
46012
  }
45969
46013
  async function tryAcquireTaskRun(input) {
45970
46014
  const key5 = taskRunLeaseKey(input.taskId);
45971
- const holder = `${input.owner}#${(0, import_node_crypto14.randomUUID)()}`;
46015
+ const holder = `${input.owner}#${(0, import_node_crypto15.randomUUID)()}`;
45972
46016
  if (!await input.store.tryAcquire(key5, holder, input.ttlMs)) return null;
45973
46017
  const heartbeatMs = input.heartbeatMs ?? Math.max(1e3, Math.floor(input.ttlMs / 3));
45974
46018
  let released = false;
@@ -46388,11 +46432,11 @@ function createTaskExecutionService(deps) {
46388
46432
  let threadId;
46389
46433
  let runId;
46390
46434
  try {
46391
- threadId = storedThreadId ?? (deps.createThreadId ?? import_node_crypto15.randomUUID)();
46435
+ threadId = storedThreadId ?? (deps.createThreadId ?? import_node_crypto16.randomUUID)();
46392
46436
  if (task.status === "interrupted" && reuseCurrentRun) {
46393
46437
  runId = storedRunId;
46394
46438
  } else if (task.status === "interrupted" || task.status === "failed") {
46395
- runId = (deps.createRunId ?? import_node_crypto15.randomUUID)();
46439
+ runId = (deps.createRunId ?? import_node_crypto16.randomUUID)();
46396
46440
  }
46397
46441
  } catch (error) {
46398
46442
  return {
@@ -46672,11 +46716,11 @@ function createTaskExecutionService(deps) {
46672
46716
  }
46673
46717
 
46674
46718
  // src/services/leadership.ts
46675
- var import_node_crypto16 = require("crypto");
46719
+ var import_node_crypto17 = require("crypto");
46676
46720
  async function runAsLeader(store2, name, fn, options = {}) {
46677
46721
  const key5 = `leader:${name}`;
46678
46722
  const owner3 = options.owner ?? getReplicaId();
46679
- const holder = `${owner3}#${(0, import_node_crypto16.randomUUID)()}`;
46723
+ const holder = `${owner3}#${(0, import_node_crypto17.randomUUID)()}`;
46680
46724
  const ttlMs = options.ttlMs ?? 6e4;
46681
46725
  if (!await store2.tryAcquire(key5, holder, ttlMs)) return { ran: false };
46682
46726
  const heartbeat = setInterval(() => {
@@ -55364,7 +55408,7 @@ function normalizeEnvelope(parsed) {
55364
55408
  }
55365
55409
 
55366
55410
  // src/sandbox_plugin/host/pluginHostSource.ts
55367
- var import_node_crypto17 = require("crypto");
55411
+ var import_node_crypto18 = require("crypto");
55368
55412
  var PLUGIN_HOST_VERSION = "1.1.0";
55369
55413
  var PLUGIN_HOST_SERVER_SOURCE = String.raw`#!/usr/bin/env node
55370
55414
  "use strict";
@@ -55659,7 +55703,7 @@ server.listen(config.port, "0.0.0.0", function () {
55659
55703
  });
55660
55704
  `;
55661
55705
  function pluginHostContentHash() {
55662
- return (0, import_node_crypto17.createHash)("sha256").update(`${PLUGIN_HOST_VERSION}:${PLUGIN_HOST_SERVER_SOURCE}`).digest("hex").slice(0, 16);
55706
+ return (0, import_node_crypto18.createHash)("sha256").update(`${PLUGIN_HOST_VERSION}:${PLUGIN_HOST_SERVER_SOURCE}`).digest("hex").slice(0, 16);
55663
55707
  }
55664
55708
 
55665
55709
  // src/sandbox_plugin/host/pluginHostInstaller.ts
@@ -56073,16 +56117,16 @@ var IdRemapper = class {
56073
56117
  };
56074
56118
 
56075
56119
  // src/util/directRoomId.ts
56076
- var import_node_crypto18 = require("crypto");
56120
+ var import_node_crypto19 = require("crypto");
56077
56121
  function generateDirectHumanProjectId(tenantId2, workspaceId, userId1, userId2) {
56078
56122
  const sortedUserIds = [userId1, userId2].sort();
56079
56123
  const parts = [tenantId2, workspaceId, ...sortedUserIds];
56080
- const hash = (0, import_node_crypto18.createHash)("sha256").update(parts.join(":")).digest("hex");
56124
+ const hash = (0, import_node_crypto19.createHash)("sha256").update(parts.join(":")).digest("hex");
56081
56125
  return `direct_human_${hash}`;
56082
56126
  }
56083
56127
  function generateDirectBotProjectId(tenantId2, workspaceId, userId, assistantId) {
56084
56128
  const parts = [tenantId2, workspaceId, userId, assistantId];
56085
- const hash = (0, import_node_crypto18.createHash)("sha256").update(parts.join(":")).digest("hex");
56129
+ const hash = (0, import_node_crypto19.createHash)("sha256").update(parts.join(":")).digest("hex");
56086
56130
  return `direct_bot_${hash}`;
56087
56131
  }
56088
56132
  function parseDirectRoomType(projectId) {