@flame0510/project-aether 1.1.9
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/README.md +150 -0
- package/agent-templates/README.md +37 -0
- package/agent-templates/argus/AGENTS.md +52 -0
- package/agent-templates/argus/IDENTITY.md +7 -0
- package/agent-templates/argus/MEMORY.md +9 -0
- package/agent-templates/argus/SOUL.md +24 -0
- package/agent-templates/argus/TOOLS.md +8 -0
- package/agent-templates/atlas/AGENTS.md +47 -0
- package/agent-templates/atlas/HEARTBEAT.md +10 -0
- package/agent-templates/atlas/IDENTITY.md +6 -0
- package/agent-templates/atlas/MEMORY.md +9 -0
- package/agent-templates/atlas/SOUL.md +21 -0
- package/agent-templates/atlas/TOOLS.md +4 -0
- package/agent-templates/base-image/.trigger +0 -0
- package/agent-templates/base-image/Dockerfile +90 -0
- package/agent-templates/base-image/entrypoint.sh +37 -0
- package/agent-templates/custom/AGENTS.md +29 -0
- package/agent-templates/custom/BOOTSTRAP.md +56 -0
- package/agent-templates/custom/MEMORY.md +8 -0
- package/agent-templates/prometheus/AGENTS.md +37 -0
- package/agent-templates/prometheus/IDENTITY.md +6 -0
- package/agent-templates/prometheus/MEMORY.md +9 -0
- package/agent-templates/prometheus/SOUL.md +21 -0
- package/agent-templates/prometheus/TOOLS.md +4 -0
- package/app/agents/ChannelManager.tsx +465 -0
- package/app/agents/ImageDownloadBanner.tsx +159 -0
- package/app/agents/PageClient.tsx +1285 -0
- package/app/agents/create/PageClient.tsx +437 -0
- package/app/agents/create/page.tsx +126 -0
- package/app/agents/loading.tsx +14 -0
- package/app/agents/page.tsx +5 -0
- package/app/api/agents/[id]/backup/route.ts +169 -0
- package/app/api/agents/[id]/channels/pairing/route.ts +69 -0
- package/app/api/agents/[id]/channels/route.ts +14 -0
- package/app/api/agents/[id]/channels/telegram/route.ts +50 -0
- package/app/api/agents/[id]/lifecycle/route.ts +94 -0
- package/app/api/agents/[id]/recreate/route.ts +199 -0
- package/app/api/agents/[id]/restart/route.ts +33 -0
- package/app/api/agents/[id]/restore/route.ts +81 -0
- package/app/api/agents/[id]/route.ts +280 -0
- package/app/api/agents/channels-summary/route.ts +39 -0
- package/app/api/agents/config-json/route.ts +58 -0
- package/app/api/agents/create/route.ts +488 -0
- package/app/api/agents/download-image/route.ts +32 -0
- package/app/api/agents/image-status/route.ts +126 -0
- package/app/api/agents/route.ts +213 -0
- package/app/api/agents/token/route.ts +94 -0
- package/app/api/agents-active/route.ts +190 -0
- package/app/api/agents-config/route.ts +629 -0
- package/app/api/alerts/smoke/route.ts +26 -0
- package/app/api/aliases/add/route.ts +28 -0
- package/app/api/aliases/remove/route.ts +27 -0
- package/app/api/assistant/route.ts +204 -0
- package/app/api/auth/check/route.ts +38 -0
- package/app/api/auth/login/route.ts +85 -0
- package/app/api/auth/logout/route.ts +7 -0
- package/app/api/auth/status/route.ts +33 -0
- package/app/api/config/env/route.ts +132 -0
- package/app/api/config/restart/route.ts +26 -0
- package/app/api/containers/route.ts +75 -0
- package/app/api/cost-override/route.ts +46 -0
- package/app/api/costs/route.ts +84 -0
- package/app/api/credentials/[id]/reveal/route.ts +21 -0
- package/app/api/credentials/[id]/route.ts +52 -0
- package/app/api/credentials/[id]/sync/route.ts +58 -0
- package/app/api/credentials/detect/route.ts +246 -0
- package/app/api/credentials/route.ts +33 -0
- package/app/api/crons/[id]/route.ts +69 -0
- package/app/api/crons/route.ts +12 -0
- package/app/api/crons/runs/route.ts +31 -0
- package/app/api/debug/route.ts +11 -0
- package/app/api/envcheck/route.ts +18 -0
- package/app/api/events/route.ts +24 -0
- package/app/api/gateway/agent/route.ts +154 -0
- package/app/api/gateway/provider/balance/route.ts +38 -0
- package/app/api/gateway/provider/keys.ts +38 -0
- package/app/api/gateway/provider/oauth/route.ts +304 -0
- package/app/api/gateway/provider/route.ts +209 -0
- package/app/api/gateway/route.ts +223 -0
- package/app/api/gateway/sync.ts +189 -0
- package/app/api/lineage/route.ts +54 -0
- package/app/api/memory-context/route.ts +15 -0
- package/app/api/metrics/route.ts +35 -0
- package/app/api/models/route.ts +77 -0
- package/app/api/plugins/route.js +37 -0
- package/app/api/provider/upstream.ts +142 -0
- package/app/api/provider/v1/chat/completions/route.ts +146 -0
- package/app/api/provider/v1/models/route.ts +167 -0
- package/app/api/provider-usage/route.ts +629 -0
- package/app/api/session/route.ts +39 -0
- package/app/api/sessions/[id]/route.ts +38 -0
- package/app/api/sessions/route.ts +23 -0
- package/app/api/setup/agent-image/route.ts +102 -0
- package/app/api/setup/password/route.ts +111 -0
- package/app/api/setup/restart/route.ts +76 -0
- package/app/api/skills/delete/route.js +105 -0
- package/app/api/skills/promote/route.js +129 -0
- package/app/api/skills/route.js +203 -0
- package/app/api/skills/save/route.js +142 -0
- package/app/api/stats/route.ts +34 -0
- package/app/api/stats-since/route.ts +20 -0
- package/app/api/stream/route.ts +70 -0
- package/app/api/system-health/route.ts +233 -0
- package/app/api/tool-calls/route.ts +24 -0
- package/app/api/tools-config/route.ts +163 -0
- package/app/api/update-check/route.ts +127 -0
- package/app/api/version/route.ts +25 -0
- package/app/api/wizard/complete/route.ts +32 -0
- package/app/api/wizard/reset/route.ts +28 -0
- package/app/api/wizard/status/route.ts +28 -0
- package/app/api/workspace/route.ts +392 -0
- package/app/api/workspace/stream/route.ts +136 -0
- package/app/components/AppShell.tsx +33 -0
- package/app/components/AuthGuard.tsx +91 -0
- package/app/components/CostBreakdown.tsx +37 -0
- package/app/components/DashboardHeader.tsx +73 -0
- package/app/components/DashboardLayout.tsx +76 -0
- package/app/components/DashboardToolbar.tsx +61 -0
- package/app/components/FloatingActions.tsx +33 -0
- package/app/components/Icons.tsx +78 -0
- package/app/components/LineageGraphPage.tsx +142 -0
- package/app/components/LiveFeed.tsx +48 -0
- package/app/components/MobileBottomNav.tsx +84 -0
- package/app/components/ModelPickerModal.tsx +94 -0
- package/app/components/PasswordInput.tsx +86 -0
- package/app/components/PulseChat.tsx +362 -0
- package/app/components/Rev4aLoader.tsx +48 -0
- package/app/components/SessionDrawer.tsx +263 -0
- package/app/components/SessionTopology.tsx +289 -0
- package/app/components/Sidebar.tsx +294 -0
- package/app/components/Skeleton.tsx +133 -0
- package/app/components/SystemCockpit.tsx +169 -0
- package/app/components/VersionBanner.tsx +105 -0
- package/app/components/WizardButton.tsx +30 -0
- package/app/components/ui/Badge.tsx +30 -0
- package/app/components/ui/Button.tsx +59 -0
- package/app/components/ui/ConfirmModal.tsx +46 -0
- package/app/components/ui/FilterBar.tsx +33 -0
- package/app/components/ui/Input.tsx +25 -0
- package/app/components/ui/ItemList.tsx +83 -0
- package/app/components/ui/LoadingSpinner.tsx +30 -0
- package/app/components/ui/Metric.tsx +22 -0
- package/app/components/ui/Modal.tsx +42 -0
- package/app/components/ui/Page.tsx +18 -0
- package/app/components/ui/Pill.tsx +6 -0
- package/app/components/ui/PropertyList.tsx +24 -0
- package/app/components/ui/Select.tsx +26 -0
- package/app/components/ui/StatusCard.tsx +32 -0
- package/app/components/ui/Surface.tsx +14 -0
- package/app/components/ui/Tabs.tsx +55 -0
- package/app/components/ui/TemplateOption.tsx +59 -0
- package/app/components/ui/Toast.tsx +44 -0
- package/app/components/ui/index.ts +19 -0
- package/app/components/ui/tokens.ts +18 -0
- package/app/config/PageClient.tsx +293 -0
- package/app/config/loading.tsx +10 -0
- package/app/config/page.tsx +7 -0
- package/app/containers/ContainersClient.tsx +129 -0
- package/app/containers/loading.tsx +21 -0
- package/app/containers/page.tsx +5 -0
- package/app/containers/terminal/[id]/TerminalClient.tsx +313 -0
- package/app/containers/terminal/[id]/page.tsx +6 -0
- package/app/credentials/PageClient.tsx +598 -0
- package/app/credentials/loading.tsx +10 -0
- package/app/credentials/page.tsx +7 -0
- package/app/crons/PageClient.tsx +538 -0
- package/app/crons/loading.tsx +10 -0
- package/app/crons/page.tsx +5 -0
- package/app/design-system.ts +57 -0
- package/app/gateway/PageClient.tsx +1048 -0
- package/app/gateway/loading.tsx +24 -0
- package/app/gateway/page.tsx +5 -0
- package/app/globals.css +1474 -0
- package/app/layout.tsx +45 -0
- package/app/lib/models-context.tsx +41 -0
- package/app/lineage/loading.tsx +10 -0
- package/app/lineage/page.tsx +13 -0
- package/app/loading.tsx +16 -0
- package/app/login/page.tsx +160 -0
- package/app/memory/MemoryContextPageClient.tsx +196 -0
- package/app/memory/loading.tsx +10 -0
- package/app/memory/page.tsx +8 -0
- package/app/page.tsx +31 -0
- package/app/plugins/PageClient.tsx +296 -0
- package/app/plugins/loading.tsx +10 -0
- package/app/plugins/page.tsx +5 -0
- package/app/setup/PageClient.tsx +227 -0
- package/app/setup/loading.tsx +21 -0
- package/app/setup/page.tsx +7 -0
- package/app/skills/PageClient.tsx +499 -0
- package/app/skills/loading.tsx +10 -0
- package/app/skills/page.tsx +5 -0
- package/app/tools/ToolsPageClient.tsx +308 -0
- package/app/tools/loading.tsx +10 -0
- package/app/tools/page.tsx +62 -0
- package/app/tools/tools-catalog.ts +141 -0
- package/app/wizard/PageClient.tsx +485 -0
- package/app/wizard/icons.tsx +89 -0
- package/app/wizard/loading.tsx +24 -0
- package/app/wizard/page.tsx +7 -0
- package/app/wizard/storage.ts +33 -0
- package/app/wizard/useWizard.ts +101 -0
- package/app/workspace/WorkspaceClient.tsx +633 -0
- package/app/workspace/loading.tsx +36 -0
- package/app/workspace/page.tsx +8 -0
- package/bin/docker-entrypoint.sh +21 -0
- package/bin/postinstall.js +20 -0
- package/bin/rev4a.js +696 -0
- package/daemon.js +783 -0
- package/docs/ARCHITECTURE.md +557 -0
- package/docs/CONTAINER-TERMINAL.md +280 -0
- package/docs/DESIGN-SYSTEM.md +99 -0
- package/docs/FRONTEND-ARCHITECTURE.md +119 -0
- package/docs/REV4A.md +504 -0
- package/docs/dev/API-REFERENCE.md +1835 -0
- package/docs/dev/DATABASE.md +224 -0
- package/docs/dev/GATEWAY.md +300 -0
- package/docs/dev/PROVIDERS.md +229 -0
- package/docs/dev/SESSION-MAINTENANCE-PLAN.md +607 -0
- package/docs/dev/WORKSPACE.md +199 -0
- package/docs/rag/DATA-FRESHNESS.md +109 -0
- package/docs/rag/GLOSSARY.md +125 -0
- package/docs/rag/REV4A-OVERVIEW.md +135 -0
- package/docs/rag/WHAT-I-CAN-ANSWER.md +124 -0
- package/lib/agent-setup.ts +130 -0
- package/lib/alerts.ts +115 -0
- package/lib/apiFetch.ts +7 -0
- package/lib/auth.ts +28 -0
- package/lib/billing.ts +100 -0
- package/lib/buildAgentImage.ts +346 -0
- package/lib/channelManager.ts +386 -0
- package/lib/container.ts +60 -0
- package/lib/credentials/db.ts +86 -0
- package/lib/credentials/delivery.ts +448 -0
- package/lib/credentials/detect.ts +149 -0
- package/lib/credentials/hash.ts +9 -0
- package/lib/credentials/providers.ts +110 -0
- package/lib/credentials/vault.ts +195 -0
- package/lib/db-bootstrap.d.ts +3 -0
- package/lib/db-bootstrap.mjs +144 -0
- package/lib/db.ts +25 -0
- package/lib/docker-utils.ts +60 -0
- package/lib/hooks/useDashboard.ts +264 -0
- package/lib/hooks/useRev4aTimezone.ts +28 -0
- package/lib/hooks/useScreenshot.ts +30 -0
- package/lib/memory-context.ts +385 -0
- package/lib/model-catalogue.ts +131 -0
- package/lib/model-pricing.ts +63 -0
- package/lib/openclaw-cron.ts +350 -0
- package/lib/patterns/ApiAdapter.ts +73 -0
- package/lib/patterns/ApiClient.ts +65 -0
- package/lib/patterns/EventBus.ts +113 -0
- package/lib/patterns/FilterStrategy.ts +79 -0
- package/lib/patterns/SessionFactory.ts +117 -0
- package/lib/patterns/sessionPresentation.ts +117 -0
- package/lib/provider-balance.ts +163 -0
- package/lib/requireAuth.tsx +38 -0
- package/lib/rev4a-auth.d.ts +3 -0
- package/lib/rev4a-auth.js +36 -0
- package/lib/rev4a-paths.ts +145 -0
- package/lib/timezone.ts +46 -0
- package/lib/types/index.ts +96 -0
- package/lib/utils/format.ts +82 -0
- package/lineage.js +56 -0
- package/model-pricing.json +482 -0
- package/models.config.json +844 -0
- package/next-env.d.ts +6 -0
- package/next.config.mjs +7 -0
- package/package.json +82 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/favicon-64.png +0 -0
- package/public/favicon.svg +58 -0
- package/public/icon-192-maskable.png +0 -0
- package/public/icon-192.png +0 -0
- package/public/icon-512-maskable.png +0 -0
- package/public/icon-512.png +0 -0
- package/public/manifest.json +38 -0
- package/public/rev4a-logo.png +0 -0
- package/public/rev4a-logo.svg +58 -0
- package/rev4a-rules/AGENTS.md +37 -0
- package/scripts/add-auth.cjs +185 -0
- package/scripts/backup.sh +66 -0
- package/scripts/check-providers.mjs +143 -0
- package/scripts/docker/traefik/docker-compose.yml +32 -0
- package/scripts/docker/traefik/dynamic/.gitkeep +18 -0
- package/scripts/docker/traefik/traefik.yml +37 -0
- package/scripts/remove-auth-profile.js +56 -0
- package/scripts/restore.sh +82 -0
- package/terminal-ws-server.js +139 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { useModels } from '../lib/models-context';
|
|
5
|
+
|
|
6
|
+
interface ProviderEntry {
|
|
7
|
+
provider: string;
|
|
8
|
+
emoji: string;
|
|
9
|
+
models: { id: string; label: string }[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface ModelPickerModalProps {
|
|
13
|
+
open: boolean;
|
|
14
|
+
value?: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
onClose: () => void;
|
|
17
|
+
onSelect: (model: string) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const FALLBACK_PROVIDERS: ProviderEntry[] = [
|
|
21
|
+
{ provider: 'Default', emoji: '🔧', models: [{ id: '', label: 'Default' }] },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
export default function ModelPickerModal({ open, value = '', title = 'Select model', onClose, onSelect }: ModelPickerModalProps) {
|
|
25
|
+
const { providers: contextProviders, loaded } = useModels();
|
|
26
|
+
const [expanded, setExpanded] = useState<Record<number, boolean>>({ 0: true });
|
|
27
|
+
const providers = loaded && contextProviders.length ? contextProviders : FALLBACK_PROVIDERS;
|
|
28
|
+
|
|
29
|
+
if (!open) return null;
|
|
30
|
+
|
|
31
|
+
const current = value ? value.split('/').slice(1).join('/') || value : 'Default';
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<div className="model-picker" onClick={onClose}>
|
|
35
|
+
<div className="model-picker__panel" onClick={(e) => e.stopPropagation()}>
|
|
36
|
+
<div className="model-picker__header">
|
|
37
|
+
<div>
|
|
38
|
+
<div className="model-picker__title">{title}</div>
|
|
39
|
+
<div className="model-picker__current">Attuale: {current}</div>
|
|
40
|
+
</div>
|
|
41
|
+
<button className="model-picker__close" onClick={onClose} aria-label="Close">×</button>
|
|
42
|
+
</div>
|
|
43
|
+
<div className="model-picker__body">
|
|
44
|
+
{providers.map((provider, pIdx) => (
|
|
45
|
+
<div key={`${provider.provider}-${pIdx}`} className="model-picker__provider">
|
|
46
|
+
<button
|
|
47
|
+
className={`model-picker__provider-header${expanded[pIdx] ? ' model-picker__provider-header--expanded' : ''}`}
|
|
48
|
+
onClick={() => setExpanded((prev) => ({ ...prev, [pIdx]: !prev[pIdx] }))}
|
|
49
|
+
>
|
|
50
|
+
<span className="model-picker__chevron">{expanded[pIdx] ? '▾' : '▸'}</span>
|
|
51
|
+
<span className="model-picker__emoji">{provider.emoji}</span>
|
|
52
|
+
<span className="model-picker__provider-name">{provider.provider}</span>
|
|
53
|
+
<span className="model-picker__count">{provider.models.length}</span>
|
|
54
|
+
</button>
|
|
55
|
+
{expanded[pIdx] && (
|
|
56
|
+
<div className="model-picker__models">
|
|
57
|
+
{provider.models.map((m) => (
|
|
58
|
+
<button
|
|
59
|
+
key={m.id || '__default__'}
|
|
60
|
+
className={`model-picker__model${(value || '') === m.id ? ' model-picker__model--active' : ''}`}
|
|
61
|
+
onClick={() => onSelect(m.id)}
|
|
62
|
+
>
|
|
63
|
+
{m.label}
|
|
64
|
+
</button>
|
|
65
|
+
))}
|
|
66
|
+
</div>
|
|
67
|
+
)}
|
|
68
|
+
</div>
|
|
69
|
+
))}
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
<style jsx>{`
|
|
73
|
+
.model-picker { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
|
|
74
|
+
.model-picker__panel { width: min(520px, 100%); max-height: min(720px, 88dvh); background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 20px 80px rgba(0,0,0,.45); overflow: hidden; display: flex; flex-direction: column; }
|
|
75
|
+
.model-picker__header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
|
|
76
|
+
.model-picker__title { color: var(--text); font-size: 14px; font-weight: 600; }
|
|
77
|
+
.model-picker__current { color: var(--text-dim); font-size: 10px; margin-top: 3px; }
|
|
78
|
+
.model-picker__close { background: none; border: 1px solid var(--border); color: var(--text-dim); border-radius: 0; width: 30px; height: 30px; cursor: pointer; font-size: 18px; line-height: 1; }
|
|
79
|
+
.model-picker__body { overflow: auto; padding: 8px; }
|
|
80
|
+
.model-picker__provider-header { width: 100%; display: flex; align-items: center; gap: 8px; padding: 9px 10px; border: 0; border-radius: 0; background: none; color: var(--text-dim); cursor: pointer; font: inherit; font-size: 12px; }
|
|
81
|
+
.model-picker__provider-header:hover, .model-picker__provider-header--expanded { background: var(--bg3); color: var(--text); }
|
|
82
|
+
.model-picker__chevron { width: 14px; }
|
|
83
|
+
.model-picker__emoji { width: 18px; text-align: center; }
|
|
84
|
+
.model-picker__provider-name { flex: 1; text-align: left; font-weight: 600; }
|
|
85
|
+
.model-picker__count { font-size: 10px; color: var(--text-dim); background: var(--bg); border-radius: 0; padding: 1px 6px; }
|
|
86
|
+
.model-picker__models { display: grid; gap: 2px; padding: 2px 0 6px 40px; }
|
|
87
|
+
.model-picker__model { text-align: left; border: 0; border-radius: 0; background: none; color: var(--text); cursor: pointer; padding: 7px 9px; font: inherit; font-size: 11px; }
|
|
88
|
+
.model-picker__model:hover { background: var(--bg3); }
|
|
89
|
+
.model-picker__model--active { background: rgba(146,91,252,.14); color: var(--violet); }
|
|
90
|
+
@media (max-width: 600px) { .model-picker { align-items: flex-end; padding: 0; } .model-picker__panel { border-radius: 0; max-height: 82dvh; } }
|
|
91
|
+
`}</style>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { Input } from './ui';
|
|
5
|
+
import { EyeIcon, EyeOffIcon } from './Icons';
|
|
6
|
+
|
|
7
|
+
function generateKey(): string {
|
|
8
|
+
const arr = new Uint8Array(24);
|
|
9
|
+
crypto.getRandomValues(arr);
|
|
10
|
+
return Array.from(arr, (b) => b.toString(16).padStart(2, '0')).join('');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface PasswordInputProps {
|
|
14
|
+
value: string;
|
|
15
|
+
onChange: (value: string) => void;
|
|
16
|
+
placeholder?: string;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
style?: React.CSSProperties;
|
|
19
|
+
showGenerate?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default function PasswordInput({
|
|
23
|
+
value,
|
|
24
|
+
onChange,
|
|
25
|
+
placeholder = '',
|
|
26
|
+
disabled = false,
|
|
27
|
+
style,
|
|
28
|
+
showGenerate = false,
|
|
29
|
+
}: PasswordInputProps) {
|
|
30
|
+
const [visible, setVisible] = useState(false);
|
|
31
|
+
|
|
32
|
+
const hasRightButton = showGenerate;
|
|
33
|
+
const paddingRight = hasRightButton ? 150 : 44;
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div style={{ position: 'relative', ...style }}>
|
|
37
|
+
<Input
|
|
38
|
+
type={visible ? 'text' : 'password'}
|
|
39
|
+
placeholder={placeholder}
|
|
40
|
+
value={value}
|
|
41
|
+
onChange={(e) => onChange(e.target.value)}
|
|
42
|
+
disabled={disabled}
|
|
43
|
+
style={{ paddingRight }}
|
|
44
|
+
/>
|
|
45
|
+
<div
|
|
46
|
+
style={{
|
|
47
|
+
position: 'absolute',
|
|
48
|
+
right: 4,
|
|
49
|
+
top: '50%',
|
|
50
|
+
transform: 'translateY(-50%)',
|
|
51
|
+
display: 'flex',
|
|
52
|
+
alignItems: 'center',
|
|
53
|
+
gap: 4,
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
{showGenerate && (
|
|
57
|
+
<button
|
|
58
|
+
onClick={() => {
|
|
59
|
+
onChange(generateKey());
|
|
60
|
+
setVisible(true);
|
|
61
|
+
}}
|
|
62
|
+
disabled={disabled}
|
|
63
|
+
type="button"
|
|
64
|
+
tabIndex={-1}
|
|
65
|
+
className="ui-btn ui-btn--ghost ui-btn--sm"
|
|
66
|
+
title="Generate secure key"
|
|
67
|
+
style={{ marginRight: 2 }}
|
|
68
|
+
>
|
|
69
|
+
Generate
|
|
70
|
+
</button>
|
|
71
|
+
)}
|
|
72
|
+
<button
|
|
73
|
+
onClick={() => setVisible((v) => !v)}
|
|
74
|
+
disabled={disabled}
|
|
75
|
+
type="button"
|
|
76
|
+
tabIndex={-1}
|
|
77
|
+
className="ui-btn ui-btn--ghost ui-btn--sm"
|
|
78
|
+
title={visible ? 'Hide' : 'Show'}
|
|
79
|
+
style={{ minWidth: 32, justifyContent: 'center' }}
|
|
80
|
+
>
|
|
81
|
+
{visible ? <EyeOffIcon size={16} /> : <EyeIcon size={16} />}
|
|
82
|
+
</button>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
4
|
+
import { usePathname } from 'next/navigation';
|
|
5
|
+
import Link from 'next/link';
|
|
6
|
+
|
|
7
|
+
const STORAGE_KEY = 'rev4a_pulse_chat';
|
|
8
|
+
const MODEL_STORAGE_KEY = 'rev4a-pulse-model';
|
|
9
|
+
|
|
10
|
+
interface ModelOption {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface ModelGroup {
|
|
16
|
+
provider: string;
|
|
17
|
+
emoji: string;
|
|
18
|
+
models: ModelOption[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Message {
|
|
22
|
+
role: 'user' | 'assistant';
|
|
23
|
+
content: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function loadMessages(): Message[] {
|
|
27
|
+
try {
|
|
28
|
+
const raw = localStorage.getItem(STORAGE_KEY);
|
|
29
|
+
if (!raw) return [];
|
|
30
|
+
const parsed = JSON.parse(raw);
|
|
31
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
32
|
+
} catch {
|
|
33
|
+
return [];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function saveMessages(messages: Message[]) {
|
|
38
|
+
try {
|
|
39
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(messages));
|
|
40
|
+
} catch {
|
|
41
|
+
// storage full or unavailable — silently ignore
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function renderContent(text: string) {
|
|
46
|
+
const parts = text.split(/(\[([^\]]+)\]\(([^)]+)\))/g);
|
|
47
|
+
const result: React.ReactNode[] = [];
|
|
48
|
+
let i = 0;
|
|
49
|
+
while (i < parts.length) {
|
|
50
|
+
const part = parts[i];
|
|
51
|
+
if (part?.startsWith('[') && parts[i + 2]) {
|
|
52
|
+
const label = parts[i + 1];
|
|
53
|
+
const href = parts[i + 2];
|
|
54
|
+
const isInternal = href?.startsWith('/');
|
|
55
|
+
result.push(
|
|
56
|
+
isInternal ? (
|
|
57
|
+
<Link key={i} href={href!} style={{ color: 'var(--violet)', textDecoration: 'underline' }}>
|
|
58
|
+
{label}
|
|
59
|
+
</Link>
|
|
60
|
+
) : (
|
|
61
|
+
<a key={i} href={href} target="_blank" rel="noopener noreferrer" style={{ color: 'var(--violet)', textDecoration: 'underline' }}>
|
|
62
|
+
{label}
|
|
63
|
+
</a>
|
|
64
|
+
),
|
|
65
|
+
);
|
|
66
|
+
i += 3;
|
|
67
|
+
} else {
|
|
68
|
+
if (part) result.push(<span key={i}>{part}</span>);
|
|
69
|
+
i += 1;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default function PulseChat() {
|
|
76
|
+
const pathname = usePathname();
|
|
77
|
+
const [open, setOpen] = useState(false);
|
|
78
|
+
const [messages, setMessages] = useState<Message[]>(loadMessages);
|
|
79
|
+
const [input, setInput] = useState('');
|
|
80
|
+
const [streaming, setStreaming] = useState(false);
|
|
81
|
+
const [selectedModel, setSelectedModel] = useState<string>('');
|
|
82
|
+
const [modelGroups, setModelGroups] = useState<ModelGroup[]>([]);
|
|
83
|
+
const [modelsLoading, setModelsLoading] = useState(true);
|
|
84
|
+
const bottomRef = useRef<HTMLDivElement>(null);
|
|
85
|
+
const inputRef = useRef<HTMLTextAreaElement>(null);
|
|
86
|
+
const abortRef = useRef<AbortController | null>(null);
|
|
87
|
+
|
|
88
|
+
// Fetch available models from backend on mount
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
let cancelled = false;
|
|
91
|
+
|
|
92
|
+
async function fetchModels() {
|
|
93
|
+
try {
|
|
94
|
+
const res = await fetch('/api/models');
|
|
95
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
96
|
+
const data: ModelGroup[] = await res.json();
|
|
97
|
+
if (cancelled) return;
|
|
98
|
+
|
|
99
|
+
setModelGroups(data);
|
|
100
|
+
|
|
101
|
+
const allIds = data.flatMap((g) => g.models.map((m) => m.id));
|
|
102
|
+
|
|
103
|
+
// Restore saved model if valid, otherwise pick first
|
|
104
|
+
try {
|
|
105
|
+
const saved = localStorage.getItem(MODEL_STORAGE_KEY);
|
|
106
|
+
if (saved && allIds.includes(saved)) {
|
|
107
|
+
setSelectedModel(saved);
|
|
108
|
+
} else if (allIds.length > 0) {
|
|
109
|
+
setSelectedModel(allIds[0]);
|
|
110
|
+
}
|
|
111
|
+
} catch {
|
|
112
|
+
if (allIds.length > 0) setSelectedModel(allIds[0]);
|
|
113
|
+
}
|
|
114
|
+
} catch {
|
|
115
|
+
// API unavailable — leave selectedModel empty, select stays disabled
|
|
116
|
+
} finally {
|
|
117
|
+
if (!cancelled) setModelsLoading(false);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
fetchModels();
|
|
122
|
+
return () => { cancelled = true; };
|
|
123
|
+
}, []);
|
|
124
|
+
|
|
125
|
+
// Save model preference on change
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
try {
|
|
128
|
+
localStorage.setItem(MODEL_STORAGE_KEY, selectedModel);
|
|
129
|
+
} catch {
|
|
130
|
+
// ignore
|
|
131
|
+
}
|
|
132
|
+
}, [selectedModel]);
|
|
133
|
+
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
saveMessages(messages);
|
|
136
|
+
}, [messages]);
|
|
137
|
+
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
if (open) {
|
|
140
|
+
bottomRef.current?.scrollIntoView({ behavior: 'smooth' });
|
|
141
|
+
inputRef.current?.focus();
|
|
142
|
+
}
|
|
143
|
+
}, [open, messages]);
|
|
144
|
+
|
|
145
|
+
const newSession = useCallback(() => {
|
|
146
|
+
setMessages([]);
|
|
147
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
148
|
+
inputRef.current?.focus();
|
|
149
|
+
}, []);
|
|
150
|
+
|
|
151
|
+
const send = useCallback(async () => {
|
|
152
|
+
const text = input.trim();
|
|
153
|
+
if (!text || streaming) return;
|
|
154
|
+
|
|
155
|
+
const userMsg: Message = { role: 'user', content: text };
|
|
156
|
+
const history = [...messages, userMsg];
|
|
157
|
+
setMessages(history);
|
|
158
|
+
setInput('');
|
|
159
|
+
setStreaming(true);
|
|
160
|
+
|
|
161
|
+
const assistantMsg: Message = { role: 'assistant', content: '' };
|
|
162
|
+
setMessages([...history, assistantMsg]);
|
|
163
|
+
|
|
164
|
+
abortRef.current = new AbortController();
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
const res = await fetch('/api/assistant', {
|
|
168
|
+
method: 'POST',
|
|
169
|
+
headers: { 'Content-Type': 'application/json' },
|
|
170
|
+
body: JSON.stringify({
|
|
171
|
+
message: text,
|
|
172
|
+
page: pathname,
|
|
173
|
+
model: selectedModel,
|
|
174
|
+
history: messages.slice(-8).map((m) => ({ role: m.role, content: m.content })),
|
|
175
|
+
}),
|
|
176
|
+
signal: abortRef.current.signal,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (!res.ok) {
|
|
180
|
+
const err = await res.text();
|
|
181
|
+
setMessages((prev) => [
|
|
182
|
+
...prev.slice(0, -1),
|
|
183
|
+
{ role: 'assistant', content: `Error: ${err}` },
|
|
184
|
+
]);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const reader = res.body?.getReader();
|
|
189
|
+
const decoder = new TextDecoder();
|
|
190
|
+
let accumulated = '';
|
|
191
|
+
|
|
192
|
+
if (!reader) return;
|
|
193
|
+
|
|
194
|
+
while (true) {
|
|
195
|
+
const { done, value } = await reader.read();
|
|
196
|
+
if (done) break;
|
|
197
|
+
|
|
198
|
+
const chunk = decoder.decode(value, { stream: true });
|
|
199
|
+
const lines = chunk.split('\n');
|
|
200
|
+
|
|
201
|
+
for (const line of lines) {
|
|
202
|
+
if (!line.startsWith('data:')) continue;
|
|
203
|
+
const data = line.slice(5).trim();
|
|
204
|
+
if (data === '[DONE]') continue;
|
|
205
|
+
try {
|
|
206
|
+
const json = JSON.parse(data);
|
|
207
|
+
const delta = json?.choices?.[0]?.delta?.content ?? '';
|
|
208
|
+
if (delta) {
|
|
209
|
+
accumulated += delta;
|
|
210
|
+
setMessages((prev) => [
|
|
211
|
+
...prev.slice(0, -1),
|
|
212
|
+
{ role: 'assistant', content: accumulated },
|
|
213
|
+
]);
|
|
214
|
+
}
|
|
215
|
+
} catch {
|
|
216
|
+
// non-JSON SSE line, skip
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
} catch (err: unknown) {
|
|
221
|
+
if ((err as Error)?.name !== 'AbortError') {
|
|
222
|
+
setMessages((prev) => [
|
|
223
|
+
...prev.slice(0, -1),
|
|
224
|
+
{ role: 'assistant', content: 'Connection error. Try again.' },
|
|
225
|
+
]);
|
|
226
|
+
}
|
|
227
|
+
} finally {
|
|
228
|
+
setStreaming(false);
|
|
229
|
+
abortRef.current = null;
|
|
230
|
+
}
|
|
231
|
+
}, [input, messages, pathname, streaming]);
|
|
232
|
+
|
|
233
|
+
const onKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
|
234
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
235
|
+
e.preventDefault();
|
|
236
|
+
send();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
return (
|
|
241
|
+
<>
|
|
242
|
+
{/* Floating trigger button */}
|
|
243
|
+
<button
|
|
244
|
+
className="ochat__trigger"
|
|
245
|
+
aria-label="Pulse — Rev4a Assistant"
|
|
246
|
+
onClick={() => setOpen((v) => !v)}
|
|
247
|
+
title="Pulse — Rev4a Assistant"
|
|
248
|
+
>
|
|
249
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round">
|
|
250
|
+
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
|
|
251
|
+
</svg>
|
|
252
|
+
</button>
|
|
253
|
+
|
|
254
|
+
{/* Chat panel */}
|
|
255
|
+
{open && (
|
|
256
|
+
<div className="ochat__panel">
|
|
257
|
+
<div className="ochat__header">
|
|
258
|
+
<span className="ochat__header-title">
|
|
259
|
+
<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="var(--violet)" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" style={{ marginRight: 6 }}>
|
|
260
|
+
<ellipse cx="12" cy="12" rx="10" ry="6" />
|
|
261
|
+
<circle cx="12" cy="12" r="3" fill="var(--violet)" stroke="none" />
|
|
262
|
+
</svg>
|
|
263
|
+
PULSE
|
|
264
|
+
</span>
|
|
265
|
+
<select
|
|
266
|
+
value={selectedModel}
|
|
267
|
+
onChange={(e) => setSelectedModel(e.target.value)}
|
|
268
|
+
disabled={modelsLoading || modelGroups.length === 0}
|
|
269
|
+
style={{
|
|
270
|
+
border: '1px solid var(--border)',
|
|
271
|
+
background: 'var(--bg)',
|
|
272
|
+
color: 'var(--text)',
|
|
273
|
+
fontFamily: 'var(--font-mono-stack)',
|
|
274
|
+
fontSize: 11,
|
|
275
|
+
borderRadius: 0,
|
|
276
|
+
padding: '1px 4px',
|
|
277
|
+
cursor: modelsLoading ? 'wait' : 'pointer',
|
|
278
|
+
outline: 'none',
|
|
279
|
+
opacity: modelsLoading ? 0.5 : 1,
|
|
280
|
+
}}
|
|
281
|
+
aria-label="Select model"
|
|
282
|
+
>
|
|
283
|
+
{modelsLoading ? (
|
|
284
|
+
<option value="">…</option>
|
|
285
|
+
) : (
|
|
286
|
+
modelGroups.map((group) => (
|
|
287
|
+
<optgroup key={group.provider} label={`${group.emoji} ${group.provider}`}>
|
|
288
|
+
{group.models.map((m) => (
|
|
289
|
+
<option key={m.id} value={m.id}>
|
|
290
|
+
{group.emoji} {m.label}
|
|
291
|
+
</option>
|
|
292
|
+
))}
|
|
293
|
+
</optgroup>
|
|
294
|
+
))
|
|
295
|
+
)}
|
|
296
|
+
</select>
|
|
297
|
+
<div style={{ display: 'flex', gap: 4, alignItems: 'center' }}>
|
|
298
|
+
{messages.length > 0 && (
|
|
299
|
+
<button
|
|
300
|
+
className="ochat__clear"
|
|
301
|
+
onClick={newSession}
|
|
302
|
+
title="New session"
|
|
303
|
+
aria-label="New session"
|
|
304
|
+
>
|
|
305
|
+
<svg width="11" height="11" viewBox="0 0 16 16" fill="none">
|
|
306
|
+
<path d="M2 8h12M8 2v12" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
|
307
|
+
</svg>
|
|
308
|
+
</button>
|
|
309
|
+
)}
|
|
310
|
+
<button className="ochat__close" onClick={() => setOpen(false)} aria-label="Close">
|
|
311
|
+
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
|
|
312
|
+
<path d="M2 2l8 8M10 2l-8 8" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
|
313
|
+
</svg>
|
|
314
|
+
</button>
|
|
315
|
+
</div>
|
|
316
|
+
</div>
|
|
317
|
+
|
|
318
|
+
<div className="ochat__messages">
|
|
319
|
+
{messages.length === 0 && (
|
|
320
|
+
<p className="ochat__empty">
|
|
321
|
+
Hello! I'm <strong>Pulse</strong>, the oracle of Rev4a. Ask me about the dashboard, data, or the page you're looking at.
|
|
322
|
+
</p>
|
|
323
|
+
)}
|
|
324
|
+
{messages.map((m, i) => (
|
|
325
|
+
<div key={i} className={`ochat__msg ochat__msg--${m.role}`}>
|
|
326
|
+
{m.role === 'assistant' ? renderContent(m.content) : m.content}
|
|
327
|
+
{m.role === 'assistant' && streaming && i === messages.length - 1 && (
|
|
328
|
+
<span className="ochat__cursor" />
|
|
329
|
+
)}
|
|
330
|
+
</div>
|
|
331
|
+
))}
|
|
332
|
+
<div ref={bottomRef} />
|
|
333
|
+
</div>
|
|
334
|
+
|
|
335
|
+
<div className="ochat__footer">
|
|
336
|
+
<textarea
|
|
337
|
+
ref={inputRef}
|
|
338
|
+
className="ochat__input"
|
|
339
|
+
value={input}
|
|
340
|
+
onChange={(e) => setInput(e.target.value)}
|
|
341
|
+
onKeyDown={onKeyDown}
|
|
342
|
+
placeholder="Ask Pulse…"
|
|
343
|
+
rows={1}
|
|
344
|
+
disabled={streaming}
|
|
345
|
+
/>
|
|
346
|
+
<button
|
|
347
|
+
className="ochat__send"
|
|
348
|
+
onClick={send}
|
|
349
|
+
disabled={!input.trim() || streaming}
|
|
350
|
+
aria-label="Send"
|
|
351
|
+
>
|
|
352
|
+
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
353
|
+
<line x1="22" y1="2" x2="11" y2="13" />
|
|
354
|
+
<polygon points="22 2 15 22 11 13 2 9 22 2" />
|
|
355
|
+
</svg>
|
|
356
|
+
</button>
|
|
357
|
+
</div>
|
|
358
|
+
</div>
|
|
359
|
+
)}
|
|
360
|
+
</>
|
|
361
|
+
);
|
|
362
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
type Rev4aLoaderProps = {
|
|
2
|
+
label?: string;
|
|
3
|
+
fullHeight?: boolean;
|
|
4
|
+
compact?: boolean;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export default function Rev4aLoader({ label = 'LOADING', fullHeight = false, compact = false }: Rev4aLoaderProps) {
|
|
8
|
+
const logoSize = compact ? 42 : 64;
|
|
9
|
+
return (
|
|
10
|
+
<div
|
|
11
|
+
style={{
|
|
12
|
+
flex: 1,
|
|
13
|
+
minHeight: fullHeight ? '100dvh' : compact ? 120 : 220,
|
|
14
|
+
display: 'flex',
|
|
15
|
+
alignItems: 'center',
|
|
16
|
+
justifyContent: 'center',
|
|
17
|
+
padding: compact ? 12 : 20,
|
|
18
|
+
}}
|
|
19
|
+
>
|
|
20
|
+
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', gap: compact ? 10 : 14 }}>
|
|
21
|
+
<img
|
|
22
|
+
src="/rev4a-logo.svg"
|
|
23
|
+
alt="Rev4a loading"
|
|
24
|
+
width={logoSize}
|
|
25
|
+
height={logoSize}
|
|
26
|
+
style={{
|
|
27
|
+
objectFit: 'contain',
|
|
28
|
+
display: 'block',
|
|
29
|
+
animation: 'rev4a-loader-pulse 1.35s ease-in-out infinite',
|
|
30
|
+
filter: 'drop-shadow(0 0 16px rgba(146,91,252,0.22))',
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
33
|
+
<div style={{ fontFamily: 'var(--font-serif-stack, serif)', fontSize: compact ? 16 : 22, letterSpacing: compact ? 3 : 4, color: 'var(--violet)' }}>
|
|
34
|
+
REV4A
|
|
35
|
+
</div>
|
|
36
|
+
<div style={{ fontSize: compact ? 10 : 11, letterSpacing: '0.12em', color: 'var(--text-dim)' }}>
|
|
37
|
+
{label}
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
<style>{`
|
|
41
|
+
@keyframes rev4a-loader-pulse {
|
|
42
|
+
0%, 100% { transform: scale(0.96); opacity: 0.72; }
|
|
43
|
+
50% { transform: scale(1); opacity: 1; }
|
|
44
|
+
}
|
|
45
|
+
`}</style>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|