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
ts 48 lines 1.06 KB
Raw
1 /**
2 * Session-management Example
3 *
4 * This example demonstrates how to use Composio SDK for session-management.
5 *
6 * Prerequisites:
7 * 1. Set up your COMPOSIO_API_KEY in the .env file
8 * 3. Run the example: pnpm start
9 */
10
11 import { Composio } from '@composio/core';
12 import 'dotenv/config';
13
14 /**
15 * Initialize Composio
16 */
17 const composio = new Composio({
18 apiKey: process.env.COMPOSIO_API_KEY,
19 });
20
21 /**
22 * Main function to run the example
23 */
24 async function main() {
25 try {
26 console.log('🚀 Starting Session-management Example...');
27
28 // create a session with custom request options
29 const session = composio.createSession({
30 headers: {
31 'x-request-id': 'custom-value',
32 },
33 });
34
35 // use the session to make API calls
36 const tools = await session.tools.get('default', 'HACKERNEWS_GET_USER');
37 console.log(`✅ Found ${tools.length} tools`);
38 } catch (error) {
39 console.error('❌ Error running example:', error);
40 process.exitCode = 1;
41 }
42 }
43
44 // Run the example
45 main().catch(error => {
46 console.error(error);
47 process.exitCode = 1;
48 });