@devries-cameron20 / composio Mirror · read-only / commits / d0fb8ed31
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

refactor(cli): extract decodeConnectedAccountListWithFallback helper

Three commands (`connected-accounts.list`, `connections.list`, `connections.remove`) carried verbatim copies of the same 13-line `Effect.catchTag('ParseError', ...)` forward-compat guard. Future changes to the warning message or fallback semantics would have to touch all three sites in lockstep. Lift the guard into `src/effects/decode-connected-account-list.ts` so each call site collapses to a single `yield*`. The helper carries the WHY (forward-compat with Apollo enum additions) and the safety justification for the cast in one place. Surfaced by Cursor Bugbot on commit afb33deef.

jkomyno committed May 7, 2026 at 11:45 UTC d0fb8ed312f466bc8d7db90765bad697cf720847
4 files changed +51 -62
ts/packages/cli/src/commands/connected-accounts/commands/connected-accounts.list.cmd.ts
+4 -22
@@ -1,11 +1,9 @@
1 import { Command, Options } from '@effect/cli';
2 -import { Effect, Option, Schema } from 'effect';
2 +import { Effect, Option } from 'effect';
3 import type { ConnectedAccountListParams } from '@composio/client/resources/connected-accounts';
4 -import {
5 - ComposioClientSingleton,
6 - ConnectedAccountListResponse,
7 -} from 'src/services/composio-clients';
4 +import { ComposioClientSingleton } from 'src/services/composio-clients';
5 import { TerminalUI } from 'src/services/terminal-ui';
6 +import { decodeConnectedAccountListWithFallback } from 'src/effects/decode-connected-account-list';
7 import { requireAuth } from 'src/effects/require-auth';
8 import { clampLimit } from 'src/ui/clamp-limit';
9 import { redact } from 'src/ui/redact';
@@ -88,23 +86,7 @@ export const connectedAccountsCmd$List = Command.make(
86 })
87 )
88 );
91 - // Forward-compat: a future Apollo status would otherwise brick the
92 - // command via the closed `Schema.Literal(...)`. Degrade to raw on
93 - // ParseError; formatters only read non-credential-bearing fields.
94 - const result = yield* Schema.decodeUnknown(ConnectedAccountListResponse)(rawResult).pipe(
95 - Effect.catchTag('ParseError', error =>
96 - Effect.gen(function* () {
97 - yield* ui.log.warn(
98 - `Server returned a connection field this CLI does not recognize ` +
99 - `(likely a newly-added status). Run "composio upgrade" to pick up ` +
100 - `the latest schema. Continuing with raw response.\n\n` +
101 - `Decode error: ${error.message}`
102 - );
103 - // Safe: formatters only read non-credential fields.
104 - return rawResult as ConnectedAccountListResponse;
105 - })
106 - )
107 - );
89 + const result = yield* decodeConnectedAccountListWithFallback(rawResult);
90
91 if (result.items.length === 0) {
92 let hint: string;
ts/packages/cli/src/commands/connections/commands/connections.list.cmd.ts
+4 -20
@@ -1,11 +1,9 @@
1 import { Command, Options } from '@effect/cli';
2 -import { Effect, Option, Schema } from 'effect';
2 +import { Effect, Option } from 'effect';
3 +import { decodeConnectedAccountListWithFallback } from 'src/effects/decode-connected-account-list';
4 import { requireAuth } from 'src/effects/require-auth';
5 import type { ConnectedAccountItem } from 'src/models/connected-accounts';
5 -import {
6 - ComposioClientSingleton,
7 - ConnectedAccountListResponse,
8 -} from 'src/services/composio-clients';
6 +import { ComposioClientSingleton } from 'src/services/composio-clients';
7 import {
8 formatResolveCommandProjectError,
9 resolveCommandProject,
@@ -73,21 +71,7 @@ export const connectionsCmd$List = Command.make('list', { toolkit }, ({ toolkit
71 limit: 1000,
72 })
73 );
76 - // Same forward-compat guard as `connected-accounts.list.cmd.ts`.
77 - const result = yield* Schema.decodeUnknown(ConnectedAccountListResponse)(rawResult).pipe(
78 - Effect.catchTag('ParseError', error =>
79 - Effect.gen(function* () {
80 - yield* ui.log.warn(
81 - `Server returned a connection field this CLI does not recognize ` +
82 - `(likely a newly-added status). Run "composio upgrade" to pick up ` +
83 - `the latest schema. Continuing with raw response.\n\n` +
84 - `Decode error: ${error.message}`
85 - );
86 - // Safe: `formatConnectionsJson` only reads non-credential fields.
87 - return rawResult as ConnectedAccountListResponse;
88 - })
89 - )
90 - );
74 + const result = yield* decodeConnectedAccountListWithFallback(rawResult);
75
76 yield* ui.output(formatConnectionsJson(result.items), { force: true });
77 })
ts/packages/cli/src/commands/connections/commands/connections.remove.cmd.ts
+4 -20
@@ -1,11 +1,9 @@
1 import { Args, Command } from '@effect/cli';
2 -import { Effect, Schema } from 'effect';
2 +import { Effect } from 'effect';
3 +import { decodeConnectedAccountListWithFallback } from 'src/effects/decode-connected-account-list';
4 import { requireAuth } from 'src/effects/require-auth';
5 import type { ConnectedAccountItem } from 'src/models/connected-accounts';
5 -import {
6 - ComposioClientSingleton,
7 - ConnectedAccountListResponse,
8 -} from 'src/services/composio-clients';
6 +import { ComposioClientSingleton } from 'src/services/composio-clients';
7 import {
8 formatResolveCommandProjectError,
9 resolveCommandProject,
@@ -109,21 +107,7 @@ export const connectionsCmd$Remove = Command.make('remove', { account }, ({ acco
107 })
108 )
109 );
112 - // Same forward-compat guard as `connected-accounts.list.cmd.ts`.
113 - const result = yield* Schema.decodeUnknown(ConnectedAccountListResponse)(rawResult).pipe(
114 - Effect.catchTag('ParseError', error =>
115 - Effect.gen(function* () {
116 - yield* ui.log.warn(
117 - `Server returned a connection field this CLI does not recognize ` +
118 - `(likely a newly-added status). Run "composio upgrade" to pick up ` +
119 - `the latest schema. Continuing with raw response.\n\n` +
120 - `Decode error: ${error.message}`
121 - );
122 - // Safe: `resolveAccount` / `formatAccountSummary` only read non-credential fields.
123 - return rawResult as ConnectedAccountListResponse;
124 - })
125 - )
126 - );
110 + const result = yield* decodeConnectedAccountListWithFallback(rawResult);
111 const resolved = resolveAccount({ accounts: result.items, selector: account });
112
113 if ('error' in resolved) {
ts/packages/cli/src/effects/decode-connected-account-list.ts new
+39
@@ -0,0 +1,39 @@
1 +import { Effect, Schema } from 'effect';
2 +import {
3 + ConnectedAccountListResponse,
4 + type ConnectedAccountListResponse as ConnectedAccountListResponseType,
5 +} from 'src/services/composio-clients';
6 +import { TerminalUI } from 'src/services/terminal-ui';
7 +
8 +/**
9 + * Decodes a raw `client.connectedAccounts.list(...)` response against
10 + * `ConnectedAccountListResponse`, falling back to the raw payload on
11 + * `ParseError`.
12 + *
13 + * Forward-compat: a future Apollo status would otherwise brick the caller
14 + * via the closed `Schema.Literal(...)`. On decode failure we warn via
15 + * `ui.log.warn` (pointing the user at `composio upgrade`) and return the
16 + * unvalidated raw response — safe because the three current call sites
17 + * only render non-credential fields (`id`, `alias`, `word_id`,
18 + * `toolkit.slug`, `status`, ...).
19 + */
20 +export const decodeConnectedAccountListWithFallback = (
21 + rawResult: unknown
22 +): Effect.Effect<ConnectedAccountListResponseType, never, TerminalUI> =>
23 + Effect.gen(function* () {
24 + const ui = yield* TerminalUI;
25 + return yield* Schema.decodeUnknown(ConnectedAccountListResponse)(rawResult).pipe(
26 + Effect.catchTag('ParseError', error =>
27 + Effect.gen(function* () {
28 + yield* ui.log.warn(
29 + `Server returned a connection field this CLI does not recognize ` +
30 + `(likely a newly-added status). Run "composio upgrade" to pick up ` +
31 + `the latest schema. Continuing with raw response.\n\n` +
32 + `Decode error: ${error.message}`
33 + );
34 + // Safe: callers only read non-credential fields.
35 + return rawResult as ConnectedAccountListResponseType;
36 + })
37 + )
38 + );
39 + });