@pikku/core 0.11.2 → 0.12.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 +33 -2
- package/dist/crypto-utils.d.ts +2 -0
- package/dist/crypto-utils.js +78 -0
- package/dist/errors/errors.d.ts +8 -0
- package/dist/errors/errors.js +16 -0
- package/dist/errors/index.d.ts +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/function/function-runner.d.ts +7 -1
- package/dist/function/function-runner.js +82 -23
- package/dist/function/functions.types.d.ts +31 -87
- package/dist/function/functions.types.js +16 -46
- package/dist/function/index.d.ts +2 -2
- package/dist/function/index.js +1 -2
- package/dist/handle-error.js +1 -10
- package/dist/index.d.ts +28 -26
- package/dist/index.js +18 -29
- package/dist/middleware/auth-apikey.d.ts +2 -2
- package/dist/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.d.ts +2 -2
- package/dist/middleware/auth-bearer.js +3 -6
- package/dist/middleware/auth-cookie.d.ts +2 -2
- package/dist/middleware/auth-cookie.js +6 -8
- package/dist/middleware/cors.d.ts +46 -0
- package/dist/middleware/cors.js +73 -0
- package/dist/middleware/index.d.ts +5 -3
- package/dist/middleware/index.js +5 -3
- package/dist/middleware/remote-auth.d.ts +5 -0
- package/dist/middleware/remote-auth.js +55 -0
- package/dist/middleware/timeout.d.ts +2 -2
- package/dist/middleware-runner.js +8 -10
- package/dist/permissions.js +11 -15
- package/dist/pikku-state.d.ts +1 -0
- package/dist/pikku-state.js +18 -8
- package/dist/schema.js +12 -11
- package/dist/services/ai-agent-runner-service.d.ts +24 -0
- package/dist/services/ai-agent-runner-service.js +1 -0
- package/dist/services/ai-run-state-service.d.ts +13 -0
- package/dist/services/ai-run-state-service.js +1 -0
- package/dist/services/ai-storage-service.d.ts +18 -0
- package/dist/services/ai-storage-service.js +1 -0
- package/dist/services/deployment-service.d.ts +19 -0
- package/dist/services/deployment-service.js +1 -0
- package/dist/services/gopass-secrets.d.ts +47 -0
- package/dist/services/gopass-secrets.js +94 -0
- package/dist/services/in-memory-trigger-service.d.ts +23 -0
- package/dist/services/in-memory-trigger-service.js +50 -0
- package/dist/services/in-memory-workflow-service.d.ts +59 -0
- package/dist/services/in-memory-workflow-service.js +287 -0
- package/dist/services/index.d.ts +25 -11
- package/dist/services/index.js +10 -13
- package/dist/services/local-secrets.d.ts +23 -0
- package/dist/services/local-secrets.js +45 -0
- package/dist/services/local-variables.d.ts +5 -0
- package/dist/services/local-variables.js +18 -0
- package/dist/services/scheduler-service.d.ts +21 -1
- package/dist/services/scheduler-service.js +14 -0
- package/dist/services/schema-service.d.ts +6 -0
- package/dist/services/scoped-secret-service.d.ts +16 -0
- package/dist/services/scoped-secret-service.js +35 -0
- package/dist/services/secret-service.d.ts +25 -4
- package/dist/services/trigger-service.d.ts +23 -0
- package/dist/services/trigger-service.js +1 -0
- package/dist/services/typed-secret-service.d.ts +30 -0
- package/dist/services/typed-secret-service.js +40 -0
- package/dist/services/typed-variables-service.d.ts +27 -0
- package/dist/services/typed-variables-service.js +46 -0
- package/dist/services/user-session-service.d.ts +13 -0
- package/dist/services/user-session-service.js +17 -0
- package/dist/services/variables-service.d.ts +5 -0
- package/dist/services/workflow-service.d.ts +9 -4
- package/dist/types/core.types.d.ts +48 -12
- package/dist/types/core.types.js +8 -1
- package/dist/types/state.types.d.ts +43 -51
- package/dist/utils.d.ts +3 -2
- package/dist/utils.js +15 -3
- package/dist/version.d.ts +6 -0
- package/dist/version.js +19 -0
- package/dist/wirings/ai-agent/ai-agent-memory.d.ts +29 -0
- package/dist/wirings/ai-agent/ai-agent-memory.js +199 -0
- package/dist/wirings/ai-agent/ai-agent-model-config.d.ts +9 -0
- package/dist/wirings/ai-agent/ai-agent-model-config.js +36 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.d.ts +60 -0
- package/dist/wirings/ai-agent/ai-agent-prepare.js +312 -0
- package/dist/wirings/ai-agent/ai-agent-registry.d.ts +15 -0
- package/dist/wirings/ai-agent/ai-agent-registry.js +47 -0
- package/dist/wirings/ai-agent/ai-agent-runner.d.ts +3 -0
- package/dist/wirings/ai-agent/ai-agent-runner.js +96 -0
- package/dist/wirings/ai-agent/ai-agent-stream.d.ts +11 -0
- package/dist/wirings/ai-agent/ai-agent-stream.js +503 -0
- package/dist/wirings/ai-agent/ai-agent.types.d.ts +254 -0
- package/dist/wirings/ai-agent/ai-agent.types.js +1 -0
- package/dist/wirings/ai-agent/index.d.ts +5 -0
- package/dist/wirings/ai-agent/index.js +4 -0
- package/dist/wirings/channel/channel-common.d.ts +7 -4
- package/dist/wirings/channel/channel-common.js +15 -8
- package/dist/wirings/channel/channel-handler.js +12 -3
- package/dist/wirings/channel/channel-middleware-runner.d.ts +9 -0
- package/dist/wirings/channel/channel-middleware-runner.js +73 -0
- package/dist/wirings/channel/channel-runner.js +7 -7
- package/dist/wirings/channel/channel.types.d.ts +5 -1
- package/dist/wirings/channel/define-channel-routes.d.ts +21 -0
- package/dist/wirings/channel/define-channel-routes.js +23 -0
- package/dist/wirings/channel/index.d.ts +10 -8
- package/dist/wirings/channel/index.js +7 -8
- package/dist/wirings/channel/local/index.d.ts +3 -3
- package/dist/wirings/channel/local/index.js +3 -3
- package/dist/wirings/channel/local/local-channel-runner.js +18 -6
- package/dist/wirings/channel/serverless/index.d.ts +1 -1
- package/dist/wirings/channel/serverless/index.js +1 -1
- package/dist/wirings/channel/serverless/serverless-channel-runner.js +15 -4
- package/dist/wirings/cli/channel/index.d.ts +1 -1
- package/dist/wirings/cli/channel/index.js +1 -1
- package/dist/wirings/cli/cli-runner.d.ts +1 -1
- package/dist/wirings/cli/cli-runner.js +12 -8
- package/dist/wirings/cli/cli.types.d.ts +6 -6
- package/dist/wirings/cli/define-cli-commands.d.ts +19 -0
- package/dist/wirings/cli/define-cli-commands.js +20 -0
- package/dist/wirings/cli/index.d.ts +2 -3
- package/dist/wirings/cli/index.js +1 -3
- package/dist/wirings/http/http-routes.d.ts +69 -0
- package/dist/wirings/http/http-routes.js +139 -0
- package/dist/wirings/http/http-runner.js +49 -23
- package/dist/wirings/http/http.types.d.ts +78 -38
- package/dist/wirings/http/index.d.ts +5 -4
- package/dist/wirings/http/index.js +4 -3
- package/dist/wirings/mcp/index.d.ts +4 -3
- package/dist/wirings/mcp/index.js +3 -3
- package/dist/wirings/mcp/mcp-runner.d.ts +1 -3
- package/dist/wirings/mcp/mcp-runner.js +25 -39
- package/dist/wirings/mcp/mcp.types.d.ts +3 -3
- package/dist/wirings/node/index.d.ts +2 -0
- package/dist/wirings/node/index.js +1 -0
- package/dist/wirings/node/node.types.d.ts +20 -0
- package/dist/wirings/node/node.types.js +1 -0
- package/dist/wirings/oauth2/index.d.ts +3 -0
- package/dist/wirings/oauth2/index.js +2 -0
- package/dist/wirings/oauth2/oauth2-client.d.ts +47 -0
- package/dist/wirings/oauth2/oauth2-client.js +267 -0
- package/dist/wirings/oauth2/oauth2.types.d.ts +65 -0
- package/dist/wirings/oauth2/oauth2.types.js +4 -0
- package/dist/wirings/oauth2/wire-oauth2-credential.d.ts +20 -0
- package/dist/wirings/oauth2/wire-oauth2-credential.js +21 -0
- package/dist/wirings/queue/index.d.ts +2 -2
- package/dist/wirings/queue/index.js +1 -1
- package/dist/wirings/queue/queue-runner.d.ts +7 -0
- package/dist/wirings/queue/queue-runner.js +17 -6
- package/dist/wirings/queue/queue.types.d.ts +8 -2
- 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 +33 -5
- package/dist/wirings/rpc/rpc-runner.js +134 -16
- package/dist/wirings/rpc/rpc-types.d.ts +8 -4
- package/dist/wirings/scheduler/index.d.ts +3 -3
- package/dist/wirings/scheduler/index.js +2 -3
- package/dist/wirings/scheduler/scheduler-runner.d.ts +5 -0
- package/dist/wirings/scheduler/scheduler-runner.js +23 -5
- package/dist/wirings/secret/index.d.ts +3 -0
- package/dist/wirings/secret/index.js +2 -0
- package/dist/wirings/secret/secret.types.d.ts +27 -0
- package/dist/wirings/secret/secret.types.js +1 -0
- package/dist/wirings/secret/validate-secret-definitions.d.ts +6 -0
- package/dist/wirings/secret/validate-secret-definitions.js +55 -0
- package/dist/wirings/trigger/index.d.ts +3 -2
- package/dist/wirings/trigger/index.js +2 -2
- package/dist/wirings/trigger/pikku-trigger-service.d.ts +26 -0
- package/dist/wirings/trigger/pikku-trigger-service.js +75 -0
- package/dist/wirings/trigger/trigger-runner.d.ts +21 -8
- package/dist/wirings/trigger/trigger-runner.js +46 -18
- package/dist/wirings/trigger/trigger.types.d.ts +99 -11
- package/dist/wirings/trigger/trigger.types.js +40 -1
- package/dist/wirings/variable/index.d.ts +3 -0
- package/dist/wirings/variable/index.js +2 -0
- package/dist/wirings/variable/validate-variable-definitions.d.ts +6 -0
- package/dist/wirings/variable/validate-variable-definitions.js +45 -0
- package/dist/wirings/variable/variable.types.d.ts +18 -0
- package/dist/wirings/variable/variable.types.js +1 -0
- package/dist/wirings/workflow/dsl/index.d.ts +1 -1
- package/dist/wirings/workflow/dsl/workflow-dsl.types.d.ts +7 -1
- package/dist/wirings/workflow/dsl/workflow-runner.js +3 -2
- package/dist/wirings/workflow/graph/graph-node.d.ts +1 -6
- package/dist/wirings/workflow/graph/graph-runner.d.ts +5 -31
- package/dist/wirings/workflow/graph/graph-runner.js +384 -296
- package/dist/wirings/workflow/graph/index.d.ts +4 -3
- package/dist/wirings/workflow/graph/index.js +3 -3
- package/dist/wirings/workflow/graph/template.d.ts +15 -0
- package/dist/wirings/workflow/graph/template.js +27 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.d.ts +15 -0
- package/dist/wirings/workflow/graph/wire-workflow-graph.js +8 -0
- package/dist/wirings/workflow/graph/workflow-graph.types.d.ts +0 -13
- package/dist/wirings/workflow/index.d.ts +6 -6
- package/dist/wirings/workflow/index.js +6 -4
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +28 -14
- package/dist/wirings/workflow/pikku-workflow-service.js +200 -56
- package/dist/wirings/workflow/workflow-helpers.d.ts +36 -0
- package/dist/wirings/workflow/workflow-helpers.js +38 -0
- package/dist/wirings/workflow/workflow-utils.d.ts +1 -23
- package/dist/wirings/workflow/workflow-utils.js +1 -66
- package/dist/wirings/workflow/workflow.types.d.ts +40 -93
- package/package.json +13 -15
- package/run-tests.sh +4 -1
- package/src/crypto-utils.ts +99 -0
- package/src/errors/errors.ts +17 -0
- package/src/errors/index.ts +0 -1
- package/src/factory-functions.test.ts +42 -2
- package/src/function/function-runner.test.ts +4 -11
- package/src/function/function-runner.ts +114 -29
- package/src/function/functions.types.ts +62 -132
- package/src/function/index.ts +5 -2
- package/src/handle-error.ts +2 -10
- package/src/index.ts +99 -25
- package/src/middleware/auth-apikey.test.ts +15 -12
- package/src/middleware/auth-apikey.ts +3 -3
- package/src/middleware/auth-bearer.test.ts +17 -14
- package/src/middleware/auth-bearer.ts +25 -27
- package/src/middleware/auth-cookie.test.ts +16 -13
- package/src/middleware/auth-cookie.ts +6 -8
- package/src/middleware/cors.ts +96 -0
- package/src/middleware/index.ts +5 -3
- package/src/middleware/remote-auth.ts +68 -0
- package/src/middleware-runner.test.ts +122 -0
- package/src/middleware-runner.ts +12 -12
- package/src/permissions.test.ts +81 -7
- package/src/permissions.ts +15 -17
- package/src/pikku-state.ts +20 -8
- package/src/run-tests-script.test.ts +49 -0
- package/src/schema.ts +18 -15
- package/src/services/ai-agent-runner-service.ts +29 -0
- package/src/services/ai-run-state-service.ts +20 -0
- package/src/services/ai-storage-service.ts +39 -0
- package/src/services/deployment-service.ts +22 -0
- package/src/services/gopass-secrets.ts +95 -0
- package/src/services/in-memory-trigger-service.ts +68 -0
- package/src/services/in-memory-workflow-service.ts +395 -0
- package/src/services/index.ts +49 -14
- package/src/services/local-secrets.ts +51 -0
- package/src/services/local-variables.ts +22 -0
- package/src/services/scheduler-service.ts +29 -1
- package/src/services/schema-service.ts +7 -0
- package/src/services/scoped-secret-service.ts +41 -0
- package/src/services/secret-service.ts +25 -4
- package/src/services/trigger-service.ts +38 -0
- package/src/services/typed-secret-service.ts +70 -0
- package/src/services/typed-variables-service.ts +81 -0
- package/src/services/user-session-service.ts +23 -0
- package/src/services/variables-service.ts +5 -0
- package/src/services/workflow-service.ts +22 -2
- package/src/types/core.types.ts +76 -11
- package/src/types/state.types.ts +37 -63
- package/src/utils.ts +20 -6
- package/src/version.test.ts +80 -0
- package/src/version.ts +25 -0
- package/src/wirings/ai-agent/ai-agent-memory.ts +300 -0
- package/src/wirings/ai-agent/ai-agent-model-config.ts +43 -0
- package/src/wirings/ai-agent/ai-agent-prepare.ts +470 -0
- package/src/wirings/ai-agent/ai-agent-registry.test.ts +37 -0
- package/src/wirings/ai-agent/ai-agent-registry.ts +82 -0
- package/src/wirings/ai-agent/ai-agent-runner.test.ts +75 -0
- package/src/wirings/ai-agent/ai-agent-runner.ts +137 -0
- package/src/wirings/ai-agent/ai-agent-stream.test.ts +246 -0
- package/src/wirings/ai-agent/ai-agent-stream.ts +774 -0
- package/src/wirings/ai-agent/ai-agent.types.ts +273 -0
- package/src/wirings/ai-agent/index.ts +28 -0
- package/src/wirings/channel/channel-common.ts +32 -19
- package/src/wirings/channel/channel-handler.ts +17 -4
- package/src/wirings/channel/channel-middleware-runner.ts +119 -0
- package/src/wirings/channel/channel-runner.ts +9 -10
- package/src/wirings/channel/channel.types.ts +17 -1
- package/src/wirings/channel/define-channel-routes.ts +25 -0
- package/src/wirings/channel/index.ts +23 -8
- package/src/wirings/channel/local/index.ts +3 -3
- package/src/wirings/channel/local/local-channel-runner.test.ts +44 -1
- package/src/wirings/channel/local/local-channel-runner.ts +22 -6
- package/src/wirings/channel/serverless/index.ts +5 -1
- package/src/wirings/channel/serverless/serverless-channel-runner.ts +20 -4
- package/src/wirings/cli/channel/index.ts +1 -1
- package/src/wirings/cli/cli-runner.test.ts +9 -9
- package/src/wirings/cli/cli-runner.ts +17 -10
- package/src/wirings/cli/cli.types.ts +11 -11
- package/src/wirings/cli/command-parser.test.ts +8 -8
- package/src/wirings/cli/define-cli-commands.ts +24 -0
- package/src/wirings/cli/index.ts +10 -4
- package/src/wirings/http/http-routes.test.ts +322 -0
- package/src/wirings/http/http-routes.ts +198 -0
- package/src/wirings/http/http-runner.test.ts +3 -3
- package/src/wirings/http/http-runner.ts +63 -29
- package/src/wirings/http/http.types.ts +121 -37
- package/src/wirings/http/index.ts +16 -4
- package/src/wirings/mcp/index.ts +27 -3
- package/src/wirings/mcp/mcp-endpoint-registry.test.ts +3 -3
- package/src/wirings/mcp/mcp-runner.ts +39 -50
- package/src/wirings/mcp/mcp.types.ts +3 -3
- package/src/wirings/node/index.ts +2 -0
- package/src/wirings/node/node.types.ts +23 -0
- package/src/wirings/oauth2/index.ts +3 -0
- package/src/wirings/oauth2/oauth2-client.test.ts +929 -0
- package/src/wirings/oauth2/oauth2-client.ts +335 -0
- package/src/wirings/oauth2/oauth2.types.ts +69 -0
- package/src/wirings/oauth2/wire-oauth2-credential.ts +23 -0
- package/src/wirings/queue/index.ts +14 -2
- package/src/wirings/queue/queue-runner.test.ts +97 -55
- package/src/wirings/queue/queue-runner.ts +33 -7
- package/src/wirings/queue/queue.types.ts +12 -2
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +187 -17
- package/src/wirings/rpc/rpc-types.ts +13 -4
- package/src/wirings/scheduler/index.ts +7 -4
- package/src/wirings/scheduler/scheduler-runner.test.ts +70 -26
- package/src/wirings/scheduler/scheduler-runner.ts +45 -5
- package/src/wirings/secret/index.ts +9 -0
- package/src/wirings/secret/secret.types.ts +32 -0
- package/src/wirings/secret/validate-secret-definitions.ts +82 -0
- package/src/wirings/trigger/index.ts +10 -2
- package/src/wirings/trigger/pikku-trigger-service.ts +134 -0
- package/src/wirings/trigger/trigger-runner.ts +80 -38
- package/src/wirings/trigger/trigger.types.ts +144 -22
- package/src/wirings/variable/index.ts +8 -0
- package/src/wirings/variable/validate-variable-definitions.ts +69 -0
- package/src/wirings/variable/variable.types.ts +22 -0
- package/src/wirings/workflow/dsl/index.ts +1 -0
- package/src/wirings/workflow/dsl/workflow-dsl.types.ts +9 -1
- package/src/wirings/workflow/dsl/workflow-runner.ts +4 -3
- package/src/wirings/workflow/graph/graph-node.ts +1 -6
- package/src/wirings/workflow/graph/graph-runner.test.ts +495 -0
- package/src/wirings/workflow/graph/graph-runner.ts +496 -374
- package/src/wirings/workflow/graph/index.ts +14 -3
- package/src/wirings/workflow/graph/template.ts +42 -0
- package/src/wirings/workflow/graph/wire-workflow-graph.ts +29 -0
- package/src/wirings/workflow/graph/workflow-graph.types.ts +0 -22
- package/src/wirings/workflow/index.ts +21 -10
- package/src/wirings/workflow/pikku-workflow-service.test.ts +212 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +285 -66
- package/src/wirings/workflow/workflow-helpers.ts +79 -0
- package/src/wirings/workflow/workflow-utils.ts +0 -120
- package/src/wirings/workflow/workflow.types.ts +45 -90
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/wirings/forge-node/forge-node.types.d.ts +0 -120
- package/dist/wirings/forge-node/forge-node.types.js +0 -38
- package/dist/wirings/forge-node/index.d.ts +0 -1
- package/dist/wirings/forge-node/index.js +0 -1
- package/dist/wirings/workflow/wire-workflow.d.ts +0 -42
- package/dist/wirings/workflow/wire-workflow.js +0 -53
- package/src/wirings/forge-node/forge-node.types.ts +0 -135
- package/src/wirings/forge-node/index.ts +0 -1
- package/src/wirings/workflow/wire-workflow.ts +0 -94
|
@@ -1,13 +1,26 @@
|
|
|
1
|
-
import { NotFoundError } from '../../errors/errors.js';
|
|
1
|
+
import { NotFoundError, PikkuMissingMetaError } from '../../errors/errors.js';
|
|
2
2
|
import { closeWireServices, createWeakUID, isSerializable, } from '../../utils.js';
|
|
3
|
-
import { PikkuSessionService } from '../../services/user-session-service.js';
|
|
3
|
+
import { PikkuSessionService, createMiddlewareSessionWireProps, } from '../../services/user-session-service.js';
|
|
4
4
|
import { handleHTTPError } from '../../handle-error.js';
|
|
5
5
|
import { pikkuState } from '../../pikku-state.js';
|
|
6
6
|
import { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js';
|
|
7
7
|
import { PikkuFetchHTTPRequest } from './pikku-fetch-http-request.js';
|
|
8
8
|
import { addFunction, runPikkuFunc } from '../../function/function-runner.js';
|
|
9
9
|
import { httpRouter } from './routers/http-router.js';
|
|
10
|
-
import {
|
|
10
|
+
import { validateSchema } from '../../schema.js';
|
|
11
|
+
/**
|
|
12
|
+
* Extract headers from a PikkuHTTPRequest based on the schema keys
|
|
13
|
+
*/
|
|
14
|
+
function extractHeadersFromRequest(request, headerKeys) {
|
|
15
|
+
const headers = {};
|
|
16
|
+
for (const headerName of headerKeys) {
|
|
17
|
+
const value = request.header(headerName);
|
|
18
|
+
if (value !== null) {
|
|
19
|
+
headers[headerName] = value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return headers;
|
|
23
|
+
}
|
|
11
24
|
/**
|
|
12
25
|
* Registers HTTP middleware for a specific route pattern.
|
|
13
26
|
*
|
|
@@ -95,10 +108,10 @@ export const wireHTTP = (httpWiring) => {
|
|
|
95
108
|
const httpMeta = pikkuState(null, 'http', 'meta');
|
|
96
109
|
const routeMeta = httpMeta[httpWiring.method][httpWiring.route];
|
|
97
110
|
if (!routeMeta) {
|
|
98
|
-
throw new
|
|
111
|
+
throw new PikkuMissingMetaError(`Missing generated metadata for HTTP route '${httpWiring.method.toUpperCase()} ${httpWiring.route}'`);
|
|
99
112
|
}
|
|
100
113
|
if (httpWiring.func) {
|
|
101
|
-
addFunction(routeMeta.
|
|
114
|
+
addFunction(routeMeta.pikkuFuncId, httpWiring.func);
|
|
102
115
|
}
|
|
103
116
|
const routes = pikkuState(null, 'http', 'routes');
|
|
104
117
|
if (!routes.has(httpWiring.method)) {
|
|
@@ -184,6 +197,12 @@ const executeRoute = async (services, matchedRoute, http, options) => {
|
|
|
184
197
|
const { singletonServices, createWireServices, skipUserSession, requestId } = services;
|
|
185
198
|
// Attach URL parameters to the request object
|
|
186
199
|
http?.request?.setParams(params);
|
|
200
|
+
// Validate request headers if schema is defined
|
|
201
|
+
if (meta.headersSchemaName && http.request && singletonServices.schema) {
|
|
202
|
+
const headerKeys = singletonServices.schema.getSchemaKeys(meta.headersSchemaName);
|
|
203
|
+
const rawHeaders = extractHeadersFromRequest(http.request, headerKeys);
|
|
204
|
+
await validateSchema(singletonServices.logger, singletonServices.schema, meta.headersSchemaName, rawHeaders);
|
|
205
|
+
}
|
|
187
206
|
const requiresSession = route.auth !== false;
|
|
188
207
|
let wireServices;
|
|
189
208
|
let result;
|
|
@@ -192,7 +211,13 @@ const executeRoute = async (services, matchedRoute, http, options) => {
|
|
|
192
211
|
if (skipUserSession && requiresSession) {
|
|
193
212
|
throw new Error("Can't skip trying to get user session if auth is required");
|
|
194
213
|
}
|
|
195
|
-
|
|
214
|
+
let cachedData;
|
|
215
|
+
const data = async () => {
|
|
216
|
+
if (cachedData === undefined) {
|
|
217
|
+
cachedData = await http.request.data();
|
|
218
|
+
}
|
|
219
|
+
return cachedData;
|
|
220
|
+
};
|
|
196
221
|
let channel;
|
|
197
222
|
if (matchedRoute.route.sse) {
|
|
198
223
|
const response = http?.response;
|
|
@@ -220,14 +245,12 @@ const executeRoute = async (services, matchedRoute, http, options) => {
|
|
|
220
245
|
state: 'open',
|
|
221
246
|
};
|
|
222
247
|
}
|
|
223
|
-
const wire = {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
result = await runPikkuFunc('http', `${meta.method}:${meta.route}`, meta.pikkuFuncName, {
|
|
248
|
+
const wire = {
|
|
249
|
+
http,
|
|
250
|
+
channel,
|
|
251
|
+
...createMiddlewareSessionWireProps(userSession),
|
|
252
|
+
};
|
|
253
|
+
result = await runPikkuFunc('http', `${meta.method}:${meta.route}`, meta.pikkuFuncId, {
|
|
231
254
|
singletonServices,
|
|
232
255
|
createWireServices,
|
|
233
256
|
auth: route.auth !== false,
|
|
@@ -239,17 +262,20 @@ const executeRoute = async (services, matchedRoute, http, options) => {
|
|
|
239
262
|
coerceDataFromSchema: options.coerceDataFromSchema,
|
|
240
263
|
tags: route.tags,
|
|
241
264
|
wire,
|
|
265
|
+
sessionService: userSession,
|
|
242
266
|
});
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
267
|
+
if (!matchedRoute.route.sse) {
|
|
268
|
+
if (result === undefined || result === null) {
|
|
269
|
+
http?.response?.status(204);
|
|
270
|
+
}
|
|
271
|
+
else if (route.returnsJSON === false) {
|
|
272
|
+
http?.response?.arrayBuffer(result);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
http?.response?.status(200);
|
|
276
|
+
http?.response?.json(result);
|
|
277
|
+
}
|
|
249
278
|
}
|
|
250
|
-
http?.response?.status(200);
|
|
251
|
-
// TODO: Evaluate if the response stream should be explicitly ended.
|
|
252
|
-
// http?.response?.end()
|
|
253
279
|
return wireServices ? { result, wireServices } : { result };
|
|
254
280
|
};
|
|
255
281
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { SerializeOptions } from 'cookie';
|
|
2
|
-
import type {
|
|
2
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
+
import { PikkuError } from '../../errors/error-handler.js';
|
|
3
4
|
import type { CoreServices, CoreSingletonServices, CoreUserSession, CreateWireServices, CorePikkuMiddleware, CommonWireMeta } from '../../types/core.types.js';
|
|
4
5
|
import type { CorePikkuFunction, CorePikkuFunctionSessionless, CorePikkuPermission, CorePermissionGroup, CorePikkuFunctionConfig } from '../../function/functions.types.js';
|
|
5
6
|
type ExtractHTTPWiringParams<S extends string> = S extends `${string}:${infer Param}/${infer Rest}` ? Param | ExtractHTTPWiringParams<`/${Rest}`> : S extends `${string}:${infer Param}` ? Param : never;
|
|
@@ -19,28 +20,43 @@ export type RunHTTPWiringOptions = Partial<{
|
|
|
19
20
|
}>;
|
|
20
21
|
export type RunHTTPWiringParams = {
|
|
21
22
|
singletonServices: CoreSingletonServices;
|
|
22
|
-
createWireServices
|
|
23
|
+
createWireServices?: CreateWireServices<CoreSingletonServices, CoreServices<CoreSingletonServices>, CoreUserSession>;
|
|
23
24
|
};
|
|
24
25
|
/**
|
|
25
26
|
* Represents the HTTP methods supported for API HTTP wirings.
|
|
26
|
-
|
|
27
|
+
*/
|
|
27
28
|
export type HTTPMethod = 'post' | 'get' | 'delete' | 'patch' | 'head' | 'put' | 'options';
|
|
28
29
|
/**
|
|
29
|
-
*
|
|
30
|
+
* Header schema type for request header validation.
|
|
31
|
+
* Uses Standard Schema interface - works with Zod, Valibot, ArkType, Effect Schema, etc.
|
|
32
|
+
*/
|
|
33
|
+
export type HTTPHeadersSchema = StandardSchemaV1<Record<string, string | string[] | undefined>>;
|
|
34
|
+
/**
|
|
35
|
+
* Documentation config for OpenAPI generation
|
|
36
|
+
*/
|
|
37
|
+
export type HTTPRouteDocsConfig = {
|
|
38
|
+
description?: string;
|
|
39
|
+
response?: string;
|
|
40
|
+
errors?: Array<typeof PikkuError>;
|
|
41
|
+
tags?: string[];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Common HTTP route configuration shared between wireHTTP and wireHTTPRoutes
|
|
30
45
|
*/
|
|
31
|
-
export type
|
|
46
|
+
export type HTTPRouteBaseConfig = {
|
|
32
47
|
contentType?: 'xml' | 'json';
|
|
48
|
+
timeout?: number;
|
|
49
|
+
tags?: string[];
|
|
50
|
+
headers?: HTTPHeadersSchema;
|
|
51
|
+
docs?: HTTPRouteDocsConfig;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Represents an API HTTP wiring without a function, including metadata such as content type, route, and timeout settings.
|
|
55
|
+
*/
|
|
56
|
+
export type CoreHTTPFunction = HTTPRouteBaseConfig & {
|
|
33
57
|
route: string;
|
|
34
58
|
eventChannel?: false;
|
|
35
59
|
returnsJSON?: false;
|
|
36
|
-
timeout?: number;
|
|
37
|
-
tags?: string[];
|
|
38
|
-
docs?: Partial<{
|
|
39
|
-
description: string;
|
|
40
|
-
response: string;
|
|
41
|
-
errors: Array<typeof PikkuError>;
|
|
42
|
-
tags: string[];
|
|
43
|
-
}>;
|
|
44
60
|
};
|
|
45
61
|
/**
|
|
46
62
|
* Represents a http wire within Pikku, including a request and response.
|
|
@@ -67,13 +83,12 @@ export type PikkuQuery<T = Record<string, string | undefined>> = Record<string,
|
|
|
67
83
|
* @template PikkuFunctionSessionless - The sessionless API function type, defaults to `CorePikkuFunctionSessionless`.
|
|
68
84
|
* @template PikkuPermission - The permission function type, defaults to `CorePikkuPermission`.
|
|
69
85
|
*/
|
|
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 & {
|
|
86
|
+
export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction extends CorePikkuFunction<In, Out, any, any, any> = CorePikkuFunction<In, Out>, PikkuFunctionSessionless extends CorePikkuFunctionSessionless<In, Out, any, any, any> = CorePikkuFunctionSessionless<In, Out>, PikkuPermission extends CorePikkuPermission<In, any, any> = CorePikkuPermission<In, any, any>, PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<any>> = (CoreHTTPFunction & {
|
|
71
87
|
route: R;
|
|
72
88
|
method: HTTPMethod;
|
|
73
89
|
func: CorePikkuFunctionConfig<PikkuFunction, PikkuPermission, PikkuMiddleware>;
|
|
74
90
|
permissions?: CorePermissionGroup<PikkuPermission>;
|
|
75
91
|
auth?: true;
|
|
76
|
-
tags?: string[];
|
|
77
92
|
middleware?: PikkuMiddleware[];
|
|
78
93
|
sse?: undefined;
|
|
79
94
|
}) | (CoreHTTPFunction & {
|
|
@@ -82,7 +97,6 @@ export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction exte
|
|
|
82
97
|
func: CorePikkuFunctionConfig<PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware>;
|
|
83
98
|
permissions?: undefined;
|
|
84
99
|
auth?: false;
|
|
85
|
-
tags?: string[];
|
|
86
100
|
middleware?: PikkuMiddleware[];
|
|
87
101
|
sse?: undefined;
|
|
88
102
|
}) | (CoreHTTPFunction & {
|
|
@@ -91,27 +105,24 @@ export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction exte
|
|
|
91
105
|
func: CorePikkuFunctionConfig<PikkuFunction, PikkuPermission, PikkuMiddleware>;
|
|
92
106
|
permissions?: CorePermissionGroup<PikkuPermission>;
|
|
93
107
|
auth?: true;
|
|
94
|
-
sse?: boolean;
|
|
95
|
-
tags?: string[];
|
|
96
108
|
middleware?: PikkuMiddleware[];
|
|
109
|
+
sse?: boolean;
|
|
97
110
|
}) | (CoreHTTPFunction & {
|
|
98
111
|
route: R;
|
|
99
112
|
method: 'get';
|
|
100
113
|
func: CorePikkuFunctionConfig<PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware>;
|
|
101
114
|
permissions?: undefined;
|
|
102
115
|
auth?: false;
|
|
103
|
-
sse?: boolean;
|
|
104
|
-
tags?: string[];
|
|
105
116
|
middleware?: PikkuMiddleware[];
|
|
117
|
+
sse?: boolean;
|
|
106
118
|
}) | (CoreHTTPFunction & {
|
|
107
119
|
route: R;
|
|
108
120
|
method: 'post';
|
|
109
121
|
func: CorePikkuFunctionConfig<PikkuFunction, PikkuPermission, PikkuMiddleware>;
|
|
110
122
|
permissions?: CorePermissionGroup<PikkuPermission>;
|
|
111
123
|
auth?: true;
|
|
112
|
-
query?: Array<keyof In>;
|
|
113
|
-
tags?: string[];
|
|
114
124
|
middleware?: PikkuMiddleware[];
|
|
125
|
+
query?: Array<keyof In>;
|
|
115
126
|
sse?: undefined;
|
|
116
127
|
}) | (CoreHTTPFunction & {
|
|
117
128
|
route: R;
|
|
@@ -119,23 +130,10 @@ export type CoreHTTPFunctionWiring<In, Out, R extends string, PikkuFunction exte
|
|
|
119
130
|
func: CorePikkuFunctionConfig<PikkuFunctionSessionless, PikkuPermission, PikkuMiddleware>;
|
|
120
131
|
permissions?: undefined;
|
|
121
132
|
auth?: false;
|
|
122
|
-
query?: Array<keyof In>;
|
|
123
|
-
tags?: string[];
|
|
124
133
|
middleware?: PikkuMiddleware[];
|
|
134
|
+
query?: Array<keyof In>;
|
|
125
135
|
sse?: undefined;
|
|
126
|
-
})
|
|
127
|
-
/** Route triggers a workflow matched by route/method from workflow wires.http */
|
|
128
|
-
route: R;
|
|
129
|
-
method: HTTPMethod;
|
|
130
|
-
workflow: true;
|
|
131
|
-
func?: undefined;
|
|
132
|
-
permissions?: undefined;
|
|
133
|
-
auth?: undefined;
|
|
134
|
-
tags?: undefined;
|
|
135
|
-
middleware?: undefined;
|
|
136
|
-
returnsJSON?: undefined;
|
|
137
|
-
sse?: boolean;
|
|
138
|
-
};
|
|
136
|
+
});
|
|
139
137
|
/**
|
|
140
138
|
* Represents the input types for HTTP wiring metadata, including parameters, query, and body types.
|
|
141
139
|
*/
|
|
@@ -153,8 +151,9 @@ export type HTTPWiringMeta = CommonWireMeta & {
|
|
|
153
151
|
params?: string[];
|
|
154
152
|
query?: string[];
|
|
155
153
|
inputTypes?: HTTPFunctionMetaInputTypes;
|
|
154
|
+
headersSchemaName?: string;
|
|
156
155
|
sse?: true;
|
|
157
|
-
|
|
156
|
+
groupBasePath?: string;
|
|
158
157
|
};
|
|
159
158
|
export type HTTPWiringsMeta = Record<HTTPMethod, Record<string, HTTPWiringMeta>>;
|
|
160
159
|
export type HTTPFunctionsMeta = Array<{
|
|
@@ -188,4 +187,45 @@ export interface PikkuHTTPResponse<Out = unknown> {
|
|
|
188
187
|
close?: () => void;
|
|
189
188
|
setMode?: (mode: 'stream') => void;
|
|
190
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Single route configuration - supports all wireHTTP options
|
|
192
|
+
*/
|
|
193
|
+
export type HTTPRouteConfig<PikkuFunction extends CorePikkuFunction<any, any, any, any, any> | CorePikkuFunctionSessionless<any, any, any, any, any> = CorePikkuFunction<any, any, any, any, any> | CorePikkuFunctionSessionless<any, any, any, any, any>, PikkuPermission extends CorePikkuPermission<any, any, any> = CorePikkuPermission<any>, PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<any, any>> = HTTPRouteBaseConfig & {
|
|
194
|
+
method: HTTPMethod;
|
|
195
|
+
route: string;
|
|
196
|
+
func: CorePikkuFunctionConfig<PikkuFunction, PikkuPermission, PikkuMiddleware>;
|
|
197
|
+
auth?: boolean;
|
|
198
|
+
permissions?: CorePermissionGroup<PikkuPermission>;
|
|
199
|
+
middleware?: PikkuMiddleware[];
|
|
200
|
+
sse?: boolean;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Group-level configuration applied to all routes
|
|
204
|
+
*/
|
|
205
|
+
export type HTTPRoutesGroupConfig<PikkuPermission extends CorePikkuPermission<any, any, any> = CorePikkuPermission<any>, PikkuMiddleware extends CorePikkuMiddleware<any, any> = CorePikkuMiddleware<any, any>> = {
|
|
206
|
+
basePath?: string;
|
|
207
|
+
tags?: string[];
|
|
208
|
+
auth?: boolean;
|
|
209
|
+
middleware?: PikkuMiddleware[];
|
|
210
|
+
permissions?: CorePermissionGroup<PikkuPermission>;
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Nested route map - allows hierarchical organization
|
|
214
|
+
* Can contain individual routes, nested maps, or contracts with config
|
|
215
|
+
*/
|
|
216
|
+
export type HTTPRouteMap = {
|
|
217
|
+
[key: string]: HTTPRouteConfig | HTTPRouteMap | HTTPRouteContract;
|
|
218
|
+
};
|
|
219
|
+
/**
|
|
220
|
+
* A route contract with optional group config (returned by defineRoutes)
|
|
221
|
+
*/
|
|
222
|
+
export type HTTPRouteContract<T extends HTTPRouteMap = HTTPRouteMap> = HTTPRoutesGroupConfig & {
|
|
223
|
+
routes: T;
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* Full configuration for wireHTTPRoutes
|
|
227
|
+
*/
|
|
228
|
+
export type WireHTTPRoutesConfig = HTTPRoutesGroupConfig & {
|
|
229
|
+
routes: HTTPRouteMap | HTTPRouteConfig[];
|
|
230
|
+
};
|
|
191
231
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { PikkuFetchHTTPRequest } from './pikku-fetch-http-request.js';
|
|
2
|
+
export { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js';
|
|
3
|
+
export { logRoutes } from './log-http-routes.js';
|
|
4
4
|
export { fetch, fetchData, wireHTTP, addHTTPMiddleware, addHTTPPermission, } from './http-runner.js';
|
|
5
|
-
export
|
|
5
|
+
export { wireHTTPRoutes, defineHTTPRoutes } from './http-routes.js';
|
|
6
|
+
export type { AssertHTTPWiringParams, CoreHTTPFunctionWiring, HTTPMethod, HTTPRouteBaseConfig, HTTPWiringsMeta, PikkuHTTPRequest, PikkuHTTPResponse, PikkuQuery, RunHTTPWiringOptions, } from './http.types.js';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { PikkuFetchHTTPRequest } from './pikku-fetch-http-request.js';
|
|
2
|
+
export { PikkuFetchHTTPResponse } from './pikku-fetch-http-response.js';
|
|
3
|
+
export { logRoutes } from './log-http-routes.js';
|
|
4
4
|
export { fetch, fetchData, wireHTTP, addHTTPMiddleware, addHTTPPermission, } from './http-runner.js';
|
|
5
|
+
export { wireHTTPRoutes, defineHTTPRoutes } from './http-routes.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { MCPEndpointRegistry } from './mcp-endpoint-registry.js';
|
|
2
|
+
export { MCPError, wireMCPResource, wireMCPPrompt, runMCPResource, runMCPTool, runMCPPrompt, } from './mcp-runner.js';
|
|
3
|
+
export { getMCPResourcesMeta, getMCPToolsMeta, getMCPPromptsMeta, } from './mcp-runner.js';
|
|
4
|
+
export type { AssertMCPResourceURIParams, CoreMCPPrompt, CoreMCPResource, CoreMCPTool, MCPPromptResponse, MCPResourceMeta, MCPResourceResponse, MCPToolMeta, MCPToolResponse, MCPPromptMeta, PikkuMCP, } from './mcp.types.js';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export { MCPEndpointRegistry } from './mcp-endpoint-registry.js';
|
|
2
|
+
export { MCPError, wireMCPResource, wireMCPPrompt, runMCPResource, runMCPTool, runMCPPrompt, } from './mcp-runner.js';
|
|
3
|
+
export { getMCPResourcesMeta, getMCPToolsMeta, getMCPPromptsMeta, } from './mcp-runner.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type CoreServices, type CoreSingletonServices, type CoreUserSession, type CreateWireServices } from '../../types/core.types.js';
|
|
2
|
-
import type { CoreMCPResource,
|
|
2
|
+
import type { CoreMCPResource, 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 {
|
|
5
5
|
readonly error: JsonRpcErrorResponse;
|
|
@@ -16,12 +16,10 @@ export type JsonRpcError = {
|
|
|
16
16
|
data?: any;
|
|
17
17
|
};
|
|
18
18
|
export declare const wireMCPResource: <PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunctionSessionless<any, any>> = CorePikkuFunctionConfig<CorePikkuFunctionSessionless<any, any>>>(mcpResource: CoreMCPResource<PikkuFunctionConfig>) => void;
|
|
19
|
-
export declare const wireMCPTool: <PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunctionSessionless<any, any>> = CorePikkuFunctionConfig<CorePikkuFunctionSessionless<any, any>>>(mcpTool: CoreMCPTool<PikkuFunctionConfig>) => void;
|
|
20
19
|
export declare const wireMCPPrompt: <PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunctionSessionless<any, any>> = CorePikkuFunctionConfig<CorePikkuFunctionSessionless<any, any>>>(mcpPrompt: CoreMCPPrompt<PikkuFunctionConfig>) => void;
|
|
21
20
|
export declare function runMCPResource(request: JsonRpcRequest, params: RunMCPEndpointParams, uri: string): Promise<JsonRpcResponse>;
|
|
22
21
|
export declare function runMCPTool(request: JsonRpcRequest, params: RunMCPEndpointParams, name: string): Promise<JsonRpcResponse>;
|
|
23
22
|
export declare function runMCPPrompt(request: JsonRpcRequest, params: RunMCPEndpointParams, name: string): Promise<JsonRpcResponse>;
|
|
24
|
-
export declare const getMCPTools: () => Map<string, CoreMCPTool>;
|
|
25
23
|
export declare const getMCPResources: () => Map<string, CoreMCPResource>;
|
|
26
24
|
export declare const getMCPResourcesMeta: () => import("./mcp.types.js").MCPResourceMeta;
|
|
27
25
|
export declare const getMCPToolsMeta: () => import("./mcp.types.js").MCPToolMeta;
|
|
@@ -2,8 +2,8 @@ import { getErrorResponse } from '../../errors/error-handler.js';
|
|
|
2
2
|
import { closeWireServices } from '../../utils.js';
|
|
3
3
|
import { pikkuState } from '../../pikku-state.js';
|
|
4
4
|
import { addFunction, runPikkuFunc } from '../../function/function-runner.js';
|
|
5
|
-
import { BadRequestError, NotFoundError } from '../../errors/errors.js';
|
|
6
|
-
import { PikkuSessionService } from '../../services/user-session-service.js';
|
|
5
|
+
import { BadRequestError, NotFoundError, PikkuMissingMetaError, } from '../../errors/errors.js';
|
|
6
|
+
import { PikkuSessionService, createMiddlewareSessionWireProps, } from '../../services/user-session-service.js';
|
|
7
7
|
export class MCPError extends Error {
|
|
8
8
|
error;
|
|
9
9
|
constructor(error) {
|
|
@@ -17,35 +17,22 @@ export const wireMCPResource = (mcpResource) => {
|
|
|
17
17
|
const resourcesMeta = pikkuState(null, 'mcp', 'resourcesMeta');
|
|
18
18
|
const mcpResourceMeta = resourcesMeta[mcpResource.uri];
|
|
19
19
|
if (!mcpResourceMeta) {
|
|
20
|
-
throw new
|
|
20
|
+
throw new PikkuMissingMetaError(`Missing generated metadata for MCP resource '${mcpResource.uri}'`);
|
|
21
21
|
}
|
|
22
|
-
addFunction(mcpResourceMeta.
|
|
22
|
+
addFunction(mcpResourceMeta.pikkuFuncId, mcpResource.func);
|
|
23
23
|
const resources = pikkuState(null, 'mcp', 'resources');
|
|
24
24
|
if (resources.has(mcpResource.uri)) {
|
|
25
25
|
throw new Error(`MCP resource already exists: ${mcpResource.uri}`);
|
|
26
26
|
}
|
|
27
27
|
resources.set(mcpResource.uri, mcpResource);
|
|
28
28
|
};
|
|
29
|
-
export const wireMCPTool = (mcpTool) => {
|
|
30
|
-
const toolsMeta = pikkuState(null, 'mcp', 'toolsMeta');
|
|
31
|
-
const mcpToolMeta = toolsMeta[mcpTool.name];
|
|
32
|
-
if (!mcpToolMeta) {
|
|
33
|
-
throw new Error(`MCP tool metadata not found for '${mcpTool.name}'`);
|
|
34
|
-
}
|
|
35
|
-
addFunction(mcpToolMeta.pikkuFuncName, mcpTool.func);
|
|
36
|
-
const tools = pikkuState(null, 'mcp', 'tools');
|
|
37
|
-
if (tools.has(mcpTool.name)) {
|
|
38
|
-
throw new Error(`MCP tool already exists: ${mcpTool.name}`);
|
|
39
|
-
}
|
|
40
|
-
tools.set(mcpTool.name, mcpTool);
|
|
41
|
-
};
|
|
42
29
|
export const wireMCPPrompt = (mcpPrompt) => {
|
|
43
30
|
const promptsMeta = pikkuState(null, 'mcp', 'promptsMeta');
|
|
44
31
|
const mcpPromptMeta = promptsMeta[mcpPrompt.name];
|
|
45
32
|
if (!mcpPromptMeta) {
|
|
46
|
-
throw new
|
|
33
|
+
throw new PikkuMissingMetaError(`Missing generated metadata for MCP prompt '${mcpPrompt.name}'`);
|
|
47
34
|
}
|
|
48
|
-
addFunction(mcpPromptMeta.
|
|
35
|
+
addFunction(mcpPromptMeta.pikkuFuncId, mcpPrompt.func);
|
|
49
36
|
const prompts = pikkuState(null, 'mcp', 'prompts');
|
|
50
37
|
if (prompts.has(mcpPrompt.name)) {
|
|
51
38
|
throw new Error(`MCP prompt already exists: ${mcpPrompt.name}`);
|
|
@@ -54,13 +41,13 @@ export const wireMCPPrompt = (mcpPrompt) => {
|
|
|
54
41
|
};
|
|
55
42
|
export async function runMCPResource(request, params, uri) {
|
|
56
43
|
let endpoint;
|
|
57
|
-
let
|
|
44
|
+
let pikkuFuncId;
|
|
58
45
|
let extractedParams = {};
|
|
59
46
|
const metas = pikkuState(null, 'mcp', 'resourcesMeta');
|
|
60
47
|
const endpoints = pikkuState(null, 'mcp', 'resources');
|
|
61
48
|
if (endpoints.has(uri)) {
|
|
62
49
|
endpoint = endpoints.get(uri);
|
|
63
|
-
|
|
50
|
+
pikkuFuncId = metas[uri]?.pikkuFuncId;
|
|
64
51
|
}
|
|
65
52
|
else {
|
|
66
53
|
for (const [uriTemplate, value] of endpoints.entries()) {
|
|
@@ -72,7 +59,7 @@ export async function runMCPResource(request, params, uri) {
|
|
|
72
59
|
const match = uri.match(regex);
|
|
73
60
|
if (match) {
|
|
74
61
|
endpoint = value;
|
|
75
|
-
|
|
62
|
+
pikkuFuncId = metas[uriTemplate]?.pikkuFuncId;
|
|
76
63
|
// Extract parameter values and create params object
|
|
77
64
|
for (let i = 0; i < paramNames.length; i++) {
|
|
78
65
|
extractedParams[paramNames[i]] = match[i + 1]; // match[0] is the full match
|
|
@@ -84,40 +71,38 @@ export async function runMCPResource(request, params, uri) {
|
|
|
84
71
|
return await runMCPPikkuFunc({
|
|
85
72
|
...request,
|
|
86
73
|
params: { ...request.params, ...extractedParams },
|
|
87
|
-
}, 'resource', uri, endpoint,
|
|
74
|
+
}, 'resource', uri, endpoint, pikkuFuncId, { ...params, mcp: { ...params.mcp, uri } });
|
|
88
75
|
}
|
|
89
76
|
export async function runMCPTool(request, params, name) {
|
|
90
|
-
const endpoint = pikkuState(null, 'mcp', 'tools').get(name);
|
|
91
77
|
const meta = pikkuState(null, 'mcp', 'toolsMeta')[name];
|
|
92
|
-
return await runMCPPikkuFunc(request, 'tool', name,
|
|
78
|
+
return await runMCPPikkuFunc(request, 'tool', name, undefined, meta?.pikkuFuncId, params);
|
|
93
79
|
}
|
|
94
80
|
export async function runMCPPrompt(request, params, name) {
|
|
95
81
|
const endpoint = pikkuState(null, 'mcp', 'prompts').get(name);
|
|
96
82
|
const meta = pikkuState(null, 'mcp', 'promptsMeta')[name];
|
|
97
|
-
return await runMCPPikkuFunc(request, 'prompt', name, endpoint, meta?.
|
|
83
|
+
return await runMCPPikkuFunc(request, 'prompt', name, endpoint, meta?.pikkuFuncId, params);
|
|
98
84
|
}
|
|
99
85
|
/**
|
|
100
86
|
* JSON-RPC 2.0 compatible MCP endpoint runner
|
|
101
87
|
*/
|
|
102
|
-
async function runMCPPikkuFunc(request, type, name, mcp,
|
|
88
|
+
async function runMCPPikkuFunc(request, type, name, mcp, pikkuFuncId, { singletonServices, createWireServices, mcp: mcpWire }) {
|
|
103
89
|
let wireServices;
|
|
104
90
|
try {
|
|
105
|
-
// Validate JSON-RPC request structure
|
|
106
91
|
if (request.jsonrpc !== '2.0') {
|
|
107
92
|
throw new BadRequestError('Invalid JSON-RPC version, only supoorted version is 2.0');
|
|
108
93
|
}
|
|
109
|
-
if (
|
|
94
|
+
if (mcp === undefined && type !== 'tool') {
|
|
110
95
|
throw new NotFoundError(`MCP '${type}' registration not found for '${name}'`);
|
|
111
96
|
}
|
|
112
|
-
if (!
|
|
97
|
+
if (!pikkuFuncId) {
|
|
113
98
|
throw new NotFoundError(`MCP '${type}' PikkuFunction Mapping not found for '${name}'`);
|
|
114
99
|
}
|
|
115
100
|
singletonServices.logger.debug(`Running MCP ${type}: ${name}`);
|
|
101
|
+
const mcpSessionService = new PikkuSessionService();
|
|
116
102
|
const wire = {
|
|
117
103
|
mcp: mcpWire,
|
|
118
|
-
|
|
104
|
+
...createMiddlewareSessionWireProps(mcpSessionService),
|
|
119
105
|
};
|
|
120
|
-
// Get metadata for the MCP endpoint to access pre-resolved middleware
|
|
121
106
|
let meta;
|
|
122
107
|
if (type === 'resource') {
|
|
123
108
|
meta = pikkuState(null, 'mcp', 'resourcesMeta')[name];
|
|
@@ -128,17 +113,21 @@ async function runMCPPikkuFunc(request, type, name, mcp, pikkuFuncName, { single
|
|
|
128
113
|
else if (type === 'prompt') {
|
|
129
114
|
meta = pikkuState(null, 'mcp', 'promptsMeta')[name];
|
|
130
115
|
}
|
|
131
|
-
|
|
116
|
+
let result = await runPikkuFunc('mcp', `${type}:${name}`, pikkuFuncId, {
|
|
132
117
|
singletonServices,
|
|
133
118
|
createWireServices,
|
|
134
119
|
data: () => request.params,
|
|
135
120
|
inheritedMiddleware: meta?.middleware,
|
|
136
|
-
wireMiddleware: mcp
|
|
121
|
+
wireMiddleware: mcp?.middleware,
|
|
137
122
|
inheritedPermissions: meta?.permissions,
|
|
138
|
-
wirePermissions: mcp
|
|
139
|
-
tags: mcp
|
|
123
|
+
wirePermissions: mcp?.permissions,
|
|
124
|
+
tags: mcp?.tags,
|
|
140
125
|
wire,
|
|
126
|
+
sessionService: mcpSessionService,
|
|
141
127
|
});
|
|
128
|
+
if (type === 'tool' && meta?.outputSchema !== 'MCPToolResponse') {
|
|
129
|
+
result = [{ type: 'text', text: JSON.stringify(result) }];
|
|
130
|
+
}
|
|
142
131
|
return {
|
|
143
132
|
id: request.id,
|
|
144
133
|
result,
|
|
@@ -172,9 +161,6 @@ async function runMCPPikkuFunc(request, type, name, mcp, pikkuFuncName, { single
|
|
|
172
161
|
}
|
|
173
162
|
}
|
|
174
163
|
}
|
|
175
|
-
export const getMCPTools = () => {
|
|
176
|
-
return pikkuState(null, 'mcp', 'tools');
|
|
177
|
-
};
|
|
178
164
|
export const getMCPResources = () => {
|
|
179
165
|
return pikkuState(null, 'mcp', 'resources');
|
|
180
166
|
};
|
|
@@ -26,7 +26,7 @@ export type PikkuMCP<Tools extends string = any> = {
|
|
|
26
26
|
* Represents metadata for MCP resources, including name, description, and documentation.
|
|
27
27
|
*/
|
|
28
28
|
export type MCPResourceMeta = Record<string, Omit<CoreMCPResource, 'func' | 'middleware' | 'permissions'> & {
|
|
29
|
-
|
|
29
|
+
pikkuFuncId: string;
|
|
30
30
|
inputSchema: string | null;
|
|
31
31
|
outputSchema: string | null;
|
|
32
32
|
middleware?: MiddlewareMetadata[];
|
|
@@ -36,7 +36,7 @@ export type MCPResourceMeta = Record<string, Omit<CoreMCPResource, 'func' | 'mid
|
|
|
36
36
|
* Represents metadata for MCP tools, including name, description, and documentation.
|
|
37
37
|
*/
|
|
38
38
|
export type MCPToolMeta = Record<string, Omit<CoreMCPTool, 'func' | 'middleware' | 'permissions'> & {
|
|
39
|
-
|
|
39
|
+
pikkuFuncId: string;
|
|
40
40
|
inputSchema: string | null;
|
|
41
41
|
outputSchema: string | null;
|
|
42
42
|
middleware?: MiddlewareMetadata[];
|
|
@@ -46,7 +46,7 @@ export type MCPToolMeta = Record<string, Omit<CoreMCPTool, 'func' | 'middleware'
|
|
|
46
46
|
* Represents metadata for MCP prompts, including name, description, and arguments.
|
|
47
47
|
*/
|
|
48
48
|
export type MCPPromptMeta = Record<string, Omit<CoreMCPPrompt, 'func' | 'middleware' | 'permissions'> & {
|
|
49
|
-
|
|
49
|
+
pikkuFuncId: string;
|
|
50
50
|
inputSchema: string | null;
|
|
51
51
|
outputSchema: string | null;
|
|
52
52
|
arguments: Array<{
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type NodeType = 'trigger' | 'action' | 'end';
|
|
2
|
+
export type CoreNodeConfig = {
|
|
3
|
+
displayName: string;
|
|
4
|
+
category: string;
|
|
5
|
+
type: NodeType;
|
|
6
|
+
errorOutput?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export type NodeMeta = {
|
|
9
|
+
name: string;
|
|
10
|
+
displayName: string;
|
|
11
|
+
category: string;
|
|
12
|
+
type: NodeType;
|
|
13
|
+
rpc: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
errorOutput: boolean;
|
|
16
|
+
inputSchemaName: string | null;
|
|
17
|
+
outputSchemaName: string | null;
|
|
18
|
+
tags?: string[];
|
|
19
|
+
};
|
|
20
|
+
export type NodesMeta = Record<string, NodeMeta>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|