@composio/core 0.18.1 → 0.19.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-Bz0f52QR.mjs → CustomTool-BMlZfJVz.mjs} +1 -1
- package/dist/{CustomTool-VRfWzMix.d.mts → CustomTool-CB5vm1Jc.d.mts} +1 -1
- package/dist/{FileModifierErrors-CwB-Inm9.mjs → FileModifierErrors-BqFmpRsm.mjs} +1 -1
- package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
- package/dist/{SsrfErrors-xhdVE4yw.mjs → SsrfErrors-C91YhASE.mjs} +14 -10
- package/dist/{Telemetry-Dw9W5RSp.mjs → Telemetry-HlftxMx6.mjs} +2 -2
- package/dist/{cancellation-P5YUlcfz.mjs → cancellation-CXpfmiVo.mjs} +7 -5
- package/dist/{composio-Cb3d1jFe.d.mts → composio-DLGaeN70.d.mts} +327 -26
- package/dist/{customTool.types-B6ej_8XZ.d.mts → customTool.types-BAmEh3MB.d.mts} +95 -4
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +2 -2
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +3 -13
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +46 -3
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +4 -4
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +33 -23
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +3 -2
- package/dist/{errors-Ue9wMrPK.mjs → errors-BuEKehbI.mjs} +23 -3
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-KE5Fa-af.mjs → fileUtils.node-L7XD8UPr.mjs} +8 -6
- package/dist/index.d.mts +160 -101
- package/dist/index.mjs +336 -127
- 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-QN7w4n8v.mjs → sensitiveFileUploadPaths-B6pBt9lO.mjs} +10 -7
- package/dist/{ssrfGuard.node-BLX6b-Rf.mjs → ssrfGuard.node-B9xQB4za.mjs} +104 -14
- package/dist/{types-CGdgK442.d.mts → types-CxLPO0Xq.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 +19 -10
- package/dist/utils/ssrfGuard.node.mjs +1 -1
- package/dist/utils/ssrfGuard.workerd.d.mts +12 -4
- package/dist/utils/ssrfGuard.workerd.mjs +2 -2
- package/package.json +8 -8
- package/src/errors/ToolErrors.ts +24 -0
- package/src/index.ts +4 -0
- package/src/models/MCP.ts +29 -15
- package/src/models/ToolRouter.ts +1 -0
- package/src/models/ToolRouterSession.ts +106 -9
- package/src/models/Toolkits.ts +1 -2
- package/src/models/Tools.ts +55 -25
- package/src/models/Triggers.ts +7 -2
- package/src/services/pusher/Pusher.ts +29 -10
- package/src/types/toolRouter.types.ts +54 -3
- package/src/types/toolkit.types.ts +17 -0
- package/src/utils/jsonSchema.ts +4 -1
- package/src/utils/ssrfGuard.node.ts +127 -13
- package/src/utils/ssrfGuard.workerd.ts +11 -1
- package/src/utils/transformers/toolkits.ts +79 -2
package/src/models/MCP.ts
CHANGED
|
@@ -99,16 +99,19 @@ export class MCP {
|
|
|
99
99
|
|
|
100
100
|
const toolkits: string[] = [];
|
|
101
101
|
const auth_config_ids: string[] = [];
|
|
102
|
-
const
|
|
102
|
+
const allowed_tools: string[] = config.data.allowedTools ?? [];
|
|
103
103
|
|
|
104
104
|
// extract all the toolkits, authconfigs, and allowed tools to separate slugs
|
|
105
105
|
config.data.toolkits.forEach(toolkit => {
|
|
106
106
|
if (typeof toolkit === 'string') {
|
|
107
107
|
toolkits.push(toolkit);
|
|
108
|
-
} else
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
} else {
|
|
109
|
+
if (toolkit.toolkit) {
|
|
110
|
+
toolkits.push(toolkit.toolkit);
|
|
111
|
+
}
|
|
112
|
+
if (toolkit.authConfigId) {
|
|
113
|
+
auth_config_ids.push(toolkit.authConfigId);
|
|
114
|
+
}
|
|
112
115
|
}
|
|
113
116
|
});
|
|
114
117
|
|
|
@@ -116,7 +119,7 @@ export class MCP {
|
|
|
116
119
|
name,
|
|
117
120
|
toolkits,
|
|
118
121
|
auth_config_ids,
|
|
119
|
-
|
|
122
|
+
allowed_tools,
|
|
120
123
|
// if manually manage account is set to true, disable composio account management tools
|
|
121
124
|
managed_auth_via_composio: config.data.manuallyManageConnections ? false : true,
|
|
122
125
|
};
|
|
@@ -380,28 +383,39 @@ export class MCP {
|
|
|
380
383
|
|
|
381
384
|
const toolkits: string[] = [];
|
|
382
385
|
const auth_config_ids: string[] = [];
|
|
383
|
-
const custom_tools: string[] | undefined = params.allowedTools ?? undefined;
|
|
384
386
|
|
|
385
387
|
// extract all the toolkits, authconfigs, and allowed tools to separate slugs
|
|
386
388
|
params.toolkits?.forEach(toolkit => {
|
|
387
389
|
if (typeof toolkit === 'string') {
|
|
388
390
|
toolkits.push(toolkit);
|
|
389
|
-
} else
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
391
|
+
} else {
|
|
392
|
+
if (toolkit.toolkit) {
|
|
393
|
+
toolkits.push(toolkit.toolkit);
|
|
394
|
+
}
|
|
395
|
+
if (toolkit.authConfigId) {
|
|
396
|
+
auth_config_ids.push(toolkit.authConfigId);
|
|
397
|
+
}
|
|
393
398
|
}
|
|
394
399
|
});
|
|
400
|
+
|
|
401
|
+
// Build a sparse PATCH body: only fields the caller provided are sent, so omitted
|
|
402
|
+
// fields keep their current server-side values. `allowed_tools` is sent whenever it
|
|
403
|
+
// is provided, independently of `toolkits` (tool-only updates are valid), and must
|
|
404
|
+
// use the API field `allowed_tools` — the update endpoint does not read the
|
|
405
|
+
// deprecated create-only alias `custom_tools`. `manuallyManageConnections` is
|
|
406
|
+
// inverted into `managed_auth_via_composio`, matching create() and generate().
|
|
395
407
|
const updateBody = {
|
|
396
|
-
...{ name: params.name
|
|
397
|
-
...(params.toolkits
|
|
408
|
+
...(params.name !== undefined ? { name: params.name } : {}),
|
|
409
|
+
...(params.toolkits !== undefined
|
|
398
410
|
? {
|
|
399
|
-
custom_tools: custom_tools,
|
|
400
411
|
toolkits: toolkits,
|
|
401
412
|
auth_config_ids: auth_config_ids,
|
|
402
413
|
}
|
|
403
414
|
: {}),
|
|
404
|
-
...{
|
|
415
|
+
...(params.allowedTools !== undefined ? { allowed_tools: params.allowedTools } : {}),
|
|
416
|
+
...(params.manuallyManageConnections !== undefined
|
|
417
|
+
? { managed_auth_via_composio: !params.manuallyManageConnections }
|
|
418
|
+
: {}),
|
|
405
419
|
};
|
|
406
420
|
const response = await withCancellation(
|
|
407
421
|
() => this.client.mcp.update(serverId, updateBody, requestOptions),
|
package/src/models/ToolRouter.ts
CHANGED
|
@@ -71,6 +71,7 @@ function getSessionMetadata(
|
|
|
71
71
|
session: SessionCreateResponse | SessionRetrieveResponse | SessionAttachResponse
|
|
72
72
|
) {
|
|
73
73
|
const metadata: ToolRouterSessionMetadata = {
|
|
74
|
+
config: session.config,
|
|
74
75
|
preload: session.config.preload,
|
|
75
76
|
workbench: session.config.workbench,
|
|
76
77
|
configVersion: session.config_version,
|
|
@@ -16,12 +16,16 @@ import {
|
|
|
16
16
|
ToolRouterSessionExecuteResponseSchema,
|
|
17
17
|
ToolRouterSessionProxyExecuteResponse,
|
|
18
18
|
ToolRouterSessionExecuteOptions,
|
|
19
|
+
ToolRouterSessionConfig,
|
|
19
20
|
ToolRouterSessionMetadata,
|
|
20
21
|
ToolRouterSessionPreloadConfig,
|
|
21
22
|
ToolRouterSessionWorkbenchConfig,
|
|
22
23
|
ToolRouterSessionWarning,
|
|
23
24
|
ToolRouterUpdateSessionConfig,
|
|
24
25
|
ToolRouterUpdateSessionConfigSchema,
|
|
26
|
+
ToolRouterSessionEnsureConnectedOptions,
|
|
27
|
+
ToolRouterSessionEnsureConnectedOptionsSchema,
|
|
28
|
+
ToolRouterSessionEnsureConnectedResult,
|
|
25
29
|
type ToolRouterSessionDeleteResponse,
|
|
26
30
|
} from '../types/toolRouter.types';
|
|
27
31
|
import {
|
|
@@ -118,6 +122,12 @@ export class ToolRouterSession<
|
|
|
118
122
|
/** Hosted MCP endpoint (`session.mcp.url` / `session.mcp.headers`). Exists on every session at runtime, but only surfaced in the type when the session is created with `{ mcp: true }` (which returns `Session`); the default `SessionWithoutMcp` omits `mcp`, so MCP is an explicit opt-in. See https://docs.composio.dev/docs/sessions-via-mcp */
|
|
119
123
|
public readonly mcp: ToolRouterMCPServerConfig;
|
|
120
124
|
public readonly experimental: SessionExperimental;
|
|
125
|
+
/**
|
|
126
|
+
* Server-side session configuration (toolkit/tool allowlists, tags, preload,
|
|
127
|
+
* sandbox, manage_connections) as returned by the API. Refreshed in place by
|
|
128
|
+
* `update()`.
|
|
129
|
+
*/
|
|
130
|
+
public config: ToolRouterSessionConfig;
|
|
121
131
|
public preload: ToolRouterSessionPreloadConfig;
|
|
122
132
|
/** Resolved sandbox (code-execution) config returned by the API. `enable` defaults to `true` server-side. */
|
|
123
133
|
public sandbox?: ToolRouterSessionWorkbenchConfig;
|
|
@@ -131,7 +141,7 @@ export class ToolRouterSession<
|
|
|
131
141
|
|
|
132
142
|
constructor(
|
|
133
143
|
private readonly client: ComposioClient,
|
|
134
|
-
private readonly
|
|
144
|
+
private readonly sdkConfig: ComposioConfig<TProvider> | undefined,
|
|
135
145
|
sessionId: string,
|
|
136
146
|
mcp: ToolRouterMCPServerConfig,
|
|
137
147
|
experimentalOverrides?: Pick<SessionExperimental, 'assistivePrompt'>,
|
|
@@ -139,6 +149,12 @@ export class ToolRouterSession<
|
|
|
139
149
|
private readonly userId?: string,
|
|
140
150
|
metadata?: ToolRouterSessionMetadata
|
|
141
151
|
) {
|
|
152
|
+
const config: ToolRouterSessionConfig = metadata?.config ?? {
|
|
153
|
+
user_id: userId ?? '',
|
|
154
|
+
execute: {},
|
|
155
|
+
search: {},
|
|
156
|
+
preload: { tools: [] },
|
|
157
|
+
};
|
|
142
158
|
if (customToolsMap && !userId) {
|
|
143
159
|
throw new Error('userId is required when custom tools are bound to a session.');
|
|
144
160
|
}
|
|
@@ -148,8 +164,9 @@ export class ToolRouterSession<
|
|
|
148
164
|
assistivePrompt: experimentalOverrides?.assistivePrompt,
|
|
149
165
|
files: new ToolRouterSessionFilesMount(client, sessionId),
|
|
150
166
|
};
|
|
151
|
-
this.
|
|
152
|
-
this.
|
|
167
|
+
this.config = config;
|
|
168
|
+
this.preload = metadata?.preload ?? config.preload;
|
|
169
|
+
this.sandbox = metadata?.workbench ?? config.workbench;
|
|
153
170
|
this.configVersion = metadata?.configVersion;
|
|
154
171
|
this.warnings = metadata?.warnings ?? [];
|
|
155
172
|
this.preloadedCustomToolSlugs = metadata?.preloadedCustomToolSlugs ?? [];
|
|
@@ -193,7 +210,7 @@ export class ToolRouterSession<
|
|
|
193
210
|
modifiers?: SessionMetaToolOptions,
|
|
194
211
|
requestOptions?: ComposioRequestOptions
|
|
195
212
|
): Promise<ReturnType<TProvider['wrapTools']>> {
|
|
196
|
-
const ToolsModel = new Tools<TToolCollection, TTool, TProvider>(this.client, this.
|
|
213
|
+
const ToolsModel = new Tools<TToolCollection, TTool, TProvider>(this.client, this.sdkConfig);
|
|
197
214
|
const rawTools = await ToolsModel.getRawToolRouterSessionTools(
|
|
198
215
|
this.sessionId,
|
|
199
216
|
undefined,
|
|
@@ -226,13 +243,13 @@ export class ToolRouterSession<
|
|
|
226
243
|
);
|
|
227
244
|
};
|
|
228
245
|
|
|
229
|
-
if (!this.
|
|
246
|
+
if (!this.sdkConfig?.provider) {
|
|
230
247
|
throw new Error(
|
|
231
248
|
'A provider is required when using custom tools with session.tools(). ' +
|
|
232
249
|
'Pass a provider in the Composio constructor.'
|
|
233
250
|
);
|
|
234
251
|
}
|
|
235
|
-
return this.
|
|
252
|
+
return this.sdkConfig.provider.wrapTools(sessionTools, routingExecuteFn) as ReturnType<
|
|
236
253
|
TProvider['wrapTools']
|
|
237
254
|
>;
|
|
238
255
|
}
|
|
@@ -470,6 +487,83 @@ export class ToolRouterSession<
|
|
|
470
487
|
);
|
|
471
488
|
}
|
|
472
489
|
|
|
490
|
+
/**
|
|
491
|
+
* Ensure a toolkit has an active connection in this session, reconciling
|
|
492
|
+
* `authorize()`/`session.link` with the session's active connection state.
|
|
493
|
+
*
|
|
494
|
+
* If the session already resolves an ACTIVE connection (or the toolkit is
|
|
495
|
+
* no-auth), this returns immediately without creating a link — unlike
|
|
496
|
+
* `authorize()`, which always starts a new link flow, even when one is
|
|
497
|
+
* already connected. Otherwise it starts the authorization flow and waits
|
|
498
|
+
* for the new connection to become ACTIVE.
|
|
499
|
+
*
|
|
500
|
+
* For interactive flows that should surface the redirect URL instead of
|
|
501
|
+
* blocking, use `authorize()` and its `waitForConnection()` directly.
|
|
502
|
+
*
|
|
503
|
+
* @param toolkit - The toolkit slug to ensure a connection for (e.g. 'github')
|
|
504
|
+
* @param options - Optional authorization options plus `timeout` (ms to wait
|
|
505
|
+
* for a newly-initiated connection, default 60000)
|
|
506
|
+
* @returns The toolkit's canonical slug, whether it was already connected,
|
|
507
|
+
* and the active connected account (omitted for no-auth toolkits)
|
|
508
|
+
* @throws {ValidationError} If the options fail validation
|
|
509
|
+
* @throws {ConnectionRequestTimeoutError} If a newly-initiated connection does
|
|
510
|
+
* not become active within `timeout`
|
|
511
|
+
* @throws {ConnectionRequestFailedError} If the new connection enters a failed,
|
|
512
|
+
* expired, or revoked state
|
|
513
|
+
*
|
|
514
|
+
* @example
|
|
515
|
+
* ```typescript
|
|
516
|
+
* const session = await composio.sessions.create({ toolkits: ['github'] });
|
|
517
|
+
* const { wasConnected, connectedAccount } = await session.ensureConnected('github');
|
|
518
|
+
* if (!wasConnected) console.log('Newly linked:', connectedAccount?.id);
|
|
519
|
+
* ```
|
|
520
|
+
*/
|
|
521
|
+
async ensureConnected(
|
|
522
|
+
toolkit: string,
|
|
523
|
+
options?: ToolRouterSessionEnsureConnectedOptions,
|
|
524
|
+
requestOptions?: ComposioRequestOptions
|
|
525
|
+
): Promise<ToolRouterSessionEnsureConnectedResult> {
|
|
526
|
+
const parsedOptions = ToolRouterSessionEnsureConnectedOptionsSchema.safeParse(options ?? {});
|
|
527
|
+
if (!parsedOptions.success) {
|
|
528
|
+
throw new ValidationError('Failed to parse tool router ensureConnected options', {
|
|
529
|
+
cause: parsedOptions.error,
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
const { callbackUrl, alias, experimental, timeout } = parsedOptions.data;
|
|
533
|
+
|
|
534
|
+
const state = await this.toolkits({ toolkits: [toolkit] }, requestOptions);
|
|
535
|
+
const existing = state.items.find(item => item.slug.toLowerCase() === toolkit.toLowerCase());
|
|
536
|
+
|
|
537
|
+
if (existing?.isNoAuth) {
|
|
538
|
+
return { toolkit: existing.slug, wasConnected: true };
|
|
539
|
+
}
|
|
540
|
+
const activeAccount = existing?.connection?.connectedAccount;
|
|
541
|
+
if (existing?.connection?.isActive && activeAccount) {
|
|
542
|
+
return {
|
|
543
|
+
toolkit: existing.slug,
|
|
544
|
+
wasConnected: true,
|
|
545
|
+
connectedAccount: { id: activeAccount.id, status: activeAccount.status },
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const request = await this.authorize(
|
|
550
|
+
toolkit,
|
|
551
|
+
{
|
|
552
|
+
...(callbackUrl !== undefined && { callbackUrl }),
|
|
553
|
+
...(alias !== undefined && { alias }),
|
|
554
|
+
...(experimental !== undefined && { experimental }),
|
|
555
|
+
},
|
|
556
|
+
requestOptions
|
|
557
|
+
);
|
|
558
|
+
const account = await request.waitForConnection(timeout);
|
|
559
|
+
|
|
560
|
+
return {
|
|
561
|
+
toolkit: existing?.slug ?? toolkit,
|
|
562
|
+
wasConnected: false,
|
|
563
|
+
connectedAccount: { id: account.id, status: account.status },
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
473
567
|
/**
|
|
474
568
|
* Query the connection state of toolkits in the session.
|
|
475
569
|
* Supports pagination and filtering by toolkit slugs.
|
|
@@ -567,7 +661,7 @@ export class ToolRouterSession<
|
|
|
567
661
|
* @param toolSlug - The tool slug to execute
|
|
568
662
|
* @param arguments_ - Optional tool arguments
|
|
569
663
|
* @param options - Optional execution options
|
|
570
|
-
* @param options.account - Account identifier for direct app tool execution in multi-account sessions. Helper/meta tools either ignore this top-level field or define their own account-selection fields.
|
|
664
|
+
* @param options.account - Account identifier for direct app tool execution. Accepted on every project: in multi-account sessions it picks the account; on single-account projects it must match one of the session's active connections for the toolkit. Helper/meta tools either ignore this top-level field or define their own account-selection fields.
|
|
571
665
|
* @returns The tool execution result
|
|
572
666
|
*/
|
|
573
667
|
async execute(
|
|
@@ -664,12 +758,13 @@ export class ToolRouterSession<
|
|
|
664
758
|
/**
|
|
665
759
|
* Partially update the session configuration.
|
|
666
760
|
* Only the fields provided will be changed; omitted fields are preserved.
|
|
667
|
-
* Mutates this session's `configVersion`, `preload`,
|
|
761
|
+
* Mutates this session's `config`, `configVersion`, `preload`, `sandbox`,
|
|
762
|
+
* and `warnings` in-place, and resolves to the updated session `config`.
|
|
668
763
|
*/
|
|
669
764
|
async update(
|
|
670
765
|
config: ToolRouterUpdateSessionConfig,
|
|
671
766
|
requestOptions?: ComposioRequestOptions
|
|
672
|
-
): Promise<
|
|
767
|
+
): Promise<ToolRouterSessionConfig> {
|
|
673
768
|
const parsed = ToolRouterUpdateSessionConfigSchema.parse(config);
|
|
674
769
|
const params = transformToolRouterUpdateParams(parsed);
|
|
675
770
|
const response = await withCancellation(
|
|
@@ -677,9 +772,11 @@ export class ToolRouterSession<
|
|
|
677
772
|
requestOptions?.signal
|
|
678
773
|
);
|
|
679
774
|
this.configVersion = response.config_version;
|
|
775
|
+
this.config = response.config;
|
|
680
776
|
this.preload = response.config.preload;
|
|
681
777
|
this.sandbox = response.config.workbench;
|
|
682
778
|
this.warnings = response.warnings ?? [];
|
|
779
|
+
return this.config;
|
|
683
780
|
}
|
|
684
781
|
|
|
685
782
|
/**
|
package/src/models/Toolkits.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ComposioClient from '@composio/client';
|
|
1
|
+
import ComposioClient, { APIError } from '@composio/client';
|
|
2
2
|
import {
|
|
3
3
|
ToolkitListParams,
|
|
4
4
|
ToolKitListResponse,
|
|
@@ -16,7 +16,6 @@ import { ConnectionRequest } from '../types/connectionRequest.types';
|
|
|
16
16
|
import { telemetry } from '../telemetry/Telemetry';
|
|
17
17
|
import { AuthSchemeType } from '../types/authConfigs.types';
|
|
18
18
|
import logger from '../utils/logger';
|
|
19
|
-
import { APIError } from 'openai';
|
|
20
19
|
import {
|
|
21
20
|
transformToolkitListResponse,
|
|
22
21
|
transformToolkitRetrieveCategoriesResponse,
|
package/src/models/Tools.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import ComposioClient from '@composio/client';
|
|
1
|
+
import ComposioClient, { APIError } from '@composio/client';
|
|
2
2
|
import { FileToolModifier } from '#file_tool_modifier';
|
|
3
3
|
import {
|
|
4
4
|
Tool,
|
|
@@ -42,6 +42,7 @@ import logger from '../utils/logger';
|
|
|
42
42
|
import { ExecuteToolFn, GlobalExecuteToolFn } from '../types/provider.types';
|
|
43
43
|
import {
|
|
44
44
|
ComposioInvalidModifierError,
|
|
45
|
+
ComposioToolFetchError,
|
|
45
46
|
ComposioToolNotFoundError,
|
|
46
47
|
ComposioProviderNotDefinedError,
|
|
47
48
|
ComposioToolVersionRequiredError,
|
|
@@ -710,7 +711,17 @@ export class Tools<
|
|
|
710
711
|
if (error instanceof ComposioRequestCancelledError) {
|
|
711
712
|
throw error;
|
|
712
713
|
}
|
|
713
|
-
|
|
714
|
+
// The tools endpoint reports an unknown slug as 404 (or 400 for a
|
|
715
|
+
// malformed one). Anything else (401, 5xx, network) is not "not found",
|
|
716
|
+
// so keep the client error reachable as `cause` under a generic error.
|
|
717
|
+
if (error instanceof APIError && (error.status === 404 || error.status === 400)) {
|
|
718
|
+
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`, {
|
|
719
|
+
meta: { slug },
|
|
720
|
+
cause: error,
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
throw new ComposioToolFetchError(`Unable to retrieve tool with slug ${slug}`, {
|
|
724
|
+
meta: { slug },
|
|
714
725
|
cause: error,
|
|
715
726
|
});
|
|
716
727
|
}
|
|
@@ -1097,6 +1108,10 @@ export class Tools<
|
|
|
1097
1108
|
*
|
|
1098
1109
|
* @example Execute with a specific version (recommended for production)
|
|
1099
1110
|
* ```typescript
|
|
1111
|
+
* // Look up the tool's current version once, then pin that string in your code or config
|
|
1112
|
+
* const { version } = await composio.tools.getRawComposioToolBySlug('GITHUB_GET_REPOS');
|
|
1113
|
+
* console.log(version); // e.g. '20250909_00'
|
|
1114
|
+
*
|
|
1100
1115
|
* const result = await composio.tools.execute('GITHUB_GET_REPOS', {
|
|
1101
1116
|
* userId: 'default',
|
|
1102
1117
|
* version: '20250909_00',
|
|
@@ -1283,21 +1298,27 @@ export class Tools<
|
|
|
1283
1298
|
}
|
|
1284
1299
|
|
|
1285
1300
|
/**
|
|
1286
|
-
*
|
|
1301
|
+
* Generates arguments for a tool from a natural-language description of the task.
|
|
1287
1302
|
*
|
|
1288
|
-
*
|
|
1303
|
+
* Composio uses an LLM to fill the tool's input parameters from `text`. Review the
|
|
1304
|
+
* generated arguments before passing them to `tools.execute()`.
|
|
1289
1305
|
*
|
|
1290
|
-
* @param {string} slug - The
|
|
1291
|
-
* @param {ToolGetInputParams} body - The
|
|
1292
|
-
* @
|
|
1306
|
+
* @param {string} slug - The slug of the tool to generate arguments for
|
|
1307
|
+
* @param {ToolGetInputParams} body - The generation request
|
|
1308
|
+
* @param {string} body.text - What you want the tool to do, in natural language
|
|
1309
|
+
* @param {string} [body.custom_description] - Extra context about the tool for the LLM
|
|
1310
|
+
* @param {string} [body.system_prompt] - System prompt that steers the LLM
|
|
1311
|
+
* @param {string} [body.version] - Tool version to generate arguments for
|
|
1312
|
+
* @returns {Promise<ToolGetInputResponse>} The generated `arguments`, or an `error` when generation fails
|
|
1293
1313
|
*
|
|
1294
1314
|
* @example
|
|
1295
1315
|
* ```typescript
|
|
1296
|
-
*
|
|
1297
|
-
*
|
|
1298
|
-
*
|
|
1316
|
+
* const { arguments: args, error } = await composio.tools.getInput('GITHUB_CREATE_ISSUE', {
|
|
1317
|
+
* text: 'Open an issue in composiohq/composio titled "Docs typo" describing the broken link',
|
|
1318
|
+
* version: '20250909_00',
|
|
1299
1319
|
* });
|
|
1300
|
-
*
|
|
1320
|
+
* if (error) throw new Error(error);
|
|
1321
|
+
* console.log(args); // { owner: 'composiohq', repo: 'composio', title: 'Docs typo', ... }
|
|
1301
1322
|
* ```
|
|
1302
1323
|
*/
|
|
1303
1324
|
async getInput(
|
|
@@ -1312,26 +1333,35 @@ export class Tools<
|
|
|
1312
1333
|
}
|
|
1313
1334
|
|
|
1314
1335
|
/**
|
|
1315
|
-
*
|
|
1336
|
+
* Sends an HTTP request to a toolkit's API, authenticated as a connected account.
|
|
1316
1337
|
*
|
|
1317
|
-
*
|
|
1318
|
-
*
|
|
1338
|
+
* Use it to call an endpoint that no predefined tool covers. Composio injects the
|
|
1339
|
+
* connected account's credentials on the server side.
|
|
1319
1340
|
*
|
|
1320
|
-
*
|
|
1321
|
-
*
|
|
1341
|
+
* A relative `endpoint` is appended to the toolkit's base URL, and that base URL can
|
|
1342
|
+
* already include a path. Google Calendar's base URL is
|
|
1343
|
+
* `https://www.googleapis.com/calendar/v3`, so pass `/users/me/calendarList`, not
|
|
1344
|
+
* `/calendar/v3/users/me/calendarList` (which resolves to `/calendar/v3/calendar/v3/...`
|
|
1345
|
+
* and returns a 404 from Google). An absolute URL on the same domain is sent as-is.
|
|
1346
|
+
*
|
|
1347
|
+
* @param {ToolProxyParams} body - The proxy request
|
|
1348
|
+
* @param {string} body.endpoint - Path relative to the toolkit's base URL, or an absolute URL
|
|
1349
|
+
* @param {'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'} body.method - HTTP method
|
|
1350
|
+
* @param {string} [body.connectedAccountId] - The connected account to authenticate as
|
|
1351
|
+
* @param {unknown} [body.body] - JSON request body
|
|
1352
|
+
* @param {Array<{ in: 'query' | 'header'; name: string; value: string | number }>} [body.parameters] - Extra query parameters or headers
|
|
1353
|
+
* @returns {Promise<ToolProxyResponse>} The upstream status, headers, and parsed body
|
|
1322
1354
|
*
|
|
1323
1355
|
* @example
|
|
1324
1356
|
* ```typescript
|
|
1325
|
-
* //
|
|
1326
|
-
* const
|
|
1327
|
-
*
|
|
1328
|
-
*
|
|
1329
|
-
*
|
|
1330
|
-
*
|
|
1331
|
-
* method: 'GET'
|
|
1332
|
-
* }
|
|
1357
|
+
* // Google Calendar's base URL is https://www.googleapis.com/calendar/v3
|
|
1358
|
+
* const { status, data } = await composio.tools.proxyExecute({
|
|
1359
|
+
* endpoint: '/users/me/calendarList',
|
|
1360
|
+
* method: 'GET',
|
|
1361
|
+
* connectedAccountId: 'ca_...',
|
|
1362
|
+
* parameters: [{ in: 'query', name: 'maxResults', value: 10 }],
|
|
1333
1363
|
* });
|
|
1334
|
-
* console.log(
|
|
1364
|
+
* console.log(status, data);
|
|
1335
1365
|
* ```
|
|
1336
1366
|
*/
|
|
1337
1367
|
async proxyExecute(
|
package/src/models/Triggers.ts
CHANGED
|
@@ -612,6 +612,10 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
612
612
|
*
|
|
613
613
|
* @param fn - The function to call when a trigger is received
|
|
614
614
|
* @param filters - The filters to apply to the triggers
|
|
615
|
+
* @param onSubscriptionError - Optional callback invoked with the raw Pusher payload when
|
|
616
|
+
* the underlying subscription fails (for example on auth or permission rejection). The
|
|
617
|
+
* subscribe promise still resolves; this is the only programmatic signal of the failure.
|
|
618
|
+
* Errors thrown from — or promises rejected by — the callback are contained and logged.
|
|
615
619
|
*
|
|
616
620
|
* @example
|
|
617
621
|
* ```ts
|
|
@@ -623,7 +627,8 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
623
627
|
*/
|
|
624
628
|
async subscribe(
|
|
625
629
|
fn: (_data: IncomingTriggerPayload) => void,
|
|
626
|
-
filters: TriggerSubscribeParams = {}
|
|
630
|
+
filters: TriggerSubscribeParams = {},
|
|
631
|
+
onSubscriptionError?: (data: Record<string, unknown>) => void
|
|
627
632
|
) {
|
|
628
633
|
if (!fn) throw new Error('Function is required for trigger subscription');
|
|
629
634
|
|
|
@@ -651,7 +656,7 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
|
|
|
651
656
|
} else {
|
|
652
657
|
logger.debug('Trigger does not match filters', JSON.stringify(parsedFilters.data, null, 2));
|
|
653
658
|
}
|
|
654
|
-
});
|
|
659
|
+
}, onSubscriptionError);
|
|
655
660
|
}
|
|
656
661
|
|
|
657
662
|
/**
|
|
@@ -162,22 +162,43 @@ export class PusherService {
|
|
|
162
162
|
* @param channelName - The name of the Pusher channel to subscribe to
|
|
163
163
|
* @param event - The event to subscribe to
|
|
164
164
|
* @param fn - The function to call when the event is received
|
|
165
|
+
* @param onSubscriptionError - Optional callback invoked with the raw payload when the
|
|
166
|
+
* Pusher subscription fails (for example on auth or permission rejection). Errors thrown
|
|
167
|
+
* from — or promises rejected by — this callback are contained and logged, never rethrown.
|
|
165
168
|
*/
|
|
166
|
-
async subscribe(
|
|
169
|
+
async subscribe(
|
|
170
|
+
fn: (data: Record<string, unknown>) => void,
|
|
171
|
+
onSubscriptionError?: (data: Record<string, unknown>) => void
|
|
172
|
+
) {
|
|
167
173
|
try {
|
|
168
174
|
logger.debug(`[PusherService] Subscribing to channel: ${this.pusherChannel}`);
|
|
169
175
|
const pusherClient = await this.getPusherClient();
|
|
170
176
|
const channel = await pusherClient.subscribe(this.pusherChannel);
|
|
171
177
|
|
|
172
178
|
// add subscription error handling
|
|
179
|
+
const logCallbackFailure = (callbackError: unknown) => {
|
|
180
|
+
const errorMessage =
|
|
181
|
+
callbackError instanceof Error ? callbackError.message : String(callbackError);
|
|
182
|
+
logger.error('❌ Error in subscription error callback:', errorMessage);
|
|
183
|
+
};
|
|
173
184
|
channel.bind('pusher:subscription_error', (data: Record<string, unknown>) => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
185
|
+
logger.error('Trigger subscription error:', data);
|
|
186
|
+
|
|
187
|
+
// surface the failure to the caller without letting a faulty
|
|
188
|
+
// handler crash the host (same containment as the trigger callback).
|
|
189
|
+
// A handler may be async: contain rejected promises too, or the
|
|
190
|
+
// rejection escapes as an unhandled rejection after subscribe()
|
|
191
|
+
// already resolved.
|
|
192
|
+
try {
|
|
193
|
+
Promise.resolve(onSubscriptionError?.(data)).catch(logCallbackFailure);
|
|
194
|
+
} catch (callbackError: unknown) {
|
|
195
|
+
logCallbackFailure(callbackError);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
// log success only when Pusher itself confirms the subscription
|
|
200
|
+
channel.bind('pusher:subscription_succeeded', () => {
|
|
201
|
+
logger.info(`✅ Subscribed to triggers. You should start receiving events now.`);
|
|
181
202
|
});
|
|
182
203
|
|
|
183
204
|
// wrap the callback to handle errors
|
|
@@ -192,8 +213,6 @@ export class PusherService {
|
|
|
192
213
|
};
|
|
193
214
|
|
|
194
215
|
this.bindWithChunking(channel as PusherClient, 'trigger_to_client', safeCallback);
|
|
195
|
-
|
|
196
|
-
logger.info(`✅ Subscribed to triggers. You should start receiving events now.`);
|
|
197
216
|
} catch (error) {
|
|
198
217
|
throw new ComposioFailedToSubscribeToPusherChannelError(
|
|
199
218
|
'Failed to subscribe to Pusher channel',
|
|
@@ -5,6 +5,7 @@ import { ConnectionRequest } from './connectionRequest.types';
|
|
|
5
5
|
import type { ComposioRequestOptions } from './requestOptions.types';
|
|
6
6
|
import type { ToolRouterSessionFilesMount } from '../models/ToolRouterSessionFileMount';
|
|
7
7
|
import type { SessionCreateResponse } from '@composio/client/resources/tool-router/session/session.mjs';
|
|
8
|
+
import { ConnectedAccountExperimentalSchema } from './connectedAccounts.types';
|
|
8
9
|
import type {
|
|
9
10
|
CustomTool,
|
|
10
11
|
CustomToolkit,
|
|
@@ -591,7 +592,9 @@ export type ToolRouterSessionExecuteFn = (
|
|
|
591
592
|
|
|
592
593
|
export interface ToolRouterSessionExecuteOptions {
|
|
593
594
|
/**
|
|
594
|
-
* Account identifier for direct app tool execution
|
|
595
|
+
* Account identifier for direct app tool execution. Accepted on every project:
|
|
596
|
+
* in multi-account sessions it picks the account; on single-account projects it
|
|
597
|
+
* must match one of the session's active connections for the toolkit.
|
|
595
598
|
* Meta/helper tools either ignore this top-level field or define
|
|
596
599
|
* their own account-selection fields, for example
|
|
597
600
|
* COMPOSIO_MULTI_EXECUTE_TOOL.tools[].account.
|
|
@@ -605,7 +608,16 @@ export type ToolRouterSessionWorkbenchConfig = SessionCreateResponse.Config.Work
|
|
|
605
608
|
|
|
606
609
|
export type ToolRouterSessionWarning = SessionCreateResponse.Warning;
|
|
607
610
|
|
|
611
|
+
/**
|
|
612
|
+
* Server-side session configuration as returned by the API: toolkit and tool
|
|
613
|
+
* allowlists, tags, auth configs, connected accounts, manage_connections,
|
|
614
|
+
* preload, sandbox (`workbench`), search and execute settings.
|
|
615
|
+
*/
|
|
616
|
+
export type ToolRouterSessionConfig = SessionCreateResponse.Config;
|
|
617
|
+
|
|
608
618
|
export interface ToolRouterSessionMetadata {
|
|
619
|
+
/** Present on every session built from an API response; the constructor synthesises a minimal config when absent. */
|
|
620
|
+
config?: ToolRouterSessionConfig;
|
|
609
621
|
preload?: ToolRouterSessionPreloadConfig;
|
|
610
622
|
workbench?: ToolRouterSessionWorkbenchConfig;
|
|
611
623
|
configVersion?: number;
|
|
@@ -699,7 +711,9 @@ export const ToolRouterUpdateSessionConfigSchema = z
|
|
|
699
711
|
|
|
700
712
|
export type ToolRouterUpdateSessionConfig = z.infer<typeof ToolRouterUpdateSessionConfigSchema>;
|
|
701
713
|
|
|
702
|
-
export type ToolRouterSessionUpdateFn = (
|
|
714
|
+
export type ToolRouterSessionUpdateFn = (
|
|
715
|
+
config: ToolRouterUpdateSessionConfig
|
|
716
|
+
) => Promise<ToolRouterSessionConfig>;
|
|
703
717
|
|
|
704
718
|
export const ToolRouterSessionDeleteResponseSchema = z.object({
|
|
705
719
|
sessionId: z.string(),
|
|
@@ -711,6 +725,35 @@ export type ToolRouterSessionDeleteFn = (
|
|
|
711
725
|
requestOptions?: ComposioRequestOptions
|
|
712
726
|
) => Promise<ToolRouterSessionDeleteResponse>;
|
|
713
727
|
|
|
728
|
+
export const ToolRouterSessionEnsureConnectedOptionsSchema = z.object({
|
|
729
|
+
callbackUrl: z.string().optional(),
|
|
730
|
+
alias: z.string().optional(),
|
|
731
|
+
experimental: ConnectedAccountExperimentalSchema.optional(),
|
|
732
|
+
/** Max time to wait for a newly-initiated connection to become active, in milliseconds. Defaults to 60000. */
|
|
733
|
+
timeout: z.number().int().positive().optional(),
|
|
734
|
+
});
|
|
735
|
+
export type ToolRouterSessionEnsureConnectedOptions = z.infer<
|
|
736
|
+
typeof ToolRouterSessionEnsureConnectedOptionsSchema
|
|
737
|
+
>;
|
|
738
|
+
|
|
739
|
+
export type ToolRouterSessionEnsureConnectedResult = {
|
|
740
|
+
/** Canonical slug of the toolkit this call ensured. */
|
|
741
|
+
toolkit: string;
|
|
742
|
+
/** True when the session already had an active connection (or a no-auth toolkit) — no link was created. */
|
|
743
|
+
wasConnected: boolean;
|
|
744
|
+
/** The active connected account backing the toolkit. Omitted for no-auth toolkits. */
|
|
745
|
+
connectedAccount?: {
|
|
746
|
+
id: string;
|
|
747
|
+
status: string;
|
|
748
|
+
};
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
export type ToolRouterSessionEnsureConnectedFn = (
|
|
752
|
+
toolkit: string,
|
|
753
|
+
options?: ToolRouterSessionEnsureConnectedOptions,
|
|
754
|
+
requestOptions?: ComposioRequestOptions
|
|
755
|
+
) => Promise<ToolRouterSessionEnsureConnectedResult>;
|
|
756
|
+
|
|
714
757
|
/** Session type returned by ToolRouter.create() and ToolRouter.use() */
|
|
715
758
|
export interface Session<
|
|
716
759
|
TToolCollection,
|
|
@@ -719,6 +762,12 @@ export interface Session<
|
|
|
719
762
|
> {
|
|
720
763
|
sessionId: string;
|
|
721
764
|
mcp: ToolRouterMCPServerConfig;
|
|
765
|
+
/**
|
|
766
|
+
* Server-side session configuration (toolkit/tool allowlists, tags, preload,
|
|
767
|
+
* sandbox, manage_connections) as returned by the API. Refreshed in place by
|
|
768
|
+
* `update()`.
|
|
769
|
+
*/
|
|
770
|
+
config: ToolRouterSessionConfig;
|
|
722
771
|
/** Stored preload configuration for this session. */
|
|
723
772
|
preload: ToolRouterSessionPreloadConfig;
|
|
724
773
|
/**
|
|
@@ -739,12 +788,14 @@ export interface Session<
|
|
|
739
788
|
warnings: ToolRouterSessionWarning[];
|
|
740
789
|
tools: ToolRouterToolsFn<TToolCollection, TTool, TProvider>;
|
|
741
790
|
authorize: ToolRouterAuthorizeFn;
|
|
791
|
+
/** Ensure a toolkit has an active connection, linking and waiting only when needed. */
|
|
792
|
+
ensureConnected: ToolRouterSessionEnsureConnectedFn;
|
|
742
793
|
toolkits: ToolRouterToolkitsFn;
|
|
743
794
|
/** Search for tools by semantic use case */
|
|
744
795
|
search: ToolRouterSessionSearchFn;
|
|
745
796
|
/** Execute a tool within the session */
|
|
746
797
|
execute: ToolRouterSessionExecuteFn;
|
|
747
|
-
/** Update the session configuration. Mutates this session in-place
|
|
798
|
+
/** Update the session configuration. Mutates this session in-place and resolves to the updated `config`. */
|
|
748
799
|
update: ToolRouterSessionUpdateFn;
|
|
749
800
|
/** Delete the session. Deleted sessions are no longer retrievable or executable. */
|
|
750
801
|
delete: ToolRouterSessionDeleteFn;
|