Server: remove members, parameters and a route alias nothing uses

Bundle.id, Libraries.flush, UsageTracker.now and the wiki cache's size getter had no callers;
upsert's `save` flag only ever skipped a save on an index with no file, text()'s `required` and
recordCall's default were never used, and wikiRoutes imported readJson for nothing. Renaming a
library answered POST as well as PATCH, which nothing sends. revertTo refused commits from before
the library existed, which no library's history holds any more; an export's file name fell back
to "untitled", which slugify already does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
thalladaandClaude Opus 5.5 committed 2026-11-17 16:07:04 -05:00
1 parent 714449fd54
commit 63593fdb22
9 files changed
+9 -27

No files matched your search

+1 -5
View File
@@ -87,10 +87,6 @@ export class Bundle {
this.handleLinks = linkRoutes({ main, linker: getLinker, index: this.nodeIndex, pending: this.pending, jobs: this.jobs, embedder: shared.embed, reviewer: this.reviewer, wrote: () => this.wrote("main") });
}
get id() {
return this.store.id;
}
/** A notice to every page open on this library. */
announce(message: Record<string, unknown>) {
const line = `data: ${JSON.stringify(message)}\n\n`;
@@ -253,7 +249,7 @@ export class Bundle {
const { text, skipped } = serializeDoc(snap, id);
res.writeHead(200, {
"content-type": "text/markdown; charset=utf-8",
"content-disposition": `attachment; filename="${slugify(snap.nodes[id].title) || "untitled"}${name === "main" ? "" : `-${encodeURIComponent(name)}`}.md"`,
"content-disposition": `attachment; filename="${slugify(snap.nodes[id].title)}${name === "main" ? "" : `-${encodeURIComponent(name)}`}.md"`,
"x-skipped": JSON.stringify(skipped),
});
return res.end(text);
+2 -2
View File
@@ -264,7 +264,7 @@ export class VectorIndex {
}
/** Add or update entries. Unchanged text (same hash, vector present) is not re-embedded. */
async upsert(items: { id: string; text: string }[], save = true): Promise<UpsertReport> {
async upsert(items: { id: string; text: string }[]): Promise<UpsertReport> {
const todo: Entry[] = [];
let skipped = 0;
for (const { id, text } of items) {
@@ -281,7 +281,7 @@ export class VectorIndex {
if (todo.length) this.bm25 = null;
const vectors = todo.length && this.embedder ? await this.embedder.embed(todo.map((e) => e.text)) : null;
if (vectors) todo.forEach((e, i) => (e.vector = vectors[i]));
if (save && todo.length) this.save();
if (todo.length) this.save();
return {
embedded: vectors ? todo.length : 0,
skipped,
+1 -1
View File
@@ -250,7 +250,7 @@ async function librariesApi(req: IncomingMessage, res: ServerResponse, parts: st
console.log(`libraries: made “${store.title}” (${store.id})`);
return json(res, 201, { library: info(store.id) });
}
if (id && parts.length === 1 && (method === "PATCH" || method === "POST")) {
if (id && parts.length === 1 && method === "PATCH") {
const input = await readJson<{ title?: unknown }>(req);
const store = libraries.rename(id, input.title as string);
bundles.get(id)?.announce({ branch: "main", from: "api" });
-5
View File
@@ -256,11 +256,6 @@ export class Libraries {
saveIndex() {
writeAtomic(join(this.dir, "index.json"), indexText(this.entries));
}
/** Write every library's waiting changes. */
flush() {
for (const s of this.stores.values()) s.flush();
}
}
function cleanTitle(title: unknown): string {
+1 -1
View File
@@ -683,7 +683,7 @@ export class Linker {
if (!items.length) return [];
const texts = items.map((i) => ({ id: `${i.title}\u0000${i.description ?? ""}`, text: `${i.title}: ${i.description ?? ""}` }));
if (this.senseVectors.size > 20_000) this.senseVectors = new VectorIndex(null, this.o.embedder);
const rep = await this.senseVectors.upsert(texts, false);
const rep = await this.senseVectors.upsert(texts);
if (rep.degraded) return null;
const out = items.map((i, k) => ({ ...i, fit: this.calibrate(dot(ctx, this.senseVectors.vectorOf(texts[k].id)!)) }));
return sorted ? out.sort((a, b) => b.fit - a.fit) : out;
+1 -5
View File
@@ -155,10 +155,6 @@ export class UsageTracker {
this.startedAt = clock();
}
now(): Date {
return this.clock();
}
configure(provider: Provider | null, model: string | null) {
this.provider = provider;
this.model = model;
@@ -173,7 +169,7 @@ export class UsageTracker {
// ---- the session ----
/** One finished model call. `tokens` null means the reply carried no counts. */
recordCall(provider: Provider, tokens: Tokens | null, opts: { ok: boolean; costUsd?: number | null; web?: WebUse | null } = { ok: true }) {
recordCall(provider: Provider, tokens: Tokens | null, opts: { ok: boolean; costUsd?: number | null; web?: WebUse | null }) {
const s = this.session(provider);
s.calls++;
if (opts.web) {
-4
View File
@@ -429,10 +429,6 @@ class KvStore<V> {
this.schedule();
}
get size() {
return this.load().size;
}
private schedule() {
if (!this.file || this.timer) return;
this.timer = setTimeout(() => this.flush(), 1000);
+3 -3
View File
@@ -19,7 +19,7 @@
* With IE_WIKI=off the server wires in wikiOff instead: every route answers 503 reason "off".
*/
import type { IncomingMessage, ServerResponse } from "node:http";
import { HttpError, abortOnClose, readJson, sendJson as send } from "./util";
import { HttpError, abortOnClose, sendJson as send } from "./util";
import type { CallOpts, Result, Uncached, WikiClient } from "./wiki";
const MAX_TITLES = 200;
@@ -35,9 +35,9 @@ function reply<V>(res: ServerResponse, r: Result<V> | Uncached, key: string) {
return send(res, 503, r, r.retryAfter ? { "retry-after": String(r.retryAfter) } : {});
}
function text(url: URL, name: string, max: number, required = true): string {
function text(url: URL, name: string, max: number): string {
const v = (url.searchParams.get(name) ?? "").trim();
if (!v && required) throw bad(`${name} is required`);
if (!v) throw bad(`${name} is required`);
if (v.length > max) throw bad(`${name} is longer than ${max} characters`);
return v;
}
-1
View File
@@ -173,7 +173,6 @@ function reanchor(doc: Doc, id: NodeId, was: NodeSnap, now: NodeSnap) {
/** Roll the whole tree back to a commit by writing the inverse as a new commit. History is kept. */
export function revertTo(doc: Doc, commit: Commit) {
const target = at(doc, commit).snap();
if (doc.snap().library && !target.library) throw new OpError("that commit is from before the library existed; revert one node to it instead");
doc.begin(`Revert to “${clip(commit.message, 60)}”`, "human", "revert");
doc.loro.revertTo(commit.frontiers);
doc.reread();