@axiom-lattice/core 10.0.3 → 10.0.5

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
@@ -29902,6 +29926,13 @@ var Agent = class {
29902
29926
  timestamp: /* @__PURE__ */ new Date(),
29903
29927
  queueMode: this.queueMode.mode
29904
29928
  });
29929
+ const abortDelegatedChildren = () => {
29930
+ delegationCancellationRegistry.abort(this.tenant_id, this.thread_id);
29931
+ };
29932
+ if (signal) {
29933
+ if (signal.aborted) abortDelegatedChildren();
29934
+ else signal.addEventListener("abort", abortDelegatedChildren, { once: true });
29935
+ }
29905
29936
  try {
29906
29937
  if (hasContinuation) {
29907
29938
  const resumeConfig = effectiveCapabilityRevision === void 0 ? { ...config ?? {} } : { ...config ?? {}, capabilityRuntimeRevision: effectiveCapabilityRevision };
@@ -29932,6 +29963,8 @@ var Agent = class {
29932
29963
  });
29933
29964
  }
29934
29965
  throw error;
29966
+ } finally {
29967
+ signal?.removeEventListener("abort", abortDelegatedChildren);
29935
29968
  }
29936
29969
  const state = await this.getCurrentState();
29937
29970
  const runStatus = statusFromSnapshot(state);
@@ -31623,6 +31656,11 @@ var DELEGATION_LEASE_TTL_MS = (() => {
31623
31656
  const configured2 = Number(process.env.DELEGATION_LEASE_TTL_MS);
31624
31657
  return Number.isFinite(configured2) && configured2 > 0 ? configured2 : 6e4;
31625
31658
  })();
31659
+ function isOfficialResumeMap(value) {
31660
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
31661
+ const keys = Object.keys(value);
31662
+ return keys.length > 0 && keys.every((key5) => isOfficialInterruptId(key5));
31663
+ }
31626
31664
  var DelegatedThreadBusyError = class extends Error {
31627
31665
  constructor(threadId) {
31628
31666
  super(`Delegated thread ${threadId} is already running`);
@@ -31703,12 +31741,27 @@ var DelegationService = class {
31703
31741
  if (cancellation.signal.aborted) onCancel();
31704
31742
  else cancellation.signal.addEventListener("abort", onCancel, { once: true });
31705
31743
  }
31744
+ let command = request.command;
31745
+ if (command) {
31746
+ let state;
31747
+ try {
31748
+ state = await agent.getCurrentState();
31749
+ } catch {
31750
+ state = void 0;
31751
+ }
31752
+ const interrupts = state === void 0 ? [] : normalizeAgentInterrupts(state, request.thread_id);
31753
+ const sole = interrupts.length === 1 ? interrupts[0] : void 0;
31754
+ if (sole !== void 0 && isOfficialInterruptId(sole.interruptId) && !isOfficialResumeMap(command.resume)) {
31755
+ command = { ...command, resume: { [sole.interruptId]: command.resume } };
31756
+ }
31757
+ }
31706
31758
  try {
31707
- const invocation = agent.invokeWithState({
31708
- input: request.input,
31709
- command: request.command,
31710
- custom_run_config: request.runConfig
31711
- }, signal, { allowUnmanagedCommand: true });
31759
+ const invocation = agent.executeRun({
31760
+ runId: (0, import_node_crypto8.randomUUID)(),
31761
+ ...command ? { command } : { input: request.input },
31762
+ config: request.runConfig,
31763
+ signal
31764
+ });
31712
31765
  let rejectAborted;
31713
31766
  const onAbort = () => rejectAborted?.(new Error("Delegated child aborted"));
31714
31767
  const aborted = new Promise((_resolve, reject) => {
@@ -38383,7 +38436,7 @@ function parseRecursiveGrepOutput(output) {
38383
38436
  }
38384
38437
 
38385
38438
  // src/sandbox_lattice/packDirectory.ts
38386
- var import_node_crypto8 = require("crypto");
38439
+ var import_node_crypto9 = require("crypto");
38387
38440
  var posix2 = __toESM(require("path/posix"));
38388
38441
  var MAX_PACK_ENTRIES = 1e4;
38389
38442
  var MAX_PACK_FILE_BYTES = 100 * 1024 * 1024;
@@ -38409,7 +38462,7 @@ function buildRemotePackDirectoryCommand(parentDir, sourceName, archiveName) {
38409
38462
  const parent = quotePosixShellArg(parentDir);
38410
38463
  const name = quotePosixShellArg(sourceName);
38411
38464
  const lock = quotePosixShellArg(`.${archiveName}.lock`);
38412
- const tempDir = quotePosixShellArg(`.${archiveName}.tmp-${(0, import_node_crypto8.randomBytes)(16).toString("hex")}`);
38465
+ const tempDir = quotePosixShellArg(`.${archiveName}.tmp-${(0, import_node_crypto9.randomBytes)(16).toString("hex")}`);
38413
38466
  const archivePath = joinPhysicalPath(parentDir, archiveName);
38414
38467
  const archive = quotePosixShellArg(archivePath);
38415
38468
  return [
@@ -39993,7 +40046,7 @@ var fs4 = __toESM(require("fs/promises"));
39993
40046
 
39994
40047
  // src/sandbox_lattice/LocalSandboxInstance.ts
39995
40048
  var import_node_child_process = require("child_process");
39996
- var import_node_crypto9 = require("crypto");
40049
+ var import_node_crypto10 = require("crypto");
39997
40050
  var fs3 = __toESM(require("fs/promises"));
39998
40051
  var path5 = __toESM(require("path"));
39999
40052
  var posix5 = __toESM(require("path/posix"));
@@ -40340,7 +40393,7 @@ ${errOut}`.trim() : out.trim();
40340
40393
  };
40341
40394
  await preflight(sourceHost);
40342
40395
  const lockName = `.${filename}.lock`;
40343
- const tempDirectoryName = `.${filename}.tmp-${(0, import_node_crypto9.randomBytes)(16).toString("hex")}`;
40396
+ const tempDirectoryName = `.${filename}.tmp-${(0, import_node_crypto10.randomBytes)(16).toString("hex")}`;
40344
40397
  const sourceOperand = `./${rootName}`;
40345
40398
  tempDirectoryHost = path5.join(realArchiveDirectory, tempDirectoryName);
40346
40399
  tempHost = path5.join(tempDirectoryHost, "archive.zip");
@@ -40720,14 +40773,14 @@ async function disconnectAllChannels(getAdapter) {
40720
40773
  }
40721
40774
 
40722
40775
  // src/channel/ChannelConnectionLeader.ts
40723
- var import_node_crypto10 = require("crypto");
40776
+ var import_node_crypto11 = require("crypto");
40724
40777
  var LEASE_KEY = "leader:channel-connections";
40725
40778
  function channelShardForInstallation(installationId, shardCount) {
40726
40779
  if (!Number.isSafeInteger(shardCount) || shardCount < 1) {
40727
40780
  throw new RangeError("shardCount must be a positive integer");
40728
40781
  }
40729
40782
  if (shardCount === 1) return 0;
40730
- return (0, import_node_crypto10.createHash)("sha256").update(installationId).digest().readUInt32BE(0) % shardCount;
40783
+ return (0, import_node_crypto11.createHash)("sha256").update(installationId).digest().readUInt32BE(0) % shardCount;
40731
40784
  }
40732
40785
  var ChannelConnectionLeader = class {
40733
40786
  constructor(deps) {
@@ -40868,7 +40921,7 @@ var ChannelConnectionLeader = class {
40868
40921
  await this.tryAcquire();
40869
40922
  }
40870
40923
  async tryAcquire() {
40871
- const holder = `${this.deps.owner}#${(0, import_node_crypto10.randomUUID)()}`;
40924
+ const holder = `${this.deps.owner}#${(0, import_node_crypto11.randomUUID)()}`;
40872
40925
  const acquired = await this.deps.leaseStore.tryAcquire(this.leaseKey, holder, this.ttlMs).catch((error) => {
40873
40926
  this.deps.log?.warn("Channel leader lease acquire failed", {
40874
40927
  error: error instanceof Error ? error.message : String(error)
@@ -42449,7 +42502,7 @@ function getCoordinationLeaseStore() {
42449
42502
  }
42450
42503
 
42451
42504
  // src/services/withLease.ts
42452
- var import_node_crypto11 = require("crypto");
42505
+ var import_node_crypto12 = require("crypto");
42453
42506
  var LeaseAcquisitionTimeoutError = class extends Error {
42454
42507
  /**
42455
42508
  * @param key Lease key that could not be acquired.
@@ -42474,7 +42527,7 @@ async function withLease(store2, key5, ownerLabel, fn, options = {}) {
42474
42527
  const acquireTimeoutMs = options.acquireTimeoutMs ?? 1e4;
42475
42528
  const retryDelayMs = options.retryDelayMs ?? 50;
42476
42529
  const heartbeatMs = options.heartbeatMs ?? Math.max(1e3, Math.floor(ttlMs / 3));
42477
- const holder = `${ownerLabel}#${(0, import_node_crypto11.randomUUID)()}`;
42530
+ const holder = `${ownerLabel}#${(0, import_node_crypto12.randomUUID)()}`;
42478
42531
  const deadline = Date.now() + acquireTimeoutMs;
42479
42532
  for (; ; ) {
42480
42533
  if (await store2.tryAcquire(key5, holder, ttlMs)) break;
@@ -43306,11 +43359,11 @@ function describe(error) {
43306
43359
  }
43307
43360
 
43308
43361
  // src/services/TaskLifecycleService.ts
43309
- var import_node_crypto13 = require("crypto");
43362
+ var import_node_crypto14 = require("crypto");
43310
43363
  var import_protocols40 = require("@axiom-lattice/protocols");
43311
43364
 
43312
43365
  // src/middlewares/taskBelief.ts
43313
- var import_node_crypto12 = require("crypto");
43366
+ var import_node_crypto13 = require("crypto");
43314
43367
  function buildBeliefCompletionEventKey(taskId, result, impacts) {
43315
43368
  const canonical = JSON.stringify({
43316
43369
  beliefImpact: impacts.map((impact) => ({
@@ -43321,7 +43374,7 @@ function buildBeliefCompletionEventKey(taskId, result, impacts) {
43321
43374
  })),
43322
43375
  result: result.trim()
43323
43376
  });
43324
- return (0, import_node_crypto12.createHash)("sha256").update(canonical).digest("hex");
43377
+ return (0, import_node_crypto13.createHash)("sha256").update(canonical).digest("hex");
43325
43378
  }
43326
43379
  function buildCompletionEvidenceDetail(result, impacts, eventKey) {
43327
43380
  return { result, beliefImpact: impacts, eventKey };
@@ -43524,7 +43577,7 @@ function canonicalJson(value) {
43524
43577
  return JSON.stringify(value);
43525
43578
  }
43526
43579
  function sha256(value) {
43527
- return (0, import_node_crypto13.createHash)("sha256").update(canonicalJson(value)).digest("hex");
43580
+ return (0, import_node_crypto14.createHash)("sha256").update(canonicalJson(value)).digest("hex");
43528
43581
  }
43529
43582
  function sameEvidenceDetail(detail, taskId, result, impacts, eventKey, beliefOwner) {
43530
43583
  const storedOwner = detail.beliefOwner;
@@ -45606,7 +45659,7 @@ function createTaskLifecycleService(deps) {
45606
45659
  }
45607
45660
 
45608
45661
  // src/services/TaskExecutionService.ts
45609
- var import_node_crypto15 = require("crypto");
45662
+ var import_node_crypto16 = require("crypto");
45610
45663
  var import_node_util3 = require("util");
45611
45664
  var import_protocols41 = require("@axiom-lattice/protocols");
45612
45665
 
@@ -45962,13 +46015,13 @@ async function reconcileAllTenantTaskRuns(input) {
45962
46015
  }
45963
46016
 
45964
46017
  // src/services/taskRunLease.ts
45965
- var import_node_crypto14 = require("crypto");
46018
+ var import_node_crypto15 = require("crypto");
45966
46019
  function taskRunLeaseKey(taskId) {
45967
46020
  return `task-run:${taskId}`;
45968
46021
  }
45969
46022
  async function tryAcquireTaskRun(input) {
45970
46023
  const key5 = taskRunLeaseKey(input.taskId);
45971
- const holder = `${input.owner}#${(0, import_node_crypto14.randomUUID)()}`;
46024
+ const holder = `${input.owner}#${(0, import_node_crypto15.randomUUID)()}`;
45972
46025
  if (!await input.store.tryAcquire(key5, holder, input.ttlMs)) return null;
45973
46026
  const heartbeatMs = input.heartbeatMs ?? Math.max(1e3, Math.floor(input.ttlMs / 3));
45974
46027
  let released = false;
@@ -46388,11 +46441,11 @@ function createTaskExecutionService(deps) {
46388
46441
  let threadId;
46389
46442
  let runId;
46390
46443
  try {
46391
- threadId = storedThreadId ?? (deps.createThreadId ?? import_node_crypto15.randomUUID)();
46444
+ threadId = storedThreadId ?? (deps.createThreadId ?? import_node_crypto16.randomUUID)();
46392
46445
  if (task.status === "interrupted" && reuseCurrentRun) {
46393
46446
  runId = storedRunId;
46394
46447
  } else if (task.status === "interrupted" || task.status === "failed") {
46395
- runId = (deps.createRunId ?? import_node_crypto15.randomUUID)();
46448
+ runId = (deps.createRunId ?? import_node_crypto16.randomUUID)();
46396
46449
  }
46397
46450
  } catch (error) {
46398
46451
  return {
@@ -46672,11 +46725,11 @@ function createTaskExecutionService(deps) {
46672
46725
  }
46673
46726
 
46674
46727
  // src/services/leadership.ts
46675
- var import_node_crypto16 = require("crypto");
46728
+ var import_node_crypto17 = require("crypto");
46676
46729
  async function runAsLeader(store2, name, fn, options = {}) {
46677
46730
  const key5 = `leader:${name}`;
46678
46731
  const owner3 = options.owner ?? getReplicaId();
46679
- const holder = `${owner3}#${(0, import_node_crypto16.randomUUID)()}`;
46732
+ const holder = `${owner3}#${(0, import_node_crypto17.randomUUID)()}`;
46680
46733
  const ttlMs = options.ttlMs ?? 6e4;
46681
46734
  if (!await store2.tryAcquire(key5, holder, ttlMs)) return { ran: false };
46682
46735
  const heartbeat = setInterval(() => {
@@ -55364,7 +55417,7 @@ function normalizeEnvelope(parsed) {
55364
55417
  }
55365
55418
 
55366
55419
  // src/sandbox_plugin/host/pluginHostSource.ts
55367
- var import_node_crypto17 = require("crypto");
55420
+ var import_node_crypto18 = require("crypto");
55368
55421
  var PLUGIN_HOST_VERSION = "1.1.0";
55369
55422
  var PLUGIN_HOST_SERVER_SOURCE = String.raw`#!/usr/bin/env node
55370
55423
  "use strict";
@@ -55659,7 +55712,7 @@ server.listen(config.port, "0.0.0.0", function () {
55659
55712
  });
55660
55713
  `;
55661
55714
  function pluginHostContentHash() {
55662
- return (0, import_node_crypto17.createHash)("sha256").update(`${PLUGIN_HOST_VERSION}:${PLUGIN_HOST_SERVER_SOURCE}`).digest("hex").slice(0, 16);
55715
+ return (0, import_node_crypto18.createHash)("sha256").update(`${PLUGIN_HOST_VERSION}:${PLUGIN_HOST_SERVER_SOURCE}`).digest("hex").slice(0, 16);
55663
55716
  }
55664
55717
 
55665
55718
  // src/sandbox_plugin/host/pluginHostInstaller.ts
@@ -56073,16 +56126,16 @@ var IdRemapper = class {
56073
56126
  };
56074
56127
 
56075
56128
  // src/util/directRoomId.ts
56076
- var import_node_crypto18 = require("crypto");
56129
+ var import_node_crypto19 = require("crypto");
56077
56130
  function generateDirectHumanProjectId(tenantId2, workspaceId, userId1, userId2) {
56078
56131
  const sortedUserIds = [userId1, userId2].sort();
56079
56132
  const parts = [tenantId2, workspaceId, ...sortedUserIds];
56080
- const hash = (0, import_node_crypto18.createHash)("sha256").update(parts.join(":")).digest("hex");
56133
+ const hash = (0, import_node_crypto19.createHash)("sha256").update(parts.join(":")).digest("hex");
56081
56134
  return `direct_human_${hash}`;
56082
56135
  }
56083
56136
  function generateDirectBotProjectId(tenantId2, workspaceId, userId, assistantId) {
56084
56137
  const parts = [tenantId2, workspaceId, userId, assistantId];
56085
- const hash = (0, import_node_crypto18.createHash)("sha256").update(parts.join(":")).digest("hex");
56138
+ const hash = (0, import_node_crypto19.createHash)("sha256").update(parts.join(":")).digest("hex");
56086
56139
  return `direct_bot_${hash}`;
56087
56140
  }
56088
56141
  function parseDirectRoomType(projectId) {