mirror of
https://github.com/open-webui/computer.git
synced 2026-12-04 02:28:04 -05:00
refac
This commit is contained in:
1 parent
5fcd0a6411
commit
391ac1f874
5 files changed
+369
-5
No files matched your search
@@ -15,7 +15,7 @@
|
||||
let { onclose, oncreated }: Props = $props();
|
||||
|
||||
let formName = $state('');
|
||||
let formProvider = $state<'anthropic' | 'openai'>('anthropic');
|
||||
let formProvider = $state<'openai' | 'anthropic'>('openai');
|
||||
let formApiType = $state<'chat_completions' | 'responses'>('chat_completions');
|
||||
let formBaseUrl = $state('');
|
||||
let formApiKey = $state('');
|
||||
@@ -94,8 +94,8 @@
|
||||
bind:value={formProvider}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer"
|
||||
>
|
||||
<option value="anthropic">Anthropic</option>
|
||||
<option value="openai">OpenAI</option>
|
||||
<option value="anthropic">Anthropic</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -130,8 +130,8 @@
|
||||
bind:value={formProvider}
|
||||
class="block w-full bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 cursor-pointer"
|
||||
>
|
||||
<option value="anthropic">Anthropic</option>
|
||||
<option value="openai">OpenAI</option>
|
||||
<option value="anthropic">Anthropic</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
<script lang="ts">
|
||||
import { goto } from '$app/navigation';
|
||||
import { toast } from 'svelte-sonner';
|
||||
|
||||
import { createConnection } from '$lib/apis/admin';
|
||||
import { refreshChatState } from '$lib/stores/chat';
|
||||
import { formatChord, keybindings } from '$lib/stores/keybindings';
|
||||
import { t } from '$lib/i18n';
|
||||
import { ApiError } from '$lib/apis';
|
||||
import DirectoryPicker from './DirectoryPicker.svelte';
|
||||
import Spinner from './common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
oncomplete: () => void;
|
||||
}
|
||||
|
||||
let { oncomplete }: Props = $props();
|
||||
|
||||
let step = $state(0);
|
||||
const totalSteps = 4;
|
||||
|
||||
// ── Step 2: Folder ──────────────────────────────────────────
|
||||
let selectedPath = $state('');
|
||||
let showPicker = $state(false);
|
||||
|
||||
// ── Step 3: AI connection ───────────────────────────────────
|
||||
let provider = $state<'openai' | 'anthropic'>('openai');
|
||||
let apiType = $state<'chat_completions' | 'responses'>('chat_completions');
|
||||
let baseUrl = $state('https://api.openai.com/v1');
|
||||
let apiKey = $state('');
|
||||
let connecting = $state(false);
|
||||
let aiConnected = $state(false);
|
||||
|
||||
const providerConfig = {
|
||||
openai: { name: 'OpenAI', baseUrl: 'https://api.openai.com/v1', placeholder: 'sk-...' },
|
||||
anthropic: { name: 'Anthropic', baseUrl: 'https://api.anthropic.com/v1', placeholder: 'sk-ant-...' }
|
||||
};
|
||||
|
||||
const config = $derived(providerConfig[provider]);
|
||||
|
||||
// Auto-fill base URL when provider changes
|
||||
$effect(() => {
|
||||
baseUrl = providerConfig[provider].baseUrl;
|
||||
});
|
||||
|
||||
function next() {
|
||||
if (step < totalSteps - 1) step++;
|
||||
}
|
||||
|
||||
function skipFolder() {
|
||||
next();
|
||||
}
|
||||
|
||||
async function connectAi() {
|
||||
if (!apiKey.trim()) return;
|
||||
connecting = true;
|
||||
try {
|
||||
await createConnection({
|
||||
name: config.name,
|
||||
provider,
|
||||
api_type: provider === 'openai' ? apiType : 'chat_completions',
|
||||
base_url: baseUrl.trim(),
|
||||
api_key: apiKey.trim()
|
||||
});
|
||||
await refreshChatState();
|
||||
aiConnected = true;
|
||||
next();
|
||||
} catch (e) {
|
||||
toast.error(e instanceof ApiError ? e.message : 'Connection failed');
|
||||
} finally {
|
||||
connecting = false;
|
||||
}
|
||||
}
|
||||
|
||||
function skipAi() {
|
||||
next();
|
||||
}
|
||||
|
||||
async function finish() {
|
||||
oncomplete();
|
||||
|
||||
if (selectedPath) {
|
||||
await goto(`/?workspace=${encodeURIComponent(selectedPath)}`);
|
||||
}
|
||||
}
|
||||
|
||||
let searchShortcut = $derived(formatChord($keybindings.quickOpen));
|
||||
</script>
|
||||
|
||||
<div class="flex items-center justify-center h-dvh bg-white dark:bg-black p-6">
|
||||
<div class="w-full max-w-md">
|
||||
<!-- Progress dots -->
|
||||
<div class="flex gap-1.5 mb-6">
|
||||
{#each Array(totalSteps) as _, i}
|
||||
<div
|
||||
class="h-0.5 flex-1 rounded-full transition-colors duration-200
|
||||
{i <= step ? 'bg-gray-900 dark:bg-white' : 'bg-gray-200 dark:bg-white/8'}"
|
||||
></div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
{#if step === 0}
|
||||
<!-- Welcome -->
|
||||
<div class="animate-in">
|
||||
<h1 class="text-lg tracking-tight text-gray-900 dark:text-white mb-1">
|
||||
{$t('onboarding.welcomeTitle')}
|
||||
</h1>
|
||||
<p class="text-[13px] text-gray-500 dark:text-gray-500 mb-6 leading-relaxed">
|
||||
{$t('onboarding.welcomeDesc')}
|
||||
</p>
|
||||
|
||||
<button
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100"
|
||||
onclick={next}
|
||||
>
|
||||
{$t('onboarding.getStarted')}
|
||||
</button>
|
||||
</div>
|
||||
{:else if step === 1}
|
||||
<!-- Open folder -->
|
||||
<div class="animate-in">
|
||||
<h2 class="text-xs text-gray-400 dark:text-gray-600 mb-1">
|
||||
{$t('onboarding.openFolder')}
|
||||
</h2>
|
||||
<p class="text-[13px] text-gray-500 dark:text-gray-500 mb-4 leading-relaxed">
|
||||
{$t('onboarding.openFolderDesc')}
|
||||
</p>
|
||||
|
||||
{#if selectedPath}
|
||||
<p class="text-[12px] font-mono text-gray-700 dark:text-gray-300 mb-3">
|
||||
{selectedPath}
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
<button
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100"
|
||||
onclick={() => (showPicker = true)}
|
||||
>
|
||||
{$t('onboarding.openFolder')}
|
||||
</button>
|
||||
|
||||
<div class="mt-4">
|
||||
<button
|
||||
class="text-[11px] text-gray-400 dark:text-gray-600 hover:text-gray-500 dark:hover:text-gray-400 transition-colors duration-100"
|
||||
onclick={skipFolder}
|
||||
>
|
||||
{$t('onboarding.skip')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{:else if step === 2}
|
||||
<!-- Connect AI -->
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div class="animate-in" onkeydown={(e) => { if (e.key === 'Enter' && apiKey.trim()) connectAi(); }}>
|
||||
<h2 class="text-xs text-gray-400 dark:text-gray-600 mb-1">
|
||||
{$t('onboarding.connectAi')}
|
||||
</h2>
|
||||
<p class="text-[13px] text-gray-500 dark:text-gray-500 mb-4 leading-relaxed">
|
||||
{$t('onboarding.connectAiDesc')}
|
||||
</p>
|
||||
|
||||
{#if aiConnected}
|
||||
<p class="text-[13px] text-gray-700 dark:text-gray-300 mb-4">
|
||||
{config.name} connected
|
||||
</p>
|
||||
<button
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100"
|
||||
onclick={next}
|
||||
>
|
||||
{$t('tour.next')}
|
||||
</button>
|
||||
{:else}
|
||||
<div class="mb-3">
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mb-0.5">Provider</p>
|
||||
<select
|
||||
bind:value={provider}
|
||||
class="bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 border-none cursor-pointer"
|
||||
>
|
||||
<option value="openai">OpenAI</option>
|
||||
<option value="anthropic">Anthropic</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{#if provider === 'openai'}
|
||||
<div class="mb-3">
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mb-0.5">API Type</p>
|
||||
<select
|
||||
bind:value={apiType}
|
||||
class="bg-transparent text-[13px] text-gray-700 dark:text-gray-300 outline-none py-0.5 border-none cursor-pointer"
|
||||
>
|
||||
<option value="chat_completions">Chat Completions</option>
|
||||
<option value="responses">Responses</option>
|
||||
</select>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="mb-3">
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mb-0.5">{$t('connections.baseUrl')}</p>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="https://api.openai.com/v1"
|
||||
bind:value={baseUrl}
|
||||
autocomplete="off"
|
||||
spellcheck="false"
|
||||
list="setup-base-url-suggestions"
|
||||
class="block w-full bg-transparent text-[13px] font-mono text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-0.5"
|
||||
/>
|
||||
<datalist id="setup-base-url-suggestions">
|
||||
<option value="https://api.openai.com/v1" />
|
||||
<option value="https://api.anthropic.com/v1" />
|
||||
<option value="https://openrouter.ai/api/v1" />
|
||||
<option value="http://localhost:11434/v1" />
|
||||
</datalist>
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mb-0.5">{$t('connections.apiKey')}</p>
|
||||
<input
|
||||
type="password"
|
||||
placeholder={config.placeholder}
|
||||
bind:value={apiKey}
|
||||
autocomplete="new-password"
|
||||
class="block w-full bg-transparent text-[13px] font-mono text-gray-700 dark:text-gray-300 placeholder:text-gray-300 dark:placeholder:text-gray-700 outline-none py-1"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<p class="text-[11px] text-gray-400 dark:text-gray-600 mb-4">
|
||||
{$t('onboarding.keyStaysLocal')}
|
||||
</p>
|
||||
|
||||
<button
|
||||
class="flex items-center gap-2 text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100
|
||||
disabled:opacity-30 disabled:pointer-events-none"
|
||||
onclick={connectAi}
|
||||
disabled={connecting || !apiKey.trim()}
|
||||
>
|
||||
{#if connecting}
|
||||
<Spinner size={14} />
|
||||
{:else}
|
||||
{$t('onboarding.connect')}
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<div class="mt-4">
|
||||
<button
|
||||
class="text-[11px] text-gray-400 dark:text-gray-600 hover:text-gray-500 dark:hover:text-gray-400 transition-colors duration-100"
|
||||
onclick={skipAi}
|
||||
>
|
||||
{$t('onboarding.connectAiSkip')}
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{:else if step === 3}
|
||||
<!-- Ready -->
|
||||
<div class="animate-in">
|
||||
<h2 class="text-xs text-gray-400 dark:text-gray-600 mb-1">
|
||||
{$t('onboarding.ready')}
|
||||
</h2>
|
||||
<p class="text-[13px] text-gray-500 dark:text-gray-500 mb-5 leading-relaxed">
|
||||
{$t('onboarding.readyDesc')}
|
||||
</p>
|
||||
|
||||
<div class="flex flex-col gap-1.5 mb-6">
|
||||
<p class="text-[12px] text-gray-500 dark:text-gray-500">
|
||||
{$t('onboarding.tipSearch', { shortcut: searchShortcut })}
|
||||
</p>
|
||||
<p class="text-[12px] text-gray-500 dark:text-gray-500">
|
||||
{$t('onboarding.tipTerminal')}
|
||||
</p>
|
||||
<p class="text-[12px] text-gray-500 dark:text-gray-500">
|
||||
{$t('onboarding.tipMobile')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="text-[13px] text-gray-600 dark:text-gray-400 hover:text-gray-900 dark:hover:text-white transition-colors duration-100"
|
||||
onclick={finish}
|
||||
>
|
||||
{$t('onboarding.startUsing')}
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if showPicker}
|
||||
<DirectoryPicker
|
||||
onclose={() => {
|
||||
showPicker = false;
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const wsPath = params.get('workspace');
|
||||
if (wsPath) {
|
||||
selectedPath = wsPath;
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.delete('workspace');
|
||||
window.history.replaceState({}, '', url.toString());
|
||||
next();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.animate-in {
|
||||
animation: fadeIn 0.15s ease-out;
|
||||
}
|
||||
|
||||
@keyframes fadeIn {
|
||||
from {
|
||||
opacity: 0;
|
||||
transform: translateY(4px);
|
||||
}
|
||||
to {
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -70,7 +70,7 @@
|
||||
"files.date": "Date",
|
||||
"files.folder": "folder",
|
||||
"files.file": "file",
|
||||
"files.clickToPreview": "{{process}} — click to preview",
|
||||
"files.clickToPreview": "{{process}} - click to preview",
|
||||
"files.showHidden": "Show dotfiles",
|
||||
"files.hideHidden": "Hide dotfiles",
|
||||
"files.failedToLoad": "Failed to load directory",
|
||||
@@ -723,6 +723,31 @@
|
||||
"admin.contextCompaction": "Context compaction",
|
||||
"admin.compactTokenThreshold": "Token threshold",
|
||||
"admin.compactTokenThresholdUnit": "tokens",
|
||||
"admin.compactTokenThresholdHint": "Older messages are summarized when estimated context exceeds this limit. Default: 80,000."
|
||||
"admin.compactTokenThresholdHint": "Older messages are summarized when estimated context exceeds this limit. Default: 80,000.",
|
||||
|
||||
"onboarding.welcomeTitle": "Your computer, from anywhere",
|
||||
"onboarding.welcomeDesc": "Code, manage, and control your machine from any device.",
|
||||
"onboarding.getStarted": "Get started →",
|
||||
"onboarding.openFolder": "Open a folder",
|
||||
"onboarding.openFolderDesc": "Pick a project or folder to work with.",
|
||||
"onboarding.skip": "Skip",
|
||||
"onboarding.connectAi": "Connect AI",
|
||||
"onboarding.connectAiDesc": "Add an API key to unlock chat, code editing, and automations.",
|
||||
"onboarding.connectAiSkip": "I'll do this later",
|
||||
"onboarding.keyStaysLocal": "Your key stays on this machine.",
|
||||
"onboarding.connect": "Connect →",
|
||||
"onboarding.ready": "You're all set",
|
||||
"onboarding.readyDesc": "A few things to try:",
|
||||
"onboarding.tipSearch": "Search for anything with {{shortcut}}",
|
||||
"onboarding.tipTerminal": "Open a terminal right in the browser",
|
||||
"onboarding.tipMobile": "Works on your phone, same URL",
|
||||
"onboarding.startUsing": "Start →",
|
||||
"onboarding.takeTour": "Take the tour",
|
||||
"onboarding.suggestion1": "Explain this project",
|
||||
"onboarding.suggestion2": "Find all TODOs",
|
||||
"onboarding.suggestion3": "What files are here?",
|
||||
"onboarding.suggestion4": "Help me write tests",
|
||||
"onboarding.connectAiNudge": "Connect an AI provider to start chatting.",
|
||||
"onboarding.goToConnections": "Settings → Connections"
|
||||
}
|
||||
|
||||
@@ -43,10 +43,12 @@
|
||||
import { t } from '$lib/i18n';
|
||||
import { refreshChatState, bindGlobalChatListener } from '$lib/stores/chat';
|
||||
import { refreshAudioState } from '$lib/stores/audio';
|
||||
import SetupWizard from '$lib/components/SetupWizard.svelte';
|
||||
|
||||
let { children } = $props();
|
||||
let showSettings = $state(false);
|
||||
let showUpdateToast = $state(false);
|
||||
let showSetup = $state(false);
|
||||
|
||||
// Auth state
|
||||
type AuthState = 'checking' | 'needs_setup' | 'needs_login' | 'authenticated';
|
||||
@@ -117,6 +119,20 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Check ?setup=true param for admin setup wizard
|
||||
$effect(() => {
|
||||
if (!$stateLoaded) return;
|
||||
if (authState !== 'authenticated') return;
|
||||
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
if (params.get('setup') === 'true' && $session?.role === 'admin') {
|
||||
showSetup = true;
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.delete('setup');
|
||||
window.history.replaceState({}, '', url.toString());
|
||||
}
|
||||
});
|
||||
|
||||
async function checkAuth() {
|
||||
try {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
@@ -167,6 +183,7 @@
|
||||
}
|
||||
|
||||
async function handleAuth() {
|
||||
const wasSetup = authState === 'needs_setup';
|
||||
try {
|
||||
const auth = await getSession();
|
||||
if (auth.authenticated) {
|
||||
@@ -181,6 +198,7 @@
|
||||
initState();
|
||||
refreshChatState();
|
||||
refreshAudioState();
|
||||
if (wasSetup) showSetup = true;
|
||||
return;
|
||||
}
|
||||
} catch {}
|
||||
@@ -299,6 +317,8 @@
|
||||
token={startupToken}
|
||||
onauth={handleAuth}
|
||||
/>
|
||||
{:else if $stateLoaded && showSetup}
|
||||
<SetupWizard oncomplete={() => { showSetup = false; }} />
|
||||
{:else if $stateLoaded}
|
||||
<div
|
||||
class="h-screen max-h-[100dvh] flex overflow-hidden font-sans antialiased text-gray-900 bg-white dark:text-gray-100 dark:bg-black"
|
||||
|
||||
Reference in new issue
Block a user