@composio/core 0.1.12-alpha.11 → 0.1.12-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +704 -218
- package/dist/index.d.cts +483 -94
- package/dist/index.d.ts +483 -94
- package/dist/index.js +700 -215
- 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"')
|
|
@@ -33,8 +59,8 @@ var ToolListResponseSchema = z.object({
|
|
|
33
59
|
var ToolListParamsSchema = z.object({
|
|
34
60
|
tools: z.array(z.string()).optional(),
|
|
35
61
|
cursor: z.string().optional(),
|
|
36
|
-
important: z.
|
|
37
|
-
limit: z.
|
|
62
|
+
important: z.boolean().optional(),
|
|
63
|
+
limit: z.number().optional(),
|
|
38
64
|
search: z.string().optional(),
|
|
39
65
|
toolkits: z.array(z.string()).optional()
|
|
40
66
|
});
|
|
@@ -172,18 +198,19 @@ var ComposioError = class _ComposioError extends Error {
|
|
|
172
198
|
*/
|
|
173
199
|
constructor(message, options = {}) {
|
|
174
200
|
super(message);
|
|
201
|
+
if (Error.captureStackTrace) {
|
|
202
|
+
Error.captureStackTrace(this, this.constructor);
|
|
203
|
+
}
|
|
175
204
|
const statusCode = options.statusCode || (options.cause instanceof BadRequestError ? options.cause.status : void 0);
|
|
176
205
|
this.code = `TS-SDK::${options.code}`;
|
|
177
206
|
this.possibleFixes = options.possibleFixes;
|
|
178
207
|
this.definePropertyIfExists("statusCode", statusCode);
|
|
179
208
|
this.definePropertyIfExists("cause", options.cause);
|
|
180
|
-
|
|
209
|
+
const combinedStack = options.cause instanceof Error ? _ComposioError.combineStackTraces(options.cause.stack, this.stack) : options.stack ?? this.stack;
|
|
210
|
+
this.definePropertyIfExists("stack", combinedStack);
|
|
181
211
|
if (options.meta && Object.keys(options.meta).length > 0) {
|
|
182
212
|
this.definePropertyIfExists("meta", options.meta);
|
|
183
213
|
}
|
|
184
|
-
if (Error.captureStackTrace) {
|
|
185
|
-
Error.captureStackTrace(this, this.constructor);
|
|
186
|
-
}
|
|
187
214
|
}
|
|
188
215
|
/**
|
|
189
216
|
* Helper method to define a property only if it has a value
|
|
@@ -201,6 +228,25 @@ var ComposioError = class _ComposioError extends Error {
|
|
|
201
228
|
});
|
|
202
229
|
}
|
|
203
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Helper method to combine stack traces when wrapping errors
|
|
233
|
+
* This ensures the full call chain is preserved
|
|
234
|
+
* @param originalStack The stack of the error being wrapped
|
|
235
|
+
* @param currentStack The stack of the wrapper error
|
|
236
|
+
* @returns Combined stack trace
|
|
237
|
+
* @private
|
|
238
|
+
*/
|
|
239
|
+
static combineStackTraces(originalStack, currentStack) {
|
|
240
|
+
if (!originalStack) return currentStack;
|
|
241
|
+
if (!currentStack) return originalStack;
|
|
242
|
+
const currentHeader = currentStack.split("\n")[0];
|
|
243
|
+
const originalStackBody = originalStack.split("\n").slice(1).join("\n");
|
|
244
|
+
return `${currentHeader}
|
|
245
|
+
${currentStack.split("\n").slice(1).join("\n")}
|
|
246
|
+
|
|
247
|
+
Caused by:
|
|
248
|
+
${originalStackBody}`;
|
|
249
|
+
}
|
|
204
250
|
/**
|
|
205
251
|
* Extract and normalize error data for formatting
|
|
206
252
|
* @param includeStack Whether to include stack trace information
|
|
@@ -230,7 +276,16 @@ var ComposioError = class _ComposioError extends Error {
|
|
|
230
276
|
data.possibleFixes = possibleFixes;
|
|
231
277
|
}
|
|
232
278
|
if (includeStack && stack) {
|
|
233
|
-
|
|
279
|
+
if (stack.includes("Caused by:")) {
|
|
280
|
+
const [currentStack, causeStack] = stack.split("Caused by:");
|
|
281
|
+
data.stack = [
|
|
282
|
+
...currentStack.split("\n").slice(1),
|
|
283
|
+
"Caused by:",
|
|
284
|
+
...causeStack.split("\n")
|
|
285
|
+
];
|
|
286
|
+
} else {
|
|
287
|
+
data.stack = stack.split("\n").slice(1);
|
|
288
|
+
}
|
|
234
289
|
}
|
|
235
290
|
return data;
|
|
236
291
|
}
|
|
@@ -434,7 +489,7 @@ var ComposioToolExecutionError = class extends ComposioError {
|
|
|
434
489
|
"Ensure the tool is correctly configured and the input is valid"
|
|
435
490
|
]
|
|
436
491
|
});
|
|
437
|
-
this.error = originalError || (options.cause instanceof Error ? options.cause : new Error(String(options.cause)));
|
|
492
|
+
this.error = originalError || (options.cause instanceof Error ? options.cause : options.cause ? new Error(String(options.cause)) : new Error("Unknown error"));
|
|
438
493
|
this.name = "ComposioToolExecutionError";
|
|
439
494
|
}
|
|
440
495
|
};
|
|
@@ -670,7 +725,7 @@ var TelemetryService = class {
|
|
|
670
725
|
const descriptor = Object.getOwnPropertyDescriptor(proto, key);
|
|
671
726
|
return key !== "constructor" && descriptor && typeof descriptor.value === "function" && descriptor.value.constructor.name === "AsyncFunction";
|
|
672
727
|
});
|
|
673
|
-
const instrumentedClassName = instance.constructor?.name || fileName
|
|
728
|
+
const instrumentedClassName = (instance.constructor?.name || fileName) ?? "unknown";
|
|
674
729
|
for (const name of methodNames) {
|
|
675
730
|
const originalMethod = instance[name];
|
|
676
731
|
instance[name] = async (...args) => {
|
|
@@ -686,9 +741,11 @@ var TelemetryService = class {
|
|
|
686
741
|
try {
|
|
687
742
|
return await originalMethod.apply(instance, args);
|
|
688
743
|
} catch (error) {
|
|
689
|
-
if (error instanceof Error
|
|
690
|
-
error.errorId
|
|
691
|
-
|
|
744
|
+
if (error instanceof Error) {
|
|
745
|
+
if (!error.errorId) {
|
|
746
|
+
error.errorId = getRandomUUID();
|
|
747
|
+
this.prepareAndSendErrorTelemetry(error, instrumentedClassName, name, args);
|
|
748
|
+
}
|
|
692
749
|
}
|
|
693
750
|
throw error;
|
|
694
751
|
}
|
|
@@ -722,7 +779,7 @@ var TelemetryService = class {
|
|
|
722
779
|
error_id: error.errorId || "",
|
|
723
780
|
error_message: error.message,
|
|
724
781
|
original_error: error.cause || error,
|
|
725
|
-
current_stack: error.stack
|
|
782
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
726
783
|
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
727
784
|
};
|
|
728
785
|
this.sendErrorTelemetry(telemetryPayload);
|
|
@@ -731,7 +788,7 @@ var TelemetryService = class {
|
|
|
731
788
|
error_id: error.errorId || "",
|
|
732
789
|
error_message: error.message,
|
|
733
790
|
original_error: error.cause || error,
|
|
734
|
-
current_stack: error.stack
|
|
791
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
735
792
|
error_code: error.code,
|
|
736
793
|
possible_fix: error.possibleFixes?.join("\n"),
|
|
737
794
|
description: `Original Call : ${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
@@ -742,7 +799,7 @@ var TelemetryService = class {
|
|
|
742
799
|
error_id: error.errorId || "",
|
|
743
800
|
error_message: error instanceof Error ? error.name : "Unknown error",
|
|
744
801
|
original_error: error,
|
|
745
|
-
current_stack: error.stack
|
|
802
|
+
current_stack: error.stack ? error.stack.split("\n") : [],
|
|
746
803
|
description: `Original Call : ${this.telemetryMetadata?.source}:${instrumentedClassName}.${name}(${JSON.stringify(args)})`
|
|
747
804
|
};
|
|
748
805
|
this.sendErrorTelemetry(telemetryPayload);
|
|
@@ -889,8 +946,7 @@ var CustomTools = class {
|
|
|
889
946
|
await this.client.toolkits.retrieve(toolkitSlug);
|
|
890
947
|
} catch (error) {
|
|
891
948
|
throw new ComposioToolNotFoundError(`Toolkit with slug ${toolkitSlug} not found`, {
|
|
892
|
-
|
|
893
|
-
error
|
|
949
|
+
cause: error
|
|
894
950
|
});
|
|
895
951
|
}
|
|
896
952
|
const connectedAccounts = await this.client.connectedAccounts.list({
|
|
@@ -899,10 +955,7 @@ var CustomTools = class {
|
|
|
899
955
|
});
|
|
900
956
|
if (!connectedAccounts.items.length) {
|
|
901
957
|
throw new ComposioConnectedAccountNotFoundError(
|
|
902
|
-
`No connected accounts found for toolkit ${toolkitSlug}
|
|
903
|
-
{
|
|
904
|
-
toolkitSlug
|
|
905
|
-
}
|
|
958
|
+
`No connected accounts found for toolkit ${toolkitSlug}`
|
|
906
959
|
);
|
|
907
960
|
}
|
|
908
961
|
return metadata.connectedAccountId ? connectedAccounts.items.find((item) => item.id === metadata.connectedAccountId) : connectedAccounts.items[0];
|
|
@@ -917,9 +970,7 @@ var CustomTools = class {
|
|
|
917
970
|
async executeCustomTool(slug, inputParams, metadata) {
|
|
918
971
|
const tool = this.customToolsRegistry.get(slug.toLowerCase());
|
|
919
972
|
if (!tool) {
|
|
920
|
-
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found
|
|
921
|
-
toolSlug: slug
|
|
922
|
-
});
|
|
973
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
|
|
923
974
|
}
|
|
924
975
|
let authCredentials = {};
|
|
925
976
|
const { toolkitSlug, execute } = tool.options;
|
|
@@ -929,8 +980,10 @@ var CustomTools = class {
|
|
|
929
980
|
throw new ComposioConnectedAccountNotFoundError(
|
|
930
981
|
`Connected account not found for toolkit ${toolkitSlug} for user ${metadata.userId}`,
|
|
931
982
|
{
|
|
932
|
-
|
|
933
|
-
|
|
983
|
+
meta: {
|
|
984
|
+
toolkitSlug,
|
|
985
|
+
userId: metadata.userId
|
|
986
|
+
}
|
|
934
987
|
}
|
|
935
988
|
);
|
|
936
989
|
}
|
|
@@ -938,7 +991,9 @@ var CustomTools = class {
|
|
|
938
991
|
}
|
|
939
992
|
if (typeof execute !== "function") {
|
|
940
993
|
throw new ComposioInvalidExecuteFunctionError("Invalid execute function", {
|
|
941
|
-
|
|
994
|
+
meta: {
|
|
995
|
+
toolSlug: slug
|
|
996
|
+
}
|
|
942
997
|
});
|
|
943
998
|
}
|
|
944
999
|
const executeToolRequest = async (data) => {
|
|
@@ -1173,11 +1228,11 @@ var Tools = class {
|
|
|
1173
1228
|
});
|
|
1174
1229
|
}
|
|
1175
1230
|
const tools = await this.client.tools.list({
|
|
1176
|
-
tool_slugs: queryParams.data.tools,
|
|
1231
|
+
tool_slugs: queryParams.data.tools?.join(","),
|
|
1177
1232
|
toolkit_slug: queryParams.data.toolkits?.join(","),
|
|
1178
1233
|
cursor: queryParams.data.cursor,
|
|
1179
|
-
important: queryParams.data.important,
|
|
1180
|
-
limit: queryParams.data.limit,
|
|
1234
|
+
important: typeof queryParams.data.important === "undefined" ? void 0 : queryParams.data.important ? "true" : "false",
|
|
1235
|
+
limit: queryParams.data.limit?.toString(),
|
|
1181
1236
|
search: queryParams.data.search
|
|
1182
1237
|
});
|
|
1183
1238
|
if (!tools) {
|
|
@@ -1191,7 +1246,7 @@ var Tools = class {
|
|
|
1191
1246
|
if (modifier) {
|
|
1192
1247
|
if (typeof modifier === "function") {
|
|
1193
1248
|
modifiedTools = modifiedTools.map((tool) => {
|
|
1194
|
-
return modifier(tool.slug, tool.toolkit?.slug
|
|
1249
|
+
return modifier(tool.slug, tool.toolkit?.slug ?? "unknown", tool);
|
|
1195
1250
|
});
|
|
1196
1251
|
} else {
|
|
1197
1252
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
@@ -1223,15 +1278,15 @@ var Tools = class {
|
|
|
1223
1278
|
cause: error
|
|
1224
1279
|
});
|
|
1225
1280
|
}
|
|
1226
|
-
let
|
|
1281
|
+
let modifiedTool = this.transformToolCases(tool);
|
|
1227
1282
|
if (modifier) {
|
|
1228
1283
|
if (typeof modifier === "function") {
|
|
1229
|
-
|
|
1284
|
+
modifiedTool = modifier(slug, modifiedTool.toolkit?.slug ?? "unknown", modifiedTool);
|
|
1230
1285
|
} else {
|
|
1231
1286
|
throw new ComposioInvalidModifierError("Invalid schema modifier. Not a function.");
|
|
1232
1287
|
}
|
|
1233
1288
|
}
|
|
1234
|
-
return
|
|
1289
|
+
return modifiedTool;
|
|
1235
1290
|
}
|
|
1236
1291
|
/**
|
|
1237
1292
|
* Get a tool or list of tools based on the provided arguments.
|
|
@@ -1284,7 +1339,7 @@ var Tools = class {
|
|
|
1284
1339
|
async handleCustomToolExecution(tool, body, modifiers) {
|
|
1285
1340
|
if (modifiers?.beforeExecute) {
|
|
1286
1341
|
if (typeof modifiers.beforeExecute === "function") {
|
|
1287
|
-
body = modifiers.beforeExecute(tool.slug, "
|
|
1342
|
+
body = modifiers.beforeExecute(tool.slug, "unknown", body);
|
|
1288
1343
|
} else {
|
|
1289
1344
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
1290
1345
|
}
|
|
@@ -1295,7 +1350,7 @@ var Tools = class {
|
|
|
1295
1350
|
});
|
|
1296
1351
|
if (modifiers?.afterExecute) {
|
|
1297
1352
|
if (typeof modifiers.afterExecute === "function") {
|
|
1298
|
-
result = modifiers.afterExecute(tool.slug, "
|
|
1353
|
+
result = modifiers.afterExecute(tool.slug, "unknown", result);
|
|
1299
1354
|
} else {
|
|
1300
1355
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
1301
1356
|
}
|
|
@@ -1313,7 +1368,7 @@ var Tools = class {
|
|
|
1313
1368
|
async handleComposioToolExecution(tool, body, modifiers) {
|
|
1314
1369
|
if (modifiers?.beforeExecute) {
|
|
1315
1370
|
if (typeof modifiers.beforeExecute === "function") {
|
|
1316
|
-
body = modifiers.beforeExecute(tool.slug, tool.toolkit?.slug
|
|
1371
|
+
body = modifiers.beforeExecute(tool.slug, tool.toolkit?.slug ?? "unknown", body);
|
|
1317
1372
|
} else {
|
|
1318
1373
|
throw new ComposioInvalidModifierError("Invalid beforeExecute modifier. Not a function.");
|
|
1319
1374
|
}
|
|
@@ -1334,7 +1389,7 @@ var Tools = class {
|
|
|
1334
1389
|
result = this.transformToolExecuteResponse(result);
|
|
1335
1390
|
if (modifiers?.afterExecute) {
|
|
1336
1391
|
if (typeof modifiers.afterExecute === "function") {
|
|
1337
|
-
result = modifiers.afterExecute(tool.slug, tool.toolkit?.slug
|
|
1392
|
+
result = modifiers.afterExecute(tool.slug, tool.toolkit?.slug ?? "unknown", result);
|
|
1338
1393
|
} else {
|
|
1339
1394
|
throw new ComposioInvalidModifierError("Invalid afterExecute modifier. Not a function.");
|
|
1340
1395
|
}
|
|
@@ -1739,7 +1794,7 @@ var AuthConfigListParamsSchema = z3.object({
|
|
|
1739
1794
|
});
|
|
1740
1795
|
var AuthConfigListResponseSchema = z3.object({
|
|
1741
1796
|
items: z3.array(AuthConfigRetrieveResponseSchema),
|
|
1742
|
-
nextCursor: z3.string().
|
|
1797
|
+
nextCursor: z3.string().nullable(),
|
|
1743
1798
|
totalPages: z3.number()
|
|
1744
1799
|
});
|
|
1745
1800
|
var AuthCustomConfigUpdateParamsSchema = z3.object({
|
|
@@ -1841,7 +1896,7 @@ var AuthConfigs = class {
|
|
|
1841
1896
|
const result = await this.client.authConfigs.list({
|
|
1842
1897
|
cursor: parsedQuery?.cursor,
|
|
1843
1898
|
is_composio_managed: parsedQuery?.isComposioManaged,
|
|
1844
|
-
limit: parsedQuery?.limit
|
|
1899
|
+
limit: parsedQuery?.limit,
|
|
1845
1900
|
toolkit_slug: parsedQuery?.toolkit
|
|
1846
1901
|
});
|
|
1847
1902
|
const parsedResult = AuthConfigListResponseSchema.safeParse({
|
|
@@ -2062,20 +2117,18 @@ var AuthConfigs = class {
|
|
|
2062
2117
|
// src/types/connectedAccounts.types.ts
|
|
2063
2118
|
import { z as z4 } from "zod";
|
|
2064
2119
|
var ConnectedAccountStatuses = {
|
|
2065
|
-
|
|
2066
|
-
INACTIVE: "INACTIVE",
|
|
2067
|
-
DELETED: "DELETED",
|
|
2120
|
+
INITIALIZING: "INITIALIZING",
|
|
2068
2121
|
INITIATED: "INITIATED",
|
|
2069
|
-
|
|
2070
|
-
FAILED: "FAILED"
|
|
2122
|
+
ACTIVE: "ACTIVE",
|
|
2123
|
+
FAILED: "FAILED",
|
|
2124
|
+
EXPIRED: "EXPIRED"
|
|
2071
2125
|
};
|
|
2072
2126
|
var ConnectedAccountStatusSchema = z4.enum([
|
|
2073
|
-
ConnectedAccountStatuses.
|
|
2074
|
-
ConnectedAccountStatuses.INACTIVE,
|
|
2075
|
-
ConnectedAccountStatuses.DELETED,
|
|
2127
|
+
ConnectedAccountStatuses.INITIALIZING,
|
|
2076
2128
|
ConnectedAccountStatuses.INITIATED,
|
|
2077
|
-
ConnectedAccountStatuses.
|
|
2078
|
-
ConnectedAccountStatuses.FAILED
|
|
2129
|
+
ConnectedAccountStatuses.ACTIVE,
|
|
2130
|
+
ConnectedAccountStatuses.FAILED,
|
|
2131
|
+
ConnectedAccountStatuses.EXPIRED
|
|
2079
2132
|
]);
|
|
2080
2133
|
var CreateConnectedAccountParamsSchema = z4.object({
|
|
2081
2134
|
authConfig: z4.object({
|
|
@@ -2277,8 +2330,7 @@ var ConnectionRequest = class {
|
|
|
2277
2330
|
}
|
|
2278
2331
|
const terminalErrorStates = [
|
|
2279
2332
|
ConnectedAccountStatuses.FAILED,
|
|
2280
|
-
ConnectedAccountStatuses.EXPIRED
|
|
2281
|
-
ConnectedAccountStatuses.DELETED
|
|
2333
|
+
ConnectedAccountStatuses.EXPIRED
|
|
2282
2334
|
];
|
|
2283
2335
|
const start = Date.now();
|
|
2284
2336
|
const pollInterval = 1e3;
|
|
@@ -2309,6 +2361,23 @@ var ConnectionRequest = class {
|
|
|
2309
2361
|
}
|
|
2310
2362
|
throw new ConnectionRequestTimeoutError(`Connection request timed out for ${this.id}`);
|
|
2311
2363
|
}
|
|
2364
|
+
/**
|
|
2365
|
+
* Returns a JSON-serializable representation of the connection request
|
|
2366
|
+
* Excludes the private client property to avoid cyclic reference issues
|
|
2367
|
+
*/
|
|
2368
|
+
toJSON() {
|
|
2369
|
+
return {
|
|
2370
|
+
id: this.id,
|
|
2371
|
+
status: this.status,
|
|
2372
|
+
redirectUrl: this.redirectUrl
|
|
2373
|
+
};
|
|
2374
|
+
}
|
|
2375
|
+
/**
|
|
2376
|
+
* Returns a string representation of the connection request
|
|
2377
|
+
*/
|
|
2378
|
+
toString() {
|
|
2379
|
+
return JSON.stringify(this.toJSON(), null, 2);
|
|
2380
|
+
}
|
|
2312
2381
|
};
|
|
2313
2382
|
|
|
2314
2383
|
// src/models/ConnectedAccounts.ts
|
|
@@ -2768,126 +2837,422 @@ var Toolkits = class {
|
|
|
2768
2837
|
}
|
|
2769
2838
|
};
|
|
2770
2839
|
|
|
2771
|
-
// src/
|
|
2772
|
-
|
|
2773
|
-
var
|
|
2774
|
-
var
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2840
|
+
// src/types/triggers.types.ts
|
|
2841
|
+
import { z as z5 } from "zod";
|
|
2842
|
+
var TriggerStatusEnum = z5.enum(["enable", "disable"]);
|
|
2843
|
+
var TriggerSubscribeParamSchema = z5.object({
|
|
2844
|
+
toolkits: z5.array(z5.string()).optional(),
|
|
2845
|
+
triggerId: z5.string().optional(),
|
|
2846
|
+
connectedAccountId: z5.string().optional(),
|
|
2847
|
+
authConfigId: z5.string().optional(),
|
|
2848
|
+
triggerSlug: z5.array(z5.string()).optional(),
|
|
2849
|
+
triggerData: z5.string().optional(),
|
|
2850
|
+
userId: z5.string().optional()
|
|
2851
|
+
});
|
|
2852
|
+
var TriggerInstanceListActiveParamsSchema = z5.object({
|
|
2853
|
+
authConfigIds: z5.array(z5.string()).nullable().optional(),
|
|
2854
|
+
connectedAccountIds: z5.array(z5.string()).nullable().optional(),
|
|
2855
|
+
limit: z5.number().optional(),
|
|
2856
|
+
page: z5.number().optional(),
|
|
2857
|
+
showDisabled: z5.boolean().nullable().optional(),
|
|
2858
|
+
triggerIds: z5.array(z5.string()).nullable().optional(),
|
|
2859
|
+
triggerNames: z5.array(z5.string()).nullable().optional()
|
|
2860
|
+
});
|
|
2861
|
+
var TriggerInstanceListActiveResponseItemSchema = z5.object({
|
|
2862
|
+
id: z5.string(),
|
|
2863
|
+
connectedAccountId: z5.string(),
|
|
2864
|
+
disabledAt: z5.string().nullable(),
|
|
2865
|
+
state: z5.record(z5.unknown()),
|
|
2866
|
+
triggerConfig: z5.record(z5.unknown()),
|
|
2867
|
+
triggerName: z5.string(),
|
|
2868
|
+
updatedAt: z5.string(),
|
|
2869
|
+
triggerData: z5.string().optional(),
|
|
2870
|
+
uuid: z5.string().optional()
|
|
2871
|
+
});
|
|
2872
|
+
var TriggerInstanceListActiveResponseSchema = z5.object({
|
|
2873
|
+
items: z5.array(TriggerInstanceListActiveResponseItemSchema),
|
|
2874
|
+
nextCursor: z5.string().nullable(),
|
|
2875
|
+
totalPages: z5.number()
|
|
2876
|
+
});
|
|
2877
|
+
var TriggerInstanceUpsertParamsSchema = z5.object({
|
|
2878
|
+
connectedAccountId: z5.string().optional(),
|
|
2879
|
+
triggerConfig: z5.record(z5.unknown()).optional()
|
|
2880
|
+
});
|
|
2881
|
+
var TriggerInstanceUpsertResponseSchema = z5.object({
|
|
2882
|
+
triggerId: z5.string()
|
|
2883
|
+
});
|
|
2884
|
+
var TriggerInstanceManageUpdateParamsSchema = z5.object({
|
|
2885
|
+
status: z5.enum(["enable", "disable"])
|
|
2886
|
+
});
|
|
2887
|
+
var TriggerInstanceManageUpdateResponseSchema = z5.object({
|
|
2888
|
+
status: z5.enum(["success"])
|
|
2889
|
+
});
|
|
2890
|
+
var TriggerInstanceManageDeleteResponseSchema = z5.object({
|
|
2891
|
+
triggerId: z5.string()
|
|
2892
|
+
});
|
|
2893
|
+
var IncomingTriggerPayloadSchema = z5.object({
|
|
2894
|
+
id: z5.string().describe("The ID of the trigger"),
|
|
2895
|
+
triggerSlug: z5.string().describe("The slug of the trigger that triggered the event"),
|
|
2896
|
+
toolkitSlug: z5.string().describe("The slug of the toolkit that triggered the event"),
|
|
2897
|
+
userId: z5.string().describe("The ID of the user that triggered the event"),
|
|
2898
|
+
payload: z5.record(z5.unknown()).describe("The payload of the trigger").optional(),
|
|
2899
|
+
originalPayload: z5.record(z5.unknown()).describe("The original payload of the trigger").optional(),
|
|
2900
|
+
metadata: z5.object({
|
|
2901
|
+
id: z5.string(),
|
|
2902
|
+
toolkitSlug: z5.string(),
|
|
2903
|
+
triggerSlug: z5.string(),
|
|
2904
|
+
triggerData: z5.string().optional(),
|
|
2905
|
+
triggerConfig: z5.record(z5.unknown()),
|
|
2906
|
+
connectedAccount: z5.object({
|
|
2907
|
+
id: z5.string(),
|
|
2908
|
+
uuid: z5.string(),
|
|
2909
|
+
authConfigId: z5.string(),
|
|
2910
|
+
authConfigUUID: z5.string(),
|
|
2911
|
+
userId: z5.string(),
|
|
2912
|
+
status: z5.enum(["ACTIVE", "INACTIVE"])
|
|
2913
|
+
})
|
|
2914
|
+
})
|
|
2915
|
+
});
|
|
2916
|
+
|
|
2917
|
+
// src/services/internal/InternalService.types.ts
|
|
2918
|
+
import { z as z6 } from "zod";
|
|
2919
|
+
var SDKRealtimeCredentialsResponseSchema = z6.object({
|
|
2920
|
+
projectId: z6.string().describe("The project ID"),
|
|
2921
|
+
pusherKey: z6.string().describe("The Pusher key"),
|
|
2922
|
+
pusherCluster: z6.string().describe("The Pusher cluster")
|
|
2923
|
+
});
|
|
2924
|
+
|
|
2925
|
+
// src/services/internal/InternalService.ts
|
|
2926
|
+
var SDK_REALTIME_CREDENTIALS_ENDPOINT = "/api/v3/internal/sdk/realtime/credentials";
|
|
2927
|
+
var InternalService = class {
|
|
2928
|
+
constructor(client) {
|
|
2929
|
+
this.client = client;
|
|
2930
|
+
this.client = client;
|
|
2791
2931
|
}
|
|
2792
2932
|
/**
|
|
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.
|
|
2933
|
+
* Get the SDK realtime credentials
|
|
2934
|
+
* @returns {SDKRealtimeCredentialsResponse} The SDK realtime credentials
|
|
2798
2935
|
*/
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2936
|
+
async getSDKRealtimeCredentials() {
|
|
2937
|
+
const response = await this.client.request({
|
|
2938
|
+
method: "get",
|
|
2939
|
+
path: SDK_REALTIME_CREDENTIALS_ENDPOINT
|
|
2940
|
+
});
|
|
2941
|
+
const parsedResponse = SDKRealtimeCredentialsResponseSchema.safeParse({
|
|
2942
|
+
pusherKey: response.pusher_key,
|
|
2943
|
+
projectId: response.project_id,
|
|
2944
|
+
pusherCluster: response.pusher_cluster
|
|
2945
|
+
});
|
|
2946
|
+
logger_default.debug(
|
|
2947
|
+
`[InternalService] SDK realtime credentials: ${JSON.stringify(parsedResponse, null, 2)}`
|
|
2948
|
+
);
|
|
2949
|
+
if (!parsedResponse.success) {
|
|
2950
|
+
throw new ValidationError(`Failed to parse SDK realtime credentials`, {
|
|
2951
|
+
cause: parsedResponse.error
|
|
2952
|
+
});
|
|
2806
2953
|
}
|
|
2954
|
+
return parsedResponse.data;
|
|
2807
2955
|
}
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2956
|
+
};
|
|
2957
|
+
|
|
2958
|
+
// src/errors/TriggerErrors.ts
|
|
2959
|
+
import { ComposioError as ComposioError2 } from "@composio/client";
|
|
2960
|
+
var TriggerErrorCodes = {
|
|
2961
|
+
TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS: "TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS",
|
|
2962
|
+
TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT: "TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT",
|
|
2963
|
+
TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL",
|
|
2964
|
+
TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL"
|
|
2965
|
+
};
|
|
2966
|
+
var ComposioFailedToGetSDKRealtimeCredentialsError = class extends ComposioError2 {
|
|
2967
|
+
name = "ComposioFailedToGetSDKRealtimeCredentialsError";
|
|
2968
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS;
|
|
2969
|
+
statusCode = 500;
|
|
2970
|
+
possibleFixes = ["Please contact support."];
|
|
2971
|
+
constructor(message, options) {
|
|
2972
|
+
super(message, options);
|
|
2973
|
+
}
|
|
2974
|
+
};
|
|
2975
|
+
var ComposioFailedToCreatePusherClientError = class extends ComposioError2 {
|
|
2976
|
+
name = "ComposioFailedToCreatePusherClientError";
|
|
2977
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT;
|
|
2978
|
+
statusCode = 500;
|
|
2979
|
+
possibleFixes = ["Please contact support."];
|
|
2980
|
+
constructor(message, options) {
|
|
2981
|
+
super(message, options);
|
|
2982
|
+
}
|
|
2983
|
+
};
|
|
2984
|
+
var ComposioFailedToSubscribeToPusherChannelError = class extends ComposioError2 {
|
|
2985
|
+
name = "ComposioFailedToSubscribeToPusherChannelError";
|
|
2986
|
+
code = TriggerErrorCodes.TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL;
|
|
2987
|
+
statusCode = 500;
|
|
2988
|
+
possibleFixes = ["Please contact support."];
|
|
2989
|
+
constructor(message, options) {
|
|
2990
|
+
super(message, options);
|
|
2991
|
+
}
|
|
2992
|
+
};
|
|
2993
|
+
|
|
2994
|
+
// src/services/pusher/Pusher.ts
|
|
2995
|
+
var PusherService = class {
|
|
2996
|
+
// these values are set via the Apollo API `/internal/sdk/realtime/credentials` endpoint
|
|
2997
|
+
clientId;
|
|
2998
|
+
pusherKey;
|
|
2999
|
+
pusherCluster;
|
|
3000
|
+
pusherChannel;
|
|
3001
|
+
// these details are set via the client SDK
|
|
3002
|
+
pusherBaseURL;
|
|
3003
|
+
apiKey;
|
|
3004
|
+
pusherClient;
|
|
3005
|
+
composioClient;
|
|
3006
|
+
constructor(client) {
|
|
3007
|
+
this.composioClient = client;
|
|
3008
|
+
this.pusherBaseURL = client.baseURL;
|
|
3009
|
+
this.apiKey = client.apiKey ?? process.env.COMPOSIO_API_KEY ?? "";
|
|
3010
|
+
telemetry.instrument(this);
|
|
2815
3011
|
}
|
|
2816
3012
|
/**
|
|
2817
|
-
*
|
|
2818
|
-
*
|
|
2819
|
-
*
|
|
2820
|
-
*
|
|
3013
|
+
* Creates a Pusher client
|
|
3014
|
+
*
|
|
3015
|
+
* This method is called when the Pusher client is first used.
|
|
3016
|
+
* It will fetch the SDK realtime credentials from the Apollo API and create a Pusher client.
|
|
2821
3017
|
*/
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
3018
|
+
async getPusherClient() {
|
|
3019
|
+
if (!this.pusherClient) {
|
|
3020
|
+
const internalService = new InternalService(this.composioClient);
|
|
3021
|
+
let sdkRealtimeCredentials;
|
|
3022
|
+
try {
|
|
3023
|
+
sdkRealtimeCredentials = await internalService.getSDKRealtimeCredentials();
|
|
3024
|
+
} catch (error) {
|
|
3025
|
+
throw new ComposioFailedToGetSDKRealtimeCredentialsError(
|
|
3026
|
+
"Failed to get SDK realtime credentials",
|
|
3027
|
+
{
|
|
3028
|
+
cause: error
|
|
3029
|
+
}
|
|
3030
|
+
);
|
|
2829
3031
|
}
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
3032
|
+
this.clientId = sdkRealtimeCredentials.projectId;
|
|
3033
|
+
this.pusherKey = sdkRealtimeCredentials.pusherKey;
|
|
3034
|
+
this.pusherCluster = sdkRealtimeCredentials.pusherCluster;
|
|
3035
|
+
this.pusherChannel = `private-${this.clientId}_triggers`;
|
|
3036
|
+
logger_default.debug(
|
|
3037
|
+
`[PusherService] Creating Pusher client for client ID: ${this.clientId} in cluster ${this.pusherCluster}`
|
|
3038
|
+
);
|
|
3039
|
+
try {
|
|
3040
|
+
const { default: Pusher } = await import("pusher-js");
|
|
3041
|
+
this.pusherClient = new Pusher(this.pusherKey, {
|
|
3042
|
+
cluster: this.pusherCluster,
|
|
3043
|
+
channelAuthorization: {
|
|
3044
|
+
endpoint: `${this.pusherBaseURL}/api/v3/internal/sdk/realtime/auth`,
|
|
3045
|
+
headers: {
|
|
3046
|
+
"x-api-key": this.apiKey
|
|
3047
|
+
},
|
|
3048
|
+
transport: "ajax"
|
|
3049
|
+
}
|
|
3050
|
+
});
|
|
3051
|
+
} catch (error) {
|
|
3052
|
+
throw new ComposioFailedToCreatePusherClientError("Failed to create Pusher client", {
|
|
3053
|
+
cause: error
|
|
3054
|
+
});
|
|
2836
3055
|
}
|
|
2837
|
-
}
|
|
3056
|
+
}
|
|
3057
|
+
return this.pusherClient;
|
|
2838
3058
|
}
|
|
2839
3059
|
/**
|
|
2840
|
-
*
|
|
2841
|
-
*
|
|
2842
|
-
*
|
|
3060
|
+
* Binds a chunked event to a Pusher client
|
|
3061
|
+
*
|
|
3062
|
+
*
|
|
3063
|
+
* @param channel - The Pusher client to bind the event to
|
|
3064
|
+
* @param event - The event to bind to
|
|
3065
|
+
* @param callback - The function to call when the event is received
|
|
2843
3066
|
*/
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
3067
|
+
bindWithChunking(channel, event, callback) {
|
|
3068
|
+
try {
|
|
3069
|
+
channel.bind(event, callback);
|
|
3070
|
+
const events = {};
|
|
3071
|
+
channel.bind("chunked-" + event, (data) => {
|
|
3072
|
+
try {
|
|
3073
|
+
const typedData = data;
|
|
3074
|
+
if (!typedData || typeof typedData.id !== "string" || typeof typedData.index !== "number") {
|
|
3075
|
+
throw new Error("Invalid chunked trigger data format");
|
|
3076
|
+
}
|
|
3077
|
+
if (!events.hasOwnProperty(typedData.id)) {
|
|
3078
|
+
events[typedData.id] = { chunks: [], receivedFinal: false };
|
|
3079
|
+
}
|
|
3080
|
+
const ev = events[typedData.id];
|
|
3081
|
+
ev.chunks[typedData.index] = typedData.chunk;
|
|
3082
|
+
if (typedData.final) ev.receivedFinal = true;
|
|
3083
|
+
if (ev.receivedFinal && ev.chunks.length === Object.keys(ev.chunks).length) {
|
|
3084
|
+
try {
|
|
3085
|
+
const parsedData = JSON.parse(ev.chunks.join(""));
|
|
3086
|
+
callback(parsedData);
|
|
3087
|
+
} catch (parseError) {
|
|
3088
|
+
const errorMessage = parseError instanceof Error ? parseError.message : String(parseError);
|
|
3089
|
+
logger_default.error("Failed to parse chunked data:", errorMessage);
|
|
3090
|
+
} finally {
|
|
3091
|
+
delete events[typedData.id];
|
|
3092
|
+
}
|
|
3093
|
+
}
|
|
3094
|
+
} catch (error) {
|
|
3095
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3096
|
+
logger_default.error("Error processing chunked trigger data:", errorMessage);
|
|
3097
|
+
if (data && typeof data === "object" && "id" in data) {
|
|
3098
|
+
delete events[data.id];
|
|
3099
|
+
}
|
|
3100
|
+
}
|
|
3101
|
+
});
|
|
3102
|
+
} catch (error) {
|
|
3103
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3104
|
+
logger_default.error("Failed to bind chunked events:", error);
|
|
3105
|
+
throw new Error(`Failed to bind chunked events: ${errorMessage}`);
|
|
3106
|
+
}
|
|
2859
3107
|
}
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
3108
|
+
/**
|
|
3109
|
+
* Subscribes to pusher to receive events from the server
|
|
3110
|
+
*
|
|
3111
|
+
* This method is used to subscribe to a Pusher channel.
|
|
3112
|
+
* It will create a Pusher client if it doesn't exist.
|
|
3113
|
+
*
|
|
3114
|
+
* @param channelName - The name of the Pusher channel to subscribe to
|
|
3115
|
+
* @param event - The event to subscribe to
|
|
3116
|
+
* @param fn - The function to call when the event is received
|
|
3117
|
+
*/
|
|
3118
|
+
async subscribe(fn) {
|
|
3119
|
+
try {
|
|
3120
|
+
logger_default.debug(`[PusherService] Subscribing to channel: ${this.pusherChannel}`);
|
|
3121
|
+
const pusherClient = await this.getPusherClient();
|
|
3122
|
+
const channel = await pusherClient.subscribe(this.pusherChannel);
|
|
3123
|
+
channel.bind("pusher:subscription_error", (data) => {
|
|
3124
|
+
const error = data.error ? String(data.error) : "Unknown subscription error";
|
|
3125
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3126
|
+
`Trigger subscription error: ${error}`,
|
|
3127
|
+
{
|
|
3128
|
+
cause: error
|
|
3129
|
+
}
|
|
3130
|
+
);
|
|
3131
|
+
});
|
|
3132
|
+
const safeCallback = (data) => {
|
|
3133
|
+
try {
|
|
3134
|
+
fn(data);
|
|
3135
|
+
} catch (error) {
|
|
3136
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3137
|
+
logger_default.error("\u274C Error in trigger callback:", errorMessage);
|
|
3138
|
+
}
|
|
3139
|
+
};
|
|
3140
|
+
this.bindWithChunking(channel, "trigger_to_client", safeCallback);
|
|
3141
|
+
logger_default.info(`\u2705 Subscribed to triggers. You should start receiving events now.`);
|
|
3142
|
+
} catch (error) {
|
|
3143
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3144
|
+
"Failed to subscribe to Pusher channel",
|
|
3145
|
+
{
|
|
3146
|
+
cause: error
|
|
3147
|
+
}
|
|
3148
|
+
);
|
|
3149
|
+
}
|
|
2868
3150
|
}
|
|
2869
3151
|
/**
|
|
2870
|
-
*
|
|
2871
|
-
*
|
|
3152
|
+
* Unsubscribes from a Pusher channel
|
|
3153
|
+
*
|
|
3154
|
+
* This method is used to unsubscribe from a Pusher channel.
|
|
3155
|
+
* It will create a Pusher client if it doesn't exist.
|
|
3156
|
+
*
|
|
3157
|
+
* @param channelName - The name of the Pusher channel to unsubscribe from
|
|
2872
3158
|
*/
|
|
2873
|
-
async
|
|
2874
|
-
|
|
3159
|
+
async unsubscribe() {
|
|
3160
|
+
try {
|
|
3161
|
+
logger_default.debug(`[PusherService] Unsubscribing from channel: ${this.pusherChannel}`);
|
|
3162
|
+
const pusherClient = await this.getPusherClient();
|
|
3163
|
+
await pusherClient.unsubscribe(this.pusherChannel);
|
|
3164
|
+
logger_default.info(`\u2705 Unsubscribed from triggers.`);
|
|
3165
|
+
} catch (error) {
|
|
3166
|
+
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
3167
|
+
"Failed to unsubscribe from Pusher channel",
|
|
3168
|
+
{
|
|
3169
|
+
cause: error
|
|
3170
|
+
}
|
|
3171
|
+
);
|
|
3172
|
+
}
|
|
2875
3173
|
}
|
|
2876
3174
|
};
|
|
2877
3175
|
|
|
2878
3176
|
// src/models/Triggers.ts
|
|
2879
3177
|
var Triggers = class {
|
|
2880
3178
|
client;
|
|
3179
|
+
pusherService;
|
|
2881
3180
|
constructor(client) {
|
|
2882
3181
|
this.client = client;
|
|
3182
|
+
this.pusherService = new PusherService(client);
|
|
2883
3183
|
telemetry.instrument(this);
|
|
2884
3184
|
}
|
|
3185
|
+
/**
|
|
3186
|
+
* Parse the trigger instance list active item
|
|
3187
|
+
*
|
|
3188
|
+
* @param response - The response from the composio client
|
|
3189
|
+
* @returns The parsed trigger instance list active item
|
|
3190
|
+
*/
|
|
3191
|
+
parseTriggerInstanceListActiveItem(response) {
|
|
3192
|
+
const parsed = TriggerInstanceListActiveResponseItemSchema.safeParse({
|
|
3193
|
+
id: response.id,
|
|
3194
|
+
connectedAccountId: response.connected_account_id,
|
|
3195
|
+
disabledAt: response.disabled_at,
|
|
3196
|
+
state: response.state,
|
|
3197
|
+
triggerConfig: response.trigger_config,
|
|
3198
|
+
triggerName: response.trigger_name,
|
|
3199
|
+
updatedAt: response.updated_at,
|
|
3200
|
+
triggerData: response.trigger_data,
|
|
3201
|
+
uuid: response.uuid
|
|
3202
|
+
});
|
|
3203
|
+
if (!parsed.success) {
|
|
3204
|
+
throw new ValidationError(`Invalid trigger instance list active item`, {
|
|
3205
|
+
cause: parsed.error
|
|
3206
|
+
});
|
|
3207
|
+
}
|
|
3208
|
+
return parsed.data;
|
|
3209
|
+
}
|
|
2885
3210
|
/**
|
|
2886
3211
|
* Fetch list of all the active triggers
|
|
2887
|
-
*
|
|
3212
|
+
*
|
|
3213
|
+
* @param {TriggerInstanceListActiveParams} query - The query parameters to filter the trigger instances
|
|
3214
|
+
* @returns {Promise<TriggerInstanceListActiveResponse>} List of trigger instances
|
|
3215
|
+
*
|
|
3216
|
+
* @throws {ValidationError} If the parameters are invalid
|
|
3217
|
+
* @throws {Error} If the client is not authenticated
|
|
3218
|
+
*
|
|
3219
|
+
* @example
|
|
3220
|
+
* ```ts
|
|
3221
|
+
* const triggers = await triggers.listActive({
|
|
3222
|
+
* authConfigIds: ['123'],
|
|
3223
|
+
* connectedAccountIds: ['456'],
|
|
3224
|
+
* });
|
|
3225
|
+
* ```
|
|
2888
3226
|
*/
|
|
2889
|
-
async
|
|
2890
|
-
|
|
3227
|
+
async listActive(query) {
|
|
3228
|
+
const parsedParams = TriggerInstanceListActiveParamsSchema.safeParse(query ?? {});
|
|
3229
|
+
if (!parsedParams.success) {
|
|
3230
|
+
throw new ValidationError(`Invalid parameters passed to list triggers`, {
|
|
3231
|
+
cause: parsedParams.error
|
|
3232
|
+
});
|
|
3233
|
+
}
|
|
3234
|
+
const result = await this.client.triggerInstances.listActive(
|
|
3235
|
+
query ? {
|
|
3236
|
+
auth_config_ids: parsedParams.data.authConfigIds,
|
|
3237
|
+
connected_account_ids: parsedParams.data.connectedAccountIds,
|
|
3238
|
+
limit: parsedParams.data.limit,
|
|
3239
|
+
page: parsedParams.data.page,
|
|
3240
|
+
show_disabled: parsedParams.data.showDisabled,
|
|
3241
|
+
trigger_ids: parsedParams.data.triggerIds,
|
|
3242
|
+
trigger_names: parsedParams.data.triggerNames
|
|
3243
|
+
} : void 0
|
|
3244
|
+
);
|
|
3245
|
+
const parsedResult = TriggerInstanceListActiveResponseSchema.safeParse({
|
|
3246
|
+
items: result.items.map((item) => this.parseTriggerInstanceListActiveItem(item)),
|
|
3247
|
+
nextCursor: result.next_cursor,
|
|
3248
|
+
totalPages: result.total_pages
|
|
3249
|
+
});
|
|
3250
|
+
if (!parsedResult.success) {
|
|
3251
|
+
throw new ValidationError(`Invalid trigger instance list active response`, {
|
|
3252
|
+
cause: parsedResult.error
|
|
3253
|
+
});
|
|
3254
|
+
}
|
|
3255
|
+
return parsedResult.data;
|
|
2891
3256
|
}
|
|
2892
3257
|
/**
|
|
2893
3258
|
* Create a new trigger instance
|
|
@@ -2896,58 +3261,76 @@ var Triggers = class {
|
|
|
2896
3261
|
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
2897
3262
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
2898
3263
|
*/
|
|
2899
|
-
async create(slug, body
|
|
2900
|
-
|
|
3264
|
+
async create(slug, body) {
|
|
3265
|
+
const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body);
|
|
3266
|
+
if (!parsedBody.success) {
|
|
3267
|
+
throw new ValidationError(`Invalid parameters passed to create trigger`, {
|
|
3268
|
+
cause: parsedBody.error
|
|
3269
|
+
});
|
|
3270
|
+
}
|
|
3271
|
+
const result = await this.client.triggerInstances.upsert(slug, {
|
|
3272
|
+
connected_account_id: parsedBody.data.connectedAccountId,
|
|
3273
|
+
trigger_config: parsedBody.data.triggerConfig
|
|
3274
|
+
});
|
|
3275
|
+
const parsedResult = TriggerInstanceUpsertResponseSchema.safeParse({
|
|
3276
|
+
triggerId: result.trigger_id
|
|
3277
|
+
});
|
|
3278
|
+
if (!parsedResult.success) {
|
|
3279
|
+
throw new ValidationError(`Invalid trigger instance upsert response`, {
|
|
3280
|
+
cause: parsedResult.error
|
|
3281
|
+
});
|
|
3282
|
+
}
|
|
3283
|
+
return parsedResult.data;
|
|
2901
3284
|
}
|
|
2902
3285
|
/**
|
|
2903
3286
|
* Update an existing trigger instance
|
|
2904
3287
|
*
|
|
2905
3288
|
* @param {string} slug - The slug of the trigger instance
|
|
2906
|
-
* @param {
|
|
3289
|
+
* @param {TriggerInstanceManageUpdateParams} body - The parameters to create the trigger instance
|
|
2907
3290
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2908
3291
|
*/
|
|
2909
|
-
async update(slug, body
|
|
2910
|
-
return this.client.triggerInstances.
|
|
3292
|
+
async update(slug, body) {
|
|
3293
|
+
return this.client.triggerInstances.manage.update(slug, body);
|
|
2911
3294
|
}
|
|
2912
3295
|
/**
|
|
2913
3296
|
* Delete a trigger instance
|
|
2914
3297
|
*
|
|
2915
|
-
* @param {string}
|
|
3298
|
+
* @param {string} triggerId - The slug of the trigger instance
|
|
2916
3299
|
* @returns
|
|
2917
3300
|
*/
|
|
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);
|
|
3301
|
+
async delete(triggerId) {
|
|
3302
|
+
const result = await this.client.triggerInstances.manage.delete(triggerId);
|
|
3303
|
+
const parsedResult = TriggerInstanceManageDeleteResponseSchema.safeParse({
|
|
3304
|
+
triggerId: result.trigger_id
|
|
3305
|
+
});
|
|
3306
|
+
if (!parsedResult.success) {
|
|
3307
|
+
throw new ValidationError(`Invalid trigger instance manage delete response`, {
|
|
3308
|
+
cause: parsedResult.error
|
|
3309
|
+
});
|
|
3310
|
+
}
|
|
3311
|
+
return parsedResult.data;
|
|
2931
3312
|
}
|
|
2932
3313
|
/**
|
|
2933
3314
|
* Disable a trigger instance
|
|
2934
3315
|
*
|
|
2935
|
-
* @param {string}
|
|
2936
|
-
* @param {RequestOptions options - Request options
|
|
3316
|
+
* @param {string} triggerId - The id of the trigger instance
|
|
2937
3317
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2938
3318
|
*/
|
|
2939
|
-
async disable(
|
|
2940
|
-
return this.client.triggerInstances.
|
|
3319
|
+
async disable(triggerId) {
|
|
3320
|
+
return this.client.triggerInstances.manage.update(triggerId, {
|
|
3321
|
+
status: "disable"
|
|
3322
|
+
});
|
|
2941
3323
|
}
|
|
2942
3324
|
/**
|
|
2943
3325
|
* Enable a trigger instance
|
|
2944
3326
|
*
|
|
2945
|
-
* @param {string}
|
|
2946
|
-
* @param {RequestOptions options - Request options
|
|
3327
|
+
* @param {string} triggerId - The id of the trigger instance
|
|
2947
3328
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The updated trigger instance
|
|
2948
3329
|
*/
|
|
2949
|
-
async enable(
|
|
2950
|
-
return this.client.triggerInstances.
|
|
3330
|
+
async enable(triggerId) {
|
|
3331
|
+
return this.client.triggerInstances.manage.update(triggerId, {
|
|
3332
|
+
status: "enable"
|
|
3333
|
+
});
|
|
2951
3334
|
}
|
|
2952
3335
|
/**
|
|
2953
3336
|
* @TODO Learn about trigger types
|
|
@@ -2959,8 +3342,8 @@ var Triggers = class {
|
|
|
2959
3342
|
* @param {RequestOptions} options - Request options
|
|
2960
3343
|
* @returns {Promise<TriggersTypeListResponse>} The list of trigger types
|
|
2961
3344
|
*/
|
|
2962
|
-
async listTypes(query
|
|
2963
|
-
return this.client.triggersTypes.list(query
|
|
3345
|
+
async listTypes(query) {
|
|
3346
|
+
return this.client.triggersTypes.list(query);
|
|
2964
3347
|
}
|
|
2965
3348
|
/**
|
|
2966
3349
|
* Retrieve a trigger type by its slug
|
|
@@ -2969,8 +3352,8 @@ var Triggers = class {
|
|
|
2969
3352
|
* @param {RequestOptions} options - request options
|
|
2970
3353
|
* @returns {Promise<TriggersTypeRetrieveResponse>} The trigger type object
|
|
2971
3354
|
*/
|
|
2972
|
-
async getType(slug
|
|
2973
|
-
return this.client.triggersTypes.retrieve(slug
|
|
3355
|
+
async getType(slug) {
|
|
3356
|
+
return this.client.triggersTypes.retrieve(slug);
|
|
2974
3357
|
}
|
|
2975
3358
|
/**
|
|
2976
3359
|
* Fetches the list of all the available trigger enums
|
|
@@ -2979,36 +3362,137 @@ var Triggers = class {
|
|
|
2979
3362
|
* @param options
|
|
2980
3363
|
* @returns
|
|
2981
3364
|
*/
|
|
2982
|
-
async listEnum(
|
|
2983
|
-
return this.client.triggersTypes.retrieveEnum(
|
|
3365
|
+
async listEnum() {
|
|
3366
|
+
return this.client.triggersTypes.retrieveEnum();
|
|
2984
3367
|
}
|
|
3368
|
+
/**
|
|
3369
|
+
* Subscribe to all the triggers
|
|
3370
|
+
*
|
|
3371
|
+
* @param fn - The function to call when a trigger is received
|
|
3372
|
+
* @param filters - The filters to apply to the triggers
|
|
3373
|
+
*
|
|
3374
|
+
* @example
|
|
3375
|
+
* ```ts
|
|
3376
|
+
*
|
|
3377
|
+
* triggers.subscribe((data) => {
|
|
3378
|
+
* console.log(data);
|
|
3379
|
+
* }, );
|
|
3380
|
+
* ```
|
|
3381
|
+
*/
|
|
2985
3382
|
async subscribe(fn, filters = {}) {
|
|
2986
3383
|
if (!fn) throw new Error("Function is required for trigger subscription");
|
|
2987
|
-
const
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
const
|
|
2994
|
-
if (
|
|
2995
|
-
|
|
2996
|
-
|
|
3384
|
+
const parsedFilters = TriggerSubscribeParamSchema.safeParse(filters);
|
|
3385
|
+
if (!parsedFilters.success) {
|
|
3386
|
+
throw new ValidationError(`Invalid parameters passed to subscribe to triggers`, {
|
|
3387
|
+
cause: parsedFilters.error
|
|
3388
|
+
});
|
|
3389
|
+
}
|
|
3390
|
+
const shouldSendTriggerAfterFilters = (data) => {
|
|
3391
|
+
if (parsedFilters.data.toolkits?.length && !parsedFilters.data.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
|
|
3392
|
+
logger_default.debug(
|
|
3393
|
+
"Trigger does not match toolkits filter",
|
|
3394
|
+
JSON.stringify(parsedFilters.data.toolkits, null, 2)
|
|
3395
|
+
);
|
|
3396
|
+
return false;
|
|
3397
|
+
}
|
|
3398
|
+
if (parsedFilters.data.triggerId && parsedFilters.data.triggerId !== data.id) {
|
|
3399
|
+
logger_default.debug(
|
|
3400
|
+
"Trigger does not match triggerId filter",
|
|
3401
|
+
JSON.stringify(parsedFilters.data.triggerId, null, 2)
|
|
3402
|
+
);
|
|
3403
|
+
return false;
|
|
3404
|
+
}
|
|
3405
|
+
if (parsedFilters.data.connectedAccountId && parsedFilters.data.connectedAccountId !== data.metadata.connectedAccount.id) {
|
|
3406
|
+
logger_default.debug(
|
|
3407
|
+
"Trigger does not match connectedAccountId filter",
|
|
3408
|
+
JSON.stringify(parsedFilters.data.connectedAccountId, null, 2)
|
|
3409
|
+
);
|
|
3410
|
+
return false;
|
|
3411
|
+
}
|
|
3412
|
+
if (parsedFilters.data.triggerSlug?.length && !parsedFilters.data.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
|
|
3413
|
+
logger_default.debug(
|
|
3414
|
+
"Trigger does not match triggerSlug filter",
|
|
3415
|
+
JSON.stringify(parsedFilters.data.triggerSlug, null, 2)
|
|
3416
|
+
);
|
|
3417
|
+
return false;
|
|
3418
|
+
}
|
|
3419
|
+
if (parsedFilters.data.triggerData && parsedFilters.data.triggerData !== data.metadata.triggerData) {
|
|
3420
|
+
logger_default.debug(
|
|
3421
|
+
"Trigger does not match triggerData filter",
|
|
3422
|
+
JSON.stringify(parsedFilters.data.triggerData, null, 2)
|
|
3423
|
+
);
|
|
3424
|
+
return false;
|
|
2997
3425
|
}
|
|
3426
|
+
if (parsedFilters.data.userId && parsedFilters.data.userId !== data.metadata.connectedAccount.userId) {
|
|
3427
|
+
logger_default.debug(
|
|
3428
|
+
"Trigger does not match userId filter",
|
|
3429
|
+
JSON.stringify(parsedFilters.data.userId, null, 2)
|
|
3430
|
+
);
|
|
3431
|
+
return false;
|
|
3432
|
+
}
|
|
3433
|
+
logger_default.debug("Trigger matches all filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
3434
|
+
return true;
|
|
2998
3435
|
};
|
|
2999
|
-
logger_default.debug("Subscribing to triggers", filters);
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3436
|
+
logger_default.debug("\u{1F504} Subscribing to triggers with filters: ", JSON.stringify(filters, null, 2));
|
|
3437
|
+
await this.pusherService.subscribe((_data) => {
|
|
3438
|
+
logger_default.debug("Received raw trigger data", JSON.stringify(_data, null, 2));
|
|
3439
|
+
const data = _data;
|
|
3440
|
+
const parsedData = IncomingTriggerPayloadSchema.safeParse({
|
|
3441
|
+
id: data.metadata.id,
|
|
3442
|
+
triggerSlug: data.metadata.triggerName,
|
|
3443
|
+
toolkitSlug: data.appName,
|
|
3444
|
+
userId: data.metadata.connection?.clientUniqueUserId,
|
|
3445
|
+
payload: data.payload,
|
|
3446
|
+
originalPayload: data.originalPayload,
|
|
3447
|
+
metadata: {
|
|
3448
|
+
id: data.metadata.id,
|
|
3449
|
+
triggerConfig: data.metadata.triggerConfig,
|
|
3450
|
+
triggerSlug: data.metadata.triggerName,
|
|
3451
|
+
toolkitSlug: data.appName,
|
|
3452
|
+
triggerData: data.metadata.triggerData,
|
|
3453
|
+
connectedAccount: {
|
|
3454
|
+
id: data.metadata.connection?.connectedAccountNanoId,
|
|
3455
|
+
uuid: data.metadata.connection?.id,
|
|
3456
|
+
authConfigId: data.metadata.connection?.authConfigNanoId,
|
|
3457
|
+
authConfigUUID: data.metadata.connection?.integrationId,
|
|
3458
|
+
userId: data.metadata.connection?.clientUniqueUserId,
|
|
3459
|
+
status: data.metadata.connection?.status
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
});
|
|
3463
|
+
logger_default.debug("Parsed trigger data", JSON.stringify(parsedData.data, null, 2));
|
|
3464
|
+
if (parsedData.error) {
|
|
3465
|
+
throw new ValidationError(`Invalid trigger payload`, {
|
|
3466
|
+
cause: parsedData.error
|
|
3467
|
+
});
|
|
3468
|
+
}
|
|
3469
|
+
if (shouldSendTriggerAfterFilters(parsedData.data)) {
|
|
3470
|
+
try {
|
|
3471
|
+
fn(parsedData.data);
|
|
3472
|
+
} catch (error) {
|
|
3473
|
+
logger_default.error("\u274C Error in trigger callback:", error);
|
|
3474
|
+
}
|
|
3475
|
+
} else {
|
|
3476
|
+
logger_default.debug("Trigger does not match filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
3003
3477
|
}
|
|
3004
3478
|
});
|
|
3005
3479
|
}
|
|
3480
|
+
/**
|
|
3481
|
+
* Unsubscribe from all the triggers
|
|
3482
|
+
*
|
|
3483
|
+
* @returns {Promise<void>}
|
|
3484
|
+
*
|
|
3485
|
+
* @example
|
|
3486
|
+
* ```ts
|
|
3487
|
+
* composio.trigger.subscribe((data) => {
|
|
3488
|
+
* console.log(data);
|
|
3489
|
+
* });
|
|
3490
|
+
*
|
|
3491
|
+
* await triggers.unsubscribe();
|
|
3492
|
+
* ```
|
|
3493
|
+
*/
|
|
3006
3494
|
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);
|
|
3495
|
+
await this.pusherService.unsubscribe();
|
|
3012
3496
|
}
|
|
3013
3497
|
};
|
|
3014
3498
|
|
|
@@ -3091,7 +3575,7 @@ var BaseProvider = class {
|
|
|
3091
3575
|
}
|
|
3092
3576
|
/**
|
|
3093
3577
|
* @public
|
|
3094
|
-
*
|
|
3578
|
+
* Global function to execute a tool.
|
|
3095
3579
|
* This function is used by provider providers to implement helper functions to execute tools.
|
|
3096
3580
|
* This is a 1:1 mapping of the `execute` method in the `Tools` class.
|
|
3097
3581
|
* @param {string} toolSlug - The slug of the tool to execute.
|
|
@@ -3158,7 +3642,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3158
3642
|
* @param {string} userId - The user id.
|
|
3159
3643
|
* @returns {Promise<string[]>} The results of the tool call.
|
|
3160
3644
|
*/
|
|
3161
|
-
async
|
|
3645
|
+
async handleToolCalls(userId, chatCompletion, options, modifiers) {
|
|
3162
3646
|
const outputs = [];
|
|
3163
3647
|
for (const message of chatCompletion.choices) {
|
|
3164
3648
|
if (message.message.tool_calls) {
|
|
@@ -3278,7 +3762,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3278
3762
|
};
|
|
3279
3763
|
|
|
3280
3764
|
// package.json
|
|
3281
|
-
var version = "0.1.12-alpha.
|
|
3765
|
+
var version = "0.1.12-alpha.12";
|
|
3282
3766
|
|
|
3283
3767
|
// src/composio.ts
|
|
3284
3768
|
var Composio = class {
|
|
@@ -3340,7 +3824,7 @@ var Composio = class {
|
|
|
3340
3824
|
{
|
|
3341
3825
|
apiKey: apiKeyParsed ?? "",
|
|
3342
3826
|
baseUrl: baseURLParsed ?? "",
|
|
3343
|
-
frameworkRuntime: this.provider?.name
|
|
3827
|
+
frameworkRuntime: this.provider?.name ?? "unknown",
|
|
3344
3828
|
isAgentic: this.provider?._isAgentic || false,
|
|
3345
3829
|
source: "javascript",
|
|
3346
3830
|
version,
|
|
@@ -3393,39 +3877,39 @@ var ConsoleTelemetryTransport = class {
|
|
|
3393
3877
|
};
|
|
3394
3878
|
|
|
3395
3879
|
// src/utils/jsonSchema.ts
|
|
3396
|
-
import { z as
|
|
3880
|
+
import { z as z7 } from "zod";
|
|
3397
3881
|
function jsonSchemaPropertiesToTSTypes(value) {
|
|
3398
3882
|
if (!value.type) {
|
|
3399
|
-
return
|
|
3883
|
+
return z7.object({});
|
|
3400
3884
|
}
|
|
3401
3885
|
let zodType;
|
|
3402
3886
|
switch (value.type) {
|
|
3403
3887
|
case "string":
|
|
3404
|
-
zodType =
|
|
3888
|
+
zodType = z7.string().describe(
|
|
3405
3889
|
(value.description || "") + (value.examples ? `
|
|
3406
3890
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3407
3891
|
);
|
|
3408
3892
|
break;
|
|
3409
3893
|
case "number":
|
|
3410
|
-
zodType =
|
|
3894
|
+
zodType = z7.number().describe(
|
|
3411
3895
|
(value.description || "") + (value.examples ? `
|
|
3412
3896
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3413
3897
|
);
|
|
3414
3898
|
break;
|
|
3415
3899
|
case "integer":
|
|
3416
|
-
zodType =
|
|
3900
|
+
zodType = z7.number().int().describe(
|
|
3417
3901
|
(value.description || "") + (value.examples ? `
|
|
3418
3902
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3419
3903
|
);
|
|
3420
3904
|
break;
|
|
3421
3905
|
case "boolean":
|
|
3422
|
-
zodType =
|
|
3906
|
+
zodType = z7.boolean().describe(
|
|
3423
3907
|
(value.description || "") + (value.examples ? `
|
|
3424
3908
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3425
3909
|
);
|
|
3426
3910
|
break;
|
|
3427
3911
|
case "array":
|
|
3428
|
-
zodType =
|
|
3912
|
+
zodType = z7.array(
|
|
3429
3913
|
jsonSchemaPropertiesToTSTypes(
|
|
3430
3914
|
value.items
|
|
3431
3915
|
)
|
|
@@ -3435,24 +3919,24 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3435
3919
|
);
|
|
3436
3920
|
break;
|
|
3437
3921
|
case "object":
|
|
3438
|
-
zodType =
|
|
3922
|
+
zodType = jsonSchemaToZodSchema(value).describe(
|
|
3439
3923
|
(value.description || "") + (value.examples ? `
|
|
3440
3924
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3441
3925
|
);
|
|
3442
3926
|
break;
|
|
3443
3927
|
case "null":
|
|
3444
|
-
zodType =
|
|
3928
|
+
zodType = z7.null().describe(value.description || "");
|
|
3445
3929
|
break;
|
|
3446
3930
|
default:
|
|
3447
3931
|
throw new Error(`Unsupported JSON schema type: ${value.type}`);
|
|
3448
3932
|
}
|
|
3449
3933
|
return zodType;
|
|
3450
3934
|
}
|
|
3451
|
-
function
|
|
3935
|
+
function jsonSchemaToZodSchema(jsonSchema) {
|
|
3452
3936
|
const properties = jsonSchema.properties;
|
|
3453
3937
|
const requiredFields = jsonSchema.required || [];
|
|
3454
3938
|
if (!properties) {
|
|
3455
|
-
return
|
|
3939
|
+
return z7.object({});
|
|
3456
3940
|
}
|
|
3457
3941
|
const zodSchema = {};
|
|
3458
3942
|
for (const [key, _] of Object.entries(properties)) {
|
|
@@ -3464,7 +3948,7 @@ function jsonSchemaToModel(jsonSchema) {
|
|
|
3464
3948
|
schema
|
|
3465
3949
|
)
|
|
3466
3950
|
);
|
|
3467
|
-
zodType =
|
|
3951
|
+
zodType = z7.union(anyOfTypes).describe(
|
|
3468
3952
|
(value.description || "") + (value.examples ? `
|
|
3469
3953
|
Examples: ${value.examples.join(", ")}` : "")
|
|
3470
3954
|
);
|
|
@@ -3474,7 +3958,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3474
3958
|
schema
|
|
3475
3959
|
)
|
|
3476
3960
|
);
|
|
3477
|
-
zodType =
|
|
3961
|
+
zodType = z7.intersection(
|
|
3478
3962
|
allOfTypes[0],
|
|
3479
3963
|
allOfTypes.slice(1).reduce((acc, schema) => acc.and(schema), allOfTypes[0])
|
|
3480
3964
|
).describe(
|
|
@@ -3498,7 +3982,7 @@ Examples: ${value.examples.join(", ")}` : "")
|
|
|
3498
3982
|
zodSchema[key] = zodType.optional();
|
|
3499
3983
|
}
|
|
3500
3984
|
}
|
|
3501
|
-
return
|
|
3985
|
+
return z7.object(zodSchema);
|
|
3502
3986
|
}
|
|
3503
3987
|
export {
|
|
3504
3988
|
AuthConfigErrorCodes,
|
|
@@ -3534,5 +4018,6 @@ export {
|
|
|
3534
4018
|
ToolkitErrorCodes,
|
|
3535
4019
|
ValidationError,
|
|
3536
4020
|
ValidationErrorCodes,
|
|
3537
|
-
|
|
4021
|
+
jsonSchemaToZodSchema,
|
|
4022
|
+
logger_default as logger
|
|
3538
4023
|
};
|