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