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

base feedback and fix types in examples

Rahul Tarak committed May 15, 2025 at 16:38 UTC bdfd652fbba7da339ed1a87c3419e86699d8f667
7 files changed +95 -73
examples/connected-accounts/src/index.ts
+10 -1
@@ -11,8 +11,14 @@ const composio = new Composio({
11 apiKey: process.env.COMPOSIO_API_KEY,
12 });
13
14 +// i think this should be a discriminated union, like only tools or toolkits or search can be there, inside the filter
15 +// the other ones should be third object {} options
16 const tools = await composio.tools.get('user123', {
17 tools: ['HACKERNEWS_GET_USER'],
18 + cursor: '123',
19 + important: '', // what is this doing do we need it can we remove it?
20 + limit: '10',
21 + toolkits: ['HACKERNEWS'],
22 });
23
24 /**
@@ -20,8 +26,9 @@ const tools = await composio.tools.get('user123', {
26 */
27 const authConfig = await composio.createAuthConfig('my-toolkit', {
28 type: AuthConfigTypes.CUSTOM,
23 - authScheme: AuthSchemeTypes.API_KEY,
29 + authScheme: AuthSchemeTypes.BASIC,
30 credentials: {
31 + // this should error not like the credentials should come from the auth scheme type
32 apiKey: '1234567890',
33 },
34 });
@@ -29,6 +36,8 @@ const authConfig = await composio.createAuthConfig('my-toolkit', {
36 /**
37 * Create a new connected account
38 */
39 +// hmm so the createConnectedAccount here doesn't feel like i am initiating a connection request -> that is probably why it was called initiateConnection
40 +// connectedAccounts.initiate or initialize work
41 const ConnectionRequest = await composio.createConnectedAccount('default', authConfig.id);
42 const connectedAccount = await ConnectionRequest.waitForConnection();
43
examples/openai/src/examples.ts
+1 -1
@@ -5,6 +5,6 @@ const composio = new Composio({
5 apiKey: process.env.COMPOSIO_API_KEY,
6 });
7
8 -const tool = await composio.getToolBySlug('HACKERNEWS_GET_USER');
8 +const tool = await composio.getToolBySlug('test-user-id', 'HACKERNEWS_GET_USER');
9
10 console.log(tool);
examples/openai/src/index.ts
+49 -34
@@ -11,47 +11,45 @@ const composio = new Composio({
11 apiKey: process.env.COMPOSIO_API_KEY,
12 });
13
14 -composio.useBeforeToolExecute('HACKERNEWS_GET_USER', params => {
15 - if (params.arguments) {
16 - // Modify the arguments before executing the tool
17 - params.arguments = {
18 - ...params.arguments,
19 - username: 'haxzie',
20 - };
21 - }
22 - return params;
23 -});
14 +// composio.useBeforeToolExecute('HACKERNEWS_GET_USER', params => {
15 +// if (params.arguments) {
16 +// // Modify the arguments before executing the tool
17 +// params.arguments = {
18 +// ...params.arguments,
19 +// username: 'haxzie',
20 +// };
21 +// }
22 +// return params;
23 +// });
24
25 -composio.useBeforeToolExecute((toolSlug, params) => {
26 - switch (toolSlug) {
27 - case 'HACKERNEWS_GET_USER':
28 - if (params.arguments) {
29 - // Modify the arguments before executing the tool
30 - params.arguments = {
31 - ...params.arguments,
32 - username: 'haxzie',
33 - };
34 - }
35 - break;
36 - default:
37 - break;
38 - }
39 - return params;
40 -});
25 +// composio.useBeforeToolExecute((toolSlug, params) => {
26 +// switch (toolSlug) {
27 +// case 'HACKERNEWS_GET_USER':
28 +// if (params.arguments) {
29 +// // Modify the arguments before executing the tool
30 +// params.arguments = {
31 +// ...params.arguments,
32 +// username: 'haxzie',
33 +// };
34 +// }
35 +// break;
36 +// default:
37 +// break;
38 +// }
39 +// return params;
40 +// });
41
42 -const connectionRequest = await composio.createConnectedAccount({
43 - authConfig: {
44 - id: 'HACKERNEWS',
45 - },
46 - connection: {},
42 +const connectionRequest = await composio.createConnectedAccount('test-user-id', 'HACKERNEWS', {
43 + // i know this is the connection data but any reason the user needs access to this like this?
44 + data: {},
45 });
46
47 const connectedAccount = await connectionRequest.waitForConnection();
48
49 // Fetch all the tools from the Composio API
50 // these tools are automatically typed and wrapped with the OpenAI Toolset
53 -const tool = await composio.getToolBySlug('HACKERNEWS_GET_USER', {
54 - schema: (toolSlug, toolSchema) => {
51 +const tool = await composio.getToolBySlug('test-user-id', 'HACKERNEWS_GET_USER', {
52 + modifyToolSchema: (toolSlug, toolSchema) => {
53 return toolSchema;
54 },
55 });
@@ -73,7 +71,24 @@ const response = await openai.chat.completions.create({
71 if (response.choices[0].message.tool_calls) {
72 try {
73 const result = await composio.toolset.executeToolCall(
76 - response.choices[0].message.tool_calls[0]
74 + 'test-user-id',
75 + response.choices[0].message.tool_calls[0],
76 + // should be optional options
77 + {
78 + // hmm ig we can have this and call this like overwriteConnectedAccountId
79 + connectedAccountId: '',
80 + // what is his for here?
81 + customAuthParams: {},
82 + },
83 + {
84 + // hmm i wonder about options then modifiers like this
85 + // toolkit slug too
86 + afterToolExecute: (toolSlug, result) => {
87 + // hmm i wonder about this
88 + },
89 + // here we should give a subset of params like userId should not be mutable here
90 + beforeToolExecute: (toolSlug, params) => {},
91 + }
92 );
93 console.log(JSON.stringify(result, null, 2));
94 } catch (error) {
examples/pre-processors/src/index.ts
+26
@@ -13,6 +13,7 @@ const toolkit = await composio.toolkits.get('HACKERNEWS');
13 console.log(toolkit);
14
15 const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER', {
16 + // toolkit slug too
17 modifyToolSchema: (toolSlug, toolSchema) => {
18 if (toolSlug === 'HACKERNEWS_GET_USER') {
19 toolSchema = {
@@ -32,3 +33,28 @@ const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER', {
33 });
34
35 console.log(tools);
36 +
37 +const vercel = new Composio({
38 + apiKey: process.env.COMPOSIO_API_KEY,
39 + // calling this provider now no? or what? or toolProvider or toolManager?
40 + toolset: new VercelToolset(),
41 +});
42 +
43 +vercel.tools.get(
44 + 'user-id',
45 + // what is the type error i am getting here?
46 + { toolkits: [''] },
47 + {
48 + // here for toolkitSlug and toolSlug before the generation mapping thing comes we should have basic generic that gets from the input type itself
49 + // so if i have toolkits then i get toolkit name and if i have tools then i get tool name
50 + modifyToolSchema: (toolSlug, toolSchema) => {
51 + return toolSchema;
52 + },
53 + afterToolExecute: (toolSlug, result) => {
54 + // hmm i wonder about this
55 + },
56 + beforeToolExecute: (toolSlug, params) => {
57 + // here we should give a subset of params like userId should not be mutable here
58 + },
59 + }
60 +);
examples/vercel/src/example.ts
+7 -35
@@ -1,40 +1,12 @@
1 -import { Composio } from "@composio/core";
2 -import { generateText } from "ai";
3 -import { openai } from "@ai-sdk/openai";
4 -import { VercelToolset } from "@composio/vercel";
1 +import { Composio } from '@composio/core';
2 +import { generateText } from 'ai';
3 +import { openai } from '@ai-sdk/openai';
4 +import { VercelToolset } from '@composio/vercel';
5
6 const composio = new Composio({
7 - apiKey: process.env.COMPOSIO_API_KEY,
8 - toolset: new VercelToolset(),
9 - userId: process.env.COMPOSIO_USER_ID, // pass the user at the global level
7 + apiKey: process.env.COMPOSIO_API_KEY,
8 + toolset: new VercelToolset(),
9 + // userId: process.env.COMPOSIO_USER_ID, // pass the user at the global level
10 });
11
12 -
13 -
12 /**
15 - * For tools that have manual execute, we need to pass userId while executing the tool
16 - */
17 -// @ts-ignore
18 -const result = composio.toolset.handleToolCall(tool, { userId: process.env.COMPOSIO_USER_ID });
19 -
20 -/**
21 - * For tools that have auto execute, we have to pass userId (required)
22 - */
23 -const tools = await composio.getTools({
24 - // @ts-ignore
25 - filters: {},
26 - userId: process.env.COMPOSIO_USER_ID, // this is mandatory
27 - connectedAccountId: process.env.COMPOSIO_CONNECTED_ACCOUNT_ID, // this is optional
28 -});
29 -
30 -
31 -/**
32 - * If the user wants to change the userId for a specifically fetched tool
33 - */
34 -// @ts-ignore
35 -const tool = await composio.wrapTool(
36 - // @ts-ignore
37 - hackerNewsTool,
38 - { userId: process.env.COMPOSIO_USER_ID }
39 -);
40 -
examples/vercel/src/index.ts
+1 -1
@@ -8,7 +8,7 @@ const composio = new Composio({
8 toolset: new VercelToolset(),
9 });
10
11 -const hackerNewsTool = await composio.toolset.getToolBySlug('HACKERNEWS_GET_FRONTPAGE');
11 +const hackerNewsTool = await composio.tools.get('test-user-id', 'HACKERNEWS_GET_FRONTPAGE');
12
13 const MessageRoles = {
14 USER: 'user',
packages/core/package.json
+1 -1
@@ -2,7 +2,7 @@
2 "name": "@composio/core",
3 "version": "0.1.8-alpha.0",
4 "description": "",
5 - "main": "dist/index.js",
5 + "main": "src/index.ts",
6 "type": "module",
7 "publishConfig": {
8 "access": "public",