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

feat(sdk): identify client products and runtime dimensions (#4689)

This PR: - distinguishes installed `@composio/core` and `@composio/slim` package identities, including their independently released versions. - sends product, transport-library, language and runtime dimensions from TypeScript, Python and CLI while preserving legacy headers. - adds the same dimensions to CLI completion events without changing their existing outcomes or durations. - routes Python metadata through the active same-origin `_headers_for` dispatch hook, including cloned clients; package versions resolve once. - includes a core/slim changeset and CLI changelog entry; no dependency pins or unrelated lockfile changes. ## Validation - Root `pnpm typecheck`: all 14 tasks passed on current `next` (16 on the original base). - Core session suite: 50 tests passed; CLI analytics, client singleton and permissions suites: 59 tests passed after resolving against current `next`. - Python transport tests: 3 passed, covering normal requests, clones and external-origin exclusion; Ruff passed. - Built and packed core/slim, then verified each extracted tarball's headers over actual HTTP. - Scoped lint and CLI boundary validation passed. Python mypy was unavailable locally; Node 24.11.0 emitted the repository's >=24.17.0 warning. ## Rollout Deploy Apollo https://github.com/ComposioHQ/platform/pull/13436 before releasing updated SDKs; the explorers are in https://github.com/ComposioHQ/metrics.composio.io/pull/241. Existing clients retain legacy attribution; historical TypeScript requests cannot be split into core/slim. No CLI command surface changes or release dispatch are included.

Alberto Schiabel committed Sep 30, 2026 at 15:37 UTC a7b49430ac3d30bae27cb947601d0659b66057c2
20 files changed +347 -39
.changeset/granular-client-provenance.md new
+6
@@ -0,0 +1,6 @@
1 +---
2 +'@composio/core': patch
3 +'@composio/slim': patch
4 +---
5 +
6 +Send product identity, product version, language, and runtime version with API requests. Identify installed core and slim packages separately while preserving existing telemetry headers.
python/composio/client/__init__.py
+56 -15
@@ -8,7 +8,7 @@ import os
8 import platform
9 import typing as t
10 import weakref
11 -from importlib.metadata import version
11 +from importlib.metadata import PackageNotFoundError, version
12 from uuid import uuid4
13
14 import typing_extensions as te
@@ -20,7 +20,8 @@ from composio_client import (
20 NotGiven,
21 )
22 from composio_client import Composio as BaseComposio
23 -from httpx import URL, Client, Request, Response, Timeout
23 +from composio_client._base_client import HeaderParam, RequestOptions
24 +from httpx import URL, Client, Response, Timeout
25
26 from composio.core.models.tool_router_constants import (
27 PROJECT_API_KEY_HEADER,
@@ -29,6 +30,18 @@ from composio.core.models.tool_router_constants import (
30 from composio.exceptions import ComposioError, InvalidParams
31 from composio.utils.logging import LogLevel, WithLogger, _VerbosityWrapper
32
33 +
34 +def _distribution_version(name: str) -> str:
35 + try:
36 + return version(name)
37 + except PackageNotFoundError:
38 + return "unknown"
39 +
40 +
41 +_SDK_VERSION = _distribution_version("composio")
42 +_CLIENT_LIBRARY_VERSION = _distribution_version("composio-client")
43 +
44 +
45 ComposioAPIError = APIError
46 APIEnvironment = te.Literal["production", "staging", "local"]
47
@@ -525,17 +538,45 @@ class HttpClient(BaseComposio, WithLogger):
538 super()._make_status_error(err_msg, body=body, response=response)
539 )
540
528 - def _prepare_request(self, request: Request) -> None:
529 - """
530 - Request interceptor to inject request id, provider, and SDK version.
531 - """
541 + def _headers_for(
542 + self,
543 + url: str,
544 + *,
545 + json_body: t.Optional[t.Dict[str, t.Any]],
546 + method_headers: t.Optional[HeaderParam],
547 + options: RequestOptions,
548 + withdrawn: bool,
549 + scheme: str,
550 + ) -> t.Dict[str, str]:
551 + """Add SDK context at the active generated client's dispatch boundary."""
552 + headers = super()._headers_for(
553 + url,
554 + json_body=json_body,
555 + method_headers=method_headers,
556 + options=options,
557 + withdrawn=withdrawn,
558 + scheme=scheme,
559 + )
560 + target, base = URL(url), URL(self.base_url)
561 + if (target.scheme, target.host, target.port) != (
562 + base.scheme,
563 + base.host,
564 + base.port,
565 + ):
566 + return headers
567 ctx = self.request_ctx.get()
533 - request.headers["x-request-id"] = ctx.get("id") or uuid4().hex
534 - request.headers["x-framework"] = ctx["provider"]
535 - request.headers["x-source"] = "PYTHON_SDK"
536 - request.headers["x-runtime"] = HttpClient._runtime_env
537 -
538 - try:
539 - request.headers["x-sdk-version"] = version("composio")
540 - except Exception:
541 - request.headers["x-sdk-version"] = "unknown"
568 + headers["x-request-id"] = (
569 + ctx.get("id") or headers.get("x-request-id") or uuid4().hex
570 + )
571 + headers["x-framework"] = ctx["provider"]
572 + headers["x-source"] = "PYTHON_SDK"
573 + headers["x-runtime"] = HttpClient._runtime_env
574 + headers["x-runtime-version"] = platform.python_version()
575 + headers["x-client-provenance"] = "composio"
576 + headers["x-client-language"] = "python"
577 + headers["x-client-runtime"] = "python"
578 + headers["x-client-library"] = "composio-client"
579 + headers["x-client-library-version"] = _CLIENT_LIBRARY_VERSION
580 + headers["x-sdk-version"] = _SDK_VERSION
581 + headers["x-client-version"] = _SDK_VERSION
582 + return headers
python/tests/test_client_provenance.py new
+58
@@ -0,0 +1,58 @@
1 +"""Product provenance must reach the HTTP transport alongside legacy headers."""
2 +
3 +import platform
4 +from importlib.metadata import version
5 +
6 +import httpx
7 +import pytest
8 +
9 +from composio.client import HttpClient
10 +
11 +
12 +@pytest.mark.parametrize("clone", [False, True])
13 +def test_product_provenance_on_request(clone):
14 + requests = []
15 +
16 + def respond(request: httpx.Request) -> httpx.Response:
17 + requests.append(request)
18 + return httpx.Response(200, json={"items": []})
19 +
20 + with HttpClient(
21 + provider="test-provider",
22 + api_key="test-key",
23 + base_url="https://backend.invalid",
24 + http_client=httpx.Client(transport=httpx.MockTransport(respond)),
25 + ) as client:
26 + request_client = client.without_retries if clone else client
27 + request_client.tools.list(limit=1)
28 +
29 + headers = requests[0].headers
30 + assert headers["x-client-provenance"] == "composio"
31 + assert headers["x-client-version"] == headers["x-sdk-version"]
32 + assert headers["x-client-language"] == "python"
33 + assert headers["x-client-library"] == "composio-client"
34 + assert headers["x-client-library-version"] == version("composio-client")
35 + assert headers["x-client-runtime"] == "python"
36 + assert headers["x-runtime-version"] == platform.python_version()
37 + assert headers["x-source"] == "PYTHON_SDK"
38 + assert headers["x-framework"] == "test-provider"
39 + assert headers["x-runtime"] == HttpClient._runtime_env
40 +
41 +
42 +def test_product_provenance_is_not_added_to_another_origin():
43 + requests = []
44 +
45 + def respond(request: httpx.Request) -> httpx.Response:
46 + requests.append(request)
47 + return httpx.Response(200, json={})
48 +
49 + with HttpClient(
50 + provider="test-provider",
51 + api_key="test-key",
52 + base_url="https://backend.invalid",
53 + http_client=httpx.Client(transport=httpx.MockTransport(respond)),
54 + ) as client:
55 + client.get("https://storage.invalid/file", cast_to=dict)
56 +
57 + assert "x-client-provenance" not in requests[0].headers
58 + assert "x-framework" not in requests[0].headers
ts/packages/cli/CHANGELOG.md
+3
@@ -4,6 +4,9 @@
4
5 ### Patch Changes
6
7 +- API requests and command analytics now report CLI product/version, language,
8 + runtime/version, and the installed API client version separately.
9 +
10 - Remove the experimental local-tools stack: the `local-tools` command group,
11 the `local_tools` experimental flag, `LOCAL_*` tool execution, `dev native-ui`,
12 and the bundled macOS sidecars (peekaboo, imessage-cli, composio-native-ui).
ts/packages/cli/src/analytics/dispatch.ts
+2
@@ -1,3 +1,4 @@
1 +import { cliRequestHeaders } from 'src/services/client-provenance';
2 import process from 'node:process';
3 import type { PlatformError } from 'effect/PlatformError';
4 import {
@@ -661,6 +662,7 @@ const captureToComposioCodactFailures = (failure: CliCodactFailure) =>
662 const invocation = yield* getCliInvocationContext;
663 const body = createCliCodactFailureBody(failure, cliSessionId, invocation);
664 const request = yield* HttpClientRequest.post(endpoint).pipe(
665 + HttpClientRequest.setHeaders(cliRequestHeaders()),
666 HttpClientRequest.setHeader('x-user-api-key', userApiKey),
667 HttpClientRequest.bodyJson(body)
668 );
ts/packages/cli/src/analytics/events.ts
+21
@@ -1,3 +1,4 @@
1 +import { cliAnalyticsProvenance } from 'src/services/client-provenance';
2 import type { CliCommandTelemetryContext, TrackEvent } from './types';
3 import { APP_VERSION } from 'src/constants';
4 import { inferSkillReleaseChannel } from 'src/effects/install-skill';
@@ -106,6 +107,7 @@ export const CLI_EVENT_JOURNEY_STAGES = {
107 CLI_TOOL_INVOCATION_FAILED: 'execute',
108 } as const satisfies Record<CliAnalyticsEventName, CliJourneyStage>;
109
110 +let cliAnalyticsVersion = APP_VERSION;
111 let cliChannel = inferSkillReleaseChannel(APP_VERSION);
112
113 /**
@@ -113,6 +115,7 @@ let cliChannel = inferSkillReleaseChannel(APP_VERSION);
115 * resolved from release-tag.txt before any command can emit telemetry.
116 */
117 export const configureCliAnalyticsReleaseVersion = (version: string): void => {
118 + cliAnalyticsVersion = version;
119 cliChannel = inferSkillReleaseChannel(version);
120 };
121
@@ -123,6 +126,24 @@ const buildEvent = (
126 name,
127 properties: {
128 ...properties,
129 + ...cliAnalyticsProvenance(
130 + typeof properties.cli_version === 'string' ? properties.cli_version : cliAnalyticsVersion
131 + ),
132 + // Command events can describe offline or mixed work. Do not pretend they
133 + // each represent one HTTP request.
134 + execution_channel:
135 + typeof properties.command_path === 'string' &&
136 + [
137 + 'execute',
138 + 'search',
139 + 'link',
140 + 'proxy',
141 + 'dev playground-execute',
142 + 'dev toolkits search',
143 + 'dev connected-accounts link',
144 + ].includes(properties.command_path)
145 + ? 'tool_router'
146 + : 'unknown',
147 journey_stage: CLI_EVENT_JOURNEY_STAGES[name],
148 cli_channel: cliChannel,
149 },
ts/packages/cli/src/services/agents.ts
+2
@@ -1,3 +1,4 @@
1 +import { cliRequestHeaders } from './client-provenance';
2 import * as FileSystem from 'effect/FileSystem';
3 import * as Path from 'effect/Path';
4 import { Data, Effect, Option, Predicate, Result, Schema } from 'effect';
@@ -228,6 +229,7 @@ const fetchAgentJson = (pathname: string, init: RequestInit = {}) =>
229 redirect: 'error',
230 ...init,
231 headers: {
232 + ...cliRequestHeaders(),
233 Accept: 'application/json',
234 ...(init.body ? { 'Content-Type': 'application/json' } : {}),
235 ...(init.headers ?? {}),
ts/packages/cli/src/services/client-provenance.ts new
+31
@@ -0,0 +1,31 @@
1 +import { VERSION as clientLibraryVersion } from '@composio/client';
2 +import { APP_VERSION } from 'src/constants';
3 +
4 +const runtime = () =>
5 + typeof Bun !== 'undefined'
6 + ? { name: 'BUN', version: Bun.version }
7 + : { name: 'NODEJS', version: process.versions.node };
8 +
9 +/** Product attribution shared by API clients and first-party raw HTTP requests. */
10 +export const cliRequestHeaders = (): Record<string, string> => ({
11 + 'x-framework': 'cli',
12 + 'x-source': 'CLI',
13 + 'x-runtime': runtime().name,
14 + 'x-client-runtime': runtime().name.toLowerCase(),
15 + 'x-runtime-version': runtime().version,
16 + 'x-sdk-version': APP_VERSION,
17 + 'x-client-provenance': '@composio/cli',
18 + 'x-client-version': APP_VERSION,
19 + 'x-client-language': 'typescript',
20 +});
21 +
22 +export const cliAnalyticsProvenance = (version = APP_VERSION) => ({
23 + client_name: '@composio/cli',
24 + client_version: version,
25 + client_language: 'typescript',
26 + client_runtime: runtime().name.toLowerCase(),
27 + client_runtime_version: runtime().version,
28 + client_library: '@composio/client',
29 + client_library_version: clientLibraryVersion,
30 + client_framework: 'cli',
31 +});
ts/packages/cli/src/services/composio-clients.ts
+5 -17
@@ -35,7 +35,8 @@ import {
35 } from 'src/effects/toolkit-version-overrides';
36 import { Session, RetrievedSession } from 'src/models/session';
37 import { TriggerType, TriggerTypes, TriggerTypesAsEnums } from 'src/models/trigger-types';
38 -import * as constants from 'src/constants';
38 +import { VERSION as clientLibraryVersion } from '@composio/client';
39 +import { cliRequestHeaders } from './client-provenance';
40 import { getCurrentCwdSessionId } from 'src/analytics/dispatch';
41 import { ComposioUserContext, ComposioUserContextLive } from './user-context';
42 import { ProjectContext } from './project-context';
@@ -492,18 +493,6 @@ export interface TriggerInstanceUpsertParams {
493 const normalizeApiKey = (rawApiKey?: string): string | undefined =>
494 typeof rawApiKey === 'string' && rawApiKey.trim().length > 0 ? rawApiKey : undefined;
495
495 -const detectCliRuntime = (): string => {
496 - if (typeof Bun !== 'undefined') {
497 - return 'BUN';
498 - }
499 -
500 - if (typeof process !== 'undefined' && process.versions?.node) {
501 - return 'NODEJS';
502 - }
503 -
504 - return 'UNKNOWN';
505 -};
506 -
496 const buildDefaultHeaders = (params: {
497 userApiKey?: string;
498 orgId?: string;
@@ -511,10 +500,9 @@ const buildDefaultHeaders = (params: {
500 cliSessionId?: string;
501 }): Record<string, string> | undefined => {
502 const defaultHeaders = {
514 - 'x-framework': 'cli',
515 - 'x-source': 'CLI',
516 - 'x-runtime': detectCliRuntime(),
517 - 'x-sdk-version': constants.APP_VERSION,
503 + ...cliRequestHeaders(),
504 + 'x-client-library': '@composio/client',
505 + 'x-client-library-version': clientLibraryVersion,
506 ...(params.userApiKey
507 ? ({ 'x-user-api-key': params.userApiKey } satisfies Record<string, string>)
508 : {}),
ts/packages/cli/src/services/run-helpers-runtime.ts
+2
@@ -1,3 +1,4 @@
1 +import { cliRequestHeaders } from './client-provenance';
2 // This module is preloaded into the user's spawned child process, where no Effect
3 // runtime or @effect/platform layers are provided, so it uses sync Node builtins.
4 // eslint-disable-next-line no-restricted-imports -- sync fs for run-log appends, run-file writes, and CLI config reads in the child process, outside the Effect runtime
@@ -920,6 +921,7 @@ const createProxyHelper = (params: {
921 const response = await fetch(`${composioBaseURL}${pathname}`, {
922 method: 'POST',
923 headers: {
924 + ...cliRequestHeaders(),
925 'content-type': 'application/json',
926 'x-user-api-key': auth.apiKey,
927 'x-org-id': auth.orgId,
ts/packages/cli/test/src/analytics.events.test.ts
+27
@@ -1,3 +1,4 @@
1 +import { VERSION as clientLibraryVersion } from '@composio/client';
2 import { readFileSync, writeFileSync } from 'node:fs';
3 import path from 'node:path';
4 import * as tempy from 'tempy';
@@ -61,6 +62,23 @@ describe('CLI analytics execute failure events', () => {
62 });
63 });
64
65 + it('keeps CLI product and installed library separate on tool-router command events', () => {
66 + const context = createCliCommandTelemetryContext(
67 + ['bun', 'composio', 'execute', 'GITHUB_GET_ME'],
68 + '0.4.2',
69 + { stdoutIsTTY: false, stderrIsTTY: false },
70 + CLI_INVOCATION
71 + );
72 + expect(getPrimaryLifecycleSucceededEvent(context)?.properties).toMatchObject({
73 + client_name: '@composio/cli',
74 + client_version: '0.4.2',
75 + client_library: '@composio/client',
76 + client_library_version: clientLibraryVersion,
77 + execution_channel: 'tool_router',
78 + duration_ms: expect.any(Number),
79 + });
80 + });
81 +
82 it('marks cached-schema validation failures as fast_fail', () => {
83 const error = new ToolInputValidationError({
84 toolSlug: 'GMAIL_SEND_EMAIL',
@@ -355,6 +373,15 @@ describe('CLI analytics setup runtime-context events', () => {
373 cli_version: APP_VERSION,
374 command_path: 'whoami',
375 agent_host: 'claude',
376 + client_name: '@composio/cli',
377 + client_version: APP_VERSION,
378 + client_language: 'typescript',
379 + client_runtime: 'nodejs',
380 + client_runtime_version: process.versions.node,
381 + client_library: '@composio/client',
382 + client_library_version: clientLibraryVersion,
383 + client_framework: 'cli',
384 + execution_channel: 'unknown',
385 journey_stage: 'setup',
386 cli_channel: inferSkillReleaseChannel(APP_VERSION),
387 },
ts/packages/cli/test/src/services/composio-client-singleton.test.ts
+4
@@ -114,6 +114,10 @@ describe('ComposioClientSingleton headers', () => {
114 expect(headers.get('x-source')).toBe('CLI');
115 expect(headers.get('x-runtime')).toBe('NODEJS');
116 expect(headers.get('x-sdk-version')).toBe(APP_VERSION);
117 + expect(headers.get('x-client-provenance')).toBe('@composio/cli');
118 + expect(headers.get('x-client-version')).toBe(APP_VERSION);
119 + expect(headers.get('x-client-language')).toBe('typescript');
120 + expect(headers.get('x-runtime-version')).toBe(process.versions.node);
121 expect(headers.get('x-cli-session-id')).toBeNull();
122 }).pipe(
123 Effect.provide(
ts/packages/core/package.json
+2 -1
@@ -42,7 +42,8 @@
42 "edge-light": "./dist/utils/ssrfGuard.workerd.mjs",
43 "node": "./dist/utils/ssrfGuard.node.mjs",
44 "default": "./dist/utils/ssrfGuard.node.mjs"
45 - }
45 + },
46 + "#client_identity": "./package.json"
47 },
48 "exports": {
49 ".": {
ts/packages/core/src/utils/session.ts
+31 -2
@@ -1,5 +1,8 @@
1 import type { BaseComposioProvider } from '../provider/BaseProvider';
2 -import { version } from '../../package.json';
2 +// Resolve against the installed package, including slim's copy of the core build.
3 +import identity from '#client_identity' with { type: 'json' };
4 +import { z } from 'zod';
5 +import { VERSION as clientLibraryVersion } from '@composio/client';
6 import type { ComposioRequestHeaders } from '../types/composio.types';
7
8 /**
@@ -90,6 +93,24 @@ function detectRuntime(): string {
93
94 // Detect once at module initialization
95 const RUNTIME_ENV = detectRuntime();
96 +const RuntimeVersionsSchema = z.object({
97 + Bun: z.object({ version: z.string() }).optional(),
98 + Deno: z.object({ version: z.object({ deno: z.string() }) }).optional(),
99 +});
100 +const runtimeVersions = RuntimeVersionsSchema.safeParse(globalThis);
101 +const detectRuntimeVersion = (): string | undefined => {
102 + switch (RUNTIME_ENV) {
103 + case 'BUN':
104 + return runtimeVersions.success ? runtimeVersions.data.Bun?.version : undefined;
105 + case 'DENO':
106 + return runtimeVersions.success ? runtimeVersions.data.Deno?.version.deno : undefined;
107 + case 'NODEJS':
108 + return process.versions.node;
109 + default:
110 + return undefined;
111 + }
112 +};
113 +const RUNTIME_VERSION = detectRuntimeVersion();
114
115 export function getSessionHeaders(
116 provider: BaseComposioProvider<unknown, unknown, unknown> | undefined
@@ -98,7 +119,15 @@ export function getSessionHeaders(
119 'x-framework': provider?.name || 'unknown',
120 'x-source': 'TYPESCRIPT_SDK',
121 'x-runtime': RUNTIME_ENV,
101 - 'x-sdk-version': version,
122 + 'x-client-runtime':
123 + RUNTIME_ENV === 'CLOUDFLARE_WORKERS' ? 'cloudflare' : RUNTIME_ENV.toLowerCase(),
124 + 'x-sdk-version': identity.version,
125 + 'x-client-provenance': identity.name,
126 + 'x-client-version': identity.version,
127 + 'x-client-language': 'typescript',
128 + 'x-client-library': '@composio/client',
129 + 'x-client-library-version': clientLibraryVersion,
130 + ...(RUNTIME_VERSION ? { 'x-runtime-version': RUNTIME_VERSION } : {}),
131 };
132 }
133
ts/packages/core/test/core/session.test.ts
+45 -1
@@ -1,3 +1,4 @@
1 +import { VERSION as clientLibraryVersion } from '@composio/client';
2 import { afterEach, beforeEach, describe, it, expect, vi } from 'vitest';
3 import * as fs from 'node:fs';
4 import * as os from 'node:os';
@@ -16,6 +17,15 @@ import {
17 import { ComposioMCPDestinationError } from '../../src/errors/ToolRouterErrors';
18 import logger from '../../src/utils/logger';
19
20 +const provenanceHeaders = {
21 + 'x-client-provenance': '@composio/core',
22 + 'x-client-version': version,
23 + 'x-client-language': 'typescript',
24 + 'x-client-library': '@composio/client',
25 + 'x-client-library-version': clientLibraryVersion,
26 + 'x-runtime-version': process.versions.node,
27 +};
28 +
29 describe('Composio Session Management', () => {
30 const baseConfig = {
31 apiKey: 'test-api-key',
@@ -46,6 +56,8 @@ describe('Composio Session Management', () => {
56 'x-framework': 'MockProvider', // from provider
57 'x-source': 'TYPESCRIPT_SDK',
58 'x-runtime': 'NODEJS',
59 + 'x-client-runtime': 'nodejs',
60 + ...provenanceHeaders,
61 'x-sdk-version': version,
62 });
63
@@ -90,6 +102,8 @@ describe('Composio Session Management', () => {
102 'x-framework': 'MockProvider',
103 'x-source': 'TYPESCRIPT_SDK',
104 'x-runtime': 'NODEJS',
105 + 'x-client-runtime': 'nodejs',
106 + ...provenanceHeaders,
107 'x-sdk-version': version,
108 });
109
@@ -99,6 +113,8 @@ describe('Composio Session Management', () => {
113 'x-framework': 'MockProvider',
114 'x-source': 'TYPESCRIPT_SDK',
115 'x-runtime': 'NODEJS',
116 + 'x-client-runtime': 'nodejs',
117 + ...provenanceHeaders,
118 'x-sdk-version': version,
119 });
120
@@ -117,6 +133,8 @@ describe('Composio Session Management', () => {
133 'x-framework': 'MockProvider', // from provider
134 'x-source': 'TYPESCRIPT_SDK',
135 'x-runtime': 'NODEJS',
136 + 'x-client-runtime': 'nodejs',
137 + ...provenanceHeaders,
138 'x-sdk-version': version,
139 });
140 });
@@ -172,6 +190,8 @@ describe('Session Headers Generation', () => {
190 'x-framework': 'openai',
191 'x-source': 'TYPESCRIPT_SDK',
192 'x-runtime': 'NODEJS',
193 + 'x-client-runtime': 'nodejs',
194 + ...provenanceHeaders,
195 'x-sdk-version': version,
196 });
197 });
@@ -184,6 +204,8 @@ describe('Session Headers Generation', () => {
204 'x-framework': 'MockProvider',
205 'x-source': 'TYPESCRIPT_SDK',
206 'x-runtime': 'NODEJS',
207 + 'x-client-runtime': 'nodejs',
208 + ...provenanceHeaders,
209 'x-sdk-version': version,
210 });
211 });
@@ -195,6 +217,8 @@ describe('Session Headers Generation', () => {
217 'x-framework': 'unknown',
218 'x-source': 'TYPESCRIPT_SDK',
219 'x-runtime': 'NODEJS',
220 + 'x-client-runtime': 'nodejs',
221 + ...provenanceHeaders,
222 'x-sdk-version': version,
223 });
224 });
@@ -209,6 +233,8 @@ describe('Session Headers Generation', () => {
233 'x-framework': 'unknown',
234 'x-source': 'TYPESCRIPT_SDK',
235 'x-runtime': 'NODEJS',
236 + 'x-client-runtime': 'nodejs',
237 + ...provenanceHeaders,
238 'x-sdk-version': version,
239 });
240 });
@@ -230,6 +256,8 @@ describe('Session Headers Generation', () => {
256 'x-framework': 'openai',
257 'x-source': 'TYPESCRIPT_SDK',
258 'x-runtime': 'NODEJS',
259 + 'x-client-runtime': 'nodejs',
260 + ...provenanceHeaders,
261 'x-sdk-version': version,
262 });
263 });
@@ -249,6 +277,8 @@ describe('Session Headers Generation', () => {
277 'x-framework': 'MockProvider',
278 'x-source': 'TYPESCRIPT_SDK',
279 'x-runtime': 'NODEJS',
280 + 'x-client-runtime': 'nodejs',
281 + ...provenanceHeaders,
282 'x-sdk-version': version,
283 });
284 });
@@ -267,7 +297,9 @@ describe('Session Headers Generation', () => {
297 expect(headers).toEqual({
298 'x-framework': 'openai', // session header takes precedence
299 'x-source': 'TYPESCRIPT_SDK', // session header takes precedence
270 - 'x-runtime': 'NODEJS', // session header takes precedence
300 + 'x-runtime': 'NODEJS',
301 + 'x-client-runtime': 'nodejs', // session header takes precedence
302 + ...provenanceHeaders,
303 'x-sdk-version': version, // session header takes precedence
304 'x-custom-header': 'custom-value', // custom header preserved
305 });
@@ -281,6 +313,8 @@ describe('Session Headers Generation', () => {
313 'x-framework': 'openai',
314 'x-source': 'TYPESCRIPT_SDK',
315 'x-runtime': 'NODEJS',
316 + 'x-client-runtime': 'nodejs',
317 + ...provenanceHeaders,
318 'x-sdk-version': version,
319 });
320 });
@@ -293,6 +327,8 @@ describe('Session Headers Generation', () => {
327 'x-framework': 'openai',
328 'x-source': 'TYPESCRIPT_SDK',
329 'x-runtime': 'NODEJS',
330 + 'x-client-runtime': 'nodejs',
331 + ...provenanceHeaders,
332 'x-sdk-version': version,
333 });
334 });
@@ -309,6 +345,8 @@ describe('Session Headers Generation', () => {
345 'x-framework': 'unknown',
346 'x-source': 'TYPESCRIPT_SDK',
347 'x-runtime': 'NODEJS',
348 + 'x-client-runtime': 'nodejs',
349 + ...provenanceHeaders,
350 'x-sdk-version': version,
351 });
352 });
@@ -380,6 +418,8 @@ describe('Session Headers Configuration Integration', () => {
418 'x-framework': 'openai',
419 'x-source': 'TYPESCRIPT_SDK',
420 'x-runtime': 'NODEJS',
421 + 'x-client-runtime': 'nodejs',
422 + ...provenanceHeaders,
423 'x-sdk-version': version,
424 });
425 });
@@ -444,6 +484,8 @@ describe('Session Headers Configuration Integration', () => {
484 'x-framework': 'openai',
485 'x-source': 'TYPESCRIPT_SDK',
486 'x-runtime': 'NODEJS',
487 + 'x-client-runtime': 'nodejs',
488 + ...provenanceHeaders,
489 'x-sdk-version': version,
490 });
491 });
@@ -479,6 +521,8 @@ describe('Session Headers Configuration Integration', () => {
521 'x-framework': 'openai', // provider-specific header
522 'x-source': 'TYPESCRIPT_SDK',
523 'x-runtime': 'NODEJS',
524 + 'x-client-runtime': 'nodejs',
525 + ...provenanceHeaders,
526 'x-sdk-version': version,
527 });
528 });
ts/packages/core/tsconfig.json
+2 -1
@@ -23,7 +23,8 @@
23 "./src/utils/config-defaults/ConfigDefaults.node.ts",
24 "./src/utils/config-defaults/ConfigDefaults.workerd.ts"
25 ],
26 - "#ssrf_guard": ["./src/utils/ssrfGuard.node.ts", "./src/utils/ssrfGuard.workerd.ts"]
26 + "#ssrf_guard": ["./src/utils/ssrfGuard.node.ts", "./src/utils/ssrfGuard.workerd.ts"],
27 + "#client_identity": ["./package.json"]
28 }
29 },
30 "include": ["src/**/*.ts"]
ts/packages/core/tsdown.config.ts
+1
@@ -48,6 +48,7 @@ export default defineConfig({
48 */
49 neverBundle: [
50 ...baseNeverBundle,
51 + '#client_identity',
52 '#platform',
53 '#files',
54 '#file_tool_modifier',
ts/packages/core/vitest.config.ts
+1
@@ -7,6 +7,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7 export default defineConfig({
8 resolve: {
9 alias: {
10 + '#client_identity': path.resolve(__dirname, 'package.json'),
11 '#platform': path.resolve(__dirname, 'src/platform/node.ts'),
12 '#files': path.resolve(__dirname, 'src/models/Files.node.ts'),
13 '#file_tool_modifier': path.resolve(
ts/packages/slim/package.json
+3 -2
@@ -42,7 +42,8 @@
42 "edge-light": "./dist/utils/ssrfGuard.workerd.mjs",
43 "node": "./dist/utils/ssrfGuard.node.mjs",
44 "default": "./dist/utils/ssrfGuard.node.mjs"
45 - }
45 + },
46 + "#client_identity": "./package.json"
47 },
48 "exports": {
49 ".": {
@@ -88,7 +89,7 @@
89 "scripts": {
90 "clean": "git clean -xdf dist generated node_modules",
91 "build": "rm -rf dist generated && cp -R ../core/dist ./dist && rm -rf dist/docs && if [ -d ../core/generated ]; then cp -R ../core/generated ./generated; fi",
91 - "test": "node -e \"import('./dist/index.mjs').then(() => console.log('@composio/slim import ok'))\""
92 + "test": "node test/provenance.mjs"
93 },
94 "keywords": [
95 "composio",
ts/packages/slim/test/provenance.mjs new
+45
@@ -0,0 +1,45 @@
1 +import assert from 'node:assert/strict';
2 +import { once } from 'node:events';
3 +import { readFile } from 'node:fs/promises';
4 +import { createServer } from 'node:http';
5 +import { resolve } from 'node:path';
6 +import { pathToFileURL } from 'node:url';
7 +
8 +// Optional package roots let this same contract run against extracted tarballs.
9 +const roots = process.argv.slice(2);
10 +const packages = roots.length ? roots : ['../core', '.'];
11 +for (const root of packages) {
12 + const manifest = JSON.parse(await readFile(resolve(root, 'package.json'), 'utf8'));
13 + const { Composio } = await import(pathToFileURL(resolve(root, 'dist/index.mjs')).href);
14 + const requests = [];
15 + const server = createServer((request, response) => {
16 + requests.push(request.headers);
17 + response.writeHead(200, { 'content-type': 'application/json' });
18 + response.end(JSON.stringify({ items: [], next_cursor: null }));
19 + });
20 + server.listen(0, '127.0.0.1');
21 + await once(server, 'listening');
22 + try {
23 + const sdk = new Composio({
24 + apiKey: 'test-key',
25 + baseURL: `http://127.0.0.1:${server.address().port}`,
26 + allowTracking: false,
27 + allowTracing: false,
28 + });
29 + await sdk.toolkits.get({ limit: 1 });
30 + assert.equal(requests.length, 1);
31 + const headers = requests[0];
32 + assert.equal(headers['x-client-provenance'], manifest.name);
33 + assert.equal(headers['x-client-version'], manifest.version);
34 + assert.equal(headers['x-sdk-version'], manifest.version);
35 + assert.equal(headers['x-client-language'], 'typescript');
36 + assert.equal(headers['x-client-runtime'], 'nodejs');
37 + assert.equal(headers['x-runtime-version'], process.versions.node);
38 + assert.equal(headers['x-client-library'], '@composio/client');
39 + assert.ok(headers['x-client-library-version']);
40 + console.log(`${manifest.name}: HTTP product, version, runtime and library headers verified`);
41 + } finally {
42 + server.close();
43 + await once(server, 'close');
44 + }
45 +}