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
Delete agent APIs for Workspaces (#71827)
Chris Trutere54b1d968ca0
diff --git a/.clj-kondo/config/modules/config.edn b/.clj-kondo/config/modules/config.ednindex 0b931435056..65f3e4356bc 100644--- a/.clj-kondo/config/modules/config.edn+++ b/.clj-kondo/config/modules/config.edn@@ -156,7 +156,6 @@agent-api{:team "Metabot":api #{metabase.agent-api.api}- :friends #{enterprise/agent-api}:uses #{apiauth-identitylib@@ -1179,25 +1178,25 @@{:team "Metabot":api #{metabase.metabot.apimetabase.metabot.api.entity-analysis- metabase.metabot.core- metabase.metabot.init- metabase.metabot.self- metabase.metabot.settings}+ metabase.metabot.core+ metabase.metabot.init+ metabase.metabot.self+ metabase.metabot.settings}:friends #{agent-apienterprise/metabotslackbot}- :uses #{activity-feed- analytics- api- api-scope- app-db- audit-app- channel- collections- config- documents- driver- legacy-mbql+ :uses #{activity-feed+ analytics+ api+ api-scope+ app-db+ audit-app+ channel+ collections+ config+ documents+ driver+ legacy-mbqlliblib-bellm@@ -2635,13 +2634,6 @@:model/Sandbox:model/Table}}- enterprise/agent-api- {:team "Metabot"- :api #{metabase-enterprise.agent-api.workspace}- :uses #{api- util- enterprise/workspaces}}-enterprise/analytics{:team "UX West":api #{}@@ -2963,8 +2955,7 @@:api #{metabase-enterprise.metabot.apimetabase-enterprise.metabot.api.routesmetabase-enterprise.metabot.init}- :friends #{enterprise/agent-api- slackbot+ :friends #{slackbotmcpmetabot}:uses #{api@@ -3309,7 +3300,6 @@:api #{metabase-enterprise.workspaces.apimetabase-enterprise.workspaces.init}:model-exports #{:model/Workspace :model/WorkspaceMergeTransform}- :friends #{enterprise/agent-api}:uses #{apiapi-scopeapp-dbdiff --git a/docs/api.json b/docs/api.jsonindex 64d12fe9f9e..24c98b6f7de 100644--- a/docs/api.json+++ b/docs/api.json@@ -15039,1619 +15039,6 @@"tags" : [ "/api/agent" ]}},- "/api/agent/v1/workspace/{ws-id}" : {- "get" : {- "operationId" : "get-api-agent-v1-workspace-ws-id",- "summary" : "GET /api/agent/v1/workspace/{ws-id}",- "description" : "Get a single workspace by ID.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "type" : "integer",- "minimum" : 1- },- "description" : "value must be an integer greater than zero."- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "collection_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "created_at" : {- "type" : "string",- "format" : "date-time"- },- "database_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "name" : {- "type" : "string"- },- "status" : {- "type" : "string",- "enum" : [ "archived", "ready", "broken", "pending", "uninitialized" ]- },- "updated_at" : {- "type" : "string",- "format" : "date-time"- }- },- "required" : [ "id", "name", "collection_id", "database_id", "status", "created_at", "updated_at" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/archive" : {- "post" : {- "operationId" : "post-api-agent-v1-workspace-ws-id-archive",- "summary" : "POST /api/agent/v1/workspace/{ws-id}/archive",- "description" : "Archive a workspace.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "type" : "integer",- "minimum" : 1- },- "description" : "value must be an integer greater than zero."- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "collection_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "created_at" : {- "type" : "string",- "format" : "date-time"- },- "database_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "name" : {- "type" : "string"- },- "status" : {- "type" : "string",- "enum" : [ "archived", "ready", "broken", "pending", "uninitialized" ]- },- "updated_at" : {- "type" : "string",- "format" : "date-time"- }- },- "required" : [ "id", "name", "collection_id", "database_id", "status", "created_at", "updated_at" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/external/transform" : {- "get" : {- "operationId" : "get-api-agent-v1-workspace-ws-id-external-transform",- "summary" : "GET /api/agent/v1/workspace/{ws-id}/external/transform",- "description" : "List external transforms not checked out into this workspace.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- }, {- "in" : "query",- "name" : "database-id",- "required" : false,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "transforms" : {- "type" : "array",- "items" : {- "type" : "object",- "properties" : {- "checkout_disabled" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "name" : {- "type" : "string"- },- "source_type" : {- "type" : "string"- }- },- "required" : [ "id", "name", "source_type", "checkout_disabled" ]- }- }- },- "required" : [ "transforms" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/graph" : {- "get" : {- "operationId" : "get-api-agent-v1-workspace-ws-id-graph",- "summary" : "GET /api/agent/v1/workspace/{ws-id}/graph",- "description" : "Get the dependency graph for a workspace.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "type" : "integer",- "minimum" : 1- },- "description" : "value must be an integer greater than zero."- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "edges" : {- "type" : "array",- "items" : {- "type" : "object",- "properties" : {- "from_entity_id" : {- "anyOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- } ]- },- "from_entity_type" : {- "type" : "string"- },- "to_entity_id" : {- "anyOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- } ]- },- "to_entity_type" : {- "type" : "string"- }- },- "required" : [ "from_entity_id", "from_entity_type", "to_entity_id", "to_entity_type" ]- }- },- "nodes" : {- "type" : "array",- "items" : {- "type" : "object",- "properties" : {- "data" : {- "type" : "object",- "properties" : { }- },- "dependents_count" : {- "type" : "object",- "additionalProperties" : {- "description" : "value must be an integer greater than zero.",- "type" : "integer",- "minimum" : 1- }- },- "id" : {- "anyOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- } ]- },- "type" : {- "type" : "string",- "enum" : [ "input-table", "external-transform", "workspace-transform" ]- }- },- "required" : [ "id", "type", "dependents_count", "data" ]- }- }- },- "required" : [ "nodes", "edges" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/input/pending" : {- "get" : {- "operationId" : "get-api-agent-v1-workspace-ws-id-input-pending",- "summary" : "GET /api/agent/v1/workspace/{ws-id}/input/pending",- "description" : "List pending input grants.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "inputs" : {- "type" : "array",- "items" : {- "type" : "object",- "properties" : {- "db_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "schema" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "table" : {- "type" : "string"- }- },- "required" : [ "db_id", "schema", "table" ]- }- }- },- "required" : [ "inputs" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/log" : {- "get" : {- "operationId" : "get-api-agent-v1-workspace-ws-id-log",- "summary" : "GET /api/agent/v1/workspace/{ws-id}/log",- "description" : "Get workspace creation status and recent log entries.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "type" : "integer",- "minimum" : 1- },- "description" : "value must be an integer greater than zero."- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "last_completed_at" : {- "oneOf" : [ { }, {- "type" : "null"- } ]- },- "logs" : {- "type" : "array",- "items" : {- "type" : "object",- "properties" : {- "completed_at" : {- "oneOf" : [ { }, {- "type" : "null"- } ]- },- "description" : { },- "id" : {- "description" : "value must be an integer greater than zero.",- "type" : "integer",- "minimum" : 1- },- "message" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "started_at" : { },- "status" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "task" : {- "type" : "string"- },- "updated_at" : { }- },- "required" : [ "id", "task", "description", "started_at", "updated_at", "completed_at", "status", "message" ]- }- },- "status" : {- "type" : "string",- "enum" : [ "archived", "ready", "broken", "pending", "uninitialized" ]- },- "updated_at" : { },- "workspace_id" : {- "description" : "value must be an integer greater than zero.",- "type" : "integer",- "minimum" : 1- }- },- "required" : [ "workspace_id", "status", "updated_at", "last_completed_at", "logs" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/problem" : {- "get" : {- "operationId" : "get-api-agent-v1-workspace-ws-id-problem",- "summary" : "GET /api/agent/v1/workspace/{ws-id}/problem",- "description" : "Detect problems in the workspace.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "type" : "integer",- "minimum" : 1- },- "description" : "value must be an integer greater than zero."- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "array",- "items" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.problem"- }- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/query" : {- "post" : {- "operationId" : "post-api-agent-v1-workspace-ws-id-query",- "summary" : "POST /api/agent/v1/workspace/{ws-id}/query",- "description" : "Execute a SQL query in the workspace's isolated database context.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.query-result"- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "requestBody" : {- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "sql" : {- "type" : "string",- "minLength" : 1- }- },- "required" : [ "sql" ]- }- }- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/run" : {- "post" : {- "operationId" : "post-api-agent-v1-workspace-ws-id-run",- "summary" : "POST /api/agent/v1/workspace/{ws-id}/run",- "description" : "Execute all transforms in the workspace in dependency order.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "failed" : {- "type" : "array",- "items" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }- },- "not_run" : {- "type" : "array",- "items" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }- },- "succeeded" : {- "type" : "array",- "items" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }- }- },- "required" : [ "succeeded", "failed", "not_run" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "requestBody" : {- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "stale_only" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.flag"- }- }- }- }- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/table" : {- "get" : {- "operationId" : "get-api-agent-v1-workspace-ws-id-table",- "summary" : "GET /api/agent/v1/workspace/{ws-id}/table",- "description" : "Get workspace input and output tables.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "type" : "integer",- "minimum" : 1- },- "description" : "value must be an integer greater than zero."- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "inputs" : {- "type" : "array",- "items" : {- "type" : "object",- "properties" : {- "db_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "schema" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "table" : {- "type" : "string"- },- "table_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- }- },- "required" : [ "db_id", "schema", "table", "table_id" ]- }- },- "outputs" : {- "type" : "array",- "items" : {- "type" : "object",- "properties" : {- "db_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "global" : {- "type" : "object",- "properties" : {- "schema" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "table" : {- "type" : "string"- },- "table_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- },- "transform_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- }- },- "required" : [ "transform_id", "schema", "table", "table_id" ]- },- "isolated" : {- "type" : "object",- "properties" : {- "schema" : {- "type" : "string"- },- "table" : {- "type" : "string"- },- "table_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- },- "transform_id" : {- "anyOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }, {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- } ]- }- },- "required" : [ "transform_id", "schema", "table", "table_id" ]- }- },- "required" : [ "db_id", "global", "isolated" ]- }- }- },- "required" : [ "inputs", "outputs" ],- "additionalProperties" : false- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/transform" : {- "get" : {- "operationId" : "get-api-agent-v1-workspace-ws-id-transform",- "summary" : "GET /api/agent/v1/workspace/{ws-id}/transform",- "description" : "List all transforms in a workspace.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "transforms" : {- "type" : "array",- "items" : {- "type" : "object",- "properties" : {- "creator_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- },- "global_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- },- "name" : {- "type" : "string"- },- "ref_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- },- "source_type" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- }- },- "required" : [ "ref_id", "global_id", "name", "source_type", "creator_id" ],- "additionalProperties" : false- }- }- },- "required" : [ "transforms" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- },- "post" : {- "operationId" : "post-api-agent-v1-workspace-ws-id-transform",- "summary" : "POST /api/agent/v1/workspace/{ws-id}/transform",- "description" : "Create a new transform in the workspace.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "last_run_at" : { },- "target_stale" : {- "oneOf" : [ {- "type" : "boolean"- }, {- "type" : "null"- } ]- },- "name" : {- "type" : "string"- },- "last_run_status" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "workspace_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "updated_at" : { },- "archived_at" : { },- "source" : {- "type" : "object",- "properties" : { }- },- "last_run_message" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "target" : {- "type" : "object",- "properties" : { }- },- "created_at" : { },- "global_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- },- "creator_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- },- "ref_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- },- "description" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- }- },- "required" : [ "ref_id", "global_id", "name", "description", "source", "target", "target_stale", "workspace_id", "creator_id", "archived_at", "created_at", "updated_at", "last_run_at", "last_run_status", "last_run_message" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "requestBody" : {- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "description" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "name" : {- "type" : "string"- },- "source" : {- "oneOf" : [ {- "type" : "object",- "properties" : {- "query" : {- "$ref" : "#/components/schemas/metabase.queries.schema.query"- },- "type" : {- "const" : "query"- }- },- "required" : [ "type", "query" ]- }, {- "type" : "object",- "properties" : {- "body" : {- "type" : "string"- },- "source-database" : {- "type" : "integer"- },- "source-tables" : {- "type" : "array",- "items" : {- "$ref" : "#/components/schemas/metabase.transforms-base.util.source-table-entry"- }- },- "type" : {- "const" : "python"- }- },- "required" : [ "source-tables", "type", "body" ],- "additionalProperties" : false- } ]- },- "target" : {- "type" : "object",- "properties" : {- "database" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "name" : {- "type" : "string",- "minLength" : 1- },- "schema" : {- "oneOf" : [ {- "type" : "string",- "minLength" : 1- }, {- "type" : "null"- } ]- },- "type" : {- "type" : "string",- "enum" : [ "table" ]- }- },- "required" : [ "type", "name" ],- "additionalProperties" : false- }- },- "required" : [ "name", "source", "target" ]- }- }- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/transform/validate/target" : {- "post" : {- "operationId" : "post-api-agent-v1-workspace-ws-id-transform-validate-target",- "summary" : "POST /api/agent/v1/workspace/{ws-id}/transform/validate/target",- "description" : "Validate the target table for a workspace transform.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- }, {- "in" : "query",- "name" : "transform-id",- "required" : false,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "body" : {- "anyOf" : [ {- "type" : "string"- }, {- "anyOf" : [ { }, { } ]- } ]- },- "status" : {- "type" : "integer"- }- },- "required" : [ "status", "body" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "requestBody" : {- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "db_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "target" : {- "type" : "object",- "properties" : {- "database" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "name" : {- "type" : "string"- },- "schema" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "type" : {- "type" : "string"- }- },- "required" : [ "type", "schema", "name" ]- }- },- "required" : [ "target" ]- }- }- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/transform/{tx-id}" : {- "get" : {- "operationId" : "get-api-agent-v1-workspace-ws-id-transform-tx-id",- "summary" : "GET /api/agent/v1/workspace/{ws-id}/transform/{tx-id}",- "description" : "Get a specific transform in a workspace.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- }, {- "in" : "path",- "name" : "tx-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "last_run_at" : { },- "target_stale" : {- "oneOf" : [ {- "type" : "boolean"- }, {- "type" : "null"- } ]- },- "name" : {- "type" : "string"- },- "last_run_status" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "workspace_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "updated_at" : { },- "archived_at" : { },- "source" : {- "type" : "object",- "properties" : { }- },- "last_run_message" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "target" : {- "type" : "object",- "properties" : { }- },- "created_at" : { },- "global_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- },- "creator_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- },- "ref_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- },- "description" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- }- },- "required" : [ "ref_id", "global_id", "name", "description", "source", "target", "target_stale", "workspace_id", "creator_id", "archived_at", "created_at", "updated_at", "last_run_at", "last_run_status", "last_run_message" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- },- "put" : {- "operationId" : "put-api-agent-v1-workspace-ws-id-transform-tx-id",- "summary" : "PUT /api/agent/v1/workspace/{ws-id}/transform/{tx-id}",- "description" : "Update or create a transform in a workspace.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- }, {- "in" : "path",- "name" : "tx-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "last_run_at" : { },- "target_stale" : {- "oneOf" : [ {- "type" : "boolean"- }, {- "type" : "null"- } ]- },- "name" : {- "type" : "string"- },- "last_run_status" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "workspace_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "updated_at" : { },- "archived_at" : { },- "source" : {- "type" : "object",- "properties" : { }- },- "last_run_message" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "target" : {- "type" : "object",- "properties" : { }- },- "created_at" : { },- "global_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- },- "creator_id" : {- "oneOf" : [ {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }, {- "type" : "null"- } ]- },- "ref_id" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- },- "description" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- }- },- "required" : [ "ref_id", "global_id", "name", "description", "source", "target", "target_stale", "workspace_id", "creator_id", "archived_at", "created_at", "updated_at", "last_run_at", "last_run_status", "last_run_message" ]- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "requestBody" : {- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "description" : {- "oneOf" : [ {- "type" : "string"- }, {- "type" : "null"- } ]- },- "name" : {- "type" : "string"- },- "source" : {- "oneOf" : [ {- "type" : "object",- "properties" : {- "query" : {- "$ref" : "#/components/schemas/metabase.queries.schema.query"- },- "type" : {- "const" : "query"- }- },- "required" : [ "type", "query" ]- }, {- "type" : "object",- "properties" : {- "body" : {- "type" : "string"- },- "source-database" : {- "type" : "integer"- },- "source-tables" : {- "type" : "array",- "items" : {- "$ref" : "#/components/schemas/metabase.transforms-base.util.source-table-entry"- }- },- "type" : {- "const" : "python"- }- },- "required" : [ "source-tables", "type", "body" ],- "additionalProperties" : false- } ]- },- "target" : {- "type" : "object",- "properties" : {- "database" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- },- "name" : {- "type" : "string",- "minLength" : 1- },- "schema" : {- "oneOf" : [ {- "type" : "string",- "minLength" : 1- }, {- "type" : "null"- } ]- },- "type" : {- "type" : "string",- "enum" : [ "table" ]- }- },- "required" : [ "type", "name" ],- "additionalProperties" : false- }- }- }- }- }- },- "tags" : [ "/api/agent/v1/workspace" ]- },- "delete" : {- "operationId" : "delete-api-agent-v1-workspace-ws-id-transform-tx-id",- "summary" : "DELETE /api/agent/v1/workspace/{ws-id}/transform/{tx-id}",- "description" : "Delete a transform from the workspace.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- }, {- "in" : "path",- "name" : "tx-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "null"- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/transform/{tx-id}/archive" : {- "post" : {- "operationId" : "post-api-agent-v1-workspace-ws-id-transform-tx-id-archive",- "summary" : "POST /api/agent/v1/workspace/{ws-id}/transform/{tx-id}/archive",- "description" : "Mark a transform for archival.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- }, {- "in" : "path",- "name" : "tx-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "null"- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/transform/{tx-id}/dry-run" : {- "post" : {- "operationId" : "post-api-agent-v1-workspace-ws-id-transform-tx-id-dry-run",- "summary" : "POST /api/agent/v1/workspace/{ws-id}/transform/{tx-id}/dry-run",- "description" : "Dry-run a transform without persisting to the target table.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- }, {- "in" : "path",- "name" : "tx-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.query-result"- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "requestBody" : {- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "run_stale_ancestors" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.flag"- }- }- }- }- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/transform/{tx-id}/run" : {- "post" : {- "operationId" : "post-api-agent-v1-workspace-ws-id-transform-tx-id-run",- "summary" : "POST /api/agent/v1/workspace/{ws-id}/transform/{tx-id}/run",- "description" : "Run a single transform in a workspace.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- }, {- "in" : "path",- "name" : "tx-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.execution-result"- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "requestBody" : {- "content" : {- "application/json" : {- "schema" : {- "type" : "object",- "properties" : {- "run_stale_ancestors" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.flag"- }- }- }- }- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },- "/api/agent/v1/workspace/{ws-id}/transform/{tx-id}/unarchive" : {- "post" : {- "operationId" : "post-api-agent-v1-workspace-ws-id-transform-tx-id-unarchive",- "summary" : "POST /api/agent/v1/workspace/{ws-id}/transform/{tx-id}/unarchive",- "description" : "Unmark a transform for archival.",- "parameters" : [ {- "in" : "path",- "name" : "ws-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.appdb-id"- }- }, {- "in" : "path",- "name" : "tx-id",- "required" : true,- "schema" : {- "$ref" : "#/components/schemas/metabase-enterprise.workspaces.types.ref-id"- }- } ],- "responses" : {- "2XX" : {- "description" : "Successful response",- "content" : {- "application/json" : {- "schema" : {- "type" : "null"- }- }- }- },- "4XX" : {- "description" : "Client error response"- },- "5XX" : {- "description" : "Server error response"- }- },- "tags" : [ "/api/agent/v1/workspace" ]- }- },"/api/ai-entity-analysis/analyze-chart" : {"post" : {"operationId" : "post-api-ai-entity-analysis-analyze-chart",diff --git a/enterprise/backend/src/metabase_enterprise/agent_api/workspace.clj b/enterprise/backend/src/metabase_enterprise/agent_api/workspace.cljdeleted file mode 100644index 9f43deebe6a..00000000000--- a/enterprise/backend/src/metabase_enterprise/agent_api/workspace.clj+++ /dev/null@@ -1,337 +0,0 @@-(ns metabase-enterprise.agent-api.workspace- "Workspace endpoints for the Agent API, mounted at `/api/agent/v1/workspace/...`.- Provides workspace access with JWT-based agent authentication."- (:require- [metabase-enterprise.workspaces.api.common :as ws.api.common]- [metabase-enterprise.workspaces.core :as ws.core]- [metabase-enterprise.workspaces.types :as ws.t]- [metabase.api.common :as api]- [metabase.api.macros :as api.macros]- [metabase.api.routes.common :as api.routes.common]- [metabase.util.i18n :as i18n]- [metabase.util.malli.schema :as ms]))--(set! *warn-on-reflection* true)--;;; ------------------------------------------------ Agent API Schemas ------------------------------------------------;;-;; These schemas define the agent API contract independently of the EE workspace API.-;; In practice we will often sync with ws.api.common, but we must be conscious and explicit about breaking changes-;; so that we can keep our skills and integrations (e.g. CLI, MCP) updated.--(def ^:private WorkspaceStatus- "Computed workspace status enum."- (into [:enum] ws.api.common/computed-statuses))--(def ^:private Workspace- "Schema for a workspace API response."- [:map- [:id ::ws.t/appdb-id]- [:name :string]- [:collection_id ::ws.t/appdb-id]- [:database_id ::ws.t/appdb-id]- [:status WorkspaceStatus]- [:created_at ms/TemporalInstant]- [:updated_at ms/TemporalInstant]])--(def ^:private TransformSource ws.api.common/TransformSource)--(def ^:private TransformTarget- [:map {:closed true}- [:database {:optional true} ::ws.t/appdb-id]- [:type [:enum "table"]]- [:schema {:optional true} [:maybe [:string {:min 1}]]]- [:name [:string {:min 1}]]])--(def ^:private InputTable- [:map- [:db_id ::ws.t/appdb-id]- [:schema [:maybe :string]]- [:table :string]- [:table_id [:maybe ::ws.t/appdb-id]]])--(def ^:private OutputTable- [:map- [:db_id ::ws.t/appdb-id]- [:global [:map- [:transform_id [:maybe ::ws.t/appdb-id]]- [:schema [:maybe :string]]- [:table :string]- [:table_id [:maybe ::ws.t/appdb-id]]]]- [:isolated [:map- [:transform_id [:or ::ws.t/ref-id ::ws.t/appdb-id]]- [:schema :string]- [:table :string]- [:table_id [:maybe ::ws.t/appdb-id]]]]])--(def ^:private WorkspaceTransform- "Schema for a full workspace transform API response."- [:map- [:ref_id ::ws.t/ref-id]- [:global_id [:maybe ::ws.t/appdb-id]]- [:name :string]- [:description [:maybe :string]]- [:source :map]- [:target :map]- [:target_stale [:maybe :boolean]]- [:workspace_id ::ws.t/appdb-id]- [:creator_id [:maybe ::ws.t/appdb-id]]- [:archived_at :any]- [:created_at :any]- [:updated_at :any]- [:last_run_at :any]- [:last_run_status [:maybe :string]]- [:last_run_message [:maybe :string]]])--(def ^:private WorkspaceTransformListing- "Schema for a transform in a workspace listing."- [:map {:closed true}- [:ref_id ::ws.t/ref-id]- [:global_id [:maybe ::ws.t/appdb-id]]- [:name :string]- [:source_type [:maybe :keyword]]- [:creator_id [:maybe ::ws.t/appdb-id]]])--(def ^:private ExternalTransform- "Schema for an external (non-workspace) transform visible to a workspace."- [:map- [:id ::ws.t/appdb-id]- [:name :string]- [:source_type :keyword]- [:checkout_disabled [:maybe :string]]])--(def ^:private PendingInput- "Schema for an input table that has not yet been granted access."- [:map- [:db_id ::ws.t/appdb-id]- [:schema [:maybe :string]]- [:table :string]])--(def ^:private GraphNode- [:map- [:id [:or ::ws.t/appdb-id ::ws.t/ref-id]]- [:type [:enum :input-table :external-transform :workspace-transform]]- [:dependents_count [:map-of [:enum :input-table :external-transform :workspace-transform] ms/PositiveInt]]- [:data :map]])--(def ^:private GraphEdge- [:map- [:from_entity_id [:or ::ws.t/appdb-id ::ws.t/ref-id]]- [:from_entity_type :string]- [:to_entity_id [:or ::ws.t/appdb-id ::ws.t/ref-id]]- [:to_entity_type :string]])--(def ^:private GraphResult- "Schema for the workspace dependency graph response."- [:map- [:nodes [:sequential GraphNode]]- [:edges [:sequential GraphEdge]]])--;;; ------------------------------------------------ Read Endpoints -----------------------------------------------------(api.macros/defendpoint :get "/:ws-id" :- Workspace- "Get a single workspace by ID."- {:scope ws.core/agent-workspace-read}- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]- _query-params]- (ws.api.common/get-workspace ws-id))--(api.macros/defendpoint :get "/:ws-id/table"- :- [:map {:closed true}- [:inputs [:sequential InputTable]]- [:outputs [:sequential OutputTable]]]- "Get workspace input and output tables."- {:scope ws.core/agent-workspace-read}- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]- _query-params]- (ws.api.common/get-workspace-tables ws-id))--(api.macros/defendpoint :get "/:ws-id/log"- :- [:map- [:workspace_id ms/PositiveInt]- [:status WorkspaceStatus]- [:updated_at :any]- [:last_completed_at [:maybe :any]]- [:logs [:sequential [:map- [:id ms/PositiveInt]- [:task :keyword]- [:description ms/LocalizedString]- [:started_at :any]- [:updated_at :any]- [:completed_at [:maybe :any]]- [:status [:maybe :keyword]]- [:message [:maybe :string]]]]]]- "Get workspace creation status and recent log entries."- {:scope ws.core/agent-workspace-read}- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]- _query-params]- (ws.api.common/get-workspace-log ws-id))--(api.macros/defendpoint :get "/:ws-id/graph" :- GraphResult- "Get the dependency graph for a workspace."- {:scope ws.core/agent-workspace-read}- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]- _query-params]- (ws.api.common/get-workspace-graph ws-id))--(api.macros/defendpoint :get "/:ws-id/problem" :- [:sequential ::ws.t/problem]- "Detect problems in the workspace."- {:scope ws.core/agent-workspace-read}- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]- _query-params]- (ws.api.common/get-workspace-problems ws-id))--(api.macros/defendpoint :get "/:ws-id/external/transform" :- [:map [:transforms [:sequential ExternalTransform]]]- "List external transforms not checked out into this workspace."- {:scope ws.core/agent-workspace-read}- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]- {:keys [database-id]} :- [:map [:database-id {:optional true} ::ws.t/appdb-id]]]- (ws.api.common/get-external-transforms ws-id database-id))--(api.macros/defendpoint :get "/:ws-id/input/pending"- :- [:map [:inputs [:sequential PendingInput]]]- "List pending input grants."- {:scope ws.core/agent-workspace-read}- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]]- (ws.api.common/get-pending-inputs ws-id))--;;; ------------------------------------------ Transform CRUD -----------------------------------------------------------(api.macros/defendpoint :get "/:ws-id/transform" :- [:map [:transforms [:sequential WorkspaceTransformListing]]]- "List all transforms in a workspace."- {:scope ws.core/agent-workspace-read}- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]]- (ws.api.common/list-transforms ws-id))--(api.macros/defendpoint :get "/:ws-id/transform/:tx-id" :- WorkspaceTransform- "Get a specific transform in a workspace."- {:scope ws.core/agent-workspace-read}- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]]- (ws.api.common/fetch-ws-transform ws-id tx-id))--(api.macros/defendpoint :post "/:ws-id/archive" :- Workspace- "Archive a workspace."- {:scope ws.core/agent-workspace-write}- [{:keys [ws-id]} :- [:map [:ws-id ms/PositiveInt]]- _query-params- _body-params]- (ws.api.common/archive-workspace! ws-id))--(api.macros/defendpoint :post "/:ws-id/transform"- :- WorkspaceTransform- "Create a new transform in the workspace."- {:scope ws.core/agent-workspace-write}- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]- _query-params- body :- [:map #_{:closed true}- [:name :string]- [:description {:optional true} [:maybe :string]]- [:source TransformSource]- [:target TransformTarget]]]- (ws.api.common/create-workspace-transform! ws-id body))--(api.macros/defendpoint :post "/:ws-id/transform/:tx-id/archive" :- :nil- "Mark a transform for archival."- {:scope ws.core/agent-workspace-write}- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]]- (ws.api.common/archive-transform! ws-id tx-id))--(api.macros/defendpoint :post "/:ws-id/transform/:tx-id/unarchive" :- :nil- "Unmark a transform for archival."- {:scope ws.core/agent-workspace-write}- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]]- (ws.api.common/unarchive-transform! ws-id tx-id))--(api.macros/defendpoint :post "/:ws-id/transform/validate/target"- :- [:map [:status :int] [:body [:or :string i18n/LocalizedString]]]- "Validate the target table for a workspace transform."- {:scope ws.core/agent-workspace-write}- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]- {:keys [transform-id]} :- [:map [:transform-id {:optional true} ::ws.t/ref-id]]- {:keys [db_id target]} :- [:map- [:db_id {:optional true} ::ws.t/appdb-id]- [:target [:map- [:database {:optional true} ::ws.t/appdb-id]- [:type :string]- [:schema [:maybe :string]]- [:name :string]]]]]- (ws.api.common/validate-target ws-id transform-id db_id target))--;;; ---------------------------------------- Run / Query Endpoints ------------------------------------------------------(api.macros/defendpoint :post "/:ws-id/run"- :- [:map- [:succeeded [:sequential ::ws.t/ref-id]]- [:failed [:sequential ::ws.t/ref-id]]- [:not_run [:sequential ::ws.t/ref-id]]]- "Execute all transforms in the workspace in dependency order."- {:scope ws.core/agent-workspace-execute}- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]- _query-params- {:keys [stale_only]} :- [:map [:stale_only {:optional true} ::ws.t/flag]]]- (ws.api.common/run-workspace! ws-id stale_only))--(api.macros/defendpoint :post "/:ws-id/transform/:tx-id/run"- :- ::ws.t/execution-result- "Run a single transform in a workspace."- {:scope ws.core/agent-workspace-execute}- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]- _query-params- {:keys [run_stale_ancestors]} :- [:map [:run_stale_ancestors {:optional true} ::ws.t/flag]]]- (ws.api.common/run-transform! ws-id tx-id run_stale_ancestors))--(api.macros/defendpoint :post "/:ws-id/transform/:tx-id/dry-run"- :- ::ws.t/query-result- "Dry-run a transform without persisting to the target table."- {:scope ws.core/agent-workspace-execute}- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]- _query-params- {:keys [run_stale_ancestors]} :- [:map [:run_stale_ancestors {:optional true} ::ws.t/flag]]]- (ws.api.common/dry-run-transform! ws-id tx-id run_stale_ancestors))--(api.macros/defendpoint :post "/:ws-id/query"- :- ::ws.t/query-result- "Execute a SQL query in the workspace's isolated database context."- {:scope ws.core/agent-workspace-execute}- [{:keys [ws-id]} :- [:map [:ws-id ::ws.t/appdb-id]]- _query-params- {:keys [sql]} :- [:map [:sql [:string {:min 1}]]]]- (ws.api.common/execute-query! ws-id sql))--;;; ------------------------------------------ Update / Delete ----------------------------------------------------------(api.macros/defendpoint :put "/:ws-id/transform/:tx-id" :- WorkspaceTransform- "Update or create a transform in a workspace."- {:scope ws.core/agent-workspace-write}- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]- _query-params- body :- [:map- [:name {:optional true} :string]- [:description {:optional true} [:maybe :string]]- [:source {:optional true} TransformSource]- [:target {:optional true} TransformTarget]]]- (ws.api.common/update-transform! ws-id tx-id body))--(api.macros/defendpoint :delete "/:ws-id/transform/:tx-id" :- :nil- "Delete a transform from the workspace."- {:scope ws.core/agent-workspace-write}- [{:keys [ws-id tx-id]} :- [:map [:ws-id ::ws.t/appdb-id] [:tx-id ::ws.t/ref-id]]]- (ws.api.common/delete-transform! ws-id tx-id))--;;; ------------------------------------------------ Handler ------------------------------------------------------------(defn- authorize-workspace-access- "Authorization middleware for agent workspace routes. Requires superuser."- [handler]- (fn [request respond raise]- (api/check-superuser)- (handler request respond raise)))--(def ^:private +authorize- (api.routes.common/wrap-middleware-for-open-api-spec-generation authorize-workspace-access))--(defn workspace-handler- "Returns the workspace routes for the agent API, keyed by version prefix.- Currently only v1; new versions can be added here without changing api.clj."- [+auth]- (api.macros/ns-handler 'metabase-enterprise.agent-api.workspace +authorize +auth))diff --git a/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj b/enterprise/backend/src/metabase_enterprise/api_routes/routes.cljindex 1410531c32f..ccac301cdc7 100644--- a/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj+++ b/enterprise/backend/src/metabase_enterprise/api_routes/routes.clj@@ -8,7 +8,6 @@[metabase-enterprise.action-v2.api][metabase-enterprise.advanced-config.api.logs][metabase-enterprise.advanced-permissions.api.routes]- [metabase-enterprise.agent-api.workspace :as agent-api.workspace][metabase-enterprise.api.core :as ee.api][metabase-enterprise.audit-app.api.routes][metabase-enterprise.billing.api.routes]@@ -40,7 +39,6 @@[metabase-enterprise.transforms.api][metabase-enterprise.upload-management.api][metabase-enterprise.workspaces.api]- [metabase.agent-api.api :as agent-api][metabase.api.macros :as api.macros][metabase.api.util.handlers :as handlers][metabase.util.i18n :refer [deferred-tru]]))@@ -135,8 +133,7 @@(def ^:private routes-map(mergenaughty-routes-map- {"/agent" {"/v1" {"/workspace" (premium-handler (agent-api.workspace/workspace-handler agent-api/+auth) :workspaces)}}- "/ee" ee-routes-map}))+ {"/ee" ee-routes-map}))(def ^{:arglists '([request respond raise])} routes"API routes only available when running Metabase® Enterprise Edition™.diff --git a/enterprise/backend/src/metabase_enterprise/workspaces/api/common.clj b/enterprise/backend/src/metabase_enterprise/workspaces/api/common.cljindex 8bc0b77f469..8abdcc6a2aa 100644--- a/enterprise/backend/src/metabase_enterprise/workspaces/api/common.clj+++ b/enterprise/backend/src/metabase_enterprise/workspaces/api/common.clj@@ -1,6 +1,6 @@(ns metabase-enterprise.workspaces.api.common"Shared schemas, validations, and handler logic for workspace API routes.- Used by both `workspaces.api` and `agent-api.workspace` (agent routes)."+ Used by `workspaces.api` only currently, but may be shared with agent APIs in future."(:require[clojure.string :as str][medley.core :as m]@@ -365,8 +365,7 @@(target->spec driver table-id-map))));;; ---------------------------------------- Shared endpoint handlers -----------------------------------------;; These functions contain the handler logic shared between the regular workspace API-;; (`workspaces/api.clj`) and the agent workspace API (`agent-api/workspace.clj`).+;; These functions contain the handler logic for the workspace API (`workspaces/api.clj`).;; Each `defendpoint` becomes a thin wrapper that calls the corresponding function here.(def ^:private log-limit "Maximum number of recent workspace log items to show" 20)diff --git a/enterprise/backend/test/metabase_enterprise/agent_api/api_test.clj b/enterprise/backend/test/metabase_enterprise/agent_api/api_test.cljdeleted file mode 100644index 829fe704dab..00000000000--- a/enterprise/backend/test/metabase_enterprise/agent_api/api_test.clj+++ /dev/null@@ -1,226 +0,0 @@-(ns metabase-enterprise.agent-api.api-test- "Agent API tests that require enterprise features (JWT authentication, scopes)."- (:require- [buddy.sign.jwt :as jwt]- [clojure.test :refer :all]- [metabase-enterprise.sso.test-setup :as sso.test-setup]- [metabase.lib.core :as lib]- [metabase.lib.metadata :as lib.metadata]- [metabase.test :as mt]- [metabase.test.fixtures :as fixtures]- [metabase.test.http-client :as client]- [metabase.test.util :as tu]- [toucan2.core :as t2]))--(set! *warn-on-reflection* true)--(use-fixtures :once (fixtures/initialize :db :web-server :test-users))--(defmacro ^:private with-agent-api-setup!- "Sets up JWT authentication and premium features for Agent API tests."- [& body]- `(sso.test-setup/with-jwt-default-setup!- (mt/with-additional-premium-features #{:agent-api}- ~@body)))--(defn- current-epoch-seconds []- (quot (System/currentTimeMillis) 1000))--(defn- sign-jwt [claims]- (jwt/sign (merge {:iat (current-epoch-seconds)} claims) sso.test-setup/default-jwt-secret))--(defn- auth-headers- ([] (auth-headers "[email protected]"))- ([email]- {"authorization" (str "Bearer " (sign-jwt {:email email}))}))--(defn- agent-client- "Helper for making authenticated agent API requests using JWT."- [user method expected-status endpoint & [body]]- (let [email (:username (mt/user->credentials user))- headers (auth-headers email)]- (apply client/client method expected-status endpoint- {:request-options {:headers headers}}- (when body [body]))))--(defn- orders-count-query- "Create a simple count query on the orders table using lib functions."- []- (-> (lib/query (mt/metadata-provider)- (lib.metadata/table (mt/metadata-provider) (mt/id :orders)))- (lib/aggregate (lib/count))))--(deftest agent-api-jwt-auth-test- (with-agent-api-setup!- (testing "Valid JWT with email claim succeeds"- (is (= {:message "pong"}- (client/client :get 200 "agent/v1/ping"- {:request-options {:headers (auth-headers)}}))))-- (testing "Email case insensitivity - uppercase email in token"- (is (= {:message "pong"}- (client/client :get 200 "agent/v1/ping"- {:request-options {:headers (auth-headers "[email protected]")}}))))-- (testing "Email case insensitivity - mixed case email in token"- (is (= {:message "pong"}- (client/client :get 200 "agent/v1/ping"- {:request-options {:headers (auth-headers "[email protected]")}}))))-- (testing "Bearer scheme is case-insensitive (uppercase BEARER)"- (let [token (sign-jwt {:email "[email protected]"})- response (client/client :get 200 "agent/v1/ping"- {:request-options {:headers {"authorization" (str "BEARER " token)}}})]- (is (= {:message "pong"}- response))))-- (testing "Bearer scheme is case-insensitive (mixed case)"- (let [token (sign-jwt {:email "[email protected]"})- response (client/client :get 200 "agent/v1/ping"- {:request-options {:headers {"authorization" (str "BeArEr " token)}}})]- (is (= {:message "pong"}- response))))))--(deftest agent-api-error-responses-test- (with-agent-api-setup!- (testing "Missing authorization header (no session, no JWT)"- (let [response (client/client :get 401 "agent/v1/ping")]- (is (= {:error "missing_authorization"- :message "Authentication required. Use X-Metabase-Session header or Authorization: Bearer <jwt>."}- response))))-- (testing "Invalid authorization header format (not Bearer)"- (let [response (client/client :get 401 "agent/v1/ping"- {:request-options {:headers {"authorization" "Basic xyz"}}})]- (is (= {:error "invalid_authorization_format"- :message "Authorization header must use Bearer scheme: Authorization: Bearer <jwt>"}- response))))-- (testing "Token with non-existent user returns same error as invalid token (no information disclosure)"- (is (= {:error "invalid_jwt"- :message "Invalid or expired JWT token."}- (client/client :get 401 "agent/v1/ping"- {:request-options {:headers (auth-headers "[email protected]")}}))))))--(deftest agent-api-inactive-user-test- (with-agent-api-setup!- (testing "JWT for deactivated user returns same error as invalid token (no information disclosure)"- (mt/with-temp [:model/User {email :email} {:is_active false}]- (is (= {:error "invalid_jwt"- :message "Invalid or expired JWT token."}- (client/client :get 401 "agent/v1/ping"- {:request-options {:headers (auth-headers email)}})))))))--(deftest agent-api-user-binding-test- (with-agent-api-setup!- (testing "User is correctly bound from JWT - permissions are enforced"- ;; Create a metric in a collection, then revoke non-admin access- (mt/with-temp [:model/Collection collection {:name "Private Collection"}- :model/Card metric {:name "Private Metric"- :type :metric- :collection_id (:id collection)- :database_id (mt/id)- :dataset_query (orders-count-query)}]- (mt/with-non-admin-groups-no-collection-perms collection- (testing "Admin user can access the metric"- (is (=? {:type "metric"- :id (:id metric)- :name "Private Metric"}- (agent-client :crowberto :get 200 (str "agent/v1/metric/" (:id metric))))))-- (testing "Non-admin user cannot access the metric"- (is (= "You don't have permissions to do that."- (agent-client :rasta :get 403 (str "agent/v1/metric/" (:id metric)))))))))))--(deftest execute-query-records-query-execution-test- (with-agent-api-setup!- (testing "Executed queries are recorded with :agent context"- (mt/with-temp [:model/User {user-id :id email :email} {:is_superuser true}]- (let [table-id (mt/id :orders)- headers (auth-headers email)- construct-resp (client/client :post 200 "agent/v1/construct-query"- {:request-options {:headers headers}}- {:table_id table-id :limit 5})- _ (client/client :post 202 "agent/v1/execute"- {:request-options {:headers headers}}- {:query (:query construct-resp)})- ;; QueryExecution is saved asynchronously, so poll for it- query-execution (tu/poll-until 5000- (t2/select-one :model/QueryExecution :executor_id user-id))]- (is (= :agent (:context query-execution))))))))--(deftest agent-api-scope-enforcement-test- (with-agent-api-setup!- (let [table-id (mt/id :orders)]- (testing "No scope claim — unscoped JWT can access all endpoints (backwards compat)"- (let [headers {"authorization" (str "Bearer " (sign-jwt {:email "[email protected]"}))}]- (is (= {:message "pong"}- (client/client :get 200 "agent/v1/ping"- {:request-options {:headers headers}})))- (is (=? {:type "table" :id table-id}- (client/client :get 200 (str "agent/v1/table/" table-id)- {:request-options {:headers headers}})))))-- (testing "Matching scope — agent:table:read can access /v1/table/:id"- (let [headers {"authorization" (str "Bearer " (sign-jwt {:email "[email protected]"- :scope "agent:table:read"}))}]- (is (=? {:type "table" :id table-id}- (client/client :get 200 (str "agent/v1/table/" table-id)- {:request-options {:headers headers}})))))-- (testing "Wildcard scope — agent:* can access any scoped endpoint"- (let [headers {"authorization" (str "Bearer " (sign-jwt {:email "[email protected]"- :scope "agent:*"}))}]- (is (=? {:type "table" :id table-id}- (client/client :get 200 (str "agent/v1/table/" table-id)- {:request-options {:headers headers}})))))-- (testing "Wrong scope — agent:search gets 403 on /v1/table/:id"- (let [headers {"authorization" (str "Bearer " (sign-jwt {:email "[email protected]"- :scope "agent:search"}))}]- (is (= {:error "unsupported_scope"- :message "Insufficient scope for this operation."}- (client/client :get 403 (str "agent/v1/table/" table-id)- {:request-options {:headers headers}})))))-- (testing "Scoped JWT on unchecked endpoint — agent:table:read can access /v1/ping"- (let [headers {"authorization" (str "Bearer " (sign-jwt {:email "[email protected]"- :scope "agent:table:read"}))}]- (is (= {:message "pong"}- (client/client :get 200 "agent/v1/ping"- {:request-options {:headers headers}})))))-- (testing "Empty scope string — gets 403 on scoped endpoints"- (let [headers {"authorization" (str "Bearer " (sign-jwt {:email "[email protected]"- :scope ""}))}]- (is (= {:error "unsupported_scope"- :message "Insufficient scope for this operation."}- (client/client :get 403 (str "agent/v1/table/" table-id)- {:request-options {:headers headers}}))))))))--(deftest combined-query-scope-test- (with-agent-api-setup!- (testing "agent:query scope grants access to combined query endpoint"- (let [headers {"authorization" (str "Bearer " (sign-jwt {:email "[email protected]"- :scope "agent:query"}))}]- (is (= "completed"- (:status (client/client :post 202 "agent/v1/query"- {:request-options {:headers headers}}- {:table_id (mt/id :orders) :limit 1}))))))-- (testing "agent:* wildcard scope grants access"- (let [headers {"authorization" (str "Bearer " (sign-jwt {:email "[email protected]"- :scope "agent:*"}))}]- (is (= "completed"- (:status (client/client :post 202 "agent/v1/query"- {:request-options {:headers headers}}- {:table_id (mt/id :orders) :limit 1}))))))-- (testing "agent:query:construct scope does NOT grant access to combined endpoint"- (let [headers {"authorization" (str "Bearer " (sign-jwt {:email "[email protected]"- :scope "agent:query:construct"}))}]- (is (= {:error "unsupported_scope"- :message "Insufficient scope for this operation."}- (client/client :post 403 "agent/v1/query"- {:request-options {:headers headers}}- {:table_id (mt/id :orders) :limit 1})))))))diff --git a/enterprise/backend/test/metabase_enterprise/agent_api/workspace_test.clj b/enterprise/backend/test/metabase_enterprise/agent_api/workspace_test.cljdeleted file mode 100644index ea1e0fea8c7..00000000000--- a/enterprise/backend/test/metabase_enterprise/agent_api/workspace_test.clj+++ /dev/null@@ -1,252 +0,0 @@-(ns ^:mb/driver-tests metabase-enterprise.agent-api.workspace-test- (:require- [buddy.sign.jwt :as jwt]- [clojure.test :refer :all]- [metabase-enterprise.sso.test-setup :as sso.test-setup]- [metabase-enterprise.workspaces.test-util :as ws.tu]- [metabase.test :as mt]- [metabase.test.fixtures :as fixtures]- [metabase.test.http-client :as client]- [toucan2.core :as t2]))--(set! *warn-on-reflection* true)--(use-fixtures :once- (fixtures/initialize :db :test-users)- (fn [thunk] (mt/test-drivers (mt/normal-drivers-with-feature :transforms/table) (thunk))))--(ws.tu/ws-fixtures!)--;;; ---------------------------------------- Auth helpers ------------------------------------------(defn- current-epoch-seconds []- (int (/ (System/currentTimeMillis) 1000)))--(defn- sign-jwt [claims]- (jwt/sign (merge {:iat (current-epoch-seconds)} claims) sso.test-setup/default-jwt-secret))--(defmacro ^:private with-agent-workspace-setup!- "Sets up JWT auth and premium features needed for agent API + workspaces."- [& body]- `(sso.test-setup/with-jwt-default-setup!- (mt/with-additional-premium-features #{:agent-api :workspaces :transforms}- ~@body)))--(defn- auth-headers- ([] (auth-headers "[email protected]"))- ([email]- {"authorization" (str "Bearer " (sign-jwt {:email email}))}))--(defn- agent-ws-client- "Make an authenticated agent API workspace request."- ([method expected-status endpoint]- (agent-ws-client method expected-status endpoint nil))- ([method expected-status endpoint body]- (apply client/client method expected-status endpoint- {:request-options {:headers (auth-headers)}}- (when body [body]))))--;;; ---------------------------------------- Tests ------------------------------------------(deftest agent-workspace-auth-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:name "Auth Test"}}]- (let [ws-id (:workspace-id res)]- (testing "Valid JWT accesses workspace endpoint"- (is (=? {:id ws-id}- (agent-ws-client :get 200 (str "agent/v1/workspace/" ws-id)))))-- (testing "No JWT gets 401"- (is (= {:error "missing_authorization"- :message "Authentication required. Use X-Metabase-Session header or Authorization: Bearer <jwt>."}- (client/client :get 401 (str "agent/v1/workspace/" ws-id)))))-- (testing "Non-superuser gets 403"- (is (= "You don't have permissions to do that."- (client/client :get 403 (str "agent/v1/workspace/" ws-id)- {:request-options {:headers (auth-headers "[email protected]")}}))))))))--(deftest agent-workspace-get-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:name "GET Test"}}]- (let [ws-id (:workspace-id res)]- (testing "GET workspace returns workspace details"- (is (=? {:id ws-id- :name "GET Test"}- (agent-ws-client :get 200 (str "agent/v1/workspace/" ws-id)))))-- (testing "GET non-existent workspace returns 404"- (is (= "Not found."- (agent-ws-client :get 404 "agent/v1/workspace/999999"))))))))--(deftest agent-workspace-table-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:definitions {:x1 [:t1]}}}]- (let [ws-id (:workspace-id res)]- (testing "GET tables returns inputs and outputs"- (let [result (agent-ws-client :get 200 (str "agent/v1/workspace/" ws-id "/table"))]- (is (contains? result :inputs))- (is (contains? result :outputs))))))))--(deftest agent-workspace-log-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:name "Log Test"}}]- (let [ws-id (:workspace-id res)]- (testing "GET log returns workspace status and logs"- (let [result (agent-ws-client :get 200 (str "agent/v1/workspace/" ws-id "/log"))]- (is (= ws-id (:workspace_id result)))- (is (contains? result :status))- (is (sequential? (:logs result)))))))))--(deftest agent-workspace-transform-crud-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:definitions {:x1 [:t1]}}}]- (let [ws-id (:workspace-id res)- ref-id (get-in res [:workspace-map :x1])]- (testing "GET transforms listing"- (let [result (agent-ws-client :get 200 (str "agent/v1/workspace/" ws-id "/transform"))]- (is (sequential? (:transforms result)))- (is (some #(= ref-id (:ref_id %)) (:transforms result)))))-- (testing "GET specific transform"- (let [result (agent-ws-client :get 200 (str "agent/v1/workspace/" ws-id "/transform/" ref-id))]- (is (= ref-id (:ref_id result)))))-- (testing "POST archive transform"- (is (nil? (agent-ws-client :post 204 (str "agent/v1/workspace/" ws-id "/transform/" ref-id "/archive")))))-- (testing "POST unarchive transform"- (is (nil? (agent-ws-client :post 204 (str "agent/v1/workspace/" ws-id "/transform/" ref-id "/unarchive")))))))))--(deftest agent-workspace-graph-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:definitions {:x1 [:t1]}}}]- (let [ws-id (:workspace-id res)]- (testing "GET graph returns nodes and edges"- (let [result (agent-ws-client :get 200 (str "agent/v1/workspace/" ws-id "/graph"))]- (is (contains? result :nodes))- (is (contains? result :edges))))))))--(deftest agent-workspace-problem-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:definitions {:x1 [:t1]}}}]- (let [ws-id (:workspace-id res)]- (testing "GET problems returns a sequence"- (is (sequential? (agent-ws-client :get 200 (str "agent/v1/workspace/" ws-id "/problem")))))))))--(deftest agent-workspace-pending-inputs-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:definitions {:x1 [:t1]}}}]- (let [ws-id (:workspace-id res)]- (testing "GET pending inputs"- (let [result (agent-ws-client :get 200 (str "agent/v1/workspace/" ws-id "/input/pending"))]- (is (contains? result :inputs))))))))--(deftest agent-workspace-archive-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:name "Archive Test"}}]- (let [ws-id (:workspace-id res)]- (testing "POST archive workspace"- (let [result (agent-ws-client :post 200 (str "agent/v1/workspace/" ws-id "/archive"))]- (is (= "archived" (:status result)))))))))--(deftest agent-workspace-run-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:definitions {:x1 [:t1]}}}]- (let [ws-id (:workspace-id res)]- (testing "POST run workspace returns execution result"- (ws.tu/with-mocked-execution- (let [result (agent-ws-client :post 200 (str "agent/v1/workspace/" ws-id "/run"))]- (is (contains? result :succeeded))- (is (contains? result :failed))- (is (contains? result :not_run)))))))))--(deftest agent-workspace-external-transforms-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:global {:x1 [:t1]}- :workspace {:name "External Test"}}]- (let [ws-id (:workspace-id res)]- (testing "GET external transforms"- (let [result (agent-ws-client :get 200 (str "agent/v1/workspace/" ws-id "/external/transform"))]- (is (contains? result :transforms))- (is (sequential? (:transforms result)))))))))--(deftest agent-workspace-execute-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:definitions {:x1 [:t1]}}}]- (let [ws-id (:workspace-id res)- ref-id (get-in res [:workspace-map :x1])]- (testing "POST transform run returns execution result"- (let [result (agent-ws-client :post 200 (str "agent/v1/workspace/" ws-id "/transform/" ref-id "/run"))]- (is (contains? result :status))))-- (testing "POST transform dry-run returns query result"- (let [result (agent-ws-client :post 200 (str "agent/v1/workspace/" ws-id "/transform/" ref-id "/dry-run"))]- (is (contains? result :status))))-- (testing "POST query returns query result"- (let [result (agent-ws-client :post 200 (str "agent/v1/workspace/" ws-id "/query") {:sql "SELECT 1"})]- (is (contains? result :status))))-- (testing "POST run on archived workspace returns 400"- (agent-ws-client :post 200 (str "agent/v1/workspace/" ws-id "/archive"))- (is (= "Cannot execute archived workspace"- (agent-ws-client :post 400 (str "agent/v1/workspace/" ws-id "/run")))))))))--(deftest agent-workspace-validate-target-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:definitions {:x1 [:t1]}}}]- (let [ws-id (:workspace-id res)- ref-id (get-in res [:workspace-map :x1])- target (-> (t2/select-one [:model/WorkspaceTransform :target]- :workspace_id ws-id :ref_id ref-id)- :target)]- (testing "Validating a transform's own target with its ref-id returns 200 (no self-conflict)"- (is (= "OK"- (client/client :post 200 (str "agent/v1/workspace/" ws-id "/transform/validate/target")- {:request-options {:headers (auth-headers)}}- {:target target}- :transform-id ref-id))))-- (testing "Validating a conflicting target without transform-id returns 403"- (is (= "Another transform in this workspace already targets that table"- (agent-ws-client :post 403 (str "agent/v1/workspace/" ws-id "/transform/validate/target")- {:target target}))))))))--(defn- scoped-auth-headers [scope]- {"authorization" (str "Bearer " (sign-jwt {:email "[email protected]" :scope scope}))})--(deftest agent-workspace-scope-enforcement-test- (with-agent-workspace-setup!- (ws.tu/with-resources! [res {:workspace {:name "Scope Test"}}]- (let [ws-id (:workspace-id res)]- (testing "read scope can GET but not POST"- (let [headers (scoped-auth-headers "agent:workspace:read")]- (is (=? {:id ws-id}- (client/client :get 200 (str "agent/v1/workspace/" ws-id)- {:request-options {:headers headers}})))- (is (= {:error "unsupported_scope"- :message "Insufficient scope for this operation."}- (client/client :post 403 (str "agent/v1/workspace/" ws-id "/archive")- {:request-options {:headers headers}})))))-- (testing "write scope can POST archive but not run"- (let [headers (scoped-auth-headers "agent:workspace:write")]- (is (= {:error "unsupported_scope"- :message "Insufficient scope for this operation."}- (client/client :post 403 (str "agent/v1/workspace/" ws-id "/run")- {:request-options {:headers headers}})))))-- (testing "execute scope can POST run but not GET workspace"- (let [headers (scoped-auth-headers "agent:workspace:execute")]- (is (= {:error "unsupported_scope"- :message "Insufficient scope for this operation."}- (client/client :get 403 (str "agent/v1/workspace/" ws-id)- {:request-options {:headers headers}})))))))))--(deftest agent-workspace-feature-gating-test- ;; Feature gates fire before routing, so we don't need a real workspace - just a valid-looking URL.- (sso.test-setup/with-jwt-default-setup!- (testing "Returns 402 when :workspaces feature is not enabled"- (is (= 402 (:status (client/client-full-response :get 402 "agent/v1/workspace/1"- {:request-options {:headers (auth-headers)}})))))))diff --git a/enterprise/backend/test/metabase_enterprise/workspaces/api_parity_test.clj b/enterprise/backend/test/metabase_enterprise/workspaces/api_parity_test.cljdeleted file mode 100644index 7e58c9eeb3e..00000000000--- a/enterprise/backend/test/metabase_enterprise/workspaces/api_parity_test.clj+++ /dev/null@@ -1,68 +0,0 @@-(ns metabase-enterprise.workspaces.api-parity-test- "Verifies that Agent API schemas stay in sync with their implementations.- In general, the implementations will be shared with the regular EE APIs, so we can use their schemas as a baseline.- For now there is no divergence, so we catch unintentional drift by comparing the response schemas of both routes."- (:require- [clojure.test :refer :all]- [clojure.walk]- [metabase-enterprise.agent-api.workspace]- [metabase-enterprise.workspaces.api]- [metabase.api.macros :as api.macros]))--(set! *warn-on-reflection* true)--(def ^:private agent-only-endpoints- "Agent API endpoints that intentionally have no EE equivalent.- Add entries here when an agent endpoint is agent-specific by design."- #{;; example: [:post "/:ws-id/agent-specific-action"]- })--(def ^:private route-mapping- "Explicit mapping from agent route to EE route for endpoints with different paths.- Keys are [method agent-route], values are [method ee-route]."- {;; example: [:get "/:ws-id/agent-path"] [:get "/:ws-id/ee-path"]- })--(defn- resolve-schema-form- "Resolve symbols in a schema form to their var values within `ns-sym`, leaving- everything else (keywords, vectors, maps) untouched. This avoids false positives- from two namespaces defining the same symbol name with different values."- [ns-sym form]- (clojure.walk/prewalk- (fn [x]- (if (symbol? x)- (if-let [v (ns-resolve (the-ns ns-sym) x)]- (var-get v)- x)- x))- form))--(defn- endpoint-schemas- "Returns a map of {[method route] -> resolved-response-schema} for a namespace.- Symbols in schema forms are resolved to their var values so that comparisons- don't produce false positives when two namespaces define the same symbol name."- [ns-sym]- (into {}- (keep (fn [[[method route _params] info]]- (when-let [schema (get-in info [:form :response-schema])]- [[method route] (resolve-schema-form ns-sym schema)])))- (api.macros/ns-routes ns-sym)))--(deftest response-schemas-in-sync-test- (let [agent-schemas (endpoint-schemas 'metabase-enterprise.agent-api.workspace)- ee-schemas (endpoint-schemas 'metabase-enterprise.workspaces.api)]- ;; In the future, we may want to diverge in certain ways. Let's tackle that when we get there, but it will probably- ;; involve skipping those routes, or defining precisely how we expect them to differ (e.g. wrapping)- (testing "Every agent API endpoint should have a matching EE endpoint with the same response schema"- (is (seq agent-schemas) "Agent API should have endpoints")- (doseq [[[method route :as agent-key] agent-schema] (sort-by key agent-schemas)- :when (not (agent-only-endpoints agent-key))]- (let [ee-key (get route-mapping agent-key agent-key)- ee-schema (ee-schemas ee-key)]- (testing (str (name method) " " route)- (if ee-schema- (is (= ee-schema agent-schema))- (is false- (str "No matching EE endpoint for agent route " agent-key ". "- "Update `route-mapping` to map it to the correct EE route, "- "or add it to `agent-only-endpoints` if there is no equivalent.")))))))))diff --git a/src/metabase/agent_api/reference.md b/src/metabase/agent_api/reference.mdindex 90fcfb86bb7..0a0baa2df81 100644--- a/src/metabase/agent_api/reference.md+++ b/src/metabase/agent_api/reference.md@@ -572,491 +572,3 @@ Row limits:| 404 | Entity not found |-----# Workspace API--The Workspace API provides endpoints for managing data workspaces — isolated-environments for building and running data transforms (ETL pipelines).--Requires the `workspaces` Metabase Pro/Enterprise feature.--## Workspace status--| Status | Description |-|-----------------|----------------------------------------------|-| uninitialized | Workspace created but database not set up |-| pending | Database setup in progress |-| ready | Workspace is ready for use |-| broken | Workspace encountered an error during setup |-| archived | Workspace has been archived |--## Read endpoints--### GET /v1/workspace/{ws-id}--Get a single workspace by ID.--**Scope**: `agent:workspace:read`--Response:--```json-{- "id": 1,- "name": "Revenue Analysis",- "collection_id": 42,- "database_id": 5,- "status": "ready",- "created_at": "2024-06-01T10:00:00Z",- "updated_at": "2024-06-15T14:30:00Z"-}-```--### GET /v1/workspace/{ws-id}/table--Get workspace input and output tables.--**Scope**: `agent:workspace:read`--Response:--```json-{- "inputs": [- {"db_id": 1, "schema": "PUBLIC", "table": "ORDERS", "table_id": 42}- ],- "outputs": [- {- "db_id": 5,- "global": {- "transform_id": 10,- "schema": "PUBLIC",- "table": "DAILY_REVENUE",- "table_id": 100- },- "isolated": {- "transform_id": "tx-abc123",- "schema": "mb__isolation_ws_1",- "table": "DAILY_REVENUE",- "table_id": 101- }- }- ]-}-```--### GET /v1/workspace/{ws-id}/log--Get workspace creation status and recent log entries (up to 20).--**Scope**: `agent:workspace:read`--Response:--```json-{- "workspace_id": 1,- "status": "ready",- "updated_at": "2024-06-15T14:30:00Z",- "last_completed_at": "2024-06-15T14:30:00Z",- "logs": [- {- "id": 1,- "task": "setup",- "description": "Creating isolated database schema",- "started_at": "2024-06-01T10:00:00Z",- "updated_at": "2024-06-01T10:01:00Z",- "completed_at": "2024-06-01T10:01:00Z",- "status": "completed",- "message": null- }- ]-}-```--### GET /v1/workspace/{ws-id}/graph--Get the dependency graph for a workspace.--**Scope**: `agent:workspace:read`--Response:--```json-{- "nodes": [- {- "id": 42,- "type": "input-table",- "dependents_count": {"workspace-transform": 1},- "data": {"table": "ORDERS", "schema": "PUBLIC"}- },- {- "id": "tx-abc123",- "type": "workspace-transform",- "dependents_count": {},- "data": {"name": "Daily Revenue"}- }- ],- "edges": [- {- "from_entity_id": 42,- "from_entity_type": "input-table",- "to_entity_id": "tx-abc123",- "to_entity_type": "workspace-transform"- }- ]-}-```--### GET /v1/workspace/{ws-id}/problem--Detect problems in the workspace (stale transforms, cycles, failures, etc.).--**Scope**: `agent:workspace:read`--Response:--```json-[- {- "category": "internal",- "problem": "stale",- "severity": "warning",- "block_merge": false,- "data": {"transform_ref_id": "tx-abc123"}- }-]-```--| Field | Description |-|-------------|--------------------------------------------------------------|-| category | `unused`, `internal-downstream`, `external-downstream`, |-| | `internal`, or `external` |-| problem | Problem type (e.g., `not-run`, `stale`, `failed`) |-| severity | `error`, `warning`, or `info` |-| block_merge | Whether this problem prevents merging to production |--### GET /v1/workspace/{ws-id}/external/transform--List external (global) transforms not checked out into this workspace.--**Scope**: `agent:workspace:read`--Query parameters:--| Parameter | Type | Required | Description |-|-------------|---------|----------|--------------------------------|-| database-id | integer | No | Filter by specific database ID |--Response:--```json-{- "transforms": [- {- "id": 10,- "name": "Daily Revenue",- "source_type": "python",- "checkout_disabled": null- }- ]-}-```--`checkout_disabled` is non-null (e.g., `"mbql"`, `"card-reference"`) when the-transform cannot be added to a workspace.--### GET /v1/workspace/{ws-id}/input/pending--List input tables that haven't been granted access yet.--**Scope**: `agent:workspace:read`--Response:--```json-{- "inputs": [- {"db_id": 1, "schema": "PUBLIC", "table": "CUSTOMERS"}- ]-}-```--### GET /v1/workspace/{ws-id}/transform--List all transforms in a workspace.--**Scope**: `agent:workspace:read`--Response:--```json-{- "transforms": [- {- "ref_id": "tx-abc123",- "global_id": 10,- "name": "Daily Revenue",- "source_type": "python",- "creator_id": 1- }- ]-}-```--### GET /v1/workspace/{ws-id}/transform/{tx-id}--Get full details for a specific transform.--**Scope**: `agent:workspace:read`--Response:--```json-{- "ref_id": "tx-abc123",- "global_id": 10,- "name": "Daily Revenue",- "description": "Aggregate daily revenue from orders",- "source": {"type": "python", "code": "..."},- "target": {"type": "table", "schema": "PUBLIC", "name": "DAILY_REVENUE"},- "target_stale": false,- "workspace_id": 1,- "creator_id": 1,- "archived_at": null,- "created_at": "2024-06-01T10:00:00Z",- "updated_at": "2024-06-15T14:30:00Z",- "last_run_at": "2024-06-15T14:30:00Z",- "last_run_status": "succeeded",- "last_run_message": null-}-```--## Write endpoints--### POST /v1/workspace/{ws-id}/archive--Archive a workspace.--**Scope**: `agent:workspace:write`--Request body: empty.--Response: the archived workspace object (same schema as GET /v1/workspace/{ws-id}).--### POST /v1/workspace/{ws-id}/transform--Create a new transform in the workspace.--**Scope**: `agent:workspace:write`--Request:--```json-{- "name": "Daily Revenue",- "description": "Aggregate daily revenue from orders",- "source": {"type": "python", "code": "..."}-}-```--| Field | Type | Required | Description |-|-------------|--------|----------|-------------------------------|-| name | string | Yes | Transform name |-| description | string | No | Transform description |-| source | object | Yes | Transform source (see below) |--Response: the created transform (same schema as GET /v1/workspace/{ws-id}/transform/{tx-id}).--### PUT /v1/workspace/{ws-id}/transform/{tx-id}--Update an existing transform, or create one with the given ref_id if it does-not exist.--**Scope**: `agent:workspace:write`--Request (all fields optional for updates):--```json-{- "name": "Updated Name",- "description": "Updated description",- "source": {"type": "python", "code": "..."},- "target": {"type": "table", "schema": "PUBLIC", "name": "DAILY_REVENUE"}-}-```--Response: the updated transform (same schema as GET /v1/workspace/{ws-id}/transform/{tx-id}).--### POST /v1/workspace/{ws-id}/transform/{tx-id}/archive--Mark a transform for archival.--**Scope**: `agent:workspace:write`--Request body: empty.--Response: 204 No Content.--### POST /v1/workspace/{ws-id}/transform/{tx-id}/unarchive--Restore an archived transform.--**Scope**: `agent:workspace:write`--Request body: empty.--Response: 204 No Content.--### DELETE /v1/workspace/{ws-id}/transform/{tx-id}--Permanently delete a transform from the workspace.--**Scope**: `agent:workspace:write`--Response: 204 No Content.--### POST /v1/workspace/{ws-id}/transform/validate/target--Validate a target table configuration for a transform.--**Scope**: `agent:workspace:write`--Query parameters:--| Parameter | Type | Required | Description |-|--------------|--------|----------|----------------------------------------------|-| transform-id | string | No | Transform ref_id to exclude from conflict check |--Request:--```json-{- "target": {- "type": "table",- "schema": "PUBLIC",- "name": "DAILY_REVENUE"- }-}-```--Response (200 if valid):--```json-{"status": 200, "body": "OK"}-```--Response (403 if invalid):--```json-{"status": 403, "body": "Unsupported target type"}-```--## Execute endpoints--### POST /v1/workspace/{ws-id}/run--Execute all transforms in the workspace in dependency order.--**Scope**: `agent:workspace:execute`--Request:--```json-{"stale_only": true}-```--| Field | Type | Required | Description |-|------------|---------|----------|------------------------------------------|-| stale_only | boolean | No | Only run stale transforms (default false) |--Response:--```json-{- "succeeded": ["tx-abc123", "tx-def456"],- "failed": [],- "not_run": []-}-```--### POST /v1/workspace/{ws-id}/transform/{tx-id}/run--Run a single transform.--**Scope**: `agent:workspace:execute`--Request:--```json-{"run_stale_ancestors": true}-```--| Field | Type | Required | Description |-|---------------------|---------|----------|-----------------------------------------------|-| run_stale_ancestors | boolean | No | Run stale ancestor transforms first |--Response:--```json-{- "status": "succeeded",- "start_time": "2024-06-15T14:30:00Z",- "end_time": "2024-06-15T14:30:05Z",- "message": null,- "table": {"name": "DAILY_REVENUE", "schema": "PUBLIC"},- "ancestors": {"succeeded": [], "failed": [], "not_run": []}-}-```--### POST /v1/workspace/{ws-id}/transform/{tx-id}/dry-run--Dry-run a transform — execute the query without persisting to the target table.--**Scope**: `agent:workspace:execute`--Request:--```json-{"run_stale_ancestors": true}-```--Response:--```json-{- "status": "succeeded",- "message": null,- "running_time": 142,- "started_at": "2024-06-15T14:30:00Z",- "data": {- "cols": [- {"name": "DATE", "base_type": "type/Date"},- {"name": "REVENUE", "base_type": "type/Float"}- ],- "rows": [- ["2024-06-01", 15234.50],- ["2024-06-02", 18102.75]- ]- }-}-```--### POST /v1/workspace/{ws-id}/query--Execute an ad-hoc SQL query in the workspace's isolated database context.--**Scope**: `agent:workspace:execute`--Request:--```json-{"sql": "SELECT * FROM daily_revenue LIMIT 10"}-```--| Field | Type | Required | Description |-|-------|--------|----------|----------------------|-| sql | string | Yes | SQL query to execute |--Response: same format as dry-run (query result with status, data, cols, rows).