@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/src/client.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { writable, get, type Writable } from "sveltore";
|
|
|
2
2
|
import {
|
|
3
3
|
type ChatMessage,
|
|
4
4
|
type HydrationSnapshot,
|
|
5
|
+
type KenningDelivery,
|
|
5
6
|
type RestoreInfo,
|
|
6
7
|
type RestoreJobInfo,
|
|
7
8
|
type UploadByteSource,
|
|
@@ -56,6 +57,11 @@ export interface WhereverClientConfig {
|
|
|
56
57
|
// `GET /session/tool-image` (see ToolImage). Off by default, so a consumer
|
|
57
58
|
// that renders `img.data` keeps getting it; the web app turns it on.
|
|
58
59
|
imageRefs?: boolean;
|
|
60
|
+
// Receive kenning's deliveries into a session (`kenning=1`): `kenning`
|
|
61
|
+
// messages in history and the live `kenning_delivery` frame, mapped to
|
|
62
|
+
// ChatMessage role 'kenning'. Off by default, so a consumer that does not
|
|
63
|
+
// render that role never sees one; the web app turns it on.
|
|
64
|
+
kenningCards?: boolean;
|
|
59
65
|
}
|
|
60
66
|
|
|
61
67
|
// Per-instance fallback identity: stable for the lifetime of this client object,
|
|
@@ -260,6 +266,7 @@ const defaultState: WhereverState = {
|
|
|
260
266
|
piVersion: null,
|
|
261
267
|
folderConflict: null,
|
|
262
268
|
folderMissing: null,
|
|
269
|
+
assistantRetired: false,
|
|
263
270
|
restore: null,
|
|
264
271
|
isInterrupted: false,
|
|
265
272
|
notice: null,
|
|
@@ -392,6 +399,29 @@ export class WhereverClient {
|
|
|
392
399
|
// null means "accept any" (e.g. session_new, whose target file is not known
|
|
393
400
|
// until the reply). The latest tap always wins.
|
|
394
401
|
private pendingLoadFile: string | null = null;
|
|
402
|
+
// A session request (load or create) the user made while the socket was not
|
|
403
|
+
// open, so its frame could not be sent. It is the user's newest intent and so
|
|
404
|
+
// supersedes the automatic rejoin: onOpen replays it INSTEAD of rejoining the
|
|
405
|
+
// previously-active session. Without this, switching away from a session that
|
|
406
|
+
// was still reconnecting (PWA brought back to the foreground) lost the switch
|
|
407
|
+
// and the rejoin pulled the user back to the old session. Cleared by a leave,
|
|
408
|
+
// a full disconnect, a server-key wipe, the request's watchdog expiring
|
|
409
|
+
// while still armed, or the replay itself. A socket that closes before
|
|
410
|
+
// opening disarms that watchdog without dropping the request, so it is then
|
|
411
|
+
// replayed on a later socket: it is still the user's latest intent.
|
|
412
|
+
private queuedSessionRequest:
|
|
413
|
+
| {type: 'load'; sessionFile: string; cwd?: string; model?: string}
|
|
414
|
+
| {type: 'create'; frame: Record<string, unknown>}
|
|
415
|
+
| null = null;
|
|
416
|
+
// Session files and ids of loads the user moved away from while their reply
|
|
417
|
+
// was still on the wire on THIS socket (a rejoin, a slow load). Their late
|
|
418
|
+
// session_created / message_history are dropped even when nothing else would
|
|
419
|
+
// reject them: a session_new in flight accepts any session_created (its file
|
|
420
|
+
// is unknown until the reply), so a late rejoin reply used to be taken for the
|
|
421
|
+
// new session's and switch the view back. Reset on every new socket (the old
|
|
422
|
+
// socket's replies can no longer arrive), and an entry is removed when the
|
|
423
|
+
// user loads that session again.
|
|
424
|
+
private abandonedSessions = new Set<string>();
|
|
395
425
|
// serverKey(config) of the socket currently open (captured by connect() next
|
|
396
426
|
// to the socket it opens). session_created stamps it on the store, so the
|
|
397
427
|
// stamp names the server that actually DELIVERED the session even if the
|
|
@@ -496,6 +526,7 @@ export class WhereverClient {
|
|
|
496
526
|
this.resumeModel = undefined;
|
|
497
527
|
this.pendingLoadFile = null;
|
|
498
528
|
this.hydratedFile = null;
|
|
529
|
+
this.queuedSessionRequest = null;
|
|
499
530
|
}
|
|
500
531
|
this.socketServerKey = key;
|
|
501
532
|
|
|
@@ -528,6 +559,7 @@ export class WhereverClient {
|
|
|
528
559
|
// rather than as base64 re-sent on every load and reconnect. Opt-in: the
|
|
529
560
|
// caller must then render images that have no `data`.
|
|
530
561
|
if (this.config.imageRefs) params.push('imageRefs=1');
|
|
562
|
+
if (this.config.kenningCards) params.push('kenning=1');
|
|
531
563
|
const wsUrl = `${protocol}://${host}:${this.config.port}/ws?${params.join('&')}`;
|
|
532
564
|
|
|
533
565
|
const WebSocketImpl = this.config.WebSocketCtor || (typeof globalThis !== 'undefined' ? (globalThis as any).WebSocket : null);
|
|
@@ -572,6 +604,8 @@ export class WhereverClient {
|
|
|
572
604
|
this.reconnectAttempts = 0;
|
|
573
605
|
this.reconnectDelay = WhereverClient.MIN_RECONNECT_DELAY;
|
|
574
606
|
this.isInitialConnect = false;
|
|
607
|
+
// Replies to loads issued on an earlier socket can no longer arrive.
|
|
608
|
+
this.abandonedSessions.clear();
|
|
575
609
|
this.startLivenessWatchdog();
|
|
576
610
|
this.stateStore.update(s => ({
|
|
577
611
|
...s,
|
|
@@ -596,6 +630,50 @@ export class WhereverClient {
|
|
|
596
630
|
// 2. the store's activeSessionFile -> an UNSOLICITED drop (network
|
|
597
631
|
// blip, tab switch, laptop sleep, half-open reap) where suspend()
|
|
598
632
|
// never ran. This is the case that used to silently freeze.
|
|
633
|
+
//
|
|
634
|
+
// A session request the user made while the socket was down (a switch or
|
|
635
|
+
// a create, see queuedSessionRequest) is newer than any rejoin, so it is
|
|
636
|
+
// sent instead and nothing is rejoined.
|
|
637
|
+
let queued = this.queuedSessionRequest;
|
|
638
|
+
this.queuedSessionRequest = null;
|
|
639
|
+
// A queued load of the session we would rejoin anyway (reloadSession()
|
|
640
|
+
// while disconnected) IS the rejoin: take that path, which keeps held
|
|
641
|
+
// uploads and the resyncing affordance.
|
|
642
|
+
if (
|
|
643
|
+
queued?.type === 'load' &&
|
|
644
|
+
queued.sessionFile === (this.resumeSessionFile ?? get(this.stateStore).activeSessionFile)
|
|
645
|
+
) {
|
|
646
|
+
queued = null;
|
|
647
|
+
}
|
|
648
|
+
if (queued) {
|
|
649
|
+
this.resumeSessionFile = null;
|
|
650
|
+
this.resumeCwd = undefined;
|
|
651
|
+
this.resumeModel = undefined;
|
|
652
|
+
this.uploadsHeldForRejoin = false;
|
|
653
|
+
this.rejectPendingUploads('The session changed before the upload could be sent');
|
|
654
|
+
if (queued.type === 'load') {
|
|
655
|
+
this.stateStore.update(s => ({...s, loadingSession: true, resyncing: false}));
|
|
656
|
+
this.pendingLoadFile = queued.sessionFile;
|
|
657
|
+
this.send({
|
|
658
|
+
type: 'session_load',
|
|
659
|
+
sessionFile: queued.sessionFile,
|
|
660
|
+
cwd: queued.cwd,
|
|
661
|
+
model: queued.model,
|
|
662
|
+
});
|
|
663
|
+
this.armLoadWatchdog();
|
|
664
|
+
} else {
|
|
665
|
+
this.stateStore.update(s => ({
|
|
666
|
+
...s,
|
|
667
|
+
creatingSession: true,
|
|
668
|
+
loadingSession: false,
|
|
669
|
+
resyncing: false,
|
|
670
|
+
}));
|
|
671
|
+
this.pendingLoadFile = null;
|
|
672
|
+
this.send(queued.frame);
|
|
673
|
+
this.armCreateWatchdog();
|
|
674
|
+
}
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
599
677
|
const cached = get(this.stateStore);
|
|
600
678
|
const rejoinFile = this.resumeSessionFile ?? cached.activeSessionFile;
|
|
601
679
|
const rejoinCwd =
|
|
@@ -771,6 +849,8 @@ export class WhereverClient {
|
|
|
771
849
|
this.rejectPendingUploads('Disconnected before the upload completed');
|
|
772
850
|
this.uploadsHeldForRejoin = false;
|
|
773
851
|
this.hydratedFile = null;
|
|
852
|
+
this.queuedSessionRequest = null;
|
|
853
|
+
this.abandonedSessions.clear();
|
|
774
854
|
this.stateStore.set({
|
|
775
855
|
...defaultState,
|
|
776
856
|
hideThinking: !!this.config.hideThinking,
|
|
@@ -1055,6 +1135,7 @@ export class WhereverClient {
|
|
|
1055
1135
|
this.loadWatchdog = setTimeout(() => {
|
|
1056
1136
|
this.loadWatchdog = null;
|
|
1057
1137
|
const s = get(this.stateStore);
|
|
1138
|
+
if (this.queuedSessionRequest?.type === 'load') this.queuedSessionRequest = null;
|
|
1058
1139
|
if (!s.loadingSession && !s.resyncing) return;
|
|
1059
1140
|
console.warn('[wherever] session load timed out; clearing loading state');
|
|
1060
1141
|
this.failHeldUploads('Could not rejoin the session, so the upload was not sent');
|
|
@@ -1087,6 +1168,8 @@ export class WhereverClient {
|
|
|
1087
1168
|
this.createWatchdog = setTimeout(() => {
|
|
1088
1169
|
this.createWatchdog = null;
|
|
1089
1170
|
const s = get(this.stateStore);
|
|
1171
|
+
// The user was told it failed: a later reconnect must not create it anyway.
|
|
1172
|
+
if (this.queuedSessionRequest?.type === 'create') this.queuedSessionRequest = null;
|
|
1090
1173
|
if (!s.creatingSession) return;
|
|
1091
1174
|
console.warn('[wherever] session create timed out; clearing creating state');
|
|
1092
1175
|
this.stateStore.update(st => ({
|
|
@@ -1190,6 +1273,7 @@ export class WhereverClient {
|
|
|
1190
1273
|
// initial load has no sessionId yet, so its history still resolves.
|
|
1191
1274
|
const active = get(this.stateStore).sessionId;
|
|
1192
1275
|
if (active && msg.sessionId && msg.sessionId !== active) break;
|
|
1276
|
+
if (msg.sessionId && this.abandonedSessions.has(msg.sessionId)) break;
|
|
1193
1277
|
this.clearLoadWatchdog();
|
|
1194
1278
|
break;
|
|
1195
1279
|
}
|
|
@@ -1318,6 +1402,30 @@ export class WhereverClient {
|
|
|
1318
1402
|
});
|
|
1319
1403
|
break;
|
|
1320
1404
|
|
|
1405
|
+
case 'kenning_delivery': {
|
|
1406
|
+
// Messages kenning delivered into this session, live. Not a user message
|
|
1407
|
+
// (no delivery confirmation, no dedupe against the composer). Keyed by
|
|
1408
|
+
// kenning's message ids, so a frame racing a history reload never shows
|
|
1409
|
+
// twice.
|
|
1410
|
+
const kenning = this.kenningDetails(msg.kenning);
|
|
1411
|
+
if (!kenning || typeof msg.content !== 'string') break;
|
|
1412
|
+
this.stateStore.update((s: WhereverState) => {
|
|
1413
|
+
const first = kenning.ids[0];
|
|
1414
|
+
if (first && s.messages.some((m) => m.role === 'kenning' && m.kenning?.ids.includes(first))) return s;
|
|
1415
|
+
const card: ChatMessage = {
|
|
1416
|
+
id: this.generateId(),
|
|
1417
|
+
role: 'kenning',
|
|
1418
|
+
content: msg.content,
|
|
1419
|
+
timestamp: typeof msg.timestamp === 'number' ? msg.timestamp : Date.now(),
|
|
1420
|
+
isStreaming: false,
|
|
1421
|
+
sessionId: msg.sessionId,
|
|
1422
|
+
kenning,
|
|
1423
|
+
};
|
|
1424
|
+
return {...s, messages: [...s.messages, card]};
|
|
1425
|
+
});
|
|
1426
|
+
break;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1321
1429
|
case 'message_ack':
|
|
1322
1430
|
// The server accepted this outbound user message (a normal turn, or a
|
|
1323
1431
|
// mid-stream steer queued for the next step) and handed it to the agent.
|
|
@@ -1747,10 +1855,22 @@ export class WhereverClient {
|
|
|
1747
1855
|
msg.sessionId === this.pendingLoadFile);
|
|
1748
1856
|
const isRequestedCreate =
|
|
1749
1857
|
this.pendingLoadFile === null && st.creatingSession;
|
|
1750
|
-
|
|
1858
|
+
// A load the user moved away from (e.g. the rejoin still in flight
|
|
1859
|
+
// when they created a new session) is never the create's reply.
|
|
1860
|
+
const abandoned =
|
|
1861
|
+
this.abandonedSessions.has(msg.sessionFile) ||
|
|
1862
|
+
this.abandonedSessions.has(msg.sessionId);
|
|
1863
|
+
if (!matchesPendingLoad && (!isRequestedCreate || abandoned)) {
|
|
1864
|
+
// Its message_history follows: drop that too, unless it is the
|
|
1865
|
+
// session already on screen.
|
|
1866
|
+
if (msg.sessionId && msg.sessionId !== st.sessionId) {
|
|
1867
|
+
this.abandonedSessions.add(msg.sessionId);
|
|
1868
|
+
}
|
|
1751
1869
|
break;
|
|
1752
1870
|
}
|
|
1753
1871
|
}
|
|
1872
|
+
this.abandonedSessions.delete(msg.sessionFile);
|
|
1873
|
+
this.abandonedSessions.delete(msg.sessionId);
|
|
1754
1874
|
// This reply matches the load we were waiting on (or the create we
|
|
1755
1875
|
// requested): the load is resolved, so stop guarding against it.
|
|
1756
1876
|
this.pendingLoadFile = null;
|
|
@@ -1802,6 +1922,11 @@ export class WhereverClient {
|
|
|
1802
1922
|
// by a notice naming the path. Hard (no "Continue anyway"); the
|
|
1803
1923
|
// authoritative `folder_missing` frame follows with the same cwd.
|
|
1804
1924
|
folderMissing: msg.folderMissing ? {cwd: msg.cwd} : null,
|
|
1925
|
+
// A RETIRED assistant session (ADR 0020): not the current pointer
|
|
1926
|
+
// session in the assistant folder. Hard read-only (no "Continue
|
|
1927
|
+
// anyway"); the UI offers to open the current assistant session.
|
|
1928
|
+
// Updated live by `assistant_retired` when the pointer moves.
|
|
1929
|
+
assistantRetired: msg.assistantRetired === true,
|
|
1805
1930
|
// The restore panel's state belongs to the folder we are leaving; the
|
|
1806
1931
|
// authoritative `folder_missing` frame below re-creates it for this
|
|
1807
1932
|
// session (carrying any job already running for its path).
|
|
@@ -1928,6 +2053,7 @@ export class WhereverClient {
|
|
|
1928
2053
|
loadingSession: false,
|
|
1929
2054
|
agentPending: false,
|
|
1930
2055
|
folderMissing: null,
|
|
2056
|
+
assistantRetired: false,
|
|
1931
2057
|
restore: null,
|
|
1932
2058
|
notice: null,
|
|
1933
2059
|
sudoPrompt: null,
|
|
@@ -1972,6 +2098,23 @@ export class WhereverClient {
|
|
|
1972
2098
|
break;
|
|
1973
2099
|
}
|
|
1974
2100
|
|
|
2101
|
+
case 'assistant_retired':
|
|
2102
|
+
// The assistant pointer moved (a reset, a `/new` in the assistant
|
|
2103
|
+
// folder), so the session on screen became RETIRED (or, rarely, current
|
|
2104
|
+
// again). The server's verdict: mirror its readOnly. A retired session
|
|
2105
|
+
// is not a party to a folder conflict, so its banner goes. Ignore a
|
|
2106
|
+
// frame for a session we already switched away from.
|
|
2107
|
+
this.stateStore.update((s: WhereverState) => {
|
|
2108
|
+
if (!s.sessionId || s.sessionId !== msg.sessionId) return s;
|
|
2109
|
+
return {
|
|
2110
|
+
...s,
|
|
2111
|
+
assistantRetired: msg.retired === true,
|
|
2112
|
+
readOnly: msg.readOnly ?? s.readOnly,
|
|
2113
|
+
folderConflict: msg.retired === true ? null : s.folderConflict,
|
|
2114
|
+
};
|
|
2115
|
+
});
|
|
2116
|
+
break;
|
|
2117
|
+
|
|
1975
2118
|
case 'folder_missing':
|
|
1976
2119
|
// The server states, authoritatively, that this session's working folder
|
|
1977
2120
|
// is not usable -- it does not exist on this machine, or a restore is
|
|
@@ -2165,6 +2308,11 @@ export class WhereverClient {
|
|
|
2165
2308
|
if (active && msg.sessionId && msg.sessionId !== active) {
|
|
2166
2309
|
break;
|
|
2167
2310
|
}
|
|
2311
|
+
// Or for a load the user abandoned, arriving before the new target's
|
|
2312
|
+
// own session_created (so no active sessionId guards it yet).
|
|
2313
|
+
if (msg.sessionId && this.abandonedSessions.has(msg.sessionId)) {
|
|
2314
|
+
break;
|
|
2315
|
+
}
|
|
2168
2316
|
}
|
|
2169
2317
|
// The server transcript is authoritative for what was actually persisted.
|
|
2170
2318
|
// Reconcile it against any unconfirmed outbound messages: keep the ones
|
|
@@ -2262,6 +2410,13 @@ export class WhereverClient {
|
|
|
2262
2410
|
return /^(command|operation)?\s*aborted$/i.test(last);
|
|
2263
2411
|
}
|
|
2264
2412
|
|
|
2413
|
+
/** The server's kenning `details`, read defensively (another version may lack a field). */
|
|
2414
|
+
private kenningDetails(raw: any): KenningDelivery | null {
|
|
2415
|
+
if (!raw || typeof raw !== 'object') return null;
|
|
2416
|
+
const strings = (v: unknown) => (Array.isArray(v) ? v.filter((x): x is string => typeof x === 'string') : []);
|
|
2417
|
+
return {ids: strings(raw.ids), from: strings(raw.from), origins: strings(raw.origins)};
|
|
2418
|
+
}
|
|
2419
|
+
|
|
2265
2420
|
/**
|
|
2266
2421
|
* Map a server `HistoryMessage[]` window into UI `ChatMessage[]`. When
|
|
2267
2422
|
* `applyStreamingTail` is true, the last assistant/thinking message and any
|
|
@@ -2414,6 +2569,7 @@ export class WhereverClient {
|
|
|
2414
2569
|
// Carry the source entry id (set on user messages by the server) so the
|
|
2415
2570
|
// UI can offer "Fork from here" on each user message.
|
|
2416
2571
|
...(typeof m.entryId === 'string' && m.entryId ? {entryId: m.entryId} : {}),
|
|
2572
|
+
...(m.role === 'kenning' ? {kenning: this.kenningDetails(m.kenning) ?? {ids: [], from: [], origins: []}} : {}),
|
|
2417
2573
|
});
|
|
2418
2574
|
}
|
|
2419
2575
|
}
|
|
@@ -3016,16 +3172,54 @@ export class WhereverClient {
|
|
|
3016
3172
|
// Both folder verdicts belong to the session being left; the load we are
|
|
3017
3173
|
// starting re-states its own (the server re-checks on every load).
|
|
3018
3174
|
folderMissing: null,
|
|
3175
|
+
assistantRetired: false,
|
|
3019
3176
|
restore: null,
|
|
3020
3177
|
sessionError: null,
|
|
3021
3178
|
loadingSession: true,
|
|
3022
3179
|
agentPending: false,
|
|
3023
3180
|
}));
|
|
3181
|
+
this.abandonPendingLoad(sessionFile);
|
|
3024
3182
|
this.pendingLoadFile = sessionFile;
|
|
3025
|
-
this.
|
|
3183
|
+
this.sendSessionLoad(sessionFile, cwd, model);
|
|
3026
3184
|
this.armLoadWatchdog();
|
|
3027
3185
|
}
|
|
3028
3186
|
|
|
3187
|
+
// The in-flight load (if any) is being superseded by a new request: remember
|
|
3188
|
+
// it so its late reply is dropped (see abandonedSessions). `next` is the load
|
|
3189
|
+
// replacing it, which must not be dropped even if it was abandoned before.
|
|
3190
|
+
private abandonPendingLoad(next?: string, {keepShownSession = false} = {}) {
|
|
3191
|
+
if (this.pendingLoadFile && this.pendingLoadFile !== next) {
|
|
3192
|
+
this.abandonedSessions.add(this.pendingLoadFile);
|
|
3193
|
+
}
|
|
3194
|
+
// A load whose session_created was accepted but whose message_history is
|
|
3195
|
+
// still arriving (a rejoin's multi-MB history can take seconds, exactly
|
|
3196
|
+
// while the user is most likely to tap away): pendingLoadFile is already
|
|
3197
|
+
// null, so remember its sessionId instead, or its history would paint over
|
|
3198
|
+
// the next target and disarm that target's watchdog.
|
|
3199
|
+
// keepShownSession: a bare create (composer `/new`) keeps showing the
|
|
3200
|
+
// current session until the new one's session_created, after which the
|
|
3201
|
+
// active-id guard drops its history anyway; abandoning it here would only
|
|
3202
|
+
// blank it if the create then failed.
|
|
3203
|
+
const s = get(this.stateStore);
|
|
3204
|
+
if (
|
|
3205
|
+
!keepShownSession &&
|
|
3206
|
+
s.sessionId &&
|
|
3207
|
+
!s.historyAuthoritative &&
|
|
3208
|
+
s.activeSessionFile !== next &&
|
|
3209
|
+
s.sessionId !== next
|
|
3210
|
+
) {
|
|
3211
|
+
this.abandonedSessions.add(s.sessionId);
|
|
3212
|
+
}
|
|
3213
|
+
if (next) this.abandonedSessions.delete(next);
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
// Send a user-requested session_load, or queue it for the next open socket
|
|
3217
|
+
// when there is none (see queuedSessionRequest).
|
|
3218
|
+
private sendSessionLoad(sessionFile: string, cwd?: string, model?: string) {
|
|
3219
|
+
const sent = this.send({type: 'session_load', sessionFile, cwd, model});
|
|
3220
|
+
this.queuedSessionRequest = sent ? null : {type: 'load', sessionFile, cwd, model};
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3029
3223
|
// Switch from the currently-active session (if any) straight to another one in
|
|
3030
3224
|
// a single, atomic step. Leaving + loading used to be done by the UI as two
|
|
3031
3225
|
// calls separated by a 100ms setTimeout; that gap could strand the loading
|
|
@@ -3045,6 +3239,8 @@ export class WhereverClient {
|
|
|
3045
3239
|
if (s.sessionId) {
|
|
3046
3240
|
this.send({type: 'session_leave', sessionId: s.sessionId});
|
|
3047
3241
|
}
|
|
3242
|
+
// Before the reset below, which forgets the session being left.
|
|
3243
|
+
this.abandonPendingLoad(sessionFile);
|
|
3048
3244
|
// Reset to a clean loading state for the target session in one update so the
|
|
3049
3245
|
// old conversation clears immediately and the spinner reflects the new load.
|
|
3050
3246
|
this.stateStore.update((st: WhereverState) => ({
|
|
@@ -3058,6 +3254,7 @@ export class WhereverClient {
|
|
|
3058
3254
|
readOnly: false,
|
|
3059
3255
|
folderConflict: null,
|
|
3060
3256
|
folderMissing: null,
|
|
3257
|
+
assistantRetired: false,
|
|
3061
3258
|
restore: null,
|
|
3062
3259
|
sessionError: null,
|
|
3063
3260
|
notice: null,
|
|
@@ -3077,7 +3274,7 @@ export class WhereverClient {
|
|
|
3077
3274
|
// later fire against the newly loaded session.
|
|
3078
3275
|
this.clearCreateWatchdog();
|
|
3079
3276
|
this.pendingLoadFile = sessionFile;
|
|
3080
|
-
this.
|
|
3277
|
+
this.sendSessionLoad(sessionFile, cwd, model);
|
|
3081
3278
|
this.armLoadWatchdog();
|
|
3082
3279
|
}
|
|
3083
3280
|
|
|
@@ -3107,6 +3304,7 @@ export class WhereverClient {
|
|
|
3107
3304
|
// Creating a session creates its folder, so no missing-folder lock can
|
|
3108
3305
|
// survive into it.
|
|
3109
3306
|
folderMissing: null,
|
|
3307
|
+
assistantRetired: false,
|
|
3110
3308
|
restore: null,
|
|
3111
3309
|
sessionError: null,
|
|
3112
3310
|
creatingSession: true,
|
|
@@ -3115,9 +3313,14 @@ export class WhereverClient {
|
|
|
3115
3313
|
// A new session supersedes any in-flight load: its session_created must not
|
|
3116
3314
|
// be rejected by a stale pendingLoadFile, and a late load reply for the old
|
|
3117
3315
|
// target must not clobber the new session.
|
|
3316
|
+
this.abandonPendingLoad(undefined, {keepShownSession: true});
|
|
3118
3317
|
this.pendingLoadFile = null;
|
|
3119
3318
|
this.hydratedFile = null;
|
|
3120
|
-
|
|
3319
|
+
// A create supersedes any rejoin the next socket would otherwise make.
|
|
3320
|
+
this.resumeSessionFile = null;
|
|
3321
|
+
this.resumeCwd = undefined;
|
|
3322
|
+
this.resumeModel = undefined;
|
|
3323
|
+
const frame = {
|
|
3121
3324
|
type: 'session_new',
|
|
3122
3325
|
cwd,
|
|
3123
3326
|
model,
|
|
@@ -3125,7 +3328,8 @@ export class WhereverClient {
|
|
|
3125
3328
|
createRemote,
|
|
3126
3329
|
repoVisibility,
|
|
3127
3330
|
cloneRemote,
|
|
3128
|
-
}
|
|
3331
|
+
};
|
|
3332
|
+
this.queuedSessionRequest = this.send(frame) ? null : {type: 'create', frame};
|
|
3129
3333
|
// Never let the blocking "Creating session..." overlay hang if the reply is
|
|
3130
3334
|
// lost. Symmetrical with armLoadWatchdog for session_load.
|
|
3131
3335
|
this.armCreateWatchdog();
|
|
@@ -3137,7 +3341,14 @@ export class WhereverClient {
|
|
|
3137
3341
|
// Leaving abandons any in-flight create too, so disarm its watchdog even when
|
|
3138
3342
|
// there is no sessionId yet (a create that has not resolved).
|
|
3139
3343
|
this.clearCreateWatchdog();
|
|
3140
|
-
|
|
3344
|
+
// Leaving cancels whatever would otherwise (re)attach a session later: a
|
|
3345
|
+
// request queued while the socket was down, the rejoin of the session being
|
|
3346
|
+
// left, and the reply of a load still in flight. Done even with no
|
|
3347
|
+
// sessionId yet (a load or rejoin that has not resolved), since that is
|
|
3348
|
+
// exactly when a late reply would pull the user back.
|
|
3349
|
+
this.queuedSessionRequest = null;
|
|
3350
|
+
this.abandonPendingLoad();
|
|
3351
|
+
if (!s.sessionId && !s.activeSessionFile && this.pendingLoadFile === null && !this.resumeSessionFile) {
|
|
3141
3352
|
if (s.creatingSession) {
|
|
3142
3353
|
this.stateStore.update((st: WhereverState) => ({
|
|
3143
3354
|
...st,
|
|
@@ -3146,7 +3357,7 @@ export class WhereverClient {
|
|
|
3146
3357
|
}
|
|
3147
3358
|
return;
|
|
3148
3359
|
}
|
|
3149
|
-
this.send({type: 'session_leave', sessionId: s.sessionId});
|
|
3360
|
+
if (s.sessionId) this.send({type: 'session_leave', sessionId: s.sessionId});
|
|
3150
3361
|
this.stateStore.update((s: WhereverState) => ({
|
|
3151
3362
|
...s,
|
|
3152
3363
|
messages: [],
|
|
@@ -3157,6 +3368,7 @@ export class WhereverClient {
|
|
|
3157
3368
|
activeModel: null,
|
|
3158
3369
|
readOnly: false,
|
|
3159
3370
|
folderMissing: null,
|
|
3371
|
+
assistantRetired: false,
|
|
3160
3372
|
restore: null,
|
|
3161
3373
|
notice: null,
|
|
3162
3374
|
sudoPrompt: null,
|
|
@@ -3269,6 +3481,9 @@ export class WhereverClient {
|
|
|
3269
3481
|
// hard lock (there is nothing to drive, and no agent was built), and the
|
|
3270
3482
|
// server refuses to lift it, so do not flash an enabled composer here.
|
|
3271
3483
|
if (s.folderMissing) return;
|
|
3484
|
+
// Same for a retired assistant session (ADR 0020): hard, its remedy is
|
|
3485
|
+
// opening the current assistant session.
|
|
3486
|
+
if (s.assistantRetired) return;
|
|
3272
3487
|
|
|
3273
3488
|
this.send({
|
|
3274
3489
|
type: 'folder_conflict_continue',
|
package/src/types.ts
CHANGED
|
@@ -15,9 +15,22 @@ export interface ToolImage {
|
|
|
15
15
|
index?: number;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Messages kenning delivered into a session (the server's
|
|
20
|
+
* `KenningDeliveryInfo`), one entry per message, in order: kenning ids, sender
|
|
21
|
+
* labels, origins (`agent`, `human`, `human-relayed`).
|
|
22
|
+
*/
|
|
23
|
+
export interface KenningDelivery {
|
|
24
|
+
ids: string[];
|
|
25
|
+
from: string[];
|
|
26
|
+
origins: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
18
29
|
export interface ChatMessage {
|
|
19
30
|
id: string;
|
|
20
|
-
|
|
31
|
+
// `kenning`: a delivery from other sessions (only with `kenningCards`). It is
|
|
32
|
+
// never a user message: not forkable, not editable, no delivery state.
|
|
33
|
+
role: 'user' | 'assistant' | 'thinking' | 'tool' | 'kenning';
|
|
21
34
|
content: string;
|
|
22
35
|
timestamp: number;
|
|
23
36
|
isStreaming?: boolean;
|
|
@@ -84,6 +97,9 @@ export interface ChatMessage {
|
|
|
84
97
|
// last user message is not enough: with several messages queued they are
|
|
85
98
|
// delivered oldest-first, so the echoed one is usually not the last bubble.
|
|
86
99
|
restoredFromQueue?: boolean;
|
|
100
|
+
// Set on role 'kenning': who sent what, with which origin. `content` is
|
|
101
|
+
// kenning's formatted text, as the model read it.
|
|
102
|
+
kenning?: KenningDelivery;
|
|
87
103
|
}
|
|
88
104
|
|
|
89
105
|
export interface SessionNotice {
|
|
@@ -248,6 +264,12 @@ export interface WhereverState {
|
|
|
248
264
|
// coming: the composer is replaced by a notice naming the path. Cleared with
|
|
249
265
|
// the session it belongs to.
|
|
250
266
|
folderMissing: FolderMissingInfo | null;
|
|
267
|
+
// The active session is a RETIRED assistant session (ADR 0020): it lives in
|
|
268
|
+
// the assistant folder but is not the current pointer session (the assistant
|
|
269
|
+
// was reset). Implies `readOnly`, HARD (no "Continue anyway"): the UI explains
|
|
270
|
+
// the reset and offers to open the current assistant session. Set from
|
|
271
|
+
// session_created's `assistantRetired` and live from `assistant_retired`.
|
|
272
|
+
assistantRetired: boolean;
|
|
251
273
|
// The restore of the active session's missing folder: the server's job for
|
|
252
274
|
// that path (running, finished or not yet started) plus this client's own last
|
|
253
275
|
// request. Non-null exactly while a folder-missing session is open, so the
|