Files
DeepTutor/web/lib/brand-icons.ts
Bingxi Zhao (Frank) 44fa7a1552 release: v1.5.8
Memory. A v1.5.7 source deployment grew past 14 GB before V8 aborted; the
causes were independent, so this cut fixes each one and bounds what was
previously unbounded.

- The dev server was never actually capped: `next dev` renders in a worker it
  spawns, and V8 flags in argv are not inherited, so
  `node --max-old-space-size=4096 .../next dev` never reached the process
  holding the memory. Next then substituted 50% of total RAM — a 12 GB heap on
  a 24 GB machine. web/scripts/dev.mjs routes the ceiling through NODE_OPTIONS
  (which the worker inherits and Next honors), clamped to 4 GB and sized off
  the cgroup limit in a container.
- Source installs serve a production build: `deeptutor start` builds once into
  .next-deeptutor and reuses it until a fingerprint over the web/ tree, the
  version file, or the build-time public settings changes. `--dev` is the
  opt-in for HMR and keeps using .next, so neither mode invalidates the other.
- LLM clients and providers come from a bounded event-loop-local LRU pool of 2
  instead of one per turn, closed on shutdown and retired on a settings
  reload; only the selected backend's SDK is imported.
- Caches gained ceilings: knowledge-task log streams cap events and bytes per
  task with a 1h TTL and a completion tombstone, the completed-task table
  keeps 256, the LlamaIndex index cache drops 8 -> 2 with a 10-minute idle
  evict, and a book runtime is released when its queue drains.
- After a turn, a finished book job, or a completed KB task, cycles are
  collected and glibc is asked to return free pages via malloc_trim; the
  container and launcher set MALLOC_ARENA_MAX=2 and a lower trim threshold,
  both operator-overridable.
- Every uvicorn launch sets --timeout-keep-alive 300. web/proxy.ts forwards
  over Node's http.globalAgent, whose 5s idle reaper matched uvicorn's default
  exactly; both ends raced to close the same socket and the loser's request
  died with ECONNRESET ("Failed to load sessions").
- deeptutor.agents, deeptutor.core.agentic, provider_core, the document
  extractor's parser libraries and the LLM error-mapping rules resolve on
  first use. `python -m deeptutor.api.run_server` no longer reloads by
  default (DEEPTUTOR_DEV_RELOAD=1 restores it).

README prose and all ten translated READMEs now describe the production-build
default instead of dev mode. Release notes: assets/releases/ver1-5-8.md
2026-08-02 13:23:45 +08:00

75 lines
2.4 KiB
TypeScript

/**
* Resolving a catalog entry to a brand mark.
*
* Two namespaces, kept apart: an MCP server id and a CLI app id can collide
* (`exa` is both a hosted search MCP and an installed CLI), and they are not the
* same product. Callers say which store they are rendering.
*
* Everything here is a pure lookup over the generated tables, so the store pages
* stay free of icon logic and this stays testable.
*/
import {
BRAND_ICONS,
CLI_ICON_SLUGS,
MCP_ICON_SLUGS,
type BrandIcon,
} from "@/lib/brand-icons.generated";
export type BrandNamespace = "mcp" | "cli";
/**
* The mark for *id* in *namespace*, or `null` when there is none.
*
* `null` is the common case and not a failure: coverage is partial on purpose
* (see `brand-slugs.ts`), and a monogram is the designed fallback rather than a
* degraded one.
*/
export function brandIconFor(
namespace: BrandNamespace,
id: string,
): BrandIcon | null {
const table = namespace === "mcp" ? MCP_ICON_SLUGS : CLI_ICON_SLUGS;
for (const key of candidateKeys(id)) {
const slug = table[key];
if (slug) return BRAND_ICONS[slug] ?? null;
}
return null;
}
/**
* The keys to try for *id*, exact form first.
*
* Exact-first matters: several catalog ids genuinely end in `-cli`
* (`1password-cli`, `android-cli`, `minimax-cli`), and a normaliser that always
* stripped that suffix would look up `1password` and find nothing. The looser
* forms exist only for a *renamed* install — the MCP store lets the installer
* choose a local name, and the common edits are case and separator changes.
*/
function candidateKeys(id: string): string[] {
const raw = String(id ?? "").trim();
if (!raw) return [];
const lowered = raw.toLowerCase();
const dashed = lowered.replace(/[\s_.]+/g, "-");
const stripped = dashed.replace(/^cli-/, "").replace(/-cli$/, "");
return [...new Set([raw, lowered, dashed, stripped])];
}
/**
* Up to two initials for the monogram fallback.
*
* Word-aware: "Google Maps" → "GM", "firecrawl" → "FI". Falls back to the first
* two characters so a single CJK word still renders something.
*/
export function brandInitials(name: string): string {
const cleaned = String(name ?? "").trim();
if (!cleaned) return "?";
const words = cleaned.split(/[\s\-_./]+/).filter(Boolean);
if (words.length >= 2) {
return (words[0][0] + words[1][0]).toUpperCase();
}
return cleaned.slice(0, 2).toUpperCase();
}
export type { BrandIcon };