@agentgrader/agent-openrouter 2.0.2 → 3.0.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/dist/index.js +39 -2
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -5,11 +5,25 @@ import { createAnthropic } from '@ai-sdk/anthropic';
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
|
|
7
7
|
// src/index.ts
|
|
8
|
+
function resolveProvider(config) {
|
|
9
|
+
if (config.provider) return config.provider;
|
|
10
|
+
const modelName = config.model || "";
|
|
11
|
+
const hasOpenRouterKey = Boolean(process.env.OPENROUTER_API_KEY || process.env.OPENAI_API_KEY);
|
|
12
|
+
if (!hasOpenRouterKey) {
|
|
13
|
+
if (/^claude-/i.test(modelName) && process.env.ANTHROPIC_API_KEY) {
|
|
14
|
+
return "anthropic";
|
|
15
|
+
}
|
|
16
|
+
if (/^(gpt-|o[0-9])/i.test(modelName) && process.env.OPENAI_API_KEY) {
|
|
17
|
+
return "openai";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return "openrouter";
|
|
21
|
+
}
|
|
8
22
|
var AiSdkAgentAdapter = class {
|
|
9
23
|
name = "ai-sdk";
|
|
10
24
|
async solve(input) {
|
|
11
25
|
const { prompt, sandbox, config, onStep } = input;
|
|
12
|
-
const provider = config
|
|
26
|
+
const provider = resolveProvider(config);
|
|
13
27
|
const modelName = config.model || "gpt-4o-mini";
|
|
14
28
|
let model;
|
|
15
29
|
if (provider === "anthropic") {
|
|
@@ -130,7 +144,30 @@ var AiSdkAgentAdapter = class {
|
|
|
130
144
|
console.error(`Failed to connect to MCP server "${serverName}": ${err.message}`);
|
|
131
145
|
}
|
|
132
146
|
}
|
|
133
|
-
const
|
|
147
|
+
const allTools = { ...localTools, ...mcpTools };
|
|
148
|
+
let tools = allTools;
|
|
149
|
+
if (config.tools?.length) {
|
|
150
|
+
const allowlist = new Set(config.tools);
|
|
151
|
+
const localToolNames = Object.keys(localTools);
|
|
152
|
+
const availableNames = new Set(Object.keys(allTools));
|
|
153
|
+
for (const name of allowlist) {
|
|
154
|
+
if (!availableNames.has(name)) {
|
|
155
|
+
console.warn(
|
|
156
|
+
`Tool "${name}" listed in config.tools was not found among local tools (${localToolNames.join(", ")}) or connected MCP server tools - ignoring.`
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (!allowlist.has("submit")) {
|
|
161
|
+
console.warn(
|
|
162
|
+
"tools allowlist did not include 'submit' - adding it automatically, as it is required to end a run."
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
const effectiveAllowlist = /* @__PURE__ */ new Set([...allowlist, "submit"]);
|
|
166
|
+
tools = Object.fromEntries(
|
|
167
|
+
Object.entries(allTools).filter(([key]) => effectiveAllowlist.has(key))
|
|
168
|
+
);
|
|
169
|
+
console.log(`Tool allowlist active: ${Object.keys(tools).join(", ")}`);
|
|
170
|
+
}
|
|
134
171
|
const getPricing = (model2) => {
|
|
135
172
|
const name = model2.toLowerCase();
|
|
136
173
|
if (name.includes("claude-3-5-sonnet")) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentgrader/agent-openrouter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "OpenRouter/AI SDK ReAct agent adapter for the Agentgrader framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"build:watch": "tsup src/index.ts --format esm --dts --watch"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@agentgrader/core": "^1.
|
|
24
|
+
"@agentgrader/core": "^1.2.0",
|
|
25
25
|
"@ai-sdk/anthropic": "^1.2.12",
|
|
26
26
|
"@ai-sdk/openai": "^1.1.0",
|
|
27
27
|
"ai": "^4.1.0",
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"tsup": "^8.5.1"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@agentgrader/core": "^1.
|
|
34
|
+
"@agentgrader/core": "^1.2.0"
|
|
35
35
|
}
|
|
36
36
|
}
|