The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Cleanup Metabot tools feature sentinels (#72113)
lbrdnke392e85ab4ca
diff --git a/enterprise/backend/src/metabase_enterprise/metabot/tools/transforms.clj b/enterprise/backend/src/metabase_enterprise/metabot/tools/transforms.cljindex 9841b37c42a..5d9853aa5d9 100644--- a/enterprise/backend/src/metabase_enterprise/metabot/tools/transforms.clj+++ b/enterprise/backend/src/metabase_enterprise/metabot/tools/transforms.clj@@ -25,7 +25,7 @@(defenterprise-schema get-transform-python-library-details-tool"Get information about a Python library by path."- :feature :none+ :feature :transforms-python[{:keys [path]} :- [:map {:closed true} [:path :string]]](tools.transforms/add-output (transforms-write-tools/get-transform-python-library-details {:path path})format-python-library-output))@@ -43,7 +43,7 @@Use `get_transform_python_library_details` before writing any Python code to inspect the shared library.Use the shared library in your code by adding `import common` at the top of the file.Keep `import common` at the top of the file even if it is currently unused."- :feature :none+ :feature :transforms-python[{:keys [transform_id edit_action thinking transform_name transform_descriptiondatabase_id source_tables]}:- tools.transforms/write-transform-python-schema]diff --git a/src/metabase/metabot/agent/profiles.clj b/src/metabase/metabot/agent/profiles.cljindex f6cadc66928..90bd177bcd3 100644--- a/src/metabase/metabot/agent/profiles.clj+++ b/src/metabase/metabot/agent/profiles.clj@@ -173,10 +173,7 @@{"frontend:navigate_user_v1" :frontend-navigate-user-v1"permission:save_questions" :permission-save-questions"permission:write_sql_queries" :permission-write-sql-queries- "permission:write_transforms" :permission-write-transforms- "feature:transforms" :feature-transforms- "feature:transforms-python" :feature-transforms-python- "feature:snippets" :feature-snippets})+ "permission:write_transforms" :permission-write-transforms})(defn- capability->keyword"Normalize a capability value to a keyword. Strings are looked up in the@@ -189,23 +186,16 @@;; gracefully without requiring a map update.(keyword (-> (str cap) (str/replace ":" "-") (str/replace "_" "-"))))))-;; TODO (lbrdnk 2026-03-18): `api-string->capability-keyword` hints there is need for feature snippets. I was unable-;; to find matching logic in ai-service. I'll remove that in followup with related logic.-(comment- (filter #(re-find #"snippet" (name %)) (keys (premium-features/token-features))))- ;;=> (:snippet_collections) <--- very probably we do not want to sentinel on this feature--(def relevant-features- "Metabase features to add to capabilities set."- #{:transforms :transforms-python})--(defn feature-capability-kws- "Get capabilities per features of this Metabase instance. Not cached to avoid staleness."+(defn feature-capabilities+ "Return set of capabilities inferred from BE state, not send from FE. Generated by function to avoid staleness."[](into #{}- (comp (filter premium-features/has-feature?)- (map #(keyword (str "feature-" (name %)))))- relevant-features))+ (remove nil?)+ [(when (or (not (premium-features/is-hosted?))+ (premium-features/has-feature? :transforms-basic))+ :feature-transforms)+ (when (premium-features/has-feature? :transforms-python)+ :feature-transforms-python)]))(defn- filter-by-capabilities"Filter tool vars by user capabilities.@@ -214,7 +204,7 @@while tool metadata uses keywords (e.g. :frontend-navigate-user-v1), so wenormalize to keywords before comparing."[tool-vars capabilities]- (let [capabilities-set (into (feature-capability-kws)+ (let [capabilities-set (into (feature-capabilities)(map capability->keyword)capabilities)](filter (fn [tool-var]@@ -232,13 +222,6 @@(api-scope/scope-matches? scope/*current-user-scope* required-scope))))tool-vars))-(defn- ee-feature-available?- "Check if a tool's :ee-feature is available (or if the tool has no :ee-feature gate)."- [tool-var]- (if-let [feature (:ee-feature (meta tool-var))]- (premium-features/has-feature? feature)- true))-(defn- tool-map"Create a map of tool-name -> tool-var from a sequence of tool vars."[tool-vars]@@ -262,7 +245,6 @@[profile-id capabilities](some-> (get-profile profile-id):tools- (->> (filter ee-feature-available?))(filter-by-capabilities capabilities)filter-by-scopetool-map))diff --git a/src/metabase/metabot/tools/snippets.clj b/src/metabase/metabot/tools/snippets.cljindex b071dd2dc57..f3f6ed7fd86 100644--- a/src/metabase/metabot/tools/snippets.clj+++ b/src/metabase/metabot/tools/snippets.clj@@ -56,8 +56,7 @@result))(mu/defn ^{:tool-name "list_snippets"- :scope scope/agent-snippets-read- :capabilities #{:feature-snippets}}+ :scope scope/agent-snippets-read}list-snippets-tool"List all SQL snippets available in the Metabase instance.@@ -68,8 +67,7 @@(add-output (get-snippets {}) format-snippet-list-output))(mu/defn ^{:tool-name "get_snippet_details"- :scope scope/agent-snippets-read- :capabilities #{:feature-snippets}}+ :scope scope/agent-snippets-read}get-snippet-details-tool"Get the full details of a SQL snippet including its content.diff --git a/src/metabase/metabot/tools/transforms.clj b/src/metabase/metabot/tools/transforms.cljindex 5ca34b6af93..6b17659c1de 100644--- a/src/metabase/metabot/tools/transforms.clj+++ b/src/metabase/metabot/tools/transforms.clj@@ -81,7 +81,8 @@;;; ──────────────────────────────────────────────────────────────────(mu/defn ^{:tool-name "get_transform_details"- :scope scope/agent-transforms-read}+ :scope scope/agent-transforms-read+ :capabilities #{:feature-transforms}}get-transform-details-tool"Get information about a transform."[{:keys [transform_id]} :- [:map {:closed true} [:transform_id :int]]]@@ -97,7 +98,7 @@(defenterprise ^{:tool-name "get_transform_python_library_details":schema [:=> [:cat python-lib-schema] :map]:scope scope/agent-transforms-read- :ee-feature :transforms}+ :capabilities #{:feature-transforms :feature-transforms-python}}get-transform-python-library-details-tool"Get Python library details. EE-only; returns an error in OSS."metabase-enterprise.metabot.tools.transforms@@ -257,8 +258,7 @@(defenterprise ^{:tool-name "write_transform_python":schema [:=> [:cat write-transform-python-schema] :map]:scope scope/agent-transforms-write- :capabilities #{:feature-transforms :feature-transforms-python :permission-write-transforms}- :ee-feature :transforms}+ :capabilities #{:feature-transforms :feature-transforms-python :permission-write-transforms}}write-transform-python-tool"Write Python transforms. EE-only; returns an error in OSS."metabase-enterprise.metabot.tools.transformsdiff --git a/test/metabase/metabot/agent/profiles_test.clj b/test/metabase/metabot/agent/profiles_test.cljindex 8efcb033d3b..83ca749ff30 100644--- a/test/metabase/metabot/agent/profiles_test.clj+++ b/test/metabase/metabot/agent/profiles_test.clj@@ -167,17 +167,42 @@#'tools.transforms/write-transform-python-tool}](testing "Available with features present"(with-redefs [premium-features/has-feature? (fn [feat]- (if (#'profiles/relevant-features feat)+ (if (#{:transforms-basic :transforms-python} feat)true(orig-has-feature feat)))](is (= transform-tools(set (#'profiles/filter-by-capabilities transform-tools["permission:write_transforms"]))))))(testing "Not available with missing features"- (with-redefs [premium-features/has-feature? (fn [feat]- (if (#'profiles/relevant-features feat)+ (with-redefs [premium-features/is-hosted? (constantly true)+ premium-features/has-feature? (fn [feat]+ (if (#{:transforms-basic :transforms-python} feat)false(orig-has-feature feat)))]+ (is (= #{}+ (set (#'profiles/filter-by-capabilities transform-tools+ ["permission:write_transforms"]))))))+ (testing "Sql tool available on self hosted instances"+ (with-redefs [premium-features/is-hosted? (constantly false)+ premium-features/has-feature? (fn [feat]+ (if (#{:transforms-basic :transforms-python} feat)+ false+ (orig-has-feature feat)))]+ (is (= #{#'tools.transforms/write-transform-sql-tool}+ (set (#'profiles/filter-by-capabilities transform-tools+ ["permission:write_transforms"]))))))+ (testing "Python transform tools not available when basic transforms are not available"+ (with-redefs [premium-features/is-hosted? (constantly true)+ premium-features/has-feature? (fn [feat]+ (cond+ (#{:transforms-basic} feat)+ false++ (#{:transforms-python} feat)+ true++ :else+ (orig-has-feature feat)))](is (= #{}(set (#'profiles/filter-by-capabilities transform-tools["permission:write_transforms"]))))))))diff --git a/test/metabase/metabot/tools_test.clj b/test/metabase/metabot/tools_test.cljindex 02242526cf4..8612c99bb91 100644--- a/test/metabase/metabot/tools_test.clj+++ b/test/metabase/metabot/tools_test.clj@@ -35,18 +35,6 @@(let [tool-vars [#'agent-tools/search-tool #'agent-tools/navigate-user-tool #'agent-tools/create-chart-tool]capabilities #{:frontend-navigate-user-v1}result (#'profiles/filter-by-capabilities tool-vars capabilities)]- (is (= tool-vars result))))-- (testing "filters snippet tools by capabilities"- (let [tool-vars [#'agent-tools/list-snippets-tool #'agent-tools/get-snippet-details-tool #'agent-tools/search-tool]- capabilities #{}- result (#'profiles/filter-by-capabilities tool-vars capabilities)]- (is (= ["search"] (mapv #(:tool-name (meta %)) result)))))-- (testing "includes snippet tools when capability present"- (let [tool-vars [#'agent-tools/list-snippets-tool #'agent-tools/get-snippet-details-tool #'agent-tools/search-tool]- capabilities #{:feature-snippets}- result (#'profiles/filter-by-capabilities tool-vars capabilities)](is (= tool-vars result)))))(defn- tools-for-profile