@composio/core 0.1.8-alpha.0 → 0.1.9-alpha.0
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 +1255 -897
- package/dist/index.d.cts +294 -320
- package/dist/index.d.ts +294 -320
- package/dist/index.js +1165 -807
- package/package.json +3 -3
- package/src/index.ts +23 -0
package/dist/index.js
CHANGED
|
@@ -31,12 +31,12 @@ var ToolListResponseSchema = z.object({
|
|
|
31
31
|
totalPages: z.number()
|
|
32
32
|
});
|
|
33
33
|
var ToolListParamsSchema = z.object({
|
|
34
|
+
tools: z.array(z.string()).optional(),
|
|
34
35
|
cursor: z.string().optional(),
|
|
35
36
|
important: z.string().optional(),
|
|
36
37
|
limit: z.string().optional(),
|
|
37
38
|
search: z.string().optional(),
|
|
38
|
-
toolkits: z.array(z.string()).optional()
|
|
39
|
-
tools: z.array(z.string()).optional()
|
|
39
|
+
toolkits: z.array(z.string()).optional()
|
|
40
40
|
});
|
|
41
41
|
var CustomAuthParamsSchema = z.object({
|
|
42
42
|
baseURL: z.string().optional(),
|
|
@@ -68,11 +68,212 @@ var ToolExecuteResponseSchema = z.object({
|
|
|
68
68
|
|
|
69
69
|
// src/models/CustomTools.ts
|
|
70
70
|
import zodToJsonSchema from "zod-to-json-schema";
|
|
71
|
+
|
|
72
|
+
// src/utils/env.ts
|
|
73
|
+
var getEnvVariable = (name, defaultValue = void 0) => {
|
|
74
|
+
try {
|
|
75
|
+
return process.env[name] || defaultValue;
|
|
76
|
+
} catch (_e) {
|
|
77
|
+
logger_default.error(`Error getting environment variable ${name}:`, _e);
|
|
78
|
+
return defaultValue;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// src/utils/logger.ts
|
|
83
|
+
var LOG_LEVELS = {
|
|
84
|
+
silent: -1,
|
|
85
|
+
// No logs
|
|
86
|
+
error: 0,
|
|
87
|
+
// Highest priority - critical errors
|
|
88
|
+
warn: 1,
|
|
89
|
+
// Warning messages
|
|
90
|
+
info: 2,
|
|
91
|
+
// General information
|
|
92
|
+
debug: 3
|
|
93
|
+
// Debug information
|
|
94
|
+
};
|
|
95
|
+
var getLogLevel = () => {
|
|
96
|
+
const envLevel = getEnvVariable("COMPOSIO_LOGGING_LEVEL", "info")?.toLowerCase();
|
|
97
|
+
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
98
|
+
};
|
|
99
|
+
var Logger = class {
|
|
100
|
+
level;
|
|
101
|
+
includeTimestamp;
|
|
102
|
+
console;
|
|
103
|
+
constructor(options = {}) {
|
|
104
|
+
this.level = options.level ?? getLogLevel();
|
|
105
|
+
this.includeTimestamp = options.includeTimestamp ?? true;
|
|
106
|
+
this.console = console;
|
|
107
|
+
}
|
|
108
|
+
formatMessage(args) {
|
|
109
|
+
const formattedArgs = args.map((arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)).join("\n");
|
|
110
|
+
if (!this.includeTimestamp) {
|
|
111
|
+
return formattedArgs;
|
|
112
|
+
}
|
|
113
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
114
|
+
return `${timestamp} - ${formattedArgs}`;
|
|
115
|
+
}
|
|
116
|
+
shouldLog(level) {
|
|
117
|
+
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
118
|
+
}
|
|
119
|
+
error(...args) {
|
|
120
|
+
if (this.shouldLog("error")) {
|
|
121
|
+
this.console.error(this.formatMessage(args));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
warn(...args) {
|
|
125
|
+
if (this.shouldLog("warn")) {
|
|
126
|
+
this.console.warn(this.formatMessage(args));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
info(...args) {
|
|
130
|
+
if (this.shouldLog("info")) {
|
|
131
|
+
this.console.info(this.formatMessage(args));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
debug(...args) {
|
|
135
|
+
if (this.shouldLog("debug")) {
|
|
136
|
+
this.console.debug(this.formatMessage(args));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var logger = new Logger();
|
|
141
|
+
var logger_default = logger;
|
|
142
|
+
|
|
143
|
+
// src/errors/ComposioError.ts
|
|
144
|
+
var ComposioError = class extends Error {
|
|
145
|
+
name = "ComposioError";
|
|
146
|
+
code;
|
|
147
|
+
statusCode;
|
|
148
|
+
cause;
|
|
149
|
+
meta;
|
|
150
|
+
possibleFixes;
|
|
151
|
+
constructor(message, options = {}) {
|
|
152
|
+
super(message);
|
|
153
|
+
this.code = options.code;
|
|
154
|
+
this.statusCode = options.statusCode;
|
|
155
|
+
this.cause = options.cause;
|
|
156
|
+
this.meta = options.meta;
|
|
157
|
+
this.possibleFixes = options.possibleFixes;
|
|
158
|
+
if (Error.captureStackTrace) {
|
|
159
|
+
Error.captureStackTrace(this, this.constructor);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
toJSON() {
|
|
163
|
+
return {
|
|
164
|
+
name: this.name,
|
|
165
|
+
message: this.message,
|
|
166
|
+
code: this.code,
|
|
167
|
+
statusCode: this.statusCode,
|
|
168
|
+
cause: this.cause instanceof Error ? this.cause.message : this.cause,
|
|
169
|
+
meta: this.meta,
|
|
170
|
+
possibleFixes: this.possibleFixes?.length ? this.possibleFixes.join("\n") : void 0
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// src/errors/ToolErrors.ts
|
|
176
|
+
var ToolErrorCodes = {
|
|
177
|
+
TOOLSET_NOT_DEFINED: "TOOLSET_NOT_DEFINED",
|
|
178
|
+
TOOL_NOT_FOUND: "TOOL_NOT_FOUND",
|
|
179
|
+
INVALID_MODIFIER: "INVALID_MODIFIER",
|
|
180
|
+
CUSTOM_TOOLS_NOT_INITIALIZED: "CUSTOM_TOOLS_NOT_INITIALIZED",
|
|
181
|
+
TOOL_EXECUTION_ERROR: "TOOL_EXECUTION_ERROR",
|
|
182
|
+
INVALID_EXECUTE_FUNCTION: "INVALID_EXECUTE_FUNCTION"
|
|
183
|
+
};
|
|
184
|
+
var ComposioToolsetNotDefinedError = class extends ComposioError {
|
|
185
|
+
constructor(message = "Toolset not defined", meta = {}) {
|
|
186
|
+
super(message, {
|
|
187
|
+
code: ToolErrorCodes.TOOLSET_NOT_DEFINED,
|
|
188
|
+
meta,
|
|
189
|
+
possibleFixes: [
|
|
190
|
+
"Ensure that the toolset is defined in the Composio project and passed into the tool instance"
|
|
191
|
+
]
|
|
192
|
+
});
|
|
193
|
+
this.name = "ComposioToolsetNotDefinedError";
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
var ComposioToolNotFoundError = class extends ComposioError {
|
|
197
|
+
constructor(message = "Tool not found", meta = {}) {
|
|
198
|
+
super(message, {
|
|
199
|
+
code: ToolErrorCodes.TOOL_NOT_FOUND,
|
|
200
|
+
meta,
|
|
201
|
+
possibleFixes: ["Ensure the tool slug is correct and exists in the Composio project"]
|
|
202
|
+
});
|
|
203
|
+
this.name = "ComposioToolNotFoundError";
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var ComposioInvalidModifierError = class extends ComposioError {
|
|
207
|
+
constructor(message = "Invalid modifier", meta = {}) {
|
|
208
|
+
super(message, {
|
|
209
|
+
code: ToolErrorCodes.INVALID_MODIFIER,
|
|
210
|
+
meta,
|
|
211
|
+
possibleFixes: ["Ensure the modifier is a function and returns a valid result"]
|
|
212
|
+
});
|
|
213
|
+
this.name = "ComposioInvalidModifierError";
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
var ComposioCustomToolsNotInitializedError = class extends ComposioError {
|
|
217
|
+
constructor(message = "Custom tools not initialized", meta = {}) {
|
|
218
|
+
super(message, {
|
|
219
|
+
code: ToolErrorCodes.CUSTOM_TOOLS_NOT_INITIALIZED,
|
|
220
|
+
meta,
|
|
221
|
+
possibleFixes: ["Ensure the custom tools class is initialized in the Tools instance"]
|
|
222
|
+
});
|
|
223
|
+
this.name = "ComposioCustomToolsNotInitializedError";
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
var ComposioToolExecutionError = class extends ComposioError {
|
|
227
|
+
error;
|
|
228
|
+
constructor(error, message = "Tool execution error", meta = {}) {
|
|
229
|
+
super(message, {
|
|
230
|
+
code: ToolErrorCodes.TOOL_EXECUTION_ERROR,
|
|
231
|
+
cause: error,
|
|
232
|
+
meta,
|
|
233
|
+
possibleFixes: ["Ensure the tool is correctly configured and the input is valid"]
|
|
234
|
+
});
|
|
235
|
+
this.error = error;
|
|
236
|
+
this.name = "ComposioToolExecutionError";
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
var ComposioInvalidExecuteFunctionError = class extends ComposioError {
|
|
240
|
+
constructor(message = "Invalid execute function", meta = {}) {
|
|
241
|
+
super(message, {
|
|
242
|
+
code: ToolErrorCodes.INVALID_EXECUTE_FUNCTION,
|
|
243
|
+
meta,
|
|
244
|
+
possibleFixes: ["Ensure the execute function is a valid function and returns a valid result"]
|
|
245
|
+
});
|
|
246
|
+
this.name = "ComposioInvalidExecuteFunctionError";
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// src/errors/ConnectedAccountsError.ts
|
|
251
|
+
var ConnectedAccountErrorCodes = {
|
|
252
|
+
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
|
|
253
|
+
};
|
|
254
|
+
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
255
|
+
constructor(message = "Connected account not found", meta = {}) {
|
|
256
|
+
super(message, {
|
|
257
|
+
code: ConnectedAccountErrorCodes.CONNECTED_ACCOUNT_NOT_FOUND,
|
|
258
|
+
statusCode: 404,
|
|
259
|
+
meta,
|
|
260
|
+
possibleFixes: [
|
|
261
|
+
"Ensure the connected account exists and is active in your Composio dashboard"
|
|
262
|
+
]
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// src/models/CustomTools.ts
|
|
71
268
|
var CustomTools = class {
|
|
72
269
|
client;
|
|
73
|
-
customToolsRegistry
|
|
270
|
+
customToolsRegistry;
|
|
74
271
|
constructor(client) {
|
|
272
|
+
if (!client) {
|
|
273
|
+
throw new ComposioError("ComposioClient is required");
|
|
274
|
+
}
|
|
75
275
|
this.client = client;
|
|
276
|
+
this.customToolsRegistry = /* @__PURE__ */ new Map();
|
|
76
277
|
}
|
|
77
278
|
/**
|
|
78
279
|
* Create a custom tool and registers it in the registry.
|
|
@@ -140,11 +341,16 @@ var CustomTools = class {
|
|
|
140
341
|
* @returns {Tool} The tool
|
|
141
342
|
*/
|
|
142
343
|
async getCustomToolBySlug(slug) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
344
|
+
if (!slug) {
|
|
345
|
+
throw new Error("Tool slug is required");
|
|
346
|
+
}
|
|
347
|
+
try {
|
|
348
|
+
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
349
|
+
return tool?.schema;
|
|
350
|
+
} catch (error) {
|
|
351
|
+
logger_default.error(`Error getting custom tool: ${error}`);
|
|
352
|
+
return void 0;
|
|
146
353
|
}
|
|
147
|
-
return tool.schema;
|
|
148
354
|
}
|
|
149
355
|
/**
|
|
150
356
|
* Get the connected account for the user and toolkit.
|
|
@@ -153,12 +359,25 @@ var CustomTools = class {
|
|
|
153
359
|
* @returns {ConnectedAccount} The connected account
|
|
154
360
|
*/
|
|
155
361
|
async getConnectedAccount(toolkitSlug, metadata) {
|
|
362
|
+
try {
|
|
363
|
+
await this.client.toolkits.retrieve(toolkitSlug);
|
|
364
|
+
} catch (error) {
|
|
365
|
+
throw new ComposioToolNotFoundError(`Toolkit with slug ${toolkitSlug} not found`, {
|
|
366
|
+
toolkitSlug,
|
|
367
|
+
error
|
|
368
|
+
});
|
|
369
|
+
}
|
|
156
370
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
157
371
|
toolkit_slug: toolkitSlug,
|
|
158
372
|
user_id: metadata.userId
|
|
159
373
|
});
|
|
160
374
|
if (!connectedAccounts.items.length) {
|
|
161
|
-
throw new
|
|
375
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
376
|
+
`No connected accounts found for toolkit ${toolkitSlug}`,
|
|
377
|
+
{
|
|
378
|
+
toolkitSlug
|
|
379
|
+
}
|
|
380
|
+
);
|
|
162
381
|
}
|
|
163
382
|
return metadata.connectedAccountId ? connectedAccounts.items.find((item) => item.id === metadata.connectedAccountId) : connectedAccounts.items[0];
|
|
164
383
|
}
|
|
@@ -172,21 +391,29 @@ var CustomTools = class {
|
|
|
172
391
|
async executeCustomTool(slug, inputParams, metadata) {
|
|
173
392
|
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
174
393
|
if (!tool) {
|
|
175
|
-
throw new
|
|
394
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`, {
|
|
395
|
+
toolSlug: slug
|
|
396
|
+
});
|
|
176
397
|
}
|
|
177
398
|
let authCredentials = {};
|
|
178
399
|
const { toolkitSlug, execute } = tool.options;
|
|
179
|
-
if (toolkitSlug) {
|
|
400
|
+
if (toolkitSlug && toolkitSlug !== "custom") {
|
|
180
401
|
const connectedAccount = await this.getConnectedAccount(toolkitSlug, metadata);
|
|
181
402
|
if (!connectedAccount) {
|
|
182
|
-
throw new
|
|
183
|
-
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}
|
|
403
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
404
|
+
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}`,
|
|
405
|
+
{
|
|
406
|
+
toolkitSlug,
|
|
407
|
+
userId: metadata.userId
|
|
408
|
+
}
|
|
184
409
|
);
|
|
185
410
|
}
|
|
186
411
|
authCredentials = connectedAccount.data?.connectionParams;
|
|
187
412
|
}
|
|
188
413
|
if (typeof execute !== "function") {
|
|
189
|
-
throw new
|
|
414
|
+
throw new ComposioInvalidExecuteFunctionError("Invalid execute function", {
|
|
415
|
+
toolSlug: slug
|
|
416
|
+
});
|
|
190
417
|
}
|
|
191
418
|
const executeToolRequest = async (data) => {
|
|
192
419
|
return this.client.tools.proxy({
|
|
@@ -202,79 +429,42 @@ var CustomTools = class {
|
|
|
202
429
|
}
|
|
203
430
|
};
|
|
204
431
|
|
|
205
|
-
// src/
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
} catch (_e) {
|
|
210
|
-
logger_default.error(`Error getting environment variable ${name}:`, _e);
|
|
211
|
-
return defaultValue;
|
|
212
|
-
}
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
// src/utils/logger.ts
|
|
216
|
-
var LOG_LEVELS = {
|
|
217
|
-
silent: -1,
|
|
218
|
-
// No logs
|
|
219
|
-
error: 0,
|
|
220
|
-
// Highest priority - critical errors
|
|
221
|
-
warn: 1,
|
|
222
|
-
// Warning messages
|
|
223
|
-
info: 2,
|
|
224
|
-
// General information
|
|
225
|
-
debug: 3
|
|
226
|
-
// Debug information
|
|
227
|
-
};
|
|
228
|
-
var getLogLevel = () => {
|
|
229
|
-
const envLevel = getEnvVariable(
|
|
230
|
-
"COMPOSIO_LOGGING_LEVEL",
|
|
231
|
-
"info"
|
|
232
|
-
)?.toLowerCase();
|
|
233
|
-
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
432
|
+
// src/errors/ValidationError.ts
|
|
433
|
+
import { ZodError } from "zod";
|
|
434
|
+
var ValidationErrorCodes = {
|
|
435
|
+
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
234
436
|
};
|
|
235
|
-
var
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
250
|
-
return `${timestamp} - ${formattedArgs}`;
|
|
251
|
-
}
|
|
252
|
-
shouldLog(level) {
|
|
253
|
-
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
254
|
-
}
|
|
255
|
-
error(...args) {
|
|
256
|
-
if (this.shouldLog("error")) {
|
|
257
|
-
this.console.error(this.formatMessage(args));
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
warn(...args) {
|
|
261
|
-
if (this.shouldLog("warn")) {
|
|
262
|
-
this.console.warn(this.formatMessage(args));
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
info(...args) {
|
|
266
|
-
if (this.shouldLog("info")) {
|
|
267
|
-
this.console.info(this.formatMessage(args));
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
debug(...args) {
|
|
271
|
-
if (this.shouldLog("debug")) {
|
|
272
|
-
this.console.debug(this.formatMessage(args));
|
|
437
|
+
var ValidationError = class extends ComposioError {
|
|
438
|
+
zodError;
|
|
439
|
+
constructor(zodError, message = "Input validation failed") {
|
|
440
|
+
let zodErrorInstance;
|
|
441
|
+
if (!(zodError instanceof ZodError)) {
|
|
442
|
+
zodErrorInstance = new ZodError([
|
|
443
|
+
{
|
|
444
|
+
path: [],
|
|
445
|
+
message: "Invalid input",
|
|
446
|
+
code: "custom"
|
|
447
|
+
}
|
|
448
|
+
]);
|
|
449
|
+
} else {
|
|
450
|
+
zodErrorInstance = zodError;
|
|
273
451
|
}
|
|
452
|
+
super(message, {
|
|
453
|
+
code: ValidationErrorCodes.VALIDATION_ERROR,
|
|
454
|
+
meta: {
|
|
455
|
+
issues: JSON.stringify(
|
|
456
|
+
zodErrorInstance.issues.map((issue) => ({
|
|
457
|
+
path: issue.path.join("."),
|
|
458
|
+
message: issue.message,
|
|
459
|
+
code: issue.code
|
|
460
|
+
}))
|
|
461
|
+
)
|
|
462
|
+
},
|
|
463
|
+
cause: zodErrorInstance
|
|
464
|
+
});
|
|
465
|
+
this.zodError = zodErrorInstance;
|
|
274
466
|
}
|
|
275
467
|
};
|
|
276
|
-
var logger = new Logger();
|
|
277
|
-
var logger_default = logger;
|
|
278
468
|
|
|
279
469
|
// src/models/Tools.ts
|
|
280
470
|
var Tools = class {
|
|
@@ -282,9 +472,18 @@ var Tools = class {
|
|
|
282
472
|
customTools;
|
|
283
473
|
toolset;
|
|
284
474
|
constructor(client, toolset) {
|
|
475
|
+
if (!client) {
|
|
476
|
+
throw new Error("ComposioClient is required");
|
|
477
|
+
}
|
|
478
|
+
if (!toolset) {
|
|
479
|
+
throw new ComposioToolsetNotDefinedError("Toolset not passed into Tools instance");
|
|
480
|
+
}
|
|
285
481
|
this.client = client;
|
|
286
482
|
this.customTools = new CustomTools(client);
|
|
287
483
|
this.toolset = toolset;
|
|
484
|
+
this.execute = this.execute.bind(this);
|
|
485
|
+
this.getComposioToolBySlug = this.getComposioToolBySlug.bind(this);
|
|
486
|
+
this.getComposioTools = this.getComposioTools.bind(this);
|
|
288
487
|
}
|
|
289
488
|
/**
|
|
290
489
|
* Transform the tool cases
|
|
@@ -393,15 +592,15 @@ var Tools = class {
|
|
|
393
592
|
async getComposioTools(userId, query = {}, modifier) {
|
|
394
593
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
395
594
|
if (queryParams.error) {
|
|
396
|
-
throw new
|
|
595
|
+
throw new ValidationError(queryParams.error);
|
|
397
596
|
}
|
|
398
597
|
const tools = await this.client.tools.list({
|
|
598
|
+
tool_slugs: queryParams.data.tools?.join(","),
|
|
599
|
+
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
399
600
|
cursor: queryParams.data.cursor,
|
|
400
601
|
important: queryParams.data.important,
|
|
401
602
|
limit: queryParams.data.limit,
|
|
402
|
-
search: queryParams.data.search
|
|
403
|
-
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
404
|
-
tool_slugs: queryParams.data.tools?.join(",")
|
|
603
|
+
search: queryParams.data.search
|
|
405
604
|
});
|
|
406
605
|
if (!tools) {
|
|
407
606
|
return [];
|
|
@@ -414,10 +613,10 @@ var Tools = class {
|
|
|
414
613
|
if (modifier) {
|
|
415
614
|
if (typeof modifier === "function") {
|
|
416
615
|
modifiedTools = modifiedTools.map((tool) => {
|
|
417
|
-
return modifier(tool.slug, tool);
|
|
616
|
+
return modifier(tool.slug, tool.toolkit?.slug || "unkown", tool);
|
|
418
617
|
});
|
|
419
618
|
} else {
|
|
420
|
-
throw new
|
|
619
|
+
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
421
620
|
}
|
|
422
621
|
}
|
|
423
622
|
return modifiedTools;
|
|
@@ -434,14 +633,14 @@ var Tools = class {
|
|
|
434
633
|
}
|
|
435
634
|
const tool = await this.client.tools.retrieve(slug);
|
|
436
635
|
if (!tool) {
|
|
437
|
-
throw new
|
|
636
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
438
637
|
}
|
|
439
638
|
let modifiedToool = this.transformToolCases(tool);
|
|
440
639
|
if (modifier) {
|
|
441
640
|
if (typeof modifier === "function") {
|
|
442
|
-
modifiedToool = modifier(slug, modifiedToool);
|
|
641
|
+
modifiedToool = modifier(slug, modifiedToool.toolkit?.slug || "unkown", modifiedToool);
|
|
443
642
|
} else {
|
|
444
|
-
throw new
|
|
643
|
+
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
445
644
|
}
|
|
446
645
|
}
|
|
447
646
|
return modifiedToool;
|
|
@@ -476,6 +675,66 @@ var Tools = class {
|
|
|
476
675
|
};
|
|
477
676
|
return executeToolFn;
|
|
478
677
|
}
|
|
678
|
+
async handleCustomToolExecution(tool, body, modifiers) {
|
|
679
|
+
if (modifiers?.beforeToolExecute) {
|
|
680
|
+
if (typeof modifiers.beforeToolExecute === "function") {
|
|
681
|
+
body = modifiers.beforeToolExecute(tool.slug, "unkown", body);
|
|
682
|
+
} else {
|
|
683
|
+
throw new ComposioInvalidModifierError(
|
|
684
|
+
"Invalid beforeToolExecute modifier. Not a function."
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
let result = await this.customTools.executeCustomTool(tool.slug, body, {
|
|
689
|
+
userId: body.userId || "default",
|
|
690
|
+
connectedAccountId: body.connectedAccountId
|
|
691
|
+
});
|
|
692
|
+
if (modifiers?.afterToolExecute) {
|
|
693
|
+
if (typeof modifiers.afterToolExecute === "function") {
|
|
694
|
+
result = modifiers.afterToolExecute(tool.slug, "unkown", result);
|
|
695
|
+
} else {
|
|
696
|
+
throw new ComposioInvalidModifierError(
|
|
697
|
+
"Invalid afterToolExecute modifier. Not a function."
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
return result;
|
|
702
|
+
}
|
|
703
|
+
async handleComposioToolExecution(tool, body, modifiers) {
|
|
704
|
+
if (modifiers?.beforeToolExecute) {
|
|
705
|
+
if (typeof modifiers.beforeToolExecute === "function") {
|
|
706
|
+
body = modifiers.beforeToolExecute(tool.slug, tool.toolkit?.slug || "unkown", body);
|
|
707
|
+
} else {
|
|
708
|
+
throw new ComposioInvalidModifierError(
|
|
709
|
+
"Invalid beforeToolExecute modifier. Not a function."
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
let connectedAccountId = body.connectedAccountId;
|
|
714
|
+
if (!connectedAccountId) {
|
|
715
|
+
connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, tool.slug) || void 0;
|
|
716
|
+
}
|
|
717
|
+
let result = await this.client.tools.execute(tool.slug, {
|
|
718
|
+
allow_tracing: body.allowTracing,
|
|
719
|
+
connected_account_id: body.connectedAccountId,
|
|
720
|
+
custom_auth_params: body.customAuthParams,
|
|
721
|
+
arguments: body.arguments,
|
|
722
|
+
entity_id: body.userId,
|
|
723
|
+
version: body.version,
|
|
724
|
+
text: body.text
|
|
725
|
+
});
|
|
726
|
+
result = this.transformToolExecuteResponse(result);
|
|
727
|
+
if (modifiers?.afterToolExecute) {
|
|
728
|
+
if (typeof modifiers.afterToolExecute === "function") {
|
|
729
|
+
result = modifiers.afterToolExecute(tool.slug, tool.toolkit?.slug || "unkown", result);
|
|
730
|
+
} else {
|
|
731
|
+
throw new ComposioInvalidModifierError(
|
|
732
|
+
"Invalid afterToolExecute modifier. Not a function."
|
|
733
|
+
);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return result;
|
|
737
|
+
}
|
|
479
738
|
/**
|
|
480
739
|
* Exectes a given tool with the provided parameters.
|
|
481
740
|
*
|
|
@@ -486,44 +745,28 @@ var Tools = class {
|
|
|
486
745
|
* @returns {Promise<ToolExecuteResponse>} - The response from the tool execution
|
|
487
746
|
*/
|
|
488
747
|
async execute(slug, body, modifiers) {
|
|
489
|
-
if (
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
throw new Error("Invalid beforeToolExecute modifier. Not a function.");
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
let result;
|
|
497
|
-
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
498
|
-
if (customTool) {
|
|
499
|
-
result = await this.customTools.executeCustomTool(slug, body, {
|
|
500
|
-
userId: body.userId || "default",
|
|
501
|
-
connectedAccountId: body.connectedAccountId
|
|
502
|
-
});
|
|
503
|
-
} else {
|
|
504
|
-
let connectedAccountId = body.connectedAccountId;
|
|
505
|
-
if (!connectedAccountId) {
|
|
506
|
-
connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, slug) || void 0;
|
|
507
|
-
}
|
|
508
|
-
result = await this.client.tools.execute(slug, {
|
|
509
|
-
allow_tracing: body.allowTracing,
|
|
510
|
-
connected_account_id: body.connectedAccountId,
|
|
511
|
-
custom_auth_params: body.customAuthParams,
|
|
512
|
-
arguments: body.arguments,
|
|
513
|
-
entity_id: body.userId,
|
|
514
|
-
version: body.version,
|
|
515
|
-
text: body.text
|
|
516
|
-
});
|
|
517
|
-
result = this.transformToolExecuteResponse(result);
|
|
748
|
+
if (!this.customTools) {
|
|
749
|
+
throw new ComposioCustomToolsNotInitializedError(
|
|
750
|
+
"CustomTools not initialized. Make sure Tools class is properly constructed."
|
|
751
|
+
);
|
|
518
752
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
753
|
+
try {
|
|
754
|
+
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
755
|
+
if (customTool) {
|
|
756
|
+
return this.handleCustomToolExecution(customTool, body, modifiers);
|
|
522
757
|
} else {
|
|
523
|
-
|
|
758
|
+
const composioTool = await this.getComposioToolBySlug(body.userId, slug);
|
|
759
|
+
if (!composioTool) {
|
|
760
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
761
|
+
}
|
|
762
|
+
return this.handleComposioToolExecution(composioTool, body, modifiers);
|
|
524
763
|
}
|
|
764
|
+
} catch (error) {
|
|
765
|
+
throw new ComposioToolExecutionError(error, `Error executing tool ${slug}`, {
|
|
766
|
+
toolSlug: slug,
|
|
767
|
+
body
|
|
768
|
+
});
|
|
525
769
|
}
|
|
526
|
-
return result;
|
|
527
770
|
}
|
|
528
771
|
/**
|
|
529
772
|
* Fetches the list of all available tools in the Composio SDK.
|
|
@@ -578,16 +821,17 @@ var ToolkitsListParamsSchema = z2.object({
|
|
|
578
821
|
var ToolKitMetaSchema = z2.object({
|
|
579
822
|
categories: z2.array(
|
|
580
823
|
z2.object({
|
|
581
|
-
|
|
824
|
+
slug: z2.string(),
|
|
582
825
|
name: z2.string()
|
|
583
826
|
})
|
|
584
|
-
),
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
827
|
+
).optional(),
|
|
828
|
+
appUrl: z2.string().optional(),
|
|
829
|
+
createdAt: z2.string().optional(),
|
|
830
|
+
description: z2.string().optional(),
|
|
831
|
+
logo: z2.string().optional(),
|
|
832
|
+
toolsCount: z2.number().optional(),
|
|
833
|
+
triggersCount: z2.number().optional(),
|
|
834
|
+
updatedAt: z2.string().optional()
|
|
591
835
|
});
|
|
592
836
|
var ToolKitItemSchema = z2.object({
|
|
593
837
|
name: z2.string(),
|
|
@@ -612,20 +856,18 @@ var ToolkitAuthFieldSchema = z2.object({
|
|
|
612
856
|
var ToolkitAuthConfigDetailsSchema = z2.object({
|
|
613
857
|
name: z2.string(),
|
|
614
858
|
mode: z2.string(),
|
|
615
|
-
fields: z2.
|
|
616
|
-
z2.object({
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
required: z2.array(ToolkitAuthFieldSchema)
|
|
624
|
-
})
|
|
859
|
+
fields: z2.object({
|
|
860
|
+
authConfigCreation: z2.object({
|
|
861
|
+
optional: z2.array(ToolkitAuthFieldSchema),
|
|
862
|
+
required: z2.array(ToolkitAuthFieldSchema)
|
|
863
|
+
}),
|
|
864
|
+
connectedAccountInitiation: z2.object({
|
|
865
|
+
optional: z2.array(ToolkitAuthFieldSchema),
|
|
866
|
+
required: z2.array(ToolkitAuthFieldSchema)
|
|
625
867
|
})
|
|
626
|
-
),
|
|
868
|
+
}),
|
|
627
869
|
proxy: z2.object({
|
|
628
|
-
|
|
870
|
+
baseUrl: z2.string()
|
|
629
871
|
})
|
|
630
872
|
});
|
|
631
873
|
var ToolkitRetrieveResponseSchema = z2.object({
|
|
@@ -647,577 +889,283 @@ var ToolkitRetrieveCategoriesResponseSchema = z2.object({
|
|
|
647
889
|
});
|
|
648
890
|
|
|
649
891
|
// src/models/Toolkits.ts
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
892
|
+
import { ZodError as ZodError3 } from "zod";
|
|
893
|
+
|
|
894
|
+
// src/types/authConfigs.types.ts
|
|
895
|
+
import { z as z3 } from "zod";
|
|
896
|
+
var AuthConfigTypes = {
|
|
897
|
+
CUSTOM: "use_custom_auth",
|
|
898
|
+
COMPOSIO_MANAGED: "use_composio_managed_auth"
|
|
899
|
+
};
|
|
900
|
+
var AuthSchemeTypes = {
|
|
901
|
+
OAUTH2: "OAUTH2",
|
|
902
|
+
OAUTH1: "OAUTH1",
|
|
903
|
+
OAUTH1A: "OAUTH1A",
|
|
904
|
+
API_KEY: "API_KEY",
|
|
905
|
+
BASIC: "BASIC",
|
|
906
|
+
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
907
|
+
BEARER_TOKEN: "BEARER_TOKEN",
|
|
908
|
+
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
909
|
+
NO_AUTH: "NO_AUTH",
|
|
910
|
+
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
911
|
+
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
912
|
+
CALCOM_AUTH: "CALCOM_AUTH",
|
|
913
|
+
SNOWFLAKE: "SNOWFLAKE"
|
|
914
|
+
};
|
|
915
|
+
var AuthSchemeEnum = z3.enum([
|
|
916
|
+
"OAUTH2",
|
|
917
|
+
"OAUTH1",
|
|
918
|
+
"OAUTH1A",
|
|
919
|
+
"API_KEY",
|
|
920
|
+
"BASIC",
|
|
921
|
+
"BILLCOM_AUTH",
|
|
922
|
+
"BEARER_TOKEN",
|
|
923
|
+
"GOOGLE_SERVICE_ACCOUNT",
|
|
924
|
+
"NO_AUTH",
|
|
925
|
+
"BASIC_WITH_JWT",
|
|
926
|
+
"COMPOSIO_LINK",
|
|
927
|
+
"CALCOM_AUTH",
|
|
928
|
+
"SNOWFLAKE"
|
|
929
|
+
]);
|
|
930
|
+
var CreateCustomAuthConfigParamsSchema = z3.object({
|
|
931
|
+
type: z3.literal("use_custom_auth"),
|
|
932
|
+
name: z3.string().optional(),
|
|
933
|
+
credentials: z3.record(z3.string(), z3.union([z3.string(), z3.number(), z3.boolean()])),
|
|
934
|
+
authScheme: AuthSchemeEnum
|
|
935
|
+
});
|
|
936
|
+
var CreateComposioManagedAuthConfigParamsSchema = z3.object({
|
|
937
|
+
type: z3.literal("use_composio_managed_auth"),
|
|
938
|
+
name: z3.string().optional(),
|
|
939
|
+
credentials: z3.record(z3.string(), z3.union([z3.string(), z3.number(), z3.boolean()])).optional()
|
|
940
|
+
});
|
|
941
|
+
var CreateAuthConfigParamsSchema = z3.discriminatedUnion("type", [
|
|
942
|
+
CreateCustomAuthConfigParamsSchema,
|
|
943
|
+
CreateComposioManagedAuthConfigParamsSchema
|
|
944
|
+
]);
|
|
945
|
+
var CreateAuthConfigResponseSchema = z3.object({
|
|
946
|
+
id: z3.string(),
|
|
947
|
+
authScheme: z3.string(),
|
|
948
|
+
isComposioManaged: z3.boolean(),
|
|
949
|
+
toolkit: z3.string()
|
|
950
|
+
});
|
|
951
|
+
var AuthConfigRetrieveResponseSchema = z3.object({
|
|
952
|
+
id: z3.string(),
|
|
953
|
+
name: z3.string(),
|
|
954
|
+
toolkit: z3.object({
|
|
955
|
+
logo: z3.string(),
|
|
956
|
+
slug: z3.string()
|
|
957
|
+
}),
|
|
958
|
+
noOfConnections: z3.number(),
|
|
959
|
+
status: z3.enum(["ENABLED", "DISABLED"]),
|
|
960
|
+
uuid: z3.string(),
|
|
961
|
+
authScheme: AuthSchemeEnum.optional(),
|
|
962
|
+
credentials: z3.record(z3.string(), z3.union([z3.string(), z3.number(), z3.boolean()])),
|
|
963
|
+
expectedInputFields: z3.array(z3.unknown()).optional(),
|
|
964
|
+
isComposioManaged: z3.boolean().optional(),
|
|
965
|
+
createdBy: z3.string().optional(),
|
|
966
|
+
createdAt: z3.string().optional(),
|
|
967
|
+
lastUpdatedAt: z3.string().optional()
|
|
968
|
+
});
|
|
969
|
+
var AuthConfigListParamsSchema = z3.object({
|
|
970
|
+
cursor: z3.string().optional(),
|
|
971
|
+
isComposioManaged: z3.boolean().optional(),
|
|
972
|
+
limit: z3.number().optional(),
|
|
973
|
+
toolkitSlug: z3.string().optional()
|
|
974
|
+
});
|
|
975
|
+
var AuthConfigListResponseSchema = z3.object({
|
|
976
|
+
items: z3.array(AuthConfigRetrieveResponseSchema),
|
|
977
|
+
nextCursor: z3.string().optional(),
|
|
978
|
+
totalPages: z3.number()
|
|
979
|
+
});
|
|
980
|
+
var AuthConfigUpdateParamsSchema = z3.object({
|
|
981
|
+
credentials: z3.record(z3.string(), z3.union([z3.string(), z3.number(), z3.boolean()]))
|
|
982
|
+
});
|
|
983
|
+
|
|
984
|
+
// src/models/AuthConfigs.ts
|
|
985
|
+
var AuthConfigs = class {
|
|
986
|
+
client;
|
|
987
|
+
constructor(client) {
|
|
988
|
+
this.client = client;
|
|
685
989
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
990
|
+
parseAuthConfigRetrieveResponse(authConfig) {
|
|
991
|
+
const result = AuthConfigRetrieveResponseSchema.safeParse({
|
|
992
|
+
id: authConfig.id,
|
|
993
|
+
name: authConfig.name,
|
|
994
|
+
noOfConnections: authConfig.no_of_connections,
|
|
995
|
+
status: authConfig.status,
|
|
996
|
+
toolkit: {
|
|
997
|
+
logo: authConfig.toolkit.logo,
|
|
998
|
+
slug: authConfig.toolkit.slug
|
|
999
|
+
},
|
|
1000
|
+
uuid: authConfig.uuid,
|
|
1001
|
+
authScheme: authConfig.auth_scheme,
|
|
1002
|
+
credentials: authConfig.credentials,
|
|
1003
|
+
expectedInputFields: authConfig.expected_input_fields,
|
|
1004
|
+
isComposioManaged: authConfig.is_composio_managed,
|
|
1005
|
+
createdBy: authConfig.created_by,
|
|
1006
|
+
createdAt: authConfig.created_at,
|
|
1007
|
+
lastUpdatedAt: authConfig.last_updated_at
|
|
702
1008
|
});
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
/**
|
|
706
|
-
* Fetches a toolkit by its Slug or a list of toolkits.
|
|
707
|
-
* This method retrieves the toolkit from the Composio API.
|
|
708
|
-
* @param arg - The ID of the toolkit to be retrieved or a list of parameters
|
|
709
|
-
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit object or a list of toolkits
|
|
710
|
-
*/
|
|
711
|
-
async get(arg) {
|
|
712
|
-
if (typeof arg === "string") {
|
|
713
|
-
return this.getToolkitBySlug(arg);
|
|
1009
|
+
if (result.error) {
|
|
1010
|
+
throw new ValidationError(result.error);
|
|
714
1011
|
}
|
|
715
|
-
return
|
|
1012
|
+
return result.data;
|
|
716
1013
|
}
|
|
717
1014
|
/**
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
* @
|
|
1015
|
+
* List all auth configs
|
|
1016
|
+
* @param {AuthConfigListParams} query - Query parameters for filtering auth configs
|
|
1017
|
+
* @param {RequestOptions} options - Request options
|
|
1018
|
+
* @returns {Promise<AuthConfigListResponse>} List of auth configs
|
|
721
1019
|
*/
|
|
722
|
-
async
|
|
723
|
-
const
|
|
724
|
-
const
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
1020
|
+
async list(query) {
|
|
1021
|
+
const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : void 0;
|
|
1022
|
+
const result = await this.client.authConfigs.list({
|
|
1023
|
+
cursor: parsedQuery?.cursor,
|
|
1024
|
+
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1025
|
+
limit: parsedQuery?.limit?.toString(),
|
|
1026
|
+
toolkit_slug: parsedQuery?.toolkitSlug
|
|
1027
|
+
});
|
|
1028
|
+
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
1029
|
+
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
732
1030
|
nextCursor: result.next_cursor,
|
|
733
1031
|
totalPages: result.total_pages
|
|
734
1032
|
});
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
};
|
|
738
|
-
|
|
739
|
-
// src/utils/pusher.ts
|
|
740
|
-
var PUSHER_KEY = process.env.CLIENT_PUSHER_KEY || "ff9f18c208855d77a152";
|
|
741
|
-
var PUSHER_CLUSTER = "mt1";
|
|
742
|
-
var PusherUtils = class _PusherUtils {
|
|
743
|
-
static pusherClient;
|
|
744
|
-
static getPusherClient(baseURL, apiKey) {
|
|
745
|
-
if (!_PusherUtils.pusherClient) {
|
|
746
|
-
const PusherClient = __require("pusher-js");
|
|
747
|
-
_PusherUtils.pusherClient = new PusherClient(PUSHER_KEY, {
|
|
748
|
-
cluster: PUSHER_CLUSTER,
|
|
749
|
-
channelAuthorization: {
|
|
750
|
-
endpoint: `${baseURL}/api/v1/client/auth/pusher_auth`,
|
|
751
|
-
headers: {
|
|
752
|
-
"x-api-key": apiKey
|
|
753
|
-
},
|
|
754
|
-
transport: "ajax"
|
|
755
|
-
}
|
|
756
|
-
});
|
|
1033
|
+
if (parsedResult.error) {
|
|
1034
|
+
throw new ValidationError(parsedResult.error);
|
|
757
1035
|
}
|
|
758
|
-
return
|
|
1036
|
+
return parsedResult.data;
|
|
759
1037
|
}
|
|
760
1038
|
/**
|
|
761
|
-
*
|
|
762
|
-
* @param {string}
|
|
763
|
-
* @param {
|
|
764
|
-
* @
|
|
765
|
-
*
|
|
1039
|
+
* Create a new auth config
|
|
1040
|
+
* @param {string} toolkit - Unique identifier of the toolkit
|
|
1041
|
+
* @param {CreateAuthConfigParams} options - Options for creating a new auth config
|
|
1042
|
+
* @returns {Promise<CreateAuthConfigResponse>} Created auth config
|
|
1043
|
+
*
|
|
1044
|
+
* @example
|
|
1045
|
+
* const authConfig = await authConfigs.create('my-toolkit', {
|
|
1046
|
+
* type: AuthConfigTypes.CUSTOM,
|
|
1047
|
+
* name: 'My Custom Auth Config',
|
|
1048
|
+
* authScheme: AuthSchemeTypes.API_KEY,
|
|
1049
|
+
* credentials: {
|
|
1050
|
+
* apiKey: '1234567890',
|
|
1051
|
+
* },
|
|
1052
|
+
* });
|
|
1053
|
+
*
|
|
1054
|
+
* @link https://docs.composio.dev/reference/auth-configs/create-auth-config
|
|
766
1055
|
*/
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
1056
|
+
async create(toolkit, options) {
|
|
1057
|
+
const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
|
|
1058
|
+
if (parsedOptions.error) {
|
|
1059
|
+
throw new ValidationError(parsedOptions.error);
|
|
1060
|
+
}
|
|
1061
|
+
const result = await this.client.authConfigs.create({
|
|
1062
|
+
toolkit: {
|
|
1063
|
+
slug: toolkit
|
|
1064
|
+
},
|
|
1065
|
+
auth_config: parsedOptions.data
|
|
1066
|
+
});
|
|
1067
|
+
const parsedResult = CreateAuthConfigResponseSchema.safeParse({
|
|
1068
|
+
id: result.auth_config.id,
|
|
1069
|
+
authScheme: result.auth_config.auth_scheme,
|
|
1070
|
+
isComposioManaged: result.auth_config.is_composio_managed,
|
|
1071
|
+
toolkit: result.toolkit.slug
|
|
1072
|
+
});
|
|
1073
|
+
if (parsedResult.error) {
|
|
1074
|
+
throw new ValidationError(parsedResult.error);
|
|
774
1075
|
}
|
|
1076
|
+
return parsedResult.data;
|
|
775
1077
|
}
|
|
776
1078
|
/**
|
|
777
|
-
*
|
|
778
|
-
* @param {string}
|
|
779
|
-
* @
|
|
1079
|
+
* Get an auth config by nanoid
|
|
1080
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1081
|
+
* @param {RequestOptions} options - Request options
|
|
1082
|
+
* @returns {Promise<AuthConfigRetrieveResponse>} Auth config details
|
|
780
1083
|
*/
|
|
781
|
-
|
|
782
|
-
|
|
1084
|
+
async get(nanoid) {
|
|
1085
|
+
const result = await this.client.authConfigs.retrieve(nanoid);
|
|
1086
|
+
return this.parseAuthConfigRetrieveResponse(result);
|
|
783
1087
|
}
|
|
784
1088
|
/**
|
|
785
|
-
*
|
|
786
|
-
* @param {
|
|
787
|
-
* @param {
|
|
788
|
-
* @param {
|
|
1089
|
+
* Update an auth config
|
|
1090
|
+
* @param {string} nanoid - Unique identifier of the auth config to update
|
|
1091
|
+
* @param {AuthConfigUpdateParams} data - Data to update
|
|
1092
|
+
* @param {RequestOptions} options - Request options
|
|
1093
|
+
* @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
|
|
789
1094
|
*/
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
const typedData = data;
|
|
795
|
-
if (!events.hasOwnProperty(typedData.id)) {
|
|
796
|
-
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
797
|
-
}
|
|
798
|
-
const ev = events[typedData.id];
|
|
799
|
-
ev.chunks[typedData.index] = typedData.chunk;
|
|
800
|
-
if (typedData.final) ev.receivedFinal = true;
|
|
801
|
-
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
802
|
-
callback(JSON.parse(ev.chunks.join("")));
|
|
803
|
-
delete events[typedData.id];
|
|
1095
|
+
async update(nanoid, data) {
|
|
1096
|
+
return this.client.authConfigs.update(nanoid, {
|
|
1097
|
+
auth_config: {
|
|
1098
|
+
credentials: data.credentials
|
|
804
1099
|
}
|
|
805
1100
|
});
|
|
806
1101
|
}
|
|
807
1102
|
/**
|
|
808
|
-
*
|
|
809
|
-
* @param {string}
|
|
810
|
-
* @param {(data: TriggerData) => void} fn - The callback function to execute when trigger data is received.
|
|
811
|
-
*/
|
|
812
|
-
static triggerSubscribe(clientId, fn) {
|
|
813
|
-
const channel = _PusherUtils.pusherClient.subscribe(
|
|
814
|
-
`private-${clientId}_triggers`
|
|
815
|
-
);
|
|
816
|
-
_PusherUtils.bindWithChunking(
|
|
817
|
-
channel,
|
|
818
|
-
"trigger_to_client",
|
|
819
|
-
fn
|
|
820
|
-
);
|
|
821
|
-
logger_default.info(
|
|
822
|
-
`Subscribed to triggers. You should start receiving events now.`
|
|
823
|
-
);
|
|
824
|
-
}
|
|
825
|
-
static triggerUnsubscribe(clientId) {
|
|
826
|
-
_PusherUtils.pusherClient.unsubscribe(`${clientId}_triggers`);
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
// src/models/Session.ts
|
|
831
|
-
var Session = class {
|
|
832
|
-
client;
|
|
833
|
-
constructor(client) {
|
|
834
|
-
this.client = client;
|
|
835
|
-
}
|
|
836
|
-
/**
|
|
837
|
-
* Get the active session info
|
|
838
|
-
* @returns {Promise<SessionGetInfoResponse>} Session info
|
|
839
|
-
*/
|
|
840
|
-
async getInfo() {
|
|
841
|
-
return this.client.auth.session.getInfo();
|
|
842
|
-
}
|
|
843
|
-
};
|
|
844
|
-
|
|
845
|
-
// src/models/Triggers.ts
|
|
846
|
-
var Triggers = class {
|
|
847
|
-
client;
|
|
848
|
-
constructor(client) {
|
|
849
|
-
this.client = client;
|
|
850
|
-
}
|
|
851
|
-
/**
|
|
852
|
-
* Fetch list of all the active triggers
|
|
853
|
-
* @returns {Promise<TriggerInstance[]>} List of trigger instances
|
|
854
|
-
*/
|
|
855
|
-
async list(query, options) {
|
|
856
|
-
return this.client.triggerInstances.listActive(query, options);
|
|
857
|
-
}
|
|
858
|
-
/**
|
|
859
|
-
* Create a new trigger instance
|
|
860
|
-
*
|
|
861
|
-
* @param {string} slug - The slug of the trigger instance
|
|
862
|
-
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
863
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
864
|
-
*/
|
|
865
|
-
async create(slug, body, options) {
|
|
866
|
-
return this.client.triggerInstances.upsert(slug, body, options);
|
|
867
|
-
}
|
|
868
|
-
/**
|
|
869
|
-
* Update an existing trigger instance
|
|
870
|
-
*
|
|
871
|
-
* @param {string} slug - The slug of the trigger instance
|
|
872
|
-
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
873
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
874
|
-
*/
|
|
875
|
-
async update(slug, body, options) {
|
|
876
|
-
return this.client.triggerInstances.upsert(slug, body, options);
|
|
877
|
-
}
|
|
878
|
-
/**
|
|
879
|
-
* Delete a trigger instance
|
|
880
|
-
*
|
|
881
|
-
* @param {string} slug - The slug of the trigger instance
|
|
882
|
-
* @returns
|
|
883
|
-
*/
|
|
884
|
-
async delete(slug) {
|
|
885
|
-
return this.client.triggerInstances.removeUpsert(slug);
|
|
886
|
-
}
|
|
887
|
-
/**
|
|
888
|
-
* Update the status of a trigger
|
|
889
|
-
*
|
|
890
|
-
* @param {TriggerStatusEnum} status - The new status of the trigger
|
|
891
|
-
* @param {TriggerInstanceUpdateStatusParams} params - The parameters to update the trigger instance
|
|
1103
|
+
* Delete an auth config
|
|
1104
|
+
* @param {string} nanoid - Unique identifier of the auth config to delete
|
|
892
1105
|
* @param {RequestOptions} options - Request options
|
|
893
|
-
* @returns {Promise<
|
|
894
|
-
*/
|
|
895
|
-
async updateStatus(status, params, options) {
|
|
896
|
-
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
897
|
-
}
|
|
898
|
-
/**
|
|
899
|
-
* Disable a trigger instance
|
|
900
|
-
*
|
|
901
|
-
* @param {string} slug - The slug of the trigger instance
|
|
902
|
-
* @param {RequestOptions options - Request options
|
|
903
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
904
|
-
*/
|
|
905
|
-
async disable(slug, options) {
|
|
906
|
-
return this.client.triggerInstances.updateStatus("disable", { slug }, options);
|
|
907
|
-
}
|
|
908
|
-
/**
|
|
909
|
-
* Enable a trigger instance
|
|
910
|
-
*
|
|
911
|
-
* @param {string} slug - The slug of the trigger instance
|
|
912
|
-
* @param {RequestOptions options - Request options
|
|
913
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1106
|
+
* @returns {Promise<AuthConfigDeleteResponse>} Response from deletion
|
|
914
1107
|
*/
|
|
915
|
-
async
|
|
916
|
-
return this.client.
|
|
1108
|
+
async delete(nanoid) {
|
|
1109
|
+
return this.client.authConfigs.delete(nanoid);
|
|
917
1110
|
}
|
|
918
1111
|
/**
|
|
919
|
-
*
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
* List all the trigger types
|
|
923
|
-
*
|
|
924
|
-
* @param {TriggersTypeListParams} query - The query parameters to filter the trigger types
|
|
1112
|
+
* Update the status of an auth config
|
|
1113
|
+
* @param {string} status - The status to update the auth config to
|
|
1114
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
925
1115
|
* @param {RequestOptions} options - Request options
|
|
926
|
-
* @returns {Promise<
|
|
1116
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
927
1117
|
*/
|
|
928
|
-
async
|
|
929
|
-
return this.client.
|
|
1118
|
+
async updateStatus(status, nanoid) {
|
|
1119
|
+
return this.client.authConfigs.updateStatus(status, { nanoid });
|
|
930
1120
|
}
|
|
931
1121
|
/**
|
|
932
|
-
*
|
|
933
|
-
*
|
|
934
|
-
* @param {
|
|
935
|
-
* @
|
|
936
|
-
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
1122
|
+
* Enable an auth config
|
|
1123
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1124
|
+
* @param {RequestOptions} options - Request options
|
|
1125
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
937
1126
|
*/
|
|
938
|
-
async
|
|
939
|
-
return this.client.
|
|
1127
|
+
async enable(nanoid) {
|
|
1128
|
+
return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
|
|
940
1129
|
}
|
|
941
1130
|
/**
|
|
942
|
-
*
|
|
943
|
-
*
|
|
944
|
-
*
|
|
945
|
-
* @
|
|
946
|
-
* @returns
|
|
1131
|
+
* Disable an auth config
|
|
1132
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1133
|
+
* @param {RequestOptions} options - Request options
|
|
1134
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
947
1135
|
*/
|
|
948
|
-
async
|
|
949
|
-
return this.client.
|
|
1136
|
+
async disable(nanoid) {
|
|
1137
|
+
return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
|
|
950
1138
|
}
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
fn(data);
|
|
968
|
-
}
|
|
1139
|
+
};
|
|
1140
|
+
|
|
1141
|
+
// src/errors/AuthConfigErrors.ts
|
|
1142
|
+
var AuthConfigErrorCodes = {
|
|
1143
|
+
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1144
|
+
};
|
|
1145
|
+
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1146
|
+
constructor(message, meta) {
|
|
1147
|
+
super(message, {
|
|
1148
|
+
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1149
|
+
cause: meta,
|
|
1150
|
+
possibleFixes: [
|
|
1151
|
+
"Check if the auth config exists",
|
|
1152
|
+
"Check if the auth config id is correct",
|
|
1153
|
+
"Check if the auth config is enabled"
|
|
1154
|
+
]
|
|
969
1155
|
});
|
|
970
|
-
|
|
971
|
-
async unsubscribe() {
|
|
972
|
-
const session = new Session(this.client);
|
|
973
|
-
const sessionInfo = await session.getInfo();
|
|
974
|
-
const clientId = sessionInfo.project?.id;
|
|
975
|
-
if (!clientId) throw new Error("Client ID not found");
|
|
976
|
-
PusherUtils.triggerUnsubscribe(clientId);
|
|
1156
|
+
this.name = "ComposioAuthConfigNotFoundError";
|
|
977
1157
|
}
|
|
978
1158
|
};
|
|
979
1159
|
|
|
980
|
-
// src/types/
|
|
981
|
-
import { z as
|
|
982
|
-
var
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
OAUTH1A: "OAUTH1A",
|
|
990
|
-
API_KEY: "API_KEY",
|
|
991
|
-
BASIC: "BASIC",
|
|
992
|
-
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
993
|
-
BEARER_TOKEN: "BEARER_TOKEN",
|
|
994
|
-
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
995
|
-
NO_AUTH: "NO_AUTH",
|
|
996
|
-
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
997
|
-
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
998
|
-
CALCOM_AUTH: "CALCOM_AUTH",
|
|
999
|
-
SNOWFLAKE: "SNOWFLAKE"
|
|
1000
|
-
};
|
|
1001
|
-
var AuthSchemeEnum = z3.enum([
|
|
1002
|
-
"OAUTH2",
|
|
1003
|
-
"OAUTH1",
|
|
1004
|
-
"OAUTH1A",
|
|
1005
|
-
"API_KEY",
|
|
1006
|
-
"BASIC",
|
|
1007
|
-
"BILLCOM_AUTH",
|
|
1008
|
-
"BEARER_TOKEN",
|
|
1009
|
-
"GOOGLE_SERVICE_ACCOUNT",
|
|
1010
|
-
"NO_AUTH",
|
|
1011
|
-
"BASIC_WITH_JWT",
|
|
1012
|
-
"COMPOSIO_LINK",
|
|
1013
|
-
"CALCOM_AUTH",
|
|
1014
|
-
"SNOWFLAKE"
|
|
1015
|
-
]);
|
|
1016
|
-
var CreateCustomAuthConfigParamsSchema = z3.object({
|
|
1017
|
-
type: z3.literal("use_custom_auth"),
|
|
1018
|
-
name: z3.string().optional(),
|
|
1019
|
-
credentials: z3.record(z3.string(), z3.union([z3.string(), z3.number(), z3.boolean()])),
|
|
1020
|
-
authScheme: AuthSchemeEnum
|
|
1021
|
-
});
|
|
1022
|
-
var CreateComposioManagedAuthConfigParamsSchema = z3.object({
|
|
1023
|
-
type: z3.literal("use_composio_managed_auth"),
|
|
1024
|
-
name: z3.string().optional(),
|
|
1025
|
-
credentials: z3.record(z3.string(), z3.union([z3.string(), z3.number(), z3.boolean()])).optional()
|
|
1026
|
-
});
|
|
1027
|
-
var CreateAuthConfigParamsSchema = z3.discriminatedUnion("type", [
|
|
1028
|
-
CreateCustomAuthConfigParamsSchema,
|
|
1029
|
-
CreateComposioManagedAuthConfigParamsSchema
|
|
1030
|
-
]);
|
|
1031
|
-
var CreateAuthConfigResponseSchema = z3.object({
|
|
1032
|
-
id: z3.string(),
|
|
1033
|
-
authScheme: z3.string(),
|
|
1034
|
-
isComposioManaged: z3.boolean(),
|
|
1035
|
-
toolkit: z3.string()
|
|
1036
|
-
});
|
|
1037
|
-
var AuthConfigRetrieveResponseSchema = z3.object({
|
|
1038
|
-
id: z3.string(),
|
|
1039
|
-
name: z3.string(),
|
|
1040
|
-
toolkit: z3.object({
|
|
1041
|
-
logo: z3.string(),
|
|
1042
|
-
slug: z3.string()
|
|
1043
|
-
}),
|
|
1044
|
-
noOfConnections: z3.number(),
|
|
1045
|
-
status: z3.enum(["ENABLED", "DISABLED"]),
|
|
1046
|
-
uuid: z3.string(),
|
|
1047
|
-
authScheme: AuthSchemeEnum.optional(),
|
|
1048
|
-
credentials: z3.record(z3.string(), z3.union([z3.string(), z3.number(), z3.boolean()])),
|
|
1049
|
-
expectedInputFields: z3.array(z3.unknown()).optional(),
|
|
1050
|
-
isComposioManaged: z3.boolean().optional(),
|
|
1051
|
-
createdBy: z3.string().optional(),
|
|
1052
|
-
createdAt: z3.string().optional(),
|
|
1053
|
-
lastUpdatedAt: z3.string().optional()
|
|
1054
|
-
});
|
|
1055
|
-
var AuthConfigListParamsSchema = z3.object({
|
|
1056
|
-
cursor: z3.string().optional(),
|
|
1057
|
-
isComposioManaged: z3.boolean().optional(),
|
|
1058
|
-
limit: z3.number().optional(),
|
|
1059
|
-
toolkitSlug: z3.string().optional()
|
|
1060
|
-
});
|
|
1061
|
-
var AuthConfigListResponseSchema = z3.object({
|
|
1062
|
-
items: z3.array(AuthConfigRetrieveResponseSchema),
|
|
1063
|
-
nextCursor: z3.string().optional(),
|
|
1064
|
-
totalPages: z3.number()
|
|
1065
|
-
});
|
|
1066
|
-
var AuthConfigUpdateParamsSchema = z3.object({
|
|
1067
|
-
credentials: z3.record(z3.string(), z3.union([z3.string(), z3.number(), z3.boolean()]))
|
|
1068
|
-
});
|
|
1069
|
-
|
|
1070
|
-
// src/models/AuthConfigs.ts
|
|
1071
|
-
var AuthConfigs = class {
|
|
1072
|
-
client;
|
|
1073
|
-
constructor(client) {
|
|
1074
|
-
this.client = client;
|
|
1075
|
-
}
|
|
1076
|
-
parseAuthConfigRetrieveResponse(authConfig) {
|
|
1077
|
-
return AuthConfigRetrieveResponseSchema.parse({
|
|
1078
|
-
id: authConfig.id,
|
|
1079
|
-
name: authConfig.name,
|
|
1080
|
-
noOfConnections: authConfig.no_of_connections,
|
|
1081
|
-
status: authConfig.status,
|
|
1082
|
-
toolkit: {
|
|
1083
|
-
logo: authConfig.toolkit.logo,
|
|
1084
|
-
slug: authConfig.toolkit.slug
|
|
1085
|
-
},
|
|
1086
|
-
uuid: authConfig.uuid,
|
|
1087
|
-
authScheme: authConfig.auth_scheme,
|
|
1088
|
-
credentials: authConfig.credentials,
|
|
1089
|
-
expectedInputFields: authConfig.expected_input_fields,
|
|
1090
|
-
isComposioManaged: authConfig.is_composio_managed,
|
|
1091
|
-
createdBy: authConfig.created_by,
|
|
1092
|
-
createdAt: authConfig.created_at,
|
|
1093
|
-
lastUpdatedAt: authConfig.last_updated_at
|
|
1094
|
-
});
|
|
1095
|
-
}
|
|
1096
|
-
/**
|
|
1097
|
-
* List all auth configs
|
|
1098
|
-
* @param {AuthConfigListParams} query - Query parameters for filtering auth configs
|
|
1099
|
-
* @param {RequestOptions} options - Request options
|
|
1100
|
-
* @returns {Promise<AuthConfigListResponse>} List of auth configs
|
|
1101
|
-
*/
|
|
1102
|
-
async list(query) {
|
|
1103
|
-
const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : void 0;
|
|
1104
|
-
const result = await this.client.authConfigs.list({
|
|
1105
|
-
cursor: parsedQuery?.cursor,
|
|
1106
|
-
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1107
|
-
limit: parsedQuery?.limit?.toString(),
|
|
1108
|
-
toolkit_slug: parsedQuery?.toolkitSlug
|
|
1109
|
-
});
|
|
1110
|
-
return AuthConfigListResponseSchema.parse({
|
|
1111
|
-
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
1112
|
-
nextCursor: result.next_cursor,
|
|
1113
|
-
totalPages: result.total_pages
|
|
1114
|
-
});
|
|
1115
|
-
}
|
|
1116
|
-
/**
|
|
1117
|
-
* Create a new auth config
|
|
1118
|
-
* @param {string} toolkit - Unique identifier of the toolkit
|
|
1119
|
-
* @param {CreateAuthConfigParams} options - Options for creating a new auth config
|
|
1120
|
-
* @returns {Promise<CreateAuthConfigResponse>} Created auth config
|
|
1121
|
-
*
|
|
1122
|
-
* @example
|
|
1123
|
-
* const authConfig = await authConfigs.create('my-toolkit', {
|
|
1124
|
-
* type: AuthConfigTypes.CUSTOM,
|
|
1125
|
-
* name: 'My Custom Auth Config',
|
|
1126
|
-
* authScheme: AuthSchemeTypes.API_KEY,
|
|
1127
|
-
* credentials: {
|
|
1128
|
-
* apiKey: '1234567890',
|
|
1129
|
-
* },
|
|
1130
|
-
* });
|
|
1131
|
-
*
|
|
1132
|
-
* @link https://docs.composio.dev/reference/auth-configs/create-auth-config
|
|
1133
|
-
*/
|
|
1134
|
-
async create(toolkit, options) {
|
|
1135
|
-
const parsedOptions = CreateAuthConfigParamsSchema.parse(options);
|
|
1136
|
-
const result = await this.client.authConfigs.create({
|
|
1137
|
-
toolkit: {
|
|
1138
|
-
slug: toolkit
|
|
1139
|
-
},
|
|
1140
|
-
auth_config: parsedOptions
|
|
1141
|
-
});
|
|
1142
|
-
return CreateAuthConfigResponseSchema.parse({
|
|
1143
|
-
id: result.auth_config.id,
|
|
1144
|
-
authScheme: result.auth_config.auth_scheme,
|
|
1145
|
-
isComposioManaged: result.auth_config.is_composio_managed,
|
|
1146
|
-
toolkit: result.toolkit.slug
|
|
1147
|
-
});
|
|
1148
|
-
}
|
|
1149
|
-
/**
|
|
1150
|
-
* Get an auth config by nanoid
|
|
1151
|
-
* @param {string} nanoid - Unique identifier of the auth config
|
|
1152
|
-
* @param {RequestOptions} options - Request options
|
|
1153
|
-
* @returns {Promise<AuthConfigRetrieveResponse>} Auth config details
|
|
1154
|
-
*/
|
|
1155
|
-
async get(nanoid) {
|
|
1156
|
-
const result = await this.client.authConfigs.retrieve(nanoid);
|
|
1157
|
-
return this.parseAuthConfigRetrieveResponse(result);
|
|
1158
|
-
}
|
|
1159
|
-
/**
|
|
1160
|
-
* Update an auth config
|
|
1161
|
-
* @param {string} nanoid - Unique identifier of the auth config to update
|
|
1162
|
-
* @param {AuthConfigUpdateParams} data - Data to update
|
|
1163
|
-
* @param {RequestOptions} options - Request options
|
|
1164
|
-
* @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
|
|
1165
|
-
*/
|
|
1166
|
-
async update(nanoid, data) {
|
|
1167
|
-
return this.client.authConfigs.update(nanoid, {
|
|
1168
|
-
auth_config: {
|
|
1169
|
-
credentials: data.credentials
|
|
1170
|
-
}
|
|
1171
|
-
});
|
|
1172
|
-
}
|
|
1173
|
-
/**
|
|
1174
|
-
* Delete an auth config
|
|
1175
|
-
* @param {string} nanoid - Unique identifier of the auth config to delete
|
|
1176
|
-
* @param {RequestOptions} options - Request options
|
|
1177
|
-
* @returns {Promise<AuthConfigDeleteResponse>} Response from deletion
|
|
1178
|
-
*/
|
|
1179
|
-
async delete(nanoid) {
|
|
1180
|
-
return this.client.authConfigs.delete(nanoid);
|
|
1181
|
-
}
|
|
1182
|
-
/**
|
|
1183
|
-
* Update the status of an auth config
|
|
1184
|
-
* @param {string} status - The status to update the auth config to
|
|
1185
|
-
* @param {string} nanoid - Unique identifier of the auth config
|
|
1186
|
-
* @param {RequestOptions} options - Request options
|
|
1187
|
-
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
1188
|
-
*/
|
|
1189
|
-
async updateStatus(status, nanoid) {
|
|
1190
|
-
return this.client.authConfigs.updateStatus(status, { nanoid });
|
|
1191
|
-
}
|
|
1192
|
-
/**
|
|
1193
|
-
* Enable an auth config
|
|
1194
|
-
* @param {string} nanoid - Unique identifier of the auth config
|
|
1195
|
-
* @param {RequestOptions} options - Request options
|
|
1196
|
-
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
1197
|
-
*/
|
|
1198
|
-
async enable(nanoid) {
|
|
1199
|
-
return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
|
|
1200
|
-
}
|
|
1201
|
-
/**
|
|
1202
|
-
* Disable an auth config
|
|
1203
|
-
* @param {string} nanoid - Unique identifier of the auth config
|
|
1204
|
-
* @param {RequestOptions} options - Request options
|
|
1205
|
-
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
1206
|
-
*/
|
|
1207
|
-
async disable(nanoid) {
|
|
1208
|
-
return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
|
|
1209
|
-
}
|
|
1210
|
-
};
|
|
1211
|
-
|
|
1212
|
-
// src/types/connectedAccounts.types.ts
|
|
1213
|
-
import { z as z4 } from "zod";
|
|
1214
|
-
var ConnectedAccountStatuses = {
|
|
1215
|
-
ACTIVE: "ACTIVE",
|
|
1216
|
-
INACTIVE: "INACTIVE",
|
|
1217
|
-
PENDING: "DELETED",
|
|
1218
|
-
INITIATED: "INITIATED",
|
|
1219
|
-
EXPIRED: "EXPIRED",
|
|
1220
|
-
FAILED: "FAILED"
|
|
1160
|
+
// src/types/connectedAccounts.types.ts
|
|
1161
|
+
import { z as z4 } from "zod";
|
|
1162
|
+
var ConnectedAccountStatuses = {
|
|
1163
|
+
ACTIVE: "ACTIVE",
|
|
1164
|
+
INACTIVE: "INACTIVE",
|
|
1165
|
+
PENDING: "DELETED",
|
|
1166
|
+
INITIATED: "INITIATED",
|
|
1167
|
+
EXPIRED: "EXPIRED",
|
|
1168
|
+
FAILED: "FAILED"
|
|
1221
1169
|
};
|
|
1222
1170
|
var ConnectedAccountStatusSchema = z4.enum([
|
|
1223
1171
|
ConnectedAccountStatuses.ACTIVE,
|
|
@@ -1310,180 +1258,590 @@ var ConnectedAccountRetrieveResponseSchema = z4.object({
|
|
|
1310
1258
|
});
|
|
1311
1259
|
|
|
1312
1260
|
// src/models/ConnectionRequest.ts
|
|
1313
|
-
import { ZodError } from "zod";
|
|
1261
|
+
import { ZodError as ZodError2 } from "zod";
|
|
1262
|
+
|
|
1263
|
+
// src/errors/ConnectionRequestError.ts
|
|
1264
|
+
var ConnectionRequestErrorCodes = {
|
|
1265
|
+
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT"
|
|
1266
|
+
};
|
|
1267
|
+
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1268
|
+
constructor(message = "Connection request timed out", meta = {}) {
|
|
1269
|
+
super(message, {
|
|
1270
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
|
|
1271
|
+
meta
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1274
|
+
};
|
|
1275
|
+
|
|
1276
|
+
// src/models/ConnectionRequest.ts
|
|
1314
1277
|
var ConnectionRequest = class {
|
|
1315
1278
|
client;
|
|
1316
1279
|
connectedAccountId;
|
|
1317
1280
|
connectedAccountStatus;
|
|
1318
|
-
|
|
1281
|
+
redirectUrl;
|
|
1282
|
+
constructor(client, connectedAccountId, connectedAccountStatus, redirectUrl) {
|
|
1319
1283
|
this.client = client;
|
|
1320
1284
|
this.connectedAccountId = connectedAccountId;
|
|
1321
1285
|
this.connectedAccountStatus = connectedAccountStatus;
|
|
1286
|
+
this.redirectUrl = redirectUrl;
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Transform the response from the Composio API to the SDK format
|
|
1290
|
+
* @param response
|
|
1291
|
+
* @returns
|
|
1292
|
+
*/
|
|
1293
|
+
async transformResponse(response) {
|
|
1294
|
+
try {
|
|
1295
|
+
const parsedResponse = ConnectedAccountRetrieveResponseSchema.parse({
|
|
1296
|
+
...response,
|
|
1297
|
+
userId: response.user_id,
|
|
1298
|
+
// Add the missing userId property
|
|
1299
|
+
authConfig: {
|
|
1300
|
+
...response.auth_config,
|
|
1301
|
+
authScheme: response.auth_config.auth_scheme,
|
|
1302
|
+
isComposioManaged: response.auth_config.is_composio_managed,
|
|
1303
|
+
isDisabled: response.auth_config.is_disabled
|
|
1304
|
+
},
|
|
1305
|
+
statusReason: response.status_reason,
|
|
1306
|
+
isDisabled: response.is_disabled,
|
|
1307
|
+
createdAt: response.created_at,
|
|
1308
|
+
updatedAt: response.updated_at,
|
|
1309
|
+
testRequestEndpoint: response.test_request_endpoint
|
|
1310
|
+
});
|
|
1311
|
+
return parsedResponse;
|
|
1312
|
+
} catch (error) {
|
|
1313
|
+
logger_default.error("Error transforming response", error);
|
|
1314
|
+
if (error instanceof ZodError2) {
|
|
1315
|
+
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1316
|
+
}
|
|
1317
|
+
throw error;
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* Wait for the connection to be established.
|
|
1322
|
+
* The function will poll the Composio API every second until the connection is established or the timeout is reached.
|
|
1323
|
+
* @param {number} timeout - The time in milliseconds to wait for the connection to be established. Default is 30 seconds.
|
|
1324
|
+
* @returns
|
|
1325
|
+
*/
|
|
1326
|
+
async waitForConnection(timeout = 6e4) {
|
|
1327
|
+
if (this.connectedAccountStatus === ConnectedAccountStatuses.ACTIVE) {
|
|
1328
|
+
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1329
|
+
return Promise.resolve(this.transformResponse(response));
|
|
1330
|
+
}
|
|
1331
|
+
return new Promise((resolve, reject) => {
|
|
1332
|
+
const interval = setInterval(async () => {
|
|
1333
|
+
try {
|
|
1334
|
+
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1335
|
+
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1336
|
+
clearInterval(interval);
|
|
1337
|
+
resolve(this.transformResponse(response));
|
|
1338
|
+
}
|
|
1339
|
+
} catch (error) {
|
|
1340
|
+
clearInterval(interval);
|
|
1341
|
+
reject(error);
|
|
1342
|
+
}
|
|
1343
|
+
}, 1e3);
|
|
1344
|
+
setTimeout(() => {
|
|
1345
|
+
clearInterval(interval);
|
|
1346
|
+
reject(
|
|
1347
|
+
new ConnectionRequestTimeoutError(
|
|
1348
|
+
`Connection request timed out for ${this.connectedAccountId}`
|
|
1349
|
+
)
|
|
1350
|
+
);
|
|
1351
|
+
}, timeout);
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
};
|
|
1355
|
+
|
|
1356
|
+
// src/models/ConnectedAccounts.ts
|
|
1357
|
+
var ConnectedAccounts = class {
|
|
1358
|
+
client;
|
|
1359
|
+
constructor(client) {
|
|
1360
|
+
this.client = client;
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* List all connected accounts
|
|
1364
|
+
* @param {ConnectedAccountListParams} query - Query parameters for filtering connected accounts
|
|
1365
|
+
* @param {RequestOptions} options - Request options
|
|
1366
|
+
* @returns {Promise<ConnectedAccountListResponse>} List of connected accounts
|
|
1367
|
+
*/
|
|
1368
|
+
async list(query) {
|
|
1369
|
+
return this.client.connectedAccounts.list(query);
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Compound function to create a new connected account.
|
|
1373
|
+
* This function creates a new connected account and returns a connection request.
|
|
1374
|
+
* Users can then wait for the connection to be established using the `waitForConnection` method.
|
|
1375
|
+
* @param {string} userId - User ID of the connected account
|
|
1376
|
+
* @param {string} authConfigId - Auth config ID of the connected account
|
|
1377
|
+
* @param {CreateConnectedAccountOptions} data - Data for creating a new connected account
|
|
1378
|
+
* @returns {Promise<ConnectionRequest>} Connection request object
|
|
1379
|
+
*
|
|
1380
|
+
* @example
|
|
1381
|
+
* const connectionRequest = await composio.createConnectedAccount('user_123', 'auth_config_123', {
|
|
1382
|
+
* data: {
|
|
1383
|
+
* name: 'My Connected Account',
|
|
1384
|
+
* },
|
|
1385
|
+
* });
|
|
1386
|
+
*
|
|
1387
|
+
* @link https://docs.composio.dev/reference/connected-accounts/create-connected-account
|
|
1388
|
+
*/
|
|
1389
|
+
async initiate(userId, authConfigId, options) {
|
|
1390
|
+
const response = await this.client.connectedAccounts.create({
|
|
1391
|
+
auth_config: {
|
|
1392
|
+
id: authConfigId
|
|
1393
|
+
},
|
|
1394
|
+
connection: {
|
|
1395
|
+
data: options?.data,
|
|
1396
|
+
redirect_uri: options?.redirectUrl,
|
|
1397
|
+
user_id: userId
|
|
1398
|
+
}
|
|
1399
|
+
});
|
|
1400
|
+
return new ConnectionRequest(this.client, response.id, response.status, response.redirect_uri);
|
|
1401
|
+
}
|
|
1402
|
+
/**
|
|
1403
|
+
* Get a connected account by nanoid
|
|
1404
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1405
|
+
* @param {RequestOptions} options - Request options
|
|
1406
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} Connected account details
|
|
1407
|
+
*/
|
|
1408
|
+
async get(nanoid) {
|
|
1409
|
+
return this.client.connectedAccounts.retrieve(nanoid);
|
|
1410
|
+
}
|
|
1411
|
+
/**
|
|
1412
|
+
* Delete a connected account
|
|
1413
|
+
* @param {string} nanoid - Unique identifier of the connected account to delete
|
|
1414
|
+
* @param {RequestOptions} options - Request options
|
|
1415
|
+
* @returns {Promise<ConnectedAccountDeleteResponse>} Response from deletion
|
|
1416
|
+
*/
|
|
1417
|
+
async delete(nanoid) {
|
|
1418
|
+
return this.client.connectedAccounts.delete(nanoid);
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Refresh a connected account's credentials
|
|
1422
|
+
* @param {string} nanoid - Unique identifier of the connected account to refresh
|
|
1423
|
+
* @param {RequestOptions} options - Request options
|
|
1424
|
+
* @returns {Promise<ConnectedAccountRefreshResponse>} Refreshed connected account details
|
|
1425
|
+
*/
|
|
1426
|
+
async refresh(nanoid) {
|
|
1427
|
+
return this.client.connectedAccounts.refresh(nanoid);
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Update the status of a connected account
|
|
1431
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1432
|
+
* @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status
|
|
1433
|
+
* @param {RequestOptions} options - Request options
|
|
1434
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
1435
|
+
*/
|
|
1436
|
+
async updateStatus(nanoid, params) {
|
|
1437
|
+
return this.client.connectedAccounts.updateStatus(nanoid, params);
|
|
1438
|
+
}
|
|
1439
|
+
/**
|
|
1440
|
+
* Enable a connected account
|
|
1441
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1442
|
+
* @param {RequestOptions} options - Request options
|
|
1443
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
1444
|
+
*/
|
|
1445
|
+
async enable(nanoid) {
|
|
1446
|
+
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true });
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* Disable a connected account
|
|
1450
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1451
|
+
* @param {RequestOptions} options - Request options
|
|
1452
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
1453
|
+
*/
|
|
1454
|
+
async disable(nanoid) {
|
|
1455
|
+
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
|
|
1456
|
+
}
|
|
1457
|
+
};
|
|
1458
|
+
|
|
1459
|
+
// src/models/Toolkits.ts
|
|
1460
|
+
var Toolkits = class {
|
|
1461
|
+
client;
|
|
1462
|
+
constructor(client) {
|
|
1463
|
+
this.client = client;
|
|
1464
|
+
this.authorize = this.authorize.bind(this);
|
|
1465
|
+
}
|
|
1466
|
+
/**
|
|
1467
|
+
* List all toolkits available in the Composio SDK.
|
|
1468
|
+
* This method fetches the toolkits from the Composio API.
|
|
1469
|
+
* @returns {Promise<Toolkit[]>} List of toolkits
|
|
1470
|
+
*/
|
|
1471
|
+
async getToolkits(query) {
|
|
1472
|
+
const parsedQuery = ToolkitsListParamsSchema.parse(query);
|
|
1473
|
+
const result = await this.client.toolkits.list({
|
|
1474
|
+
category: parsedQuery.category,
|
|
1475
|
+
is_local: parsedQuery.isLocal,
|
|
1476
|
+
managed_by: parsedQuery.managedBy,
|
|
1477
|
+
sort_by: parsedQuery.sortBy
|
|
1478
|
+
});
|
|
1479
|
+
const parsedResult = ToolKitListResponseSchema.parse({
|
|
1480
|
+
items: result.items.map((item) => {
|
|
1481
|
+
const parsedItem = ToolKitItemSchema.parse({
|
|
1482
|
+
name: item.name,
|
|
1483
|
+
slug: item.slug,
|
|
1484
|
+
meta: item.meta,
|
|
1485
|
+
isLocalToolkit: item.is_local_toolkit,
|
|
1486
|
+
authSchemes: item.auth_schemes,
|
|
1487
|
+
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
1488
|
+
noAuth: item.no_auth
|
|
1489
|
+
});
|
|
1490
|
+
return parsedItem;
|
|
1491
|
+
}),
|
|
1492
|
+
nextCursor: result.next_cursor,
|
|
1493
|
+
totalPages: result.total_pages
|
|
1494
|
+
});
|
|
1495
|
+
return parsedResult;
|
|
1496
|
+
}
|
|
1497
|
+
/**
|
|
1498
|
+
* Fetches a toolkit by its Slug.
|
|
1499
|
+
* This method retrieves the toolkit from the Composio API.
|
|
1500
|
+
* @param slug - The ID of the toolkit to be retrieved
|
|
1501
|
+
* @param options - Request options
|
|
1502
|
+
* @returns {Promise<ToolkitRetrieveResponse>} The toolkit object
|
|
1503
|
+
*/
|
|
1504
|
+
async getToolkitBySlug(slug) {
|
|
1505
|
+
try {
|
|
1506
|
+
const result = await this.client.toolkits.retrieve(slug);
|
|
1507
|
+
const parsedResult = ToolkitRetrieveResponseSchema.parse({
|
|
1508
|
+
name: result.name,
|
|
1509
|
+
slug: result.slug,
|
|
1510
|
+
meta: {
|
|
1511
|
+
...result.meta,
|
|
1512
|
+
createdAt: result.meta.created_at,
|
|
1513
|
+
updatedAt: result.meta.updated_at,
|
|
1514
|
+
toolsCount: result.meta.tools_count,
|
|
1515
|
+
triggersCount: result.meta.triggers_count
|
|
1516
|
+
// appUrl: result.meta.app_url, @TODO Update the client type to include this
|
|
1517
|
+
},
|
|
1518
|
+
isLocalToolkit: result.is_local_toolkit,
|
|
1519
|
+
composioManagedAuthSchemes: result.composio_managed_auth_schemes,
|
|
1520
|
+
authConfigDetails: result.auth_config_details?.map((authConfig) => ({
|
|
1521
|
+
name: authConfig.name,
|
|
1522
|
+
mode: authConfig.mode,
|
|
1523
|
+
fields: {
|
|
1524
|
+
authConfigCreation: authConfig.fields.auth_config_creation,
|
|
1525
|
+
connectedAccountInitiation: authConfig.fields.connected_account_initiation
|
|
1526
|
+
},
|
|
1527
|
+
proxy: {
|
|
1528
|
+
baseUrl: authConfig.proxy?.base_url
|
|
1529
|
+
}
|
|
1530
|
+
}))
|
|
1531
|
+
});
|
|
1532
|
+
return parsedResult;
|
|
1533
|
+
} catch (error) {
|
|
1534
|
+
if (error instanceof ZodError3) {
|
|
1535
|
+
throw new ValidationError(error);
|
|
1536
|
+
}
|
|
1537
|
+
throw new ComposioToolNotFoundError(`Toolkit with slug ${slug} not found`, {
|
|
1538
|
+
slug
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
/**
|
|
1543
|
+
* Fetches a toolkit by its Slug or a list of toolkits.
|
|
1544
|
+
* This method retrieves the toolkit from the Composio API.
|
|
1545
|
+
* @param arg - The ID of the toolkit to be retrieved or a list of parameters
|
|
1546
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit object or a list of toolkits
|
|
1547
|
+
*/
|
|
1548
|
+
async get(arg) {
|
|
1549
|
+
if (typeof arg === "string") {
|
|
1550
|
+
return this.getToolkitBySlug(arg);
|
|
1551
|
+
}
|
|
1552
|
+
return this.getToolkits(arg);
|
|
1553
|
+
}
|
|
1554
|
+
/**
|
|
1555
|
+
* Fetches all categories available in the Composio SDK
|
|
1556
|
+
*
|
|
1557
|
+
* @returns {Promise<ToolkitRetrieveCategoriesResponse>} List of categories
|
|
1558
|
+
*/
|
|
1559
|
+
async listCategories() {
|
|
1560
|
+
const result = await this.client.toolkits.retrieveCategories();
|
|
1561
|
+
const parsedResult = ToolkitRetrieveCategoriesResponseSchema.parse({
|
|
1562
|
+
items: result.items.map((item) => {
|
|
1563
|
+
const parsedItem = ToolkitCategorySchema.parse({
|
|
1564
|
+
id: item.id,
|
|
1565
|
+
name: item.name
|
|
1566
|
+
});
|
|
1567
|
+
return parsedItem;
|
|
1568
|
+
}),
|
|
1569
|
+
nextCursor: result.next_cursor,
|
|
1570
|
+
totalPages: result.total_pages
|
|
1571
|
+
});
|
|
1572
|
+
return parsedResult;
|
|
1573
|
+
}
|
|
1574
|
+
/**
|
|
1575
|
+
* Authorizes a user to use a toolkit.
|
|
1576
|
+
* This method will create an auth config if one doesn't exist and initiate a connection request.
|
|
1577
|
+
* @param {string} userId - The user id of the user to authorize
|
|
1578
|
+
* @param {string} toolkitSlug - The slug of the toolkit to authorize
|
|
1579
|
+
* @param {string} authConfigId - The id of the auth config to use
|
|
1580
|
+
* @returns {Promise<ConnectionRequest>} The connection request object
|
|
1581
|
+
*/
|
|
1582
|
+
async authorize(userId, toolkitSlug, authConfigId) {
|
|
1583
|
+
const toolkit = await this.getToolkitBySlug(toolkitSlug);
|
|
1584
|
+
const composioAuthConfig = new AuthConfigs(this.client);
|
|
1585
|
+
let authConfigIdToUse;
|
|
1586
|
+
if (authConfigId) {
|
|
1587
|
+
const authConfig = await composioAuthConfig.get(authConfigId);
|
|
1588
|
+
authConfigIdToUse = authConfig.id;
|
|
1589
|
+
} else {
|
|
1590
|
+
if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
|
|
1591
|
+
const authConfig = await composioAuthConfig.create(toolkitSlug, {
|
|
1592
|
+
type: "use_composio_managed_auth",
|
|
1593
|
+
name: `${toolkit.name} Auth Config`
|
|
1594
|
+
});
|
|
1595
|
+
authConfigIdToUse = authConfig.id;
|
|
1596
|
+
} else {
|
|
1597
|
+
throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
|
|
1598
|
+
toolkitSlug
|
|
1599
|
+
});
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
const composioConnectedAccount = new ConnectedAccounts(this.client);
|
|
1603
|
+
return await composioConnectedAccount.initiate(userId, authConfigIdToUse);
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
|
|
1607
|
+
// src/utils/pusher.ts
|
|
1608
|
+
var PUSHER_KEY = process.env.CLIENT_PUSHER_KEY || "ff9f18c208855d77a152";
|
|
1609
|
+
var PUSHER_CLUSTER = "mt1";
|
|
1610
|
+
var PusherUtils = class _PusherUtils {
|
|
1611
|
+
static pusherClient;
|
|
1612
|
+
static getPusherClient(baseURL, apiKey) {
|
|
1613
|
+
if (!_PusherUtils.pusherClient) {
|
|
1614
|
+
const PusherClient = __require("pusher-js");
|
|
1615
|
+
_PusherUtils.pusherClient = new PusherClient(PUSHER_KEY, {
|
|
1616
|
+
cluster: PUSHER_CLUSTER,
|
|
1617
|
+
channelAuthorization: {
|
|
1618
|
+
endpoint: `${baseURL}/api/v1/client/auth/pusher_auth`,
|
|
1619
|
+
headers: {
|
|
1620
|
+
"x-api-key": apiKey
|
|
1621
|
+
},
|
|
1622
|
+
transport: "ajax"
|
|
1623
|
+
}
|
|
1624
|
+
});
|
|
1625
|
+
}
|
|
1626
|
+
return _PusherUtils.pusherClient;
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1629
|
+
* Subscribes to a Pusher channel and binds an event to a callback function.
|
|
1630
|
+
* @param {string} channelName - The name of the channel to subscribe to.
|
|
1631
|
+
* @param {string} event - The event to bind to the channel.
|
|
1632
|
+
* @param {(data: Record<string, unknown>) => void} fn - The callback function to execute when the event is triggered.
|
|
1633
|
+
* @returns {PusherClient} The Pusher client instance.
|
|
1634
|
+
*/
|
|
1635
|
+
static async subscribe(channelName, event, fn) {
|
|
1636
|
+
try {
|
|
1637
|
+
await _PusherUtils.pusherClient.subscribe(channelName).bind(event, fn);
|
|
1638
|
+
} catch (error) {
|
|
1639
|
+
logger_default.error(
|
|
1640
|
+
`Error subscribing to ${channelName} with event ${event}: ${error}`
|
|
1641
|
+
);
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
/**
|
|
1645
|
+
* Unsubscribes from a Pusher channel.
|
|
1646
|
+
* @param {string} channelName - The name of the channel to unsubscribe from.
|
|
1647
|
+
* @returns {void}
|
|
1648
|
+
*/
|
|
1649
|
+
static async unsubscribe(channelName) {
|
|
1650
|
+
_PusherUtils.pusherClient.unsubscribe(channelName);
|
|
1651
|
+
}
|
|
1652
|
+
/**
|
|
1653
|
+
* Binds an event to a channel with support for chunked messages.
|
|
1654
|
+
* @param {PusherClient} channel - The Pusher channel to bind the event to.
|
|
1655
|
+
* @param {string} event - The event to bind to the channel.
|
|
1656
|
+
* @param {(data: unknown) => void} callback - The callback function to execute when the event is triggered.
|
|
1657
|
+
*/
|
|
1658
|
+
static bindWithChunking(channel, event, callback) {
|
|
1659
|
+
channel.bind(event, callback);
|
|
1660
|
+
const events = {};
|
|
1661
|
+
channel.bind("chunked-" + event, (data) => {
|
|
1662
|
+
const typedData = data;
|
|
1663
|
+
if (!events.hasOwnProperty(typedData.id)) {
|
|
1664
|
+
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
1665
|
+
}
|
|
1666
|
+
const ev = events[typedData.id];
|
|
1667
|
+
ev.chunks[typedData.index] = typedData.chunk;
|
|
1668
|
+
if (typedData.final) ev.receivedFinal = true;
|
|
1669
|
+
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
1670
|
+
callback(JSON.parse(ev.chunks.join("")));
|
|
1671
|
+
delete events[typedData.id];
|
|
1672
|
+
}
|
|
1673
|
+
});
|
|
1322
1674
|
}
|
|
1323
1675
|
/**
|
|
1324
|
-
*
|
|
1325
|
-
* @param
|
|
1326
|
-
* @
|
|
1676
|
+
* Subscribes to a trigger channel for a client and handles chunked data.
|
|
1677
|
+
* @param {string} clientId - The unique identifier for the client subscribing to the events.
|
|
1678
|
+
* @param {(data: TriggerData) => void} fn - The callback function to execute when trigger data is received.
|
|
1327
1679
|
*/
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
}
|
|
1352
|
-
throw error;
|
|
1353
|
-
}
|
|
1680
|
+
static triggerSubscribe(clientId, fn) {
|
|
1681
|
+
const channel = _PusherUtils.pusherClient.subscribe(
|
|
1682
|
+
`private-${clientId}_triggers`
|
|
1683
|
+
);
|
|
1684
|
+
_PusherUtils.bindWithChunking(
|
|
1685
|
+
channel,
|
|
1686
|
+
"trigger_to_client",
|
|
1687
|
+
fn
|
|
1688
|
+
);
|
|
1689
|
+
logger_default.info(
|
|
1690
|
+
`Subscribed to triggers. You should start receiving events now.`
|
|
1691
|
+
);
|
|
1692
|
+
}
|
|
1693
|
+
static triggerUnsubscribe(clientId) {
|
|
1694
|
+
_PusherUtils.pusherClient.unsubscribe(`${clientId}_triggers`);
|
|
1695
|
+
}
|
|
1696
|
+
};
|
|
1697
|
+
|
|
1698
|
+
// src/models/Session.ts
|
|
1699
|
+
var Session = class {
|
|
1700
|
+
client;
|
|
1701
|
+
constructor(client) {
|
|
1702
|
+
this.client = client;
|
|
1354
1703
|
}
|
|
1355
1704
|
/**
|
|
1356
|
-
*
|
|
1357
|
-
*
|
|
1358
|
-
* @param {number} timeout - The time in milliseconds to wait for the connection to be established. Default is 30 seconds.
|
|
1359
|
-
* @returns
|
|
1705
|
+
* Get the active session info
|
|
1706
|
+
* @returns {Promise<SessionGetInfoResponse>} Session info
|
|
1360
1707
|
*/
|
|
1361
|
-
async
|
|
1362
|
-
|
|
1363
|
-
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1364
|
-
return Promise.resolve(this.transformResponse(response));
|
|
1365
|
-
}
|
|
1366
|
-
return new Promise((resolve, reject) => {
|
|
1367
|
-
const interval = setInterval(async () => {
|
|
1368
|
-
try {
|
|
1369
|
-
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1370
|
-
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1371
|
-
clearInterval(interval);
|
|
1372
|
-
resolve(this.transformResponse(response));
|
|
1373
|
-
}
|
|
1374
|
-
} catch (error) {
|
|
1375
|
-
clearInterval(interval);
|
|
1376
|
-
reject(error);
|
|
1377
|
-
}
|
|
1378
|
-
}, 1e3);
|
|
1379
|
-
setTimeout(() => {
|
|
1380
|
-
clearInterval(interval);
|
|
1381
|
-
reject(new Error("Connection request timed out"));
|
|
1382
|
-
}, timeout);
|
|
1383
|
-
});
|
|
1708
|
+
async getInfo() {
|
|
1709
|
+
return this.client.auth.session.getInfo();
|
|
1384
1710
|
}
|
|
1385
1711
|
};
|
|
1386
1712
|
|
|
1387
|
-
// src/models/
|
|
1388
|
-
var
|
|
1713
|
+
// src/models/Triggers.ts
|
|
1714
|
+
var Triggers = class {
|
|
1389
1715
|
client;
|
|
1390
1716
|
constructor(client) {
|
|
1391
1717
|
this.client = client;
|
|
1392
1718
|
}
|
|
1393
1719
|
/**
|
|
1394
|
-
*
|
|
1395
|
-
* @
|
|
1396
|
-
* @param {RequestOptions} options - Request options
|
|
1397
|
-
* @returns {Promise<ConnectedAccountListResponse>} List of connected accounts
|
|
1720
|
+
* Fetch list of all the active triggers
|
|
1721
|
+
* @returns {Promise<TriggerInstance[]>} List of trigger instances
|
|
1398
1722
|
*/
|
|
1399
|
-
async list(query) {
|
|
1400
|
-
return this.client.
|
|
1723
|
+
async list(query, options) {
|
|
1724
|
+
return this.client.triggerInstances.listActive(query, options);
|
|
1401
1725
|
}
|
|
1402
1726
|
/**
|
|
1403
|
-
*
|
|
1404
|
-
* This function creates a new connected account and returns a connection request.
|
|
1405
|
-
* Users can then wait for the connection to be established using the `waitForConnection` method.
|
|
1406
|
-
* @param {string} userId - User ID of the connected account
|
|
1407
|
-
* @param {string} authConfigId - Auth config ID of the connected account
|
|
1408
|
-
* @param {CreateConnectedAccountOptions} data - Data for creating a new connected account
|
|
1409
|
-
* @returns {Promise<ConnectionRequest>} Connection request object
|
|
1727
|
+
* Create a new trigger instance
|
|
1410
1728
|
*
|
|
1411
|
-
* @
|
|
1412
|
-
*
|
|
1413
|
-
*
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1729
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1730
|
+
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
1731
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
1732
|
+
*/
|
|
1733
|
+
async create(slug, body, options) {
|
|
1734
|
+
return this.client.triggerInstances.upsert(slug, body, options);
|
|
1735
|
+
}
|
|
1736
|
+
/**
|
|
1737
|
+
* Update an existing trigger instance
|
|
1417
1738
|
*
|
|
1418
|
-
* @
|
|
1739
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1740
|
+
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
1741
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1419
1742
|
*/
|
|
1420
|
-
async
|
|
1421
|
-
|
|
1422
|
-
auth_config: {
|
|
1423
|
-
id: authConfigId
|
|
1424
|
-
},
|
|
1425
|
-
connection: {
|
|
1426
|
-
data: options?.data,
|
|
1427
|
-
redirect_uri: options?.redirectUrl,
|
|
1428
|
-
user_id: userId
|
|
1429
|
-
}
|
|
1430
|
-
});
|
|
1431
|
-
return new ConnectionRequest(this.client, response.id, response.status);
|
|
1743
|
+
async update(slug, body, options) {
|
|
1744
|
+
return this.client.triggerInstances.upsert(slug, body, options);
|
|
1432
1745
|
}
|
|
1433
1746
|
/**
|
|
1434
|
-
*
|
|
1435
|
-
*
|
|
1436
|
-
* @param {
|
|
1437
|
-
* @returns
|
|
1747
|
+
* Delete a trigger instance
|
|
1748
|
+
*
|
|
1749
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1750
|
+
* @returns
|
|
1438
1751
|
*/
|
|
1439
|
-
async
|
|
1440
|
-
return this.client.
|
|
1752
|
+
async delete(slug) {
|
|
1753
|
+
return this.client.triggerInstances.removeUpsert(slug);
|
|
1441
1754
|
}
|
|
1442
1755
|
/**
|
|
1443
|
-
*
|
|
1444
|
-
*
|
|
1756
|
+
* Update the status of a trigger
|
|
1757
|
+
*
|
|
1758
|
+
* @param {TriggerStatusEnum} status - The new status of the trigger
|
|
1759
|
+
* @param {TriggerInstanceUpdateStatusParams} params - The parameters to update the trigger instance
|
|
1445
1760
|
* @param {RequestOptions} options - Request options
|
|
1446
|
-
* @returns {Promise<
|
|
1761
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1447
1762
|
*/
|
|
1448
|
-
async
|
|
1449
|
-
return this.client.
|
|
1763
|
+
async updateStatus(status, params, options) {
|
|
1764
|
+
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
1450
1765
|
}
|
|
1451
1766
|
/**
|
|
1452
|
-
*
|
|
1453
|
-
*
|
|
1454
|
-
* @param {
|
|
1455
|
-
* @
|
|
1767
|
+
* Disable a trigger instance
|
|
1768
|
+
*
|
|
1769
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1770
|
+
* @param {RequestOptions options - Request options
|
|
1771
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1456
1772
|
*/
|
|
1457
|
-
async
|
|
1458
|
-
return this.client.
|
|
1773
|
+
async disable(slug, options) {
|
|
1774
|
+
return this.client.triggerInstances.updateStatus("disable", { slug }, options);
|
|
1459
1775
|
}
|
|
1460
1776
|
/**
|
|
1461
|
-
*
|
|
1462
|
-
*
|
|
1463
|
-
* @param {
|
|
1464
|
-
* @param {RequestOptions
|
|
1465
|
-
* @returns {Promise<
|
|
1777
|
+
* Enable a trigger instance
|
|
1778
|
+
*
|
|
1779
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1780
|
+
* @param {RequestOptions options - Request options
|
|
1781
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1466
1782
|
*/
|
|
1467
|
-
async
|
|
1468
|
-
return this.client.
|
|
1783
|
+
async enable(slug, options) {
|
|
1784
|
+
return this.client.triggerInstances.updateStatus("enable", { slug }, options);
|
|
1469
1785
|
}
|
|
1470
1786
|
/**
|
|
1471
|
-
*
|
|
1472
|
-
|
|
1787
|
+
* @TODO Learn about trigger types
|
|
1788
|
+
*/
|
|
1789
|
+
/**
|
|
1790
|
+
* List all the trigger types
|
|
1791
|
+
*
|
|
1792
|
+
* @param {TriggersTypeListParams} query - The query parameters to filter the trigger types
|
|
1473
1793
|
* @param {RequestOptions} options - Request options
|
|
1474
|
-
* @returns {Promise<
|
|
1794
|
+
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
|
|
1475
1795
|
*/
|
|
1476
|
-
async
|
|
1477
|
-
return this.client.
|
|
1796
|
+
async listTypes(query, options) {
|
|
1797
|
+
return this.client.triggersTypes.list(query, options);
|
|
1478
1798
|
}
|
|
1479
1799
|
/**
|
|
1480
|
-
*
|
|
1481
|
-
*
|
|
1482
|
-
* @param {
|
|
1483
|
-
* @
|
|
1800
|
+
* Retrieve a trigger type by its slug
|
|
1801
|
+
*
|
|
1802
|
+
* @param {string} slug - The slug of the trigger type
|
|
1803
|
+
* @param {RequestOptions} options - request options
|
|
1804
|
+
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
1484
1805
|
*/
|
|
1485
|
-
async
|
|
1486
|
-
return this.client.
|
|
1806
|
+
async getType(slug, options) {
|
|
1807
|
+
return this.client.triggersTypes.retrieve(slug, options);
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Fetches the list of all the available trigger enums
|
|
1811
|
+
*
|
|
1812
|
+
* This method is used by the CLI where filters are not required.
|
|
1813
|
+
* @param options
|
|
1814
|
+
* @returns
|
|
1815
|
+
*/
|
|
1816
|
+
async listEnum(options) {
|
|
1817
|
+
return this.client.triggersTypes.retrieveEnum(options);
|
|
1818
|
+
}
|
|
1819
|
+
async subscribe(fn, filters = {}) {
|
|
1820
|
+
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
1821
|
+
const session = new Session(this.client);
|
|
1822
|
+
const sessionInfo = await session.getInfo();
|
|
1823
|
+
const clientId = sessionInfo.project?.id;
|
|
1824
|
+
if (!clientId) throw new Error("Client ID not found");
|
|
1825
|
+
await PusherUtils.getPusherClient(this.client.baseURL, this.client.apiKey);
|
|
1826
|
+
const shouldSendTrigger = (data) => {
|
|
1827
|
+
if (Object.keys(filters).length === 0) return true;
|
|
1828
|
+
else {
|
|
1829
|
+
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());
|
|
1830
|
+
}
|
|
1831
|
+
};
|
|
1832
|
+
logger_default.debug("Subscribing to triggers", filters);
|
|
1833
|
+
PusherUtils.triggerSubscribe(clientId, (data) => {
|
|
1834
|
+
if (shouldSendTrigger(data)) {
|
|
1835
|
+
fn(data);
|
|
1836
|
+
}
|
|
1837
|
+
});
|
|
1838
|
+
}
|
|
1839
|
+
async unsubscribe() {
|
|
1840
|
+
const session = new Session(this.client);
|
|
1841
|
+
const sessionInfo = await session.getInfo();
|
|
1842
|
+
const clientId = sessionInfo.project?.id;
|
|
1843
|
+
if (!clientId) throw new Error("Client ID not found");
|
|
1844
|
+
PusherUtils.triggerUnsubscribe(clientId);
|
|
1487
1845
|
}
|
|
1488
1846
|
};
|
|
1489
1847
|
|
|
@@ -1837,8 +2195,8 @@ var OpenAIToolset = class extends BaseNonAgenticToolset {
|
|
|
1837
2195
|
async executeToolCall(userId, tool, options, modifiers) {
|
|
1838
2196
|
const payload = {
|
|
1839
2197
|
arguments: JSON.parse(tool.function.arguments),
|
|
1840
|
-
connectedAccountId: options
|
|
1841
|
-
customAuthParams: options
|
|
2198
|
+
connectedAccountId: options?.connectedAccountId,
|
|
2199
|
+
customAuthParams: options?.customAuthParams,
|
|
1842
2200
|
userId
|
|
1843
2201
|
};
|
|
1844
2202
|
const result = await this.executeTool(tool.function.name, payload, modifiers);
|
|
@@ -1971,7 +2329,7 @@ var OpenAIToolset = class extends BaseNonAgenticToolset {
|
|
|
1971
2329
|
};
|
|
1972
2330
|
|
|
1973
2331
|
// package.json
|
|
1974
|
-
var version = "0.1.
|
|
2332
|
+
var version = "0.1.9-alpha.0";
|
|
1975
2333
|
|
|
1976
2334
|
// src/utils/uuid.ts
|
|
1977
2335
|
import { v4 as uuidv4 } from "uuid";
|
|
@@ -2004,7 +2362,7 @@ var Composio = class {
|
|
|
2004
2362
|
createAuthConfig;
|
|
2005
2363
|
// connected accounts
|
|
2006
2364
|
connectedAccounts;
|
|
2007
|
-
|
|
2365
|
+
initiateConnection;
|
|
2008
2366
|
/**
|
|
2009
2367
|
* @param {Object} config Configuration for the Composio SDK.
|
|
2010
2368
|
* @param {string} config.apiKey The API key for the Composio SDK.
|
|
@@ -2038,7 +2396,7 @@ var Composio = class {
|
|
|
2038
2396
|
this.authConfigs = new AuthConfigs(this.client);
|
|
2039
2397
|
this.createAuthConfig = this.authConfigs.create.bind(this.authConfigs);
|
|
2040
2398
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
2041
|
-
this.
|
|
2399
|
+
this.initiateConnection = this.connectedAccounts.initiate.bind(this.connectedAccounts);
|
|
2042
2400
|
if (this.config.allowTracking ?? true) {
|
|
2043
2401
|
this.initializeTelemetry(
|
|
2044
2402
|
{
|