@devries-cameron20 / composio-1 / commits / 6dc0c93c3
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.

Create extensive docs

haxzie committed May 28, 2025 at 18:02 UTC 6dc0c93c3fc71e0d7a3d4e308d3702db33fb6422
13 files changed +1119 -205
CONTRIBUTING.md new
+359
@@ -0,0 +1,359 @@
1 +# Contributing to Composio SDK
2 +
3 +Thank you for your interest in contributing to Composio SDK! This document provides guidelines and instructions for contributing to the project.
4 +
5 +## Table of Contents
6 +
7 +- [Development Setup](#development-setup)
8 +- [Project Structure](#project-structure)
9 +- [Coding Standards](#coding-standards)
10 +- [Documentation Requirements](#documentation-requirements)
11 +- [Pull Request Process](#pull-request-process)
12 +- [Creating New Providers](#creating-new-providers)
13 +- [Testing Guidelines](#testing-guidelines)
14 +- [Release Process](#release-process)
15 +
16 +## Development Setup
17 +
18 +### Prerequisites
19 +
20 +- Node.js (Latest LTS version recommended)
21 +- [pnpm](https://pnpm.io/) (v10.8.0 or later)
22 +- [bun](https://bun.sh) for productivity (optional)
23 +
24 +### Getting Started
25 +
26 +1. Fork and clone the repository:
27 +
28 + ```bash
29 + git clone https://github.com/YOUR_USERNAME/sdk-v3.git
30 + cd sdk-v3
31 + ```
32 +
33 +2. Install dependencies:
34 +
35 + ```bash
36 + pnpm install
37 + ```
38 +
39 +3. Build the project:
40 +
41 + ```bash
42 + pnpm build
43 + ```
44 +
45 +4. Run tests:
46 + ```bash
47 + pnpm test
48 + ```
49 +
50 +### Development Commands
51 +
52 +```bash
53 +# Lint code
54 +pnpm lint
55 +
56 +# Fix linting issues
57 +pnpm lint:fix
58 +
59 +# Format code
60 +pnpm format
61 +
62 +# Create a new provider
63 +pnpm create:provider <provider-name> [--agentic]
64 +
65 +# Create a new example
66 +pnpm create:example <example-name>
67 +
68 +# Check peer dependencies
69 +pnpm check:peer-deps
70 +
71 +# Update peer dependencies
72 +pnpm update:peer-deps
73 +```
74 +
75 +## Project Structure
76 +
77 +```
78 +composio/
79 +├── packages/ # Main packages directory
80 +│ ├── core/ # Core SDK package
81 +│ └── providers/ # Provider implementations
82 +├── examples/ # Example implementations
83 +├── docs/ # Documentation
84 +├── scripts/ # Development and build scripts
85 +└── .github/ # GitHub configuration
86 +```
87 +
88 +## Coding Standards
89 +
90 +### File Headers
91 +
92 +Every source file must include a header comment with:
93 +
94 +```typescript
95 +/**
96 + * @file Description of what this file does/contains
97 + * @module path/to/module
98 + * @description Detailed description of the file's purpose
99 + *
100 + * @author Original Author <email@example.com>
101 + * @contributors
102 + * - Contributor Name <email@example.com>
103 + *
104 + * @copyright Composio 2024
105 + * @license ISC
106 + *
107 + * @see {@link https://related.documentation.link}
108 + * @see {@link https://another.related.link}
109 + */
110 +```
111 +
112 +### Function Documentation
113 +
114 +Every user-facing function must include:
115 +
116 +1. TSDoc documentation
117 +2. Example usage
118 +3. Parameter and return type descriptions
119 +4. Error cases
120 +
121 +Example:
122 +
123 +````typescript
124 +/**
125 + * Executes a tool with the given parameters.
126 + *
127 + * @description
128 + * This function executes a tool with the provided parameters and returns the result.
129 + * It handles authentication, parameter validation, and error cases automatically.
130 + *
131 + * @example
132 + * ```typescript
133 + * const result = await executeTool('GMAIL_SEND_EMAIL', {
134 + * userId: 'user123',
135 + * arguments: {
136 + * to: 'recipient@example.com',
137 + * subject: 'Hello',
138 + * body: 'Message content'
139 + * }
140 + * });
141 + * ```
142 + *
143 + * @param {string} toolId - The unique identifier of the tool to execute
144 + * @param {ExecuteToolOptions} options - Tool execution options
145 + * @returns {Promise<ExecuteToolResult>} The result of the tool execution
146 + *
147 + * @throws {ToolNotFoundError} When the specified tool doesn't exist
148 + * @throws {ValidationError} When required parameters are missing
149 + * @throws {AuthenticationError} When authentication fails
150 + *
151 + * @see {@link https://docs.composio.dev/api/tools#execute}
152 + */
153 +export async function executeTool(
154 + toolId: string,
155 + options: ExecuteToolOptions
156 +): Promise<ExecuteToolResult> {
157 + // Implementation
158 +}
159 +````
160 +
161 +### Code Style
162 +
163 +1. Use TypeScript for all new code
164 +2. Follow the existing code style in the repository
165 +3. Use ESLint and Prettier for code formatting
166 +4. Use meaningful variable and function names
167 +5. Keep functions small and focused
168 +6. Write unit tests for all new code
169 +7. Use async/await instead of Promises
170 +8. Use named exports instead of default exports
171 +9. Use const assertions for constants
172 +10. Use type assertions sparingly
173 +
174 +### Error Handling
175 +
176 +1. Use custom error classes
177 +2. Include meaningful error messages
178 +3. Document error cases in TSDoc
179 +4. Include error codes for API errors
180 +5. Log errors appropriately
181 +
182 +Example:
183 +
184 +```typescript
185 +/**
186 + * Custom error for tool execution failures.
187 + */
188 +export class ToolExecutionError extends ComposioError {
189 + constructor(
190 + message: string,
191 + public readonly toolId: string,
192 + public readonly cause?: Error
193 + ) {
194 + super(message, 'TOOL_EXECUTION_ERROR');
195 + this.name = 'ToolExecutionError';
196 + }
197 +}
198 +```
199 +
200 +## Documentation Requirements
201 +
202 +### Package Documentation
203 +
204 +Each package must include:
205 +
206 +1. README.md with:
207 +
208 + - Package description
209 + - Installation instructions
210 + - Usage examples
211 + - API reference
212 + - Environment variables
213 + - Contributing guidelines
214 +
215 +2. API documentation:
216 +
217 + - TSDoc for all public APIs
218 + - Example code snippets
219 + - Error handling documentation
220 + - Type definitions
221 +
222 +3. Example implementations:
223 + - Basic usage example
224 + - Advanced usage examples
225 + - Integration examples
226 +
227 +### Provider Documentation
228 +
229 +Provider packages must additionally include:
230 +
231 +1. Provider-specific setup instructions
232 +2. Authentication requirements
233 +3. Supported features
234 +4. Limitations and constraints
235 +5. Integration examples
236 +6. Streaming support details
237 +7. Error handling examples
238 +
239 +## Pull Request Process
240 +
241 +1. Create a new branch for your changes:
242 +
243 + ```bash
244 + git checkout -b feature/your-feature-name
245 + ```
246 +
247 +2. Make your changes following the coding standards
248 +
249 +3. Add tests for new functionality
250 +
251 +4. Update documentation as needed
252 +
253 +5. Create a changeset:
254 +
255 + ```bash
256 + pnpm changeset
257 + ```
258 +
259 +6. Push your changes and create a pull request
260 +
261 +7. Wait for review and address any feedback
262 +
263 +## Creating New Providers
264 +
265 +1. Use the provider creation script:
266 +
267 + ```bash
268 + pnpm create:provider my-provider [--agentic]
269 + ```
270 +
271 +2. Implement required methods:
272 +
273 + - For non-agentic providers: `wrapTool` and `wrapTools`, and helper functions
274 + - For agentic providers: `wrapTool`, `wrapTools`, and execution handlers
275 +
276 +3. Add comprehensive tests
277 +
278 +4. Add provider documentation
279 +
280 +5. Create example implementations
281 +
282 +## Testing Guidelines
283 +
284 +1. Write unit tests for all new code
285 +2. Include integration tests for providers
286 +3. Test error cases
287 +4. Test edge cases
288 +5. Use mocks appropriately
289 +6. Test streaming functionality
290 +7. Test with different Node.js versions
291 +
292 +Example test:
293 +
294 +```typescript
295 +describe('ToolExecution', () => {
296 + it('should execute a tool successfully', async () => {
297 + const result = await executeTool('TEST_TOOL', {
298 + userId: 'user123',
299 + arguments: { test: true },
300 + });
301 + expect(result.successful).toBe(true);
302 + });
303 +
304 + it('should handle errors appropriately', async () => {
305 + await expect(
306 + executeTool('INVALID_TOOL', {
307 + userId: 'user123',
308 + arguments: {},
309 + })
310 + ).rejects.toThrow(ToolNotFoundError);
311 + });
312 +});
313 +```
314 +
315 +## Release Process
316 +
317 +1. Create a release branch:
318 +
319 + ```bash
320 + git checkout -b release/v1.2.3
321 + ```
322 +
323 +2. Update version numbers:
324 +
325 + ```bash
326 + pnpm changeset version
327 + ```
328 +
329 +3. Update CHANGELOG.md
330 +
331 +4. Create a release commit:
332 +
333 + ```bash
334 + git commit -am "Release v1.2.3"
335 + ```
336 +
337 +5. Create a pull request for the release
338 +
339 +6. After approval, merge and tag:
340 +
341 + ```bash
342 + git tag v1.2.3
343 + git push origin v1.2.3
344 + ```
345 +
346 +7. Publish to npm:
347 + ```bash
348 + pnpm changeset publish
349 + ```
350 +
351 +## Questions and Support
352 +
353 +- Join our [Discord Community](https://discord.gg/composio)
354 +- Check our [Documentation](https://docs.composio.dev)
355 +- File issues on [GitHub](https://github.com/ComposioHQ/sdk-v3/issues)
356 +
357 +## License
358 +
359 +By contributing to Composio SDK, you agree that your contributions will be licensed under the ISC License.
README.md
+8
@@ -18,6 +18,7 @@ The SDK is thoroughly documented in the [docs](./docs) directory:
18 - [Overview](./docs/overview.md) - Introduction and key concepts
19 - [Getting Started](./docs/getting-started.md) - Quick start guide
20 - [Core Concepts](./docs/core-concepts.md) - Fundamental SDK concepts
21 +- [Configuration](./docs/internal/configuration.md) - Environment variables and SDK configuration
22
23 ### API Reference
24
@@ -42,6 +43,13 @@ The SDK is thoroughly documented in the [docs](./docs) directory:
43 - [Telemetry](./docs/advanced/telemetry.md) - SDK usage tracking
44 - [Custom Providers](./docs/advanced/custom-providers.md) - Detailed provider guide
45
46 +### Internal Documentation
47 +
48 +For SDK maintainers and contributors:
49 +
50 +- [Configuration and Environment Variables](./docs/internal/configuration.md) - Detailed guide on SDK configuration
51 +- [Triggers Implementation](./docs/internal/triggers.md) - Internal workings of the trigger system
52 +
53 ## Installation
54
55 ```bash
docs/README.md
+21 -2
@@ -12,6 +12,7 @@ Composio SDK is a powerful toolkit that enables you to integrate third-party too
12 - [Providers](#providers)
13 - [Examples](#examples)
14 - [Advanced Topics](#advanced-topics)
15 +- [Internal Documentation](#internal-documentation)
16
17 ## Overview
18
@@ -92,8 +93,18 @@ The complete API reference documentation is available here:
93
94 Composio SDK comes with built-in support for different providers:
95
95 -- [OpenAI Provider](./providers/openai.md)
96 -- [Custom Providers](./providers/custom.md)
96 +### Non-Agentic Providers
97 +
98 +- [OpenAI Provider](../packages/providers/openai/README.md) - OpenAI integration with GPT-4, GPT-3.5, etc.
99 +- [Anthropic Provider](../packages/providers/anthropic/README.md) - Anthropic Claude integration
100 +- [Google Provider](../packages/providers/google/README.md) - Google Gemini integration
101 +- [Cloudflare Provider](../packages/providers/cloudflare/README.md) - Cloudflare Workers AI integration
102 +
103 +### Agentic Providers
104 +
105 +- [LangChain Provider](../packages/providers/langchain/README.md) - LangChain integration with LCEL support
106 +- [Mastra Provider](../packages/providers/mastra/README.md) - Agentic provider for autonomous behavior
107 +- [Vercel Provider](../packages/providers/vercel/README.md) - Vercel AI SDK integration
108
109 ## Examples
110
@@ -103,6 +114,7 @@ Check out our [examples directory](../examples) for complete code samples:
114 - [OpenAI Integration](../examples/openai)
115 - [LangChain Integration](../examples/langchain)
116 - [Toolkits](../examples/toolkits)
117 +- [Triggers](../examples/triggers)
118 - [Modifiers](../examples/modifiers)
119
120 ## Advanced Topics
@@ -111,3 +123,10 @@ Check out our [examples directory](../examples) for complete code samples:
123 - [Telemetry](./advanced/telemetry.md)
124 - [Custom Providers](./advanced/custom-providers.md)
125 - [Modifiers](./advanced/modifiers.md)
126 +
127 +## Internal Documentation
128 +
129 +For SDK maintainers and contributors:
130 +
131 +- [Configuration and Environment Variables](./internal/configuration.md) - Detailed guide on SDK configuration
132 +- [Triggers Implementation](./internal/triggers.md) - Internal workings of the trigger system
docs/api/triggers.md new
+140
@@ -0,0 +1,140 @@
1 +# Triggers
2 +
3 +The Triggers API allows you to manage and subscribe to real-time events from your connected accounts. This guide explains how to work with triggers using the Composio SDK.
4 +
5 +## Overview
6 +
7 +Triggers are real-time events that occur in your connected accounts. The SDK provides methods to:
8 +
9 +- List active triggers
10 +- Create new trigger instances
11 +- Update existing triggers
12 +- Enable/disable triggers
13 +- Subscribe to real-time trigger events
14 +- Manage trigger types
15 +
16 +## Methods
17 +
18 +### List Active Triggers
19 +
20 +Fetch a list of all active triggers with optional filtering:
21 +
22 +```typescript
23 +const triggers = await composio.triggers.listActive({
24 + authConfigIds: ['auth-config-id'],
25 + connectedAccountIds: ['connected-account-id'],
26 + limit: 10,
27 + page: 1,
28 + showDisabled: false,
29 + triggerIds: ['trigger-id'],
30 + triggerNames: ['trigger-name'],
31 +});
32 +```
33 +
34 +### Create Trigger Instance
35 +
36 +Create a new trigger instance for a specific trigger type:
37 +
38 +```typescript
39 +const trigger = await composio.triggers.create('trigger-slug', {
40 + connectedAccountId: 'connected-account-id',
41 + triggerConfig: {
42 + // Trigger specific configuration
43 + },
44 +});
45 +```
46 +
47 +### Update Trigger Instance
48 +
49 +Update an existing trigger instance:
50 +
51 +```typescript
52 +const updatedTrigger = await composio.triggers.update('trigger-id', {
53 + // Updated configuration
54 +});
55 +```
56 +
57 +### Enable/Disable Triggers
58 +
59 +Control trigger activation state:
60 +
61 +```typescript
62 +// Disable a trigger
63 +await composio.triggers.disable('trigger-id');
64 +
65 +// Enable a trigger
66 +await composio.triggers.enable('trigger-id');
67 +```
68 +
69 +### Real-time Trigger Subscription
70 +
71 +Subscribe to real-time trigger events with optional filtering:
72 +
73 +```typescript
74 +composio.triggers.subscribe(
75 + triggerData => {
76 + console.log('Received trigger:', triggerData);
77 + },
78 + {
79 + toolkits: ['toolkit-name'],
80 + triggerId: 'specific-trigger-id',
81 + connectedAccountId: 'connected-account-id',
82 + triggerSlug: ['trigger-type'],
83 + triggerData: 'custom-data',
84 + userId: 'user-id',
85 + }
86 +);
87 +```
88 +
89 +#### Trigger Payload Format
90 +
91 +When you receive a trigger event, the payload will have the following structure:
92 +
93 +```typescript
94 +interface IncomingTriggerPayload {
95 + id: string; // Unique trigger instance ID
96 + triggerSlug: string; // Type of trigger
97 + toolkitSlug: string; // Associated toolkit
98 + userId: string; // User ID associated with the trigger
99 + payload: unknown; // Processed trigger payload
100 + originalPayload: unknown; // Raw trigger payload
101 + metadata: {
102 + id: string;
103 + triggerConfig: unknown; // Trigger configuration
104 + triggerSlug: string;
105 + toolkitSlug: string;
106 + triggerData: string;
107 + connectedAccount: {
108 + id: string; // Connected account nano ID
109 + uuid: string; // Connected account UUID
110 + authConfigId: string; // Auth config nano ID
111 + authConfigUUID: string; // Auth config UUID
112 + userId: string; // User ID
113 + status: string; // Connection status
114 + };
115 + };
116 +}
117 +```
118 +
119 +### Unsubscribe from Triggers
120 +
121 +Stop receiving trigger events:
122 +
123 +```typescript
124 +await composio.triggers.unsubscribe();
125 +```
126 +
127 +### Manage Trigger Types
128 +
129 +List and retrieve available trigger types:
130 +
131 +```typescript
132 +// List all trigger types
133 +const triggerTypes = await composio.triggers.listTypes();
134 +
135 +// Get details of a specific trigger type
136 +const triggerType = await composio.triggers.getType('trigger-slug');
137 +
138 +// Get enum of all available triggers
139 +const triggerEnum = await composio.triggers.listEnum();
140 +```
docs/internal/configuration.md new
+137
@@ -0,0 +1,137 @@
1 +# Configuration
2 +
3 +This guide explains how to configure the Composio SDK using environment variables and initialization options.
4 +
5 +## Environment Variables
6 +
7 +The SDK supports several environment variables for configuration:
8 +
9 +### Core Configuration
10 +
11 +- `COMPOSIO_API_KEY`: Your Composio API key
12 +
13 + - Required for authentication
14 + - Can be obtained from [Composio Dashboard](https://app.composio.dev)
15 + - Can also be set via SDK initialization or user config file
16 +
17 +- `COMPOSIO_BASE_URL`: Custom API base URL
18 + - Optional
19 + - Default: `https://backend.composio.dev`
20 + - Use this to point the SDK to a different API endpoint
21 +
22 +### Logging Configuration
23 +
24 +- `COMPOSIO_LOG_LEVEL`: Controls the verbosity of SDK logs
25 + - Values: `silent`, `error`, `warn`, `info`, `debug`
26 + - Default: `info`
27 + - Hierarchy (from highest to lowest priority):
28 + - `silent`: No logs
29 + - `error`: Only critical errors
30 + - `warn`: Warnings and errors
31 + - `info`: General information, warnings, and errors
32 + - `debug`: Detailed debugging information
33 +
34 +### Development and Testing
35 +
36 +- `NODE_ENV`: Environment mode
37 +
38 + - Values: `development`, `production`, `test`
39 + - Affects:
40 + - Telemetry collection (disabled in development/test)
41 + - Error handling verbosity
42 + - Version check notifications
43 +
44 +- `DEVELOPMENT`: Development mode flag
45 +
46 + - Set to any value to enable development mode
47 + - Enables additional debugging features
48 + - Shows more verbose logs
49 +
50 +- `CI`: CI environment flag
51 + - Set to any value to indicate CI environment
52 + - Affects certain behaviors like version checks
53 +
54 +### Telemetry
55 +
56 +- `COMPOSIO_DISABLE_TELEMETRY`: Disable telemetry collection
57 + - Set to `"true"` to disable
58 + - Default: `"false"`
59 + - Alternative to `allowTracking` initialization option
60 +
61 +## SDK Initialization Options
62 +
63 +When initializing the SDK, you can provide configuration through the constructor:
64 +
65 +```typescript
66 +const composio = new Composio({
67 + apiKey: 'your-api-key', // Override COMPOSIO_API_KEY
68 + baseURL: 'custom-url', // Override COMPOSIO_BASE_URL
69 + allowTracking: false, // Disable telemetry
70 + allowTracing: true, // Enable tracing
71 + provider: new CustomProvider(), // Custom provider
72 + telemetryTransport: customTransport, // Custom telemetry transport
73 +});
74 +```
75 +
76 +### Configuration Priority
77 +
78 +When multiple configuration sources are present, the SDK follows this priority order:
79 +
80 +1. Constructor parameters
81 +2. Environment variables
82 +3. User config file
83 +4. Default values
84 +
85 +## Examples
86 +
87 +### Development Setup
88 +
89 +```bash
90 +# Development environment with debug logging
91 +export NODE_ENV=development
92 +export COMPOSIO_LOG_LEVEL=debug
93 +export COMPOSIO_API_KEY=your-api-key
94 +```
95 +
96 +### Production Setup
97 +
98 +```bash
99 +# Production environment with minimal logging
100 +export NODE_ENV=production
101 +export COMPOSIO_LOG_LEVEL=error
102 +export COMPOSIO_API_KEY=your-api-key
103 +```
104 +
105 +### Testing Setup
106 +
107 +```bash
108 +# Test environment with telemetry disabled
109 +export NODE_ENV=test
110 +export COMPOSIO_DISABLE_TELEMETRY=true
111 +export COMPOSIO_API_KEY=your-test-api-key
112 +```
113 +
114 +## Best Practices
115 +
116 +1. **Environment-specific Configuration**
117 +
118 + - Use different log levels for different environments
119 + - Enable detailed logging in development
120 + - Use minimal logging in production
121 +
122 +2. **Security**
123 +
124 + - Never commit API keys to version control
125 + - Use environment variables or secure secrets management
126 + - Consider using different API keys for different environments
127 +
128 +3. **Telemetry**
129 +
130 + - Enable telemetry in production for better support
131 + - Disable telemetry in development and testing
132 + - Use custom telemetry transport for specific needs
133 +
134 +4. **Error Handling**
135 + - Set appropriate log levels for error tracking
136 + - Use debug level during development
137 + - Use error or warn level in production
docs/internal/triggers.md new
+101
@@ -0,0 +1,101 @@
1 +# Trigger System Implementation
2 +
3 +This document explains the internal implementation of the trigger system in the Composio SDK.
4 +
5 +## Architecture Overview
6 +
7 +The trigger system is built on top of Pusher for real-time communication. The implementation consists of two main components:
8 +
9 +1. The Triggers class (`packages/core/src/models/Triggers.ts`)
10 +2. The PusherService class (`packages/core/src/services/pusher/Pusher.ts`)
11 +
12 +## Real-time Communication
13 +
14 +### Pusher Integration
15 +
16 +The SDK uses Pusher as the underlying real-time communication infrastructure. When a client subscribes to triggers, the following process occurs:
17 +
18 +1. The SDK initializes a PusherService instance
19 +2. The service connects to Pusher using client credentials
20 +3. A channel subscription is established for the client's triggers
21 +4. Incoming messages are processed and filtered based on user-defined criteria
22 +
23 +### Message Flow
24 +
25 +```mermaid
26 +sequenceDiagram
27 + participant Client
28 + participant SDK
29 + participant Pusher
30 + participant ComposioAPI
31 +
32 + Client->>SDK: subscribe(callback, filters)
33 + SDK->>ComposioAPI: Authenticate Pusher connection
34 + ComposioAPI-->>SDK: Connection credentials
35 + SDK->>Pusher: Connect & Subscribe to channel
36 + Pusher-->>SDK: Connection established
37 + loop Real-time Events
38 + Pusher->>SDK: Trigger event
39 + SDK->>SDK: Apply filters
40 + SDK->>Client: Filtered event callback
41 + end
42 +```
43 +
44 +## API Endpoints
45 +
46 +The SDK interacts with the following Composio API endpoints for trigger management:
47 +
48 +### Trigger Instance Management
49 +
50 +- `GET /api/v3/trigger_instances/active` - List active triggers
51 +- `POST /api/v3/trigger_instances/{slug}` - Create/update trigger instance
52 +- `PATCH /api/v3/trigger_instances/manage/{id}` - Update trigger instance
53 +- `DELETE /api/v3/trigger_instances/manage/{id}` - Delete trigger instance
54 +
55 +### Trigger Types
56 +
57 +- `GET /api/v3/triggers/types` - List trigger types
58 +- `GET /api/v3/triggers/types/{slug}` - Get trigger type details
59 +- `GET /api/v3/triggers/types/enum` - Get trigger type enums
60 +
61 +### Pusher Authentication
62 +
63 +- `POST /api/v3/pusher/auth` - Authenticate Pusher connection
64 +
65 +## Data Processing
66 +
67 +When a trigger event is received through Pusher, the SDK:
68 +
69 +1. Parses the raw event data
70 +2. Validates it against the `IncomingTriggerPayloadSchema`
71 +3. Applies user-defined filters
72 +4. Delivers the processed event to the user's callback
73 +
74 +### Filter Processing
75 +
76 +The SDK supports filtering triggers based on:
77 +
78 +- Toolkit names
79 +- Trigger IDs
80 +- Connected Account IDs
81 +- Trigger slugs
82 +- Trigger data
83 +- User IDs
84 +
85 +Filters are applied in a compound manner - all specified filters must match for an event to be delivered.
86 +
87 +## Error Handling
88 +
89 +The SDK implements robust error handling:
90 +
91 +- Schema validation for all incoming and outgoing data
92 +- Connection error recovery
93 +- Callback error isolation (errors in user callbacks don't affect the subscription)
94 +- Automatic reconnection on connection loss
95 +
96 +## Security Considerations
97 +
98 +- All Pusher communications are authenticated
99 +- API credentials are never exposed to the client
100 +- Each client only receives events they are authorized to see
101 +- Connection credentials are short-lived and rotated regularly
examples/triggers/src/index.ts
+3 -1
@@ -37,7 +37,9 @@ async function main() {
37 console.log(`✅ Found ${tools.length} tools`);
38
39 // TODO: Add your example implementation here
40 - console.log('📝 Implement your triggers logic here!');
40 + console.log(
41 + '📝 Go to https://app.composio.dev to create an app and add a trigger, Once you have an incoming trigger, you will see the events'
42 + );
43
44 composio.triggers.subscribe(data => {
45 console.log('🔔 Trigger received:', data);
packages/providers/anthropic/README.md
+107 -22
@@ -9,6 +9,7 @@ Non-Agentic Provider for Anthropic in Composio SDK.
9 - **Tool Execution**: Execute tools with proper parameter handling and response formatting
10 - **Caching Support**: Optional tool caching for improved performance
11 - **Modifier Support**: Support for execution modifiers to transform tool inputs and outputs
12 +- **Streaming Support**: First-class support for streaming responses
13
14 ## Installation
15
@@ -20,6 +21,17 @@ yarn add @composio/anthropic
21 pnpm add @composio/anthropic
22 ```
23
24 +## Environment Variables
25 +
26 +Required environment variables:
27 +
28 +- `COMPOSIO_API_KEY`: Your Composio API key
29 +- `ANTHROPIC_API_KEY`: Your Anthropic API key
30 +
31 +Optional environment variables:
32 +
33 +- `ANTHROPIC_API_URL`: Custom API base URL (defaults to Anthropic's API)
34 +
35 ## Quick Start
36
37 ```typescript
@@ -40,13 +52,24 @@ const tools = await composio.tools.get('user123', {
52 });
53 ```
54
43 -## Usage Examples
55 +## Examples
56 +
57 +Check out our complete example implementations:
58 +
59 +- [Basic Anthropic Integration](../../examples/anthropic/src/index.ts)
60 +- [Streaming Example](../../examples/anthropic/src/streaming.ts)
61
62 ### Basic Example
63
64 ```typescript
65 import { Composio } from '@composio/core';
66 import { AnthropicProvider } from '@composio/anthropic';
67 +import Anthropic from '@anthropic-ai/sdk';
68 +
69 +// Initialize Anthropic
70 +const anthropic = new Anthropic({
71 + apiKey: process.env.ANTHROPIC_API_KEY,
72 +});
73
74 // Initialize Composio
75 const composio = new Composio({
@@ -59,31 +82,93 @@ const tools = await composio.tools.get('user123', {
82 toolkits: ['gmail'],
83 });
84
62 -// Handle tool execution with modifiers
63 -const modifiers = {
64 - beforeExecute: params => {
65 - // Transform tool parameters before execution
66 - return params;
67 - },
68 - afterExecute: response => {
69 - // Transform tool response after execution
70 - return response;
71 - },
72 -};
85 +// Create a message with tools
86 +const message = await anthropic.messages.create({
87 + model: 'claude-3-sonnet-20240229',
88 + max_tokens: 1024,
89 + tools: tools,
90 + messages: [
91 + {
92 + role: 'user',
93 + content: 'Send an email to support@example.com',
94 + },
95 + ],
96 +});
97
74 -// Execute a tool with options
75 -const result = await provider.executeTool(
76 - 'tool-name',
77 - {
78 - userId: 'user123',
79 - arguments: { input: 'value' },
98 +// Handle tool calls
99 +if (message.content[0].type === 'tool_calls') {
100 + const toolCall = message.content[0];
101 + const result = await composio.provider.executeToolCall('user123', toolCall, {
102 connectedAccountId: 'account123',
81 - customAuthParams: {
82 - parameters: [{ name: 'token', value: 'abc123', in: 'header' }],
103 + });
104 + console.log('Tool execution result:', result);
105 +}
106 +```
107 +
108 +### Streaming Example
109 +
110 +```typescript
111 +import { Composio } from '@composio/core';
112 +import { AnthropicProvider } from '@composio/anthropic';
113 +import Anthropic from '@anthropic-ai/sdk';
114 +
115 +const anthropic = new Anthropic({
116 + apiKey: process.env.ANTHROPIC_API_KEY,
117 +});
118 +
119 +const composio = new Composio({
120 + apiKey: process.env.COMPOSIO_API_KEY,
121 + provider: new AnthropicProvider(),
122 +});
123 +
124 +const tools = await composio.tools.get('user123', {
125 + toolkits: ['gmail'],
126 +});
127 +
128 +const stream = await anthropic.messages.stream({
129 + model: 'claude-3-sonnet-20240229',
130 + max_tokens: 1024,
131 + tools: tools,
132 + messages: [
133 + {
134 + role: 'user',
135 + content: 'Send an email to support@example.com',
136 + },
137 + ],
138 +});
139 +
140 +for await (const messageChunk of stream) {
141 + if (messageChunk.type === 'content_block_delta' && messageChunk.delta.type === 'tool_calls') {
142 + const result = await composio.provider.executeToolCall('user123', messageChunk.delta, {
143 + connectedAccountId: 'account123',
144 + });
145 + console.log('Tool execution result:', result);
146 + } else {
147 + console.log('Message chunk:', messageChunk);
148 + }
149 +}
150 +```
151 +
152 +## Provider Configuration
153 +
154 +The Anthropic provider can be configured with various options:
155 +
156 +```typescript
157 +const provider = new AnthropicProvider({
158 + // Enable tool caching
159 + cacheTools: true,
160 + // Custom execution modifiers
161 + modifiers: {
162 + beforeExecute: params => {
163 + // Transform parameters before execution
164 + return params;
165 + },
166 + afterExecute: response => {
167 + // Transform response after execution
168 + return response;
169 },
170 },
85 - modifiers
86 -);
171 +});
172 ```
173
174 ## API Reference
packages/providers/google/README.md
+35 -59
@@ -9,17 +9,30 @@ Google GenAI Provider for Composio SDK.
9 - **Type Safety**: Full TypeScript support with proper type definitions
10 - **Execution Modifiers**: Support for transforming tool inputs and outputs
11 - **Flexible Authentication**: Support for custom authentication parameters
12 +- **Streaming Support**: First-class support for streaming responses
13
14 ## Installation
15
16 ```bash
16 -npm install @composio/google @google/genai
17 +npm install @composio/core @composio/google @google/genai
18 # or
18 -yarn add @composio/google @google/genai
19 +yarn add @composio/core @composio/google @google/genai
20 # or
20 -pnpm add @composio/google @google/genai
21 +pnpm add @composio/core @composio/google @google/genai
22 ```
23
24 +## Environment Variables
25 +
26 +Required environment variables:
27 +
28 +- `COMPOSIO_API_KEY`: Your Composio API key
29 +- `GEMINI_API_KEY`: Your Google AI API key
30 +
31 +Optional environment variables:
32 +
33 +- `GOOGLE_PROJECT_ID`: Your Google Cloud project ID (for custom deployments)
34 +- `GOOGLE_LOCATION`: Your Google Cloud location (for custom deployments)
35 +
36 ## Quick Start
37
38 ```typescript
@@ -43,70 +56,33 @@ const tools = await composio.tools.get('user123', {
56 });
57 ```
58
46 -## Usage Examples
59 +## Examples
60
48 -### Function Calling Example
61 +Check out our complete example implementations:
62
50 -```typescript
51 -import { Composio } from '@composio/core';
52 -import { GoogleProvider } from '@composio/google';
53 -import { GoogleGenerativeAI } from '@google/genai';
63 +- [Basic Google Integration](../../examples/google/src/index.ts)
64
55 -// Initialize Google GenAI
56 -const genAI = new GoogleGenerativeAI(process.env.GEMINI_API_KEY);
65 +## Provider Configuration
66
58 -// Initialize Composio
59 -const composio = new Composio({
60 - apiKey: process.env.COMPOSIO_API_KEY,
61 - provider: new GoogleProvider(),
62 -});
63 -
64 -// Handle tool execution with modifiers
65 -const modifiers = {
66 - beforeExecute: params => {
67 - // Transform tool parameters before execution
68 - return params;
69 - },
70 - afterExecute: response => {
71 - // Transform tool response after execution
72 - return response;
73 - },
74 -};
67 +The Google provider can be configured with various options:
68
76 -// Execute a tool with options
77 -const result = await provider.executeTool(
78 - 'tool-name',
79 - {
80 - userId: 'user123',
81 - arguments: { input: 'value' },
82 - connectedAccountId: 'account123',
83 - customAuthParams: {
84 - parameters: [{ name: 'token', value: 'abc123', in: 'header' }],
69 +```typescript
70 +const provider = new GoogleProvider({
71 + // Custom project configuration
72 + projectId: 'your-project-id',
73 + location: 'your-location',
74 + // Custom execution modifiers
75 + modifiers: {
76 + beforeExecute: params => {
77 + // Transform parameters before execution
78 + return params;
79 },
86 - },
87 - modifiers
88 -);
89 -
90 -// Handle function calls from Google GenAI
91 -const functionCall = {
92 - name: 'tool-name',
93 - args: { param: 'value' },
94 -};
95 -
96 -const toolResult = await provider.executeToolCall(
97 - 'user123',
98 - functionCall,
99 - {
100 - connectedAccountId: 'account123',
101 - customAuthParams: {
102 - /* ... */
80 + afterExecute: response => {
81 + // Transform response after execution
82 + return response;
83 },
84 },
105 - {
106 - beforeExecute: params => params,
107 - afterExecute: response => response,
108 - }
109 -);
85 +});
86 ```
87
88 ## API Reference
packages/providers/langchain/README.md
+46 -60
@@ -14,13 +14,26 @@ The LangChain provider for Composio SDK, providing seamless integration with Lan
14 ## Installation
15
16 ```bash
17 -npm install @composio/langchain
17 +npm install @composio/core @composio/langchain @langchain/core @langchain/openai
18 # or
19 -yarn add @composio/langchain
19 +yarn add @composio/core @composio/langchain @langchain/core @langchain/openai
20 # or
21 -pnpm add @composio/langchain
21 +pnpm add @composio/core @composio/langchain @langchain/core @langchain/openai
22 ```
23
24 +## Environment Variables
25 +
26 +Required environment variables:
27 +
28 +- `COMPOSIO_API_KEY`: Your Composio API key
29 +- `OPENAI_API_KEY`: Your OpenAI API key (or other LLM provider's key)
30 +
31 +Optional environment variables:
32 +
33 +- `LANGCHAIN_TRACING_V2`: Enable LangChain tracing (set to "true")
34 +- `LANGCHAIN_ENDPOINT`: Custom LangChain API endpoint
35 +- `LANGCHAIN_API_KEY`: Your LangChain API key (for hosted services)
36 +
37 ## Quick Start
38
39 ```typescript
@@ -43,7 +56,14 @@ const tools = await composio.tools.get('user123', {
56 const sendEmailTool = await composio.tools.get('user123', 'GMAIL_SEND_EMAIL');
57 ```
58
46 -## Usage Examples
59 +## Examples
60 +
61 +Check out our complete example implementations:
62 +
63 +- [Basic LangChain Integration](../../examples/langchain/src/index.ts)
64 +- [LCEL Example](../../examples/langchain/src/lcel.ts)
65 +- [RAG Example](../../examples/langchain/src/rag.ts)
66 +- [Streaming Example](../../examples/langchain/src/streaming.ts)
67
68 ### Basic Chain with Streaming
69
@@ -125,65 +145,31 @@ for await (const event of eventStream) {
145 }
146 ```
147
128 -### RAG Application Example
148 +## Provider Configuration
149
130 -```typescript
131 -import { Composio } from '@composio/core';
132 -import { LangChainProvider } from '@composio/langchain';
133 -import { ChatPromptTemplate } from '@langchain/core/prompts';
134 -import { StringOutputParser } from '@langchain/core/output_parsers';
135 -import { MemoryVectorStore } from 'langchain/vectorstores/memory';
136 -import { OpenAIEmbeddings } from '@langchain/openai';
137 -import { ChatOpenAI } from '@langchain/openai';
138 -import { RunnableSequence, RunnablePassthrough } from '@langchain/core/runnables';
139 -
140 -const composio = new Composio({
141 - apiKey: process.env.COMPOSIO_API_KEY,
142 - provider: new LangChainProvider(),
143 -});
150 +The LangChain provider can be configured with various options:
151
145 -// Get tools for the chain
146 -const tools = await composio.tools.get('user123', {
147 - toolkits: ['gmail'],
148 -});
149 -
150 -// Setup vector store and retriever
151 -const vectorstore = await MemoryVectorStore.fromTexts(
152 - ['some text', 'more text'],
153 - [{ id: 1 }, { id: 2 }],
154 - new OpenAIEmbeddings()
155 -);
156 -
157 -const retriever = vectorstore.asRetriever();
158 -
159 -// Create RAG chain
160 -const template = `Answer the question based only on the following context:
161 -{context}
162 -
163 -Question: {question}`;
164 -
165 -const prompt = ChatPromptTemplate.fromTemplate(template);
166 -const model = new ChatOpenAI({
167 - modelName: 'gpt-4',
168 - streaming: true,
169 -});
170 -
171 -const chain = RunnableSequence.from([
172 - {
173 - context: retriever.pipe(formatDocs),
174 - question: new RunnablePassthrough(),
152 +```typescript
153 +const provider = new LangChainProvider({
154 + // Default model configuration
155 + model: new ChatOpenAI({
156 + modelName: 'gpt-4',
157 + streaming: true,
158 + }),
159 + // Custom execution modifiers
160 + modifiers: {
161 + beforeExecute: params => {
162 + // Transform parameters before execution
163 + return params;
164 + },
165 + afterExecute: response => {
166 + // Transform response after execution
167 + return response;
168 + },
169 },
176 - prompt,
177 - model,
178 - new StringOutputParser(),
179 -]);
180 -
181 -// Stream the response
182 -const stream = await chain.stream('What is the answer?');
183 -
184 -for await (const chunk of stream) {
185 - console.log(chunk);
186 -}
170 + // Enable tracing
171 + tracing: true,
172 +});
173 ```
174
175 ## API Reference
packages/providers/mastra/README.md
+86 -23
@@ -7,17 +7,32 @@ Agentic Provider for Mastra in Composio SDK.
7 - **Full Modifier Support**: Support for both schema and execution modifiers
8 - **Tool Execution**: Execute tools with proper parameter handling
9 - **Type Safety**: Full TypeScript support with proper type definitions
10 +- **Agentic Capabilities**: Full support for autonomous agent behavior
11 +- **Streaming Support**: First-class support for streaming responses
12 +- **Custom Execution**: Support for custom tool execution strategies
13
14 ## Installation
15
16 ```bash
14 -npm install @composio/mastra
17 +npm install @composio/core @composio/mastra
18 # or
16 -yarn add @composio/mastra
19 +yarn add @composio/core @composio/mastra
20 # or
18 -pnpm add @composio/mastra
21 +pnpm add @composio/core @composio/mastra
22 ```
23
24 +## Environment Variables
25 +
26 +Required environment variables:
27 +
28 +- `COMPOSIO_API_KEY`: Your Composio API key
29 +- `MASTRA_API_KEY`: Your Mastra API key
30 +
31 +Optional environment variables:
32 +
33 +- `MASTRA_API_URL`: Custom API base URL (defaults to Mastra's API)
34 +- `MASTRA_DEBUG`: Enable debug logging (set to "true")
35 +
36 ## Quick Start
37
38 ```typescript
@@ -26,8 +41,10 @@ import { MastraProvider } from '@composio/mastra';
41
42 // Initialize Composio with Mastra provider
43 const composio = new Composio({
29 - apiKey: 'your-composio-api-key',
30 - provider: new MastraProvider(),
44 + apiKey: process.env.COMPOSIO_API_KEY,
45 + provider: new MastraProvider({
46 + apiKey: process.env.MASTRA_API_KEY,
47 + }),
48 });
49
50 // Get available tools
@@ -37,45 +54,91 @@ const tools = await composio.tools.get('user123', {
54 });
55 ```
56
40 -## Usage Examples
57 +## Examples
58
42 -### Basic Example
59 +Check out our complete example implementations:
60
44 -```typescript
45 -import { Composio } from '@composio/core';
46 -import { MastraProvider } from '@composio/mastra';
61 +- [Basic Mastra Integration](../../examples/mastra/src/index.ts)
62
48 -// Initialize Composio
49 -const composio = new Composio({
50 - apiKey: process.env.COMPOSIO_API_KEY,
51 - provider: new MastraProvider(),
52 -});
63 +## Provider Configuration
64
54 -// Get tools
55 -const tools = await composio.tools.get('user123', {
56 - toolkits: ['gmail'],
57 -});
65 +The Mastra provider can be configured with various options:
66
59 -// Use tools with Mastra
60 -// Add your usage example here
67 +```typescript
68 +const provider = new MastraProvider({
69 + // API configuration
70 + apiKey: process.env.MASTRA_API_KEY,
71 + apiUrl: 'https://custom-api.mastra.ai',
72 + // Debug mode
73 + debug: true,
74 + // Custom execution modifiers
75 + modifiers: {
76 + beforeExecute: params => {
77 + // Transform parameters before execution
78 + return params;
79 + },
80 + afterExecute: response => {
81 + // Transform response after execution
82 + return response;
83 + },
84 + },
85 + // Custom tool execution strategy
86 + executionStrategy: {
87 + maxRetries: 3,
88 + retryDelay: 1000,
89 + timeout: 30000,
90 + },
91 +});
92 ```
93
94 ## API Reference
95
96 ### MastraProvider Class
97
67 -The `MastraProvider` class extends `BaseAgenticProvider` and provides mastra-specific functionality.
98 +The `MastraProvider` class extends `BaseAgenticProvider` and provides Mastra-specific functionality.
99 +
100 +#### Constructor
101 +
102 +```typescript
103 +new MastraProvider(options?: MastraProviderOptions)
104 +```
105 +
106 +Options:
107 +
108 +- `apiKey`: Your Mastra API key
109 +- `apiUrl`: Custom API base URL
110 +- `debug`: Enable debug logging
111 +- `modifiers`: Custom execution modifiers
112 +- `executionStrategy`: Custom tool execution strategy
113
114 #### Methods
115
116 ##### `wrapTool(tool: Tool, executeTool: ExecuteToolFn): MastraTool`
117
73 -Wraps a tool in the mastra format.
118 +Wraps a tool in the Mastra format.
119
120 ```typescript
121 const tool = provider.wrapTool(composioTool, executeTool);
122 ```
123
124 +##### `wrapTools(tools: Tool[], executeTool: ExecuteToolFn): MastraToolCollection`
125 +
126 +Wraps multiple tools in the Mastra format.
127 +
128 +```typescript
129 +const tools = provider.wrapTools(composioTools, executeTool);
130 +```
131 +
132 +##### `executeToolCall(userId: string, toolCall: MastraToolCall, options?: ExecuteToolFnOptions): Promise<string>`
133 +
134 +Executes a tool call from Mastra and returns the result.
135 +
136 +```typescript
137 +const result = await provider.executeToolCall('user123', toolCall, {
138 + connectedAccountId: 'account123',
139 +});
140 +```
141 +
142 ## Contributing
143
144 We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
packages/providers/openai/README.md
+39 -1
@@ -21,6 +21,18 @@ yarn add @composio/openai
21 pnpm add @composio/openai
22 ```
23
24 +## Environment Variables
25 +
26 +Required environment variables:
27 +
28 +- `COMPOSIO_API_KEY`: Your Composio API key
29 +- `OPENAI_API_KEY`: Your OpenAI API key
30 +
31 +Optional environment variables:
32 +
33 +- `OPENAI_API_BASE`: Custom API base URL (for Azure OpenAI)
34 +- `OPENAI_ORGANIZATION`: OpenAI organization ID
35 +
36 ## Quick Start
37
38 ```typescript
@@ -43,7 +55,14 @@ const tools = await composio.tools.get('user123', {
55 const sendEmailTool = await composio.tools.get('user123', 'GMAIL_SEND_EMAIL');
56 ```
57
46 -## Usage Examples
58 +## Examples
59 +
60 +Check out our complete example implementations:
61 +
62 +- [Basic OpenAI Integration](../../examples/openai/src/index.ts)
63 +- [Chat Completions Example](../../examples/openai/src/chat-completions.ts)
64 +- [Assistants Example](../../examples/openai/src/assistants.ts)
65 +- [Tools Example](../../examples/openai/src/tools.ts)
66
67 ### Basic Chat Completion with Streaming
68
@@ -197,6 +216,25 @@ export async function POST(req: Request) {
216 }
217 ```
218
219 +## Provider Configuration
220 +
221 +The OpenAI provider can be configured with various options:
222 +
223 +```typescript
224 +const provider = new OpenAIProvider({
225 + // Custom base URL for Azure OpenAI
226 + baseURL: 'https://your-azure-endpoint.openai.azure.com',
227 + // Organization ID
228 + organization: 'org-123',
229 + // Default model to use
230 + defaultModel: 'gpt-4',
231 + // Custom headers
232 + headers: {
233 + 'api-key': process.env.OPENAI_API_KEY,
234 + },
235 +});
236 +```
237 +
238 ## API Reference
239
240 ### OpenAIProvider Class
packages/providers/vercel/README.md
+37 -37
@@ -14,13 +14,25 @@ The Vercel AI SDK provider for Composio SDK, providing seamless integration with
14 ## Installation
15
16 ```bash
17 -npm install @composio/vercel
17 +npm install @composio/vercel ai
18 # or
19 -yarn add @composio/vercel
19 +yarn add @composio/vercel ai
20 # or
21 -pnpm add @composio/vercel
21 +pnpm add @composio/vercel ai
22 ```
23
24 +## Environment Variables
25 +
26 +Required environment variables:
27 +
28 +- `COMPOSIO_API_KEY`: Your Composio API key
29 +
30 +Optional environment variables (based on model choice):
31 +
32 +- `OPENAI_API_KEY`: Your OpenAI API key (if using OpenAI)
33 +- `ANTHROPIC_API_KEY`: Your Anthropic API key (if using Anthropic)
34 +- `GEMINI_API_KEY`: Your Google AI API key (if using Gemini)
35 +
36 ## Quick Start
37
38 ```typescript
@@ -43,7 +55,11 @@ const tools = await composio.tools.get('user123', {
55 const sendEmailTool = await composio.tools.get('user123', 'GMAIL_SEND_EMAIL');
56 ```
57
46 -## Usage Examples
58 +## Examples
59 +
60 +Check out our complete example implementations:
61 +
62 +- [Basic Vercel Integration](../../examples/vercel/src/index.ts)
63
64 ### Basic Chat Completion with Streaming
65
@@ -140,42 +156,26 @@ export async function POST(req: Request) {
156 }
157 ```
158
143 -### Structured Output with Streaming
144 -
145 -```typescript
146 -import { Composio } from '@composio/core';
147 -import { VercelProvider } from '@composio/vercel';
148 -import { streamObject } from 'ai';
149 -
150 -const composio = new Composio({
151 - apiKey: process.env.COMPOSIO_API_KEY,
152 - provider: new VercelProvider(),
153 -});
159 +## Provider Configuration
160
155 -// Example API route that returns structured data
156 -export async function POST(req: Request) {
157 - const { messages } = await req.json();
158 - const tools = await composio.tools.get('user123', {
159 - toolkits: ['gmail'],
160 - });
161 +The Vercel provider can be configured with various options:
162
162 - const stream = streamObject({
163 - model: openai('gpt-4'),
164 - messages,
165 - tools,
166 - schema: {
167 - type: 'object',
168 - properties: {
169 - name: { type: 'string' },
170 - age: { type: 'number' },
171 - interests: { type: 'array', items: { type: 'string' } },
172 - },
173 - required: ['name', 'age', 'interests'],
163 +```typescript
164 +const provider = new VercelProvider({
165 + // Default model configuration
166 + model: openai('gpt-4'),
167 + // Custom execution modifiers
168 + modifiers: {
169 + beforeExecute: params => {
170 + // Transform parameters before execution
171 + return params;
172 },
175 - });
176 -
177 - return stream.toDataStreamResponse();
178 -}
173 + afterExecute: response => {
174 + // Transform response after execution
175 + return response;
176 + },
177 + },
178 +});
179 ```
180
181 ## API Reference