@pikku/addon-meta-conversions 0.1.1 → 0.1.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 (258) hide show
  1. package/.pikku/addon/pikku-addon-types.gen.ts +105 -0
  2. package/.pikku/addon/pikku-package.gen.ts +11 -0
  3. package/.pikku/agent/pikku-agent-map.gen.d.ts +4 -0
  4. package/.pikku/agent/pikku-agent-types.gen.ts +84 -0
  5. package/.pikku/channel/pikku-channel-types.gen.ts +177 -0
  6. package/.pikku/console/pikku-addon-meta.gen.json +36 -0
  7. package/.pikku/console/pikku-node-types.gen.ts +8 -0
  8. package/.pikku/function/pikku-function-types.gen.ts +797 -0
  9. package/.pikku/function/pikku-functions-meta-verbose.gen.json +33 -0
  10. package/.pikku/function/pikku-functions-meta.gen.json +27 -0
  11. package/.pikku/function/pikku-functions-meta.gen.ts +7 -0
  12. package/.pikku/function/pikku-functions.gen.ts +8 -0
  13. package/.pikku/http/pikku-http-types.gen.ts +119 -0
  14. package/.pikku/mcp/pikku-mcp-types.gen.ts +183 -0
  15. package/.pikku/pikku-bootstrap-scenarios.gen.ts +9 -0
  16. package/.pikku/pikku-bootstrap.gen.ts +8 -0
  17. package/.pikku/pikku-meta-service.gen.ts +10 -0
  18. package/.pikku/pikku-services.gen.ts +50 -0
  19. package/.pikku/pikku-types.gen.ts +24 -0
  20. package/.pikku/queue/pikku-queue-types.gen.ts +27 -0
  21. package/.pikku/rpc/pikku-rpc-wirings-map.gen.d.ts +135 -0
  22. package/.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts +136 -0
  23. package/.pikku/rpc/pikku-rpc-wirings-map.remote.gen.d.ts +135 -0
  24. package/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +3 -0
  25. package/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.ts +6 -0
  26. package/.pikku/scenarios/features.gen.json +1 -0
  27. package/.pikku/scenarios/pikku-scenario-functions-meta.gen.json +1 -0
  28. package/.pikku/scenarios/pikku-scenario-functions-meta.gen.ts +12 -0
  29. package/.pikku/scenarios/pikku-scenario-functions.gen.ts +4 -0
  30. package/.pikku/scenarios/pikku-scenario-wirings-meta.gen.ts +15 -0
  31. package/.pikku/scenarios/pikku-scenario-wirings.gen.ts +4 -0
  32. package/.pikku/scenarios/schemas/register.gen.ts +4 -0
  33. package/.pikku/scheduler/pikku-scheduler-types.gen.ts +25 -0
  34. package/.pikku/schemas/register.gen.ts +15 -0
  35. package/.pikku/schemas/schemas/EventSendInput.schema.json +1 -0
  36. package/.pikku/schemas/schemas/EventSendOutput.schema.json +1 -0
  37. package/.pikku/schemas/schemas/SecretSchema_metaConversions.schema.json +1 -0
  38. package/.pikku/scopes/pikku-personas-meta.gen.json +1 -0
  39. package/.pikku/scopes/pikku-personas.gen.ts +52 -0
  40. package/.pikku/scopes/pikku-roles-meta.gen.json +1 -0
  41. package/.pikku/scopes/pikku-roles.gen.ts +41 -0
  42. package/.pikku/scopes/pikku-scope-types.gen.ts +7 -0
  43. package/.pikku/scopes/pikku-scopes-meta.gen.json +1 -0
  44. package/.pikku/scopes/pikku-scopes.gen.ts +58 -0
  45. package/.pikku/secrets/pikku-secret-types.gen.ts +5 -0
  46. package/.pikku/secrets/pikku-secrets-meta.gen.json +10 -0
  47. package/.pikku/secrets/pikku-secrets.gen.ts +36 -0
  48. package/.pikku/trigger/pikku-trigger-types.gen.ts +160 -0
  49. package/.pikku/variables/pikku-variable-types.gen.ts +5 -0
  50. package/.pikku/variables/pikku-variables-meta.gen.json +1 -0
  51. package/.pikku/variables/pikku-variables.gen.ts +34 -0
  52. package/.pikku/workflow/personas.gen.json +1 -0
  53. package/.pikku/workflow/pikku-personas.gen.ts +38 -0
  54. package/.pikku/workflow/pikku-scenario-step-map.gen.d.ts +18 -0
  55. package/.pikku/workflow/pikku-workflow-map.gen.d.ts +38 -0
  56. package/.pikku/workflow/pikku-workflow-types.gen.ts +591 -0
  57. package/.pikku/workflow/pikku-workflow-wirings-meta.gen.ts +9 -0
  58. package/.pikku/workflow/pikku-workflow-wirings.gen.ts +3 -0
  59. package/dist/.pikku/addon/pikku-addon-types.gen.d.ts +4 -4
  60. package/dist/.pikku/addon/pikku-addon-types.gen.d.ts.map +1 -1
  61. package/dist/.pikku/addon/pikku-addon-types.gen.js +7 -3
  62. package/dist/.pikku/addon/pikku-addon-types.gen.js.map +1 -1
  63. package/dist/.pikku/addon/pikku-addon-types.gen.ts +11 -6
  64. package/dist/.pikku/addon/pikku-package.gen.js +2 -1
  65. package/dist/.pikku/addon/pikku-package.gen.js.map +1 -1
  66. package/dist/.pikku/addon/pikku-package.gen.ts +3 -1
  67. package/dist/.pikku/agent/pikku-agent-map.gen.d.ts +2 -14
  68. package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +8 -6
  69. package/dist/.pikku/agent/pikku-agent-types.gen.d.ts.map +1 -1
  70. package/dist/.pikku/agent/pikku-agent-types.gen.js.map +1 -1
  71. package/dist/.pikku/agent/pikku-agent-types.gen.ts +15 -7
  72. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +112 -0
  73. package/dist/.pikku/channel/pikku-channel-types.gen.d.ts.map +1 -0
  74. package/dist/.pikku/channel/pikku-channel-types.gen.js +60 -0
  75. package/dist/.pikku/channel/pikku-channel-types.gen.js.map +1 -0
  76. package/dist/.pikku/channel/pikku-channel-types.gen.ts +177 -0
  77. package/dist/.pikku/console/pikku-addon-meta.gen.json +4 -1
  78. package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
  79. package/dist/.pikku/console/pikku-node-types.gen.ts +1 -1
  80. package/dist/.pikku/function/pikku-function-types.gen.d.ts +133 -133
  81. package/dist/.pikku/function/pikku-function-types.gen.d.ts.map +1 -1
  82. package/dist/.pikku/function/pikku-function-types.gen.js +98 -61
  83. package/dist/.pikku/function/pikku-function-types.gen.js.map +1 -1
  84. package/dist/.pikku/function/pikku-function-types.gen.ts +268 -157
  85. package/dist/.pikku/function/pikku-functions-meta-verbose.gen.json +5 -0
  86. package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
  87. package/dist/.pikku/function/pikku-functions-meta.gen.json +8 -1
  88. package/dist/.pikku/function/pikku-functions-meta.gen.ts +1 -1
  89. package/dist/.pikku/function/pikku-functions.gen.js +2 -2
  90. package/dist/.pikku/function/pikku-functions.gen.js.map +1 -1
  91. package/dist/.pikku/function/pikku-functions.gen.ts +2 -2
  92. package/dist/.pikku/http/pikku-http-types.gen.d.ts +98 -0
  93. package/dist/.pikku/http/pikku-http-types.gen.d.ts.map +1 -0
  94. package/dist/.pikku/http/pikku-http-types.gen.js +50 -0
  95. package/dist/.pikku/http/pikku-http-types.gen.js.map +1 -0
  96. package/dist/.pikku/http/pikku-http-types.gen.ts +119 -0
  97. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +131 -0
  98. package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts.map +1 -0
  99. package/dist/.pikku/mcp/pikku-mcp-types.gen.js +38 -0
  100. package/dist/.pikku/mcp/pikku-mcp-types.gen.js.map +1 -0
  101. package/dist/.pikku/mcp/pikku-mcp-types.gen.ts +183 -0
  102. package/dist/.pikku/pikku-bootstrap-scenarios.gen.d.ts +10 -0
  103. package/dist/.pikku/pikku-bootstrap-scenarios.gen.d.ts.map +1 -0
  104. package/dist/.pikku/pikku-bootstrap-scenarios.gen.js +10 -0
  105. package/dist/.pikku/pikku-bootstrap-scenarios.gen.js.map +1 -0
  106. package/dist/.pikku/pikku-bootstrap-scenarios.gen.ts +9 -0
  107. package/dist/.pikku/pikku-bootstrap.gen.d.ts +4 -2
  108. package/dist/.pikku/pikku-bootstrap.gen.d.ts.map +1 -1
  109. package/dist/.pikku/pikku-bootstrap.gen.js +2 -10
  110. package/dist/.pikku/pikku-bootstrap.gen.js.map +1 -1
  111. package/dist/.pikku/pikku-bootstrap.gen.ts +2 -9
  112. package/dist/.pikku/pikku-meta-service.gen.d.ts +8 -0
  113. package/dist/.pikku/pikku-meta-service.gen.d.ts.map +1 -0
  114. package/dist/.pikku/pikku-meta-service.gen.js +10 -0
  115. package/dist/.pikku/pikku-meta-service.gen.js.map +1 -0
  116. package/dist/.pikku/pikku-meta-service.gen.ts +10 -0
  117. package/dist/.pikku/pikku-services.gen.d.ts +15 -2
  118. package/dist/.pikku/pikku-services.gen.d.ts.map +1 -1
  119. package/dist/.pikku/pikku-services.gen.js +14 -0
  120. package/dist/.pikku/pikku-services.gen.js.map +1 -1
  121. package/dist/.pikku/pikku-services.gen.ts +17 -2
  122. package/dist/.pikku/pikku-types.gen.d.ts +2 -1
  123. package/dist/.pikku/pikku-types.gen.d.ts.map +1 -1
  124. package/dist/.pikku/pikku-types.gen.js +3 -1
  125. package/dist/.pikku/pikku-types.gen.js.map +1 -1
  126. package/dist/.pikku/pikku-types.gen.ts +4 -1
  127. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +24 -0
  128. package/dist/.pikku/queue/pikku-queue-types.gen.d.ts.map +1 -0
  129. package/dist/.pikku/queue/pikku-queue-types.gen.js +17 -0
  130. package/dist/.pikku/queue/pikku-queue-types.gen.js.map +1 -0
  131. package/dist/.pikku/queue/pikku-queue-types.gen.ts +27 -0
  132. package/dist/.pikku/rpc/pikku-rpc-wirings-map.gen.d.ts +28 -8
  133. package/dist/.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts +28 -8
  134. package/dist/.pikku/rpc/pikku-rpc-wirings-map.remote.gen.d.ts +135 -0
  135. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.d.ts +2 -0
  136. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.d.ts.map +1 -0
  137. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +7 -0
  138. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js.map +1 -0
  139. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +3 -0
  140. package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.ts +6 -0
  141. package/dist/.pikku/scenarios/features.gen.json +1 -0
  142. package/dist/.pikku/scenarios/pikku-scenario-functions-meta.gen.d.ts +2 -0
  143. package/dist/.pikku/scenarios/pikku-scenario-functions-meta.gen.d.ts.map +1 -0
  144. package/dist/.pikku/scenarios/pikku-scenario-functions-meta.gen.js +11 -0
  145. package/dist/.pikku/scenarios/pikku-scenario-functions-meta.gen.js.map +1 -0
  146. package/dist/.pikku/scenarios/pikku-scenario-functions-meta.gen.json +1 -0
  147. package/dist/.pikku/scenarios/pikku-scenario-functions-meta.gen.ts +12 -0
  148. package/dist/.pikku/scenarios/pikku-scenario-functions.gen.d.ts +5 -0
  149. package/dist/.pikku/scenarios/pikku-scenario-functions.gen.d.ts.map +1 -0
  150. package/dist/.pikku/scenarios/pikku-scenario-functions.gen.js +2 -0
  151. package/dist/.pikku/scenarios/pikku-scenario-functions.gen.js.map +1 -0
  152. package/dist/.pikku/scenarios/pikku-scenario-functions.gen.ts +4 -0
  153. package/dist/.pikku/scenarios/pikku-scenario-wirings-meta.gen.d.ts +2 -0
  154. package/dist/.pikku/scenarios/pikku-scenario-wirings-meta.gen.d.ts.map +1 -0
  155. package/dist/.pikku/scenarios/pikku-scenario-wirings-meta.gen.js +11 -0
  156. package/dist/.pikku/scenarios/pikku-scenario-wirings-meta.gen.js.map +1 -0
  157. package/dist/.pikku/scenarios/pikku-scenario-wirings-meta.gen.ts +15 -0
  158. package/dist/.pikku/scenarios/pikku-scenario-wirings.gen.d.ts +5 -0
  159. package/dist/.pikku/scenarios/pikku-scenario-wirings.gen.d.ts.map +1 -0
  160. package/dist/.pikku/scenarios/pikku-scenario-wirings.gen.js +2 -0
  161. package/dist/.pikku/scenarios/pikku-scenario-wirings.gen.js.map +1 -0
  162. package/dist/.pikku/scenarios/pikku-scenario-wirings.gen.ts +4 -0
  163. package/dist/.pikku/scenarios/schemas/register.gen.d.ts +5 -0
  164. package/dist/.pikku/scenarios/schemas/register.gen.d.ts.map +1 -0
  165. package/dist/.pikku/scenarios/schemas/register.gen.js +5 -0
  166. package/dist/.pikku/scenarios/schemas/register.gen.js.map +1 -0
  167. package/dist/.pikku/scenarios/schemas/register.gen.ts +4 -0
  168. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +22 -0
  169. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts.map +1 -0
  170. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +17 -0
  171. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js.map +1 -0
  172. package/dist/.pikku/scheduler/pikku-scheduler-types.gen.ts +25 -0
  173. package/dist/.pikku/schemas/register.gen.js +1 -1
  174. package/dist/.pikku/schemas/register.gen.ts +1 -1
  175. package/dist/.pikku/scopes/pikku-personas-meta.gen.json +1 -0
  176. package/dist/.pikku/scopes/pikku-personas.gen.d.ts +37 -0
  177. package/dist/.pikku/scopes/pikku-personas.gen.d.ts.map +1 -0
  178. package/dist/.pikku/scopes/pikku-personas.gen.js +18 -0
  179. package/dist/.pikku/scopes/pikku-personas.gen.js.map +1 -0
  180. package/dist/.pikku/scopes/pikku-personas.gen.ts +52 -0
  181. package/dist/.pikku/scopes/pikku-roles-meta.gen.json +1 -0
  182. package/dist/.pikku/scopes/pikku-roles.gen.d.ts +31 -0
  183. package/dist/.pikku/scopes/pikku-roles.gen.d.ts.map +1 -0
  184. package/dist/.pikku/scopes/pikku-roles.gen.js +19 -0
  185. package/dist/.pikku/scopes/pikku-roles.gen.js.map +1 -0
  186. package/dist/.pikku/scopes/pikku-roles.gen.ts +41 -0
  187. package/dist/.pikku/scopes/pikku-scope-types.gen.d.ts +8 -0
  188. package/dist/.pikku/scopes/pikku-scope-types.gen.d.ts.map +1 -0
  189. package/dist/.pikku/scopes/pikku-scope-types.gen.js +6 -0
  190. package/dist/.pikku/scopes/pikku-scope-types.gen.js.map +1 -0
  191. package/dist/.pikku/scopes/pikku-scope-types.gen.ts +7 -0
  192. package/dist/.pikku/scopes/pikku-scopes-meta.gen.json +1 -0
  193. package/dist/.pikku/scopes/pikku-scopes.gen.d.ts +36 -0
  194. package/dist/.pikku/scopes/pikku-scopes.gen.d.ts.map +1 -0
  195. package/dist/.pikku/scopes/pikku-scopes.gen.js +28 -0
  196. package/dist/.pikku/scopes/pikku-scopes.gen.js.map +1 -0
  197. package/dist/.pikku/scopes/pikku-scopes.gen.ts +58 -0
  198. package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +2 -2
  199. package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts.map +1 -1
  200. package/dist/.pikku/secrets/pikku-secret-types.gen.js +2 -2
  201. package/dist/.pikku/secrets/pikku-secret-types.gen.js.map +1 -1
  202. package/dist/.pikku/secrets/pikku-secret-types.gen.ts +2 -2
  203. package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +11 -1
  204. package/dist/.pikku/secrets/pikku-secrets.gen.d.ts.map +1 -1
  205. package/dist/.pikku/secrets/pikku-secrets.gen.js +12 -2
  206. package/dist/.pikku/secrets/pikku-secrets.gen.js.map +1 -1
  207. package/dist/.pikku/secrets/pikku-secrets.gen.ts +15 -2
  208. package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
  209. package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
  210. package/dist/.pikku/trigger/pikku-trigger-types.gen.ts +1 -1
  211. package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +2 -2
  212. package/dist/.pikku/variables/pikku-variable-types.gen.d.ts.map +1 -1
  213. package/dist/.pikku/variables/pikku-variable-types.gen.js +2 -2
  214. package/dist/.pikku/variables/pikku-variable-types.gen.js.map +1 -1
  215. package/dist/.pikku/variables/pikku-variable-types.gen.ts +2 -2
  216. package/dist/.pikku/variables/pikku-variables.gen.d.ts +11 -1
  217. package/dist/.pikku/variables/pikku-variables.gen.d.ts.map +1 -1
  218. package/dist/.pikku/variables/pikku-variables.gen.js +13 -3
  219. package/dist/.pikku/variables/pikku-variables.gen.js.map +1 -1
  220. package/dist/.pikku/variables/pikku-variables.gen.ts +16 -3
  221. package/dist/.pikku/workflow/personas.gen.json +1 -0
  222. package/dist/.pikku/workflow/pikku-personas.gen.d.ts +16 -0
  223. package/dist/.pikku/workflow/pikku-personas.gen.d.ts.map +1 -0
  224. package/dist/.pikku/workflow/pikku-personas.gen.js +18 -0
  225. package/dist/.pikku/workflow/pikku-personas.gen.js.map +1 -0
  226. package/dist/.pikku/workflow/pikku-personas.gen.ts +38 -0
  227. package/dist/.pikku/workflow/pikku-scenario-step-map.gen.d.ts +18 -0
  228. package/dist/.pikku/workflow/pikku-workflow-map.gen.d.ts +9 -5
  229. package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +289 -31
  230. package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts.map +1 -1
  231. package/dist/.pikku/workflow/pikku-workflow-types.gen.js +66 -18
  232. package/dist/.pikku/workflow/pikku-workflow-types.gen.js.map +1 -1
  233. package/dist/.pikku/workflow/pikku-workflow-types.gen.ts +494 -61
  234. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
  235. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js.map +1 -1
  236. package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.ts +3 -3
  237. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.d.ts +1 -1
  238. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
  239. package/dist/.pikku/workflow/pikku-workflow-wirings.gen.ts +1 -1
  240. package/dist/src/functions/events/send.function.d.ts +2 -2
  241. package/dist/src/functions/events/send.function.d.ts.map +1 -1
  242. package/dist/src/meta-conversions.secret.js +2 -2
  243. package/dist/src/meta-conversions.secret.js.map +1 -1
  244. package/dist/src/services.d.ts.map +1 -1
  245. package/dist/src/services.js +1 -1
  246. package/dist/src/services.js.map +1 -1
  247. package/package.json +7 -6
  248. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.d.ts +0 -2
  249. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.d.ts.map +0 -1
  250. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.js +0 -7
  251. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.js.map +0 -1
  252. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.json +0 -3
  253. package/dist/.pikku/agent/pikku-agent-wirings-meta.gen.ts +0 -7
  254. package/dist/.pikku/agent/pikku-agent-wirings.gen.d.ts +0 -5
  255. package/dist/.pikku/agent/pikku-agent-wirings.gen.d.ts.map +0 -1
  256. package/dist/.pikku/agent/pikku-agent-wirings.gen.js +0 -5
  257. package/dist/.pikku/agent/pikku-agent-wirings.gen.js.map +0 -1
  258. package/dist/.pikku/agent/pikku-agent-wirings.gen.ts +0 -3
@@ -0,0 +1,797 @@
1
+ /**
2
+ * This file was generated by @pikku/cli@0.12.96
3
+ */
4
+ /**
5
+ * Core function, middleware, and permission types for all wirings
6
+ */
7
+
8
+ import type { CorePikkuMiddleware, CorePermissionGroup, ListInput, ListOutput, PikkuWire, PickRequired, SecretlessServices, SecretService } from '@pikku/core'
9
+ import type { CorePikkuFunctionConfig, CorePikkuAuth, CorePikkuAuthConfig, CorePikkuPermission } from '@pikku/core/function'
10
+ import { pikkuAuth as pikkuAuthCore } from '@pikku/core/function'
11
+ import {
12
+ addTagMiddleware as addTagMiddlewareCore,
13
+ addGlobalMiddleware as addGlobalMiddlewareCore,
14
+ addGlobalPermission as addGlobalPermissionCore,
15
+ } from '@pikku/core/middleware'
16
+ import { pikkuState as __pikkuState, CreateWireServices } from '@pikku/core/internal'
17
+ import type { NodeType } from '@pikku/core/node'
18
+ import type { ScopeId } from '../scopes/pikku-scopes.gen.js'
19
+ import type { StandardSchemaV1 } from '@standard-schema/spec'
20
+ import { CorePikkuFunction, CorePikkuFunctionSessionless } from '@pikku/core/function'
21
+
22
+ import type { UserSession } from '../../types/application-types.d.js'
23
+ import type { SingletonServices } from '../../types/application-types.d.js'
24
+ import type { Services } from '../../types/application-types.d.js'
25
+ import type { Config } from '../../types/application-types.d.js'
26
+ import type { TypedPikkuRPC, FlattenedRPCMap } from '../rpc/pikku-rpc-wirings-map.internal.gen.d.js'
27
+ import type { RequiredSingletonServices, RequiredWireServices } from '../pikku-services.gen.js'
28
+ import type { TypedWorkflow, TypedScenario, TypedPersonas } from '../workflow/pikku-workflow-types.gen.js'
29
+
30
+ export type { SingletonServices as SingletonServices }
31
+ export type { Services as Services }
32
+ export type Session = UserSession
33
+
34
+
35
+ /**
36
+ * The services a wired function actually receives. The inspector records which
37
+ * services each wired `func`, `permissions` and `middleware` destructures and
38
+ * emits them as `RequiredSingletonServices`; intersecting that here makes those
39
+ * services **non-optional** at every call site. A service is optional only when
40
+ * nothing destructures it — in which case it is never created either. This is
41
+ * why an `if (!service)` guard inside a function body is always dead code.
42
+ */
43
+ export type WiredSingletonServices = RequiredSingletonServices & SingletonServices
44
+ export type WiredServices = SecretlessServices<RequiredSingletonServices & Services>
45
+
46
+ /** `WiredSingletonServices` without `secrets`, for auth gates. */
47
+ export type WiredAuthServices = SecretlessServices<WiredSingletonServices>
48
+
49
+ /**
50
+ * `WiredServices` with `secrets` restored, for the console's secret-admin
51
+ * functions. Reached by declaring `secretBroker: true` on a `pikkuFunc` config.
52
+ *
53
+ * Declaring it does not grant the service. The runner hands out the real
54
+ * `SecretService` only to the functions the inspector marks as secret brokers;
55
+ * every other function still receives the throwing accessor.
56
+ */
57
+ export type WiredSecretBrokerServices = WiredServices & { secrets: SecretService }
58
+
59
+ /**
60
+ * Inline node configuration for function definitions.
61
+ */
62
+ export type NodeConfig = {
63
+ displayName: string
64
+ category: 'Events'
65
+ type: NodeType
66
+ errorOutput?: boolean
67
+ }
68
+
69
+ /**
70
+ * Type-safe API permission definition that integrates with your application's session type.
71
+ * Use this to define authorization logic for your API endpoints.
72
+ *
73
+ * @template In - The input type that the permission check will receive
74
+ * @template RequiredServices - The services required for this permission check
75
+ */
76
+ export type PikkuPermission<In = unknown, RequiredServices extends SecretlessServices<Services> = WiredServices> = CorePikkuPermission<In, RequiredServices, PikkuWire<In, never, false, Session>>
77
+
78
+ /**
79
+ * Type-safe middleware definition that can access your application's services and session.
80
+ * Use this to define reusable middleware that can be applied to multiple wirings.
81
+ *
82
+ * @template RequiredServices - The services required for this middleware
83
+ */
84
+ export type PikkuMiddleware<RequiredServices extends SingletonServices = WiredSingletonServices> = CorePikkuMiddleware<RequiredServices>
85
+
86
+ /**
87
+ * Configuration object for creating a permission with metadata
88
+ */
89
+ export type PikkuPermissionConfig<In = unknown, RequiredServices extends SecretlessServices<Services> = WiredServices> = {
90
+ /** The permission function */
91
+ func: PikkuPermission<In, RequiredServices>
92
+ /** Optional human-readable name for the permission */
93
+ name?: string
94
+ /** Optional description of what the permission checks */
95
+ description?: string
96
+ }
97
+
98
+ /**
99
+ * Factory function for creating permissions with tree-shaking support.
100
+ * Supports both direct function and configuration object syntax.
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * // Direct function syntax
105
+ * const permission = pikkuPermission(async ({ logger }, data, { session }) => {
106
+ * const session = await session?.get()
107
+ * return session?.role === 'admin'
108
+ * })
109
+ *
110
+ * // Configuration object syntax with metadata
111
+ * const adminPermission = pikkuPermission({
112
+ * name: 'Admin Permission',
113
+ * description: 'Checks if user has admin role',
114
+ * func: async ({ logger }, data, { session }) => {
115
+ * const session = await session?.get()
116
+ * return session?.role === 'admin'
117
+ * }
118
+ * })
119
+ * ```
120
+ */
121
+ export const pikkuPermission = <In>(
122
+ permission: PikkuPermission<In> | PikkuPermissionConfig<In>
123
+ ): PikkuPermission<In> => {
124
+ return typeof permission === 'function' ? permission : permission.func
125
+ }
126
+
127
+ /**
128
+ * Type-safe auth-only permission that only needs services and session.
129
+ * Use this for upfront authorization gates (MCP tools, AI agents, workflows)
130
+ * where request data isn't available yet.
131
+ *
132
+ * @template RequiredServices - The services required for this auth check
133
+ */
134
+ export type PikkuAuth<RequiredServices extends SecretlessServices<SingletonServices> = WiredAuthServices> = CorePikkuAuth<RequiredServices, Session>
135
+
136
+ /**
137
+ * Configuration object for creating an auth permission with metadata
138
+ */
139
+ export type PikkuAuthConfig<RequiredServices extends SecretlessServices<SingletonServices> = WiredAuthServices> = CorePikkuAuthConfig<RequiredServices, Session>
140
+
141
+ /**
142
+ * Factory function for creating auth-only permissions with tree-shaking support.
143
+ * Auth permissions only receive services and session (no request data),
144
+ * making them evaluable before request data is available.
145
+ *
146
+ * @example
147
+ * \`\`\`typescript
148
+ * const isAuthenticated = pikkuAuth(async ({ logger }, session) => {
149
+ * return !!session
150
+ * })
151
+ *
152
+ * const isAdmin = pikkuAuth({
153
+ * name: 'Admin Auth',
154
+ * description: 'Checks if user is an admin',
155
+ * func: async ({ logger }, session) => {
156
+ * return session?.role === 'admin'
157
+ * }
158
+ * })
159
+ * \`\`\`
160
+ */
161
+ export const pikkuAuth = <RequiredServices extends SecretlessServices<SingletonServices> = WiredAuthServices>(
162
+ auth: PikkuAuth<RequiredServices> | PikkuAuthConfig<RequiredServices>
163
+ ): PikkuPermission<any, any> => {
164
+ return pikkuAuthCore(auth as any) as any
165
+ }
166
+
167
+ /**
168
+ * Configuration object for creating middleware with metadata
169
+ */
170
+ export type PikkuMiddlewareConfig<RequiredServices extends SingletonServices = WiredSingletonServices> = {
171
+ /** The middleware function */
172
+ func: PikkuMiddleware<RequiredServices>
173
+ /** Optional human-readable name for the middleware */
174
+ name?: string
175
+ /** Optional description of what the middleware does */
176
+ description?: string
177
+ }
178
+
179
+ /**
180
+ * Factory function for creating middleware with tree-shaking support.
181
+ * Supports both direct function and configuration object syntax.
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * // Direct function syntax
186
+ * const middleware = pikkuMiddleware(({ logger }, wires, next) => {
187
+ * logger.info('Middleware executed')
188
+ * await next()
189
+ * })
190
+ *
191
+ * // Configuration object syntax with metadata
192
+ * const logMiddleware = pikkuMiddleware({
193
+ * name: 'Request Logger',
194
+ * description: 'Logs all incoming requests',
195
+ * func: async ({ logger }, wires, next) => {
196
+ * logger.info('Request started')
197
+ * await next()
198
+ * }
199
+ * })
200
+ * ```
201
+ */
202
+ export const pikkuMiddleware = <RequiredServices extends SingletonServices = WiredSingletonServices>(
203
+ middleware: PikkuMiddleware<RequiredServices> | PikkuMiddlewareConfig<RequiredServices>
204
+ ): PikkuMiddleware<RequiredServices> => {
205
+ return typeof middleware === 'function' ? middleware : middleware.func
206
+ }
207
+
208
+ /**
209
+ * Factory function for creating middleware factories
210
+ * Use this when your middleware needs configuration/input parameters
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * export const logMiddleware = pikkuMiddlewareFactory<LogOptions>(({
215
+ * message,
216
+ * level = 'info'
217
+ * }) => {
218
+ * return pikkuMiddleware(async ({ logger }, next) => {
219
+ * logger[level](message)
220
+ * await next()
221
+ * })
222
+ * })
223
+ * ```
224
+ */
225
+ export const pikkuMiddlewareFactory = <In = any>(
226
+ factory: (input: In) => PikkuMiddleware
227
+ ): ((input: In) => PikkuMiddleware) => {
228
+ return factory
229
+ }
230
+
231
+ /**
232
+ * Factory function for creating permission factories
233
+ * Use this when your permission needs configuration/input parameters
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * export const requireRole = pikkuPermissionFactory<{ role: string }>(({
238
+ * role
239
+ * }) => {
240
+ * return pikkuPermission(async ({ logger }, data, { session }) => {
241
+ * if (!session || session.role !== role) {
242
+ * logger.warn(`Permission denied: required role '${role}'`)
243
+ * return false
244
+ * }
245
+ * return true
246
+ * })
247
+ * })
248
+ * ```
249
+ */
250
+ export const pikkuPermissionFactory = <In = any>(
251
+ factory: (input: In) => PikkuPermission<any>
252
+ ): ((input: In) => PikkuPermission<any>) => {
253
+ return factory
254
+ }
255
+
256
+ /**
257
+ * A function that generates a human-readable description of a pending approval action.
258
+ * Used by AI agents to show meaningful approval prompts instead of raw tool arguments.
259
+ *
260
+ * @template In - The input type (same as the function it describes)
261
+ * @template RequiredServices - The services required for this description function
262
+ */
263
+ export type PikkuApprovalDescription<In = unknown, RequiredServices extends SecretlessServices<Services> = WiredServices> = (
264
+ services: RequiredServices,
265
+ data: In
266
+ ) => Promise<string>
267
+
268
+ /**
269
+ * Factory function for creating approval description functions with tree-shaking support.
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * export const deleteTodoApproval = pikkuApprovalDescription(
274
+ * async ({ todoStore }, { id }) => {
275
+ * const todo = await todoStore.get(id)
276
+ * return \`Delete todo: "${todo.title}"\`
277
+ * }
278
+ * )
279
+ * ```
280
+ */
281
+ export const pikkuApprovalDescription = <In = unknown, RequiredServices extends SecretlessServices<Services> = WiredServices>(
282
+ fn: PikkuApprovalDescription<In, RequiredServices>
283
+ ): PikkuApprovalDescription<In, RequiredServices> => {
284
+ return fn
285
+ }
286
+
287
+ /**
288
+ * A sessionless API function that doesn't require user authentication.
289
+ * Use this for public endpoints, health checks, or operations that don't need user context.
290
+ *
291
+ * @template In - The input type
292
+ * @template Out - The output type that the function returns
293
+ * @template RequiredServices - Services required by this function
294
+ */
295
+ export type PikkuFunctionSessionless<
296
+ In = unknown,
297
+ Out = never,
298
+ RequiredWires extends keyof PikkuWire = never,
299
+ RequiredServices extends SecretlessServices<Services> = WiredServices
300
+ > = CorePikkuFunctionSessionless<
301
+ In,
302
+ Out,
303
+ RequiredServices,
304
+ Session,
305
+ PickRequired<PikkuWire<In, Out, false, Session, TypedPikkuRPC, null, any, TypedWorkflow, unknown, TypedScenario, TypedPersonas>, RequiredWires>
306
+ >
307
+
308
+ /**
309
+ * A session-aware API function that requires user authentication.
310
+ * Use this for protected endpoints that need access to user session data.
311
+ *
312
+ * @template In - The input type
313
+ * @template Out - The output type that the function returns
314
+ * @template RequiredServices - Services required by this function
315
+ */
316
+ export type PikkuFunction<
317
+ In = unknown,
318
+ Out = never,
319
+ RequiredWires extends keyof PikkuWire = 'session',
320
+ RequiredServices extends SecretlessServices<Services> = WiredServices
321
+ > = CorePikkuFunction<
322
+ In,
323
+ Out,
324
+ RequiredServices,
325
+ Session,
326
+ PickRequired<PikkuWire<In, Out, true, Session, TypedPikkuRPC, null, any, TypedWorkflow, unknown, TypedScenario, TypedPersonas>, RequiredWires>
327
+ >
328
+
329
+ /**
330
+ * Helper type to infer the output type from a Standard Schema
331
+ */
332
+ export type InferSchemaOutput<T> = T extends StandardSchemaV1<any, infer Output> ? Output : never
333
+
334
+ /**
335
+ * Configuration object for Pikku functions with optional middleware, permissions, tags, and documentation.
336
+ * This type wraps CorePikkuFunctionConfig with the user's custom types.
337
+ *
338
+ * @template In - The input type
339
+ * @template Out - The output type
340
+ * @template PikkuFunc - The function type (can be narrowed to PikkuFunction or PikkuFunctionSessionless)
341
+ */
342
+ export type PikkuFunctionConfig<
343
+ In = unknown,
344
+ Out = unknown,
345
+ RequiredWires extends keyof PikkuWire = never,
346
+ PikkuFunc extends PikkuFunction<In, Out, RequiredWires, any> | PikkuFunctionSessionless<In, Out, RequiredWires, any> = PikkuFunction<In, Out, RequiredWires> | PikkuFunctionSessionless<In, Out, RequiredWires>,
347
+ InputSchema extends StandardSchemaV1 | undefined = undefined,
348
+ OutputSchema extends StandardSchemaV1 | undefined = undefined
349
+ > = CorePikkuFunctionConfig<PikkuFunc, PikkuPermission<In>, PikkuMiddleware, InputSchema, OutputSchema, ScopeId>
350
+
351
+ /**
352
+ * Configuration object for Pikku functions with Zod schema validation.
353
+ * Use this when you want to define input/output schemas using Zod.
354
+ * Types are automatically inferred from the schemas.
355
+ */
356
+ type SchemaInferred<S, Fallback = unknown> = S extends StandardSchemaV1
357
+ ? InferSchemaOutput<S>
358
+ : Fallback
359
+
360
+ /**
361
+ * Schema-overload variant for pikkuFunc. Derived from CorePikkuFunctionConfig
362
+ * so adding a field on the core type automatically propagates here.
363
+ */
364
+ export type PikkuFunctionConfigWithSchema<
365
+ InputSchema extends StandardSchemaV1 | undefined = undefined,
366
+ OutputSchema extends StandardSchemaV1 | undefined = undefined,
367
+ RequiredWires extends keyof PikkuWire = never,
368
+ RequiredServices extends SecretlessServices<Services> = WiredServices
369
+ > = Omit<
370
+ CorePikkuFunctionConfig<
371
+ | PikkuFunction<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires, RequiredServices>
372
+ | PikkuFunctionSessionless<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires, RequiredServices>,
373
+ CorePikkuPermission<any>,
374
+ PikkuMiddleware,
375
+ undefined,
376
+ undefined,
377
+ ScopeId
378
+ >,
379
+ 'func' | 'input' | 'output' | 'permissions' | 'approvalDescription'
380
+ > & {
381
+ func:
382
+ | PikkuFunction<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires, RequiredServices>
383
+ | PikkuFunctionSessionless<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires, RequiredServices>
384
+ input?: InputSchema
385
+ output?: OutputSchema
386
+ permissions?: InputSchema extends StandardSchemaV1
387
+ ? CorePermissionGroup<PikkuPermission<InferSchemaOutput<InputSchema>>>
388
+ : undefined
389
+ approvalDescription?: InputSchema extends StandardSchemaV1
390
+ ? PikkuApprovalDescription<InferSchemaOutput<InputSchema>>
391
+ : never
392
+ }
393
+
394
+ /**
395
+ * Creates a Pikku function that can be either session-aware or sessionless.
396
+ * This is the main function wrapper for creating API endpoints.
397
+ *
398
+ * Define the input and output with Zod schemas — the function's types are
399
+ * inferred from them, and the schemas double as runtime validation.
400
+ *
401
+ * @param config - Function definition with `input`/`output` Zod schemas and `func`.
402
+ * @returns The normalized configuration object
403
+ *
404
+ * @example
405
+ * ```typescript
406
+ * const createUserInput = z.object({ name: z.string(), email: z.string() })
407
+ * const createUserOutput = z.object({ id: z.number() })
408
+ *
409
+ * const createUser = pikkuFunc({
410
+ * input: createUserInput,
411
+ * output: createUserOutput,
412
+ * func: async ({db}, input) => {
413
+ * // input is typed as { name: string, email: string }
414
+ * const user = await db.users.create(input)
415
+ * return { id: user.id } // must match output schema
416
+ * }
417
+ * })
418
+ * ```
419
+ */
420
+ export function pikkuFunc<
421
+ InputSchema extends StandardSchemaV1 | undefined = undefined,
422
+ OutputSchema extends StandardSchemaV1 | undefined = undefined
423
+ >(
424
+ config: PikkuFunctionConfigWithSchema<InputSchema, OutputSchema, 'session' | 'rpc', WiredSecretBrokerServices> & { secretBroker: true }
425
+ ): PikkuFunctionConfig<InputSchema extends StandardSchemaV1 ? InferSchemaOutput<InputSchema> : unknown, OutputSchema extends StandardSchemaV1 ? InferSchemaOutput<OutputSchema> : unknown, 'session' | 'rpc'>
426
+ export function pikkuFunc<
427
+ InputSchema extends StandardSchemaV1 | undefined = undefined,
428
+ OutputSchema extends StandardSchemaV1 | undefined = undefined
429
+ >(
430
+ config: PikkuFunctionConfigWithSchema<InputSchema, OutputSchema, 'session' | 'rpc'>
431
+ ): PikkuFunctionConfig<InputSchema extends StandardSchemaV1 ? InferSchemaOutput<InputSchema> : unknown, OutputSchema extends StandardSchemaV1 ? InferSchemaOutput<OutputSchema> : unknown, 'session' | 'rpc'>
432
+ export function pikkuFunc<In, Out = unknown>(
433
+ func:
434
+ | PikkuFunction<In, Out, 'session' | 'rpc'>
435
+ | PikkuFunctionConfig<In, Out, 'session' | 'rpc'>
436
+ ): PikkuFunctionConfig<In, Out, 'session' | 'rpc'>
437
+ export function pikkuFunc(func: any) {
438
+ return typeof func === 'function' ? { func } : func
439
+ }
440
+
441
+ export type PikkuListFunction<
442
+ F extends Record<string, unknown> = {},
443
+ Row = unknown,
444
+ S extends string = never
445
+ > =
446
+ | PikkuFunction<ListInput<F, S>, ListOutput<Row>, 'session' | 'rpc'>
447
+ | PikkuFunctionSessionless<
448
+ ListInput<F, S>,
449
+ ListOutput<Row>,
450
+ 'session' | 'rpc'
451
+ >
452
+
453
+ export const pikkuListFunc = <
454
+ F extends Record<string, unknown> = {},
455
+ Row = unknown,
456
+ S extends string = never
457
+ >(
458
+ config: PikkuFunctionConfig<
459
+ ListInput<F, S>,
460
+ ListOutput<Row>,
461
+ 'session' | 'rpc'
462
+ >
463
+ ): PikkuFunctionConfig<ListInput<F, S>, ListOutput<Row>, 'session' | 'rpc'> => {
464
+ return pikkuFunc(config)
465
+ }
466
+
467
+ /**
468
+ * Configuration object for sessionless Pikku functions with Zod schema validation.
469
+ */
470
+ /**
471
+ * Schema-overload variant for pikkuSessionlessFunc. Derived from
472
+ * CorePikkuFunctionConfig to stay in sync with the generic-typed config.
473
+ */
474
+ export type PikkuFunctionSessionlessConfigWithSchema<
475
+ InputSchema extends StandardSchemaV1 | undefined = undefined,
476
+ OutputSchema extends StandardSchemaV1 | undefined = undefined,
477
+ RequiredWires extends keyof PikkuWire = never,
478
+ RequiredServices extends SecretlessServices<Services> = WiredServices
479
+ > = Omit<
480
+ CorePikkuFunctionConfig<
481
+ PikkuFunctionSessionless<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, RequiredWires, RequiredServices>
482
+ >,
483
+ 'func' | 'input' | 'output' | 'permissions' | 'approvalDescription'
484
+ > & {
485
+ func: PikkuFunctionSessionless<
486
+ SchemaInferred<InputSchema>,
487
+ SchemaInferred<OutputSchema>,
488
+ RequiredWires,
489
+ RequiredServices
490
+ >
491
+ input?: InputSchema
492
+ output?: OutputSchema
493
+ permissions?: InputSchema extends StandardSchemaV1
494
+ ? CorePermissionGroup<PikkuPermission<InferSchemaOutput<InputSchema>>>
495
+ : undefined
496
+ approvalDescription?: InputSchema extends StandardSchemaV1
497
+ ? PikkuApprovalDescription<InferSchemaOutput<InputSchema>>
498
+ : never
499
+ }
500
+
501
+ /**
502
+ * Creates a sessionless Pikku function that doesn't require user authentication.
503
+ * Use this for public endpoints, webhooks, or background tasks.
504
+ *
505
+ * Define the input and output with Zod schemas — the function's types are
506
+ * inferred from them, and the schemas double as runtime validation.
507
+ *
508
+ * @param config - Function definition with `input`/`output` Zod schemas and `func`.
509
+ * @returns The normalized configuration object
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * const greetInput = z.object({ name: z.string() })
514
+ * const greetOutput = z.object({ message: z.string() })
515
+ *
516
+ * const greet = pikkuSessionlessFunc({
517
+ * input: greetInput,
518
+ * output: greetOutput,
519
+ * func: async (_services, { name }) => {
520
+ * return { message: `Hello, ${name}!` }
521
+ * }
522
+ * })
523
+ * ```
524
+ */
525
+ export function pikkuSessionlessFunc<
526
+ InputSchema extends StandardSchemaV1 | undefined = undefined,
527
+ OutputSchema extends StandardSchemaV1 | undefined = undefined,
528
+ RequiredServices extends SecretlessServices<Services> = WiredServices
529
+ >(
530
+ config: PikkuFunctionSessionlessConfigWithSchema<InputSchema, OutputSchema, 'session' | 'rpc', RequiredServices>
531
+ ): PikkuFunctionConfig<InputSchema extends StandardSchemaV1 ? InferSchemaOutput<InputSchema> : unknown, OutputSchema extends StandardSchemaV1 ? InferSchemaOutput<OutputSchema> : unknown, 'session' | 'rpc'>
532
+ export function pikkuSessionlessFunc<In, Out = unknown, RequiredServices extends SecretlessServices<Services> = WiredServices>(
533
+ func:
534
+ | PikkuFunctionSessionless<In, Out, 'session' | 'rpc', RequiredServices>
535
+ | PikkuFunctionConfig<In, Out, 'session' | 'rpc', PikkuFunctionSessionless<In, Out, 'session' | 'rpc', RequiredServices>>
536
+ ): PikkuFunctionConfig<In, Out, 'session' | 'rpc'>
537
+ export function pikkuSessionlessFunc(func: any) {
538
+ return typeof func === 'function' ? { func } : func
539
+ }
540
+
541
+ /**
542
+ * Creates a function that takes no input and returns no output.
543
+ * Useful for health checks, triggers, or cleanup operations.
544
+ *
545
+ * @param func - Function definition, either direct function or configuration object
546
+ * @returns The normalized configuration object
547
+ *
548
+ * @example
549
+ * ```typescript
550
+ * const cleanupTempFiles = pikkuVoidFunc(async ({fileSystem, logger}) => {
551
+ * logger.info('Starting cleanup of temporary files')
552
+ * await fileSystem.deleteDirectory('/tmp/uploads')
553
+ * logger.info('Cleanup completed')
554
+ * })
555
+ * ```
556
+ */
557
+ export const pikkuVoidFunc = (
558
+ func:
559
+ | PikkuFunctionSessionless<void, void, 'session' | 'rpc'>
560
+ | PikkuFunctionConfig<void, void, 'session' | 'rpc'>
561
+ ) => {
562
+ return typeof func === 'function' ? { func } : func
563
+ }
564
+
565
+ /**
566
+ * References a registered function by name for use in any wiring.
567
+ * Works for both local and addon functions — resolves via RPC at runtime.
568
+ *
569
+ * @template Name - The function name (must be a key in FlattenedRPCMap)
570
+ * @param rpcName - The name of the function to reference
571
+ * @returns A Pikku function config that proxies calls via RPC
572
+ *
573
+ * @example
574
+ * ```typescript
575
+ * // Use in agent tools
576
+ * tools: [ref('todos:listTodos'), ref('myLocalFunc')]
577
+ *
578
+ * // Use in HTTP wiring
579
+ * wireHTTP({ route: '/greet', method: 'post', func: ref('greet') })
580
+ * ```
581
+ */
582
+ export const ref = <Name extends keyof FlattenedRPCMap>(
583
+ rpcName: Name
584
+ ): PikkuFunctionConfig<
585
+ FlattenedRPCMap[Name]['input'],
586
+ FlattenedRPCMap[Name]['output'],
587
+ 'session' | 'rpc'
588
+ > => {
589
+ return {
590
+ func: async (_services: any, data: FlattenedRPCMap[Name]['input'], { rpc }: any) => {
591
+ return rpc.invoke(rpcName, data)
592
+ }
593
+ } as PikkuFunctionConfig<
594
+ FlattenedRPCMap[Name]['input'],
595
+ FlattenedRPCMap[Name]['output'],
596
+ 'session' | 'rpc'
597
+ >
598
+ }
599
+
600
+ /**
601
+ * Declares a capability the connected client answers, reachable from any
602
+ * `wireChannel` function as `channel.remote(name, input)`.
603
+ *
604
+ * There is no `func`: this side owns the contract, the client owns the body.
605
+ * The `description` is what a person is shown when asked to approve the call,
606
+ * so write it for them rather than for the caller.
607
+ *
608
+ * @example
609
+ * ```typescript
610
+ * export const localCheckoutOutput = z.object({ sha: z.string(), branch: z.string() })
611
+ *
612
+ * export const localCheckout = pikkuRemoteChannelFunc({
613
+ * description: 'Read the current commit and branch of your working tree',
614
+ * output: localCheckoutOutput,
615
+ * })
616
+ * ```
617
+ */
618
+ export function pikkuRemoteChannelFunc<
619
+ InputSchema extends StandardSchemaV1 | undefined = undefined,
620
+ OutputSchema extends StandardSchemaV1 | undefined = undefined
621
+ >(
622
+ config: Omit<
623
+ PikkuFunctionSessionlessConfigWithSchema<InputSchema, OutputSchema, 'session' | 'rpc'>,
624
+ 'func'
625
+ >
626
+ ): PikkuFunctionConfig<SchemaInferred<InputSchema>, SchemaInferred<OutputSchema>, 'session' | 'rpc'> {
627
+ return {
628
+ ...config,
629
+ func: async (_services: any, _data: any, _wire: any) => {
630
+ throw new Error(
631
+ `${config.title ?? 'This'} is a remote channel capability and has no local implementation — reach it with channel.remote() on the channel whose client exposes it.`
632
+ )
633
+ },
634
+ } as any
635
+ }
636
+
637
+ /**
638
+ * Creates a Pikku config factory.
639
+ * Use this to define your application's configuration factory.
640
+ *
641
+ * @param func - Config factory function that returns your application's config
642
+ * @returns The config factory function
643
+ *
644
+ * @example
645
+ * ```typescript
646
+ * export const createConfig = pikkuConfig(async () => {
647
+ * return {
648
+ * apiUrl: process.env.API_URL || 'http://localhost:3000',
649
+ * dbUrl: process.env.DATABASE_URL
650
+ * }
651
+ * })
652
+ * ```
653
+ */
654
+ export const pikkuConfig = (
655
+ func: (variables?: any, ...args: any[]) => Promise<Config>
656
+ ) => func
657
+
658
+
659
+ /**
660
+ * Creates a Pikku singleton services factory.
661
+ * Use this to define services that are created once and shared across all requests.
662
+ *
663
+ * @param func - Singleton services factory function
664
+ * @returns The singleton services factory function
665
+ *
666
+ * @example
667
+ * ```typescript
668
+ * export const createSingletonServices = pikkuServices(async (config, existingServices) => {
669
+ * return {
670
+ * config,
671
+ * logger: new CustomLogger(),
672
+ * db: await createDatabaseConnection(config.dbUrl)
673
+ * }
674
+ * })
675
+ * ```
676
+ */
677
+ export const pikkuServices = (
678
+ func: (config: Config, existingServices: Partial<SingletonServices>) => Promise<Partial<Omit<RequiredSingletonServices, 'auth'>>>
679
+ ) => {
680
+ return async (config: Config, existingServices: Partial<SingletonServices> = {}) => {
681
+ const createdServices = await func(config, existingServices)
682
+ const services = { ...existingServices, ...createdServices }
683
+ const authFactory = __pikkuState(null, 'package', 'authFactory')
684
+ if (authFactory) {
685
+ let authInstance: Promise<unknown> | undefined
686
+ ;(services as any).auth = () => {
687
+ authInstance ??= Promise.resolve()
688
+ .then(() => authFactory(services as any))
689
+ .catch((error) => {
690
+ authInstance = undefined
691
+ throw error
692
+ })
693
+ return authInstance
694
+ }
695
+ }
696
+ const resolved = services as RequiredSingletonServices
697
+ __pikkuState(null, 'package', 'singletonServices', resolved as any)
698
+ return resolved
699
+ }
700
+ }
701
+
702
+ /**
703
+ * Creates a Pikku wire services factory.
704
+ * Use this to define services that are created per-request/session.
705
+ *
706
+ * @param func - Wire services factory function
707
+ * @returns The wire services factory function
708
+ *
709
+ * @example
710
+ * ```typescript
711
+ * export const createWireServices = pikkuWireServices(async (services, wire) => {
712
+ * const session = await wire.session?.get()
713
+ * return {
714
+ * userCache: new UserCache(session?.userId)
715
+ * }
716
+ * })
717
+ * ```
718
+ */
719
+ export const pikkuWireServices = (
720
+ func: (
721
+ services: SingletonServices,
722
+ wire: any
723
+ ) => Promise<RequiredWireServices>
724
+ ): CreateWireServices => {
725
+ const factories = __pikkuState(null, 'package', 'factories')
726
+ __pikkuState(null, 'package', 'factories', { ...factories, createWireServices: func as any })
727
+ return func as unknown as CreateWireServices
728
+ }
729
+
730
+ /**
731
+ * Tag-scoped middleware. Applies to any wiring that carries the matching tag.
732
+ *
733
+ * @example
734
+ * addTagMiddleware('admin', [adminMiddleware])
735
+ */
736
+ export const addTagMiddleware = (tag: string, middleware: PikkuMiddleware[]) => {
737
+ addTagMiddlewareCore(tag, middleware as any, '@pikku/addon-meta-conversions')
738
+ }
739
+
740
+ /**
741
+ * Wire-agnostic global middleware. Runs at the top of every wiring's
742
+ * middleware chain — before wire-, tag-, and function-level entries.
743
+ *
744
+ * Resolution order: global -> wire -> tag -> function.
745
+ *
746
+ * @example
747
+ * addGlobalMiddleware([telemetryMiddleware])
748
+ */
749
+ export const addGlobalMiddleware = (middleware: PikkuMiddleware[]) => {
750
+ addGlobalMiddlewareCore(middleware as any, '@pikku/addon-meta-conversions')
751
+ }
752
+
753
+ /**
754
+ * Wire-agnostic global permissions. Runs at the top of every wiring's
755
+ * permission resolution — before wire-, tag-, and function-level entries.
756
+ *
757
+ * Resolution order: global -> wire -> tag -> function.
758
+ *
759
+ * @example
760
+ * addGlobalPermission([signedInUser])
761
+ */
762
+ export const addGlobalPermission = <In = unknown>(permissions: CorePermissionGroup<PikkuPermission<In>> | PikkuPermission<In>[]) => {
763
+ addGlobalPermissionCore(permissions as any, '@pikku/addon-meta-conversions')
764
+ }
765
+
766
+ export { wireAddon, wireRemoteAddon } from '@pikku/core/rpc'
767
+ export type { WireAddonConfig, WireRemoteAddonConfig, RemoteAddonAuth } from '@pikku/core/rpc'
768
+
769
+
770
+ /**
771
+ * Addon contract references. Generated from each wired addon's published
772
+ * contract metadata — no addon source is imported. Functions are proxied via
773
+ * ref() (RPC) exactly like ref('namespace:fn').
774
+ */
775
+ const __addonHttp = {} as const
776
+ const __addonChannel = {} as const
777
+ const __addonCli = {} as const
778
+
779
+ export const refHTTP = <Name extends keyof typeof __addonHttp>(
780
+ name: Name,
781
+ options?: { basePath?: string }
782
+ ): (typeof __addonHttp)[Name] => {
783
+ const contract = __addonHttp[name] as any
784
+ return (
785
+ options?.basePath !== undefined
786
+ ? { ...contract, basePath: options.basePath }
787
+ : contract
788
+ ) as (typeof __addonHttp)[Name]
789
+ }
790
+
791
+ export const refChannel = <Name extends keyof typeof __addonChannel>(
792
+ name: Name
793
+ ): (typeof __addonChannel)[Name] => __addonChannel[name]
794
+
795
+ export const refCLI = <Name extends keyof typeof __addonCli>(
796
+ name: Name
797
+ ): (typeof __addonCli)[Name] => __addonCli[name]