@devries-cameron20 / composio-1 / commits / 588cfe65a
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(cli): normalize the toolkit slug the same way on both account paths

The derived toolkit filter lower-cased only, while the grouping helpers in the same module trim first and the fallback sent the raw slug to the server. A padded `--toolkit` value could therefore match or miss depending on how many accounts the user has. Trim once, compare with the shared normalizer, and send the trimmed slug on the fallback. Drop the optional chaining on fields the client types as required. Claude-Session: https://claude.ai/code/session_01MTb47vexN35pLGsSZwBmrJ

jkomyno committed Sep 14, 2026 at 21:01 UTC 588cfe65a06c24c8ecf429696f4dc6dc4806c300
2 files changed +83 -9
ts/packages/cli/src/services/connected-account-selection.ts
+14 -9
@@ -185,8 +185,8 @@ export const listActiveConnectedAccounts = memoizeInProcess({
185 const TOOLKIT_ACCOUNTS_PAGE_SIZE = 100;
186
187 // The account picker's own query: one toolkit, first 100 active accounts, in
188 -// server order. Kept verbatim as the fallback so results stay identical when
189 -// the shared list cannot stand in for it.
188 +// server order. Kept as the fallback so results stay identical when the
189 +// shared list cannot stand in for it.
190 const fetchConnectedAccountsForToolkit = (params: {
191 readonly client: Composio;
192 readonly userId: string;
@@ -210,30 +210,35 @@ const fetchConnectedAccountsForToolkit = (params: {
210 * toolkit-filtered `GET /connected_accounts` next to the one session creation
211 * needs anyway.
212 *
213 - * Derivation reproduces the server query exactly: same slug match, server
214 - * order preserved, first 100. If the shared list was truncated (more active
213 + * Derivation reproduces the server query: same slug match, server order
214 + * preserved, first 100. If the shared list was truncated (more active
215 * accounts than its page holds), the toolkit's accounts may sit past the cut,
216 * so the original filtered request runs instead.
217 + *
218 + * The slug is trimmed and lower-cased the way the grouping helpers above
219 + * normalize toolkit slugs, and the trimmed slug is what the fallback sends,
220 + * so a padded `--toolkit` value resolves the same way on both paths.
221 */
218 -const listConnectedAccountsForToolkit = (params: {
222 +export const listConnectedAccountsForToolkit = (params: {
223 readonly client: Composio;
224 readonly userId: string;
225 readonly toolkitSlug: string;
226 }) =>
227 Effect.gen(function* () {
228 + const toolkitSlug = params.toolkitSlug.trim();
229 const shared = yield* listActiveConnectedAccounts({
230 client: params.client,
231 userId: params.userId,
232 });
228 - const items = shared.items ?? [];
233 + const items = shared.items;
234 const complete = shared.next_cursor == null && shared.total_items <= items.length;
235 if (!complete) {
231 - return yield* fetchConnectedAccountsForToolkit(params);
236 + return yield* fetchConnectedAccountsForToolkit({ ...params, toolkitSlug });
237 }
238
234 - const wantedToolkit = params.toolkitSlug.toLowerCase();
239 + const wantedToolkit = normalizeSelector(toolkitSlug);
240 return items
236 - .filter(item => item.toolkit?.slug?.toLowerCase() === wantedToolkit)
241 + .filter(item => normalizeSelector(item.toolkit.slug) === wantedToolkit)
242 .slice(0, TOOLKIT_ACCOUNTS_PAGE_SIZE);
243 });
244
ts/packages/cli/test/src/services/connected-account-selection.test.ts
+69
@@ -1,7 +1,11 @@
1 import { describe, expect, it } from 'vitest';
2 +import { it as effectIt } from '@effect/vitest';
3 +import { Effect } from 'effect';
4 +import type { Composio } from '@composio/client';
5 import {
6 formatConnectedAccountChoices,
7 groupCachedConnectedAccountsByToolkit,
8 + listConnectedAccountsForToolkit,
9 resolveConnectedAccountSelection,
10 resolveDefaultConnectedAccountsByToolkit,
11 } from 'src/services/connected-account-selection';
@@ -94,3 +98,68 @@ describe('connected-account-selection', () => {
98 ).toEqual(['default / castle (con_default)']);
99 });
100 });
101 +
102 +type ListParams = {
103 + readonly toolkit_slugs?: ReadonlyArray<string>;
104 + readonly limit?: number;
105 +};
106 +
107 +// A stand-in for the SDK client: one page of accounts, plus a log of every
108 +// `connectedAccounts.list` call so a test can see which path ran.
109 +const makeListClient = (
110 + items: ReadonlyArray<ConnectedAccountItem>,
111 + page?: { readonly total_items?: number; readonly next_cursor?: string | null }
112 +) => {
113 + const calls: ListParams[] = [];
114 + const client = {
115 + connectedAccounts: {
116 + list: async (params: ListParams) => {
117 + calls.push(params);
118 + const filtered = params.toolkit_slugs
119 + ? items.filter(item =>
120 + params.toolkit_slugs!.some(
121 + slug => slug.trim().toLowerCase() === item.toolkit.slug.trim().toLowerCase()
122 + )
123 + )
124 + : items;
125 + return {
126 + items: filtered.slice(0, params.limit ?? 30),
127 + total_items: page?.total_items ?? filtered.length,
128 + total_pages: 1,
129 + current_page: 1,
130 + next_cursor: page?.next_cursor ?? null,
131 + };
132 + },
133 + },
134 + } as unknown as Composio;
135 + return { client, calls };
136 +};
137 +
138 +describe('listConnectedAccountsForToolkit', () => {
139 + effectIt.effect('matches toolkit slugs the way the grouping helpers do, on both paths', () =>
140 + Effect.gen(function* () {
141 + const items = [
142 + makeAccount({ id: 'con_github', toolkit: { slug: 'GitHub ' } }),
143 + makeAccount({ id: 'con_gmail', toolkit: { slug: 'gmail' } }),
144 + ];
145 +
146 + const derived = makeListClient(items);
147 + const fromSharedList = yield* listConnectedAccountsForToolkit({
148 + client: derived.client,
149 + userId: 'default',
150 + toolkitSlug: ' github',
151 + });
152 + expect(fromSharedList.map(item => item.id)).toEqual(['con_github']);
153 + expect(derived.calls).toHaveLength(1);
154 +
155 + const fallback = makeListClient(items, { next_cursor: 'more' });
156 + const fromServer = yield* listConnectedAccountsForToolkit({
157 + client: fallback.client,
158 + userId: 'default',
159 + toolkitSlug: ' github',
160 + });
161 + expect(fromServer.map(item => item.id)).toEqual(['con_github']);
162 + expect(fallback.calls[1]?.toolkit_slugs).toEqual(['github']);
163 + })
164 + );
165 +});