Replies: 2 comments 3 replies
-
|
This looks like a good concrete slice of the broader architecture/readability cleanup. The screenshots make the boundary problem pretty clear: I especially like that this proposed extraction is not trying to rewrite the frontend stack or change chat behavior. Pulling model metadata, pricing/cost helpers, endpoint detection, formatting helpers, and safe URL/image helpers out of The line I would hold is:
If a module needs model pricing, endpoint labels, cost calculation, safe image source validation, or formatting utilities, those should live in focused modules with names that describe their actual responsibility. I would keep the first PR intentionally small:
This would be a strong example of the kind of incremental refactor Odysseus needs: not a rewrite, not a framework decision, just a clear responsibility boundary with a reviewable diff. If this pattern works well, it can become the template for extracting other overloaded frontend modules. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Overview
Just as the title says, this is a great module on its own - but it is increasingly being overworked, and over-referenced externally, unnecessarily, and against maintainable / best principles.
I hope I do not have to list all of the reasons this file needs refactoring...
Said shortly, we can get more out of it (and out of what it contains) by separating concerns a bit more than what exists currently.
The current list of exports contains components that ChatRenderer should not be tasked with providing.

The Current Refactor
The current state of the refactor merge request.
Models
What the refactor pulls out of ChatRenderer, and puts into the existing
modelfoldergraph LR A[Model Extractions] --> B[Data Layer] A --> C[Helper Functions] A --> D[Endpoint Detection] A --> E[Cost Calculation] B --> B1[MODEL_INFO<br/>Pricing & Context] B --> B2[IMAGE_PRICING<br/>Image Costs] B --> B3[MODEL_PRICING<br/>Compat Alias] C --> C1[shortModel<br/>Name simplification] C --> C2[sameModelName<br/>Name comparison] C --> C3[modelRouteLabel<br/>Display labels] C --> C4[replyModelPair<br/>Extract metadata] C --> C5[modelColor<br/>HSL generation] C --> C6[getModelInfo<br/>Lookup pricing] D --> D1[isLocalEndpoint<br/>Free models] D --> D2[isSubscriptionEndpoint<br/>ChatGPT] D --> D3[isCostTrackedEndpoint<br/>Billable] E --> E1[getModelCost<br/>Calculate textual cost] E --> E2[getImageCost<br/>Calculate image cost] style A fill:#e1f5ff,color:black style B fill:#fff4e1,color:black style C fill:#f3e5f5,color:black style D fill:#e8f5e9,color:black style E fill:#ffebee,color:blackUtility functions (Safe Strings)
Next up to be extracted from this file, are some useful UISafeString functions:
Utility functions ((string) Format)
formatCompactNumberexisted as_fmtCtxand may be useful outside of chatRenderer.toTrimmedStringexisted asmodelValueand is now much more clear as to its function, plus may be useful outside of chatRenderer.Benefits:
Code maintainability is improved because pricing data, validation helpers, and model-related exports have a source of truth outside of the overworked renderer file. Future changes become isolated and easier to reason about.
~300 fewer lines to sift through (it's a start)
Test Plan:
Beta Was this translation helpful? Give feedback.
All reactions