{"version":3,"sources":["../src/server/handlers/stored-workspaces.ts"],"names":["createRoute","listStoredWorkspacesQuerySchema","listStoredWorkspacesResponseSchema","HTTPException","resolveAuthorFilter","getStoredResourceScope","scopeStoredResourceMetadata","matchesAuthorFilter","handleError","storedWorkspaceIdPathParams","getStoredWorkspaceResponseSchema","assertStoredResourceScope","assertReadAccess","createStoredWorkspaceBodySchema","createStoredWorkspaceResponseSchema","toSlug","getCallerAuthorId","updateStoredWorkspaceBodySchema","updateStoredWorkspaceResponseSchema","assertWriteAccess","deleteStoredWorkspaceResponseSchema"],"mappings":";;;;;;;;;;AA+BO,IAAM,+BAA+BA,6BAAA,CAAY;AAAA,EACtD,MAAA,EAAQ,KAAA;AAAA,EACR,IAAA,EAAM,oBAAA;AAAA,EACN,YAAA,EAAc,MAAA;AAAA,EACd,gBAAA,EAAkBC,iDAAA;AAAA,EAClB,cAAA,EAAgBC,oDAAA;AAAA,EAChB,OAAA,EAAS,wBAAA;AAAA,EACT,WAAA,EAAa,iFAAA;AAAA,EACb,IAAA,EAAM,CAAC,mBAAmB,CAAA;AAAA,EAC1B,YAAA,EAAc,IAAA;AAAA,EACd,OAAA,EAAS,OAAO,EAAE,MAAA,EAAQ,IAAA,EAAM,SAAS,OAAA,EAAS,QAAA,EAAU,QAAA,EAAU,cAAA,EAAe,KAAM;AACzF,IAAA,IAAI;AACF,MAAA,MAAM,OAAA,GAAU,OAAO,UAAA,EAAW;AAElC,MAAA,IAAI,CAAC,OAAA,EAAS;AACZ,QAAA,MAAM,IAAIC,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,6BAA6B,CAAA;AAAA,MACvE;AAEA,MAAA,MAAM,cAAA,GAAiB,MAAM,OAAA,CAAQ,QAAA,CAAS,YAAY,CAAA;AAC1D,MAAA,IAAI,CAAC,cAAA,EAAgB;AACnB,QAAA,MAAM,IAAIA,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,8CAA8C,CAAA;AAAA,MACxF;AAMA,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AAA,OAAO;AAAA,QACL,OAAA,EAAS,IAAA;AAAA,QACT,OAAA,EAAS,aAAa,iBAAiB,CAAA,qBAAA;AAAA,OACzC;AAAA,IACF,SAAS,KAAA,EAAO;AACd,MAAA,OAAOX,6BAAA,CAAY,OAAO,iCAAiC,CAAA;AAAA,IAC7D;AAAA,EACF;AACF,CAAC","file":"chunk-VNWPOCOT.cjs","sourcesContent":["import { HTTPException } from '../http-exception';\nimport {\n storedWorkspaceIdPathParams,\n listStoredWorkspacesQuerySchema,\n createStoredWorkspaceBodySchema,\n updateStoredWorkspaceBodySchema,\n listStoredWorkspacesResponseSchema,\n getStoredWorkspaceResponseSchema,\n createStoredWorkspaceResponseSchema,\n updateStoredWorkspaceResponseSchema,\n deleteStoredWorkspaceResponseSchema,\n} from '../schemas/stored-workspaces';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { assertStoredResourceScope, getStoredResourceScope, scopeStoredResourceMetadata, toSlug } from '../utils';\n\nimport {\n assertReadAccess,\n assertWriteAccess,\n getCallerAuthorId,\n matchesAuthorFilter,\n resolveAuthorFilter,\n} from './authorship';\nimport { handleError } from './error';\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /stored/workspaces - List all stored workspaces\n */\nexport const LIST_STORED_WORKSPACES_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/workspaces',\n responseType: 'json',\n queryParamSchema: listStoredWorkspacesQuerySchema,\n responseSchema: listStoredWorkspacesResponseSchema,\n summary: 'List stored workspaces',\n description: 'Returns a paginated list of all workspace configurations stored in the database',\n tags: ['Stored Workspaces'],\n requiresAuth: true,\n handler: async ({ mastra, page, perPage, orderBy, authorId, metadata, requestContext }) => {\n try {\n const storage = mastra.getStorage();\n\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n\n const workspaceStore = await storage.getStore('workspaces');\n if (!workspaceStore) {\n throw new HTTPException(500, { message: 'Workspaces storage domain is not available' });\n }\n\n // Resolve the visibility scope for this caller. Non-owner queries for\n // another author return nothing (workspaces have no `public` visibility\n // yet); default lists return the caller's rows plus legacy unowned\n // records.\n const filter = resolveAuthorFilter({\n requestContext,\n resource: 'stored-workspaces',\n queryAuthorId: authorId,\n });\n\n const scope = await getStoredResourceScope(mastra, requestContext);\n const result = await workspaceStore.listResolved({\n page,\n perPage,\n orderBy,\n authorId: filter.kind === 'exact' ? filter.authorId : undefined,\n metadata: scopeStoredResourceMetadata(metadata, scope),\n });\n\n // Post-filter to enforce ownership rules across all backends. Storage\n // adapters can only do an equality filter on authorId, so we apply the\n // ownedOrPublic / ownedOrPublicOthers logic here. `total` is left as the\n // storage-reported count to keep pagination math working.\n const visibleWorkspaces = result.workspaces.filter(record => matchesAuthorFilter(record, filter));\n\n // Annotate each workspace with whether it's registered at runtime\n const runtimeWorkspaces = mastra.listWorkspaces();\n const workspaces = visibleWorkspaces.map(ws => ({\n ...ws,\n runtimeRegistered: ws.id in runtimeWorkspaces,\n }));\n\n return { ...result, workspaces };\n } catch (error) {\n return handleError(error, 'Error listing stored workspaces');\n }\n },\n});\n\n/**\n * GET /stored/workspaces/:storedWorkspaceId - Get a stored workspace by ID\n */\nexport const GET_STORED_WORKSPACE_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/workspaces/:storedWorkspaceId',\n responseType: 'json',\n pathParamSchema: storedWorkspaceIdPathParams,\n responseSchema: getStoredWorkspaceResponseSchema,\n summary: 'Get stored workspace by ID',\n description:\n 'Returns a specific workspace from storage by its unique identifier (resolved with active version config)',\n tags: ['Stored Workspaces'],\n requiresAuth: true,\n handler: async ({ mastra, storedWorkspaceId, requestContext }) => {\n try {\n const storage = mastra.getStorage();\n\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n\n const workspaceStore = await storage.getStore('workspaces');\n if (!workspaceStore) {\n throw new HTTPException(500, { message: 'Workspaces storage domain is not available' });\n }\n\n const workspace = await workspaceStore.getByIdResolved(storedWorkspaceId);\n\n if (!workspace) {\n throw new HTTPException(404, { message: `Stored workspace with id ${storedWorkspaceId} not found` });\n }\n assertStoredResourceScope(workspace, await getStoredResourceScope(mastra, requestContext));\n\n // Throws 404 if the caller isn't the owner, admin, or `stored-workspaces:read[:]` holder.\n assertReadAccess({\n requestContext,\n resource: 'stored-workspaces',\n resourceId: storedWorkspaceId,\n record: workspace,\n });\n\n return workspace;\n } catch (error) {\n return handleError(error, 'Error getting stored workspace');\n }\n },\n});\n\n/**\n * POST /stored/workspaces - Create a new stored workspace\n */\nexport const CREATE_STORED_WORKSPACE_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/workspaces',\n responseType: 'json',\n bodySchema: createStoredWorkspaceBodySchema,\n responseSchema: createStoredWorkspaceResponseSchema,\n summary: 'Create stored workspace',\n description: 'Creates a new workspace configuration in storage with the provided settings',\n tags: ['Stored Workspaces'],\n requiresAuth: true,\n handler: async ({\n mastra,\n id: providedId,\n metadata,\n name,\n description,\n filesystem,\n sandbox,\n mounts,\n search,\n skills,\n tools,\n autoSync,\n operationTimeout,\n requestContext,\n }) => {\n try {\n const storage = mastra.getStorage();\n\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n\n const workspaceStore = await storage.getStore('workspaces');\n if (!workspaceStore) {\n throw new HTTPException(500, { message: 'Workspaces storage domain is not available' });\n }\n\n // Derive ID from name if not explicitly provided\n const id = providedId || toSlug(name);\n\n if (!id) {\n throw new HTTPException(400, {\n message: 'Could not derive workspace ID from name. Please provide an explicit id.',\n });\n }\n\n // Check if workspace with this ID already exists\n const existing = await workspaceStore.getById(id);\n if (existing) {\n throw new HTTPException(409, { message: `Workspace with id ${id} already exists` });\n }\n\n // Force authorId from the authenticated caller; ignore any body-provided value.\n // No caller (auth not configured) leaves authorId undefined so legacy\n // single-user setups continue to behave as today.\n const authorId = getCallerAuthorId(requestContext) ?? undefined;\n\n await workspaceStore.create({\n workspace: {\n id,\n authorId,\n metadata: scopeStoredResourceMetadata(metadata, await getStoredResourceScope(mastra, requestContext)),\n name,\n description,\n filesystem,\n sandbox,\n mounts,\n search,\n skills,\n tools,\n autoSync,\n operationTimeout,\n },\n });\n\n // Return the resolved workspace (thin record + version config)\n const resolved = await workspaceStore.getByIdResolved(id);\n if (!resolved) {\n throw new HTTPException(500, { message: 'Failed to resolve created workspace' });\n }\n\n return resolved;\n } catch (error) {\n return handleError(error, 'Error creating stored workspace');\n }\n },\n});\n\n/**\n * PATCH /stored/workspaces/:storedWorkspaceId - Update a stored workspace\n */\nexport const UPDATE_STORED_WORKSPACE_ROUTE = createRoute({\n method: 'PATCH',\n path: '/stored/workspaces/:storedWorkspaceId',\n responseType: 'json',\n pathParamSchema: storedWorkspaceIdPathParams,\n bodySchema: updateStoredWorkspaceBodySchema,\n responseSchema: updateStoredWorkspaceResponseSchema,\n summary: 'Update stored workspace',\n description: 'Updates an existing workspace in storage with the provided fields',\n tags: ['Stored Workspaces'],\n requiresAuth: true,\n handler: async ({\n mastra,\n storedWorkspaceId,\n // Metadata-level fields\n metadata,\n // Config fields (snapshot-level)\n name,\n description,\n filesystem,\n sandbox,\n mounts,\n search,\n skills,\n tools,\n autoSync,\n operationTimeout,\n requestContext,\n }) => {\n try {\n const storage = mastra.getStorage();\n\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n\n const workspaceStore = await storage.getStore('workspaces');\n if (!workspaceStore) {\n throw new HTTPException(500, { message: 'Workspaces storage domain is not available' });\n }\n\n // Check if workspace exists\n const existing = await workspaceStore.getById(storedWorkspaceId);\n if (!existing) {\n throw new HTTPException(404, { message: `Stored workspace with id ${storedWorkspaceId} not found` });\n }\n const scope = await getStoredResourceScope(mastra, requestContext);\n assertStoredResourceScope(existing, scope);\n\n // Throws 404 if the caller isn't the owner, admin, or `stored-workspaces:edit[:]` holder.\n assertWriteAccess({\n requestContext,\n resource: 'stored-workspaces',\n resourceId: storedWorkspaceId,\n action: 'edit',\n record: existing,\n });\n\n const scopedMetadata =\n metadata !== undefined\n ? scopeStoredResourceMetadata({ ...(existing.metadata ?? {}), ...metadata }, scope)\n : undefined;\n\n // Update the workspace with both metadata-level and config-level fields.\n // The storage layer handles separating these into record updates vs\n // new-version creation. Strip undefined keys so omitted fields don't\n // overwrite persisted values (same pattern as stored-skills PATCH).\n // Note: authorId is intentionally not accepted here. Ownership cannot be\n // transferred via PATCH; admins must use a dedicated flow if that is ever\n // needed.\n const updateInput: Record = { id: storedWorkspaceId };\n const candidate: Record = {\n ...(scopedMetadata !== undefined ? { metadata: scopedMetadata } : {}),\n name,\n description,\n filesystem,\n sandbox,\n mounts,\n search,\n skills,\n tools,\n autoSync,\n operationTimeout,\n };\n for (const [key, value] of Object.entries(candidate)) {\n if (value !== undefined) updateInput[key] = value;\n }\n await workspaceStore.update(updateInput as Parameters[0]);\n\n // Return the resolved workspace with the updated config\n const resolved = await workspaceStore.getByIdResolved(storedWorkspaceId);\n if (!resolved) {\n throw new HTTPException(500, { message: 'Failed to resolve updated workspace' });\n }\n\n return resolved;\n } catch (error) {\n return handleError(error, 'Error updating stored workspace');\n }\n },\n});\n\n/**\n * DELETE /stored/workspaces/:storedWorkspaceId - Delete a stored workspace\n */\nexport const DELETE_STORED_WORKSPACE_ROUTE = createRoute({\n method: 'DELETE',\n path: '/stored/workspaces/:storedWorkspaceId',\n responseType: 'json',\n pathParamSchema: storedWorkspaceIdPathParams,\n responseSchema: deleteStoredWorkspaceResponseSchema,\n summary: 'Delete stored workspace',\n description: 'Deletes a workspace from storage by its unique identifier',\n tags: ['Stored Workspaces'],\n requiresAuth: true,\n handler: async ({ mastra, storedWorkspaceId, requestContext }) => {\n try {\n const storage = mastra.getStorage();\n\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\n }\n\n const workspaceStore = await storage.getStore('workspaces');\n if (!workspaceStore) {\n throw new HTTPException(500, { message: 'Workspaces storage domain is not available' });\n }\n\n // Check if workspace exists\n const existing = await workspaceStore.getById(storedWorkspaceId);\n if (!existing) {\n throw new HTTPException(404, { message: `Stored workspace with id ${storedWorkspaceId} not found` });\n }\n assertStoredResourceScope(existing, await getStoredResourceScope(mastra, requestContext));\n\n // Throws 404 if the caller isn't the owner, admin, or `stored-workspaces:delete[:]` holder.\n assertWriteAccess({\n requestContext,\n resource: 'stored-workspaces',\n resourceId: storedWorkspaceId,\n action: 'delete',\n record: existing,\n });\n\n await workspaceStore.delete(storedWorkspaceId);\n\n return {\n success: true,\n message: `Workspace ${storedWorkspaceId} deleted successfully`,\n };\n } catch (error) {\n return handleError(error, 'Error deleting stored workspace');\n }\n },\n});\n"]}