@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.js
CHANGED
|
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/composio.ts
|
|
9
|
-
import
|
|
9
|
+
import ComposioClient3 from "@composio/client";
|
|
10
10
|
|
|
11
11
|
// src/types/tool.types.ts
|
|
12
12
|
import { z } from "zod";
|
|
@@ -15,12 +15,38 @@ var ToolkitSchema = z.object({
|
|
|
15
15
|
name: z.string().describe("The name of the toolkit"),
|
|
16
16
|
logo: z.string().describe("The logo of the toolkit").optional()
|
|
17
17
|
});
|
|
18
|
+
var JSONSchemaType = z.enum([
|
|
19
|
+
"string",
|
|
20
|
+
"number",
|
|
21
|
+
"integer",
|
|
22
|
+
"boolean",
|
|
23
|
+
"object",
|
|
24
|
+
"array",
|
|
25
|
+
"null"
|
|
26
|
+
]);
|
|
27
|
+
var JSONSchemaProperty = z.object({
|
|
28
|
+
type: JSONSchemaType.optional(),
|
|
29
|
+
description: z.string().optional(),
|
|
30
|
+
title: z.string().optional(),
|
|
31
|
+
default: z.any().optional(),
|
|
32
|
+
properties: z.lazy(() => z.record(z.string(), JSONSchemaProperty)).optional(),
|
|
33
|
+
required: z.array(z.string()).optional(),
|
|
34
|
+
items: z.lazy(() => JSONSchemaProperty).optional()
|
|
35
|
+
});
|
|
36
|
+
var ParametersSchema = z.object({
|
|
37
|
+
type: z.literal("object"),
|
|
38
|
+
properties: z.record(z.string(), JSONSchemaProperty),
|
|
39
|
+
required: z.array(z.string()).optional(),
|
|
40
|
+
title: z.string().optional(),
|
|
41
|
+
description: z.string().optional(),
|
|
42
|
+
additionalProperties: z.boolean().optional()
|
|
43
|
+
});
|
|
18
44
|
var ToolSchema = z.object({
|
|
19
45
|
slug: z.string().describe('The slug of the tool. eg. "GOOGLE_SEARCH"'),
|
|
20
46
|
name: z.string().describe(`The name of the tool. eg. "Google Search"`),
|
|
21
47
|
description: z.string().optional().describe("The description of the tool"),
|
|
22
|
-
inputParameters:
|
|
23
|
-
outputParameters:
|
|
48
|
+
inputParameters: ParametersSchema.optional().describe("The input parameters of the tool"),
|
|
49
|
+
outputParameters: ParametersSchema.optional().describe("The output parameters of the tool"),
|
|
24
50
|
tags: z.optional(z.array(z.string())).describe("The tags of the tool. eg: Important").default([]),
|
|
25
51
|
toolkit: z.optional(ToolkitSchema).describe("The toolkit of the tool"),
|
|
26
52
|
version: z.optional(z.string()).describe('The version of the tool, e.g. "1.0.0"')
|
|
@@ -33,8 +59,8 @@ var ToolListResponseSchema = z.object({
|
|
|
33
59
|
var ToolListParamsSchema = z.object({
|
|
34
60
|
tools: z.array(z.string()).optional(),
|
|
35
61
|
cursor: z.string().optional(),
|
|
36
|
-
important: z.
|
|
37
|
-
limit: z.
|
|
62
|
+
important: z.boolean().optional(),
|
|
63
|
+
limit: z.number().optional(),
|
|
38
64
|
search: z.string().optional(),
|
|
39
65
|
toolkits: z.array(z.string()).optional()
|
|
40
66
|
});
|
|
@@ -108,7 +134,20 @@ var Logger = class {
|
|
|
108
134
|
this.console = console;
|
|
109
135
|
}
|
|
110
136
|
formatMessage(args) {
|
|
111
|
-
const formattedArgs = args.map((arg) =>
|
|
137
|
+
const formattedArgs = args.map((arg, index) => {
|
|
138
|
+
if (typeof arg === "object") {
|
|
139
|
+
return JSON.stringify(arg);
|
|
140
|
+
} else {
|
|
141
|
+
if (index === 0) {
|
|
142
|
+
if (args.length > 1) {
|
|
143
|
+
return chalk.yellow(`${arg}`);
|
|
144
|
+
} else {
|
|
145
|
+
return String(arg);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return String(arg);
|
|
149
|
+
}
|
|
150
|
+
}).join("\n");
|
|
112
151
|
if (!this.includeTimestamp) {
|
|
113
152
|
return formattedArgs;
|
|
114
153
|
}
|
|
@@ -143,34 +182,240 @@ var logger = new Logger();
|
|
|
143
182
|
var logger_default = logger;
|
|
144
183
|
|
|
145
184
|
// src/errors/ComposioError.ts
|
|
146
|
-
|
|
185
|
+
import chalk2 from "chalk";
|
|
186
|
+
import { ZodError } from "zod";
|
|
187
|
+
import { BadRequestError } from "@composio/client";
|
|
188
|
+
var ComposioError = class _ComposioError extends Error {
|
|
189
|
+
/** @readonly Error name */
|
|
147
190
|
name = "ComposioError";
|
|
148
191
|
code;
|
|
149
|
-
statusCode;
|
|
150
|
-
cause;
|
|
151
|
-
meta;
|
|
152
192
|
possibleFixes;
|
|
193
|
+
errorId;
|
|
194
|
+
/**
|
|
195
|
+
* Creates a new ComposioError
|
|
196
|
+
* @param message Error message
|
|
197
|
+
* @param options Additional error options
|
|
198
|
+
*/
|
|
153
199
|
constructor(message, options = {}) {
|
|
154
200
|
super(message);
|
|
155
|
-
this.code = options.code;
|
|
156
|
-
this.statusCode = options.statusCode;
|
|
157
|
-
this.cause = options.cause;
|
|
158
|
-
this.meta = options.meta;
|
|
159
|
-
this.possibleFixes = options.possibleFixes;
|
|
160
201
|
if (Error.captureStackTrace) {
|
|
161
202
|
Error.captureStackTrace(this, this.constructor);
|
|
162
203
|
}
|
|
204
|
+
const statusCode = options.statusCode || (options.cause instanceof BadRequestError ? options.cause.status : void 0);
|
|
205
|
+
this.code = `TS-SDK::${options.code}`;
|
|
206
|
+
this.possibleFixes = options.possibleFixes;
|
|
207
|
+
this.definePropertyIfExists("statusCode", statusCode);
|
|
208
|
+
this.definePropertyIfExists("cause", options.cause);
|
|
209
|
+
const combinedStack = options.cause instanceof Error ? _ComposioError.combineStackTraces(options.cause.stack, this.stack) : options.stack ?? this.stack;
|
|
210
|
+
this.definePropertyIfExists("stack", combinedStack);
|
|
211
|
+
if (options.meta && Object.keys(options.meta).length > 0) {
|
|
212
|
+
this.definePropertyIfExists("meta", options.meta);
|
|
213
|
+
}
|
|
163
214
|
}
|
|
164
|
-
|
|
165
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Helper method to define a property only if it has a value
|
|
217
|
+
* @param propertyName Name of the property to define
|
|
218
|
+
* @param value Value to assign to the property
|
|
219
|
+
* @private
|
|
220
|
+
*/
|
|
221
|
+
definePropertyIfExists(propertyName, value) {
|
|
222
|
+
if (value !== void 0) {
|
|
223
|
+
Object.defineProperty(this, propertyName, {
|
|
224
|
+
value,
|
|
225
|
+
enumerable: true,
|
|
226
|
+
writable: false,
|
|
227
|
+
configurable: true
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Helper method to combine stack traces when wrapping errors
|
|
233
|
+
* This ensures the full call chain is preserved
|
|
234
|
+
* @param originalStack The stack of the error being wrapped
|
|
235
|
+
* @param currentStack The stack of the wrapper error
|
|
236
|
+
* @returns Combined stack trace
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
static combineStackTraces(originalStack, currentStack) {
|
|
240
|
+
if (!originalStack) return currentStack;
|
|
241
|
+
if (!currentStack) return originalStack;
|
|
242
|
+
const currentHeader = currentStack.split("\n")[0];
|
|
243
|
+
const originalStackBody = originalStack.split("\n").slice(1).join("\n");
|
|
244
|
+
return `${currentHeader}
|
|
245
|
+
${currentStack.split("\n").slice(1).join("\n")}
|
|
246
|
+
|
|
247
|
+
Caused by:
|
|
248
|
+
${originalStackBody}`;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Extract and normalize error data for formatting
|
|
252
|
+
* @param includeStack Whether to include stack trace information
|
|
253
|
+
* @returns Structured error data for formatting
|
|
254
|
+
* @private
|
|
255
|
+
*/
|
|
256
|
+
getErrorData(includeStack = false) {
|
|
257
|
+
const data = {
|
|
166
258
|
name: this.name,
|
|
167
|
-
message: this.message
|
|
168
|
-
code: this.code,
|
|
169
|
-
statusCode: this.statusCode,
|
|
170
|
-
cause: this.cause instanceof Error ? this.cause.message : this.cause,
|
|
171
|
-
meta: this.meta,
|
|
172
|
-
possibleFixes: this.possibleFixes?.length ? this.possibleFixes.join("\n") : void 0
|
|
259
|
+
message: this.message
|
|
173
260
|
};
|
|
261
|
+
const { cause, code, stack, statusCode, meta, possibleFixes } = this;
|
|
262
|
+
if (cause !== void 0) {
|
|
263
|
+
const rawCause = cause;
|
|
264
|
+
data.cause = rawCause instanceof Error ? rawCause.message : String(rawCause);
|
|
265
|
+
}
|
|
266
|
+
if (code) {
|
|
267
|
+
data.code = code;
|
|
268
|
+
}
|
|
269
|
+
if (statusCode !== void 0) {
|
|
270
|
+
data.statusCode = statusCode;
|
|
271
|
+
}
|
|
272
|
+
if (meta) {
|
|
273
|
+
data.meta = meta;
|
|
274
|
+
}
|
|
275
|
+
if (possibleFixes) {
|
|
276
|
+
data.possibleFixes = possibleFixes;
|
|
277
|
+
}
|
|
278
|
+
if (includeStack && stack) {
|
|
279
|
+
if (stack.includes("Caused by:")) {
|
|
280
|
+
const [currentStack, causeStack] = stack.split("Caused by:");
|
|
281
|
+
data.stack = [
|
|
282
|
+
...currentStack.split("\n").slice(1),
|
|
283
|
+
"Caused by:",
|
|
284
|
+
...causeStack.split("\n")
|
|
285
|
+
];
|
|
286
|
+
} else {
|
|
287
|
+
data.stack = stack.split("\n").slice(1);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return data;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Prints a user-friendly, colorful representation of the error to the logger
|
|
294
|
+
* @param includeStack Whether to include the stack trace in the output (default: false)
|
|
295
|
+
*/
|
|
296
|
+
prettyPrint(includeStack = false) {
|
|
297
|
+
const data = this.getErrorData(includeStack);
|
|
298
|
+
let output = "\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold(data.message) + "\n";
|
|
299
|
+
if (data.code) {
|
|
300
|
+
output += chalk2.yellow(`Error Code: ${data.code}`) + "\n";
|
|
301
|
+
}
|
|
302
|
+
if (data.statusCode !== void 0) {
|
|
303
|
+
output += chalk2.yellow(`Status: ${data.statusCode}`) + "\n";
|
|
304
|
+
}
|
|
305
|
+
if (data.cause) {
|
|
306
|
+
output += chalk2.gray("Reason:") + "\n";
|
|
307
|
+
output += " " + chalk2.white(data.cause) + "\n";
|
|
308
|
+
}
|
|
309
|
+
if (data.meta) {
|
|
310
|
+
output += chalk2.gray("Additional Information:") + "\n";
|
|
311
|
+
output += " " + chalk2.white(JSON.stringify(data.meta, null, 2).replace(/\n/g, "\n ")) + "\n";
|
|
312
|
+
}
|
|
313
|
+
if (data.possibleFixes?.length) {
|
|
314
|
+
output += "\n" + chalk2.cyan.bold("Try the following:") + "\n";
|
|
315
|
+
const fixes = data.possibleFixes?.map((fix, index) => ` ${index + 1}. ` + chalk2.white(fix));
|
|
316
|
+
output += fixes?.join("\n") + "\n";
|
|
317
|
+
}
|
|
318
|
+
if (data.stack?.length) {
|
|
319
|
+
output += "\n" + chalk2.gray("Stack Trace:") + "\n";
|
|
320
|
+
output += chalk2.gray(data.stack.join("\n")) + "\n";
|
|
321
|
+
}
|
|
322
|
+
output += "\n";
|
|
323
|
+
logger_default.error(output);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Static factory method to create and pretty print an error in one step
|
|
327
|
+
* @param message Error message
|
|
328
|
+
* @param options Error options
|
|
329
|
+
* @param includeStack Whether to include the stack trace in the output
|
|
330
|
+
* @returns The created error instance
|
|
331
|
+
*/
|
|
332
|
+
static createAndPrint(message, options = {}, includeStack = false) {
|
|
333
|
+
const error = new _ComposioError(message, options);
|
|
334
|
+
error.prettyPrint(includeStack);
|
|
335
|
+
return error;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Utility function to handle errors in a consistent way
|
|
339
|
+
* This properly displays the error and exits the process if needed
|
|
340
|
+
* @param error The error to handle
|
|
341
|
+
* @param options Options for error handling
|
|
342
|
+
*/
|
|
343
|
+
static handle(error, options = {}) {
|
|
344
|
+
const { includeStack = false, exitProcess = false, exitCode = 1 } = options;
|
|
345
|
+
if (error instanceof _ComposioError) {
|
|
346
|
+
error.prettyPrint(includeStack);
|
|
347
|
+
} else if (error instanceof ZodError) {
|
|
348
|
+
this.handleZodError(error, includeStack);
|
|
349
|
+
} else if (error instanceof Error) {
|
|
350
|
+
this.handleStandardError(error, includeStack);
|
|
351
|
+
} else {
|
|
352
|
+
this.handleUnknownError(error);
|
|
353
|
+
}
|
|
354
|
+
if (exitProcess && typeof process !== "undefined") {
|
|
355
|
+
process.exit(exitCode);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Helper method to handle Zod validation errors
|
|
360
|
+
* @param error The Zod error to handle
|
|
361
|
+
* @param includeStack Whether to include the stack trace
|
|
362
|
+
* @private
|
|
363
|
+
*/
|
|
364
|
+
static handleZodError(error, includeStack) {
|
|
365
|
+
logger_default.error("\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold(error.message));
|
|
366
|
+
logger_default.error(chalk2.gray("Invalid parameters:"));
|
|
367
|
+
error.errors.forEach((err) => {
|
|
368
|
+
logger_default.error(chalk2.yellow(err.path.join(".")) + " " + chalk2.white(err.message));
|
|
369
|
+
});
|
|
370
|
+
logger_default.error(chalk2.gray("Expected parameters:"));
|
|
371
|
+
error.errors.forEach((err) => {
|
|
372
|
+
logger_default.error(chalk2.yellow(err.path.join(".")) + " " + chalk2.white(err.message));
|
|
373
|
+
});
|
|
374
|
+
if (includeStack) {
|
|
375
|
+
logger_default.error("\n" + chalk2.gray("Validation Errors:"));
|
|
376
|
+
error.errors.forEach((err) => {
|
|
377
|
+
const path = err.path.join(".");
|
|
378
|
+
logger_default.error(
|
|
379
|
+
chalk2.gray(" \u2022 ") + chalk2.yellow(path ? `${path}: ` : "") + chalk2.white(err.message)
|
|
380
|
+
);
|
|
381
|
+
});
|
|
382
|
+
if (error.stack) {
|
|
383
|
+
logger_default.error("\n" + chalk2.gray("Stack Trace:"));
|
|
384
|
+
const stackLines = error.stack.split("\n").slice(1);
|
|
385
|
+
logger_default.error(chalk2.gray(stackLines.join("\n")));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
logger_default.error("");
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Helper method to handle standard Error objects
|
|
392
|
+
* @param error The standard error to handle
|
|
393
|
+
* @param includeStack Whether to include the stack trace
|
|
394
|
+
* @private
|
|
395
|
+
*/
|
|
396
|
+
static handleStandardError(error, includeStack) {
|
|
397
|
+
logger_default.error("\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold(error.message));
|
|
398
|
+
if (includeStack && error.stack) {
|
|
399
|
+
logger_default.error("\n" + chalk2.gray("Stack Trace:"));
|
|
400
|
+
const stackLines = error.stack.split("\n").slice(1);
|
|
401
|
+
logger_default.error(chalk2.gray(stackLines.join("\n")));
|
|
402
|
+
}
|
|
403
|
+
logger_default.error("");
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Helper method to handle unknown error types
|
|
407
|
+
* @param error The unknown error value
|
|
408
|
+
* @private
|
|
409
|
+
*/
|
|
410
|
+
static handleUnknownError(error) {
|
|
411
|
+
logger_default.error(
|
|
412
|
+
"\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold("Unknown error occurred")
|
|
413
|
+
);
|
|
414
|
+
if (error !== null && error !== void 0) {
|
|
415
|
+
logger_default.error(chalk2.gray("Error details:"));
|
|
416
|
+
logger_default.error(" " + chalk2.white(String(error)));
|
|
417
|
+
}
|
|
418
|
+
logger_default.error("");
|
|
174
419
|
}
|
|
175
420
|
};
|
|
176
421
|
|
|
@@ -185,11 +430,11 @@ var ToolErrorCodes = {
|
|
|
185
430
|
GLOBAL_EXECUTE_TOOL_FN_NOT_SET: "GLOBAL_EXECUTE_TOOL_FN_NOT_SET"
|
|
186
431
|
};
|
|
187
432
|
var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
188
|
-
constructor(message = "Provider not defined",
|
|
433
|
+
constructor(message = "Provider not defined", options = {}) {
|
|
189
434
|
super(message, {
|
|
435
|
+
...options,
|
|
190
436
|
code: ToolErrorCodes.TOOLSET_NOT_DEFINED,
|
|
191
|
-
|
|
192
|
-
possibleFixes: [
|
|
437
|
+
possibleFixes: options.possibleFixes || [
|
|
193
438
|
"Ensure that the provider is defined in the Composio project and passed into the tool instance"
|
|
194
439
|
]
|
|
195
440
|
});
|
|
@@ -197,86 +442,103 @@ var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
|
197
442
|
}
|
|
198
443
|
};
|
|
199
444
|
var ComposioToolNotFoundError = class extends ComposioError {
|
|
200
|
-
constructor(message = "Tool not found",
|
|
445
|
+
constructor(message = "Tool not found", options = {}) {
|
|
201
446
|
super(message, {
|
|
447
|
+
...options,
|
|
202
448
|
code: ToolErrorCodes.TOOL_NOT_FOUND,
|
|
203
|
-
|
|
204
|
-
|
|
449
|
+
possibleFixes: options.possibleFixes || [
|
|
450
|
+
"Ensure the tool slug is correct and exists in the Composio project"
|
|
451
|
+
]
|
|
205
452
|
});
|
|
206
453
|
this.name = "ComposioToolNotFoundError";
|
|
207
454
|
}
|
|
208
455
|
};
|
|
209
456
|
var ComposioInvalidModifierError = class extends ComposioError {
|
|
210
|
-
constructor(message = "Invalid modifier",
|
|
457
|
+
constructor(message = "Invalid modifier", options = {}) {
|
|
211
458
|
super(message, {
|
|
459
|
+
...options,
|
|
212
460
|
code: ToolErrorCodes.INVALID_MODIFIER,
|
|
213
|
-
|
|
214
|
-
|
|
461
|
+
possibleFixes: options.possibleFixes || [
|
|
462
|
+
"Ensure the modifier is a function and returns a valid result"
|
|
463
|
+
]
|
|
215
464
|
});
|
|
216
465
|
this.name = "ComposioInvalidModifierError";
|
|
217
466
|
}
|
|
218
467
|
};
|
|
219
468
|
var ComposioCustomToolsNotInitializedError = class extends ComposioError {
|
|
220
|
-
constructor(message = "Custom tools not initialized",
|
|
469
|
+
constructor(message = "Custom tools not initialized", options = {}) {
|
|
221
470
|
super(message, {
|
|
471
|
+
...options,
|
|
222
472
|
code: ToolErrorCodes.CUSTOM_TOOLS_NOT_INITIALIZED,
|
|
223
|
-
|
|
224
|
-
|
|
473
|
+
possibleFixes: options.possibleFixes || [
|
|
474
|
+
"Ensure the custom tools class is initialized in the Tools instance"
|
|
475
|
+
]
|
|
225
476
|
});
|
|
226
477
|
this.name = "ComposioCustomToolsNotInitializedError";
|
|
227
478
|
}
|
|
228
479
|
};
|
|
229
480
|
var ComposioToolExecutionError = class extends ComposioError {
|
|
230
481
|
error;
|
|
231
|
-
constructor(
|
|
482
|
+
constructor(message = "Tool execution error", options = {}) {
|
|
483
|
+
const { originalError, ...restOptions } = options;
|
|
232
484
|
super(message, {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
possibleFixes:
|
|
485
|
+
...restOptions,
|
|
486
|
+
code: options.code || ToolErrorCodes.TOOL_EXECUTION_ERROR,
|
|
487
|
+
cause: options.cause || originalError,
|
|
488
|
+
possibleFixes: options.possibleFixes || [
|
|
489
|
+
"Ensure the tool is correctly configured and the input is valid"
|
|
490
|
+
]
|
|
237
491
|
});
|
|
238
|
-
this.error = error;
|
|
492
|
+
this.error = originalError || (options.cause instanceof Error ? options.cause : options.cause ? new Error(String(options.cause)) : new Error("Unknown error"));
|
|
239
493
|
this.name = "ComposioToolExecutionError";
|
|
240
494
|
}
|
|
241
495
|
};
|
|
242
496
|
var ComposioInvalidExecuteFunctionError = class extends ComposioError {
|
|
243
|
-
constructor(message = "Invalid execute function",
|
|
497
|
+
constructor(message = "Invalid execute function", options = {}) {
|
|
244
498
|
super(message, {
|
|
499
|
+
...options,
|
|
245
500
|
code: ToolErrorCodes.INVALID_EXECUTE_FUNCTION,
|
|
246
|
-
|
|
247
|
-
|
|
501
|
+
possibleFixes: options.possibleFixes || [
|
|
502
|
+
"Ensure the execute function is a valid function and returns a valid result"
|
|
503
|
+
]
|
|
248
504
|
});
|
|
249
505
|
this.name = "ComposioInvalidExecuteFunctionError";
|
|
250
506
|
}
|
|
251
507
|
};
|
|
252
508
|
var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
|
|
253
|
-
constructor(message = "Global execute tool function not set",
|
|
509
|
+
constructor(message = "Global execute tool function not set", options = {}) {
|
|
254
510
|
super(message, {
|
|
511
|
+
...options,
|
|
255
512
|
code: ToolErrorCodes.GLOBAL_EXECUTE_TOOL_FN_NOT_SET,
|
|
256
|
-
|
|
257
|
-
|
|
513
|
+
possibleFixes: options.possibleFixes || [
|
|
514
|
+
"Ensure the global execute tool function is set in the provider"
|
|
515
|
+
]
|
|
258
516
|
});
|
|
259
517
|
this.name = "ComposioGlobalExecuteToolFnNotSetError";
|
|
260
518
|
}
|
|
261
519
|
};
|
|
262
520
|
|
|
263
|
-
// src/errors/
|
|
521
|
+
// src/errors/ConnectedAccountsErrors.ts
|
|
264
522
|
var ConnectedAccountErrorCodes = {
|
|
265
523
|
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
|
|
266
524
|
};
|
|
267
525
|
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
268
|
-
constructor(message = "Connected account not found",
|
|
526
|
+
constructor(message = "Connected account not found", options = {}) {
|
|
269
527
|
super(message, {
|
|
528
|
+
...options,
|
|
270
529
|
code: ConnectedAccountErrorCodes.CONNECTED_ACCOUNT_NOT_FOUND,
|
|
271
530
|
statusCode: 404,
|
|
272
|
-
|
|
273
|
-
possibleFixes: [
|
|
531
|
+
possibleFixes: options.possibleFixes || [
|
|
274
532
|
"Ensure the connected account exists and is active in your Composio dashboard"
|
|
275
533
|
]
|
|
276
534
|
});
|
|
535
|
+
this.name = "ComposioConnectedAccountNotFoundError";
|
|
277
536
|
}
|
|
278
537
|
};
|
|
279
538
|
|
|
539
|
+
// src/telemetry/Telemetry.ts
|
|
540
|
+
import { ComposioError as ComposioClientError } from "@composio/client";
|
|
541
|
+
|
|
280
542
|
// src/types/telemetry.types.ts
|
|
281
543
|
var TELEMETRY_EVENTS = {
|
|
282
544
|
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
@@ -354,7 +616,7 @@ var BrowserTelemetryTransport = class {
|
|
|
354
616
|
};
|
|
355
617
|
|
|
356
618
|
// src/telemetry/transports/ProcessTransport.ts
|
|
357
|
-
import
|
|
619
|
+
import chalk3 from "chalk";
|
|
358
620
|
var ProcessTelemetryTransport = class {
|
|
359
621
|
send(payload) {
|
|
360
622
|
if (typeof window !== "undefined") {
|
|
@@ -397,14 +659,15 @@ var ProcessTelemetryTransport = class {
|
|
|
397
659
|
import("child_process").then(({ spawn }) => {
|
|
398
660
|
spawn("node", args, {
|
|
399
661
|
stdio: "ignore",
|
|
400
|
-
detached:
|
|
662
|
+
detached: false,
|
|
401
663
|
shell: false
|
|
402
664
|
}).unref();
|
|
403
665
|
resolve();
|
|
404
|
-
}).catch(() => {
|
|
666
|
+
}).catch((error) => {
|
|
667
|
+
logger_default.error("Error sending telemetry", error);
|
|
405
668
|
resolve();
|
|
406
669
|
});
|
|
407
|
-
logger_default.debug(
|
|
670
|
+
logger_default.debug(chalk3.yellow("Process Telemetry"), JSON.stringify(payload, null, 2));
|
|
408
671
|
} catch (error) {
|
|
409
672
|
logger_default.error("Error sending telemetry", error);
|
|
410
673
|
resolve();
|
|
@@ -413,6 +676,12 @@ var ProcessTelemetryTransport = class {
|
|
|
413
676
|
}
|
|
414
677
|
};
|
|
415
678
|
|
|
679
|
+
// src/utils/uuid.ts
|
|
680
|
+
import { v4 as uuidv4 } from "uuid";
|
|
681
|
+
function getRandomUUID() {
|
|
682
|
+
return uuidv4();
|
|
683
|
+
}
|
|
684
|
+
|
|
416
685
|
// src/telemetry/Telemetry.ts
|
|
417
686
|
var TelemetryService = class {
|
|
418
687
|
telemetryMetadata;
|
|
@@ -437,8 +706,7 @@ var TelemetryService = class {
|
|
|
437
706
|
this.sendTelemetry([
|
|
438
707
|
{
|
|
439
708
|
eventName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
440
|
-
data: {}
|
|
441
|
-
sdk_meta: this.telemetryMetadata
|
|
709
|
+
data: {}
|
|
442
710
|
}
|
|
443
711
|
]);
|
|
444
712
|
}
|
|
@@ -457,7 +725,7 @@ var TelemetryService = class {
|
|
|
457
725
|
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
458
726
|
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
459
727
|
});
|
|
460
|
-
const instrumentedClassName = instance.constructor?.name || fileName
|
|
728
|
+
const instrumentedClassName = (instance.constructor?.name || fileName) ?? "unknown";
|
|
461
729
|
for (const name of methodNames) {
|
|
462
730
|
const originalMethod = instance[name];
|
|
463
731
|
instance[name] = async (...args) => {
|
|
@@ -467,24 +735,18 @@ var TelemetryService = class {
|
|
|
467
735
|
fileName: instrumentedClassName,
|
|
468
736
|
method: name,
|
|
469
737
|
params: args
|
|
470
|
-
}
|
|
471
|
-
sdk_meta: this.telemetryMetadata
|
|
738
|
+
}
|
|
472
739
|
};
|
|
473
740
|
this.batchProcessor.pushItem(telemetryPayload);
|
|
474
741
|
try {
|
|
475
742
|
return await originalMethod.apply(instance, args);
|
|
476
743
|
} catch (error) {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
error
|
|
484
|
-
},
|
|
485
|
-
sdk_meta: this.telemetryMetadata
|
|
486
|
-
};
|
|
487
|
-
this.batchProcessor.pushItem(telemetryPayload2);
|
|
744
|
+
if (error instanceof Error) {
|
|
745
|
+
if (!error.errorId) {
|
|
746
|
+
error.errorId = getRandomUUID();
|
|
747
|
+
this.prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
488
750
|
throw error;
|
|
489
751
|
}
|
|
490
752
|
};
|
|
@@ -502,6 +764,47 @@ var TelemetryService = class {
|
|
|
502
764
|
const isTelemetryDisabledByEnv = getEnvVariable("TELEMETRY_DISABLED", "false") === "true";
|
|
503
765
|
return this.transport && !this.isTelemetryDisabled && !isTelemetryDisabledByEnv && !isDevEnvironment;
|
|
504
766
|
}
|
|
767
|
+
/**
|
|
768
|
+
* Prepare and send the error telemetry.
|
|
769
|
+
*
|
|
770
|
+
* @TODO This currently blocks the thread and sends the telemetry to the server.
|
|
771
|
+
*
|
|
772
|
+
* @param {unknown} error - The error to send.
|
|
773
|
+
* @param {string} instrumentedClassName - The class name of the instrumented class.
|
|
774
|
+
* @param {string} name - The name of the method that threw the error.
|
|
775
|
+
*/
|
|
776
|
+
prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args) {
|
|
777
|
+
if (error instanceof ComposioClientError) {
|
|
778
|
+
const telemetryPayload = {
|
|
779
|
+
error_id: error.errorId || "",
|
|
780
|
+
error_message: error.message,
|
|
781
|
+
original_error: error.cause || error,
|
|
782
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
783
|
+
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
784
|
+
};
|
|
785
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
786
|
+
} else if (error instanceof ComposioError) {
|
|
787
|
+
const telemetryPayload = {
|
|
788
|
+
error_id: error.errorId || "",
|
|
789
|
+
error_message: error.message,
|
|
790
|
+
original_error: error.cause || error,
|
|
791
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
792
|
+
error_code: error.code,
|
|
793
|
+
possible_fix: error.possibleFixes?.join("\n"),
|
|
794
|
+
description: `Original Call : ${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
795
|
+
};
|
|
796
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
797
|
+
} else if (error instanceof Error) {
|
|
798
|
+
const telemetryPayload = {
|
|
799
|
+
error_id: error.errorId || "",
|
|
800
|
+
error_message: error instanceof Error ? error.name : "Unknown error",
|
|
801
|
+
original_error: error,
|
|
802
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
803
|
+
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
804
|
+
};
|
|
805
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
505
808
|
/**
|
|
506
809
|
* Send the telemetry payload to the server.
|
|
507
810
|
* @param payload - the telemetry payload to send
|
|
@@ -513,20 +816,27 @@ var TelemetryService = class {
|
|
|
513
816
|
}
|
|
514
817
|
const url = `${TELEMETRY_URL}/api/sdk_metrics/telemetry`;
|
|
515
818
|
const reqPayload = {
|
|
516
|
-
data: payload
|
|
819
|
+
data: payload.map((p) => ({
|
|
820
|
+
...p,
|
|
821
|
+
sdk_meta: this.telemetryMetadata
|
|
822
|
+
})),
|
|
517
823
|
url,
|
|
518
824
|
method: "POST",
|
|
519
825
|
headers: { "Content-Type": "application/json" }
|
|
520
826
|
};
|
|
521
827
|
this.transport.send(reqPayload);
|
|
522
828
|
}
|
|
523
|
-
|
|
829
|
+
// @TODO: check if this will send the error telemetry to the server
|
|
830
|
+
async sendErrorTelemetry(payload) {
|
|
524
831
|
if (!this.shouldSendTelemetry()) {
|
|
525
832
|
return;
|
|
526
833
|
}
|
|
527
834
|
const url = `${TELEMETRY_URL}/api/sdk_metrics/error`;
|
|
528
835
|
const reqPayload = {
|
|
529
|
-
data: {
|
|
836
|
+
data: {
|
|
837
|
+
...payload,
|
|
838
|
+
sdk_meta: this.telemetryMetadata
|
|
839
|
+
},
|
|
530
840
|
url,
|
|
531
841
|
method: "POST",
|
|
532
842
|
headers: { "Content-Type": "application/json" }
|
|
@@ -636,8 +946,7 @@ var CustomTools = class {
|
|
|
636
946
|
await this.client.toolkits.retrieve(toolkitSlug);
|
|
637
947
|
} catch (error) {
|
|
638
948
|
throw new ComposioToolNotFoundError(`Toolkit with slug ${toolkitSlug} not found`, {
|
|
639
|
-
|
|
640
|
-
error
|
|
949
|
+
cause: error
|
|
641
950
|
});
|
|
642
951
|
}
|
|
643
952
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
@@ -646,10 +955,7 @@ var CustomTools = class {
|
|
|
646
955
|
});
|
|
647
956
|
if (!connectedAccounts.items.length) {
|
|
648
957
|
throw new ComposioConnectedAccountNotFoundError(
|
|
649
|
-
`No connected accounts found for toolkit ${toolkitSlug}
|
|
650
|
-
{
|
|
651
|
-
toolkitSlug
|
|
652
|
-
}
|
|
958
|
+
`No connected accounts found for toolkit ${toolkitSlug}`
|
|
653
959
|
);
|
|
654
960
|
}
|
|
655
961
|
return metadata.connectedAccountId ? connectedAccounts.items.find((item) => item.id === metadata.connectedAccountId) : connectedAccounts.items[0];
|
|
@@ -664,9 +970,7 @@ var CustomTools = class {
|
|
|
664
970
|
async executeCustomTool(slug, inputParams, metadata) {
|
|
665
971
|
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
666
972
|
if (!tool) {
|
|
667
|
-
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found
|
|
668
|
-
toolSlug: slug
|
|
669
|
-
});
|
|
973
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
670
974
|
}
|
|
671
975
|
let authCredentials = {};
|
|
672
976
|
const { toolkitSlug, execute } = tool.options;
|
|
@@ -676,8 +980,10 @@ var CustomTools = class {
|
|
|
676
980
|
throw new ComposioConnectedAccountNotFoundError(
|
|
677
981
|
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}`,
|
|
678
982
|
{
|
|
679
|
-
|
|
680
|
-
|
|
983
|
+
meta: {
|
|
984
|
+
toolkitSlug,
|
|
985
|
+
userId: metadata.userId
|
|
986
|
+
}
|
|
681
987
|
}
|
|
682
988
|
);
|
|
683
989
|
}
|
|
@@ -685,7 +991,9 @@ var CustomTools = class {
|
|
|
685
991
|
}
|
|
686
992
|
if (typeof execute !== "function") {
|
|
687
993
|
throw new ComposioInvalidExecuteFunctionError("Invalid execute function", {
|
|
688
|
-
|
|
994
|
+
meta: {
|
|
995
|
+
toolSlug: slug
|
|
996
|
+
}
|
|
689
997
|
});
|
|
690
998
|
}
|
|
691
999
|
const executeToolRequest = async (data) => {
|
|
@@ -702,36 +1010,50 @@ var CustomTools = class {
|
|
|
702
1010
|
}
|
|
703
1011
|
};
|
|
704
1012
|
|
|
705
|
-
// src/errors/
|
|
706
|
-
import { ZodError } from "zod";
|
|
1013
|
+
// src/errors/ValidationErrors.ts
|
|
1014
|
+
import { ZodError as ZodError2 } from "zod";
|
|
707
1015
|
var ValidationErrorCodes = {
|
|
708
1016
|
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
709
1017
|
};
|
|
710
1018
|
var ValidationError = class extends ComposioError {
|
|
711
|
-
|
|
712
|
-
|
|
1019
|
+
constructor(message = "Input validation failed", options = {}) {
|
|
1020
|
+
const { cause: providedZodError, ...restOptions } = options;
|
|
713
1021
|
let zodErrorInstance;
|
|
714
|
-
if (
|
|
715
|
-
zodErrorInstance =
|
|
1022
|
+
if (providedZodError instanceof ZodError2) {
|
|
1023
|
+
zodErrorInstance = providedZodError;
|
|
1024
|
+
} else {
|
|
1025
|
+
zodErrorInstance = new ZodError2([
|
|
716
1026
|
{
|
|
717
1027
|
path: [],
|
|
718
1028
|
message: "Invalid input",
|
|
719
1029
|
code: "custom"
|
|
720
1030
|
}
|
|
721
1031
|
]);
|
|
722
|
-
} else {
|
|
723
|
-
zodErrorInstance = zodError;
|
|
724
1032
|
}
|
|
725
1033
|
const issues = zodErrorInstance.issues.map(
|
|
726
1034
|
(issue) => `[${issue.code}] ${issue.path.join(".")} - ${issue.message}`
|
|
727
1035
|
);
|
|
728
1036
|
super(message, {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
1037
|
+
...restOptions,
|
|
1038
|
+
code: options.code || ValidationErrorCodes.VALIDATION_ERROR,
|
|
1039
|
+
possibleFixes: issues,
|
|
1040
|
+
cause: zodErrorInstance
|
|
732
1041
|
});
|
|
733
|
-
this.zodError = zodErrorInstance;
|
|
734
1042
|
this.name = "ValidationError";
|
|
1043
|
+
const userFriendlyMessage = this.generateUserFriendlyMessage();
|
|
1044
|
+
this.message = `${message}: ${userFriendlyMessage}`;
|
|
1045
|
+
}
|
|
1046
|
+
generateUserFriendlyMessage() {
|
|
1047
|
+
if (this.cause instanceof ZodError2 && this.cause.issues.length > 0) {
|
|
1048
|
+
const issue = this.cause.issues[0];
|
|
1049
|
+
const path = issue.path.join(".");
|
|
1050
|
+
const param = path || "parameter";
|
|
1051
|
+
if (issue.code === "invalid_type") {
|
|
1052
|
+
return `The ${param} should be a ${issue.expected}, but you provided a ${issue.received}`;
|
|
1053
|
+
}
|
|
1054
|
+
return issue.message;
|
|
1055
|
+
}
|
|
1056
|
+
return "Please check your input parameters";
|
|
735
1057
|
}
|
|
736
1058
|
};
|
|
737
1059
|
|
|
@@ -901,14 +1223,16 @@ var Tools = class {
|
|
|
901
1223
|
async getRawComposioTools(userId, query = {}, modifier) {
|
|
902
1224
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
903
1225
|
if (queryParams.error) {
|
|
904
|
-
throw new ValidationError(
|
|
1226
|
+
throw new ValidationError("Invalid tool list parameters", {
|
|
1227
|
+
cause: queryParams.error
|
|
1228
|
+
});
|
|
905
1229
|
}
|
|
906
1230
|
const tools = await this.client.tools.list({
|
|
907
|
-
tool_slugs: queryParams.data.tools,
|
|
1231
|
+
tool_slugs: queryParams.data.tools?.join(","),
|
|
908
1232
|
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
909
1233
|
cursor: queryParams.data.cursor,
|
|
910
|
-
important: queryParams.data.important,
|
|
911
|
-
limit: queryParams.data.limit,
|
|
1234
|
+
important: typeof queryParams.data.important === "undefined" ? void 0 : queryParams.data.important ? "true" : "false",
|
|
1235
|
+
limit: queryParams.data.limit?.toString(),
|
|
912
1236
|
search: queryParams.data.search
|
|
913
1237
|
});
|
|
914
1238
|
if (!tools) {
|
|
@@ -922,7 +1246,7 @@ var Tools = class {
|
|
|
922
1246
|
if (modifier) {
|
|
923
1247
|
if (typeof modifier === "function") {
|
|
924
1248
|
modifiedTools = modifiedTools.map((tool) => {
|
|
925
|
-
return modifier(tool.slug, tool.toolkit?.slug
|
|
1249
|
+
return modifier(tool.slug, tool.toolkit?.slug ?? "unknown", tool);
|
|
926
1250
|
});
|
|
927
1251
|
} else {
|
|
928
1252
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
@@ -946,21 +1270,23 @@ var Tools = class {
|
|
|
946
1270
|
if (customTool) {
|
|
947
1271
|
return customTool;
|
|
948
1272
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
1273
|
+
let tool;
|
|
1274
|
+
try {
|
|
1275
|
+
tool = await this.client.tools.retrieve(slug);
|
|
1276
|
+
} catch (error) {
|
|
1277
|
+
throw new ComposioToolNotFoundError(`Unable to retrieve tool with slug ${slug}`, {
|
|
1278
|
+
cause: error
|
|
1279
|
+
});
|
|
954
1280
|
}
|
|
955
|
-
let
|
|
1281
|
+
let modifiedTool = this.transformToolCases(tool);
|
|
956
1282
|
if (modifier) {
|
|
957
1283
|
if (typeof modifier === "function") {
|
|
958
|
-
|
|
1284
|
+
modifiedTool = modifier(slug, modifiedTool.toolkit?.slug ?? "unknown", modifiedTool);
|
|
959
1285
|
} else {
|
|
960
1286
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
961
1287
|
}
|
|
962
1288
|
}
|
|
963
|
-
return
|
|
1289
|
+
return modifiedTool;
|
|
964
1290
|
}
|
|
965
1291
|
/**
|
|
966
1292
|
* Get a tool or list of tools based on the provided arguments.
|
|
@@ -1013,7 +1339,7 @@ var Tools = class {
|
|
|
1013
1339
|
async handleCustomToolExecution(tool, body, modifiers) {
|
|
1014
1340
|
if (modifiers?.beforeExecute) {
|
|
1015
1341
|
if (typeof modifiers.beforeExecute === "function") {
|
|
1016
|
-
body = modifiers.beforeExecute(tool.slug, "
|
|
1342
|
+
body = modifiers.beforeExecute(tool.slug, "unknown", body);
|
|
1017
1343
|
} else {
|
|
1018
1344
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
1019
1345
|
}
|
|
@@ -1024,7 +1350,7 @@ var Tools = class {
|
|
|
1024
1350
|
});
|
|
1025
1351
|
if (modifiers?.afterExecute) {
|
|
1026
1352
|
if (typeof modifiers.afterExecute === "function") {
|
|
1027
|
-
result = modifiers.afterExecute(tool.slug, "
|
|
1353
|
+
result = modifiers.afterExecute(tool.slug, "unknown", result);
|
|
1028
1354
|
} else {
|
|
1029
1355
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
1030
1356
|
}
|
|
@@ -1042,7 +1368,7 @@ var Tools = class {
|
|
|
1042
1368
|
async handleComposioToolExecution(tool, body, modifiers) {
|
|
1043
1369
|
if (modifiers?.beforeExecute) {
|
|
1044
1370
|
if (typeof modifiers.beforeExecute === "function") {
|
|
1045
|
-
body = modifiers.beforeExecute(tool.slug, tool.toolkit?.slug
|
|
1371
|
+
body = modifiers.beforeExecute(tool.slug, tool.toolkit?.slug ?? "unknown", body);
|
|
1046
1372
|
} else {
|
|
1047
1373
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
1048
1374
|
}
|
|
@@ -1063,7 +1389,7 @@ var Tools = class {
|
|
|
1063
1389
|
result = this.transformToolExecuteResponse(result);
|
|
1064
1390
|
if (modifiers?.afterExecute) {
|
|
1065
1391
|
if (typeof modifiers.afterExecute === "function") {
|
|
1066
|
-
result = modifiers.afterExecute(tool.slug, tool.toolkit?.slug
|
|
1392
|
+
result = modifiers.afterExecute(tool.slug, tool.toolkit?.slug ?? "unknown", result);
|
|
1067
1393
|
} else {
|
|
1068
1394
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
1069
1395
|
}
|
|
@@ -1127,9 +1453,12 @@ var Tools = class {
|
|
|
1127
1453
|
return this.handleComposioToolExecution(composioTool, body, modifiers);
|
|
1128
1454
|
}
|
|
1129
1455
|
} catch (error) {
|
|
1130
|
-
throw new ComposioToolExecutionError(
|
|
1131
|
-
|
|
1132
|
-
|
|
1456
|
+
throw new ComposioToolExecutionError(`Error executing tool ${slug}`, {
|
|
1457
|
+
originalError: error,
|
|
1458
|
+
meta: {
|
|
1459
|
+
toolSlug: slug,
|
|
1460
|
+
body
|
|
1461
|
+
}
|
|
1133
1462
|
});
|
|
1134
1463
|
}
|
|
1135
1464
|
}
|
|
@@ -1203,6 +1532,9 @@ var Tools = class {
|
|
|
1203
1532
|
}
|
|
1204
1533
|
};
|
|
1205
1534
|
|
|
1535
|
+
// src/models/Toolkits.ts
|
|
1536
|
+
import ComposioClient2 from "@composio/client";
|
|
1537
|
+
|
|
1206
1538
|
// src/types/toolkit.types.ts
|
|
1207
1539
|
import { z as z2 } from "zod";
|
|
1208
1540
|
var ToolkitMangedByEnumSchema = z2.enum(["all", "composio", "project"]);
|
|
@@ -1283,8 +1615,101 @@ var ToolkitRetrieveCategoriesResponseSchema = z2.object({
|
|
|
1283
1615
|
totalPages: z2.number()
|
|
1284
1616
|
});
|
|
1285
1617
|
|
|
1286
|
-
// src/
|
|
1287
|
-
|
|
1618
|
+
// src/errors/AuthConfigErrors.ts
|
|
1619
|
+
var AuthConfigErrorCodes = {
|
|
1620
|
+
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1621
|
+
};
|
|
1622
|
+
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1623
|
+
constructor(message = "Auth config not found", options = {}) {
|
|
1624
|
+
super(message, {
|
|
1625
|
+
...options,
|
|
1626
|
+
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1627
|
+
possibleFixes: options.possibleFixes || [
|
|
1628
|
+
"Check if the auth config exists",
|
|
1629
|
+
"Check if the auth config id is correct",
|
|
1630
|
+
"Check if the auth config is enabled"
|
|
1631
|
+
]
|
|
1632
|
+
});
|
|
1633
|
+
this.name = "ComposioAuthConfigNotFoundError";
|
|
1634
|
+
}
|
|
1635
|
+
};
|
|
1636
|
+
|
|
1637
|
+
// src/errors/ConnectionRequestErrors.ts
|
|
1638
|
+
var ConnectionRequestErrorCodes = {
|
|
1639
|
+
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1640
|
+
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1641
|
+
};
|
|
1642
|
+
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1643
|
+
constructor(message = "Connection request timed out", options = {}) {
|
|
1644
|
+
super(message, {
|
|
1645
|
+
...options,
|
|
1646
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT
|
|
1647
|
+
});
|
|
1648
|
+
this.name = "ConnectionRequestTimeoutError";
|
|
1649
|
+
}
|
|
1650
|
+
};
|
|
1651
|
+
var ConnectionRequestFailedError = class extends ComposioError {
|
|
1652
|
+
constructor(message = "Connection request failed", options = {}) {
|
|
1653
|
+
super(message, {
|
|
1654
|
+
...options,
|
|
1655
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED
|
|
1656
|
+
});
|
|
1657
|
+
this.name = "ConnectionRequestFailedError";
|
|
1658
|
+
}
|
|
1659
|
+
};
|
|
1660
|
+
|
|
1661
|
+
// src/errors/ToolkitErrors.ts
|
|
1662
|
+
var ToolkitErrorCodes = {
|
|
1663
|
+
TOOLKIT_NOT_FOUND: "TOOLKIT_NOT_FOUND"
|
|
1664
|
+
};
|
|
1665
|
+
var ComposioToolkitNotFoundError = class extends ComposioError {
|
|
1666
|
+
constructor(message = "Toolkit not found", options = {}) {
|
|
1667
|
+
super(message, {
|
|
1668
|
+
...options,
|
|
1669
|
+
code: "TOOLKIT_NOT_FOUND",
|
|
1670
|
+
possibleFixes: options.possibleFixes || [
|
|
1671
|
+
"Ensure the toolkit is correctly configured and the slug is valid"
|
|
1672
|
+
]
|
|
1673
|
+
});
|
|
1674
|
+
this.name = "ComposioToolkitNotFoundError";
|
|
1675
|
+
}
|
|
1676
|
+
};
|
|
1677
|
+
var ComposioToolkitFetchError = class extends ComposioError {
|
|
1678
|
+
constructor(message = "Failed to fetch toolkit", options = {}) {
|
|
1679
|
+
super(message, {
|
|
1680
|
+
...options,
|
|
1681
|
+
code: "TOOLKIT_FETCH_ERROR",
|
|
1682
|
+
possibleFixes: options.possibleFixes || [
|
|
1683
|
+
"Ensure the toolkit slug is valid",
|
|
1684
|
+
"Ensure you are using the correct API key",
|
|
1685
|
+
"Ensure you are using the correct API endpoint / Base URL and it is working"
|
|
1686
|
+
]
|
|
1687
|
+
});
|
|
1688
|
+
this.name = "ComposioToolkitFetchError";
|
|
1689
|
+
}
|
|
1690
|
+
};
|
|
1691
|
+
|
|
1692
|
+
// src/errors/SDKErrors.ts
|
|
1693
|
+
var SDKErrorCodes = {
|
|
1694
|
+
NO_API_KEY_PROVIDED: "NO_API_KEY_PROVIDED"
|
|
1695
|
+
};
|
|
1696
|
+
var ComposioNoAPIKeyError = class extends ComposioError {
|
|
1697
|
+
constructor(message = "No Composio API key provided", options = {}) {
|
|
1698
|
+
const defaultCause = "Couldn't find an API key in the params, environment variables or in the user config file";
|
|
1699
|
+
super(message, {
|
|
1700
|
+
...options,
|
|
1701
|
+
code: "NO_API_KEY",
|
|
1702
|
+
cause: options.cause || defaultCause,
|
|
1703
|
+
possibleFixes: options.possibleFixes || [
|
|
1704
|
+
"Ensure you have an API key passed in the params, or in environment variable (COMPOSIO_API_KEY) or in the user config file",
|
|
1705
|
+
"To get an API key, please sign up at https://composio.dev/signup",
|
|
1706
|
+
"You can also use the Composio CLI to create a project and get an API key"
|
|
1707
|
+
],
|
|
1708
|
+
statusCode: 401
|
|
1709
|
+
});
|
|
1710
|
+
this.name = "ComposioNoAPIKeyError";
|
|
1711
|
+
}
|
|
1712
|
+
};
|
|
1288
1713
|
|
|
1289
1714
|
// src/types/authConfigs.types.ts
|
|
1290
1715
|
import { z as z3 } from "zod";
|
|
@@ -1365,11 +1790,11 @@ var AuthConfigListParamsSchema = z3.object({
|
|
|
1365
1790
|
cursor: z3.string().optional(),
|
|
1366
1791
|
isComposioManaged: z3.boolean().optional(),
|
|
1367
1792
|
limit: z3.number().optional(),
|
|
1368
|
-
|
|
1793
|
+
toolkit: z3.string().optional()
|
|
1369
1794
|
});
|
|
1370
1795
|
var AuthConfigListResponseSchema = z3.object({
|
|
1371
1796
|
items: z3.array(AuthConfigRetrieveResponseSchema),
|
|
1372
|
-
nextCursor: z3.string().
|
|
1797
|
+
nextCursor: z3.string().nullable(),
|
|
1373
1798
|
totalPages: z3.number()
|
|
1374
1799
|
});
|
|
1375
1800
|
var AuthCustomConfigUpdateParamsSchema = z3.object({
|
|
@@ -1434,7 +1859,9 @@ var AuthConfigs = class {
|
|
|
1434
1859
|
lastUpdatedAt: authConfig.last_updated_at
|
|
1435
1860
|
});
|
|
1436
1861
|
if (result.error) {
|
|
1437
|
-
throw new ValidationError(
|
|
1862
|
+
throw new ValidationError("Failed to parse auth config response", {
|
|
1863
|
+
cause: result.error
|
|
1864
|
+
});
|
|
1438
1865
|
}
|
|
1439
1866
|
return result.data;
|
|
1440
1867
|
}
|
|
@@ -1455,7 +1882,7 @@ var AuthConfigs = class {
|
|
|
1455
1882
|
*
|
|
1456
1883
|
* // List auth configs for a specific toolkit
|
|
1457
1884
|
* const githubConfigs = await composio.authConfigs.list({
|
|
1458
|
-
*
|
|
1885
|
+
* toolkit: 'github'
|
|
1459
1886
|
* });
|
|
1460
1887
|
*
|
|
1461
1888
|
* // List Composio-managed auth configs
|
|
@@ -1469,8 +1896,8 @@ var AuthConfigs = class {
|
|
|
1469
1896
|
const result = await this.client.authConfigs.list({
|
|
1470
1897
|
cursor: parsedQuery?.cursor,
|
|
1471
1898
|
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1472
|
-
limit: parsedQuery?.limit
|
|
1473
|
-
toolkit_slug: parsedQuery?.
|
|
1899
|
+
limit: parsedQuery?.limit,
|
|
1900
|
+
toolkit_slug: parsedQuery?.toolkit
|
|
1474
1901
|
});
|
|
1475
1902
|
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
1476
1903
|
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
@@ -1478,7 +1905,9 @@ var AuthConfigs = class {
|
|
|
1478
1905
|
totalPages: result.total_pages
|
|
1479
1906
|
});
|
|
1480
1907
|
if (parsedResult.error) {
|
|
1481
|
-
throw new ValidationError(
|
|
1908
|
+
throw new ValidationError("Failed to parse auth config list response", {
|
|
1909
|
+
cause: parsedResult.error
|
|
1910
|
+
});
|
|
1482
1911
|
}
|
|
1483
1912
|
return parsedResult.data;
|
|
1484
1913
|
}
|
|
@@ -1503,7 +1932,9 @@ var AuthConfigs = class {
|
|
|
1503
1932
|
async create(toolkit, options = { type: "use_composio_managed_auth" }) {
|
|
1504
1933
|
const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
|
|
1505
1934
|
if (parsedOptions.error) {
|
|
1506
|
-
throw new ValidationError(
|
|
1935
|
+
throw new ValidationError("Failed to parse auth config create options", {
|
|
1936
|
+
cause: parsedOptions.error
|
|
1937
|
+
});
|
|
1507
1938
|
}
|
|
1508
1939
|
const result = await this.client.authConfigs.create({
|
|
1509
1940
|
toolkit: {
|
|
@@ -1518,7 +1949,9 @@ var AuthConfigs = class {
|
|
|
1518
1949
|
toolkit: result.toolkit.slug
|
|
1519
1950
|
});
|
|
1520
1951
|
if (parsedResult.error) {
|
|
1521
|
-
throw new ValidationError(
|
|
1952
|
+
throw new ValidationError("Failed to parse auth config create response", {
|
|
1953
|
+
cause: parsedResult.error
|
|
1954
|
+
});
|
|
1522
1955
|
}
|
|
1523
1956
|
return parsedResult.data;
|
|
1524
1957
|
}
|
|
@@ -1578,7 +2011,9 @@ var AuthConfigs = class {
|
|
|
1578
2011
|
async update(nanoid, data) {
|
|
1579
2012
|
const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
|
|
1580
2013
|
if (parsedData.error) {
|
|
1581
|
-
throw new ValidationError(
|
|
2014
|
+
throw new ValidationError("Failed to parse auth config update data", {
|
|
2015
|
+
cause: parsedData.error
|
|
2016
|
+
});
|
|
1582
2017
|
}
|
|
1583
2018
|
return this.client.authConfigs.update(
|
|
1584
2019
|
nanoid,
|
|
@@ -1679,42 +2114,21 @@ var AuthConfigs = class {
|
|
|
1679
2114
|
}
|
|
1680
2115
|
};
|
|
1681
2116
|
|
|
1682
|
-
// src/errors/AuthConfigErrors.ts
|
|
1683
|
-
var AuthConfigErrorCodes = {
|
|
1684
|
-
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1685
|
-
};
|
|
1686
|
-
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1687
|
-
constructor(message, meta) {
|
|
1688
|
-
super(message, {
|
|
1689
|
-
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1690
|
-
cause: meta,
|
|
1691
|
-
possibleFixes: [
|
|
1692
|
-
"Check if the auth config exists",
|
|
1693
|
-
"Check if the auth config id is correct",
|
|
1694
|
-
"Check if the auth config is enabled"
|
|
1695
|
-
]
|
|
1696
|
-
});
|
|
1697
|
-
this.name = "ComposioAuthConfigNotFoundError";
|
|
1698
|
-
}
|
|
1699
|
-
};
|
|
1700
|
-
|
|
1701
2117
|
// src/types/connectedAccounts.types.ts
|
|
1702
2118
|
import { z as z4 } from "zod";
|
|
1703
2119
|
var ConnectedAccountStatuses = {
|
|
1704
|
-
|
|
1705
|
-
INACTIVE: "INACTIVE",
|
|
1706
|
-
DELETED: "DELETED",
|
|
2120
|
+
INITIALIZING: "INITIALIZING",
|
|
1707
2121
|
INITIATED: "INITIATED",
|
|
1708
|
-
|
|
1709
|
-
FAILED: "FAILED"
|
|
2122
|
+
ACTIVE: "ACTIVE",
|
|
2123
|
+
FAILED: "FAILED",
|
|
2124
|
+
EXPIRED: "EXPIRED"
|
|
1710
2125
|
};
|
|
1711
2126
|
var ConnectedAccountStatusSchema = z4.enum([
|
|
1712
|
-
ConnectedAccountStatuses.
|
|
1713
|
-
ConnectedAccountStatuses.INACTIVE,
|
|
1714
|
-
ConnectedAccountStatuses.DELETED,
|
|
2127
|
+
ConnectedAccountStatuses.INITIALIZING,
|
|
1715
2128
|
ConnectedAccountStatuses.INITIATED,
|
|
1716
|
-
ConnectedAccountStatuses.
|
|
1717
|
-
ConnectedAccountStatuses.FAILED
|
|
2129
|
+
ConnectedAccountStatuses.ACTIVE,
|
|
2130
|
+
ConnectedAccountStatuses.FAILED,
|
|
2131
|
+
ConnectedAccountStatuses.EXPIRED
|
|
1718
2132
|
]);
|
|
1719
2133
|
var CreateConnectedAccountParamsSchema = z4.object({
|
|
1720
2134
|
authConfig: z4.object({
|
|
@@ -1815,33 +2229,7 @@ var ConnectedAccountListResponseSchema = z4.object({
|
|
|
1815
2229
|
|
|
1816
2230
|
// src/models/ConnectionRequest.ts
|
|
1817
2231
|
import ComposioClient from "@composio/client";
|
|
1818
|
-
import { ZodError as
|
|
1819
|
-
|
|
1820
|
-
// src/errors/ConnectionRequestError.ts
|
|
1821
|
-
var ConnectionRequestErrorCodes = {
|
|
1822
|
-
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1823
|
-
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1824
|
-
};
|
|
1825
|
-
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1826
|
-
constructor(message = "Connection request timed out", meta = {}) {
|
|
1827
|
-
super(message, {
|
|
1828
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
|
|
1829
|
-
meta
|
|
1830
|
-
});
|
|
1831
|
-
this.name = "ConnectionRequestTimeoutError";
|
|
1832
|
-
}
|
|
1833
|
-
};
|
|
1834
|
-
var ConnectionRequestFailedError = class extends ComposioError {
|
|
1835
|
-
constructor(message = "Connection request failed", meta = {}) {
|
|
1836
|
-
super(message, {
|
|
1837
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED,
|
|
1838
|
-
meta
|
|
1839
|
-
});
|
|
1840
|
-
this.name = "ConnectionRequestFailedError";
|
|
1841
|
-
}
|
|
1842
|
-
};
|
|
1843
|
-
|
|
1844
|
-
// src/models/ConnectionRequest.ts
|
|
2232
|
+
import { ZodError as ZodError3 } from "zod";
|
|
1845
2233
|
var ConnectionRequest = class {
|
|
1846
2234
|
client;
|
|
1847
2235
|
id;
|
|
@@ -1887,7 +2275,7 @@ var ConnectionRequest = class {
|
|
|
1887
2275
|
return parsedResponse;
|
|
1888
2276
|
} catch (error) {
|
|
1889
2277
|
logger_default.error("Error transforming response", error);
|
|
1890
|
-
if (error instanceof
|
|
2278
|
+
if (error instanceof ZodError3) {
|
|
1891
2279
|
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1892
2280
|
}
|
|
1893
2281
|
throw error;
|
|
@@ -1931,7 +2319,9 @@ var ConnectionRequest = class {
|
|
|
1931
2319
|
throw new ComposioConnectedAccountNotFoundError(
|
|
1932
2320
|
`Connected account with id ${this.id} not found`,
|
|
1933
2321
|
{
|
|
1934
|
-
|
|
2322
|
+
meta: {
|
|
2323
|
+
connectedAccountId: this.id
|
|
2324
|
+
}
|
|
1935
2325
|
}
|
|
1936
2326
|
);
|
|
1937
2327
|
} else {
|
|
@@ -1940,8 +2330,7 @@ var ConnectionRequest = class {
|
|
|
1940
2330
|
}
|
|
1941
2331
|
const terminalErrorStates = [
|
|
1942
2332
|
ConnectedAccountStatuses.FAILED,
|
|
1943
|
-
ConnectedAccountStatuses.EXPIRED
|
|
1944
|
-
ConnectedAccountStatuses.DELETED
|
|
2333
|
+
ConnectedAccountStatuses.EXPIRED
|
|
1945
2334
|
];
|
|
1946
2335
|
const start = Date.now();
|
|
1947
2336
|
const pollInterval = 1e3;
|
|
@@ -1956,10 +2345,12 @@ var ConnectionRequest = class {
|
|
|
1956
2345
|
throw new ConnectionRequestFailedError(
|
|
1957
2346
|
`Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ""}`,
|
|
1958
2347
|
{
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
2348
|
+
meta: {
|
|
2349
|
+
userId: response.user_id,
|
|
2350
|
+
connectedAccountId: this.id,
|
|
2351
|
+
status: response.status,
|
|
2352
|
+
statusReason: response.status_reason
|
|
2353
|
+
}
|
|
1963
2354
|
}
|
|
1964
2355
|
);
|
|
1965
2356
|
}
|
|
@@ -1970,6 +2361,23 @@ var ConnectionRequest = class {
|
|
|
1970
2361
|
}
|
|
1971
2362
|
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${this.id}`);
|
|
1972
2363
|
}
|
|
2364
|
+
/**
|
|
2365
|
+
* Returns a JSON-serializable representation of the connection request
|
|
2366
|
+
* Excludes the private client property to avoid cyclic reference issues
|
|
2367
|
+
*/
|
|
2368
|
+
toJSON() {
|
|
2369
|
+
return {
|
|
2370
|
+
id: this.id,
|
|
2371
|
+
status: this.status,
|
|
2372
|
+
redirectUrl: this.redirectUrl
|
|
2373
|
+
};
|
|
2374
|
+
}
|
|
2375
|
+
/**
|
|
2376
|
+
* Returns a string representation of the connection request
|
|
2377
|
+
*/
|
|
2378
|
+
toString() {
|
|
2379
|
+
return JSON.stringify(this.toJSON(), null, 2);
|
|
2380
|
+
}
|
|
1973
2381
|
};
|
|
1974
2382
|
|
|
1975
2383
|
// src/models/ConnectedAccounts.ts
|
|
@@ -1997,7 +2405,9 @@ var ConnectedAccounts = class {
|
|
|
1997
2405
|
testRequestEndpoint: response.test_request_endpoint
|
|
1998
2406
|
});
|
|
1999
2407
|
if (!result.success) {
|
|
2000
|
-
throw new ValidationError(
|
|
2408
|
+
throw new ValidationError("Failed to parse connected account retrieve response", {
|
|
2409
|
+
cause: result.error
|
|
2410
|
+
});
|
|
2001
2411
|
}
|
|
2002
2412
|
return result.data;
|
|
2003
2413
|
}
|
|
@@ -2030,7 +2440,9 @@ var ConnectedAccounts = class {
|
|
|
2030
2440
|
if (query) {
|
|
2031
2441
|
const parsedQuery = ConnectedAccountListParamsSchema.safeParse(query);
|
|
2032
2442
|
if (!parsedQuery.success) {
|
|
2033
|
-
throw new ValidationError(
|
|
2443
|
+
throw new ValidationError("Failed to parse connected account list query", {
|
|
2444
|
+
cause: parsedQuery.error
|
|
2445
|
+
});
|
|
2034
2446
|
}
|
|
2035
2447
|
rawQuery = {
|
|
2036
2448
|
auth_config_ids: parsedQuery.data.authConfigIds,
|
|
@@ -2050,7 +2462,9 @@ var ConnectedAccounts = class {
|
|
|
2050
2462
|
totalPages: result.total_pages
|
|
2051
2463
|
});
|
|
2052
2464
|
if (!parsedResponse.success) {
|
|
2053
|
-
throw new ValidationError(
|
|
2465
|
+
throw new ValidationError("Failed to parse connected account list response", {
|
|
2466
|
+
cause: parsedResponse.error
|
|
2467
|
+
});
|
|
2054
2468
|
}
|
|
2055
2469
|
return parsedResponse.data;
|
|
2056
2470
|
}
|
|
@@ -2236,42 +2650,46 @@ var Toolkits = class {
|
|
|
2236
2650
|
* @private
|
|
2237
2651
|
*/
|
|
2238
2652
|
async getToolkits(query) {
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
sort_by: parsedQuery.sortBy
|
|
2245
|
-
});
|
|
2246
|
-
const parsedResult = ToolKitListResponseSchema.parse({
|
|
2247
|
-
items: result.items.map((item) => {
|
|
2248
|
-
const parsedItem = ToolKitItemSchema.parse({
|
|
2249
|
-
name: item.name,
|
|
2250
|
-
slug: item.slug,
|
|
2251
|
-
meta: item.meta,
|
|
2252
|
-
isLocalToolkit: item.is_local_toolkit,
|
|
2253
|
-
authSchemes: item.auth_schemes,
|
|
2254
|
-
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
2255
|
-
noAuth: item.no_auth
|
|
2653
|
+
try {
|
|
2654
|
+
const parsedQuery = ToolkitsListParamsSchema.safeParse(query);
|
|
2655
|
+
if (!parsedQuery.success) {
|
|
2656
|
+
throw new ValidationError("Failed to parse toolkit list query", {
|
|
2657
|
+
cause: parsedQuery.error
|
|
2256
2658
|
});
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2659
|
+
}
|
|
2660
|
+
const result = await this.client.toolkits.list({
|
|
2661
|
+
category: parsedQuery.data.category,
|
|
2662
|
+
is_local: parsedQuery.data.isLocal,
|
|
2663
|
+
managed_by: parsedQuery.data.managedBy,
|
|
2664
|
+
sort_by: parsedQuery.data.sortBy
|
|
2665
|
+
});
|
|
2666
|
+
const parsedResult = ToolKitListResponseSchema.safeParse({
|
|
2667
|
+
items: result.items.map((item) => {
|
|
2668
|
+
const parsedItem = ToolKitItemSchema.parse({
|
|
2669
|
+
name: item.name,
|
|
2670
|
+
slug: item.slug,
|
|
2671
|
+
meta: item.meta,
|
|
2672
|
+
isLocalToolkit: item.is_local_toolkit,
|
|
2673
|
+
authSchemes: item.auth_schemes,
|
|
2674
|
+
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
2675
|
+
noAuth: item.no_auth
|
|
2676
|
+
});
|
|
2677
|
+
return parsedItem;
|
|
2678
|
+
}),
|
|
2679
|
+
nextCursor: result.next_cursor,
|
|
2680
|
+
totalPages: result.total_pages
|
|
2681
|
+
});
|
|
2682
|
+
if (!parsedResult.success) {
|
|
2683
|
+
throw new ValidationError("Failed to parse toolkit list response", {
|
|
2684
|
+
cause: parsedResult.error
|
|
2685
|
+
});
|
|
2686
|
+
}
|
|
2687
|
+
return parsedResult.data;
|
|
2688
|
+
} catch (error) {
|
|
2689
|
+
throw new ComposioToolkitFetchError("Failed to fetch toolkits", {
|
|
2690
|
+
cause: error
|
|
2691
|
+
});
|
|
2273
2692
|
}
|
|
2274
|
-
return this.getToolkits(arg);
|
|
2275
2693
|
}
|
|
2276
2694
|
/**
|
|
2277
2695
|
* Retrieves a specific toolkit by its slug identifier.
|
|
@@ -2289,7 +2707,7 @@ var Toolkits = class {
|
|
|
2289
2707
|
async getToolkitBySlug(slug) {
|
|
2290
2708
|
try {
|
|
2291
2709
|
const result = await this.client.toolkits.retrieve(slug);
|
|
2292
|
-
const parsedResult = ToolkitRetrieveResponseSchema.
|
|
2710
|
+
const parsedResult = ToolkitRetrieveResponseSchema.safeParse({
|
|
2293
2711
|
name: result.name,
|
|
2294
2712
|
slug: result.slug,
|
|
2295
2713
|
meta: {
|
|
@@ -2314,16 +2732,41 @@ var Toolkits = class {
|
|
|
2314
2732
|
}
|
|
2315
2733
|
}))
|
|
2316
2734
|
});
|
|
2317
|
-
|
|
2735
|
+
if (!parsedResult.success) {
|
|
2736
|
+
throw new ValidationError("Failed to parse toolkit response", {
|
|
2737
|
+
cause: parsedResult.error
|
|
2738
|
+
});
|
|
2739
|
+
}
|
|
2740
|
+
return parsedResult.data;
|
|
2318
2741
|
} catch (error) {
|
|
2319
|
-
if (error instanceof
|
|
2320
|
-
throw new
|
|
2742
|
+
if (error instanceof ComposioClient2.NotFoundError) {
|
|
2743
|
+
throw new ComposioToolkitNotFoundError(`Toolkit with slug ${slug} not found`, {
|
|
2744
|
+
meta: {
|
|
2745
|
+
slug
|
|
2746
|
+
},
|
|
2747
|
+
cause: error
|
|
2748
|
+
});
|
|
2321
2749
|
}
|
|
2322
|
-
throw new
|
|
2323
|
-
|
|
2750
|
+
throw new ComposioToolkitFetchError(`Couldn't fetch Toolkit with slug: ${slug}`, {
|
|
2751
|
+
meta: {
|
|
2752
|
+
slug
|
|
2753
|
+
},
|
|
2754
|
+
cause: error
|
|
2324
2755
|
});
|
|
2325
2756
|
}
|
|
2326
2757
|
}
|
|
2758
|
+
/**
|
|
2759
|
+
* Implementation method that handles both overloads for retrieving toolkits.
|
|
2760
|
+
*
|
|
2761
|
+
* @param {string | ToolkitListParams} arg - Either a toolkit slug or query parameters
|
|
2762
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit or list of toolkits
|
|
2763
|
+
*/
|
|
2764
|
+
async get(arg) {
|
|
2765
|
+
if (typeof arg === "string") {
|
|
2766
|
+
return this.getToolkitBySlug(arg);
|
|
2767
|
+
}
|
|
2768
|
+
return this.getToolkits(arg);
|
|
2769
|
+
}
|
|
2327
2770
|
/**
|
|
2328
2771
|
* Retrieves all toolkit categories available in the Composio SDK.
|
|
2329
2772
|
*
|
|
@@ -2371,7 +2814,7 @@ var Toolkits = class {
|
|
|
2371
2814
|
const composioAuthConfig = new AuthConfigs(this.client);
|
|
2372
2815
|
let authConfigIdToUse;
|
|
2373
2816
|
const authConfig = await composioAuthConfig.list({
|
|
2374
|
-
toolkitSlug
|
|
2817
|
+
toolkit: toolkitSlug
|
|
2375
2818
|
});
|
|
2376
2819
|
authConfigIdToUse = authConfig.items[0]?.id;
|
|
2377
2820
|
if (!authConfigIdToUse) {
|
|
@@ -2383,7 +2826,9 @@ var Toolkits = class {
|
|
|
2383
2826
|
authConfigIdToUse = authConfig2.id;
|
|
2384
2827
|
} else {
|
|
2385
2828
|
throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
|
|
2386
|
-
|
|
2829
|
+
meta: {
|
|
2830
|
+
toolkitSlug
|
|
2831
|
+
}
|
|
2387
2832
|
});
|
|
2388
2833
|
}
|
|
2389
2834
|
}
|
|
@@ -2392,126 +2837,422 @@ var Toolkits = class {
|
|
|
2392
2837
|
}
|
|
2393
2838
|
};
|
|
2394
2839
|
|
|
2395
|
-
// src/
|
|
2396
|
-
|
|
2397
|
-
var
|
|
2398
|
-
var
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2840
|
+
// src/types/triggers.types.ts
|
|
2841
|
+
import { z as z5 } from "zod";
|
|
2842
|
+
var TriggerStatusEnum = z5.enum(["enable", "disable"]);
|
|
2843
|
+
var TriggerSubscribeParamSchema = z5.object({
|
|
2844
|
+
toolkits: z5.array(z5.string()).optional(),
|
|
2845
|
+
triggerId: z5.string().optional(),
|
|
2846
|
+
connectedAccountId: z5.string().optional(),
|
|
2847
|
+
authConfigId: z5.string().optional(),
|
|
2848
|
+
triggerSlug: z5.array(z5.string()).optional(),
|
|
2849
|
+
triggerData: z5.string().optional(),
|
|
2850
|
+
userId: z5.string().optional()
|
|
2851
|
+
});
|
|
2852
|
+
var TriggerInstanceListActiveParamsSchema = z5.object({
|
|
2853
|
+
authConfigIds: z5.array(z5.string()).nullable().optional(),
|
|
2854
|
+
connectedAccountIds: z5.array(z5.string()).nullable().optional(),
|
|
2855
|
+
limit: z5.number().optional(),
|
|
2856
|
+
page: z5.number().optional(),
|
|
2857
|
+
showDisabled: z5.boolean().nullable().optional(),
|
|
2858
|
+
triggerIds: z5.array(z5.string()).nullable().optional(),
|
|
2859
|
+
triggerNames: z5.array(z5.string()).nullable().optional()
|
|
2860
|
+
});
|
|
2861
|
+
var TriggerInstanceListActiveResponseItemSchema = z5.object({
|
|
2862
|
+
id: z5.string(),
|
|
2863
|
+
connectedAccountId: z5.string(),
|
|
2864
|
+
disabledAt: z5.string().nullable(),
|
|
2865
|
+
state: z5.record(z5.unknown()),
|
|
2866
|
+
triggerConfig: z5.record(z5.unknown()),
|
|
2867
|
+
triggerName: z5.string(),
|
|
2868
|
+
updatedAt: z5.string(),
|
|
2869
|
+
triggerData: z5.string().optional(),
|
|
2870
|
+
uuid: z5.string().optional()
|
|
2871
|
+
});
|
|
2872
|
+
var TriggerInstanceListActiveResponseSchema = z5.object({
|
|
2873
|
+
items: z5.array(TriggerInstanceListActiveResponseItemSchema),
|
|
2874
|
+
nextCursor: z5.string().nullable(),
|
|
2875
|
+
totalPages: z5.number()
|
|
2876
|
+
});
|
|
2877
|
+
var TriggerInstanceUpsertParamsSchema = z5.object({
|
|
2878
|
+
connectedAccountId: z5.string().optional(),
|
|
2879
|
+
triggerConfig: z5.record(z5.unknown()).optional()
|
|
2880
|
+
});
|
|
2881
|
+
var TriggerInstanceUpsertResponseSchema = z5.object({
|
|
2882
|
+
triggerId: z5.string()
|
|
2883
|
+
});
|
|
2884
|
+
var TriggerInstanceManageUpdateParamsSchema = z5.object({
|
|
2885
|
+
status: z5.enum(["enable", "disable"])
|
|
2886
|
+
});
|
|
2887
|
+
var TriggerInstanceManageUpdateResponseSchema = z5.object({
|
|
2888
|
+
status: z5.enum(["success"])
|
|
2889
|
+
});
|
|
2890
|
+
var TriggerInstanceManageDeleteResponseSchema = z5.object({
|
|
2891
|
+
triggerId: z5.string()
|
|
2892
|
+
});
|
|
2893
|
+
var IncomingTriggerPayloadSchema = z5.object({
|
|
2894
|
+
id: z5.string().describe("The ID of the trigger"),
|
|
2895
|
+
triggerSlug: z5.string().describe("The slug of the trigger that triggered the event"),
|
|
2896
|
+
toolkitSlug: z5.string().describe("The slug of the toolkit that triggered the event"),
|
|
2897
|
+
userId: z5.string().describe("The ID of the user that triggered the event"),
|
|
2898
|
+
payload: z5.record(z5.unknown()).describe("The payload of the trigger").optional(),
|
|
2899
|
+
originalPayload: z5.record(z5.unknown()).describe("The original payload of the trigger").optional(),
|
|
2900
|
+
metadata: z5.object({
|
|
2901
|
+
id: z5.string(),
|
|
2902
|
+
toolkitSlug: z5.string(),
|
|
2903
|
+
triggerSlug: z5.string(),
|
|
2904
|
+
triggerData: z5.string().optional(),
|
|
2905
|
+
triggerConfig: z5.record(z5.unknown()),
|
|
2906
|
+
connectedAccount: z5.object({
|
|
2907
|
+
id: z5.string(),
|
|
2908
|
+
uuid: z5.string(),
|
|
2909
|
+
authConfigId: z5.string(),
|
|
2910
|
+
authConfigUUID: z5.string(),
|
|
2911
|
+
userId: z5.string(),
|
|
2912
|
+
status: z5.enum(["ACTIVE", "INACTIVE"])
|
|
2913
|
+
})
|
|
2914
|
+
})
|
|
2915
|
+
});
|
|
2916
|
+
|
|
2917
|
+
// src/services/internal/InternalService.types.ts
|
|
2918
|
+
import { z as z6 } from "zod";
|
|
2919
|
+
var SDKRealtimeCredentialsResponseSchema = z6.object({
|
|
2920
|
+
projectId: z6.string().describe("The project ID"),
|
|
2921
|
+
pusherKey: z6.string().describe("The Pusher key"),
|
|
2922
|
+
pusherCluster: z6.string().describe("The Pusher cluster")
|
|
2923
|
+
});
|
|
2924
|
+
|
|
2925
|
+
// src/services/internal/InternalService.ts
|
|
2926
|
+
var SDK_REALTIME_CREDENTIALS_ENDPOINT = "/api/v3/internal/sdk/realtime/credentials";
|
|
2927
|
+
var InternalService = class {
|
|
2928
|
+
constructor(client) {
|
|
2929
|
+
this.client = client;
|
|
2930
|
+
this.client = client;
|
|
2415
2931
|
}
|
|
2416
2932
|
/**
|
|
2417
|
-
*
|
|
2418
|
-
* @
|
|
2419
|
-
* @param {string} event - The event to bind to the channel.
|
|
2420
|
-
* @param {(data: Record<string, unknown>) => void} fn - The callback function to execute when the event is triggered.
|
|
2421
|
-
* @returns {PusherClient} The Pusher client instance.
|
|
2933
|
+
* Get the SDK realtime credentials
|
|
2934
|
+
* @returns {SDKRealtimeCredentialsResponse} The SDK realtime credentials
|
|
2422
2935
|
*/
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2936
|
+
async getSDKRealtimeCredentials() {
|
|
2937
|
+
const response = await this.client.request({
|
|
2938
|
+
method: "get",
|
|
2939
|
+
path: SDK_REALTIME_CREDENTIALS_ENDPOINT
|
|
2940
|
+
});
|
|
2941
|
+
const parsedResponse = SDKRealtimeCredentialsResponseSchema.safeParse({
|
|
2942
|
+
pusherKey: response.pusher_key,
|
|
2943
|
+
projectId: response.project_id,
|
|
2944
|
+
pusherCluster: response.pusher_cluster
|
|
2945
|
+
});
|
|
2946
|
+
logger_default.debug(
|
|
2947
|
+
`[InternalService] SDK realtime credentials: ${JSON.stringify(parsedResponse, null, 2)}`
|
|
2948
|
+
);
|
|
2949
|
+
if (!parsedResponse.success) {
|
|
2950
|
+
throw new ValidationError(`Failed to parse SDK realtime credentials`, {
|
|
2951
|
+
cause: parsedResponse.error
|
|
2952
|
+
});
|
|
2430
2953
|
}
|
|
2954
|
+
return parsedResponse.data;
|
|
2431
2955
|
}
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2956
|
+
};
|
|
2957
|
+
|
|
2958
|
+
// src/errors/TriggerErrors.ts
|
|
2959
|
+
import { ComposioError as ComposioError2 } from "@composio/client";
|
|
2960
|
+
var TriggerErrorCodes = {
|
|
2961
|
+
TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS: "TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS",
|
|
2962
|
+
TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT: "TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT",
|
|
2963
|
+
TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL",
|
|
2964
|
+
TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL"
|
|
2965
|
+
};
|
|
2966
|
+
var ComposioFailedToGetSDKRealtimeCredentialsError = class extends ComposioError2 {
|
|
2967
|
+
name = "ComposioFailedToGetSDKRealtimeCredentialsError";
|
|
2968
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS;
|
|
2969
|
+
statusCode = 500;
|
|
2970
|
+
possibleFixes = ["Please contact support."];
|
|
2971
|
+
constructor(message, options) {
|
|
2972
|
+
super(message, options);
|
|
2973
|
+
}
|
|
2974
|
+
};
|
|
2975
|
+
var ComposioFailedToCreatePusherClientError = class extends ComposioError2 {
|
|
2976
|
+
name = "ComposioFailedToCreatePusherClientError";
|
|
2977
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT;
|
|
2978
|
+
statusCode = 500;
|
|
2979
|
+
possibleFixes = ["Please contact support."];
|
|
2980
|
+
constructor(message, options) {
|
|
2981
|
+
super(message, options);
|
|
2982
|
+
}
|
|
2983
|
+
};
|
|
2984
|
+
var ComposioFailedToSubscribeToPusherChannelError = class extends ComposioError2 {
|
|
2985
|
+
name = "ComposioFailedToSubscribeToPusherChannelError";
|
|
2986
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL;
|
|
2987
|
+
statusCode = 500;
|
|
2988
|
+
possibleFixes = ["Please contact support."];
|
|
2989
|
+
constructor(message, options) {
|
|
2990
|
+
super(message, options);
|
|
2991
|
+
}
|
|
2992
|
+
};
|
|
2993
|
+
|
|
2994
|
+
// src/services/pusher/Pusher.ts
|
|
2995
|
+
var PusherService = class {
|
|
2996
|
+
// these values are set via the Apollo API `/internal/sdk/realtime/credentials` endpoint
|
|
2997
|
+
clientId;
|
|
2998
|
+
pusherKey;
|
|
2999
|
+
pusherCluster;
|
|
3000
|
+
pusherChannel;
|
|
3001
|
+
// these details are set via the client SDK
|
|
3002
|
+
pusherBaseURL;
|
|
3003
|
+
apiKey;
|
|
3004
|
+
pusherClient;
|
|
3005
|
+
composioClient;
|
|
3006
|
+
constructor(client) {
|
|
3007
|
+
this.composioClient = client;
|
|
3008
|
+
this.pusherBaseURL = client.baseURL;
|
|
3009
|
+
this.apiKey = client.apiKey ?? process.env.COMPOSIO_API_KEY ?? "";
|
|
3010
|
+
telemetry.instrument(this);
|
|
2439
3011
|
}
|
|
2440
3012
|
/**
|
|
2441
|
-
*
|
|
2442
|
-
*
|
|
2443
|
-
*
|
|
2444
|
-
*
|
|
3013
|
+
* Creates a Pusher client
|
|
3014
|
+
*
|
|
3015
|
+
* This method is called when the Pusher client is first used.
|
|
3016
|
+
* It will fetch the SDK realtime credentials from the Apollo API and create a Pusher client.
|
|
2445
3017
|
*/
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
3018
|
+
async getPusherClient() {
|
|
3019
|
+
if (!this.pusherClient) {
|
|
3020
|
+
const internalService = new InternalService(this.composioClient);
|
|
3021
|
+
let sdkRealtimeCredentials;
|
|
3022
|
+
try {
|
|
3023
|
+
sdkRealtimeCredentials = await internalService.getSDKRealtimeCredentials();
|
|
3024
|
+
} catch (error) {
|
|
3025
|
+
throw new ComposioFailedToGetSDKRealtimeCredentialsError(
|
|
3026
|
+
"Failed to get SDK realtime credentials",
|
|
3027
|
+
{
|
|
3028
|
+
cause: error
|
|
3029
|
+
}
|
|
3030
|
+
);
|
|
2453
3031
|
}
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
3032
|
+
this.clientId = sdkRealtimeCredentials.projectId;
|
|
3033
|
+
this.pusherKey = sdkRealtimeCredentials.pusherKey;
|
|
3034
|
+
this.pusherCluster = sdkRealtimeCredentials.pusherCluster;
|
|
3035
|
+
this.pusherChannel = `private-${this.clientId}_triggers`;
|
|
3036
|
+
logger_default.debug(
|
|
3037
|
+
`[PusherService] Creating Pusher client for client ID: ${this.clientId} in cluster ${this.pusherCluster}`
|
|
3038
|
+
);
|
|
3039
|
+
try {
|
|
3040
|
+
const { default: Pusher } = await import("pusher-js");
|
|
3041
|
+
this.pusherClient = new Pusher(this.pusherKey, {
|
|
3042
|
+
cluster: this.pusherCluster,
|
|
3043
|
+
channelAuthorization: {
|
|
3044
|
+
endpoint: `${this.pusherBaseURL}/api/v3/internal/sdk/realtime/auth`,
|
|
3045
|
+
headers: {
|
|
3046
|
+
"x-api-key": this.apiKey
|
|
3047
|
+
},
|
|
3048
|
+
transport: "ajax"
|
|
3049
|
+
}
|
|
3050
|
+
});
|
|
3051
|
+
} catch (error) {
|
|
3052
|
+
throw new ComposioFailedToCreatePusherClientError("Failed to create Pusher client", {
|
|
3053
|
+
cause: error
|
|
3054
|
+
});
|
|
2460
3055
|
}
|
|
2461
|
-
}
|
|
3056
|
+
}
|
|
3057
|
+
return this.pusherClient;
|
|
2462
3058
|
}
|
|
2463
3059
|
/**
|
|
2464
|
-
*
|
|
2465
|
-
*
|
|
2466
|
-
*
|
|
3060
|
+
* Binds a chunked event to a Pusher client
|
|
3061
|
+
*
|
|
3062
|
+
*
|
|
3063
|
+
* @param channel - The Pusher client to bind the event to
|
|
3064
|
+
* @param event - The event to bind to
|
|
3065
|
+
* @param callback - The function to call when the event is received
|
|
2467
3066
|
*/
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
3067
|
+
bindWithChunking(channel, event, callback) {
|
|
3068
|
+
try {
|
|
3069
|
+
channel.bind(event, callback);
|
|
3070
|
+
const events = {};
|
|
3071
|
+
channel.bind("chunked-" + event, (data) => {
|
|
3072
|
+
try {
|
|
3073
|
+
const typedData = data;
|
|
3074
|
+
if (!typedData || typeof typedData.id !== "string" || typeof typedData.index !== "number") {
|
|
3075
|
+
throw new Error("Invalid chunked trigger data format");
|
|
3076
|
+
}
|
|
3077
|
+
if (!events.hasOwnProperty(typedData.id)) {
|
|
3078
|
+
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
3079
|
+
}
|
|
3080
|
+
const ev = events[typedData.id];
|
|
3081
|
+
ev.chunks[typedData.index] = typedData.chunk;
|
|
3082
|
+
if (typedData.final) ev.receivedFinal = true;
|
|
3083
|
+
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
3084
|
+
try {
|
|
3085
|
+
const parsedData = JSON.parse(ev.chunks.join(""));
|
|
3086
|
+
callback(parsedData);
|
|
3087
|
+
} catch (parseError) {
|
|
3088
|
+
const errorMessage = parseError instanceof Error ? parseError.message : String(parseError);
|
|
3089
|
+
logger_default.error("Failed to parse chunked data:", errorMessage);
|
|
3090
|
+
} finally {
|
|
3091
|
+
delete events[typedData.id];
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
} catch (error) {
|
|
3095
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3096
|
+
logger_default.error("Error processing chunked trigger data:", errorMessage);
|
|
3097
|
+
if (data && typeof data === "object" && "id" in data) {
|
|
3098
|
+
delete events[data.id];
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
});
|
|
3102
|
+
} catch (error) {
|
|
3103
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3104
|
+
logger_default.error("Failed to bind chunked events:", error);
|
|
3105
|
+
throw new Error(`Failed to bind chunked events: ${errorMessage}`);
|
|
3106
|
+
}
|
|
2483
3107
|
}
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
3108
|
+
/**
|
|
3109
|
+
* Subscribes to pusher to receive events from the server
|
|
3110
|
+
*
|
|
3111
|
+
* This method is used to subscribe to a Pusher channel.
|
|
3112
|
+
* It will create a Pusher client if it doesn't exist.
|
|
3113
|
+
*
|
|
3114
|
+
* @param channelName - The name of the Pusher channel to subscribe to
|
|
3115
|
+
* @param event - The event to subscribe to
|
|
3116
|
+
* @param fn - The function to call when the event is received
|
|
3117
|
+
*/
|
|
3118
|
+
async subscribe(fn) {
|
|
3119
|
+
try {
|
|
3120
|
+
logger_default.debug(`[PusherService] Subscribing to channel: ${this.pusherChannel}`);
|
|
3121
|
+
const pusherClient = await this.getPusherClient();
|
|
3122
|
+
const channel = await pusherClient.subscribe(this.pusherChannel);
|
|
3123
|
+
channel.bind("pusher:subscription_error", (data) => {
|
|
3124
|
+
const error = data.error ? String(data.error) : "Unknown subscription error";
|
|
3125
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3126
|
+
`Trigger subscription error: ${error}`,
|
|
3127
|
+
{
|
|
3128
|
+
cause: error
|
|
3129
|
+
}
|
|
3130
|
+
);
|
|
3131
|
+
});
|
|
3132
|
+
const safeCallback = (data) => {
|
|
3133
|
+
try {
|
|
3134
|
+
fn(data);
|
|
3135
|
+
} catch (error) {
|
|
3136
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3137
|
+
logger_default.error("\u274C Error in trigger callback:", errorMessage);
|
|
3138
|
+
}
|
|
3139
|
+
};
|
|
3140
|
+
this.bindWithChunking(channel, "trigger_to_client", safeCallback);
|
|
3141
|
+
logger_default.info(`\u2705 Subscribed to triggers. You should start receiving events now.`);
|
|
3142
|
+
} catch (error) {
|
|
3143
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3144
|
+
"Failed to subscribe to Pusher channel",
|
|
3145
|
+
{
|
|
3146
|
+
cause: error
|
|
3147
|
+
}
|
|
3148
|
+
);
|
|
3149
|
+
}
|
|
2492
3150
|
}
|
|
2493
3151
|
/**
|
|
2494
|
-
*
|
|
2495
|
-
*
|
|
3152
|
+
* Unsubscribes from a Pusher channel
|
|
3153
|
+
*
|
|
3154
|
+
* This method is used to unsubscribe from a Pusher channel.
|
|
3155
|
+
* It will create a Pusher client if it doesn't exist.
|
|
3156
|
+
*
|
|
3157
|
+
* @param channelName - The name of the Pusher channel to unsubscribe from
|
|
2496
3158
|
*/
|
|
2497
|
-
async
|
|
2498
|
-
|
|
3159
|
+
async unsubscribe() {
|
|
3160
|
+
try {
|
|
3161
|
+
logger_default.debug(`[PusherService] Unsubscribing from channel: ${this.pusherChannel}`);
|
|
3162
|
+
const pusherClient = await this.getPusherClient();
|
|
3163
|
+
await pusherClient.unsubscribe(this.pusherChannel);
|
|
3164
|
+
logger_default.info(`\u2705 Unsubscribed from triggers.`);
|
|
3165
|
+
} catch (error) {
|
|
3166
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3167
|
+
"Failed to unsubscribe from Pusher channel",
|
|
3168
|
+
{
|
|
3169
|
+
cause: error
|
|
3170
|
+
}
|
|
3171
|
+
);
|
|
3172
|
+
}
|
|
2499
3173
|
}
|
|
2500
3174
|
};
|
|
2501
3175
|
|
|
2502
3176
|
// src/models/Triggers.ts
|
|
2503
3177
|
var Triggers = class {
|
|
2504
3178
|
client;
|
|
3179
|
+
pusherService;
|
|
2505
3180
|
constructor(client) {
|
|
2506
3181
|
this.client = client;
|
|
3182
|
+
this.pusherService = new PusherService(client);
|
|
2507
3183
|
telemetry.instrument(this);
|
|
2508
3184
|
}
|
|
3185
|
+
/**
|
|
3186
|
+
* Parse the trigger instance list active item
|
|
3187
|
+
*
|
|
3188
|
+
* @param response - The response from the composio client
|
|
3189
|
+
* @returns The parsed trigger instance list active item
|
|
3190
|
+
*/
|
|
3191
|
+
parseTriggerInstanceListActiveItem(response) {
|
|
3192
|
+
const parsed = TriggerInstanceListActiveResponseItemSchema.safeParse({
|
|
3193
|
+
id: response.id,
|
|
3194
|
+
connectedAccountId: response.connected_account_id,
|
|
3195
|
+
disabledAt: response.disabled_at,
|
|
3196
|
+
state: response.state,
|
|
3197
|
+
triggerConfig: response.trigger_config,
|
|
3198
|
+
triggerName: response.trigger_name,
|
|
3199
|
+
updatedAt: response.updated_at,
|
|
3200
|
+
triggerData: response.trigger_data,
|
|
3201
|
+
uuid: response.uuid
|
|
3202
|
+
});
|
|
3203
|
+
if (!parsed.success) {
|
|
3204
|
+
throw new ValidationError(`Invalid trigger instance list active item`, {
|
|
3205
|
+
cause: parsed.error
|
|
3206
|
+
});
|
|
3207
|
+
}
|
|
3208
|
+
return parsed.data;
|
|
3209
|
+
}
|
|
2509
3210
|
/**
|
|
2510
3211
|
* Fetch list of all the active triggers
|
|
2511
|
-
*
|
|
3212
|
+
*
|
|
3213
|
+
* @param {TriggerInstanceListActiveParams} query - The query parameters to filter the trigger instances
|
|
3214
|
+
* @returns {Promise<TriggerInstanceListActiveResponse>} List of trigger instances
|
|
3215
|
+
*
|
|
3216
|
+
* @throws {ValidationError} If the parameters are invalid
|
|
3217
|
+
* @throws {Error} If the client is not authenticated
|
|
3218
|
+
*
|
|
3219
|
+
* @example
|
|
3220
|
+
* ```ts
|
|
3221
|
+
* const triggers = await triggers.listActive({
|
|
3222
|
+
* authConfigIds: ['123'],
|
|
3223
|
+
* connectedAccountIds: ['456'],
|
|
3224
|
+
* });
|
|
3225
|
+
* ```
|
|
2512
3226
|
*/
|
|
2513
|
-
async
|
|
2514
|
-
|
|
3227
|
+
async listActive(query) {
|
|
3228
|
+
const parsedParams = TriggerInstanceListActiveParamsSchema.safeParse(query ?? {});
|
|
3229
|
+
if (!parsedParams.success) {
|
|
3230
|
+
throw new ValidationError(`Invalid parameters passed to list triggers`, {
|
|
3231
|
+
cause: parsedParams.error
|
|
3232
|
+
});
|
|
3233
|
+
}
|
|
3234
|
+
const result = await this.client.triggerInstances.listActive(
|
|
3235
|
+
query ? {
|
|
3236
|
+
auth_config_ids: parsedParams.data.authConfigIds,
|
|
3237
|
+
connected_account_ids: parsedParams.data.connectedAccountIds,
|
|
3238
|
+
limit: parsedParams.data.limit,
|
|
3239
|
+
page: parsedParams.data.page,
|
|
3240
|
+
show_disabled: parsedParams.data.showDisabled,
|
|
3241
|
+
trigger_ids: parsedParams.data.triggerIds,
|
|
3242
|
+
trigger_names: parsedParams.data.triggerNames
|
|
3243
|
+
} : void 0
|
|
3244
|
+
);
|
|
3245
|
+
const parsedResult = TriggerInstanceListActiveResponseSchema.safeParse({
|
|
3246
|
+
items: result.items.map((item) => this.parseTriggerInstanceListActiveItem(item)),
|
|
3247
|
+
nextCursor: result.next_cursor,
|
|
3248
|
+
totalPages: result.total_pages
|
|
3249
|
+
});
|
|
3250
|
+
if (!parsedResult.success) {
|
|
3251
|
+
throw new ValidationError(`Invalid trigger instance list active response`, {
|
|
3252
|
+
cause: parsedResult.error
|
|
3253
|
+
});
|
|
3254
|
+
}
|
|
3255
|
+
return parsedResult.data;
|
|
2515
3256
|
}
|
|
2516
3257
|
/**
|
|
2517
3258
|
* Create a new trigger instance
|
|
@@ -2520,58 +3261,76 @@ var Triggers = class {
|
|
|
2520
3261
|
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
2521
3262
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
2522
3263
|
*/
|
|
2523
|
-
async create(slug, body
|
|
2524
|
-
|
|
3264
|
+
async create(slug, body) {
|
|
3265
|
+
const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body);
|
|
3266
|
+
if (!parsedBody.success) {
|
|
3267
|
+
throw new ValidationError(`Invalid parameters passed to create trigger`, {
|
|
3268
|
+
cause: parsedBody.error
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
const result = await this.client.triggerInstances.upsert(slug, {
|
|
3272
|
+
connected_account_id: parsedBody.data.connectedAccountId,
|
|
3273
|
+
trigger_config: parsedBody.data.triggerConfig
|
|
3274
|
+
});
|
|
3275
|
+
const parsedResult = TriggerInstanceUpsertResponseSchema.safeParse({
|
|
3276
|
+
triggerId: result.trigger_id
|
|
3277
|
+
});
|
|
3278
|
+
if (!parsedResult.success) {
|
|
3279
|
+
throw new ValidationError(`Invalid trigger instance upsert response`, {
|
|
3280
|
+
cause: parsedResult.error
|
|
3281
|
+
});
|
|
3282
|
+
}
|
|
3283
|
+
return parsedResult.data;
|
|
2525
3284
|
}
|
|
2526
3285
|
/**
|
|
2527
3286
|
* Update an existing trigger instance
|
|
2528
3287
|
*
|
|
2529
3288
|
* @param {string} slug - The slug of the trigger instance
|
|
2530
|
-
* @param {
|
|
3289
|
+
* @param {TriggerInstanceManageUpdateParams} body - The parameters to create the trigger instance
|
|
2531
3290
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2532
3291
|
*/
|
|
2533
|
-
async update(slug, body
|
|
2534
|
-
return this.client.triggerInstances.
|
|
3292
|
+
async update(slug, body) {
|
|
3293
|
+
return this.client.triggerInstances.manage.update(slug, body);
|
|
2535
3294
|
}
|
|
2536
3295
|
/**
|
|
2537
3296
|
* Delete a trigger instance
|
|
2538
3297
|
*
|
|
2539
|
-
* @param {string}
|
|
3298
|
+
* @param {string} triggerId - The slug of the trigger instance
|
|
2540
3299
|
* @returns
|
|
2541
3300
|
*/
|
|
2542
|
-
async delete(
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
async updateStatus(status, params, options) {
|
|
2554
|
-
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
3301
|
+
async delete(triggerId) {
|
|
3302
|
+
const result = await this.client.triggerInstances.manage.delete(triggerId);
|
|
3303
|
+
const parsedResult = TriggerInstanceManageDeleteResponseSchema.safeParse({
|
|
3304
|
+
triggerId: result.trigger_id
|
|
3305
|
+
});
|
|
3306
|
+
if (!parsedResult.success) {
|
|
3307
|
+
throw new ValidationError(`Invalid trigger instance manage delete response`, {
|
|
3308
|
+
cause: parsedResult.error
|
|
3309
|
+
});
|
|
3310
|
+
}
|
|
3311
|
+
return parsedResult.data;
|
|
2555
3312
|
}
|
|
2556
3313
|
/**
|
|
2557
3314
|
* Disable a trigger instance
|
|
2558
3315
|
*
|
|
2559
|
-
* @param {string}
|
|
2560
|
-
* @param {RequestOptions options - Request options
|
|
3316
|
+
* @param {string} triggerId - The id of the trigger instance
|
|
2561
3317
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2562
3318
|
*/
|
|
2563
|
-
async disable(
|
|
2564
|
-
return this.client.triggerInstances.
|
|
3319
|
+
async disable(triggerId) {
|
|
3320
|
+
return this.client.triggerInstances.manage.update(triggerId, {
|
|
3321
|
+
status: "disable"
|
|
3322
|
+
});
|
|
2565
3323
|
}
|
|
2566
3324
|
/**
|
|
2567
3325
|
* Enable a trigger instance
|
|
2568
3326
|
*
|
|
2569
|
-
* @param {string}
|
|
2570
|
-
* @param {RequestOptions options - Request options
|
|
3327
|
+
* @param {string} triggerId - The id of the trigger instance
|
|
2571
3328
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2572
3329
|
*/
|
|
2573
|
-
async enable(
|
|
2574
|
-
return this.client.triggerInstances.
|
|
3330
|
+
async enable(triggerId) {
|
|
3331
|
+
return this.client.triggerInstances.manage.update(triggerId, {
|
|
3332
|
+
status: "enable"
|
|
3333
|
+
});
|
|
2575
3334
|
}
|
|
2576
3335
|
/**
|
|
2577
3336
|
* @TODO Learn about trigger types
|
|
@@ -2583,8 +3342,8 @@ var Triggers = class {
|
|
|
2583
3342
|
* @param {RequestOptions} options - Request options
|
|
2584
3343
|
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
|
|
2585
3344
|
*/
|
|
2586
|
-
async listTypes(query
|
|
2587
|
-
return this.client.triggersTypes.list(query
|
|
3345
|
+
async listTypes(query) {
|
|
3346
|
+
return this.client.triggersTypes.list(query);
|
|
2588
3347
|
}
|
|
2589
3348
|
/**
|
|
2590
3349
|
* Retrieve a trigger type by its slug
|
|
@@ -2593,8 +3352,8 @@ var Triggers = class {
|
|
|
2593
3352
|
* @param {RequestOptions} options - request options
|
|
2594
3353
|
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
2595
3354
|
*/
|
|
2596
|
-
async getType(slug
|
|
2597
|
-
return this.client.triggersTypes.retrieve(slug
|
|
3355
|
+
async getType(slug) {
|
|
3356
|
+
return this.client.triggersTypes.retrieve(slug);
|
|
2598
3357
|
}
|
|
2599
3358
|
/**
|
|
2600
3359
|
* Fetches the list of all the available trigger enums
|
|
@@ -2603,36 +3362,137 @@ var Triggers = class {
|
|
|
2603
3362
|
* @param options
|
|
2604
3363
|
* @returns
|
|
2605
3364
|
*/
|
|
2606
|
-
async listEnum(
|
|
2607
|
-
return this.client.triggersTypes.retrieveEnum(
|
|
3365
|
+
async listEnum() {
|
|
3366
|
+
return this.client.triggersTypes.retrieveEnum();
|
|
2608
3367
|
}
|
|
3368
|
+
/**
|
|
3369
|
+
* Subscribe to all the triggers
|
|
3370
|
+
*
|
|
3371
|
+
* @param fn - The function to call when a trigger is received
|
|
3372
|
+
* @param filters - The filters to apply to the triggers
|
|
3373
|
+
*
|
|
3374
|
+
* @example
|
|
3375
|
+
* ```ts
|
|
3376
|
+
*
|
|
3377
|
+
* triggers.subscribe((data) => {
|
|
3378
|
+
* console.log(data);
|
|
3379
|
+
* }, );
|
|
3380
|
+
* ```
|
|
3381
|
+
*/
|
|
2609
3382
|
async subscribe(fn, filters = {}) {
|
|
2610
3383
|
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
2611
|
-
const
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
const
|
|
2618
|
-
if (
|
|
2619
|
-
|
|
2620
|
-
|
|
3384
|
+
const parsedFilters = TriggerSubscribeParamSchema.safeParse(filters);
|
|
3385
|
+
if (!parsedFilters.success) {
|
|
3386
|
+
throw new ValidationError(`Invalid parameters passed to subscribe to triggers`, {
|
|
3387
|
+
cause: parsedFilters.error
|
|
3388
|
+
});
|
|
3389
|
+
}
|
|
3390
|
+
const shouldSendTriggerAfterFilters = (data) => {
|
|
3391
|
+
if (parsedFilters.data.toolkits?.length && !parsedFilters.data.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
|
|
3392
|
+
logger_default.debug(
|
|
3393
|
+
"Trigger does not match toolkits filter",
|
|
3394
|
+
JSON.stringify(parsedFilters.data.toolkits, null, 2)
|
|
3395
|
+
);
|
|
3396
|
+
return false;
|
|
3397
|
+
}
|
|
3398
|
+
if (parsedFilters.data.triggerId && parsedFilters.data.triggerId !== data.id) {
|
|
3399
|
+
logger_default.debug(
|
|
3400
|
+
"Trigger does not match triggerId filter",
|
|
3401
|
+
JSON.stringify(parsedFilters.data.triggerId, null, 2)
|
|
3402
|
+
);
|
|
3403
|
+
return false;
|
|
3404
|
+
}
|
|
3405
|
+
if (parsedFilters.data.connectedAccountId && parsedFilters.data.connectedAccountId !== data.metadata.connectedAccount.id) {
|
|
3406
|
+
logger_default.debug(
|
|
3407
|
+
"Trigger does not match connectedAccountId filter",
|
|
3408
|
+
JSON.stringify(parsedFilters.data.connectedAccountId, null, 2)
|
|
3409
|
+
);
|
|
3410
|
+
return false;
|
|
3411
|
+
}
|
|
3412
|
+
if (parsedFilters.data.triggerSlug?.length && !parsedFilters.data.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
|
|
3413
|
+
logger_default.debug(
|
|
3414
|
+
"Trigger does not match triggerSlug filter",
|
|
3415
|
+
JSON.stringify(parsedFilters.data.triggerSlug, null, 2)
|
|
3416
|
+
);
|
|
3417
|
+
return false;
|
|
2621
3418
|
}
|
|
3419
|
+
if (parsedFilters.data.triggerData && parsedFilters.data.triggerData !== data.metadata.triggerData) {
|
|
3420
|
+
logger_default.debug(
|
|
3421
|
+
"Trigger does not match triggerData filter",
|
|
3422
|
+
JSON.stringify(parsedFilters.data.triggerData, null, 2)
|
|
3423
|
+
);
|
|
3424
|
+
return false;
|
|
3425
|
+
}
|
|
3426
|
+
if (parsedFilters.data.userId && parsedFilters.data.userId !== data.metadata.connectedAccount.userId) {
|
|
3427
|
+
logger_default.debug(
|
|
3428
|
+
"Trigger does not match userId filter",
|
|
3429
|
+
JSON.stringify(parsedFilters.data.userId, null, 2)
|
|
3430
|
+
);
|
|
3431
|
+
return false;
|
|
3432
|
+
}
|
|
3433
|
+
logger_default.debug("Trigger matches all filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
3434
|
+
return true;
|
|
2622
3435
|
};
|
|
2623
|
-
logger_default.debug("Subscribing to triggers", filters);
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
3436
|
+
logger_default.debug("\u{1F504} Subscribing to triggers with filters: ", JSON.stringify(filters, null, 2));
|
|
3437
|
+
await this.pusherService.subscribe((_data) => {
|
|
3438
|
+
logger_default.debug("Received raw trigger data", JSON.stringify(_data, null, 2));
|
|
3439
|
+
const data = _data;
|
|
3440
|
+
const parsedData = IncomingTriggerPayloadSchema.safeParse({
|
|
3441
|
+
id: data.metadata.id,
|
|
3442
|
+
triggerSlug: data.metadata.triggerName,
|
|
3443
|
+
toolkitSlug: data.appName,
|
|
3444
|
+
userId: data.metadata.connection?.clientUniqueUserId,
|
|
3445
|
+
payload: data.payload,
|
|
3446
|
+
originalPayload: data.originalPayload,
|
|
3447
|
+
metadata: {
|
|
3448
|
+
id: data.metadata.id,
|
|
3449
|
+
triggerConfig: data.metadata.triggerConfig,
|
|
3450
|
+
triggerSlug: data.metadata.triggerName,
|
|
3451
|
+
toolkitSlug: data.appName,
|
|
3452
|
+
triggerData: data.metadata.triggerData,
|
|
3453
|
+
connectedAccount: {
|
|
3454
|
+
id: data.metadata.connection?.connectedAccountNanoId,
|
|
3455
|
+
uuid: data.metadata.connection?.id,
|
|
3456
|
+
authConfigId: data.metadata.connection?.authConfigNanoId,
|
|
3457
|
+
authConfigUUID: data.metadata.connection?.integrationId,
|
|
3458
|
+
userId: data.metadata.connection?.clientUniqueUserId,
|
|
3459
|
+
status: data.metadata.connection?.status
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
});
|
|
3463
|
+
logger_default.debug("Parsed trigger data", JSON.stringify(parsedData.data, null, 2));
|
|
3464
|
+
if (parsedData.error) {
|
|
3465
|
+
throw new ValidationError(`Invalid trigger payload`, {
|
|
3466
|
+
cause: parsedData.error
|
|
3467
|
+
});
|
|
3468
|
+
}
|
|
3469
|
+
if (shouldSendTriggerAfterFilters(parsedData.data)) {
|
|
3470
|
+
try {
|
|
3471
|
+
fn(parsedData.data);
|
|
3472
|
+
} catch (error) {
|
|
3473
|
+
logger_default.error("\u274C Error in trigger callback:", error);
|
|
3474
|
+
}
|
|
3475
|
+
} else {
|
|
3476
|
+
logger_default.debug("Trigger does not match filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
2627
3477
|
}
|
|
2628
3478
|
});
|
|
2629
3479
|
}
|
|
3480
|
+
/**
|
|
3481
|
+
* Unsubscribe from all the triggers
|
|
3482
|
+
*
|
|
3483
|
+
* @returns {Promise<void>}
|
|
3484
|
+
*
|
|
3485
|
+
* @example
|
|
3486
|
+
* ```ts
|
|
3487
|
+
* composio.trigger.subscribe((data) => {
|
|
3488
|
+
* console.log(data);
|
|
3489
|
+
* });
|
|
3490
|
+
*
|
|
3491
|
+
* await triggers.unsubscribe();
|
|
3492
|
+
* ```
|
|
3493
|
+
*/
|
|
2630
3494
|
async unsubscribe() {
|
|
2631
|
-
|
|
2632
|
-
const sessionInfo = await session.getInfo();
|
|
2633
|
-
const clientId = sessionInfo.project?.id;
|
|
2634
|
-
if (!clientId) throw new Error("Client ID not found");
|
|
2635
|
-
PusherUtils.triggerUnsubscribe(clientId);
|
|
3495
|
+
await this.pusherService.unsubscribe();
|
|
2636
3496
|
}
|
|
2637
3497
|
};
|
|
2638
3498
|
|
|
@@ -2643,6 +3503,7 @@ var userDataPath = () => {
|
|
|
2643
3503
|
const os = __require("os");
|
|
2644
3504
|
return path.join(os.homedir(), COMPOSIO_DIR, USER_DATA_FILE_NAME);
|
|
2645
3505
|
} catch (_error) {
|
|
3506
|
+
logger_default.debug("Environment", `Unable to get user data path`);
|
|
2646
3507
|
return null;
|
|
2647
3508
|
}
|
|
2648
3509
|
};
|
|
@@ -2652,6 +3513,7 @@ var getUserDataJson = () => {
|
|
|
2652
3513
|
const data = fs.readFileSync(userDataPath(), "utf8");
|
|
2653
3514
|
return JSON.parse(data);
|
|
2654
3515
|
} catch (_error) {
|
|
3516
|
+
logger_default.debug("Environment", "No user data file found");
|
|
2655
3517
|
return {};
|
|
2656
3518
|
}
|
|
2657
3519
|
};
|
|
@@ -2660,6 +3522,13 @@ function getSDKConfig(baseUrl, apiKey) {
|
|
|
2660
3522
|
const { api_key: apiKeyFromUserConfig, base_url: baseURLFromUserConfig } = userData;
|
|
2661
3523
|
const baseURLParsed = baseUrl || getEnvVariable("COMPOSIO_BASE_URL") || baseURLFromUserConfig || DEFAULT_BASE_URL;
|
|
2662
3524
|
const apiKeyParsed = apiKey || getEnvVariable("COMPOSIO_API_KEY") || apiKeyFromUserConfig || "";
|
|
3525
|
+
if (!apiKeyParsed) {
|
|
3526
|
+
ComposioError.handle(new ComposioNoAPIKeyError(), {
|
|
3527
|
+
exitProcess: true
|
|
3528
|
+
});
|
|
3529
|
+
}
|
|
3530
|
+
logger_default.debug("Environment", `API Key: ${apiKeyParsed}`);
|
|
3531
|
+
logger_default.debug("Environment", `Base URL: ${baseURLParsed}`);
|
|
2663
3532
|
return { baseURL: baseURLParsed, apiKey: apiKeyParsed };
|
|
2664
3533
|
}
|
|
2665
3534
|
|
|
@@ -2706,7 +3575,7 @@ var BaseProvider = class {
|
|
|
2706
3575
|
}
|
|
2707
3576
|
/**
|
|
2708
3577
|
* @public
|
|
2709
|
-
*
|
|
3578
|
+
* Global function to execute a tool.
|
|
2710
3579
|
* This function is used by provider providers to implement helper functions to execute tools.
|
|
2711
3580
|
* This is a 1:1 mapping of the `execute` method in the `Tools` class.
|
|
2712
3581
|
* @param {string} toolSlug - The slug of the tool to execute.
|
|
@@ -2773,7 +3642,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2773
3642
|
* @param {string} userId - The user id.
|
|
2774
3643
|
* @returns {Promise<string[]>} The results of the tool call.
|
|
2775
3644
|
*/
|
|
2776
|
-
async
|
|
3645
|
+
async handleToolCalls(userId, chatCompletion, options, modifiers) {
|
|
2777
3646
|
const outputs = [];
|
|
2778
3647
|
for (const message of chatCompletion.choices) {
|
|
2779
3648
|
if (message.message.tool_calls) {
|
|
@@ -2893,13 +3762,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2893
3762
|
};
|
|
2894
3763
|
|
|
2895
3764
|
// package.json
|
|
2896
|
-
var version = "0.1.12-alpha.
|
|
2897
|
-
|
|
2898
|
-
// src/utils/uuid.ts
|
|
2899
|
-
import { v4 as uuidv4 } from "uuid";
|
|
2900
|
-
function getRandomUUID() {
|
|
2901
|
-
return uuidv4();
|
|
2902
|
-
}
|
|
3765
|
+
var version = "0.1.12-alpha.12";
|
|
2903
3766
|
|
|
2904
3767
|
// src/composio.ts
|
|
2905
3768
|
var Composio = class {
|
|
@@ -2939,18 +3802,18 @@ var Composio = class {
|
|
|
2939
3802
|
config?.apiKey
|
|
2940
3803
|
);
|
|
2941
3804
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
2942
|
-
logger_default.
|
|
3805
|
+
logger_default.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
2943
3806
|
}
|
|
2944
|
-
this.client = new
|
|
3807
|
+
this.client = new ComposioClient3({
|
|
2945
3808
|
apiKey: apiKeyParsed,
|
|
2946
3809
|
baseURL: baseURLParsed
|
|
2947
3810
|
});
|
|
2948
3811
|
this.config = {
|
|
2949
3812
|
...config,
|
|
2950
|
-
allowTracking: config
|
|
2951
|
-
allowTracing: config
|
|
3813
|
+
allowTracking: config?.allowTracking ?? true,
|
|
3814
|
+
allowTracing: config?.allowTracing ?? true
|
|
2952
3815
|
};
|
|
2953
|
-
this.provider = config
|
|
3816
|
+
this.provider = config?.provider ?? new OpenAIProvider();
|
|
2954
3817
|
this.tools = new Tools(this.client, this.provider);
|
|
2955
3818
|
this.toolkits = new Toolkits(this.client);
|
|
2956
3819
|
this.triggers = new Triggers(this.client);
|
|
@@ -2961,7 +3824,7 @@ var Composio = class {
|
|
|
2961
3824
|
{
|
|
2962
3825
|
apiKey: apiKeyParsed ?? "",
|
|
2963
3826
|
baseUrl: baseURLParsed ?? "",
|
|
2964
|
-
|
|
3827
|
+
frameworkRuntime: this.provider?.name ?? "unknown",
|
|
2965
3828
|
isAgentic: this.provider?._isAgentic || false,
|
|
2966
3829
|
source: "javascript",
|
|
2967
3830
|
version,
|
|
@@ -2972,7 +3835,7 @@ var Composio = class {
|
|
|
2972
3835
|
sessionId: this.config.allowTracing ? getRandomUUID() : void 0
|
|
2973
3836
|
// @TODO: get the session id
|
|
2974
3837
|
},
|
|
2975
|
-
config
|
|
3838
|
+
config?.telemetryTransport
|
|
2976
3839
|
);
|
|
2977
3840
|
}
|
|
2978
3841
|
telemetry.instrument(this);
|
|
@@ -3003,50 +3866,50 @@ var ComposioProvider = class extends BaseNonAgenticProvider {
|
|
|
3003
3866
|
};
|
|
3004
3867
|
|
|
3005
3868
|
// src/telemetry/TelemetryTransport.ts
|
|
3006
|
-
import
|
|
3869
|
+
import chalk4 from "chalk";
|
|
3007
3870
|
var BaseTelemetryTransport = class {
|
|
3008
3871
|
};
|
|
3009
3872
|
var ConsoleTelemetryTransport = class {
|
|
3010
3873
|
send(payload) {
|
|
3011
|
-
logger_default.debug(
|
|
3874
|
+
logger_default.debug(chalk4.yellow("telemetry"), JSON.stringify(payload, null, 2));
|
|
3012
3875
|
return Promise.resolve();
|
|
3013
3876
|
}
|
|
3014
3877
|
};
|
|
3015
3878
|
|
|
3016
3879
|
// src/utils/jsonSchema.ts
|
|
3017
|
-
import { z as
|
|
3880
|
+
import { z as z7 } from "zod";
|
|
3018
3881
|
function jsonSchemaPropertiesToTSTypes(value) {
|
|
3019
3882
|
if (!value.type) {
|
|
3020
|
-
return
|
|
3883
|
+
return z7.object({});
|
|
3021
3884
|
}
|
|
3022
3885
|
let zodType;
|
|
3023
3886
|
switch (value.type) {
|
|
3024
3887
|
case "string":
|
|
3025
|
-
zodType =
|
|
3888
|
+
zodType = z7.string().describe(
|
|
3026
3889
|
(value.description || "") + (value.examples ? `
|
|
3027
3890
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3028
3891
|
);
|
|
3029
3892
|
break;
|
|
3030
3893
|
case "number":
|
|
3031
|
-
zodType =
|
|
3894
|
+
zodType = z7.number().describe(
|
|
3032
3895
|
(value.description || "") + (value.examples ? `
|
|
3033
3896
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3034
3897
|
);
|
|
3035
3898
|
break;
|
|
3036
3899
|
case "integer":
|
|
3037
|
-
zodType =
|
|
3900
|
+
zodType = z7.number().int().describe(
|
|
3038
3901
|
(value.description || "") + (value.examples ? `
|
|
3039
3902
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3040
3903
|
);
|
|
3041
3904
|
break;
|
|
3042
3905
|
case "boolean":
|
|
3043
|
-
zodType =
|
|
3906
|
+
zodType = z7.boolean().describe(
|
|
3044
3907
|
(value.description || "") + (value.examples ? `
|
|
3045
3908
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3046
3909
|
);
|
|
3047
3910
|
break;
|
|
3048
3911
|
case "array":
|
|
3049
|
-
zodType =
|
|
3912
|
+
zodType = z7.array(
|
|
3050
3913
|
jsonSchemaPropertiesToTSTypes(
|
|
3051
3914
|
value.items
|
|
3052
3915
|
)
|
|
@@ -3056,24 +3919,24 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3056
3919
|
);
|
|
3057
3920
|
break;
|
|
3058
3921
|
case "object":
|
|
3059
|
-
zodType =
|
|
3922
|
+
zodType = jsonSchemaToZodSchema(value).describe(
|
|
3060
3923
|
(value.description || "") + (value.examples ? `
|
|
3061
3924
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3062
3925
|
);
|
|
3063
3926
|
break;
|
|
3064
3927
|
case "null":
|
|
3065
|
-
zodType =
|
|
3928
|
+
zodType = z7.null().describe(value.description || "");
|
|
3066
3929
|
break;
|
|
3067
3930
|
default:
|
|
3068
3931
|
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
3069
3932
|
}
|
|
3070
3933
|
return zodType;
|
|
3071
3934
|
}
|
|
3072
|
-
function
|
|
3935
|
+
function jsonSchemaToZodSchema(jsonSchema) {
|
|
3073
3936
|
const properties = jsonSchema.properties;
|
|
3074
3937
|
const requiredFields = jsonSchema.required || [];
|
|
3075
3938
|
if (!properties) {
|
|
3076
|
-
return
|
|
3939
|
+
return z7.object({});
|
|
3077
3940
|
}
|
|
3078
3941
|
const zodSchema = {};
|
|
3079
3942
|
for (const [key, _] of Object.entries(properties)) {
|
|
@@ -3085,7 +3948,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
3085
3948
|
schema
|
|
3086
3949
|
)
|
|
3087
3950
|
);
|
|
3088
|
-
zodType =
|
|
3951
|
+
zodType = z7.union(anyOfTypes).describe(
|
|
3089
3952
|
(value.description || "") + (value.examples ? `
|
|
3090
3953
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3091
3954
|
);
|
|
@@ -3095,7 +3958,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3095
3958
|
schema
|
|
3096
3959
|
)
|
|
3097
3960
|
);
|
|
3098
|
-
zodType =
|
|
3961
|
+
zodType = z7.intersection(
|
|
3099
3962
|
allOfTypes[0],
|
|
3100
3963
|
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
3101
3964
|
).describe(
|
|
@@ -3119,18 +3982,42 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3119
3982
|
zodSchema[key] = zodType.optional();
|
|
3120
3983
|
}
|
|
3121
3984
|
}
|
|
3122
|
-
return
|
|
3985
|
+
return z7.object(zodSchema);
|
|
3123
3986
|
}
|
|
3124
3987
|
export {
|
|
3988
|
+
AuthConfigErrorCodes,
|
|
3125
3989
|
AuthConfigTypes,
|
|
3126
3990
|
AuthSchemeTypes,
|
|
3127
3991
|
BaseAgenticProvider,
|
|
3128
3992
|
BaseNonAgenticProvider,
|
|
3129
3993
|
BaseTelemetryTransport,
|
|
3130
3994
|
Composio,
|
|
3995
|
+
ComposioAuthConfigNotFoundError,
|
|
3996
|
+
ComposioConnectedAccountNotFoundError,
|
|
3997
|
+
ComposioCustomToolsNotInitializedError,
|
|
3998
|
+
ComposioError,
|
|
3999
|
+
ComposioGlobalExecuteToolFnNotSetError,
|
|
4000
|
+
ComposioInvalidExecuteFunctionError,
|
|
4001
|
+
ComposioInvalidModifierError,
|
|
4002
|
+
ComposioNoAPIKeyError,
|
|
3131
4003
|
ComposioProvider,
|
|
4004
|
+
ComposioProviderNotDefinedError,
|
|
4005
|
+
ComposioToolExecutionError,
|
|
4006
|
+
ComposioToolNotFoundError,
|
|
4007
|
+
ComposioToolkitFetchError,
|
|
4008
|
+
ComposioToolkitNotFoundError,
|
|
4009
|
+
ConnectedAccountErrorCodes,
|
|
4010
|
+
ConnectionRequestErrorCodes,
|
|
4011
|
+
ConnectionRequestFailedError,
|
|
4012
|
+
ConnectionRequestTimeoutError,
|
|
3132
4013
|
ConsoleTelemetryTransport,
|
|
3133
4014
|
OpenAIProvider,
|
|
4015
|
+
SDKErrorCodes,
|
|
4016
|
+
ToolErrorCodes,
|
|
3134
4017
|
ToolListParamsSchema,
|
|
3135
|
-
|
|
4018
|
+
ToolkitErrorCodes,
|
|
4019
|
+
ValidationError,
|
|
4020
|
+
ValidationErrorCodes,
|
|
4021
|
+
jsonSchemaToZodSchema,
|
|
4022
|
+
logger_default as logger
|
|
3136
4023
|
};
|