@composio/core 0.1.12-alpha.11 → 0.1.12-alpha.13
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/dist/index.cjs +743 -231
- package/dist/index.d.cts +541 -107
- package/dist/index.d.ts +541 -107
- package/dist/index.js +739 -228
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -15,12 +15,38 @@ var ToolkitSchema = z.object({
|
|
|
15
15
|
name: z.string().describe("The name of the toolkit"),
|
|
16
16
|
logo: z.string().describe("The logo of the toolkit").optional()
|
|
17
17
|
});
|
|
18
|
+
var JSONSchemaType = z.enum([
|
|
19
|
+
"string",
|
|
20
|
+
"number",
|
|
21
|
+
"integer",
|
|
22
|
+
"boolean",
|
|
23
|
+
"object",
|
|
24
|
+
"array",
|
|
25
|
+
"null"
|
|
26
|
+
]);
|
|
27
|
+
var JSONSchemaProperty = z.object({
|
|
28
|
+
type: JSONSchemaType.optional(),
|
|
29
|
+
description: z.string().optional(),
|
|
30
|
+
title: z.string().optional(),
|
|
31
|
+
default: z.any().optional(),
|
|
32
|
+
properties: z.lazy(() => z.record(z.string(), JSONSchemaProperty)).optional(),
|
|
33
|
+
required: z.array(z.string()).optional(),
|
|
34
|
+
items: z.lazy(() => JSONSchemaProperty).optional()
|
|
35
|
+
});
|
|
36
|
+
var ParametersSchema = z.object({
|
|
37
|
+
type: z.literal("object"),
|
|
38
|
+
properties: z.record(z.string(), JSONSchemaProperty),
|
|
39
|
+
required: z.array(z.string()).optional(),
|
|
40
|
+
title: z.string().optional(),
|
|
41
|
+
description: z.string().optional(),
|
|
42
|
+
additionalProperties: z.boolean().optional()
|
|
43
|
+
});
|
|
18
44
|
var ToolSchema = z.object({
|
|
19
45
|
slug: z.string().describe('The slug of the tool. eg. "GOOGLE_SEARCH"'),
|
|
20
46
|
name: z.string().describe(`The name of the tool. eg. "Google Search"`),
|
|
21
47
|
description: z.string().optional().describe("The description of the tool"),
|
|
22
|
-
inputParameters:
|
|
23
|
-
outputParameters:
|
|
48
|
+
inputParameters: ParametersSchema.optional().describe("The input parameters of the tool"),
|
|
49
|
+
outputParameters: ParametersSchema.optional().describe("The output parameters of the tool"),
|
|
24
50
|
tags: z.optional(z.array(z.string())).describe("The tags of the tool. eg: Important").default([]),
|
|
25
51
|
toolkit: z.optional(ToolkitSchema).describe("The toolkit of the tool"),
|
|
26
52
|
version: z.optional(z.string()).describe('The version of the tool, e.g. "1.0.0"')
|
|
@@ -30,14 +56,27 @@ var ToolListResponseSchema = z.object({
|
|
|
30
56
|
nextCursor: z.string().nullable().optional(),
|
|
31
57
|
totalPages: z.number()
|
|
32
58
|
});
|
|
33
|
-
var
|
|
34
|
-
tools: z.array(z.string())
|
|
59
|
+
var ToolListFilterByToolsSchema = z.object({
|
|
60
|
+
tools: z.array(z.string())
|
|
61
|
+
});
|
|
62
|
+
var ToolListFilterByToolkitsSchema = z.object({
|
|
63
|
+
toolkits: z.array(z.string()),
|
|
64
|
+
important: z.boolean().optional(),
|
|
35
65
|
cursor: z.string().optional(),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
search: z.string().optional(),
|
|
39
|
-
toolkits: z.array(z.string()).optional()
|
|
66
|
+
limit: z.number().optional(),
|
|
67
|
+
search: z.string().optional()
|
|
40
68
|
});
|
|
69
|
+
var ToolListFilterBySearchSchema = z.object({
|
|
70
|
+
search: z.string(),
|
|
71
|
+
toolkits: z.array(z.string()).optional(),
|
|
72
|
+
cursor: z.string().optional(),
|
|
73
|
+
limit: z.number().optional()
|
|
74
|
+
});
|
|
75
|
+
var ToolListParamsSchema = z.union([
|
|
76
|
+
ToolListFilterByToolsSchema,
|
|
77
|
+
ToolListFilterByToolkitsSchema,
|
|
78
|
+
ToolListFilterBySearchSchema
|
|
79
|
+
]);
|
|
41
80
|
var CustomAuthParamsSchema = z.object({
|
|
42
81
|
baseURL: z.string().optional(),
|
|
43
82
|
body: z.record(z.string(), z.unknown()).optional(),
|
|
@@ -172,18 +211,19 @@ var ComposioError = class _ComposioError extends Error {
|
|
|
172
211
|
*/
|
|
173
212
|
constructor(message, options = {}) {
|
|
174
213
|
super(message);
|
|
214
|
+
if (Error.captureStackTrace) {
|
|
215
|
+
Error.captureStackTrace(this, this.constructor);
|
|
216
|
+
}
|
|
175
217
|
const statusCode = options.statusCode || (options.cause instanceof BadRequestError ? options.cause.status : void 0);
|
|
176
218
|
this.code = `TS-SDK::${options.code}`;
|
|
177
219
|
this.possibleFixes = options.possibleFixes;
|
|
178
220
|
this.definePropertyIfExists("statusCode", statusCode);
|
|
179
221
|
this.definePropertyIfExists("cause", options.cause);
|
|
180
|
-
|
|
222
|
+
const combinedStack = options.cause instanceof Error ? _ComposioError.combineStackTraces(options.cause.stack, this.stack) : options.stack ?? this.stack;
|
|
223
|
+
this.definePropertyIfExists("stack", combinedStack);
|
|
181
224
|
if (options.meta && Object.keys(options.meta).length > 0) {
|
|
182
225
|
this.definePropertyIfExists("meta", options.meta);
|
|
183
226
|
}
|
|
184
|
-
if (Error.captureStackTrace) {
|
|
185
|
-
Error.captureStackTrace(this, this.constructor);
|
|
186
|
-
}
|
|
187
227
|
}
|
|
188
228
|
/**
|
|
189
229
|
* Helper method to define a property only if it has a value
|
|
@@ -201,6 +241,25 @@ var ComposioError = class _ComposioError extends Error {
|
|
|
201
241
|
});
|
|
202
242
|
}
|
|
203
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Helper method to combine stack traces when wrapping errors
|
|
246
|
+
* This ensures the full call chain is preserved
|
|
247
|
+
* @param originalStack The stack of the error being wrapped
|
|
248
|
+
* @param currentStack The stack of the wrapper error
|
|
249
|
+
* @returns Combined stack trace
|
|
250
|
+
* @private
|
|
251
|
+
*/
|
|
252
|
+
static combineStackTraces(originalStack, currentStack) {
|
|
253
|
+
if (!originalStack) return currentStack;
|
|
254
|
+
if (!currentStack) return originalStack;
|
|
255
|
+
const currentHeader = currentStack.split("\n")[0];
|
|
256
|
+
const originalStackBody = originalStack.split("\n").slice(1).join("\n");
|
|
257
|
+
return `${currentHeader}
|
|
258
|
+
${currentStack.split("\n").slice(1).join("\n")}
|
|
259
|
+
|
|
260
|
+
Caused by:
|
|
261
|
+
${originalStackBody}`;
|
|
262
|
+
}
|
|
204
263
|
/**
|
|
205
264
|
* Extract and normalize error data for formatting
|
|
206
265
|
* @param includeStack Whether to include stack trace information
|
|
@@ -230,7 +289,16 @@ var ComposioError = class _ComposioError extends Error {
|
|
|
230
289
|
data.possibleFixes = possibleFixes;
|
|
231
290
|
}
|
|
232
291
|
if (includeStack && stack) {
|
|
233
|
-
|
|
292
|
+
if (stack.includes("Caused by:")) {
|
|
293
|
+
const [currentStack, causeStack] = stack.split("Caused by:");
|
|
294
|
+
data.stack = [
|
|
295
|
+
...currentStack.split("\n").slice(1),
|
|
296
|
+
"Caused by:",
|
|
297
|
+
...causeStack.split("\n")
|
|
298
|
+
];
|
|
299
|
+
} else {
|
|
300
|
+
data.stack = stack.split("\n").slice(1);
|
|
301
|
+
}
|
|
234
302
|
}
|
|
235
303
|
return data;
|
|
236
304
|
}
|
|
@@ -434,7 +502,7 @@ var ComposioToolExecutionError = class extends ComposioError {
|
|
|
434
502
|
"Ensure the tool is correctly configured and the input is valid"
|
|
435
503
|
]
|
|
436
504
|
});
|
|
437
|
-
this.error = originalError || (options.cause instanceof Error ? options.cause : new Error(String(options.cause)));
|
|
505
|
+
this.error = originalError || (options.cause instanceof Error ? options.cause : options.cause ? new Error(String(options.cause)) : new Error("Unknown error"));
|
|
438
506
|
this.name = "ComposioToolExecutionError";
|
|
439
507
|
}
|
|
440
508
|
};
|
|
@@ -670,7 +738,7 @@ var TelemetryService = class {
|
|
|
670
738
|
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
671
739
|
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
672
740
|
});
|
|
673
|
-
const instrumentedClassName = instance.constructor?.name || fileName
|
|
741
|
+
const instrumentedClassName = (instance.constructor?.name || fileName) ?? "unknown";
|
|
674
742
|
for (const name of methodNames) {
|
|
675
743
|
const originalMethod = instance[name];
|
|
676
744
|
instance[name] = async (...args) => {
|
|
@@ -686,9 +754,11 @@ var TelemetryService = class {
|
|
|
686
754
|
try {
|
|
687
755
|
return await originalMethod.apply(instance, args);
|
|
688
756
|
} catch (error) {
|
|
689
|
-
if (error instanceof Error
|
|
690
|
-
error.errorId
|
|
691
|
-
|
|
757
|
+
if (error instanceof Error) {
|
|
758
|
+
if (!error.errorId) {
|
|
759
|
+
error.errorId = getRandomUUID();
|
|
760
|
+
this.prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args);
|
|
761
|
+
}
|
|
692
762
|
}
|
|
693
763
|
throw error;
|
|
694
764
|
}
|
|
@@ -722,7 +792,7 @@ var TelemetryService = class {
|
|
|
722
792
|
error_id: error.errorId || "",
|
|
723
793
|
error_message: error.message,
|
|
724
794
|
original_error: error.cause || error,
|
|
725
|
-
current_stack: error.stack
|
|
795
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
726
796
|
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
727
797
|
};
|
|
728
798
|
this.sendErrorTelemetry(telemetryPayload);
|
|
@@ -731,7 +801,7 @@ var TelemetryService = class {
|
|
|
731
801
|
error_id: error.errorId || "",
|
|
732
802
|
error_message: error.message,
|
|
733
803
|
original_error: error.cause || error,
|
|
734
|
-
current_stack: error.stack
|
|
804
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
735
805
|
error_code: error.code,
|
|
736
806
|
possible_fix: error.possibleFixes?.join("\n"),
|
|
737
807
|
description: `Original Call : ${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
@@ -742,7 +812,7 @@ var TelemetryService = class {
|
|
|
742
812
|
error_id: error.errorId || "",
|
|
743
813
|
error_message: error instanceof Error ? error.name : "Unknown error",
|
|
744
814
|
original_error: error,
|
|
745
|
-
current_stack: error.stack
|
|
815
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
746
816
|
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
747
817
|
};
|
|
748
818
|
this.sendErrorTelemetry(telemetryPayload);
|
|
@@ -831,7 +901,7 @@ var CustomTools = class {
|
|
|
831
901
|
outputParameters: {
|
|
832
902
|
type: "object",
|
|
833
903
|
title: `Response for ${name}`,
|
|
834
|
-
properties:
|
|
904
|
+
properties: {}
|
|
835
905
|
},
|
|
836
906
|
tags: [],
|
|
837
907
|
toolkit: { name: "custom", slug: "custom" }
|
|
@@ -889,8 +959,7 @@ var CustomTools = class {
|
|
|
889
959
|
await this.client.toolkits.retrieve(toolkitSlug);
|
|
890
960
|
} catch (error) {
|
|
891
961
|
throw new ComposioToolNotFoundError(`Toolkit with slug ${toolkitSlug} not found`, {
|
|
892
|
-
|
|
893
|
-
error
|
|
962
|
+
cause: error
|
|
894
963
|
});
|
|
895
964
|
}
|
|
896
965
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
@@ -899,10 +968,7 @@ var CustomTools = class {
|
|
|
899
968
|
});
|
|
900
969
|
if (!connectedAccounts.items.length) {
|
|
901
970
|
throw new ComposioConnectedAccountNotFoundError(
|
|
902
|
-
`No connected accounts found for toolkit ${toolkitSlug}
|
|
903
|
-
{
|
|
904
|
-
toolkitSlug
|
|
905
|
-
}
|
|
971
|
+
`No connected accounts found for toolkit ${toolkitSlug}`
|
|
906
972
|
);
|
|
907
973
|
}
|
|
908
974
|
return metadata.connectedAccountId ? connectedAccounts.items.find((item) => item.id === metadata.connectedAccountId) : connectedAccounts.items[0];
|
|
@@ -917,9 +983,7 @@ var CustomTools = class {
|
|
|
917
983
|
async executeCustomTool(slug, inputParams, metadata) {
|
|
918
984
|
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
919
985
|
if (!tool) {
|
|
920
|
-
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found
|
|
921
|
-
toolSlug: slug
|
|
922
|
-
});
|
|
986
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
923
987
|
}
|
|
924
988
|
let authCredentials = {};
|
|
925
989
|
const { toolkitSlug, execute } = tool.options;
|
|
@@ -929,8 +993,10 @@ var CustomTools = class {
|
|
|
929
993
|
throw new ComposioConnectedAccountNotFoundError(
|
|
930
994
|
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}`,
|
|
931
995
|
{
|
|
932
|
-
|
|
933
|
-
|
|
996
|
+
meta: {
|
|
997
|
+
toolkitSlug,
|
|
998
|
+
userId: metadata.userId
|
|
999
|
+
}
|
|
934
1000
|
}
|
|
935
1001
|
);
|
|
936
1002
|
}
|
|
@@ -938,7 +1004,9 @@ var CustomTools = class {
|
|
|
938
1004
|
}
|
|
939
1005
|
if (typeof execute !== "function") {
|
|
940
1006
|
throw new ComposioInvalidExecuteFunctionError("Invalid execute function", {
|
|
941
|
-
|
|
1007
|
+
meta: {
|
|
1008
|
+
toolSlug: slug
|
|
1009
|
+
}
|
|
942
1010
|
});
|
|
943
1011
|
}
|
|
944
1012
|
const executeToolRequest = async (data) => {
|
|
@@ -1165,34 +1233,45 @@ var Tools = class {
|
|
|
1165
1233
|
* );
|
|
1166
1234
|
* ```
|
|
1167
1235
|
*/
|
|
1168
|
-
async getRawComposioTools(userId, query
|
|
1236
|
+
async getRawComposioTools(userId, query, modifier) {
|
|
1237
|
+
if ("tools" in query && "toolkits" in query) {
|
|
1238
|
+
throw new ValidationError(
|
|
1239
|
+
"Invalid tool list parameters. You should not use tools and toolkits filter together."
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1169
1242
|
const queryParams = ToolListParamsSchema.safeParse(query);
|
|
1170
1243
|
if (queryParams.error) {
|
|
1171
1244
|
throw new ValidationError("Invalid tool list parameters", {
|
|
1172
1245
|
cause: queryParams.error
|
|
1173
1246
|
});
|
|
1174
1247
|
}
|
|
1248
|
+
if (!("tools" in queryParams.data || "toolkits" in queryParams.data || "search" in queryParams.data)) {
|
|
1249
|
+
throw new ValidationError(
|
|
1250
|
+
"Invalid tool list parameters, atleast one of the following parameters is required: tools, toolkits, search"
|
|
1251
|
+
);
|
|
1252
|
+
}
|
|
1175
1253
|
const tools = await this.client.tools.list({
|
|
1176
|
-
tool_slugs: queryParams.data.tools,
|
|
1177
|
-
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
1178
|
-
cursor: queryParams.data.cursor,
|
|
1179
|
-
important: queryParams.data.important,
|
|
1180
|
-
limit: queryParams.data.limit,
|
|
1181
|
-
search: queryParams.data.search
|
|
1254
|
+
tool_slugs: "tools" in queryParams.data ? queryParams.data.tools?.join(",") : void 0,
|
|
1255
|
+
toolkit_slug: "toolkits" in queryParams.data ? queryParams.data.toolkits?.join(",") : void 0,
|
|
1256
|
+
cursor: "cursor" in queryParams.data ? queryParams.data.cursor : void 0,
|
|
1257
|
+
important: "important" in queryParams.data ? queryParams.data.important ? "true" : "false" : void 0,
|
|
1258
|
+
limit: "limit" in queryParams.data ? queryParams.data.limit?.toString() : void 0,
|
|
1259
|
+
search: "search" in queryParams.data ? queryParams.data.search : void 0
|
|
1182
1260
|
});
|
|
1183
1261
|
if (!tools) {
|
|
1184
1262
|
return [];
|
|
1185
1263
|
}
|
|
1186
1264
|
const caseTransformedTools = tools.items.map((tool) => this.transformToolCases(tool));
|
|
1187
1265
|
const customTools = await this.customTools.getCustomTools({
|
|
1188
|
-
toolSlugs: queryParams.data.tools
|
|
1266
|
+
toolSlugs: "tools" in queryParams.data ? queryParams.data.tools : void 0
|
|
1189
1267
|
});
|
|
1190
1268
|
let modifiedTools = [...caseTransformedTools, ...customTools];
|
|
1191
1269
|
if (modifier) {
|
|
1192
1270
|
if (typeof modifier === "function") {
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1271
|
+
const modifiedPromises = modifiedTools.map(
|
|
1272
|
+
(tool) => modifier(tool.slug, tool.toolkit?.slug ?? "unknown", tool)
|
|
1273
|
+
);
|
|
1274
|
+
modifiedTools = await Promise.all(modifiedPromises);
|
|
1196
1275
|
} else {
|
|
1197
1276
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
1198
1277
|
}
|
|
@@ -1223,15 +1302,15 @@ var Tools = class {
|
|
|
1223
1302
|
cause: error
|
|
1224
1303
|
});
|
|
1225
1304
|
}
|
|
1226
|
-
let
|
|
1305
|
+
let modifiedTool = this.transformToolCases(tool);
|
|
1227
1306
|
if (modifier) {
|
|
1228
1307
|
if (typeof modifier === "function") {
|
|
1229
|
-
|
|
1308
|
+
modifiedTool = await modifier(slug, modifiedTool.toolkit?.slug ?? "unknown", modifiedTool);
|
|
1230
1309
|
} else {
|
|
1231
1310
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
1232
1311
|
}
|
|
1233
1312
|
}
|
|
1234
|
-
return
|
|
1313
|
+
return modifiedTool;
|
|
1235
1314
|
}
|
|
1236
1315
|
/**
|
|
1237
1316
|
* Get a tool or list of tools based on the provided arguments.
|
|
@@ -1254,8 +1333,10 @@ var Tools = class {
|
|
|
1254
1333
|
}
|
|
1255
1334
|
/**
|
|
1256
1335
|
* @internal
|
|
1336
|
+
* @description
|
|
1257
1337
|
* Creates a function that executes a tool.
|
|
1258
|
-
* This function is used by agentic
|
|
1338
|
+
* This function is used by agentic toolsets to execute the tool
|
|
1339
|
+
*
|
|
1259
1340
|
* @param {string} userId - The user id
|
|
1260
1341
|
* @param {ExecuteToolModifiers} modifiers - The modifiers to be applied to the tool
|
|
1261
1342
|
* @returns {ExecuteToolFn} The execute tool function
|
|
@@ -1284,7 +1365,7 @@ var Tools = class {
|
|
|
1284
1365
|
async handleCustomToolExecution(tool, body, modifiers) {
|
|
1285
1366
|
if (modifiers?.beforeExecute) {
|
|
1286
1367
|
if (typeof modifiers.beforeExecute === "function") {
|
|
1287
|
-
body = modifiers.beforeExecute(tool.slug, "
|
|
1368
|
+
body = await modifiers.beforeExecute(tool.slug, "unknown", body);
|
|
1288
1369
|
} else {
|
|
1289
1370
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
1290
1371
|
}
|
|
@@ -1295,7 +1376,7 @@ var Tools = class {
|
|
|
1295
1376
|
});
|
|
1296
1377
|
if (modifiers?.afterExecute) {
|
|
1297
1378
|
if (typeof modifiers.afterExecute === "function") {
|
|
1298
|
-
result = modifiers.afterExecute(tool.slug, "
|
|
1379
|
+
result = await modifiers.afterExecute(tool.slug, "unknown", result);
|
|
1299
1380
|
} else {
|
|
1300
1381
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
1301
1382
|
}
|
|
@@ -1313,7 +1394,7 @@ var Tools = class {
|
|
|
1313
1394
|
async handleComposioToolExecution(tool, body, modifiers) {
|
|
1314
1395
|
if (modifiers?.beforeExecute) {
|
|
1315
1396
|
if (typeof modifiers.beforeExecute === "function") {
|
|
1316
|
-
body = modifiers.beforeExecute(tool.slug, tool.toolkit?.slug
|
|
1397
|
+
body = await modifiers.beforeExecute(tool.slug, tool.toolkit?.slug ?? "unknown", body);
|
|
1317
1398
|
} else {
|
|
1318
1399
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
1319
1400
|
}
|
|
@@ -1334,7 +1415,7 @@ var Tools = class {
|
|
|
1334
1415
|
result = this.transformToolExecuteResponse(result);
|
|
1335
1416
|
if (modifiers?.afterExecute) {
|
|
1336
1417
|
if (typeof modifiers.afterExecute === "function") {
|
|
1337
|
-
result = modifiers.afterExecute(tool.slug, tool.toolkit?.slug
|
|
1418
|
+
result = await modifiers.afterExecute(tool.slug, tool.toolkit?.slug ?? "unknown", result);
|
|
1338
1419
|
} else {
|
|
1339
1420
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
1340
1421
|
}
|
|
@@ -1739,7 +1820,7 @@ var AuthConfigListParamsSchema = z3.object({
|
|
|
1739
1820
|
});
|
|
1740
1821
|
var AuthConfigListResponseSchema = z3.object({
|
|
1741
1822
|
items: z3.array(AuthConfigRetrieveResponseSchema),
|
|
1742
|
-
nextCursor: z3.string().
|
|
1823
|
+
nextCursor: z3.string().nullable(),
|
|
1743
1824
|
totalPages: z3.number()
|
|
1744
1825
|
});
|
|
1745
1826
|
var AuthCustomConfigUpdateParamsSchema = z3.object({
|
|
@@ -1841,7 +1922,7 @@ var AuthConfigs = class {
|
|
|
1841
1922
|
const result = await this.client.authConfigs.list({
|
|
1842
1923
|
cursor: parsedQuery?.cursor,
|
|
1843
1924
|
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1844
|
-
limit: parsedQuery?.limit
|
|
1925
|
+
limit: parsedQuery?.limit,
|
|
1845
1926
|
toolkit_slug: parsedQuery?.toolkit
|
|
1846
1927
|
});
|
|
1847
1928
|
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
@@ -2062,20 +2143,18 @@ var AuthConfigs = class {
|
|
|
2062
2143
|
// src/types/connectedAccounts.types.ts
|
|
2063
2144
|
import { z as z4 } from "zod";
|
|
2064
2145
|
var ConnectedAccountStatuses = {
|
|
2065
|
-
|
|
2066
|
-
INACTIVE: "INACTIVE",
|
|
2067
|
-
DELETED: "DELETED",
|
|
2146
|
+
INITIALIZING: "INITIALIZING",
|
|
2068
2147
|
INITIATED: "INITIATED",
|
|
2069
|
-
|
|
2070
|
-
FAILED: "FAILED"
|
|
2148
|
+
ACTIVE: "ACTIVE",
|
|
2149
|
+
FAILED: "FAILED",
|
|
2150
|
+
EXPIRED: "EXPIRED"
|
|
2071
2151
|
};
|
|
2072
2152
|
var ConnectedAccountStatusSchema = z4.enum([
|
|
2073
|
-
ConnectedAccountStatuses.
|
|
2074
|
-
ConnectedAccountStatuses.INACTIVE,
|
|
2075
|
-
ConnectedAccountStatuses.DELETED,
|
|
2153
|
+
ConnectedAccountStatuses.INITIALIZING,
|
|
2076
2154
|
ConnectedAccountStatuses.INITIATED,
|
|
2077
|
-
ConnectedAccountStatuses.
|
|
2078
|
-
ConnectedAccountStatuses.FAILED
|
|
2155
|
+
ConnectedAccountStatuses.ACTIVE,
|
|
2156
|
+
ConnectedAccountStatuses.FAILED,
|
|
2157
|
+
ConnectedAccountStatuses.EXPIRED
|
|
2079
2158
|
]);
|
|
2080
2159
|
var CreateConnectedAccountParamsSchema = z4.object({
|
|
2081
2160
|
authConfig: z4.object({
|
|
@@ -2277,8 +2356,7 @@ var ConnectionRequest = class {
|
|
|
2277
2356
|
}
|
|
2278
2357
|
const terminalErrorStates = [
|
|
2279
2358
|
ConnectedAccountStatuses.FAILED,
|
|
2280
|
-
ConnectedAccountStatuses.EXPIRED
|
|
2281
|
-
ConnectedAccountStatuses.DELETED
|
|
2359
|
+
ConnectedAccountStatuses.EXPIRED
|
|
2282
2360
|
];
|
|
2283
2361
|
const start = Date.now();
|
|
2284
2362
|
const pollInterval = 1e3;
|
|
@@ -2309,6 +2387,23 @@ var ConnectionRequest = class {
|
|
|
2309
2387
|
}
|
|
2310
2388
|
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${this.id}`);
|
|
2311
2389
|
}
|
|
2390
|
+
/**
|
|
2391
|
+
* Returns a JSON-serializable representation of the connection request
|
|
2392
|
+
* Excludes the private client property to avoid cyclic reference issues
|
|
2393
|
+
*/
|
|
2394
|
+
toJSON() {
|
|
2395
|
+
return {
|
|
2396
|
+
id: this.id,
|
|
2397
|
+
status: this.status,
|
|
2398
|
+
redirectUrl: this.redirectUrl
|
|
2399
|
+
};
|
|
2400
|
+
}
|
|
2401
|
+
/**
|
|
2402
|
+
* Returns a string representation of the connection request
|
|
2403
|
+
*/
|
|
2404
|
+
toString() {
|
|
2405
|
+
return JSON.stringify(this.toJSON(), null, 2);
|
|
2406
|
+
}
|
|
2312
2407
|
};
|
|
2313
2408
|
|
|
2314
2409
|
// src/models/ConnectedAccounts.ts
|
|
@@ -2768,126 +2863,422 @@ var Toolkits = class {
|
|
|
2768
2863
|
}
|
|
2769
2864
|
};
|
|
2770
2865
|
|
|
2771
|
-
// src/
|
|
2772
|
-
|
|
2773
|
-
var
|
|
2774
|
-
var
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2866
|
+
// src/types/triggers.types.ts
|
|
2867
|
+
import { z as z5 } from "zod";
|
|
2868
|
+
var TriggerStatusEnum = z5.enum(["enable", "disable"]);
|
|
2869
|
+
var TriggerSubscribeParamSchema = z5.object({
|
|
2870
|
+
toolkits: z5.array(z5.string()).optional(),
|
|
2871
|
+
triggerId: z5.string().optional(),
|
|
2872
|
+
connectedAccountId: z5.string().optional(),
|
|
2873
|
+
authConfigId: z5.string().optional(),
|
|
2874
|
+
triggerSlug: z5.array(z5.string()).optional(),
|
|
2875
|
+
triggerData: z5.string().optional(),
|
|
2876
|
+
userId: z5.string().optional()
|
|
2877
|
+
});
|
|
2878
|
+
var TriggerInstanceListActiveParamsSchema = z5.object({
|
|
2879
|
+
authConfigIds: z5.array(z5.string()).nullable().optional(),
|
|
2880
|
+
connectedAccountIds: z5.array(z5.string()).nullable().optional(),
|
|
2881
|
+
limit: z5.number().optional(),
|
|
2882
|
+
page: z5.number().optional(),
|
|
2883
|
+
showDisabled: z5.boolean().nullable().optional(),
|
|
2884
|
+
triggerIds: z5.array(z5.string()).nullable().optional(),
|
|
2885
|
+
triggerNames: z5.array(z5.string()).nullable().optional()
|
|
2886
|
+
});
|
|
2887
|
+
var TriggerInstanceListActiveResponseItemSchema = z5.object({
|
|
2888
|
+
id: z5.string(),
|
|
2889
|
+
connectedAccountId: z5.string(),
|
|
2890
|
+
disabledAt: z5.string().nullable(),
|
|
2891
|
+
state: z5.record(z5.unknown()),
|
|
2892
|
+
triggerConfig: z5.record(z5.unknown()),
|
|
2893
|
+
triggerName: z5.string(),
|
|
2894
|
+
updatedAt: z5.string(),
|
|
2895
|
+
triggerData: z5.string().optional(),
|
|
2896
|
+
uuid: z5.string().optional()
|
|
2897
|
+
});
|
|
2898
|
+
var TriggerInstanceListActiveResponseSchema = z5.object({
|
|
2899
|
+
items: z5.array(TriggerInstanceListActiveResponseItemSchema),
|
|
2900
|
+
nextCursor: z5.string().nullable(),
|
|
2901
|
+
totalPages: z5.number()
|
|
2902
|
+
});
|
|
2903
|
+
var TriggerInstanceUpsertParamsSchema = z5.object({
|
|
2904
|
+
connectedAccountId: z5.string().optional(),
|
|
2905
|
+
triggerConfig: z5.record(z5.unknown()).optional()
|
|
2906
|
+
});
|
|
2907
|
+
var TriggerInstanceUpsertResponseSchema = z5.object({
|
|
2908
|
+
triggerId: z5.string()
|
|
2909
|
+
});
|
|
2910
|
+
var TriggerInstanceManageUpdateParamsSchema = z5.object({
|
|
2911
|
+
status: z5.enum(["enable", "disable"])
|
|
2912
|
+
});
|
|
2913
|
+
var TriggerInstanceManageUpdateResponseSchema = z5.object({
|
|
2914
|
+
status: z5.enum(["success"])
|
|
2915
|
+
});
|
|
2916
|
+
var TriggerInstanceManageDeleteResponseSchema = z5.object({
|
|
2917
|
+
triggerId: z5.string()
|
|
2918
|
+
});
|
|
2919
|
+
var IncomingTriggerPayloadSchema = z5.object({
|
|
2920
|
+
id: z5.string().describe("The ID of the trigger"),
|
|
2921
|
+
triggerSlug: z5.string().describe("The slug of the trigger that triggered the event"),
|
|
2922
|
+
toolkitSlug: z5.string().describe("The slug of the toolkit that triggered the event"),
|
|
2923
|
+
userId: z5.string().describe("The ID of the user that triggered the event"),
|
|
2924
|
+
payload: z5.record(z5.unknown()).describe("The payload of the trigger").optional(),
|
|
2925
|
+
originalPayload: z5.record(z5.unknown()).describe("The original payload of the trigger").optional(),
|
|
2926
|
+
metadata: z5.object({
|
|
2927
|
+
id: z5.string(),
|
|
2928
|
+
toolkitSlug: z5.string(),
|
|
2929
|
+
triggerSlug: z5.string(),
|
|
2930
|
+
triggerData: z5.string().optional(),
|
|
2931
|
+
triggerConfig: z5.record(z5.unknown()),
|
|
2932
|
+
connectedAccount: z5.object({
|
|
2933
|
+
id: z5.string(),
|
|
2934
|
+
uuid: z5.string(),
|
|
2935
|
+
authConfigId: z5.string(),
|
|
2936
|
+
authConfigUUID: z5.string(),
|
|
2937
|
+
userId: z5.string(),
|
|
2938
|
+
status: z5.enum(["ACTIVE", "INACTIVE"])
|
|
2939
|
+
})
|
|
2940
|
+
})
|
|
2941
|
+
});
|
|
2942
|
+
|
|
2943
|
+
// src/services/internal/InternalService.types.ts
|
|
2944
|
+
import { z as z6 } from "zod";
|
|
2945
|
+
var SDKRealtimeCredentialsResponseSchema = z6.object({
|
|
2946
|
+
projectId: z6.string().describe("The project ID"),
|
|
2947
|
+
pusherKey: z6.string().describe("The Pusher key"),
|
|
2948
|
+
pusherCluster: z6.string().describe("The Pusher cluster")
|
|
2949
|
+
});
|
|
2950
|
+
|
|
2951
|
+
// src/services/internal/InternalService.ts
|
|
2952
|
+
var SDK_REALTIME_CREDENTIALS_ENDPOINT = "/api/v3/internal/sdk/realtime/credentials";
|
|
2953
|
+
var InternalService = class {
|
|
2954
|
+
constructor(client) {
|
|
2955
|
+
this.client = client;
|
|
2956
|
+
this.client = client;
|
|
2791
2957
|
}
|
|
2792
2958
|
/**
|
|
2793
|
-
*
|
|
2794
|
-
* @
|
|
2795
|
-
* @param {string} event - The event to bind to the channel.
|
|
2796
|
-
* @param {(data: Record<string, unknown>) => void} fn - The callback function to execute when the event is triggered.
|
|
2797
|
-
* @returns {PusherClient} The Pusher client instance.
|
|
2959
|
+
* Get the SDK realtime credentials
|
|
2960
|
+
* @returns {SDKRealtimeCredentialsResponse} The SDK realtime credentials
|
|
2798
2961
|
*/
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2962
|
+
async getSDKRealtimeCredentials() {
|
|
2963
|
+
const response = await this.client.request({
|
|
2964
|
+
method: "get",
|
|
2965
|
+
path: SDK_REALTIME_CREDENTIALS_ENDPOINT
|
|
2966
|
+
});
|
|
2967
|
+
const parsedResponse = SDKRealtimeCredentialsResponseSchema.safeParse({
|
|
2968
|
+
pusherKey: response.pusher_key,
|
|
2969
|
+
projectId: response.project_id,
|
|
2970
|
+
pusherCluster: response.pusher_cluster
|
|
2971
|
+
});
|
|
2972
|
+
logger_default.debug(
|
|
2973
|
+
`[InternalService] SDK realtime credentials: ${JSON.stringify(parsedResponse, null, 2)}`
|
|
2974
|
+
);
|
|
2975
|
+
if (!parsedResponse.success) {
|
|
2976
|
+
throw new ValidationError(`Failed to parse SDK realtime credentials`, {
|
|
2977
|
+
cause: parsedResponse.error
|
|
2978
|
+
});
|
|
2806
2979
|
}
|
|
2980
|
+
return parsedResponse.data;
|
|
2807
2981
|
}
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2982
|
+
};
|
|
2983
|
+
|
|
2984
|
+
// src/errors/TriggerErrors.ts
|
|
2985
|
+
import { ComposioError as ComposioError2 } from "@composio/client";
|
|
2986
|
+
var TriggerErrorCodes = {
|
|
2987
|
+
TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS: "TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS",
|
|
2988
|
+
TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT: "TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT",
|
|
2989
|
+
TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL",
|
|
2990
|
+
TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL"
|
|
2991
|
+
};
|
|
2992
|
+
var ComposioFailedToGetSDKRealtimeCredentialsError = class extends ComposioError2 {
|
|
2993
|
+
name = "ComposioFailedToGetSDKRealtimeCredentialsError";
|
|
2994
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS;
|
|
2995
|
+
statusCode = 500;
|
|
2996
|
+
possibleFixes = ["Please contact support."];
|
|
2997
|
+
constructor(message, options) {
|
|
2998
|
+
super(message, options);
|
|
2999
|
+
}
|
|
3000
|
+
};
|
|
3001
|
+
var ComposioFailedToCreatePusherClientError = class extends ComposioError2 {
|
|
3002
|
+
name = "ComposioFailedToCreatePusherClientError";
|
|
3003
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT;
|
|
3004
|
+
statusCode = 500;
|
|
3005
|
+
possibleFixes = ["Please contact support."];
|
|
3006
|
+
constructor(message, options) {
|
|
3007
|
+
super(message, options);
|
|
3008
|
+
}
|
|
3009
|
+
};
|
|
3010
|
+
var ComposioFailedToSubscribeToPusherChannelError = class extends ComposioError2 {
|
|
3011
|
+
name = "ComposioFailedToSubscribeToPusherChannelError";
|
|
3012
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL;
|
|
3013
|
+
statusCode = 500;
|
|
3014
|
+
possibleFixes = ["Please contact support."];
|
|
3015
|
+
constructor(message, options) {
|
|
3016
|
+
super(message, options);
|
|
3017
|
+
}
|
|
3018
|
+
};
|
|
3019
|
+
|
|
3020
|
+
// src/services/pusher/Pusher.ts
|
|
3021
|
+
var PusherService = class {
|
|
3022
|
+
// these values are set via the Apollo API `/internal/sdk/realtime/credentials` endpoint
|
|
3023
|
+
clientId;
|
|
3024
|
+
pusherKey;
|
|
3025
|
+
pusherCluster;
|
|
3026
|
+
pusherChannel;
|
|
3027
|
+
// these details are set via the client SDK
|
|
3028
|
+
pusherBaseURL;
|
|
3029
|
+
apiKey;
|
|
3030
|
+
pusherClient;
|
|
3031
|
+
composioClient;
|
|
3032
|
+
constructor(client) {
|
|
3033
|
+
this.composioClient = client;
|
|
3034
|
+
this.pusherBaseURL = client.baseURL;
|
|
3035
|
+
this.apiKey = client.apiKey ?? process.env.COMPOSIO_API_KEY ?? "";
|
|
3036
|
+
telemetry.instrument(this);
|
|
2815
3037
|
}
|
|
2816
3038
|
/**
|
|
2817
|
-
*
|
|
2818
|
-
*
|
|
2819
|
-
*
|
|
2820
|
-
*
|
|
3039
|
+
* Creates a Pusher client
|
|
3040
|
+
*
|
|
3041
|
+
* This method is called when the Pusher client is first used.
|
|
3042
|
+
* It will fetch the SDK realtime credentials from the Apollo API and create a Pusher client.
|
|
2821
3043
|
*/
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
3044
|
+
async getPusherClient() {
|
|
3045
|
+
if (!this.pusherClient) {
|
|
3046
|
+
const internalService = new InternalService(this.composioClient);
|
|
3047
|
+
let sdkRealtimeCredentials;
|
|
3048
|
+
try {
|
|
3049
|
+
sdkRealtimeCredentials = await internalService.getSDKRealtimeCredentials();
|
|
3050
|
+
} catch (error) {
|
|
3051
|
+
throw new ComposioFailedToGetSDKRealtimeCredentialsError(
|
|
3052
|
+
"Failed to get SDK realtime credentials",
|
|
3053
|
+
{
|
|
3054
|
+
cause: error
|
|
3055
|
+
}
|
|
3056
|
+
);
|
|
2829
3057
|
}
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
3058
|
+
this.clientId = sdkRealtimeCredentials.projectId;
|
|
3059
|
+
this.pusherKey = sdkRealtimeCredentials.pusherKey;
|
|
3060
|
+
this.pusherCluster = sdkRealtimeCredentials.pusherCluster;
|
|
3061
|
+
this.pusherChannel = `private-${this.clientId}_triggers`;
|
|
3062
|
+
logger_default.debug(
|
|
3063
|
+
`[PusherService] Creating Pusher client for client ID: ${this.clientId} in cluster ${this.pusherCluster}`
|
|
3064
|
+
);
|
|
3065
|
+
try {
|
|
3066
|
+
const { default: Pusher } = await import("pusher-js");
|
|
3067
|
+
this.pusherClient = new Pusher(this.pusherKey, {
|
|
3068
|
+
cluster: this.pusherCluster,
|
|
3069
|
+
channelAuthorization: {
|
|
3070
|
+
endpoint: `${this.pusherBaseURL}/api/v3/internal/sdk/realtime/auth`,
|
|
3071
|
+
headers: {
|
|
3072
|
+
"x-api-key": this.apiKey
|
|
3073
|
+
},
|
|
3074
|
+
transport: "ajax"
|
|
3075
|
+
}
|
|
3076
|
+
});
|
|
3077
|
+
} catch (error) {
|
|
3078
|
+
throw new ComposioFailedToCreatePusherClientError("Failed to create Pusher client", {
|
|
3079
|
+
cause: error
|
|
3080
|
+
});
|
|
2836
3081
|
}
|
|
2837
|
-
}
|
|
3082
|
+
}
|
|
3083
|
+
return this.pusherClient;
|
|
2838
3084
|
}
|
|
2839
3085
|
/**
|
|
2840
|
-
*
|
|
2841
|
-
*
|
|
2842
|
-
*
|
|
3086
|
+
* Binds a chunked event to a Pusher client
|
|
3087
|
+
*
|
|
3088
|
+
*
|
|
3089
|
+
* @param channel - The Pusher client to bind the event to
|
|
3090
|
+
* @param event - The event to bind to
|
|
3091
|
+
* @param callback - The function to call when the event is received
|
|
2843
3092
|
*/
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
3093
|
+
bindWithChunking(channel, event, callback) {
|
|
3094
|
+
try {
|
|
3095
|
+
channel.bind(event, callback);
|
|
3096
|
+
const events = {};
|
|
3097
|
+
channel.bind("chunked-" + event, (data) => {
|
|
3098
|
+
try {
|
|
3099
|
+
const typedData = data;
|
|
3100
|
+
if (!typedData || typeof typedData.id !== "string" || typeof typedData.index !== "number") {
|
|
3101
|
+
throw new Error("Invalid chunked trigger data format");
|
|
3102
|
+
}
|
|
3103
|
+
if (!events.hasOwnProperty(typedData.id)) {
|
|
3104
|
+
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
3105
|
+
}
|
|
3106
|
+
const ev = events[typedData.id];
|
|
3107
|
+
ev.chunks[typedData.index] = typedData.chunk;
|
|
3108
|
+
if (typedData.final) ev.receivedFinal = true;
|
|
3109
|
+
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
3110
|
+
try {
|
|
3111
|
+
const parsedData = JSON.parse(ev.chunks.join(""));
|
|
3112
|
+
callback(parsedData);
|
|
3113
|
+
} catch (parseError) {
|
|
3114
|
+
const errorMessage = parseError instanceof Error ? parseError.message : String(parseError);
|
|
3115
|
+
logger_default.error("Failed to parse chunked data:", errorMessage);
|
|
3116
|
+
} finally {
|
|
3117
|
+
delete events[typedData.id];
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
} catch (error) {
|
|
3121
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3122
|
+
logger_default.error("Error processing chunked trigger data:", errorMessage);
|
|
3123
|
+
if (data && typeof data === "object" && "id" in data) {
|
|
3124
|
+
delete events[data.id];
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
});
|
|
3128
|
+
} catch (error) {
|
|
3129
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3130
|
+
logger_default.error("Failed to bind chunked events:", error);
|
|
3131
|
+
throw new Error(`Failed to bind chunked events: ${errorMessage}`);
|
|
3132
|
+
}
|
|
2859
3133
|
}
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
3134
|
+
/**
|
|
3135
|
+
* Subscribes to pusher to receive events from the server
|
|
3136
|
+
*
|
|
3137
|
+
* This method is used to subscribe to a Pusher channel.
|
|
3138
|
+
* It will create a Pusher client if it doesn't exist.
|
|
3139
|
+
*
|
|
3140
|
+
* @param channelName - The name of the Pusher channel to subscribe to
|
|
3141
|
+
* @param event - The event to subscribe to
|
|
3142
|
+
* @param fn - The function to call when the event is received
|
|
3143
|
+
*/
|
|
3144
|
+
async subscribe(fn) {
|
|
3145
|
+
try {
|
|
3146
|
+
logger_default.debug(`[PusherService] Subscribing to channel: ${this.pusherChannel}`);
|
|
3147
|
+
const pusherClient = await this.getPusherClient();
|
|
3148
|
+
const channel = await pusherClient.subscribe(this.pusherChannel);
|
|
3149
|
+
channel.bind("pusher:subscription_error", (data) => {
|
|
3150
|
+
const error = data.error ? String(data.error) : "Unknown subscription error";
|
|
3151
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3152
|
+
`Trigger subscription error: ${error}`,
|
|
3153
|
+
{
|
|
3154
|
+
cause: error
|
|
3155
|
+
}
|
|
3156
|
+
);
|
|
3157
|
+
});
|
|
3158
|
+
const safeCallback = (data) => {
|
|
3159
|
+
try {
|
|
3160
|
+
fn(data);
|
|
3161
|
+
} catch (error) {
|
|
3162
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3163
|
+
logger_default.error("\u274C Error in trigger callback:", errorMessage);
|
|
3164
|
+
}
|
|
3165
|
+
};
|
|
3166
|
+
this.bindWithChunking(channel, "trigger_to_client", safeCallback);
|
|
3167
|
+
logger_default.info(`\u2705 Subscribed to triggers. You should start receiving events now.`);
|
|
3168
|
+
} catch (error) {
|
|
3169
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3170
|
+
"Failed to subscribe to Pusher channel",
|
|
3171
|
+
{
|
|
3172
|
+
cause: error
|
|
3173
|
+
}
|
|
3174
|
+
);
|
|
3175
|
+
}
|
|
2868
3176
|
}
|
|
2869
3177
|
/**
|
|
2870
|
-
*
|
|
2871
|
-
*
|
|
3178
|
+
* Unsubscribes from a Pusher channel
|
|
3179
|
+
*
|
|
3180
|
+
* This method is used to unsubscribe from a Pusher channel.
|
|
3181
|
+
* It will create a Pusher client if it doesn't exist.
|
|
3182
|
+
*
|
|
3183
|
+
* @param channelName - The name of the Pusher channel to unsubscribe from
|
|
2872
3184
|
*/
|
|
2873
|
-
async
|
|
2874
|
-
|
|
3185
|
+
async unsubscribe() {
|
|
3186
|
+
try {
|
|
3187
|
+
logger_default.debug(`[PusherService] Unsubscribing from channel: ${this.pusherChannel}`);
|
|
3188
|
+
const pusherClient = await this.getPusherClient();
|
|
3189
|
+
await pusherClient.unsubscribe(this.pusherChannel);
|
|
3190
|
+
logger_default.info(`\u2705 Unsubscribed from triggers.`);
|
|
3191
|
+
} catch (error) {
|
|
3192
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3193
|
+
"Failed to unsubscribe from Pusher channel",
|
|
3194
|
+
{
|
|
3195
|
+
cause: error
|
|
3196
|
+
}
|
|
3197
|
+
);
|
|
3198
|
+
}
|
|
2875
3199
|
}
|
|
2876
3200
|
};
|
|
2877
3201
|
|
|
2878
3202
|
// src/models/Triggers.ts
|
|
2879
3203
|
var Triggers = class {
|
|
2880
3204
|
client;
|
|
3205
|
+
pusherService;
|
|
2881
3206
|
constructor(client) {
|
|
2882
3207
|
this.client = client;
|
|
3208
|
+
this.pusherService = new PusherService(client);
|
|
2883
3209
|
telemetry.instrument(this);
|
|
2884
3210
|
}
|
|
3211
|
+
/**
|
|
3212
|
+
* Parse the trigger instance list active item
|
|
3213
|
+
*
|
|
3214
|
+
* @param response - The response from the composio client
|
|
3215
|
+
* @returns The parsed trigger instance list active item
|
|
3216
|
+
*/
|
|
3217
|
+
parseTriggerInstanceListActiveItem(response) {
|
|
3218
|
+
const parsed = TriggerInstanceListActiveResponseItemSchema.safeParse({
|
|
3219
|
+
id: response.id,
|
|
3220
|
+
connectedAccountId: response.connected_account_id,
|
|
3221
|
+
disabledAt: response.disabled_at,
|
|
3222
|
+
state: response.state,
|
|
3223
|
+
triggerConfig: response.trigger_config,
|
|
3224
|
+
triggerName: response.trigger_name,
|
|
3225
|
+
updatedAt: response.updated_at,
|
|
3226
|
+
triggerData: response.trigger_data,
|
|
3227
|
+
uuid: response.uuid
|
|
3228
|
+
});
|
|
3229
|
+
if (!parsed.success) {
|
|
3230
|
+
throw new ValidationError(`Invalid trigger instance list active item`, {
|
|
3231
|
+
cause: parsed.error
|
|
3232
|
+
});
|
|
3233
|
+
}
|
|
3234
|
+
return parsed.data;
|
|
3235
|
+
}
|
|
2885
3236
|
/**
|
|
2886
3237
|
* Fetch list of all the active triggers
|
|
2887
|
-
*
|
|
3238
|
+
*
|
|
3239
|
+
* @param {TriggerInstanceListActiveParams} query - The query parameters to filter the trigger instances
|
|
3240
|
+
* @returns {Promise<TriggerInstanceListActiveResponse>} List of trigger instances
|
|
3241
|
+
*
|
|
3242
|
+
* @throws {ValidationError} If the parameters are invalid
|
|
3243
|
+
* @throws {Error} If the client is not authenticated
|
|
3244
|
+
*
|
|
3245
|
+
* @example
|
|
3246
|
+
* ```ts
|
|
3247
|
+
* const triggers = await triggers.listActive({
|
|
3248
|
+
* authConfigIds: ['123'],
|
|
3249
|
+
* connectedAccountIds: ['456'],
|
|
3250
|
+
* });
|
|
3251
|
+
* ```
|
|
2888
3252
|
*/
|
|
2889
|
-
async
|
|
2890
|
-
|
|
3253
|
+
async listActive(query) {
|
|
3254
|
+
const parsedParams = TriggerInstanceListActiveParamsSchema.safeParse(query ?? {});
|
|
3255
|
+
if (!parsedParams.success) {
|
|
3256
|
+
throw new ValidationError(`Invalid parameters passed to list triggers`, {
|
|
3257
|
+
cause: parsedParams.error
|
|
3258
|
+
});
|
|
3259
|
+
}
|
|
3260
|
+
const result = await this.client.triggerInstances.listActive(
|
|
3261
|
+
query ? {
|
|
3262
|
+
auth_config_ids: parsedParams.data.authConfigIds,
|
|
3263
|
+
connected_account_ids: parsedParams.data.connectedAccountIds,
|
|
3264
|
+
limit: parsedParams.data.limit,
|
|
3265
|
+
page: parsedParams.data.page,
|
|
3266
|
+
show_disabled: parsedParams.data.showDisabled,
|
|
3267
|
+
trigger_ids: parsedParams.data.triggerIds,
|
|
3268
|
+
trigger_names: parsedParams.data.triggerNames
|
|
3269
|
+
} : void 0
|
|
3270
|
+
);
|
|
3271
|
+
const parsedResult = TriggerInstanceListActiveResponseSchema.safeParse({
|
|
3272
|
+
items: result.items.map((item) => this.parseTriggerInstanceListActiveItem(item)),
|
|
3273
|
+
nextCursor: result.next_cursor,
|
|
3274
|
+
totalPages: result.total_pages
|
|
3275
|
+
});
|
|
3276
|
+
if (!parsedResult.success) {
|
|
3277
|
+
throw new ValidationError(`Invalid trigger instance list active response`, {
|
|
3278
|
+
cause: parsedResult.error
|
|
3279
|
+
});
|
|
3280
|
+
}
|
|
3281
|
+
return parsedResult.data;
|
|
2891
3282
|
}
|
|
2892
3283
|
/**
|
|
2893
3284
|
* Create a new trigger instance
|
|
@@ -2896,58 +3287,76 @@ var Triggers = class {
|
|
|
2896
3287
|
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
2897
3288
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
2898
3289
|
*/
|
|
2899
|
-
async create(slug, body
|
|
2900
|
-
|
|
3290
|
+
async create(slug, body) {
|
|
3291
|
+
const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body);
|
|
3292
|
+
if (!parsedBody.success) {
|
|
3293
|
+
throw new ValidationError(`Invalid parameters passed to create trigger`, {
|
|
3294
|
+
cause: parsedBody.error
|
|
3295
|
+
});
|
|
3296
|
+
}
|
|
3297
|
+
const result = await this.client.triggerInstances.upsert(slug, {
|
|
3298
|
+
connected_account_id: parsedBody.data.connectedAccountId,
|
|
3299
|
+
trigger_config: parsedBody.data.triggerConfig
|
|
3300
|
+
});
|
|
3301
|
+
const parsedResult = TriggerInstanceUpsertResponseSchema.safeParse({
|
|
3302
|
+
triggerId: result.trigger_id
|
|
3303
|
+
});
|
|
3304
|
+
if (!parsedResult.success) {
|
|
3305
|
+
throw new ValidationError(`Invalid trigger instance upsert response`, {
|
|
3306
|
+
cause: parsedResult.error
|
|
3307
|
+
});
|
|
3308
|
+
}
|
|
3309
|
+
return parsedResult.data;
|
|
2901
3310
|
}
|
|
2902
3311
|
/**
|
|
2903
3312
|
* Update an existing trigger instance
|
|
2904
3313
|
*
|
|
2905
3314
|
* @param {string} slug - The slug of the trigger instance
|
|
2906
|
-
* @param {
|
|
3315
|
+
* @param {TriggerInstanceManageUpdateParams} body - The parameters to create the trigger instance
|
|
2907
3316
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2908
3317
|
*/
|
|
2909
|
-
async update(slug, body
|
|
2910
|
-
return this.client.triggerInstances.
|
|
3318
|
+
async update(slug, body) {
|
|
3319
|
+
return this.client.triggerInstances.manage.update(slug, body);
|
|
2911
3320
|
}
|
|
2912
3321
|
/**
|
|
2913
3322
|
* Delete a trigger instance
|
|
2914
3323
|
*
|
|
2915
|
-
* @param {string}
|
|
3324
|
+
* @param {string} triggerId - The slug of the trigger instance
|
|
2916
3325
|
* @returns
|
|
2917
3326
|
*/
|
|
2918
|
-
async delete(
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
async updateStatus(status, params, options) {
|
|
2930
|
-
return this.client.triggerInstances.updateStatus(status, params, options);
|
|
3327
|
+
async delete(triggerId) {
|
|
3328
|
+
const result = await this.client.triggerInstances.manage.delete(triggerId);
|
|
3329
|
+
const parsedResult = TriggerInstanceManageDeleteResponseSchema.safeParse({
|
|
3330
|
+
triggerId: result.trigger_id
|
|
3331
|
+
});
|
|
3332
|
+
if (!parsedResult.success) {
|
|
3333
|
+
throw new ValidationError(`Invalid trigger instance manage delete response`, {
|
|
3334
|
+
cause: parsedResult.error
|
|
3335
|
+
});
|
|
3336
|
+
}
|
|
3337
|
+
return parsedResult.data;
|
|
2931
3338
|
}
|
|
2932
3339
|
/**
|
|
2933
3340
|
* Disable a trigger instance
|
|
2934
3341
|
*
|
|
2935
|
-
* @param {string}
|
|
2936
|
-
* @param {RequestOptions options - Request options
|
|
3342
|
+
* @param {string} triggerId - The id of the trigger instance
|
|
2937
3343
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2938
3344
|
*/
|
|
2939
|
-
async disable(
|
|
2940
|
-
return this.client.triggerInstances.
|
|
3345
|
+
async disable(triggerId) {
|
|
3346
|
+
return this.client.triggerInstances.manage.update(triggerId, {
|
|
3347
|
+
status: "disable"
|
|
3348
|
+
});
|
|
2941
3349
|
}
|
|
2942
3350
|
/**
|
|
2943
3351
|
* Enable a trigger instance
|
|
2944
3352
|
*
|
|
2945
|
-
* @param {string}
|
|
2946
|
-
* @param {RequestOptions options - Request options
|
|
3353
|
+
* @param {string} triggerId - The id of the trigger instance
|
|
2947
3354
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2948
3355
|
*/
|
|
2949
|
-
async enable(
|
|
2950
|
-
return this.client.triggerInstances.
|
|
3356
|
+
async enable(triggerId) {
|
|
3357
|
+
return this.client.triggerInstances.manage.update(triggerId, {
|
|
3358
|
+
status: "enable"
|
|
3359
|
+
});
|
|
2951
3360
|
}
|
|
2952
3361
|
/**
|
|
2953
3362
|
* @TODO Learn about trigger types
|
|
@@ -2959,8 +3368,8 @@ var Triggers = class {
|
|
|
2959
3368
|
* @param {RequestOptions} options - Request options
|
|
2960
3369
|
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
|
|
2961
3370
|
*/
|
|
2962
|
-
async listTypes(query
|
|
2963
|
-
return this.client.triggersTypes.list(query
|
|
3371
|
+
async listTypes(query) {
|
|
3372
|
+
return this.client.triggersTypes.list(query);
|
|
2964
3373
|
}
|
|
2965
3374
|
/**
|
|
2966
3375
|
* Retrieve a trigger type by its slug
|
|
@@ -2969,8 +3378,8 @@ var Triggers = class {
|
|
|
2969
3378
|
* @param {RequestOptions} options - request options
|
|
2970
3379
|
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
2971
3380
|
*/
|
|
2972
|
-
async getType(slug
|
|
2973
|
-
return this.client.triggersTypes.retrieve(slug
|
|
3381
|
+
async getType(slug) {
|
|
3382
|
+
return this.client.triggersTypes.retrieve(slug);
|
|
2974
3383
|
}
|
|
2975
3384
|
/**
|
|
2976
3385
|
* Fetches the list of all the available trigger enums
|
|
@@ -2979,36 +3388,137 @@ var Triggers = class {
|
|
|
2979
3388
|
* @param options
|
|
2980
3389
|
* @returns
|
|
2981
3390
|
*/
|
|
2982
|
-
async listEnum(
|
|
2983
|
-
return this.client.triggersTypes.retrieveEnum(
|
|
3391
|
+
async listEnum() {
|
|
3392
|
+
return this.client.triggersTypes.retrieveEnum();
|
|
2984
3393
|
}
|
|
3394
|
+
/**
|
|
3395
|
+
* Subscribe to all the triggers
|
|
3396
|
+
*
|
|
3397
|
+
* @param fn - The function to call when a trigger is received
|
|
3398
|
+
* @param filters - The filters to apply to the triggers
|
|
3399
|
+
*
|
|
3400
|
+
* @example
|
|
3401
|
+
* ```ts
|
|
3402
|
+
*
|
|
3403
|
+
* triggers.subscribe((data) => {
|
|
3404
|
+
* console.log(data);
|
|
3405
|
+
* }, );
|
|
3406
|
+
* ```
|
|
3407
|
+
*/
|
|
2985
3408
|
async subscribe(fn, filters = {}) {
|
|
2986
3409
|
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
2987
|
-
const
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
const
|
|
2994
|
-
if (
|
|
2995
|
-
|
|
2996
|
-
|
|
3410
|
+
const parsedFilters = TriggerSubscribeParamSchema.safeParse(filters);
|
|
3411
|
+
if (!parsedFilters.success) {
|
|
3412
|
+
throw new ValidationError(`Invalid parameters passed to subscribe to triggers`, {
|
|
3413
|
+
cause: parsedFilters.error
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
const shouldSendTriggerAfterFilters = (data) => {
|
|
3417
|
+
if (parsedFilters.data.toolkits?.length && !parsedFilters.data.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
|
|
3418
|
+
logger_default.debug(
|
|
3419
|
+
"Trigger does not match toolkits filter",
|
|
3420
|
+
JSON.stringify(parsedFilters.data.toolkits, null, 2)
|
|
3421
|
+
);
|
|
3422
|
+
return false;
|
|
3423
|
+
}
|
|
3424
|
+
if (parsedFilters.data.triggerId && parsedFilters.data.triggerId !== data.id) {
|
|
3425
|
+
logger_default.debug(
|
|
3426
|
+
"Trigger does not match triggerId filter",
|
|
3427
|
+
JSON.stringify(parsedFilters.data.triggerId, null, 2)
|
|
3428
|
+
);
|
|
3429
|
+
return false;
|
|
2997
3430
|
}
|
|
3431
|
+
if (parsedFilters.data.connectedAccountId && parsedFilters.data.connectedAccountId !== data.metadata.connectedAccount.id) {
|
|
3432
|
+
logger_default.debug(
|
|
3433
|
+
"Trigger does not match connectedAccountId filter",
|
|
3434
|
+
JSON.stringify(parsedFilters.data.connectedAccountId, null, 2)
|
|
3435
|
+
);
|
|
3436
|
+
return false;
|
|
3437
|
+
}
|
|
3438
|
+
if (parsedFilters.data.triggerSlug?.length && !parsedFilters.data.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
|
|
3439
|
+
logger_default.debug(
|
|
3440
|
+
"Trigger does not match triggerSlug filter",
|
|
3441
|
+
JSON.stringify(parsedFilters.data.triggerSlug, null, 2)
|
|
3442
|
+
);
|
|
3443
|
+
return false;
|
|
3444
|
+
}
|
|
3445
|
+
if (parsedFilters.data.triggerData && parsedFilters.data.triggerData !== data.metadata.triggerData) {
|
|
3446
|
+
logger_default.debug(
|
|
3447
|
+
"Trigger does not match triggerData filter",
|
|
3448
|
+
JSON.stringify(parsedFilters.data.triggerData, null, 2)
|
|
3449
|
+
);
|
|
3450
|
+
return false;
|
|
3451
|
+
}
|
|
3452
|
+
if (parsedFilters.data.userId && parsedFilters.data.userId !== data.metadata.connectedAccount.userId) {
|
|
3453
|
+
logger_default.debug(
|
|
3454
|
+
"Trigger does not match userId filter",
|
|
3455
|
+
JSON.stringify(parsedFilters.data.userId, null, 2)
|
|
3456
|
+
);
|
|
3457
|
+
return false;
|
|
3458
|
+
}
|
|
3459
|
+
logger_default.debug("Trigger matches all filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
3460
|
+
return true;
|
|
2998
3461
|
};
|
|
2999
|
-
logger_default.debug("Subscribing to triggers", filters);
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3462
|
+
logger_default.debug("\u{1F504} Subscribing to triggers with filters: ", JSON.stringify(filters, null, 2));
|
|
3463
|
+
await this.pusherService.subscribe((_data) => {
|
|
3464
|
+
logger_default.debug("Received raw trigger data", JSON.stringify(_data, null, 2));
|
|
3465
|
+
const data = _data;
|
|
3466
|
+
const parsedData = IncomingTriggerPayloadSchema.safeParse({
|
|
3467
|
+
id: data.metadata.id,
|
|
3468
|
+
triggerSlug: data.metadata.triggerName,
|
|
3469
|
+
toolkitSlug: data.appName,
|
|
3470
|
+
userId: data.metadata.connection?.clientUniqueUserId,
|
|
3471
|
+
payload: data.payload,
|
|
3472
|
+
originalPayload: data.originalPayload,
|
|
3473
|
+
metadata: {
|
|
3474
|
+
id: data.metadata.id,
|
|
3475
|
+
triggerConfig: data.metadata.triggerConfig,
|
|
3476
|
+
triggerSlug: data.metadata.triggerName,
|
|
3477
|
+
toolkitSlug: data.appName,
|
|
3478
|
+
triggerData: data.metadata.triggerData,
|
|
3479
|
+
connectedAccount: {
|
|
3480
|
+
id: data.metadata.connection?.connectedAccountNanoId,
|
|
3481
|
+
uuid: data.metadata.connection?.id,
|
|
3482
|
+
authConfigId: data.metadata.connection?.authConfigNanoId,
|
|
3483
|
+
authConfigUUID: data.metadata.connection?.integrationId,
|
|
3484
|
+
userId: data.metadata.connection?.clientUniqueUserId,
|
|
3485
|
+
status: data.metadata.connection?.status
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
});
|
|
3489
|
+
logger_default.debug("Parsed trigger data", JSON.stringify(parsedData.data, null, 2));
|
|
3490
|
+
if (parsedData.error) {
|
|
3491
|
+
throw new ValidationError(`Invalid trigger payload`, {
|
|
3492
|
+
cause: parsedData.error
|
|
3493
|
+
});
|
|
3494
|
+
}
|
|
3495
|
+
if (shouldSendTriggerAfterFilters(parsedData.data)) {
|
|
3496
|
+
try {
|
|
3497
|
+
fn(parsedData.data);
|
|
3498
|
+
} catch (error) {
|
|
3499
|
+
logger_default.error("\u274C Error in trigger callback:", error);
|
|
3500
|
+
}
|
|
3501
|
+
} else {
|
|
3502
|
+
logger_default.debug("Trigger does not match filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
3003
3503
|
}
|
|
3004
3504
|
});
|
|
3005
3505
|
}
|
|
3506
|
+
/**
|
|
3507
|
+
* Unsubscribe from all the triggers
|
|
3508
|
+
*
|
|
3509
|
+
* @returns {Promise<void>}
|
|
3510
|
+
*
|
|
3511
|
+
* @example
|
|
3512
|
+
* ```ts
|
|
3513
|
+
* composio.trigger.subscribe((data) => {
|
|
3514
|
+
* console.log(data);
|
|
3515
|
+
* });
|
|
3516
|
+
*
|
|
3517
|
+
* await triggers.unsubscribe();
|
|
3518
|
+
* ```
|
|
3519
|
+
*/
|
|
3006
3520
|
async unsubscribe() {
|
|
3007
|
-
|
|
3008
|
-
const sessionInfo = await session.getInfo();
|
|
3009
|
-
const clientId = sessionInfo.project?.id;
|
|
3010
|
-
if (!clientId) throw new Error("Client ID not found");
|
|
3011
|
-
PusherUtils.triggerUnsubscribe(clientId);
|
|
3521
|
+
await this.pusherService.unsubscribe();
|
|
3012
3522
|
}
|
|
3013
3523
|
};
|
|
3014
3524
|
|
|
@@ -3091,7 +3601,7 @@ var BaseProvider = class {
|
|
|
3091
3601
|
}
|
|
3092
3602
|
/**
|
|
3093
3603
|
* @public
|
|
3094
|
-
*
|
|
3604
|
+
* Global function to execute a tool.
|
|
3095
3605
|
* This function is used by provider providers to implement helper functions to execute tools.
|
|
3096
3606
|
* This is a 1:1 mapping of the `execute` method in the `Tools` class.
|
|
3097
3607
|
* @param {string} toolSlug - The slug of the tool to execute.
|
|
@@ -3158,7 +3668,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3158
3668
|
* @param {string} userId - The user id.
|
|
3159
3669
|
* @returns {Promise<string[]>} The results of the tool call.
|
|
3160
3670
|
*/
|
|
3161
|
-
async
|
|
3671
|
+
async handleToolCalls(userId, chatCompletion, options, modifiers) {
|
|
3162
3672
|
const outputs = [];
|
|
3163
3673
|
for (const message of chatCompletion.choices) {
|
|
3164
3674
|
if (message.message.tool_calls) {
|
|
@@ -3278,7 +3788,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3278
3788
|
};
|
|
3279
3789
|
|
|
3280
3790
|
// package.json
|
|
3281
|
-
var version = "0.1.12-alpha.
|
|
3791
|
+
var version = "0.1.12-alpha.13";
|
|
3282
3792
|
|
|
3283
3793
|
// src/composio.ts
|
|
3284
3794
|
var Composio = class {
|
|
@@ -3340,7 +3850,7 @@ var Composio = class {
|
|
|
3340
3850
|
{
|
|
3341
3851
|
apiKey: apiKeyParsed ?? "",
|
|
3342
3852
|
baseUrl: baseURLParsed ?? "",
|
|
3343
|
-
frameworkRuntime: this.provider?.name
|
|
3853
|
+
frameworkRuntime: this.provider?.name ?? "unknown",
|
|
3344
3854
|
isAgentic: this.provider?._isAgentic || false,
|
|
3345
3855
|
source: "javascript",
|
|
3346
3856
|
version,
|
|
@@ -3393,39 +3903,39 @@ var ConsoleTelemetryTransport = class {
|
|
|
3393
3903
|
};
|
|
3394
3904
|
|
|
3395
3905
|
// src/utils/jsonSchema.ts
|
|
3396
|
-
import { z as
|
|
3906
|
+
import { z as z7 } from "zod";
|
|
3397
3907
|
function jsonSchemaPropertiesToTSTypes(value) {
|
|
3398
3908
|
if (!value.type) {
|
|
3399
|
-
return
|
|
3909
|
+
return z7.object({});
|
|
3400
3910
|
}
|
|
3401
3911
|
let zodType;
|
|
3402
3912
|
switch (value.type) {
|
|
3403
3913
|
case "string":
|
|
3404
|
-
zodType =
|
|
3914
|
+
zodType = z7.string().describe(
|
|
3405
3915
|
(value.description || "") + (value.examples ? `
|
|
3406
3916
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3407
3917
|
);
|
|
3408
3918
|
break;
|
|
3409
3919
|
case "number":
|
|
3410
|
-
zodType =
|
|
3920
|
+
zodType = z7.number().describe(
|
|
3411
3921
|
(value.description || "") + (value.examples ? `
|
|
3412
3922
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3413
3923
|
);
|
|
3414
3924
|
break;
|
|
3415
3925
|
case "integer":
|
|
3416
|
-
zodType =
|
|
3926
|
+
zodType = z7.number().int().describe(
|
|
3417
3927
|
(value.description || "") + (value.examples ? `
|
|
3418
3928
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3419
3929
|
);
|
|
3420
3930
|
break;
|
|
3421
3931
|
case "boolean":
|
|
3422
|
-
zodType =
|
|
3932
|
+
zodType = z7.boolean().describe(
|
|
3423
3933
|
(value.description || "") + (value.examples ? `
|
|
3424
3934
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3425
3935
|
);
|
|
3426
3936
|
break;
|
|
3427
3937
|
case "array":
|
|
3428
|
-
zodType =
|
|
3938
|
+
zodType = z7.array(
|
|
3429
3939
|
jsonSchemaPropertiesToTSTypes(
|
|
3430
3940
|
value.items
|
|
3431
3941
|
)
|
|
@@ -3435,24 +3945,24 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3435
3945
|
);
|
|
3436
3946
|
break;
|
|
3437
3947
|
case "object":
|
|
3438
|
-
zodType =
|
|
3948
|
+
zodType = jsonSchemaToZodSchema(value).describe(
|
|
3439
3949
|
(value.description || "") + (value.examples ? `
|
|
3440
3950
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3441
3951
|
);
|
|
3442
3952
|
break;
|
|
3443
3953
|
case "null":
|
|
3444
|
-
zodType =
|
|
3954
|
+
zodType = z7.null().describe(value.description || "");
|
|
3445
3955
|
break;
|
|
3446
3956
|
default:
|
|
3447
3957
|
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
3448
3958
|
}
|
|
3449
3959
|
return zodType;
|
|
3450
3960
|
}
|
|
3451
|
-
function
|
|
3961
|
+
function jsonSchemaToZodSchema(jsonSchema) {
|
|
3452
3962
|
const properties = jsonSchema.properties;
|
|
3453
3963
|
const requiredFields = jsonSchema.required || [];
|
|
3454
3964
|
if (!properties) {
|
|
3455
|
-
return
|
|
3965
|
+
return z7.object({});
|
|
3456
3966
|
}
|
|
3457
3967
|
const zodSchema = {};
|
|
3458
3968
|
for (const [key, _] of Object.entries(properties)) {
|
|
@@ -3464,7 +3974,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
3464
3974
|
schema
|
|
3465
3975
|
)
|
|
3466
3976
|
);
|
|
3467
|
-
zodType =
|
|
3977
|
+
zodType = z7.union(anyOfTypes).describe(
|
|
3468
3978
|
(value.description || "") + (value.examples ? `
|
|
3469
3979
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3470
3980
|
);
|
|
@@ -3474,7 +3984,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3474
3984
|
schema
|
|
3475
3985
|
)
|
|
3476
3986
|
);
|
|
3477
|
-
zodType =
|
|
3987
|
+
zodType = z7.intersection(
|
|
3478
3988
|
allOfTypes[0],
|
|
3479
3989
|
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
3480
3990
|
).describe(
|
|
@@ -3498,7 +4008,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3498
4008
|
zodSchema[key] = zodType.optional();
|
|
3499
4009
|
}
|
|
3500
4010
|
}
|
|
3501
|
-
return
|
|
4011
|
+
return z7.object(zodSchema);
|
|
3502
4012
|
}
|
|
3503
4013
|
export {
|
|
3504
4014
|
AuthConfigErrorCodes,
|
|
@@ -3534,5 +4044,6 @@ export {
|
|
|
3534
4044
|
ToolkitErrorCodes,
|
|
3535
4045
|
ValidationError,
|
|
3536
4046
|
ValidationErrorCodes,
|
|
3537
|
-
|
|
4047
|
+
jsonSchemaToZodSchema,
|
|
4048
|
+
logger_default as logger
|
|
3538
4049
|
};
|