@composio/cloudflare 0.4.0 → 0.5.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.
package/dist/index.mjs ADDED
@@ -0,0 +1,195 @@
1
+ import { BaseNonAgenticProvider } from "@composio/core";
2
+
3
+ //#region src/index.ts
4
+ var CloudflareProvider = class extends 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
+ }
192
+ };
193
+
194
+ //#endregion
195
+ export { CloudflareProvider };
package/package.json CHANGED
@@ -1,17 +1,25 @@
1
1
  {
2
2
  "name": "@composio/cloudflare",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "",
5
- "main": "dist/index.js",
6
- "type": "module",
5
+ "main": "dist/index.mjs",
7
6
  "publishConfig": {
8
7
  "access": "public"
9
8
  },
10
9
  "exports": {
11
10
  ".": {
12
- "import": "./dist/index.js",
13
- "types": "./dist/index.d.ts",
14
- "require": "./dist/index.cjs"
11
+ "import": {
12
+ "types": "./dist/index.d.mts",
13
+ "default": "./dist/index.mjs"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ },
19
+ "default": {
20
+ "types": "./dist/index.d.cts",
21
+ "default": "./dist/index.cjs"
22
+ }
15
23
  }
16
24
  },
17
25
  "files": [
@@ -23,19 +31,19 @@
23
31
  "license": "ISC",
24
32
  "peerDependencies": {
25
33
  "@cloudflare/workers-types": "^4.20250917.0",
26
- "@composio/core": "0.4.0"
34
+ "@composio/core": "0.5.0"
27
35
  },
28
36
  "devDependencies": {
29
- "tsup": "^8.5.0",
37
+ "tsdown": "^0.18.4",
30
38
  "typescript": "^5.9.2",
31
39
  "vitest": "^3.2.4",
32
- "@composio/core": "0.4.0"
40
+ "@composio/core": "0.5.0"
33
41
  },
34
42
  "gitHead": "4fae6e54d5c150fba955cc5fa314281da5a1e064",
35
43
  "scripts": {
36
44
  "clean": "git clean -xdf node_modules",
37
- "build": "tsup",
45
+ "build": "tsdown",
38
46
  "test": "vitest run"
39
47
  },
40
- "types": "dist/index.d.ts"
48
+ "types": "dist/index.d.mts"
41
49
  }
package/dist/index.d.ts DELETED
@@ -1,179 +0,0 @@
1
- import { AiTextGenerationToolInput } from '@cloudflare/workers-types';
2
- import { BaseNonAgenticProvider, McpServerGetResponse, McpUrlResponse, Tool, ExecuteToolFnOptions, ExecuteToolModifiers } from '@composio/core';
3
-
4
- /**
5
- * Cloudflare AI Provider
6
- *
7
- * Author: Musthaq Ahamad <musthaq@composio.dev>
8
- * Legacy Reference: https://github.com/ComposioHQ/composio/blob/master/js/src/frameworks/cloudflare.ts
9
- *
10
- * This provider provides a set of tools for interacting with Cloudflare AI.
11
- *
12
- * @packageDocumentation
13
- * @module providers/cloudflare
14
- */
15
-
16
- type AiToolCollection = Record<string, AiTextGenerationToolInput>;
17
- declare class CloudflareProvider extends BaseNonAgenticProvider<AiToolCollection, AiTextGenerationToolInput, McpServerGetResponse> {
18
- readonly name = "cloudflare";
19
- /**
20
- * Creates a new instance of the CloudflareProvider.
21
- *
22
- * This provider enables integration with Cloudflare AI,
23
- * allowing Composio tools to be used with Cloudflare Workers AI.
24
- *
25
- * @example
26
- * ```typescript
27
- *
28
- * // Use with Composio
29
- * const composio = new Composio({
30
- * apiKey: 'your-api-key',
31
- * provider: new CloudflareProvider()
32
- * });
33
- *
34
- * // Use the provider to wrap tools for Cloudflare AI
35
- * const cloudflareTools = provider.wrapTools(composioTools);
36
- * ```
37
- */
38
- constructor();
39
- /**
40
- * Transform MCP URL response into Anthropic-specific format.
41
- * By default, Anthropic uses the standard format (same as default),
42
- * but this method is here to show providers can customize if needed.
43
- *
44
- * @param data - The MCP URL response data
45
- * @returns Standard MCP server response format
46
- */
47
- wrapMcpServerResponse(data: McpUrlResponse): McpServerGetResponse;
48
- /**
49
- * Wraps a Composio tool in the Cloudflare AI format.
50
- *
51
- * This method transforms a Composio tool definition into the format
52
- * expected by Cloudflare's AI API for function calling.
53
- *
54
- * @param tool - The Composio tool to wrap
55
- * @returns The wrapped tool in Cloudflare AI format
56
- *
57
- * @example
58
- * ```typescript
59
- * // Wrap a single tool for use with Cloudflare AI
60
- * const composioTool = {
61
- * slug: 'SEARCH_TOOL',
62
- * description: 'Search for information',
63
- * inputParameters: {
64
- * type: 'object',
65
- * properties: {
66
- * query: { type: 'string', description: 'Search query' }
67
- * },
68
- * required: ['query']
69
- * }
70
- * };
71
- *
72
- * const cloudflareTool = provider.wrapTool(composioTool);
73
- * ```
74
- */
75
- wrapTool(tool: Tool): AiTextGenerationToolInput;
76
- /**
77
- * Wraps a list of Composio tools in the Cloudflare AI format.
78
- *
79
- * This method transforms multiple Composio tool definitions into the format
80
- * expected by Cloudflare's AI API for function calling, organizing them
81
- * into a dictionary keyed by tool slug.
82
- *
83
- * @param tools - Array of Composio tools to wrap
84
- * @returns Dictionary of wrapped tools in Cloudflare AI format
85
- *
86
- * @example
87
- * ```typescript
88
- * // Wrap multiple tools for use with Cloudflare AI
89
- * const composioTools = [
90
- * {
91
- * slug: 'SEARCH_TOOL',
92
- * description: 'Search for information',
93
- * inputParameters: {
94
- * type: 'object',
95
- * properties: {
96
- * query: { type: 'string' }
97
- * },
98
- * required: ['query']
99
- * }
100
- * },
101
- * {
102
- * slug: 'WEATHER_TOOL',
103
- * description: 'Get weather information',
104
- * inputParameters: {
105
- * type: 'object',
106
- * properties: {
107
- * location: { type: 'string' }
108
- * },
109
- * required: ['location']
110
- * }
111
- * }
112
- * ];
113
- *
114
- * const cloudflareTools = provider.wrapTools(composioTools);
115
- *
116
- * // Use with Cloudflare Workers AI
117
- * // In your Cloudflare Worker:
118
- * const ai = new Ai(env.AI);
119
- *
120
- * const response = await ai.run('@cf/meta/llama-3-8b-instruct', {
121
- * messages: [{ role: 'user', content: 'How is the weather in New York?' }],
122
- * tools: cloudflareTools
123
- * });
124
- * ```
125
- */
126
- wrapTools(tools: Tool[]): AiToolCollection;
127
- /**
128
- * Executes a tool call from Cloudflare AI.
129
- *
130
- * This method processes a function call from Cloudflare's AI API,
131
- * executes the corresponding Composio tool, and returns the result.
132
- *
133
- * @param userId - The user ID for authentication and tracking
134
- * @param tool - The tool call object with name and arguments
135
- * @param options - Optional execution options like connected account ID
136
- * @param modifiers - Optional execution modifiers for tool behavior
137
- * @returns The result of the tool execution as a JSON string
138
- *
139
- * @example
140
- * ```typescript
141
- * // Execute a tool call from Cloudflare AI
142
- * const toolCall = {
143
- * name: 'SEARCH_TOOL',
144
- * arguments: {
145
- * query: 'composio documentation'
146
- * }
147
- * };
148
- *
149
- * const result = await provider.executeToolCall(
150
- * 'user123',
151
- * toolCall,
152
- * { connectedAccountId: 'conn_xyz456' }
153
- * );
154
- *
155
- * // Parse the result and use it in your application
156
- * const searchResults = JSON.parse(result);
157
- * console.log(searchResults);
158
- *
159
- * // You can also use the result to continue the conversation
160
- * // In your Cloudflare Worker:
161
- * const ai = new Ai(env.AI);
162
- *
163
- * await ai.run('@cf/meta/llama-3-8b-instruct', {
164
- * messages: [
165
- * { role: 'user', content: 'Search for Composio' },
166
- * { role: 'assistant', content: '', tool_calls: [{ name: 'SEARCH_TOOL', arguments: JSON.stringify({ query: 'composio documentation' }) }] },
167
- * { role: 'tool', tool_call_id: '1', content: result }
168
- * ],
169
- * tools: cloudflareTools
170
- * });
171
- * ```
172
- */
173
- executeToolCall(userId: string, tool: {
174
- name: string;
175
- arguments: unknown;
176
- }, options: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<string>;
177
- }
178
-
179
- export { CloudflareProvider };
package/dist/index.js DELETED
@@ -1,201 +0,0 @@
1
- // src/index.ts
2
- import {
3
- BaseNonAgenticProvider
4
- } from "@composio/core";
5
- var CloudflareProvider = class extends BaseNonAgenticProvider {
6
- name = "cloudflare";
7
- /**
8
- * Creates a new instance of the CloudflareProvider.
9
- *
10
- * This provider enables integration with Cloudflare AI,
11
- * allowing Composio tools to be used with Cloudflare Workers AI.
12
- *
13
- * @example
14
- * ```typescript
15
- *
16
- * // Use with Composio
17
- * const composio = new Composio({
18
- * apiKey: 'your-api-key',
19
- * provider: new CloudflareProvider()
20
- * });
21
- *
22
- * // Use the provider to wrap tools for Cloudflare AI
23
- * const cloudflareTools = provider.wrapTools(composioTools);
24
- * ```
25
- */
26
- constructor() {
27
- super();
28
- }
29
- /**
30
- * Transform MCP URL response into Anthropic-specific format.
31
- * By default, Anthropic uses the standard format (same as default),
32
- * but this method is here to show providers can customize if needed.
33
- *
34
- * @param data - The MCP URL response data
35
- * @returns Standard MCP server response format
36
- */
37
- wrapMcpServerResponse(data) {
38
- return data.map((item) => ({
39
- url: new URL(item.url),
40
- name: item.name
41
- }));
42
- }
43
- /**
44
- * Wraps a Composio tool in the Cloudflare AI format.
45
- *
46
- * This method transforms a Composio tool definition into the format
47
- * expected by Cloudflare's AI API for function calling.
48
- *
49
- * @param tool - The Composio tool to wrap
50
- * @returns The wrapped tool in Cloudflare AI format
51
- *
52
- * @example
53
- * ```typescript
54
- * // Wrap a single tool for use with Cloudflare AI
55
- * const composioTool = {
56
- * slug: 'SEARCH_TOOL',
57
- * description: 'Search for information',
58
- * inputParameters: {
59
- * type: 'object',
60
- * properties: {
61
- * query: { type: 'string', description: 'Search query' }
62
- * },
63
- * required: ['query']
64
- * }
65
- * };
66
- *
67
- * const cloudflareTool = provider.wrapTool(composioTool);
68
- * ```
69
- */
70
- wrapTool(tool) {
71
- const formattedSchema = {
72
- name: tool.slug,
73
- description: tool.description,
74
- parameters: tool.inputParameters
75
- };
76
- const cloudflareTool = {
77
- type: "function",
78
- function: formattedSchema
79
- };
80
- return cloudflareTool;
81
- }
82
- /**
83
- * Wraps a list of Composio tools in the Cloudflare AI format.
84
- *
85
- * This method transforms multiple Composio tool definitions into the format
86
- * expected by Cloudflare's AI API for function calling, organizing them
87
- * into a dictionary keyed by tool slug.
88
- *
89
- * @param tools - Array of Composio tools to wrap
90
- * @returns Dictionary of wrapped tools in Cloudflare AI format
91
- *
92
- * @example
93
- * ```typescript
94
- * // Wrap multiple tools for use with Cloudflare AI
95
- * const composioTools = [
96
- * {
97
- * slug: 'SEARCH_TOOL',
98
- * description: 'Search for information',
99
- * inputParameters: {
100
- * type: 'object',
101
- * properties: {
102
- * query: { type: 'string' }
103
- * },
104
- * required: ['query']
105
- * }
106
- * },
107
- * {
108
- * slug: 'WEATHER_TOOL',
109
- * description: 'Get weather information',
110
- * inputParameters: {
111
- * type: 'object',
112
- * properties: {
113
- * location: { type: 'string' }
114
- * },
115
- * required: ['location']
116
- * }
117
- * }
118
- * ];
119
- *
120
- * const cloudflareTools = provider.wrapTools(composioTools);
121
- *
122
- * // Use with Cloudflare Workers AI
123
- * // In your Cloudflare Worker:
124
- * const ai = new Ai(env.AI);
125
- *
126
- * const response = await ai.run('@cf/meta/llama-3-8b-instruct', {
127
- * messages: [{ role: 'user', content: 'How is the weather in New York?' }],
128
- * tools: cloudflareTools
129
- * });
130
- * ```
131
- */
132
- wrapTools(tools) {
133
- return tools.reduce(
134
- (acc, tool) => ({
135
- ...acc,
136
- [tool.slug]: this.wrapTool(tool)
137
- }),
138
- {}
139
- );
140
- }
141
- /**
142
- * Executes a tool call from Cloudflare AI.
143
- *
144
- * This method processes a function call from Cloudflare's AI API,
145
- * executes the corresponding Composio tool, and returns the result.
146
- *
147
- * @param userId - The user ID for authentication and tracking
148
- * @param tool - The tool call object with name and arguments
149
- * @param options - Optional execution options like connected account ID
150
- * @param modifiers - Optional execution modifiers for tool behavior
151
- * @returns The result of the tool execution as a JSON string
152
- *
153
- * @example
154
- * ```typescript
155
- * // Execute a tool call from Cloudflare AI
156
- * const toolCall = {
157
- * name: 'SEARCH_TOOL',
158
- * arguments: {
159
- * query: 'composio documentation'
160
- * }
161
- * };
162
- *
163
- * const result = await provider.executeToolCall(
164
- * 'user123',
165
- * toolCall,
166
- * { connectedAccountId: 'conn_xyz456' }
167
- * );
168
- *
169
- * // Parse the result and use it in your application
170
- * const searchResults = JSON.parse(result);
171
- * console.log(searchResults);
172
- *
173
- * // You can also use the result to continue the conversation
174
- * // In your Cloudflare Worker:
175
- * const ai = new Ai(env.AI);
176
- *
177
- * await ai.run('@cf/meta/llama-3-8b-instruct', {
178
- * messages: [
179
- * { role: 'user', content: 'Search for Composio' },
180
- * { role: 'assistant', content: '', tool_calls: [{ name: 'SEARCH_TOOL', arguments: JSON.stringify({ query: 'composio documentation' }) }] },
181
- * { role: 'tool', tool_call_id: '1', content: result }
182
- * ],
183
- * tools: cloudflareTools
184
- * });
185
- * ```
186
- */
187
- async executeToolCall(userId, tool, options, modifiers) {
188
- const payload = {
189
- arguments: typeof tool.arguments === "string" ? JSON.parse(tool.arguments) : tool.arguments,
190
- connectedAccountId: options.connectedAccountId,
191
- customAuthParams: options.customAuthParams,
192
- customConnectionData: options.customConnectionData,
193
- userId
194
- };
195
- const result = await this.executeTool(tool.name, payload, modifiers);
196
- return JSON.stringify(result);
197
- }
198
- };
199
- export {
200
- CloudflareProvider
201
- };