@composio/core 0.1.8-alpha.0 → 0.1.9-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.cjs +1255 -897
- package/dist/index.d.cts +294 -320
- package/dist/index.d.ts +294 -320
- package/dist/index.js +1165 -807
- package/package.json +3 -3
- package/src/index.ts +23 -0
package/dist/index.cjs
CHANGED
|
@@ -69,12 +69,12 @@ var ToolListResponseSchema = import_zod.z.object({
|
|
|
69
69
|
totalPages: import_zod.z.number()
|
|
70
70
|
});
|
|
71
71
|
var ToolListParamsSchema = import_zod.z.object({
|
|
72
|
+
tools: import_zod.z.array(import_zod.z.string()).optional(),
|
|
72
73
|
cursor: import_zod.z.string().optional(),
|
|
73
74
|
important: import_zod.z.string().optional(),
|
|
74
75
|
limit: import_zod.z.string().optional(),
|
|
75
76
|
search: import_zod.z.string().optional(),
|
|
76
|
-
toolkits: import_zod.z.array(import_zod.z.string()).optional()
|
|
77
|
-
tools: import_zod.z.array(import_zod.z.string()).optional()
|
|
77
|
+
toolkits: import_zod.z.array(import_zod.z.string()).optional()
|
|
78
78
|
});
|
|
79
79
|
var CustomAuthParamsSchema = import_zod.z.object({
|
|
80
80
|
baseURL: import_zod.z.string().optional(),
|
|
@@ -106,11 +106,212 @@ var ToolExecuteResponseSchema = import_zod.z.object({
|
|
|
106
106
|
|
|
107
107
|
// src/models/CustomTools.ts
|
|
108
108
|
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"), 1);
|
|
109
|
+
|
|
110
|
+
// src/utils/env.ts
|
|
111
|
+
var getEnvVariable = (name, defaultValue = void 0) => {
|
|
112
|
+
try {
|
|
113
|
+
return process.env[name] || defaultValue;
|
|
114
|
+
} catch (_e) {
|
|
115
|
+
logger_default.error(`Error getting environment variable ${name}:`, _e);
|
|
116
|
+
return defaultValue;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/utils/logger.ts
|
|
121
|
+
var LOG_LEVELS = {
|
|
122
|
+
silent: -1,
|
|
123
|
+
// No logs
|
|
124
|
+
error: 0,
|
|
125
|
+
// Highest priority - critical errors
|
|
126
|
+
warn: 1,
|
|
127
|
+
// Warning messages
|
|
128
|
+
info: 2,
|
|
129
|
+
// General information
|
|
130
|
+
debug: 3
|
|
131
|
+
// Debug information
|
|
132
|
+
};
|
|
133
|
+
var getLogLevel = () => {
|
|
134
|
+
const envLevel = getEnvVariable("COMPOSIO_LOGGING_LEVEL", "info")?.toLowerCase();
|
|
135
|
+
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
136
|
+
};
|
|
137
|
+
var Logger = class {
|
|
138
|
+
level;
|
|
139
|
+
includeTimestamp;
|
|
140
|
+
console;
|
|
141
|
+
constructor(options = {}) {
|
|
142
|
+
this.level = options.level ?? getLogLevel();
|
|
143
|
+
this.includeTimestamp = options.includeTimestamp ?? true;
|
|
144
|
+
this.console = console;
|
|
145
|
+
}
|
|
146
|
+
formatMessage(args) {
|
|
147
|
+
const formattedArgs = args.map((arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)).join("\n");
|
|
148
|
+
if (!this.includeTimestamp) {
|
|
149
|
+
return formattedArgs;
|
|
150
|
+
}
|
|
151
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
152
|
+
return `${timestamp} - ${formattedArgs}`;
|
|
153
|
+
}
|
|
154
|
+
shouldLog(level) {
|
|
155
|
+
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
156
|
+
}
|
|
157
|
+
error(...args) {
|
|
158
|
+
if (this.shouldLog("error")) {
|
|
159
|
+
this.console.error(this.formatMessage(args));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
warn(...args) {
|
|
163
|
+
if (this.shouldLog("warn")) {
|
|
164
|
+
this.console.warn(this.formatMessage(args));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
info(...args) {
|
|
168
|
+
if (this.shouldLog("info")) {
|
|
169
|
+
this.console.info(this.formatMessage(args));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
debug(...args) {
|
|
173
|
+
if (this.shouldLog("debug")) {
|
|
174
|
+
this.console.debug(this.formatMessage(args));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var logger = new Logger();
|
|
179
|
+
var logger_default = logger;
|
|
180
|
+
|
|
181
|
+
// src/errors/ComposioError.ts
|
|
182
|
+
var ComposioError = class extends Error {
|
|
183
|
+
name = "ComposioError";
|
|
184
|
+
code;
|
|
185
|
+
statusCode;
|
|
186
|
+
cause;
|
|
187
|
+
meta;
|
|
188
|
+
possibleFixes;
|
|
189
|
+
constructor(message, options = {}) {
|
|
190
|
+
super(message);
|
|
191
|
+
this.code = options.code;
|
|
192
|
+
this.statusCode = options.statusCode;
|
|
193
|
+
this.cause = options.cause;
|
|
194
|
+
this.meta = options.meta;
|
|
195
|
+
this.possibleFixes = options.possibleFixes;
|
|
196
|
+
if (Error.captureStackTrace) {
|
|
197
|
+
Error.captureStackTrace(this, this.constructor);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
toJSON() {
|
|
201
|
+
return {
|
|
202
|
+
name: this.name,
|
|
203
|
+
message: this.message,
|
|
204
|
+
code: this.code,
|
|
205
|
+
statusCode: this.statusCode,
|
|
206
|
+
cause: this.cause instanceof Error ? this.cause.message : this.cause,
|
|
207
|
+
meta: this.meta,
|
|
208
|
+
possibleFixes: this.possibleFixes?.length ? this.possibleFixes.join("\n") : void 0
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/errors/ToolErrors.ts
|
|
214
|
+
var ToolErrorCodes = {
|
|
215
|
+
TOOLSET_NOT_DEFINED: "TOOLSET_NOT_DEFINED",
|
|
216
|
+
TOOL_NOT_FOUND: "TOOL_NOT_FOUND",
|
|
217
|
+
INVALID_MODIFIER: "INVALID_MODIFIER",
|
|
218
|
+
CUSTOM_TOOLS_NOT_INITIALIZED: "CUSTOM_TOOLS_NOT_INITIALIZED",
|
|
219
|
+
TOOL_EXECUTION_ERROR: "TOOL_EXECUTION_ERROR",
|
|
220
|
+
INVALID_EXECUTE_FUNCTION: "INVALID_EXECUTE_FUNCTION"
|
|
221
|
+
};
|
|
222
|
+
var ComposioToolsetNotDefinedError = class extends ComposioError {
|
|
223
|
+
constructor(message = "Toolset not defined", meta = {}) {
|
|
224
|
+
super(message, {
|
|
225
|
+
code: ToolErrorCodes.TOOLSET_NOT_DEFINED,
|
|
226
|
+
meta,
|
|
227
|
+
possibleFixes: [
|
|
228
|
+
"Ensure that the toolset is defined in the Composio project and passed into the tool instance"
|
|
229
|
+
]
|
|
230
|
+
});
|
|
231
|
+
this.name = "ComposioToolsetNotDefinedError";
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
var ComposioToolNotFoundError = class extends ComposioError {
|
|
235
|
+
constructor(message = "Tool not found", meta = {}) {
|
|
236
|
+
super(message, {
|
|
237
|
+
code: ToolErrorCodes.TOOL_NOT_FOUND,
|
|
238
|
+
meta,
|
|
239
|
+
possibleFixes: ["Ensure the tool slug is correct and exists in the Composio project"]
|
|
240
|
+
});
|
|
241
|
+
this.name = "ComposioToolNotFoundError";
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
var ComposioInvalidModifierError = class extends ComposioError {
|
|
245
|
+
constructor(message = "Invalid modifier", meta = {}) {
|
|
246
|
+
super(message, {
|
|
247
|
+
code: ToolErrorCodes.INVALID_MODIFIER,
|
|
248
|
+
meta,
|
|
249
|
+
possibleFixes: ["Ensure the modifier is a function and returns a valid result"]
|
|
250
|
+
});
|
|
251
|
+
this.name = "ComposioInvalidModifierError";
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
var ComposioCustomToolsNotInitializedError = class extends ComposioError {
|
|
255
|
+
constructor(message = "Custom tools not initialized", meta = {}) {
|
|
256
|
+
super(message, {
|
|
257
|
+
code: ToolErrorCodes.CUSTOM_TOOLS_NOT_INITIALIZED,
|
|
258
|
+
meta,
|
|
259
|
+
possibleFixes: ["Ensure the custom tools class is initialized in the Tools instance"]
|
|
260
|
+
});
|
|
261
|
+
this.name = "ComposioCustomToolsNotInitializedError";
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
var ComposioToolExecutionError = class extends ComposioError {
|
|
265
|
+
error;
|
|
266
|
+
constructor(error, message = "Tool execution error", meta = {}) {
|
|
267
|
+
super(message, {
|
|
268
|
+
code: ToolErrorCodes.TOOL_EXECUTION_ERROR,
|
|
269
|
+
cause: error,
|
|
270
|
+
meta,
|
|
271
|
+
possibleFixes: ["Ensure the tool is correctly configured and the input is valid"]
|
|
272
|
+
});
|
|
273
|
+
this.error = error;
|
|
274
|
+
this.name = "ComposioToolExecutionError";
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
var ComposioInvalidExecuteFunctionError = class extends ComposioError {
|
|
278
|
+
constructor(message = "Invalid execute function", meta = {}) {
|
|
279
|
+
super(message, {
|
|
280
|
+
code: ToolErrorCodes.INVALID_EXECUTE_FUNCTION,
|
|
281
|
+
meta,
|
|
282
|
+
possibleFixes: ["Ensure the execute function is a valid function and returns a valid result"]
|
|
283
|
+
});
|
|
284
|
+
this.name = "ComposioInvalidExecuteFunctionError";
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
// src/errors/ConnectedAccountsError.ts
|
|
289
|
+
var ConnectedAccountErrorCodes = {
|
|
290
|
+
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
|
|
291
|
+
};
|
|
292
|
+
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
293
|
+
constructor(message = "Connected account not found", meta = {}) {
|
|
294
|
+
super(message, {
|
|
295
|
+
code: ConnectedAccountErrorCodes.CONNECTED_ACCOUNT_NOT_FOUND,
|
|
296
|
+
statusCode: 404,
|
|
297
|
+
meta,
|
|
298
|
+
possibleFixes: [
|
|
299
|
+
"Ensure the connected account exists and is active in your Composio dashboard"
|
|
300
|
+
]
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// src/models/CustomTools.ts
|
|
109
306
|
var CustomTools = class {
|
|
110
307
|
client;
|
|
111
|
-
customToolsRegistry
|
|
308
|
+
customToolsRegistry;
|
|
112
309
|
constructor(client) {
|
|
310
|
+
if (!client) {
|
|
311
|
+
throw new ComposioError("ComposioClient is required");
|
|
312
|
+
}
|
|
113
313
|
this.client = client;
|
|
314
|
+
this.customToolsRegistry = /* @__PURE__ */ new Map();
|
|
114
315
|
}
|
|
115
316
|
/**
|
|
116
317
|
* Create a custom tool and registers it in the registry.
|
|
@@ -178,11 +379,16 @@ var CustomTools = class {
|
|
|
178
379
|
* @returns {Tool} The tool
|
|
179
380
|
*/
|
|
180
381
|
async getCustomToolBySlug(slug) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
382
|
+
if (!slug) {
|
|
383
|
+
throw new Error("Tool slug is required");
|
|
384
|
+
}
|
|
385
|
+
try {
|
|
386
|
+
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
387
|
+
return tool?.schema;
|
|
388
|
+
} catch (error) {
|
|
389
|
+
logger_default.error(`Error getting custom tool: ${error}`);
|
|
390
|
+
return void 0;
|
|
184
391
|
}
|
|
185
|
-
return tool.schema;
|
|
186
392
|
}
|
|
187
393
|
/**
|
|
188
394
|
* Get the connected account for the user and toolkit.
|
|
@@ -191,12 +397,25 @@ var CustomTools = class {
|
|
|
191
397
|
* @returns {ConnectedAccount} The connected account
|
|
192
398
|
*/
|
|
193
399
|
async getConnectedAccount(toolkitSlug, metadata) {
|
|
400
|
+
try {
|
|
401
|
+
await this.client.toolkits.retrieve(toolkitSlug);
|
|
402
|
+
} catch (error) {
|
|
403
|
+
throw new ComposioToolNotFoundError(`Toolkit with slug ${toolkitSlug} not found`, {
|
|
404
|
+
toolkitSlug,
|
|
405
|
+
error
|
|
406
|
+
});
|
|
407
|
+
}
|
|
194
408
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
195
409
|
toolkit_slug: toolkitSlug,
|
|
196
410
|
user_id: metadata.userId
|
|
197
411
|
});
|
|
198
412
|
if (!connectedAccounts.items.length) {
|
|
199
|
-
throw new
|
|
413
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
414
|
+
`No connected accounts found for toolkit ${toolkitSlug}`,
|
|
415
|
+
{
|
|
416
|
+
toolkitSlug
|
|
417
|
+
}
|
|
418
|
+
);
|
|
200
419
|
}
|
|
201
420
|
return metadata.connectedAccountId ? connectedAccounts.items.find((item) => item.id === metadata.connectedAccountId) : connectedAccounts.items[0];
|
|
202
421
|
}
|
|
@@ -210,21 +429,29 @@ var CustomTools = class {
|
|
|
210
429
|
async executeCustomTool(slug, inputParams, metadata) {
|
|
211
430
|
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
212
431
|
if (!tool) {
|
|
213
|
-
throw new
|
|
432
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`, {
|
|
433
|
+
toolSlug: slug
|
|
434
|
+
});
|
|
214
435
|
}
|
|
215
436
|
let authCredentials = {};
|
|
216
437
|
const { toolkitSlug, execute } = tool.options;
|
|
217
|
-
if (toolkitSlug) {
|
|
438
|
+
if (toolkitSlug && toolkitSlug !== "custom") {
|
|
218
439
|
const connectedAccount = await this.getConnectedAccount(toolkitSlug, metadata);
|
|
219
440
|
if (!connectedAccount) {
|
|
220
|
-
throw new
|
|
221
|
-
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}
|
|
441
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
442
|
+
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}`,
|
|
443
|
+
{
|
|
444
|
+
toolkitSlug,
|
|
445
|
+
userId: metadata.userId
|
|
446
|
+
}
|
|
222
447
|
);
|
|
223
448
|
}
|
|
224
449
|
authCredentials = connectedAccount.data?.connectionParams;
|
|
225
450
|
}
|
|
226
451
|
if (typeof execute !== "function") {
|
|
227
|
-
throw new
|
|
452
|
+
throw new ComposioInvalidExecuteFunctionError("Invalid execute function", {
|
|
453
|
+
toolSlug: slug
|
|
454
|
+
});
|
|
228
455
|
}
|
|
229
456
|
const executeToolRequest = async (data) => {
|
|
230
457
|
return this.client.tools.proxy({
|
|
@@ -240,79 +467,42 @@ var CustomTools = class {
|
|
|
240
467
|
}
|
|
241
468
|
};
|
|
242
469
|
|
|
243
|
-
// src/
|
|
244
|
-
var
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
} catch (_e) {
|
|
248
|
-
logger_default.error(`Error getting environment variable ${name}:`, _e);
|
|
249
|
-
return defaultValue;
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// src/utils/logger.ts
|
|
254
|
-
var LOG_LEVELS = {
|
|
255
|
-
silent: -1,
|
|
256
|
-
// No logs
|
|
257
|
-
error: 0,
|
|
258
|
-
// Highest priority - critical errors
|
|
259
|
-
warn: 1,
|
|
260
|
-
// Warning messages
|
|
261
|
-
info: 2,
|
|
262
|
-
// General information
|
|
263
|
-
debug: 3
|
|
264
|
-
// Debug information
|
|
265
|
-
};
|
|
266
|
-
var getLogLevel = () => {
|
|
267
|
-
const envLevel = getEnvVariable(
|
|
268
|
-
"COMPOSIO_LOGGING_LEVEL",
|
|
269
|
-
"info"
|
|
270
|
-
)?.toLowerCase();
|
|
271
|
-
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
470
|
+
// src/errors/ValidationError.ts
|
|
471
|
+
var import_zod2 = require("zod");
|
|
472
|
+
var ValidationErrorCodes = {
|
|
473
|
+
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
272
474
|
};
|
|
273
|
-
var
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
288
|
-
return `${timestamp} - ${formattedArgs}`;
|
|
289
|
-
}
|
|
290
|
-
shouldLog(level) {
|
|
291
|
-
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
292
|
-
}
|
|
293
|
-
error(...args) {
|
|
294
|
-
if (this.shouldLog("error")) {
|
|
295
|
-
this.console.error(this.formatMessage(args));
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
warn(...args) {
|
|
299
|
-
if (this.shouldLog("warn")) {
|
|
300
|
-
this.console.warn(this.formatMessage(args));
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
info(...args) {
|
|
304
|
-
if (this.shouldLog("info")) {
|
|
305
|
-
this.console.info(this.formatMessage(args));
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
debug(...args) {
|
|
309
|
-
if (this.shouldLog("debug")) {
|
|
310
|
-
this.console.debug(this.formatMessage(args));
|
|
475
|
+
var ValidationError = class extends ComposioError {
|
|
476
|
+
zodError;
|
|
477
|
+
constructor(zodError, message = "Input validation failed") {
|
|
478
|
+
let zodErrorInstance;
|
|
479
|
+
if (!(zodError instanceof import_zod2.ZodError)) {
|
|
480
|
+
zodErrorInstance = new import_zod2.ZodError([
|
|
481
|
+
{
|
|
482
|
+
path: [],
|
|
483
|
+
message: "Invalid input",
|
|
484
|
+
code: "custom"
|
|
485
|
+
}
|
|
486
|
+
]);
|
|
487
|
+
} else {
|
|
488
|
+
zodErrorInstance = zodError;
|
|
311
489
|
}
|
|
490
|
+
super(message, {
|
|
491
|
+
code: ValidationErrorCodes.VALIDATION_ERROR,
|
|
492
|
+
meta: {
|
|
493
|
+
issues: JSON.stringify(
|
|
494
|
+
zodErrorInstance.issues.map((issue) => ({
|
|
495
|
+
path: issue.path.join("."),
|
|
496
|
+
message: issue.message,
|
|
497
|
+
code: issue.code
|
|
498
|
+
}))
|
|
499
|
+
)
|
|
500
|
+
},
|
|
501
|
+
cause: zodErrorInstance
|
|
502
|
+
});
|
|
503
|
+
this.zodError = zodErrorInstance;
|
|
312
504
|
}
|
|
313
505
|
};
|
|
314
|
-
var logger = new Logger();
|
|
315
|
-
var logger_default = logger;
|
|
316
506
|
|
|
317
507
|
// src/models/Tools.ts
|
|
318
508
|
var Tools = class {
|
|
@@ -320,9 +510,18 @@ var Tools = class {
|
|
|
320
510
|
customTools;
|
|
321
511
|
toolset;
|
|
322
512
|
constructor(client, toolset) {
|
|
513
|
+
if (!client) {
|
|
514
|
+
throw new Error("ComposioClient is required");
|
|
515
|
+
}
|
|
516
|
+
if (!toolset) {
|
|
517
|
+
throw new ComposioToolsetNotDefinedError("Toolset not passed into Tools instance");
|
|
518
|
+
}
|
|
323
519
|
this.client = client;
|
|
324
520
|
this.customTools = new CustomTools(client);
|
|
325
521
|
this.toolset = toolset;
|
|
522
|
+
this.execute = this.execute.bind(this);
|
|
523
|
+
this.getComposioToolBySlug = this.getComposioToolBySlug.bind(this);
|
|
524
|
+
this.getComposioTools = this.getComposioTools.bind(this);
|
|
326
525
|
}
|
|
327
526
|
/**
|
|
328
527
|
* Transform the tool cases
|
|
@@ -431,15 +630,15 @@ var Tools = class {
|
|
|
431
630
|
async getComposioTools(userId, query = {}, modifier) {
|
|
432
631
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
433
632
|
if (queryParams.error) {
|
|
434
|
-
throw new
|
|
633
|
+
throw new ValidationError(queryParams.error);
|
|
435
634
|
}
|
|
436
635
|
const tools = await this.client.tools.list({
|
|
636
|
+
tool_slugs: queryParams.data.tools?.join(","),
|
|
637
|
+
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
437
638
|
cursor: queryParams.data.cursor,
|
|
438
639
|
important: queryParams.data.important,
|
|
439
640
|
limit: queryParams.data.limit,
|
|
440
|
-
search: queryParams.data.search
|
|
441
|
-
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
442
|
-
tool_slugs: queryParams.data.tools?.join(",")
|
|
641
|
+
search: queryParams.data.search
|
|
443
642
|
});
|
|
444
643
|
if (!tools) {
|
|
445
644
|
return [];
|
|
@@ -452,10 +651,10 @@ var Tools = class {
|
|
|
452
651
|
if (modifier) {
|
|
453
652
|
if (typeof modifier === "function") {
|
|
454
653
|
modifiedTools = modifiedTools.map((tool) => {
|
|
455
|
-
return modifier(tool.slug, tool);
|
|
654
|
+
return modifier(tool.slug, tool.toolkit?.slug || "unkown", tool);
|
|
456
655
|
});
|
|
457
656
|
} else {
|
|
458
|
-
throw new
|
|
657
|
+
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
459
658
|
}
|
|
460
659
|
}
|
|
461
660
|
return modifiedTools;
|
|
@@ -472,14 +671,14 @@ var Tools = class {
|
|
|
472
671
|
}
|
|
473
672
|
const tool = await this.client.tools.retrieve(slug);
|
|
474
673
|
if (!tool) {
|
|
475
|
-
throw new
|
|
674
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
476
675
|
}
|
|
477
676
|
let modifiedToool = this.transformToolCases(tool);
|
|
478
677
|
if (modifier) {
|
|
479
678
|
if (typeof modifier === "function") {
|
|
480
|
-
modifiedToool = modifier(slug, modifiedToool);
|
|
679
|
+
modifiedToool = modifier(slug, modifiedToool.toolkit?.slug || "unkown", modifiedToool);
|
|
481
680
|
} else {
|
|
482
|
-
throw new
|
|
681
|
+
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
483
682
|
}
|
|
484
683
|
}
|
|
485
684
|
return modifiedToool;
|
|
@@ -514,6 +713,66 @@ var Tools = class {
|
|
|
514
713
|
};
|
|
515
714
|
return executeToolFn;
|
|
516
715
|
}
|
|
716
|
+
async handleCustomToolExecution(tool, body, modifiers) {
|
|
717
|
+
if (modifiers?.beforeToolExecute) {
|
|
718
|
+
if (typeof modifiers.beforeToolExecute === "function") {
|
|
719
|
+
body = modifiers.beforeToolExecute(tool.slug, "unkown", body);
|
|
720
|
+
} else {
|
|
721
|
+
throw new ComposioInvalidModifierError(
|
|
722
|
+
"Invalid beforeToolExecute modifier. Not a function."
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
let result = await this.customTools.executeCustomTool(tool.slug, body, {
|
|
727
|
+
userId: body.userId || "default",
|
|
728
|
+
connectedAccountId: body.connectedAccountId
|
|
729
|
+
});
|
|
730
|
+
if (modifiers?.afterToolExecute) {
|
|
731
|
+
if (typeof modifiers.afterToolExecute === "function") {
|
|
732
|
+
result = modifiers.afterToolExecute(tool.slug, "unkown", result);
|
|
733
|
+
} else {
|
|
734
|
+
throw new ComposioInvalidModifierError(
|
|
735
|
+
"Invalid afterToolExecute modifier. Not a function."
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
return result;
|
|
740
|
+
}
|
|
741
|
+
async handleComposioToolExecution(tool, body, modifiers) {
|
|
742
|
+
if (modifiers?.beforeToolExecute) {
|
|
743
|
+
if (typeof modifiers.beforeToolExecute === "function") {
|
|
744
|
+
body = modifiers.beforeToolExecute(tool.slug, tool.toolkit?.slug || "unkown", body);
|
|
745
|
+
} else {
|
|
746
|
+
throw new ComposioInvalidModifierError(
|
|
747
|
+
"Invalid beforeToolExecute modifier. Not a function."
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
let connectedAccountId = body.connectedAccountId;
|
|
752
|
+
if (!connectedAccountId) {
|
|
753
|
+
connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, tool.slug) || void 0;
|
|
754
|
+
}
|
|
755
|
+
let result = await this.client.tools.execute(tool.slug, {
|
|
756
|
+
allow_tracing: body.allowTracing,
|
|
757
|
+
connected_account_id: body.connectedAccountId,
|
|
758
|
+
custom_auth_params: body.customAuthParams,
|
|
759
|
+
arguments: body.arguments,
|
|
760
|
+
entity_id: body.userId,
|
|
761
|
+
version: body.version,
|
|
762
|
+
text: body.text
|
|
763
|
+
});
|
|
764
|
+
result = this.transformToolExecuteResponse(result);
|
|
765
|
+
if (modifiers?.afterToolExecute) {
|
|
766
|
+
if (typeof modifiers.afterToolExecute === "function") {
|
|
767
|
+
result = modifiers.afterToolExecute(tool.slug, tool.toolkit?.slug || "unkown", result);
|
|
768
|
+
} else {
|
|
769
|
+
throw new ComposioInvalidModifierError(
|
|
770
|
+
"Invalid afterToolExecute modifier. Not a function."
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
return result;
|
|
775
|
+
}
|
|
517
776
|
/**
|
|
518
777
|
* Exectes a given tool with the provided parameters.
|
|
519
778
|
*
|
|
@@ -524,44 +783,28 @@ var Tools = class {
|
|
|
524
783
|
* @returns {Promise<ToolExecuteResponse>} - The response from the tool execution
|
|
525
784
|
*/
|
|
526
785
|
async execute(slug, body, modifiers) {
|
|
527
|
-
if (
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
throw new Error("Invalid beforeToolExecute modifier. Not a function.");
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
let result;
|
|
535
|
-
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
536
|
-
if (customTool) {
|
|
537
|
-
result = await this.customTools.executeCustomTool(slug, body, {
|
|
538
|
-
userId: body.userId || "default",
|
|
539
|
-
connectedAccountId: body.connectedAccountId
|
|
540
|
-
});
|
|
541
|
-
} else {
|
|
542
|
-
let connectedAccountId = body.connectedAccountId;
|
|
543
|
-
if (!connectedAccountId) {
|
|
544
|
-
connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, slug) || void 0;
|
|
545
|
-
}
|
|
546
|
-
result = await this.client.tools.execute(slug, {
|
|
547
|
-
allow_tracing: body.allowTracing,
|
|
548
|
-
connected_account_id: body.connectedAccountId,
|
|
549
|
-
custom_auth_params: body.customAuthParams,
|
|
550
|
-
arguments: body.arguments,
|
|
551
|
-
entity_id: body.userId,
|
|
552
|
-
version: body.version,
|
|
553
|
-
text: body.text
|
|
554
|
-
});
|
|
555
|
-
result = this.transformToolExecuteResponse(result);
|
|
786
|
+
if (!this.customTools) {
|
|
787
|
+
throw new ComposioCustomToolsNotInitializedError(
|
|
788
|
+
"CustomTools not initialized. Make sure Tools class is properly constructed."
|
|
789
|
+
);
|
|
556
790
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
791
|
+
try {
|
|
792
|
+
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
793
|
+
if (customTool) {
|
|
794
|
+
return this.handleCustomToolExecution(customTool, body, modifiers);
|
|
560
795
|
} else {
|
|
561
|
-
|
|
796
|
+
const composioTool = await this.getComposioToolBySlug(body.userId, slug);
|
|
797
|
+
if (!composioTool) {
|
|
798
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
799
|
+
}
|
|
800
|
+
return this.handleComposioToolExecution(composioTool, body, modifiers);
|
|
562
801
|
}
|
|
802
|
+
} catch (error) {
|
|
803
|
+
throw new ComposioToolExecutionError(error, `Error executing tool ${slug}`, {
|
|
804
|
+
toolSlug: slug,
|
|
805
|
+
body
|
|
806
|
+
});
|
|
563
807
|
}
|
|
564
|
-
return result;
|
|
565
808
|
}
|
|
566
809
|
/**
|
|
567
810
|
* Fetches the list of all available tools in the Composio SDK.
|
|
@@ -604,924 +847,1039 @@ var Tools = class {
|
|
|
604
847
|
};
|
|
605
848
|
|
|
606
849
|
// src/types/toolkit.types.ts
|
|
607
|
-
var
|
|
608
|
-
var ToolkitMangedByEnumSchema =
|
|
609
|
-
var ToolkitSortByEnumSchema =
|
|
610
|
-
var ToolkitsListParamsSchema =
|
|
611
|
-
category:
|
|
612
|
-
isLocal:
|
|
850
|
+
var import_zod3 = require("zod");
|
|
851
|
+
var ToolkitMangedByEnumSchema = import_zod3.z.enum(["all", "composio_managed", "project_managed"]);
|
|
852
|
+
var ToolkitSortByEnumSchema = import_zod3.z.enum(["usage", "alphabetically"]);
|
|
853
|
+
var ToolkitsListParamsSchema = import_zod3.z.object({
|
|
854
|
+
category: import_zod3.z.string().optional(),
|
|
855
|
+
isLocal: import_zod3.z.boolean().optional(),
|
|
613
856
|
managedBy: ToolkitMangedByEnumSchema.optional(),
|
|
614
857
|
sortBy: ToolkitSortByEnumSchema.optional()
|
|
615
858
|
});
|
|
616
|
-
var ToolKitMetaSchema =
|
|
617
|
-
categories:
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
name:
|
|
859
|
+
var ToolKitMetaSchema = import_zod3.z.object({
|
|
860
|
+
categories: import_zod3.z.array(
|
|
861
|
+
import_zod3.z.object({
|
|
862
|
+
slug: import_zod3.z.string(),
|
|
863
|
+
name: import_zod3.z.string()
|
|
621
864
|
})
|
|
622
|
-
),
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
865
|
+
).optional(),
|
|
866
|
+
appUrl: import_zod3.z.string().optional(),
|
|
867
|
+
createdAt: import_zod3.z.string().optional(),
|
|
868
|
+
description: import_zod3.z.string().optional(),
|
|
869
|
+
logo: import_zod3.z.string().optional(),
|
|
870
|
+
toolsCount: import_zod3.z.number().optional(),
|
|
871
|
+
triggersCount: import_zod3.z.number().optional(),
|
|
872
|
+
updatedAt: import_zod3.z.string().optional()
|
|
629
873
|
});
|
|
630
|
-
var ToolKitItemSchema =
|
|
631
|
-
name:
|
|
632
|
-
slug:
|
|
874
|
+
var ToolKitItemSchema = import_zod3.z.object({
|
|
875
|
+
name: import_zod3.z.string(),
|
|
876
|
+
slug: import_zod3.z.string(),
|
|
633
877
|
meta: ToolKitMetaSchema,
|
|
634
|
-
isLocalToolkit:
|
|
635
|
-
authSchemes:
|
|
636
|
-
composioManagedAuthSchemes:
|
|
637
|
-
noAuth:
|
|
878
|
+
isLocalToolkit: import_zod3.z.boolean(),
|
|
879
|
+
authSchemes: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
880
|
+
composioManagedAuthSchemes: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
881
|
+
noAuth: import_zod3.z.boolean().optional()
|
|
638
882
|
});
|
|
639
|
-
var ToolKitListResponseSchema =
|
|
640
|
-
items:
|
|
641
|
-
nextCursor:
|
|
642
|
-
totalPages:
|
|
883
|
+
var ToolKitListResponseSchema = import_zod3.z.object({
|
|
884
|
+
items: import_zod3.z.array(ToolKitItemSchema),
|
|
885
|
+
nextCursor: import_zod3.z.string().nullable(),
|
|
886
|
+
totalPages: import_zod3.z.number()
|
|
643
887
|
});
|
|
644
|
-
var ToolkitAuthFieldSchema =
|
|
645
|
-
name:
|
|
646
|
-
displayName:
|
|
647
|
-
type:
|
|
648
|
-
default:
|
|
888
|
+
var ToolkitAuthFieldSchema = import_zod3.z.object({
|
|
889
|
+
name: import_zod3.z.string(),
|
|
890
|
+
displayName: import_zod3.z.string(),
|
|
891
|
+
type: import_zod3.z.string(),
|
|
892
|
+
default: import_zod3.z.string().nullable().optional()
|
|
649
893
|
});
|
|
650
|
-
var ToolkitAuthConfigDetailsSchema =
|
|
651
|
-
name:
|
|
652
|
-
mode:
|
|
653
|
-
fields:
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
required: import_zod2.z.array(ToolkitAuthFieldSchema)
|
|
662
|
-
})
|
|
894
|
+
var ToolkitAuthConfigDetailsSchema = import_zod3.z.object({
|
|
895
|
+
name: import_zod3.z.string(),
|
|
896
|
+
mode: import_zod3.z.string(),
|
|
897
|
+
fields: import_zod3.z.object({
|
|
898
|
+
authConfigCreation: import_zod3.z.object({
|
|
899
|
+
optional: import_zod3.z.array(ToolkitAuthFieldSchema),
|
|
900
|
+
required: import_zod3.z.array(ToolkitAuthFieldSchema)
|
|
901
|
+
}),
|
|
902
|
+
connectedAccountInitiation: import_zod3.z.object({
|
|
903
|
+
optional: import_zod3.z.array(ToolkitAuthFieldSchema),
|
|
904
|
+
required: import_zod3.z.array(ToolkitAuthFieldSchema)
|
|
663
905
|
})
|
|
664
|
-
),
|
|
665
|
-
proxy:
|
|
666
|
-
|
|
906
|
+
}),
|
|
907
|
+
proxy: import_zod3.z.object({
|
|
908
|
+
baseUrl: import_zod3.z.string()
|
|
667
909
|
})
|
|
668
910
|
});
|
|
669
|
-
var ToolkitRetrieveResponseSchema =
|
|
670
|
-
name:
|
|
671
|
-
slug:
|
|
911
|
+
var ToolkitRetrieveResponseSchema = import_zod3.z.object({
|
|
912
|
+
name: import_zod3.z.string(),
|
|
913
|
+
slug: import_zod3.z.string(),
|
|
672
914
|
meta: ToolKitMetaSchema,
|
|
673
|
-
isLocalToolkit:
|
|
674
|
-
composioManagedAuthSchemes:
|
|
675
|
-
authConfigDetails:
|
|
915
|
+
isLocalToolkit: import_zod3.z.boolean(),
|
|
916
|
+
composioManagedAuthSchemes: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
917
|
+
authConfigDetails: import_zod3.z.array(ToolkitAuthConfigDetailsSchema).optional()
|
|
676
918
|
});
|
|
677
|
-
var ToolkitCategorySchema =
|
|
678
|
-
id:
|
|
679
|
-
name:
|
|
919
|
+
var ToolkitCategorySchema = import_zod3.z.object({
|
|
920
|
+
id: import_zod3.z.string(),
|
|
921
|
+
name: import_zod3.z.string()
|
|
680
922
|
});
|
|
681
|
-
var ToolkitRetrieveCategoriesResponseSchema =
|
|
682
|
-
items:
|
|
683
|
-
nextCursor:
|
|
684
|
-
totalPages:
|
|
923
|
+
var ToolkitRetrieveCategoriesResponseSchema = import_zod3.z.object({
|
|
924
|
+
items: import_zod3.z.array(ToolkitCategorySchema),
|
|
925
|
+
nextCursor: import_zod3.z.string().nullable(),
|
|
926
|
+
totalPages: import_zod3.z.number()
|
|
685
927
|
});
|
|
686
928
|
|
|
687
929
|
// src/models/Toolkits.ts
|
|
688
|
-
var
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
930
|
+
var import_zod7 = require("zod");
|
|
931
|
+
|
|
932
|
+
// src/types/authConfigs.types.ts
|
|
933
|
+
var import_zod4 = require("zod");
|
|
934
|
+
var AuthConfigTypes = {
|
|
935
|
+
CUSTOM: "use_custom_auth",
|
|
936
|
+
COMPOSIO_MANAGED: "use_composio_managed_auth"
|
|
937
|
+
};
|
|
938
|
+
var AuthSchemeTypes = {
|
|
939
|
+
OAUTH2: "OAUTH2",
|
|
940
|
+
OAUTH1: "OAUTH1",
|
|
941
|
+
OAUTH1A: "OAUTH1A",
|
|
942
|
+
API_KEY: "API_KEY",
|
|
943
|
+
BASIC: "BASIC",
|
|
944
|
+
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
945
|
+
BEARER_TOKEN: "BEARER_TOKEN",
|
|
946
|
+
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
947
|
+
NO_AUTH: "NO_AUTH",
|
|
948
|
+
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
949
|
+
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
950
|
+
CALCOM_AUTH: "CALCOM_AUTH",
|
|
951
|
+
SNOWFLAKE: "SNOWFLAKE"
|
|
952
|
+
};
|
|
953
|
+
var AuthSchemeEnum = import_zod4.z.enum([
|
|
954
|
+
"OAUTH2",
|
|
955
|
+
"OAUTH1",
|
|
956
|
+
"OAUTH1A",
|
|
957
|
+
"API_KEY",
|
|
958
|
+
"BASIC",
|
|
959
|
+
"BILLCOM_AUTH",
|
|
960
|
+
"BEARER_TOKEN",
|
|
961
|
+
"GOOGLE_SERVICE_ACCOUNT",
|
|
962
|
+
"NO_AUTH",
|
|
963
|
+
"BASIC_WITH_JWT",
|
|
964
|
+
"COMPOSIO_LINK",
|
|
965
|
+
"CALCOM_AUTH",
|
|
966
|
+
"SNOWFLAKE"
|
|
967
|
+
]);
|
|
968
|
+
var CreateCustomAuthConfigParamsSchema = import_zod4.z.object({
|
|
969
|
+
type: import_zod4.z.literal("use_custom_auth"),
|
|
970
|
+
name: import_zod4.z.string().optional(),
|
|
971
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()])),
|
|
972
|
+
authScheme: AuthSchemeEnum
|
|
973
|
+
});
|
|
974
|
+
var CreateComposioManagedAuthConfigParamsSchema = import_zod4.z.object({
|
|
975
|
+
type: import_zod4.z.literal("use_composio_managed_auth"),
|
|
976
|
+
name: import_zod4.z.string().optional(),
|
|
977
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()])).optional()
|
|
978
|
+
});
|
|
979
|
+
var CreateAuthConfigParamsSchema = import_zod4.z.discriminatedUnion("type", [
|
|
980
|
+
CreateCustomAuthConfigParamsSchema,
|
|
981
|
+
CreateComposioManagedAuthConfigParamsSchema
|
|
982
|
+
]);
|
|
983
|
+
var CreateAuthConfigResponseSchema = import_zod4.z.object({
|
|
984
|
+
id: import_zod4.z.string(),
|
|
985
|
+
authScheme: import_zod4.z.string(),
|
|
986
|
+
isComposioManaged: import_zod4.z.boolean(),
|
|
987
|
+
toolkit: import_zod4.z.string()
|
|
988
|
+
});
|
|
989
|
+
var AuthConfigRetrieveResponseSchema = import_zod4.z.object({
|
|
990
|
+
id: import_zod4.z.string(),
|
|
991
|
+
name: import_zod4.z.string(),
|
|
992
|
+
toolkit: import_zod4.z.object({
|
|
993
|
+
logo: import_zod4.z.string(),
|
|
994
|
+
slug: import_zod4.z.string()
|
|
995
|
+
}),
|
|
996
|
+
noOfConnections: import_zod4.z.number(),
|
|
997
|
+
status: import_zod4.z.enum(["ENABLED", "DISABLED"]),
|
|
998
|
+
uuid: import_zod4.z.string(),
|
|
999
|
+
authScheme: AuthSchemeEnum.optional(),
|
|
1000
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()])),
|
|
1001
|
+
expectedInputFields: import_zod4.z.array(import_zod4.z.unknown()).optional(),
|
|
1002
|
+
isComposioManaged: import_zod4.z.boolean().optional(),
|
|
1003
|
+
createdBy: import_zod4.z.string().optional(),
|
|
1004
|
+
createdAt: import_zod4.z.string().optional(),
|
|
1005
|
+
lastUpdatedAt: import_zod4.z.string().optional()
|
|
1006
|
+
});
|
|
1007
|
+
var AuthConfigListParamsSchema = import_zod4.z.object({
|
|
1008
|
+
cursor: import_zod4.z.string().optional(),
|
|
1009
|
+
isComposioManaged: import_zod4.z.boolean().optional(),
|
|
1010
|
+
limit: import_zod4.z.number().optional(),
|
|
1011
|
+
toolkitSlug: import_zod4.z.string().optional()
|
|
1012
|
+
});
|
|
1013
|
+
var AuthConfigListResponseSchema = import_zod4.z.object({
|
|
1014
|
+
items: import_zod4.z.array(AuthConfigRetrieveResponseSchema),
|
|
1015
|
+
nextCursor: import_zod4.z.string().optional(),
|
|
1016
|
+
totalPages: import_zod4.z.number()
|
|
1017
|
+
});
|
|
1018
|
+
var AuthConfigUpdateParamsSchema = import_zod4.z.object({
|
|
1019
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()]))
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
// src/models/AuthConfigs.ts
|
|
1023
|
+
var AuthConfigs = class {
|
|
1024
|
+
client;
|
|
1025
|
+
constructor(client) {
|
|
1026
|
+
this.client = client;
|
|
1027
|
+
}
|
|
1028
|
+
parseAuthConfigRetrieveResponse(authConfig) {
|
|
1029
|
+
const result = AuthConfigRetrieveResponseSchema.safeParse({
|
|
1030
|
+
id: authConfig.id,
|
|
1031
|
+
name: authConfig.name,
|
|
1032
|
+
noOfConnections: authConfig.no_of_connections,
|
|
1033
|
+
status: authConfig.status,
|
|
1034
|
+
toolkit: {
|
|
1035
|
+
logo: authConfig.toolkit.logo,
|
|
1036
|
+
slug: authConfig.toolkit.slug
|
|
1037
|
+
},
|
|
1038
|
+
uuid: authConfig.uuid,
|
|
1039
|
+
authScheme: authConfig.auth_scheme,
|
|
1040
|
+
credentials: authConfig.credentials,
|
|
1041
|
+
expectedInputFields: authConfig.expected_input_fields,
|
|
1042
|
+
isComposioManaged: authConfig.is_composio_managed,
|
|
1043
|
+
createdBy: authConfig.created_by,
|
|
1044
|
+
createdAt: authConfig.created_at,
|
|
1045
|
+
lastUpdatedAt: authConfig.last_updated_at
|
|
1046
|
+
});
|
|
1047
|
+
if (result.error) {
|
|
1048
|
+
throw new ValidationError(result.error);
|
|
1049
|
+
}
|
|
1050
|
+
return result.data;
|
|
1051
|
+
}
|
|
693
1052
|
/**
|
|
694
|
-
* List all
|
|
695
|
-
*
|
|
696
|
-
* @
|
|
1053
|
+
* List all auth configs
|
|
1054
|
+
* @param {AuthConfigListParams} query - Query parameters for filtering auth configs
|
|
1055
|
+
* @param {RequestOptions} options - Request options
|
|
1056
|
+
* @returns {Promise<AuthConfigListResponse>} List of auth configs
|
|
697
1057
|
*/
|
|
698
|
-
async
|
|
699
|
-
const parsedQuery =
|
|
700
|
-
const result = await this.client.
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
1058
|
+
async list(query) {
|
|
1059
|
+
const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : void 0;
|
|
1060
|
+
const result = await this.client.authConfigs.list({
|
|
1061
|
+
cursor: parsedQuery?.cursor,
|
|
1062
|
+
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1063
|
+
limit: parsedQuery?.limit?.toString(),
|
|
1064
|
+
toolkit_slug: parsedQuery?.toolkitSlug
|
|
705
1065
|
});
|
|
706
|
-
const parsedResult =
|
|
707
|
-
items: result.items.map((item) =>
|
|
708
|
-
const parsedItem = ToolKitItemSchema.parse({
|
|
709
|
-
name: item.name,
|
|
710
|
-
slug: item.slug,
|
|
711
|
-
meta: item.meta,
|
|
712
|
-
isLocalToolkit: item.is_local_toolkit,
|
|
713
|
-
authSchemes: item.auth_schemes,
|
|
714
|
-
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
715
|
-
noAuth: item.no_auth
|
|
716
|
-
});
|
|
717
|
-
return parsedItem;
|
|
718
|
-
}),
|
|
1066
|
+
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
1067
|
+
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
719
1068
|
nextCursor: result.next_cursor,
|
|
720
1069
|
totalPages: result.total_pages
|
|
721
1070
|
});
|
|
722
|
-
|
|
1071
|
+
if (parsedResult.error) {
|
|
1072
|
+
throw new ValidationError(parsedResult.error);
|
|
1073
|
+
}
|
|
1074
|
+
return parsedResult.data;
|
|
723
1075
|
}
|
|
724
1076
|
/**
|
|
725
|
-
*
|
|
726
|
-
*
|
|
727
|
-
* @param
|
|
728
|
-
* @
|
|
729
|
-
*
|
|
1077
|
+
* Create a new auth config
|
|
1078
|
+
* @param {string} toolkit - Unique identifier of the toolkit
|
|
1079
|
+
* @param {CreateAuthConfigParams} options - Options for creating a new auth config
|
|
1080
|
+
* @returns {Promise<CreateAuthConfigResponse>} Created auth config
|
|
1081
|
+
*
|
|
1082
|
+
* @example
|
|
1083
|
+
* const authConfig = await authConfigs.create('my-toolkit', {
|
|
1084
|
+
* type: AuthConfigTypes.CUSTOM,
|
|
1085
|
+
* name: 'My Custom Auth Config',
|
|
1086
|
+
* authScheme: AuthSchemeTypes.API_KEY,
|
|
1087
|
+
* credentials: {
|
|
1088
|
+
* apiKey: '1234567890',
|
|
1089
|
+
* },
|
|
1090
|
+
* });
|
|
1091
|
+
*
|
|
1092
|
+
* @link https://docs.composio.dev/reference/auth-configs/create-auth-config
|
|
730
1093
|
*/
|
|
731
|
-
async
|
|
732
|
-
const
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
1094
|
+
async create(toolkit, options) {
|
|
1095
|
+
const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
|
|
1096
|
+
if (parsedOptions.error) {
|
|
1097
|
+
throw new ValidationError(parsedOptions.error);
|
|
1098
|
+
}
|
|
1099
|
+
const result = await this.client.authConfigs.create({
|
|
1100
|
+
toolkit: {
|
|
1101
|
+
slug: toolkit
|
|
1102
|
+
},
|
|
1103
|
+
auth_config: parsedOptions.data
|
|
740
1104
|
});
|
|
741
|
-
|
|
1105
|
+
const parsedResult = CreateAuthConfigResponseSchema.safeParse({
|
|
1106
|
+
id: result.auth_config.id,
|
|
1107
|
+
authScheme: result.auth_config.auth_scheme,
|
|
1108
|
+
isComposioManaged: result.auth_config.is_composio_managed,
|
|
1109
|
+
toolkit: result.toolkit.slug
|
|
1110
|
+
});
|
|
1111
|
+
if (parsedResult.error) {
|
|
1112
|
+
throw new ValidationError(parsedResult.error);
|
|
1113
|
+
}
|
|
1114
|
+
return parsedResult.data;
|
|
742
1115
|
}
|
|
743
1116
|
/**
|
|
744
|
-
*
|
|
745
|
-
*
|
|
746
|
-
* @param
|
|
747
|
-
* @returns {Promise<
|
|
1117
|
+
* Get an auth config by nanoid
|
|
1118
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1119
|
+
* @param {RequestOptions} options - Request options
|
|
1120
|
+
* @returns {Promise<AuthConfigRetrieveResponse>} Auth config details
|
|
748
1121
|
*/
|
|
749
|
-
async get(
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}
|
|
753
|
-
return this.getToolkits(arg);
|
|
1122
|
+
async get(nanoid) {
|
|
1123
|
+
const result = await this.client.authConfigs.retrieve(nanoid);
|
|
1124
|
+
return this.parseAuthConfigRetrieveResponse(result);
|
|
754
1125
|
}
|
|
755
1126
|
/**
|
|
756
|
-
*
|
|
757
|
-
*
|
|
758
|
-
* @
|
|
1127
|
+
* Update an auth config
|
|
1128
|
+
* @param {string} nanoid - Unique identifier of the auth config to update
|
|
1129
|
+
* @param {AuthConfigUpdateParams} data - Data to update
|
|
1130
|
+
* @param {RequestOptions} options - Request options
|
|
1131
|
+
* @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
|
|
759
1132
|
*/
|
|
760
|
-
async
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
id: item.id,
|
|
766
|
-
name: item.name
|
|
767
|
-
});
|
|
768
|
-
return parsedItem;
|
|
769
|
-
}),
|
|
770
|
-
nextCursor: result.next_cursor,
|
|
771
|
-
totalPages: result.total_pages
|
|
1133
|
+
async update(nanoid, data) {
|
|
1134
|
+
return this.client.authConfigs.update(nanoid, {
|
|
1135
|
+
auth_config: {
|
|
1136
|
+
credentials: data.credentials
|
|
1137
|
+
}
|
|
772
1138
|
});
|
|
773
|
-
return parsedResult;
|
|
774
1139
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
if (!_PusherUtils.pusherClient) {
|
|
784
|
-
const PusherClient = require("pusher-js");
|
|
785
|
-
_PusherUtils.pusherClient = new PusherClient(PUSHER_KEY, {
|
|
786
|
-
cluster: PUSHER_CLUSTER,
|
|
787
|
-
channelAuthorization: {
|
|
788
|
-
endpoint: `${baseURL}/api/v1/client/auth/pusher_auth`,
|
|
789
|
-
headers: {
|
|
790
|
-
"x-api-key": apiKey
|
|
791
|
-
},
|
|
792
|
-
transport: "ajax"
|
|
793
|
-
}
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
return _PusherUtils.pusherClient;
|
|
1140
|
+
/**
|
|
1141
|
+
* Delete an auth config
|
|
1142
|
+
* @param {string} nanoid - Unique identifier of the auth config to delete
|
|
1143
|
+
* @param {RequestOptions} options - Request options
|
|
1144
|
+
* @returns {Promise<AuthConfigDeleteResponse>} Response from deletion
|
|
1145
|
+
*/
|
|
1146
|
+
async delete(nanoid) {
|
|
1147
|
+
return this.client.authConfigs.delete(nanoid);
|
|
797
1148
|
}
|
|
798
1149
|
/**
|
|
799
|
-
*
|
|
800
|
-
* @param {string}
|
|
801
|
-
* @param {string}
|
|
802
|
-
* @param {
|
|
803
|
-
* @returns {
|
|
1150
|
+
* Update the status of an auth config
|
|
1151
|
+
* @param {string} status - The status to update the auth config to
|
|
1152
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1153
|
+
* @param {RequestOptions} options - Request options
|
|
1154
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
804
1155
|
*/
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
await _PusherUtils.pusherClient.subscribe(channelName).bind(event, fn);
|
|
808
|
-
} catch (error) {
|
|
809
|
-
logger_default.error(
|
|
810
|
-
`Error subscribing to ${channelName} with event ${event}: ${error}`
|
|
811
|
-
);
|
|
812
|
-
}
|
|
1156
|
+
async updateStatus(status, nanoid) {
|
|
1157
|
+
return this.client.authConfigs.updateStatus(status, { nanoid });
|
|
813
1158
|
}
|
|
814
1159
|
/**
|
|
815
|
-
*
|
|
816
|
-
* @param {string}
|
|
817
|
-
* @
|
|
1160
|
+
* Enable an auth config
|
|
1161
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1162
|
+
* @param {RequestOptions} options - Request options
|
|
1163
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
818
1164
|
*/
|
|
819
|
-
|
|
820
|
-
|
|
1165
|
+
async enable(nanoid) {
|
|
1166
|
+
return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
|
|
821
1167
|
}
|
|
822
1168
|
/**
|
|
823
|
-
*
|
|
824
|
-
* @param {
|
|
825
|
-
* @param {
|
|
826
|
-
* @
|
|
1169
|
+
* Disable an auth config
|
|
1170
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1171
|
+
* @param {RequestOptions} options - Request options
|
|
1172
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
827
1173
|
*/
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
const events = {};
|
|
831
|
-
channel.bind("chunked-" + event, (data) => {
|
|
832
|
-
const typedData = data;
|
|
833
|
-
if (!events.hasOwnProperty(typedData.id)) {
|
|
834
|
-
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
835
|
-
}
|
|
836
|
-
const ev = events[typedData.id];
|
|
837
|
-
ev.chunks[typedData.index] = typedData.chunk;
|
|
838
|
-
if (typedData.final) ev.receivedFinal = true;
|
|
839
|
-
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
840
|
-
callback(JSON.parse(ev.chunks.join("")));
|
|
841
|
-
delete events[typedData.id];
|
|
842
|
-
}
|
|
843
|
-
});
|
|
1174
|
+
async disable(nanoid) {
|
|
1175
|
+
return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
|
|
844
1176
|
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
);
|
|
1177
|
+
};
|
|
1178
|
+
|
|
1179
|
+
// src/errors/AuthConfigErrors.ts
|
|
1180
|
+
var AuthConfigErrorCodes = {
|
|
1181
|
+
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1182
|
+
};
|
|
1183
|
+
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1184
|
+
constructor(message, meta) {
|
|
1185
|
+
super(message, {
|
|
1186
|
+
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1187
|
+
cause: meta,
|
|
1188
|
+
possibleFixes: [
|
|
1189
|
+
"Check if the auth config exists",
|
|
1190
|
+
"Check if the auth config id is correct",
|
|
1191
|
+
"Check if the auth config is enabled"
|
|
1192
|
+
]
|
|
1193
|
+
});
|
|
1194
|
+
this.name = "ComposioAuthConfigNotFoundError";
|
|
862
1195
|
}
|
|
863
|
-
|
|
864
|
-
|
|
1196
|
+
};
|
|
1197
|
+
|
|
1198
|
+
// src/types/connectedAccounts.types.ts
|
|
1199
|
+
var import_zod5 = require("zod");
|
|
1200
|
+
var ConnectedAccountStatuses = {
|
|
1201
|
+
ACTIVE: "ACTIVE",
|
|
1202
|
+
INACTIVE: "INACTIVE",
|
|
1203
|
+
PENDING: "DELETED",
|
|
1204
|
+
INITIATED: "INITIATED",
|
|
1205
|
+
EXPIRED: "EXPIRED",
|
|
1206
|
+
FAILED: "FAILED"
|
|
1207
|
+
};
|
|
1208
|
+
var ConnectedAccountStatusSchema = import_zod5.z.enum([
|
|
1209
|
+
ConnectedAccountStatuses.ACTIVE,
|
|
1210
|
+
ConnectedAccountStatuses.INACTIVE,
|
|
1211
|
+
ConnectedAccountStatuses.PENDING,
|
|
1212
|
+
ConnectedAccountStatuses.INITIATED,
|
|
1213
|
+
ConnectedAccountStatuses.EXPIRED,
|
|
1214
|
+
ConnectedAccountStatuses.FAILED
|
|
1215
|
+
]);
|
|
1216
|
+
var CreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
1217
|
+
authConfig: import_zod5.z.object({
|
|
1218
|
+
id: import_zod5.z.string()
|
|
1219
|
+
}),
|
|
1220
|
+
connection: import_zod5.z.object({
|
|
1221
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1222
|
+
redirectUrl: import_zod5.z.string().optional(),
|
|
1223
|
+
userId: import_zod5.z.string().optional()
|
|
1224
|
+
})
|
|
1225
|
+
});
|
|
1226
|
+
var DefaultCreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
1227
|
+
auth_config: import_zod5.z.object({
|
|
1228
|
+
id: import_zod5.z.string()
|
|
1229
|
+
}),
|
|
1230
|
+
connection: import_zod5.z.object({
|
|
1231
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1232
|
+
redirect_uri: import_zod5.z.string().optional(),
|
|
1233
|
+
user_id: import_zod5.z.string().optional()
|
|
1234
|
+
})
|
|
1235
|
+
});
|
|
1236
|
+
var CreateConnectedAccountOptionsSchema = import_zod5.z.object({
|
|
1237
|
+
redirectUrl: import_zod5.z.string().optional(),
|
|
1238
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional()
|
|
1239
|
+
});
|
|
1240
|
+
var CreateConnectedAccountResponseSchema = import_zod5.z.object({
|
|
1241
|
+
id: import_zod5.z.string(),
|
|
1242
|
+
status: ConnectedAccountStatusSchema,
|
|
1243
|
+
redirectUrl: import_zod5.z.string().nullable()
|
|
1244
|
+
});
|
|
1245
|
+
var ConnectedAccountAuthSchemes = {
|
|
1246
|
+
OAUTH2: "OAUTH2",
|
|
1247
|
+
OAUTH1: "OAUTH1",
|
|
1248
|
+
OAUTH1A: "OAUTH1A",
|
|
1249
|
+
API_KEY: "API_KEY",
|
|
1250
|
+
BASIC: "BASIC",
|
|
1251
|
+
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
1252
|
+
BEARER_TOKEN: "BEARER_TOKEN",
|
|
1253
|
+
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
1254
|
+
NO_AUTH: "NO_AUTH",
|
|
1255
|
+
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
1256
|
+
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
1257
|
+
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1258
|
+
SNOWFLAKE: "SNOWFLAKE"
|
|
1259
|
+
};
|
|
1260
|
+
var ConnectedAccountAuthSchemesSchema = import_zod5.z.enum([
|
|
1261
|
+
ConnectedAccountAuthSchemes.OAUTH2,
|
|
1262
|
+
ConnectedAccountAuthSchemes.OAUTH1,
|
|
1263
|
+
ConnectedAccountAuthSchemes.OAUTH1A,
|
|
1264
|
+
ConnectedAccountAuthSchemes.API_KEY,
|
|
1265
|
+
ConnectedAccountAuthSchemes.BASIC,
|
|
1266
|
+
ConnectedAccountAuthSchemes.BILLCOM_AUTH,
|
|
1267
|
+
ConnectedAccountAuthSchemes.BEARER_TOKEN,
|
|
1268
|
+
ConnectedAccountAuthSchemes.GOOGLE_SERVICE_ACCOUNT,
|
|
1269
|
+
ConnectedAccountAuthSchemes.NO_AUTH,
|
|
1270
|
+
ConnectedAccountAuthSchemes.BASIC_WITH_JWT,
|
|
1271
|
+
ConnectedAccountAuthSchemes.COMPOSIO_LINK,
|
|
1272
|
+
ConnectedAccountAuthSchemes.CALCOM_AUTH,
|
|
1273
|
+
ConnectedAccountAuthSchemes.SNOWFLAKE
|
|
1274
|
+
]);
|
|
1275
|
+
var ConnectedAccountAuthConfigSchema = import_zod5.z.object({
|
|
1276
|
+
id: import_zod5.z.string(),
|
|
1277
|
+
authScheme: ConnectedAccountAuthSchemesSchema,
|
|
1278
|
+
isComposioManaged: import_zod5.z.boolean(),
|
|
1279
|
+
isDisabled: import_zod5.z.boolean()
|
|
1280
|
+
});
|
|
1281
|
+
var ConnectedAccountRetrieveResponseSchema = import_zod5.z.object({
|
|
1282
|
+
id: import_zod5.z.string(),
|
|
1283
|
+
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1284
|
+
userId: import_zod5.z.string(),
|
|
1285
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
|
|
1286
|
+
params: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
|
|
1287
|
+
status: ConnectedAccountStatusSchema,
|
|
1288
|
+
statusReason: import_zod5.z.string().nullable(),
|
|
1289
|
+
toolkit: import_zod5.z.object({
|
|
1290
|
+
slug: import_zod5.z.string()
|
|
1291
|
+
}),
|
|
1292
|
+
testRequestEndpoint: import_zod5.z.string().optional(),
|
|
1293
|
+
isDisabled: import_zod5.z.boolean(),
|
|
1294
|
+
createdAt: import_zod5.z.string(),
|
|
1295
|
+
updatedAt: import_zod5.z.string()
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
// src/models/ConnectionRequest.ts
|
|
1299
|
+
var import_zod6 = require("zod");
|
|
1300
|
+
|
|
1301
|
+
// src/errors/ConnectionRequestError.ts
|
|
1302
|
+
var ConnectionRequestErrorCodes = {
|
|
1303
|
+
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT"
|
|
1304
|
+
};
|
|
1305
|
+
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1306
|
+
constructor(message = "Connection request timed out", meta = {}) {
|
|
1307
|
+
super(message, {
|
|
1308
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
|
|
1309
|
+
meta
|
|
1310
|
+
});
|
|
865
1311
|
}
|
|
866
1312
|
};
|
|
867
1313
|
|
|
868
|
-
// src/models/
|
|
869
|
-
var
|
|
1314
|
+
// src/models/ConnectionRequest.ts
|
|
1315
|
+
var ConnectionRequest = class {
|
|
870
1316
|
client;
|
|
871
|
-
|
|
1317
|
+
connectedAccountId;
|
|
1318
|
+
connectedAccountStatus;
|
|
1319
|
+
redirectUrl;
|
|
1320
|
+
constructor(client, connectedAccountId, connectedAccountStatus, redirectUrl) {
|
|
872
1321
|
this.client = client;
|
|
1322
|
+
this.connectedAccountId = connectedAccountId;
|
|
1323
|
+
this.connectedAccountStatus = connectedAccountStatus;
|
|
1324
|
+
this.redirectUrl = redirectUrl;
|
|
873
1325
|
}
|
|
874
1326
|
/**
|
|
875
|
-
*
|
|
876
|
-
* @
|
|
1327
|
+
* Transform the response from the Composio API to the SDK format
|
|
1328
|
+
* @param response
|
|
1329
|
+
* @returns
|
|
877
1330
|
*/
|
|
878
|
-
async
|
|
879
|
-
|
|
1331
|
+
async transformResponse(response) {
|
|
1332
|
+
try {
|
|
1333
|
+
const parsedResponse = ConnectedAccountRetrieveResponseSchema.parse({
|
|
1334
|
+
...response,
|
|
1335
|
+
userId: response.user_id,
|
|
1336
|
+
// Add the missing userId property
|
|
1337
|
+
authConfig: {
|
|
1338
|
+
...response.auth_config,
|
|
1339
|
+
authScheme: response.auth_config.auth_scheme,
|
|
1340
|
+
isComposioManaged: response.auth_config.is_composio_managed,
|
|
1341
|
+
isDisabled: response.auth_config.is_disabled
|
|
1342
|
+
},
|
|
1343
|
+
statusReason: response.status_reason,
|
|
1344
|
+
isDisabled: response.is_disabled,
|
|
1345
|
+
createdAt: response.created_at,
|
|
1346
|
+
updatedAt: response.updated_at,
|
|
1347
|
+
testRequestEndpoint: response.test_request_endpoint
|
|
1348
|
+
});
|
|
1349
|
+
return parsedResponse;
|
|
1350
|
+
} catch (error) {
|
|
1351
|
+
logger_default.error("Error transforming response", error);
|
|
1352
|
+
if (error instanceof import_zod6.ZodError) {
|
|
1353
|
+
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1354
|
+
}
|
|
1355
|
+
throw error;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
/**
|
|
1359
|
+
* Wait for the connection to be established.
|
|
1360
|
+
* The function will poll the Composio API every second until the connection is established or the timeout is reached.
|
|
1361
|
+
* @param {number} timeout - The time in milliseconds to wait for the connection to be established. Default is 30 seconds.
|
|
1362
|
+
* @returns
|
|
1363
|
+
*/
|
|
1364
|
+
async waitForConnection(timeout = 6e4) {
|
|
1365
|
+
if (this.connectedAccountStatus === ConnectedAccountStatuses.ACTIVE) {
|
|
1366
|
+
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1367
|
+
return Promise.resolve(this.transformResponse(response));
|
|
1368
|
+
}
|
|
1369
|
+
return new Promise((resolve, reject) => {
|
|
1370
|
+
const interval = setInterval(async () => {
|
|
1371
|
+
try {
|
|
1372
|
+
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1373
|
+
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1374
|
+
clearInterval(interval);
|
|
1375
|
+
resolve(this.transformResponse(response));
|
|
1376
|
+
}
|
|
1377
|
+
} catch (error) {
|
|
1378
|
+
clearInterval(interval);
|
|
1379
|
+
reject(error);
|
|
1380
|
+
}
|
|
1381
|
+
}, 1e3);
|
|
1382
|
+
setTimeout(() => {
|
|
1383
|
+
clearInterval(interval);
|
|
1384
|
+
reject(
|
|
1385
|
+
new ConnectionRequestTimeoutError(
|
|
1386
|
+
`Connection request timed out for ${this.connectedAccountId}`
|
|
1387
|
+
)
|
|
1388
|
+
);
|
|
1389
|
+
}, timeout);
|
|
1390
|
+
});
|
|
880
1391
|
}
|
|
881
1392
|
};
|
|
882
1393
|
|
|
883
|
-
// src/models/
|
|
884
|
-
var
|
|
1394
|
+
// src/models/ConnectedAccounts.ts
|
|
1395
|
+
var ConnectedAccounts = class {
|
|
885
1396
|
client;
|
|
886
1397
|
constructor(client) {
|
|
887
1398
|
this.client = client;
|
|
888
1399
|
}
|
|
889
1400
|
/**
|
|
890
|
-
*
|
|
891
|
-
* @
|
|
1401
|
+
* List all connected accounts
|
|
1402
|
+
* @param {ConnectedAccountListParams} query - Query parameters for filtering connected accounts
|
|
1403
|
+
* @param {RequestOptions} options - Request options
|
|
1404
|
+
* @returns {Promise<ConnectedAccountListResponse>} List of connected accounts
|
|
892
1405
|
*/
|
|
893
|
-
async list(query
|
|
894
|
-
return this.client.
|
|
1406
|
+
async list(query) {
|
|
1407
|
+
return this.client.connectedAccounts.list(query);
|
|
895
1408
|
}
|
|
896
1409
|
/**
|
|
897
|
-
*
|
|
1410
|
+
* Compound function to create a new connected account.
|
|
1411
|
+
* This function creates a new connected account and returns a connection request.
|
|
1412
|
+
* Users can then wait for the connection to be established using the `waitForConnection` method.
|
|
1413
|
+
* @param {string} userId - User ID of the connected account
|
|
1414
|
+
* @param {string} authConfigId - Auth config ID of the connected account
|
|
1415
|
+
* @param {CreateConnectedAccountOptions} data - Data for creating a new connected account
|
|
1416
|
+
* @returns {Promise<ConnectionRequest>} Connection request object
|
|
898
1417
|
*
|
|
899
|
-
* @
|
|
900
|
-
*
|
|
901
|
-
*
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* Update an existing trigger instance
|
|
1418
|
+
* @example
|
|
1419
|
+
* const connectionRequest = await composio.createConnectedAccount('user_123', 'auth_config_123', {
|
|
1420
|
+
* data: {
|
|
1421
|
+
* name: 'My Connected Account',
|
|
1422
|
+
* },
|
|
1423
|
+
* });
|
|
908
1424
|
*
|
|
909
|
-
* @
|
|
910
|
-
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
911
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1425
|
+
* @link https://docs.composio.dev/reference/connected-accounts/create-connected-account
|
|
912
1426
|
*/
|
|
913
|
-
async
|
|
914
|
-
|
|
1427
|
+
async initiate(userId, authConfigId, options) {
|
|
1428
|
+
const response = await this.client.connectedAccounts.create({
|
|
1429
|
+
auth_config: {
|
|
1430
|
+
id: authConfigId
|
|
1431
|
+
},
|
|
1432
|
+
connection: {
|
|
1433
|
+
data: options?.data,
|
|
1434
|
+
redirect_uri: options?.redirectUrl,
|
|
1435
|
+
user_id: userId
|
|
1436
|
+
}
|
|
1437
|
+
});
|
|
1438
|
+
return new ConnectionRequest(this.client, response.id, response.status, response.redirect_uri);
|
|
915
1439
|
}
|
|
916
1440
|
/**
|
|
917
|
-
*
|
|
918
|
-
*
|
|
919
|
-
* @param {
|
|
920
|
-
* @returns
|
|
1441
|
+
* Get a connected account by nanoid
|
|
1442
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1443
|
+
* @param {RequestOptions} options - Request options
|
|
1444
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} Connected account details
|
|
921
1445
|
*/
|
|
922
|
-
async
|
|
923
|
-
return this.client.
|
|
1446
|
+
async get(nanoid) {
|
|
1447
|
+
return this.client.connectedAccounts.retrieve(nanoid);
|
|
924
1448
|
}
|
|
925
1449
|
/**
|
|
926
|
-
*
|
|
927
|
-
*
|
|
928
|
-
* @param {TriggerStatusEnum} status - The new status of the trigger
|
|
929
|
-
* @param {TriggerInstanceUpdateStatusParams} params - The parameters to update the trigger instance
|
|
1450
|
+
* Delete a connected account
|
|
1451
|
+
* @param {string} nanoid - Unique identifier of the connected account to delete
|
|
930
1452
|
* @param {RequestOptions} options - Request options
|
|
931
|
-
* @returns {Promise<
|
|
932
|
-
*/
|
|
933
|
-
async updateStatus(status, params, options) {
|
|
934
|
-
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
935
|
-
}
|
|
936
|
-
/**
|
|
937
|
-
* Disable a trigger instance
|
|
938
|
-
*
|
|
939
|
-
* @param {string} slug - The slug of the trigger instance
|
|
940
|
-
* @param {RequestOptions options - Request options
|
|
941
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1453
|
+
* @returns {Promise<ConnectedAccountDeleteResponse>} Response from deletion
|
|
942
1454
|
*/
|
|
943
|
-
async
|
|
944
|
-
return this.client.
|
|
1455
|
+
async delete(nanoid) {
|
|
1456
|
+
return this.client.connectedAccounts.delete(nanoid);
|
|
945
1457
|
}
|
|
946
1458
|
/**
|
|
947
|
-
*
|
|
948
|
-
*
|
|
949
|
-
* @param {
|
|
950
|
-
* @
|
|
951
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1459
|
+
* Refresh a connected account's credentials
|
|
1460
|
+
* @param {string} nanoid - Unique identifier of the connected account to refresh
|
|
1461
|
+
* @param {RequestOptions} options - Request options
|
|
1462
|
+
* @returns {Promise<ConnectedAccountRefreshResponse>} Refreshed connected account details
|
|
952
1463
|
*/
|
|
953
|
-
async
|
|
954
|
-
return this.client.
|
|
1464
|
+
async refresh(nanoid) {
|
|
1465
|
+
return this.client.connectedAccounts.refresh(nanoid);
|
|
955
1466
|
}
|
|
956
1467
|
/**
|
|
957
|
-
*
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
* List all the trigger types
|
|
961
|
-
*
|
|
962
|
-
* @param {TriggersTypeListParams} query - The query parameters to filter the trigger types
|
|
1468
|
+
* Update the status of a connected account
|
|
1469
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1470
|
+
* @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status
|
|
963
1471
|
* @param {RequestOptions} options - Request options
|
|
964
|
-
* @returns {Promise<
|
|
1472
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
965
1473
|
*/
|
|
966
|
-
async
|
|
967
|
-
return this.client.
|
|
1474
|
+
async updateStatus(nanoid, params) {
|
|
1475
|
+
return this.client.connectedAccounts.updateStatus(nanoid, params);
|
|
968
1476
|
}
|
|
969
1477
|
/**
|
|
970
|
-
*
|
|
971
|
-
*
|
|
972
|
-
* @param {
|
|
973
|
-
* @
|
|
974
|
-
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
1478
|
+
* Enable a connected account
|
|
1479
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1480
|
+
* @param {RequestOptions} options - Request options
|
|
1481
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
975
1482
|
*/
|
|
976
|
-
async
|
|
977
|
-
return this.client.
|
|
1483
|
+
async enable(nanoid) {
|
|
1484
|
+
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true });
|
|
978
1485
|
}
|
|
979
1486
|
/**
|
|
980
|
-
*
|
|
981
|
-
*
|
|
982
|
-
*
|
|
983
|
-
* @
|
|
984
|
-
* @returns
|
|
1487
|
+
* Disable a connected account
|
|
1488
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1489
|
+
* @param {RequestOptions} options - Request options
|
|
1490
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
985
1491
|
*/
|
|
986
|
-
async
|
|
987
|
-
return this.client.
|
|
988
|
-
}
|
|
989
|
-
async subscribe(fn, filters = {}) {
|
|
990
|
-
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
991
|
-
const session = new Session(this.client);
|
|
992
|
-
const sessionInfo = await session.getInfo();
|
|
993
|
-
const clientId = sessionInfo.project?.id;
|
|
994
|
-
if (!clientId) throw new Error("Client ID not found");
|
|
995
|
-
await PusherUtils.getPusherClient(this.client.baseURL, this.client.apiKey);
|
|
996
|
-
const shouldSendTrigger = (data) => {
|
|
997
|
-
if (Object.keys(filters).length === 0) return true;
|
|
998
|
-
else {
|
|
999
|
-
return (!filters.appName || data.appName.toLowerCase() === filters.appName.toLowerCase()) && (!filters.triggerId || data.metadata.id.toLowerCase() === filters.triggerId.toLowerCase()) && (!filters.connectionId || data.metadata.connectionId.toLowerCase() === filters.connectionId.toLowerCase()) && (!filters.triggerName || data.metadata.triggerName.toLowerCase() === filters.triggerName.toLowerCase()) && (!filters.entityId || data.metadata.connection.clientUniqueUserId.toLowerCase() === filters.entityId.toLowerCase()) && (!filters.integrationId || data.metadata.connection.integrationId.toLowerCase() === filters.integrationId.toLowerCase());
|
|
1000
|
-
}
|
|
1001
|
-
};
|
|
1002
|
-
logger_default.debug("Subscribing to triggers", filters);
|
|
1003
|
-
PusherUtils.triggerSubscribe(clientId, (data) => {
|
|
1004
|
-
if (shouldSendTrigger(data)) {
|
|
1005
|
-
fn(data);
|
|
1006
|
-
}
|
|
1007
|
-
});
|
|
1008
|
-
}
|
|
1009
|
-
async unsubscribe() {
|
|
1010
|
-
const session = new Session(this.client);
|
|
1011
|
-
const sessionInfo = await session.getInfo();
|
|
1012
|
-
const clientId = sessionInfo.project?.id;
|
|
1013
|
-
if (!clientId) throw new Error("Client ID not found");
|
|
1014
|
-
PusherUtils.triggerUnsubscribe(clientId);
|
|
1492
|
+
async disable(nanoid) {
|
|
1493
|
+
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
|
|
1015
1494
|
}
|
|
1016
1495
|
};
|
|
1017
1496
|
|
|
1018
|
-
// src/
|
|
1019
|
-
var
|
|
1020
|
-
var AuthConfigTypes = {
|
|
1021
|
-
CUSTOM: "use_custom_auth",
|
|
1022
|
-
COMPOSIO_MANAGED: "use_composio_managed_auth"
|
|
1023
|
-
};
|
|
1024
|
-
var AuthSchemeTypes = {
|
|
1025
|
-
OAUTH2: "OAUTH2",
|
|
1026
|
-
OAUTH1: "OAUTH1",
|
|
1027
|
-
OAUTH1A: "OAUTH1A",
|
|
1028
|
-
API_KEY: "API_KEY",
|
|
1029
|
-
BASIC: "BASIC",
|
|
1030
|
-
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
1031
|
-
BEARER_TOKEN: "BEARER_TOKEN",
|
|
1032
|
-
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
1033
|
-
NO_AUTH: "NO_AUTH",
|
|
1034
|
-
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
1035
|
-
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
1036
|
-
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1037
|
-
SNOWFLAKE: "SNOWFLAKE"
|
|
1038
|
-
};
|
|
1039
|
-
var AuthSchemeEnum = import_zod3.z.enum([
|
|
1040
|
-
"OAUTH2",
|
|
1041
|
-
"OAUTH1",
|
|
1042
|
-
"OAUTH1A",
|
|
1043
|
-
"API_KEY",
|
|
1044
|
-
"BASIC",
|
|
1045
|
-
"BILLCOM_AUTH",
|
|
1046
|
-
"BEARER_TOKEN",
|
|
1047
|
-
"GOOGLE_SERVICE_ACCOUNT",
|
|
1048
|
-
"NO_AUTH",
|
|
1049
|
-
"BASIC_WITH_JWT",
|
|
1050
|
-
"COMPOSIO_LINK",
|
|
1051
|
-
"CALCOM_AUTH",
|
|
1052
|
-
"SNOWFLAKE"
|
|
1053
|
-
]);
|
|
1054
|
-
var CreateCustomAuthConfigParamsSchema = import_zod3.z.object({
|
|
1055
|
-
type: import_zod3.z.literal("use_custom_auth"),
|
|
1056
|
-
name: import_zod3.z.string().optional(),
|
|
1057
|
-
credentials: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean()])),
|
|
1058
|
-
authScheme: AuthSchemeEnum
|
|
1059
|
-
});
|
|
1060
|
-
var CreateComposioManagedAuthConfigParamsSchema = import_zod3.z.object({
|
|
1061
|
-
type: import_zod3.z.literal("use_composio_managed_auth"),
|
|
1062
|
-
name: import_zod3.z.string().optional(),
|
|
1063
|
-
credentials: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean()])).optional()
|
|
1064
|
-
});
|
|
1065
|
-
var CreateAuthConfigParamsSchema = import_zod3.z.discriminatedUnion("type", [
|
|
1066
|
-
CreateCustomAuthConfigParamsSchema,
|
|
1067
|
-
CreateComposioManagedAuthConfigParamsSchema
|
|
1068
|
-
]);
|
|
1069
|
-
var CreateAuthConfigResponseSchema = import_zod3.z.object({
|
|
1070
|
-
id: import_zod3.z.string(),
|
|
1071
|
-
authScheme: import_zod3.z.string(),
|
|
1072
|
-
isComposioManaged: import_zod3.z.boolean(),
|
|
1073
|
-
toolkit: import_zod3.z.string()
|
|
1074
|
-
});
|
|
1075
|
-
var AuthConfigRetrieveResponseSchema = import_zod3.z.object({
|
|
1076
|
-
id: import_zod3.z.string(),
|
|
1077
|
-
name: import_zod3.z.string(),
|
|
1078
|
-
toolkit: import_zod3.z.object({
|
|
1079
|
-
logo: import_zod3.z.string(),
|
|
1080
|
-
slug: import_zod3.z.string()
|
|
1081
|
-
}),
|
|
1082
|
-
noOfConnections: import_zod3.z.number(),
|
|
1083
|
-
status: import_zod3.z.enum(["ENABLED", "DISABLED"]),
|
|
1084
|
-
uuid: import_zod3.z.string(),
|
|
1085
|
-
authScheme: AuthSchemeEnum.optional(),
|
|
1086
|
-
credentials: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean()])),
|
|
1087
|
-
expectedInputFields: import_zod3.z.array(import_zod3.z.unknown()).optional(),
|
|
1088
|
-
isComposioManaged: import_zod3.z.boolean().optional(),
|
|
1089
|
-
createdBy: import_zod3.z.string().optional(),
|
|
1090
|
-
createdAt: import_zod3.z.string().optional(),
|
|
1091
|
-
lastUpdatedAt: import_zod3.z.string().optional()
|
|
1092
|
-
});
|
|
1093
|
-
var AuthConfigListParamsSchema = import_zod3.z.object({
|
|
1094
|
-
cursor: import_zod3.z.string().optional(),
|
|
1095
|
-
isComposioManaged: import_zod3.z.boolean().optional(),
|
|
1096
|
-
limit: import_zod3.z.number().optional(),
|
|
1097
|
-
toolkitSlug: import_zod3.z.string().optional()
|
|
1098
|
-
});
|
|
1099
|
-
var AuthConfigListResponseSchema = import_zod3.z.object({
|
|
1100
|
-
items: import_zod3.z.array(AuthConfigRetrieveResponseSchema),
|
|
1101
|
-
nextCursor: import_zod3.z.string().optional(),
|
|
1102
|
-
totalPages: import_zod3.z.number()
|
|
1103
|
-
});
|
|
1104
|
-
var AuthConfigUpdateParamsSchema = import_zod3.z.object({
|
|
1105
|
-
credentials: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean()]))
|
|
1106
|
-
});
|
|
1107
|
-
|
|
1108
|
-
// src/models/AuthConfigs.ts
|
|
1109
|
-
var AuthConfigs = class {
|
|
1497
|
+
// src/models/Toolkits.ts
|
|
1498
|
+
var Toolkits = class {
|
|
1110
1499
|
client;
|
|
1111
1500
|
constructor(client) {
|
|
1112
1501
|
this.client = client;
|
|
1113
|
-
|
|
1114
|
-
parseAuthConfigRetrieveResponse(authConfig) {
|
|
1115
|
-
return AuthConfigRetrieveResponseSchema.parse({
|
|
1116
|
-
id: authConfig.id,
|
|
1117
|
-
name: authConfig.name,
|
|
1118
|
-
noOfConnections: authConfig.no_of_connections,
|
|
1119
|
-
status: authConfig.status,
|
|
1120
|
-
toolkit: {
|
|
1121
|
-
logo: authConfig.toolkit.logo,
|
|
1122
|
-
slug: authConfig.toolkit.slug
|
|
1123
|
-
},
|
|
1124
|
-
uuid: authConfig.uuid,
|
|
1125
|
-
authScheme: authConfig.auth_scheme,
|
|
1126
|
-
credentials: authConfig.credentials,
|
|
1127
|
-
expectedInputFields: authConfig.expected_input_fields,
|
|
1128
|
-
isComposioManaged: authConfig.is_composio_managed,
|
|
1129
|
-
createdBy: authConfig.created_by,
|
|
1130
|
-
createdAt: authConfig.created_at,
|
|
1131
|
-
lastUpdatedAt: authConfig.last_updated_at
|
|
1132
|
-
});
|
|
1502
|
+
this.authorize = this.authorize.bind(this);
|
|
1133
1503
|
}
|
|
1134
1504
|
/**
|
|
1135
|
-
* List all
|
|
1136
|
-
*
|
|
1137
|
-
* @
|
|
1138
|
-
* @returns {Promise<AuthConfigListResponse>} List of auth configs
|
|
1505
|
+
* List all toolkits available in the Composio SDK.
|
|
1506
|
+
* This method fetches the toolkits from the Composio API.
|
|
1507
|
+
* @returns {Promise<Toolkit[]>} List of toolkits
|
|
1139
1508
|
*/
|
|
1140
|
-
async
|
|
1141
|
-
const parsedQuery =
|
|
1142
|
-
const result = await this.client.
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1509
|
+
async getToolkits(query) {
|
|
1510
|
+
const parsedQuery = ToolkitsListParamsSchema.parse(query);
|
|
1511
|
+
const result = await this.client.toolkits.list({
|
|
1512
|
+
category: parsedQuery.category,
|
|
1513
|
+
is_local: parsedQuery.isLocal,
|
|
1514
|
+
managed_by: parsedQuery.managedBy,
|
|
1515
|
+
sort_by: parsedQuery.sortBy
|
|
1147
1516
|
});
|
|
1148
|
-
|
|
1149
|
-
items: result.items.map((item) =>
|
|
1517
|
+
const parsedResult = ToolKitListResponseSchema.parse({
|
|
1518
|
+
items: result.items.map((item) => {
|
|
1519
|
+
const parsedItem = ToolKitItemSchema.parse({
|
|
1520
|
+
name: item.name,
|
|
1521
|
+
slug: item.slug,
|
|
1522
|
+
meta: item.meta,
|
|
1523
|
+
isLocalToolkit: item.is_local_toolkit,
|
|
1524
|
+
authSchemes: item.auth_schemes,
|
|
1525
|
+
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
1526
|
+
noAuth: item.no_auth
|
|
1527
|
+
});
|
|
1528
|
+
return parsedItem;
|
|
1529
|
+
}),
|
|
1150
1530
|
nextCursor: result.next_cursor,
|
|
1151
1531
|
totalPages: result.total_pages
|
|
1152
1532
|
});
|
|
1533
|
+
return parsedResult;
|
|
1153
1534
|
}
|
|
1154
1535
|
/**
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1157
|
-
* @param
|
|
1158
|
-
* @
|
|
1159
|
-
*
|
|
1160
|
-
* @example
|
|
1161
|
-
* const authConfig = await authConfigs.create('my-toolkit', {
|
|
1162
|
-
* type: AuthConfigTypes.CUSTOM,
|
|
1163
|
-
* name: 'My Custom Auth Config',
|
|
1164
|
-
* authScheme: AuthSchemeTypes.API_KEY,
|
|
1165
|
-
* credentials: {
|
|
1166
|
-
* apiKey: '1234567890',
|
|
1167
|
-
* },
|
|
1168
|
-
* });
|
|
1169
|
-
*
|
|
1170
|
-
* @link https://docs.composio.dev/reference/auth-configs/create-auth-config
|
|
1536
|
+
* Fetches a toolkit by its Slug.
|
|
1537
|
+
* This method retrieves the toolkit from the Composio API.
|
|
1538
|
+
* @param slug - The ID of the toolkit to be retrieved
|
|
1539
|
+
* @param options - Request options
|
|
1540
|
+
* @returns {Promise<ToolkitRetrieveResponse>} The toolkit object
|
|
1171
1541
|
*/
|
|
1172
|
-
async
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1542
|
+
async getToolkitBySlug(slug) {
|
|
1543
|
+
try {
|
|
1544
|
+
const result = await this.client.toolkits.retrieve(slug);
|
|
1545
|
+
const parsedResult = ToolkitRetrieveResponseSchema.parse({
|
|
1546
|
+
name: result.name,
|
|
1547
|
+
slug: result.slug,
|
|
1548
|
+
meta: {
|
|
1549
|
+
...result.meta,
|
|
1550
|
+
createdAt: result.meta.created_at,
|
|
1551
|
+
updatedAt: result.meta.updated_at,
|
|
1552
|
+
toolsCount: result.meta.tools_count,
|
|
1553
|
+
triggersCount: result.meta.triggers_count
|
|
1554
|
+
// appUrl: result.meta.app_url, @TODO Update the client type to include this
|
|
1555
|
+
},
|
|
1556
|
+
isLocalToolkit: result.is_local_toolkit,
|
|
1557
|
+
composioManagedAuthSchemes: result.composio_managed_auth_schemes,
|
|
1558
|
+
authConfigDetails: result.auth_config_details?.map((authConfig) => ({
|
|
1559
|
+
name: authConfig.name,
|
|
1560
|
+
mode: authConfig.mode,
|
|
1561
|
+
fields: {
|
|
1562
|
+
authConfigCreation: authConfig.fields.auth_config_creation,
|
|
1563
|
+
connectedAccountInitiation: authConfig.fields.connected_account_initiation
|
|
1564
|
+
},
|
|
1565
|
+
proxy: {
|
|
1566
|
+
baseUrl: authConfig.proxy?.base_url
|
|
1567
|
+
}
|
|
1568
|
+
}))
|
|
1569
|
+
});
|
|
1570
|
+
return parsedResult;
|
|
1571
|
+
} catch (error) {
|
|
1572
|
+
if (error instanceof import_zod7.ZodError) {
|
|
1573
|
+
throw new ValidationError(error);
|
|
1574
|
+
}
|
|
1575
|
+
throw new ComposioToolNotFoundError(`Toolkit with slug ${slug} not found`, {
|
|
1576
|
+
slug
|
|
1577
|
+
});
|
|
1578
|
+
}
|
|
1186
1579
|
}
|
|
1187
1580
|
/**
|
|
1188
|
-
*
|
|
1189
|
-
*
|
|
1190
|
-
* @param
|
|
1191
|
-
* @returns {Promise<
|
|
1581
|
+
* Fetches a toolkit by its Slug or a list of toolkits.
|
|
1582
|
+
* This method retrieves the toolkit from the Composio API.
|
|
1583
|
+
* @param arg - The ID of the toolkit to be retrieved or a list of parameters
|
|
1584
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit object or a list of toolkits
|
|
1192
1585
|
*/
|
|
1193
|
-
async get(
|
|
1194
|
-
|
|
1195
|
-
|
|
1586
|
+
async get(arg) {
|
|
1587
|
+
if (typeof arg === "string") {
|
|
1588
|
+
return this.getToolkitBySlug(arg);
|
|
1589
|
+
}
|
|
1590
|
+
return this.getToolkits(arg);
|
|
1196
1591
|
}
|
|
1197
1592
|
/**
|
|
1198
|
-
*
|
|
1199
|
-
*
|
|
1200
|
-
* @
|
|
1201
|
-
* @param {RequestOptions} options - Request options
|
|
1202
|
-
* @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
|
|
1593
|
+
* Fetches all categories available in the Composio SDK
|
|
1594
|
+
*
|
|
1595
|
+
* @returns {Promise<ToolkitRetrieveCategoriesResponse>} List of categories
|
|
1203
1596
|
*/
|
|
1204
|
-
async
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1597
|
+
async listCategories() {
|
|
1598
|
+
const result = await this.client.toolkits.retrieveCategories();
|
|
1599
|
+
const parsedResult = ToolkitRetrieveCategoriesResponseSchema.parse({
|
|
1600
|
+
items: result.items.map((item) => {
|
|
1601
|
+
const parsedItem = ToolkitCategorySchema.parse({
|
|
1602
|
+
id: item.id,
|
|
1603
|
+
name: item.name
|
|
1604
|
+
});
|
|
1605
|
+
return parsedItem;
|
|
1606
|
+
}),
|
|
1607
|
+
nextCursor: result.next_cursor,
|
|
1608
|
+
totalPages: result.total_pages
|
|
1209
1609
|
});
|
|
1610
|
+
return parsedResult;
|
|
1210
1611
|
}
|
|
1211
1612
|
/**
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
* @param {
|
|
1215
|
-
* @
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1613
|
+
* Authorizes a user to use a toolkit.
|
|
1614
|
+
* This method will create an auth config if one doesn't exist and initiate a connection request.
|
|
1615
|
+
* @param {string} userId - The user id of the user to authorize
|
|
1616
|
+
* @param {string} toolkitSlug - The slug of the toolkit to authorize
|
|
1617
|
+
* @param {string} authConfigId - The id of the auth config to use
|
|
1618
|
+
* @returns {Promise<ConnectionRequest>} The connection request object
|
|
1619
|
+
*/
|
|
1620
|
+
async authorize(userId, toolkitSlug, authConfigId) {
|
|
1621
|
+
const toolkit = await this.getToolkitBySlug(toolkitSlug);
|
|
1622
|
+
const composioAuthConfig = new AuthConfigs(this.client);
|
|
1623
|
+
let authConfigIdToUse;
|
|
1624
|
+
if (authConfigId) {
|
|
1625
|
+
const authConfig = await composioAuthConfig.get(authConfigId);
|
|
1626
|
+
authConfigIdToUse = authConfig.id;
|
|
1627
|
+
} else {
|
|
1628
|
+
if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
|
|
1629
|
+
const authConfig = await composioAuthConfig.create(toolkitSlug, {
|
|
1630
|
+
type: "use_composio_managed_auth",
|
|
1631
|
+
name: `${toolkit.name} Auth Config`
|
|
1632
|
+
});
|
|
1633
|
+
authConfigIdToUse = authConfig.id;
|
|
1634
|
+
} else {
|
|
1635
|
+
throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
|
|
1636
|
+
toolkitSlug
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
const composioConnectedAccount = new ConnectedAccounts(this.client);
|
|
1641
|
+
return await composioConnectedAccount.initiate(userId, authConfigIdToUse);
|
|
1642
|
+
}
|
|
1643
|
+
};
|
|
1644
|
+
|
|
1645
|
+
// src/utils/pusher.ts
|
|
1646
|
+
var PUSHER_KEY = process.env.CLIENT_PUSHER_KEY || "ff9f18c208855d77a152";
|
|
1647
|
+
var PUSHER_CLUSTER = "mt1";
|
|
1648
|
+
var PusherUtils = class _PusherUtils {
|
|
1649
|
+
static pusherClient;
|
|
1650
|
+
static getPusherClient(baseURL, apiKey) {
|
|
1651
|
+
if (!_PusherUtils.pusherClient) {
|
|
1652
|
+
const PusherClient = require("pusher-js");
|
|
1653
|
+
_PusherUtils.pusherClient = new PusherClient(PUSHER_KEY, {
|
|
1654
|
+
cluster: PUSHER_CLUSTER,
|
|
1655
|
+
channelAuthorization: {
|
|
1656
|
+
endpoint: `${baseURL}/api/v1/client/auth/pusher_auth`,
|
|
1657
|
+
headers: {
|
|
1658
|
+
"x-api-key": apiKey
|
|
1659
|
+
},
|
|
1660
|
+
transport: "ajax"
|
|
1661
|
+
}
|
|
1662
|
+
});
|
|
1663
|
+
}
|
|
1664
|
+
return _PusherUtils.pusherClient;
|
|
1219
1665
|
}
|
|
1220
1666
|
/**
|
|
1221
|
-
*
|
|
1222
|
-
* @param {string}
|
|
1223
|
-
* @param {string}
|
|
1224
|
-
* @param {
|
|
1225
|
-
* @returns {
|
|
1667
|
+
* Subscribes to a Pusher channel and binds an event to a callback function.
|
|
1668
|
+
* @param {string} channelName - The name of the channel to subscribe to.
|
|
1669
|
+
* @param {string} event - The event to bind to the channel.
|
|
1670
|
+
* @param {(data: Record<string, unknown>) => void} fn - The callback function to execute when the event is triggered.
|
|
1671
|
+
* @returns {PusherClient} The Pusher client instance.
|
|
1226
1672
|
*/
|
|
1227
|
-
async
|
|
1228
|
-
|
|
1673
|
+
static async subscribe(channelName, event, fn) {
|
|
1674
|
+
try {
|
|
1675
|
+
await _PusherUtils.pusherClient.subscribe(channelName).bind(event, fn);
|
|
1676
|
+
} catch (error) {
|
|
1677
|
+
logger_default.error(
|
|
1678
|
+
`Error subscribing to ${channelName} with event ${event}: ${error}`
|
|
1679
|
+
);
|
|
1680
|
+
}
|
|
1229
1681
|
}
|
|
1230
1682
|
/**
|
|
1231
|
-
*
|
|
1232
|
-
* @param {string}
|
|
1233
|
-
* @
|
|
1234
|
-
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
1683
|
+
* Unsubscribes from a Pusher channel.
|
|
1684
|
+
* @param {string} channelName - The name of the channel to unsubscribe from.
|
|
1685
|
+
* @returns {void}
|
|
1235
1686
|
*/
|
|
1236
|
-
async
|
|
1237
|
-
|
|
1687
|
+
static async unsubscribe(channelName) {
|
|
1688
|
+
_PusherUtils.pusherClient.unsubscribe(channelName);
|
|
1238
1689
|
}
|
|
1239
1690
|
/**
|
|
1240
|
-
*
|
|
1241
|
-
* @param {
|
|
1242
|
-
* @param {
|
|
1243
|
-
* @
|
|
1691
|
+
* Binds an event to a channel with support for chunked messages.
|
|
1692
|
+
* @param {PusherClient} channel - The Pusher channel to bind the event to.
|
|
1693
|
+
* @param {string} event - The event to bind to the channel.
|
|
1694
|
+
* @param {(data: unknown) => void} callback - The callback function to execute when the event is triggered.
|
|
1244
1695
|
*/
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
ConnectedAccountStatuses.ACTIVE,
|
|
1262
|
-
ConnectedAccountStatuses.INACTIVE,
|
|
1263
|
-
ConnectedAccountStatuses.PENDING,
|
|
1264
|
-
ConnectedAccountStatuses.INITIATED,
|
|
1265
|
-
ConnectedAccountStatuses.EXPIRED,
|
|
1266
|
-
ConnectedAccountStatuses.FAILED
|
|
1267
|
-
]);
|
|
1268
|
-
var CreateConnectedAccountParamsSchema = import_zod4.z.object({
|
|
1269
|
-
authConfig: import_zod4.z.object({
|
|
1270
|
-
id: import_zod4.z.string()
|
|
1271
|
-
}),
|
|
1272
|
-
connection: import_zod4.z.object({
|
|
1273
|
-
data: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()).optional(),
|
|
1274
|
-
redirectUrl: import_zod4.z.string().optional(),
|
|
1275
|
-
userId: import_zod4.z.string().optional()
|
|
1276
|
-
})
|
|
1277
|
-
});
|
|
1278
|
-
var DefaultCreateConnectedAccountParamsSchema = import_zod4.z.object({
|
|
1279
|
-
auth_config: import_zod4.z.object({
|
|
1280
|
-
id: import_zod4.z.string()
|
|
1281
|
-
}),
|
|
1282
|
-
connection: import_zod4.z.object({
|
|
1283
|
-
data: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()).optional(),
|
|
1284
|
-
redirect_uri: import_zod4.z.string().optional(),
|
|
1285
|
-
user_id: import_zod4.z.string().optional()
|
|
1286
|
-
})
|
|
1287
|
-
});
|
|
1288
|
-
var CreateConnectedAccountOptionsSchema = import_zod4.z.object({
|
|
1289
|
-
redirectUrl: import_zod4.z.string().optional(),
|
|
1290
|
-
data: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()).optional()
|
|
1291
|
-
});
|
|
1292
|
-
var CreateConnectedAccountResponseSchema = import_zod4.z.object({
|
|
1293
|
-
id: import_zod4.z.string(),
|
|
1294
|
-
status: ConnectedAccountStatusSchema,
|
|
1295
|
-
redirectUrl: import_zod4.z.string().nullable()
|
|
1296
|
-
});
|
|
1297
|
-
var ConnectedAccountAuthSchemes = {
|
|
1298
|
-
OAUTH2: "OAUTH2",
|
|
1299
|
-
OAUTH1: "OAUTH1",
|
|
1300
|
-
OAUTH1A: "OAUTH1A",
|
|
1301
|
-
API_KEY: "API_KEY",
|
|
1302
|
-
BASIC: "BASIC",
|
|
1303
|
-
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
1304
|
-
BEARER_TOKEN: "BEARER_TOKEN",
|
|
1305
|
-
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
1306
|
-
NO_AUTH: "NO_AUTH",
|
|
1307
|
-
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
1308
|
-
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
1309
|
-
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1310
|
-
SNOWFLAKE: "SNOWFLAKE"
|
|
1311
|
-
};
|
|
1312
|
-
var ConnectedAccountAuthSchemesSchema = import_zod4.z.enum([
|
|
1313
|
-
ConnectedAccountAuthSchemes.OAUTH2,
|
|
1314
|
-
ConnectedAccountAuthSchemes.OAUTH1,
|
|
1315
|
-
ConnectedAccountAuthSchemes.OAUTH1A,
|
|
1316
|
-
ConnectedAccountAuthSchemes.API_KEY,
|
|
1317
|
-
ConnectedAccountAuthSchemes.BASIC,
|
|
1318
|
-
ConnectedAccountAuthSchemes.BILLCOM_AUTH,
|
|
1319
|
-
ConnectedAccountAuthSchemes.BEARER_TOKEN,
|
|
1320
|
-
ConnectedAccountAuthSchemes.GOOGLE_SERVICE_ACCOUNT,
|
|
1321
|
-
ConnectedAccountAuthSchemes.NO_AUTH,
|
|
1322
|
-
ConnectedAccountAuthSchemes.BASIC_WITH_JWT,
|
|
1323
|
-
ConnectedAccountAuthSchemes.COMPOSIO_LINK,
|
|
1324
|
-
ConnectedAccountAuthSchemes.CALCOM_AUTH,
|
|
1325
|
-
ConnectedAccountAuthSchemes.SNOWFLAKE
|
|
1326
|
-
]);
|
|
1327
|
-
var ConnectedAccountAuthConfigSchema = import_zod4.z.object({
|
|
1328
|
-
id: import_zod4.z.string(),
|
|
1329
|
-
authScheme: ConnectedAccountAuthSchemesSchema,
|
|
1330
|
-
isComposioManaged: import_zod4.z.boolean(),
|
|
1331
|
-
isDisabled: import_zod4.z.boolean()
|
|
1332
|
-
});
|
|
1333
|
-
var ConnectedAccountRetrieveResponseSchema = import_zod4.z.object({
|
|
1334
|
-
id: import_zod4.z.string(),
|
|
1335
|
-
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1336
|
-
userId: import_zod4.z.string(),
|
|
1337
|
-
data: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()),
|
|
1338
|
-
params: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()),
|
|
1339
|
-
status: ConnectedAccountStatusSchema,
|
|
1340
|
-
statusReason: import_zod4.z.string().nullable(),
|
|
1341
|
-
toolkit: import_zod4.z.object({
|
|
1342
|
-
slug: import_zod4.z.string()
|
|
1343
|
-
}),
|
|
1344
|
-
testRequestEndpoint: import_zod4.z.string().optional(),
|
|
1345
|
-
isDisabled: import_zod4.z.boolean(),
|
|
1346
|
-
createdAt: import_zod4.z.string(),
|
|
1347
|
-
updatedAt: import_zod4.z.string()
|
|
1348
|
-
});
|
|
1349
|
-
|
|
1350
|
-
// src/models/ConnectionRequest.ts
|
|
1351
|
-
var import_zod5 = require("zod");
|
|
1352
|
-
var ConnectionRequest = class {
|
|
1353
|
-
client;
|
|
1354
|
-
connectedAccountId;
|
|
1355
|
-
connectedAccountStatus;
|
|
1356
|
-
constructor(client, connectedAccountId, connectedAccountStatus) {
|
|
1357
|
-
this.client = client;
|
|
1358
|
-
this.connectedAccountId = connectedAccountId;
|
|
1359
|
-
this.connectedAccountStatus = connectedAccountStatus;
|
|
1696
|
+
static bindWithChunking(channel, event, callback) {
|
|
1697
|
+
channel.bind(event, callback);
|
|
1698
|
+
const events = {};
|
|
1699
|
+
channel.bind("chunked-" + event, (data) => {
|
|
1700
|
+
const typedData = data;
|
|
1701
|
+
if (!events.hasOwnProperty(typedData.id)) {
|
|
1702
|
+
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
1703
|
+
}
|
|
1704
|
+
const ev = events[typedData.id];
|
|
1705
|
+
ev.chunks[typedData.index] = typedData.chunk;
|
|
1706
|
+
if (typedData.final) ev.receivedFinal = true;
|
|
1707
|
+
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
1708
|
+
callback(JSON.parse(ev.chunks.join("")));
|
|
1709
|
+
delete events[typedData.id];
|
|
1710
|
+
}
|
|
1711
|
+
});
|
|
1360
1712
|
}
|
|
1361
1713
|
/**
|
|
1362
|
-
*
|
|
1363
|
-
* @param
|
|
1364
|
-
* @
|
|
1714
|
+
* Subscribes to a trigger channel for a client and handles chunked data.
|
|
1715
|
+
* @param {string} clientId - The unique identifier for the client subscribing to the events.
|
|
1716
|
+
* @param {(data: TriggerData) => void} fn - The callback function to execute when trigger data is received.
|
|
1365
1717
|
*/
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
}
|
|
1390
|
-
throw error;
|
|
1391
|
-
}
|
|
1718
|
+
static triggerSubscribe(clientId, fn) {
|
|
1719
|
+
const channel = _PusherUtils.pusherClient.subscribe(
|
|
1720
|
+
`private-${clientId}_triggers`
|
|
1721
|
+
);
|
|
1722
|
+
_PusherUtils.bindWithChunking(
|
|
1723
|
+
channel,
|
|
1724
|
+
"trigger_to_client",
|
|
1725
|
+
fn
|
|
1726
|
+
);
|
|
1727
|
+
logger_default.info(
|
|
1728
|
+
`Subscribed to triggers. You should start receiving events now.`
|
|
1729
|
+
);
|
|
1730
|
+
}
|
|
1731
|
+
static triggerUnsubscribe(clientId) {
|
|
1732
|
+
_PusherUtils.pusherClient.unsubscribe(`${clientId}_triggers`);
|
|
1733
|
+
}
|
|
1734
|
+
};
|
|
1735
|
+
|
|
1736
|
+
// src/models/Session.ts
|
|
1737
|
+
var Session = class {
|
|
1738
|
+
client;
|
|
1739
|
+
constructor(client) {
|
|
1740
|
+
this.client = client;
|
|
1392
1741
|
}
|
|
1393
1742
|
/**
|
|
1394
|
-
*
|
|
1395
|
-
*
|
|
1396
|
-
* @param {number} timeout - The time in milliseconds to wait for the connection to be established. Default is 30 seconds.
|
|
1397
|
-
* @returns
|
|
1743
|
+
* Get the active session info
|
|
1744
|
+
* @returns {Promise<SessionGetInfoResponse>} Session info
|
|
1398
1745
|
*/
|
|
1399
|
-
async
|
|
1400
|
-
|
|
1401
|
-
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1402
|
-
return Promise.resolve(this.transformResponse(response));
|
|
1403
|
-
}
|
|
1404
|
-
return new Promise((resolve, reject) => {
|
|
1405
|
-
const interval = setInterval(async () => {
|
|
1406
|
-
try {
|
|
1407
|
-
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1408
|
-
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1409
|
-
clearInterval(interval);
|
|
1410
|
-
resolve(this.transformResponse(response));
|
|
1411
|
-
}
|
|
1412
|
-
} catch (error) {
|
|
1413
|
-
clearInterval(interval);
|
|
1414
|
-
reject(error);
|
|
1415
|
-
}
|
|
1416
|
-
}, 1e3);
|
|
1417
|
-
setTimeout(() => {
|
|
1418
|
-
clearInterval(interval);
|
|
1419
|
-
reject(new Error("Connection request timed out"));
|
|
1420
|
-
}, timeout);
|
|
1421
|
-
});
|
|
1746
|
+
async getInfo() {
|
|
1747
|
+
return this.client.auth.session.getInfo();
|
|
1422
1748
|
}
|
|
1423
1749
|
};
|
|
1424
1750
|
|
|
1425
|
-
// src/models/
|
|
1426
|
-
var
|
|
1751
|
+
// src/models/Triggers.ts
|
|
1752
|
+
var Triggers = class {
|
|
1427
1753
|
client;
|
|
1428
1754
|
constructor(client) {
|
|
1429
1755
|
this.client = client;
|
|
1430
1756
|
}
|
|
1431
1757
|
/**
|
|
1432
|
-
*
|
|
1433
|
-
* @
|
|
1434
|
-
* @param {RequestOptions} options - Request options
|
|
1435
|
-
* @returns {Promise<ConnectedAccountListResponse>} List of connected accounts
|
|
1758
|
+
* Fetch list of all the active triggers
|
|
1759
|
+
* @returns {Promise<TriggerInstance[]>} List of trigger instances
|
|
1436
1760
|
*/
|
|
1437
|
-
async list(query) {
|
|
1438
|
-
return this.client.
|
|
1761
|
+
async list(query, options) {
|
|
1762
|
+
return this.client.triggerInstances.listActive(query, options);
|
|
1439
1763
|
}
|
|
1440
1764
|
/**
|
|
1441
|
-
*
|
|
1442
|
-
* This function creates a new connected account and returns a connection request.
|
|
1443
|
-
* Users can then wait for the connection to be established using the `waitForConnection` method.
|
|
1444
|
-
* @param {string} userId - User ID of the connected account
|
|
1445
|
-
* @param {string} authConfigId - Auth config ID of the connected account
|
|
1446
|
-
* @param {CreateConnectedAccountOptions} data - Data for creating a new connected account
|
|
1447
|
-
* @returns {Promise<ConnectionRequest>} Connection request object
|
|
1765
|
+
* Create a new trigger instance
|
|
1448
1766
|
*
|
|
1449
|
-
* @
|
|
1450
|
-
*
|
|
1451
|
-
*
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1767
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1768
|
+
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
1769
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
1770
|
+
*/
|
|
1771
|
+
async create(slug, body, options) {
|
|
1772
|
+
return this.client.triggerInstances.upsert(slug, body, options);
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* Update an existing trigger instance
|
|
1455
1776
|
*
|
|
1456
|
-
* @
|
|
1777
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1778
|
+
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
1779
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1457
1780
|
*/
|
|
1458
|
-
async
|
|
1459
|
-
|
|
1460
|
-
auth_config: {
|
|
1461
|
-
id: authConfigId
|
|
1462
|
-
},
|
|
1463
|
-
connection: {
|
|
1464
|
-
data: options?.data,
|
|
1465
|
-
redirect_uri: options?.redirectUrl,
|
|
1466
|
-
user_id: userId
|
|
1467
|
-
}
|
|
1468
|
-
});
|
|
1469
|
-
return new ConnectionRequest(this.client, response.id, response.status);
|
|
1781
|
+
async update(slug, body, options) {
|
|
1782
|
+
return this.client.triggerInstances.upsert(slug, body, options);
|
|
1470
1783
|
}
|
|
1471
1784
|
/**
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1474
|
-
* @param {
|
|
1475
|
-
* @returns
|
|
1785
|
+
* Delete a trigger instance
|
|
1786
|
+
*
|
|
1787
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1788
|
+
* @returns
|
|
1476
1789
|
*/
|
|
1477
|
-
async
|
|
1478
|
-
return this.client.
|
|
1790
|
+
async delete(slug) {
|
|
1791
|
+
return this.client.triggerInstances.removeUpsert(slug);
|
|
1479
1792
|
}
|
|
1480
1793
|
/**
|
|
1481
|
-
*
|
|
1482
|
-
*
|
|
1794
|
+
* Update the status of a trigger
|
|
1795
|
+
*
|
|
1796
|
+
* @param {TriggerStatusEnum} status - The new status of the trigger
|
|
1797
|
+
* @param {TriggerInstanceUpdateStatusParams} params - The parameters to update the trigger instance
|
|
1483
1798
|
* @param {RequestOptions} options - Request options
|
|
1484
|
-
* @returns {Promise<
|
|
1799
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1485
1800
|
*/
|
|
1486
|
-
async
|
|
1487
|
-
return this.client.
|
|
1801
|
+
async updateStatus(status, params, options) {
|
|
1802
|
+
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
1488
1803
|
}
|
|
1489
1804
|
/**
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1492
|
-
* @param {
|
|
1493
|
-
* @
|
|
1805
|
+
* Disable a trigger instance
|
|
1806
|
+
*
|
|
1807
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1808
|
+
* @param {RequestOptions options - Request options
|
|
1809
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1494
1810
|
*/
|
|
1495
|
-
async
|
|
1496
|
-
return this.client.
|
|
1811
|
+
async disable(slug, options) {
|
|
1812
|
+
return this.client.triggerInstances.updateStatus("disable", { slug }, options);
|
|
1497
1813
|
}
|
|
1498
1814
|
/**
|
|
1499
|
-
*
|
|
1500
|
-
*
|
|
1501
|
-
* @param {
|
|
1502
|
-
* @param {RequestOptions
|
|
1503
|
-
* @returns {Promise<
|
|
1815
|
+
* Enable a trigger instance
|
|
1816
|
+
*
|
|
1817
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1818
|
+
* @param {RequestOptions options - Request options
|
|
1819
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1504
1820
|
*/
|
|
1505
|
-
async
|
|
1506
|
-
return this.client.
|
|
1821
|
+
async enable(slug, options) {
|
|
1822
|
+
return this.client.triggerInstances.updateStatus("enable", { slug }, options);
|
|
1507
1823
|
}
|
|
1508
1824
|
/**
|
|
1509
|
-
*
|
|
1510
|
-
|
|
1825
|
+
* @TODO Learn about trigger types
|
|
1826
|
+
*/
|
|
1827
|
+
/**
|
|
1828
|
+
* List all the trigger types
|
|
1829
|
+
*
|
|
1830
|
+
* @param {TriggersTypeListParams} query - The query parameters to filter the trigger types
|
|
1511
1831
|
* @param {RequestOptions} options - Request options
|
|
1512
|
-
* @returns {Promise<
|
|
1832
|
+
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
|
|
1513
1833
|
*/
|
|
1514
|
-
async
|
|
1515
|
-
return this.client.
|
|
1834
|
+
async listTypes(query, options) {
|
|
1835
|
+
return this.client.triggersTypes.list(query, options);
|
|
1516
1836
|
}
|
|
1517
1837
|
/**
|
|
1518
|
-
*
|
|
1519
|
-
*
|
|
1520
|
-
* @param {
|
|
1521
|
-
* @
|
|
1838
|
+
* Retrieve a trigger type by its slug
|
|
1839
|
+
*
|
|
1840
|
+
* @param {string} slug - The slug of the trigger type
|
|
1841
|
+
* @param {RequestOptions} options - request options
|
|
1842
|
+
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
1522
1843
|
*/
|
|
1523
|
-
async
|
|
1524
|
-
return this.client.
|
|
1844
|
+
async getType(slug, options) {
|
|
1845
|
+
return this.client.triggersTypes.retrieve(slug, options);
|
|
1846
|
+
}
|
|
1847
|
+
/**
|
|
1848
|
+
* Fetches the list of all the available trigger enums
|
|
1849
|
+
*
|
|
1850
|
+
* This method is used by the CLI where filters are not required.
|
|
1851
|
+
* @param options
|
|
1852
|
+
* @returns
|
|
1853
|
+
*/
|
|
1854
|
+
async listEnum(options) {
|
|
1855
|
+
return this.client.triggersTypes.retrieveEnum(options);
|
|
1856
|
+
}
|
|
1857
|
+
async subscribe(fn, filters = {}) {
|
|
1858
|
+
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
1859
|
+
const session = new Session(this.client);
|
|
1860
|
+
const sessionInfo = await session.getInfo();
|
|
1861
|
+
const clientId = sessionInfo.project?.id;
|
|
1862
|
+
if (!clientId) throw new Error("Client ID not found");
|
|
1863
|
+
await PusherUtils.getPusherClient(this.client.baseURL, this.client.apiKey);
|
|
1864
|
+
const shouldSendTrigger = (data) => {
|
|
1865
|
+
if (Object.keys(filters).length === 0) return true;
|
|
1866
|
+
else {
|
|
1867
|
+
return (!filters.appName || data.appName.toLowerCase() === filters.appName.toLowerCase()) && (!filters.triggerId || data.metadata.id.toLowerCase() === filters.triggerId.toLowerCase()) && (!filters.connectionId || data.metadata.connectionId.toLowerCase() === filters.connectionId.toLowerCase()) && (!filters.triggerName || data.metadata.triggerName.toLowerCase() === filters.triggerName.toLowerCase()) && (!filters.entityId || data.metadata.connection.clientUniqueUserId.toLowerCase() === filters.entityId.toLowerCase()) && (!filters.integrationId || data.metadata.connection.integrationId.toLowerCase() === filters.integrationId.toLowerCase());
|
|
1868
|
+
}
|
|
1869
|
+
};
|
|
1870
|
+
logger_default.debug("Subscribing to triggers", filters);
|
|
1871
|
+
PusherUtils.triggerSubscribe(clientId, (data) => {
|
|
1872
|
+
if (shouldSendTrigger(data)) {
|
|
1873
|
+
fn(data);
|
|
1874
|
+
}
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
async unsubscribe() {
|
|
1878
|
+
const session = new Session(this.client);
|
|
1879
|
+
const sessionInfo = await session.getInfo();
|
|
1880
|
+
const clientId = sessionInfo.project?.id;
|
|
1881
|
+
if (!clientId) throw new Error("Client ID not found");
|
|
1882
|
+
PusherUtils.triggerUnsubscribe(clientId);
|
|
1525
1883
|
}
|
|
1526
1884
|
};
|
|
1527
1885
|
|
|
@@ -1875,8 +2233,8 @@ var OpenAIToolset = class extends BaseNonAgenticToolset {
|
|
|
1875
2233
|
async executeToolCall(userId, tool, options, modifiers) {
|
|
1876
2234
|
const payload = {
|
|
1877
2235
|
arguments: JSON.parse(tool.function.arguments),
|
|
1878
|
-
connectedAccountId: options
|
|
1879
|
-
customAuthParams: options
|
|
2236
|
+
connectedAccountId: options?.connectedAccountId,
|
|
2237
|
+
customAuthParams: options?.customAuthParams,
|
|
1880
2238
|
userId
|
|
1881
2239
|
};
|
|
1882
2240
|
const result = await this.executeTool(tool.function.name, payload, modifiers);
|
|
@@ -2009,7 +2367,7 @@ var OpenAIToolset = class extends BaseNonAgenticToolset {
|
|
|
2009
2367
|
};
|
|
2010
2368
|
|
|
2011
2369
|
// package.json
|
|
2012
|
-
var version = "0.1.
|
|
2370
|
+
var version = "0.1.9-alpha.0";
|
|
2013
2371
|
|
|
2014
2372
|
// src/utils/uuid.ts
|
|
2015
2373
|
var import_uuid = require("uuid");
|
|
@@ -2042,7 +2400,7 @@ var Composio = class {
|
|
|
2042
2400
|
createAuthConfig;
|
|
2043
2401
|
// connected accounts
|
|
2044
2402
|
connectedAccounts;
|
|
2045
|
-
|
|
2403
|
+
initiateConnection;
|
|
2046
2404
|
/**
|
|
2047
2405
|
* @param {Object} config Configuration for the Composio SDK.
|
|
2048
2406
|
* @param {string} config.apiKey The API key for the Composio SDK.
|
|
@@ -2076,7 +2434,7 @@ var Composio = class {
|
|
|
2076
2434
|
this.authConfigs = new AuthConfigs(this.client);
|
|
2077
2435
|
this.createAuthConfig = this.authConfigs.create.bind(this.authConfigs);
|
|
2078
2436
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
2079
|
-
this.
|
|
2437
|
+
this.initiateConnection = this.connectedAccounts.initiate.bind(this.connectedAccounts);
|
|
2080
2438
|
if (this.config.allowTracking ?? true) {
|
|
2081
2439
|
this.initializeTelemetry(
|
|
2082
2440
|
{
|
|
@@ -2156,39 +2514,39 @@ var BaseTelemetryTransport = class {
|
|
|
2156
2514
|
};
|
|
2157
2515
|
|
|
2158
2516
|
// src/utils/jsonSchema.ts
|
|
2159
|
-
var
|
|
2517
|
+
var import_zod8 = require("zod");
|
|
2160
2518
|
function jsonSchemaPropertiesToTSTypes(value) {
|
|
2161
2519
|
if (!value.type) {
|
|
2162
|
-
return
|
|
2520
|
+
return import_zod8.z.object({});
|
|
2163
2521
|
}
|
|
2164
2522
|
let zodType;
|
|
2165
2523
|
switch (value.type) {
|
|
2166
2524
|
case "string":
|
|
2167
|
-
zodType =
|
|
2525
|
+
zodType = import_zod8.z.string().describe(
|
|
2168
2526
|
(value.description || "") + (value.examples ? `
|
|
2169
2527
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2170
2528
|
);
|
|
2171
2529
|
break;
|
|
2172
2530
|
case "number":
|
|
2173
|
-
zodType =
|
|
2531
|
+
zodType = import_zod8.z.number().describe(
|
|
2174
2532
|
(value.description || "") + (value.examples ? `
|
|
2175
2533
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2176
2534
|
);
|
|
2177
2535
|
break;
|
|
2178
2536
|
case "integer":
|
|
2179
|
-
zodType =
|
|
2537
|
+
zodType = import_zod8.z.number().int().describe(
|
|
2180
2538
|
(value.description || "") + (value.examples ? `
|
|
2181
2539
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2182
2540
|
);
|
|
2183
2541
|
break;
|
|
2184
2542
|
case "boolean":
|
|
2185
|
-
zodType =
|
|
2543
|
+
zodType = import_zod8.z.boolean().describe(
|
|
2186
2544
|
(value.description || "") + (value.examples ? `
|
|
2187
2545
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2188
2546
|
);
|
|
2189
2547
|
break;
|
|
2190
2548
|
case "array":
|
|
2191
|
-
zodType =
|
|
2549
|
+
zodType = import_zod8.z.array(
|
|
2192
2550
|
jsonSchemaPropertiesToTSTypes(
|
|
2193
2551
|
value.items
|
|
2194
2552
|
)
|
|
@@ -2204,7 +2562,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2204
2562
|
);
|
|
2205
2563
|
break;
|
|
2206
2564
|
case "null":
|
|
2207
|
-
zodType =
|
|
2565
|
+
zodType = import_zod8.z.null().describe(value.description || "");
|
|
2208
2566
|
break;
|
|
2209
2567
|
default:
|
|
2210
2568
|
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
@@ -2215,7 +2573,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
2215
2573
|
const properties = jsonSchema.properties;
|
|
2216
2574
|
const requiredFields = jsonSchema.required || [];
|
|
2217
2575
|
if (!properties) {
|
|
2218
|
-
return
|
|
2576
|
+
return import_zod8.z.object({});
|
|
2219
2577
|
}
|
|
2220
2578
|
const zodSchema = {};
|
|
2221
2579
|
for (const [key, _] of Object.entries(properties)) {
|
|
@@ -2227,7 +2585,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
2227
2585
|
schema
|
|
2228
2586
|
)
|
|
2229
2587
|
);
|
|
2230
|
-
zodType =
|
|
2588
|
+
zodType = import_zod8.z.union(anyOfTypes).describe(
|
|
2231
2589
|
(value.description || "") + (value.examples ? `
|
|
2232
2590
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2233
2591
|
);
|
|
@@ -2237,7 +2595,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2237
2595
|
schema
|
|
2238
2596
|
)
|
|
2239
2597
|
);
|
|
2240
|
-
zodType =
|
|
2598
|
+
zodType = import_zod8.z.intersection(
|
|
2241
2599
|
allOfTypes[0],
|
|
2242
2600
|
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
2243
2601
|
).describe(
|
|
@@ -2261,7 +2619,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2261
2619
|
zodSchema[key] = zodType.optional();
|
|
2262
2620
|
}
|
|
2263
2621
|
}
|
|
2264
|
-
return
|
|
2622
|
+
return import_zod8.z.object(zodSchema);
|
|
2265
2623
|
}
|
|
2266
2624
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2267
2625
|
0 && (module.exports = {
|