@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 +193 -222
- package/dist/index.d.cts +5126 -169
- package/dist/index.d.mts +5136 -0
- package/dist/index.mjs +195 -0
- package/package.json +19 -11
- package/dist/index.d.ts +0 -179
- package/dist/index.js +0 -201
package/dist/index.cjs
CHANGED
|
@@ -1,224 +1,195 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
});
|
|
193
|
+
|
|
194
|
+
//#endregion
|
|
195
|
+
exports.CloudflareProvider = CloudflareProvider;
|