feat: complete pre-ai local completion v3

This commit is contained in:
OpenCode
2026-09-21 16:30:27 -03:00
parent 6731eeca08
commit 84b08c2150
41 changed files with 4141 additions and 9 deletions
+16
View File
@@ -18,6 +18,14 @@ class SemanticOutputError(ValueError):
"""Raised when a provider answer violates the strict structured-output schema."""
class ProviderTransportError(RuntimeError):
"""A retryable failure while contacting a semantic provider."""
class ProviderContractError(ValueError):
"""A non-retryable provider response or protocol violation."""
@dataclass
class StructuredResult:
task_type: str
@@ -137,3 +145,11 @@ class BudgetGuard:
if plan.get("estimated_cost") is None:
return allow_unknown_cost
return plan["estimated_cost"] <= self.max_run_cost_usd
def authorize_usage(self, input_tokens: int, output_tokens: int, *, prior_cost_usd: float = 0.0,
allow_unknown_cost: bool = False) -> bool:
"""Apply the same guard to actual usage before accepting a provider result."""
plan = self.estimate(input_tokens, output_tokens)
if plan.get("estimated_cost") is None:
return allow_unknown_cost
return float(prior_cost_usd) + plan["estimated_cost"] <= self.max_run_cost_usd