@devries-cameron20 / composio Mirror · read-only / commits / 75e528c0f
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, 23:30 UTC

Add CLI runtime headers to Composio client (#3222)

## Summary - Add CLI-specific default headers to Composio client requests, including `x-framework`, `x-source`, `x-runtime`, and `x-sdk-version`. - Detect runtime as `BUN`, `NODEJS`, or `UNKNOWN` when building headers. - Extend singleton tests to verify the new headers are present for user-auth requests. ## Testing - Added unit test coverage for CLI header construction in `ts/packages/cli/test/src/services/composio-client-singleton.test.ts`. - Verified `x-runtime` resolves to `NODEJS` in the test environment. - Not run: full package test suite / CI.

Rahul Tarak committed Apr 16, 2026 at 03:43 UTC 75e528c0f6fda985d2d7bf22b639d3187b63a9e9
2 files changed +23
ts/packages/cli/src/services/composio-clients.ts
+17
@@ -26,6 +26,7 @@ import {
26 } from 'src/effects/toolkit-version-overrides';
27 import { Session, RetrievedSession } from 'src/models/session';
28 import { TriggerType, TriggerTypes, TriggerTypesAsEnums } from 'src/models/trigger-types';
29 +import * as constants from 'src/constants';
30 import { ComposioUserContext, ComposioUserContextLive } from './user-context';
31 import { ProjectContext } from './project-context';
32 import type { NoSuchElementException } from 'effect/Cause';
@@ -1306,12 +1307,28 @@ export const findDeveloperProjectByName = (params: {
1307 const normalizeApiKey = (rawApiKey?: string): string | undefined =>
1308 typeof rawApiKey === 'string' && rawApiKey.trim().length > 0 ? rawApiKey : undefined;
1309
1310 +const detectCliRuntime = (): string => {
1311 + if (typeof Bun !== 'undefined') {
1312 + return 'BUN';
1313 + }
1314 +
1315 + if (typeof process !== 'undefined' && process.versions?.node) {
1316 + return 'NODEJS';
1317 + }
1318 +
1319 + return 'UNKNOWN';
1320 +};
1321 +
1322 const buildDefaultHeaders = (params: {
1323 userApiKey?: string;
1324 orgId?: string;
1325 projectId?: string;
1326 }): Record<string, string> | undefined => {
1327 const defaultHeaders = {
1328 + 'x-framework': 'cli',
1329 + 'x-source': 'CLI',
1330 + 'x-runtime': detectCliRuntime(),
1331 + 'x-sdk-version': constants.APP_VERSION,
1332 ...(params.userApiKey
1333 ? ({ 'x-user-api-key': params.userApiKey } satisfies Record<string, string>)
1334 : {}),
ts/packages/cli/test/src/services/composio-client-singleton.test.ts
+6
@@ -4,6 +4,7 @@ import { ConfigProvider, Effect, Layer, Option } from 'effect';
4 import { execSync } from 'node:child_process';
5 import * as tempy from 'tempy';
6 import { ComposioClientSingleton } from 'src/services/composio-clients';
7 +import { APP_VERSION } from 'src/constants';
8 import { defaultNodeOs, NodeOs } from 'src/services/node-os';
9 import { extendConfigProvider } from 'src/services/config';
10
@@ -72,6 +73,10 @@ describe('ComposioClientSingleton headers', () => {
73
74 expect(headers.get('x-user-api-key')).toBe('uak_from_user_env');
75 expect(headers.has('x-api-key')).toBe(false);
76 + expect(headers.get('x-framework')).toBe('cli');
77 + expect(headers.get('x-source')).toBe('CLI');
78 + expect(headers.get('x-runtime')).toBe('NODEJS');
79 + expect(headers.get('x-sdk-version')).toBe(APP_VERSION);
80 });
81
82 it('does not read COMPOSIO_API_KEY for user auth', async () => {
@@ -104,5 +109,6 @@ describe('ComposioClientSingleton headers', () => {
109
110 expect(headers.get('x-user-api-key')).toBeNull();
111 expect(headers.has('x-api-key')).toBe(false);
112 + expect(headers.get('x-source')).toBe('CLI');
113 });
114 });