Files
OmniRoute/open-sse/executors/gemini-cli.ts
diegosouzapw 94175fa04a refactor(open-sse): migrate all 94 .js files to .ts
- Rename all 94 .js files to .ts across config/, utils/, services/,
  handlers/, executors/, translator/, transformer/, and root index
- Add proper TypeScript interfaces: RegistryEntry, AudioProvider, FetchOptions
- Add class property declarations to BaseExecutor
- Type key function parameters in utils layer (tlsClient, stream,
  logger, error, proxyFetch, proxyDispatcher, etc.)
- Add @ts-ignore annotations for remaining TS2339 errors (gradual migration)
- Zero TypeScript errors in open-sse/tsconfig.json
- Zero .js files remaining in open-sse/
2026-02-17 07:47:58 -03:00

66 lines
1.9 KiB
TypeScript

import { BaseExecutor } from "./base.js";
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.js";
export class GeminiCLIExecutor extends BaseExecutor {
constructor() {
super("gemini-cli", PROVIDERS["gemini-cli"]);
}
buildUrl(model, stream, urlIndex = 0) {
const action = stream ? "streamGenerateContent?alt=sse" : "generateContent";
return `${this.config.baseUrl}:${action}`;
}
buildHeaders(credentials, stream = true) {
return {
"Content-Type": "application/json",
Authorization: `Bearer ${credentials.accessToken}`,
...(stream && { Accept: "text/event-stream" }),
};
}
transformRequest(model, body, stream, credentials) {
if (!body.project && credentials?.projectId) {
body.project = credentials.projectId;
}
return body;
}
async refreshCredentials(credentials, log) {
if (!credentials.refreshToken) return null;
try {
const response = await fetch(OAUTH_ENDPOINTS.google.token, {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
Accept: "application/json",
},
body: new URLSearchParams({
grant_type: "refresh_token",
refresh_token: credentials.refreshToken,
client_id: this.config.clientId,
client_secret: this.config.clientSecret,
}),
});
if (!response.ok) return null;
const tokens = await response.json();
log?.info?.("TOKEN", "Gemini CLI refreshed");
return {
accessToken: tokens.access_token,
refreshToken: tokens.refresh_token || credentials.refreshToken,
expiresIn: tokens.expires_in,
projectId: credentials.projectId,
};
} catch (error) {
log?.error?.("TOKEN", `Gemini CLI refresh error: ${error.message}`);
return null;
}
}
}
export default GeminiCLIExecutor;