21
` description: ${field.description || '-'}`,
22
].join('\n');
23
24
-// ---------- Tool Router format functions ----------
24
+// ---------- Unified toolkit list format ----------
25
26
/**
27
- * Derive connection status text and color from a session toolkit item.
28
- * Returns plain text + color function so callers can pad before coloring.
27
+ * Unified representation of a toolkit for list/search output.
28
+ * Catalog data is always present; connection data is optional (requires a user session).
29
*/
30
-function connectionStatusParts(item: SessionToolkitItem): {
30
+export interface UnifiedToolkit {
31
+ name: string;
32
+ slug: string;
33
+ description: string;
34
+ latest_version: string | null;
35
+ tools_count: number;
36
+ triggers_count: number;
37
+ is_no_auth: boolean;
38
+ enabled: boolean | null;
39
+ connected: {
40
+ status: string;
41
+ id: string;
42
+ auth_scheme: string | null;
43
+ is_composio_managed: boolean | null;
44
+ } | null;
45
+}
46
+
47
+/**
48
+ * Build unified toolkit items from catalog data, optionally enriched with
49
+ * session connection data (keyed by slug).
50
+ */
51
+export function mergeToolkitData(
52
+ catalogItems: ReadonlyArray<Toolkit>,
53
+ sessionItems?: ReadonlyArray<SessionToolkitItem>
54
+): UnifiedToolkit[] {
55
+ const sessionBySlug = new Map<string, SessionToolkitItem>();
56
+ if (sessionItems) {
57
+ for (const s of sessionItems) {
58
+ sessionBySlug.set(s.slug, s);
59
+ }
60
+ }
61
+
62
+ return catalogItems.map(t => {
63
+ const session = sessionBySlug.get(t.slug);
64
+ return {
65
+ name: t.name,
66
+ slug: t.slug,
67
+ description: t.meta.description,
68
+ latest_version: t.meta.available_versions.at(-1) ?? null,
69
+ tools_count: t.meta.tools_count,
70
+ triggers_count: t.meta.triggers_count,
71
+ is_no_auth: t.no_auth,
72
+ enabled: session?.enabled ?? null,
73
+ connected: session?.connected_account
74
+ ? {
75
+ status: session.connected_account.status,
76
+ id: session.connected_account.id,
77
+ auth_scheme: session.connected_account.auth_config?.auth_scheme ?? null,
78
+ is_composio_managed: session.connected_account.auth_config?.is_composio_managed ?? null,
79
+ }
80
+ : null,
81
+ };
82
+ });
83
+}
84
+
85
+/**
86
+ * Derive connection status text and color from a unified toolkit.
87
+ */
88
+function connectionStatusParts(item: UnifiedToolkit): {
89
text: string;
90
color: (s: string) => string;
91
} {
92
if (item.is_no_auth) return { text: 'no auth', color: dim };
35
- if (item.connected_account?.status === 'ACTIVE') return { text: 'active', color: green };
93
+ if (item.connected?.status === 'ACTIVE') return { text: 'active', color: green };
94
+ if (item.connected === null && item.enabled === null) return { text: '-', color: dim };
95
return { text: 'not connected', color: dim };
96
}
97
98
/**
40
- * Format a list of session toolkits as a human-readable table.
99
+ * Format a list of unified toolkits as a human-readable table.
100
*/
42
-export function formatToolkitsTable(toolkits: ReadonlyArray<SessionToolkitItem>): string {
43
- const header = `${bold('Name'.padEnd(20))} ${bold('Slug'.padEnd(20))} ${bold('Connected'.padEnd(16))} ${bold('Auth Scheme'.padEnd(14))} ${bold('Description')}`;
101
+export function formatToolkitsTable(toolkits: ReadonlyArray<UnifiedToolkit>): string {
102
+ const header = `${bold('Name'.padEnd(20))} ${bold('Slug'.padEnd(20))} ${bold('Version'.padEnd(12))} ${bold('Tools'.padEnd(7))} ${bold('Triggers'.padEnd(10))} ${bold('Connected'.padEnd(16))} ${bold('Description')}`;
103
104
const rows = toolkits.map(t => {
105
const name = t.name.padEnd(20);
106
const slug = t.slug.padEnd(20);
48
- // Pad plain text first, then apply color — ANSI escapes break padEnd.
107
+ const version = (t.latest_version ?? '-').padEnd(12);
108
+ const tools = String(t.tools_count).padEnd(7);
109
+ const triggers = String(t.triggers_count).padEnd(10);
110
const { text: statusText, color: statusColor } = connectionStatusParts(t);
111
const status = statusColor(statusText.padEnd(16));
51
- const authScheme = (t.connected_account?.auth_config?.auth_scheme ?? '-').padEnd(14);
52
- const desc = gray(truncate(t.meta.description, 50));
53
- return `${name} ${slug} ${status} ${authScheme} ${desc}`;
112
+ const desc = gray(truncate(t.description, 50));
113
+ return `${name} ${slug} ${version} ${tools} ${triggers} ${status} ${desc}`;
114
});
115
116
return [header, ...rows].join('\n');
117
}
118
119
/**
60
- * Format session toolkits as JSON for piped output.
120
+ * Format unified toolkits as JSON for piped output.
121
*/
62
-export function formatToolkitsJson(toolkits: ReadonlyArray<SessionToolkitItem>): string {
63
- return JSON.stringify(
64
- toolkits.map(t => ({
65
- name: t.name,
66
- slug: t.slug,
67
- description: t.meta.description,
68
- is_no_auth: t.is_no_auth,
69
- enabled: t.enabled,
70
- connected: t.connected_account
71
- ? {
72
- status: t.connected_account.status,
73
- id: t.connected_account.id,
74
- auth_scheme: t.connected_account.auth_config?.auth_scheme ?? null,
75
- is_composio_managed: t.connected_account.auth_config?.is_composio_managed ?? null,
76
- }
77
- : null,
78
- composio_managed_auth_schemes: t.composio_managed_auth_schemes,
79
- })),
80
- null,
81
- 2
82
- );
122
+export function formatToolkitsJson(toolkits: ReadonlyArray<UnifiedToolkit>): string {
123
+ return JSON.stringify(toolkits, null, 2);
124
}
125
126
/**
279
2
280
);
281
}
241
-
242
-// ---------- Legacy format functions (used by non-migrated commands) ----------
243
-
244
-/**
245
- * Format a list of toolkits as a human-readable table (legacy format).
246
- */
247
-export function formatLegacyToolkitsTable(toolkits: ReadonlyArray<Toolkit>): string {
248
- const header = `${bold('Name'.padEnd(20))} ${bold('Slug'.padEnd(20))} ${bold('Version'.padEnd(12))} ${bold('Tools'.padEnd(7))} ${bold('Triggers'.padEnd(10))} ${bold('Description')}`;
249
-
250
- const rows = toolkits.map(t => {
251
- const name = t.name.padEnd(20);
252
- const slug = t.slug.padEnd(20);
253
- const version = (t.meta.available_versions.at(-1) ?? '-').padEnd(12);
254
- const tools = String(t.meta.tools_count).padEnd(7);
255
- const triggers = String(t.meta.triggers_count).padEnd(10);
256
- const desc = gray(truncate(t.meta.description, 50));
257
- return `${name} ${slug} ${version} ${tools} ${triggers} ${desc}`;
258
- });
259
-
260
- return [header, ...rows].join('\n');
261
-}
262
-
263
-/**
264
- * Format toolkits as JSON for piped output (legacy format).
265
- */
266
-export function formatLegacyToolkitsJson(toolkits: ReadonlyArray<Toolkit>): string {
267
- return JSON.stringify(
268
- toolkits.map(t => ({
269
- name: t.name,
270
- slug: t.slug,
271
- latest_version: t.meta.available_versions.at(-1) ?? null,
272
- tools_count: t.meta.tools_count,
273
- triggers_count: t.meta.triggers_count,
274
- description: t.meta.description,
275
- })),
276
- null,
277
- 2
278
- );
279
-}