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:
iven
2026-04-02 02:02:59 +08:00
parent 11e3d37468
commit 837abec48a
6 changed files with 130 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ import {
formatInputType,
} from '../lib/pipeline-client';
import { useToast } from './ui/Toast';
import { saasClient } from '../lib/saas-client';
// === Category Badge Component ===
@@ -431,6 +432,13 @@ export function PipelinesPanel() {
if (result.status === 'completed') {
toast('Pipeline 执行完成', 'success');
setRunResult({ result, pipeline: selectedPipeline! });
// Report pipeline execution to billing (fire-and-forget)
try {
if (saasClient.isAuthenticated()) {
saasClient.reportUsageFireAndForget('pipeline_runs');
}
} catch { /* billing reporting must never block */ }
} else {
toast(`Pipeline 执行失败: ${result.error}`, 'error');
}