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