@devries-cameron20 / composio Mirror · read-only / commits / 254fb245d
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 22:15 UTC

feat(core): add session.update() for partial session config updates

Exposes the existing PATCH /api/v3/tool_router/session/{id} endpoint through the SDK so users can modify session config after creation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Abir Taheer committed May 7, 2026 at 02:01 UTC 254fb245df37d2a3a25556a114d757290b730c9d
3 files changed +94 -4
ts/packages/core/src/lib/toolRouterParams.ts
+53 -1
@@ -1,4 +1,7 @@
1 -import { SessionCreateParams } from '@composio/client/resources/tool-router/session/session.mjs';
1 +import {
2 + SessionCreateParams,
3 + SessionPatchParams,
4 +} from '@composio/client/resources/tool-router/session/session.mjs';
5 import {
6 ToolRouterConfigTags,
7 ToolRouterConfigTools,
@@ -9,6 +12,7 @@ import {
12 ToolRouterToolkitsParamSchema,
13 ToolRouterToolkitsDisabledConfigSchema,
14 ToolRouterToolkitsEnabledConfigSchema,
15 + ToolRouterUpdateSessionConfig,
16 } from '../types/toolRouter.types';
17 import { ValidationError } from '../errors';
18 import { z } from 'zod';
@@ -165,3 +169,51 @@ export const transformToolRouterToolkitsParams = (
169 // Otherwise return as-is (already in enable/disable format)
170 return params as SessionCreateParams.Enable | SessionCreateParams.Disable;
171 };
172 +
173 +export const transformToolRouterUpdateParams = (
174 + config: ToolRouterUpdateSessionConfig
175 +): SessionPatchParams => {
176 + const params: SessionPatchParams = {};
177 +
178 + if (config.toolkits !== undefined) {
179 + params.toolkits = transformToolRouterToolkitsParams(config.toolkits);
180 + }
181 + if (config.tools !== undefined) {
182 + params.tools = transformToolRouterToolsParams(config.tools);
183 + }
184 + if (config.tags !== undefined) {
185 + params.tags = transformToolRouterTagsParams(config.tags);
186 + }
187 + if (config.authConfigs !== undefined) {
188 + params.auth_configs = config.authConfigs;
189 + }
190 + if (config.connectedAccounts !== undefined) {
191 + params.connected_accounts = config.connectedAccounts;
192 + }
193 + if (config.manageConnections !== undefined) {
194 + if (config.manageConnections === null) {
195 + params.manage_connections = null;
196 + } else {
197 + params.manage_connections = transformToolRouterManageConnectionsParams(config.manageConnections);
198 + }
199 + }
200 + if (config.workbench !== undefined) {
201 + if (config.workbench === null) {
202 + params.workbench = null;
203 + } else {
204 + params.workbench = transformToolRouterWorkbenchParams(config.workbench);
205 + }
206 + }
207 + if (config.multiAccount !== undefined) {
208 + if (config.multiAccount === null) {
209 + params.multi_account = null;
210 + } else {
211 + params.multi_account = transformToolRouterMultiAccountParams(config.multiAccount);
212 + }
213 + }
214 + if (config.preload !== undefined) {
215 + params.preload = config.preload;
216 + }
217 +
218 + return params;
219 +};
ts/packages/core/src/models/ToolRouterSession.ts
+18 -3
@@ -16,6 +16,7 @@ import {
16 ToolRouterSessionMetadata,
17 ToolRouterSessionPreloadConfig,
18 ToolRouterSessionWarning,
19 + ToolRouterUpdateSessionConfig,
20 } from '../types/toolRouter.types';
21 import {
22 transformSearchResponse,
@@ -49,6 +50,7 @@ import { findCustomTool, executeCustomTool } from './customToolExecution';
50 import { findCustomToolMapEntryByFinalSlug } from './CustomTool';
51 import { transformProxyParams } from './proxyParamsTransform';
52 import { inlineCustomToolsExperimental } from './inlineCustomToolsPayload';
53 +import { transformToolRouterUpdateParams } from '../lib/toolRouterParams';
54
55 const COMPOSIO_MULTI_EXECUTE_TOOL = 'COMPOSIO_MULTI_EXECUTE_TOOL';
56 export const DIRECT_CUSTOM_TOOL_DESCRIPTION_PREFIX =
@@ -62,9 +64,9 @@ export class ToolRouterSession<
64 public readonly sessionId: string;
65 public readonly mcp: ToolRouterMCPServerConfig;
66 public readonly experimental: SessionExperimental;
65 - public readonly preload: ToolRouterSessionPreloadConfig;
66 - public readonly configVersion?: number;
67 - public readonly warnings: ToolRouterSessionWarning[];
67 + public preload: ToolRouterSessionPreloadConfig;
68 + public configVersion?: number;
69 + public warnings: ToolRouterSessionWarning[];
70 private readonly preloadedCustomToolSlugs: string[];
71 private readonly inlineCustomToolsPayload: ToolRouterSessionMetadata['inlineCustomToolsPayload'];
72
@@ -471,6 +473,19 @@ export class ToolRouterSession<
473 };
474 }
475
476 + /**
477 + * Partially update the session configuration.
478 + * Only the fields provided will be changed; omitted fields are preserved.
479 + * Mutates this session's `configVersion`, `preload`, and `warnings` in-place.
480 + */
481 + async update(config: ToolRouterUpdateSessionConfig): Promise<void> {
482 + const params = transformToolRouterUpdateParams(config);
483 + const response = await this.client.toolRouter.session.patch(this.sessionId, params);
484 + this.configVersion = response.config_version;
485 + this.preload = response.config.preload;
486 + this.warnings = response.warnings ?? [];
487 + }
488 +
489 // ── Private helpers ──────────────────────────────────────────
490
491 /** Check if this session has any custom tools bound. */
ts/packages/core/src/types/toolRouter.types.ts
+23
@@ -612,6 +612,27 @@ export type ToolRouterSessionProxyExecuteFn = (
612 params: SessionProxyExecuteParams
613 ) => Promise<ToolRouterSessionProxyExecuteResponse>;
614
615 +/**
616 + * Config accepted by `session.update()`. Same camelCase shape as
617 + * `ToolRouterCreateSessionConfig` but every field is optional and
618 + * `manageConnections`, `workbench`, and `multiAccount` accept `null`
619 + * to clear the stored value. `sessionPreset` and custom tools/toolkits
620 + * are not supported on update.
621 + */
622 +export interface ToolRouterUpdateSessionConfig {
623 + toolkits?: ToolRouterCreateSessionConfig['toolkits'];
624 + tools?: ToolRouterCreateSessionConfig['tools'];
625 + tags?: ToolRouterCreateSessionConfig['tags'];
626 + authConfigs?: ToolRouterCreateSessionConfig['authConfigs'];
627 + connectedAccounts?: ToolRouterCreateSessionConfig['connectedAccounts'];
628 + manageConnections?: ToolRouterCreateSessionConfig['manageConnections'] | null;
629 + workbench?: ToolRouterCreateSessionConfig['workbench'] | null;
630 + multiAccount?: ToolRouterCreateSessionConfig['multiAccount'] | null;
631 + preload?: ToolRouterCreateSessionConfig['preload'];
632 +}
633 +
634 +export type ToolRouterSessionUpdateFn = (config: ToolRouterUpdateSessionConfig) => Promise<void>;
635 +
636 /** Session type returned by ToolRouter.create() and ToolRouter.use() */
637 export interface Session<
638 TToolCollection,
@@ -633,6 +654,8 @@ export interface Session<
654 search: ToolRouterSessionSearchFn;
655 /** Execute a tool within the session */
656 execute: ToolRouterSessionExecuteFn;
657 + /** Update the session configuration. Mutates this session in-place. */
658 + update: ToolRouterSessionUpdateFn;
659 /** Proxy an API call through Composio's auth layer using the session's connected account */
660 proxyExecute: ToolRouterSessionProxyExecuteFn;
661 /** List custom tools registered in this session, with their final slugs and schemas */