agentfootprint 9.12.0 → 9.14.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/AGENTS.md +3 -2
- package/dist/adapters/llm/GeminiProvider.js +519 -0
- package/dist/adapters/llm/GeminiProvider.js.map +1 -0
- package/dist/adapters/llm/contextWindow.js +20 -0
- package/dist/adapters/llm/contextWindow.js.map +1 -1
- package/dist/adapters/llm/createProvider.js +3 -0
- package/dist/adapters/llm/createProvider.js.map +1 -1
- package/dist/adapters/llm/googleGenAI.js +109 -0
- package/dist/adapters/llm/googleGenAI.js.map +1 -0
- package/dist/core/agent/AgentBuilder.js +14 -5
- package/dist/core/agent/AgentBuilder.js.map +1 -1
- package/dist/embedders/index.js +233 -1
- package/dist/embedders/index.js.map +1 -1
- package/dist/esm/adapters/llm/GeminiProvider.d.ts +204 -0
- package/dist/esm/adapters/llm/GeminiProvider.js +514 -0
- package/dist/esm/adapters/llm/GeminiProvider.js.map +1 -0
- package/dist/esm/adapters/llm/contextWindow.js +20 -0
- package/dist/esm/adapters/llm/contextWindow.js.map +1 -1
- package/dist/esm/adapters/llm/createProvider.d.ts +4 -1
- package/dist/esm/adapters/llm/createProvider.js +3 -0
- package/dist/esm/adapters/llm/createProvider.js.map +1 -1
- package/dist/esm/adapters/llm/googleGenAI.d.ts +67 -0
- package/dist/esm/adapters/llm/googleGenAI.js +105 -0
- package/dist/esm/adapters/llm/googleGenAI.js.map +1 -0
- package/dist/esm/core/agent/AgentBuilder.d.ts +5 -2
- package/dist/esm/core/agent/AgentBuilder.js +14 -5
- package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
- package/dist/esm/embedders/index.d.ts +188 -1
- package/dist/esm/embedders/index.js +231 -0
- package/dist/esm/embedders/index.js.map +1 -1
- package/dist/esm/memory/define.d.ts +1 -1
- package/dist/esm/memory/define.js +113 -14
- package/dist/esm/memory/define.js.map +1 -1
- package/dist/esm/memory/define.types.d.ts +69 -4
- package/dist/esm/memory/define.types.js.map +1 -1
- package/dist/esm/memory/pipeline/default.d.ts +22 -0
- package/dist/esm/memory/pipeline/default.js +19 -3
- package/dist/esm/memory/pipeline/default.js.map +1 -1
- package/dist/esm/memory/stages/summarize.d.ts +193 -54
- package/dist/esm/memory/stages/summarize.js +370 -34
- package/dist/esm/memory/stages/summarize.js.map +1 -1
- package/dist/esm/memory/strategies.d.ts +7 -1
- package/dist/esm/memory/strategies.js +25 -11
- package/dist/esm/memory/strategies.js.map +1 -1
- package/dist/esm/providers.d.ts +3 -0
- package/dist/esm/providers.js +2 -0
- package/dist/esm/providers.js.map +1 -1
- package/dist/memory/define.js +113 -14
- package/dist/memory/define.js.map +1 -1
- package/dist/memory/define.types.js.map +1 -1
- package/dist/memory/pipeline/default.js +19 -3
- package/dist/memory/pipeline/default.js.map +1 -1
- package/dist/memory/stages/summarize.js +374 -35
- package/dist/memory/stages/summarize.js.map +1 -1
- package/dist/memory/strategies.js +25 -11
- package/dist/memory/strategies.js.map +1 -1
- package/dist/providers.js +5 -1
- package/dist/providers.js.map +1 -1
- package/dist/types/adapters/llm/GeminiProvider.d.ts +205 -0
- package/dist/types/adapters/llm/GeminiProvider.d.ts.map +1 -0
- package/dist/types/adapters/llm/contextWindow.d.ts.map +1 -1
- package/dist/types/adapters/llm/createProvider.d.ts +4 -1
- package/dist/types/adapters/llm/createProvider.d.ts.map +1 -1
- package/dist/types/adapters/llm/googleGenAI.d.ts +68 -0
- package/dist/types/adapters/llm/googleGenAI.d.ts.map +1 -0
- package/dist/types/core/agent/AgentBuilder.d.ts +5 -2
- package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
- package/dist/types/embedders/index.d.ts +188 -1
- package/dist/types/embedders/index.d.ts.map +1 -1
- package/dist/types/memory/define.d.ts +1 -1
- package/dist/types/memory/define.d.ts.map +1 -1
- package/dist/types/memory/define.types.d.ts +69 -4
- package/dist/types/memory/define.types.d.ts.map +1 -1
- package/dist/types/memory/pipeline/default.d.ts +22 -0
- package/dist/types/memory/pipeline/default.d.ts.map +1 -1
- package/dist/types/memory/stages/summarize.d.ts +193 -54
- package/dist/types/memory/stages/summarize.d.ts.map +1 -1
- package/dist/types/memory/strategies.d.ts +7 -1
- package/dist/types/memory/strategies.d.ts.map +1 -1
- package/dist/types/providers.d.ts +3 -0
- package/dist/types/providers.d.ts.map +1 -1
- package/package.json +7 -1
package/AGENTS.md
CHANGED
|
@@ -356,7 +356,7 @@ The 4 memory **types**:
|
|
|
356
356
|
- `CAUSAL` — footprintjs decision-evidence snapshots ⭐
|
|
357
357
|
|
|
358
358
|
The 7 **strategies**:
|
|
359
|
-
- `WINDOW` (rule, last N) · `BUDGET` (decider, fit-to-tokens) · `SUMMARIZE` (LLM
|
|
359
|
+
- `WINDOW` (rule, last N) · `BUDGET` (decider, fit-to-tokens) · `SUMMARIZE` (one LLM call folds the older entries; the summary is stored, so a span is paid for once — needs `llm` + `model`)
|
|
360
360
|
- `TOP_K` (score-threshold) · `EXTRACT` (LLM distills on write)
|
|
361
361
|
- `DECAY` (recency-weighted, planned) · `HYBRID` (compose multiple)
|
|
362
362
|
|
|
@@ -546,7 +546,8 @@ One builder call mounts ONE skill that, when the user asks a why-question, unloc
|
|
|
546
546
|
| Semantic recall via embeddings | `defineMemory({ type: SEMANTIC, strategy: TOP_K })` |
|
|
547
547
|
| Cross-run "why?" replay | `defineMemory({ type: CAUSAL, strategy: TOP_K })` ⭐ |
|
|
548
548
|
| Old memories should stop coming back | `defineMemory({ type: EPISODIC, strategy: DECAY, halfLifeMs })` |
|
|
549
|
-
| Long conversation overflows
|
|
549
|
+
| Long conversation overflows the live window | `.compaction({ summarizer, model })` on the Agent |
|
|
550
|
+
| Stored recall outgrew its window | `defineMemory({ type: EPISODIC, strategy: { kind: SUMMARIZE, recent, size, llm, model } })` — folds the older entries into one stored summary; originals kept |
|
|
550
551
|
| Retrieve from a document corpus | `defineRAG({ store, embedder, topK, threshold })` |
|
|
551
552
|
| Use tools from an external MCP server | `mcpClient({ transport, ... })` + `agent.tools(await c.tools())` |
|
|
552
553
|
|
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* GeminiProvider — wraps `@google/genai` as an `LLMProvider` (9.13.0).
|
|
4
|
+
*
|
|
5
|
+
* Pattern: Adapter (GoF) + Ports-and-Adapters (Cockburn 2005).
|
|
6
|
+
* Role: Outer ring — translates `LLMRequest`/`LLMResponse` to/from Google's
|
|
7
|
+
* `generateContent` API. Knows nothing about agents, recorders, or
|
|
8
|
+
* compositions.
|
|
9
|
+
* Emits: N/A — providers don't emit; recorders observe via Agent.
|
|
10
|
+
*
|
|
11
|
+
* ─── Two doors, one adapter ─────────────────────────────────────────
|
|
12
|
+
*
|
|
13
|
+
* The same SDK reaches two different services, and which one you get is a
|
|
14
|
+
* property of the OPTIONS, not of a separate factory:
|
|
15
|
+
*
|
|
16
|
+
* • **Vertex** — `gemini({ project, location })` builds
|
|
17
|
+
* `new GoogleGenAI({ vertexai: true, project, location, googleAuthOptions })`.
|
|
18
|
+
* Auth is Application Default Credentials (env key file, gcloud user
|
|
19
|
+
* credentials, or the metadata server on GCE / Cloud Run / Agent Runtime).
|
|
20
|
+
* No API key exists on this path.
|
|
21
|
+
* • **Gemini API (AI Studio)** — `gemini({ apiKey })` builds
|
|
22
|
+
* `new GoogleGenAI({ apiKey })`. One key, no cloud project.
|
|
23
|
+
*
|
|
24
|
+
* Neither is guessed. The factory refuses at construction when it can resolve
|
|
25
|
+
* neither a project nor a key, naming both doors — because the SDK's own
|
|
26
|
+
* behaviour in that case is to WARN on stderr, construct anyway, and fail on
|
|
27
|
+
* the first call, which reads like a network problem rather than a missing
|
|
28
|
+
* setting.
|
|
29
|
+
*
|
|
30
|
+
* ─── Why native, and not `openai({ baseURL })` ──────────────────────
|
|
31
|
+
*
|
|
32
|
+
* Google publishes an OpenAI-compatible endpoint, and it does work — for about
|
|
33
|
+
* an hour. It authenticates with an OAuth access token that expires and has no
|
|
34
|
+
* refresh home in `OpenAIProviderOptions`; its `tools.function.parameters` is
|
|
35
|
+
* **OpenAPI**, not JSON Schema, so `$ref` / `oneOf` / `additionalProperties`
|
|
36
|
+
* diverge silently; unsupported parameters are ignored rather than refused; and
|
|
37
|
+
* its documented response carries no cached- or reasoning-token counts. This
|
|
38
|
+
* adapter exists because every one of those is answerable on the native SDK:
|
|
39
|
+
* ADC refreshes itself, tools go over as JSON Schema untranslated
|
|
40
|
+
* (`parametersJsonSchema`), a forced single tool is expressible, and
|
|
41
|
+
* `usageMetadata` reports cached and thinking tokens as separate numbers.
|
|
42
|
+
*
|
|
43
|
+
* ─── Limitations (stated, not discovered) ───────────────────────────
|
|
44
|
+
*
|
|
45
|
+
* • Multi-modal input/output NOT supported — `LLMMessage.content` is `string`,
|
|
46
|
+
* so this adapter sends and reads text parts only. Inline data, files and
|
|
47
|
+
* generated images are out of scope for the port as it stands.
|
|
48
|
+
* • **Thought summaries are not requested.** `usage.thinking` is reported
|
|
49
|
+
* honestly from `thoughtsTokenCount`, and `req.thinking.budget` is threaded
|
|
50
|
+
* to `thinkingConfig.thinkingBudget` — but `includeThoughts` is deliberately
|
|
51
|
+
* left unset, so no `rawThinking` is produced. Gemini's thought parts carry a
|
|
52
|
+
* `thoughtSignature` that has to be echoed byte-exact on the next turn, and
|
|
53
|
+
* there is no Gemini `ThinkingHandler` in this release to normalize and
|
|
54
|
+
* round-trip them. Asking for content nothing can carry would be a leak, not
|
|
55
|
+
* a feature. `thinkingConfig.thinkingLevel` has no field on `LLMRequest` and
|
|
56
|
+
* is likewise not sent.
|
|
57
|
+
* • `responseJsonSchema` (native structured output) is NOT exposed; use
|
|
58
|
+
* `.outputSchema(...)`, which goes over as a forced tool — a shape this
|
|
59
|
+
* adapter DOES carry.
|
|
60
|
+
* • Grounding tools (Google Search, code execution, URL context, MCP servers)
|
|
61
|
+
* are not exposed. `tools` carries function declarations only.
|
|
62
|
+
*/
|
|
63
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
+
exports.GeminiProvider = exports.gemini = void 0;
|
|
65
|
+
const contextWindow_js_1 = require("./contextWindow.js");
|
|
66
|
+
const googleGenAI_js_1 = require("./googleGenAI.js");
|
|
67
|
+
/**
|
|
68
|
+
* Which roles this wire carries inside `contents`.
|
|
69
|
+
*
|
|
70
|
+
* `'system'` is ABSENT, and it is the wire's own rule: Gemini takes the system
|
|
71
|
+
* prompt as `config.systemInstruction`, a field OUTSIDE the turn list, exactly
|
|
72
|
+
* like Anthropic's top-level `system`. So this is an Anthropic-family wire, not
|
|
73
|
+
* an OpenAI-family one, and a `slot: 'messages'` injection with
|
|
74
|
+
* `role: 'system'` is refused at run start rather than silently dropped between
|
|
75
|
+
* the recording and the request.
|
|
76
|
+
*/
|
|
77
|
+
const CARRIES_IN_MESSAGES = Object.freeze(['user', 'assistant']);
|
|
78
|
+
/** The model asked for when the request says only `'gemini'`. */
|
|
79
|
+
const DEFAULT_MODEL = 'gemini-2.5-flash';
|
|
80
|
+
/**
|
|
81
|
+
* Prefix on a tool-call id THIS ADAPTER invented.
|
|
82
|
+
*
|
|
83
|
+
* `FunctionCall.id` is optional on Gemini's wire and is routinely absent —
|
|
84
|
+
* Vertex omits it. Our `LLMResponse.toolCalls[].id` is not optional, because
|
|
85
|
+
* the agent matches a tool RESULT back to its call by id, so one has to exist.
|
|
86
|
+
* Inventing it is safe; sending it BACK is not — Gemini never issued it, and a
|
|
87
|
+
* `functionResponse.id` the service does not recognise is a request field that
|
|
88
|
+
* means nothing to the model. The prefix is how the return trip tells the two
|
|
89
|
+
* apart without holding state across provider instances (a resumed run rebuilds
|
|
90
|
+
* its history from a checkpoint, so state would not survive anyway).
|
|
91
|
+
*/
|
|
92
|
+
const SYNTHETIC_ID_PREFIX = 'gemini-call-';
|
|
93
|
+
/**
|
|
94
|
+
* Build an `LLMProvider` backed by Gemini — on Vertex or on the Gemini API.
|
|
95
|
+
*
|
|
96
|
+
* @example Vertex (Application Default Credentials)
|
|
97
|
+
* ```ts
|
|
98
|
+
* import { Agent } from 'agentfootprint';
|
|
99
|
+
* import { gemini } from 'agentfootprint/providers';
|
|
100
|
+
*
|
|
101
|
+
* const agent = Agent.create({
|
|
102
|
+
* provider: gemini({ project: 'my-project', location: 'us-central1' }),
|
|
103
|
+
* model: 'gemini',
|
|
104
|
+
* })
|
|
105
|
+
* .tool(weatherTool)
|
|
106
|
+
* .build();
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @example Gemini API (one key, no cloud project)
|
|
110
|
+
* ```ts
|
|
111
|
+
* const provider = gemini({ apiKey: process.env.GEMINI_API_KEY });
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @throws at construction when neither a project nor an API key is resolvable,
|
|
115
|
+
* and when `@google/genai` is not installed.
|
|
116
|
+
*/
|
|
117
|
+
function gemini(options = {}) {
|
|
118
|
+
const client = (0, googleGenAI_js_1.resolveGoogleGenAIClient)(options, 'gemini', options._client);
|
|
119
|
+
const defaultModel = options.defaultModel ?? DEFAULT_MODEL;
|
|
120
|
+
const defaultMaxTokens = options.defaultMaxTokens;
|
|
121
|
+
// Ids are invented per PROVIDER INSTANCE, in call order — the same shape
|
|
122
|
+
// `ollama()` uses, and for the same reason: the wire omits them.
|
|
123
|
+
let toolCallSeq = 0;
|
|
124
|
+
const nextToolCallId = () => `${SYNTHETIC_ID_PREFIX}${++toolCallSeq}`;
|
|
125
|
+
// The ONE secret this adapter holds, so the ONE string its errors promise
|
|
126
|
+
// never to print — see `wrapError`.
|
|
127
|
+
const wrap = (err) => wrapError(err, options.apiKey);
|
|
128
|
+
const provider = {
|
|
129
|
+
name: 'gemini',
|
|
130
|
+
carriesInMessages: CARRIES_IN_MESSAGES,
|
|
131
|
+
// Earned, not assumed: `toolConfig.functionCallingConfig` with
|
|
132
|
+
// `mode: 'ANY'` and a single `allowedFunctionNames` entry constrains the
|
|
133
|
+
// model to answer through exactly that function. Both doors of this
|
|
134
|
+
// adapter speak the same field, so unlike the OpenAI-compatible path there
|
|
135
|
+
// is no endpoint whose behaviour we would be promising on its behalf.
|
|
136
|
+
carriesForcedToolChoice: true,
|
|
137
|
+
async complete(req) {
|
|
138
|
+
const params = buildParams(req, defaultModel, defaultMaxTokens);
|
|
139
|
+
try {
|
|
140
|
+
const response = await client.models.generateContent(params);
|
|
141
|
+
return fromGeminiResponse(response, nextToolCallId);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
throw wrap(err);
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
async *stream(req) {
|
|
148
|
+
const params = buildParams(req, defaultModel, defaultMaxTokens);
|
|
149
|
+
let stream;
|
|
150
|
+
try {
|
|
151
|
+
// Two awaits, one call: `generateContentStream` answers with a PROMISE
|
|
152
|
+
// of an async generator, so `for await` over the return value directly
|
|
153
|
+
// iterates a promise and yields nothing.
|
|
154
|
+
stream = await client.models.generateContentStream(params);
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
throw wrap(err);
|
|
158
|
+
}
|
|
159
|
+
const textParts = [];
|
|
160
|
+
const functionCalls = [];
|
|
161
|
+
let usage;
|
|
162
|
+
let finishReason;
|
|
163
|
+
let responseId;
|
|
164
|
+
let tokenIndex = 0;
|
|
165
|
+
try {
|
|
166
|
+
for await (const chunk of stream) {
|
|
167
|
+
// Usage FIRST, and outside any content guard. Gemini puts
|
|
168
|
+
// `usageMetadata` on the chunk that closes the stream, whose
|
|
169
|
+
// candidate carries no new text — a `continue` on an empty part list
|
|
170
|
+
// throws away the only token counts the stream ever reports, which is
|
|
171
|
+
// the failure that made streamed turns bill as zero on two other
|
|
172
|
+
// adapters before this one.
|
|
173
|
+
if (chunk.usageMetadata)
|
|
174
|
+
usage = chunk.usageMetadata;
|
|
175
|
+
if (chunk.responseId)
|
|
176
|
+
responseId = chunk.responseId;
|
|
177
|
+
const candidate = chunk.candidates?.[0];
|
|
178
|
+
if (candidate?.finishReason)
|
|
179
|
+
finishReason = candidate.finishReason;
|
|
180
|
+
for (const part of candidate?.content?.parts ?? []) {
|
|
181
|
+
if (part.functionCall)
|
|
182
|
+
functionCalls.push(part.functionCall);
|
|
183
|
+
// A thought-summary part is not visible content and is never
|
|
184
|
+
// streamed as one. Nothing asks for them today (see the file
|
|
185
|
+
// header); the guard is here so that a model that volunteers one
|
|
186
|
+
// cannot leak reasoning into the answer.
|
|
187
|
+
if (part.thought)
|
|
188
|
+
continue;
|
|
189
|
+
if (part.text) {
|
|
190
|
+
textParts.push(part.text);
|
|
191
|
+
yield { tokenIndex, content: part.text, done: false };
|
|
192
|
+
tokenIndex++;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const toolCalls = functionCalls.map((fc) => toLLMToolCall(fc, nextToolCallId));
|
|
197
|
+
const response = {
|
|
198
|
+
content: textParts.join(''),
|
|
199
|
+
toolCalls,
|
|
200
|
+
// What the wire said, and nothing else. When a stream reports no
|
|
201
|
+
// usage at all these are zero rather than an estimate: `countTokens`
|
|
202
|
+
// would answer a DIFFERENT question (what a request tokenises to)
|
|
203
|
+
// from the one a cost meter is asking (what this call was billed
|
|
204
|
+
// for), and a plausible number in the right range is worse than a
|
|
205
|
+
// zero somebody can see. Same law as `openai()` and `ollama()`.
|
|
206
|
+
usage: toUsage(usage),
|
|
207
|
+
stopReason: normalizeStopReason(finishReason, toolCalls.length > 0),
|
|
208
|
+
...(responseId !== undefined && { providerRef: responseId }),
|
|
209
|
+
};
|
|
210
|
+
yield { tokenIndex, content: '', done: true, response };
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
throw wrap(err);
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
};
|
|
217
|
+
return provider;
|
|
218
|
+
}
|
|
219
|
+
exports.gemini = gemini;
|
|
220
|
+
/**
|
|
221
|
+
* Class form for consumers who prefer `new GeminiProvider(...)` over the
|
|
222
|
+
* `gemini(...)` factory. Identical behavior; trivial wrapper.
|
|
223
|
+
*/
|
|
224
|
+
class GeminiProvider {
|
|
225
|
+
name = 'gemini';
|
|
226
|
+
carriesInMessages = CARRIES_IN_MESSAGES;
|
|
227
|
+
carriesForcedToolChoice = true;
|
|
228
|
+
inner;
|
|
229
|
+
constructor(options = {}) {
|
|
230
|
+
this.inner = gemini(options);
|
|
231
|
+
}
|
|
232
|
+
// `hooks` is FORWARDED, not dropped — see LLMCallHooks in adapters/types.ts.
|
|
233
|
+
complete(req, hooks) {
|
|
234
|
+
return this.inner.complete(req, hooks);
|
|
235
|
+
}
|
|
236
|
+
stream(req, hooks) {
|
|
237
|
+
if (!this.inner.stream) {
|
|
238
|
+
throw new Error('stream() unavailable on inner provider');
|
|
239
|
+
}
|
|
240
|
+
return this.inner.stream(req, hooks);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
exports.GeminiProvider = GeminiProvider;
|
|
244
|
+
// ─── Internals ──────────────────────────────────────────────────────
|
|
245
|
+
function buildParams(req, defaultModel, defaultMaxTokens) {
|
|
246
|
+
const config = {};
|
|
247
|
+
// The system prompt is a top-level field, not a turn — see
|
|
248
|
+
// CARRIES_IN_MESSAGES.
|
|
249
|
+
if (req.systemPrompt)
|
|
250
|
+
config.systemInstruction = req.systemPrompt;
|
|
251
|
+
if (req.temperature !== undefined)
|
|
252
|
+
config.temperature = req.temperature;
|
|
253
|
+
const maxTokens = req.maxTokens ?? defaultMaxTokens;
|
|
254
|
+
if (maxTokens !== undefined)
|
|
255
|
+
config.maxOutputTokens = maxTokens;
|
|
256
|
+
if (req.stop && req.stop.length > 0)
|
|
257
|
+
config.stopSequences = [...req.stop];
|
|
258
|
+
// Threaded so an aborted run stops paying for tokens nobody is waiting for.
|
|
259
|
+
if (req.signal)
|
|
260
|
+
config.abortSignal = req.signal;
|
|
261
|
+
if (req.tools && req.tools.length > 0) {
|
|
262
|
+
config.tools = [{ functionDeclarations: req.tools.map(toGeminiFunctionDeclaration) }];
|
|
263
|
+
}
|
|
264
|
+
// A budget, and only a budget — `includeThoughts` and `thinkingLevel` are
|
|
265
|
+
// deliberately not sent (see the file header). A budget of 0 is a real value
|
|
266
|
+
// on this wire (it turns thinking off), so the guard is on presence.
|
|
267
|
+
if (req.thinking)
|
|
268
|
+
config.thinkingConfig = { thinkingBudget: req.thinking.budget };
|
|
269
|
+
// Forced choice of ONE named function. Guarded on tools being present for
|
|
270
|
+
// the same reason the Anthropic and OpenAI adapters guard: a tool choice
|
|
271
|
+
// naming a function the request does not carry is a request that cannot be
|
|
272
|
+
// served, and Gemini would refuse it.
|
|
273
|
+
if (req.toolChoice && config.tools !== undefined) {
|
|
274
|
+
config.toolConfig = {
|
|
275
|
+
functionCallingConfig: { mode: 'ANY', allowedFunctionNames: [req.toolChoice.name] },
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
return {
|
|
279
|
+
model: req.model === 'gemini' ? defaultModel : req.model,
|
|
280
|
+
contents: toGeminiContents(req.messages),
|
|
281
|
+
...(Object.keys(config).length > 0 && { config }),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* messages → Gemini `contents`.
|
|
286
|
+
*
|
|
287
|
+
* Key transforms:
|
|
288
|
+
* • `role: 'system'` is DROPPED — it rides `config.systemInstruction`.
|
|
289
|
+
* • `role: 'assistant'` becomes `role: 'model'`, with `toolCalls` restored as
|
|
290
|
+
* `functionCall` parts so a multi-turn tool conversation round-trips.
|
|
291
|
+
* • `role: 'tool'` becomes a `functionResponse` part inside a **user** turn,
|
|
292
|
+
* which is where Gemini expects results. Consecutive tool messages merge
|
|
293
|
+
* into ONE user turn, so a reply that called three tools is answered by one
|
|
294
|
+
* turn carrying three responses — the same coalescing the Anthropic adapter
|
|
295
|
+
* does with `tool_result` blocks.
|
|
296
|
+
*/
|
|
297
|
+
function toGeminiContents(messages) {
|
|
298
|
+
const result = [];
|
|
299
|
+
for (const m of messages) {
|
|
300
|
+
if (m.role === 'system')
|
|
301
|
+
continue;
|
|
302
|
+
if (m.role === 'user') {
|
|
303
|
+
result.push({ role: 'user', parts: [{ text: m.content }] });
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
if (m.role === 'assistant') {
|
|
307
|
+
const parts = [];
|
|
308
|
+
if (m.content)
|
|
309
|
+
parts.push({ text: m.content });
|
|
310
|
+
for (const tc of m.toolCalls ?? []) {
|
|
311
|
+
parts.push({
|
|
312
|
+
functionCall: {
|
|
313
|
+
// Only an id GEMINI issued goes back to Gemini — see
|
|
314
|
+
// SYNTHETIC_ID_PREFIX.
|
|
315
|
+
...(isRealId(tc.id) && { id: tc.id }),
|
|
316
|
+
name: tc.name,
|
|
317
|
+
args: { ...tc.args },
|
|
318
|
+
},
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
// An assistant turn with neither text nor calls still has to occupy its
|
|
322
|
+
// position, or the user/model alternation the wire expects breaks.
|
|
323
|
+
result.push({ role: 'model', parts: parts.length > 0 ? parts : [{ text: '' }] });
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
if (m.role === 'tool') {
|
|
327
|
+
const part = {
|
|
328
|
+
functionResponse: {
|
|
329
|
+
...(isRealId(m.toolCallId) && { id: m.toolCallId }),
|
|
330
|
+
// Gemini matches a response to its call BY NAME, so the name is the
|
|
331
|
+
// load-bearing field here — not the id.
|
|
332
|
+
name: m.toolName ?? '',
|
|
333
|
+
// The wire takes an object, and a tool result in this library is a
|
|
334
|
+
// string. `{ output }` is that string in the one field the model can
|
|
335
|
+
// read, unwrapped; inventing a schema for it would make every tool
|
|
336
|
+
// result a different shape.
|
|
337
|
+
response: { output: m.content },
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
const last = result[result.length - 1];
|
|
341
|
+
if (last && last.role === 'user' && last.parts[0]?.functionResponse) {
|
|
342
|
+
last.parts.push(part);
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
result.push({ role: 'user', parts: [part] });
|
|
346
|
+
}
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
/** Did the SERVICE issue this id, or did we? */
|
|
353
|
+
function isRealId(id) {
|
|
354
|
+
return id !== undefined && id.length > 0 && !id.startsWith(SYNTHETIC_ID_PREFIX);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* `LLMToolSchema` → `FunctionDeclaration`, with the schema untranslated.
|
|
358
|
+
*
|
|
359
|
+
* `parametersJsonSchema` is the whole reason this adapter exists rather than a
|
|
360
|
+
* `baseURL` on the OpenAI one: it takes JSON Schema as JSON Schema. The
|
|
361
|
+
* `parameters` field beside it takes an OpenAPI subset, where `$ref`,
|
|
362
|
+
* `oneOf` and `additionalProperties` mean something else or nothing at all —
|
|
363
|
+
* which is a divergence you only find out about from a model that ignored half
|
|
364
|
+
* your constraints.
|
|
365
|
+
*/
|
|
366
|
+
function toGeminiFunctionDeclaration(schema) {
|
|
367
|
+
return {
|
|
368
|
+
name: schema.name,
|
|
369
|
+
description: schema.description,
|
|
370
|
+
parametersJsonSchema: { ...schema.inputSchema },
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
function fromGeminiResponse(response, nextToolCallId) {
|
|
374
|
+
const candidate = response.candidates?.[0];
|
|
375
|
+
const textParts = [];
|
|
376
|
+
const toolCalls = [];
|
|
377
|
+
for (const part of candidate?.content?.parts ?? []) {
|
|
378
|
+
if (part.functionCall)
|
|
379
|
+
toolCalls.push(toLLMToolCall(part.functionCall, nextToolCallId));
|
|
380
|
+
// Thought summaries are not the answer. See the header.
|
|
381
|
+
if (part.thought)
|
|
382
|
+
continue;
|
|
383
|
+
if (part.text)
|
|
384
|
+
textParts.push(part.text);
|
|
385
|
+
}
|
|
386
|
+
return {
|
|
387
|
+
content: textParts.join(''),
|
|
388
|
+
toolCalls,
|
|
389
|
+
usage: toUsage(response.usageMetadata),
|
|
390
|
+
stopReason: normalizeStopReason(candidate?.finishReason, toolCalls.length > 0),
|
|
391
|
+
...(response.responseId !== undefined && { providerRef: response.responseId }),
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
function toLLMToolCall(fc, nextToolCallId) {
|
|
395
|
+
return {
|
|
396
|
+
id: fc.id && fc.id.length > 0 ? fc.id : nextToolCallId(),
|
|
397
|
+
name: fc.name ?? '',
|
|
398
|
+
args: { ...(fc.args ?? {}) },
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* `usageMetadata` → the port's four numbers.
|
|
403
|
+
*
|
|
404
|
+
* This is the payoff of going native. `cachedContentTokenCount` and
|
|
405
|
+
* `thoughtsTokenCount` are separate line items on Google's own wire, so
|
|
406
|
+
* `usage.cacheRead` and `usage.thinking` are REPORTED rather than left
|
|
407
|
+
* undefined — the OpenAI-compatible endpoint's documented response has neither
|
|
408
|
+
* field, so a cost dashboard behind it can only ever show the total.
|
|
409
|
+
*
|
|
410
|
+
* `cacheWrite` stays undefined on purpose: Gemini's context caching is created
|
|
411
|
+
* by a separate `caches.create` call that this adapter does not make, so there
|
|
412
|
+
* is no write for a `generateContent` turn to report.
|
|
413
|
+
*/
|
|
414
|
+
function toUsage(usage) {
|
|
415
|
+
return {
|
|
416
|
+
input: usage?.promptTokenCount ?? 0,
|
|
417
|
+
output: usage?.candidatesTokenCount ?? 0,
|
|
418
|
+
...(usage?.cachedContentTokenCount !== undefined && {
|
|
419
|
+
cacheRead: usage.cachedContentTokenCount,
|
|
420
|
+
}),
|
|
421
|
+
...(usage?.thoughtsTokenCount !== undefined && { thinking: usage.thoughtsTokenCount }),
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* `FinishReason` → agentfootprint's stop vocabulary.
|
|
426
|
+
*
|
|
427
|
+
* Two facts shape this. First, **Gemini has no `tool_use` finish reason**: a
|
|
428
|
+
* turn that asks for a function still finishes `STOP`, so the presence of
|
|
429
|
+
* function calls is what distinguishes it — the same correction `ollama()`
|
|
430
|
+
* makes on its wire. Second, everything not listed passes through UNCHANGED,
|
|
431
|
+
* in Google's own spelling. `RECITATION`, `MALFORMED_FUNCTION_CALL`,
|
|
432
|
+
* `TOO_MANY_TOOL_CALLS` and the image-specific reasons are real answers with no
|
|
433
|
+
* equivalent in this vocabulary, and mapping them onto the nearest word would
|
|
434
|
+
* be this adapter guessing on the model's behalf.
|
|
435
|
+
*/
|
|
436
|
+
function normalizeStopReason(raw, hasToolCalls) {
|
|
437
|
+
if (hasToolCalls && (raw === undefined || raw === 'STOP' || raw === ''))
|
|
438
|
+
return 'tool_use';
|
|
439
|
+
switch (raw) {
|
|
440
|
+
case undefined:
|
|
441
|
+
case '':
|
|
442
|
+
return 'stop';
|
|
443
|
+
case 'STOP':
|
|
444
|
+
return 'stop';
|
|
445
|
+
case 'MAX_TOKENS':
|
|
446
|
+
return 'max_tokens';
|
|
447
|
+
// The four that are unmistakably a safety refusal rather than an ending.
|
|
448
|
+
case 'SAFETY':
|
|
449
|
+
case 'PROHIBITED_CONTENT':
|
|
450
|
+
case 'BLOCKLIST':
|
|
451
|
+
case 'SPII':
|
|
452
|
+
return 'content_filter';
|
|
453
|
+
default:
|
|
454
|
+
return raw;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* Vendor error → ours, with the key taken out.
|
|
459
|
+
*
|
|
460
|
+
* The prefix-and-rename half is the same as every other adapter's. The
|
|
461
|
+
* REDACTION half is this adapter's alone, and it is narrow on purpose: the only
|
|
462
|
+
* string removed is the literal API key this provider was constructed with, and
|
|
463
|
+
* it is removed because a thrown provider error is handed to the model as a
|
|
464
|
+
* tool result, written to the commit log, rendered in the narrative and
|
|
465
|
+
* serialized by every attached recorder — one interpolation reaches all of them.
|
|
466
|
+
*
|
|
467
|
+
* This is not a heuristic scrubber and must never become one. It cannot know
|
|
468
|
+
* about a secret it was not given, and a pattern that guessed at "things that
|
|
469
|
+
* look like keys" would eventually delete the sentence that explains the
|
|
470
|
+
* failure. What it guarantees is exactly what it can: the key YOU passed in
|
|
471
|
+
* does not come back out, whoever put it in the message.
|
|
472
|
+
*/
|
|
473
|
+
function wrapError(err, apiKey) {
|
|
474
|
+
// See OpenAIProvider.wrapError — one shared detector, one typed error, so
|
|
475
|
+
// "the request did not fit" reads the same whichever vendor said it. Google's
|
|
476
|
+
// sentence is "The input token count (N) exceeds the maximum number of tokens
|
|
477
|
+
// allowed (M)."; the phrase list in contextWindow.ts carries it.
|
|
478
|
+
const tooBig = (0, contextWindow_js_1.asContextWindowExceeded)(err, { provider: 'gemini' });
|
|
479
|
+
if (tooBig)
|
|
480
|
+
return redactKey(tooBig, apiKey);
|
|
481
|
+
if (err instanceof Error) {
|
|
482
|
+
return redactKey(Object.assign(new Error(`[gemini] ${redact(err.message, apiKey)}`), {
|
|
483
|
+
name: 'GeminiProviderError',
|
|
484
|
+
cause: err,
|
|
485
|
+
// `ApiError` from @google/genai carries `status`; withRetry reads it.
|
|
486
|
+
status: err.status,
|
|
487
|
+
}), apiKey);
|
|
488
|
+
}
|
|
489
|
+
return new Error(`[gemini] ${redact(String(err), apiKey)}`);
|
|
490
|
+
}
|
|
491
|
+
/** A key short enough to be an accident is not redacted — replacing a two-
|
|
492
|
+
* character string everywhere would shred the message it appears in. */
|
|
493
|
+
function redact(text, apiKey) {
|
|
494
|
+
if (apiKey === undefined || apiKey.length < 8)
|
|
495
|
+
return text;
|
|
496
|
+
return text.split(apiKey).join('[redacted apiKey]');
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* A `stack` is built from the message at construction, and a `cause` carries
|
|
500
|
+
* the vendor's untouched original — both are printed by ordinary logging, so
|
|
501
|
+
* neither may keep a copy of the key the message just gave up.
|
|
502
|
+
*/
|
|
503
|
+
function redactKey(error, apiKey) {
|
|
504
|
+
if (apiKey === undefined || apiKey.length < 8)
|
|
505
|
+
return error;
|
|
506
|
+
if (typeof error.stack === 'string' && error.stack.includes(apiKey)) {
|
|
507
|
+
error.stack = redact(error.stack, apiKey);
|
|
508
|
+
}
|
|
509
|
+
const cause = error.cause;
|
|
510
|
+
if (cause instanceof Error) {
|
|
511
|
+
if (cause.message.includes(apiKey))
|
|
512
|
+
cause.message = redact(cause.message, apiKey);
|
|
513
|
+
if (typeof cause.stack === 'string' && cause.stack.includes(apiKey)) {
|
|
514
|
+
cause.stack = redact(cause.stack, apiKey);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return error;
|
|
518
|
+
}
|
|
519
|
+
//# sourceMappingURL=GeminiProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeminiProvider.js","sourceRoot":"","sources":["../../../src/adapters/llm/GeminiProvider.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;;;AAYH,yDAA6D;AAC7D,qDAA+F;AAyH/F;;;;;;;;;GASG;AACH,MAAM,mBAAmB,GAAwB,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AAEtF,iEAAiE;AACjE,MAAM,aAAa,GAAG,kBAAkB,CAAC;AAEzC;;;;;;;;;;;GAWG;AACH,MAAM,mBAAmB,GAAG,cAAc,CAAC;AAE3C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,MAAM,CAAC,UAAiC,EAAE;IACxD,MAAM,MAAM,GAAG,IAAA,yCAAwB,EAAmB,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9F,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,aAAa,CAAC;IAC3D,MAAM,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAElD,yEAAyE;IACzE,iEAAiE;IACjE,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,MAAM,cAAc,GAAG,GAAW,EAAE,CAAC,GAAG,mBAAmB,GAAG,EAAE,WAAW,EAAE,CAAC;IAE9E,0EAA0E;IAC1E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S,MAAM,CAAC,IAAY,EAAE,MAA0B;IACtD,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3D,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;AACtD,CAAC;AAED;;;;GAIG;AACH,SAAS,SAAS,CAAkB,KAAQ,EAAE,MAA0B;IACtE,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5D,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACpE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,KAAK,GAAI,KAA6B,CAAC,KAAK,CAAC;IACnD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAClF,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACpE,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -108,6 +108,8 @@ exports.isContextWindowExceeded = isContextWindowExceeded;
|
|
|
108
108
|
* 195000 + 8192 > 200000
|
|
109
109
|
* bedrock Input is too long for requested model.
|
|
110
110
|
* bedrock (ValidationException carrying either anthropic phrase)
|
|
111
|
+
* gemini The input token count (1200293) exceeds the maximum number
|
|
112
|
+
* of tokens allowed (1048576).
|
|
111
113
|
*/
|
|
112
114
|
const CONTEXT_PHRASES = [
|
|
113
115
|
/context_length_exceeded/i,
|
|
@@ -121,6 +123,11 @@ const CONTEXT_PHRASES = [
|
|
|
121
123
|
// OUTPUT `max_tokens` cap, which has a different fix — and a pattern that
|
|
122
124
|
// cannot tell those apart sends callers to the wrong one.
|
|
123
125
|
/exceeds? the maximum (?:allowed )?(?:number of )?input tokens/i,
|
|
126
|
+
// gemini (9.13.0) — the same claim with the words in the other order, which
|
|
127
|
+
// is why the pattern above does not catch it. "INPUT token count" is what
|
|
128
|
+
// keeps it off a `max_tokens` validation error, and Google spells a rate
|
|
129
|
+
// limit "quota exceeded", so there is no overlap with throttling either.
|
|
130
|
+
/input token count[^.]{0,80}exceeds the maximum number of tokens allowed/i,
|
|
124
131
|
];
|
|
125
132
|
/** `"272,000"` → `272000`; anything unparseable → undefined. */
|
|
126
133
|
function num(raw) {
|
|
@@ -147,6 +154,19 @@ function readNumbers(text) {
|
|
|
147
154
|
...(num(sum[3]) !== undefined && { limitTokens: num(sum[3]) }),
|
|
148
155
|
};
|
|
149
156
|
}
|
|
157
|
+
// gemini: "The input token count (1200293) exceeds the maximum number of
|
|
158
|
+
// tokens allowed (1048576)." Both parentheses are matched loosely because
|
|
159
|
+
// Google sometimes ships the first one EMPTY — `num('')` is undefined, so a
|
|
160
|
+
// half-stated sentence yields the half it stated rather than nothing.
|
|
161
|
+
const geminiPair = /input token count\s*\(([\d,_]*)\)\s*exceeds the maximum number of tokens allowed\s*\(([\d,_]*)\)/i.exec(text);
|
|
162
|
+
if (geminiPair) {
|
|
163
|
+
const actual = num(geminiPair[1]);
|
|
164
|
+
const limit = num(geminiPair[2]);
|
|
165
|
+
return {
|
|
166
|
+
...(actual !== undefined && { actualTokens: actual }),
|
|
167
|
+
...(limit !== undefined && { limitTokens: limit }),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
150
170
|
const limit = num(/maximum context length is\s*([\d,_]+)/i.exec(text)?.[1]) ??
|
|
151
171
|
num(/configured limit of\s*([\d,_]+)/i.exec(text)?.[1]) ??
|
|
152
172
|
num(/limit of\s*([\d,_]+)\s*tokens/i.exec(text)?.[1]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextWindow.js","sourceRoot":"","sources":["../../../src/adapters/llm/contextWindow.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;;;AAEH,mEAAmE;AACtD,QAAA,2BAA2B,GAAG,6BAAsC,CAAC;AAElF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,0BAA2B,SAAQ,KAAK;IAC1C,IAAI,GAAG,mCAA2B,CAAC;IAE5C,wEAAwE;IAC/D,QAAQ,CAAS;IAE1B,6EAA6E;IACpE,WAAW,CAAU;IAE9B,4EAA4E;IACnE,YAAY,CAAU;IAE/B,+EAA+E;IACtE,MAAM,CAAU;IAEzB,2CAA2C;IACzB,KAAK,CAAS;IAEhC,YAAY,IAOX;QACC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1B,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,IAAI,CAAC,WAAW,KAAK,SAAS;YAAE,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACxE,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS;YAAE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;QAC3E,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QACzD,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,K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AAS,YAAY,CAAC,IAKrB;IACC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACvC,MAAM,IAAI,GACR,IAAI,IAAI,KAAK;QACX,CAAC,CAAC,MAAM,IAAI,4BAA4B,KAAK,EAAE;QAC/C,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,mBAAmB,KAAK,EAAE;YAC5B,CAAC,CAAC,IAAI;gBACN,CAAC,CAAC,0BAA0B,IAAI,EAAE;gBAClC,CAAC,CAAC,EAAE,CAAC;IAET,OAAO,CACL,IAAI,IAAI,CAAC,QAAQ,+CAA+C,IAAI,IAAI;QACxE,4EAA4E;QAC5E,4DAA4D;QAC5D,wEAAwE;QACxE,2EAA2E;QAC3E,8DAA8D;QAC9D,uEAAuE;QACvE,4EAA4E;QAC5E,kBAAkB;QAClB,yEAAyE;QACzE,0EAA0E;QAC1E,2EAA2E;QAC3E,8BAA8B;QAC9B,oBAAoB,IAAI,CAAC,eAAe,EAAE,CAC3C,CAAC;AACJ,CAAC"}
|
|
@@ -27,6 +27,7 @@ const AnthropicProvider_js_1 = require("./AnthropicProvider.js");
|
|
|
27
27
|
const OpenAIProvider_js_1 = require("./OpenAIProvider.js");
|
|
28
28
|
const OllamaProvider_js_1 = require("./OllamaProvider.js");
|
|
29
29
|
const BedrockProvider_js_1 = require("./BedrockProvider.js");
|
|
30
|
+
const GeminiProvider_js_1 = require("./GeminiProvider.js");
|
|
30
31
|
const BrowserAnthropicProvider_js_1 = require("./BrowserAnthropicProvider.js");
|
|
31
32
|
const BrowserOpenAIProvider_js_1 = require("./BrowserOpenAIProvider.js");
|
|
32
33
|
/**
|
|
@@ -44,6 +45,8 @@ function createProvider(options) {
|
|
|
44
45
|
return (0, OllamaProvider_js_1.ollama)(options);
|
|
45
46
|
case 'bedrock':
|
|
46
47
|
return (0, BedrockProvider_js_1.bedrock)(options);
|
|
48
|
+
case 'gemini':
|
|
49
|
+
return (0, GeminiProvider_js_1.gemini)(options);
|
|
47
50
|
case 'browser-anthropic':
|
|
48
51
|
return (0, BrowserAnthropicProvider_js_1.browserAnthropic)(options);
|
|
49
52
|
case 'browser-openai':
|