@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
package/dist/testkit.cjs
CHANGED
|
@@ -174,6 +174,7 @@ __export(runtime_kernel_exports, {
|
|
|
174
174
|
maxStepsForceFinalAnswerTemplate: () => maxStepsForceFinalAnswerTemplate,
|
|
175
175
|
noopAudit: () => noopAudit,
|
|
176
176
|
normalizeToolArgs: () => normalizeToolArgs,
|
|
177
|
+
parseEngineCheckpoint: () => parseEngineCheckpoint,
|
|
177
178
|
parseToolModelInputDeclaration: () => parseToolModelInputDeclaration,
|
|
178
179
|
periodicProgressReflectionTemplate: () => periodicProgressReflectionTemplate,
|
|
179
180
|
phaseEqualsTrigger: () => phaseEqualsTrigger,
|
|
@@ -223,6 +224,7 @@ __export(graph_engine_exports, {
|
|
|
223
224
|
evaluatePrimaryPromptCapacity: () => evaluatePrimaryPromptCapacity,
|
|
224
225
|
isRunPauseSignal: () => isRunPauseSignal,
|
|
225
226
|
isRuntimeFailureFact: () => isRuntimeFailureFact,
|
|
227
|
+
parseEngineCheckpoint: () => parseEngineCheckpoint,
|
|
226
228
|
readCheckpointContextUsage: () => readCheckpointContextUsage,
|
|
227
229
|
requireEventStoreId: () => requireEventStoreId,
|
|
228
230
|
resolveEffectivePromptBudget: () => resolveEffectivePromptBudget,
|
|
@@ -3344,23 +3346,23 @@ var GraphExecutor = class {
|
|
|
3344
3346
|
};
|
|
3345
3347
|
}
|
|
3346
3348
|
async saveCheckpoint(checkpointKey, state) {
|
|
3347
|
-
const
|
|
3349
|
+
const checkpoint2 = this.sanitize({
|
|
3348
3350
|
...state,
|
|
3349
3351
|
revision: (state.revision ?? 0) + 1
|
|
3350
3352
|
});
|
|
3351
|
-
await this.commitCheckpoint(checkpointKey,
|
|
3352
|
-
return
|
|
3353
|
+
await this.commitCheckpoint(checkpointKey, checkpoint2);
|
|
3354
|
+
return checkpoint2;
|
|
3353
3355
|
}
|
|
3354
|
-
async commitCheckpoint(checkpointKey,
|
|
3356
|
+
async commitCheckpoint(checkpointKey, checkpoint2) {
|
|
3355
3357
|
if (this.executionCheckpointPort) {
|
|
3356
|
-
await this.executionCheckpointPort.commit(checkpointKey,
|
|
3358
|
+
await this.executionCheckpointPort.commit(checkpointKey, checkpoint2);
|
|
3357
3359
|
} else {
|
|
3358
|
-
await this.checkpointer.save(checkpointKey,
|
|
3360
|
+
await this.checkpointer.save(checkpointKey, checkpoint2);
|
|
3359
3361
|
}
|
|
3360
3362
|
}
|
|
3361
3363
|
async saveCheckpointAndBuildResult(checkpointKey, state, events, stepCount) {
|
|
3362
|
-
const
|
|
3363
|
-
return { events, checkpoint, stepCount };
|
|
3364
|
+
const checkpoint2 = await this.saveCheckpoint(checkpointKey, state);
|
|
3365
|
+
return { events, checkpoint: checkpoint2, stepCount };
|
|
3364
3366
|
}
|
|
3365
3367
|
async runUntilYieldInternal(checkpointKey, initialState, reportStepsUsed, maxSteps) {
|
|
3366
3368
|
let state = initialState;
|
|
@@ -9487,16 +9489,16 @@ function requireEventStoreId(eventStoreId) {
|
|
|
9487
9489
|
}
|
|
9488
9490
|
function createMonotonicEventStoreIdFactory(nowProvider = () => Date.now()) {
|
|
9489
9491
|
let lastTimestamp = 0;
|
|
9490
|
-
let
|
|
9492
|
+
let counter2 = 0;
|
|
9491
9493
|
return () => {
|
|
9492
9494
|
const timestamp = Math.max(nowProvider(), lastTimestamp);
|
|
9493
9495
|
if (timestamp === lastTimestamp) {
|
|
9494
|
-
|
|
9496
|
+
counter2 += 1;
|
|
9495
9497
|
} else {
|
|
9496
9498
|
lastTimestamp = timestamp;
|
|
9497
|
-
|
|
9499
|
+
counter2 = 0;
|
|
9498
9500
|
}
|
|
9499
|
-
return `${String(timestamp).padStart(13, "0")}-${String(
|
|
9501
|
+
return `${String(timestamp).padStart(13, "0")}-${String(counter2).padStart(4, "0")}`;
|
|
9500
9502
|
};
|
|
9501
9503
|
}
|
|
9502
9504
|
|
|
@@ -9908,6 +9910,76 @@ function assertNonNegativeSafeInteger(value, field) {
|
|
|
9908
9910
|
throw new Error(`${field} \u5FC5\u987B\u662F\u975E\u8D1F\u5B89\u5168\u6574\u6570\u3002`);
|
|
9909
9911
|
}
|
|
9910
9912
|
}
|
|
9913
|
+
var counter = zod.z.number().int().nonnegative();
|
|
9914
|
+
var executor = zod.z.object({
|
|
9915
|
+
stepCount: counter,
|
|
9916
|
+
phase: zod.z.string().optional(),
|
|
9917
|
+
maxSteps: counter.optional(),
|
|
9918
|
+
remainingSteps: zod.z.number().int().optional(),
|
|
9919
|
+
finalStepPolicy: zod.z.enum(["final_answer", "force_tools"]).optional(),
|
|
9920
|
+
finalStepForcedTools: zod.z.array(zod.z.string()).optional(),
|
|
9921
|
+
lastStepsHintThreshold: counter.optional(),
|
|
9922
|
+
systemReminderPolicy: AgentSpecSystemReminderPolicy.optional(),
|
|
9923
|
+
toolObservationPolicy: AgentSpecToolObservationGovernancePolicy.optional(),
|
|
9924
|
+
runLockedModelId: zod.z.string().optional(),
|
|
9925
|
+
lastSuccessfulLlmModelId: zod.z.string().optional(),
|
|
9926
|
+
llmInvocationKind: zod.z.enum(["user_initiated", "continuation"]).optional(),
|
|
9927
|
+
llmInvocationCount: counter.optional(),
|
|
9928
|
+
lockRequestedModelId: zod.z.boolean().optional(),
|
|
9929
|
+
contextCompaction: zod.z.object({
|
|
9930
|
+
attemptCount: counter,
|
|
9931
|
+
committedCount: counter,
|
|
9932
|
+
lastCommittedFingerprint: zod.z.string().optional()
|
|
9933
|
+
}).strict().optional()
|
|
9934
|
+
}).strict();
|
|
9935
|
+
var checkpoint = zod.z.object({
|
|
9936
|
+
nodeId: zod.z.string().min(1),
|
|
9937
|
+
schemaVersion: zod.z.literal(ENGINE_STATE_SCHEMA_VERSION).optional(),
|
|
9938
|
+
revision: counter.optional(),
|
|
9939
|
+
executionStatus: zod.z.enum(["ready", "executing", "yielded", "awaiting_user"]).optional(),
|
|
9940
|
+
local: zod.z.object({
|
|
9941
|
+
runId: RunIdSchema.optional(),
|
|
9942
|
+
parentRunId: RunIdSchema.optional(),
|
|
9943
|
+
conversationId: zod.z.string().optional(),
|
|
9944
|
+
turnId: zod.z.string().optional(),
|
|
9945
|
+
request: SerializableJsonRecord.optional(),
|
|
9946
|
+
history: zod.z.array(RuntimeEvent).optional(),
|
|
9947
|
+
newEvents: zod.z.array(RuntimeEvent).optional(),
|
|
9948
|
+
executorLocal: executor.optional(),
|
|
9949
|
+
pendingToolCalls: zod.z.array(zod.z.object({
|
|
9950
|
+
id: ToolCallIdSchema,
|
|
9951
|
+
type: zod.z.literal("function"),
|
|
9952
|
+
function: zod.z.object({ name: zod.z.string().min(1), arguments: zod.z.string() }).strict()
|
|
9953
|
+
}).strict()).optional(),
|
|
9954
|
+
executingToolCallId: ToolCallIdSchema.optional(),
|
|
9955
|
+
toolBatchCompletionMode: zod.z.enum(["continue_to_llm", "yield_after_batch"]).optional(),
|
|
9956
|
+
pendingInteractionSpec: SerializableJsonRecord.optional(),
|
|
9957
|
+
lastToolResult: SerializableJsonRecord.optional(),
|
|
9958
|
+
finalAnswer: zod.z.string().optional(),
|
|
9959
|
+
answerId: zod.z.string().optional(),
|
|
9960
|
+
chunkSeq: counter.optional(),
|
|
9961
|
+
contextUsage: ContextUsageSnapshot.optional()
|
|
9962
|
+
}).passthrough().optional()
|
|
9963
|
+
}).strict();
|
|
9964
|
+
function parseEngineCheckpoint(value) {
|
|
9965
|
+
const result = checkpoint.parse(SerializableJsonRecord.parse(value));
|
|
9966
|
+
for (const key of [
|
|
9967
|
+
"memory",
|
|
9968
|
+
"signal",
|
|
9969
|
+
"toolContext",
|
|
9970
|
+
"runtimeEventSink",
|
|
9971
|
+
"runtimeEventCommitPort",
|
|
9972
|
+
"runtimeFailureFactSink",
|
|
9973
|
+
"summarizationCallbacks",
|
|
9974
|
+
"commitExecutionBoundary",
|
|
9975
|
+
"toolRecoveryPort"
|
|
9976
|
+
]) {
|
|
9977
|
+
if (result.local && Object.hasOwn(result.local, key)) {
|
|
9978
|
+
throw new Error(`Checkpoint must not contain execution capability: ${key}`);
|
|
9979
|
+
}
|
|
9980
|
+
}
|
|
9981
|
+
return result;
|
|
9982
|
+
}
|
|
9911
9983
|
|
|
9912
9984
|
// src/runtime-kernel/tools/index.ts
|
|
9913
9985
|
var tools_exports = {};
|
|
@@ -10369,14 +10441,14 @@ var EventBusEventPersistence = class {
|
|
|
10369
10441
|
checkpointWritesActive;
|
|
10370
10442
|
checkpointEvents = [];
|
|
10371
10443
|
/** Graph 的执行边界复用同一有序队列;没有第二条事件写入链。 */
|
|
10372
|
-
async commitCheckpoint(checkpointKey,
|
|
10444
|
+
async commitCheckpoint(checkpointKey, checkpoint2) {
|
|
10373
10445
|
const writer = this.options.checkpointWriter;
|
|
10374
10446
|
if (!writer || !this.checkpointWritesActive) throw new Error("Checkpoint writer is not active");
|
|
10375
10447
|
const events = this.checkpointEvents;
|
|
10376
10448
|
this.checkpointEvents = [];
|
|
10377
10449
|
await this.enqueueWrite(() => writer({
|
|
10378
10450
|
checkpointKey,
|
|
10379
|
-
checkpoint,
|
|
10451
|
+
checkpoint: checkpoint2,
|
|
10380
10452
|
events: events.map((event) => ({ event, eventStoreId: this.options.nextEventStoreId() }))
|
|
10381
10453
|
}));
|
|
10382
10454
|
}
|
|
@@ -12069,15 +12141,15 @@ function hasSeedHistoryPrefix(history, seedHistory) {
|
|
|
12069
12141
|
}
|
|
12070
12142
|
return true;
|
|
12071
12143
|
}
|
|
12072
|
-
function readCheckpointHistory(
|
|
12073
|
-
if (!
|
|
12074
|
-
const history =
|
|
12144
|
+
function readCheckpointHistory(checkpoint2) {
|
|
12145
|
+
if (!checkpoint2?.local) return [];
|
|
12146
|
+
const history = checkpoint2.local.history;
|
|
12075
12147
|
if (!Array.isArray(history)) return [];
|
|
12076
12148
|
return parseRuntimeEvents(history);
|
|
12077
12149
|
}
|
|
12078
12150
|
async function recoverChildRunEventsFromCheckpoint(params) {
|
|
12079
|
-
const
|
|
12080
|
-
const history = readCheckpointHistory(
|
|
12151
|
+
const checkpoint2 = await params.checkpointer.load(params.checkpointKey);
|
|
12152
|
+
const history = readCheckpointHistory(checkpoint2);
|
|
12081
12153
|
if (history.length === 0) {
|
|
12082
12154
|
return [];
|
|
12083
12155
|
}
|
|
@@ -12123,10 +12195,10 @@ var ChildRunInvoker = class {
|
|
|
12123
12195
|
runtimeEventSink,
|
|
12124
12196
|
runtimeEventCommitPort,
|
|
12125
12197
|
seedHistoryEvents,
|
|
12126
|
-
maxSteps = 8,
|
|
12127
12198
|
modelId,
|
|
12128
12199
|
abortSignal
|
|
12129
12200
|
} = config;
|
|
12201
|
+
const maxSteps = config.initialInput?.request.maxSteps ?? config.maxSteps ?? 8;
|
|
12130
12202
|
const childRunId = runId ?? generateRunId();
|
|
12131
12203
|
const internalCheckpointKey = childRunId;
|
|
12132
12204
|
const resolvedParentRunId = parentRunId ?? parentToolContext.runId;
|
|
@@ -12171,7 +12243,8 @@ var ChildRunInvoker = class {
|
|
|
12171
12243
|
if (config.persistence?.expectedRevision !== void 0) {
|
|
12172
12244
|
return this.continueChild(config, childRunId, runtimeConversationId);
|
|
12173
12245
|
}
|
|
12174
|
-
const turnId = generateTurnId();
|
|
12246
|
+
const turnId = config.initialInput?.turnId ?? generateTurnId();
|
|
12247
|
+
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");
|
|
12175
12248
|
logger17.info(`\u542F\u52A8 child-run: ${agentConfig.id}`, {
|
|
12176
12249
|
conversationId: runtimeConversationId,
|
|
12177
12250
|
checkpointKey: internalCheckpointKey,
|
|
@@ -12188,11 +12261,14 @@ var ChildRunInvoker = class {
|
|
|
12188
12261
|
});
|
|
12189
12262
|
const admittedChildUserInput = runtimeEventSink(childUserInput, "ChildRunInvoker.user_input");
|
|
12190
12263
|
const childModelId = resolveChildRunModelId({
|
|
12191
|
-
explicitModelId: modelId,
|
|
12264
|
+
explicitModelId: config.initialInput?.request.model_id ?? modelId,
|
|
12192
12265
|
agentConfig,
|
|
12193
12266
|
resolveDefaultModelId: () => this.modelResolver.resolveModelId()
|
|
12194
12267
|
});
|
|
12195
|
-
const request = {
|
|
12268
|
+
const request = config.initialInput ? {
|
|
12269
|
+
...config.initialInput.request,
|
|
12270
|
+
currentUserEventId: admittedChildUserInput.id
|
|
12271
|
+
} : {
|
|
12196
12272
|
query: userMessage,
|
|
12197
12273
|
currentUserEventId: admittedChildUserInput.id,
|
|
12198
12274
|
promptKey: agentConfig.promptKey,
|
|
@@ -12373,9 +12449,9 @@ var ChildRunInvoker = class {
|
|
|
12373
12449
|
async continueChild(config, runId, conversationId) {
|
|
12374
12450
|
const persistence = config.persistence;
|
|
12375
12451
|
if (!persistence || persistence.expectedRevision === void 0) throw new Error("Missing child continuation contract");
|
|
12376
|
-
const
|
|
12377
|
-
if (!
|
|
12378
|
-
const local = readGraphAgentLocal({ ...
|
|
12452
|
+
const checkpoint2 = await persistence.checkpointer.load(runId);
|
|
12453
|
+
if (!checkpoint2 || checkpoint2.local?.conversationId !== conversationId) throw new Error("Child checkpoint identity mismatch");
|
|
12454
|
+
const local = readGraphAgentLocal({ ...checkpoint2.local, runtimeEventSink: config.runtimeEventSink });
|
|
12379
12455
|
const request = local.request;
|
|
12380
12456
|
if (!request || !local.turnId || !request.model_id) throw new Error("Child recovery input is incomplete");
|
|
12381
12457
|
const context = createChildRunToolContext({
|
|
@@ -13652,7 +13728,15 @@ function createRunConcurrencyKeyRegistry() {
|
|
|
13652
13728
|
runIdByKey.delete(concurrencyKey);
|
|
13653
13729
|
}
|
|
13654
13730
|
}
|
|
13655
|
-
|
|
13731
|
+
function transfer(previous, next, concurrencyKey) {
|
|
13732
|
+
if (runIdByKey.get(concurrencyKey) !== previous || keyByRunId.has(next)) {
|
|
13733
|
+
throw new RunConcurrencyKeyOccupiedError(concurrencyKey, runIdByKey.get(concurrencyKey) ?? previous, next);
|
|
13734
|
+
}
|
|
13735
|
+
keyByRunId.delete(previous);
|
|
13736
|
+
keyByRunId.set(next, concurrencyKey);
|
|
13737
|
+
runIdByKey.set(concurrencyKey, next);
|
|
13738
|
+
}
|
|
13739
|
+
return { acquire, release, transfer };
|
|
13656
13740
|
}
|
|
13657
13741
|
|
|
13658
13742
|
// src/runtime-kernel/run-supervisor/functions/runRegistration.ts
|
|
@@ -13901,6 +13985,9 @@ var DefaultRunSupervisor = class {
|
|
|
13901
13985
|
});
|
|
13902
13986
|
}
|
|
13903
13987
|
async registerRun(spec) {
|
|
13988
|
+
if (spec.replacesPausedRun) {
|
|
13989
|
+
return this.withRunControlLock(spec.replacesPausedRun.runId, () => this.registerPausedReplacement(spec));
|
|
13990
|
+
}
|
|
13904
13991
|
const runId = spec.runId ?? this.runIdFactory();
|
|
13905
13992
|
if (this.handles.has(runId) || await this.registryStore.load(runId)) {
|
|
13906
13993
|
throw new RunAlreadyRegisteredError(runId);
|
|
@@ -13911,13 +13998,51 @@ var DefaultRunSupervisor = class {
|
|
|
13911
13998
|
forwardParentAbortSignal(controller, spec.parentSignal);
|
|
13912
13999
|
const record = createInitialRunRecord({ runId, spec, startedAt });
|
|
13913
14000
|
try {
|
|
13914
|
-
await
|
|
14001
|
+
if (spec.admissionCommit) await spec.admissionCommit(record);
|
|
14002
|
+
else await this.registryStore.save(record);
|
|
13915
14003
|
} catch (error) {
|
|
13916
14004
|
this.releaseRunAdmission(runId);
|
|
13917
14005
|
throw error;
|
|
13918
14006
|
}
|
|
13919
14007
|
return this.attachRun(record, spec, controller);
|
|
13920
14008
|
}
|
|
14009
|
+
async registerPausedReplacement(spec) {
|
|
14010
|
+
const target = spec.replacesPausedRun;
|
|
14011
|
+
if (!target || !spec.concurrencyKey || !spec.admissionCommit || !this.registryStore.compareAndSwap) {
|
|
14012
|
+
throw new Error("Paused replacement requires concurrency identity and atomic admissionCommit");
|
|
14013
|
+
}
|
|
14014
|
+
this.getHandle(target.runId);
|
|
14015
|
+
const previous = await this.registryStore.load(target.runId);
|
|
14016
|
+
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) {
|
|
14017
|
+
throw new RunInteractionConflictError(target.runId, "replacement does not match the settled pause");
|
|
14018
|
+
}
|
|
14019
|
+
const runId = spec.runId ?? this.runIdFactory();
|
|
14020
|
+
if (this.handles.has(runId) || await this.registryStore.load(runId)) throw new RunAlreadyRegisteredError(runId);
|
|
14021
|
+
this.runConcurrencyKeys.transfer(previous.runId, runId, spec.concurrencyKey);
|
|
14022
|
+
this.runSlotLimiter.release(previous.runId);
|
|
14023
|
+
this.runSlotLimiter.acquire(runId);
|
|
14024
|
+
const now = this.now();
|
|
14025
|
+
const record = createInitialRunRecord({ runId, spec, startedAt: now });
|
|
14026
|
+
const next = {
|
|
14027
|
+
...previous,
|
|
14028
|
+
status: "cancelled",
|
|
14029
|
+
updatedAt: now,
|
|
14030
|
+
errorIfAny: { errorCode: "RUN_REPLACED", message: "Replaced by a newly accepted request", recoverable: false }
|
|
14031
|
+
};
|
|
14032
|
+
try {
|
|
14033
|
+
await spec.admissionCommit(record, { previous, next });
|
|
14034
|
+
} catch (error) {
|
|
14035
|
+
this.runSlotLimiter.release(runId);
|
|
14036
|
+
this.runSlotLimiter.acquire(previous.runId);
|
|
14037
|
+
this.runConcurrencyKeys.transfer(runId, previous.runId, spec.concurrencyKey);
|
|
14038
|
+
throw error;
|
|
14039
|
+
}
|
|
14040
|
+
this.cleanupRunResources(previous.runId);
|
|
14041
|
+
this.notifyTerminalWaiters(previous.runId);
|
|
14042
|
+
const controller = new AbortController();
|
|
14043
|
+
forwardParentAbortSignal(controller, spec.parentSignal);
|
|
14044
|
+
return this.attachRun(record, spec, controller);
|
|
14045
|
+
}
|
|
13921
14046
|
async restoreRun(spec) {
|
|
13922
14047
|
if (!this.registryStore.compareAndSwap) throw new Error("Run restoration requires atomic registry transitions");
|
|
13923
14048
|
return this.withRunControlLock(spec.runId, async () => {
|
|
@@ -14041,7 +14166,7 @@ var DefaultRunSupervisor = class {
|
|
|
14041
14166
|
return this.withRunControlLock(input.runId, async () => {
|
|
14042
14167
|
const handle = this.getHandle(input.runId);
|
|
14043
14168
|
const record = await this.registryStore.load(input.runId);
|
|
14044
|
-
if (!record || record.status !== "paused" || record.pausedAt === void 0 || record.updatedAt !== input.expectedUpdatedAt) {
|
|
14169
|
+
if (!record || record.status !== "paused" || record.pausedAt === void 0 || record.updatedAt !== input.expectedUpdatedAt || input.expectedExecutionId !== void 0 && record.metadata?.executionId !== input.expectedExecutionId) {
|
|
14045
14170
|
throw new RunInteractionConflictError(input.runId, "run is not settled at the expected pause");
|
|
14046
14171
|
}
|
|
14047
14172
|
await persistRunTransition(this.registryStore, record, {
|
|
@@ -14054,6 +14179,7 @@ var DefaultRunSupervisor = class {
|
|
|
14054
14179
|
metadata: { ...record.metadata, executionId: input.executionId }
|
|
14055
14180
|
});
|
|
14056
14181
|
const controller = new AbortController();
|
|
14182
|
+
forwardParentAbortSignal(controller, input.parentSignal);
|
|
14057
14183
|
handle.replaceExecutionAbortController(controller, input.executionId);
|
|
14058
14184
|
handle.attachTransportEventBus(input.eventBus);
|
|
14059
14185
|
this.controllers.set(input.runId, controller);
|
|
@@ -14182,7 +14308,7 @@ var DefaultRunSupervisor = class {
|
|
|
14182
14308
|
}
|
|
14183
14309
|
const awaitingUserWithoutClaim = { ...awaitingUser };
|
|
14184
14310
|
Reflect.deleteProperty(awaitingUserWithoutClaim, "resumeClaim");
|
|
14185
|
-
|
|
14311
|
+
const nextRecord = {
|
|
14186
14312
|
...record,
|
|
14187
14313
|
status: "running",
|
|
14188
14314
|
updatedAt: this.now(),
|
|
@@ -14192,6 +14318,10 @@ var DefaultRunSupervisor = class {
|
|
|
14192
14318
|
metadata: {
|
|
14193
14319
|
...record.metadata ?? {},
|
|
14194
14320
|
...execution ? { executionId: execution.executionId } : {},
|
|
14321
|
+
...execution?.inputEventIds ? { resumeInputs: {
|
|
14322
|
+
eventIds: [...execution.inputEventIds],
|
|
14323
|
+
checkpointRevision: pendingInteraction.checkpointRevision
|
|
14324
|
+
} } : {},
|
|
14195
14325
|
awaitingUser: {
|
|
14196
14326
|
...awaitingUserWithoutClaim,
|
|
14197
14327
|
interaction: {
|
|
@@ -14200,7 +14330,9 @@ var DefaultRunSupervisor = class {
|
|
|
14200
14330
|
}
|
|
14201
14331
|
}
|
|
14202
14332
|
}
|
|
14203
|
-
}
|
|
14333
|
+
};
|
|
14334
|
+
if (execution?.admissionCommit) await execution.admissionCommit(record, nextRecord);
|
|
14335
|
+
else await persistRunTransition(this.registryStore, record, nextRecord);
|
|
14204
14336
|
const executionController = new AbortController();
|
|
14205
14337
|
forwardParentAbortSignal(executionController, parentSignal);
|
|
14206
14338
|
handle.replaceExecutionAbortController(executionController, execution?.executionId ?? (typeof record.metadata?.executionId === "string" ? record.metadata.executionId : void 0));
|
|
@@ -14366,13 +14498,13 @@ __export(system_reminder_exports, {
|
|
|
14366
14498
|
|
|
14367
14499
|
// src/runtime-kernel/testkit/defaultGraphExecutor.ts
|
|
14368
14500
|
function createDefaultGraphExecutor(options) {
|
|
14369
|
-
const
|
|
14501
|
+
const executor2 = new GraphExecutor(
|
|
14370
14502
|
options.checkpointer ?? new MemoryCheckpointer(),
|
|
14371
14503
|
{ maxSteps: options.maxSteps ?? 8 }
|
|
14372
14504
|
);
|
|
14373
|
-
|
|
14374
|
-
|
|
14375
|
-
|
|
14505
|
+
executor2.registerNode(new UserNode());
|
|
14506
|
+
executor2.registerNode(options.llmNode);
|
|
14507
|
+
executor2.registerNode(new ToolNode({
|
|
14376
14508
|
toolRuntime: options.toolRuntime,
|
|
14377
14509
|
observationPreview: options.observationPreview,
|
|
14378
14510
|
auditPort: options.auditPort,
|
|
@@ -14380,8 +14512,8 @@ function createDefaultGraphExecutor(options) {
|
|
|
14380
14512
|
modelInputCapabilityValidator: options.modelInputCapabilityValidator,
|
|
14381
14513
|
modelInputResolver: options.modelInputResolver
|
|
14382
14514
|
}));
|
|
14383
|
-
|
|
14384
|
-
return
|
|
14515
|
+
executor2.registerNode(new WaitUserNode({ auditPort: options.auditPort }));
|
|
14516
|
+
return executor2;
|
|
14385
14517
|
}
|
|
14386
14518
|
|
|
14387
14519
|
// src/runtime-kernel/testkit/graphLoopHarness.ts
|
|
@@ -14406,7 +14538,7 @@ function createGraphLoopHarness(options) {
|
|
|
14406
14538
|
return {
|
|
14407
14539
|
async run() {
|
|
14408
14540
|
const checkpointKey = options.runId ?? options.turnId;
|
|
14409
|
-
const
|
|
14541
|
+
const executor2 = createDefaultGraphExecutor({
|
|
14410
14542
|
llmNode: options.createLlmNode({
|
|
14411
14543
|
llmCaller: options.llmCaller,
|
|
14412
14544
|
toolRuntime: options.toolRuntime
|
|
@@ -14436,8 +14568,8 @@ function createGraphLoopHarness(options) {
|
|
|
14436
14568
|
signal: options.signal ?? options.toolContext.abortSignal,
|
|
14437
14569
|
executorLocal
|
|
14438
14570
|
};
|
|
14439
|
-
await
|
|
14440
|
-
const result = await
|
|
14571
|
+
await executor2.prime(checkpointKey, local, "user");
|
|
14572
|
+
const result = await executor2.runUntilYield(checkpointKey);
|
|
14441
14573
|
return {
|
|
14442
14574
|
checkpointNodeId: result.checkpoint.nodeId,
|
|
14443
14575
|
stepCount: result.stepCount,
|