@pikku/core 0.11.0 → 0.11.1

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 (105) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/dist/errors/errors.d.ts +1 -1
  3. package/dist/errors/errors.js +3 -3
  4. package/dist/function/function-runner.d.ts +6 -7
  5. package/dist/function/function-runner.js +35 -16
  6. package/dist/function/functions.types.d.ts +22 -30
  7. package/dist/function/functions.types.js +9 -6
  8. package/dist/handle-error.d.ts +1 -1
  9. package/dist/handle-error.js +1 -1
  10. package/dist/middleware/auth-apikey.js +3 -3
  11. package/dist/middleware/auth-bearer.js +3 -3
  12. package/dist/middleware/auth-cookie.js +5 -5
  13. package/dist/middleware/timeout.js +3 -2
  14. package/dist/middleware-runner.d.ts +3 -6
  15. package/dist/middleware-runner.js +11 -12
  16. package/dist/permissions.d.ts +6 -6
  17. package/dist/permissions.js +15 -16
  18. package/dist/services/user-session-service.d.ts +7 -3
  19. package/dist/services/user-session-service.js +8 -1
  20. package/dist/types/core.types.d.ts +29 -38
  21. package/dist/types/core.types.js +3 -14
  22. package/dist/utils.d.ts +1 -1
  23. package/dist/utils.js +3 -3
  24. package/dist/wirings/channel/channel-common.js +2 -3
  25. package/dist/wirings/channel/channel-handler.d.ts +3 -2
  26. package/dist/wirings/channel/channel-handler.js +6 -9
  27. package/dist/wirings/channel/channel-runner.d.ts +2 -2
  28. package/dist/wirings/channel/channel.types.d.ts +10 -5
  29. package/dist/wirings/channel/local/local-channel-runner.d.ts +1 -1
  30. package/dist/wirings/channel/local/local-channel-runner.js +19 -26
  31. package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +1 -1
  32. package/dist/wirings/channel/serverless/serverless-channel-runner.js +41 -46
  33. package/dist/wirings/cli/cli-runner.d.ts +5 -5
  34. package/dist/wirings/cli/cli-runner.js +10 -28
  35. package/dist/wirings/cli/cli.types.d.ts +15 -11
  36. package/dist/wirings/http/http-runner.d.ts +6 -6
  37. package/dist/wirings/http/http-runner.js +25 -39
  38. package/dist/wirings/http/http.types.d.ts +5 -10
  39. package/dist/wirings/mcp/mcp-runner.d.ts +2 -2
  40. package/dist/wirings/mcp/mcp-runner.js +12 -19
  41. package/dist/wirings/mcp/mcp.types.d.ts +6 -0
  42. package/dist/wirings/queue/queue-runner.d.ts +3 -3
  43. package/dist/wirings/queue/queue-runner.js +7 -17
  44. package/dist/wirings/queue/queue.types.d.ts +4 -11
  45. package/dist/wirings/rpc/rpc-runner.d.ts +10 -8
  46. package/dist/wirings/rpc/rpc-runner.js +36 -47
  47. package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -3
  48. package/dist/wirings/scheduler/scheduler-runner.js +13 -24
  49. package/dist/wirings/scheduler/scheduler.types.d.ts +3 -8
  50. package/dist/wirings/workflow/index.d.ts +11 -2
  51. package/dist/wirings/workflow/index.js +10 -2
  52. package/dist/wirings/workflow/pikku-workflow-service.d.ts +12 -4
  53. package/dist/wirings/workflow/pikku-workflow-service.js +61 -79
  54. package/dist/wirings/workflow/workflow-runner.d.ts +3 -4
  55. package/dist/wirings/workflow/workflow-runner.js +11 -14
  56. package/dist/wirings/workflow/workflow.types.d.ts +114 -29
  57. package/package.json +2 -2
  58. package/src/errors/errors.ts +3 -3
  59. package/src/factory-functions.test.ts +9 -36
  60. package/src/function/function-runner.test.ts +57 -68
  61. package/src/function/function-runner.ts +51 -28
  62. package/src/function/function-runner.ts.bak +188 -0
  63. package/src/function/functions.types.ts +68 -51
  64. package/src/handle-error.ts +1 -1
  65. package/src/middleware/auth-apikey.test.ts +360 -0
  66. package/src/middleware/auth-apikey.ts +3 -7
  67. package/src/middleware/auth-bearer.test.ts +447 -0
  68. package/src/middleware/auth-bearer.ts +27 -33
  69. package/src/middleware/auth-cookie.test.ts +525 -0
  70. package/src/middleware/auth-cookie.ts +6 -6
  71. package/src/middleware/timeout.ts +4 -2
  72. package/src/middleware-runner.test.ts +58 -127
  73. package/src/middleware-runner.ts +13 -16
  74. package/src/permissions.test.ts +41 -45
  75. package/src/permissions.ts +21 -21
  76. package/src/services/user-session-service.ts +14 -4
  77. package/src/types/core.types.ts +67 -55
  78. package/src/utils.ts +4 -4
  79. package/src/wirings/channel/channel-common.ts +4 -7
  80. package/src/wirings/channel/channel-handler.ts +16 -22
  81. package/src/wirings/channel/channel-runner.ts +2 -2
  82. package/src/wirings/channel/channel.types.ts +14 -11
  83. package/src/wirings/channel/local/local-channel-runner.test.ts +5 -3
  84. package/src/wirings/channel/local/local-channel-runner.ts +23 -38
  85. package/src/wirings/channel/serverless/serverless-channel-runner.ts +51 -77
  86. package/src/wirings/cli/cli-runner.test.ts +7 -7
  87. package/src/wirings/cli/cli-runner.ts +24 -62
  88. package/src/wirings/cli/cli.types.ts +22 -16
  89. package/src/wirings/http/http-runner.test.ts +8 -8
  90. package/src/wirings/http/http-runner.ts +29 -56
  91. package/src/wirings/http/http.types.ts +5 -14
  92. package/src/wirings/mcp/mcp-runner.ts +23 -48
  93. package/src/wirings/mcp/mcp.types.ts +6 -0
  94. package/src/wirings/queue/queue-runner.test.ts +641 -0
  95. package/src/wirings/queue/queue-runner.ts +10 -32
  96. package/src/wirings/queue/queue.types.ts +4 -11
  97. package/src/wirings/rpc/rpc-runner.ts +41 -55
  98. package/src/wirings/scheduler/scheduler-runner.test.ts +627 -0
  99. package/src/wirings/scheduler/scheduler-runner.ts +24 -50
  100. package/src/wirings/scheduler/scheduler.types.ts +3 -9
  101. package/src/wirings/workflow/index.ts +24 -3
  102. package/src/wirings/workflow/pikku-workflow-service.ts +83 -93
  103. package/src/wirings/workflow/workflow-runner.ts +12 -25
  104. package/src/wirings/workflow/workflow.types.ts +144 -54
  105. package/tsconfig.tsbuildinfo +1 -1
@@ -2,7 +2,6 @@ import {
2
2
  CorePikkuMiddleware,
3
3
  CoreSingletonServices,
4
4
  CoreUserSession,
5
- PikkuDocs,
6
5
  CoreServices,
7
6
  MiddlewareMetadata,
8
7
  PermissionMetadata,
@@ -44,7 +43,7 @@ export interface CLIPositional {
44
43
  }
45
44
 
46
45
  /**
47
- * CLI interaction context
46
+ * CLI wire context
48
47
  */
49
48
  export type PikkuCLI = {
50
49
  program: string
@@ -74,8 +73,9 @@ export interface CLICommandMeta {
74
73
  positionals: CLIPositional[]
75
74
  options: Record<string, CLIOption>
76
75
  renderName?: string
76
+ summary?: string
77
77
  description?: string
78
- docs?: PikkuDocs
78
+ errors?: string[]
79
79
  tags?: string[]
80
80
  subcommands?: Record<string, CLICommandMeta>
81
81
  middleware?: MiddlewareMetadata[] // Pre-resolved middleware chain (tag + explicit)
@@ -131,8 +131,8 @@ export type CorePikkuCLIRender<
131
131
  export type ExtractFunctionInput<Func> =
132
132
  Func extends CorePikkuFunctionConfig<infer FuncType, any, any>
133
133
  ? FuncType extends
134
- | CorePikkuFunction<infer Input, any, any, any, any>
135
- | CorePikkuFunctionSessionless<infer Input, any, any, any, any>
134
+ | CorePikkuFunction<infer Input, any, any, any>
135
+ | CorePikkuFunctionSessionless<infer Input, any, any, any>
136
136
  ? Input
137
137
  : never
138
138
  : never
@@ -198,8 +198,8 @@ export type ValidateParameters<Params extends string, Input> =
198
198
  export type ExtractFunctionOutput<Func> =
199
199
  Func extends CorePikkuFunctionConfig<infer FuncType, any, any>
200
200
  ? FuncType extends
201
- | CorePikkuFunction<any, infer Output, any, any, any>
202
- | CorePikkuFunctionSessionless<any, infer Output, any, any, any>
201
+ | CorePikkuFunction<any, infer Output, any, any>
202
+ | CorePikkuFunctionSessionless<any, infer Output, any, any>
203
203
  ? Output
204
204
  : never
205
205
  : never
@@ -210,7 +210,10 @@ export type ExtractFunctionOutput<Func> =
210
210
  */
211
211
  export type CoreCLICommandConfig<
212
212
  FuncConfig,
213
- PikkuMiddleware extends CorePikkuMiddleware<any> = CorePikkuMiddleware<any>,
213
+ PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<
214
+ any,
215
+ any
216
+ >,
214
217
  PikkuCLIRender extends CorePikkuCLIRender<any, any, any> = CorePikkuCLIRender<
215
218
  any,
216
219
  any
@@ -245,8 +248,8 @@ export interface CoreCLICommand<
245
248
  In,
246
249
  Out,
247
250
  PikkuFunctionConfig extends CorePikkuFunctionConfig<
248
- | CorePikkuFunction<In, Out, any, any, any>
249
- | CorePikkuFunctionSessionless<In, Out, any, any, any>
251
+ | CorePikkuFunction<In, Out, any, any>
252
+ | CorePikkuFunctionSessionless<In, Out, any, any>
250
253
  >,
251
254
  PikkuPermission extends CorePikkuPermission<any, any, any>,
252
255
  PikkuMiddleware extends CorePikkuMiddleware,
@@ -264,7 +267,9 @@ export interface CoreCLICommand<
264
267
  middleware?: PikkuMiddleware[]
265
268
  permissions?: Record<string, PikkuPermission | PikkuPermission[]>
266
269
  auth?: boolean
267
- docs?: PikkuDocs
270
+ summary?: string
271
+ errors?: string[]
272
+ tags?: string[]
268
273
  subcommands?: Subcommands
269
274
  isDefault?: boolean
270
275
  }
@@ -276,8 +281,8 @@ export type CLICommandShorthand<
276
281
  In,
277
282
  Out,
278
283
  PikkuFunctionConfig extends CorePikkuFunctionConfig<
279
- | CorePikkuFunction<In, Out, any, any, any>
280
- | CorePikkuFunctionSessionless<In, Out, any, any, any>
284
+ | CorePikkuFunction<In, Out, any, any>
285
+ | CorePikkuFunctionSessionless<In, Out, any, any>
281
286
  >,
282
287
  > = PikkuFunctionConfig
283
288
 
@@ -288,8 +293,8 @@ export type CLICommandDefinition<
288
293
  In,
289
294
  Out,
290
295
  PikkuFunctionConfig extends CorePikkuFunctionConfig<
291
- | CorePikkuFunction<In, Out, any, any, any>
292
- | CorePikkuFunctionSessionless<In, Out, any, any, any>
296
+ | CorePikkuFunction<In, Out, any, any>
297
+ | CorePikkuFunctionSessionless<In, Out, any, any>
293
298
  >,
294
299
  PikkuPermission extends CorePikkuPermission<any, any, any>,
295
300
  PikkuMiddleware extends CorePikkuMiddleware,
@@ -325,7 +330,8 @@ export interface CoreCLI<
325
330
  options?: CLIOptions<Options>
326
331
  middleware?: PikkuMiddleware[]
327
332
  render?: PikkuCLIRender
328
- docs?: PikkuDocs
333
+ summary?: string
334
+ errors?: string[]
329
335
  tags?: string[]
330
336
  }
331
337
 
@@ -11,8 +11,8 @@ import {
11
11
  import { addFunction } from '../../function/function-runner.js'
12
12
  import { httpRouter } from './routers/http-router.js'
13
13
 
14
- const sessionMiddleware: CorePikkuMiddleware = async (services, _, next) => {
15
- services.userSession.set({ userId: 'test' } as any)
14
+ const sessionMiddleware: CorePikkuMiddleware = async (services, wire, next) => {
15
+ wire.session?.set({ userId: 'test' } as any)
16
16
  await next()
17
17
  }
18
18
 
@@ -43,7 +43,7 @@ const setHTTPFunctionMap = (func: any) => {
43
43
 
44
44
  describe('fetch', () => {
45
45
  let singletonServices: any
46
- let createSessionServices: any
46
+ let createWireServices: any
47
47
  let request: any
48
48
  let response: any
49
49
 
@@ -59,7 +59,7 @@ describe('fetch', () => {
59
59
  },
60
60
  }
61
61
 
62
- createSessionServices = async () => ({})
62
+ createWireServices = async () => ({})
63
63
  request = new PikkuMockRequest('/test', 'get')
64
64
  response = new PikkuMockResponse()
65
65
 
@@ -77,7 +77,7 @@ describe('fetch', () => {
77
77
  async () =>
78
78
  fetch(request, {
79
79
  singletonServices,
80
- createSessionServices,
80
+ createWireServices,
81
81
  bubbleErrors: true,
82
82
  }),
83
83
  NotFoundError
@@ -99,7 +99,7 @@ describe('fetch', () => {
99
99
 
100
100
  const result = await fetch(request, {
101
101
  singletonServices,
102
- createSessionServices,
102
+ createWireServices,
103
103
  })
104
104
 
105
105
  assert.deepStrictEqual(await result.json(), { success: true })
@@ -122,7 +122,7 @@ describe('fetch', () => {
122
122
 
123
123
  await fetch(request, {
124
124
  singletonServices,
125
- createSessionServices,
125
+ createWireServices,
126
126
  })
127
127
 
128
128
  assert.strictEqual(await permissions.test(), true)
@@ -143,7 +143,7 @@ describe('fetch', () => {
143
143
  async () =>
144
144
  fetch(request, {
145
145
  singletonServices,
146
- createSessionServices,
146
+ createWireServices,
147
147
  bubbleErrors: true,
148
148
  }),
149
149
  error
@@ -18,24 +18,23 @@ import {
18
18
  CoreUserSession,
19
19
  CorePikkuMiddleware,
20
20
  CorePikkuMiddlewareGroup,
21
- SessionServices,
21
+ WireServices,
22
+ PikkuWire,
22
23
  PikkuWiringTypes,
23
- PikkuInteraction,
24
24
  } from '../../types/core.types.js'
25
25
  import { NotFoundError } from '../../errors/errors.js'
26
26
  import {
27
- closeSessionServices,
27
+ closeWireServices,
28
28
  createWeakUID,
29
29
  isSerializable,
30
30
  } from '../../utils.js'
31
- import { PikkuUserSessionService } from '../../services/user-session-service.js'
31
+ import { PikkuSessionService } from '../../services/user-session-service.js'
32
32
  import { handleHTTPError } from '../../handle-error.js'
33
33
  import { pikkuState } from '../../pikku-state.js'
34
34
  import { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js'
35
35
  import { PikkuFetchHTTPRequest } from './pikku-fetch-http-request.js'
36
36
  import { PikkuChannel } from '../channel/channel.types.js'
37
37
  import { addFunction, runPikkuFunc } from '../../function/function-runner.js'
38
- import { rpcService } from '../rpc/rpc-runner.js'
39
38
  import { httpRouter } from './routers/http-router.js'
40
39
 
41
40
  /**
@@ -203,16 +202,16 @@ const getMatchingRoute = (requestType: string, requestPath: string) => {
203
202
  }
204
203
 
205
204
  /**
206
- * Combines the request and response objects into a single HTTP interaction object.
205
+ * Combines the request and response objects into a single HTTP wire object.
207
206
  *
208
207
  * This utility function creates an object that holds both the HTTP request and response,
209
208
  * which simplifies passing these around through middleware and route execution.
210
209
  *
211
210
  * @param {PikkuHTTPRequest | undefined} request - The HTTP request object.
212
211
  * @param {PikkuHTTPResponse | undefined} response - The HTTP response object.
213
- * @returns {PikkuHTTP | undefined} The combined HTTP interaction object or undefined if none provided.
212
+ * @returns {PikkuHTTP | undefined} The combined HTTP wire object or undefined if none provided.
214
213
  */
215
- export const createHTTPInteraction = (
214
+ export const createHTTPWire = (
216
215
  request: PikkuHTTPRequest | undefined,
217
216
  response: PikkuHTTPResponse | undefined
218
217
  ): PikkuHTTP | undefined => {
@@ -246,15 +245,15 @@ export const createHTTPInteraction = (
246
245
  *
247
246
  * @param {Object} services - A collection of shared services and utilities.
248
247
  * @param {Object} matchedRoute - Contains route details, URL parameters, and optional schema.
249
- * @param {PikkuHTTP | undefined} http - The HTTP interaction object.
248
+ * @param {PikkuHTTP | undefined} http - The HTTP wire object.
250
249
  * @param {Object} options - Options for route execution (e.g., whether to coerce query strings to arrays).
251
- * @returns {Promise<any>} An object containing the route handler result and session services (if any).
250
+ * @returns {Promise<any>} An object containing the route handler result and wire services (if any).
252
251
  * @throws Throws errors like MissingSessionError or ForbiddenError on validation failures.
253
252
  */
254
253
  const executeRoute = async (
255
254
  services: {
256
255
  singletonServices: any
257
- createSessionServices: Function
256
+ createWireServices?: any
258
257
  skipUserSession: boolean
259
258
  requestId: string
260
259
  },
@@ -269,17 +268,13 @@ const executeRoute = async (
269
268
  coerceDataFromSchema: boolean
270
269
  }
271
270
  ) => {
272
- const userSession = new PikkuUserSessionService<CoreUserSession>()
271
+ const userSession = new PikkuSessionService<CoreUserSession>()
273
272
  const { params, route, meta } = matchedRoute
274
- const {
275
- singletonServices,
276
- createSessionServices,
277
- skipUserSession,
278
- requestId,
279
- } = services
273
+ const { singletonServices, createWireServices, skipUserSession, requestId } =
274
+ services
280
275
 
281
276
  const requiresSession = route.auth !== false
282
- let sessionServices: any
277
+ let wireServices: any
283
278
  let result: any
284
279
 
285
280
  // Attach URL parameters to the request object
@@ -324,38 +319,16 @@ const executeRoute = async (
324
319
  }
325
320
  }
326
321
 
327
- const interaction: PikkuInteraction = { http, channel }
328
-
329
- const getAllServices = async (session?: CoreUserSession) => {
330
- // Create session-specific services for handling the request
331
- sessionServices = await createSessionServices(
332
- { ...singletonServices, userSession, channel },
333
- { http },
334
- session
335
- )
336
-
337
- return rpcService.injectRPCService(
338
- {
339
- ...singletonServices,
340
- ...sessionServices,
341
- http,
342
- userSession,
343
- channel,
344
- },
345
- interaction,
346
- route.auth
347
- )
348
- }
322
+ const wire: PikkuWire = { http, channel, session: userSession }
349
323
 
350
324
  result = await runPikkuFunc(
351
- PikkuWiringTypes.http,
325
+ 'http',
352
326
  `${meta.method}:${meta.route}`,
353
327
  meta.pikkuFuncName,
354
328
  {
355
329
  singletonServices,
356
- getAllServices,
330
+ createWireServices,
357
331
  auth: route.auth !== false,
358
- userSession,
359
332
  data,
360
333
  inheritedMiddleware: meta.middleware,
361
334
  wireMiddleware: route.middleware,
@@ -363,7 +336,7 @@ const executeRoute = async (
363
336
  wirePermissions: route.permissions,
364
337
  coerceDataFromSchema: options.coerceDataFromSchema,
365
338
  tags: route.tags,
366
- interaction,
339
+ wire,
367
340
  }
368
341
  )
369
342
 
@@ -378,7 +351,7 @@ const executeRoute = async (
378
351
  // TODO: Evaluate if the response stream should be explicitly ended.
379
352
  // http?.response?.end()
380
353
 
381
- return sessionServices ? { result, sessionServices } : { result }
354
+ return wireServices ? { result, wireServices } : { result }
382
355
  }
383
356
 
384
357
  /**
@@ -431,11 +404,11 @@ export const pikkuFetch = async <In, Out>(
431
404
  * middleware execution, error handling, and session service cleanup.
432
405
  *
433
406
  * This function does the following:
434
- * - Wraps the incoming request and response into an HTTP interaction object.
407
+ * - Wraps the incoming request and response into an HTTP wire object.
435
408
  * - Determines the correct route based on HTTP method and path.
436
409
  * - Executes middleware and the route handler.
437
410
  * - Catches and handles errors, optionally bubbling them if configured.
438
- * - Cleans up any session services created during processing.
411
+ * - Cleans up any wire services created during processing.
439
412
  *
440
413
  * @template In Expected input data type.
441
414
  * @template Out Expected output data type.
@@ -449,7 +422,7 @@ export const fetchData = async <In, Out>(
449
422
  response: PikkuHTTPResponse,
450
423
  {
451
424
  singletonServices,
452
- createSessionServices,
425
+ createWireServices,
453
426
  skipUserSession = false,
454
427
  respondWith404 = true,
455
428
  logWarningsForStatusCodes = [],
@@ -462,11 +435,11 @@ export const fetchData = async <In, Out>(
462
435
  (request as any).getHeader?.('x-request-id') ||
463
436
  generateRequestId?.() ||
464
437
  createWeakUID()
465
- let sessionServices: SessionServices<typeof singletonServices> | undefined
438
+ let wireServices: WireServices<typeof singletonServices> | undefined
466
439
  let result: Out
467
440
 
468
- // Combine the request and response into one interaction object
469
- const http = createHTTPInteraction(
441
+ // Combine the request and response into one wire object
442
+ const http = createHTTPWire(
470
443
  request instanceof Request ? new PikkuFetchHTTPRequest(request) : request,
471
444
  response
472
445
  )
@@ -487,10 +460,10 @@ export const fetchData = async <In, Out>(
487
460
  }
488
461
 
489
462
  // Execute the matched route along with its middleware and session management
490
- ;({ result, sessionServices } = await executeRoute(
463
+ ;({ result, wireServices } = await executeRoute(
491
464
  {
492
465
  singletonServices,
493
- createSessionServices,
466
+ createWireServices,
494
467
  skipUserSession,
495
468
  requestId,
496
469
  },
@@ -513,8 +486,8 @@ export const fetchData = async <In, Out>(
513
486
  )
514
487
  } finally {
515
488
  // Clean up any session-specific services created during processing
516
- if (sessionServices) {
517
- await closeSessionServices(singletonServices.logger, sessionServices)
489
+ if (wireServices) {
490
+ await closeWireServices(singletonServices.logger, wireServices)
518
491
  }
519
492
  }
520
493
  }
@@ -1,14 +1,12 @@
1
1
  import type { SerializeOptions } from 'cookie'
2
2
  import type { PikkuError } from '../../errors/error-handler.js'
3
3
  import type {
4
- PikkuDocs,
5
4
  CoreServices,
6
5
  CoreSingletonServices,
7
6
  CoreUserSession,
8
- CreateSessionServices,
7
+ CreateWireServices,
9
8
  CorePikkuMiddleware,
10
- MiddlewareMetadata,
11
- PermissionMetadata,
9
+ CommonWireMeta,
12
10
  } from '../../types/core.types.js'
13
11
  import type {
14
12
  CorePikkuFunction,
@@ -46,7 +44,7 @@ export type RunHTTPWiringOptions = Partial<{
46
44
 
47
45
  export type RunHTTPWiringParams = {
48
46
  singletonServices: CoreSingletonServices
49
- createSessionServices: CreateSessionServices<
47
+ createWireServices: CreateWireServices<
50
48
  CoreSingletonServices,
51
49
  CoreServices<CoreSingletonServices>,
52
50
  CoreUserSession
@@ -83,7 +81,7 @@ export type CoreHTTPFunction = {
83
81
  }>
84
82
  }
85
83
  /**
86
- * Represents a http interaction within Pikku, including a request and response.
84
+ * Represents a http wire within Pikku, including a request and response.
87
85
  */
88
86
  export interface PikkuHTTP<In = unknown> {
89
87
  request?: PikkuHTTPRequest<In>
@@ -123,14 +121,12 @@ export type CoreHTTPFunctionWiring<
123
121
  In,
124
122
  Out,
125
123
  any,
126
- any,
127
124
  any
128
125
  > = CorePikkuFunction<In, Out>,
129
126
  PikkuFunctionSessionless extends CorePikkuFunctionSessionless<
130
127
  In,
131
128
  Out,
132
129
  any,
133
- any,
134
130
  any
135
131
  > = CorePikkuFunctionSessionless<In, Out>,
136
132
  PikkuPermission extends CorePikkuPermission<
@@ -242,18 +238,13 @@ export type HTTPFunctionMetaInputTypes = {
242
238
  /**
243
239
  * Represents metadata for a set of HTTP wirings, including HTTP wiring details, methods, input/output types, and documentation.
244
240
  */
245
- export type HTTPWiringMeta = {
246
- pikkuFuncName: string
241
+ export type HTTPWiringMeta = CommonWireMeta & {
247
242
  route: string
248
243
  method: HTTPMethod
249
244
  params?: string[]
250
245
  query?: string[]
251
246
  inputTypes?: HTTPFunctionMetaInputTypes
252
- docs?: PikkuDocs
253
- tags?: string[]
254
247
  sse?: true
255
- middleware?: MiddlewareMetadata[] // Pre-resolved middleware chain (global + route + tag + explicit)
256
- permissions?: PermissionMetadata[] // Pre-resolved permission chain (global + route + tag + explicit)
257
248
  }
258
249
  export type HTTPWiringsMeta = Record<HTTPMethod, Record<string, HTTPWiringMeta>>
259
250
 
@@ -1,10 +1,9 @@
1
1
  import {
2
- PikkuInteraction,
3
- PikkuWiringTypes,
2
+ PikkuWire,
4
3
  type CoreServices,
5
4
  type CoreSingletonServices,
6
5
  type CoreUserSession,
7
- type CreateSessionServices,
6
+ type CreateWireServices,
8
7
  } from '../../types/core.types.js'
9
8
  import type {
10
9
  CoreMCPResource,
@@ -20,11 +19,11 @@ import type {
20
19
  CorePikkuFunctionSessionless,
21
20
  } from '../../function/functions.types.js'
22
21
  import { getErrorResponse } from '../../errors/error-handler.js'
23
- import { closeSessionServices } from '../../utils.js'
22
+ import { closeWireServices } from '../../utils.js'
24
23
  import { pikkuState } from '../../pikku-state.js'
25
24
  import { addFunction, runPikkuFunc } from '../../function/function-runner.js'
26
- import { rpcService } from '../rpc/rpc-runner.js'
27
25
  import { BadRequestError, NotFoundError } from '../../errors/errors.js'
26
+ import { PikkuSessionService } from '../../services/user-session-service.js'
28
27
 
29
28
  export class MCPError extends Error {
30
29
  constructor(public readonly error: JsonRpcErrorResponse) {
@@ -37,7 +36,7 @@ export class MCPError extends Error {
37
36
  export type RunMCPEndpointParams<Tools extends string = any> = {
38
37
  singletonServices: CoreSingletonServices
39
38
  mcp?: PikkuMCP<Tools>
40
- createSessionServices?: CreateSessionServices<
39
+ createWireServices?: CreateWireServices<
41
40
  CoreSingletonServices,
42
41
  CoreServices<CoreSingletonServices>,
43
42
  CoreUserSession
@@ -209,13 +208,9 @@ async function runMCPPikkuFunc(
209
208
  name: string,
210
209
  mcp: CoreMCPResource | CoreMCPTool | CoreMCPPrompt | undefined,
211
210
  pikkuFuncName: string | undefined,
212
- {
213
- singletonServices,
214
- createSessionServices,
215
- mcp: mcpInteraction,
216
- }: RunMCPEndpointParams
211
+ { singletonServices, createWireServices, mcp: mcpWire }: RunMCPEndpointParams
217
212
  ): Promise<JsonRpcResponse> {
218
- let sessionServices: any
213
+ let wireServices: any
219
214
 
220
215
  try {
221
216
  // Validate JSON-RPC request structure
@@ -239,23 +234,9 @@ async function runMCPPikkuFunc(
239
234
 
240
235
  singletonServices.logger.debug(`Running MCP ${type}: ${name}`)
241
236
 
242
- const interaction: PikkuInteraction = { mcp: mcpInteraction }
243
-
244
- const getAllServices = async () => {
245
- sessionServices = await createSessionServices?.(
246
- singletonServices,
247
- interaction,
248
- undefined
249
- )
250
-
251
- return rpcService.injectRPCService(
252
- {
253
- ...singletonServices,
254
- ...sessionServices,
255
- mcp: mcpInteraction,
256
- },
257
- interaction
258
- )
237
+ const wire: PikkuWire = {
238
+ mcp: mcpWire,
239
+ session: new PikkuSessionService(),
259
240
  }
260
241
 
261
242
  // Get metadata for the MCP endpoint to access pre-resolved middleware
@@ -268,23 +249,17 @@ async function runMCPPikkuFunc(
268
249
  meta = pikkuState('mcp', 'promptsMeta')[name]
269
250
  }
270
251
 
271
- const result = await runPikkuFunc(
272
- PikkuWiringTypes.mcp,
273
- `${type}:${name}`,
274
- pikkuFuncName,
275
- {
276
- singletonServices,
277
- getAllServices,
278
- userSession: undefined, // TODO
279
- data: () => request.params,
280
- inheritedMiddleware: meta?.middleware,
281
- wireMiddleware: mcp.middleware,
282
- inheritedPermissions: meta?.permissions,
283
- wirePermissions: mcp.permissions,
284
- tags: mcp.tags,
285
- interaction,
286
- }
287
- )
252
+ const result = await runPikkuFunc('mcp', `${type}:${name}`, pikkuFuncName, {
253
+ singletonServices,
254
+ createWireServices,
255
+ data: () => request.params,
256
+ inheritedMiddleware: meta?.middleware,
257
+ wireMiddleware: mcp.middleware,
258
+ inheritedPermissions: meta?.permissions,
259
+ wirePermissions: mcp.permissions,
260
+ tags: mcp.tags,
261
+ wire,
262
+ })
288
263
 
289
264
  return {
290
265
  id: request.id,
@@ -316,8 +291,8 @@ async function runMCPPikkuFunc(
316
291
  })
317
292
  }
318
293
  } finally {
319
- if (sessionServices) {
320
- await closeSessionServices(singletonServices.logger, sessionServices)
294
+ if (wireServices) {
295
+ await closeWireServices(singletonServices.logger, wireServices)
321
296
  }
322
297
  }
323
298
  }
@@ -104,6 +104,8 @@ export type CoreMCPResource<
104
104
  uri: string
105
105
  title: string
106
106
  description: string
107
+ summary?: string
108
+ errors?: string[]
107
109
  mimeType?: string
108
110
  size?: number
109
111
  streaming?: boolean
@@ -126,6 +128,8 @@ export type CoreMCPTool<
126
128
  name: string
127
129
  title?: string
128
130
  description: string
131
+ summary?: string
132
+ errors?: string[]
129
133
  func: PikkuFunctionConfig
130
134
  tags?: string[]
131
135
  streaming?: boolean
@@ -145,6 +149,8 @@ export type CoreMCPPrompt<
145
149
  > = {
146
150
  name: string
147
151
  description: string
152
+ summary?: string
153
+ errors?: string[]
148
154
  func: PikkuFunctionConfig
149
155
  tags?: string[]
150
156
  middleware?: PikkuMiddleware[]