@devries-cameron20 / composio-1 / commits / abcc51628
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.

refactor(cli): move `logs tools` into the directory shape (#4989)

This PR: - moves `dev logs tools` to `logs/tools/logs.tools.{cmd,handler,errors}.ts`, mirroring `logs/triggers/` (#4971); `logs/commands/` no longer exists - routes to the single-log or list flow with `Option.match` on a non-empty `log_id`, as before (an empty id still lists) - builds the search params from one field table, in the same order as before - moves both test suites to `test/src/commands/logs/tools/` and adds 7 argv-level cases (empty page, every filter flag's order with clamped limit and cursor, next cursor hint, single-log fetch and failure, empty id, logged out) - part of the CLI command-layout series (legacy-shape cleanup before U10); no user-visible change, so no CHANGELOG entry ## Context The root `.gitignore` has a bare `logs` rule, so the new files under `src/commands/logs/tools/` and `test/src/commands/logs/tools/` needed `git add -f`. Verified: `pnpm --filter @composio/cli test` (2047 passed; the one failure was the known `analytics.dispatch` install_id flake, which passes on rerun; `validate:command-tests` still reports 2 exemptions), CLI `typecheck`, `lint:effect` (0 errors), oxlint and prettier on touched files, root `pnpm typecheck`, `root-help-consistency.test.ts`. Binary smoke: built the binary on this branch and on `origin/next` and ran 29 invocations with an isolated `HOME` (`--help`/`help` pages for `tools`, `dev triggers`, `dev logs`, `dev logs tools`, `dev logs triggers`, plus logged-out runs and parse errors of `dev logs tools`). stdout, stderr and exit codes are byte-identical.

Alberto Schiabel committed Oct 20, 2026 at 18:34 UTC abcc51628249395423015ddd494fb5d24a2b6bc1
8 files changed +536 -307
ts/packages/cli/src/commands/logs/commands/logs.tools.cmd.ts deleted
-252
@@ -1,252 +0,0 @@
1 -import { Argument, Command, Flag } from 'effect/cli';
2 -import { Effect, Option } from 'effect';
3 -import { failedWith, requestError } from 'src/effects/request-error';
4 -import { TerminalUI } from 'src/services/terminal-ui';
5 -import { CommandSurface } from 'src/commands/surface';
6 -import { ComposioClientSingleton } from 'src/services/composio-clients';
7 -import { idempotent } from 'src/services/composio-request';
8 -import { clampLimit } from 'src/ui/clamp-limit';
9 -import { nonEmptyOrUndefined, optionalParams } from 'src/utils/optional-params';
10 -import { parseCsv } from 'src/commands/triggers/parse-csv';
11 -import { formatToolLogInfo, formatToolLogsTable } from '../format';
12 -import { commandHintStep } from 'src/services/command-hints';
13 -import { toSearchParam } from '../utils';
14 -
15 -class ToolLogsRequestError extends requestError('commands/ToolLogsRequestError') {}
16 -
17 -type ToolLogFilterInput = {
18 - tool?: string;
19 - toolkit?: string;
20 - connectedAccountId?: string;
21 - authConfigId?: string;
22 - status?: string;
23 - userId?: string;
24 - logId?: string;
25 - toolRouterSessionId?: string;
26 - sessionId?: string;
27 -};
28 -
29 -const toSearchParams = (value: string | undefined, field: string) =>
30 - value === undefined ? [] : parseCsv(value).map(item => toSearchParam(field, item));
31 -
32 -export const buildToolLogShorthandSearchParams = (
33 - filters: ToolLogFilterInput
34 -): Array<ReturnType<typeof toSearchParam>> => [
35 - ...toSearchParams(filters.tool, 'action_key'),
36 - ...toSearchParams(filters.toolkit, 'toolkit_key'),
37 - ...toSearchParams(filters.connectedAccountId, 'connected_account_id'),
38 - ...toSearchParams(filters.authConfigId, 'auth_config_id'),
39 - ...toSearchParams(filters.status, 'execution_status'),
40 - ...toSearchParams(filters.userId, 'user_id'),
41 - ...toSearchParams(filters.logId, 'log_id'),
42 - ...toSearchParams(filters.toolRouterSessionId, 'tool_router_session_id'),
43 - ...toSearchParams(filters.sessionId, 'session_id'),
44 -];
45 -
46 -const cursor = Flag.Int('cursor').pipe(
47 - Flag.optional,
48 - Flag.withDescription('Cursor for pagination')
49 -);
50 -
51 -const from = Flag.Int('from').pipe(
52 - Flag.withDescription('Start timestamp (epoch milliseconds)'),
53 - Flag.optional
54 -);
55 -
56 -const to = Flag.Int('to').pipe(
57 - Flag.withDescription('End timestamp (epoch milliseconds)'),
58 - Flag.optional
59 -);
60 -
61 -const limit = Flag.Int('limit').pipe(
62 - Flag.withDefault(30),
63 - Flag.withDescription('Number of logs to fetch (1-1000)')
64 -);
65 -
66 -const caseSensitive = Flag.Boolean('case-sensitive').pipe(
67 - Flag.withDefault(false),
68 - Flag.withDescription('Whether search params are case-sensitive')
69 -);
70 -
71 -const toolkit = Flag.String('toolkit').pipe(
72 - Flag.withDescription('Filter by toolkit key(s), comma-separated (e.g. "gmail,slack")'),
73 - Flag.optional
74 -);
75 -
76 -const tool = Flag.String('tool').pipe(
77 - Flag.withDescription('Filter by tool key(s), comma-separated (e.g. "GMAIL_SEND_EMAIL")'),
78 - Flag.optional
79 -);
80 -
81 -const connectedAccountId = Flag.String('connected-account-id').pipe(
82 - Flag.withDescription('Filter by connected account id(s), comma-separated'),
83 - Flag.optional
84 -);
85 -
86 -const authConfigId = Flag.String('auth-config-id').pipe(
87 - Flag.withDescription('Filter by auth config id(s), comma-separated'),
88 - Flag.optional
89 -);
90 -
91 -const status = Flag.String('status').pipe(
92 - Flag.withDescription('Filter by execution status value(s), comma-separated'),
93 - Flag.optional
94 -);
95 -
96 -// Declared for its help row, which documents the comma-separated filter in place of the `dev`
97 -// group's shared row. The parser hands every `--user-id` under `dev` to the shared flag, so
98 -// the value is read from `CommandSurface`.
99 -const userId = Flag.String('user-id').pipe(
100 - Flag.withDescription('Filter by user id(s), comma-separated'),
101 - Flag.optional
102 -);
103 -
104 -const logIdFilter = Flag.String('log-id').pipe(
105 - Flag.withDescription('Filter by log id(s), comma-separated'),
106 - Flag.optional
107 -);
108 -
109 -const toolRouterSessionId = Flag.String('tool-router-session-id').pipe(
110 - Flag.withDescription('Filter by tool router session id(s), comma-separated'),
111 - Flag.optional
112 -);
113 -
114 -const sessionId = Flag.String('session-id').pipe(
115 - Flag.withDescription('Filter by session id(s), comma-separated'),
116 - Flag.optional
117 -);
118 -
119 -const logId = Argument.String('log_id').pipe(
120 - Argument.withDescription('Tool log ID'),
121 - Argument.optional
122 -);
123 -
124 -/**
125 - * List tool execution logs with optional filters.
126 - *
127 - * @example
128 - * ```bash
129 - * composio dev logs tools --limit 50
130 - * composio dev logs tools <log_id>
131 - * composio dev logs tools --toolkit gmail --tool GMAIL_SEND_EMAIL
132 - * composio dev logs tools --connected-account-id con_123 --user-id user_123
133 - * composio dev logs tools --status success --auth-config-id ac_123
134 - * composio dev logs tools --from 1735689600000 --to 1735776000000
135 - * ```
136 - */
137 -export const logsCmd$Tools = Command.make(
138 - 'tools',
139 - {
140 - logId,
141 - cursor,
142 - from,
143 - to,
144 - limit,
145 - caseSensitive,
146 - toolkit,
147 - tool,
148 - connectedAccountId,
149 - authConfigId,
150 - status,
151 - userId,
152 - logIdFilter,
153 - toolRouterSessionId,
154 - sessionId,
155 - },
156 - ({
157 - logId,
158 - cursor,
159 - from,
160 - to,
161 - limit,
162 - caseSensitive,
163 - toolkit,
164 - tool,
165 - connectedAccountId,
166 - authConfigId,
167 - status,
168 - userId,
169 - logIdFilter,
170 - toolRouterSessionId,
171 - sessionId,
172 - }) =>
173 - Effect.gen(function* () {
174 - const userIdFilter = Option.orElse((yield* CommandSurface).userId, () => userId);
175 - const ui = yield* TerminalUI;
176 - const clientSingleton = yield* ComposioClientSingleton;
177 - const client = yield* clientSingleton.get();
178 - const clampedLimit = clampLimit(limit);
179 - const shorthandSearchParams = buildToolLogShorthandSearchParams({
180 - tool: Option.getOrUndefined(tool),
181 - toolkit: Option.getOrUndefined(toolkit),
182 - connectedAccountId: Option.getOrUndefined(connectedAccountId),
183 - authConfigId: Option.getOrUndefined(authConfigId),
184 - status: Option.getOrUndefined(status),
185 - userId: Option.getOrUndefined(userIdFilter),
186 - logId: Option.getOrUndefined(logIdFilter),
187 - toolRouterSessionId: Option.getOrUndefined(toolRouterSessionId),
188 - sessionId: Option.getOrUndefined(sessionId),
189 - });
190 - const toolLogId = Option.getOrUndefined(logId);
191 -
192 - if (toolLogId) {
193 - const toolLog = yield* ui.withSpinner(
194 - `Fetching tool log "${toolLogId}"...`,
195 - client.logs.tools
196 - .retrieve(toolLogId, idempotent)
197 - .pipe(failedWith(ToolLogsRequestError, `Failed to fetch tool log "${toolLogId}".`))
198 - );
199 -
200 - yield* ui.log.info(
201 - `${formatToolLogInfo(toolLog)}\n\nPayload:\n${JSON.stringify(toolLog.payloadReceived, null, 2)}\n\nResponse:\n${JSON.stringify(toolLog.response, null, 2)}`
202 - );
203 - yield* ui.output(JSON.stringify(toolLog, null, 2));
204 - return;
205 - }
206 -
207 - const response = yield* ui.withSpinner(
208 - 'Fetching tool logs...',
209 - client.logs.tools
210 - .list(
211 - {
212 - ...optionalParams({ from, to }),
213 - cursor: Option.getOrUndefined(cursor) ?? null,
214 - limit: clampedLimit,
215 - case_sensitive: caseSensitive,
216 - search_params: nonEmptyOrUndefined(shorthandSearchParams),
217 - },
218 - idempotent
219 - )
220 - .pipe(failedWith(ToolLogsRequestError, 'Failed to fetch tool logs.'))
221 - );
222 -
223 - const logs = response.data ?? [];
224 -
225 - if (logs.length === 0) {
226 - yield* ui.log.warn('No tool logs found for the given filters.');
227 - yield* ui.output(JSON.stringify(response, null, 2));
228 - return;
229 - }
230 -
231 - yield* ui.log.info(
232 - `Listing ${logs.length} tool log${logs.length === 1 ? '' : 's'}\n\n${formatToolLogsTable(logs)}`
233 - );
234 -
235 - const firstLogId = logs[0]?.id;
236 - if (firstLogId) {
237 - yield* ui.log.step(
238 - commandHintStep('To view full details for a log', 'dev.logs.tools', {
239 - logId: firstLogId,
240 - })
241 - );
242 - }
243 -
244 - if (response.nextCursor !== null && response.nextCursor !== undefined) {
245 - yield* ui.log.step(`Next cursor: ${response.nextCursor}`);
246 - }
247 -
248 - yield* ui.output(JSON.stringify(response, null, 2));
249 - })
250 -).pipe(
251 - Command.withDescription('List tool execution logs, or pass a log_id to fetch a specific log.')
252 -);
ts/packages/cli/src/commands/logs/logs.cmd.ts
+1 -1
@@ -1,6 +1,6 @@
1 import { Command } from 'effect/cli';
2 import { requireLogin } from 'src/effects/require-auth';
3 -import { logsCmd$Tools } from './commands/logs.tools.cmd';
3 +import { logsCmd$Tools } from './tools/logs.tools.cmd';
4 import { logsCmd$Triggers } from './triggers/logs.triggers.cmd';
5
6 /**
ts/packages/cli/src/commands/logs/tools/logs.tools.cmd.ts new
+104
@@ -0,0 +1,104 @@
1 +import { Argument, Command, Flag } from 'effect/cli';
2 +import { runLogsTools } from './logs.tools.handler';
3 +
4 +const cursor = Flag.Int('cursor').pipe(
5 + Flag.optional,
6 + Flag.withDescription('Cursor for pagination')
7 +);
8 +
9 +const from = Flag.Int('from').pipe(
10 + Flag.withDescription('Start timestamp (epoch milliseconds)'),
11 + Flag.optional
12 +);
13 +
14 +const to = Flag.Int('to').pipe(
15 + Flag.withDescription('End timestamp (epoch milliseconds)'),
16 + Flag.optional
17 +);
18 +
19 +const limit = Flag.Int('limit').pipe(
20 + Flag.withDefault(30),
21 + Flag.withDescription('Number of logs to fetch (1-1000)')
22 +);
23 +
24 +const caseSensitive = Flag.Boolean('case-sensitive').pipe(
25 + Flag.withDefault(false),
26 + Flag.withDescription('Whether search params are case-sensitive')
27 +);
28 +
29 +const toolkit = Flag.String('toolkit').pipe(
30 + Flag.withDescription('Filter by toolkit key(s), comma-separated (e.g. "gmail,slack")'),
31 + Flag.optional
32 +);
33 +
34 +const tool = Flag.String('tool').pipe(
35 + Flag.withDescription('Filter by tool key(s), comma-separated (e.g. "GMAIL_SEND_EMAIL")'),
36 + Flag.optional
37 +);
38 +
39 +const connectedAccountId = Flag.String('connected-account-id').pipe(
40 + Flag.withDescription('Filter by connected account id(s), comma-separated'),
41 + Flag.optional
42 +);
43 +
44 +const authConfigId = Flag.String('auth-config-id').pipe(
45 + Flag.withDescription('Filter by auth config id(s), comma-separated'),
46 + Flag.optional
47 +);
48 +
49 +const status = Flag.String('status').pipe(
50 + Flag.withDescription('Filter by execution status value(s), comma-separated'),
51 + Flag.optional
52 +);
53 +
54 +// Declared for its help row, which documents the comma-separated filter in place of the `dev`
55 +// group's shared row. The parser hands every `--user-id` under `dev` to the shared flag, so
56 +// the value is read from `CommandSurface`.
57 +const userId = Flag.String('user-id').pipe(
58 + Flag.withDescription('Filter by user id(s), comma-separated'),
59 + Flag.optional
60 +);
61 +
62 +const logIdFilter = Flag.String('log-id').pipe(
63 + Flag.withDescription('Filter by log id(s), comma-separated'),
64 + Flag.optional
65 +);
66 +
67 +const toolRouterSessionId = Flag.String('tool-router-session-id').pipe(
68 + Flag.withDescription('Filter by tool router session id(s), comma-separated'),
69 + Flag.optional
70 +);
71 +
72 +const sessionId = Flag.String('session-id').pipe(
73 + Flag.withDescription('Filter by session id(s), comma-separated'),
74 + Flag.optional
75 +);
76 +
77 +const logId = Argument.String('log_id').pipe(
78 + Argument.withDescription('Tool log ID'),
79 + Argument.optional
80 +);
81 +
82 +export const logsCmd$Tools = Command.make(
83 + 'tools',
84 + {
85 + logId,
86 + cursor,
87 + from,
88 + to,
89 + limit,
90 + caseSensitive,
91 + toolkit,
92 + tool,
93 + connectedAccountId,
94 + authConfigId,
95 + status,
96 + userId,
97 + logIdFilter,
98 + toolRouterSessionId,
99 + sessionId,
100 + },
101 + runLogsTools
102 +).pipe(
103 + Command.withDescription('List tool execution logs, or pass a log_id to fetch a specific log.')
104 +);
ts/packages/cli/src/commands/logs/tools/logs.tools.errors.ts new
+3
@@ -0,0 +1,3 @@
1 +import { requestError } from 'src/effects/request-error';
2 +
3 +export class ToolLogsRequestError extends requestError('commands/ToolLogsRequestError') {}
ts/packages/cli/src/commands/logs/tools/logs.tools.handler.ts new
+184
@@ -0,0 +1,184 @@
1 +import { Array as Arr, Effect, Option, String as Str } from 'effect';
2 +import { CommandSurface } from 'src/commands/surface';
3 +import { parseCsv } from 'src/commands/triggers/parse-csv';
4 +import { failedWith } from 'src/effects/request-error';
5 +import { commandHintStep } from 'src/services/command-hints';
6 +import { ComposioClientSingleton } from 'src/services/composio-clients';
7 +import { idempotent } from 'src/services/composio-request';
8 +import { TerminalUI } from 'src/services/terminal-ui';
9 +import { clampLimit } from 'src/ui/clamp-limit';
10 +import { nonEmptyOrUndefined, optionalParams } from 'src/utils/optional-params';
11 +import { formatToolLogInfo, formatToolLogsTable } from '../format';
12 +import { toSearchParam, type SearchParam } from '../utils';
13 +import { ToolLogsRequestError } from './logs.tools.errors';
14 +
15 +export type LogsToolsParams = {
16 + readonly logId: Option.Option<string>;
17 + readonly cursor: Option.Option<number>;
18 + readonly from: Option.Option<number>;
19 + readonly to: Option.Option<number>;
20 + readonly limit: number;
21 + readonly caseSensitive: boolean;
22 + readonly toolkit: Option.Option<string>;
23 + readonly tool: Option.Option<string>;
24 + readonly connectedAccountId: Option.Option<string>;
25 + readonly authConfigId: Option.Option<string>;
26 + readonly status: Option.Option<string>;
27 + /** Read only when the `dev` group's shared `--user-id` is absent. */
28 + readonly userId: Option.Option<string>;
29 + readonly logIdFilter: Option.Option<string>;
30 + readonly toolRouterSessionId: Option.Option<string>;
31 + readonly sessionId: Option.Option<string>;
32 +};
33 +
34 +type ToolLogFilterInput = {
35 + readonly tool?: string;
36 + readonly toolkit?: string;
37 + readonly connectedAccountId?: string;
38 + readonly authConfigId?: string;
39 + readonly status?: string;
40 + readonly userId?: string;
41 + readonly logId?: string;
42 + readonly toolRouterSessionId?: string;
43 + readonly sessionId?: string;
44 +};
45 +
46 +/** The search field each filter is sent as, in the order the filters are sent. */
47 +const TOOL_LOG_FILTER_FIELDS = [
48 + ['tool', 'action_key'],
49 + ['toolkit', 'toolkit_key'],
50 + ['connectedAccountId', 'connected_account_id'],
51 + ['authConfigId', 'auth_config_id'],
52 + ['status', 'execution_status'],
53 + ['userId', 'user_id'],
54 + ['logId', 'log_id'],
55 + ['toolRouterSessionId', 'tool_router_session_id'],
56 + ['sessionId', 'session_id'],
57 +] as const satisfies ReadonlyArray<readonly [keyof ToolLogFilterInput, string]>;
58 +
59 +/**
60 + * One `==` search param per comma-separated value of each present filter, in
61 + * the order of `TOOL_LOG_FILTER_FIELDS`.
62 + */
63 +export const buildToolLogShorthandSearchParams = (
64 + filters: ToolLogFilterInput
65 +): Array<SearchParam> =>
66 + Arr.flatMap(TOOL_LOG_FILTER_FIELDS, ([key, field]) =>
67 + Option.match(Option.fromUndefinedOr(filters[key]), {
68 + onNone: () => [],
69 + onSome: csv => parseCsv(csv).map(value => toSearchParam(field, value)),
70 + })
71 + );
72 +
73 +const showToolLog = (toolLogId: string) =>
74 + Effect.gen(function* () {
75 + const ui = yield* TerminalUI;
76 + const client = yield* (yield* ComposioClientSingleton).get();
77 + const toolLog = yield* ui.withSpinner(
78 + `Fetching tool log "${toolLogId}"...`,
79 + client.logs.tools
80 + .retrieve(toolLogId, idempotent)
81 + .pipe(failedWith(ToolLogsRequestError, `Failed to fetch tool log "${toolLogId}".`))
82 + );
83 +
84 + yield* ui.log.info(
85 + `${formatToolLogInfo(toolLog)}\n\nPayload:\n${JSON.stringify(toolLog.payloadReceived, null, 2)}\n\nResponse:\n${JSON.stringify(toolLog.response, null, 2)}`
86 + );
87 + yield* ui.output(JSON.stringify(toolLog, null, 2));
88 + });
89 +
90 +const listToolLogs = ({
91 + cursor,
92 + from,
93 + to,
94 + limit,
95 + caseSensitive,
96 + toolkit,
97 + tool,
98 + connectedAccountId,
99 + authConfigId,
100 + status,
101 + userId,
102 + logIdFilter,
103 + toolRouterSessionId,
104 + sessionId,
105 +}: LogsToolsParams) =>
106 + Effect.gen(function* () {
107 + const userIdFilter = Option.orElse((yield* CommandSurface).userId, () => userId);
108 + const ui = yield* TerminalUI;
109 + const client = yield* (yield* ComposioClientSingleton).get();
110 + const searchParams = buildToolLogShorthandSearchParams(
111 + optionalParams({
112 + tool,
113 + toolkit,
114 + connectedAccountId,
115 + authConfigId,
116 + status,
117 + userId: userIdFilter,
118 + logId: logIdFilter,
119 + toolRouterSessionId,
120 + sessionId,
121 + })
122 + );
123 +
124 + const response = yield* ui.withSpinner(
125 + 'Fetching tool logs...',
126 + client.logs.tools
127 + .list(
128 + {
129 + ...optionalParams({ from, to }),
130 + cursor: Option.getOrNull(cursor),
131 + limit: clampLimit(limit),
132 + case_sensitive: caseSensitive,
133 + search_params: nonEmptyOrUndefined(searchParams),
134 + },
135 + idempotent
136 + )
137 + .pipe(failedWith(ToolLogsRequestError, 'Failed to fetch tool logs.'))
138 + );
139 +
140 + yield* Arr.match(response.data ?? [], {
141 + onEmpty: () => ui.log.warn('No tool logs found for the given filters.'),
142 + onNonEmpty: logs =>
143 + Effect.gen(function* () {
144 + yield* ui.log.info(
145 + `Listing ${logs.length} tool log${logs.length === 1 ? '' : 's'}\n\n${formatToolLogsTable(logs)}`
146 + );
147 +
148 + const firstLogId = Arr.headNonEmpty(logs).id;
149 + if (firstLogId) {
150 + yield* ui.log.step(
151 + commandHintStep('To view full details for a log', 'dev.logs.tools', {
152 + logId: firstLogId,
153 + })
154 + );
155 + }
156 +
157 + if (response.nextCursor !== null && response.nextCursor !== undefined) {
158 + yield* ui.log.step(`Next cursor: ${response.nextCursor}`);
159 + }
160 + }),
161 + });
162 +
163 + yield* ui.output(JSON.stringify(response, null, 2));
164 + });
165 +
166 +/**
167 + * Show one tool log when a log id is given, otherwise list tool execution logs
168 + * with optional filters.
169 + *
170 + * @example
171 + * ```bash
172 + * composio dev logs tools --limit 50
173 + * composio dev logs tools <log_id>
174 + * composio dev logs tools --toolkit gmail --tool GMAIL_SEND_EMAIL
175 + * composio dev logs tools --connected-account-id con_123 --user-id user_123
176 + * composio dev logs tools --status success --auth-config-id ac_123
177 + * composio dev logs tools --from 1735689600000 --to 1735776000000
178 + * ```
179 + */
180 +export const runLogsTools = (params: LogsToolsParams) =>
181 + Option.match(Option.filter(params.logId, Str.isNonEmpty), {
182 + onSome: showToolLog,
183 + onNone: () => listToolLogs(params),
184 + });
ts/packages/cli/test/src/commands/logs/logs.tools.cmd.test.ts deleted
-54
@@ -1,54 +0,0 @@
1 -import { describe, expect, it } from 'vitest';
2 -import { buildToolLogShorthandSearchParams } from 'src/commands/logs/commands/logs.tools.cmd';
3 -
4 -describe('buildToolLogShorthandSearchParams', () => {
5 - it('[Given] no filters [Then] returns empty search params', () => {
6 - expect(buildToolLogShorthandSearchParams({})).toEqual([]);
7 - });
8 -
9 - it('[Given] all supported filters [Then] maps each one to the expected backend key', () => {
10 - const output = buildToolLogShorthandSearchParams({
11 - tool: 'GMAIL_SEND_EMAIL',
12 - toolkit: 'gmail',
13 - connectedAccountId: 'ca_123',
14 - authConfigId: 'ac_123',
15 - status: 'success',
16 - userId: 'user_123',
17 - logId: 'log_123',
18 - toolRouterSessionId: 'trs_123',
19 - sessionId: 'sess_123',
20 - });
21 -
22 - expect(output).toEqual([
23 - { field: 'action_key', operation: '==', value: 'GMAIL_SEND_EMAIL' },
24 - { field: 'toolkit_key', operation: '==', value: 'gmail' },
25 - { field: 'connected_account_id', operation: '==', value: 'ca_123' },
26 - { field: 'auth_config_id', operation: '==', value: 'ac_123' },
27 - { field: 'execution_status', operation: '==', value: 'success' },
28 - { field: 'user_id', operation: '==', value: 'user_123' },
29 - { field: 'log_id', operation: '==', value: 'log_123' },
30 - { field: 'tool_router_session_id', operation: '==', value: 'trs_123' },
31 - { field: 'session_id', operation: '==', value: 'sess_123' },
32 - ]);
33 - });
34 -
35 - it('[Given] comma-separated filter values [Then] expands each value into separate search params', () => {
36 - const output = buildToolLogShorthandSearchParams({
37 - tool: 'GMAIL_SEND_EMAIL,SLACK_SEND_MESSAGE',
38 - toolkit: 'gmail,slack',
39 - status: 'success,failed',
40 - logId: 'log_1,log_2',
41 - });
42 -
43 - expect(output).toEqual([
44 - { field: 'action_key', operation: '==', value: 'GMAIL_SEND_EMAIL' },
45 - { field: 'action_key', operation: '==', value: 'SLACK_SEND_MESSAGE' },
46 - { field: 'toolkit_key', operation: '==', value: 'gmail' },
47 - { field: 'toolkit_key', operation: '==', value: 'slack' },
48 - { field: 'execution_status', operation: '==', value: 'success' },
49 - { field: 'execution_status', operation: '==', value: 'failed' },
50 - { field: 'log_id', operation: '==', value: 'log_1' },
51 - { field: 'log_id', operation: '==', value: 'log_2' },
52 - ]);
53 - });
54 -});
ts/packages/cli/test/src/commands/logs/tools/logs.tools.client.cmd.test.ts renamed
ts/packages/cli/test/src/commands/logs/tools/logs.tools.cmd.test.ts new
+244
@@ -0,0 +1,244 @@
1 +import { describe, expect, it, layer } from '@effect/vitest';
2 +import { ConfigProvider, Effect } from 'effect';
3 +import { buildToolLogShorthandSearchParams } from 'src/commands/logs/tools/logs.tools.handler';
4 +import { cli, MockConsole, TestLive } from 'test/__utils__';
5 +import { stubClientResources } from 'test/__utils__/services/stub-composio-client';
6 +
7 +const testLayer = TestLive({
8 + baseConfigProvider: ConfigProvider.fromEnv({ env: { COMPOSIO_USER_API_KEY: 'test_api_key' } }),
9 + fixture: 'global-test-user-id',
10 +});
11 +
12 +const log = {
13 + id: 'log_1',
14 + actionKey: 'GMAIL_SEND_EMAIL',
15 + appKey: 'gmail',
16 + app: { icon: 'https://logos.composio.dev/gmail', name: 'Gmail' },
17 + connectedAccountId: 'ca_gmail_1',
18 + entityId: 'user_1',
19 + status: 'success',
20 + executionTime: 412,
21 + minimalResponse: '{"id":"msg_1"}',
22 + createdAt: 1767225600000,
23 +};
24 +
25 +describe('buildToolLogShorthandSearchParams', () => {
26 + it('[Given] no filters [Then] returns empty search params', () => {
27 + expect(buildToolLogShorthandSearchParams({})).toEqual([]);
28 + });
29 +
30 + it('[Given] all supported filters [Then] maps each one to the expected backend key', () => {
31 + const output = buildToolLogShorthandSearchParams({
32 + tool: 'GMAIL_SEND_EMAIL',
33 + toolkit: 'gmail',
34 + connectedAccountId: 'ca_123',
35 + authConfigId: 'ac_123',
36 + status: 'success',
37 + userId: 'user_123',
38 + logId: 'log_123',
39 + toolRouterSessionId: 'trs_123',
40 + sessionId: 'sess_123',
41 + });
42 +
43 + expect(output).toEqual([
44 + { field: 'action_key', operation: '==', value: 'GMAIL_SEND_EMAIL' },
45 + { field: 'toolkit_key', operation: '==', value: 'gmail' },
46 + { field: 'connected_account_id', operation: '==', value: 'ca_123' },
47 + { field: 'auth_config_id', operation: '==', value: 'ac_123' },
48 + { field: 'execution_status', operation: '==', value: 'success' },
49 + { field: 'user_id', operation: '==', value: 'user_123' },
50 + { field: 'log_id', operation: '==', value: 'log_123' },
51 + { field: 'tool_router_session_id', operation: '==', value: 'trs_123' },
52 + { field: 'session_id', operation: '==', value: 'sess_123' },
53 + ]);
54 + });
55 +
56 + it('[Given] comma-separated filter values [Then] expands each value into separate search params', () => {
57 + const output = buildToolLogShorthandSearchParams({
58 + tool: 'GMAIL_SEND_EMAIL,SLACK_SEND_MESSAGE',
59 + toolkit: 'gmail,slack',
60 + status: 'success,failed',
61 + logId: 'log_1,log_2',
62 + });
63 +
64 + expect(output).toEqual([
65 + { field: 'action_key', operation: '==', value: 'GMAIL_SEND_EMAIL' },
66 + { field: 'action_key', operation: '==', value: 'SLACK_SEND_MESSAGE' },
67 + { field: 'toolkit_key', operation: '==', value: 'gmail' },
68 + { field: 'toolkit_key', operation: '==', value: 'slack' },
69 + { field: 'execution_status', operation: '==', value: 'success' },
70 + { field: 'execution_status', operation: '==', value: 'failed' },
71 + { field: 'log_id', operation: '==', value: 'log_1' },
72 + { field: 'log_id', operation: '==', value: 'log_2' },
73 + ]);
74 + });
75 +});
76 +
77 +describe('CLI: composio dev logs tools', () => {
78 + layer(testLayer)('[Given] no filters and no logs', it => {
79 + it.effect('[Then] it warns and prints the empty page as the API returned it', () =>
80 + Effect.gen(function* () {
81 + const page = { data: [], nextCursor: null };
82 + const stub = stubClientResources(['logs'], () => Response.json(page));
83 + yield* cli(['dev', 'logs', 'tools']).pipe(Effect.provide(stub.layer));
84 + const stderr = yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true });
85 + const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
86 +
87 + expect(stderr.join('\n')).toContain('No tool logs found for the given filters.');
88 + expect(stdout).toEqual([JSON.stringify(page, null, 2)]);
89 + expect(stub.requests).toMatchObject([
90 + { method: 'POST', body: { cursor: null, limit: 30, case_sensitive: false } },
91 + ]);
92 + expect(stub.requests[0]?.body).not.toHaveProperty('search_params');
93 + })
94 + );
95 + });
96 +
97 + layer(testLayer)('[Given] every filter flag', it => {
98 + it.effect(
99 + '[Then] each is sent as search params in a fixed order and the limit is clamped',
100 + () =>
101 + Effect.gen(function* () {
102 + const stub = stubClientResources(['logs'], () => Response.json({ data: [] }));
103 + yield* cli([
104 + 'dev',
105 + 'logs',
106 + 'tools',
107 + '--session-id',
108 + 'sess_1',
109 + '--tool-router-session-id',
110 + 'trs_1',
111 + '--log-id',
112 + 'log_a,log_b',
113 + '--user-id',
114 + 'user_1',
115 + '--status',
116 + 'failed',
117 + '--auth-config-id',
118 + 'ac_1',
119 + '--connected-account-id',
120 + 'ca_1',
121 + '--toolkit',
122 + 'gmail,slack',
123 + '--tool',
124 + 'GMAIL_SEND_EMAIL',
125 + '--cursor',
126 + '7',
127 + '--from',
128 + '1',
129 + '--to',
130 + '2',
131 + '--limit',
132 + '5000',
133 + '--case-sensitive',
134 + ]).pipe(Effect.provide(stub.layer));
135 +
136 + expect(stub.requests).toEqual([
137 + {
138 + method: 'POST',
139 + path: '/api/v3.1/internal/action_execution/logs',
140 + body: {
141 + from: 1,
142 + to: 2,
143 + cursor: 7,
144 + limit: 1000,
145 + case_sensitive: true,
146 + search_params: [
147 + { field: 'action_key', operation: '==', value: 'GMAIL_SEND_EMAIL' },
148 + { field: 'toolkit_key', operation: '==', value: 'gmail' },
149 + { field: 'toolkit_key', operation: '==', value: 'slack' },
150 + { field: 'connected_account_id', operation: '==', value: 'ca_1' },
151 + { field: 'auth_config_id', operation: '==', value: 'ac_1' },
152 + { field: 'execution_status', operation: '==', value: 'failed' },
153 + { field: 'user_id', operation: '==', value: 'user_1' },
154 + { field: 'log_id', operation: '==', value: 'log_a' },
155 + { field: 'log_id', operation: '==', value: 'log_b' },
156 + { field: 'tool_router_session_id', operation: '==', value: 'trs_1' },
157 + { field: 'session_id', operation: '==', value: 'sess_1' },
158 + ],
159 + },
160 + },
161 + ]);
162 + })
163 + );
164 + });
165 +
166 + layer(testLayer)('[Given] a page with a next cursor', it => {
167 + it.effect('[Then] it lists the logs, hints at the first one, and prints the cursor', () =>
168 + Effect.gen(function* () {
169 + const page = { data: [log], nextCursor: 42 };
170 + const stub = stubClientResources(['logs'], () => Response.json(page));
171 + yield* cli(['dev', 'logs', 'tools']).pipe(Effect.provide(stub.layer));
172 + const stderr = yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true });
173 + const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
174 +
175 + expect(stderr.join('\n')).toContain('Listing 1 tool log\n');
176 + expect(stderr).toContain(
177 + 'To view full details for a log:\n> composio dev logs tools "log_1"'
178 + );
179 + expect(stderr).toContain('Next cursor: 42');
180 + expect(stdout).toEqual([JSON.stringify(page, null, 2)]);
181 + })
182 + );
183 + });
184 +
185 + layer(testLayer)('[Given] a log id argument', it => {
186 + it.effect('[Then] it fetches that log alone and prints it as the API returned it', () =>
187 + Effect.gen(function* () {
188 + const toolLog = { ...log, payloadReceived: { to: 'a@b.c' }, response: { id: 'msg_1' } };
189 + const stub = stubClientResources(['logs'], () => Response.json(toolLog));
190 + yield* cli(['dev', 'logs', 'tools', 'log_1']).pipe(Effect.provide(stub.layer));
191 + const stderr = yield* MockConsole.getLines({ stream: 'stderr', stripAnsi: true });
192 + const stdout = yield* MockConsole.getLines({ stream: 'stdout' });
193 +
194 + expect(stub.requests).toEqual([
195 + { method: 'GET', path: '/api/v3.1/internal/action_execution/log/log_1' },
196 + ]);
197 + expect(stderr.join('\n')).toContain('Payload:\n{\n "to": "a@b.c"\n}');
198 + expect(stdout).toEqual([JSON.stringify(toolLog, null, 2)]);
199 + })
200 + );
201 + });
202 +
203 + layer(testLayer)('[Given] an empty log id argument', it => {
204 + it.effect('[Then] it lists logs instead of fetching one', () =>
205 + Effect.gen(function* () {
206 + const stub = stubClientResources(['logs'], () => Response.json({ data: [] }));
207 + yield* cli(['dev', 'logs', 'tools', '']).pipe(Effect.provide(stub.layer));
208 +
209 + expect(stub.requests).toMatchObject([{ method: 'POST' }]);
210 + })
211 + );
212 + });
213 +
214 + layer(testLayer)('[Given] the API rejects the request for one log', it => {
215 + it.effect('[Then] the failure names the log id', () =>
216 + Effect.gen(function* () {
217 + const stub = stubClientResources(['logs'], () =>
218 + Response.json(
219 + { error: { message: 'Not found', code: 1404, slug: 'Not_Found', status: 404 } },
220 + { status: 404 }
221 + )
222 + );
223 + const failure = yield* cli(['dev', 'logs', 'tools', 'log_missing']).pipe(
224 + Effect.provide(stub.layer),
225 + Effect.flip
226 + );
227 +
228 + expect(failure).toMatchObject({
229 + _tag: 'commands/ToolLogsRequestError',
230 + message: 'Failed to fetch tool log "log_missing".',
231 + });
232 + })
233 + );
234 + });
235 +
236 + layer(TestLive())('[Given] no API key', it => {
237 + it.effect('[Then] it fails with NotLoggedInError', () =>
238 + Effect.gen(function* () {
239 + const error = yield* cli(['dev', 'logs', 'tools']).pipe(Effect.flip);
240 + expect(error).toMatchObject({ _tag: 'commands/NotLoggedInError' });
241 + })
242 + );
243 + });
244 +});