@agentgrader/agent-openrouter 1.0.1 → 2.0.2
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.d.ts +3 -3
- package/dist/index.js +48 -19
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentAdapter, StepEvent, AgentResult } from '@agentgrader/core';
|
|
2
2
|
|
|
3
|
-
declare class
|
|
4
|
-
readonly name = "
|
|
3
|
+
declare class AiSdkAgentAdapter implements AgentAdapter {
|
|
4
|
+
readonly name = "ai-sdk";
|
|
5
5
|
solve(input: {
|
|
6
6
|
prompt: string;
|
|
7
7
|
sandbox: any;
|
|
@@ -10,4 +10,4 @@ declare class OpenRouterAgentAdapter implements AgentAdapter {
|
|
|
10
10
|
}): Promise<AgentResult>;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export { OpenRouterAgentAdapter };
|
|
13
|
+
export { AiSdkAgentAdapter, AiSdkAgentAdapter as OpenRouterAgentAdapter };
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,54 @@
|
|
|
1
1
|
import { tool, experimental_createMCPClient, generateText } from 'ai';
|
|
2
2
|
import { Experimental_StdioMCPTransport } from 'ai/mcp-stdio';
|
|
3
3
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
4
|
+
import { createAnthropic } from '@ai-sdk/anthropic';
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
|
|
6
7
|
// src/index.ts
|
|
7
|
-
var
|
|
8
|
-
name = "
|
|
8
|
+
var AiSdkAgentAdapter = class {
|
|
9
|
+
name = "ai-sdk";
|
|
9
10
|
async solve(input) {
|
|
10
11
|
const { prompt, sandbox, config, onStep } = input;
|
|
11
|
-
const
|
|
12
|
-
const baseURL = process.env.OPENROUTER_API_KEY ? "https://openrouter.ai/api/v1" : void 0;
|
|
13
|
-
const client = createOpenAI({
|
|
14
|
-
baseURL,
|
|
15
|
-
apiKey,
|
|
16
|
-
headers: {
|
|
17
|
-
"HTTP-Referer": "https://github.com/agentgrader/agr",
|
|
18
|
-
"X-Title": "Agentgrader"
|
|
19
|
-
}
|
|
20
|
-
});
|
|
12
|
+
const provider = config.provider || "openrouter";
|
|
21
13
|
const modelName = config.model || "gpt-4o-mini";
|
|
22
|
-
|
|
14
|
+
let model;
|
|
15
|
+
if (provider === "anthropic") {
|
|
16
|
+
if (!process.env.ANTHROPIC_API_KEY) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
"ANTHROPIC_API_KEY is not set. Set it in your environment or .env file to use provider: anthropic."
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const anthropic = createAnthropic({
|
|
22
|
+
apiKey: process.env.ANTHROPIC_API_KEY
|
|
23
|
+
});
|
|
24
|
+
model = anthropic(modelName);
|
|
25
|
+
} else if (provider === "openai") {
|
|
26
|
+
if (!process.env.OPENAI_API_KEY) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
"OPENAI_API_KEY is not set. Set it in your environment or .env file to use provider: openai."
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const openai = createOpenAI({
|
|
32
|
+
apiKey: process.env.OPENAI_API_KEY
|
|
33
|
+
});
|
|
34
|
+
model = openai(modelName);
|
|
35
|
+
} else {
|
|
36
|
+
const apiKey = process.env.OPENROUTER_API_KEY || process.env.OPENAI_API_KEY;
|
|
37
|
+
if (!apiKey) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"OPENROUTER_API_KEY (or OPENAI_API_KEY) is not set. Set it in your environment or .env file to use provider: openrouter."
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
const openrouter = createOpenAI({
|
|
43
|
+
baseURL: "https://openrouter.ai/api/v1",
|
|
44
|
+
apiKey,
|
|
45
|
+
headers: {
|
|
46
|
+
"HTTP-Referer": "https://github.com/agentgrader/agr",
|
|
47
|
+
"X-Title": "Agentgrader"
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
model = openrouter(modelName);
|
|
51
|
+
}
|
|
23
52
|
let submitted = false;
|
|
24
53
|
let stepIndex = 0;
|
|
25
54
|
const localTools = {
|
|
@@ -91,9 +120,9 @@ var OpenRouterAgentAdapter = class {
|
|
|
91
120
|
// remote transport type, regardless of the configured `type`
|
|
92
121
|
{ type: "sse", url: serverConfig.url, headers: serverConfig.headers }
|
|
93
122
|
);
|
|
94
|
-
const
|
|
95
|
-
mcpClients.push(
|
|
96
|
-
const serverTools = await
|
|
123
|
+
const client = await experimental_createMCPClient({ transport });
|
|
124
|
+
mcpClients.push(client);
|
|
125
|
+
const serverTools = await client.tools();
|
|
97
126
|
for (const [toolName, toolDef] of Object.entries(serverTools)) {
|
|
98
127
|
mcpTools[`${serverName}_${toolName}`] = toolDef;
|
|
99
128
|
}
|
|
@@ -168,9 +197,9 @@ var OpenRouterAgentAdapter = class {
|
|
|
168
197
|
} catch (err) {
|
|
169
198
|
console.error(`Error in generateText agent loop: ${err.message}`);
|
|
170
199
|
} finally {
|
|
171
|
-
for (const
|
|
200
|
+
for (const client of mcpClients) {
|
|
172
201
|
try {
|
|
173
|
-
await
|
|
202
|
+
await client.close();
|
|
174
203
|
} catch (e) {
|
|
175
204
|
}
|
|
176
205
|
}
|
|
@@ -183,4 +212,4 @@ var OpenRouterAgentAdapter = class {
|
|
|
183
212
|
}
|
|
184
213
|
};
|
|
185
214
|
|
|
186
|
-
export { OpenRouterAgentAdapter };
|
|
215
|
+
export { AiSdkAgentAdapter, AiSdkAgentAdapter as OpenRouterAgentAdapter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentgrader/agent-openrouter",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "OpenRouter/AI SDK ReAct agent adapter for the Agentgrader framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
"build:watch": "tsup src/index.ts --format esm --dts --watch"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"@agentgrader/core": "^1.1.2",
|
|
25
|
+
"@ai-sdk/anthropic": "^1.2.12",
|
|
24
26
|
"@ai-sdk/openai": "^1.1.0",
|
|
25
|
-
"@agentgrader/core": "^1.0.1",
|
|
26
27
|
"ai": "^4.1.0",
|
|
27
28
|
"zod": "^3.23.8"
|
|
28
29
|
},
|
|
@@ -30,6 +31,6 @@
|
|
|
30
31
|
"tsup": "^8.5.1"
|
|
31
32
|
},
|
|
32
33
|
"peerDependencies": {
|
|
33
|
-
"@agentgrader/core": "^1.
|
|
34
|
+
"@agentgrader/core": "^1.1.2"
|
|
34
35
|
}
|
|
35
36
|
}
|