@pikku/core 0.7.8 → 0.8.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/CHANGELOG.md +10 -1
- package/dist/errors/error-handler.d.ts +2 -0
- package/dist/errors/errors.js +2 -0
- package/dist/{channel → events/channel}/channel-handler.d.ts +1 -1
- package/dist/{channel → events/channel}/channel-handler.js +2 -2
- package/dist/{channel → events/channel}/channel-runner.d.ts +1 -1
- package/dist/{channel → events/channel}/channel-runner.js +4 -4
- package/dist/{channel → events/channel}/channel-store.d.ts +1 -1
- package/dist/{channel → events/channel}/channel.types.d.ts +3 -3
- package/dist/{channel → events/channel}/local/local-channel-runner.js +6 -6
- package/dist/{channel → events/channel}/log-channels.d.ts +1 -1
- package/dist/{channel → events/channel}/log-channels.js +1 -1
- package/dist/{channel → events/channel}/serverless/serverless-channel-runner.js +7 -7
- package/dist/{http → events/http}/http-runner.d.ts +1 -1
- package/dist/{http → events/http}/http-runner.js +8 -8
- package/dist/{http → events/http}/http.types.d.ts +3 -3
- package/dist/{http → events/http}/index.d.ts +0 -1
- package/dist/{http → events/http}/index.js +0 -1
- package/dist/{http → events/http}/log-http-routes.d.ts +1 -1
- package/dist/{http → events/http}/log-http-routes.js +1 -1
- package/dist/{http → events/http}/pikku-fetch-http-request.js +1 -1
- package/dist/events/mcp/index.d.ts +2 -0
- package/dist/events/mcp/index.js +2 -0
- package/dist/events/mcp/mcp-runner.d.ts +30 -0
- package/dist/events/mcp/mcp-runner.js +192 -0
- package/dist/events/mcp/mcp.types.d.ts +117 -0
- package/dist/events/queue/index.d.ts +6 -0
- package/dist/events/queue/index.js +6 -0
- package/dist/events/queue/queue-runner.d.ts +24 -0
- package/dist/events/queue/queue-runner.js +83 -0
- package/dist/events/queue/queue.types.d.ts +154 -0
- package/dist/events/queue/register-queue-helper.d.ts +17 -0
- package/dist/events/queue/register-queue-helper.js +34 -0
- package/dist/events/queue/validate-worker-config.d.ts +41 -0
- package/dist/events/queue/validate-worker-config.js +50 -0
- package/dist/events/rpc/index.d.ts +2 -0
- package/dist/events/rpc/rpc-runner.d.ts +28 -0
- package/dist/{rpc → events/rpc}/rpc-runner.js +2 -2
- package/dist/events/scheduler/index.d.ts +3 -0
- package/dist/events/scheduler/index.js +3 -0
- package/dist/{scheduler → events/scheduler}/log-schedulers.d.ts +1 -1
- package/dist/{scheduler → events/scheduler}/log-schedulers.js +1 -1
- package/dist/{scheduler → events/scheduler}/scheduler-runner.d.ts +4 -3
- package/dist/{scheduler → events/scheduler}/scheduler-runner.js +7 -4
- package/dist/{scheduler → events/scheduler}/scheduler.types.d.ts +3 -4
- package/dist/function/function-runner.js +8 -0
- package/dist/function/functions.types.d.ts +3 -2
- package/dist/handle-error.d.ts +2 -2
- package/dist/handle-error.js +1 -1
- package/dist/index.d.ts +10 -6
- package/dist/index.js +10 -6
- package/dist/middleware-runner.d.ts +4 -4
- package/dist/middleware-runner.js +3 -1
- package/dist/pikku-state.d.ts +18 -4
- package/dist/pikku-state.js +12 -0
- package/dist/services/user-session-service.d.ts +1 -1
- package/dist/types/core.types.d.ts +17 -5
- package/dist/types/core.types.js +2 -0
- package/lcov.info +3191 -3123
- package/package.json +8 -7
- package/src/errors/error-handler.ts +2 -1
- package/src/errors/errors.ts +2 -0
- package/src/{channel → events/channel}/channel-handler.ts +3 -3
- package/src/{channel → events/channel}/channel-runner.ts +5 -5
- package/src/{channel → events/channel}/channel-store.ts +1 -1
- package/src/{channel → events/channel}/channel.types.ts +3 -3
- package/src/{channel → events/channel}/local/local-channel-runner.test.ts +1 -1
- package/src/{channel → events/channel}/local/local-channel-runner.ts +7 -7
- package/src/{channel → events/channel}/local/local-eventhub-service.test.ts +1 -1
- package/src/{channel → events/channel}/log-channels.ts +2 -2
- package/src/{channel → events/channel}/serverless/serverless-channel-runner.ts +8 -8
- package/src/{http → events/http}/http-runner.test.ts +4 -4
- package/src/{http → events/http}/http-runner.ts +9 -9
- package/src/{http → events/http}/http.types.ts +3 -3
- package/src/{http → events/http}/index.ts +0 -1
- package/src/{http → events/http}/log-http-routes.ts +2 -2
- package/src/{http → events/http}/pikku-fetch-http-request.ts +1 -1
- package/src/events/mcp/index.ts +2 -0
- package/src/events/mcp/mcp-runner.ts +321 -0
- package/src/events/mcp/mcp.types.ts +150 -0
- package/src/events/queue/index.ts +18 -0
- package/src/events/queue/queue-runner.ts +125 -0
- package/src/events/queue/queue.types.ts +176 -0
- package/src/events/queue/register-queue-helper.ts +62 -0
- package/src/events/queue/validate-worker-config.ts +113 -0
- package/src/events/rpc/index.ts +2 -0
- package/src/{rpc → events/rpc}/rpc-runner.ts +3 -3
- package/src/events/scheduler/index.ts +9 -0
- package/src/{scheduler → events/scheduler}/log-schedulers.ts +2 -2
- package/src/{scheduler → events/scheduler}/scheduler-runner.ts +11 -10
- package/src/{scheduler → events/scheduler}/scheduler.types.ts +2 -4
- package/src/function/function-runner.ts +19 -1
- package/src/function/functions.types.ts +3 -1
- package/src/handle-error.ts +2 -2
- package/src/index.ts +23 -6
- package/src/middleware-runner.ts +14 -7
- package/src/pikku-state.ts +40 -4
- package/src/services/user-session-service.ts +1 -1
- package/src/types/core.types.ts +24 -4
- package/tsconfig.json +3 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/rpc/index.d.ts +0 -2
- package/dist/rpc/rpc-runner.d.ts +0 -27
- package/dist/scheduler/index.d.ts +0 -3
- package/dist/scheduler/index.js +0 -3
- package/src/http/incomingmessage-to-request-convertor.ts +0 -0
- package/src/rpc/index.ts +0 -2
- package/src/scheduler/index.ts +0 -5
- /package/dist/{channel → events/channel}/channel-store.js +0 -0
- /package/dist/{channel → events/channel}/channel.types.js +0 -0
- /package/dist/{channel → events/channel}/eventhub-service.d.ts +0 -0
- /package/dist/{channel → events/channel}/eventhub-service.js +0 -0
- /package/dist/{channel → events/channel}/eventhub-store.d.ts +0 -0
- /package/dist/{channel → events/channel}/eventhub-store.js +0 -0
- /package/dist/{channel → events/channel}/index.d.ts +0 -0
- /package/dist/{channel → events/channel}/index.js +0 -0
- /package/dist/{channel → events/channel}/local/index.d.ts +0 -0
- /package/dist/{channel → events/channel}/local/index.js +0 -0
- /package/dist/{channel → events/channel}/local/local-channel-handler.d.ts +0 -0
- /package/dist/{channel → events/channel}/local/local-channel-handler.js +0 -0
- /package/dist/{channel → events/channel}/local/local-channel-runner.d.ts +0 -0
- /package/dist/{channel → events/channel}/local/local-eventhub-service.d.ts +0 -0
- /package/dist/{channel → events/channel}/local/local-eventhub-service.js +0 -0
- /package/dist/{channel → events/channel}/pikku-abstract-channel-handler.d.ts +0 -0
- /package/dist/{channel → events/channel}/pikku-abstract-channel-handler.js +0 -0
- /package/dist/{channel → events/channel}/serverless/index.d.ts +0 -0
- /package/dist/{channel → events/channel}/serverless/index.js +0 -0
- /package/dist/{channel → events/channel}/serverless/serverless-channel-runner.d.ts +0 -0
- /package/dist/{http → events/http}/http.types.js +0 -0
- /package/dist/{http → events/http}/pikku-fetch-http-request.d.ts +0 -0
- /package/dist/{http → events/http}/pikku-fetch-http-response.d.ts +0 -0
- /package/dist/{http → events/http}/pikku-fetch-http-response.js +0 -0
- /package/dist/{http/incomingmessage-to-request-convertor.d.ts → events/mcp/mcp.types.js} +0 -0
- /package/dist/{http/incomingmessage-to-request-convertor.js → events/queue/queue.types.js} +0 -0
- /package/dist/{rpc → events/rpc}/index.js +0 -0
- /package/dist/{rpc → events/rpc}/rpc-types.d.ts +0 -0
- /package/dist/{rpc → events/rpc}/rpc-types.js +0 -0
- /package/dist/{scheduler → events/scheduler}/scheduler.types.js +0 -0
- /package/src/{channel → events/channel}/eventhub-service.ts +0 -0
- /package/src/{channel → events/channel}/eventhub-store.ts +0 -0
- /package/src/{channel → events/channel}/index.ts +0 -0
- /package/src/{channel → events/channel}/local/index.ts +0 -0
- /package/src/{channel → events/channel}/local/local-channel-handler.ts +0 -0
- /package/src/{channel → events/channel}/local/local-eventhub-service.ts +0 -0
- /package/src/{channel → events/channel}/pikku-abstract-channel-handler.test.ts +0 -0
- /package/src/{channel → events/channel}/pikku-abstract-channel-handler.ts +0 -0
- /package/src/{channel → events/channel}/serverless/index.ts +0 -0
- /package/src/{http → events/http}/pikku-fetch-http-request.test.ts +0 -0
- /package/src/{http → events/http}/pikku-fetch-http-response.test.ts +0 -0
- /package/src/{http → events/http}/pikku-fetch-http-response.ts +0 -0
- /package/src/{rpc → events/rpc}/rpc-types.ts +0 -0
|
@@ -3,13 +3,13 @@ import type {
|
|
|
3
3
|
CoreSingletonServices,
|
|
4
4
|
CoreUserSession,
|
|
5
5
|
CreateSessionServices,
|
|
6
|
-
} from '
|
|
6
|
+
} from '../../types/core.types.js'
|
|
7
7
|
import type { CoreScheduledTask } from './scheduler.types.js'
|
|
8
|
-
import type { CoreAPIFunctionSessionless } from '
|
|
9
|
-
import { getErrorResponse } from '
|
|
10
|
-
import { closeSessionServices } from '
|
|
11
|
-
import { pikkuState } from '
|
|
12
|
-
import { addFunction, runPikkuFunc } from '
|
|
8
|
+
import type { CoreAPIFunctionSessionless } from '../../function/functions.types.js'
|
|
9
|
+
import { getErrorResponse } from '../../errors/error-handler.js'
|
|
10
|
+
import { closeSessionServices } from '../../utils.js'
|
|
11
|
+
import { pikkuState } from '../../pikku-state.js'
|
|
12
|
+
import { addFunction, runPikkuFunc } from '../../function/function-runner.js'
|
|
13
13
|
import { rpcService } from '../rpc/rpc-runner.js'
|
|
14
14
|
|
|
15
15
|
export type RunScheduledTasksParams = {
|
|
@@ -50,10 +50,7 @@ class ScheduledTaskNotFoundError extends Error {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export async function runScheduledTask
|
|
54
|
-
SingletonServices extends CoreSingletonServices = CoreSingletonServices,
|
|
55
|
-
UserSession extends CoreUserSession = CoreUserSession,
|
|
56
|
-
>({
|
|
53
|
+
export async function runScheduledTask({
|
|
57
54
|
name,
|
|
58
55
|
session,
|
|
59
56
|
singletonServices,
|
|
@@ -108,3 +105,7 @@ export async function runScheduledTask<
|
|
|
108
105
|
}
|
|
109
106
|
}
|
|
110
107
|
}
|
|
108
|
+
|
|
109
|
+
export const getScheduledTasks = () => {
|
|
110
|
+
return pikkuState('scheduler', 'tasks')
|
|
111
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { APIDocs, CoreUserSession } from '
|
|
2
|
-
import { CoreAPIFunctionSessionless } from '
|
|
1
|
+
import { APIDocs, CoreUserSession } from '../../types/core.types.js'
|
|
2
|
+
import { CoreAPIFunctionSessionless } from '../../function/functions.types.js'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Represents metadata for scheduled tasks, including title, schedule, and documentation.
|
|
@@ -22,12 +22,10 @@ export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> =
|
|
|
22
22
|
*/
|
|
23
23
|
export type CoreScheduledTask<
|
|
24
24
|
APIFunction = CoreAPIFunctionSessionless<void, void>,
|
|
25
|
-
UserSession extends CoreUserSession = CoreUserSession,
|
|
26
25
|
> = {
|
|
27
26
|
name: string
|
|
28
27
|
schedule: string
|
|
29
28
|
func: APIFunction
|
|
30
29
|
docs?: APIDocs
|
|
31
|
-
session?: UserSession
|
|
32
30
|
tags?: string[]
|
|
33
31
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { ForbiddenError } from '../errors/errors.js'
|
|
2
|
+
import { runMiddleware } from '../middleware-runner.js'
|
|
2
3
|
import { verifyPermissions } from '../permissions.js'
|
|
3
4
|
import { pikkuState } from '../pikku-state.js'
|
|
4
5
|
import { coerceTopLevelDataFromSchema, validateSchema } from '../schema.js'
|
|
5
6
|
import { Logger } from '../services/logger.js'
|
|
6
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
CoreServices,
|
|
9
|
+
CoreUserSession,
|
|
10
|
+
PikkuFunctionMiddleware,
|
|
11
|
+
} from '../types/core.types.js'
|
|
7
12
|
import {
|
|
8
13
|
CorePermissionGroup,
|
|
9
14
|
CorePikkuFunctionConfig,
|
|
@@ -145,5 +150,18 @@ export const runPikkuFunc = async <In = any, Out = any>(
|
|
|
145
150
|
throw new ForbiddenError('Permission denied')
|
|
146
151
|
}
|
|
147
152
|
|
|
153
|
+
if (funcConfig.middleware) {
|
|
154
|
+
return (await runMiddleware<PikkuFunctionMiddleware>(
|
|
155
|
+
allServices,
|
|
156
|
+
{
|
|
157
|
+
http: allServices.http,
|
|
158
|
+
mcp: allServices.mcp,
|
|
159
|
+
rpc: allServices.rpc,
|
|
160
|
+
},
|
|
161
|
+
funcConfig.middleware,
|
|
162
|
+
async () => await funcConfig.func(allServices, data, session!)
|
|
163
|
+
)) as Out
|
|
164
|
+
}
|
|
165
|
+
|
|
148
166
|
return (await funcConfig.func(allServices, data, session!)) as Out
|
|
149
167
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { PikkuChannel } from '../channel/channel.types.js'
|
|
1
|
+
import { PikkuChannel } from '../events/channel/channel.types.js'
|
|
2
2
|
import type {
|
|
3
3
|
CoreServices,
|
|
4
4
|
CoreSingletonServices,
|
|
5
5
|
CoreUserSession,
|
|
6
|
+
PikkuFunctionMiddleware,
|
|
6
7
|
} from '../types/core.types.js'
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -85,4 +86,5 @@ export type CorePikkuFunctionConfig<
|
|
|
85
86
|
func: APIFunction
|
|
86
87
|
auth?: boolean
|
|
87
88
|
permissions?: CorePermissionGroup<APIPermission>
|
|
89
|
+
middleware?: PikkuFunctionMiddleware[]
|
|
88
90
|
}
|
package/src/handle-error.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getErrorResponse } from './errors/error-handler.js'
|
|
2
2
|
import { NotFoundError } from './errors/errors.js'
|
|
3
3
|
import { Logger } from './services/logger.js'
|
|
4
|
-
import { PikkuHTTP } from './http/http.types.js'
|
|
4
|
+
import { PikkuHTTP } from './events/http/http.types.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Handle errors that occur during route processing
|
|
@@ -14,7 +14,7 @@ import { PikkuHTTP } from './http/http.types.js'
|
|
|
14
14
|
* @param {boolean} respondWith404 - Whether to respond with 404 for NotFoundError
|
|
15
15
|
* @param {boolean} bubbleError - Whether to throw the error after handling
|
|
16
16
|
*/
|
|
17
|
-
export const
|
|
17
|
+
export const handleHTTPError = (
|
|
18
18
|
e: any,
|
|
19
19
|
http: PikkuHTTP | undefined,
|
|
20
20
|
trackerId: string | undefined,
|
package/src/index.ts
CHANGED
|
@@ -6,15 +6,32 @@ export * from './function/index.js'
|
|
|
6
6
|
export * from './pikku-request.js'
|
|
7
7
|
export * from './pikku-response.js'
|
|
8
8
|
export * from './services/index.js'
|
|
9
|
-
export * from './http/index.js'
|
|
10
|
-
export * from './channel/index.js'
|
|
11
|
-
export * from './scheduler/index.js'
|
|
9
|
+
export * from './events/http/index.js'
|
|
10
|
+
export * from './events/channel/index.js'
|
|
11
|
+
export * from './events/scheduler/index.js'
|
|
12
|
+
export * from './events/rpc/index.js'
|
|
13
|
+
export * from './events/queue/index.js'
|
|
14
|
+
export * from './events/mcp/index.js'
|
|
12
15
|
export * from './errors/index.js'
|
|
13
16
|
export * from './middleware/index.js'
|
|
14
17
|
export * from './time-utils.js'
|
|
15
18
|
export * from './utils.js'
|
|
16
19
|
export { pikkuState } from './pikku-state.js'
|
|
17
20
|
export { runMiddleware } from './middleware-runner.js'
|
|
18
|
-
export { addHTTPRoute, addMiddleware } from './http/http-runner.js'
|
|
19
|
-
export { addChannel } from './channel/channel-runner.js'
|
|
20
|
-
export { addScheduledTask } from './scheduler/scheduler-runner.js'
|
|
21
|
+
export { addHTTPRoute, addMiddleware } from './events/http/http-runner.js'
|
|
22
|
+
export { addChannel } from './events/channel/channel-runner.js'
|
|
23
|
+
export { addScheduledTask } from './events/scheduler/scheduler-runner.js'
|
|
24
|
+
export {
|
|
25
|
+
addMCPResource,
|
|
26
|
+
addMCPTool,
|
|
27
|
+
addMCPPrompt,
|
|
28
|
+
runMCPResource,
|
|
29
|
+
runMCPTool,
|
|
30
|
+
runMCPPrompt,
|
|
31
|
+
getMCPTools,
|
|
32
|
+
getMCPResources,
|
|
33
|
+
getMCPPrompts,
|
|
34
|
+
getMCPResourcesMeta,
|
|
35
|
+
getMCPToolsMeta,
|
|
36
|
+
getMCPPromptsMeta,
|
|
37
|
+
} from './events/mcp/mcp-runner.js'
|
package/src/middleware-runner.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { UserSessionService } from './services/user-session-service.js'
|
|
2
2
|
import {
|
|
3
3
|
CoreSingletonServices,
|
|
4
|
+
PikkuFunctionMiddleware,
|
|
4
5
|
PikkuInteraction,
|
|
5
6
|
PikkuMiddleware,
|
|
6
7
|
} from './types/core.types.js'
|
|
@@ -22,22 +23,28 @@ import {
|
|
|
22
23
|
* async () => { return await runMain(); }
|
|
23
24
|
* );
|
|
24
25
|
*/
|
|
25
|
-
export const runMiddleware = async
|
|
26
|
+
export const runMiddleware = async <
|
|
27
|
+
Middleware extends
|
|
28
|
+
| PikkuMiddleware
|
|
29
|
+
| PikkuFunctionMiddleware = PikkuMiddleware,
|
|
30
|
+
>(
|
|
26
31
|
services: CoreSingletonServices & {
|
|
27
|
-
userSession
|
|
32
|
+
userSession?: UserSessionService<any>
|
|
28
33
|
},
|
|
29
34
|
interaction: PikkuInteraction,
|
|
30
|
-
middlewares:
|
|
31
|
-
main?: () => Promise<
|
|
32
|
-
): Promise<
|
|
35
|
+
middlewares: Middleware[],
|
|
36
|
+
main?: () => Promise<unknown>
|
|
37
|
+
): Promise<unknown> => {
|
|
38
|
+
let result: any
|
|
33
39
|
const dispatch = async (index: number): Promise<any> => {
|
|
34
40
|
if (middlewares && index < middlewares.length) {
|
|
35
|
-
return await middlewares[index]!(services, interaction, () =>
|
|
41
|
+
return await middlewares[index]!(services as any, interaction, () =>
|
|
36
42
|
dispatch(index + 1)
|
|
37
43
|
)
|
|
38
44
|
} else if (main) {
|
|
39
|
-
await main()
|
|
45
|
+
result = await main()
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
48
|
await dispatch(0)
|
|
49
|
+
return result
|
|
43
50
|
}
|
package/src/pikku-state.ts
CHANGED
|
@@ -1,17 +1,29 @@
|
|
|
1
|
-
import { ChannelsMeta, CoreAPIChannel } from './channel/channel.types.js'
|
|
1
|
+
import { ChannelsMeta, CoreAPIChannel } from './events/channel/channel.types.js'
|
|
2
2
|
import {
|
|
3
3
|
CoreHTTPFunctionRoute,
|
|
4
4
|
HTTPMethod,
|
|
5
5
|
HTTPRoutesMeta,
|
|
6
|
-
} from './http/http.types.js'
|
|
6
|
+
} from './events/http/http.types.js'
|
|
7
7
|
import { FunctionsMeta, PikkuMiddleware } from './types/core.types.js'
|
|
8
8
|
import {
|
|
9
9
|
CoreScheduledTask,
|
|
10
10
|
ScheduledTasksMeta,
|
|
11
|
-
} from './scheduler/scheduler.types.js'
|
|
11
|
+
} from './events/scheduler/scheduler.types.js'
|
|
12
12
|
import { ErrorDetails, PikkuError } from './errors/error-handler.js'
|
|
13
13
|
import { CorePikkuFunctionConfig } from './function/functions.types.js'
|
|
14
|
-
import { RPCMeta } from './rpc/rpc-types.js'
|
|
14
|
+
import { RPCMeta } from './events/rpc/rpc-types.js'
|
|
15
|
+
import {
|
|
16
|
+
queueWorkersMeta,
|
|
17
|
+
CoreQueueWorker,
|
|
18
|
+
} from './events/queue/queue.types.js'
|
|
19
|
+
import {
|
|
20
|
+
CoreMCPResource,
|
|
21
|
+
CoreMCPTool,
|
|
22
|
+
CoreMCPPrompt,
|
|
23
|
+
MCPResourceMeta,
|
|
24
|
+
MCPToolMeta,
|
|
25
|
+
MCPPromptMeta,
|
|
26
|
+
} from './events/mcp/mcp.types.js'
|
|
15
27
|
|
|
16
28
|
interface PikkuState {
|
|
17
29
|
function: {
|
|
@@ -41,6 +53,18 @@ interface PikkuState {
|
|
|
41
53
|
tasks: Map<string, CoreScheduledTask>
|
|
42
54
|
meta: ScheduledTasksMeta
|
|
43
55
|
}
|
|
56
|
+
queue: {
|
|
57
|
+
registrations: Map<string, CoreQueueWorker>
|
|
58
|
+
meta: queueWorkersMeta
|
|
59
|
+
}
|
|
60
|
+
mcp: {
|
|
61
|
+
resources: Map<string, CoreMCPResource>
|
|
62
|
+
resourcesMeta: MCPResourceMeta
|
|
63
|
+
tools: Map<string, CoreMCPTool>
|
|
64
|
+
toolsMeta: MCPToolMeta
|
|
65
|
+
prompts: Map<string, CoreMCPPrompt>
|
|
66
|
+
promptsMeta: MCPPromptMeta
|
|
67
|
+
}
|
|
44
68
|
misc: {
|
|
45
69
|
errors: Map<PikkuError, ErrorDetails>
|
|
46
70
|
schemas: Map<string, any>
|
|
@@ -70,6 +94,18 @@ export const resetPikkuState = () => {
|
|
|
70
94
|
tasks: new Map(),
|
|
71
95
|
meta: [] as unknown as ScheduledTasksMeta,
|
|
72
96
|
},
|
|
97
|
+
queue: {
|
|
98
|
+
registrations: new Map(),
|
|
99
|
+
meta: {},
|
|
100
|
+
},
|
|
101
|
+
mcp: {
|
|
102
|
+
resources: new Map(),
|
|
103
|
+
resourcesMeta: {} as MCPResourceMeta,
|
|
104
|
+
tools: new Map(),
|
|
105
|
+
toolsMeta: {} as MCPToolMeta,
|
|
106
|
+
prompts: new Map(),
|
|
107
|
+
promptsMeta: {} as MCPPromptMeta,
|
|
108
|
+
},
|
|
73
109
|
misc: {
|
|
74
110
|
errors: globalThis.pikkuState?.misc?.errors || new Map(),
|
|
75
111
|
schemas: globalThis.pikkuState?.misc?.schema || new Map(),
|
package/src/types/core.types.ts
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import type { Logger, LogLevel } from '../services/logger.js'
|
|
2
2
|
import { VariablesService } from '../services/variables-service.js'
|
|
3
|
-
import { EventHubService } from '../channel/eventhub-service.js'
|
|
3
|
+
import { EventHubService } from '../events/channel/eventhub-service.js'
|
|
4
4
|
import { SchemaService } from '../services/schema-service.js'
|
|
5
|
-
import { PikkuHTTP } from '../http/http.types.js'
|
|
5
|
+
import { PikkuHTTP } from '../events/http/http.types.js'
|
|
6
6
|
import { UserSessionService } from '../services/user-session-service.js'
|
|
7
7
|
import { JWTService } from '../services/jwt-service.js'
|
|
8
8
|
import { SecretService } from '../services/secret-service.js'
|
|
9
|
-
import { PikkuChannel } from '../channel/channel.types.js'
|
|
10
|
-
import { PikkuRPC } from '../rpc/rpc-types.js'
|
|
9
|
+
import { PikkuChannel } from '../events/channel/channel.types.js'
|
|
10
|
+
import { PikkuRPC } from '../events/rpc/rpc-types.js'
|
|
11
|
+
import { PikkuMCP } from '../events/mcp/mcp.types.js'
|
|
11
12
|
|
|
12
13
|
export enum PikkuEventTypes {
|
|
13
14
|
http = 'http',
|
|
14
15
|
scheduled = 'scheduled',
|
|
15
16
|
channel = 'channel',
|
|
16
17
|
rpc = 'rpc',
|
|
18
|
+
queue = 'queue',
|
|
19
|
+
mcp = 'mcp',
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
export interface FunctionServicesMeta {
|
|
@@ -109,8 +112,24 @@ export interface CoreSingletonServices<Config extends CoreConfig = CoreConfig> {
|
|
|
109
112
|
*/
|
|
110
113
|
export interface PikkuInteraction {
|
|
111
114
|
http?: PikkuHTTP
|
|
115
|
+
mcp?: PikkuMCP
|
|
116
|
+
rpc?: PikkuRPC
|
|
112
117
|
}
|
|
113
118
|
|
|
119
|
+
/**
|
|
120
|
+
* A function that can wrap an interaction and be called before or after
|
|
121
|
+
*/
|
|
122
|
+
export type PikkuFunctionMiddleware<
|
|
123
|
+
SingletonServices extends CoreSingletonServices = CoreSingletonServices,
|
|
124
|
+
UserSession extends CoreUserSession = CoreUserSession,
|
|
125
|
+
> = (
|
|
126
|
+
services: SingletonServices & {
|
|
127
|
+
userSession?: UserSessionService<UserSession>
|
|
128
|
+
},
|
|
129
|
+
interactions: PikkuInteraction,
|
|
130
|
+
next: () => Promise<void>
|
|
131
|
+
) => Promise<void>
|
|
132
|
+
|
|
114
133
|
/**
|
|
115
134
|
* A function that can wrap an interaction and be called before or after
|
|
116
135
|
*/
|
|
@@ -134,6 +153,7 @@ export type CoreServices<
|
|
|
134
153
|
CoreServices extends Record<string, unknown> = {},
|
|
135
154
|
> = SingletonServices &
|
|
136
155
|
PikkuInteraction & {
|
|
156
|
+
mcp?: PikkuMCP
|
|
137
157
|
rpc?: PikkuRPC
|
|
138
158
|
userSession?: UserSessionService<UserSession>
|
|
139
159
|
channel?: PikkuChannel<unknown, unknown>
|
package/tsconfig.json
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"rootDir": "./src",
|
|
5
5
|
"composite": true,
|
|
6
|
-
"module": "
|
|
6
|
+
"module": "Node18",
|
|
7
7
|
"outDir": "dist",
|
|
8
8
|
"target": "esnext",
|
|
9
|
-
"moduleResolution": "node16"
|
|
9
|
+
"moduleResolution": "node16",
|
|
10
|
+
"tsBuildInfoFile": null
|
|
10
11
|
},
|
|
11
12
|
"exclude": ["**/*.test.ts", "node_modules", "dist"],
|
|
12
13
|
"references": []
|