@linnlabs/linnkit 0.33.0 → 0.35.0
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/CHANGELOG.md +25 -0
- package/dist/cli.cjs +155 -28
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +155 -28
- package/dist/cli.js.map +1 -1
- package/dist/context-manager.cjs +54 -0
- package/dist/context-manager.cjs.map +1 -1
- package/dist/context-manager.js +54 -0
- package/dist/context-manager.js.map +1 -1
- package/dist/index.cjs +175 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +175 -43
- package/dist/index.js.map +1 -1
- package/dist/quickstart.cjs +155 -28
- package/dist/quickstart.cjs.map +1 -1
- package/dist/quickstart.js +155 -28
- package/dist/quickstart.js.map +1 -1
- package/dist/runtime-kernel/child-runs/childRunInvoker.d.cts +5 -0
- package/dist/runtime-kernel/child-runs/childRunInvoker.d.ts +5 -0
- package/dist/runtime-kernel/graph-engine/functions/parseEngineCheckpoint.d.cts +6 -0
- package/dist/runtime-kernel/graph-engine/functions/parseEngineCheckpoint.d.ts +6 -0
- package/dist/runtime-kernel/graph-engine/index.d.cts +1 -0
- package/dist/runtime-kernel/graph-engine/index.d.ts +1 -0
- package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.cts +22 -4
- package/dist/runtime-kernel/run-supervisor/definitions/runSupervisorContracts.d.ts +22 -4
- package/dist/runtime-kernel/run-supervisor/index.d.cts +1 -1
- package/dist/runtime-kernel/run-supervisor/index.d.ts +1 -1
- package/dist/runtime-kernel/run-supervisor/runSupervisor.d.cts +2 -1
- package/dist/runtime-kernel/run-supervisor/runSupervisor.d.ts +2 -1
- package/dist/runtime-kernel.cjs +172 -40
- package/dist/runtime-kernel.cjs.map +1 -1
- package/dist/runtime-kernel.d.cts +1 -0
- package/dist/runtime-kernel.d.ts +1 -0
- package/dist/runtime-kernel.js +172 -41
- package/dist/runtime-kernel.js.map +1 -1
- package/dist/testkit.cjs +172 -40
- package/dist/testkit.cjs.map +1 -1
- package/dist/testkit.js +172 -40
- package/dist/testkit.js.map +1 -1
- package/docs/integration/child-runs.md +8 -0
- package/docs/integration/persistence.md +1 -0
- package/docs/integration/run-supervisor.md +3 -0
- package/package.json +2 -2
|
@@ -101,6 +101,7 @@ export { evaluateModelInputCompatibility, listCompatibleModelIds } from './runti
|
|
|
101
101
|
export { isRuntimeFailureFact } from './runtime-kernel/graph-engine/functions/runtimeFailureFact.cjs';
|
|
102
102
|
export { noopAudit } from './runtime-kernel/audit/noopAudit.cjs';
|
|
103
103
|
export { normalizeToolArgs } from './runtime-kernel/tools/argNormalizer.cjs';
|
|
104
|
+
export { parseEngineCheckpoint } from './runtime-kernel/graph-engine/functions/parseEngineCheckpoint.cjs';
|
|
104
105
|
export { projectChildRuntimeEventToSubRunTrace } from './runtime-kernel/child-run-trace/projectChildRuntimeEventToSubRunTrace.cjs';
|
|
105
106
|
export { readCheckpointContextUsage } from './runtime-kernel/graph-engine/functions/engineStateSnapshot.cjs';
|
|
106
107
|
export { requestEnricherRegistry } from './runtime-kernel/enrichment/registry.cjs';
|
package/dist/runtime-kernel.d.ts
CHANGED
|
@@ -101,6 +101,7 @@ export { evaluateModelInputCompatibility, listCompatibleModelIds } from './runti
|
|
|
101
101
|
export { isRuntimeFailureFact } from './runtime-kernel/graph-engine/functions/runtimeFailureFact.js';
|
|
102
102
|
export { noopAudit } from './runtime-kernel/audit/noopAudit.js';
|
|
103
103
|
export { normalizeToolArgs } from './runtime-kernel/tools/argNormalizer.js';
|
|
104
|
+
export { parseEngineCheckpoint } from './runtime-kernel/graph-engine/functions/parseEngineCheckpoint.js';
|
|
104
105
|
export { projectChildRuntimeEventToSubRunTrace } from './runtime-kernel/child-run-trace/projectChildRuntimeEventToSubRunTrace.js';
|
|
105
106
|
export { readCheckpointContextUsage } from './runtime-kernel/graph-engine/functions/engineStateSnapshot.js';
|
|
106
107
|
export { requestEnricherRegistry } from './runtime-kernel/enrichment/registry.js';
|
package/dist/runtime-kernel.js
CHANGED
|
@@ -34,6 +34,7 @@ __export(graph_engine_exports, {
|
|
|
34
34
|
evaluatePrimaryPromptCapacity: () => evaluatePrimaryPromptCapacity,
|
|
35
35
|
isRunPauseSignal: () => isRunPauseSignal,
|
|
36
36
|
isRuntimeFailureFact: () => isRuntimeFailureFact,
|
|
37
|
+
parseEngineCheckpoint: () => parseEngineCheckpoint,
|
|
37
38
|
readCheckpointContextUsage: () => readCheckpointContextUsage,
|
|
38
39
|
requireEventStoreId: () => requireEventStoreId,
|
|
39
40
|
resolveEffectivePromptBudget: () => resolveEffectivePromptBudget,
|
|
@@ -3155,23 +3156,23 @@ var GraphExecutor = class {
|
|
|
3155
3156
|
};
|
|
3156
3157
|
}
|
|
3157
3158
|
async saveCheckpoint(checkpointKey, state) {
|
|
3158
|
-
const
|
|
3159
|
+
const checkpoint2 = this.sanitize({
|
|
3159
3160
|
...state,
|
|
3160
3161
|
revision: (state.revision ?? 0) + 1
|
|
3161
3162
|
});
|
|
3162
|
-
await this.commitCheckpoint(checkpointKey,
|
|
3163
|
-
return
|
|
3163
|
+
await this.commitCheckpoint(checkpointKey, checkpoint2);
|
|
3164
|
+
return checkpoint2;
|
|
3164
3165
|
}
|
|
3165
|
-
async commitCheckpoint(checkpointKey,
|
|
3166
|
+
async commitCheckpoint(checkpointKey, checkpoint2) {
|
|
3166
3167
|
if (this.executionCheckpointPort) {
|
|
3167
|
-
await this.executionCheckpointPort.commit(checkpointKey,
|
|
3168
|
+
await this.executionCheckpointPort.commit(checkpointKey, checkpoint2);
|
|
3168
3169
|
} else {
|
|
3169
|
-
await this.checkpointer.save(checkpointKey,
|
|
3170
|
+
await this.checkpointer.save(checkpointKey, checkpoint2);
|
|
3170
3171
|
}
|
|
3171
3172
|
}
|
|
3172
3173
|
async saveCheckpointAndBuildResult(checkpointKey, state, events, stepCount) {
|
|
3173
|
-
const
|
|
3174
|
-
return { events, checkpoint, stepCount };
|
|
3174
|
+
const checkpoint2 = await this.saveCheckpoint(checkpointKey, state);
|
|
3175
|
+
return { events, checkpoint: checkpoint2, stepCount };
|
|
3175
3176
|
}
|
|
3176
3177
|
async runUntilYieldInternal(checkpointKey, initialState, reportStepsUsed, maxSteps) {
|
|
3177
3178
|
let state = initialState;
|
|
@@ -9298,16 +9299,16 @@ function requireEventStoreId(eventStoreId) {
|
|
|
9298
9299
|
}
|
|
9299
9300
|
function createMonotonicEventStoreIdFactory(nowProvider = () => Date.now()) {
|
|
9300
9301
|
let lastTimestamp = 0;
|
|
9301
|
-
let
|
|
9302
|
+
let counter2 = 0;
|
|
9302
9303
|
return () => {
|
|
9303
9304
|
const timestamp = Math.max(nowProvider(), lastTimestamp);
|
|
9304
9305
|
if (timestamp === lastTimestamp) {
|
|
9305
|
-
|
|
9306
|
+
counter2 += 1;
|
|
9306
9307
|
} else {
|
|
9307
9308
|
lastTimestamp = timestamp;
|
|
9308
|
-
|
|
9309
|
+
counter2 = 0;
|
|
9309
9310
|
}
|
|
9310
|
-
return `${String(timestamp).padStart(13, "0")}-${String(
|
|
9311
|
+
return `${String(timestamp).padStart(13, "0")}-${String(counter2).padStart(4, "0")}`;
|
|
9311
9312
|
};
|
|
9312
9313
|
}
|
|
9313
9314
|
|
|
@@ -9719,6 +9720,76 @@ function assertNonNegativeSafeInteger(value, field) {
|
|
|
9719
9720
|
throw new Error(`${field} \u5FC5\u987B\u662F\u975E\u8D1F\u5B89\u5168\u6574\u6570\u3002`);
|
|
9720
9721
|
}
|
|
9721
9722
|
}
|
|
9723
|
+
var counter = z.number().int().nonnegative();
|
|
9724
|
+
var executor = z.object({
|
|
9725
|
+
stepCount: counter,
|
|
9726
|
+
phase: z.string().optional(),
|
|
9727
|
+
maxSteps: counter.optional(),
|
|
9728
|
+
remainingSteps: z.number().int().optional(),
|
|
9729
|
+
finalStepPolicy: z.enum(["final_answer", "force_tools"]).optional(),
|
|
9730
|
+
finalStepForcedTools: z.array(z.string()).optional(),
|
|
9731
|
+
lastStepsHintThreshold: counter.optional(),
|
|
9732
|
+
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
9733
|
+
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9734
|
+
runLockedModelId: z.string().optional(),
|
|
9735
|
+
lastSuccessfulLlmModelId: z.string().optional(),
|
|
9736
|
+
llmInvocationKind: z.enum(["user_initiated", "continuation"]).optional(),
|
|
9737
|
+
llmInvocationCount: counter.optional(),
|
|
9738
|
+
lockRequestedModelId: z.boolean().optional(),
|
|
9739
|
+
contextCompaction: z.object({
|
|
9740
|
+
attemptCount: counter,
|
|
9741
|
+
committedCount: counter,
|
|
9742
|
+
lastCommittedFingerprint: z.string().optional()
|
|
9743
|
+
}).strict().optional()
|
|
9744
|
+
}).strict();
|
|
9745
|
+
var checkpoint = z.object({
|
|
9746
|
+
nodeId: z.string().min(1),
|
|
9747
|
+
schemaVersion: z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
9748
|
+
revision: counter.optional(),
|
|
9749
|
+
executionStatus: z.enum(["ready", "executing", "yielded", "awaiting_user"]).optional(),
|
|
9750
|
+
local: z.object({
|
|
9751
|
+
runId: RunIdSchema.optional(),
|
|
9752
|
+
parentRunId: RunIdSchema.optional(),
|
|
9753
|
+
conversationId: z.string().optional(),
|
|
9754
|
+
turnId: z.string().optional(),
|
|
9755
|
+
request: SerializableJsonRecord.optional(),
|
|
9756
|
+
history: z.array(RuntimeEvent).optional(),
|
|
9757
|
+
newEvents: z.array(RuntimeEvent).optional(),
|
|
9758
|
+
executorLocal: executor.optional(),
|
|
9759
|
+
pendingToolCalls: z.array(z.object({
|
|
9760
|
+
id: ToolCallIdSchema,
|
|
9761
|
+
type: z.literal("function"),
|
|
9762
|
+
function: z.object({ name: z.string().min(1), arguments: z.string() }).strict()
|
|
9763
|
+
}).strict()).optional(),
|
|
9764
|
+
executingToolCallId: ToolCallIdSchema.optional(),
|
|
9765
|
+
toolBatchCompletionMode: z.enum(["continue_to_llm", "yield_after_batch"]).optional(),
|
|
9766
|
+
pendingInteractionSpec: SerializableJsonRecord.optional(),
|
|
9767
|
+
lastToolResult: SerializableJsonRecord.optional(),
|
|
9768
|
+
finalAnswer: z.string().optional(),
|
|
9769
|
+
answerId: z.string().optional(),
|
|
9770
|
+
chunkSeq: counter.optional(),
|
|
9771
|
+
contextUsage: ContextUsageSnapshot.optional()
|
|
9772
|
+
}).passthrough().optional()
|
|
9773
|
+
}).strict();
|
|
9774
|
+
function parseEngineCheckpoint(value) {
|
|
9775
|
+
const result = checkpoint.parse(SerializableJsonRecord.parse(value));
|
|
9776
|
+
for (const key of [
|
|
9777
|
+
"memory",
|
|
9778
|
+
"signal",
|
|
9779
|
+
"toolContext",
|
|
9780
|
+
"runtimeEventSink",
|
|
9781
|
+
"runtimeEventCommitPort",
|
|
9782
|
+
"runtimeFailureFactSink",
|
|
9783
|
+
"summarizationCallbacks",
|
|
9784
|
+
"commitExecutionBoundary",
|
|
9785
|
+
"toolRecoveryPort"
|
|
9786
|
+
]) {
|
|
9787
|
+
if (result.local && Object.hasOwn(result.local, key)) {
|
|
9788
|
+
throw new Error(`Checkpoint must not contain execution capability: ${key}`);
|
|
9789
|
+
}
|
|
9790
|
+
}
|
|
9791
|
+
return result;
|
|
9792
|
+
}
|
|
9722
9793
|
|
|
9723
9794
|
// src/runtime-kernel/tools/index.ts
|
|
9724
9795
|
var tools_exports = {};
|
|
@@ -10180,14 +10251,14 @@ var EventBusEventPersistence = class {
|
|
|
10180
10251
|
checkpointWritesActive;
|
|
10181
10252
|
checkpointEvents = [];
|
|
10182
10253
|
/** Graph 的执行边界复用同一有序队列;没有第二条事件写入链。 */
|
|
10183
|
-
async commitCheckpoint(checkpointKey,
|
|
10254
|
+
async commitCheckpoint(checkpointKey, checkpoint2) {
|
|
10184
10255
|
const writer = this.options.checkpointWriter;
|
|
10185
10256
|
if (!writer || !this.checkpointWritesActive) throw new Error("Checkpoint writer is not active");
|
|
10186
10257
|
const events = this.checkpointEvents;
|
|
10187
10258
|
this.checkpointEvents = [];
|
|
10188
10259
|
await this.enqueueWrite(() => writer({
|
|
10189
10260
|
checkpointKey,
|
|
10190
|
-
checkpoint,
|
|
10261
|
+
checkpoint: checkpoint2,
|
|
10191
10262
|
events: events.map((event) => ({ event, eventStoreId: this.options.nextEventStoreId() }))
|
|
10192
10263
|
}));
|
|
10193
10264
|
}
|
|
@@ -11880,15 +11951,15 @@ function hasSeedHistoryPrefix(history, seedHistory) {
|
|
|
11880
11951
|
}
|
|
11881
11952
|
return true;
|
|
11882
11953
|
}
|
|
11883
|
-
function readCheckpointHistory(
|
|
11884
|
-
if (!
|
|
11885
|
-
const history =
|
|
11954
|
+
function readCheckpointHistory(checkpoint2) {
|
|
11955
|
+
if (!checkpoint2?.local) return [];
|
|
11956
|
+
const history = checkpoint2.local.history;
|
|
11886
11957
|
if (!Array.isArray(history)) return [];
|
|
11887
11958
|
return parseRuntimeEvents(history);
|
|
11888
11959
|
}
|
|
11889
11960
|
async function recoverChildRunEventsFromCheckpoint(params) {
|
|
11890
|
-
const
|
|
11891
|
-
const history = readCheckpointHistory(
|
|
11961
|
+
const checkpoint2 = await params.checkpointer.load(params.checkpointKey);
|
|
11962
|
+
const history = readCheckpointHistory(checkpoint2);
|
|
11892
11963
|
if (history.length === 0) {
|
|
11893
11964
|
return [];
|
|
11894
11965
|
}
|
|
@@ -11934,10 +12005,10 @@ var ChildRunInvoker = class {
|
|
|
11934
12005
|
runtimeEventSink,
|
|
11935
12006
|
runtimeEventCommitPort,
|
|
11936
12007
|
seedHistoryEvents,
|
|
11937
|
-
maxSteps = 8,
|
|
11938
12008
|
modelId,
|
|
11939
12009
|
abortSignal
|
|
11940
12010
|
} = config;
|
|
12011
|
+
const maxSteps = config.initialInput?.request.maxSteps ?? config.maxSteps ?? 8;
|
|
11941
12012
|
const childRunId = runId ?? generateRunId();
|
|
11942
12013
|
const internalCheckpointKey = childRunId;
|
|
11943
12014
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
@@ -11982,7 +12053,8 @@ var ChildRunInvoker = class {
|
|
|
11982
12053
|
if (config.persistence?.expectedRevision !== void 0) {
|
|
11983
12054
|
return this.continueChild(config, childRunId, runtimeConversationId);
|
|
11984
12055
|
}
|
|
11985
|
-
const turnId = generateTurnId();
|
|
12056
|
+
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
12057
|
+
if (config.initialInput && (!turnId.trim() || config.initialInput.request.query !== userMessage || config.initialInput.request.promptKey !== agentConfig.promptKey || !config.initialInput.request.model_id)) throw new Error("Child initial input does not match the admitted invocation");
|
|
11986
12058
|
logger17.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
11987
12059
|
conversationId: runtimeConversationId,
|
|
11988
12060
|
checkpointKey: internalCheckpointKey,
|
|
@@ -11999,11 +12071,14 @@ var ChildRunInvoker = class {
|
|
|
11999
12071
|
});
|
|
12000
12072
|
const admittedChildUserInput = runtimeEventSink(childUserInput, "ChildRunInvoker.user_input");
|
|
12001
12073
|
const childModelId = resolveChildRunModelId({
|
|
12002
|
-
explicitModelId: modelId,
|
|
12074
|
+
explicitModelId: config.initialInput?.request.model_id ?? modelId,
|
|
12003
12075
|
agentConfig,
|
|
12004
12076
|
resolveDefaultModelId: () => this.modelResolver.resolveModelId()
|
|
12005
12077
|
});
|
|
12006
|
-
const request = {
|
|
12078
|
+
const request = config.initialInput ? {
|
|
12079
|
+
...config.initialInput.request,
|
|
12080
|
+
currentUserEventId: admittedChildUserInput.id
|
|
12081
|
+
} : {
|
|
12007
12082
|
query: userMessage,
|
|
12008
12083
|
currentUserEventId: admittedChildUserInput.id,
|
|
12009
12084
|
promptKey: agentConfig.promptKey,
|
|
@@ -12184,9 +12259,9 @@ var ChildRunInvoker = class {
|
|
|
12184
12259
|
async continueChild(config, runId, conversationId) {
|
|
12185
12260
|
const persistence = config.persistence;
|
|
12186
12261
|
if (!persistence || persistence.expectedRevision === void 0) throw new Error("Missing child continuation contract");
|
|
12187
|
-
const
|
|
12188
|
-
if (!
|
|
12189
|
-
const local = readGraphAgentLocal({ ...
|
|
12262
|
+
const checkpoint2 = await persistence.checkpointer.load(runId);
|
|
12263
|
+
if (!checkpoint2 || checkpoint2.local?.conversationId !== conversationId) throw new Error("Child checkpoint identity mismatch");
|
|
12264
|
+
const local = readGraphAgentLocal({ ...checkpoint2.local, runtimeEventSink: config.runtimeEventSink });
|
|
12190
12265
|
const request = local.request;
|
|
12191
12266
|
if (!request || !local.turnId || !request.model_id) throw new Error("Child recovery input is incomplete");
|
|
12192
12267
|
const context = createChildRunToolContext({
|
|
@@ -13463,7 +13538,15 @@ function createRunConcurrencyKeyRegistry() {
|
|
|
13463
13538
|
runIdByKey.delete(concurrencyKey);
|
|
13464
13539
|
}
|
|
13465
13540
|
}
|
|
13466
|
-
|
|
13541
|
+
function transfer(previous, next, concurrencyKey) {
|
|
13542
|
+
if (runIdByKey.get(concurrencyKey) !== previous || keyByRunId.has(next)) {
|
|
13543
|
+
throw new RunConcurrencyKeyOccupiedError(concurrencyKey, runIdByKey.get(concurrencyKey) ?? previous, next);
|
|
13544
|
+
}
|
|
13545
|
+
keyByRunId.delete(previous);
|
|
13546
|
+
keyByRunId.set(next, concurrencyKey);
|
|
13547
|
+
runIdByKey.set(concurrencyKey, next);
|
|
13548
|
+
}
|
|
13549
|
+
return { acquire, release, transfer };
|
|
13467
13550
|
}
|
|
13468
13551
|
|
|
13469
13552
|
// src/runtime-kernel/run-supervisor/functions/runRegistration.ts
|
|
@@ -13712,6 +13795,9 @@ var DefaultRunSupervisor = class {
|
|
|
13712
13795
|
});
|
|
13713
13796
|
}
|
|
13714
13797
|
async registerRun(spec) {
|
|
13798
|
+
if (spec.replacesPausedRun) {
|
|
13799
|
+
return this.withRunControlLock(spec.replacesPausedRun.runId, () => this.registerPausedReplacement(spec));
|
|
13800
|
+
}
|
|
13715
13801
|
const runId = spec.runId ?? this.runIdFactory();
|
|
13716
13802
|
if (this.handles.has(runId) || await this.registryStore.load(runId)) {
|
|
13717
13803
|
throw new RunAlreadyRegisteredError(runId);
|
|
@@ -13722,13 +13808,51 @@ var DefaultRunSupervisor = class {
|
|
|
13722
13808
|
forwardParentAbortSignal(controller, spec.parentSignal);
|
|
13723
13809
|
const record = createInitialRunRecord({ runId, spec, startedAt });
|
|
13724
13810
|
try {
|
|
13725
|
-
await
|
|
13811
|
+
if (spec.admissionCommit) await spec.admissionCommit(record);
|
|
13812
|
+
else await this.registryStore.save(record);
|
|
13726
13813
|
} catch (error) {
|
|
13727
13814
|
this.releaseRunAdmission(runId);
|
|
13728
13815
|
throw error;
|
|
13729
13816
|
}
|
|
13730
13817
|
return this.attachRun(record, spec, controller);
|
|
13731
13818
|
}
|
|
13819
|
+
async registerPausedReplacement(spec) {
|
|
13820
|
+
const target = spec.replacesPausedRun;
|
|
13821
|
+
if (!target || !spec.concurrencyKey || !spec.admissionCommit || !this.registryStore.compareAndSwap) {
|
|
13822
|
+
throw new Error("Paused replacement requires concurrency identity and atomic admissionCommit");
|
|
13823
|
+
}
|
|
13824
|
+
this.getHandle(target.runId);
|
|
13825
|
+
const previous = await this.registryStore.load(target.runId);
|
|
13826
|
+
if (!previous || previous.status !== "paused" || previous.pausedAt === void 0 || previous.updatedAt !== target.expectedUpdatedAt || previous.metadata?.executionId !== target.expectedExecutionId || previous.conversationId !== spec.conversationId || previous.parentRunId !== spec.parentRunId) {
|
|
13827
|
+
throw new RunInteractionConflictError(target.runId, "replacement does not match the settled pause");
|
|
13828
|
+
}
|
|
13829
|
+
const runId = spec.runId ?? this.runIdFactory();
|
|
13830
|
+
if (this.handles.has(runId) || await this.registryStore.load(runId)) throw new RunAlreadyRegisteredError(runId);
|
|
13831
|
+
this.runConcurrencyKeys.transfer(previous.runId, runId, spec.concurrencyKey);
|
|
13832
|
+
this.runSlotLimiter.release(previous.runId);
|
|
13833
|
+
this.runSlotLimiter.acquire(runId);
|
|
13834
|
+
const now = this.now();
|
|
13835
|
+
const record = createInitialRunRecord({ runId, spec, startedAt: now });
|
|
13836
|
+
const next = {
|
|
13837
|
+
...previous,
|
|
13838
|
+
status: "cancelled",
|
|
13839
|
+
updatedAt: now,
|
|
13840
|
+
errorIfAny: { errorCode: "RUN_REPLACED", message: "Replaced by a newly accepted request", recoverable: false }
|
|
13841
|
+
};
|
|
13842
|
+
try {
|
|
13843
|
+
await spec.admissionCommit(record, { previous, next });
|
|
13844
|
+
} catch (error) {
|
|
13845
|
+
this.runSlotLimiter.release(runId);
|
|
13846
|
+
this.runSlotLimiter.acquire(previous.runId);
|
|
13847
|
+
this.runConcurrencyKeys.transfer(runId, previous.runId, spec.concurrencyKey);
|
|
13848
|
+
throw error;
|
|
13849
|
+
}
|
|
13850
|
+
this.cleanupRunResources(previous.runId);
|
|
13851
|
+
this.notifyTerminalWaiters(previous.runId);
|
|
13852
|
+
const controller = new AbortController();
|
|
13853
|
+
forwardParentAbortSignal(controller, spec.parentSignal);
|
|
13854
|
+
return this.attachRun(record, spec, controller);
|
|
13855
|
+
}
|
|
13732
13856
|
async restoreRun(spec) {
|
|
13733
13857
|
if (!this.registryStore.compareAndSwap) throw new Error("Run restoration requires atomic registry transitions");
|
|
13734
13858
|
return this.withRunControlLock(spec.runId, async () => {
|
|
@@ -13852,7 +13976,7 @@ var DefaultRunSupervisor = class {
|
|
|
13852
13976
|
return this.withRunControlLock(input.runId, async () => {
|
|
13853
13977
|
const handle = this.getHandle(input.runId);
|
|
13854
13978
|
const record = await this.registryStore.load(input.runId);
|
|
13855
|
-
if (!record || record.status !== "paused" || record.pausedAt === void 0 || record.updatedAt !== input.expectedUpdatedAt) {
|
|
13979
|
+
if (!record || record.status !== "paused" || record.pausedAt === void 0 || record.updatedAt !== input.expectedUpdatedAt || input.expectedExecutionId !== void 0 && record.metadata?.executionId !== input.expectedExecutionId) {
|
|
13856
13980
|
throw new RunInteractionConflictError(input.runId, "run is not settled at the expected pause");
|
|
13857
13981
|
}
|
|
13858
13982
|
await persistRunTransition(this.registryStore, record, {
|
|
@@ -13865,6 +13989,7 @@ var DefaultRunSupervisor = class {
|
|
|
13865
13989
|
metadata: { ...record.metadata, executionId: input.executionId }
|
|
13866
13990
|
});
|
|
13867
13991
|
const controller = new AbortController();
|
|
13992
|
+
forwardParentAbortSignal(controller, input.parentSignal);
|
|
13868
13993
|
handle.replaceExecutionAbortController(controller, input.executionId);
|
|
13869
13994
|
handle.attachTransportEventBus(input.eventBus);
|
|
13870
13995
|
this.controllers.set(input.runId, controller);
|
|
@@ -13993,7 +14118,7 @@ var DefaultRunSupervisor = class {
|
|
|
13993
14118
|
}
|
|
13994
14119
|
const awaitingUserWithoutClaim = { ...awaitingUser };
|
|
13995
14120
|
Reflect.deleteProperty(awaitingUserWithoutClaim, "resumeClaim");
|
|
13996
|
-
|
|
14121
|
+
const nextRecord = {
|
|
13997
14122
|
...record,
|
|
13998
14123
|
status: "running",
|
|
13999
14124
|
updatedAt: this.now(),
|
|
@@ -14003,6 +14128,10 @@ var DefaultRunSupervisor = class {
|
|
|
14003
14128
|
metadata: {
|
|
14004
14129
|
...record.metadata ?? {},
|
|
14005
14130
|
...execution ? { executionId: execution.executionId } : {},
|
|
14131
|
+
...execution?.inputEventIds ? { resumeInputs: {
|
|
14132
|
+
eventIds: [...execution.inputEventIds],
|
|
14133
|
+
checkpointRevision: pendingInteraction.checkpointRevision
|
|
14134
|
+
} } : {},
|
|
14006
14135
|
awaitingUser: {
|
|
14007
14136
|
...awaitingUserWithoutClaim,
|
|
14008
14137
|
interaction: {
|
|
@@ -14011,7 +14140,9 @@ var DefaultRunSupervisor = class {
|
|
|
14011
14140
|
}
|
|
14012
14141
|
}
|
|
14013
14142
|
}
|
|
14014
|
-
}
|
|
14143
|
+
};
|
|
14144
|
+
if (execution?.admissionCommit) await execution.admissionCommit(record, nextRecord);
|
|
14145
|
+
else await persistRunTransition(this.registryStore, record, nextRecord);
|
|
14015
14146
|
const executionController = new AbortController();
|
|
14016
14147
|
forwardParentAbortSignal(executionController, parentSignal);
|
|
14017
14148
|
handle.replaceExecutionAbortController(executionController, execution?.executionId ?? (typeof record.metadata?.executionId === "string" ? record.metadata.executionId : void 0));
|
|
@@ -14177,13 +14308,13 @@ __export(system_reminder_exports, {
|
|
|
14177
14308
|
|
|
14178
14309
|
// src/runtime-kernel/testkit/defaultGraphExecutor.ts
|
|
14179
14310
|
function createDefaultGraphExecutor(options) {
|
|
14180
|
-
const
|
|
14311
|
+
const executor2 = new GraphExecutor(
|
|
14181
14312
|
options.checkpointer ?? new MemoryCheckpointer(),
|
|
14182
14313
|
{ maxSteps: options.maxSteps ?? 8 }
|
|
14183
14314
|
);
|
|
14184
|
-
|
|
14185
|
-
|
|
14186
|
-
|
|
14315
|
+
executor2.registerNode(new UserNode());
|
|
14316
|
+
executor2.registerNode(options.llmNode);
|
|
14317
|
+
executor2.registerNode(new ToolNode({
|
|
14187
14318
|
toolRuntime: options.toolRuntime,
|
|
14188
14319
|
observationPreview: options.observationPreview,
|
|
14189
14320
|
auditPort: options.auditPort,
|
|
@@ -14191,8 +14322,8 @@ function createDefaultGraphExecutor(options) {
|
|
|
14191
14322
|
modelInputCapabilityValidator: options.modelInputCapabilityValidator,
|
|
14192
14323
|
modelInputResolver: options.modelInputResolver
|
|
14193
14324
|
}));
|
|
14194
|
-
|
|
14195
|
-
return
|
|
14325
|
+
executor2.registerNode(new WaitUserNode({ auditPort: options.auditPort }));
|
|
14326
|
+
return executor2;
|
|
14196
14327
|
}
|
|
14197
14328
|
|
|
14198
14329
|
// src/runtime-kernel/testkit/graphLoopHarness.ts
|
|
@@ -14217,7 +14348,7 @@ function createGraphLoopHarness(options) {
|
|
|
14217
14348
|
return {
|
|
14218
14349
|
async run() {
|
|
14219
14350
|
const checkpointKey = options.runId ?? options.turnId;
|
|
14220
|
-
const
|
|
14351
|
+
const executor2 = createDefaultGraphExecutor({
|
|
14221
14352
|
llmNode: options.createLlmNode({
|
|
14222
14353
|
llmCaller: options.llmCaller,
|
|
14223
14354
|
toolRuntime: options.toolRuntime
|
|
@@ -14247,8 +14378,8 @@ function createGraphLoopHarness(options) {
|
|
|
14247
14378
|
signal: options.signal ?? options.toolContext.abortSignal,
|
|
14248
14379
|
executorLocal
|
|
14249
14380
|
};
|
|
14250
|
-
await
|
|
14251
|
-
const result = await
|
|
14381
|
+
await executor2.prime(checkpointKey, local, "user");
|
|
14382
|
+
const result = await executor2.runUntilYield(checkpointKey);
|
|
14252
14383
|
return {
|
|
14253
14384
|
checkpointNodeId: result.checkpoint.nodeId,
|
|
14254
14385
|
stepCount: result.stepCount,
|
|
@@ -14258,6 +14389,6 @@ function createGraphLoopHarness(options) {
|
|
|
14258
14389
|
};
|
|
14259
14390
|
}
|
|
14260
14391
|
|
|
14261
|
-
export { AuditEnvelopePersistenceError, BUILTIN_SYSTEM_REMINDER_TEMPLATES, BUILTIN_SYSTEM_REMINDER_TRIGGERS, BaseTool, ChildRunParentTraceProjection, CommonParameterTypes, CompositeAuditPort, DefaultTokenizerPort, EMPTY_MODEL_INPUT_REQUIREMENT, ENGINE_ERROR_CODES, ENGINE_STATE_SCHEMA_VERSION, EventStoreAuditPort, FileAuditPort, GraphAgentExecutor, GraphExecutor, INITIAL_CANONICAL_INFERENCE_STREAM_STATE, LLMPolicyEngine, LLM_IMAGE_INPUT_ERROR_CODES, LLM_MODEL_ELIGIBILITY_ERROR_CODE, LlmCaller, LlmImageInputError, LlmModelEligibilityError, LlmNode, MODEL_INPUT_ERROR_CODES, MODEL_INPUT_PLACEMENTS, MemoryCheckpointer, MemoryEventStore, ModelInputCapabilityError, ModelResolver, PRIMARY_PROMPT_CAPACITY_ERROR_CODE, PrimaryPromptCapacityError, REASONING_EFFORTS, RunPauseRequested, RunRecoveryBlockedError, RuntimeEventSubRunTracePublisher, SYSTEM_REMINDER_RULES, SystemReminderRegistry, ToolModelInputResolutionError, ToolNode, ToolParameterSchemaError, UserNode, WaitUserNode, addLedgerAggregate, addUsageTotals, advanceCanonicalInferenceStreamState, agentHasToolTrigger, aggregateCanonicalUsage, aggregateTokenLedgerEntries, applySystemReminders, assertModelInputCompatibility, assertToolParameterSchema, audit_exports as audit, child_run_trace_exports as childRunTrace, child_runs_exports as childRuns, computeCost, computeToolIdempotencyKey, consoleAudit, consumeCanonicalInferenceStream, copyToolContextRuntimeCapability, countToolCallsInCurrentRequest, createCompositeAudit, createConsoleAudit, createContextComponentLedgerEntry, createDefaultGraphExecutor, createDefaultSystemReminderRegistry, createDefaultTokenizerPort, createEventStoreAudit, createFileAudit, createFixedChatModelCatalog, createGraphLoopHarness, createHostToolCallBootstrap, createLlmUsageLedgerEntry, createModelInputCompatibilityError, createMonotonicEventStoreIdFactory, createRunTokenUsageAggregate, createSystemReminderRules, defaultPolicyEngine, defaultSystemReminderRegistry, deriveModelInputRequirement, emitAuditEnvelope, emitSandboxDecisionAudit, enrichment_exports as enrichment, ensureToolContextRuntimeCapability, evaluateModelInputCompatibility, evaluatePrimaryPromptCapacity, events_exports as events, execution_exports as execution, findCachedToolOutputByIdempotencyKey, getToolContextRuntimeBinding, graph_engine_exports as graph, hostReminderTextTemplate, isRunPauseSignal, isRuntimeFailureFact, isValidReasoningEffort, lastStepsHintTemplate, listCompatibleModelIds, llm_exports as llm, maxStepsForceFinalAnswerTemplate, noopAudit, normalizeToolArgs, parseToolModelInputDeclaration, periodicProgressReflectionTemplate, phaseEqualsTrigger, projectChildRuntimeEventToSubRunTrace, readCheckpointContextUsage, readNonEmptyStrings, readToolContextPersistedHistory, readToolContextWorkingHistory, remainingStepsLeqTrigger, requestEnricherRegistry, requireEventStoreId, resolveEffectiveEffort, resolveEffectivePromptBudget, resolveToolModelInput, run_context_exports as runContext, run_supervisor_exports as runSupervisor, stepCountModuloTrigger, stripRuntimeReservedToolContextPatch, summarizeCheckpoint, system_reminder_exports as systemReminder, telemetry_exports as telemetry, toDisplayStep, token_accounting_exports as tokenAccounting, toolCallStreakTemplate, toolCallStreakTrigger, tools_exports as tools };
|
|
14392
|
+
export { AuditEnvelopePersistenceError, BUILTIN_SYSTEM_REMINDER_TEMPLATES, BUILTIN_SYSTEM_REMINDER_TRIGGERS, BaseTool, ChildRunParentTraceProjection, CommonParameterTypes, CompositeAuditPort, DefaultTokenizerPort, EMPTY_MODEL_INPUT_REQUIREMENT, ENGINE_ERROR_CODES, ENGINE_STATE_SCHEMA_VERSION, EventStoreAuditPort, FileAuditPort, GraphAgentExecutor, GraphExecutor, INITIAL_CANONICAL_INFERENCE_STREAM_STATE, LLMPolicyEngine, LLM_IMAGE_INPUT_ERROR_CODES, LLM_MODEL_ELIGIBILITY_ERROR_CODE, LlmCaller, LlmImageInputError, LlmModelEligibilityError, LlmNode, MODEL_INPUT_ERROR_CODES, MODEL_INPUT_PLACEMENTS, MemoryCheckpointer, MemoryEventStore, ModelInputCapabilityError, ModelResolver, PRIMARY_PROMPT_CAPACITY_ERROR_CODE, PrimaryPromptCapacityError, REASONING_EFFORTS, RunPauseRequested, RunRecoveryBlockedError, RuntimeEventSubRunTracePublisher, SYSTEM_REMINDER_RULES, SystemReminderRegistry, ToolModelInputResolutionError, ToolNode, ToolParameterSchemaError, UserNode, WaitUserNode, addLedgerAggregate, addUsageTotals, advanceCanonicalInferenceStreamState, agentHasToolTrigger, aggregateCanonicalUsage, aggregateTokenLedgerEntries, applySystemReminders, assertModelInputCompatibility, assertToolParameterSchema, audit_exports as audit, child_run_trace_exports as childRunTrace, child_runs_exports as childRuns, computeCost, computeToolIdempotencyKey, consoleAudit, consumeCanonicalInferenceStream, copyToolContextRuntimeCapability, countToolCallsInCurrentRequest, createCompositeAudit, createConsoleAudit, createContextComponentLedgerEntry, createDefaultGraphExecutor, createDefaultSystemReminderRegistry, createDefaultTokenizerPort, createEventStoreAudit, createFileAudit, createFixedChatModelCatalog, createGraphLoopHarness, createHostToolCallBootstrap, createLlmUsageLedgerEntry, createModelInputCompatibilityError, createMonotonicEventStoreIdFactory, createRunTokenUsageAggregate, createSystemReminderRules, defaultPolicyEngine, defaultSystemReminderRegistry, deriveModelInputRequirement, emitAuditEnvelope, emitSandboxDecisionAudit, enrichment_exports as enrichment, ensureToolContextRuntimeCapability, evaluateModelInputCompatibility, evaluatePrimaryPromptCapacity, events_exports as events, execution_exports as execution, findCachedToolOutputByIdempotencyKey, getToolContextRuntimeBinding, graph_engine_exports as graph, hostReminderTextTemplate, isRunPauseSignal, isRuntimeFailureFact, isValidReasoningEffort, lastStepsHintTemplate, listCompatibleModelIds, llm_exports as llm, maxStepsForceFinalAnswerTemplate, noopAudit, normalizeToolArgs, parseEngineCheckpoint, parseToolModelInputDeclaration, periodicProgressReflectionTemplate, phaseEqualsTrigger, projectChildRuntimeEventToSubRunTrace, readCheckpointContextUsage, readNonEmptyStrings, readToolContextPersistedHistory, readToolContextWorkingHistory, remainingStepsLeqTrigger, requestEnricherRegistry, requireEventStoreId, resolveEffectiveEffort, resolveEffectivePromptBudget, resolveToolModelInput, run_context_exports as runContext, run_supervisor_exports as runSupervisor, stepCountModuloTrigger, stripRuntimeReservedToolContextPatch, summarizeCheckpoint, system_reminder_exports as systemReminder, telemetry_exports as telemetry, toDisplayStep, token_accounting_exports as tokenAccounting, toolCallStreakTemplate, toolCallStreakTrigger, tools_exports as tools };
|
|
14262
14393
|
//# sourceMappingURL=runtime-kernel.js.map
|
|
14263
14394
|
//# sourceMappingURL=runtime-kernel.js.map
|