feat: disconnect a custom endpoint (DELETE /api/custom-provider + Disconnect in its editor)

Connecting was one-way: POST could only replace the base URL, and the only
escape was hand-editing settings.json. DELETE now mirrors POST — drop the
stored section, delete the reserved key, unregister the provider from
piModels() — and the connect editor grows a Disconnect beside Connect,
following the stored-key rows' Delete pattern (quiet text, one click, no
confirm, only once there is an endpoint to remove).
This commit is contained in:
Daniel Buckner
2026-10-27 15:56:17 -07:00
parent 1b01919482
commit 286a95ba04
2 changed files with 40 additions and 0 deletions
+14
View File
@@ -5,6 +5,8 @@
* fast), store the key, persist { baseUrl, models }, re-sync the
* provider into piModels(). Discovery lives here because connecting
* and discovering are one user action.
* DELETE → disconnect: drop the stored config + the stored key and unregister
* the provider (the mirror image of POST; idempotent).
*/
import {
deleteKey,
@@ -56,3 +58,15 @@ export async function POST(request: Request) {
syncCustomProvider(next.customProvider);
return Response.json({ ok: true, models: next.customProvider?.models ?? [] });
}
/** Disconnect: forget the endpoint AND its key, then unregister the provider.
* Deleting the section (rather than blanking baseUrl) keeps settings.json the
* same shape as a never-connected install. Idempotent by construction. */
export async function DELETE() {
const record = readSettingsRecord() ?? { version: 1 };
const { customProvider: _dropped, ...rest } = record;
const next = writeSettingsRecord(rest);
deleteKey(CUSTOM_PROVIDER.envVar);
syncCustomProvider(next.customProvider);
return Response.json({ ok: true });
}