@memoryblock/web 0.1.0-beta
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/LICENSE +21 -0
- package/package.json +39 -0
- package/public/app.js +205 -0
- package/public/components/archive.js +110 -0
- package/public/components/auth.js +70 -0
- package/public/components/blocks.js +444 -0
- package/public/components/chat.js +394 -0
- package/public/components/create-block.js +108 -0
- package/public/components/settings.js +363 -0
- package/public/components/setup.js +301 -0
- package/public/index.html +16 -0
- package/public/style.css +1871 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 memoryblock
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@memoryblock/web",
|
|
3
|
+
"version": "0.1.0-beta",
|
|
4
|
+
"description": "Front-end dashboard and Web UI for memoryblock.",
|
|
5
|
+
"files": [
|
|
6
|
+
"public/"
|
|
7
|
+
],
|
|
8
|
+
"keywords": [
|
|
9
|
+
"memoryblock",
|
|
10
|
+
"mblk",
|
|
11
|
+
"ai-agent",
|
|
12
|
+
"assistants",
|
|
13
|
+
"agents",
|
|
14
|
+
"automation",
|
|
15
|
+
"multi-agent",
|
|
16
|
+
"agentic-framework",
|
|
17
|
+
"web",
|
|
18
|
+
"ui",
|
|
19
|
+
"dashboard",
|
|
20
|
+
"frontend",
|
|
21
|
+
"chat",
|
|
22
|
+
"chat-ui",
|
|
23
|
+
"dashboard"
|
|
24
|
+
],
|
|
25
|
+
"author": {
|
|
26
|
+
"name": "Ghazi",
|
|
27
|
+
"url": "https://mgks.dev"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/memoryblock-io/memoryblock.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/memoryblock-io/memoryblock/issues"
|
|
35
|
+
},
|
|
36
|
+
"homepage": "https://memoryblock.io",
|
|
37
|
+
"funding": "https://github.com/sponsors/mgks",
|
|
38
|
+
"license": "MIT"
|
|
39
|
+
}
|
package/public/app.js
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* memoryblock web ui — app router & shared utilities.
|
|
3
|
+
* ES module entry point — imports components.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { renderAuth, tryAutoAuth } from './components/auth.js';
|
|
7
|
+
import { renderBlocksList, renderBlockDetail } from './components/blocks.js';
|
|
8
|
+
import { renderSettings } from './components/settings.js';
|
|
9
|
+
import { renderCreateBlock } from './components/create-block.js';
|
|
10
|
+
import { renderArchive } from './components/archive.js';
|
|
11
|
+
import { renderSetup } from './components/setup.js';
|
|
12
|
+
import { renderChatView } from './components/chat.js';
|
|
13
|
+
|
|
14
|
+
const API_BASE = location.origin;
|
|
15
|
+
|
|
16
|
+
// ===== Token Management =====
|
|
17
|
+
|
|
18
|
+
export function getToken() { return localStorage.getItem('mblk_token') || ''; }
|
|
19
|
+
export function setToken(t) { localStorage.setItem('mblk_token', t); }
|
|
20
|
+
export function clearToken() { localStorage.removeItem('mblk_token'); }
|
|
21
|
+
|
|
22
|
+
// ===== Theme Management =====
|
|
23
|
+
|
|
24
|
+
export function getTheme() { return localStorage.getItem('mblk_theme') || 'dark'; }
|
|
25
|
+
export function setTheme(t) {
|
|
26
|
+
localStorage.setItem('mblk_theme', t);
|
|
27
|
+
document.documentElement.setAttribute('data-theme', t);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ===== API Helper =====
|
|
31
|
+
|
|
32
|
+
export async function api(path, options = {}) {
|
|
33
|
+
const res = await fetch(`${API_BASE}${path}`, {
|
|
34
|
+
...options,
|
|
35
|
+
headers: {
|
|
36
|
+
'Authorization': `Bearer ${getToken()}`,
|
|
37
|
+
...(options.body ? { 'Content-Type': 'application/json' } : {}),
|
|
38
|
+
...(options.headers || {})
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
if (res.status === 401) {
|
|
42
|
+
clearToken();
|
|
43
|
+
window.dispatchEvent(new Event('auth:logout'));
|
|
44
|
+
throw new Error('unauthorized');
|
|
45
|
+
}
|
|
46
|
+
return res.json();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ===== WebSocket Helper =====
|
|
50
|
+
|
|
51
|
+
export function connectWs(blockName, onRefresh) {
|
|
52
|
+
const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
53
|
+
const ws = new WebSocket(`${protocol}//${location.host}/api/ws?token=${getToken()}`);
|
|
54
|
+
|
|
55
|
+
ws.onopen = () => {
|
|
56
|
+
ws.send(JSON.stringify({ type: 'subscribe', block: blockName }));
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
ws.onmessage = (e) => {
|
|
60
|
+
try {
|
|
61
|
+
const msg = JSON.parse(e.data);
|
|
62
|
+
if (msg.type === 'refresh' && onRefresh) onRefresh();
|
|
63
|
+
} catch {}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return ws;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ===== Layout Templates =====
|
|
70
|
+
|
|
71
|
+
function mainLayout() {
|
|
72
|
+
return `
|
|
73
|
+
<div class="view active" id="main-view">
|
|
74
|
+
<header>
|
|
75
|
+
<div class="header-left">
|
|
76
|
+
<div class="brand-small">⬡ memoryblock</div>
|
|
77
|
+
<nav>
|
|
78
|
+
<button class="nav-btn active" data-tab="blocks">blocks</button>
|
|
79
|
+
<button class="nav-btn" data-tab="archive">archive</button>
|
|
80
|
+
<button class="nav-btn" data-tab="settings">settings</button>
|
|
81
|
+
</nav>
|
|
82
|
+
</div>
|
|
83
|
+
<button class="theme-toggle" id="quick-theme">${getTheme() === 'dark' ? '☀' : '◑'}</button>
|
|
84
|
+
</header>
|
|
85
|
+
<main id="main-content"></main>
|
|
86
|
+
</div>
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ===== Router =====
|
|
91
|
+
|
|
92
|
+
let currentTab = 'blocks';
|
|
93
|
+
|
|
94
|
+
async function showMain() {
|
|
95
|
+
// Check if any blocks exist — if not, show setup wizard
|
|
96
|
+
try {
|
|
97
|
+
const data = await api('/api/blocks');
|
|
98
|
+
if (!data.blocks || data.blocks.length === 0) {
|
|
99
|
+
const setupDone = localStorage.getItem('mblk_setup_done');
|
|
100
|
+
if (!setupDone) {
|
|
101
|
+
const app = document.getElementById('app');
|
|
102
|
+
renderSetup(app, {
|
|
103
|
+
api,
|
|
104
|
+
onComplete: () => {
|
|
105
|
+
localStorage.setItem('mblk_setup_done', '1');
|
|
106
|
+
showMain();
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} catch { }
|
|
113
|
+
|
|
114
|
+
const app = document.getElementById('app');
|
|
115
|
+
app.innerHTML = mainLayout();
|
|
116
|
+
|
|
117
|
+
const content = document.getElementById('main-content');
|
|
118
|
+
|
|
119
|
+
// Tab navigation
|
|
120
|
+
document.querySelectorAll('.nav-btn').forEach(btn => {
|
|
121
|
+
btn.addEventListener('click', () => {
|
|
122
|
+
currentTab = btn.dataset.tab;
|
|
123
|
+
document.querySelectorAll('.nav-btn').forEach(b => b.classList.remove('active'));
|
|
124
|
+
btn.classList.add('active');
|
|
125
|
+
renderTab(content, currentTab);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Quick theme toggle
|
|
130
|
+
document.getElementById('quick-theme').addEventListener('click', () => {
|
|
131
|
+
const next = getTheme() === 'dark' ? 'light' : 'dark';
|
|
132
|
+
setTheme(next);
|
|
133
|
+
document.getElementById('quick-theme').textContent = next === 'dark' ? '☀' : '◑';
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
renderTab(content, currentTab);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function renderTab(content, tab) {
|
|
140
|
+
if (tab === 'blocks') renderBlocksList(content);
|
|
141
|
+
else if (tab === 'archive') renderArchive(content, { apiBase: API_BASE, token: getToken() });
|
|
142
|
+
else if (tab === 'settings') renderSettings(content);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function showAuth() {
|
|
146
|
+
const app = document.getElementById('app');
|
|
147
|
+
renderAuth(app);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// ===== Event Listeners =====
|
|
151
|
+
|
|
152
|
+
window.addEventListener('auth:success', () => showMain());
|
|
153
|
+
window.addEventListener('auth:logout', () => showAuth());
|
|
154
|
+
window.addEventListener('navigate', (e) => {
|
|
155
|
+
const { view, block } = e.detail;
|
|
156
|
+
const content = document.getElementById('main-content');
|
|
157
|
+
if (view === 'detail' && block) {
|
|
158
|
+
renderBlockDetail(content, block);
|
|
159
|
+
} else if (view === 'chat' && block) {
|
|
160
|
+
renderChatView(content, block);
|
|
161
|
+
} else if (view === 'blocks') {
|
|
162
|
+
renderBlocksList(content);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// ===== Hash Router =====
|
|
167
|
+
|
|
168
|
+
function handleHash() {
|
|
169
|
+
const hash = window.location.hash;
|
|
170
|
+
const content = document.getElementById('main-content');
|
|
171
|
+
if (!content) return;
|
|
172
|
+
|
|
173
|
+
if (hash === '#/create') {
|
|
174
|
+
renderCreateBlock(content, {
|
|
175
|
+
apiBase: API_BASE,
|
|
176
|
+
token: getToken(),
|
|
177
|
+
onCreated: () => {},
|
|
178
|
+
});
|
|
179
|
+
} else if (hash.startsWith('#/block/')) {
|
|
180
|
+
const blockName = hash.replace('#/block/', '');
|
|
181
|
+
renderBlockDetail(content, blockName);
|
|
182
|
+
} else if (hash.startsWith('#/chat/')) {
|
|
183
|
+
const blockName = hash.replace('#/chat/', '');
|
|
184
|
+
renderChatView(content, blockName);
|
|
185
|
+
} else if (hash === '#/archive') {
|
|
186
|
+
currentTab = 'archive';
|
|
187
|
+
document.querySelectorAll('.nav-btn').forEach(b => b.classList.remove('active'));
|
|
188
|
+
document.querySelector('[data-tab="archive"]')?.classList.add('active');
|
|
189
|
+
renderArchive(content, { apiBase: API_BASE, token: getToken() });
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
window.addEventListener('hashchange', handleHash);
|
|
194
|
+
|
|
195
|
+
// ===== Init =====
|
|
196
|
+
|
|
197
|
+
(async () => {
|
|
198
|
+
setTheme(getTheme());
|
|
199
|
+
if (await tryAutoAuth()) {
|
|
200
|
+
showMain();
|
|
201
|
+
handleHash();
|
|
202
|
+
} else {
|
|
203
|
+
showAuth();
|
|
204
|
+
}
|
|
205
|
+
})();
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// archive.js — Archive management component
|
|
2
|
+
|
|
3
|
+
import { showToast } from './create-block.js';
|
|
4
|
+
|
|
5
|
+
export function renderArchive(container, { apiBase, token }) {
|
|
6
|
+
container.innerHTML = `
|
|
7
|
+
<div class="archive-view">
|
|
8
|
+
<div class="view-header">
|
|
9
|
+
<h2>Archived Blocks</h2>
|
|
10
|
+
</div>
|
|
11
|
+
<div id="archive-list" class="archive-list">
|
|
12
|
+
<div class="loading">Loading archives...</div>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
15
|
+
`;
|
|
16
|
+
|
|
17
|
+
loadArchives(apiBase, token);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function loadArchives(apiBase, token) {
|
|
21
|
+
const listEl = document.getElementById('archive-list');
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const res = await fetch(`${apiBase}/api/archive`, {
|
|
25
|
+
headers: { 'Authorization': `Bearer ${token}` },
|
|
26
|
+
});
|
|
27
|
+
const data = await res.json();
|
|
28
|
+
|
|
29
|
+
if (!data.archives || data.archives.length === 0) {
|
|
30
|
+
listEl.innerHTML = `
|
|
31
|
+
<div class="empty-state">
|
|
32
|
+
<span class="empty-icon">📦</span>
|
|
33
|
+
<p>No archived blocks.</p>
|
|
34
|
+
<p class="dim">Deleted blocks appear here for safe recovery.</p>
|
|
35
|
+
</div>
|
|
36
|
+
`;
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
listEl.innerHTML = data.archives.map(a => `
|
|
41
|
+
<div class="archive-card" data-name="${a.archiveName}">
|
|
42
|
+
<div class="archive-info">
|
|
43
|
+
<span class="archive-name">${a.originalName}</span>
|
|
44
|
+
<span class="archive-date">${formatDate(a.archivedAt)}</span>
|
|
45
|
+
</div>
|
|
46
|
+
<div class="archive-actions">
|
|
47
|
+
<button class="action-btn" data-action="restore" data-archive="${a.archiveName}">
|
|
48
|
+
Restore
|
|
49
|
+
</button>
|
|
50
|
+
<button class="action-btn danger" data-action="delete" data-archive="${a.archiveName}">
|
|
51
|
+
Delete Forever
|
|
52
|
+
</button>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
`).join('');
|
|
56
|
+
|
|
57
|
+
// Bind actions
|
|
58
|
+
listEl.querySelectorAll('[data-action="restore"]').forEach(btn => {
|
|
59
|
+
btn.addEventListener('click', () => handleRestore(btn.dataset.archive, apiBase, token));
|
|
60
|
+
});
|
|
61
|
+
listEl.querySelectorAll('[data-action="delete"]').forEach(btn => {
|
|
62
|
+
btn.addEventListener('click', () => handleDelete(btn.dataset.archive, apiBase, token));
|
|
63
|
+
});
|
|
64
|
+
} catch (err) {
|
|
65
|
+
listEl.innerHTML = `<div class="error-state">Failed to load archives: ${err.message}</div>`;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function handleRestore(archiveName, apiBase, token) {
|
|
70
|
+
if (!confirm(`Restore "${archiveName.split('_')[0]}" from archive?`)) return;
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const res = await fetch(`${apiBase}/api/archive/${archiveName}/restore`, {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
headers: { 'Authorization': `Bearer ${token}` },
|
|
76
|
+
});
|
|
77
|
+
const data = await res.json();
|
|
78
|
+
if (!res.ok) throw new Error(data.error);
|
|
79
|
+
|
|
80
|
+
showToast('Block restored successfully.');
|
|
81
|
+
loadArchives(apiBase, token);
|
|
82
|
+
} catch (err) {
|
|
83
|
+
showToast(`Restore failed: ${err.message}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function handleDelete(archiveName, apiBase, token) {
|
|
88
|
+
if (!confirm(`Permanently delete "${archiveName}"? This cannot be undone.`)) return;
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
const res = await fetch(`${apiBase}/api/archive/${archiveName}`, {
|
|
92
|
+
method: 'DELETE',
|
|
93
|
+
headers: { 'Authorization': `Bearer ${token}` },
|
|
94
|
+
});
|
|
95
|
+
const data = await res.json();
|
|
96
|
+
if (!res.ok) throw new Error(data.error);
|
|
97
|
+
|
|
98
|
+
showToast('Permanently deleted.');
|
|
99
|
+
loadArchives(apiBase, token);
|
|
100
|
+
} catch (err) {
|
|
101
|
+
showToast(`Delete failed: ${err.message}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function formatDate(isoString) {
|
|
106
|
+
if (!isoString) return 'Unknown date';
|
|
107
|
+
const d = new Date(isoString);
|
|
108
|
+
return d.toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' })
|
|
109
|
+
+ ' ' + d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' });
|
|
110
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth component — token input card and session management.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { api, getToken, setToken, clearToken } from '../app.js';
|
|
6
|
+
|
|
7
|
+
export function renderAuth(container) {
|
|
8
|
+
container.innerHTML = `
|
|
9
|
+
<div class="view active" id="auth-view">
|
|
10
|
+
<div class="auth-wrapper">
|
|
11
|
+
<div class="auth-card">
|
|
12
|
+
<div class="brand">⬡ memoryblock</div>
|
|
13
|
+
<p class="auth-hint">paste your auth token to continue</p>
|
|
14
|
+
<input type="text" class="token-input" id="token-input" placeholder="mblk_..." autocomplete="off" spellcheck="false">
|
|
15
|
+
<button class="btn-primary" id="auth-btn">connect</button>
|
|
16
|
+
<p class="error-text" id="auth-error"></p>
|
|
17
|
+
</div>
|
|
18
|
+
</div>
|
|
19
|
+
</div>
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
const input = document.getElementById('token-input');
|
|
23
|
+
const errorEl = document.getElementById('auth-error');
|
|
24
|
+
|
|
25
|
+
input.addEventListener('keydown', (e) => {
|
|
26
|
+
if (e.key === 'Enter') authenticate();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
document.getElementById('auth-btn').addEventListener('click', authenticate);
|
|
30
|
+
|
|
31
|
+
async function authenticate() {
|
|
32
|
+
const token = input.value.trim();
|
|
33
|
+
if (!token) { errorEl.textContent = 'enter a token'; return; }
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const res = await fetch(`${location.origin}/api/auth/status`, {
|
|
37
|
+
headers: { 'Authorization': `Bearer ${token}` },
|
|
38
|
+
});
|
|
39
|
+
const data = await res.json();
|
|
40
|
+
|
|
41
|
+
if (data.authenticated) {
|
|
42
|
+
setToken(token);
|
|
43
|
+
errorEl.textContent = '';
|
|
44
|
+
window.dispatchEvent(new Event('auth:success'));
|
|
45
|
+
} else {
|
|
46
|
+
errorEl.textContent = 'invalid token';
|
|
47
|
+
input.focus();
|
|
48
|
+
}
|
|
49
|
+
} catch {
|
|
50
|
+
errorEl.textContent = 'cannot reach api server';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
input.focus();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function tryAutoAuth() {
|
|
58
|
+
const token = getToken();
|
|
59
|
+
if (!token) return false;
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const res = await fetch(`${location.origin}/api/auth/status`, {
|
|
63
|
+
headers: { 'Authorization': `Bearer ${token}` },
|
|
64
|
+
});
|
|
65
|
+
const data = await res.json();
|
|
66
|
+
return data.authenticated;
|
|
67
|
+
} catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
}
|