feat(usage): resolve reports from active session accounts

Resolve source inputs at fetch time so model and credential changes select the account each session spends. Keep the legacy discovered-account RPC for existing clients. Sync OpenCode model events outside foreground turns so usage follows model switches.
This commit is contained in:
Mohamed Boudra
2026-09-26 20:52:57 +02:00
parent 2e53a5b9b5
commit cd324f1bdc
31 changed files with 767 additions and 13 deletions
+17
View File
@@ -95,6 +95,7 @@ import type {
ProviderDiagnosticResponseMessage,
ProviderUsageListResponseMessage,
UsageListReportsResponseMessage,
AgentGetUsageReportResponseMessage,
DaemonGetStatusResponse,
DaemonGetPairingOfferResponse,
DaemonConfigReloadResponse,
@@ -561,6 +562,7 @@ type RefreshProvidersSnapshotPayload = RefreshProvidersSnapshotResponseMessage["
type ProviderDiagnosticPayload = ProviderDiagnosticResponseMessage["payload"];
type ProviderUsageListPayload = ProviderUsageListResponseMessage["payload"];
type UsageListReportsPayload = UsageListReportsResponseMessage["payload"];
type AgentGetUsageReportPayload = AgentGetUsageReportResponseMessage["payload"];
type DaemonStatusPayload = DaemonGetStatusResponse["payload"];
type DaemonPairingOfferPayload = DaemonGetPairingOfferResponse["payload"];
type DiagnosticsPayload = DiagnosticsResponse["payload"];
@@ -5250,6 +5252,21 @@ export class DaemonClient {
});
}
async getAgentUsageReport(options: {
agentId: string;
requestId?: string;
forceRefresh?: boolean;
}): Promise<AgentGetUsageReportPayload> {
return this.sendNamespacedCorrelatedSessionRequest({
requestId: options.requestId,
message: {
type: "agent.get_usage_report.request",
agentId: options.agentId,
forceRefresh: options.forceRefresh,
},
});
}
async listCommands(options: ListCommandsOptions): Promise<ListCommandsPayload>;
async listCommands(agentId: string, requestId?: string): Promise<ListCommandsPayload>;
async listCommands(