@composio/core 0.1.12-alpha.0 → 0.1.12-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -7
- package/dist/index.cjs +1634 -767
- package/dist/index.d.cts +1146 -172
- package/dist/index.d.ts +1146 -172
- package/dist/index.js +1448 -605
- package/package.json +13 -12
- package/src/index.ts +0 -23
package/dist/index.cjs
CHANGED
|
@@ -30,21 +30,45 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
AuthConfigErrorCodes: () => AuthConfigErrorCodes,
|
|
33
34
|
AuthConfigTypes: () => AuthConfigTypes,
|
|
34
35
|
AuthSchemeTypes: () => AuthSchemeTypes,
|
|
35
36
|
BaseAgenticProvider: () => BaseAgenticProvider,
|
|
36
37
|
BaseNonAgenticProvider: () => BaseNonAgenticProvider,
|
|
37
38
|
BaseTelemetryTransport: () => BaseTelemetryTransport,
|
|
38
39
|
Composio: () => Composio,
|
|
40
|
+
ComposioAuthConfigNotFoundError: () => ComposioAuthConfigNotFoundError,
|
|
41
|
+
ComposioConnectedAccountNotFoundError: () => ComposioConnectedAccountNotFoundError,
|
|
42
|
+
ComposioCustomToolsNotInitializedError: () => ComposioCustomToolsNotInitializedError,
|
|
43
|
+
ComposioError: () => ComposioError,
|
|
44
|
+
ComposioGlobalExecuteToolFnNotSetError: () => ComposioGlobalExecuteToolFnNotSetError,
|
|
45
|
+
ComposioInvalidExecuteFunctionError: () => ComposioInvalidExecuteFunctionError,
|
|
46
|
+
ComposioInvalidModifierError: () => ComposioInvalidModifierError,
|
|
47
|
+
ComposioNoAPIKeyError: () => ComposioNoAPIKeyError,
|
|
39
48
|
ComposioProvider: () => ComposioProvider,
|
|
49
|
+
ComposioProviderNotDefinedError: () => ComposioProviderNotDefinedError,
|
|
50
|
+
ComposioToolExecutionError: () => ComposioToolExecutionError,
|
|
51
|
+
ComposioToolNotFoundError: () => ComposioToolNotFoundError,
|
|
52
|
+
ComposioToolkitFetchError: () => ComposioToolkitFetchError,
|
|
53
|
+
ComposioToolkitNotFoundError: () => ComposioToolkitNotFoundError,
|
|
54
|
+
ConnectedAccountErrorCodes: () => ConnectedAccountErrorCodes,
|
|
55
|
+
ConnectionRequestErrorCodes: () => ConnectionRequestErrorCodes,
|
|
56
|
+
ConnectionRequestFailedError: () => ConnectionRequestFailedError,
|
|
57
|
+
ConnectionRequestTimeoutError: () => ConnectionRequestTimeoutError,
|
|
58
|
+
ConsoleTelemetryTransport: () => ConsoleTelemetryTransport,
|
|
40
59
|
OpenAIProvider: () => OpenAIProvider,
|
|
60
|
+
SDKErrorCodes: () => SDKErrorCodes,
|
|
61
|
+
ToolErrorCodes: () => ToolErrorCodes,
|
|
41
62
|
ToolListParamsSchema: () => ToolListParamsSchema,
|
|
63
|
+
ToolkitErrorCodes: () => ToolkitErrorCodes,
|
|
64
|
+
ValidationError: () => ValidationError,
|
|
65
|
+
ValidationErrorCodes: () => ValidationErrorCodes,
|
|
42
66
|
jsonSchemaToModel: () => jsonSchemaToModel
|
|
43
67
|
});
|
|
44
68
|
module.exports = __toCommonJS(index_exports);
|
|
45
69
|
|
|
46
70
|
// src/composio.ts
|
|
47
|
-
var
|
|
71
|
+
var import_client5 = __toESM(require("@composio/client"), 1);
|
|
48
72
|
|
|
49
73
|
// src/types/tool.types.ts
|
|
50
74
|
var import_zod = require("zod");
|
|
@@ -107,12 +131,14 @@ var ToolExecuteResponseSchema = import_zod.z.object({
|
|
|
107
131
|
// src/models/CustomTools.ts
|
|
108
132
|
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"), 1);
|
|
109
133
|
|
|
134
|
+
// src/utils/logger.ts
|
|
135
|
+
var import_chalk = __toESM(require("chalk"), 1);
|
|
136
|
+
|
|
110
137
|
// src/utils/env.ts
|
|
111
138
|
var getEnvVariable = (name, defaultValue = void 0) => {
|
|
112
139
|
try {
|
|
113
140
|
return process.env[name] || defaultValue;
|
|
114
141
|
} catch (_e) {
|
|
115
|
-
logger_default.error(`Error getting environment variable ${name}:`, _e);
|
|
116
142
|
return defaultValue;
|
|
117
143
|
}
|
|
118
144
|
};
|
|
@@ -131,7 +157,7 @@ var LOG_LEVELS = {
|
|
|
131
157
|
// Debug information
|
|
132
158
|
};
|
|
133
159
|
var getLogLevel = () => {
|
|
134
|
-
const envLevel = getEnvVariable("
|
|
160
|
+
const envLevel = getEnvVariable("COMPOSIO_LOG_LEVEL", "info")?.toLowerCase();
|
|
135
161
|
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
136
162
|
};
|
|
137
163
|
var Logger = class {
|
|
@@ -144,12 +170,25 @@ var Logger = class {
|
|
|
144
170
|
this.console = console;
|
|
145
171
|
}
|
|
146
172
|
formatMessage(args) {
|
|
147
|
-
const formattedArgs = args.map((arg) =>
|
|
173
|
+
const formattedArgs = args.map((arg, index) => {
|
|
174
|
+
if (typeof arg === "object") {
|
|
175
|
+
return JSON.stringify(arg);
|
|
176
|
+
} else {
|
|
177
|
+
if (index === 0) {
|
|
178
|
+
if (args.length > 1) {
|
|
179
|
+
return import_chalk.default.yellow(`${arg}`);
|
|
180
|
+
} else {
|
|
181
|
+
return String(arg);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return String(arg);
|
|
185
|
+
}
|
|
186
|
+
}).join("\n");
|
|
148
187
|
if (!this.includeTimestamp) {
|
|
149
188
|
return formattedArgs;
|
|
150
189
|
}
|
|
151
190
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
152
|
-
return `${timestamp} - ${formattedArgs}`;
|
|
191
|
+
return `${import_chalk.default.gray(timestamp)} - ${formattedArgs}`;
|
|
153
192
|
}
|
|
154
193
|
shouldLog(level) {
|
|
155
194
|
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
@@ -179,34 +218,211 @@ var logger = new Logger();
|
|
|
179
218
|
var logger_default = logger;
|
|
180
219
|
|
|
181
220
|
// src/errors/ComposioError.ts
|
|
182
|
-
var
|
|
221
|
+
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
222
|
+
var import_zod2 = require("zod");
|
|
223
|
+
var import_client = require("@composio/client");
|
|
224
|
+
var ComposioError = class _ComposioError extends Error {
|
|
225
|
+
/** @readonly Error name */
|
|
183
226
|
name = "ComposioError";
|
|
184
227
|
code;
|
|
185
|
-
statusCode;
|
|
186
|
-
cause;
|
|
187
|
-
meta;
|
|
188
228
|
possibleFixes;
|
|
229
|
+
errorId;
|
|
230
|
+
/**
|
|
231
|
+
* Creates a new ComposioError
|
|
232
|
+
* @param message Error message
|
|
233
|
+
* @param options Additional error options
|
|
234
|
+
*/
|
|
189
235
|
constructor(message, options = {}) {
|
|
190
236
|
super(message);
|
|
191
|
-
|
|
192
|
-
this.
|
|
193
|
-
this.cause = options.cause;
|
|
194
|
-
this.meta = options.meta;
|
|
237
|
+
const statusCode = options.statusCode || (options.cause instanceof import_client.BadRequestError ? options.cause.status : void 0);
|
|
238
|
+
this.code = `TS-SDK::${options.code}`;
|
|
195
239
|
this.possibleFixes = options.possibleFixes;
|
|
240
|
+
this.definePropertyIfExists("statusCode", statusCode);
|
|
241
|
+
this.definePropertyIfExists("cause", options.cause);
|
|
242
|
+
this.definePropertyIfExists("stack", options.stack);
|
|
243
|
+
if (options.meta && Object.keys(options.meta).length > 0) {
|
|
244
|
+
this.definePropertyIfExists("meta", options.meta);
|
|
245
|
+
}
|
|
196
246
|
if (Error.captureStackTrace) {
|
|
197
247
|
Error.captureStackTrace(this, this.constructor);
|
|
198
248
|
}
|
|
199
249
|
}
|
|
200
|
-
|
|
201
|
-
|
|
250
|
+
/**
|
|
251
|
+
* Helper method to define a property only if it has a value
|
|
252
|
+
* @param propertyName Name of the property to define
|
|
253
|
+
* @param value Value to assign to the property
|
|
254
|
+
* @private
|
|
255
|
+
*/
|
|
256
|
+
definePropertyIfExists(propertyName, value) {
|
|
257
|
+
if (value !== void 0) {
|
|
258
|
+
Object.defineProperty(this, propertyName, {
|
|
259
|
+
value,
|
|
260
|
+
enumerable: true,
|
|
261
|
+
writable: false,
|
|
262
|
+
configurable: true
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Extract and normalize error data for formatting
|
|
268
|
+
* @param includeStack Whether to include stack trace information
|
|
269
|
+
* @returns Structured error data for formatting
|
|
270
|
+
* @private
|
|
271
|
+
*/
|
|
272
|
+
getErrorData(includeStack = false) {
|
|
273
|
+
const data = {
|
|
202
274
|
name: this.name,
|
|
203
|
-
message: this.message
|
|
204
|
-
code: this.code,
|
|
205
|
-
statusCode: this.statusCode,
|
|
206
|
-
cause: this.cause instanceof Error ? this.cause.message : this.cause,
|
|
207
|
-
meta: this.meta,
|
|
208
|
-
possibleFixes: this.possibleFixes?.length ? this.possibleFixes.join("\n") : void 0
|
|
275
|
+
message: this.message
|
|
209
276
|
};
|
|
277
|
+
const { cause, code, stack, statusCode, meta, possibleFixes } = this;
|
|
278
|
+
if (cause !== void 0) {
|
|
279
|
+
const rawCause = cause;
|
|
280
|
+
data.cause = rawCause instanceof Error ? rawCause.message : String(rawCause);
|
|
281
|
+
}
|
|
282
|
+
if (code) {
|
|
283
|
+
data.code = code;
|
|
284
|
+
}
|
|
285
|
+
if (statusCode !== void 0) {
|
|
286
|
+
data.statusCode = statusCode;
|
|
287
|
+
}
|
|
288
|
+
if (meta) {
|
|
289
|
+
data.meta = meta;
|
|
290
|
+
}
|
|
291
|
+
if (possibleFixes) {
|
|
292
|
+
data.possibleFixes = possibleFixes;
|
|
293
|
+
}
|
|
294
|
+
if (includeStack && stack) {
|
|
295
|
+
data.stack = stack.split("\n").slice(1);
|
|
296
|
+
}
|
|
297
|
+
return data;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Prints a user-friendly, colorful representation of the error to the logger
|
|
301
|
+
* @param includeStack Whether to include the stack trace in the output (default: false)
|
|
302
|
+
*/
|
|
303
|
+
prettyPrint(includeStack = false) {
|
|
304
|
+
const data = this.getErrorData(includeStack);
|
|
305
|
+
let output = "\n" + import_chalk2.default.bgRed.white.bold(" ERROR ") + " " + import_chalk2.default.white.bold(data.message) + "\n";
|
|
306
|
+
if (data.code) {
|
|
307
|
+
output += import_chalk2.default.yellow(`Error Code: ${data.code}`) + "\n";
|
|
308
|
+
}
|
|
309
|
+
if (data.statusCode !== void 0) {
|
|
310
|
+
output += import_chalk2.default.yellow(`Status: ${data.statusCode}`) + "\n";
|
|
311
|
+
}
|
|
312
|
+
if (data.cause) {
|
|
313
|
+
output += import_chalk2.default.gray("Reason:") + "\n";
|
|
314
|
+
output += " " + import_chalk2.default.white(data.cause) + "\n";
|
|
315
|
+
}
|
|
316
|
+
if (data.meta) {
|
|
317
|
+
output += import_chalk2.default.gray("Additional Information:") + "\n";
|
|
318
|
+
output += " " + import_chalk2.default.white(JSON.stringify(data.meta, null, 2).replace(/\n/g, "\n ")) + "\n";
|
|
319
|
+
}
|
|
320
|
+
if (data.possibleFixes?.length) {
|
|
321
|
+
output += "\n" + import_chalk2.default.cyan.bold("Try the following:") + "\n";
|
|
322
|
+
const fixes = data.possibleFixes?.map((fix, index) => ` ${index + 1}. ` + import_chalk2.default.white(fix));
|
|
323
|
+
output += fixes?.join("\n") + "\n";
|
|
324
|
+
}
|
|
325
|
+
if (data.stack?.length) {
|
|
326
|
+
output += "\n" + import_chalk2.default.gray("Stack Trace:") + "\n";
|
|
327
|
+
output += import_chalk2.default.gray(data.stack.join("\n")) + "\n";
|
|
328
|
+
}
|
|
329
|
+
output += "\n";
|
|
330
|
+
logger_default.error(output);
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Static factory method to create and pretty print an error in one step
|
|
334
|
+
* @param message Error message
|
|
335
|
+
* @param options Error options
|
|
336
|
+
* @param includeStack Whether to include the stack trace in the output
|
|
337
|
+
* @returns The created error instance
|
|
338
|
+
*/
|
|
339
|
+
static createAndPrint(message, options = {}, includeStack = false) {
|
|
340
|
+
const error = new _ComposioError(message, options);
|
|
341
|
+
error.prettyPrint(includeStack);
|
|
342
|
+
return error;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Utility function to handle errors in a consistent way
|
|
346
|
+
* This properly displays the error and exits the process if needed
|
|
347
|
+
* @param error The error to handle
|
|
348
|
+
* @param options Options for error handling
|
|
349
|
+
*/
|
|
350
|
+
static handle(error, options = {}) {
|
|
351
|
+
const { includeStack = false, exitProcess = false, exitCode = 1 } = options;
|
|
352
|
+
if (error instanceof _ComposioError) {
|
|
353
|
+
error.prettyPrint(includeStack);
|
|
354
|
+
} else if (error instanceof import_zod2.ZodError) {
|
|
355
|
+
this.handleZodError(error, includeStack);
|
|
356
|
+
} else if (error instanceof Error) {
|
|
357
|
+
this.handleStandardError(error, includeStack);
|
|
358
|
+
} else {
|
|
359
|
+
this.handleUnknownError(error);
|
|
360
|
+
}
|
|
361
|
+
if (exitProcess && typeof process !== "undefined") {
|
|
362
|
+
process.exit(exitCode);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Helper method to handle Zod validation errors
|
|
367
|
+
* @param error The Zod error to handle
|
|
368
|
+
* @param includeStack Whether to include the stack trace
|
|
369
|
+
* @private
|
|
370
|
+
*/
|
|
371
|
+
static handleZodError(error, includeStack) {
|
|
372
|
+
logger_default.error("\n" + import_chalk2.default.bgRed.white.bold(" ERROR ") + " " + import_chalk2.default.white.bold(error.message));
|
|
373
|
+
logger_default.error(import_chalk2.default.gray("Invalid parameters:"));
|
|
374
|
+
error.errors.forEach((err) => {
|
|
375
|
+
logger_default.error(import_chalk2.default.yellow(err.path.join(".")) + " " + import_chalk2.default.white(err.message));
|
|
376
|
+
});
|
|
377
|
+
logger_default.error(import_chalk2.default.gray("Expected parameters:"));
|
|
378
|
+
error.errors.forEach((err) => {
|
|
379
|
+
logger_default.error(import_chalk2.default.yellow(err.path.join(".")) + " " + import_chalk2.default.white(err.message));
|
|
380
|
+
});
|
|
381
|
+
if (includeStack) {
|
|
382
|
+
logger_default.error("\n" + import_chalk2.default.gray("Validation Errors:"));
|
|
383
|
+
error.errors.forEach((err) => {
|
|
384
|
+
const path = err.path.join(".");
|
|
385
|
+
logger_default.error(
|
|
386
|
+
import_chalk2.default.gray(" \u2022 ") + import_chalk2.default.yellow(path ? `${path}: ` : "") + import_chalk2.default.white(err.message)
|
|
387
|
+
);
|
|
388
|
+
});
|
|
389
|
+
if (error.stack) {
|
|
390
|
+
logger_default.error("\n" + import_chalk2.default.gray("Stack Trace:"));
|
|
391
|
+
const stackLines = error.stack.split("\n").slice(1);
|
|
392
|
+
logger_default.error(import_chalk2.default.gray(stackLines.join("\n")));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
logger_default.error("");
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Helper method to handle standard Error objects
|
|
399
|
+
* @param error The standard error to handle
|
|
400
|
+
* @param includeStack Whether to include the stack trace
|
|
401
|
+
* @private
|
|
402
|
+
*/
|
|
403
|
+
static handleStandardError(error, includeStack) {
|
|
404
|
+
logger_default.error("\n" + import_chalk2.default.bgRed.white.bold(" ERROR ") + " " + import_chalk2.default.white.bold(error.message));
|
|
405
|
+
if (includeStack && error.stack) {
|
|
406
|
+
logger_default.error("\n" + import_chalk2.default.gray("Stack Trace:"));
|
|
407
|
+
const stackLines = error.stack.split("\n").slice(1);
|
|
408
|
+
logger_default.error(import_chalk2.default.gray(stackLines.join("\n")));
|
|
409
|
+
}
|
|
410
|
+
logger_default.error("");
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Helper method to handle unknown error types
|
|
414
|
+
* @param error The unknown error value
|
|
415
|
+
* @private
|
|
416
|
+
*/
|
|
417
|
+
static handleUnknownError(error) {
|
|
418
|
+
logger_default.error(
|
|
419
|
+
"\n" + import_chalk2.default.bgRed.white.bold(" ERROR ") + " " + import_chalk2.default.white.bold("Unknown error occurred")
|
|
420
|
+
);
|
|
421
|
+
if (error !== null && error !== void 0) {
|
|
422
|
+
logger_default.error(import_chalk2.default.gray("Error details:"));
|
|
423
|
+
logger_default.error(" " + import_chalk2.default.white(String(error)));
|
|
424
|
+
}
|
|
425
|
+
logger_default.error("");
|
|
210
426
|
}
|
|
211
427
|
};
|
|
212
428
|
|
|
@@ -221,11 +437,11 @@ var ToolErrorCodes = {
|
|
|
221
437
|
GLOBAL_EXECUTE_TOOL_FN_NOT_SET: "GLOBAL_EXECUTE_TOOL_FN_NOT_SET"
|
|
222
438
|
};
|
|
223
439
|
var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
224
|
-
constructor(message = "Provider not defined",
|
|
440
|
+
constructor(message = "Provider not defined", options = {}) {
|
|
225
441
|
super(message, {
|
|
442
|
+
...options,
|
|
226
443
|
code: ToolErrorCodes.TOOLSET_NOT_DEFINED,
|
|
227
|
-
|
|
228
|
-
possibleFixes: [
|
|
444
|
+
possibleFixes: options.possibleFixes || [
|
|
229
445
|
"Ensure that the provider is defined in the Composio project and passed into the tool instance"
|
|
230
446
|
]
|
|
231
447
|
});
|
|
@@ -233,85 +449,407 @@ var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
|
233
449
|
}
|
|
234
450
|
};
|
|
235
451
|
var ComposioToolNotFoundError = class extends ComposioError {
|
|
236
|
-
constructor(message = "Tool not found",
|
|
452
|
+
constructor(message = "Tool not found", options = {}) {
|
|
237
453
|
super(message, {
|
|
454
|
+
...options,
|
|
238
455
|
code: ToolErrorCodes.TOOL_NOT_FOUND,
|
|
239
|
-
|
|
240
|
-
|
|
456
|
+
possibleFixes: options.possibleFixes || [
|
|
457
|
+
"Ensure the tool slug is correct and exists in the Composio project"
|
|
458
|
+
]
|
|
241
459
|
});
|
|
242
460
|
this.name = "ComposioToolNotFoundError";
|
|
243
461
|
}
|
|
244
462
|
};
|
|
245
463
|
var ComposioInvalidModifierError = class extends ComposioError {
|
|
246
|
-
constructor(message = "Invalid modifier",
|
|
464
|
+
constructor(message = "Invalid modifier", options = {}) {
|
|
247
465
|
super(message, {
|
|
466
|
+
...options,
|
|
248
467
|
code: ToolErrorCodes.INVALID_MODIFIER,
|
|
249
|
-
|
|
250
|
-
|
|
468
|
+
possibleFixes: options.possibleFixes || [
|
|
469
|
+
"Ensure the modifier is a function and returns a valid result"
|
|
470
|
+
]
|
|
251
471
|
});
|
|
252
472
|
this.name = "ComposioInvalidModifierError";
|
|
253
473
|
}
|
|
254
474
|
};
|
|
255
475
|
var ComposioCustomToolsNotInitializedError = class extends ComposioError {
|
|
256
|
-
constructor(message = "Custom tools not initialized",
|
|
476
|
+
constructor(message = "Custom tools not initialized", options = {}) {
|
|
257
477
|
super(message, {
|
|
478
|
+
...options,
|
|
258
479
|
code: ToolErrorCodes.CUSTOM_TOOLS_NOT_INITIALIZED,
|
|
259
|
-
|
|
260
|
-
|
|
480
|
+
possibleFixes: options.possibleFixes || [
|
|
481
|
+
"Ensure the custom tools class is initialized in the Tools instance"
|
|
482
|
+
]
|
|
261
483
|
});
|
|
262
484
|
this.name = "ComposioCustomToolsNotInitializedError";
|
|
263
485
|
}
|
|
264
486
|
};
|
|
265
487
|
var ComposioToolExecutionError = class extends ComposioError {
|
|
266
488
|
error;
|
|
267
|
-
constructor(
|
|
489
|
+
constructor(message = "Tool execution error", options = {}) {
|
|
490
|
+
const { originalError, ...restOptions } = options;
|
|
268
491
|
super(message, {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
possibleFixes:
|
|
492
|
+
...restOptions,
|
|
493
|
+
code: options.code || ToolErrorCodes.TOOL_EXECUTION_ERROR,
|
|
494
|
+
cause: options.cause || originalError,
|
|
495
|
+
possibleFixes: options.possibleFixes || [
|
|
496
|
+
"Ensure the tool is correctly configured and the input is valid"
|
|
497
|
+
]
|
|
273
498
|
});
|
|
274
|
-
this.error =
|
|
499
|
+
this.error = originalError || (options.cause instanceof Error ? options.cause : new Error(String(options.cause)));
|
|
275
500
|
this.name = "ComposioToolExecutionError";
|
|
276
501
|
}
|
|
277
502
|
};
|
|
278
503
|
var ComposioInvalidExecuteFunctionError = class extends ComposioError {
|
|
279
|
-
constructor(message = "Invalid execute function",
|
|
504
|
+
constructor(message = "Invalid execute function", options = {}) {
|
|
280
505
|
super(message, {
|
|
506
|
+
...options,
|
|
281
507
|
code: ToolErrorCodes.INVALID_EXECUTE_FUNCTION,
|
|
282
|
-
|
|
283
|
-
|
|
508
|
+
possibleFixes: options.possibleFixes || [
|
|
509
|
+
"Ensure the execute function is a valid function and returns a valid result"
|
|
510
|
+
]
|
|
284
511
|
});
|
|
285
512
|
this.name = "ComposioInvalidExecuteFunctionError";
|
|
286
513
|
}
|
|
287
514
|
};
|
|
288
515
|
var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
|
|
289
|
-
constructor(message = "Global execute tool function not set",
|
|
516
|
+
constructor(message = "Global execute tool function not set", options = {}) {
|
|
290
517
|
super(message, {
|
|
518
|
+
...options,
|
|
291
519
|
code: ToolErrorCodes.GLOBAL_EXECUTE_TOOL_FN_NOT_SET,
|
|
292
|
-
|
|
293
|
-
|
|
520
|
+
possibleFixes: options.possibleFixes || [
|
|
521
|
+
"Ensure the global execute tool function is set in the provider"
|
|
522
|
+
]
|
|
294
523
|
});
|
|
295
524
|
this.name = "ComposioGlobalExecuteToolFnNotSetError";
|
|
296
525
|
}
|
|
297
526
|
};
|
|
298
527
|
|
|
299
|
-
// src/errors/
|
|
528
|
+
// src/errors/ConnectedAccountsErrors.ts
|
|
300
529
|
var ConnectedAccountErrorCodes = {
|
|
301
530
|
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
|
|
302
531
|
};
|
|
303
532
|
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
304
|
-
constructor(message = "Connected account not found",
|
|
533
|
+
constructor(message = "Connected account not found", options = {}) {
|
|
305
534
|
super(message, {
|
|
535
|
+
...options,
|
|
306
536
|
code: ConnectedAccountErrorCodes.CONNECTED_ACCOUNT_NOT_FOUND,
|
|
307
537
|
statusCode: 404,
|
|
308
|
-
|
|
309
|
-
possibleFixes: [
|
|
538
|
+
possibleFixes: options.possibleFixes || [
|
|
310
539
|
"Ensure the connected account exists and is active in your Composio dashboard"
|
|
311
540
|
]
|
|
312
541
|
});
|
|
542
|
+
this.name = "ComposioConnectedAccountNotFoundError";
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
|
|
546
|
+
// src/telemetry/Telemetry.ts
|
|
547
|
+
var import_client2 = require("@composio/client");
|
|
548
|
+
|
|
549
|
+
// src/types/telemetry.types.ts
|
|
550
|
+
var TELEMETRY_EVENTS = {
|
|
551
|
+
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
552
|
+
SDK_METHOD_INVOKED: "SDK_METHOD_INVOKED",
|
|
553
|
+
SDK_METHOD_ERROR: "SDK_METHOD_ERROR",
|
|
554
|
+
CLI_INVOKED: "CLI_INVOKED"
|
|
555
|
+
};
|
|
556
|
+
|
|
557
|
+
// src/utils/constants.ts
|
|
558
|
+
var COMPOSIO_DIR = ".composio";
|
|
559
|
+
var USER_DATA_FILE_NAME = "user_data.json";
|
|
560
|
+
var DEFAULT_BASE_URL = "https://backend.composio.dev";
|
|
561
|
+
var TELEMETRY_URL = "https://app.composio.dev";
|
|
562
|
+
var IS_DEVELOPMENT_OR_CI = process.env.DEVELOPMENT || process.env.CI || false;
|
|
563
|
+
|
|
564
|
+
// src/telemetry/BatchProcessor.ts
|
|
565
|
+
var BatchProcessor = class {
|
|
566
|
+
batch = [];
|
|
567
|
+
time;
|
|
568
|
+
batchSize;
|
|
569
|
+
processBatchCallback;
|
|
570
|
+
timer = null;
|
|
571
|
+
constructor(time = 2e3, batchSize = 100, processBatchCallback) {
|
|
572
|
+
this.batch = [];
|
|
573
|
+
this.time = time;
|
|
574
|
+
this.batchSize = batchSize;
|
|
575
|
+
this.processBatchCallback = processBatchCallback;
|
|
576
|
+
}
|
|
577
|
+
pushItem(item) {
|
|
578
|
+
this.batch.push(item);
|
|
579
|
+
if (this.batch.length >= this.batchSize) {
|
|
580
|
+
this.processBatch();
|
|
581
|
+
} else if (!this.timer) {
|
|
582
|
+
this.timer = setTimeout(() => this.processBatch(), this.time);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
processBatch() {
|
|
586
|
+
if (this.batch.length > 0) {
|
|
587
|
+
this.processBatchCallback(this.batch);
|
|
588
|
+
this.batch = [];
|
|
589
|
+
}
|
|
590
|
+
if (this.timer) {
|
|
591
|
+
clearTimeout(this.timer);
|
|
592
|
+
this.timer = null;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
// src/telemetry/transports/BrowserTransport.ts
|
|
598
|
+
var BrowserTelemetryTransport = class {
|
|
599
|
+
send(payload) {
|
|
600
|
+
if (typeof window === "undefined") {
|
|
601
|
+
return Promise.reject(
|
|
602
|
+
new Error("BrowserTelemetryTransport can only be used in browser environments")
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
return new Promise((resolve) => {
|
|
606
|
+
try {
|
|
607
|
+
const xhr = new XMLHttpRequest();
|
|
608
|
+
xhr.open(payload.method, payload.url, true);
|
|
609
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
610
|
+
Object.entries(payload.headers || {}).forEach(([key, value]) => {
|
|
611
|
+
xhr.setRequestHeader(key, value);
|
|
612
|
+
});
|
|
613
|
+
xhr.onload = function() {
|
|
614
|
+
resolve();
|
|
615
|
+
};
|
|
616
|
+
xhr.send(JSON.stringify(payload.data));
|
|
617
|
+
} catch (error) {
|
|
618
|
+
logger_default.error("Error sending error to telemetry", error);
|
|
619
|
+
resolve();
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// src/telemetry/transports/ProcessTransport.ts
|
|
626
|
+
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
627
|
+
var ProcessTelemetryTransport = class {
|
|
628
|
+
send(payload) {
|
|
629
|
+
if (typeof window !== "undefined") {
|
|
630
|
+
return Promise.reject(
|
|
631
|
+
new Error("ProcessTelemetryTransport can only be used in Node.js environments")
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
return new Promise((resolve) => {
|
|
635
|
+
try {
|
|
636
|
+
const url = new URL(payload.url);
|
|
637
|
+
const protocol = url.protocol === "https:" ? "https" : "http";
|
|
638
|
+
const port = url.port || (url.protocol === "https:" ? 443 : 80);
|
|
639
|
+
const args = [
|
|
640
|
+
"-e",
|
|
641
|
+
`
|
|
642
|
+
const http = require('${protocol}');
|
|
643
|
+
const options = {
|
|
644
|
+
hostname: '${url.hostname}',
|
|
645
|
+
path: '${url.pathname}${url.search}',
|
|
646
|
+
port: ${port},
|
|
647
|
+
method: '${payload.method}',
|
|
648
|
+
headers: ${JSON.stringify(payload.headers)}
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
const req = http.request(options, (res) => {
|
|
652
|
+
res.on('data', () => {});
|
|
653
|
+
res.on('end', () => {
|
|
654
|
+
process.exit(0);
|
|
655
|
+
});
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
req.on('error', () => {
|
|
659
|
+
process.exit(0);
|
|
660
|
+
});
|
|
661
|
+
|
|
662
|
+
req.write(JSON.stringify(${JSON.stringify(payload.data)}));
|
|
663
|
+
req.end();
|
|
664
|
+
`
|
|
665
|
+
];
|
|
666
|
+
import("child_process").then(({ spawn }) => {
|
|
667
|
+
spawn("node", args, {
|
|
668
|
+
stdio: "ignore",
|
|
669
|
+
detached: false,
|
|
670
|
+
shell: false
|
|
671
|
+
}).unref();
|
|
672
|
+
resolve();
|
|
673
|
+
}).catch((error) => {
|
|
674
|
+
logger_default.error("Error sending telemetry", error);
|
|
675
|
+
resolve();
|
|
676
|
+
});
|
|
677
|
+
logger_default.debug(import_chalk3.default.yellow("Process Telemetry"), JSON.stringify(payload, null, 2));
|
|
678
|
+
} catch (error) {
|
|
679
|
+
logger_default.error("Error sending telemetry", error);
|
|
680
|
+
resolve();
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
// src/utils/uuid.ts
|
|
687
|
+
var import_uuid = require("uuid");
|
|
688
|
+
function getRandomUUID() {
|
|
689
|
+
return (0, import_uuid.v4)();
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// src/telemetry/Telemetry.ts
|
|
693
|
+
var TelemetryService = class {
|
|
694
|
+
telemetryMetadata;
|
|
695
|
+
transport;
|
|
696
|
+
isTelemetryDisabled = true;
|
|
697
|
+
batchProcessor = new BatchProcessor(100, 10, async (data) => {
|
|
698
|
+
await this.sendTelemetry(data);
|
|
699
|
+
});
|
|
700
|
+
setup(metadata, transport) {
|
|
701
|
+
this.telemetryMetadata = metadata;
|
|
702
|
+
this.isTelemetryDisabled = false;
|
|
703
|
+
const isBrowser = typeof window !== "undefined";
|
|
704
|
+
if (transport) {
|
|
705
|
+
this.transport = transport;
|
|
706
|
+
} else if (isBrowser) {
|
|
707
|
+
this.transport = new BrowserTelemetryTransport();
|
|
708
|
+
this.telemetryMetadata.transport = "browser";
|
|
709
|
+
} else {
|
|
710
|
+
this.transport = new ProcessTelemetryTransport();
|
|
711
|
+
this.telemetryMetadata.transport = "process";
|
|
712
|
+
}
|
|
713
|
+
this.sendTelemetry([
|
|
714
|
+
{
|
|
715
|
+
eventName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
716
|
+
data: {}
|
|
717
|
+
}
|
|
718
|
+
]);
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Instrument the telemetry for the given instance.
|
|
722
|
+
*
|
|
723
|
+
* You can pass the instance and the file name of the instance to instrument the telemetry.
|
|
724
|
+
* This will instrument all the methods of the instance and log the telemetry for each method call.
|
|
725
|
+
* @param instance - any instance that extends InstrumentedInstance
|
|
726
|
+
* @param fileName - the file name of the instance
|
|
727
|
+
* @returns
|
|
728
|
+
*/
|
|
729
|
+
instrument(instance, fileName) {
|
|
730
|
+
const proto = Object.getPrototypeOf(instance);
|
|
731
|
+
const methodNames = Object.getOwnPropertyNames(proto).filter((key) => {
|
|
732
|
+
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
733
|
+
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
734
|
+
});
|
|
735
|
+
const instrumentedClassName = instance.constructor?.name || fileName || "unknown";
|
|
736
|
+
for (const name of methodNames) {
|
|
737
|
+
const originalMethod = instance[name];
|
|
738
|
+
instance[name] = async (...args) => {
|
|
739
|
+
const telemetryPayload = {
|
|
740
|
+
eventName: TELEMETRY_EVENTS.SDK_METHOD_INVOKED,
|
|
741
|
+
data: {
|
|
742
|
+
fileName: instrumentedClassName,
|
|
743
|
+
method: name,
|
|
744
|
+
params: args
|
|
745
|
+
}
|
|
746
|
+
};
|
|
747
|
+
this.batchProcessor.pushItem(telemetryPayload);
|
|
748
|
+
try {
|
|
749
|
+
return await originalMethod.apply(instance, args);
|
|
750
|
+
} catch (error) {
|
|
751
|
+
if (error instanceof Error && !error.errorId) {
|
|
752
|
+
error.errorId = getRandomUUID();
|
|
753
|
+
this.prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args);
|
|
754
|
+
}
|
|
755
|
+
throw error;
|
|
756
|
+
}
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
return instance;
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Check if the telemetry should be sent.
|
|
763
|
+
* @returns true if the telemetry should be sent, false otherwise
|
|
764
|
+
*/
|
|
765
|
+
shouldSendTelemetry() {
|
|
766
|
+
const devEnvironments = ["test", "development", "CI"];
|
|
767
|
+
const nodeEnv = (getEnvVariable("NODE_ENV", "development") || "").toLowerCase();
|
|
768
|
+
const isDevEnvironment = devEnvironments.includes(nodeEnv);
|
|
769
|
+
const isTelemetryDisabledByEnv = getEnvVariable("TELEMETRY_DISABLED", "false") === "true";
|
|
770
|
+
return this.transport && !this.isTelemetryDisabled && !isTelemetryDisabledByEnv && !isDevEnvironment;
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Prepare and send the error telemetry.
|
|
774
|
+
*
|
|
775
|
+
* @TODO This currently blocks the thread and sends the telemetry to the server.
|
|
776
|
+
*
|
|
777
|
+
* @param {unknown} error - The error to send.
|
|
778
|
+
* @param {string} instrumentedClassName - The class name of the instrumented class.
|
|
779
|
+
* @param {string} name - The name of the method that threw the error.
|
|
780
|
+
*/
|
|
781
|
+
prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args) {
|
|
782
|
+
if (error instanceof import_client2.ComposioError) {
|
|
783
|
+
const telemetryPayload = {
|
|
784
|
+
error_id: error.errorId || "",
|
|
785
|
+
error_message: error.message,
|
|
786
|
+
original_error: error.cause || error,
|
|
787
|
+
current_stack: error.stack?.split("\n") || [],
|
|
788
|
+
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
789
|
+
};
|
|
790
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
791
|
+
} else if (error instanceof ComposioError) {
|
|
792
|
+
const telemetryPayload = {
|
|
793
|
+
error_id: error.errorId || "",
|
|
794
|
+
error_message: error.message,
|
|
795
|
+
original_error: error.cause || error,
|
|
796
|
+
current_stack: error.stack?.split("\n") || [],
|
|
797
|
+
error_code: error.code,
|
|
798
|
+
possible_fix: error.possibleFixes?.join("\n"),
|
|
799
|
+
description: `Original Call : ${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
800
|
+
};
|
|
801
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
802
|
+
} else if (error instanceof Error) {
|
|
803
|
+
const telemetryPayload = {
|
|
804
|
+
error_id: error.errorId || "",
|
|
805
|
+
error_message: error instanceof Error ? error.name : "Unknown error",
|
|
806
|
+
original_error: error,
|
|
807
|
+
current_stack: error.stack?.split("\n") || [],
|
|
808
|
+
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
809
|
+
};
|
|
810
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Send the telemetry payload to the server.
|
|
815
|
+
* @param payload - the telemetry payload to send
|
|
816
|
+
* @returns
|
|
817
|
+
*/
|
|
818
|
+
async sendTelemetry(payload) {
|
|
819
|
+
if (!this.shouldSendTelemetry()) {
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
const url = `${TELEMETRY_URL}/api/sdk_metrics/telemetry`;
|
|
823
|
+
const reqPayload = {
|
|
824
|
+
data: payload.map((p) => ({
|
|
825
|
+
...p,
|
|
826
|
+
sdk_meta: this.telemetryMetadata
|
|
827
|
+
})),
|
|
828
|
+
url,
|
|
829
|
+
method: "POST",
|
|
830
|
+
headers: { "Content-Type": "application/json" }
|
|
831
|
+
};
|
|
832
|
+
this.transport.send(reqPayload);
|
|
833
|
+
}
|
|
834
|
+
// @TODO: check if this will send the error telemetry to the server
|
|
835
|
+
async sendErrorTelemetry(payload) {
|
|
836
|
+
if (!this.shouldSendTelemetry()) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
const url = `${TELEMETRY_URL}/api/sdk_metrics/error`;
|
|
840
|
+
const reqPayload = {
|
|
841
|
+
data: {
|
|
842
|
+
...payload,
|
|
843
|
+
sdk_meta: this.telemetryMetadata
|
|
844
|
+
},
|
|
845
|
+
url,
|
|
846
|
+
method: "POST",
|
|
847
|
+
headers: { "Content-Type": "application/json" }
|
|
848
|
+
};
|
|
849
|
+
this.transport.send(reqPayload);
|
|
313
850
|
}
|
|
314
851
|
};
|
|
852
|
+
var telemetry = new TelemetryService();
|
|
315
853
|
|
|
316
854
|
// src/models/CustomTools.ts
|
|
317
855
|
var CustomTools = class {
|
|
@@ -323,6 +861,7 @@ var CustomTools = class {
|
|
|
323
861
|
}
|
|
324
862
|
this.client = client;
|
|
325
863
|
this.customToolsRegistry = /* @__PURE__ */ new Map();
|
|
864
|
+
telemetry.instrument(this);
|
|
326
865
|
}
|
|
327
866
|
/**
|
|
328
867
|
* Create a custom tool and registers it in the registry.
|
|
@@ -417,8 +956,8 @@ var CustomTools = class {
|
|
|
417
956
|
});
|
|
418
957
|
}
|
|
419
958
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
420
|
-
|
|
421
|
-
|
|
959
|
+
toolkit_slugs: [toolkitSlug],
|
|
960
|
+
user_ids: [metadata.userId]
|
|
422
961
|
});
|
|
423
962
|
if (!connectedAccounts.items.length) {
|
|
424
963
|
throw new ComposioConnectedAccountNotFoundError(
|
|
@@ -478,40 +1017,50 @@ var CustomTools = class {
|
|
|
478
1017
|
}
|
|
479
1018
|
};
|
|
480
1019
|
|
|
481
|
-
// src/errors/
|
|
482
|
-
var
|
|
1020
|
+
// src/errors/ValidationErrors.ts
|
|
1021
|
+
var import_zod3 = require("zod");
|
|
483
1022
|
var ValidationErrorCodes = {
|
|
484
1023
|
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
485
1024
|
};
|
|
486
1025
|
var ValidationError = class extends ComposioError {
|
|
487
|
-
|
|
488
|
-
|
|
1026
|
+
constructor(message = "Input validation failed", options = {}) {
|
|
1027
|
+
const { cause: providedZodError, ...restOptions } = options;
|
|
489
1028
|
let zodErrorInstance;
|
|
490
|
-
if (
|
|
491
|
-
zodErrorInstance =
|
|
1029
|
+
if (providedZodError instanceof import_zod3.ZodError) {
|
|
1030
|
+
zodErrorInstance = providedZodError;
|
|
1031
|
+
} else {
|
|
1032
|
+
zodErrorInstance = new import_zod3.ZodError([
|
|
492
1033
|
{
|
|
493
1034
|
path: [],
|
|
494
1035
|
message: "Invalid input",
|
|
495
1036
|
code: "custom"
|
|
496
1037
|
}
|
|
497
1038
|
]);
|
|
498
|
-
} else {
|
|
499
|
-
zodErrorInstance = zodError;
|
|
500
1039
|
}
|
|
1040
|
+
const issues = zodErrorInstance.issues.map(
|
|
1041
|
+
(issue) => `[${issue.code}] ${issue.path.join(".")} - ${issue.message}`
|
|
1042
|
+
);
|
|
501
1043
|
super(message, {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
zodErrorInstance.issues.map((issue) => ({
|
|
506
|
-
path: issue.path.join("."),
|
|
507
|
-
message: issue.message,
|
|
508
|
-
code: issue.code
|
|
509
|
-
}))
|
|
510
|
-
)
|
|
511
|
-
},
|
|
1044
|
+
...restOptions,
|
|
1045
|
+
code: options.code || ValidationErrorCodes.VALIDATION_ERROR,
|
|
1046
|
+
possibleFixes: issues,
|
|
512
1047
|
cause: zodErrorInstance
|
|
513
1048
|
});
|
|
514
|
-
this.
|
|
1049
|
+
this.name = "ValidationError";
|
|
1050
|
+
const userFriendlyMessage = this.generateUserFriendlyMessage();
|
|
1051
|
+
this.message = `${message}: ${userFriendlyMessage}`;
|
|
1052
|
+
}
|
|
1053
|
+
generateUserFriendlyMessage() {
|
|
1054
|
+
if (this.cause instanceof import_zod3.ZodError && this.cause.issues.length > 0) {
|
|
1055
|
+
const issue = this.cause.issues[0];
|
|
1056
|
+
const path = issue.path.join(".");
|
|
1057
|
+
const param = path || "parameter";
|
|
1058
|
+
if (issue.code === "invalid_type") {
|
|
1059
|
+
return `The ${param} should be a ${issue.expected}, but you provided a ${issue.received}`;
|
|
1060
|
+
}
|
|
1061
|
+
return issue.message;
|
|
1062
|
+
}
|
|
1063
|
+
return "Please check your input parameters";
|
|
515
1064
|
}
|
|
516
1065
|
};
|
|
517
1066
|
|
|
@@ -531,13 +1080,21 @@ var Tools = class {
|
|
|
531
1080
|
this.customTools = new CustomTools(client);
|
|
532
1081
|
this.provider = provider;
|
|
533
1082
|
this.execute = this.execute.bind(this);
|
|
1083
|
+
this.provider._setExecuteToolFn(this.execute);
|
|
534
1084
|
this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
|
|
535
1085
|
this.getRawComposioTools = this.getRawComposioTools.bind(this);
|
|
1086
|
+
telemetry.instrument(this);
|
|
536
1087
|
}
|
|
537
1088
|
/**
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
*
|
|
1089
|
+
* Transforms tool data from snake_case API format to camelCase for internal SDK use.
|
|
1090
|
+
*
|
|
1091
|
+
* This method standardizes the property naming convention for tools retrieved from the Composio API,
|
|
1092
|
+
* making them more consistent with JavaScript/TypeScript conventions.
|
|
1093
|
+
*
|
|
1094
|
+
* @param {ToolRetrieveResponse | ComposioToolListResponse['items'][0]} tool - The tool object to transform
|
|
1095
|
+
* @returns {Tool} The transformed tool with camelCase properties
|
|
1096
|
+
*
|
|
1097
|
+
* @private
|
|
541
1098
|
*/
|
|
542
1099
|
transformToolCases(tool) {
|
|
543
1100
|
return ToolSchema.parse({
|
|
@@ -547,9 +1104,15 @@ var Tools = class {
|
|
|
547
1104
|
});
|
|
548
1105
|
}
|
|
549
1106
|
/**
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
1107
|
+
* Transforms tool execution response from snake_case API format to camelCase.
|
|
1108
|
+
*
|
|
1109
|
+
* This method converts the response received from the Composio API to a standardized format
|
|
1110
|
+
* with consistent property naming that follows JavaScript/TypeScript conventions.
|
|
1111
|
+
*
|
|
1112
|
+
* @param {ComposioToolExecuteResponse} response - The raw API response to transform
|
|
1113
|
+
* @returns {ToolExecuteResponse} The transformed response with camelCase properties
|
|
1114
|
+
*
|
|
1115
|
+
* @private
|
|
553
1116
|
*/
|
|
554
1117
|
transformToolExecuteResponse(response) {
|
|
555
1118
|
return ToolExecuteResponseSchema.parse({
|
|
@@ -634,14 +1197,42 @@ var Tools = class {
|
|
|
634
1197
|
return null;
|
|
635
1198
|
}
|
|
636
1199
|
/**
|
|
637
|
-
* Lists all tools available in the Composio SDK
|
|
638
|
-
*
|
|
639
|
-
*
|
|
1200
|
+
* Lists all tools available in the Composio SDK including custom tools.
|
|
1201
|
+
*
|
|
1202
|
+
* This method fetches tools from the Composio API in raw format and combines them with
|
|
1203
|
+
* any registered custom tools. The response can be filtered and modified as needed.
|
|
1204
|
+
*
|
|
1205
|
+
* @param {string} userId - The user ID for whom to fetch the tools
|
|
1206
|
+
* @param {ToolListParams} [query={}] - Optional query parameters to filter the tools
|
|
1207
|
+
* @param {TransformToolSchemaModifier} [modifier] - Optional function to transform tool schemas
|
|
1208
|
+
* @returns {Promise<ToolList>} List of tools matching the query criteria
|
|
1209
|
+
*
|
|
1210
|
+
* @example
|
|
1211
|
+
* ```typescript
|
|
1212
|
+
* // Get all tools
|
|
1213
|
+
* const tools = await composio.tools.getRawComposioTools('default');
|
|
1214
|
+
*
|
|
1215
|
+
* // Get tools with filters
|
|
1216
|
+
* const githubTools = await composio.tools.getRawComposioTools('default', {
|
|
1217
|
+
* toolkits: ['github'],
|
|
1218
|
+
* important: true
|
|
1219
|
+
* });
|
|
1220
|
+
*
|
|
1221
|
+
* // Get tools with schema transformation
|
|
1222
|
+
* const tools = await composio.tools.getRawComposioTools('default', {},
|
|
1223
|
+
* (toolSlug, toolkitSlug, tool) => {
|
|
1224
|
+
* // Add custom properties to tool schema
|
|
1225
|
+
* return {...tool, customProperty: 'value'};
|
|
1226
|
+
* }
|
|
1227
|
+
* );
|
|
1228
|
+
* ```
|
|
640
1229
|
*/
|
|
641
1230
|
async getRawComposioTools(userId, query = {}, modifier) {
|
|
642
1231
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
643
1232
|
if (queryParams.error) {
|
|
644
|
-
throw new ValidationError(
|
|
1233
|
+
throw new ValidationError("Invalid tool list parameters", {
|
|
1234
|
+
cause: queryParams.error
|
|
1235
|
+
});
|
|
645
1236
|
}
|
|
646
1237
|
const tools = await this.client.tools.list({
|
|
647
1238
|
tool_slugs: queryParams.data.tools,
|
|
@@ -672,6 +1263,7 @@ var Tools = class {
|
|
|
672
1263
|
}
|
|
673
1264
|
/**
|
|
674
1265
|
* Retrieves a tool by its Slug.
|
|
1266
|
+
* This method is used to get the raw tools from the composio API.
|
|
675
1267
|
* @param slug The ID of the tool to be retrieved
|
|
676
1268
|
* @returns {Promise<Tool>} The tool
|
|
677
1269
|
*
|
|
@@ -685,11 +1277,13 @@ var Tools = class {
|
|
|
685
1277
|
if (customTool) {
|
|
686
1278
|
return customTool;
|
|
687
1279
|
}
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
1280
|
+
let tool;
|
|
1281
|
+
try {
|
|
1282
|
+
tool = await this.client.tools.retrieve(slug);
|
|
1283
|
+
} catch (error) {
|
|
1284
|
+
throw new ComposioToolNotFoundError(`Unable to retrieve tool with slug ${slug}`, {
|
|
1285
|
+
cause: error
|
|
1286
|
+
});
|
|
693
1287
|
}
|
|
694
1288
|
let modifiedToool = this.transformToolCases(tool);
|
|
695
1289
|
if (modifier) {
|
|
@@ -702,19 +1296,21 @@ var Tools = class {
|
|
|
702
1296
|
return modifiedToool;
|
|
703
1297
|
}
|
|
704
1298
|
/**
|
|
705
|
-
* Get a tool
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
* @param
|
|
709
|
-
* @
|
|
1299
|
+
* Get a tool or list of tools based on the provided arguments.
|
|
1300
|
+
* This is an implementation method that handles both overloads.
|
|
1301
|
+
*
|
|
1302
|
+
* @param {string} userId - The user id to get the tool(s) for
|
|
1303
|
+
* @param {ToolListParams | string} arg2 - Either a slug string or filters object
|
|
1304
|
+
* @param {ProviderOptions<TProvider>} [options] - Optional provider options
|
|
1305
|
+
* @returns {Promise<TToolCollection>} The tool collection
|
|
710
1306
|
*/
|
|
711
1307
|
async get(userId, arg2, options) {
|
|
712
1308
|
const executeToolFn = this.createExecuteToolFn(userId, options);
|
|
713
1309
|
if (typeof arg2 === "string") {
|
|
714
|
-
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.
|
|
715
|
-
return this.provider.
|
|
1310
|
+
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifySchema);
|
|
1311
|
+
return this.provider.wrapTools([tool], executeToolFn);
|
|
716
1312
|
} else {
|
|
717
|
-
const tools = await this.getRawComposioTools(userId, arg2, options?.
|
|
1313
|
+
const tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
|
|
718
1314
|
return this.provider.wrapTools(tools, executeToolFn);
|
|
719
1315
|
}
|
|
720
1316
|
}
|
|
@@ -748,26 +1344,22 @@ var Tools = class {
|
|
|
748
1344
|
* @returns The response from the tool execution
|
|
749
1345
|
*/
|
|
750
1346
|
async handleCustomToolExecution(tool, body, modifiers) {
|
|
751
|
-
if (modifiers?.
|
|
752
|
-
if (typeof modifiers.
|
|
753
|
-
body = modifiers.
|
|
1347
|
+
if (modifiers?.beforeExecute) {
|
|
1348
|
+
if (typeof modifiers.beforeExecute === "function") {
|
|
1349
|
+
body = modifiers.beforeExecute(tool.slug, "unkown", body);
|
|
754
1350
|
} else {
|
|
755
|
-
throw new ComposioInvalidModifierError(
|
|
756
|
-
"Invalid beforeToolExecute modifier. Not a function."
|
|
757
|
-
);
|
|
1351
|
+
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
758
1352
|
}
|
|
759
1353
|
}
|
|
760
1354
|
let result = await this.customTools.executeCustomTool(tool.slug, body, {
|
|
761
1355
|
userId: body.userId || "default",
|
|
762
1356
|
connectedAccountId: body.connectedAccountId
|
|
763
1357
|
});
|
|
764
|
-
if (modifiers?.
|
|
765
|
-
if (typeof modifiers.
|
|
766
|
-
result = modifiers.
|
|
1358
|
+
if (modifiers?.afterExecute) {
|
|
1359
|
+
if (typeof modifiers.afterExecute === "function") {
|
|
1360
|
+
result = modifiers.afterExecute(tool.slug, "unkown", result);
|
|
767
1361
|
} else {
|
|
768
|
-
throw new ComposioInvalidModifierError(
|
|
769
|
-
"Invalid afterToolExecute modifier. Not a function."
|
|
770
|
-
);
|
|
1362
|
+
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
771
1363
|
}
|
|
772
1364
|
}
|
|
773
1365
|
return result;
|
|
@@ -781,13 +1373,11 @@ var Tools = class {
|
|
|
781
1373
|
* @returns The response from the tool execution
|
|
782
1374
|
*/
|
|
783
1375
|
async handleComposioToolExecution(tool, body, modifiers) {
|
|
784
|
-
if (modifiers?.
|
|
785
|
-
if (typeof modifiers.
|
|
786
|
-
body = modifiers.
|
|
1376
|
+
if (modifiers?.beforeExecute) {
|
|
1377
|
+
if (typeof modifiers.beforeExecute === "function") {
|
|
1378
|
+
body = modifiers.beforeExecute(tool.slug, tool.toolkit?.slug || "unkown", body);
|
|
787
1379
|
} else {
|
|
788
|
-
throw new ComposioInvalidModifierError(
|
|
789
|
-
"Invalid beforeToolExecute modifier. Not a function."
|
|
790
|
-
);
|
|
1380
|
+
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
791
1381
|
}
|
|
792
1382
|
}
|
|
793
1383
|
let connectedAccountId = body.connectedAccountId;
|
|
@@ -804,25 +1394,53 @@ var Tools = class {
|
|
|
804
1394
|
text: body.text
|
|
805
1395
|
});
|
|
806
1396
|
result = this.transformToolExecuteResponse(result);
|
|
807
|
-
if (modifiers?.
|
|
808
|
-
if (typeof modifiers.
|
|
809
|
-
result = modifiers.
|
|
1397
|
+
if (modifiers?.afterExecute) {
|
|
1398
|
+
if (typeof modifiers.afterExecute === "function") {
|
|
1399
|
+
result = modifiers.afterExecute(tool.slug, tool.toolkit?.slug || "unkown", result);
|
|
810
1400
|
} else {
|
|
811
|
-
throw new ComposioInvalidModifierError(
|
|
812
|
-
"Invalid afterToolExecute modifier. Not a function."
|
|
813
|
-
);
|
|
1401
|
+
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
814
1402
|
}
|
|
815
1403
|
}
|
|
816
1404
|
return result;
|
|
817
1405
|
}
|
|
818
1406
|
/**
|
|
819
|
-
*
|
|
1407
|
+
* Executes a given tool with the provided parameters.
|
|
820
1408
|
*
|
|
821
|
-
* This method calls the Composio API to execute the tool and returns the response.
|
|
1409
|
+
* This method calls the Composio API or a custom tool handler to execute the tool and returns the response.
|
|
1410
|
+
* It automatically determines whether to use a custom tool or a Composio API tool based on the slug.
|
|
822
1411
|
*
|
|
823
|
-
* @param {string} slug - The ID of the tool to be executed
|
|
1412
|
+
* @param {string} slug - The slug/ID of the tool to be executed
|
|
824
1413
|
* @param {ToolExecuteParams} body - The parameters to be passed to the tool
|
|
1414
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional modifiers to transform the request or response
|
|
825
1415
|
* @returns {Promise<ToolExecuteResponse>} - The response from the tool execution
|
|
1416
|
+
*
|
|
1417
|
+
* @throws {ComposioCustomToolsNotInitializedError} If the CustomTools instance is not initialized
|
|
1418
|
+
* @throws {ComposioToolNotFoundError} If the tool with the given slug is not found
|
|
1419
|
+
* @throws {ComposioToolExecutionError} If there is an error during tool execution
|
|
1420
|
+
*
|
|
1421
|
+
* @example
|
|
1422
|
+
* ```typescript
|
|
1423
|
+
* // Execute a Composio API tool
|
|
1424
|
+
* const result = await composio.tools.execute('HACKERNEWS_GET_USER', {
|
|
1425
|
+
* userId: 'default',
|
|
1426
|
+
* arguments: { userId: 'pg' }
|
|
1427
|
+
* });
|
|
1428
|
+
*
|
|
1429
|
+
* // Execute with modifiers
|
|
1430
|
+
* const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
|
|
1431
|
+
* userId: 'default',
|
|
1432
|
+
* arguments: { owner: 'composio', repo: 'sdk' }
|
|
1433
|
+
* }, {
|
|
1434
|
+
* beforeExecute: (toolSlug, toolkitSlug, params) => {
|
|
1435
|
+
* // Modify params before execution
|
|
1436
|
+
* return params;
|
|
1437
|
+
* },
|
|
1438
|
+
* afterExecute: (toolSlug, toolkitSlug, result) => {
|
|
1439
|
+
* // Transform result after execution
|
|
1440
|
+
* return result;
|
|
1441
|
+
* }
|
|
1442
|
+
* });
|
|
1443
|
+
* ```
|
|
826
1444
|
*/
|
|
827
1445
|
async execute(slug, body, modifiers) {
|
|
828
1446
|
if (!this.customTools) {
|
|
@@ -842,9 +1460,12 @@ var Tools = class {
|
|
|
842
1460
|
return this.handleComposioToolExecution(composioTool, body, modifiers);
|
|
843
1461
|
}
|
|
844
1462
|
} catch (error) {
|
|
845
|
-
throw new ComposioToolExecutionError(
|
|
846
|
-
|
|
847
|
-
|
|
1463
|
+
throw new ComposioToolExecutionError(`Error executing tool ${slug}`, {
|
|
1464
|
+
originalError: error,
|
|
1465
|
+
meta: {
|
|
1466
|
+
toolSlug: slug,
|
|
1467
|
+
body
|
|
1468
|
+
}
|
|
848
1469
|
});
|
|
849
1470
|
}
|
|
850
1471
|
}
|
|
@@ -879,100 +1500,226 @@ var Tools = class {
|
|
|
879
1500
|
return this.client.tools.proxy(body);
|
|
880
1501
|
}
|
|
881
1502
|
/**
|
|
882
|
-
*
|
|
883
|
-
*
|
|
884
|
-
*
|
|
1503
|
+
* Creates a custom tool that can be used within the Composio SDK.
|
|
1504
|
+
*
|
|
1505
|
+
* Custom tools allow you to extend the functionality of Composio with your own implementations
|
|
1506
|
+
* while keeping a consistent interface for both built-in and custom tools.
|
|
1507
|
+
*
|
|
1508
|
+
* @param {CustomToolOptions} body - The configuration for the custom tool
|
|
1509
|
+
* @returns {Promise<Tool>} The created custom tool
|
|
1510
|
+
*
|
|
1511
|
+
* @example
|
|
1512
|
+
* ```typescript
|
|
1513
|
+
* const customTool = await composio.tools.createCustomTool({
|
|
1514
|
+
* name: 'My Custom Tool',
|
|
1515
|
+
* description: 'A custom tool that does something specific',
|
|
1516
|
+
* slug: 'MY_CUSTOM_TOOL',
|
|
1517
|
+
* inputParameters: {
|
|
1518
|
+
* param1: {
|
|
1519
|
+
* type: 'string',
|
|
1520
|
+
* description: 'First parameter',
|
|
1521
|
+
* required: true
|
|
1522
|
+
* }
|
|
1523
|
+
* },
|
|
1524
|
+
* outputParameters: {
|
|
1525
|
+
* result: {
|
|
1526
|
+
* type: 'string',
|
|
1527
|
+
* description: 'The result of the operation'
|
|
1528
|
+
* }
|
|
1529
|
+
* },
|
|
1530
|
+
* handler: async (params, context) => {
|
|
1531
|
+
* // Custom logic here
|
|
1532
|
+
* return { data: { result: 'Success!' } };
|
|
1533
|
+
* }
|
|
1534
|
+
* });
|
|
1535
|
+
* ```
|
|
885
1536
|
*/
|
|
886
1537
|
async createCustomTool(body) {
|
|
887
1538
|
return this.customTools.createTool(body);
|
|
888
1539
|
}
|
|
889
1540
|
};
|
|
890
1541
|
|
|
891
|
-
// src/
|
|
892
|
-
var
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
var
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
})
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1542
|
+
// src/models/Toolkits.ts
|
|
1543
|
+
var import_client4 = __toESM(require("@composio/client"), 1);
|
|
1544
|
+
|
|
1545
|
+
// src/types/toolkit.types.ts
|
|
1546
|
+
var import_zod4 = require("zod");
|
|
1547
|
+
var ToolkitMangedByEnumSchema = import_zod4.z.enum(["all", "composio", "project"]);
|
|
1548
|
+
var ToolkitSortByEnumSchema = import_zod4.z.enum(["usage", "alphabetically"]);
|
|
1549
|
+
var ToolkitsListParamsSchema = import_zod4.z.object({
|
|
1550
|
+
category: import_zod4.z.string().optional(),
|
|
1551
|
+
isLocal: import_zod4.z.boolean().optional(),
|
|
1552
|
+
managedBy: ToolkitMangedByEnumSchema.optional(),
|
|
1553
|
+
sortBy: ToolkitSortByEnumSchema.optional()
|
|
1554
|
+
});
|
|
1555
|
+
var ToolKitMetaSchema = import_zod4.z.object({
|
|
1556
|
+
categories: import_zod4.z.array(
|
|
1557
|
+
import_zod4.z.object({
|
|
1558
|
+
slug: import_zod4.z.string(),
|
|
1559
|
+
name: import_zod4.z.string()
|
|
1560
|
+
})
|
|
1561
|
+
).optional(),
|
|
1562
|
+
appUrl: import_zod4.z.string().optional(),
|
|
1563
|
+
createdAt: import_zod4.z.string().optional(),
|
|
1564
|
+
description: import_zod4.z.string().optional(),
|
|
1565
|
+
logo: import_zod4.z.string().optional(),
|
|
1566
|
+
toolsCount: import_zod4.z.number().optional(),
|
|
1567
|
+
triggersCount: import_zod4.z.number().optional(),
|
|
1568
|
+
updatedAt: import_zod4.z.string().optional()
|
|
1569
|
+
});
|
|
1570
|
+
var ToolKitItemSchema = import_zod4.z.object({
|
|
1571
|
+
name: import_zod4.z.string(),
|
|
1572
|
+
slug: import_zod4.z.string(),
|
|
1573
|
+
meta: ToolKitMetaSchema,
|
|
1574
|
+
isLocalToolkit: import_zod4.z.boolean(),
|
|
1575
|
+
authSchemes: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
1576
|
+
composioManagedAuthSchemes: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
1577
|
+
noAuth: import_zod4.z.boolean().optional()
|
|
1578
|
+
});
|
|
1579
|
+
var ToolKitListResponseSchema = import_zod4.z.object({
|
|
1580
|
+
items: import_zod4.z.array(ToolKitItemSchema),
|
|
1581
|
+
nextCursor: import_zod4.z.string().nullable(),
|
|
1582
|
+
totalPages: import_zod4.z.number()
|
|
1583
|
+
});
|
|
1584
|
+
var ToolkitAuthFieldSchema = import_zod4.z.object({
|
|
1585
|
+
name: import_zod4.z.string(),
|
|
1586
|
+
displayName: import_zod4.z.string(),
|
|
1587
|
+
type: import_zod4.z.string(),
|
|
1588
|
+
default: import_zod4.z.string().nullable().optional()
|
|
1589
|
+
});
|
|
1590
|
+
var ToolkitAuthConfigDetailsSchema = import_zod4.z.object({
|
|
1591
|
+
name: import_zod4.z.string(),
|
|
1592
|
+
mode: import_zod4.z.string(),
|
|
1593
|
+
fields: import_zod4.z.object({
|
|
1594
|
+
authConfigCreation: import_zod4.z.object({
|
|
1595
|
+
optional: import_zod4.z.array(ToolkitAuthFieldSchema),
|
|
1596
|
+
required: import_zod4.z.array(ToolkitAuthFieldSchema)
|
|
1597
|
+
}),
|
|
1598
|
+
connectedAccountInitiation: import_zod4.z.object({
|
|
1599
|
+
optional: import_zod4.z.array(ToolkitAuthFieldSchema),
|
|
1600
|
+
required: import_zod4.z.array(ToolkitAuthFieldSchema)
|
|
1601
|
+
})
|
|
1602
|
+
}),
|
|
1603
|
+
proxy: import_zod4.z.object({
|
|
1604
|
+
baseUrl: import_zod4.z.string().optional()
|
|
1605
|
+
}).optional()
|
|
1606
|
+
});
|
|
1607
|
+
var ToolkitRetrieveResponseSchema = import_zod4.z.object({
|
|
1608
|
+
name: import_zod4.z.string(),
|
|
1609
|
+
slug: import_zod4.z.string(),
|
|
1610
|
+
meta: ToolKitMetaSchema,
|
|
1611
|
+
isLocalToolkit: import_zod4.z.boolean(),
|
|
1612
|
+
composioManagedAuthSchemes: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
1613
|
+
authConfigDetails: import_zod4.z.array(ToolkitAuthConfigDetailsSchema).optional()
|
|
1614
|
+
});
|
|
1615
|
+
var ToolkitCategorySchema = import_zod4.z.object({
|
|
1616
|
+
id: import_zod4.z.string(),
|
|
1617
|
+
name: import_zod4.z.string()
|
|
1618
|
+
});
|
|
1619
|
+
var ToolkitRetrieveCategoriesResponseSchema = import_zod4.z.object({
|
|
1620
|
+
items: import_zod4.z.array(ToolkitCategorySchema),
|
|
1621
|
+
nextCursor: import_zod4.z.string().nullable(),
|
|
1622
|
+
totalPages: import_zod4.z.number()
|
|
1623
|
+
});
|
|
1624
|
+
|
|
1625
|
+
// src/errors/AuthConfigErrors.ts
|
|
1626
|
+
var AuthConfigErrorCodes = {
|
|
1627
|
+
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1628
|
+
};
|
|
1629
|
+
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1630
|
+
constructor(message = "Auth config not found", options = {}) {
|
|
1631
|
+
super(message, {
|
|
1632
|
+
...options,
|
|
1633
|
+
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1634
|
+
possibleFixes: options.possibleFixes || [
|
|
1635
|
+
"Check if the auth config exists",
|
|
1636
|
+
"Check if the auth config id is correct",
|
|
1637
|
+
"Check if the auth config is enabled"
|
|
1638
|
+
]
|
|
1639
|
+
});
|
|
1640
|
+
this.name = "ComposioAuthConfigNotFoundError";
|
|
1641
|
+
}
|
|
1642
|
+
};
|
|
1643
|
+
|
|
1644
|
+
// src/errors/ConnectionRequestErrors.ts
|
|
1645
|
+
var ConnectionRequestErrorCodes = {
|
|
1646
|
+
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1647
|
+
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1648
|
+
};
|
|
1649
|
+
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1650
|
+
constructor(message = "Connection request timed out", options = {}) {
|
|
1651
|
+
super(message, {
|
|
1652
|
+
...options,
|
|
1653
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT
|
|
1654
|
+
});
|
|
1655
|
+
this.name = "ConnectionRequestTimeoutError";
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
var ConnectionRequestFailedError = class extends ComposioError {
|
|
1659
|
+
constructor(message = "Connection request failed", options = {}) {
|
|
1660
|
+
super(message, {
|
|
1661
|
+
...options,
|
|
1662
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED
|
|
1663
|
+
});
|
|
1664
|
+
this.name = "ConnectionRequestFailedError";
|
|
1665
|
+
}
|
|
1666
|
+
};
|
|
1667
|
+
|
|
1668
|
+
// src/errors/ToolkitErrors.ts
|
|
1669
|
+
var ToolkitErrorCodes = {
|
|
1670
|
+
TOOLKIT_NOT_FOUND: "TOOLKIT_NOT_FOUND"
|
|
1671
|
+
};
|
|
1672
|
+
var ComposioToolkitNotFoundError = class extends ComposioError {
|
|
1673
|
+
constructor(message = "Toolkit not found", options = {}) {
|
|
1674
|
+
super(message, {
|
|
1675
|
+
...options,
|
|
1676
|
+
code: "TOOLKIT_NOT_FOUND",
|
|
1677
|
+
possibleFixes: options.possibleFixes || [
|
|
1678
|
+
"Ensure the toolkit is correctly configured and the slug is valid"
|
|
1679
|
+
]
|
|
1680
|
+
});
|
|
1681
|
+
this.name = "ComposioToolkitNotFoundError";
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
var ComposioToolkitFetchError = class extends ComposioError {
|
|
1685
|
+
constructor(message = "Failed to fetch toolkit", options = {}) {
|
|
1686
|
+
super(message, {
|
|
1687
|
+
...options,
|
|
1688
|
+
code: "TOOLKIT_FETCH_ERROR",
|
|
1689
|
+
possibleFixes: options.possibleFixes || [
|
|
1690
|
+
"Ensure the toolkit slug is valid",
|
|
1691
|
+
"Ensure you are using the correct API key",
|
|
1692
|
+
"Ensure you are using the correct API endpoint / Base URL and it is working"
|
|
1693
|
+
]
|
|
1694
|
+
});
|
|
1695
|
+
this.name = "ComposioToolkitFetchError";
|
|
1696
|
+
}
|
|
1697
|
+
};
|
|
1698
|
+
|
|
1699
|
+
// src/errors/SDKErrors.ts
|
|
1700
|
+
var SDKErrorCodes = {
|
|
1701
|
+
NO_API_KEY_PROVIDED: "NO_API_KEY_PROVIDED"
|
|
1702
|
+
};
|
|
1703
|
+
var ComposioNoAPIKeyError = class extends ComposioError {
|
|
1704
|
+
constructor(message = "No Composio API key provided", options = {}) {
|
|
1705
|
+
const defaultCause = "Couldn't find an API key in the params, environment variables or in the user config file";
|
|
1706
|
+
super(message, {
|
|
1707
|
+
...options,
|
|
1708
|
+
code: "NO_API_KEY",
|
|
1709
|
+
cause: options.cause || defaultCause,
|
|
1710
|
+
possibleFixes: options.possibleFixes || [
|
|
1711
|
+
"Ensure you have an API key passed in the params, or in environment variable (COMPOSIO_API_KEY) or in the user config file",
|
|
1712
|
+
"To get an API key, please sign up at https://composio.dev/signup",
|
|
1713
|
+
"You can also use the Composio CLI to create a project and get an API key"
|
|
1714
|
+
],
|
|
1715
|
+
statusCode: 401
|
|
1716
|
+
});
|
|
1717
|
+
this.name = "ComposioNoAPIKeyError";
|
|
1718
|
+
}
|
|
1719
|
+
};
|
|
973
1720
|
|
|
974
1721
|
// src/types/authConfigs.types.ts
|
|
975
|
-
var
|
|
1722
|
+
var import_zod5 = require("zod");
|
|
976
1723
|
var AuthConfigTypes = {
|
|
977
1724
|
CUSTOM: "use_custom_auth",
|
|
978
1725
|
COMPOSIO_MANAGED: "use_composio_managed_auth"
|
|
@@ -992,7 +1739,7 @@ var AuthSchemeTypes = {
|
|
|
992
1739
|
CALCOM_AUTH: "CALCOM_AUTH",
|
|
993
1740
|
SNOWFLAKE: "SNOWFLAKE"
|
|
994
1741
|
};
|
|
995
|
-
var AuthSchemeEnum =
|
|
1742
|
+
var AuthSchemeEnum = import_zod5.z.enum([
|
|
996
1743
|
"OAUTH2",
|
|
997
1744
|
"OAUTH1",
|
|
998
1745
|
"OAUTH1A",
|
|
@@ -1007,67 +1754,67 @@ var AuthSchemeEnum = import_zod4.z.enum([
|
|
|
1007
1754
|
"CALCOM_AUTH",
|
|
1008
1755
|
"SNOWFLAKE"
|
|
1009
1756
|
]);
|
|
1010
|
-
var CreateCustomAuthConfigParamsSchema =
|
|
1011
|
-
type:
|
|
1012
|
-
name:
|
|
1013
|
-
credentials:
|
|
1757
|
+
var CreateCustomAuthConfigParamsSchema = import_zod5.z.object({
|
|
1758
|
+
type: import_zod5.z.literal("use_custom_auth"),
|
|
1759
|
+
name: import_zod5.z.string().optional(),
|
|
1760
|
+
credentials: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.union([import_zod5.z.string(), import_zod5.z.number(), import_zod5.z.boolean()])),
|
|
1014
1761
|
authScheme: AuthSchemeEnum
|
|
1015
1762
|
});
|
|
1016
|
-
var CreateComposioManagedAuthConfigParamsSchema =
|
|
1017
|
-
type:
|
|
1018
|
-
name:
|
|
1019
|
-
credentials:
|
|
1763
|
+
var CreateComposioManagedAuthConfigParamsSchema = import_zod5.z.object({
|
|
1764
|
+
type: import_zod5.z.literal("use_composio_managed_auth"),
|
|
1765
|
+
name: import_zod5.z.string().optional(),
|
|
1766
|
+
credentials: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.union([import_zod5.z.string(), import_zod5.z.number(), import_zod5.z.boolean()])).optional()
|
|
1020
1767
|
});
|
|
1021
|
-
var CreateAuthConfigParamsSchema =
|
|
1768
|
+
var CreateAuthConfigParamsSchema = import_zod5.z.discriminatedUnion("type", [
|
|
1022
1769
|
CreateCustomAuthConfigParamsSchema,
|
|
1023
1770
|
CreateComposioManagedAuthConfigParamsSchema
|
|
1024
1771
|
]);
|
|
1025
|
-
var CreateAuthConfigResponseSchema =
|
|
1026
|
-
id:
|
|
1027
|
-
authScheme:
|
|
1028
|
-
isComposioManaged:
|
|
1029
|
-
toolkit:
|
|
1772
|
+
var CreateAuthConfigResponseSchema = import_zod5.z.object({
|
|
1773
|
+
id: import_zod5.z.string(),
|
|
1774
|
+
authScheme: import_zod5.z.string(),
|
|
1775
|
+
isComposioManaged: import_zod5.z.boolean(),
|
|
1776
|
+
toolkit: import_zod5.z.string()
|
|
1030
1777
|
});
|
|
1031
|
-
var AuthConfigRetrieveResponseSchema =
|
|
1032
|
-
id:
|
|
1033
|
-
name:
|
|
1034
|
-
toolkit:
|
|
1035
|
-
logo:
|
|
1036
|
-
slug:
|
|
1778
|
+
var AuthConfigRetrieveResponseSchema = import_zod5.z.object({
|
|
1779
|
+
id: import_zod5.z.string(),
|
|
1780
|
+
name: import_zod5.z.string(),
|
|
1781
|
+
toolkit: import_zod5.z.object({
|
|
1782
|
+
logo: import_zod5.z.string(),
|
|
1783
|
+
slug: import_zod5.z.string()
|
|
1037
1784
|
}),
|
|
1038
|
-
noOfConnections:
|
|
1039
|
-
status:
|
|
1040
|
-
uuid:
|
|
1785
|
+
noOfConnections: import_zod5.z.number(),
|
|
1786
|
+
status: import_zod5.z.enum(["ENABLED", "DISABLED"]),
|
|
1787
|
+
uuid: import_zod5.z.string(),
|
|
1041
1788
|
authScheme: AuthSchemeEnum.optional(),
|
|
1042
|
-
credentials:
|
|
1043
|
-
expectedInputFields:
|
|
1044
|
-
isComposioManaged:
|
|
1045
|
-
createdBy:
|
|
1046
|
-
createdAt:
|
|
1047
|
-
lastUpdatedAt:
|
|
1789
|
+
credentials: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1790
|
+
expectedInputFields: import_zod5.z.array(import_zod5.z.unknown()).optional(),
|
|
1791
|
+
isComposioManaged: import_zod5.z.boolean().optional(),
|
|
1792
|
+
createdBy: import_zod5.z.string().optional(),
|
|
1793
|
+
createdAt: import_zod5.z.string().optional(),
|
|
1794
|
+
lastUpdatedAt: import_zod5.z.string().optional()
|
|
1048
1795
|
});
|
|
1049
|
-
var AuthConfigListParamsSchema =
|
|
1050
|
-
cursor:
|
|
1051
|
-
isComposioManaged:
|
|
1052
|
-
limit:
|
|
1053
|
-
|
|
1796
|
+
var AuthConfigListParamsSchema = import_zod5.z.object({
|
|
1797
|
+
cursor: import_zod5.z.string().optional(),
|
|
1798
|
+
isComposioManaged: import_zod5.z.boolean().optional(),
|
|
1799
|
+
limit: import_zod5.z.number().optional(),
|
|
1800
|
+
toolkit: import_zod5.z.string().optional()
|
|
1054
1801
|
});
|
|
1055
|
-
var AuthConfigListResponseSchema =
|
|
1056
|
-
items:
|
|
1057
|
-
nextCursor:
|
|
1058
|
-
totalPages:
|
|
1802
|
+
var AuthConfigListResponseSchema = import_zod5.z.object({
|
|
1803
|
+
items: import_zod5.z.array(AuthConfigRetrieveResponseSchema),
|
|
1804
|
+
nextCursor: import_zod5.z.string().optional(),
|
|
1805
|
+
totalPages: import_zod5.z.number()
|
|
1059
1806
|
});
|
|
1060
|
-
var AuthCustomConfigUpdateParamsSchema =
|
|
1061
|
-
credentials:
|
|
1062
|
-
type:
|
|
1063
|
-
restrictToFollowingTools:
|
|
1807
|
+
var AuthCustomConfigUpdateParamsSchema = import_zod5.z.object({
|
|
1808
|
+
credentials: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.union([import_zod5.z.string(), import_zod5.z.unknown()])),
|
|
1809
|
+
type: import_zod5.z.literal("custom"),
|
|
1810
|
+
restrictToFollowingTools: import_zod5.z.array(import_zod5.z.string()).optional()
|
|
1064
1811
|
});
|
|
1065
|
-
var AuthDefaultConfigUpdateParamsSchema =
|
|
1066
|
-
scopes:
|
|
1067
|
-
type:
|
|
1068
|
-
restrictToFollowingTools:
|
|
1812
|
+
var AuthDefaultConfigUpdateParamsSchema = import_zod5.z.object({
|
|
1813
|
+
scopes: import_zod5.z.string(),
|
|
1814
|
+
type: import_zod5.z.literal("default"),
|
|
1815
|
+
restrictToFollowingTools: import_zod5.z.array(import_zod5.z.string()).optional()
|
|
1069
1816
|
});
|
|
1070
|
-
var AuthConfigUpdateParamsSchema =
|
|
1817
|
+
var AuthConfigUpdateParamsSchema = import_zod5.z.discriminatedUnion("type", [
|
|
1071
1818
|
AuthCustomConfigUpdateParamsSchema,
|
|
1072
1819
|
AuthDefaultConfigUpdateParamsSchema
|
|
1073
1820
|
]);
|
|
@@ -1077,6 +1824,7 @@ var AuthConfigs = class {
|
|
|
1077
1824
|
client;
|
|
1078
1825
|
constructor(client) {
|
|
1079
1826
|
this.client = client;
|
|
1827
|
+
telemetry.instrument(this);
|
|
1080
1828
|
}
|
|
1081
1829
|
/**
|
|
1082
1830
|
* Protected getter for the client instance.
|
|
@@ -1086,6 +1834,18 @@ var AuthConfigs = class {
|
|
|
1086
1834
|
getClient() {
|
|
1087
1835
|
return this.client;
|
|
1088
1836
|
}
|
|
1837
|
+
/**
|
|
1838
|
+
* Transforms an auth config response from API format to SDK format.
|
|
1839
|
+
*
|
|
1840
|
+
* This method converts property names from snake_case to camelCase and reorganizes
|
|
1841
|
+
* the data structure to match the SDK's standardized format for auth configurations.
|
|
1842
|
+
*
|
|
1843
|
+
* @param {ComposioAuthConfigRetrieveResponse} authConfig - The raw API response to transform
|
|
1844
|
+
* @returns {AuthConfigRetrieveResponse} The transformed auth config data
|
|
1845
|
+
* @throws {ValidationError} If the response fails validation against the expected schema
|
|
1846
|
+
*
|
|
1847
|
+
* @private
|
|
1848
|
+
*/
|
|
1089
1849
|
parseAuthConfigRetrieveResponse(authConfig) {
|
|
1090
1850
|
const result = AuthConfigRetrieveResponseSchema.safeParse({
|
|
1091
1851
|
id: authConfig.id,
|
|
@@ -1106,15 +1866,37 @@ var AuthConfigs = class {
|
|
|
1106
1866
|
lastUpdatedAt: authConfig.last_updated_at
|
|
1107
1867
|
});
|
|
1108
1868
|
if (result.error) {
|
|
1109
|
-
throw new ValidationError(
|
|
1869
|
+
throw new ValidationError("Failed to parse auth config response", {
|
|
1870
|
+
cause: result.error
|
|
1871
|
+
});
|
|
1110
1872
|
}
|
|
1111
1873
|
return result.data;
|
|
1112
1874
|
}
|
|
1113
1875
|
/**
|
|
1114
|
-
*
|
|
1115
|
-
*
|
|
1116
|
-
*
|
|
1117
|
-
*
|
|
1876
|
+
* Lists authentication configurations based on provided filter criteria.
|
|
1877
|
+
*
|
|
1878
|
+
* This method retrieves auth configs from the Composio API, transforms them to the SDK format,
|
|
1879
|
+
* and supports filtering by various parameters.
|
|
1880
|
+
*
|
|
1881
|
+
* @param {AuthConfigListParams} [query] - Optional query parameters for filtering auth configs
|
|
1882
|
+
* @returns {Promise<AuthConfigListResponse>} A paginated list of auth configurations
|
|
1883
|
+
* @throws {ValidationError} If the query parameters or response fail validation
|
|
1884
|
+
*
|
|
1885
|
+
* @example
|
|
1886
|
+
* ```typescript
|
|
1887
|
+
* // List all auth configs
|
|
1888
|
+
* const allConfigs = await composio.authConfigs.list();
|
|
1889
|
+
*
|
|
1890
|
+
* // List auth configs for a specific toolkit
|
|
1891
|
+
* const githubConfigs = await composio.authConfigs.list({
|
|
1892
|
+
* toolkit: 'github'
|
|
1893
|
+
* });
|
|
1894
|
+
*
|
|
1895
|
+
* // List Composio-managed auth configs
|
|
1896
|
+
* const managedConfigs = await composio.authConfigs.list({
|
|
1897
|
+
* isComposioManaged: true
|
|
1898
|
+
* });
|
|
1899
|
+
* ```
|
|
1118
1900
|
*/
|
|
1119
1901
|
async list(query) {
|
|
1120
1902
|
const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : void 0;
|
|
@@ -1122,7 +1904,7 @@ var AuthConfigs = class {
|
|
|
1122
1904
|
cursor: parsedQuery?.cursor,
|
|
1123
1905
|
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1124
1906
|
limit: parsedQuery?.limit?.toString(),
|
|
1125
|
-
toolkit_slug: parsedQuery?.
|
|
1907
|
+
toolkit_slug: parsedQuery?.toolkit
|
|
1126
1908
|
});
|
|
1127
1909
|
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
1128
1910
|
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
@@ -1130,7 +1912,9 @@ var AuthConfigs = class {
|
|
|
1130
1912
|
totalPages: result.total_pages
|
|
1131
1913
|
});
|
|
1132
1914
|
if (parsedResult.error) {
|
|
1133
|
-
throw new ValidationError(
|
|
1915
|
+
throw new ValidationError("Failed to parse auth config list response", {
|
|
1916
|
+
cause: parsedResult.error
|
|
1917
|
+
});
|
|
1134
1918
|
}
|
|
1135
1919
|
return parsedResult.data;
|
|
1136
1920
|
}
|
|
@@ -1152,10 +1936,12 @@ var AuthConfigs = class {
|
|
|
1152
1936
|
*
|
|
1153
1937
|
* @link https://docs.composio.dev/reference/auth-configs/create-auth-config
|
|
1154
1938
|
*/
|
|
1155
|
-
async create(toolkit, options) {
|
|
1939
|
+
async create(toolkit, options = { type: "use_composio_managed_auth" }) {
|
|
1156
1940
|
const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
|
|
1157
1941
|
if (parsedOptions.error) {
|
|
1158
|
-
throw new ValidationError(
|
|
1942
|
+
throw new ValidationError("Failed to parse auth config create options", {
|
|
1943
|
+
cause: parsedOptions.error
|
|
1944
|
+
});
|
|
1159
1945
|
}
|
|
1160
1946
|
const result = await this.client.authConfigs.create({
|
|
1161
1947
|
toolkit: {
|
|
@@ -1170,31 +1956,71 @@ var AuthConfigs = class {
|
|
|
1170
1956
|
toolkit: result.toolkit.slug
|
|
1171
1957
|
});
|
|
1172
1958
|
if (parsedResult.error) {
|
|
1173
|
-
throw new ValidationError(
|
|
1959
|
+
throw new ValidationError("Failed to parse auth config create response", {
|
|
1960
|
+
cause: parsedResult.error
|
|
1961
|
+
});
|
|
1174
1962
|
}
|
|
1175
1963
|
return parsedResult.data;
|
|
1176
1964
|
}
|
|
1177
1965
|
/**
|
|
1178
|
-
*
|
|
1179
|
-
*
|
|
1180
|
-
*
|
|
1181
|
-
*
|
|
1966
|
+
* Retrieves a specific authentication configuration by its ID.
|
|
1967
|
+
*
|
|
1968
|
+
* This method fetches detailed information about a single auth config
|
|
1969
|
+
* and transforms the response to the SDK's standardized format.
|
|
1970
|
+
*
|
|
1971
|
+
* @param {string} nanoid - The unique identifier of the auth config to retrieve
|
|
1972
|
+
* @returns {Promise<AuthConfigRetrieveResponse>} The auth config details
|
|
1973
|
+
* @throws {Error} If the auth config cannot be found or an API error occurs
|
|
1974
|
+
* @throws {ValidationError} If the response fails validation
|
|
1975
|
+
*
|
|
1976
|
+
* @example
|
|
1977
|
+
* ```typescript
|
|
1978
|
+
* // Get an auth config by ID
|
|
1979
|
+
* const authConfig = await composio.authConfigs.get('auth_abc123');
|
|
1980
|
+
* console.log(authConfig.name); // e.g., 'GitHub Auth'
|
|
1981
|
+
* console.log(authConfig.toolkit.slug); // e.g., 'github'
|
|
1982
|
+
* ```
|
|
1182
1983
|
*/
|
|
1183
1984
|
async get(nanoid) {
|
|
1184
1985
|
const result = await this.client.authConfigs.retrieve(nanoid);
|
|
1185
1986
|
return this.parseAuthConfigRetrieveResponse(result);
|
|
1186
1987
|
}
|
|
1187
1988
|
/**
|
|
1188
|
-
*
|
|
1189
|
-
*
|
|
1190
|
-
*
|
|
1191
|
-
*
|
|
1192
|
-
*
|
|
1989
|
+
* Updates an existing authentication configuration.
|
|
1990
|
+
*
|
|
1991
|
+
* This method allows you to modify properties of an auth config such as credentials,
|
|
1992
|
+
* scopes, or tool restrictions. The update type (custom or default) determines which
|
|
1993
|
+
* fields can be updated.
|
|
1994
|
+
*
|
|
1995
|
+
* @param {string} nanoid - The unique identifier of the auth config to update
|
|
1996
|
+
* @param {AuthConfigUpdateParams} data - The data to update, which can be either custom or default type
|
|
1997
|
+
* @returns {Promise<AuthConfigUpdateResponse>} The updated auth config
|
|
1998
|
+
* @throws {ValidationError} If the update parameters are invalid
|
|
1999
|
+
* @throws {Error} If the auth config cannot be found or updated
|
|
2000
|
+
*
|
|
2001
|
+
* @example
|
|
2002
|
+
* ```typescript
|
|
2003
|
+
* // Update a custom auth config with new credentials
|
|
2004
|
+
* const updatedConfig = await composio.authConfigs.update('auth_abc123', {
|
|
2005
|
+
* type: 'custom',
|
|
2006
|
+
* credentials: {
|
|
2007
|
+
* apiKey: 'new-api-key-value'
|
|
2008
|
+
* }
|
|
2009
|
+
* });
|
|
2010
|
+
*
|
|
2011
|
+
* // Update a default auth config with new scopes
|
|
2012
|
+
* const updatedConfig = await composio.authConfigs.update('auth_abc123', {
|
|
2013
|
+
* type: 'default',
|
|
2014
|
+
* scopes: ['read:user', 'repo']
|
|
2015
|
+
* });
|
|
2016
|
+
* ```
|
|
1193
2017
|
*/
|
|
1194
2018
|
async update(nanoid, data) {
|
|
1195
2019
|
const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
|
|
1196
2020
|
if (parsedData.error) {
|
|
1197
|
-
throw new ValidationError(
|
|
2021
|
+
throw new ValidationError("Failed to parse auth config update data", {
|
|
2022
|
+
cause: parsedData.error
|
|
2023
|
+
});
|
|
1198
2024
|
}
|
|
1199
2025
|
return this.client.authConfigs.update(
|
|
1200
2026
|
nanoid,
|
|
@@ -1210,65 +2036,93 @@ var AuthConfigs = class {
|
|
|
1210
2036
|
);
|
|
1211
2037
|
}
|
|
1212
2038
|
/**
|
|
1213
|
-
*
|
|
1214
|
-
*
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
2039
|
+
* Deletes an authentication configuration.
|
|
2040
|
+
*
|
|
2041
|
+
* This method permanently removes an auth config from the Composio platform.
|
|
2042
|
+
* This action cannot be undone and will prevent any connected accounts that use
|
|
2043
|
+
* this auth config from functioning.
|
|
2044
|
+
*
|
|
2045
|
+
* @param {string} nanoid - The unique identifier of the auth config to delete
|
|
2046
|
+
* @returns {Promise<AuthConfigDeleteResponse>} The deletion response
|
|
2047
|
+
* @throws {Error} If the auth config doesn't exist or cannot be deleted
|
|
2048
|
+
*
|
|
2049
|
+
* @example
|
|
2050
|
+
* ```typescript
|
|
2051
|
+
* // Delete an auth config
|
|
2052
|
+
* await composio.authConfigs.delete('auth_abc123');
|
|
2053
|
+
* ```
|
|
1217
2054
|
*/
|
|
1218
2055
|
async delete(nanoid) {
|
|
1219
2056
|
return this.client.authConfigs.delete(nanoid);
|
|
1220
2057
|
}
|
|
1221
2058
|
/**
|
|
1222
|
-
*
|
|
1223
|
-
*
|
|
1224
|
-
*
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
2059
|
+
* Updates the status of an authentication configuration.
|
|
2060
|
+
*
|
|
2061
|
+
* This method allows you to enable or disable an auth config. When disabled,
|
|
2062
|
+
* the auth config cannot be used to create new connected accounts or authenticate
|
|
2063
|
+
* with third-party services.
|
|
2064
|
+
*
|
|
2065
|
+
* @param {string} status - The status to set ('ENABLED' or 'DISABLED')
|
|
2066
|
+
* @param {string} nanoid - The unique identifier of the auth config
|
|
2067
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
2068
|
+
* @throws {Error} If the auth config cannot be found or the status cannot be updated
|
|
2069
|
+
*
|
|
2070
|
+
* @example
|
|
2071
|
+
* ```typescript
|
|
2072
|
+
* // Disable an auth config
|
|
2073
|
+
* await composio.authConfigs.updateStatus('DISABLED', 'auth_abc123');
|
|
2074
|
+
*
|
|
2075
|
+
* // Enable an auth config
|
|
2076
|
+
* await composio.authConfigs.updateStatus('ENABLED', 'auth_abc123');
|
|
2077
|
+
* ```
|
|
1227
2078
|
*/
|
|
1228
2079
|
async updateStatus(status, nanoid) {
|
|
1229
2080
|
return this.client.authConfigs.updateStatus(status, { nanoid });
|
|
1230
2081
|
}
|
|
1231
2082
|
/**
|
|
1232
|
-
*
|
|
1233
|
-
*
|
|
1234
|
-
*
|
|
1235
|
-
*
|
|
2083
|
+
* Enables an authentication configuration.
|
|
2084
|
+
*
|
|
2085
|
+
* This is a convenience method that calls updateStatus with 'ENABLED'.
|
|
2086
|
+
* When enabled, the auth config can be used to create new connected accounts
|
|
2087
|
+
* and authenticate with third-party services.
|
|
2088
|
+
*
|
|
2089
|
+
* @param {string} nanoid - The unique identifier of the auth config to enable
|
|
2090
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
2091
|
+
* @throws {Error} If the auth config cannot be found or enabled
|
|
2092
|
+
*
|
|
2093
|
+
* @example
|
|
2094
|
+
* ```typescript
|
|
2095
|
+
* // Enable an auth config
|
|
2096
|
+
* await composio.authConfigs.enable('auth_abc123');
|
|
2097
|
+
* ```
|
|
1236
2098
|
*/
|
|
1237
2099
|
async enable(nanoid) {
|
|
1238
2100
|
return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
|
|
1239
2101
|
}
|
|
1240
2102
|
/**
|
|
1241
|
-
*
|
|
1242
|
-
*
|
|
1243
|
-
*
|
|
1244
|
-
*
|
|
2103
|
+
* Disables an authentication configuration.
|
|
2104
|
+
*
|
|
2105
|
+
* This is a convenience method that calls updateStatus with 'DISABLED'.
|
|
2106
|
+
* When disabled, the auth config cannot be used to create new connected accounts
|
|
2107
|
+
* or authenticate with third-party services, but existing connections may continue to work.
|
|
2108
|
+
*
|
|
2109
|
+
* @param {string} nanoid - The unique identifier of the auth config to disable
|
|
2110
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
2111
|
+
* @throws {Error} If the auth config cannot be found or disabled
|
|
2112
|
+
*
|
|
2113
|
+
* @example
|
|
2114
|
+
* ```typescript
|
|
2115
|
+
* // Disable an auth config
|
|
2116
|
+
* await composio.authConfigs.disable('auth_abc123');
|
|
2117
|
+
* ```
|
|
1245
2118
|
*/
|
|
1246
2119
|
async disable(nanoid) {
|
|
1247
2120
|
return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
|
|
1248
2121
|
}
|
|
1249
2122
|
};
|
|
1250
2123
|
|
|
1251
|
-
// src/errors/AuthConfigErrors.ts
|
|
1252
|
-
var AuthConfigErrorCodes = {
|
|
1253
|
-
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1254
|
-
};
|
|
1255
|
-
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1256
|
-
constructor(message, meta) {
|
|
1257
|
-
super(message, {
|
|
1258
|
-
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1259
|
-
cause: meta,
|
|
1260
|
-
possibleFixes: [
|
|
1261
|
-
"Check if the auth config exists",
|
|
1262
|
-
"Check if the auth config id is correct",
|
|
1263
|
-
"Check if the auth config is enabled"
|
|
1264
|
-
]
|
|
1265
|
-
});
|
|
1266
|
-
this.name = "ComposioAuthConfigNotFoundError";
|
|
1267
|
-
}
|
|
1268
|
-
};
|
|
1269
|
-
|
|
1270
2124
|
// src/types/connectedAccounts.types.ts
|
|
1271
|
-
var
|
|
2125
|
+
var import_zod6 = require("zod");
|
|
1272
2126
|
var ConnectedAccountStatuses = {
|
|
1273
2127
|
ACTIVE: "ACTIVE",
|
|
1274
2128
|
INACTIVE: "INACTIVE",
|
|
@@ -1277,7 +2131,7 @@ var ConnectedAccountStatuses = {
|
|
|
1277
2131
|
EXPIRED: "EXPIRED",
|
|
1278
2132
|
FAILED: "FAILED"
|
|
1279
2133
|
};
|
|
1280
|
-
var ConnectedAccountStatusSchema =
|
|
2134
|
+
var ConnectedAccountStatusSchema = import_zod6.z.enum([
|
|
1281
2135
|
ConnectedAccountStatuses.ACTIVE,
|
|
1282
2136
|
ConnectedAccountStatuses.INACTIVE,
|
|
1283
2137
|
ConnectedAccountStatuses.DELETED,
|
|
@@ -1285,34 +2139,34 @@ var ConnectedAccountStatusSchema = import_zod5.z.enum([
|
|
|
1285
2139
|
ConnectedAccountStatuses.EXPIRED,
|
|
1286
2140
|
ConnectedAccountStatuses.FAILED
|
|
1287
2141
|
]);
|
|
1288
|
-
var CreateConnectedAccountParamsSchema =
|
|
1289
|
-
authConfig:
|
|
1290
|
-
id:
|
|
2142
|
+
var CreateConnectedAccountParamsSchema = import_zod6.z.object({
|
|
2143
|
+
authConfig: import_zod6.z.object({
|
|
2144
|
+
id: import_zod6.z.string()
|
|
1291
2145
|
}),
|
|
1292
|
-
connection:
|
|
1293
|
-
data:
|
|
1294
|
-
|
|
1295
|
-
userId:
|
|
2146
|
+
connection: import_zod6.z.object({
|
|
2147
|
+
data: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.unknown()).optional(),
|
|
2148
|
+
callbackUrl: import_zod6.z.string().optional(),
|
|
2149
|
+
userId: import_zod6.z.string().optional()
|
|
1296
2150
|
})
|
|
1297
2151
|
});
|
|
1298
|
-
var DefaultCreateConnectedAccountParamsSchema =
|
|
1299
|
-
auth_config:
|
|
1300
|
-
id:
|
|
2152
|
+
var DefaultCreateConnectedAccountParamsSchema = import_zod6.z.object({
|
|
2153
|
+
auth_config: import_zod6.z.object({
|
|
2154
|
+
id: import_zod6.z.string()
|
|
1301
2155
|
}),
|
|
1302
|
-
connection:
|
|
1303
|
-
data:
|
|
1304
|
-
|
|
1305
|
-
user_id:
|
|
2156
|
+
connection: import_zod6.z.object({
|
|
2157
|
+
data: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.unknown()).optional(),
|
|
2158
|
+
callback_url: import_zod6.z.string().optional(),
|
|
2159
|
+
user_id: import_zod6.z.string().optional()
|
|
1306
2160
|
})
|
|
1307
2161
|
});
|
|
1308
|
-
var CreateConnectedAccountOptionsSchema =
|
|
1309
|
-
|
|
1310
|
-
data:
|
|
2162
|
+
var CreateConnectedAccountOptionsSchema = import_zod6.z.object({
|
|
2163
|
+
callbackUrl: import_zod6.z.string().optional(),
|
|
2164
|
+
data: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.unknown()).optional()
|
|
1311
2165
|
});
|
|
1312
|
-
var CreateConnectedAccountResponseSchema =
|
|
1313
|
-
id:
|
|
2166
|
+
var CreateConnectedAccountResponseSchema = import_zod6.z.object({
|
|
2167
|
+
id: import_zod6.z.string(),
|
|
1314
2168
|
status: ConnectedAccountStatusSchema,
|
|
1315
|
-
redirectUrl:
|
|
2169
|
+
redirectUrl: import_zod6.z.string().nullable()
|
|
1316
2170
|
});
|
|
1317
2171
|
var ConnectedAccountAuthSchemes = {
|
|
1318
2172
|
OAUTH2: "OAUTH2",
|
|
@@ -1329,7 +2183,7 @@ var ConnectedAccountAuthSchemes = {
|
|
|
1329
2183
|
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1330
2184
|
SNOWFLAKE: "SNOWFLAKE"
|
|
1331
2185
|
};
|
|
1332
|
-
var ConnectedAccountAuthSchemesSchema =
|
|
2186
|
+
var ConnectedAccountAuthSchemesSchema = import_zod6.z.enum([
|
|
1333
2187
|
ConnectedAccountAuthSchemes.OAUTH2,
|
|
1334
2188
|
ConnectedAccountAuthSchemes.OAUTH1,
|
|
1335
2189
|
ConnectedAccountAuthSchemes.OAUTH1A,
|
|
@@ -1344,72 +2198,70 @@ var ConnectedAccountAuthSchemesSchema = import_zod5.z.enum([
|
|
|
1344
2198
|
ConnectedAccountAuthSchemes.CALCOM_AUTH,
|
|
1345
2199
|
ConnectedAccountAuthSchemes.SNOWFLAKE
|
|
1346
2200
|
]);
|
|
1347
|
-
var ConnectedAccountAuthConfigSchema =
|
|
1348
|
-
id:
|
|
2201
|
+
var ConnectedAccountAuthConfigSchema = import_zod6.z.object({
|
|
2202
|
+
id: import_zod6.z.string(),
|
|
1349
2203
|
authScheme: ConnectedAccountAuthSchemesSchema,
|
|
1350
|
-
isComposioManaged:
|
|
1351
|
-
isDisabled:
|
|
2204
|
+
isComposioManaged: import_zod6.z.boolean(),
|
|
2205
|
+
isDisabled: import_zod6.z.boolean()
|
|
1352
2206
|
});
|
|
1353
|
-
var ConnectedAccountRetrieveResponseSchema =
|
|
1354
|
-
id:
|
|
2207
|
+
var ConnectedAccountRetrieveResponseSchema = import_zod6.z.object({
|
|
2208
|
+
id: import_zod6.z.string(),
|
|
1355
2209
|
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1356
|
-
userId:
|
|
1357
|
-
data:
|
|
1358
|
-
params:
|
|
2210
|
+
userId: import_zod6.z.string(),
|
|
2211
|
+
data: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.unknown()),
|
|
2212
|
+
params: import_zod6.z.record(import_zod6.z.string(), import_zod6.z.unknown()).optional(),
|
|
1359
2213
|
status: ConnectedAccountStatusSchema,
|
|
1360
|
-
statusReason:
|
|
1361
|
-
toolkit:
|
|
1362
|
-
slug:
|
|
2214
|
+
statusReason: import_zod6.z.string().nullable(),
|
|
2215
|
+
toolkit: import_zod6.z.object({
|
|
2216
|
+
slug: import_zod6.z.string()
|
|
1363
2217
|
}),
|
|
1364
|
-
testRequestEndpoint:
|
|
1365
|
-
isDisabled:
|
|
1366
|
-
createdAt:
|
|
1367
|
-
updatedAt:
|
|
2218
|
+
testRequestEndpoint: import_zod6.z.string().optional(),
|
|
2219
|
+
isDisabled: import_zod6.z.boolean(),
|
|
2220
|
+
createdAt: import_zod6.z.string(),
|
|
2221
|
+
updatedAt: import_zod6.z.string()
|
|
2222
|
+
});
|
|
2223
|
+
var ConnectedAccountListParamsSchema = import_zod6.z.object({
|
|
2224
|
+
authConfigIds: import_zod6.z.array(import_zod6.z.string()).nullable().optional().describe("The auth config ids of the connected accounts"),
|
|
2225
|
+
cursor: import_zod6.z.number().nullable().optional().describe("The cursor to paginate through the connected accounts"),
|
|
2226
|
+
labels: import_zod6.z.array(import_zod6.z.string()).nullable().optional().describe("The labels of the connected accounts"),
|
|
2227
|
+
limit: import_zod6.z.number().nullable().optional().describe("The limit of the connected accounts to return"),
|
|
2228
|
+
orderBy: import_zod6.z.enum(["created_at", "updated_at"]).optional().describe("The order by of the connected accounts"),
|
|
2229
|
+
statuses: import_zod6.z.array(ConnectedAccountStatusSchema).nullable().optional().describe("The statuses of the connected accounts"),
|
|
2230
|
+
toolkitSlugs: import_zod6.z.array(import_zod6.z.string()).nullable().optional().describe("The toolkit slugs of the connected accounts"),
|
|
2231
|
+
userIds: import_zod6.z.array(import_zod6.z.string()).nullable().optional().describe("The user ids of the connected accounts")
|
|
2232
|
+
});
|
|
2233
|
+
var ConnectedAccountListResponseSchema = import_zod6.z.object({
|
|
2234
|
+
items: import_zod6.z.array(ConnectedAccountRetrieveResponseSchema).describe("The list of connected accounts"),
|
|
2235
|
+
nextCursor: import_zod6.z.string().nullable().describe("The next cursor to paginate through the connected accounts"),
|
|
2236
|
+
totalPages: import_zod6.z.number().describe("The total number of pages of connected accounts")
|
|
1368
2237
|
});
|
|
1369
2238
|
|
|
1370
2239
|
// src/models/ConnectionRequest.ts
|
|
1371
|
-
var
|
|
1372
|
-
|
|
1373
|
-
// src/errors/ConnectionRequestError.ts
|
|
1374
|
-
var ConnectionRequestErrorCodes = {
|
|
1375
|
-
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1376
|
-
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1377
|
-
};
|
|
1378
|
-
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1379
|
-
constructor(message = "Connection request timed out", meta = {}) {
|
|
1380
|
-
super(message, {
|
|
1381
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
|
|
1382
|
-
meta
|
|
1383
|
-
});
|
|
1384
|
-
this.name = "ConnectionRequestTimeoutError";
|
|
1385
|
-
}
|
|
1386
|
-
};
|
|
1387
|
-
var ConnectionRequestFailedError = class extends ComposioError {
|
|
1388
|
-
constructor(message = "Connection request failed", meta = {}) {
|
|
1389
|
-
super(message, {
|
|
1390
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED,
|
|
1391
|
-
meta
|
|
1392
|
-
});
|
|
1393
|
-
this.name = "ConnectionRequestFailedError";
|
|
1394
|
-
}
|
|
1395
|
-
};
|
|
1396
|
-
|
|
1397
|
-
// src/models/ConnectionRequest.ts
|
|
2240
|
+
var import_client3 = __toESM(require("@composio/client"), 1);
|
|
2241
|
+
var import_zod7 = require("zod");
|
|
1398
2242
|
var ConnectionRequest = class {
|
|
1399
2243
|
client;
|
|
1400
|
-
|
|
1401
|
-
|
|
2244
|
+
id;
|
|
2245
|
+
status;
|
|
1402
2246
|
redirectUrl;
|
|
1403
|
-
constructor(client, connectedAccountId,
|
|
2247
|
+
constructor(client, connectedAccountId, status, redirectUrl) {
|
|
1404
2248
|
this.client = client;
|
|
1405
|
-
this.
|
|
1406
|
-
this.
|
|
2249
|
+
this.id = connectedAccountId;
|
|
2250
|
+
this.status = status || ConnectedAccountStatuses.INITIATED;
|
|
1407
2251
|
this.redirectUrl = redirectUrl;
|
|
2252
|
+
telemetry.instrument(this);
|
|
1408
2253
|
}
|
|
1409
2254
|
/**
|
|
1410
|
-
*
|
|
1411
|
-
*
|
|
1412
|
-
*
|
|
2255
|
+
* Transforms the raw connected account response from the Composio API to the SDK format.
|
|
2256
|
+
*
|
|
2257
|
+
* This method converts property names from snake_case to camelCase and reorganizes
|
|
2258
|
+
* the data structure to match the SDK's standardized format.
|
|
2259
|
+
*
|
|
2260
|
+
* @param {OriginalConnectedAccountResponse} response - The raw API response to transform
|
|
2261
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The transformed response
|
|
2262
|
+
* @throws {ZodError} If the response fails validation against the expected schema
|
|
2263
|
+
*
|
|
2264
|
+
* @private
|
|
1413
2265
|
*/
|
|
1414
2266
|
async transformResponse(response) {
|
|
1415
2267
|
try {
|
|
@@ -1432,22 +2284,58 @@ var ConnectionRequest = class {
|
|
|
1432
2284
|
return parsedResponse;
|
|
1433
2285
|
} catch (error) {
|
|
1434
2286
|
logger_default.error("Error transforming response", error);
|
|
1435
|
-
if (error instanceof
|
|
2287
|
+
if (error instanceof import_zod7.ZodError) {
|
|
1436
2288
|
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1437
2289
|
}
|
|
1438
2290
|
throw error;
|
|
1439
2291
|
}
|
|
1440
2292
|
}
|
|
1441
2293
|
/**
|
|
1442
|
-
*
|
|
1443
|
-
*
|
|
1444
|
-
*
|
|
1445
|
-
*
|
|
2294
|
+
* Waits for the connection request to complete and become active.
|
|
2295
|
+
*
|
|
2296
|
+
* This method continuously polls the Composio API to check the status of the connection request
|
|
2297
|
+
* until it either becomes active, enters a terminal error state, or times out.
|
|
2298
|
+
*
|
|
2299
|
+
* @param {number} [timeout=60000] - Maximum time to wait in milliseconds before timing out (default: 60 seconds)
|
|
2300
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The final connected account response when successful
|
|
2301
|
+
* @throws {ComposioConnectedAccountNotFoundError} If the connected account cannot be found
|
|
2302
|
+
* @throws {ConnectionRequestFailedError} If the connection enters a failed, expired, or deleted state
|
|
2303
|
+
* @throws {ConnectionRequestTimeoutError} If the connection request does not complete within the timeout period
|
|
2304
|
+
*
|
|
2305
|
+
* @example
|
|
2306
|
+
* ```typescript
|
|
2307
|
+
* // Wait for connection with default timeout (60 seconds)
|
|
2308
|
+
* try {
|
|
2309
|
+
* const connection = await connectionRequest.waitForConnection();
|
|
2310
|
+
* console.log('Connection established:', connection.id);
|
|
2311
|
+
* } catch (error) {
|
|
2312
|
+
* console.error('Connection failed:', error.message);
|
|
2313
|
+
* }
|
|
2314
|
+
*
|
|
2315
|
+
* // Wait for connection with custom timeout (2 minutes)
|
|
2316
|
+
* const connection = await connectionRequest.waitForConnection(120000);
|
|
2317
|
+
* ```
|
|
1446
2318
|
*/
|
|
1447
2319
|
async waitForConnection(timeout = 6e4) {
|
|
1448
|
-
|
|
1449
|
-
const response = await this.client.connectedAccounts.retrieve(this.
|
|
1450
|
-
|
|
2320
|
+
try {
|
|
2321
|
+
const response = await this.client.connectedAccounts.retrieve(this.id);
|
|
2322
|
+
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
2323
|
+
this.status = ConnectedAccountStatuses.ACTIVE;
|
|
2324
|
+
return this.transformResponse(response);
|
|
2325
|
+
}
|
|
2326
|
+
} catch (error) {
|
|
2327
|
+
if (error instanceof import_client3.default.NotFoundError) {
|
|
2328
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
2329
|
+
`Connected account with id ${this.id} not found`,
|
|
2330
|
+
{
|
|
2331
|
+
meta: {
|
|
2332
|
+
connectedAccountId: this.id
|
|
2333
|
+
}
|
|
2334
|
+
}
|
|
2335
|
+
);
|
|
2336
|
+
} else {
|
|
2337
|
+
throw error;
|
|
2338
|
+
}
|
|
1451
2339
|
}
|
|
1452
2340
|
const terminalErrorStates = [
|
|
1453
2341
|
ConnectedAccountStatuses.FAILED,
|
|
@@ -1458,7 +2346,8 @@ var ConnectionRequest = class {
|
|
|
1458
2346
|
const pollInterval = 1e3;
|
|
1459
2347
|
while (Date.now() - start < timeout) {
|
|
1460
2348
|
try {
|
|
1461
|
-
const response = await this.client.connectedAccounts.retrieve(this.
|
|
2349
|
+
const response = await this.client.connectedAccounts.retrieve(this.id);
|
|
2350
|
+
this.status = response.status;
|
|
1462
2351
|
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1463
2352
|
return this.transformResponse(response);
|
|
1464
2353
|
}
|
|
@@ -1466,10 +2355,12 @@ var ConnectionRequest = class {
|
|
|
1466
2355
|
throw new ConnectionRequestFailedError(
|
|
1467
2356
|
`Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ""}`,
|
|
1468
2357
|
{
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
2358
|
+
meta: {
|
|
2359
|
+
userId: response.user_id,
|
|
2360
|
+
connectedAccountId: this.id,
|
|
2361
|
+
status: response.status,
|
|
2362
|
+
statusReason: response.status_reason
|
|
2363
|
+
}
|
|
1473
2364
|
}
|
|
1474
2365
|
);
|
|
1475
2366
|
}
|
|
@@ -1478,9 +2369,7 @@ var ConnectionRequest = class {
|
|
|
1478
2369
|
throw error;
|
|
1479
2370
|
}
|
|
1480
2371
|
}
|
|
1481
|
-
throw new ConnectionRequestTimeoutError(
|
|
1482
|
-
`Connection request timed out for ${this.connectedAccountId}`
|
|
1483
|
-
);
|
|
2372
|
+
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${this.id}`);
|
|
1484
2373
|
}
|
|
1485
2374
|
};
|
|
1486
2375
|
|
|
@@ -1489,15 +2378,103 @@ var ConnectedAccounts = class {
|
|
|
1489
2378
|
client;
|
|
1490
2379
|
constructor(client) {
|
|
1491
2380
|
this.client = client;
|
|
2381
|
+
telemetry.instrument(this);
|
|
2382
|
+
}
|
|
2383
|
+
transformConnectedAccountRetrieveResponse(response) {
|
|
2384
|
+
const result = ConnectedAccountRetrieveResponseSchema.safeParse({
|
|
2385
|
+
...response,
|
|
2386
|
+
userId: response.user_id,
|
|
2387
|
+
// Add the missing userId property
|
|
2388
|
+
authConfig: {
|
|
2389
|
+
...response.auth_config,
|
|
2390
|
+
authScheme: response.auth_config.auth_scheme,
|
|
2391
|
+
isComposioManaged: response.auth_config.is_composio_managed,
|
|
2392
|
+
isDisabled: response.auth_config.is_disabled
|
|
2393
|
+
},
|
|
2394
|
+
statusReason: response.status_reason,
|
|
2395
|
+
isDisabled: response.is_disabled,
|
|
2396
|
+
createdAt: response.created_at,
|
|
2397
|
+
updatedAt: response.updated_at,
|
|
2398
|
+
testRequestEndpoint: response.test_request_endpoint
|
|
2399
|
+
});
|
|
2400
|
+
if (!result.success) {
|
|
2401
|
+
throw new ValidationError("Failed to parse connected account retrieve response", {
|
|
2402
|
+
cause: result.error
|
|
2403
|
+
});
|
|
2404
|
+
}
|
|
2405
|
+
return result.data;
|
|
1492
2406
|
}
|
|
1493
2407
|
/**
|
|
1494
|
-
*
|
|
1495
|
-
*
|
|
1496
|
-
*
|
|
1497
|
-
*
|
|
2408
|
+
* Lists all connected accounts based on provided filter criteria.
|
|
2409
|
+
*
|
|
2410
|
+
* This method retrieves connected accounts from the Composio API with optional filtering.
|
|
2411
|
+
*
|
|
2412
|
+
* @param {ConnectedAccountListParams} [query] - Optional query parameters for filtering connected accounts
|
|
2413
|
+
* @returns {Promise<ConnectedAccountListResponse>} A paginated list of connected accounts
|
|
2414
|
+
* @throws {ValidationError} If the query fails validation against the expected schema
|
|
2415
|
+
* @example
|
|
2416
|
+
* ```typescript
|
|
2417
|
+
* // List all connected accounts
|
|
2418
|
+
* const allAccounts = await composio.connectedAccounts.list();
|
|
2419
|
+
*
|
|
2420
|
+
* // List accounts for a specific user
|
|
2421
|
+
* const userAccounts = await composio.connectedAccounts.list({
|
|
2422
|
+
* userIds: ['user123']
|
|
2423
|
+
* });
|
|
2424
|
+
*
|
|
2425
|
+
* // List accounts for a specific toolkit
|
|
2426
|
+
* const githubAccounts = await composio.connectedAccounts.list({
|
|
2427
|
+
* toolkitSlugs: ['github']
|
|
2428
|
+
* });
|
|
2429
|
+
* ```
|
|
1498
2430
|
*/
|
|
1499
2431
|
async list(query) {
|
|
1500
|
-
|
|
2432
|
+
let rawQuery = void 0;
|
|
2433
|
+
if (query) {
|
|
2434
|
+
const parsedQuery = ConnectedAccountListParamsSchema.safeParse(query);
|
|
2435
|
+
if (!parsedQuery.success) {
|
|
2436
|
+
throw new ValidationError("Failed to parse connected account list query", {
|
|
2437
|
+
cause: parsedQuery.error
|
|
2438
|
+
});
|
|
2439
|
+
}
|
|
2440
|
+
rawQuery = {
|
|
2441
|
+
auth_config_ids: parsedQuery.data.authConfigIds,
|
|
2442
|
+
cursor: parsedQuery.data.cursor,
|
|
2443
|
+
labels: parsedQuery.data.labels,
|
|
2444
|
+
limit: parsedQuery.data.limit,
|
|
2445
|
+
order_by: parsedQuery.data.orderBy,
|
|
2446
|
+
statuses: parsedQuery.data.statuses,
|
|
2447
|
+
toolkit_slugs: parsedQuery.data.toolkitSlugs,
|
|
2448
|
+
user_ids: parsedQuery.data.userIds
|
|
2449
|
+
};
|
|
2450
|
+
}
|
|
2451
|
+
const result = await this.client.connectedAccounts.list(rawQuery);
|
|
2452
|
+
const parsedResponse = ConnectedAccountListResponseSchema.safeParse({
|
|
2453
|
+
items: result.items.map(this.transformConnectedAccountRetrieveResponse),
|
|
2454
|
+
nextCursor: result.next_cursor,
|
|
2455
|
+
totalPages: result.total_pages
|
|
2456
|
+
});
|
|
2457
|
+
if (!parsedResponse.success) {
|
|
2458
|
+
throw new ValidationError("Failed to parse connected account list response", {
|
|
2459
|
+
cause: parsedResponse.error
|
|
2460
|
+
});
|
|
2461
|
+
}
|
|
2462
|
+
return parsedResponse.data;
|
|
2463
|
+
}
|
|
2464
|
+
/**
|
|
2465
|
+
* Transforms connected account data from API format to SDK format.
|
|
2466
|
+
*
|
|
2467
|
+
* This method converts property names from snake_case to camelCase and reorganizes
|
|
2468
|
+
* the data structure to match the SDK's standardized format for connected accounts.
|
|
2469
|
+
*
|
|
2470
|
+
* @param {ConnectedAccountRetrieveResponseRaw} response - The raw API response to transform
|
|
2471
|
+
* @returns {ConnectedAccountRetrieveResponse} The transformed connected account data
|
|
2472
|
+
* @throws {ValidationError} If the response fails validation against the expected schema
|
|
2473
|
+
*
|
|
2474
|
+
* @private
|
|
2475
|
+
*/
|
|
2476
|
+
transformConnectedAccountResponse(response) {
|
|
2477
|
+
return this.transformConnectedAccountRetrieveResponse(response);
|
|
1501
2478
|
}
|
|
1502
2479
|
/**
|
|
1503
2480
|
* Compound function to create a new connected account.
|
|
@@ -1524,35 +2501,94 @@ var ConnectedAccounts = class {
|
|
|
1524
2501
|
},
|
|
1525
2502
|
connection: {
|
|
1526
2503
|
data: options?.data,
|
|
1527
|
-
|
|
2504
|
+
callback_url: options?.callbackUrl,
|
|
1528
2505
|
user_id: userId
|
|
1529
2506
|
}
|
|
1530
2507
|
});
|
|
1531
|
-
return new ConnectionRequest(this.client, response.id, response.status, response.
|
|
2508
|
+
return new ConnectionRequest(this.client, response.id, response.status, response.redirect_url);
|
|
1532
2509
|
}
|
|
1533
2510
|
/**
|
|
1534
|
-
*
|
|
1535
|
-
*
|
|
1536
|
-
*
|
|
1537
|
-
*
|
|
2511
|
+
* Waits for a connection request to complete and become active.
|
|
2512
|
+
*
|
|
2513
|
+
* This method continuously polls the Composio API to check the status of a connection
|
|
2514
|
+
* until it either becomes active, enters a terminal error state, or times out.
|
|
2515
|
+
*
|
|
2516
|
+
* @param {string} connectedAccountId - The ID of the connected account to wait for
|
|
2517
|
+
* @param {number} [timeout=60000] - Maximum time to wait in milliseconds (default: 60 seconds)
|
|
2518
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The finalized connected account data
|
|
2519
|
+
* @throws {ComposioConnectedAccountNotFoundError} If the connected account cannot be found
|
|
2520
|
+
* @throws {ConnectionRequestFailedError} If the connection enters a failed, expired, or deleted state
|
|
2521
|
+
* @throws {ConnectionRequestTimeoutError} If the connection does not complete within the timeout period
|
|
2522
|
+
*
|
|
2523
|
+
* @example
|
|
2524
|
+
* ```typescript
|
|
2525
|
+
* // Wait for a connection to complete with default timeout
|
|
2526
|
+
* const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc');
|
|
2527
|
+
*
|
|
2528
|
+
* // Wait with a custom timeout of 2 minutes
|
|
2529
|
+
* const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_123abc', 120000);
|
|
2530
|
+
* ```
|
|
2531
|
+
*/
|
|
2532
|
+
async waitForConnection(connectedAccountId, timeout = 6e4) {
|
|
2533
|
+
const connectionRequest = new ConnectionRequest(this.client, connectedAccountId);
|
|
2534
|
+
return connectionRequest.waitForConnection(timeout);
|
|
2535
|
+
}
|
|
2536
|
+
/**
|
|
2537
|
+
* Retrieves a specific connected account by its ID.
|
|
2538
|
+
*
|
|
2539
|
+
* This method fetches detailed information about a single connected account
|
|
2540
|
+
* and transforms the response to the SDK's standardized format.
|
|
2541
|
+
*
|
|
2542
|
+
* @param {string} nanoid - The unique identifier of the connected account
|
|
2543
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} The connected account details
|
|
2544
|
+
* @throws {Error} If the connected account cannot be found or an API error occurs
|
|
2545
|
+
*
|
|
2546
|
+
* @example
|
|
2547
|
+
* ```typescript
|
|
2548
|
+
* // Get a connected account by ID
|
|
2549
|
+
* const account = await composio.connectedAccounts.get('conn_abc123');
|
|
2550
|
+
* console.log(account.status); // e.g., 'ACTIVE'
|
|
2551
|
+
* console.log(account.toolkit.slug); // e.g., 'github'
|
|
2552
|
+
* ```
|
|
1538
2553
|
*/
|
|
1539
2554
|
async get(nanoid) {
|
|
1540
|
-
|
|
2555
|
+
const response = await this.client.connectedAccounts.retrieve(nanoid);
|
|
2556
|
+
return this.transformConnectedAccountResponse(response);
|
|
1541
2557
|
}
|
|
1542
2558
|
/**
|
|
1543
|
-
*
|
|
1544
|
-
*
|
|
1545
|
-
*
|
|
1546
|
-
*
|
|
2559
|
+
* Deletes a connected account.
|
|
2560
|
+
*
|
|
2561
|
+
* This method permanently removes a connected account from the Composio platform.
|
|
2562
|
+
* This action cannot be undone and will revoke any access tokens associated with the account.
|
|
2563
|
+
*
|
|
2564
|
+
* @param {string} nanoid - The unique identifier of the connected account to delete
|
|
2565
|
+
* @returns {Promise<ConnectedAccountDeleteResponse>} The deletion response
|
|
2566
|
+
* @throws {Error} If the account doesn't exist or cannot be deleted
|
|
2567
|
+
*
|
|
2568
|
+
* @example
|
|
2569
|
+
* ```typescript
|
|
2570
|
+
* // Delete a connected account
|
|
2571
|
+
* await composio.connectedAccounts.delete('conn_abc123');
|
|
2572
|
+
* ```
|
|
1547
2573
|
*/
|
|
1548
2574
|
async delete(nanoid) {
|
|
1549
2575
|
return this.client.connectedAccounts.delete(nanoid);
|
|
1550
2576
|
}
|
|
1551
2577
|
/**
|
|
1552
|
-
*
|
|
1553
|
-
*
|
|
1554
|
-
*
|
|
1555
|
-
*
|
|
2578
|
+
* Refreshes a connected account's authentication credentials.
|
|
2579
|
+
*
|
|
2580
|
+
* This method attempts to refresh OAuth tokens or other credentials associated with
|
|
2581
|
+
* the connected account. This is useful when a token has expired or is about to expire.
|
|
2582
|
+
*
|
|
2583
|
+
* @param {string} nanoid - The unique identifier of the connected account to refresh
|
|
2584
|
+
* @returns {Promise<ConnectedAccountRefreshResponse>} The response containing the refreshed account details
|
|
2585
|
+
* @throws {Error} If the account doesn't exist or credentials cannot be refreshed
|
|
2586
|
+
*
|
|
2587
|
+
* @example
|
|
2588
|
+
* ```typescript
|
|
2589
|
+
* // Refresh a connected account's credentials
|
|
2590
|
+
* const refreshedAccount = await composio.connectedAccounts.refresh('conn_abc123');
|
|
2591
|
+
* ```
|
|
1556
2592
|
*/
|
|
1557
2593
|
async refresh(nanoid) {
|
|
1558
2594
|
return this.client.connectedAccounts.refresh(nanoid);
|
|
@@ -1593,49 +2629,78 @@ var Toolkits = class {
|
|
|
1593
2629
|
constructor(client) {
|
|
1594
2630
|
this.client = client;
|
|
1595
2631
|
this.authorize = this.authorize.bind(this);
|
|
2632
|
+
telemetry.instrument(this);
|
|
1596
2633
|
}
|
|
1597
2634
|
/**
|
|
1598
|
-
*
|
|
1599
|
-
*
|
|
1600
|
-
*
|
|
2635
|
+
* Retrieves a list of toolkits based on the provided query parameters.
|
|
2636
|
+
*
|
|
2637
|
+
* This method fetches toolkits from the Composio API and transforms the response
|
|
2638
|
+
* from snake_case to camelCase format for consistency with JavaScript/TypeScript conventions.
|
|
2639
|
+
*
|
|
2640
|
+
* @param {ToolkitListParams} query - The query parameters to filter toolkits
|
|
2641
|
+
* @returns {Promise<ToolKitListResponse>} The transformed list of toolkits
|
|
2642
|
+
*
|
|
2643
|
+
* @private
|
|
1601
2644
|
*/
|
|
1602
2645
|
async getToolkits(query) {
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
sort_by: parsedQuery.sortBy
|
|
1609
|
-
});
|
|
1610
|
-
const parsedResult = ToolKitListResponseSchema.parse({
|
|
1611
|
-
items: result.items.map((item) => {
|
|
1612
|
-
const parsedItem = ToolKitItemSchema.parse({
|
|
1613
|
-
name: item.name,
|
|
1614
|
-
slug: item.slug,
|
|
1615
|
-
meta: item.meta,
|
|
1616
|
-
isLocalToolkit: item.is_local_toolkit,
|
|
1617
|
-
authSchemes: item.auth_schemes,
|
|
1618
|
-
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
1619
|
-
noAuth: item.no_auth
|
|
2646
|
+
try {
|
|
2647
|
+
const parsedQuery = ToolkitsListParamsSchema.safeParse(query);
|
|
2648
|
+
if (!parsedQuery.success) {
|
|
2649
|
+
throw new ValidationError("Failed to parse toolkit list query", {
|
|
2650
|
+
cause: parsedQuery.error
|
|
1620
2651
|
});
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
2652
|
+
}
|
|
2653
|
+
const result = await this.client.toolkits.list({
|
|
2654
|
+
category: parsedQuery.data.category,
|
|
2655
|
+
is_local: parsedQuery.data.isLocal,
|
|
2656
|
+
managed_by: parsedQuery.data.managedBy,
|
|
2657
|
+
sort_by: parsedQuery.data.sortBy
|
|
2658
|
+
});
|
|
2659
|
+
const parsedResult = ToolKitListResponseSchema.safeParse({
|
|
2660
|
+
items: result.items.map((item) => {
|
|
2661
|
+
const parsedItem = ToolKitItemSchema.parse({
|
|
2662
|
+
name: item.name,
|
|
2663
|
+
slug: item.slug,
|
|
2664
|
+
meta: item.meta,
|
|
2665
|
+
isLocalToolkit: item.is_local_toolkit,
|
|
2666
|
+
authSchemes: item.auth_schemes,
|
|
2667
|
+
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
2668
|
+
noAuth: item.no_auth
|
|
2669
|
+
});
|
|
2670
|
+
return parsedItem;
|
|
2671
|
+
}),
|
|
2672
|
+
nextCursor: result.next_cursor,
|
|
2673
|
+
totalPages: result.total_pages
|
|
2674
|
+
});
|
|
2675
|
+
if (!parsedResult.success) {
|
|
2676
|
+
throw new ValidationError("Failed to parse toolkit list response", {
|
|
2677
|
+
cause: parsedResult.error
|
|
2678
|
+
});
|
|
2679
|
+
}
|
|
2680
|
+
return parsedResult.data;
|
|
2681
|
+
} catch (error) {
|
|
2682
|
+
throw new ComposioToolkitFetchError("Failed to fetch toolkits", {
|
|
2683
|
+
cause: error
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
1627
2686
|
}
|
|
1628
2687
|
/**
|
|
1629
|
-
*
|
|
1630
|
-
*
|
|
1631
|
-
*
|
|
1632
|
-
*
|
|
1633
|
-
*
|
|
2688
|
+
* Retrieves a specific toolkit by its slug identifier.
|
|
2689
|
+
*
|
|
2690
|
+
* This method fetches a single toolkit from the Composio API and transforms
|
|
2691
|
+
* the response to use camelCase property naming consistent with JavaScript/TypeScript conventions.
|
|
2692
|
+
*
|
|
2693
|
+
* @param {string} slug - The unique slug identifier of the toolkit to retrieve
|
|
2694
|
+
* @returns {Promise<ToolkitRetrieveResponse>} The transformed toolkit object
|
|
2695
|
+
* @throws {ValidationError} If the response cannot be properly parsed
|
|
2696
|
+
* @throws {ComposioToolNotFoundError} If no toolkit with the given slug exists
|
|
2697
|
+
*
|
|
2698
|
+
* @private
|
|
1634
2699
|
*/
|
|
1635
2700
|
async getToolkitBySlug(slug) {
|
|
1636
2701
|
try {
|
|
1637
2702
|
const result = await this.client.toolkits.retrieve(slug);
|
|
1638
|
-
const parsedResult = ToolkitRetrieveResponseSchema.
|
|
2703
|
+
const parsedResult = ToolkitRetrieveResponseSchema.safeParse({
|
|
1639
2704
|
name: result.name,
|
|
1640
2705
|
slug: result.slug,
|
|
1641
2706
|
meta: {
|
|
@@ -1660,21 +2725,34 @@ var Toolkits = class {
|
|
|
1660
2725
|
}
|
|
1661
2726
|
}))
|
|
1662
2727
|
});
|
|
1663
|
-
|
|
2728
|
+
if (!parsedResult.success) {
|
|
2729
|
+
throw new ValidationError("Failed to parse toolkit response", {
|
|
2730
|
+
cause: parsedResult.error
|
|
2731
|
+
});
|
|
2732
|
+
}
|
|
2733
|
+
return parsedResult.data;
|
|
1664
2734
|
} catch (error) {
|
|
1665
|
-
if (error instanceof
|
|
1666
|
-
throw new
|
|
2735
|
+
if (error instanceof import_client4.default.NotFoundError) {
|
|
2736
|
+
throw new ComposioToolkitNotFoundError(`Toolkit with slug ${slug} not found`, {
|
|
2737
|
+
meta: {
|
|
2738
|
+
slug
|
|
2739
|
+
},
|
|
2740
|
+
cause: error
|
|
2741
|
+
});
|
|
1667
2742
|
}
|
|
1668
|
-
throw new
|
|
1669
|
-
|
|
2743
|
+
throw new ComposioToolkitFetchError(`Couldn't fetch Toolkit with slug: ${slug}`, {
|
|
2744
|
+
meta: {
|
|
2745
|
+
slug
|
|
2746
|
+
},
|
|
2747
|
+
cause: error
|
|
1670
2748
|
});
|
|
1671
2749
|
}
|
|
1672
2750
|
}
|
|
1673
2751
|
/**
|
|
1674
|
-
*
|
|
1675
|
-
*
|
|
1676
|
-
* @param arg -
|
|
1677
|
-
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit
|
|
2752
|
+
* Implementation method that handles both overloads for retrieving toolkits.
|
|
2753
|
+
*
|
|
2754
|
+
* @param {string | ToolkitListParams} arg - Either a toolkit slug or query parameters
|
|
2755
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit or list of toolkits
|
|
1678
2756
|
*/
|
|
1679
2757
|
async get(arg) {
|
|
1680
2758
|
if (typeof arg === "string") {
|
|
@@ -1683,9 +2761,19 @@ var Toolkits = class {
|
|
|
1683
2761
|
return this.getToolkits(arg);
|
|
1684
2762
|
}
|
|
1685
2763
|
/**
|
|
1686
|
-
*
|
|
2764
|
+
* Retrieves all toolkit categories available in the Composio SDK.
|
|
2765
|
+
*
|
|
2766
|
+
* This method fetches the complete list of categories from the Composio API
|
|
2767
|
+
* and transforms the response to use camelCase property naming.
|
|
2768
|
+
*
|
|
2769
|
+
* @returns {Promise<ToolkitRetrieveCategoriesResponse>} The list of toolkit categories
|
|
1687
2770
|
*
|
|
1688
|
-
* @
|
|
2771
|
+
* @example
|
|
2772
|
+
* ```typescript
|
|
2773
|
+
* // Get all toolkit categories
|
|
2774
|
+
* const categories = await composio.toolkits.listCategories();
|
|
2775
|
+
* console.log(categories.items); // Array of category objects
|
|
2776
|
+
* ```
|
|
1689
2777
|
*/
|
|
1690
2778
|
async listCategories() {
|
|
1691
2779
|
const result = await this.client.toolkits.retrieveCategories();
|
|
@@ -1707,15 +2795,19 @@ var Toolkits = class {
|
|
|
1707
2795
|
* This method will create an auth config if one doesn't exist and initiate a connection request.
|
|
1708
2796
|
* @param {string} userId - The user id of the user to authorize
|
|
1709
2797
|
* @param {string} toolkitSlug - The slug of the toolkit to authorize
|
|
1710
|
-
* @param {string} authConfigId - The id of the auth config to use
|
|
1711
2798
|
* @returns {Promise<ConnectionRequest>} The connection request object
|
|
2799
|
+
*
|
|
2800
|
+
* @example
|
|
2801
|
+
* ```typescript
|
|
2802
|
+
* const connectionRequest = await composio.toolkits.authorize(userId, 'github');
|
|
2803
|
+
* ```
|
|
1712
2804
|
*/
|
|
1713
2805
|
async authorize(userId, toolkitSlug) {
|
|
1714
2806
|
const toolkit = await this.getToolkitBySlug(toolkitSlug);
|
|
1715
2807
|
const composioAuthConfig = new AuthConfigs(this.client);
|
|
1716
2808
|
let authConfigIdToUse;
|
|
1717
2809
|
const authConfig = await composioAuthConfig.list({
|
|
1718
|
-
toolkitSlug
|
|
2810
|
+
toolkit: toolkitSlug
|
|
1719
2811
|
});
|
|
1720
2812
|
authConfigIdToUse = authConfig.items[0]?.id;
|
|
1721
2813
|
if (!authConfigIdToUse) {
|
|
@@ -1727,7 +2819,9 @@ var Toolkits = class {
|
|
|
1727
2819
|
authConfigIdToUse = authConfig2.id;
|
|
1728
2820
|
} else {
|
|
1729
2821
|
throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
|
|
1730
|
-
|
|
2822
|
+
meta: {
|
|
2823
|
+
toolkitSlug
|
|
2824
|
+
}
|
|
1731
2825
|
});
|
|
1732
2826
|
}
|
|
1733
2827
|
}
|
|
@@ -1832,6 +2926,7 @@ var Session = class {
|
|
|
1832
2926
|
client;
|
|
1833
2927
|
constructor(client) {
|
|
1834
2928
|
this.client = client;
|
|
2929
|
+
telemetry.instrument(this);
|
|
1835
2930
|
}
|
|
1836
2931
|
/**
|
|
1837
2932
|
* Get the active session info
|
|
@@ -1847,6 +2942,7 @@ var Triggers = class {
|
|
|
1847
2942
|
client;
|
|
1848
2943
|
constructor(client) {
|
|
1849
2944
|
this.client = client;
|
|
2945
|
+
telemetry.instrument(this);
|
|
1850
2946
|
}
|
|
1851
2947
|
/**
|
|
1852
2948
|
* Fetch list of all the active triggers
|
|
@@ -1978,235 +3074,6 @@ var Triggers = class {
|
|
|
1978
3074
|
}
|
|
1979
3075
|
};
|
|
1980
3076
|
|
|
1981
|
-
// src/types/telemetry.types.ts
|
|
1982
|
-
var TELEMETRY_EVENTS = {
|
|
1983
|
-
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
1984
|
-
SDK_METHOD_INVOKED: "SDK_METHOD_INVOKED",
|
|
1985
|
-
SDK_METHOD_ERROR: "SDK_METHOD_ERROR",
|
|
1986
|
-
CLI_INVOKED: "CLI_INVOKED"
|
|
1987
|
-
};
|
|
1988
|
-
|
|
1989
|
-
// src/utils/constants.ts
|
|
1990
|
-
var COMPOSIO_DIR = ".composio";
|
|
1991
|
-
var USER_DATA_FILE_NAME = "user_data.json";
|
|
1992
|
-
var DEFAULT_BASE_URL = "https://backend.composio.dev";
|
|
1993
|
-
var TELEMETRY_URL = "https://app.composio.dev";
|
|
1994
|
-
var IS_DEVELOPMENT_OR_CI = process.env.DEVELOPMENT || process.env.CI || false;
|
|
1995
|
-
|
|
1996
|
-
// src/telemetry/BatchProcessor.ts
|
|
1997
|
-
var BatchProcessor = class {
|
|
1998
|
-
batch = [];
|
|
1999
|
-
time;
|
|
2000
|
-
batchSize;
|
|
2001
|
-
processBatchCallback;
|
|
2002
|
-
timer = null;
|
|
2003
|
-
constructor(time = 2e3, batchSize = 100, processBatchCallback) {
|
|
2004
|
-
this.batch = [];
|
|
2005
|
-
this.time = time;
|
|
2006
|
-
this.batchSize = batchSize;
|
|
2007
|
-
this.processBatchCallback = processBatchCallback;
|
|
2008
|
-
}
|
|
2009
|
-
pushItem(item) {
|
|
2010
|
-
this.batch.push(item);
|
|
2011
|
-
if (this.batch.length >= this.batchSize) {
|
|
2012
|
-
this.processBatch();
|
|
2013
|
-
} else if (!this.timer) {
|
|
2014
|
-
this.timer = setTimeout(() => this.processBatch(), this.time);
|
|
2015
|
-
}
|
|
2016
|
-
}
|
|
2017
|
-
processBatch() {
|
|
2018
|
-
if (this.batch.length > 0) {
|
|
2019
|
-
this.processBatchCallback(this.batch);
|
|
2020
|
-
this.batch = [];
|
|
2021
|
-
}
|
|
2022
|
-
if (this.timer) {
|
|
2023
|
-
clearTimeout(this.timer);
|
|
2024
|
-
this.timer = null;
|
|
2025
|
-
}
|
|
2026
|
-
}
|
|
2027
|
-
};
|
|
2028
|
-
|
|
2029
|
-
// src/telemetry/transports/BrowserTransport.ts
|
|
2030
|
-
var BrowserTelemetryTransport = class {
|
|
2031
|
-
send(payload) {
|
|
2032
|
-
if (typeof window === "undefined") {
|
|
2033
|
-
return Promise.reject(
|
|
2034
|
-
new Error("BrowserTelemetryTransport can only be used in browser environments")
|
|
2035
|
-
);
|
|
2036
|
-
}
|
|
2037
|
-
return new Promise((resolve) => {
|
|
2038
|
-
try {
|
|
2039
|
-
const xhr = new XMLHttpRequest();
|
|
2040
|
-
xhr.open(payload.method, payload.url, true);
|
|
2041
|
-
xhr.setRequestHeader("Content-Type", "application/json");
|
|
2042
|
-
Object.entries(payload.headers || {}).forEach(([key, value]) => {
|
|
2043
|
-
xhr.setRequestHeader(key, value);
|
|
2044
|
-
});
|
|
2045
|
-
xhr.onload = function() {
|
|
2046
|
-
resolve();
|
|
2047
|
-
};
|
|
2048
|
-
xhr.send(JSON.stringify(payload.data));
|
|
2049
|
-
} catch (error) {
|
|
2050
|
-
logger_default.error("Error sending error to telemetry", error);
|
|
2051
|
-
resolve();
|
|
2052
|
-
}
|
|
2053
|
-
});
|
|
2054
|
-
}
|
|
2055
|
-
};
|
|
2056
|
-
|
|
2057
|
-
// src/telemetry/transports/ProcessTransport.ts
|
|
2058
|
-
var ProcessTelemetryTransport = class {
|
|
2059
|
-
send(payload) {
|
|
2060
|
-
if (typeof window !== "undefined") {
|
|
2061
|
-
return Promise.reject(
|
|
2062
|
-
new Error("ProcessTelemetryTransport can only be used in Node.js environments")
|
|
2063
|
-
);
|
|
2064
|
-
}
|
|
2065
|
-
return new Promise((resolve) => {
|
|
2066
|
-
try {
|
|
2067
|
-
const url = new URL(payload.url);
|
|
2068
|
-
const protocol = url.protocol === "https:" ? "https" : "http";
|
|
2069
|
-
const port = url.port || (url.protocol === "https:" ? 443 : 80);
|
|
2070
|
-
const args = [
|
|
2071
|
-
"-e",
|
|
2072
|
-
`
|
|
2073
|
-
const http = require('${protocol}');
|
|
2074
|
-
const options = {
|
|
2075
|
-
hostname: '${url.hostname}',
|
|
2076
|
-
path: '${url.pathname}${url.search}',
|
|
2077
|
-
port: ${port},
|
|
2078
|
-
method: '${payload.method}',
|
|
2079
|
-
headers: ${JSON.stringify(payload.headers)}
|
|
2080
|
-
};
|
|
2081
|
-
|
|
2082
|
-
const req = http.request(options, (res) => {
|
|
2083
|
-
res.on('data', () => {});
|
|
2084
|
-
res.on('end', () => {
|
|
2085
|
-
process.exit(0);
|
|
2086
|
-
});
|
|
2087
|
-
});
|
|
2088
|
-
|
|
2089
|
-
req.on('error', () => {
|
|
2090
|
-
process.exit(0);
|
|
2091
|
-
});
|
|
2092
|
-
|
|
2093
|
-
req.write(JSON.stringify(${JSON.stringify(payload.data)}));
|
|
2094
|
-
req.end();
|
|
2095
|
-
`
|
|
2096
|
-
];
|
|
2097
|
-
import("child_process").then(({ spawn }) => {
|
|
2098
|
-
spawn("node", args, {
|
|
2099
|
-
stdio: "ignore",
|
|
2100
|
-
detached: true,
|
|
2101
|
-
shell: false
|
|
2102
|
-
}).unref();
|
|
2103
|
-
resolve();
|
|
2104
|
-
}).catch(() => {
|
|
2105
|
-
resolve();
|
|
2106
|
-
});
|
|
2107
|
-
} catch (error) {
|
|
2108
|
-
logger_default.error("Error sending telemetry", error);
|
|
2109
|
-
resolve();
|
|
2110
|
-
}
|
|
2111
|
-
});
|
|
2112
|
-
}
|
|
2113
|
-
};
|
|
2114
|
-
|
|
2115
|
-
// src/telemetry/Telemetry.ts
|
|
2116
|
-
var Telemetry = class {
|
|
2117
|
-
telemetryMetadata;
|
|
2118
|
-
transport;
|
|
2119
|
-
batchProcessor = new BatchProcessor(100, 10, async (data) => {
|
|
2120
|
-
await this.sendTelemetry(data);
|
|
2121
|
-
});
|
|
2122
|
-
constructor(metadata, transport) {
|
|
2123
|
-
this.telemetryMetadata = metadata;
|
|
2124
|
-
const isBrowser = typeof window !== "undefined";
|
|
2125
|
-
if (transport) {
|
|
2126
|
-
this.transport = transport;
|
|
2127
|
-
} else if (isBrowser) {
|
|
2128
|
-
this.transport = new BrowserTelemetryTransport();
|
|
2129
|
-
} else {
|
|
2130
|
-
this.transport = new ProcessTelemetryTransport();
|
|
2131
|
-
}
|
|
2132
|
-
this.sendTelemetry([
|
|
2133
|
-
{
|
|
2134
|
-
eventName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
2135
|
-
data: {},
|
|
2136
|
-
sdk_meta: this.telemetryMetadata
|
|
2137
|
-
}
|
|
2138
|
-
]);
|
|
2139
|
-
}
|
|
2140
|
-
/**
|
|
2141
|
-
* Instrument the telemetry for the given instance.
|
|
2142
|
-
*
|
|
2143
|
-
* You can pass the instance and the file name of the instance to instrument the telemetry.
|
|
2144
|
-
* This will instrument all the methods of the instance and log the telemetry for each method call.
|
|
2145
|
-
* @param instance - any instance that extends InstrumentedInstance
|
|
2146
|
-
* @param fileName - the file name of the instance
|
|
2147
|
-
* @returns
|
|
2148
|
-
*/
|
|
2149
|
-
instrumentTelemetry(instance, fileName) {
|
|
2150
|
-
const proto = Object.getPrototypeOf(instance);
|
|
2151
|
-
const methodNames = Object.getOwnPropertyNames(proto).filter((key) => {
|
|
2152
|
-
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
2153
|
-
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
2154
|
-
});
|
|
2155
|
-
const instrumentedClassName = instance.constructor?.name || fileName || "unknown";
|
|
2156
|
-
for (const name of methodNames) {
|
|
2157
|
-
const originalMethod = instance[name];
|
|
2158
|
-
instance[name] = async (...args) => {
|
|
2159
|
-
const telemetryPayload = {
|
|
2160
|
-
eventName: TELEMETRY_EVENTS.SDK_METHOD_INVOKED,
|
|
2161
|
-
data: {
|
|
2162
|
-
fileName: instrumentedClassName,
|
|
2163
|
-
method: name,
|
|
2164
|
-
params: args
|
|
2165
|
-
},
|
|
2166
|
-
sdk_meta: this.telemetryMetadata
|
|
2167
|
-
};
|
|
2168
|
-
this.batchProcessor.pushItem(telemetryPayload);
|
|
2169
|
-
try {
|
|
2170
|
-
return await originalMethod.apply(instance, args);
|
|
2171
|
-
} catch (error) {
|
|
2172
|
-
const telemetryPayload2 = {
|
|
2173
|
-
eventName: TELEMETRY_EVENTS.SDK_METHOD_ERROR,
|
|
2174
|
-
data: {
|
|
2175
|
-
fileName: instrumentedClassName,
|
|
2176
|
-
method: name,
|
|
2177
|
-
params: args,
|
|
2178
|
-
error
|
|
2179
|
-
},
|
|
2180
|
-
sdk_meta: this.telemetryMetadata
|
|
2181
|
-
};
|
|
2182
|
-
this.batchProcessor.pushItem(telemetryPayload2);
|
|
2183
|
-
throw error;
|
|
2184
|
-
}
|
|
2185
|
-
};
|
|
2186
|
-
}
|
|
2187
|
-
return instance;
|
|
2188
|
-
}
|
|
2189
|
-
/**
|
|
2190
|
-
* Send the telemetry payload to the server.
|
|
2191
|
-
* @param payload - the telemetry payload to send
|
|
2192
|
-
* @returns
|
|
2193
|
-
*/
|
|
2194
|
-
async sendTelemetry(payload) {
|
|
2195
|
-
const isTelemetryDisabled = getEnvVariable("TELEMETRY_DISABLED", "false") === "true";
|
|
2196
|
-
if (isTelemetryDisabled) {
|
|
2197
|
-
return;
|
|
2198
|
-
}
|
|
2199
|
-
const url = `${TELEMETRY_URL}/api/sdk_metrics/telemetry`;
|
|
2200
|
-
const reqPayload = {
|
|
2201
|
-
data: payload,
|
|
2202
|
-
url,
|
|
2203
|
-
method: "POST",
|
|
2204
|
-
headers: { "Content-Type": "application/json" }
|
|
2205
|
-
};
|
|
2206
|
-
this.transport.send(reqPayload);
|
|
2207
|
-
}
|
|
2208
|
-
};
|
|
2209
|
-
|
|
2210
3077
|
// src/utils/sdk.ts
|
|
2211
3078
|
var userDataPath = () => {
|
|
2212
3079
|
try {
|
|
@@ -2214,6 +3081,7 @@ var userDataPath = () => {
|
|
|
2214
3081
|
const os = require("os");
|
|
2215
3082
|
return path.join(os.homedir(), COMPOSIO_DIR, USER_DATA_FILE_NAME);
|
|
2216
3083
|
} catch (_error) {
|
|
3084
|
+
logger_default.debug("Environment", `Unable to get user data path`);
|
|
2217
3085
|
return null;
|
|
2218
3086
|
}
|
|
2219
3087
|
};
|
|
@@ -2223,6 +3091,7 @@ var getUserDataJson = () => {
|
|
|
2223
3091
|
const data = fs.readFileSync(userDataPath(), "utf8");
|
|
2224
3092
|
return JSON.parse(data);
|
|
2225
3093
|
} catch (_error) {
|
|
3094
|
+
logger_default.debug("Environment", "No user data file found");
|
|
2226
3095
|
return {};
|
|
2227
3096
|
}
|
|
2228
3097
|
};
|
|
@@ -2231,27 +3100,33 @@ function getSDKConfig(baseUrl, apiKey) {
|
|
|
2231
3100
|
const { api_key: apiKeyFromUserConfig, base_url: baseURLFromUserConfig } = userData;
|
|
2232
3101
|
const baseURLParsed = baseUrl || getEnvVariable("COMPOSIO_BASE_URL") || baseURLFromUserConfig || DEFAULT_BASE_URL;
|
|
2233
3102
|
const apiKeyParsed = apiKey || getEnvVariable("COMPOSIO_API_KEY") || apiKeyFromUserConfig || "";
|
|
3103
|
+
if (!apiKeyParsed) {
|
|
3104
|
+
ComposioError.handle(new ComposioNoAPIKeyError(), {
|
|
3105
|
+
exitProcess: true
|
|
3106
|
+
});
|
|
3107
|
+
}
|
|
3108
|
+
logger_default.debug("Environment", `API Key: ${apiKeyParsed}`);
|
|
3109
|
+
logger_default.debug("Environment", `Base URL: ${baseURLParsed}`);
|
|
2234
3110
|
return { baseURL: baseURLParsed, apiKey: apiKeyParsed };
|
|
2235
3111
|
}
|
|
2236
3112
|
|
|
2237
3113
|
// src/utils/version.ts
|
|
2238
|
-
|
|
2239
|
-
const v1 = version1.split(".").map(Number);
|
|
2240
|
-
const v2 = version2.split(".").map(Number);
|
|
2241
|
-
for (let i = 0; i < 3; i++) {
|
|
2242
|
-
if (v1[i] > v2[i]) return true;
|
|
2243
|
-
if (v1[i] < v2[i]) return false;
|
|
2244
|
-
}
|
|
2245
|
-
return false;
|
|
2246
|
-
}
|
|
3114
|
+
var import_semver = __toESM(require("semver"), 1);
|
|
2247
3115
|
async function checkForLatestVersionFromNPM(currentVersion) {
|
|
2248
3116
|
try {
|
|
2249
|
-
const packageName = "composio
|
|
3117
|
+
const packageName = "@composio/core";
|
|
2250
3118
|
const currentVersionFromPackageJson = currentVersion;
|
|
3119
|
+
if (!import_semver.default.valid(currentVersionFromPackageJson)) {
|
|
3120
|
+
return;
|
|
3121
|
+
}
|
|
3122
|
+
const prerelease = import_semver.default.prerelease(currentVersionFromPackageJson);
|
|
3123
|
+
if (prerelease && (String(prerelease[0]).includes("alpha") || String(prerelease[0]).includes("beta"))) {
|
|
3124
|
+
return;
|
|
3125
|
+
}
|
|
2251
3126
|
const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`);
|
|
2252
3127
|
const data = await response.json();
|
|
2253
3128
|
const latestVersion = data.version;
|
|
2254
|
-
if (
|
|
3129
|
+
if (import_semver.default.gt(latestVersion, currentVersionFromPackageJson) && !IS_DEVELOPMENT_OR_CI) {
|
|
2255
3130
|
logger_default.info(
|
|
2256
3131
|
`\u{1F680} Upgrade available! Your composio-core version (${currentVersionFromPackageJson}) is behind. Latest version: ${latestVersion}.`
|
|
2257
3132
|
);
|
|
@@ -2465,13 +3340,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2465
3340
|
};
|
|
2466
3341
|
|
|
2467
3342
|
// package.json
|
|
2468
|
-
var version = "0.1.12-alpha.
|
|
2469
|
-
|
|
2470
|
-
// src/utils/uuid.ts
|
|
2471
|
-
var import_uuid = require("uuid");
|
|
2472
|
-
function getRandomUUID() {
|
|
2473
|
-
return (0, import_uuid.v4)();
|
|
2474
|
-
}
|
|
3343
|
+
var version = "0.1.12-alpha.11";
|
|
2475
3344
|
|
|
2476
3345
|
// src/composio.ts
|
|
2477
3346
|
var Composio = class {
|
|
@@ -2485,7 +3354,6 @@ var Composio = class {
|
|
|
2485
3354
|
* @type {ComposioConfig<TProvider>}
|
|
2486
3355
|
*/
|
|
2487
3356
|
config;
|
|
2488
|
-
telemetry;
|
|
2489
3357
|
/**
|
|
2490
3358
|
* Core models for Composio.
|
|
2491
3359
|
*/
|
|
@@ -2495,10 +3363,8 @@ var Composio = class {
|
|
|
2495
3363
|
provider;
|
|
2496
3364
|
// auth configs
|
|
2497
3365
|
authConfigs;
|
|
2498
|
-
createAuthConfig;
|
|
2499
3366
|
// connected accounts
|
|
2500
3367
|
connectedAccounts;
|
|
2501
|
-
initiateConnection;
|
|
2502
3368
|
/**
|
|
2503
3369
|
* @param {Object} config Configuration for the Composio SDK.
|
|
2504
3370
|
* @param {string} config.apiKey The API key for the Composio SDK.
|
|
@@ -2514,58 +3380,46 @@ var Composio = class {
|
|
|
2514
3380
|
config?.apiKey
|
|
2515
3381
|
);
|
|
2516
3382
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
2517
|
-
logger_default.
|
|
3383
|
+
logger_default.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
2518
3384
|
}
|
|
2519
|
-
this.client = new
|
|
3385
|
+
this.client = new import_client5.default({
|
|
2520
3386
|
apiKey: apiKeyParsed,
|
|
2521
3387
|
baseURL: baseURLParsed
|
|
2522
3388
|
});
|
|
2523
3389
|
this.config = {
|
|
2524
3390
|
...config,
|
|
2525
|
-
allowTracking: config
|
|
3391
|
+
allowTracking: config?.allowTracking ?? true,
|
|
3392
|
+
allowTracing: config?.allowTracing ?? true
|
|
2526
3393
|
};
|
|
2527
|
-
this.provider = config
|
|
3394
|
+
this.provider = config?.provider ?? new OpenAIProvider();
|
|
2528
3395
|
this.tools = new Tools(this.client, this.provider);
|
|
2529
|
-
this.provider._setExecuteToolFn(this.tools.execute);
|
|
2530
3396
|
this.toolkits = new Toolkits(this.client);
|
|
2531
3397
|
this.triggers = new Triggers(this.client);
|
|
2532
3398
|
this.authConfigs = new AuthConfigs(this.client);
|
|
2533
|
-
this.createAuthConfig = this.authConfigs.create.bind(this.authConfigs);
|
|
2534
3399
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
this.initializeTelemetry(
|
|
3400
|
+
if (this.config.allowTracking) {
|
|
3401
|
+
telemetry.setup(
|
|
2538
3402
|
{
|
|
2539
3403
|
apiKey: apiKeyParsed ?? "",
|
|
2540
3404
|
baseUrl: baseURLParsed ?? "",
|
|
2541
|
-
frameworkRuntime: "
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
3405
|
+
frameworkRuntime: this.provider?.name || "unknown",
|
|
3406
|
+
isAgentic: this.provider?._isAgentic || false,
|
|
3407
|
+
source: "javascript",
|
|
3408
|
+
version,
|
|
3409
|
+
sdkType: "Typescript-V3",
|
|
2545
3410
|
isBrowser: typeof window !== "undefined",
|
|
2546
|
-
|
|
3411
|
+
// @TODO: Users might want to pass their own session id
|
|
3412
|
+
// @TODO: We shouldn't be doing this as people might always have one session id throughout the process in server
|
|
3413
|
+
sessionId: this.config.allowTracing ? getRandomUUID() : void 0
|
|
2547
3414
|
// @TODO: get the session id
|
|
2548
3415
|
},
|
|
2549
|
-
config
|
|
3416
|
+
config?.telemetryTransport
|
|
2550
3417
|
);
|
|
2551
3418
|
}
|
|
3419
|
+
telemetry.instrument(this);
|
|
3420
|
+
telemetry.instrument(this.provider);
|
|
2552
3421
|
checkForLatestVersionFromNPM(version);
|
|
2553
3422
|
}
|
|
2554
|
-
/**
|
|
2555
|
-
* Initialize the instrumentations and telemetry for the Composio SDK.
|
|
2556
|
-
* @param {TelemetryMetadata} config - The configuration for the telemetry.
|
|
2557
|
-
* @param {BaseTelemetryTransport} transport - The transport for the telemetry.
|
|
2558
|
-
*/
|
|
2559
|
-
initializeTelemetry(config, transport) {
|
|
2560
|
-
this.telemetry = new Telemetry(config, transport);
|
|
2561
|
-
this.telemetry.instrumentTelemetry(this);
|
|
2562
|
-
this.telemetry.instrumentTelemetry(this.tools);
|
|
2563
|
-
this.telemetry.instrumentTelemetry(this.toolkits);
|
|
2564
|
-
this.telemetry.instrumentTelemetry(this.triggers);
|
|
2565
|
-
this.telemetry.instrumentTelemetry(this.authConfigs);
|
|
2566
|
-
this.telemetry.instrumentTelemetry(this.connectedAccounts);
|
|
2567
|
-
this.telemetry.instrumentTelemetry(this.provider);
|
|
2568
|
-
}
|
|
2569
3423
|
/**
|
|
2570
3424
|
* Get the Composio SDK client.
|
|
2571
3425
|
* @returns {ComposioClient} The Composio API client.
|
|
@@ -2576,24 +3430,6 @@ var Composio = class {
|
|
|
2576
3430
|
}
|
|
2577
3431
|
return this.client;
|
|
2578
3432
|
}
|
|
2579
|
-
/**
|
|
2580
|
-
* Fetch all the tools from Composio.
|
|
2581
|
-
* @param {ToolListParams} params Parameters to fetch the tools.
|
|
2582
|
-
* @param {ProviderOptions<TProvider>} modifiers Modifiers to apply to the tools.
|
|
2583
|
-
* @returns {Promise<ReturnType<TProvider['getTools']>>} The tools from the provider.
|
|
2584
|
-
*/
|
|
2585
|
-
getTools(userId, filters, modifiers) {
|
|
2586
|
-
return this.tools.get(userId, filters, modifiers);
|
|
2587
|
-
}
|
|
2588
|
-
/**
|
|
2589
|
-
* Fetch a tool from Composio by its slug.
|
|
2590
|
-
* @param {string} slug slug of the tool
|
|
2591
|
-
* @param {ProviderOptions<TProvider>} modifiers to be applied to the tool
|
|
2592
|
-
* @returns {Promise<ReturnType<TProvider['getToolBySlug']>>} The tool from the provider.
|
|
2593
|
-
*/
|
|
2594
|
-
getToolBySlug(userId, slug, modifiers) {
|
|
2595
|
-
return this.tools.get(userId, slug, modifiers);
|
|
2596
|
-
}
|
|
2597
3433
|
};
|
|
2598
3434
|
|
|
2599
3435
|
// src/provider/ComposioProvider.ts
|
|
@@ -2608,8 +3444,15 @@ var ComposioProvider = class extends BaseNonAgenticProvider {
|
|
|
2608
3444
|
};
|
|
2609
3445
|
|
|
2610
3446
|
// src/telemetry/TelemetryTransport.ts
|
|
3447
|
+
var import_chalk4 = __toESM(require("chalk"), 1);
|
|
2611
3448
|
var BaseTelemetryTransport = class {
|
|
2612
3449
|
};
|
|
3450
|
+
var ConsoleTelemetryTransport = class {
|
|
3451
|
+
send(payload) {
|
|
3452
|
+
logger_default.debug(import_chalk4.default.yellow("telemetry"), JSON.stringify(payload, null, 2));
|
|
3453
|
+
return Promise.resolve();
|
|
3454
|
+
}
|
|
3455
|
+
};
|
|
2613
3456
|
|
|
2614
3457
|
// src/utils/jsonSchema.ts
|
|
2615
3458
|
var import_zod8 = require("zod");
|
|
@@ -2721,14 +3564,38 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2721
3564
|
}
|
|
2722
3565
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2723
3566
|
0 && (module.exports = {
|
|
3567
|
+
AuthConfigErrorCodes,
|
|
2724
3568
|
AuthConfigTypes,
|
|
2725
3569
|
AuthSchemeTypes,
|
|
2726
3570
|
BaseAgenticProvider,
|
|
2727
3571
|
BaseNonAgenticProvider,
|
|
2728
3572
|
BaseTelemetryTransport,
|
|
2729
3573
|
Composio,
|
|
3574
|
+
ComposioAuthConfigNotFoundError,
|
|
3575
|
+
ComposioConnectedAccountNotFoundError,
|
|
3576
|
+
ComposioCustomToolsNotInitializedError,
|
|
3577
|
+
ComposioError,
|
|
3578
|
+
ComposioGlobalExecuteToolFnNotSetError,
|
|
3579
|
+
ComposioInvalidExecuteFunctionError,
|
|
3580
|
+
ComposioInvalidModifierError,
|
|
3581
|
+
ComposioNoAPIKeyError,
|
|
2730
3582
|
ComposioProvider,
|
|
3583
|
+
ComposioProviderNotDefinedError,
|
|
3584
|
+
ComposioToolExecutionError,
|
|
3585
|
+
ComposioToolNotFoundError,
|
|
3586
|
+
ComposioToolkitFetchError,
|
|
3587
|
+
ComposioToolkitNotFoundError,
|
|
3588
|
+
ConnectedAccountErrorCodes,
|
|
3589
|
+
ConnectionRequestErrorCodes,
|
|
3590
|
+
ConnectionRequestFailedError,
|
|
3591
|
+
ConnectionRequestTimeoutError,
|
|
3592
|
+
ConsoleTelemetryTransport,
|
|
2731
3593
|
OpenAIProvider,
|
|
3594
|
+
SDKErrorCodes,
|
|
3595
|
+
ToolErrorCodes,
|
|
2732
3596
|
ToolListParamsSchema,
|
|
3597
|
+
ToolkitErrorCodes,
|
|
3598
|
+
ValidationError,
|
|
3599
|
+
ValidationErrorCodes,
|
|
2733
3600
|
jsonSchemaToModel
|
|
2734
3601
|
});
|