mirror of
https://github.com/open-webui/computer.git
synced 2026-12-04 18:47:57 -05:00
refac
This commit is contained in:
1 parent
e92b376036
commit
3610efd5d0
12 files changed
+1321
-62
No files matched your search
@@ -60,7 +60,7 @@ export const updateConfig = (config: Record<string, unknown>) =>
|
||||
|
||||
// ── Agents ─────────────────────────────────────────────────
|
||||
|
||||
export type AgentType = 'codex' | 'claude_code';
|
||||
export type AgentType = 'codex' | 'claude_code' | 'cursor' | 'grok' | 'opencode';
|
||||
export type AgentMode = 'auto' | 'enabled' | 'disabled';
|
||||
export type AgentStatus = 'ready' | 'not_found' | 'missing_dependency' | 'auth_unknown' | 'error';
|
||||
|
||||
@@ -77,6 +77,9 @@ export interface AgentProfile {
|
||||
sandbox_mode?: 'read-only' | 'workspace-write' | 'danger-full-access';
|
||||
permission_mode?: 'default' | 'accept_edits' | 'bypass_permissions';
|
||||
launch_args?: string;
|
||||
api_endpoint?: string;
|
||||
server_url?: string;
|
||||
server_password?: string;
|
||||
}
|
||||
|
||||
export interface AgentsResponseProfile {
|
||||
|
||||
@@ -17,33 +17,49 @@
|
||||
// svelte-ignore state_referenced_locally
|
||||
let draft = $state<AgentProfile>({
|
||||
...profile,
|
||||
models: [...(profile.models?.length ? profile.models : ['default'])]
|
||||
models: [...(profile.models?.length ? profile.models : [])]
|
||||
});
|
||||
|
||||
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];
|
||||
const models = currentModels.filter((model) => model !== 'default');
|
||||
const defaultModel = 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'),
|
||||
command: draft.command.trim() || defaultCommand(draft.agent),
|
||||
home: draft.home?.trim() || null,
|
||||
models,
|
||||
default_model: defaultModel,
|
||||
launch_args: draft.launch_args?.trim() || ''
|
||||
launch_args: draft.launch_args?.trim() || '',
|
||||
api_endpoint: draft.api_endpoint?.trim() || '',
|
||||
server_url: draft.server_url?.trim() || '',
|
||||
server_password: draft.server_password?.trim() || ''
|
||||
};
|
||||
}
|
||||
|
||||
function defaultCommand(agent: AgentProfile['agent']): string {
|
||||
return {
|
||||
codex: 'codex',
|
||||
claude_code: 'claude',
|
||||
cursor: 'agent',
|
||||
grok: 'grok',
|
||||
opencode: 'opencode'
|
||||
}[agent];
|
||||
}
|
||||
|
||||
function defaultName(agent: AgentProfile['agent']): string {
|
||||
return {
|
||||
codex: 'Codex',
|
||||
claude_code: 'Claude Code',
|
||||
cursor: 'Cursor',
|
||||
grok: 'Grok',
|
||||
opencode: 'OpenCode'
|
||||
}[agent];
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal {onclose} class="w-full max-w-md mx-4">
|
||||
@@ -89,14 +105,14 @@
|
||||
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';
|
||||
const agent = e.currentTarget.value as AgentProfile['agent'];
|
||||
draft = {
|
||||
...draft,
|
||||
agent,
|
||||
command: agent === 'codex' ? 'codex' : 'claude',
|
||||
models: [defaultModel],
|
||||
default_model: defaultModel,
|
||||
name: defaultName(agent),
|
||||
command: defaultCommand(agent),
|
||||
models: [],
|
||||
default_model: '',
|
||||
approval_mode: draft.approval_mode || 'auto',
|
||||
sandbox_mode: draft.sandbox_mode || 'workspace-write',
|
||||
permission_mode: draft.permission_mode || 'default',
|
||||
@@ -107,6 +123,9 @@
|
||||
>
|
||||
<option value="codex">Codex</option>
|
||||
<option value="claude_code">Claude Code</option>
|
||||
<option value="cursor">Cursor</option>
|
||||
<option value="grok">Grok</option>
|
||||
<option value="opencode">OpenCode</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -130,7 +149,7 @@
|
||||
id={`${fieldPrefix}-command`}
|
||||
type="text"
|
||||
bind:value={draft.command}
|
||||
placeholder={draft.agent === 'codex' ? 'codex' : 'claude'}
|
||||
placeholder={defaultCommand(draft.agent)}
|
||||
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"
|
||||
@@ -167,6 +186,58 @@
|
||||
/>
|
||||
{/if}
|
||||
|
||||
{#if draft.agent === 'cursor'}
|
||||
<label
|
||||
for={`${fieldPrefix}-api-endpoint`}
|
||||
class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
|
||||
>
|
||||
{$t('admin.agentsApiEndpoint')}
|
||||
</label>
|
||||
<input
|
||||
id={`${fieldPrefix}-api-endpoint`}
|
||||
type="text"
|
||||
bind:value={draft.api_endpoint}
|
||||
placeholder="Optional"
|
||||
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}
|
||||
|
||||
{#if draft.agent === 'opencode'}
|
||||
<label
|
||||
for={`${fieldPrefix}-server-url`}
|
||||
class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
|
||||
>
|
||||
{$t('admin.agentsServerUrl')}
|
||||
</label>
|
||||
<input
|
||||
id={`${fieldPrefix}-server-url`}
|
||||
type="text"
|
||||
bind:value={draft.server_url}
|
||||
placeholder="Optional"
|
||||
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}-server-password`}
|
||||
class="text-[10px] text-gray-400 dark:text-gray-600 mt-2"
|
||||
>
|
||||
{$t('admin.agentsServerPassword')}
|
||||
</label>
|
||||
<input
|
||||
id={`${fieldPrefix}-server-password`}
|
||||
type="password"
|
||||
bind:value={draft.server_password}
|
||||
placeholder="Optional"
|
||||
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}
|
||||
|
||||
@@ -37,19 +37,22 @@
|
||||
|
||||
function normalizeProfile(profile: AgentProfile): AgentProfile {
|
||||
const models = profile.models?.map((m) => m.trim()).filter(Boolean);
|
||||
const nextModels = models.length ? models : ['default'];
|
||||
const nextModels = models.length ? models : [];
|
||||
const defaultModel = nextModels.includes(profile.default_model)
|
||||
? profile.default_model
|
||||
: nextModels[0];
|
||||
: nextModels[0] || '';
|
||||
return {
|
||||
...profile,
|
||||
id: profile.id.trim(),
|
||||
name: profile.name.trim() || profile.id.trim(),
|
||||
command: profile.command.trim() || (profile.agent === 'codex' ? 'codex' : 'claude'),
|
||||
command: profile.command.trim() || defaultCommand(profile.agent),
|
||||
home: profile.home?.trim() || null,
|
||||
models: nextModels,
|
||||
default_model: defaultModel,
|
||||
launch_args: profile.launch_args?.trim() || ''
|
||||
launch_args: profile.launch_args?.trim() || '',
|
||||
api_endpoint: profile.api_endpoint?.trim() || '',
|
||||
server_url: profile.server_url?.trim() || '',
|
||||
server_password: profile.server_password?.trim() || ''
|
||||
};
|
||||
}
|
||||
|
||||
@@ -60,9 +63,8 @@
|
||||
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';
|
||||
function newProfile(agent: AgentProfile['agent'] = 'codex'): AgentProfile {
|
||||
const base = defaultProfileId(agent);
|
||||
let suffix = profiles.length + 1;
|
||||
let id = `${base}-${suffix}`;
|
||||
while (profiles.some((p) => p.id === id)) {
|
||||
@@ -72,25 +74,57 @@
|
||||
return {
|
||||
id,
|
||||
agent,
|
||||
name: agent === 'codex' ? 'Codex' : 'Claude Code',
|
||||
name: agentLabel(agent),
|
||||
mode: 'enabled',
|
||||
command: agent === 'codex' ? 'codex' : 'claude',
|
||||
command: defaultCommand(agent),
|
||||
home: null,
|
||||
models: [defaultModel],
|
||||
default_model: defaultModel,
|
||||
models: [],
|
||||
default_model: '',
|
||||
approval_mode: 'auto',
|
||||
sandbox_mode: 'workspace-write',
|
||||
permission_mode: 'default',
|
||||
launch_args: ''
|
||||
launch_args: '',
|
||||
api_endpoint: '',
|
||||
server_url: '',
|
||||
server_password: ''
|
||||
};
|
||||
}
|
||||
|
||||
function profileSubtitle(profile: AgentProfile): string {
|
||||
const modelCount = profile.models?.length || 0;
|
||||
const modelLabel = modelCount === 1 ? profile.default_model : `${modelCount} models`;
|
||||
const modelLabel =
|
||||
modelCount === 0
|
||||
? 'auto-detect'
|
||||
: modelCount === 1
|
||||
? profile.default_model
|
||||
: `${modelCount} models`;
|
||||
return `agent:${profile.id} · ${modelLabel}`;
|
||||
}
|
||||
|
||||
function defaultProfileId(agent: AgentProfile['agent']): string {
|
||||
return agent === 'claude_code' ? 'claude-code' : agent;
|
||||
}
|
||||
|
||||
function defaultCommand(agent: AgentProfile['agent']): string {
|
||||
return {
|
||||
codex: 'codex',
|
||||
claude_code: 'claude',
|
||||
cursor: 'agent',
|
||||
grok: 'grok',
|
||||
opencode: 'opencode'
|
||||
}[agent];
|
||||
}
|
||||
|
||||
function agentLabel(agent: AgentProfile['agent']): string {
|
||||
return {
|
||||
codex: 'Codex',
|
||||
claude_code: 'Claude Code',
|
||||
cursor: 'Cursor',
|
||||
grok: 'Grok',
|
||||
opencode: 'OpenCode'
|
||||
}[agent];
|
||||
}
|
||||
|
||||
function statusKey(profile: AgentProfile): string {
|
||||
return statusLabelKey[detected[profile.id]?.status || 'error'] || statusLabelKey.error;
|
||||
}
|
||||
|
||||
@@ -248,6 +248,9 @@
|
||||
"admin.agentsSandboxMode": "Sandbox",
|
||||
"admin.agentsPermissionMode": "Permission mode",
|
||||
"admin.agentsLaunchArgs": "Launch arguments",
|
||||
"admin.agentsApiEndpoint": "API endpoint",
|
||||
"admin.agentsServerUrl": "Server URL",
|
||||
"admin.agentsServerPassword": "Server password",
|
||||
"admin.agentsStatusReady": "Ready",
|
||||
"admin.agentsStatusNotFound": "Not found",
|
||||
"admin.agentsStatusMissingDependency": "Missing dependency",
|
||||
|
||||
Reference in new issue
Block a user