@devries-cameron20 / composio-1 / commits / c9b6525bc
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.

fix(core): expose string | string[] in connectedAccounts public type

The Zod `.transform()` added in #3358 made the inferred type of `ToolRouterCreateSessionConfig['connectedAccounts']` resolve to `Record<string, string[]>` (the post-transform output), so TypeScript users still hit `Type 'string' is not assignable to type 'string[]'` even though the runtime accepted strings. The runtime fix landed; the public TS surface didn't follow. Drop the schema transform and coerce inside `ToolRouter.create` instead, mirroring the Python implementation. The public type is now `Record<string, string | string[]>` and behavior is unchanged. While here: - fix the JSDoc on `connectedAccounts` (was `Record<string, string>`) - drop the inaccurate `@composio/client 0.1.0-alpha.70` bump line from the v31-connected-accounts-array changeset (this PR didn't perform that bump; it landed in a separate commit on `next`)

jkomyno committed May 7, 2026 at 12:35 UTC c9b6525bc9fb64702531a85482e27d33479cdacd
4 files changed +20 -10
.changeset/fix-connected-accounts-string-type.md new
+7
@@ -0,0 +1,7 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Fix `connectedAccounts` TypeScript type so a single `string` per toolkit is actually accepted by the public API.
6 +
7 +Previously the schema's `.transform()` made `ToolRouterCreateSessionConfig['connectedAccounts']` resolve to `Record<string, string[]>` (the post-transform output), so TypeScript users still got `Type 'string' is not assignable to type 'string[]'` even though the runtime accepted strings. Coercion now happens inside `ToolRouter.create`, mirroring the Python implementation, and the public type is `Record<string, string | string[]>`.
.changeset/v31-connected-accounts-array.md
+1 -1
@@ -4,4 +4,4 @@
4
5 `connectedAccounts` now accepts both `string` and `string[]` per toolkit.
6
7 -A single string is automatically coerced to an array to match the v3.1 API wire format. Existing callers passing `{ gmail: "ca_xxx" }` continue to work without changes. Only one account per toolkit is allowed when multi-account mode is disabled. Bumps `@composio/client` to `0.1.0-alpha.70`.
7 +A single string is automatically coerced to an array to match the v3.1 API wire format. Existing callers passing `{ gmail: "ca_xxx" }` continue to work without changes. Only one account per toolkit is allowed when multi-account mode is disabled.
ts/packages/core/src/models/ToolRouter.ts
+11 -1
@@ -179,10 +179,20 @@ export class ToolRouter<
179
180 const multiAccountPayload = transformToolRouterMultiAccountParams(routerConfig.multiAccount);
181
182 + const connectedAccountsPayload =
183 + routerConfig.connectedAccounts === undefined
184 + ? undefined
185 + : Object.fromEntries(
186 + Object.entries(routerConfig.connectedAccounts).map(([toolkit, ids]) => [
187 + toolkit,
188 + typeof ids === 'string' ? [ids] : ids,
189 + ])
190 + );
191 +
192 const payload: SessionCreateParams = {
193 user_id: userId,
194 auth_configs: routerConfig.authConfigs,
185 - connected_accounts: routerConfig.connectedAccounts,
195 + connected_accounts: connectedAccountsPayload,
196 toolkits: transformToolRouterToolkitsParams(routerConfig.toolkits),
197 tools: transformToolRouterToolsParams(routerConfig.tools),
198 tags: transformToolRouterTagsParams(routerConfig.tags),
ts/packages/core/src/types/toolRouter.types.ts
+1 -8
@@ -203,13 +203,6 @@ const ToolRouterCreateSessionConfigBaseSchema = z
203 .default({}),
204 connectedAccounts: z
205 .record(z.string(), z.union([z.string(), z.array(z.string())]))
206 - .transform((rec) => {
207 - const out: Record<string, string[]> = {};
208 - for (const [k, v] of Object.entries(rec)) {
209 - out[k] = typeof v === 'string' ? [v] : v;
210 - }
211 - return out;
212 - })
206 .describe(
207 'The connected accounts to use in the tool router session. The key is the toolkit slug, the value is a connected account id or an array of ids. Only one account per toolkit is allowed when multi-account mode is disabled.'
208 )
@@ -344,7 +337,7 @@ export const ToolRouterCreateSessionConfigSchema = z
337 * @param {Record<string, ToolRouterToolsParam | ToolRouterConfigTools>} tools - The tools to configure per toolkit (key is toolkit slug)
338 * @param {Array<'readOnlyHint' | 'destructiveHint' | 'idempotentHint' | 'openWorldHint'>} tags - Global tags to filter tools by behavior
339 * @param {Record<string, string>} authConfigs - The auth configs to use in the tool router session
347 - * @param {Record<string, string>} connectedAccounts - The connected accounts to use in the tool router session
340 + * @param {Record<string, string | string[]>} connectedAccounts - The connected accounts to use in the tool router session. A single string is coerced to a single-element array before being sent to the backend.
341 * @param {ToolRouterConfigManageConnectionsSchema | boolean} manageConnections - The config for the manage connections in the tool router session. Defaults to true, if set to false, you need to manage connections manually. If set to an object, you can configure the manage connections settings.
342 * @param {boolean} [manageConnections.enable] - Whether to use tools to manage connections in the tool router session @default true
343 * @param {string} [manageConnections.callbackUrl] - The callback url to use in the tool router session