fix(skills): normalize web fetch credentials (#9859)

Co-authored-by: backryun <bakryun0718@proton.me>
This commit is contained in:
Diego Rodrigues de Sa e Souza
2026-08-09 09:52:48 -03:00
committed by GitHub
parent c4c39b1a4a
commit a1833b1159
2 changed files with 48 additions and 1 deletions

View File

@@ -61,11 +61,30 @@ function resolvePinnedBackend(input: ExecuteWebFetchInput): WebFetchProviderId |
return backend ? FETCH_BACKEND_TO_PROVIDER[backend] : undefined;
}
export function normalizeWebFetchCredentials(value: unknown): WebFetchCredentials | null {
if (!value || typeof value !== "object") return null;
const credentials = value as Record<string, unknown>;
if (credentials.allRateLimited === true || credentials.allExpired === true) return null;
const providerSpecificData =
credentials.providerSpecificData &&
typeof credentials.providerSpecificData === "object" &&
!Array.isArray(credentials.providerSpecificData)
? (credentials.providerSpecificData as Record<string, unknown>)
: undefined;
return {
...(typeof credentials.apiKey === "string" && { apiKey: credentials.apiKey }),
...(typeof credentials.baseUrl === "string" && { baseUrl: credentials.baseUrl }),
...(providerSpecificData && { providerSpecificData }),
};
}
async function resolveCredentials(
providerId: WebFetchProviderId
): Promise<WebFetchCredentials | null> {
try {
return (await getProviderCredentialsWithQuotaPreflight(providerId)) ?? null;
return normalizeWebFetchCredentials(await getProviderCredentialsWithQuotaPreflight(providerId));
} catch {
return null;
}

View File

@@ -0,0 +1,28 @@
import test from "node:test";
import assert from "node:assert/strict";
const { normalizeWebFetchCredentials } = await import("../../src/lib/skills/webFetchExecution.ts");
test("web-fetch skills reject unavailable credential sentinels", () => {
assert.equal(
normalizeWebFetchCredentials({ allRateLimited: true, retryAfter: "tomorrow" }),
null
);
assert.equal(normalizeWebFetchCredentials({ allExpired: true, expiredCount: 2 }), null);
});
test("web-fetch skills expose only the credential fields used by fetch executors", () => {
assert.deepEqual(
normalizeWebFetchCredentials({
apiKey: "secret",
baseUrl: "https://fetch.example.test",
providerSpecificData: { region: "test" },
accessToken: "must-not-leak-through",
}),
{
apiKey: "secret",
baseUrl: "https://fetch.example.test",
providerSpecificData: { region: "test" },
}
);
});