Renames the AI-harness/provider settings router into the chat namespace and clears the remaining "pi" identifiers from the chat stack. - server-settings/pi-mono.ts → chat-providers.ts; piMonoRouter → chatProvidersRouter; route /server-settings/pi-mono → /server-settings/chat-providers (+ all callers) - piId → providerId (PROVIDERS map + AIHarnessesSection UI), PiProvider → ChatProvider, PI_MONO_* query keys → CHAT_PROVIDERS_*, installPiMono → installAgent - data-path: PI_CONFIG_DIR → AGENT_CONFIG_DIR (path ~/.pi/agent unchanged); drop dead getPiMonoDir/getPiMonoSessionDir exports - settings: flip the vestigial defaultProvider literal 'pi' → 'chat' (never read; only defaultModel drives behavior); access-policy config key 'pi-access-policy' → 'chat-access-policy' - misc: ModelSelector fallback label, TaskDefaults model grouping, CapabilityPage chat var, a stale stream-parser comment Intentionally left (genuine external `pi`/opencode references, not ours to rename): the `pi` binary install/version flow (@mariozechner/pi-coding-agent, `which pi`), the ~/.pi/agent config path, PI_TOOLS_DIRS/PI_SEARXNG_URL runtime env-var contract, TOOL.md `targets: pi` metadata, and the "Pi Mono" installer UI label. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
import { createRouter } from '../../create-router';
|
|
import { getUserSettings, setUserSettings, getUserState, patchUserState } from 'officerdb';
|
|
|
|
const DEFAULT_SETTINGS = {
|
|
chat: {
|
|
defaultProvider: 'chat',
|
|
defaultModel: null,
|
|
systemPrompt: '',
|
|
temperature: 1,
|
|
defaultPwd: '~',
|
|
},
|
|
appearance: {
|
|
theme: 'light',
|
|
},
|
|
};
|
|
|
|
export const settingsRouter = createRouter();
|
|
|
|
// GET /settings — return user settings from DB, default if empty
|
|
settingsRouter.get('/settings', async (ctx) => {
|
|
const userId = ctx.get('user').id;
|
|
const settings = await getUserSettings(userId);
|
|
|
|
if (Object.keys(settings).length === 0) {
|
|
await setUserSettings(userId, DEFAULT_SETTINGS);
|
|
return ctx.json(DEFAULT_SETTINGS);
|
|
}
|
|
|
|
return ctx.json(settings);
|
|
});
|
|
|
|
// PUT /settings — full replacement
|
|
settingsRouter.put('/settings', async (ctx) => {
|
|
const userId = ctx.get('user').id;
|
|
const body = ctx.get('body');
|
|
await setUserSettings(userId, body);
|
|
return ctx.json(body);
|
|
});
|
|
|
|
// GET /state — return user state from DB
|
|
settingsRouter.get('/state', async (ctx) => {
|
|
const userId = ctx.get('user').id;
|
|
const state = await getUserState(userId);
|
|
return ctx.json(state);
|
|
});
|
|
|
|
// PATCH /state — shallow-merge incoming keys
|
|
settingsRouter.patch('/state', async (ctx) => {
|
|
const userId = ctx.get('user').id;
|
|
const body = ctx.get('body');
|
|
const merged = await patchUserState(userId, body);
|
|
return ctx.json(merged);
|
|
});
|