Skip to content

LOU-W1: token estimation and a model registry (context window + pricing) - #45

Merged
LinuxDevil merged 2 commits into
mainfrom
lou-w1-token-estimation
Oct 1, 2026
Merged

LinuxDevil merged 2 commits into
mainfrom
lou-w1-token-estimation

Conversation

@LinuxDevil

Copy link
Copy Markdown
Owner

What

New src/models/ module, exported from src/index.ts: estimateTokens, setTokenEstimator / options.estimator, getModelInfo, registerModel, estimateCost. Docs: "Models, tokens and cost" section in docs/api-overview.md. Not wired into the executor.

Why

Foundation for context compaction, budgets and cost accounting: small, dependency-free, overridable.

How verified

  • npx tsc --noEmit: clean
  • npm run lint: 0 errors (432 pre-existing warnings, none in src/models)
  • npm run build + create-loushy-agent build: success
  • npm run test:coverage: 95 files passed, 1163 tests passed, 3 skipped
  • npm run fallow: exit 0
  • npm run docs:verify-snippets: all 30 snippets type-check, 5 run cleanly
  • Merged origin/main at 13a6131 before verification (already up to date).

Notes for reviewer

  • Built-in table (retrieved 2026-10-01, sources in src/models/modelData.ts) only includes models read from OpenAI model/pricing pages, Anthropic's models overview and Ollama library pages. Ollama entries have no prices (local), so estimateCost returns undefined. Qwen2.5 was omitted because its context window was ambiguous. OpenAI pages were read via a summarizing fetch tool, so a quick spot-check of numbers is worthwhile.
  • "128K" max output read as 128000, "1M" context as 1000000 (Anthropic).
  • Snapshot prefix matching only accepts suffixes like -2024-07-18, -latest, :tag, @date, so o3-mini does not resolve to o3 and gpt-5.4 does not resolve to gpt-5.
  • Message.content is typed string; non-string content is JSON-stringified defensively.
  • model option is only forwarded to custom estimators; the built-in heuristic is model-independent.

🤖 Generated with Claude Code

LinuxDevil and others added 2 commits October 1, 2026 09:24
Adds src/models/ (exported from src/index.ts): estimateTokens (dependency-free
heuristic: ~chars/4 for Latin, higher ratios for CJK/other scripts and emoji,
counted by code point, plus per-message overhead and tool-call JSON),
setTokenEstimator / options.estimator for plugging in a real tokenizer,
getModelInfo / registerModel (exact id, provider/ prefix, then dated-snapshot
prefix match), and estimateCost (undefined when unknown).

The built-in table only contains models whose context window and prices were
read from OpenAI, Anthropic and Ollama pages; retrieval date and sources are
recorded in modelData.ts. Not wired into the executor yet.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@LinuxDevil
LinuxDevil merged commit 85c436d into main Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant