@devries-cameron20 / composio Mirror · read-only
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, 04:45 UTC

next
ts 47 lines 2.44 KB
Raw
1 import type { ConnectedAccountItem } from 'src/models/connected-accounts';
2 import { bold, gray } from 'src/ui/colors';
3 import { redact } from 'src/ui/redact';
4 import { truncate } from 'src/ui/truncate';
5
6 /**
7 * Format a list of connected accounts as a human-readable table.
8 */
9 export function formatConnectedAccountsTable(items: ReadonlyArray<ConnectedAccountItem>): string {
10 const header = `${bold('Id'.padEnd(18))} ${bold('Alias'.padEnd(14))} ${bold('Word'.padEnd(12))} ${bold('User Id'.padEnd(20))} ${bold('Toolkit'.padEnd(14))} ${bold('Auth Config'.padEnd(18))} ${bold('Auth Scheme'.padEnd(14))} ${bold('Status')}`;
11
12 const rows = items.map(item => {
13 const id = truncate(redact({ value: item.id, prefix: 'con_' }), 18).padEnd(18);
14 const alias = truncate(item.alias || '-', 14).padEnd(14);
15 const wordId = truncate(item.word_id || '-', 12).padEnd(12);
16 const userId = truncate(item.user_id, 20).padEnd(20);
17 const toolkit = truncate(item.toolkit.slug, 14).padEnd(14);
18 const authConfig = truncate(redact({ value: item.auth_config.id, prefix: 'ac_' }), 18).padEnd(
19 18
20 );
21 const authScheme = truncate(item.auth_config.auth_scheme || '-', 14).padEnd(14);
22 const status = formatStatus(item.status);
23 return `${id} ${alias} ${wordId} ${userId} ${toolkit} ${authConfig} ${authScheme} ${status}`;
24 });
25
26 return [header, ...rows].join('\n');
27 }
28
29 // --- shared by `info` and `whoami` ------------------------------------------------------------
30
31 /** The spinner label while `info` or `whoami` fetches one connected account. */
32 export const fetchingConnectedAccountMessage = (id: string) =>
33 `Fetching connected account "${id}"...`;
34
35 /** The hint after `info` or `whoami` fails to fetch the account. */
36 export const BROWSE_CONNECTED_ACCOUNTS_HINT =
37 'Browse available connected accounts:\n> composio dev connected-accounts list';
38
39 /** The warning when `info` or `whoami` is given no id. */
40 export const MISSING_ID_MESSAGE = 'Missing required argument: <id>';
41
42 /** The hint after `MISSING_ID_MESSAGE`, naming the subcommand that was run. */
43 export const missingIdHint = (subcommand: 'info' | 'whoami') =>
44 `Try specifying a connected account ID, e.g.:\n> composio dev connected-accounts ${subcommand} "con_1a2b3c4d5e6f"\n\nTo find connected account IDs:\n> composio dev connected-accounts list`;
45
46 /** The `Status:` value: plain when active, gray otherwise. */
47 export const formatStatus = (status: string) => (status === 'ACTIVE' ? status : gray(status));