@agimon-ai/po-build 0.0.0-alpha.1 → 0.0.0-alpha.3

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 (34) hide show
  1. package/dist/browserFile.mjs +1 -1
  2. package/dist/constants/contributions.cjs +1 -1
  3. package/dist/constants/contributions.cjs.map +1 -1
  4. package/dist/constants/contributions.mjs +1 -1
  5. package/dist/constants/contributions.mjs.map +1 -1
  6. package/dist/constants/layout.cjs +1 -1
  7. package/dist/constants/layout.cjs.map +1 -1
  8. package/dist/constants/layout.d.mts.map +1 -1
  9. package/dist/constants/layout.mjs +1 -1
  10. package/dist/constants/layout.mjs.map +1 -1
  11. package/dist/services/generate/index.cjs +1 -1
  12. package/dist/services/generate/index.cjs.map +1 -1
  13. package/dist/services/generate/index.d.mts.map +1 -1
  14. package/dist/services/generate/index.mjs +2 -2
  15. package/dist/services/generate/index.mjs.map +1 -1
  16. package/dist/services/renderClient/index.cjs +2 -2
  17. package/dist/services/renderClient/index.cjs.map +1 -1
  18. package/dist/services/renderClient/index.mjs +2 -2
  19. package/dist/services/renderClient/index.mjs.map +1 -1
  20. package/dist/services/resolveTarget/index.cjs +1 -1
  21. package/dist/services/resolveTarget/index.cjs.map +1 -1
  22. package/dist/services/resolveTarget/index.d.mts.map +1 -1
  23. package/dist/services/resolveTarget/index.mjs +1 -1
  24. package/dist/services/resolveTarget/index.mjs.map +1 -1
  25. package/dist/services/tsdownPreset/index.cjs +1 -1
  26. package/dist/services/tsdownPreset/index.cjs.map +1 -1
  27. package/dist/services/tsdownPreset/index.d.mts +8 -0
  28. package/dist/services/tsdownPreset/index.d.mts.map +1 -1
  29. package/dist/services/tsdownPreset/index.mjs +1 -1
  30. package/dist/services/tsdownPreset/index.mjs.map +1 -1
  31. package/dist/tsdown.cjs +1 -1
  32. package/dist/tsdown.d.mts +2 -2
  33. package/dist/tsdown.mjs +1 -1
  34. package/package.json +3 -3
@@ -1 +1 @@
1
- import{isBrowserFile as e,isNativeFile as t}from"./services/browserFile/index.mjs";export{e as isBrowserFile,t as isNativeFile};
1
+ export{isBrowserFile,isNativeFile}from"./services/browserFile/index.mjs";
@@ -1,2 +1,2 @@
1
- const e={tool:`tools`,"tool-restriction":`toolRestrictions`,command:`commands`,hook:`hooks`,mode:`minorModes`,api:`api`,channel:`channels`,method:`methods`,resource:`resources`},t={tool:`tools`,skill:`skills`,resource:`uiResources`},n={tool:`toolRenderers`,command:`paletteCommands`,mode:`minorModes`,channel:`channels`,tab:`tabs`,template:`templates`,dock:`dockFaces`,setting:`settingsSections`,slot:`slots`,fill:`fills`,action:`contextActions`,"activity-group":`activityGroups`,leader:`leaderBindings`,"selection-axis":`selectionAxes`,lifecycle:`start`,"file-links":`fileLinks`,"repository-settings-panel":`repositorySettingsPanel`,api:``,method:``,store:``},r={tool:`toolRenderers`,tab:`tabs`,slot:`slots`,fill:`fills`,channel:`channels`,"activity-group":`activityGroups`,setting:`settingsSections`,lifecycle:`start`,template:`nativeTemplates`,store:``},i={section:`settingsSections`,panel:`settingsPanels`},a={context:`contextActions`,message:`userMessageActions`};exports.ACTION_FIELDS=a,exports.MCP_FIELDS=t,exports.NATIVE_FIELDS=r,exports.SERVER_FIELDS=e,exports.SETTING_FIELDS=i,exports.WEB_FIELDS=n;
1
+ const e={tool:`tools`,"tool-restriction":`toolRestrictions`,command:`commands`,hook:`hooks`,mode:`minorModes`,api:`api`,channel:`channels`,method:`methods`,resource:`resources`},t={tool:`tools`,skill:`skills`,resource:`uiResources`},n={tool:`toolRenderers`,command:`paletteCommands`,mode:`minorModes`,channel:`channels`,tab:`tabs`,template:`templates`,dock:`dockFaces`,setting:`settingsSections`,slot:`slots`,fill:`fills`,action:`contextActions`,"activity-group":`activityGroups`,leader:`leaderBindings`,"selection-axis":`selectionAxes`,lifecycle:`start`,"file-links":`fileLinks`,"repository-settings-panel":`repositorySettingsPanel`,api:``,method:``,store:``},r={tool:`toolRenderers`,tab:`tabs`,slot:`slots`,fill:`fills`,channel:`channels`,"activity-group":`activityGroups`,"selection-axis":`selectionAxes`,setting:`settingsSections`,action:`userMessageActions`,lifecycle:`start`,template:`nativeTemplates`,store:``},i={section:`settingsSections`,panel:`settingsPanels`},a={context:`contextActions`,message:`userMessageActions`},o={message:`userMessageActions`};exports.ACTION_FIELDS=a,exports.MCP_FIELDS=t,exports.NATIVE_ACTION_FIELDS=o,exports.NATIVE_FIELDS=r,exports.SERVER_FIELDS=e,exports.SETTING_FIELDS=i,exports.WEB_FIELDS=n;
2
2
  //# sourceMappingURL=contributions.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"contributions.cjs","names":["SERVER_FIELDS","MCP_FIELDS","WEB_FIELDS","NATIVE_FIELDS","SETTING_FIELDS","ACTION_FIELDS"],"sources":["../../src/constants/contributions.ts"],"sourcesContent":["/**\n * Which contribution field each surface produces, per host and side.\n *\n * The surface names the concept; the host decides which array carries it.\n * A surface missing from a host's table is legitimately absent there, such\n * as api/ on MCP, and is skipped without complaint.\n */\n\n/** A surface that produces nothing registrable, but is still published. */\nexport const NOT_A_CONTRIBUTION = '';\n\nexport const SERVER_FIELDS: Readonly<Record<string, string>> = {\n tool: 'tools',\n 'tool-restriction': 'toolRestrictions',\n command: 'commands',\n hook: 'hooks',\n mode: 'minorModes',\n api: 'api',\n channel: 'channels',\n method: 'methods',\n resource: 'resources',\n};\n\nexport const MCP_FIELDS: Readonly<Record<string, string>> = {\n tool: 'tools',\n skill: 'skills',\n resource: 'uiResources',\n};\n\nexport const WEB_FIELDS: Readonly<Record<string, string>> = {\n tool: 'toolRenderers',\n command: 'paletteCommands',\n mode: 'minorModes',\n channel: 'channels',\n tab: 'tabs',\n template: 'templates',\n dock: 'dockFaces',\n setting: 'settingsSections',\n slot: 'slots',\n // Every fill is a slot fill. The cockpit declares its own regions as slots\n // (overlay, rail, context, activity and so on), so the build tooling needs\n // to know none of their names.\n fill: 'fills',\n action: 'contextActions',\n 'activity-group': 'activityGroups',\n leader: 'leaderBindings',\n 'selection-axis': 'selectionAxes',\n lifecycle: 'start',\n 'file-links': 'fileLinks',\n 'repository-settings-panel': 'repositorySettingsPanel',\n api: NOT_A_CONTRIBUTION,\n method: NOT_A_CONTRIBUTION,\n store: NOT_A_CONTRIBUTION,\n};\n\n/**\n * The subset of the cockpit's fields the native app installs.\n *\n * The values match WEB_FIELDS because the native app reuses the cockpit's\n * plugin registry: a native plugin is a web plugin definition built from\n * `.native` files.\n */\nexport const NATIVE_FIELDS: Readonly<Record<string, string>> = {\n tool: 'toolRenderers',\n tab: 'tabs',\n slot: 'slots',\n fill: 'fills',\n channel: 'channels',\n 'activity-group': 'activityGroups',\n setting: 'settingsSections',\n lifecycle: 'start',\n // Its own field: a phone layout has a different contract from a cockpit template.\n template: 'nativeTemplates',\n store: NOT_A_CONTRIBUTION,\n};\n\n/** Disambiguates the two shapes a `setting/` file can take. */\nexport const SETTING_FIELDS: Readonly<Record<string, string>> = {\n section: 'settingsSections',\n panel: 'settingsPanels',\n};\n\n/** Disambiguates the two shapes an `action/` file can take. */\nexport const ACTION_FIELDS: Readonly<Record<string, string>> = {\n context: 'contextActions',\n message: 'userMessageActions',\n};\n"],"mappings":"AAWA,MAAaA,EAAkD,CAC7D,KAAM,QACN,mBAAoB,mBACpB,QAAS,WACT,KAAM,QACN,KAAM,aACN,IAAK,MACL,QAAS,WACT,OAAQ,UACR,SAAU,WACZ,EAEaC,EAA+C,CAC1D,KAAM,QACN,MAAO,SACP,SAAU,aACZ,EAEaC,EAA+C,CAC1D,KAAM,gBACN,QAAS,kBACT,KAAM,aACN,QAAS,WACT,IAAK,OACL,SAAU,YACV,KAAM,YACN,QAAS,mBACT,KAAM,QAIN,KAAM,QACN,OAAQ,iBACR,iBAAkB,iBAClB,OAAQ,iBACR,iBAAkB,gBAClB,UAAW,QACX,aAAc,YACd,4BAA6B,0BAC7B,IAAA,GACA,OAAA,GACA,MAAA,EACF,EASaC,EAAkD,CAC7D,KAAM,gBACN,IAAK,OACL,KAAM,QACN,KAAM,QACN,QAAS,WACT,iBAAkB,iBAClB,QAAS,mBACT,UAAW,QAEX,SAAU,kBACV,MAAA,EACF,EAGaC,EAAmD,CAC9D,QAAS,mBACT,MAAO,gBACT,EAGaC,EAAkD,CAC7D,QAAS,iBACT,QAAS,oBACX"}
1
+ {"version":3,"file":"contributions.cjs","names":["SERVER_FIELDS","MCP_FIELDS","WEB_FIELDS","NATIVE_FIELDS","SETTING_FIELDS","ACTION_FIELDS","NATIVE_ACTION_FIELDS"],"sources":["../../src/constants/contributions.ts"],"sourcesContent":["/**\n * Which contribution field each surface produces, per host and side.\n *\n * The surface names the concept; the host decides which array carries it.\n * A surface missing from a host's table is legitimately absent there, such\n * as api/ on MCP, and is skipped without complaint.\n */\n\n/** A surface that produces nothing registrable, but is still published. */\nexport const NOT_A_CONTRIBUTION = '';\n\nexport const SERVER_FIELDS: Readonly<Record<string, string>> = {\n tool: 'tools',\n 'tool-restriction': 'toolRestrictions',\n command: 'commands',\n hook: 'hooks',\n mode: 'minorModes',\n api: 'api',\n channel: 'channels',\n method: 'methods',\n resource: 'resources',\n};\n\nexport const MCP_FIELDS: Readonly<Record<string, string>> = {\n tool: 'tools',\n skill: 'skills',\n resource: 'uiResources',\n};\n\nexport const WEB_FIELDS: Readonly<Record<string, string>> = {\n tool: 'toolRenderers',\n command: 'paletteCommands',\n mode: 'minorModes',\n channel: 'channels',\n tab: 'tabs',\n template: 'templates',\n dock: 'dockFaces',\n setting: 'settingsSections',\n slot: 'slots',\n // Every fill is a slot fill. The cockpit declares its own regions as slots\n // (overlay, rail, context, activity and so on), so the build tooling needs\n // to know none of their names.\n fill: 'fills',\n action: 'contextActions',\n 'activity-group': 'activityGroups',\n leader: 'leaderBindings',\n 'selection-axis': 'selectionAxes',\n lifecycle: 'start',\n 'file-links': 'fileLinks',\n 'repository-settings-panel': 'repositorySettingsPanel',\n api: NOT_A_CONTRIBUTION,\n method: NOT_A_CONTRIBUTION,\n store: NOT_A_CONTRIBUTION,\n};\n\n/**\n * The subset of the cockpit's fields the native app installs.\n *\n * The values match WEB_FIELDS because the native app reuses the cockpit's\n * plugin registry: a native plugin is a web plugin definition built from\n * `.native` files.\n */\nexport const NATIVE_FIELDS: Readonly<Record<string, string>> = {\n tool: 'toolRenderers',\n tab: 'tabs',\n slot: 'slots',\n fill: 'fills',\n channel: 'channels',\n 'activity-group': 'activityGroups',\n 'selection-axis': 'selectionAxes',\n setting: 'settingsSections',\n // Only the message shape: see NATIVE_ACTION_FIELDS.\n action: 'userMessageActions',\n lifecycle: 'start',\n // Its own field: a phone layout has a different contract from a cockpit template.\n template: 'nativeTemplates',\n store: NOT_A_CONTRIBUTION,\n};\n\n/** Disambiguates the two shapes a `setting/` file can take. */\nexport const SETTING_FIELDS: Readonly<Record<string, string>> = {\n section: 'settingsSections',\n panel: 'settingsPanels',\n};\n\n/** Disambiguates the two shapes an `action/` file can take. */\nexport const ACTION_FIELDS: Readonly<Record<string, string>> = {\n context: 'contextActions',\n message: 'userMessageActions',\n};\n\n/**\n * The `action/` shapes the native app installs. A phone has no context items,\n * so a context action, named or defaulted, stays unsupported there.\n */\nexport const NATIVE_ACTION_FIELDS: Readonly<Record<string, string>> = {\n message: 'userMessageActions',\n};\n"],"mappings":"AAWA,MAAaA,EAAkD,CAC7D,KAAM,QACN,mBAAoB,mBACpB,QAAS,WACT,KAAM,QACN,KAAM,aACN,IAAK,MACL,QAAS,WACT,OAAQ,UACR,SAAU,WACZ,EAEaC,EAA+C,CAC1D,KAAM,QACN,MAAO,SACP,SAAU,aACZ,EAEaC,EAA+C,CAC1D,KAAM,gBACN,QAAS,kBACT,KAAM,aACN,QAAS,WACT,IAAK,OACL,SAAU,YACV,KAAM,YACN,QAAS,mBACT,KAAM,QAIN,KAAM,QACN,OAAQ,iBACR,iBAAkB,iBAClB,OAAQ,iBACR,iBAAkB,gBAClB,UAAW,QACX,aAAc,YACd,4BAA6B,0BAC7B,IAAA,GACA,OAAA,GACA,MAAA,EACF,EASaC,EAAkD,CAC7D,KAAM,gBACN,IAAK,OACL,KAAM,QACN,KAAM,QACN,QAAS,WACT,iBAAkB,iBAClB,iBAAkB,gBAClB,QAAS,mBAET,OAAQ,qBACR,UAAW,QAEX,SAAU,kBACV,MAAA,EACF,EAGaC,EAAmD,CAC9D,QAAS,mBACT,MAAO,gBACT,EAGaC,EAAkD,CAC7D,QAAS,iBACT,QAAS,oBACX,EAMaC,EAAyD,CACpE,QAAS,oBACX"}
@@ -1,2 +1,2 @@
1
- const e={tool:`tools`,"tool-restriction":`toolRestrictions`,command:`commands`,hook:`hooks`,mode:`minorModes`,api:`api`,channel:`channels`,method:`methods`,resource:`resources`},t={tool:`tools`,skill:`skills`,resource:`uiResources`},n={tool:`toolRenderers`,command:`paletteCommands`,mode:`minorModes`,channel:`channels`,tab:`tabs`,template:`templates`,dock:`dockFaces`,setting:`settingsSections`,slot:`slots`,fill:`fills`,action:`contextActions`,"activity-group":`activityGroups`,leader:`leaderBindings`,"selection-axis":`selectionAxes`,lifecycle:`start`,"file-links":`fileLinks`,"repository-settings-panel":`repositorySettingsPanel`,api:``,method:``,store:``},r={tool:`toolRenderers`,tab:`tabs`,slot:`slots`,fill:`fills`,channel:`channels`,"activity-group":`activityGroups`,setting:`settingsSections`,lifecycle:`start`,template:`nativeTemplates`,store:``},i={section:`settingsSections`,panel:`settingsPanels`},a={context:`contextActions`,message:`userMessageActions`};export{a as ACTION_FIELDS,t as MCP_FIELDS,r as NATIVE_FIELDS,e as SERVER_FIELDS,i as SETTING_FIELDS,n as WEB_FIELDS};
1
+ const e={tool:`tools`,"tool-restriction":`toolRestrictions`,command:`commands`,hook:`hooks`,mode:`minorModes`,api:`api`,channel:`channels`,method:`methods`,resource:`resources`},t={tool:`tools`,skill:`skills`,resource:`uiResources`},n={tool:`toolRenderers`,command:`paletteCommands`,mode:`minorModes`,channel:`channels`,tab:`tabs`,template:`templates`,dock:`dockFaces`,setting:`settingsSections`,slot:`slots`,fill:`fills`,action:`contextActions`,"activity-group":`activityGroups`,leader:`leaderBindings`,"selection-axis":`selectionAxes`,lifecycle:`start`,"file-links":`fileLinks`,"repository-settings-panel":`repositorySettingsPanel`,api:``,method:``,store:``},r={tool:`toolRenderers`,tab:`tabs`,slot:`slots`,fill:`fills`,channel:`channels`,"activity-group":`activityGroups`,"selection-axis":`selectionAxes`,setting:`settingsSections`,action:`userMessageActions`,lifecycle:`start`,template:`nativeTemplates`,store:``},i={section:`settingsSections`,panel:`settingsPanels`},a={context:`contextActions`,message:`userMessageActions`},o={message:`userMessageActions`};export{a as ACTION_FIELDS,t as MCP_FIELDS,o as NATIVE_ACTION_FIELDS,r as NATIVE_FIELDS,e as SERVER_FIELDS,i as SETTING_FIELDS,n as WEB_FIELDS};
2
2
  //# sourceMappingURL=contributions.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"contributions.mjs","names":["SERVER_FIELDS","MCP_FIELDS","WEB_FIELDS","NATIVE_FIELDS","SETTING_FIELDS","ACTION_FIELDS"],"sources":["../../src/constants/contributions.ts"],"sourcesContent":["/**\n * Which contribution field each surface produces, per host and side.\n *\n * The surface names the concept; the host decides which array carries it.\n * A surface missing from a host's table is legitimately absent there, such\n * as api/ on MCP, and is skipped without complaint.\n */\n\n/** A surface that produces nothing registrable, but is still published. */\nexport const NOT_A_CONTRIBUTION = '';\n\nexport const SERVER_FIELDS: Readonly<Record<string, string>> = {\n tool: 'tools',\n 'tool-restriction': 'toolRestrictions',\n command: 'commands',\n hook: 'hooks',\n mode: 'minorModes',\n api: 'api',\n channel: 'channels',\n method: 'methods',\n resource: 'resources',\n};\n\nexport const MCP_FIELDS: Readonly<Record<string, string>> = {\n tool: 'tools',\n skill: 'skills',\n resource: 'uiResources',\n};\n\nexport const WEB_FIELDS: Readonly<Record<string, string>> = {\n tool: 'toolRenderers',\n command: 'paletteCommands',\n mode: 'minorModes',\n channel: 'channels',\n tab: 'tabs',\n template: 'templates',\n dock: 'dockFaces',\n setting: 'settingsSections',\n slot: 'slots',\n // Every fill is a slot fill. The cockpit declares its own regions as slots\n // (overlay, rail, context, activity and so on), so the build tooling needs\n // to know none of their names.\n fill: 'fills',\n action: 'contextActions',\n 'activity-group': 'activityGroups',\n leader: 'leaderBindings',\n 'selection-axis': 'selectionAxes',\n lifecycle: 'start',\n 'file-links': 'fileLinks',\n 'repository-settings-panel': 'repositorySettingsPanel',\n api: NOT_A_CONTRIBUTION,\n method: NOT_A_CONTRIBUTION,\n store: NOT_A_CONTRIBUTION,\n};\n\n/**\n * The subset of the cockpit's fields the native app installs.\n *\n * The values match WEB_FIELDS because the native app reuses the cockpit's\n * plugin registry: a native plugin is a web plugin definition built from\n * `.native` files.\n */\nexport const NATIVE_FIELDS: Readonly<Record<string, string>> = {\n tool: 'toolRenderers',\n tab: 'tabs',\n slot: 'slots',\n fill: 'fills',\n channel: 'channels',\n 'activity-group': 'activityGroups',\n setting: 'settingsSections',\n lifecycle: 'start',\n // Its own field: a phone layout has a different contract from a cockpit template.\n template: 'nativeTemplates',\n store: NOT_A_CONTRIBUTION,\n};\n\n/** Disambiguates the two shapes a `setting/` file can take. */\nexport const SETTING_FIELDS: Readonly<Record<string, string>> = {\n section: 'settingsSections',\n panel: 'settingsPanels',\n};\n\n/** Disambiguates the two shapes an `action/` file can take. */\nexport const ACTION_FIELDS: Readonly<Record<string, string>> = {\n context: 'contextActions',\n message: 'userMessageActions',\n};\n"],"mappings":"AAWA,MAAaA,EAAkD,CAC7D,KAAM,QACN,mBAAoB,mBACpB,QAAS,WACT,KAAM,QACN,KAAM,aACN,IAAK,MACL,QAAS,WACT,OAAQ,UACR,SAAU,WACZ,EAEaC,EAA+C,CAC1D,KAAM,QACN,MAAO,SACP,SAAU,aACZ,EAEaC,EAA+C,CAC1D,KAAM,gBACN,QAAS,kBACT,KAAM,aACN,QAAS,WACT,IAAK,OACL,SAAU,YACV,KAAM,YACN,QAAS,mBACT,KAAM,QAIN,KAAM,QACN,OAAQ,iBACR,iBAAkB,iBAClB,OAAQ,iBACR,iBAAkB,gBAClB,UAAW,QACX,aAAc,YACd,4BAA6B,0BAC7B,IAAA,GACA,OAAA,GACA,MAAA,EACF,EASaC,EAAkD,CAC7D,KAAM,gBACN,IAAK,OACL,KAAM,QACN,KAAM,QACN,QAAS,WACT,iBAAkB,iBAClB,QAAS,mBACT,UAAW,QAEX,SAAU,kBACV,MAAA,EACF,EAGaC,EAAmD,CAC9D,QAAS,mBACT,MAAO,gBACT,EAGaC,EAAkD,CAC7D,QAAS,iBACT,QAAS,oBACX"}
1
+ {"version":3,"file":"contributions.mjs","names":["SERVER_FIELDS","MCP_FIELDS","WEB_FIELDS","NATIVE_FIELDS","SETTING_FIELDS","ACTION_FIELDS","NATIVE_ACTION_FIELDS"],"sources":["../../src/constants/contributions.ts"],"sourcesContent":["/**\n * Which contribution field each surface produces, per host and side.\n *\n * The surface names the concept; the host decides which array carries it.\n * A surface missing from a host's table is legitimately absent there, such\n * as api/ on MCP, and is skipped without complaint.\n */\n\n/** A surface that produces nothing registrable, but is still published. */\nexport const NOT_A_CONTRIBUTION = '';\n\nexport const SERVER_FIELDS: Readonly<Record<string, string>> = {\n tool: 'tools',\n 'tool-restriction': 'toolRestrictions',\n command: 'commands',\n hook: 'hooks',\n mode: 'minorModes',\n api: 'api',\n channel: 'channels',\n method: 'methods',\n resource: 'resources',\n};\n\nexport const MCP_FIELDS: Readonly<Record<string, string>> = {\n tool: 'tools',\n skill: 'skills',\n resource: 'uiResources',\n};\n\nexport const WEB_FIELDS: Readonly<Record<string, string>> = {\n tool: 'toolRenderers',\n command: 'paletteCommands',\n mode: 'minorModes',\n channel: 'channels',\n tab: 'tabs',\n template: 'templates',\n dock: 'dockFaces',\n setting: 'settingsSections',\n slot: 'slots',\n // Every fill is a slot fill. The cockpit declares its own regions as slots\n // (overlay, rail, context, activity and so on), so the build tooling needs\n // to know none of their names.\n fill: 'fills',\n action: 'contextActions',\n 'activity-group': 'activityGroups',\n leader: 'leaderBindings',\n 'selection-axis': 'selectionAxes',\n lifecycle: 'start',\n 'file-links': 'fileLinks',\n 'repository-settings-panel': 'repositorySettingsPanel',\n api: NOT_A_CONTRIBUTION,\n method: NOT_A_CONTRIBUTION,\n store: NOT_A_CONTRIBUTION,\n};\n\n/**\n * The subset of the cockpit's fields the native app installs.\n *\n * The values match WEB_FIELDS because the native app reuses the cockpit's\n * plugin registry: a native plugin is a web plugin definition built from\n * `.native` files.\n */\nexport const NATIVE_FIELDS: Readonly<Record<string, string>> = {\n tool: 'toolRenderers',\n tab: 'tabs',\n slot: 'slots',\n fill: 'fills',\n channel: 'channels',\n 'activity-group': 'activityGroups',\n 'selection-axis': 'selectionAxes',\n setting: 'settingsSections',\n // Only the message shape: see NATIVE_ACTION_FIELDS.\n action: 'userMessageActions',\n lifecycle: 'start',\n // Its own field: a phone layout has a different contract from a cockpit template.\n template: 'nativeTemplates',\n store: NOT_A_CONTRIBUTION,\n};\n\n/** Disambiguates the two shapes a `setting/` file can take. */\nexport const SETTING_FIELDS: Readonly<Record<string, string>> = {\n section: 'settingsSections',\n panel: 'settingsPanels',\n};\n\n/** Disambiguates the two shapes an `action/` file can take. */\nexport const ACTION_FIELDS: Readonly<Record<string, string>> = {\n context: 'contextActions',\n message: 'userMessageActions',\n};\n\n/**\n * The `action/` shapes the native app installs. A phone has no context items,\n * so a context action, named or defaulted, stays unsupported there.\n */\nexport const NATIVE_ACTION_FIELDS: Readonly<Record<string, string>> = {\n message: 'userMessageActions',\n};\n"],"mappings":"AAWA,MAAaA,EAAkD,CAC7D,KAAM,QACN,mBAAoB,mBACpB,QAAS,WACT,KAAM,QACN,KAAM,aACN,IAAK,MACL,QAAS,WACT,OAAQ,UACR,SAAU,WACZ,EAEaC,EAA+C,CAC1D,KAAM,QACN,MAAO,SACP,SAAU,aACZ,EAEaC,EAA+C,CAC1D,KAAM,gBACN,QAAS,kBACT,KAAM,aACN,QAAS,WACT,IAAK,OACL,SAAU,YACV,KAAM,YACN,QAAS,mBACT,KAAM,QAIN,KAAM,QACN,OAAQ,iBACR,iBAAkB,iBAClB,OAAQ,iBACR,iBAAkB,gBAClB,UAAW,QACX,aAAc,YACd,4BAA6B,0BAC7B,IAAA,GACA,OAAA,GACA,MAAA,EACF,EASaC,EAAkD,CAC7D,KAAM,gBACN,IAAK,OACL,KAAM,QACN,KAAM,QACN,QAAS,WACT,iBAAkB,iBAClB,iBAAkB,gBAClB,QAAS,mBAET,OAAQ,qBACR,UAAW,QAEX,SAAU,kBACV,MAAA,EACF,EAGaC,EAAmD,CAC9D,QAAS,mBACT,MAAO,gBACT,EAGaC,EAAkD,CAC7D,QAAS,iBACT,QAAS,oBACX,EAMaC,EAAyD,CACpE,QAAS,oBACX"}
@@ -1,2 +1,2 @@
1
- const e=[`mode`,`domain`],t={server:`server`,web:`web`,native:`native`,mcp:`mcp`},n=[`pi`,`server`,`web`,`native`,`mcp`,`client`],r=[`server`,`mcp`],i=[`web`,`native`,`ios`,`android`,`desktop`],a=[`server`,`web`,`native`,`mcp`],o=[`tool`,`skill`,`tool-restriction`,`command`,`hook`,`api`,`channel`,`method`,`provider`,`resource`],s=[`tool`,`command`,`api`,`channel`,`method`,`tab`,`template`,`dock`,`setting`,`slot`,`fill`,`action`,`store`,`activity-group`,`leader`,`selection-axis`,`lifecycle`,`file-links`,`repository-settings-panel`],c=[`fill`,`action`],l=[`api`],u=[`ts`,`tsx`,`mts`,`cts`],d=[`test`,`spec`,`stories`];exports.API_ROUTES_MODULE=`src/types/apiRoutes.ts`,exports.BACKEND_GROUP=`backend`,exports.BACKEND_PLATFORMS=r,exports.BACKEND_SURFACES=o,exports.BUILD_TARGET_PLATFORMS=a,exports.DEFAULT_ROUTING_ROOT=`src/extensions`,exports.EXCLUDED_INFIXES=d,exports.FRONTEND_GROUP=`frontend`,exports.FRONTEND_PLATFORMS=i,exports.FRONTEND_SURFACES=s,exports.GATE_SEGMENTS=e,exports.GENERATED_CLIENT_NAME=`client`,exports.GENERATED_DIR=`generated`,exports.GENERATED_ENTRY_FILENAMES=t,exports.GENERATED_ENTRY_NAMES=n,exports.NATIVE_PLATFORM=`native`,exports.ROOT_FILE_NAME=`root`,exports.ROUTED_SURFACES=l,exports.ROUTE_FILE_NAME=`route`,exports.ROUTING_ROOT_ALIAS=`src/extension`,exports.SESSION_SEGMENT=`sessions`,exports.SOURCE_EXTENSIONS=u,exports.TARGETED_SURFACES=c,exports.WORKSPACE_SEGMENT=`workspaces`;
1
+ const e=[`mode`,`domain`],t={server:`server`,web:`web`,native:`native`,mcp:`mcp`},n=[`pi`,`server`,`web`,`native`,`mcp`,`client`,`client.native`],r=[`server`,`mcp`],i=[`web`,`native`,`ios`,`android`,`desktop`],a=[`server`,`web`,`native`,`mcp`],o=[`tool`,`skill`,`tool-restriction`,`command`,`hook`,`api`,`channel`,`method`,`provider`,`resource`],s=[`tool`,`command`,`api`,`channel`,`method`,`tab`,`template`,`dock`,`setting`,`slot`,`fill`,`action`,`store`,`activity-group`,`leader`,`selection-axis`,`lifecycle`,`file-links`,`repository-settings-panel`],c=[`fill`,`action`],l=[`api`],u=[`ts`,`tsx`,`mts`,`cts`],d=[`test`,`spec`,`stories`,`edge`];exports.API_ROUTES_MODULE=`src/types/apiRoutes.ts`,exports.BACKEND_GROUP=`backend`,exports.BACKEND_PLATFORMS=r,exports.BACKEND_SURFACES=o,exports.BUILD_TARGET_PLATFORMS=a,exports.DEFAULT_ROUTING_ROOT=`src/extensions`,exports.EXCLUDED_INFIXES=d,exports.FRONTEND_GROUP=`frontend`,exports.FRONTEND_PLATFORMS=i,exports.FRONTEND_SURFACES=s,exports.GATE_SEGMENTS=e,exports.GENERATED_CLIENT_NAME=`client`,exports.GENERATED_DIR=`generated`,exports.GENERATED_ENTRY_FILENAMES=t,exports.GENERATED_ENTRY_NAMES=n,exports.GENERATED_NATIVE_CLIENT_NAME=`client.native`,exports.NATIVE_PLATFORM=`native`,exports.ROOT_FILE_NAME=`root`,exports.ROUTED_SURFACES=l,exports.ROUTE_FILE_NAME=`route`,exports.ROUTING_ROOT_ALIAS=`src/extension`,exports.SESSION_SEGMENT=`sessions`,exports.SOURCE_EXTENSIONS=u,exports.TARGETED_SURFACES=c,exports.WORKSPACE_SEGMENT=`workspaces`;
2
2
  //# sourceMappingURL=layout.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"layout.cjs","names":["GATE_SEGMENTS","GENERATED_ENTRY_FILENAMES","GENERATED_ENTRY_NAMES","BACKEND_PLATFORMS","FRONTEND_PLATFORMS","BUILD_TARGET_PLATFORMS","BACKEND_SURFACES","FRONTEND_SURFACES","TARGETED_SURFACES","ROUTED_SURFACES","SOURCE_EXTENSIONS","EXCLUDED_INFIXES"],"sources":["../../src/constants/layout.ts"],"sourcesContent":["/**\n * The folder-convention vocabulary, in one place.\n *\n * Every name here is part of the authoring contract in\n * docs/extension-layout.md. Adding a surface means adding it to both.\n */\n\n/** Where the scan starts, package-relative. */\nexport const DEFAULT_ROUTING_ROOT = 'src/extensions';\n/** Accepted spelling of the same root, for packages that prefer the singular. */\nexport const ROUTING_ROOT_ALIAS = 'src/extension';\n\n/** Group folders that also select a build side. */\nexport const BACKEND_GROUP = 'backend';\nexport const FRONTEND_GROUP = 'frontend';\n\n/** Scope segments, in nesting order below the routing root. */\nexport const WORKSPACE_SEGMENT = 'workspaces';\nexport const SESSION_SEGMENT = 'sessions';\n\n/** Gate folders. Each is followed by exactly one id segment. */\nexport const GATE_SEGMENTS: readonly string[] = ['mode', 'domain'];\n\n/** The leaf filename of an HTTP route, as Next.js spells it. */\nexport const ROUTE_FILE_NAME = 'route';\n\n/**\n * The reserved filename that constructs a scope, as Next.js spells a layout.\n *\n * One per scope and side. It runs before every contribution beneath it, and\n * whatever it returns is handed to each of them as part of the mount context,\n * which is how a package with one shared per-mount object graph decomposes\n * into a file per surface instead of one closure.\n */\nexport const ROOT_FILE_NAME = 'root';\n\n/**\n * Where generated entries are written, package-relative.\n *\n * Not `src`. That directory is authored code, and a build that writes into it\n * makes every package carry output its author did not write and must not edit.\n * This one is gitignored per package, and the repository's formatter already\n * skips a directory by this name.\n */\nexport const GENERATED_DIR = 'generated';\n\n/**\n * The generated entry each build target writes, keyed by the target it serves.\n *\n * Keyed rather than positional, so adding a generated file never rotates which\n * host each entry belongs to.\n */\nexport const GENERATED_ENTRY_FILENAMES = { server: 'server', web: 'web', native: 'native', mcp: 'mcp' } as const;\n\n/**\n * The generated typed client, which is not a build target.\n *\n * Nothing bundles it as an entry: a `(frontend)` file imports it and the\n * cockpit's browser build pulls it in from there. It is listed among the\n * managed names so that a package which drops its route table has the stale\n * client deleted rather than left behind.\n */\nexport const GENERATED_CLIENT_NAME = 'client';\n\n/**\n * The route table a package authors, and the switch that asks for a client.\n *\n * Its presence is what opts a package in, the way `src/exports/apiContracts.ts`\n * is what asks for a contracts entry. It lives under `src/types` because that\n * is one of the two source roots a browser bundle may read.\n */\nexport const API_ROUTES_MODULE = 'src/types/apiRoutes.ts';\n\n/**\n * Every generated basename. Never scanned, never hand-edited.\n *\n * Spelled out rather than derived from the two declarations above, because a\n * constants module holds data a reader can see without running it. The cost is\n * that the names appear twice; the generate tests assert the two agree.\n *\n * `pi` is the retired terminal entry. It stays managed so a regenerate deletes\n * the stale file a package built before the terminal host was removed.\n */\nexport const GENERATED_ENTRY_NAMES: readonly string[] = ['pi', 'server', 'web', 'native', 'mcp', 'client'];\n\n/** The retired terminal platform suffix. A routed file naming it is rejected. */\nexport const RETIRED_PLATFORM = 'cli';\n\n/**\n * Platform suffixes, scoped to their side. A target may not reuse one of these words.\n *\n * Every public routed file names one of these, so which host reads it is read\n * off the filename rather than inferred. A file that names none is a notice.\n */\nexport const BACKEND_PLATFORMS: readonly string[] = ['server', 'mcp'];\nexport const FRONTEND_PLATFORMS: readonly string[] = ['web', 'native', 'ios', 'android', 'desktop'];\n\n/**\n * The React Native frontend, for the iOS and Android app alike.\n *\n * Only a file naming it reaches the native host. An unsuffixed frontend file is\n * never a fallback here, because the web half is free to use the DOM.\n */\nexport const NATIVE_PLATFORM = 'native';\n\n/** The hosts this build emits. A frontend platform outside this set is authorable but unbuildable. */\nexport const BUILD_TARGET_PLATFORMS: readonly string[] = ['server', 'web', 'native', 'mcp'];\n\n/**\n * Surfaces that produce contributions on the backend side.\n *\n * `mode` is absent on purpose: it is a gate folder, so it is consumed before\n * the surface check and its declaration file synthesises the surface instead.\n */\nexport const BACKEND_SURFACES: readonly string[] = [\n 'tool',\n 'skill',\n 'tool-restriction',\n 'command',\n 'hook',\n 'api',\n 'channel',\n 'method',\n 'provider',\n 'resource',\n];\n\n/**\n * Surfaces that produce contributions on the frontend side.\n */\nexport const FRONTEND_SURFACES: readonly string[] = [\n 'tool',\n 'command',\n 'api',\n 'channel',\n 'method',\n 'tab',\n 'template',\n 'dock',\n 'setting',\n 'slot',\n 'fill',\n 'action',\n 'store',\n 'activity-group',\n 'leader',\n 'selection-axis',\n 'lifecycle',\n 'file-links',\n 'repository-settings-panel',\n];\n\n/** Surfaces whose filename carries a relationship target. */\nexport const TARGETED_SURFACES: readonly string[] = ['fill', 'action'];\n\n/** Surfaces whose folders below the surface spell a route path. */\nexport const ROUTED_SURFACES: readonly string[] = ['api'];\n\n/** Source extensions the scan accepts. */\nexport const SOURCE_EXTENSIONS: readonly string[] = ['ts', 'tsx', 'mts', 'cts'];\n\n/** Filename infixes excluded everywhere, whatever their position. */\nexport const EXCLUDED_INFIXES: readonly string[] = ['test', 'spec', 'stories'];\n\n/** Marks a folder as organisational: not a path segment, contents still scanned. */\nexport const GROUP_PREFIX = '(';\nexport const GROUP_SUFFIX = ')';\n/** Marks a folder as private: never scanned, never built. */\nexport const PRIVATE_PREFIX = '_';\n/** Marks a folder as a dynamic route segment. */\nexport const DYNAMIC_PREFIX = '[';\nexport const DYNAMIC_SUFFIX = ']';\n/** Marks a dynamic segment as catch-all. */\nexport const CATCH_ALL_MARKER = '...';\n"],"mappings":"AAQA,MAaaA,EAAmC,CAAC,OAAQ,QAAQ,EA+BpDC,EAA4B,CAAE,OAAQ,SAAU,IAAK,MAAO,OAAQ,SAAU,IAAK,KAAM,EA+BzFC,EAA2C,CAAC,KAAM,SAAU,MAAO,SAAU,MAAO,QAAQ,EAW5FC,EAAuC,CAAC,SAAU,KAAK,EACvDC,EAAwC,CAAC,MAAO,SAAU,MAAO,UAAW,SAAS,EAWrFC,EAA4C,CAAC,SAAU,MAAO,SAAU,KAAK,EAQ7EC,EAAsC,CACjD,OACA,QACA,mBACA,UACA,OACA,MACA,UACA,SACA,WACA,UACF,EAKaC,EAAuC,CAClD,OACA,UACA,MACA,UACA,SACA,MACA,WACA,OACA,UACA,OACA,OACA,SACA,QACA,iBACA,SACA,iBACA,YACA,aACA,2BACF,EAGaC,EAAuC,CAAC,OAAQ,QAAQ,EAGxDC,EAAqC,CAAC,KAAK,EAG3CC,EAAuC,CAAC,KAAM,MAAO,MAAO,KAAK,EAGjEC,EAAsC,CAAC,OAAQ,OAAQ,SAAS"}
1
+ {"version":3,"file":"layout.cjs","names":["GATE_SEGMENTS","GENERATED_ENTRY_FILENAMES","GENERATED_ENTRY_NAMES","BACKEND_PLATFORMS","FRONTEND_PLATFORMS","BUILD_TARGET_PLATFORMS","BACKEND_SURFACES","FRONTEND_SURFACES","TARGETED_SURFACES","ROUTED_SURFACES","SOURCE_EXTENSIONS","EXCLUDED_INFIXES"],"sources":["../../src/constants/layout.ts"],"sourcesContent":["/**\n * The folder-convention vocabulary, in one place.\n *\n * Every name here is part of the authoring contract in\n * docs/extension-layout.md. Adding a surface means adding it to both.\n */\n\n/** Where the scan starts, package-relative. */\nexport const DEFAULT_ROUTING_ROOT = 'src/extensions';\n/** Accepted spelling of the same root, for packages that prefer the singular. */\nexport const ROUTING_ROOT_ALIAS = 'src/extension';\n\n/** Group folders that also select a build side. */\nexport const BACKEND_GROUP = 'backend';\nexport const FRONTEND_GROUP = 'frontend';\n\n/** Scope segments, in nesting order below the routing root. */\nexport const WORKSPACE_SEGMENT = 'workspaces';\nexport const SESSION_SEGMENT = 'sessions';\n\n/** Gate folders. Each is followed by exactly one id segment. */\nexport const GATE_SEGMENTS: readonly string[] = ['mode', 'domain'];\n\n/** The leaf filename of an HTTP route, as Next.js spells it. */\nexport const ROUTE_FILE_NAME = 'route';\n\n/**\n * The reserved filename that constructs a scope, as Next.js spells a layout.\n *\n * One per scope and side. It runs before every contribution beneath it, and\n * whatever it returns is handed to each of them as part of the mount context,\n * which is how a package with one shared per-mount object graph decomposes\n * into a file per surface instead of one closure.\n */\nexport const ROOT_FILE_NAME = 'root';\n\n/**\n * Where generated entries are written, package-relative.\n *\n * Not `src`. That directory is authored code, and a build that writes into it\n * makes every package carry output its author did not write and must not edit.\n * This one is gitignored per package, and the repository's formatter already\n * skips a directory by this name.\n */\nexport const GENERATED_DIR = 'generated';\n\n/**\n * The generated entry each build target writes, keyed by the target it serves.\n *\n * Keyed rather than positional, so adding a generated file never rotates which\n * host each entry belongs to.\n */\nexport const GENERATED_ENTRY_FILENAMES = { server: 'server', web: 'web', native: 'native', mcp: 'mcp' } as const;\n\n/**\n * The generated typed client, which is not a build target.\n *\n * Nothing bundles it as an entry: a `(frontend)` file imports it and the\n * cockpit's browser build pulls it in from there. It is listed among the\n * managed names so that a package which drops its route table has the stale\n * client deleted rather than left behind.\n */\nexport const GENERATED_CLIENT_NAME = 'client';\n\n/**\n * The same client for a `.native` file, which may import neither the browser\n * contract nor the browser's sealed transport. Imported by its full name: the\n * native build is not Metro and resolves no platform suffix.\n */\nexport const GENERATED_NATIVE_CLIENT_NAME = 'client.native';\n\n/**\n * The route table a package authors, and the switch that asks for a client.\n *\n * Its presence is what opts a package in, the way `src/exports/apiContracts.ts`\n * is what asks for a contracts entry. It lives under `src/types` because that\n * is one of the two source roots a browser bundle may read.\n */\nexport const API_ROUTES_MODULE = 'src/types/apiRoutes.ts';\n\n/**\n * Every generated basename. Never scanned, never hand-edited.\n *\n * Spelled out rather than derived from the two declarations above, because a\n * constants module holds data a reader can see without running it. The cost is\n * that the names appear twice; the generate tests assert the two agree.\n *\n * `pi` is the retired terminal entry. It stays managed so a regenerate deletes\n * the stale file a package built before the terminal host was removed.\n */\nexport const GENERATED_ENTRY_NAMES: readonly string[] = [\n 'pi',\n 'server',\n 'web',\n 'native',\n 'mcp',\n 'client',\n 'client.native',\n];\n\n/** The retired terminal platform suffix. A routed file naming it is rejected. */\nexport const RETIRED_PLATFORM = 'cli';\n\n/**\n * Platform suffixes, scoped to their side. A target may not reuse one of these words.\n *\n * Every public routed file names one of these, so which host reads it is read\n * off the filename rather than inferred. A file that names none is a notice.\n */\nexport const BACKEND_PLATFORMS: readonly string[] = ['server', 'mcp'];\nexport const FRONTEND_PLATFORMS: readonly string[] = ['web', 'native', 'ios', 'android', 'desktop'];\n\n/**\n * The React Native frontend, for the iOS and Android app alike.\n *\n * Only a file naming it reaches the native host. An unsuffixed frontend file is\n * never a fallback here, because the web half is free to use the DOM.\n */\nexport const NATIVE_PLATFORM = 'native';\n\n/** The hosts this build emits. A frontend platform outside this set is authorable but unbuildable. */\nexport const BUILD_TARGET_PLATFORMS: readonly string[] = ['server', 'web', 'native', 'mcp'];\n\n/**\n * Surfaces that produce contributions on the backend side.\n *\n * `mode` is absent on purpose: it is a gate folder, so it is consumed before\n * the surface check and its declaration file synthesises the surface instead.\n */\nexport const BACKEND_SURFACES: readonly string[] = [\n 'tool',\n 'skill',\n 'tool-restriction',\n 'command',\n 'hook',\n 'api',\n 'channel',\n 'method',\n 'provider',\n 'resource',\n];\n\n/**\n * Surfaces that produce contributions on the frontend side.\n */\nexport const FRONTEND_SURFACES: readonly string[] = [\n 'tool',\n 'command',\n 'api',\n 'channel',\n 'method',\n 'tab',\n 'template',\n 'dock',\n 'setting',\n 'slot',\n 'fill',\n 'action',\n 'store',\n 'activity-group',\n 'leader',\n 'selection-axis',\n 'lifecycle',\n 'file-links',\n 'repository-settings-panel',\n];\n\n/** Surfaces whose filename carries a relationship target. */\nexport const TARGETED_SURFACES: readonly string[] = ['fill', 'action'];\n\n/** Surfaces whose folders below the surface spell a route path. */\nexport const ROUTED_SURFACES: readonly string[] = ['api'];\n\n/** Source extensions the scan accepts. */\nexport const SOURCE_EXTENSIONS: readonly string[] = ['ts', 'tsx', 'mts', 'cts'];\n\n/**\n * Filename infixes excluded everywhere, whatever their position. `edge` marks a\n * workerd variant of its base sibling, resolved only by the private Worker build.\n */\nexport const EXCLUDED_INFIXES: readonly string[] = ['test', 'spec', 'stories', 'edge'];\n\n/** Marks a folder as organisational: not a path segment, contents still scanned. */\nexport const GROUP_PREFIX = '(';\nexport const GROUP_SUFFIX = ')';\n/** Marks a folder as private: never scanned, never built. */\nexport const PRIVATE_PREFIX = '_';\n/** Marks a folder as a dynamic route segment. */\nexport const DYNAMIC_PREFIX = '[';\nexport const DYNAMIC_SUFFIX = ']';\n/** Marks a dynamic segment as catch-all. */\nexport const CATCH_ALL_MARKER = '...';\n"],"mappings":"AAQA,MAaaA,EAAmC,CAAC,OAAQ,QAAQ,EA+BpDC,EAA4B,CAAE,OAAQ,SAAU,IAAK,MAAO,OAAQ,SAAU,IAAK,KAAM,EAsCzFC,EAA2C,CACtD,KACA,SACA,MACA,SACA,MACA,SACA,eACF,EAWaC,EAAuC,CAAC,SAAU,KAAK,EACvDC,EAAwC,CAAC,MAAO,SAAU,MAAO,UAAW,SAAS,EAWrFC,EAA4C,CAAC,SAAU,MAAO,SAAU,KAAK,EAQ7EC,EAAsC,CACjD,OACA,QACA,mBACA,UACA,OACA,MACA,UACA,SACA,WACA,UACF,EAKaC,EAAuC,CAClD,OACA,UACA,MACA,UACA,SACA,MACA,WACA,OACA,UACA,OACA,OACA,SACA,QACA,iBACA,SACA,iBACA,YACA,aACA,2BACF,EAGaC,EAAuC,CAAC,OAAQ,QAAQ,EAGxDC,EAAqC,CAAC,KAAK,EAG3CC,EAAuC,CAAC,KAAM,MAAO,MAAO,KAAK,EAMjEC,EAAsC,CAAC,OAAQ,OAAQ,UAAW,MAAM"}
@@ -1 +1 @@
1
- {"version":3,"file":"layout.d.mts","names":[],"sources":["../../src/constants/layout.ts"],"mappings":";;;;;;;;qBAQa;;qBAEA;;qBAWA;;qBAGA;;;;;;;;;qBAoBA;;;;;;;qBAkDA;qBACA;;;;;;;qBAQA;;;;;;;qBAWA;;;;qBAgBA;;qBAuBA;;qBAGA"}
1
+ {"version":3,"file":"layout.d.mts","names":[],"sources":["../../src/constants/layout.ts"],"mappings":";;;;;;;;qBAQa;;qBAEA;;qBAWA;;qBAGA;;;;;;;;;qBAoBA;;;;;;;qBAiEA;qBACA;;;;;;;qBAQA;;;;;;;qBAWA;;;;qBAgBA;;qBAuBA;;qBAGA"}
@@ -1,2 +1,2 @@
1
- const e=`src/extensions`,t=`src/extension`,n=`backend`,r=`frontend`,i=`workspaces`,a=`sessions`,o=[`mode`,`domain`],s=`route`,c=`root`,l=`generated`,u={server:`server`,web:`web`,native:`native`,mcp:`mcp`},d=`client`,f=`src/types/apiRoutes.ts`,p=[`pi`,`server`,`web`,`native`,`mcp`,`client`],m=[`server`,`mcp`],h=[`web`,`native`,`ios`,`android`,`desktop`],g=`native`,_=[`server`,`web`,`native`,`mcp`],v=[`tool`,`skill`,`tool-restriction`,`command`,`hook`,`api`,`channel`,`method`,`provider`,`resource`],y=[`tool`,`command`,`api`,`channel`,`method`,`tab`,`template`,`dock`,`setting`,`slot`,`fill`,`action`,`store`,`activity-group`,`leader`,`selection-axis`,`lifecycle`,`file-links`,`repository-settings-panel`],b=[`fill`,`action`],x=[`api`],S=[`ts`,`tsx`,`mts`,`cts`],C=[`test`,`spec`,`stories`];export{f as API_ROUTES_MODULE,n as BACKEND_GROUP,m as BACKEND_PLATFORMS,v as BACKEND_SURFACES,_ as BUILD_TARGET_PLATFORMS,e as DEFAULT_ROUTING_ROOT,C as EXCLUDED_INFIXES,r as FRONTEND_GROUP,h as FRONTEND_PLATFORMS,y as FRONTEND_SURFACES,o as GATE_SEGMENTS,d as GENERATED_CLIENT_NAME,l as GENERATED_DIR,u as GENERATED_ENTRY_FILENAMES,p as GENERATED_ENTRY_NAMES,g as NATIVE_PLATFORM,c as ROOT_FILE_NAME,x as ROUTED_SURFACES,s as ROUTE_FILE_NAME,t as ROUTING_ROOT_ALIAS,a as SESSION_SEGMENT,S as SOURCE_EXTENSIONS,b as TARGETED_SURFACES,i as WORKSPACE_SEGMENT};
1
+ const e=`src/extensions`,t=`src/extension`,n=`backend`,r=`frontend`,i=`workspaces`,a=`sessions`,o=[`mode`,`domain`],s=`route`,c=`root`,l=`generated`,u={server:`server`,web:`web`,native:`native`,mcp:`mcp`},d=`client`,f=`client.native`,p=`src/types/apiRoutes.ts`,m=[`pi`,`server`,`web`,`native`,`mcp`,`client`,`client.native`],h=[`server`,`mcp`],g=[`web`,`native`,`ios`,`android`,`desktop`],_=`native`,v=[`server`,`web`,`native`,`mcp`],y=[`tool`,`skill`,`tool-restriction`,`command`,`hook`,`api`,`channel`,`method`,`provider`,`resource`],b=[`tool`,`command`,`api`,`channel`,`method`,`tab`,`template`,`dock`,`setting`,`slot`,`fill`,`action`,`store`,`activity-group`,`leader`,`selection-axis`,`lifecycle`,`file-links`,`repository-settings-panel`],x=[`fill`,`action`],S=[`api`],C=[`ts`,`tsx`,`mts`,`cts`],w=[`test`,`spec`,`stories`,`edge`];export{p as API_ROUTES_MODULE,n as BACKEND_GROUP,h as BACKEND_PLATFORMS,y as BACKEND_SURFACES,v as BUILD_TARGET_PLATFORMS,e as DEFAULT_ROUTING_ROOT,w as EXCLUDED_INFIXES,r as FRONTEND_GROUP,g as FRONTEND_PLATFORMS,b as FRONTEND_SURFACES,o as GATE_SEGMENTS,d as GENERATED_CLIENT_NAME,l as GENERATED_DIR,u as GENERATED_ENTRY_FILENAMES,m as GENERATED_ENTRY_NAMES,f as GENERATED_NATIVE_CLIENT_NAME,_ as NATIVE_PLATFORM,c as ROOT_FILE_NAME,S as ROUTED_SURFACES,s as ROUTE_FILE_NAME,t as ROUTING_ROOT_ALIAS,a as SESSION_SEGMENT,C as SOURCE_EXTENSIONS,x as TARGETED_SURFACES,i as WORKSPACE_SEGMENT};
2
2
  //# sourceMappingURL=layout.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"layout.mjs","names":["DEFAULT_ROUTING_ROOT","ROUTING_ROOT_ALIAS","BACKEND_GROUP","FRONTEND_GROUP","WORKSPACE_SEGMENT","SESSION_SEGMENT","GATE_SEGMENTS","ROUTE_FILE_NAME","ROOT_FILE_NAME","GENERATED_DIR","GENERATED_ENTRY_FILENAMES","GENERATED_CLIENT_NAME","API_ROUTES_MODULE","GENERATED_ENTRY_NAMES","BACKEND_PLATFORMS","FRONTEND_PLATFORMS","NATIVE_PLATFORM","BUILD_TARGET_PLATFORMS","BACKEND_SURFACES","FRONTEND_SURFACES","TARGETED_SURFACES","ROUTED_SURFACES","SOURCE_EXTENSIONS","EXCLUDED_INFIXES"],"sources":["../../src/constants/layout.ts"],"sourcesContent":["/**\n * The folder-convention vocabulary, in one place.\n *\n * Every name here is part of the authoring contract in\n * docs/extension-layout.md. Adding a surface means adding it to both.\n */\n\n/** Where the scan starts, package-relative. */\nexport const DEFAULT_ROUTING_ROOT = 'src/extensions';\n/** Accepted spelling of the same root, for packages that prefer the singular. */\nexport const ROUTING_ROOT_ALIAS = 'src/extension';\n\n/** Group folders that also select a build side. */\nexport const BACKEND_GROUP = 'backend';\nexport const FRONTEND_GROUP = 'frontend';\n\n/** Scope segments, in nesting order below the routing root. */\nexport const WORKSPACE_SEGMENT = 'workspaces';\nexport const SESSION_SEGMENT = 'sessions';\n\n/** Gate folders. Each is followed by exactly one id segment. */\nexport const GATE_SEGMENTS: readonly string[] = ['mode', 'domain'];\n\n/** The leaf filename of an HTTP route, as Next.js spells it. */\nexport const ROUTE_FILE_NAME = 'route';\n\n/**\n * The reserved filename that constructs a scope, as Next.js spells a layout.\n *\n * One per scope and side. It runs before every contribution beneath it, and\n * whatever it returns is handed to each of them as part of the mount context,\n * which is how a package with one shared per-mount object graph decomposes\n * into a file per surface instead of one closure.\n */\nexport const ROOT_FILE_NAME = 'root';\n\n/**\n * Where generated entries are written, package-relative.\n *\n * Not `src`. That directory is authored code, and a build that writes into it\n * makes every package carry output its author did not write and must not edit.\n * This one is gitignored per package, and the repository's formatter already\n * skips a directory by this name.\n */\nexport const GENERATED_DIR = 'generated';\n\n/**\n * The generated entry each build target writes, keyed by the target it serves.\n *\n * Keyed rather than positional, so adding a generated file never rotates which\n * host each entry belongs to.\n */\nexport const GENERATED_ENTRY_FILENAMES = { server: 'server', web: 'web', native: 'native', mcp: 'mcp' } as const;\n\n/**\n * The generated typed client, which is not a build target.\n *\n * Nothing bundles it as an entry: a `(frontend)` file imports it and the\n * cockpit's browser build pulls it in from there. It is listed among the\n * managed names so that a package which drops its route table has the stale\n * client deleted rather than left behind.\n */\nexport const GENERATED_CLIENT_NAME = 'client';\n\n/**\n * The route table a package authors, and the switch that asks for a client.\n *\n * Its presence is what opts a package in, the way `src/exports/apiContracts.ts`\n * is what asks for a contracts entry. It lives under `src/types` because that\n * is one of the two source roots a browser bundle may read.\n */\nexport const API_ROUTES_MODULE = 'src/types/apiRoutes.ts';\n\n/**\n * Every generated basename. Never scanned, never hand-edited.\n *\n * Spelled out rather than derived from the two declarations above, because a\n * constants module holds data a reader can see without running it. The cost is\n * that the names appear twice; the generate tests assert the two agree.\n *\n * `pi` is the retired terminal entry. It stays managed so a regenerate deletes\n * the stale file a package built before the terminal host was removed.\n */\nexport const GENERATED_ENTRY_NAMES: readonly string[] = ['pi', 'server', 'web', 'native', 'mcp', 'client'];\n\n/** The retired terminal platform suffix. A routed file naming it is rejected. */\nexport const RETIRED_PLATFORM = 'cli';\n\n/**\n * Platform suffixes, scoped to their side. A target may not reuse one of these words.\n *\n * Every public routed file names one of these, so which host reads it is read\n * off the filename rather than inferred. A file that names none is a notice.\n */\nexport const BACKEND_PLATFORMS: readonly string[] = ['server', 'mcp'];\nexport const FRONTEND_PLATFORMS: readonly string[] = ['web', 'native', 'ios', 'android', 'desktop'];\n\n/**\n * The React Native frontend, for the iOS and Android app alike.\n *\n * Only a file naming it reaches the native host. An unsuffixed frontend file is\n * never a fallback here, because the web half is free to use the DOM.\n */\nexport const NATIVE_PLATFORM = 'native';\n\n/** The hosts this build emits. A frontend platform outside this set is authorable but unbuildable. */\nexport const BUILD_TARGET_PLATFORMS: readonly string[] = ['server', 'web', 'native', 'mcp'];\n\n/**\n * Surfaces that produce contributions on the backend side.\n *\n * `mode` is absent on purpose: it is a gate folder, so it is consumed before\n * the surface check and its declaration file synthesises the surface instead.\n */\nexport const BACKEND_SURFACES: readonly string[] = [\n 'tool',\n 'skill',\n 'tool-restriction',\n 'command',\n 'hook',\n 'api',\n 'channel',\n 'method',\n 'provider',\n 'resource',\n];\n\n/**\n * Surfaces that produce contributions on the frontend side.\n */\nexport const FRONTEND_SURFACES: readonly string[] = [\n 'tool',\n 'command',\n 'api',\n 'channel',\n 'method',\n 'tab',\n 'template',\n 'dock',\n 'setting',\n 'slot',\n 'fill',\n 'action',\n 'store',\n 'activity-group',\n 'leader',\n 'selection-axis',\n 'lifecycle',\n 'file-links',\n 'repository-settings-panel',\n];\n\n/** Surfaces whose filename carries a relationship target. */\nexport const TARGETED_SURFACES: readonly string[] = ['fill', 'action'];\n\n/** Surfaces whose folders below the surface spell a route path. */\nexport const ROUTED_SURFACES: readonly string[] = ['api'];\n\n/** Source extensions the scan accepts. */\nexport const SOURCE_EXTENSIONS: readonly string[] = ['ts', 'tsx', 'mts', 'cts'];\n\n/** Filename infixes excluded everywhere, whatever their position. */\nexport const EXCLUDED_INFIXES: readonly string[] = ['test', 'spec', 'stories'];\n\n/** Marks a folder as organisational: not a path segment, contents still scanned. */\nexport const GROUP_PREFIX = '(';\nexport const GROUP_SUFFIX = ')';\n/** Marks a folder as private: never scanned, never built. */\nexport const PRIVATE_PREFIX = '_';\n/** Marks a folder as a dynamic route segment. */\nexport const DYNAMIC_PREFIX = '[';\nexport const DYNAMIC_SUFFIX = ']';\n/** Marks a dynamic segment as catch-all. */\nexport const CATCH_ALL_MARKER = '...';\n"],"mappings":"AAQA,MAAaA,EAAuB,iBAEvBC,EAAqB,gBAGrBC,EAAgB,UAChBC,EAAiB,WAGjBC,EAAoB,aACpBC,EAAkB,WAGlBC,EAAmC,CAAC,OAAQ,QAAQ,EAGpDC,EAAkB,QAUlBC,EAAiB,OAUjBC,EAAgB,YAQhBC,EAA4B,CAAE,OAAQ,SAAU,IAAK,MAAO,OAAQ,SAAU,IAAK,KAAM,EAUzFC,EAAwB,SASxBC,EAAoB,yBAYpBC,EAA2C,CAAC,KAAM,SAAU,MAAO,SAAU,MAAO,QAAQ,EAW5FC,EAAuC,CAAC,SAAU,KAAK,EACvDC,EAAwC,CAAC,MAAO,SAAU,MAAO,UAAW,SAAS,EAQrFC,EAAkB,SAGlBC,EAA4C,CAAC,SAAU,MAAO,SAAU,KAAK,EAQ7EC,EAAsC,CACjD,OACA,QACA,mBACA,UACA,OACA,MACA,UACA,SACA,WACA,UACF,EAKaC,EAAuC,CAClD,OACA,UACA,MACA,UACA,SACA,MACA,WACA,OACA,UACA,OACA,OACA,SACA,QACA,iBACA,SACA,iBACA,YACA,aACA,2BACF,EAGaC,EAAuC,CAAC,OAAQ,QAAQ,EAGxDC,EAAqC,CAAC,KAAK,EAG3CC,EAAuC,CAAC,KAAM,MAAO,MAAO,KAAK,EAGjEC,EAAsC,CAAC,OAAQ,OAAQ,SAAS"}
1
+ {"version":3,"file":"layout.mjs","names":["DEFAULT_ROUTING_ROOT","ROUTING_ROOT_ALIAS","BACKEND_GROUP","FRONTEND_GROUP","WORKSPACE_SEGMENT","SESSION_SEGMENT","GATE_SEGMENTS","ROUTE_FILE_NAME","ROOT_FILE_NAME","GENERATED_DIR","GENERATED_ENTRY_FILENAMES","GENERATED_CLIENT_NAME","GENERATED_NATIVE_CLIENT_NAME","API_ROUTES_MODULE","GENERATED_ENTRY_NAMES","BACKEND_PLATFORMS","FRONTEND_PLATFORMS","NATIVE_PLATFORM","BUILD_TARGET_PLATFORMS","BACKEND_SURFACES","FRONTEND_SURFACES","TARGETED_SURFACES","ROUTED_SURFACES","SOURCE_EXTENSIONS","EXCLUDED_INFIXES"],"sources":["../../src/constants/layout.ts"],"sourcesContent":["/**\n * The folder-convention vocabulary, in one place.\n *\n * Every name here is part of the authoring contract in\n * docs/extension-layout.md. Adding a surface means adding it to both.\n */\n\n/** Where the scan starts, package-relative. */\nexport const DEFAULT_ROUTING_ROOT = 'src/extensions';\n/** Accepted spelling of the same root, for packages that prefer the singular. */\nexport const ROUTING_ROOT_ALIAS = 'src/extension';\n\n/** Group folders that also select a build side. */\nexport const BACKEND_GROUP = 'backend';\nexport const FRONTEND_GROUP = 'frontend';\n\n/** Scope segments, in nesting order below the routing root. */\nexport const WORKSPACE_SEGMENT = 'workspaces';\nexport const SESSION_SEGMENT = 'sessions';\n\n/** Gate folders. Each is followed by exactly one id segment. */\nexport const GATE_SEGMENTS: readonly string[] = ['mode', 'domain'];\n\n/** The leaf filename of an HTTP route, as Next.js spells it. */\nexport const ROUTE_FILE_NAME = 'route';\n\n/**\n * The reserved filename that constructs a scope, as Next.js spells a layout.\n *\n * One per scope and side. It runs before every contribution beneath it, and\n * whatever it returns is handed to each of them as part of the mount context,\n * which is how a package with one shared per-mount object graph decomposes\n * into a file per surface instead of one closure.\n */\nexport const ROOT_FILE_NAME = 'root';\n\n/**\n * Where generated entries are written, package-relative.\n *\n * Not `src`. That directory is authored code, and a build that writes into it\n * makes every package carry output its author did not write and must not edit.\n * This one is gitignored per package, and the repository's formatter already\n * skips a directory by this name.\n */\nexport const GENERATED_DIR = 'generated';\n\n/**\n * The generated entry each build target writes, keyed by the target it serves.\n *\n * Keyed rather than positional, so adding a generated file never rotates which\n * host each entry belongs to.\n */\nexport const GENERATED_ENTRY_FILENAMES = { server: 'server', web: 'web', native: 'native', mcp: 'mcp' } as const;\n\n/**\n * The generated typed client, which is not a build target.\n *\n * Nothing bundles it as an entry: a `(frontend)` file imports it and the\n * cockpit's browser build pulls it in from there. It is listed among the\n * managed names so that a package which drops its route table has the stale\n * client deleted rather than left behind.\n */\nexport const GENERATED_CLIENT_NAME = 'client';\n\n/**\n * The same client for a `.native` file, which may import neither the browser\n * contract nor the browser's sealed transport. Imported by its full name: the\n * native build is not Metro and resolves no platform suffix.\n */\nexport const GENERATED_NATIVE_CLIENT_NAME = 'client.native';\n\n/**\n * The route table a package authors, and the switch that asks for a client.\n *\n * Its presence is what opts a package in, the way `src/exports/apiContracts.ts`\n * is what asks for a contracts entry. It lives under `src/types` because that\n * is one of the two source roots a browser bundle may read.\n */\nexport const API_ROUTES_MODULE = 'src/types/apiRoutes.ts';\n\n/**\n * Every generated basename. Never scanned, never hand-edited.\n *\n * Spelled out rather than derived from the two declarations above, because a\n * constants module holds data a reader can see without running it. The cost is\n * that the names appear twice; the generate tests assert the two agree.\n *\n * `pi` is the retired terminal entry. It stays managed so a regenerate deletes\n * the stale file a package built before the terminal host was removed.\n */\nexport const GENERATED_ENTRY_NAMES: readonly string[] = [\n 'pi',\n 'server',\n 'web',\n 'native',\n 'mcp',\n 'client',\n 'client.native',\n];\n\n/** The retired terminal platform suffix. A routed file naming it is rejected. */\nexport const RETIRED_PLATFORM = 'cli';\n\n/**\n * Platform suffixes, scoped to their side. A target may not reuse one of these words.\n *\n * Every public routed file names one of these, so which host reads it is read\n * off the filename rather than inferred. A file that names none is a notice.\n */\nexport const BACKEND_PLATFORMS: readonly string[] = ['server', 'mcp'];\nexport const FRONTEND_PLATFORMS: readonly string[] = ['web', 'native', 'ios', 'android', 'desktop'];\n\n/**\n * The React Native frontend, for the iOS and Android app alike.\n *\n * Only a file naming it reaches the native host. An unsuffixed frontend file is\n * never a fallback here, because the web half is free to use the DOM.\n */\nexport const NATIVE_PLATFORM = 'native';\n\n/** The hosts this build emits. A frontend platform outside this set is authorable but unbuildable. */\nexport const BUILD_TARGET_PLATFORMS: readonly string[] = ['server', 'web', 'native', 'mcp'];\n\n/**\n * Surfaces that produce contributions on the backend side.\n *\n * `mode` is absent on purpose: it is a gate folder, so it is consumed before\n * the surface check and its declaration file synthesises the surface instead.\n */\nexport const BACKEND_SURFACES: readonly string[] = [\n 'tool',\n 'skill',\n 'tool-restriction',\n 'command',\n 'hook',\n 'api',\n 'channel',\n 'method',\n 'provider',\n 'resource',\n];\n\n/**\n * Surfaces that produce contributions on the frontend side.\n */\nexport const FRONTEND_SURFACES: readonly string[] = [\n 'tool',\n 'command',\n 'api',\n 'channel',\n 'method',\n 'tab',\n 'template',\n 'dock',\n 'setting',\n 'slot',\n 'fill',\n 'action',\n 'store',\n 'activity-group',\n 'leader',\n 'selection-axis',\n 'lifecycle',\n 'file-links',\n 'repository-settings-panel',\n];\n\n/** Surfaces whose filename carries a relationship target. */\nexport const TARGETED_SURFACES: readonly string[] = ['fill', 'action'];\n\n/** Surfaces whose folders below the surface spell a route path. */\nexport const ROUTED_SURFACES: readonly string[] = ['api'];\n\n/** Source extensions the scan accepts. */\nexport const SOURCE_EXTENSIONS: readonly string[] = ['ts', 'tsx', 'mts', 'cts'];\n\n/**\n * Filename infixes excluded everywhere, whatever their position. `edge` marks a\n * workerd variant of its base sibling, resolved only by the private Worker build.\n */\nexport const EXCLUDED_INFIXES: readonly string[] = ['test', 'spec', 'stories', 'edge'];\n\n/** Marks a folder as organisational: not a path segment, contents still scanned. */\nexport const GROUP_PREFIX = '(';\nexport const GROUP_SUFFIX = ')';\n/** Marks a folder as private: never scanned, never built. */\nexport const PRIVATE_PREFIX = '_';\n/** Marks a folder as a dynamic route segment. */\nexport const DYNAMIC_PREFIX = '[';\nexport const DYNAMIC_SUFFIX = ']';\n/** Marks a dynamic segment as catch-all. */\nexport const CATCH_ALL_MARKER = '...';\n"],"mappings":"AAQA,MAAaA,EAAuB,iBAEvBC,EAAqB,gBAGrBC,EAAgB,UAChBC,EAAiB,WAGjBC,EAAoB,aACpBC,EAAkB,WAGlBC,EAAmC,CAAC,OAAQ,QAAQ,EAGpDC,EAAkB,QAUlBC,EAAiB,OAUjBC,EAAgB,YAQhBC,EAA4B,CAAE,OAAQ,SAAU,IAAK,MAAO,OAAQ,SAAU,IAAK,KAAM,EAUzFC,EAAwB,SAOxBC,EAA+B,gBAS/BC,EAAoB,yBAYpBC,EAA2C,CACtD,KACA,SACA,MACA,SACA,MACA,SACA,eACF,EAWaC,EAAuC,CAAC,SAAU,KAAK,EACvDC,EAAwC,CAAC,MAAO,SAAU,MAAO,UAAW,SAAS,EAQrFC,EAAkB,SAGlBC,EAA4C,CAAC,SAAU,MAAO,SAAU,KAAK,EAQ7EC,EAAsC,CACjD,OACA,QACA,mBACA,UACA,OACA,MACA,UACA,SACA,WACA,UACF,EAKaC,EAAuC,CAClD,OACA,UACA,MACA,UACA,SACA,MACA,WACA,OACA,UACA,OACA,OACA,SACA,QACA,iBACA,SACA,iBACA,YACA,aACA,2BACF,EAGaC,EAAuC,CAAC,OAAQ,QAAQ,EAGxDC,EAAqC,CAAC,KAAK,EAG3CC,EAAuC,CAAC,KAAM,MAAO,MAAO,KAAK,EAMjEC,EAAsC,CAAC,OAAQ,OAAQ,UAAW,MAAM"}
@@ -1,3 +1,3 @@
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
- `)}`);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),S&&C&&w===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 T=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:E}=s.writeGenerated(e.packageDir,_,e.check,T);return{graph:h,packageName:a,pluginId:m,files:_,changed:E,notices:g,targets:v}}exports.defaultPluginId=u,exports.generateExtension=m;
2
+ `)}`);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
3
  //# 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","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","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} from '../../constants/layout';\nimport type { ExtensionGraph, ExtensionNotice } from '../../types/extensionGraph';\nimport { renderApiClient } 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 doomRoutedFilePosition 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 if (hasRouteTable && hasBrowserHalf && client === 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":"8ZAsBA,SAAgB4B,EAAgB,EAA6B,CAC3D,OAAOC,EAAY,QAAQ,aAAc,EAAE,CAAC,CAAC,QAAQ,QAAS,EAAE,CAClE,CAEA,SAASC,EAAgB,EAA4B,CACnD,IAAMC,EAAW,KAAK,MAAM/B,EAAAA,QAAG,aAAaC,EAAAA,QAAK,KAAK+B,EAAY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,GAAIA,EAAQ,SAAW,MAAQ,CAAC,GAAG3B,EAAAA,cAAc,WAAW,EAAI,CAAC,CACnE,EACA,CAAE,WAAYQ,EAAAA,eAAemB,EAAQ,WAAYI,EAAOJ,EAAQ,MAAOkB,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":["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 doomRoutedFilePosition 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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O,EACpF,MAAO,CAAE,QAAO,cAAa,WAAU,QAAO,UAAS,UAAS,SAAQ,CAC1E"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/generate/index.ts"],"mappings":";;;wBAsBgB,gBAAgB;;;;;;;;;wBA2BhB,kBAAkB,SAAS,kBAAkB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/generate/index.ts"],"mappings":";;;wBAuBgB,gBAAgB;;;;;;;;;wBA2BhB,kBAAkB,SAAS,kBAAkB"}
@@ -1,3 +1,3 @@
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}from"../../constants/layout.mjs";import{RETIRED_PLATFORM_NOTICE as o,scanExtensions as s}from"../scan/index.mjs";import{resolveTarget as c}from"../resolveTarget/index.mjs";import{renderApiClient as l}from"../renderClient/index.mjs";import{renderMcpEntry as u,renderNativeEntry as d,renderServerEntry as f,renderWebEntry as p}from"../renderEntry/index.mjs";import{renderMcpWidgets as m}from"../renderMcpWidgets/index.mjs";import{writeGenerated as h}from"../writeGenerated/index.mjs";import g from"node:fs";import _ from"node:path";function v(e){return e.replace(/^@[^/]+\//u,``).replace(/^po-/u,``)}function y(e){let t=JSON.parse(g.readFileSync(_.join(e,`package.json`),`utf8`));if(typeof t.name!=`string`)throw Error(`${e}/package.json has no name`);return t.name}const b={server:f,web:p,native:d,mcp:u},x=i;function S(i){let u=i.packageName??y(i.packageDir),d=i.pluginId??v(u),f=s(i),p=[...f.notices],S=/* @__PURE__ */ new Map,C=[],w=i.target===`mcp`?m(f,u,r):void 0;w?.source!==void 0&&S.set(`${r}/mcp-ui.ts`,w.source);for(let e of f.entries)e.platform===void 0||t.includes(e.platform)||p.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 T=f.notices.filter(e=>e.message===o);if(T.length>0)throw Error(`${u}: ${o}\n${T.map(e=>` ${e.path}`).join(`
2
- `)}`);let E=i.target===void 0?[`server`,`web`,`native`]:[i.target];for(let e of E){let t=c(f,e);if(p.push(...t.notices),t.contributions.length===0&&t.escapeHatches.length===0&&t.roots.length===0)continue;C.push(e);let n=b[e],i=n(t,{packageName:u,pluginId:d,root:f.root,entryDir:r,mcpWidgets:w?.declarations});S.set(`${r}/${x[e]}.ts`,i)}let D=i.target===void 0&&g.existsSync(_.join(i.packageDir,`src/types/apiRoutes.ts`)),O=C.includes(`web`),k=D&&O?l(f,{packageName:u,pluginId:d,root:f.root,entryDir:r}):void 0;k!==void 0&&S.set(`${r}/${n}.ts`,k),D&&O&&k===void 0&&p.push({path:e,message:`declares API routes, but no (backend)/api/<base-path>/ folder says where they are mounted`});let A=i.target===void 0?a.filter(e=>e!==`mcp`||!g.existsSync(_.join(i.packageDir,`tsdown.mcp.config.ts`))).map(e=>`${r}/${e}.ts`):[`${r}/${x[i.target]}.ts`,...i.target===`mcp`?[`${r}/mcp-ui.ts`]:[]],{changed:j}=h(i.packageDir,S,i.check,A);return{graph:f,packageName:u,pluginId:d,files:S,changed:j,notices:p,targets:C}}export{v as defaultPluginId,S as generateExtension};
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
+ `)}`);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
3
  //# 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","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} from '../../constants/layout';\nimport type { ExtensionGraph, ExtensionNotice } from '../../types/extensionGraph';\nimport { renderApiClient } 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 doomRoutedFilePosition 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 if (hasRouteTable && hasBrowserHalf && client === 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, pack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AAQ,KACnD,GAAIA,EAAQ,SAAW,MAAQ,CAAC,GAAGS,EAAc,WAAW,EAAI,CAAC,CACnE,EACA,CAAE,WAAYqB,EAAe9B,EAAQ,WAAYK,EAAOL,EAAQ,MAAO2B,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":["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 doomRoutedFilePosition 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,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,CAAC,EAC3F,IAAA,GACFc,IAAW,IAAA,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,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}`}function s(e){let t=e.scopes.map(e=>`'${e}'`).join(`, `),n=e.identifier===`api`?``:` for the ${e.basePath} mount`;return[`/** Scopes the tree mounts '${e.basePath}' at${n}. */`,`export const ${e.identifier}Scopes = [${t}] as const;`,``,`export const ${e.identifier} = createApiClient(routes, {`,` scopes: ${e.identifier}Scopes,`,` basePath: '${e.basePath}',`,` transport: (input, init) => sealedTransport.fetch(input, init),`,` sessionAddress: sessionApiAddress,`,`});`,``]}function c(e,t){let n=a(e);if(n.length!==0)return`${[`// Generated by @agimon-ai/po-build. Do not edit by hand.`,`import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';`,`import { sealedTransport } from '@agimon-ai/po-web-security/browser';`,``,`import routes from '${o(t.entryDir??`generated`)}';`,``,...n.flatMap(e=>s(e))].join(`
2
- `).replace(/\n+$/u,``)}\n`}exports.renderApiClient=c;
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(`
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","renderMount","scopes","mount","suffix","renderApiClient","mounts","options"],"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 `DoomApi` 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 facet mounts 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\nfunction renderMount(mount: ClientMount): 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: (input, init) => sealedTransport.fetch(input, init),',\n ' sessionAddress: sessionApiAddress,',\n '});',\n '',\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 const mounts = mountsOf(graph);\n if (mounts.length === 0) return undefined;\n\n const lines = [\n HEADER,\n \"import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';\",\n \"import { sealedTransport } from '@agimon-ai/po-web-security/browser';\",\n '',\n `import routes from '${routesSpecifier(options.entryDir ?? GENERATED_DIR)}';`,\n '',\n ...mounts.flatMap((mount) => renderMount(mount)),\n ];\n return `${lines.join('\\n').replace(/\\n+$/u, '')}\\n`;\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,GAAUe,EAAS,IAAIE,CAAK,CAAC,EACvE,MAAO,CACL,WACA,OAAQjB,EAAY,MAAMgB,CAAU,EACpC,WAAYf,EAAcG,EAAUU,EAAM,OAAS,CAAC,CACtD,CACF,CAAC,CACH,CAGA,SAASI,EAAgB,EAA0B,CACjD,IAAMC,EAAWtB,EAAAA,MAAM,SAASuB,EAAU,qBAAqB,EAC/D,OAAOD,EAAS,WAAW,GAAG,EAAIA,EAAW,KAAKA,GACpD,CAEA,SAASE,EAAY,EAA8B,CACjD,IAAMC,EAASC,EAAM,OAAO,IAAK,GAAU,IAAIN,EAAM,EAAE,CAAC,CAAC,KAAK,IAAI,EAC5DO,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,oEACA,uCACA,MACA,EACF,CACF,CAQA,SAAgBE,EAAgB,EAAuB,EAA4C,CACjG,IAAMC,EAAShB,EAASE,CAAK,EAC7B,GAAIc,EAAO,SAAW,EAWtB,MAAO,GAAG,CARR,4DACA,+EACA,wEACA,GACA,uBAAuBR,EAAgBS,EAAQ,UAAA,WAAyB,EAAE,IAC1E,GACA,GAAGD,EAAO,QAAS,GAAUL,EAAYE,CAAK,CAAC,CAEnC,CAAC,CAAC,KAAK;CAAI,CAAC,CAAC,QAAQ,QAAS,EAAE,EAAE,GAClD"}
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 `DoomApi` 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 facet mounts 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,EAAI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OAAO,IAAK,GAAU,IAAIR,EAAM,EAAE,CAAC,CAAC,KAAK,IAAI,EAC5DS,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,EAASnB,EAASE,CAAK,EAC7B,GAAIiB,EAAO,SAAW,EAUtB,MAAO,GAAG,CAPR,4DACA,GAAGF,EAAO,QACV,GACA,uBAAuBT,EAAgBY,EAAQ,UAAA,WAAyB,EAAE,IAC1E,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,EAAahB,EAAOkB,EAAST,CAAc,CACpD,CASA,SAAgBW,EAAsB,EAAuB,EAA4C,CACvG,OAAOJ,EAAahB,EAAOkB,EAASR,CAAa,CACnD"}
@@ -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}`}function s(e){let t=e.scopes.map(e=>`'${e}'`).join(`, `),n=e.identifier===`api`?``:` for the ${e.basePath} mount`;return[`/** Scopes the tree mounts '${e.basePath}' at${n}. */`,`export const ${e.identifier}Scopes = [${t}] as const;`,``,`export const ${e.identifier} = createApiClient(routes, {`,` scopes: ${e.identifier}Scopes,`,` basePath: '${e.basePath}',`,` transport: (input, init) => sealedTransport.fetch(input, init),`,` sessionAddress: sessionApiAddress,`,`});`,``]}function c(e,t){let n=a(e);if(n.length!==0)return`${[`// Generated by @agimon-ai/po-build. Do not edit by hand.`,`import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';`,`import { sealedTransport } from '@agimon-ai/po-web-security/browser';`,``,`import routes from '${o(t.entryDir??`generated`)}';`,``,...n.flatMap(e=>s(e))].join(`
2
- `).replace(/\n+$/u,``)}\n`}export{c as renderApiClient};
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(`
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","renderMount","scopes","mount","suffix","renderApiClient","mounts","options"],"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 `DoomApi` 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 facet mounts 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\nfunction renderMount(mount: ClientMount): 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: (input, init) => sealedTransport.fetch(input, init),',\n ' sessionAddress: sessionApiAddress,',\n '});',\n '',\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 const mounts = mountsOf(graph);\n if (mounts.length === 0) return undefined;\n\n const lines = [\n HEADER,\n \"import { createApiClient, sessionApiAddress } from '@agimon-ai/po-core/web';\",\n \"import { sealedTransport } from '@agimon-ai/po-web-security/browser';\",\n '',\n `import routes from '${routesSpecifier(options.entryDir ?? GENERATED_DIR)}';`,\n '',\n ...mounts.flatMap((mount) => renderMount(mount)),\n ];\n return `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CACtD,CACF,CAAC,CACH,CAGA,SAASI,EAAgB,EAA0B,CACjD,IAAMC,EAAWC,EAAM,SAASC,EAAU,qBAAqB,EAC/D,OAAOF,EAAS,WAAW,GAAG,EAAIA,EAAW,KAAKA,GACpD,CAEA,SAASG,EAAY,EAA8B,CACjD,IAAMC,EAASC,EAAM,OAAO,IAAK,GAAU,IAAIP,EAAM,EAAE,CAAC,CAAC,KAAK,IAAI,EAC5DQ,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,oEACA,uCACA,MACA,EACF,CACF,CAQA,SAAgBE,EAAgB,EAAuB,EAA4C,CACjG,IAAMC,EAASjB,EAASE,CAAK,EAC7B,GAAIe,EAAO,SAAW,EAWtB,MAAO,GAAG,CARR,4DACA,+EACA,wEACA,GACA,uBAAuBT,EAAgBU,EAAQ,UAAA,WAAyB,EAAE,IAC1E,GACA,GAAGD,EAAO,QAAS,GAAUL,EAAYE,CAAK,CAAC,CAEnC,CAAC,CAAC,KAAK;CAAI,CAAC,CAAC,QAAQ,QAAS,EAAE,EAAE,GAClD"}
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 `DoomApi` 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 facet mounts 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":"qHAsBA,MAGMA,EAAyC,CAAC,SAAU,YAAa,SAAS,EAUhF,SAASC,EAAc,EAAkB,EAA2B,CAClE,GAAI,CAACC,EAAU,MAAO,MACtB,IAAMC,EAAQC,EAAQC,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,KAAKH,CAAK,EAAIA,EAAQ,MAAMA,GACnD,CAUA,SAASK,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,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,uBAAuBV,EAAgBa,EAAQ,UAAA,WAAyB,EAAE,IAC1E,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"}
@@ -1,2 +1,2 @@
1
- require("../../constants/layout.cjs");const e=require("../../constants/contributions.cjs"),t={global:0,workspace:1,session:2};function n(e){return e===`web`||e===`native`}function r(e,t){return n(t)?e.side===`frontend`:e.side===`backend`}function i(e,t){return t===`mcp`||t===`native`?e.platform===t:e.platform===void 0||e.platform===t}const a={server:{backend:e.SERVER_FIELDS,frontend:{}},web:{backend:{},frontend:e.WEB_FIELDS},native:{backend:{},frontend:e.NATIVE_FIELDS},mcp:{backend:e.MCP_FIELDS,frontend:{}}};function o(e){let t=e.gates.map(e=>`${e.kind}:${e.id}`).join(`/`),n=e.route.map(e=>`literal`in e?e.literal:`[${e.param.name}]`).join(`/`);return[e.side,e.scope,t,e.surface??``,n,e.name,e.target??``].join(`|`)}function s(e,t,n){return n===void 0?t:e[n]??t}function c(t,r){let i=t.surface;if(i===void 0)return;let o=a[r][t.side][i];if(o!==void 0&&o!==``&&!(n(r)&&i===`lifecycle`&&t.name!==`start`))return n(r)&&i===`setting`?s(e.SETTING_FIELDS,o,t.target):r===`web`&&i===`action`?s(e.ACTION_FIELDS,o,t.target):o}function l(e,n){let a=[],s=[],l=[],u=/* @__PURE__ */ new Map;for(let t of e.entries){if(!r(t,n)||!i(t,n))continue;if(t.role===`escape-hatch`){s.push(t);continue}if(t.role===`root`){if(t.side===`frontend`){a.push({path:t.file,message:`a scope root is a backend file; the cockpit has no mount context`});continue}l.push(t);continue}let e=o(t),c=u.get(e);if(c===void 0){u.set(e,t);continue}if(c.platform===t.platform){a.push({path:t.file,message:`duplicates ${c.file} for ${n}; the first one wins`});continue}t.platform!==void 0&&u.set(e,t)}let d=[];for(let e of u.values()){let t=c(e,n);t!==void 0&&d.push({entry:e,field:t})}return{target:n,contributions:d,escapeHatches:s,roots:l.sort((e,n)=>t[e.scope]-t[n.scope]),notices:a}}exports.isFrontendTarget=n,exports.resolveTarget=l;
1
+ require("../../constants/layout.cjs");const e=require("../../constants/contributions.cjs"),t={global:0,workspace:1,session:2};function n(e){return e===`web`||e===`native`}function r(e,t){return n(t)?e.side===`frontend`:e.side===`backend`}function i(e,t){return t===`mcp`||t===`native`?e.platform===t:e.platform===void 0||e.platform===t}const a={server:{backend:e.SERVER_FIELDS,frontend:{}},web:{backend:{},frontend:e.WEB_FIELDS},native:{backend:{},frontend:e.NATIVE_FIELDS},mcp:{backend:e.MCP_FIELDS,frontend:{}}};function o(e){let t=e.gates.map(e=>`${e.kind}:${e.id}`).join(`/`),n=e.route.map(e=>`literal`in e?e.literal:`[${e.param.name}]`).join(`/`);return[e.side,e.scope,t,e.surface??``,n,e.name,e.target??``].join(`|`)}function s(e,t,n){return n===void 0?t:e[n]??t}function c(t,r){let i=t.surface;if(i===void 0)return;let o=a[r][t.side][i];if(o!==void 0&&o!==``&&!(n(r)&&i===`lifecycle`&&t.name!==`start`))return n(r)&&i===`setting`?s(e.SETTING_FIELDS,o,t.target):r===`web`&&i===`action`?s(e.ACTION_FIELDS,o,t.target):r===`native`&&i===`action`?t.target===void 0?void 0:e.NATIVE_ACTION_FIELDS[t.target]:o}function l(n,a){let s=[],l=[],u=[],d=/* @__PURE__ */ new Map;for(let e of n.entries){if(!r(e,a)||!i(e,a))continue;if(e.role===`escape-hatch`){l.push(e);continue}if(e.role===`root`){if(e.side===`frontend`){s.push({path:e.file,message:`a scope root is a backend file; the cockpit has no mount context`});continue}u.push(e);continue}let t=o(e),n=d.get(t);n===void 0?d.set(t,e):n.platform===e.platform?s.push({path:e.file,message:`duplicates ${n.file} for ${a}; the first one wins`}):e.platform!==void 0&&d.set(t,e)}let f=[];for(let t of d.values()){let n=c(t,a);n===void 0?a===`native`&&t.surface!==void 0&&e.NATIVE_FIELDS[t.surface]!==``&&s.push({path:t.file,message:`${t.surface}/${t.name} is not supported by the native host`}):f.push({entry:t,field:n})}return{target:a,contributions:f,escapeHatches:l,roots:u.sort((e,n)=>t[e.scope]-t[n.scope]),notices:s}}exports.isFrontendTarget=n,exports.resolveTarget=l;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["SERVER_FIELDS","WEB_FIELDS","NATIVE_FIELDS","MCP_FIELDS","SETTING_FIELDS","ACTION_FIELDS","require_contributions","SCOPE_DEPTH","isFrontendTarget","target","drawsFrom","entry","servesPlatform","FIELDS_OF","logicalKey","gates","gate","route","segment","variantField","entryTarget","fallback","table","fieldFor","surface","declared","resolveTarget","notices","escapeHatches","roots","winners","graph","key","held","contributions","field","left","right"],"sources":["../../../src/services/resolveTarget/index.ts"],"sourcesContent":["import {\n ACTION_FIELDS,\n MCP_FIELDS,\n NATIVE_FIELDS,\n NOT_A_CONTRIBUTION,\n SERVER_FIELDS,\n SETTING_FIELDS,\n WEB_FIELDS,\n} from '../../constants/contributions';\nimport { NATIVE_PLATFORM } from '../../constants/layout';\nimport type { ExtensionEntry, ExtensionGraph, ExtensionNotice, ExtensionSide } from '../../types/extensionGraph';\nimport type { BuildTarget, FrontendTarget, ResolvedContribution, TargetResolution } from './type';\n\n/** Nesting order, so roots compose outermost first. */\nconst SCOPE_DEPTH: Readonly<Record<string, number>> = { global: 0, workspace: 1, session: 2 };\n\n/** Whether a host draws presentation: the cockpit and the native app do, the server and MCP hosts run logic. */\nexport function isFrontendTarget(target: BuildTarget): target is FrontendTarget {\n return target === 'web' || target === NATIVE_PLATFORM;\n}\n\n/** Which side a host reads. */\nfunction drawsFrom(entry: ExtensionEntry, target: BuildTarget): boolean {\n return isFrontendTarget(target) ? entry.side === 'frontend' : entry.side === 'backend';\n}\n\n/**\n * Whether a file's platform suffix lets it reach a host.\n *\n * MCP and native take only files that name them: an unsuffixed backend file may\n * touch the whole server, and an unsuffixed frontend file may touch the DOM.\n * The server and the cockpit still accept an unsuffixed sibling as a fallback.\n */\nfunction servesPlatform(entry: ExtensionEntry, target: BuildTarget): boolean {\n if (target === 'mcp' || target === NATIVE_PLATFORM) return entry.platform === target;\n return entry.platform === undefined || entry.platform === target;\n}\n\nconst FIELDS_OF: Readonly<Record<BuildTarget, Readonly<Record<ExtensionSide, Readonly<Record<string, string>>>>>> = {\n server: { backend: SERVER_FIELDS, frontend: {} },\n web: { backend: {}, frontend: WEB_FIELDS },\n native: { backend: {}, frontend: NATIVE_FIELDS },\n mcp: { backend: MCP_FIELDS, frontend: {} },\n};\n\n/** Everything but the platform: two files sharing this are the same contribution. */\nfunction logicalKey(entry: ExtensionEntry): string {\n const gates = entry.gates.map((gate) => `${gate.kind}:${gate.id}`).join('/');\n const route = entry.route\n .map((segment) => ('literal' in segment ? segment.literal : `[${segment.param.name}]`))\n .join('/');\n // The side is part of it, so a tool's logic and its cockpit renderer never\n // look like one contribution overriding the other.\n return [entry.side, entry.scope, gates, entry.surface ?? '', route, entry.name, entry.target ?? ''].join('|');\n}\n\n/** Resolves the field for a surface whose filename target picks between two shapes. */\nfunction variantField(\n table: Readonly<Record<string, string>>,\n fallback: string,\n entryTarget: string | undefined,\n): string {\n if (entryTarget === undefined) return fallback;\n return table[entryTarget] ?? fallback;\n}\n\nfunction fieldFor(entry: ExtensionEntry, target: BuildTarget): string | undefined {\n const surface = entry.surface;\n if (surface === undefined) return undefined;\n\n const declared = FIELDS_OF[target][entry.side][surface];\n if (declared === undefined || declared === NOT_A_CONTRIBUTION) return undefined;\n\n if (isFrontendTarget(target) && surface === 'lifecycle' && entry.name !== 'start') return undefined;\n if (isFrontendTarget(target) && surface === 'setting') return variantField(SETTING_FIELDS, declared, entry.target);\n if (target === 'web' && surface === 'action') return variantField(ACTION_FIELDS, declared, entry.target);\n return declared;\n}\n\n/**\n * Picks the winning file per logical contribution for one host.\n *\n * Metro and Expo semantics: a file naming this platform replaces a sibling\n * that names none, and a file naming none serves the server or the cockpit\n * when it has no more specific sibling. The scan reports the unnamed one, so\n * this is a fallback rather than a supported way to author. MCP and native\n * have no fallback at all: they read only the files that name them. Two files\n * naming the same platform for the same contribution is an authoring mistake,\n * so the first wins and the second becomes a notice rather than silently\n * disappearing.\n */\nexport function resolveTarget(graph: ExtensionGraph, target: BuildTarget): TargetResolution {\n const notices: ExtensionNotice[] = [];\n const escapeHatches: ExtensionEntry[] = [];\n const roots: ExtensionEntry[] = [];\n const winners = new Map<string, ExtensionEntry>();\n\n for (const entry of graph.entries) {\n if (!drawsFrom(entry, target)) continue;\n if (!servesPlatform(entry, target)) continue;\n if (entry.role === 'escape-hatch') {\n escapeHatches.push(entry);\n continue;\n }\n\n if (entry.role === 'root') {\n // Backend only. A root is constructed from a mount context, and the\n // cockpit has none: it builds its plugin definition as data and starts\n // it separately, so there is nothing for a frontend root to receive.\n if (entry.side === 'frontend') {\n notices.push({ path: entry.file, message: 'a scope root is a backend file; the cockpit has no mount context' });\n continue;\n }\n roots.push(entry);\n continue;\n }\n\n const key = logicalKey(entry);\n const held = winners.get(key);\n if (held === undefined) {\n winners.set(key, entry);\n continue;\n }\n if (held.platform === entry.platform) {\n notices.push({ path: entry.file, message: `duplicates ${held.file} for ${target}; the first one wins` });\n continue;\n }\n // A platform file always beats the unsuffixed sibling it overrides.\n if (entry.platform !== undefined) winners.set(key, entry);\n }\n\n const contributions: ResolvedContribution[] = [];\n for (const entry of winners.values()) {\n const field = fieldFor(entry, target);\n if (field === undefined) continue;\n contributions.push({ entry, field });\n }\n\n return {\n target,\n contributions,\n escapeHatches,\n roots: roots.sort((left, right) => SCOPE_DEPTH[left.scope] - SCOPE_DEPTH[right.scope]),\n notices,\n };\n}\n"],"mappings":"2FAcMO,EAAgD,CAAE,OAAQ,EAAG,UAAW,EAAG,QAAS,CAAE,EAG5F,SAAgBC,EAAiB,EAA+C,CAC9E,OAAOC,IAAW,OAASA,IAAA,QAC7B,CAGA,SAASC,EAAU,EAAuB,EAA8B,CACtE,OAAOF,EAAiBC,CAAM,EAAIE,EAAM,OAAS,WAAaA,EAAM,OAAS,SAC/E,CASA,SAASC,EAAe,EAAuB,EAA8B,CAE3E,OADIH,IAAW,OAASA,IAAA,SAAmCE,EAAM,WAAaF,EACvEE,EAAM,WAAa,IAAA,IAAaA,EAAM,WAAaF,CAC5D,CAEA,MAAMI,EAA8G,CAClH,OAAQ,CAAE,QAASb,EAAAA,cAAe,SAAU,CAAC,CAAE,EAC/C,IAAK,CAAE,QAAS,CAAC,EAAG,SAAUC,EAAAA,UAAW,EACzC,OAAQ,CAAE,QAAS,CAAC,EAAG,SAAUC,EAAAA,aAAc,EAC/C,IAAK,CAAE,QAASC,EAAAA,WAAY,SAAU,CAAC,CAAE,CAC3C,EAGA,SAASW,EAAW,EAA+B,CACjD,IAAMC,EAAQJ,EAAM,MAAM,IAAK,GAAS,GAAGK,EAAK,KAAK,GAAGA,EAAK,IAAI,CAAC,CAAC,KAAK,GAAG,EACrEC,EAAQN,EAAM,MACjB,IAAK,GAAa,YAAaO,EAAUA,EAAQ,QAAU,IAAIA,EAAQ,MAAM,KAAK,EAAG,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tBsB,EAAOH,EAAQ,IAAIE,CAAG,EAC5B,GAAIC,IAAS,IAAA,GAAW,CACtBH,EAAQ,IAAIE,EAAKrB,CAAK,EACtB,QACF,CACA,GAAIsB,EAAK,WAAatB,EAAM,SAAU,CACpCgB,EAAQ,KAAK,CAAE,KAAMhB,EAAM,KAAM,QAAS,cAAcsB,EAAK,KAAK,OAAOxB,EAAO,qBAAsB,CAAC,EACvG,QACF,CAEIE,EAAM,WAAa,IAAA,IAAWmB,EAAQ,IAAIE,EAAKrB,CAAK,CAC1D,CAEA,IAAMuB,EAAwC,CAAC,EAC/C,IAAK,IAAMvB,KAASmB,EAAQ,OAAO,EAAG,CACpC,IAAMK,EAAQZ,EAASZ,EAAOF,CAAM,EAChC0B,IAAU,IAAA,IACdD,EAAc,KAAK,CAAE,QAAO,OAAM,CAAC,CACrC,CAEA,MAAO,CACL,SACA,gBACA,gBACA,MAAOL,EAAM,MAAM,EAAM,IAAUtB,EAAY6B,EAAK,OAAS7B,EAAY8B,EAAM,MAAM,EACrF,SACF,CACF"}
1
+ {"version":3,"file":"index.cjs","names":["SERVER_FIELDS","WEB_FIELDS","NATIVE_FIELDS","MCP_FIELDS","SETTING_FIELDS","ACTION_FIELDS","NATIVE_ACTION_FIELDS","require_contributions","SCOPE_DEPTH","isFrontendTarget","target","drawsFrom","entry","servesPlatform","FIELDS_OF","logicalKey","gates","gate","route","segment","variantField","entryTarget","fallback","table","fieldFor","surface","declared","resolveTarget","notices","escapeHatches","roots","winners","graph","key","held","contributions","field","left","right"],"sources":["../../../src/services/resolveTarget/index.ts"],"sourcesContent":["import {\n ACTION_FIELDS,\n MCP_FIELDS,\n NATIVE_ACTION_FIELDS,\n NATIVE_FIELDS,\n NOT_A_CONTRIBUTION,\n SERVER_FIELDS,\n SETTING_FIELDS,\n WEB_FIELDS,\n} from '../../constants/contributions';\nimport { NATIVE_PLATFORM } from '../../constants/layout';\nimport type { ExtensionEntry, ExtensionGraph, ExtensionNotice, ExtensionSide } from '../../types/extensionGraph';\nimport type { BuildTarget, FrontendTarget, ResolvedContribution, TargetResolution } from './type';\n\n/** Nesting order, so roots compose outermost first. */\nconst SCOPE_DEPTH: Readonly<Record<string, number>> = { global: 0, workspace: 1, session: 2 };\n\n/** Whether a host draws presentation: the cockpit and the native app do, the server and MCP hosts run logic. */\nexport function isFrontendTarget(target: BuildTarget): target is FrontendTarget {\n return target === 'web' || target === NATIVE_PLATFORM;\n}\n\n/** Which side a host reads. */\nfunction drawsFrom(entry: ExtensionEntry, target: BuildTarget): boolean {\n return isFrontendTarget(target) ? entry.side === 'frontend' : entry.side === 'backend';\n}\n\n/**\n * Whether a file's platform suffix lets it reach a host.\n *\n * MCP and native take only files that name them: an unsuffixed backend file may\n * touch the whole server, and an unsuffixed frontend file may touch the DOM.\n * The server and the cockpit still accept an unsuffixed sibling as a fallback.\n */\nfunction servesPlatform(entry: ExtensionEntry, target: BuildTarget): boolean {\n if (target === 'mcp' || target === NATIVE_PLATFORM) return entry.platform === target;\n return entry.platform === undefined || entry.platform === target;\n}\n\nconst FIELDS_OF: Readonly<Record<BuildTarget, Readonly<Record<ExtensionSide, Readonly<Record<string, string>>>>>> = {\n server: { backend: SERVER_FIELDS, frontend: {} },\n web: { backend: {}, frontend: WEB_FIELDS },\n native: { backend: {}, frontend: NATIVE_FIELDS },\n mcp: { backend: MCP_FIELDS, frontend: {} },\n};\n\n/** Everything but the platform: two files sharing this are the same contribution. */\nfunction logicalKey(entry: ExtensionEntry): string {\n const gates = entry.gates.map((gate) => `${gate.kind}:${gate.id}`).join('/');\n const route = entry.route\n .map((segment) => ('literal' in segment ? segment.literal : `[${segment.param.name}]`))\n .join('/');\n // The side is part of it, so a tool's logic and its cockpit renderer never\n // look like one contribution overriding the other.\n return [entry.side, entry.scope, gates, entry.surface ?? '', route, entry.name, entry.target ?? ''].join('|');\n}\n\n/** Resolves the field for a surface whose filename target picks between two shapes. */\nfunction variantField(\n table: Readonly<Record<string, string>>,\n fallback: string,\n entryTarget: string | undefined,\n): string {\n if (entryTarget === undefined) return fallback;\n return table[entryTarget] ?? fallback;\n}\n\nfunction fieldFor(entry: ExtensionEntry, target: BuildTarget): string | undefined {\n const surface = entry.surface;\n if (surface === undefined) return undefined;\n\n const declared = FIELDS_OF[target][entry.side][surface];\n if (declared === undefined || declared === NOT_A_CONTRIBUTION) return undefined;\n\n if (isFrontendTarget(target) && surface === 'lifecycle' && entry.name !== 'start') return undefined;\n if (isFrontendTarget(target) && surface === 'setting') return variantField(SETTING_FIELDS, declared, entry.target);\n if (target === 'web' && surface === 'action') return variantField(ACTION_FIELDS, declared, entry.target);\n // No fallback shape: an unnamed or context action is reported, never routed.\n if (target === NATIVE_PLATFORM && surface === 'action') {\n return entry.target === undefined ? undefined : NATIVE_ACTION_FIELDS[entry.target];\n }\n return declared;\n}\n\n/**\n * Picks the winning file per logical contribution for one host.\n *\n * Metro and Expo semantics: a file naming this platform replaces a sibling\n * that names none, and a file naming none serves the server or the cockpit\n * when it has no more specific sibling. The scan reports the unnamed one, so\n * this is a fallback rather than a supported way to author. MCP and native\n * have no fallback at all: they read only the files that name them. Two files\n * naming the same platform for the same contribution is an authoring mistake,\n * so the first wins and the second becomes a notice rather than silently\n * disappearing.\n */\nexport function resolveTarget(graph: ExtensionGraph, target: BuildTarget): TargetResolution {\n const notices: ExtensionNotice[] = [];\n const escapeHatches: ExtensionEntry[] = [];\n const roots: ExtensionEntry[] = [];\n const winners = new Map<string, ExtensionEntry>();\n\n for (const entry of graph.entries) {\n if (!drawsFrom(entry, target)) continue;\n if (!servesPlatform(entry, target)) continue;\n if (entry.role === 'escape-hatch') {\n escapeHatches.push(entry);\n continue;\n }\n\n if (entry.role === 'root') {\n // Backend only. A root is constructed from a mount context, and the\n // cockpit has none: it builds its plugin definition as data and starts\n // it separately, so there is nothing for a frontend root to receive.\n if (entry.side === 'frontend') {\n notices.push({ path: entry.file, message: 'a scope root is a backend file; the cockpit has no mount context' });\n continue;\n }\n roots.push(entry);\n continue;\n }\n\n const key = logicalKey(entry);\n const held = winners.get(key);\n if (held === undefined) {\n winners.set(key, entry);\n continue;\n }\n if (held.platform === entry.platform) {\n notices.push({ path: entry.file, message: `duplicates ${held.file} for ${target}; the first one wins` });\n continue;\n }\n // A platform file always beats the unsuffixed sibling it overrides.\n if (entry.platform !== undefined) winners.set(key, entry);\n }\n\n const contributions: ResolvedContribution[] = [];\n for (const entry of winners.values()) {\n const field = fieldFor(entry, target);\n if (field === undefined) {\n if (\n target === NATIVE_PLATFORM &&\n entry.surface !== undefined &&\n NATIVE_FIELDS[entry.surface] !== NOT_A_CONTRIBUTION\n ) {\n notices.push({\n path: entry.file,\n message: `${entry.surface}/${entry.name} is not supported by the native host`,\n });\n }\n continue;\n }\n contributions.push({ entry, field });\n }\n\n return {\n target,\n contributions,\n escapeHatches,\n roots: roots.sort((left, right) => SCOPE_DEPTH[left.scope] - SCOPE_DEPTH[right.scope]),\n notices,\n };\n}\n"],"mappings":"2FAeMQ,EAAgD,CAAE,OAAQ,EAAG,UAAW,EAAG,QAAS,CAAE,EAG5F,SAAgBC,EAAiB,EAA+C,CAC9E,OAAOC,IAAW,OAASA,IAAA,QAC7B,CAGA,SAASC,EAAU,EAAuB,EAA8B,CACtE,OAAOF,EAAiBC,CAAM,EAAIE,EAAM,OAAS,WAAaA,EAAM,OAAS,SAC/E,CASA,SAASC,EAAe,EAAuB,EAA8B,CAE3E,OADIH,IAAW,OAASA,IAAA,SAAmCE,EAAM,WAAaF,EACvEE,EAAM,WAAa,IAAA,IAAaA,EAAM,WAAaF,CAC5D,CAEA,MAAMI,EAA8G,CAClH,OAAQ,CAAE,QAASd,EAAAA,cAAe,SAAU,CAAC,CAAE,EAC/C,IAAK,CAAE,QAAS,CAAC,EAAG,SAAUC,EAAAA,UAAW,EACzC,OAAQ,CAAE,QAAS,CAAC,EAAG,SAAUC,EAAAA,aAAc,EAC/C,IAAK,CAAE,QAASC,EAAAA,WAAY,SAAU,CAAC,CAAE,CAC3C,EAGA,SAASY,EA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QAAQ,cAAc"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/resolveTarget/index.ts"],"mappings":";;;;;;;;;;;;;;;wBAgGgB,cAAc,OAAO,gBAAgB,QAAQ,cAAc"}
@@ -1,2 +1,2 @@
1
- import"../../constants/layout.mjs";import{ACTION_FIELDS as e,MCP_FIELDS as t,NATIVE_FIELDS as n,SERVER_FIELDS as r,SETTING_FIELDS as i,WEB_FIELDS as a}from"../../constants/contributions.mjs";const o={global:0,workspace:1,session:2};function s(e){return e===`web`||e===`native`}function c(e,t){return s(t)?e.side===`frontend`:e.side===`backend`}function l(e,t){return t===`mcp`||t===`native`?e.platform===t:e.platform===void 0||e.platform===t}const u={server:{backend:r,frontend:{}},web:{backend:{},frontend:a},native:{backend:{},frontend:n},mcp:{backend:t,frontend:{}}};function d(e){let t=e.gates.map(e=>`${e.kind}:${e.id}`).join(`/`),n=e.route.map(e=>`literal`in e?e.literal:`[${e.param.name}]`).join(`/`);return[e.side,e.scope,t,e.surface??``,n,e.name,e.target??``].join(`|`)}function f(e,t,n){return n===void 0?t:e[n]??t}function p(t,n){let r=t.surface;if(r===void 0)return;let a=u[n][t.side][r];if(a!==void 0&&a!==``&&!(s(n)&&r===`lifecycle`&&t.name!==`start`))return s(n)&&r===`setting`?f(i,a,t.target):n===`web`&&r===`action`?f(e,a,t.target):a}function m(e,t){let n=[],r=[],i=[],a=/* @__PURE__ */ new Map;for(let o of e.entries){if(!c(o,t)||!l(o,t))continue;if(o.role===`escape-hatch`){r.push(o);continue}if(o.role===`root`){if(o.side===`frontend`){n.push({path:o.file,message:`a scope root is a backend file; the cockpit has no mount context`});continue}i.push(o);continue}let e=d(o),s=a.get(e);if(s===void 0){a.set(e,o);continue}if(s.platform===o.platform){n.push({path:o.file,message:`duplicates ${s.file} for ${t}; the first one wins`});continue}o.platform!==void 0&&a.set(e,o)}let s=[];for(let e of a.values()){let n=p(e,t);n!==void 0&&s.push({entry:e,field:n})}return{target:t,contributions:s,escapeHatches:r,roots:i.sort((e,t)=>o[e.scope]-o[t.scope]),notices:n}}export{s as isFrontendTarget,m as resolveTarget};
1
+ import"../../constants/layout.mjs";import{ACTION_FIELDS as e,MCP_FIELDS as t,NATIVE_ACTION_FIELDS as n,NATIVE_FIELDS as r,SERVER_FIELDS as i,SETTING_FIELDS as a,WEB_FIELDS as o}from"../../constants/contributions.mjs";const s={global:0,workspace:1,session:2};function c(e){return e===`web`||e===`native`}function l(e,t){return c(t)?e.side===`frontend`:e.side===`backend`}function u(e,t){return t===`mcp`||t===`native`?e.platform===t:e.platform===void 0||e.platform===t}const d={server:{backend:i,frontend:{}},web:{backend:{},frontend:o},native:{backend:{},frontend:r},mcp:{backend:t,frontend:{}}};function f(e){let t=e.gates.map(e=>`${e.kind}:${e.id}`).join(`/`),n=e.route.map(e=>`literal`in e?e.literal:`[${e.param.name}]`).join(`/`);return[e.side,e.scope,t,e.surface??``,n,e.name,e.target??``].join(`|`)}function p(e,t,n){return n===void 0?t:e[n]??t}function m(t,r){let i=t.surface;if(i===void 0)return;let o=d[r][t.side][i];if(o!==void 0&&o!==``&&!(c(r)&&i===`lifecycle`&&t.name!==`start`))return c(r)&&i===`setting`?p(a,o,t.target):r===`web`&&i===`action`?p(e,o,t.target):r===`native`&&i===`action`?t.target===void 0?void 0:n[t.target]:o}function h(e,t){let n=[],i=[],a=[],o=/* @__PURE__ */ new Map;for(let r of e.entries){if(!l(r,t)||!u(r,t))continue;if(r.role===`escape-hatch`){i.push(r);continue}if(r.role===`root`){if(r.side===`frontend`){n.push({path:r.file,message:`a scope root is a backend file; the cockpit has no mount context`});continue}a.push(r);continue}let e=f(r),s=o.get(e);s===void 0?o.set(e,r):s.platform===r.platform?n.push({path:r.file,message:`duplicates ${s.file} for ${t}; the first one wins`}):r.platform!==void 0&&o.set(e,r)}let c=[];for(let e of o.values()){let i=m(e,t);i===void 0?t===`native`&&e.surface!==void 0&&r[e.surface]!==``&&n.push({path:e.file,message:`${e.surface}/${e.name} is not supported by the native host`}):c.push({entry:e,field:i})}return{target:t,contributions:c,escapeHatches:i,roots:a.sort((e,t)=>s[e.scope]-s[t.scope]),notices:n}}export{c as isFrontendTarget,h as resolveTarget};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["SCOPE_DEPTH","isFrontendTarget","target","drawsFrom","entry","servesPlatform","FIELDS_OF","SERVER_FIELDS","WEB_FIELDS","NATIVE_FIELDS","MCP_FIELDS","logicalKey","gates","gate","route","segment","variantField","entryTarget","fallback","table","fieldFor","surface","declared","SETTING_FIELDS","ACTION_FIELDS","resolveTarget","notices","escapeHatches","roots","winners","graph","key","held","contributions","field","left","right"],"sources":["../../../src/services/resolveTarget/index.ts"],"sourcesContent":["import {\n ACTION_FIELDS,\n MCP_FIELDS,\n NATIVE_FIELDS,\n NOT_A_CONTRIBUTION,\n SERVER_FIELDS,\n SETTING_FIELDS,\n WEB_FIELDS,\n} from '../../constants/contributions';\nimport { NATIVE_PLATFORM } from '../../constants/layout';\nimport type { ExtensionEntry, ExtensionGraph, ExtensionNotice, ExtensionSide } from '../../types/extensionGraph';\nimport type { BuildTarget, FrontendTarget, ResolvedContribution, TargetResolution } from './type';\n\n/** Nesting order, so roots compose outermost first. */\nconst SCOPE_DEPTH: Readonly<Record<string, number>> = { global: 0, workspace: 1, session: 2 };\n\n/** Whether a host draws presentation: the cockpit and the native app do, the server and MCP hosts run logic. */\nexport function isFrontendTarget(target: BuildTarget): target is FrontendTarget {\n return target === 'web' || target === NATIVE_PLATFORM;\n}\n\n/** Which side a host reads. */\nfunction drawsFrom(entry: ExtensionEntry, target: BuildTarget): boolean {\n return isFrontendTarget(target) ? entry.side === 'frontend' : entry.side === 'backend';\n}\n\n/**\n * Whether a file's platform suffix lets it reach a host.\n *\n * MCP and native take only files that name them: an unsuffixed backend file may\n * touch the whole server, and an unsuffixed frontend file may touch the DOM.\n * The server and the cockpit still accept an unsuffixed sibling as a fallback.\n */\nfunction servesPlatform(entry: ExtensionEntry, target: BuildTarget): boolean {\n if (target === 'mcp' || target === NATIVE_PLATFORM) return entry.platform === target;\n return entry.platform === undefined || entry.platform === target;\n}\n\nconst FIELDS_OF: Readonly<Record<BuildTarget, Readonly<Record<ExtensionSide, Readonly<Record<string, string>>>>>> = {\n server: { backend: SERVER_FIELDS, frontend: {} },\n web: { backend: {}, frontend: WEB_FIELDS },\n native: { backend: {}, frontend: NATIVE_FIELDS },\n mcp: { backend: MCP_FIELDS, frontend: {} },\n};\n\n/** Everything but the platform: two files sharing this are the same contribution. */\nfunction logicalKey(entry: ExtensionEntry): string {\n const gates = entry.gates.map((gate) => `${gate.kind}:${gate.id}`).join('/');\n const route = entry.route\n .map((segment) => ('literal' in segment ? segment.literal : `[${segment.param.name}]`))\n .join('/');\n // The side is part of it, so a tool's logic and its cockpit renderer never\n // look like one contribution overriding the other.\n return [entry.side, entry.scope, gates, entry.surface ?? '', route, entry.name, entry.target ?? ''].join('|');\n}\n\n/** Resolves the field for a surface whose filename target picks between two shapes. */\nfunction variantField(\n table: Readonly<Record<string, string>>,\n fallback: string,\n entryTarget: string | undefined,\n): string {\n if (entryTarget === undefined) return fallback;\n return table[entryTarget] ?? fallback;\n}\n\nfunction fieldFor(entry: ExtensionEntry, target: BuildTarget): string | undefined {\n const surface = entry.surface;\n if (surface === undefined) return undefined;\n\n const declared = FIELDS_OF[target][entry.side][surface];\n if (declared === undefined || declared === NOT_A_CONTRIBUTION) return undefined;\n\n if (isFrontendTarget(target) && surface === 'lifecycle' && entry.name !== 'start') return undefined;\n if (isFrontendTarget(target) && surface === 'setting') return variantField(SETTING_FIELDS, declared, entry.target);\n if (target === 'web' && surface === 'action') return variantField(ACTION_FIELDS, declared, entry.target);\n return declared;\n}\n\n/**\n * Picks the winning file per logical contribution for one host.\n *\n * Metro and Expo semantics: a file naming this platform replaces a sibling\n * that names none, and a file naming none serves the server or the cockpit\n * when it has no more specific sibling. The scan reports the unnamed one, so\n * this is a fallback rather than a supported way to author. MCP and native\n * have no fallback at all: they read only the files that name them. Two files\n * naming the same platform for the same contribution is an authoring mistake,\n * so the first wins and the second becomes a notice rather than silently\n * disappearing.\n */\nexport function resolveTarget(graph: ExtensionGraph, target: BuildTarget): TargetResolution {\n const notices: ExtensionNotice[] = [];\n const escapeHatches: ExtensionEntry[] = [];\n const roots: ExtensionEntry[] = [];\n const winners = new Map<string, ExtensionEntry>();\n\n for (const entry of graph.entries) {\n if (!drawsFrom(entry, target)) continue;\n if (!servesPlatform(entry, target)) continue;\n if (entry.role === 'escape-hatch') {\n escapeHatches.push(entry);\n continue;\n }\n\n if (entry.role === 'root') {\n // Backend only. A root is constructed from a mount context, and the\n // cockpit has none: it builds its plugin definition as data and starts\n // it separately, so there is nothing for a frontend root to receive.\n if (entry.side === 'frontend') {\n notices.push({ path: entry.file, message: 'a scope root is a backend file; the cockpit has no mount context' });\n continue;\n }\n roots.push(entry);\n continue;\n }\n\n const key = logicalKey(entry);\n const held = winners.get(key);\n if (held === undefined) {\n winners.set(key, entry);\n continue;\n }\n if (held.platform === entry.platform) {\n notices.push({ path: entry.file, message: `duplicates ${held.file} for ${target}; the first one wins` });\n continue;\n }\n // A platform file always beats the unsuffixed sibling it overrides.\n if (entry.platform !== undefined) winners.set(key, entry);\n }\n\n const contributions: ResolvedContribution[] = [];\n for (const entry of winners.values()) {\n const field = fieldFor(entry, target);\n if (field === undefined) continue;\n contributions.push({ entry, field });\n }\n\n return {\n target,\n contributions,\n escapeHatches,\n roots: roots.sort((left, right) => SCOPE_DEPTH[left.scope] - SCOPE_DEPTH[right.scope]),\n notices,\n };\n}\n"],"mappings":"+LAcA,MAAMA,EAAgD,CAAE,OAAQ,EAAG,UAAW,EAAG,QAAS,CAAE,EAG5F,SAAgBC,EAAiB,EAA+C,CAC9E,OAAOC,IAAW,OAASA,IAAA,QAC7B,CAGA,SAASC,EAAU,EAAuB,EAA8B,CACtE,OAAOF,EAAiBC,CAAM,EAAIE,EAAM,OAAS,WAAaA,EAA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AM,MAAM,EACrF,SACF,CACF"}
1
+ {"version":3,"file":"index.mjs","names":["SCOPE_DEPTH","isFrontendTarget","target","drawsFrom","entry","servesPlatform","FIELDS_OF","SERVER_FIELDS","WEB_FIELDS","NATIVE_FIELDS","MCP_FIELDS","logicalKey","gates","gate","route","segment","variantField","entryTarget","fallback","table","fieldFor","surface","declared","SETTING_FIELDS","ACTION_FIELDS","NATIVE_ACTION_FIELDS","resolveTarget","notices","escapeHatches","roots","winners","graph","key","held","contributions","field","left","right"],"sources":["../../../src/services/resolveTarget/index.ts"],"sourcesContent":["import {\n ACTION_FIELDS,\n MCP_FIELDS,\n NATIVE_ACTION_FIELDS,\n NATIVE_FIELDS,\n NOT_A_CONTRIBUTION,\n SERVER_FIELDS,\n SETTING_FIELDS,\n WEB_FIELDS,\n} from '../../constants/contributions';\nimport { NATIVE_PLATFORM } from '../../constants/layout';\nimport type { ExtensionEntry, ExtensionGraph, ExtensionNotice, ExtensionSide } from '../../types/extensionGraph';\nimport type { BuildTarget, FrontendTarget, ResolvedContribution, TargetResolution } from './type';\n\n/** Nesting order, so roots compose outermost first. */\nconst SCOPE_DEPTH: Readonly<Record<string, number>> = { global: 0, workspace: 1, session: 2 };\n\n/** Whether a host draws presentation: the cockpit and the native app do, the server and MCP hosts run logic. */\nexport function isFrontendTarget(target: BuildTarget): target is FrontendTarget {\n return target === 'web' || target === NATIVE_PLATFORM;\n}\n\n/** Which side a host reads. */\nfunction drawsFrom(entry: ExtensionEntry, target: BuildTarget): boolean {\n return isFrontendTarget(target) ? entry.side === 'frontend' : entry.side === 'backend';\n}\n\n/**\n * Whether a file's platform suffix lets it reach a host.\n *\n * MCP and native take only files that name them: an unsuffixed backend file may\n * touch the whole server, and an unsuffixed frontend file may touch the DOM.\n * The server and the cockpit still accept an unsuffixed sibling as a fallback.\n */\nfunction servesPlatform(entry: ExtensionEntry, target: BuildTarget): boolean {\n if (target === 'mcp' || target === NATIVE_PLATFORM) return entry.platform === target;\n return entry.platform === undefined || entry.platform === target;\n}\n\nconst FIELDS_OF: Readonly<Record<BuildTarget, Readonly<Record<ExtensionSide, Readonly<Record<string, string>>>>>> = {\n server: { backend: SERVER_FIELDS, frontend: {} },\n web: { backend: {}, frontend: WEB_FIELDS },\n native: { backend: {}, frontend: NATIVE_FIELDS },\n mcp: { backend: MCP_FIELDS, frontend: {} },\n};\n\n/** Everything but the platform: two files sharing this are the same contribution. */\nfunction logicalKey(entry: ExtensionEntry): string {\n const gates = entry.gates.map((gate) => `${gate.kind}:${gate.id}`).join('/');\n const route = entry.route\n .map((segment) => ('literal' in segment ? segment.literal : `[${segment.param.name}]`))\n .join('/');\n // The side is part of it, so a tool's logic and its cockpit renderer never\n // look like one contribution overriding the other.\n return [entry.side, entry.scope, gates, entry.surface ?? '', route, entry.name, entry.target ?? ''].join('|');\n}\n\n/** Resolves the field for a surface whose filename target picks between two shapes. */\nfunction variantField(\n table: Readonly<Record<string, string>>,\n fallback: string,\n entryTarget: string | undefined,\n): string {\n if (entryTarget === undefined) return fallback;\n return table[entryTarget] ?? fallback;\n}\n\nfunction fieldFor(entry: ExtensionEntry, target: BuildTarget): string | undefined {\n const surface = entry.surface;\n if (surface === undefined) return undefined;\n\n const declared = FIELDS_OF[target][entry.side][surface];\n if (declared === undefined || declared === NOT_A_CONTRIBUTION) return undefined;\n\n if (isFrontendTarget(target) && surface === 'lifecycle' && entry.name !== 'start') return undefined;\n if (isFrontendTarget(target) && surface === 'setting') return variantField(SETTING_FIELDS, declared, entry.target);\n if (target === 'web' && surface === 'action') return variantField(ACTION_FIELDS, declared, entry.target);\n // No fallback shape: an unnamed or context action is reported, never routed.\n if (target === NATIVE_PLATFORM && surface === 'action') {\n return entry.target === undefined ? undefined : NATIVE_ACTION_FIELDS[entry.target];\n }\n return declared;\n}\n\n/**\n * Picks the winning file per logical contribution for one host.\n *\n * Metro and Expo semantics: a file naming this platform replaces a sibling\n * that names none, and a file naming none serves the server or the cockpit\n * when it has no more specific sibling. The scan reports the unnamed one, so\n * this is a fallback rather than a supported way to author. MCP and native\n * have no fallback at all: they read only the files that name them. Two files\n * naming the same platform for the same contribution is an authoring mistake,\n * so the first wins and the second becomes a notice rather than silently\n * disappearing.\n */\nexport function resolveTarget(graph: ExtensionGraph, target: BuildTarget): TargetResolution {\n const notices: ExtensionNotice[] = [];\n const escapeHatches: ExtensionEntry[] = [];\n const roots: ExtensionEntry[] = [];\n const winners = new Map<string, ExtensionEntry>();\n\n for (const entry of graph.entries) {\n if (!drawsFrom(entry, target)) continue;\n if (!servesPlatform(entry, target)) continue;\n if (entry.role === 'escape-hatch') {\n escapeHatches.push(entry);\n continue;\n }\n\n if (entry.role === 'root') {\n // Backend only. A root is constructed from a mount context, and the\n // cockpit has none: it builds its plugin definition as data and starts\n // it separately, so there is nothing for a frontend root to receive.\n if (entry.side === 'frontend') {\n notices.push({ path: entry.file, message: 'a scope root is a backend file; the cockpit has no mount context' });\n continue;\n }\n roots.push(entry);\n continue;\n }\n\n const key = logicalKey(entry);\n const held = winners.get(key);\n if (held === undefined) {\n winners.set(key, entry);\n continue;\n }\n if (held.platform === entry.platform) {\n notices.push({ path: entry.file, message: `duplicates ${held.file} for ${target}; the first one wins` });\n continue;\n }\n // A platform file always beats the unsuffixed sibling it overrides.\n if (entry.platform !== undefined) winners.set(key, entry);\n }\n\n const contributions: ResolvedContribution[] = [];\n for (const entry of winners.values()) {\n const field = fieldFor(entry, target);\n if (field === undefined) {\n if (\n target === NATIVE_PLATFORM &&\n entry.surface !== undefined &&\n NATIVE_FIELDS[entry.surface] !== NOT_A_CONTRIBUTION\n ) {\n notices.push({\n path: entry.file,\n message: `${entry.surface}/${entry.name} is not supported by the native host`,\n });\n }\n continue;\n }\n contributions.push({ entry, field });\n }\n\n return {\n target,\n contributions,\n escapeHatches,\n roots: roots.sort((left, right) => SCOPE_DEPTH[left.scope] - SCOPE_DEPTH[right.scope]),\n notices,\n };\n}\n"],"mappings":"yNAeA,MAAMA,EAAgD,CAAE,OAAQ,EAAG,U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S0B,EAAQ,OAAO,EAAG,CACpC,IAAMK,EAAQf,EAAShB,EAAOF,CAAM,EAChCiC,IAAU,IAAA,GAEVjC,IAAA,UACAE,EAAM,UAAY,IAAA,IAClBK,EAAcL,EAAM,WAAA,IAEpBuB,EAAQ,KAAK,CACX,KAAMvB,EAAM,KACZ,QAAS,GAAGA,EAAM,QAAQ,GAAGA,EAAM,KAAK,qCAC1C,CAAC,EAIL8B,EAAc,KAAK,CAAE,QAAO,OAAM,CAAC,CACrC,CAEA,MAAO,CACL,SACA,gBACA,gBACA,MAAOL,EAAM,MAAM,EAAM,IAAU7B,EAAYoC,EAAK,OAASpC,EAAYqC,EAAM,MAAM,EACrF,SACF,CACF"}
@@ -1,2 +1,2 @@
1
- const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../constants/layout.cjs"),n=require("../renderMcpWidgets/index.cjs"),r=require("../generate/index.cjs"),i=require("../syncManifest/index.cjs"),a=require("../unistylesBabel/index.cjs");let o=require("node:fs");o=e.__toESM(o,1);let s=require("node:path");s=e.__toESM(s,1);const c=`apiContracts`;function l(e,t){let n=s.default.join(e,t);if(!o.default.existsSync(n))return{};let r={};for(let e of o.default.readdirSync(n)){if(!e.endsWith(`.ts`)||e.endsWith(`.d.ts`))continue;let n=e.slice(0,-3);r[n]=`${t}/${e}`}return r}function u(e,t,n){let r=s.default.join(e,t);if(!o.default.existsSync(r))return{};let i={};for(let e of o.default.readdirSync(r,{encoding:`utf8`,recursive:!0})){if(!n(e))continue;let r=e.split(s.default.sep).join(`/`);i[`./${t}/${r}`]=`./${t}/${r}`}return i}function d(e){let t=JSON.parse(o.default.readFileSync(s.default.join(e,`package.json`),`utf8`)),n=t.exports!==null&&typeof t.exports==`object`&&!Array.isArray(t.exports)?Object.fromEntries(Object.entries(t.exports).filter(([,e])=>typeof e==`string`)):{};return{...u(e,`skills`,e=>s.default.basename(e)===`SKILL.md`),...u(e,`themes`,e=>e.endsWith(`.json`)),...n}}function f(){return{name:`po-query-assets`,resolveId(e,t){let n=e.indexOf(`?`);if(n<0||t===void 0||!e.startsWith(`.`))return;let r=t.split(`?`)[0];return`${s.default.resolve(s.default.dirname(r),e.slice(0,n))}${e.slice(n)}`},load(e){let t=e.indexOf(`?`);if(t<0)return;let n=e.slice(0,t),r=new URLSearchParams(e.slice(t+1));if(!r.has(`url`))return;let i=r.has(`worker`);return`export default import.meta.ROLLUP_FILE_URL_${this.emitFile(i?{type:`chunk`,id:n,name:s.default.basename(n,s.default.extname(n))}:{type:`asset`,name:s.default.basename(n),source:o.default.readFileSync(n)})};`}}}function p(e=`web`){return{entry:{[`extensions/${e}`]:`${t.GENERATED_DIR}/${e}.ts`},clean:!1,dts:!1,exports:!1,format:[`esm`],platform:`browser`,fixedExtension:!0,external:e=>!e.startsWith(`.`)&&!s.default.isAbsolute(e),plugins:[f()],sourcemap:!0,unbundle:!1,tsconfig:e===`web`?`tsconfig.web.json`:`tsconfig.mcp.json`}}function m(e){return{entry:{"extensions/native":`${t.GENERATED_DIR}/native.ts`},clean:!1,dts:!1,exports:!1,format:[`esm`],platform:`neutral`,fixedExtension:!0,external:e=>!e.startsWith(`.`)&&!s.default.isAbsolute(e),plugins:[a.unistylesBabel(e)],sourcemap:!0,unbundle:!1,tsconfig:`tsconfig.native.json`}}function h(e){let t=s.default.join(e,`dist`);if(o.default.existsSync(t))for(let e of o.default.readdirSync(t,{recursive:!0,encoding:`utf8`})){let n=e.split(s.default.sep).join(`/`);if(!/^(?:extensions\/mcp(?:-ui)?|.+\.mcp)\.(?:mjs|cjs|d\.mts|d\.cts)(?:\.map)?$/u.test(n))continue;let r=s.default.join(t,e);o.default.lstatSync(r).isFile()&&o.default.rmSync(r)}}function g(e={packageDir:process.cwd()}){let a=e.packageDir??process.cwd(),u=r.generateExtension({...e,packageDir:a,check:e.check??!1});for(let e of u.notices)process.stderr.write(`[po-build] ${e.path}: ${e.message}\n`);let f=e.target===`mcp`;f&&!e.check&&h(a);let g=f&&!u.targets.includes(`mcp`),_=`\0po-empty-mcp`;g&&!e.check&&i.writeMcpManifest(a,!1);let v=f?u.targets.includes(`mcp`)?{"extensions/mcp":`${t.GENERATED_DIR}/mcp.ts`}:{"extensions/mcp":_}:{...l(a,e.exportsDir??`src/exports`),...u.targets.includes(`server`)?{"extensions/server":`${t.GENERATED_DIR}/server.ts`}:{},...e.entry},y={clean:!1,dts:!g&&{incremental:!0,parallel:!1,eager:!0},...g?{write:!1,plugins:[{name:`po-empty-mcp`,resolveId:e=>e===_?_:void 0,load:e=>e===_?`export {};`:void 0}]}:{},exports:!f&&{customExports:e=>{let t=Object.keys(v),n=t[0];return{...d(a),...e,...t.length===1&&n!==void 0&&n!==`index`&&!n.startsWith(`extensions/`)?{[`./${n}`]:e[`.`]}:{}}}},format:{esm:{},cjs:{dts:!1}},platform:`node`,outExtensions:({format:e})=>({js:e===`es`?`.mjs`:`.cjs`,dts:e===`es`?`.d.mts`:`.d.cts`}),sourcemap:!0},b=(e,r)=>({...y,entry:e,unbundle:!1,hooks:{"build:done":()=>{if(f){i.writeMcpManifest(a,u.targets.includes(`mcp`),n.renderMcpWidgets(u.graph,u.packageName,t.GENERATED_DIR).names);return}i.writeManifest({packageDir:a,manifest:JSON.parse(o.default.readFileSync(s.default.join(a,`package.json`),`utf8`)),graph:u.graph,targets:u.targets,pluginId:u.pluginId})}}}),x=!f&&c in v&&Object.keys(v).length>1?[((e,t)=>({...y,entry:e,unbundle:t}))({[c]:v[c]},!1),b(Object.fromEntries(Object.entries(v).filter(([e])=>e!==c)),!0)]:[b(v,!f)];if(f&&u.files.has(`generated/mcp-ui.ts`))return[...x,p(`mcp-ui`)];let S=f?[]:[...u.targets.includes(`web`)?[p()]:[],...u.targets.includes(`native`)?[m(a)]:[]];if(S.length>0){if(Object.keys(v).length>0)return[...x,...S];let[e,...t]=S;return[{...e,hooks:x[0].hooks},...t]}return x.length===1?x[0]:x}exports.poExtension=g;
1
+ const e=require("../../_virtual/_rolldown/runtime.cjs"),t=require("../../constants/layout.cjs"),n=require("../renderMcpWidgets/index.cjs"),r=require("../generate/index.cjs"),i=require("../syncManifest/index.cjs"),a=require("../unistylesBabel/index.cjs");let o=require("node:fs");o=e.__toESM(o,1);let s=require("node:path");s=e.__toESM(s,1);const c=`src/exports`,l=`apiContracts`;function u(e,t){let n=s.default.join(e,t);if(!o.default.existsSync(n))return{};let r={};for(let e of o.default.readdirSync(n)){if(!e.endsWith(`.ts`)||e.endsWith(`.d.ts`))continue;let n=e.slice(0,-3);r[n]=`${t}/${e}`}return r}function d(e,n=c){let r=`${t.GENERATED_DIR}/server.ts`;return{...u(e,n),...o.default.existsSync(s.default.join(e,r))?{"extensions/server":r}:{}}}function f(e,t,n){let r=s.default.join(e,t);if(!o.default.existsSync(r))return{};let i={};for(let e of o.default.readdirSync(r,{encoding:`utf8`,recursive:!0})){if(!n(e))continue;let r=e.split(s.default.sep).join(`/`);i[`./${t}/${r}`]=`./${t}/${r}`}return i}function p(e){let t=JSON.parse(o.default.readFileSync(s.default.join(e,`package.json`),`utf8`)),n=t.exports!==null&&typeof t.exports==`object`&&!Array.isArray(t.exports)?Object.fromEntries(Object.entries(t.exports).filter(([,e])=>typeof e==`string`)):{};return{...f(e,`skills`,e=>s.default.basename(e)===`SKILL.md`),...f(e,`themes`,e=>e.endsWith(`.json`)),...n}}function m(){return{name:`po-query-assets`,resolveId(e,t){let n=e.indexOf(`?`);if(n<0||t===void 0||!e.startsWith(`.`))return;let r=t.split(`?`)[0];return`${s.default.resolve(s.default.dirname(r),e.slice(0,n))}${e.slice(n)}`},load(e){let t=e.indexOf(`?`);if(t<0)return;let n=e.slice(0,t),r=new URLSearchParams(e.slice(t+1));if(!r.has(`url`))return;let i=r.has(`worker`);return`export default import.meta.ROLLUP_FILE_URL_${this.emitFile(i?{type:`chunk`,id:n,name:s.default.basename(n,s.default.extname(n))}:{type:`asset`,name:s.default.basename(n),source:o.default.readFileSync(n)})};`}}}function h(e=`web`){return{entry:{[`extensions/${e}`]:`${t.GENERATED_DIR}/${e}.ts`},clean:!1,dts:!1,exports:!1,format:[`esm`],platform:`browser`,fixedExtension:!0,external:e=>!e.startsWith(`.`)&&!s.default.isAbsolute(e),plugins:[m()],sourcemap:!0,unbundle:!1,tsconfig:e===`web`?`tsconfig.web.json`:`tsconfig.mcp.json`}}function g(e){return{entry:{"extensions/native":`${t.GENERATED_DIR}/native.ts`},clean:!1,dts:!1,exports:!1,format:[`esm`],platform:`neutral`,fixedExtension:!0,external:e=>!e.startsWith(`.`)&&!s.default.isAbsolute(e),plugins:[a.unistylesBabel(e)],sourcemap:!0,unbundle:!1,tsconfig:`tsconfig.native.json`}}const _=/^(?:extensions\/mcp(?:-ui)?|.+\.mcp)\.(?:mjs|cjs|d\.mts|d\.cts)(?:\.map)?$/u;function v(e,t){let n=s.default.join(e,`dist`);if(o.default.existsSync(n))for(let e of o.default.readdirSync(n,{recursive:!0,encoding:`utf8`})){if(_.test(e.split(s.default.sep).join(`/`))!==(t===`mcp`))continue;let r=s.default.join(n,e);o.default.lstatSync(r,{throwIfNoEntry:!1})?.isFile()&&o.default.rmSync(r)}}function y(e={packageDir:process.cwd()}){let a=e.packageDir??process.cwd(),d=r.generateExtension({...e,packageDir:a,check:e.check??!1});for(let e of d.notices)process.stderr.write(`[po-build] ${e.path}: ${e.message}\n`);let f=e.target===`mcp`;e.check||v(a,f?`mcp`:`normal`);let m=f&&!d.targets.includes(`mcp`),_=`\0po-empty-mcp`;m&&!e.check&&i.writeMcpManifest(a,!1);let y=f?d.targets.includes(`mcp`)?{"extensions/mcp":`${t.GENERATED_DIR}/mcp.ts`}:{"extensions/mcp":_}:{...u(a,e.exportsDir??c),...d.targets.includes(`server`)?{"extensions/server":`${t.GENERATED_DIR}/server.ts`}:{},...e.entry},b={clean:!1,dts:!m&&{incremental:!0,parallel:!1,eager:!0},...m?{write:!1,plugins:[{name:`po-empty-mcp`,resolveId:e=>e===_?_:void 0,load:e=>e===_?`export {};`:void 0}]}:{},exports:!f&&{customExports:e=>{let t=Object.keys(y),n=t[0];return{...p(a),...e,...t.length===1&&n!==void 0&&n!==`index`&&!n.startsWith(`extensions/`)?{[`./${n}`]:e[`.`]}:{}}}},format:{esm:{},cjs:{dts:!1}},platform:`node`,outExtensions:({format:e})=>({js:e===`es`?`.mjs`:`.cjs`,dts:e===`es`?`.d.mts`:`.d.cts`}),sourcemap:!0},x=(e,r)=>({...b,entry:e,unbundle:!1,hooks:{"build:done":()=>{f?i.writeMcpManifest(a,d.targets.includes(`mcp`),n.renderMcpWidgets(d.graph,d.packageName,t.GENERATED_DIR).names):i.writeManifest({packageDir:a,manifest:JSON.parse(o.default.readFileSync(s.default.join(a,`package.json`),`utf8`)),graph:d.graph,targets:d.targets,pluginId:d.pluginId})}}}),S=!f&&l in y&&Object.keys(y).length>1?[((e,t)=>({...b,entry:e,unbundle:t}))({[l]:y[l]},!1),x(Object.fromEntries(Object.entries(y).filter(([e])=>e!==l)),!0)]:[x(y,!f)];if(f&&d.files.has(`generated/mcp-ui.ts`))return[...S,h(`mcp-ui`)];let C=f?[]:[...d.targets.includes(`web`)?[h()]:[],...d.targets.includes(`native`)?[g(a)]:[]];if(C.length>0){if(Object.keys(y).length>0)return[...S,...C];let[e,...t]=C;return[{...e,hooks:S[0].hooks},...t]}return S.length===1?S[0]:S}exports.extensionSourceEntries=d,exports.poExtension=y;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":["path","fs","GENERATED_DIR","unistylesBabel","generateExtension","renderMcpWidgets","require_runtime","require_layout","require_index","require_index$1","require_index$2","require_index$3","node_fs","node_path","API_CONTRACTS_ENTRY","exportEntries","absolute","packageDir","exportsDir","entries","file","stem","resourceEntries","root","directory","relative","matches","normalized","staticExports","manifest","declared","target","queryAssetPlugin","queryAt","source","importer","importerFile","id","query","worker","browserConfig","nativeConfig","cleanMcpOutput","dist","poExtension","options","result","notice","mcpOnly","emptyMcp","emptyEntry","entry","baseNode","names","name","generated","format","node","configs","frontends","first","rest"],"sources":["../../../src/services/tsdownPreset/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { GENERATED_DIR } from '../../constants/layout';\nimport { generateExtension } from '../generate';\nimport type { GenerateOptions } from '../generate/type';\nimport { renderMcpWidgets } from '../renderMcpWidgets';\nimport { writeManifest, writeMcpManifest } from '../syncManifest';\nimport { unistylesBabel } from '../unistylesBabel';\nimport type { UnistylesBabelPlugin } from '../unistylesBabel/type';\n\ninterface EmittedFile {\n readonly type: 'asset' | 'chunk';\n readonly id?: string;\n readonly name: string;\n readonly source?: Buffer;\n}\n\ninterface QueryAssetPlugin {\n readonly name: string;\n resolveId(source: string, importer: string | undefined): string | undefined;\n load(this: { emitFile(file: EmittedFile): string }, id: string): string | undefined;\n}\n\n/** The shape a tsdown config needs from this preset, without importing tsdown's types. */\ninterface BrowserPresetConfig {\n entry: Record<string, string>;\n clean: boolean;\n dts: false;\n exports: boolean;\n format: 'esm'[];\n platform: 'browser';\n fixedExtension: boolean;\n external: (id: string) => boolean;\n plugins: QueryAssetPlugin[];\n sourcemap: boolean;\n unbundle: boolean;\n tsconfig: string;\n hooks?: PresetConfig['hooks'];\n}\n\n/** The separately bundled native half, shaped like the browser one. */\ninterface NativePresetConfig extends Omit<BrowserPresetConfig, 'platform' | 'plugins'> {\n platform: 'neutral';\n plugins: UnistylesBabelPlugin[];\n}\n\ninterface GeneratedExports {\n customExports: (exports: Record<string, unknown>) => Record<string, unknown>;\n}\n\ninterface BasePresetConfig {\n entry: Record<string, string>;\n clean: boolean;\n dts: false | { incremental: boolean; parallel: boolean; eager: boolean };\n write?: false;\n plugins?: QueryAssetPlugin[];\n exports: boolean | GeneratedExports;\n format: { esm: Record<string, never>; cjs: { dts: false } };\n platform: 'node';\n sourcemap: boolean;\n unbundle: boolean;\n outExtensions: ({ format }: { format: string }) => {\n js: string;\n dts: string;\n };\n}\n\ninterface PresetConfig extends BasePresetConfig {\n hooks?: { 'build:done': () => void };\n}\n\nconst DEFAULT_EXPORTS_DIR = 'src/exports';\nconst API_CONTRACTS_ENTRY = 'apiContracts';\n\n/** `src/exports/apiContracts.ts` becomes the `apiContracts` entry; index keeps its name. */\nfunction exportEntries(packageDir: string, exportsDir: string): Record<string, string> {\n const absolute = path.join(packageDir, exportsDir);\n if (!fs.existsSync(absolute)) return {};\n const entries: Record<string, string> = {};\n for (const file of fs.readdirSync(absolute)) {\n if (!file.endsWith('.ts') || file.endsWith('.d.ts')) continue;\n const stem = file.slice(0, -'.ts'.length);\n entries[stem] = `${exportsDir}/${file}`;\n }\n return entries;\n}\n\n/** Static resources receive package export entries without becoming tsdown inputs. */\nfunction resourceEntries(\n packageDir: string,\n directory: string,\n matches: (relative: string) => boolean,\n): Record<string, string> {\n const root = path.join(packageDir, directory);\n if (!fs.existsSync(root)) return {};\n const entries: Record<string, string> = {};\n for (const relative of fs.readdirSync(root, { encoding: 'utf8', recursive: true })) {\n if (!matches(relative)) continue;\n const normalized = relative.split(path.sep).join('/');\n entries[`./${directory}/${normalized}`] = `./${directory}/${normalized}`;\n }\n return entries;\n}\n\n/** Preserves declared resources and discovers default skill and theme resource exports. */\nfunction staticExports(packageDir: string): Record<string, unknown> {\n const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as Record<\n string,\n unknown\n >;\n const declared =\n manifest.exports !== null && typeof manifest.exports === 'object' && !Array.isArray(manifest.exports)\n ? Object.fromEntries(Object.entries(manifest.exports).filter(([, target]) => typeof target === 'string'))\n : {};\n return {\n ...resourceEntries(packageDir, 'skills', (relative) => path.basename(relative) === 'SKILL.md'),\n ...resourceEntries(packageDir, 'themes', (relative) => relative.endsWith('.json')),\n ...declared,\n };\n}\n/**\n * One tsdown config for a folder-routed extension.\n *\n * Entries come from the tree rather than a hand-written list, and the manifest\n * blocks that restate the tree are written after the build rather than kept in\n * step by hand. Browser contributions are emitted through a second bundled\n * config because their routed source is not published.\n */\nexport interface ExtensionPresetOptions extends GenerateOptions {\n /** Extra tsdown entries beyond the derived ones. */\n readonly entry?: Record<string, string>;\n /** Public export modules, package-relative. Defaults to `src/exports`. */\n readonly exportsDir?: string;\n}\n\n/**\n * Implements the Vite query imports extension browser code already uses.\n *\n * `?url` copies an opaque asset and `?worker&url` emits a separately bundled\n * worker chunk. Rolldown then replaces its file reference with an URL relative\n * to the extension bundle, which remains valid when the cockpit composes it.\n */\nfunction queryAssetPlugin(): QueryAssetPlugin {\n return {\n name: 'po-query-assets',\n resolveId(source, importer) {\n const queryAt = source.indexOf('?');\n if (queryAt < 0 || importer === undefined || !source.startsWith('.')) return undefined;\n const importerFile = importer.split('?')[0] as string;\n return `${path.resolve(path.dirname(importerFile), source.slice(0, queryAt))}${source.slice(queryAt)}`;\n },\n load(id) {\n const queryAt = id.indexOf('?');\n if (queryAt < 0) return undefined;\n const file = id.slice(0, queryAt);\n const query = new URLSearchParams(id.slice(queryAt + 1));\n if (!query.has('url')) return undefined;\n const worker = query.has('worker');\n const reference = this.emitFile(\n worker\n ? { type: 'chunk', id: file, name: path.basename(file, path.extname(file)) }\n : { type: 'asset', name: path.basename(file), source: fs.readFileSync(file) },\n );\n return `export default import.meta.ROLLUP_FILE_URL_${reference};`;\n },\n };\n}\n\n/** The separately bundled browser half of a routed extension. */\nfunction browserConfig(target: 'web' | 'mcp-ui' = 'web'): BrowserPresetConfig {\n return {\n entry: { [`extensions/${target}`]: `${GENERATED_DIR}/${target}.ts` },\n clean: false,\n // No declarations. Nothing imports this as a typed module: it has no\n // export subpath, and the cockpit consumes it as a bundle. The browser\n // half is still typechecked, by tsconfig.web.json in the typecheck script.\n dts: false,\n exports: false,\n format: ['esm'],\n platform: 'browser',\n // platform browser turns tsdown's fixedExtension off, which would emit\n // .js. The manifest names .mjs like the other two entries, so ask for it.\n fixedExtension: true,\n // Every bare specifier stays external and the cockpit resolves it, which\n // is what keeps one React and one store in the page no matter how many\n // plugins are installed. An allowlist would have to be kept in step with\n // the cockpit's; this cannot drift.\n //\n // A predicate rather than a pattern: rolldown tests `external` against the\n // resolved id, so /^[^.]/ also matches the absolute path of this package's\n // own routed file and would leave a dangling import to unbuilt .tsx.\n external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),\n plugins: [queryAssetPlugin()],\n sourcemap: true,\n // Bundled, unlike the node half. Unbundling would emit an import to the\n // routed source file, which is not published and is .tsx besides. One\n // module with only bare specifiers external is what the cockpit wants.\n unbundle: false,\n // Browser routes are excluded from the node tsconfig. Every browser-capable\n // extension owns this focused config for its matching typecheck.\n tsconfig: target === 'web' ? 'tsconfig.web.json' : 'tsconfig.mcp.json',\n };\n}\n\n/**\n * The separately bundled native half of a routed extension.\n *\n * Neutral rather than browser: React Native has neither the DOM nor Node, so\n * no condition set fits it better, and every bare specifier stays external\n * anyway. The CLI bundles this module into the signed composition and refuses\n * any import outside the native host module list, so nothing here has to.\n */\nfunction nativeConfig(packageDir: string): NativePresetConfig {\n return {\n entry: { 'extensions/native': `${GENERATED_DIR}/native.ts` },\n clean: false,\n dts: false,\n exports: false,\n format: ['esm'],\n platform: 'neutral',\n fixedExtension: true,\n // The same predicate as the browser half, for the same reason: the host\n // supplies React, React Native and Unistyles, one copy each.\n external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),\n plugins: [unistylesBabel(packageDir)],\n sourcemap: true,\n unbundle: false,\n // Native routes import react-native, which the DOM-typed web config must\n // not see, so they typecheck under their own config.\n tsconfig: 'tsconfig.native.json',\n };\n}\n\n/** Removes only filenames owned by the isolated MCP build, including obsolete declarations. */\nfunction cleanMcpOutput(packageDir: string): void {\n const dist = path.join(packageDir, 'dist');\n if (!fs.existsSync(dist)) return;\n for (const relative of fs.readdirSync(dist, { recursive: true, encoding: 'utf8' })) {\n const normalized = relative.split(path.sep).join('/');\n if (!/^(?:extensions\\/mcp(?:-ui)?|.+\\.mcp)\\.(?:mjs|cjs|d\\.mts|d\\.cts)(?:\\.map)?$/u.test(normalized)) continue;\n const absolute = path.join(dist, relative);\n if (fs.lstatSync(absolute).isFile()) fs.rmSync(absolute);\n }\n}\n\nexport function poExtension(\n options: ExtensionPresetOptions = { packageDir: process.cwd() },\n): PresetConfig | (PresetConfig | BrowserPresetConfig | NativePresetConfig)[] {\n const packageDir = options.packageDir ?? process.cwd();\n const result = generateExtension({ ...options, packageDir, check: options.check ?? false });\n\n for (const notice of result.notices) process.stderr.write(`[po-build] ${notice.path}: ${notice.message}\\n`);\n\n const mcpOnly = options.target === 'mcp';\n if (mcpOnly && !options.check) cleanMcpOutput(packageDir);\n const emptyMcp = mcpOnly && !result.targets.includes('mcp');\n const emptyEntry = '\\0po-empty-mcp';\n if (emptyMcp && !options.check) writeMcpManifest(packageDir, false);\n const entry: Record<string, string> = mcpOnly\n ? result.targets.includes('mcp')\n ? { 'extensions/mcp': `${GENERATED_DIR}/mcp.ts` }\n : { 'extensions/mcp': emptyEntry }\n : {\n ...exportEntries(packageDir, options.exportsDir ?? DEFAULT_EXPORTS_DIR),\n ...(result.targets.includes('server') ? { 'extensions/server': `${GENERATED_DIR}/server.ts` } : {}),\n ...options.entry,\n };\n\n const baseNode: Omit<BasePresetConfig, 'entry' | 'unbundle'> = {\n // MCP shares dist/ with the normal build, so neither build may erase the other.\n clean: false,\n dts: emptyMcp ? false : { incremental: true, parallel: false, eager: true },\n // tsdown rejects both an empty entry and an empty config array. A virtual\n // input completes its normal lifecycle without publishing an empty facet.\n ...(emptyMcp\n ? {\n write: false as const,\n plugins: [\n {\n name: 'po-empty-mcp',\n resolveId: (source: string) => (source === emptyEntry ? emptyEntry : undefined),\n load: (id: string) => (id === emptyEntry ? 'export {};' : undefined),\n },\n ],\n }\n : {}),\n exports: mcpOnly\n ? false\n : {\n customExports: (generated) => {\n const names = Object.keys(entry);\n const name = names[0];\n return {\n ...staticExports(packageDir),\n ...generated,\n ...(names.length === 1 && name !== undefined && name !== 'index' && !name.startsWith('extensions/')\n ? { [`./${name}`]: generated['.'] }\n : {}),\n };\n },\n },\n // CommonJS keeps its JavaScript but emits no declarations. Every export map\n // resolves types through .d.mts, and a CJS declaration build would rerun\n // the same whole-program tsgo emit a second time.\n format: { esm: {}, cjs: { dts: false } },\n // No minify. This is a library build, and a mangled stack trace inside a\n // published extension is far more expensive than the bytes it saves.\n // Native server entries use the .mjs filenames their hosts require.\n platform: 'node',\n outExtensions: ({ format }) => ({\n js: format === 'es' ? '.mjs' : '.cjs',\n dts: format === 'es' ? '.d.mts' : '.d.cts',\n }),\n sourcemap: true,\n };\n\n // Contract bundles are published as a self-contained graph. Normal extension\n // entries remain unbundled for routed runtime resources, while MCP remains\n // isolated from the shared dist directory.\n const node = (entries: Record<string, string>, _unbundle: boolean): PresetConfig => ({\n ...baseNode,\n entry: entries,\n // Public entry facades must remain bundled. Otherwise their relative\n // imports target unbundled implementation chunks, which Vite treats as\n // source files when resolving a workspace package.\n unbundle: false,\n hooks: {\n 'build:done': () => {\n if (mcpOnly) {\n writeMcpManifest(\n packageDir,\n result.targets.includes('mcp'),\n renderMcpWidgets(result.graph, result.packageName, GENERATED_DIR).names,\n );\n return;\n }\n writeManifest({\n packageDir,\n manifest: JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as Record<\n string,\n unknown\n >,\n graph: result.graph,\n targets: result.targets,\n pluginId: result.pluginId,\n });\n },\n },\n });\n const unsyncedNode = (entries: Record<string, string>, unbundle: boolean): PresetConfig => ({\n ...baseNode,\n entry: entries,\n unbundle,\n });\n const configs =\n !mcpOnly && API_CONTRACTS_ENTRY in entry && Object.keys(entry).length > 1\n ? [\n unsyncedNode({ [API_CONTRACTS_ENTRY]: entry[API_CONTRACTS_ENTRY] }, false),\n node(Object.fromEntries(Object.entries(entry).filter(([name]) => name !== API_CONTRACTS_ENTRY)), true),\n ]\n : [node(entry, !mcpOnly)];\n if (mcpOnly && result.files.has(`${GENERATED_DIR}/mcp-ui.ts`)) return [...configs, browserConfig('mcp-ui')];\n const frontends: (BrowserPresetConfig | NativePresetConfig)[] = mcpOnly\n ? []\n : [\n ...(result.targets.includes('web') ? [browserConfig()] : []),\n ...(result.targets.includes('native') ? [nativeConfig(packageDir)] : []),\n ];\n if (frontends.length > 0) {\n if (Object.keys(entry).length > 0) return [...configs, ...frontends];\n // No node entry to carry the manifest sync, so the first frontend build does.\n const [first, ...rest] = frontends;\n return [{ ...first!, hooks: configs[0]!.hooks }, ...rest];\n }\n return configs.length === 1 ? configs[0]! : configs;\n}\n"],"mappings":"oVAwEA,MACMc,EAAsB,eAG5B,SAASC,EAAc,EAAoB,EAA4C,CACrF,IAAMC,EAAWhB,EAAAA,QAAK,KAAKiB,EAAYC,CAAU,EACjD,GAAI,CAACjB,EAAAA,QAAG,WAAWe,CAAQ,EAAG,MAAO,CAAC,EACtC,IAAMG,EAAkC,CAAC,EACzC,IAAK,IAAMC,KAAQnB,EAAAA,QAAG,YAAYe,CAAQ,EAAG,CAC3C,GAAI,CAACI,EAAK,SAAS,KAAK,GAAKA,EAAK,SAAS,OAAO,EAAG,SACrD,IAAMC,EAAOD,EAAK,MAAM,EAAG,EAAa,EACxC,EAAQC,GAAQ,GAAGH,EAAW,GAAGE,GACnC,CACA,OAAOD,CACT,CAGA,SAASG,EACP,EACA,EACA,EACwB,CACxB,IAAMC,EAAOvB,EAAAA,QAAK,KAAKiB,EAAYO,CAAS,EAC5C,GAAI,CAACvB,EAAAA,QAAG,WAAWsB,CAAI,EAAG,MAAO,CAAC,EAClC,IAAMJ,EAAkC,CAAC,EACzC,IAAK,IAAMM,KAAYxB,EAAAA,QAAG,YAAYsB,EAAM,CAAE,SAAU,OAAQ,UAAW,EAAK,CAAC,EAAG,CAClF,GAAI,CAACG,EAAQD,CAAQ,EAAG,SACxB,IAAME,EAAaF,EAAS,MAAMzB,EAAAA,QAAK,GAAG,CAAC,CAAC,KAAK,GAAG,EACpD,EAAQ,KAAKwB,EAAU,GAAGG,KAAgB,KAAKH,EAAU,GAAGG,GAC9D,CACA,OAAOR,CACT,CAGA,SAASS,EAAc,EAA6C,CAClE,IAAMC,EAAW,KAAK,MAAM5B,EAAAA,Q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QAAQN,CAAK,CAAC,CAAC,QAAQ,CAACG,KAAUA,IAASxC,CAAmB,CAAC,EAAG,EAAI,CACvG,EACA,CAAC2C,EAAKN,EAAO,CAACH,CAAO,CAAC,EAC5B,GAAIA,GAAWF,EAAO,MAAM,IAAI,qBAA4B,EAAG,MAAO,CAAC,GAAGY,EAASlB,EAAc,QAAQ,CAAC,EAC1G,IAAMmB,EAA0DX,EAC5D,CAAC,EACD,CACE,GAAIF,EAAO,QAAQ,SAAS,KAAK,EAAI,CAACN,EAAc,CAAC,EAAI,CAAC,EAC1D,GAAIM,EAAO,QAAQ,SAAS,QAAQ,EAAI,CAACL,EAAaxB,CAAU,CAAC,EAAI,CAAC,CACxE,EACJ,GAAI0C,EAAU,OAAS,EAAG,CACxB,GAAI,OAAO,KAAKR,CAAK,CAAC,CAAC,OAAS,EAAG,MAAO,CAAC,GAAGO,EAAS,GAAGC,CAAS,EAEnE,GAAM,CAACC,EAAO,GAAGC,GAAQF,EACzB,MAAO,CAAC,CAAE,GAAGC,EAAQ,MAAOF,EAAQ,EAAE,CAAE,KAAM,EAAG,GAAGG,CAAI,CAC1D,CACA,OAAOH,EAAQ,SAAW,EAAIA,EAAQ,GAAMA,CAC9C"}
1
+ {"version":3,"file":"index.cjs","names":["path","fs","GENERATED_DIR","unistylesBabel","generateExtension","renderMcpWidgets","require_runtime","require_layout","require_index","require_index$1","require_index$2","require_index$3","node_fs","node_path","DEFAULT_EXPORTS_DIR","API_CONTRACTS_ENTRY","exportEntries","absolute","packageDir","exportsDir","entries","file","stem","extensionSourceEntries","server","resourceEntries","root","directory","relative","matches","normalized","staticExports","manifest","declared","target","queryAssetPlugin","queryAt","source","importer","importerFile","id","query","worker","browserConfig","nativeConfig","MCP_OUTPUT","cleanOutput","dist","owner","poExtension","options","result","notice","mcpOnly","emptyMcp","emptyEntry","entry","baseNode","names","name","generated","format","node","configs","frontends","first","rest"],"sources":["../../../src/services/tsdownPreset/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { GENERATED_DIR } from '../../constants/layout';\nimport { generateExtension } from '../generate';\nimport type { GenerateOptions } from '../generate/type';\nimport { renderMcpWidgets } from '../renderMcpWidgets';\nimport { writeManifest, writeMcpManifest } from '../syncManifest';\nimport { unistylesBabel } from '../unistylesBabel';\nimport type { UnistylesBabelPlugin } from '../unistylesBabel/type';\n\ninterface EmittedFile {\n readonly type: 'asset' | 'chunk';\n readonly id?: string;\n readonly name: string;\n readonly source?: Buffer;\n}\n\ninterface QueryAssetPlugin {\n readonly name: string;\n resolveId(source: string, importer: string | undefined): string | undefined;\n load(this: { emitFile(file: EmittedFile): string }, id: string): string | undefined;\n}\n\n/** The shape a tsdown config needs from this preset, without importing tsdown's types. */\ninterface BrowserPresetConfig {\n entry: Record<string, string>;\n clean: boolean;\n dts: false;\n exports: boolean;\n format: 'esm'[];\n platform: 'browser';\n fixedExtension: boolean;\n external: (id: string) => boolean;\n plugins: QueryAssetPlugin[];\n sourcemap: boolean;\n unbundle: boolean;\n tsconfig: string;\n hooks?: PresetConfig['hooks'];\n}\n\n/** The separately bundled native half, shaped like the browser one. */\ninterface NativePresetConfig extends Omit<BrowserPresetConfig, 'platform' | 'plugins'> {\n platform: 'neutral';\n plugins: UnistylesBabelPlugin[];\n}\n\ninterface GeneratedExports {\n customExports: (exports: Record<string, unknown>) => Record<string, unknown>;\n}\n\ninterface BasePresetConfig {\n entry: Record<string, string>;\n clean: boolean;\n dts: false | { incremental: boolean; parallel: boolean; eager: boolean };\n write?: false;\n plugins?: QueryAssetPlugin[];\n exports: boolean | GeneratedExports;\n format: { esm: Record<string, never>; cjs: { dts: false } };\n platform: 'node';\n sourcemap: boolean;\n unbundle: boolean;\n outExtensions: ({ format }: { format: string }) => {\n js: string;\n dts: string;\n };\n}\n\ninterface PresetConfig extends BasePresetConfig {\n hooks?: { 'build:done': () => void };\n}\n\nconst DEFAULT_EXPORTS_DIR = 'src/exports';\nconst API_CONTRACTS_ENTRY = 'apiContracts';\n\n/** `src/exports/apiContracts.ts` becomes the `apiContracts` entry; index keeps its name. */\nfunction exportEntries(packageDir: string, exportsDir: string): Record<string, string> {\n const absolute = path.join(packageDir, exportsDir);\n if (!fs.existsSync(absolute)) return {};\n const entries: Record<string, string> = {};\n for (const file of fs.readdirSync(absolute)) {\n if (!file.endsWith('.ts') || file.endsWith('.d.ts')) continue;\n const stem = file.slice(0, -'.ts'.length);\n entries[stem] = `${exportsDir}/${file}`;\n }\n return entries;\n}\n\n/**\n * Source file behind each published subpath of a folder-routed extension, keyed like\n * tsdown entries (`index`, `apiContracts`, `extensions/server`). Read from disk without\n * regenerating, so `generated/server.ts` must already exist. The private Worker build\n * uses this to bundle workspace sources instead of `dist/`.\n */\nexport function extensionSourceEntries(\n packageDir: string,\n exportsDir: string = DEFAULT_EXPORTS_DIR,\n): Record<string, string> {\n const server = `${GENERATED_DIR}/server.ts`;\n return {\n ...exportEntries(packageDir, exportsDir),\n ...(fs.existsSync(path.join(packageDir, server)) ? { 'extensions/server': server } : {}),\n };\n}\n\n/** Static resources receive package export entries without becoming tsdown inputs. */\nfunction resourceEntries(\n packageDir: string,\n directory: string,\n matches: (relative: string) => boolean,\n): Record<string, string> {\n const root = path.join(packageDir, directory);\n if (!fs.existsSync(root)) return {};\n const entries: Record<string, string> = {};\n for (const relative of fs.readdirSync(root, { encoding: 'utf8', recursive: true })) {\n if (!matches(relative)) continue;\n const normalized = relative.split(path.sep).join('/');\n entries[`./${directory}/${normalized}`] = `./${directory}/${normalized}`;\n }\n return entries;\n}\n\n/** Preserves declared resources and discovers default skill and theme resource exports. */\nfunction staticExports(packageDir: string): Record<string, unknown> {\n const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as Record<\n string,\n unknown\n >;\n const declared =\n manifest.exports !== null && typeof manifest.exports === 'object' && !Array.isArray(manifest.exports)\n ? Object.fromEntries(Object.entries(manifest.exports).filter(([, target]) => typeof target === 'string'))\n : {};\n return {\n ...resourceEntries(packageDir, 'skills', (relative) => path.basename(relative) === 'SKILL.md'),\n ...resourceEntries(packageDir, 'themes', (relative) => relative.endsWith('.json')),\n ...declared,\n };\n}\n/**\n * One tsdown config for a folder-routed extension.\n *\n * Entries come from the tree rather than a hand-written list, and the manifest\n * blocks that restate the tree are written after the build rather than kept in\n * step by hand. Browser contributions are emitted through a second bundled\n * config because their routed source is not published.\n */\nexport interface ExtensionPresetOptions extends GenerateOptions {\n /** Extra tsdown entries beyond the derived ones. */\n readonly entry?: Record<string, string>;\n /** Public export modules, package-relative. Defaults to `src/exports`. */\n readonly exportsDir?: string;\n}\n\n/**\n * Implements the Vite query imports extension browser code already uses.\n *\n * `?url` copies an opaque asset and `?worker&url` emits a separately bundled\n * worker chunk. Rolldown then replaces its file reference with an URL relative\n * to the extension bundle, which remains valid when the cockpit composes it.\n */\nfunction queryAssetPlugin(): QueryAssetPlugin {\n return {\n name: 'po-query-assets',\n resolveId(source, importer) {\n const queryAt = source.indexOf('?');\n if (queryAt < 0 || importer === undefined || !source.startsWith('.')) return undefined;\n const importerFile = importer.split('?')[0] as string;\n return `${path.resolve(path.dirname(importerFile), source.slice(0, queryAt))}${source.slice(queryAt)}`;\n },\n load(id) {\n const queryAt = id.indexOf('?');\n if (queryAt < 0) return undefined;\n const file = id.slice(0, queryAt);\n const query = new URLSearchParams(id.slice(queryAt + 1));\n if (!query.has('url')) return undefined;\n const worker = query.has('worker');\n const reference = this.emitFile(\n worker\n ? { type: 'chunk', id: file, name: path.basename(file, path.extname(file)) }\n : { type: 'asset', name: path.basename(file), source: fs.readFileSync(file) },\n );\n return `export default import.meta.ROLLUP_FILE_URL_${reference};`;\n },\n };\n}\n\n/** The separately bundled browser half of a routed extension. */\nfunction browserConfig(target: 'web' | 'mcp-ui' = 'web'): BrowserPresetConfig {\n return {\n entry: { [`extensions/${target}`]: `${GENERATED_DIR}/${target}.ts` },\n clean: false,\n // No declarations. Nothing imports this as a typed module: it has no\n // export subpath, and the cockpit consumes it as a bundle. The browser\n // half is still typechecked, by tsconfig.web.json in the typecheck script.\n dts: false,\n exports: false,\n format: ['esm'],\n platform: 'browser',\n // platform browser turns tsdown's fixedExtension off, which would emit\n // .js. The manifest names .mjs like the other two entries, so ask for it.\n fixedExtension: true,\n // Every bare specifier stays external and the cockpit resolves it, which\n // is what keeps one React and one store in the page no matter how many\n // plugins are installed. An allowlist would have to be kept in step with\n // the cockpit's; this cannot drift.\n //\n // A predicate rather than a pattern: rolldown tests `external` against the\n // resolved id, so /^[^.]/ also matches the absolute path of this package's\n // own routed file and would leave a dangling import to unbuilt .tsx.\n external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),\n plugins: [queryAssetPlugin()],\n sourcemap: true,\n // Bundled, unlike the node half. Unbundling would emit an import to the\n // routed source file, which is not published and is .tsx besides. One\n // module with only bare specifiers external is what the cockpit wants.\n unbundle: false,\n // Browser routes are excluded from the node tsconfig. Every browser-capable\n // extension owns this focused config for its matching typecheck.\n tsconfig: target === 'web' ? 'tsconfig.web.json' : 'tsconfig.mcp.json',\n };\n}\n\n/**\n * The separately bundled native half of a routed extension.\n *\n * Neutral rather than browser: React Native has neither the DOM nor Node, so\n * no condition set fits it better, and every bare specifier stays external\n * anyway. The CLI bundles this module into the signed composition and refuses\n * any import outside the native host module list, so nothing here has to.\n */\nfunction nativeConfig(packageDir: string): NativePresetConfig {\n return {\n entry: { 'extensions/native': `${GENERATED_DIR}/native.ts` },\n clean: false,\n dts: false,\n exports: false,\n format: ['esm'],\n platform: 'neutral',\n fixedExtension: true,\n // The same predicate as the browser half, for the same reason: the host\n // supplies React, React Native and Unistyles, one copy each.\n external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),\n plugins: [unistylesBabel(packageDir)],\n sourcemap: true,\n unbundle: false,\n // Native routes import react-native, which the DOM-typed web config must\n // not see, so they typecheck under their own config.\n tsconfig: 'tsconfig.native.json',\n };\n}\n\nconst MCP_OUTPUT = /^(?:extensions\\/mcp(?:-ui)?|.+\\.mcp)\\.(?:mjs|cjs|d\\.mts|d\\.cts)(?:\\.map)?$/u;\n\n/**\n * Removes files from dist that one build owns, so an entry deleted from the source tree does\n * not live on as a stale file (and in the Nx cache). The MCP build removes only its own files;\n * the normal build removes everything else and keeps the MCP files the other build wrote.\n */\nfunction cleanOutput(packageDir: string, owner: 'mcp' | 'normal'): void {\n const dist = path.join(packageDir, 'dist');\n if (!fs.existsSync(dist)) return;\n for (const relative of fs.readdirSync(dist, { recursive: true, encoding: 'utf8' })) {\n const isMcp = MCP_OUTPUT.test(relative.split(path.sep).join('/'));\n if (isMcp !== (owner === 'mcp')) continue;\n const absolute = path.join(dist, relative);\n if (fs.lstatSync(absolute, { throwIfNoEntry: false })?.isFile()) fs.rmSync(absolute);\n }\n}\n\nexport function poExtension(\n options: ExtensionPresetOptions = { packageDir: process.cwd() },\n): PresetConfig | (PresetConfig | BrowserPresetConfig | NativePresetConfig)[] {\n const packageDir = options.packageDir ?? process.cwd();\n const result = generateExtension({ ...options, packageDir, check: options.check ?? false });\n\n for (const notice of result.notices) process.stderr.write(`[po-build] ${notice.path}: ${notice.message}\\n`);\n\n const mcpOnly = options.target === 'mcp';\n // ponytail: the normal build cleans at config load, so it must run before the MCP build (every\n // build script does). Hashed assets of an mcp-ui bundle are not recognised and are rebuilt after.\n if (!options.check) cleanOutput(packageDir, mcpOnly ? 'mcp' : 'normal');\n const emptyMcp = mcpOnly && !result.targets.includes('mcp');\n const emptyEntry = '\\0po-empty-mcp';\n if (emptyMcp && !options.check) writeMcpManifest(packageDir, false);\n const entry: Record<string, string> = mcpOnly\n ? result.targets.includes('mcp')\n ? { 'extensions/mcp': `${GENERATED_DIR}/mcp.ts` }\n : { 'extensions/mcp': emptyEntry }\n : {\n ...exportEntries(packageDir, options.exportsDir ?? DEFAULT_EXPORTS_DIR),\n ...(result.targets.includes('server') ? { 'extensions/server': `${GENERATED_DIR}/server.ts` } : {}),\n ...options.entry,\n };\n\n const baseNode: Omit<BasePresetConfig, 'entry' | 'unbundle'> = {\n // MCP shares dist/ with the normal build, so neither build may erase the other.\n clean: false,\n dts: emptyMcp ? false : { incremental: true, parallel: false, eager: true },\n // tsdown rejects both an empty entry and an empty config array. A virtual\n // input completes its normal lifecycle without publishing an empty facet.\n ...(emptyMcp\n ? {\n write: false as const,\n plugins: [\n {\n name: 'po-empty-mcp',\n resolveId: (source: string) => (source === emptyEntry ? emptyEntry : undefined),\n load: (id: string) => (id === emptyEntry ? 'export {};' : undefined),\n },\n ],\n }\n : {}),\n exports: mcpOnly\n ? false\n : {\n customExports: (generated) => {\n const names = Object.keys(entry);\n const name = names[0];\n return {\n ...staticExports(packageDir),\n ...generated,\n ...(names.length === 1 && name !== undefined && name !== 'index' && !name.startsWith('extensions/')\n ? { [`./${name}`]: generated['.'] }\n : {}),\n };\n },\n },\n // CommonJS keeps its JavaScript but emits no declarations. Every export map\n // resolves types through .d.mts, and a CJS declaration build would rerun\n // the same whole-program tsgo emit a second time.\n format: { esm: {}, cjs: { dts: false } },\n // No minify. This is a library build, and a mangled stack trace inside a\n // published extension is far more expensive than the bytes it saves.\n // Native server entries use the .mjs filenames their hosts require.\n platform: 'node',\n outExtensions: ({ format }) => ({\n js: format === 'es' ? '.mjs' : '.cjs',\n dts: format === 'es' ? '.d.mts' : '.d.cts',\n }),\n sourcemap: true,\n };\n\n // Contract bundles are published as a self-contained graph. Normal extension\n // entries remain unbundled for routed runtime resources, while MCP remains\n // isolated from the shared dist directory.\n const node = (entries: Record<string, string>, _unbundle: boolean): PresetConfig => ({\n ...baseNode,\n entry: entries,\n // Public entry facades must remain bundled. Otherwise their relative\n // imports target unbundled implementation chunks, which Vite treats as\n // source files when resolving a workspace package.\n unbundle: false,\n hooks: {\n 'build:done': () => {\n if (mcpOnly) {\n writeMcpManifest(\n packageDir,\n result.targets.includes('mcp'),\n renderMcpWidgets(result.graph, result.packageName, GENERATED_DIR).names,\n );\n return;\n }\n writeManifest({\n packageDir,\n manifest: JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as Record<\n string,\n unknown\n >,\n graph: result.graph,\n targets: result.targets,\n pluginId: result.pluginId,\n });\n },\n },\n });\n const unsyncedNode = (entries: Record<string, string>, unbundle: boolean): PresetConfig => ({\n ...baseNode,\n entry: entries,\n unbundle,\n });\n const configs =\n !mcpOnly && API_CONTRACTS_ENTRY in entry && Object.keys(entry).length > 1\n ? [\n unsyncedNode({ [API_CONTRACTS_ENTRY]: entry[API_CONTRACTS_ENTRY] }, false),\n node(Object.fromEntries(Object.entries(entry).filter(([name]) => name !== API_CONTRACTS_ENTRY)), true),\n ]\n : [node(entry, !mcpOnly)];\n if (mcpOnly && result.files.has(`${GENERATED_DIR}/mcp-ui.ts`)) return [...configs, browserConfig('mcp-ui')];\n const frontends: (BrowserPresetConfig | NativePresetConfig)[] = mcpOnly\n ? []\n : [\n ...(result.targets.includes('web') ? [browserConfig()] : []),\n ...(result.targets.includes('native') ? [nativeConfig(packageDir)] : []),\n ];\n if (frontends.length > 0) {\n if (Object.keys(entry).length > 0) return [...configs, ...frontends];\n // No node entry to carry the manifest sync, so the first frontend build does.\n const [first, ...rest] = frontends;\n return [{ ...first!, hooks: configs[0]!.hooks }, ...rest];\n }\n return configs.length === 1 ? configs[0]! : configs;\n}\n"],"mappings":"oVAwEA,MAAMc,EAAsB,cACtBC,EAAsB,eAG5B,SAASC,EAAc,EAAoB,EAA4C,CACrF,IAAMC,EAAWjB,EAAAA,QAAK,KAAKkB,EAAYC,CAAU,EACjD,GAAI,CAAClB,EAAAA,QAAG,WAAWgB,CAAQ,EAAG,MAAO,CAAC,EACtC,IAAMG,EAAkC,CAAC,EACzC,IAAK,IAAMC,KAAQpB,EAAAA,QAAG,YAAYgB,CAAQ,EAAG,CAC3C,GAAI,CAACI,EAAK,SAAS,KAAK,GAAKA,EAAK,SAAS,OAAO,EAAG,SACrD,IAAMC,EAAOD,EAAK,MAAM,EAAG,EAAa,EACxC,EAAQC,GAAQ,GAAGH,EAAW,GAAGE,GACnC,CACA,OAA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,EAAI,CAACP,EAAa1B,CAAU,CAAC,EAAI,CAAC,CACxE,EACJ,GAAI8C,EAAU,OAAS,EAAG,CACxB,GAAI,OAAO,KAAKR,CAAK,CAAC,CAAC,OAAS,EAAG,MAAO,CAAC,GAAGO,EAAS,GAAGC,CAAS,EAEnE,GAAM,CAACC,EAAO,GAAGC,GAAQF,EACzB,MAAO,CAAC,CAAE,GAAGC,EAAQ,MAAOF,EAAQ,EAAE,CAAE,KAAM,EAAG,GAAGG,CAAI,CAC1D,CACA,OAAOH,EAAQ,SAAW,EAAIA,EAAQ,GAAMA,CAC9C"}
@@ -70,6 +70,13 @@ interface PresetConfig extends BasePresetConfig {
70
70
  'build:done': () => void;
71
71
  };
72
72
  }
73
+ /**
74
+ * Source file behind each published subpath of a folder-routed extension, keyed like
75
+ * tsdown entries (`index`, `apiContracts`, `extensions/server`). Read from disk without
76
+ * regenerating, so `generated/server.ts` must already exist. The private Worker build
77
+ * uses this to bundle workspace sources instead of `dist/`.
78
+ */
79
+ export declare function extensionSourceEntries(packageDir: string, exportsDir?: string): Record<string, string>;
73
80
  /**
74
81
  * One tsdown config for a folder-routed extension.
75
82
  *
@@ -86,4 +93,5 @@ export interface ExtensionPresetOptions extends GenerateOptions {
86
93
  }
87
94
  export declare function poExtension(options?: ExtensionPresetOptions): PresetConfig | (PresetConfig | BrowserPresetConfig | NativePresetConfig)[];
88
95
  //#endregion
96
+ export {};
89
97
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/tsdownPreset/index.ts"],"mappings":";;;UAWU;WACC;WACA;WACA;WACA,SAAS;;UAGV;WACC;EACT,UAAU,gBAAgB;EAC1B,KAAK;IAAQ,SAAS,MAAM;KAAwB;;;UAI5C;EACR,OAAO;EACP;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX,SAAS;EACT;EACA;EACA;EACA,QAAQ;;;UAIA,2BAA2B,KAAK;EACxC;EACA,SAAS;;UAGD;EACR,gBAAgB,SAAS,4BAA4B;;UAG7C;EACR,OAAO;EACP;EACA;IAAe;IAAsB;IAAmB;;EACxD;EACA,UAAU;EACV,mBAAmB;EACnB;IAAU,KAAK;IAAuB;MAAO;;;EAC7C;EACA;EACA;EACA,kBAAkB;IAAY;;IAC5B;IACA;;;UAIM,qBAAqB;EAC7B;IAAU;;;;;;;;;;;iBA4DK,+BAA+B;;WAErC,QAAQ;;WAER;;wBAiHK,YACd,UAAS,yBACR,gBAAgB,eAAe,sBAAsB"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/services/tsdownPreset/index.ts"],"mappings":";;;UAWU;WACC;WACA;WACA;WACA,SAAS;;UAGV;WACC;EACT,UAAU,gBAAgB;EAC1B,KAAK;IAAQ,SAAS,MAAM;KAAwB;;;UAI5C;EACR,OAAO;EACP;EACA;EACA;EACA;EACA;EACA;EACA,WAAW;EACX,SAAS;EACT;EACA;EACA;EACA,QAAQ;;;UAIA,2BAA2B,KAAK;EACxC;EACA,SAAS;;UAGD;EACR,gBAAgB,SAAS,4BAA4B;;UAG7C;EACR,OAAO;EACP;EACA;IAAe;IAAsB;IAAmB;;EACxD;EACA,UAAU;EACV,mBAAmB;EACnB;IAAU,KAAK;IAAuB;MAAO;;;EAC7C;EACA;EACA;EACA,kBAAkB;IAAY;;IAC5B;IACA;;;UAIM,qBAAqB;EAC7B;IAAU;;;;;;;;;wBAyBI,uBACd,oBACA,sBACC;;;;;;;;;iBAiDc,+BAA+B;;WAErC,QAAQ;;WAER;;wBAuHK,YACd,UAAS,yBACR,gBAAgB,eAAe,sBAAsB"}
@@ -1,2 +1,2 @@
1
- import{GENERATED_DIR as e}from"../../constants/layout.mjs";import{renderMcpWidgets as t}from"../renderMcpWidgets/index.mjs";import{generateExtension as n}from"../generate/index.mjs";import{writeManifest as r,writeMcpManifest as i}from"../syncManifest/index.mjs";import{unistylesBabel as a}from"../unistylesBabel/index.mjs";import o from"node:fs";import s from"node:path";const c=`apiContracts`;function l(e,t){let n=s.join(e,t);if(!o.existsSync(n))return{};let r={};for(let e of o.readdirSync(n)){if(!e.endsWith(`.ts`)||e.endsWith(`.d.ts`))continue;let n=e.slice(0,-3);r[n]=`${t}/${e}`}return r}function u(e,t,n){let r=s.join(e,t);if(!o.existsSync(r))return{};let i={};for(let e of o.readdirSync(r,{encoding:`utf8`,recursive:!0})){if(!n(e))continue;let r=e.split(s.sep).join(`/`);i[`./${t}/${r}`]=`./${t}/${r}`}return i}function d(e){let t=JSON.parse(o.readFileSync(s.join(e,`package.json`),`utf8`)),n=t.exports!==null&&typeof t.exports==`object`&&!Array.isArray(t.exports)?Object.fromEntries(Object.entries(t.exports).filter(([,e])=>typeof e==`string`)):{};return{...u(e,`skills`,e=>s.basename(e)===`SKILL.md`),...u(e,`themes`,e=>e.endsWith(`.json`)),...n}}function f(){return{name:`po-query-assets`,resolveId(e,t){let n=e.indexOf(`?`);if(n<0||t===void 0||!e.startsWith(`.`))return;let r=t.split(`?`)[0];return`${s.resolve(s.dirname(r),e.slice(0,n))}${e.slice(n)}`},load(e){let t=e.indexOf(`?`);if(t<0)return;let n=e.slice(0,t),r=new URLSearchParams(e.slice(t+1));if(!r.has(`url`))return;let i=r.has(`worker`);return`export default import.meta.ROLLUP_FILE_URL_${this.emitFile(i?{type:`chunk`,id:n,name:s.basename(n,s.extname(n))}:{type:`asset`,name:s.basename(n),source:o.readFileSync(n)})};`}}}function p(t=`web`){return{entry:{[`extensions/${t}`]:`${e}/${t}.ts`},clean:!1,dts:!1,exports:!1,format:[`esm`],platform:`browser`,fixedExtension:!0,external:e=>!e.startsWith(`.`)&&!s.isAbsolute(e),plugins:[f()],sourcemap:!0,unbundle:!1,tsconfig:t===`web`?`tsconfig.web.json`:`tsconfig.mcp.json`}}function m(t){return{entry:{"extensions/native":`${e}/native.ts`},clean:!1,dts:!1,exports:!1,format:[`esm`],platform:`neutral`,fixedExtension:!0,external:e=>!e.startsWith(`.`)&&!s.isAbsolute(e),plugins:[a(t)],sourcemap:!0,unbundle:!1,tsconfig:`tsconfig.native.json`}}function h(e){let t=s.join(e,`dist`);if(o.existsSync(t))for(let e of o.readdirSync(t,{recursive:!0,encoding:`utf8`})){let n=e.split(s.sep).join(`/`);if(!/^(?:extensions\/mcp(?:-ui)?|.+\.mcp)\.(?:mjs|cjs|d\.mts|d\.cts)(?:\.map)?$/u.test(n))continue;let r=s.join(t,e);o.lstatSync(r).isFile()&&o.rmSync(r)}}function g(a={packageDir:process.cwd()}){let u=a.packageDir??process.cwd(),f=n({...a,packageDir:u,check:a.check??!1});for(let e of f.notices)process.stderr.write(`[po-build] ${e.path}: ${e.message}\n`);let g=a.target===`mcp`;g&&!a.check&&h(u);let _=g&&!f.targets.includes(`mcp`),v=`\0po-empty-mcp`;_&&!a.check&&i(u,!1);let y=g?f.targets.includes(`mcp`)?{"extensions/mcp":`${e}/mcp.ts`}:{"extensions/mcp":v}:{...l(u,a.exportsDir??`src/exports`),...f.targets.includes(`server`)?{"extensions/server":`${e}/server.ts`}:{},...a.entry},b={clean:!1,dts:!_&&{incremental:!0,parallel:!1,eager:!0},..._?{write:!1,plugins:[{name:`po-empty-mcp`,resolveId:e=>e===v?v:void 0,load:e=>e===v?`export {};`:void 0}]}:{},exports:!g&&{customExports:e=>{let t=Object.keys(y),n=t[0];return{...d(u),...e,...t.length===1&&n!==void 0&&n!==`index`&&!n.startsWith(`extensions/`)?{[`./${n}`]:e[`.`]}:{}}}},format:{esm:{},cjs:{dts:!1}},platform:`node`,outExtensions:({format:e})=>({js:e===`es`?`.mjs`:`.cjs`,dts:e===`es`?`.d.mts`:`.d.cts`}),sourcemap:!0},x=(n,a)=>({...b,entry:n,unbundle:!1,hooks:{"build:done":()=>{if(g){i(u,f.targets.includes(`mcp`),t(f.graph,f.packageName,e).names);return}r({packageDir:u,manifest:JSON.parse(o.readFileSync(s.join(u,`package.json`),`utf8`)),graph:f.graph,targets:f.targets,pluginId:f.pluginId})}}}),S=!g&&c in y&&Object.keys(y).length>1?[((e,t)=>({...b,entry:e,unbundle:t}))({[c]:y[c]},!1),x(Object.fromEntries(Object.entries(y).filter(([e])=>e!==c)),!0)]:[x(y,!g)];if(g&&f.files.has(`generated/mcp-ui.ts`))return[...S,p(`mcp-ui`)];let C=g?[]:[...f.targets.includes(`web`)?[p()]:[],...f.targets.includes(`native`)?[m(u)]:[]];if(C.length>0){if(Object.keys(y).length>0)return[...S,...C];let[e,...t]=C;return[{...e,hooks:S[0].hooks},...t]}return S.length===1?S[0]:S}export{g as poExtension};
1
+ import{GENERATED_DIR as e}from"../../constants/layout.mjs";import{renderMcpWidgets as t}from"../renderMcpWidgets/index.mjs";import{generateExtension as n}from"../generate/index.mjs";import{writeManifest as r,writeMcpManifest as i}from"../syncManifest/index.mjs";import{unistylesBabel as a}from"../unistylesBabel/index.mjs";import o from"node:fs";import s from"node:path";const c=`src/exports`,l=`apiContracts`;function u(e,t){let n=s.join(e,t);if(!o.existsSync(n))return{};let r={};for(let e of o.readdirSync(n)){if(!e.endsWith(`.ts`)||e.endsWith(`.d.ts`))continue;let n=e.slice(0,-3);r[n]=`${t}/${e}`}return r}function d(t,n=c){let r=`${e}/server.ts`;return{...u(t,n),...o.existsSync(s.join(t,r))?{"extensions/server":r}:{}}}function f(e,t,n){let r=s.join(e,t);if(!o.existsSync(r))return{};let i={};for(let e of o.readdirSync(r,{encoding:`utf8`,recursive:!0})){if(!n(e))continue;let r=e.split(s.sep).join(`/`);i[`./${t}/${r}`]=`./${t}/${r}`}return i}function p(e){let t=JSON.parse(o.readFileSync(s.join(e,`package.json`),`utf8`)),n=t.exports!==null&&typeof t.exports==`object`&&!Array.isArray(t.exports)?Object.fromEntries(Object.entries(t.exports).filter(([,e])=>typeof e==`string`)):{};return{...f(e,`skills`,e=>s.basename(e)===`SKILL.md`),...f(e,`themes`,e=>e.endsWith(`.json`)),...n}}function m(){return{name:`po-query-assets`,resolveId(e,t){let n=e.indexOf(`?`);if(n<0||t===void 0||!e.startsWith(`.`))return;let r=t.split(`?`)[0];return`${s.resolve(s.dirname(r),e.slice(0,n))}${e.slice(n)}`},load(e){let t=e.indexOf(`?`);if(t<0)return;let n=e.slice(0,t),r=new URLSearchParams(e.slice(t+1));if(!r.has(`url`))return;let i=r.has(`worker`);return`export default import.meta.ROLLUP_FILE_URL_${this.emitFile(i?{type:`chunk`,id:n,name:s.basename(n,s.extname(n))}:{type:`asset`,name:s.basename(n),source:o.readFileSync(n)})};`}}}function h(t=`web`){return{entry:{[`extensions/${t}`]:`${e}/${t}.ts`},clean:!1,dts:!1,exports:!1,format:[`esm`],platform:`browser`,fixedExtension:!0,external:e=>!e.startsWith(`.`)&&!s.isAbsolute(e),plugins:[m()],sourcemap:!0,unbundle:!1,tsconfig:t===`web`?`tsconfig.web.json`:`tsconfig.mcp.json`}}function g(t){return{entry:{"extensions/native":`${e}/native.ts`},clean:!1,dts:!1,exports:!1,format:[`esm`],platform:`neutral`,fixedExtension:!0,external:e=>!e.startsWith(`.`)&&!s.isAbsolute(e),plugins:[a(t)],sourcemap:!0,unbundle:!1,tsconfig:`tsconfig.native.json`}}const _=/^(?:extensions\/mcp(?:-ui)?|.+\.mcp)\.(?:mjs|cjs|d\.mts|d\.cts)(?:\.map)?$/u;function v(e,t){let n=s.join(e,`dist`);if(o.existsSync(n))for(let e of o.readdirSync(n,{recursive:!0,encoding:`utf8`})){if(_.test(e.split(s.sep).join(`/`))!==(t===`mcp`))continue;let r=s.join(n,e);o.lstatSync(r,{throwIfNoEntry:!1})?.isFile()&&o.rmSync(r)}}function y(a={packageDir:process.cwd()}){let d=a.packageDir??process.cwd(),f=n({...a,packageDir:d,check:a.check??!1});for(let e of f.notices)process.stderr.write(`[po-build] ${e.path}: ${e.message}\n`);let m=a.target===`mcp`;a.check||v(d,m?`mcp`:`normal`);let _=m&&!f.targets.includes(`mcp`),y=`\0po-empty-mcp`;_&&!a.check&&i(d,!1);let b=m?f.targets.includes(`mcp`)?{"extensions/mcp":`${e}/mcp.ts`}:{"extensions/mcp":y}:{...u(d,a.exportsDir??c),...f.targets.includes(`server`)?{"extensions/server":`${e}/server.ts`}:{},...a.entry},x={clean:!1,dts:!_&&{incremental:!0,parallel:!1,eager:!0},..._?{write:!1,plugins:[{name:`po-empty-mcp`,resolveId:e=>e===y?y:void 0,load:e=>e===y?`export {};`:void 0}]}:{},exports:!m&&{customExports:e=>{let t=Object.keys(b),n=t[0];return{...p(d),...e,...t.length===1&&n!==void 0&&n!==`index`&&!n.startsWith(`extensions/`)?{[`./${n}`]:e[`.`]}:{}}}},format:{esm:{},cjs:{dts:!1}},platform:`node`,outExtensions:({format:e})=>({js:e===`es`?`.mjs`:`.cjs`,dts:e===`es`?`.d.mts`:`.d.cts`}),sourcemap:!0},S=(n,a)=>({...x,entry:n,unbundle:!1,hooks:{"build:done":()=>{m?i(d,f.targets.includes(`mcp`),t(f.graph,f.packageName,e).names):r({packageDir:d,manifest:JSON.parse(o.readFileSync(s.join(d,`package.json`),`utf8`)),graph:f.graph,targets:f.targets,pluginId:f.pluginId})}}}),C=!m&&l in b&&Object.keys(b).length>1?[((e,t)=>({...x,entry:e,unbundle:t}))({[l]:b[l]},!1),S(Object.fromEntries(Object.entries(b).filter(([e])=>e!==l)),!0)]:[S(b,!m)];if(m&&f.files.has(`generated/mcp-ui.ts`))return[...C,h(`mcp-ui`)];let w=m?[]:[...f.targets.includes(`web`)?[h()]:[],...f.targets.includes(`native`)?[g(d)]:[]];if(w.length>0){if(Object.keys(b).length>0)return[...C,...w];let[e,...t]=w;return[{...e,hooks:C[0].hooks},...t]}return C.length===1?C[0]:C}export{d as extensionSourceEntries,y as poExtension};
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["fs","path","API_CONTRACTS_ENTRY","exportEntries","absolute","packageDir","exportsDir","entries","file","stem","resourceEntries","root","directory","relative","matches","normalized","staticExports","manifest","declared","target","queryAssetPlugin","queryAt","source","importer","importerFile","id","query","worker","browserConfig","GENERATED_DIR","nativeConfig","unistylesBabel","cleanMcpOutput","dist","poExtension","options","result","generateExtension","notice","mcpOnly","emptyMcp","emptyEntry","writeMcpManifest","entry","baseNode","names","name","generated","format","node","renderMcpWidgets","writeManifest","configs","frontends","first","rest"],"sources":["../../../src/services/tsdownPreset/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { GENERATED_DIR } from '../../constants/layout';\nimport { generateExtension } from '../generate';\nimport type { GenerateOptions } from '../generate/type';\nimport { renderMcpWidgets } from '../renderMcpWidgets';\nimport { writeManifest, writeMcpManifest } from '../syncManifest';\nimport { unistylesBabel } from '../unistylesBabel';\nimport type { UnistylesBabelPlugin } from '../unistylesBabel/type';\n\ninterface EmittedFile {\n readonly type: 'asset' | 'chunk';\n readonly id?: string;\n readonly name: string;\n readonly source?: Buffer;\n}\n\ninterface QueryAssetPlugin {\n readonly name: string;\n resolveId(source: string, importer: string | undefined): string | undefined;\n load(this: { emitFile(file: EmittedFile): string }, id: string): string | undefined;\n}\n\n/** The shape a tsdown config needs from this preset, without importing tsdown's types. */\ninterface BrowserPresetConfig {\n entry: Record<string, string>;\n clean: boolean;\n dts: false;\n exports: boolean;\n format: 'esm'[];\n platform: 'browser';\n fixedExtension: boolean;\n external: (id: string) => boolean;\n plugins: QueryAssetPlugin[];\n sourcemap: boolean;\n unbundle: boolean;\n tsconfig: string;\n hooks?: PresetConfig['hooks'];\n}\n\n/** The separately bundled native half, shaped like the browser one. */\ninterface NativePresetConfig extends Omit<BrowserPresetConfig, 'platform' | 'plugins'> {\n platform: 'neutral';\n plugins: UnistylesBabelPlugin[];\n}\n\ninterface GeneratedExports {\n customExports: (exports: Record<string, unknown>) => Record<string, unknown>;\n}\n\ninterface BasePresetConfig {\n entry: Record<string, string>;\n clean: boolean;\n dts: false | { incremental: boolean; parallel: boolean; eager: boolean };\n write?: false;\n plugins?: QueryAssetPlugin[];\n exports: boolean | GeneratedExports;\n format: { esm: Record<string, never>; cjs: { dts: false } };\n platform: 'node';\n sourcemap: boolean;\n unbundle: boolean;\n outExtensions: ({ format }: { format: string }) => {\n js: string;\n dts: string;\n };\n}\n\ninterface PresetConfig extends BasePresetConfig {\n hooks?: { 'build:done': () => void };\n}\n\nconst DEFAULT_EXPORTS_DIR = 'src/exports';\nconst API_CONTRACTS_ENTRY = 'apiContracts';\n\n/** `src/exports/apiContracts.ts` becomes the `apiContracts` entry; index keeps its name. */\nfunction exportEntries(packageDir: string, exportsDir: string): Record<string, string> {\n const absolute = path.join(packageDir, exportsDir);\n if (!fs.existsSync(absolute)) return {};\n const entries: Record<string, string> = {};\n for (const file of fs.readdirSync(absolute)) {\n if (!file.endsWith('.ts') || file.endsWith('.d.ts')) continue;\n const stem = file.slice(0, -'.ts'.length);\n entries[stem] = `${exportsDir}/${file}`;\n }\n return entries;\n}\n\n/** Static resources receive package export entries without becoming tsdown inputs. */\nfunction resourceEntries(\n packageDir: string,\n directory: string,\n matches: (relative: string) => boolean,\n): Record<string, string> {\n const root = path.join(packageDir, directory);\n if (!fs.existsSync(root)) return {};\n const entries: Record<string, string> = {};\n for (const relative of fs.readdirSync(root, { encoding: 'utf8', recursive: true })) {\n if (!matches(relative)) continue;\n const normalized = relative.split(path.sep).join('/');\n entries[`./${directory}/${normalized}`] = `./${directory}/${normalized}`;\n }\n return entries;\n}\n\n/** Preserves declared resources and discovers default skill and theme resource exports. */\nfunction staticExports(packageDir: string): Record<string, unknown> {\n const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as Record<\n string,\n unknown\n >;\n const declared =\n manifest.exports !== null && typeof manifest.exports === 'object' && !Array.isArray(manifest.exports)\n ? Object.fromEntries(Object.entries(manifest.exports).filter(([, target]) => typeof target === 'string'))\n : {};\n return {\n ...resourceEntries(packageDir, 'skills', (relative) => path.basename(relative) === 'SKILL.md'),\n ...resourceEntries(packageDir, 'themes', (relative) => relative.endsWith('.json')),\n ...declared,\n };\n}\n/**\n * One tsdown config for a folder-routed extension.\n *\n * Entries come from the tree rather than a hand-written list, and the manifest\n * blocks that restate the tree are written after the build rather than kept in\n * step by hand. Browser contributions are emitted through a second bundled\n * config because their routed source is not published.\n */\nexport interface ExtensionPresetOptions extends GenerateOptions {\n /** Extra tsdown entries beyond the derived ones. */\n readonly entry?: Record<string, string>;\n /** Public export modules, package-relative. Defaults to `src/exports`. */\n readonly exportsDir?: string;\n}\n\n/**\n * Implements the Vite query imports extension browser code already uses.\n *\n * `?url` copies an opaque asset and `?worker&url` emits a separately bundled\n * worker chunk. Rolldown then replaces its file reference with an URL relative\n * to the extension bundle, which remains valid when the cockpit composes it.\n */\nfunction queryAssetPlugin(): QueryAssetPlugin {\n return {\n name: 'po-query-assets',\n resolveId(source, importer) {\n const queryAt = source.indexOf('?');\n if (queryAt < 0 || importer === undefined || !source.startsWith('.')) return undefined;\n const importerFile = importer.split('?')[0] as string;\n return `${path.resolve(path.dirname(importerFile), source.slice(0, queryAt))}${source.slice(queryAt)}`;\n },\n load(id) {\n const queryAt = id.indexOf('?');\n if (queryAt < 0) return undefined;\n const file = id.slice(0, queryAt);\n const query = new URLSearchParams(id.slice(queryAt + 1));\n if (!query.has('url')) return undefined;\n const worker = query.has('worker');\n const reference = this.emitFile(\n worker\n ? { type: 'chunk', id: file, name: path.basename(file, path.extname(file)) }\n : { type: 'asset', name: path.basename(file), source: fs.readFileSync(file) },\n );\n return `export default import.meta.ROLLUP_FILE_URL_${reference};`;\n },\n };\n}\n\n/** The separately bundled browser half of a routed extension. */\nfunction browserConfig(target: 'web' | 'mcp-ui' = 'web'): BrowserPresetConfig {\n return {\n entry: { [`extensions/${target}`]: `${GENERATED_DIR}/${target}.ts` },\n clean: false,\n // No declarations. Nothing imports this as a typed module: it has no\n // export subpath, and the cockpit consumes it as a bundle. The browser\n // half is still typechecked, by tsconfig.web.json in the typecheck script.\n dts: false,\n exports: false,\n format: ['esm'],\n platform: 'browser',\n // platform browser turns tsdown's fixedExtension off, which would emit\n // .js. The manifest names .mjs like the other two entries, so ask for it.\n fixedExtension: true,\n // Every bare specifier stays external and the cockpit resolves it, which\n // is what keeps one React and one store in the page no matter how many\n // plugins are installed. An allowlist would have to be kept in step with\n // the cockpit's; this cannot drift.\n //\n // A predicate rather than a pattern: rolldown tests `external` against the\n // resolved id, so /^[^.]/ also matches the absolute path of this package's\n // own routed file and would leave a dangling import to unbuilt .tsx.\n external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),\n plugins: [queryAssetPlugin()],\n sourcemap: true,\n // Bundled, unlike the node half. Unbundling would emit an import to the\n // routed source file, which is not published and is .tsx besides. One\n // module with only bare specifiers external is what the cockpit wants.\n unbundle: false,\n // Browser routes are excluded from the node tsconfig. Every browser-capable\n // extension owns this focused config for its matching typecheck.\n tsconfig: target === 'web' ? 'tsconfig.web.json' : 'tsconfig.mcp.json',\n };\n}\n\n/**\n * The separately bundled native half of a routed extension.\n *\n * Neutral rather than browser: React Native has neither the DOM nor Node, so\n * no condition set fits it better, and every bare specifier stays external\n * anyway. The CLI bundles this module into the signed composition and refuses\n * any import outside the native host module list, so nothing here has to.\n */\nfunction nativeConfig(packageDir: string): NativePresetConfig {\n return {\n entry: { 'extensions/native': `${GENERATED_DIR}/native.ts` },\n clean: false,\n dts: false,\n exports: false,\n format: ['esm'],\n platform: 'neutral',\n fixedExtension: true,\n // The same predicate as the browser half, for the same reason: the host\n // supplies React, React Native and Unistyles, one copy each.\n external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),\n plugins: [unistylesBabel(packageDir)],\n sourcemap: true,\n unbundle: false,\n // Native routes import react-native, which the DOM-typed web config must\n // not see, so they typecheck under their own config.\n tsconfig: 'tsconfig.native.json',\n };\n}\n\n/** Removes only filenames owned by the isolated MCP build, including obsolete declarations. */\nfunction cleanMcpOutput(packageDir: string): void {\n const dist = path.join(packageDir, 'dist');\n if (!fs.existsSync(dist)) return;\n for (const relative of fs.readdirSync(dist, { recursive: true, encoding: 'utf8' })) {\n const normalized = relative.split(path.sep).join('/');\n if (!/^(?:extensions\\/mcp(?:-ui)?|.+\\.mcp)\\.(?:mjs|cjs|d\\.mts|d\\.cts)(?:\\.map)?$/u.test(normalized)) continue;\n const absolute = path.join(dist, relative);\n if (fs.lstatSync(absolute).isFile()) fs.rmSync(absolute);\n }\n}\n\nexport function poExtension(\n options: ExtensionPresetOptions = { packageDir: process.cwd() },\n): PresetConfig | (PresetConfig | BrowserPresetConfig | NativePresetConfig)[] {\n const packageDir = options.packageDir ?? process.cwd();\n const result = generateExtension({ ...options, packageDir, check: options.check ?? false });\n\n for (const notice of result.notices) process.stderr.write(`[po-build] ${notice.path}: ${notice.message}\\n`);\n\n const mcpOnly = options.target === 'mcp';\n if (mcpOnly && !options.check) cleanMcpOutput(packageDir);\n const emptyMcp = mcpOnly && !result.targets.includes('mcp');\n const emptyEntry = '\\0po-empty-mcp';\n if (emptyMcp && !options.check) writeMcpManifest(packageDir, false);\n const entry: Record<string, string> = mcpOnly\n ? result.targets.includes('mcp')\n ? { 'extensions/mcp': `${GENERATED_DIR}/mcp.ts` }\n : { 'extensions/mcp': emptyEntry }\n : {\n ...exportEntries(packageDir, options.exportsDir ?? DEFAULT_EXPORTS_DIR),\n ...(result.targets.includes('server') ? { 'extensions/server': `${GENERATED_DIR}/server.ts` } : {}),\n ...options.entry,\n };\n\n const baseNode: Omit<BasePresetConfig, 'entry' | 'unbundle'> = {\n // MCP shares dist/ with the normal build, so neither build may erase the other.\n clean: false,\n dts: emptyMcp ? false : { incremental: true, parallel: false, eager: true },\n // tsdown rejects both an empty entry and an empty config array. A virtual\n // input completes its normal lifecycle without publishing an empty facet.\n ...(emptyMcp\n ? {\n write: false as const,\n plugins: [\n {\n name: 'po-empty-mcp',\n resolveId: (source: string) => (source === emptyEntry ? emptyEntry : undefined),\n load: (id: string) => (id === emptyEntry ? 'export {};' : undefined),\n },\n ],\n }\n : {}),\n exports: mcpOnly\n ? false\n : {\n customExports: (generated) => {\n const names = Object.keys(entry);\n const name = names[0];\n return {\n ...staticExports(packageDir),\n ...generated,\n ...(names.length === 1 && name !== undefined && name !== 'index' && !name.startsWith('extensions/')\n ? { [`./${name}`]: generated['.'] }\n : {}),\n };\n },\n },\n // CommonJS keeps its JavaScript but emits no declarations. Every export map\n // resolves types through .d.mts, and a CJS declaration build would rerun\n // the same whole-program tsgo emit a second time.\n format: { esm: {}, cjs: { dts: false } },\n // No minify. This is a library build, and a mangled stack trace inside a\n // published extension is far more expensive than the bytes it saves.\n // Native server entries use the .mjs filenames their hosts require.\n platform: 'node',\n outExtensions: ({ format }) => ({\n js: format === 'es' ? '.mjs' : '.cjs',\n dts: format === 'es' ? '.d.mts' : '.d.cts',\n }),\n sourcemap: true,\n };\n\n // Contract bundles are published as a self-contained graph. Normal extension\n // entries remain unbundled for routed runtime resources, while MCP remains\n // isolated from the shared dist directory.\n const node = (entries: Record<string, string>, _unbundle: boolean): PresetConfig => ({\n ...baseNode,\n entry: entries,\n // Public entry facades must remain bundled. Otherwise their relative\n // imports target unbundled implementation chunks, which Vite treats as\n // source files when resolving a workspace package.\n unbundle: false,\n hooks: {\n 'build:done': () => {\n if (mcpOnly) {\n writeMcpManifest(\n packageDir,\n result.targets.includes('mcp'),\n renderMcpWidgets(result.graph, result.packageName, GENERATED_DIR).names,\n );\n return;\n }\n writeManifest({\n packageDir,\n manifest: JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as Record<\n string,\n unknown\n >,\n graph: result.graph,\n targets: result.targets,\n pluginId: result.pluginId,\n });\n },\n },\n });\n const unsyncedNode = (entries: Record<string, string>, unbundle: boolean): PresetConfig => ({\n ...baseNode,\n entry: entries,\n unbundle,\n });\n const configs =\n !mcpOnly && API_CONTRACTS_ENTRY in entry && Object.keys(entry).length > 1\n ? [\n unsyncedNode({ [API_CONTRACTS_ENTRY]: entry[API_CONTRACTS_ENTRY] }, false),\n node(Object.fromEntries(Object.entries(entry).filter(([name]) => name !== API_CONTRACTS_ENTRY)), true),\n ]\n : [node(entry, !mcpOnly)];\n if (mcpOnly && result.files.has(`${GENERATED_DIR}/mcp-ui.ts`)) return [...configs, browserConfig('mcp-ui')];\n const frontends: (BrowserPresetConfig | NativePresetConfig)[] = mcpOnly\n ? []\n : [\n ...(result.targets.includes('web') ? [browserConfig()] : []),\n ...(result.targets.includes('native') ? [nativeConfig(packageDir)] : []),\n ];\n if (frontends.length > 0) {\n if (Object.keys(entry).length > 0) return [...configs, ...frontends];\n // No node entry to carry the manifest sync, so the first frontend build does.\n const [first, ...rest] = frontends;\n return [{ ...first!, hooks: configs[0]!.hooks }, ...rest];\n }\n return configs.length === 1 ? configs[0]! : configs;\n}\n"],"mappings":"mXAwEA,MACME,EAAsB,eAG5B,SAASC,EAAc,EAAoB,EAA4C,CACrF,IAAMC,EAAWH,EAAK,KAAKI,EAAYC,CAAU,EACjD,GAAI,CAACN,EAAG,WAAWI,CAAQ,EAAG,MAAO,CAAC,EACtC,IAAMG,EAAkC,CAAC,EACzC,IAAK,IAAMC,KAAQR,EAAG,YAAYI,CAAQ,EAAG,CAC3C,GAAI,CAACI,EAAK,SAAS,KAAK,GAAKA,EAAK,SAAS,OAAO,EAAG,SACrD,IAAMC,EAAOD,EAAK,MAAM,EAAG,EAAa,EACxC,EAAQC,GAAQ,GAAGH,EAAW,GAAGE,GACnC,CACA,OAAOD,CACT,CAGA,SAASG,EACP,EACA,EACA,EACwB,CACxB,IAAMC,EAAOV,EAAK,KAAKI,EAAYO,CAAS,EAC5C,GAAI,CAACZ,EAAG,WAAWW,CAAI,EAAG,MAAO,CAAC,EAClC,IAAMJ,EAAkC,CAAC,EACzC,IAAK,IAAMM,KAAYb,EAAG,YAAYW,EAAM,CAAE,SAAU,OAAQ,UAAW,EAAK,CAAC,EAAG,CAClF,GAAI,CAACG,EAAQD,CAAQ,EAAG,SACxB,IAAME,EAAaF,EAAS,MAAMZ,EAAK,GAAG,CAAC,CAAC,KAAK,GAAG,EACpD,EAAQ,KAAKW,EAAU,GAAGG,KAAgB,KAAKH,EAAU,GAAGG,GAC9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,MAAM,IAAI,qBAA4B,EAAG,MAAO,CAAC,GAAGgB,EAASxB,EAAc,QAAQ,CAAC,EAC1G,IAAMyB,EAA0Dd,EAC5D,CAAC,EACD,CACE,GAAIH,EAAO,QAAQ,SAAS,KAAK,EAAI,CAACR,EAAc,CAAC,EAAI,CAAC,EAC1D,GAAIQ,EAAO,QAAQ,SAAS,QAAQ,EAAI,CAACN,EAAazB,CAAU,CAAC,EAAI,CAAC,CACxE,EACJ,GAAIgD,EAAU,OAAS,EAAG,CACxB,GAAI,OAAO,KAAKV,CAAK,CAAC,CAAC,OAAS,EAAG,MAAO,CAAC,GAAGS,EAAS,GAAGC,CAAS,EAEnE,GAAM,CAACC,EAAO,GAAGC,GAAQF,EACzB,MAAO,CAAC,CAAE,GAAGC,EAAQ,MAAOF,EAAQ,EAAE,CAAE,KAAM,EAAG,GAAGG,CAAI,CAC1D,CACA,OAAOH,EAAQ,SAAW,EAAIA,EAAQ,GAAMA,CAC9C"}
1
+ {"version":3,"file":"index.mjs","names":["fs","path","DEFAULT_EXPORTS_DIR","API_CONTRACTS_ENTRY","exportEntries","absolute","packageDir","exportsDir","entries","file","stem","extensionSourceEntries","server","GENERATED_DIR","resourceEntries","root","directory","relative","matches","normalized","staticExports","manifest","declared","target","queryAssetPlugin","queryAt","source","importer","importerFile","id","query","worker","browserConfig","nativeConfig","unistylesBabel","MCP_OUTPUT","cleanOutput","dist","owner","poExtension","options","result","generateExtension","notice","mcpOnly","emptyMcp","emptyEntry","writeMcpManifest","entry","baseNode","names","name","generated","format","node","renderMcpWidgets","writeManifest","configs","frontends","first","rest"],"sources":["../../../src/services/tsdownPreset/index.ts"],"sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { GENERATED_DIR } from '../../constants/layout';\nimport { generateExtension } from '../generate';\nimport type { GenerateOptions } from '../generate/type';\nimport { renderMcpWidgets } from '../renderMcpWidgets';\nimport { writeManifest, writeMcpManifest } from '../syncManifest';\nimport { unistylesBabel } from '../unistylesBabel';\nimport type { UnistylesBabelPlugin } from '../unistylesBabel/type';\n\ninterface EmittedFile {\n readonly type: 'asset' | 'chunk';\n readonly id?: string;\n readonly name: string;\n readonly source?: Buffer;\n}\n\ninterface QueryAssetPlugin {\n readonly name: string;\n resolveId(source: string, importer: string | undefined): string | undefined;\n load(this: { emitFile(file: EmittedFile): string }, id: string): string | undefined;\n}\n\n/** The shape a tsdown config needs from this preset, without importing tsdown's types. */\ninterface BrowserPresetConfig {\n entry: Record<string, string>;\n clean: boolean;\n dts: false;\n exports: boolean;\n format: 'esm'[];\n platform: 'browser';\n fixedExtension: boolean;\n external: (id: string) => boolean;\n plugins: QueryAssetPlugin[];\n sourcemap: boolean;\n unbundle: boolean;\n tsconfig: string;\n hooks?: PresetConfig['hooks'];\n}\n\n/** The separately bundled native half, shaped like the browser one. */\ninterface NativePresetConfig extends Omit<BrowserPresetConfig, 'platform' | 'plugins'> {\n platform: 'neutral';\n plugins: UnistylesBabelPlugin[];\n}\n\ninterface GeneratedExports {\n customExports: (exports: Record<string, unknown>) => Record<string, unknown>;\n}\n\ninterface BasePresetConfig {\n entry: Record<string, string>;\n clean: boolean;\n dts: false | { incremental: boolean; parallel: boolean; eager: boolean };\n write?: false;\n plugins?: QueryAssetPlugin[];\n exports: boolean | GeneratedExports;\n format: { esm: Record<string, never>; cjs: { dts: false } };\n platform: 'node';\n sourcemap: boolean;\n unbundle: boolean;\n outExtensions: ({ format }: { format: string }) => {\n js: string;\n dts: string;\n };\n}\n\ninterface PresetConfig extends BasePresetConfig {\n hooks?: { 'build:done': () => void };\n}\n\nconst DEFAULT_EXPORTS_DIR = 'src/exports';\nconst API_CONTRACTS_ENTRY = 'apiContracts';\n\n/** `src/exports/apiContracts.ts` becomes the `apiContracts` entry; index keeps its name. */\nfunction exportEntries(packageDir: string, exportsDir: string): Record<string, string> {\n const absolute = path.join(packageDir, exportsDir);\n if (!fs.existsSync(absolute)) return {};\n const entries: Record<string, string> = {};\n for (const file of fs.readdirSync(absolute)) {\n if (!file.endsWith('.ts') || file.endsWith('.d.ts')) continue;\n const stem = file.slice(0, -'.ts'.length);\n entries[stem] = `${exportsDir}/${file}`;\n }\n return entries;\n}\n\n/**\n * Source file behind each published subpath of a folder-routed extension, keyed like\n * tsdown entries (`index`, `apiContracts`, `extensions/server`). Read from disk without\n * regenerating, so `generated/server.ts` must already exist. The private Worker build\n * uses this to bundle workspace sources instead of `dist/`.\n */\nexport function extensionSourceEntries(\n packageDir: string,\n exportsDir: string = DEFAULT_EXPORTS_DIR,\n): Record<string, string> {\n const server = `${GENERATED_DIR}/server.ts`;\n return {\n ...exportEntries(packageDir, exportsDir),\n ...(fs.existsSync(path.join(packageDir, server)) ? { 'extensions/server': server } : {}),\n };\n}\n\n/** Static resources receive package export entries without becoming tsdown inputs. */\nfunction resourceEntries(\n packageDir: string,\n directory: string,\n matches: (relative: string) => boolean,\n): Record<string, string> {\n const root = path.join(packageDir, directory);\n if (!fs.existsSync(root)) return {};\n const entries: Record<string, string> = {};\n for (const relative of fs.readdirSync(root, { encoding: 'utf8', recursive: true })) {\n if (!matches(relative)) continue;\n const normalized = relative.split(path.sep).join('/');\n entries[`./${directory}/${normalized}`] = `./${directory}/${normalized}`;\n }\n return entries;\n}\n\n/** Preserves declared resources and discovers default skill and theme resource exports. */\nfunction staticExports(packageDir: string): Record<string, unknown> {\n const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as Record<\n string,\n unknown\n >;\n const declared =\n manifest.exports !== null && typeof manifest.exports === 'object' && !Array.isArray(manifest.exports)\n ? Object.fromEntries(Object.entries(manifest.exports).filter(([, target]) => typeof target === 'string'))\n : {};\n return {\n ...resourceEntries(packageDir, 'skills', (relative) => path.basename(relative) === 'SKILL.md'),\n ...resourceEntries(packageDir, 'themes', (relative) => relative.endsWith('.json')),\n ...declared,\n };\n}\n/**\n * One tsdown config for a folder-routed extension.\n *\n * Entries come from the tree rather than a hand-written list, and the manifest\n * blocks that restate the tree are written after the build rather than kept in\n * step by hand. Browser contributions are emitted through a second bundled\n * config because their routed source is not published.\n */\nexport interface ExtensionPresetOptions extends GenerateOptions {\n /** Extra tsdown entries beyond the derived ones. */\n readonly entry?: Record<string, string>;\n /** Public export modules, package-relative. Defaults to `src/exports`. */\n readonly exportsDir?: string;\n}\n\n/**\n * Implements the Vite query imports extension browser code already uses.\n *\n * `?url` copies an opaque asset and `?worker&url` emits a separately bundled\n * worker chunk. Rolldown then replaces its file reference with an URL relative\n * to the extension bundle, which remains valid when the cockpit composes it.\n */\nfunction queryAssetPlugin(): QueryAssetPlugin {\n return {\n name: 'po-query-assets',\n resolveId(source, importer) {\n const queryAt = source.indexOf('?');\n if (queryAt < 0 || importer === undefined || !source.startsWith('.')) return undefined;\n const importerFile = importer.split('?')[0] as string;\n return `${path.resolve(path.dirname(importerFile), source.slice(0, queryAt))}${source.slice(queryAt)}`;\n },\n load(id) {\n const queryAt = id.indexOf('?');\n if (queryAt < 0) return undefined;\n const file = id.slice(0, queryAt);\n const query = new URLSearchParams(id.slice(queryAt + 1));\n if (!query.has('url')) return undefined;\n const worker = query.has('worker');\n const reference = this.emitFile(\n worker\n ? { type: 'chunk', id: file, name: path.basename(file, path.extname(file)) }\n : { type: 'asset', name: path.basename(file), source: fs.readFileSync(file) },\n );\n return `export default import.meta.ROLLUP_FILE_URL_${reference};`;\n },\n };\n}\n\n/** The separately bundled browser half of a routed extension. */\nfunction browserConfig(target: 'web' | 'mcp-ui' = 'web'): BrowserPresetConfig {\n return {\n entry: { [`extensions/${target}`]: `${GENERATED_DIR}/${target}.ts` },\n clean: false,\n // No declarations. Nothing imports this as a typed module: it has no\n // export subpath, and the cockpit consumes it as a bundle. The browser\n // half is still typechecked, by tsconfig.web.json in the typecheck script.\n dts: false,\n exports: false,\n format: ['esm'],\n platform: 'browser',\n // platform browser turns tsdown's fixedExtension off, which would emit\n // .js. The manifest names .mjs like the other two entries, so ask for it.\n fixedExtension: true,\n // Every bare specifier stays external and the cockpit resolves it, which\n // is what keeps one React and one store in the page no matter how many\n // plugins are installed. An allowlist would have to be kept in step with\n // the cockpit's; this cannot drift.\n //\n // A predicate rather than a pattern: rolldown tests `external` against the\n // resolved id, so /^[^.]/ also matches the absolute path of this package's\n // own routed file and would leave a dangling import to unbuilt .tsx.\n external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),\n plugins: [queryAssetPlugin()],\n sourcemap: true,\n // Bundled, unlike the node half. Unbundling would emit an import to the\n // routed source file, which is not published and is .tsx besides. One\n // module with only bare specifiers external is what the cockpit wants.\n unbundle: false,\n // Browser routes are excluded from the node tsconfig. Every browser-capable\n // extension owns this focused config for its matching typecheck.\n tsconfig: target === 'web' ? 'tsconfig.web.json' : 'tsconfig.mcp.json',\n };\n}\n\n/**\n * The separately bundled native half of a routed extension.\n *\n * Neutral rather than browser: React Native has neither the DOM nor Node, so\n * no condition set fits it better, and every bare specifier stays external\n * anyway. The CLI bundles this module into the signed composition and refuses\n * any import outside the native host module list, so nothing here has to.\n */\nfunction nativeConfig(packageDir: string): NativePresetConfig {\n return {\n entry: { 'extensions/native': `${GENERATED_DIR}/native.ts` },\n clean: false,\n dts: false,\n exports: false,\n format: ['esm'],\n platform: 'neutral',\n fixedExtension: true,\n // The same predicate as the browser half, for the same reason: the host\n // supplies React, React Native and Unistyles, one copy each.\n external: (id: string) => !id.startsWith('.') && !path.isAbsolute(id),\n plugins: [unistylesBabel(packageDir)],\n sourcemap: true,\n unbundle: false,\n // Native routes import react-native, which the DOM-typed web config must\n // not see, so they typecheck under their own config.\n tsconfig: 'tsconfig.native.json',\n };\n}\n\nconst MCP_OUTPUT = /^(?:extensions\\/mcp(?:-ui)?|.+\\.mcp)\\.(?:mjs|cjs|d\\.mts|d\\.cts)(?:\\.map)?$/u;\n\n/**\n * Removes files from dist that one build owns, so an entry deleted from the source tree does\n * not live on as a stale file (and in the Nx cache). The MCP build removes only its own files;\n * the normal build removes everything else and keeps the MCP files the other build wrote.\n */\nfunction cleanOutput(packageDir: string, owner: 'mcp' | 'normal'): void {\n const dist = path.join(packageDir, 'dist');\n if (!fs.existsSync(dist)) return;\n for (const relative of fs.readdirSync(dist, { recursive: true, encoding: 'utf8' })) {\n const isMcp = MCP_OUTPUT.test(relative.split(path.sep).join('/'));\n if (isMcp !== (owner === 'mcp')) continue;\n const absolute = path.join(dist, relative);\n if (fs.lstatSync(absolute, { throwIfNoEntry: false })?.isFile()) fs.rmSync(absolute);\n }\n}\n\nexport function poExtension(\n options: ExtensionPresetOptions = { packageDir: process.cwd() },\n): PresetConfig | (PresetConfig | BrowserPresetConfig | NativePresetConfig)[] {\n const packageDir = options.packageDir ?? process.cwd();\n const result = generateExtension({ ...options, packageDir, check: options.check ?? false });\n\n for (const notice of result.notices) process.stderr.write(`[po-build] ${notice.path}: ${notice.message}\\n`);\n\n const mcpOnly = options.target === 'mcp';\n // ponytail: the normal build cleans at config load, so it must run before the MCP build (every\n // build script does). Hashed assets of an mcp-ui bundle are not recognised and are rebuilt after.\n if (!options.check) cleanOutput(packageDir, mcpOnly ? 'mcp' : 'normal');\n const emptyMcp = mcpOnly && !result.targets.includes('mcp');\n const emptyEntry = '\\0po-empty-mcp';\n if (emptyMcp && !options.check) writeMcpManifest(packageDir, false);\n const entry: Record<string, string> = mcpOnly\n ? result.targets.includes('mcp')\n ? { 'extensions/mcp': `${GENERATED_DIR}/mcp.ts` }\n : { 'extensions/mcp': emptyEntry }\n : {\n ...exportEntries(packageDir, options.exportsDir ?? DEFAULT_EXPORTS_DIR),\n ...(result.targets.includes('server') ? { 'extensions/server': `${GENERATED_DIR}/server.ts` } : {}),\n ...options.entry,\n };\n\n const baseNode: Omit<BasePresetConfig, 'entry' | 'unbundle'> = {\n // MCP shares dist/ with the normal build, so neither build may erase the other.\n clean: false,\n dts: emptyMcp ? false : { incremental: true, parallel: false, eager: true },\n // tsdown rejects both an empty entry and an empty config array. A virtual\n // input completes its normal lifecycle without publishing an empty facet.\n ...(emptyMcp\n ? {\n write: false as const,\n plugins: [\n {\n name: 'po-empty-mcp',\n resolveId: (source: string) => (source === emptyEntry ? emptyEntry : undefined),\n load: (id: string) => (id === emptyEntry ? 'export {};' : undefined),\n },\n ],\n }\n : {}),\n exports: mcpOnly\n ? false\n : {\n customExports: (generated) => {\n const names = Object.keys(entry);\n const name = names[0];\n return {\n ...staticExports(packageDir),\n ...generated,\n ...(names.length === 1 && name !== undefined && name !== 'index' && !name.startsWith('extensions/')\n ? { [`./${name}`]: generated['.'] }\n : {}),\n };\n },\n },\n // CommonJS keeps its JavaScript but emits no declarations. Every export map\n // resolves types through .d.mts, and a CJS declaration build would rerun\n // the same whole-program tsgo emit a second time.\n format: { esm: {}, cjs: { dts: false } },\n // No minify. This is a library build, and a mangled stack trace inside a\n // published extension is far more expensive than the bytes it saves.\n // Native server entries use the .mjs filenames their hosts require.\n platform: 'node',\n outExtensions: ({ format }) => ({\n js: format === 'es' ? '.mjs' : '.cjs',\n dts: format === 'es' ? '.d.mts' : '.d.cts',\n }),\n sourcemap: true,\n };\n\n // Contract bundles are published as a self-contained graph. Normal extension\n // entries remain unbundled for routed runtime resources, while MCP remains\n // isolated from the shared dist directory.\n const node = (entries: Record<string, string>, _unbundle: boolean): PresetConfig => ({\n ...baseNode,\n entry: entries,\n // Public entry facades must remain bundled. Otherwise their relative\n // imports target unbundled implementation chunks, which Vite treats as\n // source files when resolving a workspace package.\n unbundle: false,\n hooks: {\n 'build:done': () => {\n if (mcpOnly) {\n writeMcpManifest(\n packageDir,\n result.targets.includes('mcp'),\n renderMcpWidgets(result.graph, result.packageName, GENERATED_DIR).names,\n );\n return;\n }\n writeManifest({\n packageDir,\n manifest: JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8')) as Record<\n string,\n unknown\n >,\n graph: result.graph,\n targets: result.targets,\n pluginId: result.pluginId,\n });\n },\n },\n });\n const unsyncedNode = (entries: Record<string, string>, unbundle: boolean): PresetConfig => ({\n ...baseNode,\n entry: entries,\n unbundle,\n });\n const configs =\n !mcpOnly && API_CONTRACTS_ENTRY in entry && Object.keys(entry).length > 1\n ? [\n unsyncedNode({ [API_CONTRACTS_ENTRY]: entry[API_CONTRACTS_ENTRY] }, false),\n node(Object.fromEntries(Object.entries(entry).filter(([name]) => name !== API_CONTRACTS_ENTRY)), true),\n ]\n : [node(entry, !mcpOnly)];\n if (mcpOnly && result.files.has(`${GENERATED_DIR}/mcp-ui.ts`)) return [...configs, browserConfig('mcp-ui')];\n const frontends: (BrowserPresetConfig | NativePresetConfig)[] = mcpOnly\n ? []\n : [\n ...(result.targets.includes('web') ? [browserConfig()] : []),\n ...(result.targets.includes('native') ? [nativeConfig(packageDir)] : []),\n ];\n if (frontends.length > 0) {\n if (Object.keys(entry).length > 0) return [...configs, ...frontends];\n // No node entry to carry the manifest sync, so the first frontend build does.\n const [first, ...rest] = frontends;\n return [{ ...first!, hooks: configs[0]!.hooks }, ...rest];\n }\n return configs.length === 1 ? configs[0]! : configs;\n}\n"],"mappings":"mXAwEA,MAAME,EAAsB,cACtBC,EAAsB,eAG5B,SAASC,EAAc,EAAoB,EAA4C,CACrF,IAAMC,EAAWJ,EAAK,KAAKK,EAAYC,CAAU,EACjD,GAAI,CAACP,EAAG,WAAWK,CAAQ,EAAG,MAAO,CAAC,EACtC,IAAMG,EAAkC,CAAC,EACzC,IAAK,IAAMC,KAAQT,EAAG,YAAYK,CAAQ,EAAG,CAC3C,GAAI,CAACI,EAAK,SAAS,KAAK,GAAKA,EAAK,SAAS,OAAO,EAAG,SACrD,IAAMC,EAAOD,EAAK,MAAM,EAAG,EAAa,EACxC,EAAQC,GAAQ,GAAGH,EAAW,GAAGE,GACnC,CACA,OAAOD,CACT,CAQA,SAAgBG,EACd,EACA,EAAqBT,EACG,CACxB,IAAMU,EAAS,GAAGC,EAAc,YAChC,MAAO,CACL,GAAGT,EAAcE,EAAYC,CAAU,EACvC,GAAIP,EAAG,WAAWC,EAAK,KAAKK,EAAYM,CAAM,CAAC,EAAI,CAAE,oBAAqBA,CAAO,EAAI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AAG,MAAM,CAAC,EAInF,MAAOmC,EAAO,MACd,QAASA,EAAO,QAChB,SAAUA,EAAO,QACnB,CAAC,CACH,CACF,CACF,GAMMgB,EACJ,CAACb,GAAWzC,KAAuB6C,GAAS,OAAO,KAAKA,CAAK,CAAC,CAAC,OAAS,EACpE,GAPgB,EAAiC,KAAqC,CAC1F,GAAGC,EACH,MAAOzC,EACP,UACF,GAIQ,CAAa,EAAGL,GAAsB6C,EAAM7C,EAAqB,EAAG,EAAK,EACzEmD,EAAK,OAAO,YAAY,OAAO,QAAQN,CAAK,CAAC,CAAC,QAAQ,CAACG,KAAUA,IAAShD,CAAmB,CAAC,EAAG,EAAI,CACvG,EACA,CAACmD,EAAKN,EAAO,CAACJ,CAAO,CAAC,EAC5B,GAAIA,GAAWH,EAAO,MAAM,IAAI,qBAA4B,EAAG,MAAO,CAAC,GAAGgB,EAASzB,EAAc,QAAQ,CAAC,EAC1G,IAAM0B,EAA0Dd,EAC5D,CAAC,EACD,CACE,GAAIH,EAAO,QAAQ,SAAS,KAAK,EAAI,CAACT,EAAc,CAAC,EAAI,CAAC,EAC1D,GAAIS,EAAO,QAAQ,SAAS,QAAQ,EAAI,CAACR,EAAa3B,CAAU,CAAC,EAAI,CAAC,CACxE,EACJ,GAAIoD,EAAU,OAAS,EAAG,CACxB,GAAI,OAAO,KAAKV,CAAK,CAAC,CAAC,OAAS,EAAG,MAAO,CAAC,GAAGS,EAAS,GAAGC,CAAS,EAEnE,GAAM,CAACC,EAAO,GAAGC,GAAQF,EACzB,MAAO,CAAC,CAAE,GAAGC,EAAQ,MAAOF,EAAQ,EAAE,CAAE,KAAM,EAAG,GAAGG,CAAI,CAC1D,CACA,OAAOH,EAAQ,SAAW,EAAIA,EAAQ,GAAMA,CAC9C"}
package/dist/tsdown.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./services/unistylesBabel/index.cjs"),t=require("./services/tsdownPreset/index.cjs");exports.poExtension=t.poExtension,exports.unistylesBabel=e.unistylesBabel;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./services/unistylesBabel/index.cjs"),t=require("./services/tsdownPreset/index.cjs");exports.extensionSourceEntries=t.extensionSourceEntries,exports.poExtension=t.poExtension,exports.unistylesBabel=e.unistylesBabel;
package/dist/tsdown.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { ExtensionPresetOptions, poExtension } from "./services/tsdownPreset/index.mjs";
1
+ import { ExtensionPresetOptions, extensionSourceEntries, poExtension } from "./services/tsdownPreset/index.mjs";
2
2
  import { unistylesBabel } from "./services/unistylesBabel/index.mjs";
3
- export { type ExtensionPresetOptions, poExtension, unistylesBabel };
3
+ export { type ExtensionPresetOptions, extensionSourceEntries, poExtension, unistylesBabel };
package/dist/tsdown.mjs CHANGED
@@ -1 +1 @@
1
- import{unistylesBabel as e}from"./services/unistylesBabel/index.mjs";import{poExtension as t}from"./services/tsdownPreset/index.mjs";export{t as poExtension,e as unistylesBabel};
1
+ import{unistylesBabel as e}from"./services/unistylesBabel/index.mjs";import{extensionSourceEntries as t,poExtension as n}from"./services/tsdownPreset/index.mjs";export{t as extensionSourceEntries,n as poExtension,e as unistylesBabel};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/po-build",
3
- "version": "0.0.0-alpha.1",
3
+ "version": "0.0.0-alpha.3",
4
4
  "description": "Folder-convention scanner and build presets for Po extensions.",
5
5
  "keywords": [
6
6
  "ai",
@@ -53,9 +53,9 @@
53
53
  "access": "public"
54
54
  },
55
55
  "devDependencies": {
56
- "@types/node": "26.6.4",
56
+ "@types/node": "25.9.9",
57
57
  "@vitest/coverage-v8": "5.0.3",
58
- "tsdown": "0.23.0",
58
+ "tsdown": "0.23.1",
59
59
  "typescript": "7.0.2",
60
60
  "vitest": "5.0.3"
61
61
  },