@composio/core 0.18.1 → 0.20.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-VRfWzMix.d.mts → CustomTool-B3m-188G.d.mts} +1 -1
- package/dist/{CustomTool-Bz0f52QR.mjs → CustomTool-fYEFjSLM.mjs} +1 -1
- package/dist/{FileModifierErrors-CwB-Inm9.mjs → FileModifierErrors-CdGSABoq.mjs} +1 -1
- package/dist/{FileToolModifier.utils.neutral-D_YkHwZP.mjs → FileToolModifier.utils.neutral-DWFpnsj2.mjs} +4 -2
- package/dist/{SsrfErrors-xhdVE4yw.mjs → SsrfErrors-DiQldIdC.mjs} +32 -17
- package/dist/{Telemetry-Dw9W5RSp.mjs → Telemetry-JRJJYS4I.mjs} +2 -2
- package/dist/{cancellation-P5YUlcfz.mjs → cancellation-Dwa9lGHA.mjs} +7 -5
- package/dist/{composio-Cb3d1jFe.d.mts → composio-B36OXii1.d.mts} +3017 -144
- package/dist/{customTool.types-B6ej_8XZ.d.mts → customTool.types-C436M_D0.d.mts} +525 -101
- package/dist/docs/reference/sdk-reference/typescript/auth-configs.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/composio.mdx +8 -15
- 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 +7 -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 +8 -1
- package/dist/docs/reference/sdk-reference/typescript/session-files.mdx +10 -10
- package/dist/docs/reference/sdk-reference/typescript/session.mdx +117 -24
- package/dist/docs/reference/sdk-reference/typescript/sessions.mdx +24 -10
- package/dist/docs/reference/sdk-reference/typescript/toolkits.mdx +151 -14
- package/dist/docs/reference/sdk-reference/typescript/tools.mdx +50 -40
- package/dist/docs/reference/sdk-reference/typescript/triggers.mdx +26 -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-Ue9wMrPK.mjs → errors-D_A4b2c2.mjs} +143 -4
- package/dist/experimental/index.d.mts +2 -2
- package/dist/experimental/index.mjs +1 -1
- package/dist/{fileUtils.node-KE5Fa-af.mjs → fileUtils.node-DNLhLg0W.mjs} +8 -6
- package/dist/index.d.mts +418 -146
- package/dist/index.mjs +2728 -349
- 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-BlLp-Yo2.mjs} +10 -7
- package/dist/{ssrfGuard.node-BLX6b-Rf.mjs → ssrfGuard.node-BZ270bcu.mjs} +104 -14
- package/dist/{types-CGdgK442.d.mts → types-Br3GBya5.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 +9 -9
- package/src/composio.ts +207 -10
- package/src/errors/ConnectedAccountsErrors.ts +47 -0
- package/src/errors/SDKErrors.ts +52 -0
- package/src/errors/ToolErrors.ts +24 -0
- package/src/errors/ToolRouterErrors.ts +57 -0
- package/src/errors/index.ts +3 -0
- package/src/index.ts +15 -0
- package/src/lib/toolRouterMcp.ts +132 -0
- package/src/lib/toolRouterParams.ts +116 -29
- 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/MCP.ts +29 -15
- package/src/models/ToolRouter.ts +43 -14
- package/src/models/ToolRouterSession.ts +224 -16
- package/src/models/Toolkits.ts +181 -2
- package/src/models/Tools.ts +58 -26
- package/src/models/Triggers.ts +10 -90
- package/src/models/Usage.ts +119 -0
- package/src/models/Webhooks.ts +520 -0
- package/src/services/pusher/Pusher.ts +46 -16
- 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 +259 -14
- package/src/types/toolkit.types.ts +161 -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/jsonSchema.ts +4 -1
- package/src/utils/logger.ts +39 -7
- package/src/utils/sdk.ts +385 -22
- package/src/utils/ssrfGuard.node.ts +127 -13
- package/src/utils/ssrfGuard.workerd.ts +11 -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 +183 -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
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { telemetry } from '../telemetry/Telemetry';
|
|
2
|
-
import { Composio as ComposioClient, BadRequestError } from '@composio/client';
|
|
2
|
+
import { Composio as ComposioClient, BadRequestError, ConflictError } from '@composio/client';
|
|
3
3
|
import type { BaseComposioProvider } from '../provider/BaseProvider';
|
|
4
4
|
import type { ComposioConfig } from '../composio';
|
|
5
5
|
import type { ComposioRequestOptions } from '../types/requestOptions.types';
|
|
6
6
|
import { withCancellation } from '../utils/cancellation';
|
|
7
7
|
import { ComposioRequestCancelledError } from '../errors/SDKErrors';
|
|
8
|
+
import { ComposioSessionConfigConflictError } from '../errors/ToolRouterErrors';
|
|
8
9
|
import {
|
|
9
10
|
ToolRouterMCPServerConfig,
|
|
10
11
|
SessionExperimental,
|
|
@@ -16,12 +17,19 @@ import {
|
|
|
16
17
|
ToolRouterSessionExecuteResponseSchema,
|
|
17
18
|
ToolRouterSessionProxyExecuteResponse,
|
|
18
19
|
ToolRouterSessionExecuteOptions,
|
|
20
|
+
ToolRouterSessionConfig,
|
|
19
21
|
ToolRouterSessionMetadata,
|
|
20
22
|
ToolRouterSessionPreloadConfig,
|
|
21
23
|
ToolRouterSessionWorkbenchConfig,
|
|
22
24
|
ToolRouterSessionWarning,
|
|
23
25
|
ToolRouterUpdateSessionConfig,
|
|
24
26
|
ToolRouterUpdateSessionConfigSchema,
|
|
27
|
+
ToolRouterSessionEnsureConnectedOptions,
|
|
28
|
+
ToolRouterSessionEnsureConnectedOptionsSchema,
|
|
29
|
+
ToolRouterSessionEnsureConnectedResult,
|
|
30
|
+
ToolRouterSessionListConfigHistoryOptions,
|
|
31
|
+
ToolRouterSessionListConfigHistoryOptionsSchema,
|
|
32
|
+
type ToolRouterSessionListConfigHistoryResponse,
|
|
25
33
|
type ToolRouterSessionDeleteResponse,
|
|
26
34
|
} from '../types/toolRouter.types';
|
|
27
35
|
import {
|
|
@@ -60,6 +68,8 @@ import type { SessionProxyExecuteParams } from '../types/toolRouter.types';
|
|
|
60
68
|
import type {
|
|
61
69
|
SessionExecuteParams,
|
|
62
70
|
SessionLinkParams,
|
|
71
|
+
SessionPatchParams,
|
|
72
|
+
SessionPatchResponse,
|
|
63
73
|
SessionSearchParams,
|
|
64
74
|
} from '@composio/client/resources/tool-router/session/session.mjs';
|
|
65
75
|
import { SessionProxyExecuteParamsSchema } from '../types/toolRouter.types';
|
|
@@ -118,9 +128,20 @@ export class ToolRouterSession<
|
|
|
118
128
|
/** 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
129
|
public readonly mcp: ToolRouterMCPServerConfig;
|
|
120
130
|
public readonly experimental: SessionExperimental;
|
|
131
|
+
/**
|
|
132
|
+
* Server-side session configuration (toolkit/tool allowlists, tags, preload,
|
|
133
|
+
* sandbox, manage_connections) as returned by the API. Refreshed in place by
|
|
134
|
+
* `update()`.
|
|
135
|
+
*/
|
|
136
|
+
public config: ToolRouterSessionConfig;
|
|
121
137
|
public preload: ToolRouterSessionPreloadConfig;
|
|
122
138
|
/** Resolved sandbox (code-execution) config returned by the API. `enable` defaults to `true` server-side. */
|
|
123
139
|
public sandbox?: ToolRouterSessionWorkbenchConfig;
|
|
140
|
+
/**
|
|
141
|
+
* Version of the server-side configuration this object last observed.
|
|
142
|
+
* Refreshed in place by `update()`, which sends it as the
|
|
143
|
+
* `expected_config_version` precondition by default.
|
|
144
|
+
*/
|
|
124
145
|
public configVersion?: number;
|
|
125
146
|
public warnings: ToolRouterSessionWarning[];
|
|
126
147
|
private readonly preloadedCustomToolSlugs: string[];
|
|
@@ -131,7 +152,7 @@ export class ToolRouterSession<
|
|
|
131
152
|
|
|
132
153
|
constructor(
|
|
133
154
|
private readonly client: ComposioClient,
|
|
134
|
-
private readonly
|
|
155
|
+
private readonly sdkConfig: ComposioConfig<TProvider> | undefined,
|
|
135
156
|
sessionId: string,
|
|
136
157
|
mcp: ToolRouterMCPServerConfig,
|
|
137
158
|
experimentalOverrides?: Pick<SessionExperimental, 'assistivePrompt'>,
|
|
@@ -139,6 +160,13 @@ export class ToolRouterSession<
|
|
|
139
160
|
private readonly userId?: string,
|
|
140
161
|
metadata?: ToolRouterSessionMetadata
|
|
141
162
|
) {
|
|
163
|
+
const config: ToolRouterSessionConfig = metadata?.config ?? {
|
|
164
|
+
user_id: userId ?? '',
|
|
165
|
+
execute: {},
|
|
166
|
+
search: {},
|
|
167
|
+
preload: { tools: [] },
|
|
168
|
+
premium_usage: false,
|
|
169
|
+
};
|
|
142
170
|
if (customToolsMap && !userId) {
|
|
143
171
|
throw new Error('userId is required when custom tools are bound to a session.');
|
|
144
172
|
}
|
|
@@ -148,8 +176,9 @@ export class ToolRouterSession<
|
|
|
148
176
|
assistivePrompt: experimentalOverrides?.assistivePrompt,
|
|
149
177
|
files: new ToolRouterSessionFilesMount(client, sessionId),
|
|
150
178
|
};
|
|
151
|
-
this.
|
|
152
|
-
this.
|
|
179
|
+
this.config = config;
|
|
180
|
+
this.preload = metadata?.preload ?? config.preload;
|
|
181
|
+
this.sandbox = metadata?.workbench ?? config.workbench;
|
|
153
182
|
this.configVersion = metadata?.configVersion;
|
|
154
183
|
this.warnings = metadata?.warnings ?? [];
|
|
155
184
|
this.preloadedCustomToolSlugs = metadata?.preloadedCustomToolSlugs ?? [];
|
|
@@ -193,7 +222,7 @@ export class ToolRouterSession<
|
|
|
193
222
|
modifiers?: SessionMetaToolOptions,
|
|
194
223
|
requestOptions?: ComposioRequestOptions
|
|
195
224
|
): Promise<ReturnType<TProvider['wrapTools']>> {
|
|
196
|
-
const ToolsModel = new Tools<TToolCollection, TTool, TProvider>(this.client, this.
|
|
225
|
+
const ToolsModel = new Tools<TToolCollection, TTool, TProvider>(this.client, this.sdkConfig);
|
|
197
226
|
const rawTools = await ToolsModel.getRawToolRouterSessionTools(
|
|
198
227
|
this.sessionId,
|
|
199
228
|
undefined,
|
|
@@ -226,13 +255,13 @@ export class ToolRouterSession<
|
|
|
226
255
|
);
|
|
227
256
|
};
|
|
228
257
|
|
|
229
|
-
if (!this.
|
|
258
|
+
if (!this.sdkConfig?.provider) {
|
|
230
259
|
throw new Error(
|
|
231
260
|
'A provider is required when using custom tools with session.tools(). ' +
|
|
232
261
|
'Pass a provider in the Composio constructor.'
|
|
233
262
|
);
|
|
234
263
|
}
|
|
235
|
-
return this.
|
|
264
|
+
return this.sdkConfig.provider.wrapTools(sessionTools, routingExecuteFn) as ReturnType<
|
|
236
265
|
TProvider['wrapTools']
|
|
237
266
|
>;
|
|
238
267
|
}
|
|
@@ -470,6 +499,83 @@ export class ToolRouterSession<
|
|
|
470
499
|
);
|
|
471
500
|
}
|
|
472
501
|
|
|
502
|
+
/**
|
|
503
|
+
* Ensure a toolkit has an active connection in this session, reconciling
|
|
504
|
+
* `authorize()`/`session.link` with the session's active connection state.
|
|
505
|
+
*
|
|
506
|
+
* If the session already resolves an ACTIVE connection (or the toolkit is
|
|
507
|
+
* no-auth), this returns immediately without creating a link — unlike
|
|
508
|
+
* `authorize()`, which always starts a new link flow, even when one is
|
|
509
|
+
* already connected. Otherwise it starts the authorization flow and waits
|
|
510
|
+
* for the new connection to become ACTIVE.
|
|
511
|
+
*
|
|
512
|
+
* For interactive flows that should surface the redirect URL instead of
|
|
513
|
+
* blocking, use `authorize()` and its `waitForConnection()` directly.
|
|
514
|
+
*
|
|
515
|
+
* @param toolkit - The toolkit slug to ensure a connection for (e.g. 'github')
|
|
516
|
+
* @param options - Optional authorization options plus `timeout` (ms to wait
|
|
517
|
+
* for a newly-initiated connection, default 60000)
|
|
518
|
+
* @returns The toolkit's canonical slug, whether it was already connected,
|
|
519
|
+
* and the active connected account (omitted for no-auth toolkits)
|
|
520
|
+
* @throws {ValidationError} If the options fail validation
|
|
521
|
+
* @throws {ConnectionRequestTimeoutError} If a newly-initiated connection does
|
|
522
|
+
* not become active within `timeout`
|
|
523
|
+
* @throws {ConnectionRequestFailedError} If the new connection enters a failed,
|
|
524
|
+
* expired, or revoked state
|
|
525
|
+
*
|
|
526
|
+
* @example
|
|
527
|
+
* ```typescript
|
|
528
|
+
* const session = await composio.sessions.create({ toolkits: ['github'] });
|
|
529
|
+
* const { wasConnected, connectedAccount } = await session.ensureConnected('github');
|
|
530
|
+
* if (!wasConnected) console.log('Newly linked:', connectedAccount?.id);
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
async ensureConnected(
|
|
534
|
+
toolkit: string,
|
|
535
|
+
options?: ToolRouterSessionEnsureConnectedOptions,
|
|
536
|
+
requestOptions?: ComposioRequestOptions
|
|
537
|
+
): Promise<ToolRouterSessionEnsureConnectedResult> {
|
|
538
|
+
const parsedOptions = ToolRouterSessionEnsureConnectedOptionsSchema.safeParse(options ?? {});
|
|
539
|
+
if (!parsedOptions.success) {
|
|
540
|
+
throw new ValidationError('Failed to parse tool router ensureConnected options', {
|
|
541
|
+
cause: parsedOptions.error,
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
const { callbackUrl, alias, experimental, timeout } = parsedOptions.data;
|
|
545
|
+
|
|
546
|
+
const state = await this.toolkits({ toolkits: [toolkit] }, requestOptions);
|
|
547
|
+
const existing = state.items.find(item => item.slug.toLowerCase() === toolkit.toLowerCase());
|
|
548
|
+
|
|
549
|
+
if (existing?.isNoAuth) {
|
|
550
|
+
return { toolkit: existing.slug, wasConnected: true };
|
|
551
|
+
}
|
|
552
|
+
const activeAccount = existing?.connection?.connectedAccount;
|
|
553
|
+
if (existing?.connection?.isActive && activeAccount) {
|
|
554
|
+
return {
|
|
555
|
+
toolkit: existing.slug,
|
|
556
|
+
wasConnected: true,
|
|
557
|
+
connectedAccount: { id: activeAccount.id, status: activeAccount.status },
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
const request = await this.authorize(
|
|
562
|
+
toolkit,
|
|
563
|
+
{
|
|
564
|
+
...(callbackUrl !== undefined && { callbackUrl }),
|
|
565
|
+
...(alias !== undefined && { alias }),
|
|
566
|
+
...(experimental !== undefined && { experimental }),
|
|
567
|
+
},
|
|
568
|
+
requestOptions
|
|
569
|
+
);
|
|
570
|
+
const account = await request.waitForConnection(timeout);
|
|
571
|
+
|
|
572
|
+
return {
|
|
573
|
+
toolkit: existing?.slug ?? toolkit,
|
|
574
|
+
wasConnected: false,
|
|
575
|
+
connectedAccount: { id: account.id, status: account.status },
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
|
|
473
579
|
/**
|
|
474
580
|
* Query the connection state of toolkits in the session.
|
|
475
581
|
* Supports pagination and filtering by toolkit slugs.
|
|
@@ -567,7 +673,7 @@ export class ToolRouterSession<
|
|
|
567
673
|
* @param toolSlug - The tool slug to execute
|
|
568
674
|
* @param arguments_ - Optional tool arguments
|
|
569
675
|
* @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.
|
|
676
|
+
* @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
677
|
* @returns The tool execution result
|
|
572
678
|
*/
|
|
573
679
|
async execute(
|
|
@@ -663,23 +769,77 @@ export class ToolRouterSession<
|
|
|
663
769
|
|
|
664
770
|
/**
|
|
665
771
|
* Partially update the session configuration.
|
|
666
|
-
*
|
|
667
|
-
*
|
|
772
|
+
*
|
|
773
|
+
* Only the fields provided are changed; omitted fields are preserved. For
|
|
774
|
+
* each policy block `null` removes the stored override (which can increase
|
|
775
|
+
* access: `toolkits: null` restores the unrestricted default, while
|
|
776
|
+
* `toolkits: []` denies every app toolkit and is sent as-is). Supplied
|
|
777
|
+
* `tools`, `authConfigs` and `connectedAccounts` maps replace the stored
|
|
778
|
+
* map entirely. `manageConnections.callbackUrl: null` removes only the
|
|
779
|
+
* stored callback URL.
|
|
780
|
+
*
|
|
781
|
+
* The request carries the `configVersion` this object last observed as the
|
|
782
|
+
* `expected_config_version` precondition, so a concurrent change surfaces as
|
|
783
|
+
* {@link ComposioSessionConfigConflictError} (HTTP 409) instead of being
|
|
784
|
+
* overwritten. Pass `expectedConfigVersion` to send another version, or
|
|
785
|
+
* `expectedConfigVersion: false` to send no precondition (last writer
|
|
786
|
+
* wins). The PATCH is never retried by the transport, so a 409 is reported
|
|
787
|
+
* exactly once. On conflict this object is left unchanged: re-fetch the
|
|
788
|
+
* session with `sessions.use(sessionId)` and retry against the fresh
|
|
789
|
+
* `configVersion`.
|
|
790
|
+
*
|
|
791
|
+
* `config`, `configVersion`, `preload`, `sandbox` and `warnings` are
|
|
792
|
+
* refreshed in place only after a successful response, and the updated
|
|
793
|
+
* `config` is returned.
|
|
668
794
|
*/
|
|
669
795
|
async update(
|
|
670
796
|
config: ToolRouterUpdateSessionConfig,
|
|
671
797
|
requestOptions?: ComposioRequestOptions
|
|
672
|
-
): Promise<
|
|
798
|
+
): Promise<ToolRouterSessionConfig> {
|
|
673
799
|
const parsed = ToolRouterUpdateSessionConfigSchema.parse(config);
|
|
674
|
-
const
|
|
675
|
-
const
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
800
|
+
const body = transformToolRouterUpdateParams(parsed);
|
|
801
|
+
const expectedConfigVersion =
|
|
802
|
+
parsed.expectedConfigVersion === false
|
|
803
|
+
? undefined
|
|
804
|
+
: (parsed.expectedConfigVersion ?? this.configVersion);
|
|
805
|
+
if (expectedConfigVersion !== undefined) {
|
|
806
|
+
body.expected_config_version = expectedConfigVersion;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
let response: SessionPatchResponse;
|
|
810
|
+
try {
|
|
811
|
+
response = await withCancellation(
|
|
812
|
+
() =>
|
|
813
|
+
this.client.toolRouter.session.patch(
|
|
814
|
+
this.sessionId,
|
|
815
|
+
// The generated client does not type `expected_config_version` or
|
|
816
|
+
// the nullable policy blocks; the body is serialized as-is.
|
|
817
|
+
body as SessionPatchParams,
|
|
818
|
+
{ ...requestOptions, maxRetries: 0 }
|
|
819
|
+
),
|
|
820
|
+
requestOptions?.signal
|
|
821
|
+
);
|
|
822
|
+
} catch (error) {
|
|
823
|
+
if (error instanceof ConflictError) {
|
|
824
|
+
throw new ComposioSessionConfigConflictError(
|
|
825
|
+
expectedConfigVersion === undefined
|
|
826
|
+
? `Session ${this.sessionId} configuration changed while this update was in flight; re-fetch the session and retry the update`
|
|
827
|
+
: `Session ${this.sessionId} configuration is no longer at version ${expectedConfigVersion}; re-fetch the session and retry the update`,
|
|
828
|
+
{
|
|
829
|
+
cause: error,
|
|
830
|
+
meta: { sessionId: this.sessionId, expectedConfigVersion },
|
|
831
|
+
}
|
|
832
|
+
);
|
|
833
|
+
}
|
|
834
|
+
throw error;
|
|
835
|
+
}
|
|
836
|
+
|
|
679
837
|
this.configVersion = response.config_version;
|
|
838
|
+
this.config = response.config;
|
|
680
839
|
this.preload = response.config.preload;
|
|
681
840
|
this.sandbox = response.config.workbench;
|
|
682
841
|
this.warnings = response.warnings ?? [];
|
|
842
|
+
return this.config;
|
|
683
843
|
}
|
|
684
844
|
|
|
685
845
|
/**
|
|
@@ -692,6 +852,54 @@ export class ToolRouterSession<
|
|
|
692
852
|
return deleteToolRouterSession(this.client, this.sessionId, requestOptions);
|
|
693
853
|
}
|
|
694
854
|
|
|
855
|
+
/**
|
|
856
|
+
* Page through this session's configuration history, newest first. The
|
|
857
|
+
* first page starts with the live config (`isCurrent: true`); every
|
|
858
|
+
* `session.update()` archives the previous version as a history row.
|
|
859
|
+
*
|
|
860
|
+
* @param options - Optional `cursor` and `limit` (max 100)
|
|
861
|
+
* @returns The config versions on this page plus pagination info
|
|
862
|
+
* @throws {ValidationError} If the options fail validation
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```typescript
|
|
866
|
+
* const { items, nextCursor } = await session.listConfigHistory({ limit: 10 });
|
|
867
|
+
* console.log(items[0].version, items[0].isCurrent); // e.g. 3, true
|
|
868
|
+
* console.log(items[1].config.toolkits);
|
|
869
|
+
* ```
|
|
870
|
+
*/
|
|
871
|
+
async listConfigHistory(
|
|
872
|
+
options?: ToolRouterSessionListConfigHistoryOptions,
|
|
873
|
+
requestOptions?: ComposioRequestOptions
|
|
874
|
+
): Promise<ToolRouterSessionListConfigHistoryResponse> {
|
|
875
|
+
const parsedOptions = ToolRouterSessionListConfigHistoryOptionsSchema.safeParse(options ?? {});
|
|
876
|
+
if (!parsedOptions.success) {
|
|
877
|
+
throw new ValidationError('Failed to parse config history options', {
|
|
878
|
+
cause: parsedOptions.error,
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
const query = {
|
|
882
|
+
cursor: parsedOptions.data.cursor,
|
|
883
|
+
limit: parsedOptions.data.limit,
|
|
884
|
+
};
|
|
885
|
+
const response = await withCancellation(
|
|
886
|
+
() => this.client.toolRouter.session.configHistory(this.sessionId, query, requestOptions),
|
|
887
|
+
requestOptions?.signal
|
|
888
|
+
);
|
|
889
|
+
return {
|
|
890
|
+
items: response.items.map(item => ({
|
|
891
|
+
version: item.version,
|
|
892
|
+
createdAt: item.created_at,
|
|
893
|
+
isCurrent: item.is_current,
|
|
894
|
+
config: item.config,
|
|
895
|
+
})),
|
|
896
|
+
nextCursor: response.next_cursor ?? null,
|
|
897
|
+
totalPages: response.total_pages,
|
|
898
|
+
currentPage: response.current_page,
|
|
899
|
+
totalItems: response.total_items,
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
|
|
695
903
|
// ── Private helpers ──────────────────────────────────────────
|
|
696
904
|
|
|
697
905
|
/** Check if this session has any custom tools bound. */
|
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,
|
|
@@ -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';
|
|
@@ -16,9 +26,13 @@ import { ConnectionRequest } from '../types/connectionRequest.types';
|
|
|
16
26
|
import { telemetry } from '../telemetry/Telemetry';
|
|
17
27
|
import { AuthSchemeType } from '../types/authConfigs.types';
|
|
18
28
|
import logger from '../utils/logger';
|
|
19
|
-
import { APIError } from 'openai';
|
|
20
29
|
import {
|
|
30
|
+
transformToolkitChangelogResponse,
|
|
31
|
+
transformToolkitListGrantContextsParams,
|
|
32
|
+
transformToolkitListGrantContextsResponse,
|
|
21
33
|
transformToolkitListResponse,
|
|
34
|
+
transformToolkitRecommendScopesParams,
|
|
35
|
+
transformToolkitRecommendScopesResponse,
|
|
22
36
|
transformToolkitRetrieveCategoriesResponse,
|
|
23
37
|
transformToolkitRetrieveResponse,
|
|
24
38
|
} from '../utils/transformers/toolkits';
|
|
@@ -191,6 +205,171 @@ export class Toolkits {
|
|
|
191
205
|
return this.getToolkits(arg ?? {}, requestOptions);
|
|
192
206
|
}
|
|
193
207
|
|
|
208
|
+
/**
|
|
209
|
+
* Retrieves several toolkits by slug in a single request.
|
|
210
|
+
*
|
|
211
|
+
* Returns the same transformed shape as `composio.toolkits.get({ ... })`.
|
|
212
|
+
* Unknown slugs are simply absent from the result.
|
|
213
|
+
*
|
|
214
|
+
* @param {string[]} slugs - The toolkit slugs to retrieve (at least one)
|
|
215
|
+
* @param {ToolkitGetManyParams} [params] - Optional filters and pagination, as for `list`
|
|
216
|
+
* @returns {Promise<ToolKitListResponse>} The matching toolkits
|
|
217
|
+
* @throws {ValidationError} If `slugs` is empty or the params fail validation
|
|
218
|
+
* @throws {ComposioToolkitFetchError} If the request fails
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```typescript
|
|
222
|
+
* const toolkits = await composio.toolkits.getMany(['github', 'slack']);
|
|
223
|
+
* console.log(toolkits.map(toolkit => toolkit.name)); // ['GitHub', 'Slack']
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
async getMany(
|
|
227
|
+
slugs: string[],
|
|
228
|
+
params?: ToolkitGetManyParams,
|
|
229
|
+
requestOptions?: ComposioRequestOptions
|
|
230
|
+
): Promise<ToolKitListResponse> {
|
|
231
|
+
const parsedSlugs = ToolkitGetManySlugsSchema.safeParse(slugs);
|
|
232
|
+
if (!parsedSlugs.success) {
|
|
233
|
+
throw new ValidationError('Failed to parse toolkit slugs', {
|
|
234
|
+
cause: parsedSlugs.error,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
const parsedParams = ToolkitsGetManyParamsSchema.safeParse(params ?? {});
|
|
238
|
+
if (!parsedParams.success) {
|
|
239
|
+
throw new ValidationError('Failed to parse toolkit getMany params', {
|
|
240
|
+
cause: parsedParams.error,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
const body = {
|
|
244
|
+
toolkits: parsedSlugs.data,
|
|
245
|
+
category: parsedParams.data.category,
|
|
246
|
+
managed_by: parsedParams.data.managedBy,
|
|
247
|
+
sort_by: parsedParams.data.sortBy,
|
|
248
|
+
cursor: parsedParams.data.cursor,
|
|
249
|
+
limit: parsedParams.data.limit,
|
|
250
|
+
};
|
|
251
|
+
try {
|
|
252
|
+
const result = await withCancellation(
|
|
253
|
+
() => this.client.toolkits.retrieveMulti(body, requestOptions),
|
|
254
|
+
requestOptions?.signal
|
|
255
|
+
);
|
|
256
|
+
return transformToolkitListResponse(result);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
if (error instanceof ComposioRequestCancelledError) {
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
throw new ComposioToolkitFetchError('Failed to fetch toolkits', {
|
|
262
|
+
meta: { slugs: parsedSlugs.data },
|
|
263
|
+
cause: error,
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Retrieves the version changelog of every toolkit (the last 10 versions
|
|
270
|
+
* per toolkit).
|
|
271
|
+
*
|
|
272
|
+
* @returns {Promise<ToolkitChangelogResponse>} Toolkits with their recent version changelogs
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* ```typescript
|
|
276
|
+
* const { items } = await composio.toolkits.changelog();
|
|
277
|
+
* const github = items.find(item => item.slug === 'github');
|
|
278
|
+
* console.log(github?.versions[0]); // { version: '20250909_00', changelog: '...' }
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
async changelog(requestOptions?: ComposioRequestOptions): Promise<ToolkitChangelogResponse> {
|
|
282
|
+
const result = await withCancellation(
|
|
283
|
+
() => this.client.toolkits.retrieveChangelog(requestOptions),
|
|
284
|
+
requestOptions?.signal
|
|
285
|
+
);
|
|
286
|
+
return transformToolkitChangelogResponse(result);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Recommends the OAuth scopes to request so a connection can run the given
|
|
291
|
+
* tools.
|
|
292
|
+
* **Experimental — the API marks this endpoint beta; shape may change.**
|
|
293
|
+
*
|
|
294
|
+
* The answer comes in two variants: `leastPrivilege` (narrowest documented
|
|
295
|
+
* scope per requirement) and `fewest` (smallest set covering everything).
|
|
296
|
+
* Pass `toolkitVersion` from a previous answer to pin the computation.
|
|
297
|
+
*
|
|
298
|
+
* @param {string} toolkitSlug - The toolkit to recommend scopes for
|
|
299
|
+
* @param {ToolkitRecommendScopesParams} params - Tools to cover (`[]` for the whole toolkit), auth scheme, grant context and scope constraints
|
|
300
|
+
* @returns {Promise<ToolkitRecommendScopesResponse>} The recommended scope sets
|
|
301
|
+
* @throws {ValidationError} If the params fail validation
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* const { scopes } = await composio.toolkits.recommendScopes('gmail', {
|
|
306
|
+
* tools: ['GMAIL_SEND_EMAIL', 'GMAIL_FETCH_EMAILS'],
|
|
307
|
+
* });
|
|
308
|
+
* console.log(scopes.leastPrivilege);
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
async recommendScopes(
|
|
312
|
+
toolkitSlug: string,
|
|
313
|
+
params: ToolkitRecommendScopesParams,
|
|
314
|
+
requestOptions?: ComposioRequestOptions
|
|
315
|
+
): Promise<ToolkitRecommendScopesResponse> {
|
|
316
|
+
const parsedParams = ToolkitRecommendScopesParamsSchema.safeParse(params);
|
|
317
|
+
if (!parsedParams.success) {
|
|
318
|
+
throw new ValidationError('Failed to parse toolkit recommendScopes params', {
|
|
319
|
+
cause: parsedParams.error,
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
const body = transformToolkitRecommendScopesParams(parsedParams.data);
|
|
323
|
+
const result = await withCancellation(
|
|
324
|
+
() => this.client.toolkits.recommendScopes(toolkitSlug, body, requestOptions),
|
|
325
|
+
requestOptions?.signal
|
|
326
|
+
);
|
|
327
|
+
return transformToolkitRecommendScopesResponse(result);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Lists the grant-context dimensions a toolkit's scope recommendation
|
|
332
|
+
* depends on (for example the Google account type), with their allowed
|
|
333
|
+
* values and the default the API assumes.
|
|
334
|
+
* **Experimental — the API marks this endpoint beta; shape may change.**
|
|
335
|
+
*
|
|
336
|
+
* Pass a dimension and a value as `grantContext` to
|
|
337
|
+
* `composio.toolkits.recommendScopes()` to tailor the recommendation.
|
|
338
|
+
*
|
|
339
|
+
* @param {string} toolkitSlug - The toolkit to list grant contexts for
|
|
340
|
+
* @param {ToolkitListGrantContextsParams} [params] - Optional auth scheme and toolkit version
|
|
341
|
+
* @returns {Promise<ToolkitListGrantContextsResponse>} The dimensions and the default grant context
|
|
342
|
+
* @throws {ValidationError} If the params fail validation
|
|
343
|
+
*
|
|
344
|
+
* @example
|
|
345
|
+
* ```typescript
|
|
346
|
+
* const { grantContextDimensions } = await composio.toolkits.listGrantContexts('gmail');
|
|
347
|
+
* const [accountType] = grantContextDimensions;
|
|
348
|
+
* const { scopes } = await composio.toolkits.recommendScopes('gmail', {
|
|
349
|
+
* tools: ['GMAIL_SEND_EMAIL'],
|
|
350
|
+
* grantContext: { [accountType.dimension]: accountType.values[0] },
|
|
351
|
+
* });
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
async listGrantContexts(
|
|
355
|
+
toolkitSlug: string,
|
|
356
|
+
params?: ToolkitListGrantContextsParams,
|
|
357
|
+
requestOptions?: ComposioRequestOptions
|
|
358
|
+
): Promise<ToolkitListGrantContextsResponse> {
|
|
359
|
+
const parsedParams = ToolkitListGrantContextsParamsSchema.safeParse(params ?? {});
|
|
360
|
+
if (!parsedParams.success) {
|
|
361
|
+
throw new ValidationError('Failed to parse toolkit listGrantContexts params', {
|
|
362
|
+
cause: parsedParams.error,
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
const query = transformToolkitListGrantContextsParams(parsedParams.data);
|
|
366
|
+
const result = await withCancellation(
|
|
367
|
+
() => this.client.toolkits.retrieveScopesGrantContext(toolkitSlug, query, requestOptions),
|
|
368
|
+
requestOptions?.signal
|
|
369
|
+
);
|
|
370
|
+
return transformToolkitListGrantContextsResponse(result);
|
|
371
|
+
}
|
|
372
|
+
|
|
194
373
|
private async getAuthConfigFields(
|
|
195
374
|
toolkitSlug: string,
|
|
196
375
|
authScheme: AuthSchemeType | null,
|