formlab-mcp 0.6.59 → 0.6.61

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/README.md CHANGED
@@ -68,6 +68,8 @@ Ask Claude (or another MCP client) things like:
68
68
  | `list_projects` | Filtered list of projects (the buckets formulations are filed under) + per-project formulation count. Filters: `status`, `name_contains` |
69
69
  | `get_project` | Full project record + the formulations filed under it |
70
70
  | `list_notebook_entries` | ELN feed — dated authored notes attached to records. Append-only: a withdrawn note is kept with `retracted` = {at, by, reason}. Filters: `entity_type`, `entity_id`, `author`, `text_contains`, `since`, `until`, `retracted` |
71
+ | `list_discussions` | Discussions beside records and work requests (live workspace): threads with their comments, resolved or not; append-only, a retracted comment keeps `retracted` = {at, reason}; `tab` = the record tab it was written on. Filters: `entity_type`, `entity_id`, `author`, `text_contains`, `since`, `open_only`, `flat` |
72
+ | `list_requests` | Work requests REQ-0001 … (Team, live workspace): title, kind, status (blocked with a reason), assignee, asked by, due, late, the linked record. Filters: `status` (or `active`), `assignee`, `kind`, `entity_type`, `entity_id`, `late_only` |
71
73
  | `get_notebook_entry` | One notebook entry — full body, author, attachment metadata, resolved linked record, and `retracted` when withdrawn |
72
74
 
73
75
  ## Install
@@ -124,9 +126,9 @@ The config sets a single env var, which switches the server into cloud mode:
124
126
  | `FORMLAB_MCP_TOKEN` | a dedicated, **read-only**, revocable token (`flmcp_…`) |
125
127
  | `FORMLAB_SUPABASE_URL` | (optional) override the backend URL — defaults to production |
126
128
  | `FORMLAB_SUPABASE_ANON_KEY` | (optional) override the publishable key — defaults to production |
127
- | `FORMLAB_REFRESH_SECONDS` | (optional) poll interval, default `60` |
129
+ | `FORMLAB_REFRESH_SECONDS` | (optional) how old the copy may be when a tool is called before it's fetched again, default `300` (5 minutes). Nothing is fetched while no tool is called |
128
130
 
129
- When `FORMLAB_MCP_TOKEN` is present, the server POSTs it to FormLab's `mcp-data` Edge Function, which returns your workspace scoped to you by row-level security and re-fetches every `FORMLAB_REFRESH_SECONDS`. It's **read-only** — enforced at the database (a dedicated `mcp_readonly` Postgres role with `SELECT`-only grants), not by trust.
131
+ When `FORMLAB_MCP_TOKEN` is present, the server POSTs it to FormLab's `mcp-data` Edge Function, which returns your workspace scoped to you by row-level security. It's fetched once at start, then again only when a tool is called and the copy is older than `FORMLAB_REFRESH_SECONDS` (5 minutes by default); an idle server sends nothing. It's **read-only** — enforced at the database (a dedicated `mcp_readonly` Postgres role with `SELECT`-only grants), not by trust.
130
132
 
131
133
  > **Security.** The token grants **read-only** access to one workspace and holds **no account session** — only a SHA-256 hash is stored server-side, and it never rotates. Treat the config like a password (don't share or commit it). **Revoke or re-mint any time** from *Settings → Account → AI tools (MCP) → Connect*.
132
134
 
@@ -189,7 +191,7 @@ claude mcp add formlab npx formlab-mcp
189
191
 
190
192
  **Cloud mode** (`FORMLAB_MCP_TOKEN` set):
191
193
 
192
- - The server sends your token to FormLab's `mcp-data` Edge Function and receives your workspace in return, re-read every 60 seconds (`FORMLAB_REFRESH_SECONDS`).
194
+ - The server sends your token to FormLab's `mcp-data` Edge Function and receives your workspace in return, re-read when a tool is called and the copy is more than 5 minutes old (`FORMLAB_REFRESH_SECONDS`); nothing while idle.
193
195
  - The function reads through a dedicated `mcp_readonly` Postgres role with `SELECT`-only grants, and row-level security limits it to the workspace the token was made for.
194
196
  - FormLab stores only a SHA-256 hash of the token. It holds no account session and you can revoke it at any time.
195
197
 
package/cloud.js CHANGED
@@ -56,32 +56,41 @@ async function _fetchDb({ url, anonKey, token }) {
56
56
  return body;
57
57
  }
58
58
 
59
- // Bootstrap: one load up front, then refresh on an interval. Returns
60
- // { workspaceId, refresh, stop } to mirror the old v1 signature.
61
- export async function startCloud({ url, anonKey, token, refreshSeconds = 60, onReload } = {}) {
59
+ // Bootstrap: one load up front (it also checks the token), then fetched AGAIN ONLY WHEN A TOOL IS CALLED and the
60
+ // copy is older than `maxAgeSeconds` (FORMLAB_REFRESH_SECONDS, default 300). Until 0.6.60 this re-fetched the
61
+ // whole workspace on a 60 s timer for as long as the server ran, asked or not: two idle copies in Claude Desktop
62
+ // pulled ~6 GB a day from production and took the Supabase project over its egress quota (19 Oct 2026). Idle
63
+ // now costs nothing. Concurrent tool calls share one fetch; a failed refresh keeps the last copy and says so.
64
+ // Returns { workspaceId, refresh, ensureFresh, stop }.
65
+ export async function startCloud({ url, anonKey, token, refreshSeconds = 300, onReload, now = () => Date.now() } = {}) {
62
66
  url = url || DEFAULT_SUPABASE_URL;
63
67
  anonKey = anonKey || DEFAULT_ANON_KEY;
64
68
  if (!token) {
65
69
  throw new Error('Cloud mode needs FORMLAB_MCP_TOKEN (mint it from FormLab → Connect to MCP).');
66
70
  }
67
71
 
68
- let workspaceId = null;
72
+ let workspaceId = null, loadedAt = 0, inflight = null;
69
73
  const refresh = async () => {
70
74
  const body = await _fetchDb({ url, anonKey, token });
71
75
  workspaceId = body.workspaceId || workspaceId;
76
+ loadedAt = now();
72
77
  setStoreFromDb(body.db, { source: 'cloud', workspaceId, schemaName: 'formlab-live', loadedAt: body.loadedAt || new Date().toISOString() });
73
78
  if (onReload) { try { onReload(body.db); } catch (_) {} }
74
79
  return body.db;
75
80
  };
81
+ // Before a tool answers: fresh enough → nothing; else one fetch, shared by every call waiting on it.
82
+ const maxAgeMs = Math.max(0, Number(refreshSeconds) || 0) * 1000;
83
+ const ensureFresh = async () => {
84
+ if (now() - loadedAt < maxAgeMs) return false;
85
+ if (!inflight) {
86
+ inflight = refresh().then(() => true, (e) => {
87
+ process.stderr.write(`[formlab-mcp] cloud refresh failed, answering from the copy loaded ${Math.round((now() - loadedAt) / 1000)} s ago: ${e.message}\n`);
88
+ return false;
89
+ }).finally(() => { inflight = null; });
90
+ }
91
+ return inflight;
92
+ };
76
93
 
77
- await refresh(); // initial synchronous load before tools accept calls
78
-
79
- let timer = null;
80
- if (refreshSeconds > 0) {
81
- timer = setInterval(() => {
82
- refresh().catch(e => process.stderr.write(`[formlab-mcp] cloud refresh failed: ${e.message}\n`));
83
- }, refreshSeconds * 1000);
84
- if (timer.unref) timer.unref();
85
- }
86
- return { workspaceId, refresh, stop: () => { if (timer) clearInterval(timer); } };
94
+ await refresh(); // initial load before tools accept calls (and an early, clear error for a bad token)
95
+ return { workspaceId, refresh, ensureFresh, stop: () => {} };
87
96
  }
package/index.js CHANGED
@@ -37,6 +37,7 @@ import * as designspace from './tools/designspace.js';
37
37
  import * as library from './tools/library.js';
38
38
  import * as projects from './tools/projects.js';
39
39
  import * as notebook from './tools/notebook.js';
40
+ import * as discussions from './tools/discussions.js';
40
41
  import * as batchAnalyze from './tools/batch-analyze.js';
41
42
  import * as suppliers from './tools/suppliers.js';
42
43
  import * as documents from './tools/documents.js';
@@ -47,20 +48,24 @@ import * as documents from './tools/documents.js';
47
48
  // FORMLAB_SUPABASE_URL / _ANON_KEY are optional overrides — cloud.js defaults to
48
49
  // the public production values, so the config only NEEDS FORMLAB_MCP_TOKEN.
49
50
  const CLOUD = !!process.env.FORMLAB_MCP_TOKEN;
51
+ // How old the cloud copy may be when a tool is called before it's fetched again (seconds). Nothing is fetched
52
+ // while no tool is called (0.6.60: no background polling).
53
+ const MAX_AGE_SECONDS = Number(process.env.FORMLAB_REFRESH_SECONDS || 300);
54
+ let cloud = null;
50
55
 
51
56
  if (CLOUD) {
52
57
  try {
53
- const h = await startCloud({
58
+ const h = cloud = await startCloud({
54
59
  url: process.env.FORMLAB_SUPABASE_URL || undefined,
55
60
  anonKey: process.env.FORMLAB_SUPABASE_ANON_KEY || undefined,
56
61
  token: process.env.FORMLAB_MCP_TOKEN,
57
- refreshSeconds: Number(process.env.FORMLAB_REFRESH_SECONDS || 60),
62
+ refreshSeconds: MAX_AGE_SECONDS,
58
63
  });
59
64
  const s = getStore();
60
65
  process.stderr.write(
61
66
  `[formlab-mcp] LIVE cloud mode · workspace ${h.workspaceId} · ` +
62
67
  `${(s.db.ingredients||[]).length} ingredients · ${(s.db.formulations||[]).length} formulas · ` +
63
- `refresh every ${Number(process.env.FORMLAB_REFRESH_SECONDS || 60)}s\n`);
68
+ `fetched again on use when older than ${MAX_AGE_SECONDS}s (no background polling)\n`);
64
69
  } catch (e) {
65
70
  process.stderr.write(`[formlab-mcp] cloud mode failed: ${e.message}\n`);
66
71
  process.exit(1);
@@ -119,6 +124,7 @@ const TOOLS = [
119
124
  ...Object.values(library.tools),
120
125
  ...Object.values(projects.tools),
121
126
  ...Object.values(notebook.tools),
127
+ ...Object.values(discussions.tools),
122
128
  ...Object.values(suppliers.tools),
123
129
  ...Object.values(documents.tools),
124
130
  ...Object.values(batchAnalyze.tools),
@@ -157,6 +163,7 @@ server.setRequestHandler(CallToolRequestSchema, async (req) => {
157
163
  };
158
164
  }
159
165
  try {
166
+ if (cloud) await cloud.ensureFresh(); // cloud mode: refetch only if the copy is older than FORMLAB_REFRESH_SECONDS
160
167
  const result = await tool.handler(args || {});
161
168
  // All tool handlers return either a plain object/array (auto-
162
169
  // serialized as JSON text) or a pre-formatted string. The MCP
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "formlab-mcp",
3
- "version": "0.6.59",
3
+ "version": "0.6.61",
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",
7
7
  "type": "module",
8
8
  "bin": {
9
- "formlab-mcp": "./index.js"
9
+ "formlab-mcp": "index.js"
10
10
  },
11
11
  "main": "index.js",
12
12
  "files": [
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.59",
5
+ "version": "0.6.61",
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.59",
11
+ "version": "0.6.61",
12
12
  "runtimeHint": "npx",
13
13
  "transport": {
14
14
  "type": "stdio"
@@ -0,0 +1,138 @@
1
+ // ============================================================
2
+ // DISCUSSION + REQUEST TOOLS (FormLab Team / Pro shared workspaces, migrations 0201-0203).
3
+ // - list_discussions: comments beside records (and on work requests), grouped by thread or flat
4
+ // - list_requests: work requests (REQ-0001 …): what was asked of whom, by when, and where it stands
5
+ // A discussion is part of the record's history, not a chat: comments are append-only (a retracted one is kept with
6
+ // retracted = {at, reason} — never cite it as a finding). Only in a live workspace (cloud mode); an export file has
7
+ // none. Read-only; the server applies project walls and the owner's switch for restricted projects.
8
+ // ============================================================
9
+
10
+ import { getStore } from '../data.js';
11
+
12
+ const _norm = (s) => String(s == null ? '' : s).toLowerCase();
13
+ const _clampLimit = (n) => Math.min(1000, Math.max(1, n || 100));
14
+
15
+ const _COLL = {
16
+ formulation: 'formulations', batch: 'batches', sample: 'samples', testResult: 'testResults', project: 'projects',
17
+ ingredient: 'ingredients', equipment: 'equipment', parameter: 'parameters', template: 'templates', lot: 'lots', doeDesign: 'doeDesigns',
18
+ };
19
+
20
+ function _record(type, id, db) {
21
+ if (type === 'request') {
22
+ const r = (db.requests || []).find(x => x && x.id === id);
23
+ return r ? { uid: r.uid, name: r.title } : null;
24
+ }
25
+ const rec = (db[_COLL[type]] || []).find(x => x && (x.id === id || x.uid === id));
26
+ return rec ? { uid: rec.uid || null, name: rec.name || rec.reportName || rec.title || '' } : null;
27
+ }
28
+
29
+ // A UID or id the caller passed, down to the id the comments carry.
30
+ function _resolveId(type, id, db) {
31
+ if (!id) return null;
32
+ if (type === 'request') { const r = (db.requests || []).find(x => x && (x.id === id || x.uid === id)); return r ? r.id : id; }
33
+ const rec = (db[_COLL[type]] || []).find(x => x && (x.id === id || x.uid === id));
34
+ return rec ? rec.id : id;
35
+ }
36
+
37
+ function _notLive(db) {
38
+ return !Array.isArray(db.discussions) && !Array.isArray(db.requests)
39
+ ? { error: 'Discussions and requests are read from a live FormLab workspace (cloud mode). This data source has none.' } : null;
40
+ }
41
+
42
+ const list_discussions = {
43
+ definition: {
44
+ name: 'list_discussions',
45
+ description: 'List discussion comments that sit beside records (formulas, batches, samples, test reports, projects, ingredients, equipment) or work requests — optionally filtered by the record (entity_type + entity_id, UID accepted), author, text, date, or only unresolved threads. Grouped by thread by default (each thread: the record, resolved or not, its comments oldest first); flat=true returns comments newest first. Comments are append-only: a retracted one keeps retracted = {at, reason} — treat it as withdrawn, not as a finding. "tab" says which tab of the record the comment was written on.',
46
+ inputSchema: {
47
+ type: 'object',
48
+ properties: {
49
+ entity_type: { type: 'string', description: 'formulation, batch, sample, testResult, project, ingredient, equipment, or request.' },
50
+ entity_id: { type: 'string', description: 'The record (internal id or UID, e.g. FORM-0012, REQ-0003).' },
51
+ author: { type: 'string', description: 'Case-insensitive substring of the author\'s name.' },
52
+ text_contains: { type: 'string', description: 'Case-insensitive substring of the comment text.' },
53
+ since: { type: 'string', description: 'ISO date/time: only comments at or after it.' },
54
+ open_only: { type: 'boolean', description: 'true = only threads not resolved.' },
55
+ flat: { type: 'boolean', description: 'true = a flat list of comments, newest first, instead of threads.' },
56
+ limit: { type: 'number', description: 'Max threads (or comments when flat), default 100, max 1000.' },
57
+ },
58
+ },
59
+ },
60
+ handler: async (args) => {
61
+ const { db } = getStore();
62
+ const none = _notLive(db); if (none) return none;
63
+ const limit = _clampLimit(args.limit);
64
+ const wantId = _resolveId(args.entity_type, args.entity_id, db);
65
+ const sinceMs = args.since ? Date.parse(args.since) : null;
66
+ const all = (db.discussions || []).filter(c => c && (!args.entity_type || c.entityType === args.entity_type) && (!wantId || c.entityId === wantId));
67
+ const threads = new Map();
68
+ all.forEach(c => { const k = `${c.entityType}:${c.entityId}`; if (!threads.has(k)) threads.set(k, []); threads.get(k).push(c); });
69
+ const resolvedOf = (list) => { const last = list.filter(c => c.kind !== 'comment').pop(); return !!(last && last.kind === 'resolve'); };
70
+ const keep = (c) => c.kind === 'comment'
71
+ && (!args.author || _norm(c.author).includes(_norm(args.author)))
72
+ && (!args.text_contains || _norm(c.body).includes(_norm(args.text_contains)))
73
+ && (sinceMs == null || Date.parse(c.at) >= sinceMs);
74
+ const row = (c) => ({ id: c.id, author: c.author, at: c.at, body: c.body, tab: c.tab || null, replyTo: c.replyTo || null,
75
+ retracted: c.retracted || null });
76
+ if (args.flat) {
77
+ const flat = [...threads.values()].filter(l => !args.open_only || !resolvedOf(l)).flat().filter(keep)
78
+ .sort((a, b) => Date.parse(b.at) - Date.parse(a.at));
79
+ return { totalMatching: flat.length, returned: Math.min(flat.length, limit),
80
+ comments: flat.slice(0, limit).map(c => { const rec = _record(c.entityType, c.entityId, db);
81
+ return { ...row(c), entityType: c.entityType, entityId: c.entityId, entityUid: rec ? rec.uid : null, entityName: rec ? rec.name : '' }; }) };
82
+ }
83
+ const out = [...threads.values()].map(list => {
84
+ const comments = list.filter(keep);
85
+ if (!comments.length) return null;
86
+ const c0 = list[0], rec = _record(c0.entityType, c0.entityId, db), resolved = resolvedOf(list);
87
+ if (args.open_only && resolved) return null;
88
+ return { entityType: c0.entityType, entityId: c0.entityId, entityUid: rec ? rec.uid : null, entityName: rec ? rec.name : '',
89
+ resolved, lastAt: list[list.length - 1].at, comments: comments.map(row) };
90
+ }).filter(Boolean).sort((a, b) => Date.parse(b.lastAt) - Date.parse(a.lastAt));
91
+ return { totalMatching: out.length, returned: Math.min(out.length, limit), threads: out.slice(0, limit) };
92
+ },
93
+ };
94
+
95
+ const list_requests = {
96
+ definition: {
97
+ name: 'list_requests',
98
+ description: 'List work requests (REQ-0001 …) in a FormLab Team workspace: what was asked of whom, by when, on which record, and where it stands (open, in_progress, blocked with a reason, done, cancelled). Filter by status, assignee (name substring), kind (batch, tests, samples, review, other), the linked record (UID accepted), or late only. Open ones first, then by due date.',
99
+ inputSchema: {
100
+ type: 'object',
101
+ properties: {
102
+ status: { type: 'string', description: 'open, in_progress, blocked, done, cancelled; or "active" for open + in_progress + blocked.' },
103
+ assignee: { type: 'string', description: 'Case-insensitive substring of the name of the person it is asked of.' },
104
+ kind: { type: 'string', description: 'batch, tests, samples, review, other.' },
105
+ entity_type: { type: 'string', description: 'The linked record\'s type (formulation, batch, sample, testResult, project).' },
106
+ entity_id: { type: 'string', description: 'The linked record (internal id or UID).' },
107
+ late_only: { type: 'boolean', description: 'true = only active requests past their due date.' },
108
+ limit: { type: 'number', description: 'Max rows (default 100, max 1000).' },
109
+ },
110
+ },
111
+ },
112
+ handler: async (args) => {
113
+ const { db } = getStore();
114
+ const none = _notLive(db); if (none) return none;
115
+ const limit = _clampLimit(args.limit);
116
+ const today = new Date().toISOString().slice(0, 10);
117
+ const active = new Set(['open', 'in_progress', 'blocked']);
118
+ const wantId = _resolveId(args.entity_type, args.entity_id, db);
119
+ const order = { blocked: 0, open: 1, in_progress: 2, done: 3, cancelled: 4 };
120
+ const rows = (db.requests || []).filter(r => r
121
+ && (!args.status || (args.status === 'active' ? active.has(r.status) : r.status === args.status))
122
+ && (!args.assignee || _norm(r.assignee).includes(_norm(args.assignee)))
123
+ && (!args.kind || r.kind === args.kind)
124
+ && (!args.entity_type || r.entityType === args.entity_type) && (!wantId || r.entityId === wantId)
125
+ && (!args.late_only || (active.has(r.status) && r.due && r.due < today)))
126
+ .sort((a, b) => (order[a.status] - order[b.status]) || String(a.due || '9999').localeCompare(String(b.due || '9999')));
127
+ return {
128
+ totalMatching: rows.length, returned: Math.min(rows.length, limit),
129
+ requests: rows.slice(0, limit).map(r => { const rec = r.entityType ? _record(r.entityType, r.entityId, db) : null;
130
+ return { uid: r.uid, title: r.title, kind: r.kind, status: r.status, blockedReason: r.blockedReason || null, assignee: r.assignee || null,
131
+ askedBy: r.askedBy || null, due: r.due || null, late: !!(active.has(r.status) && r.due && r.due < today),
132
+ on: rec ? { type: r.entityType, uid: rec.uid, name: rec.name } : null, note: r.note || null,
133
+ createdAt: r.createdAt, closedAt: r.closedAt || null }; }),
134
+ };
135
+ },
136
+ };
137
+
138
+ export const tools = { list_discussions, list_requests };
@@ -151,7 +151,7 @@ function eqCalCardHtml(e) {
151
151
  <span><span style="color:var(--text-muted)">Last</span> <strong>${esc(st.last || '—')}</strong>${st.lastResult ? ` · ${esc(_EQ_CAL_RESULT_LABEL[st.lastResult] || st.lastResult)}` : ''}</span>
152
152
  <span><span style="color:var(--text-muted)">Next due</span> <strong>${esc(st.due || '—')}</strong></span>
153
153
  <span><span style="color:var(--text-muted)">Interval</span> <strong>${interval ? interval + ' month' + (interval === 1 ? '' : 's') : '—'}</strong></span>
154
- </div>${st.state === 'failed' && e.status !== 'Out of service' ? `<div style="margin-top:10px;font-size:12.5px;color:var(--dk-red-fg, #b91c1c)">The latest calibration failed. Set the instrument <strong>Out of service</strong> (Edit) until it passes again.</div>` : ''}`;
154
+ </div>${st.state === 'failed' && e.status !== 'Out of service' ? `<div style="margin-top:10px;font-size:12.5px;color:var(--dk-red-fg, #b91c1c)">The latest calibration failed. Set the instrument <strong>Out of service</strong> (the status beside its name) until it passes again.</div>` : ''}`;
155
155
  const rows = hist.map(c => `<tr>
156
156
  <td style="font-variant-numeric:tabular-nums">${esc(c.date || '—')}</td>
157
157
  <td>${esc(c.by || '—')}</td>
@@ -199,6 +199,12 @@ function openEqCalLogModal(eqId, calId) {
199
199
  const e = typeof getEquipment === 'function' ? getEquipment(eqId) : (db.equipment || []).find(x => x.id === eqId);
200
200
  if (!e) return;
201
201
  const c = calId ? (e.calibrations || []).find(x => x && x.id === calId) : null;
202
+ // EQ1 (0186): a Technician adds calibrations; changing or deleting a logged one stays with "Edit the shared libraries".
203
+ const caps = typeof window !== 'undefined' ? window.flMyCaps : null;
204
+ if (c && Array.isArray(caps) && !caps.includes('library.edit')) {
205
+ toast('Your role can log new calibrations, not change a logged one. Ask a lab manager or a formulator.');
206
+ return;
207
+ }
202
208
  const interval = eqCalInterval(e);
203
209
  const date = c ? (c.date || '') : _eqCalToday();
204
210
  const files = Array.isArray(e.fileAttachments) ? e.fileAttachments : [];