mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-22 21:50:42 -05:00
refac
This commit is contained in:
1 parent
121bc0ec50
commit
6378f94a65
24 files changed
+657
-287
No files matched your search
@@ -160,6 +160,14 @@ class AutomationTable:
|
||||
row = await db.get(Automation, id)
|
||||
return AutomationModel.model_validate(row) if row else None
|
||||
|
||||
async def get_by_folder(self, folder_id: str, db: Optional[AsyncSession] = None) -> list[AutomationModel]:
|
||||
"""Every automation that lives in a folder, whoever created it."""
|
||||
async with get_async_db_context(db) as db:
|
||||
result = await db.execute(
|
||||
select(Automation).filter_by(folder_id=folder_id).order_by(Automation.created_at.asc())
|
||||
)
|
||||
return [AutomationModel.model_validate(r) for r in result.scalars().all()]
|
||||
|
||||
async def get_active_by_user(self, user_id: str, db: Optional[AsyncSession] = None) -> list[AutomationModel]:
|
||||
"""Get active automations for a user (for calendar RRULE expansion)."""
|
||||
async with get_async_db_context(db) as db:
|
||||
|
||||
@@ -2882,6 +2882,7 @@ class ChatTable:
|
||||
}
|
||||
# Tags are the owner's own records; status is folder workflow, so folder editors may set it.
|
||||
chat['can_edit_tags'] = chat['user_id'] == user_id
|
||||
chat['automation_id'] = meta.get('automation_id')
|
||||
chat['can_edit_status'] = folder_write_access or chat['user_id'] == user_id
|
||||
# Only explain matches the title doesn't already show.
|
||||
chat['search_snippet'] = (
|
||||
|
||||
@@ -19,6 +19,7 @@ from open_webui.models.access_grants import AccessGrants, has_public_write_acces
|
||||
from open_webui.models.channels import Channels
|
||||
from open_webui.models.config import Config
|
||||
from open_webui.models.folders import Folders
|
||||
from open_webui.utils.access_control.folders import has_folder_write_access
|
||||
from open_webui.utils.access_control import has_permission
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.agents.discovery import get_models as get_agent_models
|
||||
@@ -96,16 +97,33 @@ async def check_automation_limits(request, user, rrule_str: str, db, is_create:
|
||||
|
||||
|
||||
async def check_automation_folder_access(folder_id: Optional[str], user, db: AsyncSession):
|
||||
"""An automation can live in any folder its creator can write to."""
|
||||
if folder_id is None:
|
||||
return
|
||||
folder = await Folders.get_folder_by_id_and_user_id(folder_id, user.id, db=db)
|
||||
if not folder:
|
||||
folder = await Folders.get_folder_by_id(folder_id, db=db)
|
||||
if not folder or not (user.role == 'admin' or await has_folder_write_access(user.id, folder_id, db=db)):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=ERROR_MESSAGES.NOT_FOUND,
|
||||
)
|
||||
|
||||
|
||||
async def check_automation_manage_access(automation, user, db: AsyncSession):
|
||||
"""Pausing, running and run history: the creator, or anyone who can write to its folder."""
|
||||
if automation and automation.user_id == user.id:
|
||||
return
|
||||
if (
|
||||
automation
|
||||
and automation.folder_id
|
||||
and (user.role == 'admin' or await has_folder_write_access(user.id, automation.folder_id, db=db))
|
||||
):
|
||||
return
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail=ERROR_MESSAGES.NOT_FOUND,
|
||||
)
|
||||
|
||||
|
||||
async def check_automation_channel_access(form_data: AutomationForm, user, db: AsyncSession):
|
||||
target = form_data.data.target
|
||||
if not target or target.type != 'channel':
|
||||
@@ -324,7 +342,7 @@ async def toggle_automation_by_id(
|
||||
):
|
||||
await check_automations_permission(request, user)
|
||||
automation = await Automations.get_by_id(id, db=db)
|
||||
check_automation_access(automation, user)
|
||||
await check_automation_manage_access(automation, user, db)
|
||||
toggled = await Automations.toggle(id, await next_run_ns(automation.data['rrule'], tz=user.timezone), db=db)
|
||||
response = await enrich_automation(toggled, db, tz=user.timezone)
|
||||
await publish_event(
|
||||
@@ -350,7 +368,7 @@ async def run_automation_by_id(
|
||||
):
|
||||
await check_automations_permission(request, user)
|
||||
automation = await Automations.get_by_id(id, db=db)
|
||||
check_automation_access(automation, user)
|
||||
await check_automation_manage_access(automation, user, db)
|
||||
automation = await Automations.update_last_run_at(automation.id, db=db)
|
||||
asyncio.create_task(execute_automation(request.app, automation))
|
||||
await publish_event(
|
||||
@@ -403,7 +421,7 @@ async def get_automation_runs(
|
||||
):
|
||||
await check_automations_permission(request, user)
|
||||
automation = await Automations.get_by_id(id, db=db)
|
||||
check_automation_access(automation, user)
|
||||
await check_automation_manage_access(automation, user, db)
|
||||
return await AutomationRuns.get_by_automation(id, skip=skip, limit=limit, db=db)
|
||||
|
||||
|
||||
@@ -419,7 +437,7 @@ async def get_automation_run(
|
||||
|
||||
await check_automations_permission(request, user)
|
||||
automation = await Automations.get_by_id(id, db=db)
|
||||
check_automation_access(automation, user)
|
||||
await check_automation_manage_access(automation, user, db)
|
||||
run = await db.get(AutomationRun, run_id)
|
||||
if not run or run.automation_id != id:
|
||||
raise HTTPException(404, 'Run not found')
|
||||
|
||||
@@ -13,7 +13,7 @@ from open_webui.constants import ERROR_MESSAGES
|
||||
from open_webui.events import EVENTS, publish_event
|
||||
from open_webui.internal.db import get_async_session
|
||||
from open_webui.models.access_grants import AccessGrants
|
||||
from open_webui.models.automations import Automations
|
||||
from open_webui.models.automations import AutomationResponse, AutomationRuns, Automations
|
||||
from open_webui.models.chat_messages import ChatMessages
|
||||
from open_webui.models.chats import Chats
|
||||
from open_webui.models.config import Config
|
||||
@@ -743,6 +743,29 @@ async def check_folder_read_access(request: Request, id: str, user, db: AsyncSes
|
||||
return folder
|
||||
|
||||
|
||||
@router.get('/{id}/automations')
|
||||
async def get_folder_automations(
|
||||
request: Request, id: str, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session)
|
||||
):
|
||||
"""The folder's automations, whoever made them. Only creators edit; folder editors may pause and run."""
|
||||
folder = await check_folder_read_access(request, id, user, db)
|
||||
automations = await Automations.get_by_folder(id, db=db)
|
||||
if not automations:
|
||||
return []
|
||||
latest = await AutomationRuns.get_latest_batch([item.id for item in automations], db=db)
|
||||
creators = {u.id: u.name for u in await Users.get_users_by_user_ids(list({a.user_id for a in automations}), db=db)}
|
||||
has_write = user.role == 'admin' or folder.user_id == user.id or await _has_folder_access(user.id, folder, 'write', db)
|
||||
return [
|
||||
{
|
||||
**AutomationResponse(**item.model_dump(), last_run=latest.get(item.id)).model_dump(),
|
||||
'user_name': creators.get(item.user_id) or 'Unknown',
|
||||
'can_edit': item.user_id == user.id,
|
||||
'can_manage': item.user_id == user.id or has_write,
|
||||
}
|
||||
for item in automations
|
||||
]
|
||||
|
||||
|
||||
@router.get('/{id}/users')
|
||||
async def get_folder_users(request: Request, id: str, user=Depends(get_verified_user), db: AsyncSession = Depends(get_async_session)):
|
||||
await check_folder_read_access(request, id, user, db)
|
||||
|
||||
@@ -35,6 +35,7 @@ class ShareForm(BaseModel):
|
||||
class InstanceForm(BaseModel):
|
||||
user_id: str | None = Field(default=None, min_length=1)
|
||||
chat_id: str | None = None
|
||||
folder_id: str | None = None
|
||||
model_id: str | None = None
|
||||
|
||||
|
||||
@@ -169,6 +170,7 @@ async def current_instance(
|
||||
@router.get('/{terminal_id}/instances')
|
||||
async def list_instances(terminal_id: str, user=Depends(get_verified_user)):
|
||||
from open_webui.models.chats import Chats
|
||||
from open_webui.models.folders import Folders
|
||||
from open_webui.models.models import Models
|
||||
from open_webui.models.users import Users
|
||||
|
||||
@@ -182,6 +184,11 @@ async def list_instances(terminal_id: str, user=Depends(get_verified_user)):
|
||||
owner = await Users.get_user_by_id(chat.user_id) if chat else None
|
||||
row['label'] = chat.title if chat else None
|
||||
row['user_name'] = owner.name if owner else None
|
||||
elif kind == 'folder':
|
||||
folder = await Folders.get_folder_by_id(value)
|
||||
owner = await Users.get_user_by_id(folder.user_id) if folder else None
|
||||
row['label'] = folder.name if folder else None
|
||||
row['user_name'] = owner.name if owner else None
|
||||
elif kind == 'user':
|
||||
owner = await Users.get_user_by_id(value)
|
||||
row['label'] = owner.name if owner else None
|
||||
|
||||
@@ -14,7 +14,7 @@ def model_controls(model):
|
||||
'Reasoning effort',
|
||||
'supportedReasoningEfforts',
|
||||
'reasoningEffort',
|
||||
'reasoningEffort',
|
||||
'label',
|
||||
'defaultReasoningEffort',
|
||||
),
|
||||
('service_tier', 'Service tier', 'serviceTiers', 'id', 'name', 'defaultServiceTier'),
|
||||
|
||||
@@ -33,6 +33,7 @@ from open_webui.models.automations import AutomationModel, AutomationRuns, Autom
|
||||
from open_webui.models.chats import ChatForm, Chats
|
||||
from open_webui.models.config import Config
|
||||
from open_webui.models.folders import Folders
|
||||
from open_webui.utils.access_control.folders import has_folder_write_access
|
||||
from open_webui.models.messages import MessageForm
|
||||
from open_webui.models.users import Users
|
||||
from open_webui.utils.auth import create_token
|
||||
@@ -393,8 +394,9 @@ async def execute_automation(app, automation: AutomationModel) -> None:
|
||||
await _execute_channel_automation(app, automation, user, prompt, model_id, token)
|
||||
return
|
||||
|
||||
# Runs land in the automation's folder while its creator can still write there.
|
||||
folder_id = automation.folder_id
|
||||
if folder_id and not await Folders.get_folder_by_id_and_user_id(folder_id, automation.user_id):
|
||||
if folder_id and not await has_folder_write_access(automation.user_id, folder_id):
|
||||
await Automations.clear_folder_ids(automation.user_id, [folder_id])
|
||||
folder_id = None
|
||||
|
||||
@@ -441,6 +443,7 @@ async def execute_automation(app, automation: AutomationModel) -> None:
|
||||
'meta': {'automation_id': automation.id},
|
||||
},
|
||||
),
|
||||
internal_meta={'automation_id': automation.id},
|
||||
)
|
||||
|
||||
if not chat:
|
||||
|
||||
@@ -192,7 +192,10 @@ async def list_template_connections(user, connections):
|
||||
|
||||
class MissingTerminalContext(HTTPException):
|
||||
def __init__(self, scope):
|
||||
detail = 'This terminal requires a saved chat' if scope == 'chat' else f'This terminal requires a {scope}'
|
||||
detail = {
|
||||
'chat': 'This terminal requires a saved chat',
|
||||
'folder': 'This terminal requires a chat in a folder',
|
||||
}.get(scope, f'This terminal requires a {scope}')
|
||||
super().__init__(409, detail)
|
||||
|
||||
|
||||
@@ -200,17 +203,21 @@ def get_terminal_context(template, user_id, metadata=None):
|
||||
"""Validate a template's scope and return context for its environment."""
|
||||
metadata = metadata or {}
|
||||
scope = (template.get('data') or {}).get('scope')
|
||||
if scope not in (None, 'user', 'chat', 'model'):
|
||||
if scope not in (None, 'user', 'chat', 'folder', 'model'):
|
||||
raise HTTPException(422, 'Invalid template scope')
|
||||
chat_id = metadata.get('chat_id')
|
||||
folder_id = metadata.get('folder_id')
|
||||
model_id = metadata.get('model_id') or metadata.get('model')
|
||||
if scope == 'chat' and not is_saved_chat_id(chat_id):
|
||||
raise MissingTerminalContext(scope)
|
||||
if scope == 'folder' and not folder_id:
|
||||
raise MissingTerminalContext(scope)
|
||||
if scope == 'model' and not model_id:
|
||||
raise MissingTerminalContext(scope)
|
||||
return {
|
||||
'user_id': user_id,
|
||||
'chat_id': chat_id if is_saved_chat_id(chat_id) else None,
|
||||
'folder_id': folder_id if scope == 'folder' else None,
|
||||
'model_id': model_id if scope == 'model' else None,
|
||||
}
|
||||
|
||||
@@ -253,6 +260,8 @@ def terminal_headers(connection):
|
||||
}
|
||||
if context.get('chat_id'):
|
||||
headers['X-Terminal-Chat-Id'] = context['chat_id']
|
||||
if context.get('folder_id'):
|
||||
headers['X-Terminal-Folder-Id'] = context['folder_id']
|
||||
if context.get('model_id'):
|
||||
headers['X-Terminal-Model-Id'] = context['model_id']
|
||||
return headers
|
||||
@@ -323,11 +332,25 @@ async def find_terminal_connection(user, terminal_id, metadata=None, request=Non
|
||||
if stored and stored != terminal_id:
|
||||
raise HTTPException(409, 'Chat terminal selection changed; refresh the chat')
|
||||
|
||||
folder = None
|
||||
if scope == 'folder':
|
||||
# The folder comes from the saved chat, never from the request.
|
||||
metadata['folder_id'] = None
|
||||
if chat and chat.folder_id:
|
||||
from open_webui.models.folders import Folders
|
||||
from open_webui.utils.access_control.folders import has_folder_access
|
||||
|
||||
folder = await Folders.get_folder_by_id(chat.folder_id)
|
||||
if folder is None or not await has_folder_access(user.id, folder, 'write', None):
|
||||
raise HTTPException(403, 'Folder access denied')
|
||||
metadata['folder_id'] = folder.id
|
||||
|
||||
principal = instance_user
|
||||
if not shared_session and scope == 'chat' and chat:
|
||||
owner = user if chat.user_id == user.id else await Users.get_user_by_id(chat.user_id)
|
||||
if not shared_session and scope in ('chat', 'folder') and chat:
|
||||
owner_id = folder.user_id if folder else chat.user_id
|
||||
owner = user if owner_id == user.id else await Users.get_user_by_id(owner_id)
|
||||
if owner is None:
|
||||
raise HTTPException(403, 'Chat owner is unavailable')
|
||||
raise HTTPException(403, f"{'Folder' if folder else 'Chat'} owner is unavailable")
|
||||
if (
|
||||
owner.id != instance_user.id
|
||||
and not await has_connection_access(owner, connection)
|
||||
|
||||
@@ -327,3 +327,28 @@ export const getAutomationRuns = async (
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
/** An automation listed in a folder, with what the viewer may do with it. */
|
||||
export type FolderAutomation = AutomationResponse & {
|
||||
user_name: string;
|
||||
can_edit: boolean;
|
||||
can_manage: boolean;
|
||||
};
|
||||
|
||||
export const getFolderAutomations = async (
|
||||
token: string,
|
||||
folderId: string
|
||||
): Promise<FolderAutomation[]> => {
|
||||
const res = await fetch(
|
||||
`${WEBUI_API_BASE_URL}/folders/${encodeURIComponent(folderId)}/automations`,
|
||||
{
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
);
|
||||
if (!res.ok) throw (await res.json().catch(() => ({})))?.detail ?? res.statusText;
|
||||
return res.json();
|
||||
};
|
||||
@@ -29,6 +29,8 @@
|
||||
export let show = false;
|
||||
export let automation: AutomationResponse | null = null;
|
||||
export let cloneFrom: AutomationResponse | null = null;
|
||||
/** Folder a new automation starts in. */
|
||||
export let folderId: string | null = null;
|
||||
|
||||
let name = '';
|
||||
let prompt = '';
|
||||
@@ -201,7 +203,7 @@
|
||||
name = '';
|
||||
prompt = '';
|
||||
model_id = '';
|
||||
folder_id = '';
|
||||
folder_id = folderId ?? '';
|
||||
target_type = 'chat';
|
||||
channel_id = '';
|
||||
is_active = true;
|
||||
@@ -214,12 +216,12 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal ariaLabel={name || $i18n.t('Automation')} size="md" bind:show>
|
||||
<Modal ariaLabel={name || $i18n.t('Automation')} size="lg" bind:show>
|
||||
<div>
|
||||
<!-- Header -->
|
||||
<div class="flex justify-between dark:text-gray-100 px-4 pt-3 pb-1">
|
||||
<input
|
||||
class="w-full text-sm font-medium bg-transparent outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700"
|
||||
class="w-full text-sm bg-transparent outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700"
|
||||
type="text"
|
||||
bind:value={name}
|
||||
aria-label={$i18n.t('Automation title')}
|
||||
@@ -235,13 +237,13 @@
|
||||
</div>
|
||||
|
||||
<!-- Prompt -->
|
||||
<div class="px-5 pb-2">
|
||||
<div class="px-4 pb-2">
|
||||
<label for="automation-instructions" class="block mb-1 text-xs text-gray-500"
|
||||
>{$i18n.t('Instructions')}</label
|
||||
>
|
||||
<textarea
|
||||
id="automation-instructions"
|
||||
class="w-full text-sm bg-transparent outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700 resize-none min-h-[12rem]"
|
||||
class="w-full text-sm bg-transparent outline-hidden placeholder:text-gray-300 dark:placeholder:text-gray-700 resize-none min-h-[min(28rem,55vh)]"
|
||||
bind:value={prompt}
|
||||
rows={8}
|
||||
placeholder={$i18n.t('Enter prompt here.')}
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
||||
import ArrowRight from '$lib/components/icons/ArrowRight.svelte';
|
||||
import Check from '$lib/components/icons/Check.svelte';
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
|
||||
dayjs.extend(localizedFormat);
|
||||
|
||||
@@ -271,14 +273,7 @@
|
||||
<span class="w-24 shrink-0 text-[0.6875rem] text-gray-400 dark:text-gray-500">
|
||||
{$i18n.t('Status')}
|
||||
</span>
|
||||
<span
|
||||
class="flex min-w-0 items-center gap-1.5 text-xs {is_active
|
||||
? 'text-emerald-700 dark:text-emerald-400'
|
||||
: 'text-gray-600 dark:text-gray-400'}"
|
||||
>
|
||||
<svg class="size-1.5 shrink-0" viewBox="0 0 6 6" fill="currentColor" aria-hidden="true">
|
||||
<circle cx="3" cy="3" r="3" />
|
||||
</svg>
|
||||
<span class="min-w-0 text-xs text-gray-700 dark:text-gray-300">
|
||||
{is_active ? $i18n.t('Active') : $i18n.t('Paused')}
|
||||
</span>
|
||||
</div>
|
||||
@@ -361,10 +356,14 @@
|
||||
class="flex h-7 items-center gap-2 text-xs"
|
||||
>
|
||||
<span
|
||||
class="h-1.5 w-1.5 shrink-0 rounded-full {run.status === 'success'
|
||||
? 'bg-emerald-500'
|
||||
: 'bg-red-400'}"
|
||||
></span>
|
||||
class="flex shrink-0 text-gray-400"
|
||||
title={run.status === 'success' ? $i18n.t('Succeeded') : $i18n.t('Failed')}
|
||||
aria-label={run.status === 'success' ? $i18n.t('Succeeded') : $i18n.t('Failed')}
|
||||
>
|
||||
{#if run.status === 'success'}<Check className="size-3" />{:else}<XMark
|
||||
className="size-3"
|
||||
/>{/if}
|
||||
</span>
|
||||
<span class="text-gray-500 dark:text-gray-400">{formatTime(run.created_at)}</span>
|
||||
{#if run.chat_id}
|
||||
<button
|
||||
@@ -387,7 +386,10 @@
|
||||
</button>
|
||||
{/if}
|
||||
{#if run.error}
|
||||
<span class="truncate text-[0.6875rem] text-red-400" title={run.error}>
|
||||
<span
|
||||
class="truncate text-[0.6875rem] text-gray-400 dark:text-gray-500"
|
||||
title={run.error}
|
||||
>
|
||||
{run.error}
|
||||
</span>
|
||||
{/if}
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
<span class="truncate">{server.name || server.id}</span>
|
||||
</div>
|
||||
{#if terminalServerId === server.id}
|
||||
<div class="shrink-0 text-emerald-600 dark:text-emerald-400">
|
||||
<div class="shrink-0 text-gray-500 dark:text-gray-400">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
|
||||
@@ -1169,7 +1169,10 @@
|
||||
$: if (
|
||||
$temporaryChatEnabled &&
|
||||
($terminalServers ?? []).some(
|
||||
(t) => !!$selectedTerminalId && t.id === $selectedTerminalId && t.scope === 'chat'
|
||||
(t) =>
|
||||
!!$selectedTerminalId &&
|
||||
t.id === $selectedTerminalId &&
|
||||
['chat', 'folder'].includes(t.scope)
|
||||
)
|
||||
) {
|
||||
selectedTerminalId.set(null);
|
||||
@@ -1188,7 +1191,9 @@
|
||||
? JSON.stringify([
|
||||
terminalId,
|
||||
directory,
|
||||
($terminalServers ?? []).find((server) => server.id === terminalId)?.scope === 'chat'
|
||||
['chat', 'folder'].includes(
|
||||
($terminalServers ?? []).find((server) => server.id === terminalId)?.scope
|
||||
)
|
||||
? $chatId
|
||||
: null,
|
||||
$config,
|
||||
|
||||
@@ -822,7 +822,7 @@
|
||||
const systemTerminal = effectiveTerminalId
|
||||
? (($terminalServers ?? []).find((t) => t.id === effectiveTerminalId) ?? null)
|
||||
: ($terminalServers?.[0] ?? null);
|
||||
isPerChatTerminal = !!systemTerminal && systemTerminal?.scope === 'chat';
|
||||
isPerChatTerminal = !!systemTerminal && ['chat', 'folder'].includes(systemTerminal?.scope);
|
||||
terminalChatContextHidden = isPerChatTerminal && isTemporaryChatId(chatId);
|
||||
terminalChatContextPending =
|
||||
isPerChatTerminal && !terminalChatContextHidden && !isSavedChatId(chatId);
|
||||
|
||||
@@ -1072,7 +1072,7 @@
|
||||
if (!terminal) throw new Error('The attached file’s terminal is unavailable.');
|
||||
if (fileItem.session_id && fileItem.session_id !== sessionId)
|
||||
throw new Error('Attached files must belong to this chat.');
|
||||
if (server.scope === 'chat' && !isSavedChatId(sessionId))
|
||||
if (['chat', 'folder'].includes(server.scope) && !isSavedChatId(sessionId))
|
||||
throw new Error('A saved chat is required for this terminal');
|
||||
|
||||
const cwd =
|
||||
@@ -1161,7 +1161,7 @@
|
||||
fileItem.file = file;
|
||||
fileItem.terminal_id = $selectedTerminalId;
|
||||
fileItem.session_id = chatId || null;
|
||||
if (!chatId && filesystemUploadTerminal.scope === 'chat') {
|
||||
if (!chatId && ['chat', 'folder'].includes(filesystemUploadTerminal.scope)) {
|
||||
fileItem.status = 'pending';
|
||||
files = files;
|
||||
return;
|
||||
|
||||
@@ -118,7 +118,11 @@
|
||||
|
||||
$: systemTerminals = ($terminalServers ?? []).filter(
|
||||
(t) =>
|
||||
t.id && !(($temporaryChatEnabled || isTemporaryChatId($activeChatId)) && t.scope === 'chat')
|
||||
t.id &&
|
||||
!(
|
||||
($temporaryChatEnabled || isTemporaryChatId($activeChatId)) &&
|
||||
['chat', 'folder'].includes(t.scope)
|
||||
)
|
||||
);
|
||||
// Tether presences are the user's own paired devices, listed apart from servers.
|
||||
const isDevice = (terminal: any) => terminal.id.startsWith('tether:');
|
||||
@@ -168,7 +172,9 @@
|
||||
};
|
||||
const openInfo = async (selector: string, label: string) => {
|
||||
if (
|
||||
systemTerminals.find((t) => !!selector && t.id === selector)?.scope === 'chat' &&
|
||||
['chat', 'folder'].includes(
|
||||
systemTerminals.find((t) => !!selector && t.id === selector)?.scope
|
||||
) &&
|
||||
!isSavedChatId($activeChatId)
|
||||
)
|
||||
return;
|
||||
@@ -244,7 +250,8 @@
|
||||
{#each section.terminals as terminal}
|
||||
{@const label = terminal.name || $i18n.t('Terminal')}
|
||||
{@const owned = canManage(terminal, manageable)}
|
||||
{@const reachable = terminal.scope !== 'chat' || isSavedChatId($activeChatId)}
|
||||
{@const reachable =
|
||||
!['chat', 'folder'].includes(terminal.scope) || isSavedChatId($activeChatId)}
|
||||
<div class="group/terminal relative rounded-xl">
|
||||
<button
|
||||
type="button"
|
||||
@@ -393,7 +400,7 @@
|
||||
{/key}
|
||||
{/if}
|
||||
|
||||
{#if folderTarget && (selectedSystemTerminal?.scope !== 'chat' || isSavedChatId(chatId))}
|
||||
{#if folderTarget && (!['chat', 'folder'].includes(selectedSystemTerminal?.scope) || isSavedChatId(chatId))}
|
||||
{#key `${$user?.id}:${folderTarget.selector}:${chatId ?? ''}`}
|
||||
<WorkingDirectoryMenu
|
||||
{inMenu}
|
||||
|
||||
@@ -97,6 +97,8 @@
|
||||
|
||||
// Height of the floating folder composer, so lists can scroll clear of it.
|
||||
let composerHeight = 0;
|
||||
// The composer only belongs with the folder's chats, not its automations.
|
||||
let folderSection: 'chats' | 'automations' = 'chats';
|
||||
|
||||
let models = [];
|
||||
export let selectedModelIdx = 0;
|
||||
@@ -200,16 +202,17 @@
|
||||
{#if $selectedFolder}
|
||||
<div
|
||||
class="relative min-h-0 w-full flex-1"
|
||||
style="--folder-composer-space: {folderReadOnly ? 0 : composerHeight}px"
|
||||
style="--folder-composer-space: {folderReadOnly || folderSection !== 'chats' ? 0 : composerHeight}px"
|
||||
>
|
||||
<FolderPlaceholder
|
||||
folder={$selectedFolder}
|
||||
readOnly={folderReadOnly}
|
||||
bind:folderTabActions
|
||||
bind:folderSection
|
||||
onNewChat={() => messageInput?.focus()}
|
||||
/>
|
||||
|
||||
{#if !folderReadOnly}
|
||||
{#if !folderReadOnly && folderSection === 'chats'}
|
||||
<!-- Same mount as the in-chat composer, floating over the list and board. -->
|
||||
<div
|
||||
class="pointer-events-none absolute inset-x-0 bottom-0 bg-linear-to-t from-white from-40% to-transparent pt-8 pb-2 text-left dark:from-gray-900 {dragged
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
import FolderTags from './FolderTags.svelte';
|
||||
import FolderChatMenu from './FolderChatMenu.svelte';
|
||||
import FolderChatLink from './FolderChatLink.svelte';
|
||||
import Icon from '$lib/components/chat/FileNav/Icon.svelte';
|
||||
import FolderStatusControl from './FolderStatus.svelte';
|
||||
import StatusIcon from './FolderStatusIcon.svelte';
|
||||
import FolderStatusTime from './FolderStatusTime.svelte';
|
||||
@@ -247,6 +248,14 @@
|
||||
onclick={(event) => openFolderChat(chat, appLayout, event)}
|
||||
/>
|
||||
{/if}
|
||||
{#if chat.automation_id}
|
||||
<span
|
||||
class="flex shrink-0 text-gray-400 dark:text-gray-500"
|
||||
title={$i18n.t('Made by an automation')}
|
||||
aria-label={$i18n.t('Made by an automation')}
|
||||
><Icon name="clock" size={12} /></span
|
||||
>
|
||||
{/if}
|
||||
{#if chat.search_snippet}
|
||||
<span
|
||||
class="hidden min-w-0 flex-1 truncate text-xs text-gray-400 @lg:block dark:text-gray-500"
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
<script lang="ts">
|
||||
import { getContext, onMount } from 'svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import type { AppLayoutContext } from '$lib/types';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { socket } from '$lib/stores';
|
||||
import { toggleAutomationById, type FolderAutomation } from '$lib/apis/automations';
|
||||
import { formatShortDate } from '$lib/utils';
|
||||
import { formatSchedule } from '$lib/utils/schedule';
|
||||
import AutomationModal from '$lib/components/AutomationModal.svelte';
|
||||
import Switch from '$lib/components/common/Switch.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
import Icon from '$lib/components/chat/FileNav/Icon.svelte';
|
||||
|
||||
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
|
||||
const appLayout = getContext<AppLayoutContext | undefined>('appLayout');
|
||||
|
||||
/** The folder's automations as a list; new ones use the automation modal, existing ones open their page. */
|
||||
export let folderId: string;
|
||||
export let automations: FolderAutomation[] = [];
|
||||
export let loading = false;
|
||||
export let canCreate = false;
|
||||
export let onReload: () => Promise<void>;
|
||||
|
||||
let showModal = false;
|
||||
let busy = '';
|
||||
|
||||
export function startNew() {
|
||||
showModal = true;
|
||||
}
|
||||
|
||||
// An existing automation opens as its own page, in a tab beside the folder like chats do.
|
||||
function edit(automation: FolderAutomation) {
|
||||
if (!automation.can_edit) return;
|
||||
const href = `/automations/${automation.id}`;
|
||||
if (appLayout?.openPageTab) appLayout.openPageTab({ href, label: automation.name });
|
||||
else void goto(href);
|
||||
}
|
||||
|
||||
async function toggle(automation: FolderAutomation) {
|
||||
busy = automation.id;
|
||||
try {
|
||||
await toggleAutomationById(localStorage.token, automation.id);
|
||||
await onReload();
|
||||
} catch (error: any) {
|
||||
toast.error(error?.detail ?? String(error));
|
||||
} finally {
|
||||
busy = '';
|
||||
}
|
||||
}
|
||||
|
||||
const lastRun = (automation: FolderAutomation) =>
|
||||
!automation.is_active
|
||||
? $i18n.t('Paused')
|
||||
: automation.last_run
|
||||
? formatShortDate(automation.last_run.created_at / 1e9, $i18n.language)
|
||||
: $i18n.t('Not run yet');
|
||||
|
||||
onMount(() => {
|
||||
// A finished run updates the list's last-run times.
|
||||
const refresh = () => void onReload();
|
||||
$socket?.on('automation:result', refresh);
|
||||
return () => $socket?.off('automation:result', refresh);
|
||||
});
|
||||
</script>
|
||||
|
||||
<AutomationModal bind:show={showModal} {folderId} on:save={onReload} />
|
||||
|
||||
{#if loading && !automations.length}
|
||||
<div class="flex h-full items-center justify-center"><Spinner className="size-4" /></div>
|
||||
{:else if !automations.length}
|
||||
<div class="flex h-full flex-col items-center justify-center gap-1 px-6 pb-16 text-center">
|
||||
<div class="text-sm text-gray-800 dark:text-gray-100">{$i18n.t('No automations yet')}</div>
|
||||
<div class="text-xs text-gray-500 dark:text-gray-400">
|
||||
{$i18n.t('Run a prompt in this folder on a schedule. Each run lands here as a chat.')}
|
||||
</div>
|
||||
{#if canCreate}
|
||||
<button
|
||||
type="button"
|
||||
class="mt-2 text-xs text-gray-400 transition-colors hover:text-gray-600 dark:text-gray-500 dark:hover:text-gray-300"
|
||||
on:click={startNew}>{$i18n.t('New automation')}</button
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<ul class="scrollbar-hidden h-full overflow-y-auto px-3" aria-label={$i18n.t('Automations')}>
|
||||
{#each automations as automation (automation.id)}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_noninteractive_element_interactions -->
|
||||
<li
|
||||
class="flex items-center gap-2.5 rounded-xl px-3 py-1.5 transition-colors hover:bg-gray-50 dark:hover:bg-gray-850/50 {automation.can_edit
|
||||
? 'cursor-pointer'
|
||||
: ''}"
|
||||
on:click={() => edit(automation)}
|
||||
>
|
||||
<Icon name="clock" size={14} class="text-gray-400 dark:text-gray-500" />
|
||||
<span
|
||||
class="min-w-0 shrink truncate text-[0.8125rem] leading-5 text-gray-700 dark:text-gray-200"
|
||||
>{automation.name}</span
|
||||
>
|
||||
<span class="hidden min-w-0 truncate text-xs text-gray-400 @md:block dark:text-gray-500"
|
||||
>{formatSchedule(automation.data.rrule, $i18n)}</span
|
||||
>
|
||||
<span class="flex-1"></span>
|
||||
<span class="text-[0.6875rem] tabular-nums text-gray-400 dark:text-gray-500"
|
||||
>{lastRun(automation)}</span
|
||||
>
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
|
||||
<div on:click|stopPropagation>
|
||||
<Switch
|
||||
state={automation.is_active}
|
||||
disabled={!automation.can_manage || busy === automation.id}
|
||||
ariaLabel={$i18n.t('Active')}
|
||||
on:change={() => toggle(automation)}
|
||||
/>
|
||||
</div>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/if}
|
||||
@@ -16,6 +16,7 @@
|
||||
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
|
||||
import FolderTags from './FolderTags.svelte';
|
||||
import FolderChatLink from './FolderChatLink.svelte';
|
||||
import Icon from '$lib/components/chat/FileNav/Icon.svelte';
|
||||
import FolderStatusControl from './FolderStatus.svelte';
|
||||
import StatusIcon from './FolderStatusIcon.svelte';
|
||||
import FolderStatusTime from './FolderStatusTime.svelte';
|
||||
@@ -203,6 +204,13 @@
|
||||
: 'text-gray-700 dark:text-gray-200'}"
|
||||
onclick={(event) => openFolderChat(chat, appLayout, event)}
|
||||
/>
|
||||
{#if chat.automation_id}
|
||||
<span
|
||||
class="mt-1 flex shrink-0 text-gray-400 dark:text-gray-500"
|
||||
title={$i18n.t('Made by an automation')}
|
||||
aria-label={$i18n.t('Made by an automation')}><Icon name="clock" size={12} /></span
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if chat.search_snippet}
|
||||
|
||||
@@ -46,7 +46,11 @@
|
||||
import DropdownSub from '$lib/components/common/DropdownSub.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
import Check from '$lib/components/icons/Check.svelte';
|
||||
import Plus from '$lib/components/icons/Plus.svelte';
|
||||
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
|
||||
import ChevronDown from '$lib/components/icons/ChevronDown.svelte';
|
||||
import FolderAutomations from './FolderAutomations.svelte';
|
||||
import { getFolderAutomations, type FolderAutomation } from '$lib/apis/automations';
|
||||
import AdjustmentsHorizontal from '$lib/components/icons/AdjustmentsHorizontal.svelte';
|
||||
import TagIcon from '$lib/components/icons/Tag.svelte';
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
@@ -60,6 +64,30 @@
|
||||
|
||||
export let folder: FolderDetails | null = null;
|
||||
export let readOnly = false;
|
||||
/** Which part of the folder is showing: its chats or its automations. */
|
||||
export let folderSection: 'chats' | 'automations' = 'chats';
|
||||
let automations: FolderAutomation[] = [];
|
||||
let automationsLoading = false;
|
||||
let automationsView: FolderAutomations;
|
||||
|
||||
async function loadAutomations() {
|
||||
const id = folder?.id;
|
||||
if (!id) return;
|
||||
automationsLoading = true;
|
||||
try {
|
||||
const next = await getFolderAutomations(localStorage.token, id);
|
||||
if (folder?.id === id) automations = next;
|
||||
} catch (error) {
|
||||
if (folder?.id === id) automations = [];
|
||||
} finally {
|
||||
automationsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function showSection(next: 'chats' | 'automations') {
|
||||
folderSection = next;
|
||||
if (next === 'automations') void loadAutomations();
|
||||
}
|
||||
export let onNewChat: () => void = () => {};
|
||||
export let folderTabActions: import('svelte').Snippet | undefined = undefined;
|
||||
|
||||
@@ -733,6 +761,7 @@
|
||||
document.querySelector('[aria-modal="true"]')
|
||||
)
|
||||
return;
|
||||
if (folderSection !== 'chats' && (event.key === '/' || event.key === 'f')) return;
|
||||
if (event.key === '/') {
|
||||
event.preventDefault();
|
||||
void openSearch();
|
||||
@@ -807,8 +836,11 @@
|
||||
optionsReady = false;
|
||||
optionsError = '';
|
||||
clearTimeout(timer);
|
||||
folderSection = 'chats';
|
||||
automations = [];
|
||||
void loadOptions();
|
||||
void load(true);
|
||||
void loadAutomations();
|
||||
}
|
||||
|
||||
// Backstop: tag groups that appear later (e.g. a tag created while open) get their chats.
|
||||
@@ -981,266 +1013,328 @@
|
||||
className="mx-0.5 size-3 shrink-0 text-gray-400 rtl:rotate-180 dark:text-gray-500"
|
||||
strokeWidth="2"
|
||||
/>
|
||||
<span class="shrink-0">{$i18n.t('Chats')}</span>
|
||||
{#if loading && hasData}
|
||||
<Spinner className="size-3 opacity-60" />
|
||||
{:else if hasData && !error}
|
||||
<span class="text-sm opacity-60">{formatNumber(total)}</span>
|
||||
{/if}
|
||||
<Dropdown align="start" closeOnSelect>
|
||||
<button
|
||||
type="button"
|
||||
class="-mx-1 flex shrink-0 items-center gap-1 rounded-md px-1 transition-colors hover:bg-gray-100 dark:hover:bg-gray-850"
|
||||
aria-label={$i18n.t('Switch section')}
|
||||
>
|
||||
{#if folderSection === 'automations'}
|
||||
<span>{$i18n.t('Automations')}</span>
|
||||
{#if automations.length}<span class="text-sm opacity-60">{automations.length}</span
|
||||
>{/if}
|
||||
{:else}
|
||||
<span>{$i18n.t('Chats')}</span>
|
||||
{#if loading && hasData}
|
||||
<Spinner className="size-3 opacity-60" />
|
||||
{:else if hasData && !error}
|
||||
<span class="text-sm opacity-60">{formatNumber(total)}</span>
|
||||
{/if}
|
||||
{/if}
|
||||
<ChevronDown className="size-2.5 text-gray-400 dark:text-gray-500" strokeWidth="2.5" />
|
||||
</button>
|
||||
<DropdownMenu slot="content" className="w-44">
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={folderSection === 'chats'}
|
||||
on:click={() => showSection('chats')}
|
||||
>
|
||||
<Icon name="chat-bubble" size={14} />
|
||||
<span class="flex-1 text-left">{$i18n.t('Chats')}</span>
|
||||
{#if hasData}<span class="text-xs tabular-nums text-gray-400"
|
||||
>{formatNumber(total)}</span
|
||||
>{/if}
|
||||
{#if folderSection === 'chats'}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={folderSection === 'automations'}
|
||||
on:click={() => showSection('automations')}
|
||||
>
|
||||
<Icon name="clock" size={14} />
|
||||
<span class="flex-1 text-left">{$i18n.t('Automations')}</span>
|
||||
{#if automations.length}<span class="text-xs tabular-nums text-gray-400"
|
||||
>{automations.length}</span
|
||||
>{/if}
|
||||
{#if folderSection === 'automations'}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
</h2>
|
||||
|
||||
<div class="ml-auto flex items-center gap-1">
|
||||
{#if searchOpen || search}
|
||||
<div
|
||||
class="flex h-6.5 w-40 items-center gap-1.5 rounded-full border border-gray-100 bg-gray-50/60 px-2 text-gray-400 @lg:w-52 dark:border-gray-850 dark:bg-gray-850/50 dark:text-gray-500"
|
||||
>
|
||||
<Icon name="search" size={13} />
|
||||
<input
|
||||
bind:this={searchInput}
|
||||
class="min-w-0 flex-1 bg-transparent text-[0.8125rem] text-gray-800 outline-none placeholder:text-gray-400 dark:text-gray-100 dark:placeholder:text-gray-500"
|
||||
aria-label={$i18n.t('Search this folder')}
|
||||
title={$i18n.t('Search conversation titles and messages')}
|
||||
placeholder={$i18n.t('Search…')}
|
||||
maxlength="256"
|
||||
bind:value={search}
|
||||
on:input={searchChanged}
|
||||
on:blur={() => {
|
||||
if (!search) searchOpen = false;
|
||||
}}
|
||||
on:keydown={(event) => {
|
||||
if (event.key === 'Enter') apply();
|
||||
if (event.key === 'Escape') {
|
||||
search = '';
|
||||
apply();
|
||||
searchOpen = false;
|
||||
searchInput.blur();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{#if search}
|
||||
<button
|
||||
type="button"
|
||||
class="flex size-4 shrink-0 items-center justify-center rounded-full hover:text-gray-700 dark:hover:text-gray-200"
|
||||
aria-label={$i18n.t('Clear search')}
|
||||
on:mousedown|preventDefault
|
||||
on:click={() => {
|
||||
search = '';
|
||||
apply();
|
||||
searchInput?.focus();
|
||||
}}><XMark className="size-3" /></button
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<button
|
||||
type="button"
|
||||
class={iconButton}
|
||||
aria-label={$i18n.t('Search')}
|
||||
title={`${$i18n.t('Search')} /`}
|
||||
on:click={openSearch}><Icon name="search" size={14} /></button
|
||||
>
|
||||
{/if}
|
||||
|
||||
<Dropdown bind:show={filterShow} align="end" onOpenChange={() => (tagQuery = '')}>
|
||||
<button
|
||||
type="button"
|
||||
class="{iconButton} {filterCount ? 'text-gray-800 dark:text-gray-100' : ''}"
|
||||
aria-label={$i18n.t('Filter')}
|
||||
title={`${$i18n.t('Filter')} F`}
|
||||
>
|
||||
<svg
|
||||
class="size-3.75"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
aria-hidden="true"><path d="M2.5 4h11M4.5 8h7M6.5 12h3" /></svg
|
||||
{#if folderSection === 'automations'}
|
||||
{#if !readOnly}
|
||||
<button
|
||||
type="button"
|
||||
class={iconButton}
|
||||
aria-label={$i18n.t('New automation')}
|
||||
title={$i18n.t('New automation')}
|
||||
on:click={() => automationsView?.startNew()}
|
||||
><Plus className="size-3.5" strokeWidth="2" /></button
|
||||
>
|
||||
</button>
|
||||
{/if}
|
||||
{:else}
|
||||
{#if searchOpen || search}
|
||||
<div
|
||||
class="flex h-6.5 w-40 items-center gap-1.5 rounded-full border border-gray-100 bg-gray-50/60 px-2 text-gray-400 @lg:w-52 dark:border-gray-850 dark:bg-gray-850/50 dark:text-gray-500"
|
||||
>
|
||||
<Icon name="search" size={13} />
|
||||
<input
|
||||
bind:this={searchInput}
|
||||
class="min-w-0 flex-1 bg-transparent text-[0.8125rem] text-gray-800 outline-none placeholder:text-gray-400 dark:text-gray-100 dark:placeholder:text-gray-500"
|
||||
aria-label={$i18n.t('Search this folder')}
|
||||
title={$i18n.t('Search conversation titles and messages')}
|
||||
placeholder={$i18n.t('Search…')}
|
||||
maxlength="256"
|
||||
bind:value={search}
|
||||
on:input={searchChanged}
|
||||
on:blur={() => {
|
||||
if (!search) searchOpen = false;
|
||||
}}
|
||||
on:keydown={(event) => {
|
||||
if (event.key === 'Enter') apply();
|
||||
if (event.key === 'Escape') {
|
||||
search = '';
|
||||
apply();
|
||||
searchOpen = false;
|
||||
searchInput.blur();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{#if search}
|
||||
<button
|
||||
type="button"
|
||||
class="flex size-4 shrink-0 items-center justify-center rounded-full hover:text-gray-700 dark:hover:text-gray-200"
|
||||
aria-label={$i18n.t('Clear search')}
|
||||
on:mousedown|preventDefault
|
||||
on:click={() => {
|
||||
search = '';
|
||||
apply();
|
||||
searchInput?.focus();
|
||||
}}><XMark className="size-3" /></button
|
||||
>
|
||||
{/if}
|
||||
</div>
|
||||
{:else}
|
||||
<button
|
||||
type="button"
|
||||
class={iconButton}
|
||||
aria-label={$i18n.t('Search')}
|
||||
title={`${$i18n.t('Search')} /`}
|
||||
on:click={openSearch}><Icon name="search" size={14} /></button
|
||||
>
|
||||
{/if}
|
||||
|
||||
<DropdownMenu slot="content" className="w-48">
|
||||
{#each facets as item (item.id)}
|
||||
<DropdownSub
|
||||
contentClass={subMenu}
|
||||
maxWidth={item.id === 'users' ? 224 : 320}
|
||||
sideOffset={6}
|
||||
<Dropdown bind:show={filterShow} align="end" onOpenChange={() => (tagQuery = '')}>
|
||||
<button
|
||||
type="button"
|
||||
class="{iconButton} {filterCount ? 'text-gray-800 dark:text-gray-100' : ''}"
|
||||
aria-label={$i18n.t('Filter')}
|
||||
title={`${$i18n.t('Filter')} F`}
|
||||
>
|
||||
<svg
|
||||
class="size-3.75"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.5"
|
||||
stroke-linecap="round"
|
||||
aria-hidden="true"><path d="M2.5 4h11M4.5 8h7M6.5 12h3" /></svg
|
||||
>
|
||||
</button>
|
||||
|
||||
<DropdownMenu slot="content" className="w-48">
|
||||
{#each facets as item (item.id)}
|
||||
<DropdownSub
|
||||
contentClass={subMenu}
|
||||
maxWidth={item.id === 'users' ? 224 : 320}
|
||||
sideOffset={6}
|
||||
>
|
||||
<button slot="trigger" type="button" class={subRow}>
|
||||
<span class="text-gray-500 dark:text-gray-400">{@render facetIcon(item.id)}</span>
|
||||
<span class="min-w-0 flex-1 truncate text-left">{$i18n.t(item.label)}</span>
|
||||
{#if facetCount(item.id)}<span class="text-xs tabular-nums text-gray-400"
|
||||
>{facetCount(item.id)}</span
|
||||
>{/if}
|
||||
<ChevronRight className="size-3.5 shrink-0 text-gray-400 rtl:rotate-180" />
|
||||
</button>
|
||||
|
||||
{#if (item.id === 'tags' && options.length > 8) || (item.id === 'users' && folderUsers.length > 8)}
|
||||
<div class="flex h-[1.6875rem] items-center gap-2 px-2">
|
||||
<Icon
|
||||
name="search"
|
||||
size={12}
|
||||
class="shrink-0 text-gray-400 dark:text-gray-500"
|
||||
/>
|
||||
<input
|
||||
class="min-w-0 flex-1 bg-transparent text-[0.8125rem] outline-none placeholder:text-gray-400 dark:placeholder:text-gray-500"
|
||||
aria-label={item.id === 'users'
|
||||
? $i18n.t('Find users')
|
||||
: $i18n.t('Find tags')}
|
||||
placeholder={item.id === 'users'
|
||||
? $i18n.t('Find users…')
|
||||
: $i18n.t('Find tags…')}
|
||||
bind:value={tagQuery}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{#if optionsError && item.id === 'tags'}
|
||||
<button type="button" class="text-red-500" on:click={loadOptions}
|
||||
>{$i18n.t('Could not load tags. Retry')}</button
|
||||
>
|
||||
{/if}
|
||||
{#each facetOptions(item.id, item.id === 'tags' || item.id === 'users' ? tagQuery : '') as option (`${option.facet}:${option.value}`)}
|
||||
<button
|
||||
type="button"
|
||||
role={item.id === 'status' || item.id === 'tags' || item.id === 'users'
|
||||
? 'menuitemcheckbox'
|
||||
: 'menuitemradio'}
|
||||
aria-checked={option.checked}
|
||||
on:click={() => toggleOption(option)}
|
||||
>
|
||||
{#if option.status}
|
||||
<StatusIcon status={option.status} />
|
||||
{:else if option.avatar}
|
||||
<img
|
||||
src={option.avatar}
|
||||
alt=""
|
||||
class="size-3.5 shrink-0 rounded-full object-cover"
|
||||
/>
|
||||
{:else if item.id === 'tags'}
|
||||
<span class="flex size-3.5 shrink-0 items-center justify-center"
|
||||
><span class="size-2 rounded-full {option.dot}"></span></span
|
||||
>
|
||||
{/if}
|
||||
<span class="min-w-0 flex-1 truncate text-left" title={option.label}
|
||||
>{option.label}</span
|
||||
>
|
||||
{#if option.count != null}<span
|
||||
class="shrink-0 text-xs tabular-nums text-gray-400">{option.count}</span
|
||||
>{/if}
|
||||
{#if option.checked}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
{:else}
|
||||
<div class="px-2 py-1.5 text-xs text-gray-400 dark:text-gray-500">
|
||||
{$i18n.t('No results')}
|
||||
</div>
|
||||
{/each}
|
||||
</DropdownSub>
|
||||
{/each}
|
||||
{#if filterCount}
|
||||
<hr class="border-gray-50/30 dark:border-gray-800/30" />
|
||||
<button type="button" on:click={clear}>
|
||||
<XMark className="size-3.5" />{$i18n.t('Clear filters')}
|
||||
</button>
|
||||
{/if}
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
|
||||
<Dropdown align="end">
|
||||
<button
|
||||
type="button"
|
||||
class={iconButton}
|
||||
aria-label={$i18n.t('Display options')}
|
||||
title={$i18n.t('Display options')}
|
||||
>
|
||||
<AdjustmentsHorizontal className="size-3.75" />
|
||||
</button>
|
||||
|
||||
<DropdownMenu slot="content" className="w-52">
|
||||
<div class="px-2 pt-1.5 pb-0.5 text-xs text-gray-400 dark:text-gray-500">
|
||||
{$i18n.t('Layout')}
|
||||
</div>
|
||||
{#each [['list', 'List', 'list'], ['board', 'Board', 'grid']] as const as [value, label, icon]}
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={view === value}
|
||||
on:click={() => setView(value)}
|
||||
>
|
||||
<Icon name={icon} size={14} />
|
||||
<span class="flex-1 text-left">{$i18n.t(label)}</span>
|
||||
{#if view === value}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
{/each}
|
||||
|
||||
<hr class="border-gray-50/30 dark:border-gray-800/30" />
|
||||
|
||||
{#if view === 'list'}
|
||||
{@render groupMenu(
|
||||
$i18n.t('Grouping'),
|
||||
grouping,
|
||||
['none', 'status', 'tags', 'activity'],
|
||||
(value) => setGrouping(value)
|
||||
)}
|
||||
{:else}
|
||||
{@render groupMenu(
|
||||
$i18n.t('Columns'),
|
||||
columnsBy,
|
||||
['status', 'tags', 'activity'],
|
||||
(value) => setColumns(value as Exclude<GroupBy, 'none'>)
|
||||
)}
|
||||
{@render groupMenu(
|
||||
$i18n.t('Rows'),
|
||||
rowsBy,
|
||||
(['none', 'status', 'tags', 'activity'] as const).filter(
|
||||
(value) => value !== columnsBy
|
||||
),
|
||||
(value) => setRows(value)
|
||||
)}
|
||||
{/if}
|
||||
|
||||
<DropdownSub contentClass={subMenu} maxWidth={320} sideOffset={6}>
|
||||
<button slot="trigger" type="button" class={subRow}>
|
||||
<span class="text-gray-500 dark:text-gray-400">{@render facetIcon(item.id)}</span>
|
||||
<span class="min-w-0 flex-1 truncate text-left">{$i18n.t(item.label)}</span>
|
||||
{#if facetCount(item.id)}<span class="text-xs tabular-nums text-gray-400"
|
||||
>{facetCount(item.id)}</span
|
||||
>{/if}
|
||||
<span class="min-w-0 flex-1 truncate text-left">{$i18n.t('Ordering')}</span>
|
||||
<span class="truncate text-gray-500 dark:text-gray-400"
|
||||
>{sortBy === 'title' ? $i18n.t('Title') : $i18n.t('Updated')}</span
|
||||
>
|
||||
<ChevronRight className="size-3.5 shrink-0 text-gray-400 rtl:rotate-180" />
|
||||
</button>
|
||||
|
||||
{#if (item.id === 'tags' && options.length > 8) || (item.id === 'users' && folderUsers.length > 8)}
|
||||
<div class="flex h-[1.6875rem] items-center gap-2 px-2">
|
||||
<Icon name="search" size={12} class="shrink-0 text-gray-400 dark:text-gray-500" />
|
||||
<input
|
||||
class="min-w-0 flex-1 bg-transparent text-[0.8125rem] outline-none placeholder:text-gray-400 dark:placeholder:text-gray-500"
|
||||
aria-label={item.id === 'users' ? $i18n.t('Find users') : $i18n.t('Find tags')}
|
||||
placeholder={item.id === 'users'
|
||||
? $i18n.t('Find users…')
|
||||
: $i18n.t('Find tags…')}
|
||||
bind:value={tagQuery}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
{#if optionsError && item.id === 'tags'}
|
||||
<button type="button" class="text-red-500" on:click={loadOptions}
|
||||
>{$i18n.t('Could not load tags. Retry')}</button
|
||||
>
|
||||
{/if}
|
||||
{#each facetOptions(item.id, item.id === 'tags' || item.id === 'users' ? tagQuery : '') as option (`${option.facet}:${option.value}`)}
|
||||
{#each [['updated_at', 'Updated'], ['title', 'Title']] as const as [value, label]}
|
||||
<button
|
||||
type="button"
|
||||
role={item.id === 'status' || item.id === 'tags' || item.id === 'users'
|
||||
? 'menuitemcheckbox'
|
||||
: 'menuitemradio'}
|
||||
aria-checked={option.checked}
|
||||
on:click={() => toggleOption(option)}
|
||||
role="menuitemradio"
|
||||
aria-checked={sortBy === value}
|
||||
on:click={() => setSort(value)}
|
||||
>
|
||||
{#if option.status}
|
||||
<StatusIcon status={option.status} />
|
||||
{:else if option.avatar}
|
||||
<img
|
||||
src={option.avatar}
|
||||
alt=""
|
||||
class="size-3.5 shrink-0 rounded-full object-cover"
|
||||
/>
|
||||
{:else if item.id === 'tags'}
|
||||
<span class="flex size-3.5 shrink-0 items-center justify-center"
|
||||
><span class="size-2 rounded-full {option.dot}"></span></span
|
||||
>
|
||||
{/if}
|
||||
<span class="min-w-0 flex-1 truncate text-left" title={option.label}
|
||||
>{option.label}</span
|
||||
>
|
||||
{#if option.count != null}<span
|
||||
class="shrink-0 text-xs tabular-nums text-gray-400">{option.count}</span
|
||||
>{/if}
|
||||
{#if option.checked}<Check className="size-3! shrink-0" />{/if}
|
||||
<span class="flex-1 text-left">{$i18n.t(label)}</span>
|
||||
{#if sortBy === value}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
{/each}
|
||||
<hr class="border-gray-50/30 dark:border-gray-800/30" />
|
||||
{#each [['asc', 'Ascending'], ['desc', 'Descending']] as const as [value, label]}
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={sortDir === value}
|
||||
on:click={() => setSort(sortBy, value)}
|
||||
>
|
||||
<span class="flex-1 text-left">{$i18n.t(label)}</span>
|
||||
{#if sortDir === value}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
{:else}
|
||||
<div class="px-2 py-1.5 text-xs text-gray-400 dark:text-gray-500">
|
||||
{$i18n.t('No results')}
|
||||
</div>
|
||||
{/each}
|
||||
</DropdownSub>
|
||||
{/each}
|
||||
{#if filterCount}
|
||||
<hr class="border-gray-50/30 dark:border-gray-800/30" />
|
||||
<button type="button" on:click={clear}>
|
||||
<XMark className="size-3.5" />{$i18n.t('Clear filters')}
|
||||
</button>
|
||||
{/if}
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
|
||||
<Dropdown align="end">
|
||||
<button
|
||||
type="button"
|
||||
class={iconButton}
|
||||
aria-label={$i18n.t('Display options')}
|
||||
title={$i18n.t('Display options')}
|
||||
>
|
||||
<AdjustmentsHorizontal className="size-3.75" />
|
||||
</button>
|
||||
|
||||
<DropdownMenu slot="content" className="w-52">
|
||||
<div class="px-2 pt-1.5 pb-0.5 text-xs text-gray-400 dark:text-gray-500">
|
||||
{$i18n.t('Layout')}
|
||||
</div>
|
||||
{#each [['list', 'List', 'list'], ['board', 'Board', 'grid']] as const as [value, label, icon]}
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={view === value}
|
||||
on:click={() => setView(value)}
|
||||
>
|
||||
<Icon name={icon} size={14} />
|
||||
<span class="flex-1 text-left">{$i18n.t(label)}</span>
|
||||
{#if view === value}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
{/each}
|
||||
|
||||
<hr class="border-gray-50/30 dark:border-gray-800/30" />
|
||||
|
||||
{#if view === 'list'}
|
||||
{@render groupMenu(
|
||||
$i18n.t('Grouping'),
|
||||
grouping,
|
||||
['none', 'status', 'tags', 'activity'],
|
||||
(value) => setGrouping(value)
|
||||
)}
|
||||
{:else}
|
||||
{@render groupMenu(
|
||||
$i18n.t('Columns'),
|
||||
columnsBy,
|
||||
['status', 'tags', 'activity'],
|
||||
(value) => setColumns(value as Exclude<GroupBy, 'none'>)
|
||||
)}
|
||||
{@render groupMenu(
|
||||
$i18n.t('Rows'),
|
||||
rowsBy,
|
||||
(['none', 'status', 'tags', 'activity'] as const).filter(
|
||||
(value) => value !== columnsBy
|
||||
),
|
||||
(value) => setRows(value)
|
||||
)}
|
||||
{/if}
|
||||
|
||||
<DropdownSub contentClass={subMenu} maxWidth={320} sideOffset={6}>
|
||||
<button slot="trigger" type="button" class={subRow}>
|
||||
<span class="min-w-0 flex-1 truncate text-left">{$i18n.t('Ordering')}</span>
|
||||
<span class="truncate text-gray-500 dark:text-gray-400"
|
||||
>{sortBy === 'title' ? $i18n.t('Title') : $i18n.t('Updated')}</span
|
||||
>
|
||||
<ChevronRight className="size-3.5 shrink-0 text-gray-400 rtl:rotate-180" />
|
||||
</button>
|
||||
{#each [['updated_at', 'Updated'], ['title', 'Title']] as const as [value, label]}
|
||||
{#if view === 'list' && grouping !== 'none'}
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={sortBy === value}
|
||||
on:click={() => setSort(value)}
|
||||
role="menuitemcheckbox"
|
||||
aria-checked={showEmptyGroups}
|
||||
on:click={() => {
|
||||
showEmptyGroups = !showEmptyGroups;
|
||||
savePrefs();
|
||||
}}
|
||||
>
|
||||
<span class="flex-1 text-left">{$i18n.t(label)}</span>
|
||||
{#if sortBy === value}<Check className="size-3! shrink-0" />{/if}
|
||||
<span class="flex-1 text-left">{$i18n.t('Show empty groups')}</span>
|
||||
{#if showEmptyGroups}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
{/each}
|
||||
<hr class="border-gray-50/30 dark:border-gray-800/30" />
|
||||
{#each [['asc', 'Ascending'], ['desc', 'Descending']] as const as [value, label]}
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={sortDir === value}
|
||||
on:click={() => setSort(sortBy, value)}
|
||||
>
|
||||
<span class="flex-1 text-left">{$i18n.t(label)}</span>
|
||||
{#if sortDir === value}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
{/each}
|
||||
</DropdownSub>
|
||||
|
||||
{#if view === 'list' && grouping !== 'none'}
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemcheckbox"
|
||||
aria-checked={showEmptyGroups}
|
||||
on:click={() => {
|
||||
showEmptyGroups = !showEmptyGroups;
|
||||
savePrefs();
|
||||
}}
|
||||
>
|
||||
<span class="flex-1 text-left">{$i18n.t('Show empty groups')}</span>
|
||||
{#if showEmptyGroups}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
{/if}
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
{/if}
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1254,7 +1348,7 @@
|
||||
</p>
|
||||
{/if}
|
||||
|
||||
{#if filterCount}
|
||||
{#if filterCount && folderSection === 'chats'}
|
||||
<div class="flex shrink-0 flex-wrap items-center gap-1 px-2.5 pb-1.5 md:px-3.5">
|
||||
{#if statusFilter.length}
|
||||
{@render chip(
|
||||
@@ -1320,7 +1414,16 @@
|
||||
{/if}
|
||||
|
||||
<div class="min-h-0 min-w-0 flex-1 overflow-hidden">
|
||||
{#if loading && !hasData}
|
||||
{#if folderSection === 'automations'}
|
||||
<FolderAutomations
|
||||
bind:this={automationsView}
|
||||
folderId={folder?.id ?? ''}
|
||||
{automations}
|
||||
loading={automationsLoading}
|
||||
canCreate={!readOnly}
|
||||
onReload={loadAutomations}
|
||||
/>
|
||||
{:else if loading && !hasData}
|
||||
<div
|
||||
role="status"
|
||||
aria-label={$i18n.t('Loading…')}
|
||||
|
||||
@@ -1249,7 +1249,8 @@
|
||||
|
||||
$: hasMessages = history?.messages && Object.keys(history.messages).length > 0;
|
||||
|
||||
const chatContextNeedsSavedChat = (terminal: any) => terminal?.scope === 'chat';
|
||||
const chatContextNeedsSavedChat = (terminal: any) =>
|
||||
['chat', 'folder'].includes(terminal?.scope);
|
||||
$: selectedSystemTerminal = ($terminalServers ?? []).find(
|
||||
(t) => !!$selectedTerminalId && t.id === $selectedTerminalId
|
||||
);
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
const scopes = [
|
||||
{ value: 'user', label: 'User', hint: 'Each person gets their own instance.' },
|
||||
{ value: 'chat', label: 'Chat', hint: 'Each chat gets its own instance.' },
|
||||
{ value: 'folder', label: 'Folder', hint: 'Each folder gets its own instance.' },
|
||||
{ value: 'model', label: 'Model', hint: 'Each model gets its own instance.' }
|
||||
];
|
||||
// Open Terminal reads these at start-up; the dialog gives them their own fields.
|
||||
|
||||
@@ -100,6 +100,8 @@ export type WorkspaceChat = {
|
||||
active?: boolean;
|
||||
pending_approval?: boolean;
|
||||
search_snippet?: string | null;
|
||||
/** Set when an automation made this chat. */
|
||||
automation_id?: string | null;
|
||||
};
|
||||
export const statusKey = (status?: FolderStatus | null) => status ?? NO_STATUS;
|
||||
|
||||
|
||||
Reference in new issue
Block a user