@aeye/google 0.0.0-stage → 0.11.0
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/README.md +119 -3
- package/aeye-google.md +123 -0
- package/dist/convert.d.ts +191 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +539 -0
- package/dist/convert.js.map +1 -0
- package/dist/decisions.d.ts +97 -0
- package/dist/decisions.d.ts.map +1 -0
- package/dist/decisions.js +62 -0
- package/dist/decisions.js.map +1 -0
- package/dist/google.d.ts +494 -0
- package/dist/google.d.ts.map +1 -0
- package/dist/google.js +1366 -0
- package/dist/google.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/media.d.ts +56 -0
- package/dist/media.d.ts.map +1 -0
- package/dist/media.js +143 -0
- package/dist/media.js.map +1 -0
- package/dist/models.d.ts +133 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +126 -0
- package/dist/models.js.map +1 -0
- package/dist/retry.d.ts +112 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +231 -0
- package/dist/retry.js.map +1 -0
- package/dist/types.d.ts +63 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +74 -0
- package/dist/types.js.map +1 -0
- package/package.json +75 -4
package/README.md
CHANGED
|
@@ -1,3 +1,119 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @aeye/google
|
|
2
|
+
|
|
3
|
+
Google Gemini provider for [@aeye](https://github.com/ClickerMonkey/aeye): the Gemini API (`generativelanguage.googleapis.com`) through the official [`@google/genai`](https://www.npmjs.com/package/@google/genai) SDK, and Vertex AI through the same SDK.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @aeye/google @aeye/ai @aeye/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Requires Node 22 or later.
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { AI } from '@aeye/ai';
|
|
17
|
+
import { GoogleProvider } from '@aeye/google';
|
|
18
|
+
import { googleModels } from '@aeye/models';
|
|
19
|
+
|
|
20
|
+
const google = new GoogleProvider({ apiKey: process.env.GEMINI_API_KEY }); // or GOOGLE_API_KEY, read when apiKey is left out
|
|
21
|
+
const ai = AI.with().providers({ google }).create({ models: googleModels });
|
|
22
|
+
|
|
23
|
+
const response = await ai.chat.get(
|
|
24
|
+
{ messages: [{ role: 'user', content: 'Hello!' }] },
|
|
25
|
+
{ metadata: { model: 'gemini-3.8-flash' } },
|
|
26
|
+
);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`googleModels` (from `@aeye/models`) carries prices, capabilities, thinking levels, the parameters each model accepts and what the provider reads about it (`providerOptions.google`). Pass it as `modelInfo` too: the provider reads each model from it, and `listModels()` merges it into the live model list (offering only the models it has data for):
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const google = new GoogleProvider({ modelInfo: googleModels });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Vertex AI
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
const google = new GoogleProvider({ vertexai: true, project: 'my-project', location: 'global' });
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Credentials come from Application Default Credentials, or `googleAuthOptions`.
|
|
42
|
+
|
|
43
|
+
## What it supports
|
|
44
|
+
|
|
45
|
+
| Request | Gemini |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| Chat and streaming | `generateContent` / `streamGenerateContent` |
|
|
48
|
+
| System instructions | System messages become `systemInstruction` |
|
|
49
|
+
| Function calling | Function declarations in Gemini's JSON Schema dialect (`parametersJsonSchema`); parallel calls; tool choice as `AUTO`, `ANY`, `NONE`, or `VALIDATED` (strict tools, and `{ allowed }`) |
|
|
50
|
+
| Structured output | `responseJsonSchema` with `application/json`; `responseFormat: 'json'` for JSON mode |
|
|
51
|
+
| Thinking | `reason.effort` as `thinkingLevel` (Gemini 3 and 4), or `thinkingBudget` (Gemini 2.5, from `reason.maxTokens` or the effort); thought summaries as `reasoning`; thought signatures replayed on later turns |
|
|
52
|
+
| Media input | Images, audio, video and documents (PDF, text, Office), inline, by URL (Files API, Cloud Storage, YouTube, http), or uploaded through the Files API above `uploadThreshold`; `detail` as per-part media resolution |
|
|
53
|
+
| Hosted tools | `web_search` (Google Search grounding, with citations), `web_fetch` (URL context), `code_interpreter` (code execution), `file_search` (File Search stores), `mcp` |
|
|
54
|
+
| Context caching | Implicit by default; `explicitCaching` caches the prefix a `cacheBreakpoint` ends; `createCache` / `deleteCache`; `extra.cachedContent` |
|
|
55
|
+
| Token counting | `countTokens(request)` |
|
|
56
|
+
| Image output | `modalities: ['image']` on image models; `ai.image.generate` / `edit` (and streaming) with Gemini image models; Imagen on Vertex AI |
|
|
57
|
+
| Speech | `ai.speech` with Gemini TTS models (WAV or PCM; `instructions` and `speed` as the speaking style) |
|
|
58
|
+
| Transcription | `ai.transcribe` with Gemini 3.5 Transcribe (languages, custom vocabulary, diarization, word timestamps, SRT/WebVTT), or any Gemini model |
|
|
59
|
+
| Embeddings | `ai.embed` with `gemini-embedding-2` (text and images, one space) and `gemini-embedding-001`; `dimensions`; `extra.taskType` |
|
|
60
|
+
| Decisions | `ai.decide` with Gemini Decision 1 |
|
|
61
|
+
| Batches | `ai.batch` (inlined requests, half price) |
|
|
62
|
+
| Service tiers | `serviceTier: 'flex' \| 'fast' \| 'default'` as Flex, Priority and Standard inference |
|
|
63
|
+
| Safety | `safetySettings` in the config (or `extra.safetySettings`); blocked prompts and filtered answers end as `content_filter` with a `refusal` |
|
|
64
|
+
|
|
65
|
+
Rerank isn't offered by Gemini, so the provider has no `rerank`.
|
|
66
|
+
|
|
67
|
+
## Configuration
|
|
68
|
+
|
|
69
|
+
| Option | Purpose |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `apiKey` | Gemini API key (default `GEMINI_API_KEY`, then `GOOGLE_API_KEY`) |
|
|
72
|
+
| `vertexai`, `project`, `location`, `googleAuthOptions` | Vertex AI |
|
|
73
|
+
| `apiVersion` | API version (default `v1beta` on the Gemini API) |
|
|
74
|
+
| `baseURL`, `headers`, `timeout`, `fetch` | HTTP |
|
|
75
|
+
| `retry`, `retryEvents` | Retries with backoff; `retryDelay` from the API is honored |
|
|
76
|
+
| `hooks` | `beforeRequest` / `afterRequest` / `onError` per operation |
|
|
77
|
+
| `safetySettings` | Sent with every request |
|
|
78
|
+
| `uploadThreshold` | Bytes above which a part goes through the Files API (default 20 MB) |
|
|
79
|
+
| `explicitCaching` | `true` or `{ ttl }` to cache breakpoint prefixes explicitly |
|
|
80
|
+
| `modelInfo` | The models' data (`googleModels`): what the provider reads per model, merged into `listModels` |
|
|
81
|
+
| `defaultModels` | Models per operation |
|
|
82
|
+
|
|
83
|
+
Anything in `request.extra` goes into the request's `GenerateContentConfig` (for example `topK`, `mediaResolution`, `safetySettings`, `cachedContent`, `speechConfig`).
|
|
84
|
+
|
|
85
|
+
## Where the model rules live
|
|
86
|
+
|
|
87
|
+
The provider keeps no per-model rules, tables or id patterns. Everything it decides per model it reads from the model's `ModelInfo`:
|
|
88
|
+
|
|
89
|
+
- `supportedParameters`: sampling, penalties, seed, stop sequences, thinking (`reason`) and `serviceTier` are sent only when listed (`supportedRequest` from `@aeye/ai`, applied on the wire as well as by the ai layer);
|
|
90
|
+
- `reasoningEfforts`: the thinking levels a level model takes;
|
|
91
|
+
- `providerOptions.google` (`GoogleModelOptions`): `kind` (chat, image, imagen, tts, transcribe, embedding, decision), `thinking` (`level`, `budget` with its range and whether 0 turns it off, or `none`), `explicitCaching`, the Gemini 3 request features (`partMediaResolution`, `functionResponseParts`, `thoughtSignatures`, `serverToolInvocations`, `toolsWithOutput`), `image` (aspect ratios and sizes), `speech` (voices and style), `embedding` (sizes, multimodal) and `aliasOf`;
|
|
92
|
+
- `schema`: the schema rules (`{ base: 'google' }`).
|
|
93
|
+
|
|
94
|
+
That data is `@aeye/models`' `googleModels`: what models.list and the docs pages say (`packages/models/scraped/google.json`) with `packages/models/overrides/google.ts` merged in (family defaults, a few documented per-generation rules, corrections, and the live matrix's results in its `measured` block). Give it to the provider as `modelInfo`. A model the provider has no data for gets `defaultGoogleModel`: a current Gemini chat model that thinks by level and is sent nothing it isn't known to take (no sampling, penalties, service tier, explicit caching or Gemini 3 request features). To change one model, override its data (`modelOverrides`, or your own `modelInfo`):
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
const ai = AI.with().providers({ google }).create({
|
|
98
|
+
models: googleModels,
|
|
99
|
+
modelOverrides: [{ provider: 'google', modelId: 'gemini-3.8-flash', overrides: { providerOptions: { google: { explicitCaching: false } } } }],
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Errors
|
|
104
|
+
|
|
105
|
+
`GoogleAuthError`, `GoogleRateLimitError` (with `retryAfter`), `GoogleQuotaError` (daily limits, depleted credits), `GoogleContextWindowError`, `GoogleSafetyError`, and `GoogleError` for the rest, each with the HTTP `status` and error `body`. A request over the context window ends with `finishReason: 'length'` instead of throwing, so prompts can trim and retry; a rejected schema becomes a `SchemaRejectedError` naming the tool or output.
|
|
106
|
+
|
|
107
|
+
## Testing
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npm test # unit tests (mocked HTTP)
|
|
111
|
+
npm run test:integration # live tests; needs GEMINI_API_KEY or GOOGLE_API_KEY
|
|
112
|
+
npm run matrix # live support matrix (parameters, thinking, tools, caching, schemas)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
See `docs/measured/` for the measured support matrix.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
GPL-3.0
|
package/aeye-google.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# @aeye/google
|
|
2
|
+
|
|
3
|
+
One-line purpose: Google Gemini provider for the `@aeye/ai` framework: the Gemini API (`generativelanguage.googleapis.com`, and Vertex AI) through the official `@google/genai` SDK, covering chat, streaming, function calling, structured output, thinking, multimodal input, Google's hosted tools, context caching, token counting, image generation and editing, speech, transcription, embeddings, decisions and batches.
|
|
4
|
+
|
|
5
|
+
## When to use
|
|
6
|
+
|
|
7
|
+
- You want Gemini models (Gemini 4, 3.x, 2.5; Nano Banana image models; Gemini TTS; Gemini 3.5 Transcribe; Gemini Embedding; Gemini Decision 1) through `@aeye/ai`.
|
|
8
|
+
- You want Gemini on Vertex AI (`vertexai: true`), including Imagen there.
|
|
9
|
+
|
|
10
|
+
## Install / import
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @aeye/google
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import {
|
|
18
|
+
GoogleProvider,
|
|
19
|
+
type GoogleConfig,
|
|
20
|
+
type GoogleHooks,
|
|
21
|
+
GoogleError, GoogleAuthError, GoogleRateLimitError, GoogleQuotaError, GoogleContextWindowError, GoogleSafetyError,
|
|
22
|
+
// model data: what the provider reads (ModelInfo.providerOptions.google), and the default for a model with none
|
|
23
|
+
type GoogleModelOptions, googleOptions, defaultGoogleModel, toModelInfo, bareModelId,
|
|
24
|
+
} from '@aeye/google';
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Node >= 22. `@google/genai` (v3) is a dependency.
|
|
28
|
+
|
|
29
|
+
## Register with `@aeye/ai`
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { AI } from '@aeye/ai';
|
|
33
|
+
import { GoogleProvider } from '@aeye/google';
|
|
34
|
+
import { googleModels } from '@aeye/models';
|
|
35
|
+
|
|
36
|
+
const google = new GoogleProvider({ modelInfo: googleModels }); // apiKey defaults to GEMINI_API_KEY, then GOOGLE_API_KEY
|
|
37
|
+
const ai = AI.with().providers({ google }).create({ models: googleModels });
|
|
38
|
+
|
|
39
|
+
await ai.chat.get({ messages: [{ role: 'user', content: 'Hi' }] }, { metadata: { model: 'gemini-3.8-flash' } });
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`googleModels` carries prices (Standard tier on the scrape date), capabilities, thinking levels and each model's `supportedParameters`, so the ai layer leaves out sampling settings a model ignores or refuses.
|
|
43
|
+
|
|
44
|
+
## Configuration (`GoogleConfig`)
|
|
45
|
+
|
|
46
|
+
| Field | Notes |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| `apiKey` | Gemini API key; default `GEMINI_API_KEY`, then `GOOGLE_API_KEY` |
|
|
49
|
+
| `vertexai`, `project`, `location`, `googleAuthOptions` | Vertex AI (Application Default Credentials by default) |
|
|
50
|
+
| `apiVersion` | Default `v1beta` on the Gemini API (the SDK defaults to `v1`; caching, Files and the Decisions API are beta) |
|
|
51
|
+
| `baseURL`, `headers`, `timeout`, `fetch` | HTTP options passed to the SDK (`fetch` for proxies and tests) |
|
|
52
|
+
| `retry`, `retryEvents` | `withRetry` backoff with jitter; retries 0 (network), 429, 500, 502, 503, 504; honors `RetryInfo.retryDelay`; never retries daily quotas, `limit: 0`, auth, or context overflows. The SDK's own retries stay off |
|
|
53
|
+
| `hooks` | `beforeRequest` / `afterRequest` / `onError` for `chat`, `imageGenerate`, `imageEdit`, `transcribe`, `speech`, `embed`, `decide`; `params` is the SDK's request |
|
|
54
|
+
| `safetySettings` | Sent with every request |
|
|
55
|
+
| `uploadThreshold` | Parts above this many bytes go through the Files API (default 20 MB) |
|
|
56
|
+
| `explicitCaching` | `true` or `{ ttl }`: cache the prefix the last `cacheBreakpoint` ends |
|
|
57
|
+
| `modelInfo` | The models' data by id (`googleModels`): read per call, merged into `listModels` |
|
|
58
|
+
| `defaultModels` | Defaults: `gemini-nano-banana-2.1` (images), `gemini-3.5-flash-lite` (image analysis), `gemini-3.5-transcribe`, `gemini-3.8-flash-lite-tts`, `gemini-embedding-2`, `gemini-decision-1`; no chat default |
|
|
59
|
+
|
|
60
|
+
`request.extra` is spread into the `GenerateContentConfig` (`topK`, `mediaResolution`, `safetySettings`, `cachedContent`, `speechConfig`, `thinkingConfig`, ...), except `retry` / `retryEvents`.
|
|
61
|
+
|
|
62
|
+
## Request mapping
|
|
63
|
+
|
|
64
|
+
| @aeye | Gemini |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| system messages | `systemInstruction` |
|
|
67
|
+
| assistant / tool messages | `model` contents with `functionCall` parts; `functionResponse` parts (named after their call, `{ error }` for failures; images and files inside the response on Gemini 3+); consecutive same-role contents merged so parallel calls are answered in one turn |
|
|
68
|
+
| `tools` | `functionDeclarations` with `parametersJsonSchema` rendered by `@aeye/schema` (`google` family; strict tools `GOOGLE_STRICT`) |
|
|
69
|
+
| `toolChoice` | `auto` → AUTO (VALIDATED when a tool is strict), `required` → ANY, `{ tool }` → ANY + allowed, `{ allowed }` → VALIDATED (ANY when required) + allowed, `none` → NONE |
|
|
70
|
+
| `responseFormat` | schema → `responseJsonSchema` + `application/json`; `'json'` → JSON MIME type. Gemini 2.5 can't combine functions with a schema, so there it goes in the prompt |
|
|
71
|
+
| `reason` | Gemini 3/4: `thinkingLevel` from `effort` (clamped to `reasoningEfforts`; `none` → the lowest level; a lone `maxTokens` → the nearest level). Gemini 2.5: `thinkingBudget` from `maxTokens` or the effort, within the model's range (`none` → 0 where allowed). `includeThoughts` unless `exclude` |
|
|
72
|
+
| `temperature`, `topP`, `maxTokens`, `stop` (≤5), `seed`, penalties | `generationConfig` |
|
|
73
|
+
| `serviceTier` | `flex` → Flex, `fast` → Priority, `default` → Standard |
|
|
74
|
+
| `modalities` | `['image']` → TEXT+IMAGE; `['audio']` → AUDIO with `audio.voice` |
|
|
75
|
+
| `hostedTools` | `web_search` → `googleSearch` (`blockedDomains` → `excludeDomains` on Vertex only; `allowedDomains` refused), `web_fetch` → `urlContext`, `code_interpreter` → `codeExecution`, `file_search` → `fileSearch`, `mcp` → `mcpServers`; `image_generation` refused. With functions on Gemini 3+, `includeServerSideToolInvocations` |
|
|
76
|
+
| content parts | text; image/audio/video/file inline, by `fileData` (Files API, `gs://`, YouTube, http URLs of known type), or uploaded; `detail` → per-part `mediaResolution` on Gemini 3+; `cacheBreakpoint` → explicit cache when on |
|
|
77
|
+
| `metadata` | `labels` (Vertex AI only) |
|
|
78
|
+
|
|
79
|
+
## Response mapping
|
|
80
|
+
|
|
81
|
+
- Text, thought summaries (`reasoning.content`), tool calls (Gemini sends each whole; ids generated when missing), images, audio.
|
|
82
|
+
- Thought signatures are kept as `google-gemini-v1` reasoning details (`fc:<call id>`, `text:<n>`) and replayed on later turns, only for reasoning whose `provider` is `google` (or unset). A Gemini 3+ function call without a signature (history from another model) is sent with `skip_thought_signature_validator`. Server-side tool parts (search calls, code runs) are kept as `google.part` details and replayed.
|
|
83
|
+
- `finishReason`: STOP → stop (tool_calls when calls were made), MAX_TOKENS/CONTINUATION → length, SAFETY/RECITATION/BLOCKLIST/PROHIBITED_CONTENT/SPII/IMAGE_* /LANGUAGE → content_filter with a `refusal`; a blocked prompt → content_filter with the block reason.
|
|
84
|
+
- `usage`: prompt tokens by modality (text incl. video and documents, image, audio), server-side tool prompt tokens as input, cache reads as `text.cached` (out of the input), candidate tokens by modality (image tokens as `image.tokens`, audio as `audio.output`), thoughts as `reasoning.output`, and hosted tool calls (`web_search` per query, `web_fetch`, `code_interpreter`).
|
|
85
|
+
- `citations` from grounding chunks and supports, byte offsets turned into character offsets.
|
|
86
|
+
- A context window overflow ends as `finishReason: 'length'`; a 400 naming a function declaration or the response schema becomes a `SchemaRejectedError`.
|
|
87
|
+
|
|
88
|
+
## Other operations
|
|
89
|
+
|
|
90
|
+
- `generateImage` / `editImage` (and streams): Gemini image models via `generateContent`, `n` calls for `n` images, `size` → nearest `aspectRatio` + `imageSize` (512/1K/2K/4K), `quality` → size; edits send image, references and a described mask before the prompt. Imagen on Vertex AI only.
|
|
91
|
+
- `speech`: Gemini TTS; WAV (default) or PCM out; `instructions`/`speed` → `speechMetadata.style` (3.8 TTS) or a spoken direction; voice ids (`voice_...`, `voicekey_...`) on 3.8.
|
|
92
|
+
- `transcribe` / `transcribeStream`: Gemini 3.5 Transcribe with `audioTranscriptionConfig` (`language` → `languageCodes`, `prompt` → custom vocabulary, `diarized_json` → diarization, `srt`/`vtt`/`verbose_json` → word timestamps and captions); other models are prompted to transcribe.
|
|
93
|
+
- `embed`: one content per input so each gets a vector; `dimensions` → `outputDimensionality`; `extra.taskType` (and `title`) on `gemini-embedding-001`, a task prefix on `gemini-embedding-2`; images on `gemini-embedding-2` only.
|
|
94
|
+
- `decide`: Gemini Decision 1 (`noul`/`choice`/`score`); conversations are serialized as text; a blocked input answers every question with `refusal`.
|
|
95
|
+
- `submitBatch` / `getBatch`: inlined requests.
|
|
96
|
+
- `countTokens(request)`, `createCache` / `deleteCache`, `uploadFile` / `deleteFile`, `listModels`, `checkHealth`.
|
|
97
|
+
- No `rerank` (Gemini has none).
|
|
98
|
+
|
|
99
|
+
## Gotchas
|
|
100
|
+
|
|
101
|
+
- Gemini 3.5 Flash-Lite, 3.6 Flash and later, and Gemini 4 silently ignore `temperature`/`topP`/`topK`; their `supportedParameters` leave them out. Gemini 3 models refuse penalties, `logprobs` and `candidateCount` (measured).
|
|
102
|
+
- Gemini 3.8 Flash and Gemini 4 have no `minimal` level; only Gemini 4 Neon and Hydrogen take `xhigh`.
|
|
103
|
+
- Gemini 4 has no explicit caching; implicit caching applies from 4,096 tokens.
|
|
104
|
+
- The 2.5 models answer 404 to new users; `gemini-2.5-pro`/`-flash` route to 3.8 Flash / 3.5 Flash-Lite from December 1, 2026.
|
|
105
|
+
- Measured support: `docs/measured/` in this package (`npm run matrix` re-runs it).
|
|
106
|
+
|
|
107
|
+
## Where the model rules live
|
|
108
|
+
|
|
109
|
+
The provider keeps no per-model rules, tables or id patterns. Everything it decides per model it reads from the model's `ModelInfo`:
|
|
110
|
+
|
|
111
|
+
- `supportedParameters`: sampling, penalties, seed, stop sequences, thinking (`reason`) and `serviceTier` are sent only when listed (`supportedRequest` from `@aeye/ai`, applied on the wire as well as by the ai layer);
|
|
112
|
+
- `reasoningEfforts`: the thinking levels a level model takes;
|
|
113
|
+
- `providerOptions.google` (`GoogleModelOptions`): `kind` (chat, image, imagen, tts, transcribe, embedding, decision), `thinking` (`level`, `budget` with its range and whether 0 turns it off, or `none`), `explicitCaching`, the Gemini 3 request features (`partMediaResolution`, `functionResponseParts`, `thoughtSignatures`, `serverToolInvocations`, `toolsWithOutput`), `image` (aspect ratios and sizes), `speech` (voices and style), `embedding` (sizes, multimodal) and `aliasOf`;
|
|
114
|
+
- `schema`: the schema rules (`{ base: 'google' }`).
|
|
115
|
+
|
|
116
|
+
That data is `@aeye/models`' `googleModels`: what models.list and the docs pages say (`packages/models/scraped/google.json`) with `packages/models/overrides/google.ts` merged in (family defaults, a few documented per-generation rules, corrections, and the live matrix's results in its `measured` block). Give it to the provider as `modelInfo`. A model the provider has no data for gets `defaultGoogleModel`: a current Gemini chat model that thinks by level and is sent nothing it isn't known to take (no sampling, penalties, service tier, explicit caching or Gemini 3 request features). To change one model, override its data (`modelOverrides`, or your own `modelInfo`):
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
const ai = AI.with().providers({ google }).create({
|
|
120
|
+
models: googleModels,
|
|
121
|
+
modelOverrides: [{ provider: 'google', modelId: 'gemini-3.8-flash', overrides: { providerOptions: { google: { explicitCaching: false } } } }],
|
|
122
|
+
});
|
|
123
|
+
```
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapping between @aeye chat shapes and the Gemini API's `generateContent`.
|
|
3
|
+
*
|
|
4
|
+
* Output parts are mapped one candidate (or stream chunk) at a time into core
|
|
5
|
+
* `Chunk`s, so a complete response is its chunks folded together and a
|
|
6
|
+
* stream reuses the same mapping.
|
|
7
|
+
*/
|
|
8
|
+
import { type AudioFormat, type Chunk, type Citation, type FinishReason, type HostedTool, type HostedToolType, type Reason, type ReasoningDetail, type ReasoningEffort, type ServiceTier, type Usage } from '@aeye/core';
|
|
9
|
+
import type { Candidate, GenerateContentResponse, GenerateContentResponseUsageMetadata, GroundingMetadata, Part, ThinkingConfig, Tool } from '@google/genai';
|
|
10
|
+
import type { GoogleModelOptions } from './models';
|
|
11
|
+
/**
|
|
12
|
+
* The provider name, which marks the reasoning (thought signatures) Gemini
|
|
13
|
+
* produces so other providers don't replay it.
|
|
14
|
+
*/
|
|
15
|
+
export declare const GOOGLE_PROVIDER = "google";
|
|
16
|
+
/**
|
|
17
|
+
* The `ReasoningDetail.format` thought summaries and signatures round-trip
|
|
18
|
+
* through.
|
|
19
|
+
*/
|
|
20
|
+
export declare const GEMINI_REASONING_FORMAT = "google-gemini-v1";
|
|
21
|
+
/**
|
|
22
|
+
* The signature Gemini accepts on a function call it didn't produce (history
|
|
23
|
+
* from another model, or one whose signature was lost), per
|
|
24
|
+
* /docs/thought-signatures "FAQs".
|
|
25
|
+
*/
|
|
26
|
+
export declare const SKIP_SIGNATURE = "skip_thought_signature_validator";
|
|
27
|
+
/**
|
|
28
|
+
* The MIME type a format name, extension, or MIME type names.
|
|
29
|
+
*/
|
|
30
|
+
export declare function mimeTypeOf(format: string | undefined): string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The extension of a file name, path or URL, if any.
|
|
33
|
+
*/
|
|
34
|
+
export declare function extensionOf(path: string | undefined): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* The first MIME type a list of candidates names, ignoring the generic
|
|
37
|
+
* octet-stream the API refuses.
|
|
38
|
+
*/
|
|
39
|
+
export declare function pickMimeType(...candidates: Array<string | undefined>): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Whether a URL is one the Gemini API reads itself: a Files API file, a
|
|
42
|
+
* Cloud Storage object, or a YouTube video.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isFileUri(uri: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* `Request.reason` as a `thinkingConfig` for the model:
|
|
47
|
+
*
|
|
48
|
+
* - Level models (Gemini 3 and later) take `thinkingLevel`, the effort
|
|
49
|
+
* clamped to the levels the model accepts; a budget alone picks the
|
|
50
|
+
* nearest level. `none` goes to the lowest level, since Gemini 3 and 4
|
|
51
|
+
* can't turn thinking off.
|
|
52
|
+
* - Budget models (Gemini 2.5) take `thinkingBudget`: `maxTokens`, else the
|
|
53
|
+
* effort's budget, within the model's range; `none` is 0 where allowed.
|
|
54
|
+
* - Thought summaries are asked for (`includeThoughts`) unless `exclude`.
|
|
55
|
+
*
|
|
56
|
+
* Without `reason` nothing is sent and the model thinks by its default.
|
|
57
|
+
*
|
|
58
|
+
* @param thinking - How the model thinks (`providerOptions.google.thinking`; none: it doesn't)
|
|
59
|
+
* @param reason - The reasoning asked for
|
|
60
|
+
* @param accepted - The efforts the model accepts, when known
|
|
61
|
+
* @param maxTokens - The output limit, which a budget stays under
|
|
62
|
+
*/
|
|
63
|
+
export declare function toThinkingConfig(thinking: GoogleModelOptions['thinking'], reason: Reason | undefined, accepted: ReasoningEffort[] | undefined, maxTokens?: number): ThinkingConfig | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* A provider-run tool as a Gemini tool.
|
|
66
|
+
*
|
|
67
|
+
* - web_search: Grounding with Google Search (`blockedDomains` as
|
|
68
|
+
* `excludeDomains`, on Vertex AI only; Google Search can't limit itself to domains)
|
|
69
|
+
* - web_fetch: URL context
|
|
70
|
+
* - file_search: File Search over File Search stores (`vectorStoreIds` are
|
|
71
|
+
* store names, `fileSearchStores/...`)
|
|
72
|
+
* - code_interpreter: code execution
|
|
73
|
+
* - mcp: a remote MCP server over streamable HTTP
|
|
74
|
+
* - image_generation: not a Gemini tool; use an image model instead
|
|
75
|
+
*/
|
|
76
|
+
export declare function toHostedTool(tool: HostedTool, vertex?: boolean): Tool;
|
|
77
|
+
/**
|
|
78
|
+
* A Gemini finish reason as a @aeye finish reason. `CONTINUATION` (a long
|
|
79
|
+
* decode stopped at the per-request cap) counts as `length`; malformed calls
|
|
80
|
+
* and other failures end like a normal stop, with `finishMessage` kept as
|
|
81
|
+
* the refusal when it explains a filter.
|
|
82
|
+
*
|
|
83
|
+
* @param reason - The candidate's finish reason
|
|
84
|
+
* @param calledTools - Whether the candidate called tools
|
|
85
|
+
*/
|
|
86
|
+
export declare function toFinishReason(reason: string | undefined, calledTools: boolean): FinishReason;
|
|
87
|
+
/**
|
|
88
|
+
* Gemini usage as @aeye usage, each token counted once:
|
|
89
|
+
*
|
|
90
|
+
* - input: prompt tokens by modality (text, video and documents as text,
|
|
91
|
+
* images, audio), plus the prompt tokens of server-side tool use; tokens
|
|
92
|
+
* read from the cache come out of the text input
|
|
93
|
+
* - output: candidate tokens by modality (text, images, audio), with thought
|
|
94
|
+
* tokens as reasoning output
|
|
95
|
+
*/
|
|
96
|
+
export declare function toUsage(usage: GenerateContentResponseUsageMetadata | undefined): Usage | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Character index in `text` of a UTF-8 byte offset: grounding segments
|
|
99
|
+
* count bytes, @aeye citations count characters.
|
|
100
|
+
*/
|
|
101
|
+
export declare function charIndex(text: string, byteOffset: number): number;
|
|
102
|
+
/**
|
|
103
|
+
* Sources the response was grounded on (Google Search, Maps, URL context,
|
|
104
|
+
* File Search), with the span of the answer each supports.
|
|
105
|
+
*
|
|
106
|
+
* @param metadata - The candidate's grounding metadata
|
|
107
|
+
* @param text - The whole answer, to turn byte offsets into characters
|
|
108
|
+
*/
|
|
109
|
+
export declare function toCitations(metadata: GroundingMetadata | undefined, text: string): Citation[] | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Hosted tool calls a candidate reports, by type: search queries (Gemini 3
|
|
112
|
+
* bills each one; earlier models one per grounded prompt), URL fetches,
|
|
113
|
+
* code runs, and File Search retrievals.
|
|
114
|
+
*/
|
|
115
|
+
export declare function hostedToolUsage(candidate: Candidate | undefined, parts: Part[]): Partial<Record<HostedToolType, number>> | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* State carried across the chunks of one response: generated tool call ids,
|
|
118
|
+
* how many signatures and server parts were seen, the text so far (for
|
|
119
|
+
* citations) and the last usage reported.
|
|
120
|
+
*/
|
|
121
|
+
export declare class ResponseState {
|
|
122
|
+
readonly idPrefix: string;
|
|
123
|
+
/** Text of the answer so far */
|
|
124
|
+
text: string;
|
|
125
|
+
/** Signatures seen, to give each its own detail */
|
|
126
|
+
signatures: number;
|
|
127
|
+
/** Server-side tool parts seen */
|
|
128
|
+
serverParts: number;
|
|
129
|
+
/** Calls seen */
|
|
130
|
+
calls: number;
|
|
131
|
+
/** Latest usage (stream chunks repeat it) */
|
|
132
|
+
usage?: GenerateContentResponseUsageMetadata;
|
|
133
|
+
/** Latest candidate with grounding */
|
|
134
|
+
grounding?: Candidate;
|
|
135
|
+
/** Finish reason, when one came */
|
|
136
|
+
finish?: string;
|
|
137
|
+
/** Why it finished, in words, when the API said */
|
|
138
|
+
finishMessage?: string;
|
|
139
|
+
/** Whether a tool was called */
|
|
140
|
+
calledTools: boolean;
|
|
141
|
+
/** Blocked prompt, when it was */
|
|
142
|
+
blocked?: string;
|
|
143
|
+
/** Tier the response ran on */
|
|
144
|
+
serviceTier?: ServiceTier;
|
|
145
|
+
/** Hosted tool calls */
|
|
146
|
+
tools?: Partial<Record<HostedToolType, number>>;
|
|
147
|
+
/** Audio encoding of spoken output */
|
|
148
|
+
audioFormat?: AudioFormat;
|
|
149
|
+
constructor(idPrefix?: string);
|
|
150
|
+
/** An id for a call that came without one */
|
|
151
|
+
nextCallId(): string;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* The audio encoding of an audio MIME type the API returned.
|
|
155
|
+
*/
|
|
156
|
+
export declare function audioFormatOf(mimeType: string | undefined): AudioFormat | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* What one response (or stream chunk) contributes, as chunks: text,
|
|
159
|
+
* thought summaries, thought signatures, tool calls (named, argued and
|
|
160
|
+
* finished at once: Gemini sends each call whole), images, audio, and the
|
|
161
|
+
* server-side tool parts kept for replay. Usage, citations and the finish
|
|
162
|
+
* reason come from `endChunk` once the response is complete.
|
|
163
|
+
*/
|
|
164
|
+
export declare function responseChunks(response: GenerateContentResponse, state: ResponseState): Chunk[];
|
|
165
|
+
/**
|
|
166
|
+
* What a finished response contributes beyond its parts: why it stopped
|
|
167
|
+
* (or that the prompt was blocked), usage, citations, hosted tool use and
|
|
168
|
+
* the tier it ran on.
|
|
169
|
+
*/
|
|
170
|
+
export declare function endChunk(state: ResponseState, parts?: Part[]): Chunk;
|
|
171
|
+
/**
|
|
172
|
+
* Every part of a response's first candidate, for counting hosted tool runs
|
|
173
|
+
* at the end of a stream.
|
|
174
|
+
*/
|
|
175
|
+
export declare function candidateParts(response: GenerateContentResponse | undefined): Part[];
|
|
176
|
+
/**
|
|
177
|
+
* Gemini's thought signatures and server-side tool parts from an earlier
|
|
178
|
+
* turn, ready to put back into its parts: signatures by function call id,
|
|
179
|
+
* the last text signature, and the server parts in order. Reasoning from
|
|
180
|
+
* another provider has none.
|
|
181
|
+
*/
|
|
182
|
+
export interface ReplayedReasoning {
|
|
183
|
+
calls: Map<string, string>;
|
|
184
|
+
text?: string;
|
|
185
|
+
serverParts: Part[];
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The parts of an earlier turn's reasoning that go back to Gemini.
|
|
189
|
+
*/
|
|
190
|
+
export declare function replayReasoning(details: ReasoningDetail[] | undefined): ReplayedReasoning;
|
|
191
|
+
//# sourceMappingURL=convert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convert.d.ts","sourceRoot":"","sources":["../src/convert.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,MAAM,EAEX,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,WAAW,EAEhB,KAAK,KAAK,EACX,MAAM,YAAY,C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