dsh-claude-style 0.21.0-dev.61 → 0.21.1-dev.62
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.en.md +2 -2
- package/README.md +2 -2
- package/docs/CHANGELOG.md +90 -0
- package/docs/STYLE.md +150 -116
- package/lib/assets/032fdf4c5d95.js.br +0 -0
- package/lib/assets/74468df99d69.js.br +0 -0
- package/lib/assets/8fd9d8944401.js.br +0 -0
- package/lib/assets/manifest.json +12 -12
- package/lib/client.js +14 -14
- package/lib/host/brand.js +12 -7
- package/lib/host/routes.js +156 -166
- package/lib/host/search.js +100 -61
- package/lib/host/session-compact.js +55 -0
- package/lib/host/session-panel-call.js +27 -0
- package/lib/host/session-panel-context.js +270 -45
- package/lib/host/session-panel-log.js +75 -11
- package/lib/host/session-panel-round.js +4 -25
- package/lib/host/session-panel.js +14 -5
- package/lib/host/settings.js +22 -7
- package/lib/host/usage.js +53 -24
- package/lib/prices.json +132 -133
- package/package.json +1 -1
- package/lib/assets/032e9ea53f55.js.br +0 -0
- package/lib/assets/55f596e259b8.js.br +0 -0
- package/lib/assets/97028817245d.js.br +0 -0
package/lib/host/brand.js
CHANGED
|
@@ -25,6 +25,7 @@ var FONT_FILES_PATH = `${ROUTE_PREFIX}/fonts/`;
|
|
|
25
25
|
var WEBFONTS_PATH = `${ROUTE_PREFIX}/webfonts`;
|
|
26
26
|
var SOUND_PATH = `${ROUTE_PREFIX}/sound`;
|
|
27
27
|
var SESSION_PANEL_PATH = `${ROUTE_PREFIX}/session-panel`;
|
|
28
|
+
var SESSION_COMPACT_PATH = `${ROUTE_PREFIX}/session-compact`;
|
|
28
29
|
|
|
29
30
|
// packages/host/src/brand.ts
|
|
30
31
|
import { mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -32,7 +33,11 @@ import { join } from "node:path";
|
|
|
32
33
|
import { pluginPath } from "./harness-home.js";
|
|
33
34
|
|
|
34
35
|
// packages/engine/node/http.ts
|
|
35
|
-
function refusalOf(ctx, req) {
|
|
36
|
+
function refusalOf(ctx, req, peer) {
|
|
37
|
+
if (peer !== void 0) {
|
|
38
|
+
if (peer === null || typeof peer !== "object" || peer.signal?.aborted === true) return 403;
|
|
39
|
+
return peer.principal?.kind === "owner" ? void 0 : 403;
|
|
40
|
+
}
|
|
36
41
|
const connection = ctx.get("connection");
|
|
37
42
|
if (typeof connection?.requestRejection === "function") return connection.requestRejection(req);
|
|
38
43
|
if (!isLoopbackPeer(req.socket.remoteAddress)) return 403;
|
|
@@ -69,8 +74,8 @@ function methodRefused(req, res, methods) {
|
|
|
69
74
|
res.end();
|
|
70
75
|
return true;
|
|
71
76
|
}
|
|
72
|
-
function fenceRefused(ctx, req, res) {
|
|
73
|
-
const refused = refusalOf(ctx, req);
|
|
77
|
+
function fenceRefused(ctx, req, res, peer) {
|
|
78
|
+
const refused = refusalOf(ctx, req, peer);
|
|
74
79
|
if (refused === void 0) return false;
|
|
75
80
|
sendJson(res, refused, { ok: false, error: refused === 401 ? "unauthorized" : "forbidden" });
|
|
76
81
|
return true;
|
|
@@ -167,9 +172,9 @@ function brandRoutes(ctx) {
|
|
|
167
172
|
const status = {
|
|
168
173
|
kind: "exact",
|
|
169
174
|
path: BRAND_PATH,
|
|
170
|
-
handler: (req, res) => {
|
|
175
|
+
handler: (req, res, peer) => {
|
|
171
176
|
if (methodRefused(req, res, ["GET"])) return;
|
|
172
|
-
if (fenceRefused(ctx, req, res)) return;
|
|
177
|
+
if (fenceRefused(ctx, req, res, peer)) return;
|
|
173
178
|
sendJson(res, 200, store.answer());
|
|
174
179
|
}
|
|
175
180
|
};
|
|
@@ -178,9 +183,9 @@ function brandRoutes(ctx) {
|
|
|
178
183
|
route: {
|
|
179
184
|
kind: "exact",
|
|
180
185
|
path: IMAGE_PATHS[kind],
|
|
181
|
-
handler: (req, res) => {
|
|
186
|
+
handler: (req, res, peer) => {
|
|
182
187
|
if (methodRefused(req, res, ["GET", "HEAD", "PUT", "DELETE"])) return;
|
|
183
|
-
if (fenceRefused(ctx, req, res)) return;
|
|
188
|
+
if (fenceRefused(ctx, req, res, peer)) return;
|
|
184
189
|
if (req.method === "PUT" || req.method === "DELETE") {
|
|
185
190
|
const done = req.method === "PUT" ? storeImage(store, kind, req, res) : Promise.resolve().then(() => {
|
|
186
191
|
store.remove(kind);
|
package/lib/host/routes.js
CHANGED
|
@@ -19,12 +19,13 @@ var FONT_FILES_PATH = `${ROUTE_PREFIX}/fonts/`;
|
|
|
19
19
|
var WEBFONTS_PATH = `${ROUTE_PREFIX}/webfonts`;
|
|
20
20
|
var SOUND_PATH = `${ROUTE_PREFIX}/sound`;
|
|
21
21
|
var SESSION_PANEL_PATH = `${ROUTE_PREFIX}/session-panel`;
|
|
22
|
+
var SESSION_COMPACT_PATH = `${ROUTE_PREFIX}/session-compact`;
|
|
22
23
|
|
|
23
24
|
// packages/contracts/src/webfonts.ts
|
|
24
25
|
var OPTIONAL_WEBFONTS = [
|
|
25
|
-
{ family: "Anthropic Sans Web Text", file: "AnthropicSansWebText.ttf" },
|
|
26
|
-
{ family: "Anthropic Serif Web Text", file: "AnthropicSerifWebText.ttf" },
|
|
27
|
-
{ family: "Anthropic Mono Web", file: "AnthropicMonoWeb.ttf" }
|
|
26
|
+
{ family: "Anthropic Sans Web Text", file: "AnthropicSansWebText.ttf", label: "Anthropic Sans", stack: ["Anthropic Sans Web Text", "Anthropic Sans"] },
|
|
27
|
+
{ family: "Anthropic Serif Web Text", file: "AnthropicSerifWebText.ttf", label: "Anthropic Serif", stack: ["Anthropic Serif Web Text", "Anthropic Serif"] },
|
|
28
|
+
{ family: "Anthropic Mono Web", file: "AnthropicMonoWeb.ttf", label: "Anthropic Mono", stack: ["Anthropic Mono Web", "Anthropic Mono Variable", "Anthropic Mono"] }
|
|
28
29
|
];
|
|
29
30
|
|
|
30
31
|
// packages/host/src/routes.ts
|
|
@@ -46,7 +47,11 @@ function harnessPath(ctx, ...segments) {
|
|
|
46
47
|
import { pluginPath } from "./harness-home.js";
|
|
47
48
|
|
|
48
49
|
// packages/engine/node/http.ts
|
|
49
|
-
function refusalOf(ctx, req) {
|
|
50
|
+
function refusalOf(ctx, req, peer) {
|
|
51
|
+
if (peer !== void 0) {
|
|
52
|
+
if (peer === null || typeof peer !== "object" || peer.signal?.aborted === true) return 403;
|
|
53
|
+
return peer.principal?.kind === "owner" ? void 0 : 403;
|
|
54
|
+
}
|
|
50
55
|
const connection = ctx.get("connection");
|
|
51
56
|
if (typeof connection?.requestRejection === "function") return connection.requestRejection(req);
|
|
52
57
|
if (!isLoopbackPeer(req.socket.remoteAddress)) return 403;
|
|
@@ -83,8 +88,8 @@ function methodRefused(req, res, methods) {
|
|
|
83
88
|
res.end();
|
|
84
89
|
return true;
|
|
85
90
|
}
|
|
86
|
-
function fenceRefused(ctx, req, res) {
|
|
87
|
-
const refused = refusalOf(ctx, req);
|
|
91
|
+
function fenceRefused(ctx, req, res, peer) {
|
|
92
|
+
const refused = refusalOf(ctx, req, peer);
|
|
88
93
|
if (refused === void 0) return false;
|
|
89
94
|
sendJson(res, refused, { ok: false, error: refused === 401 ? "unauthorized" : "forbidden" });
|
|
90
95
|
return true;
|
|
@@ -191,12 +196,19 @@ import { createPrices } from "./prices.js";
|
|
|
191
196
|
import { QUERY_MAX, createSessionSearch } from "./search.js";
|
|
192
197
|
import { billingRowsOf, createSessionCost } from "./session-cost.js";
|
|
193
198
|
import { createSessionPanel } from "./session-panel.js";
|
|
199
|
+
import { compactSession } from "./session-compact.js";
|
|
194
200
|
import { sessionDirectoryName } from "./session-name.js";
|
|
195
201
|
import { createUsage } from "./usage.js";
|
|
196
202
|
|
|
197
203
|
// packages/contracts/src/services.ts
|
|
198
204
|
var OFFICIAL_MODEL_GROUP = "deepseek-official";
|
|
199
205
|
|
|
206
|
+
// packages/contracts/src/palette-schemes.ts
|
|
207
|
+
var PALETTE_SCHEME_LIMIT = 16;
|
|
208
|
+
var PALETTE_SCHEME_ENTRY_MAX = 400;
|
|
209
|
+
var PALETTE_SCHEME_ID_MAX = 24;
|
|
210
|
+
var PALETTE_SCHEME_FOLLOW = "brand";
|
|
211
|
+
|
|
200
212
|
// packages/contracts/src/prices.ts
|
|
201
213
|
var CURRENCY_CNY = "CNY";
|
|
202
214
|
var CURRENCY_USD = "USD";
|
|
@@ -224,9 +236,8 @@ var BRAND_CLAUDE = "claude";
|
|
|
224
236
|
var BRAND_DEEPSEEK = "deepseek";
|
|
225
237
|
var BRAND_DEEPSEEK_LEGACY = "off";
|
|
226
238
|
var BRANDS = [BRAND_CLAUDE, BRAND_DEEPSEEK];
|
|
227
|
-
var
|
|
228
|
-
var
|
|
229
|
-
var PALETTE_COLORINGS = [PALETTE_COLORING_BRAND, ...BRANDS, PALETTE_COLORING_CUSTOM];
|
|
239
|
+
var BRAND_DEFAULT_PRESETS = { [BRAND_CLAUDE]: "claude", [BRAND_DEEPSEEK]: "deepseek" };
|
|
240
|
+
var PALETTE_COLORING_BRAND = PALETTE_SCHEME_FOLLOW;
|
|
230
241
|
var INLINE_CODE_COLOR_PALETTE = "palette";
|
|
231
242
|
var INLINE_CODE_COLOR_CLASSIC = "classic";
|
|
232
243
|
var INLINE_CODE_COLORS = [INLINE_CODE_COLOR_PALETTE, INLINE_CODE_COLOR_CLASSIC];
|
|
@@ -349,13 +360,16 @@ var PREFS = {
|
|
|
349
360
|
/** Whether the sidebar draws its brand area; off collapses that area and leaves the sidebar toggle in place. */
|
|
350
361
|
sidebarBrand: { type: "boolean", default: true },
|
|
351
362
|
brandAccent: { type: "color", default: "" },
|
|
352
|
-
/**
|
|
353
|
-
paletteColors: { type: "
|
|
354
|
-
/** The
|
|
363
|
+
/** The selected scheme's id, or `brand` to follow the theme style; an id no scheme carries reads as `brand`. */
|
|
364
|
+
paletteColors: { type: "text", default: PALETTE_COLORING_BRAND, max: PALETTE_SCHEME_ID_MAX },
|
|
365
|
+
/** The schemes' records (palette-schemes.ts): the reader's own and the presets' overrides. */
|
|
366
|
+
paletteSchemes: { type: "list", default: [], max: PALETTE_SCHEME_LIMIT, entryMax: PALETTE_SCHEME_ENTRY_MAX, drop: [] },
|
|
367
|
+
/** The earlier single custom card's four colours; read once into the scheme `custom` and then left empty. */
|
|
355
368
|
customAccent: { type: "color", default: "" },
|
|
356
369
|
customCanvasLight: { type: "color", default: "" },
|
|
357
370
|
customCanvasDark: { type: "color", default: "" },
|
|
358
371
|
customCode: { type: "color", default: "" },
|
|
372
|
+
/** Read once and left at the default: the choice now lives in the Claude preset's override record. */
|
|
359
373
|
inlineCodeColor: { type: "choice", values: INLINE_CODE_COLORS, default: INLINE_CODE_COLOR_PALETTE },
|
|
360
374
|
motion: { type: "choice", values: MOTION_MODES, default: MOTION_SYSTEM },
|
|
361
375
|
statusMotion: { type: "choice", values: STATUS_MOTIONS, default: STATUS_MOTION_SWEEP },
|
|
@@ -406,6 +420,13 @@ var PREFS = {
|
|
|
406
420
|
/** Whether the percentage stands beside that face. */
|
|
407
421
|
contextNumbers: { type: "boolean", default: true },
|
|
408
422
|
statsFooterAlign: { type: "choice", values: STATS_FOOTER_ALIGNS, default: "center" },
|
|
423
|
+
/** Compact-footer figures; speed and TTFT join the existing figures only when asked for. */
|
|
424
|
+
statsFooterSpeed: { type: "boolean", default: false },
|
|
425
|
+
statsFooterTtft: { type: "boolean", default: false },
|
|
426
|
+
statsFooterCache: { type: "boolean", default: true },
|
|
427
|
+
statsFooterCost: { type: "boolean", default: true },
|
|
428
|
+
statsFooterTotal: { type: "boolean", default: true },
|
|
429
|
+
statsFooterContext: { type: "boolean", default: true },
|
|
409
430
|
/** Which official price table the session's cost follows, or off for no figure at all. */
|
|
410
431
|
billingCurrency: { type: "choice", values: BILLING_CHOICES, default: CURRENCY_CNY },
|
|
411
432
|
/** Custom `model|input|cacheRead|output` rows per million tokens; blank buckets inherit official rates. */
|
|
@@ -436,7 +457,7 @@ var PREFS = {
|
|
|
436
457
|
chatAnimations: { type: "boolean", default: true, legacy: { [CHAT_ANIMATIONS_OFF]: false, enhanced: true, redraw: true } },
|
|
437
458
|
chatWait: { type: "boolean", default: true },
|
|
438
459
|
chatSend: { type: "boolean", default: true },
|
|
439
|
-
chatReveal: { type: "choice", values: CHAT_REVEAL_MODES, default:
|
|
460
|
+
chatReveal: { type: "choice", values: CHAT_REVEAL_MODES, default: CHAT_REVEAL_ON },
|
|
440
461
|
reasoningDisplay: { type: "choice", values: REASONING_DISPLAYS, default: REASONING_DISPLAY_STEPPED },
|
|
441
462
|
/** Moves the reading position when an answer starts; default off because this is unsolicited movement. */
|
|
442
463
|
answerAnchor: { type: "boolean", default: false },
|
|
@@ -518,8 +539,8 @@ async function unarchiveSession(ctx, sessionId) {
|
|
|
518
539
|
if (typeof registry?.unarchiveSession !== "function") return;
|
|
519
540
|
await registry.unarchiveSession(sessionId);
|
|
520
541
|
}
|
|
521
|
-
async function deleteSession(ctx, req, res) {
|
|
522
|
-
const refused = refusalOf(ctx, req);
|
|
542
|
+
async function deleteSession(ctx, req, res, peer) {
|
|
543
|
+
const refused = refusalOf(ctx, req, peer);
|
|
523
544
|
if (refused !== void 0) {
|
|
524
545
|
sendJson(res, refused, { ok: false, error: refused === 401 ? "unauthorized" : "forbidden" });
|
|
525
546
|
return;
|
|
@@ -603,6 +624,17 @@ function registerRoutes(ctx, scope) {
|
|
|
603
624
|
report(`${label} route unavailable`, error);
|
|
604
625
|
}
|
|
605
626
|
};
|
|
627
|
+
const registerGuarded = (label, kind, path, methods, handle) => {
|
|
628
|
+
register(label, {
|
|
629
|
+
kind,
|
|
630
|
+
path,
|
|
631
|
+
handler: (req, res, peer) => {
|
|
632
|
+
if (methodRefused(req, res, methods)) return;
|
|
633
|
+
if (fenceRefused(ctx, req, res, peer)) return;
|
|
634
|
+
return handle(req, res);
|
|
635
|
+
}
|
|
636
|
+
});
|
|
637
|
+
};
|
|
606
638
|
const sendPayload = (res, answer) => {
|
|
607
639
|
void answer.then((value) => {
|
|
608
640
|
sendJson(res, 200, { ok: true, ...value });
|
|
@@ -614,184 +646,130 @@ function registerRoutes(ctx, scope) {
|
|
|
614
646
|
if (res.headersSent) res.destroy();
|
|
615
647
|
else sendJson(res, 500, { ok: false, error: String(error?.message ?? String(error)) });
|
|
616
648
|
};
|
|
617
|
-
const guardedSessionId = (req, res) => {
|
|
618
|
-
if (methodRefused(req, res, [
|
|
619
|
-
if (fenceRefused(ctx, req, res)) return null;
|
|
649
|
+
const guardedSessionId = (req, res, peer, method = "GET") => {
|
|
650
|
+
if (methodRefused(req, res, [method])) return null;
|
|
651
|
+
if (fenceRefused(ctx, req, res, peer)) return null;
|
|
620
652
|
const sessionId = (new URL(req.url ?? "/", "http://local").searchParams.get("id") ?? "").trim();
|
|
621
653
|
if (SESSION_ID_RE.test(sessionId)) return sessionId;
|
|
622
654
|
sendJson(res, 400, { ok: false, error: "invalid session id" });
|
|
623
655
|
return null;
|
|
624
656
|
};
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
if (methodRefused(req, res, ["GET", "HEAD"])) return;
|
|
630
|
-
if (fenceRefused(ctx, req, res)) return;
|
|
631
|
-
const sub = new URL(req.url ?? "/", "http://x").pathname.slice(ROUTE_PREFIX.length);
|
|
632
|
-
if (sub === `/${COPY_FILE}`) {
|
|
633
|
-
sendFile(res, req.method ?? "GET", file, {
|
|
634
|
-
"content-type": "application/json; charset=utf-8",
|
|
635
|
-
"cache-control": "no-cache"
|
|
636
|
-
});
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
if (sub === WEBFONTS_SUB) {
|
|
640
|
-
const faces = OPTIONAL_WEBFONTS.filter((face) => existsSync2(join3(userFontsDir(), face.file))).map((face) => face.file);
|
|
641
|
-
sendJson(res, 200, { ok: true, faces });
|
|
642
|
-
return;
|
|
643
|
-
}
|
|
644
|
-
const font = sub.startsWith("/fonts/") ? FONT_FILES[sub.slice("/fonts/".length)] : void 0;
|
|
645
|
-
if (font !== void 0) {
|
|
646
|
-
const name = sub.slice("/fonts/".length);
|
|
647
|
-
const dropped = join3(userFontsDir(), name);
|
|
648
|
-
sendFile(res, req.method ?? "GET", existsSync2(dropped) ? dropped : join3(fontsDir, name), {
|
|
649
|
-
"content-type": font,
|
|
650
|
-
"cache-control": "public, max-age=86400"
|
|
651
|
-
});
|
|
652
|
-
return;
|
|
653
|
-
}
|
|
654
|
-
const sheet = sub.startsWith("/assets/") ? sub.slice("/assets/".length) : "";
|
|
655
|
-
if (sheet !== "" && !sheet.includes("/")) {
|
|
656
|
-
if (!sendAsset(req, res, sheet)) {
|
|
657
|
-
res.writeHead(404);
|
|
658
|
-
res.end();
|
|
659
|
-
}
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
res.writeHead(404);
|
|
663
|
-
res.end();
|
|
664
|
-
}
|
|
665
|
-
});
|
|
666
|
-
register("username", {
|
|
667
|
-
kind: "exact",
|
|
668
|
-
path: USERNAME_PATH,
|
|
669
|
-
handler: (req, res) => {
|
|
670
|
-
if (methodRefused(req, res, ["GET", "HEAD"])) return;
|
|
671
|
-
if (fenceRefused(ctx, req, res)) return;
|
|
672
|
-
const username = userInfo().username || "";
|
|
673
|
-
const body = Buffer.from(JSON.stringify({ ok: true, username }));
|
|
674
|
-
res.writeHead(200, {
|
|
657
|
+
registerGuarded("model copy", "prefix", ROUTE_PREFIX, ["GET", "HEAD"], (req, res) => {
|
|
658
|
+
const sub = new URL(req.url ?? "/", "http://x").pathname.slice(ROUTE_PREFIX.length);
|
|
659
|
+
if (sub === `/${COPY_FILE}`) {
|
|
660
|
+
sendFile(res, req.method ?? "GET", file, {
|
|
675
661
|
"content-type": "application/json; charset=utf-8",
|
|
676
|
-
"content-length": String(body.byteLength),
|
|
677
662
|
"cache-control": "no-cache"
|
|
678
663
|
});
|
|
679
|
-
|
|
664
|
+
return;
|
|
680
665
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
666
|
+
if (sub === WEBFONTS_SUB) {
|
|
667
|
+
const faces = OPTIONAL_WEBFONTS.filter((face) => existsSync2(join3(userFontsDir(), face.file))).map((face) => face.file);
|
|
668
|
+
sendJson(res, 200, { ok: true, faces });
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
const font = sub.startsWith("/fonts/") ? FONT_FILES[sub.slice("/fonts/".length)] : void 0;
|
|
672
|
+
if (font !== void 0) {
|
|
673
|
+
const name = sub.slice("/fonts/".length);
|
|
674
|
+
const dropped = join3(userFontsDir(), name);
|
|
675
|
+
sendFile(res, req.method ?? "GET", existsSync2(dropped) ? dropped : join3(fontsDir, name), {
|
|
676
|
+
"content-type": font,
|
|
677
|
+
"cache-control": "public, max-age=86400"
|
|
678
|
+
});
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
const sheet = sub.startsWith("/assets/") ? sub.slice("/assets/".length) : "";
|
|
682
|
+
if (sheet !== "" && !sheet.includes("/")) {
|
|
683
|
+
if (!sendAsset(req, res, sheet)) {
|
|
684
|
+
res.writeHead(404);
|
|
685
|
+
res.end();
|
|
691
686
|
}
|
|
692
|
-
|
|
687
|
+
return;
|
|
693
688
|
}
|
|
689
|
+
res.writeHead(404);
|
|
690
|
+
res.end();
|
|
694
691
|
});
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
692
|
+
registerGuarded("username", "exact", USERNAME_PATH, ["GET", "HEAD"], (req, res) => {
|
|
693
|
+
const username = userInfo().username || "";
|
|
694
|
+
const body = Buffer.from(JSON.stringify({ ok: true, username }));
|
|
695
|
+
res.writeHead(200, {
|
|
696
|
+
"content-type": "application/json; charset=utf-8",
|
|
697
|
+
"content-length": String(body.byteLength),
|
|
698
|
+
"cache-control": "no-cache"
|
|
699
|
+
});
|
|
700
|
+
res.end(req.method === "HEAD" ? void 0 : body);
|
|
701
|
+
});
|
|
702
|
+
registerGuarded("sound", "exact", SOUND_PATH, ["GET", "POST"], (req, res) => {
|
|
703
|
+
if (req.method !== "POST") {
|
|
704
|
+
sendJson(res, 200, soundCapability());
|
|
705
|
+
return;
|
|
705
706
|
}
|
|
707
|
+
void playSoundRequest(req, res).catch((error) => fail(res, error));
|
|
706
708
|
});
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
res.end(req.method === "HEAD" ? void 0 : body);
|
|
709
|
+
registerGuarded("HDSL account", "exact", HDSL_PATH, ["GET", "HEAD"], (_req, res) => {
|
|
710
|
+
sendPayload(res, hdsl.read().then((profile) => {
|
|
711
|
+
const { skinFile, ...account } = profile;
|
|
712
|
+
return account;
|
|
713
|
+
}));
|
|
714
|
+
});
|
|
715
|
+
registerGuarded("HDSL skin", "exact", HDSL_SKIN_PATH, ["GET", "HEAD"], (req, res) => {
|
|
716
|
+
return hdsl.read().then((profile) => {
|
|
717
|
+
if (typeof profile.skinFile !== "string" || !existsSync2(profile.skinFile)) {
|
|
718
|
+
res.writeHead(404, { "cache-control": "no-store" });
|
|
719
|
+
res.end();
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
const body = readFileSync2(profile.skinFile);
|
|
723
|
+
res.writeHead(200, {
|
|
724
|
+
"content-type": "image/png",
|
|
725
|
+
"content-length": String(body.byteLength),
|
|
726
|
+
"cache-control": "no-cache"
|
|
726
727
|
});
|
|
727
|
-
|
|
728
|
+
res.end(req.method === "HEAD" ? void 0 : body);
|
|
729
|
+
});
|
|
728
730
|
});
|
|
729
731
|
register("session delete", {
|
|
730
732
|
kind: "exact",
|
|
731
733
|
path: SESSION_DELETE_PATH,
|
|
732
|
-
handler: (req, res) => {
|
|
734
|
+
handler: (req, res, peer) => {
|
|
733
735
|
if (methodRefused(req, res, ["POST"])) return;
|
|
734
|
-
void deleteSession(ctx, req, res).catch((error) => fail(res, error));
|
|
736
|
+
void deleteSession(ctx, req, res, peer).catch((error) => fail(res, error));
|
|
735
737
|
}
|
|
736
738
|
});
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
ok: true,
|
|
751
|
-
value: snapshot.value,
|
|
752
|
-
computing: snapshot.computing === true,
|
|
753
|
-
...snapshot.error === void 0 ? {} : { error: snapshot.error }
|
|
754
|
-
});
|
|
755
|
-
}
|
|
739
|
+
registerGuarded("usage", "exact", USAGE_PATH, ["GET", "HEAD"], (req, res) => {
|
|
740
|
+
const params = new URL(req.url ?? "/", "http://local").searchParams;
|
|
741
|
+
const requested = params.get("scope");
|
|
742
|
+
const scope2 = requested === HOME_SESSION_SCOPE_ACTIVE || requested === HOME_SESSION_SCOPE_WORKSPACE ? requested : HOME_SESSION_SCOPE_ALL;
|
|
743
|
+
const workspaceId = scope2 === HOME_SESSION_SCOPE_WORKSPACE ? (params.get("workspace") ?? "").trim().slice(0, 128) : "";
|
|
744
|
+
void usage.refresh(scope2, workspaceId);
|
|
745
|
+
const snapshot = usage.snapshot(scope2, workspaceId);
|
|
746
|
+
sendJson(res, 200, {
|
|
747
|
+
ok: true,
|
|
748
|
+
value: snapshot.value,
|
|
749
|
+
computing: snapshot.computing === true,
|
|
750
|
+
...snapshot.error === void 0 ? {} : { error: snapshot.error }
|
|
751
|
+
});
|
|
756
752
|
});
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
if (methodRefused(req, res, ["GET"])) return;
|
|
762
|
-
if (fenceRefused(ctx, req, res)) return;
|
|
763
|
-
const query = (new URL(req.url ?? "/", "http://local").searchParams.get("q") ?? "").trim().slice(0, QUERY_MAX);
|
|
764
|
-
const answer = query === "" ? sessionSearch.warm().then(() => ({ sessions: [] })) : sessionSearch.search(query);
|
|
765
|
-
sendPayload(res, answer);
|
|
766
|
-
}
|
|
753
|
+
registerGuarded("session search", "exact", SESSION_SEARCH_PATH, ["GET"], (req, res) => {
|
|
754
|
+
const query = (new URL(req.url ?? "/", "http://local").searchParams.get("q") ?? "").trim().slice(0, QUERY_MAX);
|
|
755
|
+
const answer = query === "" ? sessionSearch.warm().then(() => ({ sessions: [] })) : sessionSearch.search(query);
|
|
756
|
+
sendPayload(res, answer);
|
|
767
757
|
});
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
if (methodRefused(req, res, ["GET", "POST"])) return;
|
|
773
|
-
if (fenceRefused(ctx, req, res)) return;
|
|
774
|
-
peakrate.ensure();
|
|
775
|
-
const answer = req.method === "POST" ? peakrate.refresh().then(() => peakrate.payload()) : Promise.resolve(peakrate.payload());
|
|
776
|
-
sendPayload(res, answer);
|
|
777
|
-
}
|
|
758
|
+
registerGuarded("peak rate", "exact", PEAKRATE_PATH, ["GET", "POST"], (req, res) => {
|
|
759
|
+
peakrate.ensure();
|
|
760
|
+
const answer = req.method === "POST" ? peakrate.refresh().then(() => peakrate.payload()) : Promise.resolve(peakrate.payload());
|
|
761
|
+
sendPayload(res, answer);
|
|
778
762
|
});
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
if (methodRefused(req, res, ["GET", "POST"])) return;
|
|
784
|
-
if (fenceRefused(ctx, req, res)) return;
|
|
785
|
-
prices.ensure();
|
|
786
|
-
const answer = req.method === "POST" ? prices.refresh().then(() => prices.payload()) : Promise.resolve(prices.payload());
|
|
787
|
-
sendPayload(res, answer);
|
|
788
|
-
}
|
|
763
|
+
registerGuarded("prices", "exact", PRICES_PATH, ["GET", "POST"], (req, res) => {
|
|
764
|
+
prices.ensure();
|
|
765
|
+
const answer = req.method === "POST" ? prices.refresh().then(() => prices.payload()) : Promise.resolve(prices.payload());
|
|
766
|
+
sendPayload(res, answer);
|
|
789
767
|
});
|
|
790
768
|
register("session cost", {
|
|
791
769
|
kind: "exact",
|
|
792
770
|
path: SESSION_COST_PATH,
|
|
793
|
-
handler: (req, res) => {
|
|
794
|
-
const sessionId = guardedSessionId(req, res);
|
|
771
|
+
handler: (req, res, peer) => {
|
|
772
|
+
const sessionId = guardedSessionId(req, res, peer);
|
|
795
773
|
if (sessionId === null) return;
|
|
796
774
|
const billing = readBillingRows(new URL(req.url ?? "/", "http://local").searchParams);
|
|
797
775
|
sendPayload(res, sessionCost.get(sessionId, billing).then((value) => ({ value })));
|
|
@@ -800,8 +778,8 @@ function registerRoutes(ctx, scope) {
|
|
|
800
778
|
register("session panel", {
|
|
801
779
|
kind: "exact",
|
|
802
780
|
path: SESSION_PANEL_PATH,
|
|
803
|
-
handler: (req, res) => {
|
|
804
|
-
const sessionId = guardedSessionId(req, res);
|
|
781
|
+
handler: (req, res, peer) => {
|
|
782
|
+
const sessionId = guardedSessionId(req, res, peer);
|
|
805
783
|
if (sessionId === null) return;
|
|
806
784
|
const params = new URL(req.url ?? "/", "http://local").searchParams;
|
|
807
785
|
const jobId = (params.get("job") ?? "").trim();
|
|
@@ -816,6 +794,18 @@ function registerRoutes(ctx, scope) {
|
|
|
816
794
|
sendPayload(res, sessionPanel.get(sessionId, readBillingRows(params), params.get("live") === "1").then((value) => ({ value })));
|
|
817
795
|
}
|
|
818
796
|
});
|
|
797
|
+
register("session compact", {
|
|
798
|
+
kind: "exact",
|
|
799
|
+
path: SESSION_COMPACT_PATH,
|
|
800
|
+
handler: (req, res, peer) => {
|
|
801
|
+
const sessionId = guardedSessionId(req, res, peer, "POST");
|
|
802
|
+
if (sessionId === null) return;
|
|
803
|
+
void compactSession(ctx, sessionId).then(
|
|
804
|
+
(answer) => sendJson(res, 200, answer),
|
|
805
|
+
(error) => fail(res, error)
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
});
|
|
819
809
|
for (const { label, route } of brandRoutes(ctx)) register(label, route);
|
|
820
810
|
return () => {
|
|
821
811
|
usage.dispose();
|