GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing github.com — feat: add organization AI model price API by SasSwart · Pull Request #30720 · coder/coder Conversation
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
2bb1898 to
fca688a
Compare
fca688a to
1c1f8ee
Compare
1c1f8ee to
3f3c081
Compare
3f3c081 to
f2a98ad
Compare
f2a98ad to
dbad92e
Compare
… validation (#30716) Moves request body decoding and per-price validation out of the site-wide `upsertAIModelPrices` handler, so the organization price handler later in this stack can reuse them. - The handler still reads the body and writes the HTTP errors. `writeAIModelPricesBodyReadError` picks 413 or 400. - `decodeAIModelPricesBody` only decodes, and returns an error. - `aiModelPriceKeys` holds the JSON keys present in one price, so validation can tell an explicit `null` apart from a missing price. - `validateAIModelPriceValues` checks the four prices of one model price. It takes them as an `aiModelTokenPrices` struct, so callers set each price by name and cannot pass them in the wrong order. No behavior change. The existing `TestUpsertAIModelPrices`, `TestListAIModelPrices` and `TestValidateAIModelPrices` cover the site-wide handler. **Used later:** #30720 reuses the body read error, the price keys and the value validation for its single-price upsert. --- *This PR was generated by Coder Agents on behalf of @SasSwart.*
19145a1 to
d280997
Compare
Organization prices are only per configured provider, so remove the upsert and delete queries for provider type prices and their listing branch.
Org admins edit prices one model at a time, so the upsert takes typed params instead of a JSON batch. The org price listing tells organization and site-wide rows apart by provider_id instead of a price kind.
Replace GetOrganizationAIModelPrices, which listed every price that applies to an organization, with GetOrganizationAIProviderModelPrice, which reads one price by organization, provider and model. Queries target the renamed ai_model_configs table. Split the tests per query, and cover that an identical upsert leaves updated_at unchanged and that an empty model is rejected. Leave a TODO to authorize these queries against a resource for AI Governance model config rather than ResourceAiModelPrice.
DeleteOrganizationAIProviderModelPrice now flags the live row as deleted instead of removing it. Reads and upserts only match live rows, so an upsert after a delete inserts a new live row and leaves the soft-deleted one untouched.
d280997 to
09b9751
Compare
…elper The get helper captured the parent test's context and testing.T, which paralleltestctx flags once the subtests call t.Parallel.
…okup The lookup now ranks an organization's price for the configured provider, then site-wide custom and default prices.
Drop the price kind from the lookup and token usage records, remove the unused GetAIModelPriceByProviderModel query, and stop counting organization prices in the unpriced-models report until they apply at runtime.
Follow the rename of the organization price table to ai_model_configs. Link the TODO for passing the organization to the price lookup to AIGOV-716.
GetAIModelPriceForProvider read ai_model_configs without the deleted filter, so a deleted organization price kept pricing token usage instead of falling back to the site-wide price.
Organization upserts and deletes take a required provider_id. The provider type field and the organization_provider_type scope are gone.
POST on the organization route takes a single price for one configured provider, matching how org admins edit prices. The listing scope comes from provider_id now that the price kind is gone.
GetOrganizationAIModelPrices is gone, so the organization GET route now returns one price, keyed like DELETE by the provider_id and model query parameters, and 404s when the organization has no such price. OrganizationAIModelPrice drops the fields that only described a merged listing: scope, provider type, provider name, and source. Validate the organization price through aiModelTokenPrices.
09b9751 to
753930e
Compare
…ID as a UUID TestSDKFieldsFormatted requires uuid.UUID fields to carry format:"uuid".
Adds the store queries for organization AI model prices in `ai_model_configs`, with authorization. They cover basic CRUD on one price, keyed by `(organization_id, provider_id, model)`. - `GetOrganizationAIProviderModelPrice` reads one price. - `UpsertOrganizationAIProviderModelPrice` sets one price, with typed params. It rewrites an existing row only when a price differs, so `updated_at` records the last change. - `DeleteOrganizationAIProviderModelPrice` soft deletes one price. Reads and upserts only match live rows, so setting a price after a delete inserts a new live row. All three authorize against `ResourceAiModelPrice.InOrg(org)`. The new `AiModelPriceInOrg` case in `TestRolePermissions` pins that only owners and org admins pass. A TODO in dbauthz notes that this should become a resource for AI Governance model config. Each query has its own test. The upsert tests cover that identical prices leave `updated_at` unchanged, that changed prices advance it, and that an empty model is rejected. **Used later:** #30719 seeds its lookup tests with the upsert. #30720 serves all three through the org price API. --- *This PR was generated by Coder Agents on behalf of @SasSwart.*
Prices token usage by the most specific match: the organization's price for the configured provider, then a site-wide custom price, then the price book. The requested model is still preferred over the model the provider reports. - `GetAIModelPriceForProvider` replaces `GetAIModelPriceByProviderModel`, which is removed. It is one `UNION ALL` of primary-key lookups, ordered by requested model first, then by specificity. dbauthz checks `ResourceAiModelPrice`, scoped to the org when one is given. - `coderd/aibridge/prices` tests read seeded prices through `GetAIModelPrices`. Interceptions don't carry an organization yet, so `resolveTokenUsageCost` passes none and only site-wide prices apply at runtime for now (AIGOV-716). Org matching is covered by database tests with explicit org IDs. For the same reason, the unpriced-models report still counts only site-wide prices. **Used later:** prices set through the API in #30720 take effect here once interceptions carry an organization. --- *This PR was generated by Coder Agents on behalf of @SasSwart.*
|
Closing at the author's request. This comment was generated by Coder Agents. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.