mirror of
https://github.com/open-webui/computer.git
synced 2026-11-23 22:11:29 -05:00
refac
This commit is contained in:
1 parent
cbb33f091a
commit
d99169d94e
29 files changed
+219
-165
No files matched your search
@@ -25,6 +25,7 @@ export interface ChatInfo {
|
||||
current_message_id: string | null;
|
||||
created_at: number;
|
||||
updated_at: number;
|
||||
is_active?: boolean;
|
||||
}
|
||||
|
||||
export interface ChatDetail {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import { listConnections, updateConnection, type Connection } from '$lib/apis/admin';
|
||||
import { refreshChatState } from '$lib/stores/chat';
|
||||
import { t } from '$lib/i18n';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
let connections = $state<Connection[]>([]);
|
||||
let loading = $state(true);
|
||||
@@ -66,9 +67,7 @@
|
||||
|
||||
{#if loading}
|
||||
<div class="flex justify-center py-8">
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={16} />
|
||||
</div>
|
||||
{:else}
|
||||
<div>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { ApiError } from '$lib/apis';
|
||||
import { refreshChatState } from '$lib/stores/chat';
|
||||
import { t } from '$lib/i18n';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
onclose: () => void;
|
||||
@@ -171,9 +172,7 @@
|
||||
class="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"
|
||||
>
|
||||
{#if creating}
|
||||
<div
|
||||
class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={14} />
|
||||
{:else}
|
||||
{$t('connections.add')} →
|
||||
{/if}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import { createUser as apiCreateUser } from '$lib/apis/admin';
|
||||
import { ApiError } from '$lib/apis';
|
||||
import { t } from '$lib/i18n';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
onclose: () => void;
|
||||
@@ -96,9 +97,7 @@
|
||||
class="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"
|
||||
>
|
||||
{#if creating}
|
||||
<div
|
||||
class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={14} />
|
||||
{:else}
|
||||
{$t('admin.create')}
|
||||
{/if}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
import { ApiError } from '$lib/apis';
|
||||
import { refreshChatState } from '$lib/stores/chat';
|
||||
import { t } from '$lib/i18n';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
connection: Connection;
|
||||
@@ -212,9 +213,7 @@
|
||||
onclick={handleVerify}
|
||||
>
|
||||
{#if verifying}
|
||||
<div
|
||||
class="w-3 h-3 border border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={12} />
|
||||
{:else}
|
||||
{$t('connections.verify') || 'Verify'}
|
||||
{/if}
|
||||
@@ -226,9 +225,7 @@
|
||||
class="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"
|
||||
>
|
||||
{#if saving}
|
||||
<div
|
||||
class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={14} />
|
||||
{:else}
|
||||
{$t('settings.save') || 'Save'} →
|
||||
{/if}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import { getAdminConfig, updateConfig as apiUpdateConfig } from '$lib/apis/admin';
|
||||
import { t } from '$lib/i18n';
|
||||
import ToggleSwitch from '$lib/components/ToggleSwitch.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
let config = $state<Record<string, any>>({});
|
||||
let loading = $state(true);
|
||||
@@ -54,9 +55,7 @@
|
||||
|
||||
{#if loading}
|
||||
<div class="flex justify-center py-8">
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={16} />
|
||||
</div>
|
||||
{:else}
|
||||
<!-- Auth settings -->
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import { listUsers } from '$lib/apis/admin';
|
||||
import { session } from '$lib/session';
|
||||
import { t } from '$lib/i18n';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
interface User {
|
||||
user_id: string;
|
||||
@@ -66,9 +67,7 @@
|
||||
|
||||
{#if loading}
|
||||
<div class="flex justify-center py-8">
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={16} />
|
||||
</div>
|
||||
{:else}
|
||||
<div>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { login, setup, signup } from '$lib/apis/auth';
|
||||
import { ApiError } from '$lib/apis';
|
||||
import { t } from '$lib/i18n';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
mode: 'password' | 'pam';
|
||||
@@ -111,9 +112,7 @@
|
||||
disabled:opacity-30 disabled:pointer-events-none mt-2"
|
||||
>
|
||||
{#if loading}
|
||||
<div
|
||||
class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={14} />
|
||||
{:else}
|
||||
{isSetup
|
||||
? $t('auth.createAccountBtn')
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import Modal from './Modal.svelte';
|
||||
import Icon from './Icon.svelte';
|
||||
import { appVersion, lastSeenVersion, showChangelog } from '$lib/stores';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
type ChangelogEntry = { title: string; content: string; raw: string };
|
||||
type VersionData = { date: string; [section: string]: string | ChangelogEntry[] };
|
||||
@@ -147,9 +148,7 @@
|
||||
</div>
|
||||
{:else}
|
||||
<div class="flex flex-col items-center justify-center py-16 gap-3">
|
||||
<div
|
||||
class="h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400"
|
||||
></div>
|
||||
<Spinner size={16} />
|
||||
<span class="text-[11px] text-gray-400 dark:text-gray-600">Loading release notes...</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
import { listDir } from '$lib/apis/files';
|
||||
import Icon from './Icon.svelte';
|
||||
import { t } from '$lib/i18n';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
onclose: () => void;
|
||||
@@ -317,9 +318,7 @@
|
||||
placeholder={$t('directory.typePath')}
|
||||
/>
|
||||
{#if pathValid === 'checking'}
|
||||
<div
|
||||
class="w-3 h-3 border-[1.5px] border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin shrink-0"
|
||||
></div>
|
||||
<Spinner size={12} />
|
||||
{:else if pathValid === 'valid'}
|
||||
<span class="text-green-500 shrink-0 flex"><Icon name="check" size={12} /></span>
|
||||
{:else if pathValid === 'invalid'}
|
||||
@@ -384,9 +383,7 @@
|
||||
<div bind:this={listEl} class="flex-1 overflow-y-auto p-1 min-h-0">
|
||||
{#if loading}
|
||||
<div class="flex items-center justify-center py-8">
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={16} />
|
||||
</div>
|
||||
{:else if error}
|
||||
<div class="flex flex-col items-center justify-center gap-2 py-8 text-center">
|
||||
|
||||
@@ -761,9 +761,7 @@
|
||||
|
||||
{#if loading && initialLoad}
|
||||
<div class="flex items-center justify-center py-12">
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={16} />
|
||||
</div>
|
||||
{:else if error}
|
||||
<div class="flex flex-col items-center justify-center py-12 gap-2">
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import HtmlPreview from './preview/HtmlPreview.svelte';
|
||||
import SvgPreview from './preview/SvgPreview.svelte';
|
||||
import OfficePreview from './preview/OfficePreview.svelte';
|
||||
import Spinner from './common/Spinner.svelte';
|
||||
import { EditorState } from '@codemirror/state';
|
||||
import {
|
||||
EditorView,
|
||||
@@ -173,7 +174,7 @@
|
||||
if (type === 'added')
|
||||
return 'bg-green-100 border-l-[3px] border-l-green-500 dark:bg-green-500/15 dark:border-l-green-400';
|
||||
if (type === 'removed')
|
||||
return 'bg-red-100 border-l-[3px] border-l-red-400 dark:bg-red-500/15 dark:border-l-red-400';
|
||||
return 'bg-red-100 diff-gutter-removed dark:bg-red-500/15';
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -733,7 +734,7 @@
|
||||
|
||||
<div class="editor-area">
|
||||
{#if loading}
|
||||
<div class="state"><div class="spinner"></div></div>
|
||||
<div class="state"><Spinner size={20} /></div>
|
||||
{:else if error}
|
||||
<div class="state error">{error}</div>
|
||||
|
||||
@@ -799,7 +800,7 @@
|
||||
{:else if diffMode}
|
||||
<!-- Diff view -->
|
||||
{#if diffLoading}
|
||||
<div class="state"><div class="spinner"></div></div>
|
||||
<div class="state"><Spinner size={20} /></div>
|
||||
{:else if diffFiles.length === 0}
|
||||
<div class="state">
|
||||
<p class="state-title">No changes</p>
|
||||
@@ -1035,20 +1036,7 @@
|
||||
color: var(--color-gray-500);
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid var(--color-gray-700);
|
||||
border-top-color: var(--color-gray-400);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.6s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Diff view ────────────────────────────────────────── */
|
||||
|
||||
@@ -1132,4 +1120,16 @@
|
||||
:global(.dark) .diff-ctx .diff-prefix {
|
||||
color: var(--color-gray-600);
|
||||
}
|
||||
|
||||
.diff-gutter-removed {
|
||||
border-left: 3px solid transparent;
|
||||
border-image: repeating-linear-gradient(
|
||||
-45deg,
|
||||
#ef4444 0,
|
||||
#ef4444 1px,
|
||||
transparent 1px,
|
||||
transparent 3px
|
||||
)
|
||||
3;
|
||||
}
|
||||
</style>
|
||||
@@ -19,6 +19,7 @@
|
||||
import DropdownMenu from './DropdownMenu.svelte';
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import { t } from '$lib/i18n';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
type GitFile = { path: string; status: string; staged: boolean };
|
||||
type DiffHunk = { header: string; lines: { type: string; content: string }[] };
|
||||
@@ -527,9 +528,7 @@
|
||||
{/each}
|
||||
{:else}
|
||||
<div class="flex items-center justify-center h-10">
|
||||
<div
|
||||
class="w-3.5 h-3.5 border border-gray-300 dark:border-gray-600 border-t-gray-600 dark:border-t-gray-300 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={14} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import Icon from './Icon.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
|
||||
type DiffLine = { type: 'added' | 'removed' | 'context'; content: string };
|
||||
@@ -259,9 +260,7 @@
|
||||
>
|
||||
{#if loading && !gitStatus}
|
||||
<div class="flex h-full items-center justify-center">
|
||||
<div
|
||||
class="h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400"
|
||||
></div>
|
||||
<Spinner size={16} />
|
||||
</div>
|
||||
{:else if error && !gitStatus}
|
||||
<div class="flex h-full flex-col items-center justify-center gap-2 px-6 text-center">
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
import { chatEnabled, streamingChatTabs } from '$lib/stores/chat';
|
||||
import { keybindings, formatChord } from '$lib/stores/keybindings';
|
||||
import Icon from './Icon.svelte';
|
||||
import Spinner from './common/Spinner.svelte';
|
||||
import DropdownMenu from './DropdownMenu.svelte';
|
||||
import { tooltip } from '$lib/tooltip';
|
||||
import { t } from '$lib/i18n';
|
||||
@@ -289,7 +290,7 @@
|
||||
oncontextmenu={(e) => handleContextMenu(e, tab)}
|
||||
>
|
||||
{#if tab.type === 'chat' && $streamingChatTabs.has(tab.id)}
|
||||
<span class="tab-spinner" style="width: 14px; height: 14px;"></span>
|
||||
<Spinner size={14} />
|
||||
{:else}
|
||||
<Icon name={tabIconName(tab)} size={14} />
|
||||
{/if}
|
||||
@@ -401,19 +402,5 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
.tab-spinner {
|
||||
display: inline-block;
|
||||
border: 2px solid currentColor;
|
||||
border-top-color: transparent;
|
||||
border-radius: 50%;
|
||||
animation: tab-spin 0.8s linear infinite;
|
||||
opacity: 0.7;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@keyframes tab-spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -3,6 +3,7 @@
|
||||
import { getWelcome } from '$lib/apis/state';
|
||||
import { listDir } from '$lib/apis/files';
|
||||
import { t } from '$lib/i18n';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
defaultName?: string;
|
||||
@@ -175,9 +176,7 @@
|
||||
<div bind:this={listEl} class="flex-1 overflow-y-auto p-1 min-h-0">
|
||||
{#if loading}
|
||||
<div class="flex items-center justify-center py-8">
|
||||
<div
|
||||
class="w-4 h-4 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={16} />
|
||||
</div>
|
||||
{:else if error}
|
||||
<div class="flex flex-col items-center justify-center gap-2 py-8 text-center">
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
import { ApiError } from '$lib/apis';
|
||||
import { session, setSession } from '$lib/session';
|
||||
import { t } from '$lib/i18n';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
let currentPassword = $state('');
|
||||
let newPassword = $state('');
|
||||
@@ -136,9 +137,7 @@
|
||||
disabled={uploadingAvatar}
|
||||
>
|
||||
{#if uploadingAvatar}
|
||||
<div
|
||||
class="w-5 h-5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={20} />
|
||||
{:else}
|
||||
<img src={avatarUrl || '/user.png'} alt="Avatar" class="w-full h-full object-cover" />
|
||||
<div
|
||||
@@ -219,9 +218,7 @@
|
||||
disabled:opacity-30 disabled:pointer-events-none"
|
||||
>
|
||||
{#if updatingPassword}
|
||||
<div
|
||||
class="w-3.5 h-3.5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={14} />
|
||||
{:else}
|
||||
{$t('account.updatePassword')}
|
||||
{/if}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import type { ChatInfo } from '$lib/apis/chat';
|
||||
import DropdownMenu from '../DropdownMenu.svelte';
|
||||
import Pagination from '../common/Pagination.svelte';
|
||||
import Spinner from '../common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
chats: ChatInfo[];
|
||||
@@ -136,6 +137,9 @@
|
||||
if (e.key === 'Enter') onopen(chat.id);
|
||||
}}
|
||||
>
|
||||
{#if chat.is_active}
|
||||
<Spinner size={10} borderWidth={1.5} class="opacity-50" />
|
||||
{/if}
|
||||
<span class="flex-1 text-xs text-gray-500 dark:text-gray-500 truncate">{chat.title}</span>
|
||||
<span class="text-[10px] text-gray-300 dark:text-gray-700 shrink-0"
|
||||
>{formatTime(chat.updated_at)}</span
|
||||
@@ -175,3 +179,4 @@
|
||||
onclose={closeMenu}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import QueuedMessageItem from './QueuedMessageItem.svelte';
|
||||
import Icon from '../Icon.svelte';
|
||||
import { planMode } from '$lib/stores';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
inputText: string;
|
||||
@@ -397,7 +398,7 @@
|
||||
<div class="relative group flex-shrink-0">
|
||||
{#if upload.loading}
|
||||
<div class="flex items-center justify-center size-8 bg-gray-50 dark:bg-white/5 rounded-xl border border-gray-200 dark:border-white/10 shadow-sm">
|
||||
<div class="w-4 h-4 border-2 border-blue-500 border-t-transparent rounded-full animate-spin"></div>
|
||||
<Spinner size={16} />
|
||||
</div>
|
||||
{:else if upload.type === 'image'}
|
||||
<img src={upload.url} alt={upload.name} class="size-8 object-cover rounded-xl border border-gray-200 dark:border-white/10 shadow-sm" />
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
import UserMessage from './UserMessage.svelte';
|
||||
import AssistantMessage from './AssistantMessage.svelte';
|
||||
import ChatHistory from './ChatHistory.svelte';
|
||||
import Spinner from '../common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
workspace: string;
|
||||
@@ -302,6 +303,20 @@
|
||||
queue_processed?: boolean;
|
||||
title?: string;
|
||||
}) {
|
||||
// On the landing page, update the chat list in place from socket events
|
||||
if (isLanding) {
|
||||
if (data.done) {
|
||||
previousChats = previousChats.map((c) =>
|
||||
c.id === data.chat_id ? { ...c, is_active: false } : c
|
||||
);
|
||||
}
|
||||
if (data.title) {
|
||||
previousChats = previousChats.map((c) =>
|
||||
c.id === data.chat_id ? { ...c, title: data.title! } : c
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.chat_id !== chatId) return;
|
||||
|
||||
// Title generated by backend — update tab label
|
||||
@@ -871,35 +886,9 @@
|
||||
{:else}
|
||||
<!-- Conversation view -->
|
||||
{#if loading}
|
||||
<div class="flex-1 flex items-center justify-center text-gray-400 dark:text-gray-500">
|
||||
<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.chat-load-spin {
|
||||
transform-origin: center;
|
||||
animation: chat-load-spin 0.75s infinite linear;
|
||||
}
|
||||
@keyframes chat-load-spin {
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<circle
|
||||
cx="12"
|
||||
cy="12"
|
||||
r="10"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
opacity="0.15"
|
||||
/>
|
||||
<path
|
||||
d="M10.14,1.16a11,11,0,0,0-9,8.92A1.59,1.59,0,0,0,2.46,12,1.52,1.52,0,0,0,4.11,10.7a8,8,0,0,1,6.66-6.61A1.42,1.42,0,0,0,12,2.69h0A1.57,1.57,0,0,0,10.14,1.16Z"
|
||||
fill="currentColor"
|
||||
class="chat-load-spin"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="flex-1 flex items-center justify-center text-gray-400 dark:text-gray-500">
|
||||
<Spinner size={24} />
|
||||
</div>
|
||||
{:else}
|
||||
<div bind:this={messagesEl} class="flex-1 overflow-y-auto" onscroll={handleMessagesScroll}>
|
||||
<div class="max-w-2xl mx-auto px-4 pt-4 pb-16 flex flex-col gap-4">
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<script lang="ts">
|
||||
interface Props {
|
||||
/** Size in px or Tailwind class like '3.5' or '5'. Defaults to 16px. */
|
||||
size?: number | string;
|
||||
/** Border width in px. Scales automatically if not set. */
|
||||
borderWidth?: number;
|
||||
/** Extra CSS classes. */
|
||||
class?: string;
|
||||
}
|
||||
let { size = 16, borderWidth, class: className = '' }: Props = $props();
|
||||
|
||||
const px = typeof size === 'number' ? size : parseFloat(size) * 4;
|
||||
const bw = borderWidth ?? (px <= 12 ? 1.5 : 2);
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="spinner {className}"
|
||||
style="width:{px}px;height:{px}px;border-width:{bw}px"
|
||||
role="status"
|
||||
aria-label="Loading"
|
||||
></div>
|
||||
|
||||
<style>
|
||||
.spinner {
|
||||
display: inline-block;
|
||||
border-style: solid;
|
||||
border-color: var(--color-gray-300);
|
||||
border-top-color: var(--color-gray-600);
|
||||
border-radius: 9999px;
|
||||
animation: spin 0.75s linear infinite;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
:global(.dark) .spinner {
|
||||
border-color: var(--color-gray-700);
|
||||
border-top-color: var(--color-gray-400);
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { fetchHandler } from '$lib/apis';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
src: string;
|
||||
@@ -296,7 +297,7 @@
|
||||
|
||||
<div class="office-view">
|
||||
{#if loading}
|
||||
<div class="state"><div class="spinner"></div></div>
|
||||
<div class="state"><Spinner size={20} /></div>
|
||||
{:else if error}
|
||||
<div class="state error-msg">{error}</div>
|
||||
{:else if isDocx}
|
||||
@@ -350,20 +351,7 @@
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid var(--color-gray-700);
|
||||
border-top-color: var(--color-gray-400);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.6s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* ── DOCX ────────────────────────────────────── */
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import panzoom, { type PanZoom } from 'panzoom';
|
||||
import { fetchHandler } from '$lib/apis';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
src: string;
|
||||
@@ -228,7 +229,7 @@
|
||||
|
||||
<div class="pdf-viewer">
|
||||
{#if loading}
|
||||
<div class="state"><div class="spinner"></div></div>
|
||||
<div class="state"><Spinner size={20} /></div>
|
||||
{:else if error}
|
||||
<div class="state error-msg">{error}</div>
|
||||
{/if}
|
||||
@@ -307,20 +308,7 @@
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid var(--color-gray-700);
|
||||
border-top-color: var(--color-gray-400);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.6s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.zoom-toolbar {
|
||||
position: absolute;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import { fetchHandler } from '$lib/apis';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
interface Props {
|
||||
src: string;
|
||||
@@ -147,7 +148,7 @@
|
||||
|
||||
<div class="sqlite-view">
|
||||
{#if loading}
|
||||
<div class="state"><div class="spinner"></div></div>
|
||||
<div class="state"><Spinner size={20} /></div>
|
||||
{:else if error}
|
||||
<div class="state error-msg">{error}</div>
|
||||
{:else}
|
||||
@@ -252,20 +253,7 @@
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
border: 2px solid var(--color-gray-700);
|
||||
border-top-color: var(--color-gray-400);
|
||||
border-radius: 50%;
|
||||
animation: spin 0.6s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
/* ── Tab bar ──────────────────────────────────── */
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import { onMount } from 'svelte';
|
||||
import Bar from '$lib/components/Bar.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
import Sidebar from '$lib/components/Sidebar.svelte';
|
||||
import ShortcutBar from '$lib/components/ShortcutBar.svelte';
|
||||
import GitBar from '$lib/components/GitBar.svelte';
|
||||
@@ -233,9 +234,7 @@
|
||||
{#if authState === 'checking'}
|
||||
<!-- Loading spinner while checking auth -->
|
||||
<div class="flex items-center justify-center h-dvh bg-white dark:bg-black">
|
||||
<div
|
||||
class="w-5 h-5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={20} />
|
||||
</div>
|
||||
{:else if authState === 'needs_setup' || authState === 'needs_login'}
|
||||
<!-- Auth screen -->
|
||||
@@ -279,9 +278,7 @@
|
||||
<ChangelogModal />
|
||||
{:else}
|
||||
<div class="flex items-center justify-center h-dvh bg-white dark:bg-black">
|
||||
<div
|
||||
class="w-5 h-5 border-2 border-gray-300 border-t-gray-600 dark:border-gray-700 dark:border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={20} />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
import GroupTabBar from '$lib/components/GroupTabBar.svelte';
|
||||
import Icon from '$lib/components/Icon.svelte';
|
||||
import SystemInfo from '$lib/components/SystemInfo.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
|
||||
let showPicker = $state(false);
|
||||
|
||||
@@ -438,9 +439,7 @@
|
||||
<FileBrowser />
|
||||
{:else if groupTab.type === 'terminal' && !groupTab.sessionId}
|
||||
<div class="flex items-center justify-center h-full">
|
||||
<div
|
||||
class="w-5 h-5 border-2 border-gray-800 border-t-gray-400 rounded-full animate-spin"
|
||||
></div>
|
||||
<Spinner size={20} />
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
+13
-2
@@ -99,6 +99,11 @@ async def list_chats(
|
||||
chats = await Chat.get_by_ids(chat_ids)
|
||||
chat_map = {c.id: c for c in chats}
|
||||
|
||||
# Detect which chats have a running task (in-memory check, no DB hit)
|
||||
from cptr.utils.chat_task import get_active_chat_ids
|
||||
|
||||
active_ids = get_active_chat_ids()
|
||||
|
||||
# Build response: only include chats owned by this user
|
||||
result = []
|
||||
for entry in chat_entries:
|
||||
@@ -114,6 +119,7 @@ async def list_chats(
|
||||
"current_message_id": chat.current_message_id,
|
||||
"created_at": chat.created_at,
|
||||
"updated_at": chat.updated_at,
|
||||
"is_active": chat.id in active_ids,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -347,7 +353,7 @@ async def send_message(body: SendMessageRequest, request: Request):
|
||||
meta={"workspace": body.workspace, "params": body.params},
|
||||
created_at=now_ms(),
|
||||
)
|
||||
# Ensure .cptr/chats/ dir exists (export will write the full JSON)
|
||||
# Ensure .cptr/chats/ dir exists
|
||||
chats_dir = Path(body.workspace) / ".cptr" / "chats"
|
||||
await asyncio.to_thread(lambda: chats_dir.mkdir(parents=True, exist_ok=True))
|
||||
|
||||
@@ -410,7 +416,12 @@ async def send_message(body: SendMessageRequest, request: Request):
|
||||
# Update chat pointer to new leaf
|
||||
await Chat.update_current_message(chat.id, assistant_msg.id, now_ms())
|
||||
|
||||
# Start background task (export_chat_to_file runs after task completes)
|
||||
# Export JSON immediately so list_chats discovers it right away
|
||||
from cptr.utils.chat_export import export_chat_to_file
|
||||
|
||||
await export_chat_to_file(chat.id)
|
||||
|
||||
# Start background task (export_chat_to_file also runs after task completes)
|
||||
from cptr.utils.chat_task import start_task
|
||||
|
||||
start_task(
|
||||
|
||||
@@ -81,6 +81,11 @@ def get_live_state(message_id: str) -> dict | None:
|
||||
return _task_state.get(message_id)
|
||||
|
||||
|
||||
def get_active_chat_ids() -> set[str]:
|
||||
"""Return the set of chat_ids that currently have a running task."""
|
||||
return {cid for mid, cid in _task_chat.items() if mid in _tasks and not _tasks[mid].done()}
|
||||
|
||||
|
||||
# ── Queue processing ────────────────────────────────────────
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
"""Webhook notifications: POST to Slack, Discord, Teams, or generic JSON.
|
||||
|
||||
Adapted from open-webui's webhook.py, using httpx instead of aiohttp.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
|
||||
import httpx
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def post_webhook(url: str, title: str, message: str) -> bool:
|
||||
"""Send a notification to a webhook URL.
|
||||
|
||||
Auto-detects Slack, Discord, Teams, and Google Chat webhook URLs
|
||||
and formats the payload accordingly. Falls back to generic JSON.
|
||||
|
||||
Returns True on success, False on failure (never raises).
|
||||
"""
|
||||
try:
|
||||
payload: dict = {}
|
||||
|
||||
# Slack and Google Chat
|
||||
if "hooks.slack.com" in url or "chat.googleapis.com" in url:
|
||||
payload["text"] = f"*{title}*\n{message}"
|
||||
|
||||
# Discord (2000 char limit)
|
||||
elif "discord.com/api/webhooks" in url:
|
||||
content = f"**{title}**\n{message}"
|
||||
if len(content) > 2000:
|
||||
content = content[:1980] + "... (truncated)"
|
||||
payload["content"] = content
|
||||
|
||||
# Microsoft Teams
|
||||
elif "webhook.office.com" in url:
|
||||
payload = {
|
||||
"@type": "MessageCard",
|
||||
"@context": "http://schema.org/extensions",
|
||||
"themeColor": "0076D7",
|
||||
"summary": title,
|
||||
"sections": [
|
||||
{
|
||||
"activityTitle": title,
|
||||
"activitySubtitle": "cptr",
|
||||
"facts": [{"name": "Message", "value": message}],
|
||||
"markdown": True,
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
# Generic JSON
|
||||
else:
|
||||
payload = {
|
||||
"title": title,
|
||||
"message": message,
|
||||
"source": "cptr",
|
||||
}
|
||||
|
||||
async with httpx.AsyncClient(timeout=10) as client:
|
||||
r = await client.post(url, json=payload)
|
||||
r.raise_for_status()
|
||||
|
||||
logger.info("[webhook] Sent notification to %s", url[:50])
|
||||
return True
|
||||
|
||||
except Exception:
|
||||
logger.exception("[webhook] Failed to send notification to %s", url[:50])
|
||||
return False
|
||||
""", "Description": "Adapted from open-webui's webhook.py — uses httpx, supports Slack/Discord/Teams/generic JSON", "IsArtifact": false, "Overwrite": false, "TargetFile": "/Users/tim/Documents/workspace/computer/cptr/utils/webhook.py
|
||||
Reference in new issue
Block a user