Skip to content

Commit 9cf99b9

Browse files
Gemini vercel ai sdk adapter (#56)
* vercel ai adpater for gemini cli * tests fixed based upon v5 * remove logic for normalisation for openai (not needed) * tests fixed based upon v5
1 parent 05c4c92 commit 9cf99b9

File tree

15 files changed

+3955
-90
lines changed

15 files changed

+3955
-90
lines changed

bun.lock

Lines changed: 603 additions & 88 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@
5050
"commander": "^14.0.1",
5151
"core-js": "3.45.1",
5252
"debug": "4.4.3",
53+
"hono": "^4.10.6",
5354
"mitt": "^3.0.1",
5455
"proxy-agent": "^6.5.0",
5556
"puppeteer-core": "24.23.0",
57+
"semver": "^7.7.3",
5658
"smol-toml": "^1.4.2"
5759
},
5860
"devDependencies": {

packages/agent/package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,19 @@
2828
"author": "",
2929
"license": "MIT",
3030
"dependencies": {
31-
"@browseros/tools": "workspace:*",
31+
"@ai-sdk/amazon-bedrock": "^3.0.59",
32+
"@ai-sdk/anthropic": "^2.0.47",
33+
"@ai-sdk/azure": "^2.0.74",
34+
"@ai-sdk/google": "^2.0.43",
35+
"@ai-sdk/openai": "^2.0.72",
36+
"@ai-sdk/openai-compatible": "^1.0.27",
37+
"@anthropic-ai/claude-agent-sdk": "^0.1.11",
3238
"@browseros/common": "workspace:*",
3339
"@browseros/server": "workspace:*",
34-
"@anthropic-ai/claude-agent-sdk": "^0.1.11",
40+
"@browseros/tools": "workspace:*",
41+
"@google/gemini-cli-core": "^0.16.0",
42+
"@openrouter/ai-sdk-provider": "~1.2.5",
43+
"ai": "^5.0.101",
3544
"zod": "^4.1.12"
3645
},
3746
"devDependencies": {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* Conversion error with structured details
9+
*/
10+
11+
/**
12+
* Structured error compatible with Gemini CLI error handling
13+
*/
14+
export interface StructuredError {
15+
message: string;
16+
status?: number;
17+
}
18+
19+
export interface ConversionErrorDetails {
20+
/** Stage where conversion failed */
21+
stage: 'tool' | 'message' | 'response' | 'stream';
22+
23+
/** Specific operation that failed */
24+
operation: string;
25+
26+
/** Input that caused the failure (sanitized, no secrets) */
27+
input?: unknown;
28+
29+
/** Underlying error if available */
30+
cause?: Error;
31+
32+
/** Additional context for debugging */
33+
context?: Record<string, unknown>;
34+
}
35+
36+
export class ConversionError extends Error {
37+
constructor(
38+
message: string,
39+
readonly details: ConversionErrorDetails,
40+
) {
41+
super(message);
42+
this.name = 'ConversionError';
43+
44+
// Maintain proper stack trace
45+
if (Error.captureStackTrace) {
46+
Error.captureStackTrace(this, ConversionError);
47+
}
48+
}
49+
50+
/**
51+
* Convert to StructuredError for Gemini CLI error handling
52+
*/
53+
toStructuredError(): StructuredError {
54+
return {
55+
message: `[${this.details.stage}] ${this.details.operation}: ${this.message}`,
56+
status: 500,
57+
};
58+
}
59+
60+
/**
61+
* Get user-friendly error message
62+
*/
63+
toFriendlyMessage(): string {
64+
const stage =
65+
this.details.stage.charAt(0).toUpperCase() + this.details.stage.slice(1);
66+
return `${stage} conversion failed: ${this.message}`;
67+
}
68+
}

0 commit comments

Comments
 (0)