@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.js
CHANGED
|
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
// src/composio.ts
|
|
9
|
-
import
|
|
9
|
+
import ComposioClient4 from "@composio/client";
|
|
10
10
|
|
|
11
11
|
// src/types/tool.types.ts
|
|
12
12
|
import { z } from "zod";
|
|
@@ -108,19 +108,13 @@ var ToolListFilterByToolkitsSchema = z.object({
|
|
|
108
108
|
important: z.boolean().optional(),
|
|
109
109
|
cursor: z.string().optional(),
|
|
110
110
|
limit: z.number().optional(),
|
|
111
|
-
search: z.string().optional()
|
|
112
|
-
strict: z.boolean().optional().describe(
|
|
113
|
-
"If true, all the non-required fields will be removed from the input/output params of the tool"
|
|
114
|
-
)
|
|
111
|
+
search: z.string().optional()
|
|
115
112
|
});
|
|
116
113
|
var ToolListFilterBySearchSchema = z.object({
|
|
117
114
|
search: z.string(),
|
|
118
115
|
toolkits: z.array(z.string()).optional(),
|
|
119
116
|
cursor: z.string().optional(),
|
|
120
|
-
limit: z.number().optional()
|
|
121
|
-
strict: z.boolean().optional().describe(
|
|
122
|
-
"If true, all the non-required fields will be removed from the input/output params of the tool"
|
|
123
|
-
)
|
|
117
|
+
limit: z.number().optional()
|
|
124
118
|
});
|
|
125
119
|
var ToolListParamsSchema = z.union([
|
|
126
120
|
ToolListFilterByToolsSchema,
|
|
@@ -596,7 +590,8 @@ var ComposioGlobalExecuteToolFnNotSetError = class extends ComposioError {
|
|
|
596
590
|
|
|
597
591
|
// src/errors/ConnectedAccountsErrors.ts
|
|
598
592
|
var ConnectedAccountErrorCodes = {
|
|
599
|
-
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND"
|
|
593
|
+
CONNECTED_ACCOUNT_NOT_FOUND: "CONNECTED_ACCOUNT_NOT_FOUND",
|
|
594
|
+
MULTIPLE_CONNECTED_ACCOUNTS: "MULTIPLE_CONNECTED_ACCOUNTS"
|
|
600
595
|
};
|
|
601
596
|
var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
602
597
|
constructor(message = "Connected account not found", options = {}) {
|
|
@@ -611,6 +606,17 @@ var ComposioConnectedAccountNotFoundError = class extends ComposioError {
|
|
|
611
606
|
this.name = "ComposioConnectedAccountNotFoundError";
|
|
612
607
|
}
|
|
613
608
|
};
|
|
609
|
+
var ComposioMultipleConnectedAccountsError = class extends ComposioError {
|
|
610
|
+
constructor(message = "Multiple connected accounts found") {
|
|
611
|
+
super(message, {
|
|
612
|
+
code: ConnectedAccountErrorCodes.MULTIPLE_CONNECTED_ACCOUNTS,
|
|
613
|
+
possibleFixes: [
|
|
614
|
+
"Use the allowMultiple flag to allow multiple connected accounts per user for an auth config"
|
|
615
|
+
]
|
|
616
|
+
});
|
|
617
|
+
this.name = "ComposioMultipleConnectedAccountsError";
|
|
618
|
+
}
|
|
619
|
+
};
|
|
614
620
|
|
|
615
621
|
// src/telemetry/Telemetry.ts
|
|
616
622
|
import { ComposioError as ComposioClientError } from "@composio/client";
|
|
@@ -1103,6 +1109,7 @@ var AuthConfigRetrieveResponseSchema = z2.object({
|
|
|
1103
1109
|
authScheme: AuthSchemeEnum.optional(),
|
|
1104
1110
|
credentials: z2.record(z2.string(), z2.unknown()).optional(),
|
|
1105
1111
|
expectedInputFields: z2.array(z2.unknown()).optional(),
|
|
1112
|
+
restrictToFollowingTools: z2.array(z2.string()).optional(),
|
|
1106
1113
|
isComposioManaged: z2.boolean().optional(),
|
|
1107
1114
|
createdBy: z2.string().optional(),
|
|
1108
1115
|
createdAt: z2.string().optional(),
|
|
@@ -1534,7 +1541,8 @@ var ConnectedAccountStatuses = {
|
|
|
1534
1541
|
INITIATED: "INITIATED",
|
|
1535
1542
|
ACTIVE: "ACTIVE",
|
|
1536
1543
|
FAILED: "FAILED",
|
|
1537
|
-
EXPIRED: "EXPIRED"
|
|
1544
|
+
EXPIRED: "EXPIRED",
|
|
1545
|
+
INACTIVE: "INACTIVE"
|
|
1538
1546
|
};
|
|
1539
1547
|
var ConnectedAccountStatusSchema = z4.enum([
|
|
1540
1548
|
ConnectedAccountStatuses.INITIALIZING,
|
|
@@ -1565,6 +1573,7 @@ var DefaultCreateConnectedAccountParamsSchema = z4.object({
|
|
|
1565
1573
|
})
|
|
1566
1574
|
});
|
|
1567
1575
|
var CreateConnectedAccountOptionsSchema = z4.object({
|
|
1576
|
+
allowMultiple: z4.boolean().optional(),
|
|
1568
1577
|
callbackUrl: z4.string().optional(),
|
|
1569
1578
|
config: ConnectionDataSchema.optional()
|
|
1570
1579
|
});
|
|
@@ -1921,37 +1930,6 @@ var CustomTools = class {
|
|
|
1921
1930
|
}
|
|
1922
1931
|
};
|
|
1923
1932
|
|
|
1924
|
-
// src/utils/jsonSchema.ts
|
|
1925
|
-
import { jsonSchemaToZod } from "@composio/json-schema-to-zod";
|
|
1926
|
-
var removeNonRequiredProperties = (schema) => {
|
|
1927
|
-
if (schema && schema.type === "object" && schema.required?.length) {
|
|
1928
|
-
schema.properties = Object.fromEntries(
|
|
1929
|
-
Object.entries(schema.properties || {}).filter(
|
|
1930
|
-
([key]) => schema.required.includes(key)
|
|
1931
|
-
)
|
|
1932
|
-
);
|
|
1933
|
-
}
|
|
1934
|
-
return schema;
|
|
1935
|
-
};
|
|
1936
|
-
function jsonSchemaToZodSchema(jsonSchema, { strict } = {
|
|
1937
|
-
strict: false
|
|
1938
|
-
}) {
|
|
1939
|
-
try {
|
|
1940
|
-
let schema = jsonSchema;
|
|
1941
|
-
if (strict && schema) {
|
|
1942
|
-
schema = removeNonRequiredProperties(
|
|
1943
|
-
schema
|
|
1944
|
-
);
|
|
1945
|
-
}
|
|
1946
|
-
const zodSchema = jsonSchemaToZod(schema);
|
|
1947
|
-
return zodSchema;
|
|
1948
|
-
} catch (error) {
|
|
1949
|
-
throw new JsonSchemaToZodError("Failed to convert JSON Schema to Zod Schema", {
|
|
1950
|
-
cause: error
|
|
1951
|
-
});
|
|
1952
|
-
}
|
|
1953
|
-
}
|
|
1954
|
-
|
|
1955
1933
|
// src/models/Tools.ts
|
|
1956
1934
|
var Tools = class {
|
|
1957
1935
|
client;
|
|
@@ -2132,12 +2110,16 @@ var Tools = class {
|
|
|
2132
2110
|
"Invalid tool list parameters, atleast one of the following parameters is required: tools, toolkits, search"
|
|
2133
2111
|
);
|
|
2134
2112
|
}
|
|
2113
|
+
let limit = "limit" in queryParams.data ? queryParams.data.limit?.toString() : void 0;
|
|
2114
|
+
if ("tools" in queryParams.data) {
|
|
2115
|
+
limit = "9999";
|
|
2116
|
+
}
|
|
2135
2117
|
const tools = await this.client.tools.list({
|
|
2136
2118
|
tool_slugs: "tools" in queryParams.data ? queryParams.data.tools?.join(",") : void 0,
|
|
2137
2119
|
toolkit_slug: "toolkits" in queryParams.data ? queryParams.data.toolkits?.join(",") : void 0,
|
|
2138
2120
|
cursor: "cursor" in queryParams.data ? queryParams.data.cursor : void 0,
|
|
2139
2121
|
important: "important" in queryParams.data ? queryParams.data.important ? "true" : "false" : void 0,
|
|
2140
|
-
limit
|
|
2122
|
+
limit,
|
|
2141
2123
|
search: "search" in queryParams.data ? queryParams.data.search : void 0
|
|
2142
2124
|
});
|
|
2143
2125
|
if (!tools) {
|
|
@@ -2212,14 +2194,7 @@ var Tools = class {
|
|
|
2212
2194
|
const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifySchema);
|
|
2213
2195
|
return this.provider.wrapTools([tool], executeToolFn);
|
|
2214
2196
|
} else {
|
|
2215
|
-
|
|
2216
|
-
if (arg2?.strict) {
|
|
2217
|
-
tools = tools.map((tool) => ({
|
|
2218
|
-
...tool,
|
|
2219
|
-
inputParameters: tool.inputParameters ? removeNonRequiredProperties(tool.inputParameters) : void 0,
|
|
2220
|
-
outputParameters: tool.outputParameters ? removeNonRequiredProperties(tool.outputParameters) : void 0
|
|
2221
|
-
}));
|
|
2222
|
-
}
|
|
2197
|
+
const tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
|
|
2223
2198
|
return this.provider.wrapTools(tools, executeToolFn);
|
|
2224
2199
|
}
|
|
2225
2200
|
}
|
|
@@ -2646,7 +2621,8 @@ var AuthConfigs = class {
|
|
|
2646
2621
|
isComposioManaged: authConfig.is_composio_managed,
|
|
2647
2622
|
createdBy: authConfig.created_by,
|
|
2648
2623
|
createdAt: authConfig.created_at,
|
|
2649
|
-
lastUpdatedAt: authConfig.last_updated_at
|
|
2624
|
+
lastUpdatedAt: authConfig.last_updated_at,
|
|
2625
|
+
restrictToFollowingTools: authConfig.restrict_to_following_tools
|
|
2650
2626
|
});
|
|
2651
2627
|
if (result.error) {
|
|
2652
2628
|
throw new ValidationError("Failed to parse auth config response", {
|
|
@@ -3143,6 +3119,19 @@ var ConnectedAccounts = class {
|
|
|
3143
3119
|
* @link https://docs.composio.dev/reference/connected-accounts/create-connected-account
|
|
3144
3120
|
*/
|
|
3145
3121
|
async initiate(userId, authConfigId, options) {
|
|
3122
|
+
const connectedAccount = await this.list({
|
|
3123
|
+
userIds: [userId],
|
|
3124
|
+
authConfigIds: [authConfigId]
|
|
3125
|
+
});
|
|
3126
|
+
if (connectedAccount.items.length > 0 && !options?.allowMultiple) {
|
|
3127
|
+
throw new ComposioMultipleConnectedAccountsError(
|
|
3128
|
+
`Multiple connected accounts found for user ${userId} in auth config ${authConfigId}`
|
|
3129
|
+
);
|
|
3130
|
+
} else if (connectedAccount.items.length > 0) {
|
|
3131
|
+
logger_default.warn(
|
|
3132
|
+
`[Warn:AllowMultiple] Multiple connected accounts found for user ${userId} in auth config ${authConfigId}`
|
|
3133
|
+
);
|
|
3134
|
+
}
|
|
3146
3135
|
const response = await this.client.connectedAccounts.create({
|
|
3147
3136
|
auth_config: {
|
|
3148
3137
|
id: authConfigId
|
|
@@ -3611,10 +3600,16 @@ var Toolkits = class {
|
|
|
3611
3600
|
}
|
|
3612
3601
|
}
|
|
3613
3602
|
const composioConnectedAccount = new ConnectedAccounts(this.client);
|
|
3614
|
-
return await composioConnectedAccount.initiate(userId, authConfigIdToUse
|
|
3603
|
+
return await composioConnectedAccount.initiate(userId, authConfigIdToUse, {
|
|
3604
|
+
// in this magic function we allow multiple connected accounts per user for an auth config
|
|
3605
|
+
allowMultiple: true
|
|
3606
|
+
});
|
|
3615
3607
|
}
|
|
3616
3608
|
};
|
|
3617
3609
|
|
|
3610
|
+
// src/models/Triggers.ts
|
|
3611
|
+
import { APIError } from "@composio/client";
|
|
3612
|
+
|
|
3618
3613
|
// src/types/triggers.types.ts
|
|
3619
3614
|
import { z as z6 } from "zod";
|
|
3620
3615
|
var TriggerStatuses = {
|
|
@@ -3674,6 +3669,7 @@ var TriggerInstanceManageDeleteResponseSchema = z6.object({
|
|
|
3674
3669
|
});
|
|
3675
3670
|
var IncomingTriggerPayloadSchema = z6.object({
|
|
3676
3671
|
id: z6.string().describe("The ID of the trigger"),
|
|
3672
|
+
uuid: z6.string().describe("The UUID of the trigger"),
|
|
3677
3673
|
triggerSlug: z6.string().describe("The slug of the trigger that triggered the event"),
|
|
3678
3674
|
toolkitSlug: z6.string().describe("The slug of the toolkit that triggered the event"),
|
|
3679
3675
|
userId: z6.string().describe("The ID of the user that triggered the event"),
|
|
@@ -3681,6 +3677,7 @@ var IncomingTriggerPayloadSchema = z6.object({
|
|
|
3681
3677
|
originalPayload: z6.record(z6.unknown()).describe("The original payload of the trigger").optional(),
|
|
3682
3678
|
metadata: z6.object({
|
|
3683
3679
|
id: z6.string(),
|
|
3680
|
+
uuid: z6.string(),
|
|
3684
3681
|
toolkitSlug: z6.string(),
|
|
3685
3682
|
triggerSlug: z6.string(),
|
|
3686
3683
|
triggerData: z6.string().optional(),
|
|
@@ -3743,7 +3740,8 @@ var TriggerErrorCodes = {
|
|
|
3743
3740
|
TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS: "TRIGGER_FAILED_TO_GET_SDK_REALTIME_CREDENTIALS",
|
|
3744
3741
|
TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT: "TRIGGER_FAILED_TO_CREATE_PUSHER_CLIENT",
|
|
3745
3742
|
TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_SUBSCRIBE_TO_PUSHER_CHANNEL",
|
|
3746
|
-
TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL"
|
|
3743
|
+
TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL: "TRIGGER_FAILED_TO_UNSUBSCRIBE_FROM_PUSHER_CHANNEL",
|
|
3744
|
+
TRIGGER_TYPE_NOT_FOUND: "TRIGGER_TYPE_NOT_FOUND"
|
|
3747
3745
|
};
|
|
3748
3746
|
var ComposioFailedToGetSDKRealtimeCredentialsError = class extends ComposioError2 {
|
|
3749
3747
|
name = "ComposioFailedToGetSDKRealtimeCredentialsError";
|
|
@@ -3772,6 +3770,15 @@ var ComposioFailedToSubscribeToPusherChannelError = class extends ComposioError2
|
|
|
3772
3770
|
super(message, options);
|
|
3773
3771
|
}
|
|
3774
3772
|
};
|
|
3773
|
+
var ComposioTriggerTypeNotFoundError = class extends ComposioError2 {
|
|
3774
|
+
name = "ComposioTriggerTypeNotFoundError";
|
|
3775
|
+
code = TriggerErrorCodes.TRIGGER_TYPE_NOT_FOUND;
|
|
3776
|
+
statusCode = 404;
|
|
3777
|
+
possibleFixes = ["Please contact support."];
|
|
3778
|
+
constructor(message = "Trigger type not found", options) {
|
|
3779
|
+
super(message, options);
|
|
3780
|
+
}
|
|
3781
|
+
};
|
|
3775
3782
|
|
|
3776
3783
|
// src/services/pusher/Pusher.ts
|
|
3777
3784
|
var PusherService = class {
|
|
@@ -4037,21 +4044,89 @@ var Triggers = class {
|
|
|
4037
4044
|
return parsedResult.data;
|
|
4038
4045
|
}
|
|
4039
4046
|
/**
|
|
4040
|
-
* Create a new trigger instance
|
|
4047
|
+
* Create a new trigger instance for a user
|
|
4048
|
+
* If the connected account id is not provided, the first connected account for the user and toolkit will be used
|
|
4041
4049
|
*
|
|
4050
|
+
* @param {string} userId - The user id of the trigger instance
|
|
4042
4051
|
* @param {string} slug - The slug of the trigger instance
|
|
4043
4052
|
* @param {TriggerInstanceUpsertParams} body - The parameters to create the trigger instance
|
|
4044
4053
|
* @returns {Promise<TriggerInstanceUpsertResponse>} The created trigger instance
|
|
4045
4054
|
*/
|
|
4046
|
-
async create(slug, body) {
|
|
4047
|
-
const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body);
|
|
4055
|
+
async create(userId, slug, body) {
|
|
4056
|
+
const parsedBody = TriggerInstanceUpsertParamsSchema.safeParse(body ?? {});
|
|
4048
4057
|
if (!parsedBody.success) {
|
|
4049
4058
|
throw new ValidationError(`Invalid parameters passed to create trigger`, {
|
|
4050
4059
|
cause: parsedBody.error
|
|
4051
4060
|
});
|
|
4052
4061
|
}
|
|
4062
|
+
let triggerType;
|
|
4063
|
+
let toolkitSlug;
|
|
4064
|
+
try {
|
|
4065
|
+
triggerType = await this.getType(slug);
|
|
4066
|
+
toolkitSlug = triggerType.toolkit.slug;
|
|
4067
|
+
} catch (error) {
|
|
4068
|
+
if (error instanceof APIError && (error.status === 400 || error.status === 404)) {
|
|
4069
|
+
throw new ComposioTriggerTypeNotFoundError(`Trigger type ${slug} not found`, {
|
|
4070
|
+
cause: error,
|
|
4071
|
+
possibleFixes: [
|
|
4072
|
+
`Please check the trigger slug`,
|
|
4073
|
+
`Visit the toolkit page to see the available triggers`
|
|
4074
|
+
]
|
|
4075
|
+
});
|
|
4076
|
+
} else {
|
|
4077
|
+
throw error;
|
|
4078
|
+
}
|
|
4079
|
+
}
|
|
4080
|
+
let connectedAccountId = body?.connectedAccountId;
|
|
4081
|
+
try {
|
|
4082
|
+
const { items: connectedAccounts } = await this.client.connectedAccounts.list({
|
|
4083
|
+
user_ids: [userId],
|
|
4084
|
+
toolkit_slugs: [toolkitSlug]
|
|
4085
|
+
});
|
|
4086
|
+
if (connectedAccounts.length === 0) {
|
|
4087
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
4088
|
+
`No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
|
|
4089
|
+
{
|
|
4090
|
+
cause: new Error(`No connected account found for user ${userId}`),
|
|
4091
|
+
possibleFixes: [`Create a new connected account for user ${userId}`]
|
|
4092
|
+
}
|
|
4093
|
+
);
|
|
4094
|
+
}
|
|
4095
|
+
const accountExists = connectedAccounts.some((acc) => acc.id === connectedAccountId);
|
|
4096
|
+
if (connectedAccountId && !accountExists) {
|
|
4097
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
4098
|
+
`Connected account ID ${connectedAccountId} not found for user ${userId}`,
|
|
4099
|
+
{
|
|
4100
|
+
cause: new Error(
|
|
4101
|
+
`Connected account ID ${connectedAccountId} not found for user ${userId}`
|
|
4102
|
+
),
|
|
4103
|
+
possibleFixes: [
|
|
4104
|
+
`Create a new connected account for user ${userId}`,
|
|
4105
|
+
`Verify the connected account ID`
|
|
4106
|
+
]
|
|
4107
|
+
}
|
|
4108
|
+
);
|
|
4109
|
+
}
|
|
4110
|
+
if (!connectedAccountId) {
|
|
4111
|
+
connectedAccountId = connectedAccounts[0].id;
|
|
4112
|
+
logger_default.warn(
|
|
4113
|
+
`[Warn] Multiple connected accounts found for user ${userId}, using the first one. Pass connectedAccountId to select a specific account.`
|
|
4114
|
+
);
|
|
4115
|
+
}
|
|
4116
|
+
} catch (error) {
|
|
4117
|
+
if (error instanceof APIError && [400, 404].includes(error.status)) {
|
|
4118
|
+
throw new ComposioConnectedAccountNotFoundError(
|
|
4119
|
+
`No connected account found for user ${userId} for toolkit ${toolkitSlug}`,
|
|
4120
|
+
{
|
|
4121
|
+
cause: error,
|
|
4122
|
+
possibleFixes: [`Create a new connected account for user ${userId}`]
|
|
4123
|
+
}
|
|
4124
|
+
);
|
|
4125
|
+
}
|
|
4126
|
+
throw error;
|
|
4127
|
+
}
|
|
4053
4128
|
const result = await this.client.triggerInstances.upsert(slug, {
|
|
4054
|
-
connected_account_id:
|
|
4129
|
+
connected_account_id: connectedAccountId,
|
|
4055
4130
|
trigger_config: parsedBody.data.triggerConfig
|
|
4056
4131
|
});
|
|
4057
4132
|
const parsedResult = TriggerInstanceUpsertResponseSchema.safeParse({
|
|
@@ -4147,6 +4222,54 @@ var Triggers = class {
|
|
|
4147
4222
|
async listEnum() {
|
|
4148
4223
|
return this.client.triggersTypes.retrieveEnum();
|
|
4149
4224
|
}
|
|
4225
|
+
/**
|
|
4226
|
+
* Applies compound filters to the trigger data
|
|
4227
|
+
* @param data data to apply filters to
|
|
4228
|
+
* @returns True if the trigger data matches the filters, false otherwise
|
|
4229
|
+
*/
|
|
4230
|
+
shouldSendTriggerAfterFilters(filters, data) {
|
|
4231
|
+
if (filters.toolkits?.length && !filters.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
|
|
4232
|
+
logger_default.debug(
|
|
4233
|
+
"Trigger does not match toolkits filter",
|
|
4234
|
+
JSON.stringify(filters.toolkits, null, 2)
|
|
4235
|
+
);
|
|
4236
|
+
return false;
|
|
4237
|
+
}
|
|
4238
|
+
if (filters.triggerId && filters.triggerId !== data.id) {
|
|
4239
|
+
logger_default.debug(
|
|
4240
|
+
"Trigger does not match triggerId filter",
|
|
4241
|
+
JSON.stringify(filters.triggerId, null, 2)
|
|
4242
|
+
);
|
|
4243
|
+
return false;
|
|
4244
|
+
}
|
|
4245
|
+
if (filters.connectedAccountId && filters.connectedAccountId !== data.metadata.connectedAccount.id) {
|
|
4246
|
+
logger_default.debug(
|
|
4247
|
+
"Trigger does not match connectedAccountId filter",
|
|
4248
|
+
JSON.stringify(filters.connectedAccountId, null, 2)
|
|
4249
|
+
);
|
|
4250
|
+
return false;
|
|
4251
|
+
}
|
|
4252
|
+
if (filters.triggerSlug?.length && !filters.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
|
|
4253
|
+
logger_default.debug(
|
|
4254
|
+
"Trigger does not match triggerSlug filter",
|
|
4255
|
+
JSON.stringify(filters.triggerSlug, null, 2)
|
|
4256
|
+
);
|
|
4257
|
+
return false;
|
|
4258
|
+
}
|
|
4259
|
+
if (filters.triggerData && filters.triggerData !== data.metadata.triggerData) {
|
|
4260
|
+
logger_default.debug(
|
|
4261
|
+
"Trigger does not match triggerData filter",
|
|
4262
|
+
JSON.stringify(filters.triggerData, null, 2)
|
|
4263
|
+
);
|
|
4264
|
+
return false;
|
|
4265
|
+
}
|
|
4266
|
+
if (filters.userId && filters.userId !== data.metadata.connectedAccount.userId) {
|
|
4267
|
+
logger_default.debug("Trigger does not match userId filter", JSON.stringify(filters.userId, null, 2));
|
|
4268
|
+
return false;
|
|
4269
|
+
}
|
|
4270
|
+
logger_default.debug("Trigger matches all filters", JSON.stringify(filters, null, 2));
|
|
4271
|
+
return true;
|
|
4272
|
+
}
|
|
4150
4273
|
/**
|
|
4151
4274
|
* Subscribe to all the triggers
|
|
4152
4275
|
*
|
|
@@ -4169,65 +4292,21 @@ var Triggers = class {
|
|
|
4169
4292
|
cause: parsedFilters.error
|
|
4170
4293
|
});
|
|
4171
4294
|
}
|
|
4172
|
-
const shouldSendTriggerAfterFilters = (data) => {
|
|
4173
|
-
if (parsedFilters.data.toolkits?.length && !parsedFilters.data.toolkits.map((toolkit) => toolkit.toLowerCase()).includes(data.toolkitSlug.toLowerCase())) {
|
|
4174
|
-
logger_default.debug(
|
|
4175
|
-
"Trigger does not match toolkits filter",
|
|
4176
|
-
JSON.stringify(parsedFilters.data.toolkits, null, 2)
|
|
4177
|
-
);
|
|
4178
|
-
return false;
|
|
4179
|
-
}
|
|
4180
|
-
if (parsedFilters.data.triggerId && parsedFilters.data.triggerId !== data.id) {
|
|
4181
|
-
logger_default.debug(
|
|
4182
|
-
"Trigger does not match triggerId filter",
|
|
4183
|
-
JSON.stringify(parsedFilters.data.triggerId, null, 2)
|
|
4184
|
-
);
|
|
4185
|
-
return false;
|
|
4186
|
-
}
|
|
4187
|
-
if (parsedFilters.data.connectedAccountId && parsedFilters.data.connectedAccountId !== data.metadata.connectedAccount.id) {
|
|
4188
|
-
logger_default.debug(
|
|
4189
|
-
"Trigger does not match connectedAccountId filter",
|
|
4190
|
-
JSON.stringify(parsedFilters.data.connectedAccountId, null, 2)
|
|
4191
|
-
);
|
|
4192
|
-
return false;
|
|
4193
|
-
}
|
|
4194
|
-
if (parsedFilters.data.triggerSlug?.length && !parsedFilters.data.triggerSlug.map((triggerSlug) => triggerSlug.toLowerCase()).includes(data.triggerSlug.toLowerCase())) {
|
|
4195
|
-
logger_default.debug(
|
|
4196
|
-
"Trigger does not match triggerSlug filter",
|
|
4197
|
-
JSON.stringify(parsedFilters.data.triggerSlug, null, 2)
|
|
4198
|
-
);
|
|
4199
|
-
return false;
|
|
4200
|
-
}
|
|
4201
|
-
if (parsedFilters.data.triggerData && parsedFilters.data.triggerData !== data.metadata.triggerData) {
|
|
4202
|
-
logger_default.debug(
|
|
4203
|
-
"Trigger does not match triggerData filter",
|
|
4204
|
-
JSON.stringify(parsedFilters.data.triggerData, null, 2)
|
|
4205
|
-
);
|
|
4206
|
-
return false;
|
|
4207
|
-
}
|
|
4208
|
-
if (parsedFilters.data.userId && parsedFilters.data.userId !== data.metadata.connectedAccount.userId) {
|
|
4209
|
-
logger_default.debug(
|
|
4210
|
-
"Trigger does not match userId filter",
|
|
4211
|
-
JSON.stringify(parsedFilters.data.userId, null, 2)
|
|
4212
|
-
);
|
|
4213
|
-
return false;
|
|
4214
|
-
}
|
|
4215
|
-
logger_default.debug("Trigger matches all filters", JSON.stringify(parsedFilters.data, null, 2));
|
|
4216
|
-
return true;
|
|
4217
|
-
};
|
|
4218
4295
|
logger_default.debug("\u{1F504} Subscribing to triggers with filters: ", JSON.stringify(filters, null, 2));
|
|
4219
4296
|
await this.pusherService.subscribe((_data) => {
|
|
4220
4297
|
logger_default.debug("Received raw trigger data", JSON.stringify(_data, null, 2));
|
|
4221
4298
|
const data = _data;
|
|
4222
4299
|
const parsedData = IncomingTriggerPayloadSchema.safeParse({
|
|
4223
|
-
id: data.metadata.
|
|
4300
|
+
id: data.metadata.nanoId,
|
|
4301
|
+
uuid: data.metadata.id,
|
|
4224
4302
|
triggerSlug: data.metadata.triggerName,
|
|
4225
4303
|
toolkitSlug: data.appName,
|
|
4226
4304
|
userId: data.metadata.connection?.clientUniqueUserId,
|
|
4227
4305
|
payload: data.payload,
|
|
4228
4306
|
originalPayload: data.originalPayload,
|
|
4229
4307
|
metadata: {
|
|
4230
|
-
id: data.metadata.
|
|
4308
|
+
id: data.metadata.nanoId,
|
|
4309
|
+
uuid: data.metadata.id,
|
|
4231
4310
|
triggerConfig: data.metadata.triggerConfig,
|
|
4232
4311
|
triggerSlug: data.metadata.triggerName,
|
|
4233
4312
|
toolkitSlug: data.appName,
|
|
@@ -4248,7 +4327,7 @@ var Triggers = class {
|
|
|
4248
4327
|
cause: parsedData.error
|
|
4249
4328
|
});
|
|
4250
4329
|
}
|
|
4251
|
-
if (shouldSendTriggerAfterFilters(parsedData.data)) {
|
|
4330
|
+
if (this.shouldSendTriggerAfterFilters(parsedFilters.data, parsedData.data)) {
|
|
4252
4331
|
try {
|
|
4253
4332
|
fn(parsedData.data);
|
|
4254
4333
|
} catch (error) {
|
|
@@ -4800,7 +4879,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
4800
4879
|
};
|
|
4801
4880
|
|
|
4802
4881
|
// package.json
|
|
4803
|
-
var version = "0.1.
|
|
4882
|
+
var version = "0.1.23";
|
|
4804
4883
|
|
|
4805
4884
|
// src/composio.ts
|
|
4806
4885
|
var Composio = class _Composio {
|
|
@@ -4864,7 +4943,7 @@ var Composio = class _Composio {
|
|
|
4864
4943
|
if (IS_DEVELOPMENT_OR_CI) {
|
|
4865
4944
|
logger_default.debug(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
|
|
4866
4945
|
}
|
|
4867
|
-
this.client = new
|
|
4946
|
+
this.client = new ComposioClient4({
|
|
4868
4947
|
apiKey: apiKeyParsed,
|
|
4869
4948
|
baseURL: baseURLParsed,
|
|
4870
4949
|
defaultHeaders: config?.defaultHeaders,
|
|
@@ -4963,6 +5042,38 @@ var ComposioProvider = class extends BaseNonAgenticProvider {
|
|
|
4963
5042
|
}
|
|
4964
5043
|
};
|
|
4965
5044
|
|
|
5045
|
+
// src/utils/jsonSchema.ts
|
|
5046
|
+
import { jsonSchemaToZod } from "@composio/json-schema-to-zod";
|
|
5047
|
+
var removeNonRequiredProperties = (schema) => {
|
|
5048
|
+
if (schema && schema.type === "object" && schema.required?.length) {
|
|
5049
|
+
schema.properties = Object.fromEntries(
|
|
5050
|
+
Object.entries(schema.properties || {}).filter(
|
|
5051
|
+
([key]) => schema.required.includes(key)
|
|
5052
|
+
)
|
|
5053
|
+
);
|
|
5054
|
+
}
|
|
5055
|
+
schema.additionalProperties = false;
|
|
5056
|
+
return schema;
|
|
5057
|
+
};
|
|
5058
|
+
function jsonSchemaToZodSchema(jsonSchema, { strict } = {
|
|
5059
|
+
strict: false
|
|
5060
|
+
}) {
|
|
5061
|
+
try {
|
|
5062
|
+
let schema = jsonSchema;
|
|
5063
|
+
if (strict && schema) {
|
|
5064
|
+
schema = removeNonRequiredProperties(
|
|
5065
|
+
schema
|
|
5066
|
+
);
|
|
5067
|
+
}
|
|
5068
|
+
const zodSchema = jsonSchemaToZod(schema);
|
|
5069
|
+
return zodSchema;
|
|
5070
|
+
} catch (error) {
|
|
5071
|
+
throw new JsonSchemaToZodError("Failed to convert JSON Schema to Zod Schema", {
|
|
5072
|
+
cause: error
|
|
5073
|
+
});
|
|
5074
|
+
}
|
|
5075
|
+
}
|
|
5076
|
+
|
|
4966
5077
|
// src/models/AuthScheme.ts
|
|
4967
5078
|
var AuthScheme = class {
|
|
4968
5079
|
/**
|
|
@@ -5154,6 +5265,7 @@ export {
|
|
|
5154
5265
|
ComposioInvalidExecuteFunctionError,
|
|
5155
5266
|
ComposioInvalidModifierError,
|
|
5156
5267
|
ComposioLinkConnectionDataSchema,
|
|
5268
|
+
ComposioMultipleConnectedAccountsError,
|
|
5157
5269
|
ComposioNoAPIKeyError,
|
|
5158
5270
|
ComposioProvider,
|
|
5159
5271
|
ComposioProviderNotDefinedError,
|
|
@@ -5227,5 +5339,6 @@ export {
|
|
|
5227
5339
|
ValidationError,
|
|
5228
5340
|
ValidationErrorCodes,
|
|
5229
5341
|
jsonSchemaToZodSchema,
|
|
5230
|
-
logger_default as logger
|
|
5342
|
+
logger_default as logger,
|
|
5343
|
+
removeNonRequiredProperties
|
|
5231
5344
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composio/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"tsx": "^4.19.3",
|
|
28
28
|
"typescript": "^5.8.3",
|
|
29
29
|
"vitest": "^3.1.4",
|
|
30
|
-
"@composio/json-schema-to-zod": "0.1.
|
|
30
|
+
"@composio/json-schema-to-zod": "0.1.9"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@composio/client": "0.1.0-alpha.
|
|
33
|
+
"@composio/client": "0.1.0-alpha.23",
|
|
34
34
|
"@composio/json-schema-to-zod": "0.1.9",
|
|
35
35
|
"chalk": "^5.4.1",
|
|
36
36
|
"openai": "^4.94.0",
|