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:
@@ -1,9 +1,9 @@
|
||||
import { join } from 'node:path';
|
||||
import { claimableGenerations, failInterrupted, getProvider, markFailed, markRunning, markSucceeded } from '../db';
|
||||
import { claimableGenerations, failInterrupted, markFailed, markRunning, markSucceeded } from '../db';
|
||||
import type { Generation } from '../db';
|
||||
import { IMAGES_DIR, INPUTS_DIR, MAX_CONCURRENT_GENERATIONS } from '../env';
|
||||
import { adapterByName } from '../providers';
|
||||
import { keyForProvider } from '../providers/credentials';
|
||||
import { keyFor } from '../providers/credentials';
|
||||
import { inspectImage } from './inspect';
|
||||
import type { ImageEditRequest, ImageRequest, UploadedImage } from '../providers';
|
||||
|
||||
@@ -59,13 +59,11 @@ async function run(row: Generation): Promise<void> {
|
||||
const adapter = adapterByName(row.provider);
|
||||
if (!adapter) throw new Error(`Unknown adapter "${row.provider}"`);
|
||||
|
||||
// The provider row is looked up by id, but the adapter and model come from the ROW's own columns:
|
||||
// a provider renamed or repointed after this was queued must not change what gets generated.
|
||||
const provider = row.providerId ? await getProvider(row.providerId) : undefined;
|
||||
const apiKey = provider
|
||||
? await keyForProvider(provider)
|
||||
: await keyForProvider({ adapter: row.provider, apiKeyEncrypted: null, name: row.provider } as never);
|
||||
if (!apiKey) throw new Error(`No API key for adapter "${row.provider}"`);
|
||||
// The adapter and model come from the ROW's own columns, and the key is read at RUN time: a key
|
||||
// rotated between queueing and running should be the new one, and a row queued before a key existed
|
||||
// at all runs the moment there is one.
|
||||
const apiKey = keyFor(row.provider);
|
||||
if (!apiKey) throw new Error(`No API key for provider "${row.provider}"`);
|
||||
|
||||
const result =
|
||||
row.operation === 'edit'
|
||||
|
||||
Reference in New Issue
Block a user