@composio/core 0.19.0 → 0.21.0
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-BMlZfJVz.mjs → CustomTool-B-_VjWpy.mjs} +1 -1
- package/dist/{CustomTool-CB5vm1Jc.d.mts → CustomTool-BHOYxLZX.d.mts} +1 -1
- package/dist/{FileModifierErrors-BqFmpRsm.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
- package/dist/{SsrfErrors-C91YhASE.mjs → SsrfErrors-DiQldIdC.mjs} +18 -7
- package/dist/{Telemetry-HlftxMx6.mjs → Telemetry-JRJJYS4I.mjs} +2 -2
- package/dist/{cancellation-CXpfmiVo.mjs → cancellation-DV8CIi52.mjs} +2 -2
- package/dist/{composio-DLGaeN70.d.mts → composio-BTZsFajb.d.mts} +3149 -117
- package/dist/{customTool.types-BAmEh3MB.d.mts → customTool.types-D_w21L56.d.mts} +784 -56
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +7 -3
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +101 -18
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +123 -0
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +9 -2
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +8 -0
- package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +56 -0
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +78 -0
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +15 -15
- package/dist/docs/reference/sdk-reference/typescript/meta.json +9 -1
- package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +83 -0
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +86 -27
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +26 -6
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +149 -12
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +18 -18
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +25 -25
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +78 -0
- package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +162 -0
- package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +218 -0
- package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +20 -0
- package/dist/{errors-BuEKehbI.mjs → errors-Dyiu3ifQ.mjs} +127 -4
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-L7XD8UPr.mjs → fileUtils.node-DNLhLg0W.mjs} +4 -4
- package/dist/index.d.mts +281 -55
- package/dist/index.mjs +3552 -949
- package/dist/models/Files.node.mjs +2 -2
- package/dist/{sensitiveFileUploadPaths-B6pBt9lO.mjs → sensitiveFileUploadPaths-BlLp-Yo2.mjs} +1 -1
- package/dist/{ssrfGuard.node-B9xQB4za.mjs → ssrfGuard.node-BZ270bcu.mjs} +1 -1
- package/dist/{types-CxLPO0Xq.d.mts → types-CgRsUGqm.d.mts} +2 -2
- package/dist/utils/config-defaults/ConfigDefaults.node.d.mts +1 -1
- package/dist/utils/config-defaults/ConfigDefaults.workerd.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.d.mts +1 -1
- package/dist/utils/modifiers/FileToolModifier.node.mjs +5 -5
- package/dist/utils/modifiers/FileToolModifier.workerd.d.mts +1 -1
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.mjs +1 -1
- package/package.json +4 -2
- package/src/composio.ts +215 -10
- package/src/errors/ConnectedAccountsErrors.ts +47 -0
- package/src/errors/SDKErrors.ts +52 -0
- package/src/errors/ToolRouterErrors.ts +61 -0
- package/src/errors/index.ts +3 -0
- package/src/index.ts +13 -0
- package/src/lib/sessionConfigConflict.ts +43 -0
- package/src/lib/toolRouterMcp.ts +132 -0
- package/src/lib/toolRouterParams.ts +149 -37
- package/src/lib/toolRouterSourceSessionConfig.ts +12 -0
- package/src/models/ConnectedAccounts.ts +118 -2
- 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 +25 -8
- package/src/models/SessionConfigs.ts +117 -0
- package/src/models/ToolRouter.ts +61 -17
- package/src/models/ToolRouterSession.ts +149 -14
- package/src/models/Toolkits.ts +180 -0
- package/src/models/Tools.ts +10 -6
- package/src/models/Triggers.ts +3 -88
- package/src/models/Usage.ts +119 -0
- package/src/models/Webhooks.ts +520 -0
- package/src/services/pusher/Pusher.ts +17 -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/sessionConfigs.types.ts +81 -0
- package/src/types/tool.types.ts +2 -0
- package/src/types/toolRouter.types.ts +352 -16
- package/src/types/toolkit.types.ts +144 -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/logger.ts +39 -7
- package/src/utils/safePath.ts +172 -0
- package/src/utils/sdk.ts +385 -22
- 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/sessionConfigs.ts +54 -0
- package/src/utils/transformers/toolRouterResponseTransform.ts +6 -0
- package/src/utils/transformers/toolkits.ts +106 -3
- 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/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
|
|
@@ -215,7 +157,7 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
215
157
|
|
|
216
158
|
constructor(client: ComposioClient, config?: ComposioConfig<TProvider>) {
|
|
217
159
|
this.client = client;
|
|
218
|
-
this.pusherService = new PusherService(client);
|
|
160
|
+
this.pusherService = new PusherService(client, { defaultHeaders: config?.defaultHeaders });
|
|
219
161
|
this.toolkitVersions = config?.toolkitVersions ?? CONFIG_DEFAULTS.toolkitVersions;
|
|
220
162
|
telemetry.instrument(this, 'Triggers');
|
|
221
163
|
}
|
|
@@ -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
|
/**
|
|
@@ -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
|
+
}
|