1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290import { Tool } from '@langchain/core/tools'
import { ICommonObject, INode, INodeData, INodeOptionsValue, INodeParams } from '../../../src/Interface'
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
import { LangchainToolSet } from 'composio-core'
class ComposioTool extends Tool {
name = 'composio'
description = 'Tool for interacting with Composio applications and performing actions'
toolset: any
appName: string
actions: string[]
constructor(toolset: any, appName: string, actions: string[]) {
super()
this.toolset = toolset
this.appName = appName
this.actions = actions
}
async _call(input: string): Promise<string> {
try {
return `Executed action on ${this.appName} with input: ${input}`
} catch (error) {
return 'Failed to execute action'
}
}
}
class Composio_Tools implements INode {
label: string
name: string
version: number
type: string
icon: string
category: string
description: string
baseClasses: string[]
credential: INodeParams
inputs: INodeParams[]
constructor() {
this.label = 'Composio'
this.name = 'composio'
this.version = 2.0
this.type = 'Composio'
this.icon = 'composio.svg'
this.category = 'Tools'
this.description = 'Toolset with over 250+ Apps for building AI-powered applications'
this.baseClasses = [this.type, ...getBaseClasses(ComposioTool)]
this.credential = {
label: 'Connect Credential',
name: 'credential',
type: 'credential',
credentialNames: ['composioApi']
}
this.inputs = [
{
label: 'App Name',
name: 'appName',
type: 'asyncOptions',
loadMethod: 'listApps',
description: 'Select the app to connect with',
refresh: true
},
{
label: 'Connected Account',
name: 'connectedAccountId',
type: 'asyncOptions',
loadMethod: 'listConnections',
description: 'Select which connection to use',
refresh: true
},
{
label: 'Actions to Use',
name: 'actions',
type: 'asyncMultiOptions',
loadMethod: 'listActions',
description: 'Select the actions you want to use',
refresh: true
}
]
}
//@ts-ignore
loadMethods = {
listApps: async (nodeData: INodeData, options?: ICommonObject): Promise<INodeOptionsValue[]> => {
try {
const credentialData = await getCredentialData(nodeData.credential ?? '', options ?? {})
const composioApiKey = getCredentialParam('composioApi', credentialData, nodeData)
if (!composioApiKey) {
return [
{
label: 'API Key Required',
name: 'placeholder',
description: 'Enter Composio API key in the credential field'
}
]
}
const toolset = new LangchainToolSet({ apiKey: composioApiKey })
const apps = await toolset.client.apps.list()
apps.sort((a: any, b: any) => a.name.localeCompare(b.name))
return apps.map(({ name, ...rest }) => ({
label: name.toUpperCase(),
name: name,
description: rest.description || name
}))
} catch (error) {
console.error('Error loading apps:', error)
return [
{
label: 'Error Loading Apps',
name: 'error',
description: 'Failed to load apps. Please check your API key and try again'
}
]
}
},
listActions: async (nodeData: INodeData, options?: ICommonObject): Promise<INodeOptionsValue[]> => {
try {
const credentialData = await getCredentialData(nodeData.credential ?? '', options ?? {})
const composioApiKey = getCredentialParam('composioApi', credentialData, nodeData)
const appName = nodeData.inputs?.appName as string
if (!composioApiKey) {
return [
{
label: 'API Key Required',
name: 'placeholder',
description: 'Enter Composio API key in the credential field'
}
]
}
if (!appName) {
return [
{
label: 'Select an App first',
name: 'placeholder',
description: 'Select an app from the dropdown to view available actions'
}
]
}
const toolset = new LangchainToolSet({ apiKey: composioApiKey })
const actions = await toolset.getTools({ apps: [appName] })
actions.sort((a: any, b: any) => a.name.localeCompare(b.name))
return actions.map(({ name, ...rest }) => ({
label: name.toUpperCase(),
name: name,
description: rest.description || name
}))
} catch (error) {
console.error('Error loading actions:', error)
return [
{
label: 'Error Loading Actions',
name: 'error',
description: 'Failed to load actions. Please check your API key and try again'
}
]
}
},
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
if (!composioApiKey) {
return [
{
label: 'API Key Required',
name: 'placeholder',
description: 'Enter Composio API key in the credential field'
}
]
}
if (!appName) {
return [
{
label: 'Select an App first',
name: 'placeholder',
description: 'Select an app from the dropdown to view available connections'
}
]
}
const toolset = new LangchainToolSet({ apiKey: composioApiKey })
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()}`
}))
}
}
async init(nodeData: INodeData, _: string, options: ICommonObject): Promise<any> {
if (!nodeData.inputs) nodeData.inputs = {}
const credentialData = await getCredentialData(nodeData.credential ?? '', options)
const composioApiKey = getCredentialParam('composioApi', credentialData, nodeData)
if (!composioApiKey) {
nodeData.inputs = {
appName: undefined,
connectedAccountId: '',
actions: []
}
throw new Error('API Key Required')
}
const _actions = nodeData.inputs?.actions
let actions = []
if (_actions) {
try {
actions = typeof _actions === 'string' ? JSON.parse(_actions) : _actions
} catch (error) {
console.error('Error parsing actions:', error)
}
}
const toolset = new LangchainToolSet({ apiKey: composioApiKey })
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
}
}
module.exports = { nodeClass: Composio_Tools }