Skip to content

Commit cf5910a

Browse files
committed
fix(hosted-tools): one effective-transport decision, one hosted declaration
Follow-up to #924. Two defects a branch review found after that PR merged, both reproduced before fixing. Forward-auth validation diverged from routing. The wire check already asked `providerMatchesRegistryTransport()` whether the config still points at the registry's documented endpoint, but the forward-auth check above it read `registry.authKind` unconditionally. A `preserveCustomDestination` row reused under a custom endpoint keeps its own auth at runtime, so a forward-auth config carrying `modelPreferHostedTools` validated clean while `preferConfiguredHostedTools()` — which runs only on the non-forward branch — never applied it. Both checks now start from the same decision, computed once instead of twice. Multi-container restoration emitted the hosted tool twice. #924 made stripping walk every `additional_tools` container and made restoration walk them too. Tool declarations are request-scoped: the containers are separate carriers for one tool set, so restoring into each put `image_generation` on the wire once per stripped container. Restore into the first stripped container only, which keeps the capability without duplicating it. Both driven red against dev: reverting the two source files fails exactly two tests, one per defect. 248 pass across the four affected files, typecheck clean.
1 parent 3e889a3 commit cf5910a

2 files changed

Lines changed: 14 additions & 14 deletions

File tree

‎src/adapters/openai-responses.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -709,12 +709,12 @@ function preferConfiguredHostedTools(
709709
tools = [...tools, { type: HOSTED_IMAGE_GENERATION_TOOL }];
710710
} else if (strippedAdditionalToolsIndices.size > 0 && Array.isArray(input)) {
711711
// Restore into the FIRST stripped container only. Tool declarations are
712-
// request-scoped, not container-scoped: `hasHostedImageGenDeclaration` above is
713-
// satisfied by a declaration in ANY container, so the containers are separate
714-
// carriers for one tool set. #924 briefly restored into every stripped container,
715-
// which put `image_generation` on the wire twice.
716-
const firstStrippedContainer = Math.min(...strippedAdditionalToolsIndices);
717-
input = input.map((item, index) => index === firstStrippedContainer
712+
// request-scoped, not container-scoped — the containers are separate carriers for
713+
// one tool set, so a single hosted declaration covers the request. An earlier
714+
// revision restored into every stripped container and put `image_generation` on
715+
// the wire twice; review caught it.
716+
const firstStripped = Math.min(...strippedAdditionalToolsIndices);
717+
input = input.map((item, index) => index === firstStripped
718718
&& isPlainObject(item)
719719
&& Array.isArray(item.tools)
720720
? { ...item, tools: [...item.tools, { type: HOSTED_IMAGE_GENERATION_TOOL }] }

‎src/config.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,11 @@ export function modelPreferHostedToolsConfigError(
724724
if (prototype !== Object.prototype && prototype !== null) return `${field} must be a plain object with own properties`;
725725
const entries = Object.entries(value);
726726
const registry = getProviderRegistryEntry(providerName);
727-
// Effective transport, decided once and used by both checks below. A
728-
// `preserveCustomDestination` registry row reused under a different endpoint keeps its
729-
// own adapter AND its own auth at runtime, because `routedProviderConfig()` honors
730-
// `providerMatchesRegistryTransport()`. Deciding forward-auth from `registry.authKind`
731-
// alone accepted a preference the adapter never applies —
727+
// Effective transport: a `preserveCustomDestination` registry row reused under a
728+
// different endpoint keeps its own adapter AND its own auth at runtime, because
729+
// `routedProviderConfig()` honors `providerMatchesRegistryTransport()`. Both the
730+
// wire check below and the forward-auth check here have to start from the same
731+
// decision, or validation accepts a preference the adapter never applies —
732732
// `preferConfiguredHostedTools()` runs only on the non-forward branch.
733733
const registryTransportMatches = typeof provider.baseUrl === "string"
734734
&& providerMatchesRegistryTransport(providerName, {
@@ -788,9 +788,9 @@ export function modelPreferHostedToolsConfigError(
788788
return `${field}.${key} cannot prefer ${tool}: the model does not support it`;
789789
}
790790
}
791-
// Same `registryTransportMatches` decision the forward-auth check above uses: start
792-
// from the registry adapter only when this config still points at the registry's
793-
// documented transport.
791+
// Same `registryTransportMatches` decision the forward-auth check above uses:
792+
// start from the registry adapter only when this config still points at the
793+
// registry's documented transport.
794794
const baseWire = registryTransportMatches ? registry?.adapter ?? provider.adapter : provider.adapter;
795795
let effectiveWire = resolveEffectiveWire(key, baseWire);
796796
const virtualWireModel = resolveOpenAiVirtualModel(providerName, key)?.wireModelId;

0 commit comments

Comments
 (0)