@agimon-ai/po-build 0.0.0-alpha.21 → 0.0.0-alpha.211

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 (92) hide show
  1. package/LICENSE +21 -149
  2. package/README.md +7 -7
  3. package/dist/constants/contributions.cjs +1 -1
  4. package/dist/constants/contributions.cjs.map +1 -1
  5. package/dist/constants/contributions.mjs +1 -1
  6. package/dist/constants/contributions.mjs.map +1 -1
  7. package/dist/constants/layout.cjs +1 -1
  8. package/dist/constants/layout.cjs.map +1 -1
  9. package/dist/constants/layout.d.mts +2 -2
  10. package/dist/constants/layout.d.mts.map +1 -1
  11. package/dist/constants/layout.mjs +1 -1
  12. package/dist/constants/layout.mjs.map +1 -1
  13. package/dist/services/browserFile/index.cjs.map +1 -1
  14. package/dist/services/browserFile/index.mjs.map +1 -1
  15. package/dist/services/contentProvenance/index.cjs +3 -0
  16. package/dist/services/contentProvenance/index.cjs.map +1 -0
  17. package/dist/services/contentProvenance/index.d.mts +10 -0
  18. package/dist/services/contentProvenance/index.d.mts.map +1 -0
  19. package/dist/services/contentProvenance/index.mjs +3 -0
  20. package/dist/services/contentProvenance/index.mjs.map +1 -0
  21. package/dist/services/filename/index.cjs.map +1 -1
  22. package/dist/services/filename/index.mjs.map +1 -1
  23. package/dist/services/generate/index.cjs +1 -0
  24. package/dist/services/generate/index.cjs.map +1 -1
  25. package/dist/services/generate/index.d.mts +3 -3
  26. package/dist/services/generate/index.d.mts.map +1 -1
  27. package/dist/services/generate/index.mjs +1 -0
  28. package/dist/services/generate/index.mjs.map +1 -1
  29. package/dist/services/generate/type.d.mts +2 -0
  30. package/dist/services/generate/type.d.mts.map +1 -1
  31. package/dist/services/identity/index.cjs.map +1 -1
  32. package/dist/services/identity/index.mjs.map +1 -1
  33. package/dist/services/renderClient/index.cjs +1 -1
  34. package/dist/services/renderClient/index.cjs.map +1 -1
  35. package/dist/services/renderClient/index.mjs +1 -1
  36. package/dist/services/renderClient/index.mjs.map +1 -1
  37. package/dist/services/renderEntry/index.cjs +4 -4
  38. package/dist/services/renderEntry/index.cjs.map +1 -1
  39. package/dist/services/renderEntry/index.d.mts.map +1 -1
  40. package/dist/services/renderEntry/index.mjs +4 -4
  41. package/dist/services/renderEntry/index.mjs.map +1 -1
  42. package/dist/services/renderMcpWidgets/index.cjs.map +1 -1
  43. package/dist/services/renderMcpWidgets/index.mjs.map +1 -1
  44. package/dist/services/resolveTarget/index.cjs +1 -1
  45. package/dist/services/resolveTarget/index.cjs.map +1 -1
  46. package/dist/services/resolveTarget/index.d.mts.map +1 -1
  47. package/dist/services/resolveTarget/index.mjs +1 -1
  48. package/dist/services/resolveTarget/index.mjs.map +1 -1
  49. package/dist/services/scan/index.cjs +1 -1
  50. package/dist/services/scan/index.cjs.map +1 -1
  51. package/dist/services/scan/index.d.mts.map +1 -1
  52. package/dist/services/scan/index.mjs +1 -1
  53. package/dist/services/scan/index.mjs.map +1 -1
  54. package/dist/services/segments/index.cjs.map +1 -1
  55. package/dist/services/segments/index.mjs.map +1 -1
  56. package/dist/services/serverContracts/index.cjs +1 -1
  57. package/dist/services/serverContracts/index.cjs.map +1 -1
  58. package/dist/services/serverContracts/index.mjs +1 -1
  59. package/dist/services/serverContracts/index.mjs.map +1 -1
  60. package/dist/services/serverContracts/type.d.mts +7 -0
  61. package/dist/services/serverContracts/type.d.mts.map +1 -1
  62. package/dist/services/syncManifest/index.cjs +1 -1
  63. package/dist/services/syncManifest/index.cjs.map +1 -1
  64. package/dist/services/syncManifest/index.d.mts.map +1 -1
  65. package/dist/services/syncManifest/index.mjs +1 -1
  66. package/dist/services/syncManifest/index.mjs.map +1 -1
  67. package/dist/services/syncManifest/type.d.mts +3 -0
  68. package/dist/services/syncManifest/type.d.mts.map +1 -1
  69. package/dist/services/tsdownPreset/index.cjs +1 -1
  70. package/dist/services/tsdownPreset/index.cjs.map +1 -1
  71. package/dist/services/tsdownPreset/index.d.mts +8 -2
  72. package/dist/services/tsdownPreset/index.d.mts.map +1 -1
  73. package/dist/services/tsdownPreset/index.mjs +1 -1
  74. package/dist/services/tsdownPreset/index.mjs.map +1 -1
  75. package/dist/services/unistylesBabel/index.cjs +1 -1
  76. package/dist/services/unistylesBabel/index.cjs.map +1 -1
  77. package/dist/services/unistylesBabel/index.mjs +1 -1
  78. package/dist/services/unistylesBabel/index.mjs.map +1 -1
  79. package/dist/services/webMetadata/index.cjs +3 -0
  80. package/dist/services/webMetadata/index.cjs.map +1 -0
  81. package/dist/services/webMetadata/index.mjs +3 -0
  82. package/dist/services/webMetadata/index.mjs.map +1 -0
  83. package/dist/services/webMetadata/type.d.mts +22 -0
  84. package/dist/services/webMetadata/type.d.mts.map +1 -0
  85. package/dist/services/writeGenerated/index.cjs.map +1 -1
  86. package/dist/services/writeGenerated/index.d.mts.map +1 -1
  87. package/dist/services/writeGenerated/index.mjs.map +1 -1
  88. package/dist/tsdown.cjs +1 -1
  89. package/dist/tsdown.d.mts +2 -1
  90. package/dist/tsdown.mjs +1 -1
  91. package/dist/types/extensionGraph.d.mts +1 -1
  92. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["SOURCE_EXTENSIONS","EXCLUDED_INFIXES","require_layout","parseFilename","lastDot","fileName","extension","parts","name","rest","part","last","platform","platforms"],"sources":["../../../src/services/filename/index.ts"],"sourcesContent":["import { EXCLUDED_INFIXES, SOURCE_EXTENSIONS } from '../../constants/layout';\n\n/** One filename split into the four things the grammar encodes. */\nexport interface ParsedFilename {\n /** The contribution's identity. */\n readonly name: string;\n /** The relationship target, such as the slot a fill names. */\n readonly target: string | undefined;\n /** The platform this file serves, or undefined when the filename names none. */\n readonly platform: string | undefined;\n readonly extension: string;\n}\n\n/**\n * Parses `{name}[.{target}][.{platform}].{ext}`.\n *\n * Right to left, because the platform set is closed and the target is not: a\n * dotted slot name such as `task.detail` would otherwise be ambiguous. A file\n * whose extension is not a source extension, or that carries an excluded\n * infix, returns undefined rather than an entry the caller has to filter.\n *\n * The one word a target may not be is a platform name for its own side, since\n * the last segment is read as a platform whenever it matches.\n *\n * A filename that names no platform still parses, with `platform: undefined`.\n * Requiring one is the scan's job, since only the scan knows whether the file\n * is public: a private `_lib` helper and an `api/` route sibling name none.\n */\nexport function parseFilename(fileName: string, platforms: readonly string[]): ParsedFilename | undefined {\n const lastDot = fileName.lastIndexOf('.');\n if (lastDot <= 0) return undefined;\n\n const extension = fileName.slice(lastDot + 1);\n if (!SOURCE_EXTENSIONS.includes(extension)) return undefined;\n\n const parts = fileName.slice(0, lastDot).split('.');\n const [name, ...rest] = parts;\n if (name === undefined || name === '') return undefined;\n if (parts.some((part) => EXCLUDED_INFIXES.includes(part))) return undefined;\n\n const last = rest[rest.length - 1];\n const platform = last !== undefined && platforms.includes(last) ? rest.pop() : undefined;\n\n return { name, target: rest.length > 0 ? rest.join('.') : undefined, platform, extension };\n}\n"],"mappings":"8CA4BA,SAAgBG,EAAc,EAAkB,EAA0D,CACxG,IAAMC,EAAUC,EAAS,YAAY,GAAG,EACxC,GAAID,GAAW,EAAG,OAElB,IAAME,EAAYD,EAAS,MAAMD,EAAU,CAAC,EAC5C,GAAI,CAACJ,EAAAA,kBAAkB,SAASM,CAAS,EAAG,OAE5C,IAAMC,EAAQF,EAAS,MAAM,EAAGD,CAAO,CAAC,CAAC,MAAM,GAAG,EAC5C,CAACI,EAAM,GAAGC,GAAQF,EAExB,GADIC,IAAS,IAAA,IAAaA,IAAS,IAC/BD,EAAM,KAAM,GAASN,EAAAA,iBAAiB,SAASS,CAAI,CAAC,EAAG,OAE3D,IAAMC,EAAOF,EAAKA,EAAK,OAAS,GAC1BG,EAAWD,IAAS,IAAA,IAAaE,EAAU,SAASF,CAAI,EAAIF,EAAK,IAAI,EAAI,IAAA,GAE/E,MAAO,CAAE,OAAM,OAAQA,EAAK,OAAS,EAAIA,EAAK,KAAK,GAAG,EAAI,IAAA,GAAW,WAAU,WAAU,CAC3F"}
1
+ {"version":3,"file":"index.cjs","names":["SOURCE_EXTENSIONS","EXCLUDED_INFIXES","require_layout","parseFilename","lastDot","fileName","extension","parts","name","rest","part","last","platform","platforms"],"sources":["../../../src/services/filename/index.ts"],"sourcesContent":["import { EXCLUDED_INFIXES, SOURCE_EXTENSIONS } from '../../constants/layout';\n\n/** One filename split into the four things the grammar encodes. */\nexport interface ParsedFilename {\n /** The contribution's identity. */\n readonly name: string;\n /** The relationship target, such as the slot a fill names. */\n readonly target: string | undefined;\n /** The platform this file serves, or undefined when the filename names none. */\n readonly platform: string | undefined;\n readonly extension: string;\n}\n\n/**\n * Parses `{name}[.{target}][.{platform}].{ext}`.\n *\n * Right to left, because the platform set is closed and the target is not: a\n * dotted slot name such as `task.detail` would otherwise be ambiguous. A file\n * whose extension is not a source extension, or that carries an excluded\n * infix, returns undefined rather than an entry the caller has to filter.\n *\n * The one word a target may not be is a platform name for its own side, since\n * the last segment is read as a platform whenever it matches.\n *\n * A filename that names no platform still parses, with `platform: undefined`.\n * Requiring one is the scan's job, since only the scan knows whether the file\n * is public: a private `_lib` helper and an `api/` route sibling name none.\n */\nexport function parseFilename(fileName: string, platforms: readonly string[]): ParsedFilename | undefined {\n const lastDot = fileName.lastIndexOf('.');\n if (lastDot <= 0) return undefined;\n\n const extension = fileName.slice(lastDot + 1);\n if (!SOURCE_EXTENSIONS.includes(extension)) return undefined;\n\n const parts = fileName.slice(0, lastDot).split('.');\n const [name, ...rest] = parts;\n if (name === undefined || name === '') return undefined;\n if (parts.some((part) => EXCLUDED_INFIXES.includes(part))) return undefined;\n\n const last = rest[rest.length - 1];\n const platform = last !== undefined && platforms.includes(last) ? rest.pop() : undefined;\n\n return { name, target: rest.length > 0 ? rest.join('.') : undefined, platform, extension };\n}\n"],"mappings":"A,8CA4BA,SAAgBG,EAAc,EAAkB,EAA0D,CACxG,IAAMC,EAAUC,EAAS,YAAY,GAAG,EACxC,GAAID,GAAW,EAAG,OAElB,IAAME,EAAYD,EAAS,MAAMD,EAAU,CAAC,EAC5C,GAAI,CAACJ,EAAAA,kBAAkB,SAASM,CAAS,EAAG,OAE5C,IAAMC,EAAQF,EAAS,MAAM,EAAGD,CAAO,CAAC,CAAC,MAAM,GAAG,EAC5C,CAACI,EAAM,GAAGC,GAAQF,EAExB,GADIC,IAAS,IAAA,IAAaA,IAAS,IAC/BD,EAAM,KAAM,GAASN,EAAAA,iBAAiB,SAASS,CAAI,CAAC,EAAG,OAE3D,IAAMC,EAAOF,EAAKA,EAAK,OAAS,GAC1BG,EAAWD,IAAS,IAAA,IAAaE,EAAU,SAASF,CAAI,EAAIF,EAAK,IAAI,EAAI,IAAA,GAE/E,MAAO,CAAE,OAAM,OAAQA,EAAK,OAAS,EAAIA,EAAK,KAAK,GAAG,EAAI,IAAA,GAAW,WAAU,WAAU,CAC3F,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["parseFilename","lastDot","fileName","extension","SOURCE_EXTENSIONS","parts","name","rest","EXCLUDED_INFIXES","part","last","platform","platforms"],"sources":["../../../src/services/filename/index.ts"],"sourcesContent":["import { EXCLUDED_INFIXES, SOURCE_EXTENSIONS } from '../../constants/layout';\n\n/** One filename split into the four things the grammar encodes. */\nexport interface ParsedFilename {\n /** The contribution's identity. */\n readonly name: string;\n /** The relationship target, such as the slot a fill names. */\n readonly target: string | undefined;\n /** The platform this file serves, or undefined when the filename names none. */\n readonly platform: string | undefined;\n readonly extension: string;\n}\n\n/**\n * Parses `{name}[.{target}][.{platform}].{ext}`.\n *\n * Right to left, because the platform set is closed and the target is not: a\n * dotted slot name such as `task.detail` would otherwise be ambiguous. A file\n * whose extension is not a source extension, or that carries an excluded\n * infix, returns undefined rather than an entry the caller has to filter.\n *\n * The one word a target may not be is a platform name for its own side, since\n * the last segment is read as a platform whenever it matches.\n *\n * A filename that names no platform still parses, with `platform: undefined`.\n * Requiring one is the scan's job, since only the scan knows whether the file\n * is public: a private `_lib` helper and an `api/` route sibling name none.\n */\nexport function parseFilename(fileName: string, platforms: readonly string[]): ParsedFilename | undefined {\n const lastDot = fileName.lastIndexOf('.');\n if (lastDot <= 0) return undefined;\n\n const extension = fileName.slice(lastDot + 1);\n if (!SOURCE_EXTENSIONS.includes(extension)) return undefined;\n\n const parts = fileName.slice(0, lastDot).split('.');\n const [name, ...rest] = parts;\n if (name === undefined || name === '') return undefined;\n if (parts.some((part) => EXCLUDED_INFIXES.includes(part))) return undefined;\n\n const last = rest[rest.length - 1];\n const platform = last !== undefined && platforms.includes(last) ? rest.pop() : undefined;\n\n return { name, target: rest.length > 0 ? rest.join('.') : undefined, platform, extension };\n}\n"],"mappings":"qFA4BA,SAAgBA,EAAc,EAAkB,EAA0D,CACxG,IAAMC,EAAUC,EAAS,YAAY,GAAG,EACxC,GAAID,GAAW,EAAG,OAElB,IAAME,EAAYD,EAAS,MAAMD,EAAU,CAAC,EAC5C,GAAI,CAACG,EAAkB,SAASD,CAAS,EAAG,OAE5C,IAAME,EAAQH,EAAS,MAAM,EAAGD,CAAO,CAAC,CAAC,MAAM,GAAG,EAC5C,CAACK,EAAM,GAAGC,GAAQF,EAExB,GADIC,IAAS,IAAA,IAAaA,IAAS,IAC/BD,EAAM,KAAM,GAASG,EAAiB,SAASC,CAAI,CAAC,EAAG,OAE3D,IAAMC,EAAOH,EAAKA,EAAK,OAAS,GAC1BI,EAAWD,IAAS,IAAA,IAAaE,EAAU,SAASF,CAAI,EAAIH,EAAK,IAAI,EAAI,IAAA,GAE/E,MAAO,CAAE,OAAM,OAAQA,EAAK,OAAS,EAAIA,EAAK,KAAK,GAAG,EAAI,IAAA,GAAW,WAAU,WAAU,CAC3F"}
1
+ {"version":3,"file":"index.mjs","names":["parseFilename","lastDot","fileName","extension","SOURCE_EXTENSIONS","parts","name","rest","EXCLUDED_INFIXES","part","last","platform","platforms"],"sources":["../../../src/services/filename/index.ts"],"sourcesContent":["import { EXCLUDED_INFIXES, SOURCE_EXTENSIONS } from '../../constants/layout';\n\n/** One filename split into the four things the grammar encodes. */\nexport interface ParsedFilename {\n /** The contribution's identity. */\n readonly name: string;\n /** The relationship target, such as the slot a fill names. */\n readonly target: string | undefined;\n /** The platform this file serves, or undefined when the filename names none. */\n readonly platform: string | undefined;\n readonly extension: string;\n}\n\n/**\n * Parses `{name}[.{target}][.{platform}].{ext}`.\n *\n * Right to left, because the platform set is closed and the target is not: a\n * dotted slot name such as `task.detail` would otherwise be ambiguous. A file\n * whose extension is not a source extension, or that carries an excluded\n * infix, returns undefined rather than an entry the caller has to filter.\n *\n * The one word a target may not be is a platform name for its own side, since\n * the last segment is read as a platform whenever it matches.\n *\n * A filename that names no platform still parses, with `platform: undefined`.\n * Requiring one is the scan's job, since only the scan knows whether the file\n * is public: a private `_lib` helper and an `api/` route sibling name none.\n */\nexport function parseFilename(fileName: string, platforms: readonly string[]): ParsedFilename | undefined {\n const lastDot = fileName.lastIndexOf('.');\n if (lastDot <= 0) return undefined;\n\n const extension = fileName.slice(lastDot + 1);\n if (!SOURCE_EXTENSIONS.includes(extension)) return undefined;\n\n const parts = fileName.slice(0, lastDot).split('.');\n const [name, ...rest] = parts;\n if (name === undefined || name === '') return undefined;\n if (parts.some((part) => EXCLUDED_INFIXES.includes(part))) return undefined;\n\n const last = rest[rest.length - 1];\n const platform = last !== undefined && platforms.includes(last) ? rest.pop() : undefined;\n\n return { name, target: rest.length > 0 ? rest.join('.') : undefined, platform, extension };\n}\n"],"mappings":"A,qFA4BA,SAAgBA,EAAc,EAAkB,EAA0D,CACxG,IAAMC,EAAUC,EAAS,YAAY,GAAG,EACxC,GAAID,GAAW,EAAG,OAElB,IAAME,EAAYD,EAAS,MAAMD,EAAU,CAAC,EAC5C,GAAI,CAACG,EAAkB,SAASD,CAAS,EAAG,OAE5C,IAAME,EAAQH,EAAS,MAAM,EAAGD,CAAO,CAAC,CAAC,MAAM,GAAG,EAC5C,CAACK,EAAM,GAAGC,GAAQF,EAExB,GADIC,IAAS,IAAA,IAAaA,IAAS,IAC/BD,EAAM,KAAM,GAASG,EAAiB,SAASC,CAAI,CAAC,EAAG,OAE3D,IAAMC,EAAOH,EAAKA,EAAK,OAAS,GAC1BI,EAAWD,IAAS,IAAA,IAAaE,EAAU,SAASF,CAAI,EAAIH,EAAK,IAAI,EAAI,IAAA,GAE/E,MAAO,CAAE,OAAM,OAAQA,EAAK,OAAS,EAAIA,EAAK,KAAK,GAAG,EAAI,IAAA,GAAW,WAAU,WAAU,CAC3F,C"}
@@ -1,3 +1,4 @@
1
1
  const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../constants/layout.cjs"),n=require("../scan/index.cjs"),r=require("../resolveTarget/index.cjs"),i=require("../renderClient/index.cjs"),a=require("../renderEntry/index.cjs"),o=require("../renderMcpWidgets/index.cjs"),s=require("../writeGenerated/index.cjs");let c=require("node:fs");c=e.__toESM(c,1);let l=require("node:path");l=e.__toESM(l,1);function u(e){return e.replace(/^@[^/]+\//u,``).replace(/^po-/u,``)}function d(e){let t=JSON.parse(c.default.readFileSync(l.default.join(e,`package.json`),`utf8`));if(typeof t.name!=`string`)throw Error(`${e}/package.json has no name`);return t.name}const f={server:a.renderServerEntry,web:a.renderWebEntry,native:a.renderNativeEntry,mcp:a.renderMcpEntry},p=t.GENERATED_ENTRY_FILENAMES;function m(e){let a=e.packageName??d(e.packageDir),m=e.pluginId??u(a),h=n.scanExtensions(e),g=[...h.notices],_=/* @__PURE__ */ new Map,v=[],y=e.target===`mcp`?o.renderMcpWidgets(h,a,t.GENERATED_DIR):void 0;y?.source!==void 0&&_.set(`${t.GENERATED_DIR}/mcp-ui.ts`,y.source);for(let e of h.entries)e.platform===void 0||t.BUILD_TARGET_PLATFORMS.includes(e.platform)||g.push({path:e.file,message:`'${e.platform}' is a forward-looking platform with no build target; this file is not emitted for server, web, native or mcp`});let b=h.notices.filter(e=>e.message===n.RETIRED_PLATFORM_NOTICE);if(b.length>0)throw Error(`${a}: ${n.RETIRED_PLATFORM_NOTICE}\n${b.map(e=>` ${e.path}`).join(`
2
+ `)}`);if(e.strictLayout!==!1&&h.notices.length>0)throw Error(`${a}: misplaced routed files (set strictLayout: false to report them as notices)\n${h.notices.map(e=>` ${e.path}: ${e.message}`).join(`
2
3
  `)}`);let x=e.target===void 0?[`server`,`web`,`native`]:[e.target];for(let e of x){let n=r.resolveTarget(h,e);if(g.push(...n.notices),n.contributions.length===0&&n.escapeHatches.length===0&&n.roots.length===0)continue;v.push(e);let i=f[e],o=i(n,{packageName:a,pluginId:m,root:h.root,entryDir:t.GENERATED_DIR,mcpWidgets:y?.declarations});_.set(`${t.GENERATED_DIR}/${p[e]}.ts`,o)}let S=e.target===void 0&&c.default.existsSync(l.default.join(e.packageDir,`src/types/apiRoutes.ts`)),C=v.includes(`web`),w=S&&C?i.renderApiClient(h,{packageName:a,pluginId:m,root:h.root,entryDir:t.GENERATED_DIR}):void 0;w!==void 0&&_.set(`${t.GENERATED_DIR}/${t.GENERATED_CLIENT_NAME}.ts`,w);let T=v.includes(`native`),E=S&&T?i.renderNativeApiClient(h,{packageName:a,pluginId:m,root:h.root,entryDir:t.GENERATED_DIR}):void 0;E!==void 0&&_.set(`${t.GENERATED_DIR}/${t.GENERATED_NATIVE_CLIENT_NAME}.ts`,E),S&&(C||T)&&w===void 0&&E===void 0&&g.push({path:t.API_ROUTES_MODULE,message:`declares API routes, but no (backend)/api/<base-path>/ folder says where they are mounted`});let D=e.target===void 0?t.GENERATED_ENTRY_NAMES.filter(t=>t!==`mcp`||!c.default.existsSync(l.default.join(e.packageDir,`tsdown.mcp.config.ts`))).map(e=>`${t.GENERATED_DIR}/${e}.ts`):[`${t.GENERATED_DIR}/${p[e.target]}.ts`,...e.target===`mcp`?[`${t.GENERATED_DIR}/mcp-ui.ts`]:[]],{changed:O}=s.writeGenerated(e.packageDir,_,e.check,D);return{graph:h,packageName:a,pluginId:m,files:_,changed:O,notices:g,targets:v}}exports.defaultPluginId=u,exports.generateExtension=m;
3
4
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["fs","path","renderServerEntry","renderWebEntry","renderNativeEntry","renderMcpEntry","GENERATED_ENTRY_FILENAMES","scanExtensions","renderMcpWidgets","GENERATED_DIR","BUILD_TARGET_PLATFORMS","RETIRED_PLATFORM_NOTICE","resolveTarget","renderApiClient","GENERATED_CLIENT_NAME","renderNativeApiClient","GENERATED_NATIVE_CLIENT_NAME","API_ROUTES_MODULE","GENERATED_ENTRY_NAMES","writeGenerated","require_runtime","require_layout","require_index","require_index$1","require_index$2","require_index$3","require_index$4","require_index$5","node_fs","node_path","defaultPluginId","packageName","readPackageName","manifest","packageDir","RENDERERS","ENTRY_FILENAME","generateExtension","options","pluginId","graph","notices","files","targets","mcpWidgets","entry","retired","notice","requestedTargets","target","resolution","render","source","hasRouteTable","hasBrowserHalf","client","hasNativeHalf","nativeClient","managed","name"],"sources":["../../../src/services/generate/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport {\n API_ROUTES_MODULE,\n BUILD_TARGET_PLATFORMS,\n GENERATED_CLIENT_NAME,\n GENERATED_DIR,\n GENERATED_ENTRY_FILENAMES,\n GENERATED_ENTRY_NAMES,\n GENERATED_NATIVE_CLIENT_NAME,\n} from '../../constants/layout';\nimport type { ExtensionGraph, ExtensionNotice } from '../../types/extensionGraph';\nimport { renderApiClient, renderNativeApiClient } from '../renderClient';\nimport { renderMcpEntry, renderNativeEntry, renderServerEntry, renderWebEntry } from '../renderEntry';\nimport { renderMcpWidgets } from '../renderMcpWidgets';\nimport { resolveTarget } from '../resolveTarget';\nimport type { BuildTarget } from '../resolveTarget/type';\nimport { RETIRED_PLATFORM_NOTICE, scanExtensions } from '../scan';\nimport { writeGenerated } from '../writeGenerated';\nimport type { GenerateOptions, GenerateResult } from './type';\n\n/** `@agimon-ai/po-plan` becomes `plan`. */\nexport function defaultPluginId(packageName: string): string {\n return packageName.replace(/^@[^/]+\\//u, '').replace(/^po-/u, '');\n}\n\nfunction readPackageName(packageDir: string): string {\n const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as { name?: unknown };\n if (typeof manifest.name !== 'string') throw new Error(`${packageDir}/package.json has no name`);\n return manifest.name;\n}\n\nconst RENDERERS: Readonly<Record<BuildTarget, typeof renderServerEntry>> = {\n server: renderServerEntry,\n web: renderWebEntry,\n native: renderNativeEntry,\n mcp: renderMcpEntry,\n};\n\nconst ENTRY_FILENAME: Readonly<Record<BuildTarget, string>> = GENERATED_ENTRY_FILENAMES;\n\n/**\n * Scans a package and renders every entry its tree calls for.\n *\n * A target with nothing in it produces no file, so a backend-only package\n * never grows an empty cockpit entry. Notices from the scan and from each\n * resolution are gathered rather than thrown: an unrecognised folder costs\n * that folder, never the build.\n */\nexport function generateExtension(options: GenerateOptions): GenerateResult {\n const packageName = options.packageName ?? readPackageName(options.packageDir);\n const pluginId = options.pluginId ?? defaultPluginId(packageName);\n\n const graph: ExtensionGraph = scanExtensions(options);\n const notices: ExtensionNotice[] = [...graph.notices];\n const files = new Map<string, string>();\n const targets: BuildTarget[] = [];\n const mcpWidgets = options.target === 'mcp' ? renderMcpWidgets(graph, packageName, GENERATED_DIR) : undefined;\n if (mcpWidgets?.source !== undefined) files.set(`${GENERATED_DIR}/mcp-ui.ts`, mcpWidgets.source);\n\n // Here rather than in the scan, deliberately. The poRoutedFilePosition lint\n // rule calls scanExtensions() directly, so a scan notice would make `.ios` a\n // hard preflight failure and cost us the forward-looking platforms we kept on\n // purpose. resolveTarget runs once per target, which would repeat it per target.\n for (const entry of graph.entries) {\n if (entry.platform === undefined || BUILD_TARGET_PLATFORMS.includes(entry.platform)) continue;\n notices.push({\n path: entry.file,\n message: `'${entry.platform}' is a forward-looking platform with no build target; this file is not emitted for server, web, native or mcp`,\n });\n }\n\n const retired = graph.notices.filter((notice) => notice.message === RETIRED_PLATFORM_NOTICE);\n if (retired.length > 0) {\n throw new Error(\n `${packageName}: ${RETIRED_PLATFORM_NOTICE}\\n${retired.map((notice) => ` ${notice.path}`).join('\\n')}`,\n );\n }\n\n const requestedTargets = options.target === undefined ? (['server', 'web', 'native'] as const) : [options.target];\n for (const target of requestedTargets) {\n const resolution = resolveTarget(graph, target);\n notices.push(...resolution.notices);\n if (resolution.contributions.length === 0 && resolution.escapeHatches.length === 0 && resolution.roots.length === 0)\n continue;\n\n targets.push(target);\n const render = RENDERERS[target];\n const source = render(resolution, {\n packageName,\n pluginId,\n root: graph.root,\n entryDir: GENERATED_DIR,\n mcpWidgets: mcpWidgets?.declarations,\n });\n files.set(`${GENERATED_DIR}/${ENTRY_FILENAME[target]}.ts`, source);\n }\n\n // Not another build target: no host loads it as an entry, and adding one to\n // the target loop would mean a resolution pass and a contribution field for\n // something that is only ever imported by a routed frontend file.\n //\n // Only for a package that has a browser half. The client exists to be called\n // from a page and it carries the sealed transport, so emitting one into a\n // node-only package asks that package to depend on a browser runtime it never\n // loads, to satisfy a file nothing imports.\n const hasRouteTable = options.target === undefined && fs.existsSync(path.join(options.packageDir, API_ROUTES_MODULE));\n const hasBrowserHalf = targets.includes('web');\n const client =\n hasRouteTable && hasBrowserHalf\n ? renderApiClient(graph, { packageName, pluginId, root: graph.root, entryDir: GENERATED_DIR })\n : undefined;\n if (client !== undefined) files.set(`${GENERATED_DIR}/${GENERATED_CLIENT_NAME}.ts`, client);\n\n // The native half gets its own file rather than a shared one, because the\n // browser client's two imports are exactly what the native host refuses.\n const hasNativeHalf = targets.includes('native');\n const nativeClient =\n hasRouteTable && hasNativeHalf\n ? renderNativeApiClient(graph, { packageName, pluginId, root: graph.root, entryDir: GENERATED_DIR })\n : undefined;\n if (nativeClient !== undefined) files.set(`${GENERATED_DIR}/${GENERATED_NATIVE_CLIENT_NAME}.ts`, nativeClient);\n if (hasRouteTable && (hasBrowserHalf || hasNativeHalf) && client === undefined && nativeClient === undefined) {\n notices.push({\n path: API_ROUTES_MODULE,\n message: 'declares API routes, but no (backend)/api/<base-path>/ folder says where they are mounted',\n });\n }\n\n const managed =\n options.target === undefined\n ? GENERATED_ENTRY_NAMES.filter(\n (name) => name !== 'mcp' || !fs.existsSync(path.join(options.packageDir, 'tsdown.mcp.config.ts')),\n ).map((name) => `${GENERATED_DIR}/${name}.ts`)\n : [\n `${GENERATED_DIR}/${ENTRY_FILENAME[options.target]}.ts`,\n ...(options.target === 'mcp' ? [`${GENERATED_DIR}/mcp-ui.ts`] : []),\n ];\n const { changed } = writeGenerated(options.packageDir, files, options.check, managed);\n return { graph, packageName, pluginId, files, changed, notices, targets };\n}\n"],"mappings":"8ZAuBA,SAAgB8B,EAAgB,EAA6B,CAC3D,OAAOC,EAAY,QAAQ,aAAc,EAAE,CAAC,CAAC,QAAQ,QAAS,EAAE,CAClE,CAEA,SAASC,EAAgB,EAA4B,CACnD,IAAMC,EAAW,KAAK,MAAMjC,EAAAA,QAAG,aAAaC,EAAAA,QAAK,KAAKiC,EAAY,cAAc,EAAG,MAAM,CAAC,EAC1F,GAAI,OAAOD,EAAS,MAAS,SAAU,MAAU,MAAM,GAAGC,EAAW,0BAA0B,EAC/F,OAAOD,EAAS,IAClB,CAEA,MAAME,EAAqE,CACzE,OAAQjC,EAAAA,kBACR,IAAKC,EAAAA,eACL,OAAQC,EAAAA,kBACR,IAAKC,EAAAA,cACP,EAEM+B,EAAwD9B,EAAAA,0BAU9D,SAAgB+B,EAAkB,EAA0C,CAC1E,IAAMN,EAAcO,EAAQ,aAAeN,EAAgBM,EAAQ,UAAU,EACvEC,EAAWD,EAAQ,UAAYR,EAAgBC,CAAW,EAE1DS,EAAwBjC,EAAAA,eAAe+B,CAAO,EAC9CG,EAA6B,CAAC,GAAGD,EAAM,OAAO,EAC9CE,kBAAQ,IAAI,IACZC,EAAyB,CAAC,EAC1BC,EAAaN,EAAQ,SAAW,MAAQ9B,EAAAA,iBAAiBgC,EAAOT,EAAatB,EAAAA,aAAa,EAAI,IAAA,GAChGmC,GAAY,SAAW,IAAA,IAAWF,EAAM,IAAI,GAAGjC,EAAAA,cAAc,YAAamC,EAAW,MAAM,EAM/F,IAAK,IAAMC,KAASL,EAAM,QACpB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AAW,IAAA,IAAWb,EAAM,IAAI,GAAGjC,EAAAA,cAAc,GAAGK,EAAAA,sBAAsB,KAAMyC,CAAM,EAI1F,IAAMC,EAAgBb,EAAQ,SAAS,QAAQ,EACzCc,EACJJ,GAAiBG,EACbzC,EAAAA,sBAAsByB,EAAO,CAAE,cAAa,WAAU,KAAMA,EAAM,KAAM,SAAU/B,EAAAA,aAAc,CAAC,EACjG,IAAA,GACFgD,IAAiB,IAAA,IAAWf,EAAM,IAAI,GAAGjC,EAAAA,cAAc,GAAGO,EAAAA,6BAA6B,KAAMyC,CAAY,EACzGJ,IAAkBC,GAAkBE,IAAkBD,IAAW,IAAA,IAAaE,IAAiB,IAAA,IACjGhB,EAAQ,KAAK,CACX,KAAMxB,EAAAA,kBACN,QAAS,2FACX,CAAC,EAGH,IAAMyC,EACJpB,EAAQ,SAAW,IAAA,GACfpB,EAAAA,sBAAsB,OACnB,GAASyC,IAAS,OAAS,CAAC3D,EAAAA,QAAG,WAAWC,EAAAA,QAAK,KAAKqC,EAAQ,WAAY,sBAAsB,CAAC,CAClG,CAAC,CAAC,IAAK,GAAS,GAAG7B,EAAAA,cAAc,GAAGkD,EAAK,IAAI,EAC7C,CACE,GAAGlD,EAAAA,cAAc,GAAG2B,EAAeE,EAAQ,QAAQ,KACnD,GAAIA,EAAQ,SAAW,MAAQ,CAAC,GAAG7B,EAAAA,cAAc,WAAW,EAAI,CAAC,CACnE,EACA,CAAE,WAAYU,EAAAA,eAAemB,EAAQ,WAAYI,EAAOJ,EAAQ,MAAOoB,CAAO,EACpF,MAAO,CAAE,QAAO,cAAa,WAAU,QAAO,UAAS,UAAS,SAAQ,CAC1E"}
1
+ {"version":3,"file":"index.cjs","names":["fs","path","renderServerEntry","renderWebEntry","renderNativeEntry","renderMcpEntry","GENERATED_ENTRY_FILENAMES","scanExtensions","renderMcpWidgets","GENERATED_DIR","BUILD_TARGET_PLATFORMS","RETIRED_PLATFORM_NOTICE","resolveTarget","renderApiClient","GENERATED_CLIENT_NAME","renderNativeApiClient","GENERATED_NATIVE_CLIENT_NAME","API_ROUTES_MODULE","GENERATED_ENTRY_NAMES","writeGenerated","require_runtime","require_layout","require_index","require_index$1","require_index$2","require_index$3","require_index$4","require_index$5","node_fs","node_path","defaultPluginId","packageName","readPackageName","manifest","packageDir","RENDERERS","ENTRY_FILENAME","generateExtension","options","pluginId","graph","notices","files","targets","mcpWidgets","entry","retired","notice","requestedTargets","target","resolution","render","source","hasRouteTable","hasBrowserHalf","client","hasNativeHalf","nativeClient","managed","name"],"sources":["../../../src/services/generate/index.ts"],"sourcesContent":["// sync: Public generateExtension contract is synchronous, deferred with its cross-package callers to phase 2.\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport {\n API_ROUTES_MODULE,\n BUILD_TARGET_PLATFORMS,\n GENERATED_CLIENT_NAME,\n GENERATED_DIR,\n GENERATED_ENTRY_FILENAMES,\n GENERATED_ENTRY_NAMES,\n GENERATED_NATIVE_CLIENT_NAME,\n} from '../../constants/layout';\nimport type { ExtensionGraph, ExtensionNotice } from '../../types/extensionGraph';\nimport { renderApiClient, renderNativeApiClient } from '../renderClient';\nimport { renderMcpEntry, renderNativeEntry, renderServerEntry, renderWebEntry } from '../renderEntry';\nimport { renderMcpWidgets } from '../renderMcpWidgets';\nimport { resolveTarget } from '../resolveTarget';\nimport type { BuildTarget } from '../resolveTarget/type';\nimport { RETIRED_PLATFORM_NOTICE, scanExtensions } from '../scan';\nimport { writeGenerated } from '../writeGenerated';\nimport type { GenerateOptions, GenerateResult } from './type';\n\n/** `@agimon-ai/po-plan` becomes `plan`. */\nexport function defaultPluginId(packageName: string): string {\n return packageName.replace(/^@[^/]+\\//u, '').replace(/^po-/u, '');\n}\n\nfunction readPackageName(packageDir: string): string {\n const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as { name?: unknown };\n if (typeof manifest.name !== 'string') throw new Error(`${packageDir}/package.json has no name`);\n return manifest.name;\n}\n\nconst RENDERERS: Readonly<Record<BuildTarget, typeof renderServerEntry>> = {\n server: renderServerEntry,\n web: renderWebEntry,\n native: renderNativeEntry,\n mcp: renderMcpEntry,\n};\n\nconst ENTRY_FILENAME: Readonly<Record<BuildTarget, string>> = GENERATED_ENTRY_FILENAMES;\n\n/**\n * Scans a package and renders every entry its tree calls for.\n *\n * A target with nothing in it produces no file, so a backend-only package\n * never grows an empty cockpit entry. A misplaced routed file fails the\n * build unless `strictLayout: false`, which gathers scan notices instead.\n * Resolution notices are always gathered rather than thrown.\n */\nexport function generateExtension(options: GenerateOptions): GenerateResult {\n const packageName = options.packageName ?? readPackageName(options.packageDir);\n const pluginId = options.pluginId ?? defaultPluginId(packageName);\n\n const graph: ExtensionGraph = scanExtensions(options);\n const notices: ExtensionNotice[] = [...graph.notices];\n const files = new Map<string, string>();\n const targets: BuildTarget[] = [];\n const mcpWidgets = options.target === 'mcp' ? renderMcpWidgets(graph, packageName, GENERATED_DIR) : undefined;\n if (mcpWidgets?.source !== undefined) files.set(`${GENERATED_DIR}/mcp-ui.ts`, mcpWidgets.source);\n\n // Here rather than in the scan, deliberately. The poRoutedFilePosition lint\n // rule calls scanExtensions() directly, so a scan notice would make `.ios` a\n // hard preflight failure and cost us the forward-looking platforms we kept on\n // purpose. resolveTarget runs once per target, which would repeat it per target.\n for (const entry of graph.entries) {\n if (entry.platform === undefined || BUILD_TARGET_PLATFORMS.includes(entry.platform)) continue;\n notices.push({\n path: entry.file,\n message: `'${entry.platform}' is a forward-looking platform with no build target; this file is not emitted for server, web, native or mcp`,\n });\n }\n\n const retired = graph.notices.filter((notice) => notice.message === RETIRED_PLATFORM_NOTICE);\n if (retired.length > 0) {\n throw new Error(\n `${packageName}: ${RETIRED_PLATFORM_NOTICE}\\n${retired.map((notice) => ` ${notice.path}`).join('\\n')}`,\n );\n }\n\n if (options.strictLayout !== false && graph.notices.length > 0) {\n throw new Error(\n `${packageName}: misplaced routed files (set strictLayout: false to report them as notices)\\n${graph.notices\n .map((notice) => ` ${notice.path}: ${notice.message}`)\n .join('\\n')}`,\n );\n }\n\n const requestedTargets = options.target === undefined ? (['server', 'web', 'native'] as const) : [options.target];\n for (const target of requestedTargets) {\n const resolution = resolveTarget(graph, target);\n notices.push(...resolution.notices);\n if (resolution.contributions.length === 0 && resolution.escapeHatches.length === 0 && resolution.roots.length === 0)\n continue;\n\n targets.push(target);\n const render = RENDERERS[target];\n const source = render(resolution, {\n packageName,\n pluginId,\n root: graph.root,\n entryDir: GENERATED_DIR,\n mcpWidgets: mcpWidgets?.declarations,\n });\n files.set(`${GENERATED_DIR}/${ENTRY_FILENAME[target]}.ts`, source);\n }\n\n // Not another build target: no host loads it as an entry, and adding one to\n // the target loop would mean a resolution pass and a contribution field for\n // something that is only ever imported by a routed frontend file.\n //\n // Only for a package that has a browser half. The client exists to be called\n // from a page and it carries the sealed transport, so emitting one into a\n // node-only package asks that package to depend on a browser runtime it never\n // loads, to satisfy a file nothing imports.\n const hasRouteTable = options.target === undefined && fs.existsSync(path.join(options.packageDir, API_ROUTES_MODULE));\n const hasBrowserHalf = targets.includes('web');\n const client =\n hasRouteTable && hasBrowserHalf\n ? renderApiClient(graph, { packageName, pluginId, root: graph.root, entryDir: GENERATED_DIR })\n : undefined;\n if (client !== undefined) files.set(`${GENERATED_DIR}/${GENERATED_CLIENT_NAME}.ts`, client);\n\n // The native half gets its own file rather than a shared one, because the\n // browser client's two imports are exactly what the native host refuses.\n const hasNativeHalf = targets.includes('native');\n const nativeClient =\n hasRouteTable && hasNativeHalf\n ? renderNativeApiClient(graph, { packageName, pluginId, root: graph.root, entryDir: GENERATED_DIR })\n : undefined;\n if (nativeClient !== undefined) files.set(`${GENERATED_DIR}/${GENERATED_NATIVE_CLIENT_NAME}.ts`, nativeClient);\n if (hasRouteTable && (hasBrowserHalf || hasNativeHalf) && client === undefined && nativeClient === undefined) {\n notices.push({\n path: API_ROUTES_MODULE,\n message: 'declares API routes, but no (backend)/api/<base-path>/ folder says where they are mounted',\n });\n }\n\n const managed =\n options.target === undefined\n ? GENERATED_ENTRY_NAMES.filter(\n (name) => name !== 'mcp' || !fs.existsSync(path.join(options.packageDir, 'tsdown.mcp.config.ts')),\n ).map((name) => `${GENERATED_DIR}/${name}.ts`)\n : [\n `${GENERATED_DIR}/${ENTRY_FILENAME[options.target]}.ts`,\n ...(options.target === 'mcp' ? [`${GENERATED_DIR}/mcp-ui.ts`] : []),\n ];\n const { changed } = writeGenerated(options.packageDir, files, options.check, managed);\n return { graph, packageName, pluginId, files, changed, notices, targets };\n}\n"],"mappings":"A,8ZAwBA,SAAgB8B,EAAgB,EAA6B,CAC3D,OAAOC,EAAY,QAAQ,aAAc,EAAE,CAAC,CAAC,QAAQ,QAAS,EAAE,CAClE,CAEA,SAASC,EAAgB,EAA4B,CACnD,IAAMC,EAAW,KAAK,MAAMjC,EAAAA,QAAG,aAAaC,EAAAA,QAAK,KAAKiC,EAAY,cAAc,EAAG,MAAM,CAAC,EAC1F,GAAI,OAAOD,EAAS,MAAS,SAAU,MAAU,MAAM,GAAGC,EAAW,0BAA0B,EAC/F,OAAOD,EAAS,IAClB,CAEA,MAAME,EAAqE,CACzE,OAAQjC,EAAAA,kBACR,IAAKC,EAAAA,eACL,OAAQC,EAAAA,kBACR,IAAKC,EAAAA,cACP,EAEM+B,EAAwD9B,EAAAA,0BAU9D,SAAgB+B,EAAkB,EAA0C,CAC1E,IAAMN,EAAcO,EAAQ,aAAeN,EAAgBM,EAAQ,UAAU,EACvEC,EAAWD,EAAQ,UAAYR,EAAgBC,CAAW,EAE1DS,EAAwBjC,EAAAA,eAAe+B,CAAO,EAC9CG,EAA6B,CAAC,GAAGD,EAAM,OAAO,EAC9CE,kBAAQ,IAAI,IACZC,EAAyB,CAAC,EAC1BC,EAAaN,EAAQ,SAAW,MAAQ9B,EAAAA,iBAAiBgC,EAAOT,EAAatB,EAAAA,aAAa,EAAI,IAAA,GAChGmC,GAAY,SAAW,IAAA,IAAWF,EAAM,IAAI,GAAGjC,EAAAA,cAAc,YA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U,QAAO,UAAS,UAAS,SAAQ,CAC1E,C"}
@@ -6,9 +6,9 @@ export declare function defaultPluginId(packageName: string): string;
6
6
  * Scans a package and renders every entry its tree calls for.
7
7
  *
8
8
  * A target with nothing in it produces no file, so a backend-only package
9
- * never grows an empty cockpit entry. Notices from the scan and from each
10
- * resolution are gathered rather than thrown: an unrecognised folder costs
11
- * that folder, never the build.
9
+ * never grows an empty cockpit entry. A misplaced routed file fails the
10
+ * build unless `strictLayout: false`, which gathers scan notices instead.
11
+ * Resolution notices are always gathered rather than thrown.
12
12
  */
13
13
  export declare function generateExtension(options: GenerateOptions): GenerateResult;
14
14
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/generate/index.ts"],"mappings":";;;wBAuBgB,gBAAgB;;;;;;;;;wBA2BhB,kBAAkB,SAAS,kBAAkB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/generate/index.ts"],"mappings":";;;wBAwBgB,gBAAgB;;;;;;;;;wBA2BhB,kBAAkB,SAAS,kBAAkB"}
@@ -1,3 +1,4 @@
1
1
  import{API_ROUTES_MODULE as e,BUILD_TARGET_PLATFORMS as t,GENERATED_CLIENT_NAME as n,GENERATED_DIR as r,GENERATED_ENTRY_FILENAMES as i,GENERATED_ENTRY_NAMES as a,GENERATED_NATIVE_CLIENT_NAME as o}from"../../constants/layout.mjs";import{RETIRED_PLATFORM_NOTICE as s,scanExtensions as c}from"../scan/index.mjs";import{resolveTarget as l}from"../resolveTarget/index.mjs";import{renderApiClient as u,renderNativeApiClient as d}from"../renderClient/index.mjs";import{renderMcpEntry as f,renderNativeEntry as p,renderServerEntry as m,renderWebEntry as h}from"../renderEntry/index.mjs";import{renderMcpWidgets as g}from"../renderMcpWidgets/index.mjs";import{writeGenerated as _}from"../writeGenerated/index.mjs";import v from"node:fs";import y from"node:path";function b(e){return e.replace(/^@[^/]+\//u,``).replace(/^po-/u,``)}function x(e){let t=JSON.parse(v.readFileSync(y.join(e,`package.json`),`utf8`));if(typeof t.name!=`string`)throw Error(`${e}/package.json has no name`);return t.name}const S={server:m,web:h,native:p,mcp:f},C=i;function w(i){let f=i.packageName??x(i.packageDir),p=i.pluginId??b(f),m=c(i),h=[...m.notices],w=/* @__PURE__ */ new Map,T=[],E=i.target===`mcp`?g(m,f,r):void 0;E?.source!==void 0&&w.set(`${r}/mcp-ui.ts`,E.source);for(let e of m.entries)e.platform===void 0||t.includes(e.platform)||h.push({path:e.file,message:`'${e.platform}' is a forward-looking platform with no build target; this file is not emitted for server, web, native or mcp`});let D=m.notices.filter(e=>e.message===s);if(D.length>0)throw Error(`${f}: ${s}\n${D.map(e=>` ${e.path}`).join(`
2
+ `)}`);if(i.strictLayout!==!1&&m.notices.length>0)throw Error(`${f}: misplaced routed files (set strictLayout: false to report them as notices)\n${m.notices.map(e=>` ${e.path}: ${e.message}`).join(`
2
3
  `)}`);let O=i.target===void 0?[`server`,`web`,`native`]:[i.target];for(let e of O){let t=l(m,e);if(h.push(...t.notices),t.contributions.length===0&&t.escapeHatches.length===0&&t.roots.length===0)continue;T.push(e);let n=S[e],i=n(t,{packageName:f,pluginId:p,root:m.root,entryDir:r,mcpWidgets:E?.declarations});w.set(`${r}/${C[e]}.ts`,i)}let k=i.target===void 0&&v.existsSync(y.join(i.packageDir,`src/types/apiRoutes.ts`)),A=T.includes(`web`),j=k&&A?u(m,{packageName:f,pluginId:p,root:m.root,entryDir:r}):void 0;j!==void 0&&w.set(`${r}/${n}.ts`,j);let M=T.includes(`native`),N=k&&M?d(m,{packageName:f,pluginId:p,root:m.root,entryDir:r}):void 0;N!==void 0&&w.set(`${r}/${o}.ts`,N),k&&(A||M)&&j===void 0&&N===void 0&&h.push({path:e,message:`declares API routes, but no (backend)/api/<base-path>/ folder says where they are mounted`});let P=i.target===void 0?a.filter(e=>e!==`mcp`||!v.existsSync(y.join(i.packageDir,`tsdown.mcp.config.ts`))).map(e=>`${r}/${e}.ts`):[`${r}/${C[i.target]}.ts`,...i.target===`mcp`?[`${r}/mcp-ui.ts`]:[]],{changed:F}=_(i.packageDir,w,i.check,P);return{graph:m,packageName:f,pluginId:p,files:w,changed:F,notices:h,targets:T}}export{b as defaultPluginId,w as generateExtension};
3
4
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["fs","path","defaultPluginId","packageName","readPackageName","manifest","packageDir","RENDERERS","renderServerEntry","renderWebEntry","renderNativeEntry","renderMcpEntry","ENTRY_FILENAME","GENERATED_ENTRY_FILENAMES","generateExtension","options","pluginId","graph","scanExtensions","notices","files","targets","mcpWidgets","renderMcpWidgets","GENERATED_DIR","entry","BUILD_TARGET_PLATFORMS","retired","notice","RETIRED_PLATFORM_NOTICE","requestedTargets","target","resolution","resolveTarget","render","source","hasRouteTable","hasBrowserHalf","client","renderApiClient","GENERATED_CLIENT_NAME","hasNativeHalf","nativeClient","renderNativeApiClient","GENERATED_NATIVE_CLIENT_NAME","API_ROUTES_MODULE","managed","GENERATED_ENTRY_NAMES","name","writeGenerated"],"sources":["../../../src/services/generate/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport {\n API_ROUTES_MODULE,\n BUILD_TARGET_PLATFORMS,\n GENERATED_CLIENT_NAME,\n GENERATED_DIR,\n GENERATED_ENTRY_FILENAMES,\n GENERATED_ENTRY_NAMES,\n GENERATED_NATIVE_CLIENT_NAME,\n} from '../../constants/layout';\nimport type { ExtensionGraph, ExtensionNotice } from '../../types/extensionGraph';\nimport { renderApiClient, renderNativeApiClient } from '../renderClient';\nimport { renderMcpEntry, renderNativeEntry, renderServerEntry, renderWebEntry } from '../renderEntry';\nimport { renderMcpWidgets } from '../renderMcpWidgets';\nimport { resolveTarget } from '../resolveTarget';\nimport type { BuildTarget } from '../resolveTarget/type';\nimport { RETIRED_PLATFORM_NOTICE, scanExtensions } from '../scan';\nimport { writeGenerated } from '../writeGenerated';\nimport type { GenerateOptions, GenerateResult } from './type';\n\n/** `@agimon-ai/po-plan` becomes `plan`. */\nexport function defaultPluginId(packageName: string): string {\n return packageName.replace(/^@[^/]+\\//u, '').replace(/^po-/u, '');\n}\n\nfunction readPackageName(packageDir: string): string {\n const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as { name?: unknown };\n if (typeof manifest.name !== 'string') throw new Error(`${packageDir}/package.json has no name`);\n return manifest.name;\n}\n\nconst RENDERERS: Readonly<Record<BuildTarget, typeof renderServerEntry>> = {\n server: renderServerEntry,\n web: renderWebEntry,\n native: renderNativeEntry,\n mcp: renderMcpEntry,\n};\n\nconst ENTRY_FILENAME: Readonly<Record<BuildTarget, string>> = GENERATED_ENTRY_FILENAMES;\n\n/**\n * Scans a package and renders every entry its tree calls for.\n *\n * A target with nothing in it produces no file, so a backend-only package\n * never grows an empty cockpit entry. Notices from the scan and from each\n * resolution are gathered rather than thrown: an unrecognised folder costs\n * that folder, never the build.\n */\nexport function generateExtension(options: GenerateOptions): GenerateResult {\n const packageName = options.packageName ?? readPackageName(options.packageDir);\n const pluginId = options.pluginId ?? defaultPluginId(packageName);\n\n const graph: ExtensionGraph = scanExtensions(options);\n const notices: ExtensionNotice[] = [...graph.notices];\n const files = new Map<string, string>();\n const targets: BuildTarget[] = [];\n const mcpWidgets = options.target === 'mcp' ? renderMcpWidgets(graph, packageName, GENERATED_DIR) : undefined;\n if (mcpWidgets?.source !== undefined) files.set(`${GENERATED_DIR}/mcp-ui.ts`, mcpWidgets.source);\n\n // Here rather than in the scan, deliberately. The poRoutedFilePosition lint\n // rule calls scanExtensions() directly, so a scan notice would make `.ios` a\n // hard preflight failure and cost us the forward-looking platforms we kept on\n // purpose. resolveTarget runs once per target, which would repeat it per target.\n for (const entry of graph.entries) {\n if (entry.platform === undefined || BUILD_TARGET_PLATFORMS.includes(entry.platform)) continue;\n notices.push({\n path: entry.file,\n message: `'${entry.platform}' is a forward-looking platform with no build target; this file is not emitted for server, web, native or mcp`,\n });\n }\n\n const retired = graph.notices.filter((notice) => notice.message === RETIRED_PLATFORM_NOTICE);\n if (retired.length > 0) {\n throw new Error(\n `${packageName}: ${RETIRED_PLATFORM_NOTICE}\\n${retired.map((notice) => ` ${notice.path}`).join('\\n')}`,\n );\n }\n\n const requestedTargets = options.target === undefined ? (['server', 'web', 'native'] as const) : [options.target];\n for (const target of requestedTargets) {\n const resolution = resolveTarget(graph, target);\n notices.push(...resolution.notices);\n if (resolution.contributions.length === 0 && resolution.escapeHatches.length === 0 && resolution.roots.length === 0)\n continue;\n\n targets.push(target);\n const render = RENDERERS[target];\n const source = render(resolution, {\n packageName,\n pluginId,\n root: graph.root,\n entryDir: GENERATED_DIR,\n mcpWidgets: mcpWidgets?.declarations,\n });\n files.set(`${GENERATED_DIR}/${ENTRY_FILENAME[target]}.ts`, source);\n }\n\n // Not another build target: no host loads it as an entry, and adding one to\n // the target loop would mean a resolution pass and a contribution field for\n // something that is only ever imported by a routed frontend file.\n //\n // Only for a package that has a browser half. The client exists to be called\n // from a page and it carries the sealed transport, so emitting one into a\n // node-only package asks that package to depend on a browser runtime it never\n // loads, to satisfy a file nothing imports.\n const hasRouteTable = options.target === undefined && fs.existsSync(path.join(options.packageDir, API_ROUTES_MODULE));\n const hasBrowserHalf = targets.includes('web');\n const client =\n hasRouteTable && hasBrowserHalf\n ? renderApiClient(graph, { packageName, pluginId, root: graph.root, entryDir: GENERATED_DIR })\n : undefined;\n if (client !== undefined) files.set(`${GENERATED_DIR}/${GENERATED_CLIENT_NAME}.ts`, client);\n\n // The native half gets its own file rather than a shared one, because the\n // browser client's two imports are exactly what the native host refuses.\n const hasNativeHalf = targets.includes('native');\n const nativeClient =\n hasRouteTable && hasNativeHalf\n ? renderNativeApiClient(graph, { packageName, pluginId, root: graph.root, entryDir: GENERATED_DIR })\n : undefined;\n if (nativeClient !== undefined) files.set(`${GENERATED_DIR}/${GENERATED_NATIVE_CLIENT_NAME}.ts`, nativeClient);\n if (hasRouteTable && (hasBrowserHalf || hasNativeHalf) && client === undefined && nativeClient === undefined) {\n notices.push({\n path: API_ROUTES_MODULE,\n message: 'declares API routes, but no (backend)/api/<base-path>/ folder says where they are mounted',\n });\n }\n\n const managed =\n options.target === undefined\n ? GENERATED_ENTRY_NAMES.filter(\n (name) => name !== 'mcp' || !fs.existsSync(path.join(options.packageDir, 'tsdown.mcp.config.ts')),\n ).map((name) => `${GENERATED_DIR}/${name}.ts`)\n : [\n `${GENERATED_DIR}/${ENTRY_FILENAME[options.target]}.ts`,\n ...(options.target === 'mcp' ? [`${GENERATED_DIR}/mcp-ui.ts`] : []),\n ];\n const { changed } = writeGenerated(options.packageDir, files, options.check, managed);\n return { graph, packageName, pluginId, files, changed, notices, targets };\n}\n"],"mappings":"ivBAuBA,SAAgBE,EAAgB,EAA6B,CAC3D,OAAOC,EAAY,QAAQ,aAAc,EAAE,CAAC,CAAC,QAAQ,QAAS,EAAE,CAClE,CAEA,SAASC,EAAgB,EAA4B,CACnD,IAAMC,EAAW,KAAK,MAAML,EAAG,aAAaC,EAAK,KAAKK,EAAY,cAAc,EAAG,MAAM,CAAC,EAC1F,GAAI,OAAOD,EAAS,MAAS,SAAU,MAAU,MAAM,GAAGC,EAAW,0BAA0B,EAC/F,OAAOD,EAAS,IAClB,CAEA,MAAME,EAAqE,CACzE,OAAQC,EACR,IAAKC,EACL,OAAQC,EACR,IAAKC,CACP,EAEMC,EAAwDC,EAU9D,SAAgBC,EAAkB,EAA0C,CAC1E,IAAMX,EAAcY,EAAQ,aAAeX,EAAgBW,EAAQ,UAAU,EACvEC,EAAWD,EAAQ,UAAYb,EAAgBC,CAAW,EAE1Dc,EAAwBC,EAAeH,CAAO,EAC9CI,EAA6B,CAAC,GAAGF,EAAM,OAAO,EAC9CG,kBAAQ,IAAI,IACZC,EAAyB,CAAC,EAC1BC,EAAaP,EAAQ,SAAW,MAAQQ,EAAiBN,EAAOd,EAAaqB,CAAa,EAAI,IAAA,GAChGF,GAAY,SAAW,IAAA,IAAWF,EAAM,IAA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AA,IAAWlB,EAAM,IAAI,GAAGI,EAAc,GAAGgB,EAAsB,KAAMF,CAAM,EAI1F,IAAMG,EAAgBpB,EAAQ,SAAS,QAAQ,EACzCqB,EACJN,GAAiBK,EACbE,EAAsB1B,EAAO,CAAE,cAAa,WAAU,KAAMA,EAAM,KAAM,SAAUO,CAAc,CAAC,EACjG,IAAA,GACFkB,IAAiB,IAAA,IAAWtB,EAAM,IAAI,GAAGI,EAAc,GAAGoB,EAA6B,KAAMF,CAAY,EACzGN,IAAkBC,GAAkBI,IAAkBH,IAAW,IAAA,IAAaI,IAAiB,IAAA,IACjGvB,EAAQ,KAAK,CACX,KAAM0B,EACN,QAAS,2FACX,CAAC,EAGH,IAAMC,EACJ/B,EAAQ,SAAW,IAAA,GACfgC,EAAsB,OACnB,GAASC,IAAS,OAAS,CAAChD,EAAG,WAAWC,EAAK,KAAKc,EAAQ,WAAY,sBAAsB,CAAC,CAClG,CAAC,CAAC,IAAK,GAAS,GAAGS,EAAc,GAAGwB,EAAK,IAAI,EAC7C,CACE,GAAGxB,EAAc,GAAGZ,EAAeG,EAAQ,QAAQ,KACnD,GAAIA,EAAQ,SAAW,MAAQ,CAAC,GAAGS,EAAc,WAAW,EAAI,CAAC,CACnE,EACA,CAAE,WAAYyB,EAAelC,EAAQ,WAAYK,EAAOL,EAAQ,MAAO+B,CAAO,EACpF,MAAO,CAAE,QAAO,cAAa,WAAU,QAAO,UAAS,UAAS,SAAQ,CAC1E"}
1
+ {"version":3,"file":"index.mjs","names":["fs","path","defaultPluginId","packageName","readPackageName","manifest","packageDir","RENDERERS","renderServerEntry","renderWebEntry","renderNativeEntry","renderMcpEntry","ENTRY_FILENAME","GENERATED_ENTRY_FILENAMES","generateExtension","options","pluginId","graph","scanExtensions","notices","files","targets","mcpWidgets","renderMcpWidgets","GENERATED_DIR","entry","BUILD_TARGET_PLATFORMS","retired","notice","RETIRED_PLATFORM_NOTICE","requestedTargets","target","resolution","resolveTarget","render","source","hasRouteTable","hasBrowserHalf","client","renderApiClient","GENERATED_CLIENT_NAME","hasNativeHalf","nativeClient","renderNativeApiClient","GENERATED_NATIVE_CLIENT_NAME","API_ROUTES_MODULE","managed","GENERATED_ENTRY_NAMES","name","writeGenerated"],"sources":["../../../src/services/generate/index.ts"],"sourcesContent":["// sync: Public generateExtension contract is synchronous, deferred with its cross-package callers to phase 2.\nimport fs from 'node:fs';\nimport path from 'node:path';\n\nimport {\n API_ROUTES_MODULE,\n BUILD_TARGET_PLATFORMS,\n GENERATED_CLIENT_NAME,\n GENERATED_DIR,\n GENERATED_ENTRY_FILENAMES,\n GENERATED_ENTRY_NAMES,\n GENERATED_NATIVE_CLIENT_NAME,\n} from '../../constants/layout';\nimport type { ExtensionGraph, ExtensionNotice } from '../../types/extensionGraph';\nimport { renderApiClient, renderNativeApiClient } from '../renderClient';\nimport { renderMcpEntry, renderNativeEntry, renderServerEntry, renderWebEntry } from '../renderEntry';\nimport { renderMcpWidgets } from '../renderMcpWidgets';\nimport { resolveTarget } from '../resolveTarget';\nimport type { BuildTarget } from '../resolveTarget/type';\nimport { RETIRED_PLATFORM_NOTICE, scanExtensions } from '../scan';\nimport { writeGenerated } from '../writeGenerated';\nimport type { GenerateOptions, GenerateResult } from './type';\n\n/** `@agimon-ai/po-plan` becomes `plan`. */\nexport function defaultPluginId(packageName: string): string {\n return packageName.replace(/^@[^/]+\\//u, '').replace(/^po-/u, '');\n}\n\nfunction readPackageName(packageDir: string): string {\n const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as { name?: unknown };\n if (typeof manifest.name !== 'string') throw new Error(`${packageDir}/package.json has no name`);\n return manifest.name;\n}\n\nconst RENDERERS: Readonly<Record<BuildTarget, typeof renderServerEntry>> = {\n server: renderServerEntry,\n web: renderWebEntry,\n native: renderNativeEntry,\n mcp: renderMcpEntry,\n};\n\nconst ENTRY_FILENAME: Readonly<Record<BuildTarget, string>> = GENERATED_ENTRY_FILENAMES;\n\n/**\n * Scans a package and renders every entry its tree calls for.\n *\n * A target with nothing in it produces no file, so a backend-only package\n * never grows an empty cockpit entry. A misplaced routed file fails the\n * build unless `strictLayout: false`, which gathers scan notices instead.\n * Resolution notices are always gathered rather than thrown.\n */\nexport function generateExtension(options: GenerateOptions): GenerateResult {\n const packageName = options.packageName ?? readPackageName(options.packageDir);\n const pluginId = options.pluginId ?? defaultPluginId(packageName);\n\n const graph: ExtensionGraph = scanExtensions(options);\n const notices: ExtensionNotice[] = [...graph.notices];\n const files = new Map<string, string>();\n const targets: BuildTarget[] = [];\n const mcpWidgets = options.target === 'mcp' ? renderMcpWidgets(graph, packageName, GENERATED_DIR) : undefined;\n if (mcpWidgets?.source !== undefined) files.set(`${GENERATED_DIR}/mcp-ui.ts`, mcpWidgets.source);\n\n // Here rather than in the scan, deliberately. The poRoutedFilePosition lint\n // rule calls scanExtensions() directly, so a scan notice would make `.ios` a\n // hard preflight failure and cost us the forward-looking platforms we kept on\n // purpose. resolveTarget runs once per target, which would repeat it per target.\n for (const entry of graph.entries) {\n if (entry.platform === undefined || BUILD_TARGET_PLATFORMS.includes(entry.platform)) continue;\n notices.push({\n path: entry.file,\n message: `'${entry.platform}' is a forward-looking platform with no build target; this file is not emitted for server, web, native or mcp`,\n });\n }\n\n const retired = graph.notices.filter((notice) => notice.message === RETIRED_PLATFORM_NOTICE);\n if (retired.length > 0) {\n throw new Error(\n `${packageName}: ${RETIRED_PLATFORM_NOTICE}\\n${retired.map((notice) => ` ${notice.path}`).join('\\n')}`,\n );\n }\n\n if (options.strictLayout !== false && graph.notices.length > 0) {\n throw new Error(\n `${packageName}: misplaced routed files (set strictLayout: false to report them as notices)\\n${graph.notices\n .map((notice) => ` ${notice.path}: ${notice.message}`)\n .join('\\n')}`,\n );\n }\n\n const requestedTargets = options.target === undefined ? (['server', 'web', 'native'] as const) : [options.target];\n for (const target of requestedTargets) {\n const resolution = resolveTarget(graph, target);\n notices.push(...resolution.notices);\n if (resolution.contributions.length === 0 && resolution.escapeHatches.length === 0 && resolution.roots.length === 0)\n continue;\n\n targets.push(target);\n const render = RENDERERS[target];\n const source = render(resolution, {\n packageName,\n pluginId,\n root: graph.root,\n entryDir: GENERATED_DIR,\n mcpWidgets: mcpWidgets?.declarations,\n });\n files.set(`${GENERATED_DIR}/${ENTRY_FILENAME[target]}.ts`, source);\n }\n\n // Not another build target: no host loads it as an entry, and adding one to\n // the target loop would mean a resolution pass and a contribution field for\n // something that is only ever imported by a routed frontend file.\n //\n // Only for a package that has a browser half. The client exists to be called\n // from a page and it carries the sealed transport, so emitting one into a\n // node-only package asks that package to depend on a browser runtime it never\n // loads, to satisfy a file nothing imports.\n const hasRouteTable = options.target === undefined && fs.existsSync(path.join(options.packageDir, API_ROUTES_MODULE));\n const hasBrowserHalf = targets.includes('web');\n const client =\n hasRouteTable && hasBrowserHalf\n ? renderApiClient(graph, { packageName, pluginId, root: graph.root, entryDir: GENERATED_DIR })\n : undefined;\n if (client !== undefined) files.set(`${GENERATED_DIR}/${GENERATED_CLIENT_NAME}.ts`, client);\n\n // The native half gets its own file rather than a shared one, because the\n // browser client's two imports are exactly what the native host refuses.\n const hasNativeHalf = targets.includes('native');\n const nativeClient =\n hasRouteTable && hasNativeHalf\n ? renderNativeApiClient(graph, { packageName, pluginId, root: graph.root, entryDir: GENERATED_DIR })\n : undefined;\n if (nativeClient !== undefined) files.set(`${GENERATED_DIR}/${GENERATED_NATIVE_CLIENT_NAME}.ts`, nativeClient);\n if (hasRouteTable && (hasBrowserHalf || hasNativeHalf) && client === undefined && nativeClient === undefined) {\n notices.push({\n path: API_ROUTES_MODULE,\n message: 'declares API routes, but no (backend)/api/<base-path>/ folder says where they are mounted',\n });\n }\n\n const managed =\n options.target === undefined\n ? GENERATED_ENTRY_NAMES.filter(\n (name) => name !== 'mcp' || !fs.existsSync(path.join(options.packageDir, 'tsdown.mcp.config.ts')),\n ).map((name) => `${GENERATED_DIR}/${name}.ts`)\n : [\n `${GENERATED_DIR}/${ENTRY_FILENAME[options.target]}.ts`,\n ...(options.target === 'mcp' ? [`${GENERATED_DIR}/mcp-ui.ts`] : []),\n ];\n const { changed } = writeGenerated(options.packageDir, files, options.check, managed);\n return { graph, packageName, pluginId, files, changed, notices, targets };\n}\n"],"mappings":"A,ivBAwBA,SAAgBE,EAAgB,EAA6B,CAC3D,OAAOC,EAAY,QAAQ,aAAc,EAAE,CAAC,CAAC,QAAQ,QAAS,EAAE,CAClE,CAEA,SAASC,EAAgB,EAA4B,CACnD,IAAMC,EAAW,KAAK,MAAML,EAAG,aAAaC,EAAK,KAAKK,EAAY,cAAc,EAAG,MAAM,CAAC,EAC1F,GAAI,OAAOD,EAAS,MAAS,SAAU,MAAU,MAAM,GAAGC,EAAW,0BAA0B,EAC/F,OAAOD,EAAS,IAClB,CAEA,MAAME,EAAqE,CACzE,OAAQC,EACR,IAAKC,EACL,OAAQC,EACR,IAAKC,CACP,EAEMC,EAAwDC,EAU9D,SAAgBC,EAAkB,EAA0C,CAC1E,IAAMX,EAAcY,EAAQ,aAAeX,EAAgBW,EAAQ,UAAU,EACvEC,EAAWD,EAAQ,UAAYb,EAAgBC,CAAW,EAE1Dc,EAAwBC,EAAeH,CAAO,EAC9CI,EAA6B,CAAC,GAAGF,EAAM,OAAO,EAC9CG,kBAAQ,IAAI,IACZC,EAAyB,CAAC,EAC1BC,EAAaP,EAAQ,SAAW,MAAQQ,EAAiBN,EAAOd,EAAaqB,CAAa,EAAI,IAAA,GAChGF,GAAY,SAAW,IAAA,IAAWF,EAAM,IAAI,GAAGI,EAAc,YAAaF,EAAW,MAAM,EAM/F,IAAK,IAAMG,KAASR,EAAM,QACpBQ,EAAM,WAAa,IAAA,IAAaC,EAAuB,SAASD,EAAM,QAAQ,GAClFN,EAAQ,KAAK,CACX,KAAMM,EAAM,KACZ,QAAS,IAAIA,EAAM,SAAS,8GAC9B,CAAC,EAGH,IAAME,EAAUV,EAAM,QAAQ,OAAQ,GAAWW,EAAO,UAAYC,CAAuB,EAC3F,GAAIF,EAAQ,OA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,EACJN,GAAiBK,EACbE,EAAsB1B,EAAO,CAAE,cAAa,WAAU,KAAMA,EAAM,KAAM,SAAUO,CAAc,CAAC,EACjG,IAAA,GACFkB,IAAiB,IAAA,IAAWtB,EAAM,IAAI,GAAGI,EAAc,GAAGoB,EAA6B,KAAMF,CAAY,EACzGN,IAAkBC,GAAkBI,IAAkBH,IAAW,IAAA,IAAaI,IAAiB,IAAA,IACjGvB,EAAQ,KAAK,CACX,KAAM0B,EACN,QAAS,2FACX,CAAC,EAGH,IAAMC,EACJ/B,EAAQ,SAAW,IAAA,GACfgC,EAAsB,OACnB,GAASC,IAAS,OAAS,CAAChD,EAAG,WAAWC,EAAK,KAAKc,EAAQ,WAAY,sBAAsB,CAAC,CAClG,CAAC,CAAC,IAAK,GAAS,GAAGS,EAAc,GAAGwB,EAAK,IAAI,EAC7C,CACE,GAAGxB,EAAc,GAAGZ,EAAeG,EAAQ,QAAQ,KACnD,GAAIA,EAAQ,SAAW,MAAQ,CAAC,GAAGS,EAAc,WAAW,EAAI,CAAC,CACnE,EACA,CAAE,WAAYyB,EAAelC,EAAQ,WAAYK,EAAOL,EAAQ,MAAO+B,CAAO,EACpF,MAAO,CAAE,QAAO,cAAa,WAAU,QAAO,UAAS,UAAS,SAAQ,CAC1E,C"}
@@ -9,6 +9,8 @@ export interface GenerateOptions extends ScanOptions {
9
9
  readonly packageName?: string;
10
10
  /** Defaults to the package name without its scope and `po-` prefix. */
11
11
  readonly pluginId?: string;
12
+ /** Throw on misplaced routed files. Defaults to true; `false` reports them as notices. */
13
+ readonly strictLayout?: boolean;
12
14
  /** Throw on stale output instead of writing it. */
13
15
  readonly check?: boolean;
14
16
  }
@@ -1 +1 @@
1
- {"version":3,"file":"type.d.mts","names":[],"sources":["../../../src/services/generate/type.ts"],"mappings":";;;;iBAIiB,wBAAwB;;WAE9B,SAAS;;WAET;;WAEA;;WAEA;;iBAGM;WACN,OAAO;WACP;WACA;;WAEA,OAAO;;WAEP;WACA,kBAAkB;;WAElB,kBAAkB"}
1
+ {"version":3,"file":"type.d.mts","names":[],"sources":["../../../src/services/generate/type.ts"],"mappings":";;;;iBAIiB,wBAAwB;;WAE9B,SAAS;;WAET;;WAEA;;WAEA;;WAEA;;iBAGM;WACN,OAAO;WACP;WACA;;WAEA,OAAO;;WAEP;WACA,kBAAkB;;WAElB,kBAAkB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["toSnake","name","toKebab","renderIdentity","identity","key","value","item"],"sources":["../../../src/services/identity/index.ts"],"sourcesContent":["/**\n * What a path knows about a contribution's identity.\n *\n * The generator supplies these and the authored file is spread over the top,\n * so a file that states its own name or id always wins. That is what lets the\n * filename be the identity without taking the choice away.\n */\n\n/** `write-plan` and `writePlan` both become `write_plan`. */\nexport function toSnake(name: string): string {\n return name\n .replace(/([a-z0-9])([A-Z])/gu, '$1-$2')\n .toLowerCase()\n .replaceAll('-', '_');\n}\n\n/** `PlanPanel` becomes `plan-panel`; an already-kebab name is unchanged. */\nexport function toKebab(name: string): string {\n return name.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase();\n}\n\n/** One derived field and the literal it holds. */\nexport type Identity = Readonly<Record<string, string | readonly string[]>>;\n\n/** Renders an identity as object-literal members, ready to precede a spread. */\nexport function renderIdentity(identity: Identity): string {\n return Object.entries(identity)\n .map(([key, value]) =>\n Array.isArray(value)\n ? `${key}: [${value.map((item) => `'${item}'`).join(', ')}]`\n : `${key}: '${value as string}'`,\n )\n .join(', ');\n}\n"],"mappings":"AASA,SAAgBA,EAAQ,EAAsB,CAC5C,OAAOC,EACJ,QAAQ,sBAAuB,OAAO,CAAC,CACvC,YAAY,CAAC,CACb,WAAW,IAAK,GAAG,CACxB,CAGA,SAAgBC,EAAQ,EAAsB,CAC5C,OAAOD,EAAK,QAAQ,sBAAuB,OAAO,CAAC,CAAC,YAAY,CAClE,CAMA,SAAgBE,EAAe,EAA4B,CACzD,OAAO,OAAO,QAAQC,CAAQ,CAAC,CAC5B,KAAK,CAACC,EAAKC,KACV,MAAM,QAAQA,CAAK,EACf,GAAGD,EAAI,KAAKC,EAAM,IAAK,GAAS,IAAIC,EAAK,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,GACxD,GAAGF,EAAI,KAAKC,EAAgB,EAClC,CAAC,CACA,KAAK,IAAI,CACd"}
1
+ {"version":3,"file":"index.cjs","names":["toSnake","name","toKebab","renderIdentity","identity","key","value","item"],"sources":["../../../src/services/identity/index.ts"],"sourcesContent":["/**\n * What a path knows about a contribution's identity.\n *\n * The generator supplies these and the authored file is spread over the top,\n * so a file that states its own name or id always wins. That is what lets the\n * filename be the identity without taking the choice away.\n */\n\n/** `write-plan` and `writePlan` both become `write_plan`. */\nexport function toSnake(name: string): string {\n return name\n .replace(/([a-z0-9])([A-Z])/gu, '$1-$2')\n .toLowerCase()\n .replaceAll('-', '_');\n}\n\n/** `PlanPanel` becomes `plan-panel`; an already-kebab name is unchanged. */\nexport function toKebab(name: string): string {\n return name.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase();\n}\n\n/** One derived field and the literal it holds. */\nexport type Identity = Readonly<Record<string, string | readonly string[]>>;\n\n/** Renders an identity as object-literal members, ready to precede a spread. */\nexport function renderIdentity(identity: Identity): string {\n return Object.entries(identity)\n .map(([key, value]) =>\n Array.isArray(value)\n ? `${key}: [${value.map((item) => `'${item}'`).join(', ')}]`\n : `${key}: '${value as string}'`,\n )\n .join(', ');\n}\n"],"mappings":"AASA,SAAgBA,EAAQ,EAAsB,CAC5C,OAAOC,EACJ,QAAQ,sBAAuB,OAAO,CAAC,CACvC,YAAY,CAAC,CACb,WAAW,IAAK,GAAG,CACxB,CAGA,SAAgBC,EAAQ,EAAsB,CAC5C,OAAOD,EAAK,QAAQ,sBAAuB,OAAO,CAAC,CAAC,YAAY,CAClE,CAMA,SAAgBE,EAAe,EAA4B,CACzD,OAAO,OAAO,QAAQC,CAAQ,CAAC,CAC5B,KAAK,CAACC,EAAKC,KACV,MAAM,QAAQA,CAAK,EACf,GAAGD,EAAI,KAAKC,EAAM,IAAK,GAAS,IAAIC,EAAK,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,GACxD,GAAGF,EAAI,KAAKC,EAAgB,EAClC,CAAC,CACA,KAAK,IAAI,CACd,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["toSnake","name","toKebab","renderIdentity","identity","key","value","item"],"sources":["../../../src/services/identity/index.ts"],"sourcesContent":["/**\n * What a path knows about a contribution's identity.\n *\n * The generator supplies these and the authored file is spread over the top,\n * so a file that states its own name or id always wins. That is what lets the\n * filename be the identity without taking the choice away.\n */\n\n/** `write-plan` and `writePlan` both become `write_plan`. */\nexport function toSnake(name: string): string {\n return name\n .replace(/([a-z0-9])([A-Z])/gu, '$1-$2')\n .toLowerCase()\n .replaceAll('-', '_');\n}\n\n/** `PlanPanel` becomes `plan-panel`; an already-kebab name is unchanged. */\nexport function toKebab(name: string): string {\n return name.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase();\n}\n\n/** One derived field and the literal it holds. */\nexport type Identity = Readonly<Record<string, string | readonly string[]>>;\n\n/** Renders an identity as object-literal members, ready to precede a spread. */\nexport function renderIdentity(identity: Identity): string {\n return Object.entries(identity)\n .map(([key, value]) =>\n Array.isArray(value)\n ? `${key}: [${value.map((item) => `'${item}'`).join(', ')}]`\n : `${key}: '${value as string}'`,\n )\n .join(', ');\n}\n"],"mappings":"AASA,SAAgBA,EAAQ,EAAsB,CAC5C,OAAOC,EACJ,QAAQ,sBAAuB,OAAO,CAAC,CACvC,YAAY,CAAC,CACb,WAAW,IAAK,GAAG,CACxB,CAGA,SAAgBC,EAAQ,EAAsB,CAC5C,OAAOD,EAAK,QAAQ,sBAAuB,OAAO,CAAC,CAAC,YAAY,CAClE,CAMA,SAAgBE,EAAe,EAA4B,CACzD,OAAO,OAAO,QAAQC,CAAQ,CAAC,CAC5B,KAAK,CAACC,EAAKC,KACV,MAAM,QAAQA,CAAK,EACf,GAAGD,EAAI,KAAKC,EAAM,IAAK,GAAS,IAAIC,EAAK,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,GACxD,GAAGF,EAAI,KAAKC,EAAgB,EAClC,CAAC,CACA,KAAK,IAAI,CACd"}
1
+ {"version":3,"file":"index.mjs","names":["toSnake","name","toKebab","renderIdentity","identity","key","value","item"],"sources":["../../../src/services/identity/index.ts"],"sourcesContent":["/**\n * What a path knows about a contribution's identity.\n *\n * The generator supplies these and the authored file is spread over the top,\n * so a file that states its own name or id always wins. That is what lets the\n * filename be the identity without taking the choice away.\n */\n\n/** `write-plan` and `writePlan` both become `write_plan`. */\nexport function toSnake(name: string): string {\n return name\n .replace(/([a-z0-9])([A-Z])/gu, '$1-$2')\n .toLowerCase()\n .replaceAll('-', '_');\n}\n\n/** `PlanPanel` becomes `plan-panel`; an already-kebab name is unchanged. */\nexport function toKebab(name: string): string {\n return name.replace(/([a-z0-9])([A-Z])/gu, '$1-$2').toLowerCase();\n}\n\n/** One derived field and the literal it holds. */\nexport type Identity = Readonly<Record<string, string | readonly string[]>>;\n\n/** Renders an identity as object-literal members, ready to precede a spread. */\nexport function renderIdentity(identity: Identity): string {\n return Object.entries(identity)\n .map(([key, value]) =>\n Array.isArray(value)\n ? `${key}: [${value.map((item) => `'${item}'`).join(', ')}]`\n : `${key}: '${value as string}'`,\n )\n .join(', ');\n}\n"],"mappings":"AASA,SAAgBA,EAAQ,EAAsB,CAC5C,OAAOC,EACJ,QAAQ,sBAAuB,OAAO,CAAC,CACvC,YAAY,CAAC,CACb,WAAW,IAAK,GAAG,CACxB,CAGA,SAAgBC,EAAQ,EAAsB,CAC5C,OAAOD,EAAK,QAAQ,sBAAuB,OAAO,CAAC,CAAC,YAAY,CAClE,CAMA,SAAgBE,EAAe,EAA4B,CACzD,OAAO,OAAO,QAAQC,CAAQ,CAAC,CAC5B,KAAK,CAACC,EAAKC,KACV,MAAM,QAAQA,CAAK,EACf,GAAGD,EAAI,KAAKC,EAAM,IAAK,GAAS,IAAIC,EAAK,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,GACxD,GAAGF,EAAI,KAAKC,EAAgB,EAClC,CAAC,CACA,KAAK,IAAI,CACd,C"}
@@ -1,3 +1,3 @@
1
- require("../../constants/layout.cjs");const e=require("../identity/index.cjs");let t=require("node:path");const n=[`global`,`workspace`,`session`];function r(t,n){if(!n)return`api`;let r=e.toKebab(t).split(`-`).filter(e=>e.length>0).map((e,t)=>t===0?e:e[0]?.toUpperCase()+e.slice(1)).join(``);return/^[A-Za-z_]/u.test(r)?r:`api${r}`}function i(e){let t=e.route[0];if(t!==void 0&&`literal`in t)return t.literal}function a(e){let t=/* @__PURE__ */ new Map;for(let n of e.entries){if(n.side!==`backend`||n.surface!==`api`||n.role!==`contribution`)continue;let e=i(n);if(e===void 0)continue;let r=t.get(e)??/* @__PURE__ */ new Set;r.add(n.scope),t.set(e,r)}let a=[...t.keys()].sort();return a.map(e=>{let i=t.get(e),o=n.findIndex(e=>i.has(e));return{basePath:e,scopes:n.slice(o),identifier:r(e,a.length>1)}})}function o(e){let n=t.posix.relative(e,`src/types/apiRoutes`);return n.startsWith(`.`)?n:`./${n}`}const s={imports:[`import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';`,`import { sealedTransport } from '@agimon-ai/po-web-security/browser';`],transport:`(input, init) => sealedTransport.fetch(input, init)`},c={imports:[`import { createApiClient, nativeApiTransport, sessionApiAddress } from '@agimon-ai/po-core/native';`],transport:`nativeApiTransport`};function l(e,t){let n=e.scopes.map(e=>`'${e}'`).join(`, `),r=e.identifier===`api`?``:` for the ${e.basePath} mount`;return[`/** Scopes the tree mounts '${e.basePath}' at${r}. */`,`export const ${e.identifier}Scopes = [${n}] as const;`,``,`export const ${e.identifier} = createApiClient(routes, {`,` scopes: ${e.identifier}Scopes,`,` basePath: '${e.basePath}',`,` transport: ${t.transport},`,` sessionAddress: sessionApiAddress,`,`});`,``]}function u(e,t,n){let r=a(e);if(r.length!==0)return`${[`// Generated by @agimon-ai/po-build. Do not edit by hand.`,...n.imports,``,`import routes from '${o(t.entryDir??`generated`)}';`,``,...r.flatMap(e=>l(e,n))].join(`
1
+ require("../../constants/layout.cjs");const e=require("../identity/index.cjs");let t=require("node:path");const n=[`host`,`workspace`,`session`];function r(t,n){if(!n)return`api`;let r=e.toKebab(t).split(`-`).filter(e=>e.length>0).map((e,t)=>t===0?e:e[0]?.toUpperCase()+e.slice(1)).join(``);return/^[A-Za-z_]/u.test(r)?r:`api${r}`}function i(e){let t=e.route[0];if(t!==void 0&&`literal`in t)return t.literal}function a(e){let t=/* @__PURE__ */ new Map;for(let n of e.entries){if(n.side!==`backend`||n.surface!==`api`||n.role!==`contribution`)continue;let e=i(n);if(e===void 0)continue;let r=t.get(e)??/* @__PURE__ */ new Set;r.add(n.scope),t.set(e,r)}let a=[...t.keys()].sort();return a.map(e=>{let i=t.get(e),o=n.findIndex(e=>i.has(e));return{basePath:e,scopes:n.slice(o),identifier:r(e,a.length>1)}})}function o(e){let n=t.posix.relative(e,`src/types/apiRoutes`);return n.startsWith(`.`)?n:`./${n}`}const s={imports:[`import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';`,`import { browserTransport } from '@agimon-ai/po-web-security/browser';`],transport:`(input, init) => browserTransport.fetch(input, init)`},c={imports:[`import { createApiClient, nativeApiTransport, sessionApiAddress } from '@agimon-ai/po-core/native';`],transport:`nativeApiTransport`};function l(e,t){let n=e.scopes.map(e=>`'${e}'`).join(`, `),r=e.identifier===`api`?``:` for the ${e.basePath} mount`;return[`/** Scopes the tree mounts '${e.basePath}' at${r}. */`,`export const ${e.identifier}Scopes = [${n}] as const;`,``,`export const ${e.identifier} = createApiClient(routes, {`,` scopes: ${e.identifier}Scopes,`,` basePath: '${e.basePath}',`,` transport: ${t.transport},`,` sessionAddress: sessionApiAddress,`,`});`,``]}function u(e,t,n){let r=a(e);if(r.length!==0)return`${[`// Generated by @agimon-ai/po-build. Do not edit by hand.`,...n.imports,``,`import { routes } from '${o(t.entryDir??`generated`)}';`,``,...r.flatMap(e=>l(e,n))].join(`
2
2
  `).replace(/\n+$/u,``)}\n`}function d(e,t){return u(e,t,s)}function f(e,t){return u(e,t,c)}exports.renderApiClient=d,exports.renderNativeApiClient=f;
3
3
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["toKebab","posix","require_index","node_path","SCOPE_ORDER","identifierFor","multiple","camel","basePath","word","index","baseSegmentOf","first","entry","mountsOf","scopesByBase","graph","held","bases","declared","shallowest","scope","routesSpecifier","relative","entryDir","BROWSER_CLIENT","NATIVE_CLIENT","renderMount","scopes","mount","suffix","flavor","renderClient","mounts","options","renderApiClient","renderNativeApiClient"],"sources":["../../../src/services/renderClient/index.ts"],"sourcesContent":["import { posix } from 'node:path';\n\nimport { GENERATED_DIR } from '../../constants/layout';\nimport type { ExtensionEntry, ExtensionGraph, ExtensionScope } from '../../types/extensionGraph';\nimport { toKebab } from '../identity';\nimport type { RenderOptions } from '../renderEntry/type';\n\n/**\n * Renders the typed client a cockpit plugin calls its own API through.\n *\n * The two facts this injects are the two a package kept restating and getting\n * wrong: which scopes its API mounts at, and under which base path. Both are\n * read off the folder tree, so `api/file-edits/route.server.ts` at the session\n * scope is the whole declaration. A package that writes them out again is a\n * package that can disagree with itself, and several did.\n *\n * The route list is not read here. It is authored as plain data in\n * `src/types/apiRoutes.ts`, because this build evaluates no TypeScript and must\n * not learn how: it has no dependencies at all, and every specifier below is\n * emitted as text.\n */\n\nconst HEADER = '// Generated by @agimon-ai/po-build. Do not edit by hand.';\n\n/** Server scopes cascade outward-in, the way the generated server entry mounts them. */\nconst SCOPE_ORDER: readonly ExtensionScope[] = ['global', 'workspace', 'session'];\n\n/** One mount the tree declares: a base path, and the scopes it is reachable at. */\ninterface ClientMount {\n readonly basePath: string;\n readonly scopes: readonly ExtensionScope[];\n /** A valid identifier for the exported factory, when a package has several mounts. */\n readonly identifier: string;\n}\n\nfunction identifierFor(basePath: string, multiple: boolean): string {\n if (!multiple) return 'api';\n const camel = toKebab(basePath)\n .split('-')\n .filter((word) => word.length > 0)\n .map((word, index) => (index === 0 ? word : word[0]?.toUpperCase() + word.slice(1)))\n .join('');\n return /^[A-Za-z_]/u.test(camel) ? camel : `api${camel}`;\n}\n\n/**\n * The base path an api entry mounts at: the first literal segment below `api/`.\n *\n * An entry with no segment is the flat `api/route.server.ts` shape that predates\n * this convention. Its base path lives in a hand-written `PoApi` the build\n * cannot read, so it contributes no client and keeps its hand-built URLs until\n * the folder is renamed.\n */\nfunction baseSegmentOf(entry: ExtensionEntry): string | undefined {\n const first = entry.route[0];\n if (first === undefined || !('literal' in first)) return undefined;\n return first.literal;\n}\n\nfunction mountsOf(graph: ExtensionGraph): ClientMount[] {\n const scopesByBase = new Map<string, Set<ExtensionScope>>();\n for (const entry of graph.entries) {\n if (entry.side !== 'backend' || entry.surface !== 'api' || entry.role !== 'contribution') continue;\n const basePath = baseSegmentOf(entry);\n if (basePath === undefined) continue;\n const held = scopesByBase.get(basePath) ?? new Set<ExtensionScope>();\n held.add(entry.scope);\n scopesByBase.set(basePath, held);\n }\n\n const bases = [...scopesByBase.keys()].sort();\n return bases.map((basePath) => {\n const declared = scopesByBase.get(basePath) as Set<ExtensionScope>;\n // A server plugin offers a contribution at its own scope and every scope below it,\n // so a global API answers workspace and session requests too.\n const shallowest = SCOPE_ORDER.findIndex((scope) => declared.has(scope));\n return {\n basePath,\n scopes: SCOPE_ORDER.slice(shallowest),\n identifier: identifierFor(basePath, bases.length > 1),\n };\n });\n}\n\n/** The extensionless relative specifier from the generated directory to the route table. */\nfunction routesSpecifier(entryDir: string): string {\n const relative = posix.relative(entryDir, 'src/types/apiRoutes');\n return relative.startsWith('.') ? relative : `./${relative}`;\n}\n\n/** What differs between the browser and native clients: where the runtime comes from, and how a call leaves. */\ninterface ClientFlavor {\n readonly imports: readonly string[];\n readonly transport: string;\n}\n\nconst BROWSER_CLIENT: ClientFlavor = {\n imports: [\n \"import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';\",\n \"import { sealedTransport } from '@agimon-ai/po-web-security/browser';\",\n ],\n transport: '(input, init) => sealedTransport.fetch(input, init)',\n};\n\n/**\n * Only `@agimon-ai/po-core/native`, the one Po module on the native host list.\n * The phone's sealed channel and step-up live in the app shell, which binds\n * them behind `nativeApiTransport`.\n */\nconst NATIVE_CLIENT: ClientFlavor = {\n imports: [\"import { createApiClient, nativeApiTransport, sessionApiAddress } from '@agimon-ai/po-core/native';\"],\n transport: 'nativeApiTransport',\n};\n\nfunction renderMount(mount: ClientMount, flavor: ClientFlavor): string[] {\n const scopes = mount.scopes.map((scope) => `'${scope}'`).join(', ');\n const suffix = mount.identifier === 'api' ? '' : ` for the ${mount.basePath} mount`;\n return [\n `/** Scopes the tree mounts '${mount.basePath}' at${suffix}. */`,\n `export const ${mount.identifier}Scopes = [${scopes}] as const;`,\n '',\n `export const ${mount.identifier} = createApiClient(routes, {`,\n ` scopes: ${mount.identifier}Scopes,`,\n ` basePath: '${mount.basePath}',`,\n ` transport: ${flavor.transport},`,\n ' sessionAddress: sessionApiAddress,',\n '});',\n '',\n ];\n}\n\nfunction renderClient(graph: ExtensionGraph, options: RenderOptions, flavor: ClientFlavor): string | undefined {\n const mounts = mountsOf(graph);\n if (mounts.length === 0) return undefined;\n\n const lines = [\n HEADER,\n ...flavor.imports,\n '',\n `import routes from '${routesSpecifier(options.entryDir ?? GENERATED_DIR)}';`,\n '',\n ...mounts.flatMap((mount) => renderMount(mount, flavor)),\n ];\n return `${lines.join('\\n').replace(/\\n+$/u, '')}\\n`;\n}\n\n/**\n * The client source, or undefined when the tree declares no `api/<base-path>/`.\n *\n * `options.entryDir` is where the file will be written, so the relative import\n * of the route table is computed against it rather than assumed.\n */\nexport function renderApiClient(graph: ExtensionGraph, options: RenderOptions): string | undefined {\n return renderClient(graph, options, BROWSER_CLIENT);\n}\n\n/**\n * The same mounts and the same route table for a `.native` file.\n *\n * The route table is imported, never restated, so it must itself import only\n * what the native host provides: a table that imports `@agimon-ai/po-core/web`\n * is refused by the native composition build, which is the intended failure.\n */\nexport function renderNativeApiClient(graph: ExtensionGraph, options: RenderOptions): string | undefined {\n return renderClient(graph, options, NATIVE_CLIENT);\n}\n"],"mappings":"0GAsBA,MAGMI,EAAyC,CAAC,SAAU,YAAa,SAAS,EAUhF,SAASC,EAAc,EAAkB,EAA2B,CAClE,GAAI,CAACC,EAAU,MAAO,MACtB,IAAMC,EAAQP,EAAAA,QAAQQ,CAAQ,CAAC,CAC5B,MAAM,GAAG,CAAC,CACV,OAAQ,GAASC,EAAK,OAAS,CAAC,CAAC,CACjC,KAAK,EAAM,IAAWC,IAAU,EAAID,EAAOA,EAAK,EAAE,EAAE,YAAY,EAAIA,EAAK,MAAM,CAAC,CAAE,CAAC,CACnF,KAAK,EAAE,EACV,MAAO,cAAc,KAAKF,CAAK,EAAIA,EAAQ,MAAMA,GACnD,CAUA,SAASI,EAAc,EAA2C,CAChE,IAAMC,EAAQC,EAAM,MAAM,GAC1B,GAAID,IAAU,IAAA,IAAe,YAAaA,EAC1C,OAAOA,EAAM,OACf,CAEA,SAASE,EAAS,EAAsC,CACtD,IAAMC,kBAAe,IAAI,IACzB,IAAK,IAAMF,KAASG,EAAM,QAAS,CACjC,GAAIH,EAAM,OAAS,WAAaA,EAAM,UAAY,OAASA,EAAM,OAAS,eAAgB,SAC1F,IAAML,EAAWG,EAAcE,CAAK,EACpC,GAAIL,IAAa,IAAA,GAAW,SAC5B,IAAMS,EAAOF,EAAa,IAAIP,CAAQ,mBAAK,IAAI,IAC/CS,EAAK,IAAIJ,EAAM,KAAK,EACpBE,EAAa,IAAIP,EAAUS,CAAI,CACjC,CAEA,IAAMC,EAAQ,CAAC,GAAGH,EAAa,KAAK,CAAC,CAAC,CAAC,KAAK,EAC5C,OAAOG,EAAM,IAAK,GAAa,CAC7B,IAAMC,EAAWJ,EAAa,IAAIP,CAAQ,EAGpCY,EAAahB,EAAY,UAAW,GAAU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,EAAST,CAAc,CACpD,CASA,SAAgBW,EAAsB,EAAuB,EAA4C,CACvG,OAAOJ,EAAahB,EAAOkB,EAASR,CAAa,CACnD"}
1
+ {"version":3,"file":"index.cjs","names":["toKebab","posix","require_index","node_path","SCOPE_ORDER","identifierFor","multiple","camel","basePath","word","index","baseSegmentOf","first","entry","mountsOf","scopesByBase","graph","held","bases","declared","shallowest","scope","routesSpecifier","relative","entryDir","BROWSER_CLIENT","NATIVE_CLIENT","renderMount","scopes","mount","suffix","flavor","renderClient","mounts","options","renderApiClient","renderNativeApiClient"],"sources":["../../../src/services/renderClient/index.ts"],"sourcesContent":["import { posix } from 'node:path';\n\nimport { GENERATED_DIR } from '../../constants/layout';\nimport type { ExtensionEntry, ExtensionGraph, ExtensionScope } from '../../types/extensionGraph';\nimport { toKebab } from '../identity';\nimport type { RenderOptions } from '../renderEntry/type';\n\n/**\n * Renders the typed client a cockpit plugin calls its own API through.\n *\n * The two facts this injects are the two a package kept restating and getting\n * wrong: which scopes its API mounts at, and under which base path. Both are\n * read off the folder tree, so `api/file-edits/route.server.ts` at the session\n * scope is the whole declaration. A package that writes them out again is a\n * package that can disagree with itself, and several did.\n *\n * The route list is not read here. It is authored as plain data in\n * `src/types/apiRoutes.ts`, because this build evaluates no TypeScript and must\n * not learn how: it has no dependencies at all, and every specifier below is\n * emitted as text.\n */\n\nconst HEADER = '// Generated by @agimon-ai/po-build. Do not edit by hand.';\n\n/** Server scopes cascade outward-in, the way the generated server entry mounts them. */\nconst SCOPE_ORDER: readonly ExtensionScope[] = ['host', 'workspace', 'session'];\n\n/** One mount the tree declares: a base path, and the scopes it is reachable at. */\ninterface ClientMount {\n readonly basePath: string;\n readonly scopes: readonly ExtensionScope[];\n /** A valid identifier for the exported factory, when a package has several mounts. */\n readonly identifier: string;\n}\n\nfunction identifierFor(basePath: string, multiple: boolean): string {\n if (!multiple) return 'api';\n const camel = toKebab(basePath)\n .split('-')\n .filter((word) => word.length > 0)\n .map((word, index) => (index === 0 ? word : word[0]?.toUpperCase() + word.slice(1)))\n .join('');\n return /^[A-Za-z_]/u.test(camel) ? camel : `api${camel}`;\n}\n\n/**\n * The base path an api entry mounts at: the first literal segment below `api/`.\n *\n * An entry with no segment is the flat `api/route.server.ts` shape that predates\n * this convention. Its base path lives in a hand-written `PoApi` the build\n * cannot read, so it contributes no client and keeps its hand-built URLs until\n * the folder is renamed.\n */\nfunction baseSegmentOf(entry: ExtensionEntry): string | undefined {\n const first = entry.route[0];\n if (first === undefined || !('literal' in first)) return undefined;\n return first.literal;\n}\n\nfunction mountsOf(graph: ExtensionGraph): ClientMount[] {\n const scopesByBase = new Map<string, Set<ExtensionScope>>();\n for (const entry of graph.entries) {\n if (entry.side !== 'backend' || entry.surface !== 'api' || entry.role !== 'contribution') continue;\n const basePath = baseSegmentOf(entry);\n if (basePath === undefined) continue;\n const held = scopesByBase.get(basePath) ?? new Set<ExtensionScope>();\n held.add(entry.scope);\n scopesByBase.set(basePath, held);\n }\n\n const bases = [...scopesByBase.keys()].sort();\n return bases.map((basePath) => {\n const declared = scopesByBase.get(basePath) as Set<ExtensionScope>;\n // A server plugin offers a contribution at its own scope and every scope below it,\n // so a host API answers workspace and session requests too.\n const shallowest = SCOPE_ORDER.findIndex((scope) => declared.has(scope));\n return {\n basePath,\n scopes: SCOPE_ORDER.slice(shallowest),\n identifier: identifierFor(basePath, bases.length > 1),\n };\n });\n}\n\n/** The extensionless relative specifier from the generated directory to the route table. */\nfunction routesSpecifier(entryDir: string): string {\n const relative = posix.relative(entryDir, 'src/types/apiRoutes');\n return relative.startsWith('.') ? relative : `./${relative}`;\n}\n\n/** What differs between the browser and native clients: where the runtime comes from, and how a call leaves. */\ninterface ClientFlavor {\n readonly imports: readonly string[];\n readonly transport: string;\n}\n\nconst BROWSER_CLIENT: ClientFlavor = {\n imports: [\n \"import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';\",\n \"import { browserTransport } from '@agimon-ai/po-web-security/browser';\",\n ],\n transport: '(input, init) => browserTransport.fetch(input, init)',\n};\n\n/**\n * Only `@agimon-ai/po-core/native`, the one Po module on the native host list.\n * The phone's sealed channel and step-up live in the app shell, which binds\n * them behind `nativeApiTransport`.\n */\nconst NATIVE_CLIENT: ClientFlavor = {\n imports: [\"import { createApiClient, nativeApiTransport, sessionApiAddress } from '@agimon-ai/po-core/native';\"],\n transport: 'nativeApiTransport',\n};\n\nfunction renderMount(mount: ClientMount, flavor: ClientFlavor): string[] {\n const scopes = mount.scopes.map((scope) => `'${scope}'`).join(', ');\n const suffix = mount.identifier === 'api' ? '' : ` for the ${mount.basePath} mount`;\n return [\n `/** Scopes the tree mounts '${mount.basePath}' at${suffix}. */`,\n `export const ${mount.identifier}Scopes = [${scopes}] as const;`,\n '',\n `export const ${mount.identifier} = createApiClient(routes, {`,\n ` scopes: ${mount.identifier}Scopes,`,\n ` basePath: '${mount.basePath}',`,\n ` transport: ${flavor.transport},`,\n ' sessionAddress: sessionApiAddress,',\n '});',\n '',\n ];\n}\n\nfunction renderClient(graph: ExtensionGraph, options: RenderOptions, flavor: ClientFlavor): string | undefined {\n const mounts = mountsOf(graph);\n if (mounts.length === 0) return undefined;\n\n const lines = [\n HEADER,\n ...flavor.imports,\n '',\n `import { routes } from '${routesSpecifier(options.entryDir ?? GENERATED_DIR)}';`,\n '',\n ...mounts.flatMap((mount) => renderMount(mount, flavor)),\n ];\n return `${lines.join('\\n').replace(/\\n+$/u, '')}\\n`;\n}\n\n/**\n * The client source, or undefined when the tree declares no `api/<base-path>/`.\n *\n * `options.entryDir` is where the file will be written, so the relative import\n * of the route table is computed against it rather than assumed.\n */\nexport function renderApiClient(graph: ExtensionGraph, options: RenderOptions): string | undefined {\n return renderClient(graph, options, BROWSER_CLIENT);\n}\n\n/**\n * The same mounts and the same route table for a `.native` file.\n *\n * The route table is imported, never restated, so it must itself import only\n * what the native host provides: a table that imports `@agimon-ai/po-core/web`\n * is refused by the native composition build, which is the intended failure.\n */\nexport function renderNativeApiClient(graph: Extens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CACnD,C"}
@@ -1,3 +1,3 @@
1
- import"../../constants/layout.mjs";import{toKebab as e}from"../identity/index.mjs";import{posix as t}from"node:path";const n=[`global`,`workspace`,`session`];function r(t,n){if(!n)return`api`;let r=e(t).split(`-`).filter(e=>e.length>0).map((e,t)=>t===0?e:e[0]?.toUpperCase()+e.slice(1)).join(``);return/^[A-Za-z_]/u.test(r)?r:`api${r}`}function i(e){let t=e.route[0];if(t!==void 0&&`literal`in t)return t.literal}function a(e){let t=/* @__PURE__ */ new Map;for(let n of e.entries){if(n.side!==`backend`||n.surface!==`api`||n.role!==`contribution`)continue;let e=i(n);if(e===void 0)continue;let r=t.get(e)??/* @__PURE__ */ new Set;r.add(n.scope),t.set(e,r)}let a=[...t.keys()].sort();return a.map(e=>{let i=t.get(e),o=n.findIndex(e=>i.has(e));return{basePath:e,scopes:n.slice(o),identifier:r(e,a.length>1)}})}function o(e){let n=t.relative(e,`src/types/apiRoutes`);return n.startsWith(`.`)?n:`./${n}`}const s={imports:[`import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';`,`import { sealedTransport } from '@agimon-ai/po-web-security/browser';`],transport:`(input, init) => sealedTransport.fetch(input, init)`},c={imports:[`import { createApiClient, nativeApiTransport, sessionApiAddress } from '@agimon-ai/po-core/native';`],transport:`nativeApiTransport`};function l(e,t){let n=e.scopes.map(e=>`'${e}'`).join(`, `),r=e.identifier===`api`?``:` for the ${e.basePath} mount`;return[`/** Scopes the tree mounts '${e.basePath}' at${r}. */`,`export const ${e.identifier}Scopes = [${n}] as const;`,``,`export const ${e.identifier} = createApiClient(routes, {`,` scopes: ${e.identifier}Scopes,`,` basePath: '${e.basePath}',`,` transport: ${t.transport},`,` sessionAddress: sessionApiAddress,`,`});`,``]}function u(e,t,n){let r=a(e);if(r.length!==0)return`${[`// Generated by @agimon-ai/po-build. Do not edit by hand.`,...n.imports,``,`import routes from '${o(t.entryDir??`generated`)}';`,``,...r.flatMap(e=>l(e,n))].join(`
1
+ import"../../constants/layout.mjs";import{toKebab as e}from"../identity/index.mjs";import{posix as t}from"node:path";const n=[`host`,`workspace`,`session`];function r(t,n){if(!n)return`api`;let r=e(t).split(`-`).filter(e=>e.length>0).map((e,t)=>t===0?e:e[0]?.toUpperCase()+e.slice(1)).join(``);return/^[A-Za-z_]/u.test(r)?r:`api${r}`}function i(e){let t=e.route[0];if(t!==void 0&&`literal`in t)return t.literal}function a(e){let t=/* @__PURE__ */ new Map;for(let n of e.entries){if(n.side!==`backend`||n.surface!==`api`||n.role!==`contribution`)continue;let e=i(n);if(e===void 0)continue;let r=t.get(e)??/* @__PURE__ */ new Set;r.add(n.scope),t.set(e,r)}let a=[...t.keys()].sort();return a.map(e=>{let i=t.get(e),o=n.findIndex(e=>i.has(e));return{basePath:e,scopes:n.slice(o),identifier:r(e,a.length>1)}})}function o(e){let n=t.relative(e,`src/types/apiRoutes`);return n.startsWith(`.`)?n:`./${n}`}const s={imports:[`import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';`,`import { browserTransport } from '@agimon-ai/po-web-security/browser';`],transport:`(input, init) => browserTransport.fetch(input, init)`},c={imports:[`import { createApiClient, nativeApiTransport, sessionApiAddress } from '@agimon-ai/po-core/native';`],transport:`nativeApiTransport`};function l(e,t){let n=e.scopes.map(e=>`'${e}'`).join(`, `),r=e.identifier===`api`?``:` for the ${e.basePath} mount`;return[`/** Scopes the tree mounts '${e.basePath}' at${r}. */`,`export const ${e.identifier}Scopes = [${n}] as const;`,``,`export const ${e.identifier} = createApiClient(routes, {`,` scopes: ${e.identifier}Scopes,`,` basePath: '${e.basePath}',`,` transport: ${t.transport},`,` sessionAddress: sessionApiAddress,`,`});`,``]}function u(e,t,n){let r=a(e);if(r.length!==0)return`${[`// Generated by @agimon-ai/po-build. Do not edit by hand.`,...n.imports,``,`import { routes } from '${o(t.entryDir??`generated`)}';`,``,...r.flatMap(e=>l(e,n))].join(`
2
2
  `).replace(/\n+$/u,``)}\n`}function d(e,t){return u(e,t,s)}function f(e,t){return u(e,t,c)}export{d as renderApiClient,f as renderNativeApiClient};
3
3
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["SCOPE_ORDER","identifierFor","multiple","camel","toKebab","basePath","word","index","baseSegmentOf","first","entry","mountsOf","scopesByBase","graph","held","bases","declared","shallowest","scope","routesSpecifier","relative","posix","entryDir","BROWSER_CLIENT","NATIVE_CLIENT","renderMount","scopes","mount","suffix","flavor","renderClient","mounts","options","renderApiClient","renderNativeApiClient"],"sources":["../../../src/services/renderClient/index.ts"],"sourcesContent":["import { posix } from 'node:path';\n\nimport { GENERATED_DIR } from '../../constants/layout';\nimport type { ExtensionEntry, ExtensionGraph, ExtensionScope } from '../../types/extensionGraph';\nimport { toKebab } from '../identity';\nimport type { RenderOptions } from '../renderEntry/type';\n\n/**\n * Renders the typed client a cockpit plugin calls its own API through.\n *\n * The two facts this injects are the two a package kept restating and getting\n * wrong: which scopes its API mounts at, and under which base path. Both are\n * read off the folder tree, so `api/file-edits/route.server.ts` at the session\n * scope is the whole declaration. A package that writes them out again is a\n * package that can disagree with itself, and several did.\n *\n * The route list is not read here. It is authored as plain data in\n * `src/types/apiRoutes.ts`, because this build evaluates no TypeScript and must\n * not learn how: it has no dependencies at all, and every specifier below is\n * emitted as text.\n */\n\nconst HEADER = '// Generated by @agimon-ai/po-build. Do not edit by hand.';\n\n/** Server scopes cascade outward-in, the way the generated server entry mounts them. */\nconst SCOPE_ORDER: readonly ExtensionScope[] = ['global', 'workspace', 'session'];\n\n/** One mount the tree declares: a base path, and the scopes it is reachable at. */\ninterface ClientMount {\n readonly basePath: string;\n readonly scopes: readonly ExtensionScope[];\n /** A valid identifier for the exported factory, when a package has several mounts. */\n readonly identifier: string;\n}\n\nfunction identifierFor(basePath: string, multiple: boolean): string {\n if (!multiple) return 'api';\n const camel = toKebab(basePath)\n .split('-')\n .filter((word) => word.length > 0)\n .map((word, index) => (index === 0 ? word : word[0]?.toUpperCase() + word.slice(1)))\n .join('');\n return /^[A-Za-z_]/u.test(camel) ? camel : `api${camel}`;\n}\n\n/**\n * The base path an api entry mounts at: the first literal segment below `api/`.\n *\n * An entry with no segment is the flat `api/route.server.ts` shape that predates\n * this convention. Its base path lives in a hand-written `PoApi` the build\n * cannot read, so it contributes no client and keeps its hand-built URLs until\n * the folder is renamed.\n */\nfunction baseSegmentOf(entry: ExtensionEntry): string | undefined {\n const first = entry.route[0];\n if (first === undefined || !('literal' in first)) return undefined;\n return first.literal;\n}\n\nfunction mountsOf(graph: ExtensionGraph): ClientMount[] {\n const scopesByBase = new Map<string, Set<ExtensionScope>>();\n for (const entry of graph.entries) {\n if (entry.side !== 'backend' || entry.surface !== 'api' || entry.role !== 'contribution') continue;\n const basePath = baseSegmentOf(entry);\n if (basePath === undefined) continue;\n const held = scopesByBase.get(basePath) ?? new Set<ExtensionScope>();\n held.add(entry.scope);\n scopesByBase.set(basePath, held);\n }\n\n const bases = [...scopesByBase.keys()].sort();\n return bases.map((basePath) => {\n const declared = scopesByBase.get(basePath) as Set<ExtensionScope>;\n // A server plugin offers a contribution at its own scope and every scope below it,\n // so a global API answers workspace and session requests too.\n const shallowest = SCOPE_ORDER.findIndex((scope) => declared.has(scope));\n return {\n basePath,\n scopes: SCOPE_ORDER.slice(shallowest),\n identifier: identifierFor(basePath, bases.length > 1),\n };\n });\n}\n\n/** The extensionless relative specifier from the generated directory to the route table. */\nfunction routesSpecifier(entryDir: string): string {\n const relative = posix.relative(entryDir, 'src/types/apiRoutes');\n return relative.startsWith('.') ? relative : `./${relative}`;\n}\n\n/** What differs between the browser and native clients: where the runtime comes from, and how a call leaves. */\ninterface ClientFlavor {\n readonly imports: readonly string[];\n readonly transport: string;\n}\n\nconst BROWSER_CLIENT: ClientFlavor = {\n imports: [\n \"import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';\",\n \"import { sealedTransport } from '@agimon-ai/po-web-security/browser';\",\n ],\n transport: '(input, init) => sealedTransport.fetch(input, init)',\n};\n\n/**\n * Only `@agimon-ai/po-core/native`, the one Po module on the native host list.\n * The phone's sealed channel and step-up live in the app shell, which binds\n * them behind `nativeApiTransport`.\n */\nconst NATIVE_CLIENT: ClientFlavor = {\n imports: [\"import { createApiClient, nativeApiTransport, sessionApiAddress } from '@agimon-ai/po-core/native';\"],\n transport: 'nativeApiTransport',\n};\n\nfunction renderMount(mount: ClientMount, flavor: ClientFlavor): string[] {\n const scopes = mount.scopes.map((scope) => `'${scope}'`).join(', ');\n const suffix = mount.identifier === 'api' ? '' : ` for the ${mount.basePath} mount`;\n return [\n `/** Scopes the tree mounts '${mount.basePath}' at${suffix}. */`,\n `export const ${mount.identifier}Scopes = [${scopes}] as const;`,\n '',\n `export const ${mount.identifier} = createApiClient(routes, {`,\n ` scopes: ${mount.identifier}Scopes,`,\n ` basePath: '${mount.basePath}',`,\n ` transport: ${flavor.transport},`,\n ' sessionAddress: sessionApiAddress,',\n '});',\n '',\n ];\n}\n\nfunction renderClient(graph: ExtensionGraph, options: RenderOptions, flavor: ClientFlavor): string | undefined {\n const mounts = mountsOf(graph);\n if (mounts.length === 0) return undefined;\n\n const lines = [\n HEADER,\n ...flavor.imports,\n '',\n `import routes from '${routesSpecifier(options.entryDir ?? GENERATED_DIR)}';`,\n '',\n ...mounts.flatMap((mount) => renderMount(mount, flavor)),\n ];\n return `${lines.join('\\n').replace(/\\n+$/u, '')}\\n`;\n}\n\n/**\n * The client source, or undefined when the tree declares no `api/<base-path>/`.\n *\n * `options.entryDir` is where the file will be written, so the relative import\n * of the route table is computed against it rather than assumed.\n */\nexport function renderApiClient(graph: ExtensionGraph, options: RenderOptions): string | undefined {\n return renderClient(graph, options, BROWSER_CLIENT);\n}\n\n/**\n * The same mounts and the same route table for a `.native` file.\n *\n * The route table is imported, never restated, so it must itself import only\n * what the native host provides: a table that imports `@agimon-ai/po-core/web`\n * is refused by the native composition build, which is the intended failure.\n */\nexport function renderNativeApiClient(graph: ExtensionGraph, options: RenderOptions): string | undefined {\n return render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","identifierFor","multiple","camel","toKebab","basePath","word","index","baseSegmentOf","first","entry","mountsOf","scopesByBase","graph","held","bases","declared","shallowest","scope","routesSpecifier","relative","posix","entryDir","BROWSER_CLIENT","NATIVE_CLIENT","renderMount","scopes","mount","suffix","flavor","renderClient","mounts","options","renderApiClient","renderNativeApiClient"],"sources":["../../../src/services/renderClient/index.ts"],"sourcesContent":["import { posix } from 'node:path';\n\nimport { GENERATED_DIR } from '../../constants/layout';\nimport type { ExtensionEntry, ExtensionGraph, ExtensionScope } from '../../types/extensionGraph';\nimport { toKebab } from '../identity';\nimport type { RenderOptions } from '../renderEntry/type';\n\n/**\n * Renders the typed client a cockpit plugin calls its own API through.\n *\n * The two facts this injects are the two a package kept restating and getting\n * wrong: which scopes its API mounts at, and under which base path. Both are\n * read off the folder tree, so `api/file-edits/route.server.ts` at the session\n * scope is the whole declaration. A package that writes them out again is a\n * package that can disagree with itself, and several did.\n *\n * The route list is not read here. It is authored as plain data in\n * `src/types/apiRoutes.ts`, because this build evaluates no TypeScript and must\n * not learn how: it has no dependencies at all, and every specifier below is\n * emitted as text.\n */\n\nconst HEADER = '// Generated by @agimon-ai/po-build. Do not edit by hand.';\n\n/** Server scopes cascade outward-in, the way the generated server entry mounts them. */\nconst SCOPE_ORDER: readonly ExtensionScope[] = ['host', 'workspace', 'session'];\n\n/** One mount the tree declares: a base path, and the scopes it is reachable at. */\ninterface ClientMount {\n readonly basePath: string;\n readonly scopes: readonly ExtensionScope[];\n /** A valid identifier for the exported factory, when a package has several mounts. */\n readonly identifier: string;\n}\n\nfunction identifierFor(basePath: string, multiple: boolean): string {\n if (!multiple) return 'api';\n const camel = toKebab(basePath)\n .split('-')\n .filter((word) => word.length > 0)\n .map((word, index) => (index === 0 ? word : word[0]?.toUpperCase() + word.slice(1)))\n .join('');\n return /^[A-Za-z_]/u.test(camel) ? camel : `api${camel}`;\n}\n\n/**\n * The base path an api entry mounts at: the first literal segment below `api/`.\n *\n * An entry with no segment is the flat `api/route.server.ts` shape that predates\n * this convention. Its base path lives in a hand-written `PoApi` the build\n * cannot read, so it contributes no client and keeps its hand-built URLs until\n * the folder is renamed.\n */\nfunction baseSegmentOf(entry: ExtensionEntry): string | undefined {\n const first = entry.route[0];\n if (first === undefined || !('literal' in first)) return undefined;\n return first.literal;\n}\n\nfunction mountsOf(graph: ExtensionGraph): ClientMount[] {\n const scopesByBase = new Map<string, Set<ExtensionScope>>();\n for (const entry of graph.entries) {\n if (entry.side !== 'backend' || entry.surface !== 'api' || entry.role !== 'contribution') continue;\n const basePath = baseSegmentOf(entry);\n if (basePath === undefined) continue;\n const held = scopesByBase.get(basePath) ?? new Set<ExtensionScope>();\n held.add(entry.scope);\n scopesByBase.set(basePath, held);\n }\n\n const bases = [...scopesByBase.keys()].sort();\n return bases.map((basePath) => {\n const declared = scopesByBase.get(basePath) as Set<ExtensionScope>;\n // A server plugin offers a contribution at its own scope and every scope below it,\n // so a host API answers workspace and session requests too.\n const shallowest = SCOPE_ORDER.findIndex((scope) => declared.has(scope));\n return {\n basePath,\n scopes: SCOPE_ORDER.slice(shallowest),\n identifier: identifierFor(basePath, bases.length > 1),\n };\n });\n}\n\n/** The extensionless relative specifier from the generated directory to the route table. */\nfunction routesSpecifier(entryDir: string): string {\n const relative = posix.relative(entryDir, 'src/types/apiRoutes');\n return relative.startsWith('.') ? relative : `./${relative}`;\n}\n\n/** What differs between the browser and native clients: where the runtime comes from, and how a call leaves. */\ninterface ClientFlavor {\n readonly imports: readonly string[];\n readonly transport: string;\n}\n\nconst BROWSER_CLIENT: ClientFlavor = {\n imports: [\n \"import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';\",\n \"import { browserTransport } from '@agimon-ai/po-web-security/browser';\",\n ],\n transport: '(input, init) => browserTransport.fetch(input, init)',\n};\n\n/**\n * Only `@agimon-ai/po-core/native`, the one Po module on the native host list.\n * The phone's sealed channel and step-up live in the app shell, which binds\n * them behind `nativeApiTransport`.\n */\nconst NATIVE_CLIENT: ClientFlavor = {\n imports: [\"import { createApiClient, nativeApiTransport, sessionApiAddress } from '@agimon-ai/po-core/native';\"],\n transport: 'nativeApiTransport',\n};\n\nfunction renderMount(mount: ClientMount, flavor: ClientFlavor): string[] {\n const scopes = mount.scopes.map((scope) => `'${scope}'`).join(', ');\n const suffix = mount.identifier === 'api' ? '' : ` for the ${mount.basePath} mount`;\n return [\n `/** Scopes the tree mounts '${mount.basePath}' at${suffix}. */`,\n `export const ${mount.identifier}Scopes = [${scopes}] as const;`,\n '',\n `export const ${mount.identifier} = createApiClient(routes, {`,\n ` scopes: ${mount.identifier}Scopes,`,\n ` basePath: '${mount.basePath}',`,\n ` transport: ${flavor.transport},`,\n ' sessionAddress: sessionApiAddress,',\n '});',\n '',\n ];\n}\n\nfunction renderClient(graph: ExtensionGraph, options: RenderOptions, flavor: ClientFlavor): string | undefined {\n const mounts = mountsOf(graph);\n if (mounts.length === 0) return undefined;\n\n const lines = [\n HEADER,\n ...flavor.imports,\n '',\n `import { routes } from '${routesSpecifier(options.entryDir ?? GENERATED_DIR)}';`,\n '',\n ...mounts.flatMap((mount) => renderMount(mount, flavor)),\n ];\n return `${lines.join('\\n').replace(/\\n+$/u, '')}\\n`;\n}\n\n/**\n * The client source, or undefined when the tree declares no `api/<base-path>/`.\n *\n * `options.entryDir` is where the file will be written, so the relative import\n * of the route table is computed against it rather than assumed.\n */\nexport function renderApiClient(graph: ExtensionGraph, options: RenderOptions): string | undefined {\n return renderClient(graph, options, BROWSER_CLIENT);\n}\n\n/**\n * The same mounts and the same route table for a `.native` file.\n *\n * The route table is imported, never restated, so it must itself import only\n * what the native host provides: a table that imports `@agimon-ai/po-core/web`\n * is refused by the native composition build, which is the intended failure.\n */\nexport function renderNativeApiClient(graph: ExtensionGraph, options: RenderOptions): string | undefined {\n return renderClient(graph, options, NATIVE_CLIENT);\n}\n"],"mappings":"A,qHAsBA,MAGMA,EAAyC,CAAC,OAAQ,YAAa,SAAS,EAU9E,SAASC,EAAc,EAAkB,EAA2B,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A,EAAW,KAAKA,GACpD,CAQA,MAAMG,EAA+B,CACnC,QAAS,CACP,+EACA,wEACF,EACA,UAAW,sDACb,EAOMC,EAA8B,CAClC,QAAS,CAAC,qGAAqG,EAC/G,UAAW,oBACb,EAEA,SAASC,EAAY,EAAoB,EAAgC,CACvE,IAAMC,EAASC,EAAM,OAAO,IAAK,GAAU,IAAIT,EAAM,EAAE,CAAC,CAAC,KAAK,IAAI,EAC5DU,EAASD,EAAM,aAAe,MAAQ,GAAK,YAAYA,EAAM,SAAS,QAC5E,MAAO,CACL,+BAA+BA,EAAM,SAAS,MAAMC,EAAO,MAC3D,gBAAgBD,EAAM,WAAW,YAAYD,EAAO,aACpD,GACA,gBAAgBC,EAAM,WAAW,8BACjC,aAAaA,EAAM,WAAW,SAC9B,gBAAgBA,EAAM,SAAS,IAC/B,gBAAgBE,EAAO,UAAU,GACjC,uCACA,MACA,EACF,CACF,CAEA,SAASC,EAAa,EAAuB,EAAwB,EAA0C,CAC7G,IAAMC,EAASpB,EAASE,CAAK,EAC7B,GAAIkB,EAAO,SAAW,EAUtB,MAAO,GAAG,CAPR,4DACA,GAAGF,EAAO,QACV,GACA,2BAA2BV,EAAgBa,EAAQ,UAAA,WAAyB,EAAE,IAC9E,GACA,GAAGD,EAAO,QAAS,GAAUN,EAAYE,EAAOE,CAAM,CAAC,CAE3C,CAAC,CAAC,KAAK;CAAI,CAAC,CAAC,QAAQ,QAAS,EAAE,EAAE,GAClD,CAQA,SAAgBI,EAAgB,EAAuB,EAA4C,CACjG,OAAOH,EAAajB,EAAOmB,EAAST,CAAc,CACpD,CASA,SAAgBW,EAAsB,EAAuB,EAA4C,CACvG,OAAOJ,EAAajB,EAAOmB,EAASR,CAAa,CACnD,C"}
@@ -1,7 +1,7 @@
1
- const e=require("../resolveTarget/index.cjs"),t=require("../identity/index.cjs");let n=require("node:path");const r=`// Generated by @agimon-ai/po-build. Do not edit by hand.`,i=[`fileLinks`,`repositorySettingsPanel`,`start`],a={server:[`channels`],web:[],native:[],mcp:[]},o=[`services`],s=[`global`,`workspace`,`session`],c={server:`PoServerSessionPlugin`,web:`WebPluginContributions`,native:`WebPluginContributions`,mcp:`PoMcpSessionPlugin`};function l(){return[`type Factory<T, C> = (context: C) => T;`,`const at = <T, C>(value: T | Factory<T, C>, context: C): T =>`,` typeof value === 'function' ? (value as Factory<T, C>)(context) : value;`].join(`
1
+ const e=require("../resolveTarget/index.cjs"),t=require("../identity/index.cjs");let n=require("node:path");const r=`// Generated by @agimon-ai/po-build. Do not edit by hand.`,i=[`fileLinks`,`repositorySettingsPanel`,`start`,`provider`],a={server:[`channels`],web:[],native:[],mcp:[]},o=[`services`],s=[`host`,`workspace`,`session`],c={server:`PoServerSessionPlugin`,web:`WebPluginContributions`,native:`WebPluginContributions`,mcp:`PoMcpSessionPlugin`};function l(){return[`type Factory<T, C> = (context: C) => T;`,`const at = <T, C>(value: T | Factory<T, C>, context: C): T =>`,` typeof value === 'function' ? (value as Factory<T, C>)(context) : value;`].join(`
2
2
  `)}function u(){return[`type ManyFactory<T, C> = (context: C) => T | readonly T[];`,`const many = <T, C>(value: T | readonly T[] | ManyFactory<T, C>, context: C): readonly T[] => {`,` const resolved = typeof value === 'function' ? (value as ManyFactory<T, C>)(context) : value;`,` return Array.isArray(resolved) ? resolved : [resolved as T];`,`};`].join(`
3
3
  `)}function d(){return[`/* v8 ignore next -- generated normalization branch */`,`const defined = <T>(values: readonly (T | undefined)[]): T[] =>`,` values.filter((value): value is T => value !== undefined);`].join(`
4
- `)}const f=[`const via = <T>(identity: Record<string, unknown>, value: unknown): T =>`,` (value === undefined ? undefined : { ...identity, ...(value as object) }) as T;`].join(`
5
- `);function p(e,n){return n===void 0?{id:t.toKebab(e)}:{slot:n,id:t.toKebab(e)}}const m={tool:e=>({name:t.toSnake(e)}),command:e=>({name:t.toKebab(e)}),channel:e=>({frameType:t.toSnake(e)}),hook:e=>({event:t.toSnake(e)}),mode:e=>({name:t.toKebab(e)})},h={tool:e=>({tools:[t.toSnake(e)]}),channel:e=>({channel:t.toSnake(e)}),slot:(e,n)=>({slot:`${n.pluginId}.${t.toKebab(e)}`}),command:e=>({id:t.toKebab(e)}),tab:e=>({id:t.toKebab(e)}),template:e=>({id:t.toKebab(e)}),dock:e=>({id:t.toKebab(e)}),setting:e=>({id:t.toKebab(e)}),action:e=>({id:t.toKebab(e)}),mode:e=>({name:t.toKebab(e)}),"activity-group":e=>({name:t.toKebab(e)}),"selection-axis":e=>({name:t.toKebab(e)}),leader:(e,n)=>({id:`${n.pluginId}.${t.toKebab(e)}`})};function g(t,n,r){let{entry:i}=t,a=i.surface;if(a!==void 0)return e.isFrontendTarget(n)?a===`fill`?p(i.name,i.target):h[a]?.(i.name,r):m[a]?.(i.name)}function _(e,t){let n=e.join(`-`).split(/[^A-Za-z0-9]+/u).filter(e=>e.length>0).map((e,t)=>t===0?e:e[0]?.toUpperCase()+e.slice(1)).join(``),r=/^[A-Za-z_]/u.test(n)?n:`x${n}`,i=r,a=2;for(;t.has(i);)i=`${r}${a++}`;return t.add(i),i}function v(e,t){return _([e.entry.surface??`extra`,e.entry.name],t)}function y(e,t){let r=e.replace(/\.[^.]+$/u,``),i=n.posix.relative(t,r);return i.startsWith(`.`)?i:`./${i}`}function b(e){return JSON.stringify(e).replaceAll(`<`,`\\u003c`).replaceAll(`\u2028`,`\\u2028`).replaceAll(`\u2029`,`\\u2029`)}function x(e,t){let n=/* @__PURE__ */ new Set;return[...e.contributions].sort((e,t)=>e.entry.file.localeCompare(t.entry.file)).map(r=>{let i=v(r,n),a=e.target===`mcp`?t.mcpWidgets?.[r.entry.file]:void 0;if(a!==void 0&&!/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*\/[a-z0-9_]+$/u.test(a))throw Error(`Invalid MCP widget key '${a}'`);return{identifier:i,contribution:r,identity:g(r,e.target,t),mcpWidget:a}})}const S={global:0,workspace:1,session:2};function C(e){return e.map(e=>{let t=e.scope[0]?.toUpperCase()+e.scope.slice(1);return{identifier:`root${t}`,declaration:`scope${t}`,context:`context${t}`,entry:e}})}function w(e,t,n){let r=[],i=t;for(let[a,o]of e.entries())r.push(`const ${o.declaration} = await ${t}.scopeRoot('${o.entry.scope}', ${o.identifier}, ${i});`),(a<e.length-1||n.some(e=>e.includes(o.context)))&&r.push(`const ${o.context} = { ...${i}, root: ${o.declaration}.value };`),i=o.context;return r}function T(e,t,n){let r=n;for(let n of e)S[n.entry.scope]<=S[t]&&(r=n.context);return r}function E(e,t,n){let r=e.contribution.entry.scope;if(S[r]>=S[n])return;let{field:i}=e.contribution;return i===`channels`||t.some(e=>S[e.entry.scope]<=S[r])&&(i===`api`||i===`methods`)?r:void 0}function D(e,t){if(t===void 0)return e;let n=`context.hosted('${t}')`;return e.startsWith(`...`)?`...(${n} ? [] : ${e.slice(3)})`:`${n} ? undefined : ${e}`}function O(e){let{entry:n,field:r}=e.contribution;if(r===`hooks`)return;let i=n.gates.map(e=>`${e.kind}:${e.id}`).join(`/`);return r===`api`?`${i}|api|${n.route.map(e=>`literal`in e?e.literal:`[${e.param.name}]`).join(`/`)}`:e.identity===void 0?void 0:`${i}|${r}|${t.renderIdentity(e.identity)}`}function k(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=O(n);e!==void 0&&t.set(e,Math.max(t.get(e)??-1,S[n.contribution.entry.scope]))}return e.filter(e=>{let n=O(e);return n===void 0||t.get(n)===S[e.contribution.entry.scope]})}function A(e){return[...e].sort((e,t)=>e.file.localeCompare(t.file)).map((e,t)=>({identifier:`extra${t===0?``:t+1}`,entry:e}))}function j(e){let t=/* @__PURE__ */ new Set;return e.map(e=>({identifier:_([`contract`,e.name],t),entry:e}))}function M(n,r,i){if(o.includes(n.contribution.field))return`${n.identifier}(${r})`;let s=e.isFrontendTarget(i)?n.identifier:`at(${n.identifier}, ${r})`,c=a[i].includes(n.contribution.field);if(n.contribution.entry.cardinality===`collection`)return s;if(n.identity===void 0)return c?n.identifier:s;let l=t.renderIdentity(n.identity);if(c)return`() => via({ ${l} }, ${n.identifier}())`;let u=`via({ ${l} }, ${s})`;return n.mcpWidget===void 0?u:`withWidget(${b(n.mcpWidget)}, ${u})`}function N(e){return`import { ${[`defineServerPlugin`,...e.some(e=>e.includes(`get `))?[`type PoServerSessionPlugin`]:[]].join(`, `)} } from '@agimon-ai/po-core/serverPlugin';`}function P(e,t,n){if(e===`services`||t.startsWith(`...`))return t;let[r,...i]=t.split(`: `);return`get ${r}(): ${`${c[n]}['${r}']`} { return ${i.join(`: `).replace(/,$/u,``)}; },`}function F(e,t,n,r,a=()=>void 0){let o=/* @__PURE__ */ new Map;for(let t of e){let e=o.get(t.contribution.field);e===void 0?o.set(t.contribution.field,[t]):e.push(t)}let s=[];for(let e of[...o.keys()].sort()){let c=o.get(e);if(i.includes(e)){let i=c[0];if(i){let a=M(i,n(i),r);s.push(`${t}${P(e,`${e}: ${a},`,r)}`)}continue}let l=`[${c.map(e=>D(e.contribution.entry.cardinality===`many`?`...many(${e.identifier}, ${n(e)})${e.mcpWidget===void 0?``:`.map((tool) => withWidget(${b(e.mcpWidget)}, tool))`}`:M(e,n(e),r),a(e))).join(`, `)}]`,u=c.some(e=>e.contribution.entry.cardinality===`optional`||e.contribution.entry.cardinality!==`many`&&a(e)!==void 0)?`defined(${l})`:l;s.push(`${t}${P(e,`${e}: ${u},`,r)}`)}return s}function I(e,t,n,r,i){if(t.length===0)return[...e];let a=[...e],o=a.findIndex(e=>e.startsWith(`${r}services: [`)),s=o<0?``:a.splice(o,1)[0]?.match(/services: \[(.*)\],$/u)?.[1]??``,c=[...t.map(e=>`...(${e.declaration}.services ?? [])`),s].filter(Boolean).join(`, `);if(a.push(`${r}services: [${c}],`),n===`server`&&i===`session`){let e=a.findIndex(e=>e.startsWith(`${r}get activities()`)),n=e<0?``:a.splice(e,1)[0]?.match(/return \[(.*)\]; \},$/u)?.[1]??``,i=[...t.map(e=>`...(${e.declaration}.activities ?? [])`),n].filter(Boolean).join(`, `);a.push(`${r}get activities(): PoServerSessionPlugin['activities'] { return [${i}]; },`)}return a}function L(e,t,n,r,i=[]){return[...n.map(e=>`import ${e.identifier} from '${y(e.entry.file,r)}';`),...i.map(e=>`import ${e.identifier} from '${y(e.entry.file,r)}';`),...e.map(e=>`import ${e.identifier} from '${y(e.contribution.entry.file,r)}';`),...t.map(e=>`import ${e.identifier} from '${y(e.entry.file,r)}';`)]}function R(e){return e.filter((e,t,n)=>e!==``||n[t-1]!==``).join(`
6
- `)}function z(e){let t=[];return e.some(e=>e.includes(`at(`))&&t.push(l()),e.some(e=>e.includes(`many(`))&&t.push(u()),e.some(e=>e.includes(`defined(`))&&t.push(d()),e.some(e=>e.includes(`via(`))&&t.push(f),t.length>0?[...t,``]:[]}function B(e){return e.some(e=>/\bcontext[.,)]/u.test(e))?`(context)`:`()`}function V(e,t,n,r){let i=[...t===void 0?[]:[`${r} ${t}`],...n],a=[...e,...n].some(e=>e.includes(`await `))?`async `:``;return e.length===0?[`${a}${B(n)} => ({`,...i,`${r}}),`]:[`${a}${B([...e,...n])} => {`,...e.map(e=>`${r} ${e}`),`${r} return {`,...i.map(e=>` ${e}`),`${r} };`,`${r}},`]}function H(e){if(e.length!==0)return`...composeRootHooks(${e.map(e=>e.declaration).join(`, `)}),`}function U(e,t){let n=x(e,t),i=A(e.escapeHatches),a=C(e.roots),o=j(e.contracts),c=[],l=[],u=!1;for(let[e,t]of s.entries()){let r=k(n.filter(t=>s.indexOf(t.contribution.entry.scope)<=e)),o=i.filter(t=>s.indexOf(t.entry.scope)<=e),d=a.filter(t=>s.indexOf(t.entry.scope)<=e),f=d[d.length-1]?.context??`context`,p=[...I(F(r,` `,e=>T(d,e.contribution.entry.scope,`context`),`server`,e=>E(e,d,t)),d,`server`,` `,t),...o.map(e=>` ...await at(${e.identifier}, ${f}),`)];if(p.length===0&&d.length===0)continue;d.length>0&&(u=!0,l.push(`${t}: [${d.map(e=>e.identifier).join(`, `)}]`));let m=V(w(d,`context`,p),H(d),p,` `);c.push(` ${t}: ${m[0]}`,...m.slice(1))}let d=s.flatMap(e=>{let t=o.filter(t=>t.entry.scope===e);return t.length===0?[]:[` ${e}: [${t.map(e=>e.identifier).join(`, `)}],`]});return R([r,N(c),...a.length?[`import { composeServerProviderOverrides } from '@agimon-ai/po-core/serverPlugin';`]:[],...u?[`import { composeRootHooks, composeRootInjects } from '@agimon-ai/po-core/extensionFile';`]:[],``,...L(n,i,a,t.entryDir,o),``,...z(c),`export const serverPlugin = defineServerPlugin({`,` name: '${t.packageName}',`,...a.length?[` providerOverrides: composeServerProviderOverrides(${a.map(e=>e.identifier).join(`, `)}),`]:[],...d.length>0?[` provides: {`,...d,` },`]:[],...l.length>0?[` injects: composeRootInjects({ ${l.join(`, `)} }),`]:[],...c,`});`,``,`export default serverPlugin;`,``])}function W(e,t){let n=x(e,t),i=F(n,` `,()=>`context`,`mcp`);return R([r,`import { defineMcpPlugin, type PoMcpSessionPlugin } from '@agimon-ai/po-core/mcpFacet';`,``,...L(n,[],[],t.entryDir),``,...z(i),...n.some(e=>e.mcpWidget!==void 0)?[`const withWidget = <T>(key: string, value: T): T => value === undefined ? value : ({`,` ...value, _meta: { ...(value as { _meta?: object })._meta, ["po/widget"]: key },`,`});`,``]:[],`export const mcp = defineMcpPlugin({`,` name: '${t.packageName}',`,` session: (context) => ({`,...i,` }) satisfies PoMcpSessionPlugin,`,`});`,``,`export default mcp;`,``])}const G={web:{module:`@agimon-ai/po-core/web`,define:`defineWebPlugin`,exportName:`webPlugin`},native:{module:`@agimon-ai/po-core/native`,define:`defineNativePlugin`,exportName:`nativePlugin`}};function K(e,t,n){let i=G[n],a=x(e,t),o=A(e.escapeHatches),l=[];for(let e of s){let t=a.filter(t=>t.contribution.entry.scope===e),r=o.filter(t=>t.entry.scope===e),i=[...F(t,` `,()=>`undefined`,n),...r.map(e=>` ...${e.identifier},`)];i.length!==0&&l.push(` ${e}: {`,...i,` },`)}let u=l.some(e=>e.includes(`get `))?`${i.define}, type ${c[n]}`:i.define;return R([r,`import { ${u} } from '${i.module}';`,``,...L(a,o,[],t.entryDir),``,...z(l),`export const ${i.exportName} = ${i.define}({`,` id: '${t.pluginId}',`,...l,`});`,``])}function q(e,t){return K(e,t,`web`)}function J(e,t){return K(e,t,`native`)}exports.renderMcpEntry=W,exports.renderNativeEntry=J,exports.renderServerEntry=U,exports.renderWebEntry=q;
4
+ `)}const f=[`const via = <T>(identity: Record<string, unknown>, value: unknown): T => {`,` if (value === undefined) return undefined as T;`,` const declaration = value as { relations?: readonly Record<string, unknown>[] };`,` return { ...identity, ...declaration, ...(declaration.relations === undefined ? {} : {`,` relations: declaration.relations.map((relation) => ({ evidence: 'declared', ...relation })),`,` }) } as T;`,`};`].join(`
5
+ `);function p(e,n){return n===void 0?{id:t.toKebab(e)}:{slot:n,id:t.toKebab(e)}}const m={tool:e=>({name:t.toSnake(e)}),command:e=>({name:t.toKebab(e)}),channel:e=>({frameType:t.toSnake(e)}),hook:e=>({event:t.toSnake(e)}),mode:e=>({name:t.toKebab(e)})},h={tool:e=>({tools:[t.toSnake(e)]}),channel:e=>({channel:t.toSnake(e)}),slot:(e,n)=>({slot:`${n.pluginId}.${t.toKebab(e)}`}),command:e=>({id:t.toKebab(e)}),tab:e=>({id:t.toKebab(e)}),template:e=>({id:t.toKebab(e)}),onboarding:e=>({id:t.toKebab(e)}),dock:e=>({id:t.toKebab(e)}),setting:e=>({id:t.toKebab(e)}),action:e=>({id:t.toKebab(e)}),mode:e=>({name:t.toKebab(e)}),"activity-group":e=>({name:t.toKebab(e)}),"selection-axis":e=>({name:t.toKebab(e)}),theme:e=>({name:t.toKebab(e)}),locale:e=>({name:e}),leader:(e,n)=>({id:`${n.pluginId}.${t.toKebab(e)}`})};function g(t,n,r){let{entry:i}=t,a=i.surface;if(a!==void 0)return e.isFrontendTarget(n)?a===`fill`?p(i.name,i.target):h[a]?.(i.name,r):m[a]?.(i.name)}function _(e,t){let n=e.join(`-`).split(/[^A-Za-z0-9]+/u).filter(e=>e.length>0).map((e,t)=>t===0?e:e[0]?.toUpperCase()+e.slice(1)).join(``),r=/^[A-Za-z_]/u.test(n)?n:`x${n}`,i=r,a=2;for(;t.has(i);)i=`${r}${a++}`;return t.add(i),i}function v(e,t){return _([e.entry.surface??`extra`,e.entry.name],t)}function y(e,t){let r=e.replace(/\.[^.]+$/u,``),i=n.posix.relative(t,r);return i.startsWith(`.`)?i:`./${i}`}function b(e){return JSON.stringify(e).replaceAll(`<`,`\\u003c`).replaceAll(`\u2028`,`\\u2028`).replaceAll(`\u2029`,`\\u2029`)}function x(e,t){let n=/* @__PURE__ */ new Set;return[...e.contributions].sort((e,t)=>e.entry.file.localeCompare(t.entry.file)).map(r=>{let i=v(r,n),a=e.target===`mcp`?t.mcpWidgets?.[r.entry.file]:void 0;if(a!==void 0&&!/^(?:@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*\/[a-z0-9_]+$/u.test(a))throw Error(`Invalid MCP widget key '${a}'`);return{identifier:i,contribution:r,identity:g(r,e.target,t),mcpWidget:a}})}const S={host:0,workspace:1,session:2};function C(e){return e.map(e=>{let t=e.scope[0]?.toUpperCase()+e.scope.slice(1);return{identifier:`root${t}`,declaration:`scope${t}`,context:`context${t}`,entry:e}})}function w(e,t,n){let r=[],i=t;for(let[a,o]of e.entries())r.push(`const ${o.declaration} = await ${t}.scopeRoot('${o.entry.scope}', ${o.identifier}, ${i});`),(a<e.length-1||n.some(e=>e.includes(o.context)))&&r.push(`const ${o.context} = { ...${i}, root: ${o.declaration}.value };`),i=o.context;return r}function T(e,t,n){let r=n;for(let n of e)S[n.entry.scope]<=S[t]&&(r=n.context);return r}function E(e,t,n){let r=e.contribution.entry.scope;if(S[r]>=S[n])return;let{field:i}=e.contribution;return i===`channels`||t.some(e=>S[e.entry.scope]<=S[r])&&(i===`api`||i===`methods`)?r:void 0}function D(e,t){if(t===void 0)return e;let n=`context.hosted('${t}')`;return e.startsWith(`...`)?`...(${n} ? [] : ${e.slice(3)})`:`${n} ? undefined : ${e}`}function O(e){let{entry:n,field:r}=e.contribution;if(r===`hooks`)return;let i=n.gates.map(e=>`${e.kind}:${e.id}`).join(`/`);return r===`api`?`${i}|api|${n.route.map(e=>`literal`in e?e.literal:`[${e.param.name}]`).join(`/`)}`:e.identity===void 0?void 0:`${i}|${r}|${t.renderIdentity(e.identity)}`}function k(e){let t=/* @__PURE__ */ new Map;for(let n of e){let e=O(n);e!==void 0&&t.set(e,Math.max(t.get(e)??-1,S[n.contribution.entry.scope]))}return e.filter(e=>{let n=O(e);return n===void 0||t.get(n)===S[e.contribution.entry.scope]})}function A(e){return[...e].sort((e,t)=>e.file.localeCompare(t.file)).map((e,t)=>({identifier:`extra${t===0?``:t+1}`,entry:e}))}function j(e){let t=/* @__PURE__ */ new Set;return e.map(e=>({identifier:_([`contract`,e.name],t),entry:e}))}function M(n,r,i){if(o.includes(n.contribution.field))return`${n.identifier}(${r})`;let s=e.isFrontendTarget(i)?n.identifier:`at(${n.identifier}, ${r})`,c=a[i].includes(n.contribution.field);if(n.contribution.entry.cardinality===`collection`)return s;if(n.identity===void 0)return c?n.identifier:s;let l=t.renderIdentity(n.identity);if(c)return`() => via({ ${l} }, ${s})`;let u=`via({ ${l} }, ${s})`;return n.mcpWidget===void 0?u:`withWidget(${b(n.mcpWidget)}, ${u})`}function N(e){return`import { ${[`defineServerPlugin`,...e.some(e=>e.includes(`get `))?[`type PoServerSessionPlugin`]:[]].join(`, `)} } from '@agimon-ai/po-core/serverPlugin';`}function P(e,t,n){if(e===`services`||e===`provider`||t.startsWith(`...`))return t;let[r,...i]=t.split(`: `);return`get ${r}(): ${`${c[n]}['${r}']`} { return ${i.join(`: `).replace(/,$/u,``)}; },`}function F(e,t,n,r,a=()=>void 0){let o=/* @__PURE__ */ new Map;for(let t of e){let e=o.get(t.contribution.field);e===void 0?o.set(t.contribution.field,[t]):e.push(t)}let s=[];for(let e of[...o.keys()].sort()){let c=o.get(e);if(i.includes(e)){let i=c[0];if(i){let a=M(i,n(i),r);s.push(`${t}${P(e,`${e}: ${a},`,r)}`)}continue}let l=`[${c.map(e=>D(e.contribution.entry.cardinality===`many`?`...many(${e.identifier}, ${n(e)})${e.mcpWidget===void 0?``:`.map((tool) => withWidget(${b(e.mcpWidget)}, tool))`}`:M(e,n(e),r),a(e))).join(`, `)}]`,u=c.some(e=>e.contribution.entry.cardinality===`optional`||e.contribution.entry.cardinality!==`many`&&a(e)!==void 0)?`defined(${l})`:l;s.push(`${t}${P(e,`${e}: ${u},`,r)}`)}return s}function I(e,t,n,r,i){if(t.length===0)return[...e];let a=[...e],o=a.findIndex(e=>e.startsWith(`${r}services: [`)),s=o<0?``:a.splice(o,1)[0]?.match(/services: \[(.*)\],$/u)?.[1]??``,c=[...t.map(e=>`...(${e.declaration}.services ?? [])`),s].filter(Boolean).join(`, `);if(a.push(`${r}services: [${c}],`),n===`server`&&i===`session`){let e=a.findIndex(e=>e.startsWith(`${r}get activities()`)),n=e<0?``:a.splice(e,1)[0]?.match(/return \[(.*)\]; \},$/u)?.[1]??``,i=[...t.map(e=>`...(${e.declaration}.activities ?? [])`),n].filter(Boolean).join(`, `);a.push(`${r}get activities(): PoServerSessionPlugin['activities'] { return [${i}]; },`)}return a}function L(e,t,n,r,i=[]){return[...n.map(e=>`import ${e.identifier} from '${y(e.entry.file,r)}';`),...i.map(e=>`import ${e.identifier} from '${y(e.entry.file,r)}';`),...e.map(e=>`import ${e.identifier} from '${y(e.contribution.entry.file,r)}';`),...t.map(e=>`import ${e.identifier} from '${y(e.entry.file,r)}';`)]}function R(e){return e.filter((e,t,n)=>e!==``||n[t-1]!==``).join(`
6
+ `)}function z(e){let t=[];return e.some(e=>e.includes(`at(`))&&t.push(l()),e.some(e=>e.includes(`many(`))&&t.push(u()),e.some(e=>e.includes(`defined(`))&&t.push(d()),e.some(e=>e.includes(`via(`))&&t.push(f),t.length>0?[...t,``]:[]}function B(e){return e.some(e=>/\bcontext[.,)]/u.test(e))?`(context)`:`()`}function V(e,t,n,r){let i=[...t===void 0?[]:[`${r} ${t}`],...n],a=[...e,...n].some(e=>e.includes(`await `))?`async `:``;return e.length===0?[`${a}${B(n)} => ({`,...i,`${r}}),`]:[`${a}${B([...e,...n])} => {`,...e.map(e=>`${r} ${e}`),`${r} return {`,...i.map(e=>` ${e}`),`${r} };`,`${r}},`]}function H(e){if(e.length!==0)return`...composeRootHooks(${e.map(e=>e.declaration).join(`, `)}),`}function U(e,t){let n=x(e,t),i=A(e.escapeHatches),a=C(e.roots),o=j(e.contracts),c=[],l=[],u=!1;for(let[e,t]of s.entries()){let r=k(n.filter(t=>s.indexOf(t.contribution.entry.scope)<=e)),o=i.filter(t=>s.indexOf(t.entry.scope)<=e),d=a.filter(t=>s.indexOf(t.entry.scope)<=e),f=d[d.length-1]?.context??`context`,p=[...I(F(r,` `,e=>T(d,e.contribution.entry.scope,`context`),`server`,e=>E(e,d,t)),d,`server`,` `,t),...o.map(e=>` ...await at(${e.identifier}, ${f}),`)];if(p.length===0&&d.length===0)continue;d.length>0&&(u=!0,l.push(`${t}: [${d.map(e=>e.identifier).join(`, `)}]`));let m=V(w(d,`context`,p),H(d),p,` `);c.push(` ${t}: ${m[0]}`,...m.slice(1))}let d=s.flatMap(e=>{let t=o.filter(t=>t.entry.scope===e);return t.length===0?[]:[` ${e}: [${t.map(e=>e.identifier).join(`, `)}],`]});return R([r,N(c),...a.length?[`import { composeServerProviderOverrides } from '@agimon-ai/po-core/serverPlugin';`]:[],...u?[`import { composeRootHooks, composeRootInjects } from '@agimon-ai/po-core/extensionFile';`]:[],``,...L(n,i,a,t.entryDir,o),``,...z(c),`export const serverPlugin = defineServerPlugin({`,` name: '${t.packageName}',`,...a.length?[` providerOverrides: composeServerProviderOverrides(${a.map(e=>e.identifier).join(`, `)}),`]:[],...d.length>0?[` provides: {`,...d,` },`]:[],...l.length>0?[` injects: composeRootInjects({ ${l.join(`, `)} }),`]:[],...c,`});`,``,`export default serverPlugin;`,``])}function W(e,t){let n=x(e,t),i=F(n,` `,()=>`context`,`mcp`);return R([r,`import { defineMcpPlugin, type PoMcpSessionPlugin } from '@agimon-ai/po-core/mcpFacet';`,``,...L(n,[],[],t.entryDir),``,...z(i),...n.some(e=>e.mcpWidget!==void 0)?[`const withWidget = <T>(key: string, value: T): T => value === undefined ? value : ({`,` ...value, _meta: { ...(value as { _meta?: object })._meta, ["po/widget"]: key },`,`});`,``]:[],`export const mcp = defineMcpPlugin({`,` name: '${t.packageName}',`,` session: (context) => ({`,...i,` }) satisfies PoMcpSessionPlugin,`,`});`,``,`export default mcp;`,``])}const G={web:{module:`@agimon-ai/po-core/web`,define:`defineWebPlugin`,exportName:`webPlugin`},native:{module:`@agimon-ai/po-core/native`,define:`defineNativePlugin`,exportName:`nativePlugin`}};function K(e,t,n){let i=G[n],a=x(e,t),o=A(e.escapeHatches),l=[];for(let e of s){let t=a.filter(t=>t.contribution.entry.scope===e),r=o.filter(t=>t.entry.scope===e),i=[...F(t,` `,()=>`undefined`,n),...r.map(e=>` ...${e.identifier},`)];i.length!==0&&l.push(` ${e}: {`,...i,` },`)}let u=l.some(e=>e.includes(`get `))?`${i.define}, type ${c[n]}`:i.define;return R([r,`import { ${u} } from '${i.module}';`,``,...L(a,o,[],t.entryDir),``,...z(l),`export const ${i.exportName} = ${i.define}({`,` id: '${t.pluginId}',`,` packageName: '${t.packageName}',`,...l,`});`,``])}function q(e,t){return K(e,t,`web`)}function J(e,t){return K(e,t,`native`)}exports.renderMcpEntry=W,exports.renderNativeEntry=J,exports.renderServerEntry=U,exports.renderWebEntry=q;
7
7
  //# sourceMappingURL=index.cjs.map