fourmis-agents-sdk 0.2.4 → 0.2.5
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/dist/agents/index.js +549 -0
- package/dist/agents/tools.js +549 -0
- package/dist/api.js +572 -23
- package/dist/auth/gemini-oauth.d.ts +23 -0
- package/dist/auth/gemini-oauth.d.ts.map +1 -0
- package/dist/auth/gemini-oauth.js +110 -0
- package/dist/index.js +572 -23
- package/dist/providers/anthropic.js +61 -0
- package/dist/providers/gemini.d.ts +39 -0
- package/dist/providers/gemini.d.ts.map +1 -0
- package/dist/providers/gemini.js +710 -0
- package/dist/providers/openai.js +61 -0
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +549 -0
- package/dist/utils/cost.d.ts +13 -0
- package/dist/utils/cost.d.ts.map +1 -1
- package/dist/utils/cost.js +66 -0
- package/package.json +2 -1
|
@@ -163,6 +163,67 @@ function findOpenAIPricing(model) {
|
|
|
163
163
|
}
|
|
164
164
|
return bestPricing;
|
|
165
165
|
}
|
|
166
|
+
var GEMINI_PRICING = {
|
|
167
|
+
"gemini-2.5-pro": {
|
|
168
|
+
inputPerMillion: 1.25,
|
|
169
|
+
outputPerMillion: 10,
|
|
170
|
+
cacheReadPerMillion: 0.315
|
|
171
|
+
},
|
|
172
|
+
"gemini-2.5-flash": {
|
|
173
|
+
inputPerMillion: 0.15,
|
|
174
|
+
outputPerMillion: 0.6,
|
|
175
|
+
cacheReadPerMillion: 0.0375
|
|
176
|
+
},
|
|
177
|
+
"gemini-2.5-flash-lite": {
|
|
178
|
+
inputPerMillion: 0.075,
|
|
179
|
+
outputPerMillion: 0.3
|
|
180
|
+
},
|
|
181
|
+
"gemini-2.0-flash": {
|
|
182
|
+
inputPerMillion: 0.1,
|
|
183
|
+
outputPerMillion: 0.4,
|
|
184
|
+
cacheReadPerMillion: 0.025
|
|
185
|
+
},
|
|
186
|
+
"gemini-2.0-flash-lite": {
|
|
187
|
+
inputPerMillion: 0.075,
|
|
188
|
+
outputPerMillion: 0.3
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var GEMINI_CONTEXT_WINDOWS = {
|
|
192
|
+
"gemini-2.5-pro": 1048576,
|
|
193
|
+
"gemini-2.5-flash": 1048576,
|
|
194
|
+
"gemini-2.5-flash-lite": 1048576,
|
|
195
|
+
"gemini-2.0-flash": 1048576,
|
|
196
|
+
"gemini-2.0-flash-lite": 1048576
|
|
197
|
+
};
|
|
198
|
+
var GEMINI_MAX_OUTPUT = {
|
|
199
|
+
"gemini-2.5-pro": 65536,
|
|
200
|
+
"gemini-2.5-flash": 65536,
|
|
201
|
+
"gemini-2.5-flash-lite": 65536,
|
|
202
|
+
"gemini-2.0-flash": 8192,
|
|
203
|
+
"gemini-2.0-flash-lite": 8192
|
|
204
|
+
};
|
|
205
|
+
function calculateGeminiCost(model, usage) {
|
|
206
|
+
const pricing = findGeminiPricing(model);
|
|
207
|
+
if (!pricing)
|
|
208
|
+
return 0;
|
|
209
|
+
const inputCost = usage.inputTokens / 1e6 * pricing.inputPerMillion;
|
|
210
|
+
const outputCost = usage.outputTokens / 1e6 * pricing.outputPerMillion;
|
|
211
|
+
const cacheReadCost = usage.cacheReadInputTokens / 1e6 * (pricing.cacheReadPerMillion ?? pricing.inputPerMillion);
|
|
212
|
+
return inputCost + outputCost + cacheReadCost;
|
|
213
|
+
}
|
|
214
|
+
function findGeminiPricing(model) {
|
|
215
|
+
if (GEMINI_PRICING[model])
|
|
216
|
+
return GEMINI_PRICING[model];
|
|
217
|
+
let bestKey = "";
|
|
218
|
+
let bestPricing;
|
|
219
|
+
for (const [key, pricing] of Object.entries(GEMINI_PRICING)) {
|
|
220
|
+
if (model.startsWith(key) && key.length > bestKey.length) {
|
|
221
|
+
bestKey = key;
|
|
222
|
+
bestPricing = pricing;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return bestPricing;
|
|
226
|
+
}
|
|
166
227
|
|
|
167
228
|
// src/providers/anthropic.ts
|
|
168
229
|
import Anthropic from "@anthropic-ai/sdk";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gemini provider adapter.
|
|
3
|
+
*
|
|
4
|
+
* Dual mode:
|
|
5
|
+
* 1. API key → @google/genai SDK (standard Gemini API)
|
|
6
|
+
* 2. OAuth → Direct HTTP to Code Assist endpoint (from `gemini login` CLI)
|
|
7
|
+
*
|
|
8
|
+
* Bridges the structural gap between Gemini's Content/Part format and the
|
|
9
|
+
* SDK's Anthropic-normalized format (tool_use/tool_result content blocks).
|
|
10
|
+
*/
|
|
11
|
+
import type { ProviderAdapter, ChatRequest, ChatChunk, ProviderFeature, NormalizedMessage } from "./types.js";
|
|
12
|
+
import type { TokenUsage } from "../types.js";
|
|
13
|
+
export declare class GeminiAdapter implements ProviderAdapter {
|
|
14
|
+
name: string;
|
|
15
|
+
private client;
|
|
16
|
+
private oauthMode;
|
|
17
|
+
private currentAccessToken?;
|
|
18
|
+
private projectId?;
|
|
19
|
+
constructor(options?: {
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
baseUrl?: string;
|
|
22
|
+
});
|
|
23
|
+
chat(request: ChatRequest): AsyncGenerator<ChatChunk>;
|
|
24
|
+
calculateCost(model: string, usage: TokenUsage): number;
|
|
25
|
+
getContextWindow(model: string): number;
|
|
26
|
+
supportsFeature(feature: ProviderFeature): boolean;
|
|
27
|
+
private chatSdk;
|
|
28
|
+
private chatCodeAssist;
|
|
29
|
+
private parseSSEStream;
|
|
30
|
+
private refreshTokenIfNeeded;
|
|
31
|
+
private ensureProjectId;
|
|
32
|
+
convertMessages(messages: NormalizedMessage[]): Array<{
|
|
33
|
+
role: string;
|
|
34
|
+
parts: any[];
|
|
35
|
+
}>;
|
|
36
|
+
private convertTools;
|
|
37
|
+
private mapFinishReason;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=gemini.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gemini.d.ts","sourceRoot":"","sources":["../../src/providers/gemini.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EACX,SAAS,EACT,eAAe,EAEf,iBAAiB,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAU9C,qBAAa,aAAc,YAAW,eAAe;IACnD,IAAI,SAAY;IAChB,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,kBAAkB,CAAC,CAAS;IACpC,OAAO,CAAC,SAAS,CAAC,CAAS;gBAEf,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAqBpD,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,cAAc,CAAC,SAAS,CAAC;IAQ5D,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM;IAIvD,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIvC,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO;YAgBnC,OAAO;YAqFP,cAAc;YA2Dd,cAAc;YAqGf,oBAAoB;YAepB,eAAe;IAyC7B,eAAe,CAAC,QAAQ,EAAE,iBAAiB,EAAE,GAAG,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,EAAE,CAAA;KAAE,CAAC;IAiErF,OAAO,CAAC,YAAY;IAcpB,OAAO,CAAC,eAAe;CAYxB"}
|