@composio/core 0.1.12-alpha.9 → 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 +2714 -1241
- package/dist/index.d.cts +1304 -296
- package/dist/index.d.ts +1304 -296
- package/dist/index.js +2686 -1238
- 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,281 +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
|
}
|
|
501
1145
|
const issues = zodErrorInstance.issues.map(
|
|
502
1146
|
(issue) => `[${issue.code}] ${issue.path.join(".")} - ${issue.message}`
|
|
503
1147
|
);
|
|
504
1148
|
super(message, {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
1149
|
+
...restOptions,
|
|
1150
|
+
code: options.code || ValidationErrorCodes.VALIDATION_ERROR,
|
|
1151
|
+
possibleFixes: issues,
|
|
1152
|
+
cause: zodErrorInstance
|
|
508
1153
|
});
|
|
509
|
-
this.zodError = zodErrorInstance;
|
|
510
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);
|
|
511
1476
|
}
|
|
512
1477
|
};
|
|
513
1478
|
|
|
@@ -530,6 +1495,7 @@ var Tools = class {
|
|
|
530
1495
|
this.provider._setExecuteToolFn(this.execute);
|
|
531
1496
|
this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
|
|
532
1497
|
this.getRawComposioTools = this.getRawComposioTools.bind(this);
|
|
1498
|
+
telemetry.instrument(this);
|
|
533
1499
|
}
|
|
534
1500
|
/**
|
|
535
1501
|
* Transforms tool data from snake_case API format to camelCase for internal SDK use.
|
|
@@ -673,32 +1639,45 @@ var Tools = class {
|
|
|
673
1639
|
* );
|
|
674
1640
|
* ```
|
|
675
1641
|
*/
|
|
676
|
-
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
|
+
}
|
|
677
1648
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
678
1649
|
if (queryParams.error) {
|
|
679
|
-
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
|
+
);
|
|
680
1658
|
}
|
|
681
1659
|
const tools = await this.client.tools.list({
|
|
682
|
-
tool_slugs: queryParams.data.tools,
|
|
683
|
-
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
684
|
-
cursor: queryParams.data.cursor,
|
|
685
|
-
important: queryParams.data.important,
|
|
686
|
-
limit: queryParams.data.limit,
|
|
687
|
-
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
|
|
688
1666
|
});
|
|
689
1667
|
if (!tools) {
|
|
690
1668
|
return [];
|
|
691
1669
|
}
|
|
692
1670
|
const caseTransformedTools = tools.items.map((tool) => this.transformToolCases(tool));
|
|
693
1671
|
const customTools = await this.customTools.getCustomTools({
|
|
694
|
-
toolSlugs: queryParams.data.tools
|
|
1672
|
+
toolSlugs: "tools" in queryParams.data ? queryParams.data.tools : void 0
|
|
695
1673
|
});
|
|
696
1674
|
let modifiedTools = [...caseTransformedTools, ...customTools];
|
|
697
1675
|
if (modifier) {
|
|
698
1676
|
if (typeof modifier === "function") {
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
1677
|
+
const modifiedPromises = modifiedTools.map(
|
|
1678
|
+
(tool) => modifier(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
|
|
1679
|
+
);
|
|
1680
|
+
modifiedTools = await Promise.all(modifiedPromises);
|
|
702
1681
|
} else {
|
|
703
1682
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
704
1683
|
}
|
|
@@ -719,23 +1698,28 @@ var Tools = class {
|
|
|
719
1698
|
async getRawComposioToolBySlug(userId, slug, modifier) {
|
|
720
1699
|
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
721
1700
|
if (customTool) {
|
|
1701
|
+
logger_default.debug(`Found ${slug} to be a custom tool`, JSON.stringify(customTool, null, 2));
|
|
722
1702
|
return customTool;
|
|
1703
|
+
} else {
|
|
1704
|
+
logger_default.debug(`Tool ${slug} is not a custom tool. Fetching from Composio API`);
|
|
723
1705
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
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
|
+
});
|
|
729
1713
|
}
|
|
730
|
-
let
|
|
1714
|
+
let modifiedTool = this.transformToolCases(tool);
|
|
731
1715
|
if (modifier) {
|
|
732
1716
|
if (typeof modifier === "function") {
|
|
733
|
-
|
|
1717
|
+
modifiedTool = await modifier(slug, modifiedTool.toolkit?.slug ?? "unknown", modifiedTool);
|
|
734
1718
|
} else {
|
|
735
1719
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
736
1720
|
}
|
|
737
1721
|
}
|
|
738
|
-
return
|
|
1722
|
+
return modifiedTool;
|
|
739
1723
|
}
|
|
740
1724
|
/**
|
|
741
1725
|
* Get a tool or list of tools based on the provided arguments.
|
|
@@ -749,17 +1733,19 @@ var Tools = class {
|
|
|
749
1733
|
async get(userId, arg2, options) {
|
|
750
1734
|
const executeToolFn = this.createExecuteToolFn(userId, options);
|
|
751
1735
|
if (typeof arg2 === "string") {
|
|
752
|
-
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.
|
|
1736
|
+
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifySchema);
|
|
753
1737
|
return this.provider.wrapTools([tool], executeToolFn);
|
|
754
1738
|
} else {
|
|
755
|
-
const tools = await this.getRawComposioTools(userId, arg2, options?.
|
|
1739
|
+
const tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
|
|
756
1740
|
return this.provider.wrapTools(tools, executeToolFn);
|
|
757
1741
|
}
|
|
758
1742
|
}
|
|
759
1743
|
/**
|
|
760
1744
|
* @internal
|
|
1745
|
+
* @description
|
|
761
1746
|
* Creates a function that executes a tool.
|
|
762
|
-
* This function is used by agentic
|
|
1747
|
+
* This function is used by agentic toolsets to execute the tool
|
|
1748
|
+
*
|
|
763
1749
|
* @param {string} userId - The user id
|
|
764
1750
|
* @param {ExecuteToolModifiers} modifiers - The modifiers to be applied to the tool
|
|
765
1751
|
* @returns {ExecuteToolFn} The execute tool function
|
|
@@ -786,26 +1772,19 @@ var Tools = class {
|
|
|
786
1772
|
* @returns The response from the tool execution
|
|
787
1773
|
*/
|
|
788
1774
|
async handleCustomToolExecution(tool, body, modifiers) {
|
|
789
|
-
if (modifiers?.
|
|
790
|
-
if (typeof modifiers.
|
|
791
|
-
body = modifiers.
|
|
1775
|
+
if (modifiers?.beforeExecute) {
|
|
1776
|
+
if (typeof modifiers.beforeExecute === "function") {
|
|
1777
|
+
body = await modifiers.beforeExecute(tool.slug, "unknown", body);
|
|
792
1778
|
} else {
|
|
793
|
-
throw new ComposioInvalidModifierError(
|
|
794
|
-
"Invalid beforeToolExecute modifier. Not a function."
|
|
795
|
-
);
|
|
1779
|
+
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
796
1780
|
}
|
|
797
1781
|
}
|
|
798
|
-
let result = await this.customTools.executeCustomTool(tool.slug, body
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
if (modifiers?.afterToolExecute) {
|
|
803
|
-
if (typeof modifiers.afterToolExecute === "function") {
|
|
804
|
-
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);
|
|
805
1786
|
} else {
|
|
806
|
-
throw new ComposioInvalidModifierError(
|
|
807
|
-
"Invalid afterToolExecute modifier. Not a function."
|
|
808
|
-
);
|
|
1787
|
+
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
809
1788
|
}
|
|
810
1789
|
}
|
|
811
1790
|
return result;
|
|
@@ -819,13 +1798,11 @@ var Tools = class {
|
|
|
819
1798
|
* @returns The response from the tool execution
|
|
820
1799
|
*/
|
|
821
1800
|
async handleComposioToolExecution(tool, body, modifiers) {
|
|
822
|
-
if (modifiers?.
|
|
823
|
-
if (typeof modifiers.
|
|
824
|
-
body = modifiers.
|
|
1801
|
+
if (modifiers?.beforeExecute) {
|
|
1802
|
+
if (typeof modifiers.beforeExecute === "function") {
|
|
1803
|
+
body = await modifiers.beforeExecute(tool.slug, tool.toolkit?.slug ?? "unknown", body);
|
|
825
1804
|
} else {
|
|
826
|
-
throw new ComposioInvalidModifierError(
|
|
827
|
-
"Invalid beforeToolExecute modifier. Not a function."
|
|
828
|
-
);
|
|
1805
|
+
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
829
1806
|
}
|
|
830
1807
|
}
|
|
831
1808
|
let connectedAccountId = body.connectedAccountId;
|
|
@@ -842,13 +1819,11 @@ var Tools = class {
|
|
|
842
1819
|
text: body.text
|
|
843
1820
|
});
|
|
844
1821
|
result = this.transformToolExecuteResponse(result);
|
|
845
|
-
if (modifiers?.
|
|
846
|
-
if (typeof modifiers.
|
|
847
|
-
result = modifiers.
|
|
1822
|
+
if (modifiers?.afterExecute) {
|
|
1823
|
+
if (typeof modifiers.afterExecute === "function") {
|
|
1824
|
+
result = await modifiers.afterExecute(tool.slug, tool.toolkit?.slug ?? "unknown", result);
|
|
848
1825
|
} else {
|
|
849
|
-
throw new ComposioInvalidModifierError(
|
|
850
|
-
"Invalid afterToolExecute modifier. Not a function."
|
|
851
|
-
);
|
|
1826
|
+
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
852
1827
|
}
|
|
853
1828
|
}
|
|
854
1829
|
return result;
|
|
@@ -881,11 +1856,11 @@ var Tools = class {
|
|
|
881
1856
|
* userId: 'default',
|
|
882
1857
|
* arguments: { owner: 'composio', repo: 'sdk' }
|
|
883
1858
|
* }, {
|
|
884
|
-
*
|
|
1859
|
+
* beforeExecute: (toolSlug, toolkitSlug, params) => {
|
|
885
1860
|
* // Modify params before execution
|
|
886
1861
|
* return params;
|
|
887
1862
|
* },
|
|
888
|
-
*
|
|
1863
|
+
* afterExecute: (toolSlug, toolkitSlug, result) => {
|
|
889
1864
|
* // Transform result after execution
|
|
890
1865
|
* return result;
|
|
891
1866
|
* }
|
|
@@ -910,18 +1885,28 @@ var Tools = class {
|
|
|
910
1885
|
return this.handleComposioToolExecution(composioTool, body, modifiers);
|
|
911
1886
|
}
|
|
912
1887
|
} catch (error) {
|
|
913
|
-
throw new ComposioToolExecutionError(
|
|
914
|
-
|
|
915
|
-
|
|
1888
|
+
throw new ComposioToolExecutionError(`Error executing tool ${slug}`, {
|
|
1889
|
+
originalError: error,
|
|
1890
|
+
meta: {
|
|
1891
|
+
toolSlug: slug,
|
|
1892
|
+
body
|
|
1893
|
+
}
|
|
916
1894
|
});
|
|
917
1895
|
}
|
|
918
1896
|
}
|
|
919
1897
|
/**
|
|
920
1898
|
* Fetches the list of all available tools in the Composio SDK.
|
|
921
1899
|
*
|
|
922
|
-
* This method is mostly used by the CLI
|
|
1900
|
+
* This method is mostly used by the CLI to get the list of tools.
|
|
923
1901
|
* No filtering is done on the tools, the list is cached in the backend, no further optimization is required.
|
|
924
|
-
* @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
|
+
* ```
|
|
925
1910
|
*/
|
|
926
1911
|
async getToolsEnum() {
|
|
927
1912
|
return this.client.tools.retrieveEnum();
|
|
@@ -933,18 +1918,69 @@ var Tools = class {
|
|
|
933
1918
|
*
|
|
934
1919
|
* @param {string} slug - The ID of the tool to find input for
|
|
935
1920
|
* @param {ToolGetInputParams} body - The parameters to be passed to the tool
|
|
936
|
-
* @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
|
+
* ```
|
|
937
1931
|
*/
|
|
938
1932
|
async getInput(slug, body) {
|
|
939
1933
|
return this.client.tools.getInput(slug, body);
|
|
940
1934
|
}
|
|
941
1935
|
/**
|
|
942
|
-
* Proxies a custom request to a toolkit/integration
|
|
943
|
-
*
|
|
944
|
-
*
|
|
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
|
+
* ```
|
|
945
1957
|
*/
|
|
946
1958
|
async proxyExecute(body) {
|
|
947
|
-
|
|
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
|
+
});
|
|
948
1984
|
}
|
|
949
1985
|
/**
|
|
950
1986
|
* Creates a custom tool that can be used within the Composio SDK.
|
|
@@ -957,120 +1993,130 @@ var Tools = class {
|
|
|
957
1993
|
*
|
|
958
1994
|
* @example
|
|
959
1995
|
* ```typescript
|
|
960
|
-
*
|
|
1996
|
+
* // creating a custom tool with a toolkit
|
|
1997
|
+
* await composio.tools.createCustomTool({
|
|
961
1998
|
* name: 'My Custom Tool',
|
|
962
1999
|
* description: 'A custom tool that does something specific',
|
|
963
2000
|
* slug: 'MY_CUSTOM_TOOL',
|
|
964
|
-
*
|
|
965
|
-
*
|
|
966
|
-
*
|
|
967
|
-
*
|
|
968
|
-
*
|
|
969
|
-
*
|
|
970
|
-
*
|
|
971
|
-
* outputParameters: {
|
|
972
|
-
* result: {
|
|
973
|
-
* type: 'string',
|
|
974
|
-
* description: 'The result of the operation'
|
|
975
|
-
* }
|
|
976
|
-
* },
|
|
977
|
-
* 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) => {
|
|
978
2008
|
* // Custom logic here
|
|
979
2009
|
* return { data: { result: 'Success!' } };
|
|
980
2010
|
* }
|
|
981
2011
|
* });
|
|
982
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
|
+
* });
|
|
983
2029
|
*/
|
|
984
2030
|
async createCustomTool(body) {
|
|
985
2031
|
return this.customTools.createTool(body);
|
|
986
2032
|
}
|
|
987
2033
|
};
|
|
988
2034
|
|
|
2035
|
+
// src/models/Toolkits.ts
|
|
2036
|
+
var import_client4 = __toESM(require("@composio/client"), 1);
|
|
2037
|
+
|
|
989
2038
|
// src/types/toolkit.types.ts
|
|
990
|
-
var
|
|
991
|
-
var ToolkitMangedByEnumSchema =
|
|
992
|
-
var ToolkitSortByEnumSchema =
|
|
993
|
-
var ToolkitsListParamsSchema =
|
|
994
|
-
category:
|
|
995
|
-
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(),
|
|
996
2045
|
managedBy: ToolkitMangedByEnumSchema.optional(),
|
|
997
2046
|
sortBy: ToolkitSortByEnumSchema.optional()
|
|
998
2047
|
});
|
|
999
|
-
var ToolKitMetaSchema =
|
|
1000
|
-
categories:
|
|
1001
|
-
|
|
1002
|
-
slug:
|
|
1003
|
-
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()
|
|
1004
2053
|
})
|
|
1005
2054
|
).optional(),
|
|
1006
|
-
appUrl:
|
|
1007
|
-
createdAt:
|
|
1008
|
-
description:
|
|
1009
|
-
logo:
|
|
1010
|
-
toolsCount:
|
|
1011
|
-
triggersCount:
|
|
1012
|
-
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()
|
|
1013
2062
|
});
|
|
1014
|
-
var ToolKitItemSchema =
|
|
1015
|
-
name:
|
|
1016
|
-
slug:
|
|
2063
|
+
var ToolKitItemSchema = import_zod5.z.object({
|
|
2064
|
+
name: import_zod5.z.string(),
|
|
2065
|
+
slug: import_zod5.z.string(),
|
|
1017
2066
|
meta: ToolKitMetaSchema,
|
|
1018
|
-
isLocalToolkit:
|
|
1019
|
-
authSchemes:
|
|
1020
|
-
composioManagedAuthSchemes:
|
|
1021
|
-
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()
|
|
1022
2071
|
});
|
|
1023
|
-
var ToolKitListResponseSchema =
|
|
1024
|
-
items:
|
|
1025
|
-
nextCursor:
|
|
1026
|
-
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()
|
|
1027
2076
|
});
|
|
1028
|
-
var ToolkitAuthFieldSchema =
|
|
1029
|
-
name:
|
|
1030
|
-
displayName:
|
|
1031
|
-
type:
|
|
1032
|
-
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()
|
|
1033
2082
|
});
|
|
1034
|
-
var ToolkitAuthConfigDetailsSchema =
|
|
1035
|
-
name:
|
|
1036
|
-
mode:
|
|
1037
|
-
fields:
|
|
1038
|
-
authConfigCreation:
|
|
1039
|
-
optional:
|
|
1040
|
-
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)
|
|
1041
2090
|
}),
|
|
1042
|
-
connectedAccountInitiation:
|
|
1043
|
-
optional:
|
|
1044
|
-
required:
|
|
2091
|
+
connectedAccountInitiation: import_zod5.z.object({
|
|
2092
|
+
optional: import_zod5.z.array(ToolkitAuthFieldSchema),
|
|
2093
|
+
required: import_zod5.z.array(ToolkitAuthFieldSchema)
|
|
1045
2094
|
})
|
|
1046
2095
|
}),
|
|
1047
|
-
proxy:
|
|
1048
|
-
baseUrl:
|
|
2096
|
+
proxy: import_zod5.z.object({
|
|
2097
|
+
baseUrl: import_zod5.z.string().optional()
|
|
1049
2098
|
}).optional()
|
|
1050
2099
|
});
|
|
1051
|
-
var ToolkitRetrieveResponseSchema =
|
|
1052
|
-
name:
|
|
1053
|
-
slug:
|
|
2100
|
+
var ToolkitRetrieveResponseSchema = import_zod5.z.object({
|
|
2101
|
+
name: import_zod5.z.string(),
|
|
2102
|
+
slug: import_zod5.z.string(),
|
|
1054
2103
|
meta: ToolKitMetaSchema,
|
|
1055
|
-
isLocalToolkit:
|
|
1056
|
-
composioManagedAuthSchemes:
|
|
1057
|
-
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()
|
|
1058
2107
|
});
|
|
1059
|
-
var ToolkitCategorySchema =
|
|
1060
|
-
id:
|
|
1061
|
-
name:
|
|
2108
|
+
var ToolkitCategorySchema = import_zod5.z.object({
|
|
2109
|
+
id: import_zod5.z.string(),
|
|
2110
|
+
name: import_zod5.z.string()
|
|
1062
2111
|
});
|
|
1063
|
-
var ToolkitRetrieveCategoriesResponseSchema =
|
|
1064
|
-
items:
|
|
1065
|
-
nextCursor:
|
|
1066
|
-
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()
|
|
1067
2116
|
});
|
|
1068
2117
|
|
|
1069
|
-
// src/models/Toolkits.ts
|
|
1070
|
-
var import_zod7 = require("zod");
|
|
1071
|
-
|
|
1072
2118
|
// src/types/authConfigs.types.ts
|
|
1073
|
-
var
|
|
2119
|
+
var import_zod6 = require("zod");
|
|
1074
2120
|
var AuthConfigTypes = {
|
|
1075
2121
|
CUSTOM: "use_custom_auth",
|
|
1076
2122
|
COMPOSIO_MANAGED: "use_composio_managed_auth"
|
|
@@ -1090,7 +2136,7 @@ var AuthSchemeTypes = {
|
|
|
1090
2136
|
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1091
2137
|
SNOWFLAKE: "SNOWFLAKE"
|
|
1092
2138
|
};
|
|
1093
|
-
var AuthSchemeEnum =
|
|
2139
|
+
var AuthSchemeEnum = import_zod6.z.enum([
|
|
1094
2140
|
"OAUTH2",
|
|
1095
2141
|
"OAUTH1",
|
|
1096
2142
|
"OAUTH1A",
|
|
@@ -1105,67 +2151,67 @@ var AuthSchemeEnum = import_zod4.z.enum([
|
|
|
1105
2151
|
"CALCOM_AUTH",
|
|
1106
2152
|
"SNOWFLAKE"
|
|
1107
2153
|
]);
|
|
1108
|
-
var CreateCustomAuthConfigParamsSchema =
|
|
1109
|
-
type:
|
|
1110
|
-
name:
|
|
1111
|
-
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()])),
|
|
1112
2158
|
authScheme: AuthSchemeEnum
|
|
1113
2159
|
});
|
|
1114
|
-
var CreateComposioManagedAuthConfigParamsSchema =
|
|
1115
|
-
type:
|
|
1116
|
-
name:
|
|
1117
|
-
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()
|
|
1118
2164
|
});
|
|
1119
|
-
var CreateAuthConfigParamsSchema =
|
|
2165
|
+
var CreateAuthConfigParamsSchema = import_zod6.z.discriminatedUnion("type", [
|
|
1120
2166
|
CreateCustomAuthConfigParamsSchema,
|
|
1121
2167
|
CreateComposioManagedAuthConfigParamsSchema
|
|
1122
2168
|
]);
|
|
1123
|
-
var CreateAuthConfigResponseSchema =
|
|
1124
|
-
id:
|
|
1125
|
-
authScheme:
|
|
1126
|
-
isComposioManaged:
|
|
1127
|
-
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()
|
|
1128
2174
|
});
|
|
1129
|
-
var AuthConfigRetrieveResponseSchema =
|
|
1130
|
-
id:
|
|
1131
|
-
name:
|
|
1132
|
-
toolkit:
|
|
1133
|
-
logo:
|
|
1134
|
-
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()
|
|
1135
2181
|
}),
|
|
1136
|
-
noOfConnections:
|
|
1137
|
-
status:
|
|
1138
|
-
uuid:
|
|
2182
|
+
noOfConnections: import_zod6.z.number(),
|
|
2183
|
+
status: import_zod6.z.enum(["ENABLED", "DISABLED"]),
|
|
2184
|
+
uuid: import_zod6.z.string(),
|
|
1139
2185
|
authScheme: AuthSchemeEnum.optional(),
|
|
1140
|
-
credentials:
|
|
1141
|
-
expectedInputFields:
|
|
1142
|
-
isComposioManaged:
|
|
1143
|
-
createdBy:
|
|
1144
|
-
createdAt:
|
|
1145
|
-
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()
|
|
1146
2192
|
});
|
|
1147
|
-
var AuthConfigListParamsSchema =
|
|
1148
|
-
cursor:
|
|
1149
|
-
isComposioManaged:
|
|
1150
|
-
limit:
|
|
1151
|
-
|
|
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()
|
|
1152
2198
|
});
|
|
1153
|
-
var AuthConfigListResponseSchema =
|
|
1154
|
-
items:
|
|
1155
|
-
nextCursor:
|
|
1156
|
-
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()
|
|
1157
2203
|
});
|
|
1158
|
-
var AuthCustomConfigUpdateParamsSchema =
|
|
1159
|
-
credentials:
|
|
1160
|
-
type:
|
|
1161
|
-
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()
|
|
1162
2208
|
});
|
|
1163
|
-
var AuthDefaultConfigUpdateParamsSchema =
|
|
1164
|
-
scopes:
|
|
1165
|
-
type:
|
|
1166
|
-
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()
|
|
1167
2213
|
});
|
|
1168
|
-
var AuthConfigUpdateParamsSchema =
|
|
2214
|
+
var AuthConfigUpdateParamsSchema = import_zod6.z.discriminatedUnion("type", [
|
|
1169
2215
|
AuthCustomConfigUpdateParamsSchema,
|
|
1170
2216
|
AuthDefaultConfigUpdateParamsSchema
|
|
1171
2217
|
]);
|
|
@@ -1175,6 +2221,7 @@ var AuthConfigs = class {
|
|
|
1175
2221
|
client;
|
|
1176
2222
|
constructor(client) {
|
|
1177
2223
|
this.client = client;
|
|
2224
|
+
telemetry.instrument(this);
|
|
1178
2225
|
}
|
|
1179
2226
|
/**
|
|
1180
2227
|
* Protected getter for the client instance.
|
|
@@ -1216,7 +2263,9 @@ var AuthConfigs = class {
|
|
|
1216
2263
|
lastUpdatedAt: authConfig.last_updated_at
|
|
1217
2264
|
});
|
|
1218
2265
|
if (result.error) {
|
|
1219
|
-
throw new ValidationError(
|
|
2266
|
+
throw new ValidationError("Failed to parse auth config response", {
|
|
2267
|
+
cause: result.error
|
|
2268
|
+
});
|
|
1220
2269
|
}
|
|
1221
2270
|
return result.data;
|
|
1222
2271
|
}
|
|
@@ -1237,7 +2286,7 @@ var AuthConfigs = class {
|
|
|
1237
2286
|
*
|
|
1238
2287
|
* // List auth configs for a specific toolkit
|
|
1239
2288
|
* const githubConfigs = await composio.authConfigs.list({
|
|
1240
|
-
*
|
|
2289
|
+
* toolkit: 'github'
|
|
1241
2290
|
* });
|
|
1242
2291
|
*
|
|
1243
2292
|
* // List Composio-managed auth configs
|
|
@@ -1251,8 +2300,8 @@ var AuthConfigs = class {
|
|
|
1251
2300
|
const result = await this.client.authConfigs.list({
|
|
1252
2301
|
cursor: parsedQuery?.cursor,
|
|
1253
2302
|
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1254
|
-
limit: parsedQuery?.limit
|
|
1255
|
-
toolkit_slug: parsedQuery?.
|
|
2303
|
+
limit: parsedQuery?.limit,
|
|
2304
|
+
toolkit_slug: parsedQuery?.toolkit
|
|
1256
2305
|
});
|
|
1257
2306
|
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
1258
2307
|
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
@@ -1260,7 +2309,9 @@ var AuthConfigs = class {
|
|
|
1260
2309
|
totalPages: result.total_pages
|
|
1261
2310
|
});
|
|
1262
2311
|
if (parsedResult.error) {
|
|
1263
|
-
throw new ValidationError(
|
|
2312
|
+
throw new ValidationError("Failed to parse auth config list response", {
|
|
2313
|
+
cause: parsedResult.error
|
|
2314
|
+
});
|
|
1264
2315
|
}
|
|
1265
2316
|
return parsedResult.data;
|
|
1266
2317
|
}
|
|
@@ -1285,7 +2336,9 @@ var AuthConfigs = class {
|
|
|
1285
2336
|
async create(toolkit, options = { type: "use_composio_managed_auth" }) {
|
|
1286
2337
|
const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
|
|
1287
2338
|
if (parsedOptions.error) {
|
|
1288
|
-
throw new ValidationError(
|
|
2339
|
+
throw new ValidationError("Failed to parse auth config create options", {
|
|
2340
|
+
cause: parsedOptions.error
|
|
2341
|
+
});
|
|
1289
2342
|
}
|
|
1290
2343
|
const result = await this.client.authConfigs.create({
|
|
1291
2344
|
toolkit: {
|
|
@@ -1300,7 +2353,9 @@ var AuthConfigs = class {
|
|
|
1300
2353
|
toolkit: result.toolkit.slug
|
|
1301
2354
|
});
|
|
1302
2355
|
if (parsedResult.error) {
|
|
1303
|
-
throw new ValidationError(
|
|
2356
|
+
throw new ValidationError("Failed to parse auth config create response", {
|
|
2357
|
+
cause: parsedResult.error
|
|
2358
|
+
});
|
|
1304
2359
|
}
|
|
1305
2360
|
return parsedResult.data;
|
|
1306
2361
|
}
|
|
@@ -1360,7 +2415,9 @@ var AuthConfigs = class {
|
|
|
1360
2415
|
async update(nanoid, data) {
|
|
1361
2416
|
const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
|
|
1362
2417
|
if (parsedData.error) {
|
|
1363
|
-
throw new ValidationError(
|
|
2418
|
+
throw new ValidationError("Failed to parse auth config update data", {
|
|
2419
|
+
cause: parsedData.error
|
|
2420
|
+
});
|
|
1364
2421
|
}
|
|
1365
2422
|
return this.client.authConfigs.update(
|
|
1366
2423
|
nanoid,
|
|
@@ -1372,258 +2429,98 @@ var AuthConfigs = class {
|
|
|
1372
2429
|
type: "default",
|
|
1373
2430
|
scopes: parsedData.data.scopes,
|
|
1374
2431
|
restrict_to_following_tools: parsedData.data.restrictToFollowingTools
|
|
1375
|
-
}
|
|
1376
|
-
);
|
|
1377
|
-
}
|
|
1378
|
-
/**
|
|
1379
|
-
* Deletes an authentication configuration.
|
|
1380
|
-
*
|
|
1381
|
-
* This method permanently removes an auth config from the Composio platform.
|
|
1382
|
-
* This action cannot be undone and will prevent any connected accounts that use
|
|
1383
|
-
* this auth config from functioning.
|
|
1384
|
-
*
|
|
1385
|
-
* @param {string} nanoid - The unique identifier of the auth config to delete
|
|
1386
|
-
* @returns {Promise<AuthConfigDeleteResponse>} The deletion response
|
|
1387
|
-
* @throws {Error} If the auth config doesn't exist or cannot be deleted
|
|
1388
|
-
*
|
|
1389
|
-
* @example
|
|
1390
|
-
* ```typescript
|
|
1391
|
-
* // Delete an auth config
|
|
1392
|
-
* await composio.authConfigs.delete('auth_abc123');
|
|
1393
|
-
* ```
|
|
1394
|
-
*/
|
|
1395
|
-
async delete(nanoid) {
|
|
1396
|
-
return this.client.authConfigs.delete(nanoid);
|
|
1397
|
-
}
|
|
1398
|
-
/**
|
|
1399
|
-
* Updates the status of an authentication configuration.
|
|
1400
|
-
*
|
|
1401
|
-
* This method allows you to enable or disable an auth config. When disabled,
|
|
1402
|
-
* the auth config cannot be used to create new connected accounts or authenticate
|
|
1403
|
-
* with third-party services.
|
|
1404
|
-
*
|
|
1405
|
-
* @param {string} status - The status to set ('ENABLED' or 'DISABLED')
|
|
1406
|
-
* @param {string} nanoid - The unique identifier of the auth config
|
|
1407
|
-
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1408
|
-
* @throws {Error} If the auth config cannot be found or the status cannot be updated
|
|
1409
|
-
*
|
|
1410
|
-
* @example
|
|
1411
|
-
* ```typescript
|
|
1412
|
-
* // Disable an auth config
|
|
1413
|
-
* await composio.authConfigs.updateStatus('DISABLED', 'auth_abc123');
|
|
1414
|
-
*
|
|
1415
|
-
* // Enable an auth config
|
|
1416
|
-
* await composio.authConfigs.updateStatus('ENABLED', 'auth_abc123');
|
|
1417
|
-
* ```
|
|
1418
|
-
*/
|
|
1419
|
-
async updateStatus(status, nanoid) {
|
|
1420
|
-
return this.client.authConfigs.updateStatus(status, { nanoid });
|
|
1421
|
-
}
|
|
1422
|
-
/**
|
|
1423
|
-
* Enables an authentication configuration.
|
|
1424
|
-
*
|
|
1425
|
-
* This is a convenience method that calls updateStatus with 'ENABLED'.
|
|
1426
|
-
* When enabled, the auth config can be used to create new connected accounts
|
|
1427
|
-
* and authenticate with third-party services.
|
|
1428
|
-
*
|
|
1429
|
-
* @param {string} nanoid - The unique identifier of the auth config to enable
|
|
1430
|
-
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1431
|
-
* @throws {Error} If the auth config cannot be found or enabled
|
|
1432
|
-
*
|
|
1433
|
-
* @example
|
|
1434
|
-
* ```typescript
|
|
1435
|
-
* // Enable an auth config
|
|
1436
|
-
* await composio.authConfigs.enable('auth_abc123');
|
|
1437
|
-
* ```
|
|
1438
|
-
*/
|
|
1439
|
-
async enable(nanoid) {
|
|
1440
|
-
return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
|
|
1441
|
-
}
|
|
1442
|
-
/**
|
|
1443
|
-
* Disables an authentication configuration.
|
|
1444
|
-
*
|
|
1445
|
-
* This is a convenience method that calls updateStatus with 'DISABLED'.
|
|
1446
|
-
* When disabled, the auth config cannot be used to create new connected accounts
|
|
1447
|
-
* or authenticate with third-party services, but existing connections may continue to work.
|
|
1448
|
-
*
|
|
1449
|
-
* @param {string} nanoid - The unique identifier of the auth config to disable
|
|
1450
|
-
* @returns {Promise<AuthConfigUpdateStatusResponse>} The updated auth config details
|
|
1451
|
-
* @throws {Error} If the auth config cannot be found or disabled
|
|
1452
|
-
*
|
|
1453
|
-
* @example
|
|
1454
|
-
* ```typescript
|
|
1455
|
-
* // Disable an auth config
|
|
1456
|
-
* await composio.authConfigs.disable('auth_abc123');
|
|
1457
|
-
* ```
|
|
1458
|
-
*/
|
|
1459
|
-
async disable(nanoid) {
|
|
1460
|
-
return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
|
|
1461
|
-
}
|
|
1462
|
-
};
|
|
1463
|
-
|
|
1464
|
-
// src/errors/AuthConfigErrors.ts
|
|
1465
|
-
var AuthConfigErrorCodes = {
|
|
1466
|
-
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1467
|
-
};
|
|
1468
|
-
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1469
|
-
constructor(message, meta) {
|
|
1470
|
-
super(message, {
|
|
1471
|
-
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1472
|
-
cause: meta,
|
|
1473
|
-
possibleFixes: [
|
|
1474
|
-
"Check if the auth config exists",
|
|
1475
|
-
"Check if the auth config id is correct",
|
|
1476
|
-
"Check if the auth config is enabled"
|
|
1477
|
-
]
|
|
1478
|
-
});
|
|
1479
|
-
this.name = "ComposioAuthConfigNotFoundError";
|
|
1480
|
-
}
|
|
1481
|
-
};
|
|
1482
|
-
|
|
1483
|
-
// src/types/connectedAccounts.types.ts
|
|
1484
|
-
var import_zod5 = require("zod");
|
|
1485
|
-
var ConnectedAccountStatuses = {
|
|
1486
|
-
ACTIVE: "ACTIVE",
|
|
1487
|
-
INACTIVE: "INACTIVE",
|
|
1488
|
-
DELETED: "DELETED",
|
|
1489
|
-
INITIATED: "INITIATED",
|
|
1490
|
-
EXPIRED: "EXPIRED",
|
|
1491
|
-
FAILED: "FAILED"
|
|
1492
|
-
};
|
|
1493
|
-
var ConnectedAccountStatusSchema = import_zod5.z.enum([
|
|
1494
|
-
ConnectedAccountStatuses.ACTIVE,
|
|
1495
|
-
ConnectedAccountStatuses.INACTIVE,
|
|
1496
|
-
ConnectedAccountStatuses.DELETED,
|
|
1497
|
-
ConnectedAccountStatuses.INITIATED,
|
|
1498
|
-
ConnectedAccountStatuses.EXPIRED,
|
|
1499
|
-
ConnectedAccountStatuses.FAILED
|
|
1500
|
-
]);
|
|
1501
|
-
var CreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
1502
|
-
authConfig: import_zod5.z.object({
|
|
1503
|
-
id: import_zod5.z.string()
|
|
1504
|
-
}),
|
|
1505
|
-
connection: import_zod5.z.object({
|
|
1506
|
-
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1507
|
-
callbackUrl: import_zod5.z.string().optional(),
|
|
1508
|
-
userId: import_zod5.z.string().optional()
|
|
1509
|
-
})
|
|
1510
|
-
});
|
|
1511
|
-
var DefaultCreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
1512
|
-
auth_config: import_zod5.z.object({
|
|
1513
|
-
id: import_zod5.z.string()
|
|
1514
|
-
}),
|
|
1515
|
-
connection: import_zod5.z.object({
|
|
1516
|
-
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1517
|
-
callback_url: import_zod5.z.string().optional(),
|
|
1518
|
-
user_id: import_zod5.z.string().optional()
|
|
1519
|
-
})
|
|
1520
|
-
});
|
|
1521
|
-
var CreateConnectedAccountOptionsSchema = import_zod5.z.object({
|
|
1522
|
-
callbackUrl: import_zod5.z.string().optional(),
|
|
1523
|
-
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional()
|
|
1524
|
-
});
|
|
1525
|
-
var CreateConnectedAccountResponseSchema = import_zod5.z.object({
|
|
1526
|
-
id: import_zod5.z.string(),
|
|
1527
|
-
status: ConnectedAccountStatusSchema,
|
|
1528
|
-
redirectUrl: import_zod5.z.string().nullable()
|
|
1529
|
-
});
|
|
1530
|
-
var ConnectedAccountAuthSchemes = {
|
|
1531
|
-
OAUTH2: "OAUTH2",
|
|
1532
|
-
OAUTH1: "OAUTH1",
|
|
1533
|
-
OAUTH1A: "OAUTH1A",
|
|
1534
|
-
API_KEY: "API_KEY",
|
|
1535
|
-
BASIC: "BASIC",
|
|
1536
|
-
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
1537
|
-
BEARER_TOKEN: "BEARER_TOKEN",
|
|
1538
|
-
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
1539
|
-
NO_AUTH: "NO_AUTH",
|
|
1540
|
-
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
1541
|
-
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
1542
|
-
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1543
|
-
SNOWFLAKE: "SNOWFLAKE"
|
|
1544
|
-
};
|
|
1545
|
-
var ConnectedAccountAuthSchemesSchema = import_zod5.z.enum([
|
|
1546
|
-
ConnectedAccountAuthSchemes.OAUTH2,
|
|
1547
|
-
ConnectedAccountAuthSchemes.OAUTH1,
|
|
1548
|
-
ConnectedAccountAuthSchemes.OAUTH1A,
|
|
1549
|
-
ConnectedAccountAuthSchemes.API_KEY,
|
|
1550
|
-
ConnectedAccountAuthSchemes.BASIC,
|
|
1551
|
-
ConnectedAccountAuthSchemes.BILLCOM_AUTH,
|
|
1552
|
-
ConnectedAccountAuthSchemes.BEARER_TOKEN,
|
|
1553
|
-
ConnectedAccountAuthSchemes.GOOGLE_SERVICE_ACCOUNT,
|
|
1554
|
-
ConnectedAccountAuthSchemes.NO_AUTH,
|
|
1555
|
-
ConnectedAccountAuthSchemes.BASIC_WITH_JWT,
|
|
1556
|
-
ConnectedAccountAuthSchemes.COMPOSIO_LINK,
|
|
1557
|
-
ConnectedAccountAuthSchemes.CALCOM_AUTH,
|
|
1558
|
-
ConnectedAccountAuthSchemes.SNOWFLAKE
|
|
1559
|
-
]);
|
|
1560
|
-
var ConnectedAccountAuthConfigSchema = import_zod5.z.object({
|
|
1561
|
-
id: import_zod5.z.string(),
|
|
1562
|
-
authScheme: ConnectedAccountAuthSchemesSchema,
|
|
1563
|
-
isComposioManaged: import_zod5.z.boolean(),
|
|
1564
|
-
isDisabled: import_zod5.z.boolean()
|
|
1565
|
-
});
|
|
1566
|
-
var ConnectedAccountRetrieveResponseSchema = import_zod5.z.object({
|
|
1567
|
-
id: import_zod5.z.string(),
|
|
1568
|
-
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1569
|
-
userId: import_zod5.z.string(),
|
|
1570
|
-
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
|
|
1571
|
-
params: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1572
|
-
status: ConnectedAccountStatusSchema,
|
|
1573
|
-
statusReason: import_zod5.z.string().nullable(),
|
|
1574
|
-
toolkit: import_zod5.z.object({
|
|
1575
|
-
slug: import_zod5.z.string()
|
|
1576
|
-
}),
|
|
1577
|
-
testRequestEndpoint: import_zod5.z.string().optional(),
|
|
1578
|
-
isDisabled: import_zod5.z.boolean(),
|
|
1579
|
-
createdAt: import_zod5.z.string(),
|
|
1580
|
-
updatedAt: import_zod5.z.string()
|
|
1581
|
-
});
|
|
1582
|
-
var ConnectedAccountListParamsSchema = import_zod5.z.object({
|
|
1583
|
-
authConfigIds: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The auth config ids of the connected accounts"),
|
|
1584
|
-
cursor: import_zod5.z.number().nullable().optional().describe("The cursor to paginate through the connected accounts"),
|
|
1585
|
-
labels: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The labels of the connected accounts"),
|
|
1586
|
-
limit: import_zod5.z.number().nullable().optional().describe("The limit of the connected accounts to return"),
|
|
1587
|
-
orderBy: import_zod5.z.enum(["created_at", "updated_at"]).optional().describe("The order by of the connected accounts"),
|
|
1588
|
-
statuses: import_zod5.z.array(ConnectedAccountStatusSchema).nullable().optional().describe("The statuses of the connected accounts"),
|
|
1589
|
-
toolkitSlugs: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The toolkit slugs of the connected accounts"),
|
|
1590
|
-
userIds: import_zod5.z.array(import_zod5.z.string()).nullable().optional().describe("The user ids of the connected accounts")
|
|
1591
|
-
});
|
|
1592
|
-
var ConnectedAccountListResponseSchema = import_zod5.z.object({
|
|
1593
|
-
items: import_zod5.z.array(ConnectedAccountRetrieveResponseSchema).describe("The list of connected accounts"),
|
|
1594
|
-
nextCursor: import_zod5.z.string().nullable().describe("The next cursor to paginate through the connected accounts"),
|
|
1595
|
-
totalPages: import_zod5.z.number().describe("The total number of pages of connected accounts")
|
|
1596
|
-
});
|
|
1597
|
-
|
|
1598
|
-
// src/models/ConnectionRequest.ts
|
|
1599
|
-
var import_client = __toESM(require("@composio/client"), 1);
|
|
1600
|
-
var import_zod6 = require("zod");
|
|
1601
|
-
|
|
1602
|
-
// src/errors/ConnectionRequestError.ts
|
|
1603
|
-
var ConnectionRequestErrorCodes = {
|
|
1604
|
-
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1605
|
-
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1606
|
-
};
|
|
1607
|
-
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1608
|
-
constructor(message = "Connection request timed out", meta = {}) {
|
|
1609
|
-
super(message, {
|
|
1610
|
-
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
|
|
1611
|
-
meta
|
|
1612
|
-
});
|
|
1613
|
-
this.name = "ConnectionRequestTimeoutError";
|
|
2432
|
+
}
|
|
2433
|
+
);
|
|
1614
2434
|
}
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
2435
|
+
/**
|
|
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);
|
|
2454
|
+
}
|
|
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 });
|
|
1623
2518
|
}
|
|
1624
2519
|
};
|
|
1625
2520
|
|
|
1626
2521
|
// src/models/ConnectionRequest.ts
|
|
2522
|
+
var import_client3 = __toESM(require("@composio/client"), 1);
|
|
2523
|
+
var import_zod7 = require("zod");
|
|
1627
2524
|
var ConnectionRequest = class {
|
|
1628
2525
|
client;
|
|
1629
2526
|
id;
|
|
@@ -1634,6 +2531,7 @@ var ConnectionRequest = class {
|
|
|
1634
2531
|
this.id = connectedAccountId;
|
|
1635
2532
|
this.status = status || ConnectedAccountStatuses.INITIATED;
|
|
1636
2533
|
this.redirectUrl = redirectUrl;
|
|
2534
|
+
telemetry.instrument(this);
|
|
1637
2535
|
}
|
|
1638
2536
|
/**
|
|
1639
2537
|
* Transforms the raw connected account response from the Composio API to the SDK format.
|
|
@@ -1668,7 +2566,7 @@ var ConnectionRequest = class {
|
|
|
1668
2566
|
return parsedResponse;
|
|
1669
2567
|
} catch (error) {
|
|
1670
2568
|
logger_default.error("Error transforming response", error);
|
|
1671
|
-
if (error instanceof
|
|
2569
|
+
if (error instanceof import_zod7.ZodError) {
|
|
1672
2570
|
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1673
2571
|
}
|
|
1674
2572
|
throw error;
|
|
@@ -1708,11 +2606,13 @@ var ConnectionRequest = class {
|
|
|
1708
2606
|
return this.transformResponse(response);
|
|
1709
2607
|
}
|
|
1710
2608
|
} catch (error) {
|
|
1711
|
-
if (error instanceof
|
|
2609
|
+
if (error instanceof import_client3.default.NotFoundError) {
|
|
1712
2610
|
throw new ComposioConnectedAccountNotFoundError(
|
|
1713
2611
|
`Connected account with id ${this.id} not found`,
|
|
1714
2612
|
{
|
|
1715
|
-
|
|
2613
|
+
meta: {
|
|
2614
|
+
connectedAccountId: this.id
|
|
2615
|
+
}
|
|
1716
2616
|
}
|
|
1717
2617
|
);
|
|
1718
2618
|
} else {
|
|
@@ -1721,8 +2621,7 @@ var ConnectionRequest = class {
|
|
|
1721
2621
|
}
|
|
1722
2622
|
const terminalErrorStates = [
|
|
1723
2623
|
ConnectedAccountStatuses.FAILED,
|
|
1724
|
-
ConnectedAccountStatuses.EXPIRED
|
|
1725
|
-
ConnectedAccountStatuses.DELETED
|
|
2624
|
+
ConnectedAccountStatuses.EXPIRED
|
|
1726
2625
|
];
|
|
1727
2626
|
const start = Date.now();
|
|
1728
2627
|
const pollInterval = 1e3;
|
|
@@ -1737,10 +2636,12 @@ var ConnectionRequest = class {
|
|
|
1737
2636
|
throw new ConnectionRequestFailedError(
|
|
1738
2637
|
`Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ""}`,
|
|
1739
2638
|
{
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
2639
|
+
meta: {
|
|
2640
|
+
userId: response.user_id,
|
|
2641
|
+
connectedAccountId: this.id,
|
|
2642
|
+
status: response.status,
|
|
2643
|
+
statusReason: response.status_reason
|
|
2644
|
+
}
|
|
1744
2645
|
}
|
|
1745
2646
|
);
|
|
1746
2647
|
}
|
|
@@ -1751,6 +2652,23 @@ var ConnectionRequest = class {
|
|
|
1751
2652
|
}
|
|
1752
2653
|
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${this.id}`);
|
|
1753
2654
|
}
|
|
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
|
+
}
|
|
1754
2672
|
};
|
|
1755
2673
|
|
|
1756
2674
|
// src/models/ConnectedAccounts.ts
|
|
@@ -1758,6 +2676,7 @@ var ConnectedAccounts = class {
|
|
|
1758
2676
|
client;
|
|
1759
2677
|
constructor(client) {
|
|
1760
2678
|
this.client = client;
|
|
2679
|
+
telemetry.instrument(this);
|
|
1761
2680
|
}
|
|
1762
2681
|
transformConnectedAccountRetrieveResponse(response) {
|
|
1763
2682
|
const result = ConnectedAccountRetrieveResponseSchema.safeParse({
|
|
@@ -1777,7 +2696,9 @@ var ConnectedAccounts = class {
|
|
|
1777
2696
|
testRequestEndpoint: response.test_request_endpoint
|
|
1778
2697
|
});
|
|
1779
2698
|
if (!result.success) {
|
|
1780
|
-
throw new ValidationError(
|
|
2699
|
+
throw new ValidationError("Failed to parse connected account retrieve response", {
|
|
2700
|
+
cause: result.error
|
|
2701
|
+
});
|
|
1781
2702
|
}
|
|
1782
2703
|
return result.data;
|
|
1783
2704
|
}
|
|
@@ -1810,7 +2731,9 @@ var ConnectedAccounts = class {
|
|
|
1810
2731
|
if (query) {
|
|
1811
2732
|
const parsedQuery = ConnectedAccountListParamsSchema.safeParse(query);
|
|
1812
2733
|
if (!parsedQuery.success) {
|
|
1813
|
-
throw new ValidationError(
|
|
2734
|
+
throw new ValidationError("Failed to parse connected account list query", {
|
|
2735
|
+
cause: parsedQuery.error
|
|
2736
|
+
});
|
|
1814
2737
|
}
|
|
1815
2738
|
rawQuery = {
|
|
1816
2739
|
auth_config_ids: parsedQuery.data.authConfigIds,
|
|
@@ -1830,7 +2753,9 @@ var ConnectedAccounts = class {
|
|
|
1830
2753
|
totalPages: result.total_pages
|
|
1831
2754
|
});
|
|
1832
2755
|
if (!parsedResponse.success) {
|
|
1833
|
-
throw new ValidationError(
|
|
2756
|
+
throw new ValidationError("Failed to parse connected account list response", {
|
|
2757
|
+
cause: parsedResponse.error
|
|
2758
|
+
});
|
|
1834
2759
|
}
|
|
1835
2760
|
return parsedResponse.data;
|
|
1836
2761
|
}
|
|
@@ -1970,8 +2895,21 @@ var ConnectedAccounts = class {
|
|
|
1970
2895
|
* Update the status of a connected account
|
|
1971
2896
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
1972
2897
|
* @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status
|
|
1973
|
-
* @param {RequestOptions} options - Request options
|
|
1974
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
|
+
* ```
|
|
1975
2913
|
*/
|
|
1976
2914
|
async updateStatus(nanoid, params) {
|
|
1977
2915
|
return this.client.connectedAccounts.updateStatus(nanoid, params);
|
|
@@ -1979,8 +2917,14 @@ var ConnectedAccounts = class {
|
|
|
1979
2917
|
/**
|
|
1980
2918
|
* Enable a connected account
|
|
1981
2919
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
1982
|
-
* @param {RequestOptions} options - Request options
|
|
1983
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
|
+
* ```
|
|
1984
2928
|
*/
|
|
1985
2929
|
async enable(nanoid) {
|
|
1986
2930
|
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true });
|
|
@@ -1988,8 +2932,20 @@ var ConnectedAccounts = class {
|
|
|
1988
2932
|
/**
|
|
1989
2933
|
* Disable a connected account
|
|
1990
2934
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
1991
|
-
* @param {RequestOptions} options - Request options
|
|
1992
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
|
+
* ```
|
|
1993
2949
|
*/
|
|
1994
2950
|
async disable(nanoid) {
|
|
1995
2951
|
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
|
|
@@ -2002,6 +2958,7 @@ var Toolkits = class {
|
|
|
2002
2958
|
constructor(client) {
|
|
2003
2959
|
this.client = client;
|
|
2004
2960
|
this.authorize = this.authorize.bind(this);
|
|
2961
|
+
telemetry.instrument(this);
|
|
2005
2962
|
}
|
|
2006
2963
|
/**
|
|
2007
2964
|
* Retrieves a list of toolkits based on the provided query parameters.
|
|
@@ -2015,42 +2972,46 @@ var Toolkits = class {
|
|
|
2015
2972
|
* @private
|
|
2016
2973
|
*/
|
|
2017
2974
|
async getToolkits(query) {
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
sort_by: parsedQuery.sortBy
|
|
2024
|
-
});
|
|
2025
|
-
const parsedResult = ToolKitListResponseSchema.parse({
|
|
2026
|
-
items: result.items.map((item) => {
|
|
2027
|
-
const parsedItem = ToolKitItemSchema.parse({
|
|
2028
|
-
name: item.name,
|
|
2029
|
-
slug: item.slug,
|
|
2030
|
-
meta: item.meta,
|
|
2031
|
-
isLocalToolkit: item.is_local_toolkit,
|
|
2032
|
-
authSchemes: item.auth_schemes,
|
|
2033
|
-
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
2034
|
-
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
|
|
2035
2980
|
});
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
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
|
+
});
|
|
2052
3014
|
}
|
|
2053
|
-
return this.getToolkits(arg);
|
|
2054
3015
|
}
|
|
2055
3016
|
/**
|
|
2056
3017
|
* Retrieves a specific toolkit by its slug identifier.
|
|
@@ -2068,7 +3029,7 @@ var Toolkits = class {
|
|
|
2068
3029
|
async getToolkitBySlug(slug) {
|
|
2069
3030
|
try {
|
|
2070
3031
|
const result = await this.client.toolkits.retrieve(slug);
|
|
2071
|
-
const parsedResult = ToolkitRetrieveResponseSchema.
|
|
3032
|
+
const parsedResult = ToolkitRetrieveResponseSchema.safeParse({
|
|
2072
3033
|
name: result.name,
|
|
2073
3034
|
slug: result.slug,
|
|
2074
3035
|
meta: {
|
|
@@ -2093,16 +3054,41 @@ var Toolkits = class {
|
|
|
2093
3054
|
}
|
|
2094
3055
|
}))
|
|
2095
3056
|
});
|
|
2096
|
-
|
|
3057
|
+
if (!parsedResult.success) {
|
|
3058
|
+
throw new ValidationError("Failed to parse toolkit response", {
|
|
3059
|
+
cause: parsedResult.error
|
|
3060
|
+
});
|
|
3061
|
+
}
|
|
3062
|
+
return parsedResult.data;
|
|
2097
3063
|
} catch (error) {
|
|
2098
|
-
if (error instanceof
|
|
2099
|
-
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
|
+
});
|
|
2100
3071
|
}
|
|
2101
|
-
throw new
|
|
2102
|
-
|
|
3072
|
+
throw new ComposioToolkitFetchError(`Couldn't fetch Toolkit with slug: ${slug}`, {
|
|
3073
|
+
meta: {
|
|
3074
|
+
slug
|
|
3075
|
+
},
|
|
3076
|
+
cause: error
|
|
2103
3077
|
});
|
|
2104
3078
|
}
|
|
2105
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
|
+
}
|
|
2106
3092
|
/**
|
|
2107
3093
|
* Retrieves all toolkit categories available in the Composio SDK.
|
|
2108
3094
|
*
|
|
@@ -2150,7 +3136,7 @@ var Toolkits = class {
|
|
|
2150
3136
|
const composioAuthConfig = new AuthConfigs(this.client);
|
|
2151
3137
|
let authConfigIdToUse;
|
|
2152
3138
|
const authConfig = await composioAuthConfig.list({
|
|
2153
|
-
toolkitSlug
|
|
3139
|
+
toolkit: toolkitSlug
|
|
2154
3140
|
});
|
|
2155
3141
|
authConfigIdToUse = authConfig.items[0]?.id;
|
|
2156
3142
|
if (!authConfigIdToUse) {
|
|
@@ -2162,7 +3148,9 @@ var Toolkits = class {
|
|
|
2162
3148
|
authConfigIdToUse = authConfig2.id;
|
|
2163
3149
|
} else {
|
|
2164
3150
|
throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
|
|
2165
|
-
|
|
3151
|
+
meta: {
|
|
3152
|
+
toolkitSlug
|
|
3153
|
+
}
|
|
2166
3154
|
});
|
|
2167
3155
|
}
|
|
2168
3156
|
}
|
|
@@ -2171,474 +3159,662 @@ var Toolkits = class {
|
|
|
2171
3159
|
}
|
|
2172
3160
|
};
|
|
2173
3161
|
|
|
2174
|
-
// src/
|
|
2175
|
-
var
|
|
2176
|
-
var
|
|
2177
|
-
var
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
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);
|
|
2190
3460
|
}
|
|
2191
|
-
}
|
|
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
|
+
);
|
|
2192
3471
|
}
|
|
2193
|
-
return _PusherUtils.pusherClient;
|
|
2194
3472
|
}
|
|
2195
3473
|
/**
|
|
2196
|
-
*
|
|
2197
|
-
*
|
|
2198
|
-
*
|
|
2199
|
-
*
|
|
2200
|
-
*
|
|
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
|
|
2201
3480
|
*/
|
|
2202
|
-
|
|
3481
|
+
async unsubscribe() {
|
|
2203
3482
|
try {
|
|
2204
|
-
|
|
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.`);
|
|
2205
3487
|
} catch (error) {
|
|
2206
|
-
|
|
2207
|
-
|
|
3488
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3489
|
+
"Failed to unsubscribe from Pusher channel",
|
|
3490
|
+
{
|
|
3491
|
+
cause: error
|
|
3492
|
+
}
|
|
2208
3493
|
);
|
|
2209
3494
|
}
|
|
2210
3495
|
}
|
|
2211
|
-
/**
|
|
2212
|
-
* Unsubscribes from a Pusher channel.
|
|
2213
|
-
* @param {string} channelName - The name of the channel to unsubscribe from.
|
|
2214
|
-
* @returns {void}
|
|
2215
|
-
*/
|
|
2216
|
-
static async unsubscribe(channelName) {
|
|
2217
|
-
_PusherUtils.pusherClient.unsubscribe(channelName);
|
|
2218
|
-
}
|
|
2219
|
-
/**
|
|
2220
|
-
* Binds an event to a channel with support for chunked messages.
|
|
2221
|
-
* @param {PusherClient} channel - The Pusher channel to bind the event to.
|
|
2222
|
-
* @param {string} event - The event to bind to the channel.
|
|
2223
|
-
* @param {(data: unknown) => void} callback - The callback function to execute when the event is triggered.
|
|
2224
|
-
*/
|
|
2225
|
-
static bindWithChunking(channel, event, callback) {
|
|
2226
|
-
channel.bind(event, callback);
|
|
2227
|
-
const events = {};
|
|
2228
|
-
channel.bind("chunked-" + event, (data) => {
|
|
2229
|
-
const typedData = data;
|
|
2230
|
-
if (!events.hasOwnProperty(typedData.id)) {
|
|
2231
|
-
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
2232
|
-
}
|
|
2233
|
-
const ev = events[typedData.id];
|
|
2234
|
-
ev.chunks[typedData.index] = typedData.chunk;
|
|
2235
|
-
if (typedData.final) ev.receivedFinal = true;
|
|
2236
|
-
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
2237
|
-
callback(JSON.parse(ev.chunks.join("")));
|
|
2238
|
-
delete events[typedData.id];
|
|
2239
|
-
}
|
|
2240
|
-
});
|
|
2241
|
-
}
|
|
2242
|
-
/**
|
|
2243
|
-
* Subscribes to a trigger channel for a client and handles chunked data.
|
|
2244
|
-
* @param {string} clientId - The unique identifier for the client subscribing to the events.
|
|
2245
|
-
* @param {(data: TriggerData) => void} fn - The callback function to execute when trigger data is received.
|
|
2246
|
-
*/
|
|
2247
|
-
static triggerSubscribe(clientId, fn) {
|
|
2248
|
-
const channel = _PusherUtils.pusherClient.subscribe(
|
|
2249
|
-
`private-${clientId}_triggers`
|
|
2250
|
-
);
|
|
2251
|
-
_PusherUtils.bindWithChunking(
|
|
2252
|
-
channel,
|
|
2253
|
-
"trigger_to_client",
|
|
2254
|
-
fn
|
|
2255
|
-
);
|
|
2256
|
-
logger_default.info(
|
|
2257
|
-
`Subscribed to triggers. You should start receiving events now.`
|
|
2258
|
-
);
|
|
2259
|
-
}
|
|
2260
|
-
static triggerUnsubscribe(clientId) {
|
|
2261
|
-
_PusherUtils.pusherClient.unsubscribe(`${clientId}_triggers`);
|
|
2262
|
-
}
|
|
2263
|
-
};
|
|
2264
|
-
|
|
2265
|
-
// src/models/Session.ts
|
|
2266
|
-
var Session = class {
|
|
2267
|
-
client;
|
|
2268
|
-
constructor(client) {
|
|
2269
|
-
this.client = client;
|
|
2270
|
-
}
|
|
2271
|
-
/**
|
|
2272
|
-
* Get the active session info
|
|
2273
|
-
* @returns {Promise<SessionGetInfoResponse>} Session info
|
|
2274
|
-
*/
|
|
2275
|
-
async getInfo() {
|
|
2276
|
-
return this.client.auth.session.getInfo();
|
|
2277
|
-
}
|
|
2278
3496
|
};
|
|
2279
3497
|
|
|
2280
3498
|
// src/models/Triggers.ts
|
|
2281
3499
|
var Triggers = class {
|
|
2282
3500
|
client;
|
|
3501
|
+
pusherService;
|
|
2283
3502
|
constructor(client) {
|
|
2284
3503
|
this.client = client;
|
|
3504
|
+
this.pusherService = new PusherService(client);
|
|
3505
|
+
telemetry.instrument(this);
|
|
2285
3506
|
}
|
|
2286
3507
|
/**
|
|
2287
|
-
*
|
|
2288
|
-
* @returns {Promise<TriggerInstance[]>} List of trigger instances
|
|
2289
|
-
*/
|
|
2290
|
-
async list(query, options) {
|
|
2291
|
-
return this.client.triggerInstances.listActive(query, options);
|
|
2292
|
-
}
|
|
2293
|
-
/**
|
|
2294
|
-
* Create a new trigger instance
|
|
2295
|
-
*
|
|
2296
|
-
* @param {string} slug - The slug of the trigger instance
|
|
2297
|
-
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
2298
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
2299
|
-
*/
|
|
2300
|
-
async create(slug, body, options) {
|
|
2301
|
-
return this.client.triggerInstances.upsert(slug, body, options);
|
|
2302
|
-
}
|
|
2303
|
-
/**
|
|
2304
|
-
* Update an existing trigger instance
|
|
3508
|
+
* Parse the trigger instance list active item
|
|
2305
3509
|
*
|
|
2306
|
-
* @param
|
|
2307
|
-
* @
|
|
2308
|
-
* @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
|
|
2309
3512
|
*/
|
|
2310
|
-
|
|
2311
|
-
|
|
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;
|
|
2312
3531
|
}
|
|
2313
3532
|
/**
|
|
2314
|
-
*
|
|
3533
|
+
* Fetch list of all the active triggers
|
|
2315
3534
|
*
|
|
2316
|
-
* @param {
|
|
2317
|
-
* @returns
|
|
2318
|
-
*/
|
|
2319
|
-
async delete(slug) {
|
|
2320
|
-
return this.client.triggerInstances.removeUpsert(slug);
|
|
2321
|
-
}
|
|
2322
|
-
/**
|
|
2323
|
-
* 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
|
|
2324
3537
|
*
|
|
2325
|
-
* @
|
|
2326
|
-
* @
|
|
2327
|
-
* @param {RequestOptions} options - Request options
|
|
2328
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2329
|
-
*/
|
|
2330
|
-
async updateStatus(status, params, options) {
|
|
2331
|
-
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
2332
|
-
}
|
|
2333
|
-
/**
|
|
2334
|
-
* Disable a trigger instance
|
|
3538
|
+
* @throws {ValidationError} If the parameters are invalid
|
|
3539
|
+
* @throws {Error} If the client is not authenticated
|
|
2335
3540
|
*
|
|
2336
|
-
* @
|
|
2337
|
-
*
|
|
2338
|
-
*
|
|
3541
|
+
* @example
|
|
3542
|
+
* ```ts
|
|
3543
|
+
* const triggers = await triggers.listActive({
|
|
3544
|
+
* authConfigIds: ['123'],
|
|
3545
|
+
* connectedAccountIds: ['456'],
|
|
3546
|
+
* });
|
|
3547
|
+
* ```
|
|
2339
3548
|
*/
|
|
2340
|
-
async
|
|
2341
|
-
|
|
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;
|
|
2342
3578
|
}
|
|
2343
3579
|
/**
|
|
2344
|
-
*
|
|
3580
|
+
* Create a new trigger instance
|
|
2345
3581
|
*
|
|
2346
3582
|
* @param {string} slug - The slug of the trigger instance
|
|
2347
|
-
* @param {
|
|
2348
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The
|
|
2349
|
-
*/
|
|
2350
|
-
async
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
* @param {RequestOptions} options - Request options
|
|
2361
|
-
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
|
|
2362
|
-
*/
|
|
2363
|
-
async listTypes(query, options) {
|
|
2364
|
-
return this.client.triggersTypes.list(query, options);
|
|
2365
|
-
}
|
|
2366
|
-
/**
|
|
2367
|
-
* Retrieve a trigger type by its slug
|
|
2368
|
-
*
|
|
2369
|
-
* @param {string} slug - The slug of the trigger type
|
|
2370
|
-
* @param {RequestOptions} options - request options
|
|
2371
|
-
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
2372
|
-
*/
|
|
2373
|
-
async getType(slug, options) {
|
|
2374
|
-
return this.client.triggersTypes.retrieve(slug, options);
|
|
2375
|
-
}
|
|
2376
|
-
/**
|
|
2377
|
-
* Fetches the list of all the available trigger enums
|
|
2378
|
-
*
|
|
2379
|
-
* This method is used by the CLI where filters are not required.
|
|
2380
|
-
* @param options
|
|
2381
|
-
* @returns
|
|
2382
|
-
*/
|
|
2383
|
-
async listEnum(options) {
|
|
2384
|
-
return this.client.triggersTypes.retrieveEnum(options);
|
|
2385
|
-
}
|
|
2386
|
-
async subscribe(fn, filters = {}) {
|
|
2387
|
-
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
2388
|
-
const session = new Session(this.client);
|
|
2389
|
-
const sessionInfo = await session.getInfo();
|
|
2390
|
-
const clientId = sessionInfo.project?.id;
|
|
2391
|
-
if (!clientId) throw new Error("Client ID not found");
|
|
2392
|
-
if (!this.client.apiKey) throw new Error("API key not found");
|
|
2393
|
-
await PusherUtils.getPusherClient(this.client.baseURL, this.client.apiKey);
|
|
2394
|
-
const shouldSendTrigger = (data) => {
|
|
2395
|
-
if (Object.keys(filters).length === 0) return true;
|
|
2396
|
-
else {
|
|
2397
|
-
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());
|
|
2398
|
-
}
|
|
2399
|
-
};
|
|
2400
|
-
logger_default.debug("Subscribing to triggers", filters);
|
|
2401
|
-
PusherUtils.triggerSubscribe(clientId, (data) => {
|
|
2402
|
-
if (shouldSendTrigger(data)) {
|
|
2403
|
-
fn(data);
|
|
2404
|
-
}
|
|
2405
|
-
});
|
|
2406
|
-
}
|
|
2407
|
-
async unsubscribe() {
|
|
2408
|
-
const session = new Session(this.client);
|
|
2409
|
-
const sessionInfo = await session.getInfo();
|
|
2410
|
-
const clientId = sessionInfo.project?.id;
|
|
2411
|
-
if (!clientId) throw new Error("Client ID not found");
|
|
2412
|
-
PusherUtils.triggerUnsubscribe(clientId);
|
|
2413
|
-
}
|
|
2414
|
-
};
|
|
2415
|
-
|
|
2416
|
-
// src/types/telemetry.types.ts
|
|
2417
|
-
var TELEMETRY_EVENTS = {
|
|
2418
|
-
SDK_INITIALIZED: "SDK_INITIALIZED",
|
|
2419
|
-
SDK_METHOD_INVOKED: "SDK_METHOD_INVOKED",
|
|
2420
|
-
SDK_METHOD_ERROR: "SDK_METHOD_ERROR",
|
|
2421
|
-
CLI_INVOKED: "CLI_INVOKED"
|
|
2422
|
-
};
|
|
2423
|
-
|
|
2424
|
-
// src/utils/constants.ts
|
|
2425
|
-
var COMPOSIO_DIR = ".composio";
|
|
2426
|
-
var USER_DATA_FILE_NAME = "user_data.json";
|
|
2427
|
-
var DEFAULT_BASE_URL = "https://backend.composio.dev";
|
|
2428
|
-
var TELEMETRY_URL = "https://app.composio.dev";
|
|
2429
|
-
var IS_DEVELOPMENT_OR_CI = process.env.DEVELOPMENT || process.env.CI || false;
|
|
2430
|
-
|
|
2431
|
-
// src/telemetry/BatchProcessor.ts
|
|
2432
|
-
var BatchProcessor = class {
|
|
2433
|
-
batch = [];
|
|
2434
|
-
time;
|
|
2435
|
-
batchSize;
|
|
2436
|
-
processBatchCallback;
|
|
2437
|
-
timer = null;
|
|
2438
|
-
constructor(time = 2e3, batchSize = 100, processBatchCallback) {
|
|
2439
|
-
this.batch = [];
|
|
2440
|
-
this.time = time;
|
|
2441
|
-
this.batchSize = batchSize;
|
|
2442
|
-
this.processBatchCallback = processBatchCallback;
|
|
2443
|
-
}
|
|
2444
|
-
pushItem(item) {
|
|
2445
|
-
this.batch.push(item);
|
|
2446
|
-
if (this.batch.length >= this.batchSize) {
|
|
2447
|
-
this.processBatch();
|
|
2448
|
-
} else if (!this.timer) {
|
|
2449
|
-
this.timer = setTimeout(() => this.processBatch(), this.time);
|
|
2450
|
-
}
|
|
2451
|
-
}
|
|
2452
|
-
processBatch() {
|
|
2453
|
-
if (this.batch.length > 0) {
|
|
2454
|
-
this.processBatchCallback(this.batch);
|
|
2455
|
-
this.batch = [];
|
|
2456
|
-
}
|
|
2457
|
-
if (this.timer) {
|
|
2458
|
-
clearTimeout(this.timer);
|
|
2459
|
-
this.timer = null;
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
};
|
|
2463
|
-
|
|
2464
|
-
// src/telemetry/transports/BrowserTransport.ts
|
|
2465
|
-
var BrowserTelemetryTransport = class {
|
|
2466
|
-
send(payload) {
|
|
2467
|
-
if (typeof window === "undefined") {
|
|
2468
|
-
return Promise.reject(
|
|
2469
|
-
new Error("BrowserTelemetryTransport can only be used in browser environments")
|
|
2470
|
-
);
|
|
2471
|
-
}
|
|
2472
|
-
return new Promise((resolve) => {
|
|
2473
|
-
try {
|
|
2474
|
-
const xhr = new XMLHttpRequest();
|
|
2475
|
-
xhr.open(payload.method, payload.url, true);
|
|
2476
|
-
xhr.setRequestHeader("Content-Type", "application/json");
|
|
2477
|
-
Object.entries(payload.headers || {}).forEach(([key, value]) => {
|
|
2478
|
-
xhr.setRequestHeader(key, value);
|
|
2479
|
-
});
|
|
2480
|
-
xhr.onload = function() {
|
|
2481
|
-
resolve();
|
|
2482
|
-
};
|
|
2483
|
-
xhr.send(JSON.stringify(payload.data));
|
|
2484
|
-
} catch (error) {
|
|
2485
|
-
logger_default.error("Error sending error to telemetry", error);
|
|
2486
|
-
resolve();
|
|
2487
|
-
}
|
|
2488
|
-
});
|
|
2489
|
-
}
|
|
2490
|
-
};
|
|
2491
|
-
|
|
2492
|
-
// src/telemetry/transports/ProcessTransport.ts
|
|
2493
|
-
var ProcessTelemetryTransport = class {
|
|
2494
|
-
send(payload) {
|
|
2495
|
-
if (typeof window !== "undefined") {
|
|
2496
|
-
return Promise.reject(
|
|
2497
|
-
new Error("ProcessTelemetryTransport can only be used in Node.js environments")
|
|
2498
|
-
);
|
|
2499
|
-
}
|
|
2500
|
-
return new Promise((resolve) => {
|
|
2501
|
-
try {
|
|
2502
|
-
const url = new URL(payload.url);
|
|
2503
|
-
const protocol = url.protocol === "https:" ? "https" : "http";
|
|
2504
|
-
const port = url.port || (url.protocol === "https:" ? 443 : 80);
|
|
2505
|
-
const args = [
|
|
2506
|
-
"-e",
|
|
2507
|
-
`
|
|
2508
|
-
const http = require('${protocol}');
|
|
2509
|
-
const options = {
|
|
2510
|
-
hostname: '${url.hostname}',
|
|
2511
|
-
path: '${url.pathname}${url.search}',
|
|
2512
|
-
port: ${port},
|
|
2513
|
-
method: '${payload.method}',
|
|
2514
|
-
headers: ${JSON.stringify(payload.headers)}
|
|
2515
|
-
};
|
|
2516
|
-
|
|
2517
|
-
const req = http.request(options, (res) => {
|
|
2518
|
-
res.on('data', () => {});
|
|
2519
|
-
res.on('end', () => {
|
|
2520
|
-
process.exit(0);
|
|
2521
|
-
});
|
|
2522
|
-
});
|
|
2523
|
-
|
|
2524
|
-
req.on('error', () => {
|
|
2525
|
-
process.exit(0);
|
|
2526
|
-
});
|
|
2527
|
-
|
|
2528
|
-
req.write(JSON.stringify(${JSON.stringify(payload.data)}));
|
|
2529
|
-
req.end();
|
|
2530
|
-
`
|
|
2531
|
-
];
|
|
2532
|
-
import("child_process").then(({ spawn }) => {
|
|
2533
|
-
spawn("node", args, {
|
|
2534
|
-
stdio: "ignore",
|
|
2535
|
-
detached: true,
|
|
2536
|
-
shell: false
|
|
2537
|
-
}).unref();
|
|
2538
|
-
resolve();
|
|
2539
|
-
}).catch(() => {
|
|
2540
|
-
resolve();
|
|
2541
|
-
});
|
|
2542
|
-
} catch (error) {
|
|
2543
|
-
logger_default.error("Error sending telemetry", error);
|
|
2544
|
-
resolve();
|
|
2545
|
-
}
|
|
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
|
|
2546
3596
|
});
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
batchProcessor = new BatchProcessor(100, 10, async (data) => {
|
|
2555
|
-
await this.sendTelemetry(data);
|
|
2556
|
-
});
|
|
2557
|
-
constructor(metadata, transport) {
|
|
2558
|
-
this.telemetryMetadata = metadata;
|
|
2559
|
-
const isBrowser = typeof window !== "undefined";
|
|
2560
|
-
if (transport) {
|
|
2561
|
-
this.transport = transport;
|
|
2562
|
-
} else if (isBrowser) {
|
|
2563
|
-
this.transport = new BrowserTelemetryTransport();
|
|
2564
|
-
} else {
|
|
2565
|
-
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
|
+
});
|
|
2566
3604
|
}
|
|
2567
|
-
|
|
2568
|
-
{
|
|
2569
|
-
eventName: TELEMETRY_EVENTS.SDK_INITIALIZED,
|
|
2570
|
-
data: {},
|
|
2571
|
-
sdk_meta: this.telemetryMetadata
|
|
2572
|
-
}
|
|
2573
|
-
]);
|
|
3605
|
+
return parsedResult.data;
|
|
2574
3606
|
}
|
|
2575
3607
|
/**
|
|
2576
|
-
*
|
|
3608
|
+
* Update an existing trigger instance
|
|
2577
3609
|
*
|
|
2578
|
-
*
|
|
2579
|
-
*
|
|
2580
|
-
* @
|
|
2581
|
-
|
|
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
|
|
2582
3621
|
* @returns
|
|
2583
3622
|
*/
|
|
2584
|
-
|
|
2585
|
-
const
|
|
2586
|
-
const
|
|
2587
|
-
|
|
2588
|
-
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
|
|
2589
3627
|
});
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
const telemetryPayload = {
|
|
2595
|
-
eventName: TELEMETRY_EVENTS.SDK_METHOD_INVOKED,
|
|
2596
|
-
data: {
|
|
2597
|
-
fileName: instrumentedClassName,
|
|
2598
|
-
method: name,
|
|
2599
|
-
params: args
|
|
2600
|
-
},
|
|
2601
|
-
sdk_meta: this.telemetryMetadata
|
|
2602
|
-
};
|
|
2603
|
-
this.batchProcessor.pushItem(telemetryPayload);
|
|
2604
|
-
try {
|
|
2605
|
-
return await originalMethod.apply(instance, args);
|
|
2606
|
-
} catch (error) {
|
|
2607
|
-
const telemetryPayload2 = {
|
|
2608
|
-
eventName: TELEMETRY_EVENTS.SDK_METHOD_ERROR,
|
|
2609
|
-
data: {
|
|
2610
|
-
fileName: instrumentedClassName,
|
|
2611
|
-
method: name,
|
|
2612
|
-
params: args,
|
|
2613
|
-
error
|
|
2614
|
-
},
|
|
2615
|
-
sdk_meta: this.telemetryMetadata
|
|
2616
|
-
};
|
|
2617
|
-
this.batchProcessor.pushItem(telemetryPayload2);
|
|
2618
|
-
throw error;
|
|
2619
|
-
}
|
|
2620
|
-
};
|
|
3628
|
+
if (!parsedResult.success) {
|
|
3629
|
+
throw new ValidationError(`Invalid trigger instance manage delete response`, {
|
|
3630
|
+
cause: parsedResult.error
|
|
3631
|
+
});
|
|
2621
3632
|
}
|
|
2622
|
-
return
|
|
3633
|
+
return parsedResult.data;
|
|
2623
3634
|
}
|
|
2624
3635
|
/**
|
|
2625
|
-
*
|
|
2626
|
-
*
|
|
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
|
|
2627
3685
|
* @returns
|
|
2628
3686
|
*/
|
|
2629
|
-
async
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
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
|
+
});
|
|
2633
3711
|
}
|
|
2634
|
-
const
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
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;
|
|
2640
3757
|
};
|
|
2641
|
-
|
|
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();
|
|
2642
3818
|
}
|
|
2643
3819
|
};
|
|
2644
3820
|
|
|
@@ -2649,6 +3825,7 @@ var userDataPath = () => {
|
|
|
2649
3825
|
const os = require("os");
|
|
2650
3826
|
return path.join(os.homedir(), COMPOSIO_DIR, USER_DATA_FILE_NAME);
|
|
2651
3827
|
} catch (_error) {
|
|
3828
|
+
logger_default.debug("Environment", `Unable to get user data path`);
|
|
2652
3829
|
return null;
|
|
2653
3830
|
}
|
|
2654
3831
|
};
|
|
@@ -2658,6 +3835,7 @@ var getUserDataJson = () => {
|
|
|
2658
3835
|
const data = fs.readFileSync(userDataPath(), "utf8");
|
|
2659
3836
|
return JSON.parse(data);
|
|
2660
3837
|
} catch (_error) {
|
|
3838
|
+
logger_default.debug("Environment", "No user data file found");
|
|
2661
3839
|
return {};
|
|
2662
3840
|
}
|
|
2663
3841
|
};
|
|
@@ -2666,27 +3844,33 @@ function getSDKConfig(baseUrl, apiKey) {
|
|
|
2666
3844
|
const { api_key: apiKeyFromUserConfig, base_url: baseURLFromUserConfig } = userData;
|
|
2667
3845
|
const baseURLParsed = baseUrl || getEnvVariable("COMPOSIO_BASE_URL") || baseURLFromUserConfig || DEFAULT_BASE_URL;
|
|
2668
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}`);
|
|
2669
3854
|
return { baseURL: baseURLParsed, apiKey: apiKeyParsed };
|
|
2670
3855
|
}
|
|
2671
3856
|
|
|
2672
3857
|
// src/utils/version.ts
|
|
2673
|
-
|
|
2674
|
-
const v1 = version1.split(".").map(Number);
|
|
2675
|
-
const v2 = version2.split(".").map(Number);
|
|
2676
|
-
for (let i = 0; i < 3; i++) {
|
|
2677
|
-
if (v1[i] > v2[i]) return true;
|
|
2678
|
-
if (v1[i] < v2[i]) return false;
|
|
2679
|
-
}
|
|
2680
|
-
return false;
|
|
2681
|
-
}
|
|
3858
|
+
var import_semver = __toESM(require("semver"), 1);
|
|
2682
3859
|
async function checkForLatestVersionFromNPM(currentVersion) {
|
|
2683
3860
|
try {
|
|
2684
|
-
const packageName = "composio
|
|
3861
|
+
const packageName = "@composio/core";
|
|
2685
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
|
+
}
|
|
2686
3870
|
const response = await fetch(`https://registry.npmjs.org/${packageName}/latest`);
|
|
2687
3871
|
const data = await response.json();
|
|
2688
3872
|
const latestVersion = data.version;
|
|
2689
|
-
if (
|
|
3873
|
+
if (import_semver.default.gt(latestVersion, currentVersionFromPackageJson) && !IS_DEVELOPMENT_OR_CI) {
|
|
2690
3874
|
logger_default.info(
|
|
2691
3875
|
`\u{1F680} Upgrade available! Your composio-core version (${currentVersionFromPackageJson}) is behind. Latest version: ${latestVersion}.`
|
|
2692
3876
|
);
|
|
@@ -2713,11 +3897,12 @@ var BaseProvider = class {
|
|
|
2713
3897
|
}
|
|
2714
3898
|
/**
|
|
2715
3899
|
* @public
|
|
2716
|
-
*
|
|
2717
|
-
* 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.
|
|
2718
3902
|
* This is a 1:1 mapping of the `execute` method in the `Tools` class.
|
|
2719
3903
|
* @param {string} toolSlug - The slug of the tool to execute.
|
|
2720
|
-
* @param {
|
|
3904
|
+
* @param {ToolExecuteParams} body - The body of the tool execution.
|
|
3905
|
+
* @param {ExecuteToolModifiers} modifers - The modifiers of the tool execution.
|
|
2721
3906
|
* @returns {Promise<string>} The result of the tool execution.
|
|
2722
3907
|
*/
|
|
2723
3908
|
executeTool(toolSlug, body, modifers) {
|
|
@@ -2738,10 +3923,54 @@ var BaseAgenticProvider = class extends BaseProvider {
|
|
|
2738
3923
|
var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
2739
3924
|
name = "openai";
|
|
2740
3925
|
/**
|
|
2741
|
-
*
|
|
2742
|
-
*
|
|
2743
|
-
*
|
|
2744
|
-
*
|
|
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
|
+
* ```
|
|
2745
3974
|
*/
|
|
2746
3975
|
wrapTool = (tool) => {
|
|
2747
3976
|
const formattedSchema = {
|
|
@@ -2754,14 +3983,78 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2754
3983
|
function: formattedSchema
|
|
2755
3984
|
};
|
|
2756
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
|
+
*/
|
|
2757
4024
|
wrapTools = (tools) => {
|
|
2758
4025
|
return tools.map((tool) => this.wrapTool(tool));
|
|
2759
4026
|
};
|
|
2760
4027
|
/**
|
|
2761
|
-
*
|
|
2762
|
-
*
|
|
2763
|
-
*
|
|
2764
|
-
*
|
|
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
|
+
* ```
|
|
2765
4058
|
*/
|
|
2766
4059
|
async executeToolCall(userId, tool, options, modifiers) {
|
|
2767
4060
|
const payload = {
|
|
@@ -2774,13 +4067,48 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2774
4067
|
return JSON.stringify(result);
|
|
2775
4068
|
}
|
|
2776
4069
|
/**
|
|
2777
|
-
*
|
|
4070
|
+
* Handles tool calls from OpenAI's chat completion response.
|
|
2778
4071
|
*
|
|
2779
|
-
*
|
|
2780
|
-
*
|
|
2781
|
-
*
|
|
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
|
+
* ```
|
|
2782
4110
|
*/
|
|
2783
|
-
async
|
|
4111
|
+
async handleToolCalls(userId, chatCompletion, options, modifiers) {
|
|
2784
4112
|
const outputs = [];
|
|
2785
4113
|
for (const message of chatCompletion.choices) {
|
|
2786
4114
|
if (message.message.tool_calls) {
|
|
@@ -2792,11 +4120,51 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2792
4120
|
return outputs;
|
|
2793
4121
|
}
|
|
2794
4122
|
/**
|
|
2795
|
-
* Handles all the tool calls from the
|
|
4123
|
+
* Handles all the tool calls from the OpenAI Assistant API.
|
|
2796
4124
|
*
|
|
2797
|
-
*
|
|
2798
|
-
*
|
|
2799
|
-
*
|
|
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
|
+
* ```
|
|
2800
4168
|
*/
|
|
2801
4169
|
async handleAssistantMessage(userId, run, options, modifiers) {
|
|
2802
4170
|
const tool_calls = run.required_action?.submit_tool_outputs?.tool_calls || [];
|
|
@@ -2821,11 +4189,43 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2821
4189
|
/**
|
|
2822
4190
|
* Waits for the assistant stream and handles the tool calls.
|
|
2823
4191
|
*
|
|
2824
|
-
*
|
|
2825
|
-
*
|
|
2826
|
-
*
|
|
2827
|
-
*
|
|
2828
|
-
* @
|
|
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
|
+
* ```
|
|
2829
4229
|
*/
|
|
2830
4230
|
async *waitAndHandleAssistantStreamToolCalls(userId, client, runStream, thread, options, modifiers) {
|
|
2831
4231
|
let runId = null;
|
|
@@ -2877,11 +4277,45 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2877
4277
|
/**
|
|
2878
4278
|
* Waits for the assistant tool calls and handles them.
|
|
2879
4279
|
*
|
|
2880
|
-
*
|
|
2881
|
-
*
|
|
2882
|
-
*
|
|
2883
|
-
*
|
|
2884
|
-
* @
|
|
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
|
+
* ```
|
|
2885
4319
|
*/
|
|
2886
4320
|
async waitAndHandleAssistantToolCalls(userId, client, run, thread, options, modifiers) {
|
|
2887
4321
|
while (["queued", "in_progress", "requires_action"].includes(run.status)) {
|
|
@@ -2900,13 +4334,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
2900
4334
|
};
|
|
2901
4335
|
|
|
2902
4336
|
// package.json
|
|
2903
|
-
var version = "0.1.12
|
|
2904
|
-
|
|
2905
|
-
// src/utils/uuid.ts
|
|
2906
|
-
var import_uuid = require("uuid");
|
|
2907
|
-
function getRandomUUID() {
|
|
2908
|
-
return (0, import_uuid.v4)();
|
|
2909
|
-
}
|
|
4337
|
+
var version = "0.1.12";
|
|
2910
4338
|
|
|
2911
4339
|
// src/composio.ts
|
|
2912
4340
|
var Composio = class {
|
|
@@ -2920,7 +4348,6 @@ var Composio = class {
|
|
|
2920
4348
|
* @type {ComposioConfig<TProvider>}
|
|
2921
4349
|
*/
|
|
2922
4350
|
config;
|
|
2923
|
-
telemetry;
|
|
2924
4351
|
/**
|
|
2925
4352
|
* Core models for Composio.
|
|
2926
4353
|
*/
|
|
@@ -2933,13 +4360,36 @@ var Composio = class {
|
|
|
2933
4360
|
// connected accounts
|
|
2934
4361
|
connectedAccounts;
|
|
2935
4362
|
/**
|
|
2936
|
-
*
|
|
2937
|
-
*
|
|
2938
|
-
*
|
|
2939
|
-
*
|
|
2940
|
-
*
|
|
2941
|
-
* @param {
|
|
2942
|
-
* @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
|
+
* ```
|
|
2943
4393
|
*/
|
|
2944
4394
|
constructor(config) {
|
|
2945
4395
|
const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getSDKConfig(
|
|
@@ -2947,55 +4397,46 @@ var Composio = class {
|
|
|
2947
4397
|
config?.apiKey
|
|
2948
4398
|
);
|
|
2949
4399
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
2950
|
-
logger_default.
|
|
4400
|
+
logger_default.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
2951
4401
|
}
|
|
2952
|
-
this.client = new
|
|
4402
|
+
this.client = new import_client6.default({
|
|
2953
4403
|
apiKey: apiKeyParsed,
|
|
2954
4404
|
baseURL: baseURLParsed
|
|
2955
4405
|
});
|
|
2956
4406
|
this.config = {
|
|
2957
4407
|
...config,
|
|
2958
|
-
allowTracking: config
|
|
4408
|
+
allowTracking: config?.allowTracking ?? true,
|
|
4409
|
+
allowTracing: config?.allowTracing ?? true
|
|
2959
4410
|
};
|
|
2960
|
-
this.provider = config
|
|
4411
|
+
this.provider = config?.provider ?? new OpenAIProvider();
|
|
2961
4412
|
this.tools = new Tools(this.client, this.provider);
|
|
2962
4413
|
this.toolkits = new Toolkits(this.client);
|
|
2963
4414
|
this.triggers = new Triggers(this.client);
|
|
2964
4415
|
this.authConfigs = new AuthConfigs(this.client);
|
|
2965
4416
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
2966
|
-
if (this.config.allowTracking
|
|
2967
|
-
|
|
4417
|
+
if (this.config.allowTracking) {
|
|
4418
|
+
telemetry.setup(
|
|
2968
4419
|
{
|
|
2969
4420
|
apiKey: apiKeyParsed ?? "",
|
|
2970
4421
|
baseUrl: baseURLParsed ?? "",
|
|
2971
|
-
frameworkRuntime: "
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
4422
|
+
frameworkRuntime: this.provider?.name ?? "unknown",
|
|
4423
|
+
isAgentic: this.provider?._isAgentic || false,
|
|
4424
|
+
source: "javascript",
|
|
4425
|
+
version,
|
|
4426
|
+
sdkType: "Typescript-V3",
|
|
2975
4427
|
isBrowser: typeof window !== "undefined",
|
|
2976
|
-
|
|
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
|
|
2977
4431
|
// @TODO: get the session id
|
|
2978
4432
|
},
|
|
2979
|
-
config
|
|
4433
|
+
config?.telemetryTransport
|
|
2980
4434
|
);
|
|
2981
4435
|
}
|
|
4436
|
+
telemetry.instrument(this);
|
|
4437
|
+
telemetry.instrument(this.provider);
|
|
2982
4438
|
checkForLatestVersionFromNPM(version);
|
|
2983
4439
|
}
|
|
2984
|
-
/**
|
|
2985
|
-
* Initialize the instrumentations and telemetry for the Composio SDK.
|
|
2986
|
-
* @param {TelemetryMetadata} config - The configuration for the telemetry.
|
|
2987
|
-
* @param {BaseTelemetryTransport} transport - The transport for the telemetry.
|
|
2988
|
-
*/
|
|
2989
|
-
initializeTelemetry(config, transport) {
|
|
2990
|
-
this.telemetry = new Telemetry(config, transport);
|
|
2991
|
-
this.telemetry.instrumentTelemetry(this);
|
|
2992
|
-
this.telemetry.instrumentTelemetry(this.tools);
|
|
2993
|
-
this.telemetry.instrumentTelemetry(this.toolkits);
|
|
2994
|
-
this.telemetry.instrumentTelemetry(this.triggers);
|
|
2995
|
-
this.telemetry.instrumentTelemetry(this.authConfigs);
|
|
2996
|
-
this.telemetry.instrumentTelemetry(this.connectedAccounts);
|
|
2997
|
-
this.telemetry.instrumentTelemetry(this.provider);
|
|
2998
|
-
}
|
|
2999
4440
|
/**
|
|
3000
4441
|
* Get the Composio SDK client.
|
|
3001
4442
|
* @returns {ComposioClient} The Composio API client.
|
|
@@ -3020,43 +4461,50 @@ var ComposioProvider = class extends BaseNonAgenticProvider {
|
|
|
3020
4461
|
};
|
|
3021
4462
|
|
|
3022
4463
|
// src/telemetry/TelemetryTransport.ts
|
|
4464
|
+
var import_chalk4 = __toESM(require("chalk"), 1);
|
|
3023
4465
|
var BaseTelemetryTransport = class {
|
|
3024
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
|
+
};
|
|
3025
4473
|
|
|
3026
4474
|
// src/utils/jsonSchema.ts
|
|
3027
|
-
var
|
|
4475
|
+
var import_zod10 = require("zod");
|
|
3028
4476
|
function jsonSchemaPropertiesToTSTypes(value) {
|
|
3029
4477
|
if (!value.type) {
|
|
3030
|
-
return
|
|
4478
|
+
return import_zod10.z.object({});
|
|
3031
4479
|
}
|
|
3032
4480
|
let zodType;
|
|
3033
4481
|
switch (value.type) {
|
|
3034
4482
|
case "string":
|
|
3035
|
-
zodType =
|
|
4483
|
+
zodType = import_zod10.z.string().describe(
|
|
3036
4484
|
(value.description || "") + (value.examples ? `
|
|
3037
4485
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3038
4486
|
);
|
|
3039
4487
|
break;
|
|
3040
4488
|
case "number":
|
|
3041
|
-
zodType =
|
|
4489
|
+
zodType = import_zod10.z.number().describe(
|
|
3042
4490
|
(value.description || "") + (value.examples ? `
|
|
3043
4491
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3044
4492
|
);
|
|
3045
4493
|
break;
|
|
3046
4494
|
case "integer":
|
|
3047
|
-
zodType =
|
|
4495
|
+
zodType = import_zod10.z.number().int().describe(
|
|
3048
4496
|
(value.description || "") + (value.examples ? `
|
|
3049
4497
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3050
4498
|
);
|
|
3051
4499
|
break;
|
|
3052
4500
|
case "boolean":
|
|
3053
|
-
zodType =
|
|
4501
|
+
zodType = import_zod10.z.boolean().describe(
|
|
3054
4502
|
(value.description || "") + (value.examples ? `
|
|
3055
4503
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3056
4504
|
);
|
|
3057
4505
|
break;
|
|
3058
4506
|
case "array":
|
|
3059
|
-
zodType =
|
|
4507
|
+
zodType = import_zod10.z.array(
|
|
3060
4508
|
jsonSchemaPropertiesToTSTypes(
|
|
3061
4509
|
value.items
|
|
3062
4510
|
)
|
|
@@ -3066,24 +4514,24 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3066
4514
|
);
|
|
3067
4515
|
break;
|
|
3068
4516
|
case "object":
|
|
3069
|
-
zodType =
|
|
4517
|
+
zodType = jsonSchemaToZodSchema(value).describe(
|
|
3070
4518
|
(value.description || "") + (value.examples ? `
|
|
3071
4519
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3072
4520
|
);
|
|
3073
4521
|
break;
|
|
3074
4522
|
case "null":
|
|
3075
|
-
zodType =
|
|
4523
|
+
zodType = import_zod10.z.null().describe(value.description || "");
|
|
3076
4524
|
break;
|
|
3077
4525
|
default:
|
|
3078
4526
|
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
3079
4527
|
}
|
|
3080
4528
|
return zodType;
|
|
3081
4529
|
}
|
|
3082
|
-
function
|
|
4530
|
+
function jsonSchemaToZodSchema(jsonSchema) {
|
|
3083
4531
|
const properties = jsonSchema.properties;
|
|
3084
4532
|
const requiredFields = jsonSchema.required || [];
|
|
3085
4533
|
if (!properties) {
|
|
3086
|
-
return
|
|
4534
|
+
return import_zod10.z.object({});
|
|
3087
4535
|
}
|
|
3088
4536
|
const zodSchema = {};
|
|
3089
4537
|
for (const [key, _] of Object.entries(properties)) {
|
|
@@ -3095,7 +4543,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
3095
4543
|
schema
|
|
3096
4544
|
)
|
|
3097
4545
|
);
|
|
3098
|
-
zodType =
|
|
4546
|
+
zodType = import_zod10.z.union(anyOfTypes).describe(
|
|
3099
4547
|
(value.description || "") + (value.examples ? `
|
|
3100
4548
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3101
4549
|
);
|
|
@@ -3105,7 +4553,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3105
4553
|
schema
|
|
3106
4554
|
)
|
|
3107
4555
|
);
|
|
3108
|
-
zodType =
|
|
4556
|
+
zodType = import_zod10.z.intersection(
|
|
3109
4557
|
allOfTypes[0],
|
|
3110
4558
|
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
3111
4559
|
).describe(
|
|
@@ -3129,18 +4577,43 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3129
4577
|
zodSchema[key] = zodType.optional();
|
|
3130
4578
|
}
|
|
3131
4579
|
}
|
|
3132
|
-
return
|
|
4580
|
+
return import_zod10.z.object(zodSchema);
|
|
3133
4581
|
}
|
|
3134
4582
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3135
4583
|
0 && (module.exports = {
|
|
4584
|
+
AuthConfigErrorCodes,
|
|
3136
4585
|
AuthConfigTypes,
|
|
3137
4586
|
AuthSchemeTypes,
|
|
3138
4587
|
BaseAgenticProvider,
|
|
3139
4588
|
BaseNonAgenticProvider,
|
|
3140
4589
|
BaseTelemetryTransport,
|
|
3141
4590
|
Composio,
|
|
4591
|
+
ComposioAuthConfigNotFoundError,
|
|
4592
|
+
ComposioConnectedAccountNotFoundError,
|
|
4593
|
+
ComposioCustomToolsNotInitializedError,
|
|
4594
|
+
ComposioError,
|
|
4595
|
+
ComposioGlobalExecuteToolFnNotSetError,
|
|
4596
|
+
ComposioInvalidExecuteFunctionError,
|
|
4597
|
+
ComposioInvalidModifierError,
|
|
4598
|
+
ComposioNoAPIKeyError,
|
|
3142
4599
|
ComposioProvider,
|
|
4600
|
+
ComposioProviderNotDefinedError,
|
|
4601
|
+
ComposioToolExecutionError,
|
|
4602
|
+
ComposioToolNotFoundError,
|
|
4603
|
+
ComposioToolkitFetchError,
|
|
4604
|
+
ComposioToolkitNotFoundError,
|
|
4605
|
+
ConnectedAccountErrorCodes,
|
|
4606
|
+
ConnectionRequestErrorCodes,
|
|
4607
|
+
ConnectionRequestFailedError,
|
|
4608
|
+
ConnectionRequestTimeoutError,
|
|
4609
|
+
ConsoleTelemetryTransport,
|
|
3143
4610
|
OpenAIProvider,
|
|
4611
|
+
SDKErrorCodes,
|
|
4612
|
+
ToolErrorCodes,
|
|
3144
4613
|
ToolListParamsSchema,
|
|
3145
|
-
|
|
4614
|
+
ToolkitErrorCodes,
|
|
4615
|
+
ValidationError,
|
|
4616
|
+
ValidationErrorCodes,
|
|
4617
|
+
jsonSchemaToZodSchema,
|
|
4618
|
+
logger
|
|
3146
4619
|
});
|