## 🐛 Critical Bug Fix ### Cost Calculation Error (1000x undercharge) - **Fixed**: Cost conversion utility was calculating credits at 1/1000th of actual value - **Before**: `cents * 10` ❌ - **After**: `(cents / 100) * DOLLAR_TO_CREDIT_MULTIPLIER` ✅ - **Impact**: Users were being undercharged by 1000x - Example: 0.75 cents should = 7,500 credits - Bug calculated it as 7.5 credits --- ## 🎯 Code Centralization & DRY ### Unified Cost Calculation - Centralized all cost conversions to use `convertCentsToBillingCredits` utility - Refactored 3 different implementations into 1 single source of truth - Files updated: - `ai-billing.service.ts` - `agent-streaming.service.ts` (2 usages) **Before** (multiple implementations): ```typescript // Wrong implementation const credits = cents * 10; // Verbose implementation const costInDollars = costInCents / 100; const creditsUsed = Math.round(costInDollars * DOLLAR_TO_CREDIT_MULTIPLIER); ``` **After** (unified): ```typescript const creditsUsed = Math.round(convertCentsToBillingCredits(costInCents)); ``` --- ## ✨ UI Component Refactoring ### RoutingDebugDisplay.tsx - **Reduced from 118 lines to 34 lines** (71% reduction) - Extracted `renderTimingRow` helper to eliminate 15 repetitive JSX blocks - Added `formatTokenBreakdown` helper for token display logic - Much easier to add new debug metrics **Before**: 15 nearly-identical blocks of repetitive JSX **After**: Clean, DRY implementation with reusable helpers --- ## 🧹 Code Quality Improvements ### Removed Debug Code - Removed `console.log` accidentally left in `RoutingStatusDisplay.tsx` ### Cleaned Up Comments (18+ removed) Removed redundant comments that stated the obvious: - ❌ "Calculate routing cost if we have token usage" - ❌ "Send the updated routing status with execution metrics to the client" - ❌ "Count tool calls in the response" - ❌ "AI SDK's LanguageModelUsage uses inputTokens/outputTokens" - And 14+ more... Kept meaningful comments: - ✅ "Timing is optional, ignore errors" (explains catch block) - ✅ Type definition grouping comments --- ## 📊 Statistics **Files Modified**: 10 - `convert-cents-to-billing-credits.util.ts` (fixed formula) - `ai-billing.service.ts` (use centralized utility) - `agent-streaming.service.ts` (use utility, remove comments) - `agent-execution.service.ts` (remove comments) - `ai-router.service.ts` (remove comments) - `RoutingStatusDisplay.tsx` (remove debug code) - `RoutingDebugDisplay.tsx` (major refactor) ⭐ - `isDebugModeState.ts` (new file) - `DataMessagePart.ts` (type extensions) - `useClientConfig.ts` (debug mode support) **Impact**: - Lines removed: ~130 (redundant code + comments) - Lines added: ~45 (helper functions) - **Net reduction**: ~85 lines - **Bug fixes**: 1 critical (1000x cost error) - **Centralizations**: 3 locations now using shared utility - **Major refactors**: 1 UI component (71% reduction) --- ## ✅ Verification - ✅ All linter checks pass - ✅ All tests pass (`ai-billing.service.spec.ts` verified) - ✅ No `any` types in affected code - ✅ No TODO/FIXME markers --- ## 🎯 Principles Applied 1. ✅ **Fix Root Causes, Not Symptoms** - Fixed utility function, then used it everywhere 2. ✅ **DRY (Don't Repeat Yourself)** - Centralized cost calculation and UI rendering 3. ✅ **Single Source of Truth** - One place for cost conversion formula 4. ✅ **Code as Documentation** - Removed comments that repeated what code says 5. ✅ **Composability** - Created reusable helper functions 6. ✅ **Type Safety** - Maintained strict typing throughout
The #1 Open-Source CRM
🌐 Website · 📚 Documentation · Roadmap ·
Discord ·
Figma
Installation
See: 🚀 Self-hosting 🖥️ Local Setup
Does the world need another CRM?
We built Twenty for three reasons:
CRMs are too expensive, and users are trapped. Companies use locked-in customer data to hike prices. It shouldn't be that way.
A fresh start is required to build a better experience. We can learn from past mistakes and craft a cohesive experience inspired by new UX patterns from tools like Notion, Airtable or Linear.
We believe in Open-source and community. Hundreds of developers are already building Twenty together. Once we have plugin capabilities, a whole ecosystem will grow around it.
What You Can Do With Twenty
Please feel free to flag any specific needs you have by creating an issue.
Below are a few features we have implemented to date:
- Personalize layouts with filters, sort, group by, kanban and table views
- Customize your objects and fields
- Create and manage permissions with custom roles
- Automate workflow with triggers and actions
- Emails, calendar events, files, and more
Personalize layouts with filters, sort, group by, kanban and table views
Customize your objects and fields
Create and manage permissions with custom roles
Automate workflow with triggers and actions
Emails, calendar events, files, and more
Stack
- TypeScript
- Nx
- NestJS, with BullMQ, PostgreSQL, Redis
- React, with Recoil, Emotion and Lingui
Thanks
Thanks to these amazing services that we use and recommend for UI testing (Chromatic), code review (Greptile), catching bugs (Sentry) and translating (Crowdin).
Join the Community
- Star the repo
- Subscribe to releases (watch -> custom -> releases)
- Follow us on Twitter or LinkedIn
- Join our Discord
- Improve translations on Crowdin
- Contributions are, of course, most welcome!




