Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/hub/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ export async function createHubRuntime(
credentialCipher,
config,
installRootId,
async (request) => app.fetch(request),
),
);
const modelLogins = mountModelLogins(app, {
Expand Down
7 changes: 5 additions & 2 deletions apps/hub/src/artifacts/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ import {
} from "../config/preferences.ts";
import { awaitingApproval } from "../projects/deploy-tools.ts";
import { frozenModelChoice, workflowBindings } from "../config/models.ts";
import { modelDirectory } from "../settings/custom-providers.ts";
import { materialsNote } from "../config/materials.ts";
import { servingOffering } from "../workflows/install-for-tenant.ts";
import {
Expand Down Expand Up @@ -1003,13 +1004,15 @@ export function createArtifactService(
): Promise<AcceptedMaterials> {
await requireProject(actor, projectId, "read");
const { models } = await loadSettings(rawDB, actor.tenantId, projectId);
const choice = frozenModelChoice(models.value);
const directory = await modelDirectory(rawDB, actor.tenantId);
const choice = frozenModelChoice(directory, models.value);
const offering =
choice &&
(await servingOffering(
rawDB,
directory,
actor.tenantId,
workflowBindings(choice).coordinator,
workflowBindings(directory, choice).coordinator,
));
return acceptedMaterials(offering?.capabilities ?? []);
},
Expand Down
20 changes: 14 additions & 6 deletions apps/hub/src/availability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ const log = getLogger(["corbits-builder", "availability"]);

// These are wire-protocol adapters, not a provider/model registry. Identity,
// endpoints, shadowing and credential authority all come from the native catalog.
function probeRequest(plugin: string, baseURL: string, secret: string) {
function probeRequest(
plugin: string,
baseURL: string,
secret: string | undefined,
) {
const url = new URL(baseURL);
if (
!["http:", "https:"].includes(url.protocol) ||
Expand All @@ -45,16 +49,17 @@ function probeRequest(plugin: string, baseURL: string, secret: string) {
case "openai-responses":
case "openai-compatible":
url.pathname = `${url.pathname.replace(/\/$/, "")}/models`;
headers.set("authorization", `Bearer ${secret}`);
if (secret !== undefined)
headers.set("authorization", `Bearer ${secret}`);
break;
case "anthropic":
url.pathname = `${url.pathname.replace(/\/$/, "")}/v1/models`;
headers.set("x-api-key", secret);
if (secret !== undefined) headers.set("x-api-key", secret);
headers.set("anthropic-version", "2023-06-01");
break;
case "google-genai":
url.pathname = `${url.pathname.replace(/\/$/, "")}/v1beta/models`;
headers.set("x-goog-api-key", secret);
if (secret !== undefined) headers.set("x-goog-api-key", secret);
break;
default:
return null;
Expand Down Expand Up @@ -139,11 +144,14 @@ export function createAvailabilityProbe(
};
}

/** One model-list call with this key; `origin`, when given, is the only origin the key may reach. */
/**
* One model-list call with this key, or with none for a keyless server; `origin`, when given, is
* the only origin the key may reach.
*/
export async function probeKey(
plugin: string,
baseURL: string,
secret: string,
secret: string | undefined,
origin?: string,
): Promise<AvailabilityState> {
let request;
Expand Down
22 changes: 16 additions & 6 deletions apps/hub/src/config/models.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import { expect, test } from "bun:test";
import { resolveModelChoice } from "./models.ts";
import { MODEL_PROVIDERS, resolveModelChoice } from "./models.ts";

test("a project runs on the only connected provider's profile, a chosen one, or none", () => {
expect(resolveModelChoice(null, ["anthropic"])).toMatchObject({
expect(
resolveModelChoice(MODEL_PROVIDERS, null, ["anthropic"]),
).toMatchObject({
choice: { profile: "anthropic_default" },
});
expect(resolveModelChoice(null, ["anthropic", "openai"])).toEqual({
expect(
resolveModelChoice(MODEL_PROVIDERS, null, ["anthropic", "openai"]),
).toEqual({
refused: "model_profile_required",
});
expect(resolveModelChoice(null, [])).toEqual({
expect(resolveModelChoice(MODEL_PROVIDERS, null, [])).toEqual({
refused: "model_provider_missing",
});
expect(
resolveModelChoice({ profile: "openai_default" }, ["anthropic", "openai"]),
resolveModelChoice(MODEL_PROVIDERS, { profile: "openai_default" }, [
"anthropic",
"openai",
]),
).toMatchObject({
choice: { profile: "openai_default" },
});
// A stored choice this server no longer offers is no choice.
expect(
resolveModelChoice({ profile: "gone_default" }, ["anthropic", "openai"]),
resolveModelChoice(MODEL_PROVIDERS, { profile: "gone_default" }, [
"anthropic",
"openai",
]),
).toEqual({
refused: "model_profile_required",
});
Expand Down
Loading