@botbotgo/agent-harness 0.0.108 → 0.0.110
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/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/runtime/adapter/execution-context.d.ts +7 -0
- package/dist/runtime/adapter/execution-context.js +9 -2
- package/dist/runtime/adapter/middleware-assembly.js +2 -2
- package/dist/runtime/adapter/runnable-config.d.ts +44 -0
- package/dist/runtime/adapter/runnable-config.js +51 -0
- package/dist/runtime/adapter/runtime-adapter-support.d.ts +0 -1
- package/dist/runtime/adapter/runtime-adapter-support.js +1 -4
- package/dist/runtime/agent-runtime-adapter.d.ts +1 -0
- package/dist/runtime/agent-runtime-adapter.js +37 -20
- package/dist/runtime/harness/events/listener-runtime.d.ts +18 -0
- package/dist/runtime/harness/events/listener-runtime.js +9 -0
- package/dist/runtime/harness/events/runtime-event-operations.d.ts +17 -0
- package/dist/runtime/harness/events/runtime-event-operations.js +9 -0
- package/dist/runtime/harness/run/recovery.d.ts +1 -1
- package/dist/runtime/harness/run/recovery.js +65 -47
- package/dist/runtime/harness/run/routing.d.ts +8 -0
- package/dist/runtime/harness/run/routing.js +21 -0
- package/dist/runtime/harness/run/run-operations.d.ts +47 -0
- package/dist/runtime/harness/run/run-operations.js +108 -6
- package/dist/runtime/harness/run/start-run.d.ts +82 -0
- package/dist/runtime/harness/run/start-run.js +88 -0
- package/dist/runtime/harness/run/startup-runtime.d.ts +2 -1
- package/dist/runtime/harness/run/startup-runtime.js +38 -3
- package/dist/runtime/harness.d.ts +5 -3
- package/dist/runtime/harness.js +163 -238
- package/dist/runtime/support/runtime-adapter-options.d.ts +17 -0
- package/dist/runtime/support/runtime-adapter-options.js +29 -0
- package/dist/workspace/agent-binding-compiler.js +24 -88
- package/dist/workspace/support/agent-capabilities.js +2 -6
- package/dist/workspace/support/agent-execution-config.d.ts +18 -0
- package/dist/workspace/support/agent-execution-config.js +35 -0
- package/dist/workspace/validate.js +6 -11
- package/package.json +1 -1
- package/dist/runtime/adapter/deepagent-runnable-config.d.ts +0 -13
- package/dist/runtime/adapter/deepagent-runnable-config.js +0 -29
- package/dist/runtime/adapter/langchain-runnable-config.d.ts +0 -11
- package/dist/runtime/adapter/langchain-runnable-config.js +0 -24
|
@@ -45,6 +45,53 @@ type CancelOperationRuntime = {
|
|
|
45
45
|
error?: string;
|
|
46
46
|
}) => Promise<unknown>;
|
|
47
47
|
};
|
|
48
|
+
type ExecuteQueuedRunOperationRuntime = {
|
|
49
|
+
persistence: {
|
|
50
|
+
getRun: (runId: string) => Promise<{
|
|
51
|
+
state: RunResult["state"];
|
|
52
|
+
} | null>;
|
|
53
|
+
clearRunRequest: (threadId: string, runId: string) => Promise<void>;
|
|
54
|
+
};
|
|
55
|
+
getRunCancellation: (runId: string) => Promise<{
|
|
56
|
+
requested: boolean;
|
|
57
|
+
reason?: string;
|
|
58
|
+
}>;
|
|
59
|
+
finalizeCancelledRun: (threadId: string, runId: string, previousState: RunResult["state"] | null, reason?: string) => Promise<RunResult>;
|
|
60
|
+
emit: (threadId: string, runId: string, sequence: number, eventType: string, payload: Record<string, unknown>) => Promise<unknown>;
|
|
61
|
+
setRunStateAndEmit: (threadId: string, runId: string, sequence: number, state: RunResult["state"], options: {
|
|
62
|
+
previousState: string | null;
|
|
63
|
+
checkpointRef?: string | null;
|
|
64
|
+
error?: string;
|
|
65
|
+
}) => Promise<unknown>;
|
|
66
|
+
invokeWithHistory: (binding: CompiledAgentBinding, input: MessageContent, threadId: string, runId: string, resumePayload?: unknown, priorHistory?: TranscriptMessage[], options?: {
|
|
67
|
+
context?: Record<string, unknown>;
|
|
68
|
+
state?: Record<string, unknown>;
|
|
69
|
+
files?: Record<string, unknown>;
|
|
70
|
+
}) => Promise<RunResult>;
|
|
71
|
+
finalizeContinuedRun: (binding: CompiledAgentBinding, threadId: string, runId: string, input: MessageContent, actual: RunResult, options: {
|
|
72
|
+
previousState: RunResult["state"] | null;
|
|
73
|
+
stateSequence: number;
|
|
74
|
+
approvalSequence?: number;
|
|
75
|
+
}) => Promise<RunResult>;
|
|
76
|
+
emitSyntheticFallback: (threadId: string, runId: string, agentId: string, error: unknown) => Promise<void>;
|
|
77
|
+
renderRuntimeFailure: (error: unknown) => string;
|
|
78
|
+
};
|
|
48
79
|
export declare function resumeRun(runtime: ResumeOperationRuntime, options: ResumeOptions): Promise<RunResult>;
|
|
49
80
|
export declare function cancelRunOperation(runtime: CancelOperationRuntime, options: CancelOptions): Promise<RunResult>;
|
|
81
|
+
export declare function executeQueuedRunOperation(runtime: ExecuteQueuedRunOperationRuntime, input: {
|
|
82
|
+
binding: CompiledAgentBinding;
|
|
83
|
+
message: MessageContent;
|
|
84
|
+
threadId: string;
|
|
85
|
+
runId: string;
|
|
86
|
+
agentId: string;
|
|
87
|
+
options?: {
|
|
88
|
+
context?: Record<string, unknown>;
|
|
89
|
+
state?: Record<string, unknown>;
|
|
90
|
+
files?: Record<string, unknown>;
|
|
91
|
+
priorHistory?: TranscriptMessage[];
|
|
92
|
+
previousState?: RunResult["state"];
|
|
93
|
+
stateSequence?: number;
|
|
94
|
+
approvalSequence?: number;
|
|
95
|
+
};
|
|
96
|
+
}): Promise<RunResult>;
|
|
50
97
|
export {};
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import { isTerminalRunState } from "./helpers.js";
|
|
2
|
+
async function finalizeIfCancellationRequested(input) {
|
|
3
|
+
const cancellation = await input.getRunCancellation(input.runId);
|
|
4
|
+
if (!cancellation.requested) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return input.finalizeCancelledRun(input.threadId, input.runId, input.previousState, cancellation.reason);
|
|
8
|
+
}
|
|
9
|
+
function normalizeContinuationState(previousState) {
|
|
10
|
+
return previousState === "queued" ? "running" : previousState;
|
|
11
|
+
}
|
|
2
12
|
export async function resumeRun(runtime, options) {
|
|
3
13
|
const approvalById = options.approvalId ? await runtime.getApprovalById(options.approvalId) : null;
|
|
4
14
|
const thread = options.threadId
|
|
@@ -17,9 +27,15 @@ export async function resumeRun(runtime, options) {
|
|
|
17
27
|
throw new Error(`Unknown agent ${thread.agentId}`);
|
|
18
28
|
}
|
|
19
29
|
const resumePayload = runtime.buildResumePayload(binding, approval, options);
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
30
|
+
const cancelledBeforeResume = await finalizeIfCancellationRequested({
|
|
31
|
+
getRunCancellation: runtime.getRunCancellation,
|
|
32
|
+
finalizeCancelledRun: runtime.finalizeCancelledRun,
|
|
33
|
+
threadId,
|
|
34
|
+
runId,
|
|
35
|
+
previousState: thread.status,
|
|
36
|
+
});
|
|
37
|
+
if (cancelledBeforeResume) {
|
|
38
|
+
return cancelledBeforeResume;
|
|
23
39
|
}
|
|
24
40
|
const checkpointRef = `checkpoints/${threadId}/${runId}/cp-1`;
|
|
25
41
|
await runtime.setRunState(threadId, runId, "resuming", checkpointRef);
|
|
@@ -53,9 +69,15 @@ export async function resumeRun(runtime, options) {
|
|
|
53
69
|
try {
|
|
54
70
|
const actual = await runtime.invoke(binding, "", threadId, runId, resumePayload, priorHistory);
|
|
55
71
|
runtime.recordLlmSuccess(startedAt);
|
|
56
|
-
const cancelledAfterInvoke = await
|
|
57
|
-
|
|
58
|
-
|
|
72
|
+
const cancelledAfterInvoke = await finalizeIfCancellationRequested({
|
|
73
|
+
getRunCancellation: runtime.getRunCancellation,
|
|
74
|
+
finalizeCancelledRun: runtime.finalizeCancelledRun,
|
|
75
|
+
threadId,
|
|
76
|
+
runId,
|
|
77
|
+
previousState: "resuming",
|
|
78
|
+
});
|
|
79
|
+
if (cancelledAfterInvoke) {
|
|
80
|
+
return cancelledAfterInvoke;
|
|
59
81
|
}
|
|
60
82
|
await runtime.clearRecoveryIntent(threadId, runId);
|
|
61
83
|
const finalized = await runtime.finalizeContinuedRun(binding, threadId, runId, runInput, actual, {
|
|
@@ -111,3 +133,83 @@ export async function cancelRunOperation(runtime, options) {
|
|
|
111
133
|
output: options.reason ? `cancelling: ${options.reason}` : "cancelling",
|
|
112
134
|
};
|
|
113
135
|
}
|
|
136
|
+
export async function executeQueuedRunOperation(runtime, input) {
|
|
137
|
+
const { binding, message, threadId, runId, agentId } = input;
|
|
138
|
+
const options = input.options ?? {};
|
|
139
|
+
const previousState = options.previousState ?? "running";
|
|
140
|
+
const currentRun = await runtime.persistence.getRun(runId);
|
|
141
|
+
if (currentRun?.state === "cancelled") {
|
|
142
|
+
return {
|
|
143
|
+
threadId,
|
|
144
|
+
runId,
|
|
145
|
+
agentId,
|
|
146
|
+
state: "cancelled",
|
|
147
|
+
output: "cancelled",
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
const cancelledBeforeInvoke = await finalizeIfCancellationRequested({
|
|
151
|
+
getRunCancellation: runtime.getRunCancellation,
|
|
152
|
+
finalizeCancelledRun: runtime.finalizeCancelledRun,
|
|
153
|
+
threadId,
|
|
154
|
+
runId,
|
|
155
|
+
previousState,
|
|
156
|
+
});
|
|
157
|
+
if (cancelledBeforeInvoke) {
|
|
158
|
+
return cancelledBeforeInvoke;
|
|
159
|
+
}
|
|
160
|
+
if (previousState === "queued") {
|
|
161
|
+
await runtime.emit(threadId, runId, 101, "run.dequeued", {
|
|
162
|
+
queuePosition: 0,
|
|
163
|
+
activeRunCount: 0,
|
|
164
|
+
maxConcurrentRuns: 0,
|
|
165
|
+
recoveredOnStartup: true,
|
|
166
|
+
});
|
|
167
|
+
await runtime.setRunStateAndEmit(threadId, runId, 102, "running", {
|
|
168
|
+
previousState: "queued",
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
const continuationState = normalizeContinuationState(previousState);
|
|
172
|
+
try {
|
|
173
|
+
const actual = await runtime.invokeWithHistory(binding, message, threadId, runId, undefined, options.priorHistory, {
|
|
174
|
+
context: options.context,
|
|
175
|
+
state: options.state,
|
|
176
|
+
files: options.files,
|
|
177
|
+
});
|
|
178
|
+
const cancelledAfterInvoke = await finalizeIfCancellationRequested({
|
|
179
|
+
getRunCancellation: runtime.getRunCancellation,
|
|
180
|
+
finalizeCancelledRun: runtime.finalizeCancelledRun,
|
|
181
|
+
threadId,
|
|
182
|
+
runId,
|
|
183
|
+
previousState: continuationState,
|
|
184
|
+
});
|
|
185
|
+
if (cancelledAfterInvoke) {
|
|
186
|
+
return cancelledAfterInvoke;
|
|
187
|
+
}
|
|
188
|
+
const finalized = await runtime.finalizeContinuedRun(binding, threadId, runId, message, actual, {
|
|
189
|
+
previousState: continuationState,
|
|
190
|
+
stateSequence: options.stateSequence ?? 103,
|
|
191
|
+
approvalSequence: options.approvalSequence ?? 104,
|
|
192
|
+
});
|
|
193
|
+
return {
|
|
194
|
+
...finalized,
|
|
195
|
+
agentId,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
await runtime.emitSyntheticFallback(threadId, runId, agentId, error);
|
|
200
|
+
await runtime.setRunStateAndEmit(threadId, runId, 104, "failed", {
|
|
201
|
+
previousState: continuationState,
|
|
202
|
+
error: error instanceof Error ? error.message : String(error),
|
|
203
|
+
});
|
|
204
|
+
return {
|
|
205
|
+
threadId,
|
|
206
|
+
runId,
|
|
207
|
+
agentId,
|
|
208
|
+
state: "failed",
|
|
209
|
+
output: runtime.renderRuntimeFailure(error),
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
finally {
|
|
213
|
+
await runtime.persistence.clearRunRequest(threadId, runId);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { HarnessEvent, InvocationEnvelope, MessageContent, RunResult, RunStartOptions, WorkspaceBundle } from "../../../contracts/types.js";
|
|
2
|
+
import type { PersistedRunRequest } from "../../../persistence/types.js";
|
|
3
|
+
import type { PolicyEngine } from "../system/policy-engine.js";
|
|
4
|
+
type Binding = WorkspaceBundle["bindings"] extends Map<any, infer T> ? T : never;
|
|
5
|
+
type EnsureThreadStartedRuntime = {
|
|
6
|
+
persistence: {
|
|
7
|
+
bootstrapRun?: (input: {
|
|
8
|
+
threadId: string;
|
|
9
|
+
agentId: string;
|
|
10
|
+
runId: string;
|
|
11
|
+
status: RunResult["state"];
|
|
12
|
+
createdAt: string;
|
|
13
|
+
executionMode: string;
|
|
14
|
+
adapterKind: string;
|
|
15
|
+
userMessage: {
|
|
16
|
+
role: "user";
|
|
17
|
+
content: MessageContent;
|
|
18
|
+
runId: string;
|
|
19
|
+
createdAt: string;
|
|
20
|
+
};
|
|
21
|
+
runRequest: PersistedRunRequest;
|
|
22
|
+
createThread: boolean;
|
|
23
|
+
}) => Promise<void>;
|
|
24
|
+
createThread: (input: {
|
|
25
|
+
threadId: string;
|
|
26
|
+
agentId: string;
|
|
27
|
+
runId: string;
|
|
28
|
+
status: RunResult["state"];
|
|
29
|
+
createdAt: string;
|
|
30
|
+
}) => Promise<void>;
|
|
31
|
+
appendThreadMessage: (threadId: string, message: {
|
|
32
|
+
role: "user";
|
|
33
|
+
content: MessageContent;
|
|
34
|
+
runId: string;
|
|
35
|
+
createdAt: string;
|
|
36
|
+
}) => Promise<void>;
|
|
37
|
+
createRun: (input: {
|
|
38
|
+
threadId: string;
|
|
39
|
+
runId: string;
|
|
40
|
+
agentId: string;
|
|
41
|
+
executionMode: string;
|
|
42
|
+
adapterKind: string;
|
|
43
|
+
createdAt: string;
|
|
44
|
+
}) => Promise<void>;
|
|
45
|
+
saveRunRequest: (threadId: string, runId: string, runRequest: PersistedRunRequest) => Promise<void>;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
type PrepareRunStartRuntime = EnsureThreadStartedRuntime & {
|
|
49
|
+
workspace: WorkspaceBundle;
|
|
50
|
+
policyEngine: PolicyEngine;
|
|
51
|
+
resolveSelectedAgentId: (input: MessageContent, requestedAgentId?: string, threadId?: string) => Promise<string>;
|
|
52
|
+
emitRunCreated: (threadId: string, runId: string, payload: Record<string, unknown>) => Promise<HarnessEvent>;
|
|
53
|
+
acquireRunSlot: (threadId?: string, runId?: string, activeState?: RunResult["state"], priority?: number) => Promise<() => Promise<void>>;
|
|
54
|
+
};
|
|
55
|
+
export declare function ensureThreadStarted(runtime: EnsureThreadStartedRuntime, input: {
|
|
56
|
+
selectedAgentId: string;
|
|
57
|
+
binding: Binding;
|
|
58
|
+
message: MessageContent;
|
|
59
|
+
runRequest: PersistedRunRequest;
|
|
60
|
+
existingThreadId?: string;
|
|
61
|
+
}): Promise<{
|
|
62
|
+
threadId: string;
|
|
63
|
+
runId: string;
|
|
64
|
+
createdAt: string;
|
|
65
|
+
isNewThread: boolean;
|
|
66
|
+
}>;
|
|
67
|
+
export declare function prepareRunStart(runtime: PrepareRunStartRuntime, input: {
|
|
68
|
+
options: Pick<RunStartOptions, "input" | "agentId" | "threadId" | "priority">;
|
|
69
|
+
invocation: InvocationEnvelope;
|
|
70
|
+
runCreatedPayload: (binding: Binding, selectedAgentId: string) => Record<string, unknown>;
|
|
71
|
+
}): Promise<{
|
|
72
|
+
binding: Binding;
|
|
73
|
+
selectedAgentId: string;
|
|
74
|
+
priority: number;
|
|
75
|
+
threadId: string;
|
|
76
|
+
runId: string;
|
|
77
|
+
isNewThread: boolean;
|
|
78
|
+
runCreatedEventPromise: Promise<HarnessEvent>;
|
|
79
|
+
releaseRunSlotPromise: Promise<() => Promise<void>>;
|
|
80
|
+
}>;
|
|
81
|
+
export declare function defaultRequestedAgentId(agentId?: string): string;
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { AUTO_AGENT_ID } from "../../../contracts/types.js";
|
|
2
|
+
import { createPersistentId } from "../../../utils/id.js";
|
|
3
|
+
import { normalizeMessageContent } from "../../../utils/message-content.js";
|
|
4
|
+
import { buildPersistedRunRequest, normalizeRunPriority } from "./helpers.js";
|
|
5
|
+
import { getRequiredWorkspaceBinding } from "../bindings.js";
|
|
6
|
+
import { getBindingAdapterKind } from "../../support/compiled-binding.js";
|
|
7
|
+
export async function ensureThreadStarted(runtime, input) {
|
|
8
|
+
const { selectedAgentId, binding, message, runRequest, existingThreadId } = input;
|
|
9
|
+
const threadId = existingThreadId ?? createPersistentId();
|
|
10
|
+
const runId = createPersistentId();
|
|
11
|
+
const createdAt = new Date().toISOString();
|
|
12
|
+
const isNewThread = !existingThreadId;
|
|
13
|
+
const userMessage = {
|
|
14
|
+
role: "user",
|
|
15
|
+
content: normalizeMessageContent(message),
|
|
16
|
+
runId,
|
|
17
|
+
createdAt,
|
|
18
|
+
};
|
|
19
|
+
if (typeof runtime.persistence.bootstrapRun === "function") {
|
|
20
|
+
await runtime.persistence.bootstrapRun({
|
|
21
|
+
threadId,
|
|
22
|
+
agentId: binding.agent.id,
|
|
23
|
+
runId,
|
|
24
|
+
status: "running",
|
|
25
|
+
createdAt,
|
|
26
|
+
executionMode: getBindingAdapterKind(binding),
|
|
27
|
+
adapterKind: getBindingAdapterKind(binding),
|
|
28
|
+
userMessage,
|
|
29
|
+
runRequest,
|
|
30
|
+
createThread: isNewThread,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (isNewThread) {
|
|
35
|
+
await runtime.persistence.createThread({
|
|
36
|
+
threadId,
|
|
37
|
+
agentId: selectedAgentId,
|
|
38
|
+
runId,
|
|
39
|
+
status: "running",
|
|
40
|
+
createdAt,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
await Promise.all([
|
|
44
|
+
runtime.persistence.appendThreadMessage(threadId, userMessage),
|
|
45
|
+
runtime.persistence.createRun({
|
|
46
|
+
threadId,
|
|
47
|
+
runId,
|
|
48
|
+
agentId: binding.agent.id,
|
|
49
|
+
executionMode: getBindingAdapterKind(binding),
|
|
50
|
+
adapterKind: getBindingAdapterKind(binding),
|
|
51
|
+
createdAt,
|
|
52
|
+
}),
|
|
53
|
+
runtime.persistence.saveRunRequest(threadId, runId, runRequest),
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
return { threadId, runId, createdAt, isNewThread };
|
|
57
|
+
}
|
|
58
|
+
export async function prepareRunStart(runtime, input) {
|
|
59
|
+
const { options, invocation, runCreatedPayload } = input;
|
|
60
|
+
const selectedAgentId = await runtime.resolveSelectedAgentId(options.input, options.agentId, options.threadId);
|
|
61
|
+
const binding = getRequiredWorkspaceBinding(runtime.workspace, selectedAgentId);
|
|
62
|
+
const policyDecision = runtime.policyEngine.evaluate(binding);
|
|
63
|
+
if (!policyDecision.allowed) {
|
|
64
|
+
throw new Error(`Policy evaluation blocked agent ${selectedAgentId}: ${policyDecision.reasons.join(", ")}`);
|
|
65
|
+
}
|
|
66
|
+
const priority = normalizeRunPriority(options.priority);
|
|
67
|
+
const runRequest = buildPersistedRunRequest(options.input, invocation, priority);
|
|
68
|
+
const { threadId, runId, isNewThread } = await ensureThreadStarted(runtime, {
|
|
69
|
+
selectedAgentId,
|
|
70
|
+
binding,
|
|
71
|
+
message: options.input,
|
|
72
|
+
runRequest,
|
|
73
|
+
existingThreadId: options.threadId,
|
|
74
|
+
});
|
|
75
|
+
return {
|
|
76
|
+
binding,
|
|
77
|
+
selectedAgentId,
|
|
78
|
+
priority,
|
|
79
|
+
threadId,
|
|
80
|
+
runId,
|
|
81
|
+
isNewThread,
|
|
82
|
+
runCreatedEventPromise: runtime.emitRunCreated(threadId, runId, runCreatedPayload(binding, selectedAgentId)),
|
|
83
|
+
releaseRunSlotPromise: runtime.acquireRunSlot(threadId, runId, "running", priority),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export function defaultRequestedAgentId(agentId) {
|
|
87
|
+
return agentId ?? AUTO_AGENT_ID;
|
|
88
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RunResult, ThreadSummary } from "../../../contracts/types.js";
|
|
2
2
|
import type { RuntimePersistence } from "../../../persistence/types.js";
|
|
3
3
|
import type { ConcurrencyConfig, RecoveryConfig } from "../../../workspace/support/workspace-ref-utils.js";
|
|
4
|
+
import { type StartupRecoveryContext } from "./recovery.js";
|
|
4
5
|
type Startable = {
|
|
5
6
|
start(): Promise<void>;
|
|
6
7
|
};
|
|
@@ -11,7 +12,7 @@ export declare function initializeHarnessRuntime(input: {
|
|
|
11
12
|
export declare function recoverStartupRuns(input: {
|
|
12
13
|
recoveryConfig: RecoveryConfig;
|
|
13
14
|
persistence: RuntimePersistence;
|
|
14
|
-
createStartupRecoveryContext: () =>
|
|
15
|
+
createStartupRecoveryContext: () => StartupRecoveryContext;
|
|
15
16
|
reclaimExpiredClaimedRuns: (nowIso?: string) => Promise<void>;
|
|
16
17
|
}): Promise<void>;
|
|
17
18
|
export declare function reclaimExpiredClaimedRuns(input: {
|
|
@@ -1,13 +1,48 @@
|
|
|
1
|
+
import { recoverQueuedStartupRun, recoverResumingStartupRun, recoverRunningStartupRun, } from "./recovery.js";
|
|
1
2
|
export async function initializeHarnessRuntime(input) {
|
|
2
3
|
await input.persistence.initialize();
|
|
3
4
|
await input.healthMonitor?.start();
|
|
4
5
|
}
|
|
5
6
|
export async function recoverStartupRuns(input) {
|
|
6
|
-
|
|
7
|
+
if (!input.recoveryConfig.enabled) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
await input.reclaimExpiredClaimedRuns();
|
|
11
|
+
const threads = await input.persistence.listSessions();
|
|
12
|
+
if (threads.length === 0) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const context = input.createStartupRecoveryContext();
|
|
16
|
+
for (const thread of threads) {
|
|
17
|
+
if (await recoverQueuedStartupRun(context, thread)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (await recoverRunningStartupRun(context, thread)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
await recoverResumingStartupRun(context, thread);
|
|
24
|
+
}
|
|
7
25
|
}
|
|
8
26
|
export async function reclaimExpiredClaimedRuns(input, nowIso = new Date().toISOString()) {
|
|
9
|
-
|
|
10
|
-
|
|
27
|
+
const expiredRuns = await input.persistence.listExpiredClaimedRuns(nowIso);
|
|
28
|
+
if (expiredRuns.length === 0) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const activeRunCount = input.getActiveRunSlots();
|
|
32
|
+
const maxConcurrentRuns = input.concurrencyConfig.maxConcurrentRuns;
|
|
33
|
+
for (const [index, claimedRun] of expiredRuns.entries()) {
|
|
34
|
+
await input.persistence.releaseRunClaim(claimedRun.runId);
|
|
35
|
+
await input.setRunStateAndEmit(claimedRun.threadId, claimedRun.runId, 100, "queued", {
|
|
36
|
+
previousState: "claimed",
|
|
37
|
+
});
|
|
38
|
+
await input.emit(claimedRun.threadId, claimedRun.runId, 101, "run.queued", {
|
|
39
|
+
queuePosition: activeRunCount + index + 1,
|
|
40
|
+
activeRunCount,
|
|
41
|
+
...(maxConcurrentRuns !== undefined ? { maxConcurrentRuns } : {}),
|
|
42
|
+
priority: claimedRun.priority,
|
|
43
|
+
recoveryKind: "startup-claim-recovery",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
11
46
|
}
|
|
12
47
|
export async function isStaleRunningRun(input, thread, nowMs = Date.now()) {
|
|
13
48
|
const control = await input.persistence.getRunControl(thread.latestRunId);
|
|
@@ -33,10 +33,14 @@ export declare class AgentHarnessRuntime {
|
|
|
33
33
|
private pendingRunInsertionOrder;
|
|
34
34
|
private readonly pendingRunSlots;
|
|
35
35
|
private runtimeEventSequence;
|
|
36
|
+
private initialized;
|
|
37
|
+
private closed;
|
|
36
38
|
private readonly backgroundEventRuntime;
|
|
39
|
+
private readonly runtimeEventOperations;
|
|
37
40
|
private defaultRunRoot;
|
|
38
41
|
private getDefaultHostAgentId;
|
|
39
42
|
private resolveSelectedAgentId;
|
|
43
|
+
private createPrepareRunStartRuntime;
|
|
40
44
|
constructor(workspace: WorkspaceBundle, runtimeAdapterOptions?: RuntimeAdapterOptions);
|
|
41
45
|
private createHealthMonitor;
|
|
42
46
|
private recordLlmSuccess;
|
|
@@ -75,7 +79,7 @@ export declare class AgentHarnessRuntime {
|
|
|
75
79
|
}): Promise<string>;
|
|
76
80
|
private emit;
|
|
77
81
|
private trackBackgroundTask;
|
|
78
|
-
private
|
|
82
|
+
private resolveToolMcpServerTools;
|
|
79
83
|
private loadPriorHistory;
|
|
80
84
|
private loadRunInput;
|
|
81
85
|
private getRunCancellation;
|
|
@@ -89,10 +93,8 @@ export declare class AgentHarnessRuntime {
|
|
|
89
93
|
private requestApprovalAndEmit;
|
|
90
94
|
private isDecisionRun;
|
|
91
95
|
private notifyListener;
|
|
92
|
-
private prepareRunStart;
|
|
93
96
|
private acquireRunSlot;
|
|
94
97
|
private dropPendingRunSlot;
|
|
95
|
-
private dispatchRunListeners;
|
|
96
98
|
run(options: RunOptions): Promise<RunResult>;
|
|
97
99
|
streamEvents(options: RunStartOptions): AsyncGenerator<HarnessStreamItem>;
|
|
98
100
|
resume(options: ResumeOptions): Promise<RunResult>;
|