feat(billing): add usage increment API + wire hand/pipeline execution tracking
Server side: - POST /api/v1/billing/usage/increment endpoint with dimension whitelist (hand_executions, pipeline_runs, relay_requests) and count validation (1-100) - Returns updated usage quota after increment Desktop side: - New saas-billing.ts mixin with incrementUsageDimension() and reportUsageFireAndForget() (non-blocking, safe for finally blocks) - handStore.triggerHand: reports hand_executions after successful run - PipelinesPanel.handleRunComplete: reports pipeline_runs on completion - SaaSClient type declarations for new billing methods Billing pipeline now covers all three dimensions: relay_requests → relay handler (server-side, real-time) hand_executions → handStore (client-side, fire-and-forget) pipeline_runs → PipelinesPanel (client-side, fire-and-forget)
This commit is contained in:
@@ -8,6 +8,7 @@ import { create } from 'zustand';
|
||||
import type { GatewayClient } from '../lib/gateway-client';
|
||||
import { canAutoExecute, getAutonomyManager } from '../lib/autonomy-manager';
|
||||
import type { AutonomyDecision } from '../lib/autonomy-manager';
|
||||
import { saasClient } from '../lib/saas-client';
|
||||
|
||||
// === Re-exported Types (from gatewayStore for compatibility) ===
|
||||
|
||||
@@ -355,6 +356,13 @@ export const useHandStore = create<HandStore>((set, get) => ({
|
||||
// Refresh hands to update status
|
||||
await get().loadHands();
|
||||
|
||||
// Report hand execution to billing (fire-and-forget, non-blocking)
|
||||
try {
|
||||
if (saasClient.isAuthenticated()) {
|
||||
saasClient.reportUsageFireAndForget('hand_executions');
|
||||
}
|
||||
} catch { /* billing reporting must never block */ }
|
||||
|
||||
return run;
|
||||
} catch (err: unknown) {
|
||||
set({ error: err instanceof Error ? err.message : String(err) });
|
||||
|
||||
Reference in New Issue
Block a user