refactor(providers): a provider is a vendor and a key, and the table is gone

The dropdown was listing "connections" — a row per adapter + model + key — which
made choosing a model an act of configuration, put a key icon and a bin inside a
menu item, and showed five accounts nobody had created.

A provider is now a vendor Officer curates. Every one is listed, set up or not,
because a vendor you have no key for is exactly what you need to see in order to
add one. The model is chosen per generation, from that provider's entry in the
catalogue, beside it.

With the model off the row, all that remained of a "provider" was the key for
OpenAI — and Officer already stores keys: one active value per purpose, 0600
inside a 0700 directory, outside the backup tarball, created on first use so
nothing needs provisioning. So `atelier_providers` is dropped, along with
`generations.provider_id` that pointed into it. `provider` and `model` stay as
text on each generation, which were always the historical fact rather than a
pointer to configuration.

`getSecret`, never `getKey`: this is a foreign credential, and getKey mints a
random value for a purpose it cannot find — which for someone else's API key
means authenticating with something invented.

Resolution follows: a request names a model, and the catalogue says whose it is,
rather than a database being asked which stored row served it. A model nobody
in the catalogue claims is still accepted — the catalogue is advisory, and a
model released today should work before we ship a file that mentions it.

Two routes replace five: PUT and DELETE on /providers/:name/key. Deleting a key
that came from the environment is refused rather than faked — it belongs to the
install, not to this screen.
This commit is contained in:
2026-08-20 23:02:31 +01:00
parent 3c59bf4d0c
commit 19e94129a0
17 changed files with 441 additions and 766 deletions
+29 -10
View File
@@ -10,7 +10,7 @@ import {
} from '../db';
import type { NewGeneration } from '../db';
import { createRouter } from '../create-router';
import { resolveForRequest } from '../providers/credentials';
import { providerStatuses, resolveForRequest } from '../providers/credentials';
import { validateImageEditRequest, validateImageRequest } from '../generations/validate';
import { INPUTS_DIR } from '../env';
import { pump } from '../generations/queue';
@@ -39,6 +39,12 @@ export const imagesRouter = createRouter();
*/
const MAX_WAIT_SECONDS = 240;
/** The catalogue's default model for a provider, for a request that named one without the other. */
async function defaultModelFor(provider: string): Promise<string | undefined> {
const status = (await providerStatuses()).find((entry) => entry.name === provider);
return status?.default_model ?? undefined;
}
/**
* Resolve `?collection=` to a collection, creating one if the value is a name we have not seen.
*
@@ -87,13 +93,21 @@ imagesRouter.post('/generations', async (ctx) => {
const type = resolvedProvider.status === 404 ? 'not_found' : 'configuration_error';
return ctx.json(openaiError(resolvedProvider.error, type), resolvedProvider.status);
}
const { provider, adapter } = resolvedProvider;
const { providerName, adapter } = resolvedProvider;
const resolved = await resolveCollection(ctx.req.query('collection'));
if (resolved.error) return ctx.json(openaiError(resolved.error, 'not_found', 'collection'), 404);
// The request's model wins over the provider's, so a provider can serve a model nobody configured.
const model = request.model ?? provider.model;
// The request's model wins; otherwise the catalogue's default for this provider. A provider no longer
// carries a model of its own — that was configuration standing in for a per-generation choice — so
// when the catalogue has nothing to default to either, that is a 400 rather than a row with no model.
const model = request.model ?? (await defaultModelFor(providerName));
if (!model) {
return ctx.json(
openaiError(`No model given, and no default known for "${providerName}".`, 'invalid_request_error', 'model'),
400,
);
}
const requestId = randomUUID();
const count = request.n ?? 1;
@@ -105,8 +119,7 @@ imagesRouter.post('/generations', async (ctx) => {
requestId,
index,
status: 'queued' as const,
provider: adapter.name,
providerId: provider.id,
provider: providerName,
model,
prompt,
options,
@@ -233,7 +246,7 @@ imagesRouter.post('/edits', async (ctx) => {
const type = resolvedProvider.status === 404 ? 'not_found' : 'configuration_error';
return ctx.json(openaiError(resolvedProvider.error, type), resolvedProvider.status);
}
const { provider, adapter } = resolvedProvider;
const { providerName, adapter } = resolvedProvider;
if (!adapter.edit) {
return ctx.json(openaiError(`Adapter "${adapter.name}" cannot edit images.`, 'invalid_request_error'), 400);
@@ -252,7 +265,14 @@ imagesRouter.post('/edits', async (ctx) => {
const resolved = await resolveCollection(ctx.req.query('collection'));
if (resolved.error) return ctx.json(openaiError(resolved.error, 'not_found', 'collection'), 404);
const model = request.model ?? provider.model;
const model = request.model ?? (await defaultModelFor(providerName));
if (!model) {
return ctx.json(
openaiError(`No model given, and no default known for "${providerName}".`, 'invalid_request_error', 'model'),
400,
);
}
const requestId = randomUUID();
const count = request.n ?? 1;
@@ -264,8 +284,7 @@ imagesRouter.post('/edits', async (ctx) => {
index,
operation: 'edit' as const,
status: 'queued' as const,
provider: adapter.name,
providerId: provider.id,
provider: providerName,
model,
prompt,
options,