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

fix(sdk): resolve toolkit versions case-insensitively in both SDKs (#3762)

## Summary Toolkit version maps are keyed by **normalized (lowercase) slugs** on the *write* side — env vars (`COMPOSIO_TOOLKIT_VERSION_*`) and user-supplied dicts both get their keys lowercased when the map is built. But the *lookup* read the map with the **raw slug**. A pin configured under a different casing (e.g. `{ "GitHub": "20250101_00" }` or `COMPOSIO_TOOLKIT_VERSION_GITHUB` looked up as `GitHub`) therefore missed the map and silently fell back to `"latest"`, which `Tools.execute` then rejects with a version-required error — discarding the user's explicit pin. Rather than patch only the read side, this **centralizes the normalization rule** into a single helper per SDK and routes **both** the map-building (write) and lookup (read) paths through it, so the two sides can never drift apart again: - **Python** — `normalize_toolkit_slug()` in `python/composio/utils/toolkit_version.py` - **TypeScript** — `normalizeToolkitSlug()` in `ts/packages/core/src/utils/toolkitVersion.ts`, imported by `getToolkitVersionsFromEnv` in `sdk.ts` Behavior is now identical across the two SDKs. This **supersedes #3759**, which patched only the Python read side and left TS diverging. ## Backend verification Confirmed against the backend (staging, **1403 toolkits across 15 pages**): every toolkit `slug` is already lowercase (the mixed-case `name` field is display-only). So the *primary* execute path — which resolves via `tool.toolkit.slug` — was never broken in practice. This change: - **hardens** the direct-util and mixed-case-config paths (a user passing `{ "GitHub": "…" }` now resolves as expected), and - **removes a latent cross-SDK divergence**: the TS suite previously asserted `getToolkitVersion` was *case-sensitive* (`versions.test.ts`), locking in the bug for an input the production code path can't actually produce. That test is flipped to assert case-insensitive resolution. ## Tests - **Python** (`python/tests/test_toolkit_version.py`): case-insensitive lookup via `get_toolkit_versions` round-trip, and against a raw pre-normalized map. `18 passed`. - **TypeScript** (`ts/packages/core/test/core/versions.test.ts`): replaced the case-sensitivity assertion with case-insensitive resolution + a write→read round-trip of a mixed-case user pin. Full core suite `997 passed`. - Typecheck (`tsc --noEmit`) clean; `ruff` clean. ## Notes - Changeset added: `@composio/core` patch. - No public API change; the fix is behavioral (case-insensitive) plus an internal shared helper.

Alberto Schiabel committed Jul 6, 2026 at 15:30 UTC 820abb907243565e2c31cb941c4df60ebaa1c3bb
6 files changed +77 -16
.changeset/toolkit-version-case-insensitive.md new
+5
@@ -0,0 +1,5 @@
1 +---
2 +'@composio/core': patch
3 +---
4 +
5 +Resolve toolkit version pins case-insensitively. Version maps are keyed by normalized (lowercase) slugs, but `getToolkitVersion` previously looked them up with the raw slug, so a pin configured under a different casing (e.g. `{ GitHub: '20250101_00' }` or `COMPOSIO_TOOLKIT_VERSION_GITHUB`) could silently fall back to `'latest'`. Normalization is now centralized in a single `normalizeToolkitSlug` helper used symmetrically on both the write (map-building) and read (lookup) paths, so the two sides can no longer drift. This mirrors the equivalent fix in the Python SDK.
python/composio/utils/toolkit_version.py
+27 -6
@@ -8,6 +8,24 @@ import typing as t
8 from composio.core.types import ToolkitVersion, ToolkitVersionParam, ToolkitVersions
9
10
11 +def normalize_toolkit_slug(toolkit_slug: str) -> str:
12 + """
13 + Canonicalizes a toolkit slug into the form used as a version-map key.
14 +
15 + Toolkit slugs are matched case-insensitively. This is the single source of
16 + truth for that rule: every write into a version map (env vars, user-supplied
17 + dicts) and every read out of one MUST go through this helper so the two sides
18 + can never drift apart and silently miss a configured pin.
19 +
20 + Kept intentionally equivalent to the TypeScript SDK's ``normalizeToolkitSlug``
21 + (see ts/packages/core/src/utils/toolkitVersion.ts).
22 +
23 + :param toolkit_slug: The slug/name of the toolkit, in any casing
24 + :return: The normalized (lowercase) slug used as a version-map key
25 + """
26 + return toolkit_slug.lower()
27 +
28 +
29 def get_toolkit_version(
30 toolkit_slug: str, toolkit_versions: t.Optional[ToolkitVersionParam] = None
31 ) -> ToolkitVersion:
@@ -23,9 +41,11 @@ def get_toolkit_version(
41 if isinstance(toolkit_versions, str):
42 return toolkit_versions
43
26 - # If toolkit_versions is a dict mapping, look up the specific toolkit version
44 + # If toolkit_versions is a dict mapping, look up the specific toolkit version.
45 + # The map is keyed by normalized slugs, so normalize the lookup too
46 + # (see normalize_toolkit_slug for why).
47 if isinstance(toolkit_versions, dict) and len(toolkit_versions) > 0:
28 - return toolkit_versions.get(toolkit_slug, "latest")
48 + return toolkit_versions.get(normalize_toolkit_slug(toolkit_slug), "latest")
49
50 # Else use 'latest'
51 return "latest"
@@ -55,14 +75,15 @@ def get_toolkit_versions(
75 for key, value in os.environ.items():
76 if key.startswith("COMPOSIO_TOOLKIT_VERSION_"):
77 toolkit_name = key.replace("COMPOSIO_TOOLKIT_VERSION_", "")
58 - toolkit_versions_from_env[toolkit_name.lower()] = value
78 + toolkit_versions_from_env[normalize_toolkit_slug(toolkit_name)] = value
79
60 - # If the provided default versions is a dict, normalize the keys to be lower case
61 - # Use user provided values as overrides
80 + # Normalize keys via normalize_toolkit_slug (the same helper the lookup uses);
81 + # user-provided values override env.
82 user_provided_toolkit_versions: ToolkitVersions = {}
83 if default_versions and isinstance(default_versions, dict):
84 user_provided_toolkit_versions = {
65 - key.lower(): value for key, value in default_versions.items()
85 + normalize_toolkit_slug(key): value
86 + for key, value in default_versions.items()
87 }
88
89 # Final toolkit versions
python/tests/test_toolkit_version.py
+13
@@ -124,6 +124,19 @@ class TestToolkitVersion:
124 expected = {"github": "v1.0.0", "slack": "v2.0.0", "openai": "v3.0.0"}
125 assert result == expected
126
127 + def test_get_toolkit_version_lookup_is_case_insensitive(self):
128 + """The lookup slug is matched case-insensitively.
129 +
130 + Version maps are keyed by normalized (lowercase) slugs (write side
131 + covered by test_user_dict_case_normalization), so the read side must
132 + resolve any-cased slugs instead of silently returning 'latest'.
133 + """
134 + versions = {"github": "v1.0.0"}
135 +
136 + assert get_toolkit_version("GITHUB", versions) == "v1.0.0"
137 + assert get_toolkit_version("GitHub", versions) == "v1.0.0"
138 + assert get_toolkit_version("github", versions) == "v1.0.0"
139 +
140 def test_priority_order_matches_typescript(self):
141 """Test that priority order matches TypeScript implementation.
142
ts/packages/core/src/utils/sdk.ts
+5 -4
@@ -4,6 +4,7 @@ import { getEnvsWithPrefix, getEnvVariable } from './env';
4 import logger from './logger';
5 import { ComposioError } from '../errors/ComposioError';
6 import { ToolkitVersion, ToolkitVersionParam, ToolkitVersions } from '../types/tool.types';
7 +import { normalizeToolkitSlug } from './toolkitVersion';
8 import { platform } from '#platform';
9
10 // File path helpers
@@ -82,16 +83,16 @@ export function getToolkitVersionsFromEnv(
83 const envPrefixedVersions = getEnvsWithPrefix(`COMPOSIO_TOOLKIT_VERSION_`);
84 const toolkitVersionsFromEnv = Object.entries(envPrefixedVersions).reduce((acc, [key, value]) => {
85 const toolkitName = key.replace('COMPOSIO_TOOLKIT_VERSION_', '');
85 - acc[toolkitName.toLowerCase()] = value as ToolkitVersion;
86 + acc[normalizeToolkitSlug(toolkitName)] = value as ToolkitVersion;
87 return acc;
88 }, {} as ToolkitVersions);
89
89 - // if the provided default versions is an object, normalize the keys to be lower case
90 - // use user provided values as overrides
90 + // normalize keys via normalizeToolkitSlug (the same helper the lookup uses);
91 + // user provided values act as overrides
92 let userProvidedToolkitVersions = {};
93 if (defaultVersions && typeof defaultVersions === 'object') {
94 userProvidedToolkitVersions = Object.fromEntries(
94 - Object.entries(defaultVersions).map(([key, value]) => [key.toLowerCase(), value])
95 + Object.entries(defaultVersions).map(([key, value]) => [normalizeToolkitSlug(key), value])
96 );
97 }
98
ts/packages/core/src/utils/toolkitVersion.ts
+21 -2
@@ -1,5 +1,22 @@
1 import { ToolkitVersion, ToolkitVersionParam } from '../types/tool.types';
2
3 +/**
4 + * Canonicalizes a toolkit slug into the form used as a version-map key.
5 + *
6 + * Toolkit slugs are matched case-insensitively. This is the single source of
7 + * truth for that rule: every write into a version map (env vars, user-supplied
8 + * objects — see `getToolkitVersionsFromEnv`) and every read out of one MUST go
9 + * through this helper so the two sides can never drift apart and silently miss a
10 + * configured pin.
11 + *
12 + * Kept intentionally equivalent to the Python SDK's `normalize_toolkit_slug`
13 + * (see python/composio/utils/toolkit_version.py).
14 + *
15 + * @param toolkitSlug - The slug/name of the toolkit, in any casing
16 + * @returns The normalized (lowercase) slug used as a version-map key
17 + */
18 +export const normalizeToolkitSlug = (toolkitSlug: string): string => toolkitSlug.toLowerCase();
19 +
20 /**
21 * Gets the version for a specific toolkit based on the provided toolkit versions configuration.
22 *
@@ -15,10 +32,12 @@ export const getToolkitVersion = (
32 if (typeof toolkitVersions === 'string') {
33 return toolkitVersions;
34 }
18 - // If toolkitVersions is an object mapping, look up the specific toolkit version
35 + // If toolkitVersions is an object mapping, look up the specific toolkit version.
36 + // The map is keyed by normalized slugs, so normalize the lookup too
37 + // (see normalizeToolkitSlug for why).
38 const hasToolkitVersion = toolkitVersions && Object.keys(toolkitVersions).length > 0;
39 if (hasToolkitVersion) {
21 - return toolkitVersions[toolkitSlug] ?? 'latest';
40 + return toolkitVersions[normalizeToolkitSlug(toolkitSlug)] ?? 'latest';
41 }
42
43 // Else use 'latest'
ts/packages/core/test/core/versions.test.ts
+6 -4
@@ -283,15 +283,17 @@ describe('Version Management', () => {
283 expect(result).toBe('latest');
284 });
285
286 - it('should be case-sensitive for toolkit slugs', () => {
286 + it('should resolve the lookup slug case-insensitively', () => {
287 + // Version maps are keyed by normalized (lowercase) slugs (write side
288 + // covered by 'should normalize toolkit names to lowercase'), so the read
289 + // side must resolve any casing instead of falling back to 'latest'.
290 const toolkitVersions = {
291 github: '20250902_00',
289 - GITHUB: 'latest',
292 };
293
294 expect(getToolkitVersion('github', toolkitVersions)).toBe('20250902_00');
293 - expect(getToolkitVersion('GITHUB', toolkitVersions)).toBe('latest');
294 - expect(getToolkitVersion('GitHub', toolkitVersions)).toBe('latest'); // not found
295 + expect(getToolkitVersion('GITHUB', toolkitVersions)).toBe('20250902_00');
296 + expect(getToolkitVersion('GitHub', toolkitVersions)).toBe('20250902_00');
297 });
298 });
299