@svadmin/ui 0.29.0 → 0.29.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +20 -9
- package/src/README.md +0 -18
- package/src/actions.ts +0 -110
- package/src/app.css +0 -519
- package/src/component-registry.svelte.ts +0 -60
- package/src/components/AICommandBar.svelte +0 -180
- package/src/components/AboutSettings.svelte +0 -106
- package/src/components/AdminApp.svelte +0 -199
- package/src/components/AnimatedCounter.svelte +0 -46
- package/src/components/AnomalyBadge.svelte +0 -65
- package/src/components/AppearanceSettings.svelte +0 -183
- package/src/components/AuditLogDrawer.svelte +0 -93
- package/src/components/AuditLogViewer.svelte +0 -226
- package/src/components/Authenticated.svelte +0 -51
- package/src/components/AutoForm.svelte +0 -242
- package/src/components/AutoSaveIndicator.svelte +0 -35
- package/src/components/AutoTable.svelte +0 -839
- package/src/components/Breadcrumbs.svelte +0 -58
- package/src/components/CanAccess.svelte +0 -23
- package/src/components/CatchAllNavigate.svelte +0 -21
- package/src/components/ChatDialog.svelte +0 -535
- package/src/components/ComboboxField.svelte +0 -129
- package/src/components/CommandPalette.svelte +0 -135
- package/src/components/ConfigErrorScreen.svelte +0 -126
- package/src/components/ConfirmDialog.svelte +0 -53
- package/src/components/CopilotPanel.svelte +0 -163
- package/src/components/CreatePage.svelte +0 -39
- package/src/components/DevTools.svelte +0 -149
- package/src/components/DraggableGrid.svelte +0 -86
- package/src/components/DraggableHeader.svelte +0 -112
- package/src/components/DrawerForm.svelte +0 -35
- package/src/components/EditPage.svelte +0 -52
- package/src/components/EmptyState.svelte +0 -31
- package/src/components/ErrorBoundary.svelte +0 -49
- package/src/components/ErrorComponent.svelte +0 -36
- package/src/components/FieldRenderer.svelte +0 -357
- package/src/components/ForgotPasswordPage.svelte +0 -112
- package/src/components/Header.svelte +0 -94
- package/src/components/InferencerPanel.svelte +0 -192
- package/src/components/InfiniteList.svelte +0 -93
- package/src/components/InlineEdit.svelte +0 -88
- package/src/components/InsightCard.svelte +0 -98
- package/src/components/KeyboardShortcuts.svelte +0 -61
- package/src/components/Layout.svelte +0 -167
- package/src/components/ListPage.svelte +0 -71
- package/src/components/LiveIndicator.svelte +0 -58
- package/src/components/LoginPage.svelte +0 -163
- package/src/components/MarkdownRenderer.svelte +0 -127
- package/src/components/ModalForm.svelte +0 -38
- package/src/components/NavigateToResource.svelte +0 -20
- package/src/components/PageHeader.svelte +0 -39
- package/src/components/PageSkeleton.svelte +0 -71
- package/src/components/PasswordInput.svelte +0 -96
- package/src/components/PermissionMatrix.svelte +0 -185
- package/src/components/ProfilePage.svelte +0 -284
- package/src/components/RegisterPage.svelte +0 -112
- package/src/components/RolesSettings.svelte +0 -146
- package/src/components/SettingsPage.svelte +0 -113
- package/src/components/ShowPage.svelte +0 -73
- package/src/components/Sidebar.svelte +0 -417
- package/src/components/SidebarItem.svelte +0 -129
- package/src/components/SmartSuggest.svelte +0 -158
- package/src/components/StatsCard.svelte +0 -79
- package/src/components/StepsForm.svelte +0 -192
- package/src/components/TaskQueueDrawer.svelte +0 -158
- package/src/components/TenantSwitcher.svelte +0 -84
- package/src/components/ThemedTitle.svelte +0 -32
- package/src/components/Toast.svelte +0 -46
- package/src/components/TooltipButton.svelte +0 -42
- package/src/components/UndoableNotification.svelte +0 -69
- package/src/components/UpdatePasswordPage.svelte +0 -89
- package/src/components/VirtualTable.svelte +0 -76
- package/src/components/VoiceInput.svelte +0 -120
- package/src/components/buttons/CloneButton.svelte +0 -30
- package/src/components/buttons/CreateButton.svelte +0 -29
- package/src/components/buttons/DeleteButton.svelte +0 -59
- package/src/components/buttons/EditButton.svelte +0 -30
- package/src/components/buttons/ExportButton.svelte +0 -30
- package/src/components/buttons/ImportButton.svelte +0 -56
- package/src/components/buttons/ListButton.svelte +0 -23
- package/src/components/buttons/RefreshButton.svelte +0 -36
- package/src/components/buttons/SaveButton.svelte +0 -27
- package/src/components/buttons/ShowButton.svelte +0 -31
- package/src/components/buttons/index.ts +0 -10
- package/src/components/charts/BarChart.svelte +0 -69
- package/src/components/charts/LineChart.svelte +0 -115
- package/src/components/charts/PieChart.svelte +0 -95
- package/src/components/charts/index.ts +0 -3
- package/src/components/fieldComponentMap.ts +0 -79
- package/src/components/fields/ArrayField.svelte +0 -86
- package/src/components/fields/BooleanField.svelte +0 -13
- package/src/components/fields/DateField.svelte +0 -6
- package/src/components/fields/EmailField.svelte +0 -9
- package/src/components/fields/FileField.svelte +0 -14
- package/src/components/fields/ImageField.svelte +0 -9
- package/src/components/fields/JsonField.svelte +0 -72
- package/src/components/fields/MarkdownField.svelte +0 -9
- package/src/components/fields/MultiSelectField.svelte +0 -21
- package/src/components/fields/NumberField.svelte +0 -6
- package/src/components/fields/RelationField.svelte +0 -24
- package/src/components/fields/RichTextField.svelte +0 -35
- package/src/components/fields/SelectField.svelte +0 -14
- package/src/components/fields/TagField.svelte +0 -12
- package/src/components/fields/TextField.svelte +0 -11
- package/src/components/fields/UrlField.svelte +0 -14
- package/src/components/ui/alert/alert-description.svelte +0 -17
- package/src/components/ui/alert/alert-title.svelte +0 -17
- package/src/components/ui/alert/alert.svelte +0 -44
- package/src/components/ui/alert/index.ts +0 -15
- package/src/components/ui/alert-dialog/alert-dialog-content.svelte +0 -29
- package/src/components/ui/alert-dialog/alert-dialog-description.svelte +0 -16
- package/src/components/ui/alert-dialog/alert-dialog-footer.svelte +0 -11
- package/src/components/ui/alert-dialog/alert-dialog-header.svelte +0 -11
- package/src/components/ui/alert-dialog/alert-dialog-overlay.svelte +0 -16
- package/src/components/ui/alert-dialog/alert-dialog-portal.svelte +0 -6
- package/src/components/ui/alert-dialog/alert-dialog-title.svelte +0 -16
- package/src/components/ui/alert-dialog/index.ts +0 -20
- package/src/components/ui/avatar/avatar.svelte +0 -63
- package/src/components/ui/avatar/index.ts +0 -2
- package/src/components/ui/badge/badge.svelte +0 -49
- package/src/components/ui/badge/index.ts +0 -3
- package/src/components/ui/breadcrumb/breadcrumb-ellipsis.svelte +0 -18
- package/src/components/ui/breadcrumb/breadcrumb-item.svelte +0 -15
- package/src/components/ui/breadcrumb/breadcrumb-link.svelte +0 -15
- package/src/components/ui/breadcrumb/breadcrumb-list.svelte +0 -15
- package/src/components/ui/breadcrumb/breadcrumb-page.svelte +0 -18
- package/src/components/ui/breadcrumb/breadcrumb-separator.svelte +0 -22
- package/src/components/ui/breadcrumb/breadcrumb.svelte +0 -11
- package/src/components/ui/breadcrumb/index.ts +0 -7
- package/src/components/ui/button/button.svelte +0 -90
- package/src/components/ui/button/index.ts +0 -18
- package/src/components/ui/card/card-action.svelte +0 -23
- package/src/components/ui/card/card-content.svelte +0 -20
- package/src/components/ui/card/card-description.svelte +0 -20
- package/src/components/ui/card/card-footer.svelte +0 -20
- package/src/components/ui/card/card-header.svelte +0 -23
- package/src/components/ui/card/card-title.svelte +0 -15
- package/src/components/ui/card/card.svelte +0 -22
- package/src/components/ui/card/index.ts +0 -25
- package/src/components/ui/checkbox/checkbox.svelte +0 -39
- package/src/components/ui/checkbox/index.ts +0 -6
- package/src/components/ui/collapsible/index.ts +0 -7
- package/src/components/ui/command/command-dialog.svelte +0 -31
- package/src/components/ui/command/index.ts +0 -2
- package/src/components/ui/context-menu/index.ts +0 -11
- package/src/components/ui/dialog/dialog-close.svelte +0 -11
- package/src/components/ui/dialog/dialog-content.svelte +0 -48
- package/src/components/ui/dialog/dialog-description.svelte +0 -17
- package/src/components/ui/dialog/dialog-footer.svelte +0 -32
- package/src/components/ui/dialog/dialog-header.svelte +0 -20
- package/src/components/ui/dialog/dialog-overlay.svelte +0 -17
- package/src/components/ui/dialog/dialog-portal.svelte +0 -7
- package/src/components/ui/dialog/dialog-title.svelte +0 -17
- package/src/components/ui/dialog/dialog-trigger.svelte +0 -11
- package/src/components/ui/dialog/dialog.svelte +0 -7
- package/src/components/ui/dialog/index.ts +0 -34
- package/src/components/ui/dropdown-menu/dropdown-menu-checkbox-item.svelte +0 -43
- package/src/components/ui/dropdown-menu/dropdown-menu-content.svelte +0 -35
- package/src/components/ui/dropdown-menu/dropdown-menu-item.svelte +0 -36
- package/src/components/ui/dropdown-menu/dropdown-menu-separator.svelte +0 -10
- package/src/components/ui/dropdown-menu/dropdown-menu-trigger.svelte +0 -27
- package/src/components/ui/dropdown-menu/dropdown-menu.svelte +0 -45
- package/src/components/ui/dropdown-menu/index.ts +0 -21
- package/src/components/ui/input/index.ts +0 -7
- package/src/components/ui/input/input.svelte +0 -48
- package/src/components/ui/label/index.ts +0 -1
- package/src/components/ui/label/label.svelte +0 -18
- package/src/components/ui/pagination/index.ts +0 -7
- package/src/components/ui/pagination/pagination-content.svelte +0 -11
- package/src/components/ui/pagination/pagination-ellipsis.svelte +0 -12
- package/src/components/ui/pagination/pagination-item.svelte +0 -11
- package/src/components/ui/pagination/pagination-link.svelte +0 -26
- package/src/components/ui/pagination/pagination-next.svelte +0 -22
- package/src/components/ui/pagination/pagination-previous.svelte +0 -22
- package/src/components/ui/pagination/pagination.svelte +0 -11
- package/src/components/ui/popover/index.ts +0 -12
- package/src/components/ui/popover/popover-content.svelte +0 -25
- package/src/components/ui/progress/index.ts +0 -1
- package/src/components/ui/progress/progress.svelte +0 -22
- package/src/components/ui/scroll-area/index.ts +0 -1
- package/src/components/ui/scroll-area/scroll-area.svelte +0 -20
- package/src/components/ui/select/index.ts +0 -2
- package/src/components/ui/select/select.svelte +0 -36
- package/src/components/ui/separator/index.ts +0 -7
- package/src/components/ui/separator/separator.svelte +0 -23
- package/src/components/ui/sheet/index.ts +0 -16
- package/src/components/ui/sheet/sheet-content.svelte +0 -28
- package/src/components/ui/sheet/sheet-description.svelte +0 -22
- package/src/components/ui/sheet/sheet-footer.svelte +0 -22
- package/src/components/ui/sheet/sheet-header.svelte +0 -22
- package/src/components/ui/sheet/sheet-title.svelte +0 -22
- package/src/components/ui/sheet/sheet.svelte +0 -78
- package/src/components/ui/skeleton/index.ts +0 -2
- package/src/components/ui/skeleton/skeleton.svelte +0 -21
- package/src/components/ui/switch/index.ts +0 -2
- package/src/components/ui/switch/switch.svelte +0 -49
- package/src/components/ui/table/index.ts +0 -28
- package/src/components/ui/table/table-body.svelte +0 -15
- package/src/components/ui/table/table-caption.svelte +0 -20
- package/src/components/ui/table/table-cell.svelte +0 -15
- package/src/components/ui/table/table-footer.svelte +0 -20
- package/src/components/ui/table/table-head.svelte +0 -15
- package/src/components/ui/table/table-header.svelte +0 -20
- package/src/components/ui/table/table-row.svelte +0 -15
- package/src/components/ui/table/table.svelte +0 -17
- package/src/components/ui/tabs/index.ts +0 -15
- package/src/components/ui/tabs/tabs-content.svelte +0 -30
- package/src/components/ui/tabs/tabs-list.svelte +0 -26
- package/src/components/ui/tabs/tabs-trigger.svelte +0 -37
- package/src/components/ui/tabs/tabs.svelte +0 -27
- package/src/components/ui/textarea/index.ts +0 -2
- package/src/components/ui/textarea/textarea.svelte +0 -24
- package/src/components/ui/tooltip/index.ts +0 -19
- package/src/components/ui/tooltip/tooltip-content.svelte +0 -52
- package/src/components/ui/tooltip/tooltip-portal.svelte +0 -7
- package/src/components/ui/tooltip/tooltip-provider.svelte +0 -7
- package/src/components/ui/tooltip/tooltip-trigger.svelte +0 -7
- package/src/components/ui/tooltip/tooltip.svelte +0 -10
- package/src/editor-config.svelte.ts +0 -23
- package/src/index.ts +0 -155
- package/src/markdown-deps.d.ts +0 -21
- package/src/router-state.svelte.ts +0 -65
- package/src/types.ts +0 -33
- package/src/utils.ts +0 -28
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { getResources } from '@svadmin/core';
|
|
3
|
-
import { currentPath } from '@svadmin/core/router';
|
|
4
|
-
import { t } from '@svadmin/core/i18n';
|
|
5
|
-
import * as Breadcrumb from './ui/breadcrumb/index.js';
|
|
6
|
-
|
|
7
|
-
const resources = getResources();
|
|
8
|
-
let path = $state(currentPath());
|
|
9
|
-
|
|
10
|
-
function onHashChange() { path = currentPath(); }
|
|
11
|
-
|
|
12
|
-
interface Crumb { label: string; href: string; }
|
|
13
|
-
|
|
14
|
-
const crumbs = $derived.by(() => {
|
|
15
|
-
const result: Crumb[] = [{ label: t('common.home'), href: '#/' }];
|
|
16
|
-
if (path === '/') return result;
|
|
17
|
-
|
|
18
|
-
const segments = path.split('/').filter(Boolean);
|
|
19
|
-
const resourceName = segments[0];
|
|
20
|
-
const res = resources.find(r => r.name === resourceName);
|
|
21
|
-
|
|
22
|
-
if (res) {
|
|
23
|
-
result.push({ label: res.label, href: `#/${res.name}` });
|
|
24
|
-
|
|
25
|
-
if (segments[1] === 'create') {
|
|
26
|
-
result.push({ label: t('common.create'), href: `#/${res.name}/create` });
|
|
27
|
-
} else if (segments[1] === 'edit' && segments[2]) {
|
|
28
|
-
result.push({ label: `${t('common.edit')} #${segments[2]}`, href: `#/${res.name}/edit/${segments[2]}` });
|
|
29
|
-
} else if (segments[1] === 'show' && segments[2]) {
|
|
30
|
-
result.push({ label: `${t('common.detail')} #${segments[2]}`, href: `#/${res.name}/show/${segments[2]}` });
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
});
|
|
35
|
-
</script>
|
|
36
|
-
|
|
37
|
-
<svelte:window onhashchange={onHashChange} />
|
|
38
|
-
|
|
39
|
-
{#if crumbs.length > 1}
|
|
40
|
-
<Breadcrumb.Root class="mb-4">
|
|
41
|
-
<Breadcrumb.List>
|
|
42
|
-
{#each crumbs as crumb, i (crumb.href)}
|
|
43
|
-
{#if i > 0}
|
|
44
|
-
<Breadcrumb.Separator />
|
|
45
|
-
{/if}
|
|
46
|
-
<Breadcrumb.Item>
|
|
47
|
-
<span class="inline-flex svadmin-page-enter" style="animation-duration: 0.2s;">
|
|
48
|
-
{#if i === crumbs.length - 1}
|
|
49
|
-
<Breadcrumb.Page>{crumb.label}</Breadcrumb.Page>
|
|
50
|
-
{:else}
|
|
51
|
-
<Breadcrumb.Link href={crumb.href}>{crumb.label}</Breadcrumb.Link>
|
|
52
|
-
{/if}
|
|
53
|
-
</span>
|
|
54
|
-
</Breadcrumb.Item>
|
|
55
|
-
{/each}
|
|
56
|
-
</Breadcrumb.List>
|
|
57
|
-
</Breadcrumb.Root>
|
|
58
|
-
{/if}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import type { Snippet } from 'svelte';
|
|
3
|
-
import { useCan } from '@svadmin/core';
|
|
4
|
-
import type { Action } from '@svadmin/core';
|
|
5
|
-
|
|
6
|
-
let { resource, action, params, children, fallback } = $props<{
|
|
7
|
-
resource: string;
|
|
8
|
-
action: Action;
|
|
9
|
-
params?: Record<string, unknown>;
|
|
10
|
-
children: Snippet;
|
|
11
|
-
fallback?: Snippet;
|
|
12
|
-
}>();
|
|
13
|
-
|
|
14
|
-
const can = useCan(() => ({ resource, action, params }));
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
{#if can.isLoading}
|
|
18
|
-
<!-- Loading: nothing rendered -->
|
|
19
|
-
{:else if can.allowed}
|
|
20
|
-
{@render children()}
|
|
21
|
-
{:else if fallback}
|
|
22
|
-
{@render fallback()}
|
|
23
|
-
{/if}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { useIsAuthenticated } from '@svadmin/core';
|
|
3
|
-
import { navigate } from '@svadmin/core/router';
|
|
4
|
-
import NavigateToResource from './NavigateToResource.svelte';
|
|
5
|
-
|
|
6
|
-
const auth = useIsAuthenticated();
|
|
7
|
-
|
|
8
|
-
$effect(() => {
|
|
9
|
-
if (!auth.isLoading && !auth.isAuthenticated) {
|
|
10
|
-
navigate('/login');
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
</script>
|
|
14
|
-
|
|
15
|
-
{#if auth.isLoading}
|
|
16
|
-
<div class="flex h-screen w-screen items-center justify-center">
|
|
17
|
-
<div class="h-8 w-8 animate-spin rounded-full border-4 border-primary border-r-transparent"></div>
|
|
18
|
-
</div>
|
|
19
|
-
{:else if auth.isAuthenticated}
|
|
20
|
-
<NavigateToResource />
|
|
21
|
-
{/if}
|
|
@@ -1,535 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { getChatProvider, getChatContext, setChatContext, getAgentProvider, registerApproval, resolveApproval } from '@svadmin/core';
|
|
3
|
-
import type { ChatMessage, ChatAction, AgentEvent } from '@svadmin/core';
|
|
4
|
-
import { t } from '@svadmin/core/i18n';
|
|
5
|
-
import { useParsed } from '@svadmin/core';
|
|
6
|
-
import { fly, fade, scale } from 'svelte/transition';
|
|
7
|
-
import { Button } from './ui/button/index.js';
|
|
8
|
-
import TooltipButton from './TooltipButton.svelte';
|
|
9
|
-
import { MessageCircle, X, Minus, Send, Loader2, Bot, Trash2, ShieldCheck, ShieldX, Wrench, LayoutDashboard } from '@lucide/svelte';
|
|
10
|
-
|
|
11
|
-
interface Props {
|
|
12
|
-
/** localStorage key for chat history persistence. Set to '' to disable. */
|
|
13
|
-
persistKey?: string;
|
|
14
|
-
/** Custom persistence callback — called when messages change */
|
|
15
|
-
onPersist?: (messages: ChatMessage[]) => void;
|
|
16
|
-
/** Custom restore callback — called on mount to load history */
|
|
17
|
-
onRestore?: () => ChatMessage[];
|
|
18
|
-
/** Callback when user clicks an action button in an assistant message */
|
|
19
|
-
onAction?: (action: ChatAction, message: ChatMessage) => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const {
|
|
23
|
-
persistKey = 'svadmin-chat',
|
|
24
|
-
onPersist,
|
|
25
|
-
onRestore,
|
|
26
|
-
onAction,
|
|
27
|
-
}: Props = $props();
|
|
28
|
-
|
|
29
|
-
let open = $state(false);
|
|
30
|
-
let minimized = $state(false);
|
|
31
|
-
let inputValue = $state('');
|
|
32
|
-
let messages = $state<ChatMessage[]>([]);
|
|
33
|
-
let isStreaming = $state(false);
|
|
34
|
-
let messagesContainer: HTMLDivElement | undefined = $state();
|
|
35
|
-
let abortController: AbortController | null = null;
|
|
36
|
-
let messageIdCounter = $state(0);
|
|
37
|
-
let initialized = $state(false);
|
|
38
|
-
|
|
39
|
-
const provider = $derived(getChatProvider());
|
|
40
|
-
const agent = $derived(getAgentProvider());
|
|
41
|
-
const parsed = useParsed();
|
|
42
|
-
|
|
43
|
-
/** Track pending approval requests for UI rendering */
|
|
44
|
-
let pendingApprovalIds = $state<string[]>([]);
|
|
45
|
-
|
|
46
|
-
// ─── Auto-update ChatContext from current route ─────────────
|
|
47
|
-
$effect(() => {
|
|
48
|
-
setChatContext({
|
|
49
|
-
currentResource: parsed.resource,
|
|
50
|
-
selectedRecordId: parsed.id,
|
|
51
|
-
currentView: parsed.action as 'list' | 'edit' | 'create' | 'show' | undefined,
|
|
52
|
-
pathname: `/${parsed.resource ?? ''}${parsed.action ? '/' + parsed.action : ''}${parsed.id ? '/' + parsed.id : ''}`,
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// ─── Restore persisted history on mount ─────────────────────
|
|
57
|
-
$effect(() => {
|
|
58
|
-
if (initialized) return;
|
|
59
|
-
initialized = true;
|
|
60
|
-
if (onRestore) {
|
|
61
|
-
messages = onRestore();
|
|
62
|
-
} else if (persistKey) {
|
|
63
|
-
try {
|
|
64
|
-
const stored = localStorage.getItem(persistKey);
|
|
65
|
-
if (stored) {
|
|
66
|
-
const parsed = JSON.parse(stored) as ChatMessage[];
|
|
67
|
-
if (Array.isArray(parsed) && parsed.length > 0) {
|
|
68
|
-
messages = parsed;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
} catch {
|
|
72
|
-
// ignore corrupt data
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
// ─── Persist on change (debounced) ──────────────────────────
|
|
78
|
-
let persistTimer: ReturnType<typeof setTimeout> | null = null;
|
|
79
|
-
|
|
80
|
-
$effect(() => {
|
|
81
|
-
// Access `messages` to subscribe to changes
|
|
82
|
-
const snapshot = messages;
|
|
83
|
-
if (!initialized) return;
|
|
84
|
-
|
|
85
|
-
if (persistTimer) clearTimeout(persistTimer);
|
|
86
|
-
persistTimer = setTimeout(() => {
|
|
87
|
-
if (onPersist) {
|
|
88
|
-
onPersist(snapshot);
|
|
89
|
-
} else if (persistKey) {
|
|
90
|
-
try {
|
|
91
|
-
localStorage.setItem(persistKey, JSON.stringify(snapshot));
|
|
92
|
-
} catch {
|
|
93
|
-
// storage full or unavailable
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}, 300);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
function genId(): string {
|
|
100
|
-
messageIdCounter++;
|
|
101
|
-
return `msg-${Date.now()}-${messageIdCounter}`;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function scrollToBottom() {
|
|
105
|
-
requestAnimationFrame(() => {
|
|
106
|
-
if (messagesContainer) {
|
|
107
|
-
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Build a system message with the current admin context */
|
|
113
|
-
function buildContextSystemMessage(): ChatMessage | null {
|
|
114
|
-
const ctx = getChatContext();
|
|
115
|
-
if (!ctx.currentResource) return null;
|
|
116
|
-
|
|
117
|
-
const parts: string[] = [];
|
|
118
|
-
parts.push(`Resource: ${ctx.currentResource}`);
|
|
119
|
-
if (ctx.currentView) parts.push(`View: ${ctx.currentView}`);
|
|
120
|
-
if (ctx.selectedRecordId) parts.push(`Selected Record ID: ${ctx.selectedRecordId}`);
|
|
121
|
-
if (ctx.pathname) parts.push(`Path: ${ctx.pathname}`);
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
id: 'ctx-system',
|
|
125
|
-
role: 'system',
|
|
126
|
-
content: `[Admin Context] ${parts.join(' | ')}`,
|
|
127
|
-
timestamp: Date.now(),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async function sendMessage() {
|
|
132
|
-
if (!inputValue.trim() || isStreaming || (!provider && !agent)) return;
|
|
133
|
-
|
|
134
|
-
const userMsg: ChatMessage = {
|
|
135
|
-
id: genId(),
|
|
136
|
-
role: 'user',
|
|
137
|
-
content: inputValue.trim(),
|
|
138
|
-
timestamp: Date.now(),
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
messages = [...messages, userMsg];
|
|
142
|
-
inputValue = '';
|
|
143
|
-
scrollToBottom();
|
|
144
|
-
|
|
145
|
-
// Create placeholder assistant message
|
|
146
|
-
const assistantMsg: ChatMessage = {
|
|
147
|
-
id: genId(),
|
|
148
|
-
role: 'assistant',
|
|
149
|
-
content: '',
|
|
150
|
-
timestamp: Date.now(),
|
|
151
|
-
};
|
|
152
|
-
messages = [...messages, assistantMsg];
|
|
153
|
-
isStreaming = true;
|
|
154
|
-
scrollToBottom();
|
|
155
|
-
|
|
156
|
-
abortController = new AbortController();
|
|
157
|
-
|
|
158
|
-
try {
|
|
159
|
-
// Build message list with context system message prepended
|
|
160
|
-
const contextMsg = buildContextSystemMessage();
|
|
161
|
-
const allMessages = messages.filter((m) => m.content);
|
|
162
|
-
const messagesToSend = contextMsg ? [contextMsg, ...allMessages] : allMessages;
|
|
163
|
-
|
|
164
|
-
if (agent) {
|
|
165
|
-
// ─── AgentProvider path: typed event stream ─────────
|
|
166
|
-
const stream = agent.chat(messagesToSend, {
|
|
167
|
-
signal: abortController.signal,
|
|
168
|
-
context: getChatContext(),
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const collectedActions: ChatAction[] = [];
|
|
172
|
-
|
|
173
|
-
for await (const event of stream) {
|
|
174
|
-
switch (event.type) {
|
|
175
|
-
case 'text':
|
|
176
|
-
assistantMsg.content += event.content;
|
|
177
|
-
messages = [...messages.slice(0, -1), { ...assistantMsg }];
|
|
178
|
-
scrollToBottom();
|
|
179
|
-
break;
|
|
180
|
-
|
|
181
|
-
case 'tool_call':
|
|
182
|
-
assistantMsg.content += `\n🔧 *${event.tool}*(${JSON.stringify(event.args)})`;
|
|
183
|
-
messages = [...messages.slice(0, -1), { ...assistantMsg }];
|
|
184
|
-
scrollToBottom();
|
|
185
|
-
break;
|
|
186
|
-
|
|
187
|
-
case 'tool_result':
|
|
188
|
-
if (event.result.success) {
|
|
189
|
-
assistantMsg.content += `\n✅ ${event.tool} completed`;
|
|
190
|
-
} else {
|
|
191
|
-
assistantMsg.content += `\n❌ ${event.tool} failed: ${event.result.error ?? 'Unknown error'}`;
|
|
192
|
-
}
|
|
193
|
-
messages = [...messages.slice(0, -1), { ...assistantMsg }];
|
|
194
|
-
scrollToBottom();
|
|
195
|
-
break;
|
|
196
|
-
|
|
197
|
-
case 'approval_request': {
|
|
198
|
-
// Register in the core approval system
|
|
199
|
-
const reqId = event.id;
|
|
200
|
-
pendingApprovalIds = [...pendingApprovalIds, reqId];
|
|
201
|
-
|
|
202
|
-
collectedActions.push(
|
|
203
|
-
{
|
|
204
|
-
label: `✅ ${t('common.confirm') || 'Approve'}: ${event.description}`,
|
|
205
|
-
variant: 'default',
|
|
206
|
-
payload: { approvalId: reqId, approved: true },
|
|
207
|
-
},
|
|
208
|
-
{
|
|
209
|
-
label: `❌ ${t('common.cancel') || 'Reject'}`,
|
|
210
|
-
variant: 'destructive',
|
|
211
|
-
payload: { approvalId: reqId, approved: false },
|
|
212
|
-
},
|
|
213
|
-
);
|
|
214
|
-
|
|
215
|
-
assistantMsg.content += `\n⚠️ **${t('chat.approvalRequired') || 'Approval required'}**: ${event.description}`;
|
|
216
|
-
assistantMsg.actions = [...collectedActions];
|
|
217
|
-
messages = [...messages.slice(0, -1), { ...assistantMsg }];
|
|
218
|
-
scrollToBottom();
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
case 'component':
|
|
223
|
-
assistantMsg.content += `\n📊 [${event.name}]`;
|
|
224
|
-
messages = [...messages.slice(0, -1), { ...assistantMsg }];
|
|
225
|
-
scrollToBottom();
|
|
226
|
-
break;
|
|
227
|
-
|
|
228
|
-
case 'done':
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
} else if (provider) {
|
|
233
|
-
// ─── ChatProvider path: raw text stream ─────────────
|
|
234
|
-
const result = provider.sendMessage(
|
|
235
|
-
messagesToSend,
|
|
236
|
-
{ signal: abortController.signal },
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
if (result && typeof result === 'object' && Symbol.asyncIterator in result) {
|
|
240
|
-
for await (const chunk of result as AsyncGenerator<string>) {
|
|
241
|
-
assistantMsg.content += chunk;
|
|
242
|
-
messages = [...messages.slice(0, -1), { ...assistantMsg }];
|
|
243
|
-
scrollToBottom();
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
const text = await (result as Promise<string>);
|
|
247
|
-
assistantMsg.content = text;
|
|
248
|
-
messages = [...messages.slice(0, -1), { ...assistantMsg }];
|
|
249
|
-
scrollToBottom();
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
} catch (err: unknown) {
|
|
253
|
-
if (err instanceof Error && err.name === 'AbortError') return;
|
|
254
|
-
assistantMsg.content = t('chat.error') || 'Sorry, something went wrong. Please try again.';
|
|
255
|
-
messages = [...messages.slice(0, -1), { ...assistantMsg }];
|
|
256
|
-
} finally {
|
|
257
|
-
isStreaming = false;
|
|
258
|
-
abortController = null;
|
|
259
|
-
scrollToBottom();
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
function stopStreaming() {
|
|
264
|
-
if (abortController) {
|
|
265
|
-
abortController.abort();
|
|
266
|
-
isStreaming = false;
|
|
267
|
-
abortController = null;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function clearChat() {
|
|
272
|
-
messages = [];
|
|
273
|
-
isStreaming = false;
|
|
274
|
-
if (abortController) {
|
|
275
|
-
abortController.abort();
|
|
276
|
-
abortController = null;
|
|
277
|
-
}
|
|
278
|
-
// Also clear persisted data
|
|
279
|
-
if (persistKey) {
|
|
280
|
-
try { localStorage.removeItem(persistKey); } catch { /* noop */ }
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
function handleKeydown(e: KeyboardEvent) {
|
|
285
|
-
if (e.key === 'Enter' && !e.shiftKey) {
|
|
286
|
-
e.preventDefault();
|
|
287
|
-
sendMessage();
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
function handleGlobalKeydown(e: KeyboardEvent) {
|
|
292
|
-
if (e.ctrlKey && e.shiftKey && e.key === 'L') {
|
|
293
|
-
e.preventDefault();
|
|
294
|
-
if (open && !minimized) {
|
|
295
|
-
open = false;
|
|
296
|
-
} else {
|
|
297
|
-
open = true;
|
|
298
|
-
minimized = false;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
function handleAction(action: ChatAction, msg: ChatMessage) {
|
|
304
|
-
// Handle approval actions from AgentProvider
|
|
305
|
-
if (action.payload?.approvalId) {
|
|
306
|
-
const id = action.payload.approvalId as string;
|
|
307
|
-
const approved = action.payload.approved as boolean;
|
|
308
|
-
resolveApproval(id, approved);
|
|
309
|
-
pendingApprovalIds = pendingApprovalIds.filter(pid => pid !== id);
|
|
310
|
-
// Remove action buttons after resolution
|
|
311
|
-
msg.actions = undefined;
|
|
312
|
-
messages = [...messages];
|
|
313
|
-
return;
|
|
314
|
-
}
|
|
315
|
-
if (onAction) {
|
|
316
|
-
onAction(action, msg);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/** Simple markdown→html: bold, italic, code blocks, inline code, line breaks */
|
|
321
|
-
function renderMarkdown(text: string): string {
|
|
322
|
-
return text
|
|
323
|
-
.replace(/```(\w*)\n([\s\S]*?)```/g, '<pre class="chat-code-block"><code>$2</code></pre>')
|
|
324
|
-
.replace(/`([^`]+)`/g, '<code class="chat-inline-code">$1</code>')
|
|
325
|
-
.replace(/\*\*(.+?)\*\*/g, '<strong>$1</strong>')
|
|
326
|
-
.replace(/\*(.+?)\*/g, '<em>$1</em>')
|
|
327
|
-
.replace(/\n/g, '<br>');
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
const suggestions = $derived([
|
|
331
|
-
t('chat.suggestion1') || 'How do I create a new resource?',
|
|
332
|
-
t('chat.suggestion2') || 'Explain the data model',
|
|
333
|
-
t('chat.suggestion3') || 'Help me write a filter query',
|
|
334
|
-
]);
|
|
335
|
-
</script>
|
|
336
|
-
|
|
337
|
-
<svelte:window onkeydown={handleGlobalKeydown} />
|
|
338
|
-
|
|
339
|
-
{#if provider || agent}
|
|
340
|
-
<!-- FAB Button -->
|
|
341
|
-
{#if !open}
|
|
342
|
-
<div transition:scale={{ duration: 200 }}>
|
|
343
|
-
<TooltipButton
|
|
344
|
-
tooltip={t('chat.title') || 'AI Assistant'}
|
|
345
|
-
variant="default"
|
|
346
|
-
size="icon"
|
|
347
|
-
class="fixed bottom-4 right-4 sm:bottom-6 sm:right-6 z-[9998] h-12 w-12 rounded-full shadow-xl hover:shadow-2xl hover:scale-110 transition-all bg-primary text-primary-foreground"
|
|
348
|
-
onclick={() => { open = true; minimized = false; }}
|
|
349
|
-
>
|
|
350
|
-
<MessageCircle class="h-5 w-5" />
|
|
351
|
-
{#if messages.length > 0}
|
|
352
|
-
<span class="absolute -top-1 -right-1 h-4 w-4 rounded-full bg-destructive text-[10px] font-bold text-destructive-foreground flex items-center justify-center">
|
|
353
|
-
{messages.filter(m => m.role === 'assistant').length}
|
|
354
|
-
</span>
|
|
355
|
-
{/if}
|
|
356
|
-
</TooltipButton>
|
|
357
|
-
</div>
|
|
358
|
-
{/if}
|
|
359
|
-
|
|
360
|
-
<!-- Chat Panel -->
|
|
361
|
-
{#if open}
|
|
362
|
-
<div
|
|
363
|
-
class="fixed z-[9998] flex flex-col rounded-2xl border bg-card shadow-2xl overflow-hidden bottom-3 right-3 sm:bottom-6 sm:right-6"
|
|
364
|
-
class:w-[calc(100vw-1.5rem)]={!minimized}
|
|
365
|
-
class:sm:w-[400px]={!minimized}
|
|
366
|
-
class:h-[calc(100dvh-6rem)]={!minimized}
|
|
367
|
-
class:sm:h-[560px]={!minimized}
|
|
368
|
-
class:w-[280px]={minimized}
|
|
369
|
-
class:h-auto={minimized}
|
|
370
|
-
transition:fly={{ y: 300, duration: 250 }}
|
|
371
|
-
>
|
|
372
|
-
<!-- Header -->
|
|
373
|
-
<div class="flex items-center justify-between px-4 py-3 bg-primary text-primary-foreground shrink-0">
|
|
374
|
-
<div class="flex items-center gap-2.5">
|
|
375
|
-
<div class="flex items-center justify-center h-7 w-7 rounded-full bg-primary-foreground/20">
|
|
376
|
-
<Bot class="h-4 w-4" />
|
|
377
|
-
</div>
|
|
378
|
-
<div>
|
|
379
|
-
<h3 class="text-sm font-semibold leading-none">
|
|
380
|
-
{t('chat.title') || 'AI Assistant'}
|
|
381
|
-
</h3>
|
|
382
|
-
{#if isStreaming}
|
|
383
|
-
<p class="text-[10px] opacity-80 mt-0.5">{t('chat.typing') || 'Typing...'}</p>
|
|
384
|
-
{/if}
|
|
385
|
-
</div>
|
|
386
|
-
</div>
|
|
387
|
-
<div class="flex items-center gap-0.5">
|
|
388
|
-
{#if messages.length > 0}
|
|
389
|
-
<TooltipButton
|
|
390
|
-
tooltip={t('chat.clear') || 'Clear'}
|
|
391
|
-
variant="ghost"
|
|
392
|
-
size="icon"
|
|
393
|
-
class="h-7 w-7 text-primary-foreground/70 hover:text-primary-foreground hover:bg-primary-foreground/10"
|
|
394
|
-
onclick={clearChat}
|
|
395
|
-
>
|
|
396
|
-
<Trash2 class="h-3.5 w-3.5" />
|
|
397
|
-
</TooltipButton>
|
|
398
|
-
{/if}
|
|
399
|
-
<TooltipButton
|
|
400
|
-
tooltip={minimized ? (t('common.expand') || 'Expand') : (t('common.collapse') || 'Minimize')}
|
|
401
|
-
variant="ghost"
|
|
402
|
-
size="icon"
|
|
403
|
-
class="h-7 w-7 text-primary-foreground/70 hover:text-primary-foreground hover:bg-primary-foreground/10"
|
|
404
|
-
onclick={() => minimized = !minimized}
|
|
405
|
-
>
|
|
406
|
-
<Minus class="h-3.5 w-3.5" />
|
|
407
|
-
</TooltipButton>
|
|
408
|
-
<TooltipButton
|
|
409
|
-
tooltip={t('common.close') || 'Close'}
|
|
410
|
-
variant="ghost"
|
|
411
|
-
size="icon"
|
|
412
|
-
class="h-7 w-7 text-primary-foreground/70 hover:text-primary-foreground hover:bg-primary-foreground/10"
|
|
413
|
-
onclick={() => open = false}
|
|
414
|
-
>
|
|
415
|
-
<X class="h-3.5 w-3.5" />
|
|
416
|
-
</TooltipButton>
|
|
417
|
-
</div>
|
|
418
|
-
</div>
|
|
419
|
-
|
|
420
|
-
{#if !minimized}
|
|
421
|
-
<!-- Messages -->
|
|
422
|
-
<div
|
|
423
|
-
bind:this={messagesContainer}
|
|
424
|
-
class="flex-1 overflow-y-auto p-4 space-y-3 scroll-smooth"
|
|
425
|
-
>
|
|
426
|
-
{#if messages.length === 0}
|
|
427
|
-
<!-- Welcome state -->
|
|
428
|
-
<div class="flex flex-col items-center justify-center h-full text-center px-4" in:fade={{ duration: 200 }}>
|
|
429
|
-
<div class="h-12 w-12 rounded-full bg-primary/10 flex items-center justify-center mb-4">
|
|
430
|
-
<Bot class="h-6 w-6 text-primary" />
|
|
431
|
-
</div>
|
|
432
|
-
<h4 class="text-sm font-semibold text-foreground mb-1">
|
|
433
|
-
{t('chat.welcome') || 'How can I help?'}
|
|
434
|
-
</h4>
|
|
435
|
-
<p class="text-xs text-muted-foreground mb-4">
|
|
436
|
-
{t('chat.welcomeDesc') || 'Ask me anything about your admin panel.'}
|
|
437
|
-
</p>
|
|
438
|
-
<div class="flex flex-col gap-2 w-full max-w-[240px]">
|
|
439
|
-
{#each suggestions as suggestion}
|
|
440
|
-
<button
|
|
441
|
-
class="text-left text-xs px-3 py-2 rounded-lg border border-border hover:bg-accent hover:text-accent-foreground transition-colors cursor-pointer"
|
|
442
|
-
onclick={() => { inputValue = suggestion; }}
|
|
443
|
-
>
|
|
444
|
-
{suggestion}
|
|
445
|
-
</button>
|
|
446
|
-
{/each}
|
|
447
|
-
</div>
|
|
448
|
-
</div>
|
|
449
|
-
{:else}
|
|
450
|
-
{#each messages as msg (msg.id)}
|
|
451
|
-
<div
|
|
452
|
-
class="flex {msg.role === 'user' ? 'justify-end' : 'justify-start'}"
|
|
453
|
-
in:fly={{ y: 10, duration: 150 }}
|
|
454
|
-
>
|
|
455
|
-
<div
|
|
456
|
-
class="max-w-[85%] rounded-2xl px-3.5 py-2.5 text-sm leading-relaxed {msg.role === 'user'
|
|
457
|
-
? 'bg-primary text-primary-foreground rounded-br-md'
|
|
458
|
-
: 'bg-muted text-foreground rounded-bl-md'}"
|
|
459
|
-
>
|
|
460
|
-
{#if msg.role === 'assistant'}
|
|
461
|
-
{#if msg.content}
|
|
462
|
-
<div class="chat-markdown">{@html renderMarkdown(msg.content)}</div>
|
|
463
|
-
<!-- Action Buttons -->
|
|
464
|
-
{#if msg.actions && msg.actions.length > 0}
|
|
465
|
-
<div class="flex flex-wrap gap-1.5 mt-2 pt-2 border-t border-border/50">
|
|
466
|
-
{#each msg.actions as action}
|
|
467
|
-
<Button
|
|
468
|
-
variant={action.variant ?? 'outline'}
|
|
469
|
-
size="sm"
|
|
470
|
-
class="h-7 text-xs"
|
|
471
|
-
onclick={() => handleAction(action, msg)}
|
|
472
|
-
>
|
|
473
|
-
{action.label}
|
|
474
|
-
</Button>
|
|
475
|
-
{/each}
|
|
476
|
-
</div>
|
|
477
|
-
{/if}
|
|
478
|
-
{:else}
|
|
479
|
-
<div class="flex items-center gap-1.5 text-muted-foreground">
|
|
480
|
-
<Loader2 class="h-3.5 w-3.5 animate-spin" />
|
|
481
|
-
<span class="text-xs">{t('chat.thinking') || 'Thinking...'}</span>
|
|
482
|
-
</div>
|
|
483
|
-
{/if}
|
|
484
|
-
{:else}
|
|
485
|
-
{msg.content}
|
|
486
|
-
{/if}
|
|
487
|
-
</div>
|
|
488
|
-
</div>
|
|
489
|
-
{/each}
|
|
490
|
-
{/if}
|
|
491
|
-
</div>
|
|
492
|
-
|
|
493
|
-
<!-- Input area -->
|
|
494
|
-
<div class="shrink-0 border-t bg-card p-3">
|
|
495
|
-
<div class="flex items-end gap-2">
|
|
496
|
-
<textarea
|
|
497
|
-
bind:value={inputValue}
|
|
498
|
-
onkeydown={handleKeydown}
|
|
499
|
-
placeholder={t('chat.placeholder') || 'Type a message...'}
|
|
500
|
-
rows={1}
|
|
501
|
-
disabled={isStreaming}
|
|
502
|
-
class="flex-1 resize-none rounded-xl border border-input bg-background px-3 py-2.5 text-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-1 disabled:opacity-50 max-h-[100px] min-h-[40px]"
|
|
503
|
-
></textarea>
|
|
504
|
-
{#if isStreaming}
|
|
505
|
-
<Button
|
|
506
|
-
variant="destructive"
|
|
507
|
-
size="icon"
|
|
508
|
-
class="h-10 w-10 rounded-xl shrink-0"
|
|
509
|
-
onclick={stopStreaming}
|
|
510
|
-
>
|
|
511
|
-
<X class="h-4 w-4" />
|
|
512
|
-
</Button>
|
|
513
|
-
{:else}
|
|
514
|
-
<Button
|
|
515
|
-
variant="default"
|
|
516
|
-
size="icon"
|
|
517
|
-
class="h-10 w-10 rounded-xl shrink-0"
|
|
518
|
-
onclick={sendMessage}
|
|
519
|
-
disabled={!inputValue.trim()}
|
|
520
|
-
>
|
|
521
|
-
<Send class="h-4 w-4" />
|
|
522
|
-
</Button>
|
|
523
|
-
{/if}
|
|
524
|
-
</div>
|
|
525
|
-
<p class="text-[10px] text-muted-foreground mt-1.5 text-center">
|
|
526
|
-
<kbd class="px-1 py-0.5 rounded border border-border bg-muted text-[9px] font-mono">Ctrl+Shift+L</kbd>
|
|
527
|
-
{t('chat.shortcutHint') || 'to toggle'}
|
|
528
|
-
</p>
|
|
529
|
-
</div>
|
|
530
|
-
{/if}
|
|
531
|
-
</div>
|
|
532
|
-
{/if}
|
|
533
|
-
{/if}
|
|
534
|
-
|
|
535
|
-
|