@wherever-dev/client 0.7.0 → 0.8.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/CHANGELOG.md +19 -0
- package/dist/client.d.ts +93 -2
- package/dist/client.js +958 -63
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +68 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +1029 -63
- package/src/types.ts +94 -0
- package/test/chunked-upload.test.ts +483 -0
- package/test/harness.ts +38 -2
- package/test/hydration-seam.test.ts +400 -0
- package/test/liveness-probe.test.ts +183 -0
- package/test/upload-survives-reconnect.test.ts +482 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @wherever-dev/client
|
|
2
2
|
|
|
3
|
+
## 0.8.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 18696b8: Uploads over the WebSocket are now resumable and report real progress when the server supports it (`upload.v1`). The client sends the file as binary chunks, counts progress only from the server's acknowledgements, pauses on a dropped connection and, after the reconnect rejoins the session, continues from where the server got to instead of starting over. Cancelling an upload now tells the server to drop the partial file. Against an older server the client falls back to the previous single-frame upload, with the same limits as before (72 MB, three attempts). A file the phone can no longer read fails with "The file is no longer readable, pick it again".
|
|
8
|
+
|
|
9
|
+
Breaking for `@wherever-dev/client`: `uploadFileViaWebSocket(sessionId, filename, source, options)` now takes a byte source (`{size, read(offset, length)}`) instead of a base64 string, and gains `options.onProgress` and `options.mime`. The client also exposes `uploadsStore` (progress per upload id) and `forgetUpload(id)`. In the web app, `uploadFile()` accepts an `onProgress` callback that reports `{acked, size, state, error?}` for every upload method.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- bdafbcc: Client groundwork for showing a cached conversation instantly after a reload. `@wherever-dev/client` now exports `serverKey(config)` (a synchronous `host:port` plus token-hash identity) and `WhereverClient.hydrateCachedSession(snapshot)`, which paints a cached conversation before the socket is up and lets the normal reconnect rejoin replace it with the server's history. The store gains `serverKey` (the server that actually delivered the active session) and `historyAuthoritative` (gates `loadMoreHistory()` until the real history has arrived). A reconnect after the host, port or token were edited no longer preserves or rejoins the previous server's session. When the server refuses the load of a hydrated session outright, the client clears it and emits a synthesized `hydration_rejected` event to `onMessage` listeners. `resume()` no longer arms a load watchdog that was immediately cleared.
|
|
14
|
+
- 338a3c0: Returning to the app after the file picker, the camera or a short app switch no longer tears down a healthy connection and resyncs the session. The client's liveness watchdog now treats a silent socket as suspect, not dead: it sends a ping and waits a 5 s grace period, and only reconnects if nothing at all arrives. The page also probes the socket on every return to visibility (`client.noteVisible()`), and a detected freeze (a wall-clock jump between watchdog ticks) triggers the same probe. A genuinely dead socket is still torn down and reconnected, about 5 s later than before.
|
|
15
|
+
- 3da6573: Mobile resilience fixes for loading sessions, reconnecting and uploading files:
|
|
16
|
+
- Opening a session no longer flashes "New Session Started" while its history is still arriving. A "Loading conversation..." spinner is shown until the history lands.
|
|
17
|
+
- While disconnected or resyncing, the composer stays editable: you can keep reading, typing and attaching. Only sending (Send/Steer, Enter, dictation auto-send) waits for the connection and the resync.
|
|
18
|
+
- A WebSocket file upload is no longer tied to the socket it started on. If the socket drops (e.g. the file picker or camera backgrounds the page on mobile), the upload waits and is sent again automatically once the session has rejoined (after the server re-applies its read-only verdict). The chip shows "waiting for connection" in the meantime. Uploads always settle: they used to hang forever, leaving Send disabled. They now complete, fail, or time out after 10 minutes of waiting for a connection (time spent actually transferring does not count).
|
|
19
|
+
- Removing an attachment chip cancels its pending upload, and no longer updates the wrong chip.
|
|
20
|
+
- Uploads that waited for an unreachable server now time out after 10 minutes as intended (the clock used to restart on every reconnect attempt). An upload whose connection drops during the transfer on 3 consecutive attempts now fails with a clear message instead of retrying forever, and files too large for a single WebSocket frame (over 72 MB) are refused before being read.
|
|
21
|
+
|
|
3
22
|
## 0.7.0
|
|
4
23
|
|
|
5
24
|
### Minor Changes
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Writable } from "sveltore";
|
|
2
|
-
import { type WhereverState } from "./types.js";
|
|
2
|
+
import { type HydrationSnapshot, type UploadByteSource, type UploadOptions, type UploadProgress, type WhereverState } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Per-send options for a user message.
|
|
5
5
|
*
|
|
@@ -23,6 +23,23 @@ export interface WhereverClientConfig {
|
|
|
23
23
|
clientKey?: string;
|
|
24
24
|
onClientKeyChange?: (key: string) => void;
|
|
25
25
|
}
|
|
26
|
+
/** The capability a server advertises in `connected` for chunked uploads. */
|
|
27
|
+
export declare const UPLOAD_CAPABILITY = "upload.v1";
|
|
28
|
+
/** `[u8 kind=1][u8 version=1][u8 idLen][uploadId ascii][u64 offset BE][payload]` */
|
|
29
|
+
export declare function encodeChunkFrame(uploadId: string, offset: number, payload: Uint8Array): Uint8Array;
|
|
30
|
+
/**
|
|
31
|
+
* The identity of the server a config points at: `host:port#<fnv1a(token)>`.
|
|
32
|
+
* Two configured servers (or one server with a rotated token) never share a
|
|
33
|
+
* key, so the web's conversation cache can never show one server's
|
|
34
|
+
* conversation for another (ADR 0013).
|
|
35
|
+
*
|
|
36
|
+
* Synchronous and pure on purpose: `connect()` is synchronous and must compare
|
|
37
|
+
* it with the stamp before deciding whether to preserve the store, and
|
|
38
|
+
* `crypto.subtle` is both async and missing on plain-http LAN origins. The
|
|
39
|
+
* scheme (`secure`) is deliberately NOT part of the key: ws vs wss to the same
|
|
40
|
+
* host:port is the same server.
|
|
41
|
+
*/
|
|
42
|
+
export declare function serverKey(config: Pick<WhereverClientConfig, 'host' | 'port' | 'token'>): string;
|
|
26
43
|
export declare class WhereverClient {
|
|
27
44
|
private ws;
|
|
28
45
|
private config;
|
|
@@ -45,13 +62,25 @@ export declare class WhereverClient {
|
|
|
45
62
|
private static readonly STALE_SOCKET_MS;
|
|
46
63
|
private static readonly TURN_STALL_MS;
|
|
47
64
|
private static readonly HEARTBEAT_MS;
|
|
65
|
+
private static readonly PROBE_GRACE_MS;
|
|
66
|
+
private probeTimer;
|
|
67
|
+
private lastLivenessTickAt;
|
|
48
68
|
private isInitialConnect;
|
|
49
69
|
private resumeSessionFile;
|
|
50
70
|
private resumeCwd?;
|
|
51
71
|
private resumeModel?;
|
|
52
72
|
private pendingLoadFile;
|
|
73
|
+
private socketServerKey;
|
|
74
|
+
private hydratedFile;
|
|
53
75
|
private listeners;
|
|
54
76
|
private pendingUploads;
|
|
77
|
+
uploadsStore: Writable<Record<string, UploadProgress>>;
|
|
78
|
+
private socketCapabilities;
|
|
79
|
+
private static readonly MAX_UPLOAD_SENDS;
|
|
80
|
+
private static readonly MAX_UPLOAD_BASE64_CHARS;
|
|
81
|
+
private static readonly MAX_LEGACY_UPLOAD_BYTES;
|
|
82
|
+
private static readonly UPLOAD_TIMEOUT_MS;
|
|
83
|
+
private uploadsHeldForRejoin;
|
|
55
84
|
private confirmTimers;
|
|
56
85
|
private static readonly CONFIRM_MS;
|
|
57
86
|
private static readonly PENDING_PREFIX;
|
|
@@ -63,6 +92,10 @@ export declare class WhereverClient {
|
|
|
63
92
|
hasSuspendedSession(): boolean;
|
|
64
93
|
hasActiveSession(): boolean;
|
|
65
94
|
private startLivenessWatchdog;
|
|
95
|
+
noteVisible(): void;
|
|
96
|
+
private startLivenessProbe;
|
|
97
|
+
private cancelLivenessProbe;
|
|
98
|
+
private tearDownStaleSocket;
|
|
66
99
|
private stopLivenessWatchdog;
|
|
67
100
|
private armLoadWatchdog;
|
|
68
101
|
private clearLoadWatchdog;
|
|
@@ -119,6 +152,25 @@ export declare class WhereverClient {
|
|
|
119
152
|
* -- the one still in flight when the user switched sessions.
|
|
120
153
|
*/
|
|
121
154
|
private withRestore;
|
|
155
|
+
/**
|
|
156
|
+
* Paint a conversation from the web's on-device cache before the socket is up
|
|
157
|
+
* (ADR 0013), so a reload after the OS killed the PWA shows it at once. Call
|
|
158
|
+
* it, then `connect(cfg, true)`: onOpen's normal rejoin issues the
|
|
159
|
+
* `session_load` and its `message_history` replaces the cached messages.
|
|
160
|
+
*
|
|
161
|
+
* A no-op unless the client holds nothing that could be clobbered: no active
|
|
162
|
+
* session, no load in flight, not connected. The painted session is
|
|
163
|
+
* `resyncing` (sending blocked) and NOT `historyAuthoritative`. `agentPending`,
|
|
164
|
+
* `folderConflict`, `sudoPrompt` and `readOnly` stay at their defaults: they
|
|
165
|
+
* are verdicts the server re-states on the rejoin. `pendingLoadFile` is NOT
|
|
166
|
+
* set here (the rejoin sets it when it actually sends the load).
|
|
167
|
+
*
|
|
168
|
+
* Delivery-tagged user messages in the snapshot are dropped: undelivered
|
|
169
|
+
* outbound messages are recovered only from localStorage on the history
|
|
170
|
+
* reply (`loadPersistedPending`), so a cached copy would double-surface them.
|
|
171
|
+
*/
|
|
172
|
+
hydrateCachedSession(snapshot: HydrationSnapshot): void;
|
|
173
|
+
private rejectHydration;
|
|
122
174
|
joinSession(sessionFile: string, cwd?: string, model?: string): void;
|
|
123
175
|
switchSession(sessionFile: string, cwd?: string, model?: string): void;
|
|
124
176
|
forkSession(sessionId: string, entryId: string): boolean;
|
|
@@ -160,10 +212,49 @@ export declare class WhereverClient {
|
|
|
160
212
|
changeModel(model: string): void;
|
|
161
213
|
setConfig(updates: Partial<WhereverClientConfig>): void;
|
|
162
214
|
onMessage(cb: (msg: any) => void): () => void;
|
|
163
|
-
|
|
215
|
+
/**
|
|
216
|
+
* Upload a file over the WebSocket. Resolves with the server's saved path;
|
|
217
|
+
* rejects on failure (an `Error`, with `code: 'not_readable'` when the byte
|
|
218
|
+
* source can no longer be read) or with "Upload cancelled" when
|
|
219
|
+
* `options.signal` aborts. Progress (`{acked, size, state, error?}`) goes to
|
|
220
|
+
* `options.onProgress` and to `uploadsStore`.
|
|
221
|
+
*
|
|
222
|
+
* The protocol is chosen when the upload is SENT, from that socket's
|
|
223
|
+
* `connected.capabilities`: chunked (`upload.v1`) when advertised, else the
|
|
224
|
+
* legacy base64 `file_upload` frame (see PendingUpload). The legacy path
|
|
225
|
+
* refuses files over 72 MiB from `source.size`, before reading anything.
|
|
226
|
+
*/
|
|
227
|
+
uploadFileViaWebSocket(sessionId: string, filename: string, source: UploadByteSource, options?: UploadOptions): Promise<{
|
|
164
228
|
savedPath: string;
|
|
165
229
|
filename: string;
|
|
166
230
|
}>;
|
|
231
|
+
pendingUploadCount(): number;
|
|
232
|
+
/** Drop a SETTLED upload's entry from uploadsStore (in-flight ones stay). */
|
|
233
|
+
forgetUpload(uploadId: string): void;
|
|
234
|
+
private trySendUpload;
|
|
235
|
+
private sendLegacyUpload;
|
|
236
|
+
private prepareLegacyFrame;
|
|
237
|
+
private readLegacyBase64;
|
|
238
|
+
private beginChunkedUpload;
|
|
239
|
+
private handleUploadOffset;
|
|
240
|
+
private uploadWindow;
|
|
241
|
+
private pumpUpload;
|
|
242
|
+
private sendBinary;
|
|
243
|
+
private reportUpload;
|
|
244
|
+
private completeUpload;
|
|
245
|
+
private failUpload;
|
|
246
|
+
private abortUpload;
|
|
247
|
+
private isUploadOnWire;
|
|
248
|
+
private uploadsLostSocket;
|
|
249
|
+
private failUnsentUploads;
|
|
250
|
+
private failHeldUploads;
|
|
251
|
+
private abandonUnsentUploads;
|
|
252
|
+
private ensureUploadTimer;
|
|
253
|
+
private stopUploadTimer;
|
|
254
|
+
private armUploadTimer;
|
|
255
|
+
private takePendingUpload;
|
|
256
|
+
private resendPendingUploads;
|
|
257
|
+
private rejectPendingUploads;
|
|
167
258
|
private generateId;
|
|
168
259
|
getIsConnected(): any;
|
|
169
260
|
}
|