fix: bypass gateway for local model connection tests

This commit is contained in:
Bortlesboat 2026-04-08 18:50:54 -04:00
parent de24293cce
commit e9b392b0b9
No known key found for this signature in database
GPG key ID: A2B96F4BB60D03A1
3 changed files with 32 additions and 2 deletions

View file

@ -6,7 +6,8 @@
"types": "./dist/index.d.ts",
"scripts": {
"build": "rm -rf dist && tsc",
"dev": "tsc -w"
"dev": "tsc -w",
"test": "tsc --pretty false && node --test dist/models/models.test.js"
},
"dependencies": {
"@ai-sdk/anthropic": "^2.0.63",

View file

@ -0,0 +1,20 @@
import test from "node:test";
import assert from "node:assert/strict";
import { shouldUseGatewayForModelTest } from "./models.js";
test("signed-in ollama model tests bypass the gateway", () => {
assert.equal(shouldUseGatewayForModelTest("ollama", true), false);
});
test("signed-in openai-compatible model tests bypass the gateway", () => {
assert.equal(shouldUseGatewayForModelTest("openai-compatible", true), false);
});
test("signed-in hosted model tests still use the gateway", () => {
assert.equal(shouldUseGatewayForModelTest("openai", true), true);
});
test("signed-out hosted model tests do not use the gateway", () => {
assert.equal(shouldUseGatewayForModelTest("openai", false), false);
});

View file

@ -70,6 +70,14 @@ export function createProvider(config: z.infer<typeof Provider>): ProviderV2 {
}
}
export function shouldUseGatewayForModelTest(
flavor: z.infer<typeof Provider>["flavor"],
signedIn: boolean,
): boolean {
const isLocal = flavor === "ollama" || flavor === "openai-compatible";
return signedIn && !isLocal;
}
export async function testModelConnection(
providerConfig: z.infer<typeof Provider>,
model: string,
@ -80,7 +88,8 @@ export async function testModelConnection(
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), effectiveTimeout);
try {
const provider = await isSignedIn()
const signedIn = await isSignedIn();
const provider = shouldUseGatewayForModelTest(providerConfig.flavor, signedIn)
? await getGatewayProvider()
: createProvider(providerConfig);
const languageModel = provider.languageModel(model);