feat: add P2 features — retry policy, prompt templating, usage tracking, tech debt cleanup
- Extract shared splitMessage() into channels/utils.ts (dedup 4 adapters) - Add Slack user name resolution with caching (users.info API) - Add withRetry() with exponential backoff + jitter, isRetryable() filter - Wire retry config into ModelRouter.chat() (non-streaming only) - Add assembleSystemPrompt() multi-file template system (SOUL/AGENTS/IDENTITY/USER/TOOLS.md) - Add usage tracking accumulators in NativeAgent + AgentOrchestrator - Add estimateCost() with per-model pricing table - Add /usage TUI command with full usage report formatting - Add retrySchema and promptSchema to config schema Tests: 569 passing, typecheck clean
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
/** Approximate cost per million tokens for known models. */
|
||||
export const MODEL_COSTS_PER_MILLION: Record<string, { input: number; output: number }> = {
|
||||
// Anthropic
|
||||
'claude-sonnet-4-20250514': { input: 3, output: 15 },
|
||||
'claude-3-5-haiku-20241022': { input: 0.80, output: 4 },
|
||||
'claude-opus-4-20250514': { input: 15, output: 75 },
|
||||
// OpenAI
|
||||
'gpt-4o': { input: 2.50, output: 10 },
|
||||
'gpt-4o-mini': { input: 0.15, output: 0.60 },
|
||||
// Local / unknown models
|
||||
'default': { input: 0, output: 0 },
|
||||
};
|
||||
|
||||
/**
|
||||
* Estimate the dollar cost for a given number of input/output tokens.
|
||||
* Falls back to zero cost for unknown or local models.
|
||||
*/
|
||||
export function estimateCost(inputTokens: number, outputTokens: number, modelName?: string): number {
|
||||
const costs = MODEL_COSTS_PER_MILLION[modelName ?? ''] ?? MODEL_COSTS_PER_MILLION['default'];
|
||||
return (inputTokens * costs.input + outputTokens * costs.output) / 1_000_000;
|
||||
}
|
||||
Reference in New Issue
Block a user