@pikku/core 0.10.2 → 0.11.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 +9 -0
- package/dist/function/functions.types.d.ts +1 -0
- 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-bearer.d.ts +1 -0
- package/dist/middleware/auth-cookie.d.ts +1 -0
- package/dist/middleware/timeout.d.ts +1 -0
- package/dist/middleware-runner.js +1 -0
- package/dist/permissions.js +1 -0
- 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/time-utils.d.ts +14 -0
- package/dist/time-utils.js +62 -0
- package/dist/types/core.types.d.ts +24 -2
- package/dist/types/core.types.js +1 -0
- package/dist/wirings/cli/channel/cli-channel-runner.js +1 -1
- package/dist/wirings/cli/cli-runner.js +1 -1
- package/dist/wirings/queue/queue-runner.js +6 -3
- package/dist/wirings/queue/queue.types.d.ts +1 -3
- 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 +4 -0
- package/dist/wirings/rpc/rpc-runner.js +37 -2
- package/dist/wirings/rpc/rpc-types.d.ts +1 -0
- package/dist/wirings/workflow/index.d.ts +6 -0
- package/dist/wirings/workflow/index.js +6 -0
- package/dist/wirings/workflow/pikku-workflow-service.d.ts +152 -0
- package/dist/wirings/workflow/pikku-workflow-service.js +448 -0
- package/dist/wirings/workflow/workflow-runner.d.ts +35 -0
- package/dist/wirings/workflow/workflow-runner.js +68 -0
- package/dist/wirings/workflow/workflow.types.d.ts +247 -0
- package/dist/wirings/workflow/workflow.types.js +1 -0
- package/package.json +2 -3
- package/src/function/functions.types.ts +1 -0
- package/src/index.ts +2 -0
- package/src/middleware-runner.ts +1 -0
- package/src/permissions.ts +1 -0
- package/src/pikku-state.ts +14 -2
- package/src/services/index.ts +1 -0
- package/src/services/scheduler-service.ts +76 -0
- package/src/time-utils.ts +75 -0
- package/src/types/core.types.ts +30 -1
- package/src/wirings/cli/channel/cli-channel-runner.ts +1 -1
- package/src/wirings/cli/cli-runner.ts +1 -1
- package/src/wirings/queue/queue-runner.ts +14 -6
- package/src/wirings/queue/queue.types.ts +1 -4
- package/src/wirings/rpc/index.ts +1 -1
- package/src/wirings/rpc/rpc-runner.ts +56 -3
- package/src/wirings/rpc/rpc-types.ts +1 -0
- package/src/wirings/workflow/index.ts +22 -0
- package/src/wirings/workflow/pikku-workflow-service.ts +756 -0
- package/src/wirings/workflow/workflow-runner.ts +85 -0
- package/src/wirings/workflow/workflow.types.ts +332 -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
package/CHANGELOG.md
CHANGED
|
@@ -108,6 +108,7 @@ export type CorePermissionGroup<PikkuPermission = CorePikkuPermission<any>> = Re
|
|
|
108
108
|
export type CorePikkuFunctionConfig<PikkuFunction extends CorePikkuFunction<any, any, any, any, any> | CorePikkuFunctionSessionless<any, any, any, any, any>, PikkuPermission extends CorePikkuPermission<any, any, any> = CorePikkuPermission<any>, PikkuMiddleware extends CorePikkuMiddleware<any> = CorePikkuMiddleware<any>> = {
|
|
109
109
|
name?: string;
|
|
110
110
|
expose?: boolean;
|
|
111
|
+
internal?: boolean;
|
|
111
112
|
func: PikkuFunction;
|
|
112
113
|
auth?: boolean;
|
|
113
114
|
permissions?: CorePermissionGroup<PikkuPermission>;
|
package/dist/index.d.ts
CHANGED
|
@@ -10,11 +10,13 @@ export * from './services/schema-service.js';
|
|
|
10
10
|
export * from './services/jwt-service.js';
|
|
11
11
|
export * from './services/secret-service.js';
|
|
12
12
|
export * from './services/user-session-service.js';
|
|
13
|
+
export * from './services/scheduler-service.js';
|
|
13
14
|
export * from './wirings/http/index.js';
|
|
14
15
|
export * from './wirings/channel/index.js';
|
|
15
16
|
export * from './wirings/scheduler/index.js';
|
|
16
17
|
export * from './wirings/rpc/index.js';
|
|
17
18
|
export * from './wirings/queue/index.js';
|
|
19
|
+
export * from './wirings/workflow/index.js';
|
|
18
20
|
export * from './wirings/mcp/index.js';
|
|
19
21
|
export * from './wirings/cli/index.js';
|
|
20
22
|
export * from './errors/index.js';
|
package/dist/index.js
CHANGED
|
@@ -10,11 +10,13 @@ export * from './services/schema-service.js';
|
|
|
10
10
|
export * from './services/jwt-service.js';
|
|
11
11
|
export * from './services/secret-service.js';
|
|
12
12
|
export * from './services/user-session-service.js';
|
|
13
|
+
export * from './services/scheduler-service.js';
|
|
13
14
|
export * from './wirings/http/index.js';
|
|
14
15
|
export * from './wirings/channel/index.js';
|
|
15
16
|
export * from './wirings/scheduler/index.js';
|
|
16
17
|
export * from './wirings/rpc/index.js';
|
|
17
18
|
export * from './wirings/queue/index.js';
|
|
19
|
+
export * from './wirings/workflow/index.js';
|
|
18
20
|
export * from './wirings/mcp/index.js';
|
|
19
21
|
export * from './wirings/cli/index.js';
|
|
20
22
|
export * from './errors/index.js';
|
|
@@ -20,4 +20,5 @@ export declare const authAPIKey: import("../types/core.types.js").CorePikkuMiddl
|
|
|
20
20
|
}, import("../types/core.types.js").CoreSingletonServices<{
|
|
21
21
|
logLevel?: import("../index.js").LogLevel;
|
|
22
22
|
secrets?: {};
|
|
23
|
+
workflow?: import("../wirings/workflow/workflow.types.js").WorkflowServiceConfig;
|
|
23
24
|
}>, import("../types/core.types.js").CoreUserSession>;
|
|
@@ -36,4 +36,5 @@ export declare const authBearer: import("../types/core.types.js").CorePikkuMiddl
|
|
|
36
36
|
}, import("../types/core.types.js").CoreSingletonServices<{
|
|
37
37
|
logLevel?: import("../index.js").LogLevel;
|
|
38
38
|
secrets?: {};
|
|
39
|
+
workflow?: import("../wirings/workflow/workflow.types.js").WorkflowServiceConfig;
|
|
39
40
|
}>, CoreUserSession>;
|
|
@@ -35,4 +35,5 @@ export declare const authCookie: import("../types/core.types.js").CorePikkuMiddl
|
|
|
35
35
|
}, import("../types/core.types.js").CoreSingletonServices<{
|
|
36
36
|
logLevel?: import("../index.js").LogLevel;
|
|
37
37
|
secrets?: {};
|
|
38
|
+
workflow?: import("../wirings/workflow/workflow.types.js").WorkflowServiceConfig;
|
|
38
39
|
}>, import("../types/core.types.js").CoreUserSession>;
|
|
@@ -3,4 +3,5 @@ export declare const timeout: () => import("../types/core.types.js").CorePikkuMi
|
|
|
3
3
|
}, import("../types/core.types.js").CoreSingletonServices<{
|
|
4
4
|
logLevel?: import("../index.js").LogLevel;
|
|
5
5
|
secrets?: {};
|
|
6
|
+
workflow?: import("../wirings/workflow/workflow.types.js").WorkflowServiceConfig;
|
|
6
7
|
}>, import("../types/core.types.js").CoreUserSession>;
|
package/dist/permissions.js
CHANGED
|
@@ -154,6 +154,7 @@ const combinedPermissionsCache = {
|
|
|
154
154
|
[PikkuWiringTypes.scheduler]: {},
|
|
155
155
|
[PikkuWiringTypes.mcp]: {},
|
|
156
156
|
[PikkuWiringTypes.cli]: {},
|
|
157
|
+
[PikkuWiringTypes.workflow]: {},
|
|
157
158
|
};
|
|
158
159
|
/**
|
|
159
160
|
* Combines wiring-specific permissions with function-level permissions.
|
package/dist/pikku-state.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ import { FunctionsMeta, CorePikkuMiddleware, CorePikkuMiddlewareGroup, FunctionS
|
|
|
4
4
|
import { CoreScheduledTask, ScheduledTasksMeta } from './wirings/scheduler/scheduler.types.js';
|
|
5
5
|
import { ErrorDetails, PikkuError } from './errors/error-handler.js';
|
|
6
6
|
import { CorePermissionGroup, CorePikkuFunctionConfig, CorePikkuPermission } from './function/functions.types.js';
|
|
7
|
-
import {
|
|
7
|
+
import { QueueWorkersMeta, CoreQueueWorker } from './wirings/queue/queue.types.js';
|
|
8
8
|
import { CoreMCPResource, CoreMCPTool, CoreMCPPrompt, MCPResourceMeta, MCPToolMeta, MCPPromptMeta } from './wirings/mcp/mcp.types.js';
|
|
9
9
|
import { CLIMeta, CLIProgramState } from './wirings/cli/cli.types.js';
|
|
10
|
+
import { CoreWorkflow, WorkflowsMeta } from './wirings/workflow/workflow.types.js';
|
|
10
11
|
interface PikkuState {
|
|
11
12
|
function: {
|
|
12
13
|
meta: FunctionsMeta;
|
|
@@ -35,7 +36,11 @@ interface PikkuState {
|
|
|
35
36
|
};
|
|
36
37
|
queue: {
|
|
37
38
|
registrations: Map<string, CoreQueueWorker>;
|
|
38
|
-
meta:
|
|
39
|
+
meta: QueueWorkersMeta;
|
|
40
|
+
};
|
|
41
|
+
workflows: {
|
|
42
|
+
registrations: Map<string, CoreWorkflow>;
|
|
43
|
+
meta: WorkflowsMeta;
|
|
39
44
|
};
|
|
40
45
|
mcp: {
|
|
41
46
|
resources: Map<string, CoreMCPResource>;
|
package/dist/pikku-state.js
CHANGED
package/dist/services/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './secret-service.js';
|
|
|
8
8
|
export * from './variables-service.js';
|
|
9
9
|
export * from './schema-service.js';
|
|
10
10
|
export * from './user-session-service.js';
|
|
11
|
+
export * from './scheduler-service.js';
|
|
11
12
|
export * from './local-secrets.js';
|
|
12
13
|
export * from './local-variables.js';
|
|
13
14
|
export * from './logger-console.js';
|
package/dist/services/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * from './secret-service.js';
|
|
|
9
9
|
export * from './variables-service.js';
|
|
10
10
|
export * from './schema-service.js';
|
|
11
11
|
export * from './user-session-service.js';
|
|
12
|
+
export * from './scheduler-service.js';
|
|
12
13
|
// Local implementations
|
|
13
14
|
export * from './local-secrets.js';
|
|
14
15
|
export * from './local-variables.js';
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { CoreUserSession } from '../types/core.types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Minimal metadata for listing scheduled tasks
|
|
4
|
+
*/
|
|
5
|
+
export interface ScheduledTaskSummary {
|
|
6
|
+
/** Unique task ID */
|
|
7
|
+
taskId: string;
|
|
8
|
+
/** RPC function name to invoke */
|
|
9
|
+
rpcName: string;
|
|
10
|
+
/** Scheduled execution time */
|
|
11
|
+
scheduledFor: Date;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Full metadata for a scheduled task retrieved from the queue
|
|
15
|
+
*/
|
|
16
|
+
export interface ScheduledTaskInfo extends ScheduledTaskSummary {
|
|
17
|
+
/** Data to pass to the RPC function */
|
|
18
|
+
data?: any;
|
|
19
|
+
/** User session */
|
|
20
|
+
session?: CoreUserSession;
|
|
21
|
+
/** Task status */
|
|
22
|
+
status?: 'scheduled' | 'active' | 'completed' | 'failed';
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Abstract scheduler service for persistent scheduled task management
|
|
26
|
+
* Implementations use queue backends (pg-boss, BullMQ) for distributed scheduling
|
|
27
|
+
*/
|
|
28
|
+
export declare abstract class SchedulerService {
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the scheduler service
|
|
31
|
+
*/
|
|
32
|
+
abstract init(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Schedule a one-off delayed RPC call
|
|
35
|
+
* @param delay - Delay before execution (number in milliseconds or duration string like "5h", "30m")
|
|
36
|
+
* @param rpcName - RPC function name to invoke
|
|
37
|
+
* @param data - Data to pass to the RPC function
|
|
38
|
+
* @param session - Optional user session
|
|
39
|
+
* @returns Task ID
|
|
40
|
+
*/
|
|
41
|
+
abstract scheduleRPC(delay: number | string, rpcName: string, data?: any, session?: CoreUserSession): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Unschedule a task by ID
|
|
44
|
+
* @param taskId - Task ID
|
|
45
|
+
* @returns Success status
|
|
46
|
+
*/
|
|
47
|
+
abstract unschedule(taskId: string): Promise<boolean>;
|
|
48
|
+
/**
|
|
49
|
+
* Get a scheduled task by ID with full details
|
|
50
|
+
* @param taskId - Task ID
|
|
51
|
+
* @returns Task info or null if not found
|
|
52
|
+
*/
|
|
53
|
+
abstract getTask(taskId: string): Promise<ScheduledTaskInfo | null>;
|
|
54
|
+
/**
|
|
55
|
+
* Get all scheduled tasks with minimal info
|
|
56
|
+
* @returns Array of task summaries with taskId, rpcName, and schedule
|
|
57
|
+
*/
|
|
58
|
+
abstract getAllTasks(): Promise<ScheduledTaskSummary[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Close any open connections
|
|
61
|
+
*/
|
|
62
|
+
abstract close(): Promise<void>;
|
|
63
|
+
}
|
package/dist/time-utils.d.ts
CHANGED
|
@@ -9,4 +9,18 @@ export declare const getRelativeTimeOffset: ({ value, unit, }: RelativeTimeInput
|
|
|
9
9
|
* e.g. value = -1 and unit = 'day' => 1 day ago => now - 86400 seconds
|
|
10
10
|
*/
|
|
11
11
|
export declare const getRelativeTimeOffsetFromNow: (relativeTime: RelativeTimeInput) => Date;
|
|
12
|
+
/**
|
|
13
|
+
* Get duration in milliseconds from a string or number
|
|
14
|
+
* @param duration
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare const getDurationInMilliseconds: (duration: string | number) => number;
|
|
18
|
+
/**
|
|
19
|
+
* Parse a duration string to milliseconds
|
|
20
|
+
* Supports formats like: '2s', '5s', '5sec', '5seconds', '5m', '5min', '5minutes', '1h', '1hour', '2d', '2day', '1w', '1week'
|
|
21
|
+
*
|
|
22
|
+
* @param duration - Duration string (e.g., '2s', '5min', '2hours', '1day')
|
|
23
|
+
* @returns Duration in milliseconds
|
|
24
|
+
*/
|
|
25
|
+
export declare const parseDurationString: (duration: string) => number;
|
|
12
26
|
export {};
|
package/dist/time-utils.js
CHANGED
|
@@ -16,3 +16,65 @@ export const getRelativeTimeOffset = ({ value, unit, }) => {
|
|
|
16
16
|
export const getRelativeTimeOffsetFromNow = (relativeTime) => {
|
|
17
17
|
return new Date(Date.now() + getRelativeTimeOffset(relativeTime));
|
|
18
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Get duration in milliseconds from a string or number
|
|
21
|
+
* @param duration
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export const getDurationInMilliseconds = (duration) => {
|
|
25
|
+
if (typeof duration === 'number') {
|
|
26
|
+
return duration;
|
|
27
|
+
}
|
|
28
|
+
return parseDurationString(duration);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Parse a duration string to milliseconds
|
|
32
|
+
* Supports formats like: '2s', '5s', '5sec', '5seconds', '5m', '5min', '5minutes', '1h', '1hour', '2d', '2day', '1w', '1week'
|
|
33
|
+
*
|
|
34
|
+
* @param duration - Duration string (e.g., '2s', '5min', '2hours', '1day')
|
|
35
|
+
* @returns Duration in milliseconds
|
|
36
|
+
*/
|
|
37
|
+
export const parseDurationString = (duration) => {
|
|
38
|
+
const match = duration.match(/^(\d+)(ms|milliseconds?|s|sec|seconds?|m|min|minutes?|h|hour|hours?|d|day|days?|w|week|weeks?|y|year|years?)$/);
|
|
39
|
+
if (!match) {
|
|
40
|
+
throw new Error(`Invalid duration format: ${duration}. Use formats like '2s', '5s', '5min', '1hour', '2days', '1week'`);
|
|
41
|
+
}
|
|
42
|
+
const value = parseInt(match[1], 10);
|
|
43
|
+
const unitStr = match[2];
|
|
44
|
+
// Handle milliseconds specially
|
|
45
|
+
if (unitStr === 'ms' ||
|
|
46
|
+
unitStr === 'millisecond' ||
|
|
47
|
+
unitStr === 'milliseconds') {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
// Map string variations to TimeUnit
|
|
51
|
+
let unit;
|
|
52
|
+
if (unitStr === 's' ||
|
|
53
|
+
unitStr === 'sec' ||
|
|
54
|
+
unitStr === 'second' ||
|
|
55
|
+
unitStr === 'seconds') {
|
|
56
|
+
unit = 'second';
|
|
57
|
+
}
|
|
58
|
+
else if (unitStr === 'm' ||
|
|
59
|
+
unitStr === 'min' ||
|
|
60
|
+
unitStr === 'minute' ||
|
|
61
|
+
unitStr === 'minutes') {
|
|
62
|
+
unit = 'minute';
|
|
63
|
+
}
|
|
64
|
+
else if (unitStr === 'h' || unitStr === 'hour' || unitStr === 'hours') {
|
|
65
|
+
unit = 'hour';
|
|
66
|
+
}
|
|
67
|
+
else if (unitStr === 'd' || unitStr === 'day' || unitStr === 'days') {
|
|
68
|
+
unit = 'day';
|
|
69
|
+
}
|
|
70
|
+
else if (unitStr === 'w' || unitStr === 'week' || unitStr === 'weeks') {
|
|
71
|
+
unit = 'week';
|
|
72
|
+
}
|
|
73
|
+
else if (unitStr === 'y' || unitStr === 'year' || unitStr === 'years') {
|
|
74
|
+
unit = 'year';
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
throw new Error(`Unknown time unit: ${unitStr}`);
|
|
78
|
+
}
|
|
79
|
+
return getRelativeTimeOffset({ value, unit });
|
|
80
|
+
};
|
|
@@ -8,8 +8,10 @@ import { PikkuChannel } from '../wirings/channel/channel.types.js';
|
|
|
8
8
|
import { PikkuRPC } from '../wirings/rpc/rpc-types.js';
|
|
9
9
|
import { PikkuMCP } from '../wirings/mcp/mcp.types.js';
|
|
10
10
|
import { PikkuScheduledTask } from '../wirings/scheduler/scheduler.types.js';
|
|
11
|
-
import { PikkuQueue } from '../wirings/queue/queue.types.js';
|
|
11
|
+
import { PikkuQueue, QueueService } from '../wirings/queue/queue.types.js';
|
|
12
12
|
import { PikkuCLI } from '../wirings/cli/cli.types.js';
|
|
13
|
+
import { PikkuWorkflowInteraction, WorkflowService, WorkflowServiceConfig, WorkflowStepInteraction } from '../wirings/workflow/workflow.types.js';
|
|
14
|
+
import { SchedulerService } from '../services/scheduler-service.js';
|
|
13
15
|
export declare enum PikkuWiringTypes {
|
|
14
16
|
http = "http",
|
|
15
17
|
scheduler = "scheduler",
|
|
@@ -17,7 +19,8 @@ export declare enum PikkuWiringTypes {
|
|
|
17
19
|
rpc = "rpc",
|
|
18
20
|
queue = "queue",
|
|
19
21
|
mcp = "mcp",
|
|
20
|
-
cli = "cli"
|
|
22
|
+
cli = "cli",
|
|
23
|
+
workflow = "workflow"
|
|
21
24
|
}
|
|
22
25
|
export interface FunctionServicesMeta {
|
|
23
26
|
optimized: boolean;
|
|
@@ -62,6 +65,7 @@ export type FunctionRuntimeMeta = {
|
|
|
62
65
|
inputSchemaName: string | null;
|
|
63
66
|
outputSchemaName: string | null;
|
|
64
67
|
expose?: boolean;
|
|
68
|
+
internal?: boolean;
|
|
65
69
|
};
|
|
66
70
|
export type FunctionMeta = FunctionRuntimeMeta & Partial<{
|
|
67
71
|
name: string;
|
|
@@ -109,6 +113,7 @@ export type CoreConfig<Config extends Record<string, unknown> = {}> = {
|
|
|
109
113
|
logLevel?: LogLevel;
|
|
110
114
|
/** Secrets used by the application (optional). */
|
|
111
115
|
secrets?: {};
|
|
116
|
+
workflow?: WorkflowServiceConfig;
|
|
112
117
|
} & Config;
|
|
113
118
|
/**
|
|
114
119
|
* Represents a core user session, which can be extended for more specific session information.
|
|
@@ -129,6 +134,12 @@ export interface CoreSingletonServices<Config extends CoreConfig = CoreConfig> {
|
|
|
129
134
|
logger: Logger;
|
|
130
135
|
/** The variable service to be used */
|
|
131
136
|
variables: VariablesService;
|
|
137
|
+
/** The workflow orchestrator service */
|
|
138
|
+
workflowService?: WorkflowService;
|
|
139
|
+
/** The queue service */
|
|
140
|
+
queueService?: QueueService;
|
|
141
|
+
/** The scheduler service */
|
|
142
|
+
schedulerService?: SchedulerService;
|
|
132
143
|
}
|
|
133
144
|
/**
|
|
134
145
|
* Represents different forms of interaction within Pikku and the outside world.
|
|
@@ -141,6 +152,8 @@ export type PikkuInteraction<In = unknown, Out = unknown> = Partial<{
|
|
|
141
152
|
scheduledTask: PikkuScheduledTask;
|
|
142
153
|
queue: PikkuQueue;
|
|
143
154
|
cli: PikkuCLI;
|
|
155
|
+
workflow: PikkuWorkflowInteraction;
|
|
156
|
+
workflowStep: WorkflowStepInteraction;
|
|
144
157
|
}>;
|
|
145
158
|
/**
|
|
146
159
|
* A function that can wrap an interaction and be called before or after
|
|
@@ -244,3 +257,12 @@ export type PikkuDocs = {
|
|
|
244
257
|
tags?: string[];
|
|
245
258
|
errors?: string[];
|
|
246
259
|
};
|
|
260
|
+
/**
|
|
261
|
+
* Serialized error for storage
|
|
262
|
+
*/
|
|
263
|
+
export interface SerializedError {
|
|
264
|
+
message: string;
|
|
265
|
+
stack?: string;
|
|
266
|
+
code?: string;
|
|
267
|
+
[key: string]: any;
|
|
268
|
+
}
|
package/dist/types/core.types.js
CHANGED
|
@@ -7,6 +7,7 @@ export var PikkuWiringTypes;
|
|
|
7
7
|
PikkuWiringTypes["queue"] = "queue";
|
|
8
8
|
PikkuWiringTypes["mcp"] = "mcp";
|
|
9
9
|
PikkuWiringTypes["cli"] = "cli";
|
|
10
|
+
PikkuWiringTypes["workflow"] = "workflow";
|
|
10
11
|
})(PikkuWiringTypes || (PikkuWiringTypes = {}));
|
|
11
12
|
/**
|
|
12
13
|
* Factory function for creating middleware with tree-shaking support
|
|
@@ -14,7 +14,7 @@ export async function executeCLIViaChannel({ programName, pikkuWS, args = proces
|
|
|
14
14
|
// Get CLI metadata from state
|
|
15
15
|
const allCLIMeta = pikkuState('cli', 'meta');
|
|
16
16
|
if (!allCLIMeta) {
|
|
17
|
-
throw new Error('[PKU342] CLI metadata not found. No CLI wirings were registered. See https://pikku.dev/errors/pku342 for more information.');
|
|
17
|
+
throw new Error('[PKU342] CLI metadata not found. No CLI wirings were registered. See https://pikku.dev/docs/pikku-cli/errors/pku342 for more information.');
|
|
18
18
|
}
|
|
19
19
|
const programMeta = allCLIMeta.programs[programName];
|
|
20
20
|
if (!programMeta) {
|
|
@@ -286,7 +286,7 @@ export async function executeCLI({ programName, args, createConfig, createSingle
|
|
|
286
286
|
// Get CLI metadata from state
|
|
287
287
|
const allCLIMeta = pikkuState('cli', 'meta');
|
|
288
288
|
if (!allCLIMeta) {
|
|
289
|
-
throw new Error('[PKU342] CLI metadata not found. No CLI wirings were registered. See https://pikku.dev/errors/pku342 for more information.');
|
|
289
|
+
throw new Error('[PKU342] CLI metadata not found. No CLI wirings were registered. See https://pikku.dev/docs/pikku-cli/errors/pku342 for more information.');
|
|
290
290
|
}
|
|
291
291
|
const programMeta = allCLIMeta.programs[programName];
|
|
292
292
|
if (!programMeta) {
|
|
@@ -2,6 +2,7 @@ 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
4
|
import { PikkuWiringTypes, } from '../../types/core.types.js';
|
|
5
|
+
import { rpcService } from '../rpc/rpc-runner.js';
|
|
5
6
|
/**
|
|
6
7
|
* Error class for queue processor not found
|
|
7
8
|
*/
|
|
@@ -102,13 +103,15 @@ export async function runQueueJob({ singletonServices, createSessionServices, jo
|
|
|
102
103
|
};
|
|
103
104
|
try {
|
|
104
105
|
logger.info(`Processing job ${job.id} in queue ${job.queueName}`);
|
|
106
|
+
const interaction = { queue };
|
|
105
107
|
// Use provided singleton services
|
|
106
108
|
const getAllServices = async () => {
|
|
107
109
|
const sessionServices = await createSessionServices?.(singletonServices, { queue }, undefined);
|
|
108
|
-
|
|
110
|
+
const services = rpcService.injectRPCService({
|
|
109
111
|
...singletonServices,
|
|
110
112
|
...sessionServices,
|
|
111
|
-
};
|
|
113
|
+
}, interaction, false);
|
|
114
|
+
return services;
|
|
112
115
|
};
|
|
113
116
|
// Execute the pikku function with the job data
|
|
114
117
|
const result = await runPikkuFunc(PikkuWiringTypes.queue, job.queueName, processorMeta.pikkuFuncName, {
|
|
@@ -119,7 +122,7 @@ export async function runQueueJob({ singletonServices, createSessionServices, jo
|
|
|
119
122
|
inheritedMiddleware: processorMeta.middleware,
|
|
120
123
|
wireMiddleware: queueWorker.middleware,
|
|
121
124
|
tags: queueWorker.tags,
|
|
122
|
-
interaction
|
|
125
|
+
interaction,
|
|
123
126
|
});
|
|
124
127
|
logger.debug(`Successfully processed job ${job.id} in queue ${job.queueName}`);
|
|
125
128
|
return result;
|
|
@@ -126,13 +126,11 @@ 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
|
|
133
|
+
export type QueueWorkersMeta = Record<string, {
|
|
136
134
|
pikkuFuncName: string;
|
|
137
135
|
schemaName?: string;
|
|
138
136
|
queueName: string;
|
|
@@ -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';
|
|
@@ -13,6 +13,10 @@ export declare class ContextAwareRPCService {
|
|
|
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
|
+
rpcWithInteraction<In = any, Out = any>(funcName: string, data: In, interaction: PikkuInteraction): 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?;
|
|
@@ -32,8 +32,7 @@ export class ContextAwareRPCService {
|
|
|
32
32
|
}
|
|
33
33
|
async rpc(funcName, data) {
|
|
34
34
|
const rpcDepth = this.services.rpc?.depth || 0;
|
|
35
|
-
|
|
36
|
-
return runPikkuFunc(PikkuWiringTypes.rpc, pikkuFuncName, pikkuFuncName, {
|
|
35
|
+
return runPikkuFunc(PikkuWiringTypes.rpc, funcName, getPikkuFunctionName(funcName), {
|
|
37
36
|
auth: this.options.requiresAuth,
|
|
38
37
|
singletonServices: this.services,
|
|
39
38
|
getAllServices: () => {
|
|
@@ -52,6 +51,40 @@ export class ContextAwareRPCService {
|
|
|
52
51
|
interaction: this.interaction,
|
|
53
52
|
});
|
|
54
53
|
}
|
|
54
|
+
async rpcWithInteraction(funcName, data, interaction) {
|
|
55
|
+
const rpcDepth = this.services.rpc?.depth || 0;
|
|
56
|
+
const mergedInteraction = {
|
|
57
|
+
...this.interaction,
|
|
58
|
+
...interaction,
|
|
59
|
+
};
|
|
60
|
+
return runPikkuFunc(PikkuWiringTypes.rpc, funcName, getPikkuFunctionName(funcName), {
|
|
61
|
+
auth: this.options.requiresAuth,
|
|
62
|
+
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
|
+
data: () => data,
|
|
77
|
+
userSession: this.services.userSession,
|
|
78
|
+
coerceDataFromSchema: this.options.coerceDataFromSchema,
|
|
79
|
+
interaction: mergedInteraction,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async startWorkflow(workflowName, input) {
|
|
83
|
+
if (!this.services.workflowService) {
|
|
84
|
+
throw new Error('WorkflowService service not available');
|
|
85
|
+
}
|
|
86
|
+
return this.services.workflowService.startWorkflow(workflowName, input, this);
|
|
87
|
+
}
|
|
55
88
|
}
|
|
56
89
|
// RPC Service class for the global interface
|
|
57
90
|
export class PikkuRPCService {
|
|
@@ -74,6 +107,8 @@ export class PikkuRPCService {
|
|
|
74
107
|
global: false,
|
|
75
108
|
invoke: serviceRPC.rpc.bind(serviceRPC),
|
|
76
109
|
invokeExposed: serviceRPC.rpc.bind(serviceRPC),
|
|
110
|
+
startWorkflow: serviceRPC.startWorkflow.bind(serviceRPC),
|
|
111
|
+
rpcWithInteraction: serviceRPC.rpcWithInteraction.bind(serviceRPC),
|
|
77
112
|
};
|
|
78
113
|
return serviceCopy;
|
|
79
114
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow module exports
|
|
3
|
+
*/
|
|
4
|
+
export type { CoreWorkflow, WorkflowStepOptions, WorkflowStepMeta, PikkuWorkflowInteraction, PikkuWorkflow, WorkflowsMeta, WorkflowRun, StepState, WorkflowStatus, StepStatus, } from './workflow.types.js';
|
|
5
|
+
export { PikkuWorkflowService } from './pikku-workflow-service.js';
|
|
6
|
+
export { wireWorkflow } from './workflow-runner.js';
|