mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-11 01:32:22 +03:00
fix(skills): normalize web fetch credentials
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
28
tests/unit/web-fetch-execution-credentials.test.ts
Normal file
28
tests/unit/web-fetch-execution-credentials.test.ts
Normal 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" },
|
||||
}
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user