diff --git a/server/bundle.ts b/server/bundle.ts index 52bc14e..e9b92ef 100644 --- a/server/bundle.ts +++ b/server/bundle.ts @@ -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) { 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); diff --git a/server/embed.ts b/server/embed.ts index 1809b63..515a438 100644 --- a/server/embed.ts +++ b/server/embed.ts @@ -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 { + async upsert(items: { id: string; text: string }[]): Promise { 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, diff --git a/server/index.ts b/server/index.ts index 75e0b3e..7c24c31 100644 --- a/server/index.ts +++ b/server/index.ts @@ -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" }); diff --git a/server/libraries.ts b/server/libraries.ts index 651140b..2387a14 100644 --- a/server/libraries.ts +++ b/server/libraries.ts @@ -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 { diff --git a/server/links/scan.ts b/server/links/scan.ts index 3fb8f43..af60c6c 100644 --- a/server/links/scan.ts +++ b/server/links/scan.ts @@ -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; diff --git a/server/usage.ts b/server/usage.ts index e8f8752..0ee3b47 100644 --- a/server/usage.ts +++ b/server/usage.ts @@ -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) { diff --git a/server/wiki.ts b/server/wiki.ts index 7e84135..020cf85 100644 --- a/server/wiki.ts +++ b/server/wiki.ts @@ -429,10 +429,6 @@ class KvStore { this.schedule(); } - get size() { - return this.load().size; - } - private schedule() { if (!this.file || this.timer) return; this.timer = setTimeout(() => this.flush(), 1000); diff --git a/server/wikiRoutes.ts b/server/wikiRoutes.ts index 1851747..05ac484 100644 --- a/server/wikiRoutes.ts +++ b/server/wikiRoutes.ts @@ -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(res: ServerResponse, r: Result | 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; } diff --git a/src/core/repo.ts b/src/core/repo.ts index 6582218..4baa231 100644 --- a/src/core/repo.ts +++ b/src/core/repo.ts @@ -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();