Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 65 lines 2.34 KB
Raw
1 import { Array as Arr, Effect, Option, String } from 'effect';
2 import { resolveDeveloperResourceProject } from 'src/commands/surface';
3 import { ComposioToolkitsRepository } from 'src/services/composio-clients';
4 import { TerminalUI } from 'src/services/terminal-ui';
5 import { clampLimit } from 'src/ui/clamp-limit';
6 import { redact } from 'src/ui/redact';
7 import { formatAuthConfigsJson, formatAuthConfigsTable } from './auth-configs.list.format';
8
9 export type AuthConfigsListParams = {
10 readonly toolkits: Option.Option<string>;
11 readonly query: Option.Option<string>;
12 readonly limit: number;
13 };
14
15 /**
16 * List the developer project's auth configs, filtered by toolkit and name: the table on stderr,
17 * the JSON on stdout. Fails with `ProjectResolutionError` when no developer project can be found
18 * (`resolveDeveloperResourceProject`).
19 */
20 export const runAuthConfigsList = ({ toolkits, query, limit }: AuthConfigsListParams) =>
21 Effect.gen(function* () {
22 const ui = yield* TerminalUI;
23 const repo = yield* ComposioToolkitsRepository;
24 const project = yield* resolveDeveloperResourceProject;
25
26 const result = yield* ui.withSpinner(
27 'Fetching auth configs...',
28 repo.listAuthConfigs(project, {
29 search: Option.getOrUndefined(query),
30 toolkit_slug: Option.getOrUndefined(toolkits),
31 limit: clampLimit(limit),
32 })
33 );
34
35 if (result.items.length === 0) {
36 const hint = Option.match(toolkits, {
37 onNone: () => 'No auth configs found. Try broadening your search.',
38 onSome: toolkit =>
39 `No auth configs found for toolkit "${toolkit}". Verify the toolkit slug with:\n> composio dev toolkits list`,
40 });
41 yield* ui.log.warn(hint);
42 return;
43 }
44
45 const showing = result.items.length;
46 const total = result.total_items;
47
48 yield* ui.log.info(
49 `Listing ${showing} of ${total} auth configs\n\n${formatAuthConfigsTable(result.items)}`
50 );
51
52 const firstId = Arr.head(result.items).pipe(
53 Option.map(item => item.id),
54 Option.filter(String.isNonEmpty)
55 );
56 yield* Option.match(firstId, {
57 onNone: () => Effect.void,
58 onSome: id =>
59 ui.log.step(
60 `To view details of an auth config:\n> composio dev auth-configs info "${redact({ value: id, prefix: 'ac_' })}"`
61 ),
62 });
63
64 yield* ui.output(formatAuthConfigsJson(result.items));
65 });