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

next
sh 207 lines 4.79 KB
Raw
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="ts/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 "dependencies": {
40 "@composio/core": "workspace:*",
41 "dotenv": "^16.4.1"
42 },
43 "devDependencies": {
44 "@types/bun": "^1.4.3",
45 "typescript": "catalog:"
46 }
47 }
48 EOL
49
50 # Create tsconfig.json
51 cat > "$EXAMPLE_PATH/tsconfig.json" << EOL
52 {
53 "compilerOptions": {
54 "target": "es2022",
55 "module": "esnext",
56 "declaration": true,
57 "declarationDir": "./dist",
58 "outDir": "./dist",
59 "rootDir": "./src",
60 "strict": true,
61 "esModuleInterop": true,
62 "moduleResolution": "bundler",
63 "skipLibCheck": true,
64 "resolveJsonModule": true
65 },
66 "include": ["src"]
67 }
68 EOL
69
70 # Create .env.example
71 cat > "$EXAMPLE_PATH/.env.example" << EOL
72 # Composio API Key - Get it from https://app.composio.dev
73 COMPOSIO_API_KEY=your_composio_api_key_here
74
75 # Add other environment variables as needed for your example
76 # OPENAI_API_KEY=your_openai_api_key_here
77 # ANTHROPIC_API_KEY=your_anthropic_api_key_here
78 EOL
79
80 # Create .env (copy of .env.example)
81 cp "$EXAMPLE_PATH/.env.example" "$EXAMPLE_PATH/.env"
82
83 # Create src/index.ts
84 cat > "$EXAMPLE_PATH/src/index.ts" << EOL
85 /**
86 * ${CAPITAL_EXAMPLE_NAME} Example
87 *
88 * This example demonstrates how to use Composio SDK for ${EXAMPLE_NAME}.
89 *
90 * Prerequisites:
91 * 1. Set up your COMPOSIO_API_KEY in the .env file
92 * 3. Run the example: pnpm start
93 */
94
95 import { Composio } from '@composio/core';
96 import 'dotenv/config';
97
98 /**
99 * Initialize Composio
100 */
101 const composio = new Composio({
102 apiKey: process.env.COMPOSIO_API_KEY,
103 });
104
105 /**
106 * Main function to run the example
107 */
108 async function main() {
109 try {
110 console.log('🚀 Starting ${CAPITAL_EXAMPLE_NAME} Example...');
111
112 // Get available tools
113 const tools = await composio.tools.get('default', {
114 // Specify the apps you want to use
115 toolkits: ['gmail', 'googlecalendar'],
116 limit: 10,
117 });
118
119 console.log(\`✅ Found \${tools.length} tools\`);
120
121 // TODO: Add your example implementation here
122 console.log('📝 Implement your ${EXAMPLE_NAME} logic here!');
123
124 } catch (error) {
125 console.error('❌ Error running example:', error);
126 }
127 }
128
129 // Run the example
130 main().catch(console.error);
131 EOL
132
133 # Create README.md
134 cat > "$EXAMPLE_PATH/README.md" << EOL
135 # ${CAPITAL_EXAMPLE_NAME} Example
136
137 This example demonstrates how to use Composio SDK for ${EXAMPLE_NAME}.
138
139 ## Setup
140
141 1. **Install dependencies:**
142 \`\`\`bash
143 pnpm install
144 \`\`\`
145
146 2. **Configure environment:**
147 \`\`\`bash
148 cp .env.example .env
149 \`\`\`
150
151 Then edit \`.env\` and add your API keys:
152 - \`COMPOSIO_API_KEY\`: Get it from [Composio Dashboard](https://app.composio.dev)
153
154 ## Running the Example
155
156 \`\`\`bash
157 # Run the example
158 pnpm start
159
160 # Run in development mode (with file watching)
161 pnpm dev
162 \`\`\`
163
164 ## What This Example Does
165
166 - Initializes Composio SDK
167 - Fetches available tools
168 - Demonstrates basic usage patterns
169
170 ## Customization
171
172 Edit \`src/index.ts\` to:
173 - Add specific apps you want to integrate with
174 - Implement your business logic
175 - Add error handling and logging
176
177 ## Related Examples
178
179 - [OpenAI Example](../openai) - Shows integration with OpenAI
180 - [LangChain Example](../langchain) - Shows integration with LangChain
181 - [More Examples](../) - Browse all available examples
182
183 ## Support
184
185 - [Documentation](https://docs.composio.dev)
186 - [Discord Community](https://discord.gg/composio)
187 - [GitHub Issues](https://github.com/composio/composio/issues)
188 EOL
189
190 # Install dependencies using pnpm
191 cd "$EXAMPLE_PATH" && pnpm install
192
193 echo "✨ Created new example at $EXAMPLE_PATH"
194 echo "✨ Dependencies installed successfully"
195 echo ""
196 echo "📁 Generated files:"
197 echo " - package.json"
198 echo " - tsconfig.json"
199 echo " - .env.example"
200 echo " - .env"
201 echo " - src/index.ts"
202 echo " - README.md"
203 echo ""
204 echo "🚀 Next steps:"
205 echo " 1. cd $EXAMPLE_PATH"
206 echo " 2. Edit .env and add your COMPOSIO_API_KEY"
207 echo " 3. pnpm start"