@composio/google 0.4.0 → 0.5.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/dist/index.cjs CHANGED
@@ -1,225 +1,214 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ let _composio_core = require("@composio/core");
19
2
 
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- GoogleProvider: () => GoogleProvider
24
- });
25
- module.exports = __toCommonJS(index_exports);
26
- var import_core = require("@composio/core");
27
- var GoogleProvider = class extends import_core.BaseNonAgenticProvider {
28
- 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
- super();
52
- }
53
- /**
54
- * Transform MCP URL response into Anthropic-specific format.
55
- * By default, Anthropic uses the standard format (same as default),
56
- * but this method is here to show providers can customize if needed.
57
- *
58
- * @param data - The MCP URL response data
59
- * @returns Standard MCP server response format
60
- */
61
- wrapMcpServerResponse(data) {
62
- return data.map((item) => ({
63
- url: new URL(item.url),
64
- name: item.name
65
- }));
66
- }
67
- /**
68
- * Wraps a Composio tool in the Google GenAI function declaration format.
69
- *
70
- * This method transforms a Composio tool definition into the format
71
- * expected by Google's GenAI API for function calling.
72
- *
73
- * @param tool - The Composio tool to wrap
74
- * @returns The wrapped tool in Google GenAI format
75
- *
76
- * @example
77
- * ```typescript
78
- * // Wrap a single tool for use with Google GenAI
79
- * const composioTool = {
80
- * slug: 'SEARCH_TOOL',
81
- * description: 'Search for information',
82
- * inputParameters: {
83
- * type: 'object',
84
- * properties: {
85
- * query: { type: 'string' }
86
- * },
87
- * required: ['query']
88
- * }
89
- * };
90
- *
91
- * const googleTool = provider.wrapTool(composioTool);
92
- * // Use with Google GenAI SDK
93
- * const genAI = new GoogleGenerativeAI('YOUR_API_KEY');
94
- * const model = genAI.getGenerativeModel({ model: 'gemini-pro' });
95
- *
96
- * const result = await model.generateContent({
97
- * contents: [{ role: 'user', parts: [{ text: 'Search for Composio' }] }],
98
- * tools: [googleTool]
99
- * });
100
- * ```
101
- */
102
- wrapTool(tool) {
103
- return {
104
- name: tool.slug,
105
- description: tool.description || "",
106
- parameters: {
107
- type: "object",
108
- description: tool.description || "",
109
- properties: tool.inputParameters?.properties || {},
110
- required: tool.inputParameters?.required || []
111
- }
112
- };
113
- }
114
- /**
115
- * Wraps a list of Composio tools in the Google GenAI function declaration format.
116
- *
117
- * This method transforms multiple Composio tool definitions into the format
118
- * expected by Google's GenAI API for function calling.
119
- *
120
- * @param tools - Array of Composio tools to wrap
121
- * @returns Array of wrapped tools in Google GenAI format
122
- *
123
- * @example
124
- * ```typescript
125
- * // Wrap multiple tools for use with Google GenAI
126
- * const composioTools = [
127
- * {
128
- * slug: 'SEARCH_TOOL',
129
- * description: 'Search for information',
130
- * inputParameters: {
131
- * type: 'object',
132
- * properties: {
133
- * query: { type: 'string' }
134
- * },
135
- * required: ['query']
136
- * }
137
- * },
138
- * {
139
- * slug: 'WEATHER_TOOL',
140
- * description: 'Get weather information',
141
- * inputParameters: {
142
- * type: 'object',
143
- * properties: {
144
- * location: { type: 'string' }
145
- * },
146
- * required: ['location']
147
- * }
148
- * }
149
- * ];
150
- *
151
- * const googleTools = provider.wrapTools(composioTools);
152
- *
153
- * // Use with Google GenAI SDK
154
- * const genAI = new GoogleGenerativeAI('YOUR_API_KEY');
155
- * const model = genAI.getGenerativeModel({ model: 'gemini-pro' });
156
- *
157
- * const result = await model.generateContent({
158
- * contents: [{ role: 'user', parts: [{ text: 'How is the weather in New York?' }] }],
159
- * tools: googleTools
160
- * });
161
- * ```
162
- */
163
- wrapTools(tools) {
164
- return tools.map((tool) => this.wrapTool(tool));
165
- }
166
- /**
167
- * Executes a tool call from Google GenAI.
168
- *
169
- * This method processes a function call from Google's GenAI API,
170
- * executes the corresponding Composio tool, and returns the result.
171
- *
172
- * @param userId - The user ID for authentication and tracking
173
- * @param tool - The Google GenAI function call to execute
174
- * @param options - Optional execution options like connected account ID
175
- * @param modifiers - Optional execution modifiers for tool behavior
176
- * @returns The result of the tool execution as a JSON string
177
- *
178
- * @example
179
- * ```typescript
180
- * // Execute a tool call from Google GenAI
181
- * const functionCall = {
182
- * name: 'SEARCH_TOOL',
183
- * args: {
184
- * query: 'composio documentation'
185
- * }
186
- * };
187
- *
188
- * const result = await provider.executeToolCall(
189
- * 'user123',
190
- * functionCall,
191
- * { connectedAccountId: 'conn_xyz456' }
192
- * );
193
- *
194
- * // Parse the result and use it in your application
195
- * const searchResults = JSON.parse(result);
196
- * console.log(searchResults);
197
- *
198
- * // You can also use the result to continue the conversation
199
- * const genAI = new GoogleGenerativeAI('YOUR_API_KEY');
200
- * const model = genAI.getGenerativeModel({ model: 'gemini-pro' });
201
- *
202
- * await model.generateContent({
203
- * contents: [
204
- * { role: 'user', parts: [{ text: 'Search for Composio' }] },
205
- * { role: 'model', parts: [{ functionResponse: { name: 'SEARCH_TOOL', response: result } }] }
206
- * ]
207
- * });
208
- * ```
209
- */
210
- async executeToolCall(userId, tool, options, modifiers) {
211
- const payload = {
212
- arguments: tool.args,
213
- connectedAccountId: options?.connectedAccountId,
214
- customAuthParams: options?.customAuthParams,
215
- customConnectionData: options?.customConnectionData,
216
- userId
217
- };
218
- const result = await this.executeTool(tool.name, payload, modifiers);
219
- return JSON.stringify(result);
220
- }
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: tool.args,
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
+ }
221
211
  };
222
- // Annotate the CommonJS export names for ESM import in node:
223
- 0 && (module.exports = {
224
- GoogleProvider
225
- });
212
+
213
+ //#endregion
214
+ exports.GoogleProvider = GoogleProvider;