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 154 lines 5.49 KB
Raw
1 import { telemetry, withCommandTelemetry } from 'src/analytics/command-input';
2 import { Array } from 'effect';
3 import { Argument, Command, Flag } from 'effect/cli';
4 import { withCommandMeta } from 'src/invocation/command-identity';
5 import { runToolsExecuteCommand } from './tools.execute.handler';
6
7 const slug = Argument.String('slug').pipe(
8 Argument.withDescription('Tool slug (e.g. "GITHUB_CREATE_ISSUE")')
9 );
10
11 const additionalSlugs = Argument.String('additional-slugs').pipe(
12 Argument.variadic(),
13 Argument.withDescription('Additional tool slugs for --parallel')
14 );
15 const parallel = Flag.Boolean('parallel').pipe(
16 Flag.withAlias('p'),
17 Flag.withDefault(false),
18 Flag.withDescription('Execute repeated tool slug/data groups concurrently')
19 );
20
21 const data = Flag.String('data').pipe(
22 Flag.withAlias('d'),
23 Flag.withDescription('JSON arguments, @file, or - for stdin'),
24 Flag.atLeast(0),
25 Flag.map(Array.head)
26 );
27 const file = Flag.String('file').pipe(
28 Flag.withDescription('Inject a local file path into the single file_uploadable input'),
29 Flag.optional
30 );
31 const accountOption = Flag.String('account').pipe(
32 Flag.withDescription(
33 'Connected account selector for the inferred toolkit. Matches alias, word_id, or connected account id.'
34 ),
35 Flag.atLeast(0),
36 Flag.map(Array.head)
37 );
38
39 const getSchema = Flag.Boolean('get-schema').pipe(
40 Flag.withDescription('Fetch and print the CLI-facing input schema without executing'),
41 Flag.withDefault(false)
42 );
43 const dryRun = Flag.Boolean('dry-run').pipe(
44 Flag.withDescription('Validate and preview the tool call without executing'),
45 Flag.withDefault(false)
46 );
47 const skipConnectionCheck = Flag.Boolean('skip-connection-check').pipe(
48 Flag.withDescription('Skip the connected-account check'),
49 Flag.withDefault(false)
50 );
51 const skipToolParamsCheck = Flag.Boolean('skip-tool-params-check').pipe(
52 Flag.withDescription('Skip input validation against cached schema'),
53 Flag.withDefault(false)
54 );
55 const skipChecks = Flag.Boolean('skip-checks').pipe(
56 Flag.withDescription('Skip both connection and input validation checks'),
57 Flag.withDefault(false)
58 );
59
60 const executeExamples = [
61 {
62 command:
63 'composio execute GMAIL_SEND_EMAIL -d \'{ recipient_email: "a@b.com", subject: "Hello", body: "World" }\'',
64 description: 'Send an email',
65 },
66 {
67 command:
68 'composio execute GITHUB_CREATE_ISSUE --account work -d \'{ owner: "acme", repo: "app", title: "Bug report", body: "Steps to reproduce..." }\'',
69 description: 'Create a GitHub issue with a named account',
70 },
71 {
72 command:
73 'composio execute SLACK_SEND_MESSAGE --dry-run -d \'{ channel: "general", markdown_text: "Hello team" }\'',
74 description: 'Preview what a tool call would send without executing',
75 },
76 {
77 command: 'composio execute GMAIL_SEND_EMAIL --get-schema',
78 description: 'Print the tool input schema as JSON (--help shows command options)',
79 },
80 {
81 command: 'composio execute GITHUB_CREATE_ISSUE -d @issue.json',
82 description: 'Read arguments from a file',
83 },
84 {
85 command:
86 'composio execute -p GMAIL_SEND_EMAIL -d \'{ recipient_email: "a@b.com" }\' GITHUB_CREATE_AN_ISSUE -d \'{ owner: "acme", repo: "app", title: "Bug" }\'',
87 description: 'Execute multiple tools concurrently',
88 },
89 ];
90
91 const executeFlags = {
92 slug,
93 additionalSlugs,
94 parallel,
95 data,
96 file,
97 account: accountOption,
98 getSchema,
99 dryRun,
100 skipConnectionCheck,
101 skipToolParamsCheck,
102 skipChecks,
103 };
104
105 const executeTelemetry = (input: Command.Command.Config.Infer<typeof executeFlags>) =>
106 telemetry.fields(
107 {
108 dry_run: telemetry.flag('--dry-run', input.dryRun),
109 get_schema: telemetry.flag('--get-schema', input.getSchema),
110 has_data: telemetry.flag('--data', telemetry.present(input.data)),
111 skip_connection_check: telemetry.flag('--skip-connection-check', input.skipConnectionCheck),
112 skip_tool_params_check: telemetry.flag('--skip-tool-params-check', input.skipToolParamsCheck),
113 skip_checks: telemetry.flag('--skip-checks', input.skipChecks),
114 },
115 input.slug
116 );
117
118 const rootToolsCmd$ExecuteBase = Command.make('execute', executeFlags, runToolsExecuteCommand).pipe(
119 Command.withDescription(
120 'Execute a tool by slug. Validates inputs against cached schemas and checks connections\nautomatically — just try it and it will tell you what to fix.'
121 ),
122 Command.withShortDescription(
123 'Execute a tool by slug. Validates inputs against cached schemas and checks connections'
124 ),
125 Command.withExamples(executeExamples),
126 withCommandMeta({ requiresLogin: true })
127 );
128
129 const devToolsCmd$ExecuteBase = Command.make(
130 'playground-execute',
131 executeFlags,
132 runToolsExecuteCommand
133 ).pipe(
134 Command.withDescription(
135 'Test tool executions against playground users using your developer project auth configs.\nUses --user-id when provided, otherwise falls back to your local or global playground test user id.\nArguments are validated against cached tool schemas in `~/.composio/tool_definitions/` when available.'
136 ),
137 Command.withShortDescription(
138 'Test tool executions against playground users using your developer project auth configs.'
139 ),
140 Command.withExamples(
141 executeExamples.map(example => ({
142 ...example,
143 command: example.command.replace('composio execute', 'composio dev playground-execute'),
144 }))
145 ),
146 withCommandMeta({ requiresLogin: true })
147 );
148
149 export const rootToolsCmd$Execute = withCommandTelemetry(
150 rootToolsCmd$ExecuteBase,
151 executeTelemetry
152 );
153
154 export const devToolsCmd$Execute = withCommandTelemetry(devToolsCmd$ExecuteBase, executeTelemetry);