Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 23, 01:45 UTC
Add ability to create examples
haxzie committed
May 23, 2025 at 11:34 UTC
fcd797b42da6910420b56358d8e13b889686a358
10 files changed
+372
-2
examples/triggers/.env.example
new
+6
@@ -0,0 +1,6 @@
1
+# Composio API Key - Get it from https://app.composio.dev
2
+COMPOSIO_API_KEY=your_composio_api_key_here
3
+
4
+# Add other environment variables as needed for your example
5
+# OPENAI_API_KEY=your_openai_api_key_here
6
+# ANTHROPIC_API_KEY=your_anthropic_api_key_here
examples/triggers/README.md
new
+53
@@ -0,0 +1,53 @@
1
+# Triggers Example
2
+
3
+This example demonstrates how to use Composio SDK for triggers.
4
+
5
+## Setup
6
+
7
+1. **Install dependencies:**
8
+ ```bash
9
+ pnpm install
10
+ ```
11
+
12
+2. **Configure environment:**
13
+ ```bash
14
+ cp .env.example .env
15
+ ```
16
+
17
+ Then edit `.env` and add your API keys:
18
+ - `COMPOSIO_API_KEY`: Get it from [Composio Dashboard](https://app.composio.dev)
19
+
20
+## Running the Example
21
+
22
+```bash
23
+# Run the example
24
+pnpm start
25
+
26
+# Run in development mode (with file watching)
27
+pnpm dev
28
+```
29
+
30
+## What This Example Does
31
+
32
+- Initializes Composio SDK
33
+- Fetches available tools
34
+- Demonstrates basic usage patterns
35
+
36
+## Customization
37
+
38
+Edit `src/index.ts` to:
39
+- Add specific apps you want to integrate with
40
+- Implement your business logic
41
+- Add error handling and logging
42
+
43
+## Related Examples
44
+
45
+- [OpenAI Example](../openai) - Shows integration with OpenAI
46
+- [LangChain Example](../langchain) - Shows integration with LangChain
47
+- [More Examples](../) - Browse all available examples
48
+
49
+## Support
50
+
51
+- [Documentation](https://docs.composio.dev)
52
+- [Discord Community](https://discord.gg/composio)
53
+- [GitHub Issues](https://github.com/composio/composio/issues)
examples/triggers/package.json
new
+24
@@ -0,0 +1,24 @@
1
+{
2
+ "name": "triggers-example",
3
+ "private": true,
4
+ "version": "0.1.0",
5
+ "description": "Example project for Triggers",
6
+ "main": "src/index.ts",
7
+ "scripts": {
8
+ "start": "bun src/index.ts",
9
+ "dev": "bun --watch src/index.ts",
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": ["composio", "example", "triggers"],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "packageManager": "pnpm@10.8.0",
16
+ "dependencies": {
17
+ "@composio/core": "workspace:*",
18
+ "dotenv": "^16.4.1"
19
+ },
20
+ "devDependencies": {
21
+ "@types/bun": "^1.2.9",
22
+ "typescript": "^5.8.3"
23
+ }
24
+}
examples/triggers/src/index.ts
new
+46
@@ -0,0 +1,46 @@
1
+/**
2
+ * Triggers Example
3
+ *
4
+ * This example demonstrates how to use Composio SDK for triggers.
5
+ *
6
+ * Prerequisites:
7
+ * 1. Set up your COMPOSIO_API_KEY in the .env file
8
+ * 2. Install dependencies: pnpm install
9
+ * 3. Run the example: pnpm start
10
+ */
11
+
12
+import { Composio } from '@composio/core';
13
+import 'dotenv/config';
14
+
15
+/**
16
+ * Initialize Composio
17
+ */
18
+const composio = new Composio({
19
+ apiKey: process.env.COMPOSIO_API_KEY,
20
+});
21
+
22
+/**
23
+ * Main function to run the example
24
+ */
25
+async function main() {
26
+ try {
27
+ console.log('🚀 Starting Triggers Example...');
28
+
29
+ // Get available tools
30
+ const tools = await composio.tools.get('default', {
31
+ // Specify the apps you want to use
32
+ // apps: ['gmail', 'googlecalendar'],
33
+ limit: 10,
34
+ });
35
+
36
+ console.log(`✅ Found ${tools.length} tools`);
37
+
38
+ // TODO: Add your example implementation here
39
+ console.log('📝 Implement your triggers logic here!');
40
+ } catch (error) {
41
+ console.error('❌ Error running example:', error);
42
+ }
43
+}
44
+
45
+// Run the example
46
+main().catch(console.error);
examples/triggers/tsconfig.json
new
+16
@@ -0,0 +1,16 @@
1
+{
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "declaration": true,
6
+ "declarationDir": "./dist",
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "moduleResolution": "node",
12
+ "skipLibCheck": true,
13
+ "resolveJsonModule": true
14
+ },
15
+ "include": ["src"]
16
+}
package.json
+1
@@ -16,6 +16,7 @@
16
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"",
17
"prepare": "husky",
18
"create:provider": "bash scripts/create-provider.sh",
19
+ "create:example": "bash scripts/create-example.sh",
20
"check:peer-deps": "tsx scripts/check-peer-deps.ts",
21
"update:peer-deps": "tsx scripts/update-peer-deps.ts",
22
"prepublish": "pnpm run build",
packages/core/src/models/Tools.ts
+1
-1
@@ -263,7 +263,7 @@ export class Tools<
263
toolkit_slug: queryParams.data.toolkits?.join(','),
264
cursor: queryParams.data.cursor,
265
important: queryParams.data.important,
266
- limit: queryParams.data.limit,
266
+ limit: queryParams.data.limit?.toString(),
267
search: queryParams.data.search,
268
});
269
packages/core/src/types/tool.types.ts
+1
-1
@@ -59,7 +59,7 @@ export const ToolListParamsSchema = z.object({
59
tools: z.array(z.string()).optional(),
60
cursor: z.string().optional(),
61
important: z.string().optional(),
62
- limit: z.string().optional(),
62
+ limit: z.number().optional(),
63
search: z.string().optional(),
64
toolkits: z.array(z.string()).optional(),
65
});
pnpm-lock.yaml
+16
@@ -183,6 +183,22 @@ importers:
183
specifier: ^5.8.3
184
version: 5.8.3
185
186
+ examples/triggers:
187
+ dependencies:
188
+ '@composio/core':
189
+ specifier: workspace:*
190
+ version: link:../../packages/core
191
+ dotenv:
192
+ specifier: ^16.4.1
193
+ version: 16.5.0
194
+ devDependencies:
195
+ '@types/bun':
196
+ specifier: ^1.2.9
197
+ version: 1.2.13
198
+ typescript:
199
+ specifier: ^5.8.3
200
+ version: 5.8.3
201
+
202
examples/vercel:
203
dependencies:
204
'@ai-sdk/openai':
scripts/create-example.sh
new
+208
@@ -0,0 +1,208 @@
1
+#!/bin/bash
2
+
3
+# Check if example name is provided
4
+if [ -z "$1" ]; then
5
+ echo "Please provide an example name"
6
+ echo "Usage: pnpm create:example <example-name>"
7
+ exit 1
8
+fi
9
+
10
+EXAMPLE_NAME=$1
11
+EXAMPLE_PATH="examples/$EXAMPLE_NAME"
12
+CAPITAL_EXAMPLE_NAME="$(tr '[:lower:]' '[:upper:]' <<< ${EXAMPLE_NAME:0:1})${EXAMPLE_NAME:1}"
13
+
14
+# Check if example directory already exists
15
+if [ -d "$EXAMPLE_PATH" ]; then
16
+ echo "❌ Example '$EXAMPLE_NAME' already exists in $EXAMPLE_PATH"
17
+ exit 1
18
+fi
19
+
20
+# Create directory structure
21
+mkdir -p "$EXAMPLE_PATH/src"
22
+
23
+# Create package.json
24
+cat > "$EXAMPLE_PATH/package.json" << EOL
25
+{
26
+ "name": "${EXAMPLE_NAME}-example",
27
+ "private": true,
28
+ "version": "0.1.0",
29
+ "description": "Example project for ${CAPITAL_EXAMPLE_NAME}",
30
+ "main": "src/index.ts",
31
+ "scripts": {
32
+ "start": "bun src/index.ts",
33
+ "dev": "bun --watch src/index.ts",
34
+ "test": "echo \"Error: no test specified\" && exit 1"
35
+ },
36
+ "keywords": ["composio", "example", "${EXAMPLE_NAME}"],
37
+ "author": "",
38
+ "license": "ISC",
39
+ "packageManager": "pnpm@10.8.0",
40
+ "dependencies": {
41
+ "@composio/core": "workspace:*",
42
+ "dotenv": "^16.4.1"
43
+ },
44
+ "devDependencies": {
45
+ "@types/bun": "^1.2.9",
46
+ "typescript": "^5.8.3"
47
+ }
48
+}
49
+EOL
50
+
51
+# Create tsconfig.json
52
+cat > "$EXAMPLE_PATH/tsconfig.json" << EOL
53
+{
54
+ "compilerOptions": {
55
+ "target": "ESNext",
56
+ "module": "ESNext",
57
+ "declaration": true,
58
+ "declarationDir": "./dist",
59
+ "outDir": "./dist",
60
+ "rootDir": "./src",
61
+ "strict": true,
62
+ "esModuleInterop": true,
63
+ "moduleResolution": "node",
64
+ "skipLibCheck": true,
65
+ "resolveJsonModule": true
66
+ },
67
+ "include": ["src"]
68
+}
69
+EOL
70
+
71
+# Create .env.example
72
+cat > "$EXAMPLE_PATH/.env.example" << EOL
73
+# Composio API Key - Get it from https://app.composio.dev
74
+COMPOSIO_API_KEY=your_composio_api_key_here
75
+
76
+# Add other environment variables as needed for your example
77
+# OPENAI_API_KEY=your_openai_api_key_here
78
+# ANTHROPIC_API_KEY=your_anthropic_api_key_here
79
+EOL
80
+
81
+# Create .env (copy of .env.example)
82
+cp "$EXAMPLE_PATH/.env.example" "$EXAMPLE_PATH/.env"
83
+
84
+# Create src/index.ts
85
+cat > "$EXAMPLE_PATH/src/index.ts" << EOL
86
+/**
87
+ * ${CAPITAL_EXAMPLE_NAME} Example
88
+ *
89
+ * This example demonstrates how to use Composio SDK for ${EXAMPLE_NAME}.
90
+ *
91
+ * Prerequisites:
92
+ * 1. Set up your COMPOSIO_API_KEY in the .env file
93
+ * 3. Run the example: pnpm start
94
+ */
95
+
96
+import { Composio } from '@composio/core';
97
+import 'dotenv/config';
98
+
99
+/**
100
+ * Initialize Composio
101
+ */
102
+const composio = new Composio({
103
+ apiKey: process.env.COMPOSIO_API_KEY,
104
+});
105
+
106
+/**
107
+ * Main function to run the example
108
+ */
109
+async function main() {
110
+ try {
111
+ console.log('🚀 Starting ${CAPITAL_EXAMPLE_NAME} Example...');
112
+
113
+ // Get available tools
114
+ const tools = await composio.tools.get('default', {
115
+ // Specify the apps you want to use
116
+ toolkits: ['gmail', 'googlecalendar'],
117
+ limit: 10,
118
+ });
119
+
120
+ console.log(\`✅ Found \${tools.length} tools\`);
121
+
122
+ // TODO: Add your example implementation here
123
+ console.log('📝 Implement your ${EXAMPLE_NAME} logic here!');
124
+
125
+ } catch (error) {
126
+ console.error('❌ Error running example:', error);
127
+ }
128
+}
129
+
130
+// Run the example
131
+main().catch(console.error);
132
+EOL
133
+
134
+# Create README.md
135
+cat > "$EXAMPLE_PATH/README.md" << EOL
136
+# ${CAPITAL_EXAMPLE_NAME} Example
137
+
138
+This example demonstrates how to use Composio SDK for ${EXAMPLE_NAME}.
139
+
140
+## Setup
141
+
142
+1. **Install dependencies:**
143
+ \`\`\`bash
144
+ pnpm install
145
+ \`\`\`
146
+
147
+2. **Configure environment:**
148
+ \`\`\`bash
149
+ cp .env.example .env
150
+ \`\`\`
151
+
152
+ Then edit \`.env\` and add your API keys:
153
+ - \`COMPOSIO_API_KEY\`: Get it from [Composio Dashboard](https://app.composio.dev)
154
+
155
+## Running the Example
156
+
157
+\`\`\`bash
158
+# Run the example
159
+pnpm start
160
+
161
+# Run in development mode (with file watching)
162
+pnpm dev
163
+\`\`\`
164
+
165
+## What This Example Does
166
+
167
+- Initializes Composio SDK
168
+- Fetches available tools
169
+- Demonstrates basic usage patterns
170
+
171
+## Customization
172
+
173
+Edit \`src/index.ts\` to:
174
+- Add specific apps you want to integrate with
175
+- Implement your business logic
176
+- Add error handling and logging
177
+
178
+## Related Examples
179
+
180
+- [OpenAI Example](../openai) - Shows integration with OpenAI
181
+- [LangChain Example](../langchain) - Shows integration with LangChain
182
+- [More Examples](../) - Browse all available examples
183
+
184
+## Support
185
+
186
+- [Documentation](https://docs.composio.dev)
187
+- [Discord Community](https://discord.gg/composio)
188
+- [GitHub Issues](https://github.com/composio/composio/issues)
189
+EOL
190
+
191
+# Install dependencies using pnpm
192
+cd "$EXAMPLE_PATH" && pnpm install
193
+
194
+echo "✨ Created new example at $EXAMPLE_PATH"
195
+echo "✨ Dependencies installed successfully"
196
+echo ""
197
+echo "📁 Generated files:"
198
+echo " - package.json"
199
+echo " - tsconfig.json"
200
+echo " - .env.example"
201
+echo " - .env"
202
+echo " - src/index.ts"
203
+echo " - README.md"
204
+echo ""
205
+echo "🚀 Next steps:"
206
+echo " 1. cd $EXAMPLE_PATH"
207
+echo " 2. Edit .env and add your COMPOSIO_API_KEY"
208
+echo " 3. pnpm start"
\ No newline at end of file