@pikku/core 0.11.0 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -1
- 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 +22 -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/middleware/auth-apikey.js +3 -3
- package/dist/middleware/auth-bearer.js +3 -3
- package/dist/middleware/auth-cookie.js +5 -5
- package/dist/middleware/timeout.js +3 -2
- package/dist/middleware-runner.d.ts +3 -6
- package/dist/middleware-runner.js +11 -12
- package/dist/permissions.d.ts +6 -6
- package/dist/permissions.js +15 -16
- package/dist/services/user-session-service.d.ts +7 -3
- package/dist/services/user-session-service.js +8 -1
- package/dist/types/core.types.d.ts +29 -38
- package/dist/types/core.types.js +3 -14
- 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/cli-runner.d.ts +5 -5
- package/dist/wirings/cli/cli-runner.js +10 -28
- 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 -17
- package/dist/wirings/queue/queue.types.d.ts +4 -11
- package/dist/wirings/rpc/rpc-runner.d.ts +10 -8
- package/dist/wirings/rpc/rpc-runner.js +36 -47
- 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 +11 -2
- package/dist/wirings/workflow/index.js +10 -2
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +12 -4
- package/dist/wirings/workflow/pikku-workflow-service.js +61 -79
- package/dist/wirings/workflow/workflow-runner.d.ts +3 -4
- package/dist/wirings/workflow/workflow-runner.js +11 -14
- package/dist/wirings/workflow/workflow.types.d.ts +114 -29
- package/package.json +2 -2
- 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 +68 -51
- package/src/handle-error.ts +1 -1
- 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 -16
- package/src/permissions.test.ts +41 -45
- package/src/permissions.ts +21 -21
- package/src/services/user-session-service.ts +14 -4
- package/src/types/core.types.ts +67 -55
- 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/cli-runner.test.ts +7 -7
- package/src/wirings/cli/cli-runner.ts +24 -62
- 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 -32
- package/src/wirings/queue/queue.types.ts +4 -11
- package/src/wirings/rpc/rpc-runner.ts +41 -55
- 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 +24 -3
- package/src/wirings/workflow/pikku-workflow-service.ts +83 -93
- package/src/wirings/workflow/workflow-runner.ts +12 -25
- package/src/wirings/workflow/workflow.types.ts +144 -54
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -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,8 +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
|
-
import { rpcService } from '../rpc/rpc-runner.js';
|
|
6
4
|
/**
|
|
7
5
|
* Error class for queue processor not found
|
|
8
6
|
*/
|
|
@@ -46,7 +44,6 @@ export const wireQueueWorker = (queueWorker) => {
|
|
|
46
44
|
permissions: queueWorker.func.permissions,
|
|
47
45
|
middleware: queueWorker.func.middleware,
|
|
48
46
|
tags: queueWorker.func.tags,
|
|
49
|
-
docs: queueWorker.func.docs,
|
|
50
47
|
});
|
|
51
48
|
// Store processor definition in state - runtime adapters will pick this up
|
|
52
49
|
const registrations = pikkuState('queue', 'registrations');
|
|
@@ -72,7 +69,7 @@ export async function removeQueueWorker(name) {
|
|
|
72
69
|
/**
|
|
73
70
|
* Process a single queue job - this function is called by queue consumers
|
|
74
71
|
*/
|
|
75
|
-
export async function runQueueJob({ singletonServices,
|
|
72
|
+
export async function runQueueJob({ singletonServices, createWireServices, job, updateProgress, }) {
|
|
76
73
|
const logger = singletonServices.logger;
|
|
77
74
|
const meta = pikkuState('queue', 'meta');
|
|
78
75
|
const processorMeta = meta[job.queueName];
|
|
@@ -85,7 +82,7 @@ export async function runQueueJob({ singletonServices, createSessionServices, jo
|
|
|
85
82
|
if (!queueWorker) {
|
|
86
83
|
throw new Error(`Queue worker registration not found for: ${job.queueName}`);
|
|
87
84
|
}
|
|
88
|
-
// Create the queue
|
|
85
|
+
// Create the queue wire object
|
|
89
86
|
const queue = {
|
|
90
87
|
queueName: job.queueName,
|
|
91
88
|
jobId: job.id,
|
|
@@ -103,26 +100,19 @@ export async function runQueueJob({ singletonServices, createSessionServices, jo
|
|
|
103
100
|
};
|
|
104
101
|
try {
|
|
105
102
|
logger.info(`Processing job ${job.id} in queue ${job.queueName}`);
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
const getAllServices = async () => {
|
|
109
|
-
const sessionServices = await createSessionServices?.(singletonServices, { queue }, undefined);
|
|
110
|
-
const services = rpcService.injectRPCService({
|
|
111
|
-
...singletonServices,
|
|
112
|
-
...sessionServices,
|
|
113
|
-
}, interaction, false);
|
|
114
|
-
return services;
|
|
103
|
+
const wire = {
|
|
104
|
+
queue,
|
|
115
105
|
};
|
|
116
106
|
// Execute the pikku function with the job data
|
|
117
|
-
const result = await runPikkuFunc(
|
|
107
|
+
const result = await runPikkuFunc('queue', job.queueName, processorMeta.pikkuFuncName, {
|
|
118
108
|
singletonServices,
|
|
119
|
-
|
|
109
|
+
createWireServices,
|
|
120
110
|
auth: false,
|
|
121
111
|
data: () => job.data,
|
|
122
112
|
inheritedMiddleware: processorMeta.middleware,
|
|
123
113
|
wireMiddleware: queueWorker.middleware,
|
|
124
114
|
tags: queueWorker.tags,
|
|
125
|
-
|
|
115
|
+
wire,
|
|
126
116
|
});
|
|
127
117
|
logger.debug(`Successfully processed job ${job.id} in queue ${job.queueName}`);
|
|
128
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
|
/**
|
|
@@ -130,15 +130,9 @@ export interface QueueWorkers {
|
|
|
130
130
|
/**
|
|
131
131
|
* Queue processor metadata
|
|
132
132
|
*/
|
|
133
|
-
export type QueueWorkersMeta = Record<string, {
|
|
134
|
-
pikkuFuncName: string;
|
|
135
|
-
schemaName?: string;
|
|
133
|
+
export type QueueWorkersMeta = Record<string, CommonWireMeta & {
|
|
136
134
|
queueName: string;
|
|
137
|
-
session?: undefined;
|
|
138
|
-
docs?: PikkuDocs;
|
|
139
|
-
tags?: string[];
|
|
140
135
|
config?: PikkuWorkerConfig;
|
|
141
|
-
middleware?: MiddlewareMetadata[];
|
|
142
136
|
}>;
|
|
143
137
|
/**
|
|
144
138
|
* Core queue processor definition
|
|
@@ -147,13 +141,12 @@ export type CoreQueueWorker<PikkuFunctionConfig extends CorePikkuFunctionConfig<
|
|
|
147
141
|
queueName: string;
|
|
148
142
|
func: PikkuFunctionConfig;
|
|
149
143
|
config?: PikkuWorkerConfig;
|
|
150
|
-
|
|
151
|
-
session?: undefined;
|
|
144
|
+
errors?: string[];
|
|
152
145
|
tags?: string[];
|
|
153
146
|
middleware?: PikkuFunctionConfig['middleware'];
|
|
154
147
|
};
|
|
155
148
|
/**
|
|
156
|
-
* Represents a queue
|
|
149
|
+
* Represents a queue wire object for middleware
|
|
157
150
|
* Provides information and actions for the current queue job execution
|
|
158
151
|
*/
|
|
159
152
|
export interface PikkuQueue {
|
|
@@ -1,19 +1,19 @@
|
|
|
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
|
-
|
|
16
|
+
rpcWithWire<In = any, Out = any>(rpcName: string, data: In, wire: PikkuWire): Promise<Out>;
|
|
17
17
|
startWorkflow<In = any>(workflowName: string, input: In): Promise<{
|
|
18
18
|
runId: string;
|
|
19
19
|
}>;
|
|
@@ -21,10 +21,12 @@ export declare class ContextAwareRPCService {
|
|
|
21
21
|
export declare class PikkuRPCService<Services extends CoreServices, TypedRPC = PikkuRPC> {
|
|
22
22
|
private config?;
|
|
23
23
|
initialize(config: RPCServiceConfig): void;
|
|
24
|
-
|
|
25
|
-
rpc: TypedRPC;
|
|
26
|
-
};
|
|
24
|
+
getContextRPCService(services: Services, wire: PikkuWire, requiresAuth?: boolean | undefined, depth?: number): TypedRPC;
|
|
27
25
|
}
|
|
28
|
-
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>;
|
|
29
31
|
export declare const initialize: (config: RPCServiceConfig) => void;
|
|
30
32
|
export {};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PikkuWiringTypes, } from '../../types/core.types.js';
|
|
2
1
|
import { runPikkuFunc } from '../../function/function-runner.js';
|
|
3
2
|
import { pikkuState } from '../../pikku-state.js';
|
|
4
3
|
import { ForbiddenError } from '../../errors/errors.js';
|
|
@@ -13,11 +12,11 @@ const getPikkuFunctionName = (rpcName) => {
|
|
|
13
12
|
// Context-aware RPC client for use within services
|
|
14
13
|
export class ContextAwareRPCService {
|
|
15
14
|
services;
|
|
16
|
-
|
|
15
|
+
wire;
|
|
17
16
|
options;
|
|
18
|
-
constructor(services,
|
|
17
|
+
constructor(services, wire, options) {
|
|
19
18
|
this.services = services;
|
|
20
|
-
this.
|
|
19
|
+
this.wire = wire;
|
|
21
20
|
this.options = options;
|
|
22
21
|
}
|
|
23
22
|
async rpcExposed(funcName, data) {
|
|
@@ -31,52 +30,46 @@ export class ContextAwareRPCService {
|
|
|
31
30
|
return await this.rpc(funcName, data);
|
|
32
31
|
}
|
|
33
32
|
async rpc(funcName, data) {
|
|
34
|
-
const rpcDepth = this.
|
|
35
|
-
|
|
33
|
+
const rpcDepth = this.wire.rpc?.depth || 0;
|
|
34
|
+
const updatedWire = {
|
|
35
|
+
...this.wire,
|
|
36
|
+
rpc: this.wire.rpc
|
|
37
|
+
? {
|
|
38
|
+
...this.wire.rpc,
|
|
39
|
+
depth: rpcDepth + 1,
|
|
40
|
+
global: false,
|
|
41
|
+
}
|
|
42
|
+
: undefined,
|
|
43
|
+
};
|
|
44
|
+
return runPikkuFunc('rpc', funcName, getPikkuFunctionName(funcName), {
|
|
36
45
|
auth: this.options.requiresAuth,
|
|
46
|
+
// TODO: this is a hack since services have already been created
|
|
47
|
+
// but is valid since we don't want to keep creating new wire services
|
|
37
48
|
singletonServices: this.services,
|
|
38
|
-
getAllServices: () => {
|
|
39
|
-
this.services.rpc = this.services.rpc
|
|
40
|
-
? {
|
|
41
|
-
...this.services.rpc,
|
|
42
|
-
depth: rpcDepth + 1,
|
|
43
|
-
global: false,
|
|
44
|
-
}
|
|
45
|
-
: undefined;
|
|
46
|
-
return this.services;
|
|
47
|
-
},
|
|
48
49
|
data: () => data,
|
|
49
|
-
userSession: this.services.userSession,
|
|
50
50
|
coerceDataFromSchema: this.options.coerceDataFromSchema,
|
|
51
|
-
|
|
51
|
+
wire: updatedWire,
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
|
-
async
|
|
55
|
-
const rpcDepth = this.
|
|
56
|
-
const
|
|
57
|
-
...this.
|
|
58
|
-
...
|
|
54
|
+
async rpcWithWire(rpcName, data, wire) {
|
|
55
|
+
const rpcDepth = this.wire.rpc?.depth || 0;
|
|
56
|
+
const mergedWire = {
|
|
57
|
+
...this.wire,
|
|
58
|
+
...wire,
|
|
59
|
+
rpc: this.wire.rpc
|
|
60
|
+
? {
|
|
61
|
+
...this.wire.rpc,
|
|
62
|
+
depth: rpcDepth + 1,
|
|
63
|
+
global: false,
|
|
64
|
+
}
|
|
65
|
+
: undefined,
|
|
59
66
|
};
|
|
60
|
-
return runPikkuFunc(
|
|
67
|
+
return runPikkuFunc('rpc', rpcName, getPikkuFunctionName(rpcName), {
|
|
61
68
|
auth: this.options.requiresAuth,
|
|
62
69
|
singletonServices: this.services,
|
|
63
|
-
getAllServices: () => {
|
|
64
|
-
this.services.rpc = this.services.rpc
|
|
65
|
-
? {
|
|
66
|
-
...this.services.rpc,
|
|
67
|
-
depth: rpcDepth + 1,
|
|
68
|
-
global: false,
|
|
69
|
-
}
|
|
70
|
-
: undefined;
|
|
71
|
-
return {
|
|
72
|
-
...this.services,
|
|
73
|
-
...mergedInteraction,
|
|
74
|
-
};
|
|
75
|
-
},
|
|
76
70
|
data: () => data,
|
|
77
|
-
userSession: this.services.userSession,
|
|
78
71
|
coerceDataFromSchema: this.options.coerceDataFromSchema,
|
|
79
|
-
|
|
72
|
+
wire: mergedWire,
|
|
80
73
|
});
|
|
81
74
|
}
|
|
82
75
|
async startWorkflow(workflowName, input) {
|
|
@@ -94,23 +87,19 @@ export class PikkuRPCService {
|
|
|
94
87
|
this.config = config;
|
|
95
88
|
}
|
|
96
89
|
// Convenience function for initializing
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
...services,
|
|
100
|
-
};
|
|
101
|
-
const serviceRPC = new ContextAwareRPCService(serviceCopy, interaction, {
|
|
90
|
+
getContextRPCService(services, wire, requiresAuth, depth = 0) {
|
|
91
|
+
const serviceRPC = new ContextAwareRPCService(services, wire, {
|
|
102
92
|
coerceDataFromSchema: this.config?.coerceDataFromSchema,
|
|
103
93
|
requiresAuth,
|
|
104
94
|
});
|
|
105
|
-
|
|
95
|
+
return {
|
|
106
96
|
depth,
|
|
107
97
|
global: false,
|
|
108
98
|
invoke: serviceRPC.rpc.bind(serviceRPC),
|
|
109
99
|
invokeExposed: serviceRPC.rpc.bind(serviceRPC),
|
|
110
100
|
startWorkflow: serviceRPC.startWorkflow.bind(serviceRPC),
|
|
111
|
-
|
|
101
|
+
rpcWithWire: serviceRPC.rpcWithWire.bind(serviceRPC),
|
|
112
102
|
};
|
|
113
|
-
return serviceCopy;
|
|
114
103
|
}
|
|
115
104
|
}
|
|
116
105
|
// Create a singleton instance
|
|
@@ -1,12 +1,12 @@
|
|
|
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 { CoreScheduledTask } from './scheduler.types.js';
|
|
3
3
|
import { CorePikkuFunctionConfig, CorePikkuFunctionSessionless } from '../../function/functions.types.js';
|
|
4
4
|
export type RunScheduledTasksParams = {
|
|
5
5
|
name: string;
|
|
6
6
|
session?: CoreUserSession;
|
|
7
7
|
singletonServices: CoreSingletonServices;
|
|
8
|
-
|
|
8
|
+
createWireServices?: CreateWireServices<CoreSingletonServices, CoreServices<CoreSingletonServices>, CoreUserSession>;
|
|
9
9
|
};
|
|
10
10
|
export declare const wireScheduler: <PikkuFunctionConfig extends CorePikkuFunctionConfig<CorePikkuFunctionSessionless<void, void>>>(scheduledTask: CoreScheduledTask<PikkuFunctionConfig>) => void;
|
|
11
|
-
export declare function runScheduledTask({ name, session, singletonServices,
|
|
11
|
+
export declare function runScheduledTask({ name, session, singletonServices, createWireServices, }: RunScheduledTasksParams): Promise<void>;
|
|
12
12
|
export declare const getScheduledTasks: () => Map<string, CoreScheduledTask>;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { PikkuWiringTypes, } from '../../types/core.types.js';
|
|
2
1
|
import { getErrorResponse, PikkuError } 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 {
|
|
7
|
-
import { PikkuUserSessionService } from '../../services/user-session-service.js';
|
|
5
|
+
import { PikkuSessionService } from '../../services/user-session-service.js';
|
|
8
6
|
export const wireScheduler = (scheduledTask) => {
|
|
9
7
|
const meta = pikkuState('scheduler', 'meta');
|
|
10
8
|
const taskMeta = meta[scheduledTask.name];
|
|
@@ -17,7 +15,6 @@ export const wireScheduler = (scheduledTask) => {
|
|
|
17
15
|
permissions: scheduledTask.func.permissions,
|
|
18
16
|
middleware: scheduledTask.func.middleware,
|
|
19
17
|
tags: scheduledTask.func.tags,
|
|
20
|
-
docs: scheduledTask.func.docs,
|
|
21
18
|
});
|
|
22
19
|
const tasks = pikkuState('scheduler', 'tasks');
|
|
23
20
|
if (tasks.has(scheduledTask.name)) {
|
|
@@ -36,11 +33,11 @@ class ScheduledTaskSkippedError extends PikkuError {
|
|
|
36
33
|
this.name = 'ScheduledTaskSkippedError';
|
|
37
34
|
}
|
|
38
35
|
}
|
|
39
|
-
export async function runScheduledTask({ name, session, singletonServices,
|
|
40
|
-
let
|
|
36
|
+
export async function runScheduledTask({ name, session, singletonServices, createWireServices, }) {
|
|
37
|
+
let wireServices;
|
|
41
38
|
const task = pikkuState('scheduler', 'tasks').get(name);
|
|
42
39
|
const meta = pikkuState('scheduler', 'meta')[name];
|
|
43
|
-
const userSession = new
|
|
40
|
+
const userSession = new PikkuSessionService();
|
|
44
41
|
if (session) {
|
|
45
42
|
userSession.set(session);
|
|
46
43
|
}
|
|
@@ -50,8 +47,8 @@ export async function runScheduledTask({ name, session, singletonServices, creat
|
|
|
50
47
|
if (!meta) {
|
|
51
48
|
throw new ScheduledTaskNotFoundError(`Scheduled task meta not found: ${name}`);
|
|
52
49
|
}
|
|
53
|
-
// Create the scheduled task
|
|
54
|
-
const
|
|
50
|
+
// Create the scheduled task wire object
|
|
51
|
+
const wire = {
|
|
55
52
|
scheduledTask: {
|
|
56
53
|
name,
|
|
57
54
|
schedule: task.schedule,
|
|
@@ -60,28 +57,20 @@ export async function runScheduledTask({ name, session, singletonServices, creat
|
|
|
60
57
|
throw new ScheduledTaskSkippedError(name, reason);
|
|
61
58
|
},
|
|
62
59
|
},
|
|
60
|
+
session: userSession,
|
|
63
61
|
};
|
|
64
62
|
try {
|
|
65
63
|
singletonServices.logger.info(`Running schedule task: ${name} | schedule: ${task.schedule}`);
|
|
66
|
-
|
|
67
|
-
sessionServices = await createSessionServices?.(singletonServices, interaction, session);
|
|
68
|
-
return rpcService.injectRPCService({
|
|
69
|
-
...singletonServices,
|
|
70
|
-
...sessionServices,
|
|
71
|
-
}, interaction);
|
|
72
|
-
};
|
|
73
|
-
const result = await runPikkuFunc(PikkuWiringTypes.scheduler, meta.name, meta.pikkuFuncName, {
|
|
64
|
+
await runPikkuFunc('scheduler', meta.name, meta.pikkuFuncName, {
|
|
74
65
|
singletonServices,
|
|
75
|
-
|
|
76
|
-
userSession,
|
|
66
|
+
createWireServices,
|
|
77
67
|
auth: false,
|
|
78
68
|
data: () => undefined,
|
|
79
69
|
inheritedMiddleware: meta.middleware,
|
|
80
70
|
wireMiddleware: task.middleware,
|
|
81
71
|
tags: task.tags,
|
|
82
|
-
|
|
72
|
+
wire,
|
|
83
73
|
});
|
|
84
|
-
return result;
|
|
85
74
|
}
|
|
86
75
|
catch (e) {
|
|
87
76
|
const errorResponse = getErrorResponse(e);
|
|
@@ -91,8 +80,8 @@ export async function runScheduledTask({ name, session, singletonServices, creat
|
|
|
91
80
|
throw e;
|
|
92
81
|
}
|
|
93
82
|
finally {
|
|
94
|
-
if (
|
|
95
|
-
await
|
|
83
|
+
if (wireServices) {
|
|
84
|
+
await closeWireServices(singletonServices.logger, wireServices);
|
|
96
85
|
}
|
|
97
86
|
}
|
|
98
87
|
}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CoreUserSession, CorePikkuMiddleware, CommonWireMeta } from '../../types/core.types.js';
|
|
2
2
|
import { CorePikkuFunctionConfig, CorePikkuFunctionSessionless } from '../../function/functions.types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Represents metadata for scheduled tasks, including title, schedule, and documentation.
|
|
5
5
|
*/
|
|
6
|
-
export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> = Record<string, {
|
|
7
|
-
pikkuFuncName: string;
|
|
6
|
+
export type ScheduledTasksMeta<UserSession extends CoreUserSession = any> = Record<string, CommonWireMeta & {
|
|
8
7
|
name: string;
|
|
9
8
|
schedule: string;
|
|
10
9
|
session?: UserSession;
|
|
11
|
-
docs?: PikkuDocs;
|
|
12
|
-
tags?: string[];
|
|
13
|
-
middleware?: MiddlewareMetadata[];
|
|
14
10
|
}>;
|
|
15
11
|
/**
|
|
16
12
|
* Represents a core scheduled task.
|
|
@@ -19,12 +15,11 @@ export type CoreScheduledTask<PikkuFunctionConfig = CorePikkuFunctionConfig<Core
|
|
|
19
15
|
name: string;
|
|
20
16
|
schedule: string;
|
|
21
17
|
func: PikkuFunctionConfig;
|
|
22
|
-
docs?: PikkuDocs;
|
|
23
18
|
tags?: string[];
|
|
24
19
|
middleware?: PikkuMiddleware[];
|
|
25
20
|
};
|
|
26
21
|
/**
|
|
27
|
-
* Represents a scheduled task
|
|
22
|
+
* Represents a scheduled task wire object for middleware
|
|
28
23
|
* Provides information about the current scheduled task execution
|
|
29
24
|
*/
|
|
30
25
|
export interface PikkuScheduledTask {
|
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Workflow module exports
|
|
3
3
|
*/
|
|
4
|
-
export type { CoreWorkflow, WorkflowStepOptions, WorkflowStepMeta,
|
|
4
|
+
export type { CoreWorkflow, WorkflowStepOptions, WorkflowStepMeta, RpcStepMeta, BranchStepMeta, ParallelGroupStepMeta, FanoutStepMeta, ReturnStepMeta, InlineStepMeta, SleepStepMeta, CancelStepMeta, InputSource, OutputBinding, PikkuWorkflowWire, PikkuWorkflow, WorkflowsMeta, WorkflowRun, StepState, WorkflowStatus, StepStatus, } from './workflow.types.js';
|
|
5
5
|
export { PikkuWorkflowService } from './pikku-workflow-service.js';
|
|
6
|
-
export {
|
|
6
|
+
export { addWorkflow } from './workflow-runner.js';
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated This function is no longer used and will be removed in a future release.
|
|
9
|
+
* It exists only for backwards compatibility with generated code.
|
|
10
|
+
* TODO: Remove this export in a future release after updating code generation
|
|
11
|
+
*/
|
|
12
|
+
export declare const wireWorkflow: <T extends {
|
|
13
|
+
name: string;
|
|
14
|
+
func: any;
|
|
15
|
+
}>(workflow: T) => void;
|
|
@@ -2,5 +2,13 @@
|
|
|
2
2
|
* Workflow module exports
|
|
3
3
|
*/
|
|
4
4
|
export { PikkuWorkflowService } from './pikku-workflow-service.js';
|
|
5
|
-
//
|
|
6
|
-
export {
|
|
5
|
+
// Internal registration function (used by generated code)
|
|
6
|
+
export { addWorkflow } from './workflow-runner.js';
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated This function is no longer used and will be removed in a future release.
|
|
9
|
+
* It exists only for backwards compatibility with generated code.
|
|
10
|
+
* TODO: Remove this export in a future release after updating code generation
|
|
11
|
+
*/
|
|
12
|
+
export const wireWorkflow = (workflow) => {
|
|
13
|
+
// Empty function - no longer used, kept for backwards compatibility
|
|
14
|
+
};
|