94
limit: 1000,
95
})
96
).pipe(
97
- Effect.flatMap(response =>
98
- Effect.gen(function* () {
99
- const items = (response.items ?? []) as ReadonlyArray<RawConnectedAccount>;
100
- const unknownStatuses = new Set<string>();
101
- const normalizedItems: SelectableConnectedAccount[] = items.map(item => {
102
- const normalizedStatus = normalizeConnectedAccountStatus(item.status);
103
- if (normalizedStatus === 'UNKNOWN' && item.status) {
104
- unknownStatuses.add(item.status);
105
- }
106
- return {
107
- id: item.id,
108
- alias: item.alias ?? null,
109
- word_id: item.word_id ?? null,
110
- status: normalizedStatus,
111
- status_reason: null,
112
- is_disabled: item.is_disabled ?? false,
113
- user_id: item.user_id ?? '',
114
- toolkit: {
115
- slug: item.toolkit?.slug ?? '',
116
- },
117
- auth_config: {
118
- id: item.auth_config?.id ?? '',
119
- auth_scheme: '',
120
- is_composio_managed: item.auth_config?.is_composio_managed ?? true,
121
- is_disabled: false,
122
- },
123
- created_at: item.created_at ?? '',
124
- updated_at: item.updated_at ?? '',
125
- test_request_endpoint: '',
126
- } satisfies SelectableConnectedAccount;
127
- });
128
-
129
- if (unknownStatuses.size > 0) {
130
- // Service-layer code: peers use `Effect.logDebug` for diagnostic
131
- // signal. The user-facing `ui.log.warn` channel runs from command
132
- // layers (e.g. `connected-accounts.list.cmd.ts`).
133
- yield* Effect.logDebug(
134
- `[ToolRouterSession] received unrecognized connected_account.status ` +
135
- `value(s): ${[...unknownStatuses].join(', ')}. Treating as 'UNKNOWN' ` +
136
- `(not selectable). Run "composio upgrade" to pick up the latest schema.`
137
- );
97
+ Effect.map(response => {
98
+ const items = (response.items ?? []) as ReadonlyArray<RawConnectedAccount>;
99
+ const unknownStatuses = new Set<string>();
100
+ const normalizedItems: SelectableConnectedAccount[] = items.map(item => {
101
+ const normalizedStatus = normalizeConnectedAccountStatus(item.status);
102
+ if (normalizedStatus === 'UNKNOWN' && item.status) {
103
+ unknownStatuses.add(item.status);
104
}
105
+ return {
106
+ id: item.id,
107
+ alias: item.alias ?? null,
108
+ word_id: item.word_id ?? null,
109
+ status: normalizedStatus,
110
+ status_reason: null,
111
+ is_disabled: item.is_disabled ?? false,
112
+ user_id: item.user_id ?? '',
113
+ toolkit: {
114
+ slug: item.toolkit?.slug ?? '',
115
+ },
116
+ auth_config: {
117
+ id: item.auth_config?.id ?? '',
118
+ auth_scheme: '',
119
+ is_composio_managed: item.auth_config?.is_composio_managed ?? true,
120
+ is_disabled: false,
121
+ },
122
+ created_at: item.created_at ?? '',
123
+ updated_at: item.updated_at ?? '',
124
+ test_request_endpoint: '',
125
+ } satisfies SelectableConnectedAccount;
126
+ });
127
140
- const connectedToolkits = new Set<string>();
141
- const explicitAccountsByToolkit = new Map<string, RawConnectedAccount>();
142
-
143
- for (const item of items) {
144
- const toolkit = item.toolkit?.slug?.toLowerCase().trim();
145
- if (!toolkit || item.is_disabled) continue;
128
+ const connectedToolkits = new Set<string>();
129
+ const explicitAccountsByToolkit = new Map<string, RawConnectedAccount>();
130
147
- connectedToolkits.add(toolkit);
131
+ // Second pass over the raw items — needs untouched `auth_config` and
132
+ // `is_disabled` metadata that the normalized projection drops.
133
+ for (const item of items) {
134
+ const toolkit = item.toolkit?.slug?.toLowerCase().trim();
135
+ if (!toolkit || item.is_disabled) continue;
136
149
- // Tool Router already handles Composio-managed auth well.
150
- // Explicitly pin non-managed auth configs/accounts so consumer sessions
151
- // can execute against custom-auth toolkits like PostHog.
152
- if (item.auth_config?.is_composio_managed !== false) {
153
- continue;
154
- }
137
+ connectedToolkits.add(toolkit);
138
156
- const current = explicitAccountsByToolkit.get(toolkit);
157
- if (!current || isNewerAccount(item, current)) {
158
- explicitAccountsByToolkit.set(toolkit, item);
159
- }
139
+ // Tool Router already handles Composio-managed auth well.
140
+ // Explicitly pin non-managed auth configs/accounts so consumer sessions
141
+ // can execute against custom-auth toolkits like PostHog.
142
+ if (item.auth_config?.is_composio_managed !== false) {
143
+ continue;
144
}
145
162
- const authConfigs: Record<string, string> = {};
163
- for (const [toolkit, item] of explicitAccountsByToolkit) {
164
- const authConfigId = item.auth_config?.id?.trim();
165
- if (!authConfigId) continue;
166
- authConfigs[toolkit] = authConfigId;
146
+ const current = explicitAccountsByToolkit.get(toolkit);
147
+ if (!current || isNewerAccount(item, current)) {
148
+ explicitAccountsByToolkit.set(toolkit, item);
149
}
150
+ }
151
169
- return {
152
+ const authConfigs: Record<string, string> = {};
153
+ for (const [toolkit, item] of explicitAccountsByToolkit) {
154
+ const authConfigId = item.auth_config?.id?.trim();
155
+ if (!authConfigId) continue;
156
+ authConfigs[toolkit] = authConfigId;
157
+ }
158
+
159
+ return {
160
+ unknownStatuses,
161
+ context: {
162
connectedToolkits: [...connectedToolkits],
163
authConfigs: Object.keys(authConfigs).length > 0 ? authConfigs : undefined,
164
connectedAccounts: (() => {
169
const grouped = groupCachedConnectedAccountsByToolkit(normalizedItems);
170
return Object.keys(grouped).length > 0 ? grouped : undefined;
171
})(),
180
- } satisfies ToolRouterSessionConnectionContext;
181
- })
172
+ } satisfies ToolRouterSessionConnectionContext,
173
+ };
174
+ }),
175
+ Effect.tap(({ unknownStatuses }) =>
176
+ unknownStatuses.size > 0
177
+ ? // Service-layer code: peers use `Effect.logDebug` for diagnostic
178
+ // signal. The user-facing `ui.log.warn` channel runs from command
179
+ // layers (e.g. `connected-accounts.list.cmd.ts`).
180
+ Effect.logDebug(
181
+ `[ToolRouterSession] received unrecognized connected_account.status ` +
182
+ `value(s): ${[...unknownStatuses].join(', ')}. Treating as 'UNKNOWN' ` +
183
+ `(not selectable). Run "composio upgrade" to pick up the latest schema.`
184
+ )
185
+ : Effect.void
186
),
187
+ Effect.map(({ context }) => context),
188
Effect.catchAll(() =>
189
Effect.succeed({
190
connectedToolkits: [],