@composio/core 0.13.1 → 0.14.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.
Files changed (57) hide show
  1. package/README.md +62 -247
  2. package/dist/BaseProvider-lCxnjFKQ.d.mts +29395 -0
  3. package/dist/{CustomTool-D9qwyMrv.mjs → CustomTool-C_5NvBsX.mjs} +17 -15
  4. package/dist/{CustomTool-DLf7JeKt.d.mts → CustomTool-CmokRT9q.d.mts} +1 -1
  5. package/dist/{FileModifierErrors-3fSwIWoa.mjs → SsrfErrors-BQRozkeU.mjs} +33 -1
  6. package/dist/{Telemetry-DhGI_J4G.mjs → Telemetry-llfvticE.mjs} +40 -8
  7. package/dist/{jsonSchema-CFKdONpP.mjs → cancellation-W65QRyj2.mjs} +64 -19
  8. package/dist/{composio-BHSQwOUz.d.mts → composio-6C8kHtqc.d.mts} +827 -808
  9. package/dist/{customTool.types-9yFqPjdw.d.mts → customTool.types-kFhNYuzh.d.mts} +502 -502
  10. package/dist/docs/reference/sdk-reference/typescript/index.mdx +1 -22
  11. package/dist/{errors-DSIlYfl5.mjs → errors-B165yJUQ.mjs} +74 -74
  12. package/dist/experimental/index.d.mts +2 -2
  13. package/dist/experimental/index.mjs +1 -1
  14. package/dist/{fileUtils.node-BiO1JQsJ.mjs → fileUtils.node-iPFi2o4i.mjs} +182 -68
  15. package/dist/index.d.mts +1451 -1400
  16. package/dist/index.mjs +1408 -1378
  17. package/dist/models/Files.node.mjs +2 -2
  18. package/dist/platform/node.d.mts +1 -1
  19. package/dist/platform/node.mjs +3 -0
  20. package/dist/platform/workerd.d.mts +1 -1
  21. package/dist/platform/workerd.mjs +3 -0
  22. package/dist/sensitiveFileUploadPaths-B1OLsd8F.mjs +114 -0
  23. package/dist/{types-DdoCRzLj.d.mts → types-DY1r-kN9.d.mts} +9 -0
  24. package/dist/{types-BJLCRj9q.d.mts → types-yCrveqAj.d.mts} +2 -2
  25. package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
  26. package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
  27. package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
  28. package/dist/utils/modifiers/FileToolModifier.node.mjs +5 -5
  29. package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
  30. package/package.json +10 -10
  31. package/src/errors/SsrfErrors.ts +47 -0
  32. package/src/errors/index.ts +3 -0
  33. package/src/index.ts +10 -0
  34. package/src/models/CustomTool.ts +1 -3
  35. package/src/models/ToolRouterSession.ts +38 -16
  36. package/src/models/Tools.ts +32 -2
  37. package/src/models/Triggers.ts +16 -76
  38. package/src/platform/node.ts +4 -0
  39. package/src/platform/types.ts +10 -0
  40. package/src/platform/workerd.ts +6 -0
  41. package/src/provider/OpenAIProvider.ts +19 -14
  42. package/src/telemetry/Telemetry.ts +9 -6
  43. package/src/telemetry/redact.ts +40 -0
  44. package/src/types/tool.types.ts +36 -32
  45. package/src/utils/fileUtils.node.ts +27 -4
  46. package/src/utils/jsonSchema.ts +58 -0
  47. package/src/utils/modifiers/FileToolModifier.node.ts +2 -1
  48. package/src/utils/sdk.ts +5 -4
  49. package/src/utils/{sensitiveFileUploadPaths.node.ts → sensitiveFileUploadPaths.ts} +29 -13
  50. package/src/utils/ssrfGuard.node.ts +202 -0
  51. package/src/utils/toolkitVersion.ts +21 -2
  52. package/dist/BaseProvider-Brb3o86-.d.mts +0 -29425
  53. package/dist/CustomTool-NpHpqdnU.d.mts +0 -74
  54. package/dist/buffer-PcbMMsgm.mjs +0 -33
  55. package/dist/composio-DfPD7BAi.d.mts +0 -5666
  56. package/dist/customTool.types-D-6YqFdW.d.mts +0 -2826
  57. package/dist/types-CCh8qvui.d.mts +0 -12
package/README.md CHANGED
@@ -1,304 +1,119 @@
1
- ![Composio Banner](https://github.com/user-attachments/assets/9ba0e9c1-85a4-4b51-ae60-f9fe7992e819)
2
-
3
1
  # @composio/core
4
2
 
5
- The core Composio SDK which allows users to interact with the Composio Platform. It provides a powerful and flexible way to manage and execute tools, handle authentication, and integrate with various platforms and frameworks.
6
-
7
- [Learn more about the SDK from our docs](https://docs.composio.dev)
3
+ The Composio SDK for TypeScript. Create a session for one of your users, hand its tools to your agent, and let the agent take action across 1000+ apps with authentication handled for you.
8
4
 
9
- ## Core Features
10
-
11
- - **Tools**: Manage and execute tools within the Composio ecosystem. Includes functionality to list, retrieve, and execute tools.
12
- - **Toolkits**: Organize and manage collections of tools for specific use cases.
13
- - **Triggers**: Create and manage event triggers that can execute tools based on specific conditions.
14
- - **AuthConfigs**: Configure authentication providers and settings.
15
- - **ConnectedAccounts**: Manage third-party service connections.
16
- - **ActionExecution**: Track and manage the execution of actions within the platform.
5
+ Full documentation lives at [docs.composio.dev](https://docs.composio.dev). This package intentionally ships its TypeScript source and SDK docs so the installed package is inspectable by coding agents; if you want a smaller install with the same API, use [`@composio/slim`](https://www.npmjs.com/package/@composio/slim).
17
6
 
18
7
  ## Installation
19
8
 
20
9
  ```bash
21
10
  npm install @composio/core
22
- # or
23
- yarn add @composio/core
24
- # or
25
- pnpm add @composio/core
26
11
  ```
27
12
 
28
- ## Getting Started
13
+ ## Quickstart
29
14
 
30
- ### Basic Usage with OpenAI Provider
15
+ Grab a `COMPOSIO_API_KEY` from the [dashboard](https://dashboard.composio.dev/settings), then create a session:
31
16
 
32
17
  ```typescript
33
18
  import { Composio } from '@composio/core';
34
- import { OpenAI } from 'openai';
35
-
36
- // Initialize OpenAI client
37
- const openai = new OpenAI({
38
- apiKey: process.env.OPENAI_API_KEY,
39
- });
40
-
41
- // Initialize Composio with your API key
42
- const composio = new Composio({
43
- apiKey: process.env.COMPOSIO_API_KEY,
44
- });
45
-
46
- async function main() {
47
- try {
48
- // Fetch tools - single tool or multiple tools
49
- const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
50
- // Or fetch multiple tools: await composio.tools.get('default', { toolkits: ['hackernews'] });
51
-
52
- const query = "Find information about the HackerNews user 'pg'";
53
-
54
- // Create chat completion with tools
55
- const response = await openai.chat.completions.create({
56
- model: 'gpt-4o',
57
- messages: [
58
- {
59
- role: 'system',
60
- content: 'You are a helpful assistant that can use tools to answer questions.',
61
- },
62
- { role: 'user', content: query },
63
- ],
64
- tools: tools,
65
- tool_choice: 'auto',
66
- });
67
-
68
- // Handle tool calls if the assistant decides to use them
69
- if (response.choices[0].message.tool_calls) {
70
- console.log(
71
- '🔧 Assistant is using tool:',
72
- response.choices[0].message.tool_calls[0].function.name
73
- );
74
-
75
- // Execute the tool call
76
- const toolResult = await composio.provider.executeToolCall(
77
- 'default',
78
- response.choices[0].message.tool_calls[0],
79
- {
80
- connectedAccountId: '', // Optional: specify connected account
81
- }
82
- );
83
-
84
- console.log('✅ Tool execution result:', JSON.parse(toolResult));
85
-
86
- // Get final response from assistant with tool result
87
- const finalResponse = await openai.chat.completions.create({
88
- model: 'gpt-4o',
89
- messages: [
90
- {
91
- role: 'system',
92
- content: 'You are a helpful assistant that can use tools to answer questions.',
93
- },
94
- { role: 'user', content: query },
95
- response.choices[0].message,
96
- {
97
- role: 'tool',
98
- tool_call_id: response.choices[0].message.tool_calls[0].id,
99
- content: toolResult,
100
- },
101
- ],
102
- });
103
-
104
- console.log('🤖 Final response:', finalResponse.choices[0].message.content);
105
- } else {
106
- console.log('🤖 Response:', response.choices[0].message.content);
107
- }
108
- } catch (error) {
109
- console.error('❌ Error:', error);
110
- }
111
- }
112
-
113
- main();
114
- ```
115
-
116
- ## Configuration
117
19
 
118
- The Composio constructor accepts the following configuration options:
20
+ const composio = new Composio({ apiKey: process.env.COMPOSIO_API_KEY });
119
21
 
120
- ```typescript
121
- interface ComposioConfig {
122
- apiKey?: string | null; // Your Composio API key
123
- baseURL?: string | null; // Custom API base URL (optional)
124
- allowTracking?: boolean; // Enable/disable telemetry (default: true)
125
- dangerouslyAllowAutoUploadDownloadFiles?: boolean; // Opt-in for automatic file upload/download during tool execution (default: false)
126
- provider?: TProvider; // Custom provider (default: OpenAIProvider)
127
- host?: string; // Name of the host service which is using the SDK, this is for telemetry
128
- defaultHeaders?: ComposioRequestHeaders; // Request headers to be passed to the Composio API client
129
- disableVersionCheck?: boolean; // Whether to disable version check for the Composio SDK (default: false)
130
- }
131
- ```
132
-
133
- ## Modifiers
134
-
135
- Composio SDK supports powerful modifiers to transform tool schemas and execution behavior.
136
-
137
- ### Schema Modifiers
138
-
139
- Schema modifiers allow you to transform tool schemas before they are used:
140
-
141
- ```typescript
142
- const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
143
- modifySchema: ({ toolSlug, toolkitSlug, schema }) => ({
144
- ...tool,
145
- description: 'Enhanced HackerNews search with additional features',
146
- inputParameters: {
147
- ...tool.inputParameters,
148
- limit: {
149
- type: 'number',
150
- description: 'Maximum number of posts to return',
151
- default: 10,
152
- },
153
- },
154
- }),
155
- });
22
+ // Each session is scoped to one of your users
23
+ const session = await composio.create('user_123');
24
+ const tools = await session.tools();
156
25
  ```
157
26
 
158
- ### Execution Modifiers
27
+ By default a session gives your agent a small set of meta tools that discover, authenticate, and execute app tools at runtime, so you never load hundreds of tool definitions into context. Without a provider configured, `session.tools()` returns OpenAI function-calling format.
159
28
 
160
- For agentic providers (like Vercel AI and Langchain), you can also modify tool execution behavior:
29
+ Sessions persist on the server. For multi-turn conversations, store `session.sessionId` and reuse it instead of calling `create()` again:
161
30
 
162
31
  ```typescript
163
- const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
164
- // Transform input before execution
165
- beforeExecute: ({ toolSlug, toolkitSlug, params }) => ({
166
- ...params,
167
- arguments: {
168
- ...params.arguments,
169
- limit: Math.min((params.arguments?.limit as number) || 10, 100),
170
- },
171
- }),
172
-
173
- // Transform output after execution
174
- afterExecute: ({ toolSlug, toolkitSlug, result }) => ({
175
- ...response,
176
- data: {
177
- ...response.data,
178
- posts: (response.data?.posts as any[]).map(post => ({
179
- ...post,
180
- url: post.url || `https://news.ycombinator.com/item?id=${post.id}`,
181
- })),
182
- },
183
- }),
184
- });
32
+ const session = await composio.use(sessionId);
185
33
  ```
186
34
 
187
- ## Connected Accounts
35
+ See [what a session is](https://docs.composio.dev/docs/how-composio-works) and [configuring sessions](https://docs.composio.dev/docs/configuring-sessions) for restricting toolkits, auth configs, and connected accounts.
188
36
 
189
- Composio SDK provides a powerful way to manage third-party service connections through Connected Accounts. This feature allows you to authenticate with various services and maintain those connections.
37
+ ## Providers
190
38
 
191
- ### Creating a Connected Account
39
+ A provider formats session tools for your agent framework and wires up execution:
192
40
 
193
41
  ```typescript
194
42
  import { Composio } from '@composio/core';
43
+ import { OpenAIAgentsProvider } from '@composio/openai-agents';
195
44
 
196
- const composio = new Composio({
197
- apiKey: process.env.COMPOSIO_API_KEY,
198
- });
45
+ const composio = new Composio({ provider: new OpenAIAgentsProvider() });
199
46
 
200
- // Create a connected account
201
- const connectionRequest = await composio.connectedAccounts.initiate(
202
- 'user123', // userId
203
- 'ac_12343544', // authConfigId: You can create it from the dashboard
204
- {
205
- callbackUrl: 'https://your-app.com/callback',
206
- data: {
207
- // Additional data for the connection
208
- scope: ['read', 'write'],
209
- },
210
- }
211
- );
212
-
213
- // Wait for the connection to be established
214
- // Default timeout is 60 seconds
215
- const connectedAccount = await connectionRequest.waitForConnection();
216
- console.log({ connectedAccount });
47
+ const session = await composio.create('user_123');
48
+ const tools = await session.tools(); // ready to pass to the OpenAI Agents SDK
217
49
  ```
218
50
 
219
- ### Waiting for Connection Establishment
51
+ Adapters exist for OpenAI, OpenAI Agents, Anthropic, Claude Agent SDK, Vercel AI SDK, Google GenAI, LangChain, LlamaIndex, Mastra, and Cloudflare Workers AI. See the [provider table](https://github.com/ComposioHQ/composio#providers) and the [framework quickstarts](https://docs.composio.dev/docs/quickstart).
220
52
 
221
- The `waitForConnection` method is available on both the `ConnectionRequest` and `ConnectedAccounts` classes. It allows you to poll for a connection to become active:
53
+ ## MCP
54
+
55
+ Every session also exposes a hosted MCP endpoint. Pass `mcp: true` to surface it in the type, then point Claude, Cursor, or any MCP client at it:
222
56
 
223
57
  ```typescript
224
- // From a ConnectionRequest instance (returned by createConnectedAccount)
225
- const connectedAccount = await connectionRequest.waitForConnection(120000); // 2 minute timeout
58
+ const session = await composio.create('user_123', { mcp: true });
226
59
 
227
- // From the ConnectedAccounts class (using a connected account ID)
228
- const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_abc123', 60000); // 1 minute timeout
60
+ console.log(session.mcp.url);
61
+ console.log(session.mcp.headers);
229
62
  ```
230
63
 
231
- The method continuously polls the Composio API until the connection:
232
-
233
- - Becomes `ACTIVE` (returns the connected account)
234
- - Enters a terminal state like `FAILED`, `EXPIRED`, or `DELETED` (throws an error)
235
- - Exceeds the specified timeout (throws a timeout error)
64
+ See [sessions via MCP](https://docs.composio.dev/docs/sessions-via-mcp).
236
65
 
237
- If the connection does not complete within the provided timeout (default: 60 seconds), a `ConnectionRequestTimeoutError` is thrown.
66
+ ## Modifiers
238
67
 
239
- ### Managing Connected Accounts
68
+ `session.tools()` accepts modifiers to transform tool schemas and intercept execution:
240
69
 
241
70
  ```typescript
242
- // List all connected accounts
243
- const accounts = await composio.connectedAccounts.list({
244
- userId: 'user123',
71
+ const tools = await session.tools({
72
+ modifySchema: ({ toolSlug, toolkitSlug, schema }) => ({
73
+ ...schema,
74
+ description: `${schema.description} (via my-app)`,
75
+ }),
76
+ beforeExecute: ({ toolSlug, toolkitSlug, params }) => params,
77
+ afterExecute: ({ toolSlug, toolkitSlug, result }) => result,
245
78
  });
246
-
247
- // Get a specific connected account
248
- const account = await composio.connectedAccounts.get('account_id');
249
-
250
- // Enable/Disable a connected account
251
- await composio.connectedAccounts.enable('account_id');
252
- await composio.connectedAccounts.disable('account_id');
253
-
254
- // Refresh credentials
255
- await composio.connectedAccounts.refresh('account_id');
256
-
257
- // Delete a connected account
258
- await composio.connectedAccounts.delete('account_id');
259
79
  ```
260
80
 
261
- ### Connection Statuses
81
+ See [modify tool behavior](https://docs.composio.dev/docs/tools-direct/modify-tool-behavior/schema-modifiers).
262
82
 
263
- Connected accounts can have the following statuses:
83
+ ## Configuration
264
84
 
265
- - `ACTIVE`: Connection is established and working
266
- - `INACTIVE`: Connection is temporarily disabled
267
- - `PENDING`: Connection is being processed
268
- - `INITIATED`: Connection request has started
269
- - `EXPIRED`: Connection credentials have expired
270
- - `FAILED`: Connection attempt failed
85
+ The `Composio` constructor accepts:
271
86
 
272
- ### Authentication Schemes
87
+ ```typescript
88
+ interface ComposioConfig {
89
+ apiKey?: string | null; // Defaults to COMPOSIO_API_KEY
90
+ baseURL?: string | null; // Custom API base URL
91
+ provider?: TProvider; // Provider adapter (default: OpenAIProvider)
92
+ allowTracking?: boolean; // Enable/disable telemetry (default: true)
93
+ defaultHeaders?: ComposioRequestHeaders; // Extra headers for API requests
94
+ disableVersionCheck?: boolean; // Skip the SDK version check (default: false)
95
+ dangerouslyAllowAutoUploadDownloadFiles?: boolean; // Auto file upload/download during execution (default: false)
96
+ }
97
+ ```
273
98
 
274
- Composio supports various authentication schemes:
99
+ Environment variables:
275
100
 
276
- - OAuth2
277
- - OAuth1
278
- - OAuth1a
279
- - API Key
280
- - Basic Auth
281
- - Bearer Token
282
- - Google Service Account
283
- - And more...
101
+ - `COMPOSIO_API_KEY`: your Composio API key
102
+ - `COMPOSIO_BASE_URL`: custom API base URL
103
+ - `COMPOSIO_LOG_LEVEL`: `silent`, `error`, `warn`, `info`, or `debug`
104
+ - `COMPOSIO_TOOLKIT_VERSION_<TOOLKIT>`: pin a toolkit version, e.g. `COMPOSIO_TOOLKIT_VERSION_GITHUB=20250902_00`
284
105
 
285
- ## Environment Variables
106
+ ## Beyond sessions
286
107
 
287
- - `COMPOSIO_API_KEY`: Your Composio API key
288
- - `COMPOSIO_BASE_URL`: Custom API base URL
289
- - `COMPOSIO_LOGGING_LEVEL`: Logging level (silent, error, warn, info, debug)
290
- - `DEVELOPMENT`: Development mode flag
291
- - `COMPOSIO_TOOLKIT_VERSION_<TOOLKITNAME>`: Version of the specific tool
292
- - `CI`: CI environment flag
108
+ The `Composio` instance also exposes `composio.toolkits`, `composio.triggers`, `composio.authConfigs`, and `composio.connectedAccounts` for managing resources outside a session. The older [direct tool execution](https://docs.composio.dev/docs/tools-direct/executing-tools) flow (`composio.tools.get` and `composio.tools.execute`) still works but is legacy; prefer sessions for new code.
293
109
 
294
- ## Contributing
110
+ ## Support
295
111
 
296
- We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
112
+ - [Documentation](https://docs.composio.dev)
113
+ - [TypeScript SDK reference](https://docs.composio.dev/reference/sdk-reference/typescript)
114
+ - [Discord community](https://discord.gg/composio)
115
+ - [Open an issue](https://github.com/ComposioHQ/composio/issues)
297
116
 
298
117
  ## License
299
118
 
300
- ISC License
301
-
302
- ## Support
303
-
304
- For support, please visit our [Documentation](https://docs.composio.dev) or join our [Discord Community](https://discord.gg/composio).
119
+ MIT