@devries-cameron20 / composio Mirror · read-only / commits / 6808eecfd
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 22, 04:30 UTC

perf(cli): parallelize catalog fetch and session creation in toolkits list

Run the catalog API call and Tool Router session creation concurrently using Effect.all with unbounded concurrency. The session toolkits call still runs sequentially after session creation (it needs the session ID). This saves one network round trip (~100-500ms) when a user ID is available.

jkomyno committed Mar 9, 2026 at 16:14 UTC 6808eecfd8c71d33e0d8d99cfc334d0495ad622d
1 file changed +35 -24
ts/packages/cli/src/commands/toolkits/commands/toolkits.list.cmd.ts
+35 -24
@@ -85,13 +85,25 @@ export const toolkitsCmd$List = Command.make(
85 );
86 }
87
88 - // Always fetch catalog data (has tools_count, triggers_count, versions).
89 - const catalogResult = yield* ui.withSpinner(
88 + // Fetch catalog data (always) and session context (when user ID available) in parallel.
89 + // The session toolkits call depends on the session ID, so it runs after session creation.
90 + const catalogEffect = repo.searchToolkits({
91 + search: Option.getOrUndefined(query),
92 + limit: clampedLimit,
93 + });
94 +
95 + // Resolve session context in parallel with catalog fetch (saves one round trip).
96 + const sessionContextEffect = Option.isSome(resolvedUserId)
97 + ? resolveToolRouterSession(resolvedUserId.value).pipe(
98 + Effect.catchAll(error =>
99 + Effect.logDebug('Failed to create session:', error).pipe(Effect.as(undefined))
100 + )
101 + )
102 + : Effect.succeed(undefined as undefined);
103 +
104 + const [catalogResult, sessionContext] = yield* ui.withSpinner(
105 'Fetching toolkits...',
91 - repo.searchToolkits({
92 - search: Option.getOrUndefined(query),
93 - limit: clampedLimit,
94 - })
106 + Effect.all([catalogEffect, sessionContextEffect], { concurrency: 'unbounded' })
107 );
108
109 if (catalogResult.items.length === 0) {
@@ -100,31 +112,30 @@ export const toolkitsCmd$List = Command.make(
112 return;
113 }
114
103 - // When a user ID is available, also fetch session data for connection status.
115 + // When session context is available, fetch session toolkits for connection status.
116 let sessionItems:
117 | ReadonlyArray<
118 import('@composio/client/resources/tool-router').SessionToolkitsResponse.Item
119 >
120 | undefined;
109 - if (Option.isSome(resolvedUserId)) {
110 - sessionItems = yield* resolveToolRouterSession(resolvedUserId.value).pipe(
111 - Effect.flatMap(({ client, sessionId }) =>
112 - Effect.tryPromise(() =>
113 - client.toolRouter.session.toolkits(sessionId, {
114 - search: Option.getOrUndefined(query),
115 - limit: clampedLimit,
116 - is_connected: Option.getOrUndefined(connected),
117 - })
118 - )
119 - ),
121 + if (sessionContext) {
122 + const { client, sessionId } = sessionContext;
123 + sessionItems = yield* Effect.tryPromise(() =>
124 + client.toolRouter.session.toolkits(sessionId, {
125 + search: Option.getOrUndefined(query),
126 + limit: clampedLimit,
127 + is_connected: Option.getOrUndefined(connected),
128 + })
129 + ).pipe(
130 Effect.map(r => r.items),
131 Effect.catchAll(error =>
122 - Effect.gen(function* () {
123 - yield* Effect.logDebug('Failed to fetch session data for connection status:', error);
124 - return [] as ReadonlyArray<
125 - import('@composio/client/resources/tool-router').SessionToolkitsResponse.Item
126 - >;
127 - })
132 + Effect.logDebug('Failed to fetch session toolkits:', error).pipe(
133 + Effect.as(
134 + [] as ReadonlyArray<
135 + import('@composio/client/resources/tool-router').SessionToolkitsResponse.Item
136 + >
137 + )
138 + )
139 )
140 );
141 if (sessionItems.length === 0) sessionItems = undefined;