This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-25 16:53:57 -04:00
1 parent 14cfd98a67
commit 89ff737dfd
21 files changed
+1875 -90

No files matched your search

+62 -1
View File
@@ -58,6 +58,60 @@ export const updateConfig = (config: Record<string, unknown>) =>
method: 'PUT'
});
// ── Agents ─────────────────────────────────────────────────
export type AgentType = 'codex' | 'claude_code';
export type AgentMode = 'auto' | 'enabled' | 'disabled';
export type AgentStatus = 'ready' | 'not_found' | 'missing_dependency' | 'auth_unknown' | 'error';
export interface AgentProfile {
id: string;
agent: AgentType;
name: string;
mode: AgentMode;
command: string;
home: string | null;
models: string[];
default_model: string;
approval_mode?: 'ask' | 'auto' | 'full';
sandbox_mode?: 'read-only' | 'workspace-write' | 'danger-full-access';
permission_mode?: 'default' | 'accept_edits' | 'bypass_permissions';
launch_args?: string;
}
export interface AgentsResponseProfile {
id: string;
agent: AgentType;
name: string;
config: AgentProfile;
detected: {
status: AgentStatus;
command: string | null;
version: string | null;
message: string | null;
models?: string[] | null;
};
available: boolean;
implicit: boolean;
model_ids: string[];
}
export interface AgentsResponse {
profiles: AgentsResponseProfile[];
}
export const getAgents = async (): Promise<AgentsResponse> =>
fetchJSON<AgentsResponse>('/api/admin/agents');
export const updateAgents = (profiles: AgentProfile[]): Promise<AgentsResponse> =>
fetchJSON<AgentsResponse>('/api/admin/agents', {
...jsonBody({ profiles }),
method: 'PUT'
});
export const refreshAgents = async (): Promise<AgentsResponse> =>
fetchJSON<AgentsResponse>('/api/admin/agents/refresh', { method: 'POST' });
// ── Connections ─────────────────────────────────────────────
export interface Connection {
@@ -118,7 +172,14 @@ export interface ModelConfigEntry {
export interface ModelConfigResponse {
config: Record<string, ModelConfigEntry>;
models: { id: string; name: string; provider: string; connection_id: string }[];
models: {
id: string;
name: string;
provider: string;
connection_id: string;
agent_id?: string;
profile_id?: string;
}[];
}
export const getModelConfig = async (): Promise<ModelConfigResponse> =>
@@ -0,0 +1,192 @@
<script lang="ts">
import Modal from '../Modal.svelte';
import { t } from '$lib/i18n';
import type { AgentProfile } from '$lib/apis/admin';
interface Props {
profile: AgentProfile;
isNew?: boolean;
onclose: () => void;
onsave: (profile: AgentProfile) => void;
ondelete: () => void;
}
let { profile, isNew = false, onclose, onsave, ondelete }: Props = $props();
const fieldPrefix = `agent-profile-${Math.random().toString(36).slice(2)}`;
// svelte-ignore state_referenced_locally
let draft = $state<AgentProfile>({
...profile,
models: [...(profile.models?.length ? profile.models : ['default'])]
});
function normalizeDraft(): AgentProfile {
const fallbackModel = draft.agent === 'codex' ? 'gpt-5.4' : 'claude-sonnet-4-6';
const currentModels = draft.models?.map((model) => model.trim()).filter(Boolean) || [];
const models =
currentModels.length === 1 && currentModels[0] === 'default'
? [fallbackModel]
: currentModels.length
? currentModels
: [fallbackModel];
const defaultModel =
draft.default_model !== 'default' && models.includes(draft.default_model)
? draft.default_model
: models[0];
return {
...draft,
id: draft.id.trim(),
name: draft.name.trim() || draft.id.trim(),
command: draft.command.trim() || (draft.agent === 'codex' ? 'codex' : 'claude'),
home: draft.home?.trim() || null,
models,
default_model: defaultModel,
launch_args: draft.launch_args?.trim() || ''
};
}
</script>
<Modal {onclose} class="w-full max-w-md mx-4">
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
class="p-4"
onkeydown={(e) => {
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) onsave(normalizeDraft());
}}
>
<div class="flex items-center justify-between gap-3 mb-3">
<h2 class="text-sm font-medium text-gray-900 dark:text-white">
{isNew ? $t('admin.agentsAddProfile') : draft.name}
</h2>
<button
type="button"
class="text-[13px] text-gray-400 dark:text-gray-600 hover:text-gray-700 dark:hover:text-gray-300 transition-colors"
onclick={onclose}
>
Close
</button>
</div>
<div class="flex gap-3">
<div class="flex-1">
<label for={`${fieldPrefix}-name`} class="text-[10px] text-gray-400 dark:text-gray-600">
{$t('admin.agentsProfileName')}
</label>
<input
id={`${fieldPrefix}-name`}
type="text"
bind:value={draft.name}
autocomplete="off"
spellcheck="false"
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5"
/>
</div>
<div class="w-32 shrink-0">
<label for={`${fieldPrefix}-type`} class="text-[10px] text-gray-400 dark:text-gray-600">
{$t('admin.agentsType')}
</label>
<select
id={`${fieldPrefix}-type`}
value={draft.agent}
onchange={(e) => {
const agent = e.currentTarget.value as 'codex' | 'claude_code';
const defaultModel = agent === 'codex' ? 'gpt-5.4' : 'claude-sonnet-4-6';
draft = {
...draft,
agent,
command: agent === 'codex' ? 'codex' : 'claude',
models: [defaultModel],
default_model: defaultModel,
approval_mode: draft.approval_mode || 'auto',
sandbox_mode: draft.sandbox_mode || 'workspace-write',
permission_mode: draft.permission_mode || 'default',
launch_args: draft.launch_args || ''
};
}}
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer"
>
<option value="codex">Codex</option>
<option value="claude_code">Claude Code</option>
</select>
</div>
</div>
<label for={`${fieldPrefix}-id`} class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">
{$t('admin.agentsProfileId')}
</label>
<input
id={`${fieldPrefix}-id`}
type="text"
bind:value={draft.id}
autocomplete="off"
spellcheck="false"
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
/>
<label for={`${fieldPrefix}-command`} class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">
{$t('admin.agentsCommand')}
</label>
<input
id={`${fieldPrefix}-command`}
type="text"
bind:value={draft.command}
placeholder={draft.agent === 'codex' ? 'codex' : 'claude'}
autocomplete="off"
spellcheck="false"
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
/>
<label for={`${fieldPrefix}-home`} class="text-[10px] text-gray-400 dark:text-gray-600 mt-2">
{$t('admin.agentsHome')}
</label>
<input
id={`${fieldPrefix}-home`}
type="text"
value={draft.home || ''}
placeholder="Optional"
autocomplete="off"
spellcheck="false"
oninput={(e) => (draft.home = e.currentTarget.value || null)}
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
/>
{#if draft.agent === 'claude_code'}
<label
for={`${fieldPrefix}-launch-args`}
class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
>
{$t('admin.agentsLaunchArgs')}
</label>
<input
id={`${fieldPrefix}-launch-args`}
type="text"
bind:value={draft.launch_args}
autocomplete="off"
spellcheck="false"
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5 font-mono"
/>
{/if}
<div class="flex items-center justify-between mt-3">
<div class="flex items-center gap-3">
{#if !isNew}
<button
type="button"
class="text-[13px] text-gray-400 hover:text-red-500 dark:hover:text-red-400 transition-colors duration-100"
onclick={ondelete}
title={$t('admin.agentsDeleteProfile')}
>
{$t('admin.agentsDeleteProfile')}
</button>
{/if}
</div>
<button
type="button"
onclick={() => onsave(normalizeDraft())}
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100"
>
{$t('settings.save')}
</button>
</div>
</div>
</Modal>
@@ -0,0 +1,309 @@
<script lang="ts">
import { onMount } from 'svelte';
import { toast } from 'svelte-sonner';
import {
getAgents,
refreshAgents,
updateAgents,
type AgentProfile,
type AgentsResponseProfile
} from '$lib/apis/admin';
import Icon from '$lib/components/Icon.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import { t } from '$lib/i18n';
import { refreshChatState } from '$lib/stores/chat';
import AgentProfileModal from './AgentProfileModal.svelte';
type ModalState =
| { mode: 'create'; profile: AgentProfile }
| { mode: 'edit'; index: number; profile: AgentProfile };
let loading = $state(true);
let saving = $state(false);
let refreshing = $state(false);
let profiles = $state<AgentProfile[]>([]);
let detected = $state<Record<string, AgentsResponseProfile['detected']>>({});
let available = $state<Record<string, boolean>>({});
let saved = $state<Record<string, boolean>>({});
let modal = $state<ModalState | null>(null);
const statusLabelKey: Record<string, string> = {
ready: 'admin.agentsStatusReady',
not_found: 'admin.agentsStatusNotFound',
missing_dependency: 'admin.agentsStatusMissingDependency',
auth_unknown: 'admin.agentsStatusAuthUnknown',
error: 'admin.agentsStatusError'
};
function normalizeProfile(profile: AgentProfile): AgentProfile {
const models = profile.models?.map((m) => m.trim()).filter(Boolean);
const nextModels = models.length ? models : ['default'];
const defaultModel = nextModels.includes(profile.default_model)
? profile.default_model
: nextModels[0];
return {
...profile,
id: profile.id.trim(),
name: profile.name.trim() || profile.id.trim(),
command: profile.command.trim() || (profile.agent === 'codex' ? 'codex' : 'claude'),
home: profile.home?.trim() || null,
models: nextModels,
default_model: defaultModel,
launch_args: profile.launch_args?.trim() || ''
};
}
function applyResponse(data: { profiles: AgentsResponseProfile[] }) {
profiles = data.profiles.map((entry) => entry.config);
detected = Object.fromEntries(data.profiles.map((entry) => [entry.id, entry.detected]));
available = Object.fromEntries(data.profiles.map((entry) => [entry.id, entry.available]));
saved = Object.fromEntries(data.profiles.map((entry) => [entry.id, !entry.implicit]));
}
function newProfile(agent: 'codex' | 'claude_code' = 'codex'): AgentProfile {
const base = agent === 'codex' ? 'codex' : 'claude-code';
const defaultModel = agent === 'codex' ? 'gpt-5.4' : 'claude-sonnet-4-6';
let suffix = profiles.length + 1;
let id = `${base}-${suffix}`;
while (profiles.some((p) => p.id === id)) {
suffix += 1;
id = `${base}-${suffix}`;
}
return {
id,
agent,
name: agent === 'codex' ? 'Codex' : 'Claude Code',
mode: 'enabled',
command: agent === 'codex' ? 'codex' : 'claude',
home: null,
models: [defaultModel],
default_model: defaultModel,
approval_mode: 'auto',
sandbox_mode: 'workspace-write',
permission_mode: 'default',
launch_args: ''
};
}
function profileSubtitle(profile: AgentProfile): string {
const modelCount = profile.models?.length || 0;
const modelLabel = modelCount === 1 ? profile.default_model : `${modelCount} models`;
return `agent:${profile.id} · ${modelLabel}`;
}
function statusKey(profile: AgentProfile): string {
return statusLabelKey[detected[profile.id]?.status || 'error'] || statusLabelKey.error;
}
function statusTone(profile: AgentProfile): string {
if (profile.mode === 'disabled') return 'bg-gray-300 dark:bg-gray-700';
const status = detected[profile.id]?.status || 'error';
if (available[profile.id] && status === 'ready') return 'bg-emerald-500 dark:bg-emerald-400';
if (status === 'missing_dependency' || status === 'auth_unknown') {
return 'bg-amber-400 dark:bg-amber-300';
}
return 'bg-gray-300 dark:bg-gray-700';
}
function saveProfile(profile: AgentProfile) {
const normalized = normalizeProfile(profile);
const currentModal = modal;
if (currentModal?.mode === 'edit') {
const previousId = currentModal.profile.id;
profiles = profiles.map((current, index) =>
index === currentModal.index ? normalized : current
);
if (previousId !== normalized.id) {
const { [previousId]: _removed, ...rest } = saved;
saved = rest;
}
} else {
profiles = [...profiles, normalized];
}
saved = { ...saved, [normalized.id]: true };
modal = null;
}
function deleteProfile() {
const currentModal = modal;
if (currentModal?.mode !== 'edit') {
modal = null;
return;
}
const profile = profiles[currentModal.index];
profiles = profiles.filter((_, index) => index !== currentModal.index);
if (profile) {
const { [profile.id]: _removed, ...rest } = saved;
saved = rest;
}
modal = null;
}
function toggleProfile(e: Event, index: number) {
e.stopPropagation();
const profile = profiles[index];
if (!profile) return;
const mode = profile.mode === 'disabled' ? 'enabled' : 'disabled';
profiles = profiles.map((current, i) => (i === index ? { ...current, mode } : current));
saved = { ...saved, [profile.id]: true };
}
async function save() {
const savedProfiles = profiles.filter((profile) => saved[profile.id]);
if (savedProfiles.length === 0) {
toast.success($t('settings.saved'));
return;
}
saving = true;
try {
applyResponse(await updateAgents(savedProfiles.map(normalizeProfile)));
await refreshChatState();
toast.success($t('settings.saved'));
} catch (error) {
toast.error(error instanceof Error ? error.message : $t('admin.failedToSave'));
} finally {
saving = false;
}
}
async function refresh() {
refreshing = true;
try {
applyResponse(await refreshAgents());
await refreshChatState();
} catch {
toast.error($t('admin.failedToLoadConfig'));
} finally {
refreshing = false;
}
}
onMount(async () => {
try {
applyResponse(await getAgents());
} catch {
toast.error($t('admin.failedToLoadConfig'));
} finally {
loading = false;
}
});
</script>
<div class="flex flex-col min-h-full">
<div class="flex items-center justify-between mb-4">
<h2 class="text-sm font-medium text-gray-900 dark:text-white">{$t('admin.agents')}</h2>
<div class="flex items-center gap-1">
<button
class="flex items-center justify-center w-6 h-6 rounded-lg text-gray-400 hover:text-gray-700 dark:text-gray-600 dark:hover:text-gray-300 transition-colors duration-75 disabled:opacity-30"
onclick={refresh}
disabled={refreshing}
title={$t('admin.agentsRefresh')}
>
{#if refreshing}
<Spinner size={13} />
{:else}
<Icon name="refresh" size={13} />
{/if}
</button>
<button
class="flex items-center justify-center w-6 h-6 rounded-lg text-gray-400 hover:text-gray-700 dark:text-gray-600 dark:hover:text-gray-300 transition-colors duration-75"
onclick={() => (modal = { mode: 'create', profile: newProfile() })}
title={$t('admin.agentsAddProfile')}
>
<Icon name="plus" size={14} />
</button>
</div>
</div>
{#if loading}
<div class="flex justify-center py-8">
<Spinner size={16} />
</div>
{:else}
<div class="divide-y divide-gray-100 dark:divide-white/5">
{#each profiles as profile, index (profile.id)}
<button
class="group flex items-center gap-2 w-full min-h-9 py-1.5 text-left"
onclick={() => (modal = { mode: 'edit', index, profile })}
>
<span class="flex-1 min-w-0">
<span
class="block text-[13px] truncate {profile.mode === 'disabled'
? 'text-gray-400 dark:text-gray-600'
: 'text-gray-700 dark:text-gray-300'}"
>
{profile.name}
</span>
<span class="block text-[11px] text-gray-400 dark:text-gray-600 truncate">
{profileSubtitle(profile)}
</span>
{#if detected[profile.id]?.message}
<span class="block text-[11px] text-gray-300 dark:text-gray-700 truncate">
{detected[profile.id]?.message}
</span>
{/if}
</span>
<span
class="hidden sm:flex items-center gap-1.5 shrink-0 text-[11px] text-gray-400 dark:text-gray-600"
>
<span class="w-1.5 h-1.5 rounded-full {statusTone(profile)}"></span>
<span>{$t(statusKey(profile))}</span>
</span>
<!-- svelte-ignore a11y_no_static_element_interactions -->
<span
class="relative w-6 h-3.5 rounded-full shrink-0 cursor-pointer transition-colors duration-150
{profile.mode !== 'disabled' ? 'bg-gray-900 dark:bg-white' : 'bg-gray-200 dark:bg-gray-700'}"
role="switch"
tabindex="-1"
aria-checked={profile.mode !== 'disabled'}
onclick={(e) => toggleProfile(e, index)}
onkeydown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
toggleProfile(e, index);
}
}}
>
<span
class="absolute top-0.5 w-2.5 h-2.5 rounded-full transition-all duration-150
{profile.mode !== 'disabled'
? 'left-3 bg-white dark:bg-gray-900'
: 'left-0.5 bg-white dark:bg-gray-500'}"
></span>
</span>
</button>
{/each}
</div>
{#if profiles.length === 0}
<p class="text-[13px] text-gray-400 dark:text-gray-600 py-4">No agent profiles</p>
{/if}
<div class="mt-auto pt-6 flex items-center justify-between">
<span class="text-xs text-gray-500">
{profiles.length} profile{profiles.length === 1 ? '' : 's'}
</span>
<button
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100 disabled:opacity-50"
onclick={save}
disabled={saving}
>
{#if saving}
<Spinner size={14} />
{:else}
{$t('settings.save')}
{/if}
</button>
</div>
{/if}
</div>
{#if modal}
<AgentProfileModal
profile={modal.profile}
isNew={modal.mode === 'create'}
onclose={() => (modal = null)}
onsave={saveProfile}
ondelete={deleteProfile}
/>
{/if}
@@ -10,6 +10,7 @@
import About from './Settings/About.svelte';
import Users from './Admin/Users.svelte';
import Connections from './Admin/Connections.svelte';
import Agents from './Admin/Agents.svelte';
import Models from './Admin/Models.svelte';
import Messaging from './Admin/Messaging.svelte';
import Gateway from './Admin/Gateway.svelte';
@@ -30,6 +31,7 @@
| 'about'
| 'users'
| 'connections'
| 'agents'
| 'models'
| 'messaging'
| 'gateway'
@@ -56,6 +58,7 @@
const adminTabIds: Tab[] = [
'users',
'connections',
'agents',
'models',
'messaging',
'gateway',
@@ -81,6 +84,7 @@
const adminTabs: { id: Tab; label: string; icon: string }[] = $derived([
{ id: 'users', label: $t('admin.users'), icon: 'user' },
{ id: 'connections', label: $t('admin.connections'), icon: 'plug' },
{ id: 'agents', label: $t('admin.agents'), icon: 'terminal' },
{ id: 'models', label: $t('admin.models'), icon: 'cube' },
{ id: 'messaging', label: $t('admin.messaging'), icon: 'chat-bubble' },
{ id: 'gateway', label: $t('admin.gateway.tab'), icon: 'gateway' },
@@ -168,11 +172,11 @@
</nav>
<div class="flex-1 overflow-y-auto min-h-0 p-4 md:px-5">
{#if activeTab === 'general'}
<General />
{:else if activeTab === 'memory'}
<Memory />
{:else if activeTab === 'pwa' && showPwaSettings}
{#if activeTab === 'general'}
<General />
{:else if activeTab === 'memory'}
<Memory />
{:else if activeTab === 'pwa' && showPwaSettings}
<PWA />
{:else if activeTab === 'keyboard'}
<Keyboard />
@@ -184,6 +188,8 @@
<Users />
{:else if activeTab === 'connections'}
<Connections />
{:else if activeTab === 'agents'}
<Agents />
{:else if activeTab === 'models'}
<Models />
{:else if activeTab === 'messaging'}
@@ -235,6 +235,24 @@
"admin.minCharsPassword": "Min 6 characters",
"admin.connections": "Connections",
"admin.agents": "Agents",
"admin.agentsRefresh": "Refresh",
"admin.agentsAddProfile": "Add profile",
"admin.agentsDeleteProfile": "Delete",
"admin.agentsProfileName": "Name",
"admin.agentsProfileId": "Profile ID",
"admin.agentsType": "Agent",
"admin.agentsCommand": "Command",
"admin.agentsHome": "Home path",
"admin.agentsApprovalMode": "Approval mode",
"admin.agentsSandboxMode": "Sandbox",
"admin.agentsPermissionMode": "Permission mode",
"admin.agentsLaunchArgs": "Launch arguments",
"admin.agentsStatusReady": "Ready",
"admin.agentsStatusNotFound": "Not found",
"admin.agentsStatusMissingDependency": "Missing dependency",
"admin.agentsStatusAuthUnknown": "Auth unknown",
"admin.agentsStatusError": "Error",
"connections.loadError": "Failed to load connections",
"connections.fieldsRequired": "Base URL and API key required",