@lukstei/dsh-yaml-workflow 0.0.0-stage → 0.2.2-rc.5.4
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/LICENSE +21 -0
- package/README.md +452 -2
- package/cordis.patch.yml +4 -0
- package/dist/client.js +1746 -0
- package/dist/index.js +3495 -0
- package/examples/gate.yml +4 -0
- package/examples/parametrized-wf.yml +20 -0
- package/examples/wf.yml +3 -0
- package/package.json +114 -3
- package/src/boolean.ts +96 -0
- package/src/client/WorkflowCommandCard.tsx +217 -0
- package/src/client/WorkflowErrorCard.tsx +99 -0
- package/src/client/WorkflowMarkdown.tsx +28 -0
- package/src/client/WorkflowMarkdownResult.tsx +86 -0
- package/src/client/WorkflowPrintStep.tsx +46 -0
- package/src/client/WorkflowResumeButton.tsx +159 -0
- package/src/client/WorkflowStepRow.tsx +106 -0
- package/src/client/WorkflowStyles.tsx +10 -0
- package/src/client/actions.ts +113 -0
- package/src/client/context.ts +30 -0
- package/src/client/dsh.d.ts +33 -0
- package/src/client/icons.tsx +91 -0
- package/src/client/index.tsx +186 -0
- package/src/client/store.ts +655 -0
- package/src/client/styles.ts +340 -0
- package/src/effects.ts +696 -0
- package/src/fold.ts +201 -0
- package/src/index.ts +468 -0
- package/src/parser.ts +1146 -0
- package/src/requests.ts +85 -0
- package/src/rules.ts +647 -0
- package/src/runner.ts +1955 -0
- package/src/skill.ts +67 -0
- package/src/transitions.ts +357 -0
- package/src/types.ts +604 -0
package/src/requests.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PURPOSE: Pure selection of pending workflow requests from command history.
|
|
3
|
+
* ALLOWED: Schema validation and deterministic event folding.
|
|
4
|
+
* FORBIDDEN: I/O and framework services.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { WORKFLOW_EVENT_NAME } from "./fold.ts";
|
|
9
|
+
|
|
10
|
+
const commandEnvelope = z.discriminatedUnion("type", [
|
|
11
|
+
z.object({
|
|
12
|
+
type: z.literal("command/run"),
|
|
13
|
+
data: z.object({
|
|
14
|
+
commandId: z.string(),
|
|
15
|
+
name: z.string(),
|
|
16
|
+
args: z.string().optional(),
|
|
17
|
+
}),
|
|
18
|
+
}),
|
|
19
|
+
z.object({
|
|
20
|
+
type: z.literal("command/done"),
|
|
21
|
+
data: z.object({
|
|
22
|
+
commandId: z.string(),
|
|
23
|
+
kind: z.enum(["success", "error"]),
|
|
24
|
+
}),
|
|
25
|
+
}),
|
|
26
|
+
]);
|
|
27
|
+
const requestPayload = z.discriminatedUnion("action", [
|
|
28
|
+
z.object({
|
|
29
|
+
action: z.literal("request"),
|
|
30
|
+
runId: z.string(),
|
|
31
|
+
rawInput: z.string(),
|
|
32
|
+
}),
|
|
33
|
+
z.object({ action: z.enum(["init", "request-failed"]), runId: z.string() }),
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Purpose: Selects the first accepted workflow request in command-arrival order.
|
|
38
|
+
* Contract:
|
|
39
|
+
* - Inputs: chronological command events, including each request's originating /wf command.
|
|
40
|
+
* - Outputs: the next unconsumed request, or undefined while an earlier command validates.
|
|
41
|
+
* - Throws / Errors: malformed command payloads are ignored.
|
|
42
|
+
*/
|
|
43
|
+
export function nextWorkflowRequest(
|
|
44
|
+
events: readonly { readonly type: string; readonly data?: unknown }[],
|
|
45
|
+
): { readonly runId: string; readonly rawInput: string } | undefined {
|
|
46
|
+
const commands = new Map<string, "validating" | "success" | "error">();
|
|
47
|
+
const requests = new Map<
|
|
48
|
+
string,
|
|
49
|
+
{ readonly runId: string; readonly rawInput: string }
|
|
50
|
+
>();
|
|
51
|
+
for (const event of events) {
|
|
52
|
+
if (event.type !== "command/run" && event.type !== "command/done") continue;
|
|
53
|
+
const envelope = commandEnvelope.safeParse(event);
|
|
54
|
+
if (!envelope.success) continue;
|
|
55
|
+
const { type, data: command } = envelope.data;
|
|
56
|
+
if (type === "command/done") {
|
|
57
|
+
if (commands.has(command.commandId))
|
|
58
|
+
commands.set(command.commandId, command.kind);
|
|
59
|
+
} else if (command.name === "wf") {
|
|
60
|
+
commands.set(command.commandId, "validating");
|
|
61
|
+
} else if (
|
|
62
|
+
command.name === WORKFLOW_EVENT_NAME &&
|
|
63
|
+
command.args !== undefined
|
|
64
|
+
) {
|
|
65
|
+
let data: unknown;
|
|
66
|
+
try {
|
|
67
|
+
data = JSON.parse(command.args);
|
|
68
|
+
} catch {
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const payload = requestPayload.safeParse(data);
|
|
72
|
+
if (!payload.success) continue;
|
|
73
|
+
if (payload.data.action === "request")
|
|
74
|
+
requests.set(payload.data.runId, payload.data);
|
|
75
|
+
else requests.delete(payload.data.runId);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
for (const [runId, status] of commands) {
|
|
79
|
+
if (status === "validating") return undefined;
|
|
80
|
+
if (status === "error") continue;
|
|
81
|
+
const request = requests.get(runId);
|
|
82
|
+
if (request !== undefined) return request;
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|