@composio/core 1.0.0-beta.0 → 1.0.0-beta.1
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/{CustomTool-l-j5HtEf.mjs → CustomTool-CM-roKk7.mjs} +16 -6
- package/dist/{CustomTool-CwpeQhz2.d.mts → CustomTool-yMQjEyMz.d.mts} +1 -1
- package/dist/{FileModifierErrors-B8V8_3VE.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
- package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
- package/dist/{SsrfErrors-DNJt57GL.mjs → SsrfErrors-DiQldIdC.mjs} +154 -19
- package/dist/{Telemetry-DK1uAWnD.mjs → Telemetry-JRJJYS4I.mjs} +28 -44
- package/dist/cancellation-BEpFk2S8.mjs +706 -0
- package/dist/{composio-XjF7EMEe.d.mts → composio-BVNJTVYa.d.mts} +2450 -119
- package/dist/{customTool.types-DpJbYY5m.d.mts → customTool.types-CY5SXFfF.d.mts} +143 -28
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +1 -1
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +4 -3
- package/dist/{errors-BcEUHZbq.mjs → errors-CvZjP9CH.mjs} +42 -4
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-BwpUOF0s.mjs → fileUtils.node-HQsywtTj.mjs} +11 -9
- package/dist/index.d.mts +393 -142
- package/dist/index.mjs +1945 -171
- package/dist/models/Files.node.d.mts +2 -3
- package/dist/models/Files.node.mjs +2 -2
- package/dist/models/Files.workerd.d.mts +2 -3
- package/dist/platform/node.d.mts +2 -3
- package/dist/platform/workerd.d.mts +2 -3
- package/dist/{sensitiveFileUploadPaths-B0w8dqpv.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +10 -7
- package/dist/{ssrfGuard.node-DlxO8uzr.mjs → ssrfGuard.node-BK50mYTq.mjs} +187 -24
- package/dist/{types-C9kJAurw.d.mts → types-CqGfjlZg.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +3 -4
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.node.mjs +6 -6
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +3 -4
- package/dist/utils/modifiers/FileToolModifier.workerd.mjs +1 -1
- package/dist/utils/ssrfGuard.node.d.mts +7 -7
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.d.mts +3 -4
- package/dist/utils/ssrfGuard.workerd.mjs +2 -2
- package/package.json +25 -7
- package/src/composio.ts +86 -2
- package/src/errors/ConnectedAccountsErrors.ts +47 -0
- package/src/errors/ToolErrors.ts +1 -0
- package/src/errors/ValidationErrors.ts +2 -0
- package/src/index.ts +21 -0
- package/src/models/ConnectedAccounts.ts +118 -2
- package/src/models/CustomTool.ts +41 -6
- package/src/models/CustomToolkits.ts +169 -0
- package/src/models/Experimental.ts +27 -0
- package/src/models/Keyring.ts +65 -0
- package/src/models/Logs.ts +101 -0
- package/src/models/RemoteFile.ts +54 -36
- package/src/models/ToolRouterSession.ts +60 -4
- package/src/models/Toolkits.ts +180 -0
- package/src/models/Tools.ts +3 -1
- package/src/models/Triggers.ts +17 -87
- package/src/models/Usage.ts +119 -0
- package/src/models/Webhooks.ts +520 -0
- package/src/services/telemetry/TelemetryService.ts +27 -12
- package/src/telemetry/redact.ts +133 -6
- package/src/types/authConfigs.types.ts +2 -0
- package/src/types/connectedAccounts.types.ts +54 -0
- package/src/types/customToolkits.types.ts +102 -0
- package/src/types/keyring.types.ts +32 -0
- package/src/types/logs.types.ts +108 -0
- package/src/types/toolRouter.types.ts +49 -1
- package/src/types/toolkit.types.ts +131 -0
- package/src/types/usage.types.ts +81 -0
- package/src/types/webhooks.types.ts +143 -0
- package/src/utils/constants.ts +1 -5
- package/src/utils/fileUtils.node.ts +10 -2
- package/src/utils/jsonSchema.ts +509 -28
- package/src/utils/logger.ts +45 -13
- package/src/utils/pinnedDispatcher.node.ts +109 -13
- package/src/utils/sdk.ts +1 -1
- package/src/utils/ssrfGuard.node.ts +124 -21
- package/src/utils/ssrfGuard.workerd.ts +5 -1
- package/src/utils/transformers/connectedAccounts.ts +37 -2
- package/src/utils/transformers/customToolkits.ts +98 -0
- package/src/utils/transformers/keyring.ts +24 -0
- package/src/utils/transformers/logs.ts +85 -0
- package/src/utils/transformers/toolkits.ts +100 -1
- package/src/utils/transformers/triggers.ts +2 -2
- package/src/utils/transformers/usage.ts +77 -0
- package/src/utils/transformers/webhooks.ts +139 -0
- package/dist/cancellation-C-qy8rcj.mjs +0 -364
package/src/models/Toolkits.ts
CHANGED
|
@@ -6,6 +6,16 @@ import {
|
|
|
6
6
|
ToolkitsListParamsSchema,
|
|
7
7
|
ToolkitRetrieveCategoriesResponse,
|
|
8
8
|
ToolkitAuthFieldsResponse,
|
|
9
|
+
ToolkitGetManyParams,
|
|
10
|
+
ToolkitGetManySlugsSchema,
|
|
11
|
+
ToolkitsGetManyParamsSchema,
|
|
12
|
+
ToolkitChangelogResponse,
|
|
13
|
+
ToolkitRecommendScopesParams,
|
|
14
|
+
ToolkitRecommendScopesParamsSchema,
|
|
15
|
+
ToolkitRecommendScopesResponse,
|
|
16
|
+
ToolkitListGrantContextsParams,
|
|
17
|
+
ToolkitListGrantContextsParamsSchema,
|
|
18
|
+
ToolkitListGrantContextsResponse,
|
|
9
19
|
} from '../types/toolkit.types';
|
|
10
20
|
import { ComposioToolkitFetchError, ComposioToolkitNotFoundError } from '../errors';
|
|
11
21
|
import { ValidationError } from '../errors/ValidationErrors';
|
|
@@ -18,7 +28,12 @@ import { AuthSchemeType } from '../types/authConfigs.types';
|
|
|
18
28
|
import logger from '../utils/logger';
|
|
19
29
|
import { APIError } from 'openai';
|
|
20
30
|
import {
|
|
31
|
+
transformToolkitChangelogResponse,
|
|
32
|
+
transformToolkitListGrantContextsParams,
|
|
33
|
+
transformToolkitListGrantContextsResponse,
|
|
21
34
|
transformToolkitListResponse,
|
|
35
|
+
transformToolkitRecommendScopesParams,
|
|
36
|
+
transformToolkitRecommendScopesResponse,
|
|
22
37
|
transformToolkitRetrieveCategoriesResponse,
|
|
23
38
|
transformToolkitRetrieveResponse,
|
|
24
39
|
} from '../utils/transformers/toolkits';
|
|
@@ -191,6 +206,171 @@ export class Toolkits {
|
|
|
191
206
|
return this.getToolkits(arg ?? {}, requestOptions);
|
|
192
207
|
}
|
|
193
208
|
|
|
209
|
+
/**
|
|
210
|
+
* Retrieves several toolkits by slug in a single request.
|
|
211
|
+
*
|
|
212
|
+
* Returns the same transformed shape as `composio.toolkits.get({ ... })`.
|
|
213
|
+
* Unknown slugs are simply absent from the result.
|
|
214
|
+
*
|
|
215
|
+
* @param {string[]} slugs - The toolkit slugs to retrieve (at least one)
|
|
216
|
+
* @param {ToolkitGetManyParams} [params] - Optional filters and pagination, as for `list`
|
|
217
|
+
* @returns {Promise<ToolKitListResponse>} The matching toolkits
|
|
218
|
+
* @throws {ValidationError} If `slugs` is empty or the params fail validation
|
|
219
|
+
* @throws {ComposioToolkitFetchError} If the request fails
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const toolkits = await composio.toolkits.getMany(['github', 'slack']);
|
|
224
|
+
* console.log(toolkits.map(toolkit => toolkit.name)); // ['GitHub', 'Slack']
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
async getMany(
|
|
228
|
+
slugs: string[],
|
|
229
|
+
params?: ToolkitGetManyParams,
|
|
230
|
+
requestOptions?: ComposioRequestOptions
|
|
231
|
+
): Promise<ToolKitListResponse> {
|
|
232
|
+
const parsedSlugs = ToolkitGetManySlugsSchema.safeParse(slugs);
|
|
233
|
+
if (!parsedSlugs.success) {
|
|
234
|
+
throw new ValidationError('Failed to parse toolkit slugs', {
|
|
235
|
+
cause: parsedSlugs.error,
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
const parsedParams = ToolkitsGetManyParamsSchema.safeParse(params ?? {});
|
|
239
|
+
if (!parsedParams.success) {
|
|
240
|
+
throw new ValidationError('Failed to parse toolkit getMany params', {
|
|
241
|
+
cause: parsedParams.error,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
const body = {
|
|
245
|
+
toolkits: parsedSlugs.data,
|
|
246
|
+
category: parsedParams.data.category,
|
|
247
|
+
managed_by: parsedParams.data.managedBy,
|
|
248
|
+
sort_by: parsedParams.data.sortBy,
|
|
249
|
+
cursor: parsedParams.data.cursor,
|
|
250
|
+
limit: parsedParams.data.limit,
|
|
251
|
+
};
|
|
252
|
+
try {
|
|
253
|
+
const result = await withCancellation(
|
|
254
|
+
() => this.client.toolkits.retrieveMulti(body, requestOptions),
|
|
255
|
+
requestOptions?.signal
|
|
256
|
+
);
|
|
257
|
+
return transformToolkitListResponse(result);
|
|
258
|
+
} catch (error) {
|
|
259
|
+
if (error instanceof ComposioRequestCancelledError) {
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
throw new ComposioToolkitFetchError('Failed to fetch toolkits', {
|
|
263
|
+
meta: { slugs: parsedSlugs.data },
|
|
264
|
+
cause: error,
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Retrieves the version changelog of every toolkit (the last 10 versions
|
|
271
|
+
* per toolkit).
|
|
272
|
+
*
|
|
273
|
+
* @returns {Promise<ToolkitChangelogResponse>} Toolkits with their recent version changelogs
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```typescript
|
|
277
|
+
* const { items } = await composio.toolkits.changelog();
|
|
278
|
+
* const github = items.find(item => item.slug === 'github');
|
|
279
|
+
* console.log(github?.versions[0]); // { version: '20250909_00', changelog: '...' }
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
async changelog(requestOptions?: ComposioRequestOptions): Promise<ToolkitChangelogResponse> {
|
|
283
|
+
const result = await withCancellation(
|
|
284
|
+
() => this.client.toolkits.retrieveChangelog(requestOptions),
|
|
285
|
+
requestOptions?.signal
|
|
286
|
+
);
|
|
287
|
+
return transformToolkitChangelogResponse(result);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Recommends the OAuth scopes to request so a connection can run the given
|
|
292
|
+
* tools.
|
|
293
|
+
* **Experimental — the API marks this endpoint beta; shape may change.**
|
|
294
|
+
*
|
|
295
|
+
* The answer comes in two variants: `leastPrivilege` (narrowest documented
|
|
296
|
+
* scope per requirement) and `fewest` (smallest set covering everything).
|
|
297
|
+
* Pass `toolkitVersion` from a previous answer to pin the computation.
|
|
298
|
+
*
|
|
299
|
+
* @param {string} toolkitSlug - The toolkit to recommend scopes for
|
|
300
|
+
* @param {ToolkitRecommendScopesParams} params - Tools to cover (`[]` for the whole toolkit), auth scheme, grant context and scope constraints
|
|
301
|
+
* @returns {Promise<ToolkitRecommendScopesResponse>} The recommended scope sets
|
|
302
|
+
* @throws {ValidationError} If the params fail validation
|
|
303
|
+
*
|
|
304
|
+
* @example
|
|
305
|
+
* ```typescript
|
|
306
|
+
* const { scopes } = await composio.toolkits.recommendScopes('gmail', {
|
|
307
|
+
* tools: ['GMAIL_SEND_EMAIL', 'GMAIL_FETCH_EMAILS'],
|
|
308
|
+
* });
|
|
309
|
+
* console.log(scopes.leastPrivilege);
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
async recommendScopes(
|
|
313
|
+
toolkitSlug: string,
|
|
314
|
+
params: ToolkitRecommendScopesParams,
|
|
315
|
+
requestOptions?: ComposioRequestOptions
|
|
316
|
+
): Promise<ToolkitRecommendScopesResponse> {
|
|
317
|
+
const parsedParams = ToolkitRecommendScopesParamsSchema.safeParse(params);
|
|
318
|
+
if (!parsedParams.success) {
|
|
319
|
+
throw new ValidationError('Failed to parse toolkit recommendScopes params', {
|
|
320
|
+
cause: parsedParams.error,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
const body = transformToolkitRecommendScopesParams(parsedParams.data);
|
|
324
|
+
const result = await withCancellation(
|
|
325
|
+
() => this.client.toolkits.recommendScopes(toolkitSlug, body, requestOptions),
|
|
326
|
+
requestOptions?.signal
|
|
327
|
+
);
|
|
328
|
+
return transformToolkitRecommendScopesResponse(result);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Lists the grant-context dimensions a toolkit's scope recommendation
|
|
333
|
+
* depends on (for example the Google account type), with their allowed
|
|
334
|
+
* values and the default the API assumes.
|
|
335
|
+
* **Experimental — the API marks this endpoint beta; shape may change.**
|
|
336
|
+
*
|
|
337
|
+
* Pass a dimension and a value as `grantContext` to
|
|
338
|
+
* `composio.toolkits.recommendScopes()` to tailor the recommendation.
|
|
339
|
+
*
|
|
340
|
+
* @param {string} toolkitSlug - The toolkit to list grant contexts for
|
|
341
|
+
* @param {ToolkitListGrantContextsParams} [params] - Optional auth scheme and toolkit version
|
|
342
|
+
* @returns {Promise<ToolkitListGrantContextsResponse>} The dimensions and the default grant context
|
|
343
|
+
* @throws {ValidationError} If the params fail validation
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```typescript
|
|
347
|
+
* const { grantContextDimensions } = await composio.toolkits.listGrantContexts('gmail');
|
|
348
|
+
* const [accountType] = grantContextDimensions;
|
|
349
|
+
* const { scopes } = await composio.toolkits.recommendScopes('gmail', {
|
|
350
|
+
* tools: ['GMAIL_SEND_EMAIL'],
|
|
351
|
+
* grantContext: { [accountType.dimension]: accountType.values[0] },
|
|
352
|
+
* });
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
async listGrantContexts(
|
|
356
|
+
toolkitSlug: string,
|
|
357
|
+
params?: ToolkitListGrantContextsParams,
|
|
358
|
+
requestOptions?: ComposioRequestOptions
|
|
359
|
+
): Promise<ToolkitListGrantContextsResponse> {
|
|
360
|
+
const parsedParams = ToolkitListGrantContextsParamsSchema.safeParse(params ?? {});
|
|
361
|
+
if (!parsedParams.success) {
|
|
362
|
+
throw new ValidationError('Failed to parse toolkit listGrantContexts params', {
|
|
363
|
+
cause: parsedParams.error,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
const query = transformToolkitListGrantContextsParams(parsedParams.data);
|
|
367
|
+
const result = await withCancellation(
|
|
368
|
+
() => this.client.toolkits.retrieveScopesGrantContext(toolkitSlug, query, requestOptions),
|
|
369
|
+
requestOptions?.signal
|
|
370
|
+
);
|
|
371
|
+
return transformToolkitListGrantContextsResponse(result);
|
|
372
|
+
}
|
|
373
|
+
|
|
194
374
|
private async getAuthConfigFields(
|
|
195
375
|
toolkitSlug: string,
|
|
196
376
|
authScheme: AuthSchemeType | null,
|
package/src/models/Tools.ts
CHANGED
|
@@ -540,7 +540,9 @@ export class Tools<
|
|
|
540
540
|
...(limit ? { limit } : {}),
|
|
541
541
|
...('tags' in queryParams.data ? { tags: queryParams.data.tags } : {}),
|
|
542
542
|
...('scopes' in queryParams.data ? { scopes: queryParams.data.scopes } : {}),
|
|
543
|
-
|
|
543
|
+
// `search` is the SDK's public option; the API deprecated the `search`
|
|
544
|
+
// wire param in favour of `query`, so send the replacement.
|
|
545
|
+
...('search' in queryParams.data ? { query: queryParams.data.search } : {}),
|
|
544
546
|
...('authConfigIds' in queryParams.data
|
|
545
547
|
? { auth_config_ids: queryParams.data.authConfigIds }
|
|
546
548
|
: {}),
|
package/src/models/Triggers.ts
CHANGED
|
@@ -33,11 +33,10 @@ import {
|
|
|
33
33
|
WebhookTriggerPayloadV3Schema,
|
|
34
34
|
WebhookVersion,
|
|
35
35
|
WebhookVersions,
|
|
36
|
-
DefaultWebhookSubscriptionEvents,
|
|
37
36
|
SetWebhookSubscriptionParams,
|
|
38
|
-
SetWebhookSubscriptionParamsSchema,
|
|
39
37
|
WebhookSubscription,
|
|
40
38
|
} from '../types/triggers.types';
|
|
39
|
+
import { upsertWebhookSubscription } from './Webhooks';
|
|
41
40
|
import logger from '../utils/logger';
|
|
42
41
|
import { telemetry } from '../telemetry/Telemetry';
|
|
43
42
|
import { ValidationError } from '../errors';
|
|
@@ -75,63 +74,6 @@ const toStringOrDefault = (value: unknown, defaultValue: string): string => {
|
|
|
75
74
|
return str.length > 0 ? str : defaultValue;
|
|
76
75
|
};
|
|
77
76
|
|
|
78
|
-
const WEBHOOK_SUBSCRIPTIONS_PATH = '/api/v3.1/webhook_subscriptions';
|
|
79
|
-
|
|
80
|
-
type RawWebhookSubscription = Record<string, unknown> & {
|
|
81
|
-
id?: unknown;
|
|
82
|
-
webhook_url?: unknown;
|
|
83
|
-
webhookUrl?: unknown;
|
|
84
|
-
version?: unknown;
|
|
85
|
-
enabled_events?: unknown;
|
|
86
|
-
enabledEvents?: unknown;
|
|
87
|
-
secret?: unknown;
|
|
88
|
-
created_at?: unknown;
|
|
89
|
-
createdAt?: unknown;
|
|
90
|
-
updated_at?: unknown;
|
|
91
|
-
updatedAt?: unknown;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
type RawWebhookSubscriptionListResponse = Record<string, unknown> & {
|
|
95
|
-
items?: unknown;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
const asRecord = (value: unknown): Record<string, unknown> =>
|
|
99
|
-
value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
100
|
-
? (value as Record<string, unknown>)
|
|
101
|
-
: {};
|
|
102
|
-
|
|
103
|
-
const firstString = (value: unknown): string | undefined =>
|
|
104
|
-
typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
105
|
-
|
|
106
|
-
const stringArray = (value: unknown): string[] =>
|
|
107
|
-
Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string') : [];
|
|
108
|
-
|
|
109
|
-
const transformWebhookSubscription = (subscription: unknown): WebhookSubscription => {
|
|
110
|
-
const raw = asRecord(subscription) as RawWebhookSubscription;
|
|
111
|
-
|
|
112
|
-
// Map to camelCase explicitly — do NOT spread `...raw`, or the response's
|
|
113
|
-
// snake_case keys (webhook_url, enabled_events, created_at, ...) leak into the
|
|
114
|
-
// public object alongside their camelCase counterparts.
|
|
115
|
-
return {
|
|
116
|
-
id: firstString(raw.id) ?? '',
|
|
117
|
-
webhookUrl: firstString(raw.webhook_url) ?? firstString(raw.webhookUrl) ?? '',
|
|
118
|
-
version: (firstString(raw.version) ?? WebhookVersions.V3) as WebhookVersion,
|
|
119
|
-
enabledEvents: stringArray(raw.enabled_events).length
|
|
120
|
-
? stringArray(raw.enabled_events)
|
|
121
|
-
: stringArray(raw.enabledEvents),
|
|
122
|
-
secret: firstString(raw.secret),
|
|
123
|
-
createdAt: firstString(raw.created_at) ?? firstString(raw.createdAt),
|
|
124
|
-
updatedAt: firstString(raw.updated_at) ?? firstString(raw.updatedAt),
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const firstWebhookSubscriptionId = (
|
|
129
|
-
response: RawWebhookSubscriptionListResponse
|
|
130
|
-
): string | undefined => {
|
|
131
|
-
const firstItem = Array.isArray(response.items) ? response.items[0] : undefined;
|
|
132
|
-
return firstString(asRecord(firstItem).id);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
77
|
/**
|
|
136
78
|
* The signature header names Composio sends with every webhook delivery.
|
|
137
79
|
* @private
|
|
@@ -234,34 +176,7 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
234
176
|
* ```
|
|
235
177
|
*/
|
|
236
178
|
async setWebhookSubscription(params: SetWebhookSubscriptionParams): Promise<WebhookSubscription> {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
if (!parsedParams.success) {
|
|
240
|
-
throw new ValidationError(`Invalid parameters passed to set webhook subscription`, {
|
|
241
|
-
cause: parsedParams.error,
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const body = {
|
|
246
|
-
webhook_url: parsedParams.data.webhookUrl,
|
|
247
|
-
enabled_events: parsedParams.data.enabledEvents ?? [...DefaultWebhookSubscriptionEvents],
|
|
248
|
-
version: parsedParams.data.version ?? WebhookVersions.V3,
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
const existing = await this.client.get<RawWebhookSubscriptionListResponse>(
|
|
252
|
-
WEBHOOK_SUBSCRIPTIONS_PATH,
|
|
253
|
-
{ query: { limit: 1 } }
|
|
254
|
-
);
|
|
255
|
-
const subscriptionId = firstWebhookSubscriptionId(existing);
|
|
256
|
-
|
|
257
|
-
const subscription = subscriptionId
|
|
258
|
-
? await this.client.patch<RawWebhookSubscription>(
|
|
259
|
-
`${WEBHOOK_SUBSCRIPTIONS_PATH}/${encodeURIComponent(subscriptionId)}`,
|
|
260
|
-
{ body }
|
|
261
|
-
)
|
|
262
|
-
: await this.client.post<RawWebhookSubscription>(WEBHOOK_SUBSCRIPTIONS_PATH, { body });
|
|
263
|
-
|
|
264
|
-
return transformWebhookSubscription(subscription);
|
|
179
|
+
return upsertWebhookSubscription(this.client, params);
|
|
265
180
|
}
|
|
266
181
|
|
|
267
182
|
/**
|
|
@@ -558,6 +473,21 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
558
473
|
return false;
|
|
559
474
|
}
|
|
560
475
|
|
|
476
|
+
// Check if authConfigId filter matches.
|
|
477
|
+
// Only V3 trigger payloads (and the legacy TriggerData shape) carry an auth config id;
|
|
478
|
+
// V1/V2 payloads and non-trigger V3 events normalize it to '', so this filter drops
|
|
479
|
+
// those events entirely. This mirrors the Python SDK's `auth_config_id` filter.
|
|
480
|
+
if (
|
|
481
|
+
filters.authConfigId &&
|
|
482
|
+
filters.authConfigId !== data.metadata.connectedAccount.authConfigId
|
|
483
|
+
) {
|
|
484
|
+
logger.debug(
|
|
485
|
+
'Trigger does not match authConfigId filter',
|
|
486
|
+
JSON.stringify(filters.authConfigId, null, 2)
|
|
487
|
+
);
|
|
488
|
+
return false;
|
|
489
|
+
}
|
|
490
|
+
|
|
561
491
|
// Check if triggerName filter matches
|
|
562
492
|
if (
|
|
563
493
|
filters.triggerSlug?.length &&
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview `composio.experimental.usage`: project-scoped metering.
|
|
3
|
+
* **Experimental — shape may change in future releases.**
|
|
4
|
+
*
|
|
5
|
+
* @module Usage
|
|
6
|
+
*/
|
|
7
|
+
import ComposioClient from '@composio/client';
|
|
8
|
+
import {
|
|
9
|
+
UsageBreakdownParams,
|
|
10
|
+
UsageBreakdownParamsSchema,
|
|
11
|
+
UsageBreakdownResponse,
|
|
12
|
+
UsageSummaryParams,
|
|
13
|
+
UsageSummaryParamsSchema,
|
|
14
|
+
UsageSummaryResponse,
|
|
15
|
+
} from '../types/usage.types';
|
|
16
|
+
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
17
|
+
import { ValidationError } from '../errors/ValidationErrors';
|
|
18
|
+
import { telemetry } from '../telemetry/Telemetry';
|
|
19
|
+
import { withCancellation } from '../utils/cancellation';
|
|
20
|
+
import {
|
|
21
|
+
transformUsageBreakdownParams,
|
|
22
|
+
transformUsageBreakdownResponse,
|
|
23
|
+
transformUsageSummaryParams,
|
|
24
|
+
transformUsageSummaryResponse,
|
|
25
|
+
} from '../utils/transformers/usage';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* `composio.experimental.usage` — metering for the project the API key
|
|
29
|
+
* belongs to. **Experimental — shape may change in future releases.**
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* const summary = await composio.experimental.usage.summary();
|
|
34
|
+
* console.log(summary.entities.tool_calls?.totalQuantity);
|
|
35
|
+
*
|
|
36
|
+
* const byTool = await composio.experimental.usage.breakdown('tool_calls', {
|
|
37
|
+
* groupBy: 'tool_slug',
|
|
38
|
+
* limit: 10,
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export class Usage {
|
|
43
|
+
private client: ComposioClient;
|
|
44
|
+
|
|
45
|
+
constructor(client: ComposioClient) {
|
|
46
|
+
this.client = client;
|
|
47
|
+
telemetry.instrument(this, 'Usage');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Usage totals per metering entity type for a time range.
|
|
52
|
+
* **Experimental — shape may change in future releases.**
|
|
53
|
+
*
|
|
54
|
+
* @param {UsageSummaryParams} [params] - Optional range, `entityTypes` and filters
|
|
55
|
+
* @returns {Promise<UsageSummaryResponse>} Totals keyed by entity type
|
|
56
|
+
* @throws {ValidationError} If the params fail validation
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const summary = await composio.experimental.usage.summary({
|
|
61
|
+
* from: Date.now() - 7 * 24 * 60 * 60 * 1000,
|
|
62
|
+
* filters: { userId: ['user_123'] },
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
async summary(
|
|
67
|
+
params?: UsageSummaryParams,
|
|
68
|
+
requestOptions?: ComposioRequestOptions
|
|
69
|
+
): Promise<UsageSummaryResponse> {
|
|
70
|
+
const parsedParams = UsageSummaryParamsSchema.safeParse(params ?? {});
|
|
71
|
+
if (!parsedParams.success) {
|
|
72
|
+
throw new ValidationError('Failed to parse usage summary params', {
|
|
73
|
+
cause: parsedParams.error,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
const body = transformUsageSummaryParams(parsedParams.data);
|
|
77
|
+
const result = await withCancellation(
|
|
78
|
+
() => this.client.project.usage.retrieveSummary(body, requestOptions),
|
|
79
|
+
requestOptions?.signal
|
|
80
|
+
);
|
|
81
|
+
return transformUsageSummaryResponse(result);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Usage for one metering entity type, grouped by a dimension.
|
|
86
|
+
* **Experimental — shape may change in future releases.**
|
|
87
|
+
*
|
|
88
|
+
* @param {string} entityType - Entity type to break down (e.g. `tool_calls`, `sessions`)
|
|
89
|
+
* @param {UsageBreakdownParams} [params] - Optional range, `groupBy`, ordering, `limit` and filters
|
|
90
|
+
* @returns {Promise<UsageBreakdownResponse>} Totals plus per-group rows
|
|
91
|
+
* @throws {ValidationError} If the params fail validation
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const byUser = await composio.experimental.usage.breakdown('sessions', {
|
|
96
|
+
* groupBy: 'user_id',
|
|
97
|
+
* orderBy: 'event_count',
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
async breakdown(
|
|
102
|
+
entityType: string,
|
|
103
|
+
params?: UsageBreakdownParams,
|
|
104
|
+
requestOptions?: ComposioRequestOptions
|
|
105
|
+
): Promise<UsageBreakdownResponse> {
|
|
106
|
+
const parsedParams = UsageBreakdownParamsSchema.safeParse(params ?? {});
|
|
107
|
+
if (!parsedParams.success) {
|
|
108
|
+
throw new ValidationError('Failed to parse usage breakdown params', {
|
|
109
|
+
cause: parsedParams.error,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
const body = transformUsageBreakdownParams(parsedParams.data);
|
|
113
|
+
const result = await withCancellation(
|
|
114
|
+
() => this.client.project.usage.retrieve(entityType, body, requestOptions),
|
|
115
|
+
requestOptions?.signal
|
|
116
|
+
);
|
|
117
|
+
return transformUsageBreakdownResponse(result);
|
|
118
|
+
}
|
|
119
|
+
}
|