Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions Sources/CodexBar/InlineUsageDashboardContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ extension UsageMenuCardView.Model {
]
}

if input.provider == .deepseek,
let usage = input.snapshot?.deepseekUsage
{
let symbol = usage.currency == "CNY" ? "¥" : "$"
let todayCostStr = usage.todayCost.map { "\(symbol)\(String(format: "%.4f", max(0, $0)))" } ?? "—"
return [
"Today: \(todayCostStr) · \(UsageFormatter.tokenCountString(usage.todayTokens)) tokens",
"This month: \(UsageFormatter.tokenCountString(usage.currentMonthTokens)) tokens",
]
}

if input.provider == .ollama,
input.snapshot?.identity?.loginMethod == "API key"
{
Expand Down Expand Up @@ -115,6 +126,12 @@ extension UsageMenuCardView.Model {
{
return Self.minimaxInlineDashboard(billing)
}
if input.provider == .deepseek,
let usage = input.snapshot?.deepseekUsage,
!usage.daily.isEmpty
{
return Self.deepseekInlineDashboard(usage)
}
if [.codex, .claude, .vertexai, .bedrock].contains(input.provider),
input.tokenCostUsageEnabled,
let tokenSnapshot = input.tokenSnapshot,
Expand Down Expand Up @@ -422,6 +439,59 @@ extension UsageMenuCardView.Model {
detailLines: details)
}

private static func deepseekInlineDashboard(_ usage: DeepSeekUsageSummary) -> InlineUsageDashboardModel {
let symbol = usage.currency == "CNY" ? "¥" : "$"
let points = usage.daily.suffix(30).map {
InlineUsageDashboardModel.Point(
id: $0.date,
label: Self.shortDayLabel($0.date),
value: Double($0.totalTokens),
accessibilityValue: "\($0.date): \(UsageFormatter.tokenCountString($0.totalTokens)) tokens")
}
var details: [String] = []
if let topModel = usage.topModel {
details.append("Top model: \(Self.shortModelName(topModel))")
}
if let cacheHit = usage.categoryBreakdown.first(where: { $0.category == .promptCacheHitToken }) {
details.append("cache-hit input: \(UsageFormatter.tokenCountString(cacheHit.tokens))")
}
if let cacheMiss = usage.categoryBreakdown.first(where: { $0.category == .promptCacheMissToken }) {
details.append("cache-miss input: \(UsageFormatter.tokenCountString(cacheMiss.tokens))")
}
if let output = usage.categoryBreakdown.first(where: { $0.category == .responseToken }) {
details.append("output: \(UsageFormatter.tokenCountString(output.tokens))")
}
details.append("requests: \(usage.currentMonthRequestCount)")

let todayCostStr = usage.todayCost.map { "\(symbol)\(String(format: "%.4f", max(0, $0)))" } ?? "—"
let monthCostStr = usage.currentMonthCost.map { "\(symbol)\(String(format: "%.4f", max(0, $0)))" } ?? "—"
let monthTokensStr = UsageFormatter.tokenCountString(usage.currentMonthTokens)

return InlineUsageDashboardModel(
accessibilityLabel: "DeepSeek 30 day token usage trend",
valueStyle: .tokens,
kpis: [
.init(
title: "Today",
value: "\(todayCostStr) · \(UsageFormatter.tokenCountString(usage.todayTokens))",
emphasis: true),
.init(
title: "This month",
value: "\(monthCostStr) · \(monthTokensStr)",
emphasis: false),
.init(
title: "Models",
value: usage.topModel.map { Self.shortModelName($0) } ?? "—",
emphasis: false),
.init(
title: "Requests",
value: "\(usage.currentMonthRequestCount)",
emphasis: false),
],
points: points,
detailLines: details)
}

private static func topMistralModel(from entries: [MistralDailyUsageBucket]) -> String? {
var tokens: [String: Int] = [:]
for entry in entries {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ struct DeepSeekAPIFetchStrategy: ProviderFetchStrategy {
guard let apiKey = Self.resolveToken(environment: context.env) else {
throw DeepSeekUsageError.missingCredentials
}
let usage = try await DeepSeekUsageFetcher.fetchUsage(apiKey: apiKey)
let usage = try await DeepSeekUsageFetcher.fetchUsage(
apiKey: apiKey,
includeOptionalUsage: context.includeOptionalUsage)

return self.makeResult(
usage: usage.toUsageSnapshot(),
sourceLabel: "api")
Expand Down
Loading