@anmol-srv/sigil 0.12.2 → 0.14.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/dist/cli.js +359 -373
- package/dist/daemon.js +151 -165
- package/dist/hooks/post-tool-use.js +25 -22
- package/dist/hooks/session-end.js +76 -73
- package/dist/hooks/stop.js +72 -69
- package/dist/hooks/user-prompt-submit.js +48 -45
- package/dist/server.js +46 -41
- package/package.json +1 -1
- package/src/db/migrations/20260429120200_upgrade-embedding-dim-1024.cjs +11 -22
- package/src/gui/web/app.css +102 -0
- package/src/gui/web/app.js +84 -557
- package/src/gui/web/index.html +18 -185
- package/src/gui/web/setup.js +445 -0
package/src/gui/web/app.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
// Sigil GUI — vanilla JS. Onboarding wizard + dashboard.
|
|
2
2
|
import { toast } from './toast.js';
|
|
3
|
-
import { connectorCard
|
|
3
|
+
import { connectorCard } from './components.js';
|
|
4
|
+
import { initSetup } from './setup.js';
|
|
4
5
|
|
|
5
6
|
const $ = (sel, root = document) => root.querySelector(sel);
|
|
6
7
|
const $$ = (sel, root = document) => root.querySelectorAll(sel);
|
|
7
8
|
|
|
8
|
-
// Onboarding machine step (SCREAMING_SNAKE) → wizard section id.
|
|
9
|
-
const MACHINE_TO_STEP = { CONNECTORS: 'connectors', PROVIDER: 'llm', EMBEDDING: 'embedding', DATABASE: 'database', FINISH: 'finish' };
|
|
10
|
-
async function persistStep(step, status, data = {}) {
|
|
11
|
-
try { await rpc('onboardingAdvance', { step, status, data }); }
|
|
12
|
-
catch (err) { /* non-fatal: state persistence is best-effort */ void err; }
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
// ── RPC ──────────────────────────────────────────────────────────────
|
|
16
10
|
async function rpc(method, params = {}) {
|
|
17
11
|
const res = await fetch('/api/v1/rpc', {
|
|
@@ -55,493 +49,6 @@ async function copyToClipboard(text) {
|
|
|
55
49
|
}
|
|
56
50
|
}
|
|
57
51
|
|
|
58
|
-
// ════════════════════════════════════════════════════════════════════
|
|
59
|
-
// ONBOARDING WIZARD
|
|
60
|
-
// ════════════════════════════════════════════════════════════════════
|
|
61
|
-
const wizardState = { step: 'connectors', llmProvider: null, embProvider: null, llmProviders: [], embProviders: [], connectorsLoaded: false, dbInit: false, connectedCount: 0 };
|
|
62
|
-
|
|
63
|
-
const STEP_ORDER = ['connectors', 'llm', 'embedding', 'database', 'finish'];
|
|
64
|
-
|
|
65
|
-
function setOnbStep(stepId) {
|
|
66
|
-
wizardState.step = stepId;
|
|
67
|
-
const idx = STEP_ORDER.indexOf(stepId);
|
|
68
|
-
$$('.onboarding-step').forEach((el) => {
|
|
69
|
-
const i = STEP_ORDER.indexOf(el.dataset.obStep);
|
|
70
|
-
el.classList.remove('active', 'done', 'future');
|
|
71
|
-
if (i < idx) el.classList.add('done');
|
|
72
|
-
else if (i === idx) el.classList.add('active');
|
|
73
|
-
else el.classList.add('future');
|
|
74
|
-
});
|
|
75
|
-
$$('.wizard-step').forEach((el) => el.classList.toggle('active', el.dataset.step === stepId));
|
|
76
|
-
// Lazy-fetch per-step data when first entering a step.
|
|
77
|
-
if (stepId === 'connectors' && !wizardState.connectorsLoaded) loadConnectors();
|
|
78
|
-
if (stepId === 'llm' && !wizardState.llmProviders.length) loadLlmProviders();
|
|
79
|
-
if (stepId === 'embedding' && !wizardState.embProviders.length) loadEmbeddingProviders();
|
|
80
|
-
if (stepId === 'database' && !wizardState.dbInit) initDbStep();
|
|
81
|
-
if (stepId === 'finish') renderFinish();
|
|
82
|
-
document.querySelector('.onboarding-content')?.scrollTo(0, 0);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
async function loadOnboardingState() {
|
|
86
|
-
try {
|
|
87
|
-
const state = await rpc('onboardingState');
|
|
88
|
-
if (state.setupComplete) {
|
|
89
|
-
$('#onboarding').hidden = true;
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
$('#onboarding').hidden = false;
|
|
93
|
-
if (state.steps.database.done) $('#ob-db-next').disabled = false;
|
|
94
|
-
if (state.steps.llm.done) $('#ob-llm-next').disabled = false;
|
|
95
|
-
if (state.steps.embedding.done) $('#ob-emb-next').disabled = false;
|
|
96
|
-
// Resume at the machine's current step (refresh mid-wizard → same place).
|
|
97
|
-
const resume = MACHINE_TO_STEP[state.machine?.currentStep];
|
|
98
|
-
if (resume && resume !== 'connectors') setOnbStep(resume);
|
|
99
|
-
else setOnbStep('connectors');
|
|
100
|
-
} catch {
|
|
101
|
-
// Could not reach daemon — show the first step anyway.
|
|
102
|
-
$('#onboarding').hidden = false;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// ── Connectors step ──────────────────────────────────────────────────
|
|
107
|
-
async function loadConnectors() {
|
|
108
|
-
wizardState.connectorsLoaded = true;
|
|
109
|
-
const host = $('#ob-connectors');
|
|
110
|
-
try {
|
|
111
|
-
const { connectors } = await rpc('listConnectors');
|
|
112
|
-
wizardState.connectedCount = connectors.filter((c) => c.status === 'connected').length;
|
|
113
|
-
renderConnectors(connectors);
|
|
114
|
-
} catch (err) {
|
|
115
|
-
host.innerHTML = `<div class="muted">could not load connectors: ${escape(err.message)}</div>`;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function renderConnectors(connectors) {
|
|
120
|
-
const host = $('#ob-connectors');
|
|
121
|
-
host.innerHTML = '';
|
|
122
|
-
connectors.forEach((c) => host.appendChild(connectorCard(c, onConnectorAction)));
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function onConnectorAction(id, action) {
|
|
126
|
-
const host = $('#ob-connectors');
|
|
127
|
-
const card = host.querySelector(`[data-id="${id}"]`);
|
|
128
|
-
if (action === 'disconnect') {
|
|
129
|
-
try {
|
|
130
|
-
await rpc('disconnectConnector', { id });
|
|
131
|
-
toast({ variant: 'success', message: `${id} disconnected` });
|
|
132
|
-
} catch (err) { toast({ variant: 'error', message: err.message, hint: err.hint, code: err.code }); }
|
|
133
|
-
return loadConnectors();
|
|
134
|
-
}
|
|
135
|
-
// connect / retry → optimistic "connecting" card, then refresh.
|
|
136
|
-
if (card) card.replaceWith(connectorCard({ id, label: id, hint: '', uiState: 'connecting' }, onConnectorAction));
|
|
137
|
-
try {
|
|
138
|
-
await rpc('connectConnector', { id });
|
|
139
|
-
toast({ variant: 'success', message: `${id} connected` });
|
|
140
|
-
} catch (err) {
|
|
141
|
-
toast({ variant: 'error', message: err.message || `could not connect ${id}`, hint: err.hint, code: err.code });
|
|
142
|
-
}
|
|
143
|
-
return loadConnectors();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// ── DB step (linear guided flow) ─────────────────────────────────────
|
|
147
|
-
function dbMode() {
|
|
148
|
-
return $('input[name="db-mode"]:checked')?.value || 'url';
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
$('#db-mode-cards')?.addEventListener('click', (e) => {
|
|
152
|
-
const card = e.target.closest('[data-db-mode]');
|
|
153
|
-
if (!card || card.hidden) return;
|
|
154
|
-
$$('#db-mode-cards .provider-card').forEach((c) => c.classList.remove('selected'));
|
|
155
|
-
card.classList.add('selected');
|
|
156
|
-
card.querySelector('input').checked = true;
|
|
157
|
-
const mode = card.dataset.dbMode;
|
|
158
|
-
$('#ob-db-url').style.display = mode === 'url' ? '' : 'none';
|
|
159
|
-
$('#ob-db-fields').style.display = mode === 'fields' ? '' : 'none';
|
|
160
|
-
$('#ob-db-setup').textContent = mode === 'docker' ? 'Create local database' : 'Set up database';
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// Probe Docker once; if present, surface the recommended "Local (automatic)"
|
|
164
|
-
// mode and select it by default. Otherwise leave URL selected.
|
|
165
|
-
async function initDbStep() {
|
|
166
|
-
wizardState.dbInit = true;
|
|
167
|
-
try {
|
|
168
|
-
const d = await rpc('dbDockerAvailable');
|
|
169
|
-
const note = $('#ob-db-docker-note');
|
|
170
|
-
if (d.available) {
|
|
171
|
-
const dockerCard = $('#ob-db-mode-docker');
|
|
172
|
-
dockerCard.hidden = false;
|
|
173
|
-
dockerCard.click();
|
|
174
|
-
} else if (note) {
|
|
175
|
-
note.hidden = false;
|
|
176
|
-
note.textContent = `Docker not detected (${d.reason || 'unavailable'}) — use a connection URL or local Postgres.`;
|
|
177
|
-
}
|
|
178
|
-
} catch { /* leave URL mode as the default */ }
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function obDbParams() {
|
|
182
|
-
if (dbMode() === 'url') return { url: $('#ob-db-url-input').value.trim() };
|
|
183
|
-
return {
|
|
184
|
-
host: $('#ob-db-host').value.trim(),
|
|
185
|
-
port: Number($('#ob-db-port').value),
|
|
186
|
-
database: $('#ob-db-db').value.trim(),
|
|
187
|
-
user: $('#ob-db-user').value.trim(),
|
|
188
|
-
password: $('#ob-db-pass').value,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function dbFlowInit(rows) {
|
|
193
|
-
const flow = $('#ob-db-flow');
|
|
194
|
-
flow.hidden = false;
|
|
195
|
-
flow.innerHTML = '';
|
|
196
|
-
rows.forEach(([id, label]) => flow.appendChild(dbFlowRow(id, label)));
|
|
197
|
-
return flow;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
$('#ob-db-setup')?.addEventListener('click', async () => {
|
|
201
|
-
const btn = $('#ob-db-setup');
|
|
202
|
-
btn.disabled = true;
|
|
203
|
-
$('#ob-db-next').disabled = true;
|
|
204
|
-
const mode = dbMode();
|
|
205
|
-
try {
|
|
206
|
-
if (mode === 'docker') {
|
|
207
|
-
await runDockerFlow();
|
|
208
|
-
} else {
|
|
209
|
-
await runUrlFlow();
|
|
210
|
-
}
|
|
211
|
-
} finally {
|
|
212
|
-
btn.disabled = false;
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
async function runDockerFlow() {
|
|
217
|
-
const flow = dbFlowInit([['provision', 'Create pgvector container'], ['migrate', 'Run migrations']]);
|
|
218
|
-
setFlowRow(flow, 'provision', { phase: 'active', detail: 'pulling image + starting…' });
|
|
219
|
-
try {
|
|
220
|
-
const r = await rpc('dbProvisionDocker');
|
|
221
|
-
setFlowRow(flow, 'provision', { phase: 'done', detail: `${r.container} :${r.port}${r.reused ? ' (reused)' : ''}` });
|
|
222
|
-
setFlowRow(flow, 'migrate', { phase: 'done', detail: `${r.migrationsRan} migrations · pgvector ✓` });
|
|
223
|
-
await onDbReady({ pgvector: true, migrationsRan: r.migrationsRan, mode: 'docker' });
|
|
224
|
-
} catch (err) {
|
|
225
|
-
setFlowRow(flow, 'provision', { phase: 'error', detail: err.code || 'failed' });
|
|
226
|
-
toast({ variant: 'error', message: err.message, hint: err.hint, code: err.code });
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
async function runUrlFlow() {
|
|
231
|
-
const params = obDbParams();
|
|
232
|
-
const flow = dbFlowInit([['test', 'Test connection'], ['pgvector', 'Enable pgvector'], ['migrate', 'Run migrations']]);
|
|
233
|
-
// 1. test
|
|
234
|
-
setFlowRow(flow, 'test', { phase: 'active', detail: 'connecting…' });
|
|
235
|
-
let test;
|
|
236
|
-
try {
|
|
237
|
-
test = await rpc('testDbConnection', params);
|
|
238
|
-
} catch (err) {
|
|
239
|
-
setFlowRow(flow, 'test', { phase: 'error', detail: err.code || 'failed' });
|
|
240
|
-
return toast({ variant: 'error', message: err.message, hint: err.hint, code: err.code });
|
|
241
|
-
}
|
|
242
|
-
if (!test.ok) {
|
|
243
|
-
setFlowRow(flow, 'test', { phase: 'error', detail: test.code || test.stage || 'failed' });
|
|
244
|
-
return toast({ variant: 'error', message: test.error || 'connection failed', hint: test.fixHint, code: test.kind });
|
|
245
|
-
}
|
|
246
|
-
setFlowRow(flow, 'test', { phase: 'done', detail: `${test.provider} · ${test.connectMs}ms` });
|
|
247
|
-
// 2. pgvector
|
|
248
|
-
if (!test.pgvector) {
|
|
249
|
-
setFlowRow(flow, 'pgvector', { phase: 'active', detail: 'installing…' });
|
|
250
|
-
try {
|
|
251
|
-
const pg = await rpc('ensurePgvector', params);
|
|
252
|
-
if (!pg.ok || !pg.installed) throw Object.assign(new Error(pg.error || 'could not enable pgvector'), { hint: pg.fixHint });
|
|
253
|
-
setFlowRow(flow, 'pgvector', { phase: 'done', detail: pg.version ? `v${pg.version}` : 'enabled' });
|
|
254
|
-
} catch (err) {
|
|
255
|
-
setFlowRow(flow, 'pgvector', { phase: 'error', detail: err.code || 'failed' });
|
|
256
|
-
return toast({ variant: 'error', message: err.message, hint: err.hint, code: err.code });
|
|
257
|
-
}
|
|
258
|
-
} else {
|
|
259
|
-
setFlowRow(flow, 'pgvector', { phase: 'done', detail: 'already enabled' });
|
|
260
|
-
}
|
|
261
|
-
// 3. persist + migrate
|
|
262
|
-
setFlowRow(flow, 'migrate', { phase: 'active', detail: 'writing env + migrating…' });
|
|
263
|
-
try {
|
|
264
|
-
if (params.url) {
|
|
265
|
-
await rpc('writeEnv', { patch: { SIGIL_DATABASE_URL: params.url, SIGIL_DB_HOST: null, SIGIL_DB_PORT: null, SIGIL_DB_NAME: null, SIGIL_DB_USER: null, SIGIL_DB_PASSWORD: null } });
|
|
266
|
-
} else {
|
|
267
|
-
await rpc('writeEnv', { patch: { SIGIL_DB_HOST: params.host, SIGIL_DB_PORT: String(params.port), SIGIL_DB_NAME: params.database, SIGIL_DB_USER: params.user, SIGIL_DB_PASSWORD: params.password, SIGIL_DATABASE_URL: null } });
|
|
268
|
-
}
|
|
269
|
-
const m = await rpc('runMigrations', params);
|
|
270
|
-
setFlowRow(flow, 'migrate', { phase: 'done', detail: `batch ${m.batchNo} · ${m.ran.length} applied` });
|
|
271
|
-
await onDbReady({ pgvector: true, migrationsRan: m.ran.length, mode: dbMode() });
|
|
272
|
-
} catch (err) {
|
|
273
|
-
setFlowRow(flow, 'migrate', { phase: 'error', detail: err.code || 'failed' });
|
|
274
|
-
toast({ variant: 'error', message: err.message, hint: err.hint, code: err.code });
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
async function onDbReady(data) {
|
|
279
|
-
$('#ob-db-next').disabled = false;
|
|
280
|
-
toast({ variant: 'success', message: 'Database ready.' });
|
|
281
|
-
await persistStep('DATABASE', 'DONE', data);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// ── LLM provider step ───────────────────────────────────────────────
|
|
285
|
-
async function loadLlmProviders() {
|
|
286
|
-
try {
|
|
287
|
-
const { providers } = await rpc('listLlmProviders');
|
|
288
|
-
wizardState.llmProviders = providers;
|
|
289
|
-
$('#ob-llm-cards').innerHTML = providers.map((p) => `
|
|
290
|
-
<label class="provider-card" data-llm-id="${escape(p.id)}">
|
|
291
|
-
<span class="check"></span>
|
|
292
|
-
<span class="name">${escape(p.label)}${p.recommended ? ' <span class="badge info" style="margin-left:8px;">RECOMMENDED</span>' : ''}</span>
|
|
293
|
-
<span class="hint">${escape(p.hint)}</span>
|
|
294
|
-
</label>
|
|
295
|
-
`).join('');
|
|
296
|
-
// Auto-select recommended
|
|
297
|
-
const recommended = providers.find((p) => p.recommended);
|
|
298
|
-
if (recommended) selectLlmProvider(recommended.id);
|
|
299
|
-
} catch (err) {
|
|
300
|
-
$('#ob-llm-cards').innerHTML = `<div class="muted">failed: ${escape(err.message)}</div>`;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
function selectLlmProvider(id) {
|
|
304
|
-
wizardState.llmProvider = id;
|
|
305
|
-
$$('#ob-llm-cards .provider-card').forEach((c) => c.classList.toggle('selected', c.dataset.llmId === id));
|
|
306
|
-
const p = wizardState.llmProviders.find((x) => x.id === id);
|
|
307
|
-
if (!p) return;
|
|
308
|
-
if (!p.fields.length) {
|
|
309
|
-
$('#ob-llm-fields').innerHTML = `<p class="muted text-sm">No additional configuration needed — Sigil will use your local Claude Code subscription.</p>`;
|
|
310
|
-
} else {
|
|
311
|
-
$('#ob-llm-fields').innerHTML = p.fields.map((f) => `
|
|
312
|
-
<label class="field">
|
|
313
|
-
<span class="label">${escape(f.label)}${f.optional ? ' <span class="muted text-xs">(optional)</span>' : ''}</span>
|
|
314
|
-
<input type="${f.type}" data-llm-field="${escape(f.name)}" placeholder="${escape(f.placeholder || '')}" autocomplete="off">
|
|
315
|
-
</label>
|
|
316
|
-
`).join('');
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
$('#ob-llm-cards')?.addEventListener('click', (e) => {
|
|
320
|
-
const card = e.target.closest('[data-llm-id]');
|
|
321
|
-
if (card) selectLlmProvider(card.dataset.llmId);
|
|
322
|
-
});
|
|
323
|
-
$('#ob-llm-save')?.addEventListener('click', async () => {
|
|
324
|
-
if (!wizardState.llmProvider) return;
|
|
325
|
-
const fields = {};
|
|
326
|
-
$$('#ob-llm-fields [data-llm-field]').forEach((i) => { if (i.value) fields[i.dataset.llmField] = i.value; });
|
|
327
|
-
const out = $('#ob-llm-result');
|
|
328
|
-
out.hidden = false; out.className = 'result'; out.textContent = 'saving…';
|
|
329
|
-
try {
|
|
330
|
-
await rpc('configureLlm', { id: wizardState.llmProvider, ...fields });
|
|
331
|
-
out.textContent = 'env written. Testing live LLM call…';
|
|
332
|
-
const test = await rpc('testLlm', {});
|
|
333
|
-
if (test.ok) {
|
|
334
|
-
out.classList.add('ok');
|
|
335
|
-
out.textContent += `\n✓ provider responded: "${test.response}"`;
|
|
336
|
-
$('#ob-llm-next').disabled = false;
|
|
337
|
-
await persistStep('PROVIDER', 'DONE', { llmProvider: wizardState.llmProvider });
|
|
338
|
-
} else {
|
|
339
|
-
out.classList.add('err');
|
|
340
|
-
out.textContent += `\n✗ test failed: ${test.error}`;
|
|
341
|
-
toast({ variant: 'error', message: test.error || 'LLM test failed', hint: test.fixHint, code: test.kind });
|
|
342
|
-
}
|
|
343
|
-
} catch (err) {
|
|
344
|
-
out.classList.add('err');
|
|
345
|
-
out.textContent = `✗ ${err.message}`;
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
// ── Embedding step ──────────────────────────────────────────────────
|
|
350
|
-
async function loadEmbeddingProviders() {
|
|
351
|
-
try {
|
|
352
|
-
const { providers } = await rpc('listEmbeddingProviders');
|
|
353
|
-
wizardState.embProviders = providers;
|
|
354
|
-
$('#ob-emb-cards').innerHTML = providers.map((p) => `
|
|
355
|
-
<label class="provider-card" data-emb-id="${escape(p.id)}">
|
|
356
|
-
<span class="check"></span>
|
|
357
|
-
<span class="name">${escape(p.label)}${p.recommended ? ' <span class="badge info" style="margin-left:8px;">RECOMMENDED</span>' : ''}</span>
|
|
358
|
-
<span class="hint">${escape(p.hint)}</span>
|
|
359
|
-
</label>
|
|
360
|
-
`).join('');
|
|
361
|
-
const r = providers.find((p) => p.recommended);
|
|
362
|
-
if (r) selectEmbProvider(r.id);
|
|
363
|
-
} catch (err) {
|
|
364
|
-
$('#ob-emb-cards').innerHTML = `<div class="muted">failed: ${escape(err.message)}</div>`;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
function selectEmbProvider(id) {
|
|
368
|
-
wizardState.embProvider = id;
|
|
369
|
-
$$('#ob-emb-cards .provider-card').forEach((c) => c.classList.toggle('selected', c.dataset.embId === id));
|
|
370
|
-
const p = wizardState.embProviders.find((x) => x.id === id);
|
|
371
|
-
if (!p) return;
|
|
372
|
-
const visibleFields = p.fields.filter((f) => !f.sharedWith);
|
|
373
|
-
if (!visibleFields.length) {
|
|
374
|
-
const sharedNote = p.fields.find((f) => f.sharedWith === 'llm')
|
|
375
|
-
? '<p class="muted text-sm">Reuses the API key from your LLM step.</p>'
|
|
376
|
-
: '<p class="muted text-sm">No configuration needed.</p>';
|
|
377
|
-
$('#ob-emb-fields').innerHTML = sharedNote;
|
|
378
|
-
} else {
|
|
379
|
-
$('#ob-emb-fields').innerHTML = visibleFields.map((f) => `
|
|
380
|
-
<label class="field">
|
|
381
|
-
<span class="label">${escape(f.label)}</span>
|
|
382
|
-
<input type="${f.type}" data-emb-field="${escape(f.name)}" placeholder="${escape(f.placeholder || '')}" autocomplete="off">
|
|
383
|
-
</label>
|
|
384
|
-
`).join('');
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
$('#ob-emb-cards')?.addEventListener('click', (e) => {
|
|
388
|
-
const card = e.target.closest('[data-emb-id]');
|
|
389
|
-
if (card) selectEmbProvider(card.dataset.embId);
|
|
390
|
-
});
|
|
391
|
-
// Shared embedding apply+gate, used by both the wizard and Settings.
|
|
392
|
-
// 1. Check dim-compat against the target DB BEFORE writing config.
|
|
393
|
-
// 2. If a conflict (DB has data at a different dim) → render Wipe/Cancel,
|
|
394
|
-
// do NOT write config. Caller stays put until the user resolves it.
|
|
395
|
-
// 3. Otherwise configure + live-test, surfacing honest errors.
|
|
396
|
-
// Returns true on success (embedder healthy), false otherwise.
|
|
397
|
-
async function applyEmbeddingProvider({ providerId, fields, out, conflictHost, onSuccess }) {
|
|
398
|
-
const prov = (wizardState.embProviders || []).find((p) => p.id === providerId);
|
|
399
|
-
out.hidden = false; out.className = 'result';
|
|
400
|
-
out.textContent = 'checking compatibility with your database…';
|
|
401
|
-
|
|
402
|
-
// Dim-conflict gate (skip silently if the DB isn't reachable yet — the
|
|
403
|
-
// embedder test below will surface that honestly).
|
|
404
|
-
try {
|
|
405
|
-
const compat = await rpc('inspectEmbeddingCompat', { id: providerId });
|
|
406
|
-
if (compat.ok && compat.conflict) {
|
|
407
|
-
renderConflictCard({
|
|
408
|
-
host: conflictHost, compat, providerId, fields,
|
|
409
|
-
out, onResolved: () => applyEmbeddingProvider({ providerId, fields, out, conflictHost, onSuccess }),
|
|
410
|
-
});
|
|
411
|
-
return false;
|
|
412
|
-
}
|
|
413
|
-
} catch { /* DB unreachable — let the embed test report the real cause */ }
|
|
414
|
-
|
|
415
|
-
out.textContent = 'saving…';
|
|
416
|
-
try {
|
|
417
|
-
await rpc('configureEmbedding', { id: providerId, ...fields });
|
|
418
|
-
out.textContent = 'env written. Testing embed call…';
|
|
419
|
-
const test = await rpc('testEmbedding', {});
|
|
420
|
-
if (test.ok) {
|
|
421
|
-
out.classList.add('ok');
|
|
422
|
-
out.textContent = `✓ embedder healthy — returned ${test.dim}-dim vector (${escape(prov?.label || providerId)})`;
|
|
423
|
-
if (onSuccess) onSuccess(test);
|
|
424
|
-
return true;
|
|
425
|
-
}
|
|
426
|
-
out.classList.add('err');
|
|
427
|
-
out.textContent = `✗ ${test.error || 'embed test failed'}`;
|
|
428
|
-
if (test.fixHint) out.textContent += `\n → ${test.fixHint}`;
|
|
429
|
-
return false;
|
|
430
|
-
} catch (err) {
|
|
431
|
-
out.classList.add('err');
|
|
432
|
-
out.textContent = `✗ ${err.message}`;
|
|
433
|
-
return false;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
// Render the dimension-conflict resolution card: Wipe (destructive, confirmed)
|
|
438
|
-
// or Cancel. Never auto-destroys. `host` (the conflict container element) gets
|
|
439
|
-
// the card; `onResolved` re-runs the apply after a successful wipe.
|
|
440
|
-
function renderConflictCard({ host, compat, out, onResolved }) {
|
|
441
|
-
const target = host || out.parentElement;
|
|
442
|
-
const rows = Object.entries(compat.rowsAtRisk || {})
|
|
443
|
-
.map(([t, n]) => `${n.toLocaleString()} ${t}`).join(', ');
|
|
444
|
-
const card = document.createElement('div');
|
|
445
|
-
card.className = 'result err conflict-card';
|
|
446
|
-
card.innerHTML = `
|
|
447
|
-
<strong>Embedding size mismatch.</strong>
|
|
448
|
-
Your database stores <b>${compat.currentDim}-dim</b> vectors, but this provider produces
|
|
449
|
-
<b>${compat.targetDim}-dim</b>. They can't coexist — every save would fail.
|
|
450
|
-
<div class="muted" style="margin:6px 0;">At risk: ${escape(rows)} (${compat.totalAtRisk.toLocaleString()} rows).</div>
|
|
451
|
-
<div class="flex-row" style="margin-top:8px;">
|
|
452
|
-
<button type="button" class="btn danger" data-conflict-wipe>Wipe data & switch to ${compat.targetDim}-dim</button>
|
|
453
|
-
<button type="button" class="btn" data-conflict-cancel>Cancel</button>
|
|
454
|
-
</div>
|
|
455
|
-
<div class="muted text-sm" style="margin-top:6px;">Wipe deletes all ${compat.totalAtRisk.toLocaleString()} stored vectors. Pods/structure are kept; re-ingest to repopulate.</div>
|
|
456
|
-
`;
|
|
457
|
-
out.hidden = true;
|
|
458
|
-
// Remove any prior card before adding a fresh one.
|
|
459
|
-
target.querySelectorAll('.conflict-card').forEach((c) => c.remove());
|
|
460
|
-
target.appendChild(card);
|
|
461
|
-
|
|
462
|
-
card.querySelector('[data-conflict-cancel]').addEventListener('click', () => {
|
|
463
|
-
card.remove();
|
|
464
|
-
out.hidden = false; out.className = 'result';
|
|
465
|
-
out.textContent = 'Cancelled — no changes made. Pick a provider matching your data, or wipe to switch.';
|
|
466
|
-
});
|
|
467
|
-
card.querySelector('[data-conflict-wipe]').addEventListener('click', async (e) => {
|
|
468
|
-
const btn = e.target;
|
|
469
|
-
btn.disabled = true; btn.textContent = 'Wiping…';
|
|
470
|
-
try {
|
|
471
|
-
const r = await rpc('wipeEmbeddingData', { confirm: true });
|
|
472
|
-
if (!r.ok) { btn.textContent = `Wipe failed: ${r.error}`; btn.disabled = false; return; }
|
|
473
|
-
card.remove();
|
|
474
|
-
// Re-migrate the now-empty schema to the new dim happens on next
|
|
475
|
-
// migration/restart; re-run the apply which will now find no conflict.
|
|
476
|
-
if (onResolved) await onResolved();
|
|
477
|
-
} catch (err) {
|
|
478
|
-
btn.textContent = `Wipe failed: ${err.message}`; btn.disabled = false;
|
|
479
|
-
}
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
$('#ob-emb-save')?.addEventListener('click', async () => {
|
|
484
|
-
if (!wizardState.embProvider) return;
|
|
485
|
-
const fields = {};
|
|
486
|
-
$$('#ob-emb-fields [data-emb-field]').forEach((i) => { if (i.value) fields[i.dataset.embField] = i.value; });
|
|
487
|
-
const ok = await applyEmbeddingProvider({
|
|
488
|
-
providerId: wizardState.embProvider,
|
|
489
|
-
fields,
|
|
490
|
-
out: $('#ob-emb-result'),
|
|
491
|
-
conflictHost: $('#ob-emb-fields')?.parentElement,
|
|
492
|
-
onSuccess: () => {
|
|
493
|
-
$('#ob-emb-next').disabled = false;
|
|
494
|
-
persistStep('EMBEDDING', 'DONE', { provider: wizardState.embProvider });
|
|
495
|
-
},
|
|
496
|
-
});
|
|
497
|
-
if (!ok) $('#ob-emb-next').disabled = true;
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
// ── Finish step ─────────────────────────────────────────────────────
|
|
501
|
-
async function renderFinish() {
|
|
502
|
-
try {
|
|
503
|
-
const [ping, state] = await Promise.all([rpc('ping'), rpc('onboardingState')]);
|
|
504
|
-
$('#ob-finish-daemon').textContent = `pid ${ping.pid} · up ${formatUptime(ping.uptimeMs)}`;
|
|
505
|
-
$('#ob-finish-db').textContent = state.steps.database.done
|
|
506
|
-
? `${state.steps.database.migrationsRan} migrations · pgvector ${state.steps.database.pgvector ? '✓' : '✗'}`
|
|
507
|
-
: 'not configured';
|
|
508
|
-
$('#ob-finish-llm').textContent = state.env.llmProvider || 'not configured';
|
|
509
|
-
$('#ob-finish-emb').textContent = state.env.embeddingProvider
|
|
510
|
-
? `${state.env.embeddingProvider} · ${state.env.embeddingModel} · ${state.env.embeddingDim}d`
|
|
511
|
-
: 'not configured';
|
|
512
|
-
} catch { /* ignore */ }
|
|
513
|
-
}
|
|
514
|
-
$('#ob-complete')?.addEventListener('click', async () => {
|
|
515
|
-
const installService = $('#ob-always-up')?.checked === true;
|
|
516
|
-
try {
|
|
517
|
-
const r = await rpc('markOnboardingComplete', { installService });
|
|
518
|
-
if (installService && r && r.serviceInstalled === false) {
|
|
519
|
-
toast({ variant: 'info', message: 'Could not install the always-up service on this platform.', hint: 'Sigil still auto-starts on first use; retry with `sigil service install`.' });
|
|
520
|
-
}
|
|
521
|
-
} catch { /* daemon restarts on complete — expected to drop */ }
|
|
522
|
-
$('#onboarding').hidden = true;
|
|
523
|
-
// Daemon is handing off (restart / service). Give it a moment, then refresh.
|
|
524
|
-
setTimeout(() => refreshHealth(), 1500);
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
// ── Navigation between wizard steps ──────────────────────────────────
|
|
528
|
-
document.addEventListener('click', (e) => {
|
|
529
|
-
const n = e.target.closest('[data-ob-next]');
|
|
530
|
-
if (n) {
|
|
531
|
-
e.preventDefault();
|
|
532
|
-
// Persist the step we're leaving (connectors is skippable — DONE if any
|
|
533
|
-
// tool connected, else SKIPPED). Provider/Embedding/Database persist on
|
|
534
|
-
// their own success handlers.
|
|
535
|
-
if (wizardState.step === 'connectors') {
|
|
536
|
-
persistStep('CONNECTORS', wizardState.connectedCount > 0 ? 'DONE' : 'SKIPPED', {});
|
|
537
|
-
}
|
|
538
|
-
setOnbStep(n.dataset.obNext);
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
const b = e.target.closest('[data-ob-back]');
|
|
542
|
-
if (b) { e.preventDefault(); setOnbStep(b.dataset.obBack); return; }
|
|
543
|
-
});
|
|
544
|
-
|
|
545
52
|
// ════════════════════════════════════════════════════════════════════
|
|
546
53
|
// DASHBOARD (unchanged behavior)
|
|
547
54
|
// ════════════════════════════════════════════════════════════════════
|
|
@@ -648,31 +155,37 @@ async function refreshMethods() {
|
|
|
648
155
|
}
|
|
649
156
|
|
|
650
157
|
async function refreshEnv() {
|
|
651
|
-
// Config summary
|
|
158
|
+
// Config summary from the config store (config.json), secrets masked.
|
|
652
159
|
try {
|
|
653
|
-
const
|
|
654
|
-
const
|
|
655
|
-
const dbDesc =
|
|
656
|
-
:
|
|
160
|
+
const c = await rpc('setup.config', {});
|
|
161
|
+
const db = c.database || {};
|
|
162
|
+
const dbDesc = db.mode === 'url' ? `connection URL (${db.urlHost || '—'})`
|
|
163
|
+
: db.mode === 'docker' ? `Docker container (localhost:${db.port})`
|
|
164
|
+
: db.mode === 'local' ? `local Postgres (${db.host}:${db.port})`
|
|
657
165
|
: 'not configured';
|
|
658
|
-
$('#cfg-db').textContent = `${dbDesc}${
|
|
659
|
-
$('#cfg-llm').textContent =
|
|
660
|
-
$('#cfg-emb').textContent =
|
|
661
|
-
? `${
|
|
166
|
+
$('#cfg-db').textContent = `${dbDesc}${c.setup?.steps?.database === 'done' ? ' · ready' : ''}`;
|
|
167
|
+
$('#cfg-llm').textContent = c.llm?.provider ? `${c.llm.provider}${c.llm.model ? ` · ${c.llm.model}` : ''}` : 'not configured';
|
|
168
|
+
$('#cfg-emb').textContent = c.embedding?.provider
|
|
169
|
+
? `${c.embedding.provider} · ${c.embedding.model} · ${c.embedding.dim}d`
|
|
662
170
|
: 'not configured';
|
|
663
|
-
} catch { /* summary best-effort */ }
|
|
664
|
-
|
|
665
|
-
try {
|
|
666
|
-
const data = await rpc('readEnv', {});
|
|
667
171
|
const tbody = $('#env-table tbody');
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
172
|
+
if (tbody) {
|
|
173
|
+
const rows = [
|
|
174
|
+
['Database', dbDesc],
|
|
175
|
+
['LLM provider', c.llm?.provider || '—'],
|
|
176
|
+
['LLM model', c.llm?.model || '—'],
|
|
177
|
+
['LLM key', c.llm?.hasKey ? 'configured' : '—'],
|
|
178
|
+
['Embedding provider', c.embedding?.provider || '—'],
|
|
179
|
+
['Embedding model', c.embedding?.model || '—'],
|
|
180
|
+
['Embedding dim', String(c.embedding?.dim || '—')],
|
|
181
|
+
['Embedding key', c.embedding?.hasKey ? 'configured' : '—'],
|
|
182
|
+
['Name', c.identity?.name || '—'],
|
|
183
|
+
];
|
|
184
|
+
tbody.innerHTML = rows.map(([k, v]) => `<tr><td class="mono">${escape(k)}</td><td>${escape(v)}</td></tr>`).join('');
|
|
185
|
+
}
|
|
674
186
|
} catch (err) {
|
|
675
|
-
$('#env-table tbody')
|
|
187
|
+
const tbody = $('#env-table tbody');
|
|
188
|
+
if (tbody) tbody.innerHTML = `<tr><td colspan="2" class="empty">${escape(err.message)}</td></tr>`;
|
|
676
189
|
}
|
|
677
190
|
}
|
|
678
191
|
|
|
@@ -717,13 +230,14 @@ async function onSettingsClientAction(id, action) {
|
|
|
717
230
|
}
|
|
718
231
|
|
|
719
232
|
// ── Settings: live provider switcher (LLM + embedding) ───────────────
|
|
720
|
-
//
|
|
721
|
-
//
|
|
722
|
-
//
|
|
723
|
-
const cfgSwitch = { kind: null, providerId: null, providers: [] };
|
|
233
|
+
// Drives the same setup service the first-run wizard uses (setup.detect +
|
|
234
|
+
// setup.run). "Apply" persists config + live-tests, then restarts the daemon
|
|
235
|
+
// so the new provider takes effect; the 5s health poll recovers from the gap.
|
|
236
|
+
const cfgSwitch = { kind: null, step: null, providerId: null, providers: [] };
|
|
724
237
|
|
|
725
238
|
async function openSwitcher(kind) {
|
|
726
239
|
cfgSwitch.kind = kind;
|
|
240
|
+
cfgSwitch.step = kind === 'llm' ? 'llm' : 'embedding';
|
|
727
241
|
cfgSwitch.providerId = null;
|
|
728
242
|
$('#cfg-switch-title').textContent = kind === 'llm' ? 'Change LLM provider' : 'Change embedding provider';
|
|
729
243
|
$('#cfg-switch-conflict').innerHTML = '';
|
|
@@ -731,11 +245,9 @@ async function openSwitcher(kind) {
|
|
|
731
245
|
const res = $('#cfg-switch-result'); res.style.display = 'none'; res.textContent = '';
|
|
732
246
|
$('#cfg-switch').style.display = '';
|
|
733
247
|
try {
|
|
734
|
-
const { providers } = await rpc(
|
|
735
|
-
cfgSwitch.providers = providers;
|
|
736
|
-
|
|
737
|
-
if (kind === 'embedding') wizardState.embProviders = providers;
|
|
738
|
-
$('#cfg-switch-cards').innerHTML = providers.map((p) => `
|
|
248
|
+
const { providers } = await rpc('setup.detect', { step: cfgSwitch.step });
|
|
249
|
+
cfgSwitch.providers = providers || [];
|
|
250
|
+
$('#cfg-switch-cards').innerHTML = cfgSwitch.providers.map((p) => `
|
|
739
251
|
<label class="provider-card" data-cfg-id="${escape(p.id)}">
|
|
740
252
|
<span class="check"></span>
|
|
741
253
|
<span class="name">${escape(p.label)}${p.recommended ? ' <span class="badge info" style="margin-left:8px;">RECOMMENDED</span>' : ''}</span>
|
|
@@ -746,16 +258,25 @@ async function openSwitcher(kind) {
|
|
|
746
258
|
}
|
|
747
259
|
}
|
|
748
260
|
|
|
261
|
+
// Fields to collect for the chosen provider (llm: from the catalog; embedding:
|
|
262
|
+
// synthesized — a key unless it can reuse the LLM key, + an Ollama host).
|
|
263
|
+
function cfgSwitchFields(p) {
|
|
264
|
+
if (cfgSwitch.step === 'llm') return p.fields || [];
|
|
265
|
+
const f = [];
|
|
266
|
+
if (p.keyed && !p.sharedKeyAvailable) f.push({ name: 'apiKey', label: `${p.label} API key`, type: 'password', placeholder: 'paste key' });
|
|
267
|
+
if (p.id === 'ollama') f.push({ name: 'host', label: 'Ollama host', type: 'text', placeholder: 'http://localhost:11434', optional: true });
|
|
268
|
+
return f;
|
|
269
|
+
}
|
|
270
|
+
|
|
749
271
|
function selectSwitchProvider(id) {
|
|
750
272
|
cfgSwitch.providerId = id;
|
|
751
273
|
$$('#cfg-switch-cards .provider-card').forEach((c) => c.classList.toggle('selected', c.dataset.cfgId === id));
|
|
752
274
|
const p = cfgSwitch.providers.find((x) => x.id === id);
|
|
753
275
|
if (!p) return;
|
|
754
|
-
const
|
|
755
|
-
$('#cfg-switch-fields').innerHTML =
|
|
756
|
-
?
|
|
757
|
-
<
|
|
758
|
-
<input type="${f.type}" data-cfg-field="${escape(f.name)}" placeholder="${escape(f.placeholder || '')}" autocomplete="off"></label>`).join('')
|
|
276
|
+
const fields = cfgSwitchFields(p);
|
|
277
|
+
$('#cfg-switch-fields').innerHTML = fields.length
|
|
278
|
+
? fields.map((f) => `<label class="field"><span class="label">${escape(f.label)}</span>
|
|
279
|
+
<input type="${escape(f.type)}" data-cfg-field="${escape(f.name)}" placeholder="${escape(f.placeholder || '')}" autocomplete="off"></label>`).join('')
|
|
759
280
|
: '<p class="muted text-sm">No additional configuration needed.</p>';
|
|
760
281
|
$('#cfg-switch-conflict').innerHTML = '';
|
|
761
282
|
}
|
|
@@ -770,35 +291,25 @@ $('#cfg-switch-cards')?.addEventListener('click', (e) => {
|
|
|
770
291
|
|
|
771
292
|
$('#cfg-switch-apply')?.addEventListener('click', async () => {
|
|
772
293
|
if (!cfgSwitch.providerId) return;
|
|
773
|
-
const
|
|
774
|
-
$$('#cfg-switch-fields [data-cfg-field]').forEach((i) => { if (i.value)
|
|
294
|
+
const input = { provider: cfgSwitch.providerId };
|
|
295
|
+
$$('#cfg-switch-fields [data-cfg-field]').forEach((i) => { if (i.value) input[i.dataset.cfgField] = i.value; });
|
|
775
296
|
const out = $('#cfg-switch-result');
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
out
|
|
783
|
-
|
|
784
|
-
onSuccess: () => restartAndClose(out),
|
|
785
|
-
});
|
|
786
|
-
if (!ok) return;
|
|
787
|
-
} else {
|
|
788
|
-
out.style.display = 'block'; out.className = 'result'; out.textContent = 'saving…';
|
|
789
|
-
try {
|
|
790
|
-
await rpc('configureLlm', { id: cfgSwitch.providerId, ...fields });
|
|
791
|
-
const test = await rpc('testLlm', {});
|
|
792
|
-
if (!test.ok) {
|
|
793
|
-
out.classList.add('err');
|
|
794
|
-
out.textContent = `✗ ${test.error || 'LLM test failed'}${test.fixHint ? '\n → ' + test.fixHint : ''}`;
|
|
795
|
-
return;
|
|
796
|
-
}
|
|
797
|
-
out.classList.add('ok'); out.textContent = `✓ LLM responded: "${test.response}"`;
|
|
798
|
-
restartAndClose(out);
|
|
799
|
-
} catch (err) {
|
|
800
|
-
out.classList.add('err'); out.textContent = `✗ ${err.message}`;
|
|
297
|
+
out.style.display = 'block'; out.className = 'result'; out.textContent = 'saving…';
|
|
298
|
+
try {
|
|
299
|
+
const res = await rpc('setup.run', { step: cfgSwitch.step, input });
|
|
300
|
+
if (!res.ok) {
|
|
301
|
+
out.classList.add('err');
|
|
302
|
+
const msg = res.error || (res.errors && Object.values(res.errors)[0]) || 'failed';
|
|
303
|
+
out.textContent = `✗ ${msg}${res.hint ? `\n → ${res.hint}` : ''}`;
|
|
304
|
+
return;
|
|
801
305
|
}
|
|
306
|
+
out.classList.add('ok');
|
|
307
|
+
out.textContent = cfgSwitch.step === 'llm'
|
|
308
|
+
? `✓ LLM responded: "${res.result?.response || 'ok'}"`
|
|
309
|
+
: `✓ embedder healthy — ${res.result?.dim}-dim`;
|
|
310
|
+
restartAndClose(out);
|
|
311
|
+
} catch (err) {
|
|
312
|
+
out.classList.add('err'); out.textContent = `✗ ${err.message}`;
|
|
802
313
|
}
|
|
803
314
|
});
|
|
804
315
|
|
|
@@ -1264,7 +775,23 @@ $('#dev-create')?.addEventListener('click', async () => {
|
|
|
1264
775
|
// ════════════════════════════════════════════════════════════════════
|
|
1265
776
|
// BOOT
|
|
1266
777
|
// ════════════════════════════════════════════════════════════════════
|
|
778
|
+
// Branded landing splash: stays up while we check ~/.sigil (via setup.state)
|
|
779
|
+
// and route to setup or the dashboard, then fades out. A minimum dwell keeps
|
|
780
|
+
// it from flashing on a fast check.
|
|
781
|
+
function dismissLanding() {
|
|
782
|
+
const el = $('#landing');
|
|
783
|
+
if (!el) return;
|
|
784
|
+
el.classList.add('fade-out');
|
|
785
|
+
setTimeout(() => { el.hidden = true; }, 550);
|
|
786
|
+
}
|
|
787
|
+
async function runLanding() {
|
|
788
|
+
const started = Date.now();
|
|
789
|
+
try { await initSetup(); } catch { /* initSetup handles its own errors */ }
|
|
790
|
+
const MIN_MS = 1100;
|
|
791
|
+
setTimeout(dismissLanding, Math.max(0, MIN_MS - (Date.now() - started)));
|
|
792
|
+
}
|
|
793
|
+
|
|
1267
794
|
const initial = (window.location.hash || '#health').slice(1);
|
|
1268
795
|
setRoute(validRoutes.includes(initial) ? initial : 'health');
|
|
1269
|
-
|
|
796
|
+
runLanding();
|
|
1270
797
|
setInterval(refreshHealth, 5000);
|