@devries-cameron20 / composio Mirror · read-only / commits / 876c88767
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, 12:15 UTC

fix(core): normalize a missing toolkit auth field group instead of throwing

Replacing the pass-through with an eager projection changed the failure mode for an auth config detail that omits a field group. Passing the group through left `undefined` in place, which zod rejected as a handled validation error; `transformToolkitAuthFieldGroup` instead reads `group.required`, so the same response now throws a `TypeError` before validation runs and crashes `toolkits.get()`. Default a missing or null group, and a missing list inside a group, to empty lists. This repo's docs pipeline already assumes that shape: the schemas in `docs/lib/toolkit-api.ts` carry `.catch({ required: [], optional: [] })` on the same fields. Normalizing also keeps the other group usable when only one is absent, which is typically the one the caller asked for, where a validation error would have returned nothing. Reported by greptile-apps on #4411. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

Moritz Diesing committed Sep 15, 2026 at 15:11 UTC 876c88767c89da1b1b1630f8ed5e41a63a0065b0
3 files changed +117 -9
.changeset/toolkit-auth-field-is-secret.md
+1 -1
@@ -2,4 +2,4 @@
2 '@composio/core': patch
3 ---
4
5 -Stop dropping `is_secret`, `legacy_template_name` and `auth_hint_url` from toolkit auth config details. `transformToolkitRetrieveResponse` passed the auth field groups through unchanged, so the snake_case keys never matched `ToolkitAuthFieldSchema` and zod stripped them during validation; `auth_hint_url` was never mapped at all. Fields returned by `toolkits.getConnectedAccountInitiationFields()` and `toolkits.getAuthConfigCreationFields()` now carry `isSecret`, which the API documents as the signal for whether a client should mask the input, plus `legacyTemplateName`; auth config details returned by `toolkits.get()` now carry `authHintUrl`. Each of these keys is present only when the API sends it, so spreading a field no longer overwrites a caller's own fallback with `undefined`.
5 +Stop dropping `is_secret`, `legacy_template_name` and `auth_hint_url` from toolkit auth config details. `transformToolkitRetrieveResponse` passed the auth field groups through unchanged, so the snake_case keys never matched `ToolkitAuthFieldSchema` and zod stripped them during validation; `auth_hint_url` was never mapped at all. Fields returned by `toolkits.getConnectedAccountInitiationFields()` and `toolkits.getAuthConfigCreationFields()` now carry `isSecret`, which the API documents as the signal for whether a client should mask the input, plus `legacyTemplateName`; auth config details returned by `toolkits.get()` now carry `authHintUrl`. Each of these keys is present only when the API sends it, so spreading a field no longer overwrites a caller's own fallback with `undefined`. An auth config detail that omits a field group entirely now yields empty lists for that group, matching how the docs pipeline defaults them, instead of failing validation and leaving the other group unusable.
ts/packages/core/src/utils/transformers/toolkits.ts
+25 -8
@@ -58,12 +58,29 @@ const transformToolkitAuthField = (field: RawToolkitAuthField): ToolkitAuthField
58 }),
59 });
60
61 -const transformToolkitAuthFieldGroup = (group: {
62 - required: Array<RawToolkitAuthField>;
63 - optional: Array<RawToolkitAuthField>;
64 -}) => ({
65 - required: group.required.map(transformToolkitAuthField),
66 - optional: group.optional.map(transformToolkitAuthField),
61 +/**
62 + * Normalize one field group to empty lists when the API omits it, the way this
63 + * repo's own docs pipeline does (`docs/lib/toolkit-api.ts` defaults a missing
64 + * group to `{ required: [], optional: [] }`).
65 + *
66 + * The generated client declares both groups and both lists as required, but a
67 + * response that omits one reached zod and failed validation there. Mapping it
68 + * eagerly would instead throw a `TypeError` on the property access, before
69 + * validation, turning a handled validation error into a crash of
70 + * `toolkits.get()`. Normalizing also leaves the other group usable, which is
71 + * typically the one the caller asked for.
72 + */
73 +const transformToolkitAuthFieldGroup = (
74 + group:
75 + | {
76 + required?: Array<RawToolkitAuthField> | null;
77 + optional?: Array<RawToolkitAuthField> | null;
78 + }
79 + | null
80 + | undefined
81 +) => ({
82 + required: (group?.required ?? []).map(transformToolkitAuthField),
83 + optional: (group?.optional ?? []).map(transformToolkitAuthField),
84 });
85
86 export const transformToolkitListResponse = (
@@ -128,10 +145,10 @@ export const transformToolkitRetrieveResponse = (
145 }),
146 fields: {
147 authConfigCreation: transformToolkitAuthFieldGroup(
131 - authConfig.fields.auth_config_creation
148 + authConfig.fields?.auth_config_creation
149 ),
150 connectedAccountInitiation: transformToolkitAuthFieldGroup(
134 - authConfig.fields.connected_account_initiation
151 + authConfig.fields?.connected_account_initiation
152 ),
153 },
154 proxy: {
ts/packages/core/test/utils/transformers/toolkits.test.ts
+91
@@ -175,6 +175,97 @@ describe('transformToolkitRetrieveResponse', () => {
175 ).not.toHaveProperty('authHintUrl');
176 });
177
178 + /**
179 + * The generated client declares both groups, but responses that omit one do
180 + * occur: this repo's own docs pipeline defaults them (`docs/lib/toolkit-api.ts`).
181 + * A missing group used to reach zod and fail validation; mapping it eagerly
182 + * would throw a TypeError before validation instead.
183 + */
184 + describe('when the API omits a field group', () => {
185 + const withDetail = (detail: unknown) =>
186 + ({ ...rawToolkit, auth_config_details: [detail] }) as unknown as RawRetrieveResponse;
187 +
188 + const populatedInitiation = {
189 + required: [
190 + {
191 + name: 'api_key',
192 + displayName: 'API Key',
193 + description: 'Your API key',
194 + type: 'string',
195 + required: true,
196 + is_secret: true,
197 + },
198 + ],
199 + optional: [],
200 + };
201 +
202 + it('returns empty lists for a missing auth_config_creation and keeps the other group', () => {
203 + const detail = {
204 + name: 'API Key',
205 + mode: 'API_KEY',
206 + fields: { connected_account_initiation: populatedInitiation },
207 + };
208 +
209 + const fields = transformToolkitRetrieveResponse(withDetail(detail)).authConfigDetails?.[0]
210 + .fields;
211 +
212 + expect(fields?.authConfigCreation).toEqual({ required: [], optional: [] });
213 + expect(fields?.connectedAccountInitiation.required[0]).toEqual({
214 + name: 'api_key',
215 + displayName: 'API Key',
216 + description: 'Your API key',
217 + type: 'string',
218 + required: true,
219 + isSecret: true,
220 + });
221 + });
222 +
223 + it('returns empty lists for a missing connected_account_initiation and keeps the other group', () => {
224 + const detail = {
225 + name: 'API Key',
226 + mode: 'API_KEY',
227 + fields: { auth_config_creation: populatedInitiation },
228 + };
229 +
230 + const fields = transformToolkitRetrieveResponse(withDetail(detail)).authConfigDetails?.[0]
231 + .fields;
232 +
233 + expect(fields?.connectedAccountInitiation).toEqual({ required: [], optional: [] });
234 + expect(fields?.authConfigCreation.required).toHaveLength(1);
235 + });
236 +
237 + it('fills in a list the group itself is missing', () => {
238 + const detail = {
239 + name: 'API Key',
240 + mode: 'API_KEY',
241 + fields: {
242 + auth_config_creation: { required: [], optional: [] },
243 + connected_account_initiation: { optional: populatedInitiation.required },
244 + },
245 + };
246 +
247 + const group = transformToolkitRetrieveResponse(withDetail(detail)).authConfigDetails?.[0]
248 + .fields.connectedAccountInitiation;
249 +
250 + expect(group?.required).toEqual([]);
251 + expect(group?.optional).toHaveLength(1);
252 + });
253 +
254 + it('treats a null group like a missing one', () => {
255 + const detail = {
256 + name: 'API Key',
257 + mode: 'API_KEY',
258 + fields: { auth_config_creation: null, connected_account_initiation: populatedInitiation },
259 + };
260 +
261 + expect(() => transformToolkitRetrieveResponse(withDetail(detail))).not.toThrow();
262 + expect(
263 + transformToolkitRetrieveResponse(withDetail(detail)).authConfigDetails?.[0].fields
264 + .authConfigCreation
265 + ).toEqual({ required: [], optional: [] });
266 + });
267 + });
268 +
269 it('lets a caller fallback survive spreading a field with no default', () => {
270 const field = initiationRequired(rawToolkitWithoutOptionalKeys);
271