{"version":3,"sources":["../src/server/handlers/stored-skills.ts"],"names":["createRoute","listStoredSkillsQuerySchema","listStoredSkillsResponseSchema","HTTPException","resolveAuthorFilter","getStoredResourceScope","scopeStoredResourceMetadata","getCallerAuthorId","isBuilderFeatureEnabled","matchesAuthorFilter","annotated","stripFavoriteFields","prepareFavoritesEnrichment","handleError","storedSkillIdPathParams","getStoredSkillResponseSchema","assertStoredResourceScope","assertReadAccess","enrichOrStripFavorites","createStoredSkillBodySchema","createStoredSkillResponseSchema","toSlug","updateStoredSkillBodySchema","updateStoredSkillResponseSchema","assertWriteAccess","deleteStoredSkillResponseSchema","publishStoredSkillBodySchema","publishStoredSkillResponseSchema","LocalSkillSource"],"mappings":";;;;;;;;;;;;AAuCA,IAAM,eAAA,GAAkB,CAAC,YAAA,EAAc,SAAA,EAAW,QAAQ,CAAA;AAQ1D,SAAS,4BAAA,CACP,OACA,QAAA,EASA;AACA,EAAA,IAAI,CAAC,KAAA,IAAS,KAAA,CAAM,MAAA,KAAW,CAAA,SAAU,EAAC;AAG1C,EAAA,MAAM,OAAO,KAAA,CAAM,IAAA,CAAK,CAAA,CAAA,KAAK,CAAA,CAAE,SAAS,QAAQ,CAAA;AAChD,EAAA,IAAI,CAAC,IAAA,EAAM,QAAA,EAAU,OAAO,EAAC;AAE7B,EAAA,MAAM,SAAmC,EAAC;AAE1C,EAAA,KAAA,MAAW,cAAc,eAAA,EAAiB;AACxC,IAAA,MAAM,MAAA,GAAS,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,CAAA,CAAA,KAAK,EAAE,IAAA,KAAS,QAAA,IAAY,CAAA,CAAE,IAAA,KAAS,UAAU,CAAA;AACnF,IAAA,IAAI,CAAC,MAAA,EAAQ,QAAA,IAAY,MAAA,CAAO,QAAA,CAAS,WAAW,CAAA,EAAG;AAEvD,IAAA,MAAM,gBAAgB,IAAI,GAAA,CAAI,SAAS,UAAU,CAAA,IAAK,EAAE,CAAA;AACxD,IAAA,MAAM,KAAA,GAAkB,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ACrE,MAAA,IAAI,aAAA,EAAe;AACjB,QAAA,MAAM,WAAW,MAAA,CAAO;AAAA,UACtB,EAAA,EAAI,aAAA;AAAA,UACJ,iBAAiB,aAAA,CAAc;AAAA,SAChC,CAAA;AAAA,MACH;AAEA,MAAA,MAAM,QAAA,GAAW,MAAM,UAAA,CAAW,eAAA,CAAgB,aAAa,CAAA;AAC/D,MAAA,IAAI,CAAC,QAAA,EAAU;AACb,QAAA,MAAM,IAAIzB,+BAAA,CAAc,GAAA,EAAK,EAAE,OAAA,EAAS,yCAAyC,CAAA;AAAA,MACnF;AAEA,MAAA,OAAOe,wCAAA,CAAuB,MAAA,EAAQ,cAAA,EAAgB,OAAA,EAAS,QAAQ,CAAA;AAAA,IACzE,SAAS,KAAA,EAAO;AACd,MAAA,OAAOL,6BAAA,CAAY,OAAO,+BAA+B,CAAA;AAAA,IAC3D;AAAA,EACF;AACF,CAAC","file":"chunk-WX7XEIYG.cjs","sourcesContent":["import type { StorageSkillFileNode } from '@mastra/core/storage';\nimport { LocalSkillSource } from '@mastra/core/workspace';\n\nimport { HTTPException } from '../http-exception';\nimport {\n storedSkillIdPathParams,\n listStoredSkillsQuerySchema,\n createStoredSkillBodySchema,\n updateStoredSkillBodySchema,\n publishStoredSkillBodySchema,\n listStoredSkillsResponseSchema,\n getStoredSkillResponseSchema,\n createStoredSkillResponseSchema,\n updateStoredSkillResponseSchema,\n deleteStoredSkillResponseSchema,\n publishStoredSkillResponseSchema,\n} from '../schemas/stored-skills';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { toSlug, assertStoredResourceScope, getStoredResourceScope, scopeStoredResourceMetadata } from '../utils';\n\nimport {\n assertReadAccess,\n assertWriteAccess,\n getCallerAuthorId,\n matchesAuthorFilter,\n resolveAuthorFilter,\n} from './authorship';\nimport { isBuilderFeatureEnabled } from './editor-builder';\nimport { handleError } from './error';\nimport { enrichOrStripFavorites, prepareFavoritesEnrichment, stripFavoriteFields } from './favorites-enrichment';\n\n// ============================================================================\n// Helpers\n// ============================================================================\n\n/**\n * Well-known folder names in the skill file tree whose children represent\n * indexable path arrays (references, scripts, assets).\n */\nconst INDEXED_FOLDERS = ['references', 'scripts', 'assets'] as const;\n\n/**\n * Walks the `files` tree and collects relative file paths for each well-known\n * folder (references, scripts, assets). Returned arrays only include entries\n * that are not already present in any explicitly-provided arrays so callers\n * can pass both `files` and `references` without creating duplicates.\n */\nfunction extractIndexedPathsFromFiles(\n files: StorageSkillFileNode[] | undefined,\n existing: {\n references?: string[];\n scripts?: string[];\n assets?: string[];\n },\n): {\n references?: string[];\n scripts?: string[];\n assets?: string[];\n} {\n if (!files || files.length === 0) return {};\n\n // Find the root folder (first folder node, usually id=\"root\")\n const root = files.find(n => n.type === 'folder');\n if (!root?.children) return {};\n\n const result: Record = {};\n\n for (const folderName of INDEXED_FOLDERS) {\n const folder = root.children.find(n => n.type === 'folder' && n.name === folderName);\n if (!folder?.children || folder.children.length === 0) continue;\n\n const existingPaths = new Set(existing[folderName] ?? []);\n const paths: string[] = [...existingPaths];\n\n collectFilePaths(folder.children, folderName, existingPaths, paths);\n\n if (paths.length > 0) {\n result[folderName] = paths;\n }\n }\n\n return result;\n}\n\n/** Recursively collects file paths from a subtree, building relative paths. */\nfunction collectFilePaths(\n nodes: StorageSkillFileNode[],\n prefix: string,\n existingPaths: Set,\n out: string[],\n): void {\n for (const node of nodes) {\n if (node.type === 'file') {\n const relativePath = `${prefix}/${node.name}`;\n if (!existingPaths.has(relativePath)) {\n out.push(relativePath);\n }\n } else if (node.type === 'folder' && node.children) {\n collectFilePaths(node.children, `${prefix}/${node.name}`, existingPaths, out);\n }\n }\n}\n\n// ============================================================================\n// Route Definitions\n// ============================================================================\n\n/**\n * GET /stored/skills - List all stored skills\n */\nexport const LIST_STORED_SKILLS_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/skills',\n responseType: 'json',\n queryParamSchema: listStoredSkillsQuerySchema,\n responseSchema: listStoredSkillsResponseSchema,\n summary: 'List stored skills',\n description: 'Returns a paginated list of all skill configurations stored in the database',\n tags: ['Stored Skills'],\n requiresAuth: true,\n handler: async ({\n mastra,\n requestContext,\n page,\n perPage,\n orderBy,\n status,\n authorId,\n visibility,\n metadata,\n favoritedOnly,\n pinFavoritedFor,\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 skillStore = await storage.getStore('skills');\n if (!skillStore) {\n throw new HTTPException(500, { message: 'Skills storage domain is not available' });\n }\n\n const filter = resolveAuthorFilter({\n requestContext,\n resource: 'stored-skills',\n queryAuthorId: authorId,\n queryVisibility: visibility,\n });\n\n const scope = await getStoredResourceScope(mastra, requestContext);\n const scopedMetadata = scopeStoredResourceMetadata(metadata, scope);\n\n const callerId = getCallerAuthorId(requestContext);\n const favoritesEnabled = await isBuilderFeatureEnabled(mastra, 'favorites');\n const honoredStarredOnly = favoritesEnabled && favoritedOnly === true;\n const favoriteSubjectId = pinFavoritedFor ?? callerId;\n\n // `?favoritedOnly=true` flow: fetch caller's favorited IDs, restrict the list\n // to that set, then post-filter by visibility and recompute total/pages.\n if (honoredStarredOnly) {\n const effectivePerPage: number = perPage ?? 100;\n if (!favoriteSubjectId) {\n // Caller cannot have favorited anything without an identity.\n return { skills: [], total: 0, page, perPage: effectivePerPage, hasMore: false };\n }\n const favoritesStore = await storage.getStore('favorites');\n if (!favoritesStore) {\n throw new HTTPException(500, { message: 'Favorites storage domain is not available' });\n }\n const starredIds = await favoritesStore.listFavoritedIds({ userId: favoriteSubjectId, entityType: 'skill' });\n if (starredIds.length === 0) {\n return { skills: [], total: 0, page, perPage: effectivePerPage, hasMore: false };\n }\n const allMatching = await skillStore.listResolved({\n perPage: false,\n orderBy,\n status,\n authorId: filter.kind === 'exact' ? filter.authorId : undefined,\n metadata: scopedMetadata,\n entityIds: starredIds,\n });\n const visible = allMatching.skills.filter(record => matchesAuthorFilter(record, filter));\n const total = visible.length;\n const startIdx = effectivePerPage === 0 ? 0 : page * effectivePerPage;\n const endIdx = effectivePerPage === 0 ? 0 : startIdx + effectivePerPage;\n const sliced = effectivePerPage === 0 ? [] : visible.slice(startIdx, endIdx);\n const annotated = sliced.map(record => ({ ...record, isFavorited: true }));\n const hasMore = effectivePerPage > 0 && endIdx < total;\n return {\n skills: annotated,\n total,\n page,\n perPage: effectivePerPage,\n hasMore,\n };\n }\n\n const result = await skillStore.listResolved({\n page,\n perPage,\n orderBy,\n status,\n authorId: filter.kind === 'exact' ? filter.authorId : undefined,\n metadata: scopedMetadata,\n });\n\n // Post-filter to enforce ownership + visibility rules across all backends.\n // Storage adapters can only do an equality filter on authorId, so we apply\n // the ownedOrPublic / publicOnly logic here.\n // Note: `result.total` / `result.hasMore` reflect the storage-reported\n // count before this post-filter. For `unrestricted` / `exact` filters\n // nothing is removed; for `ownedOrPublic` / `publicOnly`, downstream UIs\n // should treat the filter as a view over the caller's scope — an\n // approximation is OK and preserves pagination math.\n const visibleSkills = result.skills.filter(record => matchesAuthorFilter(record, filter));\n\n if (!favoritesEnabled) {\n return { ...result, skills: visibleSkills.map(stripFavoriteFields) };\n }\n\n const enrichment = await prepareFavoritesEnrichment(\n mastra,\n requestContext,\n 'skill',\n visibleSkills.map(s => s.id),\n );\n const annotated = enrichment\n ? visibleSkills.map(record => ({ ...record, isFavorited: enrichment.starredIds.has(record.id) }))\n : visibleSkills.map(stripFavoriteFields);\n\n return { ...result, skills: annotated };\n } catch (error) {\n return handleError(error, 'Error listing stored skills');\n }\n },\n});\n\n/**\n * GET /stored/skills/:storedSkillId - Get a stored skill by ID\n */\nexport const GET_STORED_SKILL_ROUTE = createRoute({\n method: 'GET',\n path: '/stored/skills/:storedSkillId',\n responseType: 'json',\n pathParamSchema: storedSkillIdPathParams,\n responseSchema: getStoredSkillResponseSchema,\n summary: 'Get stored skill by ID',\n description: 'Returns a specific skill from storage by its unique identifier (resolved with active version config)',\n tags: ['Stored Skills'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, storedSkillId }) => {\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 skillStore = await storage.getStore('skills');\n if (!skillStore) {\n throw new HTTPException(500, { message: 'Skills storage domain is not available' });\n }\n\n const skill = await skillStore.getByIdResolved(storedSkillId);\n\n if (!skill) {\n throw new HTTPException(404, { message: `Stored skill with id ${storedSkillId} not found` });\n }\n assertStoredResourceScope(skill, await getStoredResourceScope(mastra, requestContext));\n\n assertReadAccess({ requestContext, resource: 'stored-skills', resourceId: storedSkillId, record: skill });\n\n return enrichOrStripFavorites(mastra, requestContext, 'skill', skill);\n } catch (error) {\n return handleError(error, 'Error getting stored skill');\n }\n },\n});\n\n/**\n * POST /stored/skills - Create a new stored skill\n */\nexport const CREATE_STORED_SKILL_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/skills',\n responseType: 'json',\n bodySchema: createStoredSkillBodySchema,\n responseSchema: createStoredSkillResponseSchema,\n summary: 'Create stored skill',\n description: 'Creates a new skill configuration in storage with the provided details',\n tags: ['Stored Skills'],\n requiresAuth: true,\n handler: async ({\n mastra,\n requestContext,\n id: providedId,\n name,\n description,\n instructions,\n license,\n compatibility,\n source,\n references,\n scripts,\n assets,\n files,\n metadata,\n visibility: bodyVisibility,\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 skillStore = await storage.getStore('skills');\n if (!skillStore) {\n throw new HTTPException(500, { message: 'Skills 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 skill ID from name. Please provide an explicit id.',\n });\n }\n\n // Check if skill with this ID already exists\n const existing = await skillStore.getById(id);\n if (existing) {\n throw new HTTPException(409, { message: `Skill with id ${id} already exists` });\n }\n\n // Force authorId from the authenticated caller; ignore any body-provided value.\n // No owner = always public (no auth / no user context).\n // With an owner, respect the client's choice, defaulting to 'private'.\n const authorId = getCallerAuthorId(requestContext) ?? undefined;\n const visibility: 'private' | 'public' = authorId ? (bodyVisibility ?? 'private') : 'public';\n\n // Derive references/scripts/assets path arrays from the files tree\n // so agents can discover them via skill_read even when only `files` is provided.\n const indexedPaths = extractIndexedPathsFromFiles(files, { references, scripts, assets });\n\n await skillStore.create({\n skill: {\n id,\n authorId,\n visibility,\n name,\n description,\n instructions,\n license,\n compatibility,\n source,\n references: indexedPaths.references ?? references,\n scripts: indexedPaths.scripts ?? scripts,\n assets: indexedPaths.assets ?? assets,\n files,\n metadata: scopeStoredResourceMetadata(metadata, await getStoredResourceScope(mastra, requestContext)),\n },\n });\n\n // Return the resolved skill (thin record + version config)\n const resolved = await skillStore.getByIdResolved(id);\n if (!resolved) {\n throw new HTTPException(500, { message: 'Failed to resolve created skill' });\n }\n\n return enrichOrStripFavorites(mastra, requestContext, 'skill', resolved);\n } catch (error) {\n return handleError(error, 'Error creating stored skill');\n }\n },\n});\n\n/**\n * PATCH /stored/skills/:storedSkillId - Update a stored skill\n */\nexport const UPDATE_STORED_SKILL_ROUTE = createRoute({\n method: 'PATCH',\n path: '/stored/skills/:storedSkillId',\n responseType: 'json',\n pathParamSchema: storedSkillIdPathParams,\n bodySchema: updateStoredSkillBodySchema,\n responseSchema: updateStoredSkillResponseSchema,\n summary: 'Update stored skill',\n description: 'Updates an existing skill in storage with the provided fields',\n tags: ['Stored Skills'],\n requiresAuth: true,\n handler: async ({\n mastra,\n requestContext,\n storedSkillId,\n // Entity-level fields\n authorId,\n visibility,\n // Config fields (snapshot-level)\n name,\n description,\n instructions,\n license,\n compatibility,\n source,\n references,\n scripts,\n assets,\n files,\n metadata,\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 skillStore = await storage.getStore('skills');\n if (!skillStore) {\n throw new HTTPException(500, { message: 'Skills storage domain is not available' });\n }\n\n // Check if skill exists. Skill metadata lives on the resolved snapshot.\n const existing = await skillStore.getByIdResolved(storedSkillId);\n if (!existing) {\n throw new HTTPException(404, { message: `Stored skill with id ${storedSkillId} 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-skills:write[:]` holder.\n assertWriteAccess({\n requestContext,\n resource: 'stored-skills',\n resourceId: storedSkillId,\n action: 'edit',\n record: existing,\n });\n\n // No owner = always public, regardless of what the client sent.\n const callerAuthorId = getCallerAuthorId(requestContext) ?? undefined;\n const resolvedVisibility = callerAuthorId ? visibility : visibility != null ? 'public' : undefined;\n\n // Derive references/scripts/assets path arrays from the files tree\n const indexedPaths = files ? extractIndexedPathsFromFiles(files, { references, scripts, assets }) : {};\n\n // Update the skill with both entity-level and config-level fields.\n // The storage layer handles separating these into record updates vs\n // new-version creation, but it uses `field in updates` to detect config\n // changes — so we must only include fields the caller actually sent.\n // Forwarding `undefined` keys would trigger a spurious version create\n // and pass `undefined` into the database driver.\n const update: Record = { id: storedSkillId };\n if (authorId !== undefined) update.authorId = authorId;\n if (resolvedVisibility !== undefined) update.visibility = resolvedVisibility;\n if (name !== undefined) update.name = name;\n if (description !== undefined) update.description = description;\n if (instructions !== undefined) update.instructions = instructions;\n if (license !== undefined) update.license = license;\n if (compatibility !== undefined) update.compatibility = compatibility;\n if (source !== undefined) update.source = source;\n const resolvedReferences = indexedPaths.references ?? references;\n const resolvedScripts = indexedPaths.scripts ?? scripts;\n const resolvedAssets = indexedPaths.assets ?? assets;\n if (resolvedReferences !== undefined) update.references = resolvedReferences;\n if (resolvedScripts !== undefined) update.scripts = resolvedScripts;\n if (resolvedAssets !== undefined) update.assets = resolvedAssets;\n if (files !== undefined) update.files = files;\n if (metadata !== undefined) {\n update.metadata = scopeStoredResourceMetadata({ ...(existing.metadata ?? {}), ...metadata }, scope);\n }\n\n await skillStore.update(update as Parameters[0]);\n\n // Return the resolved skill with the updated config\n const resolved = await skillStore.getByIdResolved(storedSkillId);\n if (!resolved) {\n throw new HTTPException(500, { message: 'Failed to resolve updated skill' });\n }\n\n return enrichOrStripFavorites(mastra, requestContext, 'skill', resolved);\n } catch (error) {\n return handleError(error, 'Error updating stored skill');\n }\n },\n});\n\n/**\n * DELETE /stored/skills/:storedSkillId - Delete a stored skill\n */\nexport const DELETE_STORED_SKILL_ROUTE = createRoute({\n method: 'DELETE',\n path: '/stored/skills/:storedSkillId',\n responseType: 'json',\n pathParamSchema: storedSkillIdPathParams,\n responseSchema: deleteStoredSkillResponseSchema,\n summary: 'Delete stored skill',\n description: 'Deletes a skill from storage by its unique identifier',\n tags: ['Stored Skills'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, storedSkillId }) => {\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 skillStore = await storage.getStore('skills');\n if (!skillStore) {\n throw new HTTPException(500, { message: 'Skills storage domain is not available' });\n }\n\n // Check if skill exists. Skill metadata lives on the resolved snapshot.\n const existing = await skillStore.getByIdResolved(storedSkillId);\n if (!existing) {\n throw new HTTPException(404, { message: `Stored skill with id ${storedSkillId} not found` });\n }\n assertStoredResourceScope(existing, await getStoredResourceScope(mastra, requestContext));\n\n // Throws 404 if the caller isn't the owner, admin, or `skills:delete[:]` holder.\n assertWriteAccess({\n requestContext,\n resource: 'stored-skills',\n resourceId: storedSkillId,\n action: 'delete',\n record: existing,\n });\n\n await skillStore.delete(storedSkillId);\n\n // Cascade: drop any favorite rows referencing this skill. Failure must not\n // abort the delete.\n try {\n const favoritesStore = await storage.getStore('favorites');\n await favoritesStore?.deleteFavoritesForEntity({ entityType: 'skill', entityId: storedSkillId });\n } catch (cascadeError) {\n mastra\n .getLogger?.()\n ?.warn?.('Failed to cascade-delete favorites for skill', { storedSkillId, error: cascadeError });\n }\n\n return {\n success: true,\n message: `Skill ${storedSkillId} deleted successfully`,\n };\n } catch (error) {\n return handleError(error, 'Error deleting stored skill');\n }\n },\n});\n\n/**\n * POST /stored/skills/:storedSkillId/publish - Publish a skill from filesystem\n * Walks the skill directory, hashes files into blob store, creates a new version\n * with the tree manifest, and sets activeVersionId.\n */\nexport const PUBLISH_STORED_SKILL_ROUTE = createRoute({\n method: 'POST',\n path: '/stored/skills/:storedSkillId/publish',\n responseType: 'json',\n pathParamSchema: storedSkillIdPathParams,\n bodySchema: publishStoredSkillBodySchema,\n responseSchema: publishStoredSkillResponseSchema,\n summary: 'Publish stored skill',\n description:\n 'Snapshots the skill directory from the filesystem into content-addressable blob storage, creates a new version with a tree manifest, and marks the skill as published',\n tags: ['Stored Skills'],\n requiresAuth: true,\n handler: async ({ mastra, requestContext, storedSkillId, skillPath }) => {\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 skillStore = await storage.getStore('skills');\n if (!skillStore) {\n throw new HTTPException(500, { message: 'Skills storage domain is not available' });\n }\n\n const blobStore = await storage.getStore('blobs');\n if (!blobStore) {\n throw new HTTPException(500, { message: 'Blob storage domain is not available' });\n }\n\n // Verify skill exists. Skill metadata lives on the resolved snapshot.\n const existing = await skillStore.getByIdResolved(storedSkillId);\n if (!existing) {\n throw new HTTPException(404, { message: `Stored skill with id ${storedSkillId} not found` });\n }\n assertStoredResourceScope(existing, await getStoredResourceScope(mastra, requestContext));\n\n // Throws 404 if the caller isn't the owner, admin, or `stored-skills:write[:]` holder.\n assertWriteAccess({\n requestContext,\n resource: 'stored-skills',\n resourceId: storedSkillId,\n action: 'edit',\n record: existing,\n });\n\n // Validate skillPath to prevent path traversal\n const path = await import('node:path');\n const fs = await import('node:fs/promises');\n const resolvedPath = path.default.resolve(skillPath);\n const allowedBase = path.default.resolve(process.env.SKILLS_BASE_DIR || process.cwd());\n if (!resolvedPath.startsWith(allowedBase + path.default.sep) && resolvedPath !== allowedBase) {\n throw new HTTPException(400, {\n message: `skillPath must be within the allowed directory: ${allowedBase}`,\n });\n }\n\n // Verify the source directory exists and contains a SKILL.md before attempting\n // to publish, so callers get a 400 with context instead of a raw 500/ENOENT.\n try {\n const stat = await fs.stat(resolvedPath);\n if (!stat.isDirectory()) {\n throw new HTTPException(400, { message: `skillPath is not a directory: ${resolvedPath}` });\n }\n } catch (err) {\n if (err instanceof HTTPException) throw err;\n if ((err as NodeJS.ErrnoException)?.code === 'ENOENT') {\n throw new HTTPException(400, {\n message: `skillPath does not exist on the server filesystem: ${resolvedPath}. Create the skill directory (with a SKILL.md) before publishing, or use a skill that was materialized to disk.`,\n });\n }\n throw err;\n }\n try {\n await fs.stat(path.default.join(resolvedPath, 'SKILL.md'));\n } catch (err) {\n if ((err as NodeJS.ErrnoException)?.code === 'ENOENT') {\n throw new HTTPException(400, {\n message: `skillPath is missing SKILL.md: ${resolvedPath}`,\n });\n }\n throw err;\n }\n\n // Use LocalSkillSource to read from the server filesystem\n const source = new LocalSkillSource();\n const { publishSkillFromSource } = await import('@mastra/core/workspace');\n\n const { snapshot, tree, files } = await publishSkillFromSource(source, resolvedPath, blobStore);\n\n // Strip undefined keys from the snapshot before passing to update(). The\n // storage layer treats \"field present\" as \"field changed\"; forwarding\n // undefined would overwrite populated columns with undefined and trip\n // NOT NULL / \"undefined cannot be passed as argument\" errors in\n // adapters that bind args raw (libsql, pg).\n const snapshotUpdate: Record = {};\n for (const [key, value] of Object.entries(snapshot)) {\n if (value !== undefined) snapshotUpdate[key] = value;\n }\n\n // Update the skill with new version data + tree + UI-facing file tree.\n // `files` is the nested folder/file structure shown in the editor; without\n // it the column would stay null and the UI would render an empty tree.\n await skillStore.update({\n id: storedSkillId,\n ...snapshotUpdate,\n tree,\n files,\n status: 'published',\n });\n\n // Point activeVersionId to the newly created version\n const latestVersion = await skillStore.getLatestVersion(storedSkillId);\n if (latestVersion) {\n await skillStore.update({\n id: storedSkillId,\n activeVersionId: latestVersion.id,\n });\n }\n\n const resolved = await skillStore.getByIdResolved(storedSkillId);\n if (!resolved) {\n throw new HTTPException(500, { message: 'Failed to resolve skill after publish' });\n }\n\n return enrichOrStripFavorites(mastra, requestContext, 'skill', resolved);\n } catch (error) {\n return handleError(error, 'Error publishing stored skill');\n }\n },\n});\n"]}