@conarium-ai/core 0.1.2 → 0.2.0

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/public/app.js ADDED
@@ -0,0 +1,289 @@
1
+ document.addEventListener('DOMContentLoaded', () => {
2
+
3
+ // Tab Switching Logic
4
+ const tabs = document.querySelectorAll('.nav-item');
5
+ const contents = document.querySelectorAll('.tab-content');
6
+
7
+ tabs.forEach(tab => {
8
+ tab.addEventListener('click', (e) => {
9
+ e.preventDefault();
10
+ const targetId = `tab-${tab.dataset.tab}`;
11
+
12
+ tabs.forEach(t => t.classList.remove('active'));
13
+ contents.forEach(c => c.classList.remove('active'));
14
+
15
+ tab.classList.add('active');
16
+ document.getElementById(targetId).classList.add('active');
17
+ });
18
+ });
19
+
20
+ function authHeaders(extra) {
21
+ const params = new URLSearchParams(location.search)
22
+ let token = params.get('token') || sessionStorage.getItem('conarium-console-token') || ''
23
+ if (token) sessionStorage.setItem('conarium-console-token', token)
24
+ const headers = { ...(extra || {}) }
25
+ if (token) {
26
+ headers['Authorization'] = 'Bearer ' + token
27
+ headers['x-csrf-token'] = token
28
+ }
29
+ return headers
30
+ }
31
+
32
+ function policyOf(data) {
33
+ if (data && typeof data.policy === 'object' && data.policy) return data.policy
34
+ return data || {}
35
+ }
36
+
37
+ function parseList(raw) {
38
+ return String(raw || '')
39
+ .split(/[\n,]+/)
40
+ .map(s => s.trim())
41
+ .filter(Boolean)
42
+ }
43
+
44
+ function fillList(id, arr) {
45
+ const el = document.getElementById(id)
46
+ el.value = Array.isArray(arr) ? arr.join('\n') : ''
47
+ }
48
+
49
+ function setAllowTablesWarn(empty) {
50
+ const w = document.getElementById('allowTables-warn')
51
+ if (!w) return
52
+ w.hidden = !empty
53
+ }
54
+
55
+ // Load Config
56
+ async function loadConfig() {
57
+ try {
58
+ const res = await fetch('/api/config', { headers: authHeaders() })
59
+ if (!res.ok) {
60
+ showToast('Could not load policy (' + res.status + '). Pass ?token=…')
61
+ return
62
+ }
63
+ const data = await res.json()
64
+ const pol = policyOf(data)
65
+ const maxEl = document.getElementById('maxRows')
66
+ maxEl.value = pol.maxRows == null ? '' : String(pol.maxRows)
67
+ fillList('allowTables', pol.allowTables)
68
+ fillList('denyTables', pol.denyTables)
69
+ fillList('maskColumns', pol.maskColumns)
70
+ document.getElementById('allowTools').value = Array.isArray(pol.allowTools) ? pol.allowTools.join(', ') : ''
71
+ document.getElementById('denyTools').value = Array.isArray(pol.denyTools) ? pol.denyTools.join(', ') : ''
72
+ setAllowTablesWarn(!Array.isArray(pol.allowTables) || pol.allowTables.length === 0)
73
+ } catch (e) {
74
+ console.error('Failed to load config', e)
75
+ }
76
+ }
77
+
78
+ // Save Config — only the fields this form edits. connectors/audit/profiles stay on the server.
79
+ document.getElementById('config-form').addEventListener('submit', async (e) => {
80
+ e.preventDefault()
81
+
82
+ const maxRaw = document.getElementById('maxRows').value
83
+ const body = {
84
+ allowTables: parseList(document.getElementById('allowTables').value),
85
+ denyTables: parseList(document.getElementById('denyTables').value),
86
+ maskColumns: parseList(document.getElementById('maskColumns').value),
87
+ allowTools: parseList(document.getElementById('allowTools').value),
88
+ denyTools: parseList(document.getElementById('denyTools').value),
89
+ }
90
+ if (maxRaw !== '') body.maxRows = parseInt(maxRaw, 10)
91
+
92
+ setAllowTablesWarn(body.allowTables.length === 0)
93
+
94
+ try {
95
+ const res = await fetch('/api/config', {
96
+ method: 'POST',
97
+ headers: authHeaders({ 'Content-Type': 'application/json' }),
98
+ body: JSON.stringify(body)
99
+ })
100
+ if (res.ok) {
101
+ const out = await res.json().catch(() => ({}))
102
+ if (out.allowTablesEmpty) setAllowTablesWarn(true)
103
+ showToast('Governance Policy Saved')
104
+ } else {
105
+ showToast('Save failed (' + res.status + ')')
106
+ }
107
+ } catch (e) {
108
+ console.error('Failed to save config', e)
109
+ }
110
+ })
111
+
112
+ // Load Audit Logs
113
+ async function loadAudit() {
114
+ try {
115
+ const res = await fetch('/api/audit', { headers: authHeaders() });
116
+ const data = await res.json();
117
+
118
+ const tbody = document.getElementById('audit-body');
119
+ tbody.innerHTML = '';
120
+
121
+ if (data.length === 0) {
122
+ tbody.innerHTML = `<tr><td colspan="8" class="text-center">No audit logs found.</td></tr>`;
123
+ return;
124
+ }
125
+
126
+ data.forEach(log => {
127
+ const tr = document.createElement('tr');
128
+ const isDenied = Boolean(log.denied);
129
+ const statusClass = isDenied ? 'status-rejected' : 'status-success';
130
+ const statusText = isDenied ? 'Denied' : 'Allowed';
131
+ const sqlText = String(log.args && log.args.sql ? log.args.sql : (log.query || '-'));
132
+ const hashValue = String(log.hash || '');
133
+ const hashText = hashValue ? hashValue.substring(0, 8) + '...' : '-';
134
+
135
+ function tdText(value) {
136
+ const td = document.createElement('td');
137
+ td.textContent = String(value);
138
+ return td;
139
+ }
140
+ function tdCode(value) {
141
+ const td = document.createElement('td');
142
+ const code = document.createElement('code');
143
+ code.textContent = String(value);
144
+ td.appendChild(code);
145
+ return td;
146
+ }
147
+
148
+ tr.appendChild(tdText(new Date(log.timestamp).toLocaleString()));
149
+ tr.appendChild(tdText(log.actor || 'unknown'));
150
+ tr.appendChild(tdCode(log.tool || '-'));
151
+
152
+ const sqlTd = document.createElement('td');
153
+ sqlTd.title = sqlText;
154
+ const sqlCode = document.createElement('code');
155
+ sqlCode.textContent = sqlText.length > 40 ? sqlText.substring(0, 40) + '...' : sqlText;
156
+ sqlTd.appendChild(sqlCode);
157
+ tr.appendChild(sqlTd);
158
+
159
+ tr.appendChild(tdText(log.rowsReturned || 0));
160
+ tr.appendChild(tdText(`${log.maskedCount || 0} PII`));
161
+
162
+ const statusTd = document.createElement('td');
163
+ const status = document.createElement('span');
164
+ status.className = `status-badge-sm ${statusClass}`;
165
+ status.textContent = statusText;
166
+ statusTd.appendChild(status);
167
+ tr.appendChild(statusTd);
168
+
169
+ const hashTd = document.createElement('td');
170
+ hashTd.title = hashValue;
171
+ const hashCode = document.createElement('code');
172
+ hashCode.style.fontSize = '0.75rem';
173
+ hashCode.style.color = 'var(--text-secondary)';
174
+ hashCode.textContent = hashText;
175
+ hashTd.appendChild(hashCode);
176
+ tr.appendChild(hashTd);
177
+
178
+ tbody.appendChild(tr);
179
+ });
180
+ } catch (e) {
181
+ console.error('Failed to load audit logs', e);
182
+ }
183
+ }
184
+
185
+ document.getElementById('refresh-audit').addEventListener('click', loadAudit);
186
+
187
+ // Load Connectors
188
+ async function loadConnectors() {
189
+ try {
190
+ const res = await fetch('/api/connectors', { headers: authHeaders() });
191
+ const data = await res.json();
192
+
193
+ const list = document.getElementById('connector-list');
194
+ list.innerHTML = '';
195
+
196
+ data.forEach(conn => {
197
+ const statusColor = conn.status === 'connected' ? 'var(--success)' : 'var(--danger)';
198
+ const el = document.createElement('div');
199
+ el.className = 'connector-item';
200
+ el.innerHTML = `
201
+ <div class="connector-info">
202
+ <h4>${conn.id}</h4>
203
+ <span>${conn.type}</span>
204
+ </div>
205
+ <div style="text-align: right">
206
+ <div style="color: ${statusColor}; font-weight: 600; font-size: 0.875rem;">
207
+ ● ${conn.status}
208
+ </div>
209
+ <span style="font-size: 0.75rem; color: var(--text-secondary)">${conn.latency}</span>
210
+ </div>
211
+ `;
212
+ list.appendChild(el);
213
+ });
214
+ } catch (e) {
215
+ console.error('Failed to load connectors', e);
216
+ }
217
+ }
218
+
219
+ // --- Live Playground ---
220
+ const pgQuery = document.getElementById('pg-query');
221
+ document.querySelectorAll('.pg-samples .chip').forEach(chip => {
222
+ chip.addEventListener('click', () => { pgQuery.value = chip.dataset.q; });
223
+ });
224
+
225
+ function renderRows(rows) {
226
+ return rows.map(r => {
227
+ const lines = Object.entries(r).map(([k, v]) => {
228
+ const masked = v === '[MASKED_PII]';
229
+ return ` <span class="jk">"${k}"</span>: <span class="${masked ? 'jmask' : 'jv'}">${JSON.stringify(v)}</span>`;
230
+ }).join(',\n');
231
+ return `{\n${lines}\n}`;
232
+ }).join(',\n');
233
+ }
234
+
235
+ const pgRun = document.getElementById('pg-run');
236
+ if (pgRun) pgRun.addEventListener('click', async () => {
237
+ const query = pgQuery.value.trim();
238
+ const out = document.getElementById('pg-result');
239
+ out.innerHTML = '<div class="loader">Running through Conarium…</div>';
240
+ try {
241
+ const res = await fetch('/api/playground', {
242
+ method: 'POST', headers: authHeaders({ 'Content-Type': 'application/json' }),
243
+ body: JSON.stringify({ query })
244
+ });
245
+ const d = await res.json();
246
+ if (d.decision === 'deny') {
247
+ out.innerHTML = `
248
+ <div class="pg-blocked">
249
+ <div class="pg-blocked-icon">🛑</div>
250
+ <div>
251
+ <h4>BLOCKED by Conarium</h4>
252
+ <p>${d.reason}</p>
253
+ <span class="pg-logged">✓ Logged to audit · decision: <code>deny</code></span>
254
+ </div>
255
+ </div>`;
256
+ } else {
257
+ out.innerHTML = `
258
+ <div class="pg-compare">
259
+ <div class="pg-col pg-raw">
260
+ <div class="pg-col-head">🔴 RAW — direct DB access</div>
261
+ <pre>${renderRows(d.raw)}</pre>
262
+ </div>
263
+ <div class="pg-arrow">▸</div>
264
+ <div class="pg-col pg-gov">
265
+ <div class="pg-col-head">🟢 GOVERNED — through Conarium</div>
266
+ <pre>${renderRows(d.governed)}</pre>
267
+ </div>
268
+ </div>
269
+ <div class="pg-logged">✓ <strong>${d.maskedCount}</strong> PII field(s) masked · ${d.governed.length} row(s) · logged to audit</div>`;
270
+ }
271
+ loadAudit();
272
+ } catch (e) {
273
+ out.innerHTML = `<div class="pg-blocked"><p>Error: ${e.message}</p></div>`;
274
+ }
275
+ });
276
+
277
+ // Toast Utility
278
+ function showToast(msg) {
279
+ const toast = document.getElementById('toast');
280
+ toast.textContent = msg;
281
+ toast.classList.add('show');
282
+ setTimeout(() => toast.classList.remove('show'), 3000);
283
+ }
284
+
285
+ // Initialize
286
+ loadConfig();
287
+ loadAudit();
288
+ loadConnectors();
289
+ });
@@ -0,0 +1,131 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Conarium Governance Console</title>
7
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
8
+ <link rel="stylesheet" href="style.css">
9
+ </head>
10
+ <body>
11
+ <div class="app-container">
12
+ <!-- Sidebar -->
13
+ <aside class="sidebar glass-panel">
14
+ <div class="logo">
15
+ <div class="logo-icon"></div>
16
+ <h2>Conarium</h2>
17
+ </div>
18
+ <nav>
19
+ <a href="#" class="nav-item active" data-tab="dashboard">Dashboard</a>
20
+ <a href="#" class="nav-item" data-tab="playground">Playground</a>
21
+ <a href="#" class="nav-item" data-tab="governance">Governance</a>
22
+ <a href="#" class="nav-item" data-tab="audit">Audit Logs</a>
23
+ </nav>
24
+ </aside>
25
+
26
+ <!-- Main Content -->
27
+ <main class="main-content">
28
+ <header class="header glass-panel">
29
+ <h1>Conarium Control Center</h1>
30
+ <div class="status-badge pulse"><span class="dot"></span> System Active</div>
31
+ </header>
32
+
33
+ <div class="tab-content active" id="tab-dashboard">
34
+ <div class="dashboard-grid">
35
+ <div class="card glass-panel span-2">
36
+ <h3>Connectors Health</h3>
37
+ <div class="connector-list" id="connector-list">
38
+ <div class="loader">Loading connectors...</div>
39
+ </div>
40
+ </div>
41
+ </div>
42
+ </div>
43
+
44
+ <div class="tab-content" id="tab-playground">
45
+ <div class="card glass-panel">
46
+ <h3>Live Playground</h3>
47
+ <p class="pg-sub">An AI assistant queries your data. Watch Conarium <strong>mask the secrets</strong> and <strong>block forbidden tables</strong> — live.</p>
48
+ <div class="pg-samples">
49
+ <button class="chip" data-q="SELECT * FROM customers">customers <span>(PII)</span></button>
50
+ <button class="chip" data-q="SELECT * FROM orders">orders</button>
51
+ <button class="chip chip-danger" data-q="SELECT * FROM secrets">secrets <span>(denied)</span></button>
52
+ <button class="chip chip-danger" data-q="DELETE FROM customers">DELETE <span>(write)</span></button>
53
+ </div>
54
+ <div class="pg-input-row">
55
+ <input type="text" id="pg-query" class="glass-input" value="SELECT * FROM customers" placeholder="SELECT * FROM customers">
56
+ <button class="btn primary-btn" id="pg-run">Run through Conarium ▸</button>
57
+ </div>
58
+ <div id="pg-result" class="pg-result"></div>
59
+ </div>
60
+ </div>
61
+
62
+ <div class="tab-content" id="tab-governance">
63
+ <div class="card glass-panel">
64
+ <h3>Governance Policy</h3>
65
+ <form id="config-form" class="config-form">
66
+ <div class="form-group">
67
+ <label for="maxRows">Max rows</label>
68
+ <input type="number" id="maxRows" name="maxRows" class="glass-input" min="1" max="10000">
69
+ </div>
70
+ <div class="form-group">
71
+ <label for="allowTables">Allow tables <span class="hint">schema-qualified, one per line or comma-separated — public.accounts</span></label>
72
+ <textarea id="allowTables" name="allowTables" class="glass-input list-input" rows="4" placeholder="public.accounts&#10;public.transactions"></textarea>
73
+ <p id="allowTables-warn" class="policy-warn" hidden>allowTables is empty — fail-closed: the gateway will deny every table. Add schema-qualified names if that is not what you meant.</p>
74
+ </div>
75
+ <div class="form-group">
76
+ <label for="denyTables">Deny tables</label>
77
+ <textarea id="denyTables" name="denyTables" class="glass-input list-input" rows="3" placeholder="public.card_vault"></textarea>
78
+ </div>
79
+ <div class="form-group">
80
+ <label for="maskColumns">Mask columns <span class="hint">*.tckn, public.accounts.iban</span></label>
81
+ <textarea id="maskColumns" name="maskColumns" class="glass-input list-input" rows="3" placeholder="*.tckn&#10;*.iban&#10;*.email"></textarea>
82
+ </div>
83
+ <div class="form-group">
84
+ <label for="allowTools">Allow tools (optional)</label>
85
+ <input type="text" id="allowTools" name="allowTools" class="glass-input">
86
+ </div>
87
+ <div class="form-group">
88
+ <label for="denyTools">Deny tools (optional)</label>
89
+ <input type="text" id="denyTools" name="denyTools" class="glass-input">
90
+ </div>
91
+ <button type="submit" class="btn primary-btn">Save Policy</button>
92
+ </form>
93
+ </div>
94
+ </div>
95
+
96
+ <div class="tab-content" id="tab-audit">
97
+ <div class="card glass-panel">
98
+ <div class="card-header">
99
+ <h3>Audit Logs</h3>
100
+ <button class="btn secondary-btn" id="refresh-audit">Refresh</button>
101
+ </div>
102
+ <div class="table-container">
103
+ <table class="audit-table">
104
+ <thead>
105
+ <tr>
106
+ <th>Timestamp</th>
107
+ <th>Actor</th>
108
+ <th>Tool</th>
109
+ <th>Query (SQL)</th>
110
+ <th>Rows</th>
111
+ <th>Masked</th>
112
+ <th>Status</th>
113
+ <th>Hash</th>
114
+ </tr>
115
+ </thead>
116
+ <tbody id="audit-body">
117
+ <tr><td colspan="8" class="text-center">Loading...</td></tr>
118
+ </tbody>
119
+ </table>
120
+ </div>
121
+ </div>
122
+ </div>
123
+ </main>
124
+ </div>
125
+
126
+ <!-- Notification Toast -->
127
+ <div id="toast" class="toast">Saved successfully</div>
128
+
129
+ <script src="app.js"></script>
130
+ </body>
131
+ </html>