@deep-podder/dsh-remote-mobile 0.0.0-stage → 0.0.6

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/mobile/sw.js ADDED
@@ -0,0 +1,396 @@
1
+ /* DSH Remote — service worker (v20)
2
+ *
3
+ * Zero dependencies. Caches only the app shell:
4
+ * - navigations: network first, cached "/" fallback when offline
5
+ * - versioned same-origin assets: cache first + stale-while-revalidate
6
+ * - never touches /api/*, /ws, /remote-mobile/*, /share-target, or anything
7
+ * cross-origin / opaque
8
+ *
9
+ * Bump CACHE when the shell changes; registration in app.js uses
10
+ * updateViaCache: 'none'. The page reloads at most once on controllerchange.
11
+ */
12
+ 'use strict';
13
+
14
+ var CACHE = 'dsh-remote-v20';
15
+ var PRECACHE = [
16
+ '/',
17
+ '/app.js?v=20',
18
+ '/styles.css?v=20',
19
+ '/manifest.webmanifest',
20
+ '/favicon.svg',
21
+ '/icons/icon-192.png',
22
+ '/icons/icon-512.png',
23
+ '/icons/icon-maskable-512.png',
24
+ '/icons/apple-touch-icon.png'
25
+ ];
26
+
27
+ /* Bounded diagnostics for the Host debug log: only event names, the cache
28
+ * version and (optionally) an error name. Never sends a subscription endpoint,
29
+ * key material or notification content. */
30
+ function reportPush(kind, detail) {
31
+ try {
32
+ fetch('/api/push/report', {
33
+ method: 'POST',
34
+ keepalive: true,
35
+ credentials: 'same-origin',
36
+ headers: { 'content-type': 'application/json' },
37
+ body: JSON.stringify({
38
+ kind: String(kind || 'event').slice(0, 40),
39
+ detail: String(detail || '').slice(0, 180),
40
+ scope: self.registration ? String(self.registration.scope || '') : ''
41
+ })
42
+ }).catch(function () {});
43
+ } catch (err) {
44
+ /* diagnostics must never break the push path */
45
+ }
46
+ }
47
+
48
+ var SHELL_PATHS = { '/': true,
49
+ '/index.html': true,
50
+ '/app.js': true,
51
+ '/styles.css': true,
52
+ '/manifest.webmanifest': true,
53
+ '/favicon.svg': true,
54
+ '/icons/icon-192.png': true,
55
+ '/icons/icon-512.png': true,
56
+ '/icons/icon-maskable-512.png': true,
57
+ '/icons/apple-touch-icon.png': true
58
+ };
59
+
60
+ var NEVER_PREFIXES = ['/api/', '/remote-mobile/'];
61
+ var NEVER_PATHS = { '/ws': true, '/share-target': true, '/sw.js': true };
62
+
63
+ function isNever(url) {
64
+ if (NEVER_PATHS[url.pathname]) return true;
65
+ for (var i = 0; i < NEVER_PREFIXES.length; i += 1) {
66
+ if (url.pathname.indexOf(NEVER_PREFIXES[i]) === 0) return true;
67
+ }
68
+ return false;
69
+ }
70
+
71
+ function isShellAsset(url) {
72
+ if (SHELL_PATHS[url.pathname]) return true;
73
+ /* A cache-busting version query always identifies a shell asset. */
74
+ return url.searchParams.has('v');
75
+ }
76
+
77
+ function stash(request, response) {
78
+ if (!response || !response.ok || response.type !== 'basic') return;
79
+ caches.open(CACHE).then(function (cache) {
80
+ return cache.put(request, response.clone());
81
+ }).catch(function () {
82
+ /* best effort: a failed write must never break a response */
83
+ });
84
+ }
85
+
86
+ function navigationResponse(request) {
87
+ return fetch(request).then(function (response) {
88
+ if (
89
+ response &&
90
+ response.ok &&
91
+ response.type === 'basic' &&
92
+ new URL(request.url).pathname === '/'
93
+ ) {
94
+ stash(new Request('/'), response);
95
+ }
96
+ return response;
97
+ }).catch(function () {
98
+ return caches.open(CACHE).then(function (cache) {
99
+ return cache.match('/').then(function (cached) {
100
+ return cached || cache.match('/index.html');
101
+ });
102
+ }).then(function (cached) {
103
+ return cached || Response.error();
104
+ });
105
+ });
106
+ }
107
+
108
+ function staticAsset(event, request) {
109
+ var cachePromise = caches.open(CACHE);
110
+ var networkPromise = fetch(request).then(function (response) {
111
+ if (response && response.ok && response.type === 'basic') {
112
+ return cachePromise.then(function (cache) {
113
+ return cache.put(request, response.clone());
114
+ }).then(function () {
115
+ return response;
116
+ }).catch(function () {
117
+ return response;
118
+ });
119
+ }
120
+ return response;
121
+ }).catch(function () {
122
+ return null;
123
+ });
124
+
125
+ /* Start the revalidation without waiting for the response body. */
126
+ event.waitUntil(networkPromise.then(function () {}).catch(function () {}));
127
+
128
+ return cachePromise.then(function (cache) {
129
+ return cache.match(request);
130
+ }).then(function (cached) {
131
+ if (cached) return cached;
132
+ return networkPromise.then(function (response) {
133
+ if (response) return response;
134
+ return caches.open(CACHE).then(function (cache) {
135
+ return cache.match(request, { ignoreSearch: true });
136
+ }).then(function (fallback) {
137
+ return fallback || Response.error();
138
+ });
139
+ });
140
+ });
141
+ }
142
+
143
+ self.addEventListener('install', function (event) {
144
+ event.waitUntil(
145
+ caches.open(CACHE).then(function (cache) {
146
+ return cache.addAll(PRECACHE);
147
+ }).then(function () {
148
+ return self.skipWaiting();
149
+ })
150
+ );
151
+ });
152
+
153
+ self.addEventListener('activate', function (event) {
154
+ event.waitUntil(
155
+ caches.keys().then(function (keys) {
156
+ return Promise.all(keys.map(function (key) {
157
+ if (key.indexOf('dsh-remote-') === 0 && key !== CACHE) {
158
+ return caches.delete(key);
159
+ }
160
+ return Promise.resolve(false);
161
+ }));
162
+ }).then(function () {
163
+ return self.clients.claim();
164
+ }).then(function () {
165
+ reportPush('sw-activated', 'cache=' + CACHE);
166
+ })
167
+ );
168
+ });
169
+
170
+ /* ---------- Web Push ------------------------------------------------------ */
171
+ /* The page registers for push and reports `client.visibility` over the socket;
172
+ * this worker only renders the payload the Host sent and routes a tap back
173
+ * into the app. Payload parsing is defensive: a malformed or empty message
174
+ * still produces a notification, because a push event that ends without
175
+ * showNotification can make the browser revoke the subscription. */
176
+
177
+ var PUSH_ICON = '/icons/icon-192.png';
178
+ var PUSH_FALLBACK_TITLE = 'DSH Remote';
179
+ var PUSH_FALLBACK_BODY = 'Something needs your attention.';
180
+
181
+ function readPushPayload(event) {
182
+ var payload = null;
183
+ try {
184
+ payload = event && event.data ? event.data.json() : null;
185
+ } catch (err) {
186
+ payload = null;
187
+ }
188
+ if (payload === null || typeof payload !== 'object' || Array.isArray(payload)) payload = {};
189
+ return payload;
190
+ }
191
+
192
+ function pushString(value, fallback, limit) {
193
+ if (typeof value !== 'string') return fallback;
194
+ var text = value.replace(/[\u0000-\u001f\u007f]+/g, ' ').trim();
195
+ if (!text) return fallback;
196
+ return limit && text.length > limit ? text.slice(0, limit) : text;
197
+ }
198
+
199
+ function pushNotificationOptions(payload) {
200
+ var options = {
201
+ body: pushString(payload.body, PUSH_FALLBACK_BODY, 240),
202
+ icon: PUSH_ICON,
203
+ badge: PUSH_ICON,
204
+ data: {
205
+ url: pushString(payload.url, '/', 700),
206
+ sessionId: typeof payload.sessionId === 'string' && payload.sessionId ? payload.sessionId.slice(0, 200) : null,
207
+ kind: pushString(payload.kind, 'reply', 24)
208
+ }
209
+ };
210
+ var tag = pushString(payload.tag, '', 200);
211
+ if (tag) options.tag = tag;
212
+ return options;
213
+ }
214
+
215
+ self.addEventListener('push', function (event) {
216
+ var payload = readPushPayload(event);
217
+ var title = pushString(payload.title, PUSH_FALLBACK_TITLE, 120);
218
+ var shown;
219
+ try {
220
+ var registration = self.registration;
221
+ if (registration && typeof registration.showNotification === 'function') {
222
+ shown = registration.showNotification(title, pushNotificationOptions(payload));
223
+ }
224
+ } catch (err) {
225
+ shown = null;
226
+ }
227
+ var outcome = 'kind=' + pushString(payload.kind, 'unknown', 24) + ' tag=' + pushString(payload.tag, '-', 60);
228
+ if (!shown || typeof shown.then !== 'function') shown = Promise.resolve();
229
+ event.waitUntil(shown.then(function () {
230
+ reportPush('push-shown', outcome);
231
+ }, function (err) {
232
+ reportPush('push-error', outcome + ' error=' + (err && err.name ? String(err.name) : 'unknown'));
233
+ }));
234
+ });
235
+
236
+ function sameOriginUrl(value, origin) {
237
+ try {
238
+ return new URL(value, origin);
239
+ } catch (err) {
240
+ try {
241
+ return new URL('/', origin);
242
+ } catch (nextErr) {
243
+ return null;
244
+ }
245
+ }
246
+ }
247
+
248
+ function clientOrigin(url) {
249
+ try {
250
+ return new URL(url).origin;
251
+ } catch (err) {
252
+ return '';
253
+ }
254
+ }
255
+
256
+ self.addEventListener('notificationclick', function (event) {
257
+ try {
258
+ event.notification.close();
259
+ } catch (err) {
260
+ /* ignore */
261
+ }
262
+ var data = event.notification && event.notification.data && typeof event.notification.data === 'object'
263
+ ? event.notification.data
264
+ : {};
265
+ var origin = self.location ? self.location.origin : '';
266
+ var target = sameOriginUrl(typeof data.url === 'string' && data.url ? data.url : '/', origin);
267
+ /* A notification must never navigate the phone to a third-party page, even
268
+ if a malformed/future payload carries an absolute URL. */
269
+ if (!target || target.origin !== origin) target = sameOriginUrl('/', origin);
270
+ var sessionId = typeof data.sessionId === 'string' && data.sessionId ? data.sessionId : null;
271
+
272
+ var work = Promise.resolve().then(function () {
273
+ var matching = [];
274
+ try {
275
+ return self.clients.matchAll({ type: 'window', includeUncontrolled: true });
276
+ } catch (err) {
277
+ return matching;
278
+ }
279
+ }).then(function (list) {
280
+ var clients = Array.isArray(list) ? list : [];
281
+ var wantedOrigin = target ? target.origin : origin;
282
+ for (var i = 0; i < clients.length; i += 1) {
283
+ var client = clients[i];
284
+ if (!client || clientOrigin(client.url) !== wantedOrigin) continue;
285
+ var focused = null;
286
+ try {
287
+ focused = client.focus();
288
+ } catch (err) {
289
+ focused = null;
290
+ }
291
+ return Promise.resolve(focused).catch(function () {}).then(function () {
292
+ try {
293
+ client.postMessage({ type: 'open-session', sessionId: sessionId });
294
+ } catch (err) {
295
+ /* ignore */
296
+ }
297
+ });
298
+ }
299
+ if (!target || !self.clients || typeof self.clients.openWindow !== 'function') return undefined;
300
+ return self.clients.openWindow(target.href).catch(function () {});
301
+ });
302
+ event.waitUntil(work.then(function () {
303
+ reportPush('notification-click', 'session=' + (sessionId || '-'));
304
+ }, function (err) {
305
+ reportPush('notification-click-error', err && err.name ? String(err.name) : 'unknown');
306
+ }));
307
+ });
308
+
309
+ function decodeBase64Url(value) {
310
+ var text = String(value || '').replace(/-/g, '+').replace(/_/g, '/');
311
+ while (text.length % 4 !== 0) text += '=';
312
+ var binary = atob(text);
313
+ var bytes = new Uint8Array(binary.length);
314
+ for (var i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i);
315
+ return bytes;
316
+ }
317
+
318
+ /* Rebuild a lost/rotated push subscription from the Host's VAPID key. Best
319
+ * effort: failure is retried on the next app start by app.js. */
320
+ function renewPushSubscription(event) {
321
+ var registration = null;
322
+ try {
323
+ registration = self.registration;
324
+ } catch (err) {
325
+ registration = null;
326
+ }
327
+ if (!registration || !registration.pushManager || typeof registration.pushManager.subscribe !== 'function') {
328
+ return Promise.resolve();
329
+ }
330
+ return fetch('/api/push/key', { credentials: 'same-origin', cache: 'no-store' })
331
+ .then(function (response) {
332
+ if (!response || !response.ok) return null;
333
+ return response.json();
334
+ })
335
+ .then(function (data) {
336
+ if (!data || data.enabled !== true || typeof data.publicKey !== 'string') return null;
337
+ var existing = event && event.newSubscription ? event.newSubscription : null;
338
+ if (existing) return existing;
339
+ return registration.pushManager.subscribe({
340
+ userVisibleOnly: true,
341
+ applicationServerKey: decodeBase64Url(data.publicKey)
342
+ });
343
+ })
344
+ .then(function (subscription) {
345
+ if (!subscription) return undefined;
346
+ var json = null;
347
+ try {
348
+ json = typeof subscription.toJSON === 'function' ? subscription.toJSON() : subscription;
349
+ } catch (err) {
350
+ json = null;
351
+ }
352
+ if (!json || typeof json !== 'object') return undefined;
353
+ return fetch('/api/push/subscribe', {
354
+ method: 'POST',
355
+ credentials: 'same-origin',
356
+ headers: { 'Content-Type': 'application/json' },
357
+ body: JSON.stringify({ subscription: json })
358
+ }).catch(function () {});
359
+ })
360
+ .catch(function () {});
361
+ }
362
+
363
+ self.addEventListener('pushsubscriptionchange', function (event) {
364
+ event.waitUntil(renewPushSubscription(event).catch(function () {}));
365
+ });
366
+
367
+ self.addEventListener('fetch', function (event) {
368
+ var request = event.request;
369
+ if (!request || request.method !== 'GET') return;
370
+
371
+ var url;
372
+ try {
373
+ url = new URL(request.url);
374
+ } catch (err) {
375
+ return;
376
+ }
377
+
378
+ /* Never proxy or cache cross-origin traffic. */
379
+ if (url.origin !== self.location.origin) return;
380
+ if (isNever(url)) return;
381
+
382
+ if (request.mode === 'navigate') {
383
+ event.respondWith(navigationResponse(request));
384
+ return;
385
+ }
386
+
387
+ if (isShellAsset(url)) {
388
+ event.respondWith(staticAsset(event, request));
389
+ }
390
+ });
391
+
392
+
393
+
394
+
395
+
396
+
package/package.json CHANGED
@@ -1,6 +1,76 @@
1
1
  {
2
2
  "name": "@deep-podder/dsh-remote-mobile",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.6",
4
+ "type": "module",
5
+ "description": "Secure local mobile companion for DeepSeek Harness: pair a phone with a QR code and control live sessions.",
6
+ "license": "MIT",
7
+ "author": "dsh-remote-mobile contributors",
8
+ "homepage": "https://github.com/unknown-spec10/dsg-remote-mobile#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/unknown-spec10/dsg-remote-mobile.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/unknown-spec10/dsg-remote-mobile/issues"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "engines": {
20
+ "node": ">=22"
21
+ },
22
+ "keywords": [
23
+ "deepseek-harness",
24
+ "dsh",
25
+ "cordis-plugin",
26
+ "mobile",
27
+ "remote",
28
+ "pwa"
29
+ ],
30
+ "exports": {
31
+ ".": "./index.js",
32
+ "./client": "./client.js",
33
+ "./locale/*.json": "./locale/*.json",
34
+ "./icon": "./icon.svg",
35
+ "./package.json": "./package.json"
36
+ },
37
+ "files": [
38
+ "index.js",
39
+ "client.js",
40
+ "bridge.js",
41
+ "server.js",
42
+ "auth.js",
43
+ "push.js",
44
+ "qr.js",
45
+ "cordis.patch.yml",
46
+ "locale/*.json",
47
+ "icon.svg",
48
+ "vendor/qrcode.js",
49
+ "vendor/LICENSE",
50
+ "mobile/index.html",
51
+ "mobile/app.js",
52
+ "mobile/styles.css",
53
+ "mobile/manifest.webmanifest",
54
+ "mobile/sw.js",
55
+ "mobile/favicon.svg",
56
+ "mobile/icons/*.png",
57
+ "mobile/mock-server.js",
58
+ "mobile/README.md",
59
+ "README.md",
60
+ "PROTOCOL.md",
61
+ "SECURITY.md",
62
+ "LICENSE",
63
+ "docs/*.md",
64
+ "docs/screenshots/*.png"
65
+ ],
66
+ "dsh": {
67
+ "bundle": {
68
+ "patch": "./cordis.patch.yml"
69
+ },
70
+ "client": {
71
+ "platform": "web",
72
+ "immediately": true,
73
+ "inject": ["@deepseek-ai/dsh-client-ui-conversation"]
74
+ }
75
+ }
76
+ }