@devries-cameron20 / composio Mirror · read-only / commits / 5f8c4ecee
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.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 09:45 UTC

fix(cli): report the instant charge on execute (#4857)

## Summary - `composio execute` and `composio run`'s `execute()` now return an `instantCharge` object (`amount`, `currency`, `chargedBy`) and print `instant charge: <amount> USD` in the success line when a call ran on a Composio instant account instead of a linked connection. A billed call used to look free. - Cause 1: `createToolRouterSessionContext` created Tool Router sessions without `instant.return_instant_charge`, and Apollo only returns `instant_charge` when the session asks for it (visibility only; billing and eligibility are unchanged). - Cause 2: `normalizeResponse` in `tools-executor.ts` copied only `successful`, `data`, `error` and `log_id` from the session execute and executeMeta responses and dropped `instant_charge`. - The stored-file summary and `--parallel` results carry `instantCharge` the same way, including a failed `--parallel` result: a multi-execute batch is reported as failed when any child fails but still carries the aggregate charge of the successful children. The proxy test's expected session payload gains the new `instant` field. ## Validation - `pnpm run typecheck` (CLI package): pass. - `vitest run` (full CLI suite): 134 files, 1404 tests pass after updating the proxy session payload expectation. - `pnpm run validate:boundaries`, oxlint and prettier on changed files, `git diff --check`: pass. - Manual trace on org `kj_workspace` with no exa connection linked, from source: ``` composio execute EXA_SEARCH -d '{"query":"composio"}' ◇ Execution successful (instant charge: 0.007000 USD, logId: log_b8zxaFGiu6-D) ... "instantCharge": { "amount": "0.007000", "currency": "USD", "chargedBy": "composio" } ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: Alberto Schiabel <jkomyno@users.noreply.github.com> Co-authored-by: jkomyno <alberto@composio.dev>

Kshitij Jhunjhunwala committed Oct 15, 2026 at 05:32 UTC 5f8c4ecee03ec0a9dbed42031863617dcd90f7a1
7 files changed +197 -18
ts/packages/cli/CHANGELOG.md
+8
@@ -4,6 +4,14 @@
4
5 ### Patch Changes
6
7 +- `composio execute` and the `execute()` helper in `composio run` scripts now
8 + report the Instant charge when a call ran on a Composio instant account
9 + instead of a linked connection: the result carries an `instantCharge` object
10 + (`amount`, `currency`, `chargedBy`) and the success line shows
11 + `instant charge: <amount> USD`. The CLI used to create Tool Router sessions
12 + without asking for the charge and dropped it from the response, so a billed
13 + call looked free.
14 +
15 - `composio execute` (including meta tools), `composio proxy`, the `proxy()`
16 helper in `composio run` scripts, and the custom tool schema lookup in
17 `composio search` now fail with a clear error when the call needs user input,
ts/packages/cli/src/commands/tools/commands/tools.execute.cmd.ts
+18 -3
@@ -16,7 +16,11 @@ import {
16 import { TerminalUI } from 'src/services/terminal-ui';
17 import { logToolDebug, makePerfDebugLogger } from 'src/services/runtime-debug-logger';
18 import { ToolsExecutor, detectInBandWarning } from 'src/services/tools-executor';
19 -import type { ToolExecuteParams, ToolExecuteResponse } from 'src/services/tools-executor';
19 +import type {
20 + InstantCharge,
21 + ToolExecuteParams,
22 + ToolExecuteResponse,
23 +} from 'src/services/tools-executor';
24 import type { ToolkitProjectScope } from 'src/services/composio-clients';
25 import { ComposioUserContext } from 'src/services/user-context';
26 import { ProjectContext } from 'src/services/project-context';
@@ -342,6 +346,7 @@ type StoredExecuteOutputSummary = {
346 readonly successful: true;
347 readonly error: null;
348 readonly logId: string;
349 + readonly instantCharge?: InstantCharge;
350 readonly storedInFile: true;
351 readonly tokenCount: number;
352 readonly sizeBytes: number;
@@ -370,12 +375,19 @@ const permissionApprovalLabel = (approval?: string): string | undefined => {
375 }
376 };
377
378 +const instantChargeLabel = (charge?: InstantCharge): string | undefined => {
379 + if (!charge) return undefined;
380 + return `instant charge: ${charge.amount} ${charge.currency}`;
381 +};
382 +
383 const executionSuccessSuffix = (result: {
384 readonly logId?: string;
385 readonly permissionApproval?: string;
386 + readonly instantCharge?: InstantCharge;
387 }) => {
388 const metadata = [
389 permissionApprovalLabel(result.permissionApproval),
390 + instantChargeLabel(result.instantCharge),
391 result.logId ? `logId: ${redact({ value: result.logId, prefix: 'log_' })}` : undefined,
392 ].filter((value): value is string => Boolean(value));
393 return metadata.length > 0 ? ` (${metadata.join(', ')})` : '';
@@ -433,6 +445,7 @@ const prepareExecuteOutput = (
445 summary: {
446 ...(yield* persistLargeExecuteOutput(toolSlug, json, sizeBytes, sharedDirectory)),
447 logId: result.logId,
448 + ...(result.instantCharge ? { instantCharge: result.instantCharge } : {}),
449 } satisfies StoredExecuteOutputSummary,
450 } satisfies PreparedExecuteOutput;
451 });
@@ -1788,12 +1801,14 @@ const runParallelToolsExecuteFromParsed = (params: ParsedParallelExecuteArgs) =>
1801
1802 const result = yield* context.executor.execute(toolSlug, context.executeParams);
1803 if (!result.successful) {
1791 - return {
1804 + const failed = {
1805 slug: toolSlug,
1793 - successful: false,
1806 + successful: false as const,
1807 error: result.error ?? 'Execution failed.',
1808 logId: result.logId,
1809 };
1810 + if (!result.instantCharge) return failed;
1811 + return { ...failed, instantCharge: result.instantCharge };
1812 }
1813
1814 const output = yield* prepareExecuteOutput(toolSlug, result, context.executeOutputDir);
ts/packages/cli/src/effects/create-tool-router-session.ts
+1
@@ -181,6 +181,7 @@ export const createToolRouterSessionContext = (
181 }
182 : undefined,
183 toolkits: requestedToolkits.length > 0 ? { enable: [...requestedToolkits] } : undefined,
184 + instant: { return_instant_charge: true },
185 experimental: permissionSnapshot?.enhancedControlsEnabled
186 ? { link_url_overwrite: ENHANCED_LINK_URL_OVERWRITE }
187 : undefined,
ts/packages/cli/src/services/tools-executor.ts
+38 -14
@@ -71,6 +71,14 @@ export interface ToolExecuteResponse {
71 readonly error: string | null;
72 readonly logId: string;
73 readonly permissionApproval?: NonNullable<PermissionGateResult>['approvalStatus'];
74 + readonly instantCharge?: InstantCharge;
75 +}
76 +
77 +/** Charge billed to the org when the call ran on a Composio instant account. */
78 +export interface InstantCharge {
79 + readonly amount: string;
80 + readonly currency: 'USD';
81 + readonly chargedBy: 'composio';
82 }
83
84 export interface ToolsExecutor {
@@ -107,24 +115,40 @@ export const isExecutionSuccessful = (raw: {
115 readonly result_type: 'completed' | 'failed';
116 }): boolean => raw.result_type === 'completed';
117
118 +type ExecutedSessionResponse = Exclude<
119 + SessionExecuteResponse | SessionExecuteMetaResponse,
120 + { result_type: 'input_required' }
121 +>;
122 +
123 +const toInstantCharge = (raw: ExecutedSessionResponse): InstantCharge | undefined => {
124 + if (!raw.instant_charge) return undefined;
125 + return {
126 + amount: raw.instant_charge.amount,
127 + currency: raw.instant_charge.currency,
128 + chargedBy: raw.instant_charge.charged_by,
129 + };
130 +};
131 +
132 /**
133 * Normalize the raw Tool Router response into the shape the CLI commands expect.
134 */
113 -const normalizeResponse = (
114 - raw: Exclude<
115 - SessionExecuteResponse | SessionExecuteMetaResponse,
116 - { result_type: 'input_required' }
117 - >,
135 +export const normalizeResponse = (
136 + raw: ExecutedSessionResponse,
137 permissionGateResult?: PermissionGateResult
119 -): ToolExecuteResponse => ({
120 - successful: isExecutionSuccessful(raw),
121 - data: raw.data,
122 - error: raw.error,
123 - logId: raw.log_id,
124 - ...(permissionGateResult?.approvalStatus
125 - ? { permissionApproval: permissionGateResult.approvalStatus }
126 - : {}),
127 -});
138 +): ToolExecuteResponse => {
139 + const response: ToolExecuteResponse = {
140 + successful: isExecutionSuccessful(raw),
141 + data: raw.data,
142 + error: raw.error,
143 + logId: raw.log_id,
144 + ...(permissionGateResult?.approvalStatus
145 + ? { permissionApproval: permissionGateResult.approvalStatus }
146 + : {}),
147 + };
148 + const instantCharge = toInstantCharge(raw);
149 + if (!instantCharge) return response;
150 + return { ...response, instantCharge };
151 +};
152
153 /**
154 * Detect in-band error hints in tool response data.
ts/packages/cli/test/src/commands/proxy.cmd.test.ts
+1
@@ -171,6 +171,7 @@ describe('CLI: composio proxy', () => {
171 connected_accounts: { gmail: 'con_gmail_work' },
172 manage_connections: { enable: false },
173 toolkits: { enable: ['gmail'] },
174 + instant: { return_instant_charge: true },
175 });
176 expect(proxyParams).toEqual({
177 sessionId: 'trs_proxy_test',
ts/packages/cli/test/src/commands/tools/tools.execute.cmd.test.ts
+96
@@ -214,6 +214,46 @@ describe('CLI: composio execute', () => {
214 );
215 });
216
217 + layer(
218 + TestLive({
219 + baseConfigProvider: testConfigProvider,
220 + fixture: 'global-test-user-id',
221 + stdin: { isTTY: true, data: '' },
222 + toolRouter: {
223 + execute: (_sessionId, params) =>
224 + Effect.succeed({
225 + result_type: 'completed' as const,
226 + data: { tool_slug: params.tool_slug },
227 + error: null,
228 + log_id: 'log_instant_charge',
229 + instant_charge: {
230 + amount: '0.005',
231 + currency: 'USD' as const,
232 + charged_by: 'composio' as const,
233 + },
234 + }),
235 + },
236 + })
237 + )('[Given] an instant charge [Then] execute reports it in the success line and output', it => {
238 + it.effect('prints the charge before the log id', () =>
239 + Effect.gen(function* () {
240 + yield* cli(['execute', 'EXA_SEARCH', '--skip-connection-check', '-d', '{"query":"a"}']);
241 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
242 + const text = lines.join('\n');
243 + const output = parseLastJson(lines);
244 +
245 + expect(text).toContain(
246 + 'Execution successful (instant charge: 0.005 USD, logId: log_instant_charge)'
247 + );
248 + expect(output).toHaveProperty('instantCharge', {
249 + amount: '0.005',
250 + currency: 'USD',
251 + chargedBy: 'composio',
252 + });
253 + })
254 + );
255 + });
256 +
257 layer(
258 TestLive({
259 baseConfigProvider: testConfigProvider,
@@ -240,6 +280,7 @@ describe('CLI: composio execute', () => {
280 expect(output.data.tool_slug).toBe('GMAIL_SEND_EMAIL');
281 expect(output.data.arguments).toEqual({ recipient: 'a' });
282 expect(output.logId).toBe('log_test');
283 + expect(output).not.toHaveProperty('instantCharge');
284 })
285 );
286 });
@@ -951,6 +992,9 @@ describe('CLI: composio execute', () => {
992 expect(recordedSessionCreateParams[0]?.connected_accounts).toEqual({
993 posthog: 'con_posthog_active',
994 });
995 + expect(recordedSessionCreateParams[0]?.instant).toEqual({
996 + return_instant_charge: true,
997 + });
998 })
999 );
1000 }
@@ -1764,6 +1808,58 @@ describe('CLI: composio execute', () => {
1808 );
1809 });
1810
1811 + layer(
1812 + TestLive({
1813 + baseConfigProvider: testConfigProvider,
1814 + fixture: 'global-test-user-id',
1815 + stdin: { isTTY: true, data: '' },
1816 + toolRouter: {
1817 + executeMeta: () =>
1818 + Effect.succeed({
1819 + result_type: 'failed' as const,
1820 + data: { results: [], total_count: 2, success_count: 1, error_count: 1 },
1821 + error: '1 out of 2 tools failed',
1822 + log_id: 'log_parallel_batch',
1823 + instant_charge: {
1824 + amount: '0.025000',
1825 + currency: 'USD' as const,
1826 + charged_by: 'composio' as const,
1827 + },
1828 + }),
1829 + },
1830 + })
1831 + )('[Given] a parallel multi-execute batch fails with a charge [Then] the charge is kept', it => {
1832 + it.effect('reports instantCharge on the failed parallel result', () =>
1833 + Effect.gen(function* () {
1834 + const error = yield* cli([
1835 + 'execute',
1836 + '--parallel',
1837 + '--skip-checks',
1838 + 'COMPOSIO_MULTI_EXECUTE_TOOL',
1839 + '-d',
1840 + '{"tools":[]}',
1841 + ]).pipe(Effect.flip);
1842 +
1843 + const lines = yield* MockConsole.getLines({ stripAnsi: true });
1844 + const output = parseLastJson(lines);
1845 + expect(Predicate.isTagged(error, 'ReportedToolExecutionError')).toBe(true);
1846 + expect(error).toMatchObject({ reason: 'parallel_failed' });
1847 + expect(output).toMatchObject({
1848 + successful: false,
1849 + results: [
1850 + {
1851 + slug: 'COMPOSIO_MULTI_EXECUTE_TOOL',
1852 + successful: false,
1853 + error: '1 out of 2 tools failed',
1854 + logId: 'log_parallel_batch',
1855 + instantCharge: { amount: '0.025000', currency: 'USD', chargedBy: 'composio' },
1856 + },
1857 + ],
1858 + });
1859 + })
1860 + );
1861 + });
1862 +
1863 layer(
1864 TestLive({
1865 baseConfigProvider: testConfigProvider,
ts/packages/cli/test/src/services/tools-executor.test.ts
+35 -1
@@ -1,5 +1,5 @@
1 import { describe, expect, it } from 'vitest';
2 -import { isExecutionSuccessful } from 'src/services/tools-executor';
2 +import { isExecutionSuccessful, normalizeResponse } from 'src/services/tools-executor';
3
4 describe('isExecutionSuccessful', () => {
5 it.each([
@@ -23,3 +23,37 @@ describe('isExecutionSuccessful', () => {
23 expect(isExecutionSuccessful(raw)).toBe(expected);
24 });
25 });
26 +
27 +describe('normalizeResponse', () => {
28 + const completed = {
29 + result_type: 'completed' as const,
30 + data: { ok: true },
31 + error: null,
32 + log_id: 'log_test',
33 + };
34 +
35 + it('[Given] a response with instant_charge [Then] it yields instantCharge', () => {
36 + const response = normalizeResponse({
37 + ...completed,
38 + instant_charge: { amount: '0.005', currency: 'USD', charged_by: 'composio' },
39 + });
40 +
41 + expect(response.instantCharge).toEqual({
42 + amount: '0.005',
43 + currency: 'USD',
44 + chargedBy: 'composio',
45 + });
46 + });
47 +
48 + it('[Given] a response without instant_charge [Then] it has no instantCharge key', () => {
49 + const response = normalizeResponse(completed);
50 +
51 + expect(response).not.toHaveProperty('instantCharge');
52 + expect(response).toEqual({
53 + successful: true,
54 + data: { ok: true },
55 + error: null,
56 + logId: 'log_test',
57 + });
58 + });
59 +});