@workbench-ai/workbench-built-in-adapters 0.0.46
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/agent-turn.d.ts +31 -0
- package/dist/agent-turn.d.ts.map +1 -0
- package/dist/agent-turn.js +384 -0
- package/dist/bin/claude.d.ts +3 -0
- package/dist/bin/claude.d.ts.map +1 -0
- package/dist/bin/claude.js +3 -0
- package/dist/bin/codex.d.ts +3 -0
- package/dist/bin/codex.d.ts.map +1 -0
- package/dist/bin/codex.js +3 -0
- package/dist/bin/command.d.ts +3 -0
- package/dist/bin/command.d.ts.map +1 -0
- package/dist/bin/command.js +3 -0
- package/dist/bin/pi.d.ts +3 -0
- package/dist/bin/pi.d.ts.map +1 -0
- package/dist/bin/pi.js +3 -0
- package/dist/bin/rubric.d.ts +3 -0
- package/dist/bin/rubric.d.ts.map +1 -0
- package/dist/bin/rubric.js +3 -0
- package/dist/bin/tests.d.ts +3 -0
- package/dist/bin/tests.d.ts.map +1 -0
- package/dist/bin/tests.js +3 -0
- package/dist/bin/workbench.d.ts +3 -0
- package/dist/bin/workbench.d.ts.map +1 -0
- package/dist/bin/workbench.js +3 -0
- package/dist/execute.d.ts +13 -0
- package/dist/execute.d.ts.map +1 -0
- package/dist/execute.js +1336 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/manifests.d.ts +9 -0
- package/dist/manifests.d.ts.map +1 -0
- package/dist/manifests.js +108 -0
- package/dist/runtime.d.ts +3 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +34 -0
- package/package.json +54 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { SurfaceSnapshotFile, UsageSummary } from "@workbench-ai/workbench-contract";
|
|
2
|
+
import { type JsonValue } from "@workbench-ai/agent-driver";
|
|
3
|
+
import type { WorkbenchExecutionEventPublisher } from "@workbench-ai/workbench-core";
|
|
4
|
+
export interface AgentProviderSpec {
|
|
5
|
+
use: string;
|
|
6
|
+
model?: string;
|
|
7
|
+
effort?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface WorkbenchAgentTurnRequest {
|
|
10
|
+
role: "optimizer" | "runner" | "engine";
|
|
11
|
+
provider: AgentProviderSpec;
|
|
12
|
+
adapterAuthRoot?: string;
|
|
13
|
+
adapterAuthRequest?: JsonValue;
|
|
14
|
+
adapterAuthEnv?: Record<string, string>;
|
|
15
|
+
workspaceRoot: string;
|
|
16
|
+
cwd: string;
|
|
17
|
+
prompt: string;
|
|
18
|
+
traceRoot: string;
|
|
19
|
+
jobId: string;
|
|
20
|
+
eventPublisher?: WorkbenchExecutionEventPublisher;
|
|
21
|
+
}
|
|
22
|
+
export interface WorkbenchAgentTurnResult {
|
|
23
|
+
output: string;
|
|
24
|
+
traceFiles: SurfaceSnapshotFile[];
|
|
25
|
+
metadata: Record<string, JsonValue>;
|
|
26
|
+
usage?: UsageSummary;
|
|
27
|
+
}
|
|
28
|
+
export type WorkbenchAgentTurnExecutor = (request: WorkbenchAgentTurnRequest) => Promise<WorkbenchAgentTurnResult>;
|
|
29
|
+
export declare function executeWorkbenchAgentTurn(executor: (request: WorkbenchAgentTurnRequest) => Promise<WorkbenchAgentTurnResult>, request: WorkbenchAgentTurnRequest): Promise<WorkbenchAgentTurnResult>;
|
|
30
|
+
export declare function defaultWorkbenchAgentTurnExecutor(request: WorkbenchAgentTurnRequest): Promise<WorkbenchAgentTurnResult>;
|
|
31
|
+
//# sourceMappingURL=agent-turn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-turn.d.ts","sourceRoot":"","sources":["../src/agent-turn.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAEV,mBAAmB,EACnB,YAAY,EACb,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EAQL,KAAK,SAAS,EAEf,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,gCAAgC,EACjC,MAAM,8BAA8B,CAAC;AAetC,MAAM,WAAW,iBAAiB;IAChC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE,WAAW,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACxC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,SAAS,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,CAAC,EAAE,gCAAgC,CAAC;CACnD;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,mBAAmB,EAAE,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACpC,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED,MAAM,MAAM,0BAA0B,GAAG,CAAC,OAAO,EAAE,yBAAyB,KAAK,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAoCnH,wBAAsB,yBAAyB,CAC7C,QAAQ,EAAE,CAAC,OAAO,EAAE,yBAAyB,KAAK,OAAO,CAAC,wBAAwB,CAAC,EACnF,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,wBAAwB,CAAC,CAenC;AAED,wBAAsB,iCAAiC,CACrD,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC,wBAAwB,CAAC,CA2FnC"}
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { randomUUID } from "node:crypto";
|
|
3
|
+
import { promises as fs } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { promisify } from "node:util";
|
|
6
|
+
import { DEFAULT_HARNESS_CANCEL, DEFAULT_HARNESS_RETRY, resolveRuntimeHome, } from "@workbench-ai/agent-driver";
|
|
7
|
+
import { importWorkbenchRuntime } from "./runtime.js";
|
|
8
|
+
const DEFAULT_AGENT_TURN_MAX_ATTEMPTS = 3;
|
|
9
|
+
const DEFAULT_AGENT_TURN_RETRY_BASE_MS = 5_000;
|
|
10
|
+
const DEFAULT_AGENT_TURN_RETRY_MAX_MS = 30_000;
|
|
11
|
+
const AGENT_HARNESS_REGISTRY = {
|
|
12
|
+
codex: {
|
|
13
|
+
executable: "codex",
|
|
14
|
+
installHint: "@openai/codex",
|
|
15
|
+
defaultConfig: {
|
|
16
|
+
sandbox_mode: "danger-full-access",
|
|
17
|
+
},
|
|
18
|
+
async load() {
|
|
19
|
+
const module = await import("@workbench-ai/agent-driver-openai-codex");
|
|
20
|
+
return module.codexHarness();
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
claude: {
|
|
24
|
+
executable: "claude",
|
|
25
|
+
installHint: "@anthropic-ai/claude-code",
|
|
26
|
+
defaultConfig: {
|
|
27
|
+
max_turns: 64,
|
|
28
|
+
permission_mode: "bypassPermissions",
|
|
29
|
+
},
|
|
30
|
+
async load() {
|
|
31
|
+
const module = await import("@workbench-ai/agent-driver-anthropic-claude-code");
|
|
32
|
+
return module.claudeCodeHarness();
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
pi: {
|
|
36
|
+
executable: "pi",
|
|
37
|
+
installHint: "@mariozechner/pi-coding-agent",
|
|
38
|
+
async load() {
|
|
39
|
+
const module = await import("@workbench-ai/agent-driver-badlogic-pi-coding-agent");
|
|
40
|
+
return module.piCodingAgentHarness();
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
export async function executeWorkbenchAgentTurn(executor, request) {
|
|
45
|
+
const maxAttempts = workbenchAgentTurnMaxAttempts();
|
|
46
|
+
let lastError;
|
|
47
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
48
|
+
try {
|
|
49
|
+
return await executor(request);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
lastError = error;
|
|
53
|
+
if (attempt >= maxAttempts || !isTransientAgentTurnError(error)) {
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
await sleep(agentTurnRetryDelayMs(attempt));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
throw lastError instanceof Error ? lastError : new Error(String(lastError ?? "Agent turn failed."));
|
|
60
|
+
}
|
|
61
|
+
export async function defaultWorkbenchAgentTurnExecutor(request) {
|
|
62
|
+
const execFileAsync = promisify(execFile);
|
|
63
|
+
await ensureAgentExecutableOnPath(request.provider.use, execFileAsync);
|
|
64
|
+
const provider = await loadAgentHarnessProvider(request.provider.use);
|
|
65
|
+
const agentHome = resolveRuntimeHome();
|
|
66
|
+
const stageSessionPath = path.join(request.traceRoot, "session");
|
|
67
|
+
await fs.mkdir(stageSessionPath, { recursive: true });
|
|
68
|
+
const restoreEnv = applyAdapterAuthEnv(request.adapterAuthEnv);
|
|
69
|
+
try {
|
|
70
|
+
const plan = await buildAgentHarnessExecutionPlan(provider, request.provider, request.workspaceRoot, agentHome, {
|
|
71
|
+
root: request.adapterAuthRoot,
|
|
72
|
+
request: request.adapterAuthRequest,
|
|
73
|
+
});
|
|
74
|
+
const readiness = await provider.checkReadiness?.({
|
|
75
|
+
repoRoot: request.workspaceRoot,
|
|
76
|
+
runtimeHome: agentHome,
|
|
77
|
+
plan,
|
|
78
|
+
});
|
|
79
|
+
const readinessErrors = readiness?.availability_errors ?? [];
|
|
80
|
+
if (readinessErrors.length > 0) {
|
|
81
|
+
throw new Error(readinessErrors.join("\n"));
|
|
82
|
+
}
|
|
83
|
+
const adapter = provider.create();
|
|
84
|
+
const stageId = `workbench-${request.role}`;
|
|
85
|
+
let activeSession = null;
|
|
86
|
+
try {
|
|
87
|
+
await fs.writeFile(path.join(stageSessionPath, "agent-request.json"), `${JSON.stringify({
|
|
88
|
+
role: request.role,
|
|
89
|
+
provider: request.provider.use,
|
|
90
|
+
workspaceRoot: request.workspaceRoot,
|
|
91
|
+
cwd: request.cwd,
|
|
92
|
+
jobId: request.jobId,
|
|
93
|
+
}, null, 2)}\n`);
|
|
94
|
+
activeSession = await adapter.startSession({
|
|
95
|
+
repoRoot: request.workspaceRoot,
|
|
96
|
+
runtimeHome: agentHome,
|
|
97
|
+
plan,
|
|
98
|
+
ownerId: "workbench",
|
|
99
|
+
executionId: createWorkbenchAgentTurnId("workbench_exec"),
|
|
100
|
+
attemptNumber: 1,
|
|
101
|
+
stageId,
|
|
102
|
+
stageRunIndex: 1,
|
|
103
|
+
workspacePath: request.cwd,
|
|
104
|
+
ownerStageId: stageId,
|
|
105
|
+
sessionMode: "fresh",
|
|
106
|
+
persistedSession: null,
|
|
107
|
+
stageSessionPath,
|
|
108
|
+
});
|
|
109
|
+
const runtime = await importWorkbenchRuntime();
|
|
110
|
+
const eventsFile = path.join(stageSessionPath, "events.ndjson");
|
|
111
|
+
const rawEventsFile = path.join(stageSessionPath, "raw-events.ndjson");
|
|
112
|
+
const turnResult = await adapter.startTurn(activeSession, {
|
|
113
|
+
prompt: request.prompt,
|
|
114
|
+
eventsFile,
|
|
115
|
+
rawEventsFile,
|
|
116
|
+
stageSpanId: createWorkbenchAgentTurnId("workbench_span"),
|
|
117
|
+
plan,
|
|
118
|
+
livePersistence: agentLivePersistenceForPublisher(request.eventPublisher, request.role),
|
|
119
|
+
});
|
|
120
|
+
const usage = runtime.extractExecutionUsageFromTrace(turnResult.trace, request.provider, provider.manifest.id, turnResult.events);
|
|
121
|
+
const eventCount = Math.max(turnResult.events.length, traceEventCount(turnResult.trace));
|
|
122
|
+
await writeAgentTraceFile(path.join(stageSessionPath, "trace.json"), turnResult.trace);
|
|
123
|
+
await fs.writeFile(path.join(stageSessionPath, "agent-result.json"), `${JSON.stringify({
|
|
124
|
+
sessionId: turnResult.sessionId,
|
|
125
|
+
finalOutput: turnResult.finalOutput,
|
|
126
|
+
eventCount,
|
|
127
|
+
...(usage ? { usage } : {}),
|
|
128
|
+
}, null, 2)}\n`);
|
|
129
|
+
return {
|
|
130
|
+
output: turnResult.finalOutput,
|
|
131
|
+
traceFiles: await runtime.readOutputTraceFiles(request.traceRoot, `.workbench/traces/${request.jobId}/${request.role}`),
|
|
132
|
+
metadata: {
|
|
133
|
+
providerId: provider.manifest.id,
|
|
134
|
+
sessionId: turnResult.sessionId,
|
|
135
|
+
eventCount,
|
|
136
|
+
},
|
|
137
|
+
...(usage ? { usage } : {}),
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
if (activeSession) {
|
|
142
|
+
await activeSession.adapter.closeSession(activeSession).catch(() => undefined);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
restoreEnv();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function agentLivePersistenceForPublisher(publisher, role) {
|
|
151
|
+
if (!publisher?.enabled) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
...(publisher.flushWindowMs ? { flushWindowMs: publisher.flushWindowMs } : {}),
|
|
156
|
+
async onFlush(batch) {
|
|
157
|
+
const traceBundle = batch.traceBundle;
|
|
158
|
+
if (traceBundle.spans.length === 0 &&
|
|
159
|
+
traceBundle.events.length === 0 &&
|
|
160
|
+
traceBundle.summaries.length === 0) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
await publisher.publish([{
|
|
164
|
+
source: "adapter",
|
|
165
|
+
role,
|
|
166
|
+
schema: "workbench.trace.delta.v1",
|
|
167
|
+
payload: toJsonPayload(traceBundle),
|
|
168
|
+
}]).catch(() => undefined);
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function createWorkbenchAgentTurnId(prefix) {
|
|
173
|
+
return `${prefix}_${randomUUID().replace(/-/gu, "")}`;
|
|
174
|
+
}
|
|
175
|
+
async function writeAgentTraceFile(filePath, trace) {
|
|
176
|
+
try {
|
|
177
|
+
await fs.writeFile(filePath, `${JSON.stringify(trace, null, 2)}\n`);
|
|
178
|
+
}
|
|
179
|
+
catch {
|
|
180
|
+
// Trace files are diagnostic only; the agent turn result remains authoritative.
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function traceEventCount(trace) {
|
|
184
|
+
const traceRecord = trace && typeof trace === "object" && !Array.isArray(trace)
|
|
185
|
+
? trace
|
|
186
|
+
: {};
|
|
187
|
+
return Array.isArray(traceRecord.events) ? traceRecord.events.length : 0;
|
|
188
|
+
}
|
|
189
|
+
async function loadAgentHarnessProvider(providerName) {
|
|
190
|
+
return await agentHarnessRegistration(providerName).load();
|
|
191
|
+
}
|
|
192
|
+
async function ensureAgentExecutableOnPath(providerName, execFileAsync) {
|
|
193
|
+
const executable = agentExecutableName(providerName);
|
|
194
|
+
try {
|
|
195
|
+
await execFileAsync("sh", ["-c", `command -v ${quoteShellArg(executable)} >/dev/null 2>&1`], {
|
|
196
|
+
maxBuffer: 1024 * 1024,
|
|
197
|
+
timeout: 5_000,
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
throw new Error(`Agent provider "${providerName}" requires "${executable}" on PATH. Install ${agentExecutableInstallHint(providerName)} in the adapter runtime.`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
function agentExecutableName(providerName) {
|
|
205
|
+
return agentHarnessRegistration(providerName).executable;
|
|
206
|
+
}
|
|
207
|
+
function agentExecutableInstallHint(providerName) {
|
|
208
|
+
return agentHarnessRegistration(providerName).installHint;
|
|
209
|
+
}
|
|
210
|
+
function agentHarnessRegistration(providerName) {
|
|
211
|
+
const registration = AGENT_HARNESS_REGISTRY[providerName];
|
|
212
|
+
if (!registration) {
|
|
213
|
+
throw new Error(`Unsupported first-party agent adapter: ${providerName}`);
|
|
214
|
+
}
|
|
215
|
+
return registration;
|
|
216
|
+
}
|
|
217
|
+
async function buildAgentHarnessExecutionPlan(provider, providerSpec, workspaceRoot, agentHome, adapterAuth) {
|
|
218
|
+
const turnTimeoutMs = provider.manifest.defaults.turn_timeout_ms ?? 3_600_000;
|
|
219
|
+
const harness = {
|
|
220
|
+
id: provider.manifest.id,
|
|
221
|
+
auth: await resolveAgentHarnessAuth(provider, providerSpec, workspaceRoot, agentHome, adapterAuth),
|
|
222
|
+
...(firstNonEmpty(providerSpec.model, provider.manifest.defaults.model) ? { model: firstNonEmpty(providerSpec.model, provider.manifest.defaults.model) } : {}),
|
|
223
|
+
...(firstNonEmpty(providerSpec.effort, provider.manifest.defaults.effort) ? { effort: firstNonEmpty(providerSpec.effort, provider.manifest.defaults.effort) } : {}),
|
|
224
|
+
turn_timeout_ms: turnTimeoutMs,
|
|
225
|
+
stall_timeout_ms: Math.max(provider.manifest.defaults.stall_timeout_ms ?? 0, turnTimeoutMs),
|
|
226
|
+
config: resolveAgentHarnessConfig(provider, defaultWorkbenchAgentHarnessConfig(provider, providerSpec.use)),
|
|
227
|
+
retry: DEFAULT_HARNESS_RETRY,
|
|
228
|
+
cancel: DEFAULT_HARNESS_CANCEL,
|
|
229
|
+
};
|
|
230
|
+
return {
|
|
231
|
+
workspace: {
|
|
232
|
+
mode: "project",
|
|
233
|
+
prune_ttl_seconds: 604_800,
|
|
234
|
+
},
|
|
235
|
+
harness,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
function defaultWorkbenchAgentHarnessConfig(provider, providerName) {
|
|
239
|
+
const fallback = (provider.manifest.defaults.config ?? {});
|
|
240
|
+
return {
|
|
241
|
+
...fallback,
|
|
242
|
+
...(AGENT_HARNESS_REGISTRY[providerName]?.defaultConfig ?? {}),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
async function resolveAgentHarnessAuth(provider, providerSpec, workspaceRoot, agentHome, adapterAuth) {
|
|
246
|
+
const subject = adapterAuthHarnessSubject(adapterAuth.request, providerSpec.use) ??
|
|
247
|
+
(provider.manifest.defaults.auth ?? {});
|
|
248
|
+
const parsed = provider.schemas.auth.safeParse(subject);
|
|
249
|
+
if (!parsed.success) {
|
|
250
|
+
throw new Error(`Agent provider "${provider.manifest.id}" auth is invalid: ${formatValidationIssues(parsed.error.issues)}`);
|
|
251
|
+
}
|
|
252
|
+
void workspaceRoot;
|
|
253
|
+
void agentHome;
|
|
254
|
+
return { ...parsed.data };
|
|
255
|
+
}
|
|
256
|
+
function adapterAuthHarnessSubject(auth, providerName) {
|
|
257
|
+
const record = jsonRecord(auth);
|
|
258
|
+
const self = jsonRecord(record?.self);
|
|
259
|
+
const adapters = jsonRecord(record?.adapters);
|
|
260
|
+
const provider = jsonRecord(adapters?.[providerName]);
|
|
261
|
+
const entry = jsonRecord(self?.default) ??
|
|
262
|
+
jsonRecord(provider?.default) ??
|
|
263
|
+
jsonRecord(record?.default);
|
|
264
|
+
if (!entry) {
|
|
265
|
+
return null;
|
|
266
|
+
}
|
|
267
|
+
const method = typeof entry.method === "string" ? entry.method : "";
|
|
268
|
+
if (method === "bedrock") {
|
|
269
|
+
return { strategy: "bedrock_env" };
|
|
270
|
+
}
|
|
271
|
+
const filesRoot = typeof entry.filesRoot === "string" ? entry.filesRoot : "";
|
|
272
|
+
if (filesRoot) {
|
|
273
|
+
return {
|
|
274
|
+
strategy: "profile_path",
|
|
275
|
+
path: filesRoot,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
const env = jsonRecord(entry.env);
|
|
279
|
+
const [envName] = Object.keys(env ?? {}).sort();
|
|
280
|
+
if (envName) {
|
|
281
|
+
return {
|
|
282
|
+
strategy: "secret_ref",
|
|
283
|
+
ref: envName,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
function resolveAgentHarnessConfig(provider, fallback) {
|
|
289
|
+
const parsed = provider.schemas.config.safeParse(fallback);
|
|
290
|
+
if (!parsed.success) {
|
|
291
|
+
throw new Error(`Agent provider "${provider.manifest.id}" config is invalid: ${formatValidationIssues(parsed.error.issues)}`);
|
|
292
|
+
}
|
|
293
|
+
return { ...parsed.data };
|
|
294
|
+
}
|
|
295
|
+
function applyAdapterAuthEnv(env) {
|
|
296
|
+
if (!env || Object.keys(env).length === 0) {
|
|
297
|
+
return () => undefined;
|
|
298
|
+
}
|
|
299
|
+
const previous = new Map();
|
|
300
|
+
for (const [name, value] of Object.entries(env)) {
|
|
301
|
+
previous.set(name, process.env[name]);
|
|
302
|
+
process.env[name] = value;
|
|
303
|
+
}
|
|
304
|
+
return () => {
|
|
305
|
+
for (const [name, value] of previous) {
|
|
306
|
+
if (value === undefined) {
|
|
307
|
+
delete process.env[name];
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
process.env[name] = value;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
function jsonRecord(value) {
|
|
316
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
317
|
+
? value
|
|
318
|
+
: null;
|
|
319
|
+
}
|
|
320
|
+
function toJsonPayload(value) {
|
|
321
|
+
const normalized = JSON.parse(JSON.stringify(value ?? null));
|
|
322
|
+
return isJsonValue(normalized) ? normalized : null;
|
|
323
|
+
}
|
|
324
|
+
function isJsonValue(value) {
|
|
325
|
+
if (value === null ||
|
|
326
|
+
typeof value === "string" ||
|
|
327
|
+
typeof value === "boolean" ||
|
|
328
|
+
(typeof value === "number" && Number.isFinite(value))) {
|
|
329
|
+
return true;
|
|
330
|
+
}
|
|
331
|
+
if (Array.isArray(value)) {
|
|
332
|
+
return value.every(isJsonValue);
|
|
333
|
+
}
|
|
334
|
+
return value !== null &&
|
|
335
|
+
typeof value === "object" &&
|
|
336
|
+
Object.values(value).every(isJsonValue);
|
|
337
|
+
}
|
|
338
|
+
function workbenchAgentTurnMaxAttempts() {
|
|
339
|
+
const raw = Number.parseInt(process.env.WORKBENCH_AGENT_TURN_MAX_ATTEMPTS ?? "", 10);
|
|
340
|
+
return Number.isSafeInteger(raw) && raw > 0 ? raw : DEFAULT_AGENT_TURN_MAX_ATTEMPTS;
|
|
341
|
+
}
|
|
342
|
+
function agentTurnRetryDelayMs(attempt) {
|
|
343
|
+
const fallback = process.env.NODE_ENV === "test" ? 1 : DEFAULT_AGENT_TURN_RETRY_BASE_MS;
|
|
344
|
+
const raw = Number.parseInt(process.env.WORKBENCH_AGENT_TURN_RETRY_BASE_MS ?? "", 10);
|
|
345
|
+
const baseDelay = Number.isSafeInteger(raw) && raw >= 0 ? raw : fallback;
|
|
346
|
+
return Math.min(baseDelay * 2 ** Math.max(0, attempt - 1), DEFAULT_AGENT_TURN_RETRY_MAX_MS);
|
|
347
|
+
}
|
|
348
|
+
function isTransientAgentTurnError(error) {
|
|
349
|
+
const message = error instanceof Error
|
|
350
|
+
? `${error.message}\n${error.stack ?? ""}\n${String(error.cause ?? "")}`
|
|
351
|
+
: String(error);
|
|
352
|
+
if (isNativeCaCertificateFailure(message)) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
return /\b(fetch failed|error sending request|stream disconnected before completion|ECONNRESET|ETIMEDOUT|EAI_AGAIN|ENETUNREACH|ECONNREFUSED|socket hang up|network error|UND_ERR_|signal SIGTERM)/iu.test(message);
|
|
356
|
+
}
|
|
357
|
+
function isNativeCaCertificateFailure(message) {
|
|
358
|
+
return /\bno native root CA certificates found\b|install ca-certificates/iu.test(message);
|
|
359
|
+
}
|
|
360
|
+
async function sleep(ms) {
|
|
361
|
+
if (ms <= 0) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
365
|
+
}
|
|
366
|
+
function firstNonEmpty(...values) {
|
|
367
|
+
for (const value of values) {
|
|
368
|
+
if (typeof value === "string" && value.length > 0) {
|
|
369
|
+
return value;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return undefined;
|
|
373
|
+
}
|
|
374
|
+
function formatValidationIssues(issues) {
|
|
375
|
+
return issues
|
|
376
|
+
.map((issue) => {
|
|
377
|
+
const issuePath = issue.path.length > 0 ? issue.path.join(".") : "(root)";
|
|
378
|
+
return `${issuePath}: ${issue.message}`;
|
|
379
|
+
})
|
|
380
|
+
.join("; ");
|
|
381
|
+
}
|
|
382
|
+
function quoteShellArg(value) {
|
|
383
|
+
return `'${value.replace(/'/gu, "'\\''")}'`;
|
|
384
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/bin/claude.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/bin/codex.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/bin/command.ts"],"names":[],"mappings":""}
|
package/dist/bin/pi.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi.d.ts","sourceRoot":"","sources":["../../src/bin/pi.ts"],"names":[],"mappings":""}
|
package/dist/bin/pi.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rubric.d.ts","sourceRoot":"","sources":["../../src/bin/rubric.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tests.d.ts","sourceRoot":"","sources":["../../src/bin/tests.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workbench.d.ts","sourceRoot":"","sources":["../../src/bin/workbench.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Json } from "@workbench-ai/workbench-contract";
|
|
2
|
+
import type { WorkbenchAgentTurnExecutor } from "./agent-turn.ts";
|
|
3
|
+
export interface ExecuteWorkbenchBuiltInAdapterCommandOptions {
|
|
4
|
+
adapterId?: string;
|
|
5
|
+
requestPath?: string;
|
|
6
|
+
outputRoot?: string;
|
|
7
|
+
agentExecutor?: WorkbenchAgentTurnExecutor;
|
|
8
|
+
adapterAuthRoot?: string;
|
|
9
|
+
adapterAuthRequest?: Json;
|
|
10
|
+
adapterAuthEnv?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
export declare function executeWorkbenchBuiltInAdapterCommand(args?: ExecuteWorkbenchBuiltInAdapterCommandOptions): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=execute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.d.ts","sourceRoot":"","sources":["../src/execute.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAEV,IAAI,EAKL,MAAM,kCAAkC,CAAC;AAY1C,OAAO,KAAK,EAEV,0BAA0B,EAG3B,MAAM,iBAAiB,CAAC;AAQzB,MAAM,WAAW,4CAA4C;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,0BAA0B,CAAC;IAC3C,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,IAAI,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AA4CD,wBAAsB,qCAAqC,CACzD,IAAI,GAAE,4CAAiD,GACtD,OAAO,CAAC,IAAI,CAAC,CAiEf"}
|