Refactoring#49
Conversation
Add a new @enfinyte/services package that re-exports all shared Live service layers (Resolver, Vault, Ledger) from a single canonical import path. Update backend and api_platform to import from @enfinyte/services instead of directly from resolver, vault, and ledger packages.
- Fix bugs: getCostForModel return type mismatch, unsafe LLM output assertion, typo in model_cost.ts - Add logging helper (log.ts) to reduce boilerplate across all modules - Clean up service entry: extract withRedis helper, move logging into resolveImpl, simplify getCostForModel to one-liner - Split resolve_auto.ts (261 lines) into extract_text.ts, classify.ts, and slimmed resolve_auto.ts - Split parse_model_id.ts (968 lines) into per-family parser directory with types, constants, helpers, strip, and 6 family parsers - Reorganize data_manager/fetch.ts: remove unsafe generic cast, split modelsDevAction into focused functions, reduce logging noise
models.dev reports costs in USD per million tokens (e.g. input=15 means $15/1M tokens), but buildTransaction was multiplying raw token counts directly by this rate, producing costs 1,000,000x too high.
Greptile SummaryThis PR is a structural refactoring that introduces a new Key changes:
Issues found:
Confidence Score: 4/5Safe to merge; primarily structural refactoring with a critical billing bug fix and no breaking API changes The changes are well-scoped: the new @enfinyte/services package is a clean consolidation, the parse_model_id split is a faithful extraction with no logic changes, and the billing fix is correct. Score is 4 rather than 5 due to the removed error logging for network failures (operational regression), one internal-path import that violates the PR's own package-boundary goal, and a dead null return type that could mislead future contributors. packages/backend/src/services/apikey.ts (internal path import), packages/resolver/src/data_manager/fetch.ts (removed error logging), packages/resolver/src/parser/parse_model_id/index.ts (dead null return type) Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["@enfinyte/services\n(new package)"] -->|re-exports| B["resolver"]
A -->|re-exports| C["vault"]
A -->|re-exports| D["ledger"]
E["api_platform"] -->|imports from| A
F["backend"] -->|imports from| A
F -->|"direct internal import ⚠️"| B
B --> G["resolver/index.ts\n(ResolverServiceLive)"]
G --> H["resolver/classify.ts (new)"]
G --> I["resolver/extract_text.ts (new)"]
G --> J["resolver/resolve_auto.ts"]
G --> K["resolver/resolve_intent.ts"]
B --> M["parser/parse_model_id/ (new dir)"]
M --> N["index.ts"]
M --> O["families/claude.ts"]
M --> P["families/gpt.ts"]
M --> Q["families/gemini.ts + llama.ts + o_series.ts + generic.ts"]
B --> U["log.ts (new)"]
U -->|resolverLog| G
U -->|dataManagerLog| V["data_manager/fetch.ts"]
Reviews (1): Last reviewed commit: "fix: divide token costs by 1M to match m..." | Re-trigger Greptile |
No description provided.