@composio/core 0.1.12-alpha.8 → 0.1.12
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 +2720 -1265
- package/dist/index.d.cts +1313 -331
- package/dist/index.d.ts +1313 -331
- package/dist/index.js +2692 -1262
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/composio.ts
|
|
9
|
-
import
|
|
9
|
+
import ComposioClient3 from "@composio/client";
|
|
10
10
|
|
|
11
11
|
// src/types/tool.types.ts
|
|
12
12
|
import { z } from "zod";
|
|
@@ -15,12 +15,38 @@ var ToolkitSchema = z.object({
|
|
|
15
15
|
name: z.string().describe("The name of the toolkit"),
|
|
16
16
|
logo: z.string().describe("The logo of the toolkit").optional()
|
|
17
17
|
});
|
|
18
|
+
var JSONSchemaType = z.enum([
|
|
19
|
+
"string",
|
|
20
|
+
"number",
|
|
21
|
+
"integer",
|
|
22
|
+
"boolean",
|
|
23
|
+
"object",
|
|
24
|
+
"array",
|
|
25
|
+
"null"
|
|
26
|
+
]);
|
|
27
|
+
var JSONSchemaProperty = z.object({
|
|
28
|
+
type: JSONSchemaType.optional(),
|
|
29
|
+
description: z.string().optional(),
|
|
30
|
+
title: z.string().optional(),
|
|
31
|
+
default: z.any().optional(),
|
|
32
|
+
properties: z.lazy(() => z.record(z.string(), JSONSchemaProperty)).optional(),
|
|
33
|
+
required: z.array(z.string()).optional(),
|
|
34
|
+
items: z.lazy(() => JSONSchemaProperty).optional()
|
|
35
|
+
});
|
|
36
|
+
var ParametersSchema = z.object({
|
|
37
|
+
type: z.literal("object"),
|
|
38
|
+
properties: z.record(z.string(), JSONSchemaProperty),
|
|
39
|
+
required: z.array(z.string()).optional(),
|
|
40
|
+
title: z.string().optional(),
|
|
41
|
+
description: z.string().optional(),
|
|
42
|
+
additionalProperties: z.boolean().optional()
|
|
43
|
+
});
|
|
18
44
|
var ToolSchema = z.object({
|
|
19
45
|
slug: z.string().describe('The slug of the tool. eg. "GOOGLE_SEARCH"'),
|
|
20
46
|
name: z.string().describe(`The name of the tool. eg. "Google Search"`),
|
|
21
47
|
description: z.string().optional().describe("The description of the tool"),
|
|
22
|
-
inputParameters:
|
|
23
|
-
outputParameters:
|
|
48
|
+
inputParameters: ParametersSchema.optional().describe("The input parameters of the tool"),
|
|
49
|
+
outputParameters: ParametersSchema.optional().describe("The output parameters of the tool"),
|
|
24
50
|
tags: z.optional(z.array(z.string())).describe("The tags of the tool. eg: Important").default([]),
|
|
25
51
|
toolkit: z.optional(ToolkitSchema).describe("The toolkit of the tool"),
|
|
26
52
|
version: z.optional(z.string()).describe('The version of the tool, e.g. "1.0.0"')
|
|
@@ -30,14 +56,27 @@ var ToolListResponseSchema = z.object({
|
|
|
30
56
|
nextCursor: z.string().nullable().optional(),
|
|
31
57
|
totalPages: z.number()
|
|
32
58
|
});
|
|
33
|
-
var
|
|
34
|
-
tools: z.array(z.string())
|
|
59
|
+
var ToolListFilterByToolsSchema = z.object({
|
|
60
|
+
tools: z.array(z.string())
|
|
61
|
+
});
|
|
62
|
+
var ToolListFilterByToolkitsSchema = z.object({
|
|
63
|
+
toolkits: z.array(z.string()),
|
|
64
|
+
important: z.boolean().optional(),
|
|
65
|
+
cursor: z.string().optional(),
|
|
66
|
+
limit: z.number().optional(),
|
|
67
|
+
search: z.string().optional()
|
|
68
|
+
});
|
|
69
|
+
var ToolListFilterBySearchSchema = z.object({
|
|
70
|
+
search: z.string(),
|
|
71
|
+
toolkits: z.array(z.string()).optional(),
|
|
35
72
|
cursor: z.string().optional(),
|
|
36
|
-
|
|
37
|
-
limit: z.string().optional(),
|
|
38
|
-
search: z.string().optional(),
|
|
39
|
-
toolkits: z.array(z.string()).optional()
|
|
73
|
+
limit: z.number().optional()
|
|
40
74
|
});
|
|
75
|
+
var ToolListParamsSchema = z.union([
|
|
76
|
+
ToolListFilterByToolsSchema,
|
|
77
|
+
ToolListFilterByToolkitsSchema,
|
|
78
|
+
ToolListFilterBySearchSchema
|
|
79
|
+
]);
|
|
41
80
|
var CustomAuthParamsSchema = z.object({
|
|
42
81
|
baseURL: z.string().optional(),
|
|
43
82
|
body: z.record(z.string(), z.unknown()).optional(),
|
|
@@ -65,16 +104,31 @@ var ToolExecuteResponseSchema = z.object({
|
|
|
65
104
|
logId: z.string().optional(),
|
|
66
105
|
sessionInfo: z.unknown().optional()
|
|
67
106
|
});
|
|
107
|
+
var ToolProxyParamsSchema = z.object({
|
|
108
|
+
endpoint: z.string(),
|
|
109
|
+
method: z.enum(["GET", "POST", "PUT", "DELETE", "PATCH"]),
|
|
110
|
+
body: z.unknown().optional(),
|
|
111
|
+
parameters: z.array(
|
|
112
|
+
z.object({
|
|
113
|
+
in: z.enum(["query", "header"]),
|
|
114
|
+
name: z.string(),
|
|
115
|
+
value: z.union([z.string(), z.number()])
|
|
116
|
+
})
|
|
117
|
+
),
|
|
118
|
+
connectedAccountId: z.string().optional()
|
|
119
|
+
});
|
|
68
120
|
|
|
69
121
|
// src/models/CustomTools.ts
|
|
70
122
|
import zodToJsonSchema from "zod-to-json-schema";
|
|
71
123
|
|
|
124
|
+
// src/utils/logger.ts
|
|
125
|
+
import chalk from "chalk";
|
|
126
|
+
|
|
72
127
|
// src/utils/env.ts
|
|
73
128
|
var getEnvVariable = (name, defaultValue = void 0) => {
|
|
74
129
|
try {
|
|
75
130
|
return process.env[name] || defaultValue;
|
|
76
131
|
} catch (_e) {
|
|
77
|
-
logger_default.error(`Error getting environment variable ${name}:`, _e);
|
|
78
132
|
return defaultValue;
|
|
79
133
|
}
|
|
80
134
|
};
|
|
@@ -93,7 +147,7 @@ var LOG_LEVELS = {
|
|
|
93
147
|
// Debug information
|
|
94
148
|
};
|
|
95
149
|
var getLogLevel = () => {
|
|
96
|
-
const envLevel = getEnvVariable("
|
|
150
|
+
const envLevel = getEnvVariable("COMPOSIO_LOG_LEVEL", "info")?.toLowerCase();
|
|
97
151
|
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
98
152
|
};
|
|
99
153
|
var Logger = class {
|
|
@@ -106,12 +160,25 @@ var Logger = class {
|
|
|
106
160
|
this.console = console;
|
|
107
161
|
}
|
|
108
162
|
formatMessage(args) {
|
|
109
|
-
const formattedArgs = args.map((arg) =>
|
|
163
|
+
const formattedArgs = args.map((arg, index) => {
|
|
164
|
+
if (typeof arg === "object") {
|
|
165
|
+
return JSON.stringify(arg);
|
|
166
|
+
} else {
|
|
167
|
+
if (index === 0) {
|
|
168
|
+
if (args.length > 1) {
|
|
169
|
+
return chalk.yellow(`${arg}`);
|
|
170
|
+
} else {
|
|
171
|
+
return String(arg);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return String(arg);
|
|
175
|
+
}
|
|
176
|
+
}).join("\n");
|
|
110
177
|
if (!this.includeTimestamp) {
|
|
111
178
|
return formattedArgs;
|
|
112
179
|
}
|
|
113
180
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
114
|
-
return `${timestamp} - ${formattedArgs}`;
|
|
181
|
+
return `${chalk.gray(timestamp)} - ${formattedArgs}`;
|
|
115
182
|
}
|
|
116
183
|
shouldLog(level) {
|
|
117
184
|
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
@@ -141,34 +208,240 @@ var logger = new Logger();
|
|
|
141
208
|
var logger_default = logger;
|
|
142
209
|
|
|
143
210
|
// src/errors/ComposioError.ts
|
|
144
|
-
|
|
211
|
+
import chalk2 from "chalk";
|
|
212
|
+
import { ZodError } from "zod";
|
|
213
|
+
import { BadRequestError } from "@composio/client";
|
|
214
|
+
var ComposioError = class _ComposioError extends Error {
|
|
215
|
+
/** @readonly Error name */
|
|
145
216
|
name = "ComposioError";
|
|
146
217
|
code;
|
|
147
|
-
statusCode;
|
|
148
|
-
cause;
|
|
149
|
-
meta;
|
|
150
218
|
possibleFixes;
|
|
219
|
+
errorId;
|
|
220
|
+
/**
|
|
221
|
+
* Creates a new ComposioError
|
|
222
|
+
* @param message Error message
|
|
223
|
+
* @param options Additional error options
|
|
224
|
+
*/
|
|
151
225
|
constructor(message, options = {}) {
|
|
152
226
|
super(message);
|
|
153
|
-
this.code = options.code;
|
|
154
|
-
this.statusCode = options.statusCode;
|
|
155
|
-
this.cause = options.cause;
|
|
156
|
-
this.meta = options.meta;
|
|
157
|
-
this.possibleFixes = options.possibleFixes;
|
|
158
227
|
if (Error.captureStackTrace) {
|
|
159
228
|
Error.captureStackTrace(this, this.constructor);
|
|
160
229
|
}
|
|
230
|
+
const statusCode = options.statusCode || (options.cause instanceof BadRequestError ? options.cause.status : void 0);
|
|
231
|
+
this.code = `TS-SDK::${options.code}`;
|
|
232
|
+
this.possibleFixes = options.possibleFixes;
|
|
233
|
+
this.definePropertyIfExists("statusCode", statusCode);
|
|
234
|
+
this.definePropertyIfExists("cause", options.cause);
|
|
235
|
+
const combinedStack = options.cause instanceof Error ? _ComposioError.combineStackTraces(options.cause.stack, this.stack) : options.stack ?? this.stack;
|
|
236
|
+
this.definePropertyIfExists("stack", combinedStack);
|
|
237
|
+
if (options.meta && Object.keys(options.meta).length > 0) {
|
|
238
|
+
this.definePropertyIfExists("meta", options.meta);
|
|
239
|
+
}
|
|
161
240
|
}
|
|
162
|
-
|
|
163
|
-
|
|
241
|
+
/**
|
|
242
|
+
* Helper method to define a property only if it has a value
|
|
243
|
+
* @param propertyName Name of the property to define
|
|
244
|
+
* @param value Value to assign to the property
|
|
245
|
+
* @private
|
|
246
|
+
*/
|
|
247
|
+
definePropertyIfExists(propertyName, value) {
|
|
248
|
+
if (value !== void 0) {
|
|
249
|
+
Object.defineProperty(this, propertyName, {
|
|
250
|
+
value,
|
|
251
|
+
enumerable: true,
|
|
252
|
+
writable: false,
|
|
253
|
+
configurable: true
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Helper method to combine stack traces when wrapping errors
|
|
259
|
+
* This ensures the full call chain is preserved
|
|
260
|
+
* @param originalStack The stack of the error being wrapped
|
|
261
|
+
* @param currentStack The stack of the wrapper error
|
|
262
|
+
* @returns Combined stack trace
|
|
263
|
+
* @private
|
|
264
|
+
*/
|
|
265
|
+
static combineStackTraces(originalStack, currentStack) {
|
|
266
|
+
if (!originalStack) return currentStack;
|
|
267
|
+
if (!currentStack) return originalStack;
|
|
268
|
+
const currentHeader = currentStack.split("\n")[0];
|
|
269
|
+
const originalStackBody = originalStack.split("\n").slice(1).join("\n");
|
|
270
|
+
return `${currentHeader}
|
|
271
|
+
${currentStack.split("\n").slice(1).join("\n")}
|
|
272
|
+
|
|
273
|
+
Caused by:
|
|
274
|
+
${originalStackBody}`;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Extract and normalize error data for formatting
|
|
278
|
+
* @param includeStack Whether to include stack trace information
|
|
279
|
+
* @returns Structured error data for formatting
|
|
280
|
+
* @private
|
|
281
|
+
*/
|
|
282
|
+
getErrorData(includeStack = false) {
|
|
283
|
+
const data = {
|
|
164
284
|
name: this.name,
|
|
165
|
-
message: this.message
|
|
166
|
-
code: this.code,
|
|
167
|
-
statusCode: this.statusCode,
|
|
168
|
-
cause: this.cause instanceof Error ? this.cause.message : this.cause,
|
|
169
|
-
meta: this.meta,
|
|
170
|
-
possibleFixes: this.possibleFixes?.length ? this.possibleFixes.join("\n") : void 0
|
|
285
|
+
message: this.message
|
|
171
286
|
};
|
|
287
|
+
const { cause, code, stack, statusCode, meta, possibleFixes } = this;
|
|
288
|
+
if (cause !== void 0) {
|
|
289
|
+
const rawCause = cause;
|
|
290
|
+
data.cause = rawCause instanceof Error ? rawCause.message : String(rawCause);
|
|
291
|
+
}
|
|
292
|
+
if (code) {
|
|
293
|
+
data.code = code;
|
|
294
|
+
}
|
|
295
|
+
if (statusCode !== void 0) {
|
|
296
|
+
data.statusCode = statusCode;
|
|
297
|
+
}
|
|
298
|
+
if (meta) {
|
|
299
|
+
data.meta = meta;
|
|
300
|
+
}
|
|
301
|
+
if (possibleFixes) {
|
|
302
|
+
data.possibleFixes = possibleFixes;
|
|
303
|
+
}
|
|
304
|
+
if (includeStack && stack) {
|
|
305
|
+
if (stack.includes("Caused by:")) {
|
|
306
|
+
const [currentStack, causeStack] = stack.split("Caused by:");
|
|
307
|
+
data.stack = [
|
|
308
|
+
...currentStack.split("\n").slice(1),
|
|
309
|
+
"Caused by:",
|
|
310
|
+
...causeStack.split("\n")
|
|
311
|
+
];
|
|
312
|
+
} else {
|
|
313
|
+
data.stack = stack.split("\n").slice(1);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return data;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Prints a user-friendly, colorful representation of the error to the logger
|
|
320
|
+
* @param includeStack Whether to include the stack trace in the output (default: false)
|
|
321
|
+
*/
|
|
322
|
+
prettyPrint(includeStack = false) {
|
|
323
|
+
const data = this.getErrorData(includeStack);
|
|
324
|
+
let output = "\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold(data.message) + "\n";
|
|
325
|
+
if (data.code) {
|
|
326
|
+
output += chalk2.yellow(`Error Code: ${data.code}`) + "\n";
|
|
327
|
+
}
|
|
328
|
+
if (data.statusCode !== void 0) {
|
|
329
|
+
output += chalk2.yellow(`Status: ${data.statusCode}`) + "\n";
|
|
330
|
+
}
|
|
331
|
+
if (data.cause) {
|
|
332
|
+
output += chalk2.gray("Reason:") + "\n";
|
|
333
|
+
output += " " + chalk2.white(data.cause) + "\n";
|
|
334
|
+
}
|
|
335
|
+
if (data.meta) {
|
|
336
|
+
output += chalk2.gray("Additional Information:") + "\n";
|
|
337
|
+
output += " " + chalk2.white(JSON.stringify(data.meta, null, 2).replace(/\n/g, "\n ")) + "\n";
|
|
338
|
+
}
|
|
339
|
+
if (data.possibleFixes?.length) {
|
|
340
|
+
output += "\n" + chalk2.cyan.bold("Try the following:") + "\n";
|
|
341
|
+
const fixes = data.possibleFixes?.map((fix, index) => ` ${index + 1}. ` + chalk2.white(fix));
|
|
342
|
+
output += fixes?.join("\n") + "\n";
|
|
343
|
+
}
|
|
344
|
+
if (data.stack?.length) {
|
|
345
|
+
output += "\n" + chalk2.gray("Stack Trace:") + "\n";
|
|
346
|
+
output += chalk2.gray(data.stack.join("\n")) + "\n";
|
|
347
|
+
}
|
|
348
|
+
output += "\n";
|
|
349
|
+
logger_default.error(output);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Static factory method to create and pretty print an error in one step
|
|
353
|
+
* @param message Error message
|
|
354
|
+
* @param options Error options
|
|
355
|
+
* @param includeStack Whether to include the stack trace in the output
|
|
356
|
+
* @returns The created error instance
|
|
357
|
+
*/
|
|
358
|
+
static createAndPrint(message, options = {}, includeStack = false) {
|
|
359
|
+
const error = new _ComposioError(message, options);
|
|
360
|
+
error.prettyPrint(includeStack);
|
|
361
|
+
return error;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Utility function to handle errors in a consistent way
|
|
365
|
+
* This properly displays the error and exits the process if needed
|
|
366
|
+
* @param error The error to handle
|
|
367
|
+
* @param options Options for error handling
|
|
368
|
+
*/
|
|
369
|
+
static handle(error, options = {}) {
|
|
370
|
+
const { includeStack = false, exitProcess = false, exitCode = 1 } = options;
|
|
371
|
+
if (error instanceof _ComposioError) {
|
|
372
|
+
error.prettyPrint(includeStack);
|
|
373
|
+
} else if (error instanceof ZodError) {
|
|
374
|
+
this.handleZodError(error, includeStack);
|
|
375
|
+
} else if (error instanceof Error) {
|
|
376
|
+
this.handleStandardError(error, includeStack);
|
|
377
|
+
} else {
|
|
378
|
+
this.handleUnknownError(error);
|
|
379
|
+
}
|
|
380
|
+
if (exitProcess && typeof process !== "undefined") {
|
|
381
|
+
process.exit(exitCode);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Helper method to handle Zod validation errors
|
|
386
|
+
* @param error The Zod error to handle
|
|
387
|
+
* @param includeStack Whether to include the stack trace
|
|
388
|
+
* @private
|
|
389
|
+
*/
|
|
390
|
+
static handleZodError(error, includeStack) {
|
|
391
|
+
logger_default.error("\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold(error.message));
|
|
392
|
+
logger_default.error(chalk2.gray("Invalid parameters:"));
|
|
393
|
+
error.errors.forEach((err) => {
|
|
394
|
+
logger_default.error(chalk2.yellow(err.path.join(".")) + " " + chalk2.white(err.message));
|
|
395
|
+
});
|
|
396
|
+
logger_default.error(chalk2.gray("Expected parameters:"));
|
|
397
|
+
error.errors.forEach((err) => {
|
|
398
|
+
logger_default.error(chalk2.yellow(err.path.join(".")) + " " + chalk2.white(err.message));
|
|
399
|
+
});
|
|
400
|
+
if (includeStack) {
|
|
401
|
+
logger_default.error("\n" + chalk2.gray("Validation Errors:"));
|
|
402
|
+
error.errors.forEach((err) => {
|
|
403
|
+
const path = err.path.join(".");
|
|
404
|
+
logger_default.error(
|
|
405
|
+
chalk2.gray(" \u2022 ") + chalk2.yellow(path ? `${path}: ` : "") + chalk2.white(err.message)
|
|
406
|
+
);
|
|
407
|
+
});
|
|
408
|
+
if (error.stack) {
|
|
409
|
+
logger_default.error("\n" + chalk2.gray("Stack Trace:"));
|
|
410
|
+
const stackLines = error.stack.split("\n").slice(1);
|
|
411
|
+
logger_default.error(chalk2.gray(stackLines.join("\n")));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
logger_default.error("");
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Helper method to handle standard Error objects
|
|
418
|
+
* @param error The standard error to handle
|
|
419
|
+
* @param includeStack Whether to include the stack trace
|
|
420
|
+
* @private
|
|
421
|
+
*/
|
|
422
|
+
static handleStandardError(error, includeStack) {
|
|
423
|
+
logger_default.error("\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold(error.message));
|
|
424
|
+
if (includeStack && error.stack) {
|
|
425
|
+
logger_default.error("\n" + chalk2.gray("Stack Trace:"));
|
|
426
|
+
const stackLines = error.stack.split("\n").slice(1);
|
|
427
|
+
logger_default.error(chalk2.gray(stackLines.join("\n")));
|
|
428
|
+
}
|
|
429
|
+
logger_default.error("");
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Helper method to handle unknown error types
|
|
433
|
+
* @param error The unknown error value
|
|
434
|
+
* @private
|
|
435
|
+
*/
|
|
436
|
+
static handleUnknownError(error) {
|
|
437
|
+
logger_default.error(
|
|
438
|
+
"\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold("Unknown error occurred")
|
|
439
|
+
);
|
|
440
|
+
if (error !== null && error !== void 0) {
|
|
441
|
+
logger_default.error(chalk2.gray("Error details:"));
|
|
442
|
+
logger_default.error(" " + chalk2.white(String(error)));
|
|
443
|
+
}
|
|
444
|
+
logger_default.error("");
|
|
172
445
|
}
|
|
173
446
|
};
|
|
174
447
|
|
|
@@ -183,11 +456,11 @@ var ToolErrorCodes = {
|
|
|
183
456
|
GLOBAL_EXECUTE_TOOL_FN_NOT_SET: "GLOBAL_EXECUTE_TOOL_FN_NOT_SET"
|
|
184
457
|
};
|
|
185
458
|
var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
186
|
-
constructor(message = "Provider not defined",
|
|
459
|
+
constructor(message = "Provider not defined", options = {}) {
|
|
187
460
|
super(message, {
|
|
461
|
+
...options,
|
|
188
462
|
code: ToolErrorCodes.TOOLSET_NOT_DEFINED,
|
|
189
|
-
|
|
190
|
-
possibleFixes: [
|
|
463
|
+
possibleFixes: options.possibleFixes || [
|
|
191
464
|
"Ensure that the provider is defined in the Composio project and passed into the tool instance"
|
|
192
465
|
]
|
|
193
466
|
});
|
|
@@ -195,286 +468,948 @@ var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
|
195
468
|
}
|
|
196
469
|
};
|
|
197
470
|
var ComposioToolNotFoundError = class extends ComposioError {
|
|
198
|
-
constructor(message = "Tool not found",
|
|
471
|
+
constructor(message = "Tool not found", options = {}) {
|
|
199
472
|
super(message, {
|
|
473
|
+
...options,
|
|
200
474
|
code: ToolErrorCodes.TOOL_NOT_FOUND,
|
|
201
|
-
|
|
202
|
-
|
|
475
|
+
possibleFixes: options.possibleFixes || [
|
|
476
|
+
"Ensure the tool slug is correct and exists in the Composio project"
|
|
477
|
+
]
|
|
203
478
|
});
|
|
204
479
|
this.name = "ComposioToolNotFoundError";
|
|
205
480
|
}
|
|
206
481
|
};
|
|
207
482
|
var ComposioInvalidModifierError = class extends ComposioError {
|
|
208
|
-
constructor(message = "Invalid modifier",
|
|
483
|
+
constructor(message = "Invalid modifier", options = {}) {
|
|
209
484
|
super(message, {
|
|
485
|
+
...options,
|
|
210
486
|
code: ToolErrorCodes.INVALID_MODIFIER,
|
|
211
|
-
|
|
212
|
-
|
|
487
|
+
possibleFixes: options.possibleFixes || [
|
|
488
|
+
"Ensure the modifier is a function and returns a valid result"
|
|
489
|
+
]
|
|
213
490
|
});
|
|
214
491
|
this.name = "ComposioInvalidModifierError";
|
|
215
492
|
}
|
|
216
493
|
};
|
|
217
494
|
var ComposioCustomToolsNotInitializedError = class extends ComposioError {
|
|
218
|
-
constructor(message = "Custom tools not initialized",
|
|
495
|
+
constructor(message = "Custom tools not initialized", options = {}) {
|
|
219
496
|
super(message, {
|
|
497
|
+
...options,
|
|
220
498
|
code: ToolErrorCodes.CUSTOM_TOOLS_NOT_INITIALIZED,
|
|
221
|
-
|
|
222
|
-
|
|
499
|
+
possibleFixes: options.possibleFixes || [
|
|
500
|
+
"Ensure the custom tools class is initialized in the Tools instance"
|
|
501
|
+
]
|
|
223
502
|
});
|
|
224
503
|
this.name = "ComposioCustomToolsNotInitializedError";
|
|
225
504
|
}
|
|
226
505
|
};
|
|
227
506
|
var ComposioToolExecutionError = class extends ComposioError {
|
|
228
507
|
error;
|
|
229
|
-
constructor(
|
|
508
|
+
constructor(message = "Tool execution error", options = {}) {
|
|
509
|
+
const { originalError, ...restOptions } = options;
|
|
230
510
|
super(message, {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
possibleFixes:
|
|
511
|
+
...restOptions,
|
|
512
|
+
code: options.code || ToolErrorCodes.TOOL_EXECUTION_ERROR,
|
|
513
|
+
cause: options.cause || originalError,
|
|
514
|
+
possibleFixes: options.possibleFixes || [
|
|
515
|
+
"Ensure the tool is correctly configured and the input is valid"
|
|
516
|
+
]
|
|
235
517
|
});
|
|
236
|
-
this.error = error;
|
|
518
|
+
this.error = originalError || (options.cause instanceof Error ? options.cause : options.cause ? new Error(String(options.cause)) : new Error("Unknown error"));
|
|
237
519
|
this.name = "ComposioToolExecutionError";
|
|
238
520
|
}
|
|
239
521
|
};
|
|
240
522
|
var ComposioInvalidExecuteFunctionError = class extends ComposioError {
|
|
241
|
-
constructor(message = "Invalid execute function",
|
|
523
|
+
constructor(message = "Invalid execute function", options = {}) {
|
|
242
524
|
super(message, {
|
|
525
|
+
...options,
|
|
243
526
|
code: ToolErrorCodes.INVALID_EXECUTE_FUNCTION,
|
|
244
|
-
|
|
245
|
-
|
|
527
|
+
possibleFixes: options.possibleFixes || [
|
|
528
|
+
"Ensure the execute function is a valid function and returns a valid result"
|
|
529
|
+
]
|
|
246
530
|
});
|
|
247
531
|
this.name = "ComposioInvalidExecuteFunctionError";
|
|
248
532
|
}
|
|
249
533
|
};
|
|
250
534
|
var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
|
|
251
|
-
constructor(message = "Global execute tool function not set",
|
|
535
|
+
constructor(message = "Global execute tool function not set", options = {}) {
|
|
252
536
|
super(message, {
|
|
537
|
+
...options,
|
|
253
538
|
code: ToolErrorCodes.GLOBAL_EXECUTE_TOOL_FN_NOT_SET,
|
|
254
|
-
|
|
255
|
-
|
|
539
|
+
possibleFixes: options.possibleFixes || [
|
|
540
|
+
"Ensure the global execute tool function is set in the provider"
|
|
541
|
+
]
|
|
256
542
|
});
|
|
257
543
|
this.name = "ComposioGlobalExecuteToolFnNotSetError";
|
|
258
544
|
}
|
|
259
545
|
};
|
|
260
546
|
|
|
261
|
-
// src/errors/
|
|
547
|
+
// src/errors/ConnectedAccountsErrors.ts
|
|
262
548
|
var ConnectedAccountErrorCodes = {
|
|
263
549
|
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
|
|
264
550
|
};
|
|
265
551
|
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
266
|
-
constructor(message = "Connected account not found",
|
|
552
|
+
constructor(message = "Connected account not found", options = {}) {
|
|
267
553
|
super(message, {
|
|
554
|
+
...options,
|
|
268
555
|
code: ConnectedAccountErrorCodes.CONNECTED_ACCOUNT_NOT_FOUND,
|
|
269
556
|
statusCode: 404,
|
|
270
|
-
|
|
271
|
-
possibleFixes: [
|
|
557
|
+
possibleFixes: options.possibleFixes || [
|
|
272
558
|
"Ensure the connected account exists and is active in your Composio dashboard"
|
|
273
559
|
]
|
|
274
560
|
});
|
|
561
|
+
this.name = "ComposioConnectedAccountNotFoundError";
|
|
275
562
|
}
|
|
276
563
|
};
|
|
277
564
|
|
|
278
|
-
// src/
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
inputParameters: {
|
|
309
|
-
title: name,
|
|
310
|
-
type: "object",
|
|
311
|
-
description,
|
|
312
|
-
properties: paramsSchemaJson.properties,
|
|
313
|
-
required: paramsSchemaJson.required
|
|
314
|
-
},
|
|
315
|
-
// the output parameters are not used yet
|
|
316
|
-
outputParameters: {
|
|
317
|
-
type: "object",
|
|
318
|
-
title: `Response for ${name}`,
|
|
319
|
-
properties: []
|
|
320
|
-
},
|
|
321
|
-
tags: [],
|
|
322
|
-
toolkit: { name: "custom", slug: "custom" }
|
|
323
|
-
};
|
|
324
|
-
this.customToolsRegistry.set(slug.toLowerCase(), {
|
|
325
|
-
options: toolOptions,
|
|
326
|
-
schema: toolSchema
|
|
327
|
-
});
|
|
328
|
-
return toolSchema;
|
|
565
|
+
// src/telemetry/Telemetry.ts
|
|
566
|
+
import { ComposioError as ComposioClientError } from "@composio/client";
|
|
567
|
+
|
|
568
|
+
// src/types/telemetry.types.ts
|
|
569
|
+
var TELEMETRY_EVENTS = {
|
|
570
|
+
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
571
|
+
SDK_METHOD_INVOKED: "SDK_METHOD_INVOKED",
|
|
572
|
+
SDK_METHOD_ERROR: "SDK_METHOD_ERROR",
|
|
573
|
+
CLI_INVOKED: "CLI_INVOKED"
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
// src/utils/constants.ts
|
|
577
|
+
var COMPOSIO_DIR = ".composio";
|
|
578
|
+
var USER_DATA_FILE_NAME = "user_data.json";
|
|
579
|
+
var DEFAULT_BASE_URL = "https://backend.composio.dev";
|
|
580
|
+
var TELEMETRY_URL = "https://app.composio.dev";
|
|
581
|
+
var IS_DEVELOPMENT_OR_CI = process.env.DEVELOPMENT || process.env.CI || false;
|
|
582
|
+
|
|
583
|
+
// src/telemetry/BatchProcessor.ts
|
|
584
|
+
var BatchProcessor = class {
|
|
585
|
+
batch = [];
|
|
586
|
+
time;
|
|
587
|
+
batchSize;
|
|
588
|
+
processBatchCallback;
|
|
589
|
+
timer = null;
|
|
590
|
+
constructor(time = 2e3, batchSize = 100, processBatchCallback) {
|
|
591
|
+
this.batch = [];
|
|
592
|
+
this.time = time;
|
|
593
|
+
this.batchSize = batchSize;
|
|
594
|
+
this.processBatchCallback = processBatchCallback;
|
|
329
595
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const tools = [];
|
|
337
|
-
if (toolSlugs) {
|
|
338
|
-
for (const slug of toolSlugs) {
|
|
339
|
-
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
340
|
-
if (tool) {
|
|
341
|
-
tools.push(tool.schema);
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
} else {
|
|
345
|
-
return Array.from(this.customToolsRegistry.values()).map((tool) => tool.schema);
|
|
596
|
+
pushItem(item) {
|
|
597
|
+
this.batch.push(item);
|
|
598
|
+
if (this.batch.length >= this.batchSize) {
|
|
599
|
+
this.processBatch();
|
|
600
|
+
} else if (!this.timer) {
|
|
601
|
+
this.timer = setTimeout(() => this.processBatch(), this.time);
|
|
346
602
|
}
|
|
347
|
-
return tools;
|
|
348
603
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
*/
|
|
354
|
-
async getCustomToolBySlug(slug) {
|
|
355
|
-
if (!slug) {
|
|
356
|
-
throw new Error("Tool slug is required");
|
|
604
|
+
processBatch() {
|
|
605
|
+
if (this.batch.length > 0) {
|
|
606
|
+
this.processBatchCallback(this.batch);
|
|
607
|
+
this.batch = [];
|
|
357
608
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
} catch (error) {
|
|
362
|
-
logger_default.error(`Error getting custom tool: ${error}`);
|
|
363
|
-
return void 0;
|
|
609
|
+
if (this.timer) {
|
|
610
|
+
clearTimeout(this.timer);
|
|
611
|
+
this.timer = null;
|
|
364
612
|
}
|
|
365
613
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
await this.client.toolkits.retrieve(toolkitSlug);
|
|
375
|
-
} catch (error) {
|
|
376
|
-
throw new ComposioToolNotFoundError(`Toolkit with slug ${toolkitSlug} not found`, {
|
|
377
|
-
toolkitSlug,
|
|
378
|
-
error
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
382
|
-
toolkit_slugs: [toolkitSlug],
|
|
383
|
-
user_ids: [metadata.userId]
|
|
384
|
-
});
|
|
385
|
-
if (!connectedAccounts.items.length) {
|
|
386
|
-
throw new ComposioConnectedAccountNotFoundError(
|
|
387
|
-
`No connected accounts found for toolkit ${toolkitSlug}`,
|
|
388
|
-
{
|
|
389
|
-
toolkitSlug
|
|
390
|
-
}
|
|
614
|
+
};
|
|
615
|
+
|
|
616
|
+
// src/telemetry/transports/BrowserTransport.ts
|
|
617
|
+
var BrowserTelemetryTransport = class {
|
|
618
|
+
send(payload) {
|
|
619
|
+
if (typeof window === "undefined") {
|
|
620
|
+
return Promise.reject(
|
|
621
|
+
new Error("BrowserTelemetryTransport can only be used in browser environments")
|
|
391
622
|
);
|
|
392
623
|
}
|
|
393
|
-
return
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
624
|
+
return new Promise((resolve) => {
|
|
625
|
+
try {
|
|
626
|
+
const xhr = new XMLHttpRequest();
|
|
627
|
+
xhr.open(payload.method, payload.url, true);
|
|
628
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
629
|
+
Object.entries(payload.headers || {}).forEach(([key, value]) => {
|
|
630
|
+
xhr.setRequestHeader(key, value);
|
|
631
|
+
});
|
|
632
|
+
xhr.onload = function() {
|
|
633
|
+
resolve();
|
|
634
|
+
};
|
|
635
|
+
xhr.send(JSON.stringify(payload.data));
|
|
636
|
+
} catch (error) {
|
|
637
|
+
logger_default.error("Error sending error to telemetry", error);
|
|
638
|
+
resolve();
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
|
|
644
|
+
// src/telemetry/transports/ProcessTransport.ts
|
|
645
|
+
import chalk3 from "chalk";
|
|
646
|
+
var ProcessTelemetryTransport = class {
|
|
647
|
+
send(payload) {
|
|
648
|
+
if (typeof window !== "undefined") {
|
|
649
|
+
return Promise.reject(
|
|
650
|
+
new Error("ProcessTelemetryTransport can only be used in Node.js environments")
|
|
651
|
+
);
|
|
408
652
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
653
|
+
return new Promise((resolve) => {
|
|
654
|
+
try {
|
|
655
|
+
const url = new URL(payload.url);
|
|
656
|
+
const protocol = url.protocol === "https:" ? "https" : "http";
|
|
657
|
+
const port = url.port || (url.protocol === "https:" ? 443 : 80);
|
|
658
|
+
const args = [
|
|
659
|
+
"-e",
|
|
660
|
+
`
|
|
661
|
+
const http = require('${protocol}');
|
|
662
|
+
const options = {
|
|
663
|
+
hostname: '${url.hostname}',
|
|
664
|
+
path: '${url.pathname}${url.search}',
|
|
665
|
+
port: ${port},
|
|
666
|
+
method: '${payload.method}',
|
|
667
|
+
headers: ${JSON.stringify(payload.headers)}
|
|
668
|
+
};
|
|
669
|
+
|
|
670
|
+
const req = http.request(options, (res) => {
|
|
671
|
+
res.on('data', () => {});
|
|
672
|
+
res.on('end', () => {
|
|
673
|
+
process.exit(0);
|
|
674
|
+
});
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
req.on('error', () => {
|
|
678
|
+
process.exit(0);
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
req.write(JSON.stringify(${JSON.stringify(payload.data)}));
|
|
682
|
+
req.end();
|
|
683
|
+
`
|
|
684
|
+
];
|
|
685
|
+
import("child_process").then(({ spawn }) => {
|
|
686
|
+
spawn("node", args, {
|
|
687
|
+
stdio: "ignore",
|
|
688
|
+
detached: false,
|
|
689
|
+
shell: false
|
|
690
|
+
}).unref();
|
|
691
|
+
resolve();
|
|
692
|
+
}).catch((error) => {
|
|
693
|
+
logger_default.error("Error sending telemetry", error);
|
|
694
|
+
resolve();
|
|
695
|
+
});
|
|
696
|
+
logger_default.debug(chalk3.yellow("Process Telemetry"), JSON.stringify(payload, null, 2));
|
|
697
|
+
} catch (error) {
|
|
698
|
+
logger_default.error("Error sending telemetry", error);
|
|
699
|
+
resolve();
|
|
421
700
|
}
|
|
422
|
-
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
// src/utils/uuid.ts
|
|
706
|
+
import { v4 as uuidv4 } from "uuid";
|
|
707
|
+
function getRandomUUID() {
|
|
708
|
+
return uuidv4();
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// src/telemetry/Telemetry.ts
|
|
712
|
+
var TelemetryService = class {
|
|
713
|
+
telemetryMetadata;
|
|
714
|
+
transport;
|
|
715
|
+
isTelemetryDisabled = true;
|
|
716
|
+
batchProcessor = new BatchProcessor(100, 10, async (data) => {
|
|
717
|
+
await this.sendTelemetry(data);
|
|
718
|
+
});
|
|
719
|
+
setup(metadata, transport) {
|
|
720
|
+
this.telemetryMetadata = metadata;
|
|
721
|
+
this.isTelemetryDisabled = false;
|
|
722
|
+
const isBrowser = typeof window !== "undefined";
|
|
723
|
+
if (transport) {
|
|
724
|
+
this.transport = transport;
|
|
725
|
+
} else if (isBrowser) {
|
|
726
|
+
this.transport = new BrowserTelemetryTransport();
|
|
727
|
+
this.telemetryMetadata.transport = "browser";
|
|
728
|
+
} else {
|
|
729
|
+
this.transport = new ProcessTelemetryTransport();
|
|
730
|
+
this.telemetryMetadata.transport = "process";
|
|
423
731
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
732
|
+
this.sendTelemetry([
|
|
733
|
+
{
|
|
734
|
+
eventName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
735
|
+
data: {}
|
|
736
|
+
}
|
|
737
|
+
]);
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Instrument the telemetry for the given instance.
|
|
741
|
+
*
|
|
742
|
+
* You can pass the instance and the file name of the instance to instrument the telemetry.
|
|
743
|
+
* This will instrument all the methods of the instance and log the telemetry for each method call.
|
|
744
|
+
* @param instance - any instance that extends InstrumentedInstance
|
|
745
|
+
* @param fileName - the file name of the instance
|
|
746
|
+
* @returns
|
|
747
|
+
*/
|
|
748
|
+
instrument(instance, fileName) {
|
|
749
|
+
const proto = Object.getPrototypeOf(instance);
|
|
750
|
+
const methodNames = Object.getOwnPropertyNames(proto).filter((key) => {
|
|
751
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
752
|
+
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
753
|
+
});
|
|
754
|
+
const instrumentedClassName = (instance.constructor?.name || fileName) ?? "unknown";
|
|
755
|
+
for (const name of methodNames) {
|
|
756
|
+
const originalMethod = instance[name];
|
|
757
|
+
instance[name] = async (...args) => {
|
|
758
|
+
const telemetryPayload = {
|
|
759
|
+
eventName: TELEMETRY_EVENTS.SDK_METHOD_INVOKED,
|
|
760
|
+
data: {
|
|
761
|
+
fileName: instrumentedClassName,
|
|
762
|
+
method: name,
|
|
763
|
+
params: args
|
|
764
|
+
}
|
|
765
|
+
};
|
|
766
|
+
this.batchProcessor.pushItem(telemetryPayload);
|
|
767
|
+
try {
|
|
768
|
+
return await originalMethod.apply(instance, args);
|
|
769
|
+
} catch (error) {
|
|
770
|
+
if (error instanceof Error) {
|
|
771
|
+
if (!error.errorId) {
|
|
772
|
+
error.errorId = getRandomUUID();
|
|
773
|
+
this.prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
throw error;
|
|
777
|
+
}
|
|
778
|
+
};
|
|
428
779
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
780
|
+
return instance;
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Check if the telemetry should be sent.
|
|
784
|
+
* @returns true if the telemetry should be sent, false otherwise
|
|
785
|
+
*/
|
|
786
|
+
shouldSendTelemetry() {
|
|
787
|
+
const devEnvironments = ["test", "development", "CI"];
|
|
788
|
+
const nodeEnv = (getEnvVariable("NODE_ENV", "development") || "").toLowerCase();
|
|
789
|
+
const isDevEnvironment = devEnvironments.includes(nodeEnv);
|
|
790
|
+
const isTelemetryDisabledByEnv = getEnvVariable("TELEMETRY_DISABLED", "false") === "true";
|
|
791
|
+
return this.transport && !this.isTelemetryDisabled && !isTelemetryDisabledByEnv && !isDevEnvironment;
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Prepare and send the error telemetry.
|
|
795
|
+
*
|
|
796
|
+
* @TODO This currently blocks the thread and sends the telemetry to the server.
|
|
797
|
+
*
|
|
798
|
+
* @param {unknown} error - The error to send.
|
|
799
|
+
* @param {string} instrumentedClassName - The class name of the instrumented class.
|
|
800
|
+
* @param {string} name - The name of the method that threw the error.
|
|
801
|
+
*/
|
|
802
|
+
prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args) {
|
|
803
|
+
if (error instanceof ComposioClientError) {
|
|
804
|
+
const telemetryPayload = {
|
|
805
|
+
error_id: error.errorId || "",
|
|
806
|
+
error_message: error.message,
|
|
807
|
+
original_error: error.cause || error,
|
|
808
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
809
|
+
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
810
|
+
};
|
|
811
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
812
|
+
} else if (error instanceof ComposioError) {
|
|
813
|
+
const telemetryPayload = {
|
|
814
|
+
error_id: error.errorId || "",
|
|
815
|
+
error_message: error.message,
|
|
816
|
+
original_error: error.cause || error,
|
|
817
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
818
|
+
error_code: error.code,
|
|
819
|
+
possible_fix: error.possibleFixes?.join("\n"),
|
|
820
|
+
description: `Original Call : ${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
821
|
+
};
|
|
822
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
823
|
+
} else if (error instanceof Error) {
|
|
824
|
+
const telemetryPayload = {
|
|
825
|
+
error_id: error.errorId || "",
|
|
826
|
+
error_message: error instanceof Error ? error.name : "Unknown error",
|
|
827
|
+
original_error: error,
|
|
828
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
829
|
+
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
830
|
+
};
|
|
831
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
/**
|
|
835
|
+
* Send the telemetry payload to the server.
|
|
836
|
+
* @param payload - the telemetry payload to send
|
|
837
|
+
* @returns
|
|
838
|
+
*/
|
|
839
|
+
async sendTelemetry(payload) {
|
|
840
|
+
if (!this.shouldSendTelemetry()) {
|
|
841
|
+
return;
|
|
842
|
+
}
|
|
843
|
+
const url = `${TELEMETRY_URL}/api/sdk_metrics/telemetry`;
|
|
844
|
+
const reqPayload = {
|
|
845
|
+
data: payload.map((p) => ({
|
|
846
|
+
...p,
|
|
847
|
+
sdk_meta: this.telemetryMetadata
|
|
848
|
+
})),
|
|
849
|
+
url,
|
|
850
|
+
method: "POST",
|
|
851
|
+
headers: { "Content-Type": "application/json" }
|
|
434
852
|
};
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
)
|
|
853
|
+
this.transport.send(reqPayload);
|
|
854
|
+
}
|
|
855
|
+
// @TODO: check if this will send the error telemetry to the server
|
|
856
|
+
async sendErrorTelemetry(payload) {
|
|
857
|
+
if (!this.shouldSendTelemetry()) {
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
const url = `${TELEMETRY_URL}/api/sdk_metrics/error`;
|
|
861
|
+
const reqPayload = {
|
|
862
|
+
data: {
|
|
863
|
+
...payload,
|
|
864
|
+
sdk_meta: this.telemetryMetadata
|
|
865
|
+
},
|
|
866
|
+
url,
|
|
867
|
+
method: "POST",
|
|
868
|
+
headers: { "Content-Type": "application/json" }
|
|
869
|
+
};
|
|
870
|
+
this.transport.send(reqPayload);
|
|
440
871
|
}
|
|
441
872
|
};
|
|
873
|
+
var telemetry = new TelemetryService();
|
|
442
874
|
|
|
443
|
-
// src/
|
|
444
|
-
import {
|
|
875
|
+
// src/types/connectedAccounts.types.ts
|
|
876
|
+
import { z as z2 } from "zod";
|
|
877
|
+
var ConnectedAccountStatuses = {
|
|
878
|
+
INITIALIZING: "INITIALIZING",
|
|
879
|
+
INITIATED: "INITIATED",
|
|
880
|
+
ACTIVE: "ACTIVE",
|
|
881
|
+
FAILED: "FAILED",
|
|
882
|
+
EXPIRED: "EXPIRED"
|
|
883
|
+
};
|
|
884
|
+
var ConnectedAccountStatusSchema = z2.enum([
|
|
885
|
+
ConnectedAccountStatuses.INITIALIZING,
|
|
886
|
+
ConnectedAccountStatuses.INITIATED,
|
|
887
|
+
ConnectedAccountStatuses.ACTIVE,
|
|
888
|
+
ConnectedAccountStatuses.FAILED,
|
|
889
|
+
ConnectedAccountStatuses.EXPIRED
|
|
890
|
+
]);
|
|
891
|
+
var CreateConnectedAccountParamsSchema = z2.object({
|
|
892
|
+
authConfig: z2.object({
|
|
893
|
+
id: z2.string()
|
|
894
|
+
}),
|
|
895
|
+
connection: z2.object({
|
|
896
|
+
data: z2.record(z2.string(), z2.unknown()).optional(),
|
|
897
|
+
callbackUrl: z2.string().optional(),
|
|
898
|
+
userId: z2.string().optional()
|
|
899
|
+
})
|
|
900
|
+
});
|
|
901
|
+
var DefaultCreateConnectedAccountParamsSchema = z2.object({
|
|
902
|
+
auth_config: z2.object({
|
|
903
|
+
id: z2.string()
|
|
904
|
+
}),
|
|
905
|
+
connection: z2.object({
|
|
906
|
+
data: z2.record(z2.string(), z2.unknown()).optional(),
|
|
907
|
+
callback_url: z2.string().optional(),
|
|
908
|
+
user_id: z2.string().optional()
|
|
909
|
+
})
|
|
910
|
+
});
|
|
911
|
+
var CreateConnectedAccountOptionsSchema = z2.object({
|
|
912
|
+
callbackUrl: z2.string().optional(),
|
|
913
|
+
data: z2.record(z2.string(), z2.unknown()).optional()
|
|
914
|
+
});
|
|
915
|
+
var CreateConnectedAccountResponseSchema = z2.object({
|
|
916
|
+
id: z2.string(),
|
|
917
|
+
status: ConnectedAccountStatusSchema,
|
|
918
|
+
redirectUrl: z2.string().nullable()
|
|
919
|
+
});
|
|
920
|
+
var ConnectedAccountAuthSchemes = {
|
|
921
|
+
OAUTH2: "OAUTH2",
|
|
922
|
+
OAUTH1: "OAUTH1",
|
|
923
|
+
OAUTH1A: "OAUTH1A",
|
|
924
|
+
API_KEY: "API_KEY",
|
|
925
|
+
BASIC: "BASIC",
|
|
926
|
+
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
927
|
+
BEARER_TOKEN: "BEARER_TOKEN",
|
|
928
|
+
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
929
|
+
NO_AUTH: "NO_AUTH",
|
|
930
|
+
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
931
|
+
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
932
|
+
CALCOM_AUTH: "CALCOM_AUTH",
|
|
933
|
+
SNOWFLAKE: "SNOWFLAKE"
|
|
934
|
+
};
|
|
935
|
+
var ConnectedAccountAuthSchemesSchema = z2.enum([
|
|
936
|
+
ConnectedAccountAuthSchemes.OAUTH2,
|
|
937
|
+
ConnectedAccountAuthSchemes.OAUTH1,
|
|
938
|
+
ConnectedAccountAuthSchemes.OAUTH1A,
|
|
939
|
+
ConnectedAccountAuthSchemes.API_KEY,
|
|
940
|
+
ConnectedAccountAuthSchemes.BASIC,
|
|
941
|
+
ConnectedAccountAuthSchemes.BILLCOM_AUTH,
|
|
942
|
+
ConnectedAccountAuthSchemes.BEARER_TOKEN,
|
|
943
|
+
ConnectedAccountAuthSchemes.GOOGLE_SERVICE_ACCOUNT,
|
|
944
|
+
ConnectedAccountAuthSchemes.NO_AUTH,
|
|
945
|
+
ConnectedAccountAuthSchemes.BASIC_WITH_JWT,
|
|
946
|
+
ConnectedAccountAuthSchemes.COMPOSIO_LINK,
|
|
947
|
+
ConnectedAccountAuthSchemes.CALCOM_AUTH,
|
|
948
|
+
ConnectedAccountAuthSchemes.SNOWFLAKE
|
|
949
|
+
]);
|
|
950
|
+
var ConnectedAccountAuthConfigSchema = z2.object({
|
|
951
|
+
id: z2.string(),
|
|
952
|
+
authScheme: ConnectedAccountAuthSchemesSchema,
|
|
953
|
+
isComposioManaged: z2.boolean(),
|
|
954
|
+
isDisabled: z2.boolean()
|
|
955
|
+
});
|
|
956
|
+
var ConnectedAccountRetrieveResponseSchema = z2.object({
|
|
957
|
+
id: z2.string(),
|
|
958
|
+
authConfig: ConnectedAccountAuthConfigSchema,
|
|
959
|
+
userId: z2.string(),
|
|
960
|
+
data: z2.record(z2.string(), z2.unknown()),
|
|
961
|
+
params: z2.record(z2.string(), z2.unknown()).optional(),
|
|
962
|
+
status: ConnectedAccountStatusSchema,
|
|
963
|
+
statusReason: z2.string().nullable(),
|
|
964
|
+
toolkit: z2.object({
|
|
965
|
+
slug: z2.string()
|
|
966
|
+
}),
|
|
967
|
+
testRequestEndpoint: z2.string().optional(),
|
|
968
|
+
isDisabled: z2.boolean(),
|
|
969
|
+
createdAt: z2.string(),
|
|
970
|
+
updatedAt: z2.string()
|
|
971
|
+
});
|
|
972
|
+
var ConnectedAccountListParamsSchema = z2.object({
|
|
973
|
+
authConfigIds: z2.array(z2.string()).nullable().optional().describe("The auth config ids of the connected accounts"),
|
|
974
|
+
cursor: z2.number().nullable().optional().describe("The cursor to paginate through the connected accounts"),
|
|
975
|
+
labels: z2.array(z2.string()).nullable().optional().describe("The labels of the connected accounts"),
|
|
976
|
+
limit: z2.number().nullable().optional().describe("The limit of the connected accounts to return"),
|
|
977
|
+
orderBy: z2.enum(["created_at", "updated_at"]).optional().describe("The order by of the connected accounts"),
|
|
978
|
+
statuses: z2.array(ConnectedAccountStatusSchema).nullable().optional().describe("The statuses of the connected accounts"),
|
|
979
|
+
toolkitSlugs: z2.array(z2.string()).nullable().optional().describe("The toolkit slugs of the connected accounts"),
|
|
980
|
+
userIds: z2.array(z2.string()).nullable().optional().describe("The user ids of the connected accounts")
|
|
981
|
+
});
|
|
982
|
+
var ConnectedAccountListResponseSchema = z2.object({
|
|
983
|
+
items: z2.array(ConnectedAccountRetrieveResponseSchema).describe("The list of connected accounts"),
|
|
984
|
+
nextCursor: z2.string().nullable().describe("The next cursor to paginate through the connected accounts"),
|
|
985
|
+
totalPages: z2.number().describe("The total number of pages of connected accounts")
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
// src/errors/AuthConfigErrors.ts
|
|
989
|
+
var AuthConfigErrorCodes = {
|
|
990
|
+
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
991
|
+
};
|
|
992
|
+
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
993
|
+
constructor(message = "Auth config not found", options = {}) {
|
|
994
|
+
super(message, {
|
|
995
|
+
...options,
|
|
996
|
+
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
997
|
+
possibleFixes: options.possibleFixes || [
|
|
998
|
+
"Check if the auth config exists",
|
|
999
|
+
"Check if the auth config id is correct",
|
|
1000
|
+
"Check if the auth config is enabled"
|
|
1001
|
+
]
|
|
1002
|
+
});
|
|
1003
|
+
this.name = "ComposioAuthConfigNotFoundError";
|
|
1004
|
+
}
|
|
1005
|
+
};
|
|
1006
|
+
|
|
1007
|
+
// src/errors/ConnectionRequestErrors.ts
|
|
1008
|
+
var ConnectionRequestErrorCodes = {
|
|
1009
|
+
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1010
|
+
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1011
|
+
};
|
|
1012
|
+
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1013
|
+
constructor(message = "Connection request timed out", options = {}) {
|
|
1014
|
+
super(message, {
|
|
1015
|
+
...options,
|
|
1016
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT
|
|
1017
|
+
});
|
|
1018
|
+
this.name = "ConnectionRequestTimeoutError";
|
|
1019
|
+
}
|
|
1020
|
+
};
|
|
1021
|
+
var ConnectionRequestFailedError = class extends ComposioError {
|
|
1022
|
+
constructor(message = "Connection request failed", options = {}) {
|
|
1023
|
+
super(message, {
|
|
1024
|
+
...options,
|
|
1025
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED
|
|
1026
|
+
});
|
|
1027
|
+
this.name = "ConnectionRequestFailedError";
|
|
1028
|
+
}
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
// src/errors/ToolkitErrors.ts
|
|
1032
|
+
var ToolkitErrorCodes = {
|
|
1033
|
+
TOOLKIT_NOT_FOUND: "TOOLKIT_NOT_FOUND"
|
|
1034
|
+
};
|
|
1035
|
+
var ComposioToolkitNotFoundError = class extends ComposioError {
|
|
1036
|
+
constructor(message = "Toolkit not found", options = {}) {
|
|
1037
|
+
super(message, {
|
|
1038
|
+
...options,
|
|
1039
|
+
code: "TOOLKIT_NOT_FOUND",
|
|
1040
|
+
possibleFixes: options.possibleFixes || [
|
|
1041
|
+
"Ensure the toolkit is correctly configured and the slug is valid"
|
|
1042
|
+
]
|
|
1043
|
+
});
|
|
1044
|
+
this.name = "ComposioToolkitNotFoundError";
|
|
1045
|
+
}
|
|
1046
|
+
};
|
|
1047
|
+
var ComposioToolkitFetchError = class extends ComposioError {
|
|
1048
|
+
constructor(message = "Failed to fetch toolkit", options = {}) {
|
|
1049
|
+
super(message, {
|
|
1050
|
+
...options,
|
|
1051
|
+
code: "TOOLKIT_FETCH_ERROR",
|
|
1052
|
+
possibleFixes: options.possibleFixes || [
|
|
1053
|
+
"Ensure the toolkit slug is valid",
|
|
1054
|
+
"Ensure you are using the correct API key",
|
|
1055
|
+
"Ensure you are using the correct API endpoint / Base URL and it is working"
|
|
1056
|
+
]
|
|
1057
|
+
});
|
|
1058
|
+
this.name = "ComposioToolkitFetchError";
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
// src/errors/ValidationErrors.ts
|
|
1063
|
+
import { ZodError as ZodError2 } from "zod";
|
|
445
1064
|
var ValidationErrorCodes = {
|
|
446
1065
|
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
447
1066
|
};
|
|
448
1067
|
var ValidationError = class extends ComposioError {
|
|
449
|
-
|
|
450
|
-
|
|
1068
|
+
constructor(message = "Input validation failed", options = {}) {
|
|
1069
|
+
const { cause: providedZodError, ...restOptions } = options;
|
|
451
1070
|
let zodErrorInstance;
|
|
452
|
-
if (
|
|
453
|
-
zodErrorInstance =
|
|
1071
|
+
if (providedZodError instanceof ZodError2) {
|
|
1072
|
+
zodErrorInstance = providedZodError;
|
|
1073
|
+
} else {
|
|
1074
|
+
zodErrorInstance = new ZodError2([
|
|
454
1075
|
{
|
|
455
1076
|
path: [],
|
|
456
1077
|
message: "Invalid input",
|
|
457
1078
|
code: "custom"
|
|
458
1079
|
}
|
|
459
1080
|
]);
|
|
460
|
-
} else {
|
|
461
|
-
zodErrorInstance = zodError;
|
|
462
1081
|
}
|
|
1082
|
+
const issues = zodErrorInstance.issues.map(
|
|
1083
|
+
(issue) => `[${issue.code}] ${issue.path.join(".")} - ${issue.message}`
|
|
1084
|
+
);
|
|
463
1085
|
super(message, {
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
zodErrorInstance.issues.map((issue) => ({
|
|
468
|
-
path: issue.path.join("."),
|
|
469
|
-
message: issue.message,
|
|
470
|
-
code: issue.code
|
|
471
|
-
}))
|
|
472
|
-
)
|
|
473
|
-
},
|
|
1086
|
+
...restOptions,
|
|
1087
|
+
code: options.code || ValidationErrorCodes.VALIDATION_ERROR,
|
|
1088
|
+
possibleFixes: issues,
|
|
474
1089
|
cause: zodErrorInstance
|
|
475
1090
|
});
|
|
476
|
-
this.zodError = zodErrorInstance;
|
|
477
1091
|
this.name = "ValidationError";
|
|
1092
|
+
const userFriendlyMessage = this.generateUserFriendlyMessage();
|
|
1093
|
+
this.message = `${message}: ${userFriendlyMessage}`;
|
|
1094
|
+
}
|
|
1095
|
+
generateUserFriendlyMessage() {
|
|
1096
|
+
if (this.cause instanceof ZodError2 && this.cause.issues.length > 0) {
|
|
1097
|
+
const issue = this.cause.issues[0];
|
|
1098
|
+
const path = issue.path.join(".");
|
|
1099
|
+
const param = path || "parameter";
|
|
1100
|
+
if (issue.code === "invalid_type") {
|
|
1101
|
+
return `The ${param} should be a ${issue.expected}, but you provided a ${issue.received}`;
|
|
1102
|
+
}
|
|
1103
|
+
return issue.message;
|
|
1104
|
+
}
|
|
1105
|
+
return "Please check your input parameters";
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
|
|
1109
|
+
// src/errors/SDKErrors.ts
|
|
1110
|
+
var SDKErrorCodes = {
|
|
1111
|
+
NO_API_KEY_PROVIDED: "NO_API_KEY_PROVIDED"
|
|
1112
|
+
};
|
|
1113
|
+
var ComposioNoAPIKeyError = class extends ComposioError {
|
|
1114
|
+
constructor(message = "No Composio API key provided", options = {}) {
|
|
1115
|
+
const defaultCause = "Couldn't find an API key in the params, environment variables or in the user config file";
|
|
1116
|
+
super(message, {
|
|
1117
|
+
...options,
|
|
1118
|
+
code: "NO_API_KEY",
|
|
1119
|
+
cause: options.cause || defaultCause,
|
|
1120
|
+
possibleFixes: options.possibleFixes || [
|
|
1121
|
+
"Ensure you have an API key passed in the params, or in environment variable (COMPOSIO_API_KEY) or in the user config file",
|
|
1122
|
+
"To get an API key, please sign up at https://composio.dev/signup",
|
|
1123
|
+
"You can also use the Composio CLI to create a project and get an API key"
|
|
1124
|
+
],
|
|
1125
|
+
statusCode: 401
|
|
1126
|
+
});
|
|
1127
|
+
this.name = "ComposioNoAPIKeyError";
|
|
1128
|
+
}
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
// src/models/CustomTools.ts
|
|
1132
|
+
var CustomTools = class {
|
|
1133
|
+
client;
|
|
1134
|
+
customToolsRegistry;
|
|
1135
|
+
constructor(client) {
|
|
1136
|
+
if (!client) {
|
|
1137
|
+
throw new ComposioError("ComposioClient is required");
|
|
1138
|
+
}
|
|
1139
|
+
this.client = client;
|
|
1140
|
+
this.customToolsRegistry = /* @__PURE__ */ new Map();
|
|
1141
|
+
telemetry.instrument(this);
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Create a custom tool and registers it in the registry.
|
|
1145
|
+
* This is just an in memory registry and is not persisted.
|
|
1146
|
+
* @param {CustomToolOptions} toolOptions CustomToolOptions
|
|
1147
|
+
* @returns {Tool} The tool created
|
|
1148
|
+
*
|
|
1149
|
+
* @example
|
|
1150
|
+
* ```typescript
|
|
1151
|
+
* // Create a custom tool with input parameters
|
|
1152
|
+
* const customTool = await composio.customTools.createTool({
|
|
1153
|
+
* name: 'My Custom Tool',
|
|
1154
|
+
* description: 'A tool that performs a custom operation',
|
|
1155
|
+
* slug: 'MY_CUSTOM_TOOL',
|
|
1156
|
+
* inputParams: z.object({
|
|
1157
|
+
* query: z.string().describe('The search query'),
|
|
1158
|
+
* limit: z.number().optional().describe('Maximum number of results')
|
|
1159
|
+
* }),
|
|
1160
|
+
* execute: async (input, authCredentials, executeToolRequest) => {
|
|
1161
|
+
* // Custom implementation logic
|
|
1162
|
+
* return {
|
|
1163
|
+
* data: { results: ['result1', 'result2'] }
|
|
1164
|
+
* };
|
|
1165
|
+
* }
|
|
1166
|
+
* });
|
|
1167
|
+
* ```
|
|
1168
|
+
*/
|
|
1169
|
+
async createTool(toolOptions) {
|
|
1170
|
+
const { slug, execute, inputParams, name, description } = toolOptions;
|
|
1171
|
+
if (!slug || !execute || !inputParams || !name) {
|
|
1172
|
+
throw new Error("Invalid tool options");
|
|
1173
|
+
}
|
|
1174
|
+
const paramsSchema = await zodToJsonSchema(inputParams, {
|
|
1175
|
+
name: "input"
|
|
1176
|
+
});
|
|
1177
|
+
const paramsSchemaJson = paramsSchema.definitions.input;
|
|
1178
|
+
const toolSchema = {
|
|
1179
|
+
name,
|
|
1180
|
+
slug,
|
|
1181
|
+
description,
|
|
1182
|
+
inputParameters: {
|
|
1183
|
+
title: name,
|
|
1184
|
+
type: "object",
|
|
1185
|
+
description,
|
|
1186
|
+
properties: paramsSchemaJson.properties,
|
|
1187
|
+
required: paramsSchemaJson.required
|
|
1188
|
+
},
|
|
1189
|
+
// the output parameters are not used yet
|
|
1190
|
+
outputParameters: {
|
|
1191
|
+
type: "object",
|
|
1192
|
+
title: `Response for ${name}`,
|
|
1193
|
+
properties: {}
|
|
1194
|
+
},
|
|
1195
|
+
tags: [],
|
|
1196
|
+
// this is never set to the user provided toolkitslug so that we can differentiate
|
|
1197
|
+
// the toolkitslug is used via the execute function.
|
|
1198
|
+
toolkit: { name: "custom", slug: "custom" }
|
|
1199
|
+
};
|
|
1200
|
+
this.customToolsRegistry.set(slug.toLowerCase(), {
|
|
1201
|
+
options: toolOptions,
|
|
1202
|
+
schema: toolSchema
|
|
1203
|
+
});
|
|
1204
|
+
return toolSchema;
|
|
1205
|
+
}
|
|
1206
|
+
/**
|
|
1207
|
+
* Get all the custom tools from the registry.
|
|
1208
|
+
* @param {string[]} param0.toolSlugs The slugs of the tools to get
|
|
1209
|
+
* @returns {ToolList} The list of tools
|
|
1210
|
+
*
|
|
1211
|
+
* @example
|
|
1212
|
+
* ```typescript
|
|
1213
|
+
* // Get all custom tools
|
|
1214
|
+
* const allTools = await composio.customTools.getCustomTools({});
|
|
1215
|
+
*
|
|
1216
|
+
* // Get specific custom tools by slug
|
|
1217
|
+
* const specificTools = await composio.customTools.getCustomTools({
|
|
1218
|
+
* toolSlugs: ['MY_CUSTOM_TOOL', 'ANOTHER_CUSTOM_TOOL']
|
|
1219
|
+
* });
|
|
1220
|
+
* ```
|
|
1221
|
+
*/
|
|
1222
|
+
async getCustomTools({ toolSlugs }) {
|
|
1223
|
+
const tools = [];
|
|
1224
|
+
if (toolSlugs) {
|
|
1225
|
+
for (const slug of toolSlugs) {
|
|
1226
|
+
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
1227
|
+
if (tool) {
|
|
1228
|
+
tools.push(tool.schema);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
} else {
|
|
1232
|
+
return Array.from(this.customToolsRegistry.values()).map((tool) => tool.schema);
|
|
1233
|
+
}
|
|
1234
|
+
return tools;
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Get a custom tool by slug from the registry.
|
|
1238
|
+
* @param {string} slug The slug of the tool to get
|
|
1239
|
+
* @returns {Tool} The tool
|
|
1240
|
+
*
|
|
1241
|
+
* @example
|
|
1242
|
+
* ```typescript
|
|
1243
|
+
* // Get a specific custom tool by its slug
|
|
1244
|
+
* const myTool = await composio.customTools.getCustomToolBySlug('MY_CUSTOM_TOOL');
|
|
1245
|
+
* if (myTool) {
|
|
1246
|
+
* console.log(`Found tool: ${myTool.name}`);
|
|
1247
|
+
* } else {
|
|
1248
|
+
* console.log('Tool not found');
|
|
1249
|
+
* }
|
|
1250
|
+
* ```
|
|
1251
|
+
*/
|
|
1252
|
+
async getCustomToolBySlug(slug) {
|
|
1253
|
+
if (!slug) {
|
|
1254
|
+
throw new Error("Tool slug is required");
|
|
1255
|
+
}
|
|
1256
|
+
try {
|
|
1257
|
+
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
1258
|
+
return tool?.schema;
|
|
1259
|
+
} catch (error) {
|
|
1260
|
+
logger_default.error(`Error getting custom tool: ${error}`);
|
|
1261
|
+
return void 0;
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
/**
|
|
1265
|
+
* Get the connected account for the user and toolkit.
|
|
1266
|
+
* @param {string} toolkitSlug The slug of the toolkit
|
|
1267
|
+
* @param {ExecuteMetadata} metadata The metadata of the execution
|
|
1268
|
+
* @returns {ConnectedAccount} The connected account
|
|
1269
|
+
*/
|
|
1270
|
+
async getConnectedAccountForToolkit(toolkitSlug, userId, connectedAccountId) {
|
|
1271
|
+
try {
|
|
1272
|
+
await this.client.toolkits.retrieve(toolkitSlug);
|
|
1273
|
+
} catch (error) {
|
|
1274
|
+
throw new ComposioToolNotFoundError(`Toolkit with slug ${toolkitSlug} not found`, {
|
|
1275
|
+
cause: error
|
|
1276
|
+
});
|
|
1277
|
+
}
|
|
1278
|
+
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
1279
|
+
toolkit_slugs: [toolkitSlug],
|
|
1280
|
+
user_ids: [userId]
|
|
1281
|
+
});
|
|
1282
|
+
if (!connectedAccounts.items.length) {
|
|
1283
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
1284
|
+
`No connected accounts found for toolkit ${toolkitSlug}`
|
|
1285
|
+
);
|
|
1286
|
+
}
|
|
1287
|
+
const connectedAccount = connectedAccountId ? connectedAccounts.items.find((item) => item.id === connectedAccountId) : connectedAccounts.items[0];
|
|
1288
|
+
if (!connectedAccount) {
|
|
1289
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
1290
|
+
`Connected account not found for toolkit ${toolkitSlug} for user ${userId}`
|
|
1291
|
+
);
|
|
1292
|
+
}
|
|
1293
|
+
const connectedAccountResponse = await ConnectedAccountRetrieveResponseSchema.safeParse({
|
|
1294
|
+
id: connectedAccount.id,
|
|
1295
|
+
authConfig: {
|
|
1296
|
+
id: connectedAccount.auth_config.id,
|
|
1297
|
+
authScheme: connectedAccount.auth_config.auth_scheme,
|
|
1298
|
+
isComposioManaged: connectedAccount.auth_config.is_composio_managed,
|
|
1299
|
+
isDisabled: connectedAccount.auth_config.is_disabled
|
|
1300
|
+
},
|
|
1301
|
+
userId: connectedAccount.user_id,
|
|
1302
|
+
data: connectedAccount.data || {},
|
|
1303
|
+
status: connectedAccount.status,
|
|
1304
|
+
statusReason: connectedAccount.status_reason,
|
|
1305
|
+
toolkit: {
|
|
1306
|
+
slug: connectedAccount.toolkit.slug
|
|
1307
|
+
},
|
|
1308
|
+
testRequestEndpoint: connectedAccount.test_request_endpoint,
|
|
1309
|
+
isDisabled: connectedAccount.is_disabled,
|
|
1310
|
+
createdAt: connectedAccount.created_at,
|
|
1311
|
+
updatedAt: connectedAccount.updated_at
|
|
1312
|
+
});
|
|
1313
|
+
if (!connectedAccountResponse.success) {
|
|
1314
|
+
throw new ValidationError(
|
|
1315
|
+
`Validation error for connected account of ${toolkitSlug} for user ${userId}`,
|
|
1316
|
+
{
|
|
1317
|
+
cause: connectedAccountResponse.error
|
|
1318
|
+
}
|
|
1319
|
+
);
|
|
1320
|
+
}
|
|
1321
|
+
return connectedAccountResponse.data;
|
|
1322
|
+
}
|
|
1323
|
+
/**
|
|
1324
|
+
* Execute a custom tool
|
|
1325
|
+
*
|
|
1326
|
+
* @description If a toolkit is used, the connected account id is used to execute the tool.
|
|
1327
|
+
* If a connected account id is provided, it is used to execute the tool.
|
|
1328
|
+
* If a connected account id is not provided, the first connected account for the toolkit is used.
|
|
1329
|
+
*
|
|
1330
|
+
* @param {slug} slug The slug of the tool to execute
|
|
1331
|
+
* @param {Record<string, unknown>} inputParams The input parameters for the tool
|
|
1332
|
+
* @param {ExecuteMetadata} metadata The metadata of the execution
|
|
1333
|
+
* @returns {Promise<ToolExecuteResponse>} The response from the tool
|
|
1334
|
+
*/
|
|
1335
|
+
async executeCustomTool(slug, body) {
|
|
1336
|
+
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
1337
|
+
if (!tool) {
|
|
1338
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
1339
|
+
}
|
|
1340
|
+
let authCredentials = {};
|
|
1341
|
+
const { toolkitSlug, execute, inputParams } = tool.options;
|
|
1342
|
+
let connectedAccountId = body.connectedAccountId;
|
|
1343
|
+
if (toolkitSlug && toolkitSlug !== "custom") {
|
|
1344
|
+
const connectedAccount = await this.getConnectedAccountForToolkit(
|
|
1345
|
+
toolkitSlug,
|
|
1346
|
+
body.userId,
|
|
1347
|
+
body.connectedAccountId
|
|
1348
|
+
);
|
|
1349
|
+
logger_default.debug(
|
|
1350
|
+
`[CustomTool] Connected account for ${toolkitSlug} found for user ${body.userId}`,
|
|
1351
|
+
JSON.stringify(connectedAccount, null, 2)
|
|
1352
|
+
);
|
|
1353
|
+
if (!connectedAccount) {
|
|
1354
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
1355
|
+
`Connected account not found for toolkit ${toolkitSlug} for user ${body.userId}`,
|
|
1356
|
+
{
|
|
1357
|
+
meta: {
|
|
1358
|
+
toolkitSlug,
|
|
1359
|
+
userId: body.userId
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
);
|
|
1363
|
+
}
|
|
1364
|
+
authCredentials = connectedAccount.data;
|
|
1365
|
+
connectedAccountId = connectedAccount.id;
|
|
1366
|
+
}
|
|
1367
|
+
if (typeof execute !== "function") {
|
|
1368
|
+
throw new ComposioInvalidExecuteFunctionError("Invalid execute function", {
|
|
1369
|
+
meta: {
|
|
1370
|
+
toolSlug: slug
|
|
1371
|
+
}
|
|
1372
|
+
});
|
|
1373
|
+
}
|
|
1374
|
+
const executeToolRequest = async (data) => {
|
|
1375
|
+
if (toolkitSlug && toolkitSlug === "custom") {
|
|
1376
|
+
throw new ComposioInvalidExecuteFunctionError(
|
|
1377
|
+
"Custom tools without a toolkit cannot be executed using the executeToolRequest function",
|
|
1378
|
+
{
|
|
1379
|
+
possibleFixes: [
|
|
1380
|
+
"Please manually execute the tool using your logic.",
|
|
1381
|
+
"Pass a toolkit slug to execute the tool on behalf of a toolkit credentials"
|
|
1382
|
+
]
|
|
1383
|
+
}
|
|
1384
|
+
);
|
|
1385
|
+
}
|
|
1386
|
+
const parameters = data.parameters?.map((param) => ({
|
|
1387
|
+
name: param.name,
|
|
1388
|
+
type: param.in,
|
|
1389
|
+
value: param.value.toString()
|
|
1390
|
+
}));
|
|
1391
|
+
const response = await this.client.tools.proxy({
|
|
1392
|
+
endpoint: data.endpoint,
|
|
1393
|
+
method: data.method,
|
|
1394
|
+
parameters,
|
|
1395
|
+
body: data.body,
|
|
1396
|
+
connected_account_id: data.connectedAccountId ?? connectedAccountId
|
|
1397
|
+
});
|
|
1398
|
+
return {
|
|
1399
|
+
data: response.data,
|
|
1400
|
+
error: null,
|
|
1401
|
+
successful: true,
|
|
1402
|
+
logId: void 0,
|
|
1403
|
+
sessionInfo: void 0
|
|
1404
|
+
};
|
|
1405
|
+
};
|
|
1406
|
+
const parsedInput = inputParams.safeParse(body.arguments);
|
|
1407
|
+
if (!parsedInput.success) {
|
|
1408
|
+
throw new ValidationError("Invalid input parameters", {
|
|
1409
|
+
cause: parsedInput.error
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
return execute(parsedInput.data, authCredentials, executeToolRequest);
|
|
478
1413
|
}
|
|
479
1414
|
};
|
|
480
1415
|
|
|
@@ -497,6 +1432,7 @@ var Tools = class {
|
|
|
497
1432
|
this.provider._setExecuteToolFn(this.execute);
|
|
498
1433
|
this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
|
|
499
1434
|
this.getRawComposioTools = this.getRawComposioTools.bind(this);
|
|
1435
|
+
telemetry.instrument(this);
|
|
500
1436
|
}
|
|
501
1437
|
/**
|
|
502
1438
|
* Transforms tool data from snake_case API format to camelCase for internal SDK use.
|
|
@@ -640,32 +1576,45 @@ var Tools = class {
|
|
|
640
1576
|
* );
|
|
641
1577
|
* ```
|
|
642
1578
|
*/
|
|
643
|
-
async getRawComposioTools(userId, query
|
|
1579
|
+
async getRawComposioTools(userId, query, modifier) {
|
|
1580
|
+
if ("tools" in query && "toolkits" in query) {
|
|
1581
|
+
throw new ValidationError(
|
|
1582
|
+
"Invalid tool list parameters. You should not use tools and toolkits filter together."
|
|
1583
|
+
);
|
|
1584
|
+
}
|
|
644
1585
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
645
1586
|
if (queryParams.error) {
|
|
646
|
-
throw new ValidationError(
|
|
1587
|
+
throw new ValidationError("Invalid tool list parameters", {
|
|
1588
|
+
cause: queryParams.error
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
if (!("tools" in queryParams.data || "toolkits" in queryParams.data || "search" in queryParams.data)) {
|
|
1592
|
+
throw new ValidationError(
|
|
1593
|
+
"Invalid tool list parameters, atleast one of the following parameters is required: tools, toolkits, search"
|
|
1594
|
+
);
|
|
647
1595
|
}
|
|
648
1596
|
const tools = await this.client.tools.list({
|
|
649
|
-
tool_slugs: queryParams.data.tools,
|
|
650
|
-
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
651
|
-
cursor: queryParams.data.cursor,
|
|
652
|
-
important: queryParams.data.important,
|
|
653
|
-
limit: queryParams.data.limit,
|
|
654
|
-
search: queryParams.data.search
|
|
1597
|
+
tool_slugs: "tools" in queryParams.data ? queryParams.data.tools?.join(",") : void 0,
|
|
1598
|
+
toolkit_slug: "toolkits" in queryParams.data ? queryParams.data.toolkits?.join(",") : void 0,
|
|
1599
|
+
cursor: "cursor" in queryParams.data ? queryParams.data.cursor : void 0,
|
|
1600
|
+
important: "important" in queryParams.data ? queryParams.data.important ? "true" : "false" : void 0,
|
|
1601
|
+
limit: "limit" in queryParams.data ? queryParams.data.limit?.toString() : void 0,
|
|
1602
|
+
search: "search" in queryParams.data ? queryParams.data.search : void 0
|
|
655
1603
|
});
|
|
656
1604
|
if (!tools) {
|
|
657
1605
|
return [];
|
|
658
1606
|
}
|
|
659
1607
|
const caseTransformedTools = tools.items.map((tool) => this.transformToolCases(tool));
|
|
660
1608
|
const customTools = await this.customTools.getCustomTools({
|
|
661
|
-
toolSlugs: queryParams.data.tools
|
|
1609
|
+
toolSlugs: "tools" in queryParams.data ? queryParams.data.tools : void 0
|
|
662
1610
|
});
|
|
663
1611
|
let modifiedTools = [...caseTransformedTools, ...customTools];
|
|
664
1612
|
if (modifier) {
|
|
665
1613
|
if (typeof modifier === "function") {
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
1614
|
+
const modifiedPromises = modifiedTools.map(
|
|
1615
|
+
(tool) => modifier(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
|
|
1616
|
+
);
|
|
1617
|
+
modifiedTools = await Promise.all(modifiedPromises);
|
|
669
1618
|
} else {
|
|
670
1619
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
671
1620
|
}
|
|
@@ -686,23 +1635,28 @@ var Tools = class {
|
|
|
686
1635
|
async getRawComposioToolBySlug(userId, slug, modifier) {
|
|
687
1636
|
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
688
1637
|
if (customTool) {
|
|
1638
|
+
logger_default.debug(`Found ${slug} to be a custom tool`, JSON.stringify(customTool, null, 2));
|
|
689
1639
|
return customTool;
|
|
1640
|
+
} else {
|
|
1641
|
+
logger_default.debug(`Tool ${slug} is not a custom tool. Fetching from Composio API`);
|
|
690
1642
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
1643
|
+
let tool;
|
|
1644
|
+
try {
|
|
1645
|
+
tool = await this.client.tools.retrieve(slug);
|
|
1646
|
+
} catch (error) {
|
|
1647
|
+
throw new ComposioToolNotFoundError(`Unable to retrieve tool with slug ${slug}`, {
|
|
1648
|
+
cause: error
|
|
1649
|
+
});
|
|
696
1650
|
}
|
|
697
|
-
let
|
|
1651
|
+
let modifiedTool = this.transformToolCases(tool);
|
|
698
1652
|
if (modifier) {
|
|
699
1653
|
if (typeof modifier === "function") {
|
|
700
|
-
|
|
1654
|
+
modifiedTool = await modifier(slug, modifiedTool.toolkit?.slug ?? "unknown", modifiedTool);
|
|
701
1655
|
} else {
|
|
702
1656
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
703
1657
|
}
|
|
704
1658
|
}
|
|
705
|
-
return
|
|
1659
|
+
return modifiedTool;
|
|
706
1660
|
}
|
|
707
1661
|
/**
|
|
708
1662
|
* Get a tool or list of tools based on the provided arguments.
|
|
@@ -716,17 +1670,19 @@ var Tools = class {
|
|
|
716
1670
|
async get(userId, arg2, options) {
|
|
717
1671
|
const executeToolFn = this.createExecuteToolFn(userId, options);
|
|
718
1672
|
if (typeof arg2 === "string") {
|
|
719
|
-
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.
|
|
1673
|
+
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifySchema);
|
|
720
1674
|
return this.provider.wrapTools([tool], executeToolFn);
|
|
721
1675
|
} else {
|
|
722
|
-
const tools = await this.getRawComposioTools(userId, arg2, options?.
|
|
1676
|
+
const tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
|
|
723
1677
|
return this.provider.wrapTools(tools, executeToolFn);
|
|
724
1678
|
}
|
|
725
1679
|
}
|
|
726
1680
|
/**
|
|
727
1681
|
* @internal
|
|
1682
|
+
* @description
|
|
728
1683
|
* Creates a function that executes a tool.
|
|
729
|
-
* This function is used by agentic
|
|
1684
|
+
* This function is used by agentic toolsets to execute the tool
|
|
1685
|
+
*
|
|
730
1686
|
* @param {string} userId - The user id
|
|
731
1687
|
* @param {ExecuteToolModifiers} modifiers - The modifiers to be applied to the tool
|
|
732
1688
|
* @returns {ExecuteToolFn} The execute tool function
|
|
@@ -753,26 +1709,19 @@ var Tools = class {
|
|
|
753
1709
|
* @returns The response from the tool execution
|
|
754
1710
|
*/
|
|
755
1711
|
async handleCustomToolExecution(tool, body, modifiers) {
|
|
756
|
-
if (modifiers?.
|
|
757
|
-
if (typeof modifiers.
|
|
758
|
-
body = modifiers.
|
|
1712
|
+
if (modifiers?.beforeExecute) {
|
|
1713
|
+
if (typeof modifiers.beforeExecute === "function") {
|
|
1714
|
+
body = await modifiers.beforeExecute(tool.slug, "unknown", body);
|
|
759
1715
|
} else {
|
|
760
|
-
throw new ComposioInvalidModifierError(
|
|
761
|
-
"Invalid beforeToolExecute modifier. Not a function."
|
|
762
|
-
);
|
|
1716
|
+
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
763
1717
|
}
|
|
764
1718
|
}
|
|
765
|
-
let result = await this.customTools.executeCustomTool(tool.slug, body
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
if (modifiers?.afterToolExecute) {
|
|
770
|
-
if (typeof modifiers.afterToolExecute === "function") {
|
|
771
|
-
result = modifiers.afterToolExecute(tool.slug, "unkown", result);
|
|
1719
|
+
let result = await this.customTools.executeCustomTool(tool.slug, body);
|
|
1720
|
+
if (modifiers?.afterExecute) {
|
|
1721
|
+
if (typeof modifiers.afterExecute === "function") {
|
|
1722
|
+
result = await modifiers.afterExecute(tool.slug, "unknown", result);
|
|
772
1723
|
} else {
|
|
773
|
-
throw new ComposioInvalidModifierError(
|
|
774
|
-
"Invalid afterToolExecute modifier. Not a function."
|
|
775
|
-
);
|
|
1724
|
+
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
776
1725
|
}
|
|
777
1726
|
}
|
|
778
1727
|
return result;
|
|
@@ -786,13 +1735,11 @@ var Tools = class {
|
|
|
786
1735
|
* @returns The response from the tool execution
|
|
787
1736
|
*/
|
|
788
1737
|
async handleComposioToolExecution(tool, body, modifiers) {
|
|
789
|
-
if (modifiers?.
|
|
790
|
-
if (typeof modifiers.
|
|
791
|
-
body = modifiers.
|
|
1738
|
+
if (modifiers?.beforeExecute) {
|
|
1739
|
+
if (typeof modifiers.beforeExecute === "function") {
|
|
1740
|
+
body = await modifiers.beforeExecute(tool.slug, tool.toolkit?.slug ?? "unknown", body);
|
|
792
1741
|
} else {
|
|
793
|
-
throw new ComposioInvalidModifierError(
|
|
794
|
-
"Invalid beforeToolExecute modifier. Not a function."
|
|
795
|
-
);
|
|
1742
|
+
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
796
1743
|
}
|
|
797
1744
|
}
|
|
798
1745
|
let connectedAccountId = body.connectedAccountId;
|
|
@@ -809,13 +1756,11 @@ var Tools = class {
|
|
|
809
1756
|
text: body.text
|
|
810
1757
|
});
|
|
811
1758
|
result = this.transformToolExecuteResponse(result);
|
|
812
|
-
if (modifiers?.
|
|
813
|
-
if (typeof modifiers.
|
|
814
|
-
result = modifiers.
|
|
1759
|
+
if (modifiers?.afterExecute) {
|
|
1760
|
+
if (typeof modifiers.afterExecute === "function") {
|
|
1761
|
+
result = await modifiers.afterExecute(tool.slug, tool.toolkit?.slug ?? "unknown", result);
|
|
815
1762
|
} else {
|
|
816
|
-
throw new ComposioInvalidModifierError(
|
|
817
|
-
"Invalid afterToolExecute modifier. Not a function."
|
|
818
|
-
);
|
|
1763
|
+
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
819
1764
|
}
|
|
820
1765
|
}
|
|
821
1766
|
return result;
|
|
@@ -848,11 +1793,11 @@ var Tools = class {
|
|
|
848
1793
|
* userId: 'default',
|
|
849
1794
|
* arguments: { owner: 'composio', repo: 'sdk' }
|
|
850
1795
|
* }, {
|
|
851
|
-
*
|
|
1796
|
+
* beforeExecute: (toolSlug, toolkitSlug, params) => {
|
|
852
1797
|
* // Modify params before execution
|
|
853
1798
|
* return params;
|
|
854
1799
|
* },
|
|
855
|
-
*
|
|
1800
|
+
* afterExecute: (toolSlug, toolkitSlug, result) => {
|
|
856
1801
|
* // Transform result after execution
|
|
857
1802
|
* return result;
|
|
858
1803
|
* }
|
|
@@ -877,18 +1822,28 @@ var Tools = class {
|
|
|
877
1822
|
return this.handleComposioToolExecution(composioTool, body, modifiers);
|
|
878
1823
|
}
|
|
879
1824
|
} catch (error) {
|
|
880
|
-
throw new ComposioToolExecutionError(
|
|
881
|
-
|
|
882
|
-
|
|
1825
|
+
throw new ComposioToolExecutionError(`Error executing tool ${slug}`, {
|
|
1826
|
+
originalError: error,
|
|
1827
|
+
meta: {
|
|
1828
|
+
toolSlug: slug,
|
|
1829
|
+
body
|
|
1830
|
+
}
|
|
883
1831
|
});
|
|
884
1832
|
}
|
|
885
1833
|
}
|
|
886
1834
|
/**
|
|
887
1835
|
* Fetches the list of all available tools in the Composio SDK.
|
|
888
1836
|
*
|
|
889
|
-
* This method is mostly used by the CLI
|
|
1837
|
+
* This method is mostly used by the CLI to get the list of tools.
|
|
890
1838
|
* No filtering is done on the tools, the list is cached in the backend, no further optimization is required.
|
|
891
|
-
* @returns {
|
|
1839
|
+
* @returns {Promise<ToolRetrieveEnumResponse>} The complete list of all available tools with their metadata
|
|
1840
|
+
*
|
|
1841
|
+
* @example
|
|
1842
|
+
* ```typescript
|
|
1843
|
+
* // Get all available tools as an enum
|
|
1844
|
+
* const toolsEnum = await composio.tools.getToolsEnum();
|
|
1845
|
+
* console.log(toolsEnum.items);
|
|
1846
|
+
* ```
|
|
892
1847
|
*/
|
|
893
1848
|
async getToolsEnum() {
|
|
894
1849
|
return this.client.tools.retrieveEnum();
|
|
@@ -900,18 +1855,69 @@ var Tools = class {
|
|
|
900
1855
|
*
|
|
901
1856
|
* @param {string} slug - The ID of the tool to find input for
|
|
902
1857
|
* @param {ToolGetInputParams} body - The parameters to be passed to the tool
|
|
903
|
-
* @returns
|
|
1858
|
+
* @returns {Promise<ToolGetInputResponse>} The input parameters schema for the specified tool
|
|
1859
|
+
*
|
|
1860
|
+
* @example
|
|
1861
|
+
* ```typescript
|
|
1862
|
+
* // Get input parameters for a specific tool
|
|
1863
|
+
* const inputParams = await composio.tools.getInput('GITHUB_CREATE_ISSUE', {
|
|
1864
|
+
* userId: 'default'
|
|
1865
|
+
* });
|
|
1866
|
+
* console.log(inputParams.schema);
|
|
1867
|
+
* ```
|
|
904
1868
|
*/
|
|
905
1869
|
async getInput(slug, body) {
|
|
906
1870
|
return this.client.tools.getInput(slug, body);
|
|
907
1871
|
}
|
|
908
1872
|
/**
|
|
909
|
-
* Proxies a custom request to a toolkit/integration
|
|
910
|
-
*
|
|
911
|
-
*
|
|
1873
|
+
* Proxies a custom request to a toolkit/integration.
|
|
1874
|
+
*
|
|
1875
|
+
* This method allows sending custom requests to a specific toolkit or integration
|
|
1876
|
+
* when you need more flexibility than the standard tool execution methods provide.
|
|
1877
|
+
*
|
|
1878
|
+
* @param {ToolProxyParams} body - The parameters for the proxy request including toolkit slug and custom data
|
|
1879
|
+
* @returns {Promise<ToolProxyResponse>} The response from the proxied request
|
|
1880
|
+
*
|
|
1881
|
+
* @example
|
|
1882
|
+
* ```typescript
|
|
1883
|
+
* // Send a custom request to a toolkit
|
|
1884
|
+
* const response = await composio.tools.proxyExecute({
|
|
1885
|
+
* toolkitSlug: 'github',
|
|
1886
|
+
* userId: 'default',
|
|
1887
|
+
* data: {
|
|
1888
|
+
* endpoint: '/repos/owner/repo/issues',
|
|
1889
|
+
* method: 'GET'
|
|
1890
|
+
* }
|
|
1891
|
+
* });
|
|
1892
|
+
* console.log(response.data);
|
|
1893
|
+
* ```
|
|
912
1894
|
*/
|
|
913
1895
|
async proxyExecute(body) {
|
|
914
|
-
|
|
1896
|
+
const toolProxyParams = ToolProxyParamsSchema.safeParse(body);
|
|
1897
|
+
if (!toolProxyParams.success) {
|
|
1898
|
+
throw new ValidationError("Invalid tool proxy parameters", { cause: toolProxyParams.error });
|
|
1899
|
+
}
|
|
1900
|
+
const parameters = [];
|
|
1901
|
+
const parameterTypes = {
|
|
1902
|
+
header: "header",
|
|
1903
|
+
query: "query"
|
|
1904
|
+
};
|
|
1905
|
+
if (toolProxyParams.data.parameters) {
|
|
1906
|
+
parameters.push(
|
|
1907
|
+
...Object.entries(toolProxyParams.data.parameters).map(([key, value]) => ({
|
|
1908
|
+
name: key,
|
|
1909
|
+
type: value.in === "header" ? parameterTypes.header : parameterTypes.query,
|
|
1910
|
+
value: value.value.toString()
|
|
1911
|
+
}))
|
|
1912
|
+
);
|
|
1913
|
+
}
|
|
1914
|
+
return this.client.tools.proxy({
|
|
1915
|
+
endpoint: toolProxyParams.data.endpoint,
|
|
1916
|
+
method: toolProxyParams.data.method,
|
|
1917
|
+
body: toolProxyParams.data.body,
|
|
1918
|
+
connected_account_id: toolProxyParams.data.connectedAccountId,
|
|
1919
|
+
parameters
|
|
1920
|
+
});
|
|
915
1921
|
}
|
|
916
1922
|
/**
|
|
917
1923
|
* Creates a custom tool that can be used within the Composio SDK.
|
|
@@ -924,120 +1930,130 @@ var Tools = class {
|
|
|
924
1930
|
*
|
|
925
1931
|
* @example
|
|
926
1932
|
* ```typescript
|
|
927
|
-
*
|
|
1933
|
+
* // creating a custom tool with a toolkit
|
|
1934
|
+
* await composio.tools.createCustomTool({
|
|
928
1935
|
* name: 'My Custom Tool',
|
|
929
1936
|
* description: 'A custom tool that does something specific',
|
|
930
1937
|
* slug: 'MY_CUSTOM_TOOL',
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
934
|
-
*
|
|
935
|
-
*
|
|
936
|
-
*
|
|
937
|
-
*
|
|
938
|
-
* outputParameters: {
|
|
939
|
-
* result: {
|
|
940
|
-
* type: 'string',
|
|
941
|
-
* description: 'The result of the operation'
|
|
942
|
-
* }
|
|
943
|
-
* },
|
|
944
|
-
* handler: async (params, context) => {
|
|
1938
|
+
* userId: 'default',
|
|
1939
|
+
* connectedAccountId: '123',
|
|
1940
|
+
* toolkitSlug: 'github',
|
|
1941
|
+
* inputParameters: z.object({
|
|
1942
|
+
* param1: z.string().describe('First parameter'),
|
|
1943
|
+
* }),
|
|
1944
|
+
* execute: async (input, authCredentials, executeToolRequest) => {
|
|
945
1945
|
* // Custom logic here
|
|
946
1946
|
* return { data: { result: 'Success!' } };
|
|
947
1947
|
* }
|
|
948
1948
|
* });
|
|
949
1949
|
* ```
|
|
1950
|
+
*
|
|
1951
|
+
* @example
|
|
1952
|
+
* ```typescript
|
|
1953
|
+
* // creating a custom tool without a toolkit
|
|
1954
|
+
* await composio.tools.createCustomTool({
|
|
1955
|
+
* name: 'My Custom Tool',
|
|
1956
|
+
* description: 'A custom tool that does something specific',
|
|
1957
|
+
* slug: 'MY_CUSTOM_TOOL',
|
|
1958
|
+
* inputParameters: z.object({
|
|
1959
|
+
* param1: z.string().describe('First parameter'),
|
|
1960
|
+
* }),
|
|
1961
|
+
* execute: async (input) => {
|
|
1962
|
+
* // Custom logic here
|
|
1963
|
+
* return { data: { result: 'Success!' } };
|
|
1964
|
+
* }
|
|
1965
|
+
* });
|
|
950
1966
|
*/
|
|
951
1967
|
async createCustomTool(body) {
|
|
952
1968
|
return this.customTools.createTool(body);
|
|
953
1969
|
}
|
|
954
1970
|
};
|
|
955
1971
|
|
|
1972
|
+
// src/models/Toolkits.ts
|
|
1973
|
+
import ComposioClient2 from "@composio/client";
|
|
1974
|
+
|
|
956
1975
|
// src/types/toolkit.types.ts
|
|
957
|
-
import { z as
|
|
958
|
-
var ToolkitMangedByEnumSchema =
|
|
959
|
-
var ToolkitSortByEnumSchema =
|
|
960
|
-
var ToolkitsListParamsSchema =
|
|
961
|
-
category:
|
|
962
|
-
isLocal:
|
|
1976
|
+
import { z as z3 } from "zod";
|
|
1977
|
+
var ToolkitMangedByEnumSchema = z3.enum(["all", "composio", "project"]);
|
|
1978
|
+
var ToolkitSortByEnumSchema = z3.enum(["usage", "alphabetically"]);
|
|
1979
|
+
var ToolkitsListParamsSchema = z3.object({
|
|
1980
|
+
category: z3.string().optional(),
|
|
1981
|
+
isLocal: z3.boolean().optional(),
|
|
963
1982
|
managedBy: ToolkitMangedByEnumSchema.optional(),
|
|
964
1983
|
sortBy: ToolkitSortByEnumSchema.optional()
|
|
965
1984
|
});
|
|
966
|
-
var ToolKitMetaSchema =
|
|
967
|
-
categories:
|
|
968
|
-
|
|
969
|
-
slug:
|
|
970
|
-
name:
|
|
1985
|
+
var ToolKitMetaSchema = z3.object({
|
|
1986
|
+
categories: z3.array(
|
|
1987
|
+
z3.object({
|
|
1988
|
+
slug: z3.string(),
|
|
1989
|
+
name: z3.string()
|
|
971
1990
|
})
|
|
972
1991
|
).optional(),
|
|
973
|
-
appUrl:
|
|
974
|
-
createdAt:
|
|
975
|
-
description:
|
|
976
|
-
logo:
|
|
977
|
-
toolsCount:
|
|
978
|
-
triggersCount:
|
|
979
|
-
updatedAt:
|
|
1992
|
+
appUrl: z3.string().optional(),
|
|
1993
|
+
createdAt: z3.string().optional(),
|
|
1994
|
+
description: z3.string().optional(),
|
|
1995
|
+
logo: z3.string().optional(),
|
|
1996
|
+
toolsCount: z3.number().optional(),
|
|
1997
|
+
triggersCount: z3.number().optional(),
|
|
1998
|
+
updatedAt: z3.string().optional()
|
|
980
1999
|
});
|
|
981
|
-
var ToolKitItemSchema =
|
|
982
|
-
name:
|
|
983
|
-
slug:
|
|
2000
|
+
var ToolKitItemSchema = z3.object({
|
|
2001
|
+
name: z3.string(),
|
|
2002
|
+
slug: z3.string(),
|
|
984
2003
|
meta: ToolKitMetaSchema,
|
|
985
|
-
isLocalToolkit:
|
|
986
|
-
authSchemes:
|
|
987
|
-
composioManagedAuthSchemes:
|
|
988
|
-
noAuth:
|
|
2004
|
+
isLocalToolkit: z3.boolean(),
|
|
2005
|
+
authSchemes: z3.array(z3.string()).optional(),
|
|
2006
|
+
composioManagedAuthSchemes: z3.array(z3.string()).optional(),
|
|
2007
|
+
noAuth: z3.boolean().optional()
|
|
989
2008
|
});
|
|
990
|
-
var ToolKitListResponseSchema =
|
|
991
|
-
items:
|
|
992
|
-
nextCursor:
|
|
993
|
-
totalPages:
|
|
2009
|
+
var ToolKitListResponseSchema = z3.object({
|
|
2010
|
+
items: z3.array(ToolKitItemSchema),
|
|
2011
|
+
nextCursor: z3.string().nullable(),
|
|
2012
|
+
totalPages: z3.number()
|
|
994
2013
|
});
|
|
995
|
-
var ToolkitAuthFieldSchema =
|
|
996
|
-
name:
|
|
997
|
-
displayName:
|
|
998
|
-
type:
|
|
999
|
-
default:
|
|
2014
|
+
var ToolkitAuthFieldSchema = z3.object({
|
|
2015
|
+
name: z3.string(),
|
|
2016
|
+
displayName: z3.string(),
|
|
2017
|
+
type: z3.string(),
|
|
2018
|
+
default: z3.string().nullable().optional()
|
|
1000
2019
|
});
|
|
1001
|
-
var ToolkitAuthConfigDetailsSchema =
|
|
1002
|
-
name:
|
|
1003
|
-
mode:
|
|
1004
|
-
fields:
|
|
1005
|
-
authConfigCreation:
|
|
1006
|
-
optional:
|
|
1007
|
-
required:
|
|
2020
|
+
var ToolkitAuthConfigDetailsSchema = z3.object({
|
|
2021
|
+
name: z3.string(),
|
|
2022
|
+
mode: z3.string(),
|
|
2023
|
+
fields: z3.object({
|
|
2024
|
+
authConfigCreation: z3.object({
|
|
2025
|
+
optional: z3.array(ToolkitAuthFieldSchema),
|
|
2026
|
+
required: z3.array(ToolkitAuthFieldSchema)
|
|
1008
2027
|
}),
|
|
1009
|
-
connectedAccountInitiation:
|
|
1010
|
-
optional:
|
|
1011
|
-
required:
|
|
2028
|
+
connectedAccountInitiation: z3.object({
|
|
2029
|
+
optional: z3.array(ToolkitAuthFieldSchema),
|
|
2030
|
+
required: z3.array(ToolkitAuthFieldSchema)
|
|
1012
2031
|
})
|
|
1013
2032
|
}),
|
|
1014
|
-
proxy:
|
|
1015
|
-
baseUrl:
|
|
2033
|
+
proxy: z3.object({
|
|
2034
|
+
baseUrl: z3.string().optional()
|
|
1016
2035
|
}).optional()
|
|
1017
2036
|
});
|
|
1018
|
-
var ToolkitRetrieveResponseSchema =
|
|
1019
|
-
name:
|
|
1020
|
-
slug:
|
|
2037
|
+
var ToolkitRetrieveResponseSchema = z3.object({
|
|
2038
|
+
name: z3.string(),
|
|
2039
|
+
slug: z3.string(),
|
|
1021
2040
|
meta: ToolKitMetaSchema,
|
|
1022
|
-
isLocalToolkit:
|
|
1023
|
-
composioManagedAuthSchemes:
|
|
1024
|
-
authConfigDetails:
|
|
2041
|
+
isLocalToolkit: z3.boolean(),
|
|
2042
|
+
composioManagedAuthSchemes: z3.array(z3.string()).optional(),
|
|
2043
|
+
authConfigDetails: z3.array(ToolkitAuthConfigDetailsSchema).optional()
|
|
1025
2044
|
});
|
|
1026
|
-
var ToolkitCategorySchema =
|
|
1027
|
-
id:
|
|
1028
|
-
name:
|
|
2045
|
+
var ToolkitCategorySchema = z3.object({
|
|
2046
|
+
id: z3.string(),
|
|
2047
|
+
name: z3.string()
|
|
1029
2048
|
});
|
|
1030
|
-
var ToolkitRetrieveCategoriesResponseSchema =
|
|
1031
|
-
items:
|
|
1032
|
-
nextCursor:
|
|
1033
|
-
totalPages:
|
|
2049
|
+
var ToolkitRetrieveCategoriesResponseSchema = z3.object({
|
|
2050
|
+
items: z3.array(ToolkitCategorySchema),
|
|
2051
|
+
nextCursor: z3.string().nullable(),
|
|
2052
|
+
totalPages: z3.number()
|
|
1034
2053
|
});
|
|
1035
2054
|
|
|
1036
|
-
// src/models/Toolkits.ts
|
|
1037
|
-
import { ZodError as ZodError3 } from "zod";
|
|
1038
|
-
|
|
1039
2055
|
// src/types/authConfigs.types.ts
|
|
1040
|
-
import { z as
|
|
2056
|
+
import { z as z4 } from "zod";
|
|
1041
2057
|
var AuthConfigTypes = {
|
|
1042
2058
|
CUSTOM: "use_custom_auth",
|
|
1043
2059
|
COMPOSIO_MANAGED: "use_composio_managed_auth"
|
|
@@ -1057,7 +2073,7 @@ var AuthSchemeTypes = {
|
|
|
1057
2073
|
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1058
2074
|
SNOWFLAKE: "SNOWFLAKE"
|
|
1059
2075
|
};
|
|
1060
|
-
var AuthSchemeEnum =
|
|
2076
|
+
var AuthSchemeEnum = z4.enum([
|
|
1061
2077
|
"OAUTH2",
|
|
1062
2078
|
"OAUTH1",
|
|
1063
2079
|
"OAUTH1A",
|
|
@@ -1072,67 +2088,67 @@ var AuthSchemeEnum = z3.enum([
|
|
|
1072
2088
|
"CALCOM_AUTH",
|
|
1073
2089
|
"SNOWFLAKE"
|
|
1074
2090
|
]);
|
|
1075
|
-
var CreateCustomAuthConfigParamsSchema =
|
|
1076
|
-
type:
|
|
1077
|
-
name:
|
|
1078
|
-
credentials:
|
|
2091
|
+
var CreateCustomAuthConfigParamsSchema = z4.object({
|
|
2092
|
+
type: z4.literal("use_custom_auth"),
|
|
2093
|
+
name: z4.string().optional(),
|
|
2094
|
+
credentials: z4.record(z4.string(), z4.union([z4.string(), z4.number(), z4.boolean()])),
|
|
1079
2095
|
authScheme: AuthSchemeEnum
|
|
1080
2096
|
});
|
|
1081
|
-
var CreateComposioManagedAuthConfigParamsSchema =
|
|
1082
|
-
type:
|
|
1083
|
-
name:
|
|
1084
|
-
credentials:
|
|
2097
|
+
var CreateComposioManagedAuthConfigParamsSchema = z4.object({
|
|
2098
|
+
type: z4.literal("use_composio_managed_auth"),
|
|
2099
|
+
name: z4.string().optional(),
|
|
2100
|
+
credentials: z4.record(z4.string(), z4.union([z4.string(), z4.number(), z4.boolean()])).optional()
|
|
1085
2101
|
});
|
|
1086
|
-
var CreateAuthConfigParamsSchema =
|
|
2102
|
+
var CreateAuthConfigParamsSchema = z4.discriminatedUnion("type", [
|
|
1087
2103
|
CreateCustomAuthConfigParamsSchema,
|
|
1088
2104
|
CreateComposioManagedAuthConfigParamsSchema
|
|
1089
2105
|
]);
|
|
1090
|
-
var CreateAuthConfigResponseSchema =
|
|
1091
|
-
id:
|
|
1092
|
-
authScheme:
|
|
1093
|
-
isComposioManaged:
|
|
1094
|
-
toolkit:
|
|
2106
|
+
var CreateAuthConfigResponseSchema = z4.object({
|
|
2107
|
+
id: z4.string(),
|
|
2108
|
+
authScheme: z4.string(),
|
|
2109
|
+
isComposioManaged: z4.boolean(),
|
|
2110
|
+
toolkit: z4.string()
|
|
1095
2111
|
});
|
|
1096
|
-
var AuthConfigRetrieveResponseSchema =
|
|
1097
|
-
id:
|
|
1098
|
-
name:
|
|
1099
|
-
toolkit:
|
|
1100
|
-
logo:
|
|
1101
|
-
slug:
|
|
2112
|
+
var AuthConfigRetrieveResponseSchema = z4.object({
|
|
2113
|
+
id: z4.string(),
|
|
2114
|
+
name: z4.string(),
|
|
2115
|
+
toolkit: z4.object({
|
|
2116
|
+
logo: z4.string(),
|
|
2117
|
+
slug: z4.string()
|
|
1102
2118
|
}),
|
|
1103
|
-
noOfConnections:
|
|
1104
|
-
status:
|
|
1105
|
-
uuid:
|
|
2119
|
+
noOfConnections: z4.number(),
|
|
2120
|
+
status: z4.enum(["ENABLED", "DISABLED"]),
|
|
2121
|
+
uuid: z4.string(),
|
|
1106
2122
|
authScheme: AuthSchemeEnum.optional(),
|
|
1107
|
-
credentials:
|
|
1108
|
-
expectedInputFields:
|
|
1109
|
-
isComposioManaged:
|
|
1110
|
-
createdBy:
|
|
1111
|
-
createdAt:
|
|
1112
|
-
lastUpdatedAt:
|
|
2123
|
+
credentials: z4.record(z4.string(), z4.unknown()).optional(),
|
|
2124
|
+
expectedInputFields: z4.array(z4.unknown()).optional(),
|
|
2125
|
+
isComposioManaged: z4.boolean().optional(),
|
|
2126
|
+
createdBy: z4.string().optional(),
|
|
2127
|
+
createdAt: z4.string().optional(),
|
|
2128
|
+
lastUpdatedAt: z4.string().optional()
|
|
1113
2129
|
});
|
|
1114
|
-
var AuthConfigListParamsSchema =
|
|
1115
|
-
cursor:
|
|
1116
|
-
isComposioManaged:
|
|
1117
|
-
limit:
|
|
1118
|
-
|
|
2130
|
+
var AuthConfigListParamsSchema = z4.object({
|
|
2131
|
+
cursor: z4.string().optional(),
|
|
2132
|
+
isComposioManaged: z4.boolean().optional(),
|
|
2133
|
+
limit: z4.number().optional(),
|
|
2134
|
+
toolkit: z4.string().optional()
|
|
1119
2135
|
});
|
|
1120
|
-
var AuthConfigListResponseSchema =
|
|
1121
|
-
items:
|
|
1122
|
-
nextCursor:
|
|
1123
|
-
totalPages:
|
|
2136
|
+
var AuthConfigListResponseSchema = z4.object({
|
|
2137
|
+
items: z4.array(AuthConfigRetrieveResponseSchema),
|
|
2138
|
+
nextCursor: z4.string().nullable(),
|
|
2139
|
+
totalPages: z4.number()
|
|
1124
2140
|
});
|
|
1125
|
-
var AuthCustomConfigUpdateParamsSchema =
|
|
1126
|
-
credentials:
|
|
1127
|
-
type:
|
|
1128
|
-
restrictToFollowingTools:
|
|
2141
|
+
var AuthCustomConfigUpdateParamsSchema = z4.object({
|
|
2142
|
+
credentials: z4.record(z4.string(), z4.union([z4.string(), z4.unknown()])),
|
|
2143
|
+
type: z4.literal("custom"),
|
|
2144
|
+
restrictToFollowingTools: z4.array(z4.string()).optional()
|
|
1129
2145
|
});
|
|
1130
|
-
var AuthDefaultConfigUpdateParamsSchema =
|
|
1131
|
-
scopes:
|
|
1132
|
-
type:
|
|
1133
|
-
restrictToFollowingTools:
|
|
2146
|
+
var AuthDefaultConfigUpdateParamsSchema = z4.object({
|
|
2147
|
+
scopes: z4.string(),
|
|
2148
|
+
type: z4.literal("default"),
|
|
2149
|
+
restrictToFollowingTools: z4.array(z4.string()).optional()
|
|
1134
2150
|
});
|
|
1135
|
-
var AuthConfigUpdateParamsSchema =
|
|
2151
|
+
var AuthConfigUpdateParamsSchema = z4.discriminatedUnion("type", [
|
|
1136
2152
|
AuthCustomConfigUpdateParamsSchema,
|
|
1137
2153
|
AuthDefaultConfigUpdateParamsSchema
|
|
1138
2154
|
]);
|
|
@@ -1142,6 +2158,7 @@ var AuthConfigs = class {
|
|
|
1142
2158
|
client;
|
|
1143
2159
|
constructor(client) {
|
|
1144
2160
|
this.client = client;
|
|
2161
|
+
telemetry.instrument(this);
|
|
1145
2162
|
}
|
|
1146
2163
|
/**
|
|
1147
2164
|
* Protected getter for the client instance.
|
|
@@ -1183,7 +2200,9 @@ var AuthConfigs = class {
|
|
|
1183
2200
|
lastUpdatedAt: authConfig.last_updated_at
|
|
1184
2201
|
});
|
|
1185
2202
|
if (result.error) {
|
|
1186
|
-
throw new ValidationError(
|
|
2203
|
+
throw new ValidationError("Failed to parse auth config response", {
|
|
2204
|
+
cause: result.error
|
|
2205
|
+
});
|
|
1187
2206
|
}
|
|
1188
2207
|
return result.data;
|
|
1189
2208
|
}
|
|
@@ -1204,7 +2223,7 @@ var AuthConfigs = class {
|
|
|
1204
2223
|
*
|
|
1205
2224
|
* // List auth configs for a specific toolkit
|
|
1206
2225
|
* const githubConfigs = await composio.authConfigs.list({
|
|
1207
|
-
*
|
|
2226
|
+
* toolkit: 'github'
|
|
1208
2227
|
* });
|
|
1209
2228
|
*
|
|
1210
2229
|
* // List Composio-managed auth configs
|
|
@@ -1218,8 +2237,8 @@ var AuthConfigs = class {
|
|
|
1218
2237
|
const result = await this.client.authConfigs.list({
|
|
1219
2238
|
cursor: parsedQuery?.cursor,
|
|
1220
2239
|
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1221
|
-
limit: parsedQuery?.limit
|
|
1222
|
-
toolkit_slug: parsedQuery?.
|
|
2240
|
+
limit: parsedQuery?.limit,
|
|
2241
|
+
toolkit_slug: parsedQuery?.toolkit
|
|
1223
2242
|
});
|
|
1224
2243
|
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
1225
2244
|
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
@@ -1227,7 +2246,9 @@ var AuthConfigs = class {
|
|
|
1227
2246
|
totalPages: result.total_pages
|
|
1228
2247
|
});
|
|
1229
2248
|
if (parsedResult.error) {
|
|
1230
|
-
throw new ValidationError(
|
|
2249
|
+
throw new ValidationError("Failed to parse auth config list response", {
|
|
2250
|
+
cause: parsedResult.error
|
|
2251
|
+
});
|
|
1231
2252
|
}
|
|
1232
2253
|
return parsedResult.data;
|
|
1233
2254
|
}
|
|
@@ -1252,7 +2273,9 @@ var AuthConfigs = class {
|
|
|
1252
2273
|
async create(toolkit, options = { type: "use_composio_managed_auth" }) {
|
|
1253
2274
|
const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
|
|
1254
2275
|
if (parsedOptions.error) {
|
|
1255
|
-
throw new ValidationError(
|
|
2276
|
+
throw new ValidationError("Failed to parse auth config create options", {
|
|
2277
|
+
cause: parsedOptions.error
|
|
2278
|
+
});
|
|
1256
2279
|
}
|
|
1257
2280
|
const result = await this.client.authConfigs.create({
|
|
1258
2281
|
toolkit: {
|
|
@@ -1267,7 +2290,9 @@ var AuthConfigs = class {
|
|
|
1267
2290
|
toolkit: result.toolkit.slug
|
|
1268
2291
|
});
|
|
1269
2292
|
if (parsedResult.error) {
|
|
1270
|
-
throw new ValidationError(
|
|
2293
|
+
throw new ValidationError("Failed to parse auth config create response", {
|
|
2294
|
+
cause: parsedResult.error
|
|
2295
|
+
});
|
|
1271
2296
|
}
|
|
1272
2297
|
return parsedResult.data;
|
|
1273
2298
|
}
|
|
@@ -1327,7 +2352,9 @@ var AuthConfigs = class {
|
|
|
1327
2352
|
async update(nanoid, data) {
|
|
1328
2353
|
const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
|
|
1329
2354
|
if (parsedData.error) {
|
|
1330
|
-
throw new ValidationError(
|
|
2355
|
+
throw new ValidationError("Failed to parse auth config update data", {
|
|
2356
|
+
cause: parsedData.error
|
|
2357
|
+
});
|
|
1331
2358
|
}
|
|
1332
2359
|
return this.client.authConfigs.update(
|
|
1333
2360
|
nanoid,
|
|
@@ -1344,263 +2371,104 @@ var AuthConfigs = class {
|
|
|
1344
2371
|
}
|
|
1345
2372
|
/**
|
|
1346
2373
|
* Deletes an authentication configuration.
|
|
1347
|
-
*
|
|
1348
|
-
* This method permanently removes an auth config from the Composio platform.
|
|
1349
|
-
* This action cannot be undone and will prevent any connected accounts that use
|
|
1350
|
-
* this auth config from functioning.
|
|
1351
|
-
*
|
|
1352
|
-
* @param {string} nanoid - The unique identifier of the auth config to delete
|
|
1353
|
-
* @returns {Promise<AuthConfigDeleteResponse>} The deletion response
|
|
1354
|
-
* @throws {Error} If the auth config doesn't exist or cannot be deleted
|
|
1355
|
-
*
|
|
1356
|
-
* @example
|
|
1357
|
-
* ```typescript
|
|
1358
|
-
* // Delete an auth config
|
|
1359
|
-
* await composio.authConfigs.delete('auth_abc123');
|
|
1360
|
-
* ```
|
|
1361
|
-
*/
|
|
1362
|
-
async delete(nanoid) {
|
|
1363
|
-
return this.client.authConfigs.delete(nanoid);
|
|
1364
|
-
}
|
|
1365
|
-
/**
|
|
1366
|
-
* Updates the status of an authentication configuration.
|
|
1367
|
-
*
|
|
1368
|
-
* This method allows you to enable or disable an auth config. When disabled,
|
|
1369
|
-
* the auth config cannot be used to create new connected accounts or authenticate
|
|
1370
|
-
* with third-party services.
|
|
1371
|
-
*
|
|
1372
|
-
* @param {string} status - The status to set ('ENABLED' or 'DISABLED')
|
|
1373
|
-
* @param {string} nanoid - The unique identifier of the auth config
|
|
1374
|
-
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1375
|
-
* @throws {Error} If the auth config cannot be found or the status cannot be updated
|
|
1376
|
-
*
|
|
1377
|
-
* @example
|
|
1378
|
-
* ```typescript
|
|
1379
|
-
* // Disable an auth config
|
|
1380
|
-
* await composio.authConfigs.updateStatus('DISABLED', 'auth_abc123');
|
|
1381
|
-
*
|
|
1382
|
-
* // Enable an auth config
|
|
1383
|
-
* await composio.authConfigs.updateStatus('ENABLED', 'auth_abc123');
|
|
1384
|
-
* ```
|
|
1385
|
-
*/
|
|
1386
|
-
async updateStatus(status, nanoid) {
|
|
1387
|
-
return this.client.authConfigs.updateStatus(status, { nanoid });
|
|
1388
|
-
}
|
|
1389
|
-
/**
|
|
1390
|
-
* Enables an authentication configuration.
|
|
1391
|
-
*
|
|
1392
|
-
* This is a convenience method that calls updateStatus with 'ENABLED'.
|
|
1393
|
-
* When enabled, the auth config can be used to create new connected accounts
|
|
1394
|
-
* and authenticate with third-party services.
|
|
1395
|
-
*
|
|
1396
|
-
* @param {string} nanoid - The unique identifier of the auth config to enable
|
|
1397
|
-
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1398
|
-
* @throws {Error} If the auth config cannot be found or enabled
|
|
1399
|
-
*
|
|
1400
|
-
* @example
|
|
1401
|
-
* ```typescript
|
|
1402
|
-
* // Enable an auth config
|
|
1403
|
-
* await composio.authConfigs.enable('auth_abc123');
|
|
1404
|
-
* ```
|
|
1405
|
-
*/
|
|
1406
|
-
async enable(nanoid) {
|
|
1407
|
-
return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
|
|
1408
|
-
}
|
|
1409
|
-
/**
|
|
1410
|
-
* Disables an authentication configuration.
|
|
1411
|
-
*
|
|
1412
|
-
* This is a convenience method that calls updateStatus with 'DISABLED'.
|
|
1413
|
-
* When disabled, the auth config cannot be used to create new connected accounts
|
|
1414
|
-
* or authenticate with third-party services, but existing connections may continue to work.
|
|
1415
|
-
*
|
|
1416
|
-
* @param {string} nanoid - The unique identifier of the auth config to disable
|
|
1417
|
-
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1418
|
-
* @throws {Error} If the auth config cannot be found or disabled
|
|
1419
|
-
*
|
|
1420
|
-
* @example
|
|
1421
|
-
* ```typescript
|
|
1422
|
-
* // Disable an auth config
|
|
1423
|
-
* await composio.authConfigs.disable('auth_abc123');
|
|
1424
|
-
* ```
|
|
1425
|
-
*/
|
|
1426
|
-
async disable(nanoid) {
|
|
1427
|
-
return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
|
|
1428
|
-
}
|
|
1429
|
-
};
|
|
1430
|
-
|
|
1431
|
-
// src/errors/AuthConfigErrors.ts
|
|
1432
|
-
var AuthConfigErrorCodes = {
|
|
1433
|
-
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1434
|
-
};
|
|
1435
|
-
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1436
|
-
constructor(message, meta) {
|
|
1437
|
-
super(message, {
|
|
1438
|
-
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1439
|
-
cause: meta,
|
|
1440
|
-
possibleFixes: [
|
|
1441
|
-
"Check if the auth config exists",
|
|
1442
|
-
"Check if the auth config id is correct",
|
|
1443
|
-
"Check if the auth config is enabled"
|
|
1444
|
-
]
|
|
1445
|
-
});
|
|
1446
|
-
this.name = "ComposioAuthConfigNotFoundError";
|
|
1447
|
-
}
|
|
1448
|
-
};
|
|
1449
|
-
|
|
1450
|
-
// src/types/connectedAccounts.types.ts
|
|
1451
|
-
import { z as z4 } from "zod";
|
|
1452
|
-
var ConnectedAccountStatuses = {
|
|
1453
|
-
ACTIVE: "ACTIVE",
|
|
1454
|
-
INACTIVE: "INACTIVE",
|
|
1455
|
-
DELETED: "DELETED",
|
|
1456
|
-
INITIATED: "INITIATED",
|
|
1457
|
-
EXPIRED: "EXPIRED",
|
|
1458
|
-
FAILED: "FAILED"
|
|
1459
|
-
};
|
|
1460
|
-
var ConnectedAccountStatusSchema = z4.enum([
|
|
1461
|
-
ConnectedAccountStatuses.ACTIVE,
|
|
1462
|
-
ConnectedAccountStatuses.INACTIVE,
|
|
1463
|
-
ConnectedAccountStatuses.DELETED,
|
|
1464
|
-
ConnectedAccountStatuses.INITIATED,
|
|
1465
|
-
ConnectedAccountStatuses.EXPIRED,
|
|
1466
|
-
ConnectedAccountStatuses.FAILED
|
|
1467
|
-
]);
|
|
1468
|
-
var CreateConnectedAccountParamsSchema = z4.object({
|
|
1469
|
-
authConfig: z4.object({
|
|
1470
|
-
id: z4.string()
|
|
1471
|
-
}),
|
|
1472
|
-
connection: z4.object({
|
|
1473
|
-
data: z4.record(z4.string(), z4.unknown()).optional(),
|
|
1474
|
-
redirectUrl: z4.string().optional(),
|
|
1475
|
-
userId: z4.string().optional()
|
|
1476
|
-
})
|
|
1477
|
-
});
|
|
1478
|
-
var DefaultCreateConnectedAccountParamsSchema = z4.object({
|
|
1479
|
-
auth_config: z4.object({
|
|
1480
|
-
id: z4.string()
|
|
1481
|
-
}),
|
|
1482
|
-
connection: z4.object({
|
|
1483
|
-
data: z4.record(z4.string(), z4.unknown()).optional(),
|
|
1484
|
-
redirect_uri: z4.string().optional(),
|
|
1485
|
-
user_id: z4.string().optional()
|
|
1486
|
-
})
|
|
1487
|
-
});
|
|
1488
|
-
var CreateConnectedAccountOptionsSchema = z4.object({
|
|
1489
|
-
redirectUrl: z4.string().optional(),
|
|
1490
|
-
data: z4.record(z4.string(), z4.unknown()).optional()
|
|
1491
|
-
});
|
|
1492
|
-
var CreateConnectedAccountResponseSchema = z4.object({
|
|
1493
|
-
id: z4.string(),
|
|
1494
|
-
status: ConnectedAccountStatusSchema,
|
|
1495
|
-
redirectUrl: z4.string().nullable()
|
|
1496
|
-
});
|
|
1497
|
-
var ConnectedAccountAuthSchemes = {
|
|
1498
|
-
OAUTH2: "OAUTH2",
|
|
1499
|
-
OAUTH1: "OAUTH1",
|
|
1500
|
-
OAUTH1A: "OAUTH1A",
|
|
1501
|
-
API_KEY: "API_KEY",
|
|
1502
|
-
BASIC: "BASIC",
|
|
1503
|
-
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
1504
|
-
BEARER_TOKEN: "BEARER_TOKEN",
|
|
1505
|
-
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
1506
|
-
NO_AUTH: "NO_AUTH",
|
|
1507
|
-
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
1508
|
-
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
1509
|
-
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1510
|
-
SNOWFLAKE: "SNOWFLAKE"
|
|
1511
|
-
};
|
|
1512
|
-
var ConnectedAccountAuthSchemesSchema = z4.enum([
|
|
1513
|
-
ConnectedAccountAuthSchemes.OAUTH2,
|
|
1514
|
-
ConnectedAccountAuthSchemes.OAUTH1,
|
|
1515
|
-
ConnectedAccountAuthSchemes.OAUTH1A,
|
|
1516
|
-
ConnectedAccountAuthSchemes.API_KEY,
|
|
1517
|
-
ConnectedAccountAuthSchemes.BASIC,
|
|
1518
|
-
ConnectedAccountAuthSchemes.BILLCOM_AUTH,
|
|
1519
|
-
ConnectedAccountAuthSchemes.BEARER_TOKEN,
|
|
1520
|
-
ConnectedAccountAuthSchemes.GOOGLE_SERVICE_ACCOUNT,
|
|
1521
|
-
ConnectedAccountAuthSchemes.NO_AUTH,
|
|
1522
|
-
ConnectedAccountAuthSchemes.BASIC_WITH_JWT,
|
|
1523
|
-
ConnectedAccountAuthSchemes.COMPOSIO_LINK,
|
|
1524
|
-
ConnectedAccountAuthSchemes.CALCOM_AUTH,
|
|
1525
|
-
ConnectedAccountAuthSchemes.SNOWFLAKE
|
|
1526
|
-
]);
|
|
1527
|
-
var ConnectedAccountAuthConfigSchema = z4.object({
|
|
1528
|
-
id: z4.string(),
|
|
1529
|
-
authScheme: ConnectedAccountAuthSchemesSchema,
|
|
1530
|
-
isComposioManaged: z4.boolean(),
|
|
1531
|
-
isDisabled: z4.boolean()
|
|
1532
|
-
});
|
|
1533
|
-
var ConnectedAccountRetrieveResponseSchema = z4.object({
|
|
1534
|
-
id: z4.string(),
|
|
1535
|
-
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1536
|
-
userId: z4.string(),
|
|
1537
|
-
data: z4.record(z4.string(), z4.unknown()),
|
|
1538
|
-
params: z4.record(z4.string(), z4.unknown()).optional(),
|
|
1539
|
-
status: ConnectedAccountStatusSchema,
|
|
1540
|
-
statusReason: z4.string().nullable(),
|
|
1541
|
-
toolkit: z4.object({
|
|
1542
|
-
slug: z4.string()
|
|
1543
|
-
}),
|
|
1544
|
-
testRequestEndpoint: z4.string().optional(),
|
|
1545
|
-
isDisabled: z4.boolean(),
|
|
1546
|
-
createdAt: z4.string(),
|
|
1547
|
-
updatedAt: z4.string()
|
|
1548
|
-
});
|
|
1549
|
-
var ConnectedAccountListParamsSchema = z4.object({
|
|
1550
|
-
authConfigIds: z4.array(z4.string()).nullable().optional().describe("The auth config ids of the connected accounts"),
|
|
1551
|
-
cursor: z4.number().nullable().optional().describe("The cursor to paginate through the connected accounts"),
|
|
1552
|
-
labels: z4.array(z4.string()).nullable().optional().describe("The labels of the connected accounts"),
|
|
1553
|
-
limit: z4.number().nullable().optional().describe("The limit of the connected accounts to return"),
|
|
1554
|
-
orderBy: z4.enum(["created_at", "updated_at"]).optional().describe("The order by of the connected accounts"),
|
|
1555
|
-
statuses: z4.array(ConnectedAccountStatusSchema).nullable().optional().describe("The statuses of the connected accounts"),
|
|
1556
|
-
toolkitSlugs: z4.array(z4.string()).nullable().optional().describe("The toolkit slugs of the connected accounts"),
|
|
1557
|
-
userIds: z4.array(z4.string()).nullable().optional().describe("The user ids of the connected accounts")
|
|
1558
|
-
});
|
|
1559
|
-
var ConnectedAccountListResponseSchema = z4.object({
|
|
1560
|
-
items: z4.array(ConnectedAccountRetrieveResponseSchema).describe("The list of connected accounts"),
|
|
1561
|
-
nextCursor: z4.string().nullable().describe("The next cursor to paginate through the connected accounts"),
|
|
1562
|
-
totalPages: z4.number().describe("The total number of pages of connected accounts")
|
|
1563
|
-
});
|
|
1564
|
-
|
|
1565
|
-
// src/models/ConnectionRequest.ts
|
|
1566
|
-
import ComposioClient from "@composio/client";
|
|
1567
|
-
import { ZodError as ZodError2 } from "zod";
|
|
1568
|
-
|
|
1569
|
-
// src/errors/ConnectionRequestError.ts
|
|
1570
|
-
var ConnectionRequestErrorCodes = {
|
|
1571
|
-
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1572
|
-
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1573
|
-
};
|
|
1574
|
-
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1575
|
-
constructor(message = "Connection request timed out", meta = {}) {
|
|
1576
|
-
super(message, {
|
|
1577
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
|
|
1578
|
-
meta
|
|
1579
|
-
});
|
|
1580
|
-
this.name = "ConnectionRequestTimeoutError";
|
|
2374
|
+
*
|
|
2375
|
+
* This method permanently removes an auth config from the Composio platform.
|
|
2376
|
+
* This action cannot be undone and will prevent any connected accounts that use
|
|
2377
|
+
* this auth config from functioning.
|
|
2378
|
+
*
|
|
2379
|
+
* @param {string} nanoid - The unique identifier of the auth config to delete
|
|
2380
|
+
* @returns {Promise<AuthConfigDeleteResponse>} The deletion response
|
|
2381
|
+
* @throws {Error} If the auth config doesn't exist or cannot be deleted
|
|
2382
|
+
*
|
|
2383
|
+
* @example
|
|
2384
|
+
* ```typescript
|
|
2385
|
+
* // Delete an auth config
|
|
2386
|
+
* await composio.authConfigs.delete('auth_abc123');
|
|
2387
|
+
* ```
|
|
2388
|
+
*/
|
|
2389
|
+
async delete(nanoid) {
|
|
2390
|
+
return this.client.authConfigs.delete(nanoid);
|
|
1581
2391
|
}
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
2392
|
+
/**
|
|
2393
|
+
* Updates the status of an authentication configuration.
|
|
2394
|
+
*
|
|
2395
|
+
* This method allows you to enable or disable an auth config. When disabled,
|
|
2396
|
+
* the auth config cannot be used to create new connected accounts or authenticate
|
|
2397
|
+
* with third-party services.
|
|
2398
|
+
*
|
|
2399
|
+
* @param {string} status - The status to set ('ENABLED' or 'DISABLED')
|
|
2400
|
+
* @param {string} nanoid - The unique identifier of the auth config
|
|
2401
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
2402
|
+
* @throws {Error} If the auth config cannot be found or the status cannot be updated
|
|
2403
|
+
*
|
|
2404
|
+
* @example
|
|
2405
|
+
* ```typescript
|
|
2406
|
+
* // Disable an auth config
|
|
2407
|
+
* await composio.authConfigs.updateStatus('DISABLED', 'auth_abc123');
|
|
2408
|
+
*
|
|
2409
|
+
* // Enable an auth config
|
|
2410
|
+
* await composio.authConfigs.updateStatus('ENABLED', 'auth_abc123');
|
|
2411
|
+
* ```
|
|
2412
|
+
*/
|
|
2413
|
+
async updateStatus(status, nanoid) {
|
|
2414
|
+
return this.client.authConfigs.updateStatus(status, { nanoid });
|
|
2415
|
+
}
|
|
2416
|
+
/**
|
|
2417
|
+
* Enables an authentication configuration.
|
|
2418
|
+
*
|
|
2419
|
+
* This is a convenience method that calls updateStatus with 'ENABLED'.
|
|
2420
|
+
* When enabled, the auth config can be used to create new connected accounts
|
|
2421
|
+
* and authenticate with third-party services.
|
|
2422
|
+
*
|
|
2423
|
+
* @param {string} nanoid - The unique identifier of the auth config to enable
|
|
2424
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
2425
|
+
* @throws {Error} If the auth config cannot be found or enabled
|
|
2426
|
+
*
|
|
2427
|
+
* @example
|
|
2428
|
+
* ```typescript
|
|
2429
|
+
* // Enable an auth config
|
|
2430
|
+
* await composio.authConfigs.enable('auth_abc123');
|
|
2431
|
+
* ```
|
|
2432
|
+
*/
|
|
2433
|
+
async enable(nanoid) {
|
|
2434
|
+
return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
|
|
2435
|
+
}
|
|
2436
|
+
/**
|
|
2437
|
+
* Disables an authentication configuration.
|
|
2438
|
+
*
|
|
2439
|
+
* This is a convenience method that calls updateStatus with 'DISABLED'.
|
|
2440
|
+
* When disabled, the auth config cannot be used to create new connected accounts
|
|
2441
|
+
* or authenticate with third-party services, but existing connections may continue to work.
|
|
2442
|
+
*
|
|
2443
|
+
* @param {string} nanoid - The unique identifier of the auth config to disable
|
|
2444
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
2445
|
+
* @throws {Error} If the auth config cannot be found or disabled
|
|
2446
|
+
*
|
|
2447
|
+
* @example
|
|
2448
|
+
* ```typescript
|
|
2449
|
+
* // Disable an auth config
|
|
2450
|
+
* await composio.authConfigs.disable('auth_abc123');
|
|
2451
|
+
* ```
|
|
2452
|
+
*/
|
|
2453
|
+
async disable(nanoid) {
|
|
2454
|
+
return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
|
|
1590
2455
|
}
|
|
1591
2456
|
};
|
|
1592
2457
|
|
|
1593
2458
|
// src/models/ConnectionRequest.ts
|
|
2459
|
+
import ComposioClient from "@composio/client";
|
|
2460
|
+
import { ZodError as ZodError3 } from "zod";
|
|
1594
2461
|
var ConnectionRequest = class {
|
|
1595
2462
|
client;
|
|
1596
2463
|
id;
|
|
1597
2464
|
status;
|
|
1598
2465
|
redirectUrl;
|
|
1599
|
-
constructor(client, connectedAccountId,
|
|
2466
|
+
constructor(client, connectedAccountId, status, redirectUrl) {
|
|
1600
2467
|
this.client = client;
|
|
1601
2468
|
this.id = connectedAccountId;
|
|
1602
|
-
this.status =
|
|
2469
|
+
this.status = status || ConnectedAccountStatuses.INITIATED;
|
|
1603
2470
|
this.redirectUrl = redirectUrl;
|
|
2471
|
+
telemetry.instrument(this);
|
|
1604
2472
|
}
|
|
1605
2473
|
/**
|
|
1606
2474
|
* Transforms the raw connected account response from the Composio API to the SDK format.
|
|
@@ -1635,7 +2503,7 @@ var ConnectionRequest = class {
|
|
|
1635
2503
|
return parsedResponse;
|
|
1636
2504
|
} catch (error) {
|
|
1637
2505
|
logger_default.error("Error transforming response", error);
|
|
1638
|
-
if (error instanceof
|
|
2506
|
+
if (error instanceof ZodError3) {
|
|
1639
2507
|
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1640
2508
|
}
|
|
1641
2509
|
throw error;
|
|
@@ -1671,6 +2539,7 @@ var ConnectionRequest = class {
|
|
|
1671
2539
|
try {
|
|
1672
2540
|
const response = await this.client.connectedAccounts.retrieve(this.id);
|
|
1673
2541
|
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
2542
|
+
this.status = ConnectedAccountStatuses.ACTIVE;
|
|
1674
2543
|
return this.transformResponse(response);
|
|
1675
2544
|
}
|
|
1676
2545
|
} catch (error) {
|
|
@@ -1678,7 +2547,9 @@ var ConnectionRequest = class {
|
|
|
1678
2547
|
throw new ComposioConnectedAccountNotFoundError(
|
|
1679
2548
|
`Connected account with id ${this.id} not found`,
|
|
1680
2549
|
{
|
|
1681
|
-
|
|
2550
|
+
meta: {
|
|
2551
|
+
connectedAccountId: this.id
|
|
2552
|
+
}
|
|
1682
2553
|
}
|
|
1683
2554
|
);
|
|
1684
2555
|
} else {
|
|
@@ -1687,14 +2558,14 @@ var ConnectionRequest = class {
|
|
|
1687
2558
|
}
|
|
1688
2559
|
const terminalErrorStates = [
|
|
1689
2560
|
ConnectedAccountStatuses.FAILED,
|
|
1690
|
-
ConnectedAccountStatuses.EXPIRED
|
|
1691
|
-
ConnectedAccountStatuses.DELETED
|
|
2561
|
+
ConnectedAccountStatuses.EXPIRED
|
|
1692
2562
|
];
|
|
1693
2563
|
const start = Date.now();
|
|
1694
2564
|
const pollInterval = 1e3;
|
|
1695
2565
|
while (Date.now() - start < timeout) {
|
|
1696
2566
|
try {
|
|
1697
2567
|
const response = await this.client.connectedAccounts.retrieve(this.id);
|
|
2568
|
+
this.status = response.status;
|
|
1698
2569
|
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1699
2570
|
return this.transformResponse(response);
|
|
1700
2571
|
}
|
|
@@ -1702,10 +2573,12 @@ var ConnectionRequest = class {
|
|
|
1702
2573
|
throw new ConnectionRequestFailedError(
|
|
1703
2574
|
`Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ""}`,
|
|
1704
2575
|
{
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
2576
|
+
meta: {
|
|
2577
|
+
userId: response.user_id,
|
|
2578
|
+
connectedAccountId: this.id,
|
|
2579
|
+
status: response.status,
|
|
2580
|
+
statusReason: response.status_reason
|
|
2581
|
+
}
|
|
1709
2582
|
}
|
|
1710
2583
|
);
|
|
1711
2584
|
}
|
|
@@ -1716,17 +2589,23 @@ var ConnectionRequest = class {
|
|
|
1716
2589
|
}
|
|
1717
2590
|
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${this.id}`);
|
|
1718
2591
|
}
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
2592
|
+
/**
|
|
2593
|
+
* Returns a JSON-serializable representation of the connection request
|
|
2594
|
+
* Excludes the private client property to avoid cyclic reference issues
|
|
2595
|
+
*/
|
|
2596
|
+
toJSON() {
|
|
2597
|
+
return {
|
|
2598
|
+
id: this.id,
|
|
2599
|
+
status: this.status,
|
|
2600
|
+
redirectUrl: this.redirectUrl
|
|
2601
|
+
};
|
|
2602
|
+
}
|
|
2603
|
+
/**
|
|
2604
|
+
* Returns a string representation of the connection request
|
|
2605
|
+
*/
|
|
2606
|
+
toString() {
|
|
2607
|
+
return JSON.stringify(this.toJSON(), null, 2);
|
|
2608
|
+
}
|
|
1730
2609
|
};
|
|
1731
2610
|
|
|
1732
2611
|
// src/models/ConnectedAccounts.ts
|
|
@@ -1734,6 +2613,7 @@ var ConnectedAccounts = class {
|
|
|
1734
2613
|
client;
|
|
1735
2614
|
constructor(client) {
|
|
1736
2615
|
this.client = client;
|
|
2616
|
+
telemetry.instrument(this);
|
|
1737
2617
|
}
|
|
1738
2618
|
transformConnectedAccountRetrieveResponse(response) {
|
|
1739
2619
|
const result = ConnectedAccountRetrieveResponseSchema.safeParse({
|
|
@@ -1753,7 +2633,9 @@ var ConnectedAccounts = class {
|
|
|
1753
2633
|
testRequestEndpoint: response.test_request_endpoint
|
|
1754
2634
|
});
|
|
1755
2635
|
if (!result.success) {
|
|
1756
|
-
throw new ValidationError(
|
|
2636
|
+
throw new ValidationError("Failed to parse connected account retrieve response", {
|
|
2637
|
+
cause: result.error
|
|
2638
|
+
});
|
|
1757
2639
|
}
|
|
1758
2640
|
return result.data;
|
|
1759
2641
|
}
|
|
@@ -1786,7 +2668,9 @@ var ConnectedAccounts = class {
|
|
|
1786
2668
|
if (query) {
|
|
1787
2669
|
const parsedQuery = ConnectedAccountListParamsSchema.safeParse(query);
|
|
1788
2670
|
if (!parsedQuery.success) {
|
|
1789
|
-
throw new ValidationError(
|
|
2671
|
+
throw new ValidationError("Failed to parse connected account list query", {
|
|
2672
|
+
cause: parsedQuery.error
|
|
2673
|
+
});
|
|
1790
2674
|
}
|
|
1791
2675
|
rawQuery = {
|
|
1792
2676
|
auth_config_ids: parsedQuery.data.authConfigIds,
|
|
@@ -1806,7 +2690,9 @@ var ConnectedAccounts = class {
|
|
|
1806
2690
|
totalPages: result.total_pages
|
|
1807
2691
|
});
|
|
1808
2692
|
if (!parsedResponse.success) {
|
|
1809
|
-
throw new ValidationError(
|
|
2693
|
+
throw new ValidationError("Failed to parse connected account list response", {
|
|
2694
|
+
cause: parsedResponse.error
|
|
2695
|
+
});
|
|
1810
2696
|
}
|
|
1811
2697
|
return parsedResponse.data;
|
|
1812
2698
|
}
|
|
@@ -1850,11 +2736,11 @@ var ConnectedAccounts = class {
|
|
|
1850
2736
|
},
|
|
1851
2737
|
connection: {
|
|
1852
2738
|
data: options?.data,
|
|
1853
|
-
|
|
2739
|
+
callback_url: options?.callbackUrl,
|
|
1854
2740
|
user_id: userId
|
|
1855
2741
|
}
|
|
1856
2742
|
});
|
|
1857
|
-
return new ConnectionRequest(this.client, response.id, response.status, response.
|
|
2743
|
+
return new ConnectionRequest(this.client, response.id, response.status, response.redirect_url);
|
|
1858
2744
|
}
|
|
1859
2745
|
/**
|
|
1860
2746
|
* Waits for a connection request to complete and become active.
|
|
@@ -1879,8 +2765,8 @@ var ConnectedAccounts = class {
|
|
|
1879
2765
|
* ```
|
|
1880
2766
|
*/
|
|
1881
2767
|
async waitForConnection(connectedAccountId, timeout = 6e4) {
|
|
1882
|
-
const
|
|
1883
|
-
return
|
|
2768
|
+
const connectionRequest = new ConnectionRequest(this.client, connectedAccountId);
|
|
2769
|
+
return connectionRequest.waitForConnection(timeout);
|
|
1884
2770
|
}
|
|
1885
2771
|
/**
|
|
1886
2772
|
* Retrieves a specific connected account by its ID.
|
|
@@ -1946,8 +2832,21 @@ var ConnectedAccounts = class {
|
|
|
1946
2832
|
* Update the status of a connected account
|
|
1947
2833
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
1948
2834
|
* @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status
|
|
1949
|
-
* @param {RequestOptions} options - Request options
|
|
1950
2835
|
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
2836
|
+
*
|
|
2837
|
+
* @example
|
|
2838
|
+
* ```typescript
|
|
2839
|
+
* // Enable a connected account
|
|
2840
|
+
* const updatedAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
2841
|
+
* enabled: true
|
|
2842
|
+
* });
|
|
2843
|
+
*
|
|
2844
|
+
* // Disable a connected account with a reason
|
|
2845
|
+
* const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
2846
|
+
* enabled: false,
|
|
2847
|
+
* reason: 'Token expired'
|
|
2848
|
+
* });
|
|
2849
|
+
* ```
|
|
1951
2850
|
*/
|
|
1952
2851
|
async updateStatus(nanoid, params) {
|
|
1953
2852
|
return this.client.connectedAccounts.updateStatus(nanoid, params);
|
|
@@ -1955,8 +2854,14 @@ var ConnectedAccounts = class {
|
|
|
1955
2854
|
/**
|
|
1956
2855
|
* Enable a connected account
|
|
1957
2856
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
1958
|
-
* @param {RequestOptions} options - Request options
|
|
1959
2857
|
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
2858
|
+
*
|
|
2859
|
+
* @example
|
|
2860
|
+
* ```typescript
|
|
2861
|
+
* // Enable a previously disabled connected account
|
|
2862
|
+
* const enabledAccount = await composio.connectedAccounts.enable('conn_abc123');
|
|
2863
|
+
* console.log(enabledAccount.isDisabled); // false
|
|
2864
|
+
* ```
|
|
1960
2865
|
*/
|
|
1961
2866
|
async enable(nanoid) {
|
|
1962
2867
|
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true });
|
|
@@ -1964,8 +2869,20 @@ var ConnectedAccounts = class {
|
|
|
1964
2869
|
/**
|
|
1965
2870
|
* Disable a connected account
|
|
1966
2871
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
1967
|
-
* @param {RequestOptions} options - Request options
|
|
1968
2872
|
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
2873
|
+
*
|
|
2874
|
+
* @example
|
|
2875
|
+
* ```typescript
|
|
2876
|
+
* // Disable a connected account
|
|
2877
|
+
* const disabledAccount = await composio.connectedAccounts.disable('conn_abc123');
|
|
2878
|
+
* console.log(disabledAccount.isDisabled); // true
|
|
2879
|
+
*
|
|
2880
|
+
* // You can also use updateStatus with a reason
|
|
2881
|
+
* // const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
2882
|
+
* // enabled: false,
|
|
2883
|
+
* // reason: 'No longer needed'
|
|
2884
|
+
* // });
|
|
2885
|
+
* ```
|
|
1969
2886
|
*/
|
|
1970
2887
|
async disable(nanoid) {
|
|
1971
2888
|
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
|
|
@@ -1978,6 +2895,7 @@ var Toolkits = class {
|
|
|
1978
2895
|
constructor(client) {
|
|
1979
2896
|
this.client = client;
|
|
1980
2897
|
this.authorize = this.authorize.bind(this);
|
|
2898
|
+
telemetry.instrument(this);
|
|
1981
2899
|
}
|
|
1982
2900
|
/**
|
|
1983
2901
|
* Retrieves a list of toolkits based on the provided query parameters.
|
|
@@ -1991,42 +2909,46 @@ var Toolkits = class {
|
|
|
1991
2909
|
* @private
|
|
1992
2910
|
*/
|
|
1993
2911
|
async getToolkits(query) {
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
sort_by: parsedQuery.sortBy
|
|
2000
|
-
});
|
|
2001
|
-
const parsedResult = ToolKitListResponseSchema.parse({
|
|
2002
|
-
items: result.items.map((item) => {
|
|
2003
|
-
const parsedItem = ToolKitItemSchema.parse({
|
|
2004
|
-
name: item.name,
|
|
2005
|
-
slug: item.slug,
|
|
2006
|
-
meta: item.meta,
|
|
2007
|
-
isLocalToolkit: item.is_local_toolkit,
|
|
2008
|
-
authSchemes: item.auth_schemes,
|
|
2009
|
-
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
2010
|
-
noAuth: item.no_auth
|
|
2912
|
+
try {
|
|
2913
|
+
const parsedQuery = ToolkitsListParamsSchema.safeParse(query);
|
|
2914
|
+
if (!parsedQuery.success) {
|
|
2915
|
+
throw new ValidationError("Failed to parse toolkit list query", {
|
|
2916
|
+
cause: parsedQuery.error
|
|
2011
2917
|
});
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2918
|
+
}
|
|
2919
|
+
const result = await this.client.toolkits.list({
|
|
2920
|
+
category: parsedQuery.data.category,
|
|
2921
|
+
is_local: parsedQuery.data.isLocal,
|
|
2922
|
+
managed_by: parsedQuery.data.managedBy,
|
|
2923
|
+
sort_by: parsedQuery.data.sortBy
|
|
2924
|
+
});
|
|
2925
|
+
const parsedResult = ToolKitListResponseSchema.safeParse({
|
|
2926
|
+
items: result.items.map((item) => {
|
|
2927
|
+
const parsedItem = ToolKitItemSchema.parse({
|
|
2928
|
+
name: item.name,
|
|
2929
|
+
slug: item.slug,
|
|
2930
|
+
meta: item.meta,
|
|
2931
|
+
isLocalToolkit: item.is_local_toolkit,
|
|
2932
|
+
authSchemes: item.auth_schemes,
|
|
2933
|
+
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
2934
|
+
noAuth: item.no_auth
|
|
2935
|
+
});
|
|
2936
|
+
return parsedItem;
|
|
2937
|
+
}),
|
|
2938
|
+
nextCursor: result.next_cursor,
|
|
2939
|
+
totalPages: result.total_pages
|
|
2940
|
+
});
|
|
2941
|
+
if (!parsedResult.success) {
|
|
2942
|
+
throw new ValidationError("Failed to parse toolkit list response", {
|
|
2943
|
+
cause: parsedResult.error
|
|
2944
|
+
});
|
|
2945
|
+
}
|
|
2946
|
+
return parsedResult.data;
|
|
2947
|
+
} catch (error) {
|
|
2948
|
+
throw new ComposioToolkitFetchError("Failed to fetch toolkits", {
|
|
2949
|
+
cause: error
|
|
2950
|
+
});
|
|
2028
2951
|
}
|
|
2029
|
-
return this.getToolkits(arg);
|
|
2030
2952
|
}
|
|
2031
2953
|
/**
|
|
2032
2954
|
* Retrieves a specific toolkit by its slug identifier.
|
|
@@ -2044,7 +2966,7 @@ var Toolkits = class {
|
|
|
2044
2966
|
async getToolkitBySlug(slug) {
|
|
2045
2967
|
try {
|
|
2046
2968
|
const result = await this.client.toolkits.retrieve(slug);
|
|
2047
|
-
const parsedResult = ToolkitRetrieveResponseSchema.
|
|
2969
|
+
const parsedResult = ToolkitRetrieveResponseSchema.safeParse({
|
|
2048
2970
|
name: result.name,
|
|
2049
2971
|
slug: result.slug,
|
|
2050
2972
|
meta: {
|
|
@@ -2069,16 +2991,41 @@ var Toolkits = class {
|
|
|
2069
2991
|
}
|
|
2070
2992
|
}))
|
|
2071
2993
|
});
|
|
2072
|
-
|
|
2994
|
+
if (!parsedResult.success) {
|
|
2995
|
+
throw new ValidationError("Failed to parse toolkit response", {
|
|
2996
|
+
cause: parsedResult.error
|
|
2997
|
+
});
|
|
2998
|
+
}
|
|
2999
|
+
return parsedResult.data;
|
|
2073
3000
|
} catch (error) {
|
|
2074
|
-
if (error instanceof
|
|
2075
|
-
throw new
|
|
3001
|
+
if (error instanceof ComposioClient2.NotFoundError) {
|
|
3002
|
+
throw new ComposioToolkitNotFoundError(`Toolkit with slug ${slug} not found`, {
|
|
3003
|
+
meta: {
|
|
3004
|
+
slug
|
|
3005
|
+
},
|
|
3006
|
+
cause: error
|
|
3007
|
+
});
|
|
2076
3008
|
}
|
|
2077
|
-
throw new
|
|
2078
|
-
|
|
3009
|
+
throw new ComposioToolkitFetchError(`Couldn't fetch Toolkit with slug: ${slug}`, {
|
|
3010
|
+
meta: {
|
|
3011
|
+
slug
|
|
3012
|
+
},
|
|
3013
|
+
cause: error
|
|
2079
3014
|
});
|
|
2080
3015
|
}
|
|
2081
3016
|
}
|
|
3017
|
+
/**
|
|
3018
|
+
* Implementation method that handles both overloads for retrieving toolkits.
|
|
3019
|
+
*
|
|
3020
|
+
* @param {string | ToolkitListParams} arg - Either a toolkit slug or query parameters
|
|
3021
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit or list of toolkits
|
|
3022
|
+
*/
|
|
3023
|
+
async get(arg) {
|
|
3024
|
+
if (typeof arg === "string") {
|
|
3025
|
+
return this.getToolkitBySlug(arg);
|
|
3026
|
+
}
|
|
3027
|
+
return this.getToolkits(arg);
|
|
3028
|
+
}
|
|
2082
3029
|
/**
|
|
2083
3030
|
* Retrieves all toolkit categories available in the Composio SDK.
|
|
2084
3031
|
*
|
|
@@ -2126,7 +3073,7 @@ var Toolkits = class {
|
|
|
2126
3073
|
const composioAuthConfig = new AuthConfigs(this.client);
|
|
2127
3074
|
let authConfigIdToUse;
|
|
2128
3075
|
const authConfig = await composioAuthConfig.list({
|
|
2129
|
-
toolkitSlug
|
|
3076
|
+
toolkit: toolkitSlug
|
|
2130
3077
|
});
|
|
2131
3078
|
authConfigIdToUse = authConfig.items[0]?.id;
|
|
2132
3079
|
if (!authConfigIdToUse) {
|
|
@@ -2138,7 +3085,9 @@ var Toolkits = class {
|
|
|
2138
3085
|
authConfigIdToUse = authConfig2.id;
|
|
2139
3086
|
} else {
|
|
2140
3087
|
throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
|
|
2141
|
-
|
|
3088
|
+
meta: {
|
|
3089
|
+
toolkitSlug
|
|
3090
|
+
}
|
|
2142
3091
|
});
|
|
2143
3092
|
}
|
|
2144
3093
|
}
|
|
@@ -2147,474 +3096,662 @@ var Toolkits = class {
|
|
|
2147
3096
|
}
|
|
2148
3097
|
};
|
|
2149
3098
|
|
|
2150
|
-
// src/
|
|
2151
|
-
|
|
2152
|
-
var
|
|
2153
|
-
var
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
3099
|
+
// src/types/triggers.types.ts
|
|
3100
|
+
import { z as z5 } from "zod";
|
|
3101
|
+
var TriggerStatusEnum = z5.enum(["enable", "disable"]);
|
|
3102
|
+
var TriggerSubscribeParamSchema = z5.object({
|
|
3103
|
+
toolkits: z5.array(z5.string()).optional(),
|
|
3104
|
+
triggerId: z5.string().optional(),
|
|
3105
|
+
connectedAccountId: z5.string().optional(),
|
|
3106
|
+
authConfigId: z5.string().optional(),
|
|
3107
|
+
triggerSlug: z5.array(z5.string()).optional(),
|
|
3108
|
+
triggerData: z5.string().optional(),
|
|
3109
|
+
userId: z5.string().optional()
|
|
3110
|
+
});
|
|
3111
|
+
var TriggerInstanceListActiveParamsSchema = z5.object({
|
|
3112
|
+
authConfigIds: z5.array(z5.string()).nullable().optional(),
|
|
3113
|
+
connectedAccountIds: z5.array(z5.string()).nullable().optional(),
|
|
3114
|
+
limit: z5.number().optional(),
|
|
3115
|
+
page: z5.number().optional(),
|
|
3116
|
+
showDisabled: z5.boolean().nullable().optional(),
|
|
3117
|
+
triggerIds: z5.array(z5.string()).nullable().optional(),
|
|
3118
|
+
triggerNames: z5.array(z5.string()).nullable().optional()
|
|
3119
|
+
});
|
|
3120
|
+
var TriggerInstanceListActiveResponseItemSchema = z5.object({
|
|
3121
|
+
id: z5.string(),
|
|
3122
|
+
connectedAccountId: z5.string(),
|
|
3123
|
+
disabledAt: z5.string().nullable(),
|
|
3124
|
+
state: z5.record(z5.unknown()),
|
|
3125
|
+
triggerConfig: z5.record(z5.unknown()),
|
|
3126
|
+
triggerName: z5.string(),
|
|
3127
|
+
updatedAt: z5.string(),
|
|
3128
|
+
triggerData: z5.string().optional(),
|
|
3129
|
+
uuid: z5.string().optional()
|
|
3130
|
+
});
|
|
3131
|
+
var TriggerInstanceListActiveResponseSchema = z5.object({
|
|
3132
|
+
items: z5.array(TriggerInstanceListActiveResponseItemSchema),
|
|
3133
|
+
nextCursor: z5.string().nullable(),
|
|
3134
|
+
totalPages: z5.number()
|
|
3135
|
+
});
|
|
3136
|
+
var TriggerInstanceUpsertParamsSchema = z5.object({
|
|
3137
|
+
connectedAccountId: z5.string().optional(),
|
|
3138
|
+
triggerConfig: z5.record(z5.unknown()).optional()
|
|
3139
|
+
});
|
|
3140
|
+
var TriggerInstanceUpsertResponseSchema = z5.object({
|
|
3141
|
+
triggerId: z5.string()
|
|
3142
|
+
});
|
|
3143
|
+
var TriggerInstanceManageUpdateParamsSchema = z5.object({
|
|
3144
|
+
status: z5.enum(["enable", "disable"])
|
|
3145
|
+
});
|
|
3146
|
+
var TriggerInstanceManageUpdateResponseSchema = z5.object({
|
|
3147
|
+
status: z5.enum(["success"])
|
|
3148
|
+
});
|
|
3149
|
+
var TriggerInstanceManageDeleteResponseSchema = z5.object({
|
|
3150
|
+
triggerId: z5.string()
|
|
3151
|
+
});
|
|
3152
|
+
var IncomingTriggerPayloadSchema = z5.object({
|
|
3153
|
+
id: z5.string().describe("The ID of the trigger"),
|
|
3154
|
+
triggerSlug: z5.string().describe("The slug of the trigger that triggered the event"),
|
|
3155
|
+
toolkitSlug: z5.string().describe("The slug of the toolkit that triggered the event"),
|
|
3156
|
+
userId: z5.string().describe("The ID of the user that triggered the event"),
|
|
3157
|
+
payload: z5.record(z5.unknown()).describe("The payload of the trigger").optional(),
|
|
3158
|
+
originalPayload: z5.record(z5.unknown()).describe("The original payload of the trigger").optional(),
|
|
3159
|
+
metadata: z5.object({
|
|
3160
|
+
id: z5.string(),
|
|
3161
|
+
toolkitSlug: z5.string(),
|
|
3162
|
+
triggerSlug: z5.string(),
|
|
3163
|
+
triggerData: z5.string().optional(),
|
|
3164
|
+
triggerConfig: z5.record(z5.unknown()),
|
|
3165
|
+
connectedAccount: z5.object({
|
|
3166
|
+
id: z5.string(),
|
|
3167
|
+
uuid: z5.string(),
|
|
3168
|
+
authConfigId: z5.string(),
|
|
3169
|
+
authConfigUUID: z5.string(),
|
|
3170
|
+
userId: z5.string(),
|
|
3171
|
+
status: z5.enum(["ACTIVE", "INACTIVE"])
|
|
3172
|
+
})
|
|
3173
|
+
})
|
|
3174
|
+
});
|
|
3175
|
+
|
|
3176
|
+
// src/services/internal/InternalService.types.ts
|
|
3177
|
+
import { z as z6 } from "zod";
|
|
3178
|
+
var SDKRealtimeCredentialsResponseSchema = z6.object({
|
|
3179
|
+
projectId: z6.string().describe("The project ID"),
|
|
3180
|
+
pusherKey: z6.string().describe("The Pusher key"),
|
|
3181
|
+
pusherCluster: z6.string().describe("The Pusher cluster")
|
|
3182
|
+
});
|
|
3183
|
+
|
|
3184
|
+
// src/services/internal/InternalService.ts
|
|
3185
|
+
var SDK_REALTIME_CREDENTIALS_ENDPOINT = "/api/v3/internal/sdk/realtime/credentials";
|
|
3186
|
+
var InternalService = class {
|
|
3187
|
+
constructor(client) {
|
|
3188
|
+
this.client = client;
|
|
3189
|
+
this.client = client;
|
|
3190
|
+
}
|
|
3191
|
+
/**
|
|
3192
|
+
* Get the SDK realtime credentials
|
|
3193
|
+
* @returns {SDKRealtimeCredentialsResponse} The SDK realtime credentials
|
|
3194
|
+
*/
|
|
3195
|
+
async getSDKRealtimeCredentials() {
|
|
3196
|
+
const response = await this.client.request({
|
|
3197
|
+
method: "get",
|
|
3198
|
+
path: SDK_REALTIME_CREDENTIALS_ENDPOINT
|
|
3199
|
+
});
|
|
3200
|
+
const parsedResponse = SDKRealtimeCredentialsResponseSchema.safeParse({
|
|
3201
|
+
pusherKey: response.pusher_key,
|
|
3202
|
+
projectId: response.project_id,
|
|
3203
|
+
pusherCluster: response.pusher_cluster
|
|
3204
|
+
});
|
|
3205
|
+
logger_default.debug(
|
|
3206
|
+
`[InternalService] SDK realtime credentials: ${JSON.stringify(parsedResponse, null, 2)}`
|
|
3207
|
+
);
|
|
3208
|
+
if (!parsedResponse.success) {
|
|
3209
|
+
throw new ValidationError(`Failed to parse SDK realtime credentials`, {
|
|
3210
|
+
cause: parsedResponse.error
|
|
3211
|
+
});
|
|
3212
|
+
}
|
|
3213
|
+
return parsedResponse.data;
|
|
3214
|
+
}
|
|
3215
|
+
};
|
|
3216
|
+
|
|
3217
|
+
// src/errors/TriggerErrors.ts
|
|
3218
|
+
import { ComposioError as ComposioError2 } from "@composio/client";
|
|
3219
|
+
var TriggerErrorCodes = {
|
|
3220
|
+
TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS: "TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS",
|
|
3221
|
+
TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT: "TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT",
|
|
3222
|
+
TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL",
|
|
3223
|
+
TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL"
|
|
3224
|
+
};
|
|
3225
|
+
var ComposioFailedToGetSDKRealtimeCredentialsError = class extends ComposioError2 {
|
|
3226
|
+
name = "ComposioFailedToGetSDKRealtimeCredentialsError";
|
|
3227
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS;
|
|
3228
|
+
statusCode = 500;
|
|
3229
|
+
possibleFixes = ["Please contact support."];
|
|
3230
|
+
constructor(message, options) {
|
|
3231
|
+
super(message, options);
|
|
3232
|
+
}
|
|
3233
|
+
};
|
|
3234
|
+
var ComposioFailedToCreatePusherClientError = class extends ComposioError2 {
|
|
3235
|
+
name = "ComposioFailedToCreatePusherClientError";
|
|
3236
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT;
|
|
3237
|
+
statusCode = 500;
|
|
3238
|
+
possibleFixes = ["Please contact support."];
|
|
3239
|
+
constructor(message, options) {
|
|
3240
|
+
super(message, options);
|
|
3241
|
+
}
|
|
3242
|
+
};
|
|
3243
|
+
var ComposioFailedToSubscribeToPusherChannelError = class extends ComposioError2 {
|
|
3244
|
+
name = "ComposioFailedToSubscribeToPusherChannelError";
|
|
3245
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL;
|
|
3246
|
+
statusCode = 500;
|
|
3247
|
+
possibleFixes = ["Please contact support."];
|
|
3248
|
+
constructor(message, options) {
|
|
3249
|
+
super(message, options);
|
|
3250
|
+
}
|
|
3251
|
+
};
|
|
3252
|
+
|
|
3253
|
+
// src/services/pusher/Pusher.ts
|
|
3254
|
+
var PusherService = class {
|
|
3255
|
+
// these values are set via the Apollo API `/internal/sdk/realtime/credentials` endpoint
|
|
3256
|
+
clientId;
|
|
3257
|
+
pusherKey;
|
|
3258
|
+
pusherCluster;
|
|
3259
|
+
pusherChannel;
|
|
3260
|
+
// these details are set via the client SDK
|
|
3261
|
+
pusherBaseURL;
|
|
3262
|
+
apiKey;
|
|
3263
|
+
pusherClient;
|
|
3264
|
+
composioClient;
|
|
3265
|
+
constructor(client) {
|
|
3266
|
+
this.composioClient = client;
|
|
3267
|
+
this.pusherBaseURL = client.baseURL;
|
|
3268
|
+
this.apiKey = client.apiKey ?? process.env.COMPOSIO_API_KEY ?? "";
|
|
3269
|
+
telemetry.instrument(this);
|
|
3270
|
+
}
|
|
3271
|
+
/**
|
|
3272
|
+
* Creates a Pusher client
|
|
3273
|
+
*
|
|
3274
|
+
* This method is called when the Pusher client is first used.
|
|
3275
|
+
* It will fetch the SDK realtime credentials from the Apollo API and create a Pusher client.
|
|
3276
|
+
*/
|
|
3277
|
+
async getPusherClient() {
|
|
3278
|
+
if (!this.pusherClient) {
|
|
3279
|
+
const internalService = new InternalService(this.composioClient);
|
|
3280
|
+
let sdkRealtimeCredentials;
|
|
3281
|
+
try {
|
|
3282
|
+
sdkRealtimeCredentials = await internalService.getSDKRealtimeCredentials();
|
|
3283
|
+
} catch (error) {
|
|
3284
|
+
throw new ComposioFailedToGetSDKRealtimeCredentialsError(
|
|
3285
|
+
"Failed to get SDK realtime credentials",
|
|
3286
|
+
{
|
|
3287
|
+
cause: error
|
|
3288
|
+
}
|
|
3289
|
+
);
|
|
3290
|
+
}
|
|
3291
|
+
this.clientId = sdkRealtimeCredentials.projectId;
|
|
3292
|
+
this.pusherKey = sdkRealtimeCredentials.pusherKey;
|
|
3293
|
+
this.pusherCluster = sdkRealtimeCredentials.pusherCluster;
|
|
3294
|
+
this.pusherChannel = `private-${this.clientId}_triggers`;
|
|
3295
|
+
logger_default.debug(
|
|
3296
|
+
`[PusherService] Creating Pusher client for client ID: ${this.clientId} in cluster ${this.pusherCluster}`
|
|
3297
|
+
);
|
|
3298
|
+
try {
|
|
3299
|
+
const { default: Pusher } = await import("pusher-js");
|
|
3300
|
+
this.pusherClient = new Pusher(this.pusherKey, {
|
|
3301
|
+
cluster: this.pusherCluster,
|
|
3302
|
+
channelAuthorization: {
|
|
3303
|
+
endpoint: `${this.pusherBaseURL}/api/v3/internal/sdk/realtime/auth`,
|
|
3304
|
+
headers: {
|
|
3305
|
+
"x-api-key": this.apiKey
|
|
3306
|
+
},
|
|
3307
|
+
transport: "ajax"
|
|
3308
|
+
}
|
|
3309
|
+
});
|
|
3310
|
+
} catch (error) {
|
|
3311
|
+
throw new ComposioFailedToCreatePusherClientError("Failed to create Pusher client", {
|
|
3312
|
+
cause: error
|
|
3313
|
+
});
|
|
3314
|
+
}
|
|
3315
|
+
}
|
|
3316
|
+
return this.pusherClient;
|
|
3317
|
+
}
|
|
3318
|
+
/**
|
|
3319
|
+
* Binds a chunked event to a Pusher client
|
|
3320
|
+
*
|
|
3321
|
+
*
|
|
3322
|
+
* @param channel - The Pusher client to bind the event to
|
|
3323
|
+
* @param event - The event to bind to
|
|
3324
|
+
* @param callback - The function to call when the event is received
|
|
3325
|
+
*/
|
|
3326
|
+
bindWithChunking(channel, event, callback) {
|
|
3327
|
+
try {
|
|
3328
|
+
channel.bind(event, callback);
|
|
3329
|
+
const events = {};
|
|
3330
|
+
channel.bind("chunked-" + event, (data) => {
|
|
3331
|
+
try {
|
|
3332
|
+
const typedData = data;
|
|
3333
|
+
if (!typedData || typeof typedData.id !== "string" || typeof typedData.index !== "number") {
|
|
3334
|
+
throw new Error("Invalid chunked trigger data format");
|
|
3335
|
+
}
|
|
3336
|
+
if (!events.hasOwnProperty(typedData.id)) {
|
|
3337
|
+
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
3338
|
+
}
|
|
3339
|
+
const ev = events[typedData.id];
|
|
3340
|
+
ev.chunks[typedData.index] = typedData.chunk;
|
|
3341
|
+
if (typedData.final) ev.receivedFinal = true;
|
|
3342
|
+
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
3343
|
+
try {
|
|
3344
|
+
const parsedData = JSON.parse(ev.chunks.join(""));
|
|
3345
|
+
callback(parsedData);
|
|
3346
|
+
} catch (parseError) {
|
|
3347
|
+
const errorMessage = parseError instanceof Error ? parseError.message : String(parseError);
|
|
3348
|
+
logger_default.error("Failed to parse chunked data:", errorMessage);
|
|
3349
|
+
} finally {
|
|
3350
|
+
delete events[typedData.id];
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3353
|
+
} catch (error) {
|
|
3354
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3355
|
+
logger_default.error("Error processing chunked trigger data:", errorMessage);
|
|
3356
|
+
if (data && typeof data === "object" && "id" in data) {
|
|
3357
|
+
delete events[data.id];
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
});
|
|
3361
|
+
} catch (error) {
|
|
3362
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3363
|
+
logger_default.error("Failed to bind chunked events:", error);
|
|
3364
|
+
throw new Error(`Failed to bind chunked events: ${errorMessage}`);
|
|
3365
|
+
}
|
|
3366
|
+
}
|
|
3367
|
+
/**
|
|
3368
|
+
* Subscribes to pusher to receive events from the server
|
|
3369
|
+
*
|
|
3370
|
+
* This method is used to subscribe to a Pusher channel.
|
|
3371
|
+
* It will create a Pusher client if it doesn't exist.
|
|
3372
|
+
*
|
|
3373
|
+
* @param channelName - The name of the Pusher channel to subscribe to
|
|
3374
|
+
* @param event - The event to subscribe to
|
|
3375
|
+
* @param fn - The function to call when the event is received
|
|
3376
|
+
*/
|
|
3377
|
+
async subscribe(fn) {
|
|
3378
|
+
try {
|
|
3379
|
+
logger_default.debug(`[PusherService] Subscribing to channel: ${this.pusherChannel}`);
|
|
3380
|
+
const pusherClient = await this.getPusherClient();
|
|
3381
|
+
const channel = await pusherClient.subscribe(this.pusherChannel);
|
|
3382
|
+
channel.bind("pusher:subscription_error", (data) => {
|
|
3383
|
+
const error = data.error ? String(data.error) : "Unknown subscription error";
|
|
3384
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3385
|
+
`Trigger subscription error: ${error}`,
|
|
3386
|
+
{
|
|
3387
|
+
cause: error
|
|
3388
|
+
}
|
|
3389
|
+
);
|
|
3390
|
+
});
|
|
3391
|
+
const safeCallback = (data) => {
|
|
3392
|
+
try {
|
|
3393
|
+
fn(data);
|
|
3394
|
+
} catch (error) {
|
|
3395
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3396
|
+
logger_default.error("\u274C Error in trigger callback:", errorMessage);
|
|
2166
3397
|
}
|
|
2167
|
-
}
|
|
3398
|
+
};
|
|
3399
|
+
this.bindWithChunking(channel, "trigger_to_client", safeCallback);
|
|
3400
|
+
logger_default.info(`\u2705 Subscribed to triggers. You should start receiving events now.`);
|
|
3401
|
+
} catch (error) {
|
|
3402
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3403
|
+
"Failed to subscribe to Pusher channel",
|
|
3404
|
+
{
|
|
3405
|
+
cause: error
|
|
3406
|
+
}
|
|
3407
|
+
);
|
|
2168
3408
|
}
|
|
2169
|
-
return _PusherUtils.pusherClient;
|
|
2170
3409
|
}
|
|
2171
3410
|
/**
|
|
2172
|
-
*
|
|
2173
|
-
*
|
|
2174
|
-
*
|
|
2175
|
-
*
|
|
2176
|
-
*
|
|
3411
|
+
* Unsubscribes from a Pusher channel
|
|
3412
|
+
*
|
|
3413
|
+
* This method is used to unsubscribe from a Pusher channel.
|
|
3414
|
+
* It will create a Pusher client if it doesn't exist.
|
|
3415
|
+
*
|
|
3416
|
+
* @param channelName - The name of the Pusher channel to unsubscribe from
|
|
2177
3417
|
*/
|
|
2178
|
-
|
|
3418
|
+
async unsubscribe() {
|
|
2179
3419
|
try {
|
|
2180
|
-
|
|
3420
|
+
logger_default.debug(`[PusherService] Unsubscribing from channel: ${this.pusherChannel}`);
|
|
3421
|
+
const pusherClient = await this.getPusherClient();
|
|
3422
|
+
await pusherClient.unsubscribe(this.pusherChannel);
|
|
3423
|
+
logger_default.info(`\u2705 Unsubscribed from triggers.`);
|
|
2181
3424
|
} catch (error) {
|
|
2182
|
-
|
|
2183
|
-
|
|
3425
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3426
|
+
"Failed to unsubscribe from Pusher channel",
|
|
3427
|
+
{
|
|
3428
|
+
cause: error
|
|
3429
|
+
}
|
|
2184
3430
|
);
|
|
2185
3431
|
}
|
|
2186
3432
|
}
|
|
2187
|
-
/**
|
|
2188
|
-
* Unsubscribes from a Pusher channel.
|
|
2189
|
-
* @param {string} channelName - The name of the channel to unsubscribe from.
|
|
2190
|
-
* @returns {void}
|
|
2191
|
-
*/
|
|
2192
|
-
static async unsubscribe(channelName) {
|
|
2193
|
-
_PusherUtils.pusherClient.unsubscribe(channelName);
|
|
2194
|
-
}
|
|
2195
|
-
/**
|
|
2196
|
-
* Binds an event to a channel with support for chunked messages.
|
|
2197
|
-
* @param {PusherClient} channel - The Pusher channel to bind the event to.
|
|
2198
|
-
* @param {string} event - The event to bind to the channel.
|
|
2199
|
-
* @param {(data: unknown) => void} callback - The callback function to execute when the event is triggered.
|
|
2200
|
-
*/
|
|
2201
|
-
static bindWithChunking(channel, event, callback) {
|
|
2202
|
-
channel.bind(event, callback);
|
|
2203
|
-
const events = {};
|
|
2204
|
-
channel.bind("chunked-" + event, (data) => {
|
|
2205
|
-
const typedData = data;
|
|
2206
|
-
if (!events.hasOwnProperty(typedData.id)) {
|
|
2207
|
-
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
2208
|
-
}
|
|
2209
|
-
const ev = events[typedData.id];
|
|
2210
|
-
ev.chunks[typedData.index] = typedData.chunk;
|
|
2211
|
-
if (typedData.final) ev.receivedFinal = true;
|
|
2212
|
-
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
2213
|
-
callback(JSON.parse(ev.chunks.join("")));
|
|
2214
|
-
delete events[typedData.id];
|
|
2215
|
-
}
|
|
2216
|
-
});
|
|
2217
|
-
}
|
|
2218
|
-
/**
|
|
2219
|
-
* Subscribes to a trigger channel for a client and handles chunked data.
|
|
2220
|
-
* @param {string} clientId - The unique identifier for the client subscribing to the events.
|
|
2221
|
-
* @param {(data: TriggerData) => void} fn - The callback function to execute when trigger data is received.
|
|
2222
|
-
*/
|
|
2223
|
-
static triggerSubscribe(clientId, fn) {
|
|
2224
|
-
const channel = _PusherUtils.pusherClient.subscribe(
|
|
2225
|
-
`private-${clientId}_triggers`
|
|
2226
|
-
);
|
|
2227
|
-
_PusherUtils.bindWithChunking(
|
|
2228
|
-
channel,
|
|
2229
|
-
"trigger_to_client",
|
|
2230
|
-
fn
|
|
2231
|
-
);
|
|
2232
|
-
logger_default.info(
|
|
2233
|
-
`Subscribed to triggers. You should start receiving events now.`
|
|
2234
|
-
);
|
|
2235
|
-
}
|
|
2236
|
-
static triggerUnsubscribe(clientId) {
|
|
2237
|
-
_PusherUtils.pusherClient.unsubscribe(`${clientId}_triggers`);
|
|
2238
|
-
}
|
|
2239
|
-
};
|
|
2240
|
-
|
|
2241
|
-
// src/models/Session.ts
|
|
2242
|
-
var Session = class {
|
|
2243
|
-
client;
|
|
2244
|
-
constructor(client) {
|
|
2245
|
-
this.client = client;
|
|
2246
|
-
}
|
|
2247
|
-
/**
|
|
2248
|
-
* Get the active session info
|
|
2249
|
-
* @returns {Promise<SessionGetInfoResponse>} Session info
|
|
2250
|
-
*/
|
|
2251
|
-
async getInfo() {
|
|
2252
|
-
return this.client.auth.session.getInfo();
|
|
2253
|
-
}
|
|
2254
3433
|
};
|
|
2255
3434
|
|
|
2256
3435
|
// src/models/Triggers.ts
|
|
2257
3436
|
var Triggers = class {
|
|
2258
3437
|
client;
|
|
3438
|
+
pusherService;
|
|
2259
3439
|
constructor(client) {
|
|
2260
3440
|
this.client = client;
|
|
3441
|
+
this.pusherService = new PusherService(client);
|
|
3442
|
+
telemetry.instrument(this);
|
|
2261
3443
|
}
|
|
2262
3444
|
/**
|
|
2263
|
-
*
|
|
2264
|
-
* @returns {Promise<TriggerInstance[]>} List of trigger instances
|
|
2265
|
-
*/
|
|
2266
|
-
async list(query, options) {
|
|
2267
|
-
return this.client.triggerInstances.listActive(query, options);
|
|
2268
|
-
}
|
|
2269
|
-
/**
|
|
2270
|
-
* Create a new trigger instance
|
|
2271
|
-
*
|
|
2272
|
-
* @param {string} slug - The slug of the trigger instance
|
|
2273
|
-
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
2274
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
2275
|
-
*/
|
|
2276
|
-
async create(slug, body, options) {
|
|
2277
|
-
return this.client.triggerInstances.upsert(slug, body, options);
|
|
2278
|
-
}
|
|
2279
|
-
/**
|
|
2280
|
-
* Update an existing trigger instance
|
|
3445
|
+
* Parse the trigger instance list active item
|
|
2281
3446
|
*
|
|
2282
|
-
* @param
|
|
2283
|
-
* @
|
|
2284
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
3447
|
+
* @param response - The response from the composio client
|
|
3448
|
+
* @returns The parsed trigger instance list active item
|
|
2285
3449
|
*/
|
|
2286
|
-
|
|
2287
|
-
|
|
3450
|
+
parseTriggerInstanceListActiveItem(response) {
|
|
3451
|
+
const parsed = TriggerInstanceListActiveResponseItemSchema.safeParse({
|
|
3452
|
+
id: response.id,
|
|
3453
|
+
connectedAccountId: response.connected_account_id,
|
|
3454
|
+
disabledAt: response.disabled_at,
|
|
3455
|
+
state: response.state,
|
|
3456
|
+
triggerConfig: response.trigger_config,
|
|
3457
|
+
triggerName: response.trigger_name,
|
|
3458
|
+
updatedAt: response.updated_at,
|
|
3459
|
+
triggerData: response.trigger_data,
|
|
3460
|
+
uuid: response.uuid
|
|
3461
|
+
});
|
|
3462
|
+
if (!parsed.success) {
|
|
3463
|
+
throw new ValidationError(`Invalid trigger instance list active item`, {
|
|
3464
|
+
cause: parsed.error
|
|
3465
|
+
});
|
|
3466
|
+
}
|
|
3467
|
+
return parsed.data;
|
|
2288
3468
|
}
|
|
2289
3469
|
/**
|
|
2290
|
-
*
|
|
3470
|
+
* Fetch list of all the active triggers
|
|
2291
3471
|
*
|
|
2292
|
-
* @param {
|
|
2293
|
-
* @returns
|
|
2294
|
-
*/
|
|
2295
|
-
async delete(slug) {
|
|
2296
|
-
return this.client.triggerInstances.removeUpsert(slug);
|
|
2297
|
-
}
|
|
2298
|
-
/**
|
|
2299
|
-
* Update the status of a trigger
|
|
3472
|
+
* @param {TriggerInstanceListActiveParams} query - The query parameters to filter the trigger instances
|
|
3473
|
+
* @returns {Promise<TriggerInstanceListActiveResponse>} List of trigger instances
|
|
2300
3474
|
*
|
|
2301
|
-
* @
|
|
2302
|
-
* @
|
|
2303
|
-
* @param {RequestOptions} options - Request options
|
|
2304
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2305
|
-
*/
|
|
2306
|
-
async updateStatus(status, params, options) {
|
|
2307
|
-
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
2308
|
-
}
|
|
2309
|
-
/**
|
|
2310
|
-
* Disable a trigger instance
|
|
3475
|
+
* @throws {ValidationError} If the parameters are invalid
|
|
3476
|
+
* @throws {Error} If the client is not authenticated
|
|
2311
3477
|
*
|
|
2312
|
-
* @
|
|
2313
|
-
*
|
|
2314
|
-
*
|
|
3478
|
+
* @example
|
|
3479
|
+
* ```ts
|
|
3480
|
+
* const triggers = await triggers.listActive({
|
|
3481
|
+
* authConfigIds: ['123'],
|
|
3482
|
+
* connectedAccountIds: ['456'],
|
|
3483
|
+
* });
|
|
3484
|
+
* ```
|
|
2315
3485
|
*/
|
|
2316
|
-
async
|
|
2317
|
-
|
|
3486
|
+
async listActive(query) {
|
|
3487
|
+
const parsedParams = TriggerInstanceListActiveParamsSchema.safeParse(query ?? {});
|
|
3488
|
+
if (!parsedParams.success) {
|
|
3489
|
+
throw new ValidationError(`Invalid parameters passed to list triggers`, {
|
|
3490
|
+
cause: parsedParams.error
|
|
3491
|
+
});
|
|
3492
|
+
}
|
|
3493
|
+
const result = await this.client.triggerInstances.listActive(
|
|
3494
|
+
query ? {
|
|
3495
|
+
auth_config_ids: parsedParams.data.authConfigIds,
|
|
3496
|
+
connected_account_ids: parsedParams.data.connectedAccountIds,
|
|
3497
|
+
limit: parsedParams.data.limit,
|
|
3498
|
+
page: parsedParams.data.page,
|
|
3499
|
+
show_disabled: parsedParams.data.showDisabled,
|
|
3500
|
+
trigger_ids: parsedParams.data.triggerIds,
|
|
3501
|
+
trigger_names: parsedParams.data.triggerNames
|
|
3502
|
+
} : void 0
|
|
3503
|
+
);
|
|
3504
|
+
const parsedResult = TriggerInstanceListActiveResponseSchema.safeParse({
|
|
3505
|
+
items: result.items.map((item) => this.parseTriggerInstanceListActiveItem(item)),
|
|
3506
|
+
nextCursor: result.next_cursor,
|
|
3507
|
+
totalPages: result.total_pages
|
|
3508
|
+
});
|
|
3509
|
+
if (!parsedResult.success) {
|
|
3510
|
+
throw new ValidationError(`Invalid trigger instance list active response`, {
|
|
3511
|
+
cause: parsedResult.error
|
|
3512
|
+
});
|
|
3513
|
+
}
|
|
3514
|
+
return parsedResult.data;
|
|
2318
3515
|
}
|
|
2319
3516
|
/**
|
|
2320
|
-
*
|
|
3517
|
+
* Create a new trigger instance
|
|
2321
3518
|
*
|
|
2322
3519
|
* @param {string} slug - The slug of the trigger instance
|
|
2323
|
-
* @param {
|
|
2324
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The
|
|
2325
|
-
*/
|
|
2326
|
-
async
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
* @param {RequestOptions} options - Request options
|
|
2337
|
-
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
|
|
2338
|
-
*/
|
|
2339
|
-
async listTypes(query, options) {
|
|
2340
|
-
return this.client.triggersTypes.list(query, options);
|
|
2341
|
-
}
|
|
2342
|
-
/**
|
|
2343
|
-
* Retrieve a trigger type by its slug
|
|
2344
|
-
*
|
|
2345
|
-
* @param {string} slug - The slug of the trigger type
|
|
2346
|
-
* @param {RequestOptions} options - request options
|
|
2347
|
-
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
2348
|
-
*/
|
|
2349
|
-
async getType(slug, options) {
|
|
2350
|
-
return this.client.triggersTypes.retrieve(slug, options);
|
|
2351
|
-
}
|
|
2352
|
-
/**
|
|
2353
|
-
* Fetches the list of all the available trigger enums
|
|
2354
|
-
*
|
|
2355
|
-
* This method is used by the CLI where filters are not required.
|
|
2356
|
-
* @param options
|
|
2357
|
-
* @returns
|
|
2358
|
-
*/
|
|
2359
|
-
async listEnum(options) {
|
|
2360
|
-
return this.client.triggersTypes.retrieveEnum(options);
|
|
2361
|
-
}
|
|
2362
|
-
async subscribe(fn, filters = {}) {
|
|
2363
|
-
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
2364
|
-
const session = new Session(this.client);
|
|
2365
|
-
const sessionInfo = await session.getInfo();
|
|
2366
|
-
const clientId = sessionInfo.project?.id;
|
|
2367
|
-
if (!clientId) throw new Error("Client ID not found");
|
|
2368
|
-
if (!this.client.apiKey) throw new Error("API key not found");
|
|
2369
|
-
await PusherUtils.getPusherClient(this.client.baseURL, this.client.apiKey);
|
|
2370
|
-
const shouldSendTrigger = (data) => {
|
|
2371
|
-
if (Object.keys(filters).length === 0) return true;
|
|
2372
|
-
else {
|
|
2373
|
-
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());
|
|
2374
|
-
}
|
|
2375
|
-
};
|
|
2376
|
-
logger_default.debug("Subscribing to triggers", filters);
|
|
2377
|
-
PusherUtils.triggerSubscribe(clientId, (data) => {
|
|
2378
|
-
if (shouldSendTrigger(data)) {
|
|
2379
|
-
fn(data);
|
|
2380
|
-
}
|
|
2381
|
-
});
|
|
2382
|
-
}
|
|
2383
|
-
async unsubscribe() {
|
|
2384
|
-
const session = new Session(this.client);
|
|
2385
|
-
const sessionInfo = await session.getInfo();
|
|
2386
|
-
const clientId = sessionInfo.project?.id;
|
|
2387
|
-
if (!clientId) throw new Error("Client ID not found");
|
|
2388
|
-
PusherUtils.triggerUnsubscribe(clientId);
|
|
2389
|
-
}
|
|
2390
|
-
};
|
|
2391
|
-
|
|
2392
|
-
// src/types/telemetry.types.ts
|
|
2393
|
-
var TELEMETRY_EVENTS = {
|
|
2394
|
-
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
2395
|
-
SDK_METHOD_INVOKED: "SDK_METHOD_INVOKED",
|
|
2396
|
-
SDK_METHOD_ERROR: "SDK_METHOD_ERROR",
|
|
2397
|
-
CLI_INVOKED: "CLI_INVOKED"
|
|
2398
|
-
};
|
|
2399
|
-
|
|
2400
|
-
// src/utils/constants.ts
|
|
2401
|
-
var COMPOSIO_DIR = ".composio";
|
|
2402
|
-
var USER_DATA_FILE_NAME = "user_data.json";
|
|
2403
|
-
var DEFAULT_BASE_URL = "https://backend.composio.dev";
|
|
2404
|
-
var TELEMETRY_URL = "https://app.composio.dev";
|
|
2405
|
-
var IS_DEVELOPMENT_OR_CI = process.env.DEVELOPMENT || process.env.CI || false;
|
|
2406
|
-
|
|
2407
|
-
// src/telemetry/BatchProcessor.ts
|
|
2408
|
-
var BatchProcessor = class {
|
|
2409
|
-
batch = [];
|
|
2410
|
-
time;
|
|
2411
|
-
batchSize;
|
|
2412
|
-
processBatchCallback;
|
|
2413
|
-
timer = null;
|
|
2414
|
-
constructor(time = 2e3, batchSize = 100, processBatchCallback) {
|
|
2415
|
-
this.batch = [];
|
|
2416
|
-
this.time = time;
|
|
2417
|
-
this.batchSize = batchSize;
|
|
2418
|
-
this.processBatchCallback = processBatchCallback;
|
|
2419
|
-
}
|
|
2420
|
-
pushItem(item) {
|
|
2421
|
-
this.batch.push(item);
|
|
2422
|
-
if (this.batch.length >= this.batchSize) {
|
|
2423
|
-
this.processBatch();
|
|
2424
|
-
} else if (!this.timer) {
|
|
2425
|
-
this.timer = setTimeout(() => this.processBatch(), this.time);
|
|
2426
|
-
}
|
|
2427
|
-
}
|
|
2428
|
-
processBatch() {
|
|
2429
|
-
if (this.batch.length > 0) {
|
|
2430
|
-
this.processBatchCallback(this.batch);
|
|
2431
|
-
this.batch = [];
|
|
2432
|
-
}
|
|
2433
|
-
if (this.timer) {
|
|
2434
|
-
clearTimeout(this.timer);
|
|
2435
|
-
this.timer = null;
|
|
2436
|
-
}
|
|
2437
|
-
}
|
|
2438
|
-
};
|
|
2439
|
-
|
|
2440
|
-
// src/telemetry/transports/BrowserTransport.ts
|
|
2441
|
-
var BrowserTelemetryTransport = class {
|
|
2442
|
-
send(payload) {
|
|
2443
|
-
if (typeof window === "undefined") {
|
|
2444
|
-
return Promise.reject(
|
|
2445
|
-
new Error("BrowserTelemetryTransport can only be used in browser environments")
|
|
2446
|
-
);
|
|
2447
|
-
}
|
|
2448
|
-
return new Promise((resolve) => {
|
|
2449
|
-
try {
|
|
2450
|
-
const xhr = new XMLHttpRequest();
|
|
2451
|
-
xhr.open(payload.method, payload.url, true);
|
|
2452
|
-
xhr.setRequestHeader("Content-Type", "application/json");
|
|
2453
|
-
Object.entries(payload.headers || {}).forEach(([key, value]) => {
|
|
2454
|
-
xhr.setRequestHeader(key, value);
|
|
2455
|
-
});
|
|
2456
|
-
xhr.onload = function() {
|
|
2457
|
-
resolve();
|
|
2458
|
-
};
|
|
2459
|
-
xhr.send(JSON.stringify(payload.data));
|
|
2460
|
-
} catch (error) {
|
|
2461
|
-
logger_default.error("Error sending error to telemetry", error);
|
|
2462
|
-
resolve();
|
|
2463
|
-
}
|
|
2464
|
-
});
|
|
2465
|
-
}
|
|
2466
|
-
};
|
|
2467
|
-
|
|
2468
|
-
// src/telemetry/transports/ProcessTransport.ts
|
|
2469
|
-
var ProcessTelemetryTransport = class {
|
|
2470
|
-
send(payload) {
|
|
2471
|
-
if (typeof window !== "undefined") {
|
|
2472
|
-
return Promise.reject(
|
|
2473
|
-
new Error("ProcessTelemetryTransport can only be used in Node.js environments")
|
|
2474
|
-
);
|
|
2475
|
-
}
|
|
2476
|
-
return new Promise((resolve) => {
|
|
2477
|
-
try {
|
|
2478
|
-
const url = new URL(payload.url);
|
|
2479
|
-
const protocol = url.protocol === "https:" ? "https" : "http";
|
|
2480
|
-
const port = url.port || (url.protocol === "https:" ? 443 : 80);
|
|
2481
|
-
const args = [
|
|
2482
|
-
"-e",
|
|
2483
|
-
`
|
|
2484
|
-
const http = require('${protocol}');
|
|
2485
|
-
const options = {
|
|
2486
|
-
hostname: '${url.hostname}',
|
|
2487
|
-
path: '${url.pathname}${url.search}',
|
|
2488
|
-
port: ${port},
|
|
2489
|
-
method: '${payload.method}',
|
|
2490
|
-
headers: ${JSON.stringify(payload.headers)}
|
|
2491
|
-
};
|
|
2492
|
-
|
|
2493
|
-
const req = http.request(options, (res) => {
|
|
2494
|
-
res.on('data', () => {});
|
|
2495
|
-
res.on('end', () => {
|
|
2496
|
-
process.exit(0);
|
|
2497
|
-
});
|
|
2498
|
-
});
|
|
2499
|
-
|
|
2500
|
-
req.on('error', () => {
|
|
2501
|
-
process.exit(0);
|
|
2502
|
-
});
|
|
2503
|
-
|
|
2504
|
-
req.write(JSON.stringify(${JSON.stringify(payload.data)}));
|
|
2505
|
-
req.end();
|
|
2506
|
-
`
|
|
2507
|
-
];
|
|
2508
|
-
import("child_process").then(({ spawn }) => {
|
|
2509
|
-
spawn("node", args, {
|
|
2510
|
-
stdio: "ignore",
|
|
2511
|
-
detached: true,
|
|
2512
|
-
shell: false
|
|
2513
|
-
}).unref();
|
|
2514
|
-
resolve();
|
|
2515
|
-
}).catch(() => {
|
|
2516
|
-
resolve();
|
|
2517
|
-
});
|
|
2518
|
-
} catch (error) {
|
|
2519
|
-
logger_default.error("Error sending telemetry", error);
|
|
2520
|
-
resolve();
|
|
2521
|
-
}
|
|
3520
|
+
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
3521
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
3522
|
+
*/
|
|
3523
|
+
async create(slug, body) {
|
|
3524
|
+
const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body);
|
|
3525
|
+
if (!parsedBody.success) {
|
|
3526
|
+
throw new ValidationError(`Invalid parameters passed to create trigger`, {
|
|
3527
|
+
cause: parsedBody.error
|
|
3528
|
+
});
|
|
3529
|
+
}
|
|
3530
|
+
const result = await this.client.triggerInstances.upsert(slug, {
|
|
3531
|
+
connected_account_id: parsedBody.data.connectedAccountId,
|
|
3532
|
+
trigger_config: parsedBody.data.triggerConfig
|
|
2522
3533
|
});
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
batchProcessor = new BatchProcessor(100, 10, async (data) => {
|
|
2531
|
-
await this.sendTelemetry(data);
|
|
2532
|
-
});
|
|
2533
|
-
constructor(metadata, transport) {
|
|
2534
|
-
this.telemetryMetadata = metadata;
|
|
2535
|
-
const isBrowser = typeof window !== "undefined";
|
|
2536
|
-
if (transport) {
|
|
2537
|
-
this.transport = transport;
|
|
2538
|
-
} else if (isBrowser) {
|
|
2539
|
-
this.transport = new BrowserTelemetryTransport();
|
|
2540
|
-
} else {
|
|
2541
|
-
this.transport = new ProcessTelemetryTransport();
|
|
3534
|
+
const parsedResult = TriggerInstanceUpsertResponseSchema.safeParse({
|
|
3535
|
+
triggerId: result.trigger_id
|
|
3536
|
+
});
|
|
3537
|
+
if (!parsedResult.success) {
|
|
3538
|
+
throw new ValidationError(`Invalid trigger instance upsert response`, {
|
|
3539
|
+
cause: parsedResult.error
|
|
3540
|
+
});
|
|
2542
3541
|
}
|
|
2543
|
-
|
|
2544
|
-
{
|
|
2545
|
-
eventName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
2546
|
-
data: {},
|
|
2547
|
-
sdk_meta: this.telemetryMetadata
|
|
2548
|
-
}
|
|
2549
|
-
]);
|
|
3542
|
+
return parsedResult.data;
|
|
2550
3543
|
}
|
|
2551
3544
|
/**
|
|
2552
|
-
*
|
|
3545
|
+
* Update an existing trigger instance
|
|
2553
3546
|
*
|
|
2554
|
-
*
|
|
2555
|
-
*
|
|
2556
|
-
* @
|
|
2557
|
-
|
|
3547
|
+
* @param {string} slug - The slug of the trigger instance
|
|
3548
|
+
* @param {TriggerInstanceManageUpdateParams} body - The parameters to create the trigger instance
|
|
3549
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
3550
|
+
*/
|
|
3551
|
+
async update(slug, body) {
|
|
3552
|
+
return this.client.triggerInstances.manage.update(slug, body);
|
|
3553
|
+
}
|
|
3554
|
+
/**
|
|
3555
|
+
* Delete a trigger instance
|
|
3556
|
+
*
|
|
3557
|
+
* @param {string} triggerId - The slug of the trigger instance
|
|
2558
3558
|
* @returns
|
|
2559
3559
|
*/
|
|
2560
|
-
|
|
2561
|
-
const
|
|
2562
|
-
const
|
|
2563
|
-
|
|
2564
|
-
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
3560
|
+
async delete(triggerId) {
|
|
3561
|
+
const result = await this.client.triggerInstances.manage.delete(triggerId);
|
|
3562
|
+
const parsedResult = TriggerInstanceManageDeleteResponseSchema.safeParse({
|
|
3563
|
+
triggerId: result.trigger_id
|
|
2565
3564
|
});
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
const telemetryPayload = {
|
|
2571
|
-
eventName: TELEMETRY_EVENTS.SDK_METHOD_INVOKED,
|
|
2572
|
-
data: {
|
|
2573
|
-
fileName: instrumentedClassName,
|
|
2574
|
-
method: name,
|
|
2575
|
-
params: args
|
|
2576
|
-
},
|
|
2577
|
-
sdk_meta: this.telemetryMetadata
|
|
2578
|
-
};
|
|
2579
|
-
this.batchProcessor.pushItem(telemetryPayload);
|
|
2580
|
-
try {
|
|
2581
|
-
return await originalMethod.apply(instance, args);
|
|
2582
|
-
} catch (error) {
|
|
2583
|
-
const telemetryPayload2 = {
|
|
2584
|
-
eventName: TELEMETRY_EVENTS.SDK_METHOD_ERROR,
|
|
2585
|
-
data: {
|
|
2586
|
-
fileName: instrumentedClassName,
|
|
2587
|
-
method: name,
|
|
2588
|
-
params: args,
|
|
2589
|
-
error
|
|
2590
|
-
},
|
|
2591
|
-
sdk_meta: this.telemetryMetadata
|
|
2592
|
-
};
|
|
2593
|
-
this.batchProcessor.pushItem(telemetryPayload2);
|
|
2594
|
-
throw error;
|
|
2595
|
-
}
|
|
2596
|
-
};
|
|
3565
|
+
if (!parsedResult.success) {
|
|
3566
|
+
throw new ValidationError(`Invalid trigger instance manage delete response`, {
|
|
3567
|
+
cause: parsedResult.error
|
|
3568
|
+
});
|
|
2597
3569
|
}
|
|
2598
|
-
return
|
|
3570
|
+
return parsedResult.data;
|
|
2599
3571
|
}
|
|
2600
3572
|
/**
|
|
2601
|
-
*
|
|
2602
|
-
*
|
|
3573
|
+
* Disable a trigger instance
|
|
3574
|
+
*
|
|
3575
|
+
* @param {string} triggerId - The id of the trigger instance
|
|
3576
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
3577
|
+
*/
|
|
3578
|
+
async disable(triggerId) {
|
|
3579
|
+
return this.client.triggerInstances.manage.update(triggerId, {
|
|
3580
|
+
status: "disable"
|
|
3581
|
+
});
|
|
3582
|
+
}
|
|
3583
|
+
/**
|
|
3584
|
+
* Enable a trigger instance
|
|
3585
|
+
*
|
|
3586
|
+
* @param {string} triggerId - The id of the trigger instance
|
|
3587
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
3588
|
+
*/
|
|
3589
|
+
async enable(triggerId) {
|
|
3590
|
+
return this.client.triggerInstances.manage.update(triggerId, {
|
|
3591
|
+
status: "enable"
|
|
3592
|
+
});
|
|
3593
|
+
}
|
|
3594
|
+
/**
|
|
3595
|
+
* @TODO Learn about trigger types
|
|
3596
|
+
*/
|
|
3597
|
+
/**
|
|
3598
|
+
* List all the trigger types
|
|
3599
|
+
*
|
|
3600
|
+
* @param {TriggersTypeListParams} query - The query parameters to filter the trigger types
|
|
3601
|
+
* @param {RequestOptions} options - Request options
|
|
3602
|
+
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
|
|
3603
|
+
*/
|
|
3604
|
+
async listTypes(query) {
|
|
3605
|
+
return this.client.triggersTypes.list(query);
|
|
3606
|
+
}
|
|
3607
|
+
/**
|
|
3608
|
+
* Retrieve a trigger type by its slug
|
|
3609
|
+
*
|
|
3610
|
+
* @param {string} slug - The slug of the trigger type
|
|
3611
|
+
* @param {RequestOptions} options - request options
|
|
3612
|
+
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
3613
|
+
*/
|
|
3614
|
+
async getType(slug) {
|
|
3615
|
+
return this.client.triggersTypes.retrieve(slug);
|
|
3616
|
+
}
|
|
3617
|
+
/**
|
|
3618
|
+
* Fetches the list of all the available trigger enums
|
|
3619
|
+
*
|
|
3620
|
+
* This method is used by the CLI where filters are not required.
|
|
3621
|
+
* @param options
|
|
2603
3622
|
* @returns
|
|
2604
3623
|
*/
|
|
2605
|
-
async
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
3624
|
+
async listEnum() {
|
|
3625
|
+
return this.client.triggersTypes.retrieveEnum();
|
|
3626
|
+
}
|
|
3627
|
+
/**
|
|
3628
|
+
* Subscribe to all the triggers
|
|
3629
|
+
*
|
|
3630
|
+
* @param fn - The function to call when a trigger is received
|
|
3631
|
+
* @param filters - The filters to apply to the triggers
|
|
3632
|
+
*
|
|
3633
|
+
* @example
|
|
3634
|
+
* ```ts
|
|
3635
|
+
*
|
|
3636
|
+
* triggers.subscribe((data) => {
|
|
3637
|
+
* console.log(data);
|
|
3638
|
+
* }, );
|
|
3639
|
+
* ```
|
|
3640
|
+
*/
|
|
3641
|
+
async subscribe(fn, filters = {}) {
|
|
3642
|
+
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
3643
|
+
const parsedFilters = TriggerSubscribeParamSchema.safeParse(filters);
|
|
3644
|
+
if (!parsedFilters.success) {
|
|
3645
|
+
throw new ValidationError(`Invalid parameters passed to subscribe to triggers`, {
|
|
3646
|
+
cause: parsedFilters.error
|
|
3647
|
+
});
|
|
2609
3648
|
}
|
|
2610
|
-
const
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
3649
|
+
const shouldSendTriggerAfterFilters = (data) => {
|
|
3650
|
+
if (parsedFilters.data.toolkits?.length && !parsedFilters.data.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
|
|
3651
|
+
logger_default.debug(
|
|
3652
|
+
"Trigger does not match toolkits filter",
|
|
3653
|
+
JSON.stringify(parsedFilters.data.toolkits, null, 2)
|
|
3654
|
+
);
|
|
3655
|
+
return false;
|
|
3656
|
+
}
|
|
3657
|
+
if (parsedFilters.data.triggerId && parsedFilters.data.triggerId !== data.id) {
|
|
3658
|
+
logger_default.debug(
|
|
3659
|
+
"Trigger does not match triggerId filter",
|
|
3660
|
+
JSON.stringify(parsedFilters.data.triggerId, null, 2)
|
|
3661
|
+
);
|
|
3662
|
+
return false;
|
|
3663
|
+
}
|
|
3664
|
+
if (parsedFilters.data.connectedAccountId && parsedFilters.data.connectedAccountId !== data.metadata.connectedAccount.id) {
|
|
3665
|
+
logger_default.debug(
|
|
3666
|
+
"Trigger does not match connectedAccountId filter",
|
|
3667
|
+
JSON.stringify(parsedFilters.data.connectedAccountId, null, 2)
|
|
3668
|
+
);
|
|
3669
|
+
return false;
|
|
3670
|
+
}
|
|
3671
|
+
if (parsedFilters.data.triggerSlug?.length && !parsedFilters.data.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
|
|
3672
|
+
logger_default.debug(
|
|
3673
|
+
"Trigger does not match triggerSlug filter",
|
|
3674
|
+
JSON.stringify(parsedFilters.data.triggerSlug, null, 2)
|
|
3675
|
+
);
|
|
3676
|
+
return false;
|
|
3677
|
+
}
|
|
3678
|
+
if (parsedFilters.data.triggerData && parsedFilters.data.triggerData !== data.metadata.triggerData) {
|
|
3679
|
+
logger_default.debug(
|
|
3680
|
+
"Trigger does not match triggerData filter",
|
|
3681
|
+
JSON.stringify(parsedFilters.data.triggerData, null, 2)
|
|
3682
|
+
);
|
|
3683
|
+
return false;
|
|
3684
|
+
}
|
|
3685
|
+
if (parsedFilters.data.userId && parsedFilters.data.userId !== data.metadata.connectedAccount.userId) {
|
|
3686
|
+
logger_default.debug(
|
|
3687
|
+
"Trigger does not match userId filter",
|
|
3688
|
+
JSON.stringify(parsedFilters.data.userId, null, 2)
|
|
3689
|
+
);
|
|
3690
|
+
return false;
|
|
3691
|
+
}
|
|
3692
|
+
logger_default.debug("Trigger matches all filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
3693
|
+
return true;
|
|
2616
3694
|
};
|
|
2617
|
-
|
|
3695
|
+
logger_default.debug("\u{1F504} Subscribing to triggers with filters: ", JSON.stringify(filters, null, 2));
|
|
3696
|
+
await this.pusherService.subscribe((_data) => {
|
|
3697
|
+
logger_default.debug("Received raw trigger data", JSON.stringify(_data, null, 2));
|
|
3698
|
+
const data = _data;
|
|
3699
|
+
const parsedData = IncomingTriggerPayloadSchema.safeParse({
|
|
3700
|
+
id: data.metadata.id,
|
|
3701
|
+
triggerSlug: data.metadata.triggerName,
|
|
3702
|
+
toolkitSlug: data.appName,
|
|
3703
|
+
userId: data.metadata.connection?.clientUniqueUserId,
|
|
3704
|
+
payload: data.payload,
|
|
3705
|
+
originalPayload: data.originalPayload,
|
|
3706
|
+
metadata: {
|
|
3707
|
+
id: data.metadata.id,
|
|
3708
|
+
triggerConfig: data.metadata.triggerConfig,
|
|
3709
|
+
triggerSlug: data.metadata.triggerName,
|
|
3710
|
+
toolkitSlug: data.appName,
|
|
3711
|
+
triggerData: data.metadata.triggerData,
|
|
3712
|
+
connectedAccount: {
|
|
3713
|
+
id: data.metadata.connection?.connectedAccountNanoId,
|
|
3714
|
+
uuid: data.metadata.connection?.id,
|
|
3715
|
+
authConfigId: data.metadata.connection?.authConfigNanoId,
|
|
3716
|
+
authConfigUUID: data.metadata.connection?.integrationId,
|
|
3717
|
+
userId: data.metadata.connection?.clientUniqueUserId,
|
|
3718
|
+
status: data.metadata.connection?.status
|
|
3719
|
+
}
|
|
3720
|
+
}
|
|
3721
|
+
});
|
|
3722
|
+
logger_default.debug("Parsed trigger data", JSON.stringify(parsedData.data, null, 2));
|
|
3723
|
+
if (parsedData.error) {
|
|
3724
|
+
throw new ValidationError(`Invalid trigger payload`, {
|
|
3725
|
+
cause: parsedData.error
|
|
3726
|
+
});
|
|
3727
|
+
}
|
|
3728
|
+
if (shouldSendTriggerAfterFilters(parsedData.data)) {
|
|
3729
|
+
try {
|
|
3730
|
+
fn(parsedData.data);
|
|
3731
|
+
} catch (error) {
|
|
3732
|
+
logger_default.error("\u274C Error in trigger callback:", error);
|
|
3733
|
+
}
|
|
3734
|
+
} else {
|
|
3735
|
+
logger_default.debug("Trigger does not match filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
3736
|
+
}
|
|
3737
|
+
});
|
|
3738
|
+
}
|
|
3739
|
+
/**
|
|
3740
|
+
* Unsubscribe from all the triggers
|
|
3741
|
+
*
|
|
3742
|
+
* @returns {Promise<void>}
|
|
3743
|
+
*
|
|
3744
|
+
* @example
|
|
3745
|
+
* ```ts
|
|
3746
|
+
* composio.trigger.subscribe((data) => {
|
|
3747
|
+
* console.log(data);
|
|
3748
|
+
* });
|
|
3749
|
+
*
|
|
3750
|
+
* await triggers.unsubscribe();
|
|
3751
|
+
* ```
|
|
3752
|
+
*/
|
|
3753
|
+
async unsubscribe() {
|
|
3754
|
+
await this.pusherService.unsubscribe();
|
|
2618
3755
|
}
|
|
2619
3756
|
};
|
|
2620
3757
|
|
|
@@ -2625,6 +3762,7 @@ var userDataPath = () => {
|
|
|
2625
3762
|
const os = __require("os");
|
|
2626
3763
|
return path.join(os.homedir(), COMPOSIO_DIR, USER_DATA_FILE_NAME);
|
|
2627
3764
|
} catch (_error) {
|
|
3765
|
+
logger_default.debug("Environment", `Unable to get user data path`);
|
|
2628
3766
|
return null;
|
|
2629
3767
|
}
|
|
2630
3768
|
};
|
|
@@ -2634,6 +3772,7 @@ var getUserDataJson = () => {
|
|
|
2634
3772
|
const data = fs.readFileSync(userDataPath(), "utf8");
|
|
2635
3773
|
return JSON.parse(data);
|
|
2636
3774
|
} catch (_error) {
|
|
3775
|
+
logger_default.debug("Environment", "No user data file found");
|
|
2637
3776
|
return {};
|
|
2638
3777
|
}
|
|
2639
3778
|
};
|
|
@@ -2642,27 +3781,33 @@ function getSDKConfig(baseUrl, apiKey) {
|
|
|
2642
3781
|
const { api_key: apiKeyFromUserConfig, base_url: baseURLFromUserConfig } = userData;
|
|
2643
3782
|
const baseURLParsed = baseUrl || getEnvVariable("COMPOSIO_BASE_URL") || baseURLFromUserConfig || DEFAULT_BASE_URL;
|
|
2644
3783
|
const apiKeyParsed = apiKey || getEnvVariable("COMPOSIO_API_KEY") || apiKeyFromUserConfig || "";
|
|
3784
|
+
if (!apiKeyParsed) {
|
|
3785
|
+
ComposioError.handle(new ComposioNoAPIKeyError(), {
|
|
3786
|
+
exitProcess: true
|
|
3787
|
+
});
|
|
3788
|
+
}
|
|
3789
|
+
logger_default.debug("Environment", `API Key: ${apiKeyParsed}`);
|
|
3790
|
+
logger_default.debug("Environment", `Base URL: ${baseURLParsed}`);
|
|
2645
3791
|
return { baseURL: baseURLParsed, apiKey: apiKeyParsed };
|
|
2646
3792
|
}
|
|
2647
3793
|
|
|
2648
3794
|
// src/utils/version.ts
|
|
2649
|
-
|
|
2650
|
-
const v1 = version1.split(".").map(Number);
|
|
2651
|
-
const v2 = version2.split(".").map(Number);
|
|
2652
|
-
for (let i = 0; i < 3; i++) {
|
|
2653
|
-
if (v1[i] > v2[i]) return true;
|
|
2654
|
-
if (v1[i] < v2[i]) return false;
|
|
2655
|
-
}
|
|
2656
|
-
return false;
|
|
2657
|
-
}
|
|
3795
|
+
import semver from "semver";
|
|
2658
3796
|
async function checkForLatestVersionFromNPM(currentVersion) {
|
|
2659
3797
|
try {
|
|
2660
|
-
const packageName = "composio
|
|
3798
|
+
const packageName = "@composio/core";
|
|
2661
3799
|
const currentVersionFromPackageJson = currentVersion;
|
|
3800
|
+
if (!semver.valid(currentVersionFromPackageJson)) {
|
|
3801
|
+
return;
|
|
3802
|
+
}
|
|
3803
|
+
const prerelease = semver.prerelease(currentVersionFromPackageJson);
|
|
3804
|
+
if (prerelease && (String(prerelease[0]).includes("alpha") || String(prerelease[0]).includes("beta"))) {
|
|
3805
|
+
return;
|
|
3806
|
+
}
|
|
2662
3807
|
const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`);
|
|
2663
3808
|
const data = await response.json();
|
|
2664
3809
|
const latestVersion = data.version;
|
|
2665
|
-
if (
|
|
3810
|
+
if (semver.gt(latestVersion, currentVersionFromPackageJson) && !IS_DEVELOPMENT_OR_CI) {
|
|
2666
3811
|
logger_default.info(
|
|
2667
3812
|
`\u{1F680} Upgrade available! Your composio-core version (${currentVersionFromPackageJson}) is behind. Latest version: ${latestVersion}.`
|
|
2668
3813
|
);
|
|
@@ -2689,11 +3834,12 @@ var BaseProvider = class {
|
|
|
2689
3834
|
}
|
|
2690
3835
|
/**
|
|
2691
3836
|
* @public
|
|
2692
|
-
*
|
|
2693
|
-
* This function is used by
|
|
3837
|
+
* Global function to execute a tool.
|
|
3838
|
+
* This function is used by providerds to implement helper functions to execute tools.
|
|
2694
3839
|
* This is a 1:1 mapping of the `execute` method in the `Tools` class.
|
|
2695
3840
|
* @param {string} toolSlug - The slug of the tool to execute.
|
|
2696
|
-
* @param {
|
|
3841
|
+
* @param {ToolExecuteParams} body - The body of the tool execution.
|
|
3842
|
+
* @param {ExecuteToolModifiers} modifers - The modifiers of the tool execution.
|
|
2697
3843
|
* @returns {Promise<string>} The result of the tool execution.
|
|
2698
3844
|
*/
|
|
2699
3845
|
executeTool(toolSlug, body, modifers) {
|
|
@@ -2714,10 +3860,54 @@ var BaseAgenticProvider = class extends BaseProvider {
|
|
|
2714
3860
|
var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
2715
3861
|
name = "openai";
|
|
2716
3862
|
/**
|
|
2717
|
-
*
|
|
2718
|
-
*
|
|
2719
|
-
*
|
|
2720
|
-
*
|
|
3863
|
+
* Creates a new instance of the OpenAIProvider.
|
|
3864
|
+
*
|
|
3865
|
+
* This is the default provider for the Composio SDK and is automatically
|
|
3866
|
+
* available without additional installation.
|
|
3867
|
+
*
|
|
3868
|
+
* @example
|
|
3869
|
+
* ```typescript
|
|
3870
|
+
* // The OpenAIProvider is used by default when initializing Composio
|
|
3871
|
+
* const composio = new Composio({
|
|
3872
|
+
* apiKey: 'your-api-key'
|
|
3873
|
+
* });
|
|
3874
|
+
*
|
|
3875
|
+
* // You can also explicitly specify it
|
|
3876
|
+
* const composio = new Composio({
|
|
3877
|
+
* apiKey: 'your-api-key',
|
|
3878
|
+
* provider: new OpenAIProvider()
|
|
3879
|
+
* });
|
|
3880
|
+
* ```
|
|
3881
|
+
*/
|
|
3882
|
+
constructor() {
|
|
3883
|
+
super();
|
|
3884
|
+
}
|
|
3885
|
+
/**
|
|
3886
|
+
* Wraps a Composio tool in the OpenAI function calling format.
|
|
3887
|
+
*
|
|
3888
|
+
* This method transforms a Composio tool definition into the format
|
|
3889
|
+
* expected by OpenAI's function calling API.
|
|
3890
|
+
*
|
|
3891
|
+
* @param tool - The Composio tool to wrap
|
|
3892
|
+
* @returns The wrapped tool in OpenAI format
|
|
3893
|
+
*
|
|
3894
|
+
* @example
|
|
3895
|
+
* ```typescript
|
|
3896
|
+
* // Wrap a single tool for use with OpenAI
|
|
3897
|
+
* const composioTool = {
|
|
3898
|
+
* slug: 'SEARCH_TOOL',
|
|
3899
|
+
* description: 'Search for information',
|
|
3900
|
+
* inputParameters: {
|
|
3901
|
+
* type: 'object',
|
|
3902
|
+
* properties: {
|
|
3903
|
+
* query: { type: 'string' }
|
|
3904
|
+
* },
|
|
3905
|
+
* required: ['query']
|
|
3906
|
+
* }
|
|
3907
|
+
* };
|
|
3908
|
+
*
|
|
3909
|
+
* const openAITool = provider.wrapTool(composioTool);
|
|
3910
|
+
* ```
|
|
2721
3911
|
*/
|
|
2722
3912
|
wrapTool = (tool) => {
|
|
2723
3913
|
const formattedSchema = {
|
|
@@ -2730,14 +3920,78 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2730
3920
|
function: formattedSchema
|
|
2731
3921
|
};
|
|
2732
3922
|
};
|
|
3923
|
+
/**
|
|
3924
|
+
* Wraps multiple Composio tools in the OpenAI function calling format.
|
|
3925
|
+
*
|
|
3926
|
+
* This method transforms a list of Composio tools into the format
|
|
3927
|
+
* expected by OpenAI's function calling API.
|
|
3928
|
+
*
|
|
3929
|
+
* @param tools - Array of Composio tools to wrap
|
|
3930
|
+
* @returns Array of wrapped tools in OpenAI format
|
|
3931
|
+
*
|
|
3932
|
+
* @example
|
|
3933
|
+
* ```typescript
|
|
3934
|
+
* // Wrap multiple tools for use with OpenAI
|
|
3935
|
+
* const composioTools = [
|
|
3936
|
+
* {
|
|
3937
|
+
* slug: 'SEARCH_TOOL',
|
|
3938
|
+
* description: 'Search for information',
|
|
3939
|
+
* inputParameters: {
|
|
3940
|
+
* type: 'object',
|
|
3941
|
+
* properties: {
|
|
3942
|
+
* query: { type: 'string' }
|
|
3943
|
+
* }
|
|
3944
|
+
* }
|
|
3945
|
+
* },
|
|
3946
|
+
* {
|
|
3947
|
+
* slug: 'WEATHER_TOOL',
|
|
3948
|
+
* description: 'Get weather information',
|
|
3949
|
+
* inputParameters: {
|
|
3950
|
+
* type: 'object',
|
|
3951
|
+
* properties: {
|
|
3952
|
+
* location: { type: 'string' }
|
|
3953
|
+
* }
|
|
3954
|
+
* }
|
|
3955
|
+
* }
|
|
3956
|
+
* ];
|
|
3957
|
+
*
|
|
3958
|
+
* const openAITools = provider.wrapTools(composioTools);
|
|
3959
|
+
* ```
|
|
3960
|
+
*/
|
|
2733
3961
|
wrapTools = (tools) => {
|
|
2734
3962
|
return tools.map((tool) => this.wrapTool(tool));
|
|
2735
3963
|
};
|
|
2736
3964
|
/**
|
|
2737
|
-
*
|
|
2738
|
-
*
|
|
2739
|
-
*
|
|
2740
|
-
*
|
|
3965
|
+
* Executes a tool call from OpenAI's chat completion.
|
|
3966
|
+
*
|
|
3967
|
+
* This method processes a tool call from OpenAI's chat completion API,
|
|
3968
|
+
* executes the corresponding Composio tool, and returns the result.
|
|
3969
|
+
*
|
|
3970
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
3971
|
+
* @param {OpenAI.ChatCompletionMessageToolCall} tool - The tool call from OpenAI
|
|
3972
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
3973
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
3974
|
+
* @returns {Promise<string>} The result of the tool call as a JSON string
|
|
3975
|
+
*
|
|
3976
|
+
* @example
|
|
3977
|
+
* ```typescript
|
|
3978
|
+
* // Execute a tool call from OpenAI
|
|
3979
|
+
* const toolCall = {
|
|
3980
|
+
* id: 'call_abc123',
|
|
3981
|
+
* type: 'function',
|
|
3982
|
+
* function: {
|
|
3983
|
+
* name: 'SEARCH_TOOL',
|
|
3984
|
+
* arguments: '{"query":"composio documentation"}'
|
|
3985
|
+
* }
|
|
3986
|
+
* };
|
|
3987
|
+
*
|
|
3988
|
+
* const result = await provider.executeToolCall(
|
|
3989
|
+
* 'user123',
|
|
3990
|
+
* toolCall,
|
|
3991
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
3992
|
+
* );
|
|
3993
|
+
* console.log(JSON.parse(result));
|
|
3994
|
+
* ```
|
|
2741
3995
|
*/
|
|
2742
3996
|
async executeToolCall(userId, tool, options, modifiers) {
|
|
2743
3997
|
const payload = {
|
|
@@ -2750,13 +4004,48 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2750
4004
|
return JSON.stringify(result);
|
|
2751
4005
|
}
|
|
2752
4006
|
/**
|
|
2753
|
-
*
|
|
4007
|
+
* Handles tool calls from OpenAI's chat completion response.
|
|
2754
4008
|
*
|
|
2755
|
-
*
|
|
2756
|
-
*
|
|
2757
|
-
*
|
|
4009
|
+
* This method processes tool calls from an OpenAI chat completion response,
|
|
4010
|
+
* executes each tool call, and returns the results.
|
|
4011
|
+
*
|
|
4012
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
4013
|
+
* @param {OpenAI.ChatCompletion} chatCompletion - The chat completion response from OpenAI
|
|
4014
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
4015
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
4016
|
+
* @returns {Promise<string[]>} Array of tool execution results as JSON strings
|
|
4017
|
+
*
|
|
4018
|
+
* @example
|
|
4019
|
+
* ```typescript
|
|
4020
|
+
* // Handle tool calls from a chat completion response
|
|
4021
|
+
* const chatCompletion = {
|
|
4022
|
+
* choices: [
|
|
4023
|
+
* {
|
|
4024
|
+
* message: {
|
|
4025
|
+
* tool_calls: [
|
|
4026
|
+
* {
|
|
4027
|
+
* id: 'call_abc123',
|
|
4028
|
+
* type: 'function',
|
|
4029
|
+
* function: {
|
|
4030
|
+
* name: 'SEARCH_TOOL',
|
|
4031
|
+
* arguments: '{"query":"composio documentation"}'
|
|
4032
|
+
* }
|
|
4033
|
+
* }
|
|
4034
|
+
* ]
|
|
4035
|
+
* }
|
|
4036
|
+
* }
|
|
4037
|
+
* ]
|
|
4038
|
+
* };
|
|
4039
|
+
*
|
|
4040
|
+
* const results = await provider.handleToolCalls(
|
|
4041
|
+
* 'user123',
|
|
4042
|
+
* chatCompletion,
|
|
4043
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
4044
|
+
* );
|
|
4045
|
+
* console.log(results); // Array of tool execution results
|
|
4046
|
+
* ```
|
|
2758
4047
|
*/
|
|
2759
|
-
async
|
|
4048
|
+
async handleToolCalls(userId, chatCompletion, options, modifiers) {
|
|
2760
4049
|
const outputs = [];
|
|
2761
4050
|
for (const message of chatCompletion.choices) {
|
|
2762
4051
|
if (message.message.tool_calls) {
|
|
@@ -2768,11 +4057,51 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2768
4057
|
return outputs;
|
|
2769
4058
|
}
|
|
2770
4059
|
/**
|
|
2771
|
-
* Handles all the tool calls from the
|
|
4060
|
+
* Handles all the tool calls from the OpenAI Assistant API.
|
|
2772
4061
|
*
|
|
2773
|
-
*
|
|
2774
|
-
*
|
|
2775
|
-
*
|
|
4062
|
+
* This method processes tool calls from an OpenAI Assistant run,
|
|
4063
|
+
* executes each tool call, and returns the tool outputs for submission.
|
|
4064
|
+
*
|
|
4065
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
4066
|
+
* @param {OpenAI.Beta.Threads.Run} run - The Assistant run object containing tool calls
|
|
4067
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
4068
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
4069
|
+
* @returns {Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>} Array of tool outputs for submission
|
|
4070
|
+
*
|
|
4071
|
+
* @example
|
|
4072
|
+
* ```typescript
|
|
4073
|
+
* // Handle tool calls from an OpenAI Assistant run
|
|
4074
|
+
* const run = {
|
|
4075
|
+
* id: 'run_abc123',
|
|
4076
|
+
* required_action: {
|
|
4077
|
+
* submit_tool_outputs: {
|
|
4078
|
+
* tool_calls: [
|
|
4079
|
+
* {
|
|
4080
|
+
* id: 'call_xyz789',
|
|
4081
|
+
* type: 'function',
|
|
4082
|
+
* function: {
|
|
4083
|
+
* name: 'SEARCH_TOOL',
|
|
4084
|
+
* arguments: '{"query":"composio documentation"}'
|
|
4085
|
+
* }
|
|
4086
|
+
* }
|
|
4087
|
+
* ]
|
|
4088
|
+
* }
|
|
4089
|
+
* }
|
|
4090
|
+
* };
|
|
4091
|
+
*
|
|
4092
|
+
* const toolOutputs = await provider.handleAssistantMessage(
|
|
4093
|
+
* 'user123',
|
|
4094
|
+
* run,
|
|
4095
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
4096
|
+
* );
|
|
4097
|
+
*
|
|
4098
|
+
* // Submit tool outputs back to OpenAI
|
|
4099
|
+
* await openai.beta.threads.runs.submitToolOutputs(
|
|
4100
|
+
* thread.id,
|
|
4101
|
+
* run.id,
|
|
4102
|
+
* { tool_outputs: toolOutputs }
|
|
4103
|
+
* );
|
|
4104
|
+
* ```
|
|
2776
4105
|
*/
|
|
2777
4106
|
async handleAssistantMessage(userId, run, options, modifiers) {
|
|
2778
4107
|
const tool_calls = run.required_action?.submit_tool_outputs?.tool_calls || [];
|
|
@@ -2797,11 +4126,43 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2797
4126
|
/**
|
|
2798
4127
|
* Waits for the assistant stream and handles the tool calls.
|
|
2799
4128
|
*
|
|
2800
|
-
*
|
|
2801
|
-
*
|
|
2802
|
-
*
|
|
2803
|
-
*
|
|
2804
|
-
* @
|
|
4129
|
+
* This method processes an OpenAI Assistant stream, handles any tool calls
|
|
4130
|
+
* that require action, and yields each event from the stream. It's designed
|
|
4131
|
+
* for streaming Assistant responses while handling tool calls in real-time.
|
|
4132
|
+
*
|
|
4133
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
4134
|
+
* @param {OpenAI} client - The OpenAI client instance
|
|
4135
|
+
* @param {Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>} runStream - The Assistant run stream
|
|
4136
|
+
* @param {OpenAI.Beta.Threads.Thread} thread - The thread object
|
|
4137
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
4138
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
4139
|
+
* @returns {AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>} Generator yielding stream events
|
|
4140
|
+
*
|
|
4141
|
+
* @example
|
|
4142
|
+
* ```typescript
|
|
4143
|
+
* // Process an OpenAI Assistant stream with tool calls
|
|
4144
|
+
* const thread = await openai.beta.threads.create();
|
|
4145
|
+
* const runStream = openai.beta.threads.runs.stream(thread.id, {
|
|
4146
|
+
* assistant_id: 'asst_abc123',
|
|
4147
|
+
* tools: provider.wrapTools(composioTools)
|
|
4148
|
+
* });
|
|
4149
|
+
*
|
|
4150
|
+
* // Process the stream and handle tool calls
|
|
4151
|
+
* const streamProcessor = provider.waitAndHandleAssistantStreamToolCalls(
|
|
4152
|
+
* 'user123',
|
|
4153
|
+
* openai,
|
|
4154
|
+
* runStream,
|
|
4155
|
+
* thread,
|
|
4156
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
4157
|
+
* );
|
|
4158
|
+
*
|
|
4159
|
+
* // Consume the stream events
|
|
4160
|
+
* for await (const event of streamProcessor) {
|
|
4161
|
+
* if (event.event === 'thread.message.delta') {
|
|
4162
|
+
* console.log(event.data.delta.content);
|
|
4163
|
+
* }
|
|
4164
|
+
* }
|
|
4165
|
+
* ```
|
|
2805
4166
|
*/
|
|
2806
4167
|
async *waitAndHandleAssistantStreamToolCalls(userId, client, runStream, thread, options, modifiers) {
|
|
2807
4168
|
let runId = null;
|
|
@@ -2853,11 +4214,45 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2853
4214
|
/**
|
|
2854
4215
|
* Waits for the assistant tool calls and handles them.
|
|
2855
4216
|
*
|
|
2856
|
-
*
|
|
2857
|
-
*
|
|
2858
|
-
*
|
|
2859
|
-
*
|
|
2860
|
-
* @
|
|
4217
|
+
* This method polls an OpenAI Assistant run until it completes or requires action,
|
|
4218
|
+
* handles any tool calls, and returns the final run object. It's designed for
|
|
4219
|
+
* non-streaming Assistant interactions.
|
|
4220
|
+
*
|
|
4221
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
4222
|
+
* @param {OpenAI} client - The OpenAI client instance
|
|
4223
|
+
* @param {OpenAI.Beta.Threads.Run} run - The initial run object
|
|
4224
|
+
* @param {OpenAI.Beta.Threads.Thread} thread - The thread object
|
|
4225
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
4226
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
4227
|
+
* @returns {Promise<OpenAI.Beta.Threads.Run>} The final run object after completion
|
|
4228
|
+
*
|
|
4229
|
+
* @example
|
|
4230
|
+
* ```typescript
|
|
4231
|
+
* // Process an OpenAI Assistant run with tool calls
|
|
4232
|
+
* const thread = await openai.beta.threads.create();
|
|
4233
|
+
* await openai.beta.threads.messages.create(thread.id, {
|
|
4234
|
+
* role: 'user',
|
|
4235
|
+
* content: 'Find information about Composio'
|
|
4236
|
+
* });
|
|
4237
|
+
*
|
|
4238
|
+
* let run = await openai.beta.threads.runs.create(thread.id, {
|
|
4239
|
+
* assistant_id: 'asst_abc123',
|
|
4240
|
+
* tools: provider.wrapTools(composioTools)
|
|
4241
|
+
* });
|
|
4242
|
+
*
|
|
4243
|
+
* // Wait for the run to complete, handling any tool calls
|
|
4244
|
+
* run = await provider.waitAndHandleAssistantToolCalls(
|
|
4245
|
+
* 'user123',
|
|
4246
|
+
* openai,
|
|
4247
|
+
* run,
|
|
4248
|
+
* thread,
|
|
4249
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
4250
|
+
* );
|
|
4251
|
+
*
|
|
4252
|
+
* // Get the final messages after run completion
|
|
4253
|
+
* const messages = await openai.beta.threads.messages.list(thread.id);
|
|
4254
|
+
* console.log(messages.data[0].content);
|
|
4255
|
+
* ```
|
|
2861
4256
|
*/
|
|
2862
4257
|
async waitAndHandleAssistantToolCalls(userId, client, run, thread, options, modifiers) {
|
|
2863
4258
|
while (["queued", "in_progress", "requires_action"].includes(run.status)) {
|
|
@@ -2876,13 +4271,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2876
4271
|
};
|
|
2877
4272
|
|
|
2878
4273
|
// package.json
|
|
2879
|
-
var version = "0.1.12
|
|
2880
|
-
|
|
2881
|
-
// src/utils/uuid.ts
|
|
2882
|
-
import { v4 as uuidv4 } from "uuid";
|
|
2883
|
-
function getRandomUUID() {
|
|
2884
|
-
return uuidv4();
|
|
2885
|
-
}
|
|
4274
|
+
var version = "0.1.12";
|
|
2886
4275
|
|
|
2887
4276
|
// src/composio.ts
|
|
2888
4277
|
var Composio = class {
|
|
@@ -2896,7 +4285,6 @@ var Composio = class {
|
|
|
2896
4285
|
* @type {ComposioConfig<TProvider>}
|
|
2897
4286
|
*/
|
|
2898
4287
|
config;
|
|
2899
|
-
telemetry;
|
|
2900
4288
|
/**
|
|
2901
4289
|
* Core models for Composio.
|
|
2902
4290
|
*/
|
|
@@ -2908,15 +4296,37 @@ var Composio = class {
|
|
|
2908
4296
|
authConfigs;
|
|
2909
4297
|
// connected accounts
|
|
2910
4298
|
connectedAccounts;
|
|
2911
|
-
experimental;
|
|
2912
4299
|
/**
|
|
2913
|
-
*
|
|
2914
|
-
*
|
|
2915
|
-
*
|
|
2916
|
-
*
|
|
2917
|
-
*
|
|
2918
|
-
* @param {
|
|
2919
|
-
* @param {
|
|
4300
|
+
* Creates a new instance of the Composio SDK.
|
|
4301
|
+
*
|
|
4302
|
+
* The constructor initializes the SDK with the provided configuration options,
|
|
4303
|
+
* sets up the API client, and initializes all core models (tools, toolkits, etc.).
|
|
4304
|
+
*
|
|
4305
|
+
* @param {ComposioConfig<TProvider>} config - Configuration options for the Composio SDK
|
|
4306
|
+
* @param {string} [config.apiKey] - The API key for authenticating with the Composio API
|
|
4307
|
+
* @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
|
|
4308
|
+
* @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
|
|
4309
|
+
* @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
|
|
4310
|
+
* @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
|
|
4311
|
+
* @param {BaseTelemetryTransport} [config.telemetryTransport] - Custom telemetry transport implementation
|
|
4312
|
+
*
|
|
4313
|
+
* @example
|
|
4314
|
+
* ```typescript
|
|
4315
|
+
* // Initialize with default configuration
|
|
4316
|
+
* const composio = new Composio();
|
|
4317
|
+
*
|
|
4318
|
+
* // Initialize with custom API key and base URL
|
|
4319
|
+
* const composio = new Composio({
|
|
4320
|
+
* apiKey: 'your-api-key',
|
|
4321
|
+
* baseURL: 'https://api.composio.dev'
|
|
4322
|
+
* });
|
|
4323
|
+
*
|
|
4324
|
+
* // Initialize with custom provider
|
|
4325
|
+
* const composio = new Composio({
|
|
4326
|
+
* apiKey: 'your-api-key',
|
|
4327
|
+
* provider: new CustomProvider()
|
|
4328
|
+
* });
|
|
4329
|
+
* ```
|
|
2920
4330
|
*/
|
|
2921
4331
|
constructor(config) {
|
|
2922
4332
|
const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getSDKConfig(
|
|
@@ -2924,58 +4334,46 @@ var Composio = class {
|
|
|
2924
4334
|
config?.apiKey
|
|
2925
4335
|
);
|
|
2926
4336
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
2927
|
-
logger_default.
|
|
4337
|
+
logger_default.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
2928
4338
|
}
|
|
2929
|
-
this.client = new
|
|
4339
|
+
this.client = new ComposioClient3({
|
|
2930
4340
|
apiKey: apiKeyParsed,
|
|
2931
4341
|
baseURL: baseURLParsed
|
|
2932
4342
|
});
|
|
2933
4343
|
this.config = {
|
|
2934
4344
|
...config,
|
|
2935
|
-
allowTracking: config
|
|
4345
|
+
allowTracking: config?.allowTracking ?? true,
|
|
4346
|
+
allowTracing: config?.allowTracing ?? true
|
|
2936
4347
|
};
|
|
2937
|
-
this.provider = config
|
|
4348
|
+
this.provider = config?.provider ?? new OpenAIProvider();
|
|
2938
4349
|
this.tools = new Tools(this.client, this.provider);
|
|
2939
4350
|
this.toolkits = new Toolkits(this.client);
|
|
2940
4351
|
this.triggers = new Triggers(this.client);
|
|
2941
4352
|
this.authConfigs = new AuthConfigs(this.client);
|
|
2942
4353
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
2943
|
-
this.
|
|
2944
|
-
|
|
2945
|
-
};
|
|
2946
|
-
if (this.config.allowTracking ?? true) {
|
|
2947
|
-
this.initializeTelemetry(
|
|
4354
|
+
if (this.config.allowTracking) {
|
|
4355
|
+
telemetry.setup(
|
|
2948
4356
|
{
|
|
2949
4357
|
apiKey: apiKeyParsed ?? "",
|
|
2950
4358
|
baseUrl: baseURLParsed ?? "",
|
|
2951
|
-
frameworkRuntime: "
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
4359
|
+
frameworkRuntime: this.provider?.name ?? "unknown",
|
|
4360
|
+
isAgentic: this.provider?._isAgentic || false,
|
|
4361
|
+
source: "javascript",
|
|
4362
|
+
version,
|
|
4363
|
+
sdkType: "Typescript-V3",
|
|
2955
4364
|
isBrowser: typeof window !== "undefined",
|
|
2956
|
-
|
|
4365
|
+
// @TODO: Users might want to pass their own session id
|
|
4366
|
+
// @TODO: We shouldn't be doing this as people might always have one session id throughout the process in server
|
|
4367
|
+
sessionId: this.config.allowTracing ? getRandomUUID() : void 0
|
|
2957
4368
|
// @TODO: get the session id
|
|
2958
4369
|
},
|
|
2959
|
-
config
|
|
4370
|
+
config?.telemetryTransport
|
|
2960
4371
|
);
|
|
2961
4372
|
}
|
|
4373
|
+
telemetry.instrument(this);
|
|
4374
|
+
telemetry.instrument(this.provider);
|
|
2962
4375
|
checkForLatestVersionFromNPM(version);
|
|
2963
4376
|
}
|
|
2964
|
-
/**
|
|
2965
|
-
* Initialize the instrumentations and telemetry for the Composio SDK.
|
|
2966
|
-
* @param {TelemetryMetadata} config - The configuration for the telemetry.
|
|
2967
|
-
* @param {BaseTelemetryTransport} transport - The transport for the telemetry.
|
|
2968
|
-
*/
|
|
2969
|
-
initializeTelemetry(config, transport) {
|
|
2970
|
-
this.telemetry = new Telemetry(config, transport);
|
|
2971
|
-
this.telemetry.instrumentTelemetry(this);
|
|
2972
|
-
this.telemetry.instrumentTelemetry(this.tools);
|
|
2973
|
-
this.telemetry.instrumentTelemetry(this.toolkits);
|
|
2974
|
-
this.telemetry.instrumentTelemetry(this.triggers);
|
|
2975
|
-
this.telemetry.instrumentTelemetry(this.authConfigs);
|
|
2976
|
-
this.telemetry.instrumentTelemetry(this.connectedAccounts);
|
|
2977
|
-
this.telemetry.instrumentTelemetry(this.provider);
|
|
2978
|
-
}
|
|
2979
4377
|
/**
|
|
2980
4378
|
* Get the Composio SDK client.
|
|
2981
4379
|
* @returns {ComposioClient} The Composio API client.
|
|
@@ -3000,43 +4398,50 @@ var ComposioProvider = class extends BaseNonAgenticProvider {
|
|
|
3000
4398
|
};
|
|
3001
4399
|
|
|
3002
4400
|
// src/telemetry/TelemetryTransport.ts
|
|
4401
|
+
import chalk4 from "chalk";
|
|
3003
4402
|
var BaseTelemetryTransport = class {
|
|
3004
4403
|
};
|
|
4404
|
+
var ConsoleTelemetryTransport = class {
|
|
4405
|
+
send(payload) {
|
|
4406
|
+
logger_default.debug(chalk4.yellow("telemetry"), JSON.stringify(payload, null, 2));
|
|
4407
|
+
return Promise.resolve();
|
|
4408
|
+
}
|
|
4409
|
+
};
|
|
3005
4410
|
|
|
3006
4411
|
// src/utils/jsonSchema.ts
|
|
3007
|
-
import { z as
|
|
4412
|
+
import { z as z7 } from "zod";
|
|
3008
4413
|
function jsonSchemaPropertiesToTSTypes(value) {
|
|
3009
4414
|
if (!value.type) {
|
|
3010
|
-
return
|
|
4415
|
+
return z7.object({});
|
|
3011
4416
|
}
|
|
3012
4417
|
let zodType;
|
|
3013
4418
|
switch (value.type) {
|
|
3014
4419
|
case "string":
|
|
3015
|
-
zodType =
|
|
4420
|
+
zodType = z7.string().describe(
|
|
3016
4421
|
(value.description || "") + (value.examples ? `
|
|
3017
4422
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3018
4423
|
);
|
|
3019
4424
|
break;
|
|
3020
4425
|
case "number":
|
|
3021
|
-
zodType =
|
|
4426
|
+
zodType = z7.number().describe(
|
|
3022
4427
|
(value.description || "") + (value.examples ? `
|
|
3023
4428
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3024
4429
|
);
|
|
3025
4430
|
break;
|
|
3026
4431
|
case "integer":
|
|
3027
|
-
zodType =
|
|
4432
|
+
zodType = z7.number().int().describe(
|
|
3028
4433
|
(value.description || "") + (value.examples ? `
|
|
3029
4434
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3030
4435
|
);
|
|
3031
4436
|
break;
|
|
3032
4437
|
case "boolean":
|
|
3033
|
-
zodType =
|
|
4438
|
+
zodType = z7.boolean().describe(
|
|
3034
4439
|
(value.description || "") + (value.examples ? `
|
|
3035
4440
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3036
4441
|
);
|
|
3037
4442
|
break;
|
|
3038
4443
|
case "array":
|
|
3039
|
-
zodType =
|
|
4444
|
+
zodType = z7.array(
|
|
3040
4445
|
jsonSchemaPropertiesToTSTypes(
|
|
3041
4446
|
value.items
|
|
3042
4447
|
)
|
|
@@ -3046,24 +4451,24 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3046
4451
|
);
|
|
3047
4452
|
break;
|
|
3048
4453
|
case "object":
|
|
3049
|
-
zodType =
|
|
4454
|
+
zodType = jsonSchemaToZodSchema(value).describe(
|
|
3050
4455
|
(value.description || "") + (value.examples ? `
|
|
3051
4456
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3052
4457
|
);
|
|
3053
4458
|
break;
|
|
3054
4459
|
case "null":
|
|
3055
|
-
zodType =
|
|
4460
|
+
zodType = z7.null().describe(value.description || "");
|
|
3056
4461
|
break;
|
|
3057
4462
|
default:
|
|
3058
4463
|
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
3059
4464
|
}
|
|
3060
4465
|
return zodType;
|
|
3061
4466
|
}
|
|
3062
|
-
function
|
|
4467
|
+
function jsonSchemaToZodSchema(jsonSchema) {
|
|
3063
4468
|
const properties = jsonSchema.properties;
|
|
3064
4469
|
const requiredFields = jsonSchema.required || [];
|
|
3065
4470
|
if (!properties) {
|
|
3066
|
-
return
|
|
4471
|
+
return z7.object({});
|
|
3067
4472
|
}
|
|
3068
4473
|
const zodSchema = {};
|
|
3069
4474
|
for (const [key, _] of Object.entries(properties)) {
|
|
@@ -3075,7 +4480,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
3075
4480
|
schema
|
|
3076
4481
|
)
|
|
3077
4482
|
);
|
|
3078
|
-
zodType =
|
|
4483
|
+
zodType = z7.union(anyOfTypes).describe(
|
|
3079
4484
|
(value.description || "") + (value.examples ? `
|
|
3080
4485
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3081
4486
|
);
|
|
@@ -3085,7 +4490,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3085
4490
|
schema
|
|
3086
4491
|
)
|
|
3087
4492
|
);
|
|
3088
|
-
zodType =
|
|
4493
|
+
zodType = z7.intersection(
|
|
3089
4494
|
allOfTypes[0],
|
|
3090
4495
|
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
3091
4496
|
).describe(
|
|
@@ -3109,17 +4514,42 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3109
4514
|
zodSchema[key] = zodType.optional();
|
|
3110
4515
|
}
|
|
3111
4516
|
}
|
|
3112
|
-
return
|
|
4517
|
+
return z7.object(zodSchema);
|
|
3113
4518
|
}
|
|
3114
4519
|
export {
|
|
4520
|
+
AuthConfigErrorCodes,
|
|
3115
4521
|
AuthConfigTypes,
|
|
3116
4522
|
AuthSchemeTypes,
|
|
3117
4523
|
BaseAgenticProvider,
|
|
3118
4524
|
BaseNonAgenticProvider,
|
|
3119
4525
|
BaseTelemetryTransport,
|
|
3120
4526
|
Composio,
|
|
4527
|
+
ComposioAuthConfigNotFoundError,
|
|
4528
|
+
ComposioConnectedAccountNotFoundError,
|
|
4529
|
+
ComposioCustomToolsNotInitializedError,
|
|
4530
|
+
ComposioError,
|
|
4531
|
+
ComposioGlobalExecuteToolFnNotSetError,
|
|
4532
|
+
ComposioInvalidExecuteFunctionError,
|
|
4533
|
+
ComposioInvalidModifierError,
|
|
4534
|
+
ComposioNoAPIKeyError,
|
|
3121
4535
|
ComposioProvider,
|
|
4536
|
+
ComposioProviderNotDefinedError,
|
|
4537
|
+
ComposioToolExecutionError,
|
|
4538
|
+
ComposioToolNotFoundError,
|
|
4539
|
+
ComposioToolkitFetchError,
|
|
4540
|
+
ComposioToolkitNotFoundError,
|
|
4541
|
+
ConnectedAccountErrorCodes,
|
|
4542
|
+
ConnectionRequestErrorCodes,
|
|
4543
|
+
ConnectionRequestFailedError,
|
|
4544
|
+
ConnectionRequestTimeoutError,
|
|
4545
|
+
ConsoleTelemetryTransport,
|
|
3122
4546
|
OpenAIProvider,
|
|
4547
|
+
SDKErrorCodes,
|
|
4548
|
+
ToolErrorCodes,
|
|
3123
4549
|
ToolListParamsSchema,
|
|
3124
|
-
|
|
4550
|
+
ToolkitErrorCodes,
|
|
4551
|
+
ValidationError,
|
|
4552
|
+
ValidationErrorCodes,
|
|
4553
|
+
jsonSchemaToZodSchema,
|
|
4554
|
+
logger_default as logger
|
|
3125
4555
|
};
|