@executioncontrolprotocol/app 0.0.0-stage → 0.51.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/LICENSE +202 -0
- package/README.md +64 -2
- package/dist/graph/dirty-buffer.d.ts +7 -0
- package/dist/graph/dirty-buffer.d.ts.map +1 -0
- package/dist/graph/dirty-buffer.js +9 -0
- package/dist/graph/dirty-buffer.js.map +1 -0
- package/dist/graph/extract-data-edges.d.ts +24 -0
- package/dist/graph/extract-data-edges.d.ts.map +1 -0
- package/dist/graph/extract-data-edges.js +139 -0
- package/dist/graph/extract-data-edges.js.map +1 -0
- package/dist/graph/index.d.ts +12 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +11 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/io-from-schema.d.ts +36 -0
- package/dist/graph/io-from-schema.d.ts.map +1 -0
- package/dist/graph/io-from-schema.js +140 -0
- package/dist/graph/io-from-schema.js.map +1 -0
- package/dist/graph/layout.d.ts +7 -0
- package/dist/graph/layout.d.ts.map +1 -0
- package/dist/graph/layout.js +66 -0
- package/dist/graph/layout.js.map +1 -0
- package/dist/graph/map-run-events.d.ts +8 -0
- package/dist/graph/map-run-events.d.ts.map +1 -0
- package/dist/graph/map-run-events.js +31 -0
- package/dist/graph/map-run-events.js.map +1 -0
- package/dist/graph/patch-source.d.ts +13 -0
- package/dist/graph/patch-source.d.ts.map +1 -0
- package/dist/graph/patch-source.js +24 -0
- package/dist/graph/patch-source.js.map +1 -0
- package/dist/graph/ports-from-zod.d.ts +35 -0
- package/dist/graph/ports-from-zod.d.ts.map +1 -0
- package/dist/graph/ports-from-zod.js +203 -0
- package/dist/graph/ports-from-zod.js.map +1 -0
- package/dist/graph/progress.d.ts +23 -0
- package/dist/graph/progress.d.ts.map +1 -0
- package/dist/graph/progress.js +27 -0
- package/dist/graph/progress.js.map +1 -0
- package/dist/graph/types.d.ts +152 -0
- package/dist/graph/types.d.ts.map +1 -0
- package/dist/graph/types.js +2 -0
- package/dist/graph/types.js.map +1 -0
- package/dist/graph/value-schema-hint.d.ts +36 -0
- package/dist/graph/value-schema-hint.d.ts.map +1 -0
- package/dist/graph/value-schema-hint.js +205 -0
- package/dist/graph/value-schema-hint.js.map +1 -0
- package/dist/graph/workflow-to-reactflow.d.ts +11 -0
- package/dist/graph/workflow-to-reactflow.d.ts.map +1 -0
- package/dist/graph/workflow-to-reactflow.js +224 -0
- package/dist/graph/workflow-to-reactflow.js.map +1 -0
- package/dist/host/adapter.d.ts +76 -0
- package/dist/host/adapter.d.ts.map +1 -0
- package/dist/host/adapter.js +2 -0
- package/dist/host/adapter.js.map +1 -0
- package/dist/host/config-source.d.ts +11 -0
- package/dist/host/config-source.d.ts.map +1 -0
- package/dist/host/config-source.js +19 -0
- package/dist/host/config-source.js.map +1 -0
- package/dist/host/constants.d.ts +21 -0
- package/dist/host/constants.d.ts.map +1 -0
- package/dist/host/constants.js +21 -0
- package/dist/host/constants.js.map +1 -0
- package/dist/host/local-client.d.ts +36 -0
- package/dist/host/local-client.d.ts.map +1 -0
- package/dist/host/local-client.js +138 -0
- package/dist/host/local-client.js.map +1 -0
- package/dist/host/protocol.d.ts +98 -0
- package/dist/host/protocol.d.ts.map +1 -0
- package/dist/host/protocol.js +2 -0
- package/dist/host/protocol.js.map +1 -0
- package/dist/host/round-trip.d.ts +19 -0
- package/dist/host/round-trip.d.ts.map +1 -0
- package/dist/host/round-trip.js +37 -0
- package/dist/host/round-trip.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/web/assets/index-BZiUJZIM.js +150 -0
- package/dist/web/assets/index-BaWYUR_k.css +2 -0
- package/dist/web/index.html +17 -0
- package/package.json +57 -3
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/** How a step input is supplied on the graph. @category App */
|
|
2
|
+
export type ReactFlowPortBinding = "literal" | "ref";
|
|
3
|
+
/** Port on a React Flow step node. @category App */
|
|
4
|
+
export interface ReactFlowPort {
|
|
5
|
+
/** Handle id (matches edge sourceHandle / targetHandle). */
|
|
6
|
+
id: string;
|
|
7
|
+
/** Parameter / field name. */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Human-readable type (`string`, `file!`, or `unknown`). */
|
|
10
|
+
typeLabel: string;
|
|
11
|
+
/**
|
|
12
|
+
* Portable JSON Schema hint for the port value (primitives + constraints).
|
|
13
|
+
* Never includes UI widget names — viewers map this to controls.
|
|
14
|
+
*/
|
|
15
|
+
valueSchema?: Record<string, unknown>;
|
|
16
|
+
/** Whether the field is required (inputs only). */
|
|
17
|
+
required?: boolean;
|
|
18
|
+
/** How this input is supplied (`literal` `.with()` value or `$ref`). */
|
|
19
|
+
binding?: ReactFlowPortBinding;
|
|
20
|
+
/** Truncated display for literal values. */
|
|
21
|
+
valuePreview?: string;
|
|
22
|
+
/** Full literal string for tooltip / editor seed. */
|
|
23
|
+
valueTitle?: string;
|
|
24
|
+
/** Short `$ref` path without `state.` (e.g. `summary.text`). */
|
|
25
|
+
refPath?: string;
|
|
26
|
+
}
|
|
27
|
+
/** Step node payload. @category App */
|
|
28
|
+
export interface ReactFlowStepData {
|
|
29
|
+
/** Display label. */
|
|
30
|
+
label: string;
|
|
31
|
+
/** Capability id (`uses`). */
|
|
32
|
+
uses?: string;
|
|
33
|
+
/** Commit key (`as`). */
|
|
34
|
+
as?: string;
|
|
35
|
+
/** Input handles. */
|
|
36
|
+
inputs: ReactFlowPort[];
|
|
37
|
+
/** Output handles. */
|
|
38
|
+
outputs: ReactFlowPort[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Group node payload (optional viewer type; encoder emits step nodes only).
|
|
42
|
+
* @category App
|
|
43
|
+
*/
|
|
44
|
+
export interface ReactFlowGroupData {
|
|
45
|
+
/** Display label. */
|
|
46
|
+
label: string;
|
|
47
|
+
/** Structural kind. */
|
|
48
|
+
kind: "parallel" | "branch" | "loop" | "workflow";
|
|
49
|
+
}
|
|
50
|
+
/** Workflow I/O projection (`accepts` / `returns`) — not a capability step. @category App */
|
|
51
|
+
export type ReactFlowIoKind = "accepts" | "returns";
|
|
52
|
+
/** Payload for projected Inputs / Outputs nodes. @category App */
|
|
53
|
+
export interface ReactFlowIoData {
|
|
54
|
+
/** Display label (`Inputs` / `Outputs`). */
|
|
55
|
+
label: string;
|
|
56
|
+
/** Which workflow contract this node edits. */
|
|
57
|
+
kind: ReactFlowIoKind;
|
|
58
|
+
/** Input handles (Outputs node only). */
|
|
59
|
+
inputs: ReactFlowPort[];
|
|
60
|
+
/** Output handles (Inputs node only). */
|
|
61
|
+
outputs: ReactFlowPort[];
|
|
62
|
+
}
|
|
63
|
+
/** React Flow node. @category App */
|
|
64
|
+
export interface ReactFlowNode {
|
|
65
|
+
/** Node id (typically a workflow step id). */
|
|
66
|
+
id: string;
|
|
67
|
+
/** Node type for the viewer. */
|
|
68
|
+
type: "ecp-step" | "ecp-group" | "ecp-io";
|
|
69
|
+
/** Layout position (absolute; canvas is the workflow surface). */
|
|
70
|
+
position: {
|
|
71
|
+
x: number;
|
|
72
|
+
y: number;
|
|
73
|
+
};
|
|
74
|
+
/** Node payload. */
|
|
75
|
+
data: ReactFlowStepData | ReactFlowGroupData | ReactFlowIoData;
|
|
76
|
+
/** Soft size hint for layout. */
|
|
77
|
+
style?: {
|
|
78
|
+
width?: number;
|
|
79
|
+
height?: number;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** Edge kind. @category App */
|
|
83
|
+
export type ReactFlowEdgeKind = "data" | "control";
|
|
84
|
+
/** React Flow edge. @category App */
|
|
85
|
+
export interface ReactFlowEdge {
|
|
86
|
+
/** Edge id. */
|
|
87
|
+
id: string;
|
|
88
|
+
/** Source node id. */
|
|
89
|
+
source: string;
|
|
90
|
+
/** Target node id. */
|
|
91
|
+
target: string;
|
|
92
|
+
/** Source handle id. */
|
|
93
|
+
sourceHandle?: string;
|
|
94
|
+
/** Target handle id. */
|
|
95
|
+
targetHandle?: string;
|
|
96
|
+
/** Edge metadata. */
|
|
97
|
+
data: {
|
|
98
|
+
kind: ReactFlowEdgeKind;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** Encoded React Flow document. @category App */
|
|
102
|
+
export interface ReactFlowDocument {
|
|
103
|
+
/** Nodes. */
|
|
104
|
+
nodes: ReactFlowNode[];
|
|
105
|
+
/** Edges. */
|
|
106
|
+
edges: ReactFlowEdge[];
|
|
107
|
+
}
|
|
108
|
+
/** JSON Schema I/O for one capability, from authoring `describe()`. @category App */
|
|
109
|
+
export interface CapabilityIoSchemas {
|
|
110
|
+
/** Projected capability input JSON Schema. */
|
|
111
|
+
inputSchema?: unknown;
|
|
112
|
+
/** Projected capability output JSON Schema. */
|
|
113
|
+
outputSchema?: unknown;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Capability id → JSON Schema I/O used when the encoder has no {@link Registry}.
|
|
117
|
+
* @category App
|
|
118
|
+
*/
|
|
119
|
+
export type CapabilitySchemaIndex = Record<string, CapabilityIoSchemas>;
|
|
120
|
+
/** Encode options. @category App */
|
|
121
|
+
export interface ReactFlowEncodeOptions {
|
|
122
|
+
/** Rank direction for dagre. Default `LR`. */
|
|
123
|
+
direction?: "LR" | "TB";
|
|
124
|
+
/** Node width used for layout. */
|
|
125
|
+
nodeWidth?: number;
|
|
126
|
+
/** Node height used for layout. */
|
|
127
|
+
nodeHeight?: number;
|
|
128
|
+
/**
|
|
129
|
+
* Capability I/O JSON Schemas from `describe()`. Used when `registry` is
|
|
130
|
+
* omitted so the live App can still draw typed ports.
|
|
131
|
+
*/
|
|
132
|
+
capabilitySchemas?: CapabilitySchemaIndex;
|
|
133
|
+
}
|
|
134
|
+
/** Step run status for progress events. @category App */
|
|
135
|
+
export type ReactFlowStepStatus = "idle" | "pending" | "running" | "completed" | "failed";
|
|
136
|
+
/** Detail for `step:status` progress events. @category App */
|
|
137
|
+
export interface ReactFlowStepStatusDetail {
|
|
138
|
+
/** Workflow step id. */
|
|
139
|
+
stepId: string;
|
|
140
|
+
/** Status. */
|
|
141
|
+
status: ReactFlowStepStatus;
|
|
142
|
+
/** Optional failure message for hover tooltips. */
|
|
143
|
+
message?: string;
|
|
144
|
+
}
|
|
145
|
+
/** Detail for `run:reset` / `run:done`. @category App */
|
|
146
|
+
export interface ReactFlowRunLifecycleDetail {
|
|
147
|
+
/** Run id when available. */
|
|
148
|
+
runId?: string;
|
|
149
|
+
/** Terminal outcome when done. */
|
|
150
|
+
outcome?: "completed" | "failed" | "cancelled";
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/graph/types.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,KAAK,CAAA;AAEpD,oDAAoD;AACpD,MAAM,WAAW,aAAa;IAC5B,4DAA4D;IAC5D,EAAE,EAAE,MAAM,CAAA;IACV,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,6DAA6D;IAC7D,SAAS,EAAE,MAAM,CAAA;IACjB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACrC,mDAAmD;IACnD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,wEAAwE;IACxE,OAAO,CAAC,EAAE,oBAAoB,CAAA;IAC9B,4CAA4C;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gEAAgE;IAChE,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,uCAAuC;AACvC,MAAM,WAAW,iBAAiB;IAChC,qBAAqB;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,8BAA8B;IAC9B,I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AE,MAAM,CAAA;CACjB;AAED,yDAAyD;AACzD,MAAM,WAAW,2BAA2B;IAC1C,6BAA6B;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kCAAkC;IAClC,OAAO,CAAC,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAA;CAC/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/graph/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** JSON Schema fragment used as a portable port type hint. @category App */
|
|
3
|
+
export type ValueSchemaHint = Record<string, unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* Whether a JSON Schema hint describes a file ref port (`x-ecp-file`, `contentMediaType`, or FileRef shape).
|
|
6
|
+
* @category App
|
|
7
|
+
*/
|
|
8
|
+
export declare function isFileValueSchemaHint(schema: Record<string, unknown>): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Unwrap Zod wrappers that do not change the value shape for UI hints.
|
|
11
|
+
* @category App
|
|
12
|
+
*/
|
|
13
|
+
export declare function unwrapZodType(type: z.ZodType): z.ZodType;
|
|
14
|
+
/**
|
|
15
|
+
* Project a Zod type to a primitive-centered JSON Schema hint.
|
|
16
|
+
* Enums stay `type: "string"` (or number) with an `enum` constraint — never a widget name.
|
|
17
|
+
* @category App
|
|
18
|
+
*/
|
|
19
|
+
export declare function valueSchemaFromZod(type: z.ZodType): ValueSchemaHint | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Synthesize a minimal valueSchema from a type label (`string!`, `number`, …).
|
|
22
|
+
* @category App
|
|
23
|
+
*/
|
|
24
|
+
export declare function valueSchemaFromEqlLabel(typeLabel: string): ValueSchemaHint | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Pass through a JSON Schema property node as a valueSchema hint (shallow clone).
|
|
27
|
+
* @category App
|
|
28
|
+
*/
|
|
29
|
+
export declare function valueSchemaFromJsonSchemaProp(prop: unknown): ValueSchemaHint | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Build a name → valueSchema map from a capability input/output schema.
|
|
32
|
+
* Supports Zod objects and JSON Schema objects with `properties`.
|
|
33
|
+
* @category App
|
|
34
|
+
*/
|
|
35
|
+
export declare function valueSchemasFromCapabilitySchema(schema: unknown): Map<string, ValueSchemaHint>;
|
|
36
|
+
//# sourceMappingURL=value-schema-hint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-schema-hint.d.ts","sourceRoot":"","sources":["../../src/graph/value-schema-hint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAOvB,4EAA4E;AAC5E,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAMrD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAgB9E;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAcxD;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,GAAG,eAAe,GAAG,SAAS,CAgF/E;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAYtF;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,SAAS,CAGxF;AAED;;;;GAIG;AACH,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,OAAO,GACd,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAwB9B"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { fileRefSchemaOptions, fileRefValueSchemaHint, isFileRefSchema, } from "@executioncontrolprotocol/core/types";
|
|
3
|
+
function isRecord(value) {
|
|
4
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Whether a JSON Schema hint describes a file ref port (`x-ecp-file`, `contentMediaType`, or FileRef shape).
|
|
8
|
+
* @category App
|
|
9
|
+
*/
|
|
10
|
+
export function isFileValueSchemaHint(schema) {
|
|
11
|
+
if (schema["x-ecp-file"] === true)
|
|
12
|
+
return true;
|
|
13
|
+
if (typeof schema.contentMediaType === "string" && schema.contentMediaType.length > 0) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
if (Array.isArray(schema.contentMediaType) && schema.contentMediaType.length > 0) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (schema.format === "binary" || schema.format === "byte")
|
|
20
|
+
return true;
|
|
21
|
+
if (schema.type === "object" && isRecord(schema.properties)) {
|
|
22
|
+
const kind = schema.properties.kind;
|
|
23
|
+
if (isRecord(kind) && Array.isArray(kind.enum)) {
|
|
24
|
+
return kind.enum.some((v) => v === "file" || v === "artifact" || v === "buffer" || v === "url");
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Unwrap Zod wrappers that do not change the value shape for UI hints.
|
|
31
|
+
* @category App
|
|
32
|
+
*/
|
|
33
|
+
export function unwrapZodType(type) {
|
|
34
|
+
if (type instanceof z.ZodOptional) {
|
|
35
|
+
return unwrapZodType(type.unwrap());
|
|
36
|
+
}
|
|
37
|
+
if (type instanceof z.ZodDefault) {
|
|
38
|
+
return unwrapZodType(type.removeDefault());
|
|
39
|
+
}
|
|
40
|
+
if (type instanceof z.ZodNullable) {
|
|
41
|
+
return unwrapZodType(type.unwrap());
|
|
42
|
+
}
|
|
43
|
+
if (type instanceof z.ZodEffects) {
|
|
44
|
+
return unwrapZodType(type._def.schema);
|
|
45
|
+
}
|
|
46
|
+
return type;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Project a Zod type to a primitive-centered JSON Schema hint.
|
|
50
|
+
* Enums stay `type: "string"` (or number) with an `enum` constraint — never a widget name.
|
|
51
|
+
* @category App
|
|
52
|
+
*/
|
|
53
|
+
export function valueSchemaFromZod(type) {
|
|
54
|
+
const inner = unwrapZodType(type);
|
|
55
|
+
if (isFileRefSchema(inner)) {
|
|
56
|
+
return fileRefValueSchemaHint(fileRefSchemaOptions(type));
|
|
57
|
+
}
|
|
58
|
+
if (inner instanceof z.ZodString) {
|
|
59
|
+
const hint = { type: "string" };
|
|
60
|
+
for (const check of inner._def.checks) {
|
|
61
|
+
if (check.kind === "min")
|
|
62
|
+
hint.minLength = check.value;
|
|
63
|
+
if (check.kind === "max")
|
|
64
|
+
hint.maxLength = check.value;
|
|
65
|
+
}
|
|
66
|
+
return hint;
|
|
67
|
+
}
|
|
68
|
+
if (inner instanceof z.ZodNumber) {
|
|
69
|
+
const hint = { type: "number" };
|
|
70
|
+
for (const check of inner._def.checks) {
|
|
71
|
+
if (check.kind === "min")
|
|
72
|
+
hint.minimum = check.value;
|
|
73
|
+
if (check.kind === "max")
|
|
74
|
+
hint.maximum = check.value;
|
|
75
|
+
}
|
|
76
|
+
return hint;
|
|
77
|
+
}
|
|
78
|
+
if (inner instanceof z.ZodBoolean) {
|
|
79
|
+
return { type: "boolean" };
|
|
80
|
+
}
|
|
81
|
+
if (inner instanceof z.ZodNull) {
|
|
82
|
+
return { type: "null" };
|
|
83
|
+
}
|
|
84
|
+
if (inner instanceof z.ZodEnum) {
|
|
85
|
+
const values = inner.options;
|
|
86
|
+
return { type: "string", enum: [...values] };
|
|
87
|
+
}
|
|
88
|
+
if (inner instanceof z.ZodNativeEnum) {
|
|
89
|
+
const raw = inner.enum;
|
|
90
|
+
const values = Object.values(raw).filter((v) => typeof v === "string" || typeof v === "number");
|
|
91
|
+
const allNumber = values.every((v) => typeof v === "number");
|
|
92
|
+
return {
|
|
93
|
+
type: allNumber ? "number" : "string",
|
|
94
|
+
enum: values,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
if (inner instanceof z.ZodLiteral) {
|
|
98
|
+
const value = inner.value;
|
|
99
|
+
if (typeof value === "string")
|
|
100
|
+
return { type: "string", enum: [value] };
|
|
101
|
+
if (typeof value === "number")
|
|
102
|
+
return { type: "number", enum: [value] };
|
|
103
|
+
if (typeof value === "boolean")
|
|
104
|
+
return { type: "boolean", enum: [value] };
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
if (inner instanceof z.ZodArray) {
|
|
108
|
+
const items = valueSchemaFromZod(inner.element);
|
|
109
|
+
return items ? { type: "array", items } : { type: "array" };
|
|
110
|
+
}
|
|
111
|
+
if (inner instanceof z.ZodObject) {
|
|
112
|
+
const properties = {};
|
|
113
|
+
for (const [name, field] of Object.entries(inner.shape)) {
|
|
114
|
+
const child = valueSchemaFromZod(field);
|
|
115
|
+
if (child)
|
|
116
|
+
properties[name] = child;
|
|
117
|
+
}
|
|
118
|
+
return Object.keys(properties).length > 0
|
|
119
|
+
? { type: "object", properties }
|
|
120
|
+
: { type: "object" };
|
|
121
|
+
}
|
|
122
|
+
if (inner instanceof z.ZodRecord) {
|
|
123
|
+
return { type: "object" };
|
|
124
|
+
}
|
|
125
|
+
if (inner instanceof z.ZodUnion || inner instanceof z.ZodDiscriminatedUnion) {
|
|
126
|
+
const options = inner.options
|
|
127
|
+
.map((opt) => valueSchemaFromZod(opt))
|
|
128
|
+
.filter((s) => Boolean(s));
|
|
129
|
+
if (options.length === 0)
|
|
130
|
+
return undefined;
|
|
131
|
+
if (options.length === 1)
|
|
132
|
+
return options[0];
|
|
133
|
+
return { oneOf: options };
|
|
134
|
+
}
|
|
135
|
+
if (inner instanceof z.ZodAny || inner instanceof z.ZodUnknown) {
|
|
136
|
+
return {};
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Synthesize a minimal valueSchema from a type label (`string!`, `number`, …).
|
|
142
|
+
* @category App
|
|
143
|
+
*/
|
|
144
|
+
export function valueSchemaFromEqlLabel(typeLabel) {
|
|
145
|
+
const base = typeLabel.replace(/!+$/, "").trim().toLowerCase();
|
|
146
|
+
if (!base || base === "unknown")
|
|
147
|
+
return undefined;
|
|
148
|
+
if (base === "string")
|
|
149
|
+
return { type: "string" };
|
|
150
|
+
if (base === "number" || base === "float")
|
|
151
|
+
return { type: "number" };
|
|
152
|
+
if (base === "int" || base === "integer")
|
|
153
|
+
return { type: "integer" };
|
|
154
|
+
if (base === "boolean" || base === "bool")
|
|
155
|
+
return { type: "boolean" };
|
|
156
|
+
if (base === "null")
|
|
157
|
+
return { type: "null" };
|
|
158
|
+
if (base === "array")
|
|
159
|
+
return { type: "array" };
|
|
160
|
+
if (base === "file")
|
|
161
|
+
return fileRefValueSchemaHint();
|
|
162
|
+
if (base === "object" || base === "record" || base === "json")
|
|
163
|
+
return { type: "object" };
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Pass through a JSON Schema property node as a valueSchema hint (shallow clone).
|
|
168
|
+
* @category App
|
|
169
|
+
*/
|
|
170
|
+
export function valueSchemaFromJsonSchemaProp(prop) {
|
|
171
|
+
if (prop === null || typeof prop !== "object" || Array.isArray(prop))
|
|
172
|
+
return undefined;
|
|
173
|
+
return { ...prop };
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Build a name → valueSchema map from a capability input/output schema.
|
|
177
|
+
* Supports Zod objects and JSON Schema objects with `properties`.
|
|
178
|
+
* @category App
|
|
179
|
+
*/
|
|
180
|
+
export function valueSchemasFromCapabilitySchema(schema) {
|
|
181
|
+
const out = new Map();
|
|
182
|
+
if (schema === null || schema === undefined)
|
|
183
|
+
return out;
|
|
184
|
+
if (schema instanceof z.ZodObject) {
|
|
185
|
+
for (const [name, field] of Object.entries(schema.shape)) {
|
|
186
|
+
const hint = valueSchemaFromZod(field);
|
|
187
|
+
if (hint)
|
|
188
|
+
out.set(name, hint);
|
|
189
|
+
}
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
if (typeof schema === "object" && !Array.isArray(schema)) {
|
|
193
|
+
const obj = schema;
|
|
194
|
+
const props = obj.properties;
|
|
195
|
+
if (props && typeof props === "object" && !Array.isArray(props)) {
|
|
196
|
+
for (const [name, prop] of Object.entries(props)) {
|
|
197
|
+
const hint = valueSchemaFromJsonSchemaProp(prop);
|
|
198
|
+
if (hint)
|
|
199
|
+
out.set(name, hint);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return out;
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=value-schema-hint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-schema-hint.js","sourceRoot":"","sources":["../../src/graph/value-schema-hint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,GAChB,MAAM,sCAAsC,CAAA;AAK7C,SAAS,QAAQ,CAAC,KAAc;IAC9B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAA+B;IACnE,IAAI,MAAM,CAAC,YAAY,CAAC,KAAK,IAAI;QAAE,OAAO,IAAI,CAAA;IAC9C,IAAI,OAAO,MAAM,CAAC,gBAAgB,KAAK,QAAQ,IAAI,MAAM,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtF,OAAO,IAAI,CAAA;IACb,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,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AAK,GAAG,GAAG,CAAC,UAAU,CAAA;QAC5B,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChE,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,EAAE,CAAC;gBAC5E,MAAM,IAAI,GAAG,6BAA6B,CAAC,IAAI,CAAC,CAAA;gBAChD,IAAI,IAAI;oBAAE,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Registry } from "@executioncontrolprotocol/core";
|
|
2
|
+
import type { WorkflowManifest } from "@executioncontrolprotocol/core/types";
|
|
3
|
+
import type { ReactFlowDocument, ReactFlowEncodeOptions } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Convert a workflow manifest into a positioned React Flow document.
|
|
6
|
+
* Emits step nodes, projected Inputs / Outputs (`ecp-io`), and data edges.
|
|
7
|
+
* Sequential control edges are used internally for layout, then discarded.
|
|
8
|
+
* @category App
|
|
9
|
+
*/
|
|
10
|
+
export declare function workflowToReactFlow(manifest: WorkflowManifest, registry?: Registry, options?: ReactFlowEncodeOptions): ReactFlowDocument;
|
|
11
|
+
//# sourceMappingURL=workflow-to-reactflow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"workflow-to-reactflow.d.ts","sourceRoot":"","sources":["../../src/graph/workflow-to-reactflow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAA;AAC9D,OAAO,KAAK,EAAY,gBAAgB,EAAgB,MAAM,sCAAsC,CAAA;AAWpG,OAAO,KAAK,EAEV,iBAAiB,EAEjB,sBAAsB,EAGvB,MAAM,YAAY,CAAA;AAsMnB;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,CAAC,EAAE,QAAQ,EACnB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,iBAAiB,CA2DnB"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { extractDataEdges, longestMatchingPortId } from "./extract-data-edges.js";
|
|
2
|
+
import { acceptsReactFlowNode, jsonSchemaObjectProperties, returnsReactFlowNode, WORKFLOW_ACCEPTS_NODE_ID, WORKFLOW_RETURNS_NODE_ID, } from "./io-from-schema.js";
|
|
3
|
+
import { layoutReactFlowDocument } from "./layout.js";
|
|
4
|
+
import { portsForStep, ensureOutputPort } from "./ports-from-zod.js";
|
|
5
|
+
function isStepNode(node) {
|
|
6
|
+
return !node.type || node.type === "step";
|
|
7
|
+
}
|
|
8
|
+
function connectControl(edges, fromIds, toIds, prefix) {
|
|
9
|
+
if (fromIds.length === 0 || toIds.length === 0)
|
|
10
|
+
return;
|
|
11
|
+
let i = 0;
|
|
12
|
+
for (const from of fromIds) {
|
|
13
|
+
for (const to of toIds) {
|
|
14
|
+
edges.push({
|
|
15
|
+
id: `ctrl-${prefix}-${i++}-${from}-${to}`,
|
|
16
|
+
source: from,
|
|
17
|
+
target: to,
|
|
18
|
+
data: { kind: "control" },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function renderStep(node, ctx) {
|
|
24
|
+
const ports = portsForStep(node, ctx.registry, ctx.capabilitySchemas?.[String(node.uses)]);
|
|
25
|
+
const data = {
|
|
26
|
+
label: node.label ?? node.id,
|
|
27
|
+
uses: String(node.uses),
|
|
28
|
+
...(node.as !== undefined ? { as: node.as } : {}),
|
|
29
|
+
inputs: ports.inputs,
|
|
30
|
+
outputs: ports.outputs,
|
|
31
|
+
};
|
|
32
|
+
const rfNode = {
|
|
33
|
+
id: node.id,
|
|
34
|
+
type: "ecp-step",
|
|
35
|
+
position: { x: 0, y: 0 },
|
|
36
|
+
data,
|
|
37
|
+
};
|
|
38
|
+
return { nodes: [rfNode], edges: [], entryIds: [node.id], exitIds: [node.id] };
|
|
39
|
+
}
|
|
40
|
+
function renderParallel(node, ctx) {
|
|
41
|
+
const nodes = [];
|
|
42
|
+
const edges = [];
|
|
43
|
+
const entryIds = [];
|
|
44
|
+
const exitIds = [];
|
|
45
|
+
node.branches.forEach((branch) => {
|
|
46
|
+
const seg = renderNodes(branch, ctx);
|
|
47
|
+
nodes.push(...seg.nodes);
|
|
48
|
+
edges.push(...seg.edges);
|
|
49
|
+
entryIds.push(...seg.entryIds);
|
|
50
|
+
exitIds.push(...seg.exitIds);
|
|
51
|
+
});
|
|
52
|
+
return { nodes, edges, entryIds, exitIds };
|
|
53
|
+
}
|
|
54
|
+
function renderBranch(node, ctx) {
|
|
55
|
+
const nodes = [];
|
|
56
|
+
const edges = [];
|
|
57
|
+
const entryIds = [];
|
|
58
|
+
const exitIds = [];
|
|
59
|
+
for (const arm of node.branches) {
|
|
60
|
+
const seg = renderNodes(arm.steps, ctx);
|
|
61
|
+
nodes.push(...seg.nodes);
|
|
62
|
+
edges.push(...seg.edges);
|
|
63
|
+
entryIds.push(...seg.entryIds);
|
|
64
|
+
exitIds.push(...seg.exitIds);
|
|
65
|
+
}
|
|
66
|
+
return { nodes, edges, entryIds, exitIds };
|
|
67
|
+
}
|
|
68
|
+
function renderLoop(node, ctx) {
|
|
69
|
+
return renderNodes(node.steps, ctx);
|
|
70
|
+
}
|
|
71
|
+
function renderNode(node, ctx) {
|
|
72
|
+
if (isStepNode(node))
|
|
73
|
+
return renderStep(node, ctx);
|
|
74
|
+
if (node.type === "parallel")
|
|
75
|
+
return renderParallel(node, ctx);
|
|
76
|
+
if (node.type === "branch")
|
|
77
|
+
return renderBranch(node, ctx);
|
|
78
|
+
return renderLoop(node, ctx);
|
|
79
|
+
}
|
|
80
|
+
function renderNodes(nodes, ctx) {
|
|
81
|
+
const outNodes = [];
|
|
82
|
+
const outEdges = [];
|
|
83
|
+
let entryIds = [];
|
|
84
|
+
let exitIds = [];
|
|
85
|
+
nodes.forEach((node, index) => {
|
|
86
|
+
const segment = renderNode(node, ctx);
|
|
87
|
+
outNodes.push(...segment.nodes);
|
|
88
|
+
outEdges.push(...segment.edges);
|
|
89
|
+
if (segment.entryIds.length === 0)
|
|
90
|
+
return;
|
|
91
|
+
if (entryIds.length === 0) {
|
|
92
|
+
entryIds = segment.entryIds;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
connectControl(outEdges, exitIds, segment.entryIds, `seq-root-${index}`);
|
|
96
|
+
}
|
|
97
|
+
exitIds = segment.exitIds;
|
|
98
|
+
});
|
|
99
|
+
return { nodes: outNodes, edges: outEdges, entryIds, exitIds };
|
|
100
|
+
}
|
|
101
|
+
function acceptsPropertyKeys(manifest) {
|
|
102
|
+
return new Set(jsonSchemaObjectProperties(manifest.workflow.accepts).map((field) => field.name));
|
|
103
|
+
}
|
|
104
|
+
function sourceHandleForStep(data) {
|
|
105
|
+
return data.outputs[0]?.id ?? "output";
|
|
106
|
+
}
|
|
107
|
+
function returnsAsKey(fieldName) {
|
|
108
|
+
const dotIndex = fieldName.indexOf(".");
|
|
109
|
+
return dotIndex === -1 ? fieldName : fieldName.slice(0, dotIndex);
|
|
110
|
+
}
|
|
111
|
+
function sourceHandleForReturnsField(fieldName, data) {
|
|
112
|
+
const portIds = data.outputs.map((port) => port.id);
|
|
113
|
+
const dotIndex = fieldName.indexOf(".");
|
|
114
|
+
if (dotIndex >= 0) {
|
|
115
|
+
const fieldPath = fieldName.slice(dotIndex + 1);
|
|
116
|
+
return longestMatchingPortId(fieldPath, portIds);
|
|
117
|
+
}
|
|
118
|
+
if (data.outputs.some((port) => port.id === "output"))
|
|
119
|
+
return "output";
|
|
120
|
+
return sourceHandleForStep(data);
|
|
121
|
+
}
|
|
122
|
+
function extractReturnsEdges(manifest, nodes) {
|
|
123
|
+
const returnsNode = nodes.find((n) => n.id === WORKFLOW_RETURNS_NODE_ID && n.type === "ecp-io");
|
|
124
|
+
if (!returnsNode)
|
|
125
|
+
return [];
|
|
126
|
+
const fields = jsonSchemaObjectProperties(manifest.workflow.returns);
|
|
127
|
+
const acceptsKeys = acceptsPropertyKeys(manifest);
|
|
128
|
+
const asToStep = new Map();
|
|
129
|
+
for (const node of nodes) {
|
|
130
|
+
if (node.type !== "ecp-step")
|
|
131
|
+
continue;
|
|
132
|
+
const data = node.data;
|
|
133
|
+
if (data.as)
|
|
134
|
+
asToStep.set(data.as, node);
|
|
135
|
+
}
|
|
136
|
+
const edges = [];
|
|
137
|
+
let i = 0;
|
|
138
|
+
for (const field of fields) {
|
|
139
|
+
const asKey = returnsAsKey(field.name);
|
|
140
|
+
const stepSource = asToStep.get(asKey);
|
|
141
|
+
if (stepSource && stepSource.type === "ecp-step") {
|
|
142
|
+
const data = stepSource.data;
|
|
143
|
+
edges.push({
|
|
144
|
+
id: `data-returns-${i++}-${stepSource.id}-${field.name}`,
|
|
145
|
+
source: stepSource.id,
|
|
146
|
+
target: WORKFLOW_RETURNS_NODE_ID,
|
|
147
|
+
sourceHandle: sourceHandleForReturnsField(field.name, data),
|
|
148
|
+
targetHandle: field.name,
|
|
149
|
+
data: { kind: "data" },
|
|
150
|
+
});
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (!acceptsKeys.has(field.name))
|
|
154
|
+
continue;
|
|
155
|
+
edges.push({
|
|
156
|
+
id: `data-returns-${i++}-${WORKFLOW_ACCEPTS_NODE_ID}-${field.name}`,
|
|
157
|
+
source: WORKFLOW_ACCEPTS_NODE_ID,
|
|
158
|
+
target: WORKFLOW_RETURNS_NODE_ID,
|
|
159
|
+
sourceHandle: field.name,
|
|
160
|
+
targetHandle: field.name,
|
|
161
|
+
data: { kind: "data" },
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return edges;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Convert a workflow manifest into a positioned React Flow document.
|
|
168
|
+
* Emits step nodes, projected Inputs / Outputs (`ecp-io`), and data edges.
|
|
169
|
+
* Sequential control edges are used internally for layout, then discarded.
|
|
170
|
+
* @category App
|
|
171
|
+
*/
|
|
172
|
+
export function workflowToReactFlow(manifest, registry, options) {
|
|
173
|
+
const acceptsNode = acceptsReactFlowNode(manifest);
|
|
174
|
+
const returnsNode = returnsReactFlowNode(manifest);
|
|
175
|
+
const ctx = {
|
|
176
|
+
registry,
|
|
177
|
+
capabilitySchemas: options?.capabilitySchemas,
|
|
178
|
+
};
|
|
179
|
+
const body = manifest.steps.length === 0
|
|
180
|
+
? { nodes: [], edges: [], entryIds: [], exitIds: [] }
|
|
181
|
+
: renderNodes(manifest.steps, ctx);
|
|
182
|
+
const nodes = [acceptsNode, ...body.nodes];
|
|
183
|
+
if (returnsNode)
|
|
184
|
+
nodes.push(returnsNode);
|
|
185
|
+
const outputPortIdsByStepId = new Map();
|
|
186
|
+
for (const node of body.nodes) {
|
|
187
|
+
if (node.type !== "ecp-step")
|
|
188
|
+
continue;
|
|
189
|
+
const data = node.data;
|
|
190
|
+
outputPortIdsByStepId.set(node.id, data.outputs.map((port) => port.id));
|
|
191
|
+
}
|
|
192
|
+
const dataEdges = extractDataEdges(manifest.steps, acceptsPropertyKeys(manifest), outputPortIdsByStepId);
|
|
193
|
+
const returnsEdges = extractReturnsEdges(manifest, nodes);
|
|
194
|
+
const allDataEdges = [...dataEdges, ...returnsEdges];
|
|
195
|
+
for (const edge of allDataEdges) {
|
|
196
|
+
if (!edge.sourceHandle)
|
|
197
|
+
continue;
|
|
198
|
+
const source = nodes.find((n) => n.id === edge.source);
|
|
199
|
+
if (!source || source.type !== "ecp-step")
|
|
200
|
+
continue;
|
|
201
|
+
const data = source.data;
|
|
202
|
+
ensureOutputPort(data.outputs, edge.sourceHandle);
|
|
203
|
+
}
|
|
204
|
+
const layoutEdges = [...body.edges, ...allDataEdges];
|
|
205
|
+
if (body.entryIds.length > 0) {
|
|
206
|
+
connectControl(layoutEdges, [acceptsNode.id], body.entryIds, "io-accepts");
|
|
207
|
+
}
|
|
208
|
+
else if (returnsNode) {
|
|
209
|
+
connectControl(layoutEdges, [acceptsNode.id], [returnsNode.id], "io-empty");
|
|
210
|
+
}
|
|
211
|
+
if (returnsNode && body.exitIds.length > 0) {
|
|
212
|
+
connectControl(layoutEdges, body.exitIds, [returnsNode.id], "io-returns");
|
|
213
|
+
}
|
|
214
|
+
const doc = {
|
|
215
|
+
nodes,
|
|
216
|
+
edges: layoutEdges,
|
|
217
|
+
};
|
|
218
|
+
const laid = layoutReactFlowDocument(doc, options);
|
|
219
|
+
return {
|
|
220
|
+
nodes: laid.nodes,
|
|
221
|
+
edges: laid.edges.filter((edge) => edge.data.kind === "data"),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=workflow-to-reactflow.js.map
|