integrate-sdk 0.7.41 → 0.7.43
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/ai/google.d.ts +31 -37
- package/dist/ai/google.d.ts.map +1 -1
- package/dist/ai/google.js +45 -13
- package/dist/ai/index.js +45 -13
- package/dist/server.js +45 -13
- package/dist/src/ai/google.d.ts +31 -37
- package/dist/src/ai/google.d.ts.map +1 -1
- package/package.json +5 -4
package/dist/ai/google.d.ts
CHANGED
|
@@ -6,40 +6,11 @@
|
|
|
6
6
|
import type { MCPClient } from "../client.js";
|
|
7
7
|
import type { MCPTool } from "../protocol/messages.js";
|
|
8
8
|
import { type AIToolsOptions } from "./utils.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
description?: string;
|
|
15
|
-
enum?: string[];
|
|
16
|
-
items?: Schema;
|
|
17
|
-
properties?: Record<string, Schema>;
|
|
18
|
-
required?: string[];
|
|
19
|
-
[key: string]: unknown;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Google GenAI function declaration
|
|
23
|
-
* Compatible with @google/genai SDK FunctionDeclaration type
|
|
24
|
-
*/
|
|
25
|
-
export interface GoogleTool {
|
|
26
|
-
name: string;
|
|
27
|
-
description: string;
|
|
28
|
-
parameters: {
|
|
29
|
-
type: 'object';
|
|
30
|
-
description?: string;
|
|
31
|
-
properties?: Record<string, Schema>;
|
|
32
|
-
required?: string[];
|
|
33
|
-
[key: string]: unknown;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Google GenAI function call
|
|
38
|
-
*/
|
|
39
|
-
export interface GoogleFunctionCall {
|
|
40
|
-
name?: string;
|
|
41
|
-
args?: Record<string, unknown>;
|
|
42
|
-
}
|
|
9
|
+
import { Type } from "@google/genai";
|
|
10
|
+
import type { Schema, FunctionDeclaration, FunctionCall } from "@google/genai";
|
|
11
|
+
export type GoogleTool = FunctionDeclaration;
|
|
12
|
+
export type GoogleFunctionCall = FunctionCall;
|
|
13
|
+
export type { Schema, Type };
|
|
43
14
|
/**
|
|
44
15
|
* Options for converting MCP tools to Google GenAI format
|
|
45
16
|
*/
|
|
@@ -81,6 +52,8 @@ export declare function convertMCPToolsToGoogle(client: MCPClient<any>, options?
|
|
|
81
52
|
/**
|
|
82
53
|
* Execute a function call from Google GenAI
|
|
83
54
|
*
|
|
55
|
+
* Automatically extracts provider tokens from the request if not provided.
|
|
56
|
+
*
|
|
84
57
|
* @param client - The MCP client instance
|
|
85
58
|
* @param functionCall - The function call from Google GenAI response
|
|
86
59
|
* @param options - Optional configuration including provider tokens
|
|
@@ -88,6 +61,16 @@ export declare function convertMCPToolsToGoogle(client: MCPClient<any>, options?
|
|
|
88
61
|
*
|
|
89
62
|
* @example
|
|
90
63
|
* ```typescript
|
|
64
|
+
* // Tokens are automatically extracted
|
|
65
|
+
* const result = await executeGoogleFunctionCall(client, {
|
|
66
|
+
* name: 'github_create_issue',
|
|
67
|
+
* args: { owner: 'user', repo: 'repo', title: 'Bug' }
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* // Or explicitly pass provider tokens
|
|
91
74
|
* const result = await executeGoogleFunctionCall(client, {
|
|
92
75
|
* name: 'github_create_issue',
|
|
93
76
|
* args: { owner: 'user', repo: 'repo', title: 'Bug' }
|
|
@@ -101,6 +84,8 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
101
84
|
* This function handles the transformation from Google's function call format
|
|
102
85
|
* to the format expected by the SDK, then executes each call.
|
|
103
86
|
*
|
|
87
|
+
* Automatically extracts provider tokens from the request if not provided.
|
|
88
|
+
*
|
|
104
89
|
* @param client - The MCP client instance
|
|
105
90
|
* @param functionCalls - Array of function calls from Google GenAI response
|
|
106
91
|
* @param options - Optional configuration including provider tokens
|
|
@@ -108,7 +93,7 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
108
93
|
*
|
|
109
94
|
* @example
|
|
110
95
|
* ```typescript
|
|
111
|
-
* // In your API route
|
|
96
|
+
* // In your API route - tokens are automatically extracted
|
|
112
97
|
* const response = await ai.models.generateContent({
|
|
113
98
|
* model: 'gemini-2.0-flash-001',
|
|
114
99
|
* contents: messages,
|
|
@@ -120,12 +105,21 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
120
105
|
* if (response.functionCalls && response.functionCalls.length > 0) {
|
|
121
106
|
* const results = await executeGoogleFunctionCalls(
|
|
122
107
|
* serverClient,
|
|
123
|
-
* response.functionCalls
|
|
124
|
-
* { providerTokens }
|
|
108
|
+
* response.functionCalls
|
|
125
109
|
* );
|
|
126
110
|
* return Response.json(results);
|
|
127
111
|
* }
|
|
128
112
|
* ```
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // Or explicitly pass provider tokens
|
|
117
|
+
* const results = await executeGoogleFunctionCalls(
|
|
118
|
+
* serverClient,
|
|
119
|
+
* response.functionCalls,
|
|
120
|
+
* { providerTokens }
|
|
121
|
+
* );
|
|
122
|
+
* ```
|
|
129
123
|
*/
|
|
130
124
|
export declare function executeGoogleFunctionCalls(client: MCPClient<any>, functionCalls: GoogleFunctionCall[] | undefined | null, options?: GoogleToolsOptions): Promise<string[]>;
|
|
131
125
|
/**
|
package/dist/ai/google.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/ai/google.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"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tB,aAAa,EAAE,kBAAkB,EAAE,GAAG,SAAS,GAAG,IAAI,EACtD,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,MAAM,EAAE,CAAC,CAsBnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,SAAS,CAAC,GAAG,CAAC,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,UAAU,EAAE,CAAC,CAevB"}
|
package/dist/ai/google.js
CHANGED
|
@@ -4203,6 +4203,18 @@ async function ensureClientConnected(client) {
|
|
|
4203
4203
|
}
|
|
4204
4204
|
|
|
4205
4205
|
// google.ts
|
|
4206
|
+
import { Type } from "@google/genai";
|
|
4207
|
+
function convertJsonSchemaTypeToGoogleType(type) {
|
|
4208
|
+
const typeMap = {
|
|
4209
|
+
string: Type.STRING,
|
|
4210
|
+
number: Type.NUMBER,
|
|
4211
|
+
integer: Type.INTEGER,
|
|
4212
|
+
boolean: Type.BOOLEAN,
|
|
4213
|
+
array: Type.ARRAY,
|
|
4214
|
+
object: Type.OBJECT
|
|
4215
|
+
};
|
|
4216
|
+
return typeMap[type.toLowerCase()] || Type.STRING;
|
|
4217
|
+
}
|
|
4206
4218
|
function convertPropertiesToSchema(properties) {
|
|
4207
4219
|
const result = {};
|
|
4208
4220
|
for (const [key, value] of Object.entries(properties)) {
|
|
@@ -4211,11 +4223,12 @@ function convertPropertiesToSchema(properties) {
|
|
|
4211
4223
|
continue;
|
|
4212
4224
|
}
|
|
4213
4225
|
const schema = {
|
|
4214
|
-
type: value.type,
|
|
4215
4226
|
description: value.description,
|
|
4216
|
-
enum: value.enum
|
|
4217
|
-
required: value.required
|
|
4227
|
+
enum: value.enum
|
|
4218
4228
|
};
|
|
4229
|
+
if (value.type) {
|
|
4230
|
+
schema.type = convertJsonSchemaTypeToGoogleType(value.type);
|
|
4231
|
+
}
|
|
4219
4232
|
if (value.items) {
|
|
4220
4233
|
schema.items = convertPropertiesToSchema({ items: value.items }).items;
|
|
4221
4234
|
}
|
|
@@ -4223,7 +4236,7 @@ function convertPropertiesToSchema(properties) {
|
|
|
4223
4236
|
schema.properties = convertPropertiesToSchema(value.properties);
|
|
4224
4237
|
}
|
|
4225
4238
|
for (const [k, v] of Object.entries(value)) {
|
|
4226
|
-
if (!["type", "description", "enum", "
|
|
4239
|
+
if (!["type", "description", "enum", "items", "properties"].includes(k)) {
|
|
4227
4240
|
schema[k] = v;
|
|
4228
4241
|
}
|
|
4229
4242
|
}
|
|
@@ -4233,15 +4246,19 @@ function convertPropertiesToSchema(properties) {
|
|
|
4233
4246
|
}
|
|
4234
4247
|
function convertMCPToolToGoogle(mcpTool, _client, _options) {
|
|
4235
4248
|
const properties = mcpTool.inputSchema?.properties || {};
|
|
4249
|
+
const convertedProperties = convertPropertiesToSchema(properties);
|
|
4250
|
+
const parameters = {
|
|
4251
|
+
type: Type.OBJECT,
|
|
4252
|
+
description: mcpTool.description || "",
|
|
4253
|
+
properties: convertedProperties
|
|
4254
|
+
};
|
|
4255
|
+
if (mcpTool.inputSchema?.required && mcpTool.inputSchema.required.length > 0) {
|
|
4256
|
+
parameters.required = mcpTool.inputSchema.required;
|
|
4257
|
+
}
|
|
4236
4258
|
return {
|
|
4237
4259
|
name: mcpTool.name,
|
|
4238
4260
|
description: mcpTool.description || `Execute ${mcpTool.name}`,
|
|
4239
|
-
parameters
|
|
4240
|
-
type: "object",
|
|
4241
|
-
description: mcpTool.description || "",
|
|
4242
|
-
properties: convertPropertiesToSchema(properties),
|
|
4243
|
-
required: mcpTool.inputSchema?.required || []
|
|
4244
|
-
}
|
|
4261
|
+
parameters
|
|
4245
4262
|
};
|
|
4246
4263
|
}
|
|
4247
4264
|
function convertMCPToolsToGoogle(client, options) {
|
|
@@ -4249,17 +4266,32 @@ function convertMCPToolsToGoogle(client, options) {
|
|
|
4249
4266
|
return mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, options));
|
|
4250
4267
|
}
|
|
4251
4268
|
async function executeGoogleFunctionCall(client, functionCall, options) {
|
|
4252
|
-
if (!functionCall
|
|
4269
|
+
if (!functionCall?.name) {
|
|
4253
4270
|
throw new Error("Function call must have a name");
|
|
4254
4271
|
}
|
|
4255
|
-
|
|
4272
|
+
let providerTokens = options?.providerTokens;
|
|
4273
|
+
if (!providerTokens) {
|
|
4274
|
+
try {
|
|
4275
|
+
providerTokens = await getProviderTokens();
|
|
4276
|
+
} catch {}
|
|
4277
|
+
}
|
|
4278
|
+
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
4279
|
+
const args = functionCall.args || {};
|
|
4280
|
+
const result = await executeToolWithToken(client, functionCall.name, args, finalOptions);
|
|
4256
4281
|
return JSON.stringify(result);
|
|
4257
4282
|
}
|
|
4258
4283
|
async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
4259
4284
|
if (!functionCalls || functionCalls.length === 0) {
|
|
4260
4285
|
return [];
|
|
4261
4286
|
}
|
|
4262
|
-
|
|
4287
|
+
let providerTokens = options?.providerTokens;
|
|
4288
|
+
if (!providerTokens) {
|
|
4289
|
+
try {
|
|
4290
|
+
providerTokens = await getProviderTokens();
|
|
4291
|
+
} catch {}
|
|
4292
|
+
}
|
|
4293
|
+
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
4294
|
+
const results = await Promise.all(functionCalls.map((call) => executeGoogleFunctionCall(client, call, finalOptions)));
|
|
4263
4295
|
return results;
|
|
4264
4296
|
}
|
|
4265
4297
|
async function getGoogleTools(client, options) {
|
package/dist/ai/index.js
CHANGED
|
@@ -4317,6 +4317,18 @@ async function getCloudflareTools(client, options) {
|
|
|
4317
4317
|
}
|
|
4318
4318
|
|
|
4319
4319
|
// google.ts
|
|
4320
|
+
import { Type } from "@google/genai";
|
|
4321
|
+
function convertJsonSchemaTypeToGoogleType(type) {
|
|
4322
|
+
const typeMap = {
|
|
4323
|
+
string: Type.STRING,
|
|
4324
|
+
number: Type.NUMBER,
|
|
4325
|
+
integer: Type.INTEGER,
|
|
4326
|
+
boolean: Type.BOOLEAN,
|
|
4327
|
+
array: Type.ARRAY,
|
|
4328
|
+
object: Type.OBJECT
|
|
4329
|
+
};
|
|
4330
|
+
return typeMap[type.toLowerCase()] || Type.STRING;
|
|
4331
|
+
}
|
|
4320
4332
|
function convertPropertiesToSchema(properties) {
|
|
4321
4333
|
const result = {};
|
|
4322
4334
|
for (const [key, value] of Object.entries(properties)) {
|
|
@@ -4325,11 +4337,12 @@ function convertPropertiesToSchema(properties) {
|
|
|
4325
4337
|
continue;
|
|
4326
4338
|
}
|
|
4327
4339
|
const schema = {
|
|
4328
|
-
type: value.type,
|
|
4329
4340
|
description: value.description,
|
|
4330
|
-
enum: value.enum
|
|
4331
|
-
required: value.required
|
|
4341
|
+
enum: value.enum
|
|
4332
4342
|
};
|
|
4343
|
+
if (value.type) {
|
|
4344
|
+
schema.type = convertJsonSchemaTypeToGoogleType(value.type);
|
|
4345
|
+
}
|
|
4333
4346
|
if (value.items) {
|
|
4334
4347
|
schema.items = convertPropertiesToSchema({ items: value.items }).items;
|
|
4335
4348
|
}
|
|
@@ -4337,7 +4350,7 @@ function convertPropertiesToSchema(properties) {
|
|
|
4337
4350
|
schema.properties = convertPropertiesToSchema(value.properties);
|
|
4338
4351
|
}
|
|
4339
4352
|
for (const [k, v] of Object.entries(value)) {
|
|
4340
|
-
if (!["type", "description", "enum", "
|
|
4353
|
+
if (!["type", "description", "enum", "items", "properties"].includes(k)) {
|
|
4341
4354
|
schema[k] = v;
|
|
4342
4355
|
}
|
|
4343
4356
|
}
|
|
@@ -4347,15 +4360,19 @@ function convertPropertiesToSchema(properties) {
|
|
|
4347
4360
|
}
|
|
4348
4361
|
function convertMCPToolToGoogle(mcpTool, _client, _options) {
|
|
4349
4362
|
const properties = mcpTool.inputSchema?.properties || {};
|
|
4363
|
+
const convertedProperties = convertPropertiesToSchema(properties);
|
|
4364
|
+
const parameters = {
|
|
4365
|
+
type: Type.OBJECT,
|
|
4366
|
+
description: mcpTool.description || "",
|
|
4367
|
+
properties: convertedProperties
|
|
4368
|
+
};
|
|
4369
|
+
if (mcpTool.inputSchema?.required && mcpTool.inputSchema.required.length > 0) {
|
|
4370
|
+
parameters.required = mcpTool.inputSchema.required;
|
|
4371
|
+
}
|
|
4350
4372
|
return {
|
|
4351
4373
|
name: mcpTool.name,
|
|
4352
4374
|
description: mcpTool.description || `Execute ${mcpTool.name}`,
|
|
4353
|
-
parameters
|
|
4354
|
-
type: "object",
|
|
4355
|
-
description: mcpTool.description || "",
|
|
4356
|
-
properties: convertPropertiesToSchema(properties),
|
|
4357
|
-
required: mcpTool.inputSchema?.required || []
|
|
4358
|
-
}
|
|
4375
|
+
parameters
|
|
4359
4376
|
};
|
|
4360
4377
|
}
|
|
4361
4378
|
function convertMCPToolsToGoogle(client, options) {
|
|
@@ -4363,17 +4380,32 @@ function convertMCPToolsToGoogle(client, options) {
|
|
|
4363
4380
|
return mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, options));
|
|
4364
4381
|
}
|
|
4365
4382
|
async function executeGoogleFunctionCall(client, functionCall, options) {
|
|
4366
|
-
if (!functionCall
|
|
4383
|
+
if (!functionCall?.name) {
|
|
4367
4384
|
throw new Error("Function call must have a name");
|
|
4368
4385
|
}
|
|
4369
|
-
|
|
4386
|
+
let providerTokens = options?.providerTokens;
|
|
4387
|
+
if (!providerTokens) {
|
|
4388
|
+
try {
|
|
4389
|
+
providerTokens = await getProviderTokens();
|
|
4390
|
+
} catch {}
|
|
4391
|
+
}
|
|
4392
|
+
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
4393
|
+
const args = functionCall.args || {};
|
|
4394
|
+
const result = await executeToolWithToken(client, functionCall.name, args, finalOptions);
|
|
4370
4395
|
return JSON.stringify(result);
|
|
4371
4396
|
}
|
|
4372
4397
|
async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
4373
4398
|
if (!functionCalls || functionCalls.length === 0) {
|
|
4374
4399
|
return [];
|
|
4375
4400
|
}
|
|
4376
|
-
|
|
4401
|
+
let providerTokens = options?.providerTokens;
|
|
4402
|
+
if (!providerTokens) {
|
|
4403
|
+
try {
|
|
4404
|
+
providerTokens = await getProviderTokens();
|
|
4405
|
+
} catch {}
|
|
4406
|
+
}
|
|
4407
|
+
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
4408
|
+
const results = await Promise.all(functionCalls.map((call) => executeGoogleFunctionCall(client, call, finalOptions)));
|
|
4377
4409
|
return results;
|
|
4378
4410
|
}
|
|
4379
4411
|
async function getGoogleTools(client, options) {
|
package/dist/server.js
CHANGED
|
@@ -6675,6 +6675,18 @@ async function handleAnthropicMessage(client, message, options) {
|
|
|
6675
6675
|
];
|
|
6676
6676
|
}
|
|
6677
6677
|
// src/ai/google.ts
|
|
6678
|
+
import { Type } from "@google/genai";
|
|
6679
|
+
function convertJsonSchemaTypeToGoogleType(type) {
|
|
6680
|
+
const typeMap = {
|
|
6681
|
+
string: Type.STRING,
|
|
6682
|
+
number: Type.NUMBER,
|
|
6683
|
+
integer: Type.INTEGER,
|
|
6684
|
+
boolean: Type.BOOLEAN,
|
|
6685
|
+
array: Type.ARRAY,
|
|
6686
|
+
object: Type.OBJECT
|
|
6687
|
+
};
|
|
6688
|
+
return typeMap[type.toLowerCase()] || Type.STRING;
|
|
6689
|
+
}
|
|
6678
6690
|
function convertPropertiesToSchema(properties) {
|
|
6679
6691
|
const result = {};
|
|
6680
6692
|
for (const [key, value] of Object.entries(properties)) {
|
|
@@ -6683,11 +6695,12 @@ function convertPropertiesToSchema(properties) {
|
|
|
6683
6695
|
continue;
|
|
6684
6696
|
}
|
|
6685
6697
|
const schema = {
|
|
6686
|
-
type: value.type,
|
|
6687
6698
|
description: value.description,
|
|
6688
|
-
enum: value.enum
|
|
6689
|
-
required: value.required
|
|
6699
|
+
enum: value.enum
|
|
6690
6700
|
};
|
|
6701
|
+
if (value.type) {
|
|
6702
|
+
schema.type = convertJsonSchemaTypeToGoogleType(value.type);
|
|
6703
|
+
}
|
|
6691
6704
|
if (value.items) {
|
|
6692
6705
|
schema.items = convertPropertiesToSchema({ items: value.items }).items;
|
|
6693
6706
|
}
|
|
@@ -6695,7 +6708,7 @@ function convertPropertiesToSchema(properties) {
|
|
|
6695
6708
|
schema.properties = convertPropertiesToSchema(value.properties);
|
|
6696
6709
|
}
|
|
6697
6710
|
for (const [k, v] of Object.entries(value)) {
|
|
6698
|
-
if (!["type", "description", "enum", "
|
|
6711
|
+
if (!["type", "description", "enum", "items", "properties"].includes(k)) {
|
|
6699
6712
|
schema[k] = v;
|
|
6700
6713
|
}
|
|
6701
6714
|
}
|
|
@@ -6705,15 +6718,19 @@ function convertPropertiesToSchema(properties) {
|
|
|
6705
6718
|
}
|
|
6706
6719
|
function convertMCPToolToGoogle(mcpTool, _client, _options) {
|
|
6707
6720
|
const properties = mcpTool.inputSchema?.properties || {};
|
|
6721
|
+
const convertedProperties = convertPropertiesToSchema(properties);
|
|
6722
|
+
const parameters = {
|
|
6723
|
+
type: Type.OBJECT,
|
|
6724
|
+
description: mcpTool.description || "",
|
|
6725
|
+
properties: convertedProperties
|
|
6726
|
+
};
|
|
6727
|
+
if (mcpTool.inputSchema?.required && mcpTool.inputSchema.required.length > 0) {
|
|
6728
|
+
parameters.required = mcpTool.inputSchema.required;
|
|
6729
|
+
}
|
|
6708
6730
|
return {
|
|
6709
6731
|
name: mcpTool.name,
|
|
6710
6732
|
description: mcpTool.description || `Execute ${mcpTool.name}`,
|
|
6711
|
-
parameters
|
|
6712
|
-
type: "object",
|
|
6713
|
-
description: mcpTool.description || "",
|
|
6714
|
-
properties: convertPropertiesToSchema(properties),
|
|
6715
|
-
required: mcpTool.inputSchema?.required || []
|
|
6716
|
-
}
|
|
6733
|
+
parameters
|
|
6717
6734
|
};
|
|
6718
6735
|
}
|
|
6719
6736
|
function convertMCPToolsToGoogle(client, options) {
|
|
@@ -6721,17 +6738,32 @@ function convertMCPToolsToGoogle(client, options) {
|
|
|
6721
6738
|
return mcpTools.map((mcpTool) => convertMCPToolToGoogle(mcpTool, client, options));
|
|
6722
6739
|
}
|
|
6723
6740
|
async function executeGoogleFunctionCall(client, functionCall, options) {
|
|
6724
|
-
if (!functionCall
|
|
6741
|
+
if (!functionCall?.name) {
|
|
6725
6742
|
throw new Error("Function call must have a name");
|
|
6726
6743
|
}
|
|
6727
|
-
|
|
6744
|
+
let providerTokens = options?.providerTokens;
|
|
6745
|
+
if (!providerTokens) {
|
|
6746
|
+
try {
|
|
6747
|
+
providerTokens = await getProviderTokens();
|
|
6748
|
+
} catch {}
|
|
6749
|
+
}
|
|
6750
|
+
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
6751
|
+
const args = functionCall.args || {};
|
|
6752
|
+
const result = await executeToolWithToken(client, functionCall.name, args, finalOptions);
|
|
6728
6753
|
return JSON.stringify(result);
|
|
6729
6754
|
}
|
|
6730
6755
|
async function executeGoogleFunctionCalls(client, functionCalls, options) {
|
|
6731
6756
|
if (!functionCalls || functionCalls.length === 0) {
|
|
6732
6757
|
return [];
|
|
6733
6758
|
}
|
|
6734
|
-
|
|
6759
|
+
let providerTokens = options?.providerTokens;
|
|
6760
|
+
if (!providerTokens) {
|
|
6761
|
+
try {
|
|
6762
|
+
providerTokens = await getProviderTokens();
|
|
6763
|
+
} catch {}
|
|
6764
|
+
}
|
|
6765
|
+
const finalOptions = providerTokens ? { ...options, providerTokens } : options;
|
|
6766
|
+
const results = await Promise.all(functionCalls.map((call) => executeGoogleFunctionCall(client, call, finalOptions)));
|
|
6735
6767
|
return results;
|
|
6736
6768
|
}
|
|
6737
6769
|
async function getGoogleTools(client, options) {
|
package/dist/src/ai/google.d.ts
CHANGED
|
@@ -6,40 +6,11 @@
|
|
|
6
6
|
import type { MCPClient } from "../client.js";
|
|
7
7
|
import type { MCPTool } from "../protocol/messages.js";
|
|
8
8
|
import { type AIToolsOptions } from "./utils.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
description?: string;
|
|
15
|
-
enum?: string[];
|
|
16
|
-
items?: Schema;
|
|
17
|
-
properties?: Record<string, Schema>;
|
|
18
|
-
required?: string[];
|
|
19
|
-
[key: string]: unknown;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Google GenAI function declaration
|
|
23
|
-
* Compatible with @google/genai SDK FunctionDeclaration type
|
|
24
|
-
*/
|
|
25
|
-
export interface GoogleTool {
|
|
26
|
-
name: string;
|
|
27
|
-
description: string;
|
|
28
|
-
parameters: {
|
|
29
|
-
type: 'object';
|
|
30
|
-
description?: string;
|
|
31
|
-
properties?: Record<string, Schema>;
|
|
32
|
-
required?: string[];
|
|
33
|
-
[key: string]: unknown;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Google GenAI function call
|
|
38
|
-
*/
|
|
39
|
-
export interface GoogleFunctionCall {
|
|
40
|
-
name?: string;
|
|
41
|
-
args?: Record<string, unknown>;
|
|
42
|
-
}
|
|
9
|
+
import { Type } from "@google/genai";
|
|
10
|
+
import type { Schema, FunctionDeclaration, FunctionCall } from "@google/genai";
|
|
11
|
+
export type GoogleTool = FunctionDeclaration;
|
|
12
|
+
export type GoogleFunctionCall = FunctionCall;
|
|
13
|
+
export type { Schema, Type };
|
|
43
14
|
/**
|
|
44
15
|
* Options for converting MCP tools to Google GenAI format
|
|
45
16
|
*/
|
|
@@ -81,6 +52,8 @@ export declare function convertMCPToolsToGoogle(client: MCPClient<any>, options?
|
|
|
81
52
|
/**
|
|
82
53
|
* Execute a function call from Google GenAI
|
|
83
54
|
*
|
|
55
|
+
* Automatically extracts provider tokens from the request if not provided.
|
|
56
|
+
*
|
|
84
57
|
* @param client - The MCP client instance
|
|
85
58
|
* @param functionCall - The function call from Google GenAI response
|
|
86
59
|
* @param options - Optional configuration including provider tokens
|
|
@@ -88,6 +61,16 @@ export declare function convertMCPToolsToGoogle(client: MCPClient<any>, options?
|
|
|
88
61
|
*
|
|
89
62
|
* @example
|
|
90
63
|
* ```typescript
|
|
64
|
+
* // Tokens are automatically extracted
|
|
65
|
+
* const result = await executeGoogleFunctionCall(client, {
|
|
66
|
+
* name: 'github_create_issue',
|
|
67
|
+
* args: { owner: 'user', repo: 'repo', title: 'Bug' }
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* // Or explicitly pass provider tokens
|
|
91
74
|
* const result = await executeGoogleFunctionCall(client, {
|
|
92
75
|
* name: 'github_create_issue',
|
|
93
76
|
* args: { owner: 'user', repo: 'repo', title: 'Bug' }
|
|
@@ -101,6 +84,8 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
101
84
|
* This function handles the transformation from Google's function call format
|
|
102
85
|
* to the format expected by the SDK, then executes each call.
|
|
103
86
|
*
|
|
87
|
+
* Automatically extracts provider tokens from the request if not provided.
|
|
88
|
+
*
|
|
104
89
|
* @param client - The MCP client instance
|
|
105
90
|
* @param functionCalls - Array of function calls from Google GenAI response
|
|
106
91
|
* @param options - Optional configuration including provider tokens
|
|
@@ -108,7 +93,7 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
108
93
|
*
|
|
109
94
|
* @example
|
|
110
95
|
* ```typescript
|
|
111
|
-
* // In your API route
|
|
96
|
+
* // In your API route - tokens are automatically extracted
|
|
112
97
|
* const response = await ai.models.generateContent({
|
|
113
98
|
* model: 'gemini-2.0-flash-001',
|
|
114
99
|
* contents: messages,
|
|
@@ -120,12 +105,21 @@ export declare function executeGoogleFunctionCall(client: MCPClient<any>, functi
|
|
|
120
105
|
* if (response.functionCalls && response.functionCalls.length > 0) {
|
|
121
106
|
* const results = await executeGoogleFunctionCalls(
|
|
122
107
|
* serverClient,
|
|
123
|
-
* response.functionCalls
|
|
124
|
-
* { providerTokens }
|
|
108
|
+
* response.functionCalls
|
|
125
109
|
* );
|
|
126
110
|
* return Response.json(results);
|
|
127
111
|
* }
|
|
128
112
|
* ```
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // Or explicitly pass provider tokens
|
|
117
|
+
* const results = await executeGoogleFunctionCalls(
|
|
118
|
+
* serverClient,
|
|
119
|
+
* response.functionCalls,
|
|
120
|
+
* { providerTokens }
|
|
121
|
+
* );
|
|
122
|
+
* ```
|
|
129
123
|
*/
|
|
130
124
|
export declare function executeGoogleFunctionCalls(client: MCPClient<any>, functionCalls: GoogleFunctionCall[] | undefined | null, options?: GoogleToolsOptions): Promise<string[]>;
|
|
131
125
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/ai/google.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/ai/google.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAkE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjH,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,KAAK,EACV,MAAM,EACN,mBAAmB,EACnB,YAAY,EACb,MAAM,eAAe,CAAC;AAGvB,MAAM,MAAM,UAAU,GAAG,mBAAmB,CAAC;AAC7C,MAAM,MAAM,kBAAkB,GAAG,YAAY,C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
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.43",
|
|
4
4
|
"description": "Type-safe 3rd party integration SDK for the Integrate MCP server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"prep": "bun run type-check && bun run build",
|
|
45
45
|
"build": "bun run build:client && bun run build:server && bun run build:adapters && bun run build:ai && bun run build:types && bun run build:copy-types",
|
|
46
46
|
"build:client": "bun build index.ts react.ts --outdir dist --target browser --format esm --external react",
|
|
47
|
-
"build:server": "bun build server.ts oauth.ts --outdir dist --target node --format esm",
|
|
47
|
+
"build:server": "bun build server.ts oauth.ts --outdir dist --target node --format esm --external @google/genai --external @anthropic-ai/sdk --external openai --external ai --external @langchain/core --external llamaindex --external @mastra/core --external @cloudflare/workers-types --external @openai/agents",
|
|
48
48
|
"build:adapters": "cd src/adapters && bun build *.ts --outdir ../../dist/adapters --target node --format esm && cd ../..",
|
|
49
|
-
"build:ai": "cd src/ai && bun build *.ts --outdir ../../dist/ai --target node --format esm && cd ../..",
|
|
49
|
+
"build:ai": "cd src/ai && bun build *.ts --outdir ../../dist/ai --target node --format esm --external @google/genai --external @anthropic-ai/sdk --external openai --external ai --external @langchain/core --external llamaindex --external @mastra/core --external @cloudflare/workers-types --external @openai/agents && cd ../..",
|
|
50
50
|
"build:types": "tsc --emitDeclarationOnly --declaration --declarationMap",
|
|
51
51
|
"build:copy-types": "cp dist/src/ai/*.d.ts dist/ai/ && cp dist/src/ai/*.d.ts.map dist/ai/ && cp dist/src/adapters/*.d.ts dist/adapters/ && cp dist/src/adapters/*.d.ts.map dist/adapters/",
|
|
52
52
|
"dev": "bun --watch src/index.ts",
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@anthropic-ai/sdk": "^0.32.1",
|
|
75
|
+
"@google/genai": "^1.29.0",
|
|
75
76
|
"@types/bun": "latest",
|
|
76
77
|
"@types/react": "^18.3.0",
|
|
77
78
|
"openai": "^4.77.3",
|
|
@@ -86,7 +87,7 @@
|
|
|
86
87
|
"openai": ">=4.0.0",
|
|
87
88
|
"@openai/agents": ">=0.1.0",
|
|
88
89
|
"@anthropic-ai/sdk": ">=0.20.0",
|
|
89
|
-
"@google/genai": "
|
|
90
|
+
"@google/genai": "",
|
|
90
91
|
"@cloudflare/workers-types": ">=4.0.0",
|
|
91
92
|
"@langchain/core": ">=0.1.0",
|
|
92
93
|
"llamaindex": ">=0.1.0",
|