@composio/cloudflare 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,224 +1,195 @@
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
- CloudflareProvider: () => CloudflareProvider
24
- });
25
- module.exports = __toCommonJS(index_exports);
26
- var import_core = require("@composio/core");
27
- var CloudflareProvider = class extends import_core.BaseNonAgenticProvider {
28
- name = "cloudflare";
29
- /**
30
- * Creates a new instance of the CloudflareProvider.
31
- *
32
- * This provider enables integration with Cloudflare AI,
33
- * allowing Composio tools to be used with Cloudflare Workers AI.
34
- *
35
- * @example
36
- * ```typescript
37
- *
38
- * // Use with Composio
39
- * const composio = new Composio({
40
- * apiKey: 'your-api-key',
41
- * provider: new CloudflareProvider()
42
- * });
43
- *
44
- * // Use the provider to wrap tools for Cloudflare AI
45
- * const cloudflareTools = provider.wrapTools(composioTools);
46
- * ```
47
- */
48
- constructor() {
49
- super();
50
- }
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) {
60
- return data.map((item) => ({
61
- url: new URL(item.url),
62
- name: item.name
63
- }));
64
- }
65
- /**
66
- * Wraps a Composio tool in the Cloudflare AI format.
67
- *
68
- * This method transforms a Composio tool definition into the format
69
- * expected by Cloudflare's AI API for function calling.
70
- *
71
- * @param tool - The Composio tool to wrap
72
- * @returns The wrapped tool in Cloudflare AI format
73
- *
74
- * @example
75
- * ```typescript
76
- * // Wrap a single tool for use with Cloudflare AI
77
- * const composioTool = {
78
- * slug: 'SEARCH_TOOL',
79
- * description: 'Search for information',
80
- * inputParameters: {
81
- * type: 'object',
82
- * properties: {
83
- * query: { type: 'string', description: 'Search query' }
84
- * },
85
- * required: ['query']
86
- * }
87
- * };
88
- *
89
- * const cloudflareTool = provider.wrapTool(composioTool);
90
- * ```
91
- */
92
- wrapTool(tool) {
93
- const formattedSchema = {
94
- name: tool.slug,
95
- description: tool.description,
96
- parameters: tool.inputParameters
97
- };
98
- const cloudflareTool = {
99
- type: "function",
100
- function: formattedSchema
101
- };
102
- return cloudflareTool;
103
- }
104
- /**
105
- * Wraps a list of Composio tools in the Cloudflare AI format.
106
- *
107
- * This method transforms multiple Composio tool definitions into the format
108
- * expected by Cloudflare's AI API for function calling, organizing them
109
- * into a dictionary keyed by tool slug.
110
- *
111
- * @param tools - Array of Composio tools to wrap
112
- * @returns Dictionary of wrapped tools in Cloudflare AI format
113
- *
114
- * @example
115
- * ```typescript
116
- * // Wrap multiple tools for use with Cloudflare AI
117
- * const composioTools = [
118
- * {
119
- * slug: 'SEARCH_TOOL',
120
- * description: 'Search for information',
121
- * inputParameters: {
122
- * type: 'object',
123
- * properties: {
124
- * query: { type: 'string' }
125
- * },
126
- * required: ['query']
127
- * }
128
- * },
129
- * {
130
- * slug: 'WEATHER_TOOL',
131
- * description: 'Get weather information',
132
- * inputParameters: {
133
- * type: 'object',
134
- * properties: {
135
- * location: { type: 'string' }
136
- * },
137
- * required: ['location']
138
- * }
139
- * }
140
- * ];
141
- *
142
- * const cloudflareTools = provider.wrapTools(composioTools);
143
- *
144
- * // Use with Cloudflare Workers AI
145
- * // In your Cloudflare Worker:
146
- * const ai = new Ai(env.AI);
147
- *
148
- * const response = await ai.run('@cf/meta/llama-3-8b-instruct', {
149
- * messages: [{ role: 'user', content: 'How is the weather in New York?' }],
150
- * tools: cloudflareTools
151
- * });
152
- * ```
153
- */
154
- wrapTools(tools) {
155
- return tools.reduce(
156
- (acc, tool) => ({
157
- ...acc,
158
- [tool.slug]: this.wrapTool(tool)
159
- }),
160
- {}
161
- );
162
- }
163
- /**
164
- * Executes a tool call from Cloudflare AI.
165
- *
166
- * This method processes a function call from Cloudflare's AI API,
167
- * executes the corresponding Composio tool, and returns the result.
168
- *
169
- * @param userId - The user ID for authentication and tracking
170
- * @param tool - The tool call object with name and arguments
171
- * @param options - Optional execution options like connected account ID
172
- * @param modifiers - Optional execution modifiers for tool behavior
173
- * @returns The result of the tool execution as a JSON string
174
- *
175
- * @example
176
- * ```typescript
177
- * // Execute a tool call from Cloudflare AI
178
- * const toolCall = {
179
- * name: 'SEARCH_TOOL',
180
- * arguments: {
181
- * query: 'composio documentation'
182
- * }
183
- * };
184
- *
185
- * const result = await provider.executeToolCall(
186
- * 'user123',
187
- * toolCall,
188
- * { connectedAccountId: 'conn_xyz456' }
189
- * );
190
- *
191
- * // Parse the result and use it in your application
192
- * const searchResults = JSON.parse(result);
193
- * console.log(searchResults);
194
- *
195
- * // You can also use the result to continue the conversation
196
- * // In your Cloudflare Worker:
197
- * const ai = new Ai(env.AI);
198
- *
199
- * await ai.run('@cf/meta/llama-3-8b-instruct', {
200
- * messages: [
201
- * { role: 'user', content: 'Search for Composio' },
202
- * { role: 'assistant', content: '', tool_calls: [{ name: 'SEARCH_TOOL', arguments: JSON.stringify({ query: 'composio documentation' }) }] },
203
- * { role: 'tool', tool_call_id: '1', content: result }
204
- * ],
205
- * tools: cloudflareTools
206
- * });
207
- * ```
208
- */
209
- async executeToolCall(userId, tool, options, modifiers) {
210
- const payload = {
211
- arguments: typeof tool.arguments === "string" ? JSON.parse(tool.arguments) : tool.arguments,
212
- connectedAccountId: options.connectedAccountId,
213
- customAuthParams: options.customAuthParams,
214
- customConnectionData: options.customConnectionData,
215
- userId
216
- };
217
- const result = await this.executeTool(tool.name, payload, modifiers);
218
- return JSON.stringify(result);
219
- }
3
+ //#region src/index.ts
4
+ var CloudflareProvider = class extends _composio_core.BaseNonAgenticProvider {
5
+ name = "cloudflare";
6
+ /**
7
+ * Creates a new instance of the CloudflareProvider.
8
+ *
9
+ * This provider enables integration with Cloudflare AI,
10
+ * allowing Composio tools to be used with Cloudflare Workers AI.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ *
15
+ * // Use with Composio
16
+ * const composio = new Composio({
17
+ * apiKey: 'your-api-key',
18
+ * provider: new CloudflareProvider()
19
+ * });
20
+ *
21
+ * // Use the provider to wrap tools for Cloudflare AI
22
+ * const cloudflareTools = provider.wrapTools(composioTools);
23
+ * ```
24
+ */
25
+ constructor() {
26
+ super();
27
+ }
28
+ /**
29
+ * Transform MCP URL response into Anthropic-specific format.
30
+ * By default, Anthropic uses the standard format (same as default),
31
+ * but this method is here to show providers can customize if needed.
32
+ *
33
+ * @param data - The MCP URL response data
34
+ * @returns Standard MCP server response format
35
+ */
36
+ wrapMcpServerResponse(data) {
37
+ return data.map((item) => ({
38
+ url: new URL(item.url),
39
+ name: item.name
40
+ }));
41
+ }
42
+ /**
43
+ * Wraps a Composio tool in the Cloudflare AI format.
44
+ *
45
+ * This method transforms a Composio tool definition into the format
46
+ * expected by Cloudflare's AI API for function calling.
47
+ *
48
+ * @param tool - The Composio tool to wrap
49
+ * @returns The wrapped tool in Cloudflare AI format
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * // Wrap a single tool for use with Cloudflare AI
54
+ * const composioTool = {
55
+ * slug: 'SEARCH_TOOL',
56
+ * description: 'Search for information',
57
+ * inputParameters: {
58
+ * type: 'object',
59
+ * properties: {
60
+ * query: { type: 'string', description: 'Search query' }
61
+ * },
62
+ * required: ['query']
63
+ * }
64
+ * };
65
+ *
66
+ * const cloudflareTool = provider.wrapTool(composioTool);
67
+ * ```
68
+ */
69
+ wrapTool(tool) {
70
+ return {
71
+ type: "function",
72
+ function: {
73
+ name: tool.slug,
74
+ description: tool.description,
75
+ parameters: tool.inputParameters
76
+ }
77
+ };
78
+ }
79
+ /**
80
+ * Wraps a list of Composio tools in the Cloudflare AI format.
81
+ *
82
+ * This method transforms multiple Composio tool definitions into the format
83
+ * expected by Cloudflare's AI API for function calling, organizing them
84
+ * into a dictionary keyed by tool slug.
85
+ *
86
+ * @param tools - Array of Composio tools to wrap
87
+ * @returns Dictionary of wrapped tools in Cloudflare AI format
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * // Wrap multiple tools for use with Cloudflare AI
92
+ * const composioTools = [
93
+ * {
94
+ * slug: 'SEARCH_TOOL',
95
+ * description: 'Search for information',
96
+ * inputParameters: {
97
+ * type: 'object',
98
+ * properties: {
99
+ * query: { type: 'string' }
100
+ * },
101
+ * required: ['query']
102
+ * }
103
+ * },
104
+ * {
105
+ * slug: 'WEATHER_TOOL',
106
+ * description: 'Get weather information',
107
+ * inputParameters: {
108
+ * type: 'object',
109
+ * properties: {
110
+ * location: { type: 'string' }
111
+ * },
112
+ * required: ['location']
113
+ * }
114
+ * }
115
+ * ];
116
+ *
117
+ * const cloudflareTools = provider.wrapTools(composioTools);
118
+ *
119
+ * // Use with Cloudflare Workers AI
120
+ * // In your Cloudflare Worker:
121
+ * const ai = new Ai(env.AI);
122
+ *
123
+ * const response = await ai.run('@cf/meta/llama-3-8b-instruct', {
124
+ * messages: [{ role: 'user', content: 'How is the weather in New York?' }],
125
+ * tools: cloudflareTools
126
+ * });
127
+ * ```
128
+ */
129
+ wrapTools(tools) {
130
+ return tools.reduce((acc, tool) => ({
131
+ ...acc,
132
+ [tool.slug]: this.wrapTool(tool)
133
+ }), {});
134
+ }
135
+ /**
136
+ * Executes a tool call from Cloudflare AI.
137
+ *
138
+ * This method processes a function call from Cloudflare's AI API,
139
+ * executes the corresponding Composio tool, and returns the result.
140
+ *
141
+ * @param userId - The user ID for authentication and tracking
142
+ * @param tool - The tool call object with name and arguments
143
+ * @param options - Optional execution options like connected account ID
144
+ * @param modifiers - Optional execution modifiers for tool behavior
145
+ * @returns The result of the tool execution as a JSON string
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * // Execute a tool call from Cloudflare AI
150
+ * const toolCall = {
151
+ * name: 'SEARCH_TOOL',
152
+ * arguments: {
153
+ * query: 'composio documentation'
154
+ * }
155
+ * };
156
+ *
157
+ * const result = await provider.executeToolCall(
158
+ * 'user123',
159
+ * toolCall,
160
+ * { connectedAccountId: 'conn_xyz456' }
161
+ * );
162
+ *
163
+ * // Parse the result and use it in your application
164
+ * const searchResults = JSON.parse(result);
165
+ * console.log(searchResults);
166
+ *
167
+ * // You can also use the result to continue the conversation
168
+ * // In your Cloudflare Worker:
169
+ * const ai = new Ai(env.AI);
170
+ *
171
+ * await ai.run('@cf/meta/llama-3-8b-instruct', {
172
+ * messages: [
173
+ * { role: 'user', content: 'Search for Composio' },
174
+ * { role: 'assistant', content: '', tool_calls: [{ name: 'SEARCH_TOOL', arguments: JSON.stringify({ query: 'composio documentation' }) }] },
175
+ * { role: 'tool', tool_call_id: '1', content: result }
176
+ * ],
177
+ * tools: cloudflareTools
178
+ * });
179
+ * ```
180
+ */
181
+ async executeToolCall(userId, tool, options, modifiers) {
182
+ const payload = {
183
+ arguments: typeof tool.arguments === "string" ? JSON.parse(tool.arguments) : tool.arguments,
184
+ connectedAccountId: options.connectedAccountId,
185
+ customAuthParams: options.customAuthParams,
186
+ customConnectionData: options.customConnectionData,
187
+ userId
188
+ };
189
+ const result = await this.executeTool(tool.name, payload, modifiers);
190
+ return JSON.stringify(result);
191
+ }
220
192
  };
221
- // Annotate the CommonJS export names for ESM import in node:
222
- 0 && (module.exports = {
223
- CloudflareProvider
224
- });
193
+
194
+ //#endregion
195
+ exports.CloudflareProvider = CloudflareProvider;