@composio/core 0.31.0 → 0.32.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-9Vlb4XaS.mjs → CustomTool-B4dQn2M5.mjs} +1 -1
- package/dist/{CustomTool-Ds5aLDth.d.mts → CustomTool-CBx9kzea.d.mts} +1 -1
- package/dist/{FileModifierErrors-WrqokuIF.mjs → FileModifierErrors-D-AKc3ds.mjs} +1 -1
- package/dist/{SsrfErrors-BSVMW915.mjs → SsrfErrors-BekZPeWY.mjs} +59 -12
- package/dist/{Telemetry-a7SOQXcg.mjs → Telemetry-BWKZmDxM.mjs} +2 -2
- package/dist/composio-CPf6NHnB.d.mts +20334 -0
- package/dist/{customTool.types-DHxXBU6E.d.mts → customTool.types-BSbIG1OG.d.mts} +291 -68
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +20 -12
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +28 -10
- package/dist/docs/reference/sdk-reference/typescript/connected-accounts.mdx +44 -32
- package/dist/docs/reference/sdk-reference/typescript/custom-toolkits.mdx +8 -6
- package/dist/docs/reference/sdk-reference/typescript/experimental.mdx +4 -3
- package/dist/docs/reference/sdk-reference/typescript/index.mdx +4 -2
- package/dist/docs/reference/sdk-reference/typescript/keyring.mdx +6 -3
- package/dist/docs/reference/sdk-reference/typescript/logs.mdx +5 -3
- package/dist/docs/reference/sdk-reference/typescript/mcp.mdx +53 -42
- package/dist/docs/reference/sdk-reference/typescript/meta.json +1 -0
- package/dist/docs/reference/sdk-reference/typescript/remote-file.mdx +5 -14
- package/dist/docs/reference/sdk-reference/typescript/session-configs.mdx +5 -3
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +7 -5
- package/dist/docs/reference/sdk-reference/typescript/session-webhooks.mdx +64 -0
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +16 -16
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +36 -8
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +14 -11
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +16 -18
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +42 -30
- package/dist/docs/reference/sdk-reference/typescript/usage.mdx +6 -4
- package/dist/docs/reference/sdk-reference/typescript/webhook-endpoints.mdx +9 -7
- package/dist/docs/reference/sdk-reference/typescript/webhook-subscriptions.mdx +13 -9
- package/dist/docs/reference/sdk-reference/typescript/webhooks.mdx +3 -1
- package/dist/{errors-xC13uvaA.mjs → errors-CtIKA9BH.mjs} +2 -2
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-CAwIbWYH.mjs → fileUtils.node-BJUYMEph.mjs} +7 -7
- package/dist/index.d.mts +6 -11
- package/dist/index.mjs +526 -233
- package/dist/{jsonSchema-Cc4EtHRw.mjs → jsonSchema-BZoXGUCr.mjs} +2 -2
- package/dist/models/Files.node.mjs +3 -3
- package/dist/{sensitiveFileUploadPaths-CSyJ3Ku8.mjs → sensitiveFileUploadPaths-CcbMAYCC.mjs} +21 -15
- package/dist/{ssrfGuard.node-CdIkwqVu.mjs → ssrfGuard.node-B749ae5Q.mjs} +1 -1
- package/dist/{types-DcdZy5Nc.d.mts → types-ns3Q_WrP.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 +2 -2
- package/src/composio.ts +26 -7
- package/src/errors/ComposioError.ts +3 -2
- package/src/index.ts +19 -0
- package/src/lib/toolRouterParams.ts +38 -14
- package/src/models/AuthConfigs.ts +10 -3
- package/src/models/ConnectedAccounts.ts +30 -17
- package/src/models/CustomTool.ts +0 -10
- package/src/models/Keyring.ts +2 -1
- package/src/models/MCP.ts +43 -35
- package/src/models/SessionWebhooks.ts +136 -0
- package/src/models/ToolRouter.ts +39 -4
- package/src/models/ToolRouterSession.ts +2 -2
- package/src/models/ToolRouterSessionFileMount.ts +3 -1
- package/src/models/Toolkits.ts +1 -0
- package/src/models/Tools.ts +4 -8
- package/src/models/Triggers.ts +48 -213
- package/src/models/Webhooks.ts +2 -0
- package/src/provider/ComposioProvider.ts +0 -1
- package/src/telemetry/BatchProcessor.ts +1 -1
- package/src/telemetry/Telemetry.ts +1 -1
- package/src/types/connectedAccountAuthStates.types.ts +0 -1
- package/src/types/provider.types.ts +0 -1
- package/src/types/sessionWebhooks.types.ts +292 -0
- package/src/types/toolRouter.types.ts +33 -4
- package/src/types/triggers.types.ts +4 -0
- package/src/utils/crypto.ts +6 -5
- package/src/utils/env.ts +2 -5
- package/src/utils/fileUtils.node.ts +4 -3
- package/src/utils/logger.ts +19 -9
- package/src/utils/pusher.ts +5 -2
- package/src/utils/readResponseBody.ts +30 -17
- package/src/utils/transformers/authConfigs.ts +0 -1
- package/src/utils/userCallback.ts +3 -1
- package/src/utils/webhookVerification.ts +211 -0
- package/dist/composio-Ba89XGHL.d.mts +0 -9736
package/src/models/MCP.ts
CHANGED
|
@@ -83,18 +83,19 @@ export class MCP {
|
|
|
83
83
|
*
|
|
84
84
|
* @example
|
|
85
85
|
* ```typescript
|
|
86
|
-
* const server = await composio.
|
|
86
|
+
* const server = await composio.mcp.create("personal-mcp-server", {
|
|
87
87
|
* toolkits: ["github", "slack"],
|
|
88
|
-
* allowedTools: ["
|
|
88
|
+
* allowedTools: ["GITHUB_CREATE_AN_ISSUE", "SLACK_SEND_MESSAGE"],
|
|
89
89
|
* manuallyManageConnections: false
|
|
90
|
-
* }
|
|
91
90
|
* });
|
|
91
|
+
* ```
|
|
92
92
|
*
|
|
93
|
-
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* const server = await composio.mcp.create("personal-mcp-server", {
|
|
94
96
|
* toolkits: [{ toolkit: "gmail", authConfigId: "ac_243434343" }],
|
|
95
97
|
* allowedTools: ["GMAIL_FETCH_EMAILS"],
|
|
96
98
|
* manuallyManageConnections: false
|
|
97
|
-
* }
|
|
98
99
|
* });
|
|
99
100
|
* ```
|
|
100
101
|
*/
|
|
@@ -174,22 +175,31 @@ export class MCP {
|
|
|
174
175
|
*
|
|
175
176
|
* @example
|
|
176
177
|
* ```typescript
|
|
177
|
-
* // List
|
|
178
|
-
* const allServers = await composio.
|
|
178
|
+
* // List the first page of MCP servers
|
|
179
|
+
* const allServers = await composio.mcp.list({ page: 1, limit: 10, toolkits: [], authConfigs: [] });
|
|
179
180
|
*
|
|
180
181
|
* // List with pagination
|
|
181
|
-
* const pagedServers = await composio.
|
|
182
|
+
* const pagedServers = await composio.mcp.list({
|
|
182
183
|
* page: 2,
|
|
183
|
-
* limit: 5
|
|
184
|
+
* limit: 5,
|
|
185
|
+
* toolkits: [],
|
|
186
|
+
* authConfigs: []
|
|
184
187
|
* });
|
|
185
188
|
*
|
|
186
189
|
* // Filter by toolkit
|
|
187
|
-
* const githubServers = await composio.
|
|
188
|
-
*
|
|
190
|
+
* const githubServers = await composio.mcp.list({
|
|
191
|
+
* page: 1,
|
|
192
|
+
* limit: 10,
|
|
193
|
+
* toolkits: ['github', 'slack'],
|
|
194
|
+
* authConfigs: []
|
|
189
195
|
* });
|
|
190
196
|
*
|
|
191
197
|
* // Filter by name
|
|
192
|
-
* const namedServers = await composio.
|
|
198
|
+
* const namedServers = await composio.mcp.list({
|
|
199
|
+
* page: 1,
|
|
200
|
+
* limit: 10,
|
|
201
|
+
* toolkits: [],
|
|
202
|
+
* authConfigs: [],
|
|
193
203
|
* name: 'personal'
|
|
194
204
|
* });
|
|
195
205
|
* ```
|
|
@@ -246,7 +256,7 @@ export class MCP {
|
|
|
246
256
|
* @example
|
|
247
257
|
* ```typescript
|
|
248
258
|
* // Get a specific MCP server by ID
|
|
249
|
-
* const server = await composio.
|
|
259
|
+
* const server = await composio.mcp.get("mcp_12345");
|
|
250
260
|
*
|
|
251
261
|
* console.log(server.name); // "My Personal MCP Server"
|
|
252
262
|
* console.log(server.allowedTools); // ["GITHUB_CREATE_AN_ISSUE", "SLACK_SEND_MESSAGE"]
|
|
@@ -280,7 +290,7 @@ export class MCP {
|
|
|
280
290
|
* @example
|
|
281
291
|
* ```typescript
|
|
282
292
|
* // Delete an MCP server by ID
|
|
283
|
-
* const result = await composio.
|
|
293
|
+
* const result = await composio.mcp.delete("mcp_12345");
|
|
284
294
|
*
|
|
285
295
|
* if (result.deleted) {
|
|
286
296
|
* console.log(`Server ${result.id} has been successfully deleted`);
|
|
@@ -290,15 +300,15 @@ export class MCP {
|
|
|
290
300
|
*
|
|
291
301
|
* // Example with error handling
|
|
292
302
|
* try {
|
|
293
|
-
* const result = await composio.
|
|
303
|
+
* const result = await composio.mcp.delete("mcp_12345");
|
|
294
304
|
* console.log("Deletion successful:", result);
|
|
295
305
|
* } catch (error) {
|
|
296
|
-
* console.error("Failed to delete MCP server:", error
|
|
306
|
+
* console.error("Failed to delete MCP server:", error);
|
|
297
307
|
* }
|
|
298
308
|
*
|
|
299
309
|
* // Delete and verify from list
|
|
300
|
-
* await composio.
|
|
301
|
-
* const servers = await composio.
|
|
310
|
+
* await composio.mcp.delete("mcp_12345");
|
|
311
|
+
* const servers = await composio.mcp.list({ page: 1, limit: 10, toolkits: [], authConfigs: [] });
|
|
302
312
|
* const serverExists = servers.items.some(server => server.id === "mcp_12345");
|
|
303
313
|
* console.log("Server still exists:", serverExists); // Should be false
|
|
304
314
|
* ```
|
|
@@ -333,34 +343,32 @@ export class MCP {
|
|
|
333
343
|
* @example
|
|
334
344
|
* ```typescript
|
|
335
345
|
* // Update server name only
|
|
336
|
-
* const updatedServer = await composio.
|
|
346
|
+
* const updatedServer = await composio.mcp.update("mcp_12345", {
|
|
337
347
|
* name: "My Updated MCP Server"
|
|
338
348
|
* });
|
|
339
349
|
*
|
|
340
350
|
* // Update toolkits and tools
|
|
341
|
-
* const serverWithNewTools = await composio.
|
|
351
|
+
* const serverWithNewTools = await composio.mcp.update("mcp_12345", {
|
|
342
352
|
* toolkits: [
|
|
343
|
-
* {
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
* allowedTools: ["SLACK_SEND_MESSAGE", "SLACK_LIST_CHANNELS"]
|
|
352
|
-
* }
|
|
353
|
+
* { toolkit: "github", authConfigId: "auth_abc123" },
|
|
354
|
+
* { toolkit: "slack", authConfigId: "auth_xyz789" }
|
|
355
|
+
* ],
|
|
356
|
+
* allowedTools: [
|
|
357
|
+
* "GITHUB_CREATE_AN_ISSUE",
|
|
358
|
+
* "GITHUB_LIST_REPOS",
|
|
359
|
+
* "SLACK_SEND_MESSAGE",
|
|
360
|
+
* "SLACK_LIST_CHANNELS"
|
|
353
361
|
* ]
|
|
354
362
|
* });
|
|
355
363
|
*
|
|
356
364
|
* // Update connection management setting
|
|
357
|
-
* const serverWithManualAuth = await composio.
|
|
365
|
+
* const serverWithManualAuth = await composio.mcp.update("mcp_12345", {
|
|
358
366
|
* name: "Manual Auth Server",
|
|
359
367
|
* manuallyManageConnections: true
|
|
360
368
|
* });
|
|
361
369
|
*
|
|
362
370
|
* // Complete update example
|
|
363
|
-
* const fullyUpdatedServer = await composio.
|
|
371
|
+
* const fullyUpdatedServer = await composio.mcp.update("mcp_12345", {
|
|
364
372
|
* name: "Production MCP Server",
|
|
365
373
|
* toolkits: [
|
|
366
374
|
* {
|
|
@@ -368,7 +376,7 @@ export class MCP {
|
|
|
368
376
|
* authConfigId: "auth_gmail_prod",
|
|
369
377
|
* }
|
|
370
378
|
* ],
|
|
371
|
-
* allowedTools: ["GMAIL_SEND_EMAIL", "GMAIL_FETCH_EMAILS"]
|
|
379
|
+
* allowedTools: ["GMAIL_SEND_EMAIL", "GMAIL_FETCH_EMAILS"],
|
|
372
380
|
* manuallyManageConnections: false
|
|
373
381
|
* });
|
|
374
382
|
*
|
|
@@ -443,10 +451,10 @@ export class MCP {
|
|
|
443
451
|
*
|
|
444
452
|
* @example
|
|
445
453
|
* ```typescript
|
|
446
|
-
* import { Composio } from "@composio/
|
|
454
|
+
* import { Composio } from "@composio/core";
|
|
447
455
|
*
|
|
448
456
|
* const composio = new Composio();
|
|
449
|
-
* const mcp = await composio.
|
|
457
|
+
* const mcp = await composio.mcp.generate("default", "<mcp_config_id>");
|
|
450
458
|
* ```
|
|
451
459
|
*
|
|
452
460
|
* @param userId {string} external user id from your database for whom you want the server for
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The `composio.sessions.webhooks` namespace: reading the events
|
|
3
|
+
* Composio sends to a project's session webhook URL.
|
|
4
|
+
*
|
|
5
|
+
* @module SessionWebhooks
|
|
6
|
+
*/
|
|
7
|
+
import { ValidationError } from '../errors/ValidationErrors';
|
|
8
|
+
import { ComposioWebhookPayloadError } from '../errors/TriggerErrors';
|
|
9
|
+
import { telemetry } from '../telemetry/Telemetry';
|
|
10
|
+
import {
|
|
11
|
+
ParseSessionWebhookParams,
|
|
12
|
+
SessionWebhookEvent,
|
|
13
|
+
SessionWebhookEventSchema,
|
|
14
|
+
SessionWebhookEventTypes,
|
|
15
|
+
} from '../types/sessionWebhooks.types';
|
|
16
|
+
import {
|
|
17
|
+
WEBHOOK_HEADERS,
|
|
18
|
+
getHeader,
|
|
19
|
+
validateWebhookTimestamp,
|
|
20
|
+
verifyWebhookSignature,
|
|
21
|
+
} from '../utils/webhookVerification';
|
|
22
|
+
|
|
23
|
+
const DEFAULT_TOLERANCE_SECONDS = 300;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* `composio.sessions.webhooks` — for the endpoint at a project's session
|
|
27
|
+
* webhook URL, which answers session hooks that have a `webhook` handler.
|
|
28
|
+
*/
|
|
29
|
+
export class SessionWebhooks {
|
|
30
|
+
constructor() {
|
|
31
|
+
telemetry.instrument(this, 'SessionWebhooks');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Verify and parse an event Composio sent to the session webhook URL.
|
|
36
|
+
*
|
|
37
|
+
* Composio sends one before or after each tool or proxy call that a hook
|
|
38
|
+
* with a `webhook` handler applies to, and waits for the endpoint's answer.
|
|
39
|
+
* The signature is always verified, with the project's session webhook
|
|
40
|
+
* secret. The event is returned as Composio sent it, with the field names of
|
|
41
|
+
* the webhook reference.
|
|
42
|
+
*
|
|
43
|
+
* Pass the raw, unparsed request body: the signature covers its exact bytes.
|
|
44
|
+
*
|
|
45
|
+
* @param {ParseSessionWebhookParams} params - The request and how to verify it
|
|
46
|
+
* @param {string | Uint8Array} params.body - The raw request body
|
|
47
|
+
* @param {Headers | Record<string, string | string[] | undefined>} params.headers - The request headers
|
|
48
|
+
* @param {string} params.verifySecret - The project's session webhook secret
|
|
49
|
+
* @param {number} [params.tolerance=300] - Max event age in seconds. Set to 0 to disable the check.
|
|
50
|
+
* @returns {Promise<SessionWebhookEvent>} The verified event
|
|
51
|
+
*
|
|
52
|
+
* @throws {ValidationError} If `verifySecret` is empty or the signature headers are missing
|
|
53
|
+
* @throws {ComposioWebhookSignatureVerificationError} If signature verification fails
|
|
54
|
+
* @throws {ComposioWebhookPayloadError} If the body is not a session webhook event
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* // Next.js App Router, at the project's session webhook URL
|
|
59
|
+
* export async function POST(request: Request) {
|
|
60
|
+
* const hook = await composio.sessions.webhooks.parse({
|
|
61
|
+
* body: await request.text(),
|
|
62
|
+
* headers: request.headers,
|
|
63
|
+
* verifySecret: process.env.COMPOSIO_SESSION_WEBHOOK_SECRET!,
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Keep a confidential project out of every call and every result
|
|
67
|
+
* if (JSON.stringify(hook.data).includes('Project Titan')) {
|
|
68
|
+
* return Response.json({ action: 'block', message: 'Project Titan is confidential' });
|
|
69
|
+
* }
|
|
70
|
+
* return Response.json({ action: 'continue' });
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
async parse(params: ParseSessionWebhookParams): Promise<SessionWebhookEvent> {
|
|
75
|
+
const { body: rawBody, headers, verifySecret: secret } = params;
|
|
76
|
+
|
|
77
|
+
if (!secret) {
|
|
78
|
+
throw new ValidationError(
|
|
79
|
+
`Cannot verify session webhook: 'verifySecret' is empty — your ` +
|
|
80
|
+
`COMPOSIO_SESSION_WEBHOOK_SECRET is likely unset. Set it to the project's ` +
|
|
81
|
+
`session webhook secret from the Composio dashboard.`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const id = getHeader(headers, WEBHOOK_HEADERS.id);
|
|
86
|
+
const timestamp = getHeader(headers, WEBHOOK_HEADERS.timestamp);
|
|
87
|
+
const signature = getHeader(headers, WEBHOOK_HEADERS.signature);
|
|
88
|
+
|
|
89
|
+
if (!id || !timestamp || !signature) {
|
|
90
|
+
const missing = [
|
|
91
|
+
!id ? `'${WEBHOOK_HEADERS.id}'` : undefined,
|
|
92
|
+
!timestamp ? `'${WEBHOOK_HEADERS.timestamp}'` : undefined,
|
|
93
|
+
!signature ? `'${WEBHOOK_HEADERS.signature}'` : undefined,
|
|
94
|
+
].filter((header): header is string => header !== undefined);
|
|
95
|
+
|
|
96
|
+
throw new ValidationError(
|
|
97
|
+
`Cannot verify session webhook: missing signature header(s) ${missing.join(', ')}. ` +
|
|
98
|
+
`Pass the raw, unparsed request body and ensure the Composio signature headers ` +
|
|
99
|
+
`(${WEBHOOK_HEADERS.id}, ${WEBHOOK_HEADERS.timestamp}, ${WEBHOOK_HEADERS.signature}) ` +
|
|
100
|
+
`are forwarded to sessions.webhooks.parse().`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const tolerance = params.tolerance ?? DEFAULT_TOLERANCE_SECONDS;
|
|
105
|
+
if (tolerance > 0) {
|
|
106
|
+
validateWebhookTimestamp(timestamp, tolerance);
|
|
107
|
+
}
|
|
108
|
+
// Verification and parsing must use the same bytes across the await.
|
|
109
|
+
const body = typeof rawBody === 'string' ? rawBody : new Uint8Array(rawBody);
|
|
110
|
+
await verifyWebhookSignature(id, timestamp, body, signature, secret);
|
|
111
|
+
|
|
112
|
+
let json: unknown;
|
|
113
|
+
try {
|
|
114
|
+
const text =
|
|
115
|
+
typeof body === 'string'
|
|
116
|
+
? body
|
|
117
|
+
: new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(body);
|
|
118
|
+
json = JSON.parse(text);
|
|
119
|
+
} catch {
|
|
120
|
+
throw new ComposioWebhookPayloadError('Failed to parse session webhook payload as JSON');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const event = SessionWebhookEventSchema.safeParse(json);
|
|
124
|
+
if (!event.success) {
|
|
125
|
+
const fields = [...new Set(event.error.issues.map(issue => issue.path.join('.')))].sort();
|
|
126
|
+
const isAnotherPayload = fields.includes('') || fields.includes('type');
|
|
127
|
+
throw new ComposioWebhookPayloadError(
|
|
128
|
+
isAnotherPayload
|
|
129
|
+
? `Payload is not a session webhook event. Expected a '${SessionWebhookEventTypes.BEFORE_EXECUTE}' ` +
|
|
130
|
+
`or '${SessionWebhookEventTypes.AFTER_EXECUTE}' event.`
|
|
131
|
+
: `Session webhook event has missing or invalid fields: ${fields.join(', ')}`
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return event.data;
|
|
135
|
+
}
|
|
136
|
+
}
|
package/src/models/ToolRouter.ts
CHANGED
|
@@ -56,12 +56,14 @@ import {
|
|
|
56
56
|
resolveToolRouterSandboxConfig,
|
|
57
57
|
resolveLocalToolsOptions,
|
|
58
58
|
type LocalToolsOptions,
|
|
59
|
+
type SessionCreateBody,
|
|
59
60
|
} from '../lib/toolRouterParams';
|
|
60
61
|
import { PRELOAD_TOOLS_ALL } from '../lib/toolRouterConstants';
|
|
61
62
|
import { buildMCPServerConfig } from '../lib/toolRouterMcp';
|
|
62
63
|
import { parseSessionConfigInput } from '../lib/sessionConfigConflict';
|
|
63
64
|
import { getSourceSessionConfig } from '../lib/toolRouterSourceSessionConfig';
|
|
64
65
|
import { ToolRouterSession } from './ToolRouterSession';
|
|
66
|
+
import { SessionWebhooks } from './SessionWebhooks';
|
|
65
67
|
import { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
66
68
|
import { withCancellation } from '../utils/cancellation';
|
|
67
69
|
import { deleteToolRouterSession } from '../lib/toolRouterSessionDelete';
|
|
@@ -132,10 +134,17 @@ export class ToolRouter<
|
|
|
132
134
|
TTool,
|
|
133
135
|
TProvider extends BaseComposioProvider<TToolCollection, TTool, unknown>,
|
|
134
136
|
> {
|
|
137
|
+
/**
|
|
138
|
+
* Read the events Composio sends to the project's session webhook URL, for
|
|
139
|
+
* session hooks with a `webhook` handler.
|
|
140
|
+
*/
|
|
141
|
+
webhooks: SessionWebhooks;
|
|
142
|
+
|
|
135
143
|
constructor(
|
|
136
144
|
private client: ComposioClient,
|
|
137
145
|
private config?: ComposioConfig<TProvider>
|
|
138
146
|
) {
|
|
147
|
+
this.webhooks = new SessionWebhooks();
|
|
139
148
|
telemetry.instrument(this, 'ToolRouter');
|
|
140
149
|
}
|
|
141
150
|
|
|
@@ -187,10 +196,30 @@ export class ToolRouter<
|
|
|
187
196
|
*
|
|
188
197
|
* @example
|
|
189
198
|
* ```typescript
|
|
190
|
-
* import { Composio } from '@composio/core';
|
|
199
|
+
* import { Composio, experimental_createTool, experimental_createToolkit } from '@composio/core';
|
|
200
|
+
* import { z } from 'zod';
|
|
191
201
|
*
|
|
192
202
|
* const composio = new Composio();
|
|
193
203
|
*
|
|
204
|
+
* const myLocalTool = experimental_createTool('GET_WEATHER', {
|
|
205
|
+
* name: 'Get Weather',
|
|
206
|
+
* description: 'Get the weather for a city',
|
|
207
|
+
* inputParams: z.object({ city: z.string() }),
|
|
208
|
+
* execute: async ({ city }) => ({ city, forecast: 'sunny' }),
|
|
209
|
+
* });
|
|
210
|
+
* const myLocalToolkit = experimental_createToolkit('DEV_TOOLS', {
|
|
211
|
+
* name: 'Dev Tools',
|
|
212
|
+
* description: 'Local developer utilities',
|
|
213
|
+
* tools: [
|
|
214
|
+
* experimental_createTool('ECHO', {
|
|
215
|
+
* name: 'Echo',
|
|
216
|
+
* description: 'Return the input text',
|
|
217
|
+
* inputParams: z.object({ text: z.string() }),
|
|
218
|
+
* execute: async ({ text }) => ({ text }),
|
|
219
|
+
* }),
|
|
220
|
+
* ],
|
|
221
|
+
* });
|
|
222
|
+
*
|
|
194
223
|
* const session = await composio.sessions.create('user_123', {
|
|
195
224
|
* toolkits: ['gmail'],
|
|
196
225
|
* manageConnections: true,
|
|
@@ -280,7 +309,7 @@ export class ToolRouter<
|
|
|
280
309
|
])
|
|
281
310
|
);
|
|
282
311
|
|
|
283
|
-
const payload:
|
|
312
|
+
const payload: SessionCreateBody = {
|
|
284
313
|
user_id: userId,
|
|
285
314
|
auth_configs: routerConfig.authConfigs,
|
|
286
315
|
connected_accounts: connectedAccountsPayload,
|
|
@@ -310,7 +339,13 @@ export class ToolRouter<
|
|
|
310
339
|
};
|
|
311
340
|
|
|
312
341
|
const session = await withCancellation(
|
|
313
|
-
() =>
|
|
342
|
+
() =>
|
|
343
|
+
this.client.toolRouter.session.create(
|
|
344
|
+
// The `webhook` hook handler is not in `@composio/client` until it
|
|
345
|
+
// picks up ComposioHQ/platform#15328; the body is serialized as-is.
|
|
346
|
+
payload as SessionCreateParams,
|
|
347
|
+
requestOptions
|
|
348
|
+
),
|
|
314
349
|
requestOptions?.signal
|
|
315
350
|
);
|
|
316
351
|
|
|
@@ -368,7 +403,7 @@ export class ToolRouter<
|
|
|
368
403
|
*
|
|
369
404
|
* const composio = new Composio();
|
|
370
405
|
* const id = 'session_123';
|
|
371
|
-
* const session = await composio.sessions.use(id);
|
|
406
|
+
* const session = await composio.sessions.use(id, { mcp: true });
|
|
372
407
|
*
|
|
373
408
|
* console.log(session.mcp.url);
|
|
374
409
|
* console.log(session.mcp.headers);
|
|
@@ -559,7 +559,7 @@ export class ToolRouterSession<
|
|
|
559
559
|
*
|
|
560
560
|
* @example
|
|
561
561
|
* ```typescript
|
|
562
|
-
* const session = await composio.sessions.create({ toolkits: ['github'] });
|
|
562
|
+
* const session = await composio.sessions.create('user_123', { toolkits: ['github'] });
|
|
563
563
|
* const { wasConnected, connectedAccount } = await session.ensureConnected('github');
|
|
564
564
|
* if (!wasConnected) console.log('Newly linked:', connectedAccount?.id);
|
|
565
565
|
* ```
|
|
@@ -1034,7 +1034,7 @@ export class ToolRouterSession<
|
|
|
1034
1034
|
}
|
|
1035
1035
|
const obj = item as Record<string, unknown>;
|
|
1036
1036
|
return {
|
|
1037
|
-
tool_slug:
|
|
1037
|
+
tool_slug: typeof obj.tool_slug === 'string' ? obj.tool_slug : '',
|
|
1038
1038
|
arguments: (obj.arguments as Record<string, unknown> | undefined) ?? {},
|
|
1039
1039
|
};
|
|
1040
1040
|
}
|
|
@@ -200,12 +200,14 @@ export class ToolRouterSessionFilesMount {
|
|
|
200
200
|
* @example
|
|
201
201
|
* ```typescript
|
|
202
202
|
* // From native File (e.g. from input[type=file])
|
|
203
|
-
*
|
|
203
|
+
* const file = new File(['hello world'], 'hello.txt', { type: 'text/plain' });
|
|
204
|
+
* await session.experimental.files.upload(file);
|
|
204
205
|
* ```
|
|
205
206
|
*
|
|
206
207
|
* @example
|
|
207
208
|
* ```typescript
|
|
208
209
|
* // From raw buffer
|
|
210
|
+
* const buffer = new TextEncoder().encode(JSON.stringify({ hello: 'world' }));
|
|
209
211
|
* await session.experimental.files.upload(buffer, { remotePath: 'data.json', mimetype: 'application/json' });
|
|
210
212
|
* ```
|
|
211
213
|
*/
|
package/src/models/Toolkits.ts
CHANGED
package/src/models/Tools.ts
CHANGED
|
@@ -344,7 +344,7 @@ export class Tools<
|
|
|
344
344
|
error: z.ZodError,
|
|
345
345
|
droppedSides: Array<'inputParameters' | 'outputParameters'>
|
|
346
346
|
): void {
|
|
347
|
-
const slug =
|
|
347
|
+
const slug = typeof tool.slug === 'string' ? tool.slug : '';
|
|
348
348
|
if (slug && this.warnedMalformedToolParametersSlugs.has(slug)) return;
|
|
349
349
|
if (slug) this.warnedMalformedToolParametersSlugs.add(slug);
|
|
350
350
|
const inputFailed = droppedSides.includes('inputParameters');
|
|
@@ -609,12 +609,6 @@ export class Tools<
|
|
|
609
609
|
* tools: ['GITHUB_GET_REPOS', 'HACKERNEWS_GET_USER']
|
|
610
610
|
* });
|
|
611
611
|
*
|
|
612
|
-
* // Get tools from specific toolkits
|
|
613
|
-
* const githubTools = await composio.tools.getRawComposioTools({
|
|
614
|
-
* toolkits: ['github'],
|
|
615
|
-
* limit: 10
|
|
616
|
-
* });
|
|
617
|
-
*
|
|
618
612
|
* // Get tools with schema transformation
|
|
619
613
|
* const customizedTools = await composio.tools.getRawComposioTools({
|
|
620
614
|
* toolkits: ['github'],
|
|
@@ -1326,6 +1320,8 @@ export class Tools<
|
|
|
1326
1320
|
*
|
|
1327
1321
|
* @example Execute with SDK-level toolkit versions configuration
|
|
1328
1322
|
* ```typescript
|
|
1323
|
+
* import { Composio } from '@composio/core';
|
|
1324
|
+
*
|
|
1329
1325
|
* // If toolkitVersions are set during Composio initialization, no need to pass version
|
|
1330
1326
|
* const composio = new Composio({ toolkitVersions: { github: '20250909_00' } });
|
|
1331
1327
|
* const result = await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
@@ -1518,7 +1514,7 @@ export class Tools<
|
|
|
1518
1514
|
* ```typescript
|
|
1519
1515
|
* // Get all available tools as an enum
|
|
1520
1516
|
* const toolsEnum = await composio.tools.getToolsEnum();
|
|
1521
|
-
* console.log(toolsEnum
|
|
1517
|
+
* console.log(toolsEnum); // ['GITHUB_GET_REPOS', ...]
|
|
1522
1518
|
* ```
|
|
1523
1519
|
*/
|
|
1524
1520
|
async getToolsEnum(requestOptions?: ComposioRequestOptions): Promise<ToolRetrieveEnumResponse> {
|