@composio/core 0.1.12-alpha.10 → 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/dist/index.cjs +798 -373
- package/dist/index.d.cts +208 -22
- package/dist/index.d.ts +208 -22
- package/dist/index.js +614 -212
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/composio.ts
|
|
9
|
-
import
|
|
9
|
+
import ComposioClient3 from "@composio/client";
|
|
10
10
|
|
|
11
11
|
// src/types/tool.types.ts
|
|
12
12
|
import { z } from "zod";
|
|
@@ -108,7 +108,20 @@ var Logger = class {
|
|
|
108
108
|
this.console = console;
|
|
109
109
|
}
|
|
110
110
|
formatMessage(args) {
|
|
111
|
-
const formattedArgs = args.map((arg) =>
|
|
111
|
+
const formattedArgs = args.map((arg, index) => {
|
|
112
|
+
if (typeof arg === "object") {
|
|
113
|
+
return JSON.stringify(arg);
|
|
114
|
+
} else {
|
|
115
|
+
if (index === 0) {
|
|
116
|
+
if (args.length > 1) {
|
|
117
|
+
return chalk.yellow(`${arg}`);
|
|
118
|
+
} else {
|
|
119
|
+
return String(arg);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return String(arg);
|
|
123
|
+
}
|
|
124
|
+
}).join("\n");
|
|
112
125
|
if (!this.includeTimestamp) {
|
|
113
126
|
return formattedArgs;
|
|
114
127
|
}
|
|
@@ -143,34 +156,211 @@ var logger = new Logger();
|
|
|
143
156
|
var logger_default = logger;
|
|
144
157
|
|
|
145
158
|
// src/errors/ComposioError.ts
|
|
146
|
-
|
|
159
|
+
import chalk2 from "chalk";
|
|
160
|
+
import { ZodError } from "zod";
|
|
161
|
+
import { BadRequestError } from "@composio/client";
|
|
162
|
+
var ComposioError = class _ComposioError extends Error {
|
|
163
|
+
/** @readonly Error name */
|
|
147
164
|
name = "ComposioError";
|
|
148
165
|
code;
|
|
149
|
-
statusCode;
|
|
150
|
-
cause;
|
|
151
|
-
meta;
|
|
152
166
|
possibleFixes;
|
|
167
|
+
errorId;
|
|
168
|
+
/**
|
|
169
|
+
* Creates a new ComposioError
|
|
170
|
+
* @param message Error message
|
|
171
|
+
* @param options Additional error options
|
|
172
|
+
*/
|
|
153
173
|
constructor(message, options = {}) {
|
|
154
174
|
super(message);
|
|
155
|
-
|
|
156
|
-
this.
|
|
157
|
-
this.cause = options.cause;
|
|
158
|
-
this.meta = options.meta;
|
|
175
|
+
const statusCode = options.statusCode || (options.cause instanceof BadRequestError ? options.cause.status : void 0);
|
|
176
|
+
this.code = `TS-SDK::${options.code}`;
|
|
159
177
|
this.possibleFixes = options.possibleFixes;
|
|
178
|
+
this.definePropertyIfExists("statusCode", statusCode);
|
|
179
|
+
this.definePropertyIfExists("cause", options.cause);
|
|
180
|
+
this.definePropertyIfExists("stack", options.stack);
|
|
181
|
+
if (options.meta && Object.keys(options.meta).length > 0) {
|
|
182
|
+
this.definePropertyIfExists("meta", options.meta);
|
|
183
|
+
}
|
|
160
184
|
if (Error.captureStackTrace) {
|
|
161
185
|
Error.captureStackTrace(this, this.constructor);
|
|
162
186
|
}
|
|
163
187
|
}
|
|
164
|
-
|
|
165
|
-
|
|
188
|
+
/**
|
|
189
|
+
* Helper method to define a property only if it has a value
|
|
190
|
+
* @param propertyName Name of the property to define
|
|
191
|
+
* @param value Value to assign to the property
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
definePropertyIfExists(propertyName, value) {
|
|
195
|
+
if (value !== void 0) {
|
|
196
|
+
Object.defineProperty(this, propertyName, {
|
|
197
|
+
value,
|
|
198
|
+
enumerable: true,
|
|
199
|
+
writable: false,
|
|
200
|
+
configurable: true
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Extract and normalize error data for formatting
|
|
206
|
+
* @param includeStack Whether to include stack trace information
|
|
207
|
+
* @returns Structured error data for formatting
|
|
208
|
+
* @private
|
|
209
|
+
*/
|
|
210
|
+
getErrorData(includeStack = false) {
|
|
211
|
+
const data = {
|
|
166
212
|
name: this.name,
|
|
167
|
-
message: this.message
|
|
168
|
-
code: this.code,
|
|
169
|
-
statusCode: this.statusCode,
|
|
170
|
-
cause: this.cause instanceof Error ? this.cause.message : this.cause,
|
|
171
|
-
meta: this.meta,
|
|
172
|
-
possibleFixes: this.possibleFixes?.length ? this.possibleFixes.join("\n") : void 0
|
|
213
|
+
message: this.message
|
|
173
214
|
};
|
|
215
|
+
const { cause, code, stack, statusCode, meta, possibleFixes } = this;
|
|
216
|
+
if (cause !== void 0) {
|
|
217
|
+
const rawCause = cause;
|
|
218
|
+
data.cause = rawCause instanceof Error ? rawCause.message : String(rawCause);
|
|
219
|
+
}
|
|
220
|
+
if (code) {
|
|
221
|
+
data.code = code;
|
|
222
|
+
}
|
|
223
|
+
if (statusCode !== void 0) {
|
|
224
|
+
data.statusCode = statusCode;
|
|
225
|
+
}
|
|
226
|
+
if (meta) {
|
|
227
|
+
data.meta = meta;
|
|
228
|
+
}
|
|
229
|
+
if (possibleFixes) {
|
|
230
|
+
data.possibleFixes = possibleFixes;
|
|
231
|
+
}
|
|
232
|
+
if (includeStack && stack) {
|
|
233
|
+
data.stack = stack.split("\n").slice(1);
|
|
234
|
+
}
|
|
235
|
+
return data;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Prints a user-friendly, colorful representation of the error to the logger
|
|
239
|
+
* @param includeStack Whether to include the stack trace in the output (default: false)
|
|
240
|
+
*/
|
|
241
|
+
prettyPrint(includeStack = false) {
|
|
242
|
+
const data = this.getErrorData(includeStack);
|
|
243
|
+
let output = "\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold(data.message) + "\n";
|
|
244
|
+
if (data.code) {
|
|
245
|
+
output += chalk2.yellow(`Error Code: ${data.code}`) + "\n";
|
|
246
|
+
}
|
|
247
|
+
if (data.statusCode !== void 0) {
|
|
248
|
+
output += chalk2.yellow(`Status: ${data.statusCode}`) + "\n";
|
|
249
|
+
}
|
|
250
|
+
if (data.cause) {
|
|
251
|
+
output += chalk2.gray("Reason:") + "\n";
|
|
252
|
+
output += " " + chalk2.white(data.cause) + "\n";
|
|
253
|
+
}
|
|
254
|
+
if (data.meta) {
|
|
255
|
+
output += chalk2.gray("Additional Information:") + "\n";
|
|
256
|
+
output += " " + chalk2.white(JSON.stringify(data.meta, null, 2).replace(/\n/g, "\n ")) + "\n";
|
|
257
|
+
}
|
|
258
|
+
if (data.possibleFixes?.length) {
|
|
259
|
+
output += "\n" + chalk2.cyan.bold("Try the following:") + "\n";
|
|
260
|
+
const fixes = data.possibleFixes?.map((fix, index) => ` ${index + 1}. ` + chalk2.white(fix));
|
|
261
|
+
output += fixes?.join("\n") + "\n";
|
|
262
|
+
}
|
|
263
|
+
if (data.stack?.length) {
|
|
264
|
+
output += "\n" + chalk2.gray("Stack Trace:") + "\n";
|
|
265
|
+
output += chalk2.gray(data.stack.join("\n")) + "\n";
|
|
266
|
+
}
|
|
267
|
+
output += "\n";
|
|
268
|
+
logger_default.error(output);
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Static factory method to create and pretty print an error in one step
|
|
272
|
+
* @param message Error message
|
|
273
|
+
* @param options Error options
|
|
274
|
+
* @param includeStack Whether to include the stack trace in the output
|
|
275
|
+
* @returns The created error instance
|
|
276
|
+
*/
|
|
277
|
+
static createAndPrint(message, options = {}, includeStack = false) {
|
|
278
|
+
const error = new _ComposioError(message, options);
|
|
279
|
+
error.prettyPrint(includeStack);
|
|
280
|
+
return error;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Utility function to handle errors in a consistent way
|
|
284
|
+
* This properly displays the error and exits the process if needed
|
|
285
|
+
* @param error The error to handle
|
|
286
|
+
* @param options Options for error handling
|
|
287
|
+
*/
|
|
288
|
+
static handle(error, options = {}) {
|
|
289
|
+
const { includeStack = false, exitProcess = false, exitCode = 1 } = options;
|
|
290
|
+
if (error instanceof _ComposioError) {
|
|
291
|
+
error.prettyPrint(includeStack);
|
|
292
|
+
} else if (error instanceof ZodError) {
|
|
293
|
+
this.handleZodError(error, includeStack);
|
|
294
|
+
} else if (error instanceof Error) {
|
|
295
|
+
this.handleStandardError(error, includeStack);
|
|
296
|
+
} else {
|
|
297
|
+
this.handleUnknownError(error);
|
|
298
|
+
}
|
|
299
|
+
if (exitProcess && typeof process !== "undefined") {
|
|
300
|
+
process.exit(exitCode);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Helper method to handle Zod validation errors
|
|
305
|
+
* @param error The Zod error to handle
|
|
306
|
+
* @param includeStack Whether to include the stack trace
|
|
307
|
+
* @private
|
|
308
|
+
*/
|
|
309
|
+
static handleZodError(error, includeStack) {
|
|
310
|
+
logger_default.error("\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold(error.message));
|
|
311
|
+
logger_default.error(chalk2.gray("Invalid parameters:"));
|
|
312
|
+
error.errors.forEach((err) => {
|
|
313
|
+
logger_default.error(chalk2.yellow(err.path.join(".")) + " " + chalk2.white(err.message));
|
|
314
|
+
});
|
|
315
|
+
logger_default.error(chalk2.gray("Expected parameters:"));
|
|
316
|
+
error.errors.forEach((err) => {
|
|
317
|
+
logger_default.error(chalk2.yellow(err.path.join(".")) + " " + chalk2.white(err.message));
|
|
318
|
+
});
|
|
319
|
+
if (includeStack) {
|
|
320
|
+
logger_default.error("\n" + chalk2.gray("Validation Errors:"));
|
|
321
|
+
error.errors.forEach((err) => {
|
|
322
|
+
const path = err.path.join(".");
|
|
323
|
+
logger_default.error(
|
|
324
|
+
chalk2.gray(" \u2022 ") + chalk2.yellow(path ? `${path}: ` : "") + chalk2.white(err.message)
|
|
325
|
+
);
|
|
326
|
+
});
|
|
327
|
+
if (error.stack) {
|
|
328
|
+
logger_default.error("\n" + chalk2.gray("Stack Trace:"));
|
|
329
|
+
const stackLines = error.stack.split("\n").slice(1);
|
|
330
|
+
logger_default.error(chalk2.gray(stackLines.join("\n")));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
logger_default.error("");
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Helper method to handle standard Error objects
|
|
337
|
+
* @param error The standard error to handle
|
|
338
|
+
* @param includeStack Whether to include the stack trace
|
|
339
|
+
* @private
|
|
340
|
+
*/
|
|
341
|
+
static handleStandardError(error, includeStack) {
|
|
342
|
+
logger_default.error("\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold(error.message));
|
|
343
|
+
if (includeStack && error.stack) {
|
|
344
|
+
logger_default.error("\n" + chalk2.gray("Stack Trace:"));
|
|
345
|
+
const stackLines = error.stack.split("\n").slice(1);
|
|
346
|
+
logger_default.error(chalk2.gray(stackLines.join("\n")));
|
|
347
|
+
}
|
|
348
|
+
logger_default.error("");
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Helper method to handle unknown error types
|
|
352
|
+
* @param error The unknown error value
|
|
353
|
+
* @private
|
|
354
|
+
*/
|
|
355
|
+
static handleUnknownError(error) {
|
|
356
|
+
logger_default.error(
|
|
357
|
+
"\n" + chalk2.bgRed.white.bold(" ERROR ") + " " + chalk2.white.bold("Unknown error occurred")
|
|
358
|
+
);
|
|
359
|
+
if (error !== null && error !== void 0) {
|
|
360
|
+
logger_default.error(chalk2.gray("Error details:"));
|
|
361
|
+
logger_default.error(" " + chalk2.white(String(error)));
|
|
362
|
+
}
|
|
363
|
+
logger_default.error("");
|
|
174
364
|
}
|
|
175
365
|
};
|
|
176
366
|
|
|
@@ -185,11 +375,11 @@ var ToolErrorCodes = {
|
|
|
185
375
|
GLOBAL_EXECUTE_TOOL_FN_NOT_SET: "GLOBAL_EXECUTE_TOOL_FN_NOT_SET"
|
|
186
376
|
};
|
|
187
377
|
var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
188
|
-
constructor(message = "Provider not defined",
|
|
378
|
+
constructor(message = "Provider not defined", options = {}) {
|
|
189
379
|
super(message, {
|
|
380
|
+
...options,
|
|
190
381
|
code: ToolErrorCodes.TOOLSET_NOT_DEFINED,
|
|
191
|
-
|
|
192
|
-
possibleFixes: [
|
|
382
|
+
possibleFixes: options.possibleFixes || [
|
|
193
383
|
"Ensure that the provider is defined in the Composio project and passed into the tool instance"
|
|
194
384
|
]
|
|
195
385
|
});
|
|
@@ -197,86 +387,103 @@ var ComposioProviderNotDefinedError = class extends ComposioError {
|
|
|
197
387
|
}
|
|
198
388
|
};
|
|
199
389
|
var ComposioToolNotFoundError = class extends ComposioError {
|
|
200
|
-
constructor(message = "Tool not found",
|
|
390
|
+
constructor(message = "Tool not found", options = {}) {
|
|
201
391
|
super(message, {
|
|
392
|
+
...options,
|
|
202
393
|
code: ToolErrorCodes.TOOL_NOT_FOUND,
|
|
203
|
-
|
|
204
|
-
|
|
394
|
+
possibleFixes: options.possibleFixes || [
|
|
395
|
+
"Ensure the tool slug is correct and exists in the Composio project"
|
|
396
|
+
]
|
|
205
397
|
});
|
|
206
398
|
this.name = "ComposioToolNotFoundError";
|
|
207
399
|
}
|
|
208
400
|
};
|
|
209
401
|
var ComposioInvalidModifierError = class extends ComposioError {
|
|
210
|
-
constructor(message = "Invalid modifier",
|
|
402
|
+
constructor(message = "Invalid modifier", options = {}) {
|
|
211
403
|
super(message, {
|
|
404
|
+
...options,
|
|
212
405
|
code: ToolErrorCodes.INVALID_MODIFIER,
|
|
213
|
-
|
|
214
|
-
|
|
406
|
+
possibleFixes: options.possibleFixes || [
|
|
407
|
+
"Ensure the modifier is a function and returns a valid result"
|
|
408
|
+
]
|
|
215
409
|
});
|
|
216
410
|
this.name = "ComposioInvalidModifierError";
|
|
217
411
|
}
|
|
218
412
|
};
|
|
219
413
|
var ComposioCustomToolsNotInitializedError = class extends ComposioError {
|
|
220
|
-
constructor(message = "Custom tools not initialized",
|
|
414
|
+
constructor(message = "Custom tools not initialized", options = {}) {
|
|
221
415
|
super(message, {
|
|
416
|
+
...options,
|
|
222
417
|
code: ToolErrorCodes.CUSTOM_TOOLS_NOT_INITIALIZED,
|
|
223
|
-
|
|
224
|
-
|
|
418
|
+
possibleFixes: options.possibleFixes || [
|
|
419
|
+
"Ensure the custom tools class is initialized in the Tools instance"
|
|
420
|
+
]
|
|
225
421
|
});
|
|
226
422
|
this.name = "ComposioCustomToolsNotInitializedError";
|
|
227
423
|
}
|
|
228
424
|
};
|
|
229
425
|
var ComposioToolExecutionError = class extends ComposioError {
|
|
230
426
|
error;
|
|
231
|
-
constructor(
|
|
427
|
+
constructor(message = "Tool execution error", options = {}) {
|
|
428
|
+
const { originalError, ...restOptions } = options;
|
|
232
429
|
super(message, {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
possibleFixes:
|
|
430
|
+
...restOptions,
|
|
431
|
+
code: options.code || ToolErrorCodes.TOOL_EXECUTION_ERROR,
|
|
432
|
+
cause: options.cause || originalError,
|
|
433
|
+
possibleFixes: options.possibleFixes || [
|
|
434
|
+
"Ensure the tool is correctly configured and the input is valid"
|
|
435
|
+
]
|
|
237
436
|
});
|
|
238
|
-
this.error =
|
|
437
|
+
this.error = originalError || (options.cause instanceof Error ? options.cause : new Error(String(options.cause)));
|
|
239
438
|
this.name = "ComposioToolExecutionError";
|
|
240
439
|
}
|
|
241
440
|
};
|
|
242
441
|
var ComposioInvalidExecuteFunctionError = class extends ComposioError {
|
|
243
|
-
constructor(message = "Invalid execute function",
|
|
442
|
+
constructor(message = "Invalid execute function", options = {}) {
|
|
244
443
|
super(message, {
|
|
444
|
+
...options,
|
|
245
445
|
code: ToolErrorCodes.INVALID_EXECUTE_FUNCTION,
|
|
246
|
-
|
|
247
|
-
|
|
446
|
+
possibleFixes: options.possibleFixes || [
|
|
447
|
+
"Ensure the execute function is a valid function and returns a valid result"
|
|
448
|
+
]
|
|
248
449
|
});
|
|
249
450
|
this.name = "ComposioInvalidExecuteFunctionError";
|
|
250
451
|
}
|
|
251
452
|
};
|
|
252
453
|
var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
|
|
253
|
-
constructor(message = "Global execute tool function not set",
|
|
454
|
+
constructor(message = "Global execute tool function not set", options = {}) {
|
|
254
455
|
super(message, {
|
|
456
|
+
...options,
|
|
255
457
|
code: ToolErrorCodes.GLOBAL_EXECUTE_TOOL_FN_NOT_SET,
|
|
256
|
-
|
|
257
|
-
|
|
458
|
+
possibleFixes: options.possibleFixes || [
|
|
459
|
+
"Ensure the global execute tool function is set in the provider"
|
|
460
|
+
]
|
|
258
461
|
});
|
|
259
462
|
this.name = "ComposioGlobalExecuteToolFnNotSetError";
|
|
260
463
|
}
|
|
261
464
|
};
|
|
262
465
|
|
|
263
|
-
// src/errors/
|
|
466
|
+
// src/errors/ConnectedAccountsErrors.ts
|
|
264
467
|
var ConnectedAccountErrorCodes = {
|
|
265
468
|
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
|
|
266
469
|
};
|
|
267
470
|
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
268
|
-
constructor(message = "Connected account not found",
|
|
471
|
+
constructor(message = "Connected account not found", options = {}) {
|
|
269
472
|
super(message, {
|
|
473
|
+
...options,
|
|
270
474
|
code: ConnectedAccountErrorCodes.CONNECTED_ACCOUNT_NOT_FOUND,
|
|
271
475
|
statusCode: 404,
|
|
272
|
-
|
|
273
|
-
possibleFixes: [
|
|
476
|
+
possibleFixes: options.possibleFixes || [
|
|
274
477
|
"Ensure the connected account exists and is active in your Composio dashboard"
|
|
275
478
|
]
|
|
276
479
|
});
|
|
480
|
+
this.name = "ComposioConnectedAccountNotFoundError";
|
|
277
481
|
}
|
|
278
482
|
};
|
|
279
483
|
|
|
484
|
+
// src/telemetry/Telemetry.ts
|
|
485
|
+
import { ComposioError as ComposioClientError } from "@composio/client";
|
|
486
|
+
|
|
280
487
|
// src/types/telemetry.types.ts
|
|
281
488
|
var TELEMETRY_EVENTS = {
|
|
282
489
|
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
@@ -354,7 +561,7 @@ var BrowserTelemetryTransport = class {
|
|
|
354
561
|
};
|
|
355
562
|
|
|
356
563
|
// src/telemetry/transports/ProcessTransport.ts
|
|
357
|
-
import
|
|
564
|
+
import chalk3 from "chalk";
|
|
358
565
|
var ProcessTelemetryTransport = class {
|
|
359
566
|
send(payload) {
|
|
360
567
|
if (typeof window !== "undefined") {
|
|
@@ -397,14 +604,15 @@ var ProcessTelemetryTransport = class {
|
|
|
397
604
|
import("child_process").then(({ spawn }) => {
|
|
398
605
|
spawn("node", args, {
|
|
399
606
|
stdio: "ignore",
|
|
400
|
-
detached:
|
|
607
|
+
detached: false,
|
|
401
608
|
shell: false
|
|
402
609
|
}).unref();
|
|
403
610
|
resolve();
|
|
404
|
-
}).catch(() => {
|
|
611
|
+
}).catch((error) => {
|
|
612
|
+
logger_default.error("Error sending telemetry", error);
|
|
405
613
|
resolve();
|
|
406
614
|
});
|
|
407
|
-
logger_default.debug(
|
|
615
|
+
logger_default.debug(chalk3.yellow("Process Telemetry"), JSON.stringify(payload, null, 2));
|
|
408
616
|
} catch (error) {
|
|
409
617
|
logger_default.error("Error sending telemetry", error);
|
|
410
618
|
resolve();
|
|
@@ -413,6 +621,12 @@ var ProcessTelemetryTransport = class {
|
|
|
413
621
|
}
|
|
414
622
|
};
|
|
415
623
|
|
|
624
|
+
// src/utils/uuid.ts
|
|
625
|
+
import { v4 as uuidv4 } from "uuid";
|
|
626
|
+
function getRandomUUID() {
|
|
627
|
+
return uuidv4();
|
|
628
|
+
}
|
|
629
|
+
|
|
416
630
|
// src/telemetry/Telemetry.ts
|
|
417
631
|
var TelemetryService = class {
|
|
418
632
|
telemetryMetadata;
|
|
@@ -437,8 +651,7 @@ var TelemetryService = class {
|
|
|
437
651
|
this.sendTelemetry([
|
|
438
652
|
{
|
|
439
653
|
eventName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
440
|
-
data: {}
|
|
441
|
-
sdk_meta: this.telemetryMetadata
|
|
654
|
+
data: {}
|
|
442
655
|
}
|
|
443
656
|
]);
|
|
444
657
|
}
|
|
@@ -467,24 +680,16 @@ var TelemetryService = class {
|
|
|
467
680
|
fileName: instrumentedClassName,
|
|
468
681
|
method: name,
|
|
469
682
|
params: args
|
|
470
|
-
}
|
|
471
|
-
sdk_meta: this.telemetryMetadata
|
|
683
|
+
}
|
|
472
684
|
};
|
|
473
685
|
this.batchProcessor.pushItem(telemetryPayload);
|
|
474
686
|
try {
|
|
475
687
|
return await originalMethod.apply(instance, args);
|
|
476
688
|
} catch (error) {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
method: name,
|
|
482
|
-
params: args,
|
|
483
|
-
error
|
|
484
|
-
},
|
|
485
|
-
sdk_meta: this.telemetryMetadata
|
|
486
|
-
};
|
|
487
|
-
this.batchProcessor.pushItem(telemetryPayload2);
|
|
689
|
+
if (error instanceof Error && !error.errorId) {
|
|
690
|
+
error.errorId = getRandomUUID();
|
|
691
|
+
this.prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args);
|
|
692
|
+
}
|
|
488
693
|
throw error;
|
|
489
694
|
}
|
|
490
695
|
};
|
|
@@ -502,6 +707,47 @@ var TelemetryService = class {
|
|
|
502
707
|
const isTelemetryDisabledByEnv = getEnvVariable("TELEMETRY_DISABLED", "false") === "true";
|
|
503
708
|
return this.transport && !this.isTelemetryDisabled && !isTelemetryDisabledByEnv && !isDevEnvironment;
|
|
504
709
|
}
|
|
710
|
+
/**
|
|
711
|
+
* Prepare and send the error telemetry.
|
|
712
|
+
*
|
|
713
|
+
* @TODO This currently blocks the thread and sends the telemetry to the server.
|
|
714
|
+
*
|
|
715
|
+
* @param {unknown} error - The error to send.
|
|
716
|
+
* @param {string} instrumentedClassName - The class name of the instrumented class.
|
|
717
|
+
* @param {string} name - The name of the method that threw the error.
|
|
718
|
+
*/
|
|
719
|
+
prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args) {
|
|
720
|
+
if (error instanceof ComposioClientError) {
|
|
721
|
+
const telemetryPayload = {
|
|
722
|
+
error_id: error.errorId || "",
|
|
723
|
+
error_message: error.message,
|
|
724
|
+
original_error: error.cause || error,
|
|
725
|
+
current_stack: error.stack?.split("\n") || [],
|
|
726
|
+
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
727
|
+
};
|
|
728
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
729
|
+
} else if (error instanceof ComposioError) {
|
|
730
|
+
const telemetryPayload = {
|
|
731
|
+
error_id: error.errorId || "",
|
|
732
|
+
error_message: error.message,
|
|
733
|
+
original_error: error.cause || error,
|
|
734
|
+
current_stack: error.stack?.split("\n") || [],
|
|
735
|
+
error_code: error.code,
|
|
736
|
+
possible_fix: error.possibleFixes?.join("\n"),
|
|
737
|
+
description: `Original Call : ${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
738
|
+
};
|
|
739
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
740
|
+
} else if (error instanceof Error) {
|
|
741
|
+
const telemetryPayload = {
|
|
742
|
+
error_id: error.errorId || "",
|
|
743
|
+
error_message: error instanceof Error ? error.name : "Unknown error",
|
|
744
|
+
original_error: error,
|
|
745
|
+
current_stack: error.stack?.split("\n") || [],
|
|
746
|
+
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
747
|
+
};
|
|
748
|
+
this.sendErrorTelemetry(telemetryPayload);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
505
751
|
/**
|
|
506
752
|
* Send the telemetry payload to the server.
|
|
507
753
|
* @param payload - the telemetry payload to send
|
|
@@ -513,20 +759,27 @@ var TelemetryService = class {
|
|
|
513
759
|
}
|
|
514
760
|
const url = `${TELEMETRY_URL}/api/sdk_metrics/telemetry`;
|
|
515
761
|
const reqPayload = {
|
|
516
|
-
data: payload
|
|
762
|
+
data: payload.map((p) => ({
|
|
763
|
+
...p,
|
|
764
|
+
sdk_meta: this.telemetryMetadata
|
|
765
|
+
})),
|
|
517
766
|
url,
|
|
518
767
|
method: "POST",
|
|
519
768
|
headers: { "Content-Type": "application/json" }
|
|
520
769
|
};
|
|
521
770
|
this.transport.send(reqPayload);
|
|
522
771
|
}
|
|
523
|
-
|
|
772
|
+
// @TODO: check if this will send the error telemetry to the server
|
|
773
|
+
async sendErrorTelemetry(payload) {
|
|
524
774
|
if (!this.shouldSendTelemetry()) {
|
|
525
775
|
return;
|
|
526
776
|
}
|
|
527
777
|
const url = `${TELEMETRY_URL}/api/sdk_metrics/error`;
|
|
528
778
|
const reqPayload = {
|
|
529
|
-
data: {
|
|
779
|
+
data: {
|
|
780
|
+
...payload,
|
|
781
|
+
sdk_meta: this.telemetryMetadata
|
|
782
|
+
},
|
|
530
783
|
url,
|
|
531
784
|
method: "POST",
|
|
532
785
|
headers: { "Content-Type": "application/json" }
|
|
@@ -702,36 +955,50 @@ var CustomTools = class {
|
|
|
702
955
|
}
|
|
703
956
|
};
|
|
704
957
|
|
|
705
|
-
// src/errors/
|
|
706
|
-
import { ZodError } from "zod";
|
|
958
|
+
// src/errors/ValidationErrors.ts
|
|
959
|
+
import { ZodError as ZodError2 } from "zod";
|
|
707
960
|
var ValidationErrorCodes = {
|
|
708
961
|
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
709
962
|
};
|
|
710
963
|
var ValidationError = class extends ComposioError {
|
|
711
|
-
|
|
712
|
-
|
|
964
|
+
constructor(message = "Input validation failed", options = {}) {
|
|
965
|
+
const { cause: providedZodError, ...restOptions } = options;
|
|
713
966
|
let zodErrorInstance;
|
|
714
|
-
if (
|
|
715
|
-
zodErrorInstance =
|
|
967
|
+
if (providedZodError instanceof ZodError2) {
|
|
968
|
+
zodErrorInstance = providedZodError;
|
|
969
|
+
} else {
|
|
970
|
+
zodErrorInstance = new ZodError2([
|
|
716
971
|
{
|
|
717
972
|
path: [],
|
|
718
973
|
message: "Invalid input",
|
|
719
974
|
code: "custom"
|
|
720
975
|
}
|
|
721
976
|
]);
|
|
722
|
-
} else {
|
|
723
|
-
zodErrorInstance = zodError;
|
|
724
977
|
}
|
|
725
978
|
const issues = zodErrorInstance.issues.map(
|
|
726
979
|
(issue) => `[${issue.code}] ${issue.path.join(".")} - ${issue.message}`
|
|
727
980
|
);
|
|
728
981
|
super(message, {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
982
|
+
...restOptions,
|
|
983
|
+
code: options.code || ValidationErrorCodes.VALIDATION_ERROR,
|
|
984
|
+
possibleFixes: issues,
|
|
985
|
+
cause: zodErrorInstance
|
|
732
986
|
});
|
|
733
|
-
this.zodError = zodErrorInstance;
|
|
734
987
|
this.name = "ValidationError";
|
|
988
|
+
const userFriendlyMessage = this.generateUserFriendlyMessage();
|
|
989
|
+
this.message = `${message}: ${userFriendlyMessage}`;
|
|
990
|
+
}
|
|
991
|
+
generateUserFriendlyMessage() {
|
|
992
|
+
if (this.cause instanceof ZodError2 && this.cause.issues.length > 0) {
|
|
993
|
+
const issue = this.cause.issues[0];
|
|
994
|
+
const path = issue.path.join(".");
|
|
995
|
+
const param = path || "parameter";
|
|
996
|
+
if (issue.code === "invalid_type") {
|
|
997
|
+
return `The ${param} should be a ${issue.expected}, but you provided a ${issue.received}`;
|
|
998
|
+
}
|
|
999
|
+
return issue.message;
|
|
1000
|
+
}
|
|
1001
|
+
return "Please check your input parameters";
|
|
735
1002
|
}
|
|
736
1003
|
};
|
|
737
1004
|
|
|
@@ -901,7 +1168,9 @@ var Tools = class {
|
|
|
901
1168
|
async getRawComposioTools(userId, query = {}, modifier) {
|
|
902
1169
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
903
1170
|
if (queryParams.error) {
|
|
904
|
-
throw new ValidationError(
|
|
1171
|
+
throw new ValidationError("Invalid tool list parameters", {
|
|
1172
|
+
cause: queryParams.error
|
|
1173
|
+
});
|
|
905
1174
|
}
|
|
906
1175
|
const tools = await this.client.tools.list({
|
|
907
1176
|
tool_slugs: queryParams.data.tools,
|
|
@@ -946,11 +1215,13 @@ var Tools = class {
|
|
|
946
1215
|
if (customTool) {
|
|
947
1216
|
return customTool;
|
|
948
1217
|
}
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
1218
|
+
let tool;
|
|
1219
|
+
try {
|
|
1220
|
+
tool = await this.client.tools.retrieve(slug);
|
|
1221
|
+
} catch (error) {
|
|
1222
|
+
throw new ComposioToolNotFoundError(`Unable to retrieve tool with slug ${slug}`, {
|
|
1223
|
+
cause: error
|
|
1224
|
+
});
|
|
954
1225
|
}
|
|
955
1226
|
let modifiedToool = this.transformToolCases(tool);
|
|
956
1227
|
if (modifier) {
|
|
@@ -1127,9 +1398,12 @@ var Tools = class {
|
|
|
1127
1398
|
return this.handleComposioToolExecution(composioTool, body, modifiers);
|
|
1128
1399
|
}
|
|
1129
1400
|
} catch (error) {
|
|
1130
|
-
throw new ComposioToolExecutionError(
|
|
1131
|
-
|
|
1132
|
-
|
|
1401
|
+
throw new ComposioToolExecutionError(`Error executing tool ${slug}`, {
|
|
1402
|
+
originalError: error,
|
|
1403
|
+
meta: {
|
|
1404
|
+
toolSlug: slug,
|
|
1405
|
+
body
|
|
1406
|
+
}
|
|
1133
1407
|
});
|
|
1134
1408
|
}
|
|
1135
1409
|
}
|
|
@@ -1203,6 +1477,9 @@ var Tools = class {
|
|
|
1203
1477
|
}
|
|
1204
1478
|
};
|
|
1205
1479
|
|
|
1480
|
+
// src/models/Toolkits.ts
|
|
1481
|
+
import ComposioClient2 from "@composio/client";
|
|
1482
|
+
|
|
1206
1483
|
// src/types/toolkit.types.ts
|
|
1207
1484
|
import { z as z2 } from "zod";
|
|
1208
1485
|
var ToolkitMangedByEnumSchema = z2.enum(["all", "composio", "project"]);
|
|
@@ -1283,8 +1560,101 @@ var ToolkitRetrieveCategoriesResponseSchema = z2.object({
|
|
|
1283
1560
|
totalPages: z2.number()
|
|
1284
1561
|
});
|
|
1285
1562
|
|
|
1286
|
-
// src/
|
|
1287
|
-
|
|
1563
|
+
// src/errors/AuthConfigErrors.ts
|
|
1564
|
+
var AuthConfigErrorCodes = {
|
|
1565
|
+
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1566
|
+
};
|
|
1567
|
+
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1568
|
+
constructor(message = "Auth config not found", options = {}) {
|
|
1569
|
+
super(message, {
|
|
1570
|
+
...options,
|
|
1571
|
+
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1572
|
+
possibleFixes: options.possibleFixes || [
|
|
1573
|
+
"Check if the auth config exists",
|
|
1574
|
+
"Check if the auth config id is correct",
|
|
1575
|
+
"Check if the auth config is enabled"
|
|
1576
|
+
]
|
|
1577
|
+
});
|
|
1578
|
+
this.name = "ComposioAuthConfigNotFoundError";
|
|
1579
|
+
}
|
|
1580
|
+
};
|
|
1581
|
+
|
|
1582
|
+
// src/errors/ConnectionRequestErrors.ts
|
|
1583
|
+
var ConnectionRequestErrorCodes = {
|
|
1584
|
+
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1585
|
+
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1586
|
+
};
|
|
1587
|
+
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1588
|
+
constructor(message = "Connection request timed out", options = {}) {
|
|
1589
|
+
super(message, {
|
|
1590
|
+
...options,
|
|
1591
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT
|
|
1592
|
+
});
|
|
1593
|
+
this.name = "ConnectionRequestTimeoutError";
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
var ConnectionRequestFailedError = class extends ComposioError {
|
|
1597
|
+
constructor(message = "Connection request failed", options = {}) {
|
|
1598
|
+
super(message, {
|
|
1599
|
+
...options,
|
|
1600
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED
|
|
1601
|
+
});
|
|
1602
|
+
this.name = "ConnectionRequestFailedError";
|
|
1603
|
+
}
|
|
1604
|
+
};
|
|
1605
|
+
|
|
1606
|
+
// src/errors/ToolkitErrors.ts
|
|
1607
|
+
var ToolkitErrorCodes = {
|
|
1608
|
+
TOOLKIT_NOT_FOUND: "TOOLKIT_NOT_FOUND"
|
|
1609
|
+
};
|
|
1610
|
+
var ComposioToolkitNotFoundError = class extends ComposioError {
|
|
1611
|
+
constructor(message = "Toolkit not found", options = {}) {
|
|
1612
|
+
super(message, {
|
|
1613
|
+
...options,
|
|
1614
|
+
code: "TOOLKIT_NOT_FOUND",
|
|
1615
|
+
possibleFixes: options.possibleFixes || [
|
|
1616
|
+
"Ensure the toolkit is correctly configured and the slug is valid"
|
|
1617
|
+
]
|
|
1618
|
+
});
|
|
1619
|
+
this.name = "ComposioToolkitNotFoundError";
|
|
1620
|
+
}
|
|
1621
|
+
};
|
|
1622
|
+
var ComposioToolkitFetchError = class extends ComposioError {
|
|
1623
|
+
constructor(message = "Failed to fetch toolkit", options = {}) {
|
|
1624
|
+
super(message, {
|
|
1625
|
+
...options,
|
|
1626
|
+
code: "TOOLKIT_FETCH_ERROR",
|
|
1627
|
+
possibleFixes: options.possibleFixes || [
|
|
1628
|
+
"Ensure the toolkit slug is valid",
|
|
1629
|
+
"Ensure you are using the correct API key",
|
|
1630
|
+
"Ensure you are using the correct API endpoint / Base URL and it is working"
|
|
1631
|
+
]
|
|
1632
|
+
});
|
|
1633
|
+
this.name = "ComposioToolkitFetchError";
|
|
1634
|
+
}
|
|
1635
|
+
};
|
|
1636
|
+
|
|
1637
|
+
// src/errors/SDKErrors.ts
|
|
1638
|
+
var SDKErrorCodes = {
|
|
1639
|
+
NO_API_KEY_PROVIDED: "NO_API_KEY_PROVIDED"
|
|
1640
|
+
};
|
|
1641
|
+
var ComposioNoAPIKeyError = class extends ComposioError {
|
|
1642
|
+
constructor(message = "No Composio API key provided", options = {}) {
|
|
1643
|
+
const defaultCause = "Couldn't find an API key in the params, environment variables or in the user config file";
|
|
1644
|
+
super(message, {
|
|
1645
|
+
...options,
|
|
1646
|
+
code: "NO_API_KEY",
|
|
1647
|
+
cause: options.cause || defaultCause,
|
|
1648
|
+
possibleFixes: options.possibleFixes || [
|
|
1649
|
+
"Ensure you have an API key passed in the params, or in environment variable (COMPOSIO_API_KEY) or in the user config file",
|
|
1650
|
+
"To get an API key, please sign up at https://composio.dev/signup",
|
|
1651
|
+
"You can also use the Composio CLI to create a project and get an API key"
|
|
1652
|
+
],
|
|
1653
|
+
statusCode: 401
|
|
1654
|
+
});
|
|
1655
|
+
this.name = "ComposioNoAPIKeyError";
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1288
1658
|
|
|
1289
1659
|
// src/types/authConfigs.types.ts
|
|
1290
1660
|
import { z as z3 } from "zod";
|
|
@@ -1365,7 +1735,7 @@ var AuthConfigListParamsSchema = z3.object({
|
|
|
1365
1735
|
cursor: z3.string().optional(),
|
|
1366
1736
|
isComposioManaged: z3.boolean().optional(),
|
|
1367
1737
|
limit: z3.number().optional(),
|
|
1368
|
-
|
|
1738
|
+
toolkit: z3.string().optional()
|
|
1369
1739
|
});
|
|
1370
1740
|
var AuthConfigListResponseSchema = z3.object({
|
|
1371
1741
|
items: z3.array(AuthConfigRetrieveResponseSchema),
|
|
@@ -1434,7 +1804,9 @@ var AuthConfigs = class {
|
|
|
1434
1804
|
lastUpdatedAt: authConfig.last_updated_at
|
|
1435
1805
|
});
|
|
1436
1806
|
if (result.error) {
|
|
1437
|
-
throw new ValidationError(
|
|
1807
|
+
throw new ValidationError("Failed to parse auth config response", {
|
|
1808
|
+
cause: result.error
|
|
1809
|
+
});
|
|
1438
1810
|
}
|
|
1439
1811
|
return result.data;
|
|
1440
1812
|
}
|
|
@@ -1455,7 +1827,7 @@ var AuthConfigs = class {
|
|
|
1455
1827
|
*
|
|
1456
1828
|
* // List auth configs for a specific toolkit
|
|
1457
1829
|
* const githubConfigs = await composio.authConfigs.list({
|
|
1458
|
-
*
|
|
1830
|
+
* toolkit: 'github'
|
|
1459
1831
|
* });
|
|
1460
1832
|
*
|
|
1461
1833
|
* // List Composio-managed auth configs
|
|
@@ -1470,7 +1842,7 @@ var AuthConfigs = class {
|
|
|
1470
1842
|
cursor: parsedQuery?.cursor,
|
|
1471
1843
|
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1472
1844
|
limit: parsedQuery?.limit?.toString(),
|
|
1473
|
-
toolkit_slug: parsedQuery?.
|
|
1845
|
+
toolkit_slug: parsedQuery?.toolkit
|
|
1474
1846
|
});
|
|
1475
1847
|
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
1476
1848
|
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
@@ -1478,7 +1850,9 @@ var AuthConfigs = class {
|
|
|
1478
1850
|
totalPages: result.total_pages
|
|
1479
1851
|
});
|
|
1480
1852
|
if (parsedResult.error) {
|
|
1481
|
-
throw new ValidationError(
|
|
1853
|
+
throw new ValidationError("Failed to parse auth config list response", {
|
|
1854
|
+
cause: parsedResult.error
|
|
1855
|
+
});
|
|
1482
1856
|
}
|
|
1483
1857
|
return parsedResult.data;
|
|
1484
1858
|
}
|
|
@@ -1503,7 +1877,9 @@ var AuthConfigs = class {
|
|
|
1503
1877
|
async create(toolkit, options = { type: "use_composio_managed_auth" }) {
|
|
1504
1878
|
const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
|
|
1505
1879
|
if (parsedOptions.error) {
|
|
1506
|
-
throw new ValidationError(
|
|
1880
|
+
throw new ValidationError("Failed to parse auth config create options", {
|
|
1881
|
+
cause: parsedOptions.error
|
|
1882
|
+
});
|
|
1507
1883
|
}
|
|
1508
1884
|
const result = await this.client.authConfigs.create({
|
|
1509
1885
|
toolkit: {
|
|
@@ -1518,7 +1894,9 @@ var AuthConfigs = class {
|
|
|
1518
1894
|
toolkit: result.toolkit.slug
|
|
1519
1895
|
});
|
|
1520
1896
|
if (parsedResult.error) {
|
|
1521
|
-
throw new ValidationError(
|
|
1897
|
+
throw new ValidationError("Failed to parse auth config create response", {
|
|
1898
|
+
cause: parsedResult.error
|
|
1899
|
+
});
|
|
1522
1900
|
}
|
|
1523
1901
|
return parsedResult.data;
|
|
1524
1902
|
}
|
|
@@ -1578,7 +1956,9 @@ var AuthConfigs = class {
|
|
|
1578
1956
|
async update(nanoid, data) {
|
|
1579
1957
|
const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
|
|
1580
1958
|
if (parsedData.error) {
|
|
1581
|
-
throw new ValidationError(
|
|
1959
|
+
throw new ValidationError("Failed to parse auth config update data", {
|
|
1960
|
+
cause: parsedData.error
|
|
1961
|
+
});
|
|
1582
1962
|
}
|
|
1583
1963
|
return this.client.authConfigs.update(
|
|
1584
1964
|
nanoid,
|
|
@@ -1679,25 +2059,6 @@ var AuthConfigs = class {
|
|
|
1679
2059
|
}
|
|
1680
2060
|
};
|
|
1681
2061
|
|
|
1682
|
-
// src/errors/AuthConfigErrors.ts
|
|
1683
|
-
var AuthConfigErrorCodes = {
|
|
1684
|
-
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1685
|
-
};
|
|
1686
|
-
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1687
|
-
constructor(message, meta) {
|
|
1688
|
-
super(message, {
|
|
1689
|
-
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1690
|
-
cause: meta,
|
|
1691
|
-
possibleFixes: [
|
|
1692
|
-
"Check if the auth config exists",
|
|
1693
|
-
"Check if the auth config id is correct",
|
|
1694
|
-
"Check if the auth config is enabled"
|
|
1695
|
-
]
|
|
1696
|
-
});
|
|
1697
|
-
this.name = "ComposioAuthConfigNotFoundError";
|
|
1698
|
-
}
|
|
1699
|
-
};
|
|
1700
|
-
|
|
1701
2062
|
// src/types/connectedAccounts.types.ts
|
|
1702
2063
|
import { z as z4 } from "zod";
|
|
1703
2064
|
var ConnectedAccountStatuses = {
|
|
@@ -1815,33 +2176,7 @@ var ConnectedAccountListResponseSchema = z4.object({
|
|
|
1815
2176
|
|
|
1816
2177
|
// src/models/ConnectionRequest.ts
|
|
1817
2178
|
import ComposioClient from "@composio/client";
|
|
1818
|
-
import { ZodError as
|
|
1819
|
-
|
|
1820
|
-
// src/errors/ConnectionRequestError.ts
|
|
1821
|
-
var ConnectionRequestErrorCodes = {
|
|
1822
|
-
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1823
|
-
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1824
|
-
};
|
|
1825
|
-
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1826
|
-
constructor(message = "Connection request timed out", meta = {}) {
|
|
1827
|
-
super(message, {
|
|
1828
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
|
|
1829
|
-
meta
|
|
1830
|
-
});
|
|
1831
|
-
this.name = "ConnectionRequestTimeoutError";
|
|
1832
|
-
}
|
|
1833
|
-
};
|
|
1834
|
-
var ConnectionRequestFailedError = class extends ComposioError {
|
|
1835
|
-
constructor(message = "Connection request failed", meta = {}) {
|
|
1836
|
-
super(message, {
|
|
1837
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED,
|
|
1838
|
-
meta
|
|
1839
|
-
});
|
|
1840
|
-
this.name = "ConnectionRequestFailedError";
|
|
1841
|
-
}
|
|
1842
|
-
};
|
|
1843
|
-
|
|
1844
|
-
// src/models/ConnectionRequest.ts
|
|
2179
|
+
import { ZodError as ZodError3 } from "zod";
|
|
1845
2180
|
var ConnectionRequest = class {
|
|
1846
2181
|
client;
|
|
1847
2182
|
id;
|
|
@@ -1887,7 +2222,7 @@ var ConnectionRequest = class {
|
|
|
1887
2222
|
return parsedResponse;
|
|
1888
2223
|
} catch (error) {
|
|
1889
2224
|
logger_default.error("Error transforming response", error);
|
|
1890
|
-
if (error instanceof
|
|
2225
|
+
if (error instanceof ZodError3) {
|
|
1891
2226
|
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1892
2227
|
}
|
|
1893
2228
|
throw error;
|
|
@@ -1931,7 +2266,9 @@ var ConnectionRequest = class {
|
|
|
1931
2266
|
throw new ComposioConnectedAccountNotFoundError(
|
|
1932
2267
|
`Connected account with id ${this.id} not found`,
|
|
1933
2268
|
{
|
|
1934
|
-
|
|
2269
|
+
meta: {
|
|
2270
|
+
connectedAccountId: this.id
|
|
2271
|
+
}
|
|
1935
2272
|
}
|
|
1936
2273
|
);
|
|
1937
2274
|
} else {
|
|
@@ -1956,10 +2293,12 @@ var ConnectionRequest = class {
|
|
|
1956
2293
|
throw new ConnectionRequestFailedError(
|
|
1957
2294
|
`Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ""}`,
|
|
1958
2295
|
{
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
2296
|
+
meta: {
|
|
2297
|
+
userId: response.user_id,
|
|
2298
|
+
connectedAccountId: this.id,
|
|
2299
|
+
status: response.status,
|
|
2300
|
+
statusReason: response.status_reason
|
|
2301
|
+
}
|
|
1963
2302
|
}
|
|
1964
2303
|
);
|
|
1965
2304
|
}
|
|
@@ -1997,7 +2336,9 @@ var ConnectedAccounts = class {
|
|
|
1997
2336
|
testRequestEndpoint: response.test_request_endpoint
|
|
1998
2337
|
});
|
|
1999
2338
|
if (!result.success) {
|
|
2000
|
-
throw new ValidationError(
|
|
2339
|
+
throw new ValidationError("Failed to parse connected account retrieve response", {
|
|
2340
|
+
cause: result.error
|
|
2341
|
+
});
|
|
2001
2342
|
}
|
|
2002
2343
|
return result.data;
|
|
2003
2344
|
}
|
|
@@ -2030,7 +2371,9 @@ var ConnectedAccounts = class {
|
|
|
2030
2371
|
if (query) {
|
|
2031
2372
|
const parsedQuery = ConnectedAccountListParamsSchema.safeParse(query);
|
|
2032
2373
|
if (!parsedQuery.success) {
|
|
2033
|
-
throw new ValidationError(
|
|
2374
|
+
throw new ValidationError("Failed to parse connected account list query", {
|
|
2375
|
+
cause: parsedQuery.error
|
|
2376
|
+
});
|
|
2034
2377
|
}
|
|
2035
2378
|
rawQuery = {
|
|
2036
2379
|
auth_config_ids: parsedQuery.data.authConfigIds,
|
|
@@ -2050,7 +2393,9 @@ var ConnectedAccounts = class {
|
|
|
2050
2393
|
totalPages: result.total_pages
|
|
2051
2394
|
});
|
|
2052
2395
|
if (!parsedResponse.success) {
|
|
2053
|
-
throw new ValidationError(
|
|
2396
|
+
throw new ValidationError("Failed to parse connected account list response", {
|
|
2397
|
+
cause: parsedResponse.error
|
|
2398
|
+
});
|
|
2054
2399
|
}
|
|
2055
2400
|
return parsedResponse.data;
|
|
2056
2401
|
}
|
|
@@ -2236,42 +2581,46 @@ var Toolkits = class {
|
|
|
2236
2581
|
* @private
|
|
2237
2582
|
*/
|
|
2238
2583
|
async getToolkits(query) {
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
sort_by: parsedQuery.sortBy
|
|
2245
|
-
});
|
|
2246
|
-
const parsedResult = ToolKitListResponseSchema.parse({
|
|
2247
|
-
items: result.items.map((item) => {
|
|
2248
|
-
const parsedItem = ToolKitItemSchema.parse({
|
|
2249
|
-
name: item.name,
|
|
2250
|
-
slug: item.slug,
|
|
2251
|
-
meta: item.meta,
|
|
2252
|
-
isLocalToolkit: item.is_local_toolkit,
|
|
2253
|
-
authSchemes: item.auth_schemes,
|
|
2254
|
-
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
2255
|
-
noAuth: item.no_auth
|
|
2584
|
+
try {
|
|
2585
|
+
const parsedQuery = ToolkitsListParamsSchema.safeParse(query);
|
|
2586
|
+
if (!parsedQuery.success) {
|
|
2587
|
+
throw new ValidationError("Failed to parse toolkit list query", {
|
|
2588
|
+
cause: parsedQuery.error
|
|
2256
2589
|
});
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2590
|
+
}
|
|
2591
|
+
const result = await this.client.toolkits.list({
|
|
2592
|
+
category: parsedQuery.data.category,
|
|
2593
|
+
is_local: parsedQuery.data.isLocal,
|
|
2594
|
+
managed_by: parsedQuery.data.managedBy,
|
|
2595
|
+
sort_by: parsedQuery.data.sortBy
|
|
2596
|
+
});
|
|
2597
|
+
const parsedResult = ToolKitListResponseSchema.safeParse({
|
|
2598
|
+
items: result.items.map((item) => {
|
|
2599
|
+
const parsedItem = ToolKitItemSchema.parse({
|
|
2600
|
+
name: item.name,
|
|
2601
|
+
slug: item.slug,
|
|
2602
|
+
meta: item.meta,
|
|
2603
|
+
isLocalToolkit: item.is_local_toolkit,
|
|
2604
|
+
authSchemes: item.auth_schemes,
|
|
2605
|
+
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
2606
|
+
noAuth: item.no_auth
|
|
2607
|
+
});
|
|
2608
|
+
return parsedItem;
|
|
2609
|
+
}),
|
|
2610
|
+
nextCursor: result.next_cursor,
|
|
2611
|
+
totalPages: result.total_pages
|
|
2612
|
+
});
|
|
2613
|
+
if (!parsedResult.success) {
|
|
2614
|
+
throw new ValidationError("Failed to parse toolkit list response", {
|
|
2615
|
+
cause: parsedResult.error
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
return parsedResult.data;
|
|
2619
|
+
} catch (error) {
|
|
2620
|
+
throw new ComposioToolkitFetchError("Failed to fetch toolkits", {
|
|
2621
|
+
cause: error
|
|
2622
|
+
});
|
|
2273
2623
|
}
|
|
2274
|
-
return this.getToolkits(arg);
|
|
2275
2624
|
}
|
|
2276
2625
|
/**
|
|
2277
2626
|
* Retrieves a specific toolkit by its slug identifier.
|
|
@@ -2289,7 +2638,7 @@ var Toolkits = class {
|
|
|
2289
2638
|
async getToolkitBySlug(slug) {
|
|
2290
2639
|
try {
|
|
2291
2640
|
const result = await this.client.toolkits.retrieve(slug);
|
|
2292
|
-
const parsedResult = ToolkitRetrieveResponseSchema.
|
|
2641
|
+
const parsedResult = ToolkitRetrieveResponseSchema.safeParse({
|
|
2293
2642
|
name: result.name,
|
|
2294
2643
|
slug: result.slug,
|
|
2295
2644
|
meta: {
|
|
@@ -2314,16 +2663,41 @@ var Toolkits = class {
|
|
|
2314
2663
|
}
|
|
2315
2664
|
}))
|
|
2316
2665
|
});
|
|
2317
|
-
|
|
2666
|
+
if (!parsedResult.success) {
|
|
2667
|
+
throw new ValidationError("Failed to parse toolkit response", {
|
|
2668
|
+
cause: parsedResult.error
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
return parsedResult.data;
|
|
2318
2672
|
} catch (error) {
|
|
2319
|
-
if (error instanceof
|
|
2320
|
-
throw new
|
|
2673
|
+
if (error instanceof ComposioClient2.NotFoundError) {
|
|
2674
|
+
throw new ComposioToolkitNotFoundError(`Toolkit with slug ${slug} not found`, {
|
|
2675
|
+
meta: {
|
|
2676
|
+
slug
|
|
2677
|
+
},
|
|
2678
|
+
cause: error
|
|
2679
|
+
});
|
|
2321
2680
|
}
|
|
2322
|
-
throw new
|
|
2323
|
-
|
|
2681
|
+
throw new ComposioToolkitFetchError(`Couldn't fetch Toolkit with slug: ${slug}`, {
|
|
2682
|
+
meta: {
|
|
2683
|
+
slug
|
|
2684
|
+
},
|
|
2685
|
+
cause: error
|
|
2324
2686
|
});
|
|
2325
2687
|
}
|
|
2326
2688
|
}
|
|
2689
|
+
/**
|
|
2690
|
+
* Implementation method that handles both overloads for retrieving toolkits.
|
|
2691
|
+
*
|
|
2692
|
+
* @param {string | ToolkitListParams} arg - Either a toolkit slug or query parameters
|
|
2693
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit or list of toolkits
|
|
2694
|
+
*/
|
|
2695
|
+
async get(arg) {
|
|
2696
|
+
if (typeof arg === "string") {
|
|
2697
|
+
return this.getToolkitBySlug(arg);
|
|
2698
|
+
}
|
|
2699
|
+
return this.getToolkits(arg);
|
|
2700
|
+
}
|
|
2327
2701
|
/**
|
|
2328
2702
|
* Retrieves all toolkit categories available in the Composio SDK.
|
|
2329
2703
|
*
|
|
@@ -2371,7 +2745,7 @@ var Toolkits = class {
|
|
|
2371
2745
|
const composioAuthConfig = new AuthConfigs(this.client);
|
|
2372
2746
|
let authConfigIdToUse;
|
|
2373
2747
|
const authConfig = await composioAuthConfig.list({
|
|
2374
|
-
toolkitSlug
|
|
2748
|
+
toolkit: toolkitSlug
|
|
2375
2749
|
});
|
|
2376
2750
|
authConfigIdToUse = authConfig.items[0]?.id;
|
|
2377
2751
|
if (!authConfigIdToUse) {
|
|
@@ -2383,7 +2757,9 @@ var Toolkits = class {
|
|
|
2383
2757
|
authConfigIdToUse = authConfig2.id;
|
|
2384
2758
|
} else {
|
|
2385
2759
|
throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
|
|
2386
|
-
|
|
2760
|
+
meta: {
|
|
2761
|
+
toolkitSlug
|
|
2762
|
+
}
|
|
2387
2763
|
});
|
|
2388
2764
|
}
|
|
2389
2765
|
}
|
|
@@ -2643,6 +3019,7 @@ var userDataPath = () => {
|
|
|
2643
3019
|
const os = __require("os");
|
|
2644
3020
|
return path.join(os.homedir(), COMPOSIO_DIR, USER_DATA_FILE_NAME);
|
|
2645
3021
|
} catch (_error) {
|
|
3022
|
+
logger_default.debug("Environment", `Unable to get user data path`);
|
|
2646
3023
|
return null;
|
|
2647
3024
|
}
|
|
2648
3025
|
};
|
|
@@ -2652,6 +3029,7 @@ var getUserDataJson = () => {
|
|
|
2652
3029
|
const data = fs.readFileSync(userDataPath(), "utf8");
|
|
2653
3030
|
return JSON.parse(data);
|
|
2654
3031
|
} catch (_error) {
|
|
3032
|
+
logger_default.debug("Environment", "No user data file found");
|
|
2655
3033
|
return {};
|
|
2656
3034
|
}
|
|
2657
3035
|
};
|
|
@@ -2660,6 +3038,13 @@ function getSDKConfig(baseUrl, apiKey) {
|
|
|
2660
3038
|
const { api_key: apiKeyFromUserConfig, base_url: baseURLFromUserConfig } = userData;
|
|
2661
3039
|
const baseURLParsed = baseUrl || getEnvVariable("COMPOSIO_BASE_URL") || baseURLFromUserConfig || DEFAULT_BASE_URL;
|
|
2662
3040
|
const apiKeyParsed = apiKey || getEnvVariable("COMPOSIO_API_KEY") || apiKeyFromUserConfig || "";
|
|
3041
|
+
if (!apiKeyParsed) {
|
|
3042
|
+
ComposioError.handle(new ComposioNoAPIKeyError(), {
|
|
3043
|
+
exitProcess: true
|
|
3044
|
+
});
|
|
3045
|
+
}
|
|
3046
|
+
logger_default.debug("Environment", `API Key: ${apiKeyParsed}`);
|
|
3047
|
+
logger_default.debug("Environment", `Base URL: ${baseURLParsed}`);
|
|
2663
3048
|
return { baseURL: baseURLParsed, apiKey: apiKeyParsed };
|
|
2664
3049
|
}
|
|
2665
3050
|
|
|
@@ -2893,13 +3278,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2893
3278
|
};
|
|
2894
3279
|
|
|
2895
3280
|
// package.json
|
|
2896
|
-
var version = "0.1.12-alpha.
|
|
2897
|
-
|
|
2898
|
-
// src/utils/uuid.ts
|
|
2899
|
-
import { v4 as uuidv4 } from "uuid";
|
|
2900
|
-
function getRandomUUID() {
|
|
2901
|
-
return uuidv4();
|
|
2902
|
-
}
|
|
3281
|
+
var version = "0.1.12-alpha.11";
|
|
2903
3282
|
|
|
2904
3283
|
// src/composio.ts
|
|
2905
3284
|
var Composio = class {
|
|
@@ -2939,18 +3318,18 @@ var Composio = class {
|
|
|
2939
3318
|
config?.apiKey
|
|
2940
3319
|
);
|
|
2941
3320
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
2942
|
-
logger_default.
|
|
3321
|
+
logger_default.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
2943
3322
|
}
|
|
2944
|
-
this.client = new
|
|
3323
|
+
this.client = new ComposioClient3({
|
|
2945
3324
|
apiKey: apiKeyParsed,
|
|
2946
3325
|
baseURL: baseURLParsed
|
|
2947
3326
|
});
|
|
2948
3327
|
this.config = {
|
|
2949
3328
|
...config,
|
|
2950
|
-
allowTracking: config
|
|
2951
|
-
allowTracing: config
|
|
3329
|
+
allowTracking: config?.allowTracking ?? true,
|
|
3330
|
+
allowTracing: config?.allowTracing ?? true
|
|
2952
3331
|
};
|
|
2953
|
-
this.provider = config
|
|
3332
|
+
this.provider = config?.provider ?? new OpenAIProvider();
|
|
2954
3333
|
this.tools = new Tools(this.client, this.provider);
|
|
2955
3334
|
this.toolkits = new Toolkits(this.client);
|
|
2956
3335
|
this.triggers = new Triggers(this.client);
|
|
@@ -2961,7 +3340,7 @@ var Composio = class {
|
|
|
2961
3340
|
{
|
|
2962
3341
|
apiKey: apiKeyParsed ?? "",
|
|
2963
3342
|
baseUrl: baseURLParsed ?? "",
|
|
2964
|
-
|
|
3343
|
+
frameworkRuntime: this.provider?.name || "unknown",
|
|
2965
3344
|
isAgentic: this.provider?._isAgentic || false,
|
|
2966
3345
|
source: "javascript",
|
|
2967
3346
|
version,
|
|
@@ -2972,7 +3351,7 @@ var Composio = class {
|
|
|
2972
3351
|
sessionId: this.config.allowTracing ? getRandomUUID() : void 0
|
|
2973
3352
|
// @TODO: get the session id
|
|
2974
3353
|
},
|
|
2975
|
-
config
|
|
3354
|
+
config?.telemetryTransport
|
|
2976
3355
|
);
|
|
2977
3356
|
}
|
|
2978
3357
|
telemetry.instrument(this);
|
|
@@ -3003,12 +3382,12 @@ var ComposioProvider = class extends BaseNonAgenticProvider {
|
|
|
3003
3382
|
};
|
|
3004
3383
|
|
|
3005
3384
|
// src/telemetry/TelemetryTransport.ts
|
|
3006
|
-
import
|
|
3385
|
+
import chalk4 from "chalk";
|
|
3007
3386
|
var BaseTelemetryTransport = class {
|
|
3008
3387
|
};
|
|
3009
3388
|
var ConsoleTelemetryTransport = class {
|
|
3010
3389
|
send(payload) {
|
|
3011
|
-
logger_default.debug(
|
|
3390
|
+
logger_default.debug(chalk4.yellow("telemetry"), JSON.stringify(payload, null, 2));
|
|
3012
3391
|
return Promise.resolve();
|
|
3013
3392
|
}
|
|
3014
3393
|
};
|
|
@@ -3122,15 +3501,38 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3122
3501
|
return z5.object(zodSchema);
|
|
3123
3502
|
}
|
|
3124
3503
|
export {
|
|
3504
|
+
AuthConfigErrorCodes,
|
|
3125
3505
|
AuthConfigTypes,
|
|
3126
3506
|
AuthSchemeTypes,
|
|
3127
3507
|
BaseAgenticProvider,
|
|
3128
3508
|
BaseNonAgenticProvider,
|
|
3129
3509
|
BaseTelemetryTransport,
|
|
3130
3510
|
Composio,
|
|
3511
|
+
ComposioAuthConfigNotFoundError,
|
|
3512
|
+
ComposioConnectedAccountNotFoundError,
|
|
3513
|
+
ComposioCustomToolsNotInitializedError,
|
|
3514
|
+
ComposioError,
|
|
3515
|
+
ComposioGlobalExecuteToolFnNotSetError,
|
|
3516
|
+
ComposioInvalidExecuteFunctionError,
|
|
3517
|
+
ComposioInvalidModifierError,
|
|
3518
|
+
ComposioNoAPIKeyError,
|
|
3131
3519
|
ComposioProvider,
|
|
3520
|
+
ComposioProviderNotDefinedError,
|
|
3521
|
+
ComposioToolExecutionError,
|
|
3522
|
+
ComposioToolNotFoundError,
|
|
3523
|
+
ComposioToolkitFetchError,
|
|
3524
|
+
ComposioToolkitNotFoundError,
|
|
3525
|
+
ConnectedAccountErrorCodes,
|
|
3526
|
+
ConnectionRequestErrorCodes,
|
|
3527
|
+
ConnectionRequestFailedError,
|
|
3528
|
+
ConnectionRequestTimeoutError,
|
|
3132
3529
|
ConsoleTelemetryTransport,
|
|
3133
3530
|
OpenAIProvider,
|
|
3531
|
+
SDKErrorCodes,
|
|
3532
|
+
ToolErrorCodes,
|
|
3134
3533
|
ToolListParamsSchema,
|
|
3534
|
+
ToolkitErrorCodes,
|
|
3535
|
+
ValidationError,
|
|
3536
|
+
ValidationErrorCodes,
|
|
3135
3537
|
jsonSchemaToModel
|
|
3136
3538
|
};
|