mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 16:28:31 +00:00
* feat: retire AI provider flag and add rollout audit * test: remove obsolete AI provider flag setup and docs * chore: clean up AI provider configuration and tests * feat: deprecate legacy AI provider environment configuration * docs: explain AI provider migration sizing and timing * docs: mark AI provider migration audit for removal * docs: explain AI provider migration audit usage * fix: log AI provider env deprecations after logging setup log_ai_provider_env_deprecations() ran at the tail of _setup_health_checks(), which ready() calls before setup_logging(). The notice went out through loguru's default sink and missed BASEROW_BACKEND_LOG_LEVEL, the Baserow format, and the OpenTelemetry log exporter, so operators shipping logs to a collector never saw it. Also drop two references the flag removal invalidated: the getEffectiveAIAgentModels JSDoc still described filtering as conditional on the removed provider flag, and the AI field architecture doc still pointed provider authors at the deleted legacy workspace-setting hook. That doc now names BuiltInGenerativeAIModelType, which is what grants an integration override model inheritance. * fix: reuse environment AI settings in generation workers * feat: import legacy AI provider settings on upgrade Removing the ai-providers flag makes database-backed providers the default, which would leave every existing installation on an empty AI providers page with a management command as the only way to populate it. A data migration imports the environment and each workspace's stored settings instead, so a standard upgrade needs no commands. Both scopes are imported in one migration. Legacy workspace settings replaced the instance ones entirely, while database providers inherit, so each imported workspace is also switched off the instance provider of the same type. Without that a workspace would silently gain models billed to the instance account. Settings that cannot fit their columns are skipped and logged rather than raising DataError and rolling back the whole upgrade. The migration reverses as a no-op because the previous version does not read these tables, so deleting rows would only discard edits made during a rollback window. migrate_ai_provider_settings stays as the recovery path and now shares its planning logic with the migration, so both agree on which legacy settings are complete. It deliberately does not switch workspaces off inherited providers, and warns instead. * chore: remove the temporary AI provider audit command audit_ai_provider_settings existed to inventory legacy configuration before a manual import. The upgrade now imports automatically, so the command has no remaining step to support. Removal was already tracked in #5749. * docs: reduce AI provider docs to lasting behaviour The upgrade procedure, rehearsal plan and sizing query described a one-time transition and do not help anyone after the release; they live in the pull request instead. What remains explains how providers work: the two scopes, how they combine, the inheritance switch, what the deprecated environment variables still do, and how integration overrides and published applications behave. Also corrects claims that no longer hold: published applications keep materialised credentials only when they were published before the upgrade, the import is no longer optional, and a workspace-owned provider suppresses the environment fallback too. * docs: shorten the AI provider changelog entries Bullet points render as single list items under the entry. The released entries average around twenty characters; these ran to four hundred, so the detail belongs in the AI providers guide rather than the changelog. * docs: clarify where imported AI credentials are stored The previous wording implied Baserow's own exports carry provider credentials. They do not: AIIntegrationType lists ai_settings as a sensitive field and ImportExportConfig excludes those by default, and AIProviderConfig is not part of any export path. * docs: explain the AI provider upgrade and where to configure providers State that the upgrade imports the BASEROW_* provider variables once and no longer reads them, list the exceptions, and give the exact navigation for instance admins (Admin tools -> AI providers) and workspace admins (workspace Settings -> AI providers). Map each deprecated variable to the field that replaces it. * fix: renumber the legacy AI provider import after 0121_agent Develop's core 0121_agent and this branch's import migration both depended on 0120, leaving two leaf nodes, so migrate refused to run and the startup check and E2E shards failed. The import is now 0122 and depends on 0121_agent. * feat: remove the legacy workspace generative AI settings endpoint GET/PATCH /api/workspaces/{id}/settings/generative-ai/ had no caller left, yet a PATCH was still honoured for any provider type without a workspace provider and never shown in the AI providers UI. Remove it with the handler parameter, receivers and frontend handler that only it could trigger. * fix: stop instance AI provider changes from fanning out per workspace An instance-level change queued one Celery task per 25 workspaces behind a global blocking lock, sent a payload to every connected user, and made the premium receiver serialize every AI field on the instance. Instance changes now notify staff only; other users see them after a reload. The render lock is per scope, and the in-use guards no longer read one row per workspace. * fix: keep inherited Kuma when a workspace switches off the instance provider The upgrade switches imported workspaces off the same-type instance provider, which made an inherited instance Kuma model invalid there, so Kuma fell back to the deprecated env model or turned off. Inheriting the instance Kuma selection now ignores workspace switch-offs; explicit workspace selections stay strict and are the only ones that block a switch-off. * fix: skip malformed Ollama URLs during AI provider migration * fix: preserve skipped legacy AI provider connections * test: cover independent legacy AI workspace connections * fix: skip malformed legacy AI provider settings * fix: move legacy AI import after current core migrations The linear rebase omitted the migration renumbering from the previous merge commit, while develop advanced through core 0124. Rename the existing AI import to 0125, depend on 0124, and update its historical migration test so core has a single leaf.
403 lines
12 KiB
JavaScript
403 lines
12 KiB
JavaScript
import aiProviderService from '@baserow/modules/core/services/aiProvider'
|
|
|
|
export const state = () => ({
|
|
providers: [],
|
|
providerTypes: [],
|
|
featureSettings: [],
|
|
workspaceId: null,
|
|
loading: false,
|
|
loaded: false,
|
|
requestGeneration: 0,
|
|
providersRevision: 0,
|
|
featureSettingsRevision: 0,
|
|
})
|
|
|
|
export const mutations = {
|
|
SET_PROVIDERS(state, providers) {
|
|
state.providers = providers
|
|
},
|
|
SET_PROVIDER_TYPES(state, providerTypes) {
|
|
state.providerTypes = providerTypes
|
|
},
|
|
SET_FEATURE_SETTINGS(state, featureSettings) {
|
|
state.featureSettings = featureSettings
|
|
},
|
|
SET_WORKSPACE_ID(state, workspaceId) {
|
|
state.workspaceId = workspaceId
|
|
},
|
|
SET_LOADING(state, loading) {
|
|
state.loading = loading
|
|
},
|
|
SET_LOADED(state, loaded) {
|
|
state.loaded = loaded
|
|
},
|
|
SET_REQUEST_GENERATION(state, generation) {
|
|
state.requestGeneration = generation
|
|
},
|
|
BUMP_PROVIDERS_REVISION(state) {
|
|
state.providersRevision += 1
|
|
},
|
|
BUMP_FEATURE_SETTINGS_REVISION(state) {
|
|
state.featureSettingsRevision += 1
|
|
},
|
|
ADD_PROVIDER(state, provider) {
|
|
const index = state.providers.findIndex((item) => item.id === provider.id)
|
|
if (index === -1) {
|
|
state.providers.push(provider)
|
|
} else {
|
|
state.providers.splice(index, 1, provider)
|
|
}
|
|
},
|
|
UPDATE_PROVIDER(state, provider) {
|
|
const index = state.providers.findIndex((item) => item.id === provider.id)
|
|
if (index !== -1) state.providers.splice(index, 1, provider)
|
|
},
|
|
DELETE_PROVIDER(state, providerId) {
|
|
state.providers = state.providers.filter((item) => item.id !== providerId)
|
|
},
|
|
ADD_MODEL(state, { providerId, model }) {
|
|
const provider = state.providers.find((item) => item.id === providerId)
|
|
if (provider) {
|
|
const index = provider.models.findIndex((item) => item.id === model.id)
|
|
if (index === -1) {
|
|
provider.models.push(model)
|
|
} else {
|
|
provider.models.splice(index, 1, model)
|
|
}
|
|
}
|
|
},
|
|
UPDATE_MODEL(state, model) {
|
|
for (const provider of state.providers) {
|
|
const index = provider.models.findIndex((item) => item.id === model.id)
|
|
if (index !== -1) {
|
|
provider.models.splice(index, 1, model)
|
|
return
|
|
}
|
|
}
|
|
},
|
|
UPDATE_MODEL_TEST_RESULTS(state, results) {
|
|
const resultsById = new Map(
|
|
results.map((result) => [result.model_id, result])
|
|
)
|
|
for (const provider of state.providers) {
|
|
for (const model of provider.models) {
|
|
const result = resultsById.get(model.id)
|
|
if (result) {
|
|
model.last_test_at = result.tested_at
|
|
model.last_test_status = result.status
|
|
model.last_test_error = result.error
|
|
model.last_test_feature_results = result.feature_results
|
|
}
|
|
}
|
|
}
|
|
},
|
|
DELETE_MODEL(state, modelId) {
|
|
for (const provider of state.providers) {
|
|
provider.models = provider.models.filter((item) => item.id !== modelId)
|
|
}
|
|
},
|
|
UPDATE_FEATURE_SETTING(state, featureSetting) {
|
|
const index = state.featureSettings.findIndex(
|
|
(setting) => setting.feature_type === featureSetting.feature_type
|
|
)
|
|
if (index === -1) state.featureSettings.push(featureSetting)
|
|
else state.featureSettings.splice(index, 1, featureSetting)
|
|
},
|
|
}
|
|
|
|
const commitIfScopeIsCurrent = (
|
|
state,
|
|
workspaceId,
|
|
commit,
|
|
mutation,
|
|
payload,
|
|
revisionMutation = null
|
|
) => {
|
|
if (state.workspaceId === workspaceId) {
|
|
if (revisionMutation !== null) {
|
|
commit(revisionMutation)
|
|
}
|
|
commit(mutation, payload)
|
|
}
|
|
}
|
|
|
|
export const actions = {
|
|
async fetchInitial(
|
|
{ commit, state },
|
|
{ workspaceId = null, realtimeRecovery = false } = {}
|
|
) {
|
|
// Claim the scope before awaiting; a refresh must not reload the old one.
|
|
if (state.workspaceId !== workspaceId) {
|
|
commit('SET_WORKSPACE_ID', workspaceId)
|
|
commit('SET_PROVIDERS', [])
|
|
commit('SET_PROVIDER_TYPES', [])
|
|
commit('SET_FEATURE_SETTINGS', [])
|
|
commit('SET_LOADED', false)
|
|
}
|
|
const requestGeneration = state.requestGeneration + 1
|
|
commit('SET_REQUEST_GENERATION', requestGeneration)
|
|
const providersRevision = state.providersRevision
|
|
const featureSettingsRevision = state.featureSettingsRevision
|
|
commit('SET_LOADING', true)
|
|
try {
|
|
const service = aiProviderService(this.$client, workspaceId)
|
|
const [providers, providerTypes, featureSettings] = await Promise.all([
|
|
service.fetchAll(realtimeRecovery),
|
|
service.fetchTypes(),
|
|
service.fetchFeatureSettings(realtimeRecovery),
|
|
])
|
|
// A newer scope may have been claimed while this request was in flight.
|
|
if (
|
|
state.workspaceId !== workspaceId ||
|
|
state.requestGeneration !== requestGeneration
|
|
) {
|
|
return
|
|
}
|
|
if (state.providersRevision === providersRevision) {
|
|
commit('SET_PROVIDERS', providers.data)
|
|
}
|
|
if (state.featureSettingsRevision === featureSettingsRevision) {
|
|
commit('SET_FEATURE_SETTINGS', featureSettings.data)
|
|
}
|
|
commit('SET_PROVIDER_TYPES', providerTypes.data)
|
|
commit('SET_LOADED', true)
|
|
} finally {
|
|
if (
|
|
state.workspaceId === workspaceId &&
|
|
state.requestGeneration === requestGeneration
|
|
) {
|
|
commit('SET_LOADING', false)
|
|
}
|
|
}
|
|
},
|
|
async refresh({ commit, state }) {
|
|
if (!state.loaded) {
|
|
return []
|
|
}
|
|
const workspaceId = state.workspaceId
|
|
const requestGeneration = state.requestGeneration + 1
|
|
commit('SET_REQUEST_GENERATION', requestGeneration)
|
|
const providersRevision = state.providersRevision
|
|
const featureSettingsRevision = state.featureSettingsRevision
|
|
const service = aiProviderService(this.$client, workspaceId)
|
|
const [providers, featureSettings] = await Promise.all([
|
|
service.fetchAll(),
|
|
service.fetchFeatureSettings(),
|
|
])
|
|
if (
|
|
state.workspaceId !== workspaceId ||
|
|
state.requestGeneration !== requestGeneration
|
|
) {
|
|
return []
|
|
}
|
|
const providersAreCurrent = state.providersRevision === providersRevision
|
|
if (providersAreCurrent) {
|
|
commit('SET_PROVIDERS', providers.data)
|
|
}
|
|
if (state.featureSettingsRevision === featureSettingsRevision) {
|
|
commit('SET_FEATURE_SETTINGS', featureSettings.data)
|
|
}
|
|
return providersAreCurrent ? providers.data : []
|
|
},
|
|
replaceFromRealtime(
|
|
{ commit, state },
|
|
{ workspaceId, providers, featureSettings }
|
|
) {
|
|
if (state.workspaceId === workspaceId) {
|
|
if (providers !== undefined) {
|
|
commit('BUMP_PROVIDERS_REVISION')
|
|
commit('SET_PROVIDERS', providers)
|
|
}
|
|
if (featureSettings !== undefined) {
|
|
commit('BUMP_FEATURE_SETTINGS_REVISION')
|
|
commit('SET_FEATURE_SETTINGS', featureSettings)
|
|
}
|
|
}
|
|
},
|
|
async create({ commit, state }, payload) {
|
|
const workspaceId = payload.workspaceId ?? null
|
|
const values = workspaceId === null ? payload : payload.values
|
|
const { data } = await aiProviderService(this.$client, workspaceId).create(
|
|
values
|
|
)
|
|
commitIfScopeIsCurrent(
|
|
state,
|
|
workspaceId,
|
|
commit,
|
|
'ADD_PROVIDER',
|
|
data,
|
|
'BUMP_PROVIDERS_REVISION'
|
|
)
|
|
return data
|
|
},
|
|
async update({ commit, state }, { providerId, values, workspaceId = null }) {
|
|
const { data } = await aiProviderService(this.$client, workspaceId).update(
|
|
providerId,
|
|
values
|
|
)
|
|
commitIfScopeIsCurrent(
|
|
state,
|
|
workspaceId,
|
|
commit,
|
|
'UPDATE_PROVIDER',
|
|
data,
|
|
'BUMP_PROVIDERS_REVISION'
|
|
)
|
|
return data
|
|
},
|
|
async delete({ commit, state }, payload) {
|
|
const providerId =
|
|
typeof payload === 'object' ? payload.providerId : payload
|
|
const workspaceId =
|
|
typeof payload === 'object' ? (payload.workspaceId ?? null) : null
|
|
await aiProviderService(this.$client, workspaceId).delete(providerId)
|
|
commitIfScopeIsCurrent(
|
|
state,
|
|
workspaceId,
|
|
commit,
|
|
'DELETE_PROVIDER',
|
|
providerId,
|
|
'BUMP_PROVIDERS_REVISION'
|
|
)
|
|
},
|
|
async createModel(
|
|
{ commit, state },
|
|
{ providerId, values, workspaceId = null }
|
|
) {
|
|
const { data } = await aiProviderService(
|
|
this.$client,
|
|
workspaceId
|
|
).createModel(providerId, values)
|
|
commitIfScopeIsCurrent(
|
|
state,
|
|
workspaceId,
|
|
commit,
|
|
'ADD_MODEL',
|
|
{
|
|
providerId,
|
|
model: data,
|
|
},
|
|
'BUMP_PROVIDERS_REVISION'
|
|
)
|
|
return data
|
|
},
|
|
async discoverModels(_context, payload) {
|
|
const providerType =
|
|
typeof payload === 'object' ? payload.providerType : payload
|
|
const workspaceId =
|
|
typeof payload === 'object' ? (payload.workspaceId ?? null) : null
|
|
const { data } = await aiProviderService(
|
|
this.$client,
|
|
workspaceId
|
|
).discoverModels(providerType)
|
|
return data
|
|
},
|
|
async updateModel(
|
|
{ commit, state },
|
|
{ modelId, values, workspaceId = null }
|
|
) {
|
|
const { data } = await aiProviderService(
|
|
this.$client,
|
|
workspaceId
|
|
).updateModel(modelId, values)
|
|
commitIfScopeIsCurrent(
|
|
state,
|
|
workspaceId,
|
|
commit,
|
|
'UPDATE_MODEL',
|
|
data,
|
|
'BUMP_PROVIDERS_REVISION'
|
|
)
|
|
return data
|
|
},
|
|
async deleteModel({ commit, state }, payload) {
|
|
const modelId = typeof payload === 'object' ? payload.modelId : payload
|
|
const workspaceId =
|
|
typeof payload === 'object' ? (payload.workspaceId ?? null) : null
|
|
await aiProviderService(this.$client, workspaceId).deleteModel(modelId)
|
|
commitIfScopeIsCurrent(
|
|
state,
|
|
workspaceId,
|
|
commit,
|
|
'DELETE_MODEL',
|
|
modelId,
|
|
'BUMP_PROVIDERS_REVISION'
|
|
)
|
|
},
|
|
async fetchModelUsage(_context, payload) {
|
|
const modelId = typeof payload === 'object' ? payload.modelId : payload
|
|
const workspaceId =
|
|
typeof payload === 'object' ? (payload.workspaceId ?? null) : null
|
|
const { data } = await aiProviderService(
|
|
this.$client,
|
|
workspaceId
|
|
).fetchModelUsage(modelId)
|
|
return {
|
|
usage: data.usage.map(({ feature_type: featureType, count }) => ({
|
|
featureType,
|
|
count,
|
|
})),
|
|
}
|
|
},
|
|
async testModels({ commit, state }, payload) {
|
|
const workspaceId = payload.workspaceId ?? null
|
|
const values = workspaceId === null ? payload : payload.values
|
|
const { data } = await aiProviderService(
|
|
this.$client,
|
|
workspaceId
|
|
).testModels(values)
|
|
commitIfScopeIsCurrent(
|
|
state,
|
|
workspaceId,
|
|
commit,
|
|
'UPDATE_MODEL_TEST_RESULTS',
|
|
data.results,
|
|
'BUMP_PROVIDERS_REVISION'
|
|
)
|
|
return data.results
|
|
},
|
|
async updateFeatureSetting(
|
|
{ commit, dispatch, state },
|
|
{ featureType, values, workspaceId = null }
|
|
) {
|
|
const { data } = await aiProviderService(
|
|
this.$client,
|
|
workspaceId
|
|
).updateFeatureSetting(featureType, values)
|
|
commitIfScopeIsCurrent(
|
|
state,
|
|
workspaceId,
|
|
commit,
|
|
'UPDATE_FEATURE_SETTING',
|
|
data,
|
|
'BUMP_FEATURE_SETTINGS_REVISION'
|
|
)
|
|
// Availability also reflects inheritance and legacy fallbacks the response omits.
|
|
try {
|
|
await dispatch('workspace/refreshAllGenerativeAIModels', null, {
|
|
root: true,
|
|
})
|
|
} catch {
|
|
// Saving succeeded, so an interrupted refresh must not report a failure.
|
|
}
|
|
return data
|
|
},
|
|
}
|
|
|
|
export const getters = {
|
|
// One scope at a time: reads name the scope they expect.
|
|
getAll: (state) => (workspaceId) =>
|
|
state.workspaceId === workspaceId ? state.providers : [],
|
|
getTypes: (state) => (workspaceId) =>
|
|
state.workspaceId === workspaceId ? state.providerTypes : [],
|
|
getFeatureSettings: (state) => (workspaceId) =>
|
|
state.workspaceId === workspaceId ? state.featureSettings : [],
|
|
isLoading: (state) => state.loading,
|
|
hasLoaded: (state) => state.loaded,
|
|
getWorkspaceId: (state) => state.workspaceId,
|
|
isLoaded: (state) => (workspaceId) =>
|
|
state.loaded && state.workspaceId === workspaceId,
|
|
}
|
|
|
|
export default { namespaced: true, state, mutations, actions, getters }
|