@pikku/core 0.10.2 → 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.
- package/CHANGELOG.md +19 -0
- package/dist/errors/errors.d.ts +1 -1
- package/dist/errors/errors.js +3 -3
- package/dist/function/function-runner.d.ts +6 -7
- package/dist/function/function-runner.js +35 -16
- package/dist/function/functions.types.d.ts +23 -30
- package/dist/function/functions.types.js +9 -6
- package/dist/handle-error.d.ts +1 -1
- package/dist/handle-error.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/middleware/auth-apikey.d.ts +1 -0
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +1 -0
- package/dist/middleware/auth-bearer.js +3 -3
- package/dist/middleware/auth-cookie.d.ts +1 -0
- package/dist/middleware/auth-cookie.js +5 -5
- package/dist/middleware/timeout.d.ts +1 -0
- package/dist/middleware/timeout.js +3 -2
- package/dist/middleware-runner.d.ts +3 -6
- package/dist/middleware-runner.js +11 -11
- package/dist/permissions.d.ts +6 -6
- package/dist/permissions.js +15 -15
- package/dist/pikku-state.d.ts +7 -2
- package/dist/pikku-state.js +4 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/scheduler-service.d.ts +63 -0
- package/dist/services/scheduler-service.js +6 -0
- package/dist/services/user-session-service.d.ts +7 -3
- package/dist/services/user-session-service.js +8 -1
- package/dist/time-utils.d.ts +14 -0
- package/dist/time-utils.js +62 -0
- package/dist/types/core.types.d.ts +48 -35
- package/dist/types/core.types.js +3 -13
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +3 -3
- package/dist/wirings/channel/channel-common.js +2 -3
- package/dist/wirings/channel/channel-handler.d.ts +3 -2
- package/dist/wirings/channel/channel-handler.js +6 -9
- package/dist/wirings/channel/channel-runner.d.ts +2 -2
- package/dist/wirings/channel/channel.types.d.ts +10 -5
- package/dist/wirings/channel/local/local-channel-runner.d.ts +1 -1
- package/dist/wirings/channel/local/local-channel-runner.js +19 -26
- package/dist/wirings/channel/serverless/serverless-channel-runner.d.ts +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +41 -46
- package/dist/wirings/cli/channel/cli-channel-runner.js +1 -1
- package/dist/wirings/cli/cli-runner.d.ts +5 -5
- package/dist/wirings/cli/cli-runner.js +11 -29
- package/dist/wirings/cli/cli.types.d.ts +15 -11
- package/dist/wirings/http/http-runner.d.ts +6 -6
- package/dist/wirings/http/http-runner.js +25 -39
- package/dist/wirings/http/http.types.d.ts +5 -10
- package/dist/wirings/mcp/mcp-runner.d.ts +2 -2
- package/dist/wirings/mcp/mcp-runner.js +12 -19
- package/dist/wirings/mcp/mcp.types.d.ts +6 -0
- package/dist/wirings/queue/queue-runner.d.ts +3 -3
- package/dist/wirings/queue/queue-runner.js +7 -14
- package/dist/wirings/queue/queue.types.d.ts +4 -13
- package/dist/wirings/rpc/index.d.ts +1 -1
- package/dist/wirings/rpc/index.js +1 -1
- package/dist/wirings/rpc/rpc-runner.d.ts +13 -7
- package/dist/wirings/rpc/rpc-runner.js +50 -26
- package/dist/wirings/rpc/rpc-types.d.ts +1 -0
- package/dist/wirings/scheduler/scheduler-runner.d.ts +3 -3
- package/dist/wirings/scheduler/scheduler-runner.js +13 -24
- package/dist/wirings/scheduler/scheduler.types.d.ts +3 -8
- package/dist/wirings/workflow/index.d.ts +15 -0
- package/dist/wirings/workflow/index.js +14 -0
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +160 -0
- package/dist/wirings/workflow/pikku-workflow-service.js +430 -0
- package/dist/wirings/workflow/workflow-runner.d.ts +34 -0
- package/dist/wirings/workflow/workflow-runner.js +65 -0
- package/dist/wirings/workflow/workflow.types.d.ts +332 -0
- package/dist/wirings/workflow/workflow.types.js +1 -0
- package/package.json +3 -4
- package/src/errors/errors.ts +3 -3
- package/src/factory-functions.test.ts +9 -36
- package/src/function/function-runner.test.ts +57 -68
- package/src/function/function-runner.ts +51 -28
- package/src/function/function-runner.ts.bak +188 -0
- package/src/function/functions.types.ts +69 -51
- package/src/handle-error.ts +1 -1
- package/src/index.ts +2 -0
- package/src/middleware/auth-apikey.test.ts +360 -0
- package/src/middleware/auth-apikey.ts +3 -7
- package/src/middleware/auth-bearer.test.ts +447 -0
- package/src/middleware/auth-bearer.ts +27 -33
- package/src/middleware/auth-cookie.test.ts +525 -0
- package/src/middleware/auth-cookie.ts +6 -6
- package/src/middleware/timeout.ts +4 -2
- package/src/middleware-runner.test.ts +58 -127
- package/src/middleware-runner.ts +13 -15
- package/src/permissions.test.ts +41 -45
- package/src/permissions.ts +21 -20
- package/src/pikku-state.ts +14 -2
- package/src/services/index.ts +1 -0
- package/src/services/scheduler-service.ts +76 -0
- package/src/services/user-session-service.ts +14 -4
- package/src/time-utils.ts +75 -0
- package/src/types/core.types.ts +92 -51
- package/src/utils.ts +4 -4
- package/src/wirings/channel/channel-common.ts +4 -7
- package/src/wirings/channel/channel-handler.ts +16 -22
- package/src/wirings/channel/channel-runner.ts +2 -2
- package/src/wirings/channel/channel.types.ts +14 -11
- package/src/wirings/channel/local/local-channel-runner.test.ts +5 -3
- package/src/wirings/channel/local/local-channel-runner.ts +23 -38
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +51 -77
- package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +7 -7
- package/src/wirings/cli/cli-runner.ts +25 -63
- package/src/wirings/cli/cli.types.ts +22 -16
- package/src/wirings/http/http-runner.test.ts +8 -8
- package/src/wirings/http/http-runner.ts +29 -56
- package/src/wirings/http/http.types.ts +5 -14
- package/src/wirings/mcp/mcp-runner.ts +23 -48
- package/src/wirings/mcp/mcp.types.ts +6 -0
- package/src/wirings/queue/queue-runner.test.ts +641 -0
- package/src/wirings/queue/queue-runner.ts +10 -24
- package/src/wirings/queue/queue.types.ts +5 -15
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +71 -32
- package/src/wirings/rpc/rpc-types.ts +1 -0
- package/src/wirings/scheduler/scheduler-runner.test.ts +627 -0
- package/src/wirings/scheduler/scheduler-runner.ts +24 -50
- package/src/wirings/scheduler/scheduler.types.ts +3 -9
- package/src/wirings/workflow/index.ts +43 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +746 -0
- package/src/wirings/workflow/workflow-runner.ts +72 -0
- package/src/wirings/workflow/workflow.types.ts +422 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/services/file-channel-store.d.ts +0 -19
- package/dist/services/file-channel-store.js +0 -69
- package/dist/services/file-eventhub-store.d.ts +0 -17
- package/dist/services/file-eventhub-store.js +0 -71
- package/src/services/file-channel-store.ts +0 -86
- package/src/services/file-eventhub-store.ts +0 -90
|
@@ -79,16 +79,16 @@ export declare const addHTTPPermission: <PikkuPermission extends CorePikkuPermis
|
|
|
79
79
|
*/
|
|
80
80
|
export declare const wireHTTP: <In, Out, Route extends string, PikkuFunction extends CorePikkuFunction<In, Out> = CorePikkuFunction<In, Out>, PikkuFunctionSessionless extends CorePikkuFunctionSessionless<In, Out> = CorePikkuFunctionSessionless<In, Out>, PikkuPermissionGroup extends CorePikkuPermission<In> = CorePikkuPermission<In>, PikkuMiddleware extends CorePikkuMiddleware = CorePikkuMiddleware>(httpWiring: CoreHTTPFunctionWiring<In, Out, Route, PikkuFunction, PikkuFunctionSessionless, PikkuPermissionGroup, PikkuMiddleware>) => void;
|
|
81
81
|
/**
|
|
82
|
-
* Combines the request and response objects into a single HTTP
|
|
82
|
+
* Combines the request and response objects into a single HTTP wire object.
|
|
83
83
|
*
|
|
84
84
|
* This utility function creates an object that holds both the HTTP request and response,
|
|
85
85
|
* which simplifies passing these around through middleware and route execution.
|
|
86
86
|
*
|
|
87
87
|
* @param {PikkuHTTPRequest | undefined} request - The HTTP request object.
|
|
88
88
|
* @param {PikkuHTTPResponse | undefined} response - The HTTP response object.
|
|
89
|
-
* @returns {PikkuHTTP | undefined} The combined HTTP
|
|
89
|
+
* @returns {PikkuHTTP | undefined} The combined HTTP wire object or undefined if none provided.
|
|
90
90
|
*/
|
|
91
|
-
export declare const
|
|
91
|
+
export declare const createHTTPWire: (request: PikkuHTTPRequest | undefined, response: PikkuHTTPResponse | undefined) => PikkuHTTP | undefined;
|
|
92
92
|
/**
|
|
93
93
|
* Executes an HTTP route for a given Fetch API request.
|
|
94
94
|
*
|
|
@@ -123,11 +123,11 @@ export declare const pikkuFetch: <In, Out>(request: Request | PikkuHTTPRequest,
|
|
|
123
123
|
* middleware execution, error handling, and session service cleanup.
|
|
124
124
|
*
|
|
125
125
|
* This function does the following:
|
|
126
|
-
* - Wraps the incoming request and response into an HTTP
|
|
126
|
+
* - Wraps the incoming request and response into an HTTP wire object.
|
|
127
127
|
* - Determines the correct route based on HTTP method and path.
|
|
128
128
|
* - Executes middleware and the route handler.
|
|
129
129
|
* - Catches and handles errors, optionally bubbling them if configured.
|
|
130
|
-
* - Cleans up any
|
|
130
|
+
* - Cleans up any wire services created during processing.
|
|
131
131
|
*
|
|
132
132
|
* @template In Expected input data type.
|
|
133
133
|
* @template Out Expected output data type.
|
|
@@ -136,4 +136,4 @@ export declare const pikkuFetch: <In, Out>(request: Request | PikkuHTTPRequest,
|
|
|
136
136
|
* @param {RunHTTPWiringOptions & RunHTTPWiringParams} options - Options such as singleton services, session handling, and error configuration.
|
|
137
137
|
* @returns {Promise<Out | void>} The output from the route handler or void if an error occurred.
|
|
138
138
|
*/
|
|
139
|
-
export declare const fetchData: <In, Out>(request: Request | PikkuHTTPRequest, response: PikkuHTTPResponse, { singletonServices,
|
|
139
|
+
export declare const fetchData: <In, Out>(request: Request | PikkuHTTPRequest, response: PikkuHTTPResponse, { singletonServices, createWireServices, skipUserSession, respondWith404, logWarningsForStatusCodes, coerceDataFromSchema, bubbleErrors, generateRequestId, }: RunHTTPWiringOptions & RunHTTPWiringParams) => Promise<Out | void>;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { PikkuWiringTypes, } from '../../types/core.types.js';
|
|
2
1
|
import { NotFoundError } from '../../errors/errors.js';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { closeWireServices, createWeakUID, isSerializable, } from '../../utils.js';
|
|
3
|
+
import { PikkuSessionService } from '../../services/user-session-service.js';
|
|
5
4
|
import { handleHTTPError } from '../../handle-error.js';
|
|
6
5
|
import { pikkuState } from '../../pikku-state.js';
|
|
7
6
|
import { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js';
|
|
8
7
|
import { PikkuFetchHTTPRequest } from './pikku-fetch-http-request.js';
|
|
9
8
|
import { addFunction, runPikkuFunc } from '../../function/function-runner.js';
|
|
10
|
-
import { rpcService } from '../rpc/rpc-runner.js';
|
|
11
9
|
import { httpRouter } from './routers/http-router.js';
|
|
12
10
|
/**
|
|
13
11
|
* Registers HTTP middleware for a specific route pattern.
|
|
@@ -135,16 +133,16 @@ const getMatchingRoute = (requestType, requestPath) => {
|
|
|
135
133
|
}
|
|
136
134
|
};
|
|
137
135
|
/**
|
|
138
|
-
* Combines the request and response objects into a single HTTP
|
|
136
|
+
* Combines the request and response objects into a single HTTP wire object.
|
|
139
137
|
*
|
|
140
138
|
* This utility function creates an object that holds both the HTTP request and response,
|
|
141
139
|
* which simplifies passing these around through middleware and route execution.
|
|
142
140
|
*
|
|
143
141
|
* @param {PikkuHTTPRequest | undefined} request - The HTTP request object.
|
|
144
142
|
* @param {PikkuHTTPResponse | undefined} response - The HTTP response object.
|
|
145
|
-
* @returns {PikkuHTTP | undefined} The combined HTTP
|
|
143
|
+
* @returns {PikkuHTTP | undefined} The combined HTTP wire object or undefined if none provided.
|
|
146
144
|
*/
|
|
147
|
-
export const
|
|
145
|
+
export const createHTTPWire = (request, response) => {
|
|
148
146
|
let http = undefined;
|
|
149
147
|
if (request || response) {
|
|
150
148
|
http = {};
|
|
@@ -172,17 +170,17 @@ export const createHTTPInteraction = (request, response) => {
|
|
|
172
170
|
*
|
|
173
171
|
* @param {Object} services - A collection of shared services and utilities.
|
|
174
172
|
* @param {Object} matchedRoute - Contains route details, URL parameters, and optional schema.
|
|
175
|
-
* @param {PikkuHTTP | undefined} http - The HTTP
|
|
173
|
+
* @param {PikkuHTTP | undefined} http - The HTTP wire object.
|
|
176
174
|
* @param {Object} options - Options for route execution (e.g., whether to coerce query strings to arrays).
|
|
177
|
-
* @returns {Promise<any>} An object containing the route handler result and
|
|
175
|
+
* @returns {Promise<any>} An object containing the route handler result and wire services (if any).
|
|
178
176
|
* @throws Throws errors like MissingSessionError or ForbiddenError on validation failures.
|
|
179
177
|
*/
|
|
180
178
|
const executeRoute = async (services, matchedRoute, http, options) => {
|
|
181
|
-
const userSession = new
|
|
179
|
+
const userSession = new PikkuSessionService();
|
|
182
180
|
const { params, route, meta } = matchedRoute;
|
|
183
|
-
const { singletonServices,
|
|
181
|
+
const { singletonServices, createWireServices, skipUserSession, requestId } = services;
|
|
184
182
|
const requiresSession = route.auth !== false;
|
|
185
|
-
let
|
|
183
|
+
let wireServices;
|
|
186
184
|
let result;
|
|
187
185
|
// Attach URL parameters to the request object
|
|
188
186
|
http?.request?.setParams(params);
|
|
@@ -219,23 +217,11 @@ const executeRoute = async (services, matchedRoute, http, options) => {
|
|
|
219
217
|
state: 'open',
|
|
220
218
|
};
|
|
221
219
|
}
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
// Create session-specific services for handling the request
|
|
225
|
-
sessionServices = await createSessionServices({ ...singletonServices, userSession, channel }, { http }, session);
|
|
226
|
-
return rpcService.injectRPCService({
|
|
227
|
-
...singletonServices,
|
|
228
|
-
...sessionServices,
|
|
229
|
-
http,
|
|
230
|
-
userSession,
|
|
231
|
-
channel,
|
|
232
|
-
}, interaction, route.auth);
|
|
233
|
-
};
|
|
234
|
-
result = await runPikkuFunc(PikkuWiringTypes.http, `${meta.method}:${meta.route}`, meta.pikkuFuncName, {
|
|
220
|
+
const wire = { http, channel, session: userSession };
|
|
221
|
+
result = await runPikkuFunc('http', `${meta.method}:${meta.route}`, meta.pikkuFuncName, {
|
|
235
222
|
singletonServices,
|
|
236
|
-
|
|
223
|
+
createWireServices,
|
|
237
224
|
auth: route.auth !== false,
|
|
238
|
-
userSession,
|
|
239
225
|
data,
|
|
240
226
|
inheritedMiddleware: meta.middleware,
|
|
241
227
|
wireMiddleware: route.middleware,
|
|
@@ -243,7 +229,7 @@ const executeRoute = async (services, matchedRoute, http, options) => {
|
|
|
243
229
|
wirePermissions: route.permissions,
|
|
244
230
|
coerceDataFromSchema: options.coerceDataFromSchema,
|
|
245
231
|
tags: route.tags,
|
|
246
|
-
|
|
232
|
+
wire,
|
|
247
233
|
});
|
|
248
234
|
// Respond with either a binary or JSON response based on configuration
|
|
249
235
|
if (route.returnsJSON === false) {
|
|
@@ -255,7 +241,7 @@ const executeRoute = async (services, matchedRoute, http, options) => {
|
|
|
255
241
|
http?.response?.status(200);
|
|
256
242
|
// TODO: Evaluate if the response stream should be explicitly ended.
|
|
257
243
|
// http?.response?.end()
|
|
258
|
-
return
|
|
244
|
+
return wireServices ? { result, wireServices } : { result };
|
|
259
245
|
};
|
|
260
246
|
/**
|
|
261
247
|
* Executes an HTTP route for a given Fetch API request.
|
|
@@ -299,11 +285,11 @@ export const pikkuFetch = async (request, params) => {
|
|
|
299
285
|
* middleware execution, error handling, and session service cleanup.
|
|
300
286
|
*
|
|
301
287
|
* This function does the following:
|
|
302
|
-
* - Wraps the incoming request and response into an HTTP
|
|
288
|
+
* - Wraps the incoming request and response into an HTTP wire object.
|
|
303
289
|
* - Determines the correct route based on HTTP method and path.
|
|
304
290
|
* - Executes middleware and the route handler.
|
|
305
291
|
* - Catches and handles errors, optionally bubbling them if configured.
|
|
306
|
-
* - Cleans up any
|
|
292
|
+
* - Cleans up any wire services created during processing.
|
|
307
293
|
*
|
|
308
294
|
* @template In Expected input data type.
|
|
309
295
|
* @template Out Expected output data type.
|
|
@@ -312,14 +298,14 @@ export const pikkuFetch = async (request, params) => {
|
|
|
312
298
|
* @param {RunHTTPWiringOptions & RunHTTPWiringParams} options - Options such as singleton services, session handling, and error configuration.
|
|
313
299
|
* @returns {Promise<Out | void>} The output from the route handler or void if an error occurred.
|
|
314
300
|
*/
|
|
315
|
-
export const fetchData = async (request, response, { singletonServices,
|
|
301
|
+
export const fetchData = async (request, response, { singletonServices, createWireServices, skipUserSession = false, respondWith404 = true, logWarningsForStatusCodes = [], coerceDataFromSchema = true, bubbleErrors = false, generateRequestId, }) => {
|
|
316
302
|
const requestId = request.getHeader?.('x-request-id') ||
|
|
317
303
|
generateRequestId?.() ||
|
|
318
304
|
createWeakUID();
|
|
319
|
-
let
|
|
305
|
+
let wireServices;
|
|
320
306
|
let result;
|
|
321
|
-
// Combine the request and response into one
|
|
322
|
-
const http =
|
|
307
|
+
// Combine the request and response into one wire object
|
|
308
|
+
const http = createHTTPWire(request instanceof Request ? new PikkuFetchHTTPRequest(request) : request, response);
|
|
323
309
|
const apiType = http.request.method();
|
|
324
310
|
const apiRoute = http.request.path();
|
|
325
311
|
// Locate the matching route based on the HTTP method and path
|
|
@@ -336,9 +322,9 @@ export const fetchData = async (request, response, { singletonServices, createSe
|
|
|
336
322
|
}
|
|
337
323
|
// Execute the matched route along with its middleware and session management
|
|
338
324
|
;
|
|
339
|
-
({ result,
|
|
325
|
+
({ result, wireServices } = await executeRoute({
|
|
340
326
|
singletonServices,
|
|
341
|
-
|
|
327
|
+
createWireServices,
|
|
342
328
|
skipUserSession,
|
|
343
329
|
requestId,
|
|
344
330
|
}, matchedRoute, http, { coerceDataFromSchema }));
|
|
@@ -350,8 +336,8 @@ export const fetchData = async (request, response, { singletonServices, createSe
|
|
|
350
336
|
}
|
|
351
337
|
finally {
|
|
352
338
|
// Clean up any session-specific services created during processing
|
|
353
|
-
if (
|
|
354
|
-
await
|
|
339
|
+
if (wireServices) {
|
|
340
|
+
await closeWireServices(singletonServices.logger, wireServices);
|
|
355
341
|
}
|
|
356
342
|
}
|
|
357
343
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SerializeOptions } from 'cookie';
|
|
2
2
|
import type { PikkuError } from '../../errors/error-handler.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { CoreServices, CoreSingletonServices, CoreUserSession, CreateWireServices, CorePikkuMiddleware, CommonWireMeta } from '../../types/core.types.js';
|
|
4
4
|
import type { CorePikkuFunction, CorePikkuFunctionSessionless, CorePikkuPermission, CorePermissionGroup, CorePikkuFunctionConfig } from '../../function/functions.types.js';
|
|
5
5
|
type ExtractHTTPWiringParams<S extends string> = S extends `${string}:${infer Param}/${infer Rest}` ? Param | ExtractHTTPWiringParams<`/${Rest}`> : S extends `${string}:${infer Param}` ? Param : never;
|
|
6
6
|
export type AssertHTTPWiringParams<In, HTTPWiring extends string> = ExtractHTTPWiringParams<HTTPWiring> extends keyof In ? unknown : [
|
|
@@ -19,7 +19,7 @@ export type RunHTTPWiringOptions = Partial<{
|
|
|
19
19
|
}>;
|
|
20
20
|
export type RunHTTPWiringParams = {
|
|
21
21
|
singletonServices: CoreSingletonServices;
|
|
22
|
-
|
|
22
|
+
createWireServices: CreateWireServices<CoreSingletonServices, CoreServices<CoreSingletonServices>, CoreUserSession>;
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* Represents the HTTP methods supported for API HTTP wirings.
|
|
@@ -43,7 +43,7 @@ export type CoreHTTPFunction = {
|
|
|
43
43
|
}>;
|
|
44
44
|
};
|
|
45
45
|
/**
|
|
46
|
-
* Represents a http
|
|
46
|
+
* Represents a http wire within Pikku, including a request and response.
|
|
47
47
|
*/
|
|
48
48
|
export interface PikkuHTTP<In = unknown> {
|
|
49
49
|
request?: PikkuHTTPRequest<In>;
|
|
@@ -67,7 +67,7 @@ export type PikkuQuery<T = Record<string, string | undefined>> = Record<string,
|
|
|
67
67
|
* @template PikkuFunctionSessionless - The sessionless API function type, defaults to `CorePikkuFunctionSessionless`.
|
|
68
68
|
* @template PikkuPermission - The permission function type, defaults to `CorePikkuPermission`.
|
|
69
69
|
*/
|
|
70
|
-
export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction extends CorePikkuFunction<In, Out, any, any
|
|
70
|
+
export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction extends CorePikkuFunction<In, Out, any, any> = CorePikkuFunction<In, Out>, PikkuFunctionSessionless extends CorePikkuFunctionSessionless<In, Out, any, any> = CorePikkuFunctionSessionless<In, Out>, PikkuPermission extends CorePikkuPermission<In, any, any> = CorePikkuPermission<In, any, any>, PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<any>> = (CoreHTTPFunction & {
|
|
71
71
|
route: R;
|
|
72
72
|
method: HTTPMethod;
|
|
73
73
|
func: CorePikkuFunctionConfig<PikkuFunction, PikkuPermission, PikkuMiddleware>;
|
|
@@ -135,18 +135,13 @@ export type HTTPFunctionMetaInputTypes = {
|
|
|
135
135
|
/**
|
|
136
136
|
* Represents metadata for a set of HTTP wirings, including HTTP wiring details, methods, input/output types, and documentation.
|
|
137
137
|
*/
|
|
138
|
-
export type HTTPWiringMeta = {
|
|
139
|
-
pikkuFuncName: string;
|
|
138
|
+
export type HTTPWiringMeta = CommonWireMeta & {
|
|
140
139
|
route: string;
|
|
141
140
|
method: HTTPMethod;
|
|
142
141
|
params?: string[];
|
|
143
142
|
query?: string[];
|
|
144
143
|
inputTypes?: HTTPFunctionMetaInputTypes;
|
|
145
|
-
docs?: PikkuDocs;
|
|
146
|
-
tags?: string[];
|
|
147
144
|
sse?: true;
|
|
148
|
-
middleware?: MiddlewareMetadata[];
|
|
149
|
-
permissions?: PermissionMetadata[];
|
|
150
145
|
};
|
|
151
146
|
export type HTTPWiringsMeta = Record<HTTPMethod, Record<string, HTTPWiringMeta>>;
|
|
152
147
|
export type HTTPFunctionsMeta = Array<{
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type CoreServices, type CoreSingletonServices, type CoreUserSession, type
|
|
1
|
+
import { type CoreServices, type CoreSingletonServices, type CoreUserSession, type CreateWireServices } from '../../types/core.types.js';
|
|
2
2
|
import type { CoreMCPResource, CoreMCPTool, CoreMCPPrompt, JsonRpcRequest, JsonRpcResponse, JsonRpcErrorResponse, PikkuMCP } from './mcp.types.js';
|
|
3
3
|
import type { CorePikkuFunctionConfig, CorePikkuFunctionSessionless } from '../../function/functions.types.js';
|
|
4
4
|
export declare class MCPError extends Error {
|
|
@@ -8,7 +8,7 @@ export declare class MCPError extends Error {
|
|
|
8
8
|
export type RunMCPEndpointParams<Tools extends string = any> = {
|
|
9
9
|
singletonServices: CoreSingletonServices;
|
|
10
10
|
mcp?: PikkuMCP<Tools>;
|
|
11
|
-
|
|
11
|
+
createWireServices?: CreateWireServices<CoreSingletonServices, CoreServices<CoreSingletonServices>, CoreUserSession>;
|
|
12
12
|
};
|
|
13
13
|
export type JsonRpcError = {
|
|
14
14
|
code: number;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { PikkuWiringTypes, } from '../../types/core.types.js';
|
|
2
1
|
import { getErrorResponse } from '../../errors/error-handler.js';
|
|
3
|
-
import {
|
|
2
|
+
import { closeWireServices } from '../../utils.js';
|
|
4
3
|
import { pikkuState } from '../../pikku-state.js';
|
|
5
4
|
import { addFunction, runPikkuFunc } from '../../function/function-runner.js';
|
|
6
|
-
import { rpcService } from '../rpc/rpc-runner.js';
|
|
7
5
|
import { BadRequestError, NotFoundError } from '../../errors/errors.js';
|
|
6
|
+
import { PikkuSessionService } from '../../services/user-session-service.js';
|
|
8
7
|
export class MCPError extends Error {
|
|
9
8
|
error;
|
|
10
9
|
constructor(error) {
|
|
@@ -100,8 +99,8 @@ export async function runMCPPrompt(request, params, name) {
|
|
|
100
99
|
/**
|
|
101
100
|
* JSON-RPC 2.0 compatible MCP endpoint runner
|
|
102
101
|
*/
|
|
103
|
-
async function runMCPPikkuFunc(request, type, name, mcp, pikkuFuncName, { singletonServices,
|
|
104
|
-
let
|
|
102
|
+
async function runMCPPikkuFunc(request, type, name, mcp, pikkuFuncName, { singletonServices, createWireServices, mcp: mcpWire }) {
|
|
103
|
+
let wireServices;
|
|
105
104
|
try {
|
|
106
105
|
// Validate JSON-RPC request structure
|
|
107
106
|
if (request.jsonrpc !== '2.0') {
|
|
@@ -114,14 +113,9 @@ async function runMCPPikkuFunc(request, type, name, mcp, pikkuFuncName, { single
|
|
|
114
113
|
throw new NotFoundError(`MCP '${type}' PikkuFunction Mapping not found for '${name}'`);
|
|
115
114
|
}
|
|
116
115
|
singletonServices.logger.debug(`Running MCP ${type}: ${name}`);
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return rpcService.injectRPCService({
|
|
121
|
-
...singletonServices,
|
|
122
|
-
...sessionServices,
|
|
123
|
-
mcp: mcpInteraction,
|
|
124
|
-
}, interaction);
|
|
116
|
+
const wire = {
|
|
117
|
+
mcp: mcpWire,
|
|
118
|
+
session: new PikkuSessionService(),
|
|
125
119
|
};
|
|
126
120
|
// Get metadata for the MCP endpoint to access pre-resolved middleware
|
|
127
121
|
let meta;
|
|
@@ -134,17 +128,16 @@ async function runMCPPikkuFunc(request, type, name, mcp, pikkuFuncName, { single
|
|
|
134
128
|
else if (type === 'prompt') {
|
|
135
129
|
meta = pikkuState('mcp', 'promptsMeta')[name];
|
|
136
130
|
}
|
|
137
|
-
const result = await runPikkuFunc(
|
|
131
|
+
const result = await runPikkuFunc('mcp', `${type}:${name}`, pikkuFuncName, {
|
|
138
132
|
singletonServices,
|
|
139
|
-
|
|
140
|
-
userSession: undefined, // TODO
|
|
133
|
+
createWireServices,
|
|
141
134
|
data: () => request.params,
|
|
142
135
|
inheritedMiddleware: meta?.middleware,
|
|
143
136
|
wireMiddleware: mcp.middleware,
|
|
144
137
|
inheritedPermissions: meta?.permissions,
|
|
145
138
|
wirePermissions: mcp.permissions,
|
|
146
139
|
tags: mcp.tags,
|
|
147
|
-
|
|
140
|
+
wire,
|
|
148
141
|
});
|
|
149
142
|
return {
|
|
150
143
|
id: request.id,
|
|
@@ -174,8 +167,8 @@ async function runMCPPikkuFunc(request, type, name, mcp, pikkuFuncName, { single
|
|
|
174
167
|
}
|
|
175
168
|
}
|
|
176
169
|
finally {
|
|
177
|
-
if (
|
|
178
|
-
await
|
|
170
|
+
if (wireServices) {
|
|
171
|
+
await closeWireServices(singletonServices.logger, wireServices);
|
|
179
172
|
}
|
|
180
173
|
}
|
|
181
174
|
}
|
|
@@ -64,6 +64,8 @@ export type CoreMCPResource<PikkuFunctionConfig = CorePikkuFunctionConfig<CorePi
|
|
|
64
64
|
uri: string;
|
|
65
65
|
title: string;
|
|
66
66
|
description: string;
|
|
67
|
+
summary?: string;
|
|
68
|
+
errors?: string[];
|
|
67
69
|
mimeType?: string;
|
|
68
70
|
size?: number;
|
|
69
71
|
streaming?: boolean;
|
|
@@ -79,6 +81,8 @@ export type CoreMCPTool<PikkuFunctionConfig = CorePikkuFunctionConfig<CorePikkuF
|
|
|
79
81
|
name: string;
|
|
80
82
|
title?: string;
|
|
81
83
|
description: string;
|
|
84
|
+
summary?: string;
|
|
85
|
+
errors?: string[];
|
|
82
86
|
func: PikkuFunctionConfig;
|
|
83
87
|
tags?: string[];
|
|
84
88
|
streaming?: boolean;
|
|
@@ -91,6 +95,8 @@ export type CoreMCPTool<PikkuFunctionConfig = CorePikkuFunctionConfig<CorePikkuF
|
|
|
91
95
|
export type CoreMCPPrompt<PikkuFunctionConfig = CorePikkuFunctionConfig<CorePikkuFunctionSessionless<any, MCPPromptResponse>>, PikkuPermission = CorePikkuPermission<any, any>, PikkuMiddleware = CorePikkuMiddleware<any>> = {
|
|
92
96
|
name: string;
|
|
93
97
|
description: string;
|
|
98
|
+
summary?: string;
|
|
99
|
+
errors?: string[];
|
|
94
100
|
func: PikkuFunctionConfig;
|
|
95
101
|
tags?: string[];
|
|
96
102
|
middleware?: PikkuMiddleware[];
|
|
@@ -2,7 +2,7 @@ import type { CoreServices } from '../../types/core.types.js';
|
|
|
2
2
|
import type { CoreQueueWorker, QueueJob } from './queue.types.js';
|
|
3
3
|
import type { CorePikkuFunctionConfig, CorePikkuFunctionSessionless } from '../../function/functions.types.js';
|
|
4
4
|
import { PikkuError } from '../../errors/error-handler.js';
|
|
5
|
-
import {
|
|
5
|
+
import { CreateWireServices } from '../../types/core.types.js';
|
|
6
6
|
/**
|
|
7
7
|
* Error class for when a queue job is explicitly failed
|
|
8
8
|
*/
|
|
@@ -30,9 +30,9 @@ export declare function removeQueueWorker(name: string): Promise<void>;
|
|
|
30
30
|
/**
|
|
31
31
|
* Process a single queue job - this function is called by queue consumers
|
|
32
32
|
*/
|
|
33
|
-
export declare function runQueueJob({ singletonServices,
|
|
33
|
+
export declare function runQueueJob({ singletonServices, createWireServices, job, updateProgress, }: {
|
|
34
34
|
singletonServices: CoreServices;
|
|
35
|
-
|
|
35
|
+
createWireServices?: CreateWireServices;
|
|
36
36
|
job: QueueJob;
|
|
37
37
|
updateProgress?: (progress: number | string | object) => Promise<void>;
|
|
38
38
|
}): Promise<void>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getErrorResponse, PikkuError } from '../../errors/error-handler.js';
|
|
2
2
|
import { pikkuState } from '../../pikku-state.js';
|
|
3
3
|
import { addFunction, runPikkuFunc } from '../../function/function-runner.js';
|
|
4
|
-
import { PikkuWiringTypes, } from '../../types/core.types.js';
|
|
5
4
|
/**
|
|
6
5
|
* Error class for queue processor not found
|
|
7
6
|
*/
|
|
@@ -45,7 +44,6 @@ export const wireQueueWorker = (queueWorker) => {
|
|
|
45
44
|
permissions: queueWorker.func.permissions,
|
|
46
45
|
middleware: queueWorker.func.middleware,
|
|
47
46
|
tags: queueWorker.func.tags,
|
|
48
|
-
docs: queueWorker.func.docs,
|
|
49
47
|
});
|
|
50
48
|
// Store processor definition in state - runtime adapters will pick this up
|
|
51
49
|
const registrations = pikkuState('queue', 'registrations');
|
|
@@ -71,7 +69,7 @@ export async function removeQueueWorker(name) {
|
|
|
71
69
|
/**
|
|
72
70
|
* Process a single queue job - this function is called by queue consumers
|
|
73
71
|
*/
|
|
74
|
-
export async function runQueueJob({ singletonServices,
|
|
72
|
+
export async function runQueueJob({ singletonServices, createWireServices, job, updateProgress, }) {
|
|
75
73
|
const logger = singletonServices.logger;
|
|
76
74
|
const meta = pikkuState('queue', 'meta');
|
|
77
75
|
const processorMeta = meta[job.queueName];
|
|
@@ -84,7 +82,7 @@ export async function runQueueJob({ singletonServices, createSessionServices, jo
|
|
|
84
82
|
if (!queueWorker) {
|
|
85
83
|
throw new Error(`Queue worker registration not found for: ${job.queueName}`);
|
|
86
84
|
}
|
|
87
|
-
// Create the queue
|
|
85
|
+
// Create the queue wire object
|
|
88
86
|
const queue = {
|
|
89
87
|
queueName: job.queueName,
|
|
90
88
|
jobId: job.id,
|
|
@@ -102,24 +100,19 @@ export async function runQueueJob({ singletonServices, createSessionServices, jo
|
|
|
102
100
|
};
|
|
103
101
|
try {
|
|
104
102
|
logger.info(`Processing job ${job.id} in queue ${job.queueName}`);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const sessionServices = await createSessionServices?.(singletonServices, { queue }, undefined);
|
|
108
|
-
return {
|
|
109
|
-
...singletonServices,
|
|
110
|
-
...sessionServices,
|
|
111
|
-
};
|
|
103
|
+
const wire = {
|
|
104
|
+
queue,
|
|
112
105
|
};
|
|
113
106
|
// Execute the pikku function with the job data
|
|
114
|
-
const result = await runPikkuFunc(
|
|
107
|
+
const result = await runPikkuFunc('queue', job.queueName, processorMeta.pikkuFuncName, {
|
|
115
108
|
singletonServices,
|
|
116
|
-
|
|
109
|
+
createWireServices,
|
|
117
110
|
auth: false,
|
|
118
111
|
data: () => job.data,
|
|
119
112
|
inheritedMiddleware: processorMeta.middleware,
|
|
120
113
|
wireMiddleware: queueWorker.middleware,
|
|
121
114
|
tags: queueWorker.tags,
|
|
122
|
-
|
|
115
|
+
wire,
|
|
123
116
|
});
|
|
124
117
|
logger.debug(`Successfully processed job ${job.id} in queue ${job.queueName}`);
|
|
125
118
|
return result;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommonWireMeta } from '../../types/core.types.js';
|
|
2
2
|
import { CorePikkuFunctionConfig } from '../../function/functions.types.js';
|
|
3
3
|
import { QueueConfigMapping } from './validate-worker-config.js';
|
|
4
4
|
/**
|
|
@@ -126,21 +126,13 @@ export interface QueueWorkers {
|
|
|
126
126
|
configMappings: QueueConfigMapping;
|
|
127
127
|
/** Scan state and register all compatible processors */
|
|
128
128
|
registerQueues(): Promise<Record<string, ConfigValidationResult[]>>;
|
|
129
|
-
/** Close all queues and connections */
|
|
130
|
-
close(): Promise<void>;
|
|
131
129
|
}
|
|
132
130
|
/**
|
|
133
131
|
* Queue processor metadata
|
|
134
132
|
*/
|
|
135
|
-
export type
|
|
136
|
-
pikkuFuncName: string;
|
|
137
|
-
schemaName?: string;
|
|
133
|
+
export type QueueWorkersMeta = Record<string, CommonWireMeta & {
|
|
138
134
|
queueName: string;
|
|
139
|
-
session?: undefined;
|
|
140
|
-
docs?: PikkuDocs;
|
|
141
|
-
tags?: string[];
|
|
142
135
|
config?: PikkuWorkerConfig;
|
|
143
|
-
middleware?: MiddlewareMetadata[];
|
|
144
136
|
}>;
|
|
145
137
|
/**
|
|
146
138
|
* Core queue processor definition
|
|
@@ -149,13 +141,12 @@ export type CoreQueueWorker<PikkuFunctionConfig extends CorePikkuFunctionConfig<
|
|
|
149
141
|
queueName: string;
|
|
150
142
|
func: PikkuFunctionConfig;
|
|
151
143
|
config?: PikkuWorkerConfig;
|
|
152
|
-
|
|
153
|
-
session?: undefined;
|
|
144
|
+
errors?: string[];
|
|
154
145
|
tags?: string[];
|
|
155
146
|
middleware?: PikkuFunctionConfig['middleware'];
|
|
156
147
|
};
|
|
157
148
|
/**
|
|
158
|
-
* Represents a queue
|
|
149
|
+
* Represents a queue wire object for middleware
|
|
159
150
|
* Provides information and actions for the current queue job execution
|
|
160
151
|
*/
|
|
161
152
|
export interface PikkuQueue {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { initialize, PikkuRPCService } from './rpc-runner.js';
|
|
1
|
+
export { initialize, PikkuRPCService, rpcService } from './rpc-runner.js';
|
|
2
2
|
export type { PikkuRPC, RPCMeta } from './rpc-types.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { initialize, PikkuRPCService } from './rpc-runner.js';
|
|
1
|
+
export { initialize, PikkuRPCService, rpcService } from './rpc-runner.js';
|
|
@@ -1,26 +1,32 @@
|
|
|
1
|
-
import { CoreServices,
|
|
1
|
+
import { CoreServices, PikkuWire } from '../../types/core.types.js';
|
|
2
2
|
import { PikkuRPC } from './rpc-types.js';
|
|
3
3
|
type RPCServiceConfig = {
|
|
4
4
|
coerceDataFromSchema: boolean;
|
|
5
5
|
};
|
|
6
6
|
export declare class ContextAwareRPCService {
|
|
7
7
|
private services;
|
|
8
|
-
private
|
|
8
|
+
private wire;
|
|
9
9
|
private options;
|
|
10
|
-
constructor(services: CoreServices,
|
|
10
|
+
constructor(services: CoreServices, wire: PikkuWire, options: {
|
|
11
11
|
coerceDataFromSchema?: boolean;
|
|
12
12
|
requiresAuth?: boolean;
|
|
13
13
|
});
|
|
14
14
|
rpcExposed(funcName: string, data: any): Promise<any>;
|
|
15
15
|
rpc<In = any, Out = any>(funcName: string, data: In): Promise<Out>;
|
|
16
|
+
rpcWithWire<In = any, Out = any>(rpcName: string, data: In, wire: PikkuWire): Promise<Out>;
|
|
17
|
+
startWorkflow<In = any>(workflowName: string, input: In): Promise<{
|
|
18
|
+
runId: string;
|
|
19
|
+
}>;
|
|
16
20
|
}
|
|
17
21
|
export declare class PikkuRPCService<Services extends CoreServices, TypedRPC = PikkuRPC> {
|
|
18
22
|
private config?;
|
|
19
23
|
initialize(config: RPCServiceConfig): void;
|
|
20
|
-
|
|
21
|
-
rpc: TypedRPC;
|
|
22
|
-
};
|
|
24
|
+
getContextRPCService(services: Services, wire: PikkuWire, requiresAuth?: boolean | undefined, depth?: number): TypedRPC;
|
|
23
25
|
}
|
|
24
|
-
export declare const rpcService: PikkuRPCService<
|
|
26
|
+
export declare const rpcService: PikkuRPCService<import("../../types/core.types.js").CoreSingletonServices<{
|
|
27
|
+
logLevel?: import("../../index.js").LogLevel;
|
|
28
|
+
secrets?: {};
|
|
29
|
+
workflow?: import("../workflow/workflow.types.js").WorkflowServiceConfig;
|
|
30
|
+
}>, PikkuRPC>;
|
|
25
31
|
export declare const initialize: (config: RPCServiceConfig) => void;
|
|
26
32
|
export {};
|