1
import { Args, Command } from '@effect/cli';
2
import { Effect, Option } from 'effect';
3
-import { ComposioToolkitsRepository, HttpServerError } from 'src/services/composio-clients';
3
+import { ComposioToolkitsRepository } from 'src/services/composio-clients';
4
import { TerminalUI } from 'src/services/terminal-ui';
5
import { requireAuth } from 'src/effects/require-auth';
6
-import type { ToolkitDetailed, AuthConfigDetail } from 'src/models/toolkits';
7
-import { bold, gray } from 'src/ui/colors';
6
+import { handleHttpServerError } from 'src/effects/handle-http-error';
7
+import { formatToolkitInfo } from '../format';
8
9
const slug = Args.text({ name: 'slug' }).pipe(
10
Args.withDescription('Toolkit slug (e.g. "gmail")'),
11
Args.optional
12
);
13
14
-/**
15
- * Format auth config fields for display.
16
- */
17
-function formatFields(fields: ReadonlyArray<AuthConfigDetail['fields']['auth_config_creation']>) {
18
- const lines: string[] = [];
19
-
20
- for (const group of fields) {
21
- const allFields = [
22
- ...group.required.map(f => ({ ...f, label: 'required' })),
23
- ...group.optional.map(f => ({ ...f, label: 'optional' })),
24
- ];
25
-
26
- if (allFields.length === 0) {
27
- lines.push(' (none)');
28
- } else {
29
- const nameWidth = Math.max(...allFields.map(f => f.name.length));
30
- const labelWidth = Math.max(...allFields.map(f => f.label.length));
31
- const typeWidth = Math.max(...allFields.map(f => f.type.length));
32
-
33
- for (const field of allFields) {
34
- const desc = field.description ? ` ${gray(`"${field.description}"`)}` : '';
35
- lines.push(
36
- ` ${field.name.padEnd(nameWidth)} ${field.label.padEnd(labelWidth)} ${field.type.padEnd(typeWidth)}${desc}`
37
- );
38
- }
39
- }
40
- }
41
-
42
- return lines.join('\n');
43
-}
44
-
45
-/**
46
- * Format a detailed toolkit for interactive display.
47
- */
48
-function formatToolkitInfo(toolkit: ToolkitDetailed): string {
49
- const lines: string[] = [];
50
-
51
- lines.push(`${bold('Name:')} ${toolkit.name}`);
52
- lines.push(`${bold('Slug:')} ${toolkit.slug}`);
53
- lines.push(`${bold('Description:')} ${toolkit.meta.description || '(none)'}`);
54
-
55
- // Derive auth schemes from auth_config_details
56
- const authSchemes = toolkit.auth_config_details.map(d => d.mode);
57
- if (toolkit.no_auth) {
58
- lines.push(`${bold('Auth:')} No authentication required`);
59
- } else if (authSchemes.length > 0) {
60
- lines.push(`${bold('Auth Schemes:')} ${authSchemes.join(', ')}`);
61
- if (toolkit.composio_managed_auth_schemes.length > 0) {
62
- lines.push(
63
- `${bold('Composio Managed Auth Schemes:')} ${toolkit.composio_managed_auth_schemes.join(', ')}`
64
- );
65
- }
66
- }
67
-
68
- // Auth config creation fields
69
- if (toolkit.auth_config_details.length > 0) {
70
- lines.push('');
71
- lines.push(bold('Fields Required for AuthConfig creation:'));
72
- for (const detail of toolkit.auth_config_details) {
73
- lines.push(` ${detail.name} (${detail.mode}):`);
74
- lines.push(formatFields([detail.fields.auth_config_creation]));
75
- }
76
-
77
- lines.push('');
78
- lines.push(bold('Fields Required for Connected Account creation:'));
79
- for (const detail of toolkit.auth_config_details) {
80
- lines.push(` ${detail.name} (${detail.mode}):`);
81
- lines.push(formatFields([detail.fields.connected_account_initiation]));
82
- }
83
- }
84
-
85
- return lines.join('\n');
86
-}
87
-
14
/**
15
* View details of a specific toolkit including auth schemes and required fields.
16
*
39
.withSpinner(`Fetching toolkit "${slugValue}"...`, repo.getToolkitDetailed(slugValue))
40
.pipe(
41
Effect.asSome,
116
- Effect.catchTag('services/HttpServerError', (e: HttpServerError) =>
117
- Effect.gen(function* () {
118
- // Show structured error message and suggested fix from the API
119
- if (e.details) {
120
- yield* ui.log.error(e.details.message);
121
- yield* ui.log.step(e.details.suggestedFix);
122
- } else {
123
- yield* ui.log.error(`Failed to fetch toolkit "${slugValue}".`);
124
- }
125
-
126
- // Try to suggest similar toolkits
127
- const suggestions = yield* repo.searchToolkits({ search: slugValue, limit: 3 }).pipe(
128
- Effect.map(r => r.items),
129
- Effect.catchAll(() => Effect.succeed([]))
130
- );
131
-
132
- if (suggestions.length > 0) {
133
- const suggestionLines = suggestions
134
- .map(s => ` ${s.slug} — ${s.meta.description}`)
135
- .join('\n');
136
- yield* ui.log.step(
137
- `Did you mean?\n${suggestionLines}\n\n> composio toolkits info "${suggestions[0]!.slug}"`
138
- );
139
- } else {
140
- yield* ui.log.step('Browse available toolkits:\n> composio toolkits list');
141
- }
142
-
143
- return Option.none();
42
+ Effect.catchTag(
43
+ 'services/HttpServerError',
44
+ handleHttpServerError(ui, {
45
+ fallbackMessage: `Failed to fetch toolkit "${slugValue}".`,
46
+ hint: 'Browse available toolkits:\n> composio toolkits list',
47
+ fallbackValue: Option.none(),
48
+ searchForSuggestions: () =>
49
+ repo.searchToolkits({ search: slugValue, limit: 3 }).pipe(
50
+ Effect.map(r =>
51
+ r.items.map(s => ({
52
+ label: `${s.slug} — ${s.meta.description}`,
53
+ command: `> composio toolkits info "${s.slug}"`,
54
+ }))
55
+ )
56
+ ),
57
})
58
)
59
);
68
69
// Next step hint
70
yield* ui.log.step(
158
- `To list tools in this toolkit:\n> composio tools list --toolkit "${toolkit.slug}"`
71
+ `To list tools in this toolkit:\n> composio tools list --toolkits "${toolkit.slug}"`
72
);
73
74
yield* ui.output(JSON.stringify(toolkit, null, 2));