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
wait for connection stuff
Sushmithamallesh49dec971d218
diff --git a/fern/assets/images/auth-screen-example.png b/fern/assets/images/auth-screen-example.pngnew file mode 100644index 000000000..9f7a15766Binary files /dev/null and b/fern/assets/images/auth-screen-example.png differdiff --git a/fern/pages/src/tool-calling/authenticating-tools.mdx b/fern/pages/src/tool-calling/authenticating-tools.mdxindex 1a178bc49..2fe88829a 100644--- a/fern/pages/src/tool-calling/authenticating-tools.mdx+++ b/fern/pages/src/tool-calling/authenticating-tools.mdx@@ -85,49 +85,32 @@ User authentication requires a User ID - a unique identifier that groups connectRedirect users to a Composio-hosted URL that handles the entire authentication process—OAuth flows, API key collection, or custom fields like subdomain. You can specify a callback URL to control where users return after authentication.-<CodeGroup>-```python Python {11-13}-from composio import Composio--composio = Composio(api_key="your_api_key")--# Use the "AUTH CONFIG ID" from your dashboard-auth_config_id = "your_auth_config_id"--# Use a unique identifier for each user in your application-user_id = 'user-1349-129-12'--connection_request = composio.connected_accounts.link(user_id, auth_config_id, callback_url: 'https://your-app.com/callback')--redirect_url = connection_request.redirect_url-print(f"Visit: {redirect_url} to authenticate your account")--# Wait for the connection to be established-connected_account = connection_request.wait_for_connection()-print(connected_account.id)-```-```typescript Typescript {11-13}-import { Composio } from '@composio/core';--const composio = new Composio({apiKey: "your_api_key"});--// Use the "AUTH CONFIG ID" from your dashboard-const authConfigId = 'your_auth_config_id';--// Use a unique identifier for each user in your application-const userId = 'user-1349-129-12';--const connectionRequest = await composio.connectedAccounts.link(userId, authConfigId, {- callbackUrl: 'https://your-app.com/callback'-});-const redirectUrl = connectionRequest.redirectUrl;-console.log(`Visit: ${redirectUrl} to authenticate your account`);+<Frame caption="Connect Link authentication screen">+ <img+ src="../../../assets/images/auth-screen-example.png"+ alt="Composio authentication screen showing Gmail connection"+ style={{ maxWidth: '350px', maxHeight: '400px', width: 'auto', height: 'auto', margin: '0 auto', display: 'block' }}+ />+</Frame>-// Wait for the connection to be established-const connectedAccount = await composio.connectedAccounts.waitForConnection(connectionRequest.id);-console.log(connectedAccount.id)+<CodeGroup>+<SnippetCode+ src="fern/snippets/authentication/python/connect-link.py"+ title="Python"+ startLine={1}+ endLine={22}+ highlightStart={11}+ highlightEnd={15}+/>-````+<SnippetCode+ src="fern/snippets/authentication/typescript/connect-link.ts"+ title="TypeScript"+ startLine={1}+ endLine={19}+ highlightStart={11}+ highlightEnd={13}+/></CodeGroup>#### Customizing Connect Link@@ -365,9 +348,38 @@ After creating a connection, it will have one of the following statuses that ind| **INACTIVE** | Connection is temporarily disabled. Re-enable it to use the connection again. || **PENDING** | Connection is being processed. Wait for it to become active. || **INITIATED** | Connection request has started but not yet completed. User may still need to complete authentication. |-| **EXPIRED** | Connection credentials have expired. Re-authenticate to restore access. |+| **EXPIRED** | Connection credentials have expired. Composio automatically attempts to refresh credentials before marking as expired. Re-authenticate to restore access. || **FAILED** | Connection attempt failed. Check error details and try creating a new connection. |+<Note>+When credentials expire for OAuth connections, Composio automatically attempts to refresh them using the refresh token. The connection is only marked as **EXPIRED** after multiple refresh attempts have failed.+</Note>++### Waiting for Connection Establishment++The `waitForConnection` method allows you to poll for a connection to become active after initiating authentication. This is useful when you need to ensure a connection is ready before proceeding.++<CodeGroup>+<SnippetCode+ src="fern/snippets/authentication/python/connect-link.py"+ title="Python"+ startLine={20}+ endLine={29}+/>++<SnippetCode+ src="fern/snippets/authentication/typescript/connect-link.ts"+ title="TypeScript"+ startLine={17}+ endLine={26}+/>+</CodeGroup>++The method continuously polls the Composio API until the connection:+- Becomes **ACTIVE** (returns the connected account)+- Enters a terminal state like **FAILED** or **EXPIRED** (throws an error)+- Exceeds the specified timeout (throws a timeout error)+### Checking Connection StatusYou can check the status of a connected account programmatically:diff --git a/fern/snippets/authentication/python/connect-link.py b/fern/snippets/authentication/python/connect-link.pynew file mode 100644index 000000000..d67c8dfc2--- /dev/null+++ b/fern/snippets/authentication/python/connect-link.py@@ -0,0 +1,29 @@+from composio import Composio++composio = Composio(api_key="your_api_key")++# Use the "AUTH CONFIG ID" from your dashboard+auth_config_id = "your_auth_config_id"++# Use a unique identifier for each user in your application+user_id = 'user-1349-129-12'++connection_request = composio.connected_accounts.link(+ user_id=user_id,+ auth_config_id=auth_config_id,+ callback_url='https://your-app.com/callback'+)++redirect_url = connection_request.redirect_url+print(f"Visit: {redirect_url} to authenticate your account")++# Wait for the connection to be established+connected_account = connection_request.wait_for_connection()+print(connected_account.id)++# Alternative: Wait with custom timeout+# connected_account = connection_request.wait_for_connection(120) # 2 minute timeout++# Alternative: If you only have the connection request ID (e.g., stored in database)+# connection_id = connection_request.id # You can store this ID in your database+# connected_account = composio.connected_accounts.wait_for_connection(connection_id, 60)\ No newline at end of filediff --git a/fern/snippets/authentication/typescript/connect-link.ts b/fern/snippets/authentication/typescript/connect-link.tsnew file mode 100644index 000000000..23c0a0dc9--- /dev/null+++ b/fern/snippets/authentication/typescript/connect-link.ts@@ -0,0 +1,26 @@+import { Composio } from '@composio/core';++const composio = new Composio({apiKey: "your_api_key"});++// Use the "AUTH CONFIG ID" from your dashboard+const authConfigId = 'your_auth_config_id';++// Use a unique identifier for each user in your application+const userId = 'user-1349-129-12';++const connectionRequest = await composio.connectedAccounts.link(userId, authConfigId, {+ callbackUrl: 'https://your-app.com/callback'+});+const redirectUrl = connectionRequest.redirectUrl;+console.log(`Visit: ${redirectUrl} to authenticate your account`);++// Wait for the connection to be established+const connectedAccount = await connectionRequest.waitForConnection();+console.log(connectedAccount.id);++// Alternative: Wait with custom timeout+// const connectedAccount = await connectionRequest.waitForConnection(120000); // 2 minutes++// Alternative: If you only have the connection request ID (e.g., stored in database)+// const connectionId = connectionRequest.id; // You can store this ID in your database+// const connectedAccount = await composio.connectedAccounts.waitForConnection(connectionId, 60000);\ No newline at end of filediff --git a/fern/vapidocs b/fern/vapidocsnew file mode 160000index 000000000..aee1e2bff--- /dev/null+++ b/fern/vapidocs@@ -0,0 +1 @@+Subproject commit aee1e2bffe7153fa2a373e246234f9c24994f2f9