Skip to content

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

jkomynoc9b6525bc9fb
diff --git a/.changeset/fix-connected-accounts-string-type.md b/.changeset/fix-connected-accounts-string-type.md
new file mode 100644
index 000000000..d05ec6cbf
--- /dev/null
+++ b/.changeset/fix-connected-accounts-string-type.md
@@ -0,0 +1,7 @@
+---
+'@composio/core': patch
+---
+
+Fix `connectedAccounts` TypeScript type so a single `string` per toolkit is actually accepted by the public API.
+
+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[]>`.
diff --git a/.changeset/v31-connected-accounts-array.md b/.changeset/v31-connected-accounts-array.md
index ee9c07c3c..b47c8d5ba 100644
--- a/.changeset/v31-connected-accounts-array.md
+++ b/.changeset/v31-connected-accounts-array.md
@@ -4,4 +4,4 @@
`connectedAccounts` now accepts both `string` and `string[]` per toolkit.
-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`.
+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.
diff --git a/ts/packages/core/src/models/ToolRouter.ts b/ts/packages/core/src/models/ToolRouter.ts
index 0d7e21c66..03d1e78d3 100644
--- a/ts/packages/core/src/models/ToolRouter.ts
+++ b/ts/packages/core/src/models/ToolRouter.ts
@@ -179,10 +179,20 @@ export class ToolRouter<
const multiAccountPayload = transformToolRouterMultiAccountParams(routerConfig.multiAccount);
+ const connectedAccountsPayload =
+ routerConfig.connectedAccounts === undefined
+ ? undefined
+ : Object.fromEntries(
+ Object.entries(routerConfig.connectedAccounts).map(([toolkit, ids]) => [
+ toolkit,
+ typeof ids === 'string' ? [ids] : ids,
+ ])
+ );
+
const payload: SessionCreateParams = {
user_id: userId,
auth_configs: routerConfig.authConfigs,
- connected_accounts: routerConfig.connectedAccounts,
+ connected_accounts: connectedAccountsPayload,
toolkits: transformToolRouterToolkitsParams(routerConfig.toolkits),
tools: transformToolRouterToolsParams(routerConfig.tools),
tags: transformToolRouterTagsParams(routerConfig.tags),
diff --git a/ts/packages/core/src/types/toolRouter.types.ts b/ts/packages/core/src/types/toolRouter.types.ts
index 94d8ccf49..4b2644622 100644
--- a/ts/packages/core/src/types/toolRouter.types.ts
+++ b/ts/packages/core/src/types/toolRouter.types.ts
@@ -203,13 +203,6 @@ const ToolRouterCreateSessionConfigBaseSchema = z
.default({}),
connectedAccounts: z
.record(z.string(), z.union([z.string(), z.array(z.string())]))
- .transform((rec) => {
- const out: Record<string, string[]> = {};
- for (const [k, v] of Object.entries(rec)) {
- out[k] = typeof v === 'string' ? [v] : v;
- }
- return out;
- })
.describe(
'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.'
)
@@ -344,7 +337,7 @@ export const ToolRouterCreateSessionConfigSchema = z
* @param {Record<string, ToolRouterToolsParam | ToolRouterConfigTools>} tools - The tools to configure per toolkit (key is toolkit slug)
* @param {Array<'readOnlyHint' | 'destructiveHint' | 'idempotentHint' | 'openWorldHint'>} tags - Global tags to filter tools by behavior
* @param {Record<string, string>} authConfigs - The auth configs to use in the tool router session
- * @param {Record<string, string>} connectedAccounts - The connected accounts to use in the tool router session
+ * @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.
* @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.
* @param {boolean} [manageConnections.enable] - Whether to use tools to manage connections in the tool router session @default true
* @param {string} [manageConnections.callbackUrl] - The callback url to use in the tool router session