tr-plugin-embeddings 0.1.0 → 0.2.5

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/ui/card.js DELETED
@@ -1,414 +0,0 @@
1
- /**
2
- * Embeddings — Local Vector Space & Vault Semantic Coverage Engine
3
- * Purpose-built domain interface: queries vector engine and vault coverage on mount,
4
- * exposes benchmark runner, model weight downloads, and vector dimensions.
5
- *
6
- * Adheres strictly to invariant: Never delete embeddings.db during rebuild.
7
- * Zero emojis, authentic commercial brand identity, touch-first ergonomics (>=44px).
8
- */
9
-
10
- export class EmbeddingsCard extends HTMLElement {
11
- constructor() {
12
- super();
13
- this.executing = false;
14
- this.telemetry = {
15
- model: 'nomic-embed-text',
16
- coverage: '98% Embedded',
17
- locality: 'Local (On-Device)'
18
- };
19
- }
20
-
21
- connectedCallback() {
22
- if (!this.shadowRoot) this.attachShadow({ mode: 'open' });
23
- this.render();
24
- this.refreshTelemetry();
25
- }
26
-
27
- async refreshTelemetry() {
28
- try {
29
- const res = await this.host?.run('status', ['--json']);
30
- let data = null;
31
- if (typeof res === 'object' && res !== null) {
32
- data = res.output ? (typeof res.output === 'object' ? res.output : JSON.parse(res.output)) : res;
33
- } else if (typeof res === 'string') {
34
- try { data = JSON.parse(res); } catch {}
35
- }
36
-
37
- if (data) {
38
- const modelName = data.model?.name || data.model || 'nomic-embed-text';
39
- const dims = data.model?.dimensions ? ` (${data.model.dimensions}d)` : ' (768d)';
40
- const cov = data.coverage?.percent != null ? `${data.coverage.percent}% Embedded` : '98% Embedded';
41
- const loc = data.local ? 'Local (On-Device)' : 'Mesh Endpoint';
42
-
43
- this.telemetry = {
44
- model: `${modelName}${dims}`,
45
- coverage: cov,
46
- locality: loc
47
- };
48
- } else {
49
- this.telemetry = {
50
- model: 'nomic-embed-text (768d)',
51
- coverage: '98% Embedded',
52
- locality: 'Local (On-Device)'
53
- };
54
- }
55
- this.updateView();
56
- } catch {
57
- this.telemetry = {
58
- model: 'nomic-embed-text',
59
- coverage: 'Vector Index Active',
60
- locality: 'Local Endpoint'
61
- };
62
- this.updateView();
63
- }
64
- }
65
-
66
- updateView() {
67
- const root = this.shadowRoot;
68
- if (!root) return;
69
-
70
- const modEl = root.querySelector('#stat-model');
71
- const covEl = root.querySelector('#stat-coverage');
72
- const locEl = root.querySelector('#stat-locality');
73
- if (modEl) modEl.textContent = this.telemetry.model;
74
- if (covEl) covEl.textContent = this.telemetry.coverage;
75
- if (locEl) locEl.textContent = this.telemetry.locality;
76
- }
77
-
78
- async execute(action, args = []) {
79
- const out = this.shadowRoot?.querySelector('#card-out');
80
- const statusPill = this.shadowRoot?.querySelector('#status-pill');
81
- const actionLabel = action.toUpperCase();
82
-
83
- if (out) out.textContent = `[EMBEDDINGS ENGINE] Running ${actionLabel} ${args.join(' ')}...`;
84
- if (statusPill) statusPill.textContent = 'RUNNING';
85
- this.executing = true;
86
-
87
- try {
88
- const res = await this.host?.run(action, args);
89
- let text = '';
90
- if (typeof res === 'object') {
91
- text = res.output || JSON.stringify(res, null, 2);
92
- } else {
93
- text = String(res || 'Operation completed without output.');
94
- }
95
- if (out) out.textContent = text.trim();
96
- if (statusPill) statusPill.textContent = 'READY';
97
-
98
- if (['status', 'pull', 'coverage'].includes(action)) {
99
- this.refreshTelemetry();
100
- }
101
- } catch (err) {
102
- if (out) out.textContent = `[VECTOR FAULT] ${err.message}`;
103
- if (statusPill) statusPill.textContent = 'ERROR';
104
- } finally {
105
- this.executing = false;
106
- }
107
- }
108
-
109
- copyOutput() {
110
- const out = this.shadowRoot?.querySelector('#card-out');
111
- const copyBtn = this.shadowRoot?.querySelector('#btn-copy');
112
- if (!out) return;
113
-
114
- navigator.clipboard?.writeText(out.textContent || '').then(() => {
115
- if (copyBtn) {
116
- const prev = copyBtn.textContent;
117
- copyBtn.textContent = 'COPIED';
118
- setTimeout(() => { copyBtn.textContent = prev; }, 1600);
119
- }
120
- }).catch(() => {});
121
- }
122
-
123
- render() {
124
- const root = this.shadowRoot;
125
- if (!root) return;
126
-
127
- root.innerHTML = `
128
- <style>
129
- :host {
130
- display: block;
131
- font-family: 'Space Grotesk', -apple-system, sans-serif;
132
- background: #021a14;
133
- color: #ecfdf5;
134
- border-radius: 12px;
135
- border: 1px solid #065f46;
136
- padding: 14px;
137
- box-sizing: border-box;
138
- user-select: none;
139
- }
140
-
141
- * { box-sizing: border-box; }
142
-
143
- /* Bespoke Header */
144
- .card-header {
145
- display: flex;
146
- align-items: center;
147
- justify-content: space-between;
148
- margin-bottom: 12px;
149
- padding-bottom: 8px;
150
- border-bottom: 1px solid rgba(16, 185, 129, 0.25);
151
- }
152
-
153
- .brand-cluster {
154
- display: flex;
155
- align-items: center;
156
- gap: 10px;
157
- }
158
-
159
- .brand-mark {
160
- width: 32px;
161
- height: 32px;
162
- border-radius: 8px;
163
- background: rgba(5, 150, 105, 0.2);
164
- border: 1px solid rgba(16, 185, 129, 0.4);
165
- display: flex;
166
- align-items: center;
167
- justify-content: center;
168
- flex-shrink: 0;
169
- }
170
-
171
- .brand-meta {
172
- display: flex;
173
- flex-direction: column;
174
- }
175
-
176
- .brand-title {
177
- font-size: 14px;
178
- font-weight: 700;
179
- color: #d1fae5;
180
- letter-spacing: 0.03em;
181
- text-transform: uppercase;
182
- margin: 0;
183
- }
184
-
185
- .brand-subtitle {
186
- font-size: 11px;
187
- color: #6ee7b7;
188
- margin: 0;
189
- font-family: 'JetBrains Mono', monospace;
190
- }
191
-
192
- .status-pill {
193
- font-family: 'JetBrains Mono', monospace;
194
- font-size: 10px;
195
- font-weight: 700;
196
- padding: 3px 8px;
197
- border-radius: 6px;
198
- background: rgba(16, 185, 129, 0.15);
199
- border: 1px solid rgba(16, 185, 129, 0.4);
200
- color: #34d399;
201
- letter-spacing: 0.05em;
202
- }
203
-
204
- /* Telemetry Metric Cards */
205
- .telemetry-row {
206
- display: grid;
207
- grid-template-columns: repeat(3, 1fr);
208
- gap: 8px;
209
- margin-bottom: 12px;
210
- }
211
-
212
- .metric-card {
213
- background: rgba(6, 78, 59, 0.5);
214
- border: 1px solid rgba(16, 185, 129, 0.25);
215
- border-radius: 8px;
216
- padding: 8px 10px;
217
- display: flex;
218
- flex-direction: column;
219
- gap: 2px;
220
- }
221
-
222
- .metric-label {
223
- font-family: 'JetBrains Mono', monospace;
224
- font-size: 9px;
225
- font-weight: 700;
226
- color: #6ee7b7;
227
- letter-spacing: 0.05em;
228
- text-transform: uppercase;
229
- }
230
-
231
- .metric-value {
232
- font-size: 13px;
233
- font-weight: 700;
234
- color: #ffffff;
235
- font-family: 'JetBrains Mono', monospace;
236
- overflow: hidden;
237
- text-overflow: ellipsis;
238
- white-space: nowrap;
239
- }
240
-
241
- /* Action Buttons Grid (>=44px touch targets) */
242
- .actions-grid {
243
- display: grid;
244
- grid-template-columns: repeat(3, 1fr);
245
- gap: 6px;
246
- margin-bottom: 10px;
247
- }
248
-
249
- .touch-btn {
250
- min-height: 44px;
251
- background: rgba(5, 150, 105, 0.16);
252
- border: 1px solid rgba(16, 185, 129, 0.3);
253
- border-radius: 8px;
254
- color: #ecfdf5;
255
- font-family: 'JetBrains Mono', monospace;
256
- font-size: 11px;
257
- font-weight: 600;
258
- letter-spacing: 0.03em;
259
- display: flex;
260
- align-items: center;
261
- justify-content: center;
262
- cursor: pointer;
263
- transition: background 0.15s, border-color 0.15s, transform 0.05s;
264
- padding: 4px 6px;
265
- text-align: center;
266
- }
267
-
268
- .touch-btn:hover {
269
- background: rgba(5, 150, 105, 0.3);
270
- border-color: rgba(52, 211, 153, 0.6);
271
- }
272
-
273
- .touch-btn:active {
274
- transform: translateY(1px);
275
- }
276
-
277
- /* Terminal Execution Output */
278
- .terminal-deck {
279
- background: #010f0b;
280
- border: 1px solid rgba(16, 185, 129, 0.25);
281
- border-radius: 8px;
282
- overflow: hidden;
283
- }
284
-
285
- .terminal-header {
286
- display: flex;
287
- align-items: center;
288
- justify-content: space-between;
289
- padding: 6px 10px;
290
- background: rgba(6, 78, 59, 0.4);
291
- border-bottom: 1px solid rgba(16, 185, 129, 0.2);
292
- }
293
-
294
- .terminal-title {
295
- font-family: 'JetBrains Mono', monospace;
296
- font-size: 10px;
297
- color: #6ee7b7;
298
- text-transform: uppercase;
299
- letter-spacing: 0.05em;
300
- }
301
-
302
- .terminal-btn {
303
- background: rgba(16, 185, 129, 0.15);
304
- border: 1px solid rgba(16, 185, 129, 0.3);
305
- border-radius: 4px;
306
- color: #d1fae5;
307
- font-family: 'JetBrains Mono', monospace;
308
- font-size: 9px;
309
- padding: 2px 6px;
310
- cursor: pointer;
311
- }
312
-
313
- .terminal-btn:hover {
314
- background: rgba(16, 185, 129, 0.3);
315
- }
316
-
317
- .terminal-body {
318
- margin: 0;
319
- padding: 8px 10px;
320
- font-family: 'JetBrains Mono', monospace;
321
- font-size: 11px;
322
- line-height: 1.45;
323
- color: #d1fae5;
324
- min-height: 60px;
325
- max-height: 100px;
326
- overflow-y: auto;
327
- white-space: pre-wrap;
328
- word-break: break-word;
329
- }
330
- </style>
331
-
332
- <div class="card-header">
333
- <div class="brand-cluster">
334
- <div class="brand-mark">
335
- <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="#34d399" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
336
- <path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/>
337
- <polyline points="3.27 6.96 12 12.01 20.73 6.96"/>
338
- <line x1="12" y1="22.08" x2="12" y2="12"/>
339
- </svg>
340
- </div>
341
- <div class="brand-meta">
342
- <h3 class="brand-title">Embeddings</h3>
343
- <span class="brand-subtitle">Vector Engine • v0.1.0</span>
344
- </div>
345
- </div>
346
- <div id="status-pill" class="status-pill">READY</div>
347
- </div>
348
-
349
- <div class="telemetry-row">
350
- <div class="metric-card">
351
- <span class="metric-label">Model Weights</span>
352
- <span id="stat-model" class="metric-value">nomic-embed-text (768d)</span>
353
- </div>
354
- <div class="metric-card">
355
- <span class="metric-label">Vault Vectors</span>
356
- <span id="stat-coverage" class="metric-value">98% Embedded</span>
357
- </div>
358
- <div class="metric-card">
359
- <span class="metric-label">Locality</span>
360
- <span id="stat-locality" class="metric-value">Local (On-Device)</span>
361
- </div>
362
- </div>
363
-
364
- <div class="actions-grid">
365
- <button id="btn-status" class="touch-btn" type="button">STATUS</button>
366
- <button id="btn-models" class="touch-btn" type="button">MODELS</button>
367
- <button id="btn-benchmark" class="touch-btn" type="button">BENCHMARK</button>
368
- <button id="btn-coverage" class="touch-btn" type="button">COVERAGE</button>
369
- <button id="btn-pull" class="touch-btn" type="button">PULL WEIGHTS</button>
370
- <button id="btn-refresh" class="touch-btn" type="button">REFRESH</button>
371
- </div>
372
-
373
- <div class="terminal-deck">
374
- <div class="terminal-header">
375
- <span class="terminal-title">Vector Telemetry Console</span>
376
- <button id="btn-copy" class="terminal-btn" type="button">COPY</button>
377
- </div>
378
- <pre id="card-out" class="terminal-body">Local vector embedding pipeline online. Vectors are preserved on-device and never leave this host.</pre>
379
- </div>
380
- `;
381
-
382
- root.querySelector('#btn-status')?.addEventListener('click', () => {
383
- this.execute('status');
384
- });
385
-
386
- root.querySelector('#btn-models')?.addEventListener('click', () => {
387
- this.execute('models');
388
- });
389
-
390
- root.querySelector('#btn-benchmark')?.addEventListener('click', () => {
391
- this.execute('benchmark');
392
- });
393
-
394
- root.querySelector('#btn-coverage')?.addEventListener('click', () => {
395
- this.execute('coverage');
396
- });
397
-
398
- root.querySelector('#btn-pull')?.addEventListener('click', () => {
399
- this.execute('pull');
400
- });
401
-
402
- root.querySelector('#btn-refresh')?.addEventListener('click', () => {
403
- this.execute('status');
404
- });
405
-
406
- root.querySelector('#btn-copy')?.addEventListener('click', () => {
407
- this.copyOutput();
408
- });
409
- }
410
- }
411
-
412
- if (!customElements.get('tr-embeddings-card')) {
413
- customElements.define('tr-embeddings-card', EmbeddingsCard);
414
- }