@mastra/server 1.57.0-alpha.1 → 1.57.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/_types/@internal_core/dist/storage/index.d.ts +2 -0
  3. package/dist/_types/@internal_voice/dist/_types/@internal_core/dist/request-context/index.d.ts +4 -1
  4. package/dist/{a2a-CE7HKP5V.cjs → a2a-DKnwIgiw.cjs} +2 -2
  5. package/dist/{a2a-CE7HKP5V.cjs.map → a2a-DKnwIgiw.cjs.map} +1 -1
  6. package/dist/{a2a-_3LYIc9y.js → a2a-uPi5sPwb.js} +2 -2
  7. package/dist/{a2a-_3LYIc9y.js.map → a2a-uPi5sPwb.js.map} +1 -1
  8. package/dist/{agent-versions-DC1Rp5EP.js → agent-versions-Bsrpa_zb.js} +2 -2
  9. package/dist/{agent-versions-DC1Rp5EP.js.map → agent-versions-Bsrpa_zb.js.map} +1 -1
  10. package/dist/{agent-versions-DhkWMz0z.cjs → agent-versions-CdQGF-3e.cjs} +2 -2
  11. package/dist/{agent-versions-DhkWMz0z.cjs.map → agent-versions-CdQGF-3e.cjs.map} +1 -1
  12. package/dist/{agents-DD4PJgsF.js → agents-CYvun9iI.js} +12 -7
  13. package/dist/agents-CYvun9iI.js.map +1 -0
  14. package/dist/{agents-B9ofSVSn.cjs → agents-Dk2qoJi_.cjs} +12 -7
  15. package/dist/agents-Dk2qoJi_.cjs.map +1 -0
  16. package/dist/{api-schema-manifest-Ba-Ssw4H.cjs → api-schema-manifest-7-NC9Dyc.cjs} +2 -2
  17. package/dist/{api-schema-manifest-Ba-Ssw4H.cjs.map → api-schema-manifest-7-NC9Dyc.cjs.map} +1 -1
  18. package/dist/{api-schema-manifest-DbTP-DpV.js → api-schema-manifest-C5hpdIE_.js} +2 -2
  19. package/dist/{api-schema-manifest-DbTP-DpV.js.map → api-schema-manifest-C5hpdIE_.js.map} +1 -1
  20. package/dist/{builder-registry-C_PysvMI.cjs → builder-registry-BoaXBdm_.cjs} +2 -2
  21. package/dist/{builder-registry-C_PysvMI.cjs.map → builder-registry-BoaXBdm_.cjs.map} +1 -1
  22. package/dist/{builder-registry-DaPvPspl.js → builder-registry-DE5w7bNk.js} +2 -2
  23. package/dist/{builder-registry-DaPvPspl.js.map → builder-registry-DE5w7bNk.js.map} +1 -1
  24. package/dist/{dist-DRyzA92e.js → dist-B1RiUqwz.js} +30 -8
  25. package/dist/{dist-DRyzA92e.js.map → dist-B1RiUqwz.js.map} +1 -1
  26. package/dist/{dist-DhFw0bEW.cjs → dist-BvR1YpT5.cjs} +30 -8
  27. package/dist/{dist-DhFw0bEW.cjs.map → dist-BvR1YpT5.cjs.map} +1 -1
  28. package/dist/docs/SKILL.md +1 -1
  29. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  30. package/dist/docs/references/reference-server-routes.md +13 -0
  31. package/dist/{editor-builder-ByNr3nc9.cjs → editor-builder-BW4nlDcX.cjs} +2 -2
  32. package/dist/{editor-builder-ByNr3nc9.cjs.map → editor-builder-BW4nlDcX.cjs.map} +1 -1
  33. package/dist/{editor-builder-DZRQf2UD.cjs → editor-builder-CWTGCtNu.cjs} +2 -2
  34. package/dist/{editor-builder-DZRQf2UD.cjs.map → editor-builder-CWTGCtNu.cjs.map} +1 -1
  35. package/dist/{editor-builder-CW9Tcqg1.js → editor-builder-Ct2nIbum.js} +2 -2
  36. package/dist/{editor-builder-CW9Tcqg1.js.map → editor-builder-Ct2nIbum.js.map} +1 -1
  37. package/dist/{editor-builder-XFcH8gX0.js → editor-builder-fKbRRlK_.js} +2 -2
  38. package/dist/{editor-builder-XFcH8gX0.js.map → editor-builder-fKbRRlK_.js.map} +1 -1
  39. package/dist/{observability-new-endpoints-DFBDedGH.cjs → observability-new-endpoints-Dk3oatL8.cjs} +3 -1
  40. package/dist/observability-new-endpoints-Dk3oatL8.cjs.map +1 -0
  41. package/dist/{observability-new-endpoints-CCyqX1Ra.js → observability-new-endpoints-YK2DjZto.js} +3 -1
  42. package/dist/observability-new-endpoints-YK2DjZto.js.map +1 -0
  43. package/dist/{processor-providers-BmOA_jeU.js → processor-providers-DBhZC6-4.js} +3 -2
  44. package/dist/processor-providers-DBhZC6-4.js.map +1 -0
  45. package/dist/{processor-providers-DGBNerTY.cjs → processor-providers-DHvTA9AL.cjs} +3 -2
  46. package/dist/processor-providers-DHvTA9AL.cjs.map +1 -0
  47. package/dist/{processors-05Z4P9eW.js → processors-88oJ_4J-.js} +7 -4
  48. package/dist/processors-88oJ_4J-.js.map +1 -0
  49. package/dist/{processors-BirBp7z3.cjs → processors-D6lRjS0e.cjs} +7 -4
  50. package/dist/processors-D6lRjS0e.cjs.map +1 -0
  51. package/dist/{routes-CN8wYsyr.js → routes-CRoTKPvQ.js} +5 -5
  52. package/dist/{routes-CN8wYsyr.js.map → routes-CRoTKPvQ.js.map} +1 -1
  53. package/dist/{routes-2WgTU1wN.cjs → routes-hSY4wTeS.cjs} +5 -5
  54. package/dist/{routes-2WgTU1wN.cjs.map → routes-hSY4wTeS.cjs.map} +1 -1
  55. package/dist/{scorer-versions-BoAERQxp.js → scorer-versions-BA8N488c.js} +2 -2
  56. package/dist/{scorer-versions-BoAERQxp.js.map → scorer-versions-BA8N488c.js.map} +1 -1
  57. package/dist/{scorer-versions-DX81YG5X.cjs → scorer-versions-DpmAJKsY.cjs} +2 -2
  58. package/dist/{scorer-versions-DX81YG5X.cjs.map → scorer-versions-DpmAJKsY.cjs.map} +1 -1
  59. package/dist/server/handlers/a2a.cjs +1 -1
  60. package/dist/server/handlers/a2a.js +1 -1
  61. package/dist/server/handlers/agent-builder.cjs +3 -3
  62. package/dist/server/handlers/agent-builder.js +3 -3
  63. package/dist/server/handlers/agent-versions.cjs +2 -2
  64. package/dist/server/handlers/agent-versions.d.ts +224 -112
  65. package/dist/server/handlers/agent-versions.d.ts.map +1 -1
  66. package/dist/server/handlers/agent-versions.js +2 -2
  67. package/dist/server/handlers/agents.cjs +3 -3
  68. package/dist/server/handlers/agents.d.ts +56 -28
  69. package/dist/server/handlers/agents.d.ts.map +1 -1
  70. package/dist/server/handlers/agents.js +3 -3
  71. package/dist/server/handlers/builder-registry.cjs +1 -1
  72. package/dist/server/handlers/builder-registry.js +1 -1
  73. package/dist/server/handlers/editor-builder.cjs +1 -1
  74. package/dist/server/handlers/editor-builder.js +1 -1
  75. package/dist/server/handlers/favorites-enrichment.cjs +1 -1
  76. package/dist/server/handlers/favorites-enrichment.js +1 -1
  77. package/dist/server/handlers/mcp-client-versions.cjs +2 -2
  78. package/dist/server/handlers/mcp-client-versions.js +2 -2
  79. package/dist/server/handlers/observability-new-endpoints.cjs +1 -1
  80. package/dist/server/handlers/observability-new-endpoints.js +1 -1
  81. package/dist/server/handlers/observability.cjs +1 -1
  82. package/dist/server/handlers/observability.js +1 -1
  83. package/dist/server/handlers/processor-providers.cjs +1 -1
  84. package/dist/server/handlers/processor-providers.d.ts +4 -2
  85. package/dist/server/handlers/processor-providers.d.ts.map +1 -1
  86. package/dist/server/handlers/processor-providers.js +1 -1
  87. package/dist/server/handlers/processors.cjs +17 -2
  88. package/dist/server/handlers/processors.cjs.map +1 -1
  89. package/dist/server/handlers/processors.d.ts +6 -2
  90. package/dist/server/handlers/processors.d.ts.map +1 -1
  91. package/dist/server/handlers/processors.js +17 -2
  92. package/dist/server/handlers/processors.js.map +1 -1
  93. package/dist/server/handlers/prompt-block-versions.cjs +2 -2
  94. package/dist/server/handlers/prompt-block-versions.js +2 -2
  95. package/dist/server/handlers/schedules.d.ts +16 -16
  96. package/dist/server/handlers/scorer-versions.cjs +2 -2
  97. package/dist/server/handlers/scorer-versions.js +2 -2
  98. package/dist/server/handlers/stored-agent-favorites.cjs +3 -3
  99. package/dist/server/handlers/stored-agent-favorites.js +3 -3
  100. package/dist/server/handlers/stored-agents.cjs +3 -3
  101. package/dist/server/handlers/stored-agents.d.ts +224 -56
  102. package/dist/server/handlers/stored-agents.d.ts.map +1 -1
  103. package/dist/server/handlers/stored-agents.js +3 -3
  104. package/dist/server/handlers/stored-mcp-clients.cjs +2 -2
  105. package/dist/server/handlers/stored-mcp-clients.js +2 -2
  106. package/dist/server/handlers/stored-prompt-blocks.cjs +2 -2
  107. package/dist/server/handlers/stored-prompt-blocks.js +2 -2
  108. package/dist/server/handlers/stored-scorers.cjs +2 -2
  109. package/dist/server/handlers/stored-scorers.js +2 -2
  110. package/dist/server/handlers/stored-skill-favorites.cjs +3 -3
  111. package/dist/server/handlers/stored-skill-favorites.js +3 -3
  112. package/dist/server/handlers/stored-skills.cjs +3 -3
  113. package/dist/server/handlers/stored-skills.js +3 -3
  114. package/dist/server/handlers/stored-workspaces.cjs +1 -1
  115. package/dist/server/handlers/stored-workspaces.js +1 -1
  116. package/dist/server/handlers/system.cjs +1 -1
  117. package/dist/server/handlers/system.js +1 -1
  118. package/dist/server/handlers/tools.cjs +2 -2
  119. package/dist/server/handlers/tools.js +2 -2
  120. package/dist/server/handlers/workflows.cjs +2 -2
  121. package/dist/server/handlers/workflows.js +2 -2
  122. package/dist/server/handlers.cjs +1 -1
  123. package/dist/server/handlers.js +1 -1
  124. package/dist/server/schemas/agent-versions.d.ts +140 -0
  125. package/dist/server/schemas/agent-versions.d.ts.map +1 -1
  126. package/dist/server/schemas/agents.d.ts +60 -20
  127. package/dist/server/schemas/agents.d.ts.map +1 -1
  128. package/dist/server/schemas/index.cjs +8 -8
  129. package/dist/server/schemas/index.js +8 -8
  130. package/dist/server/schemas/processor-providers.d.ts +2 -0
  131. package/dist/server/schemas/processor-providers.d.ts.map +1 -1
  132. package/dist/server/schemas/processors.d.ts +4 -0
  133. package/dist/server/schemas/processors.d.ts.map +1 -1
  134. package/dist/server/schemas/schedules.d.ts +5 -5
  135. package/dist/server/schemas/stored-agents.d.ts +296 -0
  136. package/dist/server/schemas/stored-agents.d.ts.map +1 -1
  137. package/dist/server/server-adapter/index.cjs +2 -2
  138. package/dist/server/server-adapter/index.js +2 -2
  139. package/dist/server/server-adapter/routes/processor-providers.d.ts +4 -2
  140. package/dist/server/server-adapter/routes/processor-providers.d.ts.map +1 -1
  141. package/dist/server/server-adapter/routes/processors.d.ts +6 -2
  142. package/dist/server/server-adapter/routes/processors.d.ts.map +1 -1
  143. package/dist/{stored-agents-GBSl2bkv.js → stored-agents-D8ar1Pn7.js} +3 -2
  144. package/dist/stored-agents-D8ar1Pn7.js.map +1 -0
  145. package/dist/{stored-agents-DR_L2wPJ.cjs → stored-agents-DKd89v5z.cjs} +3 -2
  146. package/dist/stored-agents-DKd89v5z.cjs.map +1 -0
  147. package/dist/{stored-scorers-0eeoiKkg.js → stored-scorers-BIKumDRO.js} +2 -2
  148. package/dist/{stored-scorers-0eeoiKkg.js.map → stored-scorers-BIKumDRO.js.map} +1 -1
  149. package/dist/{stored-scorers-CMHNFquG.cjs → stored-scorers-_dqFdh-G.cjs} +2 -2
  150. package/dist/{stored-scorers-CMHNFquG.cjs.map → stored-scorers-_dqFdh-G.cjs.map} +1 -1
  151. package/dist/{utils-qxLrCsRx.js → utils-BUK03Frl.js} +3 -2
  152. package/dist/{utils-qxLrCsRx.js.map → utils-BUK03Frl.js.map} +1 -1
  153. package/dist/{utils-xsPNtHk8.cjs → utils-wESuBh27.cjs} +3 -2
  154. package/dist/{utils-xsPNtHk8.cjs.map → utils-wESuBh27.cjs.map} +1 -1
  155. package/package.json +6 -6
  156. package/dist/agents-B9ofSVSn.cjs.map +0 -1
  157. package/dist/agents-DD4PJgsF.js.map +0 -1
  158. package/dist/observability-new-endpoints-CCyqX1Ra.js.map +0 -1
  159. package/dist/observability-new-endpoints-DFBDedGH.cjs.map +0 -1
  160. package/dist/processor-providers-BmOA_jeU.js.map +0 -1
  161. package/dist/processor-providers-DGBNerTY.cjs.map +0 -1
  162. package/dist/processors-05Z4P9eW.js.map +0 -1
  163. package/dist/processors-BirBp7z3.cjs.map +0 -1
  164. package/dist/stored-agents-DR_L2wPJ.cjs.map +0 -1
  165. package/dist/stored-agents-GBSl2bkv.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"builder-registry-DaPvPspl.js","names":[],"sources":["../src/server/schemas/builder-registry.ts","../src/server/handlers/builder-registry.ts"],"sourcesContent":["/**\n * Builder Registry Schemas\n *\n * Schemas for the Agent Builder skill registry routes. These are distinct from\n * the workspace skills.sh proxy schemas because:\n * - Builder routes are not scoped to a workspace.\n * - Builder install does not accept a `mount` field.\n * - Builder install body carries visibility + the resolved registry id.\n * - Builder install response returns the created stored skill id.\n *\n * The upstream skills.sh proxy response shapes are reused via the shared\n * `skillsShSearchResponseSchema`, `skillsShListResponseSchema`, and\n * `skillsShPreviewResponseSchema` since the wire shape from skills.sh is\n * registry-independent.\n */\n\nimport { z } from 'zod/v4';\n\n// =============================================================================\n// Registry list\n// =============================================================================\n\n/** Single entry in the registries list. */\nexport const builderRegistryEntrySchema = z.object({\n id: z.literal('skills-sh').describe('Stable registry identifier'),\n enabled: z.boolean().describe('Whether this registry is enabled in the running deployment'),\n label: z.string().describe('Human-readable registry name'),\n});\n\n/** Response for `GET /editor/builder/registries`. */\nexport const builderRegistriesResponseSchema = z.object({\n registries: z.array(builderRegistryEntrySchema),\n});\n\n// =============================================================================\n// Search / popular / preview\n// =============================================================================\n\n/** Path params used by every per-registry route. */\nexport const builderRegistryPathParams = z.object({\n registryId: z.string().describe('Registry identifier (e.g. \"skills-sh\")'),\n});\n\nexport const builderRegistrySearchQuerySchema = z.object({\n q: z.string().describe('Search query'),\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n});\n\nexport const builderRegistryPopularQuerySchema = z\n .object({\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n offset: z.coerce\n .number()\n .int()\n .min(0)\n .optional()\n .default(0)\n .describe('Offset for pagination (must be a multiple of `limit`)'),\n })\n .refine(args => args.offset % args.limit === 0, {\n message: 'offset must be a multiple of limit (the upstream registry pages by `limit`)',\n path: ['offset'],\n });\n\nexport const builderRegistryPreviewQuerySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n path: z.string().describe('Skill name within repo'),\n});\n\n// =============================================================================\n// Install\n// =============================================================================\n\n/**\n * Body for `POST /editor/builder/registries/:registryId/install`.\n *\n * Visibility behaves like the standard stored-skill create flow: optional,\n * defaults to private when the caller is authenticated.\n */\nexport const builderRegistryInstallBodySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n skillName: z.string().describe('Skill name from the registry'),\n visibility: z.enum(['private', 'public']).optional().describe('Visibility for the new stored skill'),\n});\n\n/** Response for the install route. Mirrors stored-skill identity fields. */\nexport const builderRegistryInstallResponseSchema = z.object({\n storedSkillId: z.string().describe('Id of the newly created stored skill'),\n name: z.string().describe('Resolved skill name'),\n filesWritten: z.number().describe('Number of files materialized into the skill version snapshot'),\n});\n\nexport type BuilderRegistryEntry = z.infer<typeof builderRegistryEntrySchema>;\nexport type BuilderRegistriesResponse = z.infer<typeof builderRegistriesResponseSchema>;\nexport type BuilderRegistryInstallBody = z.infer<typeof builderRegistryInstallBodySchema>;\nexport type BuilderRegistryInstallResponse = z.infer<typeof builderRegistryInstallResponseSchema>;\n","/**\n * Builder Registry Handlers\n *\n * Routes that let admins browse and install skills from configured external\n * registries (currently just skills.sh) directly into the Builder's stored\n * skills DB. Distinct from the workspace skills.sh routes, which write to a\n * workspace filesystem and never touch storage.\n *\n * Registry availability is driven by `AgentBuilderOptions.registries`. When\n * the requested registry is disabled (or the builder is missing entirely),\n * the routes 404 instead of leaking the surface.\n */\n\nimport type { Mastra } from '@mastra/core';\nimport type { StorageSkillFileNode } from '@mastra/core/storage';\n\nimport { HTTPException } from '../http-exception';\nimport {\n builderRegistriesResponseSchema,\n builderRegistryInstallBodySchema,\n builderRegistryInstallResponseSchema,\n builderRegistryPathParams,\n builderRegistryPopularQuerySchema,\n builderRegistryPreviewQuerySchema,\n builderRegistrySearchQuerySchema,\n} from '../schemas/builder-registry';\nimport {\n skillsShListResponseSchema,\n skillsShPreviewResponseSchema,\n skillsShSearchResponseSchema,\n} from '../schemas/workspace';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { toSlug } from '../utils';\nimport { getCallerAuthorId } from './authorship';\nimport { handleError } from './error';\nimport {\n assertSafeFilePath,\n assertSafeSkillName,\n fetchSkillFiles,\n getPopularSkillsSh,\n previewSkillsSh,\n searchSkillsSh,\n} from './skills-sh-shared';\n\n// =============================================================================\n// Registry resolution\n// =============================================================================\n\n/** Stable identifiers + display labels for every supported registry. */\nconst REGISTRY_LABELS: Record<string, string> = {\n 'skills-sh': 'skills.sh',\n};\n\ninterface RegistryStatus {\n id: 'skills-sh';\n enabled: boolean;\n label: string;\n}\n\n/**\n * Resolve which registries are enabled for the running deployment by reading\n * the builder's `registries` config. Returns a list with all known registries\n * (so the frontend can render an empty/disabled state) plus their enabled\n * flag.\n */\nasync function resolveRegistries(mastra: Mastra): Promise<RegistryStatus[]> {\n const editor = mastra.getEditor();\n if (!editor || typeof editor.resolveBuilder !== 'function') {\n return [{ id: 'skills-sh', enabled: false, label: REGISTRY_LABELS['skills-sh']! }];\n }\n const builder = await editor.resolveBuilder();\n const registries = builder?.getRegistries?.();\n return [\n {\n id: 'skills-sh',\n enabled: registries?.skillsSh?.enabled === true,\n label: REGISTRY_LABELS['skills-sh']!,\n },\n ];\n}\n\n/**\n * Hard-gate: throws 404 when the requested registry is unknown or disabled.\n * Mirrors `requireBuilderFeature` semantics — no surface leak for OFF registries.\n */\nasync function requireEnabledRegistry(mastra: Mastra, registryId: string): Promise<void> {\n const list = await resolveRegistries(mastra);\n const match = list.find(r => r.id === registryId);\n if (!match || !match.enabled) {\n throw new HTTPException(404, { message: 'Registry not found' });\n }\n}\n\n// =============================================================================\n// File-tree helpers\n// =============================================================================\n\n/**\n * Convert a flat list of `{ path, content, encoding }` entries into the\n * `StorageSkillFileNode` tree shape expected by the stored-skills create path.\n *\n * Each path is validated via `assertSafeFilePath` to prevent traversal from\n * upstream-controlled responses. Folder nodes are created on demand.\n */\nfunction buildFileTree(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): StorageSkillFileNode[] {\n const root: StorageSkillFileNode[] = [];\n\n for (const file of files) {\n const safePath = assertSafeFilePath(file.path);\n const segments = safePath.split('/').filter(Boolean);\n if (segments.length === 0) continue;\n\n let cursor = root;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n let folder = cursor.find(node => node.type === 'folder' && node.name === segment);\n if (!folder) {\n folder = { name: segment, type: 'folder', children: [] };\n cursor.push(folder);\n }\n if (!folder.children) folder.children = [];\n cursor = folder.children;\n }\n\n const fileName = segments[segments.length - 1]!;\n const content = file.encoding === 'base64' ? Buffer.from(file.content, 'base64').toString('utf-8') : file.content;\n cursor.push({ name: fileName, type: 'file', content });\n }\n\n return root;\n}\n\n/**\n * Locally-bound SKILL.md frontmatter parser.\n *\n * Mirrors `parseSkillSnapshotFromFiles` from `@mastra/core/workspace`, but\n * inlined here because the server package's `@mastra/core` peer floor\n * (>=1.32.0) predates that helper. Once the floor is bumped to a release\n * containing the helper, this can be replaced by the shared core import.\n *\n * Only SKILL.md is consulted — frontmatter is split from the body using a\n * minimal YAML key:value reader sufficient for the fields registries\n * actually use (name, description). The body is everything after the\n * second `---` line, trimmed.\n */\ntype ParsedSkillSnapshot = {\n name?: string;\n description?: string;\n instructions: string;\n};\n\nfunction parseSkillSnapshot(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): ParsedSkillSnapshot | null {\n const skillMd = files.find(f => f.path === 'SKILL.md');\n if (!skillMd) return null;\n\n const raw =\n skillMd.encoding === 'base64' ? Buffer.from(skillMd.content, 'base64').toString('utf-8') : skillMd.content;\n\n const fmMatch = raw.match(/^---\\r?\\n([\\s\\S]*?)\\r?\\n---\\r?\\n?([\\s\\S]*)$/);\n if (!fmMatch) {\n return { instructions: raw.trim() };\n }\n\n const fmBlock = fmMatch[1] ?? '';\n const body = fmMatch[2] ?? '';\n const frontmatter: Record<string, string> = {};\n for (const line of fmBlock.split(/\\r?\\n/)) {\n const m = line.match(/^([A-Za-z0-9_-]+)\\s*:\\s*(.*)$/);\n if (!m) continue;\n const key = m[1];\n const value = m[2] ?? '';\n if (!key) continue;\n // Strip surrounding quotes, leave the rest as-is. Registry SKILL.md\n // frontmatter is consistently flat string fields in practice.\n frontmatter[key] = value.trim().replace(/^[\"'](.*)[\"']$/, '$1');\n }\n\n return {\n name: frontmatter.name,\n description: frontmatter.description,\n instructions: body.trim(),\n };\n}\n\n// =============================================================================\n// Routes\n// =============================================================================\n\n/**\n * GET /editor/builder/registries\n *\n * Lists every known registry and whether it's enabled in this deployment.\n * Used by the Builder UI to decide whether to show the \"Browse registry\"\n * entry point at all.\n */\nexport const LIST_BUILDER_REGISTRIES_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries',\n responseType: 'json',\n responseSchema: builderRegistriesResponseSchema,\n summary: 'List available skill registries',\n description: 'Returns the configured external skill registries and their enabled state.',\n tags: ['Editor'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra }) => {\n try {\n const registries = await resolveRegistries(mastra);\n return { registries };\n } catch (error) {\n return handleError(error, 'Error listing builder registries');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/search\n *\n * Proxies a search query to the underlying registry. Currently only\n * registryId=\"skills-sh\" is supported.\n */\nexport const BUILDER_REGISTRY_SEARCH_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/search',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistrySearchQuerySchema,\n responseSchema: skillsShSearchResponseSchema,\n summary: 'Search skills in a registry',\n description: 'Proxies a search request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, q, limit }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await searchSkillsSh({ q, limit });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error searching registry');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/popular\n *\n * Returns the most popular skills in a registry.\n */\nexport const BUILDER_REGISTRY_POPULAR_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/popular',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPopularQuerySchema,\n responseSchema: skillsShListResponseSchema,\n summary: 'Get popular skills from a registry',\n description: 'Proxies a popular-skills request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, limit, offset }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await getPopularSkillsSh({ limit, offset });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching popular skills');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/preview\n *\n * Returns the rendered SKILL.md content for a single skill in the registry.\n */\nexport const BUILDER_REGISTRY_PREVIEW_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/preview',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPreviewQuerySchema,\n responseSchema: skillsShPreviewResponseSchema,\n summary: 'Preview a skill from a registry',\n description: 'Fetches the SKILL.md content for a single skill in the configured registry.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, owner, repo, path: skillName }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await previewSkillsSh({ owner, repo, skillName });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching skill preview');\n }\n },\n});\n\n/**\n * POST /editor/builder/registries/:registryId/install\n *\n * Fetches the full file tree for a skill from the registry, parses the\n * SKILL.md frontmatter for name/description, and persists everything as a\n * new stored skill. The registry origin is recorded under `metadata.origin`\n * so the UI can surface \"imported from skills.sh\" badges and re-resolve the\n * source later.\n *\n * Collisions (a stored skill with the derived id already exists) return 409\n * so the UI can offer an \"Open existing\" link instead of silently\n * overwriting.\n */\nexport const BUILDER_REGISTRY_INSTALL_ROUTE = createRoute({\n method: 'POST',\n path: '/editor/builder/registries/:registryId/install',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n bodySchema: builderRegistryInstallBodySchema,\n responseSchema: builderRegistryInstallResponseSchema,\n summary: 'Install a registry skill into stored skills',\n description: 'Fetches a skill from the configured registry and persists it as a new stored skill.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:write',\n handler: async ({ mastra, requestContext, registryId, owner, repo, skillName, visibility: bodyVisibility }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\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 // Pull files from the registry\n const result = await fetchSkillFiles(owner, repo, skillName);\n if (!result || result.files.length === 0) {\n throw new HTTPException(404, {\n message: `Could not find skill \"${skillName}\" in ${owner}/${repo}.`,\n });\n }\n\n const safeSkillId = assertSafeSkillName(result.skillId);\n const files = buildFileTree(result.files);\n\n // Parse SKILL.md frontmatter into structured fields. Splitting\n // frontmatter (name/description) from the markdown body keeps the\n // body as the agent-facing `instructions` instead of polluting it\n // with raw YAML metadata. SKILL.md missing or unparseable simply\n // yields a null snapshot — registry-provided values then fill in.\n const snapshot = parseSkillSnapshot(result.files);\n\n const resolvedName = snapshot?.name ?? safeSkillId;\n const description = snapshot?.description ?? `Imported from ${owner}/${repo}`;\n const id = toSlug(resolvedName) || safeSkillId;\n\n if (!id) {\n throw new HTTPException(400, {\n message: 'Could not derive skill ID from registry skill metadata.',\n });\n }\n\n // Reject collisions instead of silently overwriting; UI offers \"Open existing\".\n const existing = await skillStore.getById(id);\n if (existing) {\n throw new HTTPException(409, {\n message: `Skill with id \"${id}\" already exists.`,\n // Surface the existing id so the client can deep-link.\n cause: { storedSkillId: id },\n });\n }\n\n // Match the standard create flow: no caller = always public, otherwise default private.\n const authorId = getCallerAuthorId(requestContext) ?? undefined;\n const visibility: 'private' | 'public' = authorId ? (bodyVisibility ?? 'private') : 'public';\n\n // Use the SKILL.md body (post-frontmatter) as instructions. Frontmatter\n // values are already lifted into structured columns above, so re-storing\n // them in `instructions` would both duplicate metadata and feed YAML\n // into the agent's prompt. Fall back to description when no usable body\n // exists so `resolved.snapshot.instructions` stays non-empty.\n const instructions = snapshot?.instructions?.trim() ? snapshot.instructions : description;\n\n await skillStore.create({\n skill: {\n id,\n authorId,\n visibility,\n name: resolvedName,\n description,\n instructions,\n files,\n metadata: {\n origin: {\n type: 'skills-sh',\n owner,\n repo,\n skillName,\n },\n },\n },\n });\n\n return {\n storedSkillId: id,\n name: resolvedName,\n filesWritten: result.files.length,\n };\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error installing registry skill');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,6BAA6B,EAAE,OAAO;CACjD,IAAI,EAAE,QAAQ,WAAW,CAAC,CAAC,SAAS,4BAA4B;CAChE,SAAS,EAAE,QAAQ,CAAC,CAAC,SAAS,4DAA4D;CAC1F,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,8BAA8B;AAC3D,CAAC;;AAGD,MAAa,kCAAkC,EAAE,OAAO,EACtD,YAAY,EAAE,MAAM,0BAA0B,EAChD,CAAC;;AAOD,MAAa,4BAA4B,EAAE,OAAO,EAChD,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS,0CAAwC,EAC1E,CAAC;AAED,MAAa,mCAAmC,EAAE,OAAO;CACvD,GAAG,EAAE,OAAO,CAAC,CAAC,SAAS,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AKH,IAAI,MADmB,WAAW,QAAQ,EAAE,GAE1C,MAAM,IAAI,cAAc,KAAK;IAC3B,SAAS,kBAAkB,GAAG;IAE9B,OAAO,EAAE,eAAe,GAAG;GAC7B,CAAC;GAIH,MAAM,WAAW,kBAAkB,cAAc,KAAK,KAAA;GACtD,MAAM,aAAmC,WAAY,kBAAkB,YAAa;GAOpF,MAAM,eAAe,UAAU,cAAc,KAAK,IAAI,SAAS,eAAe;GAE9E,MAAM,WAAW,OAAO,EACtB,OAAO;IACL;IACA;IACA;IACA,MAAM;IACN;IACA;IACA;IACA,UAAU,EACR,QAAQ;KACN,MAAM;KACN;KACA;KACA;IACF,EACF;GACF,EACF,CAAC;GAED,OAAO;IACL,eAAe;IACf,MAAM;IACN,cAAc,OAAO,MAAM;GAC7B;EACF,SAAS,OAAO;GACd,IAAI,iBAAiB,eAAe,MAAM;GAC1C,OAAO,YAAY,OAAO,iCAAiC;EAC7D;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"builder-registry-DE5w7bNk.js","names":[],"sources":["../src/server/schemas/builder-registry.ts","../src/server/handlers/builder-registry.ts"],"sourcesContent":["/**\n * Builder Registry Schemas\n *\n * Schemas for the Agent Builder skill registry routes. These are distinct from\n * the workspace skills.sh proxy schemas because:\n * - Builder routes are not scoped to a workspace.\n * - Builder install does not accept a `mount` field.\n * - Builder install body carries visibility + the resolved registry id.\n * - Builder install response returns the created stored skill id.\n *\n * The upstream skills.sh proxy response shapes are reused via the shared\n * `skillsShSearchResponseSchema`, `skillsShListResponseSchema`, and\n * `skillsShPreviewResponseSchema` since the wire shape from skills.sh is\n * registry-independent.\n */\n\nimport { z } from 'zod/v4';\n\n// =============================================================================\n// Registry list\n// =============================================================================\n\n/** Single entry in the registries list. */\nexport const builderRegistryEntrySchema = z.object({\n id: z.literal('skills-sh').describe('Stable registry identifier'),\n enabled: z.boolean().describe('Whether this registry is enabled in the running deployment'),\n label: z.string().describe('Human-readable registry name'),\n});\n\n/** Response for `GET /editor/builder/registries`. */\nexport const builderRegistriesResponseSchema = z.object({\n registries: z.array(builderRegistryEntrySchema),\n});\n\n// =============================================================================\n// Search / popular / preview\n// =============================================================================\n\n/** Path params used by every per-registry route. */\nexport const builderRegistryPathParams = z.object({\n registryId: z.string().describe('Registry identifier (e.g. \"skills-sh\")'),\n});\n\nexport const builderRegistrySearchQuerySchema = z.object({\n q: z.string().describe('Search query'),\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n});\n\nexport const builderRegistryPopularQuerySchema = z\n .object({\n limit: z.coerce.number().int().min(1).max(100).optional().default(10).describe('Maximum number of results (1-100)'),\n offset: z.coerce\n .number()\n .int()\n .min(0)\n .optional()\n .default(0)\n .describe('Offset for pagination (must be a multiple of `limit`)'),\n })\n .refine(args => args.offset % args.limit === 0, {\n message: 'offset must be a multiple of limit (the upstream registry pages by `limit`)',\n path: ['offset'],\n });\n\nexport const builderRegistryPreviewQuerySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n path: z.string().describe('Skill name within repo'),\n});\n\n// =============================================================================\n// Install\n// =============================================================================\n\n/**\n * Body for `POST /editor/builder/registries/:registryId/install`.\n *\n * Visibility behaves like the standard stored-skill create flow: optional,\n * defaults to private when the caller is authenticated.\n */\nexport const builderRegistryInstallBodySchema = z.object({\n owner: z.string().describe('GitHub repository owner'),\n repo: z.string().describe('GitHub repository name'),\n skillName: z.string().describe('Skill name from the registry'),\n visibility: z.enum(['private', 'public']).optional().describe('Visibility for the new stored skill'),\n});\n\n/** Response for the install route. Mirrors stored-skill identity fields. */\nexport const builderRegistryInstallResponseSchema = z.object({\n storedSkillId: z.string().describe('Id of the newly created stored skill'),\n name: z.string().describe('Resolved skill name'),\n filesWritten: z.number().describe('Number of files materialized into the skill version snapshot'),\n});\n\nexport type BuilderRegistryEntry = z.infer<typeof builderRegistryEntrySchema>;\nexport type BuilderRegistriesResponse = z.infer<typeof builderRegistriesResponseSchema>;\nexport type BuilderRegistryInstallBody = z.infer<typeof builderRegistryInstallBodySchema>;\nexport type BuilderRegistryInstallResponse = z.infer<typeof builderRegistryInstallResponseSchema>;\n","/**\n * Builder Registry Handlers\n *\n * Routes that let admins browse and install skills from configured external\n * registries (currently just skills.sh) directly into the Builder's stored\n * skills DB. Distinct from the workspace skills.sh routes, which write to a\n * workspace filesystem and never touch storage.\n *\n * Registry availability is driven by `AgentBuilderOptions.registries`. When\n * the requested registry is disabled (or the builder is missing entirely),\n * the routes 404 instead of leaking the surface.\n */\n\nimport type { Mastra } from '@mastra/core';\nimport type { StorageSkillFileNode } from '@mastra/core/storage';\n\nimport { HTTPException } from '../http-exception';\nimport {\n builderRegistriesResponseSchema,\n builderRegistryInstallBodySchema,\n builderRegistryInstallResponseSchema,\n builderRegistryPathParams,\n builderRegistryPopularQuerySchema,\n builderRegistryPreviewQuerySchema,\n builderRegistrySearchQuerySchema,\n} from '../schemas/builder-registry';\nimport {\n skillsShListResponseSchema,\n skillsShPreviewResponseSchema,\n skillsShSearchResponseSchema,\n} from '../schemas/workspace';\nimport { createRoute } from '../server-adapter/routes/route-builder';\nimport { toSlug } from '../utils';\nimport { getCallerAuthorId } from './authorship';\nimport { handleError } from './error';\nimport {\n assertSafeFilePath,\n assertSafeSkillName,\n fetchSkillFiles,\n getPopularSkillsSh,\n previewSkillsSh,\n searchSkillsSh,\n} from './skills-sh-shared';\n\n// =============================================================================\n// Registry resolution\n// =============================================================================\n\n/** Stable identifiers + display labels for every supported registry. */\nconst REGISTRY_LABELS: Record<string, string> = {\n 'skills-sh': 'skills.sh',\n};\n\ninterface RegistryStatus {\n id: 'skills-sh';\n enabled: boolean;\n label: string;\n}\n\n/**\n * Resolve which registries are enabled for the running deployment by reading\n * the builder's `registries` config. Returns a list with all known registries\n * (so the frontend can render an empty/disabled state) plus their enabled\n * flag.\n */\nasync function resolveRegistries(mastra: Mastra): Promise<RegistryStatus[]> {\n const editor = mastra.getEditor();\n if (!editor || typeof editor.resolveBuilder !== 'function') {\n return [{ id: 'skills-sh', enabled: false, label: REGISTRY_LABELS['skills-sh']! }];\n }\n const builder = await editor.resolveBuilder();\n const registries = builder?.getRegistries?.();\n return [\n {\n id: 'skills-sh',\n enabled: registries?.skillsSh?.enabled === true,\n label: REGISTRY_LABELS['skills-sh']!,\n },\n ];\n}\n\n/**\n * Hard-gate: throws 404 when the requested registry is unknown or disabled.\n * Mirrors `requireBuilderFeature` semantics — no surface leak for OFF registries.\n */\nasync function requireEnabledRegistry(mastra: Mastra, registryId: string): Promise<void> {\n const list = await resolveRegistries(mastra);\n const match = list.find(r => r.id === registryId);\n if (!match || !match.enabled) {\n throw new HTTPException(404, { message: 'Registry not found' });\n }\n}\n\n// =============================================================================\n// File-tree helpers\n// =============================================================================\n\n/**\n * Convert a flat list of `{ path, content, encoding }` entries into the\n * `StorageSkillFileNode` tree shape expected by the stored-skills create path.\n *\n * Each path is validated via `assertSafeFilePath` to prevent traversal from\n * upstream-controlled responses. Folder nodes are created on demand.\n */\nfunction buildFileTree(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): StorageSkillFileNode[] {\n const root: StorageSkillFileNode[] = [];\n\n for (const file of files) {\n const safePath = assertSafeFilePath(file.path);\n const segments = safePath.split('/').filter(Boolean);\n if (segments.length === 0) continue;\n\n let cursor = root;\n for (let i = 0; i < segments.length - 1; i++) {\n const segment = segments[i]!;\n let folder = cursor.find(node => node.type === 'folder' && node.name === segment);\n if (!folder) {\n folder = { name: segment, type: 'folder', children: [] };\n cursor.push(folder);\n }\n if (!folder.children) folder.children = [];\n cursor = folder.children;\n }\n\n const fileName = segments[segments.length - 1]!;\n const content = file.encoding === 'base64' ? Buffer.from(file.content, 'base64').toString('utf-8') : file.content;\n cursor.push({ name: fileName, type: 'file', content });\n }\n\n return root;\n}\n\n/**\n * Locally-bound SKILL.md frontmatter parser.\n *\n * Mirrors `parseSkillSnapshotFromFiles` from `@mastra/core/workspace`, but\n * inlined here because the server package's `@mastra/core` peer floor\n * (>=1.32.0) predates that helper. Once the floor is bumped to a release\n * containing the helper, this can be replaced by the shared core import.\n *\n * Only SKILL.md is consulted — frontmatter is split from the body using a\n * minimal YAML key:value reader sufficient for the fields registries\n * actually use (name, description). The body is everything after the\n * second `---` line, trimmed.\n */\ntype ParsedSkillSnapshot = {\n name?: string;\n description?: string;\n instructions: string;\n};\n\nfunction parseSkillSnapshot(\n files: Array<{ path: string; content: string; encoding: 'utf-8' | 'base64' }>,\n): ParsedSkillSnapshot | null {\n const skillMd = files.find(f => f.path === 'SKILL.md');\n if (!skillMd) return null;\n\n const raw =\n skillMd.encoding === 'base64' ? Buffer.from(skillMd.content, 'base64').toString('utf-8') : skillMd.content;\n\n const fmMatch = raw.match(/^---\\r?\\n([\\s\\S]*?)\\r?\\n---\\r?\\n?([\\s\\S]*)$/);\n if (!fmMatch) {\n return { instructions: raw.trim() };\n }\n\n const fmBlock = fmMatch[1] ?? '';\n const body = fmMatch[2] ?? '';\n const frontmatter: Record<string, string> = {};\n for (const line of fmBlock.split(/\\r?\\n/)) {\n const m = line.match(/^([A-Za-z0-9_-]+)\\s*:\\s*(.*)$/);\n if (!m) continue;\n const key = m[1];\n const value = m[2] ?? '';\n if (!key) continue;\n // Strip surrounding quotes, leave the rest as-is. Registry SKILL.md\n // frontmatter is consistently flat string fields in practice.\n frontmatter[key] = value.trim().replace(/^[\"'](.*)[\"']$/, '$1');\n }\n\n return {\n name: frontmatter.name,\n description: frontmatter.description,\n instructions: body.trim(),\n };\n}\n\n// =============================================================================\n// Routes\n// =============================================================================\n\n/**\n * GET /editor/builder/registries\n *\n * Lists every known registry and whether it's enabled in this deployment.\n * Used by the Builder UI to decide whether to show the \"Browse registry\"\n * entry point at all.\n */\nexport const LIST_BUILDER_REGISTRIES_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries',\n responseType: 'json',\n responseSchema: builderRegistriesResponseSchema,\n summary: 'List available skill registries',\n description: 'Returns the configured external skill registries and their enabled state.',\n tags: ['Editor'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra }) => {\n try {\n const registries = await resolveRegistries(mastra);\n return { registries };\n } catch (error) {\n return handleError(error, 'Error listing builder registries');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/search\n *\n * Proxies a search query to the underlying registry. Currently only\n * registryId=\"skills-sh\" is supported.\n */\nexport const BUILDER_REGISTRY_SEARCH_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/search',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistrySearchQuerySchema,\n responseSchema: skillsShSearchResponseSchema,\n summary: 'Search skills in a registry',\n description: 'Proxies a search request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, q, limit }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await searchSkillsSh({ q, limit });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error searching registry');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/popular\n *\n * Returns the most popular skills in a registry.\n */\nexport const BUILDER_REGISTRY_POPULAR_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/popular',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPopularQuerySchema,\n responseSchema: skillsShListResponseSchema,\n summary: 'Get popular skills from a registry',\n description: 'Proxies a popular-skills request to the configured registry to avoid CORS issues.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, limit, offset }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await getPopularSkillsSh({ limit, offset });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching popular skills');\n }\n },\n});\n\n/**\n * GET /editor/builder/registries/:registryId/preview\n *\n * Returns the rendered SKILL.md content for a single skill in the registry.\n */\nexport const BUILDER_REGISTRY_PREVIEW_ROUTE = createRoute({\n method: 'GET',\n path: '/editor/builder/registries/:registryId/preview',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n queryParamSchema: builderRegistryPreviewQuerySchema,\n responseSchema: skillsShPreviewResponseSchema,\n summary: 'Preview a skill from a registry',\n description: 'Fetches the SKILL.md content for a single skill in the configured registry.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:read',\n handler: async ({ mastra, registryId, owner, repo, path: skillName }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n return await previewSkillsSh({ owner, repo, skillName });\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error fetching skill preview');\n }\n },\n});\n\n/**\n * POST /editor/builder/registries/:registryId/install\n *\n * Fetches the full file tree for a skill from the registry, parses the\n * SKILL.md frontmatter for name/description, and persists everything as a\n * new stored skill. The registry origin is recorded under `metadata.origin`\n * so the UI can surface \"imported from skills.sh\" badges and re-resolve the\n * source later.\n *\n * Collisions (a stored skill with the derived id already exists) return 409\n * so the UI can offer an \"Open existing\" link instead of silently\n * overwriting.\n */\nexport const BUILDER_REGISTRY_INSTALL_ROUTE = createRoute({\n method: 'POST',\n path: '/editor/builder/registries/:registryId/install',\n responseType: 'json',\n pathParamSchema: builderRegistryPathParams,\n bodySchema: builderRegistryInstallBodySchema,\n responseSchema: builderRegistryInstallResponseSchema,\n summary: 'Install a registry skill into stored skills',\n description: 'Fetches a skill from the configured registry and persists it as a new stored skill.',\n tags: ['Editor', 'Skills'],\n requiresAuth: true,\n requiresPermission: 'stored-skills:write',\n handler: async ({ mastra, requestContext, registryId, owner, repo, skillName, visibility: bodyVisibility }) => {\n try {\n await requireEnabledRegistry(mastra, registryId);\n\n const storage = mastra.getStorage();\n if (!storage) {\n throw new HTTPException(500, { message: 'Storage is not configured' });\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 // Pull files from the registry\n const result = await fetchSkillFiles(owner, repo, skillName);\n if (!result || result.files.length === 0) {\n throw new HTTPException(404, {\n message: `Could not find skill \"${skillName}\" in ${owner}/${repo}.`,\n });\n }\n\n const safeSkillId = assertSafeSkillName(result.skillId);\n const files = buildFileTree(result.files);\n\n // Parse SKILL.md frontmatter into structured fields. Splitting\n // frontmatter (name/description) from the markdown body keeps the\n // body as the agent-facing `instructions` instead of polluting it\n // with raw YAML metadata. SKILL.md missing or unparseable simply\n // yields a null snapshot — registry-provided values then fill in.\n const snapshot = parseSkillSnapshot(result.files);\n\n const resolvedName = snapshot?.name ?? safeSkillId;\n const description = snapshot?.description ?? `Imported from ${owner}/${repo}`;\n const id = toSlug(resolvedName) || safeSkillId;\n\n if (!id) {\n throw new HTTPException(400, {\n message: 'Could not derive skill ID from registry skill metadata.',\n });\n }\n\n // Reject collisions instead of silently overwriting; UI offers \"Open existing\".\n const existing = await skillStore.getById(id);\n if (existing) {\n throw new HTTPException(409, {\n message: `Skill with id \"${id}\" already exists.`,\n // Surface the existing id so the client can deep-link.\n cause: { storedSkillId: id },\n });\n }\n\n // Match the standard create flow: no caller = always public, otherwise default private.\n const authorId = getCallerAuthorId(requestContext) ?? undefined;\n const visibility: 'private' | 'public' = authorId ? (bodyVisibility ?? 'private') : 'public';\n\n // Use the SKILL.md body (post-frontmatter) as instructions. Frontmatter\n // values are already lifted into structured columns above, so re-storing\n // them in `instructions` would both duplicate metadata and feed YAML\n // into the agent's prompt. Fall back to description when no usable body\n // exists so `resolved.snapshot.instructions` stays non-empty.\n const instructions = snapshot?.instructions?.trim() ? snapshot.instructions : description;\n\n await skillStore.create({\n skill: {\n id,\n authorId,\n visibility,\n name: resolvedName,\n description,\n instructions,\n files,\n metadata: {\n origin: {\n type: 'skills-sh',\n owner,\n repo,\n skillName,\n },\n },\n },\n });\n\n return {\n storedSkillId: id,\n name: resolvedName,\n filesWritten: result.files.length,\n };\n } catch (error) {\n if (error instanceof HTTPException) throw error;\n return handleError(error, 'Error installing registry skill');\n }\n },\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAa,6BAA6B,EAAE,OAAO;CACjD,IAAI,EAAE,QAAQ,WAAW,CAAC,CAAC,SAAS,4BAA4B;CAChE,SAAS,EAAE,QAAQ,CAAC,CAAC,SAAS,4DAA4D;CAC1F,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,8BAA8B;AAC3D,CAAC;;AAGD,MAAa,kCAAkC,EAAE,OAAO,EACtD,YAAY,EAAE,MAAM,0BAA0B,EAChD,CAAC;;AAOD,MAAa,4BAA4B,EAAE,OAAO,EAChD,YAAY,EAAE,OAAO,CAAC,CAAC,SAAS,0CAAwC,EAC1E,CAAC;AAED,MAAa,mCAAmC,EAAE,OAAO;CACvD,GAAG,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;CACrC,OAAO,EAAE,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,mCAAmC;AACpH,CAAC;AAED,MAAa,oCAAoC,EAC9C,OAAO;CACN,OAAO,EAAE,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,SAAS,mCAAmC;CAClH,QAAQ,EAAE,OACP,OAAO,CAAC,CACR,IAAI,CAAC,CACL,IAAI,CAAC,CAAC,CACN,SAAS,CAAC,CACV,QAAQ,CAAC,CAAC,CACV,SAAS,uDAAuD;AACrE,CAAC,CAAC,CACD,QAAO,SAAQ,KAAK,SAAS,KAAK,UAAU,GAAG;CAC9C,SAAS;CACT,MAAM,CAAC,QAAQ;AACjB,CAAC;AAEH,MAAa,oCAAoC,EA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
5961
5961
  //#endregion
5962
- //#region ../memory/dist/src-DvQWV6nH.js
5962
+ //#region ../memory/dist/src-DmmFrMMF.js
5963
5963
  var __defProp$4 = Object.defineProperty;
5964
5964
  var __exportAll = (all, no_symbols) => {
5965
5965
  let target = {};
@@ -29631,6 +29631,14 @@ var ObservationalMemory = class ObservationalMemory {
29631
29631
  */
29632
29632
  locks = /* @__PURE__ */ new Map();
29633
29633
  /**
29634
+ * Initial record lookup/creation promises keyed by the effective storage scope.
29635
+ * Concurrent callers share the full read-or-create operation so a stale read
29636
+ * cannot create another generation-zero record after the first insert finishes.
29637
+ * Entries are removed after both success and failure so later calls always
29638
+ * re-read storage and transient failures can be retried.
29639
+ */
29640
+ recordInitializations = /* @__PURE__ */ new Map();
29641
+ /**
29634
29642
  * Acquire a lock for the given key, execute the callback, then release.
29635
29643
  * If a lock is already held, waits for it to be released before acquiring.
29636
29644
  */
@@ -29991,10 +29999,14 @@ var ObservationalMemory = class ObservationalMemory {
29991
29999
  */
29992
30000
  async getOrCreateRecord(threadId, resourceId) {
29993
30001
  const ids = this.getStorageIds(threadId, resourceId);
29994
- let record = await this.storage.getObservationalMemory(ids.threadId, ids.resourceId);
29995
- if (!record) {
30002
+ const initializationKey = ids.threadId === null ? `resource:${ids.resourceId}` : `thread:${ids.threadId}`;
30003
+ const pendingInitialization = this.recordInitializations.get(initializationKey);
30004
+ if (pendingInitialization) return pendingInitialization;
30005
+ const initialization = Promise.resolve().then(async () => {
30006
+ const record = await this.storage.getObservationalMemory(ids.threadId, ids.resourceId);
30007
+ if (record) return record;
29996
30008
  const observedTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
29997
- record = await this.storage.initializeObservationalMemory({
30009
+ return this.storage.initializeObservationalMemory({
29998
30010
  threadId: ids.threadId,
29999
30011
  resourceId: ids.resourceId,
30000
30012
  scope: this.scope,
@@ -30005,8 +30017,13 @@ var ObservationalMemory = class ObservationalMemory {
30005
30017
  },
30006
30018
  observedTimezone
30007
30019
  });
30020
+ });
30021
+ this.recordInitializations.set(initializationKey, initialization);
30022
+ try {
30023
+ return await initialization;
30024
+ } finally {
30025
+ if (this.recordInitializations.get(initializationKey) === initialization) this.recordInitializations.delete(initializationKey);
30008
30026
  }
30009
- return record;
30010
30027
  }
30011
30028
  /**
30012
30029
  * Get current config snapshot for observation markers.
@@ -32347,6 +32364,11 @@ function filterSystemReminderMessages(messages, includeSystemReminders) {
32347
32364
  if (includeSystemReminders) return messages;
32348
32365
  return messages.filter((message) => !isSystemReminderMessage(message));
32349
32366
  }
32367
+ function isTransientSignalMessage(message) {
32368
+ if (message.role !== "signal" || !isRecord(message.content)) return false;
32369
+ const metadata = message.content.metadata;
32370
+ return isRecord(metadata) && isRecord(metadata.signal) && !Array.isArray(metadata.signal) && metadata.signal.transient === true;
32371
+ }
32350
32372
  function normalizeObservationalMemoryConfig(config) {
32351
32373
  if (config === true) return { model: "google/gemini-2.5-flash" };
32352
32374
  if (config === false || config === void 0) return void 0;
@@ -32880,7 +32902,7 @@ ${workingMemory}`;
32880
32902
  async saveMessages({ messages, memoryConfig, observabilityContext }) {
32881
32903
  const span = this.createMemorySpan("save", observabilityContext, void 0, { messageCount: messages.length });
32882
32904
  try {
32883
- const updatedMessages = messages.filter((m) => m.role !== "system").map((m) => {
32905
+ const updatedMessages = messages.filter((m) => m.role !== "system" && !isTransientSignalMessage(m)).map((m) => {
32884
32906
  return this.updateMessageToHideWorkingMemoryV2(m);
32885
32907
  }).filter((m) => Boolean(m));
32886
32908
  const config = this.getMergedThreadConfig(memoryConfig);
@@ -33172,7 +33194,7 @@ ${workingMemory}`;
33172
33194
  */
33173
33195
  async persistMessages(messages) {
33174
33196
  if (messages.length === 0) return;
33175
- const persistableMessages = messages.filter((m) => m.role !== "system");
33197
+ const persistableMessages = messages.filter((m) => m.role !== "system" && !isTransientSignalMessage(m));
33176
33198
  if (persistableMessages.length === 0) return;
33177
33199
  await (await this.getMemoryStore()).saveMessages({ messages: persistableMessages });
33178
33200
  }
@@ -44492,4 +44514,4 @@ const agentBuilderWorkflows = {
44492
44514
  //#endregion
44493
44515
  export { agentBuilderWorkflows };
44494
44516
 
44495
- //# sourceMappingURL=dist-DRyzA92e.js.map
44517
+ //# sourceMappingURL=dist-B1RiUqwz.js.map