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