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): validate API responses only where a call asks for it (#4856)
This PR: - is rebased onto `next` after https://github.com/ComposioHQ/composio/pull/4855 and https://github.com/ComposioHQ/composio/pull/4898 merged; its two own commits remain - makes client response validation opt-in: a read passes the `validated` request option (`src/services/composio-request.ts`) when the command uses the response through the client's types; every other call sends nothing extra - gives the client its full `schemaLoaders` table and deletes the hand-kept `composio-schema-loaders.ts`, its test, about 45 `decode: false` opt-outs, and the test-client guard that mirrored the client's pre-dispatch check - keeps validation on exactly the reads `next` validates since https://github.com/ComposioHQ/composio/pull/4878: `org.list`, `org.consumer.listConnectedToolkits` and `cli.realtime.credentials`; the drift-tolerant reads that PR made lenient (`logs.tools.*`, `logs.triggers.*`, `tools.list`, `tools.retrieve`, `org.project.list`, `toolRouter.session.search`, `toolRouter.session.toolkits`, `connectedAccounts.list`, `triggerInstances.listActive`) stay lenient, now by passing nothing - makes `getFor` take an org and a project together or neither (`ClientScope`); a scope with only an org used to compile and silently send no org header - adds lint bans on importing `make` or the client layers from `@composio/client/effect` outside `composio-clients.ts`, and on the `.js`/`.mjs` spellings of `@composio/client/pagination` - updates the contributor guidance in `ts/packages/cli/AGENTS.md` - adds `optionalParams` (`src/utils/optional-params.ts`), which turns a record of optional flags into request parameters in one call; the two `logs` list calls use it (review feedback) ## Context Adding an API call used to need one of two things nobody would guess: a new entry in a loader table, or `decode: false`, with a failure before dispatch when both were missing. Now a call needs neither, and validation is one visible word at the call sites that want it. Cost of shipping the full schema table, measured on the built binary: about +3 ms startup and +198 KB. No output change: after the rebase onto `next`, `pnpm typecheck` passes, the CLI suite passes (151 files, 1668 passed, 1 skipped; 18 exemptions), and `oxlint` is clean. Before this rebase, a live run of 23 read-only commands matched the pre-refactor baseline (22 byte-identical, 1 differing only in a request id). ## Unapplied review findings From a full code review of the rebased head (run `20261015-185607-0daee430`, seven reviewers, validator confirmed all four). Left for a decision because each goes beyond the rebase this round owns: - [ ] P2 — `ts/packages/cli/src/commands/listen.cmd.ts:709` (and `triggers/commands/triggers.listen.cmd.ts:339`) — the new AGENTS.md sentence says a `DecodeError` reaches the user with the operation, request id and upgrade hint, but the listen path wraps the validated `cli.realtime.credentials` failure in `TriggerRealtimeSubscriptionError` and prints only the network/login hint. Pre-existing path; either report `describeDecodeError(error.cause)` there or narrow the sentence. - [ ] P2 — `ts/packages/cli/src/services/composio-clients.ts:511` — two of the three validated reads (`cli.realtime.credentials`, `org.consumer.listConnectedToolkits`) have no test that a misshapen body fails with `DecodeError`; dropping `validated` from either would pass the suite. Mirror the `org.list` case in `composio-clients.test.ts:175-194`. - [ ] P2 — `ts/packages/cli/test/__utils__/services/test-layer.ts:1234` — with the pre-dispatch guard gone, a shadow ignores `decode: true`, so a `validated` added to a drift-tolerant read is decodable in production but invisible to `TestLayer` suites; the comment at :1222-1223 still claims `decode` is honoured. Make the shadow run the operation's `schemaLoaders` entry when `decode === true`, or drop the comment. - [ ] P3 — `.oxlintrc.json:261` — the `tool-input-validation.ts` override re-declares `no-restricted-imports` without the new `@composio/client/effect` `importNames` and `pagination.js/.mjs` entries, so the ban the AGENTS.md sentence calls "anywhere but `composio-clients.ts`" has one gap (no violation today). Applied during the review round: prettier on `create-tool-router-session.ts` and `tool-file-uploads.ts`, and the unused `Predicate` import in `test-layer.ts` (all three were rebase artifacts).