@composio/core 0.1.12-alpha.10 → 0.1.12-alpha.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/dist/index.cjs +1486 -575
- package/dist/index.d.cts +690 -115
- package/dist/index.d.ts +690 -115
- package/dist/index.js +1301 -414
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -30,22 +30,46 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
AuthConfigErrorCodes: () => AuthConfigErrorCodes,
|
|
33
34
|
AuthConfigTypes: () => AuthConfigTypes,
|
|
34
35
|
AuthSchemeTypes: () => AuthSchemeTypes,
|
|
35
36
|
BaseAgenticProvider: () => BaseAgenticProvider,
|
|
36
37
|
BaseNonAgenticProvider: () => BaseNonAgenticProvider,
|
|
37
38
|
BaseTelemetryTransport: () => BaseTelemetryTransport,
|
|
38
39
|
Composio: () => Composio,
|
|
40
|
+
ComposioAuthConfigNotFoundError: () => ComposioAuthConfigNotFoundError,
|
|
41
|
+
ComposioConnectedAccountNotFoundError: () => ComposioConnectedAccountNotFoundError,
|
|
42
|
+
ComposioCustomToolsNotInitializedError: () => ComposioCustomToolsNotInitializedError,
|
|
43
|
+
ComposioError: () => ComposioError,
|
|
44
|
+
ComposioGlobalExecuteToolFnNotSetError: () => ComposioGlobalExecuteToolFnNotSetError,
|
|
45
|
+
ComposioInvalidExecuteFunctionError: () => ComposioInvalidExecuteFunctionError,
|
|
46
|
+
ComposioInvalidModifierError: () => ComposioInvalidModifierError,
|
|
47
|
+
ComposioNoAPIKeyError: () => ComposioNoAPIKeyError,
|
|
39
48
|
ComposioProvider: () => ComposioProvider,
|
|
49
|
+
ComposioProviderNotDefinedError: () => ComposioProviderNotDefinedError,
|
|
50
|
+
ComposioToolExecutionError: () => ComposioToolExecutionError,
|
|
51
|
+
ComposioToolNotFoundError: () => ComposioToolNotFoundError,
|
|
52
|
+
ComposioToolkitFetchError: () => ComposioToolkitFetchError,
|
|
53
|
+
ComposioToolkitNotFoundError: () => ComposioToolkitNotFoundError,
|
|
54
|
+
ConnectedAccountErrorCodes: () => ConnectedAccountErrorCodes,
|
|
55
|
+
ConnectionRequestErrorCodes: () => ConnectionRequestErrorCodes,
|
|
56
|
+
ConnectionRequestFailedError: () => ConnectionRequestFailedError,
|
|
57
|
+
ConnectionRequestTimeoutError: () => ConnectionRequestTimeoutError,
|
|
40
58
|
ConsoleTelemetryTransport: () => ConsoleTelemetryTransport,
|
|
41
59
|
OpenAIProvider: () => OpenAIProvider,
|
|
60
|
+
SDKErrorCodes: () => SDKErrorCodes,
|
|
61
|
+
ToolErrorCodes: () => ToolErrorCodes,
|
|
42
62
|
ToolListParamsSchema: () => ToolListParamsSchema,
|
|
43
|
-
|
|
63
|
+
ToolkitErrorCodes: () => ToolkitErrorCodes,
|
|
64
|
+
ValidationError: () => ValidationError,
|
|
65
|
+
ValidationErrorCodes: () => ValidationErrorCodes,
|
|
66
|
+
jsonSchemaToZodSchema: () => jsonSchemaToZodSchema,
|
|
67
|
+
logger: () => logger_default
|
|
44
68
|
});
|
|
45
69
|
module.exports = __toCommonJS(index_exports);
|
|
46
70
|
|
|
47
71
|
// src/composio.ts
|
|
48
|
-
var
|
|
72
|
+
var import_client6 = __toESM(require("@composio/client"), 1);
|
|
49
73
|
|
|
50
74
|
// src/types/tool.types.ts
|
|
51
75
|
var import_zod = require("zod");
|
|
@@ -54,12 +78,38 @@ var ToolkitSchema = import_zod.z.object({
|
|
|
54
78
|
name: import_zod.z.string().describe("The name of the toolkit"),
|
|
55
79
|
logo: import_zod.z.string().describe("The logo of the toolkit").optional()
|
|
56
80
|
});
|
|
81
|
+
var JSONSchemaType = import_zod.z.enum([
|
|
82
|
+
"string",
|
|
83
|
+
"number",
|
|
84
|
+
"integer",
|
|
85
|
+
"boolean",
|
|
86
|
+
"object",
|
|
87
|
+
"array",
|
|
88
|
+
"null"
|
|
89
|
+
]);
|
|
90
|
+
var JSONSchemaProperty = import_zod.z.object({
|
|
91
|
+
type: JSONSchemaType.optional(),
|
|
92
|
+
description: import_zod.z.string().optional(),
|
|
93
|
+
title: import_zod.z.string().optional(),
|
|
94
|
+
default: import_zod.z.any().optional(),
|
|
95
|
+
properties: import_zod.z.lazy(() => import_zod.z.record(import_zod.z.string(), JSONSchemaProperty)).optional(),
|
|
96
|
+
required: import_zod.z.array(import_zod.z.string()).optional(),
|
|
97
|
+
items: import_zod.z.lazy(() => JSONSchemaProperty).optional()
|
|
98
|
+
});
|
|
99
|
+
var ParametersSchema = import_zod.z.object({
|
|
100
|
+
type: import_zod.z.literal("object"),
|
|
101
|
+
properties: import_zod.z.record(import_zod.z.string(), JSONSchemaProperty),
|
|
102
|
+
required: import_zod.z.array(import_zod.z.string()).optional(),
|
|
103
|
+
title: import_zod.z.string().optional(),
|
|
104
|
+
description: import_zod.z.string().optional(),
|
|
105
|
+
additionalProperties: import_zod.z.boolean().optional()
|
|
106
|
+
});
|
|
57
107
|
var ToolSchema = import_zod.z.object({
|
|
58
108
|
slug: import_zod.z.string().describe('The slug of the tool. eg. "GOOGLE_SEARCH"'),
|
|
59
109
|
name: import_zod.z.string().describe(`The name of the tool. eg. "Google Search"`),
|
|
60
110
|
description: import_zod.z.string().optional().describe("The description of the tool"),
|
|
61
|
-
inputParameters:
|
|
62
|
-
outputParameters:
|
|
111
|
+
inputParameters: ParametersSchema.optional().describe("The input parameters of the tool"),
|
|
112
|
+
outputParameters: ParametersSchema.optional().describe("The output parameters of the tool"),
|
|
63
113
|
tags: import_zod.z.optional(import_zod.z.array(import_zod.z.string())).describe("The tags of the tool. eg: Important").default([]),
|
|
64
114
|
toolkit: import_zod.z.optional(ToolkitSchema).describe("The toolkit of the tool"),
|
|
65
115
|
version: import_zod.z.optional(import_zod.z.string()).describe('The version of the tool, e.g. "1.0.0"')
|
|
@@ -72,8 +122,8 @@ var ToolListResponseSchema = import_zod.z.object({
|
|
|
72
122
|
var ToolListParamsSchema = import_zod.z.object({
|
|
73
123
|
tools: import_zod.z.array(import_zod.z.string()).optional(),
|
|
74
124
|
cursor: import_zod.z.string().optional(),
|
|
75
|
-
important: import_zod.z.
|
|
76
|
-
limit: import_zod.z.
|
|
125
|
+
important: import_zod.z.boolean().optional(),
|
|
126
|
+
limit: import_zod.z.number().optional(),
|
|
77
127
|
search: import_zod.z.string().optional(),
|
|
78
128
|
toolkits: import_zod.z.array(import_zod.z.string()).optional()
|
|
79
129
|
});
|
|
@@ -147,7 +197,20 @@ var Logger = class {
|
|
|
147
197
|
this.console = console;
|
|
148
198
|
}
|
|
149
199
|
formatMessage(args) {
|
|
150
|
-
const formattedArgs = args.map((arg) =>
|
|
200
|
+
const formattedArgs = args.map((arg, index) => {
|
|
201
|
+
if (typeof arg === "object") {
|
|
202
|
+
return JSON.stringify(arg);
|
|
203
|
+
} else {
|
|
204
|
+
if (index === 0) {
|
|
205
|
+
if (args.length > 1) {
|
|
206
|
+
return import_chalk.default.yellow(`${arg}`);
|
|
207
|
+
} else {
|
|
208
|
+
return String(arg);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return String(arg);
|
|
212
|
+
}
|
|
213
|
+
}).join("\n");
|
|
151
214
|
if (!this.includeTimestamp) {
|
|
152
215
|
return formattedArgs;
|
|
153
216
|
}
|
|
@@ -182,34 +245,240 @@ var logger = new Logger();
|
|
|
182
245
|
var logger_default = logger;
|
|
183
246
|
|
|
184
247
|
// src/errors/ComposioError.ts
|
|
185
|
-
var
|
|
248
|
+
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
249
|
+
var import_zod2 = require("zod");
|
|
250
|
+
var import_client = require("@composio/client");
|
|
251
|
+
var ComposioError = class _ComposioError extends Error {
|
|
252
|
+
/** @readonly Error name */
|
|
186
253
|
name = "ComposioError";
|
|
187
254
|
code;
|
|
188
|
-
statusCode;
|
|
189
|
-
cause;
|
|
190
|
-
meta;
|
|
191
255
|
possibleFixes;
|
|
256
|
+
errorId;
|
|
257
|
+
/**
|
|
258
|
+
* Creates a new ComposioError
|
|
259
|
+
* @param message Error message
|
|
260
|
+
* @param options Additional error options
|
|
261
|
+
*/
|
|
192
262
|
constructor(message, options = {}) {
|
|
193
263
|
super(message);
|
|
194
|
-
this.code = options.code;
|
|
195
|
-
this.statusCode = options.statusCode;
|
|
196
|
-
this.cause = options.cause;
|
|
197
|
-
this.meta = options.meta;
|
|
198
|
-
this.possibleFixes = options.possibleFixes;
|
|
199
264
|
if (Error.captureStackTrace) {
|
|
200
265
|
Error.captureStackTrace(this, this.constructor);
|
|
201
266
|
}
|
|
267
|
+
const statusCode = options.statusCode || (options.cause instanceof import_client.BadRequestError ? options.cause.status : void 0);
|
|
268
|
+
this.code = `TS-SDK::${options.code}`;
|
|
269
|
+
this.possibleFixes = options.possibleFixes;
|
|
270
|
+
this.definePropertyIfExists("statusCode", statusCode);
|
|
271
|
+
this.definePropertyIfExists("cause", options.cause);
|
|
272
|
+
const combinedStack = options.cause instanceof Error ? _ComposioError.combineStackTraces(options.cause.stack, this.stack) : options.stack ?? this.stack;
|
|
273
|
+
this.definePropertyIfExists("stack", combinedStack);
|
|
274
|
+
if (options.meta && Object.keys(options.meta).length > 0) {
|
|
275
|
+
this.definePropertyIfExists("meta", options.meta);
|
|
276
|
+
}
|
|
202
277
|
}
|
|
203
|
-
|
|
204
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Helper method to define a property only if it has a value
|
|
280
|
+
* @param propertyName Name of the property to define
|
|
281
|
+
* @param value Value to assign to the property
|
|
282
|
+
* @private
|
|
283
|
+
*/
|
|
284
|
+
definePropertyIfExists(propertyName, value) {
|
|
285
|
+
if (value !== void 0) {
|
|
286
|
+
Object.defineProperty(this, propertyName, {
|
|
287
|
+
value,
|
|
288
|
+
enumerable: true,
|
|
289
|
+
writable: false,
|
|
290
|
+
configurable: true
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Helper method to combine stack traces when wrapping errors
|
|
296
|
+
* This ensures the full call chain is preserved
|
|
297
|
+
* @param originalStack The stack of the error being wrapped
|
|
298
|
+
* @param currentStack The stack of the wrapper error
|
|
299
|
+
* @returns Combined stack trace
|
|
300
|
+
* @private
|
|
301
|
+
*/
|
|
302
|
+
static combineStackTraces(originalStack, currentStack) {
|
|
303
|
+
if (!originalStack) return currentStack;
|
|
304
|
+
if (!currentStack) return originalStack;
|
|
305
|
+
const currentHeader = currentStack.split("\n")[0];
|
|
306
|
+
const originalStackBody = originalStack.split("\n").slice(1).join("\n");
|
|
307
|
+
return `${currentHeader}
|
|
308
|
+
${currentStack.split("\n").slice(1).join("\n")}
|
|
309
|
+
|
|
310
|
+
Caused by:
|
|
311
|
+
${originalStackBody}`;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Extract and normalize error data for formatting
|
|
315
|
+
* @param includeStack Whether to include stack trace information
|
|
316
|
+
* @returns Structured error data for formatting
|
|
317
|
+
* @private
|
|
318
|
+
*/
|
|
319
|
+
getErrorData(includeStack = false) {
|
|
320
|
+
const data = {
|
|
205
321
|
name: this.name,
|
|
206
|
-
message: this.message
|
|
207
|
-
code: this.code,
|
|
208
|
-
statusCode: this.statusCode,
|
|
209
|
-
cause: this.cause instanceof Error ? this.cause.message : this.cause,
|
|
210
|
-
meta: this.meta,
|
|
211
|
-
possibleFixes: this.possibleFixes?.length ? this.possibleFixes.join("\n") : void 0
|
|
322
|
+
message: this.message
|
|
212
323
|
};
|
|
324
|
+
const { cause, code, stack, statusCode, meta, possibleFixes } = this;
|
|
325
|
+
if (cause !== void 0) {
|
|
326
|
+
const rawCause = cause;
|
|
327
|
+
data.cause = rawCause instanceof Error ? rawCause.message : String(rawCause);
|
|
328
|
+
}
|
|
329
|
+
if (code) {
|
|
330
|
+
data.code = code;
|
|
331
|
+
}
|
|
332
|
+
if (statusCode !== void 0) {
|
|
333
|
+
data.statusCode = statusCode;
|
|
334
|
+
}
|
|
335
|
+
if (meta) {
|
|
336
|
+
data.meta = meta;
|
|
337
|
+
}
|
|
338
|
+
if (possibleFixes) {
|
|
339
|
+
data.possibleFixes = possibleFixes;
|
|
340
|
+
}
|
|
341
|
+
if (includeStack && stack) {
|
|
342
|
+
if (stack.includes("Caused by:")) {
|
|
343
|
+
const [currentStack, causeStack] = stack.split("Caused by:");
|
|
344
|
+
data.stack = [
|
|
345
|
+
...currentStack.split("\n").slice(1),
|
|
346
|
+
"Caused by:",
|
|
347
|
+
...causeStack.split("\n")
|
|
348
|
+
];
|
|
349
|
+
} else {
|
|
350
|
+
data.stack = stack.split("\n").slice(1);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
return data;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Prints a user-friendly, colorful representation of the error to the logger
|
|
357
|
+
* @param includeStack Whether to include the stack trace in the output (default: false)
|
|
358
|
+
*/
|
|
359
|
+
prettyPrint(includeStack = false) {
|
|
360
|
+
const data = this.getErrorData(includeStack);
|
|
361
|
+
let output = "\n" + import_chalk2.default.bgRed.white.bold(" ERROR ") + " " + import_chalk2.default.white.bold(data.message) + "\n";
|
|
362
|
+
if (data.code) {
|
|
363
|
+
output += import_chalk2.default.yellow(`Error Code: ${data.code}`) + "\n";
|
|
364
|
+
}
|
|
365
|
+
if (data.statusCode !== void 0) {
|
|
366
|
+
output += import_chalk2.default.yellow(`Status: ${data.statusCode}`) + "\n";
|
|
367
|
+
}
|
|
368
|
+
if (data.cause) {
|
|
369
|
+
output += import_chalk2.default.gray("Reason:") + "\n";
|
|
370
|
+
output += " " + import_chalk2.default.white(data.cause) + "\n";
|
|
371
|
+
}
|
|
372
|
+
if (data.meta) {
|
|
373
|
+
output += import_chalk2.default.gray("Additional Information:") + "\n";
|
|
374
|
+
output += " " + import_chalk2.default.white(JSON.stringify(data.meta, null, 2).replace(/\n/g, "\n ")) + "\n";
|
|
375
|
+
}
|
|
376
|
+
if (data.possibleFixes?.length) {
|
|
377
|
+
output += "\n" + import_chalk2.default.cyan.bold("Try the following:") + "\n";
|
|
378
|
+
const fixes = data.possibleFixes?.map((fix, index) => ` ${index + 1}. ` + import_chalk2.default.white(fix));
|
|
379
|
+
output += fixes?.join("\n") + "\n";
|
|
380
|
+
}
|
|
381
|
+
if (data.stack?.length) {
|
|
382
|
+
output += "\n" + import_chalk2.default.gray("Stack Trace:") + "\n";
|
|
383
|
+
output += import_chalk2.default.gray(data.stack.join("\n")) + "\n";
|
|
384
|
+
}
|
|
385
|
+
output += "\n";
|
|
386
|
+
logger_default.error(output);
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Static factory method to create and pretty print an error in one step
|
|
390
|
+
* @param message Error message
|
|
391
|
+
* @param options Error options
|
|
392
|
+
* @param includeStack Whether to include the stack trace in the output
|
|
393
|
+
* @returns The created error instance
|
|
394
|
+
*/
|
|
395
|
+
static createAndPrint(message, options = {}, includeStack = false) {
|
|
396
|
+
const error = new _ComposioError(message, options);
|
|
397
|
+
error.prettyPrint(includeStack);
|
|
398
|
+
return error;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Utility function to handle errors in a consistent way
|
|
402
|
+
* This properly displays the error and exits the process if needed
|
|
403
|
+
* @param error The error to handle
|
|
404
|
+
* @param options Options for error handling
|
|
405
|
+
*/
|
|
406
|
+
static handle(error, options = {}) {
|
|
407
|
+
const { includeStack = false, exitProcess = false, exitCode = 1 } = options;
|
|
408
|
+
if (error instanceof _ComposioError) {
|
|
409
|
+
error.prettyPrint(includeStack);
|
|
410
|
+
} else if (error instanceof import_zod2.ZodError) {
|
|
411
|
+
this.handleZodError(error, includeStack);
|
|
412
|
+
} else if (error instanceof Error) {
|
|
413
|
+
this.handleStandardError(error, includeStack);
|
|
414
|
+
} else {
|
|
415
|
+
this.handleUnknownError(error);
|
|
416
|
+
}
|
|
417
|
+
if (exitProcess && typeof process !== "undefined") {
|
|
418
|
+
process.exit(exitCode);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Helper method to handle Zod validation errors
|
|
423
|
+
* @param error The Zod error to handle
|
|
424
|
+
* @param includeStack Whether to include the stack trace
|
|
425
|
+
* @private
|
|
426
|
+
*/
|
|
427
|
+
static handleZodError(error, includeStack) {
|
|
428
|
+
logger_default.error("\n" + import_chalk2.default.bgRed.white.bold(" ERROR ") + " " + import_chalk2.default.white.bold(error.message));
|
|
429
|
+
logger_default.error(import_chalk2.default.gray("Invalid parameters:"));
|
|
430
|
+
error.errors.forEach((err) => {
|
|
431
|
+
logger_default.error(import_chalk2.default.yellow(err.path.join(".")) + " " + import_chalk2.default.white(err.message));
|
|
432
|
+
});
|
|
433
|
+
logger_default.error(import_chalk2.default.gray("Expected parameters:"));
|
|
434
|
+
error.errors.forEach((err) => {
|
|
435
|
+
logger_default.error(import_chalk2.default.yellow(err.path.join(".")) + " " + import_chalk2.default.white(err.message));
|
|
436
|
+
});
|
|
437
|
+
if (includeStack) {
|
|
438
|
+
logger_default.error("\n" + import_chalk2.default.gray("Validation Errors:"));
|
|
439
|
+
error.errors.forEach((err) => {
|
|
440
|
+
const path = err.path.join(".");
|
|
441
|
+
logger_default.error(
|
|
442
|
+
import_chalk2.default.gray(" \u2022 ") + import_chalk2.default.yellow(path ? `${path}: ` : "") + import_chalk2.default.white(err.message)
|
|
443
|
+
);
|
|
444
|
+
});
|
|
445
|
+
if (error.stack) {
|
|
446
|
+
logger_default.error("\n" + import_chalk2.default.gray("Stack Trace:"));
|
|
447
|
+
const stackLines = error.stack.split("\n").slice(1);
|
|
448
|
+
logger_default.error(import_chalk2.default.gray(stackLines.join("\n")));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
logger_default.error("");
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Helper method to handle standard Error objects
|
|
455
|
+
* @param error The standard error to handle
|
|
456
|
+
* @param includeStack Whether to include the stack trace
|
|
457
|
+
* @private
|
|
458
|
+
*/
|
|
459
|
+
static handleStandardError(error, includeStack) {
|
|
460
|
+
logger_default.error("\n" + import_chalk2.default.bgRed.white.bold(" ERROR ") + " " + import_chalk2.default.white.bold(error.message));
|
|
461
|
+
if (includeStack && error.stack) {
|
|
462
|
+
logger_default.error("\n" + import_chalk2.default.gray("Stack Trace:"));
|
|
463
|
+
const stackLines = error.stack.split("\n").slice(1);
|
|
464
|
+
logger_default.error(import_chalk2.default.gray(stackLines.join("\n")));
|
|
465
|
+
}
|
|
466
|
+
logger_default.error("");
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Helper method to handle unknown error types
|
|
470
|
+
* @param error The unknown error value
|
|
471
|
+
* @private
|
|
472
|
+
*/
|
|
473
|
+
static handleUnknownError(error) {
|
|
474
|
+
logger_default.error(
|
|
475
|
+
"\n" + import_chalk2.default.bgRed.white.bold(" ERROR ") + " " + import_chalk2.default.white.bold("Unknown error occurred")
|
|
476
|
+
);
|
|
477
|
+
if (error !== null && error !== void 0) {
|
|
478
|
+
logger_default.error(import_chalk2.default.gray("Error details:"));
|
|
479
|
+
logger_default.error(" " + import_chalk2.default.white(String(error)));
|
|
480
|
+
}
|
|
481
|
+
logger_default.error("");
|
|
213
482
|
}
|
|
214
483
|
};
|
|
215
484
|
|
|
@@ -224,11 +493,11 @@ var ToolErrorCodes = {
|
|
|
224
493
|
GLOBAL_EXECUTE_TOOL_FN_NOT_SET: "GLOBAL_EXECUTE_TOOL_FN_NOT_SET"
|
|
225
494
|
};
|
|
226
495
|
var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
227
|
-
constructor(message = "Provider not defined",
|
|
496
|
+
constructor(message = "Provider not defined", options = {}) {
|
|
228
497
|
super(message, {
|
|
498
|
+
...options,
|
|
229
499
|
code: ToolErrorCodes.TOOLSET_NOT_DEFINED,
|
|
230
|
-
|
|
231
|
-
possibleFixes: [
|
|
500
|
+
possibleFixes: options.possibleFixes || [
|
|
232
501
|
"Ensure that the provider is defined in the Composio project and passed into the tool instance"
|
|
233
502
|
]
|
|
234
503
|
});
|
|
@@ -236,86 +505,103 @@ var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
|
236
505
|
}
|
|
237
506
|
};
|
|
238
507
|
var ComposioToolNotFoundError = class extends ComposioError {
|
|
239
|
-
constructor(message = "Tool not found",
|
|
508
|
+
constructor(message = "Tool not found", options = {}) {
|
|
240
509
|
super(message, {
|
|
510
|
+
...options,
|
|
241
511
|
code: ToolErrorCodes.TOOL_NOT_FOUND,
|
|
242
|
-
|
|
243
|
-
|
|
512
|
+
possibleFixes: options.possibleFixes || [
|
|
513
|
+
"Ensure the tool slug is correct and exists in the Composio project"
|
|
514
|
+
]
|
|
244
515
|
});
|
|
245
516
|
this.name = "ComposioToolNotFoundError";
|
|
246
517
|
}
|
|
247
518
|
};
|
|
248
519
|
var ComposioInvalidModifierError = class extends ComposioError {
|
|
249
|
-
constructor(message = "Invalid modifier",
|
|
520
|
+
constructor(message = "Invalid modifier", options = {}) {
|
|
250
521
|
super(message, {
|
|
522
|
+
...options,
|
|
251
523
|
code: ToolErrorCodes.INVALID_MODIFIER,
|
|
252
|
-
|
|
253
|
-
|
|
524
|
+
possibleFixes: options.possibleFixes || [
|
|
525
|
+
"Ensure the modifier is a function and returns a valid result"
|
|
526
|
+
]
|
|
254
527
|
});
|
|
255
528
|
this.name = "ComposioInvalidModifierError";
|
|
256
529
|
}
|
|
257
530
|
};
|
|
258
531
|
var ComposioCustomToolsNotInitializedError = class extends ComposioError {
|
|
259
|
-
constructor(message = "Custom tools not initialized",
|
|
532
|
+
constructor(message = "Custom tools not initialized", options = {}) {
|
|
260
533
|
super(message, {
|
|
534
|
+
...options,
|
|
261
535
|
code: ToolErrorCodes.CUSTOM_TOOLS_NOT_INITIALIZED,
|
|
262
|
-
|
|
263
|
-
|
|
536
|
+
possibleFixes: options.possibleFixes || [
|
|
537
|
+
"Ensure the custom tools class is initialized in the Tools instance"
|
|
538
|
+
]
|
|
264
539
|
});
|
|
265
540
|
this.name = "ComposioCustomToolsNotInitializedError";
|
|
266
541
|
}
|
|
267
542
|
};
|
|
268
543
|
var ComposioToolExecutionError = class extends ComposioError {
|
|
269
544
|
error;
|
|
270
|
-
constructor(
|
|
545
|
+
constructor(message = "Tool execution error", options = {}) {
|
|
546
|
+
const { originalError, ...restOptions } = options;
|
|
271
547
|
super(message, {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
possibleFixes:
|
|
548
|
+
...restOptions,
|
|
549
|
+
code: options.code || ToolErrorCodes.TOOL_EXECUTION_ERROR,
|
|
550
|
+
cause: options.cause || originalError,
|
|
551
|
+
possibleFixes: options.possibleFixes || [
|
|
552
|
+
"Ensure the tool is correctly configured and the input is valid"
|
|
553
|
+
]
|
|
276
554
|
});
|
|
277
|
-
this.error = error;
|
|
555
|
+
this.error = originalError || (options.cause instanceof Error ? options.cause : options.cause ? new Error(String(options.cause)) : new Error("Unknown error"));
|
|
278
556
|
this.name = "ComposioToolExecutionError";
|
|
279
557
|
}
|
|
280
558
|
};
|
|
281
559
|
var ComposioInvalidExecuteFunctionError = class extends ComposioError {
|
|
282
|
-
constructor(message = "Invalid execute function",
|
|
560
|
+
constructor(message = "Invalid execute function", options = {}) {
|
|
283
561
|
super(message, {
|
|
562
|
+
...options,
|
|
284
563
|
code: ToolErrorCodes.INVALID_EXECUTE_FUNCTION,
|
|
285
|
-
|
|
286
|
-
|
|
564
|
+
possibleFixes: options.possibleFixes || [
|
|
565
|
+
"Ensure the execute function is a valid function and returns a valid result"
|
|
566
|
+
]
|
|
287
567
|
});
|
|
288
568
|
this.name = "ComposioInvalidExecuteFunctionError";
|
|
289
569
|
}
|
|
290
570
|
};
|
|
291
571
|
var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
|
|
292
|
-
constructor(message = "Global execute tool function not set",
|
|
572
|
+
constructor(message = "Global execute tool function not set", options = {}) {
|
|
293
573
|
super(message, {
|
|
574
|
+
...options,
|
|
294
575
|
code: ToolErrorCodes.GLOBAL_EXECUTE_TOOL_FN_NOT_SET,
|
|
295
|
-
|
|
296
|
-
|
|
576
|
+
possibleFixes: options.possibleFixes || [
|
|
577
|
+
"Ensure the global execute tool function is set in the provider"
|
|
578
|
+
]
|
|
297
579
|
});
|
|
298
580
|
this.name = "ComposioGlobalExecuteToolFnNotSetError";
|
|
299
581
|
}
|
|
300
582
|
};
|
|
301
583
|
|
|
302
|
-
// src/errors/
|
|
584
|
+
// src/errors/ConnectedAccountsErrors.ts
|
|
303
585
|
var ConnectedAccountErrorCodes = {
|
|
304
586
|
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
|
|
305
587
|
};
|
|
306
588
|
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
307
|
-
constructor(message = "Connected account not found",
|
|
589
|
+
constructor(message = "Connected account not found", options = {}) {
|
|
308
590
|
super(message, {
|
|
591
|
+
...options,
|
|
309
592
|
code: ConnectedAccountErrorCodes.CONNECTED_ACCOUNT_NOT_FOUND,
|
|
310
593
|
statusCode: 404,
|
|
311
|
-
|
|
312
|
-
possibleFixes: [
|
|
594
|
+
possibleFixes: options.possibleFixes || [
|
|
313
595
|
"Ensure the connected account exists and is active in your Composio dashboard"
|
|
314
596
|
]
|
|
315
597
|
});
|
|
598
|
+
this.name = "ComposioConnectedAccountNotFoundError";
|
|
316
599
|
}
|
|
317
600
|
};
|
|
318
601
|
|
|
602
|
+
// src/telemetry/Telemetry.ts
|
|
603
|
+
var import_client2 = require("@composio/client");
|
|
604
|
+
|
|
319
605
|
// src/types/telemetry.types.ts
|
|
320
606
|
var TELEMETRY_EVENTS = {
|
|
321
607
|
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
@@ -393,7 +679,7 @@ var BrowserTelemetryTransport = class {
|
|
|
393
679
|
};
|
|
394
680
|
|
|
395
681
|
// src/telemetry/transports/ProcessTransport.ts
|
|
396
|
-
var
|
|
682
|
+
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
397
683
|
var ProcessTelemetryTransport = class {
|
|
398
684
|
send(payload) {
|
|
399
685
|
if (typeof window !== "undefined") {
|
|
@@ -436,14 +722,15 @@ var ProcessTelemetryTransport = class {
|
|
|
436
722
|
import("child_process").then(({ spawn }) => {
|
|
437
723
|
spawn("node", args, {
|
|
438
724
|
stdio: "ignore",
|
|
439
|
-
detached:
|
|
725
|
+
detached: false,
|
|
440
726
|
shell: false
|
|
441
727
|
}).unref();
|
|
442
728
|
resolve();
|
|
443
|
-
}).catch(() => {
|
|
729
|
+
}).catch((error) => {
|
|
730
|
+
logger_default.error("Error sending telemetry", error);
|
|
444
731
|
resolve();
|
|
445
732
|
});
|
|
446
|
-
logger_default.debug(
|
|
733
|
+
logger_default.debug(import_chalk3.default.yellow("Process Telemetry"), JSON.stringify(payload, null, 2));
|
|
447
734
|
} catch (error) {
|
|
448
735
|
logger_default.error("Error sending telemetry", error);
|
|
449
736
|
resolve();
|
|
@@ -452,6 +739,12 @@ var ProcessTelemetryTransport = class {
|
|
|
452
739
|
}
|
|
453
740
|
};
|
|
454
741
|
|
|
742
|
+
// src/utils/uuid.ts
|
|
743
|
+
var import_uuid = require("uuid");
|
|
744
|
+
function getRandomUUID() {
|
|
745
|
+
return (0, import_uuid.v4)();
|
|
746
|
+
}
|
|
747
|
+
|
|
455
748
|
// src/telemetry/Telemetry.ts
|
|
456
749
|
var TelemetryService = class {
|
|
457
750
|
telemetryMetadata;
|
|
@@ -476,8 +769,7 @@ var TelemetryService = class {
|
|
|
476
769
|
this.sendTelemetry([
|
|
477
770
|
{
|
|
478
771
|
eventName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
479
|
-
data: {}
|
|
480
|
-
sdk_meta: this.telemetryMetadata
|
|
772
|
+
data: {}
|
|
481
773
|
}
|
|
482
774
|
]);
|
|
483
775
|
}
|
|
@@ -496,7 +788,7 @@ var TelemetryService = class {
|
|
|
496
788
|
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
497
789
|
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
498
790
|
});
|
|
499
|
-
const instrumentedClassName = instance.constructor?.name || fileName
|
|
791
|
+
const instrumentedClassName = (instance.constructor?.name || fileName) ?? "unknown";
|
|
500
792
|
for (const name of methodNames) {
|
|
501
793
|
const originalMethod = instance[name];
|
|
502
794
|
instance[name] = async (...args) => {
|
|
@@ -506,24 +798,18 @@ var TelemetryService = class {
|
|
|
506
798
|
fileName: instrumentedClassName,
|
|
507
799
|
method: name,
|
|
508
800
|
params: args
|
|
509
|
-
}
|
|
510
|
-
sdk_meta: this.telemetryMetadata
|
|
801
|
+
}
|
|
511
802
|
};
|
|
512
803
|
this.batchProcessor.pushItem(telemetryPayload);
|
|
513
804
|
try {
|
|
514
805
|
return await originalMethod.apply(instance, args);
|
|
515
806
|
} catch (error) {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
error
|
|
523
|
-
},
|
|
524
|
-
sdk_meta: this.telemetryMetadata
|
|
525
|
-
};
|
|
526
|
-
this.batchProcessor.pushItem(telemetryPayload2);
|
|
807
|
+
if (error instanceof Error) {
|
|
808
|
+
if (!error.errorId) {
|
|
809
|
+
error.errorId = getRandomUUID();
|
|
810
|
+
this.prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
527
813
|
throw error;
|
|
528
814
|
}
|
|
529
815
|
};
|
|
@@ -541,6 +827,47 @@ var TelemetryService = class {
|
|
|
541
827
|
const isTelemetryDisabledByEnv = getEnvVariable("TELEMETRY_DISABLED", "false") === "true";
|
|
542
828
|
return this.transport && !this.isTelemetryDisabled && !isTelemetryDisabledByEnv && !isDevEnvironment;
|
|
543
829
|
}
|
|
830
|
+
/**
|
|
831
|
+
* Prepare and send the error telemetry.
|
|
832
|
+
*
|
|
833
|
+
* @TODO This currently blocks the thread and sends the telemetry to the server.
|
|
834
|
+
*
|
|
835
|
+
* @param {unknown} error - The error to send.
|
|
836
|
+
* @param {string} instrumentedClassName - The class name of the instrumented class.
|
|
837
|
+
* @param {string} name - The name of the method that threw the error.
|
|
838
|
+
*/
|
|
839
|
+
prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args) {
|
|
840
|
+
if (error instanceof import_client2.ComposioError) {
|
|
841
|
+
const telemetryPayload = {
|
|
842
|
+
error_id: error.errorId || "",
|
|
843
|
+
error_message: error.message,
|
|
844
|
+
original_error: error.cause || error,
|
|
845
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
846
|
+
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
847
|
+
};
|
|
848
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
849
|
+
} else if (error instanceof ComposioError) {
|
|
850
|
+
const telemetryPayload = {
|
|
851
|
+
error_id: error.errorId || "",
|
|
852
|
+
error_message: error.message,
|
|
853
|
+
original_error: error.cause || error,
|
|
854
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
855
|
+
error_code: error.code,
|
|
856
|
+
possible_fix: error.possibleFixes?.join("\n"),
|
|
857
|
+
description: `Original Call : ${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
858
|
+
};
|
|
859
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
860
|
+
} else if (error instanceof Error) {
|
|
861
|
+
const telemetryPayload = {
|
|
862
|
+
error_id: error.errorId || "",
|
|
863
|
+
error_message: error instanceof Error ? error.name : "Unknown error",
|
|
864
|
+
original_error: error,
|
|
865
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
866
|
+
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
867
|
+
};
|
|
868
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
544
871
|
/**
|
|
545
872
|
* Send the telemetry payload to the server.
|
|
546
873
|
* @param payload - the telemetry payload to send
|
|
@@ -552,20 +879,27 @@ var TelemetryService = class {
|
|
|
552
879
|
}
|
|
553
880
|
const url = `${TELEMETRY_URL}/api/sdk_metrics/telemetry`;
|
|
554
881
|
const reqPayload = {
|
|
555
|
-
data: payload
|
|
882
|
+
data: payload.map((p) => ({
|
|
883
|
+
...p,
|
|
884
|
+
sdk_meta: this.telemetryMetadata
|
|
885
|
+
})),
|
|
556
886
|
url,
|
|
557
887
|
method: "POST",
|
|
558
888
|
headers: { "Content-Type": "application/json" }
|
|
559
889
|
};
|
|
560
890
|
this.transport.send(reqPayload);
|
|
561
891
|
}
|
|
562
|
-
|
|
892
|
+
// @TODO: check if this will send the error telemetry to the server
|
|
893
|
+
async sendErrorTelemetry(payload) {
|
|
563
894
|
if (!this.shouldSendTelemetry()) {
|
|
564
895
|
return;
|
|
565
896
|
}
|
|
566
897
|
const url = `${TELEMETRY_URL}/api/sdk_metrics/error`;
|
|
567
898
|
const reqPayload = {
|
|
568
|
-
data: {
|
|
899
|
+
data: {
|
|
900
|
+
...payload,
|
|
901
|
+
sdk_meta: this.telemetryMetadata
|
|
902
|
+
},
|
|
569
903
|
url,
|
|
570
904
|
method: "POST",
|
|
571
905
|
headers: { "Content-Type": "application/json" }
|
|
@@ -675,8 +1009,7 @@ var CustomTools = class {
|
|
|
675
1009
|
await this.client.toolkits.retrieve(toolkitSlug);
|
|
676
1010
|
} catch (error) {
|
|
677
1011
|
throw new ComposioToolNotFoundError(`Toolkit with slug ${toolkitSlug} not found`, {
|
|
678
|
-
|
|
679
|
-
error
|
|
1012
|
+
cause: error
|
|
680
1013
|
});
|
|
681
1014
|
}
|
|
682
1015
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
@@ -685,10 +1018,7 @@ var CustomTools = class {
|
|
|
685
1018
|
});
|
|
686
1019
|
if (!connectedAccounts.items.length) {
|
|
687
1020
|
throw new ComposioConnectedAccountNotFoundError(
|
|
688
|
-
`No connected accounts found for toolkit ${toolkitSlug}
|
|
689
|
-
{
|
|
690
|
-
toolkitSlug
|
|
691
|
-
}
|
|
1021
|
+
`No connected accounts found for toolkit ${toolkitSlug}`
|
|
692
1022
|
);
|
|
693
1023
|
}
|
|
694
1024
|
return metadata.connectedAccountId ? connectedAccounts.items.find((item) => item.id === metadata.connectedAccountId) : connectedAccounts.items[0];
|
|
@@ -703,9 +1033,7 @@ var CustomTools = class {
|
|
|
703
1033
|
async executeCustomTool(slug, inputParams, metadata) {
|
|
704
1034
|
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
705
1035
|
if (!tool) {
|
|
706
|
-
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found
|
|
707
|
-
toolSlug: slug
|
|
708
|
-
});
|
|
1036
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
709
1037
|
}
|
|
710
1038
|
let authCredentials = {};
|
|
711
1039
|
const { toolkitSlug, execute } = tool.options;
|
|
@@ -715,8 +1043,10 @@ var CustomTools = class {
|
|
|
715
1043
|
throw new ComposioConnectedAccountNotFoundError(
|
|
716
1044
|
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}`,
|
|
717
1045
|
{
|
|
718
|
-
|
|
719
|
-
|
|
1046
|
+
meta: {
|
|
1047
|
+
toolkitSlug,
|
|
1048
|
+
userId: metadata.userId
|
|
1049
|
+
}
|
|
720
1050
|
}
|
|
721
1051
|
);
|
|
722
1052
|
}
|
|
@@ -724,7 +1054,9 @@ var CustomTools = class {
|
|
|
724
1054
|
}
|
|
725
1055
|
if (typeof execute !== "function") {
|
|
726
1056
|
throw new ComposioInvalidExecuteFunctionError("Invalid execute function", {
|
|
727
|
-
|
|
1057
|
+
meta: {
|
|
1058
|
+
toolSlug: slug
|
|
1059
|
+
}
|
|
728
1060
|
});
|
|
729
1061
|
}
|
|
730
1062
|
const executeToolRequest = async (data) => {
|
|
@@ -741,36 +1073,50 @@ var CustomTools = class {
|
|
|
741
1073
|
}
|
|
742
1074
|
};
|
|
743
1075
|
|
|
744
|
-
// src/errors/
|
|
745
|
-
var
|
|
1076
|
+
// src/errors/ValidationErrors.ts
|
|
1077
|
+
var import_zod3 = require("zod");
|
|
746
1078
|
var ValidationErrorCodes = {
|
|
747
1079
|
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
748
1080
|
};
|
|
749
1081
|
var ValidationError = class extends ComposioError {
|
|
750
|
-
|
|
751
|
-
|
|
1082
|
+
constructor(message = "Input validation failed", options = {}) {
|
|
1083
|
+
const { cause: providedZodError, ...restOptions } = options;
|
|
752
1084
|
let zodErrorInstance;
|
|
753
|
-
if (
|
|
754
|
-
zodErrorInstance =
|
|
1085
|
+
if (providedZodError instanceof import_zod3.ZodError) {
|
|
1086
|
+
zodErrorInstance = providedZodError;
|
|
1087
|
+
} else {
|
|
1088
|
+
zodErrorInstance = new import_zod3.ZodError([
|
|
755
1089
|
{
|
|
756
1090
|
path: [],
|
|
757
1091
|
message: "Invalid input",
|
|
758
1092
|
code: "custom"
|
|
759
1093
|
}
|
|
760
1094
|
]);
|
|
761
|
-
} else {
|
|
762
|
-
zodErrorInstance = zodError;
|
|
763
1095
|
}
|
|
764
1096
|
const issues = zodErrorInstance.issues.map(
|
|
765
1097
|
(issue) => `[${issue.code}] ${issue.path.join(".")} - ${issue.message}`
|
|
766
1098
|
);
|
|
767
1099
|
super(message, {
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
1100
|
+
...restOptions,
|
|
1101
|
+
code: options.code || ValidationErrorCodes.VALIDATION_ERROR,
|
|
1102
|
+
possibleFixes: issues,
|
|
1103
|
+
cause: zodErrorInstance
|
|
771
1104
|
});
|
|
772
|
-
this.zodError = zodErrorInstance;
|
|
773
1105
|
this.name = "ValidationError";
|
|
1106
|
+
const userFriendlyMessage = this.generateUserFriendlyMessage();
|
|
1107
|
+
this.message = `${message}: ${userFriendlyMessage}`;
|
|
1108
|
+
}
|
|
1109
|
+
generateUserFriendlyMessage() {
|
|
1110
|
+
if (this.cause instanceof import_zod3.ZodError && this.cause.issues.length > 0) {
|
|
1111
|
+
const issue = this.cause.issues[0];
|
|
1112
|
+
const path = issue.path.join(".");
|
|
1113
|
+
const param = path || "parameter";
|
|
1114
|
+
if (issue.code === "invalid_type") {
|
|
1115
|
+
return `The ${param} should be a ${issue.expected}, but you provided a ${issue.received}`;
|
|
1116
|
+
}
|
|
1117
|
+
return issue.message;
|
|
1118
|
+
}
|
|
1119
|
+
return "Please check your input parameters";
|
|
774
1120
|
}
|
|
775
1121
|
};
|
|
776
1122
|
|
|
@@ -940,14 +1286,16 @@ var Tools = class {
|
|
|
940
1286
|
async getRawComposioTools(userId, query = {}, modifier) {
|
|
941
1287
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
942
1288
|
if (queryParams.error) {
|
|
943
|
-
throw new ValidationError(
|
|
1289
|
+
throw new ValidationError("Invalid tool list parameters", {
|
|
1290
|
+
cause: queryParams.error
|
|
1291
|
+
});
|
|
944
1292
|
}
|
|
945
1293
|
const tools = await this.client.tools.list({
|
|
946
|
-
tool_slugs: queryParams.data.tools,
|
|
1294
|
+
tool_slugs: queryParams.data.tools?.join(","),
|
|
947
1295
|
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
948
1296
|
cursor: queryParams.data.cursor,
|
|
949
|
-
important: queryParams.data.important,
|
|
950
|
-
limit: queryParams.data.limit,
|
|
1297
|
+
important: typeof queryParams.data.important === "undefined" ? void 0 : queryParams.data.important ? "true" : "false",
|
|
1298
|
+
limit: queryParams.data.limit?.toString(),
|
|
951
1299
|
search: queryParams.data.search
|
|
952
1300
|
});
|
|
953
1301
|
if (!tools) {
|
|
@@ -961,7 +1309,7 @@ var Tools = class {
|
|
|
961
1309
|
if (modifier) {
|
|
962
1310
|
if (typeof modifier === "function") {
|
|
963
1311
|
modifiedTools = modifiedTools.map((tool) => {
|
|
964
|
-
return modifier(tool.slug, tool.toolkit?.slug
|
|
1312
|
+
return modifier(tool.slug, tool.toolkit?.slug ?? "unknown", tool);
|
|
965
1313
|
});
|
|
966
1314
|
} else {
|
|
967
1315
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
@@ -985,21 +1333,23 @@ var Tools = class {
|
|
|
985
1333
|
if (customTool) {
|
|
986
1334
|
return customTool;
|
|
987
1335
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
1336
|
+
let tool;
|
|
1337
|
+
try {
|
|
1338
|
+
tool = await this.client.tools.retrieve(slug);
|
|
1339
|
+
} catch (error) {
|
|
1340
|
+
throw new ComposioToolNotFoundError(`Unable to retrieve tool with slug ${slug}`, {
|
|
1341
|
+
cause: error
|
|
1342
|
+
});
|
|
993
1343
|
}
|
|
994
|
-
let
|
|
1344
|
+
let modifiedTool = this.transformToolCases(tool);
|
|
995
1345
|
if (modifier) {
|
|
996
1346
|
if (typeof modifier === "function") {
|
|
997
|
-
|
|
1347
|
+
modifiedTool = modifier(slug, modifiedTool.toolkit?.slug ?? "unknown", modifiedTool);
|
|
998
1348
|
} else {
|
|
999
1349
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
1000
1350
|
}
|
|
1001
1351
|
}
|
|
1002
|
-
return
|
|
1352
|
+
return modifiedTool;
|
|
1003
1353
|
}
|
|
1004
1354
|
/**
|
|
1005
1355
|
* Get a tool or list of tools based on the provided arguments.
|
|
@@ -1052,7 +1402,7 @@ var Tools = class {
|
|
|
1052
1402
|
async handleCustomToolExecution(tool, body, modifiers) {
|
|
1053
1403
|
if (modifiers?.beforeExecute) {
|
|
1054
1404
|
if (typeof modifiers.beforeExecute === "function") {
|
|
1055
|
-
body = modifiers.beforeExecute(tool.slug, "
|
|
1405
|
+
body = modifiers.beforeExecute(tool.slug, "unknown", body);
|
|
1056
1406
|
} else {
|
|
1057
1407
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
1058
1408
|
}
|
|
@@ -1063,7 +1413,7 @@ var Tools = class {
|
|
|
1063
1413
|
});
|
|
1064
1414
|
if (modifiers?.afterExecute) {
|
|
1065
1415
|
if (typeof modifiers.afterExecute === "function") {
|
|
1066
|
-
result = modifiers.afterExecute(tool.slug, "
|
|
1416
|
+
result = modifiers.afterExecute(tool.slug, "unknown", result);
|
|
1067
1417
|
} else {
|
|
1068
1418
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
1069
1419
|
}
|
|
@@ -1081,7 +1431,7 @@ var Tools = class {
|
|
|
1081
1431
|
async handleComposioToolExecution(tool, body, modifiers) {
|
|
1082
1432
|
if (modifiers?.beforeExecute) {
|
|
1083
1433
|
if (typeof modifiers.beforeExecute === "function") {
|
|
1084
|
-
body = modifiers.beforeExecute(tool.slug, tool.toolkit?.slug
|
|
1434
|
+
body = modifiers.beforeExecute(tool.slug, tool.toolkit?.slug ?? "unknown", body);
|
|
1085
1435
|
} else {
|
|
1086
1436
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
1087
1437
|
}
|
|
@@ -1102,7 +1452,7 @@ var Tools = class {
|
|
|
1102
1452
|
result = this.transformToolExecuteResponse(result);
|
|
1103
1453
|
if (modifiers?.afterExecute) {
|
|
1104
1454
|
if (typeof modifiers.afterExecute === "function") {
|
|
1105
|
-
result = modifiers.afterExecute(tool.slug, tool.toolkit?.slug
|
|
1455
|
+
result = modifiers.afterExecute(tool.slug, tool.toolkit?.slug ?? "unknown", result);
|
|
1106
1456
|
} else {
|
|
1107
1457
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
1108
1458
|
}
|
|
@@ -1166,9 +1516,12 @@ var Tools = class {
|
|
|
1166
1516
|
return this.handleComposioToolExecution(composioTool, body, modifiers);
|
|
1167
1517
|
}
|
|
1168
1518
|
} catch (error) {
|
|
1169
|
-
throw new ComposioToolExecutionError(
|
|
1170
|
-
|
|
1171
|
-
|
|
1519
|
+
throw new ComposioToolExecutionError(`Error executing tool ${slug}`, {
|
|
1520
|
+
originalError: error,
|
|
1521
|
+
meta: {
|
|
1522
|
+
toolSlug: slug,
|
|
1523
|
+
body
|
|
1524
|
+
}
|
|
1172
1525
|
});
|
|
1173
1526
|
}
|
|
1174
1527
|
}
|
|
@@ -1242,91 +1595,187 @@ var Tools = class {
|
|
|
1242
1595
|
}
|
|
1243
1596
|
};
|
|
1244
1597
|
|
|
1598
|
+
// src/models/Toolkits.ts
|
|
1599
|
+
var import_client4 = __toESM(require("@composio/client"), 1);
|
|
1600
|
+
|
|
1245
1601
|
// src/types/toolkit.types.ts
|
|
1246
|
-
var
|
|
1247
|
-
var ToolkitMangedByEnumSchema =
|
|
1248
|
-
var ToolkitSortByEnumSchema =
|
|
1249
|
-
var ToolkitsListParamsSchema =
|
|
1250
|
-
category:
|
|
1251
|
-
isLocal:
|
|
1602
|
+
var import_zod4 = require("zod");
|
|
1603
|
+
var ToolkitMangedByEnumSchema = import_zod4.z.enum(["all", "composio", "project"]);
|
|
1604
|
+
var ToolkitSortByEnumSchema = import_zod4.z.enum(["usage", "alphabetically"]);
|
|
1605
|
+
var ToolkitsListParamsSchema = import_zod4.z.object({
|
|
1606
|
+
category: import_zod4.z.string().optional(),
|
|
1607
|
+
isLocal: import_zod4.z.boolean().optional(),
|
|
1252
1608
|
managedBy: ToolkitMangedByEnumSchema.optional(),
|
|
1253
1609
|
sortBy: ToolkitSortByEnumSchema.optional()
|
|
1254
1610
|
});
|
|
1255
|
-
var ToolKitMetaSchema =
|
|
1256
|
-
categories:
|
|
1257
|
-
|
|
1258
|
-
slug:
|
|
1259
|
-
name:
|
|
1611
|
+
var ToolKitMetaSchema = import_zod4.z.object({
|
|
1612
|
+
categories: import_zod4.z.array(
|
|
1613
|
+
import_zod4.z.object({
|
|
1614
|
+
slug: import_zod4.z.string(),
|
|
1615
|
+
name: import_zod4.z.string()
|
|
1260
1616
|
})
|
|
1261
1617
|
).optional(),
|
|
1262
|
-
appUrl:
|
|
1263
|
-
createdAt:
|
|
1264
|
-
description:
|
|
1265
|
-
logo:
|
|
1266
|
-
toolsCount:
|
|
1267
|
-
triggersCount:
|
|
1268
|
-
updatedAt:
|
|
1618
|
+
appUrl: import_zod4.z.string().optional(),
|
|
1619
|
+
createdAt: import_zod4.z.string().optional(),
|
|
1620
|
+
description: import_zod4.z.string().optional(),
|
|
1621
|
+
logo: import_zod4.z.string().optional(),
|
|
1622
|
+
toolsCount: import_zod4.z.number().optional(),
|
|
1623
|
+
triggersCount: import_zod4.z.number().optional(),
|
|
1624
|
+
updatedAt: import_zod4.z.string().optional()
|
|
1269
1625
|
});
|
|
1270
|
-
var ToolKitItemSchema =
|
|
1271
|
-
name:
|
|
1272
|
-
slug:
|
|
1626
|
+
var ToolKitItemSchema = import_zod4.z.object({
|
|
1627
|
+
name: import_zod4.z.string(),
|
|
1628
|
+
slug: import_zod4.z.string(),
|
|
1273
1629
|
meta: ToolKitMetaSchema,
|
|
1274
|
-
isLocalToolkit:
|
|
1275
|
-
authSchemes:
|
|
1276
|
-
composioManagedAuthSchemes:
|
|
1277
|
-
noAuth:
|
|
1630
|
+
isLocalToolkit: import_zod4.z.boolean(),
|
|
1631
|
+
authSchemes: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
1632
|
+
composioManagedAuthSchemes: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
1633
|
+
noAuth: import_zod4.z.boolean().optional()
|
|
1278
1634
|
});
|
|
1279
|
-
var ToolKitListResponseSchema =
|
|
1280
|
-
items:
|
|
1281
|
-
nextCursor:
|
|
1282
|
-
totalPages:
|
|
1635
|
+
var ToolKitListResponseSchema = import_zod4.z.object({
|
|
1636
|
+
items: import_zod4.z.array(ToolKitItemSchema),
|
|
1637
|
+
nextCursor: import_zod4.z.string().nullable(),
|
|
1638
|
+
totalPages: import_zod4.z.number()
|
|
1283
1639
|
});
|
|
1284
|
-
var ToolkitAuthFieldSchema =
|
|
1285
|
-
name:
|
|
1286
|
-
displayName:
|
|
1287
|
-
type:
|
|
1288
|
-
default:
|
|
1640
|
+
var ToolkitAuthFieldSchema = import_zod4.z.object({
|
|
1641
|
+
name: import_zod4.z.string(),
|
|
1642
|
+
displayName: import_zod4.z.string(),
|
|
1643
|
+
type: import_zod4.z.string(),
|
|
1644
|
+
default: import_zod4.z.string().nullable().optional()
|
|
1289
1645
|
});
|
|
1290
|
-
var ToolkitAuthConfigDetailsSchema =
|
|
1291
|
-
name:
|
|
1292
|
-
mode:
|
|
1293
|
-
fields:
|
|
1294
|
-
authConfigCreation:
|
|
1295
|
-
optional:
|
|
1296
|
-
required:
|
|
1646
|
+
var ToolkitAuthConfigDetailsSchema = import_zod4.z.object({
|
|
1647
|
+
name: import_zod4.z.string(),
|
|
1648
|
+
mode: import_zod4.z.string(),
|
|
1649
|
+
fields: import_zod4.z.object({
|
|
1650
|
+
authConfigCreation: import_zod4.z.object({
|
|
1651
|
+
optional: import_zod4.z.array(ToolkitAuthFieldSchema),
|
|
1652
|
+
required: import_zod4.z.array(ToolkitAuthFieldSchema)
|
|
1297
1653
|
}),
|
|
1298
|
-
connectedAccountInitiation:
|
|
1299
|
-
optional:
|
|
1300
|
-
required:
|
|
1654
|
+
connectedAccountInitiation: import_zod4.z.object({
|
|
1655
|
+
optional: import_zod4.z.array(ToolkitAuthFieldSchema),
|
|
1656
|
+
required: import_zod4.z.array(ToolkitAuthFieldSchema)
|
|
1301
1657
|
})
|
|
1302
1658
|
}),
|
|
1303
|
-
proxy:
|
|
1304
|
-
baseUrl:
|
|
1659
|
+
proxy: import_zod4.z.object({
|
|
1660
|
+
baseUrl: import_zod4.z.string().optional()
|
|
1305
1661
|
}).optional()
|
|
1306
1662
|
});
|
|
1307
|
-
var ToolkitRetrieveResponseSchema =
|
|
1308
|
-
name:
|
|
1309
|
-
slug:
|
|
1663
|
+
var ToolkitRetrieveResponseSchema = import_zod4.z.object({
|
|
1664
|
+
name: import_zod4.z.string(),
|
|
1665
|
+
slug: import_zod4.z.string(),
|
|
1310
1666
|
meta: ToolKitMetaSchema,
|
|
1311
|
-
isLocalToolkit:
|
|
1312
|
-
composioManagedAuthSchemes:
|
|
1313
|
-
authConfigDetails:
|
|
1667
|
+
isLocalToolkit: import_zod4.z.boolean(),
|
|
1668
|
+
composioManagedAuthSchemes: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
1669
|
+
authConfigDetails: import_zod4.z.array(ToolkitAuthConfigDetailsSchema).optional()
|
|
1314
1670
|
});
|
|
1315
|
-
var ToolkitCategorySchema =
|
|
1316
|
-
id:
|
|
1317
|
-
name:
|
|
1671
|
+
var ToolkitCategorySchema = import_zod4.z.object({
|
|
1672
|
+
id: import_zod4.z.string(),
|
|
1673
|
+
name: import_zod4.z.string()
|
|
1318
1674
|
});
|
|
1319
|
-
var ToolkitRetrieveCategoriesResponseSchema =
|
|
1320
|
-
items:
|
|
1321
|
-
nextCursor:
|
|
1322
|
-
totalPages:
|
|
1675
|
+
var ToolkitRetrieveCategoriesResponseSchema = import_zod4.z.object({
|
|
1676
|
+
items: import_zod4.z.array(ToolkitCategorySchema),
|
|
1677
|
+
nextCursor: import_zod4.z.string().nullable(),
|
|
1678
|
+
totalPages: import_zod4.z.number()
|
|
1323
1679
|
});
|
|
1324
1680
|
|
|
1325
|
-
// src/
|
|
1326
|
-
var
|
|
1681
|
+
// src/errors/AuthConfigErrors.ts
|
|
1682
|
+
var AuthConfigErrorCodes = {
|
|
1683
|
+
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1684
|
+
};
|
|
1685
|
+
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1686
|
+
constructor(message = "Auth config not found", options = {}) {
|
|
1687
|
+
super(message, {
|
|
1688
|
+
...options,
|
|
1689
|
+
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1690
|
+
possibleFixes: options.possibleFixes || [
|
|
1691
|
+
"Check if the auth config exists",
|
|
1692
|
+
"Check if the auth config id is correct",
|
|
1693
|
+
"Check if the auth config is enabled"
|
|
1694
|
+
]
|
|
1695
|
+
});
|
|
1696
|
+
this.name = "ComposioAuthConfigNotFoundError";
|
|
1697
|
+
}
|
|
1698
|
+
};
|
|
1699
|
+
|
|
1700
|
+
// src/errors/ConnectionRequestErrors.ts
|
|
1701
|
+
var ConnectionRequestErrorCodes = {
|
|
1702
|
+
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1703
|
+
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1704
|
+
};
|
|
1705
|
+
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1706
|
+
constructor(message = "Connection request timed out", options = {}) {
|
|
1707
|
+
super(message, {
|
|
1708
|
+
...options,
|
|
1709
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT
|
|
1710
|
+
});
|
|
1711
|
+
this.name = "ConnectionRequestTimeoutError";
|
|
1712
|
+
}
|
|
1713
|
+
};
|
|
1714
|
+
var ConnectionRequestFailedError = class extends ComposioError {
|
|
1715
|
+
constructor(message = "Connection request failed", options = {}) {
|
|
1716
|
+
super(message, {
|
|
1717
|
+
...options,
|
|
1718
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED
|
|
1719
|
+
});
|
|
1720
|
+
this.name = "ConnectionRequestFailedError";
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
|
|
1724
|
+
// src/errors/ToolkitErrors.ts
|
|
1725
|
+
var ToolkitErrorCodes = {
|
|
1726
|
+
TOOLKIT_NOT_FOUND: "TOOLKIT_NOT_FOUND"
|
|
1727
|
+
};
|
|
1728
|
+
var ComposioToolkitNotFoundError = class extends ComposioError {
|
|
1729
|
+
constructor(message = "Toolkit not found", options = {}) {
|
|
1730
|
+
super(message, {
|
|
1731
|
+
...options,
|
|
1732
|
+
code: "TOOLKIT_NOT_FOUND",
|
|
1733
|
+
possibleFixes: options.possibleFixes || [
|
|
1734
|
+
"Ensure the toolkit is correctly configured and the slug is valid"
|
|
1735
|
+
]
|
|
1736
|
+
});
|
|
1737
|
+
this.name = "ComposioToolkitNotFoundError";
|
|
1738
|
+
}
|
|
1739
|
+
};
|
|
1740
|
+
var ComposioToolkitFetchError = class extends ComposioError {
|
|
1741
|
+
constructor(message = "Failed to fetch toolkit", options = {}) {
|
|
1742
|
+
super(message, {
|
|
1743
|
+
...options,
|
|
1744
|
+
code: "TOOLKIT_FETCH_ERROR",
|
|
1745
|
+
possibleFixes: options.possibleFixes || [
|
|
1746
|
+
"Ensure the toolkit slug is valid",
|
|
1747
|
+
"Ensure you are using the correct API key",
|
|
1748
|
+
"Ensure you are using the correct API endpoint / Base URL and it is working"
|
|
1749
|
+
]
|
|
1750
|
+
});
|
|
1751
|
+
this.name = "ComposioToolkitFetchError";
|
|
1752
|
+
}
|
|
1753
|
+
};
|
|
1754
|
+
|
|
1755
|
+
// src/errors/SDKErrors.ts
|
|
1756
|
+
var SDKErrorCodes = {
|
|
1757
|
+
NO_API_KEY_PROVIDED: "NO_API_KEY_PROVIDED"
|
|
1758
|
+
};
|
|
1759
|
+
var ComposioNoAPIKeyError = class extends ComposioError {
|
|
1760
|
+
constructor(message = "No Composio API key provided", options = {}) {
|
|
1761
|
+
const defaultCause = "Couldn't find an API key in the params, environment variables or in the user config file";
|
|
1762
|
+
super(message, {
|
|
1763
|
+
...options,
|
|
1764
|
+
code: "NO_API_KEY",
|
|
1765
|
+
cause: options.cause || defaultCause,
|
|
1766
|
+
possibleFixes: options.possibleFixes || [
|
|
1767
|
+
"Ensure you have an API key passed in the params, or in environment variable (COMPOSIO_API_KEY) or in the user config file",
|
|
1768
|
+
"To get an API key, please sign up at https://composio.dev/signup",
|
|
1769
|
+
"You can also use the Composio CLI to create a project and get an API key"
|
|
1770
|
+
],
|
|
1771
|
+
statusCode: 401
|
|
1772
|
+
});
|
|
1773
|
+
this.name = "ComposioNoAPIKeyError";
|
|
1774
|
+
}
|
|
1775
|
+
};
|
|
1327
1776
|
|
|
1328
1777
|
// src/types/authConfigs.types.ts
|
|
1329
|
-
var
|
|
1778
|
+
var import_zod5 = require("zod");
|
|
1330
1779
|
var AuthConfigTypes = {
|
|
1331
1780
|
CUSTOM: "use_custom_auth",
|
|
1332
1781
|
COMPOSIO_MANAGED: "use_composio_managed_auth"
|
|
@@ -1346,7 +1795,7 @@ var AuthSchemeTypes = {
|
|
|
1346
1795
|
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1347
1796
|
SNOWFLAKE: "SNOWFLAKE"
|
|
1348
1797
|
};
|
|
1349
|
-
var AuthSchemeEnum =
|
|
1798
|
+
var AuthSchemeEnum = import_zod5.z.enum([
|
|
1350
1799
|
"OAUTH2",
|
|
1351
1800
|
"OAUTH1",
|
|
1352
1801
|
"OAUTH1A",
|
|
@@ -1361,67 +1810,67 @@ var AuthSchemeEnum = import_zod4.z.enum([
|
|
|
1361
1810
|
"CALCOM_AUTH",
|
|
1362
1811
|
"SNOWFLAKE"
|
|
1363
1812
|
]);
|
|
1364
|
-
var CreateCustomAuthConfigParamsSchema =
|
|
1365
|
-
type:
|
|
1366
|
-
name:
|
|
1367
|
-
credentials:
|
|
1813
|
+
var CreateCustomAuthConfigParamsSchema = import_zod5.z.object({
|
|
1814
|
+
type: import_zod5.z.literal("use_custom_auth"),
|
|
1815
|
+
name: import_zod5.z.string().optional(),
|
|
1816
|
+
credentials: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.union([import_zod5.z.string(), import_zod5.z.number(), import_zod5.z.boolean()])),
|
|
1368
1817
|
authScheme: AuthSchemeEnum
|
|
1369
1818
|
});
|
|
1370
|
-
var CreateComposioManagedAuthConfigParamsSchema =
|
|
1371
|
-
type:
|
|
1372
|
-
name:
|
|
1373
|
-
credentials:
|
|
1819
|
+
var CreateComposioManagedAuthConfigParamsSchema = import_zod5.z.object({
|
|
1820
|
+
type: import_zod5.z.literal("use_composio_managed_auth"),
|
|
1821
|
+
name: import_zod5.z.string().optional(),
|
|
1822
|
+
credentials: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.union([import_zod5.z.string(), import_zod5.z.number(), import_zod5.z.boolean()])).optional()
|
|
1374
1823
|
});
|
|
1375
|
-
var CreateAuthConfigParamsSchema =
|
|
1824
|
+
var CreateAuthConfigParamsSchema = import_zod5.z.discriminatedUnion("type", [
|
|
1376
1825
|
CreateCustomAuthConfigParamsSchema,
|
|
1377
1826
|
CreateComposioManagedAuthConfigParamsSchema
|
|
1378
1827
|
]);
|
|
1379
|
-
var CreateAuthConfigResponseSchema =
|
|
1380
|
-
id:
|
|
1381
|
-
authScheme:
|
|
1382
|
-
isComposioManaged:
|
|
1383
|
-
toolkit:
|
|
1828
|
+
var CreateAuthConfigResponseSchema = import_zod5.z.object({
|
|
1829
|
+
id: import_zod5.z.string(),
|
|
1830
|
+
authScheme: import_zod5.z.string(),
|
|
1831
|
+
isComposioManaged: import_zod5.z.boolean(),
|
|
1832
|
+
toolkit: import_zod5.z.string()
|
|
1384
1833
|
});
|
|
1385
|
-
var AuthConfigRetrieveResponseSchema =
|
|
1386
|
-
id:
|
|
1387
|
-
name:
|
|
1388
|
-
toolkit:
|
|
1389
|
-
logo:
|
|
1390
|
-
slug:
|
|
1834
|
+
var AuthConfigRetrieveResponseSchema = import_zod5.z.object({
|
|
1835
|
+
id: import_zod5.z.string(),
|
|
1836
|
+
name: import_zod5.z.string(),
|
|
1837
|
+
toolkit: import_zod5.z.object({
|
|
1838
|
+
logo: import_zod5.z.string(),
|
|
1839
|
+
slug: import_zod5.z.string()
|
|
1391
1840
|
}),
|
|
1392
|
-
noOfConnections:
|
|
1393
|
-
status:
|
|
1394
|
-
uuid:
|
|
1841
|
+
noOfConnections: import_zod5.z.number(),
|
|
1842
|
+
status: import_zod5.z.enum(["ENABLED", "DISABLED"]),
|
|
1843
|
+
uuid: import_zod5.z.string(),
|
|
1395
1844
|
authScheme: AuthSchemeEnum.optional(),
|
|
1396
|
-
credentials:
|
|
1397
|
-
expectedInputFields:
|
|
1398
|
-
isComposioManaged:
|
|
1399
|
-
createdBy:
|
|
1400
|
-
createdAt:
|
|
1401
|
-
lastUpdatedAt:
|
|
1845
|
+
credentials: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1846
|
+
expectedInputFields: import_zod5.z.array(import_zod5.z.unknown()).optional(),
|
|
1847
|
+
isComposioManaged: import_zod5.z.boolean().optional(),
|
|
1848
|
+
createdBy: import_zod5.z.string().optional(),
|
|
1849
|
+
createdAt: import_zod5.z.string().optional(),
|
|
1850
|
+
lastUpdatedAt: import_zod5.z.string().optional()
|
|
1402
1851
|
});
|
|
1403
|
-
var AuthConfigListParamsSchema =
|
|
1404
|
-
cursor:
|
|
1405
|
-
isComposioManaged:
|
|
1406
|
-
limit:
|
|
1407
|
-
|
|
1852
|
+
var AuthConfigListParamsSchema = import_zod5.z.object({
|
|
1853
|
+
cursor: import_zod5.z.string().optional(),
|
|
1854
|
+
isComposioManaged: import_zod5.z.boolean().optional(),
|
|
1855
|
+
limit: import_zod5.z.number().optional(),
|
|
1856
|
+
toolkit: import_zod5.z.string().optional()
|
|
1408
1857
|
});
|
|
1409
|
-
var AuthConfigListResponseSchema =
|
|
1410
|
-
items:
|
|
1411
|
-
nextCursor:
|
|
1412
|
-
totalPages:
|
|
1858
|
+
var AuthConfigListResponseSchema = import_zod5.z.object({
|
|
1859
|
+
items: import_zod5.z.array(AuthConfigRetrieveResponseSchema),
|
|
1860
|
+
nextCursor: import_zod5.z.string().nullable(),
|
|
1861
|
+
totalPages: import_zod5.z.number()
|
|
1413
1862
|
});
|
|
1414
|
-
var AuthCustomConfigUpdateParamsSchema =
|
|
1415
|
-
credentials:
|
|
1416
|
-
type:
|
|
1417
|
-
restrictToFollowingTools:
|
|
1863
|
+
var AuthCustomConfigUpdateParamsSchema = import_zod5.z.object({
|
|
1864
|
+
credentials: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.union([import_zod5.z.string(), import_zod5.z.unknown()])),
|
|
1865
|
+
type: import_zod5.z.literal("custom"),
|
|
1866
|
+
restrictToFollowingTools: import_zod5.z.array(import_zod5.z.string()).optional()
|
|
1418
1867
|
});
|
|
1419
|
-
var AuthDefaultConfigUpdateParamsSchema =
|
|
1420
|
-
scopes:
|
|
1421
|
-
type:
|
|
1422
|
-
restrictToFollowingTools:
|
|
1868
|
+
var AuthDefaultConfigUpdateParamsSchema = import_zod5.z.object({
|
|
1869
|
+
scopes: import_zod5.z.string(),
|
|
1870
|
+
type: import_zod5.z.literal("default"),
|
|
1871
|
+
restrictToFollowingTools: import_zod5.z.array(import_zod5.z.string()).optional()
|
|
1423
1872
|
});
|
|
1424
|
-
var AuthConfigUpdateParamsSchema =
|
|
1873
|
+
var AuthConfigUpdateParamsSchema = import_zod5.z.discriminatedUnion("type", [
|
|
1425
1874
|
AuthCustomConfigUpdateParamsSchema,
|
|
1426
1875
|
AuthDefaultConfigUpdateParamsSchema
|
|
1427
1876
|
]);
|
|
@@ -1473,7 +1922,9 @@ var AuthConfigs = class {
|
|
|
1473
1922
|
lastUpdatedAt: authConfig.last_updated_at
|
|
1474
1923
|
});
|
|
1475
1924
|
if (result.error) {
|
|
1476
|
-
throw new ValidationError(
|
|
1925
|
+
throw new ValidationError("Failed to parse auth config response", {
|
|
1926
|
+
cause: result.error
|
|
1927
|
+
});
|
|
1477
1928
|
}
|
|
1478
1929
|
return result.data;
|
|
1479
1930
|
}
|
|
@@ -1494,7 +1945,7 @@ var AuthConfigs = class {
|
|
|
1494
1945
|
*
|
|
1495
1946
|
* // List auth configs for a specific toolkit
|
|
1496
1947
|
* const githubConfigs = await composio.authConfigs.list({
|
|
1497
|
-
*
|
|
1948
|
+
* toolkit: 'github'
|
|
1498
1949
|
* });
|
|
1499
1950
|
*
|
|
1500
1951
|
* // List Composio-managed auth configs
|
|
@@ -1508,8 +1959,8 @@ var AuthConfigs = class {
|
|
|
1508
1959
|
const result = await this.client.authConfigs.list({
|
|
1509
1960
|
cursor: parsedQuery?.cursor,
|
|
1510
1961
|
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1511
|
-
limit: parsedQuery?.limit
|
|
1512
|
-
toolkit_slug: parsedQuery?.
|
|
1962
|
+
limit: parsedQuery?.limit,
|
|
1963
|
+
toolkit_slug: parsedQuery?.toolkit
|
|
1513
1964
|
});
|
|
1514
1965
|
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
1515
1966
|
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
@@ -1517,7 +1968,9 @@ var AuthConfigs = class {
|
|
|
1517
1968
|
totalPages: result.total_pages
|
|
1518
1969
|
});
|
|
1519
1970
|
if (parsedResult.error) {
|
|
1520
|
-
throw new ValidationError(
|
|
1971
|
+
throw new ValidationError("Failed to parse auth config list response", {
|
|
1972
|
+
cause: parsedResult.error
|
|
1973
|
+
});
|
|
1521
1974
|
}
|
|
1522
1975
|
return parsedResult.data;
|
|
1523
1976
|
}
|
|
@@ -1542,7 +1995,9 @@ var AuthConfigs = class {
|
|
|
1542
1995
|
async create(toolkit, options = { type: "use_composio_managed_auth" }) {
|
|
1543
1996
|
const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
|
|
1544
1997
|
if (parsedOptions.error) {
|
|
1545
|
-
throw new ValidationError(
|
|
1998
|
+
throw new ValidationError("Failed to parse auth config create options", {
|
|
1999
|
+
cause: parsedOptions.error
|
|
2000
|
+
});
|
|
1546
2001
|
}
|
|
1547
2002
|
const result = await this.client.authConfigs.create({
|
|
1548
2003
|
toolkit: {
|
|
@@ -1557,7 +2012,9 @@ var AuthConfigs = class {
|
|
|
1557
2012
|
toolkit: result.toolkit.slug
|
|
1558
2013
|
});
|
|
1559
2014
|
if (parsedResult.error) {
|
|
1560
|
-
throw new ValidationError(
|
|
2015
|
+
throw new ValidationError("Failed to parse auth config create response", {
|
|
2016
|
+
cause: parsedResult.error
|
|
2017
|
+
});
|
|
1561
2018
|
}
|
|
1562
2019
|
return parsedResult.data;
|
|
1563
2020
|
}
|
|
@@ -1617,7 +2074,9 @@ var AuthConfigs = class {
|
|
|
1617
2074
|
async update(nanoid, data) {
|
|
1618
2075
|
const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
|
|
1619
2076
|
if (parsedData.error) {
|
|
1620
|
-
throw new ValidationError(
|
|
2077
|
+
throw new ValidationError("Failed to parse auth config update data", {
|
|
2078
|
+
cause: parsedData.error
|
|
2079
|
+
});
|
|
1621
2080
|
}
|
|
1622
2081
|
return this.client.authConfigs.update(
|
|
1623
2082
|
nanoid,
|
|
@@ -1718,71 +2177,50 @@ var AuthConfigs = class {
|
|
|
1718
2177
|
}
|
|
1719
2178
|
};
|
|
1720
2179
|
|
|
1721
|
-
// src/errors/AuthConfigErrors.ts
|
|
1722
|
-
var AuthConfigErrorCodes = {
|
|
1723
|
-
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1724
|
-
};
|
|
1725
|
-
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1726
|
-
constructor(message, meta) {
|
|
1727
|
-
super(message, {
|
|
1728
|
-
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1729
|
-
cause: meta,
|
|
1730
|
-
possibleFixes: [
|
|
1731
|
-
"Check if the auth config exists",
|
|
1732
|
-
"Check if the auth config id is correct",
|
|
1733
|
-
"Check if the auth config is enabled"
|
|
1734
|
-
]
|
|
1735
|
-
});
|
|
1736
|
-
this.name = "ComposioAuthConfigNotFoundError";
|
|
1737
|
-
}
|
|
1738
|
-
};
|
|
1739
|
-
|
|
1740
2180
|
// src/types/connectedAccounts.types.ts
|
|
1741
|
-
var
|
|
2181
|
+
var import_zod6 = require("zod");
|
|
1742
2182
|
var ConnectedAccountStatuses = {
|
|
1743
|
-
|
|
1744
|
-
INACTIVE: "INACTIVE",
|
|
1745
|
-
DELETED: "DELETED",
|
|
2183
|
+
INITIALIZING: "INITIALIZING",
|
|
1746
2184
|
INITIATED: "INITIATED",
|
|
1747
|
-
|
|
1748
|
-
FAILED: "FAILED"
|
|
2185
|
+
ACTIVE: "ACTIVE",
|
|
2186
|
+
FAILED: "FAILED",
|
|
2187
|
+
EXPIRED: "EXPIRED"
|
|
1749
2188
|
};
|
|
1750
|
-
var ConnectedAccountStatusSchema =
|
|
1751
|
-
ConnectedAccountStatuses.
|
|
1752
|
-
ConnectedAccountStatuses.INACTIVE,
|
|
1753
|
-
ConnectedAccountStatuses.DELETED,
|
|
2189
|
+
var ConnectedAccountStatusSchema = import_zod6.z.enum([
|
|
2190
|
+
ConnectedAccountStatuses.INITIALIZING,
|
|
1754
2191
|
ConnectedAccountStatuses.INITIATED,
|
|
1755
|
-
ConnectedAccountStatuses.
|
|
1756
|
-
ConnectedAccountStatuses.FAILED
|
|
2192
|
+
ConnectedAccountStatuses.ACTIVE,
|
|
2193
|
+
ConnectedAccountStatuses.FAILED,
|
|
2194
|
+
ConnectedAccountStatuses.EXPIRED
|
|
1757
2195
|
]);
|
|
1758
|
-
var CreateConnectedAccountParamsSchema =
|
|
1759
|
-
authConfig:
|
|
1760
|
-
id:
|
|
2196
|
+
var CreateConnectedAccountParamsSchema = import_zod6.z.object({
|
|
2197
|
+
authConfig: import_zod6.z.object({
|
|
2198
|
+
id: import_zod6.z.string()
|
|
1761
2199
|
}),
|
|
1762
|
-
connection:
|
|
1763
|
-
data:
|
|
1764
|
-
callbackUrl:
|
|
1765
|
-
userId:
|
|
2200
|
+
connection: import_zod6.z.object({
|
|
2201
|
+
data: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.unknown()).optional(),
|
|
2202
|
+
callbackUrl: import_zod6.z.string().optional(),
|
|
2203
|
+
userId: import_zod6.z.string().optional()
|
|
1766
2204
|
})
|
|
1767
2205
|
});
|
|
1768
|
-
var DefaultCreateConnectedAccountParamsSchema =
|
|
1769
|
-
auth_config:
|
|
1770
|
-
id:
|
|
2206
|
+
var DefaultCreateConnectedAccountParamsSchema = import_zod6.z.object({
|
|
2207
|
+
auth_config: import_zod6.z.object({
|
|
2208
|
+
id: import_zod6.z.string()
|
|
1771
2209
|
}),
|
|
1772
|
-
connection:
|
|
1773
|
-
data:
|
|
1774
|
-
callback_url:
|
|
1775
|
-
user_id:
|
|
2210
|
+
connection: import_zod6.z.object({
|
|
2211
|
+
data: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.unknown()).optional(),
|
|
2212
|
+
callback_url: import_zod6.z.string().optional(),
|
|
2213
|
+
user_id: import_zod6.z.string().optional()
|
|
1776
2214
|
})
|
|
1777
2215
|
});
|
|
1778
|
-
var CreateConnectedAccountOptionsSchema =
|
|
1779
|
-
callbackUrl:
|
|
1780
|
-
data:
|
|
2216
|
+
var CreateConnectedAccountOptionsSchema = import_zod6.z.object({
|
|
2217
|
+
callbackUrl: import_zod6.z.string().optional(),
|
|
2218
|
+
data: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.unknown()).optional()
|
|
1781
2219
|
});
|
|
1782
|
-
var CreateConnectedAccountResponseSchema =
|
|
1783
|
-
id:
|
|
2220
|
+
var CreateConnectedAccountResponseSchema = import_zod6.z.object({
|
|
2221
|
+
id: import_zod6.z.string(),
|
|
1784
2222
|
status: ConnectedAccountStatusSchema,
|
|
1785
|
-
redirectUrl:
|
|
2223
|
+
redirectUrl: import_zod6.z.string().nullable()
|
|
1786
2224
|
});
|
|
1787
2225
|
var ConnectedAccountAuthSchemes = {
|
|
1788
2226
|
OAUTH2: "OAUTH2",
|
|
@@ -1799,7 +2237,7 @@ var ConnectedAccountAuthSchemes = {
|
|
|
1799
2237
|
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1800
2238
|
SNOWFLAKE: "SNOWFLAKE"
|
|
1801
2239
|
};
|
|
1802
|
-
var ConnectedAccountAuthSchemesSchema =
|
|
2240
|
+
var ConnectedAccountAuthSchemesSchema = import_zod6.z.enum([
|
|
1803
2241
|
ConnectedAccountAuthSchemes.OAUTH2,
|
|
1804
2242
|
ConnectedAccountAuthSchemes.OAUTH1,
|
|
1805
2243
|
ConnectedAccountAuthSchemes.OAUTH1A,
|
|
@@ -1814,73 +2252,47 @@ var ConnectedAccountAuthSchemesSchema = import_zod5.z.enum([
|
|
|
1814
2252
|
ConnectedAccountAuthSchemes.CALCOM_AUTH,
|
|
1815
2253
|
ConnectedAccountAuthSchemes.SNOWFLAKE
|
|
1816
2254
|
]);
|
|
1817
|
-
var ConnectedAccountAuthConfigSchema =
|
|
1818
|
-
id:
|
|
2255
|
+
var ConnectedAccountAuthConfigSchema = import_zod6.z.object({
|
|
2256
|
+
id: import_zod6.z.string(),
|
|
1819
2257
|
authScheme: ConnectedAccountAuthSchemesSchema,
|
|
1820
|
-
isComposioManaged:
|
|
1821
|
-
isDisabled:
|
|
2258
|
+
isComposioManaged: import_zod6.z.boolean(),
|
|
2259
|
+
isDisabled: import_zod6.z.boolean()
|
|
1822
2260
|
});
|
|
1823
|
-
var ConnectedAccountRetrieveResponseSchema =
|
|
1824
|
-
id:
|
|
2261
|
+
var ConnectedAccountRetrieveResponseSchema = import_zod6.z.object({
|
|
2262
|
+
id: import_zod6.z.string(),
|
|
1825
2263
|
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1826
|
-
userId:
|
|
1827
|
-
data:
|
|
1828
|
-
params:
|
|
2264
|
+
userId: import_zod6.z.string(),
|
|
2265
|
+
data: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.unknown()),
|
|
2266
|
+
params: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.unknown()).optional(),
|
|
1829
2267
|
status: ConnectedAccountStatusSchema,
|
|
1830
|
-
statusReason:
|
|
1831
|
-
toolkit:
|
|
1832
|
-
slug:
|
|
2268
|
+
statusReason: import_zod6.z.string().nullable(),
|
|
2269
|
+
toolkit: import_zod6.z.object({
|
|
2270
|
+
slug: import_zod6.z.string()
|
|
1833
2271
|
}),
|
|
1834
|
-
testRequestEndpoint:
|
|
1835
|
-
isDisabled:
|
|
1836
|
-
createdAt:
|
|
1837
|
-
updatedAt:
|
|
2272
|
+
testRequestEndpoint: import_zod6.z.string().optional(),
|
|
2273
|
+
isDisabled: import_zod6.z.boolean(),
|
|
2274
|
+
createdAt: import_zod6.z.string(),
|
|
2275
|
+
updatedAt: import_zod6.z.string()
|
|
1838
2276
|
});
|
|
1839
|
-
var ConnectedAccountListParamsSchema =
|
|
1840
|
-
authConfigIds:
|
|
1841
|
-
cursor:
|
|
1842
|
-
labels:
|
|
1843
|
-
limit:
|
|
1844
|
-
orderBy:
|
|
1845
|
-
statuses:
|
|
1846
|
-
toolkitSlugs:
|
|
1847
|
-
userIds:
|
|
2277
|
+
var ConnectedAccountListParamsSchema = import_zod6.z.object({
|
|
2278
|
+
authConfigIds: import_zod6.z.array(import_zod6.z.string()).nullable().optional().describe("The auth config ids of the connected accounts"),
|
|
2279
|
+
cursor: import_zod6.z.number().nullable().optional().describe("The cursor to paginate through the connected accounts"),
|
|
2280
|
+
labels: import_zod6.z.array(import_zod6.z.string()).nullable().optional().describe("The labels of the connected accounts"),
|
|
2281
|
+
limit: import_zod6.z.number().nullable().optional().describe("The limit of the connected accounts to return"),
|
|
2282
|
+
orderBy: import_zod6.z.enum(["created_at", "updated_at"]).optional().describe("The order by of the connected accounts"),
|
|
2283
|
+
statuses: import_zod6.z.array(ConnectedAccountStatusSchema).nullable().optional().describe("The statuses of the connected accounts"),
|
|
2284
|
+
toolkitSlugs: import_zod6.z.array(import_zod6.z.string()).nullable().optional().describe("The toolkit slugs of the connected accounts"),
|
|
2285
|
+
userIds: import_zod6.z.array(import_zod6.z.string()).nullable().optional().describe("The user ids of the connected accounts")
|
|
1848
2286
|
});
|
|
1849
|
-
var ConnectedAccountListResponseSchema =
|
|
1850
|
-
items:
|
|
1851
|
-
nextCursor:
|
|
1852
|
-
totalPages:
|
|
2287
|
+
var ConnectedAccountListResponseSchema = import_zod6.z.object({
|
|
2288
|
+
items: import_zod6.z.array(ConnectedAccountRetrieveResponseSchema).describe("The list of connected accounts"),
|
|
2289
|
+
nextCursor: import_zod6.z.string().nullable().describe("The next cursor to paginate through the connected accounts"),
|
|
2290
|
+
totalPages: import_zod6.z.number().describe("The total number of pages of connected accounts")
|
|
1853
2291
|
});
|
|
1854
2292
|
|
|
1855
2293
|
// src/models/ConnectionRequest.ts
|
|
1856
|
-
var
|
|
1857
|
-
var
|
|
1858
|
-
|
|
1859
|
-
// src/errors/ConnectionRequestError.ts
|
|
1860
|
-
var ConnectionRequestErrorCodes = {
|
|
1861
|
-
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1862
|
-
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1863
|
-
};
|
|
1864
|
-
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1865
|
-
constructor(message = "Connection request timed out", meta = {}) {
|
|
1866
|
-
super(message, {
|
|
1867
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
|
|
1868
|
-
meta
|
|
1869
|
-
});
|
|
1870
|
-
this.name = "ConnectionRequestTimeoutError";
|
|
1871
|
-
}
|
|
1872
|
-
};
|
|
1873
|
-
var ConnectionRequestFailedError = class extends ComposioError {
|
|
1874
|
-
constructor(message = "Connection request failed", meta = {}) {
|
|
1875
|
-
super(message, {
|
|
1876
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED,
|
|
1877
|
-
meta
|
|
1878
|
-
});
|
|
1879
|
-
this.name = "ConnectionRequestFailedError";
|
|
1880
|
-
}
|
|
1881
|
-
};
|
|
1882
|
-
|
|
1883
|
-
// src/models/ConnectionRequest.ts
|
|
2294
|
+
var import_client3 = __toESM(require("@composio/client"), 1);
|
|
2295
|
+
var import_zod7 = require("zod");
|
|
1884
2296
|
var ConnectionRequest = class {
|
|
1885
2297
|
client;
|
|
1886
2298
|
id;
|
|
@@ -1926,7 +2338,7 @@ var ConnectionRequest = class {
|
|
|
1926
2338
|
return parsedResponse;
|
|
1927
2339
|
} catch (error) {
|
|
1928
2340
|
logger_default.error("Error transforming response", error);
|
|
1929
|
-
if (error instanceof
|
|
2341
|
+
if (error instanceof import_zod7.ZodError) {
|
|
1930
2342
|
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1931
2343
|
}
|
|
1932
2344
|
throw error;
|
|
@@ -1966,11 +2378,13 @@ var ConnectionRequest = class {
|
|
|
1966
2378
|
return this.transformResponse(response);
|
|
1967
2379
|
}
|
|
1968
2380
|
} catch (error) {
|
|
1969
|
-
if (error instanceof
|
|
2381
|
+
if (error instanceof import_client3.default.NotFoundError) {
|
|
1970
2382
|
throw new ComposioConnectedAccountNotFoundError(
|
|
1971
2383
|
`Connected account with id ${this.id} not found`,
|
|
1972
2384
|
{
|
|
1973
|
-
|
|
2385
|
+
meta: {
|
|
2386
|
+
connectedAccountId: this.id
|
|
2387
|
+
}
|
|
1974
2388
|
}
|
|
1975
2389
|
);
|
|
1976
2390
|
} else {
|
|
@@ -1979,8 +2393,7 @@ var ConnectionRequest = class {
|
|
|
1979
2393
|
}
|
|
1980
2394
|
const terminalErrorStates = [
|
|
1981
2395
|
ConnectedAccountStatuses.FAILED,
|
|
1982
|
-
ConnectedAccountStatuses.EXPIRED
|
|
1983
|
-
ConnectedAccountStatuses.DELETED
|
|
2396
|
+
ConnectedAccountStatuses.EXPIRED
|
|
1984
2397
|
];
|
|
1985
2398
|
const start = Date.now();
|
|
1986
2399
|
const pollInterval = 1e3;
|
|
@@ -1995,10 +2408,12 @@ var ConnectionRequest = class {
|
|
|
1995
2408
|
throw new ConnectionRequestFailedError(
|
|
1996
2409
|
`Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ""}`,
|
|
1997
2410
|
{
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2411
|
+
meta: {
|
|
2412
|
+
userId: response.user_id,
|
|
2413
|
+
connectedAccountId: this.id,
|
|
2414
|
+
status: response.status,
|
|
2415
|
+
statusReason: response.status_reason
|
|
2416
|
+
}
|
|
2002
2417
|
}
|
|
2003
2418
|
);
|
|
2004
2419
|
}
|
|
@@ -2009,6 +2424,23 @@ var ConnectionRequest = class {
|
|
|
2009
2424
|
}
|
|
2010
2425
|
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${this.id}`);
|
|
2011
2426
|
}
|
|
2427
|
+
/**
|
|
2428
|
+
* Returns a JSON-serializable representation of the connection request
|
|
2429
|
+
* Excludes the private client property to avoid cyclic reference issues
|
|
2430
|
+
*/
|
|
2431
|
+
toJSON() {
|
|
2432
|
+
return {
|
|
2433
|
+
id: this.id,
|
|
2434
|
+
status: this.status,
|
|
2435
|
+
redirectUrl: this.redirectUrl
|
|
2436
|
+
};
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Returns a string representation of the connection request
|
|
2440
|
+
*/
|
|
2441
|
+
toString() {
|
|
2442
|
+
return JSON.stringify(this.toJSON(), null, 2);
|
|
2443
|
+
}
|
|
2012
2444
|
};
|
|
2013
2445
|
|
|
2014
2446
|
// src/models/ConnectedAccounts.ts
|
|
@@ -2036,7 +2468,9 @@ var ConnectedAccounts = class {
|
|
|
2036
2468
|
testRequestEndpoint: response.test_request_endpoint
|
|
2037
2469
|
});
|
|
2038
2470
|
if (!result.success) {
|
|
2039
|
-
throw new ValidationError(
|
|
2471
|
+
throw new ValidationError("Failed to parse connected account retrieve response", {
|
|
2472
|
+
cause: result.error
|
|
2473
|
+
});
|
|
2040
2474
|
}
|
|
2041
2475
|
return result.data;
|
|
2042
2476
|
}
|
|
@@ -2069,7 +2503,9 @@ var ConnectedAccounts = class {
|
|
|
2069
2503
|
if (query) {
|
|
2070
2504
|
const parsedQuery = ConnectedAccountListParamsSchema.safeParse(query);
|
|
2071
2505
|
if (!parsedQuery.success) {
|
|
2072
|
-
throw new ValidationError(
|
|
2506
|
+
throw new ValidationError("Failed to parse connected account list query", {
|
|
2507
|
+
cause: parsedQuery.error
|
|
2508
|
+
});
|
|
2073
2509
|
}
|
|
2074
2510
|
rawQuery = {
|
|
2075
2511
|
auth_config_ids: parsedQuery.data.authConfigIds,
|
|
@@ -2089,7 +2525,9 @@ var ConnectedAccounts = class {
|
|
|
2089
2525
|
totalPages: result.total_pages
|
|
2090
2526
|
});
|
|
2091
2527
|
if (!parsedResponse.success) {
|
|
2092
|
-
throw new ValidationError(
|
|
2528
|
+
throw new ValidationError("Failed to parse connected account list response", {
|
|
2529
|
+
cause: parsedResponse.error
|
|
2530
|
+
});
|
|
2093
2531
|
}
|
|
2094
2532
|
return parsedResponse.data;
|
|
2095
2533
|
}
|
|
@@ -2275,42 +2713,46 @@ var Toolkits = class {
|
|
|
2275
2713
|
* @private
|
|
2276
2714
|
*/
|
|
2277
2715
|
async getToolkits(query) {
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
sort_by: parsedQuery.sortBy
|
|
2284
|
-
});
|
|
2285
|
-
const parsedResult = ToolKitListResponseSchema.parse({
|
|
2286
|
-
items: result.items.map((item) => {
|
|
2287
|
-
const parsedItem = ToolKitItemSchema.parse({
|
|
2288
|
-
name: item.name,
|
|
2289
|
-
slug: item.slug,
|
|
2290
|
-
meta: item.meta,
|
|
2291
|
-
isLocalToolkit: item.is_local_toolkit,
|
|
2292
|
-
authSchemes: item.auth_schemes,
|
|
2293
|
-
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
2294
|
-
noAuth: item.no_auth
|
|
2716
|
+
try {
|
|
2717
|
+
const parsedQuery = ToolkitsListParamsSchema.safeParse(query);
|
|
2718
|
+
if (!parsedQuery.success) {
|
|
2719
|
+
throw new ValidationError("Failed to parse toolkit list query", {
|
|
2720
|
+
cause: parsedQuery.error
|
|
2295
2721
|
});
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2722
|
+
}
|
|
2723
|
+
const result = await this.client.toolkits.list({
|
|
2724
|
+
category: parsedQuery.data.category,
|
|
2725
|
+
is_local: parsedQuery.data.isLocal,
|
|
2726
|
+
managed_by: parsedQuery.data.managedBy,
|
|
2727
|
+
sort_by: parsedQuery.data.sortBy
|
|
2728
|
+
});
|
|
2729
|
+
const parsedResult = ToolKitListResponseSchema.safeParse({
|
|
2730
|
+
items: result.items.map((item) => {
|
|
2731
|
+
const parsedItem = ToolKitItemSchema.parse({
|
|
2732
|
+
name: item.name,
|
|
2733
|
+
slug: item.slug,
|
|
2734
|
+
meta: item.meta,
|
|
2735
|
+
isLocalToolkit: item.is_local_toolkit,
|
|
2736
|
+
authSchemes: item.auth_schemes,
|
|
2737
|
+
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
2738
|
+
noAuth: item.no_auth
|
|
2739
|
+
});
|
|
2740
|
+
return parsedItem;
|
|
2741
|
+
}),
|
|
2742
|
+
nextCursor: result.next_cursor,
|
|
2743
|
+
totalPages: result.total_pages
|
|
2744
|
+
});
|
|
2745
|
+
if (!parsedResult.success) {
|
|
2746
|
+
throw new ValidationError("Failed to parse toolkit list response", {
|
|
2747
|
+
cause: parsedResult.error
|
|
2748
|
+
});
|
|
2749
|
+
}
|
|
2750
|
+
return parsedResult.data;
|
|
2751
|
+
} catch (error) {
|
|
2752
|
+
throw new ComposioToolkitFetchError("Failed to fetch toolkits", {
|
|
2753
|
+
cause: error
|
|
2754
|
+
});
|
|
2312
2755
|
}
|
|
2313
|
-
return this.getToolkits(arg);
|
|
2314
2756
|
}
|
|
2315
2757
|
/**
|
|
2316
2758
|
* Retrieves a specific toolkit by its slug identifier.
|
|
@@ -2328,7 +2770,7 @@ var Toolkits = class {
|
|
|
2328
2770
|
async getToolkitBySlug(slug) {
|
|
2329
2771
|
try {
|
|
2330
2772
|
const result = await this.client.toolkits.retrieve(slug);
|
|
2331
|
-
const parsedResult = ToolkitRetrieveResponseSchema.
|
|
2773
|
+
const parsedResult = ToolkitRetrieveResponseSchema.safeParse({
|
|
2332
2774
|
name: result.name,
|
|
2333
2775
|
slug: result.slug,
|
|
2334
2776
|
meta: {
|
|
@@ -2353,16 +2795,41 @@ var Toolkits = class {
|
|
|
2353
2795
|
}
|
|
2354
2796
|
}))
|
|
2355
2797
|
});
|
|
2356
|
-
|
|
2798
|
+
if (!parsedResult.success) {
|
|
2799
|
+
throw new ValidationError("Failed to parse toolkit response", {
|
|
2800
|
+
cause: parsedResult.error
|
|
2801
|
+
});
|
|
2802
|
+
}
|
|
2803
|
+
return parsedResult.data;
|
|
2357
2804
|
} catch (error) {
|
|
2358
|
-
if (error instanceof
|
|
2359
|
-
throw new
|
|
2805
|
+
if (error instanceof import_client4.default.NotFoundError) {
|
|
2806
|
+
throw new ComposioToolkitNotFoundError(`Toolkit with slug ${slug} not found`, {
|
|
2807
|
+
meta: {
|
|
2808
|
+
slug
|
|
2809
|
+
},
|
|
2810
|
+
cause: error
|
|
2811
|
+
});
|
|
2360
2812
|
}
|
|
2361
|
-
throw new
|
|
2362
|
-
|
|
2813
|
+
throw new ComposioToolkitFetchError(`Couldn't fetch Toolkit with slug: ${slug}`, {
|
|
2814
|
+
meta: {
|
|
2815
|
+
slug
|
|
2816
|
+
},
|
|
2817
|
+
cause: error
|
|
2363
2818
|
});
|
|
2364
2819
|
}
|
|
2365
2820
|
}
|
|
2821
|
+
/**
|
|
2822
|
+
* Implementation method that handles both overloads for retrieving toolkits.
|
|
2823
|
+
*
|
|
2824
|
+
* @param {string | ToolkitListParams} arg - Either a toolkit slug or query parameters
|
|
2825
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit or list of toolkits
|
|
2826
|
+
*/
|
|
2827
|
+
async get(arg) {
|
|
2828
|
+
if (typeof arg === "string") {
|
|
2829
|
+
return this.getToolkitBySlug(arg);
|
|
2830
|
+
}
|
|
2831
|
+
return this.getToolkits(arg);
|
|
2832
|
+
}
|
|
2366
2833
|
/**
|
|
2367
2834
|
* Retrieves all toolkit categories available in the Composio SDK.
|
|
2368
2835
|
*
|
|
@@ -2410,7 +2877,7 @@ var Toolkits = class {
|
|
|
2410
2877
|
const composioAuthConfig = new AuthConfigs(this.client);
|
|
2411
2878
|
let authConfigIdToUse;
|
|
2412
2879
|
const authConfig = await composioAuthConfig.list({
|
|
2413
|
-
toolkitSlug
|
|
2880
|
+
toolkit: toolkitSlug
|
|
2414
2881
|
});
|
|
2415
2882
|
authConfigIdToUse = authConfig.items[0]?.id;
|
|
2416
2883
|
if (!authConfigIdToUse) {
|
|
@@ -2422,7 +2889,9 @@ var Toolkits = class {
|
|
|
2422
2889
|
authConfigIdToUse = authConfig2.id;
|
|
2423
2890
|
} else {
|
|
2424
2891
|
throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
|
|
2425
|
-
|
|
2892
|
+
meta: {
|
|
2893
|
+
toolkitSlug
|
|
2894
|
+
}
|
|
2426
2895
|
});
|
|
2427
2896
|
}
|
|
2428
2897
|
}
|
|
@@ -2431,126 +2900,422 @@ var Toolkits = class {
|
|
|
2431
2900
|
}
|
|
2432
2901
|
};
|
|
2433
2902
|
|
|
2434
|
-
// src/
|
|
2435
|
-
var
|
|
2436
|
-
var
|
|
2437
|
-
var
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2903
|
+
// src/types/triggers.types.ts
|
|
2904
|
+
var import_zod8 = require("zod");
|
|
2905
|
+
var TriggerStatusEnum = import_zod8.z.enum(["enable", "disable"]);
|
|
2906
|
+
var TriggerSubscribeParamSchema = import_zod8.z.object({
|
|
2907
|
+
toolkits: import_zod8.z.array(import_zod8.z.string()).optional(),
|
|
2908
|
+
triggerId: import_zod8.z.string().optional(),
|
|
2909
|
+
connectedAccountId: import_zod8.z.string().optional(),
|
|
2910
|
+
authConfigId: import_zod8.z.string().optional(),
|
|
2911
|
+
triggerSlug: import_zod8.z.array(import_zod8.z.string()).optional(),
|
|
2912
|
+
triggerData: import_zod8.z.string().optional(),
|
|
2913
|
+
userId: import_zod8.z.string().optional()
|
|
2914
|
+
});
|
|
2915
|
+
var TriggerInstanceListActiveParamsSchema = import_zod8.z.object({
|
|
2916
|
+
authConfigIds: import_zod8.z.array(import_zod8.z.string()).nullable().optional(),
|
|
2917
|
+
connectedAccountIds: import_zod8.z.array(import_zod8.z.string()).nullable().optional(),
|
|
2918
|
+
limit: import_zod8.z.number().optional(),
|
|
2919
|
+
page: import_zod8.z.number().optional(),
|
|
2920
|
+
showDisabled: import_zod8.z.boolean().nullable().optional(),
|
|
2921
|
+
triggerIds: import_zod8.z.array(import_zod8.z.string()).nullable().optional(),
|
|
2922
|
+
triggerNames: import_zod8.z.array(import_zod8.z.string()).nullable().optional()
|
|
2923
|
+
});
|
|
2924
|
+
var TriggerInstanceListActiveResponseItemSchema = import_zod8.z.object({
|
|
2925
|
+
id: import_zod8.z.string(),
|
|
2926
|
+
connectedAccountId: import_zod8.z.string(),
|
|
2927
|
+
disabledAt: import_zod8.z.string().nullable(),
|
|
2928
|
+
state: import_zod8.z.record(import_zod8.z.unknown()),
|
|
2929
|
+
triggerConfig: import_zod8.z.record(import_zod8.z.unknown()),
|
|
2930
|
+
triggerName: import_zod8.z.string(),
|
|
2931
|
+
updatedAt: import_zod8.z.string(),
|
|
2932
|
+
triggerData: import_zod8.z.string().optional(),
|
|
2933
|
+
uuid: import_zod8.z.string().optional()
|
|
2934
|
+
});
|
|
2935
|
+
var TriggerInstanceListActiveResponseSchema = import_zod8.z.object({
|
|
2936
|
+
items: import_zod8.z.array(TriggerInstanceListActiveResponseItemSchema),
|
|
2937
|
+
nextCursor: import_zod8.z.string().nullable(),
|
|
2938
|
+
totalPages: import_zod8.z.number()
|
|
2939
|
+
});
|
|
2940
|
+
var TriggerInstanceUpsertParamsSchema = import_zod8.z.object({
|
|
2941
|
+
connectedAccountId: import_zod8.z.string().optional(),
|
|
2942
|
+
triggerConfig: import_zod8.z.record(import_zod8.z.unknown()).optional()
|
|
2943
|
+
});
|
|
2944
|
+
var TriggerInstanceUpsertResponseSchema = import_zod8.z.object({
|
|
2945
|
+
triggerId: import_zod8.z.string()
|
|
2946
|
+
});
|
|
2947
|
+
var TriggerInstanceManageUpdateParamsSchema = import_zod8.z.object({
|
|
2948
|
+
status: import_zod8.z.enum(["enable", "disable"])
|
|
2949
|
+
});
|
|
2950
|
+
var TriggerInstanceManageUpdateResponseSchema = import_zod8.z.object({
|
|
2951
|
+
status: import_zod8.z.enum(["success"])
|
|
2952
|
+
});
|
|
2953
|
+
var TriggerInstanceManageDeleteResponseSchema = import_zod8.z.object({
|
|
2954
|
+
triggerId: import_zod8.z.string()
|
|
2955
|
+
});
|
|
2956
|
+
var IncomingTriggerPayloadSchema = import_zod8.z.object({
|
|
2957
|
+
id: import_zod8.z.string().describe("The ID of the trigger"),
|
|
2958
|
+
triggerSlug: import_zod8.z.string().describe("The slug of the trigger that triggered the event"),
|
|
2959
|
+
toolkitSlug: import_zod8.z.string().describe("The slug of the toolkit that triggered the event"),
|
|
2960
|
+
userId: import_zod8.z.string().describe("The ID of the user that triggered the event"),
|
|
2961
|
+
payload: import_zod8.z.record(import_zod8.z.unknown()).describe("The payload of the trigger").optional(),
|
|
2962
|
+
originalPayload: import_zod8.z.record(import_zod8.z.unknown()).describe("The original payload of the trigger").optional(),
|
|
2963
|
+
metadata: import_zod8.z.object({
|
|
2964
|
+
id: import_zod8.z.string(),
|
|
2965
|
+
toolkitSlug: import_zod8.z.string(),
|
|
2966
|
+
triggerSlug: import_zod8.z.string(),
|
|
2967
|
+
triggerData: import_zod8.z.string().optional(),
|
|
2968
|
+
triggerConfig: import_zod8.z.record(import_zod8.z.unknown()),
|
|
2969
|
+
connectedAccount: import_zod8.z.object({
|
|
2970
|
+
id: import_zod8.z.string(),
|
|
2971
|
+
uuid: import_zod8.z.string(),
|
|
2972
|
+
authConfigId: import_zod8.z.string(),
|
|
2973
|
+
authConfigUUID: import_zod8.z.string(),
|
|
2974
|
+
userId: import_zod8.z.string(),
|
|
2975
|
+
status: import_zod8.z.enum(["ACTIVE", "INACTIVE"])
|
|
2976
|
+
})
|
|
2977
|
+
})
|
|
2978
|
+
});
|
|
2979
|
+
|
|
2980
|
+
// src/services/internal/InternalService.types.ts
|
|
2981
|
+
var import_zod9 = require("zod");
|
|
2982
|
+
var SDKRealtimeCredentialsResponseSchema = import_zod9.z.object({
|
|
2983
|
+
projectId: import_zod9.z.string().describe("The project ID"),
|
|
2984
|
+
pusherKey: import_zod9.z.string().describe("The Pusher key"),
|
|
2985
|
+
pusherCluster: import_zod9.z.string().describe("The Pusher cluster")
|
|
2986
|
+
});
|
|
2987
|
+
|
|
2988
|
+
// src/services/internal/InternalService.ts
|
|
2989
|
+
var SDK_REALTIME_CREDENTIALS_ENDPOINT = "/api/v3/internal/sdk/realtime/credentials";
|
|
2990
|
+
var InternalService = class {
|
|
2991
|
+
constructor(client) {
|
|
2992
|
+
this.client = client;
|
|
2993
|
+
this.client = client;
|
|
2454
2994
|
}
|
|
2455
2995
|
/**
|
|
2456
|
-
*
|
|
2457
|
-
* @
|
|
2458
|
-
* @param {string} event - The event to bind to the channel.
|
|
2459
|
-
* @param {(data: Record<string, unknown>) => void} fn - The callback function to execute when the event is triggered.
|
|
2460
|
-
* @returns {PusherClient} The Pusher client instance.
|
|
2996
|
+
* Get the SDK realtime credentials
|
|
2997
|
+
* @returns {SDKRealtimeCredentialsResponse} The SDK realtime credentials
|
|
2461
2998
|
*/
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2999
|
+
async getSDKRealtimeCredentials() {
|
|
3000
|
+
const response = await this.client.request({
|
|
3001
|
+
method: "get",
|
|
3002
|
+
path: SDK_REALTIME_CREDENTIALS_ENDPOINT
|
|
3003
|
+
});
|
|
3004
|
+
const parsedResponse = SDKRealtimeCredentialsResponseSchema.safeParse({
|
|
3005
|
+
pusherKey: response.pusher_key,
|
|
3006
|
+
projectId: response.project_id,
|
|
3007
|
+
pusherCluster: response.pusher_cluster
|
|
3008
|
+
});
|
|
3009
|
+
logger_default.debug(
|
|
3010
|
+
`[InternalService] SDK realtime credentials: ${JSON.stringify(parsedResponse, null, 2)}`
|
|
3011
|
+
);
|
|
3012
|
+
if (!parsedResponse.success) {
|
|
3013
|
+
throw new ValidationError(`Failed to parse SDK realtime credentials`, {
|
|
3014
|
+
cause: parsedResponse.error
|
|
3015
|
+
});
|
|
2469
3016
|
}
|
|
3017
|
+
return parsedResponse.data;
|
|
2470
3018
|
}
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
3019
|
+
};
|
|
3020
|
+
|
|
3021
|
+
// src/errors/TriggerErrors.ts
|
|
3022
|
+
var import_client5 = require("@composio/client");
|
|
3023
|
+
var TriggerErrorCodes = {
|
|
3024
|
+
TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS: "TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS",
|
|
3025
|
+
TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT: "TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT",
|
|
3026
|
+
TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL",
|
|
3027
|
+
TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL"
|
|
3028
|
+
};
|
|
3029
|
+
var ComposioFailedToGetSDKRealtimeCredentialsError = class extends import_client5.ComposioError {
|
|
3030
|
+
name = "ComposioFailedToGetSDKRealtimeCredentialsError";
|
|
3031
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS;
|
|
3032
|
+
statusCode = 500;
|
|
3033
|
+
possibleFixes = ["Please contact support."];
|
|
3034
|
+
constructor(message, options) {
|
|
3035
|
+
super(message, options);
|
|
3036
|
+
}
|
|
3037
|
+
};
|
|
3038
|
+
var ComposioFailedToCreatePusherClientError = class extends import_client5.ComposioError {
|
|
3039
|
+
name = "ComposioFailedToCreatePusherClientError";
|
|
3040
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT;
|
|
3041
|
+
statusCode = 500;
|
|
3042
|
+
possibleFixes = ["Please contact support."];
|
|
3043
|
+
constructor(message, options) {
|
|
3044
|
+
super(message, options);
|
|
3045
|
+
}
|
|
3046
|
+
};
|
|
3047
|
+
var ComposioFailedToSubscribeToPusherChannelError = class extends import_client5.ComposioError {
|
|
3048
|
+
name = "ComposioFailedToSubscribeToPusherChannelError";
|
|
3049
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL;
|
|
3050
|
+
statusCode = 500;
|
|
3051
|
+
possibleFixes = ["Please contact support."];
|
|
3052
|
+
constructor(message, options) {
|
|
3053
|
+
super(message, options);
|
|
3054
|
+
}
|
|
3055
|
+
};
|
|
3056
|
+
|
|
3057
|
+
// src/services/pusher/Pusher.ts
|
|
3058
|
+
var PusherService = class {
|
|
3059
|
+
// these values are set via the Apollo API `/internal/sdk/realtime/credentials` endpoint
|
|
3060
|
+
clientId;
|
|
3061
|
+
pusherKey;
|
|
3062
|
+
pusherCluster;
|
|
3063
|
+
pusherChannel;
|
|
3064
|
+
// these details are set via the client SDK
|
|
3065
|
+
pusherBaseURL;
|
|
3066
|
+
apiKey;
|
|
3067
|
+
pusherClient;
|
|
3068
|
+
composioClient;
|
|
3069
|
+
constructor(client) {
|
|
3070
|
+
this.composioClient = client;
|
|
3071
|
+
this.pusherBaseURL = client.baseURL;
|
|
3072
|
+
this.apiKey = client.apiKey ?? process.env.COMPOSIO_API_KEY ?? "";
|
|
3073
|
+
telemetry.instrument(this);
|
|
2478
3074
|
}
|
|
2479
3075
|
/**
|
|
2480
|
-
*
|
|
2481
|
-
*
|
|
2482
|
-
*
|
|
2483
|
-
*
|
|
3076
|
+
* Creates a Pusher client
|
|
3077
|
+
*
|
|
3078
|
+
* This method is called when the Pusher client is first used.
|
|
3079
|
+
* It will fetch the SDK realtime credentials from the Apollo API and create a Pusher client.
|
|
2484
3080
|
*/
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
3081
|
+
async getPusherClient() {
|
|
3082
|
+
if (!this.pusherClient) {
|
|
3083
|
+
const internalService = new InternalService(this.composioClient);
|
|
3084
|
+
let sdkRealtimeCredentials;
|
|
3085
|
+
try {
|
|
3086
|
+
sdkRealtimeCredentials = await internalService.getSDKRealtimeCredentials();
|
|
3087
|
+
} catch (error) {
|
|
3088
|
+
throw new ComposioFailedToGetSDKRealtimeCredentialsError(
|
|
3089
|
+
"Failed to get SDK realtime credentials",
|
|
3090
|
+
{
|
|
3091
|
+
cause: error
|
|
3092
|
+
}
|
|
3093
|
+
);
|
|
2492
3094
|
}
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
3095
|
+
this.clientId = sdkRealtimeCredentials.projectId;
|
|
3096
|
+
this.pusherKey = sdkRealtimeCredentials.pusherKey;
|
|
3097
|
+
this.pusherCluster = sdkRealtimeCredentials.pusherCluster;
|
|
3098
|
+
this.pusherChannel = `private-${this.clientId}_triggers`;
|
|
3099
|
+
logger_default.debug(
|
|
3100
|
+
`[PusherService] Creating Pusher client for client ID: ${this.clientId} in cluster ${this.pusherCluster}`
|
|
3101
|
+
);
|
|
3102
|
+
try {
|
|
3103
|
+
const { default: Pusher } = await import("pusher-js");
|
|
3104
|
+
this.pusherClient = new Pusher(this.pusherKey, {
|
|
3105
|
+
cluster: this.pusherCluster,
|
|
3106
|
+
channelAuthorization: {
|
|
3107
|
+
endpoint: `${this.pusherBaseURL}/api/v3/internal/sdk/realtime/auth`,
|
|
3108
|
+
headers: {
|
|
3109
|
+
"x-api-key": this.apiKey
|
|
3110
|
+
},
|
|
3111
|
+
transport: "ajax"
|
|
3112
|
+
}
|
|
3113
|
+
});
|
|
3114
|
+
} catch (error) {
|
|
3115
|
+
throw new ComposioFailedToCreatePusherClientError("Failed to create Pusher client", {
|
|
3116
|
+
cause: error
|
|
3117
|
+
});
|
|
2499
3118
|
}
|
|
2500
|
-
}
|
|
3119
|
+
}
|
|
3120
|
+
return this.pusherClient;
|
|
2501
3121
|
}
|
|
2502
3122
|
/**
|
|
2503
|
-
*
|
|
2504
|
-
*
|
|
2505
|
-
*
|
|
3123
|
+
* Binds a chunked event to a Pusher client
|
|
3124
|
+
*
|
|
3125
|
+
*
|
|
3126
|
+
* @param channel - The Pusher client to bind the event to
|
|
3127
|
+
* @param event - The event to bind to
|
|
3128
|
+
* @param callback - The function to call when the event is received
|
|
2506
3129
|
*/
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
3130
|
+
bindWithChunking(channel, event, callback) {
|
|
3131
|
+
try {
|
|
3132
|
+
channel.bind(event, callback);
|
|
3133
|
+
const events = {};
|
|
3134
|
+
channel.bind("chunked-" + event, (data) => {
|
|
3135
|
+
try {
|
|
3136
|
+
const typedData = data;
|
|
3137
|
+
if (!typedData || typeof typedData.id !== "string" || typeof typedData.index !== "number") {
|
|
3138
|
+
throw new Error("Invalid chunked trigger data format");
|
|
3139
|
+
}
|
|
3140
|
+
if (!events.hasOwnProperty(typedData.id)) {
|
|
3141
|
+
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
3142
|
+
}
|
|
3143
|
+
const ev = events[typedData.id];
|
|
3144
|
+
ev.chunks[typedData.index] = typedData.chunk;
|
|
3145
|
+
if (typedData.final) ev.receivedFinal = true;
|
|
3146
|
+
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
3147
|
+
try {
|
|
3148
|
+
const parsedData = JSON.parse(ev.chunks.join(""));
|
|
3149
|
+
callback(parsedData);
|
|
3150
|
+
} catch (parseError) {
|
|
3151
|
+
const errorMessage = parseError instanceof Error ? parseError.message : String(parseError);
|
|
3152
|
+
logger_default.error("Failed to parse chunked data:", errorMessage);
|
|
3153
|
+
} finally {
|
|
3154
|
+
delete events[typedData.id];
|
|
3155
|
+
}
|
|
3156
|
+
}
|
|
3157
|
+
} catch (error) {
|
|
3158
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3159
|
+
logger_default.error("Error processing chunked trigger data:", errorMessage);
|
|
3160
|
+
if (data && typeof data === "object" && "id" in data) {
|
|
3161
|
+
delete events[data.id];
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
});
|
|
3165
|
+
} catch (error) {
|
|
3166
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3167
|
+
logger_default.error("Failed to bind chunked events:", error);
|
|
3168
|
+
throw new Error(`Failed to bind chunked events: ${errorMessage}`);
|
|
3169
|
+
}
|
|
2522
3170
|
}
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
3171
|
+
/**
|
|
3172
|
+
* Subscribes to pusher to receive events from the server
|
|
3173
|
+
*
|
|
3174
|
+
* This method is used to subscribe to a Pusher channel.
|
|
3175
|
+
* It will create a Pusher client if it doesn't exist.
|
|
3176
|
+
*
|
|
3177
|
+
* @param channelName - The name of the Pusher channel to subscribe to
|
|
3178
|
+
* @param event - The event to subscribe to
|
|
3179
|
+
* @param fn - The function to call when the event is received
|
|
3180
|
+
*/
|
|
3181
|
+
async subscribe(fn) {
|
|
3182
|
+
try {
|
|
3183
|
+
logger_default.debug(`[PusherService] Subscribing to channel: ${this.pusherChannel}`);
|
|
3184
|
+
const pusherClient = await this.getPusherClient();
|
|
3185
|
+
const channel = await pusherClient.subscribe(this.pusherChannel);
|
|
3186
|
+
channel.bind("pusher:subscription_error", (data) => {
|
|
3187
|
+
const error = data.error ? String(data.error) : "Unknown subscription error";
|
|
3188
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3189
|
+
`Trigger subscription error: ${error}`,
|
|
3190
|
+
{
|
|
3191
|
+
cause: error
|
|
3192
|
+
}
|
|
3193
|
+
);
|
|
3194
|
+
});
|
|
3195
|
+
const safeCallback = (data) => {
|
|
3196
|
+
try {
|
|
3197
|
+
fn(data);
|
|
3198
|
+
} catch (error) {
|
|
3199
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3200
|
+
logger_default.error("\u274C Error in trigger callback:", errorMessage);
|
|
3201
|
+
}
|
|
3202
|
+
};
|
|
3203
|
+
this.bindWithChunking(channel, "trigger_to_client", safeCallback);
|
|
3204
|
+
logger_default.info(`\u2705 Subscribed to triggers. You should start receiving events now.`);
|
|
3205
|
+
} catch (error) {
|
|
3206
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3207
|
+
"Failed to subscribe to Pusher channel",
|
|
3208
|
+
{
|
|
3209
|
+
cause: error
|
|
3210
|
+
}
|
|
3211
|
+
);
|
|
3212
|
+
}
|
|
2531
3213
|
}
|
|
2532
3214
|
/**
|
|
2533
|
-
*
|
|
2534
|
-
*
|
|
3215
|
+
* Unsubscribes from a Pusher channel
|
|
3216
|
+
*
|
|
3217
|
+
* This method is used to unsubscribe from a Pusher channel.
|
|
3218
|
+
* It will create a Pusher client if it doesn't exist.
|
|
3219
|
+
*
|
|
3220
|
+
* @param channelName - The name of the Pusher channel to unsubscribe from
|
|
2535
3221
|
*/
|
|
2536
|
-
async
|
|
2537
|
-
|
|
3222
|
+
async unsubscribe() {
|
|
3223
|
+
try {
|
|
3224
|
+
logger_default.debug(`[PusherService] Unsubscribing from channel: ${this.pusherChannel}`);
|
|
3225
|
+
const pusherClient = await this.getPusherClient();
|
|
3226
|
+
await pusherClient.unsubscribe(this.pusherChannel);
|
|
3227
|
+
logger_default.info(`\u2705 Unsubscribed from triggers.`);
|
|
3228
|
+
} catch (error) {
|
|
3229
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3230
|
+
"Failed to unsubscribe from Pusher channel",
|
|
3231
|
+
{
|
|
3232
|
+
cause: error
|
|
3233
|
+
}
|
|
3234
|
+
);
|
|
3235
|
+
}
|
|
2538
3236
|
}
|
|
2539
3237
|
};
|
|
2540
3238
|
|
|
2541
3239
|
// src/models/Triggers.ts
|
|
2542
3240
|
var Triggers = class {
|
|
2543
3241
|
client;
|
|
3242
|
+
pusherService;
|
|
2544
3243
|
constructor(client) {
|
|
2545
3244
|
this.client = client;
|
|
3245
|
+
this.pusherService = new PusherService(client);
|
|
2546
3246
|
telemetry.instrument(this);
|
|
2547
3247
|
}
|
|
3248
|
+
/**
|
|
3249
|
+
* Parse the trigger instance list active item
|
|
3250
|
+
*
|
|
3251
|
+
* @param response - The response from the composio client
|
|
3252
|
+
* @returns The parsed trigger instance list active item
|
|
3253
|
+
*/
|
|
3254
|
+
parseTriggerInstanceListActiveItem(response) {
|
|
3255
|
+
const parsed = TriggerInstanceListActiveResponseItemSchema.safeParse({
|
|
3256
|
+
id: response.id,
|
|
3257
|
+
connectedAccountId: response.connected_account_id,
|
|
3258
|
+
disabledAt: response.disabled_at,
|
|
3259
|
+
state: response.state,
|
|
3260
|
+
triggerConfig: response.trigger_config,
|
|
3261
|
+
triggerName: response.trigger_name,
|
|
3262
|
+
updatedAt: response.updated_at,
|
|
3263
|
+
triggerData: response.trigger_data,
|
|
3264
|
+
uuid: response.uuid
|
|
3265
|
+
});
|
|
3266
|
+
if (!parsed.success) {
|
|
3267
|
+
throw new ValidationError(`Invalid trigger instance list active item`, {
|
|
3268
|
+
cause: parsed.error
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
return parsed.data;
|
|
3272
|
+
}
|
|
2548
3273
|
/**
|
|
2549
3274
|
* Fetch list of all the active triggers
|
|
2550
|
-
*
|
|
3275
|
+
*
|
|
3276
|
+
* @param {TriggerInstanceListActiveParams} query - The query parameters to filter the trigger instances
|
|
3277
|
+
* @returns {Promise<TriggerInstanceListActiveResponse>} List of trigger instances
|
|
3278
|
+
*
|
|
3279
|
+
* @throws {ValidationError} If the parameters are invalid
|
|
3280
|
+
* @throws {Error} If the client is not authenticated
|
|
3281
|
+
*
|
|
3282
|
+
* @example
|
|
3283
|
+
* ```ts
|
|
3284
|
+
* const triggers = await triggers.listActive({
|
|
3285
|
+
* authConfigIds: ['123'],
|
|
3286
|
+
* connectedAccountIds: ['456'],
|
|
3287
|
+
* });
|
|
3288
|
+
* ```
|
|
2551
3289
|
*/
|
|
2552
|
-
async
|
|
2553
|
-
|
|
3290
|
+
async listActive(query) {
|
|
3291
|
+
const parsedParams = TriggerInstanceListActiveParamsSchema.safeParse(query ?? {});
|
|
3292
|
+
if (!parsedParams.success) {
|
|
3293
|
+
throw new ValidationError(`Invalid parameters passed to list triggers`, {
|
|
3294
|
+
cause: parsedParams.error
|
|
3295
|
+
});
|
|
3296
|
+
}
|
|
3297
|
+
const result = await this.client.triggerInstances.listActive(
|
|
3298
|
+
query ? {
|
|
3299
|
+
auth_config_ids: parsedParams.data.authConfigIds,
|
|
3300
|
+
connected_account_ids: parsedParams.data.connectedAccountIds,
|
|
3301
|
+
limit: parsedParams.data.limit,
|
|
3302
|
+
page: parsedParams.data.page,
|
|
3303
|
+
show_disabled: parsedParams.data.showDisabled,
|
|
3304
|
+
trigger_ids: parsedParams.data.triggerIds,
|
|
3305
|
+
trigger_names: parsedParams.data.triggerNames
|
|
3306
|
+
} : void 0
|
|
3307
|
+
);
|
|
3308
|
+
const parsedResult = TriggerInstanceListActiveResponseSchema.safeParse({
|
|
3309
|
+
items: result.items.map((item) => this.parseTriggerInstanceListActiveItem(item)),
|
|
3310
|
+
nextCursor: result.next_cursor,
|
|
3311
|
+
totalPages: result.total_pages
|
|
3312
|
+
});
|
|
3313
|
+
if (!parsedResult.success) {
|
|
3314
|
+
throw new ValidationError(`Invalid trigger instance list active response`, {
|
|
3315
|
+
cause: parsedResult.error
|
|
3316
|
+
});
|
|
3317
|
+
}
|
|
3318
|
+
return parsedResult.data;
|
|
2554
3319
|
}
|
|
2555
3320
|
/**
|
|
2556
3321
|
* Create a new trigger instance
|
|
@@ -2559,58 +3324,76 @@ var Triggers = class {
|
|
|
2559
3324
|
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
2560
3325
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
2561
3326
|
*/
|
|
2562
|
-
async create(slug, body
|
|
2563
|
-
|
|
3327
|
+
async create(slug, body) {
|
|
3328
|
+
const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body);
|
|
3329
|
+
if (!parsedBody.success) {
|
|
3330
|
+
throw new ValidationError(`Invalid parameters passed to create trigger`, {
|
|
3331
|
+
cause: parsedBody.error
|
|
3332
|
+
});
|
|
3333
|
+
}
|
|
3334
|
+
const result = await this.client.triggerInstances.upsert(slug, {
|
|
3335
|
+
connected_account_id: parsedBody.data.connectedAccountId,
|
|
3336
|
+
trigger_config: parsedBody.data.triggerConfig
|
|
3337
|
+
});
|
|
3338
|
+
const parsedResult = TriggerInstanceUpsertResponseSchema.safeParse({
|
|
3339
|
+
triggerId: result.trigger_id
|
|
3340
|
+
});
|
|
3341
|
+
if (!parsedResult.success) {
|
|
3342
|
+
throw new ValidationError(`Invalid trigger instance upsert response`, {
|
|
3343
|
+
cause: parsedResult.error
|
|
3344
|
+
});
|
|
3345
|
+
}
|
|
3346
|
+
return parsedResult.data;
|
|
2564
3347
|
}
|
|
2565
3348
|
/**
|
|
2566
3349
|
* Update an existing trigger instance
|
|
2567
3350
|
*
|
|
2568
3351
|
* @param {string} slug - The slug of the trigger instance
|
|
2569
|
-
* @param {
|
|
3352
|
+
* @param {TriggerInstanceManageUpdateParams} body - The parameters to create the trigger instance
|
|
2570
3353
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2571
3354
|
*/
|
|
2572
|
-
async update(slug, body
|
|
2573
|
-
return this.client.triggerInstances.
|
|
3355
|
+
async update(slug, body) {
|
|
3356
|
+
return this.client.triggerInstances.manage.update(slug, body);
|
|
2574
3357
|
}
|
|
2575
3358
|
/**
|
|
2576
3359
|
* Delete a trigger instance
|
|
2577
3360
|
*
|
|
2578
|
-
* @param {string}
|
|
3361
|
+
* @param {string} triggerId - The slug of the trigger instance
|
|
2579
3362
|
* @returns
|
|
2580
3363
|
*/
|
|
2581
|
-
async delete(
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
async updateStatus(status, params, options) {
|
|
2593
|
-
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
3364
|
+
async delete(triggerId) {
|
|
3365
|
+
const result = await this.client.triggerInstances.manage.delete(triggerId);
|
|
3366
|
+
const parsedResult = TriggerInstanceManageDeleteResponseSchema.safeParse({
|
|
3367
|
+
triggerId: result.trigger_id
|
|
3368
|
+
});
|
|
3369
|
+
if (!parsedResult.success) {
|
|
3370
|
+
throw new ValidationError(`Invalid trigger instance manage delete response`, {
|
|
3371
|
+
cause: parsedResult.error
|
|
3372
|
+
});
|
|
3373
|
+
}
|
|
3374
|
+
return parsedResult.data;
|
|
2594
3375
|
}
|
|
2595
3376
|
/**
|
|
2596
3377
|
* Disable a trigger instance
|
|
2597
3378
|
*
|
|
2598
|
-
* @param {string}
|
|
2599
|
-
* @param {RequestOptions options - Request options
|
|
3379
|
+
* @param {string} triggerId - The id of the trigger instance
|
|
2600
3380
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2601
3381
|
*/
|
|
2602
|
-
async disable(
|
|
2603
|
-
return this.client.triggerInstances.
|
|
3382
|
+
async disable(triggerId) {
|
|
3383
|
+
return this.client.triggerInstances.manage.update(triggerId, {
|
|
3384
|
+
status: "disable"
|
|
3385
|
+
});
|
|
2604
3386
|
}
|
|
2605
3387
|
/**
|
|
2606
3388
|
* Enable a trigger instance
|
|
2607
3389
|
*
|
|
2608
|
-
* @param {string}
|
|
2609
|
-
* @param {RequestOptions options - Request options
|
|
3390
|
+
* @param {string} triggerId - The id of the trigger instance
|
|
2610
3391
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2611
3392
|
*/
|
|
2612
|
-
async enable(
|
|
2613
|
-
return this.client.triggerInstances.
|
|
3393
|
+
async enable(triggerId) {
|
|
3394
|
+
return this.client.triggerInstances.manage.update(triggerId, {
|
|
3395
|
+
status: "enable"
|
|
3396
|
+
});
|
|
2614
3397
|
}
|
|
2615
3398
|
/**
|
|
2616
3399
|
* @TODO Learn about trigger types
|
|
@@ -2622,8 +3405,8 @@ var Triggers = class {
|
|
|
2622
3405
|
* @param {RequestOptions} options - Request options
|
|
2623
3406
|
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
|
|
2624
3407
|
*/
|
|
2625
|
-
async listTypes(query
|
|
2626
|
-
return this.client.triggersTypes.list(query
|
|
3408
|
+
async listTypes(query) {
|
|
3409
|
+
return this.client.triggersTypes.list(query);
|
|
2627
3410
|
}
|
|
2628
3411
|
/**
|
|
2629
3412
|
* Retrieve a trigger type by its slug
|
|
@@ -2632,8 +3415,8 @@ var Triggers = class {
|
|
|
2632
3415
|
* @param {RequestOptions} options - request options
|
|
2633
3416
|
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
2634
3417
|
*/
|
|
2635
|
-
async getType(slug
|
|
2636
|
-
return this.client.triggersTypes.retrieve(slug
|
|
3418
|
+
async getType(slug) {
|
|
3419
|
+
return this.client.triggersTypes.retrieve(slug);
|
|
2637
3420
|
}
|
|
2638
3421
|
/**
|
|
2639
3422
|
* Fetches the list of all the available trigger enums
|
|
@@ -2642,36 +3425,137 @@ var Triggers = class {
|
|
|
2642
3425
|
* @param options
|
|
2643
3426
|
* @returns
|
|
2644
3427
|
*/
|
|
2645
|
-
async listEnum(
|
|
2646
|
-
return this.client.triggersTypes.retrieveEnum(
|
|
3428
|
+
async listEnum() {
|
|
3429
|
+
return this.client.triggersTypes.retrieveEnum();
|
|
2647
3430
|
}
|
|
3431
|
+
/**
|
|
3432
|
+
* Subscribe to all the triggers
|
|
3433
|
+
*
|
|
3434
|
+
* @param fn - The function to call when a trigger is received
|
|
3435
|
+
* @param filters - The filters to apply to the triggers
|
|
3436
|
+
*
|
|
3437
|
+
* @example
|
|
3438
|
+
* ```ts
|
|
3439
|
+
*
|
|
3440
|
+
* triggers.subscribe((data) => {
|
|
3441
|
+
* console.log(data);
|
|
3442
|
+
* }, );
|
|
3443
|
+
* ```
|
|
3444
|
+
*/
|
|
2648
3445
|
async subscribe(fn, filters = {}) {
|
|
2649
3446
|
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
2650
|
-
const
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
const
|
|
2657
|
-
if (
|
|
2658
|
-
|
|
2659
|
-
|
|
3447
|
+
const parsedFilters = TriggerSubscribeParamSchema.safeParse(filters);
|
|
3448
|
+
if (!parsedFilters.success) {
|
|
3449
|
+
throw new ValidationError(`Invalid parameters passed to subscribe to triggers`, {
|
|
3450
|
+
cause: parsedFilters.error
|
|
3451
|
+
});
|
|
3452
|
+
}
|
|
3453
|
+
const shouldSendTriggerAfterFilters = (data) => {
|
|
3454
|
+
if (parsedFilters.data.toolkits?.length && !parsedFilters.data.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
|
|
3455
|
+
logger_default.debug(
|
|
3456
|
+
"Trigger does not match toolkits filter",
|
|
3457
|
+
JSON.stringify(parsedFilters.data.toolkits, null, 2)
|
|
3458
|
+
);
|
|
3459
|
+
return false;
|
|
2660
3460
|
}
|
|
3461
|
+
if (parsedFilters.data.triggerId && parsedFilters.data.triggerId !== data.id) {
|
|
3462
|
+
logger_default.debug(
|
|
3463
|
+
"Trigger does not match triggerId filter",
|
|
3464
|
+
JSON.stringify(parsedFilters.data.triggerId, null, 2)
|
|
3465
|
+
);
|
|
3466
|
+
return false;
|
|
3467
|
+
}
|
|
3468
|
+
if (parsedFilters.data.connectedAccountId && parsedFilters.data.connectedAccountId !== data.metadata.connectedAccount.id) {
|
|
3469
|
+
logger_default.debug(
|
|
3470
|
+
"Trigger does not match connectedAccountId filter",
|
|
3471
|
+
JSON.stringify(parsedFilters.data.connectedAccountId, null, 2)
|
|
3472
|
+
);
|
|
3473
|
+
return false;
|
|
3474
|
+
}
|
|
3475
|
+
if (parsedFilters.data.triggerSlug?.length && !parsedFilters.data.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
|
|
3476
|
+
logger_default.debug(
|
|
3477
|
+
"Trigger does not match triggerSlug filter",
|
|
3478
|
+
JSON.stringify(parsedFilters.data.triggerSlug, null, 2)
|
|
3479
|
+
);
|
|
3480
|
+
return false;
|
|
3481
|
+
}
|
|
3482
|
+
if (parsedFilters.data.triggerData && parsedFilters.data.triggerData !== data.metadata.triggerData) {
|
|
3483
|
+
logger_default.debug(
|
|
3484
|
+
"Trigger does not match triggerData filter",
|
|
3485
|
+
JSON.stringify(parsedFilters.data.triggerData, null, 2)
|
|
3486
|
+
);
|
|
3487
|
+
return false;
|
|
3488
|
+
}
|
|
3489
|
+
if (parsedFilters.data.userId && parsedFilters.data.userId !== data.metadata.connectedAccount.userId) {
|
|
3490
|
+
logger_default.debug(
|
|
3491
|
+
"Trigger does not match userId filter",
|
|
3492
|
+
JSON.stringify(parsedFilters.data.userId, null, 2)
|
|
3493
|
+
);
|
|
3494
|
+
return false;
|
|
3495
|
+
}
|
|
3496
|
+
logger_default.debug("Trigger matches all filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
3497
|
+
return true;
|
|
2661
3498
|
};
|
|
2662
|
-
logger_default.debug("Subscribing to triggers", filters);
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
3499
|
+
logger_default.debug("\u{1F504} Subscribing to triggers with filters: ", JSON.stringify(filters, null, 2));
|
|
3500
|
+
await this.pusherService.subscribe((_data) => {
|
|
3501
|
+
logger_default.debug("Received raw trigger data", JSON.stringify(_data, null, 2));
|
|
3502
|
+
const data = _data;
|
|
3503
|
+
const parsedData = IncomingTriggerPayloadSchema.safeParse({
|
|
3504
|
+
id: data.metadata.id,
|
|
3505
|
+
triggerSlug: data.metadata.triggerName,
|
|
3506
|
+
toolkitSlug: data.appName,
|
|
3507
|
+
userId: data.metadata.connection?.clientUniqueUserId,
|
|
3508
|
+
payload: data.payload,
|
|
3509
|
+
originalPayload: data.originalPayload,
|
|
3510
|
+
metadata: {
|
|
3511
|
+
id: data.metadata.id,
|
|
3512
|
+
triggerConfig: data.metadata.triggerConfig,
|
|
3513
|
+
triggerSlug: data.metadata.triggerName,
|
|
3514
|
+
toolkitSlug: data.appName,
|
|
3515
|
+
triggerData: data.metadata.triggerData,
|
|
3516
|
+
connectedAccount: {
|
|
3517
|
+
id: data.metadata.connection?.connectedAccountNanoId,
|
|
3518
|
+
uuid: data.metadata.connection?.id,
|
|
3519
|
+
authConfigId: data.metadata.connection?.authConfigNanoId,
|
|
3520
|
+
authConfigUUID: data.metadata.connection?.integrationId,
|
|
3521
|
+
userId: data.metadata.connection?.clientUniqueUserId,
|
|
3522
|
+
status: data.metadata.connection?.status
|
|
3523
|
+
}
|
|
3524
|
+
}
|
|
3525
|
+
});
|
|
3526
|
+
logger_default.debug("Parsed trigger data", JSON.stringify(parsedData.data, null, 2));
|
|
3527
|
+
if (parsedData.error) {
|
|
3528
|
+
throw new ValidationError(`Invalid trigger payload`, {
|
|
3529
|
+
cause: parsedData.error
|
|
3530
|
+
});
|
|
3531
|
+
}
|
|
3532
|
+
if (shouldSendTriggerAfterFilters(parsedData.data)) {
|
|
3533
|
+
try {
|
|
3534
|
+
fn(parsedData.data);
|
|
3535
|
+
} catch (error) {
|
|
3536
|
+
logger_default.error("\u274C Error in trigger callback:", error);
|
|
3537
|
+
}
|
|
3538
|
+
} else {
|
|
3539
|
+
logger_default.debug("Trigger does not match filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
2666
3540
|
}
|
|
2667
3541
|
});
|
|
2668
3542
|
}
|
|
3543
|
+
/**
|
|
3544
|
+
* Unsubscribe from all the triggers
|
|
3545
|
+
*
|
|
3546
|
+
* @returns {Promise<void>}
|
|
3547
|
+
*
|
|
3548
|
+
* @example
|
|
3549
|
+
* ```ts
|
|
3550
|
+
* composio.trigger.subscribe((data) => {
|
|
3551
|
+
* console.log(data);
|
|
3552
|
+
* });
|
|
3553
|
+
*
|
|
3554
|
+
* await triggers.unsubscribe();
|
|
3555
|
+
* ```
|
|
3556
|
+
*/
|
|
2669
3557
|
async unsubscribe() {
|
|
2670
|
-
|
|
2671
|
-
const sessionInfo = await session.getInfo();
|
|
2672
|
-
const clientId = sessionInfo.project?.id;
|
|
2673
|
-
if (!clientId) throw new Error("Client ID not found");
|
|
2674
|
-
PusherUtils.triggerUnsubscribe(clientId);
|
|
3558
|
+
await this.pusherService.unsubscribe();
|
|
2675
3559
|
}
|
|
2676
3560
|
};
|
|
2677
3561
|
|
|
@@ -2682,6 +3566,7 @@ var userDataPath = () => {
|
|
|
2682
3566
|
const os = require("os");
|
|
2683
3567
|
return path.join(os.homedir(), COMPOSIO_DIR, USER_DATA_FILE_NAME);
|
|
2684
3568
|
} catch (_error) {
|
|
3569
|
+
logger_default.debug("Environment", `Unable to get user data path`);
|
|
2685
3570
|
return null;
|
|
2686
3571
|
}
|
|
2687
3572
|
};
|
|
@@ -2691,6 +3576,7 @@ var getUserDataJson = () => {
|
|
|
2691
3576
|
const data = fs.readFileSync(userDataPath(), "utf8");
|
|
2692
3577
|
return JSON.parse(data);
|
|
2693
3578
|
} catch (_error) {
|
|
3579
|
+
logger_default.debug("Environment", "No user data file found");
|
|
2694
3580
|
return {};
|
|
2695
3581
|
}
|
|
2696
3582
|
};
|
|
@@ -2699,6 +3585,13 @@ function getSDKConfig(baseUrl, apiKey) {
|
|
|
2699
3585
|
const { api_key: apiKeyFromUserConfig, base_url: baseURLFromUserConfig } = userData;
|
|
2700
3586
|
const baseURLParsed = baseUrl || getEnvVariable("COMPOSIO_BASE_URL") || baseURLFromUserConfig || DEFAULT_BASE_URL;
|
|
2701
3587
|
const apiKeyParsed = apiKey || getEnvVariable("COMPOSIO_API_KEY") || apiKeyFromUserConfig || "";
|
|
3588
|
+
if (!apiKeyParsed) {
|
|
3589
|
+
ComposioError.handle(new ComposioNoAPIKeyError(), {
|
|
3590
|
+
exitProcess: true
|
|
3591
|
+
});
|
|
3592
|
+
}
|
|
3593
|
+
logger_default.debug("Environment", `API Key: ${apiKeyParsed}`);
|
|
3594
|
+
logger_default.debug("Environment", `Base URL: ${baseURLParsed}`);
|
|
2702
3595
|
return { baseURL: baseURLParsed, apiKey: apiKeyParsed };
|
|
2703
3596
|
}
|
|
2704
3597
|
|
|
@@ -2745,7 +3638,7 @@ var BaseProvider = class {
|
|
|
2745
3638
|
}
|
|
2746
3639
|
/**
|
|
2747
3640
|
* @public
|
|
2748
|
-
*
|
|
3641
|
+
* Global function to execute a tool.
|
|
2749
3642
|
* This function is used by provider providers to implement helper functions to execute tools.
|
|
2750
3643
|
* This is a 1:1 mapping of the `execute` method in the `Tools` class.
|
|
2751
3644
|
* @param {string} toolSlug - The slug of the tool to execute.
|
|
@@ -2812,7 +3705,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2812
3705
|
* @param {string} userId - The user id.
|
|
2813
3706
|
* @returns {Promise<string[]>} The results of the tool call.
|
|
2814
3707
|
*/
|
|
2815
|
-
async
|
|
3708
|
+
async handleToolCalls(userId, chatCompletion, options, modifiers) {
|
|
2816
3709
|
const outputs = [];
|
|
2817
3710
|
for (const message of chatCompletion.choices) {
|
|
2818
3711
|
if (message.message.tool_calls) {
|
|
@@ -2932,13 +3825,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2932
3825
|
};
|
|
2933
3826
|
|
|
2934
3827
|
// package.json
|
|
2935
|
-
var version = "0.1.12-alpha.
|
|
2936
|
-
|
|
2937
|
-
// src/utils/uuid.ts
|
|
2938
|
-
var import_uuid = require("uuid");
|
|
2939
|
-
function getRandomUUID() {
|
|
2940
|
-
return (0, import_uuid.v4)();
|
|
2941
|
-
}
|
|
3828
|
+
var version = "0.1.12-alpha.12";
|
|
2942
3829
|
|
|
2943
3830
|
// src/composio.ts
|
|
2944
3831
|
var Composio = class {
|
|
@@ -2978,18 +3865,18 @@ var Composio = class {
|
|
|
2978
3865
|
config?.apiKey
|
|
2979
3866
|
);
|
|
2980
3867
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
2981
|
-
logger_default.
|
|
3868
|
+
logger_default.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
2982
3869
|
}
|
|
2983
|
-
this.client = new
|
|
3870
|
+
this.client = new import_client6.default({
|
|
2984
3871
|
apiKey: apiKeyParsed,
|
|
2985
3872
|
baseURL: baseURLParsed
|
|
2986
3873
|
});
|
|
2987
3874
|
this.config = {
|
|
2988
3875
|
...config,
|
|
2989
|
-
allowTracking: config
|
|
2990
|
-
allowTracing: config
|
|
3876
|
+
allowTracking: config?.allowTracking ?? true,
|
|
3877
|
+
allowTracing: config?.allowTracing ?? true
|
|
2991
3878
|
};
|
|
2992
|
-
this.provider = config
|
|
3879
|
+
this.provider = config?.provider ?? new OpenAIProvider();
|
|
2993
3880
|
this.tools = new Tools(this.client, this.provider);
|
|
2994
3881
|
this.toolkits = new Toolkits(this.client);
|
|
2995
3882
|
this.triggers = new Triggers(this.client);
|
|
@@ -3000,7 +3887,7 @@ var Composio = class {
|
|
|
3000
3887
|
{
|
|
3001
3888
|
apiKey: apiKeyParsed ?? "",
|
|
3002
3889
|
baseUrl: baseURLParsed ?? "",
|
|
3003
|
-
|
|
3890
|
+
frameworkRuntime: this.provider?.name ?? "unknown",
|
|
3004
3891
|
isAgentic: this.provider?._isAgentic || false,
|
|
3005
3892
|
source: "javascript",
|
|
3006
3893
|
version,
|
|
@@ -3011,7 +3898,7 @@ var Composio = class {
|
|
|
3011
3898
|
sessionId: this.config.allowTracing ? getRandomUUID() : void 0
|
|
3012
3899
|
// @TODO: get the session id
|
|
3013
3900
|
},
|
|
3014
|
-
config
|
|
3901
|
+
config?.telemetryTransport
|
|
3015
3902
|
);
|
|
3016
3903
|
}
|
|
3017
3904
|
telemetry.instrument(this);
|
|
@@ -3042,50 +3929,50 @@ var ComposioProvider = class extends BaseNonAgenticProvider {
|
|
|
3042
3929
|
};
|
|
3043
3930
|
|
|
3044
3931
|
// src/telemetry/TelemetryTransport.ts
|
|
3045
|
-
var
|
|
3932
|
+
var import_chalk4 = __toESM(require("chalk"), 1);
|
|
3046
3933
|
var BaseTelemetryTransport = class {
|
|
3047
3934
|
};
|
|
3048
3935
|
var ConsoleTelemetryTransport = class {
|
|
3049
3936
|
send(payload) {
|
|
3050
|
-
logger_default.debug(
|
|
3937
|
+
logger_default.debug(import_chalk4.default.yellow("telemetry"), JSON.stringify(payload, null, 2));
|
|
3051
3938
|
return Promise.resolve();
|
|
3052
3939
|
}
|
|
3053
3940
|
};
|
|
3054
3941
|
|
|
3055
3942
|
// src/utils/jsonSchema.ts
|
|
3056
|
-
var
|
|
3943
|
+
var import_zod10 = require("zod");
|
|
3057
3944
|
function jsonSchemaPropertiesToTSTypes(value) {
|
|
3058
3945
|
if (!value.type) {
|
|
3059
|
-
return
|
|
3946
|
+
return import_zod10.z.object({});
|
|
3060
3947
|
}
|
|
3061
3948
|
let zodType;
|
|
3062
3949
|
switch (value.type) {
|
|
3063
3950
|
case "string":
|
|
3064
|
-
zodType =
|
|
3951
|
+
zodType = import_zod10.z.string().describe(
|
|
3065
3952
|
(value.description || "") + (value.examples ? `
|
|
3066
3953
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3067
3954
|
);
|
|
3068
3955
|
break;
|
|
3069
3956
|
case "number":
|
|
3070
|
-
zodType =
|
|
3957
|
+
zodType = import_zod10.z.number().describe(
|
|
3071
3958
|
(value.description || "") + (value.examples ? `
|
|
3072
3959
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3073
3960
|
);
|
|
3074
3961
|
break;
|
|
3075
3962
|
case "integer":
|
|
3076
|
-
zodType =
|
|
3963
|
+
zodType = import_zod10.z.number().int().describe(
|
|
3077
3964
|
(value.description || "") + (value.examples ? `
|
|
3078
3965
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3079
3966
|
);
|
|
3080
3967
|
break;
|
|
3081
3968
|
case "boolean":
|
|
3082
|
-
zodType =
|
|
3969
|
+
zodType = import_zod10.z.boolean().describe(
|
|
3083
3970
|
(value.description || "") + (value.examples ? `
|
|
3084
3971
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3085
3972
|
);
|
|
3086
3973
|
break;
|
|
3087
3974
|
case "array":
|
|
3088
|
-
zodType =
|
|
3975
|
+
zodType = import_zod10.z.array(
|
|
3089
3976
|
jsonSchemaPropertiesToTSTypes(
|
|
3090
3977
|
value.items
|
|
3091
3978
|
)
|
|
@@ -3095,24 +3982,24 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3095
3982
|
);
|
|
3096
3983
|
break;
|
|
3097
3984
|
case "object":
|
|
3098
|
-
zodType =
|
|
3985
|
+
zodType = jsonSchemaToZodSchema(value).describe(
|
|
3099
3986
|
(value.description || "") + (value.examples ? `
|
|
3100
3987
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3101
3988
|
);
|
|
3102
3989
|
break;
|
|
3103
3990
|
case "null":
|
|
3104
|
-
zodType =
|
|
3991
|
+
zodType = import_zod10.z.null().describe(value.description || "");
|
|
3105
3992
|
break;
|
|
3106
3993
|
default:
|
|
3107
3994
|
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
3108
3995
|
}
|
|
3109
3996
|
return zodType;
|
|
3110
3997
|
}
|
|
3111
|
-
function
|
|
3998
|
+
function jsonSchemaToZodSchema(jsonSchema) {
|
|
3112
3999
|
const properties = jsonSchema.properties;
|
|
3113
4000
|
const requiredFields = jsonSchema.required || [];
|
|
3114
4001
|
if (!properties) {
|
|
3115
|
-
return
|
|
4002
|
+
return import_zod10.z.object({});
|
|
3116
4003
|
}
|
|
3117
4004
|
const zodSchema = {};
|
|
3118
4005
|
for (const [key, _] of Object.entries(properties)) {
|
|
@@ -3124,7 +4011,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
3124
4011
|
schema
|
|
3125
4012
|
)
|
|
3126
4013
|
);
|
|
3127
|
-
zodType =
|
|
4014
|
+
zodType = import_zod10.z.union(anyOfTypes).describe(
|
|
3128
4015
|
(value.description || "") + (value.examples ? `
|
|
3129
4016
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3130
4017
|
);
|
|
@@ -3134,7 +4021,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3134
4021
|
schema
|
|
3135
4022
|
)
|
|
3136
4023
|
);
|
|
3137
|
-
zodType =
|
|
4024
|
+
zodType = import_zod10.z.intersection(
|
|
3138
4025
|
allOfTypes[0],
|
|
3139
4026
|
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
3140
4027
|
).describe(
|
|
@@ -3158,19 +4045,43 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3158
4045
|
zodSchema[key] = zodType.optional();
|
|
3159
4046
|
}
|
|
3160
4047
|
}
|
|
3161
|
-
return
|
|
4048
|
+
return import_zod10.z.object(zodSchema);
|
|
3162
4049
|
}
|
|
3163
4050
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3164
4051
|
0 && (module.exports = {
|
|
4052
|
+
AuthConfigErrorCodes,
|
|
3165
4053
|
AuthConfigTypes,
|
|
3166
4054
|
AuthSchemeTypes,
|
|
3167
4055
|
BaseAgenticProvider,
|
|
3168
4056
|
BaseNonAgenticProvider,
|
|
3169
4057
|
BaseTelemetryTransport,
|
|
3170
4058
|
Composio,
|
|
4059
|
+
ComposioAuthConfigNotFoundError,
|
|
4060
|
+
ComposioConnectedAccountNotFoundError,
|
|
4061
|
+
ComposioCustomToolsNotInitializedError,
|
|
4062
|
+
ComposioError,
|
|
4063
|
+
ComposioGlobalExecuteToolFnNotSetError,
|
|
4064
|
+
ComposioInvalidExecuteFunctionError,
|
|
4065
|
+
ComposioInvalidModifierError,
|
|
4066
|
+
ComposioNoAPIKeyError,
|
|
3171
4067
|
ComposioProvider,
|
|
4068
|
+
ComposioProviderNotDefinedError,
|
|
4069
|
+
ComposioToolExecutionError,
|
|
4070
|
+
ComposioToolNotFoundError,
|
|
4071
|
+
ComposioToolkitFetchError,
|
|
4072
|
+
ComposioToolkitNotFoundError,
|
|
4073
|
+
ConnectedAccountErrorCodes,
|
|
4074
|
+
ConnectionRequestErrorCodes,
|
|
4075
|
+
ConnectionRequestFailedError,
|
|
4076
|
+
ConnectionRequestTimeoutError,
|
|
3172
4077
|
ConsoleTelemetryTransport,
|
|
3173
4078
|
OpenAIProvider,
|
|
4079
|
+
SDKErrorCodes,
|
|
4080
|
+
ToolErrorCodes,
|
|
3174
4081
|
ToolListParamsSchema,
|
|
3175
|
-
|
|
4082
|
+
ToolkitErrorCodes,
|
|
4083
|
+
ValidationError,
|
|
4084
|
+
ValidationErrorCodes,
|
|
4085
|
+
jsonSchemaToZodSchema,
|
|
4086
|
+
logger
|
|
3176
4087
|
});
|