@composio/core 0.1.8-alpha.0 → 0.1.10-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 +1347 -891
- package/dist/index.d.cts +381 -335
- package/dist/index.d.ts +381 -335
- package/dist/index.js +1057 -601
- package/package.json +7 -6
- package/src/index.ts +23 -0
package/dist/index.cjs
CHANGED
|
@@ -69,12 +69,12 @@ var ToolListResponseSchema = import_zod.z.object({
|
|
|
69
69
|
totalPages: import_zod.z.number()
|
|
70
70
|
});
|
|
71
71
|
var ToolListParamsSchema = import_zod.z.object({
|
|
72
|
+
tools: import_zod.z.array(import_zod.z.string()).optional(),
|
|
72
73
|
cursor: import_zod.z.string().optional(),
|
|
73
74
|
important: import_zod.z.string().optional(),
|
|
74
75
|
limit: import_zod.z.string().optional(),
|
|
75
76
|
search: import_zod.z.string().optional(),
|
|
76
|
-
toolkits: import_zod.z.array(import_zod.z.string()).optional()
|
|
77
|
-
tools: import_zod.z.array(import_zod.z.string()).optional()
|
|
77
|
+
toolkits: import_zod.z.array(import_zod.z.string()).optional()
|
|
78
78
|
});
|
|
79
79
|
var CustomAuthParamsSchema = import_zod.z.object({
|
|
80
80
|
baseURL: import_zod.z.string().optional(),
|
|
@@ -106,11 +106,223 @@ var ToolExecuteResponseSchema = import_zod.z.object({
|
|
|
106
106
|
|
|
107
107
|
// src/models/CustomTools.ts
|
|
108
108
|
var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"), 1);
|
|
109
|
+
|
|
110
|
+
// src/utils/env.ts
|
|
111
|
+
var getEnvVariable = (name, defaultValue = void 0) => {
|
|
112
|
+
try {
|
|
113
|
+
return process.env[name] || defaultValue;
|
|
114
|
+
} catch (_e) {
|
|
115
|
+
logger_default.error(`Error getting environment variable ${name}:`, _e);
|
|
116
|
+
return defaultValue;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/utils/logger.ts
|
|
121
|
+
var LOG_LEVELS = {
|
|
122
|
+
silent: -1,
|
|
123
|
+
// No logs
|
|
124
|
+
error: 0,
|
|
125
|
+
// Highest priority - critical errors
|
|
126
|
+
warn: 1,
|
|
127
|
+
// Warning messages
|
|
128
|
+
info: 2,
|
|
129
|
+
// General information
|
|
130
|
+
debug: 3
|
|
131
|
+
// Debug information
|
|
132
|
+
};
|
|
133
|
+
var getLogLevel = () => {
|
|
134
|
+
const envLevel = getEnvVariable("COMPOSIO_LOGGING_LEVEL", "info")?.toLowerCase();
|
|
135
|
+
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
136
|
+
};
|
|
137
|
+
var Logger = class {
|
|
138
|
+
level;
|
|
139
|
+
includeTimestamp;
|
|
140
|
+
console;
|
|
141
|
+
constructor(options = {}) {
|
|
142
|
+
this.level = options.level ?? getLogLevel();
|
|
143
|
+
this.includeTimestamp = options.includeTimestamp ?? true;
|
|
144
|
+
this.console = console;
|
|
145
|
+
}
|
|
146
|
+
formatMessage(args) {
|
|
147
|
+
const formattedArgs = args.map((arg) => typeof arg === "object" ? JSON.stringify(arg) : String(arg)).join("\n");
|
|
148
|
+
if (!this.includeTimestamp) {
|
|
149
|
+
return formattedArgs;
|
|
150
|
+
}
|
|
151
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
152
|
+
return `${timestamp} - ${formattedArgs}`;
|
|
153
|
+
}
|
|
154
|
+
shouldLog(level) {
|
|
155
|
+
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
156
|
+
}
|
|
157
|
+
error(...args) {
|
|
158
|
+
if (this.shouldLog("error")) {
|
|
159
|
+
this.console.error(this.formatMessage(args));
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
warn(...args) {
|
|
163
|
+
if (this.shouldLog("warn")) {
|
|
164
|
+
this.console.warn(this.formatMessage(args));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
info(...args) {
|
|
168
|
+
if (this.shouldLog("info")) {
|
|
169
|
+
this.console.info(this.formatMessage(args));
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
debug(...args) {
|
|
173
|
+
if (this.shouldLog("debug")) {
|
|
174
|
+
this.console.debug(this.formatMessage(args));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
var logger = new Logger();
|
|
179
|
+
var logger_default = logger;
|
|
180
|
+
|
|
181
|
+
// src/errors/ComposioError.ts
|
|
182
|
+
var ComposioError = class extends Error {
|
|
183
|
+
name = "ComposioError";
|
|
184
|
+
code;
|
|
185
|
+
statusCode;
|
|
186
|
+
cause;
|
|
187
|
+
meta;
|
|
188
|
+
possibleFixes;
|
|
189
|
+
constructor(message, options = {}) {
|
|
190
|
+
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
|
+
if (Error.captureStackTrace) {
|
|
197
|
+
Error.captureStackTrace(this, this.constructor);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
toJSON() {
|
|
201
|
+
return {
|
|
202
|
+
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
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/errors/ToolErrors.ts
|
|
214
|
+
var ToolErrorCodes = {
|
|
215
|
+
TOOLSET_NOT_DEFINED: "TOOLSET_NOT_DEFINED",
|
|
216
|
+
TOOL_NOT_FOUND: "TOOL_NOT_FOUND",
|
|
217
|
+
INVALID_MODIFIER: "INVALID_MODIFIER",
|
|
218
|
+
CUSTOM_TOOLS_NOT_INITIALIZED: "CUSTOM_TOOLS_NOT_INITIALIZED",
|
|
219
|
+
TOOL_EXECUTION_ERROR: "TOOL_EXECUTION_ERROR",
|
|
220
|
+
INVALID_EXECUTE_FUNCTION: "INVALID_EXECUTE_FUNCTION",
|
|
221
|
+
GLOBAL_EXECUTE_TOOL_FN_NOT_SET: "GLOBAL_EXECUTE_TOOL_FN_NOT_SET"
|
|
222
|
+
};
|
|
223
|
+
var ComposioToolsetNotDefinedError = class extends ComposioError {
|
|
224
|
+
constructor(message = "Toolset not defined", meta = {}) {
|
|
225
|
+
super(message, {
|
|
226
|
+
code: ToolErrorCodes.TOOLSET_NOT_DEFINED,
|
|
227
|
+
meta,
|
|
228
|
+
possibleFixes: [
|
|
229
|
+
"Ensure that the toolset is defined in the Composio project and passed into the tool instance"
|
|
230
|
+
]
|
|
231
|
+
});
|
|
232
|
+
this.name = "ComposioToolsetNotDefinedError";
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
var ComposioToolNotFoundError = class extends ComposioError {
|
|
236
|
+
constructor(message = "Tool not found", meta = {}) {
|
|
237
|
+
super(message, {
|
|
238
|
+
code: ToolErrorCodes.TOOL_NOT_FOUND,
|
|
239
|
+
meta,
|
|
240
|
+
possibleFixes: ["Ensure the tool slug is correct and exists in the Composio project"]
|
|
241
|
+
});
|
|
242
|
+
this.name = "ComposioToolNotFoundError";
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
var ComposioInvalidModifierError = class extends ComposioError {
|
|
246
|
+
constructor(message = "Invalid modifier", meta = {}) {
|
|
247
|
+
super(message, {
|
|
248
|
+
code: ToolErrorCodes.INVALID_MODIFIER,
|
|
249
|
+
meta,
|
|
250
|
+
possibleFixes: ["Ensure the modifier is a function and returns a valid result"]
|
|
251
|
+
});
|
|
252
|
+
this.name = "ComposioInvalidModifierError";
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
var ComposioCustomToolsNotInitializedError = class extends ComposioError {
|
|
256
|
+
constructor(message = "Custom tools not initialized", meta = {}) {
|
|
257
|
+
super(message, {
|
|
258
|
+
code: ToolErrorCodes.CUSTOM_TOOLS_NOT_INITIALIZED,
|
|
259
|
+
meta,
|
|
260
|
+
possibleFixes: ["Ensure the custom tools class is initialized in the Tools instance"]
|
|
261
|
+
});
|
|
262
|
+
this.name = "ComposioCustomToolsNotInitializedError";
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
var ComposioToolExecutionError = class extends ComposioError {
|
|
266
|
+
error;
|
|
267
|
+
constructor(error, message = "Tool execution error", meta = {}) {
|
|
268
|
+
super(message, {
|
|
269
|
+
code: ToolErrorCodes.TOOL_EXECUTION_ERROR,
|
|
270
|
+
cause: error,
|
|
271
|
+
meta,
|
|
272
|
+
possibleFixes: ["Ensure the tool is correctly configured and the input is valid"]
|
|
273
|
+
});
|
|
274
|
+
this.error = error;
|
|
275
|
+
this.name = "ComposioToolExecutionError";
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
var ComposioInvalidExecuteFunctionError = class extends ComposioError {
|
|
279
|
+
constructor(message = "Invalid execute function", meta = {}) {
|
|
280
|
+
super(message, {
|
|
281
|
+
code: ToolErrorCodes.INVALID_EXECUTE_FUNCTION,
|
|
282
|
+
meta,
|
|
283
|
+
possibleFixes: ["Ensure the execute function is a valid function and returns a valid result"]
|
|
284
|
+
});
|
|
285
|
+
this.name = "ComposioInvalidExecuteFunctionError";
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
|
|
289
|
+
constructor(message = "Global execute tool function not set", meta = {}) {
|
|
290
|
+
super(message, {
|
|
291
|
+
code: ToolErrorCodes.GLOBAL_EXECUTE_TOOL_FN_NOT_SET,
|
|
292
|
+
meta,
|
|
293
|
+
possibleFixes: ["Ensure the global execute tool function is set in the toolset"]
|
|
294
|
+
});
|
|
295
|
+
this.name = "ComposioGlobalExecuteToolFnNotSetError";
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/errors/ConnectedAccountsError.ts
|
|
300
|
+
var ConnectedAccountErrorCodes = {
|
|
301
|
+
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
|
|
302
|
+
};
|
|
303
|
+
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
304
|
+
constructor(message = "Connected account not found", meta = {}) {
|
|
305
|
+
super(message, {
|
|
306
|
+
code: ConnectedAccountErrorCodes.CONNECTED_ACCOUNT_NOT_FOUND,
|
|
307
|
+
statusCode: 404,
|
|
308
|
+
meta,
|
|
309
|
+
possibleFixes: [
|
|
310
|
+
"Ensure the connected account exists and is active in your Composio dashboard"
|
|
311
|
+
]
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// src/models/CustomTools.ts
|
|
109
317
|
var CustomTools = class {
|
|
110
318
|
client;
|
|
111
|
-
customToolsRegistry
|
|
319
|
+
customToolsRegistry;
|
|
112
320
|
constructor(client) {
|
|
321
|
+
if (!client) {
|
|
322
|
+
throw new ComposioError("ComposioClient is required");
|
|
323
|
+
}
|
|
113
324
|
this.client = client;
|
|
325
|
+
this.customToolsRegistry = /* @__PURE__ */ new Map();
|
|
114
326
|
}
|
|
115
327
|
/**
|
|
116
328
|
* Create a custom tool and registers it in the registry.
|
|
@@ -178,11 +390,16 @@ var CustomTools = class {
|
|
|
178
390
|
* @returns {Tool} The tool
|
|
179
391
|
*/
|
|
180
392
|
async getCustomToolBySlug(slug) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
393
|
+
if (!slug) {
|
|
394
|
+
throw new Error("Tool slug is required");
|
|
395
|
+
}
|
|
396
|
+
try {
|
|
397
|
+
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
398
|
+
return tool?.schema;
|
|
399
|
+
} catch (error) {
|
|
400
|
+
logger_default.error(`Error getting custom tool: ${error}`);
|
|
401
|
+
return void 0;
|
|
184
402
|
}
|
|
185
|
-
return tool.schema;
|
|
186
403
|
}
|
|
187
404
|
/**
|
|
188
405
|
* Get the connected account for the user and toolkit.
|
|
@@ -191,12 +408,25 @@ var CustomTools = class {
|
|
|
191
408
|
* @returns {ConnectedAccount} The connected account
|
|
192
409
|
*/
|
|
193
410
|
async getConnectedAccount(toolkitSlug, metadata) {
|
|
411
|
+
try {
|
|
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
|
+
}
|
|
194
419
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
195
420
|
toolkit_slug: toolkitSlug,
|
|
196
421
|
user_id: metadata.userId
|
|
197
422
|
});
|
|
198
423
|
if (!connectedAccounts.items.length) {
|
|
199
|
-
throw new
|
|
424
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
425
|
+
`No connected accounts found for toolkit ${toolkitSlug}`,
|
|
426
|
+
{
|
|
427
|
+
toolkitSlug
|
|
428
|
+
}
|
|
429
|
+
);
|
|
200
430
|
}
|
|
201
431
|
return metadata.connectedAccountId ? connectedAccounts.items.find((item) => item.id === metadata.connectedAccountId) : connectedAccounts.items[0];
|
|
202
432
|
}
|
|
@@ -210,21 +440,29 @@ var CustomTools = class {
|
|
|
210
440
|
async executeCustomTool(slug, inputParams, metadata) {
|
|
211
441
|
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
212
442
|
if (!tool) {
|
|
213
|
-
throw new
|
|
443
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`, {
|
|
444
|
+
toolSlug: slug
|
|
445
|
+
});
|
|
214
446
|
}
|
|
215
447
|
let authCredentials = {};
|
|
216
448
|
const { toolkitSlug, execute } = tool.options;
|
|
217
|
-
if (toolkitSlug) {
|
|
449
|
+
if (toolkitSlug && toolkitSlug !== "custom") {
|
|
218
450
|
const connectedAccount = await this.getConnectedAccount(toolkitSlug, metadata);
|
|
219
451
|
if (!connectedAccount) {
|
|
220
|
-
throw new
|
|
221
|
-
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}
|
|
452
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
453
|
+
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}`,
|
|
454
|
+
{
|
|
455
|
+
toolkitSlug,
|
|
456
|
+
userId: metadata.userId
|
|
457
|
+
}
|
|
222
458
|
);
|
|
223
459
|
}
|
|
224
460
|
authCredentials = connectedAccount.data?.connectionParams;
|
|
225
461
|
}
|
|
226
462
|
if (typeof execute !== "function") {
|
|
227
|
-
throw new
|
|
463
|
+
throw new ComposioInvalidExecuteFunctionError("Invalid execute function", {
|
|
464
|
+
toolSlug: slug
|
|
465
|
+
});
|
|
228
466
|
}
|
|
229
467
|
const executeToolRequest = async (data) => {
|
|
230
468
|
return this.client.tools.proxy({
|
|
@@ -240,79 +478,42 @@ var CustomTools = class {
|
|
|
240
478
|
}
|
|
241
479
|
};
|
|
242
480
|
|
|
243
|
-
// src/
|
|
244
|
-
var
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
} catch (_e) {
|
|
248
|
-
logger_default.error(`Error getting environment variable ${name}:`, _e);
|
|
249
|
-
return defaultValue;
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
// src/utils/logger.ts
|
|
254
|
-
var LOG_LEVELS = {
|
|
255
|
-
silent: -1,
|
|
256
|
-
// No logs
|
|
257
|
-
error: 0,
|
|
258
|
-
// Highest priority - critical errors
|
|
259
|
-
warn: 1,
|
|
260
|
-
// Warning messages
|
|
261
|
-
info: 2,
|
|
262
|
-
// General information
|
|
263
|
-
debug: 3
|
|
264
|
-
// Debug information
|
|
265
|
-
};
|
|
266
|
-
var getLogLevel = () => {
|
|
267
|
-
const envLevel = getEnvVariable(
|
|
268
|
-
"COMPOSIO_LOGGING_LEVEL",
|
|
269
|
-
"info"
|
|
270
|
-
)?.toLowerCase();
|
|
271
|
-
return envLevel && envLevel in LOG_LEVELS ? envLevel : "info";
|
|
481
|
+
// src/errors/ValidationError.ts
|
|
482
|
+
var import_zod2 = require("zod");
|
|
483
|
+
var ValidationErrorCodes = {
|
|
484
|
+
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
272
485
|
};
|
|
273
|
-
var
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
288
|
-
return `${timestamp} - ${formattedArgs}`;
|
|
289
|
-
}
|
|
290
|
-
shouldLog(level) {
|
|
291
|
-
return LOG_LEVELS[level] <= LOG_LEVELS[this.level];
|
|
292
|
-
}
|
|
293
|
-
error(...args) {
|
|
294
|
-
if (this.shouldLog("error")) {
|
|
295
|
-
this.console.error(this.formatMessage(args));
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
warn(...args) {
|
|
299
|
-
if (this.shouldLog("warn")) {
|
|
300
|
-
this.console.warn(this.formatMessage(args));
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
info(...args) {
|
|
304
|
-
if (this.shouldLog("info")) {
|
|
305
|
-
this.console.info(this.formatMessage(args));
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
debug(...args) {
|
|
309
|
-
if (this.shouldLog("debug")) {
|
|
310
|
-
this.console.debug(this.formatMessage(args));
|
|
486
|
+
var ValidationError = class extends ComposioError {
|
|
487
|
+
zodError;
|
|
488
|
+
constructor(zodError, message = "Input validation failed") {
|
|
489
|
+
let zodErrorInstance;
|
|
490
|
+
if (!(zodError instanceof import_zod2.ZodError)) {
|
|
491
|
+
zodErrorInstance = new import_zod2.ZodError([
|
|
492
|
+
{
|
|
493
|
+
path: [],
|
|
494
|
+
message: "Invalid input",
|
|
495
|
+
code: "custom"
|
|
496
|
+
}
|
|
497
|
+
]);
|
|
498
|
+
} else {
|
|
499
|
+
zodErrorInstance = zodError;
|
|
311
500
|
}
|
|
501
|
+
super(message, {
|
|
502
|
+
code: ValidationErrorCodes.VALIDATION_ERROR,
|
|
503
|
+
meta: {
|
|
504
|
+
issues: JSON.stringify(
|
|
505
|
+
zodErrorInstance.issues.map((issue) => ({
|
|
506
|
+
path: issue.path.join("."),
|
|
507
|
+
message: issue.message,
|
|
508
|
+
code: issue.code
|
|
509
|
+
}))
|
|
510
|
+
)
|
|
511
|
+
},
|
|
512
|
+
cause: zodErrorInstance
|
|
513
|
+
});
|
|
514
|
+
this.zodError = zodErrorInstance;
|
|
312
515
|
}
|
|
313
516
|
};
|
|
314
|
-
var logger = new Logger();
|
|
315
|
-
var logger_default = logger;
|
|
316
517
|
|
|
317
518
|
// src/models/Tools.ts
|
|
318
519
|
var Tools = class {
|
|
@@ -320,9 +521,18 @@ var Tools = class {
|
|
|
320
521
|
customTools;
|
|
321
522
|
toolset;
|
|
322
523
|
constructor(client, toolset) {
|
|
524
|
+
if (!client) {
|
|
525
|
+
throw new Error("ComposioClient is required");
|
|
526
|
+
}
|
|
527
|
+
if (!toolset) {
|
|
528
|
+
throw new ComposioToolsetNotDefinedError("Toolset not passed into Tools instance");
|
|
529
|
+
}
|
|
323
530
|
this.client = client;
|
|
324
531
|
this.customTools = new CustomTools(client);
|
|
325
532
|
this.toolset = toolset;
|
|
533
|
+
this.execute = this.execute.bind(this);
|
|
534
|
+
this.getComposioToolBySlug = this.getComposioToolBySlug.bind(this);
|
|
535
|
+
this.getComposioTools = this.getComposioTools.bind(this);
|
|
326
536
|
}
|
|
327
537
|
/**
|
|
328
538
|
* Transform the tool cases
|
|
@@ -356,12 +566,12 @@ var Tools = class {
|
|
|
356
566
|
* @param {ToolList} tools - The tools to check.
|
|
357
567
|
* @returns {Promise<boolean>} True if the connected account exists for the given tools, false otherwise.
|
|
358
568
|
*/
|
|
359
|
-
async checkIfConnectedAccountExistsForTools(
|
|
569
|
+
async checkIfConnectedAccountExistsForTools(userIds, tools) {
|
|
360
570
|
if (!tools.length) {
|
|
361
571
|
return true;
|
|
362
572
|
}
|
|
363
573
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
364
|
-
|
|
574
|
+
user_ids: userIds
|
|
365
575
|
});
|
|
366
576
|
if (connectedAccounts.items.length === 0) {
|
|
367
577
|
return false;
|
|
@@ -410,8 +620,8 @@ var Tools = class {
|
|
|
410
620
|
);
|
|
411
621
|
if (!isNoAuthApp) {
|
|
412
622
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
413
|
-
|
|
414
|
-
|
|
623
|
+
user_ids: [userId],
|
|
624
|
+
toolkit_slugs: [tool.toolkit.slug]
|
|
415
625
|
});
|
|
416
626
|
if (connectedAccounts.items.length === 0) {
|
|
417
627
|
throw new Error("No connected accounts found");
|
|
@@ -431,15 +641,15 @@ var Tools = class {
|
|
|
431
641
|
async getComposioTools(userId, query = {}, modifier) {
|
|
432
642
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
433
643
|
if (queryParams.error) {
|
|
434
|
-
throw new
|
|
644
|
+
throw new ValidationError(queryParams.error);
|
|
435
645
|
}
|
|
436
646
|
const tools = await this.client.tools.list({
|
|
647
|
+
tool_slugs: queryParams.data.tools,
|
|
648
|
+
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
437
649
|
cursor: queryParams.data.cursor,
|
|
438
650
|
important: queryParams.data.important,
|
|
439
651
|
limit: queryParams.data.limit,
|
|
440
|
-
search: queryParams.data.search
|
|
441
|
-
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
442
|
-
tool_slugs: queryParams.data.tools?.join(",")
|
|
652
|
+
search: queryParams.data.search
|
|
443
653
|
});
|
|
444
654
|
if (!tools) {
|
|
445
655
|
return [];
|
|
@@ -452,10 +662,10 @@ var Tools = class {
|
|
|
452
662
|
if (modifier) {
|
|
453
663
|
if (typeof modifier === "function") {
|
|
454
664
|
modifiedTools = modifiedTools.map((tool) => {
|
|
455
|
-
return modifier(tool.slug, tool);
|
|
665
|
+
return modifier(tool.slug, tool.toolkit?.slug || "unkown", tool);
|
|
456
666
|
});
|
|
457
667
|
} else {
|
|
458
|
-
throw new
|
|
668
|
+
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
459
669
|
}
|
|
460
670
|
}
|
|
461
671
|
return modifiedTools;
|
|
@@ -464,6 +674,11 @@ var Tools = class {
|
|
|
464
674
|
* Retrieves a tool by its Slug.
|
|
465
675
|
* @param slug The ID of the tool to be retrieved
|
|
466
676
|
* @returns {Promise<Tool>} The tool
|
|
677
|
+
*
|
|
678
|
+
* @example
|
|
679
|
+
* ```ts
|
|
680
|
+
* const tool = await composio.tools.getComposioToolBySlug('default', 'github');
|
|
681
|
+
* ```
|
|
467
682
|
*/
|
|
468
683
|
async getComposioToolBySlug(userId, slug, modifier) {
|
|
469
684
|
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
@@ -472,18 +687,27 @@ var Tools = class {
|
|
|
472
687
|
}
|
|
473
688
|
const tool = await this.client.tools.retrieve(slug);
|
|
474
689
|
if (!tool) {
|
|
475
|
-
throw new
|
|
690
|
+
throw new ComposioToolNotFoundError(
|
|
691
|
+
`[getComposioToolBySlug] Tool with slug ${slug} not found`
|
|
692
|
+
);
|
|
476
693
|
}
|
|
477
694
|
let modifiedToool = this.transformToolCases(tool);
|
|
478
695
|
if (modifier) {
|
|
479
696
|
if (typeof modifier === "function") {
|
|
480
|
-
modifiedToool = modifier(slug, modifiedToool);
|
|
697
|
+
modifiedToool = modifier(slug, modifiedToool.toolkit?.slug || "unkown", modifiedToool);
|
|
481
698
|
} else {
|
|
482
|
-
throw new
|
|
699
|
+
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
483
700
|
}
|
|
484
701
|
}
|
|
485
702
|
return modifiedToool;
|
|
486
703
|
}
|
|
704
|
+
/**
|
|
705
|
+
* Get a tool by its slug
|
|
706
|
+
* @param userId - The user id
|
|
707
|
+
* @param arg2 - The slug of the tool or the filters for the tools
|
|
708
|
+
* @param options - The options for the tools
|
|
709
|
+
* @returns The tool or the tools
|
|
710
|
+
*/
|
|
487
711
|
async get(userId, arg2, options) {
|
|
488
712
|
const executeToolFn = this.createExecuteToolFn(userId, options);
|
|
489
713
|
if (typeof arg2 === "string") {
|
|
@@ -495,6 +719,7 @@ var Tools = class {
|
|
|
495
719
|
}
|
|
496
720
|
}
|
|
497
721
|
/**
|
|
722
|
+
* @internal
|
|
498
723
|
* Creates a function that executes a tool.
|
|
499
724
|
* This function is used by agentic the toolsets to execute the tool
|
|
500
725
|
* @param {string} userId - The user id
|
|
@@ -514,6 +739,82 @@ var Tools = class {
|
|
|
514
739
|
};
|
|
515
740
|
return executeToolFn;
|
|
516
741
|
}
|
|
742
|
+
/**
|
|
743
|
+
* @internal
|
|
744
|
+
* Handles the execution of a custom tool
|
|
745
|
+
* @param tool - The tool to execute
|
|
746
|
+
* @param body - The body of the tool execution
|
|
747
|
+
* @param modifiers - The modifiers to be applied to the tool execution
|
|
748
|
+
* @returns The response from the tool execution
|
|
749
|
+
*/
|
|
750
|
+
async handleCustomToolExecution(tool, body, modifiers) {
|
|
751
|
+
if (modifiers?.beforeToolExecute) {
|
|
752
|
+
if (typeof modifiers.beforeToolExecute === "function") {
|
|
753
|
+
body = modifiers.beforeToolExecute(tool.slug, "unkown", body);
|
|
754
|
+
} else {
|
|
755
|
+
throw new ComposioInvalidModifierError(
|
|
756
|
+
"Invalid beforeToolExecute modifier. Not a function."
|
|
757
|
+
);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
let result = await this.customTools.executeCustomTool(tool.slug, body, {
|
|
761
|
+
userId: body.userId || "default",
|
|
762
|
+
connectedAccountId: body.connectedAccountId
|
|
763
|
+
});
|
|
764
|
+
if (modifiers?.afterToolExecute) {
|
|
765
|
+
if (typeof modifiers.afterToolExecute === "function") {
|
|
766
|
+
result = modifiers.afterToolExecute(tool.slug, "unkown", result);
|
|
767
|
+
} else {
|
|
768
|
+
throw new ComposioInvalidModifierError(
|
|
769
|
+
"Invalid afterToolExecute modifier. Not a function."
|
|
770
|
+
);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
return result;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* @internal
|
|
777
|
+
* Handles the execution of a composio tool
|
|
778
|
+
* @param tool - The tool to execute
|
|
779
|
+
* @param body - The body of the tool execution
|
|
780
|
+
* @param modifiers - The modifiers to be applied to the tool execution
|
|
781
|
+
* @returns The response from the tool execution
|
|
782
|
+
*/
|
|
783
|
+
async handleComposioToolExecution(tool, body, modifiers) {
|
|
784
|
+
if (modifiers?.beforeToolExecute) {
|
|
785
|
+
if (typeof modifiers.beforeToolExecute === "function") {
|
|
786
|
+
body = modifiers.beforeToolExecute(tool.slug, tool.toolkit?.slug || "unkown", body);
|
|
787
|
+
} else {
|
|
788
|
+
throw new ComposioInvalidModifierError(
|
|
789
|
+
"Invalid beforeToolExecute modifier. Not a function."
|
|
790
|
+
);
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
let connectedAccountId = body.connectedAccountId;
|
|
794
|
+
if (!connectedAccountId) {
|
|
795
|
+
connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, tool.slug) || void 0;
|
|
796
|
+
}
|
|
797
|
+
let result = await this.client.tools.execute(tool.slug, {
|
|
798
|
+
allow_tracing: body.allowTracing,
|
|
799
|
+
connected_account_id: body.connectedAccountId,
|
|
800
|
+
custom_auth_params: body.customAuthParams,
|
|
801
|
+
arguments: body.arguments,
|
|
802
|
+
entity_id: body.userId,
|
|
803
|
+
version: body.version,
|
|
804
|
+
text: body.text
|
|
805
|
+
});
|
|
806
|
+
result = this.transformToolExecuteResponse(result);
|
|
807
|
+
if (modifiers?.afterToolExecute) {
|
|
808
|
+
if (typeof modifiers.afterToolExecute === "function") {
|
|
809
|
+
result = modifiers.afterToolExecute(tool.slug, tool.toolkit?.slug || "unkown", result);
|
|
810
|
+
} else {
|
|
811
|
+
throw new ComposioInvalidModifierError(
|
|
812
|
+
"Invalid afterToolExecute modifier. Not a function."
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
return result;
|
|
817
|
+
}
|
|
517
818
|
/**
|
|
518
819
|
* Exectes a given tool with the provided parameters.
|
|
519
820
|
*
|
|
@@ -524,44 +825,28 @@ var Tools = class {
|
|
|
524
825
|
* @returns {Promise<ToolExecuteResponse>} - The response from the tool execution
|
|
525
826
|
*/
|
|
526
827
|
async execute(slug, body, modifiers) {
|
|
527
|
-
if (
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
throw new Error("Invalid beforeToolExecute modifier. Not a function.");
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
let result;
|
|
535
|
-
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
536
|
-
if (customTool) {
|
|
537
|
-
result = await this.customTools.executeCustomTool(slug, body, {
|
|
538
|
-
userId: body.userId || "default",
|
|
539
|
-
connectedAccountId: body.connectedAccountId
|
|
540
|
-
});
|
|
541
|
-
} else {
|
|
542
|
-
let connectedAccountId = body.connectedAccountId;
|
|
543
|
-
if (!connectedAccountId) {
|
|
544
|
-
connectedAccountId = await this.getConnectedAccountIdForTool(body.userId, slug) || void 0;
|
|
545
|
-
}
|
|
546
|
-
result = await this.client.tools.execute(slug, {
|
|
547
|
-
allow_tracing: body.allowTracing,
|
|
548
|
-
connected_account_id: body.connectedAccountId,
|
|
549
|
-
custom_auth_params: body.customAuthParams,
|
|
550
|
-
arguments: body.arguments,
|
|
551
|
-
entity_id: body.userId,
|
|
552
|
-
version: body.version,
|
|
553
|
-
text: body.text
|
|
554
|
-
});
|
|
555
|
-
result = this.transformToolExecuteResponse(result);
|
|
828
|
+
if (!this.customTools) {
|
|
829
|
+
throw new ComposioCustomToolsNotInitializedError(
|
|
830
|
+
"CustomTools not initialized. Make sure Tools class is properly constructed."
|
|
831
|
+
);
|
|
556
832
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
833
|
+
try {
|
|
834
|
+
const customTool = await this.customTools.getCustomToolBySlug(slug);
|
|
835
|
+
if (customTool) {
|
|
836
|
+
return this.handleCustomToolExecution(customTool, body, modifiers);
|
|
560
837
|
} else {
|
|
561
|
-
|
|
838
|
+
const composioTool = await this.getComposioToolBySlug(body.userId, slug);
|
|
839
|
+
if (!composioTool) {
|
|
840
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
841
|
+
}
|
|
842
|
+
return this.handleComposioToolExecution(composioTool, body, modifiers);
|
|
562
843
|
}
|
|
844
|
+
} catch (error) {
|
|
845
|
+
throw new ComposioToolExecutionError(error, `Error executing tool ${slug}`, {
|
|
846
|
+
toolSlug: slug,
|
|
847
|
+
body
|
|
848
|
+
});
|
|
563
849
|
}
|
|
564
|
-
return result;
|
|
565
850
|
}
|
|
566
851
|
/**
|
|
567
852
|
* Fetches the list of all available tools in the Composio SDK.
|
|
@@ -604,424 +889,432 @@ var Tools = class {
|
|
|
604
889
|
};
|
|
605
890
|
|
|
606
891
|
// src/types/toolkit.types.ts
|
|
607
|
-
var
|
|
608
|
-
var ToolkitMangedByEnumSchema =
|
|
609
|
-
var ToolkitSortByEnumSchema =
|
|
610
|
-
var ToolkitsListParamsSchema =
|
|
611
|
-
category:
|
|
612
|
-
isLocal:
|
|
892
|
+
var import_zod3 = require("zod");
|
|
893
|
+
var ToolkitMangedByEnumSchema = import_zod3.z.enum(["all", "composio", "project"]);
|
|
894
|
+
var ToolkitSortByEnumSchema = import_zod3.z.enum(["usage", "alphabetically"]);
|
|
895
|
+
var ToolkitsListParamsSchema = import_zod3.z.object({
|
|
896
|
+
category: import_zod3.z.string().optional(),
|
|
897
|
+
isLocal: import_zod3.z.boolean().optional(),
|
|
613
898
|
managedBy: ToolkitMangedByEnumSchema.optional(),
|
|
614
899
|
sortBy: ToolkitSortByEnumSchema.optional()
|
|
615
900
|
});
|
|
616
|
-
var ToolKitMetaSchema =
|
|
617
|
-
categories:
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
name:
|
|
901
|
+
var ToolKitMetaSchema = import_zod3.z.object({
|
|
902
|
+
categories: import_zod3.z.array(
|
|
903
|
+
import_zod3.z.object({
|
|
904
|
+
slug: import_zod3.z.string(),
|
|
905
|
+
name: import_zod3.z.string()
|
|
621
906
|
})
|
|
622
|
-
),
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
907
|
+
).optional(),
|
|
908
|
+
appUrl: import_zod3.z.string().optional(),
|
|
909
|
+
createdAt: import_zod3.z.string().optional(),
|
|
910
|
+
description: import_zod3.z.string().optional(),
|
|
911
|
+
logo: import_zod3.z.string().optional(),
|
|
912
|
+
toolsCount: import_zod3.z.number().optional(),
|
|
913
|
+
triggersCount: import_zod3.z.number().optional(),
|
|
914
|
+
updatedAt: import_zod3.z.string().optional()
|
|
629
915
|
});
|
|
630
|
-
var ToolKitItemSchema =
|
|
631
|
-
name:
|
|
632
|
-
slug:
|
|
916
|
+
var ToolKitItemSchema = import_zod3.z.object({
|
|
917
|
+
name: import_zod3.z.string(),
|
|
918
|
+
slug: import_zod3.z.string(),
|
|
633
919
|
meta: ToolKitMetaSchema,
|
|
634
|
-
isLocalToolkit:
|
|
635
|
-
authSchemes:
|
|
636
|
-
composioManagedAuthSchemes:
|
|
637
|
-
noAuth:
|
|
920
|
+
isLocalToolkit: import_zod3.z.boolean(),
|
|
921
|
+
authSchemes: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
922
|
+
composioManagedAuthSchemes: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
923
|
+
noAuth: import_zod3.z.boolean().optional()
|
|
638
924
|
});
|
|
639
|
-
var ToolKitListResponseSchema =
|
|
640
|
-
items:
|
|
641
|
-
nextCursor:
|
|
642
|
-
totalPages:
|
|
925
|
+
var ToolKitListResponseSchema = import_zod3.z.object({
|
|
926
|
+
items: import_zod3.z.array(ToolKitItemSchema),
|
|
927
|
+
nextCursor: import_zod3.z.string().nullable(),
|
|
928
|
+
totalPages: import_zod3.z.number()
|
|
643
929
|
});
|
|
644
|
-
var ToolkitAuthFieldSchema =
|
|
645
|
-
name:
|
|
646
|
-
displayName:
|
|
647
|
-
type:
|
|
648
|
-
default:
|
|
930
|
+
var ToolkitAuthFieldSchema = import_zod3.z.object({
|
|
931
|
+
name: import_zod3.z.string(),
|
|
932
|
+
displayName: import_zod3.z.string(),
|
|
933
|
+
type: import_zod3.z.string(),
|
|
934
|
+
default: import_zod3.z.string().nullable().optional()
|
|
649
935
|
});
|
|
650
|
-
var ToolkitAuthConfigDetailsSchema =
|
|
651
|
-
name:
|
|
652
|
-
mode:
|
|
653
|
-
fields:
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
required: import_zod2.z.array(ToolkitAuthFieldSchema)
|
|
662
|
-
})
|
|
936
|
+
var ToolkitAuthConfigDetailsSchema = import_zod3.z.object({
|
|
937
|
+
name: import_zod3.z.string(),
|
|
938
|
+
mode: import_zod3.z.string(),
|
|
939
|
+
fields: import_zod3.z.object({
|
|
940
|
+
authConfigCreation: import_zod3.z.object({
|
|
941
|
+
optional: import_zod3.z.array(ToolkitAuthFieldSchema),
|
|
942
|
+
required: import_zod3.z.array(ToolkitAuthFieldSchema)
|
|
943
|
+
}),
|
|
944
|
+
connectedAccountInitiation: import_zod3.z.object({
|
|
945
|
+
optional: import_zod3.z.array(ToolkitAuthFieldSchema),
|
|
946
|
+
required: import_zod3.z.array(ToolkitAuthFieldSchema)
|
|
663
947
|
})
|
|
664
|
-
),
|
|
665
|
-
proxy:
|
|
666
|
-
|
|
667
|
-
})
|
|
948
|
+
}),
|
|
949
|
+
proxy: import_zod3.z.object({
|
|
950
|
+
baseUrl: import_zod3.z.string().optional()
|
|
951
|
+
}).optional()
|
|
668
952
|
});
|
|
669
|
-
var ToolkitRetrieveResponseSchema =
|
|
670
|
-
name:
|
|
671
|
-
slug:
|
|
953
|
+
var ToolkitRetrieveResponseSchema = import_zod3.z.object({
|
|
954
|
+
name: import_zod3.z.string(),
|
|
955
|
+
slug: import_zod3.z.string(),
|
|
672
956
|
meta: ToolKitMetaSchema,
|
|
673
|
-
isLocalToolkit:
|
|
674
|
-
composioManagedAuthSchemes:
|
|
675
|
-
authConfigDetails:
|
|
957
|
+
isLocalToolkit: import_zod3.z.boolean(),
|
|
958
|
+
composioManagedAuthSchemes: import_zod3.z.array(import_zod3.z.string()).optional(),
|
|
959
|
+
authConfigDetails: import_zod3.z.array(ToolkitAuthConfigDetailsSchema).optional()
|
|
676
960
|
});
|
|
677
|
-
var ToolkitCategorySchema =
|
|
678
|
-
id:
|
|
679
|
-
name:
|
|
961
|
+
var ToolkitCategorySchema = import_zod3.z.object({
|
|
962
|
+
id: import_zod3.z.string(),
|
|
963
|
+
name: import_zod3.z.string()
|
|
680
964
|
});
|
|
681
|
-
var ToolkitRetrieveCategoriesResponseSchema =
|
|
682
|
-
items:
|
|
683
|
-
nextCursor:
|
|
684
|
-
totalPages:
|
|
965
|
+
var ToolkitRetrieveCategoriesResponseSchema = import_zod3.z.object({
|
|
966
|
+
items: import_zod3.z.array(ToolkitCategorySchema),
|
|
967
|
+
nextCursor: import_zod3.z.string().nullable(),
|
|
968
|
+
totalPages: import_zod3.z.number()
|
|
685
969
|
});
|
|
686
970
|
|
|
687
971
|
// src/models/Toolkits.ts
|
|
688
|
-
var
|
|
972
|
+
var import_zod7 = require("zod");
|
|
973
|
+
|
|
974
|
+
// src/types/authConfigs.types.ts
|
|
975
|
+
var import_zod4 = require("zod");
|
|
976
|
+
var AuthConfigTypes = {
|
|
977
|
+
CUSTOM: "use_custom_auth",
|
|
978
|
+
COMPOSIO_MANAGED: "use_composio_managed_auth"
|
|
979
|
+
};
|
|
980
|
+
var AuthSchemeTypes = {
|
|
981
|
+
OAUTH2: "OAUTH2",
|
|
982
|
+
OAUTH1: "OAUTH1",
|
|
983
|
+
OAUTH1A: "OAUTH1A",
|
|
984
|
+
API_KEY: "API_KEY",
|
|
985
|
+
BASIC: "BASIC",
|
|
986
|
+
BILLCOM_AUTH: "BILLCOM_AUTH",
|
|
987
|
+
BEARER_TOKEN: "BEARER_TOKEN",
|
|
988
|
+
GOOGLE_SERVICE_ACCOUNT: "GOOGLE_SERVICE_ACCOUNT",
|
|
989
|
+
NO_AUTH: "NO_AUTH",
|
|
990
|
+
BASIC_WITH_JWT: "BASIC_WITH_JWT",
|
|
991
|
+
COMPOSIO_LINK: "COMPOSIO_LINK",
|
|
992
|
+
CALCOM_AUTH: "CALCOM_AUTH",
|
|
993
|
+
SNOWFLAKE: "SNOWFLAKE"
|
|
994
|
+
};
|
|
995
|
+
var AuthSchemeEnum = import_zod4.z.enum([
|
|
996
|
+
"OAUTH2",
|
|
997
|
+
"OAUTH1",
|
|
998
|
+
"OAUTH1A",
|
|
999
|
+
"API_KEY",
|
|
1000
|
+
"BASIC",
|
|
1001
|
+
"BILLCOM_AUTH",
|
|
1002
|
+
"BEARER_TOKEN",
|
|
1003
|
+
"GOOGLE_SERVICE_ACCOUNT",
|
|
1004
|
+
"NO_AUTH",
|
|
1005
|
+
"BASIC_WITH_JWT",
|
|
1006
|
+
"COMPOSIO_LINK",
|
|
1007
|
+
"CALCOM_AUTH",
|
|
1008
|
+
"SNOWFLAKE"
|
|
1009
|
+
]);
|
|
1010
|
+
var CreateCustomAuthConfigParamsSchema = import_zod4.z.object({
|
|
1011
|
+
type: import_zod4.z.literal("use_custom_auth"),
|
|
1012
|
+
name: import_zod4.z.string().optional(),
|
|
1013
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()])),
|
|
1014
|
+
authScheme: AuthSchemeEnum
|
|
1015
|
+
});
|
|
1016
|
+
var CreateComposioManagedAuthConfigParamsSchema = import_zod4.z.object({
|
|
1017
|
+
type: import_zod4.z.literal("use_composio_managed_auth"),
|
|
1018
|
+
name: import_zod4.z.string().optional(),
|
|
1019
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()])).optional()
|
|
1020
|
+
});
|
|
1021
|
+
var CreateAuthConfigParamsSchema = import_zod4.z.discriminatedUnion("type", [
|
|
1022
|
+
CreateCustomAuthConfigParamsSchema,
|
|
1023
|
+
CreateComposioManagedAuthConfigParamsSchema
|
|
1024
|
+
]);
|
|
1025
|
+
var CreateAuthConfigResponseSchema = import_zod4.z.object({
|
|
1026
|
+
id: import_zod4.z.string(),
|
|
1027
|
+
authScheme: import_zod4.z.string(),
|
|
1028
|
+
isComposioManaged: import_zod4.z.boolean(),
|
|
1029
|
+
toolkit: import_zod4.z.string()
|
|
1030
|
+
});
|
|
1031
|
+
var AuthConfigRetrieveResponseSchema = import_zod4.z.object({
|
|
1032
|
+
id: import_zod4.z.string(),
|
|
1033
|
+
name: import_zod4.z.string(),
|
|
1034
|
+
toolkit: import_zod4.z.object({
|
|
1035
|
+
logo: import_zod4.z.string(),
|
|
1036
|
+
slug: import_zod4.z.string()
|
|
1037
|
+
}),
|
|
1038
|
+
noOfConnections: import_zod4.z.number(),
|
|
1039
|
+
status: import_zod4.z.enum(["ENABLED", "DISABLED"]),
|
|
1040
|
+
uuid: import_zod4.z.string(),
|
|
1041
|
+
authScheme: AuthSchemeEnum.optional(),
|
|
1042
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.number(), import_zod4.z.boolean()])),
|
|
1043
|
+
expectedInputFields: import_zod4.z.array(import_zod4.z.unknown()).optional(),
|
|
1044
|
+
isComposioManaged: import_zod4.z.boolean().optional(),
|
|
1045
|
+
createdBy: import_zod4.z.string().optional(),
|
|
1046
|
+
createdAt: import_zod4.z.string().optional(),
|
|
1047
|
+
lastUpdatedAt: import_zod4.z.string().optional()
|
|
1048
|
+
});
|
|
1049
|
+
var AuthConfigListParamsSchema = import_zod4.z.object({
|
|
1050
|
+
cursor: import_zod4.z.string().optional(),
|
|
1051
|
+
isComposioManaged: import_zod4.z.boolean().optional(),
|
|
1052
|
+
limit: import_zod4.z.number().optional(),
|
|
1053
|
+
toolkitSlug: import_zod4.z.string().optional()
|
|
1054
|
+
});
|
|
1055
|
+
var AuthConfigListResponseSchema = import_zod4.z.object({
|
|
1056
|
+
items: import_zod4.z.array(AuthConfigRetrieveResponseSchema),
|
|
1057
|
+
nextCursor: import_zod4.z.string().optional(),
|
|
1058
|
+
totalPages: import_zod4.z.number()
|
|
1059
|
+
});
|
|
1060
|
+
var AuthCustomConfigUpdateParamsSchema = import_zod4.z.object({
|
|
1061
|
+
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.union([import_zod4.z.string(), import_zod4.z.unknown()])),
|
|
1062
|
+
type: import_zod4.z.literal("custom"),
|
|
1063
|
+
restrictToFollowingTools: import_zod4.z.array(import_zod4.z.string()).optional()
|
|
1064
|
+
});
|
|
1065
|
+
var AuthDefaultConfigUpdateParamsSchema = import_zod4.z.object({
|
|
1066
|
+
scopes: import_zod4.z.string(),
|
|
1067
|
+
type: import_zod4.z.literal("default"),
|
|
1068
|
+
restrictToFollowingTools: import_zod4.z.array(import_zod4.z.string()).optional()
|
|
1069
|
+
});
|
|
1070
|
+
var AuthConfigUpdateParamsSchema = import_zod4.z.discriminatedUnion("type", [
|
|
1071
|
+
AuthCustomConfigUpdateParamsSchema,
|
|
1072
|
+
AuthDefaultConfigUpdateParamsSchema
|
|
1073
|
+
]);
|
|
1074
|
+
|
|
1075
|
+
// src/models/AuthConfigs.ts
|
|
1076
|
+
var AuthConfigs = class {
|
|
689
1077
|
client;
|
|
690
1078
|
constructor(client) {
|
|
691
1079
|
this.client = client;
|
|
692
1080
|
}
|
|
693
1081
|
/**
|
|
694
|
-
*
|
|
695
|
-
* This
|
|
696
|
-
* @
|
|
1082
|
+
* Protected getter for the client instance.
|
|
1083
|
+
* This is primarily used for testing purposes.
|
|
1084
|
+
* @protected
|
|
697
1085
|
*/
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
const result = await this.client.toolkits.list({
|
|
701
|
-
category: parsedQuery.category,
|
|
702
|
-
is_local: parsedQuery.isLocal,
|
|
703
|
-
managed_by: parsedQuery.managedBy,
|
|
704
|
-
sort_by: parsedQuery.sortBy
|
|
705
|
-
});
|
|
706
|
-
const parsedResult = ToolKitListResponseSchema.parse({
|
|
707
|
-
items: result.items.map((item) => {
|
|
708
|
-
const parsedItem = ToolKitItemSchema.parse({
|
|
709
|
-
name: item.name,
|
|
710
|
-
slug: item.slug,
|
|
711
|
-
meta: item.meta,
|
|
712
|
-
isLocalToolkit: item.is_local_toolkit,
|
|
713
|
-
authSchemes: item.auth_schemes,
|
|
714
|
-
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
715
|
-
noAuth: item.no_auth
|
|
716
|
-
});
|
|
717
|
-
return parsedItem;
|
|
718
|
-
}),
|
|
719
|
-
nextCursor: result.next_cursor,
|
|
720
|
-
totalPages: result.total_pages
|
|
721
|
-
});
|
|
722
|
-
return parsedResult;
|
|
1086
|
+
getClient() {
|
|
1087
|
+
return this.client;
|
|
723
1088
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
1089
|
+
parseAuthConfigRetrieveResponse(authConfig) {
|
|
1090
|
+
const result = AuthConfigRetrieveResponseSchema.safeParse({
|
|
1091
|
+
id: authConfig.id,
|
|
1092
|
+
name: authConfig.name,
|
|
1093
|
+
noOfConnections: authConfig.no_of_connections,
|
|
1094
|
+
status: authConfig.status,
|
|
1095
|
+
toolkit: {
|
|
1096
|
+
logo: authConfig.toolkit.logo,
|
|
1097
|
+
slug: authConfig.toolkit.slug
|
|
1098
|
+
},
|
|
1099
|
+
uuid: authConfig.uuid,
|
|
1100
|
+
authScheme: authConfig.auth_scheme,
|
|
1101
|
+
credentials: authConfig.credentials,
|
|
1102
|
+
expectedInputFields: authConfig.expected_input_fields,
|
|
1103
|
+
isComposioManaged: authConfig.is_composio_managed,
|
|
1104
|
+
createdBy: authConfig.created_by,
|
|
1105
|
+
createdAt: authConfig.created_at,
|
|
1106
|
+
lastUpdatedAt: authConfig.last_updated_at
|
|
740
1107
|
});
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
/**
|
|
744
|
-
* Fetches a toolkit by its Slug or a list of toolkits.
|
|
745
|
-
* This method retrieves the toolkit from the Composio API.
|
|
746
|
-
* @param arg - The ID of the toolkit to be retrieved or a list of parameters
|
|
747
|
-
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit object or a list of toolkits
|
|
748
|
-
*/
|
|
749
|
-
async get(arg) {
|
|
750
|
-
if (typeof arg === "string") {
|
|
751
|
-
return this.getToolkitBySlug(arg);
|
|
1108
|
+
if (result.error) {
|
|
1109
|
+
throw new ValidationError(result.error);
|
|
752
1110
|
}
|
|
753
|
-
return
|
|
1111
|
+
return result.data;
|
|
754
1112
|
}
|
|
755
1113
|
/**
|
|
756
|
-
*
|
|
757
|
-
*
|
|
758
|
-
* @
|
|
1114
|
+
* List all auth configs
|
|
1115
|
+
* @param {AuthConfigListParams} query - Query parameters for filtering auth configs
|
|
1116
|
+
* @param {RequestOptions} options - Request options
|
|
1117
|
+
* @returns {Promise<AuthConfigListResponse>} List of auth configs
|
|
759
1118
|
*/
|
|
760
|
-
async
|
|
761
|
-
const
|
|
762
|
-
const
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
1119
|
+
async list(query) {
|
|
1120
|
+
const parsedQuery = query ? AuthConfigListParamsSchema.parse(query) : void 0;
|
|
1121
|
+
const result = await this.client.authConfigs.list({
|
|
1122
|
+
cursor: parsedQuery?.cursor,
|
|
1123
|
+
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1124
|
+
limit: parsedQuery?.limit?.toString(),
|
|
1125
|
+
toolkit_slug: parsedQuery?.toolkitSlug
|
|
1126
|
+
});
|
|
1127
|
+
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
1128
|
+
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
770
1129
|
nextCursor: result.next_cursor,
|
|
771
1130
|
totalPages: result.total_pages
|
|
772
1131
|
});
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
};
|
|
776
|
-
|
|
777
|
-
// src/utils/pusher.ts
|
|
778
|
-
var PUSHER_KEY = process.env.CLIENT_PUSHER_KEY || "ff9f18c208855d77a152";
|
|
779
|
-
var PUSHER_CLUSTER = "mt1";
|
|
780
|
-
var PusherUtils = class _PusherUtils {
|
|
781
|
-
static pusherClient;
|
|
782
|
-
static getPusherClient(baseURL, apiKey) {
|
|
783
|
-
if (!_PusherUtils.pusherClient) {
|
|
784
|
-
const PusherClient = require("pusher-js");
|
|
785
|
-
_PusherUtils.pusherClient = new PusherClient(PUSHER_KEY, {
|
|
786
|
-
cluster: PUSHER_CLUSTER,
|
|
787
|
-
channelAuthorization: {
|
|
788
|
-
endpoint: `${baseURL}/api/v1/client/auth/pusher_auth`,
|
|
789
|
-
headers: {
|
|
790
|
-
"x-api-key": apiKey
|
|
791
|
-
},
|
|
792
|
-
transport: "ajax"
|
|
793
|
-
}
|
|
794
|
-
});
|
|
1132
|
+
if (parsedResult.error) {
|
|
1133
|
+
throw new ValidationError(parsedResult.error);
|
|
795
1134
|
}
|
|
796
|
-
return
|
|
1135
|
+
return parsedResult.data;
|
|
797
1136
|
}
|
|
798
1137
|
/**
|
|
799
|
-
*
|
|
800
|
-
* @param {string}
|
|
801
|
-
* @param {
|
|
802
|
-
* @
|
|
803
|
-
*
|
|
1138
|
+
* Create a new auth config
|
|
1139
|
+
* @param {string} toolkit - Unique identifier of the toolkit
|
|
1140
|
+
* @param {CreateAuthConfigParams} options - Options for creating a new auth config
|
|
1141
|
+
* @returns {Promise<CreateAuthConfigResponse>} Created auth config
|
|
1142
|
+
*
|
|
1143
|
+
* @example
|
|
1144
|
+
* const authConfig = await authConfigs.create('my-toolkit', {
|
|
1145
|
+
* type: AuthConfigTypes.CUSTOM,
|
|
1146
|
+
* name: 'My Custom Auth Config',
|
|
1147
|
+
* authScheme: AuthSchemeTypes.API_KEY,
|
|
1148
|
+
* credentials: {
|
|
1149
|
+
* apiKey: '1234567890',
|
|
1150
|
+
* },
|
|
1151
|
+
* });
|
|
1152
|
+
*
|
|
1153
|
+
* @link https://docs.composio.dev/reference/auth-configs/create-auth-config
|
|
804
1154
|
*/
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
1155
|
+
async create(toolkit, options) {
|
|
1156
|
+
const parsedOptions = CreateAuthConfigParamsSchema.safeParse(options);
|
|
1157
|
+
if (parsedOptions.error) {
|
|
1158
|
+
throw new ValidationError(parsedOptions.error);
|
|
1159
|
+
}
|
|
1160
|
+
const result = await this.client.authConfigs.create({
|
|
1161
|
+
toolkit: {
|
|
1162
|
+
slug: toolkit
|
|
1163
|
+
},
|
|
1164
|
+
auth_config: parsedOptions.data
|
|
1165
|
+
});
|
|
1166
|
+
const parsedResult = CreateAuthConfigResponseSchema.safeParse({
|
|
1167
|
+
id: result.auth_config.id,
|
|
1168
|
+
authScheme: result.auth_config.auth_scheme,
|
|
1169
|
+
isComposioManaged: result.auth_config.is_composio_managed,
|
|
1170
|
+
toolkit: result.toolkit.slug
|
|
1171
|
+
});
|
|
1172
|
+
if (parsedResult.error) {
|
|
1173
|
+
throw new ValidationError(parsedResult.error);
|
|
812
1174
|
}
|
|
1175
|
+
return parsedResult.data;
|
|
813
1176
|
}
|
|
814
1177
|
/**
|
|
815
|
-
*
|
|
816
|
-
* @param {string}
|
|
817
|
-
* @
|
|
1178
|
+
* Get an auth config by nanoid
|
|
1179
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1180
|
+
* @param {RequestOptions} options - Request options
|
|
1181
|
+
* @returns {Promise<AuthConfigRetrieveResponse>} Auth config details
|
|
818
1182
|
*/
|
|
819
|
-
|
|
820
|
-
|
|
1183
|
+
async get(nanoid) {
|
|
1184
|
+
const result = await this.client.authConfigs.retrieve(nanoid);
|
|
1185
|
+
return this.parseAuthConfigRetrieveResponse(result);
|
|
821
1186
|
}
|
|
822
1187
|
/**
|
|
823
|
-
*
|
|
824
|
-
* @param {
|
|
825
|
-
* @param {
|
|
826
|
-
* @param {
|
|
1188
|
+
* Update an auth config
|
|
1189
|
+
* @param {string} nanoid - Unique identifier of the auth config to update
|
|
1190
|
+
* @param {AuthConfigUpdateParams} data - Data to update
|
|
1191
|
+
* @param {RequestOptions} options - Request options
|
|
1192
|
+
* @returns {Promise<AuthConfigUpdateResponse>} Updated auth config
|
|
827
1193
|
*/
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
1194
|
+
async update(nanoid, data) {
|
|
1195
|
+
const parsedData = AuthConfigUpdateParamsSchema.safeParse(data);
|
|
1196
|
+
if (parsedData.error) {
|
|
1197
|
+
throw new ValidationError(parsedData.error);
|
|
1198
|
+
}
|
|
1199
|
+
return this.client.authConfigs.update(
|
|
1200
|
+
nanoid,
|
|
1201
|
+
parsedData.data.type === "custom" ? {
|
|
1202
|
+
type: "custom",
|
|
1203
|
+
credentials: parsedData.data.credentials,
|
|
1204
|
+
restrict_to_following_tools: parsedData.data.restrictToFollowingTools
|
|
1205
|
+
} : {
|
|
1206
|
+
type: "default",
|
|
1207
|
+
scopes: parsedData.data.scopes,
|
|
1208
|
+
restrict_to_following_tools: parsedData.data.restrictToFollowingTools
|
|
835
1209
|
}
|
|
836
|
-
const ev = events[typedData.id];
|
|
837
|
-
ev.chunks[typedData.index] = typedData.chunk;
|
|
838
|
-
if (typedData.final) ev.receivedFinal = true;
|
|
839
|
-
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
840
|
-
callback(JSON.parse(ev.chunks.join("")));
|
|
841
|
-
delete events[typedData.id];
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
}
|
|
845
|
-
/**
|
|
846
|
-
* Subscribes to a trigger channel for a client and handles chunked data.
|
|
847
|
-
* @param {string} clientId - The unique identifier for the client subscribing to the events.
|
|
848
|
-
* @param {(data: TriggerData) => void} fn - The callback function to execute when trigger data is received.
|
|
849
|
-
*/
|
|
850
|
-
static triggerSubscribe(clientId, fn) {
|
|
851
|
-
const channel = _PusherUtils.pusherClient.subscribe(
|
|
852
|
-
`private-${clientId}_triggers`
|
|
853
1210
|
);
|
|
854
|
-
_PusherUtils.bindWithChunking(
|
|
855
|
-
channel,
|
|
856
|
-
"trigger_to_client",
|
|
857
|
-
fn
|
|
858
|
-
);
|
|
859
|
-
logger_default.info(
|
|
860
|
-
`Subscribed to triggers. You should start receiving events now.`
|
|
861
|
-
);
|
|
862
|
-
}
|
|
863
|
-
static triggerUnsubscribe(clientId) {
|
|
864
|
-
_PusherUtils.pusherClient.unsubscribe(`${clientId}_triggers`);
|
|
865
|
-
}
|
|
866
|
-
};
|
|
867
|
-
|
|
868
|
-
// src/models/Session.ts
|
|
869
|
-
var Session = class {
|
|
870
|
-
client;
|
|
871
|
-
constructor(client) {
|
|
872
|
-
this.client = client;
|
|
873
|
-
}
|
|
874
|
-
/**
|
|
875
|
-
* Get the active session info
|
|
876
|
-
* @returns {Promise<SessionGetInfoResponse>} Session info
|
|
877
|
-
*/
|
|
878
|
-
async getInfo() {
|
|
879
|
-
return this.client.auth.session.getInfo();
|
|
880
|
-
}
|
|
881
|
-
};
|
|
882
|
-
|
|
883
|
-
// src/models/Triggers.ts
|
|
884
|
-
var Triggers = class {
|
|
885
|
-
client;
|
|
886
|
-
constructor(client) {
|
|
887
|
-
this.client = client;
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Fetch list of all the active triggers
|
|
891
|
-
* @returns {Promise<TriggerInstance[]>} List of trigger instances
|
|
892
|
-
*/
|
|
893
|
-
async list(query, options) {
|
|
894
|
-
return this.client.triggerInstances.listActive(query, options);
|
|
895
|
-
}
|
|
896
|
-
/**
|
|
897
|
-
* Create a new trigger instance
|
|
898
|
-
*
|
|
899
|
-
* @param {string} slug - The slug of the trigger instance
|
|
900
|
-
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
901
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
902
|
-
*/
|
|
903
|
-
async create(slug, body, options) {
|
|
904
|
-
return this.client.triggerInstances.upsert(slug, body, options);
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* Update an existing trigger instance
|
|
908
|
-
*
|
|
909
|
-
* @param {string} slug - The slug of the trigger instance
|
|
910
|
-
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
911
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
912
|
-
*/
|
|
913
|
-
async update(slug, body, options) {
|
|
914
|
-
return this.client.triggerInstances.upsert(slug, body, options);
|
|
915
|
-
}
|
|
916
|
-
/**
|
|
917
|
-
* Delete a trigger instance
|
|
918
|
-
*
|
|
919
|
-
* @param {string} slug - The slug of the trigger instance
|
|
920
|
-
* @returns
|
|
921
|
-
*/
|
|
922
|
-
async delete(slug) {
|
|
923
|
-
return this.client.triggerInstances.removeUpsert(slug);
|
|
924
1211
|
}
|
|
925
1212
|
/**
|
|
926
|
-
*
|
|
927
|
-
*
|
|
928
|
-
* @param {TriggerStatusEnum} status - The new status of the trigger
|
|
929
|
-
* @param {TriggerInstanceUpdateStatusParams} params - The parameters to update the trigger instance
|
|
1213
|
+
* Delete an auth config
|
|
1214
|
+
* @param {string} nanoid - Unique identifier of the auth config to delete
|
|
930
1215
|
* @param {RequestOptions} options - Request options
|
|
931
|
-
* @returns {Promise<
|
|
932
|
-
*/
|
|
933
|
-
async updateStatus(status, params, options) {
|
|
934
|
-
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
935
|
-
}
|
|
936
|
-
/**
|
|
937
|
-
* Disable a trigger instance
|
|
938
|
-
*
|
|
939
|
-
* @param {string} slug - The slug of the trigger instance
|
|
940
|
-
* @param {RequestOptions options - Request options
|
|
941
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
942
|
-
*/
|
|
943
|
-
async disable(slug, options) {
|
|
944
|
-
return this.client.triggerInstances.updateStatus("disable", { slug }, options);
|
|
945
|
-
}
|
|
946
|
-
/**
|
|
947
|
-
* Enable a trigger instance
|
|
948
|
-
*
|
|
949
|
-
* @param {string} slug - The slug of the trigger instance
|
|
950
|
-
* @param {RequestOptions options - Request options
|
|
951
|
-
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1216
|
+
* @returns {Promise<AuthConfigDeleteResponse>} Response from deletion
|
|
952
1217
|
*/
|
|
953
|
-
async
|
|
954
|
-
return this.client.
|
|
1218
|
+
async delete(nanoid) {
|
|
1219
|
+
return this.client.authConfigs.delete(nanoid);
|
|
955
1220
|
}
|
|
956
1221
|
/**
|
|
957
|
-
*
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
* List all the trigger types
|
|
961
|
-
*
|
|
962
|
-
* @param {TriggersTypeListParams} query - The query parameters to filter the trigger types
|
|
1222
|
+
* Update the status of an auth config
|
|
1223
|
+
* @param {string} status - The status to update the auth config to
|
|
1224
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
963
1225
|
* @param {RequestOptions} options - Request options
|
|
964
|
-
* @returns {Promise<
|
|
1226
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
965
1227
|
*/
|
|
966
|
-
async
|
|
967
|
-
return this.client.
|
|
1228
|
+
async updateStatus(status, nanoid) {
|
|
1229
|
+
return this.client.authConfigs.updateStatus(status, { nanoid });
|
|
968
1230
|
}
|
|
969
1231
|
/**
|
|
970
|
-
*
|
|
971
|
-
*
|
|
972
|
-
* @param {
|
|
973
|
-
* @
|
|
974
|
-
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
1232
|
+
* Enable an auth config
|
|
1233
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1234
|
+
* @param {RequestOptions} options - Request options
|
|
1235
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
975
1236
|
*/
|
|
976
|
-
async
|
|
977
|
-
return this.client.
|
|
1237
|
+
async enable(nanoid) {
|
|
1238
|
+
return this.client.authConfigs.updateStatus("ENABLED", { nanoid });
|
|
978
1239
|
}
|
|
979
1240
|
/**
|
|
980
|
-
*
|
|
981
|
-
*
|
|
982
|
-
*
|
|
983
|
-
* @
|
|
984
|
-
* @returns
|
|
1241
|
+
* Disable an auth config
|
|
1242
|
+
* @param {string} nanoid - Unique identifier of the auth config
|
|
1243
|
+
* @param {RequestOptions} options - Request options
|
|
1244
|
+
* @returns {Promise<AuthConfigUpdateStatusResponse>} Updated auth config details
|
|
985
1245
|
*/
|
|
986
|
-
async
|
|
987
|
-
return this.client.
|
|
1246
|
+
async disable(nanoid) {
|
|
1247
|
+
return this.client.authConfigs.updateStatus("DISABLED", { nanoid });
|
|
988
1248
|
}
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
fn(data);
|
|
1006
|
-
}
|
|
1249
|
+
};
|
|
1250
|
+
|
|
1251
|
+
// src/errors/AuthConfigErrors.ts
|
|
1252
|
+
var AuthConfigErrorCodes = {
|
|
1253
|
+
AUTH_CONFIG_NOT_FOUND: "AUTH_CONFIG_NOT_FOUND"
|
|
1254
|
+
};
|
|
1255
|
+
var ComposioAuthConfigNotFoundError = class extends ComposioError {
|
|
1256
|
+
constructor(message, meta) {
|
|
1257
|
+
super(message, {
|
|
1258
|
+
code: AuthConfigErrorCodes.AUTH_CONFIG_NOT_FOUND,
|
|
1259
|
+
cause: meta,
|
|
1260
|
+
possibleFixes: [
|
|
1261
|
+
"Check if the auth config exists",
|
|
1262
|
+
"Check if the auth config id is correct",
|
|
1263
|
+
"Check if the auth config is enabled"
|
|
1264
|
+
]
|
|
1007
1265
|
});
|
|
1008
|
-
|
|
1009
|
-
async unsubscribe() {
|
|
1010
|
-
const session = new Session(this.client);
|
|
1011
|
-
const sessionInfo = await session.getInfo();
|
|
1012
|
-
const clientId = sessionInfo.project?.id;
|
|
1013
|
-
if (!clientId) throw new Error("Client ID not found");
|
|
1014
|
-
PusherUtils.triggerUnsubscribe(clientId);
|
|
1266
|
+
this.name = "ComposioAuthConfigNotFoundError";
|
|
1015
1267
|
}
|
|
1016
1268
|
};
|
|
1017
1269
|
|
|
1018
|
-
// src/types/
|
|
1019
|
-
var
|
|
1020
|
-
var
|
|
1021
|
-
|
|
1022
|
-
|
|
1270
|
+
// src/types/connectedAccounts.types.ts
|
|
1271
|
+
var import_zod5 = require("zod");
|
|
1272
|
+
var ConnectedAccountStatuses = {
|
|
1273
|
+
ACTIVE: "ACTIVE",
|
|
1274
|
+
INACTIVE: "INACTIVE",
|
|
1275
|
+
DELETED: "DELETED",
|
|
1276
|
+
INITIATED: "INITIATED",
|
|
1277
|
+
EXPIRED: "EXPIRED",
|
|
1278
|
+
FAILED: "FAILED"
|
|
1023
1279
|
};
|
|
1024
|
-
var
|
|
1280
|
+
var ConnectedAccountStatusSchema = import_zod5.z.enum([
|
|
1281
|
+
ConnectedAccountStatuses.ACTIVE,
|
|
1282
|
+
ConnectedAccountStatuses.INACTIVE,
|
|
1283
|
+
ConnectedAccountStatuses.DELETED,
|
|
1284
|
+
ConnectedAccountStatuses.INITIATED,
|
|
1285
|
+
ConnectedAccountStatuses.EXPIRED,
|
|
1286
|
+
ConnectedAccountStatuses.FAILED
|
|
1287
|
+
]);
|
|
1288
|
+
var CreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
1289
|
+
authConfig: import_zod5.z.object({
|
|
1290
|
+
id: import_zod5.z.string()
|
|
1291
|
+
}),
|
|
1292
|
+
connection: import_zod5.z.object({
|
|
1293
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1294
|
+
redirectUrl: import_zod5.z.string().optional(),
|
|
1295
|
+
userId: import_zod5.z.string().optional()
|
|
1296
|
+
})
|
|
1297
|
+
});
|
|
1298
|
+
var DefaultCreateConnectedAccountParamsSchema = import_zod5.z.object({
|
|
1299
|
+
auth_config: import_zod5.z.object({
|
|
1300
|
+
id: import_zod5.z.string()
|
|
1301
|
+
}),
|
|
1302
|
+
connection: import_zod5.z.object({
|
|
1303
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional(),
|
|
1304
|
+
redirect_uri: import_zod5.z.string().optional(),
|
|
1305
|
+
user_id: import_zod5.z.string().optional()
|
|
1306
|
+
})
|
|
1307
|
+
});
|
|
1308
|
+
var CreateConnectedAccountOptionsSchema = import_zod5.z.object({
|
|
1309
|
+
redirectUrl: import_zod5.z.string().optional(),
|
|
1310
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()).optional()
|
|
1311
|
+
});
|
|
1312
|
+
var CreateConnectedAccountResponseSchema = import_zod5.z.object({
|
|
1313
|
+
id: import_zod5.z.string(),
|
|
1314
|
+
status: ConnectedAccountStatusSchema,
|
|
1315
|
+
redirectUrl: import_zod5.z.string().nullable()
|
|
1316
|
+
});
|
|
1317
|
+
var ConnectedAccountAuthSchemes = {
|
|
1025
1318
|
OAUTH2: "OAUTH2",
|
|
1026
1319
|
OAUTH1: "OAUTH1",
|
|
1027
1320
|
OAUTH1A: "OAUTH1A",
|
|
@@ -1036,492 +1329,652 @@ var AuthSchemeTypes = {
|
|
|
1036
1329
|
CALCOM_AUTH: "CALCOM_AUTH",
|
|
1037
1330
|
SNOWFLAKE: "SNOWFLAKE"
|
|
1038
1331
|
};
|
|
1039
|
-
var
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
]);
|
|
1054
|
-
var CreateCustomAuthConfigParamsSchema = import_zod3.z.object({
|
|
1055
|
-
type: import_zod3.z.literal("use_custom_auth"),
|
|
1056
|
-
name: import_zod3.z.string().optional(),
|
|
1057
|
-
credentials: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean()])),
|
|
1058
|
-
authScheme: AuthSchemeEnum
|
|
1059
|
-
});
|
|
1060
|
-
var CreateComposioManagedAuthConfigParamsSchema = import_zod3.z.object({
|
|
1061
|
-
type: import_zod3.z.literal("use_composio_managed_auth"),
|
|
1062
|
-
name: import_zod3.z.string().optional(),
|
|
1063
|
-
credentials: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean()])).optional()
|
|
1064
|
-
});
|
|
1065
|
-
var CreateAuthConfigParamsSchema = import_zod3.z.discriminatedUnion("type", [
|
|
1066
|
-
CreateCustomAuthConfigParamsSchema,
|
|
1067
|
-
CreateComposioManagedAuthConfigParamsSchema
|
|
1332
|
+
var ConnectedAccountAuthSchemesSchema = import_zod5.z.enum([
|
|
1333
|
+
ConnectedAccountAuthSchemes.OAUTH2,
|
|
1334
|
+
ConnectedAccountAuthSchemes.OAUTH1,
|
|
1335
|
+
ConnectedAccountAuthSchemes.OAUTH1A,
|
|
1336
|
+
ConnectedAccountAuthSchemes.API_KEY,
|
|
1337
|
+
ConnectedAccountAuthSchemes.BASIC,
|
|
1338
|
+
ConnectedAccountAuthSchemes.BILLCOM_AUTH,
|
|
1339
|
+
ConnectedAccountAuthSchemes.BEARER_TOKEN,
|
|
1340
|
+
ConnectedAccountAuthSchemes.GOOGLE_SERVICE_ACCOUNT,
|
|
1341
|
+
ConnectedAccountAuthSchemes.NO_AUTH,
|
|
1342
|
+
ConnectedAccountAuthSchemes.BASIC_WITH_JWT,
|
|
1343
|
+
ConnectedAccountAuthSchemes.COMPOSIO_LINK,
|
|
1344
|
+
ConnectedAccountAuthSchemes.CALCOM_AUTH,
|
|
1345
|
+
ConnectedAccountAuthSchemes.SNOWFLAKE
|
|
1068
1346
|
]);
|
|
1069
|
-
var
|
|
1070
|
-
id:
|
|
1071
|
-
authScheme:
|
|
1072
|
-
isComposioManaged:
|
|
1073
|
-
|
|
1347
|
+
var ConnectedAccountAuthConfigSchema = import_zod5.z.object({
|
|
1348
|
+
id: import_zod5.z.string(),
|
|
1349
|
+
authScheme: ConnectedAccountAuthSchemesSchema,
|
|
1350
|
+
isComposioManaged: import_zod5.z.boolean(),
|
|
1351
|
+
isDisabled: import_zod5.z.boolean()
|
|
1074
1352
|
});
|
|
1075
|
-
var
|
|
1076
|
-
id:
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1353
|
+
var ConnectedAccountRetrieveResponseSchema = import_zod5.z.object({
|
|
1354
|
+
id: import_zod5.z.string(),
|
|
1355
|
+
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1356
|
+
userId: import_zod5.z.string(),
|
|
1357
|
+
data: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
|
|
1358
|
+
params: import_zod5.z.record(import_zod5.z.string(), import_zod5.z.unknown()),
|
|
1359
|
+
status: ConnectedAccountStatusSchema,
|
|
1360
|
+
statusReason: import_zod5.z.string().nullable(),
|
|
1361
|
+
toolkit: import_zod5.z.object({
|
|
1362
|
+
slug: import_zod5.z.string()
|
|
1081
1363
|
}),
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
credentials: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean()])),
|
|
1087
|
-
expectedInputFields: import_zod3.z.array(import_zod3.z.unknown()).optional(),
|
|
1088
|
-
isComposioManaged: import_zod3.z.boolean().optional(),
|
|
1089
|
-
createdBy: import_zod3.z.string().optional(),
|
|
1090
|
-
createdAt: import_zod3.z.string().optional(),
|
|
1091
|
-
lastUpdatedAt: import_zod3.z.string().optional()
|
|
1092
|
-
});
|
|
1093
|
-
var AuthConfigListParamsSchema = import_zod3.z.object({
|
|
1094
|
-
cursor: import_zod3.z.string().optional(),
|
|
1095
|
-
isComposioManaged: import_zod3.z.boolean().optional(),
|
|
1096
|
-
limit: import_zod3.z.number().optional(),
|
|
1097
|
-
toolkitSlug: import_zod3.z.string().optional()
|
|
1098
|
-
});
|
|
1099
|
-
var AuthConfigListResponseSchema = import_zod3.z.object({
|
|
1100
|
-
items: import_zod3.z.array(AuthConfigRetrieveResponseSchema),
|
|
1101
|
-
nextCursor: import_zod3.z.string().optional(),
|
|
1102
|
-
totalPages: import_zod3.z.number()
|
|
1103
|
-
});
|
|
1104
|
-
var AuthConfigUpdateParamsSchema = import_zod3.z.object({
|
|
1105
|
-
credentials: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.union([import_zod3.z.string(), import_zod3.z.number(), import_zod3.z.boolean()]))
|
|
1364
|
+
testRequestEndpoint: import_zod5.z.string().optional(),
|
|
1365
|
+
isDisabled: import_zod5.z.boolean(),
|
|
1366
|
+
createdAt: import_zod5.z.string(),
|
|
1367
|
+
updatedAt: import_zod5.z.string()
|
|
1106
1368
|
});
|
|
1107
1369
|
|
|
1108
|
-
// src/models/
|
|
1109
|
-
var
|
|
1370
|
+
// src/models/ConnectionRequest.ts
|
|
1371
|
+
var import_zod6 = require("zod");
|
|
1372
|
+
|
|
1373
|
+
// src/errors/ConnectionRequestError.ts
|
|
1374
|
+
var ConnectionRequestErrorCodes = {
|
|
1375
|
+
CONNECTION_REQUEST_TIMEOUT: "CONNECTION_REQUEST_TIMEOUT",
|
|
1376
|
+
CONNECTION_REQUEST_FAILED: "CONNECTION_REQUEST_FAILED"
|
|
1377
|
+
};
|
|
1378
|
+
var ConnectionRequestTimeoutError = class extends ComposioError {
|
|
1379
|
+
constructor(message = "Connection request timed out", meta = {}) {
|
|
1380
|
+
super(message, {
|
|
1381
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_TIMEOUT,
|
|
1382
|
+
meta
|
|
1383
|
+
});
|
|
1384
|
+
this.name = "ConnectionRequestTimeoutError";
|
|
1385
|
+
}
|
|
1386
|
+
};
|
|
1387
|
+
var ConnectionRequestFailedError = class extends ComposioError {
|
|
1388
|
+
constructor(message = "Connection request failed", meta = {}) {
|
|
1389
|
+
super(message, {
|
|
1390
|
+
code: ConnectionRequestErrorCodes.CONNECTION_REQUEST_FAILED,
|
|
1391
|
+
meta
|
|
1392
|
+
});
|
|
1393
|
+
this.name = "ConnectionRequestFailedError";
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
|
|
1397
|
+
// src/models/ConnectionRequest.ts
|
|
1398
|
+
var ConnectionRequest = class {
|
|
1110
1399
|
client;
|
|
1111
|
-
|
|
1400
|
+
connectedAccountId;
|
|
1401
|
+
connectedAccountStatus;
|
|
1402
|
+
redirectUrl;
|
|
1403
|
+
constructor(client, connectedAccountId, connectedAccountStatus, redirectUrl) {
|
|
1112
1404
|
this.client = client;
|
|
1405
|
+
this.connectedAccountId = connectedAccountId;
|
|
1406
|
+
this.connectedAccountStatus = connectedAccountStatus;
|
|
1407
|
+
this.redirectUrl = redirectUrl;
|
|
1113
1408
|
}
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1409
|
+
/**
|
|
1410
|
+
* Transform the response from the Composio API to the SDK format
|
|
1411
|
+
* @param response
|
|
1412
|
+
* @returns
|
|
1413
|
+
*/
|
|
1414
|
+
async transformResponse(response) {
|
|
1415
|
+
try {
|
|
1416
|
+
const parsedResponse = ConnectedAccountRetrieveResponseSchema.parse({
|
|
1417
|
+
...response,
|
|
1418
|
+
userId: response.user_id,
|
|
1419
|
+
// Add the missing userId property
|
|
1420
|
+
authConfig: {
|
|
1421
|
+
...response.auth_config,
|
|
1422
|
+
authScheme: response.auth_config.auth_scheme,
|
|
1423
|
+
isComposioManaged: response.auth_config.is_composio_managed,
|
|
1424
|
+
isDisabled: response.auth_config.is_disabled
|
|
1425
|
+
},
|
|
1426
|
+
statusReason: response.status_reason,
|
|
1427
|
+
isDisabled: response.is_disabled,
|
|
1428
|
+
createdAt: response.created_at,
|
|
1429
|
+
updatedAt: response.updated_at,
|
|
1430
|
+
testRequestEndpoint: response.test_request_endpoint
|
|
1431
|
+
});
|
|
1432
|
+
return parsedResponse;
|
|
1433
|
+
} catch (error) {
|
|
1434
|
+
logger_default.error("Error transforming response", error);
|
|
1435
|
+
if (error instanceof import_zod6.ZodError) {
|
|
1436
|
+
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1437
|
+
}
|
|
1438
|
+
throw error;
|
|
1439
|
+
}
|
|
1133
1440
|
}
|
|
1134
1441
|
/**
|
|
1135
|
-
*
|
|
1136
|
-
*
|
|
1442
|
+
* Wait for the connection to be established.
|
|
1443
|
+
* The function will poll the Composio API every second until the connection is established or the timeout is reached.
|
|
1444
|
+
* @param {number} timeout - The time in milliseconds to wait for the connection to be established. Default is 30 seconds.
|
|
1445
|
+
* @returns
|
|
1446
|
+
*/
|
|
1447
|
+
async waitForConnection(timeout = 6e4) {
|
|
1448
|
+
if (this.connectedAccountStatus === ConnectedAccountStatuses.ACTIVE) {
|
|
1449
|
+
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1450
|
+
return this.transformResponse(response);
|
|
1451
|
+
}
|
|
1452
|
+
const terminalErrorStates = [
|
|
1453
|
+
ConnectedAccountStatuses.FAILED,
|
|
1454
|
+
ConnectedAccountStatuses.EXPIRED,
|
|
1455
|
+
ConnectedAccountStatuses.DELETED
|
|
1456
|
+
];
|
|
1457
|
+
const start = Date.now();
|
|
1458
|
+
const pollInterval = 1e3;
|
|
1459
|
+
while (Date.now() - start < timeout) {
|
|
1460
|
+
try {
|
|
1461
|
+
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1462
|
+
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1463
|
+
return this.transformResponse(response);
|
|
1464
|
+
}
|
|
1465
|
+
if (terminalErrorStates.includes(response.status)) {
|
|
1466
|
+
throw new ConnectionRequestFailedError(
|
|
1467
|
+
`Connection request failed with status: ${response.status}${response.status_reason ? `, reason: ${response.status_reason}` : ""}`,
|
|
1468
|
+
{
|
|
1469
|
+
userId: response.user_id,
|
|
1470
|
+
connectedAccountId: this.connectedAccountId,
|
|
1471
|
+
status: response.status,
|
|
1472
|
+
statusReason: response.status_reason
|
|
1473
|
+
}
|
|
1474
|
+
);
|
|
1475
|
+
}
|
|
1476
|
+
await new Promise((resolve) => setTimeout(resolve, pollInterval));
|
|
1477
|
+
} catch (error) {
|
|
1478
|
+
throw error;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
throw new ConnectionRequestTimeoutError(
|
|
1482
|
+
`Connection request timed out for ${this.connectedAccountId}`
|
|
1483
|
+
);
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
// src/models/ConnectedAccounts.ts
|
|
1488
|
+
var ConnectedAccounts = class {
|
|
1489
|
+
client;
|
|
1490
|
+
constructor(client) {
|
|
1491
|
+
this.client = client;
|
|
1492
|
+
}
|
|
1493
|
+
/**
|
|
1494
|
+
* List all connected accounts
|
|
1495
|
+
* @param {ConnectedAccountListParams} query - Query parameters for filtering connected accounts
|
|
1137
1496
|
* @param {RequestOptions} options - Request options
|
|
1138
|
-
* @returns {Promise<
|
|
1497
|
+
* @returns {Promise<ConnectedAccountListResponse>} List of connected accounts
|
|
1139
1498
|
*/
|
|
1140
1499
|
async list(query) {
|
|
1141
|
-
|
|
1142
|
-
const result = await this.client.authConfigs.list({
|
|
1143
|
-
cursor: parsedQuery?.cursor,
|
|
1144
|
-
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1145
|
-
limit: parsedQuery?.limit?.toString(),
|
|
1146
|
-
toolkit_slug: parsedQuery?.toolkitSlug
|
|
1147
|
-
});
|
|
1148
|
-
return AuthConfigListResponseSchema.parse({
|
|
1149
|
-
items: result.items.map((item) => this.parseAuthConfigRetrieveResponse(item)),
|
|
1150
|
-
nextCursor: result.next_cursor,
|
|
1151
|
-
totalPages: result.total_pages
|
|
1152
|
-
});
|
|
1500
|
+
return this.client.connectedAccounts.list(query);
|
|
1153
1501
|
}
|
|
1154
1502
|
/**
|
|
1155
|
-
*
|
|
1156
|
-
*
|
|
1157
|
-
*
|
|
1158
|
-
* @
|
|
1503
|
+
* Compound function to create a new connected account.
|
|
1504
|
+
* This function creates a new connected account and returns a connection request.
|
|
1505
|
+
* Users can then wait for the connection to be established using the `waitForConnection` method.
|
|
1506
|
+
* @param {string} userId - User ID of the connected account
|
|
1507
|
+
* @param {string} authConfigId - Auth config ID of the connected account
|
|
1508
|
+
* @param {CreateConnectedAccountOptions} data - Data for creating a new connected account
|
|
1509
|
+
* @returns {Promise<ConnectionRequest>} Connection request object
|
|
1159
1510
|
*
|
|
1160
1511
|
* @example
|
|
1161
|
-
* const
|
|
1162
|
-
*
|
|
1163
|
-
*
|
|
1164
|
-
* authScheme: AuthSchemeTypes.API_KEY,
|
|
1165
|
-
* credentials: {
|
|
1166
|
-
* apiKey: '1234567890',
|
|
1512
|
+
* const connectionRequest = await composio.createConnectedAccount('user_123', 'auth_config_123', {
|
|
1513
|
+
* data: {
|
|
1514
|
+
* name: 'My Connected Account',
|
|
1167
1515
|
* },
|
|
1168
1516
|
* });
|
|
1169
1517
|
*
|
|
1170
|
-
* @link https://docs.composio.dev/reference/
|
|
1518
|
+
* @link https://docs.composio.dev/reference/connected-accounts/create-connected-account
|
|
1171
1519
|
*/
|
|
1172
|
-
async
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
slug: toolkit
|
|
1520
|
+
async initiate(userId, authConfigId, options) {
|
|
1521
|
+
const response = await this.client.connectedAccounts.create({
|
|
1522
|
+
auth_config: {
|
|
1523
|
+
id: authConfigId
|
|
1177
1524
|
},
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
isComposioManaged: result.auth_config.is_composio_managed,
|
|
1184
|
-
toolkit: result.toolkit.slug
|
|
1525
|
+
connection: {
|
|
1526
|
+
data: options?.data,
|
|
1527
|
+
redirect_uri: options?.redirectUrl,
|
|
1528
|
+
user_id: userId
|
|
1529
|
+
}
|
|
1185
1530
|
});
|
|
1531
|
+
return new ConnectionRequest(this.client, response.id, response.status, response.redirect_uri);
|
|
1186
1532
|
}
|
|
1187
1533
|
/**
|
|
1188
|
-
* Get
|
|
1189
|
-
* @param {string} nanoid - Unique identifier of the
|
|
1534
|
+
* Get a connected account by nanoid
|
|
1535
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1190
1536
|
* @param {RequestOptions} options - Request options
|
|
1191
|
-
* @returns {Promise<
|
|
1537
|
+
* @returns {Promise<ConnectedAccountRetrieveResponse>} Connected account details
|
|
1192
1538
|
*/
|
|
1193
1539
|
async get(nanoid) {
|
|
1194
|
-
|
|
1195
|
-
return this.parseAuthConfigRetrieveResponse(result);
|
|
1540
|
+
return this.client.connectedAccounts.retrieve(nanoid);
|
|
1196
1541
|
}
|
|
1197
1542
|
/**
|
|
1198
|
-
*
|
|
1199
|
-
* @param {string} nanoid - Unique identifier of the
|
|
1200
|
-
* @param {AuthConfigUpdateParams} data - Data to update
|
|
1543
|
+
* Delete a connected account
|
|
1544
|
+
* @param {string} nanoid - Unique identifier of the connected account to delete
|
|
1201
1545
|
* @param {RequestOptions} options - Request options
|
|
1202
|
-
* @returns {Promise<
|
|
1546
|
+
* @returns {Promise<ConnectedAccountDeleteResponse>} Response from deletion
|
|
1203
1547
|
*/
|
|
1204
|
-
async
|
|
1205
|
-
return this.client.
|
|
1206
|
-
auth_config: {
|
|
1207
|
-
credentials: data.credentials
|
|
1208
|
-
}
|
|
1209
|
-
});
|
|
1548
|
+
async delete(nanoid) {
|
|
1549
|
+
return this.client.connectedAccounts.delete(nanoid);
|
|
1210
1550
|
}
|
|
1211
1551
|
/**
|
|
1212
|
-
*
|
|
1213
|
-
* @param {string} nanoid - Unique identifier of the
|
|
1552
|
+
* Refresh a connected account's credentials
|
|
1553
|
+
* @param {string} nanoid - Unique identifier of the connected account to refresh
|
|
1214
1554
|
* @param {RequestOptions} options - Request options
|
|
1215
|
-
* @returns {Promise<
|
|
1555
|
+
* @returns {Promise<ConnectedAccountRefreshResponse>} Refreshed connected account details
|
|
1216
1556
|
*/
|
|
1217
|
-
async
|
|
1218
|
-
return this.client.
|
|
1557
|
+
async refresh(nanoid) {
|
|
1558
|
+
return this.client.connectedAccounts.refresh(nanoid);
|
|
1219
1559
|
}
|
|
1220
1560
|
/**
|
|
1221
|
-
* Update the status of
|
|
1222
|
-
* @param {string}
|
|
1223
|
-
* @param {
|
|
1561
|
+
* Update the status of a connected account
|
|
1562
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1563
|
+
* @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status
|
|
1224
1564
|
* @param {RequestOptions} options - Request options
|
|
1225
|
-
* @returns {Promise<
|
|
1565
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
1226
1566
|
*/
|
|
1227
|
-
async updateStatus(
|
|
1228
|
-
return this.client.
|
|
1567
|
+
async updateStatus(nanoid, params) {
|
|
1568
|
+
return this.client.connectedAccounts.updateStatus(nanoid, params);
|
|
1229
1569
|
}
|
|
1230
1570
|
/**
|
|
1231
|
-
* Enable
|
|
1232
|
-
* @param {string} nanoid - Unique identifier of the
|
|
1571
|
+
* Enable a connected account
|
|
1572
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1233
1573
|
* @param {RequestOptions} options - Request options
|
|
1234
|
-
* @returns {Promise<
|
|
1574
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
1235
1575
|
*/
|
|
1236
1576
|
async enable(nanoid) {
|
|
1237
|
-
return this.client.
|
|
1577
|
+
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true });
|
|
1238
1578
|
}
|
|
1239
1579
|
/**
|
|
1240
|
-
* Disable
|
|
1241
|
-
* @param {string} nanoid - Unique identifier of the
|
|
1580
|
+
* Disable a connected account
|
|
1581
|
+
* @param {string} nanoid - Unique identifier of the connected account
|
|
1242
1582
|
* @param {RequestOptions} options - Request options
|
|
1243
|
-
* @returns {Promise<
|
|
1583
|
+
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
1244
1584
|
*/
|
|
1245
1585
|
async disable(nanoid) {
|
|
1246
|
-
return this.client.
|
|
1586
|
+
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
|
|
1247
1587
|
}
|
|
1248
1588
|
};
|
|
1249
1589
|
|
|
1250
|
-
// src/
|
|
1251
|
-
var
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1590
|
+
// src/models/Toolkits.ts
|
|
1591
|
+
var Toolkits = class {
|
|
1592
|
+
client;
|
|
1593
|
+
constructor(client) {
|
|
1594
|
+
this.client = client;
|
|
1595
|
+
this.authorize = this.authorize.bind(this);
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* List all toolkits available in the Composio SDK.
|
|
1599
|
+
* This method fetches the toolkits from the Composio API.
|
|
1600
|
+
* @returns {Promise<Toolkit[]>} List of toolkits
|
|
1601
|
+
*/
|
|
1602
|
+
async getToolkits(query) {
|
|
1603
|
+
const parsedQuery = ToolkitsListParamsSchema.parse(query);
|
|
1604
|
+
const result = await this.client.toolkits.list({
|
|
1605
|
+
category: parsedQuery.category,
|
|
1606
|
+
is_local: parsedQuery.isLocal,
|
|
1607
|
+
managed_by: parsedQuery.managedBy,
|
|
1608
|
+
sort_by: parsedQuery.sortBy
|
|
1609
|
+
});
|
|
1610
|
+
const parsedResult = ToolKitListResponseSchema.parse({
|
|
1611
|
+
items: result.items.map((item) => {
|
|
1612
|
+
const parsedItem = ToolKitItemSchema.parse({
|
|
1613
|
+
name: item.name,
|
|
1614
|
+
slug: item.slug,
|
|
1615
|
+
meta: item.meta,
|
|
1616
|
+
isLocalToolkit: item.is_local_toolkit,
|
|
1617
|
+
authSchemes: item.auth_schemes,
|
|
1618
|
+
composioManagedAuthSchemes: item.composio_managed_auth_schemes,
|
|
1619
|
+
noAuth: item.no_auth
|
|
1620
|
+
});
|
|
1621
|
+
return parsedItem;
|
|
1622
|
+
}),
|
|
1623
|
+
nextCursor: result.next_cursor,
|
|
1624
|
+
totalPages: result.total_pages
|
|
1625
|
+
});
|
|
1626
|
+
return parsedResult;
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1629
|
+
* Fetches a toolkit by its Slug.
|
|
1630
|
+
* This method retrieves the toolkit from the Composio API.
|
|
1631
|
+
* @param slug - The ID of the toolkit to be retrieved
|
|
1632
|
+
* @param options - Request options
|
|
1633
|
+
* @returns {Promise<ToolkitRetrieveResponse>} The toolkit object
|
|
1634
|
+
*/
|
|
1635
|
+
async getToolkitBySlug(slug) {
|
|
1636
|
+
try {
|
|
1637
|
+
const result = await this.client.toolkits.retrieve(slug);
|
|
1638
|
+
const parsedResult = ToolkitRetrieveResponseSchema.parse({
|
|
1639
|
+
name: result.name,
|
|
1640
|
+
slug: result.slug,
|
|
1641
|
+
meta: {
|
|
1642
|
+
...result.meta,
|
|
1643
|
+
createdAt: result.meta.created_at,
|
|
1644
|
+
updatedAt: result.meta.updated_at,
|
|
1645
|
+
toolsCount: result.meta.tools_count,
|
|
1646
|
+
triggersCount: result.meta.triggers_count
|
|
1647
|
+
// appUrl: result.meta.app_url, @TODO Update the client type to include this
|
|
1648
|
+
},
|
|
1649
|
+
isLocalToolkit: result.is_local_toolkit,
|
|
1650
|
+
composioManagedAuthSchemes: result.composio_managed_auth_schemes,
|
|
1651
|
+
authConfigDetails: result.auth_config_details?.map((authConfig) => ({
|
|
1652
|
+
name: authConfig.name,
|
|
1653
|
+
mode: authConfig.mode,
|
|
1654
|
+
fields: {
|
|
1655
|
+
authConfigCreation: authConfig.fields.auth_config_creation,
|
|
1656
|
+
connectedAccountInitiation: authConfig.fields.connected_account_initiation
|
|
1657
|
+
},
|
|
1658
|
+
proxy: {
|
|
1659
|
+
baseUrl: authConfig.proxy?.base_url
|
|
1660
|
+
}
|
|
1661
|
+
}))
|
|
1662
|
+
});
|
|
1663
|
+
return parsedResult;
|
|
1664
|
+
} catch (error) {
|
|
1665
|
+
if (error instanceof import_zod7.ZodError) {
|
|
1666
|
+
throw new ValidationError(error);
|
|
1667
|
+
}
|
|
1668
|
+
throw new ComposioToolNotFoundError(`Toolkit with slug ${slug} not found`, {
|
|
1669
|
+
slug
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
/**
|
|
1674
|
+
* Fetches a toolkit by its Slug or a list of toolkits.
|
|
1675
|
+
* This method retrieves the toolkit from the Composio API.
|
|
1676
|
+
* @param arg - The ID of the toolkit to be retrieved or a list of parameters
|
|
1677
|
+
* @returns {Promise<ToolkitRetrieveResponse | ToolKitListResponse>} The toolkit object or a list of toolkits
|
|
1678
|
+
*/
|
|
1679
|
+
async get(arg) {
|
|
1680
|
+
if (typeof arg === "string") {
|
|
1681
|
+
return this.getToolkitBySlug(arg);
|
|
1682
|
+
}
|
|
1683
|
+
return this.getToolkits(arg);
|
|
1684
|
+
}
|
|
1685
|
+
/**
|
|
1686
|
+
* Fetches all categories available in the Composio SDK
|
|
1687
|
+
*
|
|
1688
|
+
* @returns {Promise<ToolkitRetrieveCategoriesResponse>} List of categories
|
|
1689
|
+
*/
|
|
1690
|
+
async listCategories() {
|
|
1691
|
+
const result = await this.client.toolkits.retrieveCategories();
|
|
1692
|
+
const parsedResult = ToolkitRetrieveCategoriesResponseSchema.parse({
|
|
1693
|
+
items: result.items.map((item) => {
|
|
1694
|
+
const parsedItem = ToolkitCategorySchema.parse({
|
|
1695
|
+
id: item.id,
|
|
1696
|
+
name: item.name
|
|
1697
|
+
});
|
|
1698
|
+
return parsedItem;
|
|
1699
|
+
}),
|
|
1700
|
+
nextCursor: result.next_cursor,
|
|
1701
|
+
totalPages: result.total_pages
|
|
1702
|
+
});
|
|
1703
|
+
return parsedResult;
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* Authorizes a user to use a toolkit.
|
|
1707
|
+
* This method will create an auth config if one doesn't exist and initiate a connection request.
|
|
1708
|
+
* @param {string} userId - The user id of the user to authorize
|
|
1709
|
+
* @param {string} toolkitSlug - The slug of the toolkit to authorize
|
|
1710
|
+
* @param {string} authConfigId - The id of the auth config to use
|
|
1711
|
+
* @returns {Promise<ConnectionRequest>} The connection request object
|
|
1712
|
+
*/
|
|
1713
|
+
async authorize(userId, toolkitSlug) {
|
|
1714
|
+
const toolkit = await this.getToolkitBySlug(toolkitSlug);
|
|
1715
|
+
const composioAuthConfig = new AuthConfigs(this.client);
|
|
1716
|
+
let authConfigIdToUse;
|
|
1717
|
+
const authConfig = await composioAuthConfig.list({
|
|
1718
|
+
toolkitSlug
|
|
1719
|
+
});
|
|
1720
|
+
authConfigIdToUse = authConfig.items[0]?.id;
|
|
1721
|
+
if (!authConfigIdToUse) {
|
|
1722
|
+
if (toolkit.authConfigDetails && toolkit.authConfigDetails.length > 0) {
|
|
1723
|
+
const authConfig2 = await composioAuthConfig.create(toolkitSlug, {
|
|
1724
|
+
type: "use_composio_managed_auth",
|
|
1725
|
+
name: `${toolkit.name} Auth Config`
|
|
1726
|
+
});
|
|
1727
|
+
authConfigIdToUse = authConfig2.id;
|
|
1728
|
+
} else {
|
|
1729
|
+
throw new ComposioAuthConfigNotFoundError("No auth config found for toolkit", {
|
|
1730
|
+
toolkitSlug
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
const composioConnectedAccount = new ConnectedAccounts(this.client);
|
|
1735
|
+
return await composioConnectedAccount.initiate(userId, authConfigIdToUse);
|
|
1736
|
+
}
|
|
1259
1737
|
};
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
}
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1738
|
+
|
|
1739
|
+
// src/utils/pusher.ts
|
|
1740
|
+
var PUSHER_KEY = process.env.CLIENT_PUSHER_KEY || "ff9f18c208855d77a152";
|
|
1741
|
+
var PUSHER_CLUSTER = "mt1";
|
|
1742
|
+
var PusherUtils = class _PusherUtils {
|
|
1743
|
+
static pusherClient;
|
|
1744
|
+
static getPusherClient(baseURL, apiKey) {
|
|
1745
|
+
if (!_PusherUtils.pusherClient) {
|
|
1746
|
+
const PusherClient = require("pusher-js");
|
|
1747
|
+
_PusherUtils.pusherClient = new PusherClient(PUSHER_KEY, {
|
|
1748
|
+
cluster: PUSHER_CLUSTER,
|
|
1749
|
+
channelAuthorization: {
|
|
1750
|
+
endpoint: `${baseURL}/api/v1/client/auth/pusher_auth`,
|
|
1751
|
+
headers: {
|
|
1752
|
+
"x-api-key": apiKey
|
|
1753
|
+
},
|
|
1754
|
+
transport: "ajax"
|
|
1755
|
+
}
|
|
1756
|
+
});
|
|
1757
|
+
}
|
|
1758
|
+
return _PusherUtils.pusherClient;
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Subscribes to a Pusher channel and binds an event to a callback function.
|
|
1762
|
+
* @param {string} channelName - The name of the channel to subscribe to.
|
|
1763
|
+
* @param {string} event - The event to bind to the channel.
|
|
1764
|
+
* @param {(data: Record<string, unknown>) => void} fn - The callback function to execute when the event is triggered.
|
|
1765
|
+
* @returns {PusherClient} The Pusher client instance.
|
|
1766
|
+
*/
|
|
1767
|
+
static async subscribe(channelName, event, fn) {
|
|
1768
|
+
try {
|
|
1769
|
+
await _PusherUtils.pusherClient.subscribe(channelName).bind(event, fn);
|
|
1770
|
+
} catch (error) {
|
|
1771
|
+
logger_default.error(
|
|
1772
|
+
`Error subscribing to ${channelName} with event ${event}: ${error}`
|
|
1773
|
+
);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Unsubscribes from a Pusher channel.
|
|
1778
|
+
* @param {string} channelName - The name of the channel to unsubscribe from.
|
|
1779
|
+
* @returns {void}
|
|
1780
|
+
*/
|
|
1781
|
+
static async unsubscribe(channelName) {
|
|
1782
|
+
_PusherUtils.pusherClient.unsubscribe(channelName);
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* Binds an event to a channel with support for chunked messages.
|
|
1786
|
+
* @param {PusherClient} channel - The Pusher channel to bind the event to.
|
|
1787
|
+
* @param {string} event - The event to bind to the channel.
|
|
1788
|
+
* @param {(data: unknown) => void} callback - The callback function to execute when the event is triggered.
|
|
1789
|
+
*/
|
|
1790
|
+
static bindWithChunking(channel, event, callback) {
|
|
1791
|
+
channel.bind(event, callback);
|
|
1792
|
+
const events = {};
|
|
1793
|
+
channel.bind("chunked-" + event, (data) => {
|
|
1794
|
+
const typedData = data;
|
|
1795
|
+
if (!events.hasOwnProperty(typedData.id)) {
|
|
1796
|
+
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
1797
|
+
}
|
|
1798
|
+
const ev = events[typedData.id];
|
|
1799
|
+
ev.chunks[typedData.index] = typedData.chunk;
|
|
1800
|
+
if (typedData.final) ev.receivedFinal = true;
|
|
1801
|
+
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
1802
|
+
callback(JSON.parse(ev.chunks.join("")));
|
|
1803
|
+
delete events[typedData.id];
|
|
1804
|
+
}
|
|
1805
|
+
});
|
|
1806
|
+
}
|
|
1807
|
+
/**
|
|
1808
|
+
* Subscribes to a trigger channel for a client and handles chunked data.
|
|
1809
|
+
* @param {string} clientId - The unique identifier for the client subscribing to the events.
|
|
1810
|
+
* @param {(data: TriggerData) => void} fn - The callback function to execute when trigger data is received.
|
|
1811
|
+
*/
|
|
1812
|
+
static triggerSubscribe(clientId, fn) {
|
|
1813
|
+
const channel = _PusherUtils.pusherClient.subscribe(
|
|
1814
|
+
`private-${clientId}_triggers`
|
|
1815
|
+
);
|
|
1816
|
+
_PusherUtils.bindWithChunking(
|
|
1817
|
+
channel,
|
|
1818
|
+
"trigger_to_client",
|
|
1819
|
+
fn
|
|
1820
|
+
);
|
|
1821
|
+
logger_default.info(
|
|
1822
|
+
`Subscribed to triggers. You should start receiving events now.`
|
|
1823
|
+
);
|
|
1824
|
+
}
|
|
1825
|
+
static triggerUnsubscribe(clientId) {
|
|
1826
|
+
_PusherUtils.pusherClient.unsubscribe(`${clientId}_triggers`);
|
|
1827
|
+
}
|
|
1311
1828
|
};
|
|
1312
|
-
var ConnectedAccountAuthSchemesSchema = import_zod4.z.enum([
|
|
1313
|
-
ConnectedAccountAuthSchemes.OAUTH2,
|
|
1314
|
-
ConnectedAccountAuthSchemes.OAUTH1,
|
|
1315
|
-
ConnectedAccountAuthSchemes.OAUTH1A,
|
|
1316
|
-
ConnectedAccountAuthSchemes.API_KEY,
|
|
1317
|
-
ConnectedAccountAuthSchemes.BASIC,
|
|
1318
|
-
ConnectedAccountAuthSchemes.BILLCOM_AUTH,
|
|
1319
|
-
ConnectedAccountAuthSchemes.BEARER_TOKEN,
|
|
1320
|
-
ConnectedAccountAuthSchemes.GOOGLE_SERVICE_ACCOUNT,
|
|
1321
|
-
ConnectedAccountAuthSchemes.NO_AUTH,
|
|
1322
|
-
ConnectedAccountAuthSchemes.BASIC_WITH_JWT,
|
|
1323
|
-
ConnectedAccountAuthSchemes.COMPOSIO_LINK,
|
|
1324
|
-
ConnectedAccountAuthSchemes.CALCOM_AUTH,
|
|
1325
|
-
ConnectedAccountAuthSchemes.SNOWFLAKE
|
|
1326
|
-
]);
|
|
1327
|
-
var ConnectedAccountAuthConfigSchema = import_zod4.z.object({
|
|
1328
|
-
id: import_zod4.z.string(),
|
|
1329
|
-
authScheme: ConnectedAccountAuthSchemesSchema,
|
|
1330
|
-
isComposioManaged: import_zod4.z.boolean(),
|
|
1331
|
-
isDisabled: import_zod4.z.boolean()
|
|
1332
|
-
});
|
|
1333
|
-
var ConnectedAccountRetrieveResponseSchema = import_zod4.z.object({
|
|
1334
|
-
id: import_zod4.z.string(),
|
|
1335
|
-
authConfig: ConnectedAccountAuthConfigSchema,
|
|
1336
|
-
userId: import_zod4.z.string(),
|
|
1337
|
-
data: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()),
|
|
1338
|
-
params: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()),
|
|
1339
|
-
status: ConnectedAccountStatusSchema,
|
|
1340
|
-
statusReason: import_zod4.z.string().nullable(),
|
|
1341
|
-
toolkit: import_zod4.z.object({
|
|
1342
|
-
slug: import_zod4.z.string()
|
|
1343
|
-
}),
|
|
1344
|
-
testRequestEndpoint: import_zod4.z.string().optional(),
|
|
1345
|
-
isDisabled: import_zod4.z.boolean(),
|
|
1346
|
-
createdAt: import_zod4.z.string(),
|
|
1347
|
-
updatedAt: import_zod4.z.string()
|
|
1348
|
-
});
|
|
1349
1829
|
|
|
1350
|
-
// src/models/
|
|
1351
|
-
var
|
|
1352
|
-
var ConnectionRequest = class {
|
|
1830
|
+
// src/models/Session.ts
|
|
1831
|
+
var Session = class {
|
|
1353
1832
|
client;
|
|
1354
|
-
|
|
1355
|
-
connectedAccountStatus;
|
|
1356
|
-
constructor(client, connectedAccountId, connectedAccountStatus) {
|
|
1833
|
+
constructor(client) {
|
|
1357
1834
|
this.client = client;
|
|
1358
|
-
this.connectedAccountId = connectedAccountId;
|
|
1359
|
-
this.connectedAccountStatus = connectedAccountStatus;
|
|
1360
|
-
}
|
|
1361
|
-
/**
|
|
1362
|
-
* Transform the response from the Composio API to the SDK format
|
|
1363
|
-
* @param response
|
|
1364
|
-
* @returns
|
|
1365
|
-
*/
|
|
1366
|
-
async transformResponse(response) {
|
|
1367
|
-
try {
|
|
1368
|
-
const parsedResponse = ConnectedAccountRetrieveResponseSchema.parse({
|
|
1369
|
-
...response,
|
|
1370
|
-
userId: response.user_id,
|
|
1371
|
-
// Add the missing userId property
|
|
1372
|
-
authConfig: {
|
|
1373
|
-
...response.auth_config,
|
|
1374
|
-
authScheme: response.auth_config.auth_scheme,
|
|
1375
|
-
isComposioManaged: response.auth_config.is_composio_managed,
|
|
1376
|
-
isDisabled: response.auth_config.is_disabled
|
|
1377
|
-
},
|
|
1378
|
-
statusReason: response.status_reason,
|
|
1379
|
-
isDisabled: response.is_disabled,
|
|
1380
|
-
createdAt: response.created_at,
|
|
1381
|
-
updatedAt: response.updated_at,
|
|
1382
|
-
testRequestEndpoint: response.test_request_endpoint
|
|
1383
|
-
});
|
|
1384
|
-
return parsedResponse;
|
|
1385
|
-
} catch (error) {
|
|
1386
|
-
logger_default.error("Error transforming response", error);
|
|
1387
|
-
if (error instanceof import_zod5.ZodError) {
|
|
1388
|
-
logger_default.error(JSON.stringify(error.errors, null, 2));
|
|
1389
|
-
}
|
|
1390
|
-
throw error;
|
|
1391
|
-
}
|
|
1392
1835
|
}
|
|
1393
1836
|
/**
|
|
1394
|
-
*
|
|
1395
|
-
*
|
|
1396
|
-
* @param {number} timeout - The time in milliseconds to wait for the connection to be established. Default is 30 seconds.
|
|
1397
|
-
* @returns
|
|
1837
|
+
* Get the active session info
|
|
1838
|
+
* @returns {Promise<SessionGetInfoResponse>} Session info
|
|
1398
1839
|
*/
|
|
1399
|
-
async
|
|
1400
|
-
|
|
1401
|
-
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1402
|
-
return Promise.resolve(this.transformResponse(response));
|
|
1403
|
-
}
|
|
1404
|
-
return new Promise((resolve, reject) => {
|
|
1405
|
-
const interval = setInterval(async () => {
|
|
1406
|
-
try {
|
|
1407
|
-
const response = await this.client.connectedAccounts.retrieve(this.connectedAccountId);
|
|
1408
|
-
if (response.status === ConnectedAccountStatuses.ACTIVE) {
|
|
1409
|
-
clearInterval(interval);
|
|
1410
|
-
resolve(this.transformResponse(response));
|
|
1411
|
-
}
|
|
1412
|
-
} catch (error) {
|
|
1413
|
-
clearInterval(interval);
|
|
1414
|
-
reject(error);
|
|
1415
|
-
}
|
|
1416
|
-
}, 1e3);
|
|
1417
|
-
setTimeout(() => {
|
|
1418
|
-
clearInterval(interval);
|
|
1419
|
-
reject(new Error("Connection request timed out"));
|
|
1420
|
-
}, timeout);
|
|
1421
|
-
});
|
|
1840
|
+
async getInfo() {
|
|
1841
|
+
return this.client.auth.session.getInfo();
|
|
1422
1842
|
}
|
|
1423
1843
|
};
|
|
1424
1844
|
|
|
1425
|
-
// src/models/
|
|
1426
|
-
var
|
|
1845
|
+
// src/models/Triggers.ts
|
|
1846
|
+
var Triggers = class {
|
|
1427
1847
|
client;
|
|
1428
1848
|
constructor(client) {
|
|
1429
1849
|
this.client = client;
|
|
1430
1850
|
}
|
|
1431
1851
|
/**
|
|
1432
|
-
*
|
|
1433
|
-
* @
|
|
1434
|
-
* @param {RequestOptions} options - Request options
|
|
1435
|
-
* @returns {Promise<ConnectedAccountListResponse>} List of connected accounts
|
|
1852
|
+
* Fetch list of all the active triggers
|
|
1853
|
+
* @returns {Promise<TriggerInstance[]>} List of trigger instances
|
|
1436
1854
|
*/
|
|
1437
|
-
async list(query) {
|
|
1438
|
-
return this.client.
|
|
1855
|
+
async list(query, options) {
|
|
1856
|
+
return this.client.triggerInstances.listActive(query, options);
|
|
1439
1857
|
}
|
|
1440
1858
|
/**
|
|
1441
|
-
*
|
|
1442
|
-
* This function creates a new connected account and returns a connection request.
|
|
1443
|
-
* Users can then wait for the connection to be established using the `waitForConnection` method.
|
|
1444
|
-
* @param {string} userId - User ID of the connected account
|
|
1445
|
-
* @param {string} authConfigId - Auth config ID of the connected account
|
|
1446
|
-
* @param {CreateConnectedAccountOptions} data - Data for creating a new connected account
|
|
1447
|
-
* @returns {Promise<ConnectionRequest>} Connection request object
|
|
1859
|
+
* Create a new trigger instance
|
|
1448
1860
|
*
|
|
1449
|
-
* @
|
|
1450
|
-
*
|
|
1451
|
-
*
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1861
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1862
|
+
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
1863
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
1864
|
+
*/
|
|
1865
|
+
async create(slug, body, options) {
|
|
1866
|
+
return this.client.triggerInstances.upsert(slug, body, options);
|
|
1867
|
+
}
|
|
1868
|
+
/**
|
|
1869
|
+
* Update an existing trigger instance
|
|
1455
1870
|
*
|
|
1456
|
-
* @
|
|
1871
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1872
|
+
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
1873
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1457
1874
|
*/
|
|
1458
|
-
async
|
|
1459
|
-
|
|
1460
|
-
auth_config: {
|
|
1461
|
-
id: authConfigId
|
|
1462
|
-
},
|
|
1463
|
-
connection: {
|
|
1464
|
-
data: options?.data,
|
|
1465
|
-
redirect_uri: options?.redirectUrl,
|
|
1466
|
-
user_id: userId
|
|
1467
|
-
}
|
|
1468
|
-
});
|
|
1469
|
-
return new ConnectionRequest(this.client, response.id, response.status);
|
|
1875
|
+
async update(slug, body, options) {
|
|
1876
|
+
return this.client.triggerInstances.upsert(slug, body, options);
|
|
1470
1877
|
}
|
|
1471
1878
|
/**
|
|
1472
|
-
*
|
|
1473
|
-
*
|
|
1474
|
-
* @param {
|
|
1475
|
-
* @returns
|
|
1879
|
+
* Delete a trigger instance
|
|
1880
|
+
*
|
|
1881
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1882
|
+
* @returns
|
|
1476
1883
|
*/
|
|
1477
|
-
async
|
|
1478
|
-
return this.client.
|
|
1884
|
+
async delete(slug) {
|
|
1885
|
+
return this.client.triggerInstances.removeUpsert(slug);
|
|
1479
1886
|
}
|
|
1480
1887
|
/**
|
|
1481
|
-
*
|
|
1482
|
-
*
|
|
1888
|
+
* Update the status of a trigger
|
|
1889
|
+
*
|
|
1890
|
+
* @param {TriggerStatusEnum} status - The new status of the trigger
|
|
1891
|
+
* @param {TriggerInstanceUpdateStatusParams} params - The parameters to update the trigger instance
|
|
1483
1892
|
* @param {RequestOptions} options - Request options
|
|
1484
|
-
* @returns {Promise<
|
|
1893
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1485
1894
|
*/
|
|
1486
|
-
async
|
|
1487
|
-
return this.client.
|
|
1895
|
+
async updateStatus(status, params, options) {
|
|
1896
|
+
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
1488
1897
|
}
|
|
1489
1898
|
/**
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
1492
|
-
* @param {
|
|
1493
|
-
* @
|
|
1899
|
+
* Disable a trigger instance
|
|
1900
|
+
*
|
|
1901
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1902
|
+
* @param {RequestOptions options - Request options
|
|
1903
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1494
1904
|
*/
|
|
1495
|
-
async
|
|
1496
|
-
return this.client.
|
|
1905
|
+
async disable(slug, options) {
|
|
1906
|
+
return this.client.triggerInstances.updateStatus("disable", { slug }, options);
|
|
1497
1907
|
}
|
|
1498
1908
|
/**
|
|
1499
|
-
*
|
|
1500
|
-
*
|
|
1501
|
-
* @param {
|
|
1502
|
-
* @param {RequestOptions
|
|
1503
|
-
* @returns {Promise<
|
|
1909
|
+
* Enable a trigger instance
|
|
1910
|
+
*
|
|
1911
|
+
* @param {string} slug - The slug of the trigger instance
|
|
1912
|
+
* @param {RequestOptions options - Request options
|
|
1913
|
+
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
1504
1914
|
*/
|
|
1505
|
-
async
|
|
1506
|
-
return this.client.
|
|
1915
|
+
async enable(slug, options) {
|
|
1916
|
+
return this.client.triggerInstances.updateStatus("enable", { slug }, options);
|
|
1507
1917
|
}
|
|
1508
1918
|
/**
|
|
1509
|
-
*
|
|
1510
|
-
|
|
1919
|
+
* @TODO Learn about trigger types
|
|
1920
|
+
*/
|
|
1921
|
+
/**
|
|
1922
|
+
* List all the trigger types
|
|
1923
|
+
*
|
|
1924
|
+
* @param {TriggersTypeListParams} query - The query parameters to filter the trigger types
|
|
1511
1925
|
* @param {RequestOptions} options - Request options
|
|
1512
|
-
* @returns {Promise<
|
|
1926
|
+
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
|
|
1513
1927
|
*/
|
|
1514
|
-
async
|
|
1515
|
-
return this.client.
|
|
1928
|
+
async listTypes(query, options) {
|
|
1929
|
+
return this.client.triggersTypes.list(query, options);
|
|
1516
1930
|
}
|
|
1517
1931
|
/**
|
|
1518
|
-
*
|
|
1519
|
-
*
|
|
1520
|
-
* @param {
|
|
1521
|
-
* @
|
|
1932
|
+
* Retrieve a trigger type by its slug
|
|
1933
|
+
*
|
|
1934
|
+
* @param {string} slug - The slug of the trigger type
|
|
1935
|
+
* @param {RequestOptions} options - request options
|
|
1936
|
+
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
1522
1937
|
*/
|
|
1523
|
-
async
|
|
1524
|
-
return this.client.
|
|
1938
|
+
async getType(slug, options) {
|
|
1939
|
+
return this.client.triggersTypes.retrieve(slug, options);
|
|
1940
|
+
}
|
|
1941
|
+
/**
|
|
1942
|
+
* Fetches the list of all the available trigger enums
|
|
1943
|
+
*
|
|
1944
|
+
* This method is used by the CLI where filters are not required.
|
|
1945
|
+
* @param options
|
|
1946
|
+
* @returns
|
|
1947
|
+
*/
|
|
1948
|
+
async listEnum(options) {
|
|
1949
|
+
return this.client.triggersTypes.retrieveEnum(options);
|
|
1950
|
+
}
|
|
1951
|
+
async subscribe(fn, filters = {}) {
|
|
1952
|
+
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
1953
|
+
const session = new Session(this.client);
|
|
1954
|
+
const sessionInfo = await session.getInfo();
|
|
1955
|
+
const clientId = sessionInfo.project?.id;
|
|
1956
|
+
if (!clientId) throw new Error("Client ID not found");
|
|
1957
|
+
if (!this.client.apiKey) throw new Error("API key not found");
|
|
1958
|
+
await PusherUtils.getPusherClient(this.client.baseURL, this.client.apiKey);
|
|
1959
|
+
const shouldSendTrigger = (data) => {
|
|
1960
|
+
if (Object.keys(filters).length === 0) return true;
|
|
1961
|
+
else {
|
|
1962
|
+
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());
|
|
1963
|
+
}
|
|
1964
|
+
};
|
|
1965
|
+
logger_default.debug("Subscribing to triggers", filters);
|
|
1966
|
+
PusherUtils.triggerSubscribe(clientId, (data) => {
|
|
1967
|
+
if (shouldSendTrigger(data)) {
|
|
1968
|
+
fn(data);
|
|
1969
|
+
}
|
|
1970
|
+
});
|
|
1971
|
+
}
|
|
1972
|
+
async unsubscribe() {
|
|
1973
|
+
const session = new Session(this.client);
|
|
1974
|
+
const sessionInfo = await session.getInfo();
|
|
1975
|
+
const clientId = sessionInfo.project?.id;
|
|
1976
|
+
if (!clientId) throw new Error("Client ID not found");
|
|
1977
|
+
PusherUtils.triggerUnsubscribe(clientId);
|
|
1525
1978
|
}
|
|
1526
1979
|
};
|
|
1527
1980
|
|
|
@@ -1818,7 +2271,7 @@ var BaseToolset = class {
|
|
|
1818
2271
|
/**
|
|
1819
2272
|
* @internal
|
|
1820
2273
|
* Set the function to execute a tool.
|
|
1821
|
-
* This is set automatically injected by the core SDK.
|
|
2274
|
+
* This is set automatically and injected by the core SDK.
|
|
1822
2275
|
*/
|
|
1823
2276
|
_setExecuteToolFn(executeToolFn) {
|
|
1824
2277
|
this._globalExecuteToolFn = executeToolFn;
|
|
@@ -1833,6 +2286,9 @@ var BaseToolset = class {
|
|
|
1833
2286
|
* @returns {Promise<string>} The result of the tool execution.
|
|
1834
2287
|
*/
|
|
1835
2288
|
executeTool(toolSlug, body, modifers) {
|
|
2289
|
+
if (!this._globalExecuteToolFn) {
|
|
2290
|
+
throw new ComposioGlobalExecuteToolFnNotSetError("executeToolFn is not set");
|
|
2291
|
+
}
|
|
1836
2292
|
return this._globalExecuteToolFn(toolSlug, body, modifers);
|
|
1837
2293
|
}
|
|
1838
2294
|
};
|
|
@@ -1875,8 +2331,8 @@ var OpenAIToolset = class extends BaseNonAgenticToolset {
|
|
|
1875
2331
|
async executeToolCall(userId, tool, options, modifiers) {
|
|
1876
2332
|
const payload = {
|
|
1877
2333
|
arguments: JSON.parse(tool.function.arguments),
|
|
1878
|
-
connectedAccountId: options
|
|
1879
|
-
customAuthParams: options
|
|
2334
|
+
connectedAccountId: options?.connectedAccountId,
|
|
2335
|
+
customAuthParams: options?.customAuthParams,
|
|
1880
2336
|
userId
|
|
1881
2337
|
};
|
|
1882
2338
|
const result = await this.executeTool(tool.function.name, payload, modifiers);
|
|
@@ -2009,7 +2465,7 @@ var OpenAIToolset = class extends BaseNonAgenticToolset {
|
|
|
2009
2465
|
};
|
|
2010
2466
|
|
|
2011
2467
|
// package.json
|
|
2012
|
-
var version = "0.1.
|
|
2468
|
+
var version = "0.1.10-alpha.0";
|
|
2013
2469
|
|
|
2014
2470
|
// src/utils/uuid.ts
|
|
2015
2471
|
var import_uuid = require("uuid");
|
|
@@ -2042,7 +2498,7 @@ var Composio = class {
|
|
|
2042
2498
|
createAuthConfig;
|
|
2043
2499
|
// connected accounts
|
|
2044
2500
|
connectedAccounts;
|
|
2045
|
-
|
|
2501
|
+
initiateConnection;
|
|
2046
2502
|
/**
|
|
2047
2503
|
* @param {Object} config Configuration for the Composio SDK.
|
|
2048
2504
|
* @param {string} config.apiKey The API key for the Composio SDK.
|
|
@@ -2076,7 +2532,7 @@ var Composio = class {
|
|
|
2076
2532
|
this.authConfigs = new AuthConfigs(this.client);
|
|
2077
2533
|
this.createAuthConfig = this.authConfigs.create.bind(this.authConfigs);
|
|
2078
2534
|
this.connectedAccounts = new ConnectedAccounts(this.client);
|
|
2079
|
-
this.
|
|
2535
|
+
this.initiateConnection = this.connectedAccounts.initiate.bind(this.connectedAccounts);
|
|
2080
2536
|
if (this.config.allowTracking ?? true) {
|
|
2081
2537
|
this.initializeTelemetry(
|
|
2082
2538
|
{
|
|
@@ -2156,39 +2612,39 @@ var BaseTelemetryTransport = class {
|
|
|
2156
2612
|
};
|
|
2157
2613
|
|
|
2158
2614
|
// src/utils/jsonSchema.ts
|
|
2159
|
-
var
|
|
2615
|
+
var import_zod8 = require("zod");
|
|
2160
2616
|
function jsonSchemaPropertiesToTSTypes(value) {
|
|
2161
2617
|
if (!value.type) {
|
|
2162
|
-
return
|
|
2618
|
+
return import_zod8.z.object({});
|
|
2163
2619
|
}
|
|
2164
2620
|
let zodType;
|
|
2165
2621
|
switch (value.type) {
|
|
2166
2622
|
case "string":
|
|
2167
|
-
zodType =
|
|
2623
|
+
zodType = import_zod8.z.string().describe(
|
|
2168
2624
|
(value.description || "") + (value.examples ? `
|
|
2169
2625
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2170
2626
|
);
|
|
2171
2627
|
break;
|
|
2172
2628
|
case "number":
|
|
2173
|
-
zodType =
|
|
2629
|
+
zodType = import_zod8.z.number().describe(
|
|
2174
2630
|
(value.description || "") + (value.examples ? `
|
|
2175
2631
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2176
2632
|
);
|
|
2177
2633
|
break;
|
|
2178
2634
|
case "integer":
|
|
2179
|
-
zodType =
|
|
2635
|
+
zodType = import_zod8.z.number().int().describe(
|
|
2180
2636
|
(value.description || "") + (value.examples ? `
|
|
2181
2637
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2182
2638
|
);
|
|
2183
2639
|
break;
|
|
2184
2640
|
case "boolean":
|
|
2185
|
-
zodType =
|
|
2641
|
+
zodType = import_zod8.z.boolean().describe(
|
|
2186
2642
|
(value.description || "") + (value.examples ? `
|
|
2187
2643
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2188
2644
|
);
|
|
2189
2645
|
break;
|
|
2190
2646
|
case "array":
|
|
2191
|
-
zodType =
|
|
2647
|
+
zodType = import_zod8.z.array(
|
|
2192
2648
|
jsonSchemaPropertiesToTSTypes(
|
|
2193
2649
|
value.items
|
|
2194
2650
|
)
|
|
@@ -2204,7 +2660,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2204
2660
|
);
|
|
2205
2661
|
break;
|
|
2206
2662
|
case "null":
|
|
2207
|
-
zodType =
|
|
2663
|
+
zodType = import_zod8.z.null().describe(value.description || "");
|
|
2208
2664
|
break;
|
|
2209
2665
|
default:
|
|
2210
2666
|
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
@@ -2215,7 +2671,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
2215
2671
|
const properties = jsonSchema.properties;
|
|
2216
2672
|
const requiredFields = jsonSchema.required || [];
|
|
2217
2673
|
if (!properties) {
|
|
2218
|
-
return
|
|
2674
|
+
return import_zod8.z.object({});
|
|
2219
2675
|
}
|
|
2220
2676
|
const zodSchema = {};
|
|
2221
2677
|
for (const [key, _] of Object.entries(properties)) {
|
|
@@ -2227,7 +2683,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
2227
2683
|
schema
|
|
2228
2684
|
)
|
|
2229
2685
|
);
|
|
2230
|
-
zodType =
|
|
2686
|
+
zodType = import_zod8.z.union(anyOfTypes).describe(
|
|
2231
2687
|
(value.description || "") + (value.examples ? `
|
|
2232
2688
|
Examples: ${value.examples.join(", ")}` : "")
|
|
2233
2689
|
);
|
|
@@ -2237,7 +2693,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2237
2693
|
schema
|
|
2238
2694
|
)
|
|
2239
2695
|
);
|
|
2240
|
-
zodType =
|
|
2696
|
+
zodType = import_zod8.z.intersection(
|
|
2241
2697
|
allOfTypes[0],
|
|
2242
2698
|
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
2243
2699
|
).describe(
|
|
@@ -2261,7 +2717,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
2261
2717
|
zodSchema[key] = zodType.optional();
|
|
2262
2718
|
}
|
|
2263
2719
|
}
|
|
2264
|
-
return
|
|
2720
|
+
return import_zod8.z.object(zodSchema);
|
|
2265
2721
|
}
|
|
2266
2722
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2267
2723
|
0 && (module.exports = {
|