fix(provider-utils): make validateUrl optional to avoid a breaking change - #17168
Conversation
…rnal callers A required property on getFromApi is a compile break for community provider packages built on @ai-sdk/provider-utils. Make it optional (omitting behaves like false, matching the previous behavior at runtime) and enforce the explicit-decision rule for this repository through the contributor docs instead: AGENTS.md, contributing/providers.md, and contributing/secure-url-handling.md now require every in-repo call site to set it explicitly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
| * decision — see `contributing/secure-url-handling.md`. | ||
| */ | ||
| validateUrl: boolean; | ||
| validateUrl?: boolean; |
There was a problem hiding this comment.
Making this optional avoids the breaking change, but it also drops the compile-time forcing function: omitting the flag now silently skips validation (fail-open) instead of failing to compile. We keep every in-repo call site explicit plus docs, but that is convention, not enforcement, so a future or external caller can still forget it.
If we want the guarantee back without the breaking change, an oxlint rule that requires validateUrl on every getFromApi call in this repo would enforce it in CI while leaving the public type optional. A separate always-validating helper would also work.
There was a problem hiding this comment.
Agreed — convention without enforcement wasn't good enough. Added the oxlint enforcement you suggested in 1ecfff3:
tools/oxlint-plugin-ai-sdk— a repo-local oxlint js-plugin with anai-sdk/require-validate-urlrule: everygetFromApicall must pass an inline options object with an explicitvalidateUrlproperty. Non-literal options arguments (getFromApi(opts)) are rejected too, since they can't be verified statically — the rule fails closed.- Wired into
.oxlintrc.jsonviajsPlugins, so it runs in the existing Lint & Format CI job (pnpm check) — no new workflow needed. - Verified coverage: with the rule active, the only violation in the entire repo was the deliberate backwards-compat test in
get-from-api.test.ts, which now carries a targetedoxlint-disable-next-linewith a justification. - Docs updated (
contributing/providers.md,contributing/secure-url-handling.md,AGENTS.md) to state the rule is CI-enforced rather than convention.
So the guarantee is back for in-repo code — omitting the flag fails pnpm check — while the public type stays optional for external callers. Making the type required again (and deleting this rule) is tracked for the next major.
…nt rule Restores the forcing function that making validateUrl optional dropped: a repo-local oxlint js-plugin rule (ai-sdk/require-validate-url) fails pnpm check for any in-repo getFromApi call without an explicit inline validateUrl, while the public type stays optional for external callers. Non-literal options arguments are rejected too (fail closed). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…mapi-validateurl-optional
5fa672b
into
dnukumamras/getfromapi-url-validation
What this does
Follow-up to the review of #16971.
getFromApiis part of the public@ai-sdk/provider-utilsAPI that community provider packages build on. Adding a required property is a compile break for every external TypeScript caller on a patch release — and for plain-JS callers the requirement was never enforced anyway (validateUrl: undefinedis falsy and silently took the unvalidated path).This makes
validateUrloptional. Omitting it behaves likefalse, which is byte-for-byte the pre-#16971 behavior, so external callers are unaffected. The "every call site makes an explicit trust decision" rule is kept for this repository, enforced through the contributor docs rather than the type system:contributing/providers.md: new Fetching URLs from Responses section — always setvalidateUrlexplicitly,truefor response-body URLs,falsefor config-derived URLs, pluscredentialedOriginguidanceAGENTS.mdandcontributing/secure-url-handling.md: reworded from "required" to "optional for backwards compatibility, but in-repo code must always pass it"validateUrlskips validation (backwards-compat regression test)All existing in-repo call sites keep their explicit
validateUrl: true/false.