@wherever-dev/client 0.9.0 → 0.10.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 +14 -0
- package/dist/client.d.ts +7 -0
- package/dist/client.js +215 -7
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +13 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +222 -7
- package/src/types.ts +23 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @wherever-dev/client
|
|
2
2
|
|
|
3
|
+
## 0.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 242c77a: The chat now shows what kenning delivered into a session. A session woken by a message from another session, or a spawned session receiving its owner's first prompt, used to show the agent replying to nothing; each delivery is now a card with its sender, an origin badge (agent, human, human-relayed), its kind, the message text, "First prompt from <owner>" for a spawn, and the full text the agent read one click away. They appear in history and live (a new `kenning_delivery` frame), and are never user messages: no fork point, no reply routing, never sent to Telegram. A client receives them only when it asks (`kenning=1` on the socket URL; `kenningCards: true` in `@wherever-dev/client`, which the web app sets), so older clients see nothing new.
|
|
8
|
+
|
|
9
|
+
While kenning's inbox holds questions for you, the tab title starts with "(N) " and the installed app shows N on its icon where the browser supports app badges. This needs no assistant; pushes for blocking questions still do.
|
|
10
|
+
|
|
11
|
+
## 0.9.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 58bb85d: Switching session while the previous one is still reconnecting no longer snaps back to it. Coming back to the PWA reconnects and rejoins the session that was open; if the user opened another session or created a new one before that finished, the rejoin landed afterwards and switched the view back. A switch is now the newer intent and cancels the rejoin: a session load or create requested while the socket is still opening is sent once it opens (instead of the rejoin, and it used to be lost), the late reply of an abandoned load is dropped (a create in flight used to accept it as its own), and the page no longer auto-joins a URL hash still naming the left session while a create is in flight or after leaving while disconnected.
|
|
16
|
+
|
|
3
17
|
## 0.9.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/dist/client.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface WhereverClientConfig {
|
|
|
23
23
|
clientKey?: string;
|
|
24
24
|
onClientKeyChange?: (key: string) => void;
|
|
25
25
|
imageRefs?: boolean;
|
|
26
|
+
kenningCards?: boolean;
|
|
26
27
|
}
|
|
27
28
|
/** The capability a server advertises in `connected` for chunked uploads. */
|
|
28
29
|
export declare const UPLOAD_CAPABILITY = "upload.v1";
|
|
@@ -75,6 +76,8 @@ export declare class WhereverClient {
|
|
|
75
76
|
private resumeCwd?;
|
|
76
77
|
private resumeModel?;
|
|
77
78
|
private pendingLoadFile;
|
|
79
|
+
private queuedSessionRequest;
|
|
80
|
+
private abandonedSessions;
|
|
78
81
|
private socketServerKey;
|
|
79
82
|
private hydratedFile;
|
|
80
83
|
private listeners;
|
|
@@ -121,6 +124,8 @@ export declare class WhereverClient {
|
|
|
121
124
|
* merely contains the word "aborted".
|
|
122
125
|
*/
|
|
123
126
|
private isAbortedToolResult;
|
|
127
|
+
/** The server's kenning `details`, read defensively (another version may lack a field). */
|
|
128
|
+
private kenningDetails;
|
|
124
129
|
/**
|
|
125
130
|
* Map a server `HistoryMessage[]` window into UI `ChatMessage[]`. When
|
|
126
131
|
* `applyStreamingTail` is true, the last assistant/thinking message and any
|
|
@@ -178,6 +183,8 @@ export declare class WhereverClient {
|
|
|
178
183
|
hydrateCachedSession(snapshot: HydrationSnapshot): void;
|
|
179
184
|
private rejectHydration;
|
|
180
185
|
joinSession(sessionFile: string, cwd?: string, model?: string): void;
|
|
186
|
+
private abandonPendingLoad;
|
|
187
|
+
private sendSessionLoad;
|
|
181
188
|
switchSession(sessionFile: string, cwd?: string, model?: string): void;
|
|
182
189
|
forkSession(sessionId: string, entryId: string): boolean;
|
|
183
190
|
createSession(cwd: string, model?: string, gitInit?: boolean, createRemote?: boolean, repoVisibility?: 'private' | 'public', cloneRemote?: boolean): void;
|
package/dist/client.js
CHANGED
|
@@ -136,6 +136,7 @@ const defaultState = {
|
|
|
136
136
|
piVersion: null,
|
|
137
137
|
folderConflict: null,
|
|
138
138
|
folderMissing: null,
|
|
139
|
+
assistantRetired: false,
|
|
139
140
|
restore: null,
|
|
140
141
|
isInterrupted: false,
|
|
141
142
|
notice: null,
|
|
@@ -267,6 +268,26 @@ export class WhereverClient {
|
|
|
267
268
|
// null means "accept any" (e.g. session_new, whose target file is not known
|
|
268
269
|
// until the reply). The latest tap always wins.
|
|
269
270
|
pendingLoadFile = null;
|
|
271
|
+
// A session request (load or create) the user made while the socket was not
|
|
272
|
+
// open, so its frame could not be sent. It is the user's newest intent and so
|
|
273
|
+
// supersedes the automatic rejoin: onOpen replays it INSTEAD of rejoining the
|
|
274
|
+
// previously-active session. Without this, switching away from a session that
|
|
275
|
+
// was still reconnecting (PWA brought back to the foreground) lost the switch
|
|
276
|
+
// and the rejoin pulled the user back to the old session. Cleared by a leave,
|
|
277
|
+
// a full disconnect, a server-key wipe, the request's watchdog expiring
|
|
278
|
+
// while still armed, or the replay itself. A socket that closes before
|
|
279
|
+
// opening disarms that watchdog without dropping the request, so it is then
|
|
280
|
+
// replayed on a later socket: it is still the user's latest intent.
|
|
281
|
+
queuedSessionRequest = null;
|
|
282
|
+
// Session files and ids of loads the user moved away from while their reply
|
|
283
|
+
// was still on the wire on THIS socket (a rejoin, a slow load). Their late
|
|
284
|
+
// session_created / message_history are dropped even when nothing else would
|
|
285
|
+
// reject them: a session_new in flight accepts any session_created (its file
|
|
286
|
+
// is unknown until the reply), so a late rejoin reply used to be taken for the
|
|
287
|
+
// new session's and switch the view back. Reset on every new socket (the old
|
|
288
|
+
// socket's replies can no longer arrive), and an entry is removed when the
|
|
289
|
+
// user loads that session again.
|
|
290
|
+
abandonedSessions = new Set();
|
|
270
291
|
// serverKey(config) of the socket currently open (captured by connect() next
|
|
271
292
|
// to the socket it opens). session_created stamps it on the store, so the
|
|
272
293
|
// stamp names the server that actually DELIVERED the session even if the
|
|
@@ -367,6 +388,7 @@ export class WhereverClient {
|
|
|
367
388
|
this.resumeModel = undefined;
|
|
368
389
|
this.pendingLoadFile = null;
|
|
369
390
|
this.hydratedFile = null;
|
|
391
|
+
this.queuedSessionRequest = null;
|
|
370
392
|
}
|
|
371
393
|
this.socketServerKey = key;
|
|
372
394
|
// preserveState keeps the cached session/messages in the store across a
|
|
@@ -399,6 +421,8 @@ export class WhereverClient {
|
|
|
399
421
|
// caller must then render images that have no `data`.
|
|
400
422
|
if (this.config.imageRefs)
|
|
401
423
|
params.push('imageRefs=1');
|
|
424
|
+
if (this.config.kenningCards)
|
|
425
|
+
params.push('kenning=1');
|
|
402
426
|
const wsUrl = `${protocol}://${host}:${this.config.port}/ws?${params.join('&')}`;
|
|
403
427
|
const WebSocketImpl = this.config.WebSocketCtor || (typeof globalThis !== 'undefined' ? globalThis.WebSocket : null);
|
|
404
428
|
if (!WebSocketImpl) {
|
|
@@ -440,6 +464,8 @@ export class WhereverClient {
|
|
|
440
464
|
this.reconnectAttempts = 0;
|
|
441
465
|
this.reconnectDelay = WhereverClient.MIN_RECONNECT_DELAY;
|
|
442
466
|
this.isInitialConnect = false;
|
|
467
|
+
// Replies to loads issued on an earlier socket can no longer arrive.
|
|
468
|
+
this.abandonedSessions.clear();
|
|
443
469
|
this.startLivenessWatchdog();
|
|
444
470
|
this.stateStore.update(s => ({
|
|
445
471
|
...s,
|
|
@@ -464,6 +490,49 @@ export class WhereverClient {
|
|
|
464
490
|
// 2. the store's activeSessionFile -> an UNSOLICITED drop (network
|
|
465
491
|
// blip, tab switch, laptop sleep, half-open reap) where suspend()
|
|
466
492
|
// never ran. This is the case that used to silently freeze.
|
|
493
|
+
//
|
|
494
|
+
// A session request the user made while the socket was down (a switch or
|
|
495
|
+
// a create, see queuedSessionRequest) is newer than any rejoin, so it is
|
|
496
|
+
// sent instead and nothing is rejoined.
|
|
497
|
+
let queued = this.queuedSessionRequest;
|
|
498
|
+
this.queuedSessionRequest = null;
|
|
499
|
+
// A queued load of the session we would rejoin anyway (reloadSession()
|
|
500
|
+
// while disconnected) IS the rejoin: take that path, which keeps held
|
|
501
|
+
// uploads and the resyncing affordance.
|
|
502
|
+
if (queued?.type === 'load' &&
|
|
503
|
+
queued.sessionFile === (this.resumeSessionFile ?? get(this.stateStore).activeSessionFile)) {
|
|
504
|
+
queued = null;
|
|
505
|
+
}
|
|
506
|
+
if (queued) {
|
|
507
|
+
this.resumeSessionFile = null;
|
|
508
|
+
this.resumeCwd = undefined;
|
|
509
|
+
this.resumeModel = undefined;
|
|
510
|
+
this.uploadsHeldForRejoin = false;
|
|
511
|
+
this.rejectPendingUploads('The session changed before the upload could be sent');
|
|
512
|
+
if (queued.type === 'load') {
|
|
513
|
+
this.stateStore.update(s => ({ ...s, loadingSession: true, resyncing: false }));
|
|
514
|
+
this.pendingLoadFile = queued.sessionFile;
|
|
515
|
+
this.send({
|
|
516
|
+
type: 'session_load',
|
|
517
|
+
sessionFile: queued.sessionFile,
|
|
518
|
+
cwd: queued.cwd,
|
|
519
|
+
model: queued.model,
|
|
520
|
+
});
|
|
521
|
+
this.armLoadWatchdog();
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
this.stateStore.update(s => ({
|
|
525
|
+
...s,
|
|
526
|
+
creatingSession: true,
|
|
527
|
+
loadingSession: false,
|
|
528
|
+
resyncing: false,
|
|
529
|
+
}));
|
|
530
|
+
this.pendingLoadFile = null;
|
|
531
|
+
this.send(queued.frame);
|
|
532
|
+
this.armCreateWatchdog();
|
|
533
|
+
}
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
467
536
|
const cached = get(this.stateStore);
|
|
468
537
|
const rejoinFile = this.resumeSessionFile ?? cached.activeSessionFile;
|
|
469
538
|
const rejoinCwd = this.resumeSessionFile != null
|
|
@@ -641,6 +710,8 @@ export class WhereverClient {
|
|
|
641
710
|
this.rejectPendingUploads('Disconnected before the upload completed');
|
|
642
711
|
this.uploadsHeldForRejoin = false;
|
|
643
712
|
this.hydratedFile = null;
|
|
713
|
+
this.queuedSessionRequest = null;
|
|
714
|
+
this.abandonedSessions.clear();
|
|
644
715
|
this.stateStore.set({
|
|
645
716
|
...defaultState,
|
|
646
717
|
hideThinking: !!this.config.hideThinking,
|
|
@@ -923,6 +994,8 @@ export class WhereverClient {
|
|
|
923
994
|
this.loadWatchdog = setTimeout(() => {
|
|
924
995
|
this.loadWatchdog = null;
|
|
925
996
|
const s = get(this.stateStore);
|
|
997
|
+
if (this.queuedSessionRequest?.type === 'load')
|
|
998
|
+
this.queuedSessionRequest = null;
|
|
926
999
|
if (!s.loadingSession && !s.resyncing)
|
|
927
1000
|
return;
|
|
928
1001
|
console.warn('[wherever] session load timed out; clearing loading state');
|
|
@@ -953,6 +1026,9 @@ export class WhereverClient {
|
|
|
953
1026
|
this.createWatchdog = setTimeout(() => {
|
|
954
1027
|
this.createWatchdog = null;
|
|
955
1028
|
const s = get(this.stateStore);
|
|
1029
|
+
// The user was told it failed: a later reconnect must not create it anyway.
|
|
1030
|
+
if (this.queuedSessionRequest?.type === 'create')
|
|
1031
|
+
this.queuedSessionRequest = null;
|
|
956
1032
|
if (!s.creatingSession)
|
|
957
1033
|
return;
|
|
958
1034
|
console.warn('[wherever] session create timed out; clearing creating state');
|
|
@@ -1046,6 +1122,8 @@ export class WhereverClient {
|
|
|
1046
1122
|
const active = get(this.stateStore).sessionId;
|
|
1047
1123
|
if (active && msg.sessionId && msg.sessionId !== active)
|
|
1048
1124
|
break;
|
|
1125
|
+
if (msg.sessionId && this.abandonedSessions.has(msg.sessionId))
|
|
1126
|
+
break;
|
|
1049
1127
|
this.clearLoadWatchdog();
|
|
1050
1128
|
break;
|
|
1051
1129
|
}
|
|
@@ -1159,6 +1237,31 @@ export class WhereverClient {
|
|
|
1159
1237
|
};
|
|
1160
1238
|
});
|
|
1161
1239
|
break;
|
|
1240
|
+
case 'kenning_delivery': {
|
|
1241
|
+
// Messages kenning delivered into this session, live. Not a user message
|
|
1242
|
+
// (no delivery confirmation, no dedupe against the composer). Keyed by
|
|
1243
|
+
// kenning's message ids, so a frame racing a history reload never shows
|
|
1244
|
+
// twice.
|
|
1245
|
+
const kenning = this.kenningDetails(msg.kenning);
|
|
1246
|
+
if (!kenning || typeof msg.content !== 'string')
|
|
1247
|
+
break;
|
|
1248
|
+
this.stateStore.update((s) => {
|
|
1249
|
+
const first = kenning.ids[0];
|
|
1250
|
+
if (first && s.messages.some((m) => m.role === 'kenning' && m.kenning?.ids.includes(first)))
|
|
1251
|
+
return s;
|
|
1252
|
+
const card = {
|
|
1253
|
+
id: this.generateId(),
|
|
1254
|
+
role: 'kenning',
|
|
1255
|
+
content: msg.content,
|
|
1256
|
+
timestamp: typeof msg.timestamp === 'number' ? msg.timestamp : Date.now(),
|
|
1257
|
+
isStreaming: false,
|
|
1258
|
+
sessionId: msg.sessionId,
|
|
1259
|
+
kenning,
|
|
1260
|
+
};
|
|
1261
|
+
return { ...s, messages: [...s.messages, card] };
|
|
1262
|
+
});
|
|
1263
|
+
break;
|
|
1264
|
+
}
|
|
1162
1265
|
case 'message_ack':
|
|
1163
1266
|
// The server accepted this outbound user message (a normal turn, or a
|
|
1164
1267
|
// mid-stream steer queued for the next step) and handed it to the agent.
|
|
@@ -1528,10 +1631,21 @@ export class WhereverClient {
|
|
|
1528
1631
|
(msg.sessionFile === this.pendingLoadFile ||
|
|
1529
1632
|
msg.sessionId === this.pendingLoadFile);
|
|
1530
1633
|
const isRequestedCreate = this.pendingLoadFile === null && st.creatingSession;
|
|
1531
|
-
|
|
1634
|
+
// A load the user moved away from (e.g. the rejoin still in flight
|
|
1635
|
+
// when they created a new session) is never the create's reply.
|
|
1636
|
+
const abandoned = this.abandonedSessions.has(msg.sessionFile) ||
|
|
1637
|
+
this.abandonedSessions.has(msg.sessionId);
|
|
1638
|
+
if (!matchesPendingLoad && (!isRequestedCreate || abandoned)) {
|
|
1639
|
+
// Its message_history follows: drop that too, unless it is the
|
|
1640
|
+
// session already on screen.
|
|
1641
|
+
if (msg.sessionId && msg.sessionId !== st.sessionId) {
|
|
1642
|
+
this.abandonedSessions.add(msg.sessionId);
|
|
1643
|
+
}
|
|
1532
1644
|
break;
|
|
1533
1645
|
}
|
|
1534
1646
|
}
|
|
1647
|
+
this.abandonedSessions.delete(msg.sessionFile);
|
|
1648
|
+
this.abandonedSessions.delete(msg.sessionId);
|
|
1535
1649
|
// This reply matches the load we were waiting on (or the create we
|
|
1536
1650
|
// requested): the load is resolved, so stop guarding against it.
|
|
1537
1651
|
this.pendingLoadFile = null;
|
|
@@ -1580,6 +1694,11 @@ export class WhereverClient {
|
|
|
1580
1694
|
// by a notice naming the path. Hard (no "Continue anyway"); the
|
|
1581
1695
|
// authoritative `folder_missing` frame follows with the same cwd.
|
|
1582
1696
|
folderMissing: msg.folderMissing ? { cwd: msg.cwd } : null,
|
|
1697
|
+
// A RETIRED assistant session (ADR 0020): not the current pointer
|
|
1698
|
+
// session in the assistant folder. Hard read-only (no "Continue
|
|
1699
|
+
// anyway"); the UI offers to open the current assistant session.
|
|
1700
|
+
// Updated live by `assistant_retired` when the pointer moves.
|
|
1701
|
+
assistantRetired: msg.assistantRetired === true,
|
|
1583
1702
|
// The restore panel's state belongs to the folder we are leaving; the
|
|
1584
1703
|
// authoritative `folder_missing` frame below re-creates it for this
|
|
1585
1704
|
// session (carrying any job already running for its path).
|
|
@@ -1704,6 +1823,7 @@ export class WhereverClient {
|
|
|
1704
1823
|
loadingSession: false,
|
|
1705
1824
|
agentPending: false,
|
|
1706
1825
|
folderMissing: null,
|
|
1826
|
+
assistantRetired: false,
|
|
1707
1827
|
restore: null,
|
|
1708
1828
|
notice: null,
|
|
1709
1829
|
sudoPrompt: null,
|
|
@@ -1746,6 +1866,23 @@ export class WhereverClient {
|
|
|
1746
1866
|
this.rejectHydration();
|
|
1747
1867
|
break;
|
|
1748
1868
|
}
|
|
1869
|
+
case 'assistant_retired':
|
|
1870
|
+
// The assistant pointer moved (a reset, a `/new` in the assistant
|
|
1871
|
+
// folder), so the session on screen became RETIRED (or, rarely, current
|
|
1872
|
+
// again). The server's verdict: mirror its readOnly. A retired session
|
|
1873
|
+
// is not a party to a folder conflict, so its banner goes. Ignore a
|
|
1874
|
+
// frame for a session we already switched away from.
|
|
1875
|
+
this.stateStore.update((s) => {
|
|
1876
|
+
if (!s.sessionId || s.sessionId !== msg.sessionId)
|
|
1877
|
+
return s;
|
|
1878
|
+
return {
|
|
1879
|
+
...s,
|
|
1880
|
+
assistantRetired: msg.retired === true,
|
|
1881
|
+
readOnly: msg.readOnly ?? s.readOnly,
|
|
1882
|
+
folderConflict: msg.retired === true ? null : s.folderConflict,
|
|
1883
|
+
};
|
|
1884
|
+
});
|
|
1885
|
+
break;
|
|
1749
1886
|
case 'folder_missing':
|
|
1750
1887
|
// The server states, authoritatively, that this session's working folder
|
|
1751
1888
|
// is not usable -- it does not exist on this machine, or a restore is
|
|
@@ -1929,6 +2066,11 @@ export class WhereverClient {
|
|
|
1929
2066
|
if (active && msg.sessionId && msg.sessionId !== active) {
|
|
1930
2067
|
break;
|
|
1931
2068
|
}
|
|
2069
|
+
// Or for a load the user abandoned, arriving before the new target's
|
|
2070
|
+
// own session_created (so no active sessionId guards it yet).
|
|
2071
|
+
if (msg.sessionId && this.abandonedSessions.has(msg.sessionId)) {
|
|
2072
|
+
break;
|
|
2073
|
+
}
|
|
1932
2074
|
}
|
|
1933
2075
|
// The server transcript is authoritative for what was actually persisted.
|
|
1934
2076
|
// Reconcile it against any unconfirmed outbound messages: keep the ones
|
|
@@ -2021,6 +2163,13 @@ export class WhereverClient {
|
|
|
2021
2163
|
const last = (lines[lines.length - 1] || '').trim();
|
|
2022
2164
|
return /^(command|operation)?\s*aborted$/i.test(last);
|
|
2023
2165
|
}
|
|
2166
|
+
/** The server's kenning `details`, read defensively (another version may lack a field). */
|
|
2167
|
+
kenningDetails(raw) {
|
|
2168
|
+
if (!raw || typeof raw !== 'object')
|
|
2169
|
+
return null;
|
|
2170
|
+
const strings = (v) => (Array.isArray(v) ? v.filter((x) => typeof x === 'string') : []);
|
|
2171
|
+
return { ids: strings(raw.ids), from: strings(raw.from), origins: strings(raw.origins) };
|
|
2172
|
+
}
|
|
2024
2173
|
/**
|
|
2025
2174
|
* Map a server `HistoryMessage[]` window into UI `ChatMessage[]`. When
|
|
2026
2175
|
* `applyStreamingTail` is true, the last assistant/thinking message and any
|
|
@@ -2173,6 +2322,7 @@ export class WhereverClient {
|
|
|
2173
2322
|
// Carry the source entry id (set on user messages by the server) so the
|
|
2174
2323
|
// UI can offer "Fork from here" on each user message.
|
|
2175
2324
|
...(typeof m.entryId === 'string' && m.entryId ? { entryId: m.entryId } : {}),
|
|
2325
|
+
...(m.role === 'kenning' ? { kenning: this.kenningDetails(m.kenning) ?? { ids: [], from: [], origins: [] } } : {}),
|
|
2176
2326
|
});
|
|
2177
2327
|
}
|
|
2178
2328
|
}
|
|
@@ -2747,15 +2897,50 @@ export class WhereverClient {
|
|
|
2747
2897
|
// Both folder verdicts belong to the session being left; the load we are
|
|
2748
2898
|
// starting re-states its own (the server re-checks on every load).
|
|
2749
2899
|
folderMissing: null,
|
|
2900
|
+
assistantRetired: false,
|
|
2750
2901
|
restore: null,
|
|
2751
2902
|
sessionError: null,
|
|
2752
2903
|
loadingSession: true,
|
|
2753
2904
|
agentPending: false,
|
|
2754
2905
|
}));
|
|
2906
|
+
this.abandonPendingLoad(sessionFile);
|
|
2755
2907
|
this.pendingLoadFile = sessionFile;
|
|
2756
|
-
this.
|
|
2908
|
+
this.sendSessionLoad(sessionFile, cwd, model);
|
|
2757
2909
|
this.armLoadWatchdog();
|
|
2758
2910
|
}
|
|
2911
|
+
// The in-flight load (if any) is being superseded by a new request: remember
|
|
2912
|
+
// it so its late reply is dropped (see abandonedSessions). `next` is the load
|
|
2913
|
+
// replacing it, which must not be dropped even if it was abandoned before.
|
|
2914
|
+
abandonPendingLoad(next, { keepShownSession = false } = {}) {
|
|
2915
|
+
if (this.pendingLoadFile && this.pendingLoadFile !== next) {
|
|
2916
|
+
this.abandonedSessions.add(this.pendingLoadFile);
|
|
2917
|
+
}
|
|
2918
|
+
// A load whose session_created was accepted but whose message_history is
|
|
2919
|
+
// still arriving (a rejoin's multi-MB history can take seconds, exactly
|
|
2920
|
+
// while the user is most likely to tap away): pendingLoadFile is already
|
|
2921
|
+
// null, so remember its sessionId instead, or its history would paint over
|
|
2922
|
+
// the next target and disarm that target's watchdog.
|
|
2923
|
+
// keepShownSession: a bare create (composer `/new`) keeps showing the
|
|
2924
|
+
// current session until the new one's session_created, after which the
|
|
2925
|
+
// active-id guard drops its history anyway; abandoning it here would only
|
|
2926
|
+
// blank it if the create then failed.
|
|
2927
|
+
const s = get(this.stateStore);
|
|
2928
|
+
if (!keepShownSession &&
|
|
2929
|
+
s.sessionId &&
|
|
2930
|
+
!s.historyAuthoritative &&
|
|
2931
|
+
s.activeSessionFile !== next &&
|
|
2932
|
+
s.sessionId !== next) {
|
|
2933
|
+
this.abandonedSessions.add(s.sessionId);
|
|
2934
|
+
}
|
|
2935
|
+
if (next)
|
|
2936
|
+
this.abandonedSessions.delete(next);
|
|
2937
|
+
}
|
|
2938
|
+
// Send a user-requested session_load, or queue it for the next open socket
|
|
2939
|
+
// when there is none (see queuedSessionRequest).
|
|
2940
|
+
sendSessionLoad(sessionFile, cwd, model) {
|
|
2941
|
+
const sent = this.send({ type: 'session_load', sessionFile, cwd, model });
|
|
2942
|
+
this.queuedSessionRequest = sent ? null : { type: 'load', sessionFile, cwd, model };
|
|
2943
|
+
}
|
|
2759
2944
|
// Switch from the currently-active session (if any) straight to another one in
|
|
2760
2945
|
// a single, atomic step. Leaving + loading used to be done by the UI as two
|
|
2761
2946
|
// calls separated by a 100ms setTimeout; that gap could strand the loading
|
|
@@ -2775,6 +2960,8 @@ export class WhereverClient {
|
|
|
2775
2960
|
if (s.sessionId) {
|
|
2776
2961
|
this.send({ type: 'session_leave', sessionId: s.sessionId });
|
|
2777
2962
|
}
|
|
2963
|
+
// Before the reset below, which forgets the session being left.
|
|
2964
|
+
this.abandonPendingLoad(sessionFile);
|
|
2778
2965
|
// Reset to a clean loading state for the target session in one update so the
|
|
2779
2966
|
// old conversation clears immediately and the spinner reflects the new load.
|
|
2780
2967
|
this.stateStore.update((st) => ({
|
|
@@ -2788,6 +2975,7 @@ export class WhereverClient {
|
|
|
2788
2975
|
readOnly: false,
|
|
2789
2976
|
folderConflict: null,
|
|
2790
2977
|
folderMissing: null,
|
|
2978
|
+
assistantRetired: false,
|
|
2791
2979
|
restore: null,
|
|
2792
2980
|
sessionError: null,
|
|
2793
2981
|
notice: null,
|
|
@@ -2807,7 +2995,7 @@ export class WhereverClient {
|
|
|
2807
2995
|
// later fire against the newly loaded session.
|
|
2808
2996
|
this.clearCreateWatchdog();
|
|
2809
2997
|
this.pendingLoadFile = sessionFile;
|
|
2810
|
-
this.
|
|
2998
|
+
this.sendSessionLoad(sessionFile, cwd, model);
|
|
2811
2999
|
this.armLoadWatchdog();
|
|
2812
3000
|
}
|
|
2813
3001
|
// Fork the given session at a specific user-message entry, mirroring pi's
|
|
@@ -2829,6 +3017,7 @@ export class WhereverClient {
|
|
|
2829
3017
|
// Creating a session creates its folder, so no missing-folder lock can
|
|
2830
3018
|
// survive into it.
|
|
2831
3019
|
folderMissing: null,
|
|
3020
|
+
assistantRetired: false,
|
|
2832
3021
|
restore: null,
|
|
2833
3022
|
sessionError: null,
|
|
2834
3023
|
creatingSession: true,
|
|
@@ -2837,9 +3026,14 @@ export class WhereverClient {
|
|
|
2837
3026
|
// A new session supersedes any in-flight load: its session_created must not
|
|
2838
3027
|
// be rejected by a stale pendingLoadFile, and a late load reply for the old
|
|
2839
3028
|
// target must not clobber the new session.
|
|
3029
|
+
this.abandonPendingLoad(undefined, { keepShownSession: true });
|
|
2840
3030
|
this.pendingLoadFile = null;
|
|
2841
3031
|
this.hydratedFile = null;
|
|
2842
|
-
|
|
3032
|
+
// A create supersedes any rejoin the next socket would otherwise make.
|
|
3033
|
+
this.resumeSessionFile = null;
|
|
3034
|
+
this.resumeCwd = undefined;
|
|
3035
|
+
this.resumeModel = undefined;
|
|
3036
|
+
const frame = {
|
|
2843
3037
|
type: 'session_new',
|
|
2844
3038
|
cwd,
|
|
2845
3039
|
model,
|
|
@@ -2847,7 +3041,8 @@ export class WhereverClient {
|
|
|
2847
3041
|
createRemote,
|
|
2848
3042
|
repoVisibility,
|
|
2849
3043
|
cloneRemote,
|
|
2850
|
-
}
|
|
3044
|
+
};
|
|
3045
|
+
this.queuedSessionRequest = this.send(frame) ? null : { type: 'create', frame };
|
|
2851
3046
|
// Never let the blocking "Creating session..." overlay hang if the reply is
|
|
2852
3047
|
// lost. Symmetrical with armLoadWatchdog for session_load.
|
|
2853
3048
|
this.armCreateWatchdog();
|
|
@@ -2858,7 +3053,14 @@ export class WhereverClient {
|
|
|
2858
3053
|
// Leaving abandons any in-flight create too, so disarm its watchdog even when
|
|
2859
3054
|
// there is no sessionId yet (a create that has not resolved).
|
|
2860
3055
|
this.clearCreateWatchdog();
|
|
2861
|
-
|
|
3056
|
+
// Leaving cancels whatever would otherwise (re)attach a session later: a
|
|
3057
|
+
// request queued while the socket was down, the rejoin of the session being
|
|
3058
|
+
// left, and the reply of a load still in flight. Done even with no
|
|
3059
|
+
// sessionId yet (a load or rejoin that has not resolved), since that is
|
|
3060
|
+
// exactly when a late reply would pull the user back.
|
|
3061
|
+
this.queuedSessionRequest = null;
|
|
3062
|
+
this.abandonPendingLoad();
|
|
3063
|
+
if (!s.sessionId && !s.activeSessionFile && this.pendingLoadFile === null && !this.resumeSessionFile) {
|
|
2862
3064
|
if (s.creatingSession) {
|
|
2863
3065
|
this.stateStore.update((st) => ({
|
|
2864
3066
|
...st,
|
|
@@ -2867,7 +3069,8 @@ export class WhereverClient {
|
|
|
2867
3069
|
}
|
|
2868
3070
|
return;
|
|
2869
3071
|
}
|
|
2870
|
-
|
|
3072
|
+
if (s.sessionId)
|
|
3073
|
+
this.send({ type: 'session_leave', sessionId: s.sessionId });
|
|
2871
3074
|
this.stateStore.update((s) => ({
|
|
2872
3075
|
...s,
|
|
2873
3076
|
messages: [],
|
|
@@ -2878,6 +3081,7 @@ export class WhereverClient {
|
|
|
2878
3081
|
activeModel: null,
|
|
2879
3082
|
readOnly: false,
|
|
2880
3083
|
folderMissing: null,
|
|
3084
|
+
assistantRetired: false,
|
|
2881
3085
|
restore: null,
|
|
2882
3086
|
notice: null,
|
|
2883
3087
|
sudoPrompt: null,
|
|
@@ -2987,6 +3191,10 @@ export class WhereverClient {
|
|
|
2987
3191
|
// server refuses to lift it, so do not flash an enabled composer here.
|
|
2988
3192
|
if (s.folderMissing)
|
|
2989
3193
|
return;
|
|
3194
|
+
// Same for a retired assistant session (ADR 0020): hard, its remedy is
|
|
3195
|
+
// opening the current assistant session.
|
|
3196
|
+
if (s.assistantRetired)
|
|
3197
|
+
return;
|
|
2990
3198
|
this.send({
|
|
2991
3199
|
type: 'folder_conflict_continue',
|
|
2992
3200
|
sessionId: s.sessionId,
|