@pikku/cli 0.9.16-next.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.pikku/channel/pikku-channel-types.gen.ts +28 -29
- package/.pikku/channel/pikku-channels-map.gen.d.ts +44 -0
- package/.pikku/channel/pikku-channels-meta.gen.ts +5 -0
- package/.pikku/channel/pikku-channels.gen.ts +4 -0
- package/.pikku/cli/pikku-cli-channel.gen.ts +34 -0
- package/.pikku/cli/pikku-cli-client.gen.ts +43 -0
- package/.pikku/cli/pikku-cli-types.gen.ts +14 -15
- package/.pikku/cli/pikku-cli-wirings-meta.gen.ts +142 -2
- package/.pikku/cli/pikku-cli-wirings.gen.ts +4 -2
- package/.pikku/cli/pikku-cli.gen.ts +41 -0
- package/.pikku/function/pikku-function-types.gen.ts +167 -19
- package/.pikku/function/pikku-functions-meta.gen.ts +220 -192
- package/.pikku/function/pikku-functions-meta.min.gen.ts +61 -56
- package/.pikku/function/pikku-functions.gen.ts +3 -1
- package/.pikku/http/pikku-http-types.gen.ts +28 -3
- package/.pikku/http/pikku-http-wirings-map.gen.d.ts +43 -0
- package/.pikku/http/pikku-http-wirings-meta.gen.ts +13 -0
- package/.pikku/http/pikku-http-wirings.gen.ts +4 -0
- package/.pikku/mcp/pikku-mcp-types.gen.ts +15 -13
- package/.pikku/mcp/pikku-mcp-wirings-meta.gen.ts +7 -0
- package/.pikku/mcp/pikku-mcp-wirings.gen.ts +4 -0
- package/.pikku/mcp/pikku-mcp.gen.json +5 -0
- package/.pikku/pikku-bootstrap.gen.ts +11 -1
- package/.pikku/pikku-services.gen.ts +1 -5
- package/.pikku/pikku-types.gen.ts +1 -2
- package/.pikku/pikku-websocket.gen.ts +76 -0
- package/.pikku/queue/pikku-queue-types.gen.ts +1 -2
- package/.pikku/queue/pikku-queue-workers-wirings-map.gen.d.ts +57 -0
- package/.pikku/queue/pikku-queue-workers-wirings-meta.gen.ts +5 -0
- package/.pikku/queue/pikku-queue-workers-wirings.gen.ts +4 -0
- package/.pikku/rpc/pikku-rpc-wirings-map.gen.d.ts +5 -4
- package/.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts +19 -17
- package/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.ts +15 -14
- package/.pikku/scheduler/pikku-scheduler-types.gen.ts +1 -2
- package/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.ts +5 -0
- package/.pikku/scheduler/pikku-schedulers-wirings.gen.ts +4 -0
- package/.pikku/schemas/register.gen.ts +15 -11
- package/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
- package/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -0
- package/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
- package/CHANGELOG.md +6 -0
- package/bin/pikku.ts +63 -11
- package/build.sh +1 -1
- package/cli.schema.json +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +11 -20
- package/dist/.pikku/channel/pikku-channel-types.gen.js +9 -11
- package/dist/.pikku/channel/pikku-channels-meta.gen.d.ts +1 -0
- package/dist/.pikku/channel/pikku-channels-meta.gen.js +5 -0
- package/dist/.pikku/channel/pikku-channels.gen.d.ts +4 -0
- package/dist/.pikku/channel/pikku-channels.gen.js +5 -0
- package/dist/.pikku/cli/pikku-cli-channel.gen.d.ts +1 -0
- package/dist/.pikku/cli/pikku-cli-channel.gen.js +33 -0
- package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +10 -0
- package/dist/.pikku/cli/pikku-cli-client.gen.js +34 -0
- package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +9 -12
- package/dist/.pikku/cli/pikku-cli-types.gen.js +5 -4
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +142 -2
- package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +3 -2
- package/dist/.pikku/cli/pikku-cli-wirings.gen.js +4 -3
- package/dist/.pikku/cli/pikku-cli.gen.d.ts +10 -0
- package/dist/.pikku/cli/pikku-cli.gen.js +38 -0
- package/dist/.pikku/function/pikku-function-types.gen.d.ts +141 -20
- package/dist/.pikku/function/pikku-function-types.gen.js +108 -12
- package/dist/.pikku/function/pikku-functions-meta.gen.js +220 -192
- package/dist/.pikku/function/pikku-functions-meta.min.gen.js +61 -56
- package/dist/.pikku/function/pikku-functions.gen.js +3 -1
- package/dist/.pikku/http/pikku-http-types.gen.d.ts +21 -2
- package/dist/.pikku/http/pikku-http-types.gen.js +24 -3
- package/dist/.pikku/http/pikku-http-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/http/pikku-http-wirings-meta.gen.js +13 -0
- package/dist/.pikku/http/pikku-http-wirings.gen.d.ts +4 -0
- package/dist/.pikku/http/pikku-http-wirings.gen.js +5 -0
- package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +11 -8
- package/dist/.pikku/mcp/pikku-mcp-types.gen.js +6 -6
- package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/mcp/pikku-mcp-wirings-meta.gen.js +7 -0
- package/dist/.pikku/mcp/pikku-mcp-wirings.gen.d.ts +4 -0
- package/dist/.pikku/mcp/pikku-mcp-wirings.gen.js +5 -0
- package/dist/.pikku/pikku-bootstrap.gen.d.ts +11 -1
- package/dist/.pikku/pikku-bootstrap.gen.js +11 -1
- package/dist/.pikku/pikku-services.gen.d.ts +1 -4
- package/dist/.pikku/pikku-services.gen.js +0 -6
- package/dist/.pikku/pikku-types.gen.d.ts +1 -2
- package/dist/.pikku/pikku-types.gen.js +1 -2
- package/dist/.pikku/pikku-websocket.gen.d.ts +31 -0
- package/dist/.pikku/pikku-websocket.gen.js +49 -0
- package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -2
- package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -2
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +5 -0
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +4 -0
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +5 -0
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +15 -14
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -2
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -2
- package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/scheduler/pikku-schedulers-wirings-meta.gen.js +5 -0
- package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.d.ts +4 -0
- package/dist/.pikku/scheduler/pikku-schedulers-wirings.gen.js +5 -0
- package/dist/.pikku/schemas/register.gen.js +9 -7
- package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuChannelsOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuPermissionsOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/PikkuSchemasOutput.schema.json +1 -1
- package/dist/bin/pikku.d.ts +1 -1
- package/dist/bin/pikku.js +37 -6
- package/dist/src/cli.wiring.js +99 -75
- package/dist/src/functions/commands/all.js +10 -0
- package/dist/src/functions/runtimes/nextjs/pikku-command-nextjs.js +10 -8
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.d.ts +1 -1
- package/dist/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.js +2 -2
- package/dist/src/functions/wirings/channels/pikku-channels.js +0 -5
- package/dist/src/functions/wirings/channels/pikku-command-channel-types.js +0 -2
- package/dist/src/functions/wirings/channels/pikku-command-channels-map.js +0 -5
- package/dist/src/functions/wirings/channels/pikku-command-channels.js +0 -5
- package/dist/src/functions/wirings/channels/pikku-command-websocket-typed.js +6 -3
- package/dist/src/functions/wirings/channels/serialize-channel-types.js +27 -28
- package/dist/src/functions/wirings/channels/serialize-typed-channel-map.js +4 -1
- package/dist/src/functions/wirings/cli/pikku-command-cli-entry.js +31 -8
- package/dist/src/functions/wirings/cli/pikku-command-cli-types.js +0 -2
- package/dist/src/functions/wirings/cli/pikku-command-cli.js +0 -2
- package/dist/src/functions/wirings/cli/serialize-channel-cli-client.d.ts +6 -2
- package/dist/src/functions/wirings/cli/serialize-channel-cli-client.js +88 -11
- package/dist/src/functions/wirings/cli/serialize-channel-cli.d.ts +1 -1
- package/dist/src/functions/wirings/cli/serialize-channel-cli.js +1 -18
- package/dist/src/functions/wirings/cli/serialize-cli-types.js +13 -14
- package/dist/src/functions/wirings/cli/serialize-local-cli-bootstrap.js +19 -14
- package/dist/src/functions/wirings/fetch/index.js +6 -3
- package/dist/src/functions/wirings/functions/pikku-command-function-types-split.js +6 -5
- package/dist/src/functions/wirings/functions/pikku-command-function-types.js +0 -2
- package/dist/src/functions/wirings/functions/pikku-command-functions.js +0 -2
- package/dist/src/functions/wirings/functions/pikku-command-services.d.ts +1 -1
- package/dist/src/functions/wirings/functions/pikku-command-services.js +11 -21
- package/dist/src/functions/wirings/functions/pikku-function-types.js +0 -2
- package/dist/src/functions/wirings/functions/schemas.js +0 -2
- package/dist/src/functions/wirings/functions/serialize-function-types.d.ts +1 -1
- package/dist/src/functions/wirings/functions/serialize-function-types.js +167 -19
- package/dist/src/functions/wirings/functions/serialize-pikku-types-hub.js +0 -1
- package/dist/src/functions/wirings/http/openapi-spec-generator.d.ts +2 -1
- package/dist/src/functions/wirings/http/pikku-command-http-map.js +0 -5
- package/dist/src/functions/wirings/http/pikku-command-http-routes.js +0 -5
- package/dist/src/functions/wirings/http/pikku-command-http-types.js +0 -2
- package/dist/src/functions/wirings/http/pikku-command-openapi.js +7 -4
- package/dist/src/functions/wirings/http/pikku-http-routes.js +0 -5
- package/dist/src/functions/wirings/http/serialize-http-types.js +27 -2
- package/dist/src/functions/wirings/mcp/pikku-command-mcp-json.js +0 -5
- package/dist/src/functions/wirings/mcp/pikku-command-mcp-types.js +0 -2
- package/dist/src/functions/wirings/mcp/pikku-command-mcp.js +0 -5
- package/dist/src/functions/wirings/mcp/serialize-mcp-json.d.ts +1 -1
- package/dist/src/functions/wirings/mcp/serialize-mcp-types.js +14 -12
- package/dist/src/functions/wirings/middleware/pikku-command-middleware.js +0 -2
- package/dist/src/functions/wirings/middleware/serialize-middleware-groups-meta.js +1 -7
- package/dist/src/functions/wirings/permissions/pikku-command-permissions.d.ts +1 -0
- package/dist/src/functions/wirings/permissions/pikku-command-permissions.js +28 -0
- package/dist/src/functions/wirings/permissions/serialize-permissions-imports.d.ts +2 -0
- package/dist/src/functions/wirings/permissions/serialize-permissions-imports.js +43 -0
- package/dist/src/functions/wirings/queue/pikku-command-queue-map.js +0 -5
- package/dist/src/functions/wirings/queue/pikku-command-queue-service.js +6 -3
- package/dist/src/functions/wirings/queue/pikku-command-queue-types.js +0 -2
- package/dist/src/functions/wirings/queue/pikku-command-queue.js +0 -5
- package/dist/src/functions/wirings/queue/pikku-queue-map.js +0 -5
- package/dist/src/functions/wirings/queue/pikku-queue.js +1 -5
- package/dist/src/functions/wirings/queue/serialize-queue-meta.d.ts +1 -1
- package/dist/src/functions/wirings/queue/serialize-queue-types.js +0 -1
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-client.js +5 -3
- package/dist/src/functions/wirings/rpc/pikku-command-rpc-map.js +0 -4
- package/dist/src/functions/wirings/rpc/pikku-command-rpc.js +0 -2
- package/dist/src/functions/wirings/scheduler/pikku-command-scheduler-types.js +0 -2
- package/dist/src/functions/wirings/scheduler/pikku-command-scheduler.js +0 -5
- package/dist/src/functions/wirings/scheduler/serialize-scheduler-types.js +0 -1
- package/dist/src/middleware/log-command-info-and-time.d.ts +2 -8
- package/dist/src/middleware/log-command-info-and-time.js +2 -14
- package/dist/src/services/cli-logger-forwarder.service.d.ts +6 -2
- package/dist/src/services/cli-logger-forwarder.service.js +9 -0
- package/dist/src/services/cli-logger.service.d.ts +4 -0
- package/dist/src/services/cli-logger.service.js +11 -0
- package/dist/src/services.d.ts +5 -0
- package/dist/src/services.js +111 -13
- package/dist/src/utils/custom-types-generator.js +8 -2
- package/dist/src/utils/file-writer.d.ts +4 -1
- package/dist/src/utils/file-writer.js +13 -3
- package/dist/src/utils/get-cli-version.d.ts +5 -0
- package/dist/src/utils/get-cli-version.js +27 -0
- package/dist/src/utils/pikku-cli-config.d.ts +1 -2
- package/dist/src/utils/pikku-cli-config.js +9 -28
- package/dist/src/utils/schema-generator.js +3 -2
- package/dist/src/utils/serialize-import-map.js +0 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -8
- package/pikku.config.json +4 -2
- package/src/cli.wiring.ts +101 -74
- package/src/functions/commands/all.ts +12 -0
- package/src/functions/runtimes/nextjs/pikku-command-nextjs.ts +12 -12
- package/src/functions/runtimes/nextjs/serialize-nextjs-backend-wrapper.ts +2 -2
- package/src/functions/wirings/channels/pikku-channels.ts +0 -5
- package/src/functions/wirings/channels/pikku-command-channel-types.ts +0 -2
- package/src/functions/wirings/channels/pikku-command-channels-map.ts +0 -5
- package/src/functions/wirings/channels/pikku-command-channels.ts +0 -5
- package/src/functions/wirings/channels/pikku-command-websocket-typed.ts +7 -3
- package/src/functions/wirings/channels/serialize-channel-types.ts +27 -28
- package/src/functions/wirings/channels/serialize-typed-channel-map.ts +4 -1
- package/src/functions/wirings/cli/pikku-command-cli-entry.ts +52 -9
- package/src/functions/wirings/cli/pikku-command-cli-types.ts +0 -2
- package/src/functions/wirings/cli/pikku-command-cli.ts +0 -2
- package/src/functions/wirings/cli/serialize-channel-cli-client.ts +111 -12
- package/src/functions/wirings/cli/serialize-channel-cli.ts +2 -23
- package/src/functions/wirings/cli/serialize-cli-types.ts +13 -14
- package/src/functions/wirings/cli/serialize-local-cli-bootstrap.ts +19 -14
- package/src/functions/wirings/fetch/index.ts +7 -3
- package/src/functions/wirings/functions/pikku-command-function-types-split.ts +14 -5
- package/src/functions/wirings/functions/pikku-command-function-types.ts +0 -2
- package/src/functions/wirings/functions/pikku-command-functions.ts +0 -2
- package/src/functions/wirings/functions/pikku-command-services.ts +13 -24
- package/src/functions/wirings/functions/pikku-function-types.ts +0 -2
- package/src/functions/wirings/functions/schemas.ts +0 -2
- package/src/functions/wirings/functions/serialize-function-types.ts +169 -19
- package/src/functions/wirings/functions/serialize-pikku-types-hub.ts +0 -1
- package/src/functions/wirings/http/openapi-spec-generator.ts +2 -1
- package/src/functions/wirings/http/pikku-command-http-map.ts +0 -5
- package/src/functions/wirings/http/pikku-command-http-routes.ts +0 -5
- package/src/functions/wirings/http/pikku-command-http-types.ts +0 -2
- package/src/functions/wirings/http/pikku-command-openapi.ts +9 -4
- package/src/functions/wirings/http/pikku-http-routes.ts +0 -5
- package/src/functions/wirings/http/serialize-http-types.ts +27 -2
- package/src/functions/wirings/mcp/pikku-command-mcp-json.ts +0 -5
- package/src/functions/wirings/mcp/pikku-command-mcp-types.ts +0 -2
- package/src/functions/wirings/mcp/pikku-command-mcp.ts +0 -5
- package/src/functions/wirings/mcp/serialize-mcp-json.ts +1 -1
- package/src/functions/wirings/mcp/serialize-mcp-types.ts +14 -12
- package/src/functions/wirings/middleware/pikku-command-middleware.ts +0 -2
- package/src/functions/wirings/middleware/serialize-middleware-groups-meta.ts +1 -7
- package/src/functions/wirings/permissions/pikku-command-permissions.ts +49 -0
- package/src/functions/wirings/permissions/serialize-permissions-imports.test.ts +274 -0
- package/src/functions/wirings/permissions/serialize-permissions-imports.ts +78 -0
- package/src/functions/wirings/queue/pikku-command-queue-map.ts +0 -5
- package/src/functions/wirings/queue/pikku-command-queue-service.ts +7 -3
- package/src/functions/wirings/queue/pikku-command-queue-types.ts +0 -2
- package/src/functions/wirings/queue/pikku-command-queue.ts +0 -5
- package/src/functions/wirings/queue/pikku-queue-map.ts +0 -5
- package/src/functions/wirings/queue/pikku-queue.ts +3 -6
- package/src/functions/wirings/queue/serialize-queue-meta.ts +1 -1
- package/src/functions/wirings/queue/serialize-queue-types.ts +0 -1
- package/src/functions/wirings/rpc/pikku-command-rpc-client.ts +6 -3
- package/src/functions/wirings/rpc/pikku-command-rpc-map.ts +0 -4
- package/src/functions/wirings/rpc/pikku-command-rpc.ts +0 -2
- package/src/functions/wirings/scheduler/pikku-command-scheduler-types.ts +0 -2
- package/src/functions/wirings/scheduler/pikku-command-scheduler.ts +0 -5
- package/src/functions/wirings/scheduler/serialize-scheduler-types.ts +0 -1
- package/src/middleware/log-command-info-and-time.ts +2 -28
- package/src/services/cli-logger-forwarder.service.ts +15 -2
- package/src/services/cli-logger.service.ts +15 -0
- package/src/services.ts +148 -19
- package/src/utils/custom-types-generator.ts +8 -2
- package/src/utils/file-writer.ts +19 -3
- package/src/utils/get-cli-version.ts +28 -0
- package/src/utils/pikku-cli-config.ts +6 -35
- package/src/utils/schema-generator.ts +7 -3
- package/src/utils/serialize-import-map.ts +0 -4
- package/types/application-types.d.ts +4 -1
- package/types/config.d.ts +15 -3
- package/dist/.pikku/rpc/pikku-bootstrap-rpc.gen.d.ts +0 -6
- package/dist/.pikku/rpc/pikku-bootstrap-rpc.gen.js +0 -6
- package/dist/src/serialize-pikku-types.d.ts +0 -4
- package/dist/src/serialize-pikku-types.js +0 -605
- package/src/serialize-pikku-types.ts +0 -613
|
@@ -1,613 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*/
|
|
4
|
-
export const serializePikkuTypes = (
|
|
5
|
-
userSessionTypeImport: string,
|
|
6
|
-
userSessionTypeName: string,
|
|
7
|
-
singletonServicesTypeImport: string,
|
|
8
|
-
singletonServicesTypeName: string,
|
|
9
|
-
sessionServicesTypeImport: string,
|
|
10
|
-
sessionServicesTypeName: string,
|
|
11
|
-
rpcMapTypeImport: string
|
|
12
|
-
) => {
|
|
13
|
-
return `/**
|
|
14
|
-
* This is used to provide the application types in the typescript project
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { CorePikkuFunctionConfig, CorePikkuPermission, CorePikkuMiddleware, addHTTPMiddleware, addMiddleware, addPermission } from '@pikku/core'
|
|
18
|
-
import { CorePikkuFunction, CorePikkuFunctionSessionless } from '@pikku/core/function'
|
|
19
|
-
import { CoreHTTPFunctionWiring, AssertHTTPWiringParams, wireHTTP as wireHTTPCore } from '@pikku/core/http'
|
|
20
|
-
import { CoreScheduledTask, wireScheduler as wireSchedulerCore } from '@pikku/core/scheduler'
|
|
21
|
-
import { CoreChannel, PikkuChannel, wireChannel as wireChannelCore } from '@pikku/core/channel'
|
|
22
|
-
import { CoreQueueWorker, wireQueueWorker as wireQueueWorkerCore } from '@pikku/core/queue'
|
|
23
|
-
import { CoreMCPResource, CoreMCPTool, CoreMCPPrompt, wireMCPResource as wireMCPResourceCore, wireMCPTool as wireMCPToolCore, wireMCPPrompt as wireMCPPromptCore, MCPResourceResponse, MCPToolResponse, MCPPromptResponse, PikkuMCP } from '@pikku/core'
|
|
24
|
-
|
|
25
|
-
${userSessionTypeImport}
|
|
26
|
-
${singletonServicesTypeImport}
|
|
27
|
-
${sessionServicesTypeImport}
|
|
28
|
-
${rpcMapTypeImport}
|
|
29
|
-
|
|
30
|
-
${singletonServicesTypeName !== 'SingletonServices' ? `type SingletonServices = ${singletonServicesTypeName}` : ''}
|
|
31
|
-
${sessionServicesTypeName !== 'Services' ? `type Services = ${sessionServicesTypeName}` : ''}
|
|
32
|
-
${userSessionTypeName !== 'Session' ? `type Session = ${userSessionTypeName}` : ''}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Type-safe API permission definition that integrates with your application's session type.
|
|
36
|
-
* Use this to define authorization logic for your API endpoints.
|
|
37
|
-
*
|
|
38
|
-
* @template In - The input type that the permission check will receive
|
|
39
|
-
* @template RequiredServices - The services required for this permission check
|
|
40
|
-
*/
|
|
41
|
-
type PikkuPermission<In = unknown, RequiredServices extends Services = Services> = CorePikkuPermission<In, RequiredServices, Session>
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Type-safe middleware definition that can access your application's services and session.
|
|
45
|
-
* Use this to define reusable middleware that can be applied to multiple HTTP wirings.
|
|
46
|
-
*
|
|
47
|
-
* @template RequiredServices - The services required for this middleware
|
|
48
|
-
*/
|
|
49
|
-
type PikkuMiddleware<RequiredServices extends SingletonServices = SingletonServices> = CorePikkuMiddleware<RequiredServices, Session>
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Factory function for creating permissions with tree-shaking support.
|
|
53
|
-
* This enables the bundler to detect which services your permission actually uses.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* \`\`\`typescript
|
|
57
|
-
* const permission = pikkuPermission(({ logger }, data, session) => {
|
|
58
|
-
* return session?.isAdmin || false
|
|
59
|
-
* })
|
|
60
|
-
* \`\`\`
|
|
61
|
-
*/
|
|
62
|
-
export const pikkuPermission = <In>(func: PikkuPermission<In>) => {
|
|
63
|
-
return func
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Factory function for creating middleware with tree-shaking support.
|
|
68
|
-
* This enables the bundler to detect which services your middleware actually uses.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* \`\`\`typescript
|
|
72
|
-
* const middleware = pikkuMiddleware(({ logger }, interactions, next) => {
|
|
73
|
-
* logger.info('Middleware executed')
|
|
74
|
-
* await next()
|
|
75
|
-
* })
|
|
76
|
-
* \`\`\`
|
|
77
|
-
*/
|
|
78
|
-
export const pikkuMiddleware = (func: PikkuMiddleware) => {
|
|
79
|
-
return func
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* A sessionless API function that doesn't require user authentication.
|
|
84
|
-
* Use this for public endpoints, health checks, or operations that don't need user context.
|
|
85
|
-
*
|
|
86
|
-
* @template In - The input type
|
|
87
|
-
* @template Out - The output type that the function returns
|
|
88
|
-
* @template ChannelData - Channel data type (null = optional channel)
|
|
89
|
-
* @template MCPData - MCP data type (null = optional MCP)
|
|
90
|
-
* @template RequiredServices - Services required by this function
|
|
91
|
-
*/
|
|
92
|
-
type PikkuFunctionSessionless<
|
|
93
|
-
In = unknown,
|
|
94
|
-
Out = never,
|
|
95
|
-
ChannelData = null, // null means optional channel
|
|
96
|
-
MCPData = null, // null means optional MCP
|
|
97
|
-
RequiredServices extends Services = Services &
|
|
98
|
-
{ rpc: TypedPikkuRPC } & (
|
|
99
|
-
[ChannelData] extends [null]
|
|
100
|
-
? { channel?: PikkuChannel<unknown, Out> } // Optional channel
|
|
101
|
-
: { channel: PikkuChannel<ChannelData, Out> } // Required channel with any data type
|
|
102
|
-
) & ([MCPData] extends [null]
|
|
103
|
-
? { mcp?: PikkuMCP } // Optional MCP
|
|
104
|
-
: { mcp: PikkuMCP } // Required MCP
|
|
105
|
-
)
|
|
106
|
-
> = CorePikkuFunctionSessionless<In, Out, ChannelData, RequiredServices, Session>
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* A session-aware API function that requires user authentication.
|
|
110
|
-
* Use this for protected endpoints that need access to user session data.
|
|
111
|
-
*
|
|
112
|
-
* @template In - The input type
|
|
113
|
-
* @template Out - The output type that the function returns
|
|
114
|
-
* @template ChannelData - Channel data type (null = optional channel)
|
|
115
|
-
* @template MCPData - MCP data type (null = optional MCP)
|
|
116
|
-
* @template RequiredServices - Services required by this function
|
|
117
|
-
*/
|
|
118
|
-
type PikkuFunction<
|
|
119
|
-
In = unknown,
|
|
120
|
-
Out = never,
|
|
121
|
-
ChannelData = null, // null means optional channel
|
|
122
|
-
MCPData = null, // null means optional MCP
|
|
123
|
-
RequiredServices extends Services = Services &
|
|
124
|
-
{ rpc: TypedPikkuRPC } & (
|
|
125
|
-
[ChannelData] extends [null]
|
|
126
|
-
? { channel?: PikkuChannel<unknown, Out> } // Optional channel
|
|
127
|
-
: { channel: PikkuChannel<ChannelData, Out> } // Required channel with any data type
|
|
128
|
-
) & ([MCPData] extends [null]
|
|
129
|
-
? { mcp?: PikkuMCP } // Optional MCP
|
|
130
|
-
: { mcp: PikkuMCP } // Required MCP
|
|
131
|
-
)
|
|
132
|
-
> = CorePikkuFunction<In, Out, ChannelData, RequiredServices, Session>
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Type definition for HTTP API wirings with type-safe path parameters.
|
|
136
|
-
* Supports both authenticated and unauthenticated functions.
|
|
137
|
-
*
|
|
138
|
-
* @template In - Input type for the HTTP wiring
|
|
139
|
-
* @template Out - Output type for the HTTP wiring
|
|
140
|
-
* @template Route - String literal type for the HTTP path (e.g., "/users/:id")
|
|
141
|
-
*/
|
|
142
|
-
type HTTPWiring<In, Out, Route extends string> = CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction<In, Out>, PikkuFunctionSessionless<In, Out>, PikkuPermission<In>, PikkuMiddleware>
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Type definition for WebSocket channels with typed data exchange.
|
|
146
|
-
* Supports connection, disconnection, and message handling.
|
|
147
|
-
*
|
|
148
|
-
* @template ChannelData - Type of data exchanged through the channel
|
|
149
|
-
* @template Channel - String literal type for the channel name
|
|
150
|
-
*/
|
|
151
|
-
type ChannelWiringFunction<I, O, C = {}> = PikkuFunctionSessionless<I, O, C> | PikkuFunction<I, O, C>
|
|
152
|
-
type ChannelWiring<ChannelData, Channel extends string> = CoreChannel<ChannelData, Channel, ChannelWiringFunction<void, unknown> | ChannelWiringFunction<void, unknown, ChannelData>, ChannelWiringFunction<void, void> | ChannelWiringFunction<void, void, ChannelData>, ChannelWiringFunction<any, any> | ChannelWiringFunction<any, any, ChannelData>, PikkuPermission>
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Type definition for scheduled tasks that run at specified intervals.
|
|
156
|
-
* These are sessionless functions that execute based on cron expressions.
|
|
157
|
-
*/
|
|
158
|
-
type SchedulerWiring = CoreScheduledTask<PikkuFunctionSessionless<void, void>, PikkuMiddleware>
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Type definition for queue workers that process background jobs.
|
|
162
|
-
*
|
|
163
|
-
* @template In - Input type for the queue job
|
|
164
|
-
* @template Out - Output type for the queue job
|
|
165
|
-
*/
|
|
166
|
-
type QueueWiring<In, Out> = CoreQueueWorker<any>
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Type definition for MCP resources that provide data to AI models.
|
|
170
|
-
*
|
|
171
|
-
* @template In - Input type for the resource request
|
|
172
|
-
*/
|
|
173
|
-
type MCPResourceWiring<In> = CoreMCPResource<PikkuFunctionSessionless<In, MCPResourceResponse, null, true>>
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Type definition for MCP tools that AI models can invoke.
|
|
177
|
-
*
|
|
178
|
-
* @template In - Input type for the tool invocation
|
|
179
|
-
*/
|
|
180
|
-
type MCPToolWiring<In> = CoreMCPTool<PikkuFunctionSessionless<In, MCPToolResponse, null, true>>
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Type definition for MCP prompts that provide templates to AI models.
|
|
184
|
-
*
|
|
185
|
-
* @template In - Input type for the prompt parameters
|
|
186
|
-
*/
|
|
187
|
-
type MCPPromptWiring<In> = CoreMCPPrompt<PikkuFunctionSessionless<In, MCPPromptResponse, null, true>>
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Creates a Pikku function that can be either session-aware or sessionless.
|
|
191
|
-
* This is the main function wrapper for creating API endpoints.
|
|
192
|
-
*
|
|
193
|
-
* @template In - Input type for the function
|
|
194
|
-
* @template Out - Output type for the function
|
|
195
|
-
* @param func - Function definition, either direct function or configuration object
|
|
196
|
-
* @returns The unwrapped function for internal use
|
|
197
|
-
*
|
|
198
|
-
* @example
|
|
199
|
-
* \\\`\\\`\\\`typescript
|
|
200
|
-
* const createUser = pikkuFunc<{name: string, email: string}, {id: number, message: string}>({
|
|
201
|
-
* func: async ({db, logger}, input) => {
|
|
202
|
-
* logger.info('Creating user', input.name)
|
|
203
|
-
* const user = await db.users.create(input)
|
|
204
|
-
* return {id: user.id, message: \\\`User \\\${input.name} created successfully\\\`}
|
|
205
|
-
* },
|
|
206
|
-
* auth: true
|
|
207
|
-
* })
|
|
208
|
-
* \\\`\\\`\\\`
|
|
209
|
-
*/
|
|
210
|
-
export const pikkuFunc = <In, Out = unknown>(
|
|
211
|
-
func:
|
|
212
|
-
| PikkuFunction<In, Out>
|
|
213
|
-
| CorePikkuFunctionConfig<PikkuFunction<In, Out>, PikkuPermission<In>>
|
|
214
|
-
) => {
|
|
215
|
-
return typeof func === 'function' ? { func } : func
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Creates a sessionless Pikku function that doesn't require user authentication.
|
|
220
|
-
* Use this for public endpoints, webhooks, or background tasks.
|
|
221
|
-
*
|
|
222
|
-
* @template In - Input type for the function
|
|
223
|
-
* @template Out - Output type for the function
|
|
224
|
-
* @param func - Function definition, either direct function or configuration object
|
|
225
|
-
* @returns The unwrapped function for internal use
|
|
226
|
-
*
|
|
227
|
-
* @example
|
|
228
|
-
* \\\`\\\`\\\`typescript
|
|
229
|
-
* const healthCheck = pikkuSessionlessFunc<void, {status: string, timestamp: string}>({
|
|
230
|
-
* func: async ({logger}) => {
|
|
231
|
-
* logger.info('Health check requested')
|
|
232
|
-
* return {status: 'healthy', timestamp: new Date().toISOString()}
|
|
233
|
-
* },
|
|
234
|
-
* name: 'healthCheck'
|
|
235
|
-
* })
|
|
236
|
-
* \\\`\\\`\\\`
|
|
237
|
-
*/
|
|
238
|
-
export const pikkuSessionlessFunc = <In, Out = unknown>(
|
|
239
|
-
func:
|
|
240
|
-
| PikkuFunctionSessionless<In, Out>
|
|
241
|
-
| CorePikkuFunctionConfig<PikkuFunctionSessionless<In, Out>, PikkuPermission<In>, PikkuMiddleware>
|
|
242
|
-
) => {
|
|
243
|
-
return typeof func === 'function' ? { func } : func
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Creates a function that handles WebSocket channel connections.
|
|
248
|
-
* Called when a client connects to a channel.
|
|
249
|
-
*
|
|
250
|
-
* @template Out - Output type for connection response
|
|
251
|
-
* @template ChannelData - Type of data associated with the channel
|
|
252
|
-
* @param func - Function definition, either direct function or configuration object
|
|
253
|
-
* @returns The unwrapped function for internal use
|
|
254
|
-
*
|
|
255
|
-
* @example
|
|
256
|
-
* \\\`\\\`\\\`typescript
|
|
257
|
-
* const onChatConnect = pikkuChannelConnectionFunc<string>({
|
|
258
|
-
* func: async ({logger, channel, eventHub}) => {
|
|
259
|
-
* logger.info('User connected to chat')
|
|
260
|
-
* await eventHub.publish('chat:join', channel.channelId, {channelId: channel.channelId})
|
|
261
|
-
* return 'Welcome to the chat!'
|
|
262
|
-
* }
|
|
263
|
-
* })
|
|
264
|
-
* \\\`\\\`\\\`
|
|
265
|
-
*/
|
|
266
|
-
export const pikkuChannelConnectionFunc = <Out = unknown, ChannelData = unknown>(
|
|
267
|
-
func:
|
|
268
|
-
| PikkuFunctionSessionless<void, Out, ChannelData>
|
|
269
|
-
| {
|
|
270
|
-
func: PikkuFunctionSessionless<void, Out, ChannelData>
|
|
271
|
-
name?: string
|
|
272
|
-
}
|
|
273
|
-
) => {
|
|
274
|
-
return typeof func === 'function' ? { func } : func
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Creates a function that handles WebSocket channel disconnections.
|
|
279
|
-
* Called when a client disconnects from a channel.
|
|
280
|
-
*
|
|
281
|
-
* @template ChannelData - Type of data associated with the channel
|
|
282
|
-
* @param func - Function definition, either direct function or configuration object
|
|
283
|
-
* @returns The unwrapped function for internal use
|
|
284
|
-
*
|
|
285
|
-
* @example
|
|
286
|
-
* \\\`\\\`\\\`typescript
|
|
287
|
-
* const onChatDisconnect = pikkuChannelDisconnectionFunc({
|
|
288
|
-
* func: async ({logger, channel, eventHub}) => {
|
|
289
|
-
* logger.info('User disconnected from chat')
|
|
290
|
-
* await eventHub.publish('chat:join', channel.channelId, {channelId: channel.channelId})
|
|
291
|
-
* }
|
|
292
|
-
* })
|
|
293
|
-
* \\\`\\\`\\\`
|
|
294
|
-
*/
|
|
295
|
-
export const pikkuChannelDisconnectionFunc = <ChannelData = unknown>(
|
|
296
|
-
func:
|
|
297
|
-
| PikkuFunctionSessionless<void, void, ChannelData>
|
|
298
|
-
| {
|
|
299
|
-
func: PikkuFunction<void, void, ChannelData>
|
|
300
|
-
name?: string
|
|
301
|
-
}
|
|
302
|
-
) => {
|
|
303
|
-
return typeof func === 'function' ? { func } : func
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
/**
|
|
307
|
-
* Creates a function that handles WebSocket channel messages.
|
|
308
|
-
* Called when a message is received on a channel.
|
|
309
|
-
*
|
|
310
|
-
* @template In - Input type for channel messages
|
|
311
|
-
* @template Out - Output type for channel responses
|
|
312
|
-
* @template ChannelData - Type of data associated with the channel
|
|
313
|
-
* @param func - Function definition, either direct function or configuration object
|
|
314
|
-
* @returns The unwrapped function for internal use
|
|
315
|
-
*
|
|
316
|
-
* @example
|
|
317
|
-
* \\\`\\\`\\\`typescript
|
|
318
|
-
* const handleChatMessage = pikkuChannelFunc<{message: string}, void>({
|
|
319
|
-
* func: async ({logger, channel}, input) => {
|
|
320
|
-
* logger.info('Chat message received:', input.message)
|
|
321
|
-
* }
|
|
322
|
-
* })
|
|
323
|
-
* \\\`\\\`\\\`
|
|
324
|
-
*/
|
|
325
|
-
export const pikkuChannelFunc = <In = unknown, Out = unknown, ChannelData = unknown>(
|
|
326
|
-
func:
|
|
327
|
-
| PikkuFunctionSessionless<In, Out, ChannelData>
|
|
328
|
-
| CorePikkuFunctionConfig<PikkuFunction<In, Out, ChannelData>, PikkuPermission<In>>
|
|
329
|
-
) => {
|
|
330
|
-
return typeof func === 'function' ? { func } : func
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Creates a function that takes no input and returns no output.
|
|
335
|
-
* Useful for health checks, triggers, or cleanup operations.
|
|
336
|
-
*
|
|
337
|
-
* @param func - Function definition, either direct function or configuration object
|
|
338
|
-
* @returns The unwrapped function for internal use
|
|
339
|
-
*
|
|
340
|
-
* @example
|
|
341
|
-
* \\\`\\\`\\\`typescript
|
|
342
|
-
* const cleanupTempFiles = pikkuVoidFunc(async ({fileSystem, logger}) => {
|
|
343
|
-
* logger.info('Starting cleanup of temporary files')
|
|
344
|
-
* await fileSystem.deleteDirectory('/tmp/uploads')
|
|
345
|
-
* logger.info('Cleanup completed')
|
|
346
|
-
* })
|
|
347
|
-
* \\\`\\\`\\\`
|
|
348
|
-
*/
|
|
349
|
-
export const pikkuVoidFunc = (
|
|
350
|
-
func:
|
|
351
|
-
| PikkuFunctionSessionless<void, void>
|
|
352
|
-
| CorePikkuFunctionConfig<PikkuFunctionSessionless<void, void>, PikkuPermission<void>>
|
|
353
|
-
) => {
|
|
354
|
-
return typeof func === 'function' ? { func } : func
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
/**
|
|
358
|
-
* Registers a WebSocket channel with the Pikku framework.
|
|
359
|
-
*
|
|
360
|
-
* @template ChannelData - Type of data associated with the channel
|
|
361
|
-
* @template Channel - String literal type for the channel name
|
|
362
|
-
* @param channel - Channel definition with connection, disconnection, and message handlers
|
|
363
|
-
*/
|
|
364
|
-
export const wireChannel = <ChannelData, Channel extends string>(
|
|
365
|
-
channel: ChannelWiring<ChannelData, Channel> & AssertHTTPWiringParams<ChannelData, Channel>
|
|
366
|
-
) => {
|
|
367
|
-
wireChannelCore(channel as any) // TODO
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Registers middleware either globally or for a specific route.
|
|
372
|
-
*
|
|
373
|
-
* When a string route pattern is provided along with middleware, the middleware
|
|
374
|
-
* is applied only to that route. Otherwise, if an array is provided, it is treated
|
|
375
|
-
* as global middleware (applied to all routes).
|
|
376
|
-
*
|
|
377
|
-
* @param routeOrMiddleware - Either a global middleware array or a route pattern string
|
|
378
|
-
* @param middleware - The middleware array to apply when a route pattern is specified
|
|
379
|
-
*
|
|
380
|
-
* @example
|
|
381
|
-
* \`\`\`typescript
|
|
382
|
-
* // Add global middleware
|
|
383
|
-
* addHTTPMiddleware([authMiddleware, loggingMiddleware])
|
|
384
|
-
*
|
|
385
|
-
* // Add route-specific middleware
|
|
386
|
-
* addHTTPMiddleware('/api/admin/*', [adminAuthMiddleware])
|
|
387
|
-
* \`\`\`
|
|
388
|
-
*/
|
|
389
|
-
export { addHTTPMiddleware }
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* Adds global middleware for a specific tag.
|
|
393
|
-
*
|
|
394
|
-
* This function allows you to register middleware that will be applied to
|
|
395
|
-
* any wiring (HTTP, Channel, Queue, Scheduler, MCP) that includes the matching tag.
|
|
396
|
-
*
|
|
397
|
-
* @param tag - The tag that the middleware should apply to.
|
|
398
|
-
* @param middleware - The middleware array to apply for the specified tag.
|
|
399
|
-
*
|
|
400
|
-
* @throws Error if middleware for the tag already exists.
|
|
401
|
-
*
|
|
402
|
-
* @example
|
|
403
|
-
* \`\`\`typescript
|
|
404
|
-
* // Add admin middleware for admin endpoints
|
|
405
|
-
* addMiddleware('admin', [adminMiddleware])
|
|
406
|
-
*
|
|
407
|
-
* // Add authentication middleware for auth endpoints
|
|
408
|
-
* addMiddleware('auth', [authMiddleware])
|
|
409
|
-
*
|
|
410
|
-
* // Add logging middleware for all API endpoints
|
|
411
|
-
* addMiddleware('api', [loggingMiddleware])
|
|
412
|
-
* \`\`\`
|
|
413
|
-
*/
|
|
414
|
-
export { addMiddleware }
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* Adds global permissions for a specific tag.
|
|
418
|
-
*
|
|
419
|
-
* This function allows you to register permissions that will be applied to
|
|
420
|
-
* any wiring (HTTP, Channel, Queue, Scheduler, MCP) that includes the matching tag.
|
|
421
|
-
*
|
|
422
|
-
* @param tag - The tag that the permissions should apply to.
|
|
423
|
-
* @param permissions - The permissions array to apply for the specified tag.
|
|
424
|
-
*
|
|
425
|
-
* @throws Error if permissions for the tag already exist.
|
|
426
|
-
*
|
|
427
|
-
* @example
|
|
428
|
-
* \`\`\`typescript
|
|
429
|
-
* // Add admin permissions for admin endpoints
|
|
430
|
-
* addPermission('admin', [adminPermission])
|
|
431
|
-
*
|
|
432
|
-
* // Add authentication permissions for auth endpoints
|
|
433
|
-
* addPermission('auth', [authPermission])
|
|
434
|
-
*
|
|
435
|
-
* // Add read permissions for all API endpoints
|
|
436
|
-
* addPermission('api', [readPermission])
|
|
437
|
-
* \`\`\`
|
|
438
|
-
*/
|
|
439
|
-
export { addPermission }
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Registers an HTTP wiring with the Pikku framework.
|
|
443
|
-
*
|
|
444
|
-
* @template In - Input type for the HTTP wiring
|
|
445
|
-
* @template Out - Output type for the HTTP wiring
|
|
446
|
-
* @template Route - String literal type for the HTTP path (e.g., "/users/:id")
|
|
447
|
-
* @param httpWiring - HTTP wiring definition with handler, method, and optional middleware
|
|
448
|
-
*/
|
|
449
|
-
export const wireHTTP = <In, Out, Route extends string>(
|
|
450
|
-
httpWiring: HTTPWiring<In, Out, Route> & AssertHTTPWiringParams<In, Route>
|
|
451
|
-
) => {
|
|
452
|
-
wireHTTPCore(httpWiring as any) // TODO
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
/**
|
|
456
|
-
* Registers a scheduled task with the Pikku framework.
|
|
457
|
-
* Tasks run based on cron expressions and are sessionless.
|
|
458
|
-
*
|
|
459
|
-
* @param task - Scheduled task definition with cron expression and handler
|
|
460
|
-
*/
|
|
461
|
-
export const wireScheduler = (task: SchedulerWiring) => {
|
|
462
|
-
wireSchedulerCore(task as any) // TODO
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
/**
|
|
466
|
-
* Registers a queue worker with the Pikku framework.
|
|
467
|
-
* Workers process background jobs from queues.
|
|
468
|
-
*
|
|
469
|
-
* @param queueWorker - Queue worker definition with job handler
|
|
470
|
-
*/
|
|
471
|
-
export const wireQueueWorker = (queueWorker: QueueWiring<any, any>) => {
|
|
472
|
-
wireQueueWorkerCore(queueWorker as any) // TODO
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Registers an MCP resource with the Pikku framework.
|
|
477
|
-
* Resources provide data that AI models can access.
|
|
478
|
-
*
|
|
479
|
-
* @template In - Input type for the resource request
|
|
480
|
-
* @param mcpResource - MCP resource definition with data provider function
|
|
481
|
-
*/
|
|
482
|
-
export const wireMCPResource = <In>(
|
|
483
|
-
mcpResource: MCPResourceWiring<In>
|
|
484
|
-
) => {
|
|
485
|
-
wireMCPResourceCore(mcpResource as any)
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* Registers an MCP tool with the Pikku framework.
|
|
490
|
-
* Tools are functions that AI models can invoke.
|
|
491
|
-
*
|
|
492
|
-
* @template In - Input type for the tool invocation
|
|
493
|
-
* @param mcpTool - MCP tool definition with action function
|
|
494
|
-
*/
|
|
495
|
-
export const wireMCPTool = <In>(
|
|
496
|
-
mcpTool: MCPToolWiring<In>
|
|
497
|
-
) => {
|
|
498
|
-
wireMCPToolCore(mcpTool as any)
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* Registers an MCP prompt with the Pikku framework.
|
|
503
|
-
* Prompts provide templates that AI models can use.
|
|
504
|
-
*
|
|
505
|
-
* @template In - Input type for the prompt parameters
|
|
506
|
-
* @param mcpPrompt - MCP prompt definition with template function
|
|
507
|
-
*/
|
|
508
|
-
export const wireMCPPrompt = <In>(
|
|
509
|
-
mcpPrompt: MCPPromptWiring<In>
|
|
510
|
-
) => {
|
|
511
|
-
wireMCPPromptCore(mcpPrompt as any)
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
/**
|
|
515
|
-
* Creates a function for handling MCP prompt requests.
|
|
516
|
-
* These functions generate prompt templates for AI models.
|
|
517
|
-
*
|
|
518
|
-
* @template In - Input type for the prompt parameters
|
|
519
|
-
* @param func - Function definition, either direct function or configuration object
|
|
520
|
-
* @returns The unwrapped function for internal use
|
|
521
|
-
*
|
|
522
|
-
* @example
|
|
523
|
-
* \`\`\`typescript
|
|
524
|
-
* const codeReviewPrompt = pikkuMCPPromptFunc<{language: string, code: string}>({
|
|
525
|
-
* func: async ({}, input) => ({
|
|
526
|
-
* messages: [{
|
|
527
|
-
* role: 'user',
|
|
528
|
-
* content: {
|
|
529
|
-
* type: 'text',
|
|
530
|
-
* text: \`Please review this \${input.language} code: \${input.code}\`
|
|
531
|
-
* }
|
|
532
|
-
* }]
|
|
533
|
-
* })
|
|
534
|
-
* })
|
|
535
|
-
* \`\`\`
|
|
536
|
-
*/
|
|
537
|
-
export const pikkuMCPPromptFunc = <In>(
|
|
538
|
-
func:
|
|
539
|
-
| PikkuFunctionSessionless<In, MCPPromptResponse>
|
|
540
|
-
| {
|
|
541
|
-
func: PikkuFunctionSessionless<In, MCPPromptResponse>
|
|
542
|
-
name?: string
|
|
543
|
-
}
|
|
544
|
-
) => {
|
|
545
|
-
return typeof func === 'function' ? { func } : func
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
/**
|
|
549
|
-
* Creates a function for handling MCP tool invocations.
|
|
550
|
-
* These functions perform actions that AI models can request.
|
|
551
|
-
*
|
|
552
|
-
* @template In - Input type for the tool invocation
|
|
553
|
-
* @param func - Function definition, either direct function or configuration object
|
|
554
|
-
* @returns The unwrapped function for internal use
|
|
555
|
-
*
|
|
556
|
-
* @example
|
|
557
|
-
* \`\`\`typescript
|
|
558
|
-
* const searchFiles = pikkuMCPToolFunc<{query: string, directory: string}>({
|
|
559
|
-
* func: async ({fileSystem}, input) => {
|
|
560
|
-
* const results = await fileSystem.search(input.query, input.directory)
|
|
561
|
-
* return [{
|
|
562
|
-
* type: 'text',
|
|
563
|
-
* text: \`Found \${results.length} files matching "\${input.query}"\`
|
|
564
|
-
* }]
|
|
565
|
-
* }
|
|
566
|
-
* })
|
|
567
|
-
* \`\`\`
|
|
568
|
-
*/
|
|
569
|
-
export const pikkuMCPToolFunc = <In>(
|
|
570
|
-
func:
|
|
571
|
-
| PikkuFunctionSessionless<In, MCPToolResponse, null, true>
|
|
572
|
-
| {
|
|
573
|
-
func: PikkuFunctionSessionless<In, MCPToolResponse, null, true>
|
|
574
|
-
name?: string
|
|
575
|
-
}
|
|
576
|
-
) => {
|
|
577
|
-
return typeof func === 'function' ? { func } : func
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
/**
|
|
581
|
-
* Creates a function for handling MCP resource requests.
|
|
582
|
-
* These functions provide data that AI models can access.
|
|
583
|
-
*
|
|
584
|
-
* @template In - Input type for the resource request
|
|
585
|
-
* @param func - Function definition, either direct function or configuration object
|
|
586
|
-
* @returns The unwrapped function for internal use
|
|
587
|
-
*
|
|
588
|
-
* @example
|
|
589
|
-
* \`\`\`typescript
|
|
590
|
-
* const getProjectFiles = pikkuMCPResourceFunc<{path: string}>({
|
|
591
|
-
* func: async ({ fileSystem }, input) => {
|
|
592
|
-
* const fileContent = await fileSystem.readFile(input.path)
|
|
593
|
-
* return [{
|
|
594
|
-
* uri: \`file://\${input.path}\`,
|
|
595
|
-
* mimeType: 'text/plain',
|
|
596
|
-
* text: fileContent
|
|
597
|
-
* }]
|
|
598
|
-
* }
|
|
599
|
-
* })
|
|
600
|
-
* \`\`\`
|
|
601
|
-
*/
|
|
602
|
-
export const pikkuMCPResourceFunc = <In>(
|
|
603
|
-
func:
|
|
604
|
-
| PikkuFunctionSessionless<In, MCPResourceResponse, null, true>
|
|
605
|
-
| {
|
|
606
|
-
func: PikkuFunctionSessionless<In, MCPResourceResponse, null, true>
|
|
607
|
-
name?: string
|
|
608
|
-
}
|
|
609
|
-
) => {
|
|
610
|
-
return typeof func === 'function' ? { func } : func
|
|
611
|
-
}
|
|
612
|
-
`
|
|
613
|
-
}
|