@devries-cameron20 / composio-1 / commits / 8063a2747
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Fix imports

haxzie committed May 15, 2025 at 15:03 UTC 8063a274755d0ac5eca12ef82719053f93b4c8c9
5 files changed +126 -100
README.md
+115 -91
@@ -1,18 +1,20 @@
1 # @composio/core
2
3 -The core Composio SDK which allows users to interact with the Composio Platform.
3 +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.
4
5 ## Core Features
6
7 - **Tools**: Manage and execute tools within the Composio ecosystem. Includes functionality to list, retrieve, and execute tools.
8 - **Toolkits**: Organize and manage collections of tools for specific use cases.
9 -- **Triggers**: Create and manage event triggers that can execute tools based on specific conditions. Includes support for different trigger types and status management.
10 -- **AuthConfigs**: Configure authentication providers and settings. Manage auth configs with features to create, update, enable/disable, and delete configurations.
11 -- **ConnectedAccounts**: Manage third-party service connections. Includes functionality to create, list, refresh, and manage the status of connected accounts.
9 +- **Triggers**: Create and manage event triggers that can execute tools based on specific conditions.
10 +- **AuthConfigs**: Configure authentication providers and settings.
11 +- **ConnectedAccounts**: Manage third-party service connections.
12 - **ActionExecution**: Track and manage the execution of actions within the platform.
13
14 ## Installation
15
16 +### Core SDK
17 +
18 ```bash
19 npm install @composio/core
20 # or
@@ -21,94 +23,100 @@ yarn add @composio/core
23 pnpm add @composio/core
24 ```
25
24 -## Configuration
25 -
26 -```typescript
27 -interface ComposioConfig {
28 - apiKey?: string; // Your Composio API key
29 - baseURL?: string; // Custom API base URL (optional)
30 - allowTracking?: boolean; // Enable/disable telemetry (default: true)
31 - allowTracing?: boolean; // Enable/disable tracing (default: true)
32 - toolset?: TToolset; // Custom toolset (default: OpenAIToolset)
33 - telemetryTransport?: BaseTelemetryTransport; // Custom telemetry transport
34 -}
26 +### Toolsets
27
36 -const composio = new Composio({
37 - apiKey: process.env.COMPOSIO_API_KEY,
38 - toolset: new OpenAIToolset(), // Optional: defaults to OpenAIToolset
39 -});
40 -```
28 +```bash
29 +# Install OpenAI toolset (included in core)
30 +npm install @composio/openai
31
42 -## Toolsets
32 +# Install Vercel AI toolset
33 +npm install @composio/vercel
34
44 -Composio SDK supports two types of toolsets, each with different modifier capabilities:
35 +# Install Langchain toolset
36 +npm install @composio/langchain
37 +```
38
46 -### 1. Non-Agentic Toolsets
39 +## Getting Started
40
48 -These toolsets only support schema modifiers for transforming tool schemas. They are suitable for simple integrations like OpenAI, Anthropic, etc.
41 +### Basic Usage with OpenAI Toolset
42
43 ```typescript
44 import { Composio } from '@composio/core';
45 import { OpenAIToolset } from '@composio/openai-toolset';
53 -import type { Tool } from '@composio/core';
46
47 const composio = new Composio({
48 apiKey: process.env.COMPOSIO_API_KEY,
49 + // OpenAIToolset is the default, so this is optional
50 toolset: new OpenAIToolset(),
51 });
52
60 -// Get a tool with schema modifiers
61 -const tool = await composio.getToolBySlug('user123', 'HACKERNEWS_SEARCH_POSTS', {
62 - modifyToolSchema: (toolSlug: string, tool: Tool) => ({
63 - ...tool,
64 - description: 'Search HackerNews posts with improved description',
65 - inputParameters: {
66 - ...tool.inputParameters,
67 - limit: {
68 - type: 'number',
69 - description: 'Maximum number of posts to return',
70 - },
71 - },
72 - }),
53 +// Fetch a single tool
54 +const searchTool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS');
55 +
56 +// Fetch multiple tools
57 +const tools = await composio.tools.get('user123', {
58 + category: 'search',
59 + limit: 10,
60 });
61 ```
62
76 -### 2. Agentic Toolsets
77 -
78 -These toolsets support full modifier capabilities, making them suitable for complex integrations like Vercel, Langchain, etc. They support:
79 -
80 -1. **Schema Modifiers**: Transform tool schemas using `modifyToolSchema`
81 -2. **Execution Modifiers**: Transform tool execution behavior
82 - - `beforeToolExecute`: Transform input parameters before execution
83 - - `afterToolExecute`: Transform output after execution
63 +## Using with a Toolset
64
85 -Example:
65 +### Example with Vercel AI Toolset
66
67 ```typescript
68 import { Composio } from '@composio/core';
69 import { VercelToolset } from '@composio/vercel-toolset';
90 -import type { Tool, ToolExecuteParams, ToolExecuteResponse } from '@composio/core';
70
71 const composio = new Composio({
72 apiKey: process.env.COMPOSIO_API_KEY,
73 toolset: new VercelToolset(),
74 });
75
97 -// Get a tool with full modifier support
98 -const tool = await composio.getToolBySlug('user123', 'HACKERNEWS_SEARCH_POSTS', {
99 - // Schema modifier
76 +// Fetch tools for Vercel AI SDK
77 +const tools = await composio.tools.get('user123', {
78 + category: 'search',
79 +});
80 +
81 +// Use tools with Vercel AI SDK
82 +const completion = await ai.chat({
83 + messages: [{ role: 'user', content: 'Search for posts about React' }],
84 + tools: tools,
85 +});
86 +```
87 +
88 +## Modifiers
89 +
90 +Composio SDK supports powerful modifiers to transform tool schemas and execution behavior.
91 +
92 +### Schema Modifiers
93 +
94 +Schema modifiers allow you to transform tool schemas before they are used:
95 +
96 +```typescript
97 +const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
98 modifyToolSchema: (toolSlug: string, tool: Tool) => ({
99 ...tool,
102 - description: 'Search HackerNews posts with improved description',
100 + description: 'Enhanced HackerNews search with additional features',
101 inputParameters: {
102 ...tool.inputParameters,
103 limit: {
104 type: 'number',
105 description: 'Maximum number of posts to return',
106 + default: 10,
107 },
108 },
109 }),
111 - // Execution modifiers
110 +});
111 +```
112 +
113 +### Execution Modifiers
114 +
115 +For agentic toolsets (like Vercel AI and Langchain), you can also modify tool execution behavior:
116 +
117 +```typescript
118 +const tool = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
119 + // Transform input before execution
120 beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
121 ...params,
122 arguments: {
@@ -116,6 +124,8 @@ const tool = await composio.getToolBySlug('user123', 'HACKERNEWS_SEARCH_POSTS',
124 limit: Math.min((params.arguments?.limit as number) || 10, 100),
125 },
126 }),
127 +
128 + // Transform output after execution
129 afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
130 ...response,
131 data: {
@@ -129,75 +139,89 @@ const tool = await composio.getToolBySlug('user123', 'HACKERNEWS_SEARCH_POSTS',
139 });
140 ```
141
132 -## Creating a Custom Toolset
142 +## Development
143 +
144 +### Creating Custom Toolsets
145
134 -To create a new toolset, extend either `BaseNonAgenticToolset` or `BaseAgenticToolset` from `@composio/core`:
146 +You can create custom toolsets by extending either `BaseNonAgenticToolset` or `BaseAgenticToolset`:
147 +
148 +#### Non-Agentic Toolset
149
150 ```typescript
151 import { BaseNonAgenticToolset } from '@composio/core';
138 -import type { Tool, ToolListParams, ToolOptions } from '@composio/core';
152 +import type { Tool } from '@composio/core';
153
154 interface CustomTool {
155 name: string;
156 // ... custom tool properties
157 }
158
145 -export class CustomToolset extends BaseNonAgenticToolset<Array<CustomTool>, CustomTool> {
146 - readonly FILE_NAME: string = 'custom/toolset.ts';
159 +export class CustomToolset extends BaseNonAgenticToolset<CustomTool[], CustomTool> {
160 + readonly name = 'custom-toolset';
161
148 - wrapTool = (tool: Tool): CustomTool => {
149 - return {
150 - name: tool.name,
151 - // ... map other properties
152 - };
153 - };
162 + wrapTool = (tool: Tool): CustomTool => ({
163 + name: tool.name,
164 + // ... map other properties
165 + });
166
155 - async getTools(
156 - userId: string,
157 - params?: ToolListParams,
158 - options?: ToolOptions
159 - ): Promise<Array<CustomTool>> {
160 - const tools = await this.getComposio().tools.getComposioTools(
161 - userId,
162 - params,
163 - options?.modifyToolSchema
164 - );
165 - return tools?.map(tool => this.wrapTool(tool)) ?? [];
166 - }
167 + wrapTools = (tools: Tool[]): CustomTool[] => tools.map(tool => this.wrapTool(tool));
168 +}
169 +```
170 +
171 +#### Agentic Toolset
172 +
173 +```typescript
174 +import { BaseAgenticToolset } from '@composio/core';
175 +import type { Tool, ToolExecuteParams, ToolExecuteResponse } from '@composio/core';
176
168 - async getToolBySlug(userId: string, slug: string, options?: ToolOptions): Promise<CustomTool> {
169 - const tool = await this.getComposio().tools.getComposioToolBySlug(
170 - userId,
171 - slug,
172 - options?.modifyToolSchema
177 +export class CustomAgenticToolset extends BaseAgenticToolset<CustomTool[], CustomTool> {
178 + readonly name = 'custom-agentic-toolset';
179 +
180 + wrapTool = (tool: Tool): CustomTool => ({
181 + name: tool.name,
182 + // ... map other properties
183 + });
184 +
185 + wrapTools = (tools: Tool[]): CustomTool[] => tools.map(tool => this.wrapTool(tool));
186 +
187 + async executeToolCall(
188 + userId: string,
189 + tool: { name: string; arguments: unknown },
190 + options: ExecuteToolFnOptions,
191 + modifiers?: ExecuteToolModifiers
192 + ): Promise<string> {
193 + const result = await this.executeTool(
194 + tool.name,
195 + {
196 + arguments: tool.arguments,
197 + userId,
198 + ...options,
199 + },
200 + modifiers
201 );
174 - return this.wrapTool(tool);
202 + return JSON.stringify(result);
203 }
204 }
205 ```
206
179 -To quickly create a toolset project, use the provided script:
207 +To quickly create a new toolset project, use the provided script:
208
209 ```bash
182 -# Create a non-agentic toolset (default)
183 -pnpm run create-toolset <your-toolset-name>
210 +# Create a non-agentic toolset
211 +pnpm create-toolset my-toolset
212
213 # Create an agentic toolset
186 -pnpm run create-toolset <your-toolset-name> --agentic
214 +pnpm create-toolset my-toolset --agentic
215 ```
216
217 ## Environment Variables
218
219 - `COMPOSIO_API_KEY`: Your Composio API key
192 -- `COMPOSIO_BASE_URL`: Custom API base URL
220 +- `COMPOSIO_BASE_URL`: Custom API base URL (optional)
221 - `COMPOSIO_LOGGING_LEVEL`: Logging level (silent, error, warn, info, debug)
222 - `DEVELOPMENT`: Development mode flag
223 - `CI`: CI environment flag
224
197 -## Contributing
198 -
199 -We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
200 -
225 ## License
226
227 ISC License
packages/core/src/index.ts
+2 -2
@@ -9,8 +9,8 @@ export {
9 export { OpenAIToolset } from './toolset/OpenAIToolset';
10 export { BaseTelemetryTransport } from './telemetry/TelemetryTransport';
11 export { jsonSchemaToModel } from './utils/jsonSchema';
12 -export { Tool, ToolListParams, ToolListParamsSchema } from './types/tool.types';
13 -export { Toolset } from './types/toolset.types';
12 +export { Tool, ToolListParams, ToolListParamsSchema, ToolExecuteParams } from './types/tool.types';
13 +export { Toolset, ExecuteToolFn, ExecuteToolFnOptions } from './types/toolset.types';
14 export { ExecuteMetadata } from './types/customTool.types';
15 // Type exports
16 export type {
packages/toolsets/cloudflare/src/index.ts
+7 -3
@@ -10,9 +10,13 @@
10 * @module toolsets/cloudflare
11 */
12 import { AiTextGenerationToolInput } from '@cloudflare/workers-types';
13 -import { Tool, ExecuteToolModifiers, BaseNonAgenticToolset } from '@composio/core';
14 -import { ToolExecuteParams } from 'packages/core/src/types/tool.types';
15 -import { ExecuteToolFnOptions } from 'packages/core/src/types/toolset.types';
13 +import {
14 + Tool,
15 + ExecuteToolModifiers,
16 + BaseNonAgenticToolset,
17 + ToolExecuteParams,
18 + ExecuteToolFnOptions,
19 +} from '@composio/core';
20
21 type AiToolCollection = Record<string, AiTextGenerationToolInput>;
22
packages/toolsets/langchain/src/index.ts
+1 -2
@@ -9,9 +9,8 @@
9 * @packageDocumentation
10 * @module toolsets/langchain
11 */
12 -import { BaseAgenticToolset, jsonSchemaToModel, Tool } from '@composio/core';
12 +import { BaseAgenticToolset, jsonSchemaToModel, Tool, ExecuteToolFn } from '@composio/core';
13 import { DynamicStructuredTool } from '@langchain/core/tools';
14 -import { ExecuteToolFn } from 'packages/core/src/types/toolset.types';
14
15 export type LangChainToolCollection = Array<DynamicStructuredTool>;
16 export class LangchainToolset extends BaseAgenticToolset<
packages/toolsets/vercel/src/index.ts
+1 -2
@@ -10,10 +10,9 @@
10 * @packageDocumentation
11 * @module toolsets/vercel
12 */
13 -import { BaseAgenticToolset, Tool as ComposioTool } from '@composio/core';
13 +import { BaseAgenticToolset, Tool as ComposioTool, ExecuteToolFn } from '@composio/core';
14 import type { Tool as VercelTool } from 'ai';
15 import { jsonSchema, tool } from 'ai';
16 -import { ExecuteToolFn } from 'packages/core/src/types/toolset.types';
16
17 type VercelToolCollection = Record<string, VercelTool>;
18 export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, VercelTool> {