38 lines
1.8 KiB
Markdown
38 lines
1.8 KiB
Markdown
|
|
---
|
||
|
|
brief: 1
|
||
|
|
convoy: polish-dag-tiers-cost
|
||
|
|
role: role-implementer
|
||
|
|
title: Cost budget UI + caps — month-to-date spend and dispatch pause
|
||
|
|
status: ready
|
||
|
|
priority: P1
|
||
|
|
slice_dependencies: []
|
||
|
|
recommended_model: qwen-coder
|
||
|
|
model_tier: local
|
||
|
|
---
|
||
|
|
|
||
|
|
# Brief 1 — `Task-cost-budget-ui-and-caps` (Epic 1 follow-on)
|
||
|
|
|
||
|
|
## Goal
|
||
|
|
|
||
|
|
Month-to-date spend per alias/tier visible, caps pause dispatch when exceeded. Autensa benchmark row `cost tracking & budget caps` `plans/Plan-automation-foundation/Plan-automation-foundation.md:236`.
|
||
|
|
|
||
|
|
## Files
|
||
|
|
|
||
|
|
- `packages/database/src/schema/budget_caps.ts` NEW — `id uuid, workspace_id fk, cap_usd numeric(12,2), period varchar monthly, enabled bool, created_at`. + `spend_ledger` view or `convoy_events` sum query.
|
||
|
|
- `apps/web/server/routers/budgets.ts` NEW — `getSpend(workspaceId)` sums `convoy_events.estimated_cost_usd` month-to-date grouped by `model_alias`; `getCap`/`upsertCap`/`deleteCap` admin only; `shouldPauseDispatch` helper for orchestrator.
|
||
|
|
- `apps/orchestrator/src/tick.ts` — call `shouldPauseDispatch` before `enqueueJob`, return `pause` action when cap exceeded.
|
||
|
|
- `apps/web/app/(app)/[workspaceSlug]/settings/ai/budgets/page.tsx` NEW — table cap + spend chart (simple bar), Test.
|
||
|
|
|
||
|
|
## Acceptance
|
||
|
|
|
||
|
|
- `/settings/ai/budgets` shows MTD $42/$100 (example), `upsertCap cap_usd:100` → orchestrator `tick` returns `pause reason: budget cap` when sum > cap.
|
||
|
|
- `pnpm lint && pnpm type-check` pass.
|
||
|
|
|
||
|
|
## Prompt
|
||
|
|
|
||
|
|
You are `role-implementer` brief 1. Read `plans/Plan-automation-foundation/Epic-model-provider-registry/Task-cost-budget-ui-and-caps.md`, `packages/database/src/schema/convoy_events.ts`, `apps/orchestrator/src/tick.ts`, `docs/adr-model-routing.md`. Keep ledger query simple (sum `estimated_cost_usd` where `occurred_at >= month_start`).
|
||
|
|
|
||
|
|
## Depends
|
||
|
|
|
||
|
|
None.
|