@wonderwhy-er/desktop-commander 0.2.51 → 0.3.0
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 +14 -24
- package/dist/command-manager.d.ts +7 -2
- package/dist/command-manager.js +16 -11
- package/dist/config-manager.d.ts +55 -3
- package/dist/config-manager.js +329 -87
- package/dist/config-recovery.d.ts +28 -0
- package/dist/config-recovery.js +81 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +9 -0
- package/dist/handlers/filesystem-handlers.d.ts +1 -1
- package/dist/handlers/filesystem-handlers.js +26 -16
- package/dist/handlers/search-answers.d.ts +58 -0
- package/dist/handlers/search-answers.js +172 -0
- package/dist/handlers/search-handlers.js +4 -92
- package/dist/index.js +14 -7
- package/dist/npm-scripts/remote.js +47 -4
- package/dist/remote-device/desktop-commander-integration.d.ts +21 -0
- package/dist/remote-device/desktop-commander-integration.js +121 -40
- package/dist/remote-device/device-authenticator.d.ts +13 -1
- package/dist/remote-device/device-authenticator.js +87 -47
- package/dist/remote-device/device.d.ts +14 -0
- package/dist/remote-device/device.js +244 -51
- package/dist/remote-device/diagnostics/device-log.d.ts +63 -0
- package/dist/remote-device/diagnostics/device-log.js +219 -0
- package/dist/remote-device/diagnostics/redact.d.ts +1 -0
- package/dist/remote-device/diagnostics/redact.js +76 -0
- package/dist/remote-device/diagnostics/report.d.ts +118 -0
- package/dist/remote-device/diagnostics/report.js +748 -0
- package/dist/remote-device/diagnostics/upload.d.ts +11 -0
- package/dist/remote-device/diagnostics/upload.js +59 -0
- package/dist/remote-device/realtime-health-telemetry.d.ts +35 -0
- package/dist/remote-device/realtime-health-telemetry.js +110 -0
- package/dist/remote-device/remote-channel.d.ts +86 -5
- package/dist/remote-device/remote-channel.js +470 -68
- package/dist/remote-device/scripts/blocking-offline-update.js +108 -69
- package/dist/remote-device/transport-telemetry.d.ts +32 -0
- package/dist/remote-device/transport-telemetry.js +48 -0
- package/dist/search-manager.d.ts +239 -27
- package/dist/search-manager.js +746 -312
- package/dist/server.js +157 -303
- package/dist/terminal-manager.d.ts +138 -21
- package/dist/terminal-manager.js +300 -215
- package/dist/tools/config.d.ts +1 -1
- package/dist/tools/config.js +21 -70
- package/dist/tools/edit.js +12 -4
- package/dist/tools/filesystem.d.ts +30 -6
- package/dist/tools/filesystem.js +246 -140
- package/dist/tools/improved-process-tools.d.ts +9 -3
- package/dist/tools/improved-process-tools.js +171 -68
- package/dist/tools/pdf/extract-images.d.ts +2 -0
- package/dist/tools/pdf/extract-images.js +4 -1
- package/dist/tools/pdf/index.d.ts +5 -3
- package/dist/tools/pdf/index.js +4 -3
- package/dist/tools/pdf/lib/pdf2md.d.ts +8 -1
- package/dist/tools/pdf/lib/pdf2md.js +12 -5
- package/dist/tools/pdf/manipulations.d.ts +12 -1
- package/dist/tools/pdf/manipulations.js +17 -4
- package/dist/tools/pdf/markdown.d.ts +96 -0
- package/dist/tools/pdf/markdown.js +485 -20
- package/dist/tools/pdf/utils.d.ts +2 -2
- package/dist/tools/pdf/utils.js +4 -4
- package/dist/tools/process.js +8 -5
- package/dist/tools/schemas.d.ts +1 -11
- package/dist/tools/schemas.js +15 -14
- package/dist/types.d.ts +1 -1
- package/dist/ui/config-editor/config-editor-runtime.js +53 -53
- package/dist/ui/config-editor/src/app.js +2 -15
- package/dist/ui/file-preview/preview-runtime.js +190 -182
- package/dist/utils/ab-test.js +27 -9
- package/dist/utils/atomic-write.d.ts +14 -0
- package/dist/utils/atomic-write.js +80 -0
- package/dist/utils/capture.d.ts +17 -1
- package/dist/utils/capture.js +177 -68
- package/dist/utils/exit-process.d.ts +24 -0
- package/dist/utils/exit-process.js +31 -0
- package/dist/utils/feature-flags.js +2 -1
- package/dist/utils/files/base.d.ts +3 -1
- package/dist/utils/files/docx.d.ts +3 -0
- package/dist/utils/files/docx.js +24 -9
- package/dist/utils/files/excel.d.ts +10 -0
- package/dist/utils/files/excel.js +93 -33
- package/dist/utils/files/factory.d.ts +22 -1
- package/dist/utils/files/factory.js +59 -4
- package/dist/utils/files/image.d.ts +12 -4
- package/dist/utils/files/image.js +19 -8
- package/dist/utils/files/index.d.ts +5 -3
- package/dist/utils/files/index.js +4 -3
- package/dist/utils/files/pdf.js +18 -36
- package/dist/utils/files/text.d.ts +21 -5
- package/dist/utils/files/text.js +90 -86
- package/dist/utils/internal-facts.d.ts +3 -0
- package/dist/utils/internal-facts.js +23 -0
- package/dist/utils/lazy-package.d.ts +25 -0
- package/dist/utils/lazy-package.js +44 -0
- package/dist/utils/open-browser.js +2 -1
- package/dist/utils/process-detection.d.ts +24 -5
- package/dist/utils/process-detection.js +199 -89
- package/dist/utils/process-tree.d.ts +14 -0
- package/dist/utils/process-tree.js +223 -0
- package/dist/utils/rename.d.ts +9 -0
- package/dist/utils/rename.js +74 -0
- package/dist/utils/ripgrep-resolver.js +9 -14
- package/dist/utils/shell.d.ts +42 -0
- package/dist/utils/shell.js +187 -0
- package/dist/utils/system-info.d.ts +1 -0
- package/dist/utils/system-info.js +40 -25
- package/dist/utils/trackTools.js +2 -1
- package/dist/utils/usageTracker.d.ts +0 -39
- package/dist/utils/usageTracker.js +1 -161
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -0
- package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -0
- package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +38 -0
- package/node_modules/@desktop-commander/telemetry-contract/transport.js +164 -0
- package/package.json +32 -16
- package/vendor/telemetry-contract/README.md +56 -0
- package/vendor/telemetry-contract/package.json +32 -0
- package/vendor/telemetry-contract/transport.d.ts +38 -0
- package/vendor/telemetry-contract/transport.js +164 -0
- package/vendor/telemetry-contract/transport.test.js +39 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The signed-in user's id from ~/.desktop-commander-device/device.json, or null. */
|
|
2
|
+
export declare function savedUserId(home: string): string | null;
|
|
3
|
+
export interface UploadOptions {
|
|
4
|
+
/** From /api/mcp-info; null when the server names none, and then nothing is uploaded. */
|
|
5
|
+
diagnosticsUrl: string | null;
|
|
6
|
+
userId: string | null;
|
|
7
|
+
deviceId: string | null;
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/** POSTs the zip and resolves the report id; rejects with a short reason. */
|
|
11
|
+
export declare function uploadReport(zip: Buffer, options: UploadOptions): Promise<string>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* Sends the diagnostics zip to Desktop Commander's diagnostics Worker, which
|
|
5
|
+
* stores it for 7 days and answers with a report id the user gives support.
|
|
6
|
+
*
|
|
7
|
+
* The address comes only from the server's /api/mcp-info `diagnosticsUrl`, so
|
|
8
|
+
* the Worker can move without a release. When the server names none, nothing
|
|
9
|
+
* is uploaded and the zip stays saved.
|
|
10
|
+
* The ids only sort the upload into a folder: the user id is the saved access
|
|
11
|
+
* token's `sub`, read locally like blocking-offline-update.js reads `exp`, and
|
|
12
|
+
* the device id is device.json's. Nothing is refreshed, nothing signs in, and
|
|
13
|
+
* device.json is only read.
|
|
14
|
+
*/
|
|
15
|
+
const UPLOAD_TIMEOUT_MS = 30000;
|
|
16
|
+
const ID_SHAPED = /^[A-Za-z0-9_-]{1,64}$/;
|
|
17
|
+
/** The longest piece of the Worker's error message that is shown. */
|
|
18
|
+
const MAX_MESSAGE_CHARS = 200;
|
|
19
|
+
/** The signed-in user's id from ~/.desktop-commander-device/device.json, or null. */
|
|
20
|
+
export function savedUserId(home) {
|
|
21
|
+
try {
|
|
22
|
+
const config = JSON.parse(fs.readFileSync(path.join(home, '.desktop-commander-device', 'device.json'), 'utf8'));
|
|
23
|
+
const token = config?.session?.access_token;
|
|
24
|
+
if (typeof token !== 'string')
|
|
25
|
+
return null;
|
|
26
|
+
const { sub } = JSON.parse(Buffer.from(token.split('.')[1] ?? '', 'base64url').toString('utf8'));
|
|
27
|
+
return typeof sub === 'string' && ID_SHAPED.test(sub) ? sub : null;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** POSTs the zip and resolves the report id; rejects with a short reason. */
|
|
34
|
+
export async function uploadReport(zip, options) {
|
|
35
|
+
const url = options.diagnosticsUrl;
|
|
36
|
+
if (!url)
|
|
37
|
+
throw new Error('the server named no upload address');
|
|
38
|
+
const headers = { 'Content-Type': 'application/zip' };
|
|
39
|
+
if (options.userId)
|
|
40
|
+
headers['X-DC-User-Id'] = options.userId;
|
|
41
|
+
if (options.deviceId)
|
|
42
|
+
headers['X-DC-Device-Id'] = options.deviceId;
|
|
43
|
+
const response = await fetch(url, {
|
|
44
|
+
method: 'POST',
|
|
45
|
+
headers,
|
|
46
|
+
body: new Uint8Array(zip),
|
|
47
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? UPLOAD_TIMEOUT_MS),
|
|
48
|
+
});
|
|
49
|
+
const body = await response.json().catch(() => null);
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
// The Worker answers errors as {code, message}: show its message, on one short line
|
|
52
|
+
const message = typeof body?.message === 'string' ? body.message.replace(/\s+/g, ' ').trim().slice(0, MAX_MESSAGE_CHARS) : '';
|
|
53
|
+
throw new Error(`the server answered ${response.status}${message ? `: ${message}` : ''}`);
|
|
54
|
+
}
|
|
55
|
+
const id = body?.id;
|
|
56
|
+
if (typeof id !== 'string' || !ID_SHAPED.test(id))
|
|
57
|
+
throw new Error('the server gave no report id');
|
|
58
|
+
return id;
|
|
59
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type RealtimeCounter = 'explicit_subscribe_calls' | 'join_successes' | 'join_errors' | 'join_timeouts' | 'join_closures' | 'watchdog_recreates' | 'socket_disconnects' | 'presence_attempts' | 'presence_successes' | 'presence_failures' | 'readiness_write_failures';
|
|
2
|
+
export type RealtimeWindow = Record<RealtimeCounter, number> & {
|
|
3
|
+
event_version: number;
|
|
4
|
+
device_diag_id: string;
|
|
5
|
+
process_session_id: string;
|
|
6
|
+
channel_generation: number;
|
|
7
|
+
window_start: string;
|
|
8
|
+
window_seconds: number;
|
|
9
|
+
app_version: string;
|
|
10
|
+
platform: string;
|
|
11
|
+
};
|
|
12
|
+
export declare class RealtimeHealthTelemetry {
|
|
13
|
+
private readonly emit;
|
|
14
|
+
private readonly sample;
|
|
15
|
+
private readonly random;
|
|
16
|
+
readonly processSessionId: `${string}-${string}-${string}-${string}-${string}`;
|
|
17
|
+
private deviceDiagId;
|
|
18
|
+
private generation;
|
|
19
|
+
private counts;
|
|
20
|
+
private windowStart;
|
|
21
|
+
private windowStartMonotonic;
|
|
22
|
+
private socketState;
|
|
23
|
+
private timer;
|
|
24
|
+
constructor(emit: (window: RealtimeWindow) => void, sample?: (key: string) => number, random?: () => number);
|
|
25
|
+
private emptyCounts;
|
|
26
|
+
/** Stable for one registered device, unlinkable to its raw UUID without knowing the UUID. */
|
|
27
|
+
setDevice(deviceId: string): void;
|
|
28
|
+
newChannel(): void;
|
|
29
|
+
record(key: RealtimeCounter): void;
|
|
30
|
+
observeSocketState(state: string): void;
|
|
31
|
+
start(): void;
|
|
32
|
+
private schedule;
|
|
33
|
+
flush(now?: number, monotonicNow?: number): RealtimeWindow | null;
|
|
34
|
+
stop(): void;
|
|
35
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-volume Realtime lifecycle counters. No per-retry HTTP requests.
|
|
3
|
+
* Counts are local observations, NOT exact Phoenix phx_join wire frames.
|
|
4
|
+
*/
|
|
5
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
6
|
+
import { VERSION } from '../version.js';
|
|
7
|
+
const COUNTERS = [
|
|
8
|
+
'explicit_subscribe_calls', 'join_successes', 'join_errors',
|
|
9
|
+
'join_timeouts', 'join_closures', 'watchdog_recreates',
|
|
10
|
+
'socket_disconnects', 'presence_attempts', 'presence_successes',
|
|
11
|
+
'presence_failures', 'readiness_write_failures',
|
|
12
|
+
];
|
|
13
|
+
const DEGRADED = [
|
|
14
|
+
'join_errors', 'join_timeouts', 'join_closures', 'watchdog_recreates',
|
|
15
|
+
'socket_disconnects', 'presence_failures', 'readiness_write_failures',
|
|
16
|
+
];
|
|
17
|
+
export class RealtimeHealthTelemetry {
|
|
18
|
+
constructor(emit, sample = (key) => parseInt(createHash('sha256').update(key).digest('hex').slice(0, 8), 16) / 0x100000000, random = Math.random) {
|
|
19
|
+
this.emit = emit;
|
|
20
|
+
this.sample = sample;
|
|
21
|
+
this.random = random;
|
|
22
|
+
this.processSessionId = randomUUID();
|
|
23
|
+
this.deviceDiagId = '';
|
|
24
|
+
this.generation = 0;
|
|
25
|
+
this.counts = this.emptyCounts();
|
|
26
|
+
this.windowStart = Date.now();
|
|
27
|
+
this.windowStartMonotonic = performance.now();
|
|
28
|
+
this.socketState = null;
|
|
29
|
+
this.timer = null;
|
|
30
|
+
}
|
|
31
|
+
emptyCounts() {
|
|
32
|
+
return Object.fromEntries(COUNTERS.map((key) => [key, 0]));
|
|
33
|
+
}
|
|
34
|
+
/** Stable for one registered device, unlinkable to its raw UUID without knowing the UUID. */
|
|
35
|
+
setDevice(deviceId) {
|
|
36
|
+
if (!deviceId)
|
|
37
|
+
return;
|
|
38
|
+
const id = createHash('sha256').update('dc-realtime-diagnostics-v1:').update(deviceId).digest('hex').slice(0, 32);
|
|
39
|
+
if (this.deviceDiagId === id)
|
|
40
|
+
return;
|
|
41
|
+
this.deviceDiagId = id;
|
|
42
|
+
this.windowStart = Date.now();
|
|
43
|
+
this.windowStartMonotonic = performance.now();
|
|
44
|
+
this.counts = this.emptyCounts();
|
|
45
|
+
}
|
|
46
|
+
newChannel() {
|
|
47
|
+
this.generation++;
|
|
48
|
+
this.record('explicit_subscribe_calls');
|
|
49
|
+
}
|
|
50
|
+
record(key) {
|
|
51
|
+
this.counts[key]++;
|
|
52
|
+
}
|
|
53
|
+
observeSocketState(state) {
|
|
54
|
+
if (this.socketState === 'open' && state !== 'open')
|
|
55
|
+
this.record('socket_disconnects');
|
|
56
|
+
this.socketState = state;
|
|
57
|
+
}
|
|
58
|
+
start() {
|
|
59
|
+
if (this.timer)
|
|
60
|
+
return;
|
|
61
|
+
this.schedule();
|
|
62
|
+
}
|
|
63
|
+
schedule() {
|
|
64
|
+
// Each device chooses a different reporting boundary; never a fleet-wide minute mark.
|
|
65
|
+
this.timer = setTimeout(() => {
|
|
66
|
+
this.timer = null;
|
|
67
|
+
this.flush();
|
|
68
|
+
this.schedule();
|
|
69
|
+
}, 60000 + Math.floor(this.random() * 30000));
|
|
70
|
+
this.timer.unref?.();
|
|
71
|
+
}
|
|
72
|
+
flush(now = Date.now(), monotonicNow = performance.now()) {
|
|
73
|
+
// Wall time may jump when observeServerDate() corrects clock skew.
|
|
74
|
+
// Use only monotonic time for durations; wall time still locates the window.
|
|
75
|
+
const elapsed = Math.max(1, Math.round((monotonicNow - this.windowStartMonotonic) / 1000));
|
|
76
|
+
const counts = this.counts;
|
|
77
|
+
const start = this.windowStart;
|
|
78
|
+
this.counts = this.emptyCounts();
|
|
79
|
+
this.windowStart = now;
|
|
80
|
+
this.windowStartMonotonic = monotonicNow;
|
|
81
|
+
if (!this.deviceDiagId)
|
|
82
|
+
return null;
|
|
83
|
+
const degraded = DEGRADED.some((key) => counts[key] > 0);
|
|
84
|
+
const sampleRate = degraded ? 0.05 : 0.01;
|
|
85
|
+
if (this.sample(this.deviceDiagId) >= sampleRate)
|
|
86
|
+
return null;
|
|
87
|
+
const window = {
|
|
88
|
+
...counts,
|
|
89
|
+
event_version: 1,
|
|
90
|
+
device_diag_id: this.deviceDiagId,
|
|
91
|
+
process_session_id: this.processSessionId,
|
|
92
|
+
channel_generation: this.generation,
|
|
93
|
+
window_start: new Date(start).toISOString(),
|
|
94
|
+
window_seconds: elapsed,
|
|
95
|
+
app_version: VERSION,
|
|
96
|
+
platform: process.platform,
|
|
97
|
+
};
|
|
98
|
+
try {
|
|
99
|
+
this.emit(window);
|
|
100
|
+
}
|
|
101
|
+
catch { /* diagnostics must not affect transport */ }
|
|
102
|
+
return window;
|
|
103
|
+
}
|
|
104
|
+
stop() {
|
|
105
|
+
if (this.timer)
|
|
106
|
+
clearTimeout(this.timer);
|
|
107
|
+
this.timer = null;
|
|
108
|
+
this.flush();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -10,6 +10,16 @@ export interface AuthSession {
|
|
|
10
10
|
refresh_token: string | null;
|
|
11
11
|
device_id?: string;
|
|
12
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* The device registered, but its realtime channel is not usable — the join
|
|
15
|
+
* failed, or presence was never acknowledged. Distinct from every other
|
|
16
|
+
* registration failure on purpose: this one the socket watchdog can repair, so
|
|
17
|
+
* the caller keeps the process alive, while a failed lookup or a missing row
|
|
18
|
+
* happens before the recreation parameters are stored and nothing can repair it.
|
|
19
|
+
*/
|
|
20
|
+
export declare class ChannelUnreachableError extends Error {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
13
23
|
interface DeviceData {
|
|
14
24
|
user_id: string;
|
|
15
25
|
device_name: string;
|
|
@@ -17,6 +27,15 @@ interface DeviceData {
|
|
|
17
27
|
status: string;
|
|
18
28
|
last_seen: string;
|
|
19
29
|
}
|
|
30
|
+
/** Exponential-ish SDK backoff. Attempts 1-4 preserve short recovery latency. */
|
|
31
|
+
export declare function realtimeReconnectDelayMs(tries: number, random?: () => number): number;
|
|
32
|
+
/** Watchdog must not defeat the SDK's slower persistent-failure backoff. */
|
|
33
|
+
export declare function watchdogRecreateDelayMs(tries: number, random?: () => number): number;
|
|
34
|
+
/** Preserve short in-batch Presence retries, independently jittered. */
|
|
35
|
+
export declare function presenceRetryDelayMs(failedAttempt: number, random?: () => number): number;
|
|
36
|
+
/** Delay new Presence batches after repeated failed batches, even across SDK rejoins.
|
|
37
|
+
* This is intentionally independent of the Phoenix channel/socket reconnect timer. */
|
|
38
|
+
export declare function presenceRecoveryDelayMs(failures: number, random?: () => number): number;
|
|
20
39
|
export declare function observeServerDate(dateHeader: string | null): void;
|
|
21
40
|
export declare class RemoteChannel {
|
|
22
41
|
private client;
|
|
@@ -26,6 +45,12 @@ export declare class RemoteChannel {
|
|
|
26
45
|
/** Device the heartbeat timer maintains; null = stopped, so re-arm is inert. */
|
|
27
46
|
private heartbeatDeviceId;
|
|
28
47
|
private statusWriteChain;
|
|
48
|
+
/**
|
|
49
|
+
* Answers whether the local execution child is alive. Default yes, so a
|
|
50
|
+
* RemoteChannel used without a device (tests, other callers) behaves as
|
|
51
|
+
* before; MCPDevice installs the real probe.
|
|
52
|
+
*/
|
|
53
|
+
private localExecutorProbe;
|
|
29
54
|
/** Tokens from the last setSession / TOKEN_REFRESHED, for setOffline(). */
|
|
30
55
|
private lastKnownSession;
|
|
31
56
|
/** Notified when auth-js rotates the session; the device persists it. */
|
|
@@ -45,9 +70,23 @@ export declare class RemoteChannel {
|
|
|
45
70
|
private presenceTracked;
|
|
46
71
|
/** Last capability value written (null = never), to avoid redundant writes. */
|
|
47
72
|
private transportCapableWritten;
|
|
73
|
+
/** Value of the last capability write still queued or in flight; null once the queue is idle. */
|
|
74
|
+
private transportCapableQueued;
|
|
75
|
+
private capabilityWriteChain;
|
|
76
|
+
/** Monotonic start of a Presence-only degradation while broadcast remains joined. */
|
|
77
|
+
private presenceFailureStartedAt;
|
|
48
78
|
/** Re-entrancy guard: on a wedged socket each track() buffers for the full
|
|
49
79
|
* 10s push timeout, so 10s health ticks would stack pushes. */
|
|
50
80
|
private isTrackingPresence;
|
|
81
|
+
private consecutiveUnreadyJoins;
|
|
82
|
+
private consecutivePresenceFailures;
|
|
83
|
+
private nextPresenceAttemptAt;
|
|
84
|
+
/** performance.now() of the latest SUBSCRIBED; null while not joined. */
|
|
85
|
+
private joinedAt;
|
|
86
|
+
/** SDK channel and socket timers share reconnectAfterMs. The persistent
|
|
87
|
+
* unready-join budget prevents a series of partial successes restarting at 1s. */
|
|
88
|
+
private reconnectDelayMs;
|
|
89
|
+
private readonly realtimeHealth;
|
|
51
90
|
private lastDeviceStatus;
|
|
52
91
|
private lastChannelState;
|
|
53
92
|
private reconnectAttempt;
|
|
@@ -65,6 +104,12 @@ export declare class RemoteChannel {
|
|
|
65
104
|
private _user;
|
|
66
105
|
get user(): User | null;
|
|
67
106
|
initialize(url: string, key: string): void;
|
|
107
|
+
/**
|
|
108
|
+
* Teach the channel how to ask whether the local executor is alive.
|
|
109
|
+
* `status` is a claim that this device will run a tool call right now, and
|
|
110
|
+
* a joined channel alone cannot support that claim - issue #4.
|
|
111
|
+
*/
|
|
112
|
+
setLocalExecutorProbe(probe: () => boolean): void;
|
|
68
113
|
/**
|
|
69
114
|
* Register a callback fired when auth-js rotates the session. auth-js
|
|
70
115
|
* rotates the refresh token on every refresh and the previous one is spent,
|
|
@@ -108,6 +153,11 @@ export declare class RemoteChannel {
|
|
|
108
153
|
* dashboard. `presenceTracked` lets the health check retry later.
|
|
109
154
|
*/
|
|
110
155
|
private trackPresenceWithRetry;
|
|
156
|
+
/** One failed Presence batch: grow the Presence-only cooldown. Deadlines are
|
|
157
|
+
* monotonic so a Date.now skew correction cannot shorten or extend them. */
|
|
158
|
+
private recordPresenceBatchFailure;
|
|
159
|
+
/** Presence is withheld by its cooldown right now. */
|
|
160
|
+
private presenceInCooldown;
|
|
111
161
|
private trackPresenceInner;
|
|
112
162
|
/**
|
|
113
163
|
* The complete `capabilities` JSONB value. One place only: every write
|
|
@@ -118,10 +168,28 @@ export declare class RemoteChannel {
|
|
|
118
168
|
* Advertise (or withdraw) the broadcast capability. Only true while genuinely
|
|
119
169
|
* reachable that way — the server fails dispatch fast without it and picks
|
|
120
170
|
* the offline-sweep tier from it, so every change must re-arm the heartbeat.
|
|
171
|
+
*
|
|
172
|
+
* Writes are queued, like the status writes. A withdrawal the recreate stops
|
|
173
|
+
* waiting for still lands: compared with the last landed value, a re-publish
|
|
174
|
+
* in the meantime looked redundant and was skipped, and the withdrawal then
|
|
175
|
+
* left a device that claims to be online without the flag. Resolves with
|
|
176
|
+
* whether the row holds `capable` once this write is done.
|
|
121
177
|
*/
|
|
122
178
|
private setTransportCapable;
|
|
179
|
+
private writeTransportCapable;
|
|
180
|
+
/** Aborts one write to this device's row after DEVICE_ROW_WRITE_TIMEOUT_MS (a method, so tests can shorten it). */
|
|
181
|
+
private deviceRowWriteSignal;
|
|
123
182
|
/** Create and subscribe the private channel (initial join and recreation). */
|
|
124
183
|
private createChannel;
|
|
184
|
+
/**
|
|
185
|
+
* Recover calls whose Realtime doorbell was missed while this device was
|
|
186
|
+
* disconnected. Broadcast provides the fast path; the DB row is the source
|
|
187
|
+
* of truth. Only still-live pending rows for this device are considered.
|
|
188
|
+
*
|
|
189
|
+
* The follow-up onDoorbell() call performs the existing conditional claim,
|
|
190
|
+
* which makes this safe against a doorbell arriving at the same time.
|
|
191
|
+
*/
|
|
192
|
+
private recoverPendingCalls;
|
|
125
193
|
/** Hand a call to device.ts, observing the rejection — the handler is async
|
|
126
194
|
* and an unhandled rejection terminates the process. */
|
|
127
195
|
private dispatchToolCall;
|
|
@@ -163,21 +231,33 @@ export declare class RemoteChannel {
|
|
|
163
231
|
* Claim a call. True only when THIS update flipped the row pending ->
|
|
164
232
|
* executing, which is what makes dual delivery safe across processes.
|
|
165
233
|
* .eq('status','pending') makes it conditional; .select('id') makes the
|
|
166
|
-
* result observable.
|
|
167
|
-
*
|
|
234
|
+
* result observable. Expiry is checked using Postgres time, not the
|
|
235
|
+
* device clock. On a transient DB error it returns true (execute anyway),
|
|
236
|
+
* matching prior behaviour — so device.ts's in-memory guard is what
|
|
168
237
|
* actually guarantees exactly-once within a process.
|
|
169
238
|
*/
|
|
170
239
|
markCallExecuting(callId: string): Promise<boolean>;
|
|
171
240
|
updateCallResult(callId: string, status: string, result?: any, errorMessage?: string | null): Promise<void>;
|
|
172
|
-
/**
|
|
241
|
+
/**
|
|
242
|
+
* Reachable means all of it is true at once: the private channel is
|
|
243
|
+
* joined, this device has published its presence, and the local executor
|
|
244
|
+
* answers. The server needs the first two before it will dispatch, and a
|
|
245
|
+
* healthy channel on a device whose executor is dead is the false-online
|
|
246
|
+
* state issue #4 was opened for. Gates the heartbeat and `status`.
|
|
247
|
+
*/
|
|
173
248
|
private isReachable;
|
|
174
249
|
/**
|
|
175
250
|
* Set `status` from actual reachability. `status` is transport-agnostic (the
|
|
176
251
|
* server filters on it), so it must not follow one channel's health — the
|
|
177
252
|
* private channel's error path re-fires on every rejoin and would oscillate
|
|
178
253
|
* the row against the heartbeat. Same predicate as the heartbeat gate.
|
|
254
|
+
*
|
|
255
|
+
* Every transition belongs here rather than calling setOnlineStatus(), which
|
|
256
|
+
* is the write and not the decision. Public so the device can route its
|
|
257
|
+
* recovery transition through the predicate too.
|
|
179
258
|
*/
|
|
180
|
-
|
|
259
|
+
/** Resolves with whether the row actually took the write. */
|
|
260
|
+
syncReachabilityStatus(): Promise<boolean>;
|
|
181
261
|
/**
|
|
182
262
|
* Serialize the channel-callback status writes. They fire from un-awaited
|
|
183
263
|
* callbacks, and inside recreateChannel() a teardown's 'offline' and the
|
|
@@ -202,7 +282,8 @@ export declare class RemoteChannel {
|
|
|
202
282
|
/** Arm (or re-arm) the last_seen timer at the current tier's cadence. */
|
|
203
283
|
private scheduleHeartbeat;
|
|
204
284
|
stopHeartbeat(): void;
|
|
205
|
-
|
|
285
|
+
/** @returns whether the row actually took the write. */
|
|
286
|
+
setOnlineStatus(deviceId: string, status: 'online' | 'offline'): Promise<boolean>;
|
|
206
287
|
setOffline(deviceId: string | undefined): Promise<void>;
|
|
207
288
|
unsubscribe(): Promise<void>;
|
|
208
289
|
}
|