@composio/google 0.9.3 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -94
- package/dist/index.d.mts +0 -1
- package/dist/index.mjs +4 -3
- package/package.json +9 -18
- package/dist/index.cjs +0 -214
- package/dist/index.d.cts +0 -193
package/README.md
CHANGED
|
@@ -1,124 +1,72 @@
|
|
|
1
1
|
# @composio/google
|
|
2
2
|
|
|
3
|
-
Google GenAI
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Google GenAI Integration**: Seamless integration with Google's Generative AI models (Gemini)
|
|
8
|
-
- **Function Calling Support**: Convert Composio tools to Google GenAI function declarations
|
|
9
|
-
- **Type Safety**: Full TypeScript support with proper type definitions
|
|
10
|
-
- **Execution Modifiers**: Support for transforming tool inputs and outputs
|
|
11
|
-
- **Flexible Authentication**: Support for custom authentication parameters
|
|
12
|
-
- **Streaming Support**: First-class support for streaming responses
|
|
3
|
+
Adapts Composio tools to Gemini function declarations for the Google GenAI SDK (`@google/genai`) and executes the function calls the model returns.
|
|
13
4
|
|
|
14
5
|
## Installation
|
|
15
6
|
|
|
16
7
|
```bash
|
|
17
8
|
npm install @composio/core @composio/google @google/genai
|
|
18
|
-
# or
|
|
19
|
-
yarn add @composio/core @composio/google @google/genai
|
|
20
|
-
# or
|
|
21
|
-
pnpm add @composio/core @composio/google @google/genai
|
|
22
9
|
```
|
|
23
10
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
Required environment variables:
|
|
27
|
-
|
|
28
|
-
- `COMPOSIO_API_KEY`: Your Composio API key
|
|
29
|
-
- `GEMINI_API_KEY`: Your Google AI API key
|
|
30
|
-
|
|
31
|
-
Optional environment variables:
|
|
11
|
+
Set `COMPOSIO_API_KEY` (create one at https://dashboard.composio.dev/settings) and `GOOGLE_API_KEY` (from https://aistudio.google.com/apikey) in your environment.
|
|
32
12
|
|
|
33
|
-
|
|
34
|
-
- `GOOGLE_LOCATION`: Your Google Cloud location (for custom deployments)
|
|
13
|
+
## Quickstart
|
|
35
14
|
|
|
36
|
-
|
|
15
|
+
Create a session for your user, pass its tools to Gemini as function declarations, and run the loop: execute each function call with `composio.provider.executeToolCall`, feed the result back, and repeat until the model replies with text.
|
|
37
16
|
|
|
38
17
|
```typescript
|
|
39
18
|
import { Composio } from '@composio/core';
|
|
40
19
|
import { GoogleProvider } from '@composio/google';
|
|
41
|
-
import {
|
|
20
|
+
import { GoogleGenAI, type Part } from '@google/genai';
|
|
42
21
|
|
|
43
|
-
// Initialize Google GenAI
|
|
44
|
-
const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
|
|
45
|
-
|
|
46
|
-
// Initialize Composio with Google provider
|
|
47
22
|
const composio = new Composio({
|
|
48
|
-
apiKey: process.env.COMPOSIO_API_KEY,
|
|
49
23
|
provider: new GoogleProvider(),
|
|
50
24
|
});
|
|
25
|
+
const ai = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY! });
|
|
51
26
|
|
|
52
|
-
//
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
limit: 10,
|
|
56
|
-
});
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Examples
|
|
27
|
+
// Create a session for your user
|
|
28
|
+
const session = await composio.create('user_123');
|
|
29
|
+
const tools = await session.tools();
|
|
60
30
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
### GoogleProvider Class
|
|
68
|
-
|
|
69
|
-
The `GoogleProvider` class extends `BaseNonAgenticProvider` and provides Google GenAI-specific functionality.
|
|
70
|
-
|
|
71
|
-
#### Methods
|
|
72
|
-
|
|
73
|
-
##### `wrapTool(tool: Tool): GoogleTool`
|
|
74
|
-
|
|
75
|
-
Wraps a Composio tool in the Google GenAI function declaration format.
|
|
76
|
-
|
|
77
|
-
```typescript
|
|
78
|
-
const wrappedTool = provider.wrapTool(composioTool);
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
##### `wrapTools(tools: Tool[]): GoogleGenAIToolCollection`
|
|
82
|
-
|
|
83
|
-
Wraps multiple Composio tools in the Google GenAI function declaration format.
|
|
84
|
-
|
|
85
|
-
```typescript
|
|
86
|
-
const wrappedTools = provider.wrapTools(composioTools);
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
##### `executeToolCall(userId: string, tool: GoogleGenAIFunctionCall, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<string>`
|
|
90
|
-
|
|
91
|
-
Executes a tool call from Google GenAI and returns the result as a JSON string.
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
const result = await provider.executeToolCall('user123', functionCall, options, modifiers);
|
|
95
|
-
```
|
|
31
|
+
const chat = ai.chats.create({
|
|
32
|
+
model: 'gemini-3-pro-preview',
|
|
33
|
+
config: {
|
|
34
|
+
tools: [{ functionDeclarations: tools }],
|
|
35
|
+
},
|
|
36
|
+
});
|
|
96
37
|
|
|
97
|
-
|
|
38
|
+
let response = await chat.sendMessage({
|
|
39
|
+
message:
|
|
40
|
+
"Send an email to john@example.com with the subject 'Hello' and body 'Hello from Composio!'",
|
|
41
|
+
});
|
|
98
42
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
43
|
+
// Agentic loop: keep executing tool calls until the model responds with text
|
|
44
|
+
while (response.functionCalls && response.functionCalls.length > 0) {
|
|
45
|
+
const parts: Part[] = [];
|
|
46
|
+
for (const fc of response.functionCalls) {
|
|
47
|
+
const result = await composio.provider.executeToolCall('user_123', {
|
|
48
|
+
name: fc.name || '',
|
|
49
|
+
args: (fc.args || {}) as Record<string, unknown>,
|
|
50
|
+
});
|
|
51
|
+
parts.push({
|
|
52
|
+
functionResponse: {
|
|
53
|
+
id: fc.id,
|
|
54
|
+
name: fc.name,
|
|
55
|
+
response: JSON.parse(result),
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
response = await chat.sendMessage({ message: parts });
|
|
103
60
|
}
|
|
104
61
|
|
|
105
|
-
|
|
106
|
-
name: string;
|
|
107
|
-
description: string;
|
|
108
|
-
parameters: Schema;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
type GoogleGenAIToolCollection = GoogleTool[];
|
|
62
|
+
console.log(response.text);
|
|
112
63
|
```
|
|
113
64
|
|
|
114
|
-
##
|
|
115
|
-
|
|
116
|
-
We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
|
|
117
|
-
|
|
118
|
-
## License
|
|
65
|
+
## Tool execution
|
|
119
66
|
|
|
120
|
-
|
|
67
|
+
Gemini function calling is non-agentic; the model returns function calls and you execute them. `GoogleProvider` exposes `executeToolCall(userId, functionCall, options?, modifiers?)`, which takes a `{ name, args }` pair and returns the tool result as a JSON string. The constructor takes no options.
|
|
121
68
|
|
|
122
|
-
##
|
|
69
|
+
## Links
|
|
123
70
|
|
|
124
|
-
|
|
71
|
+
- [Google provider docs](https://docs.composio.dev/docs/providers/google)
|
|
72
|
+
- [Composio documentation](https://docs.composio.dev)
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { BaseNonAgenticProvider, ExecuteToolFnOptions, ExecuteToolModifiers, Mcp
|
|
|
2
2
|
import { FunctionDeclaration } from "@google/genai";
|
|
3
3
|
|
|
4
4
|
//#region src/index.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Interface for Google GenAI function declaration
|
|
8
7
|
* Based on the FunctionDeclaration type from @google/genai
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseNonAgenticProvider, normalizeToolArguments } from "@composio/core";
|
|
1
|
+
import { BaseNonAgenticProvider, deduplicateJsonSchemaRequiredArrays, normalizeToolArguments } from "@composio/core";
|
|
2
2
|
|
|
3
3
|
//#region src/index.ts
|
|
4
4
|
/**
|
|
@@ -90,14 +90,15 @@ var GoogleProvider = class extends BaseNonAgenticProvider {
|
|
|
90
90
|
* ```
|
|
91
91
|
*/
|
|
92
92
|
wrapTool(tool) {
|
|
93
|
+
const inputParameters = deduplicateJsonSchemaRequiredArrays(tool.inputParameters);
|
|
93
94
|
return {
|
|
94
95
|
name: tool.slug,
|
|
95
96
|
description: tool.description || "",
|
|
96
97
|
parameters: {
|
|
97
98
|
type: "object",
|
|
98
99
|
description: tool.description || "",
|
|
99
|
-
properties:
|
|
100
|
-
required:
|
|
100
|
+
properties: inputParameters?.properties || {},
|
|
101
|
+
required: inputParameters?.required || []
|
|
101
102
|
}
|
|
102
103
|
};
|
|
103
104
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composio/google",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Google GenAI Provider for Composio SDK",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
9
|
"url": "https://github.com/ComposioHQ/composio.git",
|
|
@@ -11,24 +12,14 @@
|
|
|
11
12
|
"bugs": {
|
|
12
13
|
"url": "https://github.com/ComposioHQ/composio/issues"
|
|
13
14
|
},
|
|
14
|
-
"homepage": "https://github.com/ComposioHQ/composio/tree/
|
|
15
|
+
"homepage": "https://github.com/ComposioHQ/composio/tree/next/ts/packages/providers/google#readme",
|
|
15
16
|
"publishConfig": {
|
|
16
17
|
"access": "public"
|
|
17
18
|
},
|
|
18
19
|
"exports": {
|
|
19
20
|
".": {
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"default": "./dist/index.mjs"
|
|
23
|
-
},
|
|
24
|
-
"require": {
|
|
25
|
-
"types": "./dist/index.d.cts",
|
|
26
|
-
"default": "./dist/index.cjs"
|
|
27
|
-
},
|
|
28
|
-
"default": {
|
|
29
|
-
"types": "./dist/index.d.cts",
|
|
30
|
-
"default": "./dist/index.cjs"
|
|
31
|
-
}
|
|
21
|
+
"types": "./dist/index.d.mts",
|
|
22
|
+
"default": "./dist/index.mjs"
|
|
32
23
|
}
|
|
33
24
|
},
|
|
34
25
|
"files": [
|
|
@@ -49,13 +40,13 @@
|
|
|
49
40
|
"@google/genai": "^1.1.0"
|
|
50
41
|
},
|
|
51
42
|
"devDependencies": {
|
|
52
|
-
"tsdown": "^0.
|
|
53
|
-
"typescript": "^
|
|
54
|
-
"@composio/core": "0.
|
|
43
|
+
"tsdown": "^0.22.3",
|
|
44
|
+
"typescript": "^6.0.3",
|
|
45
|
+
"@composio/core": "0.14.0"
|
|
55
46
|
},
|
|
56
47
|
"scripts": {
|
|
57
48
|
"clean": "git clean -xdf node_modules",
|
|
58
|
-
"build": "
|
|
49
|
+
"build": "tsdown",
|
|
59
50
|
"test": "vitest run"
|
|
60
51
|
},
|
|
61
52
|
"types": "dist/index.d.mts"
|
package/dist/index.cjs
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
let _composio_core = require("@composio/core");
|
|
2
|
-
|
|
3
|
-
//#region src/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* Google GenAI Provider
|
|
6
|
-
*
|
|
7
|
-
* This provider provides a set of tools for interacting with Google's GenAI API.
|
|
8
|
-
* It supports both the Gemini Developer API and Vertex AI implementations.
|
|
9
|
-
*
|
|
10
|
-
* @packageDocumentation
|
|
11
|
-
* @module providers/google
|
|
12
|
-
*/
|
|
13
|
-
/**
|
|
14
|
-
* Google GenAI Provider for Composio SDK
|
|
15
|
-
* Implements the BaseNonAgenticProvider to wrap Composio tools for use with Google's GenAI API
|
|
16
|
-
*/
|
|
17
|
-
var GoogleProvider = class extends _composio_core.BaseNonAgenticProvider {
|
|
18
|
-
name = "google";
|
|
19
|
-
/**
|
|
20
|
-
* Creates a new instance of the GoogleProvider.
|
|
21
|
-
*
|
|
22
|
-
* This provider enables integration with Google's GenAI API,
|
|
23
|
-
* supporting both the Gemini Developer API and Vertex AI implementations.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* // Initialize the Google provider
|
|
28
|
-
* const provider = new GoogleProvider();
|
|
29
|
-
*
|
|
30
|
-
* // Use with Composio
|
|
31
|
-
* const composio = new Composio({
|
|
32
|
-
* apiKey: 'your-api-key',
|
|
33
|
-
* provider: new GoogleProvider()
|
|
34
|
-
* });
|
|
35
|
-
*
|
|
36
|
-
* // Use the provider to wrap tools for Google GenAI
|
|
37
|
-
* const googleTools = provider.wrapTools(composioTools);
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
constructor() {
|
|
41
|
-
super();
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Transform MCP URL response into Anthropic-specific format.
|
|
45
|
-
* By default, Anthropic uses the standard format (same as default),
|
|
46
|
-
* but this method is here to show providers can customize if needed.
|
|
47
|
-
*
|
|
48
|
-
* @param data - The MCP URL response data
|
|
49
|
-
* @returns Standard MCP server response format
|
|
50
|
-
*/
|
|
51
|
-
wrapMcpServerResponse(data) {
|
|
52
|
-
return data.map((item) => ({
|
|
53
|
-
url: new URL(item.url),
|
|
54
|
-
name: item.name
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Wraps a Composio tool in the Google GenAI function declaration format.
|
|
59
|
-
*
|
|
60
|
-
* This method transforms a Composio tool definition into the format
|
|
61
|
-
* expected by Google's GenAI API for function calling.
|
|
62
|
-
*
|
|
63
|
-
* @param tool - The Composio tool to wrap
|
|
64
|
-
* @returns The wrapped tool in Google GenAI format
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* // Wrap a single tool for use with Google GenAI
|
|
69
|
-
* const composioTool = {
|
|
70
|
-
* slug: 'SEARCH_TOOL',
|
|
71
|
-
* description: 'Search for information',
|
|
72
|
-
* inputParameters: {
|
|
73
|
-
* type: 'object',
|
|
74
|
-
* properties: {
|
|
75
|
-
* query: { type: 'string' }
|
|
76
|
-
* },
|
|
77
|
-
* required: ['query']
|
|
78
|
-
* }
|
|
79
|
-
* };
|
|
80
|
-
*
|
|
81
|
-
* const googleTool = provider.wrapTool(composioTool);
|
|
82
|
-
* // Use with Google GenAI SDK
|
|
83
|
-
* const genAI = new GoogleGenerativeAI('YOUR_API_KEY');
|
|
84
|
-
* const model = genAI.getGenerativeModel({ model: 'gemini-pro' });
|
|
85
|
-
*
|
|
86
|
-
* const result = await model.generateContent({
|
|
87
|
-
* contents: [{ role: 'user', parts: [{ text: 'Search for Composio' }] }],
|
|
88
|
-
* tools: [googleTool]
|
|
89
|
-
* });
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
wrapTool(tool) {
|
|
93
|
-
return {
|
|
94
|
-
name: tool.slug,
|
|
95
|
-
description: tool.description || "",
|
|
96
|
-
parameters: {
|
|
97
|
-
type: "object",
|
|
98
|
-
description: tool.description || "",
|
|
99
|
-
properties: tool.inputParameters?.properties || {},
|
|
100
|
-
required: tool.inputParameters?.required || []
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Wraps a list of Composio tools in the Google GenAI function declaration format.
|
|
106
|
-
*
|
|
107
|
-
* This method transforms multiple Composio tool definitions into the format
|
|
108
|
-
* expected by Google's GenAI API for function calling.
|
|
109
|
-
*
|
|
110
|
-
* @param tools - Array of Composio tools to wrap
|
|
111
|
-
* @returns Array of wrapped tools in Google GenAI format
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* // Wrap multiple tools for use with Google GenAI
|
|
116
|
-
* const composioTools = [
|
|
117
|
-
* {
|
|
118
|
-
* slug: 'SEARCH_TOOL',
|
|
119
|
-
* description: 'Search for information',
|
|
120
|
-
* inputParameters: {
|
|
121
|
-
* type: 'object',
|
|
122
|
-
* properties: {
|
|
123
|
-
* query: { type: 'string' }
|
|
124
|
-
* },
|
|
125
|
-
* required: ['query']
|
|
126
|
-
* }
|
|
127
|
-
* },
|
|
128
|
-
* {
|
|
129
|
-
* slug: 'WEATHER_TOOL',
|
|
130
|
-
* description: 'Get weather information',
|
|
131
|
-
* inputParameters: {
|
|
132
|
-
* type: 'object',
|
|
133
|
-
* properties: {
|
|
134
|
-
* location: { type: 'string' }
|
|
135
|
-
* },
|
|
136
|
-
* required: ['location']
|
|
137
|
-
* }
|
|
138
|
-
* }
|
|
139
|
-
* ];
|
|
140
|
-
*
|
|
141
|
-
* const googleTools = provider.wrapTools(composioTools);
|
|
142
|
-
*
|
|
143
|
-
* // Use with Google GenAI SDK
|
|
144
|
-
* const genAI = new GoogleGenerativeAI('YOUR_API_KEY');
|
|
145
|
-
* const model = genAI.getGenerativeModel({ model: 'gemini-pro' });
|
|
146
|
-
*
|
|
147
|
-
* const result = await model.generateContent({
|
|
148
|
-
* contents: [{ role: 'user', parts: [{ text: 'How is the weather in New York?' }] }],
|
|
149
|
-
* tools: googleTools
|
|
150
|
-
* });
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
wrapTools(tools) {
|
|
154
|
-
return tools.map((tool) => this.wrapTool(tool));
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Executes a tool call from Google GenAI.
|
|
158
|
-
*
|
|
159
|
-
* This method processes a function call from Google's GenAI API,
|
|
160
|
-
* executes the corresponding Composio tool, and returns the result.
|
|
161
|
-
*
|
|
162
|
-
* @param userId - The user ID for authentication and tracking
|
|
163
|
-
* @param tool - The Google GenAI function call to execute
|
|
164
|
-
* @param options - Optional execution options like connected account ID
|
|
165
|
-
* @param modifiers - Optional execution modifiers for tool behavior
|
|
166
|
-
* @returns The result of the tool execution as a JSON string
|
|
167
|
-
*
|
|
168
|
-
* @example
|
|
169
|
-
* ```typescript
|
|
170
|
-
* // Execute a tool call from Google GenAI
|
|
171
|
-
* const functionCall = {
|
|
172
|
-
* name: 'SEARCH_TOOL',
|
|
173
|
-
* args: {
|
|
174
|
-
* query: 'composio documentation'
|
|
175
|
-
* }
|
|
176
|
-
* };
|
|
177
|
-
*
|
|
178
|
-
* const result = await provider.executeToolCall(
|
|
179
|
-
* 'user123',
|
|
180
|
-
* functionCall,
|
|
181
|
-
* { connectedAccountId: 'conn_xyz456' }
|
|
182
|
-
* );
|
|
183
|
-
*
|
|
184
|
-
* // Parse the result and use it in your application
|
|
185
|
-
* const searchResults = JSON.parse(result);
|
|
186
|
-
* console.log(searchResults);
|
|
187
|
-
*
|
|
188
|
-
* // You can also use the result to continue the conversation
|
|
189
|
-
* const genAI = new GoogleGenerativeAI('YOUR_API_KEY');
|
|
190
|
-
* const model = genAI.getGenerativeModel({ model: 'gemini-pro' });
|
|
191
|
-
*
|
|
192
|
-
* await model.generateContent({
|
|
193
|
-
* contents: [
|
|
194
|
-
* { role: 'user', parts: [{ text: 'Search for Composio' }] },
|
|
195
|
-
* { role: 'model', parts: [{ functionResponse: { name: 'SEARCH_TOOL', response: result } }] }
|
|
196
|
-
* ]
|
|
197
|
-
* });
|
|
198
|
-
* ```
|
|
199
|
-
*/
|
|
200
|
-
async executeToolCall(userId, tool, options, modifiers) {
|
|
201
|
-
const payload = {
|
|
202
|
-
arguments: (0, _composio_core.normalizeToolArguments)(tool.args, tool.name),
|
|
203
|
-
connectedAccountId: options?.connectedAccountId,
|
|
204
|
-
customAuthParams: options?.customAuthParams,
|
|
205
|
-
customConnectionData: options?.customConnectionData,
|
|
206
|
-
userId
|
|
207
|
-
};
|
|
208
|
-
const result = await this.executeTool(tool.name, payload, modifiers);
|
|
209
|
-
return JSON.stringify(result);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
//#endregion
|
|
214
|
-
exports.GoogleProvider = GoogleProvider;
|
package/dist/index.d.cts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { BaseNonAgenticProvider, ExecuteToolFnOptions, ExecuteToolModifiers, McpServerGetResponse, McpUrlResponse, Tool } from "@composio/core";
|
|
2
|
-
import { FunctionDeclaration } from "@google/genai";
|
|
3
|
-
|
|
4
|
-
//#region src/index.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Interface for Google GenAI function declaration
|
|
8
|
-
* Based on the FunctionDeclaration type from @google/genai
|
|
9
|
-
*/
|
|
10
|
-
type GoogleTool = FunctionDeclaration;
|
|
11
|
-
/**
|
|
12
|
-
* Interface for Google GenAI function call
|
|
13
|
-
* Based on the FunctionCall type from @google/genai
|
|
14
|
-
*/
|
|
15
|
-
interface GoogleGenAIFunctionCall {
|
|
16
|
-
name: string;
|
|
17
|
-
args: Record<string, unknown>;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Type for a collection of Google GenAI function declarations
|
|
21
|
-
*/
|
|
22
|
-
type GoogleGenAIToolCollection = GoogleTool[];
|
|
23
|
-
/**
|
|
24
|
-
* Google GenAI Provider for Composio SDK
|
|
25
|
-
* Implements the BaseNonAgenticProvider to wrap Composio tools for use with Google's GenAI API
|
|
26
|
-
*/
|
|
27
|
-
declare class GoogleProvider extends BaseNonAgenticProvider<GoogleGenAIToolCollection, GoogleTool, McpServerGetResponse> {
|
|
28
|
-
readonly name = "google";
|
|
29
|
-
/**
|
|
30
|
-
* Creates a new instance of the GoogleProvider.
|
|
31
|
-
*
|
|
32
|
-
* This provider enables integration with Google's GenAI API,
|
|
33
|
-
* supporting both the Gemini Developer API and Vertex AI implementations.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* // Initialize the Google provider
|
|
38
|
-
* const provider = new GoogleProvider();
|
|
39
|
-
*
|
|
40
|
-
* // Use with Composio
|
|
41
|
-
* const composio = new Composio({
|
|
42
|
-
* apiKey: 'your-api-key',
|
|
43
|
-
* provider: new GoogleProvider()
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* // Use the provider to wrap tools for Google GenAI
|
|
47
|
-
* const googleTools = provider.wrapTools(composioTools);
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
constructor();
|
|
51
|
-
/**
|
|
52
|
-
* Transform MCP URL response into Anthropic-specific format.
|
|
53
|
-
* By default, Anthropic uses the standard format (same as default),
|
|
54
|
-
* but this method is here to show providers can customize if needed.
|
|
55
|
-
*
|
|
56
|
-
* @param data - The MCP URL response data
|
|
57
|
-
* @returns Standard MCP server response format
|
|
58
|
-
*/
|
|
59
|
-
wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse;
|
|
60
|
-
/**
|
|
61
|
-
* Wraps a Composio tool in the Google GenAI function declaration format.
|
|
62
|
-
*
|
|
63
|
-
* This method transforms a Composio tool definition into the format
|
|
64
|
-
* expected by Google's GenAI API for function calling.
|
|
65
|
-
*
|
|
66
|
-
* @param tool - The Composio tool to wrap
|
|
67
|
-
* @returns The wrapped tool in Google GenAI format
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* // Wrap a single tool for use with Google GenAI
|
|
72
|
-
* const composioTool = {
|
|
73
|
-
* slug: 'SEARCH_TOOL',
|
|
74
|
-
* description: 'Search for information',
|
|
75
|
-
* inputParameters: {
|
|
76
|
-
* type: 'object',
|
|
77
|
-
* properties: {
|
|
78
|
-
* query: { type: 'string' }
|
|
79
|
-
* },
|
|
80
|
-
* required: ['query']
|
|
81
|
-
* }
|
|
82
|
-
* };
|
|
83
|
-
*
|
|
84
|
-
* const googleTool = provider.wrapTool(composioTool);
|
|
85
|
-
* // Use with Google GenAI SDK
|
|
86
|
-
* const genAI = new GoogleGenerativeAI('YOUR_API_KEY');
|
|
87
|
-
* const model = genAI.getGenerativeModel({ model: 'gemini-pro' });
|
|
88
|
-
*
|
|
89
|
-
* const result = await model.generateContent({
|
|
90
|
-
* contents: [{ role: 'user', parts: [{ text: 'Search for Composio' }] }],
|
|
91
|
-
* tools: [googleTool]
|
|
92
|
-
* });
|
|
93
|
-
* ```
|
|
94
|
-
*/
|
|
95
|
-
wrapTool(tool: Tool): GoogleTool;
|
|
96
|
-
/**
|
|
97
|
-
* Wraps a list of Composio tools in the Google GenAI function declaration format.
|
|
98
|
-
*
|
|
99
|
-
* This method transforms multiple Composio tool definitions into the format
|
|
100
|
-
* expected by Google's GenAI API for function calling.
|
|
101
|
-
*
|
|
102
|
-
* @param tools - Array of Composio tools to wrap
|
|
103
|
-
* @returns Array of wrapped tools in Google GenAI format
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* // Wrap multiple tools for use with Google GenAI
|
|
108
|
-
* const composioTools = [
|
|
109
|
-
* {
|
|
110
|
-
* slug: 'SEARCH_TOOL',
|
|
111
|
-
* description: 'Search for information',
|
|
112
|
-
* inputParameters: {
|
|
113
|
-
* type: 'object',
|
|
114
|
-
* properties: {
|
|
115
|
-
* query: { type: 'string' }
|
|
116
|
-
* },
|
|
117
|
-
* required: ['query']
|
|
118
|
-
* }
|
|
119
|
-
* },
|
|
120
|
-
* {
|
|
121
|
-
* slug: 'WEATHER_TOOL',
|
|
122
|
-
* description: 'Get weather information',
|
|
123
|
-
* inputParameters: {
|
|
124
|
-
* type: 'object',
|
|
125
|
-
* properties: {
|
|
126
|
-
* location: { type: 'string' }
|
|
127
|
-
* },
|
|
128
|
-
* required: ['location']
|
|
129
|
-
* }
|
|
130
|
-
* }
|
|
131
|
-
* ];
|
|
132
|
-
*
|
|
133
|
-
* const googleTools = provider.wrapTools(composioTools);
|
|
134
|
-
*
|
|
135
|
-
* // Use with Google GenAI SDK
|
|
136
|
-
* const genAI = new GoogleGenerativeAI('YOUR_API_KEY');
|
|
137
|
-
* const model = genAI.getGenerativeModel({ model: 'gemini-pro' });
|
|
138
|
-
*
|
|
139
|
-
* const result = await model.generateContent({
|
|
140
|
-
* contents: [{ role: 'user', parts: [{ text: 'How is the weather in New York?' }] }],
|
|
141
|
-
* tools: googleTools
|
|
142
|
-
* });
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
wrapTools(tools: Tool[]): GoogleGenAIToolCollection;
|
|
146
|
-
/**
|
|
147
|
-
* Executes a tool call from Google GenAI.
|
|
148
|
-
*
|
|
149
|
-
* This method processes a function call from Google's GenAI API,
|
|
150
|
-
* executes the corresponding Composio tool, and returns the result.
|
|
151
|
-
*
|
|
152
|
-
* @param userId - The user ID for authentication and tracking
|
|
153
|
-
* @param tool - The Google GenAI function call to execute
|
|
154
|
-
* @param options - Optional execution options like connected account ID
|
|
155
|
-
* @param modifiers - Optional execution modifiers for tool behavior
|
|
156
|
-
* @returns The result of the tool execution as a JSON string
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* ```typescript
|
|
160
|
-
* // Execute a tool call from Google GenAI
|
|
161
|
-
* const functionCall = {
|
|
162
|
-
* name: 'SEARCH_TOOL',
|
|
163
|
-
* args: {
|
|
164
|
-
* query: 'composio documentation'
|
|
165
|
-
* }
|
|
166
|
-
* };
|
|
167
|
-
*
|
|
168
|
-
* const result = await provider.executeToolCall(
|
|
169
|
-
* 'user123',
|
|
170
|
-
* functionCall,
|
|
171
|
-
* { connectedAccountId: 'conn_xyz456' }
|
|
172
|
-
* );
|
|
173
|
-
*
|
|
174
|
-
* // Parse the result and use it in your application
|
|
175
|
-
* const searchResults = JSON.parse(result);
|
|
176
|
-
* console.log(searchResults);
|
|
177
|
-
*
|
|
178
|
-
* // You can also use the result to continue the conversation
|
|
179
|
-
* const genAI = new GoogleGenerativeAI('YOUR_API_KEY');
|
|
180
|
-
* const model = genAI.getGenerativeModel({ model: 'gemini-pro' });
|
|
181
|
-
*
|
|
182
|
-
* await model.generateContent({
|
|
183
|
-
* contents: [
|
|
184
|
-
* { role: 'user', parts: [{ text: 'Search for Composio' }] },
|
|
185
|
-
* { role: 'model', parts: [{ functionResponse: { name: 'SEARCH_TOOL', response: result } }] }
|
|
186
|
-
* ]
|
|
187
|
-
* });
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
executeToolCall(userId: string, tool: GoogleGenAIFunctionCall, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<string>;
|
|
191
|
-
}
|
|
192
|
-
//#endregion
|
|
193
|
-
export { GoogleGenAIFunctionCall, GoogleGenAIToolCollection, GoogleProvider, GoogleTool };
|