formlab-mcp 0.6.98 → 0.6.99
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/calibration.js +2 -2
- package/package.json +1 -1
- package/server.json +2 -2
- package/vendor/equipment-calibration.js +64 -30
package/calibration.js
CHANGED
|
@@ -28,7 +28,7 @@ function ctx() {
|
|
|
28
28
|
return _ctx;
|
|
29
29
|
}
|
|
30
30
|
const _today = () => { const d = new Date(); return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; };
|
|
31
|
-
const _slim = (e) => JSON.stringify({ status: e.status || '', calIntervalMonths: e.calIntervalMonths || null, calibrations: Array.isArray(e.calibrations) ? e.calibrations : [] });
|
|
31
|
+
const _slim = (e) => JSON.stringify({ status: e.status || '', calIntervalMonths: e.calIntervalMonths || null, calibrations: Array.isArray(e.calibrations) ? e.calibrations : [], calReviews: Array.isArray(e.calReviews) ? e.calReviews : [] });
|
|
32
32
|
|
|
33
33
|
// { state, due, last, lastResult, interval, daysToDue, count } — state: ok | soon | overdue | failed | never | none
|
|
34
34
|
export function calibrationStatus(e, today) { return JSON.parse(ctx().__calStatus(_slim(e), today || _today())); }
|
|
@@ -45,7 +45,7 @@ export function readingDoubts(db, resolveIns, today) {
|
|
|
45
45
|
const now = Date.now();
|
|
46
46
|
if (_doubtMemo && _doubtMemo.db === db && now - _doubtMemo.at < 5000) return _doubtMemo.out;
|
|
47
47
|
const equipment = (db.equipment || []).filter(Boolean).map(e => ({ id: e.id, uid: e.uid || '', name: e.name || '', status: e.status || '',
|
|
48
|
-
_trashed: !!e._trashed, calIntervalMonths: e.calIntervalMonths || null, calibrations: Array.isArray(e.calibrations) ? e.calibrations : [] }));
|
|
48
|
+
_trashed: !!e._trashed, calIntervalMonths: e.calIntervalMonths || null, calibrations: Array.isArray(e.calibrations) ? e.calibrations : [], calReviews: Array.isArray(e.calReviews) ? e.calReviews : [] }));
|
|
49
49
|
const tests = (db.testResults || []).filter(t => t && t.id).map(t => ({ id: t.id, testDate: t.testDate || '',
|
|
50
50
|
measurements: (t.measurements || []).map(m => { const r = resolveIns(m, t, db) || {}; return { instrument: r.instrument || '', equipmentId: r.equipmentId || '', ...(m && m.instrumentOos ? { instrumentOos: m.instrumentOos } : {}) }; }) }));
|
|
51
51
|
let out = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formlab-mcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.99",
|
|
4
4
|
"mcpName": "io.github.juliu1980/formlab-mcp",
|
|
5
5
|
"description": "Read-only Model Context Protocol server for FormLab. Lets Claude and other MCP clients read and analyze your FormLab data, from a local export file or your live cloud workspace.",
|
|
6
6
|
"homepage": "https://formvix.com/mcp",
|
package/server.json
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.juliu1980/formlab-mcp",
|
|
4
4
|
"description": "Read-only MCP server for FormLab formulation data: a local export file or your live cloud workspace.",
|
|
5
|
-
"version": "0.6.
|
|
5
|
+
"version": "0.6.99",
|
|
6
6
|
"websiteUrl": "https://formvix.com/mcp",
|
|
7
7
|
"packages": [
|
|
8
8
|
{
|
|
9
9
|
"registryType": "npm",
|
|
10
10
|
"identifier": "formlab-mcp",
|
|
11
|
-
"version": "0.6.
|
|
11
|
+
"version": "0.6.99",
|
|
12
12
|
"runtimeHint": "npx",
|
|
13
13
|
"transport": {
|
|
14
14
|
"type": "stdio"
|
|
@@ -131,31 +131,54 @@ function eqCalSortKey(e) {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
// Readings to doubt after a calibration found the unit out of tolerance (dogfooding 28 Nov: RV-1 failed and nothing
|
|
134
|
-
// said which of its 8 reports came after its last pass).
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
//
|
|
140
|
-
function
|
|
134
|
+
// said which of its 8 reports came after its last pass). Every Fail or Adjusted (out of tolerance as found) entry opens
|
|
135
|
+
// a window: reports dated after the last good calibration before it, up to the failure's repair (the first good entry
|
|
136
|
+
// after it), or to today while it still fails; an Adjusted one ends at the adjustment. A window stays open until someone
|
|
137
|
+
// closes its review with a reason (e.calReviews, Jun 30 Nov: "Yes, do that"); later calibrations never close it (it
|
|
138
|
+
// used to close "two entries on", and two passes logged the same day cleared every doubt). Retested readings leave it
|
|
139
|
+
// on their own (the retest replaces them). `tests` = the reports that used this unit.
|
|
140
|
+
function eqCalReviews(e) { return (e && Array.isArray(e.calReviews)) ? e.calReviews.filter(r => r && r.calId) : []; }
|
|
141
|
+
// The review on a bad calibration entry, if one is closed (the latest word on it: closed, or reopened).
|
|
142
|
+
function eqCalReviewOf(e, calId) {
|
|
143
|
+
const rs = eqCalReviews(e).filter(r => r.calId === calId).sort((x, y) => String(x.at || '').localeCompare(String(y.at || '')));
|
|
144
|
+
const last = rs[rs.length - 1];
|
|
145
|
+
return last && !last.reopened ? last : null;
|
|
146
|
+
}
|
|
147
|
+
// Every window, newest first: { calId, kind, at, since, until, fixedAt, review }.
|
|
148
|
+
function eqCalWindows(e, todayIso) {
|
|
141
149
|
const hist = eqCalHistory(e);
|
|
142
150
|
const res = (c) => String((c && c.result) || '').trim().toLowerCase();
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
const good = (c) => ['pass', 'adjusted'].includes(res(c));
|
|
152
|
+
const out = [];
|
|
153
|
+
hist.forEach((bad, i) => {
|
|
154
|
+
const kind = res(bad);
|
|
155
|
+
if (kind !== 'fail' && kind !== 'adjusted') return;
|
|
156
|
+
const before = hist.slice(i + 1).find(good);
|
|
157
|
+
let fixed = null; for (let j = i - 1; j >= 0; j--) { if (good(hist[j])) { fixed = hist[j]; break; } }
|
|
158
|
+
const until = kind === 'adjusted' ? (bad.date || '') : ((fixed && fixed.date) || todayIso || _eqCalToday());
|
|
159
|
+
out.push({ calId: bad.id || '', kind, at: bad.date || '', since: (before && before.date) || '', until, fixedAt: kind === 'fail' && fixed ? (fixed.date || '') : '', review: bad.id ? eqCalReviewOf(e, bad.id) : null });
|
|
160
|
+
});
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
function _eqCalWindowTests(w, tests) {
|
|
149
164
|
const day = (t) => String((t && t.testDate) || '').split('T')[0];
|
|
150
|
-
|
|
165
|
+
return (tests || []).filter(t => { const d = day(t); return d && (!w.since || d > w.since) && (!w.until || d <= w.until); })
|
|
151
166
|
.sort((a, b) => day(a).localeCompare(day(b)));
|
|
167
|
+
}
|
|
168
|
+
// The latest window still open (its review not closed), with its reports and batches; null when none is open.
|
|
169
|
+
// { calId, kind, at, since, until, fixedAt, tests, batches, open (how many windows are open) }
|
|
170
|
+
function eqCalSuspect(e, tests, todayIso) {
|
|
171
|
+
const open = eqCalWindows(e, todayIso).filter(w => !w.review);
|
|
172
|
+
if (!open.length) return null;
|
|
173
|
+
const w = open[0];
|
|
174
|
+
const hit = _eqCalWindowTests(w, tests);
|
|
152
175
|
const batches = [];
|
|
153
176
|
hit.forEach(t => {
|
|
154
177
|
const sm = (typeof db !== 'undefined' && db.samples || []).find(x => x && x.id === t.sampleId);
|
|
155
178
|
const b = sm && sm.batchId ? (db.batches || []).find(x => x && x.id === sm.batchId && !x._trashed) : null;
|
|
156
179
|
if (b && !batches.includes(b)) batches.push(b);
|
|
157
180
|
});
|
|
158
|
-
return { kind:
|
|
181
|
+
return { calId: w.calId, kind: w.kind, at: w.at, since: w.since, until: w.until, fixedAt: w.fixedAt, tests: hit, batches, open: open.length };
|
|
159
182
|
}
|
|
160
183
|
|
|
161
184
|
// ---- Readings in doubt (Jun, 30 Nov: "Flag doubtful readings"; shared with the MCP server) ----
|
|
@@ -165,24 +188,26 @@ function eqCalSuspect(e, tests, todayIso) {
|
|
|
165
188
|
// eqCalDoubtIndex: Map testId → [{ eqId, lname, why }]; eqCalReadingDoubt: { why } or null.
|
|
166
189
|
function eqCalDoubtIndex(equipment, tests, insOf, todayIso) {
|
|
167
190
|
const map = new Map();
|
|
168
|
-
const res = (c) => String((c && c.result) || '').trim().toLowerCase();
|
|
169
191
|
(equipment || []).forEach(e => {
|
|
170
192
|
if (!e || e._trashed) return;
|
|
171
|
-
|
|
193
|
+
const open = eqCalWindows(e, todayIso).filter(w => !w.review);
|
|
194
|
+
if (!open.length) return; // nothing to doubt
|
|
172
195
|
const lname = String(e.name || '').trim().toLowerCase();
|
|
173
196
|
const match = (m, t) => { const r = (insOf && insOf(m, t)) || {}; return r.equipmentId ? r.equipmentId === e.id : (!!lname && String(r.name || '').trim().toLowerCase() === lname); };
|
|
174
197
|
const used = (tests || []).filter(t => t && (t.measurements || []).some(m => match(m, t)));
|
|
175
|
-
const sus = eqCalSuspect(e, used, todayIso);
|
|
176
|
-
if (!sus || !sus.tests.length) return;
|
|
177
198
|
const name = e.name || e.uid || 'its instrument';
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
199
|
+
open.forEach(w => {
|
|
200
|
+
const hit = _eqCalWindowTests(w, used);
|
|
201
|
+
if (!hit.length) return;
|
|
202
|
+
const from = w.since ? `after its last good calibration (${w.since})` : 'before any good calibration on record';
|
|
203
|
+
const why = w.kind === 'adjusted' ? `Taken on ${name} ${from}; it was found out of tolerance on ${w.at}.`
|
|
204
|
+
: w.fixedAt ? `Taken on ${name} ${from} and before the repair passed on ${w.fixedAt}; it failed calibration on ${w.at}.`
|
|
205
|
+
: `Taken on ${name} ${from}; it failed calibration on ${w.at} and has not passed since.`;
|
|
206
|
+
// short: the same in a few words, for compact uses (the AI context).
|
|
207
|
+
const short = `${name} ${w.kind === 'adjusted' ? 'out of tolerance' : 'failed calibration'} ${w.at}`;
|
|
208
|
+
const d = { eqId: e.id, lname, why, short };
|
|
209
|
+
hit.forEach(t => { const l = map.get(t.id) || []; if (!l.some(x => x.eqId === d.eqId)) { l.push(d); map.set(t.id, l); } });
|
|
210
|
+
});
|
|
186
211
|
});
|
|
187
212
|
return map;
|
|
188
213
|
}
|
|
@@ -244,8 +269,14 @@ function eqCalCardHtml(e) {
|
|
|
244
269
|
// How many already are, once some are (dogfooding 30 Nov: after the hold the link just went away).
|
|
245
270
|
const onHold = sus.batches.filter(b => b.fgHold && b.fgHold.at && !b.fgHold.releasedAt).length;
|
|
246
271
|
const heldTxt = onHold ? ` · <span style="white-space:nowrap">${onHold} on hold</span>` : '';
|
|
247
|
-
return (open && typeof flEqHoldSuspectUI === 'function' ? ` · <a style="cursor:pointer;font-weight:600;color:inherit;text-decoration:underline;white-space:nowrap" onclick="flEqHoldSuspectUI('${_eqCalJs(e.id)}')">Put ${open} batch${open === 1 ? '' : 'es'} on hold</a>` : '') + heldTxt; })()}
|
|
272
|
+
return (open && typeof flEqHoldSuspectUI === 'function' ? ` · <a style="cursor:pointer;font-weight:600;color:inherit;text-decoration:underline;white-space:nowrap" onclick="flEqHoldSuspectUI('${_eqCalJs(e.id)}')">Put ${open} batch${open === 1 ? '' : 'es'} on hold</a>` : '') + heldTxt; })()}${
|
|
273
|
+
// Closing the review is a decision with a reason (Jun, 30 Nov): later calibrations no longer close it.
|
|
274
|
+
typeof flEqCloseReviewUI === 'function' && sus.calId ? ` · <a style="cursor:pointer;font-weight:600;color:inherit;text-decoration:underline;white-space:nowrap" onclick="flEqCloseReviewUI('${_eqCalJs(e.id)}','${_eqCalJs(sus.calId)}')">Close the review</a>` : ''}${
|
|
275
|
+
sus.open > 1 ? `<div style="margin-top:4px">${sus.open - 1} earlier ${sus.open - 1 === 1 ? 'failure is' : 'failures are'} still open too.</div>` : ''}</div>`;
|
|
248
276
|
})() : '';
|
|
277
|
+
// The latest closed review, when nothing is open: who closed it, why, and the way back.
|
|
278
|
+
const lastClosed = !sus ? eqCalWindows(e).find(w => w.review) : null;
|
|
279
|
+
const closedHtml = lastClosed ? `<div class="eq-cal-reviewed" style="margin-top:10px;font-size:12.5px;color:var(--text-muted)">Review of the ${esc(lastClosed.at)} ${lastClosed.kind === 'adjusted' ? 'out-of-tolerance finding' : 'failure'} closed${lastClosed.review.by ? ' by ' + esc(lastClosed.review.by) : ''}${lastClosed.review.at && typeof flLocalDay === 'function' ? ' on ' + esc(flLocalDay(lastClosed.review.at)) : ''}: ${esc(lastClosed.review.reason || '')}${typeof flEqReopenReviewUI === 'function' ? ` · <a style="cursor:pointer;color:var(--primary);white-space:nowrap" onclick="flEqReopenReviewUI('${_eqCalJs(e.id)}','${_eqCalJs(lastClosed.calId)}')">Reopen</a>` : ''}</div>` : '';
|
|
249
280
|
// Dates never wrap ("2026-11-/30" in a narrow window, 30 Nov Definition tab check).
|
|
250
281
|
const rows = hist.map(c => `<tr>
|
|
251
282
|
<td style="font-variant-numeric:tabular-nums;white-space:nowrap">${esc(c.date || '—')}</td>
|
|
@@ -262,7 +293,7 @@ function eqCalCardHtml(e) {
|
|
|
262
293
|
const freeNote = on ? '' : `<div style="margin-top:10px;font-size:12px;color:var(--text-muted)">Read-only on Free: your calibration records are kept. Logging and due-date alerts are Pro.</div>`;
|
|
263
294
|
return `<div class="card" id="eq-cal-card" style="margin-top:16px">
|
|
264
295
|
<div class="card-header" style="display:flex;justify-content:space-between;align-items:center;gap:10px;flex-wrap:wrap"><h2>Calibration</h2>${editBtns}</div>
|
|
265
|
-
<div class="card-body">${summary}${susHtml}${table}${freeNote}</div></div>`;
|
|
296
|
+
<div class="card-body">${summary}${susHtml}${closedHtml}${table}${freeNote}</div></div>`;
|
|
266
297
|
}
|
|
267
298
|
|
|
268
299
|
// ---- Interval ----
|
|
@@ -358,7 +389,10 @@ function openEqCalLogModal(eqId, calId) {
|
|
|
358
389
|
// calibrator may set In service / Out of service (0186); Retired is left alone.
|
|
359
390
|
const outNow = !c && rec.result === 'fail' && (cur.status || 'In service') === 'In service';
|
|
360
391
|
if (outNow) patch.status = 'Out of service';
|
|
361
|
-
|
|
392
|
+
// The trail says why the status moved (30 Nov: an auditor saw "In service → Out of service" with no reason).
|
|
393
|
+
const _why = outNow ? `In service → Out of service: failed calibration on ${rec.date}` : '';
|
|
394
|
+
if (_why) { try { if (window.__pro && typeof window.__pro.setReason === 'function') window.__pro.setReason('equipment', eqId, _why); } catch (_) {} }
|
|
395
|
+
updateEquipment(eqId, patch, _why ? { auditNote: _why } : undefined);
|
|
362
396
|
if (typeof renderEquipmentDetail === 'function' && typeof currentView !== 'undefined' && currentView === 'equipment-detail') renderEquipmentDetail(eqId);
|
|
363
397
|
toast(c ? 'Calibration updated.' : (rec.result === 'fail' ? (outNow ? 'Calibration logged as failed. The instrument is now Out of service until it passes.' : 'Calibration logged as failed. Keep the instrument out of use until it passes.')
|
|
364
398
|
: (cur.status === 'Out of service' ? 'Calibration logged. The instrument is still Out of service.' : 'Calibration logged.')));
|