wherever-dev 0.17.1 → 0.18.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/dist/extension-lifecycle.d.ts +27 -7
- package/dist/extension-lifecycle.d.ts.map +1 -1
- package/dist/extension-lifecycle.js +39 -8
- package/dist/extension-lifecycle.js.map +1 -1
- package/dist/index.js +93 -2
- package/dist/index.js.map +1 -1
- package/dist/protocol.d.ts +6 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/session-pool.d.ts +67 -0
- package/dist/session-pool.d.ts.map +1 -1
- package/dist/session-pool.js +241 -74
- package/dist/session-pool.js.map +1 -1
- package/package.json +1 -1
- package/public/_app/immutable/chunks/{BhP7_nMn.js → 6cDLdLMr.js} +2 -2
- package/public/_app/immutable/chunks/{BhP7_nMn.js.map → 6cDLdLMr.js.map} +1 -1
- package/public/_app/immutable/chunks/BWLk4g7S.js +2 -0
- package/public/_app/immutable/chunks/{Bio1jLTG.js.map → BWLk4g7S.js.map} +1 -1
- package/public/_app/immutable/chunks/{BRAYQ_mD.js → C2gDSNg3.js} +2 -2
- package/public/_app/immutable/chunks/{BRAYQ_mD.js.map → C2gDSNg3.js.map} +1 -1
- package/public/_app/immutable/entry/{app.D06PTvNp.js → app.DCsaSS2h.js} +3 -3
- package/public/_app/immutable/entry/{app.D06PTvNp.js.map → app.DCsaSS2h.js.map} +1 -1
- package/public/_app/immutable/entry/start.CVu9YCQp.js +2 -0
- package/public/_app/immutable/entry/start.CVu9YCQp.js.map +1 -0
- package/public/_app/immutable/nodes/{0.05Mp-ARy.js → 0.BKhPUBoV.js} +2 -2
- package/public/_app/immutable/nodes/{0.05Mp-ARy.js.map → 0.BKhPUBoV.js.map} +1 -1
- package/public/_app/immutable/nodes/{1.C_Y-Wpdd.js → 1.D-6k-nc0.js} +2 -2
- package/public/_app/immutable/nodes/{1.C_Y-Wpdd.js.map → 1.D-6k-nc0.js.map} +1 -1
- package/public/_app/immutable/nodes/{2.DmncGYOi.js → 2.B1UIQ9ew.js} +46 -46
- package/public/_app/immutable/nodes/2.B1UIQ9ew.js.map +1 -0
- package/public/_app/version.json +1 -1
- package/public/index.html +10 -10
- package/public/service-worker.js +1 -1
- package/public/_app/immutable/chunks/Bio1jLTG.js +0 -2
- package/public/_app/immutable/entry/start.DoiCihIa.js +0 -2
- package/public/_app/immutable/entry/start.DoiCihIa.js.map +0 -1
- package/public/_app/immutable/nodes/2.DmncGYOi.js.map +0 -1
|
@@ -21,6 +21,23 @@ import type { AgentSession } from '@earendil-works/pi-coding-agent';
|
|
|
21
21
|
* - shut down before dispose: `shutdownAndDisposeAgentSession()` is the ONLY way
|
|
22
22
|
* a server session is disposed, so no call site can skip `session_shutdown`.
|
|
23
23
|
*/
|
|
24
|
+
/**
|
|
25
|
+
* Drop pi's PROCESS-WIDE cache of loaded extension factories, so the next
|
|
26
|
+
* resource load re-reads extension code from disk.
|
|
27
|
+
*
|
|
28
|
+
* pi caches each extension's factory at module level (keyed by cwd), and only
|
|
29
|
+
* `DefaultResourceLoader.reload()` on an ALREADY-LOADED loader clears it: that is
|
|
30
|
+
* how pi's own `/reload` picks up edited extension code. Wherever's `/reload`
|
|
31
|
+
* rebuilds with a FRESH loader (see SessionPool.reloadSession), whose first
|
|
32
|
+
* `reload()` does not clear, so without this the rebuilt agent silently runs the
|
|
33
|
+
* old code. `clearExtensionCache` is not in the package's `exports` map, so it is
|
|
34
|
+
* reached through the module file next to the resolved entry point; it is the
|
|
35
|
+
* same module instance the SDK uses (same URL). If a future SDK moves it, reload
|
|
36
|
+
* still works for settings, skills, prompts and context files, and this logs
|
|
37
|
+
* why extension edits were not picked up. Pinned by test/session-reload-ws.test.ts.
|
|
38
|
+
* Clearing is safe for other sessions: their next build just reloads from disk.
|
|
39
|
+
*/
|
|
40
|
+
export declare function clearPiExtensionCache(): Promise<void>;
|
|
24
41
|
/** Upper bound on extension `session_shutdown` handlers before we dispose anyway. */
|
|
25
42
|
export declare const EXTENSION_SHUTDOWN_TIMEOUT_MS = 5000;
|
|
26
43
|
/**
|
|
@@ -59,9 +76,10 @@ type ExtensionBindings = Parameters<AgentSession['bindExtensions']>[0];
|
|
|
59
76
|
* session could not survive it, but because `AgentSession.reload()` calls pi-ai's
|
|
60
77
|
* `resetApiProviders()`, which is PROCESS-WIDE: in a multi-session server, one
|
|
61
78
|
* session's reload would drop the custom API providers every OTHER live
|
|
62
|
-
* session's extensions registered.
|
|
63
|
-
*
|
|
64
|
-
*
|
|
79
|
+
* session's extensions registered. The web `/reload` does not use it either: it
|
|
80
|
+
* REBUILDS the agent (`SessionPool.reloadSession`). Routing an extension's
|
|
81
|
+
* `ctx.reload()` there is possible but would dispose the session whose command
|
|
82
|
+
* is still running, so it stays refused until that is designed.
|
|
65
83
|
* - `shutdownHandler`: left unset. `ctx.shutdown()` from an extension must not
|
|
66
84
|
* stop the whole multi-session server.
|
|
67
85
|
* - `abortHandler`: left unset, so `ctx.abort()` aborts this session's turn (the
|
|
@@ -71,10 +89,12 @@ export declare function serverExtensionBindings(agentSession: AgentSession, labe
|
|
|
71
89
|
/** Start the extensions of a freshly created server session (emits session_start + resources_discover). */
|
|
72
90
|
export declare function bindServerSessionExtensions(agentSession: AgentSession, label: string, warnAfterMs?: number): Promise<void>;
|
|
73
91
|
/**
|
|
74
|
-
* Emit `session_shutdown`
|
|
75
|
-
*
|
|
76
|
-
*
|
|
92
|
+
* Emit `session_shutdown` to the session's extensions, then dispose it. The
|
|
93
|
+
* shutdown is awaited but bounded by `timeoutMs`, so a hung extension cannot
|
|
94
|
+
* block idle eviction or server shutdown. Never rejects. `reason` is `quit` for
|
|
95
|
+
* every teardown except the pool's `/reload` rebuild, which says `reload` so
|
|
96
|
+
* extensions can tell a restart from an exit (as they can under the pi CLI).
|
|
77
97
|
*/
|
|
78
|
-
export declare function shutdownAndDisposeAgentSession(agentSession: AgentSession, label: string, timeoutMs?: number): Promise<void>;
|
|
98
|
+
export declare function shutdownAndDisposeAgentSession(agentSession: AgentSession, label: string, timeoutMs?: number, reason?: 'quit' | 'reload'): Promise<void>;
|
|
79
99
|
export {};
|
|
80
100
|
//# sourceMappingURL=extension-lifecycle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension-lifecycle.d.ts","sourceRoot":"","sources":["../src/extension-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,iCAAiC,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,qFAAqF;AACrF,eAAO,MAAM,6BAA6B,OAAQ,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAEnD,KAAK,iBAAiB,GAAG,UAAU,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAWvE
|
|
1
|
+
{"version":3,"file":"extension-lifecycle.d.ts","sourceRoot":"","sources":["../src/extension-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAkB,MAAM,iCAAiC,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAa3D;AAED,qFAAqF;AACrF,eAAO,MAAM,6BAA6B,OAAQ,CAAC;AAEnD;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,QAAS,CAAC;AAEnD,KAAK,iBAAiB,GAAG,UAAU,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAWvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,uBAAuB,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,iBAAiB,CAmBpG;AAED,2GAA2G;AAC3G,wBAAsB,2BAA2B,CAC/C,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,WAAW,SAA+B,GACzC,OAAO,CAAC,IAAI,CAAC,CAcf;AAED;;;;;;GAMG;AACH,wBAAsB,8BAA8B,CAClD,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,SAAgC,EACzC,MAAM,GAAE,MAAM,GAAG,QAAiB,GACjC,OAAO,CAAC,IAAI,CAAC,CAoCf"}
|
|
@@ -20,6 +20,34 @@
|
|
|
20
20
|
* - shut down before dispose: `shutdownAndDisposeAgentSession()` is the ONLY way
|
|
21
21
|
* a server session is disposed, so no call site can skip `session_shutdown`.
|
|
22
22
|
*/
|
|
23
|
+
/**
|
|
24
|
+
* Drop pi's PROCESS-WIDE cache of loaded extension factories, so the next
|
|
25
|
+
* resource load re-reads extension code from disk.
|
|
26
|
+
*
|
|
27
|
+
* pi caches each extension's factory at module level (keyed by cwd), and only
|
|
28
|
+
* `DefaultResourceLoader.reload()` on an ALREADY-LOADED loader clears it: that is
|
|
29
|
+
* how pi's own `/reload` picks up edited extension code. Wherever's `/reload`
|
|
30
|
+
* rebuilds with a FRESH loader (see SessionPool.reloadSession), whose first
|
|
31
|
+
* `reload()` does not clear, so without this the rebuilt agent silently runs the
|
|
32
|
+
* old code. `clearExtensionCache` is not in the package's `exports` map, so it is
|
|
33
|
+
* reached through the module file next to the resolved entry point; it is the
|
|
34
|
+
* same module instance the SDK uses (same URL). If a future SDK moves it, reload
|
|
35
|
+
* still works for settings, skills, prompts and context files, and this logs
|
|
36
|
+
* why extension edits were not picked up. Pinned by test/session-reload-ws.test.ts.
|
|
37
|
+
* Clearing is safe for other sessions: their next build just reloads from disk.
|
|
38
|
+
*/
|
|
39
|
+
export async function clearPiExtensionCache() {
|
|
40
|
+
try {
|
|
41
|
+
const entry = import.meta.resolve('@earendil-works/pi-coding-agent');
|
|
42
|
+
const loader = (await import(new URL('./core/extensions/loader.js', entry).href));
|
|
43
|
+
if (typeof loader.clearExtensionCache !== 'function')
|
|
44
|
+
throw new Error('clearExtensionCache not found');
|
|
45
|
+
loader.clearExtensionCache();
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
console.error(`[wherever] could not clear pi's extension cache; /reload will not pick up edited extension code: ${err.message}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
23
51
|
/** Upper bound on extension `session_shutdown` handlers before we dispose anyway. */
|
|
24
52
|
export const EXTENSION_SHUTDOWN_TIMEOUT_MS = 5_000;
|
|
25
53
|
/**
|
|
@@ -63,9 +91,10 @@ function logExtensionError(label, err) {
|
|
|
63
91
|
* session could not survive it, but because `AgentSession.reload()` calls pi-ai's
|
|
64
92
|
* `resetApiProviders()`, which is PROCESS-WIDE: in a multi-session server, one
|
|
65
93
|
* session's reload would drop the custom API providers every OTHER live
|
|
66
|
-
* session's extensions registered.
|
|
67
|
-
*
|
|
68
|
-
*
|
|
94
|
+
* session's extensions registered. The web `/reload` does not use it either: it
|
|
95
|
+
* REBUILDS the agent (`SessionPool.reloadSession`). Routing an extension's
|
|
96
|
+
* `ctx.reload()` there is possible but would dispose the session whose command
|
|
97
|
+
* is still running, so it stays refused until that is designed.
|
|
69
98
|
* - `shutdownHandler`: left unset. `ctx.shutdown()` from an extension must not
|
|
70
99
|
* stop the whole multi-session server.
|
|
71
100
|
* - `abortHandler`: left unset, so `ctx.abort()` aborts this session's turn (the
|
|
@@ -108,11 +137,13 @@ export async function bindServerSessionExtensions(agentSession, label, warnAfter
|
|
|
108
137
|
}
|
|
109
138
|
}
|
|
110
139
|
/**
|
|
111
|
-
* Emit `session_shutdown`
|
|
112
|
-
*
|
|
113
|
-
*
|
|
140
|
+
* Emit `session_shutdown` to the session's extensions, then dispose it. The
|
|
141
|
+
* shutdown is awaited but bounded by `timeoutMs`, so a hung extension cannot
|
|
142
|
+
* block idle eviction or server shutdown. Never rejects. `reason` is `quit` for
|
|
143
|
+
* every teardown except the pool's `/reload` rebuild, which says `reload` so
|
|
144
|
+
* extensions can tell a restart from an exit (as they can under the pi CLI).
|
|
114
145
|
*/
|
|
115
|
-
export async function shutdownAndDisposeAgentSession(agentSession, label, timeoutMs = EXTENSION_SHUTDOWN_TIMEOUT_MS) {
|
|
146
|
+
export async function shutdownAndDisposeAgentSession(agentSession, label, timeoutMs = EXTENSION_SHUTDOWN_TIMEOUT_MS, reason = 'quit') {
|
|
116
147
|
// Stop any in-flight turn FIRST, synchronously. dispose() would abort it, but
|
|
117
148
|
// it runs only after the (up to timeoutMs) shutdown handlers; until then a live
|
|
118
149
|
// turn would keep streaming, running tools and appending to the transcript,
|
|
@@ -131,7 +162,7 @@ export async function shutdownAndDisposeAgentSession(agentSession, label, timeou
|
|
|
131
162
|
if (runner.hasHandlers('session_shutdown')) {
|
|
132
163
|
let timer;
|
|
133
164
|
const timedOut = await Promise.race([
|
|
134
|
-
runner.emit({ type: 'session_shutdown', reason
|
|
165
|
+
runner.emit({ type: 'session_shutdown', reason }).then(() => false),
|
|
135
166
|
new Promise((resolve) => {
|
|
136
167
|
timer = setTimeout(() => resolve(true), timeoutMs);
|
|
137
168
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extension-lifecycle.js","sourceRoot":"","sources":["../src/extension-lifecycle.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,qFAAqF;AACrF,MAAM,CAAC,MAAM,6BAA6B,GAAG,KAAK,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC;AAInD,SAAS,iBAAiB,CAAC,KAAa,EAAE,GAAmB;IAC3D,8EAA8E;IAC9E,8DAA8D;IAC9D,OAAO,CAAC,KAAK,CACX,iCAAiC,KAAK,KAAK,GAAG,CAAC,aAAa,KAAK,GAAG,CAAC,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE;QACzF,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE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AC,KAAK,CAAC,CAAC,CAAC;YACtC,IAAI,QAAQ,EAAE,CAAC;gBACb,OAAO,CAAC,KAAK,CAAC,6CAA6C,KAAK,aAAa,SAAS,sBAAsB,CAAC,CAAC;YAChH,CAAC;QACH,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,sFAAsF;QACtF,OAAO,CAAC,KAAK,CAAC,0CAA0C,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,CAAC;QACH,YAAY,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,iCAAiC,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC;IAChE,CAAC;AACH,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createServer as createHttpServer } from 'node:http';
|
|
|
3
3
|
import { createServer as createHttpsServer, request as httpRequest } from 'node:https';
|
|
4
4
|
import { connect as netConnect } from 'node:net';
|
|
5
5
|
import { WebSocketServer, WebSocket } from 'ws';
|
|
6
|
-
import { SessionPool, getWhereverConfig, getWhereverCertsDir, detectRemoteRepo, normalizePath, invalidateFolderExistence } from './session-pool.js';
|
|
6
|
+
import { SessionPool, RELOADING_REFUSAL, getWhereverConfig, getWhereverCertsDir, detectRemoteRepo, normalizePath, invalidateFolderExistence } from './session-pool.js';
|
|
7
7
|
import { readDrafts, addDraft, deleteDraft, validateDraftInput } from './drafts.js';
|
|
8
8
|
import { searchConversations } from './conversation-search.js';
|
|
9
9
|
import { matchRemoteRepoRule, resolveRemoteCandidates } from './remote-candidates.js';
|
|
@@ -2686,6 +2686,7 @@ async function handleWSMessage(msg, client, pool, clients, broadcast, onSessions
|
|
|
2686
2686
|
// folder -- but the client is locked and, on the cold path below, no live
|
|
2687
2687
|
// agent is built at all.
|
|
2688
2688
|
const restoreInFlight = restoreJobs.get(meta.cwd)?.state === 'running';
|
|
2689
|
+
const reloadingNow = meta.resident && pool.isReloading(meta.sessionFile);
|
|
2689
2690
|
const folderMissing = meta.folderMissing || restoreInFlight;
|
|
2690
2691
|
client.folderMissingCwd = folderMissing ? meta.cwd : undefined;
|
|
2691
2692
|
// A session whose cwd matches a sessions.readOnly glob is forced read-only.
|
|
@@ -2709,7 +2710,10 @@ async function handleWSMessage(msg, client, pool, clients, broadcast, onSessions
|
|
|
2709
2710
|
folderConflict,
|
|
2710
2711
|
folderMissing,
|
|
2711
2712
|
contextUsage: meta.resident ? (pool.getContextUsage(meta.sessionFile) ?? null) : null,
|
|
2712
|
-
|
|
2713
|
+
// A resident session mid-/reload has no usable agent yet: paint it as
|
|
2714
|
+
// pending; the reload's own session_ready (sent to every viewer, this
|
|
2715
|
+
// one included once attached below) ends it.
|
|
2716
|
+
pending: !meta.resident || reloadingNow,
|
|
2713
2717
|
});
|
|
2714
2718
|
sendWS(client.ws, {
|
|
2715
2719
|
type: 'message_history',
|
|
@@ -2743,6 +2747,9 @@ async function handleWSMessage(msg, client, pool, clients, broadcast, onSessions
|
|
|
2743
2747
|
pool.addClient(meta.sessionFile, client.id);
|
|
2744
2748
|
switchClientSession(client, meta.sessionFile, pool, onSessionsUpdated);
|
|
2745
2749
|
client.readOnly = forcedReadOnly;
|
|
2750
|
+
// Mid-/reload: the reload's completion frame is this client's ready.
|
|
2751
|
+
if (reloadingNow)
|
|
2752
|
+
break;
|
|
2746
2753
|
sendWS(client.ws, {
|
|
2747
2754
|
type: 'session_ready',
|
|
2748
2755
|
sessionId: meta.sessionId,
|
|
@@ -3152,6 +3159,15 @@ async function handleWSMessage(msg, client, pool, clients, broadcast, onSessions
|
|
|
3152
3159
|
});
|
|
3153
3160
|
break;
|
|
3154
3161
|
}
|
|
3162
|
+
// A /reload is rebuilding the agent. The composer is blocked on every viewer
|
|
3163
|
+
// (session_reloading), so this is a race or an old client: answer, retryably.
|
|
3164
|
+
if (pool.isReloading(client.sessionId)) {
|
|
3165
|
+
// session_error is what fails the message on the client (Retry), but it
|
|
3166
|
+
// also clears agentPending: re-assert the reload block right after it.
|
|
3167
|
+
sendWS(client.ws, { type: 'session_error', sessionId: msg.sessionId, error: RELOADING_REFUSAL });
|
|
3168
|
+
sendWS(client.ws, { type: 'session_reloading', sessionId: attached.sessionId });
|
|
3169
|
+
break;
|
|
3170
|
+
}
|
|
3155
3171
|
const streaming = pool.isStreaming(client.sessionId);
|
|
3156
3172
|
// The optional conversationMode field is the per-turn spoken-conversation
|
|
3157
3173
|
// signal (absent = off). It only decides whether a hint is appended to this
|
|
@@ -3203,6 +3219,74 @@ async function handleWSMessage(msg, client, pool, clients, broadcast, onSessions
|
|
|
3203
3219
|
await pool.cancelSteerQueue(client.sessionId);
|
|
3204
3220
|
break;
|
|
3205
3221
|
}
|
|
3222
|
+
case 'session_reload': {
|
|
3223
|
+
if (!client.sessionId)
|
|
3224
|
+
return;
|
|
3225
|
+
// Same authority guard as 'message': only reload the session this
|
|
3226
|
+
// connection is attached to AND looking at.
|
|
3227
|
+
const attached = pool.getSession(client.sessionId);
|
|
3228
|
+
const target = msg.sessionId ? pool.getSession(msg.sessionId) : attached;
|
|
3229
|
+
if (!attached || !target || target !== attached) {
|
|
3230
|
+
sendWS(client.ws, {
|
|
3231
|
+
type: 'session_error',
|
|
3232
|
+
sessionId: msg.sessionId,
|
|
3233
|
+
error: 'The session changed, so it was not reloaded. Re-open it and try /reload again.',
|
|
3234
|
+
});
|
|
3235
|
+
break;
|
|
3236
|
+
}
|
|
3237
|
+
const refuse = (message) => sendWS(client.ws, { type: 'session_notice', sessionId: attached.sessionId, level: 'warning', message });
|
|
3238
|
+
// Reloading re-runs extension code and rebuilds the agent every viewer
|
|
3239
|
+
// shares: an observe-only client may not trigger that.
|
|
3240
|
+
if (client.readOnly) {
|
|
3241
|
+
refuse('This session is read-only from here, so it was not reloaded.');
|
|
3242
|
+
break;
|
|
3243
|
+
}
|
|
3244
|
+
const sessionFile = attached.sessionFile;
|
|
3245
|
+
const sessionId = attached.sessionId;
|
|
3246
|
+
// Tell the connections that are CURRENTLY on this session, decided at send
|
|
3247
|
+
// time: a viewer who switched away mid-reload must not get this session's
|
|
3248
|
+
// frames (the client's session_error handler is not session-scoped). Found
|
|
3249
|
+
// by scanning connections rather than the pool entry, because a failed
|
|
3250
|
+
// rebuild drops the entry while its viewers are still attached to the file.
|
|
3251
|
+
const tellViewers = (message) => {
|
|
3252
|
+
for (const c of clients.values()) {
|
|
3253
|
+
if (c.sessionId === sessionFile)
|
|
3254
|
+
sendWS(c.ws, message);
|
|
3255
|
+
}
|
|
3256
|
+
};
|
|
3257
|
+
const result = await pool.reloadSession(sessionFile, {
|
|
3258
|
+
onStart: () => tellViewers({ type: 'session_reloading', sessionId }),
|
|
3259
|
+
});
|
|
3260
|
+
if (!result.started) {
|
|
3261
|
+
refuse(result.error ?? 'The session could not be reloaded.');
|
|
3262
|
+
break;
|
|
3263
|
+
}
|
|
3264
|
+
if (result.closed) {
|
|
3265
|
+
// Deleted / evicted / taken over mid-reload: the path that closed it has
|
|
3266
|
+
// already told its viewers what happened. An error on top would mislead.
|
|
3267
|
+
break;
|
|
3268
|
+
}
|
|
3269
|
+
if (result.error) {
|
|
3270
|
+
// Every current viewer saw session_reloading, so each needs its end.
|
|
3271
|
+
tellViewers({ type: 'session_error', sessionId, error: result.error });
|
|
3272
|
+
break;
|
|
3273
|
+
}
|
|
3274
|
+
tellViewers({
|
|
3275
|
+
type: 'session_ready',
|
|
3276
|
+
sessionId,
|
|
3277
|
+
sessionFile,
|
|
3278
|
+
model: pool.getSession(sessionFile)?.model,
|
|
3279
|
+
isStreaming: pool.isStreaming(sessionFile),
|
|
3280
|
+
contextUsage: pool.getContextUsage(sessionFile) ?? null,
|
|
3281
|
+
});
|
|
3282
|
+
tellViewers({
|
|
3283
|
+
type: 'session_notice',
|
|
3284
|
+
sessionId,
|
|
3285
|
+
level: 'info',
|
|
3286
|
+
message: 'Reloaded extensions, skills, prompts and context files.',
|
|
3287
|
+
});
|
|
3288
|
+
break;
|
|
3289
|
+
}
|
|
3206
3290
|
case 'bash_sudo_password': {
|
|
3207
3291
|
if (!client.sessionId)
|
|
3208
3292
|
return;
|
|
@@ -3227,6 +3311,13 @@ async function handleWSMessage(msg, client, pool, clients, broadcast, onSessions
|
|
|
3227
3311
|
case 'model_change': {
|
|
3228
3312
|
if (!client.sessionId)
|
|
3229
3313
|
return;
|
|
3314
|
+
if (pool.isReloading(client.sessionId)) {
|
|
3315
|
+
// A notice, not session_error: the latter would clear the reload's
|
|
3316
|
+
// composer block on this client before the rebuilt agent is ready.
|
|
3317
|
+
const reloadingId = pool.getSession(client.sessionId)?.sessionId ?? '';
|
|
3318
|
+
sendWS(client.ws, { type: 'session_notice', sessionId: reloadingId, level: 'warning', message: RELOADING_REFUSAL });
|
|
3319
|
+
break;
|
|
3320
|
+
}
|
|
3230
3321
|
const result = await pool.changeModel(client.sessionId, msg.model);
|
|
3231
3322
|
if (result.error) {
|
|
3232
3323
|
sendWS(client.ws, { type: 'session_error', error: result.error });
|