@botbotgo/agent-harness 0.0.99 → 0.0.101
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/README.md +3 -6
- package/README.zh.md +2 -2
- package/dist/benchmark/upstream-runtime-ab-benchmark.d.ts +1 -1
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -2
- package/dist/contracts/core.d.ts +2 -2
- package/dist/contracts/runtime.d.ts +1 -5
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -1
- package/dist/resource/resource-impl.js +78 -76
- package/dist/runtime/adapter/deepagent-runnable-config.d.ts +30 -0
- package/dist/runtime/adapter/deepagent-runnable-config.js +22 -0
- package/dist/runtime/adapter/index.d.ts +0 -2
- package/dist/runtime/adapter/index.js +0 -2
- package/dist/runtime/adapter/invocation-result.d.ts +13 -0
- package/dist/runtime/adapter/invocation-result.js +40 -0
- package/dist/runtime/adapter/langchain-runnable-config.d.ts +25 -0
- package/dist/runtime/adapter/langchain-runnable-config.js +19 -0
- package/dist/runtime/adapter/local-tool-invocation.d.ts +23 -0
- package/dist/runtime/adapter/local-tool-invocation.js +64 -0
- package/dist/runtime/adapter/runtime-adapter-support.d.ts +18 -0
- package/dist/runtime/adapter/runtime-adapter-support.js +54 -0
- package/dist/runtime/adapter/stream-event-projection.d.ts +19 -0
- package/dist/runtime/adapter/stream-event-projection.js +79 -0
- package/dist/runtime/adapter/stream-text-consumption.d.ts +4 -0
- package/dist/runtime/adapter/stream-text-consumption.js +18 -0
- package/dist/runtime/adapter/tool/builtin-middleware-tools.d.ts +64 -0
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +144 -0
- package/dist/runtime/adapter/tool/tool-replay.d.ts +18 -0
- package/dist/runtime/adapter/tool/tool-replay.js +26 -0
- package/dist/runtime/agent-runtime-adapter.d.ts +2 -54
- package/dist/runtime/agent-runtime-adapter.js +122 -1568
- package/dist/runtime/harness/run/helpers.js +2 -8
- package/dist/runtime/harness/run/recovery.d.ts +42 -0
- package/dist/runtime/harness/run/recovery.js +139 -0
- package/dist/runtime/harness/run/routing.d.ts +1 -3
- package/dist/runtime/harness/run/routing.js +2 -25
- package/dist/runtime/harness/run/run-lifecycle.d.ts +0 -11
- package/dist/runtime/harness/run/run-lifecycle.js +7 -50
- package/dist/runtime/harness/runtime-defaults.d.ts +4 -0
- package/dist/runtime/harness/runtime-defaults.js +39 -0
- package/dist/runtime/harness/system/inventory.js +2 -1
- package/dist/runtime/harness/system/skill-requirements.d.ts +1 -0
- package/dist/runtime/harness.d.ts +5 -24
- package/dist/runtime/harness.js +356 -536
- package/dist/runtime/index.d.ts +1 -12
- package/dist/runtime/index.js +1 -12
- package/dist/runtime/support/compiled-binding.d.ts +0 -2
- package/dist/runtime/support/compiled-binding.js +3 -22
- package/dist/runtime/support/harness-support.d.ts +0 -11
- package/dist/runtime/support/harness-support.js +1 -44
- package/dist/runtime/support/index.d.ts +1 -1
- package/dist/runtime/support/index.js +1 -1
- package/dist/runtime/support/runtime-factories.js +2 -2
- package/dist/workspace/agent-binding-compiler.js +9 -93
- package/dist/workspace/index.d.ts +0 -5
- package/dist/workspace/index.js +0 -5
- package/dist/workspace/object-loader.js +44 -99
- package/dist/workspace/support/agent-capabilities.js +2 -2
- package/dist/workspace/support/workspace-ref-utils.d.ts +0 -2
- package/dist/workspace/support/workspace-ref-utils.js +0 -17
- package/dist/workspace/validate.js +1 -1
- package/package.json +1 -1
- package/dist/config/workflows/langgraph-workflows.yaml +0 -570
- package/dist/config/workflows/runtime-profiles.yaml +0 -94
- package/dist/runtime/adapter/langgraph/presets.d.ts +0 -25
- package/dist/runtime/adapter/langgraph/presets.js +0 -165
- package/dist/runtime/adapter/langgraph/profiles.d.ts +0 -6
- package/dist/runtime/adapter/langgraph/profiles.js +0 -206
- package/dist/runtime/checkpoint-maintenance.d.ts +0 -1
- package/dist/runtime/checkpoint-maintenance.js +0 -1
- package/dist/runtime/file-checkpoint-saver.d.ts +0 -1
- package/dist/runtime/file-checkpoint-saver.js +0 -1
- package/dist/runtime/sqlite-maintained-checkpoint-saver.d.ts +0 -1
- package/dist/runtime/sqlite-maintained-checkpoint-saver.js +0 -1
|
@@ -42,17 +42,11 @@ export function normalizeRunPriority(priority) {
|
|
|
42
42
|
return Math.trunc(priority);
|
|
43
43
|
}
|
|
44
44
|
export function resolveRunListeners(options) {
|
|
45
|
-
const runtimeListeners = "runtimeListeners" in options ? options.runtimeListeners : undefined;
|
|
46
|
-
const frontendListeners = "frontendListeners" in options ? options.frontendListeners : undefined;
|
|
47
45
|
const listeners = options.listeners;
|
|
48
|
-
if (!listeners
|
|
46
|
+
if (!listeners) {
|
|
49
47
|
return undefined;
|
|
50
48
|
}
|
|
51
|
-
return
|
|
52
|
-
...(runtimeListeners ?? {}),
|
|
53
|
-
...(frontendListeners ?? {}),
|
|
54
|
-
...(listeners ?? {}),
|
|
55
|
-
};
|
|
49
|
+
return listeners;
|
|
56
50
|
}
|
|
57
51
|
export function mergeRunResultOutput(result, streamedOutput) {
|
|
58
52
|
return {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { MessageContent, RunResult, ThreadSummary, WorkspaceBundle } from "../../../contracts/types.js";
|
|
2
|
+
import type { RuntimePersistence } from "../../../persistence/types.js";
|
|
3
|
+
import type { AgentRuntimeAdapter } from "../../agent-runtime-adapter.js";
|
|
4
|
+
import type { ConcurrencyConfig, RecoveryConfig } from "../../../workspace/support/workspace-ref-utils.js";
|
|
5
|
+
type RecoveryBinding = WorkspaceBundle["bindings"] extends Map<any, infer T> ? T : never;
|
|
6
|
+
type StartupRecoveryContext = {
|
|
7
|
+
persistence: RuntimePersistence;
|
|
8
|
+
workspace: WorkspaceBundle;
|
|
9
|
+
runtimeAdapter: AgentRuntimeAdapter;
|
|
10
|
+
recoveryConfig: RecoveryConfig;
|
|
11
|
+
concurrencyConfig: ConcurrencyConfig;
|
|
12
|
+
getBinding: (agentId: string) => RecoveryBinding | undefined;
|
|
13
|
+
acquireRunSlot: (threadId?: string, runId?: string, activeState?: RunResult["state"], priority?: number) => Promise<() => Promise<void>>;
|
|
14
|
+
executeQueuedRun: (binding: RecoveryBinding, input: MessageContent, threadId: string, runId: string, agentId: string, options?: {
|
|
15
|
+
context?: Record<string, unknown>;
|
|
16
|
+
state?: Record<string, unknown>;
|
|
17
|
+
files?: Record<string, unknown>;
|
|
18
|
+
previousState?: RunResult["state"];
|
|
19
|
+
stateSequence?: number;
|
|
20
|
+
approvalSequence?: number;
|
|
21
|
+
}) => Promise<RunResult>;
|
|
22
|
+
setRunStateAndEmit: (threadId: string, runId: string, sequence: number, state: RunResult["state"], options: {
|
|
23
|
+
previousState: string | null;
|
|
24
|
+
checkpointRef?: string | null;
|
|
25
|
+
error?: string;
|
|
26
|
+
}) => Promise<unknown>;
|
|
27
|
+
emit: (threadId: string, runId: string, sequence: number, eventType: string, payload: Record<string, unknown>) => Promise<unknown>;
|
|
28
|
+
loadRunInput: (threadId: string, runId: string) => Promise<MessageContent>;
|
|
29
|
+
finalizeContinuedRun: (binding: RecoveryBinding, threadId: string, runId: string, input: MessageContent, actual: RunResult, options: {
|
|
30
|
+
previousState: RunResult["state"] | null;
|
|
31
|
+
stateSequence: number;
|
|
32
|
+
approvalSequence?: number;
|
|
33
|
+
}) => Promise<RunResult>;
|
|
34
|
+
supportsRunningReplay: (binding: RecoveryBinding) => boolean;
|
|
35
|
+
isStaleRunningRun: (thread: ThreadSummary, nowMs?: number) => Promise<boolean>;
|
|
36
|
+
recordLlmSuccess: (startedAt: number) => void;
|
|
37
|
+
recordLlmFailure: (startedAt: number) => void;
|
|
38
|
+
};
|
|
39
|
+
export declare function recoverQueuedStartupRun(context: StartupRecoveryContext, thread: ThreadSummary): Promise<boolean>;
|
|
40
|
+
export declare function recoverRunningStartupRun(context: StartupRecoveryContext, thread: ThreadSummary): Promise<boolean>;
|
|
41
|
+
export declare function recoverResumingStartupRun(context: StartupRecoveryContext, thread: ThreadSummary): Promise<boolean>;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { normalizeRunPriority } from "./helpers.js";
|
|
2
|
+
export async function recoverQueuedStartupRun(context, thread) {
|
|
3
|
+
if (thread.status !== "queued") {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
const runMeta = await context.persistence.getRunMeta(thread.threadId, thread.latestRunId);
|
|
7
|
+
const binding = context.getBinding(runMeta.agentId);
|
|
8
|
+
if (!binding) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
const request = await context.persistence.getRunRequest(thread.threadId, thread.latestRunId);
|
|
12
|
+
if (!request) {
|
|
13
|
+
await context.setRunStateAndEmit(thread.threadId, thread.latestRunId, 100, "failed", {
|
|
14
|
+
previousState: "queued",
|
|
15
|
+
error: "missing persisted run request for queued run recovery",
|
|
16
|
+
});
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
const releaseRunSlot = await context.acquireRunSlot(thread.threadId, thread.latestRunId, "running", normalizeRunPriority(request.priority));
|
|
20
|
+
try {
|
|
21
|
+
await context.executeQueuedRun(binding, request.input, thread.threadId, thread.latestRunId, runMeta.agentId, {
|
|
22
|
+
context: request.invocation?.context,
|
|
23
|
+
state: request.invocation?.inputs,
|
|
24
|
+
files: request.invocation?.attachments,
|
|
25
|
+
previousState: "queued",
|
|
26
|
+
stateSequence: 103,
|
|
27
|
+
approvalSequence: 104,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
await releaseRunSlot();
|
|
32
|
+
}
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
export async function recoverRunningStartupRun(context, thread) {
|
|
36
|
+
if (thread.status !== "running") {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const isStale = await context.isStaleRunningRun(thread);
|
|
40
|
+
if (!isStale) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
const runMeta = await context.persistence.getRunMeta(thread.threadId, thread.latestRunId);
|
|
44
|
+
const binding = context.getBinding(runMeta.agentId);
|
|
45
|
+
if (!binding) {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
if (!context.supportsRunningReplay(binding)) {
|
|
49
|
+
await context.setRunStateAndEmit(thread.threadId, thread.latestRunId, 100, "failed", {
|
|
50
|
+
previousState: "running",
|
|
51
|
+
error: "stale running run cannot be replayed safely",
|
|
52
|
+
});
|
|
53
|
+
await context.persistence.releaseRunClaim(thread.latestRunId);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
const request = await context.persistence.getRunRequest(thread.threadId, thread.latestRunId);
|
|
57
|
+
if (!request) {
|
|
58
|
+
await context.setRunStateAndEmit(thread.threadId, thread.latestRunId, 100, "failed", {
|
|
59
|
+
previousState: "running",
|
|
60
|
+
error: "missing persisted run request for stale running run recovery",
|
|
61
|
+
});
|
|
62
|
+
await context.persistence.releaseRunClaim(thread.latestRunId);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
const releaseRunSlot = await context.acquireRunSlot(thread.threadId, thread.latestRunId, "running", normalizeRunPriority(request.priority));
|
|
66
|
+
try {
|
|
67
|
+
await context.emit(thread.threadId, thread.latestRunId, 100, "run.resumed", {
|
|
68
|
+
resumeKind: "startup-running-recovery",
|
|
69
|
+
state: "running",
|
|
70
|
+
});
|
|
71
|
+
await context.executeQueuedRun(binding, request.input, thread.threadId, thread.latestRunId, runMeta.agentId, {
|
|
72
|
+
context: request.invocation?.context,
|
|
73
|
+
state: request.invocation?.inputs,
|
|
74
|
+
files: request.invocation?.attachments,
|
|
75
|
+
previousState: "running",
|
|
76
|
+
stateSequence: 103,
|
|
77
|
+
approvalSequence: 104,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
await releaseRunSlot();
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
export async function recoverResumingStartupRun(context, thread) {
|
|
86
|
+
if (thread.status !== "resuming" || !context.recoveryConfig.resumeResumingRunsOnStartup) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
const binding = context.getBinding(thread.agentId);
|
|
90
|
+
if (!binding) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
const recoveryIntent = await context.persistence.getRecoveryIntent(thread.threadId, thread.latestRunId);
|
|
94
|
+
if (!recoveryIntent || recoveryIntent.kind !== "approval-decision") {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (recoveryIntent.attempts >= context.recoveryConfig.maxRecoveryAttempts) {
|
|
98
|
+
await context.persistence.setRunState(thread.threadId, thread.latestRunId, "failed", recoveryIntent.checkpointRef);
|
|
99
|
+
await context.persistence.clearRecoveryIntent(thread.threadId, thread.latestRunId);
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
await context.persistence.saveRecoveryIntent(thread.threadId, thread.latestRunId, {
|
|
103
|
+
...recoveryIntent,
|
|
104
|
+
attempts: recoveryIntent.attempts + 1,
|
|
105
|
+
});
|
|
106
|
+
await context.emit(thread.threadId, thread.latestRunId, 100, "run.resumed", {
|
|
107
|
+
resumeKind: "startup-recovery",
|
|
108
|
+
checkpointRef: recoveryIntent.checkpointRef,
|
|
109
|
+
state: "resuming",
|
|
110
|
+
});
|
|
111
|
+
const history = await context.persistence.listThreadMessages(thread.threadId);
|
|
112
|
+
const priorHistory = history.filter((message) => message.runId !== thread.latestRunId);
|
|
113
|
+
const runInput = await context.loadRunInput(thread.threadId, thread.latestRunId);
|
|
114
|
+
const startedAt = Date.now();
|
|
115
|
+
try {
|
|
116
|
+
const actual = await context.runtimeAdapter.invoke(binding, "", thread.threadId, thread.latestRunId, recoveryIntent.resumePayload, priorHistory);
|
|
117
|
+
context.recordLlmSuccess(startedAt);
|
|
118
|
+
await context.persistence.clearRecoveryIntent(thread.threadId, thread.latestRunId);
|
|
119
|
+
await context.finalizeContinuedRun(binding, thread.threadId, thread.latestRunId, runInput, actual, {
|
|
120
|
+
previousState: "resuming",
|
|
121
|
+
stateSequence: 101,
|
|
122
|
+
approvalSequence: 102,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
context.recordLlmFailure(startedAt);
|
|
127
|
+
if (recoveryIntent.attempts + 1 >= context.recoveryConfig.maxRecoveryAttempts) {
|
|
128
|
+
await context.persistence.setRunState(thread.threadId, thread.latestRunId, "failed", recoveryIntent.checkpointRef);
|
|
129
|
+
await context.persistence.clearRecoveryIntent(thread.threadId, thread.latestRunId);
|
|
130
|
+
await context.emit(thread.threadId, thread.latestRunId, 101, "run.state.changed", {
|
|
131
|
+
previousState: "resuming",
|
|
132
|
+
state: "failed",
|
|
133
|
+
checkpointRef: recoveryIntent.checkpointRef,
|
|
134
|
+
error: error instanceof Error ? error.message : String(error),
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { type MessageContent, type ThreadSummary, type
|
|
2
|
-
export declare function heuristicHostRoute(workspace: WorkspaceBundle, input: MessageContent): string;
|
|
1
|
+
import { type MessageContent, type ThreadSummary, type WorkspaceBundle } from "../../../contracts/types.js";
|
|
3
2
|
export declare function getDefaultHostAgentId(workspace: WorkspaceBundle, preferredHostAgentId: string): string;
|
|
4
|
-
export declare function buildRoutingInput(input: MessageContent, history?: TranscriptMessage[]): string;
|
|
5
3
|
export declare function resolveSelectedAgentId(options: {
|
|
6
4
|
workspace: WorkspaceBundle;
|
|
7
5
|
input: MessageContent;
|
|
@@ -1,35 +1,12 @@
|
|
|
1
1
|
import { AUTO_AGENT_ID } from "../../../contracts/types.js";
|
|
2
|
-
import {
|
|
3
|
-
import { heuristicRoute, inferRoutingBindings } from "../../support/harness-support.js";
|
|
2
|
+
import { inferRoutingBindings } from "../../support/harness-support.js";
|
|
4
3
|
import { isRuntimeEntryBinding } from "../../support/runtime-entry.js";
|
|
5
|
-
export function heuristicHostRoute(workspace, input) {
|
|
6
|
-
const { primaryBinding, secondaryBinding } = inferRoutingBindings(workspace);
|
|
7
|
-
return heuristicRoute(extractMessageText(input), primaryBinding, secondaryBinding);
|
|
8
|
-
}
|
|
9
4
|
export function getDefaultHostAgentId(workspace, preferredHostAgentId) {
|
|
10
5
|
const preferredBinding = workspace.bindings.get(preferredHostAgentId);
|
|
11
6
|
if (preferredBinding && isRuntimeEntryBinding(preferredBinding)) {
|
|
12
7
|
return preferredBinding.agent.id;
|
|
13
8
|
}
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
export function buildRoutingInput(input, history = []) {
|
|
17
|
-
const inputText = extractMessageText(input);
|
|
18
|
-
const priorHistory = history.filter((message) => extractMessageText(message.content).trim());
|
|
19
|
-
if (priorHistory.length === 0) {
|
|
20
|
-
return inputText;
|
|
21
|
-
}
|
|
22
|
-
const recentTurns = priorHistory.slice(-6).map((message) => {
|
|
23
|
-
const role = message.role === "assistant" ? "assistant" : "user";
|
|
24
|
-
const compact = extractMessageText(message.content).replace(/\s+/g, " ").trim();
|
|
25
|
-
return `${role}: ${compact.slice(0, 240)}`;
|
|
26
|
-
});
|
|
27
|
-
return [
|
|
28
|
-
"Recent conversation context:",
|
|
29
|
-
...recentTurns,
|
|
30
|
-
"",
|
|
31
|
-
`Current user request: ${inputText}`,
|
|
32
|
-
].join("\n");
|
|
9
|
+
return inferRoutingBindings(workspace).primaryBinding?.agent.id ?? "agent";
|
|
33
10
|
}
|
|
34
11
|
export async function resolveSelectedAgentId(options) {
|
|
35
12
|
const { workspace, input, requestedAgentId, threadId, preferredHostAgentId, getThreadSummary } = options;
|
|
@@ -13,22 +13,11 @@ type LifecycleRuntime<TBinding> = {
|
|
|
13
13
|
approval: InternalApprovalRecord;
|
|
14
14
|
event: HarnessEvent;
|
|
15
15
|
}>;
|
|
16
|
-
synthesizeFinalResult: (binding: TBinding, input: MessageContent, actual: RunResult) => Promise<{
|
|
17
|
-
output: string;
|
|
18
|
-
finalMessageText?: string;
|
|
19
|
-
modelId: string;
|
|
20
|
-
} | null | undefined>;
|
|
21
|
-
reviewRunResult: (binding: TBinding, input: MessageContent, actual: RunResult) => Promise<{
|
|
22
|
-
modelId: string;
|
|
23
|
-
assessment: string;
|
|
24
|
-
} | null | undefined>;
|
|
25
16
|
};
|
|
26
17
|
export declare function appendAssistantMessage(persistence: Pick<RuntimePersistence, "appendThreadMessage">, threadId: string, runId: string, content?: string): Promise<void>;
|
|
27
18
|
export declare function checkpointRefForState(threadId: string, runId: string, state: RunResult["state"]): string | null;
|
|
28
19
|
export declare function expirePendingApprovals(runtime: Pick<LifecycleRuntime<never>, "persistence" | "emit">, threadId: string, runId: string): Promise<void>;
|
|
29
20
|
export declare function finalizeCancelledRun(runtime: Pick<LifecycleRuntime<never>, "persistence" | "emit" | "setRunStateAndEmit">, threadId: string, runId: string, previousState: RunResult["state"] | null, reason?: string): Promise<RunResult>;
|
|
30
|
-
export declare function synthesizeCompletedRun<TBinding>(runtime: Pick<LifecycleRuntime<TBinding>, "synthesizeFinalResult">, binding: TBinding, input: MessageContent, actual: RunResult): Promise<RunResult>;
|
|
31
|
-
export declare function reviewCompletedRun<TBinding>(runtime: Pick<LifecycleRuntime<TBinding>, "reviewRunResult" | "emit">, binding: TBinding, threadId: string, runId: string, input: MessageContent, actual: RunResult): Promise<void>;
|
|
32
21
|
export declare function finalizeContinuedRun<TBinding>(runtime: LifecycleRuntime<TBinding>, binding: TBinding, threadId: string, runId: string, input: MessageContent, actual: RunResult, options: {
|
|
33
22
|
previousState: RunResult["state"] | null;
|
|
34
23
|
stateSequence: number;
|
|
@@ -45,65 +45,22 @@ export async function finalizeCancelledRun(runtime, threadId, runId, previousSta
|
|
|
45
45
|
output: reason ? `cancelled: ${reason}` : "cancelled",
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
|
-
export async function synthesizeCompletedRun(runtime, binding, input, actual) {
|
|
49
|
-
try {
|
|
50
|
-
const synthesized = await runtime.synthesizeFinalResult(binding, input, actual);
|
|
51
|
-
if (!synthesized) {
|
|
52
|
-
return actual;
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
...actual,
|
|
56
|
-
output: synthesized.output,
|
|
57
|
-
finalMessageText: synthesized.finalMessageText,
|
|
58
|
-
metadata: {
|
|
59
|
-
...(typeof actual.metadata === "object" && actual.metadata ? actual.metadata : {}),
|
|
60
|
-
finalSynthesis: {
|
|
61
|
-
modelId: synthesized.modelId,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
catch {
|
|
67
|
-
return actual;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
export async function reviewCompletedRun(runtime, binding, threadId, runId, input, actual) {
|
|
71
|
-
try {
|
|
72
|
-
const review = await runtime.reviewRunResult(binding, input, actual);
|
|
73
|
-
if (!review) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
await runtime.emit(threadId, runId, 7, "run.reviewed", {
|
|
77
|
-
modelId: review.modelId,
|
|
78
|
-
assessment: review.assessment,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
// Review is advisory; do not fail the completed run if the review pass fails.
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
48
|
export async function finalizeContinuedRun(runtime, binding, threadId, runId, input, actual, options) {
|
|
86
49
|
let approval;
|
|
87
|
-
|
|
88
|
-
? await synthesizeCompletedRun(runtime, binding, input, actual)
|
|
89
|
-
: actual;
|
|
90
|
-
await appendAssistantMessage(runtime.persistence, threadId, runId, finalizedActual.output);
|
|
50
|
+
await appendAssistantMessage(runtime.persistence, threadId, runId, actual.output);
|
|
91
51
|
const checkpointRef = checkpointRefForState(threadId, runId, actual.state);
|
|
92
|
-
await runtime.setRunStateAndEmit(threadId, runId, options.stateSequence,
|
|
52
|
+
await runtime.setRunStateAndEmit(threadId, runId, options.stateSequence, actual.state, {
|
|
93
53
|
previousState: options.previousState,
|
|
94
54
|
checkpointRef,
|
|
95
55
|
});
|
|
96
|
-
if (
|
|
97
|
-
approval = (await runtime.requestApprovalAndEmit(threadId, runId, input,
|
|
98
|
-
}
|
|
99
|
-
if (finalizedActual.state === "completed") {
|
|
100
|
-
await reviewCompletedRun(runtime, binding, threadId, runId, input, finalizedActual);
|
|
56
|
+
if (actual.state === "waiting_for_approval" && options.approvalSequence) {
|
|
57
|
+
approval = (await runtime.requestApprovalAndEmit(threadId, runId, input, actual.interruptContent, checkpointRef, options.approvalSequence)).approval;
|
|
101
58
|
}
|
|
102
59
|
return {
|
|
103
|
-
...
|
|
60
|
+
...actual,
|
|
104
61
|
threadId,
|
|
105
62
|
runId,
|
|
106
|
-
approvalId: approval?.approvalId ??
|
|
107
|
-
pendingActionId: approval?.pendingActionId ??
|
|
63
|
+
approvalId: approval?.approvalId ?? actual.approvalId,
|
|
64
|
+
pendingActionId: approval?.pendingActionId ?? actual.pendingActionId,
|
|
108
65
|
};
|
|
109
66
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RuntimeHealthSnapshot, WorkspaceBundle } from "../../contracts/types.js";
|
|
2
|
+
export declare function isThreadMemorySyncEnabled(workspace: WorkspaceBundle): boolean;
|
|
3
|
+
export declare function isInventoryEnabled(workspace: WorkspaceBundle): boolean;
|
|
4
|
+
export declare function createDefaultHealthSnapshot(activeRunSlots: number, pendingRunSlots: number): RuntimeHealthSnapshot;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function isThreadMemorySyncEnabled(workspace) {
|
|
2
|
+
const runtimeMemory = workspace.bindings.values().next().value?.harnessRuntime.runtimeMemory;
|
|
3
|
+
const syncConfig = typeof runtimeMemory?.threadMemorySync === "object" && runtimeMemory.threadMemorySync
|
|
4
|
+
? runtimeMemory.threadMemorySync
|
|
5
|
+
: undefined;
|
|
6
|
+
return runtimeMemory?.enabled === true && syncConfig?.enabled === true;
|
|
7
|
+
}
|
|
8
|
+
export function isInventoryEnabled(workspace) {
|
|
9
|
+
const runtime = workspace.refs.get("runtime/default");
|
|
10
|
+
const value = runtime && "value" in runtime && typeof runtime.value === "object" && runtime.value
|
|
11
|
+
? runtime.value
|
|
12
|
+
: undefined;
|
|
13
|
+
const inventory = typeof value?.inventory === "object" && value.inventory
|
|
14
|
+
? value.inventory
|
|
15
|
+
: undefined;
|
|
16
|
+
return inventory?.enabled === true;
|
|
17
|
+
}
|
|
18
|
+
export function createDefaultHealthSnapshot(activeRunSlots, pendingRunSlots) {
|
|
19
|
+
const updatedAt = new Date().toISOString();
|
|
20
|
+
const healthy = { status: "healthy", updatedAt, reason: "health monitor disabled" };
|
|
21
|
+
return {
|
|
22
|
+
status: "healthy",
|
|
23
|
+
updatedAt,
|
|
24
|
+
checks: {
|
|
25
|
+
runtime: healthy,
|
|
26
|
+
llm: healthy,
|
|
27
|
+
persistence: healthy,
|
|
28
|
+
capacity: healthy,
|
|
29
|
+
workload: healthy,
|
|
30
|
+
},
|
|
31
|
+
symptoms: [],
|
|
32
|
+
stats: {
|
|
33
|
+
activeRunSlots,
|
|
34
|
+
pendingRunSlots,
|
|
35
|
+
pendingApprovals: 0,
|
|
36
|
+
stuckRuns: 0,
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -41,6 +41,7 @@ function mergeRequirementOptions(binding, options = {}) {
|
|
|
41
41
|
return {
|
|
42
42
|
...fromBackend,
|
|
43
43
|
...options,
|
|
44
|
+
assessRequirements: options.assessRequirements ?? true,
|
|
44
45
|
env: options.env ? { ...(fromBackend.env ?? {}), ...options.env } : fromBackend.env,
|
|
45
46
|
path: options.path ?? fromBackend.path,
|
|
46
47
|
};
|
|
@@ -58,7 +59,7 @@ function toSkillRecords(skillPaths, options = {}) {
|
|
|
58
59
|
allowedTools: metadata.allowedTools,
|
|
59
60
|
userInvocable: metadata.userInvocable,
|
|
60
61
|
openclaw: metadata.openclaw,
|
|
61
|
-
requirements: assessSkillRequirements(metadata, options),
|
|
62
|
+
...(options.assessRequirements === false ? {} : { requirements: assessSkillRequirements(metadata, options) }),
|
|
62
63
|
};
|
|
63
64
|
});
|
|
64
65
|
}
|
|
@@ -18,6 +18,7 @@ export type SkillRequirementAssessment = {
|
|
|
18
18
|
openclaw?: OpenClawRequirementAssessment;
|
|
19
19
|
};
|
|
20
20
|
export type RequirementAssessmentOptions = {
|
|
21
|
+
assessRequirements?: boolean;
|
|
21
22
|
env?: Record<string, string | undefined>;
|
|
22
23
|
path?: string;
|
|
23
24
|
availableBins?: string[];
|
|
@@ -17,10 +17,8 @@ export declare class AgentHarnessRuntime {
|
|
|
17
17
|
private readonly vectorStores;
|
|
18
18
|
private readonly defaultStore;
|
|
19
19
|
private readonly runtimeMemoryStore;
|
|
20
|
-
private readonly routingSystemPrompt?;
|
|
21
20
|
private readonly routingRules;
|
|
22
21
|
private readonly routingDefaultAgentId?;
|
|
23
|
-
private readonly modelRoutingEnabled;
|
|
24
22
|
private readonly threadMemorySync;
|
|
25
23
|
private readonly unregisterThreadMemorySync;
|
|
26
24
|
private readonly resolvedRuntimeAdapterOptions;
|
|
@@ -37,20 +35,15 @@ export declare class AgentHarnessRuntime {
|
|
|
37
35
|
private runtimeEventSequence;
|
|
38
36
|
private listHostBindings;
|
|
39
37
|
private defaultRunRoot;
|
|
40
|
-
private heuristicRoute;
|
|
41
38
|
private getDefaultHostAgentId;
|
|
42
|
-
private buildRoutingInput;
|
|
43
39
|
private resolveSelectedAgentId;
|
|
44
|
-
private resolveStore;
|
|
45
|
-
private resolveStoreFromConfig;
|
|
46
|
-
private resolveEmbeddingModel;
|
|
47
|
-
private resolveVectorStore;
|
|
48
40
|
constructor(workspace: WorkspaceBundle, runtimeAdapterOptions?: RuntimeAdapterOptions);
|
|
41
|
+
private createHealthMonitor;
|
|
42
|
+
private recordLlmSuccess;
|
|
43
|
+
private recordLlmFailure;
|
|
49
44
|
initialize(): Promise<void>;
|
|
50
45
|
subscribe(listener: (event: HarnessEvent) => void): () => void;
|
|
51
46
|
getHealth(): Promise<RuntimeHealthSnapshot>;
|
|
52
|
-
private getBinding;
|
|
53
|
-
private listAgentTools;
|
|
54
47
|
private resolveAgentTools;
|
|
55
48
|
private supportsRunningReplay;
|
|
56
49
|
listThreads(filter?: {
|
|
@@ -87,36 +80,25 @@ export declare class AgentHarnessRuntime {
|
|
|
87
80
|
private ensureThreadStarted;
|
|
88
81
|
private loadPriorHistory;
|
|
89
82
|
private loadRunInput;
|
|
90
|
-
private appendAssistantMessage;
|
|
91
83
|
private getRunCancellation;
|
|
92
|
-
private expirePendingApprovals;
|
|
93
84
|
private finalizeCancelledRun;
|
|
94
85
|
private invokeWithHistory;
|
|
95
86
|
private resolvePersistedRunPriority;
|
|
96
87
|
private enqueuePendingRunSlot;
|
|
97
88
|
private executeQueuedRun;
|
|
98
|
-
private checkpointRefForState;
|
|
99
89
|
private finalizeContinuedRun;
|
|
100
|
-
private synthesizeCompletedRun;
|
|
101
|
-
private reviewCompletedRun;
|
|
102
|
-
private emitOutputDeltaAndCreateItem;
|
|
103
|
-
private createContentBlocksItem;
|
|
104
|
-
private createToolResultKey;
|
|
105
|
-
private emitRunCreated;
|
|
106
90
|
private setRunStateAndEmit;
|
|
107
91
|
private requestApprovalAndEmit;
|
|
108
|
-
private emitSyntheticFallback;
|
|
109
|
-
private persistApproval;
|
|
110
|
-
private resolveApprovalRecord;
|
|
111
92
|
private isDecisionRun;
|
|
112
93
|
private notifyListener;
|
|
94
|
+
private prepareRunStart;
|
|
95
|
+
private createStartupRecoveryContext;
|
|
113
96
|
private acquireRunSlot;
|
|
114
97
|
private dropPendingRunSlot;
|
|
115
98
|
private dispatchRunListeners;
|
|
116
99
|
run(options: RunOptions): Promise<RunResult>;
|
|
117
100
|
streamEvents(options: RunStartOptions): AsyncGenerator<HarnessStreamItem>;
|
|
118
101
|
resume(options: ResumeOptions): Promise<RunResult>;
|
|
119
|
-
private buildResumePayload;
|
|
120
102
|
restartConversation(options: RestartConversationOptions): Promise<RunResult & {
|
|
121
103
|
restart: Record<string, string>;
|
|
122
104
|
}>;
|
|
@@ -127,4 +109,3 @@ export declare class AgentHarnessRuntime {
|
|
|
127
109
|
private reclaimExpiredClaimedRuns;
|
|
128
110
|
private isStaleRunningRun;
|
|
129
111
|
}
|
|
130
|
-
export { AgentHarnessRuntime as AgentHarness };
|