agents-relay 2.0.266 → 2.0.267

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.
@@ -0,0 +1,92 @@
1
+ <!doctype html>
2
+ <html lang="en" data-dashboard-contract="safe-dom,named-relay-events,snapshot-events,bounded-event-history">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <meta name="theme-color" content="#285f86">
7
+ <meta name="apple-mobile-web-app-capable" content="yes">
8
+ <meta name="apple-mobile-web-app-status-bar-style" content="default">
9
+ <link rel="manifest" href="/manifest.webmanifest">
10
+ <link rel="apple-touch-icon" href="/icons/icon-180.png">
11
+ <title>Agents Relay Console</title>
12
+ <link rel="stylesheet" href="/dashboard.css">
13
+ </head>
14
+ <body>
15
+ <header>
16
+ <div class="brand"><h1>Agents Relay Console</h1><p class="tagline">Durable PR state is authoritative; events are observability.</p><span class="version"></span></div>
17
+ <div id="runtime-summary" class="runtime-summary" aria-label="Runtime summary"></div>
18
+ <div id="rate-limit-warning" class="warning-banner" role="status" hidden></div>
19
+ <nav role="tablist" aria-label="Console views">
20
+ <button id="jobs-tab" type="button" role="tab" aria-selected="true" aria-controls="jobs-view">Jobs</button>
21
+ <button id="usage-tab" type="button" role="tab" aria-selected="false" aria-controls="usage-view">Usage</button>
22
+ <button id="rules-tab" type="button" role="tab" aria-selected="false" aria-controls="rules-view">Router Rules</button>
23
+ <button id="qa-tab" type="button" role="tab" aria-selected="false" aria-controls="qa-view">Troubleshooter Q&A</button>
24
+ <button id="graphs-tab" type="button" role="tab" aria-selected="false" aria-controls="graphs-view">Workflow</button>
25
+ </nav>
26
+ </header>
27
+ <main>
28
+ <section id="jobs-view" role="tabpanel" aria-labelledby="jobs-tab" class="panel jobs-panel">
29
+ <div class="panel-head"><h2>Jobs</h2><div class="panel-actions"><div class="job-filters"><input id="job-search" class="job-search" type="search" placeholder="Search" aria-label="Search jobs by title or PR number"><select id="status-filter" class="job-filter" aria-label="Filter jobs by status (default excludes cancelled)"><option value="">No cancelled</option><option value="DRAFT">DRAFT</option><option value="ACTIVE">ACTIVE</option><option value="COMPLETED">COMPLETED</option><option value="CANCELLED">CANCELLED</option></select><select id="repo-filter" class="job-filter" aria-label="Filter jobs by repository"><option value="">All repos</option></select></div><div class="jobs-actions"><button id="jobs-refresh" class="icon-button" type="button" aria-label="Refresh jobs" title="Refresh jobs"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M20 11a8 8 0 1 0 1 5"/><path d="M20 4v7h-7"/></svg></button></div><span id="jobs-feedback" class="jobs-feedback subtle" role="status" aria-live="polite"></span></div></div>
30
+ <div class="panel-body" aria-live="polite"><ul id="job-list" class="job-list"><li class="skeleton" aria-hidden="true"></li></ul></div>
31
+ </section>
32
+ <div class="workspace" id="jobs-workspace">
33
+ <section class="panel" aria-labelledby="workspace-heading">
34
+ <div class="panel-head"><button id="mobile-jobs-back" class="icon-button mobile-only" type="button" aria-label="Back to Jobs" title="Back to Jobs"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M19 12H5m7-7-7 7 7 7"/></svg></button><h2 id="workspace-heading"><span id="selected-job-title" class="subtle"></span></h2><div class="panel-actions"><button id="job-content-open" class="icon-button job-status-button" type="button" aria-label="Job details" title="Job details" data-state="IDLE"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="9"/><circle cx="12" cy="12" r="3" class="status-center"/></svg></button><button id="selected-job-refresh" class="icon-button" type="button" aria-label="Refresh selected job" title="Refresh selected job"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M20 11a8 8 0 1 0 1 5"/><path d="M20 4v7h-7"/></svg></button></div></div>
35
+ <div class="panel-body">
36
+ <div id="job-detail"><div class="skeleton"></div></div>
37
+ <h3 class="section-title">Task hierarchy</h3>
38
+ <ul id="task-tree" class="tree"><li class="skeleton"></li></ul>
39
+ <h3 class="section-title">Task detail</h3>
40
+ <div id="task-detail"><p class="empty">Select a task to inspect execution details.</p></div>
41
+ </div>
42
+ </section>
43
+ <section class="panel" id="events-panel" aria-labelledby="events-heading">
44
+ <div class="panel-head"><h2 id="events-heading">Events</h2><div class="panel-actions"><button id="events-all-tasks" class="icon-button" type="button" aria-label="Show events for all tasks" title="All tasks"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 6h2m4 0h10M4 12h2m4 0h10M4 18h2m4 0h10"/></svg></button><span id="events-scope" class="subtle">Job-wide · newest first · 60 max</span></div></div>
45
+ <div class="panel-body"><ol id="event-feed" class="event-list"><li class="empty">Waiting for events.</li></ol></div>
46
+ </section>
47
+ </div>
48
+ <section id="usage-view" role="tabpanel" aria-labelledby="usage-tab" hidden>
49
+ <div class="panel">
50
+ <div class="panel-head"><h2 id="usage-heading">Usage</h2><span id="usage-meta" class="subtle"></span></div>
51
+ <div class="panel-body" id="usage-root" aria-live="polite"><div class="skeleton"></div></div>
52
+ </div>
53
+ </section>
54
+ <section id="graphs-view" role="tabpanel" aria-labelledby="graphs-tab" hidden>
55
+ <div class="panel">
56
+ <div class="panel-head"><h2>Workflow Graphs</h2><span id="graphs-meta" class="subtle"></span></div>
57
+ <div class="panel-body">
58
+ <div class="graphs-browser">
59
+ <div id="graph-list" class="graph-list" aria-label="Workflow graphs"></div>
60
+ <div class="graph-preview">
61
+ <div id="graph-navigation" class="graph-navigation" aria-label="Graph navigation"><button type="button" id="graph-back" class="refresh-button">Back</button><button type="button" id="graph-forward" class="refresh-button">Forward</button><button type="button" id="graph-entry" class="refresh-button">Entry</button><span id="graph-breadcrumb" class="subtle"></span></div>
62
+ <div id="graph-detail" class="graph-source" aria-live="polite" hidden></div>
63
+ <div class="graph-preview-head"><h3 id="graph-title">Select a graph</h3><button type="button" id="graph-maximize" class="refresh-button">Maximize graph</button></div><p id="graph-description" class="subtle"></p><span id="graph-path" class="subtle"></span>
64
+ <div id="graph-canvas" class="graph-canvas"><p class="empty">Select a graph to inspect it.</p></div>
65
+ </div>
66
+ </div>
67
+ </div>
68
+ </div>
69
+ </section>
70
+ <div id="jel-chart" class="graph-canvas jel-chart" aria-live="polite" hidden></div>
71
+ <dialog id="graph-dialog" class="graph-dialog" aria-label="Graph viewer"><div class="graph-dialog-header"><strong id="graph-dialog-title">Workflow graph</strong><div class="graph-navigation"><button type="button" id="graph-zoom-out" class="refresh-button" aria-label="Zoom out">−</button><span id="graph-zoom-level" aria-live="polite">100%</span><button type="button" id="graph-zoom-in" class="refresh-button" aria-label="Zoom in">+</button><button type="button" id="graph-zoom-reset" class="refresh-button">Fit</button><button type="button" id="graph-dialog-close" class="refresh-button">Close</button></div></div><div id="graph-dialog-viewport" class="graph-dialog-viewport"></div></dialog>
72
+ <section id="rules-view" role="tabpanel" aria-labelledby="rules-tab" hidden><div class="panel"><div class="panel-head"><h2>Router Rules</h2><span id="rules-meta" class="subtle"></span></div><div class="panel-body"><div class="router-rules-workspace"><div class="router-rules-pane rules-editor"><h3>Rules Editor</h3><p class="rules-help">Execution Router rules with an explicit <code>[choices]</code> section (provider: model [reasoning] entries, additive to profile defaults) and a <code>[routing-instruction]</code> section forwarded verbatim to Laya. Relay deduplicates, applies hard gates, and sends one merged choice list; impossible routes remain excluded by code and Codex stays the deterministic fallback.</p><textarea id="rules-text" class="rules-textarea" spellcheck="true" aria-label="Execution router rules" placeholder="[choices]
73
+ openai: sol medium, luna high
74
+ zai: glm-5.3-flash high
75
+
76
+ [routing-instruction]
77
+ Prefer zai until its quota resets; otherwise use the openai default."></textarea><div class="rules-footer"><span id="rules-status" class="subtle" aria-live="polite"></span><div><button id="rules-test" class="rules-save" type="button">Test Router</button> <button id="rules-save" class="rules-save" type="button">Save rules</button></div></div></div><div class="router-rules-pane"><div class="panel-head"><h3>Audit Log</h3><button id="audit-refresh" type="button">Refresh</button></div><div id="audit-log" class="audit-log" aria-live="polite"><p class="empty">Loading latest routing decisions…</p></div></div></div><div class="router-test-panel"><h3>Test Router Result</h3><div id="router-test-results" class="router-test-results" aria-live="polite"><p class="empty">Select a Job and Task, then run Test Router.</p></div></div></div></div></section>
78
+ <section id="qa-view" role="tabpanel" aria-labelledby="qa-tab" hidden>
79
+ <div class="panel"><div class="panel-head"><h2>Troubleshooter Q&A</h2><span class="subtle">skills/agents-relay/troubleshooter-qa.md</span></div>
80
+ <div class="panel-body"><div class="rules-editor">
81
+ <p class="rules-help">Edit Markdown directly. Troubleshooter reads this file as guidance, not workflow policy.</p>
82
+ <textarea id="qa-text" class="rules-textarea" spellcheck="true" aria-label="Troubleshooter Q&A Markdown"></textarea>
83
+ <div class="rules-footer"><span id="qa-status" class="subtle" aria-live="polite"></span><div><button id="qa-reload" class="rules-save" type="button">Reload</button> <button id="qa-save" class="rules-save" type="button">Save Q&A</button></div></div>
84
+ </div></div></div>
85
+ </section>
86
+ </main>
87
+ <script src="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"></script>
88
+ <script src="/dashboard-config.js" defer></script>
89
+ <script src="/dashboard.js" defer></script>
90
+ <script src="/pwa.js" defer></script>
91
+ </body>
92
+ </html>
@@ -0,0 +1,193 @@
1
+ function jobJelDiagram(job) {
2
+ const lines = ['flowchart LR'];
3
+ const safe = (value) => String(value ?? 'Unknown').replace(/https?:\/\/[^\s]*/gi, '').replace(/[^\p{L}\p{N} _./()—:-]/gu, '').slice(0, 100);
4
+ const now = Date.now();
5
+ const instant = (value) => {
6
+ if (typeof value !== 'string' || !value)
7
+ return null;
8
+ const parsed = Date.parse(value);
9
+ return Number.isFinite(parsed) && parsed <= now ? parsed : null;
10
+ };
11
+ const elapsed = (start, end) => {
12
+ const from = instant(start);
13
+ const to = end === 'NOW' ? now : instant(end);
14
+ if (from === null || to === null || to < from)
15
+ return '—';
16
+ const seconds = Math.floor((to - from) / 1000);
17
+ if (seconds < 60)
18
+ return seconds + 's';
19
+ const minutes = Math.floor(seconds / 60);
20
+ if (minutes < 60)
21
+ return minutes + 'm' + String(seconds % 60).padStart(2, '0') + 's';
22
+ const hours = Math.floor(minutes / 60);
23
+ if (hours < 24)
24
+ return hours + 'h' + String(minutes % 60).padStart(2, '0') + 'm';
25
+ return Math.floor(hours / 24) + 'd' + String(hours % 24).padStart(2, '0') + 'h';
26
+ };
27
+ const terminalTask = (task) => ['SUCCEEDED', 'FAILED', 'CANCELLED'].includes(task.state || '');
28
+ const workElapsed = (work) => {
29
+ const starts = work.map(task => instant(task.createdAt)).filter((time) => time !== null);
30
+ if (starts.length !== work.length || !starts.length)
31
+ return '—';
32
+ const ends = work.map(task => instant(task.updatedAt)).filter((time) => time !== null);
33
+ return elapsed(new Date(Math.min(...starts)).toISOString(), work.every(terminalTask) && ends.length === work.length ? new Date(Math.max(...ends)).toISOString() : 'NOW');
34
+ };
35
+ const node = (id, label, time) => lines.push(' ' + id + '["' + safe(label).slice(0, 80) + ' (' + safe(time) + ')"]');
36
+ const edge = (from, to, reason = '') => lines.push(' ' + from + ' -->' + (reason ? '|' + safe(reason) + '|' : '') + ' ' + to);
37
+ const tasks = Array.isArray(job.tasks) ? job.tasks : [];
38
+ const isReviewer = (task) => ['job-acceptance-reviewer', 'reviewer'].includes(task.agentName || '');
39
+ const isTroubleshooter = (task) => task.agentName === 'troubleshooter';
40
+ // These dashed observation branches are not workflow transitions: persisted
41
+ // Task facts are projected without inferring a new scheduling decision.
42
+ const diagnostics = (executionId, suffix, work, troubleshoot) => {
43
+ const failed = new Set();
44
+ const add = (kind, label, time, origin) => {
45
+ const id = kind + '_' + suffix + '_' + String(lines.filter(line => line.startsWith(' ' + kind + '_' + suffix + '_')).length);
46
+ node(id, label, time);
47
+ lines.push(' ' + (origin ? taskNodeId(origin) : executionId) + ' -.-> ' + id);
48
+ lines.push(' class ' + id + ' jel' + kind[0].toUpperCase() + kind.slice(1));
49
+ };
50
+ for (const task of work) {
51
+ if (task.state === 'FAILED') {
52
+ const key = (task.id || 'unknown') + ':' + String(task.attempt ?? '?');
53
+ failed.add(key);
54
+ add('failed', 'Failed', elapsed(task.createdAt, task.updatedAt), task);
55
+ }
56
+ if (typeof task.attempt === 'number' && Number.isInteger(task.attempt) && task.attempt > 1) {
57
+ const history = Array.isArray(task.executionHistory) ? task.executionHistory : [];
58
+ const current = history.slice().reverse().find(record => record.attempt === task.attempt);
59
+ add('retry', 'Retry', elapsed(current?.startedAt, terminalTask(task) ? task.updatedAt : 'NOW'), task);
60
+ }
61
+ }
62
+ for (const task of troubleshoot) {
63
+ const parent = work.find(candidate => candidate.id === task.parentTaskId);
64
+ if (parent && Number.isInteger(task.recoveryForAttempt) && (task.recoveryForAttempt ?? 0) > 0) {
65
+ const key = (parent.id || 'unknown') + ':' + task.recoveryForAttempt;
66
+ if (!failed.has(key)) {
67
+ failed.add(key);
68
+ // Recovery-for-attempt is durable evidence of a failed attempt, but
69
+ // not of its terminal timestamp: display unknown, never fabricate.
70
+ add('failed', 'Failed', '—', parent);
71
+ }
72
+ }
73
+ add('troubleshooter', task.title || task.agentName || 'Troubleshooter', workElapsed([task]), parent);
74
+ }
75
+ };
76
+ // Exact Task IDs, DAG lineage and dependencies are persisted facts, not inferred
77
+ // workflow transitions. Task nodes are clickable in the dashboard after SVG sanitization.
78
+ const taskNodeId = (task) => 'task_' + tasks.indexOf(task);
79
+ const taskElapsed = (task) => {
80
+ const end = terminalTask(task) ? task.updatedAt : 'NOW';
81
+ const coordinator = (task.kind || '').toLowerCase() === 'coordinator' ||
82
+ (/coordinator/i.test(task.agentName || '') && !task.dagNode) || !!task.agentGraph;
83
+ const history = Array.isArray(task.executionHistory) ? task.executionHistory : [];
84
+ const last = history.slice().reverse().find(record => record.attempt === task.attempt);
85
+ const run = coordinator ? '—' : elapsed(last?.startedAt, end);
86
+ return run !== '—' ? run : elapsed(task.createdAt, end);
87
+ };
88
+ const taskNodes = (stage, work) => {
89
+ const byId = new Map(work.filter(task => task.id).map(task => [task.id, task]));
90
+ for (const task of work) {
91
+ const id = taskNodeId(task);
92
+ node(id, task.title?.trim() || task.agentName?.trim() || task.id || 'Task', taskElapsed(task));
93
+ if (task.state === 'FAILED')
94
+ lines.push(' class ' + id + ' jelFailed');
95
+ else if ((task.attempt || 0) > 1)
96
+ lines.push(' class ' + id + ' jelRetry');
97
+ const parent = task.parentTaskId ? byId.get(task.parentTaskId) : undefined;
98
+ if (parent)
99
+ edge(taskNodeId(parent), id, 'DAG child');
100
+ else
101
+ lines.push(' ' + stage + ' -.-> ' + id);
102
+ for (const dependency of task.dependencies || []) {
103
+ const upstream = byId.get(dependency);
104
+ if (upstream && upstream !== parent)
105
+ edge(taskNodeId(upstream), id, 'depends');
106
+ }
107
+ }
108
+ };
109
+ const finish = () => {
110
+ // The browser applies the same palette *after* SVG sanitization; Mermaid
111
+ // styling alone is not trusted to survive the safe SVG renderer.
112
+ lines.push(' classDef jelFailed fill:#fee2e2,stroke:#b91c1c,color:#991b1b,stroke-width:2px');
113
+ lines.push(' classDef jelRetry fill:#ede9fe,stroke:#7c3aed,color:#5b21b6,stroke-width:2px');
114
+ lines.push(' classDef jelTroubleshooter fill:#fef3c7,stroke:#b45309,color:#92400e,stroke-width:2px');
115
+ lines.push(' classDef jelReviewer fill:#dbeafe,stroke:#2563eb,color:#1e40af,stroke-width:2px');
116
+ return lines.join('\n');
117
+ };
118
+ const plans = Array.isArray(job.plans) ? job.plans : [];
119
+ const jobEnd = ['COMPLETED', 'CANCELLED'].includes(job.state || '') ? job.updatedAt : 'NOW';
120
+ const firstStart = plans[0]?.createdAt || (job.tasks || []).map(task => task.createdAt).filter(Boolean).sort()[0];
121
+ node('created', 'Create', elapsed(job.createdAt, firstStart || jobEnd));
122
+ const rounds = plans.length ? plans : [{ id: '', round: 1, status: 'NOT STARTED', generatedTaskIds: [] }];
123
+ let previous = 'created';
124
+ const allocated = new Set();
125
+ for (let i = 0; i < rounds.length; i++) {
126
+ const plan = rounds[i];
127
+ const number = Number.isInteger(plan.round) && (plan.round ?? 0) > 0 ? plan.round : i + 1;
128
+ const suffix = String(i + 1);
129
+ const planId = 'plan_' + suffix;
130
+ const executeId = 'execute_' + suffix;
131
+ const reviewId = 'review_' + suffix;
132
+ const assigned = new Set(Array.isArray(plan.generatedTaskIds) ? plan.generatedTaskIds : []);
133
+ const candidates = tasks.filter(task => !isReviewer(task) && !isTroubleshooter(task));
134
+ if (plans.length) {
135
+ for (const task of candidates)
136
+ if (task.planningDecisionId === plan.id || task.planningRound === number)
137
+ assigned.add(task.id || '');
138
+ // DAG children often have only parentTaskId; inherit the parent round.
139
+ for (let depth = 0; depth < candidates.length; depth++) {
140
+ let changed = false;
141
+ for (const task of candidates)
142
+ if (task.parentTaskId && assigned.has(task.parentTaskId) && !assigned.has(task.id || '')) {
143
+ assigned.add(task.id || '');
144
+ changed = true;
145
+ }
146
+ if (!changed)
147
+ break;
148
+ }
149
+ }
150
+ const work = plans.length
151
+ ? candidates.filter(task => !allocated.has(task.id || '') && (assigned.has(task.id || '') || (i === rounds.length - 1)))
152
+ : candidates;
153
+ for (const task of work)
154
+ if (task.id)
155
+ allocated.add(task.id);
156
+ if (plans.length)
157
+ node(planId, 'Plan ' + number, elapsed(plan.createdAt, plan.status === 'PLANNING' ? 'NOW' : plan.updatedAt));
158
+ node(executeId, 'Execute ' + number, workElapsed(work));
159
+ const workIds = new Set(work.map(task => task.id));
160
+ const troubleshoot = tasks.filter(task => isTroubleshooter(task) &&
161
+ (workIds.has(task.parentTaskId || '') || task.planningDecisionId === plan.id || !plans.length));
162
+ taskNodes(executeId, work);
163
+ diagnostics(executeId, suffix, work, troubleshoot);
164
+ const nextPlan = plans[i + 1];
165
+ // Review Tasks are not guaranteed to carry the Plan ID. Use their persisted
166
+ // timestamps within the current round, never guess a Review duration.
167
+ const reviewTasks = tasks.filter(task => isReviewer(task) &&
168
+ (!plans.length || (instant(task.createdAt) !== null && instant(plan.createdAt) !== null &&
169
+ instant(task.createdAt) >= instant(plan.createdAt) && (!nextPlan?.createdAt || (instant(nextPlan.createdAt) !== null && instant(task.createdAt) < instant(nextPlan.createdAt))))));
170
+ node(reviewId, 'Final Review ' + number, workElapsed(reviewTasks));
171
+ for (const task of reviewTasks) {
172
+ node(taskNodeId(task), task.title?.trim() || task.agentName || task.id || 'Final Review', taskElapsed(task));
173
+ lines.push(' ' + reviewId + ' -.-> ' + taskNodeId(task));
174
+ lines.push(' class ' + taskNodeId(task) + (task.state === 'FAILED' ? ' jelFailed' : ' jelReviewer'));
175
+ }
176
+ if (plans.length) {
177
+ edge(previous, planId, i > 0 && plan.trigger?.source === 'review' ? 'changes required' : '');
178
+ edge(planId, executeId);
179
+ }
180
+ else
181
+ edge(previous, executeId);
182
+ edge(executeId, reviewId);
183
+ previous = reviewId;
184
+ }
185
+ const merge = job.localMerge?.status === 'failed' ? 'FAILED' : job.localMerge?.status === 'succeeded' || job.githubState === 'MERGED' || job.publication?.version ? 'DONE' : job.state === 'COMPLETED' ? 'NOT RECORDED' : 'PENDING';
186
+ const mergeStart = job.review?.outcome === 'approved' ? job.review.updatedAt : undefined;
187
+ const mergeEnd = merge === 'DONE' ? job.localMerge?.updatedAt || job.mergedAt : merge === 'PENDING' && mergeStart ? 'NOW' : undefined;
188
+ node('merge', 'Merge', elapsed(mergeStart, mergeEnd));
189
+ node('finished', 'Job', elapsed(job.createdAt, jobEnd));
190
+ edge(previous, 'merge');
191
+ edge('merge', 'finished');
192
+ return finish();
193
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "Agents Relay Console",
3
+ "short_name": "Relay",
4
+ "description": "Local Agents Relay job and task console",
5
+ "id": "/",
6
+ "start_url": "/",
7
+ "scope": "/",
8
+ "display": "standalone",
9
+ "background_color": "#f3f5f8",
10
+ "theme_color": "#285f86",
11
+ "icons": [
12
+ {
13
+ "src": "/icons/icon-192.png",
14
+ "sizes": "192x192",
15
+ "type": "image/png",
16
+ "purpose": "any maskable"
17
+ },
18
+ {
19
+ "src": "/icons/icon-512.png",
20
+ "sizes": "512x512",
21
+ "type": "image/png",
22
+ "purpose": "any maskable"
23
+ }
24
+ ]
25
+ }
@@ -0,0 +1,6 @@
1
+ // Installation shell only. Dashboard and API behavior remain in dashboard.js.
2
+ if ('serviceWorker' in navigator && (location.protocol === 'https:' || ['localhost','127.0.0.1'].includes(location.hostname))) {
3
+ window.addEventListener('load', () => {
4
+ void navigator.serviceWorker.register('/service-worker.js', { scope: '/' }).catch(() => {});
5
+ });
6
+ }
@@ -0,0 +1,24 @@
1
+ // Only public, non-sensitive, version-independent app-shell assets are cached.
2
+ // Never intercept /api/*, /events, /dashboard-config.js or navigations.
3
+ const CACHE = 'agents-relay-pwa-shell-v1';
4
+ const ASSETS = ['/dashboard.css', '/dashboard.js', '/pwa.js', '/manifest.webmanifest',
5
+ '/icons/icon-180.png', '/icons/icon-192.png', '/icons/icon-512.png'];
6
+ const ALLOWED = new Set(ASSETS);
7
+ self.addEventListener('install', event => {
8
+ event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(ASSETS)).then(() => self.skipWaiting()));
9
+ });
10
+ self.addEventListener('activate', event => {
11
+ event.waitUntil(caches.keys().then(keys => Promise.all(keys.filter(key => key.startsWith('agents-relay-pwa-') && key !== CACHE).map(key => caches.delete(key)))).then(() => self.clients.claim()));
12
+ });
13
+ self.addEventListener('fetch', event => {
14
+ if (event.request.method !== 'GET') return;
15
+ const url = new URL(event.request.url);
16
+ if (url.origin !== self.location.origin || !ALLOWED.has(url.pathname)) return;
17
+ event.respondWith(fetch(event.request).then(response => {
18
+ if (response.ok) {
19
+ const copy = response.clone();
20
+ void caches.open(CACHE).then(cache => cache.put(event.request, copy));
21
+ }
22
+ return response;
23
+ }).catch(async () => (await caches.match(event.request)) || Response.error()));
24
+ });