mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* feat: report AI provider model usage per feature type Feature types now count the rows they store referencing a provider model, so the admin can be warned before disabling, deleting or narrowing one instead of being blocked. Counting is by provider type and model identifier because consumers do not store the provider row id, which makes the result an upper bound: fit to warn, never to block. Default-model features are excluded, their RESTRICT foreign key already blocks the change. * feat: count AI field and AI Agent references to a provider model Both features store a provider type and model identifier per row rather than a reference to the model, so nothing told an administrator what a model change would break. They now count their own rows, skipping every consumer whose owner is trashed: a field's table, database or workspace, and an agent service's automation node, builder workflow action, integration or application. * feat: expose AI provider model usage over the API GET /ai-providers/models/<id>/usage/ reports the per-consumer counts to warn about and, separately, the default-model features that refuse the change outright. Kuma holds a restricted foreign key, so naming it up front lets the client say which selection to repoint instead of letting the admin discover it through a generic error. Permissions and scoping mirror the sibling model endpoints, so a workspace-scoped caller cannot read an instance model's usage. * feat: warn before an AI model change breaks its consumers Disabling, deleting, renaming or narrowing a model now names what depends on it and proceeds on confirmation. Disabling was entirely unguarded before, and a rename orphans consumers just as thoroughly as a delete because they persist the identifier string. The counts are an upper bound: an instance model and a workspace model sharing an identifier are indistinguishable to a consumer, so the copy says a feature uses the model rather than claiming it will break. A failed lookup degrades to the plain confirmation instead of trapping the administrator. * fix: keep an unavailable AI model visible in the AI field form The form dropped a saved provider or model as soon as it stopped being available, leaving empty dropdowns that hid what the field had been configured with. It now retains the saved selection, disabled and marked unavailable, the way the AI Agent node form already does, while the validator keeps reading the genuine list so the field cannot be saved until a real model is picked. * docs: describe the AI provider model usage warning * refactor: drop redundant blocking feature types from model usage The usage endpoint pre-announced the features whose selection refuses a change, but ERROR_AI_PROVIDER_MODEL_IN_USE already names them and the frontend already renders that detail. Worse, the modal applied the list only on rename, the one path that is never refused: Kuma holds a foreign key to the model row, so the selection follows the rename instead of breaking. The same claim was in the installation docs; both are corrected to say what actually happens. Also drop the `trashed=False` filters from both model reference counts. AIAgentService.objects and AIField.objects are no-trash managers, so the generated SQL already excludes trashed rows. Rename the endpoint's operation id to get_ai_provider_model_usage: the documented response is an object, not a list. * fix: address Qodo review of the model usage warning Count a service only while a live owner still reaches it. The previous exclusion dropped the whole service as soon as any related builder action was trashed, so a service shared by a live and a trashed action vanished from the warning. Both owner managers already encode which ancestors count as trashed, so the check reuses them through EXISTS instead of restating the rules. Treat a failed usage lookup as unknown rather than zero. Returning empty counts made every caller skip its confirmation, letting a rename orphan consumers with no warning at all; the dialog now says the check failed and still lets the admin proceed. Cover fetchModelUsage directly: payload forms, workspace scoping and the snake_case to camelCase mapping had no store test.
46 lines
1.5 KiB
JavaScript
46 lines
1.5 KiB
JavaScript
import { aiProviderModelUsageMessage } from '@baserow/modules/core/utils/aiProvider'
|
|
|
|
/**
|
|
* Shared model-usage lookup and copy for the surfaces that disable, delete or
|
|
* narrow an AI provider model.
|
|
*/
|
|
export default {
|
|
methods: {
|
|
/**
|
|
* @param {number} modelId The provider model to count consumers for.
|
|
* @param {number|null} workspaceId The workspace scope, null for instance.
|
|
* @returns {Promise<{usage: Array<{featureType: string, count: number}>,
|
|
* failed: boolean}>} The counts to warn about, and whether the lookup
|
|
* itself failed.
|
|
*/
|
|
async lookupModelUsage(modelId, workspaceId = null) {
|
|
try {
|
|
const result = await this.$store.dispatch(
|
|
'aiProvider/fetchModelUsage',
|
|
{
|
|
modelId,
|
|
...(workspaceId === null ? {} : { workspaceId }),
|
|
}
|
|
)
|
|
return { ...result, failed: false }
|
|
} catch {
|
|
// An unchecked model is not a safe model: confirm instead of assuming zero.
|
|
return { usage: [], failed: true }
|
|
}
|
|
},
|
|
/** @returns {boolean} Whether the model may still have dependents. */
|
|
modelHasDependents(result) {
|
|
return result.failed || result.usage.some((entry) => entry.count > 0)
|
|
},
|
|
/** @returns {string} The description, prefixed with what depends on the model. */
|
|
modelUsageMessage(result, description) {
|
|
return aiProviderModelUsageMessage(
|
|
result,
|
|
description,
|
|
this.$t.bind(this),
|
|
this.$registry
|
|
)
|
|
},
|
|
},
|
|
}
|