wherever-dev 0.25.0 → 0.26.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 +32 -0
- package/dist/assistant-channels.d.ts +42 -1
- package/dist/assistant-channels.d.ts.map +1 -1
- package/dist/assistant-channels.js +18 -0
- package/dist/assistant-channels.js.map +1 -1
- package/dist/cli-requests.d.ts +7 -0
- package/dist/cli-requests.d.ts.map +1 -1
- package/dist/cli-requests.js +27 -0
- package/dist/cli-requests.js.map +1 -1
- package/dist/index.js +197 -10
- package/dist/index.js.map +1 -1
- package/dist/kenning-delivery.d.ts +42 -0
- package/dist/kenning-delivery.d.ts.map +1 -0
- package/dist/kenning-delivery.js +40 -0
- package/dist/kenning-delivery.js.map +1 -0
- package/dist/kenning-host.d.ts +93 -0
- package/dist/kenning-host.d.ts.map +1 -0
- package/dist/kenning-host.js +165 -0
- package/dist/kenning-host.js.map +1 -0
- package/dist/kenning-human-input.d.ts +70 -0
- package/dist/kenning-human-input.d.ts.map +1 -0
- package/dist/kenning-human-input.js +87 -0
- package/dist/kenning-human-input.js.map +1 -0
- package/dist/kenning-service.d.ts +243 -0
- package/dist/kenning-service.d.ts.map +1 -0
- package/dist/kenning-service.js +516 -0
- package/dist/kenning-service.js.map +1 -0
- package/dist/protocol.d.ts +41 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js.map +1 -1
- package/dist/reply-routing.d.ts +26 -0
- package/dist/reply-routing.d.ts.map +1 -1
- package/dist/reply-routing.js +35 -0
- package/dist/reply-routing.js.map +1 -1
- package/dist/session-pool.d.ts +35 -0
- package/dist/session-pool.d.ts.map +1 -1
- package/dist/session-pool.js +104 -7
- package/dist/session-pool.js.map +1 -1
- package/dist/session-transcript.d.ts.map +1 -1
- package/dist/session-transcript.js +34 -2
- package/dist/session-transcript.js.map +1 -1
- package/dist/session-types.d.ts +24 -1
- package/dist/session-types.d.ts.map +1 -1
- package/dist/telegram-channel.d.ts +51 -0
- package/dist/telegram-channel.d.ts.map +1 -1
- package/dist/telegram-channel.js +105 -5
- package/dist/telegram-channel.js.map +1 -1
- package/package.json +4 -2
- package/public/_app/immutable/assets/0.CBxclSgC.css +1 -0
- package/public/_app/immutable/chunks/{XW0SPyOK.js → B_u4L4CL.js} +2 -2
- package/public/_app/immutable/chunks/{XW0SPyOK.js.map → B_u4L4CL.js.map} +1 -1
- package/public/_app/immutable/chunks/{ClUQt0nO.js → BgzcA-pV.js} +2 -2
- package/public/_app/immutable/chunks/{ClUQt0nO.js.map → BgzcA-pV.js.map} +1 -1
- package/public/_app/immutable/chunks/wWzBzbDK.js +2 -0
- package/public/_app/immutable/chunks/wWzBzbDK.js.map +1 -0
- package/public/_app/immutable/entry/{app.D1EX_9pb.js → app.CBSjrM4B.js} +3 -3
- package/public/_app/immutable/entry/{app.D1EX_9pb.js.map → app.CBSjrM4B.js.map} +1 -1
- package/public/_app/immutable/entry/start.fPf-MumQ.js +2 -0
- package/public/_app/immutable/entry/start.fPf-MumQ.js.map +1 -0
- package/public/_app/immutable/nodes/{0.DsJW22vw.js → 0.hee657hN.js} +3 -3
- package/public/_app/immutable/nodes/{0.DsJW22vw.js.map → 0.hee657hN.js.map} +1 -1
- package/public/_app/immutable/nodes/{1.BsL25UTD.js → 1.eykDFZ1z.js} +2 -2
- package/public/_app/immutable/nodes/{1.BsL25UTD.js.map → 1.eykDFZ1z.js.map} +1 -1
- package/public/_app/immutable/nodes/2.DsE4vG-2.js +127 -0
- package/public/_app/immutable/nodes/2.DsE4vG-2.js.map +1 -0
- package/public/_app/version.json +1 -1
- package/public/index.html +11 -11
- package/public/service-worker.js +1 -1
- package/public/_app/immutable/assets/0.hWfYEET-.css +0 -1
- package/public/_app/immutable/chunks/CRvF0-wF.js +0 -2
- package/public/_app/immutable/chunks/CRvF0-wF.js.map +0 -1
- package/public/_app/immutable/entry/start.ga0QZFSJ.js +0 -2
- package/public/_app/immutable/entry/start.ga0QZFSJ.js.map +0 -1
- package/public/_app/immutable/nodes/2.DO5lRCyx.js +0 -124
- package/public/_app/immutable/nodes/2.DO5lRCyx.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ import { DEFAULT_DOWNLOAD_MAX_BYTES } from './attach-file-tool.js';
|
|
|
29
29
|
import { splitFrame, wantsFrameChunks, FRAME_CHUNK_CHARS } from './frame-chunks.js';
|
|
30
30
|
import { compressCached, isCompressible, negotiateEncoding } from './static-compression.js';
|
|
31
31
|
import { stripHistoryImages, wantsImageRefs, SERVABLE_IMAGE_TYPES } from './history-images.js';
|
|
32
|
+
import { kenningDeliveryOf, stripKenningCards, wantsKenningCards } from './kenning-delivery.js';
|
|
32
33
|
import { readToolResultImage } from './session-transcript.js';
|
|
33
34
|
import { DeltaCoalescer } from './delta-coalescer.js';
|
|
34
35
|
import { UploadStaging, UPLOAD_CAPABILITY, isValidUploadId, parseChunkFrame, CHUNK_FRAME_KIND } from './upload-staging.js';
|
|
@@ -40,6 +41,8 @@ import { execFileSync } from 'node:child_process';
|
|
|
40
41
|
import { runInstall, runUninstall, runServiceStatus, parseInstallOptions, printInstallHelp, } from './commands/install.js';
|
|
41
42
|
import { runConfigCommand } from './commands/config.js';
|
|
42
43
|
import { getWhereverConfigPath } from './config-dir.js';
|
|
44
|
+
import { KenningService } from './kenning-service.js';
|
|
45
|
+
import { registerKenningHost, WhereverKenningHost } from './kenning-host.js';
|
|
43
46
|
const __filename = fileURLToPath(import.meta.url);
|
|
44
47
|
const __dirname = path.dirname(__filename);
|
|
45
48
|
const devStaticPath = path.resolve(__dirname, '../../web/build');
|
|
@@ -902,6 +905,10 @@ let nextFrameChunkId = 1;
|
|
|
902
905
|
// Sockets whose client loads large history images by reference (`imageRefs=1`,
|
|
903
906
|
// see history-images.ts) instead of receiving their base64 inline.
|
|
904
907
|
const imageRefSockets = new WeakSet();
|
|
908
|
+
// Sockets whose client renders kenning's deliveries (`kenning=1`, see
|
|
909
|
+
// kenning-delivery.ts). Every other socket gets history without them and no
|
|
910
|
+
// `kenning_delivery` frame: an older client would show the raw text as a bubble.
|
|
911
|
+
const kenningCardSockets = new WeakSet();
|
|
905
912
|
// Per-socket coalescing of streamed deltas (delta-coalescer.ts): fewer, larger
|
|
906
913
|
// frames, frame order unchanged. "Backed up" = more than 64 KB still unsent.
|
|
907
914
|
const deltaCoalescers = new WeakMap();
|
|
@@ -925,8 +932,16 @@ function sendWS(ws, msg) {
|
|
|
925
932
|
function writeWS(ws, msg) {
|
|
926
933
|
if (ws.readyState === WebSocket.OPEN) {
|
|
927
934
|
try {
|
|
928
|
-
if (
|
|
929
|
-
|
|
935
|
+
if (msg.type === 'message_history' || msg.type === 'message_history_prepend') {
|
|
936
|
+
// `offset` / `totalCount` keep counting the cards, so a client without
|
|
937
|
+
// them pages through the same indices and only gets fewer messages.
|
|
938
|
+
if (!kenningCardSockets.has(ws))
|
|
939
|
+
msg = { ...msg, messages: stripKenningCards(msg.messages) };
|
|
940
|
+
if (imageRefSockets.has(ws))
|
|
941
|
+
msg = { ...msg, messages: stripHistoryImages(msg.messages) };
|
|
942
|
+
}
|
|
943
|
+
else if (msg.type === 'kenning_delivery' && !kenningCardSockets.has(ws)) {
|
|
944
|
+
return;
|
|
930
945
|
}
|
|
931
946
|
const json = JSON.stringify(msg);
|
|
932
947
|
if (chunkingSockets.has(ws) && json.length > FRAME_CHUNK_CHARS) {
|
|
@@ -1257,6 +1272,68 @@ async function main() {
|
|
|
1257
1272
|
jobForSession: (sessionFile) => scheduler.jobForSession(sessionFile),
|
|
1258
1273
|
};
|
|
1259
1274
|
}
|
|
1275
|
+
// wherever as a kenning host (kenning-service.ts): the attention inbox and
|
|
1276
|
+
// presence on every dashboard (`kenning_update`), and blocking items pushed
|
|
1277
|
+
// once through the channels above, a Telegram reply to one answering it. It
|
|
1278
|
+
// opens kenning's database only once that exists, so nothing is written for
|
|
1279
|
+
// a user who does not use kenning. Independent of the assistant: without
|
|
1280
|
+
// active channels the inbox is still on the web, it is just never pushed.
|
|
1281
|
+
const kenningEnabled = getWhereverConfig().kenning?.enabled !== false;
|
|
1282
|
+
// kenning's host for spawn and stop (kenning-host.ts, ADR 0024): registered
|
|
1283
|
+
// for the whole process at start, so a session's `session_spawn` becomes a
|
|
1284
|
+
// sidebar session; it reads kenning through the service below.
|
|
1285
|
+
const kenningHost = new WhereverKenningHost({
|
|
1286
|
+
pool: sessionPool,
|
|
1287
|
+
stateDir: getWhereverStateDir(),
|
|
1288
|
+
kenning: () => kenning.api(),
|
|
1289
|
+
onSpawned: () => broadcastSessionsUpdated(),
|
|
1290
|
+
});
|
|
1291
|
+
const unregisterKenningHost = kenningEnabled ? registerKenningHost(kenningHost) : () => { };
|
|
1292
|
+
const kenning = new KenningService({
|
|
1293
|
+
enabled: kenningEnabled,
|
|
1294
|
+
// Wake an evicted child of ours when a message waits for it (D29's rule).
|
|
1295
|
+
onKenningChange: () => kenningHost.wakeEvicted(),
|
|
1296
|
+
whereverStateDir: getWhereverStateDir(),
|
|
1297
|
+
// The same knob kenning-pi reads (its shared.ts), so one setting speeds up both.
|
|
1298
|
+
pollMs: Number(process.env.KENNING_POLL_MS) || undefined,
|
|
1299
|
+
onUpdate: (snapshot) => {
|
|
1300
|
+
const frame = { type: 'kenning_update', ...snapshot };
|
|
1301
|
+
for (const c of clients.values()) {
|
|
1302
|
+
if (!c.isCliBridge)
|
|
1303
|
+
sendWS(c.ws, frame);
|
|
1304
|
+
}
|
|
1305
|
+
},
|
|
1306
|
+
});
|
|
1307
|
+
kenning.start();
|
|
1308
|
+
// Transcripts of a cascaded delete go only once kenning says the undo window
|
|
1309
|
+
// passed (D24): checked once kenning is open, then hourly.
|
|
1310
|
+
const purgeKenningDeletes = () => {
|
|
1311
|
+
const n = kenning.purgeExpired((file) => {
|
|
1312
|
+
const tracked = sessionPool.getSession(file);
|
|
1313
|
+
if (tracked)
|
|
1314
|
+
void sessionPool.destroySession(tracked.sessionFile, 'deleted');
|
|
1315
|
+
if (sessionPool.isSessionFile(file) && fs.existsSync(file))
|
|
1316
|
+
fs.unlinkSync(file);
|
|
1317
|
+
forgetStar(file);
|
|
1318
|
+
kenningHost.forget(file);
|
|
1319
|
+
});
|
|
1320
|
+
if (n) {
|
|
1321
|
+
console.log(`[wherever] kenning: deleted ${n} transcript(s) whose undo window passed`);
|
|
1322
|
+
broadcastSessionsUpdated();
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
void kenning.ready().then(purgeKenningDeletes);
|
|
1326
|
+
const kenningPurgeTimer = setInterval(purgeKenningDeletes, 60 * 60 * 1000);
|
|
1327
|
+
kenningPurgeTimer.unref?.();
|
|
1328
|
+
if (channelDispatcher) {
|
|
1329
|
+
const dispatcher = channelDispatcher;
|
|
1330
|
+
kenning.setNotifier(async (n) => {
|
|
1331
|
+
const out = await dispatcher.notify({ title: n.title, body: n.body, source: n.source, navigate: n.navigate, question: { options: n.options } });
|
|
1332
|
+
const refs = out.deliveries.flatMap((d) => (d.result.ok ? (d.result.refs ?? []) : []));
|
|
1333
|
+
return out.ok ? { delivered: true, refs } : { delivered: false, refs, error: out.error };
|
|
1334
|
+
});
|
|
1335
|
+
dispatcher.setNotificationReplyHandler((r) => r.channel === 'telegram' ? kenning.answerFromReply(r.ref, r.text, 'telegram') : { handled: false });
|
|
1336
|
+
}
|
|
1260
1337
|
/** The Web Push part of the assistant status (only while active). */
|
|
1261
1338
|
const webPushStatus = () => ({
|
|
1262
1339
|
enabled: !!webPushChannel,
|
|
@@ -1309,7 +1386,11 @@ async function main() {
|
|
|
1309
1386
|
assistantFolder: assistantController && assistant.status.folder ? canonicalPath(assistant.status.folder) : null,
|
|
1310
1387
|
timezone: assistantController ? currentTimezone() : null,
|
|
1311
1388
|
});
|
|
1312
|
-
const cliRequests = createCliRequestRouter({
|
|
1389
|
+
const cliRequests = createCliRequestRouter({
|
|
1390
|
+
assistantInfo: currentAssistantInfo,
|
|
1391
|
+
assistantHooks: () => assistantHooks,
|
|
1392
|
+
kenningHost: () => (kenningEnabled ? kenningHost : null),
|
|
1393
|
+
});
|
|
1313
1394
|
// Push the current assistant info to every connected CLI bridge, which updates
|
|
1314
1395
|
// its cached `assistant_info`. The folder takes effect on restart only, so the
|
|
1315
1396
|
// one runtime change is the user's timezone: the scheduler's
|
|
@@ -1485,12 +1566,33 @@ async function main() {
|
|
|
1485
1566
|
}
|
|
1486
1567
|
case 'message_end': {
|
|
1487
1568
|
const role = event.message?.role;
|
|
1569
|
+
if (role === 'custom') {
|
|
1570
|
+
// A kenning wake (`sendMessage(..., {triggerTurn: true})`) or what its
|
|
1571
|
+
// `before_agent_start` attached. Not a user message: the routing only
|
|
1572
|
+
// ever takes an entry for role `user` (ADR 0014).
|
|
1573
|
+
const d = kenningDeliveryOf(event.message);
|
|
1574
|
+
const t = event.message.timestamp;
|
|
1575
|
+
if (d)
|
|
1576
|
+
msg = { type: 'kenning_delivery', sessionId, content: d.content, timestamp: typeof t === 'number' ? t : Date.now(), kenning: d.kenning };
|
|
1577
|
+
break;
|
|
1578
|
+
}
|
|
1488
1579
|
if (role !== 'assistant' && role !== 'user')
|
|
1489
1580
|
break;
|
|
1490
1581
|
const content = extractText(event.message);
|
|
1491
1582
|
msg = { type: 'message_end', sessionId, content, role };
|
|
1492
1583
|
break;
|
|
1493
1584
|
}
|
|
1585
|
+
case 'entry_appended': {
|
|
1586
|
+
// What kenning returned from `agent_before_settle` / `turn_end`: pi
|
|
1587
|
+
// writes those boundary entries without a message_end.
|
|
1588
|
+
const entry = event.entry;
|
|
1589
|
+
const d = entry?.type === 'custom_message' ? kenningDeliveryOf(entry) : null;
|
|
1590
|
+
if (d) {
|
|
1591
|
+
const t = Date.parse(entry.timestamp);
|
|
1592
|
+
msg = { type: 'kenning_delivery', sessionId, content: d.content, timestamp: Number.isFinite(t) ? t : Date.now(), kenning: d.kenning };
|
|
1593
|
+
}
|
|
1594
|
+
break;
|
|
1595
|
+
}
|
|
1494
1596
|
case 'queue_update': {
|
|
1495
1597
|
// pi's queue changed (a steer was queued, delivered, or cleared). Relay
|
|
1496
1598
|
// the current steering queue so the web can show which messages are
|
|
@@ -1713,7 +1815,23 @@ async function main() {
|
|
|
1713
1815
|
// ?view=readonly returns only the sessions.readOnly folders (the separate
|
|
1714
1816
|
// read-only page); default returns the main list (ignore + readOnly hidden).
|
|
1715
1817
|
const view = url.searchParams.get('view') === 'readonly' ? 'readonly' : 'default';
|
|
1716
|
-
const
|
|
1818
|
+
const listed = await sessionPool.listSessions(view);
|
|
1819
|
+
// kenning (ADR 0024): each session's owner, so the sidebar shows a spawned
|
|
1820
|
+
// session under the session that spawned it, and sessions a cascaded
|
|
1821
|
+
// delete hid (within its undo window) left out. Memoized lookups.
|
|
1822
|
+
const folders = kenning.available
|
|
1823
|
+
? listed
|
|
1824
|
+
.map((f) => ({
|
|
1825
|
+
...f,
|
|
1826
|
+
sessions: f.sessions
|
|
1827
|
+
.filter((s) => !kenning.isArchived(s.path))
|
|
1828
|
+
.map((s) => {
|
|
1829
|
+
const owner = kenning.ownerOf(s.path);
|
|
1830
|
+
return owner ? { ...s, ownerSessionPath: owner } : s;
|
|
1831
|
+
}),
|
|
1832
|
+
}))
|
|
1833
|
+
.filter((f) => f.sessions.length > 0 || listed.find((l) => l.path === f.path)?.sessions.length === 0)
|
|
1834
|
+
: listed;
|
|
1717
1835
|
const active = sessionPool.getActiveSessions();
|
|
1718
1836
|
sendJSON(res, 200, { folders, activeSessions: active });
|
|
1719
1837
|
return;
|
|
@@ -2335,9 +2453,11 @@ async function main() {
|
|
|
2335
2453
|
sendJSON(res, 400, { error: 'Invalid session file: not a session in the sessions directory' });
|
|
2336
2454
|
return;
|
|
2337
2455
|
}
|
|
2338
|
-
//
|
|
2339
|
-
const
|
|
2340
|
-
|
|
2456
|
+
// Close a resident session: its viewers are told, its agent goes.
|
|
2457
|
+
const closeResident = (file) => {
|
|
2458
|
+
const tracked = sessionPool.getSession(file);
|
|
2459
|
+
if (!tracked)
|
|
2460
|
+
return;
|
|
2341
2461
|
const wsMsg = {
|
|
2342
2462
|
type: 'session_destroyed',
|
|
2343
2463
|
sessionId: tracked.sessionId,
|
|
@@ -2353,8 +2473,30 @@ async function main() {
|
|
|
2353
2473
|
clearConflictState(c);
|
|
2354
2474
|
}
|
|
2355
2475
|
}
|
|
2356
|
-
|
|
2476
|
+
if (tracked.type === 'server')
|
|
2477
|
+
sessionPool.destroySession(tracked.sessionFile, 'deleted');
|
|
2478
|
+
};
|
|
2479
|
+
// kenning (D24, ADR 0024): a session that owns others takes them with it,
|
|
2480
|
+
// as ONE undoable batch: all are hidden and their agents closed, and the
|
|
2481
|
+
// transcripts stay until the undo window passed (purgeKenningDeletes). A
|
|
2482
|
+
// session a cascade already hid needs nothing more. Every other session
|
|
2483
|
+
// is deleted at once, as before.
|
|
2484
|
+
if (kenning.isArchived(resolved)) {
|
|
2485
|
+
sendJSON(res, 200, { status: 'deleted' });
|
|
2486
|
+
return;
|
|
2487
|
+
}
|
|
2488
|
+
if (kenning.ownsSessions(resolved)) {
|
|
2489
|
+
const cascade = kenning.deleteCascade(resolved);
|
|
2490
|
+
if (cascade) {
|
|
2491
|
+
for (const file of cascade.sessions)
|
|
2492
|
+
closeResident(file);
|
|
2493
|
+
broadcastSessionsUpdated();
|
|
2494
|
+
sendJSON(res, 200, { status: 'deleted', cascade });
|
|
2495
|
+
return;
|
|
2496
|
+
}
|
|
2357
2497
|
}
|
|
2498
|
+
closeResident(sessionFile);
|
|
2499
|
+
closeResident(resolved);
|
|
2358
2500
|
if (fs.existsSync(resolved)) {
|
|
2359
2501
|
fs.unlinkSync(resolved);
|
|
2360
2502
|
}
|
|
@@ -2833,6 +2975,8 @@ async function main() {
|
|
|
2833
2975
|
chunkingSockets.add(ws);
|
|
2834
2976
|
if (wantsImageRefs(url.searchParams))
|
|
2835
2977
|
imageRefSockets.add(ws);
|
|
2978
|
+
if (wantsKenningCards(url.searchParams))
|
|
2979
|
+
kenningCardSockets.add(ws);
|
|
2836
2980
|
}
|
|
2837
2981
|
catch { }
|
|
2838
2982
|
if (clientKey) {
|
|
@@ -2856,6 +3000,9 @@ async function main() {
|
|
|
2856
3000
|
missedPings.set(ws, 0);
|
|
2857
3001
|
});
|
|
2858
3002
|
sendWS(ws, { type: 'connected', clientId, serverVersion: getVersion(), capabilities: [UPLOAD_CAPABILITY], piVersion: piSdkInfo.version });
|
|
3003
|
+
// The kenning inbox and presence as they are now; live changes follow as
|
|
3004
|
+
// further `kenning_update` frames. A CLI bridge ignores it (unknown frame).
|
|
3005
|
+
sendWS(ws, { type: 'kenning_update', ...kenning.snapshot() });
|
|
2859
3006
|
ws.on('message', async (data, isBinary) => {
|
|
2860
3007
|
// Binary frames are upload chunks (`upload.v1`), routed BEFORE any
|
|
2861
3008
|
// JSON.parse: a chunk is raw bytes, never text. A binary frame that does not
|
|
@@ -2885,7 +3032,7 @@ async function main() {
|
|
|
2885
3032
|
return;
|
|
2886
3033
|
}
|
|
2887
3034
|
try {
|
|
2888
|
-
await handleWSMessage(msg, client, sessionPool, clients, broadcastToSession, broadcastSessionsUpdated, assistantController, cliRequests, onClientTimezone);
|
|
3035
|
+
await handleWSMessage(msg, client, sessionPool, clients, broadcastToSession, broadcastSessionsUpdated, assistantController, cliRequests, onClientTimezone, kenning);
|
|
2889
3036
|
}
|
|
2890
3037
|
catch (err) {
|
|
2891
3038
|
console.error('WS message processing error:', err);
|
|
@@ -3053,6 +3200,9 @@ This encrypts all network traffic securely and enables safe, private remote acce
|
|
|
3053
3200
|
}
|
|
3054
3201
|
assistantScheduler?.stop();
|
|
3055
3202
|
await channelDispatcher?.stop();
|
|
3203
|
+
kenning.stop();
|
|
3204
|
+
unregisterKenningHost();
|
|
3205
|
+
clearInterval(kenningPurgeTimer);
|
|
3056
3206
|
await sessionPool.disposeAll();
|
|
3057
3207
|
assistant.release();
|
|
3058
3208
|
server.close();
|
|
@@ -3407,8 +3557,37 @@ function sendQueueSnapshot(client, sessionFile, sessionId, pool) {
|
|
|
3407
3557
|
return;
|
|
3408
3558
|
sendWS(client.ws, { type: 'queue_update', sessionId, steering });
|
|
3409
3559
|
}
|
|
3410
|
-
async function handleWSMessage(msg, client, pool, clients, broadcast, onSessionsUpdated, assistantController = null, cliRequests = null, onClientTimezone = () => { }) {
|
|
3560
|
+
async function handleWSMessage(msg, client, pool, clients, broadcast, onSessionsUpdated, assistantController = null, cliRequests = null, onClientTimezone = () => { }, kenning = null) {
|
|
3411
3561
|
switch (msg.type) {
|
|
3562
|
+
case 'kenning_undo_delete': {
|
|
3563
|
+
// Undo a cascaded delete (kenning D24) from the web, within its window.
|
|
3564
|
+
const r = client.isCliBridge
|
|
3565
|
+
? { ok: false, error: 'a CLI bridge cannot undo a delete' }
|
|
3566
|
+
: kenning
|
|
3567
|
+
? kenning.undoDelete(msg.batch)
|
|
3568
|
+
: { ok: false, error: 'kenning is not available on this server' };
|
|
3569
|
+
sendWS(client.ws, r.ok ? { type: 'kenning_undo_result', batch: msg.batch, ok: true } : { type: 'kenning_undo_result', batch: msg.batch, ok: false, error: r.error });
|
|
3570
|
+
if (r.ok)
|
|
3571
|
+
onSessionsUpdated();
|
|
3572
|
+
return;
|
|
3573
|
+
}
|
|
3574
|
+
case 'kenning_answer': {
|
|
3575
|
+
// The human answering a kenning attention item from the web: an
|
|
3576
|
+
// authenticated dashboard is a human act (ADR 0003, wherever ADR 0023).
|
|
3577
|
+
// Never from a CLI bridge connection, which an agent's process holds.
|
|
3578
|
+
const r = client.isCliBridge
|
|
3579
|
+
? { ok: false, error: 'a CLI bridge cannot answer the inbox' }
|
|
3580
|
+
: kenning
|
|
3581
|
+
? kenning.answer(msg.itemId, msg.text, 'web')
|
|
3582
|
+
: { ok: false, error: 'kenning is not available on this server' };
|
|
3583
|
+
sendWS(client.ws, {
|
|
3584
|
+
type: 'kenning_answer_result',
|
|
3585
|
+
itemId: msg.itemId,
|
|
3586
|
+
...(typeof msg.requestId === 'string' ? { requestId: msg.requestId } : {}),
|
|
3587
|
+
...r,
|
|
3588
|
+
});
|
|
3589
|
+
return;
|
|
3590
|
+
}
|
|
3412
3591
|
case 'client_timezone':
|
|
3413
3592
|
// The web's timezone report when its device moved (see onClientTimezone in main).
|
|
3414
3593
|
onClientTimezone({ timezone: msg.timezone, first: msg.first });
|
|
@@ -4061,6 +4240,14 @@ async function handleWSMessage(msg, client, pool, clients, broadcast, onSessions
|
|
|
4061
4240
|
break;
|
|
4062
4241
|
}
|
|
4063
4242
|
case 'message': {
|
|
4243
|
+
// A user message is a dashboard's (origin `none`, which the pool marks as
|
|
4244
|
+
// the human's for kenning, ADR 0023). A CLI bridge connection is held by
|
|
4245
|
+
// an agent's process: it relays its terminal's input as `cli_event`, never
|
|
4246
|
+
// as `message`, so refuse it rather than let it mark text as human.
|
|
4247
|
+
if (client.isCliBridge) {
|
|
4248
|
+
sendWS(client.ws, { type: 'session_error', sessionId: msg.sessionId, error: 'A CLI bridge connection cannot send user messages.' });
|
|
4249
|
+
return;
|
|
4250
|
+
}
|
|
4064
4251
|
// The session's working folder does not exist on this machine, so no live
|
|
4065
4252
|
// agent was built for it and there is nothing to attach to (which would
|
|
4066
4253
|
// otherwise make this a SILENT drop on the sessionId check below). Refuse
|