/** * @license * Copyright 2026 aphrody-code * SPDX-License-Identifier: Apache-2.0 */ import { geminiWebAskAsync } from "../rust/bridge.ts"; import { resolveCookiePath } from "../utils/paths.ts"; import type { GeminiAskOptions, GeminiChatResponse } from "./types.ts"; export class GeminiRustClient { private cookiePath: string; constructor(cookiePath?: string) { this.cookiePath = cookiePath ? resolveCookiePath(cookiePath) : resolveCookiePath("gemini"); } isAvailable(): boolean { try { // Check if file exists return Bun.file(this.cookiePath).size > 0; } catch { return false; } } async ask(prompt: string, opts: GeminiAskOptions = {}): Promise { const targetCookiePath = opts.cookiePath ? resolveCookiePath(opts.cookiePath) : this.cookiePath; const model = opts.model ?? "flash"; const res = await geminiWebAskAsync(targetCookiePath, prompt, model, { timeoutMs: opts.timeoutMs ?? 120_000, }); if (!res || res.error) { throw new Error(res?.error ?? "Unknown error executing Gemini via Rust bridge"); } return { text: res.text, conversationId: res.conversation_id, responseId: res.response_id, choiceId: res.choice_id, engine: "rust", model, raw: res, }; } }