@llm-ports/adapter-google 0.1.0-alpha.11

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Babak Abbaschian and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # @llm-ports/adapter-google
2
+
3
+ Native Google Gemini adapter for [`llm-ports`](https://github.com/baabakk/llm-ports), built on the unified [`@google/genai`](https://www.npmjs.com/package/@google/genai) SDK. Implements `LLMPort` with full multimodal support — image content blocks pass through as `inlineData` (base64) or `fileData` (URL), not degraded to placeholder text.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @llm-ports/core @llm-ports/adapter-google @google/genai zod
9
+ ```
10
+
11
+ ## Configure
12
+
13
+ ```ts
14
+ import { createRegistryFromEnv } from "@llm-ports/core";
15
+ import { createGoogleAdapter } from "@llm-ports/adapter-google";
16
+
17
+ const registry = createRegistryFromEnv({
18
+ adapters: {
19
+ google: createGoogleAdapter({
20
+ apiKey: process.env.GOOGLE_API_KEY!, // get one at https://aistudio.google.com/apikey
21
+ }),
22
+ },
23
+ });
24
+
25
+ const llm = registry.getPort();
26
+ ```
27
+
28
+ Env config:
29
+
30
+ ```bash
31
+ LLM_PROVIDER_FAST=google|gemini-2.5-flash|cost:5/day
32
+ LLM_PROVIDER_SMART=google|gemini-2.5-pro|cost:50/day
33
+ LLM_TASK_ROUTE_TRIAGE=fast,smart
34
+ ```
35
+
36
+ ## Why use this over the OpenAI-compat baseURL
37
+
38
+ Gemini exposes an OpenAI-compatible surface at `https://generativelanguage.googleapis.com/v1beta/openai/`. It works for most cases. Reasons to prefer this native adapter:
39
+
40
+ | Concern | OpenAI-compat baseURL | `adapter-google` |
41
+ |---|---|---|
42
+ | `ImageSource.detail` field | Silently ignored | Ignored explicitly (consistent w/ other non-OpenAI providers) |
43
+ | `systemInstruction` | Prepended to user message — changes Gemini's behavior | Native top-level field |
44
+ | Multimodal image richness | image_url with base64 data URI (lossy) | inlineData with explicit mediaType |
45
+ | Bundled pricing | None — supply via `pricingOverrides` | Gemini 2.5 + 2.0 family bundled |
46
+ | `responseSchema` constrained-decoding | Not exposed | v0.2 (currently prompted-JSON + Zod) |
47
+
48
+ ## Supported features (v0.1)
49
+
50
+ | Feature | Status |
51
+ |---------|--------|
52
+ | `generateText` | ✓ |
53
+ | `generateStructured` (Zod schemas) | ✓ (prompted JSON + alpha.5 repair pass; native `responseSchema` in v0.2) |
54
+ | `streamText` | ✓ |
55
+ | `streamStructured` | ✓ (best-effort partial parse) |
56
+ | `runAgent` (single-turn) | ✓ (multi-turn native function-calling in v0.2) |
57
+ | Vision input — base64 images | ✓ (inlineData) |
58
+ | Vision input — URL images | ✓ (fileData) |
59
+ | Audio input — base64 | ✓ (inlineData) |
60
+ | Image size + URL validation at boundary | ✓ (alpha.5) |
61
+ | Embeddings (`gemini-embedding-001`) | ✗ — v0.2 |
62
+ | Explicit context caching | ✗ — v0.2 |
63
+ | Code execution tool | ✗ — v0.2 |
64
+
65
+ ## Adapter options
66
+
67
+ ```ts
68
+ interface GoogleAdapterOptions {
69
+ apiKey: string;
70
+ pricingOverrides?: Record<string, ModelPricing>;
71
+ validationStrategy?: ValidationStrategy;
72
+ imageSizeLimitBytes?: number; // default 20 MB
73
+ }
74
+ ```
75
+
76
+ ## Bundled pricing
77
+
78
+ | Model | Input/1M | Output/1M | Cached input/1M |
79
+ |-------|---------:|----------:|----------------:|
80
+ | `gemini-2.5-pro` | $1.25 | $5.00 | $0.3125 |
81
+ | `gemini-2.5-flash` | $0.075 | $0.30 | $0.01875 |
82
+ | `gemini-2.5-flash-lite` | $0.0375 | $0.15 | $0.009375 |
83
+ | `gemini-2.0-flash` | $0.10 | $0.40 | $0.025 |
84
+ | `gemini-2.0-flash-lite` | $0.075 | $0.30 | — |
85
+
86
+ Pricing source: <https://ai.google.dev/gemini-api/docs/pricing> (verified 2026-05). Bundled values are the under-200k-token tier. For long-context workloads, supply `pricingOverrides` with the over-200k rates.
87
+
88
+ ## Content blocks supported
89
+
90
+ `text`, `image` (base64 → inlineData; URL → fileData), `audio` (base64 only — Gemini accepts inlineData for audio), `tool_use`, `tool_result`. Throws `ContentBlockUnsupportedError` for URL-form audio.
91
+
92
+ ## Cancellation
93
+
94
+ Full `AbortSignal` support shipped in `0.1.0-alpha.6`. The signal is threaded into the `config` arg of `client.models.generateContent`, so `controller.abort()` cancels the in-flight HTTP request. `runAgent` also re-checks the signal between steps. See the [Cancellation guide](https://baabakk.github.io/llm-ports/guides/cancellation).
95
+
96
+ ## Reading next
97
+
98
+ - [Google adapter docs](https://baabakk.github.io/llm-ports/adapters/google) — full feature deep-dive
99
+ - [OpenAI adapter](https://baabakk.github.io/llm-ports/adapters/openai) — comparison when choosing between native Gemini and OpenAI-compat path
100
+ - [Multi-provider routing](https://baabakk.github.io/llm-ports/guides/multi-provider) — chain Gemini with Anthropic / OpenAI fallbacks
101
+ - [@google/genai SDK docs](https://github.com/googleapis/js-genai) — underlying SDK reference