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.59 KB
Raw
1 import type { ToolRetrieveResponse } from '@composio/client/resources/tools';
2 import { commandHintExample } from 'src/services/command-hints';
3 import { bold } from 'src/ui/colors';
4
5 /** The cached input definition `tools info` reports: where it lives and which version it is. */
6 export type ToolInfoDefinition = {
7 readonly schemaPath: string;
8 readonly version: string | null;
9 };
10
11 // --- stderr -----------------------------------------------------------------------------------
12
13 export const MISSING_SLUG_MESSAGE = 'Missing required argument: <slug>';
14 export const MISSING_SLUG_HINT =
15 'Try specifying a tool slug, e.g.:\n> composio tools info "GMAIL_SEND_EMAIL"';
16
17 export const fetchingToolMessage = (slug: string) => `Fetching tool "${slug}"...`;
18 export const toolNotFoundMessage = (slug: string) => `Tool "${slug}" not found.`;
19
20 /** One "did you mean" suggestion for a slug that was not found. */
21 export const toolSuggestion = (tool: { readonly slug: string; readonly description: string }) => ({
22 label: `${tool.slug} — ${tool.description}`,
23 command: `> composio tools info "${tool.slug}"`,
24 });
25
26 /** The note body: slug, name, toolkit, version, description, and the schema cache path. */
27 export const formatToolInfoSummary = (tool: ToolRetrieveResponse, definition: ToolInfoDefinition) =>
28 [
29 `${bold('Slug:')} ${tool.slug}`,
30 `${bold('Name:')} ${tool.name}`,
31 `${bold('Toolkit:')} ${tool.toolkit.slug}`,
32 `${bold('Version:')} ${definition.version ?? '-'}`,
33 `${bold('Description:')} ${tool.description}`,
34 `${bold('Schema Cache:')} ${definition.schemaPath}`,
35 ].join('\n');
36
37 export const toolInfoNoteTitle = (tool: ToolRetrieveResponse) => `Tool: ${tool.name}`;
38
39 export const inspectSchemaHint = (definition: ToolInfoDefinition) =>
40 `Inspect schema with jq:\n> jq '{required: (.inputSchema.required // []), keys: (.inputSchema.properties | keys)}' "${definition.schemaPath}"`;
41
42 export const executeToolHint = (tool: ToolRetrieveResponse) =>
43 `Then execute it:\n> ${commandHintExample('root.execute', { slug: tool.slug })} --dry-run`;
44
45 // --- stdout -----------------------------------------------------------------------------------
46
47 /** The tool and the CLI-facing input schema `composio execute` validates against. */
48 export const formatToolInfoJson = (
49 tool: ToolRetrieveResponse,
50 definition: ToolInfoDefinition,
51 inputSchema: unknown
52 ) =>
53 JSON.stringify(
54 {
55 slug: tool.slug,
56 name: tool.name,
57 description: tool.description,
58 toolkit: tool.toolkit.slug,
59 version: definition.version,
60 schemaPath: definition.schemaPath,
61 inputSchema,
62 },
63 null,
64 2
65 );