@thready-web/dsh-bot-plugin 0.1.0-beta.10 → 0.1.0-beta.12
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/README.md +19 -2
- package/dist/approvals.js +19 -1
- package/dist/canvas-compose.js +73 -0
- package/dist/canvas-http.js +379 -0
- package/dist/canvas-skills.js +56 -0
- package/dist/canvas-store.js +1015 -0
- package/dist/canvas-tools.js +380 -0
- package/dist/card-log.js +216 -0
- package/dist/context.js +6 -3
- package/dist/deleting.js +54 -0
- package/dist/desk-ledger.js +18 -0
- package/dist/desk.js +30 -5
- package/dist/http-plugin.js +2 -1
- package/dist/http.js +218 -3
- package/dist/inbox.js +24 -2
- package/dist/index.js +75 -12
- package/dist/questions.js +10 -0
- package/dist/runtime-registry.js +20 -0
- package/dist/session-delete-job.js +77 -0
- package/dist/session-files.js +33 -1
- package/dist/session-wipe.js +204 -0
- package/dist/store.js +46 -3
- package/dist/triggers.js +8 -0
- package/dist/work-admit.js +9 -20
- package/dist/work-child.js +27 -10
- package/dist/work-http.js +19 -0
- package/dist/work-ledger.js +5 -1
- package/dist/work-mock.js +10 -0
- package/dist/work-tickets.js +5 -3
- package/dist/work-tools.js +11 -9
- package/dist/work-worker.js +245 -6
- package/dist/worker-handles.js +33 -0
- package/dist/workspace-files.js +98 -17
- package/package.json +2 -1
- package/public/assets/{SourceEditor-BEQaScgR.js → SourceEditor-BjtoMvcX.js} +3 -3
- package/public/assets/{cssMode-gpcjCFFS.js → cssMode--96PQtWh.js} +1 -1
- package/public/assets/{freemarker2-C1qemGIt.js → freemarker2-Bz-HlISL.js} +1 -1
- package/public/assets/{handlebars-sZqIfAlP.js → handlebars-D9ScJ8AM.js} +1 -1
- package/public/assets/{html-Bn1WXB8L.js → html-Czc0jojJ.js} +1 -1
- package/public/assets/{htmlMode-CvQyXnaW.js → htmlMode-CCww5Z1w.js} +1 -1
- package/public/assets/index-DRCgKxWk.css +1 -0
- package/public/assets/index-ztUdW074.js +72 -0
- package/public/assets/{javascript-Ox4Jg12j.js → javascript-B-yRZSiz.js} +1 -1
- package/public/assets/{jsonMode-DMR7R2dQ.js → jsonMode-ASWsY833.js} +1 -1
- package/public/assets/{liquid-B6HxtpBd.js → liquid-BGoox2vJ.js} +1 -1
- package/public/assets/{mdx--jDhmrXq.js → mdx-DHgvnl_U.js} +1 -1
- package/public/assets/{python-YjG50skX.js → python-BJvVD30_.js} +1 -1
- package/public/assets/{razor-CEcFE3UK.js → razor-0PwR35mu.js} +1 -1
- package/public/assets/{tsMode-g4kTQl09.js → tsMode-3ETp8Gdh.js} +1 -1
- package/public/assets/{typescript-CnHeFmPW.js → typescript-BT0iTK6K.js} +1 -1
- package/public/assets/{xml-BFXMY9nb.js → xml-BTaNc_uT.js} +1 -1
- package/public/assets/{yaml-DNm87nSf.js → yaml-Dr7LW3tK.js} +1 -1
- package/public/index.html +2 -2
- package/skills/ui/baseline-ui/SKILL.md +85 -0
- package/skills/ui/bencium-innovative-ux-designer/SKILL.md +227 -0
- package/skills/ui/better-ui/SKILL.md +133 -0
- package/skills/ui/design-lab/SKILL.md +920 -0
- package/skills/ui/frontend-design/SKILL.md +71 -0
- package/skills/ui/impeccable/SKILL.md +93 -0
- package/skills/ui/interface-design/SKILL.md +320 -0
- package/skills/ui/sources.json +66 -0
- package/skills/ui/ui-design/SKILL.md +41 -0
- package/skills/ui/ui-skills-root/SKILL.md +59 -0
- package/skills/ui/visual-design-foundations/SKILL.md +318 -0
- package/skills/ui/web-design-guidelines/SKILL.md +39 -0
- package/public/assets/index-DRNkUrer.css +0 -1
- package/public/assets/index-DhL5Kdlz.js +0 -63
package/dist/deleting.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Sessions whose turns must not start. A failed delete keeps the fence. */
|
|
2
|
+
const fenced = new Set();
|
|
3
|
+
export function isFenced(sessionId) {
|
|
4
|
+
return sessionId !== '' && fenced.has(sessionId);
|
|
5
|
+
}
|
|
6
|
+
export function fence(sessionIds) {
|
|
7
|
+
for (const id of sessionIds)
|
|
8
|
+
if (id !== '')
|
|
9
|
+
fenced.add(id);
|
|
10
|
+
}
|
|
11
|
+
export function unfence(sessionIds) {
|
|
12
|
+
for (const id of sessionIds)
|
|
13
|
+
fenced.delete(id);
|
|
14
|
+
}
|
|
15
|
+
const jobs = new Map();
|
|
16
|
+
/**
|
|
17
|
+
* Start a delete, or join the one already running for this bot.
|
|
18
|
+
* A finished job is replayed. A failed job starts again.
|
|
19
|
+
* The run is deferred so the caller can listen before the first event.
|
|
20
|
+
*/
|
|
21
|
+
export function beginDelete(ownerId, run) {
|
|
22
|
+
const existing = jobs.get(ownerId);
|
|
23
|
+
if (existing && existing.latest.phase !== 'error' && existing.latest.phase !== 'done')
|
|
24
|
+
return existing;
|
|
25
|
+
if (existing?.latest.phase === 'done')
|
|
26
|
+
return existing;
|
|
27
|
+
const listeners = existing?.listeners ?? new Set();
|
|
28
|
+
const job = {
|
|
29
|
+
ownerId,
|
|
30
|
+
latest: { phase: 'fence', percent: 10 },
|
|
31
|
+
listeners,
|
|
32
|
+
promise: Promise.resolve(),
|
|
33
|
+
listen(listener) {
|
|
34
|
+
listeners.add(listener);
|
|
35
|
+
},
|
|
36
|
+
unlisten(listener) {
|
|
37
|
+
listeners.delete(listener);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
const publish = (event) => {
|
|
41
|
+
job.latest = event;
|
|
42
|
+
for (const listener of listeners)
|
|
43
|
+
listener(event);
|
|
44
|
+
};
|
|
45
|
+
job.promise = Promise.resolve().then(() => run(publish).catch((error) => {
|
|
46
|
+
const message = error instanceof Error ? error.message : 'delete failed';
|
|
47
|
+
publish({ phase: 'error', percent: job.latest.percent, error: message });
|
|
48
|
+
}));
|
|
49
|
+
jobs.set(ownerId, job);
|
|
50
|
+
return job;
|
|
51
|
+
}
|
|
52
|
+
export function deleteStatus(ownerId) {
|
|
53
|
+
return jobs.get(ownerId)?.latest ?? null;
|
|
54
|
+
}
|
package/dist/desk-ledger.js
CHANGED
|
@@ -80,6 +80,24 @@ export function openLedger(file) {
|
|
|
80
80
|
tasks() {
|
|
81
81
|
return tasksOf().sort((a, b) => (a.createdAt < b.createdAt ? 1 : -1));
|
|
82
82
|
},
|
|
83
|
+
/** Drop idempotency rows and tasks that point at one deleted session. */
|
|
84
|
+
forgetSession(sessionId) {
|
|
85
|
+
let changed = false;
|
|
86
|
+
for (const [key, record] of Object.entries(state.sessions)) {
|
|
87
|
+
if (record.sessionId !== sessionId)
|
|
88
|
+
continue;
|
|
89
|
+
delete state.sessions[key];
|
|
90
|
+
changed = true;
|
|
91
|
+
}
|
|
92
|
+
for (const [key, record] of Object.entries(state.tasks)) {
|
|
93
|
+
if (record.sessionId !== sessionId)
|
|
94
|
+
continue;
|
|
95
|
+
delete state.tasks[key];
|
|
96
|
+
changed = true;
|
|
97
|
+
}
|
|
98
|
+
if (changed)
|
|
99
|
+
save();
|
|
100
|
+
},
|
|
83
101
|
};
|
|
84
102
|
}
|
|
85
103
|
/**
|
package/dist/desk.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/** Workbench routes inside the DSH process. The browser calls /dsh-bot/api. */
|
|
2
2
|
import { mkdirSync, readFileSync } from 'node:fs';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
3
|
import { dirname, join, resolve } from 'node:path';
|
|
5
4
|
import { Readable } from 'node:stream';
|
|
6
5
|
import { openLedger, validIdempotencyKey } from "./desk-ledger.js";
|
|
7
6
|
import { openSessionPreviews } from "./session-previews.js";
|
|
7
|
+
import { isFenced } from "./deleting.js";
|
|
8
8
|
import { purgeSessionFiles, sessionDirectory, writeBotMarker } from "./session-files.js";
|
|
9
|
-
import { MAX_UPLOAD_BYTES, listDirectory, openDownload, readFileText, resolveFileRoots, saveUploadFile, } from "./workspace-files.js";
|
|
9
|
+
import { MAX_UPLOAD_BYTES, listDirectory, openDownload, readFileText, resolveFileRoots, saveUploadFile, selectBrowserHome, } from "./workspace-files.js";
|
|
10
10
|
/**
|
|
11
11
|
* Working directory for workbench-created sessions. THREADY_SESSION_CWD wins;
|
|
12
12
|
* otherwise <DSH_HOME>/workspace, so the model does not start inside DSH_HOME
|
|
@@ -48,7 +48,7 @@ const SECRET_KEY = /token|secret|password|authorization|api[-_]?key|cookie/i;
|
|
|
48
48
|
* @param {(sessionId: string) => boolean} [options.stillAttached]
|
|
49
49
|
* @param {(endpoint: string, args: Record<string, unknown>, req: DeskRequest) => Promise<{ status: number, body: RpcEnvelope }>} options.rpc
|
|
50
50
|
* @param {(req: DeskRequest) => Promise<Record<string, unknown>>} options.usage
|
|
51
|
-
* @param {{ home: string, dshHome: string }} [options.files] Browser roots.
|
|
51
|
+
* @param {{ home: string, dshHome: string }} [options.files] Browser roots. Home is an explicit safe directory, not process HOME. DSH_HOME stays closed.
|
|
52
52
|
*/
|
|
53
53
|
export function createDesk(options) {
|
|
54
54
|
const ledger = openLedger(options.ledgerFile);
|
|
@@ -139,6 +139,12 @@ export function createDesk(options) {
|
|
|
139
139
|
saveUpload(req, url) {
|
|
140
140
|
return uploadFile(req, url.searchParams.get('sessionId') ?? '', url.searchParams.get('dir') ?? '', url.searchParams.get('name') ?? '', url.searchParams.get('overwrite') === '1');
|
|
141
141
|
},
|
|
142
|
+
forgetSessions(sessionIds) {
|
|
143
|
+
for (const sessionId of sessionIds) {
|
|
144
|
+
sessionPreviews.forget(sessionId);
|
|
145
|
+
ledger.forgetSession(sessionId);
|
|
146
|
+
}
|
|
147
|
+
},
|
|
142
148
|
};
|
|
143
149
|
/**
|
|
144
150
|
* @param {DeskRequest} req
|
|
@@ -508,8 +514,18 @@ export function createDesk(options) {
|
|
|
508
514
|
const cwd = await workspaceCwd(req, sessionId);
|
|
509
515
|
if (typeof cwd !== 'string')
|
|
510
516
|
return cwd;
|
|
511
|
-
const files = options.files ?? {
|
|
512
|
-
|
|
517
|
+
const files = options.files ?? {
|
|
518
|
+
home: selectBrowserHome(process.env, undefined),
|
|
519
|
+
dshHome: process.env.DSH_HOME ?? '',
|
|
520
|
+
};
|
|
521
|
+
return {
|
|
522
|
+
access: resolveFileRoots({
|
|
523
|
+
workspace: cwd,
|
|
524
|
+
home: files.home,
|
|
525
|
+
dshHome: files.dshHome,
|
|
526
|
+
legacyWorkspace: options.sessionCwd,
|
|
527
|
+
}),
|
|
528
|
+
};
|
|
513
529
|
}
|
|
514
530
|
/**
|
|
515
531
|
* @param {DeskRequest} req
|
|
@@ -626,6 +642,15 @@ export function createDesk(options) {
|
|
|
626
642
|
* @param {string} requestId
|
|
627
643
|
*/
|
|
628
644
|
async function deliverPrompt(req, sessionId, text, requestId) {
|
|
645
|
+
if (isFenced(sessionId)) {
|
|
646
|
+
return {
|
|
647
|
+
ok: false,
|
|
648
|
+
status: 409,
|
|
649
|
+
error: 'deleting',
|
|
650
|
+
reason: 'This session is being deleted.',
|
|
651
|
+
upstreamCode: '',
|
|
652
|
+
};
|
|
653
|
+
}
|
|
629
654
|
const running = await sessionRunning(req, sessionId);
|
|
630
655
|
if (running === null) {
|
|
631
656
|
return {
|
package/dist/http-plugin.js
CHANGED
|
@@ -13,7 +13,7 @@ export const inject = ['webServer', 'agents', 'sessionPersistence', 'sessionQuer
|
|
|
13
13
|
* Local management routes for the same SQLite the main plugin uses.
|
|
14
14
|
* Loaded only on profiles that have a web server, so headless does not need it.
|
|
15
15
|
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
16
|
-
* @param {{ dataDir?: string }} [config]
|
|
16
|
+
* @param {{ dataDir?: string, files?: { home?: unknown } }} [config]
|
|
17
17
|
*/
|
|
18
18
|
export function apply(ctx, config = {}) {
|
|
19
19
|
const dataDir = config.dataDir ?? (ctx.profileContext?.dir ? join(ctx.profileContext.dir, 'session-foundations') : '');
|
|
@@ -39,5 +39,6 @@ export function apply(ctx, config = {}) {
|
|
|
39
39
|
registerHttp(ctx, engine, () => runtimeFor(key) ?? runtimeFor(dataDir), () => workRuntimeFor(key) ?? workRuntimeFor(dataDir), dataDir, () => questionAnswererFor(key) ?? questionAnswererFor(dataDir), {
|
|
40
40
|
getApprovals: () => approvalAnswererFor(key) ?? approvalAnswererFor(dataDir),
|
|
41
41
|
getAuthorization: () => authorizationFor(key) ?? authorizationFor(dataDir),
|
|
42
|
+
filesHome: config.files?.home,
|
|
42
43
|
});
|
|
43
44
|
}
|
package/dist/http.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { createReadStream, statSync } from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { request as httpRequest } from 'node:http';
|
|
3
|
+
import { connect as connectSocket } from 'node:net';
|
|
4
|
+
import { dirname, extname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { beginDelete, deleteStatus } from "./deleting.js";
|
|
5
7
|
import { createDesk, defaultSessionCwd } from "./desk.js";
|
|
8
|
+
import { dropSessions } from "./runtime-registry.js";
|
|
9
|
+
import { executeDelete } from "./session-delete-job.js";
|
|
6
10
|
import { serveWorkspaceImage } from "./workspace-image.js";
|
|
11
|
+
import { selectBrowserHome } from "./workspace-files.js";
|
|
7
12
|
import { toolError } from "./errors.js";
|
|
8
13
|
import { permissionView, setPermission } from "./permissions.js";
|
|
9
14
|
import { cuaAction, cuaSnapshot } from "./cua-access.js";
|
|
@@ -14,6 +19,9 @@ import { createLogSource } from "./log/source.js";
|
|
|
14
19
|
import { createLogSnapshotService } from "./log/snapshot-service.js";
|
|
15
20
|
import { dispatchLogRequest, probeConnection, registerLogRoutes } from "./log/routes.js";
|
|
16
21
|
import { handleMemoryRoute } from "./memory-catalog.js";
|
|
22
|
+
import { handleCanvasApi, serveCanvasInspect, serveCanvasMedia } from "./canvas-http.js";
|
|
23
|
+
import { openCanvasStore } from "./canvas-store.js";
|
|
24
|
+
import { bindCanvasCards } from "./card-log.js";
|
|
17
25
|
/**
|
|
18
26
|
* Local management routes. Model tools cannot confirm a persona or change revocation.
|
|
19
27
|
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
@@ -27,6 +35,9 @@ export function registerHttp(ctx, engine, getRuntime = () => null, getWork = ()
|
|
|
27
35
|
const webServer = ctx.webServer;
|
|
28
36
|
const storeDir = dataDir || (ctx.profileContext?.dir ? join(ctx.profileContext.dir, 'session-foundations') : '');
|
|
29
37
|
const profileDir = ctx.profileContext?.dir || (storeDir !== '' ? dirname(storeDir) : '');
|
|
38
|
+
const canvas = storeDir === '' ? null : openCanvasStore(join(storeDir, 'canvas.sqlite'));
|
|
39
|
+
if (canvas && storeDir !== '')
|
|
40
|
+
bindCanvasCards(canvas, ctx, storeDir);
|
|
30
41
|
const logService = createLogSnapshotService(createLogSource(ctx));
|
|
31
42
|
const logOnConnection = registerLogRoutes(ctx, logService);
|
|
32
43
|
const persistence = ctx.sessionPersistence;
|
|
@@ -51,7 +62,10 @@ export function registerHttp(ctx, engine, getRuntime = () => null, getWork = ()
|
|
|
51
62
|
stillAttached: sessionId => attachedSession(ctx, sessionId),
|
|
52
63
|
rpc: (endpoint, args, req) => hostRpc(req, endpoint, args),
|
|
53
64
|
usage: req => hostUsage(req),
|
|
54
|
-
files: {
|
|
65
|
+
files: {
|
|
66
|
+
home: selectBrowserHome(process.env, extras.filesHome),
|
|
67
|
+
dshHome: process.env.DSH_HOME ?? '',
|
|
68
|
+
},
|
|
55
69
|
});
|
|
56
70
|
/**
|
|
57
71
|
* @param {import('node:http').IncomingMessage} req
|
|
@@ -88,7 +102,48 @@ export function registerHttp(ctx, engine, getRuntime = () => null, getWork = ()
|
|
|
88
102
|
},
|
|
89
103
|
};
|
|
90
104
|
}
|
|
105
|
+
const stateRoot = sessionsRoot !== '' ? dirname(sessionsRoot) : '';
|
|
106
|
+
function sessionDeleteRoute(res, req, ownerId, statusOnly) {
|
|
107
|
+
if (statusOnly)
|
|
108
|
+
return send(res, 200, deleteStatus(ownerId) ?? { phase: 'absent', percent: 0 });
|
|
109
|
+
const job = beginDelete(ownerId, publish => executeDelete({
|
|
110
|
+
store: engine.store,
|
|
111
|
+
canvas,
|
|
112
|
+
sessionsRoot,
|
|
113
|
+
stateRoot,
|
|
114
|
+
running: sessionId => sessionListedRunning(req, sessionId),
|
|
115
|
+
stop: sessionId => stopForDelete(ctx, sessionId),
|
|
116
|
+
silence: sessionId => {
|
|
117
|
+
getWork()?.silence(sessionId);
|
|
118
|
+
},
|
|
119
|
+
cancelQuestions: sessionId => {
|
|
120
|
+
getQuestions()?.cancelSession(sessionId);
|
|
121
|
+
},
|
|
122
|
+
abandonApprovals: sessionId => {
|
|
123
|
+
getApprovals()?.abandonSession(sessionId);
|
|
124
|
+
},
|
|
125
|
+
forgetDesk: sessionIds => {
|
|
126
|
+
desk?.forgetSessions(sessionIds);
|
|
127
|
+
},
|
|
128
|
+
dropMemory: sessionIds => {
|
|
129
|
+
for (const sessionId of sessionIds) {
|
|
130
|
+
engine.openViews.delete(sessionId);
|
|
131
|
+
engine.surface.delete(sessionId);
|
|
132
|
+
}
|
|
133
|
+
dropSessions(engine.store.root, sessionIds);
|
|
134
|
+
},
|
|
135
|
+
}, ownerId, publish));
|
|
136
|
+
writeDeleteStream(res, job);
|
|
137
|
+
}
|
|
91
138
|
const handler = async (req, res) => {
|
|
139
|
+
const requestTarget = req.url ?? '/';
|
|
140
|
+
if ((requestTarget.split('?')[0] ?? '').startsWith('/dsh-bot/canvas-media/')) {
|
|
141
|
+
return serveCanvasMedia(req, res, requestTarget, canvas);
|
|
142
|
+
}
|
|
143
|
+
if ((requestTarget.split('?')[0] ?? '') === '/dsh-bot/canvas-inspector.js' ||
|
|
144
|
+
(requestTarget.split('?')[0] ?? '').startsWith('/dsh-bot/canvas-inspect/')) {
|
|
145
|
+
return serveCanvasInspect(req, res, requestTarget, canvas);
|
|
146
|
+
}
|
|
92
147
|
const rejection = reject(ctx, req);
|
|
93
148
|
if (rejection)
|
|
94
149
|
return send(res, rejection, { ok: false, code: 'FORBIDDEN' });
|
|
@@ -100,6 +155,8 @@ export function registerHttp(ctx, engine, getRuntime = () => null, getWork = ()
|
|
|
100
155
|
return sendFetchResponse(res, response);
|
|
101
156
|
}
|
|
102
157
|
if (rawPath === '/dsh-bot' || (rawPath.startsWith('/dsh-bot/') && !rawPath.startsWith('/dsh-bot/api'))) {
|
|
158
|
+
if (await proxyDevUi(req, res))
|
|
159
|
+
return;
|
|
103
160
|
if (serveDesk(req, res, rawPath))
|
|
104
161
|
return;
|
|
105
162
|
if (serveWorkspaceImage(req, res, rawPath, defaultSessionCwd(process.env, { mkdir: false })))
|
|
@@ -120,6 +177,10 @@ export function registerHttp(ctx, engine, getRuntime = () => null, getWork = ()
|
|
|
120
177
|
res.on('finish', () => req.destroy());
|
|
121
178
|
return;
|
|
122
179
|
}
|
|
180
|
+
const sessionDelete = path.match(/^\/session-foundations\/api\/sessions\/(session-[A-Za-z0-9-]+)\/delete$/);
|
|
181
|
+
if (sessionDelete && (req.method === 'GET' || req.method === 'POST')) {
|
|
182
|
+
return sessionDeleteRoute(res, req, sessionDelete[1], req.method === 'GET');
|
|
183
|
+
}
|
|
123
184
|
if (desk && desk.owns(req.method ?? 'GET', path)) {
|
|
124
185
|
const outcome = await desk.handle(req.method ?? 'GET', path, url, req);
|
|
125
186
|
return send(res, outcome.status, outcome.body);
|
|
@@ -409,6 +470,7 @@ export function registerHttp(ctx, engine, getRuntime = () => null, getWork = ()
|
|
|
409
470
|
workBoard: () => work.liveBoardAll(),
|
|
410
471
|
loadDesk: () => loadPageDesk(req),
|
|
411
472
|
interactions: () => interactionSnapshot(url.searchParams.get('sessionId') ?? '', true),
|
|
473
|
+
...(canvas ? { canvas: () => canvas.live(url.searchParams.get('sessionId') ?? '') } : {}),
|
|
412
474
|
});
|
|
413
475
|
}
|
|
414
476
|
if (req.method === 'GET' && path === '/session-foundations/api/work/live') {
|
|
@@ -417,6 +479,11 @@ export function registerHttp(ctx, engine, getRuntime = () => null, getWork = ()
|
|
|
417
479
|
return send(res, 503, toolError('UNAVAILABLE', 'The work host is not attached yet.'));
|
|
418
480
|
return openWorkLive(req, res, url.searchParams.get('sessionId') ?? '', work);
|
|
419
481
|
}
|
|
482
|
+
if (canvas &&
|
|
483
|
+
(path === '/session-foundations/api/canvas' || path.startsWith('/session-foundations/api/canvas/'))) {
|
|
484
|
+
const outcome = await handleCanvasApi(req, path, url, canvas);
|
|
485
|
+
return send(res, outcome.status, outcome.body);
|
|
486
|
+
}
|
|
420
487
|
if (path.startsWith('/session-foundations/api/work')) {
|
|
421
488
|
const workBody = req.method === 'GET' ? {} : await readJson(req);
|
|
422
489
|
const workHit = await handleWorkApi(req.method ?? 'GET', path, url, workBody, getWork());
|
|
@@ -462,6 +529,18 @@ export function registerHttp(ctx, engine, getRuntime = () => null, getWork = ()
|
|
|
462
529
|
path: '/api/dsh-bot',
|
|
463
530
|
handler,
|
|
464
531
|
});
|
|
532
|
+
const disposeUpgrade = devUiSocket() && typeof webServer.registerUpgrade === 'function'
|
|
533
|
+
? webServer.registerUpgrade({
|
|
534
|
+
path: '/dsh-bot/',
|
|
535
|
+
handler: (req, socket, head) => {
|
|
536
|
+
if (reject(ctx, req)) {
|
|
537
|
+
socket.destroy();
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
proxyDevUpgrade(req, socket, head);
|
|
541
|
+
},
|
|
542
|
+
})
|
|
543
|
+
: null;
|
|
465
544
|
return () => {
|
|
466
545
|
if (typeof disposeFoundations === 'function')
|
|
467
546
|
disposeFoundations();
|
|
@@ -469,6 +548,14 @@ export function registerHttp(ctx, engine, getRuntime = () => null, getWork = ()
|
|
|
469
548
|
disposeDesk();
|
|
470
549
|
if (typeof disposeLog === 'function')
|
|
471
550
|
disposeLog();
|
|
551
|
+
if (typeof disposeUpgrade === 'function')
|
|
552
|
+
disposeUpgrade();
|
|
553
|
+
try {
|
|
554
|
+
canvas?.close();
|
|
555
|
+
}
|
|
556
|
+
catch {
|
|
557
|
+
/* closed */
|
|
558
|
+
}
|
|
472
559
|
};
|
|
473
560
|
});
|
|
474
561
|
}
|
|
@@ -725,6 +812,58 @@ function readJson(req) {
|
|
|
725
812
|
* @param {string} endpoint
|
|
726
813
|
* @param {Record<string, unknown>} args
|
|
727
814
|
*/
|
|
815
|
+
async function sessionListedRunning(req, sessionId) {
|
|
816
|
+
const listed = await hostRpc(req, 'session/list', { _request: {} });
|
|
817
|
+
const items = listed.body?.result?.value?.items;
|
|
818
|
+
if (listed.body?.result?.ok !== true || !Array.isArray(items))
|
|
819
|
+
return null;
|
|
820
|
+
const item = items.find((entry) => entry?.sessionId === sessionId);
|
|
821
|
+
if (!item)
|
|
822
|
+
return false;
|
|
823
|
+
return item.running === true;
|
|
824
|
+
}
|
|
825
|
+
async function stopForDelete(ctx, sessionId) {
|
|
826
|
+
let timer;
|
|
827
|
+
const stopped = await Promise.race([
|
|
828
|
+
unloadAttachedSession(ctx, sessionId).then(() => true, () => true),
|
|
829
|
+
new Promise(resolve => {
|
|
830
|
+
timer = setTimeout(() => resolve(false), 15_000);
|
|
831
|
+
}),
|
|
832
|
+
]);
|
|
833
|
+
clearTimeout(timer);
|
|
834
|
+
return stopped;
|
|
835
|
+
}
|
|
836
|
+
function writeDeleteStream(res, job) {
|
|
837
|
+
res.writeHead(200, {
|
|
838
|
+
'content-type': 'application/x-ndjson; charset=utf-8',
|
|
839
|
+
'cache-control': 'no-store',
|
|
840
|
+
});
|
|
841
|
+
let finished = false;
|
|
842
|
+
const write = (event) => {
|
|
843
|
+
if (finished || res.writableEnded)
|
|
844
|
+
return;
|
|
845
|
+
res.write(`${JSON.stringify(event)}\n`);
|
|
846
|
+
};
|
|
847
|
+
const finish = () => {
|
|
848
|
+
if (finished)
|
|
849
|
+
return;
|
|
850
|
+
finished = true;
|
|
851
|
+
job.unlisten(listener);
|
|
852
|
+
if (!res.writableEnded)
|
|
853
|
+
res.end();
|
|
854
|
+
};
|
|
855
|
+
const listener = (event) => {
|
|
856
|
+
write(event);
|
|
857
|
+
if (event.phase === 'done' || event.phase === 'error')
|
|
858
|
+
finish();
|
|
859
|
+
};
|
|
860
|
+
job.listen(listener);
|
|
861
|
+
write(job.latest);
|
|
862
|
+
res.on('close', () => {
|
|
863
|
+
job.unlisten(listener);
|
|
864
|
+
});
|
|
865
|
+
void job.promise.finally(finish);
|
|
866
|
+
}
|
|
728
867
|
async function hostRpc(req, endpoint, args) {
|
|
729
868
|
const origin = localOrigin(req);
|
|
730
869
|
const cookie = header(req, 'cookie') ?? '';
|
|
@@ -828,6 +967,82 @@ const DESK_TYPES = new Map([
|
|
|
828
967
|
['.woff2', 'font/woff2'],
|
|
829
968
|
['.ttf', 'font/ttf'],
|
|
830
969
|
]);
|
|
970
|
+
/**
|
|
971
|
+
* Absolute Unix socket where the dev Vite server listens.
|
|
972
|
+
* Unset in production, where `/dsh-bot/` is read from `public/`.
|
|
973
|
+
*/
|
|
974
|
+
export function devUiSocket() {
|
|
975
|
+
const raw = process.env.DSH_BOT_UI_DEV;
|
|
976
|
+
if (!raw || !isAbsolute(raw))
|
|
977
|
+
return null;
|
|
978
|
+
return raw;
|
|
979
|
+
}
|
|
980
|
+
/**
|
|
981
|
+
* Forward one workbench document or asset to the Vite socket.
|
|
982
|
+
* A connection failure returns false so the caller can serve `public/`.
|
|
983
|
+
*/
|
|
984
|
+
export function proxyDevUi(req, res) {
|
|
985
|
+
const socketPath = devUiSocket();
|
|
986
|
+
if (!socketPath)
|
|
987
|
+
return Promise.resolve(false);
|
|
988
|
+
return new Promise(resolvePromise => {
|
|
989
|
+
let settled = false;
|
|
990
|
+
const finish = (proxied) => {
|
|
991
|
+
if (settled)
|
|
992
|
+
return;
|
|
993
|
+
settled = true;
|
|
994
|
+
resolvePromise(proxied);
|
|
995
|
+
};
|
|
996
|
+
const headers = { ...req.headers };
|
|
997
|
+
delete headers.connection;
|
|
998
|
+
delete headers['transfer-encoding'];
|
|
999
|
+
const proxy = httpRequest({
|
|
1000
|
+
socketPath,
|
|
1001
|
+
method: req.method,
|
|
1002
|
+
path: req.url,
|
|
1003
|
+
headers,
|
|
1004
|
+
}, upstream => {
|
|
1005
|
+
res.writeHead(upstream.statusCode ?? 502, upstream.headers);
|
|
1006
|
+
upstream.pipe(res);
|
|
1007
|
+
finish(true);
|
|
1008
|
+
});
|
|
1009
|
+
proxy.on('error', () => {
|
|
1010
|
+
proxy.destroy();
|
|
1011
|
+
finish(false);
|
|
1012
|
+
});
|
|
1013
|
+
req.pipe(proxy);
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
/** Forward the workbench hot-reload upgrade to the Vite socket. */
|
|
1017
|
+
export function proxyDevUpgrade(req, socket, head) {
|
|
1018
|
+
const socketPath = devUiSocket();
|
|
1019
|
+
if (!socketPath) {
|
|
1020
|
+
socket.destroy();
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
const upstream = connectSocket(socketPath);
|
|
1024
|
+
const fail = () => {
|
|
1025
|
+
upstream.destroy();
|
|
1026
|
+
socket.destroy();
|
|
1027
|
+
};
|
|
1028
|
+
upstream.on('error', fail);
|
|
1029
|
+
socket.on('error', () => upstream.destroy());
|
|
1030
|
+
upstream.once('connect', () => {
|
|
1031
|
+
const lines = [`${req.method ?? 'GET'} ${req.url ?? '/'} HTTP/1.1`];
|
|
1032
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
1033
|
+
if (value == null || key === 'transfer-encoding')
|
|
1034
|
+
continue;
|
|
1035
|
+
const items = Array.isArray(value) ? value : [value];
|
|
1036
|
+
for (const item of items)
|
|
1037
|
+
lines.push(`${key}: ${item}`);
|
|
1038
|
+
}
|
|
1039
|
+
upstream.write(`${lines.join('\r\n')}\r\n\r\n`);
|
|
1040
|
+
if (head.length > 0)
|
|
1041
|
+
upstream.write(head);
|
|
1042
|
+
upstream.pipe(socket);
|
|
1043
|
+
socket.pipe(upstream);
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
831
1046
|
/** Workbench files built into public/. API routes are handled before this. */
|
|
832
1047
|
function serveDesk(req, res, pathname) {
|
|
833
1048
|
if (req.method !== 'GET' && req.method !== 'HEAD')
|
package/dist/inbox.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* agent.followup(), which appends agent/inbox/spliced and wakes a later turn.
|
|
4
4
|
* This module does not keep a second execution queue.
|
|
5
5
|
*/
|
|
6
|
+
import { isFenced } from "./deleting.js";
|
|
6
7
|
import { createLogSource, logHasMessage as eventsHaveMessage, spliceSeq as seqOfSplice, } from "./log/source.js";
|
|
7
8
|
import { workerFileSetup } from "./work-child.js";
|
|
8
9
|
const handles = new Map();
|
|
@@ -92,10 +93,31 @@ export async function followupDurable(ctx, sessionId, messageId, text) {
|
|
|
92
93
|
loaded.agent.followup(userMessage(messageId, text));
|
|
93
94
|
process.exit(97);
|
|
94
95
|
}
|
|
96
|
+
return deliverUser(ctx, sessionId, messageId, text, 'followup');
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Steering for the nearest step. On a running worker the host aborts first,
|
|
100
|
+
* so this call lands after the abort and wakes the next turn. An idle worker
|
|
101
|
+
* starts a turn immediately.
|
|
102
|
+
*/
|
|
103
|
+
export async function steerDurable(ctx, sessionId, messageId, text) {
|
|
104
|
+
return deliverUser(ctx, sessionId, messageId, text, 'steer');
|
|
105
|
+
}
|
|
106
|
+
async function deliverUser(ctx, sessionId, messageId, text, method) {
|
|
107
|
+
if (isFenced(sessionId)) {
|
|
108
|
+
return {
|
|
109
|
+
ok: false,
|
|
110
|
+
ambiguous: false,
|
|
111
|
+
seq: null,
|
|
112
|
+
error: 'deleting',
|
|
113
|
+
target: method === 'steer' ? 'next-step' : 'next-turn',
|
|
114
|
+
wakeup: false,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
95
117
|
const loaded = await loadAgent(ctx, sessionId);
|
|
96
118
|
const agent = loaded.agent;
|
|
97
119
|
try {
|
|
98
|
-
agent
|
|
120
|
+
agent[method](userMessage(messageId, text));
|
|
99
121
|
}
|
|
100
122
|
catch (error) {
|
|
101
123
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -122,7 +144,7 @@ export async function followupDurable(ctx, sessionId, messageId, text) {
|
|
|
122
144
|
ambiguous: !flushed,
|
|
123
145
|
seq,
|
|
124
146
|
error: flushError,
|
|
125
|
-
target: 'next-turn',
|
|
147
|
+
target: method === 'steer' ? 'next-step' : 'next-turn',
|
|
126
148
|
wakeup: true,
|
|
127
149
|
};
|
|
128
150
|
}
|