@composio/core 0.1.21 → 0.1.23
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 +226 -111
- package/dist/index.d.cts +52 -22
- package/dist/index.d.ts +52 -22
- package/dist/index.js +223 -110
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -54,6 +54,7 @@ __export(index_exports, {
|
|
|
54
54
|
ComposioInvalidExecuteFunctionError: () => ComposioInvalidExecuteFunctionError,
|
|
55
55
|
ComposioInvalidModifierError: () => ComposioInvalidModifierError,
|
|
56
56
|
ComposioLinkConnectionDataSchema: () => ComposioLinkConnectionDataSchema,
|
|
57
|
+
ComposioMultipleConnectedAccountsError: () => ComposioMultipleConnectedAccountsError,
|
|
57
58
|
ComposioNoAPIKeyError: () => ComposioNoAPIKeyError,
|
|
58
59
|
ComposioProvider: () => ComposioProvider,
|
|
59
60
|
ComposioProviderNotDefinedError: () => ComposioProviderNotDefinedError,
|
|
@@ -127,12 +128,13 @@ __export(index_exports, {
|
|
|
127
128
|
ValidationError: () => ValidationError,
|
|
128
129
|
ValidationErrorCodes: () => ValidationErrorCodes,
|
|
129
130
|
jsonSchemaToZodSchema: () => jsonSchemaToZodSchema,
|
|
130
|
-
logger: () => logger_default
|
|
131
|
+
logger: () => logger_default,
|
|
132
|
+
removeNonRequiredProperties: () => removeNonRequiredProperties
|
|
131
133
|
});
|
|
132
134
|
module.exports = __toCommonJS(index_exports);
|
|
133
135
|
|
|
134
136
|
// src/composio.ts
|
|
135
|
-
var
|
|
137
|
+
var import_client7 = __toESM(require("@composio/client"), 1);
|
|
136
138
|
|
|
137
139
|
// src/types/tool.types.ts
|
|
138
140
|
var import_zod = require("zod");
|
|
@@ -234,19 +236,13 @@ var ToolListFilterByToolkitsSchema = import_zod.z.object({
|
|
|
234
236
|
important: import_zod.z.boolean().optional(),
|
|
235
237
|
cursor: import_zod.z.string().optional(),
|
|
236
238
|
limit: import_zod.z.number().optional(),
|
|
237
|
-
search: import_zod.z.string().optional()
|
|
238
|
-
strict: import_zod.z.boolean().optional().describe(
|
|
239
|
-
"If true, all the non-required fields will be removed from the input/output params of the tool"
|
|
240
|
-
)
|
|
239
|
+
search: import_zod.z.string().optional()
|
|
241
240
|
});
|
|
242
241
|
var ToolListFilterBySearchSchema = import_zod.z.object({
|
|
243
242
|
search: import_zod.z.string(),
|
|
244
243
|
toolkits: import_zod.z.array(import_zod.z.string()).optional(),
|
|
245
244
|
cursor: import_zod.z.string().optional(),
|
|
246
|
-
limit: import_zod.z.number().optional()
|
|
247
|
-
strict: import_zod.z.boolean().optional().describe(
|
|
248
|
-
"If true, all the non-required fields will be removed from the input/output params of the tool"
|
|
249
|
-
)
|
|
245
|
+
limit: import_zod.z.number().optional()
|
|
250
246
|
});
|
|
251
247
|
var ToolListParamsSchema = import_zod.z.union([
|
|
252
248
|
ToolListFilterByToolsSchema,
|
|
@@ -722,7 +718,8 @@ var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
|
|
|
722
718
|
|
|
723
719
|
// src/errors/ConnectedAccountsErrors.ts
|
|
724
720
|
var ConnectedAccountErrorCodes = {
|
|
725
|
-
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
|
|
721
|
+
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND",
|
|
722
|
+
MULTIPLE_CONNECTED_ACCOUNTS: "MULTIPLE_CONNECTED_ACCOUNTS"
|
|
726
723
|
};
|
|
727
724
|
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
728
725
|
constructor(message = "Connected account not found", options = {}) {
|
|
@@ -737,6 +734,17 @@ var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
|
737
734
|
this.name = "ComposioConnectedAccountNotFoundError";
|
|
738
735
|
}
|
|
739
736
|
};
|
|
737
|
+
var ComposioMultipleConnectedAccountsError = class extends ComposioError {
|
|
738
|
+
constructor(message = "Multiple connected accounts found") {
|
|
739
|
+
super(message, {
|
|
740
|
+
code: ConnectedAccountErrorCodes.MULTIPLE_CONNECTED_ACCOUNTS,
|
|
741
|
+
possibleFixes: [
|
|
742
|
+
"Use the allowMultiple flag to allow multiple connected accounts per user for an auth config"
|
|
743
|
+
]
|
|
744
|
+
});
|
|
745
|
+
this.name = "ComposioMultipleConnectedAccountsError";
|
|
746
|
+
}
|
|
747
|
+
};
|
|
740
748
|
|
|
741
749
|
// src/telemetry/Telemetry.ts
|
|
742
750
|
var import_client2 = require("@composio/client");
|
|
@@ -1229,6 +1237,7 @@ var AuthConfigRetrieveResponseSchema = import_zod4.z.object({
|
|
|
1229
1237
|
authScheme: AuthSchemeEnum.optional(),
|
|
1230
1238
|
credentials: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()).optional(),
|
|
1231
1239
|
expectedInputFields: import_zod4.z.array(import_zod4.z.unknown()).optional(),
|
|
1240
|
+
restrictToFollowingTools: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
1232
1241
|
isComposioManaged: import_zod4.z.boolean().optional(),
|
|
1233
1242
|
createdBy: import_zod4.z.string().optional(),
|
|
1234
1243
|
createdAt: import_zod4.z.string().optional(),
|
|
@@ -1660,7 +1669,8 @@ var ConnectedAccountStatuses = {
|
|
|
1660
1669
|
INITIATED: "INITIATED",
|
|
1661
1670
|
ACTIVE: "ACTIVE",
|
|
1662
1671
|
FAILED: "FAILED",
|
|
1663
|
-
EXPIRED: "EXPIRED"
|
|
1672
|
+
EXPIRED: "EXPIRED",
|
|
1673
|
+
INACTIVE: "INACTIVE"
|
|
1664
1674
|
};
|
|
1665
1675
|
var ConnectedAccountStatusSchema = import_zod6.z.enum([
|
|
1666
1676
|
ConnectedAccountStatuses.INITIALIZING,
|
|
@@ -1691,6 +1701,7 @@ var DefaultCreateConnectedAccountParamsSchema = import_zod6.z.object({
|
|
|
1691
1701
|
})
|
|
1692
1702
|
});
|
|
1693
1703
|
var CreateConnectedAccountOptionsSchema = import_zod6.z.object({
|
|
1704
|
+
allowMultiple: import_zod6.z.boolean().optional(),
|
|
1694
1705
|
callbackUrl: import_zod6.z.string().optional(),
|
|
1695
1706
|
config: ConnectionDataSchema.optional()
|
|
1696
1707
|
});
|
|
@@ -2047,37 +2058,6 @@ var CustomTools = class {
|
|
|
2047
2058
|
}
|
|
2048
2059
|
};
|
|
2049
2060
|
|
|
2050
|
-
// src/utils/jsonSchema.ts
|
|
2051
|
-
var import_json_schema_to_zod = require("@composio/json-schema-to-zod");
|
|
2052
|
-
var removeNonRequiredProperties = (schema) => {
|
|
2053
|
-
if (schema && schema.type === "object" && schema.required?.length) {
|
|
2054
|
-
schema.properties = Object.fromEntries(
|
|
2055
|
-
Object.entries(schema.properties || {}).filter(
|
|
2056
|
-
([key]) => schema.required.includes(key)
|
|
2057
|
-
)
|
|
2058
|
-
);
|
|
2059
|
-
}
|
|
2060
|
-
return schema;
|
|
2061
|
-
};
|
|
2062
|
-
function jsonSchemaToZodSchema(jsonSchema, { strict } = {
|
|
2063
|
-
strict: false
|
|
2064
|
-
}) {
|
|
2065
|
-
try {
|
|
2066
|
-
let schema = jsonSchema;
|
|
2067
|
-
if (strict && schema) {
|
|
2068
|
-
schema = removeNonRequiredProperties(
|
|
2069
|
-
schema
|
|
2070
|
-
);
|
|
2071
|
-
}
|
|
2072
|
-
const zodSchema = (0, import_json_schema_to_zod.jsonSchemaToZod)(schema);
|
|
2073
|
-
return zodSchema;
|
|
2074
|
-
} catch (error) {
|
|
2075
|
-
throw new JsonSchemaToZodError("Failed to convert JSON Schema to Zod Schema", {
|
|
2076
|
-
cause: error
|
|
2077
|
-
});
|
|
2078
|
-
}
|
|
2079
|
-
}
|
|
2080
|
-
|
|
2081
2061
|
// src/models/Tools.ts
|
|
2082
2062
|
var Tools = class {
|
|
2083
2063
|
client;
|
|
@@ -2258,12 +2238,16 @@ var Tools = class {
|
|
|
2258
2238
|
"Invalid tool list parameters, atleast one of the following parameters is required: tools, toolkits, search"
|
|
2259
2239
|
);
|
|
2260
2240
|
}
|
|
2241
|
+
let limit = "limit" in queryParams.data ? queryParams.data.limit?.toString() : void 0;
|
|
2242
|
+
if ("tools" in queryParams.data) {
|
|
2243
|
+
limit = "9999";
|
|
2244
|
+
}
|
|
2261
2245
|
const tools = await this.client.tools.list({
|
|
2262
2246
|
tool_slugs: "tools" in queryParams.data ? queryParams.data.tools?.join(",") : void 0,
|
|
2263
2247
|
toolkit_slug: "toolkits" in queryParams.data ? queryParams.data.toolkits?.join(",") : void 0,
|
|
2264
2248
|
cursor: "cursor" in queryParams.data ? queryParams.data.cursor : void 0,
|
|
2265
2249
|
important: "important" in queryParams.data ? queryParams.data.important ? "true" : "false" : void 0,
|
|
2266
|
-
limit
|
|
2250
|
+
limit,
|
|
2267
2251
|
search: "search" in queryParams.data ? queryParams.data.search : void 0
|
|
2268
2252
|
});
|
|
2269
2253
|
if (!tools) {
|
|
@@ -2338,14 +2322,7 @@ var Tools = class {
|
|
|
2338
2322
|
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifySchema);
|
|
2339
2323
|
return this.provider.wrapTools([tool], executeToolFn);
|
|
2340
2324
|
} else {
|
|
2341
|
-
|
|
2342
|
-
if (arg2?.strict) {
|
|
2343
|
-
tools = tools.map((tool) => ({
|
|
2344
|
-
...tool,
|
|
2345
|
-
inputParameters: tool.inputParameters ? removeNonRequiredProperties(tool.inputParameters) : void 0,
|
|
2346
|
-
outputParameters: tool.outputParameters ? removeNonRequiredProperties(tool.outputParameters) : void 0
|
|
2347
|
-
}));
|
|
2348
|
-
}
|
|
2325
|
+
const tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
|
|
2349
2326
|
return this.provider.wrapTools(tools, executeToolFn);
|
|
2350
2327
|
}
|
|
2351
2328
|
}
|
|
@@ -2772,7 +2749,8 @@ var AuthConfigs = class {
|
|
|
2772
2749
|
isComposioManaged: authConfig.is_composio_managed,
|
|
2773
2750
|
createdBy: authConfig.created_by,
|
|
2774
2751
|
createdAt: authConfig.created_at,
|
|
2775
|
-
lastUpdatedAt: authConfig.last_updated_at
|
|
2752
|
+
lastUpdatedAt: authConfig.last_updated_at,
|
|
2753
|
+
restrictToFollowingTools: authConfig.restrict_to_following_tools
|
|
2776
2754
|
});
|
|
2777
2755
|
if (result.error) {
|
|
2778
2756
|
throw new ValidationError("Failed to parse auth config response", {
|
|
@@ -3269,6 +3247,19 @@ var ConnectedAccounts = class {
|
|
|
3269
3247
|
* @link https://docs.composio.dev/reference/connected-accounts/create-connected-account
|
|
3270
3248
|
*/
|
|
3271
3249
|
async initiate(userId, authConfigId, options) {
|
|
3250
|
+
const connectedAccount = await this.list({
|
|
3251
|
+
userIds: [userId],
|
|
3252
|
+
authConfigIds: [authConfigId]
|
|
3253
|
+
});
|
|
3254
|
+
if (connectedAccount.items.length > 0 && !options?.allowMultiple) {
|
|
3255
|
+
throw new ComposioMultipleConnectedAccountsError(
|
|
3256
|
+
`Multiple connected accounts found for user ${userId} in auth config ${authConfigId}`
|
|
3257
|
+
);
|
|
3258
|
+
} else if (connectedAccount.items.length > 0) {
|
|
3259
|
+
logger_default.warn(
|
|
3260
|
+
`[Warn:AllowMultiple] Multiple connected accounts found for user ${userId} in auth config ${authConfigId}`
|
|
3261
|
+
);
|
|
3262
|
+
}
|
|
3272
3263
|
const response = await this.client.connectedAccounts.create({
|
|
3273
3264
|
auth_config: {
|
|
3274
3265
|
id: authConfigId
|
|
@@ -3737,10 +3728,16 @@ var Toolkits = class {
|
|
|
3737
3728
|
}
|
|
3738
3729
|
}
|
|
3739
3730
|
const composioConnectedAccount = new ConnectedAccounts(this.client);
|
|
3740
|
-
return await composioConnectedAccount.initiate(userId, authConfigIdToUse
|
|
3731
|
+
return await composioConnectedAccount.initiate(userId, authConfigIdToUse, {
|
|
3732
|
+
// in this magic function we allow multiple connected accounts per user for an auth config
|
|
3733
|
+
allowMultiple: true
|
|
3734
|
+
});
|
|
3741
3735
|
}
|
|
3742
3736
|
};
|
|
3743
3737
|
|
|
3738
|
+
// src/models/Triggers.ts
|
|
3739
|
+
var import_client6 = require("@composio/client");
|
|
3740
|
+
|
|
3744
3741
|
// src/types/triggers.types.ts
|
|
3745
3742
|
var import_zod8 = require("zod");
|
|
3746
3743
|
var TriggerStatuses = {
|
|
@@ -3800,6 +3797,7 @@ var TriggerInstanceManageDeleteResponseSchema = import_zod8.z.object({
|
|
|
3800
3797
|
});
|
|
3801
3798
|
var IncomingTriggerPayloadSchema = import_zod8.z.object({
|
|
3802
3799
|
id: import_zod8.z.string().describe("The ID of the trigger"),
|
|
3800
|
+
uuid: import_zod8.z.string().describe("The UUID of the trigger"),
|
|
3803
3801
|
triggerSlug: import_zod8.z.string().describe("The slug of the trigger that triggered the event"),
|
|
3804
3802
|
toolkitSlug: import_zod8.z.string().describe("The slug of the toolkit that triggered the event"),
|
|
3805
3803
|
userId: import_zod8.z.string().describe("The ID of the user that triggered the event"),
|
|
@@ -3807,6 +3805,7 @@ var IncomingTriggerPayloadSchema = import_zod8.z.object({
|
|
|
3807
3805
|
originalPayload: import_zod8.z.record(import_zod8.z.unknown()).describe("The original payload of the trigger").optional(),
|
|
3808
3806
|
metadata: import_zod8.z.object({
|
|
3809
3807
|
id: import_zod8.z.string(),
|
|
3808
|
+
uuid: import_zod8.z.string(),
|
|
3810
3809
|
toolkitSlug: import_zod8.z.string(),
|
|
3811
3810
|
triggerSlug: import_zod8.z.string(),
|
|
3812
3811
|
triggerData: import_zod8.z.string().optional(),
|
|
@@ -3869,7 +3868,8 @@ var TriggerErrorCodes = {
|
|
|
3869
3868
|
TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS: "TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS",
|
|
3870
3869
|
TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT: "TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT",
|
|
3871
3870
|
TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL",
|
|
3872
|
-
TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL"
|
|
3871
|
+
TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL",
|
|
3872
|
+
TRIGGER_TYPE_NOT_FOUND: "TRIGGER_TYPE_NOT_FOUND"
|
|
3873
3873
|
};
|
|
3874
3874
|
var ComposioFailedToGetSDKRealtimeCredentialsError = class extends import_client5.ComposioError {
|
|
3875
3875
|
name = "ComposioFailedToGetSDKRealtimeCredentialsError";
|
|
@@ -3898,6 +3898,15 @@ var ComposioFailedToSubscribeToPusherChannelError = class extends import_client5
|
|
|
3898
3898
|
super(message, options);
|
|
3899
3899
|
}
|
|
3900
3900
|
};
|
|
3901
|
+
var ComposioTriggerTypeNotFoundError = class extends import_client5.ComposioError {
|
|
3902
|
+
name = "ComposioTriggerTypeNotFoundError";
|
|
3903
|
+
code = TriggerErrorCodes.TRIGGER_TYPE_NOT_FOUND;
|
|
3904
|
+
statusCode = 404;
|
|
3905
|
+
possibleFixes = ["Please contact support."];
|
|
3906
|
+
constructor(message = "Trigger type not found", options) {
|
|
3907
|
+
super(message, options);
|
|
3908
|
+
}
|
|
3909
|
+
};
|
|
3901
3910
|
|
|
3902
3911
|
// src/services/pusher/Pusher.ts
|
|
3903
3912
|
var PusherService = class {
|
|
@@ -4163,21 +4172,89 @@ var Triggers = class {
|
|
|
4163
4172
|
return parsedResult.data;
|
|
4164
4173
|
}
|
|
4165
4174
|
/**
|
|
4166
|
-
* Create a new trigger instance
|
|
4175
|
+
* Create a new trigger instance for a user
|
|
4176
|
+
* If the connected account id is not provided, the first connected account for the user and toolkit will be used
|
|
4167
4177
|
*
|
|
4178
|
+
* @param {string} userId - The user id of the trigger instance
|
|
4168
4179
|
* @param {string} slug - The slug of the trigger instance
|
|
4169
4180
|
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
4170
4181
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
4171
4182
|
*/
|
|
4172
|
-
async create(slug, body) {
|
|
4173
|
-
const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body);
|
|
4183
|
+
async create(userId, slug, body) {
|
|
4184
|
+
const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body ?? {});
|
|
4174
4185
|
if (!parsedBody.success) {
|
|
4175
4186
|
throw new ValidationError(`Invalid parameters passed to create trigger`, {
|
|
4176
4187
|
cause: parsedBody.error
|
|
4177
4188
|
});
|
|
4178
4189
|
}
|
|
4190
|
+
let triggerType;
|
|
4191
|
+
let toolkitSlug;
|
|
4192
|
+
try {
|
|
4193
|
+
triggerType = await this.getType(slug);
|
|
4194
|
+
toolkitSlug = triggerType.toolkit.slug;
|
|
4195
|
+
} catch (error) {
|
|
4196
|
+
if (error instanceof import_client6.APIError && (error.status === 400 || error.status === 404)) {
|
|
4197
|
+
throw new ComposioTriggerTypeNotFoundError(`Trigger type ${slug} not found`, {
|
|
4198
|
+
cause: error,
|
|
4199
|
+
possibleFixes: [
|
|
4200
|
+
`Please check the trigger slug`,
|
|
4201
|
+
`Visit the toolkit page to see the available triggers`
|
|
4202
|
+
]
|
|
4203
|
+
});
|
|
4204
|
+
} else {
|
|
4205
|
+
throw error;
|
|
4206
|
+
}
|
|
4207
|
+
}
|
|
4208
|
+
let connectedAccountId = body?.connectedAccountId;
|
|
4209
|
+
try {
|
|
4210
|
+
const { items: connectedAccounts } = await this.client.connectedAccounts.list({
|
|
4211
|
+
user_ids: [userId],
|
|
4212
|
+
toolkit_slugs: [toolkitSlug]
|
|
4213
|
+
});
|
|
4214
|
+
if (connectedAccounts.length === 0) {
|
|
4215
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
4216
|
+
`No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
|
|
4217
|
+
{
|
|
4218
|
+
cause: new Error(`No connected account found for user ${userId}`),
|
|
4219
|
+
possibleFixes: [`Create a new connected account for user ${userId}`]
|
|
4220
|
+
}
|
|
4221
|
+
);
|
|
4222
|
+
}
|
|
4223
|
+
const accountExists = connectedAccounts.some((acc) => acc.id === connectedAccountId);
|
|
4224
|
+
if (connectedAccountId && !accountExists) {
|
|
4225
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
4226
|
+
`Connected account ID ${connectedAccountId} not found for user ${userId}`,
|
|
4227
|
+
{
|
|
4228
|
+
cause: new Error(
|
|
4229
|
+
`Connected account ID ${connectedAccountId} not found for user ${userId}`
|
|
4230
|
+
),
|
|
4231
|
+
possibleFixes: [
|
|
4232
|
+
`Create a new connected account for user ${userId}`,
|
|
4233
|
+
`Verify the connected account ID`
|
|
4234
|
+
]
|
|
4235
|
+
}
|
|
4236
|
+
);
|
|
4237
|
+
}
|
|
4238
|
+
if (!connectedAccountId) {
|
|
4239
|
+
connectedAccountId = connectedAccounts[0].id;
|
|
4240
|
+
logger_default.warn(
|
|
4241
|
+
`[Warn] Multiple connected accounts found for user ${userId}, using the first one. Pass connectedAccountId to select a specific account.`
|
|
4242
|
+
);
|
|
4243
|
+
}
|
|
4244
|
+
} catch (error) {
|
|
4245
|
+
if (error instanceof import_client6.APIError && [400, 404].includes(error.status)) {
|
|
4246
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
4247
|
+
`No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
|
|
4248
|
+
{
|
|
4249
|
+
cause: error,
|
|
4250
|
+
possibleFixes: [`Create a new connected account for user ${userId}`]
|
|
4251
|
+
}
|
|
4252
|
+
);
|
|
4253
|
+
}
|
|
4254
|
+
throw error;
|
|
4255
|
+
}
|
|
4179
4256
|
const result = await this.client.triggerInstances.upsert(slug, {
|
|
4180
|
-
connected_account_id:
|
|
4257
|
+
connected_account_id: connectedAccountId,
|
|
4181
4258
|
trigger_config: parsedBody.data.triggerConfig
|
|
4182
4259
|
});
|
|
4183
4260
|
const parsedResult = TriggerInstanceUpsertResponseSchema.safeParse({
|
|
@@ -4273,6 +4350,54 @@ var Triggers = class {
|
|
|
4273
4350
|
async listEnum() {
|
|
4274
4351
|
return this.client.triggersTypes.retrieveEnum();
|
|
4275
4352
|
}
|
|
4353
|
+
/**
|
|
4354
|
+
* Applies compound filters to the trigger data
|
|
4355
|
+
* @param data data to apply filters to
|
|
4356
|
+
* @returns True if the trigger data matches the filters, false otherwise
|
|
4357
|
+
*/
|
|
4358
|
+
shouldSendTriggerAfterFilters(filters, data) {
|
|
4359
|
+
if (filters.toolkits?.length && !filters.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
|
|
4360
|
+
logger_default.debug(
|
|
4361
|
+
"Trigger does not match toolkits filter",
|
|
4362
|
+
JSON.stringify(filters.toolkits, null, 2)
|
|
4363
|
+
);
|
|
4364
|
+
return false;
|
|
4365
|
+
}
|
|
4366
|
+
if (filters.triggerId && filters.triggerId !== data.id) {
|
|
4367
|
+
logger_default.debug(
|
|
4368
|
+
"Trigger does not match triggerId filter",
|
|
4369
|
+
JSON.stringify(filters.triggerId, null, 2)
|
|
4370
|
+
);
|
|
4371
|
+
return false;
|
|
4372
|
+
}
|
|
4373
|
+
if (filters.connectedAccountId && filters.connectedAccountId !== data.metadata.connectedAccount.id) {
|
|
4374
|
+
logger_default.debug(
|
|
4375
|
+
"Trigger does not match connectedAccountId filter",
|
|
4376
|
+
JSON.stringify(filters.connectedAccountId, null, 2)
|
|
4377
|
+
);
|
|
4378
|
+
return false;
|
|
4379
|
+
}
|
|
4380
|
+
if (filters.triggerSlug?.length && !filters.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
|
|
4381
|
+
logger_default.debug(
|
|
4382
|
+
"Trigger does not match triggerSlug filter",
|
|
4383
|
+
JSON.stringify(filters.triggerSlug, null, 2)
|
|
4384
|
+
);
|
|
4385
|
+
return false;
|
|
4386
|
+
}
|
|
4387
|
+
if (filters.triggerData && filters.triggerData !== data.metadata.triggerData) {
|
|
4388
|
+
logger_default.debug(
|
|
4389
|
+
"Trigger does not match triggerData filter",
|
|
4390
|
+
JSON.stringify(filters.triggerData, null, 2)
|
|
4391
|
+
);
|
|
4392
|
+
return false;
|
|
4393
|
+
}
|
|
4394
|
+
if (filters.userId && filters.userId !== data.metadata.connectedAccount.userId) {
|
|
4395
|
+
logger_default.debug("Trigger does not match userId filter", JSON.stringify(filters.userId, null, 2));
|
|
4396
|
+
return false;
|
|
4397
|
+
}
|
|
4398
|
+
logger_default.debug("Trigger matches all filters", JSON.stringify(filters, null, 2));
|
|
4399
|
+
return true;
|
|
4400
|
+
}
|
|
4276
4401
|
/**
|
|
4277
4402
|
* Subscribe to all the triggers
|
|
4278
4403
|
*
|
|
@@ -4295,65 +4420,21 @@ var Triggers = class {
|
|
|
4295
4420
|
cause: parsedFilters.error
|
|
4296
4421
|
});
|
|
4297
4422
|
}
|
|
4298
|
-
const shouldSendTriggerAfterFilters = (data) => {
|
|
4299
|
-
if (parsedFilters.data.toolkits?.length && !parsedFilters.data.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
|
|
4300
|
-
logger_default.debug(
|
|
4301
|
-
"Trigger does not match toolkits filter",
|
|
4302
|
-
JSON.stringify(parsedFilters.data.toolkits, null, 2)
|
|
4303
|
-
);
|
|
4304
|
-
return false;
|
|
4305
|
-
}
|
|
4306
|
-
if (parsedFilters.data.triggerId && parsedFilters.data.triggerId !== data.id) {
|
|
4307
|
-
logger_default.debug(
|
|
4308
|
-
"Trigger does not match triggerId filter",
|
|
4309
|
-
JSON.stringify(parsedFilters.data.triggerId, null, 2)
|
|
4310
|
-
);
|
|
4311
|
-
return false;
|
|
4312
|
-
}
|
|
4313
|
-
if (parsedFilters.data.connectedAccountId && parsedFilters.data.connectedAccountId !== data.metadata.connectedAccount.id) {
|
|
4314
|
-
logger_default.debug(
|
|
4315
|
-
"Trigger does not match connectedAccountId filter",
|
|
4316
|
-
JSON.stringify(parsedFilters.data.connectedAccountId, null, 2)
|
|
4317
|
-
);
|
|
4318
|
-
return false;
|
|
4319
|
-
}
|
|
4320
|
-
if (parsedFilters.data.triggerSlug?.length && !parsedFilters.data.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
|
|
4321
|
-
logger_default.debug(
|
|
4322
|
-
"Trigger does not match triggerSlug filter",
|
|
4323
|
-
JSON.stringify(parsedFilters.data.triggerSlug, null, 2)
|
|
4324
|
-
);
|
|
4325
|
-
return false;
|
|
4326
|
-
}
|
|
4327
|
-
if (parsedFilters.data.triggerData && parsedFilters.data.triggerData !== data.metadata.triggerData) {
|
|
4328
|
-
logger_default.debug(
|
|
4329
|
-
"Trigger does not match triggerData filter",
|
|
4330
|
-
JSON.stringify(parsedFilters.data.triggerData, null, 2)
|
|
4331
|
-
);
|
|
4332
|
-
return false;
|
|
4333
|
-
}
|
|
4334
|
-
if (parsedFilters.data.userId && parsedFilters.data.userId !== data.metadata.connectedAccount.userId) {
|
|
4335
|
-
logger_default.debug(
|
|
4336
|
-
"Trigger does not match userId filter",
|
|
4337
|
-
JSON.stringify(parsedFilters.data.userId, null, 2)
|
|
4338
|
-
);
|
|
4339
|
-
return false;
|
|
4340
|
-
}
|
|
4341
|
-
logger_default.debug("Trigger matches all filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
4342
|
-
return true;
|
|
4343
|
-
};
|
|
4344
4423
|
logger_default.debug("\u{1F504} Subscribing to triggers with filters: ", JSON.stringify(filters, null, 2));
|
|
4345
4424
|
await this.pusherService.subscribe((_data) => {
|
|
4346
4425
|
logger_default.debug("Received raw trigger data", JSON.stringify(_data, null, 2));
|
|
4347
4426
|
const data = _data;
|
|
4348
4427
|
const parsedData = IncomingTriggerPayloadSchema.safeParse({
|
|
4349
|
-
id: data.metadata.
|
|
4428
|
+
id: data.metadata.nanoId,
|
|
4429
|
+
uuid: data.metadata.id,
|
|
4350
4430
|
triggerSlug: data.metadata.triggerName,
|
|
4351
4431
|
toolkitSlug: data.appName,
|
|
4352
4432
|
userId: data.metadata.connection?.clientUniqueUserId,
|
|
4353
4433
|
payload: data.payload,
|
|
4354
4434
|
originalPayload: data.originalPayload,
|
|
4355
4435
|
metadata: {
|
|
4356
|
-
id: data.metadata.
|
|
4436
|
+
id: data.metadata.nanoId,
|
|
4437
|
+
uuid: data.metadata.id,
|
|
4357
4438
|
triggerConfig: data.metadata.triggerConfig,
|
|
4358
4439
|
triggerSlug: data.metadata.triggerName,
|
|
4359
4440
|
toolkitSlug: data.appName,
|
|
@@ -4374,7 +4455,7 @@ var Triggers = class {
|
|
|
4374
4455
|
cause: parsedData.error
|
|
4375
4456
|
});
|
|
4376
4457
|
}
|
|
4377
|
-
if (shouldSendTriggerAfterFilters(parsedData.data)) {
|
|
4458
|
+
if (this.shouldSendTriggerAfterFilters(parsedFilters.data, parsedData.data)) {
|
|
4378
4459
|
try {
|
|
4379
4460
|
fn(parsedData.data);
|
|
4380
4461
|
} catch (error) {
|
|
@@ -4926,7 +5007,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
4926
5007
|
};
|
|
4927
5008
|
|
|
4928
5009
|
// package.json
|
|
4929
|
-
var version = "0.1.
|
|
5010
|
+
var version = "0.1.23";
|
|
4930
5011
|
|
|
4931
5012
|
// src/composio.ts
|
|
4932
5013
|
var Composio = class _Composio {
|
|
@@ -4990,7 +5071,7 @@ var Composio = class _Composio {
|
|
|
4990
5071
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
4991
5072
|
logger_default.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
4992
5073
|
}
|
|
4993
|
-
this.client = new
|
|
5074
|
+
this.client = new import_client7.default({
|
|
4994
5075
|
apiKey: apiKeyParsed,
|
|
4995
5076
|
baseURL: baseURLParsed,
|
|
4996
5077
|
defaultHeaders: config?.defaultHeaders,
|
|
@@ -5089,6 +5170,38 @@ var ComposioProvider = class extends BaseNonAgenticProvider {
|
|
|
5089
5170
|
}
|
|
5090
5171
|
};
|
|
5091
5172
|
|
|
5173
|
+
// src/utils/jsonSchema.ts
|
|
5174
|
+
var import_json_schema_to_zod = require("@composio/json-schema-to-zod");
|
|
5175
|
+
var removeNonRequiredProperties = (schema) => {
|
|
5176
|
+
if (schema && schema.type === "object" && schema.required?.length) {
|
|
5177
|
+
schema.properties = Object.fromEntries(
|
|
5178
|
+
Object.entries(schema.properties || {}).filter(
|
|
5179
|
+
([key]) => schema.required.includes(key)
|
|
5180
|
+
)
|
|
5181
|
+
);
|
|
5182
|
+
}
|
|
5183
|
+
schema.additionalProperties = false;
|
|
5184
|
+
return schema;
|
|
5185
|
+
};
|
|
5186
|
+
function jsonSchemaToZodSchema(jsonSchema, { strict } = {
|
|
5187
|
+
strict: false
|
|
5188
|
+
}) {
|
|
5189
|
+
try {
|
|
5190
|
+
let schema = jsonSchema;
|
|
5191
|
+
if (strict && schema) {
|
|
5192
|
+
schema = removeNonRequiredProperties(
|
|
5193
|
+
schema
|
|
5194
|
+
);
|
|
5195
|
+
}
|
|
5196
|
+
const zodSchema = (0, import_json_schema_to_zod.jsonSchemaToZod)(schema);
|
|
5197
|
+
return zodSchema;
|
|
5198
|
+
} catch (error) {
|
|
5199
|
+
throw new JsonSchemaToZodError("Failed to convert JSON Schema to Zod Schema", {
|
|
5200
|
+
cause: error
|
|
5201
|
+
});
|
|
5202
|
+
}
|
|
5203
|
+
}
|
|
5204
|
+
|
|
5092
5205
|
// src/models/AuthScheme.ts
|
|
5093
5206
|
var AuthScheme = class {
|
|
5094
5207
|
/**
|
|
@@ -5281,6 +5394,7 @@ var AuthScheme = class {
|
|
|
5281
5394
|
ComposioInvalidExecuteFunctionError,
|
|
5282
5395
|
ComposioInvalidModifierError,
|
|
5283
5396
|
ComposioLinkConnectionDataSchema,
|
|
5397
|
+
ComposioMultipleConnectedAccountsError,
|
|
5284
5398
|
ComposioNoAPIKeyError,
|
|
5285
5399
|
ComposioProvider,
|
|
5286
5400
|
ComposioProviderNotDefinedError,
|
|
@@ -5354,5 +5468,6 @@ var AuthScheme = class {
|
|
|
5354
5468
|
ValidationError,
|
|
5355
5469
|
ValidationErrorCodes,
|
|
5356
5470
|
jsonSchemaToZodSchema,
|
|
5357
|
-
logger
|
|
5471
|
+
logger,
|
|
5472
|
+
removeNonRequiredProperties
|
|
5358
5473
|
});
|