@yourgpt/llm-sdk 0.1.0 → 1.0.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.
Files changed (56) hide show
  1. package/README.md +61 -40
  2. package/dist/adapters/index.d.mts +4 -258
  3. package/dist/adapters/index.d.ts +4 -258
  4. package/dist/adapters/index.js +0 -113
  5. package/dist/adapters/index.js.map +1 -1
  6. package/dist/adapters/index.mjs +1 -112
  7. package/dist/adapters/index.mjs.map +1 -1
  8. package/dist/base-D_FyHFKj.d.mts +235 -0
  9. package/dist/base-D_FyHFKj.d.ts +235 -0
  10. package/dist/index.d.mts +209 -451
  11. package/dist/index.d.ts +209 -451
  12. package/dist/index.js +1905 -311
  13. package/dist/index.js.map +1 -1
  14. package/dist/index.mjs +1895 -309
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/providers/anthropic/index.d.mts +61 -0
  17. package/dist/providers/anthropic/index.d.ts +61 -0
  18. package/dist/providers/anthropic/index.js +939 -0
  19. package/dist/providers/anthropic/index.js.map +1 -0
  20. package/dist/providers/anthropic/index.mjs +934 -0
  21. package/dist/providers/anthropic/index.mjs.map +1 -0
  22. package/dist/providers/azure/index.d.mts +38 -0
  23. package/dist/providers/azure/index.d.ts +38 -0
  24. package/dist/providers/azure/index.js +380 -0
  25. package/dist/providers/azure/index.js.map +1 -0
  26. package/dist/providers/azure/index.mjs +377 -0
  27. package/dist/providers/azure/index.mjs.map +1 -0
  28. package/dist/providers/google/index.d.mts +72 -0
  29. package/dist/providers/google/index.d.ts +72 -0
  30. package/dist/providers/google/index.js +790 -0
  31. package/dist/providers/google/index.js.map +1 -0
  32. package/dist/providers/google/index.mjs +785 -0
  33. package/dist/providers/google/index.mjs.map +1 -0
  34. package/dist/providers/ollama/index.d.mts +24 -0
  35. package/dist/providers/ollama/index.d.ts +24 -0
  36. package/dist/providers/ollama/index.js +235 -0
  37. package/dist/providers/ollama/index.js.map +1 -0
  38. package/dist/providers/ollama/index.mjs +232 -0
  39. package/dist/providers/ollama/index.mjs.map +1 -0
  40. package/dist/providers/openai/index.d.mts +82 -0
  41. package/dist/providers/openai/index.d.ts +82 -0
  42. package/dist/providers/openai/index.js +679 -0
  43. package/dist/providers/openai/index.js.map +1 -0
  44. package/dist/providers/openai/index.mjs +674 -0
  45. package/dist/providers/openai/index.mjs.map +1 -0
  46. package/dist/providers/xai/index.d.mts +78 -0
  47. package/dist/providers/xai/index.d.ts +78 -0
  48. package/dist/providers/xai/index.js +671 -0
  49. package/dist/providers/xai/index.js.map +1 -0
  50. package/dist/providers/xai/index.mjs +666 -0
  51. package/dist/providers/xai/index.mjs.map +1 -0
  52. package/dist/types-BBCZ3Fxy.d.mts +308 -0
  53. package/dist/types-CdORv1Yu.d.mts +338 -0
  54. package/dist/types-CdORv1Yu.d.ts +338 -0
  55. package/dist/types-DcoCaVVC.d.ts +308 -0
  56. package/package.json +34 -3
@@ -0,0 +1,790 @@
1
+ 'use strict';
2
+
3
+ var core = require('@yourgpt/copilot-sdk/core');
4
+
5
+ // src/providers/google/provider.ts
6
+ var GOOGLE_MODELS = {
7
+ // Gemini 2.0
8
+ "gemini-2.0-flash": {
9
+ vision: true,
10
+ tools: true,
11
+ audio: true,
12
+ video: true,
13
+ maxTokens: 1048576
14
+ },
15
+ "gemini-2.0-flash-exp": {
16
+ vision: true,
17
+ tools: true,
18
+ audio: true,
19
+ video: true,
20
+ maxTokens: 1048576
21
+ },
22
+ "gemini-2.0-flash-thinking-exp": {
23
+ vision: true,
24
+ tools: false,
25
+ audio: false,
26
+ video: false,
27
+ maxTokens: 32767
28
+ },
29
+ // Gemini 1.5
30
+ "gemini-1.5-pro": {
31
+ vision: true,
32
+ tools: true,
33
+ audio: true,
34
+ video: true,
35
+ maxTokens: 2097152
36
+ },
37
+ "gemini-1.5-pro-latest": {
38
+ vision: true,
39
+ tools: true,
40
+ audio: true,
41
+ video: true,
42
+ maxTokens: 2097152
43
+ },
44
+ "gemini-1.5-flash": {
45
+ vision: true,
46
+ tools: true,
47
+ audio: true,
48
+ video: true,
49
+ maxTokens: 1048576
50
+ },
51
+ "gemini-1.5-flash-latest": {
52
+ vision: true,
53
+ tools: true,
54
+ audio: true,
55
+ video: true,
56
+ maxTokens: 1048576
57
+ },
58
+ "gemini-1.5-flash-8b": {
59
+ vision: true,
60
+ tools: true,
61
+ audio: false,
62
+ video: false,
63
+ maxTokens: 1048576
64
+ }
65
+ };
66
+ function google(modelId, options = {}) {
67
+ const apiKey = options.apiKey ?? process.env.GOOGLE_API_KEY ?? process.env.GEMINI_API_KEY;
68
+ let client = null;
69
+ async function getClient() {
70
+ if (!client) {
71
+ const { GoogleGenerativeAI } = await import('@google/generative-ai');
72
+ client = new GoogleGenerativeAI(apiKey);
73
+ }
74
+ return client;
75
+ }
76
+ const modelConfig = GOOGLE_MODELS[modelId] ?? GOOGLE_MODELS["gemini-2.0-flash"];
77
+ return {
78
+ provider: "google",
79
+ modelId,
80
+ capabilities: {
81
+ supportsVision: modelConfig.vision,
82
+ supportsTools: modelConfig.tools,
83
+ supportsStreaming: true,
84
+ supportsJsonMode: true,
85
+ supportsThinking: modelId.includes("thinking"),
86
+ supportsPDF: true,
87
+ maxTokens: modelConfig.maxTokens,
88
+ supportedImageTypes: modelConfig.vision ? ["image/png", "image/jpeg", "image/gif", "image/webp"] : []
89
+ },
90
+ async doGenerate(params) {
91
+ const client2 = await getClient();
92
+ const model = client2.getGenerativeModel({
93
+ model: modelId,
94
+ safetySettings: options.safetySettings
95
+ });
96
+ const { systemInstruction, contents } = formatMessagesForGemini(
97
+ params.messages
98
+ );
99
+ const chat = model.startChat({
100
+ history: contents.slice(0, -1),
101
+ systemInstruction: systemInstruction ? { parts: [{ text: systemInstruction }] } : void 0,
102
+ tools: params.tools ? [{ functionDeclarations: formatToolsForGemini(params.tools) }] : void 0,
103
+ generationConfig: {
104
+ temperature: params.temperature,
105
+ maxOutputTokens: params.maxTokens
106
+ }
107
+ });
108
+ const lastMessage = contents[contents.length - 1];
109
+ const result = await chat.sendMessage(lastMessage.parts);
110
+ const response = result.response;
111
+ let text = "";
112
+ const toolCalls = [];
113
+ let toolCallIndex = 0;
114
+ const candidate = response.candidates?.[0];
115
+ if (candidate?.content?.parts) {
116
+ for (const part of candidate.content.parts) {
117
+ if ("text" in part && part.text) {
118
+ text += part.text;
119
+ }
120
+ if ("functionCall" in part && part.functionCall) {
121
+ toolCalls.push({
122
+ id: `call_${toolCallIndex++}`,
123
+ name: part.functionCall.name,
124
+ args: part.functionCall.args || {}
125
+ });
126
+ }
127
+ }
128
+ }
129
+ return {
130
+ text,
131
+ toolCalls,
132
+ finishReason: mapFinishReason(candidate?.finishReason),
133
+ usage: {
134
+ promptTokens: response.usageMetadata?.promptTokenCount ?? 0,
135
+ completionTokens: response.usageMetadata?.candidatesTokenCount ?? 0,
136
+ totalTokens: response.usageMetadata?.totalTokenCount ?? 0
137
+ },
138
+ rawResponse: response
139
+ };
140
+ },
141
+ async *doStream(params) {
142
+ const client2 = await getClient();
143
+ const model = client2.getGenerativeModel({
144
+ model: modelId,
145
+ safetySettings: options.safetySettings
146
+ });
147
+ const { systemInstruction, contents } = formatMessagesForGemini(
148
+ params.messages
149
+ );
150
+ const chat = model.startChat({
151
+ history: contents.slice(0, -1),
152
+ systemInstruction: systemInstruction ? { parts: [{ text: systemInstruction }] } : void 0,
153
+ tools: params.tools ? [{ functionDeclarations: formatToolsForGemini(params.tools) }] : void 0,
154
+ generationConfig: {
155
+ temperature: params.temperature,
156
+ maxOutputTokens: params.maxTokens
157
+ }
158
+ });
159
+ const lastMessage = contents[contents.length - 1];
160
+ const result = await chat.sendMessageStream(lastMessage.parts);
161
+ let toolCallIndex = 0;
162
+ let promptTokens = 0;
163
+ let completionTokens = 0;
164
+ try {
165
+ for await (const chunk of result.stream) {
166
+ if (params.signal?.aborted) {
167
+ yield { type: "error", error: new Error("Aborted") };
168
+ return;
169
+ }
170
+ const candidate = chunk.candidates?.[0];
171
+ if (!candidate?.content?.parts) continue;
172
+ for (const part of candidate.content.parts) {
173
+ if ("text" in part && part.text) {
174
+ yield { type: "text-delta", text: part.text };
175
+ }
176
+ if ("functionCall" in part && part.functionCall) {
177
+ yield {
178
+ type: "tool-call",
179
+ toolCall: {
180
+ id: `call_${toolCallIndex++}`,
181
+ name: part.functionCall.name,
182
+ args: part.functionCall.args || {}
183
+ }
184
+ };
185
+ }
186
+ }
187
+ if (chunk.usageMetadata) {
188
+ promptTokens = chunk.usageMetadata.promptTokenCount ?? 0;
189
+ completionTokens = chunk.usageMetadata.candidatesTokenCount ?? 0;
190
+ }
191
+ if (candidate.finishReason) {
192
+ yield {
193
+ type: "finish",
194
+ finishReason: mapFinishReason(candidate.finishReason),
195
+ usage: {
196
+ promptTokens,
197
+ completionTokens,
198
+ totalTokens: promptTokens + completionTokens
199
+ }
200
+ };
201
+ }
202
+ }
203
+ } catch (error) {
204
+ yield {
205
+ type: "error",
206
+ error: error instanceof Error ? error : new Error(String(error))
207
+ };
208
+ }
209
+ }
210
+ };
211
+ }
212
+ function mapFinishReason(reason) {
213
+ switch (reason) {
214
+ case "STOP":
215
+ return "stop";
216
+ case "MAX_TOKENS":
217
+ return "length";
218
+ case "SAFETY":
219
+ return "content-filter";
220
+ default:
221
+ return "unknown";
222
+ }
223
+ }
224
+ function formatMessagesForGemini(messages) {
225
+ let systemInstruction = "";
226
+ const contents = [];
227
+ for (const msg of messages) {
228
+ if (msg.role === "system") {
229
+ systemInstruction += (systemInstruction ? "\n" : "") + msg.content;
230
+ continue;
231
+ }
232
+ const parts = [];
233
+ if (msg.role === "user") {
234
+ if (typeof msg.content === "string") {
235
+ parts.push({ text: msg.content });
236
+ } else {
237
+ for (const part of msg.content) {
238
+ if (part.type === "text") {
239
+ parts.push({ text: part.text });
240
+ } else if (part.type === "image") {
241
+ const imageData = typeof part.image === "string" ? part.image : Buffer.from(part.image).toString("base64");
242
+ const base64 = imageData.startsWith("data:") ? imageData.split(",")[1] : imageData;
243
+ parts.push({
244
+ inlineData: {
245
+ mimeType: part.mimeType ?? "image/png",
246
+ data: base64
247
+ }
248
+ });
249
+ }
250
+ }
251
+ }
252
+ contents.push({ role: "user", parts });
253
+ } else if (msg.role === "assistant") {
254
+ if (msg.content) {
255
+ parts.push({ text: msg.content });
256
+ }
257
+ if (msg.toolCalls?.length) {
258
+ for (const tc of msg.toolCalls) {
259
+ parts.push({
260
+ functionCall: {
261
+ name: tc.name,
262
+ args: tc.args
263
+ }
264
+ });
265
+ }
266
+ }
267
+ if (parts.length > 0) {
268
+ contents.push({ role: "model", parts });
269
+ }
270
+ } else if (msg.role === "tool") {
271
+ contents.push({
272
+ role: "user",
273
+ parts: [
274
+ {
275
+ functionResponse: {
276
+ name: "tool",
277
+ // Gemini doesn't track by ID
278
+ response: JSON.parse(msg.content || "{}")
279
+ }
280
+ }
281
+ ]
282
+ });
283
+ }
284
+ }
285
+ if (contents.length === 0 || contents[0].role !== "user") {
286
+ contents.unshift({ role: "user", parts: [{ text: "" }] });
287
+ }
288
+ const merged = [];
289
+ for (const content of contents) {
290
+ const last = merged[merged.length - 1];
291
+ if (last && last.role === content.role) {
292
+ last.parts.push(...content.parts);
293
+ } else {
294
+ merged.push({ ...content, parts: [...content.parts] });
295
+ }
296
+ }
297
+ return { systemInstruction, contents: merged };
298
+ }
299
+ function formatToolsForGemini(tools) {
300
+ return tools.map((t) => ({
301
+ name: t.function.name,
302
+ description: t.function.description,
303
+ parameters: t.function.parameters
304
+ }));
305
+ }
306
+ function attachmentToGeminiPart(attachment) {
307
+ if (!attachment.data) {
308
+ console.warn(
309
+ "Gemini adapter: URL-based attachments not supported, skipping"
310
+ );
311
+ return null;
312
+ }
313
+ if (attachment.type === "image") {
314
+ let base64Data = attachment.data;
315
+ if (base64Data.startsWith("data:")) {
316
+ const commaIndex = base64Data.indexOf(",");
317
+ if (commaIndex !== -1) {
318
+ base64Data = base64Data.slice(commaIndex + 1);
319
+ }
320
+ }
321
+ return {
322
+ inlineData: {
323
+ mimeType: attachment.mimeType || "image/png",
324
+ data: base64Data
325
+ }
326
+ };
327
+ }
328
+ if (attachment.type === "audio" || attachment.type === "video") {
329
+ let base64Data = attachment.data;
330
+ if (base64Data.startsWith("data:")) {
331
+ const commaIndex = base64Data.indexOf(",");
332
+ if (commaIndex !== -1) {
333
+ base64Data = base64Data.slice(commaIndex + 1);
334
+ }
335
+ }
336
+ return {
337
+ inlineData: {
338
+ mimeType: attachment.mimeType || (attachment.type === "audio" ? "audio/mp3" : "video/mp4"),
339
+ data: base64Data
340
+ }
341
+ };
342
+ }
343
+ return null;
344
+ }
345
+ function messageToGeminiContent(msg) {
346
+ if (msg.role === "system") return null;
347
+ const parts = [];
348
+ if (msg.role === "tool" && msg.tool_call_id) {
349
+ let responseData;
350
+ try {
351
+ responseData = JSON.parse(msg.content || "{}");
352
+ } catch {
353
+ responseData = { result: msg.content || "" };
354
+ }
355
+ const toolName = msg.metadata?.toolName || "tool";
356
+ parts.push({
357
+ functionResponse: {
358
+ name: toolName,
359
+ response: responseData
360
+ }
361
+ });
362
+ return { role: "user", parts };
363
+ }
364
+ if (msg.content) {
365
+ parts.push({ text: msg.content });
366
+ }
367
+ const attachments = msg.metadata?.attachments;
368
+ if (attachments && Array.isArray(attachments)) {
369
+ for (const attachment of attachments) {
370
+ const part = attachmentToGeminiPart(attachment);
371
+ if (part) {
372
+ parts.push(part);
373
+ }
374
+ }
375
+ }
376
+ if (msg.role === "assistant" && msg.tool_calls && msg.tool_calls.length > 0) {
377
+ for (const tc of msg.tool_calls) {
378
+ let args = {};
379
+ try {
380
+ args = JSON.parse(tc.function.arguments);
381
+ } catch {
382
+ }
383
+ parts.push({
384
+ functionCall: {
385
+ name: tc.function.name,
386
+ args
387
+ }
388
+ });
389
+ }
390
+ }
391
+ if (parts.length === 0) return null;
392
+ return {
393
+ role: msg.role === "assistant" ? "model" : "user",
394
+ parts
395
+ };
396
+ }
397
+ function formatToolsForGemini2(actions) {
398
+ if (!actions || actions.length === 0) return void 0;
399
+ return {
400
+ functionDeclarations: actions.map((action) => ({
401
+ name: action.name,
402
+ description: action.description,
403
+ parameters: action.parameters ? {
404
+ type: "object",
405
+ properties: Object.fromEntries(
406
+ Object.entries(action.parameters).map(([key, param]) => [
407
+ key,
408
+ {
409
+ type: param.type,
410
+ description: param.description,
411
+ enum: param.enum
412
+ }
413
+ ])
414
+ ),
415
+ required: Object.entries(action.parameters).filter(([, param]) => param.required).map(([key]) => key)
416
+ } : void 0
417
+ }))
418
+ };
419
+ }
420
+ var GoogleAdapter = class {
421
+ constructor(config) {
422
+ this.provider = "google";
423
+ this.config = config;
424
+ this.model = config.model || "gemini-2.0-flash";
425
+ }
426
+ async getClient() {
427
+ if (!this.client) {
428
+ const { GoogleGenerativeAI } = await import('@google/generative-ai');
429
+ this.client = new GoogleGenerativeAI(this.config.apiKey);
430
+ }
431
+ return this.client;
432
+ }
433
+ async *stream(request) {
434
+ const client = await this.getClient();
435
+ const modelId = request.config?.model || this.model;
436
+ const model = client.getGenerativeModel({
437
+ model: modelId,
438
+ safetySettings: this.config.safetySettings
439
+ });
440
+ let contents = [];
441
+ let systemInstruction;
442
+ if (request.rawMessages && request.rawMessages.length > 0) {
443
+ for (const msg of request.rawMessages) {
444
+ if (msg.role === "system") {
445
+ systemInstruction = (systemInstruction || "") + (msg.content || "");
446
+ continue;
447
+ }
448
+ const content = messageToGeminiContent(msg);
449
+ if (content) {
450
+ contents.push(content);
451
+ }
452
+ }
453
+ if (request.systemPrompt && !systemInstruction) {
454
+ systemInstruction = request.systemPrompt;
455
+ }
456
+ } else {
457
+ for (const msg of request.messages) {
458
+ if (msg.role === "system") {
459
+ systemInstruction = (systemInstruction || "") + (msg.content || "");
460
+ continue;
461
+ }
462
+ const content = messageToGeminiContent(msg);
463
+ if (content) {
464
+ contents.push(content);
465
+ }
466
+ }
467
+ if (request.systemPrompt) {
468
+ systemInstruction = request.systemPrompt;
469
+ }
470
+ }
471
+ if (contents.length === 0 || contents[0].role !== "user") {
472
+ contents = [{ role: "user", parts: [{ text: "" }] }, ...contents];
473
+ }
474
+ const mergedContents = [];
475
+ for (const content of contents) {
476
+ const last = mergedContents[mergedContents.length - 1];
477
+ if (last && last.role === content.role) {
478
+ last.parts.push(...content.parts);
479
+ } else {
480
+ mergedContents.push({ ...content, parts: [...content.parts] });
481
+ }
482
+ }
483
+ const tools = formatToolsForGemini2(request.actions);
484
+ const messageId = core.generateMessageId();
485
+ yield { type: "message:start", id: messageId };
486
+ try {
487
+ const chat = model.startChat({
488
+ history: mergedContents.slice(0, -1),
489
+ // All but the last message
490
+ systemInstruction: systemInstruction ? { parts: [{ text: systemInstruction }] } : void 0,
491
+ tools: tools ? [tools] : void 0,
492
+ generationConfig: {
493
+ temperature: request.config?.temperature ?? this.config.temperature,
494
+ maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
495
+ }
496
+ });
497
+ const lastMessage = mergedContents[mergedContents.length - 1];
498
+ const result = await chat.sendMessageStream(lastMessage.parts);
499
+ let currentToolCall = null;
500
+ for await (const chunk of result.stream) {
501
+ if (request.signal?.aborted) {
502
+ break;
503
+ }
504
+ const candidate = chunk.candidates?.[0];
505
+ if (!candidate?.content?.parts) continue;
506
+ for (const part of candidate.content.parts) {
507
+ if ("text" in part && part.text) {
508
+ yield { type: "message:delta", content: part.text };
509
+ }
510
+ if ("functionCall" in part && part.functionCall) {
511
+ const fc = part.functionCall;
512
+ const toolId = core.generateToolCallId();
513
+ if (currentToolCall) {
514
+ yield {
515
+ type: "action:args",
516
+ id: currentToolCall.id,
517
+ args: JSON.stringify(currentToolCall.args)
518
+ };
519
+ }
520
+ currentToolCall = {
521
+ id: toolId,
522
+ name: fc.name,
523
+ args: fc.args || {}
524
+ };
525
+ yield {
526
+ type: "action:start",
527
+ id: toolId,
528
+ name: fc.name
529
+ };
530
+ }
531
+ }
532
+ if (candidate.finishReason) {
533
+ if (currentToolCall) {
534
+ yield {
535
+ type: "action:args",
536
+ id: currentToolCall.id,
537
+ args: JSON.stringify(currentToolCall.args)
538
+ };
539
+ }
540
+ }
541
+ }
542
+ yield { type: "message:end" };
543
+ yield { type: "done" };
544
+ } catch (error) {
545
+ yield {
546
+ type: "error",
547
+ message: error instanceof Error ? error.message : "Unknown error",
548
+ code: "GOOGLE_ERROR"
549
+ };
550
+ }
551
+ }
552
+ /**
553
+ * Non-streaming completion (optional, for debugging)
554
+ */
555
+ async complete(request) {
556
+ const client = await this.getClient();
557
+ const modelId = request.config?.model || this.model;
558
+ const model = client.getGenerativeModel({
559
+ model: modelId,
560
+ safetySettings: this.config.safetySettings
561
+ });
562
+ let contents = [];
563
+ let systemInstruction;
564
+ for (const msg of request.messages) {
565
+ if (msg.role === "system") {
566
+ systemInstruction = (systemInstruction || "") + (msg.content || "");
567
+ continue;
568
+ }
569
+ const content = messageToGeminiContent(msg);
570
+ if (content) {
571
+ contents.push(content);
572
+ }
573
+ }
574
+ if (request.systemPrompt) {
575
+ systemInstruction = request.systemPrompt;
576
+ }
577
+ if (contents.length === 0 || contents[0].role !== "user") {
578
+ contents = [{ role: "user", parts: [{ text: "" }] }, ...contents];
579
+ }
580
+ const mergedContents = [];
581
+ for (const content of contents) {
582
+ const last = mergedContents[mergedContents.length - 1];
583
+ if (last && last.role === content.role) {
584
+ last.parts.push(...content.parts);
585
+ } else {
586
+ mergedContents.push({ ...content, parts: [...content.parts] });
587
+ }
588
+ }
589
+ const tools = formatToolsForGemini2(request.actions);
590
+ const chat = model.startChat({
591
+ history: mergedContents.slice(0, -1),
592
+ systemInstruction: systemInstruction ? { parts: [{ text: systemInstruction }] } : void 0,
593
+ tools: tools ? [tools] : void 0,
594
+ generationConfig: {
595
+ temperature: request.config?.temperature ?? this.config.temperature,
596
+ maxOutputTokens: request.config?.maxTokens ?? this.config.maxTokens
597
+ }
598
+ });
599
+ const lastMessage = mergedContents[mergedContents.length - 1];
600
+ const result = await chat.sendMessage(lastMessage.parts);
601
+ const response = result.response;
602
+ let textContent = "";
603
+ const toolCalls = [];
604
+ const candidate = response.candidates?.[0];
605
+ if (candidate?.content?.parts) {
606
+ for (const part of candidate.content.parts) {
607
+ if ("text" in part && part.text) {
608
+ textContent += part.text;
609
+ }
610
+ if ("functionCall" in part && part.functionCall) {
611
+ toolCalls.push({
612
+ id: core.generateToolCallId(),
613
+ name: part.functionCall.name,
614
+ args: part.functionCall.args || {}
615
+ });
616
+ }
617
+ }
618
+ }
619
+ return {
620
+ content: textContent,
621
+ toolCalls,
622
+ rawResponse: response
623
+ };
624
+ }
625
+ };
626
+ function createGoogleAdapter(config) {
627
+ return new GoogleAdapter(config);
628
+ }
629
+
630
+ // src/providers/google/index.ts
631
+ var GOOGLE_MODELS2 = {
632
+ // Gemini 2.0 series (latest)
633
+ "gemini-2.0-flash": {
634
+ vision: true,
635
+ tools: true,
636
+ audio: true,
637
+ video: true,
638
+ pdf: true,
639
+ maxTokens: 1e6,
640
+ outputTokens: 8192
641
+ },
642
+ "gemini-2.0-flash-lite": {
643
+ vision: true,
644
+ tools: true,
645
+ audio: false,
646
+ video: false,
647
+ pdf: true,
648
+ maxTokens: 1e6,
649
+ outputTokens: 8192
650
+ },
651
+ // Gemini 2.5 series (experimental)
652
+ "gemini-2.5-pro-preview-05-06": {
653
+ vision: true,
654
+ tools: true,
655
+ audio: true,
656
+ video: true,
657
+ pdf: true,
658
+ maxTokens: 1e6,
659
+ outputTokens: 65536
660
+ },
661
+ "gemini-2.5-flash-preview-05-20": {
662
+ vision: true,
663
+ tools: true,
664
+ audio: true,
665
+ video: true,
666
+ pdf: true,
667
+ maxTokens: 1e6,
668
+ outputTokens: 65536
669
+ },
670
+ // Gemini 1.5 series
671
+ "gemini-1.5-pro": {
672
+ vision: true,
673
+ tools: true,
674
+ audio: true,
675
+ video: true,
676
+ pdf: true,
677
+ maxTokens: 2e6,
678
+ outputTokens: 8192
679
+ },
680
+ "gemini-1.5-pro-latest": {
681
+ vision: true,
682
+ tools: true,
683
+ audio: true,
684
+ video: true,
685
+ pdf: true,
686
+ maxTokens: 2e6,
687
+ outputTokens: 8192
688
+ },
689
+ "gemini-1.5-flash": {
690
+ vision: true,
691
+ tools: true,
692
+ audio: true,
693
+ video: true,
694
+ pdf: true,
695
+ maxTokens: 1e6,
696
+ outputTokens: 8192
697
+ },
698
+ "gemini-1.5-flash-latest": {
699
+ vision: true,
700
+ tools: true,
701
+ audio: true,
702
+ video: true,
703
+ pdf: true,
704
+ maxTokens: 1e6,
705
+ outputTokens: 8192
706
+ },
707
+ "gemini-1.5-flash-8b": {
708
+ vision: true,
709
+ tools: true,
710
+ audio: false,
711
+ video: false,
712
+ pdf: true,
713
+ maxTokens: 1e6,
714
+ outputTokens: 8192
715
+ },
716
+ // Gemini 1.0 series (legacy)
717
+ "gemini-1.0-pro": {
718
+ vision: false,
719
+ tools: true,
720
+ audio: false,
721
+ video: false,
722
+ pdf: false,
723
+ maxTokens: 30720,
724
+ outputTokens: 2048
725
+ }
726
+ };
727
+ function createGoogle(config = {}) {
728
+ const apiKey = config.apiKey ?? process.env.GOOGLE_API_KEY ?? "";
729
+ return {
730
+ name: "google",
731
+ supportedModels: Object.keys(GOOGLE_MODELS2),
732
+ languageModel(modelId) {
733
+ return createGoogleAdapter({
734
+ apiKey,
735
+ model: modelId,
736
+ baseUrl: config.baseUrl,
737
+ safetySettings: config.safetySettings
738
+ });
739
+ },
740
+ getCapabilities(modelId) {
741
+ const model = GOOGLE_MODELS2[modelId] ?? GOOGLE_MODELS2["gemini-2.0-flash"];
742
+ return {
743
+ supportsVision: model.vision,
744
+ supportsTools: model.tools,
745
+ supportsThinking: false,
746
+ // Gemini doesn't have extended thinking like Claude
747
+ supportsStreaming: true,
748
+ supportsPDF: model.pdf,
749
+ supportsAudio: model.audio,
750
+ supportsVideo: model.video,
751
+ maxTokens: model.maxTokens,
752
+ supportedImageTypes: model.vision ? [
753
+ "image/png",
754
+ "image/jpeg",
755
+ "image/gif",
756
+ "image/webp",
757
+ "image/heic",
758
+ "image/heif"
759
+ ] : [],
760
+ supportedAudioTypes: model.audio ? [
761
+ "audio/mp3",
762
+ "audio/wav",
763
+ "audio/aiff",
764
+ "audio/aac",
765
+ "audio/ogg",
766
+ "audio/flac"
767
+ ] : [],
768
+ supportedVideoTypes: model.video ? [
769
+ "video/mp4",
770
+ "video/mpeg",
771
+ "video/mov",
772
+ "video/avi",
773
+ "video/webm",
774
+ "video/mkv"
775
+ ] : [],
776
+ supportsJsonMode: true,
777
+ // Gemini supports JSON mode
778
+ supportsSystemMessages: true
779
+ };
780
+ }
781
+ };
782
+ }
783
+ var createGoogleProvider = createGoogle;
784
+
785
+ exports.createGoogle = createGoogle;
786
+ exports.createGoogleModel = google;
787
+ exports.createGoogleProvider = createGoogleProvider;
788
+ exports.google = google;
789
+ //# sourceMappingURL=index.js.map
790
+ //# sourceMappingURL=index.js.map