Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
base feedback and fix types in examples
Rahul Tarakbdfd652fbba7
diff --git a/examples/connected-accounts/src/index.ts b/examples/connected-accounts/src/index.tsindex 7d9839af7..e65a20a72 100644--- a/examples/connected-accounts/src/index.ts+++ b/examples/connected-accounts/src/index.ts@@ -11,8 +11,14 @@ const composio = new Composio({apiKey: process.env.COMPOSIO_API_KEY,});+// i think this should be a discriminated union, like only tools or toolkits or search can be there, inside the filter+// the other ones should be third object {} optionsconst tools = await composio.tools.get('user123', {tools: ['HACKERNEWS_GET_USER'],+ cursor: '123',+ important: '', // what is this doing do we need it can we remove it?+ limit: '10',+ toolkits: ['HACKERNEWS'],});/**@@ -20,8 +26,9 @@ const tools = await composio.tools.get('user123', {*/const authConfig = await composio.createAuthConfig('my-toolkit', {type: AuthConfigTypes.CUSTOM,- authScheme: AuthSchemeTypes.API_KEY,+ authScheme: AuthSchemeTypes.BASIC,credentials: {+ // this should error not like the credentials should come from the auth scheme typeapiKey: '1234567890',},});@@ -29,6 +36,8 @@ const authConfig = await composio.createAuthConfig('my-toolkit', {/*** Create a new connected account*/+// hmm so the createConnectedAccount here doesn't feel like i am initiating a connection request -> that is probably why it was called initiateConnection+// connectedAccounts.initiate or initialize workconst ConnectionRequest = await composio.createConnectedAccount('default', authConfig.id);const connectedAccount = await ConnectionRequest.waitForConnection();diff --git a/examples/openai/src/examples.ts b/examples/openai/src/examples.tsindex 34dea7dad..1f6963d1e 100644--- a/examples/openai/src/examples.ts+++ b/examples/openai/src/examples.ts@@ -5,6 +5,6 @@ const composio = new Composio({apiKey: process.env.COMPOSIO_API_KEY,});-const tool = await composio.getToolBySlug('HACKERNEWS_GET_USER');+const tool = await composio.getToolBySlug('test-user-id', 'HACKERNEWS_GET_USER');console.log(tool);diff --git a/examples/openai/src/index.ts b/examples/openai/src/index.tsindex 7535f783b..756d9d392 100644--- a/examples/openai/src/index.ts+++ b/examples/openai/src/index.ts@@ -11,47 +11,45 @@ const composio = new Composio({apiKey: process.env.COMPOSIO_API_KEY,});-composio.useBeforeToolExecute('HACKERNEWS_GET_USER', params => {- if (params.arguments) {- // Modify the arguments before executing the tool- params.arguments = {- ...params.arguments,- username: 'haxzie',- };- }- return params;-});+// composio.useBeforeToolExecute('HACKERNEWS_GET_USER', params => {+// if (params.arguments) {+// // Modify the arguments before executing the tool+// params.arguments = {+// ...params.arguments,+// username: 'haxzie',+// };+// }+// return params;+// });-composio.useBeforeToolExecute((toolSlug, params) => {- switch (toolSlug) {- case 'HACKERNEWS_GET_USER':- if (params.arguments) {- // Modify the arguments before executing the tool- params.arguments = {- ...params.arguments,- username: 'haxzie',- };- }- break;- default:- break;- }- return params;-});+// composio.useBeforeToolExecute((toolSlug, params) => {+// switch (toolSlug) {+// case 'HACKERNEWS_GET_USER':+// if (params.arguments) {+// // Modify the arguments before executing the tool+// params.arguments = {+// ...params.arguments,+// username: 'haxzie',+// };+// }+// break;+// default:+// break;+// }+// return params;+// });-const connectionRequest = await composio.createConnectedAccount({- authConfig: {- id: 'HACKERNEWS',- },- connection: {},+const connectionRequest = await composio.createConnectedAccount('test-user-id', 'HACKERNEWS', {+ // i know this is the connection data but any reason the user needs access to this like this?+ data: {},});const connectedAccount = await connectionRequest.waitForConnection();// Fetch all the tools from the Composio API// these tools are automatically typed and wrapped with the OpenAI Toolset-const tool = await composio.getToolBySlug('HACKERNEWS_GET_USER', {- schema: (toolSlug, toolSchema) => {+const tool = await composio.getToolBySlug('test-user-id', 'HACKERNEWS_GET_USER', {+ modifyToolSchema: (toolSlug, toolSchema) => {return toolSchema;},});@@ -73,7 +71,24 @@ const response = await openai.chat.completions.create({if (response.choices[0].message.tool_calls) {try {const result = await composio.toolset.executeToolCall(- response.choices[0].message.tool_calls[0]+ 'test-user-id',+ response.choices[0].message.tool_calls[0],+ // should be optional options+ {+ // hmm ig we can have this and call this like overwriteConnectedAccountId+ connectedAccountId: '',+ // what is his for here?+ customAuthParams: {},+ },+ {+ // hmm i wonder about options then modifiers like this+ // toolkit slug too+ afterToolExecute: (toolSlug, result) => {+ // hmm i wonder about this+ },+ // here we should give a subset of params like userId should not be mutable here+ beforeToolExecute: (toolSlug, params) => {},+ });console.log(JSON.stringify(result, null, 2));} catch (error) {diff --git a/examples/pre-processors/src/index.ts b/examples/pre-processors/src/index.tsindex 551792027..114b62e59 100644--- a/examples/pre-processors/src/index.ts+++ b/examples/pre-processors/src/index.ts@@ -13,6 +13,7 @@ const toolkit = await composio.toolkits.get('HACKERNEWS');console.log(toolkit);const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER', {+ // toolkit slug toomodifyToolSchema: (toolSlug, toolSchema) => {if (toolSlug === 'HACKERNEWS_GET_USER') {toolSchema = {@@ -32,3 +33,28 @@ const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER', {});console.log(tools);++const vercel = new Composio({+ apiKey: process.env.COMPOSIO_API_KEY,+ // calling this provider now no? or what? or toolProvider or toolManager?+ toolset: new VercelToolset(),+});++vercel.tools.get(+ 'user-id',+ // what is the type error i am getting here?+ { toolkits: [''] },+ {+ // here for toolkitSlug and toolSlug before the generation mapping thing comes we should have basic generic that gets from the input type itself+ // so if i have toolkits then i get toolkit name and if i have tools then i get tool name+ modifyToolSchema: (toolSlug, toolSchema) => {+ return toolSchema;+ },+ afterToolExecute: (toolSlug, result) => {+ // hmm i wonder about this+ },+ beforeToolExecute: (toolSlug, params) => {+ // here we should give a subset of params like userId should not be mutable here+ },+ }+);diff --git a/examples/vercel/src/example.ts b/examples/vercel/src/example.tsindex c58683e5b..bdcbc4bf2 100644--- a/examples/vercel/src/example.ts+++ b/examples/vercel/src/example.ts@@ -1,40 +1,12 @@-import { Composio } from "@composio/core";-import { generateText } from "ai";-import { openai } from "@ai-sdk/openai";-import { VercelToolset } from "@composio/vercel";+import { Composio } from '@composio/core';+import { generateText } from 'ai';+import { openai } from '@ai-sdk/openai';+import { VercelToolset } from '@composio/vercel';const composio = new Composio({- apiKey: process.env.COMPOSIO_API_KEY,- toolset: new VercelToolset(),- userId: process.env.COMPOSIO_USER_ID, // pass the user at the global level+ apiKey: process.env.COMPOSIO_API_KEY,+ toolset: new VercelToolset(),+ // userId: process.env.COMPOSIO_USER_ID, // pass the user at the global level});--/**- * For tools that have manual execute, we need to pass userId while executing the tool- */-// @ts-ignore-const result = composio.toolset.handleToolCall(tool, { userId: process.env.COMPOSIO_USER_ID });--/**- * For tools that have auto execute, we have to pass userId (required)- */-const tools = await composio.getTools({- // @ts-ignore- filters: {},- userId: process.env.COMPOSIO_USER_ID, // this is mandatory- connectedAccountId: process.env.COMPOSIO_CONNECTED_ACCOUNT_ID, // this is optional-});---/**- * If the user wants to change the userId for a specifically fetched tool- */-// @ts-ignore-const tool = await composio.wrapTool(- // @ts-ignore- hackerNewsTool,- { userId: process.env.COMPOSIO_USER_ID }-);-diff --git a/examples/vercel/src/index.ts b/examples/vercel/src/index.tsindex c067b0eed..d8511027b 100644--- a/examples/vercel/src/index.ts+++ b/examples/vercel/src/index.ts@@ -8,7 +8,7 @@ const composio = new Composio({toolset: new VercelToolset(),});-const hackerNewsTool = await composio.toolset.getToolBySlug('HACKERNEWS_GET_FRONTPAGE');+const hackerNewsTool = await composio.tools.get('test-user-id', 'HACKERNEWS_GET_FRONTPAGE');const MessageRoles = {USER: 'user',diff --git a/packages/core/package.json b/packages/core/package.jsonindex b8f20140a..b8ff1c175 100644--- a/packages/core/package.json+++ b/packages/core/package.json@@ -2,7 +2,7 @@"name": "@composio/core","version": "0.1.8-alpha.0","description": "",- "main": "dist/index.js",+ "main": "src/index.ts","type": "module","publishConfig": {"access": "public",