Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 70 additions & 16 deletions packages/components/nodes/tools/Composio/Composio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ class Composio_Tools implements INode {
refresh: true
},
{
label: 'Auth Status',
name: 'authStatus',
label: 'Connected Account',
name: 'connectedAccountId',
type: 'asyncOptions',
loadMethod: 'authStatus',
placeholder: 'Connection status will appear here',
loadMethod: 'listConnections',
description: 'Select which connection to use',
refresh: true
},
{
Expand Down Expand Up @@ -164,7 +164,7 @@ class Composio_Tools implements INode {
]
}
},
authStatus: async (nodeData: INodeData, options?: ICommonObject): Promise<INodeOptionsValue[]> => {
listConnections: async (nodeData: INodeData, options?: ICommonObject): Promise<INodeOptionsValue[]> => {
const credentialData = await getCredentialData(nodeData.credential ?? '', options ?? {})
const composioApiKey = getCredentialParam('composioApi', credentialData, nodeData)
const appName = nodeData.inputs?.appName as string
Expand All @@ -184,20 +184,44 @@ class Composio_Tools implements INode {
{
label: 'Select an App first',
name: 'placeholder',
description: 'Select an app from the dropdown to view available actions'
description: 'Select an app from the dropdown to view available connections'
}
]
}

const toolset = new LangchainToolSet({ apiKey: composioApiKey })
const authStatus = await toolset.client.getEntity('default').getConnection({ app: appName.toLowerCase() })
return [
{
label: authStatus ? 'Connected' : 'Not Connected',
name: authStatus ? 'Connected' : 'Not Connected',
description: authStatus ? 'Selected app has an active connection' : 'Please connect the app on app.composio.dev'
}
]

const appInfo = await toolset.client.apps.get({ appKey: appName.toLowerCase() })
const requiresAuth = (appInfo as any)?.no_auth !== true

if (!requiresAuth) {
return [
{
label: 'No connection needed',
name: 'No connection needed',
description: 'This app does not require authentication'
}
]
}

const connections = await toolset.client.connectedAccounts.list({ appNames: appName.toLowerCase() })
const activeConnections = connections.items?.filter((c: any) => c.status === 'ACTIVE') || []

if (activeConnections.length === 0) {
return [
{
label: 'No connections available',
name: '',
description: 'Please connect the app on app.composio.dev first'
}
]
}

return activeConnections.map((c: any) => ({
label: c.clientUniqueUserId || c.id,
name: c.id,
description: `Created: ${new Date(c.createdAt).toLocaleDateString()}`
}))
}
}

Expand All @@ -210,7 +234,7 @@ class Composio_Tools implements INode {
if (!composioApiKey) {
nodeData.inputs = {
appName: undefined,
authStatus: '',
connectedAccountId: '',
actions: []
}
throw new Error('API Key Required')
Expand All @@ -227,7 +251,37 @@ class Composio_Tools implements INode {
}

const toolset = new LangchainToolSet({ apiKey: composioApiKey })
const tools = await toolset.getTools({ actions })
const appName = nodeData.inputs?.appName as string

if (!appName) {
throw new Error('App name is required. Please select an app.')
}

const appInfo = await toolset.client.apps.get({ appKey: appName.toLowerCase() })
const requiresAuth = (appInfo as any)?.no_auth !== true

if (!requiresAuth) {
const tools = await toolset.getTools({ actions })
return tools
}

const selectedConnectionId = nodeData.inputs?.connectedAccountId as string

if (!selectedConnectionId) {
throw new Error(`Please select a connected account for ${appName}`)
}

const activeConnection = await toolset.client.connectedAccounts.get({ connectedAccountId: selectedConnectionId })

if (!activeConnection || (activeConnection as any).status !== 'ACTIVE') {
throw new Error(
`Selected connection is no longer active for ${appName}. Please select a different connection or reconnect on app.composio.dev`
)
}

const entityId = (activeConnection as any).clientUniqueUserId || 'default'
const toolsetWithEntity = new LangchainToolSet({ apiKey: composioApiKey, entityId })
const tools = await toolsetWithEntity.getTools({ actions })
return tools
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"cheerio": "^1.0.0-rc.12",
"chromadb": "3.1.6",
"cohere-ai": "^7.7.5",
"composio-core": "^0.4.7",
"composio-core": "^0.5.39",
"couchbase": "4.4.1",
"crypto-js": "^4.1.1",
"css-what": "^6.1.0",
Expand Down
Loading