feat(capabilities): allow free verbs with no billing unit

This commit is contained in:
CREDO23 2026-07-01 17:08:58 +02:00
parent 8d76afc9d6
commit a413539f6a
3 changed files with 17 additions and 4 deletions

View file

@ -17,9 +17,11 @@ if TYPE_CHECKING:
async def charge_capability(
output: BillableOutput, unit: BillingUnit, ctx: CapabilityContext
output: BillableOutput, unit: BillingUnit | None, ctx: CapabilityContext
) -> None:
"""Bill the workspace owner for this result's billable successes (03c)."""
"""Bill the workspace owner for this result's billable successes (03c). ``None`` = free."""
if unit is None:
return
units = output.billable_units
if units <= 0:
return

View file

@ -13,7 +13,7 @@ if TYPE_CHECKING:
class BillingUnit(StrEnum):
"""The meter a verb charges on (priced by the billing service, 03c)."""
"""The meter a verb charges on (priced by the billing service, 03c). ``None`` = free."""
WEB_CRAWL = "web_crawl"
@ -44,4 +44,4 @@ class Capability:
input_schema: type[BaseModel]
output_schema: type[BaseModel]
executor: Executor
billing_unit: BillingUnit
billing_unit: BillingUnit | None

View file

@ -114,3 +114,14 @@ async def test_disabled_is_noop(monkeypatch, record_usage):
record_usage.assert_not_awaited()
session.execute.assert_not_called()
assert user.credit_micros_balance == 100_000
async def test_free_verb_without_a_unit_is_noop(monkeypatch, record_usage):
monkeypatch.setattr(config, "WEB_CRAWL_CREDIT_BILLING_ENABLED", True)
session, user = _make_session(_OWNER, balance_micros=100_000)
await charge_capability(_output("success", "success"), None, _ctx(session))
record_usage.assert_not_awaited()
session.execute.assert_not_called()
assert user.credit_micros_balance == 100_000