@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 +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +86 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
-
|
|
99
|
-
const
|
|
100
|
-
|
|
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
|
|
@@ -27850,6 +27874,13 @@ var Agent = class {
|
|
|
27850
27874
|
timestamp: /* @__PURE__ */ new Date(),
|
|
27851
27875
|
queueMode: this.queueMode.mode
|
|
27852
27876
|
});
|
|
27877
|
+
const abortDelegatedChildren = () => {
|
|
27878
|
+
delegationCancellationRegistry.abort(this.tenant_id, this.thread_id);
|
|
27879
|
+
};
|
|
27880
|
+
if (signal) {
|
|
27881
|
+
if (signal.aborted) abortDelegatedChildren();
|
|
27882
|
+
else signal.addEventListener("abort", abortDelegatedChildren, { once: true });
|
|
27883
|
+
}
|
|
27853
27884
|
try {
|
|
27854
27885
|
if (hasContinuation) {
|
|
27855
27886
|
const resumeConfig = effectiveCapabilityRevision === void 0 ? { ...config ?? {} } : { ...config ?? {}, capabilityRuntimeRevision: effectiveCapabilityRevision };
|
|
@@ -27880,6 +27911,8 @@ var Agent = class {
|
|
|
27880
27911
|
});
|
|
27881
27912
|
}
|
|
27882
27913
|
throw error;
|
|
27914
|
+
} finally {
|
|
27915
|
+
signal?.removeEventListener("abort", abortDelegatedChildren);
|
|
27883
27916
|
}
|
|
27884
27917
|
const state = await this.getCurrentState();
|
|
27885
27918
|
const runStatus = statusFromSnapshot(state);
|
|
@@ -29571,6 +29604,11 @@ var DELEGATION_LEASE_TTL_MS = (() => {
|
|
|
29571
29604
|
const configured2 = Number(process.env.DELEGATION_LEASE_TTL_MS);
|
|
29572
29605
|
return Number.isFinite(configured2) && configured2 > 0 ? configured2 : 6e4;
|
|
29573
29606
|
})();
|
|
29607
|
+
function isOfficialResumeMap(value) {
|
|
29608
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
|
|
29609
|
+
const keys = Object.keys(value);
|
|
29610
|
+
return keys.length > 0 && keys.every((key5) => isOfficialInterruptId(key5));
|
|
29611
|
+
}
|
|
29574
29612
|
var DelegatedThreadBusyError = class extends Error {
|
|
29575
29613
|
constructor(threadId) {
|
|
29576
29614
|
super(`Delegated thread ${threadId} is already running`);
|
|
@@ -29651,12 +29689,27 @@ var DelegationService = class {
|
|
|
29651
29689
|
if (cancellation.signal.aborted) onCancel();
|
|
29652
29690
|
else cancellation.signal.addEventListener("abort", onCancel, { once: true });
|
|
29653
29691
|
}
|
|
29692
|
+
let command = request.command;
|
|
29693
|
+
if (command) {
|
|
29694
|
+
let state;
|
|
29695
|
+
try {
|
|
29696
|
+
state = await agent.getCurrentState();
|
|
29697
|
+
} catch {
|
|
29698
|
+
state = void 0;
|
|
29699
|
+
}
|
|
29700
|
+
const interrupts = state === void 0 ? [] : normalizeAgentInterrupts(state, request.thread_id);
|
|
29701
|
+
const sole = interrupts.length === 1 ? interrupts[0] : void 0;
|
|
29702
|
+
if (sole !== void 0 && isOfficialInterruptId(sole.interruptId) && !isOfficialResumeMap(command.resume)) {
|
|
29703
|
+
command = { ...command, resume: { [sole.interruptId]: command.resume } };
|
|
29704
|
+
}
|
|
29705
|
+
}
|
|
29654
29706
|
try {
|
|
29655
|
-
const invocation = agent.
|
|
29656
|
-
|
|
29657
|
-
command: request.
|
|
29658
|
-
|
|
29659
|
-
|
|
29707
|
+
const invocation = agent.executeRun({
|
|
29708
|
+
runId: randomUUID10(),
|
|
29709
|
+
...command ? { command } : { input: request.input },
|
|
29710
|
+
config: request.runConfig,
|
|
29711
|
+
signal
|
|
29712
|
+
});
|
|
29660
29713
|
let rejectAborted;
|
|
29661
29714
|
const onAbort = () => rejectAborted?.(new Error("Delegated child aborted"));
|
|
29662
29715
|
const aborted = new Promise((_resolve, reject) => {
|
|
@@ -38663,7 +38716,7 @@ async function disconnectAllChannels(getAdapter) {
|
|
|
38663
38716
|
}
|
|
38664
38717
|
|
|
38665
38718
|
// src/channel/ChannelConnectionLeader.ts
|
|
38666
|
-
import { createHash as createHash5, randomUUID as
|
|
38719
|
+
import { createHash as createHash5, randomUUID as randomUUID11 } from "crypto";
|
|
38667
38720
|
var LEASE_KEY = "leader:channel-connections";
|
|
38668
38721
|
function channelShardForInstallation(installationId, shardCount) {
|
|
38669
38722
|
if (!Number.isSafeInteger(shardCount) || shardCount < 1) {
|
|
@@ -38811,7 +38864,7 @@ var ChannelConnectionLeader = class {
|
|
|
38811
38864
|
await this.tryAcquire();
|
|
38812
38865
|
}
|
|
38813
38866
|
async tryAcquire() {
|
|
38814
|
-
const holder = `${this.deps.owner}#${
|
|
38867
|
+
const holder = `${this.deps.owner}#${randomUUID11()}`;
|
|
38815
38868
|
const acquired = await this.deps.leaseStore.tryAcquire(this.leaseKey, holder, this.ttlMs).catch((error) => {
|
|
38816
38869
|
this.deps.log?.warn("Channel leader lease acquire failed", {
|
|
38817
38870
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -40392,7 +40445,7 @@ function getCoordinationLeaseStore() {
|
|
|
40392
40445
|
}
|
|
40393
40446
|
|
|
40394
40447
|
// src/services/withLease.ts
|
|
40395
|
-
import { randomUUID as
|
|
40448
|
+
import { randomUUID as randomUUID12 } from "crypto";
|
|
40396
40449
|
var LeaseAcquisitionTimeoutError = class extends Error {
|
|
40397
40450
|
/**
|
|
40398
40451
|
* @param key Lease key that could not be acquired.
|
|
@@ -40417,7 +40470,7 @@ async function withLease(store2, key5, ownerLabel, fn, options = {}) {
|
|
|
40417
40470
|
const acquireTimeoutMs = options.acquireTimeoutMs ?? 1e4;
|
|
40418
40471
|
const retryDelayMs = options.retryDelayMs ?? 50;
|
|
40419
40472
|
const heartbeatMs = options.heartbeatMs ?? Math.max(1e3, Math.floor(ttlMs / 3));
|
|
40420
|
-
const holder = `${ownerLabel}#${
|
|
40473
|
+
const holder = `${ownerLabel}#${randomUUID12()}`;
|
|
40421
40474
|
const deadline = Date.now() + acquireTimeoutMs;
|
|
40422
40475
|
for (; ; ) {
|
|
40423
40476
|
if (await store2.tryAcquire(key5, holder, ttlMs)) break;
|
|
@@ -40524,7 +40577,7 @@ function createTrustedAgentMessageDispatcher(resolve4) {
|
|
|
40524
40577
|
}
|
|
40525
40578
|
|
|
40526
40579
|
// src/services/RoomAgentMessageService.ts
|
|
40527
|
-
import { randomUUID as
|
|
40580
|
+
import { randomUUID as randomUUID13 } from "crypto";
|
|
40528
40581
|
import { snapshotExactArray, snapshotExactRecord as snapshotExactRecord5 } from "@axiom-lattice/protocols";
|
|
40529
40582
|
var INPUT_KEYS = [
|
|
40530
40583
|
"tenantId",
|
|
@@ -40614,7 +40667,7 @@ var RoomAgentMessageService = class {
|
|
|
40614
40667
|
throw new Error("Invalid project room membership");
|
|
40615
40668
|
}
|
|
40616
40669
|
const candidate = {
|
|
40617
|
-
id: (this.deps.idFactory ??
|
|
40670
|
+
id: (this.deps.idFactory ?? randomUUID13)(),
|
|
40618
40671
|
tenantId: member.tenantId,
|
|
40619
40672
|
workspaceId: member.workspaceId,
|
|
40620
40673
|
projectId: member.projectId,
|
|
@@ -40657,7 +40710,7 @@ var RoomAgentMessageService = class {
|
|
|
40657
40710
|
throw new Error("Invalid project room membership");
|
|
40658
40711
|
}
|
|
40659
40712
|
const candidate = {
|
|
40660
|
-
id: (this.deps.idFactory ??
|
|
40713
|
+
id: (this.deps.idFactory ?? randomUUID13)(),
|
|
40661
40714
|
tenantId: input.tenantId,
|
|
40662
40715
|
workspaceId: input.workspaceId,
|
|
40663
40716
|
projectId: input.projectId,
|
|
@@ -43549,7 +43602,7 @@ function createTaskLifecycleService(deps) {
|
|
|
43549
43602
|
}
|
|
43550
43603
|
|
|
43551
43604
|
// src/services/TaskExecutionService.ts
|
|
43552
|
-
import { randomUUID as
|
|
43605
|
+
import { randomUUID as randomUUID15 } from "crypto";
|
|
43553
43606
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "util";
|
|
43554
43607
|
import { isExecutionResultEventKey as isExecutionResultEventKey2 } from "@axiom-lattice/protocols";
|
|
43555
43608
|
|
|
@@ -43905,13 +43958,13 @@ async function reconcileAllTenantTaskRuns(input) {
|
|
|
43905
43958
|
}
|
|
43906
43959
|
|
|
43907
43960
|
// src/services/taskRunLease.ts
|
|
43908
|
-
import { randomUUID as
|
|
43961
|
+
import { randomUUID as randomUUID14 } from "crypto";
|
|
43909
43962
|
function taskRunLeaseKey(taskId) {
|
|
43910
43963
|
return `task-run:${taskId}`;
|
|
43911
43964
|
}
|
|
43912
43965
|
async function tryAcquireTaskRun(input) {
|
|
43913
43966
|
const key5 = taskRunLeaseKey(input.taskId);
|
|
43914
|
-
const holder = `${input.owner}#${
|
|
43967
|
+
const holder = `${input.owner}#${randomUUID14()}`;
|
|
43915
43968
|
if (!await input.store.tryAcquire(key5, holder, input.ttlMs)) return null;
|
|
43916
43969
|
const heartbeatMs = input.heartbeatMs ?? Math.max(1e3, Math.floor(input.ttlMs / 3));
|
|
43917
43970
|
let released = false;
|
|
@@ -44331,11 +44384,11 @@ function createTaskExecutionService(deps) {
|
|
|
44331
44384
|
let threadId;
|
|
44332
44385
|
let runId;
|
|
44333
44386
|
try {
|
|
44334
|
-
threadId = storedThreadId ?? (deps.createThreadId ??
|
|
44387
|
+
threadId = storedThreadId ?? (deps.createThreadId ?? randomUUID15)();
|
|
44335
44388
|
if (task.status === "interrupted" && reuseCurrentRun) {
|
|
44336
44389
|
runId = storedRunId;
|
|
44337
44390
|
} else if (task.status === "interrupted" || task.status === "failed") {
|
|
44338
|
-
runId = (deps.createRunId ??
|
|
44391
|
+
runId = (deps.createRunId ?? randomUUID15)();
|
|
44339
44392
|
}
|
|
44340
44393
|
} catch (error) {
|
|
44341
44394
|
return {
|
|
@@ -44615,11 +44668,11 @@ function createTaskExecutionService(deps) {
|
|
|
44615
44668
|
}
|
|
44616
44669
|
|
|
44617
44670
|
// src/services/leadership.ts
|
|
44618
|
-
import { randomUUID as
|
|
44671
|
+
import { randomUUID as randomUUID16 } from "crypto";
|
|
44619
44672
|
async function runAsLeader(store2, name, fn, options = {}) {
|
|
44620
44673
|
const key5 = `leader:${name}`;
|
|
44621
44674
|
const owner3 = options.owner ?? getReplicaId();
|
|
44622
|
-
const holder = `${owner3}#${
|
|
44675
|
+
const holder = `${owner3}#${randomUUID16()}`;
|
|
44623
44676
|
const ttlMs = options.ttlMs ?? 6e4;
|
|
44624
44677
|
if (!await store2.tryAcquire(key5, holder, ttlMs)) return { ran: false };
|
|
44625
44678
|
const heartbeat = setInterval(() => {
|