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
+ });