@pikku/cli 0.9.16-next.0 → 0.10.0

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 (266) hide show
  1. package/.pikku/channel/pikku-channel-types.gen.ts +28 -29
  2. package/.pikku/channel/pikku-channels-map.gen.d.ts +44 -0
  3. package/.pikku/channel/pikku-channels-meta.gen.ts +5 -0
  4. package/.pikku/channel/pikku-channels.gen.ts +4 -0
  5. package/.pikku/cli/pikku-cli-channel.gen.ts +34 -0
  6. package/.pikku/cli/pikku-cli-client.gen.ts +43 -0
  7. package/.pikku/cli/pikku-cli-types.gen.ts +14 -15
  8. package/.pikku/cli/pikku-cli-wirings-meta.gen.ts +142 -2
  9. package/.pikku/cli/pikku-cli-wirings.gen.ts +4 -2
  10. package/.pikku/cli/pikku-cli.gen.ts +41 -0
  11. package/.pikku/function/pikku-function-types.gen.ts +167 -19
  12. package/.pikku/function/pikku-functions-meta.gen.ts +220 -192
  13. package/.pikku/function/pikku-functions-meta.min.gen.ts +61 -56
  14. package/.pikku/function/pikku-functions.gen.ts +3 -1
  15. package/.pikku/http/pikku-http-types.gen.ts +28 -3
  16. package/.pikku/http/pikku-http-wirings-map.gen.d.ts +43 -0
  17. package/.pikku/http/pikku-http-wirings-meta.gen.ts +13 -0
  18. package/.pikku/http/pikku-http-wirings.gen.ts +4 -0
  19. package/.pikku/mcp/pikku-mcp-types.gen.ts +15 -13
  20. package/.pikku/mcp/pikku-mcp-wirings-meta.gen.ts +7 -0
  21. package/.pikku/mcp/pikku-mcp-wirings.gen.ts +4 -0
  22. package/.pikku/mcp/pikku-mcp.gen.json +5 -0
  23. package/.pikku/pikku-bootstrap.gen.ts +11 -1
  24. package/.pikku/pikku-services.gen.ts +1 -5
  25. package/.pikku/pikku-types.gen.ts +1 -2
  26. package/.pikku/pikku-websocket.gen.ts +76 -0
  27. package/.pikku/queue/pikku-queue-types.gen.ts +1 -2
  28. package/.pikku/queue/pikku-queue-workers-wirings-map.gen.d.ts +57 -0
  29. package/.pikku/queue/pikku-queue-workers-wirings-meta.gen.ts +5 -0
  30. package/.pikku/queue/pikku-queue-workers-wirings.gen.ts +4 -0
  31. package/.pikku/rpc/pikku-rpc-wirings-map.gen.d.ts +5 -4
  32. package/.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts +19 -17
  33. package/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.ts +15 -14
  34. package/.pikku/scheduler/pikku-scheduler-types.gen.ts +1 -2
  35. package/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.ts +5 -0
  36. package/.pikku/scheduler/pikku-schedulers-wirings.gen.ts +4 -0
  37. package/.pikku/schemas/register.gen.ts +15 -11
  38. package/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
  39. package/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
  40. package/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -0
  41. package/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
  42. package/CHANGELOG.md +6 -0
  43. package/bin/pikku.ts +63 -11
  44. package/build.sh +1 -1
  45. package/cli.schema.json +1 -1
  46. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +11 -20
  47. package/dist/.pikku/channel/pikku-channel-types.gen.js +9 -11
  48. package/dist/.pikku/channel/pikku-channels-meta.gen.d.ts +1 -0
  49. package/dist/.pikku/channel/pikku-channels-meta.gen.js +5 -0
  50. package/dist/.pikku/channel/pikku-channels.gen.d.ts +4 -0
  51. package/dist/.pikku/channel/pikku-channels.gen.js +5 -0
  52. package/dist/.pikku/cli/pikku-cli-channel.gen.d.ts +1 -0
  53. package/dist/.pikku/cli/pikku-cli-channel.gen.js +33 -0
  54. package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +10 -0
  55. package/dist/.pikku/cli/pikku-cli-client.gen.js +34 -0
  56. package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +9 -12
  57. package/dist/.pikku/cli/pikku-cli-types.gen.js +5 -4
  58. package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +142 -2
  59. package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +3 -2
  60. package/dist/.pikku/cli/pikku-cli-wirings.gen.js +4 -3
  61. package/dist/.pikku/cli/pikku-cli.gen.d.ts +10 -0
  62. package/dist/.pikku/cli/pikku-cli.gen.js +38 -0
  63. package/dist/.pikku/function/pikku-function-types.gen.d.ts +141 -20
  64. package/dist/.pikku/function/pikku-function-types.gen.js +108 -12
  65. package/dist/.pikku/function/pikku-functions-meta.gen.js +220 -192
  66. package/dist/.pikku/function/pikku-functions-meta.min.gen.js +61 -56
  67. package/dist/.pikku/function/pikku-functions.gen.js +3 -1
  68. package/dist/.pikku/http/pikku-http-types.gen.d.ts +21 -2
  69. package/dist/.pikku/http/pikku-http-types.gen.js +24 -3
  70. package/dist/.pikku/http/pikku-http-wirings-meta.gen.d.ts +1 -0
  71. package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +13 -0
  72. package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +4 -0
  73. package/dist/.pikku/http/pikku-http-wirings.gen.js +5 -0
  74. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +11 -8
  75. package/dist/.pikku/mcp/pikku-mcp-types.gen.js +6 -6
  76. package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.d.ts +1 -0
  77. package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.js +7 -0
  78. package/dist/.pikku/mcp/pikku-mcp-wirings.gen.d.ts +4 -0
  79. package/dist/.pikku/mcp/pikku-mcp-wirings.gen.js +5 -0
  80. package/dist/.pikku/pikku-bootstrap.gen.d.ts +11 -1
  81. package/dist/.pikku/pikku-bootstrap.gen.js +11 -1
  82. package/dist/.pikku/pikku-services.gen.d.ts +1 -4
  83. package/dist/.pikku/pikku-services.gen.js +0 -6
  84. package/dist/.pikku/pikku-types.gen.d.ts +1 -2
  85. package/dist/.pikku/pikku-types.gen.js +1 -2
  86. package/dist/.pikku/pikku-websocket.gen.d.ts +31 -0
  87. package/dist/.pikku/pikku-websocket.gen.js +49 -0
  88. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -2
  89. package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -2
  90. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.d.ts +1 -0
  91. package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +5 -0
  92. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +4 -0
  93. package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +5 -0
  94. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +15 -14
  95. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -2
  96. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -2
  97. package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.d.ts +1 -0
  98. package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.js +5 -0
  99. package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.d.ts +4 -0
  100. package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.js +5 -0
  101. package/dist/.pikku/schemas/register.gen.js +9 -7
  102. package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
  103. package/dist/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
  104. package/dist/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -0
  105. package/dist/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
  106. package/dist/bin/pikku.d.ts +1 -1
  107. package/dist/bin/pikku.js +37 -6
  108. package/dist/src/cli.wiring.js +99 -75
  109. package/dist/src/functions/commands/all.js +10 -0
  110. package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.js +10 -8
  111. package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts +1 -1
  112. package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.js +2 -2
  113. package/dist/src/functions/wirings/channels/pikku-channels.js +0 -5
  114. package/dist/src/functions/wirings/channels/pikku-command-channel-types.js +0 -2
  115. package/dist/src/functions/wirings/channels/pikku-command-channels-map.js +0 -5
  116. package/dist/src/functions/wirings/channels/pikku-command-channels.js +0 -5
  117. package/dist/src/functions/wirings/channels/pikku-command-websocket-typed.js +6 -3
  118. package/dist/src/functions/wirings/channels/serialize-channel-types.js +27 -28
  119. package/dist/src/functions/wirings/channels/serialize-typed-channel-map.js +4 -1
  120. package/dist/src/functions/wirings/cli/pikku-command-cli-entry.js +31 -8
  121. package/dist/src/functions/wirings/cli/pikku-command-cli-types.js +0 -2
  122. package/dist/src/functions/wirings/cli/pikku-command-cli.js +0 -2
  123. package/dist/src/functions/wirings/cli/serialize-channel-cli-client.d.ts +6 -2
  124. package/dist/src/functions/wirings/cli/serialize-channel-cli-client.js +88 -11
  125. package/dist/src/functions/wirings/cli/serialize-channel-cli.d.ts +1 -1
  126. package/dist/src/functions/wirings/cli/serialize-channel-cli.js +1 -18
  127. package/dist/src/functions/wirings/cli/serialize-cli-types.js +13 -14
  128. package/dist/src/functions/wirings/cli/serialize-local-cli-bootstrap.js +19 -14
  129. package/dist/src/functions/wirings/fetch/index.js +6 -3
  130. package/dist/src/functions/wirings/functions/pikku-command-function-types-split.js +6 -5
  131. package/dist/src/functions/wirings/functions/pikku-command-function-types.js +0 -2
  132. package/dist/src/functions/wirings/functions/pikku-command-functions.js +0 -2
  133. package/dist/src/functions/wirings/functions/pikku-command-services.d.ts +1 -1
  134. package/dist/src/functions/wirings/functions/pikku-command-services.js +11 -21
  135. package/dist/src/functions/wirings/functions/pikku-function-types.js +0 -2
  136. package/dist/src/functions/wirings/functions/schemas.js +0 -2
  137. package/dist/src/functions/wirings/functions/serialize-function-types.d.ts +1 -1
  138. package/dist/src/functions/wirings/functions/serialize-function-types.js +167 -19
  139. package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.js +0 -1
  140. package/dist/src/functions/wirings/http/openapi-spec-generator.d.ts +2 -1
  141. package/dist/src/functions/wirings/http/pikku-command-http-map.js +0 -5
  142. package/dist/src/functions/wirings/http/pikku-command-http-routes.js +0 -5
  143. package/dist/src/functions/wirings/http/pikku-command-http-types.js +0 -2
  144. package/dist/src/functions/wirings/http/pikku-command-openapi.js +7 -4
  145. package/dist/src/functions/wirings/http/pikku-http-routes.js +0 -5
  146. package/dist/src/functions/wirings/http/serialize-http-types.js +27 -2
  147. package/dist/src/functions/wirings/mcp/pikku-command-mcp-json.js +0 -5
  148. package/dist/src/functions/wirings/mcp/pikku-command-mcp-types.js +0 -2
  149. package/dist/src/functions/wirings/mcp/pikku-command-mcp.js +0 -5
  150. package/dist/src/functions/wirings/mcp/serialize-mcp-json.d.ts +1 -1
  151. package/dist/src/functions/wirings/mcp/serialize-mcp-types.js +14 -12
  152. package/dist/src/functions/wirings/middleware/pikku-command-middleware.js +0 -2
  153. package/dist/src/functions/wirings/middleware/serialize-middleware-groups-meta.js +1 -7
  154. package/dist/src/functions/wirings/permissions/pikku-command-permissions.d.ts +1 -0
  155. package/dist/src/functions/wirings/permissions/pikku-command-permissions.js +28 -0
  156. package/dist/src/functions/wirings/permissions/serialize-permissions-imports.d.ts +2 -0
  157. package/dist/src/functions/wirings/permissions/serialize-permissions-imports.js +43 -0
  158. package/dist/src/functions/wirings/queue/pikku-command-queue-map.js +0 -5
  159. package/dist/src/functions/wirings/queue/pikku-command-queue-service.js +6 -3
  160. package/dist/src/functions/wirings/queue/pikku-command-queue-types.js +0 -2
  161. package/dist/src/functions/wirings/queue/pikku-command-queue.js +0 -5
  162. package/dist/src/functions/wirings/queue/pikku-queue-map.js +0 -5
  163. package/dist/src/functions/wirings/queue/pikku-queue.js +1 -5
  164. package/dist/src/functions/wirings/queue/serialize-queue-meta.d.ts +1 -1
  165. package/dist/src/functions/wirings/queue/serialize-queue-types.js +0 -1
  166. package/dist/src/functions/wirings/rpc/pikku-command-rpc-client.js +5 -3
  167. package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.js +0 -4
  168. package/dist/src/functions/wirings/rpc/pikku-command-rpc.js +0 -2
  169. package/dist/src/functions/wirings/scheduler/pikku-command-scheduler-types.js +0 -2
  170. package/dist/src/functions/wirings/scheduler/pikku-command-scheduler.js +0 -5
  171. package/dist/src/functions/wirings/scheduler/serialize-scheduler-types.js +0 -1
  172. package/dist/src/middleware/log-command-info-and-time.d.ts +2 -8
  173. package/dist/src/middleware/log-command-info-and-time.js +2 -14
  174. package/dist/src/services/cli-logger-forwarder.service.d.ts +6 -2
  175. package/dist/src/services/cli-logger-forwarder.service.js +9 -0
  176. package/dist/src/services/cli-logger.service.d.ts +4 -0
  177. package/dist/src/services/cli-logger.service.js +11 -0
  178. package/dist/src/services.d.ts +5 -0
  179. package/dist/src/services.js +111 -13
  180. package/dist/src/utils/custom-types-generator.js +8 -2
  181. package/dist/src/utils/file-writer.d.ts +4 -1
  182. package/dist/src/utils/file-writer.js +13 -3
  183. package/dist/src/utils/get-cli-version.d.ts +5 -0
  184. package/dist/src/utils/get-cli-version.js +27 -0
  185. package/dist/src/utils/pikku-cli-config.d.ts +1 -2
  186. package/dist/src/utils/pikku-cli-config.js +9 -28
  187. package/dist/src/utils/schema-generator.js +3 -2
  188. package/dist/src/utils/serialize-import-map.js +0 -3
  189. package/dist/tsconfig.tsbuildinfo +1 -1
  190. package/package.json +10 -8
  191. package/pikku.config.json +4 -2
  192. package/src/cli.wiring.ts +101 -74
  193. package/src/functions/commands/all.ts +12 -0
  194. package/src/functions/runtimes/nextjs/pikku-command-nextjs.ts +12 -12
  195. package/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.ts +2 -2
  196. package/src/functions/wirings/channels/pikku-channels.ts +0 -5
  197. package/src/functions/wirings/channels/pikku-command-channel-types.ts +0 -2
  198. package/src/functions/wirings/channels/pikku-command-channels-map.ts +0 -5
  199. package/src/functions/wirings/channels/pikku-command-channels.ts +0 -5
  200. package/src/functions/wirings/channels/pikku-command-websocket-typed.ts +7 -3
  201. package/src/functions/wirings/channels/serialize-channel-types.ts +27 -28
  202. package/src/functions/wirings/channels/serialize-typed-channel-map.ts +4 -1
  203. package/src/functions/wirings/cli/pikku-command-cli-entry.ts +52 -9
  204. package/src/functions/wirings/cli/pikku-command-cli-types.ts +0 -2
  205. package/src/functions/wirings/cli/pikku-command-cli.ts +0 -2
  206. package/src/functions/wirings/cli/serialize-channel-cli-client.ts +111 -12
  207. package/src/functions/wirings/cli/serialize-channel-cli.ts +2 -23
  208. package/src/functions/wirings/cli/serialize-cli-types.ts +13 -14
  209. package/src/functions/wirings/cli/serialize-local-cli-bootstrap.ts +19 -14
  210. package/src/functions/wirings/fetch/index.ts +7 -3
  211. package/src/functions/wirings/functions/pikku-command-function-types-split.ts +14 -5
  212. package/src/functions/wirings/functions/pikku-command-function-types.ts +0 -2
  213. package/src/functions/wirings/functions/pikku-command-functions.ts +0 -2
  214. package/src/functions/wirings/functions/pikku-command-services.ts +13 -24
  215. package/src/functions/wirings/functions/pikku-function-types.ts +0 -2
  216. package/src/functions/wirings/functions/schemas.ts +0 -2
  217. package/src/functions/wirings/functions/serialize-function-types.ts +169 -19
  218. package/src/functions/wirings/functions/serialize-pikku-types-hub.ts +0 -1
  219. package/src/functions/wirings/http/openapi-spec-generator.ts +2 -1
  220. package/src/functions/wirings/http/pikku-command-http-map.ts +0 -5
  221. package/src/functions/wirings/http/pikku-command-http-routes.ts +0 -5
  222. package/src/functions/wirings/http/pikku-command-http-types.ts +0 -2
  223. package/src/functions/wirings/http/pikku-command-openapi.ts +9 -4
  224. package/src/functions/wirings/http/pikku-http-routes.ts +0 -5
  225. package/src/functions/wirings/http/serialize-http-types.ts +27 -2
  226. package/src/functions/wirings/mcp/pikku-command-mcp-json.ts +0 -5
  227. package/src/functions/wirings/mcp/pikku-command-mcp-types.ts +0 -2
  228. package/src/functions/wirings/mcp/pikku-command-mcp.ts +0 -5
  229. package/src/functions/wirings/mcp/serialize-mcp-json.ts +1 -1
  230. package/src/functions/wirings/mcp/serialize-mcp-types.ts +14 -12
  231. package/src/functions/wirings/middleware/pikku-command-middleware.ts +0 -2
  232. package/src/functions/wirings/middleware/serialize-middleware-groups-meta.ts +1 -7
  233. package/src/functions/wirings/permissions/pikku-command-permissions.ts +49 -0
  234. package/src/functions/wirings/permissions/serialize-permissions-imports.test.ts +274 -0
  235. package/src/functions/wirings/permissions/serialize-permissions-imports.ts +78 -0
  236. package/src/functions/wirings/queue/pikku-command-queue-map.ts +0 -5
  237. package/src/functions/wirings/queue/pikku-command-queue-service.ts +7 -3
  238. package/src/functions/wirings/queue/pikku-command-queue-types.ts +0 -2
  239. package/src/functions/wirings/queue/pikku-command-queue.ts +0 -5
  240. package/src/functions/wirings/queue/pikku-queue-map.ts +0 -5
  241. package/src/functions/wirings/queue/pikku-queue.ts +3 -6
  242. package/src/functions/wirings/queue/serialize-queue-meta.ts +1 -1
  243. package/src/functions/wirings/queue/serialize-queue-types.ts +0 -1
  244. package/src/functions/wirings/rpc/pikku-command-rpc-client.ts +6 -3
  245. package/src/functions/wirings/rpc/pikku-command-rpc-map.ts +0 -4
  246. package/src/functions/wirings/rpc/pikku-command-rpc.ts +0 -2
  247. package/src/functions/wirings/scheduler/pikku-command-scheduler-types.ts +0 -2
  248. package/src/functions/wirings/scheduler/pikku-command-scheduler.ts +0 -5
  249. package/src/functions/wirings/scheduler/serialize-scheduler-types.ts +0 -1
  250. package/src/middleware/log-command-info-and-time.ts +2 -28
  251. package/src/services/cli-logger-forwarder.service.ts +15 -2
  252. package/src/services/cli-logger.service.ts +15 -0
  253. package/src/services.ts +148 -19
  254. package/src/utils/custom-types-generator.ts +8 -2
  255. package/src/utils/file-writer.ts +19 -3
  256. package/src/utils/get-cli-version.ts +28 -0
  257. package/src/utils/pikku-cli-config.ts +6 -35
  258. package/src/utils/schema-generator.ts +7 -3
  259. package/src/utils/serialize-import-map.ts +0 -4
  260. package/types/application-types.d.ts +4 -1
  261. package/types/config.d.ts +15 -3
  262. package/dist/.pikku/rpc/pikku-bootstrap-rpc.gen.d.ts +0 -6
  263. package/dist/.pikku/rpc/pikku-bootstrap-rpc.gen.js +0 -6
  264. package/dist/src/serialize-pikku-types.d.ts +0 -4
  265. package/dist/src/serialize-pikku-types.js +0 -605
  266. package/src/serialize-pikku-types.ts +0 -613
@@ -54,8 +54,6 @@ export const pikkuFunctions: any = pikkuSessionlessFunc<
54
54
  logCommandInfoAndTime({
55
55
  commandStart: 'Serializing Pikku functions',
56
56
  commandEnd: 'Serialized Pikku functions',
57
- skipCondition: false,
58
- skipMessage: '',
59
57
  }),
60
58
  ],
61
59
  })
@@ -5,30 +5,24 @@ import { writeFileInDir } from '../../../utils/file-writer.js'
5
5
  import { logCommandInfoAndTime } from '../../../middleware/log-command-info-and-time.js'
6
6
 
7
7
  export const serializeServicesMap = (
8
- functionsMetaData: Record<string, any>,
9
- middlewareServices: string[] = [],
8
+ requiredServices: Set<string>,
9
+ forceRequiredServices: string[] = [],
10
10
  servicesImport: string,
11
11
  sessionServicesImport: string
12
12
  ): string => {
13
- // Extract all unique services from all functions
14
- const usedServices = new Set<string>()
13
+ // Use pre-aggregated services from inspector state
14
+ // This includes services from:
15
+ // - Wired functions (HTTP, channels, queues, schedulers, MCP, CLI, RPC)
16
+ // - Middleware used by wired functions
17
+ // - Permissions used by wired functions
18
+ // - Session factories
19
+ const usedServices = new Set(requiredServices)
15
20
 
16
21
  // Internal services that are created internally and not via the create service script
17
22
  const internalServices = new Set(['rpc', 'mcp', 'channel', 'userSession'])
18
23
 
19
- for (const funcMeta of Object.values(functionsMetaData)) {
20
- if (funcMeta.services && Array.isArray(funcMeta.services.services)) {
21
- funcMeta.services.services.forEach((service: string) => {
22
- // Only include services that are not internal
23
- if (!internalServices.has(service)) {
24
- usedServices.add(service)
25
- }
26
- })
27
- }
28
- }
29
-
30
- // Add middleware services that might not be detected from function inspection
31
- middlewareServices.forEach((service) => {
24
+ // Add force-required services that might not be detected from function inspection
25
+ forceRequiredServices.forEach((service) => {
32
26
  if (!internalServices.has(service)) {
33
27
  usedServices.add(service)
34
28
  }
@@ -57,10 +51,6 @@ export const serializeServicesMap = (
57
51
  // We don't need to hardcode which services are singletons beyond the core framework ones
58
52
 
59
53
  const code = [
60
- '/**',
61
- ' * This file was generated by the @pikku/cli',
62
- ' */',
63
- '',
64
54
  servicesImport,
65
55
  sessionServicesImport,
66
56
  "import type { PikkuInteraction } from '@pikku/core'",
@@ -105,8 +95,8 @@ export const pikkuServices: any = pikkuSessionlessFunc<void, void>({
105
95
  const sessionServicesImport = `import type { ${sessionServicesType.type} } from '${getFileImportRelativePath(config.typesDeclarationFile, sessionServicesType.typePath, config.packageMappings)}'`
106
96
 
107
97
  const servicesCode = serializeServicesMap(
108
- visitState.functions.meta,
109
- config.middlewareServices,
98
+ visitState.serviceAggregation.requiredServices,
99
+ config.forceRequiredServices,
110
100
  servicesImport,
111
101
  sessionServicesImport
112
102
  )
@@ -116,7 +106,6 @@ export const pikkuServices: any = pikkuSessionlessFunc<void, void>({
116
106
  logCommandInfoAndTime({
117
107
  commandStart: 'Generating Pikku services map',
118
108
  commandEnd: 'Generated Pikku services map',
119
- skipMessage: '',
120
109
  }),
121
110
  ],
122
111
  })
@@ -38,8 +38,6 @@ export const pikkuFunctionTypes: any = pikkuSessionlessFunc<void, void>({
38
38
  logCommandInfoAndTime({
39
39
  commandStart: 'Creating api types hub',
40
40
  commandEnd: 'Created api types hub',
41
- skipCondition: false,
42
- skipMessage: '',
43
41
  }),
44
42
  ],
45
43
  })
@@ -40,8 +40,6 @@ export const pikkuSchemas: any = pikkuSessionlessFunc<
40
40
  logCommandInfoAndTime({
41
41
  commandStart: 'Generating schemas',
42
42
  commandEnd: 'Generated schemas',
43
- skipCondition: false,
44
- skipMessage: '',
45
43
  }),
46
44
  ],
47
45
  })
@@ -8,25 +8,30 @@ export const serializeFunctionTypes = (
8
8
  singletonServicesTypeName: string,
9
9
  sessionServicesTypeImport: string,
10
10
  sessionServicesTypeName: string,
11
- rpcMapTypeImport: string
11
+ rpcMapTypeImport: string,
12
+ requiredServicesTypeImport: string,
13
+ configTypeImport: string
12
14
  ) => {
13
15
  return `/**
14
- * This file was generated by the @pikku/cli
15
16
  * Core function, middleware, and permission types for all wirings
16
17
  */
17
18
 
18
- import { CorePikkuFunctionConfig, CorePikkuPermission, CorePikkuMiddleware, addMiddleware as addMiddlewareCore, addPermission as addPermissionCore } from '@pikku/core'
19
+ import { CorePikkuFunctionConfig, CorePikkuPermission, CorePikkuMiddleware, CorePermissionGroup, addMiddleware as addMiddlewareCore, addPermission as addPermissionCore } from '@pikku/core'
19
20
  import { CorePikkuFunction, CorePikkuFunctionSessionless } from '@pikku/core/function'
20
- import { PikkuChannel, PikkuMCP } from '@pikku/core'
21
+ import { PikkuChannel } from '@pikku/core/channel'
22
+ import { PikkuMCP } from '@pikku/core/mcp'
21
23
 
22
24
  ${userSessionTypeImport}
23
25
  ${singletonServicesTypeImport}
24
26
  ${sessionServicesTypeImport}
27
+ ${configTypeImport}
25
28
  ${rpcMapTypeImport}
29
+ ${requiredServicesTypeImport}
26
30
 
27
31
  ${singletonServicesTypeName !== 'SingletonServices' ? `type SingletonServices = ${singletonServicesTypeName}` : ''}
28
32
  ${sessionServicesTypeName !== 'Services' ? `type Services = ${sessionServicesTypeName}` : ''}
29
33
  ${userSessionTypeName !== 'Session' ? `type Session = ${userSessionTypeName}` : ''}
34
+ ${configTypeImport.includes('Config type not found') ? 'type Config = any' : ''}
30
35
 
31
36
  /**
32
37
  * Type-safe API permission definition that integrates with your application's session type.
@@ -45,35 +50,84 @@ export type PikkuPermission<In = unknown, RequiredServices extends Services = Se
45
50
  */
46
51
  export type PikkuMiddleware<RequiredServices extends SingletonServices = SingletonServices> = CorePikkuMiddleware<RequiredServices, Session>
47
52
 
53
+ /**
54
+ * Configuration object for creating a permission with metadata
55
+ */
56
+ export type PikkuPermissionConfig<In = unknown, RequiredServices extends Services = Services> = {
57
+ /** The permission function */
58
+ func: PikkuPermission<In, RequiredServices>
59
+ /** Optional human-readable name for the permission */
60
+ name?: string
61
+ /** Optional description of what the permission checks */
62
+ description?: string
63
+ }
64
+
48
65
  /**
49
66
  * Factory function for creating permissions with tree-shaking support.
50
- * This enables the bundler to detect which services your permission actually uses.
67
+ * Supports both direct function and configuration object syntax.
51
68
  *
52
69
  * @example
53
70
  * \`\`\`typescript
71
+ * // Direct function syntax
54
72
  * const permission = pikkuPermission(({ logger }, data, session) => {
55
- * return session?.isAdmin || false
73
+ * return session?.role === 'admin'
74
+ * })
75
+ *
76
+ * // Configuration object syntax with metadata
77
+ * const adminPermission = pikkuPermission({
78
+ * name: 'Admin Permission',
79
+ * description: 'Checks if user has admin role',
80
+ * func: async ({ logger }, data, session) => {
81
+ * return session?.role === 'admin'
82
+ * }
56
83
  * })
57
84
  * \`\`\`
58
85
  */
59
- export const pikkuPermission = <In>(func: PikkuPermission<In>) => {
60
- return func
86
+ export const pikkuPermission = <In>(
87
+ permission: PikkuPermission<In> | PikkuPermissionConfig<In>
88
+ ): PikkuPermission<In> => {
89
+ return typeof permission === 'function' ? permission : permission.func
90
+ }
91
+
92
+ /**
93
+ * Configuration object for creating middleware with metadata
94
+ */
95
+ export type PikkuMiddlewareConfig<RequiredServices extends SingletonServices = SingletonServices> = {
96
+ /** The middleware function */
97
+ func: PikkuMiddleware<RequiredServices>
98
+ /** Optional human-readable name for the middleware */
99
+ name?: string
100
+ /** Optional description of what the middleware does */
101
+ description?: string
61
102
  }
62
103
 
63
104
  /**
64
105
  * Factory function for creating middleware with tree-shaking support.
65
- * This enables the bundler to detect which services your middleware actually uses.
106
+ * Supports both direct function and configuration object syntax.
66
107
  *
67
108
  * @example
68
109
  * \`\`\`typescript
110
+ * // Direct function syntax
69
111
  * const middleware = pikkuMiddleware(({ logger }, interactions, next) => {
70
112
  * logger.info('Middleware executed')
71
113
  * await next()
72
114
  * })
115
+ *
116
+ * // Configuration object syntax with metadata
117
+ * const logMiddleware = pikkuMiddleware({
118
+ * name: 'Request Logger',
119
+ * description: 'Logs all incoming requests',
120
+ * func: async ({ logger }, interactions, next) => {
121
+ * logger.info('Request started')
122
+ * await next()
123
+ * }
124
+ * })
73
125
  * \`\`\`
74
126
  */
75
- export const pikkuMiddleware = (func: PikkuMiddleware) => {
76
- return func
127
+ export const pikkuMiddleware = <RequiredServices extends SingletonServices = SingletonServices>(
128
+ middleware: PikkuMiddleware<RequiredServices> | PikkuMiddlewareConfig<RequiredServices>
129
+ ): PikkuMiddleware<RequiredServices> => {
130
+ return typeof middleware === 'function' ? middleware : middleware.func
77
131
  }
78
132
 
79
133
  /**
@@ -99,6 +153,31 @@ export const pikkuMiddlewareFactory = <In = any>(
99
153
  return factory
100
154
  }
101
155
 
156
+ /**
157
+ * Factory function for creating permission factories
158
+ * Use this when your permission needs configuration/input parameters
159
+ *
160
+ * @example
161
+ * \`\`\`typescript
162
+ * export const requireRole = pikkuPermissionFactory<{ role: string }>(({
163
+ * role
164
+ * }) => {
165
+ * return pikkuPermission(async ({ logger }, data, session) => {
166
+ * if (!session || session.role !== role) {
167
+ * logger.warn(\`Permission denied: required role '\${role}'\`)
168
+ * return false
169
+ * }
170
+ * return true
171
+ * })
172
+ * })
173
+ * \`\`\`
174
+ */
175
+ export const pikkuPermissionFactory = <In = any>(
176
+ factory: (input: In) => PikkuPermission<any>
177
+ ): ((input: In) => PikkuPermission<any>) => {
178
+ return factory
179
+ }
180
+
102
181
  /**
103
182
  * A sessionless API function that doesn't require user authentication.
104
183
  * Use this for public endpoints, health checks, or operations that don't need user context.
@@ -114,7 +193,7 @@ export type PikkuFunctionSessionless<
114
193
  Out = never,
115
194
  ChannelData = null, // null means optional channel
116
195
  MCPData = null, // null means optional MCP
117
- RequiredServices extends Services = Services &
196
+ RequiredServices extends Services = Omit<Services, 'rpc' | 'channel' | 'mcp'> &
118
197
  { rpc: TypedPikkuRPC } & (
119
198
  [ChannelData] extends [null]
120
199
  ? { channel?: PikkuChannel<unknown, Out> } // Optional channel
@@ -140,7 +219,7 @@ export type PikkuFunction<
140
219
  Out = never,
141
220
  ChannelData = null, // null means optional channel
142
221
  MCPData = null, // null means optional MCP
143
- RequiredServices extends Services = Omit<Services, 'rpc'> &
222
+ RequiredServices extends Services = Omit<Services, 'rpc' | 'channel' | 'mcp'> &
144
223
  { rpc: TypedPikkuRPC } & (
145
224
  [ChannelData] extends [null]
146
225
  ? { channel?: PikkuChannel<unknown, Out> } // Optional channel
@@ -157,12 +236,16 @@ export type PikkuFunction<
157
236
  *
158
237
  * @template In - The input type
159
238
  * @template Out - The output type
239
+ * @template ChannelData - Channel data type
240
+ * @template MCPData - MCP data type
160
241
  * @template PikkuFunc - The function type (can be narrowed to PikkuFunction or PikkuFunctionSessionless)
161
242
  */
162
243
  export type PikkuFunctionConfig<
163
244
  In = unknown,
164
245
  Out = unknown,
165
- PikkuFunc extends PikkuFunction<In, Out> | PikkuFunctionSessionless<In, Out> = PikkuFunction<In, Out> | PikkuFunctionSessionless<In, Out>
246
+ ChannelData = unknown,
247
+ MCPData = unknown,
248
+ PikkuFunc extends PikkuFunction<In, Out, ChannelData, MCPData> | PikkuFunctionSessionless<In, Out, ChannelData, MCPData> = PikkuFunction<In, Out, ChannelData, MCPData> | PikkuFunctionSessionless<In, Out, ChannelData, MCPData>
166
249
  > = CorePikkuFunctionConfig<PikkuFunc, PikkuPermission<In>, PikkuMiddleware>
167
250
 
168
251
  /**
@@ -189,7 +272,7 @@ export type PikkuFunctionConfig<
189
272
  export const pikkuFunc = <In, Out = unknown>(
190
273
  func:
191
274
  | PikkuFunction<In, Out>
192
- | CorePikkuFunctionConfig<PikkuFunction<In, Out>, PikkuPermission<In>>
275
+ | CorePikkuFunctionConfig<PikkuFunction<In, Out>, PikkuPermission<In>, PikkuMiddleware>
193
276
  ) => {
194
277
  return typeof func === 'function' ? { func } : func
195
278
  }
@@ -246,6 +329,73 @@ export const pikkuVoidFunc = (
246
329
  return typeof func === 'function' ? { func } : func
247
330
  }
248
331
 
332
+ /**
333
+ * Creates a Pikku config factory.
334
+ * Use this to define your application's configuration factory.
335
+ *
336
+ * @param func - Config factory function that returns your application's config
337
+ * @returns The config factory function
338
+ *
339
+ * @example
340
+ * \`\`\`typescript
341
+ * export const createConfig = pikkuConfig(async () => {
342
+ * return {
343
+ * apiUrl: process.env.API_URL || 'http://localhost:3000',
344
+ * dbUrl: process.env.DATABASE_URL
345
+ * }
346
+ * })
347
+ * \`\`\`
348
+ */
349
+ export const pikkuConfig = (
350
+ func: (variables?: any, ...args: any[]) => Promise<Config>
351
+ ) => func
352
+
353
+ /**
354
+ * Creates a Pikku singleton services factory.
355
+ * Use this to define services that are created once and shared across all requests.
356
+ *
357
+ * @param func - Singleton services factory function
358
+ * @returns The singleton services factory function
359
+ *
360
+ * @example
361
+ * \`\`\`typescript
362
+ * export const createSingletonServices = pikkuServices(async (config, existingServices) => {
363
+ * return {
364
+ * config,
365
+ * logger: new CustomLogger(),
366
+ * db: await createDatabaseConnection(config.dbUrl)
367
+ * }
368
+ * })
369
+ * \`\`\`
370
+ */
371
+ export const pikkuServices = (
372
+ func: (config: Config, existingServices?: Partial<SingletonServices>) => Promise<RequiredSingletonServices>
373
+ ) => func
374
+
375
+ /**
376
+ * Creates a Pikku session services factory.
377
+ * Use this to define services that are created per-request/session.
378
+ *
379
+ * @param func - Session services factory function
380
+ * @returns The session services factory function
381
+ *
382
+ * @example
383
+ * \`\`\`typescript
384
+ * export const createSessionServices = pikkuSessionServices(async (services, interaction, session) => {
385
+ * return {
386
+ * userCache: new UserCache(session?.userId)
387
+ * }
388
+ * })
389
+ * \`\`\`
390
+ */
391
+ export const pikkuSessionServices = (
392
+ func: (
393
+ services: SingletonServices,
394
+ interaction: any,
395
+ session: Session | undefined
396
+ ) => Promise<RequiredSessionServices>
397
+ ) => func
398
+
249
399
  /**
250
400
  * Adds global middleware for a specific tag.
251
401
  *
@@ -280,7 +430,7 @@ export const addMiddleware = (tag: string, middleware: PikkuMiddleware[]) => {
280
430
  * any wiring (HTTP, Channel, Queue, Scheduler, MCP) that includes the matching tag.
281
431
  *
282
432
  * @param tag - The tag that the permissions should apply to.
283
- * @param permissions - The permissions array to apply for the specified tag.
433
+ * @param permissions - The permissions array or object to apply for the specified tag.
284
434
  *
285
435
  * @throws Error if permissions for the tag already exist.
286
436
  *
@@ -292,11 +442,11 @@ export const addMiddleware = (tag: string, middleware: PikkuMiddleware[]) => {
292
442
  * // Add authentication permissions for auth endpoints
293
443
  * addPermission('auth', [authPermission])
294
444
  *
295
- * // Add read permissions for all API endpoints
296
- * addPermission('api', [readPermission])
445
+ * // Add read permissions for all API endpoints (as object)
446
+ * addPermission('api', { read: readPermission })
297
447
  * \`\`\`
298
448
  */
299
- export const addPermission = <In = unknown>(tag: string, permissions: PikkuPermission<In>[]) => {
449
+ export const addPermission = <In = unknown>(tag: string, permissions: CorePermissionGroup<PikkuPermission<In>> | PikkuPermission<In>[]) => {
300
450
  addPermissionCore(tag, permissions as any)
301
451
  }
302
452
  `
@@ -11,7 +11,6 @@ export const serializePikkuTypesHub = (
11
11
  cliTypesImportPath: string
12
12
  ) => {
13
13
  return `/**
14
- * This file was generated by the @pikku/cli
15
14
  * Main type export hub - re-exports all wiring-specific types
16
15
  */
17
16
 
@@ -1,4 +1,5 @@
1
- import { FunctionsMeta, HTTPWiringsMeta, pikkuState } from '@pikku/core'
1
+ import { FunctionsMeta, pikkuState } from '@pikku/core'
2
+ import { HTTPWiringsMeta } from '@pikku/core/http'
2
3
  import _convertSchema from '@openapi-contrib/json-schema-to-openapi-schema'
3
4
  import { CLILogger } from '../../../services/cli-logger.service.js'
4
5
  const convertSchema =
@@ -22,11 +22,6 @@ export const pikkuHTTPMap: any = pikkuSessionlessFunc<void, void>({
22
22
  logCommandInfoAndTime({
23
23
  commandStart: 'Creating HTTP map',
24
24
  commandEnd: 'Created HTTP map',
25
- skipCondition: async ({ getInspectorState }) => {
26
- const { http } = await getInspectorState()
27
- return http.files.size === 0
28
- },
29
- skipMessage: 'none found',
30
25
  }),
31
26
  ],
32
27
  })
@@ -31,11 +31,6 @@ export const pikkuHTTP: any = pikkuSessionlessFunc<void, boolean | undefined>({
31
31
  logCommandInfoAndTime({
32
32
  commandStart: 'Finding HTTP routes',
33
33
  commandEnd: 'Found HTTP routes',
34
- skipCondition: async ({ getInspectorState }) => {
35
- const visitState = await getInspectorState()
36
- return visitState.http.files.size === 0
37
- },
38
- skipMessage: 'none found',
39
34
  }),
40
35
  ],
41
36
  })
@@ -20,8 +20,6 @@ export const pikkuHTTPTypes: any = pikkuSessionlessFunc<void, void>({
20
20
  logCommandInfoAndTime({
21
21
  commandStart: 'Creating HTTP types',
22
22
  commandEnd: 'Created HTTP types',
23
- skipCondition: false,
24
- skipMessage: '',
25
23
  }),
26
24
  ],
27
25
  })
@@ -7,13 +7,20 @@ import { stringify } from 'yaml'
7
7
 
8
8
  export const pikkuOpenAPI: any = pikkuSessionlessFunc<void, void>({
9
9
  func: async ({ logger, config, getInspectorState }) => {
10
- const { http, functions } = await getInspectorState()
11
10
  const { tsconfig, openAPI, schemasFromTypes } = config
12
11
 
12
+ // If openAPI outputFile is not defined, clean up any existing file and return
13
13
  if (!openAPI?.outputFile) {
14
- throw new Error('openAPI is required')
14
+ logger.info({
15
+ message:
16
+ 'Skipping creating OpenAPI spec since openAPI outfile is not defined.',
17
+ type: 'skip',
18
+ })
19
+ return
15
20
  }
16
21
 
22
+ const { http, functions } = await getInspectorState()
23
+
17
24
  const schemas = await generateSchemas(
18
25
  logger,
19
26
  tsconfig,
@@ -50,8 +57,6 @@ export const pikkuOpenAPI: any = pikkuSessionlessFunc<void, void>({
50
57
  logCommandInfoAndTime({
51
58
  commandStart: 'Creating OpenAPI spec',
52
59
  commandEnd: 'Created OpenAPI spec',
53
- skipCondition: ({ config }) => config.openAPI?.outputFile === undefined,
54
- skipMessage: 'openAPI outfile is not defined',
55
60
  }),
56
61
  ],
57
62
  })
@@ -30,11 +30,6 @@ export const pikkuHTTP: any = pikkuSessionlessFunc<void, boolean>({
30
30
  logCommandInfoAndTime({
31
31
  commandStart: 'Finding HTTP routes',
32
32
  commandEnd: 'Found HTTP routes',
33
- skipCondition: async ({ getInspectorState }) => {
34
- const visitState = await getInspectorState()
35
- return visitState.http.files.size === 0
36
- },
37
- skipMessage: 'none found',
38
33
  }),
39
34
  ],
40
35
  })
@@ -3,11 +3,10 @@
3
3
  */
4
4
  export const serializeHTTPTypes = (functionTypesImportPath: string) => {
5
5
  return `/**
6
- * This file was generated by the @pikku/cli
7
6
  * HTTP-specific type definitions for tree-shaking optimization
8
7
  */
9
8
 
10
- import { AssertHTTPWiringParams, wireHTTP as wireHTTPCore, addHTTPMiddleware as addHTTPMiddlewareCore } from '@pikku/core/http'
9
+ import { AssertHTTPWiringParams, wireHTTP as wireHTTPCore, addHTTPMiddleware as addHTTPMiddlewareCore, addHTTPPermission as addHTTPPermissionCore } from '@pikku/core/http'
11
10
  import type { PikkuFunction, PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware } from '${functionTypesImportPath}'
12
11
  import type { CoreHTTPFunctionWiring } from '@pikku/core/http'
13
12
 
@@ -60,5 +59,31 @@ export const addHTTPMiddleware = (
60
59
  ) => {
61
60
  addHTTPMiddlewareCore(routeOrMiddleware as any, middleware as any)
62
61
  }
62
+
63
+ /**
64
+ * Registers HTTP permissions either globally or for a specific route pattern.
65
+ *
66
+ * When a string route pattern is provided along with permissions, the permissions
67
+ * are applied only to that route. Permissions can be passed as an array or as a
68
+ * permission group object.
69
+ *
70
+ * @param pattern - Route pattern string (e.g., '*' for all routes, '/api/*' for specific routes)
71
+ * @param permissions - The permissions to apply for the specified route pattern
72
+ *
73
+ * @example
74
+ * \`\`\`typescript
75
+ * // Add global HTTP permissions
76
+ * addHTTPPermission('*', { global: globalPermission })
77
+ *
78
+ * // Add route-specific permissions
79
+ * addHTTPPermission('/api/admin/*', { admin: adminPermission })
80
+ * \`\`\`
81
+ */
82
+ export const addHTTPPermission = <In = unknown>(
83
+ pattern: string,
84
+ permissions: Record<string, PikkuPermission<In>> | PikkuPermission<In>[]
85
+ ) => {
86
+ addHTTPPermissionCore(pattern, permissions as any)
87
+ }
63
88
  `
64
89
  }
@@ -28,11 +28,6 @@ export const pikkuMCPJSON: any = pikkuSessionlessFunc<void, void>({
28
28
  logCommandInfoAndTime({
29
29
  commandStart: 'Generating MCP JSON',
30
30
  commandEnd: 'Generated MCP JSON',
31
- skipCondition: async ({ getInspectorState, config }) => {
32
- const { mcpEndpoints } = await getInspectorState()
33
- return mcpEndpoints.files.size === 0 || !config.mcpJsonFile
34
- },
35
- skipMessage: 'none found or mcpJsonFile not set',
36
31
  }),
37
32
  ],
38
33
  })
@@ -20,8 +20,6 @@ export const pikkuMCPTypes: any = pikkuSessionlessFunc<void, void>({
20
20
  logCommandInfoAndTime({
21
21
  commandStart: 'Creating MCP types',
22
22
  commandEnd: 'Created MCP types',
23
- skipCondition: false,
24
- skipMessage: '',
25
23
  }),
26
24
  ],
27
25
  })
@@ -109,11 +109,6 @@ pikkuState('mcp', 'promptsMeta', ${JSON.stringify(promptsMetaWithArguments, null
109
109
  logCommandInfoAndTime({
110
110
  commandStart: 'Finding MCP endpoints',
111
111
  commandEnd: 'Found MCP endpoints',
112
- skipCondition: async ({ getInspectorState }) => {
113
- const { mcpEndpoints } = await getInspectorState()
114
- return mcpEndpoints.files.size === 0
115
- },
116
- skipMessage: 'none found',
117
112
  }),
118
113
  ],
119
114
  })
@@ -1,6 +1,6 @@
1
1
  import { readFile } from 'fs/promises'
2
2
  import { join } from 'path'
3
- import { MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from '@pikku/core'
3
+ import { MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from '@pikku/core/mcp'
4
4
  import { FunctionsMeta, JSONValue } from '@pikku/core'
5
5
  import { TypesMap } from '@pikku/inspector'
6
6
  import { CLILogger } from '../../../services/cli-logger.service.js'
@@ -3,7 +3,6 @@
3
3
  */
4
4
  export const serializeMCPTypes = (functionTypesImportPath: string) => {
5
5
  return `/**
6
- * This file was generated by the @pikku/cli
7
6
  * MCP-specific type definitions for tree-shaking optimization
8
7
  */
9
8
 
@@ -16,8 +15,9 @@ import {
16
15
  wireMCPPrompt as wireMCPPromptCore,
17
16
  MCPResourceResponse,
18
17
  MCPToolResponse,
19
- MCPPromptResponse
20
- } from '@pikku/core'
18
+ MCPPromptResponse,
19
+ AssertMCPResourceURIParams
20
+ } from '@pikku/core/mcp'
21
21
 
22
22
  import type { PikkuFunctionConfig, PikkuFunctionSessionless } from '${functionTypesImportPath}'
23
23
 
@@ -25,8 +25,9 @@ import type { PikkuFunctionConfig, PikkuFunctionSessionless } from '${functionTy
25
25
  * Type definition for MCP resources that provide data to AI models.
26
26
  *
27
27
  * @template In - Input type for the resource request
28
+ * @template URI - URI template string type for compile-time parameter validation
28
29
  */
29
- type MCPResourceWiring<In> = CoreMCPResource<PikkuFunctionConfig<In, MCPResourceResponse>>
30
+ type MCPResourceWiring<In, URI extends string> = CoreMCPResource<PikkuFunctionConfig<In, MCPResourceResponse>> & { uri: URI }
30
31
 
31
32
  /**
32
33
  * Type definition for MCP tools that AI models can invoke.
@@ -47,10 +48,11 @@ type MCPPromptWiring<In> = CoreMCPPrompt<PikkuFunctionConfig<In, MCPPromptRespon
47
48
  * Resources provide data that AI models can access.
48
49
  *
49
50
  * @template In - Input type for the resource request
51
+ * @template URI - URI template string for compile-time parameter validation
50
52
  * @param mcpResource - MCP resource definition with data provider function
51
53
  */
52
- export const wireMCPResource = <In>(
53
- mcpResource: MCPResourceWiring<In>
54
+ export const wireMCPResource = <In, URI extends string>(
55
+ mcpResource: MCPResourceWiring<In, URI> & AssertMCPResourceURIParams<In, URI>
54
56
  ) => {
55
57
  wireMCPResourceCore(mcpResource as any)
56
58
  }
@@ -96,8 +98,8 @@ export const pikkuMCPPromptFunc = <In>(
96
98
  func: PikkuFunctionSessionless<In, MCPPromptResponse>
97
99
  name?: string
98
100
  }
99
- ) => {
100
- return typeof func === 'function' ? func : func.func
101
+ ): PikkuFunctionConfig<In, MCPPromptResponse> => {
102
+ return typeof func === 'function' ? { func } : func
101
103
  }
102
104
 
103
105
  /**
@@ -115,8 +117,8 @@ export const pikkuMCPToolFunc = <In>(
115
117
  func: PikkuFunctionSessionless<In, MCPToolResponse, null, true>
116
118
  name?: string
117
119
  }
118
- ) => {
119
- return typeof func === 'function' ? func : func.func
120
+ ): PikkuFunctionConfig<In, MCPToolResponse> => {
121
+ return typeof func === 'function' ? { func } : func
120
122
  }
121
123
 
122
124
  /**
@@ -134,8 +136,8 @@ export const pikkuMCPResourceFunc = <In>(
134
136
  func: PikkuFunctionSessionless<In, MCPResourceResponse, null, true>
135
137
  name?: string
136
138
  }
137
- ) => {
138
- return typeof func === 'function' ? func : func.func
139
+ ): PikkuFunctionConfig<In, MCPResourceResponse> => {
140
+ return typeof func === 'function' ? { func } : func
139
141
  }
140
142
  `
141
143
  }