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

Add wrapper docs

haxzie committed Apr 18, 2025 at 13:05 UTC 8d4bacbba16e6175f1cfb149c884ed9717f202f2
2 files changed +154
packages/wrappers/.gitkeep
packages/wrappers/README.md new
+154
@@ -0,0 +1,154 @@
1 +# Composio Wrappers
2 +
3 +> **Note:** This is a work in progress. The wrapper system is under active development and may change in future releases.
4 +
5 +## Overview
6 +
7 +Composio Wrappers provide runtime-specific implementations of Composio Core functionality. These wrappers adapt the core functionality to work in different environments such as:
8 +
9 +- Browser environments
10 +- Edge runtimes
11 +- Serverless environments
12 +- Node.js environments
13 +- Mobile environments
14 +
15 +## Available Interfaces
16 +
17 +### Core Components
18 +
19 +- **@composio/core**: The main package containing core functionality and interfaces
20 +- **BaseComposioToolset**: Abstract base class for creating custom toolsets
21 +
22 +### Telemetry
23 +
24 +Composio provides built-in telemetry capabilities that can be used in your wrappers:
25 +
26 +- **Telemetry**: Core telemetry implementation
27 +- **BaseTelemetryTransport**: Base class for creating custom telemetry transports
28 +
29 +### Models
30 +
31 +The following models are available for extension:
32 +
33 +- **Tools**: Manage and interact with tools
34 +- **Toolkits**: Handle collections of tools
35 +- **Triggers**: Manage event triggers and subscriptions
36 +- **AuthConfigs**: Handle authentication configurations
37 +- **ConnectedAccounts**: Manage connected accounts
38 +- **Session**: Handle session management
39 +
40 +## Creating a Runtime Wrapper
41 +
42 +To create a runtime-specific wrapper, you need to implement the core functionality while adapting it to your target environment:
43 +
44 +```typescript
45 +import { Composio } from '@composio/core';
46 +
47 +class BrowserRuntimeWrapper {
48 + private composio: Composio;
49 +
50 + constructor(config: ComposioConfig) {
51 + // Initialize with browser-specific configurations
52 + this.composio = new Composio({
53 + ...config,
54 + // Add browser-specific configurations
55 + allowTracking: true,
56 + telemetryTransport: new BrowserTelemetryTransport()
57 + });
58 + }
59 +
60 + // Implement browser-specific methods
61 + async initialize() {
62 + // Browser-specific initialization
63 + }
64 +
65 + // Override or extend core methods as needed
66 + async getTools() {
67 + // Browser-specific implementation
68 + return this.composio.getTools();
69 + }
70 +}
71 +```
72 +
73 +## Configuration
74 +
75 +Wrappers can be configured using the `ComposioConfig` interface with runtime-specific options:
76 +
77 +```typescript
78 +const config = {
79 + apiKey: 'your-api-key',
80 + baseURL: 'https://api.composio.dev',
81 + allowTracking: true,
82 + allowTracing: true,
83 + // Runtime-specific configurations
84 + runtime: 'browser',
85 + userId: 'user-id',
86 + connectedAccountIds: {},
87 + telemetryTransport: new RuntimeSpecificTelemetryTransport()
88 +};
89 +```
90 +
91 +## Best Practices
92 +
93 +1. **Environment Detection**: Implement proper environment detection for your target runtime
94 +2. **Telemetry Integration**: Implement telemetry that works in your target environment
95 +3. **Error Handling**: Implement runtime-specific error handling
96 +4. **Type Safety**: Use TypeScript for better type safety and developer experience
97 +5. **Documentation**: Document your wrapper's functionality and usage
98 +6. **Polyfills**: Include necessary polyfills for your target environment
99 +7. **Size Optimization**: Optimize bundle size for your target environment
100 +
101 +## Example: Browser Wrapper
102 +
103 +Here's a simple example of creating a browser-specific wrapper:
104 +
105 +```typescript
106 +import { Composio } from '@composio/core';
107 +
108 +class BrowserWrapper {
109 + private composio: Composio;
110 +
111 + constructor(config: ComposioConfig) {
112 + // Initialize with browser-specific configurations
113 + this.composio = new Composio({
114 + ...config,
115 + runtime: 'browser',
116 + telemetryTransport: new BrowserTelemetryTransport()
117 + });
118 + }
119 +
120 + async initialize() {
121 + // Check if running in browser
122 + if (typeof window === 'undefined') {
123 + throw new Error('This wrapper is only for browser environments');
124 + }
125 +
126 + // Initialize browser-specific features
127 + await this.initializeBrowserFeatures();
128 + }
129 +
130 + private async initializeBrowserFeatures() {
131 + // Initialize browser-specific features
132 + // e.g., service workers, indexedDB, etc.
133 + }
134 +
135 + // Browser-specific implementation of core methods
136 + async getTools() {
137 + // Add browser-specific caching or other optimizations
138 + return this.composio.getTools();
139 + }
140 +}
141 +```
142 +
143 +## Contributing
144 +
145 +We welcome contributions to the wrapper system. Please follow these guidelines:
146 +
147 +1. Create a new package in the `packages/wrappers` directory
148 +2. Follow the existing code structure and patterns
149 +3. Include proper documentation and tests
150 +4. Submit a pull request with a clear description of your changes
151 +
152 +## License
153 +
154 +This project is licensed under the ISC License.