@vercel/agent-eval 1.3.0 → 1.3.1
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.
|
@@ -40,6 +40,28 @@ export interface OpenCodeProviderConfig {
|
|
|
40
40
|
};
|
|
41
41
|
}>;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Resolve a model override into the id the OpenCode CLI expects.
|
|
45
|
+
*
|
|
46
|
+
* OpenCode reads `--model` as `<providerID>/<modelID>` and the generated
|
|
47
|
+
* opencode.json only configures the `vercel` (AI Gateway) provider. A canonical
|
|
48
|
+
* gateway id like `anthropic/claude-sonnet-5` therefore selects a *provider*
|
|
49
|
+
* named `anthropic` — which is not configured and has no key in the sandbox —
|
|
50
|
+
* and the CLI dies at session start ("Unexpected server error") on every task.
|
|
51
|
+
* The gateway form OpenCode understands is `vercel/anthropic/claude-sonnet-5`.
|
|
52
|
+
*
|
|
53
|
+
* So: prefix `vercel/` unless the caller already targets a configured provider
|
|
54
|
+
* (`vercel` itself, or a key in agentOptions.extraProviders — the escape hatch
|
|
55
|
+
* for unreleased models). Mirrors codex's `openai/` prefixing in
|
|
56
|
+
* generateCodexConfig, and the package's own defaultModel shape
|
|
57
|
+
* (`vercel/anthropic/claude-sonnet-4`). A bare id with no `/` (never a valid
|
|
58
|
+
* gateway id) is prefixed too, trading the opaque provider error for the
|
|
59
|
+
* gateway's model-not-found.
|
|
60
|
+
*
|
|
61
|
+
* Stays host-side (and exported for the unit tests) — the resolution needs
|
|
62
|
+
* extraProviders, which only the host knows.
|
|
63
|
+
*/
|
|
64
|
+
export declare function resolveOpenCodeModel(model: string, extraProviders?: Record<string, OpenCodeProviderConfig>): string;
|
|
43
65
|
/**
|
|
44
66
|
* Generate OpenCode config file content.
|
|
45
67
|
* Configures the Vercel AI Gateway provider, plus any additional providers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../../../src/lib/agents/opencode/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAmB,MAAM,aAAa,CAAC;AAG1D,OAAO,KAAK,EAAE,eAAe,EAA2B,MAAM,uBAAuB,CAAC;AAGtF;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QACtB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,KAAK,CAAC,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC;KAC7C,CAAC,CAAC;CACJ;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,EACvD,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,OAAO,GACpB,MAAM,CA8BR;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,IAAI,eAAe,
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../../../src/lib/agents/opencode/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAmB,MAAM,aAAa,CAAC;AAG1D,OAAO,KAAK,EAAE,eAAe,EAA2B,MAAM,uBAAuB,CAAC;AAGtF;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QACtB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,WAAW,CAAC,EAAE,OAAO,CAAC;QACtB,KAAK,CAAC,EAAE;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,MAAM,CAAA;SAAE,CAAC;KAC7C,CAAC,CAAC;CACJ;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,GACtD,MAAM,CAMR;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,EACvD,MAAM,CAAC,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,MAAM,EAClB,WAAW,CAAC,EAAE,OAAO,GACpB,MAAM,CA8BR;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,IAAI,eAAe,CA2G1D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,KAAK,CAY3C"}
|
|
@@ -20,6 +20,34 @@
|
|
|
20
20
|
import { fileURLToPath } from 'node:url';
|
|
21
21
|
import { AI_GATEWAY } from '../shared.js';
|
|
22
22
|
import { runWithDefinition } from '../plugin/orchestrator.js';
|
|
23
|
+
/**
|
|
24
|
+
* Resolve a model override into the id the OpenCode CLI expects.
|
|
25
|
+
*
|
|
26
|
+
* OpenCode reads `--model` as `<providerID>/<modelID>` and the generated
|
|
27
|
+
* opencode.json only configures the `vercel` (AI Gateway) provider. A canonical
|
|
28
|
+
* gateway id like `anthropic/claude-sonnet-5` therefore selects a *provider*
|
|
29
|
+
* named `anthropic` — which is not configured and has no key in the sandbox —
|
|
30
|
+
* and the CLI dies at session start ("Unexpected server error") on every task.
|
|
31
|
+
* The gateway form OpenCode understands is `vercel/anthropic/claude-sonnet-5`.
|
|
32
|
+
*
|
|
33
|
+
* So: prefix `vercel/` unless the caller already targets a configured provider
|
|
34
|
+
* (`vercel` itself, or a key in agentOptions.extraProviders — the escape hatch
|
|
35
|
+
* for unreleased models). Mirrors codex's `openai/` prefixing in
|
|
36
|
+
* generateCodexConfig, and the package's own defaultModel shape
|
|
37
|
+
* (`vercel/anthropic/claude-sonnet-4`). A bare id with no `/` (never a valid
|
|
38
|
+
* gateway id) is prefixed too, trading the opaque provider error for the
|
|
39
|
+
* gateway's model-not-found.
|
|
40
|
+
*
|
|
41
|
+
* Stays host-side (and exported for the unit tests) — the resolution needs
|
|
42
|
+
* extraProviders, which only the host knows.
|
|
43
|
+
*/
|
|
44
|
+
export function resolveOpenCodeModel(model, extraProviders) {
|
|
45
|
+
const providerID = model.split('/')[0];
|
|
46
|
+
if (providerID === 'vercel' || (extraProviders && Object.hasOwn(extraProviders, providerID))) {
|
|
47
|
+
return model;
|
|
48
|
+
}
|
|
49
|
+
return `vercel/${model}`;
|
|
50
|
+
}
|
|
23
51
|
/**
|
|
24
52
|
* Generate OpenCode config file content.
|
|
25
53
|
* Configures the Vercel AI Gateway provider, plus any additional providers.
|
|
@@ -144,6 +172,19 @@ export function createOpenCodeDefinition() {
|
|
|
144
172
|
...(options.webResearch ? { OPENCODE_ENABLE_EXA: '1' } : {}),
|
|
145
173
|
};
|
|
146
174
|
},
|
|
175
|
+
/**
|
|
176
|
+
* Host-computed value the runner passes as `--model`: the model override
|
|
177
|
+
* resolved against the configured providers (see resolveOpenCodeModel).
|
|
178
|
+
* Computed here because extraProviders is host-side knowledge; the runner
|
|
179
|
+
* also uses cliModel-vs-model to report observations back in the caller's
|
|
180
|
+
* namespace (see normalizeObservedModel in run.mjs). null on native-default.
|
|
181
|
+
*/
|
|
182
|
+
runnerExtra(options) {
|
|
183
|
+
const extraProviders = options.agentOptions?.extraProviders;
|
|
184
|
+
return {
|
|
185
|
+
cliModel: options.model ? resolveOpenCodeModel(options.model, extraProviders) : null,
|
|
186
|
+
};
|
|
187
|
+
},
|
|
147
188
|
};
|
|
148
189
|
}
|
|
149
190
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../../../../src/lib/agents/opencode/agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAqB9D;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CACpC,cAAuD,EACvD,MAAe,EACf,SAAkB,EAClB,WAAqB;IAErB,MAAM,UAAU,GAA4B;QAC1C,OAAO,EAAE;YACP,MAAM,EAAE,MAAM,IAAI,0BAA0B;YAC5C,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC7C;KACF,CAAC;IACF,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,cAAc,EAAE,GAAG,cAAc,IAAI,EAAE,CAAC;IAExE,MAAM,SAAS,GAA4B;QACzC,MAAM,EAAE;YACN,GAAG,UAAU;YACb,GAAG,WAAW;YACd,OAAO,EAAE,EAAE,GAAI,UAAU,CAAC,OAAmC,EAAE,GAAG,WAAW,EAAE,OAAO,EAAE;SACzF;QACD,GAAG,cAAc;KAClB,CAAC;IAEF,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,OAAO,EAAE,iCAAiC;QAC1C,QAAQ,EAAE,SA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C,UAAU,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM;gBACzC,yEAAyE;gBACzE,kEAAkE;gBAClE,0BAA0B;gBAC1B,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC7D,CAAC;QACJ,CAAC;QAED;;;;;;WAMG;QACH,WAAW,CAAC,OAAwB;YAClC,MAAM,cAAc,GAAG,OAAO,CAAC,YAAY,EAAE,cAEhC,CAAC;YACd,OAAO;gBACL,QAAQ,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC,IAAI;aACrF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,UAAU,GAAG,wBAAwB,EAAE,CAAC;IAC9C,OAAO;QACL,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,eAAe,EAAE,UAAU,CAAC,eAAe;QAC3C,eAAe;YACb,OAAO,UAAU,CAAC,YAAY,CAAC;QACjC,CAAC;QACD,GAAG,EAAE,CAAC,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC,iBAAiB,CAAC,UAAU,EAAE,WAAW,EAAE,OAAO,CAAC;QAClF,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -25,27 +25,65 @@ import { fileURLToPath } from 'node:url';
|
|
|
25
25
|
/**
|
|
26
26
|
* Build the OpenCode CLI argument list.
|
|
27
27
|
*
|
|
28
|
-
* Preserved verbatim from the old adapter:
|
|
29
28
|
* - `run <prompt> --format json` is always emitted (`--format json` gives the
|
|
30
29
|
* structured JSON event stream we parse for the transcript).
|
|
31
|
-
* - `--model <
|
|
30
|
+
* - `--model <extra.cliModel>` is appended when a model override is present.
|
|
31
|
+
* cliModel is HOST-computed (resolveOpenCodeModel in agent.ts, threaded via
|
|
32
|
+
* runnerExtra like codex's resolved model) so a canonical gateway id like
|
|
33
|
+
* `anthropic/claude-sonnet-5` arrives as `vercel/anthropic/claude-sonnet-5` —
|
|
34
|
+
* the form OpenCode routes through the configured `vercel` provider. There is
|
|
35
|
+
* deliberately NO fallback to input.model: passing it verbatim is the exact
|
|
36
|
+
* mis-route this fixes, and both runner entry points (the orchestrator and
|
|
37
|
+
* the judge's eval-helper) always ship extra.
|
|
32
38
|
* - else, when modelPolicy === 'native-default', `--print-logs --log-level INFO`
|
|
33
39
|
* is appended so older OpenCode versions print the CLI-selected model (the
|
|
34
40
|
* log-scrape path) without a follow-up export call.
|
|
35
41
|
*
|
|
36
|
-
* @param {{prompt:string,
|
|
42
|
+
* @param {{prompt:string, modelPolicy?:string, extra?:Record<string,unknown>}} input
|
|
37
43
|
* @returns {string[]}
|
|
38
44
|
*/
|
|
39
45
|
export function buildOpenCodeCliArgs(input) {
|
|
40
46
|
const cliArgs = ['run', input.prompt, '--format', 'json'];
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
const cliModel = input.extra?.cliModel;
|
|
48
|
+
if (cliModel) {
|
|
49
|
+
cliArgs.push('--model', String(cliModel));
|
|
43
50
|
} else if (input.modelPolicy === 'native-default') {
|
|
44
51
|
cliArgs.push('--print-logs', '--log-level', 'INFO');
|
|
45
52
|
}
|
|
46
53
|
return cliArgs;
|
|
47
54
|
}
|
|
48
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Report the observed model in the caller's namespace.
|
|
58
|
+
*
|
|
59
|
+
* When the host prefixed the requested model with `vercel/` (extra.cliModel !==
|
|
60
|
+
* input.model), OpenCode observes it back in its own provider namespace —
|
|
61
|
+
* `vercel/anthropic/claude-sonnet-5` for a requested `anthropic/claude-sonnet-5`.
|
|
62
|
+
* Un-apply exactly that translation so observed === requested holds for callers
|
|
63
|
+
* that speak canonical gateway ids, and a gateway substitution still surfaces as
|
|
64
|
+
* a clean gateway id (`anthropic/claude-haiku-4`, not `vercel/anthropic/...`).
|
|
65
|
+
*
|
|
66
|
+
* Everything else passes through untouched: native-default runs (no override —
|
|
67
|
+
* consumers already treat `vercel/google/gemini-3-pro-preview` as canonical),
|
|
68
|
+
* callers that already speak OpenCode's namespace (`vercel/...` requested), and
|
|
69
|
+
* extraProviders runs (their providerID isn't `vercel`).
|
|
70
|
+
*
|
|
71
|
+
* @param {string|undefined} observedModel
|
|
72
|
+
* @param {{model?:string, extra?:Record<string,unknown>}} input
|
|
73
|
+
* @returns {string|undefined}
|
|
74
|
+
*/
|
|
75
|
+
export function normalizeObservedModel(observedModel, input) {
|
|
76
|
+
if (!observedModel) {
|
|
77
|
+
return observedModel;
|
|
78
|
+
}
|
|
79
|
+
const cliModel = input.extra?.cliModel;
|
|
80
|
+
const hostPrefixed = typeof cliModel === 'string' && cliModel !== input.model;
|
|
81
|
+
if (hostPrefixed && observedModel.startsWith('vercel/')) {
|
|
82
|
+
return observedModel.slice('vercel/'.length);
|
|
83
|
+
}
|
|
84
|
+
return observedModel;
|
|
85
|
+
}
|
|
86
|
+
|
|
49
87
|
/**
|
|
50
88
|
* Extract transcript from OpenCode JSON output.
|
|
51
89
|
* When run with --format json, OpenCode outputs JSON events to stdout.
|
|
@@ -228,7 +266,7 @@ export async function runAgent(input) {
|
|
|
228
266
|
}
|
|
229
267
|
}
|
|
230
268
|
}
|
|
231
|
-
const observedModelOrNull = observedModel ?? null;
|
|
269
|
+
const observedModelOrNull = normalizeObservedModel(observedModel, input) ?? null;
|
|
232
270
|
|
|
233
271
|
if (res.error || agentExitCode !== 0) {
|
|
234
272
|
// Mirror the old error string: last 5 lines of output, else a coded fallback.
|