mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-04 01:48:57 +00:00
* fix(proxy): reset customer org, team and member spend on their budget row's window The customer tables carried their own budget_reset_at next to a budget_id whose row already has one. Drop the column from the three tables and let the budget table cascade zero the customer rows it governs, with a member following its unexpired override when that override has a duration and its template otherwise. Customer budget writes stamp budget_reset_at from budget_duration the way /budget/new does, and the management responses report the governing budget's window under the same budget_reset_at field. * feat(budgets): support concurrent customer budget windows * fix(budgets): resolve compatibility and validation checks * feat(proxy): name budget rows, give customer teams an override and members a parent org * fix(budgets): preserve admitted windows during accounting * chore(schema): allow dropping the unreleased customer budget_reset_at columns * fix(budgets): apply standard migration lock timeout * feat(proxy): customer members belong to many teams, charged to the one the request names * test(migrations): allow the unreleased customer budget_reset_at drop * style(ui): prettier the customer dashboard files Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * chore(reset-job): name the batch bound on the customer budget IN filters Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * fix(budgets): preserve mixed limits and resolve CI regressions * fix(budgets): reuse shared spend verification for customer windows * refactor(ui): isolate customer budget group creation Keep only the customer-creation UI on current main. This local patch still depends on the BudgetTemplate.budget_limits API and generated types from the #51510 rebuild. * fix(proxy): restore Field import and bound the member team lookup after the merge Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * test(proxy): send parent_team_ids in the budget window customer tests Co-authored-by: Tin <tin@berri.ai> Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * fix(proxy): keep rejecting another organization's template after the budget_template_ids rename Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * fix(proxy): reset customer teams and members in pages against each row's own cap, keep a template's clock on resubmitted durations Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * feat(proxy): pause_allow_increase cap policy with customer budget increase requests reviewed like MCP and skill submissions Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * test(proxy): cover customer budget increase requests and the cap_policy field Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * chore(ui): regenerate API types for cap_policy and customer budget increase requests Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * fix(proxy): hang the increase request back-reference on the customer member model Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * fix(proxy): declare increase request list filters with Annotated Query Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * fix(proxy): scope budget increase requests to the key's organization, require a future expiry, one pending request per member, and never revive an expired override on approval Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * fix(proxy): write customer budgets without windows as Prisma Json null, run the increase request table through the hierarchy transaction Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> * fix(proxy): review increase requests exactly once, let an approval replace template windows, pin member budget_id to the org's templates, open the request route to virtual keys Co-Authored-By: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com> --------- Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Tin <tin@berri.ai> Co-authored-by: kerry <kerry@berri.ai> Co-authored-by: Ishaan Jaffer <155045088+ishaan-berri@users.noreply.github.com>
108 lines
4.5 KiB
Python
108 lines
4.5 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
from collections.abc import Iterator, Mapping
|
|
from pathlib import Path
|
|
from types import MappingProxyType
|
|
from typing import Final
|
|
|
|
from pydantic import TypeAdapter
|
|
|
|
Schema = Mapping[str, Mapping[str, str]]
|
|
MODELS: Final = re.compile(r"^[ \t]*model\s+(\w+)\s*\{(.*?)^[ \t]*\}", re.MULTILINE | re.DOTALL)
|
|
DROPPED_UNUSED_MODELS: Final = frozenset({"LiteLLM_AccountingDelivery", "LiteLLM_AccountingEvent"})
|
|
RENAMED_UNRELEASED_FIELDS: Final = frozenset(
|
|
{
|
|
("LiteLLM_CustomerMemberTable", "budget_template_id"),
|
|
("LiteLLM_CustomerMemberTable", "budget_template"),
|
|
("LiteLLM_BudgetTable", "customer_member_templates"),
|
|
("LiteLLM_CustomerOrganizationTable", "budget_ids"),
|
|
("LiteLLM_CustomerOrganizationTable", "budget_names"),
|
|
("LiteLLM_CustomerOrganizationTable", "default_budget_id"),
|
|
("LiteLLM_CustomerOrganizationTable", "default_budget"),
|
|
("LiteLLM_CustomerTeamTable", "members"),
|
|
("LiteLLM_CustomerMemberTable", "parent_team_id"),
|
|
("LiteLLM_CustomerMemberTable", "parent_team"),
|
|
("LiteLLM_CustomerOrganizationTable", "budget_reset_at"),
|
|
("LiteLLM_CustomerTeamTable", "budget_reset_at"),
|
|
("LiteLLM_CustomerMemberTable", "budget_reset_at"),
|
|
}
|
|
)
|
|
|
|
|
|
def parse_model_fields(schema: str) -> Schema:
|
|
def fields(body: str) -> Mapping[str, str]:
|
|
parts: Final = tuple(line.split() for line in body.splitlines())
|
|
return MappingProxyType({part[0]: " ".join(part[1:]) for part in parts if len(part) >= 2})
|
|
|
|
return MappingProxyType({match[1]: fields(match[2]) for match in MODELS.finditer(schema)})
|
|
|
|
|
|
def _field_changes(model: str, field: str, old_type: str, new_fields: Mapping[str, str]) -> Iterator[str]:
|
|
if field not in new_fields:
|
|
if (model, field) in RENAMED_UNRELEASED_FIELDS:
|
|
return
|
|
yield f"Breaking: Field {model}.{field} was removed"
|
|
return
|
|
old_base: Final = old_type.split()[0]
|
|
new_base: Final = new_fields[field].split()[0]
|
|
if old_base.endswith("?") and not new_base.endswith("?"):
|
|
yield f"Breaking: Field {model}.{field} changed from optional to required"
|
|
if old_base.rstrip("?") != new_base.rstrip("?"):
|
|
yield f"Breaking: Field {model}.{field} changed type from {old_base} to {new_base}"
|
|
|
|
|
|
def _model_changes(model: str, old_fields: Mapping[str, str], new_schema: Schema) -> Iterator[str]:
|
|
if model not in new_schema:
|
|
if model not in DROPPED_UNUSED_MODELS:
|
|
yield f"Breaking: Model {model} was removed"
|
|
return
|
|
for field, old_type in old_fields.items():
|
|
yield from _field_changes(model, field, old_type, new_schema[model])
|
|
|
|
|
|
def check_breaking_changes(old_schema: Schema, new_schema: Schema) -> tuple[str, ...]:
|
|
def changes() -> Iterator[str]:
|
|
for model, fields in old_schema.items():
|
|
yield from _model_changes(model, fields, new_schema)
|
|
|
|
return tuple(changes())
|
|
|
|
|
|
def _merge_base(base_ref: str) -> str:
|
|
return subprocess.run(
|
|
("git", "merge-base", "HEAD", base_ref), capture_output=True, text=True, check=True
|
|
).stdout.strip()
|
|
|
|
|
|
def main() -> int:
|
|
parser: Final = argparse.ArgumentParser()
|
|
source: Final = parser.add_mutually_exclusive_group(required=True)
|
|
source.add_argument("--base-ref", help="compare against the merge base of HEAD and this ref (needs history)")
|
|
source.add_argument("--base-commit", help="compare against this commit as is (works in a shallow clone)")
|
|
options: Final = TypeAdapter(dict[str, str | None]).validate_python(vars(parser.parse_args()))
|
|
base_commit: Final = options["base_commit"]
|
|
base: Final = base_commit if base_commit else _merge_base(options["base_ref"] or "")
|
|
canonical: Final = subprocess.run(
|
|
("git", "show", f"{base}:litellm/schema.prisma"), capture_output=True, text=True, check=False
|
|
)
|
|
previous: Final = (
|
|
canonical.stdout
|
|
if canonical.returncode == 0
|
|
else subprocess.run(("git", "show", f"{base}:schema.prisma"), capture_output=True, text=True, check=True).stdout
|
|
)
|
|
changes: Final = check_breaking_changes(
|
|
parse_model_fields(previous), parse_model_fields(Path("litellm/schema.prisma").read_text())
|
|
)
|
|
if changes:
|
|
sys.stderr.write("\n".join(changes) + "\n")
|
|
return 1
|
|
sys.stdout.write(f"Schema compatibility passed against merge base {base}\n")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|