@pikku/core 0.12.2 → 0.12.4

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 (282) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/crypto-utils.d.ts +10 -0
  3. package/dist/crypto-utils.js +62 -0
  4. package/dist/function/function-runner.js +4 -4
  5. package/dist/function/functions.types.d.ts +26 -1
  6. package/dist/function/functions.types.js +16 -0
  7. package/dist/handle-error.d.ts +1 -1
  8. package/dist/handle-error.js +7 -3
  9. package/dist/index.d.ts +14 -2
  10. package/dist/index.js +1 -1
  11. package/dist/pikku-state.js +3 -1
  12. package/dist/schema.js +1 -1
  13. package/dist/services/in-memory-workflow-service.d.ts +22 -3
  14. package/dist/services/in-memory-workflow-service.js +77 -1
  15. package/dist/services/workflow-service.d.ts +8 -2
  16. package/dist/testing/index.d.ts +2 -0
  17. package/dist/testing/index.js +1 -0
  18. package/dist/testing/service-tests.d.ts +31 -0
  19. package/dist/testing/service-tests.js +598 -0
  20. package/dist/types/core.types.d.ts +9 -1
  21. package/dist/types/state.types.d.ts +4 -2
  22. package/dist/utils/hash.d.ts +2 -0
  23. package/dist/utils/hash.js +23 -0
  24. package/dist/wirings/ai-agent/agent-dynamic-workflow.d.ts +6 -0
  25. package/dist/wirings/ai-agent/agent-dynamic-workflow.js +348 -0
  26. package/dist/wirings/ai-agent/ai-agent-memory.d.ts +1 -1
  27. package/dist/wirings/ai-agent/ai-agent-memory.js +6 -5
  28. package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +10 -7
  29. package/dist/wirings/ai-agent/ai-agent-prepare.js +127 -47
  30. package/dist/wirings/ai-agent/ai-agent-runner.d.ts +4 -0
  31. package/dist/wirings/ai-agent/ai-agent-runner.js +381 -27
  32. package/dist/wirings/ai-agent/ai-agent-stream.d.ts +7 -2
  33. package/dist/wirings/ai-agent/ai-agent-stream.js +109 -46
  34. package/dist/wirings/ai-agent/ai-agent.types.d.ts +22 -1
  35. package/dist/wirings/ai-agent/index.d.ts +1 -2
  36. package/dist/wirings/ai-agent/index.js +1 -2
  37. package/dist/wirings/channel/channel-handler.js +5 -1
  38. package/dist/wirings/channel/channel.types.d.ts +1 -7
  39. package/dist/wirings/channel/local/local-channel-handler.d.ts +1 -1
  40. package/dist/wirings/channel/local/local-channel-handler.js +5 -3
  41. package/dist/wirings/channel/local/local-channel-runner.js +14 -4
  42. package/dist/wirings/channel/serverless/serverless-channel-runner.js +4 -1
  43. package/dist/wirings/cli/cli-runner.js +10 -2
  44. package/dist/wirings/cli/cli.types.d.ts +1 -0
  45. package/dist/wirings/http/http-routes.js +0 -1
  46. package/dist/wirings/http/http-runner.d.ts +1 -1
  47. package/dist/wirings/http/http-runner.js +25 -3
  48. package/dist/wirings/http/http.types.d.ts +3 -11
  49. package/dist/wirings/http/index.d.ts +2 -1
  50. package/dist/wirings/http/index.js +1 -0
  51. package/dist/wirings/http/pikku-fetch-http-request.d.ts +1 -0
  52. package/dist/wirings/http/pikku-fetch-http-request.js +3 -0
  53. package/dist/wirings/http/pikku-fetch-http-response.d.ts +1 -0
  54. package/dist/wirings/http/pikku-fetch-http-response.js +4 -4
  55. package/dist/wirings/http/web-request.d.ts +12 -0
  56. package/dist/wirings/http/web-request.js +85 -0
  57. package/dist/wirings/mcp/mcp-endpoint-registry.js +1 -1
  58. package/dist/wirings/mcp/mcp-runner.js +13 -1
  59. package/dist/wirings/rpc/rpc-runner.d.ts +30 -6
  60. package/dist/wirings/rpc/rpc-runner.js +36 -14
  61. package/dist/wirings/rpc/rpc-types.d.ts +6 -1
  62. package/dist/wirings/rpc/wire-addon.d.ts +1 -0
  63. package/dist/wirings/rpc/wire-addon.js +1 -1
  64. package/dist/wirings/scheduler/scheduler-runner.js +1 -0
  65. package/dist/wirings/workflow/graph/graph-validation.d.ts +3 -0
  66. package/dist/wirings/workflow/graph/graph-validation.js +175 -0
  67. package/dist/wirings/workflow/graph/index.d.ts +1 -0
  68. package/dist/wirings/workflow/graph/index.js +1 -0
  69. package/dist/wirings/workflow/index.d.ts +1 -1
  70. package/dist/wirings/workflow/pikku-workflow-service.d.ts +8 -2
  71. package/dist/wirings/workflow/pikku-workflow-service.js +1 -2
  72. package/dist/wirings/workflow/workflow.types.d.ts +10 -1
  73. package/lcov.info +18891 -0
  74. package/package.json +4 -2
  75. package/dist/wirings/ai-agent/ai-agent-assistant-ui.d.ts +0 -5
  76. package/dist/wirings/ai-agent/ai-agent-assistant-ui.js +0 -168
  77. package/src/crypto-utils.test.ts +0 -116
  78. package/src/crypto-utils.ts +0 -99
  79. package/src/errors/error-handler.ts +0 -62
  80. package/src/errors/error.test.ts +0 -195
  81. package/src/errors/errors.ts +0 -374
  82. package/src/errors/index.ts +0 -2
  83. package/src/factory-functions.test.ts +0 -109
  84. package/src/function/function-runner.test.ts +0 -536
  85. package/src/function/function-runner.ts +0 -365
  86. package/src/function/functions.types.ts +0 -267
  87. package/src/function/index.ts +0 -5
  88. package/src/handle-error.test.ts +0 -361
  89. package/src/handle-error.ts +0 -65
  90. package/src/index.ts +0 -104
  91. package/src/internal.ts +0 -6
  92. package/src/middleware/auth-apikey.test.ts +0 -363
  93. package/src/middleware/auth-apikey.ts +0 -47
  94. package/src/middleware/auth-bearer.test.ts +0 -450
  95. package/src/middleware/auth-bearer.ts +0 -72
  96. package/src/middleware/auth-cookie.test.ts +0 -528
  97. package/src/middleware/auth-cookie.ts +0 -80
  98. package/src/middleware/cors.test.ts +0 -424
  99. package/src/middleware/cors.ts +0 -104
  100. package/src/middleware/index.ts +0 -5
  101. package/src/middleware/remote-auth.test.ts +0 -488
  102. package/src/middleware/remote-auth.ts +0 -68
  103. package/src/middleware/timeout.ts +0 -15
  104. package/src/middleware-runner.test.ts +0 -418
  105. package/src/middleware-runner.ts +0 -234
  106. package/src/permissions.test.ts +0 -434
  107. package/src/permissions.ts +0 -319
  108. package/src/pikku-request.ts +0 -23
  109. package/src/pikku-response.ts +0 -5
  110. package/src/pikku-state.test.ts +0 -224
  111. package/src/pikku-state.ts +0 -214
  112. package/src/run-tests-script.test.ts +0 -49
  113. package/src/schema.test.ts +0 -249
  114. package/src/schema.ts +0 -151
  115. package/src/services/ai-agent-runner-service.ts +0 -41
  116. package/src/services/ai-run-state-service.ts +0 -20
  117. package/src/services/ai-storage-service.ts +0 -39
  118. package/src/services/content-service.ts +0 -76
  119. package/src/services/deployment-service.ts +0 -22
  120. package/src/services/gateway-service.ts +0 -20
  121. package/src/services/gopass-secrets.ts +0 -98
  122. package/src/services/in-memory-ai-run-state-service.ts +0 -73
  123. package/src/services/in-memory-trigger-service.ts +0 -64
  124. package/src/services/in-memory-workflow-service.test.ts +0 -351
  125. package/src/services/in-memory-workflow-service.ts +0 -395
  126. package/src/services/index.ts +0 -56
  127. package/src/services/jwt-service.ts +0 -30
  128. package/src/services/local-content.ts +0 -120
  129. package/src/services/local-gateway-service.ts +0 -62
  130. package/src/services/local-secrets.test.ts +0 -80
  131. package/src/services/local-secrets.ts +0 -94
  132. package/src/services/local-variables.test.ts +0 -61
  133. package/src/services/local-variables.ts +0 -39
  134. package/src/services/logger-console.test.ts +0 -118
  135. package/src/services/logger-console.ts +0 -98
  136. package/src/services/logger.ts +0 -57
  137. package/src/services/scheduler-service.ts +0 -86
  138. package/src/services/schema-service.ts +0 -33
  139. package/src/services/scoped-secret-service.test.ts +0 -74
  140. package/src/services/scoped-secret-service.ts +0 -41
  141. package/src/services/secret-service.ts +0 -38
  142. package/src/services/trigger-service.ts +0 -17
  143. package/src/services/typed-secret-service.test.ts +0 -93
  144. package/src/services/typed-secret-service.ts +0 -70
  145. package/src/services/typed-variables-service.test.ts +0 -73
  146. package/src/services/typed-variables-service.ts +0 -81
  147. package/src/services/user-session-service.test.ts +0 -113
  148. package/src/services/user-session-service.ts +0 -86
  149. package/src/services/variables-service.ts +0 -11
  150. package/src/services/workflow-service.ts +0 -84
  151. package/src/time-utils.test.ts +0 -56
  152. package/src/time-utils.ts +0 -107
  153. package/src/types/core.types.ts +0 -470
  154. package/src/types/state.types.ts +0 -186
  155. package/src/utils.test.ts +0 -350
  156. package/src/utils.ts +0 -129
  157. package/src/version.test.ts +0 -80
  158. package/src/version.ts +0 -25
  159. package/src/wirings/ai-agent/ai-agent-assistant-ui.test.ts +0 -363
  160. package/src/wirings/ai-agent/ai-agent-assistant-ui.ts +0 -238
  161. package/src/wirings/ai-agent/ai-agent-helpers.test.ts +0 -152
  162. package/src/wirings/ai-agent/ai-agent-helpers.ts +0 -76
  163. package/src/wirings/ai-agent/ai-agent-memory.ts +0 -309
  164. package/src/wirings/ai-agent/ai-agent-model-config.test.ts +0 -115
  165. package/src/wirings/ai-agent/ai-agent-model-config.ts +0 -43
  166. package/src/wirings/ai-agent/ai-agent-prepare.ts +0 -522
  167. package/src/wirings/ai-agent/ai-agent-registry.test.ts +0 -37
  168. package/src/wirings/ai-agent/ai-agent-registry.ts +0 -82
  169. package/src/wirings/ai-agent/ai-agent-runner.test.ts +0 -317
  170. package/src/wirings/ai-agent/ai-agent-runner.ts +0 -251
  171. package/src/wirings/ai-agent/ai-agent-stream.test.ts +0 -652
  172. package/src/wirings/ai-agent/ai-agent-stream.ts +0 -1060
  173. package/src/wirings/ai-agent/ai-agent.types.ts +0 -360
  174. package/src/wirings/ai-agent/index.ts +0 -41
  175. package/src/wirings/channel/channel-common.ts +0 -90
  176. package/src/wirings/channel/channel-handler.ts +0 -241
  177. package/src/wirings/channel/channel-middleware-runner.ts +0 -120
  178. package/src/wirings/channel/channel-runner.ts +0 -166
  179. package/src/wirings/channel/channel-store.ts +0 -29
  180. package/src/wirings/channel/channel.types.ts +0 -178
  181. package/src/wirings/channel/define-channel-routes.ts +0 -25
  182. package/src/wirings/channel/eventhub-service.ts +0 -34
  183. package/src/wirings/channel/eventhub-store.ts +0 -13
  184. package/src/wirings/channel/index.ts +0 -24
  185. package/src/wirings/channel/local/index.ts +0 -3
  186. package/src/wirings/channel/local/local-channel-handler.ts +0 -79
  187. package/src/wirings/channel/local/local-channel-runner.test.ts +0 -215
  188. package/src/wirings/channel/local/local-channel-runner.ts +0 -200
  189. package/src/wirings/channel/local/local-eventhub-service.test.ts +0 -95
  190. package/src/wirings/channel/local/local-eventhub-service.ts +0 -101
  191. package/src/wirings/channel/log-channels.ts +0 -20
  192. package/src/wirings/channel/pikku-abstract-channel-handler.test.ts +0 -54
  193. package/src/wirings/channel/pikku-abstract-channel-handler.ts +0 -45
  194. package/src/wirings/channel/serverless/index.ts +0 -5
  195. package/src/wirings/channel/serverless/serverless-channel-runner.ts +0 -286
  196. package/src/wirings/cli/channel/cli-channel-runner.ts +0 -136
  197. package/src/wirings/cli/channel/index.ts +0 -1
  198. package/src/wirings/cli/cli-runner.test.ts +0 -403
  199. package/src/wirings/cli/cli-runner.ts +0 -519
  200. package/src/wirings/cli/cli.types.ts +0 -357
  201. package/src/wirings/cli/command-parser.test.ts +0 -445
  202. package/src/wirings/cli/command-parser.ts +0 -504
  203. package/src/wirings/cli/define-cli-commands.ts +0 -24
  204. package/src/wirings/cli/index.ts +0 -19
  205. package/src/wirings/gateway/gateway-runner.test.ts +0 -474
  206. package/src/wirings/gateway/gateway-runner.ts +0 -411
  207. package/src/wirings/gateway/gateway.types.ts +0 -149
  208. package/src/wirings/gateway/index.ts +0 -13
  209. package/src/wirings/http/http-routes.test.ts +0 -322
  210. package/src/wirings/http/http-routes.ts +0 -198
  211. package/src/wirings/http/http-runner.test.ts +0 -144
  212. package/src/wirings/http/http-runner.ts +0 -563
  213. package/src/wirings/http/http.types.ts +0 -378
  214. package/src/wirings/http/index.ts +0 -25
  215. package/src/wirings/http/log-http-routes.ts +0 -22
  216. package/src/wirings/http/pikku-fetch-http-request.test.ts +0 -237
  217. package/src/wirings/http/pikku-fetch-http-request.ts +0 -166
  218. package/src/wirings/http/pikku-fetch-http-response.test.ts +0 -82
  219. package/src/wirings/http/pikku-fetch-http-response.ts +0 -147
  220. package/src/wirings/http/routers/http-router.ts +0 -13
  221. package/src/wirings/http/routers/path-to-regex.test.ts +0 -319
  222. package/src/wirings/http/routers/path-to-regex.ts +0 -126
  223. package/src/wirings/mcp/index.ts +0 -27
  224. package/src/wirings/mcp/mcp-endpoint-registry.test.ts +0 -389
  225. package/src/wirings/mcp/mcp-endpoint-registry.ts +0 -159
  226. package/src/wirings/mcp/mcp-runner.ts +0 -305
  227. package/src/wirings/mcp/mcp.types.ts +0 -216
  228. package/src/wirings/node/index.ts +0 -2
  229. package/src/wirings/node/node.types.ts +0 -23
  230. package/src/wirings/oauth2/index.ts +0 -3
  231. package/src/wirings/oauth2/oauth2-client.test.ts +0 -929
  232. package/src/wirings/oauth2/oauth2-client.ts +0 -335
  233. package/src/wirings/oauth2/oauth2.types.ts +0 -69
  234. package/src/wirings/oauth2/wire-oauth2-credential.ts +0 -23
  235. package/src/wirings/queue/index.ts +0 -31
  236. package/src/wirings/queue/queue-runner.test.ts +0 -710
  237. package/src/wirings/queue/queue-runner.ts +0 -192
  238. package/src/wirings/queue/queue.types.ts +0 -189
  239. package/src/wirings/queue/register-queue-helper.ts +0 -60
  240. package/src/wirings/queue/validate-worker-config.test.ts +0 -108
  241. package/src/wirings/queue/validate-worker-config.ts +0 -116
  242. package/src/wirings/rpc/index.ts +0 -4
  243. package/src/wirings/rpc/rpc-runner.ts +0 -439
  244. package/src/wirings/rpc/rpc-types.ts +0 -51
  245. package/src/wirings/rpc/wire-addon.ts +0 -20
  246. package/src/wirings/scheduler/index.ts +0 -11
  247. package/src/wirings/scheduler/log-schedulers.ts +0 -20
  248. package/src/wirings/scheduler/scheduler-runner.test.ts +0 -660
  249. package/src/wirings/scheduler/scheduler-runner.ts +0 -132
  250. package/src/wirings/scheduler/scheduler.types.ts +0 -53
  251. package/src/wirings/secret/index.ts +0 -9
  252. package/src/wirings/secret/secret.types.ts +0 -32
  253. package/src/wirings/secret/validate-secret-definitions.test.ts +0 -140
  254. package/src/wirings/secret/validate-secret-definitions.ts +0 -82
  255. package/src/wirings/trigger/index.ts +0 -10
  256. package/src/wirings/trigger/pikku-trigger-service.ts +0 -112
  257. package/src/wirings/trigger/trigger-runner.test.ts +0 -79
  258. package/src/wirings/trigger/trigger-runner.ts +0 -135
  259. package/src/wirings/trigger/trigger.types.ts +0 -178
  260. package/src/wirings/variable/index.ts +0 -8
  261. package/src/wirings/variable/validate-variable-definitions.test.ts +0 -91
  262. package/src/wirings/variable/validate-variable-definitions.ts +0 -69
  263. package/src/wirings/variable/variable.types.ts +0 -22
  264. package/src/wirings/workflow/dsl/index.ts +0 -31
  265. package/src/wirings/workflow/dsl/workflow-dsl.types.ts +0 -320
  266. package/src/wirings/workflow/dsl/workflow-runner.ts +0 -28
  267. package/src/wirings/workflow/graph/graph-node.ts +0 -222
  268. package/src/wirings/workflow/graph/graph-runner.test.ts +0 -487
  269. package/src/wirings/workflow/graph/graph-runner.ts +0 -816
  270. package/src/wirings/workflow/graph/index.ts +0 -14
  271. package/src/wirings/workflow/graph/template.test.ts +0 -49
  272. package/src/wirings/workflow/graph/template.ts +0 -42
  273. package/src/wirings/workflow/graph/wire-workflow-graph.ts +0 -29
  274. package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -104
  275. package/src/wirings/workflow/index.ts +0 -81
  276. package/src/wirings/workflow/pikku-workflow-service.test.ts +0 -200
  277. package/src/wirings/workflow/pikku-workflow-service.ts +0 -1165
  278. package/src/wirings/workflow/workflow-helpers.test.ts +0 -129
  279. package/src/wirings/workflow/workflow-helpers.ts +0 -79
  280. package/src/wirings/workflow/workflow.types.ts +0 -266
  281. package/tsconfig.json +0 -14
  282. package/tsconfig.tsbuildinfo +0 -1
@@ -1,470 +0,0 @@
1
- import type { Logger, LogLevel } from '../services/logger.js'
2
- import type { VariablesService } from '../services/variables-service.js'
3
- import type { SecretService } from '../services/secret-service.js'
4
- import type { SchemaService } from '../services/schema-service.js'
5
- import type { JWTService } from '../services/jwt-service.js'
6
- import type { PikkuHTTP } from '../wirings/http/http.types.js'
7
- import type {
8
- PikkuChannel,
9
- CorePikkuChannelMiddleware,
10
- CorePikkuChannelMiddlewareFactory,
11
- } from '../wirings/channel/channel.types.js'
12
- import type { PikkuRPC } from '../wirings/rpc/rpc-types.js'
13
- import type { PikkuMCP } from '../wirings/mcp/mcp.types.js'
14
- import type { PikkuScheduledTask } from '../wirings/scheduler/scheduler.types.js'
15
- import type { PikkuQueue, QueueService } from '../wirings/queue/queue.types.js'
16
- import type { PikkuCLI } from '../wirings/cli/cli.types.js'
17
- import type {
18
- PikkuWorkflowWire,
19
- WorkflowService,
20
- WorkflowServiceConfig,
21
- WorkflowStepWire,
22
- } from '../wirings/workflow/workflow.types.js'
23
- import type { PikkuGraphWire } from '../wirings/workflow/graph/workflow-graph.types.js'
24
- import type { PikkuTrigger } from '../wirings/trigger/trigger.types.js'
25
- import type { PikkuGateway } from '../wirings/gateway/gateway.types.js'
26
- import type { SchedulerService } from '../services/scheduler-service.js'
27
- import type { DeploymentService } from '../services/deployment-service.js'
28
- import type { AIStorageService } from '../services/ai-storage-service.js'
29
-
30
- import type { ContentService } from '../services/content-service.js'
31
- import type { AIAgentRunnerService } from '../services/ai-agent-runner-service.js'
32
- import type { AIRunStateService } from '../services/ai-run-state-service.js'
33
- import type { PikkuAIMiddlewareHooks } from '../wirings/ai-agent/ai-agent.types.js'
34
-
35
- export type PikkuWiringTypes =
36
- | 'http'
37
- | 'scheduler'
38
- | 'trigger'
39
- | 'channel'
40
- | 'rpc'
41
- | 'queue'
42
- | 'mcp'
43
- | 'cli'
44
- | 'workflow'
45
- | 'agent'
46
- | 'gateway'
47
-
48
- export interface FunctionServicesMeta {
49
- optimized: boolean
50
- services: string[]
51
- }
52
-
53
- export interface FunctionWiresMeta {
54
- optimized: boolean
55
- wires: string[]
56
- }
57
-
58
- /**
59
- * Metadata for middleware at any level
60
- * - type: 'http' = HTTP route middleware group (references httpGroup in pikkuState)
61
- * - type: 'tag' = Tag-based middleware group (references tagGroup in pikkuState)
62
- * - type: 'wire' = Wire-level individual middleware
63
- */
64
- export type MiddlewareMetadata =
65
- | {
66
- type: 'http'
67
- route: string // Route pattern (e.g., '*' for all, '/api/*' for specific)
68
- }
69
- | {
70
- type: 'tag'
71
- tag: string // Tag name
72
- }
73
- | {
74
- type: 'wire'
75
- name: string
76
- inline?: boolean // true if inline middleware
77
- }
78
-
79
- /**
80
- * Metadata for permissions at any level
81
- * - type: 'http' = HTTP route permission group (references httpGroup in pikkuState)
82
- * - type: 'tag' = Tag-based permission group (references tagGroup in pikkuState)
83
- * - type: 'wire' = Wire-level individual permission
84
- */
85
- export type PermissionMetadata =
86
- | {
87
- type: 'http'
88
- route: string // Route pattern (e.g., '*' for all, '/api/*' for specific)
89
- }
90
- | {
91
- type: 'tag'
92
- tag: string // Tag name
93
- }
94
- | {
95
- type: 'wire'
96
- name: string
97
- inline?: boolean // true if inline permission
98
- }
99
-
100
- export type FunctionRuntimeMeta = {
101
- pikkuFuncId: string
102
- inputSchemaName: string | null
103
- outputSchemaName: string | null
104
- expose?: boolean
105
- remote?: boolean
106
- mcp?: boolean
107
- readonly?: boolean
108
- sessionless?: boolean
109
- version?: number
110
- requiresApproval?: boolean
111
- contractHash?: string
112
- inputHash?: string
113
- outputHash?: string
114
- }
115
-
116
- export type FunctionMeta = FunctionRuntimeMeta &
117
- Partial<
118
- {
119
- name: string
120
- functionType: 'user' | 'inline' | 'helper'
121
- funcWrapper: string
122
- services: FunctionServicesMeta
123
- wires: FunctionWiresMeta
124
- inputs: string[] | null
125
- outputs: string[] | null
126
- middleware: MiddlewareMetadata[]
127
- permissions: PermissionMetadata[]
128
- isDirectFunction: boolean
129
- } & CommonWireMeta
130
- >
131
-
132
- export type FunctionsRuntimeMeta = Record<string, FunctionRuntimeMeta>
133
- export type FunctionsMeta = Record<string, FunctionMeta>
134
-
135
- // Optimized runtime metadata with only essential fields
136
-
137
- export type MakeRequired<T, K extends keyof T> = Omit<T, K> &
138
- Required<Pick<T, K>>
139
-
140
- /**
141
- * Represents a JSON primitive type which can be a string, number, boolean, null, or undefined.
142
- */
143
- export type JSONPrimitive = string | number | boolean | null | undefined
144
-
145
- /**
146
- * Represents a JSON value which can be a primitive, an array, or an object.
147
- */
148
- export type JSONValue =
149
- | JSONPrimitive
150
- | JSONValue[]
151
- | {
152
- [key: string]: JSONValue
153
- }
154
-
155
- /**
156
- * Utility type for making certain keys required and leaving the rest as optional.
157
- */
158
- export type PickRequired<T, K extends keyof T> = Required<Pick<T, K>> &
159
- Partial<T>
160
-
161
- /**
162
- * Utility type for making certain keys optional while keeping the rest required.
163
- */
164
- export type PickOptional<T, K extends keyof T> = Partial<T> & Pick<T, K>
165
-
166
- /**
167
- * Utility type that ensures at least one key in the given type `T` is required.
168
- */
169
- export type RequireAtLeastOne<T> = {
170
- [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>
171
- }[keyof T]
172
-
173
- /**
174
- * Interface for the core configuration settings of Pikku.
175
- */
176
- export type CoreConfig<Config extends Record<string, unknown> = {}> = {
177
- /** The log level for the application. */
178
- logLevel?: LogLevel
179
- /** Secrets used by the application (optional). */
180
- secrets?: {}
181
-
182
- workflow?: WorkflowServiceConfig
183
- } & Config
184
-
185
- /**
186
- * Represents a core user session, which can be extended for more specific session information.
187
- */
188
- export interface CoreUserSession {}
189
-
190
- /**
191
- * Interface for core singleton services provided by Pikku.
192
- */
193
- export interface CoreSingletonServices<Config extends CoreConfig = CoreConfig> {
194
- /** The schema library used to validate data */
195
- schema?: SchemaService
196
- /** The JWT service used to encode and decode tokens */
197
- jwt?: JWTService
198
- /** The core configuration for the application. */
199
- config: Config
200
- /** The logger used by the application. */
201
- logger: Logger
202
- /** The variable service to be used */
203
- variables: VariablesService
204
- /** The secrets service to retrieve secrets */
205
- secrets: SecretService
206
- /** The workflow orchestrator service */
207
- workflowService?: WorkflowService
208
- /** The queue service */
209
- queueService?: QueueService
210
- /** The scheduler service */
211
- schedulerService?: SchedulerService
212
- /** The deployment service for service discovery */
213
- deploymentService?: DeploymentService
214
- /** AI agent storage service (threads, messages, working memory) */
215
- aiStorage?: AIStorageService
216
-
217
- /** Content service for file storage and retrieval */
218
- content?: ContentService
219
- /** AI agent runner service (model calls + tool loop) */
220
- aiAgentRunner?: AIAgentRunnerService
221
- /** AI run state service (run lifecycle + approval persistence) */
222
- aiRunState?: AIRunStateService
223
- }
224
-
225
- /**
226
- * Represents different forms of wire within Pikku and the outside world.
227
- */
228
- export type PikkuWire<
229
- In = unknown,
230
- Out = unknown,
231
- HasInitialSession extends boolean = false,
232
- UserSession extends CoreUserSession = CoreUserSession,
233
- TypedRPC extends PikkuRPC = PikkuRPC,
234
- IsChannel extends true | null = null,
235
- MCPTools extends string | never = never,
236
- TypedWorkflow extends PikkuWorkflowWire | never = PikkuWorkflowWire,
237
- TriggerOutput = unknown,
238
- > = Partial<{
239
- wireType: PikkuWiringTypes
240
- wireId: string
241
- http: PikkuHTTP<In>
242
- mcp: PikkuMCP<MCPTools>
243
- rpc: TypedRPC
244
- channel: [IsChannel] extends [null]
245
- ? PikkuChannel<unknown, Out>
246
- : PikkuChannel<unknown, Out> | undefined
247
- scheduledTask: PikkuScheduledTask
248
- queue: PikkuQueue
249
- cli: PikkuCLI
250
- workflow: TypedWorkflow
251
- workflowStep: WorkflowStepWire
252
- graph: PikkuGraphWire
253
- trigger: PikkuTrigger<TriggerOutput>
254
- gateway: PikkuGateway
255
- session: HasInitialSession extends true
256
- ? UserSession
257
- : UserSession | undefined
258
- /** Update and persist the current session */
259
- setSession: (session: CoreUserSession) => Promise<void> | void
260
- /** Clear and persist the current session */
261
- clearSession: () => Promise<void> | void
262
- /** Fetch the latest session (may read from backing store) */
263
- getSession: () => Promise<UserSession> | UserSession | undefined
264
- /** Whether the session was modified during this run */
265
- hasSessionChanged: () => boolean
266
- }>
267
-
268
- /**
269
- * A function that can wrap an wire and be called before or after
270
- */
271
- export type CorePikkuMiddleware<
272
- SingletonServices extends CoreSingletonServices = CoreSingletonServices,
273
- UserSession extends CoreUserSession = CoreUserSession,
274
- > = (
275
- services: SingletonServices,
276
- wires: PikkuWire<unknown, unknown, false, UserSession>,
277
- next: () => Promise<void>
278
- ) => Promise<void>
279
-
280
- /**
281
- * Configuration object for creating middleware with metadata
282
- *
283
- * @template SingletonServices - The singleton services type
284
- * @template UserSession - The user session type
285
- */
286
- export type CorePikkuMiddlewareConfig<
287
- SingletonServices extends CoreSingletonServices = CoreSingletonServices,
288
- UserSession extends CoreUserSession = CoreUserSession,
289
- > = {
290
- /** The middleware function */
291
- func: CorePikkuMiddleware<SingletonServices, UserSession>
292
- /** Optional human-readable name for the middleware */
293
- name?: string
294
- /** Optional description of what the middleware does */
295
- description?: string
296
- }
297
-
298
- /**
299
- * A factory function that takes input and returns middleware
300
- * Used when middleware needs configuration/input parameters
301
- */
302
- export type CorePikkuMiddlewareFactory<
303
- In = any,
304
- SingletonServices extends CoreSingletonServices = CoreSingletonServices,
305
- UserSession extends CoreUserSession = CoreUserSession,
306
- > = (input: In) => CorePikkuMiddleware<SingletonServices, UserSession>
307
-
308
- /**
309
- * A group of middleware (combination of regular middleware and factories)
310
- * Used with addMiddleware() and addHTTPMiddleware() to group related middleware together
311
- */
312
- export type CorePikkuMiddlewareGroup<
313
- SingletonServices extends CoreSingletonServices = CoreSingletonServices,
314
- UserSession extends CoreUserSession = CoreUserSession,
315
- > = Array<
316
- | CorePikkuMiddleware<SingletonServices, UserSession>
317
- | CorePikkuMiddlewareFactory<any, SingletonServices, UserSession>
318
- >
319
-
320
- /**
321
- * Factory function for creating middleware with tree-shaking support
322
- * Supports both direct function and configuration object syntax
323
- *
324
- * @example
325
- * ```typescript
326
- * // Direct function syntax
327
- * export const logMiddleware = pikkuMiddleware(
328
- * async ({ logger }, next) => {
329
- * logger.info('Request started')
330
- * await next()
331
- * }
332
- * )
333
- *
334
- * // Configuration object syntax with metadata
335
- * export const logMiddleware = pikkuMiddleware({
336
- * name: 'Request Logger',
337
- * description: 'Logs request information',
338
- * func: async ({ logger }, next) => {
339
- * logger.info('Request started')
340
- * await next()
341
- * }
342
- * })
343
- * ```
344
- */
345
- export const pikkuMiddleware = <
346
- SingletonServices extends CoreSingletonServices = CoreSingletonServices,
347
- UserSession extends CoreUserSession = CoreUserSession,
348
- >(
349
- middleware:
350
- | CorePikkuMiddleware<SingletonServices, UserSession>
351
- | CorePikkuMiddlewareConfig<SingletonServices, UserSession>
352
- ): CorePikkuMiddleware<SingletonServices, UserSession> => {
353
- return typeof middleware === 'function' ? middleware : middleware.func
354
- }
355
-
356
- /**
357
- * Factory function for creating middleware factories
358
- * Use this when your middleware needs configuration/input parameters
359
- *
360
- * @example
361
- * ```typescript
362
- * export const logMiddleware = pikkuMiddlewareFactory<LogOptions>(({
363
- * message,
364
- * level = 'info'
365
- * }) => {
366
- * return pikkuMiddleware(async ({ logger }, next) => {
367
- * logger[level](message)
368
- * await next()
369
- * })
370
- * })
371
- * ```
372
- */
373
- export const pikkuMiddlewareFactory = <In = any>(
374
- factory: CorePikkuMiddlewareFactory<In>
375
- ): CorePikkuMiddlewareFactory<In> => {
376
- return factory
377
- }
378
-
379
- export const pikkuChannelMiddleware = <
380
- SingletonServices extends CoreSingletonServices = CoreSingletonServices,
381
- Event = unknown,
382
- >(
383
- middleware: CorePikkuChannelMiddleware<SingletonServices, Event>
384
- ): CorePikkuChannelMiddleware<SingletonServices, Event> => {
385
- return middleware
386
- }
387
-
388
- export const pikkuChannelMiddlewareFactory = <In = any>(
389
- factory: CorePikkuChannelMiddlewareFactory<In>
390
- ): CorePikkuChannelMiddlewareFactory<In> => {
391
- return factory
392
- }
393
-
394
- export type { PikkuAIMiddlewareHooks } from '../wirings/ai-agent/ai-agent.types.js'
395
-
396
- export const pikkuAIMiddleware = <
397
- State extends Record<string, unknown> = Record<string, unknown>,
398
- SingletonServices extends CoreSingletonServices = CoreSingletonServices,
399
- >(
400
- hooks: PikkuAIMiddlewareHooks<State, SingletonServices>
401
- ): PikkuAIMiddlewareHooks<State, SingletonServices> => hooks
402
-
403
- /**
404
- * Represents the core services used by Pikku, including singleton services.
405
- */
406
- export type CoreServices<SingletonServices = CoreSingletonServices> =
407
- SingletonServices
408
-
409
- export type WireServices<
410
- SingletonServices extends CoreSingletonServices = CoreSingletonServices,
411
- Services = CoreServices<SingletonServices>,
412
- > = Omit<Services, keyof SingletonServices | 'session'>
413
-
414
- /**
415
- * Defines a function type for creating singleton services from the given configuration.
416
- */
417
- export type CreateSingletonServices<
418
- Config extends CoreConfig,
419
- SingletonServices extends CoreSingletonServices,
420
- > = (
421
- config: Config,
422
- existingServices?: Partial<SingletonServices>
423
- ) => Promise<SingletonServices>
424
-
425
- /**
426
- * Defines a function type for creating session-specific services.
427
- */
428
- export type CreateWireServices<
429
- SingletonServices extends CoreSingletonServices = CoreSingletonServices,
430
- Services extends
431
- CoreServices<SingletonServices> = CoreServices<SingletonServices>,
432
- UserSession extends CoreUserSession = CoreUserSession,
433
- > = (
434
- services: SingletonServices,
435
- wire: PikkuWire<unknown, unknown, false, UserSession>
436
- ) => Promise<WireServices<Services, SingletonServices>>
437
-
438
- /**
439
- * Defines a function type for creating config.
440
- */
441
- export type CreateConfig<
442
- Config extends CoreConfig,
443
- RemainingArgs extends any[] = unknown[],
444
- > = (variables?: VariablesService, ...args: RemainingArgs) => Promise<Config>
445
-
446
- /**
447
- * Represents the documentation for a route, including summary, description, tags, and errors.
448
- */
449
- export type CommonWireMeta = {
450
- pikkuFuncId: string
451
-
452
- title?: string
453
- tags?: string[]
454
- summary?: string
455
- description?: string
456
- errors?: string[]
457
-
458
- middleware?: MiddlewareMetadata[]
459
- permissions?: PermissionMetadata[]
460
- }
461
-
462
- /**
463
- * Serialized error for storage
464
- */
465
- export interface SerializedError {
466
- message: string
467
- stack?: string
468
- code?: string
469
- [key: string]: any
470
- }
@@ -1,186 +0,0 @@
1
- import type { PikkuError, ErrorDetails } from '../errors/error-handler.js'
2
- import type {
3
- CorePikkuFunctionConfig,
4
- CorePermissionGroup,
5
- CorePikkuPermission,
6
- } from '../function/functions.types.js'
7
- import type { CorePikkuTriggerFunctionConfig } from '../wirings/trigger/trigger.types.js'
8
- import type {
9
- CoreChannel,
10
- ChannelsMeta,
11
- } from '../wirings/channel/channel.types.js'
12
- import type { CLIMeta, CLIProgramState } from '../wirings/cli/cli.types.js'
13
- import type {
14
- HTTPMethod,
15
- CoreHTTPFunctionWiring,
16
- HTTPWiringsMeta,
17
- } from '../wirings/http/http.types.js'
18
- import type {
19
- CoreMCPResource,
20
- MCPResourceMeta,
21
- MCPToolMeta,
22
- CoreMCPPrompt,
23
- MCPPromptMeta,
24
- } from '../wirings/mcp/mcp.types.js'
25
- import type {
26
- CoreAIAgent,
27
- AIAgentMeta,
28
- } from '../wirings/ai-agent/ai-agent.types.js'
29
- import type {
30
- CoreGateway,
31
- GatewaysMeta,
32
- } from '../wirings/gateway/gateway.types.js'
33
- import type {
34
- CoreQueueWorker,
35
- QueueWorkersMeta,
36
- } from '../wirings/queue/queue.types.js'
37
- import type {
38
- CoreScheduledTask,
39
- ScheduledTasksMeta,
40
- } from '../wirings/scheduler/scheduler.types.js'
41
- import type {
42
- CoreWorkflow,
43
- WorkflowsRuntimeMeta,
44
- } from '../wirings/workflow/workflow.types.js'
45
- import type {
46
- CoreTrigger,
47
- CoreTriggerSource,
48
- TriggerMeta,
49
- TriggerSourceMeta,
50
- } from '../wirings/trigger/trigger.types.js'
51
- import type {
52
- FunctionsMeta,
53
- CorePikkuMiddleware,
54
- CorePikkuMiddlewareGroup,
55
- CreateConfig,
56
- CreateSingletonServices,
57
- CreateWireServices,
58
- CoreConfig,
59
- CoreSingletonServices,
60
- CoreServices,
61
- CoreUserSession,
62
- } from './core.types.js'
63
- import type { CorePikkuChannelMiddleware } from '../wirings/channel/channel.types.js'
64
-
65
- /**
66
- * State structure for an individual package
67
- */
68
- export interface PikkuPackageState {
69
- function: {
70
- meta: FunctionsMeta
71
- functions: Map<string, CorePikkuFunctionConfig<any, any>>
72
- }
73
- rpc: {
74
- meta: Record<string, string>
75
- files: Map<
76
- string,
77
- {
78
- exportedName: string
79
- path: string
80
- }
81
- >
82
- /** Maps namespace aliases to package config (e.g., 'ext' -> { package: '@pikku/...', rpcEndpoint: '...' }) */
83
- addons: Map<
84
- string,
85
- { package: string; rpcEndpoint?: string; auth?: boolean; tags?: string[] }
86
- >
87
- }
88
- http: {
89
- middleware: Map<string, CorePikkuMiddleware<any, any>[]>
90
- permissions: Map<string, CorePermissionGroup | CorePikkuPermission[]>
91
- routes: Map<HTTPMethod, Map<string, CoreHTTPFunctionWiring<any, any, any>>>
92
- meta: HTTPWiringsMeta
93
- }
94
- channel: {
95
- channels: Map<string, CoreChannel<any, any>>
96
- meta: ChannelsMeta
97
- }
98
- scheduler: {
99
- tasks: Map<string, CoreScheduledTask>
100
- meta: ScheduledTasksMeta
101
- }
102
- queue: {
103
- registrations: Map<string, CoreQueueWorker>
104
- meta: QueueWorkersMeta
105
- }
106
- workflows: {
107
- registrations: Map<string, CoreWorkflow>
108
- meta: WorkflowsRuntimeMeta
109
- }
110
- trigger: {
111
- functions: Map<string, CorePikkuTriggerFunctionConfig<any, any>>
112
- triggers: Map<string, CoreTrigger>
113
- triggerSources: Map<string, CoreTriggerSource>
114
- meta: TriggerMeta
115
- sourceMeta: TriggerSourceMeta
116
- }
117
- mcp: {
118
- resources: Map<string, CoreMCPResource>
119
- resourcesMeta: MCPResourceMeta
120
- toolsMeta: MCPToolMeta
121
- prompts: Map<string, CoreMCPPrompt>
122
- promptsMeta: MCPPromptMeta
123
- }
124
- agent: {
125
- agents: Map<string, CoreAIAgent>
126
- agentsMeta: AIAgentMeta
127
- }
128
- gateway: {
129
- gateways: Map<string, CoreGateway>
130
- meta: GatewaysMeta
131
- }
132
- cli: {
133
- meta: CLIMeta | Record<string, any> // Backward compatible with old published CLI format
134
- programs: Record<string, CLIProgramState>
135
- }
136
- middleware: {
137
- tagGroup: Record<string, CorePikkuMiddlewareGroup>
138
- httpGroup: Record<string, CorePikkuMiddlewareGroup>
139
- }
140
- channelMiddleware: {
141
- tagGroup: Record<string, CorePikkuChannelMiddleware[]>
142
- }
143
- permissions: {
144
- tagGroup: Record<string, CorePermissionGroup | CorePikkuPermission[]>
145
- httpGroup: Record<string, CorePermissionGroup | CorePikkuPermission[]>
146
- }
147
- misc: {
148
- errors: Map<PikkuError, ErrorDetails>
149
- schemas: Map<string, any>
150
- middleware: Record<string, CorePikkuMiddleware[]>
151
- channelMiddleware: Record<string, CorePikkuChannelMiddleware[]>
152
- permissions: Record<string, CorePermissionGroup | CorePikkuPermission[]>
153
- }
154
- models: {
155
- config: {
156
- models?: Record<
157
- string,
158
- string | { model: string; temperature?: number; maxSteps?: number }
159
- >
160
- agentDefaults?: { temperature?: number; maxSteps?: number }
161
- agentOverrides?: Record<
162
- string,
163
- { model?: string; temperature?: number; maxSteps?: number }
164
- >
165
- } | null
166
- }
167
- package: {
168
- /** Service factory functions for addon packages */
169
- factories: {
170
- createConfig?: CreateConfig<CoreConfig>
171
- createSingletonServices?: CreateSingletonServices<
172
- CoreConfig,
173
- CoreSingletonServices
174
- >
175
- createWireServices?: CreateWireServices<
176
- CoreSingletonServices,
177
- CoreServices,
178
- CoreUserSession
179
- >
180
- } | null
181
- /** Cached singleton services for this package */
182
- singletonServices: CoreSingletonServices | null
183
- /** Absolute path to this package's .pikku directory */
184
- metaDir: string | null
185
- }
186
- }